Skip to content

Commit 5fd8c57

Browse files
authored
bpo-47098: Replace Keccak Code Package with tiny_sha3 (GH-32060)
1 parent b16b6bb commit 5fd8c57

25 files changed

+346
-5634
lines changed

Doc/whatsnew/3.11.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ hashlib
252252
over Python's vendored copy.
253253
(Contributed by Christian Heimes in :issue:`47095`.)
254254

255+
* The internal ``_sha3`` module with SHA3 and SHAKE algorithms now uses
256+
*tiny_sha3* instead of the *Keccak Code Package* to reduce code and binary
257+
size. The :mod:`hashlib` module prefers optimized SHA3 and SHAKE
258+
implementations from OpenSSL. The change affects only installations without
259+
OpenSSL support.
260+
(Contributed by Christian Heimes in :issue:`47098`.)
261+
255262
IDLE and idlelib
256263
----------------
257264

Makefile.pre.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ coverage-lcov:
667667
'*/Modules/_blake2/impl/*' \
668668
'*/Modules/_ctypes/libffi*/*' \
669669
'*/Modules/_decimal/libmpdec/*' \
670-
'*/Modules/_sha3/kcp/*' \
671670
'*/Modules/expat/*' \
672671
'*/Modules/zlib/*' \
673672
'*/Include/*' \
@@ -2491,7 +2490,7 @@ MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h
24912490
MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h
24922491
MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h
24932492
MODULE__SHA256_DEPS=$(srcdir)/Modules/hashlib.h
2494-
MODULE__SHA3_DEPS=$(srcdir)/Modules/_sha3/kcp/KeccakHash.c $(srcdir)/Modules/_sha3/kcp/KeccakHash.h $(srcdir)/Modules/_sha3/kcp/KeccakP-1600-64.macros $(srcdir)/Modules/_sha3/kcp/KeccakP-1600-SnP-opt32.h $(srcdir)/Modules/_sha3/kcp/KeccakP-1600-SnP-opt64.h $(srcdir)/Modules/_sha3/kcp/KeccakP-1600-SnP.h $(srcdir)/Modules/_sha3/kcp/KeccakP-1600-inplace32BI.c $(srcdir)/Modules/_sha3/kcp/KeccakP-1600-opt64-config.h $(srcdir)/Modules/_sha3/kcp/KeccakP-1600-opt64.c $(srcdir)/Modules/_sha3/kcp/KeccakP-1600-unrolling.macros $(srcdir)/Modules/_sha3/kcp/KeccakSponge.c $(srcdir)/Modules/_sha3/kcp/KeccakSponge.h $(srcdir)/Modules/_sha3/kcp/KeccakSponge.inc $(srcdir)/Modules/_sha3/kcp/PlSnP-Fallback.inc $(srcdir)/Modules/_sha3/kcp/SnP-Relaned.h $(srcdir)/Modules/_sha3/kcp/align.h $(srcdir)/Modules/hashlib.h
2493+
MODULE__SHA3_DEPS=$(srcdir)/Modules/_sha3/sha3.c $(srcdir)/Modules/_sha3/sha3.h $(srcdir)/Modules/hashlib.h
24952494
MODULE__SHA512_DEPS=$(srcdir)/Modules/hashlib.h
24962495
MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h
24972496
MODULE__SSL_DEPS=$(srcdir)/Modules/_ssl.h $(srcdir)/Modules/_ssl/cert.c $(srcdir)/Modules/_ssl/debughelpers.c $(srcdir)/Modules/_ssl/misc.c $(srcdir)/Modules/_ssl_data.h $(srcdir)/Modules/_ssl_data_111.h $(srcdir)/Modules/_ssl_data_300.h $(srcdir)/Modules/socketmodule.h
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The Keccak Code Package for :mod:`hashlib`'s internal ``_sha3`` module has
2+
been replaced with tiny_sha3. The module is used as fallback when Python is
3+
built without OpenSSL.

Modules/_sha3/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Markku-Juhani O. Saarinen
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

Modules/_sha3/README.txt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
Keccak Code Package
2-
===================
1+
tiny_sha3
2+
=========
33

4-
The files in kcp are taken from the Keccak Code Package. They have been
5-
slightly to be C89 compatible. The architecture specific header file
6-
KeccakP-1600-SnP.h ha been renamed to KeccakP-1600-SnP-opt32.h or
7-
KeccakP-1600-SnP-opt64.h.
8-
9-
The 64bit files were generated with generic64lc/libkeccak.a.pack target, the
10-
32bit files with generic32lc/libkeccak.a.pack.
4+
https://github.com/mjosaarinen/tiny_sha3
5+
commit dcbb3192047c2a721f5f851db591871d428036a9
116

7+
- All functions have been converted to static functions.
8+
- sha3() function is commented out.

Modules/_sha3/cleanup.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

Modules/_sha3/kcp/KeccakHash.c

Lines changed: 0 additions & 82 deletions
This file was deleted.

Modules/_sha3/kcp/KeccakHash.h

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)