Skip to content

Commit c14c87d

Browse files
committed
simplify HMAC
1 parent 7c6842b commit c14c87d

1 file changed

Lines changed: 5 additions & 24 deletions

File tree

Modules/hmacmodule.c

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -728,29 +728,6 @@ hmac_new_initial_state(HMACObject *self, uint8_t *key, Py_ssize_t len)
728728
return self->state == NULL ? -1 : 0;
729729
}
730730

731-
/*
732-
* Feed initial data.
733-
*
734-
* This function MUST only be called by the HMAC object constructor
735-
* and after hmac_set_hinfo() and hmac_new_initial_state() have been
736-
* called, lest the behaviour is undefined.
737-
*
738-
* Return 0 on success; otherwise, set an exception and return -1 on failure.
739-
*/
740-
static int
741-
hmac_feed_initial_data(HMACObject *self, uint8_t *msg, Py_ssize_t len)
742-
{
743-
assert(self->name != NULL);
744-
assert(self->state != NULL);
745-
int rc = 0;
746-
/* Do not use self->mutex here as this is the constructor
747-
* where it is not yet possible to have concurrent access. */
748-
Py_BEGIN_ALLOW_THREADS
749-
rc = _hacl_hmac_state_update(self->state, msg, len);
750-
Py_END_ALLOW_THREADS
751-
return rc;
752-
}
753-
754731
/*[clinic input]
755732
_hmac.new
756733
@@ -797,7 +774,11 @@ _hmac_new_impl(PyObject *module, PyObject *keyobj, PyObject *msgobj,
797774
if (msgobj != NULL && msgobj != Py_None) {
798775
Py_buffer msg;
799776
GET_BUFFER_VIEW_OR_ERROR(msgobj, &msg, goto error);
800-
rc = hmac_feed_initial_data(self, msg.buf, msg.len);
777+
/* Do not use self->mutex here as this is the constructor
778+
* where it is not yet possible to have concurrent access. */
779+
Py_BEGIN_ALLOW_THREADS
780+
rc = _hacl_hmac_state_update(self->state, msg.buf, msg.len);
781+
Py_END_ALLOW_THREADS
801782
PyBuffer_Release(&msg);
802783
#ifndef NDEBUG
803784
if (rc < 0) {

0 commit comments

Comments
 (0)