Skip to content
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

SHA-512: impl SHA-512/224, SHA-512/256 #98

Merged
merged 6 commits into from
Jan 16, 2024

Conversation

inkydragon
Copy link
Collaborator

@inkydragon inkydragon commented Jan 5, 2024

Close #61

  1. install pip install pycryptodome
  2. gen ref hash values:
python scripts
from Crypto.Hash import SHA512

def sha512(s):
    "Input bytes: b'abc'"
    h = SHA512.new()
    h.update(s)
    return h.hexdigest()

def sha512_224(s):
    h = SHA512.new(truncate="224")
    h.update(s)
    return h.hexdigest()

def sha512_256(s):
    h = SHA512.new(truncate="256")
    h.update(s)
    return h.hexdigest()

funcs = [sha512, sha512_224, sha512_256]
lorem = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
datas = ["", "test", lorem, '\0', 'a'*1000_000]

# [ (f, f(bytes(data, encoding='ASCII'))) for data in datas for f in funcs ]

[ print(f(bytes(data, encoding='ASCII'))) for data in datas for f in [sha512] ]
[ print(f(bytes(data, encoding='ASCII'))) for data in datas for f in [sha512_224] ]
[ print(f(bytes(data, encoding='ASCII'))) for data in datas for f in [sha512_256] ]

Output

>>> [ print(f(bytes(data, encoding='ASCII'))) for data in datas for f in [sha512] ]
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff
f41d92bc9fc1157a0d1387e67f3d0893b70f7039d3d46d8115b5079d45ad601159398c79c281681e2da09bf7d9f8c23b41d1a0a3c5b528a7f2735933a4353194
b8244d028981d693af7b456af8efa4cad63d282e19ff14942c246e50d9351d22704a802a71c3580b6370de4ceb293c324a8423342557d4e5c38438f0e36910ee
e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b
[None, None, None, None, None]
>>> [ print(f(bytes(data, encoding='ASCII'))) for data in datas for f in [sha512_224] ]
6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4
06001bf08dfb17d2b54925116823be230e98b5c6c278303bc4909a8c
3a312b004a593b706790a4a5b25309eb7c83efb85a4d1f0a8440e09e
283bb59af7081ed08197227d8f65b9591ffe1155be43e9550e57f941
37ab331d76f0d36de422bd0edeb22a28accd487b7a8453ae965dd287
[None, None, None, None, None]
>>> [ print(f(bytes(data, encoding='ASCII'))) for data in datas for f in [sha512_256] ]
c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a
3d37fe58435e0d87323dee4a2c1b339ef954de63716ee79f5747f94d974f913f
9423e3863ebb6f22b9464aeb873a39d757ef6b6a87c4bc55642f69052741fc43
10baad1713566ac2333467bddb0597dec9066120dd72ac2dcb8394221dcbe43d
9a59a052930187a97038cae692f30708aa6491923ef5194394dc68d56c74fb21
[None, None, None, None, None]

  • Because of added new APIs, maybe the version number should be increased to V0.8.0 ?

@codecov-commenter
Copy link

codecov-commenter commented Jan 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (068f85d) 98.14% compared to head (11a4c73) 99.79%.
Report is 4 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #98      +/-   ##
==========================================
+ Coverage   98.14%   99.79%   +1.65%     
==========================================
  Files           9        9              
  Lines         484      490       +6     
==========================================
+ Hits          475      489      +14     
+ Misses          9        1       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@inkydragon
Copy link
Collaborator Author

cc @staticfloat , @pixel27

inkydragon

This comment was marked as resolved.

Simplify types.  `Array{T, 1}`  => `Vector{T}`
@inkydragon inkydragon merged commit 4ab324c into JuliaCrypto:master Jan 16, 2024
11 checks passed
@inkydragon inkydragon deleted the sha512-t branch January 16, 2024 02:17
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.

Is there any interest in adding the SHA512/224 and SHA512/256 algorithms?
4 participants