X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
20ce770
Merge branch 'main' into feat/hmac/hacl-99108
picnixz Feb 15, 2025
713fe1b
Merge remote-tracking branch 'upstream/main' into feat/hmac/hacl-99108
picnixz Mar 11, 2025
bc2a2f8
Merge remote-tracking branch 'upstream/main' into feat/hmac/hacl-99108
picnixz Mar 12, 2025
9fc5a71
Merge remote-tracking branch 'upstream/main' into feat/hmac/hacl-99108
picnixz Mar 16, 2025
e88b113
Merge remote-tracking branch 'upstream/main' into feat/hmac/hacl-99108
picnixz Mar 17, 2025
d2e72aa
update vendored HACL* project
picnixz Dec 12, 2024
9fa2b0b
prepare build configurations
picnixz Dec 12, 2024
1f33995
add HMAC module
picnixz Dec 13, 2024
8162616
add HMAC module state
picnixz Dec 13, 2024
02988f0
add HMAC-HASH static information
picnixz Dec 13, 2024
8df0fbf
implement HMAC-HASH known hashes table
picnixz Dec 13, 2024
f541600
add HMAC unknown hash exception type
picnixz Dec 13, 2024
88d2b96
intern `"lower"` for `str.lower` calls
picnixz Dec 13, 2024
77e51d4
implement hash information lookup
picnixz Dec 13, 2024
264e43c
add one-shot HMAC HACL* minimal API
picnixz Dec 13, 2024
c791feb
implement one-shot HMAC
picnixz Dec 13, 2024
6b77844
implement minimal HMAC object interface
picnixz Dec 13, 2024
0770202
implement HMAC simple getters
picnixz Dec 13, 2024
af443c2
implement `HMAC.__repr__()` method
picnixz Dec 12, 2024
4a0e9cd
implement streaming `HMAC.update()` macros
picnixz Dec 12, 2024
2d02577
implement streaming `HMAC.update()` interface
picnixz Dec 12, 2024
2b010ef
implement `HMAC.{digest,hexdigest}()` methods
picnixz Dec 12, 2024
6227892
implement `HMAC.copy()` interface
picnixz Dec 12, 2024
5c13316
add vectorized blake2s/2b kinds
picnixz Dec 12, 2024
617b793
implement `HMAC.new()` interface
picnixz Dec 12, 2024
cc28e3e
update HMAC python interface
picnixz Dec 12, 2024
166e7e8
add blurb & CHANGELOG entries
picnixz Feb 15, 2025
f2817ae
add `hashlib_helper.requires_builtin_hmac`
picnixz Mar 11, 2025
2b544e5
add various tests for the HACL* HMAC implementation
picnixz Mar 11, 2025
b4bfe5e
update comments concerning `int` return values
picnixz Mar 17, 2025
3aae0a8
handle error code returned by `Hacl_Streaming_HMAC_digest`
picnixz Mar 17, 2025
59b365a
Merge remote-tracking branch 'upstream/main' into feat/hmac/hacl-99108
picnixz Mar 18, 2025
c86d51e
summarize HMAC changes in "Improved Modules" as well
picnixz Mar 18, 2025
5fd72f0
force safe downcast to `uint32_t` in `hmac_new_initial_state`
picnixz Mar 18, 2025
da71ef8
`make clinic`
picnixz Mar 18, 2025
5baa874
fix HMAC max block size
picnixz Mar 18, 2025
10e1189
Merge remote-tracking branch 'upstream/main' into feat/hmac/hacl-99108
picnixz Mar 18, 2025
aab2b0b
align naming of one-shot HMAC with OpenSSL
picnixz Mar 18, 2025
da3a3e3
test one-shot HMAC functions
picnixz Mar 18, 2025
b2540ef
remove dubious `eval`
picnixz Mar 19, 2025
e90f685
Merge remote-tracking branch 'upstream/main' into feat/hmac/hacl-99108
picnixz Mar 23, 2025
0b18234
fixup test docstring
picnixz Mar 28, 2025
218015a
remove un-necessary guards
picnixz Mar 28, 2025
d0ca0e5
Merge remote-tracking branch 'upstream/main' into feat/hmac/hacl-99108
picnixz Mar 28, 2025
0ae4a9d
make clinic
picnixz Mar 28, 2025
47a15d6
make regen-sbom
picnixz Mar 28, 2025
f203c6d
fix obvious typo
picnixz Mar 28, 2025
a5fc810
narrow `except` guard
picnixz Mar 29, 2025
b58073d
put `hmac` section before `http` section
picnixz Mar 29, 2025
6f84a82
cosmetic changes in hmac.py
picnixz Apr 1, 2025
de7ad74
group cryptographic primitives modules
picnixz Apr 1, 2025
674af07
better group cryptographic primitives
picnixz Apr 1, 2025
26cfeb0
update naming
picnixz Apr 1, 2025
258aa20
update naming
picnixz Apr 1, 2025
629cbce
Merge branch 'main' into feat/hmac/hacl-99108
picnixz Apr 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
implement HMAC.copy() interface
The internal HACL* state can be agilely copied. Stated otherwise,
this only adds a thin wrapper around `Hacl_Streaming_HMAC_copy`
  • Loading branch information
picnixz committed Mar 17, 2025
commit 6227892259f1d0c887833898e5bf19d6a19b4a93
24 changes: 23 additions & 1 deletion Modules/clinic/hmacmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions Modules/hmacmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,79 @@ has_uint32_t_buffer_length(const Py_buffer *buffer)

// --- HMAC object ------------------------------------------------------------

/*
* Copy HMAC hash information from 'src' to 'out'.
*/
static void
hmac_copy_hinfo(HMACObject *out, const HMACObject *src)
{
assert(src->name != NULL);
out->name = Py_NewRef(src->name);
assert(src->kind != Py_hmac_kind_hash_unknown);
out->kind = src->kind;
assert(src->block_size <= Py_hmac_hash_max_block_size);
out->block_size = src->block_size;
assert(src->digest_size <= Py_hmac_hash_max_digest_size);
out->digest_size = src->digest_size;
assert(src->api.compute != NULL);
assert(src->api.compute_py != NULL);
out->api = src->api;
}

/*
* Copy the HMAC internal state from 'src' to 'out'.
*
* The internal state of 'out' must not already exist.
*
* Return 0 on success and -1 on failure.
*/
static int
hmac_copy_state(HMACObject *out, const HMACObject *src)
{
assert(src->state != NULL);
out->state = Hacl_Streaming_HMAC_copy(src->state);
if (out->state == NULL) {
PyErr_NoMemory();
return -1;
}
return 0;
}

/*[clinic input]
_hmac.HMAC.copy

cls: defining_class

Return a copy ("clone") of the HMAC object.
[clinic start generated code]*/

static PyObject *
_hmac_HMAC_copy_impl(HMACObject *self, PyTypeObject *cls)
/*[clinic end generated code: output=a955bfa55b65b215 input=17b2c0ad0b147e36]*/
{
hmacmodule_state *state = get_hmacmodule_state_by_cls(cls);
HMACObject *copy = PyObject_GC_New(HMACObject, state->hmac_type);
if (copy == NULL) {
return NULL;
}

ENTER_HASHLIB(self);
/* copy hash information */
hmac_copy_hinfo(copy, self);
/* copy internal state */
int rc = hmac_copy_state(copy, self);
LEAVE_HASHLIB(self);

if (rc < 0) {
Py_DECREF(copy);
return NULL;
}

HASHLIB_INIT_MUTEX(copy);
PyObject_GC_Track(copy);
return (PyObject *)copy;
}

/*
* Update the HMAC object with the given buffer.
*
Expand Down Expand Up @@ -806,6 +879,7 @@ HMACObject_traverse(PyObject *op, visitproc visit, void *arg)
}

static PyMethodDef HMACObject_methods[] = {
_HMAC_HMAC_COPY_METHODDEF
_HMAC_HMAC_UPDATE_METHODDEF
_HMAC_HMAC_DIGEST_METHODDEF
_HMAC_HMAC_HEXDIGEST_METHODDEF
Expand Down
X Tutup