| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + :mod:`!_blake2`: Ensure that BLAKE-2 objects are correctly initialized | ||
| 2 | + before being tracked by the garbage collector. Patch by Bénédikt Tran. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -388,6 +388,29 @@ new_Blake2Object(PyTypeObject *type) | |||
| 388 | 388 | return NULL; | |
| 389 | 389 | } | |
| 390 | 390 | HASHLIB_INIT_MUTEX(self); | |
| 391 | + self->impl = type_to_impl(type); | ||
| 392 | + // Ensure that the states are NULL-initialized in case of an error. | ||
| 393 | + // See: py_blake2_clear() for more details. | ||
| 394 | + switch (self->impl) { | ||
| 395 | + #if _Py_HACL_CAN_COMPILE_VEC256 | ||
| 396 | + case Blake2b_256: | ||
| 397 | + self->blake2b_256_state = NULL; | ||
| 398 | + break; | ||
| 399 | + #endif | ||
| 400 | + #if _Py_HACL_CAN_COMPILE_VEC128 | ||
| 401 | + case Blake2s_128: | ||
| 402 | + self->blake2s_128_state = NULL; | ||
| 403 | + break; | ||
| 404 | + #endif | ||
| 405 | + case Blake2b: | ||
| 406 | + self->blake2b_state = NULL; | ||
| 407 | + break; | ||
| 408 | + case Blake2s: | ||
| 409 | + self->blake2s_state = NULL; | ||
| 410 | + break; | ||
| 411 | + default: | ||
| 412 | + Py_UNREACHABLE(); | ||
| 413 | + } | ||
| 391 | 414 | ||
| 392 | 415 | PyObject_GC_Track(self); | |
| 393 | 416 | return self; | |
@@ -464,29 +487,6 @@ py_blake2b_or_s_new(PyTypeObject *type, PyObject *data, int digest_size, | |||
| 464 | 487 | goto error; | |
| 465 | 488 | } | |
| 466 | 489 | ||
| 467 | - self->impl = type_to_impl(type); | ||
| 468 | - // Ensure that the states are NULL-initialized in case of an error. | ||
| 469 | - // See: py_blake2_clear() for more details. | ||
| 470 | - switch (self->impl) { | ||
| 471 | - #if _Py_HACL_CAN_COMPILE_VEC256 | ||
| 472 | - case Blake2b_256: | ||
| 473 | - self->blake2b_256_state = NULL; | ||
| 474 | - break; | ||
| 475 | - #endif | ||
| 476 | - #if _Py_HACL_CAN_COMPILE_VEC128 | ||
| 477 | - case Blake2s_128: | ||
| 478 | - self->blake2s_128_state = NULL; | ||
| 479 | - break; | ||
| 480 | - #endif | ||
| 481 | - case Blake2b: | ||
| 482 | - self->blake2b_state = NULL; | ||
| 483 | - break; | ||
| 484 | - case Blake2s: | ||
| 485 | - self->blake2s_state = NULL; | ||
| 486 | - break; | ||
| 487 | - default: | ||
| 488 | - Py_UNREACHABLE(); | ||
| 489 | - } | ||
| 490 | 490 | // Using Blake2b because we statically know that these are greater than the | |
| 491 | 491 | // Blake2s sizes -- this avoids a VLA. | |
| 492 | 492 | uint8_t salt_[HACL_HASH_BLAKE2B_SALT_BYTES] = { 0 }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments