Save leaf_node and node_offset as character array
authorKurt Roeckx <kurt@roeckx.be>
Fri, 11 Mar 2016 00:06:51 +0000 (01:06 +0100)
committerRich Salz <rsalz@openssl.org>
Fri, 11 Mar 2016 15:39:10 +0000 (10:39 -0500)
They are not numbers in the machine byte order.

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
crypto/blake2/blake2_impl.h
crypto/blake2/blake2b.c
crypto/blake2/blake2s.c
crypto/include/internal/blake2_locl.h

index bd02de9ad2ac52f6637c479782427b086ca7115f..694f9bb434dee0a2e7fadf6c8a554fb98e87f182 100644 (file)
@@ -18,7 +18,7 @@
 #include <string.h>
 #include "e_os.h"
 
-static ossl_inline uint32_t load32(const void *src)
+static ossl_inline uint32_t load32(const uint8_t *src)
 {
     const union {
         long one;
@@ -30,16 +30,15 @@ static ossl_inline uint32_t load32(const void *src)
         memcpy(&w, src, sizeof(w));
         return w;
     } else {
-        const uint8_t *p = (const uint8_t *)src;
-        uint32_t w = *p++;
-        w |= (uint32_t)(*p++) <<  8;
-        w |= (uint32_t)(*p++) << 16;
-        w |= (uint32_t)(*p++) << 24;
+        uint32_t w = *src++;
+        w |= (uint32_t)(*src++) <<  8;
+        w |= (uint32_t)(*src++) << 16;
+        w |= (uint32_t)(*src++) << 24;
         return w;
     }
 }
 
-static ossl_inline uint64_t load64(const void *src)
+static ossl_inline uint64_t load64(const uint8_t *src)
 {
     const union {
         long one;
@@ -51,20 +50,19 @@ static ossl_inline uint64_t load64(const void *src)
         memcpy(&w, src, sizeof(w));
         return w;
     } else {
-        const uint8_t *p = (const uint8_t *)src;
-        uint64_t w = *p++;
-        w |= (uint64_t)(*p++) <<  8;
-        w |= (uint64_t)(*p++) << 16;
-        w |= (uint64_t)(*p++) << 24;
-        w |= (uint64_t)(*p++) << 32;
-        w |= (uint64_t)(*p++) << 40;
-        w |= (uint64_t)(*p++) << 48;
-        w |= (uint64_t)(*p++) << 56;
+        uint64_t w = *src++;
+        w |= (uint64_t)(*src++) <<  8;
+        w |= (uint64_t)(*src++) << 16;
+        w |= (uint64_t)(*src++) << 24;
+        w |= (uint64_t)(*src++) << 32;
+        w |= (uint64_t)(*src++) << 40;
+        w |= (uint64_t)(*src++) << 48;
+        w |= (uint64_t)(*src++) << 56;
         return w;
     }
 }
 
-static ossl_inline void store32(void *dst, uint32_t w)
+static ossl_inline void store32(uint8_t *dst, uint32_t w)
 {
     const union {
         long one;
@@ -82,7 +80,7 @@ static ossl_inline void store32(void *dst, uint32_t w)
     }
 }
 
-static ossl_inline void store64(void *dst, uint64_t w)
+static ossl_inline void store64(uint8_t *dst, uint64_t w)
 {
     const union {
         long one;
@@ -100,19 +98,18 @@ static ossl_inline void store64(void *dst, uint64_t w)
     }
 }
 
-static ossl_inline uint64_t load48(const void *src)
+static ossl_inline uint64_t load48(const uint8_t *src)
 {
-    const uint8_t *p = (const uint8_t *)src;
-    uint64_t w = *p++;
-    w |= (uint64_t)(*p++) <<  8;
-    w |= (uint64_t)(*p++) << 16;
-    w |= (uint64_t)(*p++) << 24;
-    w |= (uint64_t)(*p++) << 32;
-    w |= (uint64_t)(*p++) << 40;
+    uint64_t w = *src++;
+    w |= (uint64_t)(*src++) <<  8;
+    w |= (uint64_t)(*src++) << 16;
+    w |= (uint64_t)(*src++) << 24;
+    w |= (uint64_t)(*src++) << 32;
+    w |= (uint64_t)(*src++) << 40;
     return w;
 }
 
-static ossl_inline void store48(void *dst, uint64_t w)
+static ossl_inline void store48(uint8_t *dst, uint64_t w)
 {
     uint8_t *p = (uint8_t *)dst;
     *p++ = (uint8_t)w;
index d187e6bd21240d77fe8d019da840702b2194718d..621949013a6ee6be0730b86dcb3b237528f92f58 100644 (file)
@@ -95,8 +95,8 @@ int BLAKE2b_Init(BLAKE2B_CTX *c)
     P->key_length    = 0;
     P->fanout        = 1;
     P->depth         = 1;
-    store32(&P->leaf_length, 0);
-    store64(&P->node_offset, 0);
+    store32(P->leaf_length, 0);
+    store64(P->node_offset, 0);
     P->node_depth    = 0;
     P->inner_length  = 0;
     memset(P->reserved, 0, sizeof(P->reserved));
index eee615d9444ad4f215f98d3cc4afb674625549ac..75be06a79e2bd65e0a8aee6e6bb4dd89e2ec21c9 100644 (file)
@@ -70,7 +70,7 @@ static ossl_inline void blake2s_init0(BLAKE2S_CTX *S)
 /* init2 xors IV with input parameter block */
 static void blake2s_init_param(BLAKE2S_CTX *S, const BLAKE2S_PARAM *P)
 {
-    const uint32_t *p = (const uint32_t *)(P);
+    const uint8_t *p = (const uint8_t *)(P);
     size_t i;
 
     /* The param struct is carefully hand packed, and should be 32 bytes on
@@ -79,7 +79,7 @@ static void blake2s_init_param(BLAKE2S_CTX *S, const BLAKE2S_PARAM *P)
     blake2s_init0(S);
     /* IV XOR ParamBlock */
     for(i = 0; i < 8; ++i) {
-        S->h[i] ^= load32(&p[i]);
+        S->h[i] ^= load32(&p[i*4]);
     }
 }
 
@@ -92,8 +92,8 @@ int BLAKE2s_Init(BLAKE2S_CTX *c)
     P->key_length    = 0;
     P->fanout        = 1;
     P->depth         = 1;
-    store32(&P->leaf_length, 0);
-    store48(&P->node_offset, 0);
+    store32(P->leaf_length, 0);
+    store48(P->node_offset, 0);
     P->node_depth    = 0;
     P->inner_length  = 0;
     memset(P->salt,     0, sizeof(P->salt));
index 390065a8b2b04fbb0aef94ba83f2fc2827a76af0..ba438f4e3e76b619939aaa55de544040bba0653b 100644 (file)
@@ -39,7 +39,7 @@ struct blake2s_param_st {
     uint8_t  key_length;    /* 2 */
     uint8_t  fanout;        /* 3 */
     uint8_t  depth;         /* 4 */
-    uint32_t leaf_length;   /* 8 */
+    uint8_t  leaf_length[4];/* 8 */
     uint8_t  node_offset[6];/* 14 */
     uint8_t  node_depth;    /* 15 */
     uint8_t  inner_length;  /* 16 */
@@ -62,8 +62,8 @@ struct blake2b_param_st {
     uint8_t  key_length;    /* 2 */
     uint8_t  fanout;        /* 3 */
     uint8_t  depth;         /* 4 */
-    uint32_t leaf_length;   /* 8 */
-    uint64_t node_offset;   /* 16 */
+    uint8_t  leaf_length[4];/* 8 */
+    uint8_t  node_offset[8];/* 16 */
     uint8_t  node_depth;    /* 17 */
     uint8_t  inner_length;  /* 18 */
     uint8_t  reserved[14];  /* 32 */