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

gh-99108: Import SHA2-224 and SHA2-256 from HACL* #99109

Merged
merged 36 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f941537
Replace SHA2 implementation with verified code from HACL*
msprotz Nov 4, 2022
89712f6
Fixup some casts
msprotz Nov 4, 2022
21fddf1
And proper error handling for maximum hashing lengths exceeded
msprotz Nov 4, 2022
6c5498e
Remove extra file
msprotz Nov 4, 2022
77c682c
See if using srcdir helps
msprotz Nov 4, 2022
1586188
Delete 11 un-needed files
msprotz Nov 7, 2022
621ef0d
Wrong direction for error checking
msprotz Nov 7, 2022
81cac0f
Remove another four files
msprotz Nov 7, 2022
5134c6a
better code quality
msprotz Nov 7, 2022
f212447
Fixup memory management mistake
msprotz Nov 7, 2022
6543fdd
Fix Linux build
msprotz Nov 7, 2022
a52e9ce
Address review comments from @tiran; regenerate configure
msprotz Nov 8, 2022
de35332
Merge remote-tracking branch 'origin/sha2_hacl' into sha2_hacl
msprotz Nov 8, 2022
7f997a9
Move Linux & BSD CFLAGS into configure
msprotz Nov 8, 2022
ec36acb
Add NEWS entry.
msprotz Nov 8, 2022
c5d5e67
SRCDIRS
msprotz Nov 8, 2022
adc0b8b
Properly regenerate configure
msprotz Nov 8, 2022
ca1e02e
Fix paths in Windows build
msprotz Nov 8, 2022
47be718
Add include directory
msprotz Nov 8, 2022
b508177
Fixup include paths
msprotz Nov 8, 2022
e893889
Fix patchcheck
msprotz Nov 9, 2022
1c82dc2
Automate import of HACL* into the tree with a script
msprotz Dec 20, 2022
a632c84
Use newly-implemented copy operation
msprotz Dec 20, 2022
60d87fe
Merge remote-tracking branch 'upstream/main' into sha2_hacl
msprotz Dec 20, 2022
f4b267e
Add a suitable test for data > 4GB
msprotz Dec 20, 2022
537831e
Make more robust & follow shellcheck.
gpshead Jan 31, 2023
f33e2ef
Update to the latest HACL* revision.
gpshead Jan 31, 2023
ce292e7
Add a README to the _hacl directory.
gpshead Jan 31, 2023
aa24fd4
reword and ReSTify the news entry.
gpshead Jan 31, 2023
29fd3c9
Dynamically rename the Hacl_ C symbols.
gpshead Jan 31, 2023
0362c1a
missing file add & readme update.
gpshead Jan 31, 2023
0f33a6a
_
gpshead Jan 31, 2023
d7c1240
remove wrongly placed defines.
gpshead Jan 31, 2023
9ec37a6
Merge branch 'main' into sha2_hacl
gpshead Jan 31, 2023
92033ad
Stylistic fix in Modules/sha256module.c
msprotz Jan 31, 2023
c670530
Fix a warning on Windows builders
msprotz Jan 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/test_hashlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from test.support import _4G, bigmemtest
from test.support.import_helper import import_fresh_module
from test.support import os_helper
from test.support import requires_resource
from test.support import threading_helper
from test.support import warnings_helper
from http.client import HTTPException
Expand Down Expand Up @@ -354,6 +355,15 @@ def test_large_update(self):
self.assertEqual(m1.digest(*args), m4_copy.digest(*args))
self.assertEqual(m4.digest(*args), m4_digest)

@requires_resource('cpu')
def test_sha256_update_over_4gb(self):
zero_1mb = b"\0" * 1024 * 1024
h = hashlib.sha256()
for i in range(0, 4096):
h.update(zero_1mb)
h.update(b"hello world")
self.assertEqual(h.hexdigest(), "a5364f7a52ebe2e25f1838a4ca715a893b6fd7a23f2a0d9e9762120da8b1bf53")

def check(self, name, data, hexdigest, shake=False, **kwargs):
length = len(hexdigest)//2
hexdigest = hexdigest.lower()
Expand Down
2 changes: 1 addition & 1 deletion Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -2612,7 +2612,7 @@ MODULE__HASHLIB_DEPS=$(srcdir)/Modules/hashlib.h
MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h
MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h
MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h
MODULE__SHA256_DEPS=$(srcdir)/Modules/hashlib.h
MODULE__SHA256_DEPS=$(srcdir)/Modules/hashlib.h $(srcdir)/Modules/_hacl/include/krml/FStar_UInt_8_16_32_64.h $(srcdir)/Modules/_hacl/include/krml/lowstar_endianness.h $(srcdir)/Modules/_hacl/include/krml/internal/target.h $(srcdir)/Modules/_hacl/Hacl_Streaming_SHA2.h
MODULE__SHA3_DEPS=$(srcdir)/Modules/_sha3/sha3.c $(srcdir)/Modules/_sha3/sha3.h $(srcdir)/Modules/hashlib.h
MODULE__SHA512_DEPS=$(srcdir)/Modules/hashlib.h
MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h $(srcdir)/Modules/addrinfo.h $(srcdir)/Modules/getaddrinfo.c $(srcdir)/Modules/getnameinfo.c
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Replace the builtin :mod:`hashlib` implementations of SHA2-224 and SHA2-256
originally from LibTomCrypt with formally verified, side-channel resistant
code from the `HACL* <https://github.com/hacl-star/hacl-star/>`_ project. The
builtins remain a fallback only used when OpenSSL does not provide them.
2 changes: 1 addition & 1 deletion Modules/Setup.stdlib.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
# hashing builtins, can be disabled with --without-builtin-hashlib-hashes
@MODULE__MD5_TRUE@_md5 md5module.c
@MODULE__SHA1_TRUE@_sha1 sha1module.c
@MODULE__SHA256_TRUE@_sha256 sha256module.c
@MODULE__SHA256_TRUE@_sha256 sha256module.c _hacl/Hacl_Streaming_SHA2.c
@MODULE__SHA512_TRUE@_sha512 sha512module.c
@MODULE__SHA3_TRUE@_sha3 _sha3/sha3module.c
@MODULE__BLAKE2_TRUE@_blake2 _blake2/blake2module.c _blake2/blake2b_impl.c _blake2/blake2s_impl.c
Expand Down
Loading