| 1 | """HMAC (Keyed-Hashing for Message Authentication) Python module.
|
|---|
| 2 |
|
|---|
| 3 | Implements the HMAC algorithm as described by RFC 2104.
|
|---|
| 4 | """
|
|---|
| 5 |
|
|---|
| 6 | def _strxor(s1, s2):
|
|---|
| 7 | """Utility method. XOR the two strings s1 and s2 (must have same length).
|
|---|
| 8 | """
|
|---|
| 9 | return "".join(map(lambda x, y: chr(ord(x) ^ ord(y)), s1, s2))
|
|---|
| 10 |
|
|---|
| 11 | # The size of the digests returned by HMAC depends on the underlying
|
|---|
| 12 | # hashing module used.
|
|---|
| 13 | digest_size = None
|
|---|
| 14 |
|
|---|
| 15 | # A unique object passed by HMAC.copy() to the HMAC constructor, in order
|
|---|
| 16 | # that the latter return very quickly. HMAC("") in contrast is quite
|
|---|
| 17 | # expensive.
|
|---|
| 18 | _secret_backdoor_key = []
|
|---|
| 19 |
|
|---|
| 20 | class HMAC:
|
|---|
| 21 | """RFC2104 HMAC class.
|
|---|
| 22 |
|
|---|
|
|---|