Skip to content

Commit 6e10d74

Browse files
committed
Merge branch 'main' into feat/hashlib/evp-mac-134531
2 parents e92f7cc + 621a8bd commit 6e10d74

File tree

6 files changed

+89
-52
lines changed

6 files changed

+89
-52
lines changed

Modules/_hashopenssl.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ py_hashentry_table_new(void) {
270270
return NULL;
271271
}
272272

273-
/* Module state */
273+
// --- Module state -----------------------------------------------------------
274+
274275
static PyModuleDef _hashlibmodule;
275276

276277
typedef struct {
@@ -295,6 +296,8 @@ get_hashlib_state(PyObject *module)
295296
return (_hashlibstate *)state;
296297
}
297298

299+
// --- Module objects ---------------------------------------------------------
300+
298301
typedef struct {
299302
HASHLIB_OBJECT_HEAD
300303
EVP_MD_CTX *ctx; /* OpenSSL message digest context */
@@ -314,15 +317,17 @@ typedef struct {
314317

315318
#define HMACobject_CAST(op) ((HMACobject *)(op))
316319

317-
#include "clinic/_hashopenssl.c.h"
320+
// --- Module clinic configuration --------------------------------------------
321+
318322
/*[clinic input]
319323
module _hashlib
320-
class _hashlib.HASH "HASHobject *" "((_hashlibstate *)PyModule_GetState(module))->HASH_type"
321-
class _hashlib.HASHXOF "HASHobject *" "((_hashlibstate *)PyModule_GetState(module))->HASHXOF_type"
322-
class _hashlib.HMAC "HMACobject *" "((_hashlibstate *)PyModule_GetState(module))->HMAC_type"
324+
class _hashlib.HASH "HASHobject *" "&PyType_Type"
325+
class _hashlib.HASHXOF "HASHobject *" "&PyType_Type"
326+
class _hashlib.HMAC "HMACobject *" "&PyType_Type"
323327
[clinic start generated code]*/
324-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=eb805ce4b90b1b31]*/
328+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6b5c9ce5c28bdc58]*/
325329

330+
#include "clinic/_hashopenssl.c.h"
326331

327332
/* LCOV_EXCL_START */
328333

Modules/blake2module.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Written in 2013 by Dmitry Chestnykh <dmitry@codingrobots.com>
33
* Modified for CPython by Christian Heimes <christian@python.org>
44
* Updated to use HACL* by Jonathan Protzenko <jonathan@protzenko.fr>
5+
* Additional work by Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
56
*
67
* To the extent possible under law, the author have dedicated all
78
* copyright and related and neighboring rights to this software to
@@ -368,15 +369,18 @@ typedef struct {
368369

369370
#define _Blake2Object_CAST(op) ((Blake2Object *)(op))
370371

371-
#include "clinic/blake2module.c.h"
372+
// --- Module clinic configuration --------------------------------------------
372373

373374
/*[clinic input]
374375
module _blake2
375-
class _blake2.blake2b "Blake2Object *" "&PyBlake2_BLAKE2bType"
376-
class _blake2.blake2s "Blake2Object *" "&PyBlake2_BLAKE2sType"
376+
class _blake2.blake2b "Blake2Object *" "&PyType_Type"
377+
class _blake2.blake2s "Blake2Object *" "&PyType_Type"
377378
[clinic start generated code]*/
378-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b7526666bd18af83]*/
379+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=86b0972b0c41b3d0]*/
380+
381+
#include "clinic/blake2module.c.h"
379382

383+
// --- BLAKE-2 object interface -----------------------------------------------
380384

381385
static Blake2Object *
382386
new_Blake2Object(PyTypeObject *type)

Modules/md5module.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Andrew Kuchling (amk@amk.ca)
99
Greg Stein (gstein@lyra.org)
1010
Trevor Perrin (trevp@trevp.net)
11+
Bénédikt Tran (10796600+picnixz@users.noreply.github.com)
1112
1213
Copyright (C) 2005-2007 Gregory P. Smith (greg@krypto.org)
1314
Licensed to PSF under a Contributor Agreement.
@@ -25,18 +26,14 @@
2526

2627
#include "hashlib.h"
2728

28-
/*[clinic input]
29-
module _md5
30-
class MD5Type "MD5object *" "&PyType_Type"
31-
[clinic start generated code]*/
32-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6e5261719957a912]*/
29+
#include "_hacl/Hacl_Hash_MD5.h"
3330

3431
/* The MD5 block size and message digest sizes, in bytes */
3532

3633
#define MD5_BLOCKSIZE 64
3734
#define MD5_DIGESTSIZE 16
3835

39-
#include "_hacl/Hacl_Hash_MD5.h"
36+
// --- Module objects ---------------------------------------------------------
4037

4138
typedef struct {
4239
HASHLIB_OBJECT_HEAD
@@ -45,8 +42,7 @@ typedef struct {
4542

4643
#define _MD5object_CAST(op) ((MD5object *)(op))
4744

48-
#include "clinic/md5module.c.h"
49-
45+
// --- Module state -----------------------------------------------------------
5046

5147
typedef struct {
5248
PyTypeObject* md5_type;
@@ -60,6 +56,18 @@ md5_get_state(PyObject *module)
6056
return (MD5State *)state;
6157
}
6258

59+
// --- Module clinic configuration --------------------------------------------
60+
61+
/*[clinic input]
62+
module _md5
63+
class MD5Type "MD5object *" "&PyType_Type"
64+
[clinic start generated code]*/
65+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6e5261719957a912]*/
66+
67+
#include "clinic/md5module.c.h"
68+
69+
// --- MD5 object interface ---------------------------------------------------
70+
6371
static MD5object *
6472
newMD5object(MD5State * st)
6573
{

Modules/sha1module.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
Andrew Kuchling (amk@amk.ca)
99
Greg Stein (gstein@lyra.org)
1010
Trevor Perrin (trevp@trevp.net)
11+
Bénédikt Tran (10796600+picnixz@users.noreply.github.com)
1112
1213
Copyright (C) 2005-2007 Gregory P. Smith (greg@krypto.org)
1314
Licensed to PSF under a Contributor Agreement.
1415
1516
*/
1617

17-
/* SHA1 objects */
1818
#ifndef Py_BUILD_CORE_BUILTIN
1919
# define Py_BUILD_CORE_MODULE 1
2020
#endif
@@ -24,18 +24,14 @@
2424
#include "pycore_strhex.h" // _Py_strhex()
2525
#include "pycore_typeobject.h" // _PyType_GetModuleState()
2626

27-
/*[clinic input]
28-
module _sha1
29-
class SHA1Type "SHA1object *" "&PyType_Type"
30-
[clinic start generated code]*/
31-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=3dc9a20d1becb759]*/
27+
#include "_hacl/Hacl_Hash_SHA1.h"
3228

3329
/* The SHA1 block size and message digest sizes, in bytes */
3430

3531
#define SHA1_BLOCKSIZE 64
3632
#define SHA1_DIGESTSIZE 20
3733

38-
#include "_hacl/Hacl_Hash_SHA1.h"
34+
// --- Module objects ---------------------------------------------------------
3935

4036
typedef struct {
4137
HASHLIB_OBJECT_HEAD
@@ -44,8 +40,7 @@ typedef struct {
4440

4541
#define _SHA1object_CAST(op) ((SHA1object *)(op))
4642

47-
#include "clinic/sha1module.c.h"
48-
43+
// --- Module state -----------------------------------------------------------
4944

5045
typedef struct {
5146
PyTypeObject* sha1_type;
@@ -59,6 +54,18 @@ sha1_get_state(PyObject *module)
5954
return (SHA1State *)state;
6055
}
6156

57+
// --- Module clinic configuration --------------------------------------------
58+
59+
/*[clinic input]
60+
module _sha1
61+
class SHA1Type "SHA1object *" "&PyType_Type"
62+
[clinic start generated code]*/
63+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=3dc9a20d1becb759]*/
64+
65+
#include "clinic/sha1module.c.h"
66+
67+
// --- SHA-1 object interface configuration -----------------------------------
68+
6269
static SHA1object *
6370
newSHA1object(SHA1State *st)
6471
{

Modules/sha2module.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,25 @@
99
Greg Stein (gstein@lyra.org)
1010
Trevor Perrin (trevp@trevp.net)
1111
Jonathan Protzenko (jonathan@protzenko.fr)
12+
Bénédikt Tran (10796600+picnixz@users.noreply.github.com)
1213
1314
Copyright (C) 2005-2007 Gregory P. Smith (greg@krypto.org)
1415
Licensed to PSF under a Contributor Agreement.
1516
1617
*/
1718

18-
/* SHA objects */
1919
#ifndef Py_BUILD_CORE_BUILTIN
2020
# define Py_BUILD_CORE_MODULE 1
2121
#endif
2222

2323
#include "Python.h"
24-
#include "pycore_bitutils.h" // _Py_bswap32()
2524
#include "pycore_moduleobject.h" // _PyModule_GetState()
2625
#include "pycore_typeobject.h" // _PyType_GetModuleState()
2726
#include "pycore_strhex.h" // _Py_strhex()
2827

2928
#include "hashlib.h"
3029

31-
/*[clinic input]
32-
module _sha2
33-
class SHA256Type "SHA256object *" "&PyType_Type"
34-
class SHA512Type "SHA512object *" "&PyType_Type"
35-
[clinic start generated code]*/
36-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b5315a7b611c9afc]*/
37-
30+
#include "_hacl/Hacl_Hash_SHA2.h"
3831

3932
/* The SHA block sizes and maximum message digest sizes, in bytes */
4033

@@ -43,9 +36,7 @@ class SHA512Type "SHA512object *" "&PyType_Type"
4336
#define SHA512_BLOCKSIZE 128
4437
#define SHA512_DIGESTSIZE 64
4538

46-
/* Our SHA2 implementations defer to the HACL* verified library. */
47-
48-
#include "_hacl/Hacl_Hash_SHA2.h"
39+
// --- Module objects ---------------------------------------------------------
4940

5041
// TODO: Get rid of int digestsize in favor of Hacl state info?
5142

@@ -64,7 +55,7 @@ typedef struct {
6455
#define _SHA256object_CAST(op) ((SHA256object *)(op))
6556
#define _SHA512object_CAST(op) ((SHA512object *)(op))
6657

67-
#include "clinic/sha2module.c.h"
58+
// --- Module state -----------------------------------------------------------
6859

6960
/* We shall use run-time type information in the remainder of this module to
7061
* tell apart SHA2-224 and SHA2-256 */
@@ -83,6 +74,19 @@ sha2_get_state(PyObject *module)
8374
return (sha2_state *)state;
8475
}
8576

77+
// --- Module clinic configuration --------------------------------------------
78+
79+
/*[clinic input]
80+
module _sha2
81+
class SHA256Type "SHA256object *" "&PyType_Type"
82+
class SHA512Type "SHA512object *" "&PyType_Type"
83+
[clinic start generated code]*/
84+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b5315a7b611c9afc]*/
85+
86+
#include "clinic/sha2module.c.h"
87+
88+
// --- SHA-2 object interface -------------------------------------------------
89+
8690
static int
8791
SHA256copy(SHA256object *src, SHA256object *dest)
8892
{

Modules/sha3module.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Greg Stein (gstein@lyra.org)
1010
* Trevor Perrin (trevp@trevp.net)
1111
* Gregory P. Smith (greg@krypto.org)
12+
* Bénédikt Tran (10796600+picnixz@users.noreply.github.com)
1213
*
1314
* Copyright (C) 2012-2022 Christian Heimes (christian@python.org)
1415
* Licensed to PSF under a Contributor Agreement.
@@ -24,6 +25,8 @@
2425
#include "pycore_typeobject.h" // _PyType_GetModuleState()
2526
#include "hashlib.h"
2627

28+
#include "_hacl/Hacl_Hash_SHA3.h"
29+
2730
/*
2831
* Assert that 'LEN' can be safely casted to uint32_t.
2932
*
@@ -37,6 +40,8 @@
3740

3841
#define SHA3_MAX_DIGESTSIZE 64 /* 64 Bytes (512 Bits) for 224 to 512 */
3942

43+
// --- Module state -----------------------------------------------------------
44+
4045
typedef struct {
4146
PyTypeObject *sha3_224_type;
4247
PyTypeObject *sha3_256_type;
@@ -54,30 +59,34 @@ sha3_get_state(PyObject *module)
5459
return (SHA3State *)state;
5560
}
5661

57-
/*[clinic input]
58-
module _sha3
59-
class _sha3.sha3_224 "SHA3object *" "&SHA3_224typ"
60-
class _sha3.sha3_256 "SHA3object *" "&SHA3_256typ"
61-
class _sha3.sha3_384 "SHA3object *" "&SHA3_384typ"
62-
class _sha3.sha3_512 "SHA3object *" "&SHA3_512typ"
63-
class _sha3.shake_128 "SHA3object *" "&SHAKE128type"
64-
class _sha3.shake_256 "SHA3object *" "&SHAKE256type"
65-
[clinic start generated code]*/
66-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b8a53680f370285a]*/
62+
// --- Module objects ---------------------------------------------------------
6763

6864
/* The structure for storing SHA3 info */
6965

70-
#include "_hacl/Hacl_Hash_SHA3.h"
71-
7266
typedef struct {
7367
HASHLIB_OBJECT_HEAD
7468
Hacl_Hash_SHA3_state_t *hash_state;
7569
} SHA3object;
7670

7771
#define _SHA3object_CAST(op) ((SHA3object *)(op))
7872

73+
// --- Module clinic configuration --------------------------------------------
74+
75+
/*[clinic input]
76+
module _sha3
77+
class _sha3.sha3_224 "SHA3object *" "&PyType_Type"
78+
class _sha3.sha3_256 "SHA3object *" "&PyType_Type"
79+
class _sha3.sha3_384 "SHA3object *" "&PyType_Type"
80+
class _sha3.sha3_512 "SHA3object *" "&PyType_Type"
81+
class _sha3.shake_128 "SHA3object *" "&PyType_Type"
82+
class _sha3.shake_256 "SHA3object *" "&PyType_Type"
83+
[clinic start generated code]*/
84+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=ccd22550c7fb99bf]*/
85+
7986
#include "clinic/sha3module.c.h"
8087

88+
// --- SHA-3 object interface -------------------------------------------------
89+
8190
static SHA3object *
8291
newSHA3object(PyTypeObject *type)
8392
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy