CVS commit: src/sys/crypto/nist_hash_drbg

2019-09-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Sep 19 18:29:55 UTC 2019

Modified Files:
src/sys/crypto/nist_hash_drbg: nist_hash_drbg.c

Log Message:
Use an explicit run-time assertion where compile-time doesn't work.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.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/crypto/nist_hash_drbg/nist_hash_drbg.c
diff -u src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c:1.2 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c:1.3
--- src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c:1.2	Thu Sep 19 14:34:59 2019
+++ src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c	Thu Sep 19 18:29:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: nist_hash_drbg.c,v 1.2 2019/09/19 14:34:59 riastradh Exp $	*/
+/*	$NetBSD: nist_hash_drbg.c,v 1.3 2019/09/19 18:29:55 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nist_hash_drbg.c,v 1.2 2019/09/19 14:34:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nist_hash_drbg.c,v 1.3 2019/09/19 18:29:55 riastradh Exp $");
 #endif
 
 #include 
@@ -1009,10 +1009,6 @@ static const struct {
 #define	CHECK(i, name, actual, expected, n) do  \
 {	  \
 	CTASSERT(sizeof(actual) == (n));  \
-	CTASSERT(__builtin_constant_p(n) ? sizeof(actual) == (n) : 1);	  \
-	ASSERT(__builtin_constant_p(n) ? 1 : sizeof(actual) >= (n));	  \
-	CTASSERT(__builtin_constant_p(n) ? sizeof(expected) == (n) : 1);  \
-	ASSERT(__builtin_constant_p(n) ? 1 : sizeof(expected) >= (n));	  \
 	ok &= check(i, name, actual, expected, (n));			  \
 } while (0)
 
@@ -1091,7 +1087,9 @@ nist_hash_drbg_initialize(void)
 			kat[i].reseed ? 0 : kat[i].additional[0]->hv_len);
 			reseed_counter++;
 			CHECK(i, "V[1]", D->V, kat[i].V[1], SEEDLEN_BYTES);
-			CHECK(i, "rnd_val[0]", rnd_val, kat[i].rnd_val[0],
+			ASSERT(sizeof(kat[i].rnd_val[0]) - trunc <=
+			sizeof rnd_val);
+			check(i, "rnd_val[0]", rnd_val, kat[i].rnd_val[0],
 			sizeof(kat[i].rnd_val[0]) - trunc);
 			if (D->reseed_counter != reseed_counter) {
 DPRINTF("bad reseed counter: %u, expected %u",
@@ -1113,7 +,9 @@ nist_hash_drbg_initialize(void)
 			kat[i].reseed ? 0 : kat[i].additional[1]->hv_len);
 			reseed_counter++;
 			CHECK(i, "V[2]", D->V, kat[i].V[2], SEEDLEN_BYTES);
-			CHECK(i, "rnd_val[1]", rnd_val, kat[i].rnd_val[1],
+			ASSERT(sizeof(kat[i].rnd_val[1]) - trunc <=
+			sizeof rnd_val);
+			check(i, "rnd_val[1]", rnd_val, kat[i].rnd_val[1],
 			sizeof(kat[i].rnd_val[1]) - trunc);
 			if (D->reseed_counter != reseed_counter) {
 DPRINTF("bad reseed counter: %u, expected %u",



CVS commit: src/sys/crypto/nist_hash_drbg

2019-09-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Sep 19 18:29:55 UTC 2019

Modified Files:
src/sys/crypto/nist_hash_drbg: nist_hash_drbg.c

Log Message:
Use an explicit run-time assertion where compile-time doesn't work.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys/crypto/nist_hash_drbg

2019-09-19 Thread Kamil Rytarowski
On 19.09.2019 16:35, Taylor R Campbell wrote:
> Module Name:  src
> Committed By: riastradh
> Date: Thu Sep 19 14:35:00 UTC 2019
> 
> Modified Files:
>   src/sys/crypto/nist_hash_drbg: nist_hash_drbg.c
> 
> Log Message:
> Use CTASSERT where possible, run-time assertion where not.
> 
> Should fix negative-length variable-length array found by kamil.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c
> 
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.
> 

Unfortunately this still breaks with new __CTASSERT proposed in:

http://netbsd.org/~kamil/patch-00150-__CTASSERT1-bitfield.txt



signature.asc
Description: OpenPGP digital signature


CVS commit: src/sys/crypto/nist_hash_drbg

2019-09-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Sep 19 14:35:00 UTC 2019

Modified Files:
src/sys/crypto/nist_hash_drbg: nist_hash_drbg.c

Log Message:
Use CTASSERT where possible, run-time assertion where not.

Should fix negative-length variable-length array found by kamil.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/crypto/nist_hash_drbg

2019-09-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Sep 19 14:35:00 UTC 2019

Modified Files:
src/sys/crypto/nist_hash_drbg: nist_hash_drbg.c

Log Message:
Use CTASSERT where possible, run-time assertion where not.

Should fix negative-length variable-length array found by kamil.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.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/crypto/nist_hash_drbg/nist_hash_drbg.c
diff -u src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c:1.1 src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c:1.2
--- src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c:1.1	Mon Sep  2 20:09:29 2019
+++ src/sys/crypto/nist_hash_drbg/nist_hash_drbg.c	Thu Sep 19 14:34:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: nist_hash_drbg.c,v 1.1 2019/09/02 20:09:29 riastradh Exp $	*/
+/*	$NetBSD: nist_hash_drbg.c,v 1.2 2019/09/19 14:34:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nist_hash_drbg.c,v 1.1 2019/09/02 20:09:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nist_hash_drbg.c,v 1.2 2019/09/19 14:34:59 riastradh Exp $");
 #endif
 
 #include 
@@ -1009,6 +1009,10 @@ static const struct {
 #define	CHECK(i, name, actual, expected, n) do  \
 {	  \
 	CTASSERT(sizeof(actual) == (n));  \
+	CTASSERT(__builtin_constant_p(n) ? sizeof(actual) == (n) : 1);	  \
+	ASSERT(__builtin_constant_p(n) ? 1 : sizeof(actual) >= (n));	  \
+	CTASSERT(__builtin_constant_p(n) ? sizeof(expected) == (n) : 1);  \
+	ASSERT(__builtin_constant_p(n) ? 1 : sizeof(expected) >= (n));	  \
 	ok &= check(i, name, actual, expected, (n));			  \
 } while (0)