Skip to content

Commit

Permalink
md: Add support for MD2 and MD4
Browse files Browse the repository at this point in the history
> low hanging fruits
  • Loading branch information
Synss committed Sep 27, 2019
1 parent 3bcdb93 commit 1825a07
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[next]

* md: Support MD2 and MD4 algo.

[0.18.3]

* setup.py: Refuse to build if mbedtls is too old.
Expand Down
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ information to mbed TLS.
Message digest
--------------

The *mbedtls.hash* module supports MD5, SHA-1, SHA-2 (in 224, 256, 384,
and 512-bits), and RIPEMD-160 secure hashes and message digests.
The *mbedtls.hash* module supports MD2, MD4, MD5, SHA-1, SHA-2
(in 224, 256, 384, and 512-bits), and RIPEMD-160 secure hashes
and message digests. Note that MD2 and MD4 are not included
by default and are only present if they are compiled in mbedtls.

Here are the examples from *hashlib* ported to *python-mbedtls*:

Expand Down
32 changes: 32 additions & 0 deletions tests/test_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ class TestHashMD2(_TestHash):
def algorithm(self):
return md_hash.md2()

@pytest.fixture
def digest_size(self):
return 16

@pytest.fixture
def block_size(self):
return 16


@pytest.mark.skipif(
not mbedtls.has_feature("md4"), reason="requires MD4 support in libmbedtls"
Expand All @@ -101,6 +109,14 @@ class TestHashMD4(_TestHash):
def algorithm(self):
return md_hash.md4()

@pytest.fixture
def digest_size(self):
return 16

@pytest.fixture
def block_size(self):
return 64


@pytest.mark.skipif(
not mbedtls.has_feature("md5"), reason="requires MD5 support in libmbedtls"
Expand Down Expand Up @@ -255,6 +271,14 @@ class TestHmacMD2(_TestHmac):
def algorithm(self, key):
return md_hmac.md2(key)

@pytest.fixture
def digest_size(self):
return 16

@pytest.fixture
def block_size(self):
return 16


@pytest.mark.skipif(
not mbedtls.has_feature("md4"), reason="requires MD4 support in libmbedtls"
Expand All @@ -264,6 +288,14 @@ class TestHmacMD4(_TestHmac):
def algorithm(self, key):
return md_hmac.md4(key)

@pytest.fixture
def digest_size(self):
return 16

@pytest.fixture
def block_size(self):
return 64


@pytest.mark.skipif(
not mbedtls.has_feature("md5"), reason="requires MD5 support in libmbedtls"
Expand Down

0 comments on commit 1825a07

Please sign in to comment.