From aa217583ee9d1049995b4ca219d3336d449b811a Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Wed, 12 Oct 2022 14:14:30 +0800 Subject: [PATCH] Update hash_drbg.c --- src/hash_drbg.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/hash_drbg.c b/src/hash_drbg.c index 4d248807..ea06bcfe 100644 --- a/src/hash_drbg.c +++ b/src/hash_drbg.c @@ -175,10 +175,9 @@ end: static void drbg_add(uint8_t *R, const uint8_t *A, size_t seedlen) { int temp = 0; - int i; - for (i = seedlen - 1; i >= 0; i--) { - temp += R[i] + A[i]; - R[i] = temp & 0xff; + while (seedlen--) { + temp += R[seedlen] + A[seedlen]; + R[seedlen] = temp & 0xff; temp >>= 8; } } @@ -186,10 +185,9 @@ static void drbg_add(uint8_t *R, const uint8_t *A, size_t seedlen) static void drbg_add1(uint8_t *R, size_t seedlen) { int temp = 1; - int i; - for (i = seedlen - 1; i >= 0; i--) { - temp += R[i]; - R[i] = temp & 0xff; + while (seedlen--) { + temp += R[seedlen]; + R[seedlen] = temp & 0xff; temp >>= 8; } }