summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2024-04-25 14:27:29 +0000
committerjsing <>2024-04-25 14:27:29 +0000
commitc8f4b15f88b5685979d38ab3878846bbf39d57ff (patch)
tree12d4ad4550c67dcdfdb5a9d13f31fc75b3b736c0
parent87dc7b3e69175b93ba1a68686a34fc4d18a65af2 (diff)
downloadopenbsd-c8f4b15f88b5685979d38ab3878846bbf39d57ff.tar.gz
openbsd-c8f4b15f88b5685979d38ab3878846bbf39d57ff.tar.bz2
openbsd-c8f4b15f88b5685979d38ab3878846bbf39d57ff.zip
Add regress coverage for crypto_ct_*_u8()
-rw-r--r--src/regress/lib/libcrypto/Makefile3
-rw-r--r--src/regress/lib/libcrypto/crypto/Makefile12
-rw-r--r--src/regress/lib/libcrypto/crypto/crypto_test.c97
3 files changed, 111 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/Makefile b/src/regress/lib/libcrypto/Makefile
index 871ae2093a..ffe08d04bd 100644
--- a/src/regress/lib/libcrypto/Makefile
+++ b/src/regress/lib/libcrypto/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.56 2024/03/29 07:13:38 joshua Exp $ 1# $OpenBSD: Makefile,v 1.57 2024/04/25 14:27:29 jsing Exp $
2 2
3SUBDIR += aead 3SUBDIR += aead
4SUBDIR += aes 4SUBDIR += aes
@@ -14,6 +14,7 @@ SUBDIR += cast
14SUBDIR += certs 14SUBDIR += certs
15SUBDIR += chacha 15SUBDIR += chacha
16SUBDIR += cms 16SUBDIR += cms
17SUBDIR += crypto
17SUBDIR += ct 18SUBDIR += ct
18SUBDIR += curve25519 19SUBDIR += curve25519
19SUBDIR += des 20SUBDIR += des
diff --git a/src/regress/lib/libcrypto/crypto/Makefile b/src/regress/lib/libcrypto/crypto/Makefile
new file mode 100644
index 0000000000..34a4e7050b
--- /dev/null
+++ b/src/regress/lib/libcrypto/crypto/Makefile
@@ -0,0 +1,12 @@
1# $OpenBSD: Makefile,v 1.1 2024/04/25 14:27:29 jsing Exp $
2
3PROG = crypto_test
4
5DPADD+= ${LIBCRYPTO}
6WARNINGS= Yes
7LDFLAGS+= -lcrypto
8CFLAGS+= -DLIBRESSL_INTERNAL
9CFLAGS+= -Wall -Wundef -Werror
10CFLAGS+= -I${.CURDIR}/../../../../lib/libcrypto
11
12.include <bsd.regress.mk>
diff --git a/src/regress/lib/libcrypto/crypto/crypto_test.c b/src/regress/lib/libcrypto/crypto/crypto_test.c
new file mode 100644
index 0000000000..38ee2d57d4
--- /dev/null
+++ b/src/regress/lib/libcrypto/crypto/crypto_test.c
@@ -0,0 +1,97 @@
1/* $OpenBSD: crypto_test.c,v 1.1 2024/04/25 14:27:29 jsing Exp $ */
2/*
3 * Copyright (c) 2024 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdint.h>
19#include <stdio.h>
20
21#include "crypto_internal.h"
22
23static int
24test_ct_u8(void)
25{
26 uint8_t i, j, mask;
27 int failed = 1;
28
29 i = 0;
30
31 do {
32 if ((i != 0) != crypto_ct_ne_zero_u8(i)) {
33 fprintf(stderr, "FAIL: crypto_ct_ne_zero_u8(%d) = %d, "
34 "want %d\n", i, crypto_ct_ne_zero_u8(i), i != 0);
35 goto failure;
36 }
37 mask = (i != 0) ? 0xff : 0x00;
38 if (mask != crypto_ct_ne_zero_mask_u8(i)) {
39 fprintf(stderr, "FAIL: crypto_ct_ne_zero_mask_u8(%d) = %x, "
40 "want %x\n", i, crypto_ct_ne_zero_mask_u8(i), mask);
41 goto failure;
42 }
43 if ((i == 0) != crypto_ct_eq_zero_u8(i)) {
44 fprintf(stderr, "FAIL: crypto_ct_eq_zero_u8(%d) = %d, "
45 "want %d\n", i, crypto_ct_ne_zero_u8(i), i != 0);
46 goto failure;
47 }
48 mask = (i == 0) ? 0xff : 0x00;
49 if (mask != crypto_ct_eq_zero_mask_u8(i)) {
50 fprintf(stderr, "FAIL: crypto_ct_eq_zero_mask_u8(%d) = %x, "
51 "want %x\n", i, crypto_ct_ne_zero_mask_u8(i), mask);
52 goto failure;
53 }
54
55 j = 0;
56
57 do {
58 if ((i != j) != crypto_ct_ne_u8(i, j)) {
59 fprintf(stderr, "FAIL: crypto_ct_ne_u8(%d, %d) = %d, "
60 "want %d\n", i, j, crypto_ct_ne_u8(i, j), i != j);
61 goto failure;
62 }
63 mask = (i != j) ? 0xff : 0x00;
64 if (mask != crypto_ct_ne_mask_u8(i, j)) {
65 fprintf(stderr, "FAIL: crypto_ct_ne_mask_u8(%d, %d) = %x, "
66 "want %x\n", i, j, crypto_ct_ne_mask_u8(i, j), mask);
67 goto failure;
68 }
69 if ((i == j) != crypto_ct_eq_u8(i, j)) {
70 fprintf(stderr, "FAIL: crypto_ct_eq_u8(%d, %d) = %d, "
71 "want %d\n", i, j, crypto_ct_eq_u8(i, j), i != j);
72 goto failure;
73 }
74 mask = (i == j) ? 0xff : 0x00;
75 if (mask != crypto_ct_eq_mask_u8(i, j)) {
76 fprintf(stderr, "FAIL: crypto_ct_eq_mask_u8(%d, %d) = %x, "
77 "want %x\n", i, j, crypto_ct_eq_mask_u8(i, j), mask);
78 goto failure;
79 }
80 } while (++j != 0);
81 } while (++i != 0);
82
83 failed = 0;
84
85 failure:
86 return failed;
87}
88
89int
90main(int argc, char **argv)
91{
92 int failed = 0;
93
94 failed |= test_ct_u8();
95
96 return failed;
97}