diff options
author | Jack O'Connor <oconnor663@gmail.com> | 2017-11-03 19:02:41 (GMT) |
---|---|---|
committer | Christian Heimes <christian@python.org> | 2017-11-03 19:02:41 (GMT) |
commit | dcfb0e3c04f1b29a0d09bb0a81dcd5ee5a5fef1a (patch) | |
tree | 4f160c37de78a47989bdabea0bdb3f3a44330c99 /Modules/_blake2/blake2b_impl.c | |
parent | f6f90ff079a22b79a58d47b6117cc8a8c7d366f3 (diff) | |
download | cpython-dcfb0e3c04f1b29a0d09bb0a81dcd5ee5a5fef1a.zip cpython-dcfb0e3c04f1b29a0d09bb0a81dcd5ee5a5fef1a.tar.gz cpython-dcfb0e3c04f1b29a0d09bb0a81dcd5ee5a5fef1a.tar.bz2 |
bpo-31933: fix blake2 multi-byte params on big endian platforms (#4250)
All Blake2 params have to be encoded in little-endian byte order. For
the two multi-byte integer params, leaf_length and node_offset, that
means that assigning a native-endian integer to them appears to work on
little-endian platforms, but gives the wrong result on big-endian. The
current libb2 API doesn't make that very clear, and @sneves is working
on new API functions in the GH issue above. In the meantime, we can work
around the problem by explicitly assigning little-endian values to the
parameter block.
See https://github.com/BLAKE2/libb2/issues/12.
Diffstat (limited to 'Modules/_blake2/blake2b_impl.c')
-rw-r--r-- | Modules/_blake2/blake2b_impl.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Modules/_blake2/blake2b_impl.c b/Modules/_blake2/blake2b_impl.c index 3c2a035..822b9f2 100644 --- a/Modules/_blake2/blake2b_impl.c +++ b/Modules/_blake2/blake2b_impl.c @@ -162,7 +162,8 @@ py_blake2b_new_impl(PyTypeObject *type, PyObject *data, int digest_size, goto error; } } - self->param.leaf_length = (unsigned int)leaf_size; + // NB: Simple assignment here would be incorrect on big endian platforms. + store32(&(self->param.leaf_length), leaf_size); if (node_offset_obj != NULL) { node_offset = PyLong_AsUnsignedLongLong(node_offset_obj); @@ -178,7 +179,8 @@ py_blake2b_new_impl(PyTypeObject *type, PyObject *data, int digest_size, } store48(&(self->param.node_offset), node_offset); #else - self->param.node_offset = node_offset; + // NB: Simple assignment here would be incorrect on big endian platforms. + store64(&(self->param.node_offset), node_offset); #endif if (node_depth < 0 || node_depth > 255) { |