Skip to content

Implement MD5 hash algorithm #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2021
Merged

Implement MD5 hash algorithm #17

merged 1 commit into from
Dec 20, 2021

Conversation

timhawes
Copy link
Contributor

No description provided.

@brentru
Copy link
Member

brentru commented Dec 20, 2021

@timhawes Could you please paste the REPL output after running examples/hashlib_simpletest.py so I can validate against the CPython MD5 algorithm?

@brentru brentru self-requested a review December 20, 2021 14:30
@timhawes
Copy link
Contributor Author

Adafruit CircuitPython 7.0.0 on 2021-09-20; FeatherS2 with ESP32S2
>>> import hashlib_simpletest
--MD5--
Msg Digest: 6a61334a5d9f848bea9affcd82864819
Msg Digest Size: 16
Msg Block Size: 64
--SHA1--
Msg Digest: 62c6e222ccd72f21b8ce0c61f42860d6c70954c0
Msg Digest Size: 20
Msg Block Size: 64
--SHA224--
Msg Digest: 744535a10879be6b18bbcdd135032891346f530a7845d580f7869f36
Msg Digest Size: 28
Msg Block Size: 64
--SHA256--
Msg Digest: 3ce8334ca39e66afb9c37d571da4caad68ab4a8bcbd6d584f75e4268e36c0954
Msg Digest Size: 32
Msg Block Size: 64
--SHA384--
Msg Digest: 7a12f0815f5511b8ba52c67922d1ae86dfd9bfcc4e0799ad89a9f01fc526c8f074ddb5948c06db9893536f2e65c7621b
Msg Digest Size: 48
Msg Block Size: 128
--SHA512--
Msg Digest: 20a88a9b04aa490e457f8980e57331bc85c4d6ca30735a9e502f817e74011a9ece07078e53adf70c232ac91f6c79d4cd6cc69426cd77535645fe9016a71122c2
Msg Digest Size: 64
Msg Block Size: 128
>>>

@timhawes
Copy link
Contributor Author

I've also passed the following tests on CircuitPython and CPython (with the import line changed as required):

from hashlib import md5

# RFC1321 test suite
assert md5(b"").hexdigest() == "d41d8cd98f00b204e9800998ecf8427e"
assert md5(b"a").hexdigest() == "0cc175b9c0f1b6a831c399e269772661"
assert md5(b"abc").hexdigest() == "900150983cd24fb0d6963f7d28e17f72"
assert md5(b"message digest").hexdigest() == "f96b697d7cb7938d525a2f31aaf161d0"
assert md5(b"abcdefghijklmnopqrstuvwxyz").hexdigest() == "c3fcd3d76192e4007dfb496cca67e13b"
assert md5(b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789").hexdigest() == "d174ab98d277d9f5a5611c2c9f419d9f"
assert md5(b"12345678901234567890123456789012345678901234567890123456789012345678901234567890").hexdigest() == "57edf4a22be3c955ac49da2e2107b67a"

# Functional tests
m = md5(b"one")
m.update(b"two")
m.update(b"three")
assert m.digest() == b"{\x03\x91\xfe\xb2\xe0\xcd'\x1f\x1c\xf3\x9a\xaf\xb47o"
assert m.hexdigest() == "7b0391feb2e0cd271f1cf39aafb4376f"
m2 = m.copy()
m.update(b"four")
m2.update(b"five")
assert m.hexdigest() == "645c7d7c377538df94ecd9335cab6bd3"
assert m2.hexdigest() == "f9dc7c7491eb84ed61909eb383800085"

print("ok")

Copy link
Member

@brentru brentru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for providing test results!

@brentru brentru merged commit a3487f5 into adafruit:main Dec 20, 2021
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Dec 28, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_HT16K33 to 4.1.8 from 4.1.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_HT16K33#80 from Daviey/moar_lolz
  > update rtd py version

Updating https://github.com/adafruit/Adafruit_CircuitPython_RA8875 to 3.1.8 from 3.1.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_RA8875#28 from adafruit/dhalbert-ustruct
  > update rtd py version

Updating https://github.com/adafruit/Adafruit_CircuitPython_SI5351 to 1.2.10 from 1.2.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_SI5351#24 from adafruit/dhalbert-ustruct
  > update rtd py version

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_BroadcastNet to 0.11.0 from 0.10.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE_BroadcastNet#23 from tekktrik/feature/add-sound-level
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE_BroadcastNet#22 from tekktrik/feature/add-typing
  > update rtd py version

Updating https://github.com/adafruit/Adafruit_CircuitPython_BluefruitConnect to 1.2.0 from 1.1.10:
  > Merge pull request adafruit/Adafruit_CircuitPython_BluefruitConnect#33 from TonyLHansen/main
  > update rtd py version

Updating https://github.com/adafruit/Adafruit_CircuitPython_BoardTest to 1.2.8 from 1.2.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_BoardTest#19 from tekktrik/feature/add-typing
  > update rtd py version

Updating https://github.com/adafruit/Adafruit_CircuitPython_CursorControl to 2.5.1 from 2.5.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_CursorControl#30 from tekktrik/feature/add-typing
  > update rtd py version

Updating https://github.com/adafruit/Adafruit_CircuitPython_hashlib to 1.4.0 from 1.3.6:
  > Update README.rst
  > Merge pull request adafruit/Adafruit_CircuitPython_hashlib#17 from timhawes/main
  > update rtd py version

Updating https://github.com/adafruit/Adafruit_CircuitPython_Motor to 3.3.3 from 3.3.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_Motor#59 from FoamyGuy/typing_input_error_catch

Updating https://github.com/adafruit/Adafruit_CircuitPython_Register to 1.9.7 from 1.9.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_Register#46 from adafruit/dhalbert-ustruct
  > update rtd py version

Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.10.3 from 1.10.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#87 from tekktrik/main
  > update rtd py version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants