[PATCH v2] random-drbg: use bufhelp function for big-endian store
Jussi Kivilinna
jussi.kivilinna at iki.fi
Mon Dec 5 15:44:58 CET 2016
* random/random-drbg.c (drbg_cpu_to_be32): Remove.
(drbg_ctr_df, drbg_hash_df): Use 'buf_put_be32' instead of
'drbg_cpu_to_be32'.
--
Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
0 files changed
diff --git a/random/random-drbg.c b/random/random-drbg.c
index f9d11a3..4d3198e 100644
--- a/random/random-drbg.c
+++ b/random/random-drbg.c
@@ -155,7 +155,7 @@
#include "g10lib.h"
#include "random.h"
#include "rand-internal.h"
-#include "../cipher/bithelp.h"
+#include "../cipher/bufhelp.h"
@@ -533,27 +533,6 @@ drbg_sec_strength (u32 flags)
return 32;
}
-/*
- * Convert an integer into a byte representation of this integer.
- * The byte representation is big-endian
- *
- * @val value to be converted
- * @buf buffer holding the converted integer -- caller must ensure that
- * buffer size is at least 32 bit
- */
-static inline void
-drbg_cpu_to_be32 (u32 val, unsigned char *buf)
-{
- /* FIXME: This may raise a bus error. */
- struct s
- {
- u32 conv;
- };
- struct s *conversion = (struct s *) buf;
-
- conversion->conv = be_bswap32 (val);
-}
-
static void
drbg_add_buf (unsigned char *dst, size_t dstlen,
unsigned char *add, size_t addlen)
@@ -785,10 +764,10 @@ drbg_ctr_df (drbg_state_t drbg, unsigned char *df_data,
/* 10.4.2 step 2 -- calculate the entire length of all input data */
for (; NULL != tempstr; tempstr = tempstr->next)
inputlen += tempstr->len;
- drbg_cpu_to_be32 (inputlen, &L_N[0]);
+ buf_put_be32 (&L_N[0], inputlen);
/* 10.4.2 step 3 */
- drbg_cpu_to_be32 (bytes_to_return, &L_N[4]);
+ buf_put_be32 (&L_N[4], bytes_to_return);
/* 10.4.2 step 5: length is size of L_N, input_string, one byte, padding */
padlen = (inputlen + sizeof (L_N) + 1) % (drbg_blocklen (drbg));
@@ -821,7 +800,7 @@ drbg_ctr_df (drbg_state_t drbg, unsigned char *df_data,
/* 10.4.2 step 9.1 - the padding is implicit as the buffer
* holds zeros after allocation -- even the increment of i
* is irrelevant as the increment remains within length of i */
- drbg_cpu_to_be32 (i, iv);
+ buf_put_be32 (iv, i);
/* 10.4.2 step 9.2 -- BCC and concatenation with temp */
ret = drbg_ctr_bcc (drbg, temp + templen, K, &S1);
if (ret)
@@ -1139,7 +1118,7 @@ drbg_hash_df (drbg_state_t drbg,
/* 10.4.1 step 3 */
input[0] = 1;
- drbg_cpu_to_be32 ((outlen * 8), &input[1]);
+ buf_put_be32 (&input[1], (outlen * 8));
/* 10.4.1 step 4.1 -- concatenation of data for input into hash */
drbg_string_fill (&data1, input, 5);
More information about the Gcrypt-devel
mailing list