|
|
98709d |
commit 0238eb8f3612515f4374381b593dd79116169330
|
|
|
98709d |
Author: John Dennis <jdennis@redhat.com>
|
|
|
98709d |
Date: Thu Aug 2 16:21:33 2018 -0400
|
|
|
98709d |
|
|
|
98709d |
fix concatkdf failures on big endian architectures
|
|
|
98709d |
|
|
|
98709d |
Several of the elements used to compute the digest in ECDH-ES key
|
|
|
98709d |
agreement computation are represented in binary form as a 32-bit
|
|
|
98709d |
integer length followed by that number of octets. the length
|
|
|
98709d |
field. The 32-bit length integer is represented in big endian
|
|
|
98709d |
format (the 8 most significant bits are in the first octet.).
|
|
|
98709d |
|
|
|
98709d |
The conversion to a 4 byte big endian integer was being computed
|
|
|
98709d |
in a manner that only worked on little endian architectures. The
|
|
|
98709d |
function htonl() returns a 32-bit integer whose octet sequence given
|
|
|
98709d |
the address of the integer is big endian. There is no need for any
|
|
|
98709d |
further manipulation.
|
|
|
98709d |
|
|
|
98709d |
The existing code used bit shifting on a 32-bit value. In C bit
|
|
|
98709d |
shifting is endian agnostic for multi-octet values, a right shift
|
|
|
98709d |
moves most significant bits toward least significant bits. The result
|
|
|
98709d |
of a bit shift of a multi-octet value on either big or little
|
|
|
98709d |
archictures will always be the same provided you "view" it as the same
|
|
|
98709d |
data type (e.g. 32-bit integer). But indexing the octets of that
|
|
|
98709d |
mulit-octet value will be different depending on endianness, hence the
|
|
|
98709d |
assembled octets differed depending on endianness.
|
|
|
98709d |
|
|
|
98709d |
Issue: #77
|
|
|
98709d |
Signed-off-by: John Dennis <jdennis@redhat.com>
|
|
|
98709d |
|
|
|
98709d |
diff --git a/src/concatkdf.c b/src/concatkdf.c
|
|
|
98709d |
index ec064ab..59b845a 100644
|
|
|
98709d |
--- a/src/concatkdf.c
|
|
|
98709d |
+++ b/src/concatkdf.c
|
|
|
98709d |
@@ -29,15 +29,9 @@
|
|
|
98709d |
////////////////////////////////////////////////////////////////////////////////
|
|
|
98709d |
static uint8_t *_apply_uint32(const uint32_t value, uint8_t *buffer)
|
|
|
98709d |
{
|
|
|
98709d |
- const uint32_t formatted = htonl(value);
|
|
|
98709d |
- const uint8_t data[4] = {
|
|
|
98709d |
- (formatted >> 0) & 0xff,
|
|
|
98709d |
- (formatted >> 8) & 0xff,
|
|
|
98709d |
- (formatted >> 16) & 0xff,
|
|
|
98709d |
- (formatted >> 24) & 0xff
|
|
|
98709d |
- };
|
|
|
98709d |
- memcpy(buffer, data, 4);
|
|
|
98709d |
+ const uint32_t big_endian_int32 = htonl(value);
|
|
|
98709d |
|
|
|
98709d |
+ memcpy(buffer, &big_endian_int32, 4);
|
|
|
98709d |
return buffer + 4;
|
|
|
98709d |
}
|
|
|
98709d |
|
|
|
98709d |
diff --git a/test/check_concatkdf.c b/test/check_concatkdf.c
|
|
|
98709d |
index e4325fc..41d0f1c 100644
|
|
|
98709d |
--- a/test/check_concatkdf.c
|
|
|
98709d |
+++ b/test/check_concatkdf.c
|
|
|
98709d |
@@ -60,14 +60,9 @@ _create_otherinfo_header_finish:
|
|
|
98709d |
|
|
|
98709d |
static bool _cmp_uint32(uint8_t **actual, uint32_t expected)
|
|
|
98709d |
{
|
|
|
98709d |
- uint32_t value = htonl(expected);
|
|
|
98709d |
- uint8_t expectedData[] = {
|
|
|
98709d |
- (value >> 0) & 0xff,
|
|
|
98709d |
- (value >> 8) & 0xff,
|
|
|
98709d |
- (value >> 16) & 0xff,
|
|
|
98709d |
- (value >> 24) & 0xff
|
|
|
98709d |
- };
|
|
|
98709d |
- bool result = (0 == memcmp(*actual, expectedData, 4));
|
|
|
98709d |
+ uint32_t big_endian_int32 = htonl(expected);
|
|
|
98709d |
+
|
|
|
98709d |
+ bool result = (0 == memcmp(*actual, &big_endian_int32, 4));
|
|
|
98709d |
(*actual) += 4;
|
|
|
98709d |
return result;
|
|
|
98709d |
}
|