summaryrefslogtreecommitdiff
path: root/regress/lib/libcrypto
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2024-04-25 14:27:30 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2024-04-25 14:27:30 +0000
commit43a9375d4c1a49453c2034d06eed619670ab4b20 (patch)
tree1e1ae811e4c8a9ea645dc61bb07d19dfba941a86 /regress/lib/libcrypto
parent909d3e081fc7d1e1d59fdbbb079edeb81dd4e91d (diff)
Add regress coverage for crypto_ct_*_u8()
Diffstat (limited to 'regress/lib/libcrypto')
-rw-r--r--regress/lib/libcrypto/Makefile3
-rw-r--r--regress/lib/libcrypto/crypto/Makefile12
-rw-r--r--regress/lib/libcrypto/crypto/crypto_test.c97
3 files changed, 111 insertions, 1 deletions
diff --git a/regress/lib/libcrypto/Makefile b/regress/lib/libcrypto/Makefile
index 871ae2093a6..ffe08d04bdc 100644
--- a/regress/lib/libcrypto/Makefile
+++ b/regress/lib/libcrypto/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.56 2024/03/29 07:13:38 joshua Exp $
+# $OpenBSD: Makefile,v 1.57 2024/04/25 14:27:29 jsing Exp $
SUBDIR += aead
SUBDIR += aes
@@ -14,6 +14,7 @@ SUBDIR += cast
SUBDIR += certs
SUBDIR += chacha
SUBDIR += cms
+SUBDIR += crypto
SUBDIR += ct
SUBDIR += curve25519
SUBDIR += des
diff --git a/regress/lib/libcrypto/crypto/Makefile b/regress/lib/libcrypto/crypto/Makefile
new file mode 100644
index 00000000000..34a4e7050bd
--- /dev/null
+++ b/regress/lib/libcrypto/crypto/Makefile
@@ -0,0 +1,12 @@
+# $OpenBSD: Makefile,v 1.1 2024/04/25 14:27:29 jsing Exp $
+
+PROG = crypto_test
+
+DPADD+= ${LIBCRYPTO}
+WARNINGS= Yes
+LDFLAGS+= -lcrypto
+CFLAGS+= -DLIBRESSL_INTERNAL
+CFLAGS+= -Wall -Wundef -Werror
+CFLAGS+= -I${.CURDIR}/../../../../lib/libcrypto
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libcrypto/crypto/crypto_test.c b/regress/lib/libcrypto/crypto/crypto_test.c
new file mode 100644
index 00000000000..38ee2d57d4c
--- /dev/null
+++ b/regress/lib/libcrypto/crypto/crypto_test.c
@@ -0,0 +1,97 @@
+/* $OpenBSD: crypto_test.c,v 1.1 2024/04/25 14:27:29 jsing Exp $ */
+/*
+ * Copyright (c) 2024 Joel Sing <jsing@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+
+#include "crypto_internal.h"
+
+static int
+test_ct_u8(void)
+{
+ uint8_t i, j, mask;
+ int failed = 1;
+
+ i = 0;
+
+ do {
+ if ((i != 0) != crypto_ct_ne_zero_u8(i)) {
+ fprintf(stderr, "FAIL: crypto_ct_ne_zero_u8(%d) = %d, "
+ "want %d\n", i, crypto_ct_ne_zero_u8(i), i != 0);
+ goto failure;
+ }
+ mask = (i != 0) ? 0xff : 0x00;
+ if (mask != crypto_ct_ne_zero_mask_u8(i)) {
+ fprintf(stderr, "FAIL: crypto_ct_ne_zero_mask_u8(%d) = %x, "
+ "want %x\n", i, crypto_ct_ne_zero_mask_u8(i), mask);
+ goto failure;
+ }
+ if ((i == 0) != crypto_ct_eq_zero_u8(i)) {
+ fprintf(stderr, "FAIL: crypto_ct_eq_zero_u8(%d) = %d, "
+ "want %d\n", i, crypto_ct_ne_zero_u8(i), i != 0);
+ goto failure;
+ }
+ mask = (i == 0) ? 0xff : 0x00;
+ if (mask != crypto_ct_eq_zero_mask_u8(i)) {
+ fprintf(stderr, "FAIL: crypto_ct_eq_zero_mask_u8(%d) = %x, "
+ "want %x\n", i, crypto_ct_ne_zero_mask_u8(i), mask);
+ goto failure;
+ }
+
+ j = 0;
+
+ do {
+ if ((i != j) != crypto_ct_ne_u8(i, j)) {
+ fprintf(stderr, "FAIL: crypto_ct_ne_u8(%d, %d) = %d, "
+ "want %d\n", i, j, crypto_ct_ne_u8(i, j), i != j);
+ goto failure;
+ }
+ mask = (i != j) ? 0xff : 0x00;
+ if (mask != crypto_ct_ne_mask_u8(i, j)) {
+ fprintf(stderr, "FAIL: crypto_ct_ne_mask_u8(%d, %d) = %x, "
+ "want %x\n", i, j, crypto_ct_ne_mask_u8(i, j), mask);
+ goto failure;
+ }
+ if ((i == j) != crypto_ct_eq_u8(i, j)) {
+ fprintf(stderr, "FAIL: crypto_ct_eq_u8(%d, %d) = %d, "
+ "want %d\n", i, j, crypto_ct_eq_u8(i, j), i != j);
+ goto failure;
+ }
+ mask = (i == j) ? 0xff : 0x00;
+ if (mask != crypto_ct_eq_mask_u8(i, j)) {
+ fprintf(stderr, "FAIL: crypto_ct_eq_mask_u8(%d, %d) = %x, "
+ "want %x\n", i, j, crypto_ct_eq_mask_u8(i, j), mask);
+ goto failure;
+ }
+ } while (++j != 0);
+ } while (++i != 0);
+
+ failed = 0;
+
+ failure:
+ return failed;
+}
+
+int
+main(int argc, char **argv)
+{
+ int failed = 0;
+
+ failed |= test_ct_u8();
+
+ return failed;
+}