summaryrefslogtreecommitdiff
path: root/src/pkg/crypto/rsa/rsa.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2010-05-03 18:48:05 -0700
committerRobert Griesemer <gri@golang.org>2010-05-03 18:48:05 -0700
commit8100a94c4a2b2bf1ac99d13aaaf5d6fcaa663d32 (patch)
tree3ee2c6961586d01143436c28521c2ea8e4e8806a /src/pkg/crypto/rsa/rsa.go
parent412ab4139d09839f351245f09749efe342c45c94 (diff)
downloadgolang-8100a94c4a2b2bf1ac99d13aaaf5d6fcaa663d32.tar.gz
big: completed set of Int division routines & cleanups
- renamed Len -> BitLen, simplified implementation - renamed old Div, Mod, DivMod -> Que, Rem, QuoRem - implemented Div, Mod, DivMod (Euclidian definition, more useful in a mathematical context) - fixed a bug in Exp (-0 was possible) - added extra tests to check normalized results everywhere - uniformly set Int.neg flag at the end of computations - minor cosmetic cleanups - ran all tests R=rsc CC=golang-dev http://codereview.appspot.com/1091041
Diffstat (limited to 'src/pkg/crypto/rsa/rsa.go')
-rw-r--r--src/pkg/crypto/rsa/rsa.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/pkg/crypto/rsa/rsa.go b/src/pkg/crypto/rsa/rsa.go
index 941b061b5..c7a8d2053 100644
--- a/src/pkg/crypto/rsa/rsa.go
+++ b/src/pkg/crypto/rsa/rsa.go
@@ -50,11 +50,11 @@ func randomPrime(rand io.Reader, bits int) (p *big.Int, err os.Error) {
// randomNumber returns a uniform random value in [0, max).
func randomNumber(rand io.Reader, max *big.Int) (n *big.Int, err os.Error) {
- k := (max.Len() + 7) / 8
+ k := (max.BitLen() + 7) / 8
// r is the number of bits in the used in the most significant byte of
// max.
- r := uint(max.Len() % 8)
+ r := uint(max.BitLen() % 8)
if r == 0 {
r = 8
}
@@ -244,7 +244,7 @@ func encrypt(c *big.Int, pub *PublicKey, m *big.Int) *big.Int {
// twice the hash length plus 2.
func EncryptOAEP(hash hash.Hash, rand io.Reader, pub *PublicKey, msg []byte, label []byte) (out []byte, err os.Error) {
hash.Reset()
- k := (pub.N.Len() + 7) / 8
+ k := (pub.N.BitLen() + 7) / 8
if len(msg) > k-2*hash.Size()-2 {
err = MessageTooLongError{}
return
@@ -365,7 +365,7 @@ func decrypt(rand io.Reader, priv *PrivateKey, c *big.Int) (m *big.Int, err os.E
// DecryptOAEP decrypts ciphertext using RSA-OAEP.
// If rand != nil, DecryptOAEP uses RSA blinding to avoid timing side-channel attacks.
func DecryptOAEP(hash hash.Hash, rand io.Reader, priv *PrivateKey, ciphertext []byte, label []byte) (msg []byte, err os.Error) {
- k := (priv.N.Len() + 7) / 8
+ k := (priv.N.BitLen() + 7) / 8
if len(ciphertext) > k ||
k < hash.Size()*2+2 {
err = DecryptionError{}