Blame SOURCES/concatkdf.patch

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