summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2025-09-05 14:36:03 +0000
committertb <>2025-09-05 14:36:03 +0000
commit3e5ba5bb23cdfff48594161be8b5aca5ec221d3b (patch)
tree03fa5d553dd089af5d5aa68225c4b0800fd0b73a /src
parent3215e696a22402c1551529bc8861c0d746223a04 (diff)
downloadopenbsd-3e5ba5bb23cdfff48594161be8b5aca5ec221d3b.tar.gz
openbsd-3e5ba5bb23cdfff48594161be8b5aca5ec221d3b.tar.bz2
openbsd-3e5ba5bb23cdfff48594161be8b5aca5ec221d3b.zip
wycheproof: port the MI primes check to v1
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/wycheproof/wycheproof-json.pl4
-rw-r--r--src/regress/lib/libcrypto/wycheproof/wycheproof-primes.c23
2 files changed, 24 insertions, 3 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof-json.pl b/src/regress/lib/libcrypto/wycheproof/wycheproof-json.pl
index 45c7542b59..0eea14752c 100644
--- a/src/regress/lib/libcrypto/wycheproof/wycheproof-json.pl
+++ b/src/regress/lib/libcrypto/wycheproof/wycheproof-json.pl
@@ -1,4 +1,4 @@
1# $OpenBSD: wycheproof-json.pl,v 1.2 2022/07/08 14:33:56 tb Exp $ 1# $OpenBSD: wycheproof-json.pl,v 1.3 2025/09/05 14:36:03 tb Exp $
2 2
3# Copyright (c) 2022 Joel Sing <jsing@openbsd.org> 3# Copyright (c) 2022 Joel Sing <jsing@openbsd.org>
4# Copyright (c) 2022 Theo Buehler <tb@openbsd.org> 4# Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
@@ -17,7 +17,7 @@
17 17
18use JSON::PP; 18use JSON::PP;
19 19
20$test_vector_path = "/usr/local/share/wycheproof/testvectors"; 20$test_vector_path = "/usr/local/share/wycheproof/testvectors_v1";
21 21
22open JSON, "$test_vector_path/primality_test.json" or die; 22open JSON, "$test_vector_path/primality_test.json" or die;
23@json = <JSON>; 23@json = <JSON>;
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof-primes.c b/src/regress/lib/libcrypto/wycheproof/wycheproof-primes.c
index 57bd7a53da..e54fd484f9 100644
--- a/src/regress/lib/libcrypto/wycheproof/wycheproof-primes.c
+++ b/src/regress/lib/libcrypto/wycheproof/wycheproof-primes.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: wycheproof-primes.c,v 1.2 2022/12/01 13:49:12 tb Exp $ */ 1/* $OpenBSD: wycheproof-primes.c,v 1.3 2025/09/05 14:36:03 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> 3 * Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
4 * 4 *
@@ -16,7 +16,9 @@
16 */ 16 */
17 17
18#include <err.h> 18#include <err.h>
19#include <limits.h>
19#include <stdio.h> 20#include <stdio.h>
21#include <string.h>
20 22
21#include <openssl/bn.h> 23#include <openssl/bn.h>
22 24
@@ -26,12 +28,31 @@ int
26primality_test(struct wycheproof_testcase *test) 28primality_test(struct wycheproof_testcase *test)
27{ 29{
28 BIGNUM *value = NULL; 30 BIGNUM *value = NULL;
31 size_t len;
29 int ret; 32 int ret;
30 int failed = 1; 33 int failed = 1;
31 34
32 if (!BN_hex2bn(&value, test->value)) 35 if (!BN_hex2bn(&value, test->value))
33 errx(1, "%d: failed to set value \"%s\"", test->id, test->value); 36 errx(1, "%d: failed to set value \"%s\"", test->id, test->value);
34 37
38 if ((len = strlen(test->value)) > INT_MAX / 4)
39 errx(1, "%d: overlong test string %zu", test->id, len);
40
41 if (len > 0 && test->value[0] >= '8') {
42 BIGNUM *pow2;
43
44 if ((pow2 = BN_new()) == NULL)
45 errx(1, "BN_new");
46
47 if (!BN_set_bit(pow2, 4 * len))
48 errx(1, "BN_set_bit");
49
50 if (!BN_sub(value, value, pow2))
51 errx(1, "BN_sub");
52
53 BN_free(pow2);
54 }
55
35 if ((ret = BN_is_prime_ex(value, BN_prime_checks, NULL, NULL)) < 0) 56 if ((ret = BN_is_prime_ex(value, BN_prime_checks, NULL, NULL)) < 0)
36 errx(1, "%d: BN_is_prime_ex errored", test->id); 57 errx(1, "%d: BN_is_prime_ex errored", test->id);
37 58