Permalink
Browse files

Rename SIGSIZE to DIGESTSIZE and add some comments on Key properties.

  • Loading branch information...
1 parent dedd465 commit 180a0a9aa0f2ce4e09c4268000c197b83c4a42ab @rfk rfk committed with almet Jul 31, 2012
Showing with 21 additions and 12 deletions.
  1. +3 −1 CHANGES.txt
  2. +11 −4 browserid/crypto/fallback.py
  3. +1 −1 browserid/crypto/m2.py
  4. +3 −3 browserid/jwt.py
  5. +3 −3 browserid/tests/test_jwt.py
View
@@ -2,7 +2,9 @@
==================
* Correct the pure-python RSA implementation. Unfortunately this
- requires a small backwards-incompatible API change on RSKey objects.
+ requires a small backwards-incompatible API change on RSKey objects
+ (the SIZE property is now DIGESTSIZE and it gives the size of the
+ internal hex digest string in bytes)
0.7.0 - 2012-07-26
==================
@@ -53,11 +53,16 @@ def sign(self, data):
class RSKey(Key):
"""Generic base class for RSA key objects.
- Concrete subclasses should provide the SIGSIZE, HASHNAME and HASHMOD
+ Concrete subclasses should provide the DIGESTSIZE, HASHNAME and HASHMOD
attributes.
"""
- SIGSIZE = None
+ # The size of the internal hex digest, in bytes.
+ # This must equal the bit-length of the modulus "n" divided by 4.
+ # The digest gets padded to this size to ensure that, when converted to
+ # an integer, it will be of a similar magnitude to the modulus.
+ DIGESTSIZE = None
+ # The name and hashlib module to use for calculating the digest.
HASHNAME = None
HASHMOD = None
@@ -74,7 +79,7 @@ def verify(self, signed_data, signature):
n, e = self.n, self.e
m = long(signature.encode("hex"), 16)
c = pow(m, e, n)
- padded_digest = hex(c)[2:].rstrip("L").rjust(self.SIGSIZE, "0")
+ padded_digest = hex(c)[2:].rstrip("L").rjust(self.DIGESTSIZE, "0")
return padded_digest == self._get_digest(signed_data)
def sign(self, data):
@@ -88,7 +93,7 @@ def sign(self, data):
def _get_digest(self, data):
digest = self.HASHMOD(data).hexdigest()
padded_digest = "00" + RSA_DIGESTINFO_HEADER[self.HASHNAME] + digest
- padding_len = (self.SIGSIZE) - 4 - len(padded_digest)
+ padding_len = (self.DIGESTSIZE) - 4 - len(padded_digest)
padded_digest = "0001" + ("f" * padding_len) + padded_digest
return padded_digest
@@ -99,7 +104,9 @@ class DSKey(Key):
Concrete subclasses should provide the BITLENGTH and HASHMOD attributes.
"""
+ # The length of the signature to be produced, in bits.
BITLENGTH = None
+ # The hashlib module used to calculate the digest.
HASHMOD = None
def __init__(self, data):
@@ -67,7 +67,7 @@ def sign(self, data):
class RSKey(Key):
KEY_MODULE = _RSA
- SIZE = None
+ DIGESTSIZE = None
HASHNAME = None
HASHMOD = None
View
@@ -72,19 +72,19 @@ def load_key(algorithm, key_data):
class RS64Key(RSKey):
- SIGSIZE = 256
+ DIGESTSIZE = 256
HASHNAME = "sha256"
HASHMOD = hashlib.sha256
class RS128Key(RSKey):
- SIGSIZE = 320
+ DIGESTSIZE = 320
HASHNAME = "sha256"
HASHMOD = hashlib.sha256
class RS256Key(RSKey):
- SIGSIZE = 512
+ DIGESTSIZE = 512
HASHNAME = "sha256"
HASHMOD = hashlib.sha256
@@ -17,19 +17,19 @@
class FALLBACK_RS64Key(browserid.crypto.fallback.RSKey):
- SIGSIZE = jwt.RS64Key.SIGSIZE
+ DIGESTSIZE = jwt.RS64Key.DIGESTSIZE
HASHNAME = jwt.RS64Key.HASHNAME
HASHMOD = jwt.RS64Key.HASHMOD
class FALLBACK_RS128Key(browserid.crypto.fallback.RSKey):
- SIGSIZE = jwt.RS128Key.SIGSIZE
+ DIGESTSIZE = jwt.RS128Key.DIGESTSIZE
HASHNAME = jwt.RS128Key.HASHNAME
HASHMOD = jwt.RS128Key.HASHMOD
class FALLBACK_RS256Key(browserid.crypto.fallback.RSKey):
- SIGSIZE = jwt.RS256Key.SIGSIZE
+ DIGESTSIZE = jwt.RS256Key.DIGESTSIZE
HASHNAME = jwt.RS256Key.HASHNAME
HASHMOD = jwt.RS256Key.HASHMOD

0 comments on commit 180a0a9

Please sign in to comment.