Skip to content

Commit 2ec0136

Browse files
committed
fixup hmac constructors
1 parent 6cd9d85 commit 2ec0136

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

mbedtls/hmac.pyx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,45 +70,45 @@ def new(key, buffer=None, digestmod=None):
7070

7171
def md2(key, buffer=None):
7272
"""MD2 message-digest algorithm."""
73-
return Hash(key, buffer, digestmod="md2")
73+
return Hmac(key, "md2", buffer)
7474

7575

7676
def md4(key, buffer=None):
7777
"""MD4 message-digest algorithm."""
78-
return Hash(key, buffer, digestmod="md4")
78+
return Hmac(key, "md4", buffer)
7979

8080

8181
def md5(key, buffer=None):
8282
"""MD5 message-digest algorithm."""
83-
return Hash(key, buffer, digestmod="md5")
83+
return Hmac(key, "md5", buffer)
8484

8585

8686
def sha1(key, buffer=None):
87-
"""Secure Hash Algorithm 1 (SHA-1)."""
88-
return Hash(key, buffer, digestmod="sha1")
87+
"""Secure Hmac Algorithm 1 (SHA-1)."""
88+
return Hmac(key, "sha1", buffer)
8989

9090

9191
def sha224(key, buffer=None):
92-
"""Secure Hash Algorithm 2 (SHA-2) with 224 bits hash value."""
93-
return Hash(key, buffer, digestmod="sha224")
92+
"""Secure Hmac Algorithm 2 (SHA-2) with 224 bits hash value."""
93+
return Hmac(key, "sha224", buffer)
9494

9595

9696
def sha256(key, buffer=None):
97-
"""Secure Hash Algorithm 2 (SHA-2) with 256 bits hash value."""
98-
return Hash(key, buffer, digestmod="sha256")
97+
"""Secure Hmac Algorithm 2 (SHA-2) with 256 bits hash value."""
98+
return Hmac(key, "sha256", buffer)
9999

100100

101101
def sha384(key, buffer=None):
102-
"""Secure Hash Algorithm 2 (SHA-2) with 384 bits hash value."""
103-
return Hash(key, buffer, digestmod="sha384")
102+
"""Secure Hmac Algorithm 2 (SHA-2) with 384 bits hash value."""
103+
return Hmac(key, "sha384", buffer)
104104

105105

106106
def sha512(key, buffer=None):
107-
"""Secure Hash Algorithm 2 (SHA-2) with 512 bits hash value."""
108-
return Hash(key, buffer, digestmod="sha512")
107+
"""Secure Hmac Algorithm 2 (SHA-2) with 512 bits hash value."""
108+
return Hmac(key, "sha512", buffer)
109109

110110

111111
def ripemd160(key, buffer=None):
112112
"""RACE Integrity Primitives Evaluation Message Digest (RIPEMD) with
113113
160 bits hash value."""
114-
return Hash(key, buffer, digestmod="ripemd160")
114+
return Hmac(key, "ripemd160", buffer)

tests/test_md.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def test_check_against_hmac_buf():
127127
yield test
128128

129129

130-
def test_instantiation():
130+
def test_hash_instantiation():
131131
import inspect
132132

133133
def check_instantiation(fun, name):
@@ -139,5 +139,22 @@ def check_instantiation(fun, name):
139139
for name, member in inspect.getmembers(md_hash):
140140
if name in md_hash.algorithms_available:
141141
test = partial(check_instantiation, member, name)
142-
test.description = "check_instantiation(%s)" % name
142+
test.description = "check_hash_instantiation(%s)" % name
143+
yield test
144+
145+
146+
def test_hmac_instantiation():
147+
import inspect
148+
149+
def check_instantiation(fun, name):
150+
key = _rnd(16)
151+
alg1 = fun(key)
152+
alg2 = md_hmac.new(key, digestmod=name)
153+
assert_equal(type(alg1), type(alg2))
154+
assert_equal(alg1.name, alg2.name)
155+
156+
for name, member in inspect.getmembers(md_hmac):
157+
if name in md_hmac.algorithms_available:
158+
test = partial(check_instantiation, member, name)
159+
test.description = "check_hmac_instantiation(%s)" % name
143160
yield test

0 commit comments

Comments
 (0)