Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src-draft/trunk]: src/sys/opencrypto swcrypto(4): Simplify iv generation log...



details:   https://anonhg.NetBSD.org/src-all/rev/8800139dacba
branches:  trunk
changeset: 934601:8800139dacba
user:      Taylor R Campbell <riastradh%NetBSD.org@localhost>
date:      Sun Jun 14 19:45:18 2020 +0000

description:
swcrypto(4): Simplify iv generation logic with cprng_fast.

diffstat:

 sys/opencrypto/cryptosoft.c |  20 +-------------------
 1 files changed, 1 insertions(+), 19 deletions(-)

diffs (30 lines):

diff -r 213955aeae1a -r 8800139dacba sys/opencrypto/cryptosoft.c
--- a/sys/opencrypto/cryptosoft.c       Sun Jun 14 19:43:32 2020 +0000
+++ b/sys/opencrypto/cryptosoft.c       Sun Jun 14 19:45:18 2020 +0000
@@ -112,25 +112,7 @@
                } else if (exf->reinit) {
                        exf->reinit(sw->sw_kschedule, 0, iv);
                } else {
-                       /* Get random IV */
-                       for (i = 0;
-                           i + sizeof (u_int32_t) <= EALG_MAX_BLOCK_LEN;
-                           i += sizeof (u_int32_t)) {
-                               u_int32_t temp = cprng_fast32();
-
-                               memcpy(iv + i, &temp, sizeof(u_int32_t));
-                       }
-                       /*
-                        * What if the block size is not a multiple
-                        * of sizeof (u_int32_t), which is the size of
-                        * what arc4random() returns ?
-                        */
-                       if (EALG_MAX_BLOCK_LEN % sizeof (u_int32_t) != 0) {
-                               u_int32_t temp = cprng_fast32();
-
-                               bcopy (&temp, iv + i,
-                                   EALG_MAX_BLOCK_LEN - i);
-                       }
+                       cprng_fast(iv, EALG_MAX_BLOCK_LEN);
                }
 
                /* Do we need to write the IV */



Home | Main Index | Thread Index | Old Index