You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Probable bug in the crypto/rsa package. GenerateKey is declaring new errs
which override the return value ones. Caller function gets a nil error in
the top scope because the lower scoped error is not bound to the
return.
What steps will reproduce the problem?
1. generate a rsa private key (let's call it priv)
2. priv.Validate() or any attempt to print fields from priv results in a crash
What is your $GOOS? $GOARCH?
$ echo $GOOS $GOARCH
linux 386
Which revision are you using? (hg identify)
$ hg log -l 1
changeset: 4108:d1b75410b793
tag: tip
user: Adam Langley <agl@golang.org>
date: Tue Nov 17 18:21:47 2009 -0800
Please provide any additional information below.
Modifying the GenerateKey function as follows properly returns a EOF error
to the caller. (Thanks to Noah Evans for figuring out the issue!)
----
// GenerateKeyPair generates an RSA keypair of the given bit size.
func GenerateKey(rand io.Reader, bits int) (priv *PrivateKey, err os.Error) {
priv = new(PrivateKey);
// Smaller public exponents lead to faster public key
// operations. Since the exponent must be coprime to
// (p-1)(q-1), the smallest possible value is 3. Some have
// suggested that a larger exponent (often 2**16+1) be used
// since previous implementation bugs[1] were avoided when this
// was the case. However, there are no current reasons not to use
// small exponents.
// [1] http://marc.info/?l=cryptography&;m=115694833312008&w=2
priv.E = 3;
pminus1 := new(big.Int);
qminus1 := new(big.Int);
totient := new(big.Int);
for {
var p, q *big.Int; // line changed from original
p, err = randomSafePrime(rand, bits/2);
if err != nil {
return
}
q, err = randomSafePrime(rand, bits/2);
if err != nil {
return
}
if p.Cmp(q) == 0 {
continue
}
n := new(big.Int).Mul(p, q);
pminus1.Sub(p, bigOne);
qminus1.Sub(q, bigOne);
totient.Mul(pminus1, qminus1);
g := new(big.Int);
priv.D = new(big.Int);
y := new(big.Int);
e := big.NewInt(int64(priv.E));
big.GcdInt(g, priv.D, y, e, totient);
if g.Cmp(bigOne) == 0 {
priv.D.Add(priv.D, totient);
priv.P = p;
priv.Q = q;
priv.N = n;
break;
}
}
return;
}
----
The text was updated successfully, but these errors were encountered:
by fabio.pianese:
The text was updated successfully, but these errors were encountered: