Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSA CRT parameters? #574

Closed
public opened this issue Feb 7, 2014 · 3 comments
Closed

RSA CRT parameters? #574

public opened this issue Feb 7, 2014 · 3 comments

Comments

@public
Copy link
Member

public commented Feb 7, 2014

AKA dp, dq and qinv.

Should we extend the RSA private key API to include these? Probably both in __init__ as well as getters.

Some probably extremely suspect fors and againsts...

For:

Against:

  • Adds 3 more things to __init__.
  • How do we validate them?
  • Maybe not every RSA implementation actually uses CRT?
  • Not strictly required, (but then we only need p, q, and e anyway.)
@Ivoz
Copy link
Contributor

Ivoz commented Feb 7, 2014

If they're only generated when an RSA private key is instantiated, I don't think it's very slow; certainly not slower than generation of p and q themselves.

code to generate them is just (assuming an implementation of mod_mul_inv)

    phi = (p - 1) * (q - 1)
    # d = pow(e, phi - 1, phi)
    d = mod_mul_inv(e, phi)
    dp = d % (p - 1)
    dq = d % (q - 1)
    # qinv = pow(q, p - 2, p)
    qinv = mod_mul_inv(q, p)
def mod_mul_inv(e, m):
    """ Modular Multiplicative Inverse.
        return the value x such that (x*e) mod m == 1 """
    x1, y1, x2, y2 = 1, 0, 0, 1
    a, b = e, m
    while b > 0:
        q, r = divmod(a, b)
        xn, yn = x1 - q * x2, y1 - q * y2
        a, b, x1, y1, x2, y2 = b, r, x2, y2, xn, yn
    return x1 % m

@public
Copy link
Member Author

public commented Feb 7, 2014

Caching them on the private key object ourselves is indeed an option too. We need some benchmarks :)

@reaperhulk
Copy link
Member

Per discussion in IRC I support adding these values as required parameters to the constructor. We can loosen this restriction in the future if we decide computing these values in Python is permissible/desirable.

@reaperhulk reaperhulk added this to the Second Release milestone Feb 9, 2014
@alex alex closed this as completed Feb 16, 2014
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants