summaryrefslogtreecommitdiff
path: root/crypto/rand/drbg_ctr.c
diff options
context:
space:
mode:
authorJung-uk Kim <jkim@FreeBSD.org>2020-04-21 19:07:46 +0000
committerJung-uk Kim <jkim@FreeBSD.org>2020-04-21 19:07:46 +0000
commit65aa3028e51cba07879f3dc4608949c5c6b9fcc0 (patch)
tree310ff0dc688f5f84a478a310752abb888ac68e4e /crypto/rand/drbg_ctr.c
parentb6cfecdc04a5a5e42ae4f2b025d8246cc16f3342 (diff)
downloadsrc-test2-65aa3028e51cba07879f3dc4608949c5c6b9fcc0.tar.gz
src-test2-65aa3028e51cba07879f3dc4608949c5c6b9fcc0.zip
Notes
Diffstat (limited to 'crypto/rand/drbg_ctr.c')
-rw-r--r--crypto/rand/drbg_ctr.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/crypto/rand/drbg_ctr.c b/crypto/rand/drbg_ctr.c
index 93b82f34ceda..0f0ad1b37be4 100644
--- a/crypto/rand/drbg_ctr.c
+++ b/crypto/rand/drbg_ctr.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2018 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -12,28 +12,25 @@
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/rand.h>
-#include "internal/thread_once.h"
+#include "modes_local.h"
#include "internal/thread_once.h"
#include "rand_local.h"
+
/*
* Implementation of NIST SP 800-90A CTR DRBG.
*/
static void inc_128(RAND_DRBG_CTR *ctr)
{
- int i;
- unsigned char c;
- unsigned char *p = &ctr->V[15];
-
- for (i = 0; i < 16; i++, p--) {
- c = *p;
- c++;
- *p = c;
- if (c != 0) {
- /* If we didn't wrap around, we're done. */
- break;
- }
- }
+ unsigned char *p = &ctr->V[0];
+ u32 n = 16, c = 1;
+
+ do {
+ --n;
+ c += p[n];
+ p[n] = (u8)c;
+ c >>= 8;
+ } while (n);
}
static void ctr_XOR(RAND_DRBG_CTR *ctr, const unsigned char *in, size_t inlen)