Skip to content

Commit 0dcc799

Browse files
committed
use 'state' attribute instead of 'hash_state'
1 parent 7b7b1a3 commit 0dcc799

3 files changed

Lines changed: 53 additions & 53 deletions

File tree

Modules/md5module.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class MD5Type "MD5object *" "&PyType_Type"
4040
typedef struct {
4141
PyObject_HEAD
4242
HASHLIB_MUTEX_API
43-
Hacl_Hash_MD5_state_t *hash_state;
43+
Hacl_Hash_MD5_state_t *state;
4444
} MD5object;
4545

4646
#define _MD5object_CAST(op) ((MD5object *)(op))
@@ -85,7 +85,7 @@ static void
8585
MD5_dealloc(PyObject *op)
8686
{
8787
MD5object *ptr = _MD5object_CAST(op);
88-
Hacl_Hash_MD5_free(ptr->hash_state);
88+
Hacl_Hash_MD5_free(ptr->state);
8989
PyTypeObject *tp = Py_TYPE(op);
9090
PyObject_GC_UnTrack(ptr);
9191
PyObject_GC_Del(ptr);
@@ -115,9 +115,9 @@ MD5Type_copy_impl(MD5object *self, PyTypeObject *cls)
115115
}
116116

117117
ENTER_HASHLIB(self);
118-
newobj->hash_state = Hacl_Hash_MD5_copy(self->hash_state);
118+
newobj->state = Hacl_Hash_MD5_copy(self->state);
119119
LEAVE_HASHLIB(self);
120-
if (newobj->hash_state == NULL) {
120+
if (newobj->state == NULL) {
121121
Py_DECREF(newobj);
122122
return PyErr_NoMemory();
123123
}
@@ -136,7 +136,7 @@ MD5Type_digest_impl(MD5object *self)
136136
{
137137
unsigned char digest[MD5_DIGESTSIZE];
138138
ENTER_HASHLIB(self);
139-
Hacl_Hash_MD5_digest(self->hash_state, digest);
139+
Hacl_Hash_MD5_digest(self->state, digest);
140140
LEAVE_HASHLIB(self);
141141
return PyBytes_FromStringAndSize((const char *)digest, MD5_DIGESTSIZE);
142142
}
@@ -153,7 +153,7 @@ MD5Type_hexdigest_impl(MD5object *self)
153153
{
154154
unsigned char digest[MD5_DIGESTSIZE];
155155
ENTER_HASHLIB(self);
156-
Hacl_Hash_MD5_digest(self->hash_state, digest);
156+
Hacl_Hash_MD5_digest(self->state, digest);
157157
LEAVE_HASHLIB(self);
158158

159159
const char *hexdigits = "0123456789abcdef";
@@ -209,11 +209,11 @@ MD5Type_update_impl(MD5object *self, PyObject *obj)
209209
if (self->use_mutex) {
210210
Py_BEGIN_ALLOW_THREADS
211211
PyMutex_Lock(&self->mutex);
212-
update(self->hash_state, buf.buf, buf.len);
212+
update(self->state, buf.buf, buf.len);
213213
PyMutex_Unlock(&self->mutex);
214214
Py_END_ALLOW_THREADS
215215
} else {
216-
update(self->hash_state, buf.buf, buf.len);
216+
update(self->state, buf.buf, buf.len);
217217
}
218218

219219
PyBuffer_Release(&buf);
@@ -307,8 +307,8 @@ _md5_md5_impl(PyObject *module, PyObject *data, int usedforsecurity,
307307
return NULL;
308308
}
309309

310-
new->hash_state = Hacl_Hash_MD5_malloc();
311-
if (new->hash_state == NULL) {
310+
new->state = Hacl_Hash_MD5_malloc();
311+
if (new->state == NULL) {
312312
Py_DECREF(new);
313313
if (string) {
314314
PyBuffer_Release(&buf);
@@ -321,11 +321,11 @@ _md5_md5_impl(PyObject *module, PyObject *data, int usedforsecurity,
321321
/* We do not initialize self->lock here as this is the constructor
322322
* where it is not yet possible to have concurrent access. */
323323
Py_BEGIN_ALLOW_THREADS
324-
update(new->hash_state, buf.buf, buf.len);
324+
update(new->state, buf.buf, buf.len);
325325
Py_END_ALLOW_THREADS
326326
}
327327
else {
328-
update(new->hash_state, buf.buf, buf.len);
328+
update(new->state, buf.buf, buf.len);
329329
}
330330
PyBuffer_Release(&buf);
331331
}

Modules/sha1module.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SHA1Type "SHA1object *" "&PyType_Type"
4040
typedef struct {
4141
PyObject_HEAD
4242
HASHLIB_MUTEX_API
43-
Hacl_Hash_SHA1_state_t *hash_state;
43+
Hacl_Hash_SHA1_state_t *state;
4444
} SHA1object;
4545

4646
#define _SHA1object_CAST(op) ((SHA1object *)(op))
@@ -86,9 +86,9 @@ static void
8686
SHA1_dealloc(PyObject *op)
8787
{
8888
SHA1object *ptr = _SHA1object_CAST(op);
89-
if (ptr->hash_state != NULL) {
90-
Hacl_Hash_SHA1_free(ptr->hash_state);
91-
ptr->hash_state = NULL;
89+
if (ptr->state != NULL) {
90+
Hacl_Hash_SHA1_free(ptr->state);
91+
ptr->state = NULL;
9292
}
9393
PyTypeObject *tp = Py_TYPE(ptr);
9494
PyObject_GC_UnTrack(ptr);
@@ -119,9 +119,9 @@ SHA1Type_copy_impl(SHA1object *self, PyTypeObject *cls)
119119
}
120120

121121
ENTER_HASHLIB(self);
122-
newobj->hash_state = Hacl_Hash_SHA1_copy(self->hash_state);
122+
newobj->state = Hacl_Hash_SHA1_copy(self->state);
123123
LEAVE_HASHLIB(self);
124-
if (newobj->hash_state == NULL) {
124+
if (newobj->state == NULL) {
125125
Py_DECREF(newobj);
126126
return PyErr_NoMemory();
127127
}
@@ -140,7 +140,7 @@ SHA1Type_digest_impl(SHA1object *self)
140140
{
141141
unsigned char digest[SHA1_DIGESTSIZE];
142142
ENTER_HASHLIB(self);
143-
Hacl_Hash_SHA1_digest(self->hash_state, digest);
143+
Hacl_Hash_SHA1_digest(self->state, digest);
144144
LEAVE_HASHLIB(self);
145145
return PyBytes_FromStringAndSize((const char *)digest, SHA1_DIGESTSIZE);
146146
}
@@ -157,7 +157,7 @@ SHA1Type_hexdigest_impl(SHA1object *self)
157157
{
158158
unsigned char digest[SHA1_DIGESTSIZE];
159159
ENTER_HASHLIB(self);
160-
Hacl_Hash_SHA1_digest(self->hash_state, digest);
160+
Hacl_Hash_SHA1_digest(self->state, digest);
161161
LEAVE_HASHLIB(self);
162162
return _Py_strhex((const char *)digest, SHA1_DIGESTSIZE);
163163
}
@@ -204,11 +204,11 @@ SHA1Type_update_impl(SHA1object *self, PyObject *obj)
204204
if (self->use_mutex) {
205205
Py_BEGIN_ALLOW_THREADS
206206
PyMutex_Lock(&self->mutex);
207-
update(self->hash_state, buf.buf, buf.len);
207+
update(self->state, buf.buf, buf.len);
208208
PyMutex_Unlock(&self->mutex);
209209
Py_END_ALLOW_THREADS
210210
} else {
211-
update(self->hash_state, buf.buf, buf.len);
211+
update(self->state, buf.buf, buf.len);
212212
}
213213

214214
PyBuffer_Release(&buf);
@@ -301,9 +301,9 @@ _sha1_sha1_impl(PyObject *module, PyObject *data, int usedforsecurity,
301301
return NULL;
302302
}
303303

304-
new->hash_state = Hacl_Hash_SHA1_malloc();
304+
new->state = Hacl_Hash_SHA1_malloc();
305305

306-
if (new->hash_state == NULL) {
306+
if (new->state == NULL) {
307307
Py_DECREF(new);
308308
if (string) {
309309
PyBuffer_Release(&buf);
@@ -315,11 +315,11 @@ _sha1_sha1_impl(PyObject *module, PyObject *data, int usedforsecurity,
315315
/* We do not initialize self->lock here as this is the constructor
316316
* where it is not yet possible to have concurrent access. */
317317
Py_BEGIN_ALLOW_THREADS
318-
update(new->hash_state, buf.buf, buf.len);
318+
update(new->state, buf.buf, buf.len);
319319
Py_END_ALLOW_THREADS
320320
}
321321
else {
322-
update(new->hash_state, buf.buf, buf.len);
322+
update(new->state, buf.buf, buf.len);
323323
}
324324
PyBuffer_Release(&buf);
325325
}

Modules/sha3module.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class _sha3.shake_256 "SHA3object *" "&SHAKE256type"
6161
typedef struct {
6262
PyObject_HEAD
6363
HASHLIB_MUTEX_API
64-
Hacl_Hash_SHA3_state_t *hash_state;
64+
Hacl_Hash_SHA3_state_t *state;
6565
} SHA3object;
6666

6767
#define _SHA3object_CAST(op) ((SHA3object *)(op))
@@ -132,29 +132,29 @@ py_sha3_new_impl(PyTypeObject *type, PyObject *data_obj, int usedforsecurity,
132132
assert(state != NULL);
133133

134134
if (type == state->sha3_224_type) {
135-
self->hash_state = Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_SHA3_224);
135+
self->state = Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_SHA3_224);
136136
}
137137
else if (type == state->sha3_256_type) {
138-
self->hash_state = Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_SHA3_256);
138+
self->state = Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_SHA3_256);
139139
}
140140
else if (type == state->sha3_384_type) {
141-
self->hash_state = Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_SHA3_384);
141+
self->state = Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_SHA3_384);
142142
}
143143
else if (type == state->sha3_512_type) {
144-
self->hash_state = Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_SHA3_512);
144+
self->state = Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_SHA3_512);
145145
}
146146
else if (type == state->shake_128_type) {
147-
self->hash_state = Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_Shake128);
147+
self->state = Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_Shake128);
148148
}
149149
else if (type == state->shake_256_type) {
150-
self->hash_state = Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_Shake256);
150+
self->state = Hacl_Hash_SHA3_malloc(Spec_Hash_Definitions_Shake256);
151151
}
152152
else {
153153
PyErr_BadInternalCall();
154154
goto error;
155155
}
156156

157-
if (self->hash_state == NULL) {
157+
if (self->state == NULL) {
158158
(void)PyErr_NoMemory();
159159
goto error;
160160
}
@@ -165,11 +165,11 @@ py_sha3_new_impl(PyTypeObject *type, PyObject *data_obj, int usedforsecurity,
165165
/* We do not initialize self->lock here as this is the constructor
166166
* where it is not yet possible to have concurrent access. */
167167
Py_BEGIN_ALLOW_THREADS
168-
sha3_update(self->hash_state, buf.buf, buf.len);
168+
sha3_update(self->state, buf.buf, buf.len);
169169
Py_END_ALLOW_THREADS
170170
}
171171
else {
172-
sha3_update(self->hash_state, buf.buf, buf.len);
172+
sha3_update(self->state, buf.buf, buf.len);
173173
}
174174
}
175175

@@ -194,9 +194,9 @@ static int
194194
SHA3_clear(PyObject *op)
195195
{
196196
SHA3object *self = _SHA3object_CAST(op);
197-
if (self->hash_state != NULL) {
198-
Hacl_Hash_SHA3_free(self->hash_state);
199-
self->hash_state = NULL;
197+
if (self->state != NULL) {
198+
Hacl_Hash_SHA3_free(self->state);
199+
self->state = NULL;
200200
}
201201
return 0;
202202
}
@@ -237,9 +237,9 @@ _sha3_sha3_224_copy_impl(SHA3object *self)
237237
return NULL;
238238
}
239239
ENTER_HASHLIB(self);
240-
newobj->hash_state = Hacl_Hash_SHA3_copy(self->hash_state);
240+
newobj->state = Hacl_Hash_SHA3_copy(self->state);
241241
LEAVE_HASHLIB(self);
242-
if (newobj->hash_state == NULL) {
242+
if (newobj->state == NULL) {
243243
Py_DECREF(newobj);
244244
return PyErr_NoMemory();
245245
}
@@ -261,10 +261,10 @@ _sha3_sha3_224_digest_impl(SHA3object *self)
261261
// This function errors out if the algorithm is SHAKE. Here, we know this
262262
// not to be the case, and therefore do not perform error checking.
263263
ENTER_HASHLIB(self);
264-
(void)Hacl_Hash_SHA3_digest(self->hash_state, digest);
264+
(void)Hacl_Hash_SHA3_digest(self->state, digest);
265265
LEAVE_HASHLIB(self);
266266
return PyBytes_FromStringAndSize((const char *)digest,
267-
Hacl_Hash_SHA3_hash_len(self->hash_state));
267+
Hacl_Hash_SHA3_hash_len(self->state));
268268
}
269269

270270

@@ -280,10 +280,10 @@ _sha3_sha3_224_hexdigest_impl(SHA3object *self)
280280
{
281281
unsigned char digest[SHA3_MAX_DIGESTSIZE];
282282
ENTER_HASHLIB(self);
283-
(void)Hacl_Hash_SHA3_digest(self->hash_state, digest);
283+
(void)Hacl_Hash_SHA3_digest(self->state, digest);
284284
LEAVE_HASHLIB(self);
285285
return _Py_strhex((const char *)digest,
286-
Hacl_Hash_SHA3_hash_len(self->hash_state));
286+
Hacl_Hash_SHA3_hash_len(self->state));
287287
}
288288

289289

@@ -310,11 +310,11 @@ _sha3_sha3_224_update_impl(SHA3object *self, PyObject *data)
310310
if (self->use_mutex) {
311311
Py_BEGIN_ALLOW_THREADS
312312
PyMutex_Lock(&self->mutex);
313-
sha3_update(self->hash_state, buf.buf, buf.len);
313+
sha3_update(self->state, buf.buf, buf.len);
314314
PyMutex_Unlock(&self->mutex);
315315
Py_END_ALLOW_THREADS
316316
} else {
317-
sha3_update(self->hash_state, buf.buf, buf.len);
317+
sha3_update(self->state, buf.buf, buf.len);
318318
}
319319

320320
PyBuffer_Release(&buf);
@@ -335,7 +335,7 @@ static PyObject *
335335
SHA3_get_block_size(PyObject *op, void *Py_UNUSED(closure))
336336
{
337337
SHA3object *self = _SHA3object_CAST(op);
338-
uint32_t rate = Hacl_Hash_SHA3_block_len(self->hash_state);
338+
uint32_t rate = Hacl_Hash_SHA3_block_len(self->state);
339339
return PyLong_FromLong(rate);
340340
}
341341

@@ -372,18 +372,18 @@ SHA3_get_digest_size(PyObject *op, void *Py_UNUSED(closure))
372372
{
373373
// Preserving previous behavior: variable-length algorithms return 0
374374
SHA3object *self = _SHA3object_CAST(op);
375-
if (Hacl_Hash_SHA3_is_shake(self->hash_state))
375+
if (Hacl_Hash_SHA3_is_shake(self->state))
376376
return PyLong_FromLong(0);
377377
else
378-
return PyLong_FromLong(Hacl_Hash_SHA3_hash_len(self->hash_state));
378+
return PyLong_FromLong(Hacl_Hash_SHA3_hash_len(self->state));
379379
}
380380

381381

382382
static PyObject *
383383
SHA3_get_capacity_bits(PyObject *op, void *Py_UNUSED(closure))
384384
{
385385
SHA3object *self = _SHA3object_CAST(op);
386-
uint32_t rate = Hacl_Hash_SHA3_block_len(self->hash_state) * 8;
386+
uint32_t rate = Hacl_Hash_SHA3_block_len(self->state) * 8;
387387
assert(rate <= 1600);
388388
int capacity = 1600 - rate;
389389
return PyLong_FromLong(capacity);
@@ -394,7 +394,7 @@ static PyObject *
394394
SHA3_get_rate_bits(PyObject *op, void *Py_UNUSED(closure))
395395
{
396396
SHA3object *self = _SHA3object_CAST(op);
397-
uint32_t rate = Hacl_Hash_SHA3_block_len(self->hash_state) * 8;
397+
uint32_t rate = Hacl_Hash_SHA3_block_len(self->state) * 8;
398398
return PyLong_FromLong(rate);
399399
}
400400

@@ -491,7 +491,7 @@ _SHAKE_digest(PyObject *op, unsigned long digestlen, int hex)
491491
* - the output length is zero -- we follow the existing behavior and return
492492
* an empty digest, without raising an error */
493493
if (digestlen > 0) {
494-
(void)Hacl_Hash_SHA3_squeeze(self->hash_state, digest, digestlen);
494+
(void)Hacl_Hash_SHA3_squeeze(self->state, digest, digestlen);
495495
}
496496
if (hex) {
497497
result = _Py_strhex((const char *)digest, digestlen);

0 commit comments

Comments
 (0)