Module Name: src
Committed By: riastradh
Date: Sun Jun 14 23:23:55 UTC 2020
Modified Files:
src/sys/opencrypto: cryptosoft.c
Log Message:
swcrypto(4): Simplify iv generation logic with cprng_fast.
To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/opencrypto/cryptosoft.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/opencrypto/cryptosoft.c
diff -u src/sys/opencrypto/cryptosoft.c:1.54 src/sys/opencrypto/cryptosoft.c:1.55
--- src/sys/opencrypto/cryptosoft.c:1.54 Sat Oct 12 00:49:30 2019
+++ src/sys/opencrypto/cryptosoft.c Sun Jun 14 23:23:55 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cryptosoft.c,v 1.54 2019/10/12 00:49:30 christos Exp $ */
+/* $NetBSD: cryptosoft.c,v 1.55 2020/06/14 23:23:55 riastradh Exp $ */
/* $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $ */
/* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */
@@ -24,7 +24,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.54 2019/10/12 00:49:30 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.55 2020/06/14 23:23:55 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -112,25 +112,7 @@ swcr_encdec(struct cryptodesc *crd, cons
} 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 */