Skip to content

Commit d18d73f

Browse files
committed
simplify ifdefs: always check for the hacl error
1 parent e81a055 commit d18d73f

2 files changed

Lines changed: 6 additions & 17 deletions

File tree

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
Fix a crash on DEBUG builds when the HACL* routine used by
2-
:meth:`hmac.HMAC.update` fails. This only happens for messages larger
3-
than 4 GiB once the maximum input length of the underlying hash function
4-
is exceeded. Patch by Bénédikt Tran.
1+
Fix the error handling of the HACL* routine used by :func:`hmac.new` and
2+
:meth:`hmac.HMAC.update`. If the maximum input length of the underlying hash
3+
function is exceeded, an :exc:`OverflowError` is now raised on all builds,
4+
instead of crashing on DEBUG builds and being silently ignored otherwise.
5+
Code correctness. Realistically this can only happen at implausible sizes.
6+
Patch by Bénédikt Tran.

‎Modules/hmacmodule.c‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -449,28 +449,19 @@ _hacl_hmac_state_free(HACL_HMAC_state *state)
449449
/*
450450
* Call the HACL* HMAC-HASH update function on the given data.
451451
*
452-
* On DEBUG builds, the update() call is verified.
453-
*
454452
* Return the HACL* exit code. No exception is set, so that this
455453
* can be called without an attached thread state or with a lock held.
456454
*/
457455
static hacl_errno_t
458456
_hacl_hmac_state_update_once(HACL_HMAC_state *state,
459457
uint8_t *buf, uint32_t len)
460458
{
461-
#ifndef NDEBUG
462459
return Hacl_Streaming_HMAC_update(state, buf, len);
463-
#else
464-
(void)Hacl_Streaming_HMAC_update(state, buf, len);
465-
return Hacl_Streaming_Types_Success;
466-
#endif
467460
}
468461

469462
/*
470463
* Perform the HMAC-HASH update() operation in a streaming fashion.
471464
*
472-
* On DEBUG builds, each update() call is verified.
473-
*
474465
* Return the HACL* exit code. No exception is set, so that this
475466
* can be called without an attached thread state or with a lock held.
476467
* Use _hacl_convert_errno() afterwards to set an appropriate exception.
@@ -795,14 +786,10 @@ _hmac_new_impl(PyObject *module, PyObject *keyobj, PyObject *msgobj,
795786
code = _hacl_hmac_state_update(self->state, msg.buf, msg.len)
796787
);
797788
PyBuffer_Release(&msg);
798-
#ifndef NDEBUG
799789
rc = _hacl_convert_errno(code);
800790
if (rc < 0) {
801791
goto error;
802792
}
803-
#else
804-
(void)code;
805-
#endif
806793
}
807794
assert(rc == 0);
808795
return (PyObject *)self;

0 commit comments

Comments
 (0)