summaryrefslogtreecommitdiff
path: root/regress/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'regress/unittests')
-rw-r--r--regress/unittests/Makefile4
-rw-r--r--regress/unittests/bitmap/tests.c4
-rw-r--r--regress/unittests/conversion/tests.c4
-rw-r--r--regress/unittests/hostkeys/test_iterate.c28
-rw-r--r--regress/unittests/kex/test_kex.c12
-rw-r--r--regress/unittests/sshbuf/test_sshbuf_getput_basic.c231
-rw-r--r--regress/unittests/sshbuf/test_sshbuf_getput_crypto.c3
-rw-r--r--regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c8
-rw-r--r--regress/unittests/sshbuf/test_sshbuf_misc.c71
-rw-r--r--regress/unittests/sshbuf/tests.c2
-rw-r--r--regress/unittests/sshkey/common.c6
-rw-r--r--regress/unittests/sshkey/test_file.c8
-rw-r--r--regress/unittests/sshkey/test_fuzz.c14
-rw-r--r--regress/unittests/sshkey/test_sshkey.c42
-rw-r--r--regress/unittests/sshkey/testdata/ed25519_1_pw12
-rw-r--r--regress/unittests/test_helper/test_helper.c29
-rw-r--r--regress/unittests/test_helper/test_helper.h4
-rw-r--r--regress/unittests/utf8/tests.c2
18 files changed, 432 insertions, 52 deletions
diff --git a/regress/unittests/Makefile b/regress/unittests/Makefile
index e464b085a..4e56e1104 100644
--- a/regress/unittests/Makefile
+++ b/regress/unittests/Makefile
@@ -1,7 +1,7 @@
1# $OpenBSD: Makefile,v 1.10 2018/03/03 03:16:17 djm Exp $ 1# $OpenBSD: Makefile,v 1.11 2019/04/28 22:53:26 dtucker Exp $
2 2
3REGRESS_FAIL_EARLY?= yes 3REGRESS_FAIL_EARLY?= yes
4SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys utf8 match conversion 4SUBDIR= test_helper sshbuf sshkey bitmap kex hostkeys utf8 match conversion
5SUBDIR+=authopt 5SUBDIR+=authopt misc
6 6
7.include <bsd.subdir.mk> 7.include <bsd.subdir.mk>
diff --git a/regress/unittests/bitmap/tests.c b/regress/unittests/bitmap/tests.c
index 23025f90a..f66a4ce46 100644
--- a/regress/unittests/bitmap/tests.c
+++ b/regress/unittests/bitmap/tests.c
@@ -16,7 +16,9 @@
16#include <stdlib.h> 16#include <stdlib.h>
17#include <string.h> 17#include <string.h>
18 18
19#ifdef WITH_OPENSSL
19#include <openssl/bn.h> 20#include <openssl/bn.h>
21#endif
20 22
21#include "../test_helper/test_helper.h" 23#include "../test_helper/test_helper.h"
22 24
@@ -27,6 +29,7 @@
27void 29void
28tests(void) 30tests(void)
29{ 31{
32#ifdef WITH_OPENSSL
30 struct bitmap *b; 33 struct bitmap *b;
31 BIGNUM *bn; 34 BIGNUM *bn;
32 size_t len; 35 size_t len;
@@ -131,5 +134,6 @@ tests(void)
131 bitmap_free(b); 134 bitmap_free(b);
132 BN_free(bn); 135 BN_free(bn);
133 TEST_DONE(); 136 TEST_DONE();
137#endif
134} 138}
135 139
diff --git a/regress/unittests/conversion/tests.c b/regress/unittests/conversion/tests.c
index 6dd77ef42..ae1154d42 100644
--- a/regress/unittests/conversion/tests.c
+++ b/regress/unittests/conversion/tests.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tests.c,v 1.1 2017/03/14 01:20:29 dtucker Exp $ */ 1/* $OpenBSD: tests.c,v 1.2 2019/06/14 04:03:48 djm Exp $ */
2/* 2/*
3 * Regress test for conversions 3 * Regress test for conversions
4 * 4 *
@@ -40,6 +40,8 @@ tests(void)
40 ASSERT_LONG_EQ(convtime("-9d"), -1); 40 ASSERT_LONG_EQ(convtime("-9d"), -1);
41 41
42 /* overflow */ 42 /* overflow */
43 snprintf(buf, sizeof buf, "%llu", (unsigned long long)LONG_MAX);
44 ASSERT_LONG_EQ(convtime(buf), -1);
43 snprintf(buf, sizeof buf, "%llu", (unsigned long long)LONG_MAX + 1); 45 snprintf(buf, sizeof buf, "%llu", (unsigned long long)LONG_MAX + 1);
44 ASSERT_LONG_EQ(convtime(buf), -1); 46 ASSERT_LONG_EQ(convtime(buf), -1);
45 47
diff --git a/regress/unittests/hostkeys/test_iterate.c b/regress/unittests/hostkeys/test_iterate.c
index d6963bd2a..5904121ef 100644
--- a/regress/unittests/hostkeys/test_iterate.c
+++ b/regress/unittests/hostkeys/test_iterate.c
@@ -57,7 +57,7 @@ check(struct hostkey_foreach_line *l, void *_ctx)
57 int parse_key = (ctx->flags & HKF_WANT_PARSE_KEY) != 0; 57 int parse_key = (ctx->flags & HKF_WANT_PARSE_KEY) != 0;
58 const int matching = (ctx->flags & HKF_WANT_MATCH) != 0; 58 const int matching = (ctx->flags & HKF_WANT_MATCH) != 0;
59 u_int expected_status, expected_match; 59 u_int expected_status, expected_match;
60 int expected_keytype; 60 int expected_keytype, skip = 0;
61 61
62 test_subtest_info("entry %zu/%zu, file line %ld", 62 test_subtest_info("entry %zu/%zu, file line %ld",
63 ctx->i + 1, ctx->nexpected, l->linenum); 63 ctx->i + 1, ctx->nexpected, l->linenum);
@@ -92,13 +92,23 @@ check(struct hostkey_foreach_line *l, void *_ctx)
92 92
93#ifndef OPENSSL_HAS_ECC 93#ifndef OPENSSL_HAS_ECC
94 if (expected->l.keytype == KEY_ECDSA || 94 if (expected->l.keytype == KEY_ECDSA ||
95 expected->no_parse_keytype == KEY_ECDSA) { 95 expected->no_parse_keytype == KEY_ECDSA)
96 skip = 1;
97#endif /* OPENSSL_HAS_ECC */
98#ifndef WITH_OPENSSL
99 if (expected->l.keytype == KEY_DSA ||
100 expected->no_parse_keytype == KEY_DSA ||
101 expected->l.keytype == KEY_RSA ||
102 expected->no_parse_keytype == KEY_RSA ||
103 expected->l.keytype == KEY_ECDSA ||
104 expected->no_parse_keytype == KEY_ECDSA)
105 skip = 1;
106#endif /* WITH_OPENSSL */
107 if (skip) {
96 expected_status = HKF_STATUS_INVALID; 108 expected_status = HKF_STATUS_INVALID;
97 expected_keytype = KEY_UNSPEC; 109 expected_keytype = KEY_UNSPEC;
98 parse_key = 0; 110 parse_key = 0;
99 } 111 }
100#endif
101
102 UPDATE_MATCH_STATUS(match_host_p); 112 UPDATE_MATCH_STATUS(match_host_p);
103 UPDATE_MATCH_STATUS(match_host_s); 113 UPDATE_MATCH_STATUS(match_host_s);
104 UPDATE_MATCH_STATUS(match_ipv4); 114 UPDATE_MATCH_STATUS(match_ipv4);
@@ -145,7 +155,15 @@ prepare_expected(struct expected *expected, size_t n)
145#ifndef OPENSSL_HAS_ECC 155#ifndef OPENSSL_HAS_ECC
146 if (expected[i].l.keytype == KEY_ECDSA) 156 if (expected[i].l.keytype == KEY_ECDSA)
147 continue; 157 continue;
148#endif 158#endif /* OPENSSL_HAS_ECC */
159#ifndef WITH_OPENSSL
160 switch (expected[i].l.keytype) {
161 case KEY_RSA:
162 case KEY_DSA:
163 case KEY_ECDSA:
164 continue;
165 }
166#endif /* WITH_OPENSSL */
149 ASSERT_INT_EQ(sshkey_load_public( 167 ASSERT_INT_EQ(sshkey_load_public(
150 test_data_file(expected[i].key_file), &expected[i].l.key, 168 test_data_file(expected[i].key_file), &expected[i].l.key,
151 NULL), 0); 169 NULL), 0);
diff --git a/regress/unittests/kex/test_kex.c b/regress/unittests/kex/test_kex.c
index a860efc02..0e7cd9e07 100644
--- a/regress/unittests/kex/test_kex.c
+++ b/regress/unittests/kex/test_kex.c
@@ -142,13 +142,15 @@ do_kex_with_key(char *kex, int keytype, int bits)
142 sshbuf_free(state); 142 sshbuf_free(state);
143 ASSERT_PTR_NE(server2->kex, NULL); 143 ASSERT_PTR_NE(server2->kex, NULL);
144 /* XXX we need to set the callbacks */ 144 /* XXX we need to set the callbacks */
145#ifdef WITH_OPENSSL
145 server2->kex->kex[KEX_DH_GRP1_SHA1] = kex_gen_server; 146 server2->kex->kex[KEX_DH_GRP1_SHA1] = kex_gen_server;
146 server2->kex->kex[KEX_DH_GRP14_SHA1] = kex_gen_server; 147 server2->kex->kex[KEX_DH_GRP14_SHA1] = kex_gen_server;
147 server2->kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; 148 server2->kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
148 server2->kex->kex[KEX_DH_GEX_SHA256] = kexgex_server; 149 server2->kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
149#ifdef OPENSSL_HAS_ECC 150#ifdef OPENSSL_HAS_ECC
150 server2->kex->kex[KEX_ECDH_SHA2] = kex_gen_server; 151 server2->kex->kex[KEX_ECDH_SHA2] = kex_gen_server;
151#endif 152#endif /* OPENSSL_HAS_ECC */
153#endif /* WITH_OPENSSL */
152 server2->kex->kex[KEX_C25519_SHA256] = kex_gen_server; 154 server2->kex->kex[KEX_C25519_SHA256] = kex_gen_server;
153 server2->kex->load_host_public_key = server->kex->load_host_public_key; 155 server2->kex->load_host_public_key = server->kex->load_host_public_key;
154 server2->kex->load_host_private_key = server->kex->load_host_private_key; 156 server2->kex->load_host_private_key = server->kex->load_host_private_key;
@@ -175,11 +177,13 @@ do_kex_with_key(char *kex, int keytype, int bits)
175static void 177static void
176do_kex(char *kex) 178do_kex(char *kex)
177{ 179{
180#ifdef WITH_OPENSSL
178 do_kex_with_key(kex, KEY_RSA, 2048); 181 do_kex_with_key(kex, KEY_RSA, 2048);
179 do_kex_with_key(kex, KEY_DSA, 1024); 182 do_kex_with_key(kex, KEY_DSA, 1024);
180#ifdef OPENSSL_HAS_ECC 183#ifdef OPENSSL_HAS_ECC
181 do_kex_with_key(kex, KEY_ECDSA, 256); 184 do_kex_with_key(kex, KEY_ECDSA, 256);
182#endif 185#endif /* OPENSSL_HAS_ECC */
186#endif /* WITH_OPENSSL */
183 do_kex_with_key(kex, KEY_ED25519, 256); 187 do_kex_with_key(kex, KEY_ED25519, 256);
184} 188}
185 189
@@ -187,13 +191,15 @@ void
187kex_tests(void) 191kex_tests(void)
188{ 192{
189 do_kex("curve25519-sha256@libssh.org"); 193 do_kex("curve25519-sha256@libssh.org");
194#ifdef WITH_OPENSSL
190#ifdef OPENSSL_HAS_ECC 195#ifdef OPENSSL_HAS_ECC
191 do_kex("ecdh-sha2-nistp256"); 196 do_kex("ecdh-sha2-nistp256");
192 do_kex("ecdh-sha2-nistp384"); 197 do_kex("ecdh-sha2-nistp384");
193 do_kex("ecdh-sha2-nistp521"); 198 do_kex("ecdh-sha2-nistp521");
194#endif 199#endif /* OPENSSL_HAS_ECC */
195 do_kex("diffie-hellman-group-exchange-sha256"); 200 do_kex("diffie-hellman-group-exchange-sha256");
196 do_kex("diffie-hellman-group-exchange-sha1"); 201 do_kex("diffie-hellman-group-exchange-sha1");
197 do_kex("diffie-hellman-group14-sha1"); 202 do_kex("diffie-hellman-group14-sha1");
198 do_kex("diffie-hellman-group1-sha1"); 203 do_kex("diffie-hellman-group1-sha1");
204#endif /* WITH_OPENSSL */
199} 205}
diff --git a/regress/unittests/sshbuf/test_sshbuf_getput_basic.c b/regress/unittests/sshbuf/test_sshbuf_getput_basic.c
index 966e8432b..bea89881a 100644
--- a/regress/unittests/sshbuf/test_sshbuf_getput_basic.c
+++ b/regress/unittests/sshbuf/test_sshbuf_getput_basic.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: test_sshbuf_getput_basic.c,v 1.1 2014/04/30 05:32:00 djm Exp $ */ 1/* $OpenBSD: test_sshbuf_getput_basic.c,v 1.2 2019/07/14 23:33:19 djm Exp $ */
2/* 2/*
3 * Regress test for sshbuf.h buffer API 3 * Regress test for sshbuf.h buffer API
4 * 4 *
@@ -481,4 +481,233 @@ sshbuf_getput_basic_tests(void)
481 ASSERT_MEM_EQ(sshbuf_ptr(p1), bn_exp3, sizeof(bn_exp3)); 481 ASSERT_MEM_EQ(sshbuf_ptr(p1), bn_exp3, sizeof(bn_exp3));
482 sshbuf_free(p1); 482 sshbuf_free(p1);
483 TEST_DONE(); 483 TEST_DONE();
484
485 TEST_START("sshbuf_peek_u64");
486 p1 = sshbuf_new();
487 ASSERT_PTR_NE(p1, NULL);
488 ASSERT_INT_EQ(sshbuf_put(p1, x, sizeof(x)), 0);
489 ASSERT_INT_EQ(sshbuf_peek_u64(p1, 0, &v64), 0);
490 ASSERT_U64_EQ(v64, 0x1122334455667788ULL);
491 ASSERT_INT_EQ(sshbuf_peek_u64(p1, 2, &v64), 0);
492 ASSERT_U64_EQ(v64, 0x3344556677880099ULL);
493 ASSERT_INT_EQ(sshbuf_peek_u64(p1, 3, &v64), SSH_ERR_MESSAGE_INCOMPLETE);
494 ASSERT_INT_EQ(sshbuf_peek_u64(p1, sizeof(x), &v64),
495 SSH_ERR_MESSAGE_INCOMPLETE);
496 ASSERT_INT_EQ(sshbuf_peek_u64(p1, 1000, &v64),
497 SSH_ERR_MESSAGE_INCOMPLETE);
498 sshbuf_free(p1);
499 TEST_DONE();
500
501 TEST_START("sshbuf_peek_u32");
502 p1 = sshbuf_new();
503 ASSERT_PTR_NE(p1, NULL);
504 ASSERT_INT_EQ(sshbuf_put(p1, x, sizeof(x)), 0);
505 ASSERT_INT_EQ(sshbuf_peek_u32(p1, 0, &v32), 0);
506 ASSERT_U32_EQ(v32, 0x11223344);
507 ASSERT_INT_EQ(sshbuf_peek_u32(p1, 6, &v32), 0);
508 ASSERT_U32_EQ(v32, 0x77880099);
509 ASSERT_INT_EQ(sshbuf_peek_u32(p1, 7, &v32), SSH_ERR_MESSAGE_INCOMPLETE);
510 ASSERT_INT_EQ(sshbuf_peek_u32(p1, sizeof(x), &v32),
511 SSH_ERR_MESSAGE_INCOMPLETE);
512 ASSERT_INT_EQ(sshbuf_peek_u32(p1, 1000, &v32),
513 SSH_ERR_MESSAGE_INCOMPLETE);
514 sshbuf_free(p1);
515 TEST_DONE();
516
517 TEST_START("sshbuf_peek_u16");
518 p1 = sshbuf_new();
519 ASSERT_PTR_NE(p1, NULL);
520 ASSERT_INT_EQ(sshbuf_put(p1, x, sizeof(x)), 0);
521 ASSERT_INT_EQ(sshbuf_peek_u16(p1, 0, &v16), 0);
522 ASSERT_U16_EQ(v16, 0x1122);
523 ASSERT_INT_EQ(sshbuf_peek_u16(p1, 8, &v16), 0);
524 ASSERT_U16_EQ(v16, 0x99);
525 ASSERT_INT_EQ(sshbuf_peek_u16(p1, 9, &v16), SSH_ERR_MESSAGE_INCOMPLETE);
526 ASSERT_INT_EQ(sshbuf_peek_u16(p1, sizeof(x), &v16),
527 SSH_ERR_MESSAGE_INCOMPLETE);
528 ASSERT_INT_EQ(sshbuf_peek_u16(p1, 1000, &v16),
529 SSH_ERR_MESSAGE_INCOMPLETE);
530 sshbuf_free(p1);
531 TEST_DONE();
532
533 TEST_START("sshbuf_peek_u8");
534 p1 = sshbuf_new();
535 ASSERT_PTR_NE(p1, NULL);
536 ASSERT_INT_EQ(sshbuf_put(p1, x, sizeof(x)), 0);
537 ASSERT_INT_EQ(sshbuf_peek_u8(p1, 0, &v8), 0);
538 ASSERT_U8_EQ(v8, 0x11);
539 ASSERT_INT_EQ(sshbuf_peek_u8(p1, 9, &v8), 0);
540 ASSERT_U8_EQ(v8, 0x99);
541 ASSERT_INT_EQ(sshbuf_peek_u8(p1, sizeof(x), &v8),
542 SSH_ERR_MESSAGE_INCOMPLETE);
543 ASSERT_INT_EQ(sshbuf_peek_u8(p1, 1000, &v8),
544 SSH_ERR_MESSAGE_INCOMPLETE);
545 sshbuf_free(p1);
546 TEST_DONE();
547
548 TEST_START("sshbuf_poke_u64");
549 p1 = sshbuf_new();
550 ASSERT_PTR_NE(p1, NULL);
551 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
552 /* poke at start of buffer */
553 ASSERT_INT_EQ(sshbuf_poke_u64(p1, 0, 0xa1b2c3d4e5f60718ULL), 0);
554 s2 = sshbuf_dtob16(p1);
555 ASSERT_PTR_NE(s2, NULL);
556 ASSERT_STRING_EQ(s2, "a1b2c3d4e5f607180000");
557 free(s2);
558 sshbuf_reset(p1);
559 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
560 /* poke aligned with end of buffer */
561 ASSERT_INT_EQ(sshbuf_poke_u64(p1, 2, 0xa1b2c3d4e5f60718ULL), 0);
562 s2 = sshbuf_dtob16(p1);
563 ASSERT_PTR_NE(s2, NULL);
564 ASSERT_STRING_EQ(s2, "0000a1b2c3d4e5f60718");
565 free(s2);
566 sshbuf_reset(p1);
567 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
568 /* poke past end of buffer */
569 ASSERT_INT_EQ(sshbuf_poke_u64(p1, 3, 0xa1b2c3d4e5f60718ULL),
570 SSH_ERR_NO_BUFFER_SPACE);
571 ASSERT_INT_EQ(sshbuf_poke_u64(p1, 10, 0xa1b2c3d4e5f60718ULL),
572 SSH_ERR_NO_BUFFER_SPACE);
573 ASSERT_INT_EQ(sshbuf_poke_u64(p1, 1000, 0xa1b2c3d4e5f60718ULL),
574 SSH_ERR_NO_BUFFER_SPACE);
575 /* ensure failed pokes do not modify buffer */
576 s2 = sshbuf_dtob16(p1);
577 ASSERT_PTR_NE(s2, NULL);
578 ASSERT_STRING_EQ(s2, "00000000000000000000");
579 sshbuf_free(p1);
580 TEST_DONE();
581
582 TEST_START("sshbuf_poke_u32");
583 p1 = sshbuf_new();
584 ASSERT_PTR_NE(p1, NULL);
585 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
586 /* poke at start of buffer */
587 ASSERT_INT_EQ(sshbuf_poke_u32(p1, 0, 0xa1b2c3d4), 0);
588 s2 = sshbuf_dtob16(p1);
589 ASSERT_PTR_NE(s2, NULL);
590 ASSERT_STRING_EQ(s2, "a1b2c3d4000000000000");
591 free(s2);
592 sshbuf_reset(p1);
593 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
594 /* poke aligned with end of buffer */
595 ASSERT_INT_EQ(sshbuf_poke_u32(p1, 6, 0xa1b2c3d4), 0);
596 s2 = sshbuf_dtob16(p1);
597 ASSERT_PTR_NE(s2, NULL);
598 ASSERT_STRING_EQ(s2, "000000000000a1b2c3d4");
599 free(s2);
600 sshbuf_reset(p1);
601 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
602 /* poke past end of buffer */
603 ASSERT_INT_EQ(sshbuf_poke_u32(p1, 7, 0xa1b2c3d4),
604 SSH_ERR_NO_BUFFER_SPACE);
605 ASSERT_INT_EQ(sshbuf_poke_u32(p1, 10, 0xa1b2c3d4),
606 SSH_ERR_NO_BUFFER_SPACE);
607 ASSERT_INT_EQ(sshbuf_poke_u32(p1, 1000, 0xa1b2c3d4),
608 SSH_ERR_NO_BUFFER_SPACE);
609 /* ensure failed pokes do not modify buffer */
610 s2 = sshbuf_dtob16(p1);
611 ASSERT_PTR_NE(s2, NULL);
612 ASSERT_STRING_EQ(s2, "00000000000000000000");
613 sshbuf_free(p1);
614 TEST_DONE();
615
616 TEST_START("sshbuf_poke_u16");
617 p1 = sshbuf_new();
618 ASSERT_PTR_NE(p1, NULL);
619 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
620 /* poke at start of buffer */
621 ASSERT_INT_EQ(sshbuf_poke_u16(p1, 0, 0xa1b2), 0);
622 s2 = sshbuf_dtob16(p1);
623 ASSERT_PTR_NE(s2, NULL);
624 ASSERT_STRING_EQ(s2, "a1b20000000000000000");
625 free(s2);
626 sshbuf_reset(p1);
627 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
628 /* poke aligned with end of buffer */
629 ASSERT_INT_EQ(sshbuf_poke_u16(p1, 8, 0xa1b2), 0);
630 s2 = sshbuf_dtob16(p1);
631 ASSERT_PTR_NE(s2, NULL);
632 ASSERT_STRING_EQ(s2, "0000000000000000a1b2");
633 free(s2);
634 sshbuf_reset(p1);
635 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
636 /* poke past end of buffer */
637 ASSERT_INT_EQ(sshbuf_poke_u16(p1, 9, 0xa1b2),
638 SSH_ERR_NO_BUFFER_SPACE);
639 ASSERT_INT_EQ(sshbuf_poke_u16(p1, 10, 0xa1b2),
640 SSH_ERR_NO_BUFFER_SPACE);
641 ASSERT_INT_EQ(sshbuf_poke_u16(p1, 1000, 0xa1b2),
642 SSH_ERR_NO_BUFFER_SPACE);
643 /* ensure failed pokes do not modify buffer */
644 s2 = sshbuf_dtob16(p1);
645 ASSERT_PTR_NE(s2, NULL);
646 ASSERT_STRING_EQ(s2, "00000000000000000000");
647 sshbuf_free(p1);
648 TEST_DONE();
649
650 TEST_START("sshbuf_poke_u8");
651 p1 = sshbuf_new();
652 ASSERT_PTR_NE(p1, NULL);
653 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
654 /* poke at start of buffer */
655 ASSERT_INT_EQ(sshbuf_poke_u8(p1, 0, 0xa1), 0);
656 s2 = sshbuf_dtob16(p1);
657 ASSERT_PTR_NE(s2, NULL);
658 ASSERT_STRING_EQ(s2, "a1000000000000000000");
659 free(s2);
660 sshbuf_reset(p1);
661 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
662 /* poke aligned with end of buffer */
663 ASSERT_INT_EQ(sshbuf_poke_u8(p1, 9, 0xa1), 0);
664 s2 = sshbuf_dtob16(p1);
665 ASSERT_PTR_NE(s2, NULL);
666 ASSERT_STRING_EQ(s2, "000000000000000000a1");
667 free(s2);
668 sshbuf_reset(p1);
669 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
670 /* poke past end of buffer */
671 ASSERT_INT_EQ(sshbuf_poke_u8(p1, 10, 0xa1), SSH_ERR_NO_BUFFER_SPACE);
672 ASSERT_INT_EQ(sshbuf_poke_u8(p1, 1000, 0xa1), SSH_ERR_NO_BUFFER_SPACE);
673 /* ensure failed pokes do not modify buffer */
674 s2 = sshbuf_dtob16(p1);
675 ASSERT_PTR_NE(s2, NULL);
676 ASSERT_STRING_EQ(s2, "00000000000000000000");
677 sshbuf_free(p1);
678 TEST_DONE();
679
680 TEST_START("sshbuf_poke");
681 p1 = sshbuf_new();
682 ASSERT_PTR_NE(p1, NULL);
683 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
684 /* poke at start of buffer */
685 ASSERT_INT_EQ(sshbuf_poke(p1, 0, "hello!", 6), 0);
686 s2 = sshbuf_dtob16(p1);
687 ASSERT_PTR_NE(s2, NULL);
688 ASSERT_STRING_EQ(s2, "68656c6c6f2100000000");
689 free(s2);
690 sshbuf_reset(p1);
691 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
692 /* poke aligned with end of buffer */
693 ASSERT_INT_EQ(sshbuf_poke(p1, 4, "hello!", 6), 0);
694 s2 = sshbuf_dtob16(p1);
695 ASSERT_PTR_NE(s2, NULL);
696 ASSERT_STRING_EQ(s2, "0000000068656c6c6f21");
697 free(s2);
698 sshbuf_reset(p1);
699 ASSERT_INT_EQ(sshbuf_reserve(p1, 10, NULL), 0);
700 /* poke past end of buffer */
701 ASSERT_INT_EQ(sshbuf_poke(p1, 7, "hello!", 6),
702 SSH_ERR_NO_BUFFER_SPACE);
703 ASSERT_INT_EQ(sshbuf_poke(p1, 10, "hello!", 6),
704 SSH_ERR_NO_BUFFER_SPACE);
705 ASSERT_INT_EQ(sshbuf_poke(p1, 1000, "hello!", 6),
706 SSH_ERR_NO_BUFFER_SPACE);
707 /* ensure failed pokes do not modify buffer */
708 s2 = sshbuf_dtob16(p1);
709 ASSERT_PTR_NE(s2, NULL);
710 ASSERT_STRING_EQ(s2, "00000000000000000000");
711 sshbuf_free(p1);
712 TEST_DONE();
484} 713}
diff --git a/regress/unittests/sshbuf/test_sshbuf_getput_crypto.c b/regress/unittests/sshbuf/test_sshbuf_getput_crypto.c
index 5d39e63e1..492b3bdf0 100644
--- a/regress/unittests/sshbuf/test_sshbuf_getput_crypto.c
+++ b/regress/unittests/sshbuf/test_sshbuf_getput_crypto.c
@@ -7,6 +7,8 @@
7 7
8#include "includes.h" 8#include "includes.h"
9 9
10#ifdef WITH_OPENSSL
11
10#include <sys/types.h> 12#include <sys/types.h>
11#include <sys/param.h> 13#include <sys/param.h>
12#include <stdio.h> 14#include <stdio.h>
@@ -276,3 +278,4 @@ sshbuf_getput_crypto_tests(void)
276#endif 278#endif
277} 279}
278 280
281#endif /* WITH_OPENSSL */
diff --git a/regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c b/regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c
index ca06bfb00..1ca30be97 100644
--- a/regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c
+++ b/regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c
@@ -32,10 +32,12 @@ static void
32attempt_parse_blob(u_char *blob, size_t len) 32attempt_parse_blob(u_char *blob, size_t len)
33{ 33{
34 struct sshbuf *p1; 34 struct sshbuf *p1;
35#ifdef WITH_OPENSSL
35 BIGNUM *bn; 36 BIGNUM *bn;
36#if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256) 37#if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256)
37 EC_KEY *eck; 38 EC_KEY *eck;
38#endif 39#endif /* defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256) */
40#endif /* WITH_OPENSSL */
39 u_char *s; 41 u_char *s;
40 size_t l; 42 size_t l;
41 u_int8_t u8; 43 u_int8_t u8;
@@ -54,6 +56,7 @@ attempt_parse_blob(u_char *blob, size_t len)
54 bzero(s, l); 56 bzero(s, l);
55 free(s); 57 free(s);
56 } 58 }
59#ifdef WITH_OPENSSL
57 bn = NULL; 60 bn = NULL;
58 sshbuf_get_bignum2(p1, &bn); 61 sshbuf_get_bignum2(p1, &bn);
59 BN_clear_free(bn); 62 BN_clear_free(bn);
@@ -62,7 +65,8 @@ attempt_parse_blob(u_char *blob, size_t len)
62 ASSERT_PTR_NE(eck, NULL); 65 ASSERT_PTR_NE(eck, NULL);
63 sshbuf_get_eckey(p1, eck); 66 sshbuf_get_eckey(p1, eck);
64 EC_KEY_free(eck); 67 EC_KEY_free(eck);
65#endif 68#endif /* defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256) */
69#endif /* WITH_OPENSSL */
66 sshbuf_free(p1); 70 sshbuf_free(p1);
67} 71}
68 72
diff --git a/regress/unittests/sshbuf/test_sshbuf_misc.c b/regress/unittests/sshbuf/test_sshbuf_misc.c
index 762a6c31c..c53db937f 100644
--- a/regress/unittests/sshbuf/test_sshbuf_misc.c
+++ b/regress/unittests/sshbuf/test_sshbuf_misc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: test_sshbuf_misc.c,v 1.2 2016/05/03 13:48:33 djm Exp $ */ 1/* $OpenBSD: test_sshbuf_misc.c,v 1.4 2019/07/16 22:16:49 djm Exp $ */
2/* 2/*
3 * Regress test for sshbuf.h buffer API 3 * Regress test for sshbuf.h buffer API
4 * 4 *
@@ -19,6 +19,7 @@
19#include "../test_helper/test_helper.h" 19#include "../test_helper/test_helper.h"
20 20
21#include "sshbuf.h" 21#include "sshbuf.h"
22#include "ssherr.h"
22 23
23void sshbuf_misc_tests(void); 24void sshbuf_misc_tests(void);
24 25
@@ -26,7 +27,7 @@ void
26sshbuf_misc_tests(void) 27sshbuf_misc_tests(void)
27{ 28{
28 struct sshbuf *p1; 29 struct sshbuf *p1;
29 char tmp[512], *p; 30 char tmp[512], msg[] = "imploring ping silence ping over", *p;
30 FILE *out; 31 FILE *out;
31 size_t sz; 32 size_t sz;
32 33
@@ -60,48 +61,48 @@ sshbuf_misc_tests(void)
60 sshbuf_free(p1); 61 sshbuf_free(p1);
61 TEST_DONE(); 62 TEST_DONE();
62 63
63 TEST_START("sshbuf_dtob64 len 1"); 64 TEST_START("sshbuf_dtob64_string len 1");
64 p1 = sshbuf_new(); 65 p1 = sshbuf_new();
65 ASSERT_PTR_NE(p1, NULL); 66 ASSERT_PTR_NE(p1, NULL);
66 ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x11), 0); 67 ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x11), 0);
67 p = sshbuf_dtob64(p1); 68 p = sshbuf_dtob64_string(p1, 0);
68 ASSERT_PTR_NE(p, NULL); 69 ASSERT_PTR_NE(p, NULL);
69 ASSERT_STRING_EQ(p, "EQ=="); 70 ASSERT_STRING_EQ(p, "EQ==");
70 free(p); 71 free(p);
71 sshbuf_free(p1); 72 sshbuf_free(p1);
72 TEST_DONE(); 73 TEST_DONE();
73 74
74 TEST_START("sshbuf_dtob64 len 2"); 75 TEST_START("sshbuf_dtob64_string len 2");
75 p1 = sshbuf_new(); 76 p1 = sshbuf_new();
76 ASSERT_PTR_NE(p1, NULL); 77 ASSERT_PTR_NE(p1, NULL);
77 ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x11), 0); 78 ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x11), 0);
78 ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x22), 0); 79 ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x22), 0);
79 p = sshbuf_dtob64(p1); 80 p = sshbuf_dtob64_string(p1, 0);
80 ASSERT_PTR_NE(p, NULL); 81 ASSERT_PTR_NE(p, NULL);
81 ASSERT_STRING_EQ(p, "ESI="); 82 ASSERT_STRING_EQ(p, "ESI=");
82 free(p); 83 free(p);
83 sshbuf_free(p1); 84 sshbuf_free(p1);
84 TEST_DONE(); 85 TEST_DONE();
85 86
86 TEST_START("sshbuf_dtob64 len 3"); 87 TEST_START("sshbuf_dtob64_string len 3");
87 p1 = sshbuf_new(); 88 p1 = sshbuf_new();
88 ASSERT_PTR_NE(p1, NULL); 89 ASSERT_PTR_NE(p1, NULL);
89 ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x11), 0); 90 ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x11), 0);
90 ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x22), 0); 91 ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x22), 0);
91 ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x33), 0); 92 ASSERT_INT_EQ(sshbuf_put_u8(p1, 0x33), 0);
92 p = sshbuf_dtob64(p1); 93 p = sshbuf_dtob64_string(p1, 0);
93 ASSERT_PTR_NE(p, NULL); 94 ASSERT_PTR_NE(p, NULL);
94 ASSERT_STRING_EQ(p, "ESIz"); 95 ASSERT_STRING_EQ(p, "ESIz");
95 free(p); 96 free(p);
96 sshbuf_free(p1); 97 sshbuf_free(p1);
97 TEST_DONE(); 98 TEST_DONE();
98 99
99 TEST_START("sshbuf_dtob64 len 8191"); 100 TEST_START("sshbuf_dtob64_string len 8191");
100 p1 = sshbuf_new(); 101 p1 = sshbuf_new();
101 ASSERT_PTR_NE(p1, NULL); 102 ASSERT_PTR_NE(p1, NULL);
102 ASSERT_INT_EQ(sshbuf_reserve(p1, 8192, NULL), 0); 103 ASSERT_INT_EQ(sshbuf_reserve(p1, 8192, NULL), 0);
103 bzero(sshbuf_mutable_ptr(p1), 8192); 104 bzero(sshbuf_mutable_ptr(p1), 8192);
104 p = sshbuf_dtob64(p1); 105 p = sshbuf_dtob64_string(p1, 0);
105 ASSERT_PTR_NE(p, NULL); 106 ASSERT_PTR_NE(p, NULL);
106 ASSERT_SIZE_T_EQ(strlen(p), ((8191 + 2) / 3) * 4); 107 ASSERT_SIZE_T_EQ(strlen(p), ((8191 + 2) / 3) * 4);
107 free(p); 108 free(p);
@@ -163,5 +164,55 @@ sshbuf_misc_tests(void)
163 ASSERT_PTR_EQ(p, NULL); 164 ASSERT_PTR_EQ(p, NULL);
164 sshbuf_free(p1); 165 sshbuf_free(p1);
165 TEST_DONE(); 166 TEST_DONE();
167
168 TEST_START("sshbuf_cmp");
169 p1 = sshbuf_from(msg, sizeof(msg) - 1);
170 ASSERT_PTR_NE(p1, NULL);
171 ASSERT_INT_EQ(sshbuf_cmp(p1, 0, "i", 1), 0);
172 ASSERT_INT_EQ(sshbuf_cmp(p1, 0, "j", 1), SSH_ERR_INVALID_FORMAT);
173 ASSERT_INT_EQ(sshbuf_cmp(p1, 0, "imploring", 9), 0);
174 ASSERT_INT_EQ(sshbuf_cmp(p1, 0, "implored", 9), SSH_ERR_INVALID_FORMAT);
175 ASSERT_INT_EQ(sshbuf_cmp(p1, 10, "ping", 4), 0);
176 ASSERT_INT_EQ(sshbuf_cmp(p1, 10, "ring", 4), SSH_ERR_INVALID_FORMAT);
177 ASSERT_INT_EQ(sshbuf_cmp(p1, 28, "over", 4), 0);
178 ASSERT_INT_EQ(sshbuf_cmp(p1, 28, "rove", 4), SSH_ERR_INVALID_FORMAT);
179 ASSERT_INT_EQ(sshbuf_cmp(p1, 28, "overt", 5),
180 SSH_ERR_MESSAGE_INCOMPLETE);
181 ASSERT_INT_EQ(sshbuf_cmp(p1, 32, "ping", 4),
182 SSH_ERR_MESSAGE_INCOMPLETE);
183 ASSERT_INT_EQ(sshbuf_cmp(p1, 1000, "silence", 7),
184 SSH_ERR_MESSAGE_INCOMPLETE);
185 ASSERT_INT_EQ(sshbuf_cmp(p1, 0, msg, sizeof(msg) - 1), 0);
186 TEST_DONE();
187
188 TEST_START("sshbuf_find");
189 p1 = sshbuf_from(msg, sizeof(msg) - 1);
190 ASSERT_PTR_NE(p1, NULL);
191 ASSERT_INT_EQ(sshbuf_find(p1, 0, "i", 1, &sz), 0);
192 ASSERT_SIZE_T_EQ(sz, 0);
193 ASSERT_INT_EQ(sshbuf_find(p1, 0, "j", 1, &sz), SSH_ERR_INVALID_FORMAT);
194 ASSERT_INT_EQ(sshbuf_find(p1, 0, "imploring", 9, &sz), 0);
195 ASSERT_SIZE_T_EQ(sz, 0);
196 ASSERT_INT_EQ(sshbuf_find(p1, 0, "implored", 9, &sz),
197 SSH_ERR_INVALID_FORMAT);
198 ASSERT_INT_EQ(sshbuf_find(p1, 3, "ping", 4, &sz), 0);
199 ASSERT_SIZE_T_EQ(sz, 10);
200 ASSERT_INT_EQ(sshbuf_find(p1, 11, "ping", 4, &sz), 0);
201 ASSERT_SIZE_T_EQ(sz, 23);
202 ASSERT_INT_EQ(sshbuf_find(p1, 20, "over", 4, &sz), 0);
203 ASSERT_SIZE_T_EQ(sz, 28);
204 ASSERT_INT_EQ(sshbuf_find(p1, 28, "over", 4, &sz), 0);
205 ASSERT_SIZE_T_EQ(sz, 28);
206 ASSERT_INT_EQ(sshbuf_find(p1, 28, "rove", 4, &sz),
207 SSH_ERR_INVALID_FORMAT);
208 ASSERT_INT_EQ(sshbuf_find(p1, 28, "overt", 5, &sz),
209 SSH_ERR_MESSAGE_INCOMPLETE);
210 ASSERT_INT_EQ(sshbuf_find(p1, 32, "ping", 4, &sz),
211 SSH_ERR_MESSAGE_INCOMPLETE);
212 ASSERT_INT_EQ(sshbuf_find(p1, 1000, "silence", 7, &sz),
213 SSH_ERR_MESSAGE_INCOMPLETE);
214 ASSERT_INT_EQ(sshbuf_find(p1, 0, msg + 1, sizeof(msg) - 2, &sz), 0);
215 ASSERT_SIZE_T_EQ(sz, 1);
216 TEST_DONE();
166} 217}
167 218
diff --git a/regress/unittests/sshbuf/tests.c b/regress/unittests/sshbuf/tests.c
index 1557e4342..29916a10b 100644
--- a/regress/unittests/sshbuf/tests.c
+++ b/regress/unittests/sshbuf/tests.c
@@ -20,7 +20,9 @@ tests(void)
20{ 20{
21 sshbuf_tests(); 21 sshbuf_tests();
22 sshbuf_getput_basic_tests(); 22 sshbuf_getput_basic_tests();
23#ifdef WITH_OPENSSL
23 sshbuf_getput_crypto_tests(); 24 sshbuf_getput_crypto_tests();
25#endif
24 sshbuf_misc_tests(); 26 sshbuf_misc_tests();
25 sshbuf_fuzz_tests(); 27 sshbuf_fuzz_tests();
26 sshbuf_getput_fuzz_tests(); 28 sshbuf_getput_fuzz_tests();
diff --git a/regress/unittests/sshkey/common.c b/regress/unittests/sshkey/common.c
index e63465c47..e21638093 100644
--- a/regress/unittests/sshkey/common.c
+++ b/regress/unittests/sshkey/common.c
@@ -19,13 +19,15 @@
19#include <string.h> 19#include <string.h>
20#include <unistd.h> 20#include <unistd.h>
21 21
22#ifdef WITH_OPENSSL
22#include <openssl/bn.h> 23#include <openssl/bn.h>
23#include <openssl/rsa.h> 24#include <openssl/rsa.h>
24#include <openssl/dsa.h> 25#include <openssl/dsa.h>
25#include <openssl/objects.h> 26#include <openssl/objects.h>
26#ifdef OPENSSL_HAS_NISTP256 27#ifdef OPENSSL_HAS_NISTP256
27# include <openssl/ec.h> 28# include <openssl/ec.h>
28#endif 29#endif /* OPENSSL_HAS_NISTP256 */
30#endif /* WITH_OPENSSL */
29 31
30#include "openbsd-compat/openssl-compat.h" 32#include "openbsd-compat/openssl-compat.h"
31 33
@@ -72,6 +74,7 @@ load_text_file(const char *name)
72 return ret; 74 return ret;
73} 75}
74 76
77#ifdef WITH_OPENSSL
75BIGNUM * 78BIGNUM *
76load_bignum(const char *name) 79load_bignum(const char *name)
77{ 80{
@@ -160,4 +163,5 @@ dsa_priv_key(struct sshkey *k)
160 DSA_get0_key(k->dsa, NULL, &priv_key); 163 DSA_get0_key(k->dsa, NULL, &priv_key);
161 return priv_key; 164 return priv_key;
162} 165}
166#endif /* WITH_OPENSSL */
163 167
diff --git a/regress/unittests/sshkey/test_file.c b/regress/unittests/sshkey/test_file.c
index 65610dacc..55627bc12 100644
--- a/regress/unittests/sshkey/test_file.c
+++ b/regress/unittests/sshkey/test_file.c
@@ -19,13 +19,15 @@
19#include <string.h> 19#include <string.h>
20#include <unistd.h> 20#include <unistd.h>
21 21
22#ifdef WITH_OPENSSL
22#include <openssl/bn.h> 23#include <openssl/bn.h>
23#include <openssl/rsa.h> 24#include <openssl/rsa.h>
24#include <openssl/dsa.h> 25#include <openssl/dsa.h>
25#include <openssl/objects.h> 26#include <openssl/objects.h>
26#ifdef OPENSSL_HAS_NISTP256 27#ifdef OPENSSL_HAS_NISTP256
27# include <openssl/ec.h> 28# include <openssl/ec.h>
28#endif 29#endif /* OPENSSL_HAS_NISTP256 */
30#endif /* WITH_OPENSSL */
29 31
30#include "../test_helper/test_helper.h" 32#include "../test_helper/test_helper.h"
31 33
@@ -44,7 +46,9 @@ sshkey_file_tests(void)
44{ 46{
45 struct sshkey *k1, *k2; 47 struct sshkey *k1, *k2;
46 struct sshbuf *buf, *pw; 48 struct sshbuf *buf, *pw;
49#ifdef WITH_OPENSSL
47 BIGNUM *a, *b, *c; 50 BIGNUM *a, *b, *c;
51#endif
48 char *cp; 52 char *cp;
49 53
50 TEST_START("load passphrase"); 54 TEST_START("load passphrase");
@@ -52,6 +56,7 @@ sshkey_file_tests(void)
52 TEST_DONE(); 56 TEST_DONE();
53 57
54 58
59#ifdef WITH_OPENSSL
55 TEST_START("parse RSA from private"); 60 TEST_START("parse RSA from private");
56 buf = load_file("rsa_1"); 61 buf = load_file("rsa_1");
57 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); 62 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
@@ -350,6 +355,7 @@ sshkey_file_tests(void)
350 355
351 sshkey_free(k1); 356 sshkey_free(k1);
352#endif /* OPENSSL_HAS_ECC */ 357#endif /* OPENSSL_HAS_ECC */
358#endif /* WITH_OPENSSL */
353 359
354 TEST_START("parse Ed25519 from private"); 360 TEST_START("parse Ed25519 from private");
355 buf = load_file("ed25519_1"); 361 buf = load_file("ed25519_1");
diff --git a/regress/unittests/sshkey/test_fuzz.c b/regress/unittests/sshkey/test_fuzz.c
index 5953de595..1323f8997 100644
--- a/regress/unittests/sshkey/test_fuzz.c
+++ b/regress/unittests/sshkey/test_fuzz.c
@@ -113,7 +113,7 @@ sshkey_fuzz_tests(void)
113 struct fuzz *fuzz; 113 struct fuzz *fuzz;
114 int r, i; 114 int r, i;
115 115
116 116#ifdef WITH_OPENSSL
117 TEST_START("fuzz RSA private"); 117 TEST_START("fuzz RSA private");
118 buf = load_file("rsa_1"); 118 buf = load_file("rsa_1");
119 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf), 119 fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf),
@@ -246,7 +246,8 @@ sshkey_fuzz_tests(void)
246 sshbuf_free(fuzzed); 246 sshbuf_free(fuzzed);
247 fuzz_cleanup(fuzz); 247 fuzz_cleanup(fuzz);
248 TEST_DONE(); 248 TEST_DONE();
249#endif 249#endif /* OPENSSL_HAS_ECC */
250#endif /* WITH_OPENSSL */
250 251
251 TEST_START("fuzz Ed25519 private"); 252 TEST_START("fuzz Ed25519 private");
252 buf = load_file("ed25519_1"); 253 buf = load_file("ed25519_1");
@@ -270,6 +271,7 @@ sshkey_fuzz_tests(void)
270 fuzz_cleanup(fuzz); 271 fuzz_cleanup(fuzz);
271 TEST_DONE(); 272 TEST_DONE();
272 273
274#ifdef WITH_OPENSSL
273 TEST_START("fuzz RSA public"); 275 TEST_START("fuzz RSA public");
274 buf = load_file("rsa_1"); 276 buf = load_file("rsa_1");
275 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); 277 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
@@ -312,7 +314,8 @@ sshkey_fuzz_tests(void)
312 public_fuzz(k1); 314 public_fuzz(k1);
313 sshkey_free(k1); 315 sshkey_free(k1);
314 TEST_DONE(); 316 TEST_DONE();
315#endif 317#endif /* OPENSSL_HAS_ECC */
318#endif /* WITH_OPENSSL */
316 319
317 TEST_START("fuzz Ed25519 public"); 320 TEST_START("fuzz Ed25519 public");
318 buf = load_file("ed25519_1"); 321 buf = load_file("ed25519_1");
@@ -328,6 +331,7 @@ sshkey_fuzz_tests(void)
328 sshkey_free(k1); 331 sshkey_free(k1);
329 TEST_DONE(); 332 TEST_DONE();
330 333
334#ifdef WITH_OPENSSL
331 TEST_START("fuzz RSA sig"); 335 TEST_START("fuzz RSA sig");
332 buf = load_file("rsa_1"); 336 buf = load_file("rsa_1");
333 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0); 337 ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
@@ -368,7 +372,8 @@ sshkey_fuzz_tests(void)
368 sig_fuzz(k1, NULL); 372 sig_fuzz(k1, NULL);
369 sshkey_free(k1); 373 sshkey_free(k1);
370 TEST_DONE(); 374 TEST_DONE();
371#endif 375#endif /* OPENSSL_HAS_ECC */
376#endif /* WITH_OPENSSL */
372 377
373 TEST_START("fuzz Ed25519 sig"); 378 TEST_START("fuzz Ed25519 sig");
374 buf = load_file("ed25519_1"); 379 buf = load_file("ed25519_1");
@@ -379,5 +384,6 @@ sshkey_fuzz_tests(void)
379 TEST_DONE(); 384 TEST_DONE();
380 385
381/* XXX fuzz decoded new-format blobs too */ 386/* XXX fuzz decoded new-format blobs too */
387/* XXX fuzz XMSS too */
382 388
383} 389}
diff --git a/regress/unittests/sshkey/test_sshkey.c b/regress/unittests/sshkey/test_sshkey.c
index 47a03fad4..42395b8db 100644
--- a/regress/unittests/sshkey/test_sshkey.c
+++ b/regress/unittests/sshkey/test_sshkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: test_sshkey.c,v 1.17 2018/09/13 09:03:20 djm Exp $ */ 1/* $OpenBSD: test_sshkey.c,v 1.18 2019/06/21 04:21:45 djm Exp $ */
2/* 2/*
3 * Regress test for sshkey.h key management API 3 * Regress test for sshkey.h key management API
4 * 4 *
@@ -50,9 +50,10 @@ put_opt(struct sshbuf *b, const char *name, const char *value)
50 sshbuf_free(sect); 50 sshbuf_free(sect);
51} 51}
52 52
53#ifdef WITH_OPENSSL
53static void 54static void
54build_cert(struct sshbuf *b, const struct sshkey *k, const char *type, 55build_cert(struct sshbuf *b, struct sshkey *k, const char *type,
55 const struct sshkey *sign_key, const struct sshkey *ca_key, 56 struct sshkey *sign_key, struct sshkey *ca_key,
56 const char *sig_alg) 57 const char *sig_alg)
57{ 58{
58 struct sshbuf *ca_buf, *pk, *principals, *critopts, *exts; 59 struct sshbuf *ca_buf, *pk, *principals, *critopts, *exts;
@@ -110,6 +111,7 @@ build_cert(struct sshbuf *b, const struct sshkey *k, const char *type,
110 sshbuf_free(principals); 111 sshbuf_free(principals);
111 sshbuf_free(pk); 112 sshbuf_free(pk);
112} 113}
114#endif /* WITH_OPENSSL */
113 115
114static void 116static void
115signature_test(struct sshkey *k, struct sshkey *bad, const char *sig_alg, 117signature_test(struct sshkey *k, struct sshkey *bad, const char *sig_alg,
@@ -176,10 +178,13 @@ get_private(const char *n)
176void 178void
177sshkey_tests(void) 179sshkey_tests(void)
178{ 180{
179 struct sshkey *k1, *k2, *k3, *k4, *kr, *kd, *kf; 181 struct sshkey *k1, *k2, *k3, *kf;
182#ifdef WITH_OPENSSL
183 struct sshkey *k4, *kr, *kd;
180#ifdef OPENSSL_HAS_ECC 184#ifdef OPENSSL_HAS_ECC
181 struct sshkey *ke; 185 struct sshkey *ke;
182#endif 186#endif /* OPENSSL_HAS_ECC */
187#endif /* WITH_OPENSSL */
183 struct sshbuf *b; 188 struct sshbuf *b;
184 189
185 TEST_START("new invalid"); 190 TEST_START("new invalid");
@@ -193,6 +198,7 @@ sshkey_tests(void)
193 sshkey_free(k1); 198 sshkey_free(k1);
194 TEST_DONE(); 199 TEST_DONE();
195 200
201#ifdef WITH_OPENSSL
196 TEST_START("new/free KEY_RSA"); 202 TEST_START("new/free KEY_RSA");
197 k1 = sshkey_new(KEY_RSA); 203 k1 = sshkey_new(KEY_RSA);
198 ASSERT_PTR_NE(k1, NULL); 204 ASSERT_PTR_NE(k1, NULL);
@@ -281,7 +287,8 @@ sshkey_tests(void)
281 ASSERT_PTR_NE(EC_KEY_get0_public_key(ke->ecdsa), NULL); 287 ASSERT_PTR_NE(EC_KEY_get0_public_key(ke->ecdsa), NULL);
282 ASSERT_PTR_NE(EC_KEY_get0_private_key(ke->ecdsa), NULL); 288 ASSERT_PTR_NE(EC_KEY_get0_private_key(ke->ecdsa), NULL);
283 TEST_DONE(); 289 TEST_DONE();
284#endif 290#endif /* OPENSSL_HAS_ECC */
291#endif /* WITH_OPENSSL */
285 292
286 TEST_START("generate KEY_ED25519"); 293 TEST_START("generate KEY_ED25519");
287 ASSERT_INT_EQ(sshkey_generate(KEY_ED25519, 256, &kf), 0); 294 ASSERT_INT_EQ(sshkey_generate(KEY_ED25519, 256, &kf), 0);
@@ -291,6 +298,7 @@ sshkey_tests(void)
291 ASSERT_PTR_NE(kf->ed25519_sk, NULL); 298 ASSERT_PTR_NE(kf->ed25519_sk, NULL);
292 TEST_DONE(); 299 TEST_DONE();
293 300
301#ifdef WITH_OPENSSL
294 TEST_START("demote KEY_RSA"); 302 TEST_START("demote KEY_RSA");
295 ASSERT_INT_EQ(sshkey_from_private(kr, &k1), 0); 303 ASSERT_INT_EQ(sshkey_from_private(kr, &k1), 0);
296 ASSERT_PTR_NE(k1, NULL); 304 ASSERT_PTR_NE(k1, NULL);
@@ -338,7 +346,8 @@ sshkey_tests(void)
338 ASSERT_INT_EQ(sshkey_equal(ke, k1), 1); 346 ASSERT_INT_EQ(sshkey_equal(ke, k1), 1);
339 sshkey_free(k1); 347 sshkey_free(k1);
340 TEST_DONE(); 348 TEST_DONE();
341#endif 349#endif /* OPENSSL_HAS_ECC */
350#endif /* WITH_OPENSSL */
342 351
343 TEST_START("demote KEY_ED25519"); 352 TEST_START("demote KEY_ED25519");
344 ASSERT_INT_EQ(sshkey_from_private(kf, &k1), 0); 353 ASSERT_INT_EQ(sshkey_from_private(kf, &k1), 0);
@@ -354,17 +363,20 @@ sshkey_tests(void)
354 sshkey_free(k1); 363 sshkey_free(k1);
355 TEST_DONE(); 364 TEST_DONE();
356 365
366#ifdef WITH_OPENSSL
357 TEST_START("equal mismatched key types"); 367 TEST_START("equal mismatched key types");
358 ASSERT_INT_EQ(sshkey_equal(kd, kr), 0); 368 ASSERT_INT_EQ(sshkey_equal(kd, kr), 0);
359#ifdef OPENSSL_HAS_ECC 369#ifdef OPENSSL_HAS_ECC
360 ASSERT_INT_EQ(sshkey_equal(kd, ke), 0); 370 ASSERT_INT_EQ(sshkey_equal(kd, ke), 0);
361 ASSERT_INT_EQ(sshkey_equal(kr, ke), 0); 371 ASSERT_INT_EQ(sshkey_equal(kr, ke), 0);
362 ASSERT_INT_EQ(sshkey_equal(ke, kf), 0); 372 ASSERT_INT_EQ(sshkey_equal(ke, kf), 0);
363#endif 373#endif /* OPENSSL_HAS_ECC */
364 ASSERT_INT_EQ(sshkey_equal(kd, kf), 0); 374 ASSERT_INT_EQ(sshkey_equal(kd, kf), 0);
365 TEST_DONE(); 375 TEST_DONE();
376#endif /* WITH_OPENSSL */
366 377
367 TEST_START("equal different keys"); 378 TEST_START("equal different keys");
379#ifdef WITH_OPENSSL
368 ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &k1), 0); 380 ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &k1), 0);
369 ASSERT_INT_EQ(sshkey_equal(kr, k1), 0); 381 ASSERT_INT_EQ(sshkey_equal(kr, k1), 0);
370 sshkey_free(k1); 382 sshkey_free(k1);
@@ -375,17 +387,20 @@ sshkey_tests(void)
375 ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &k1), 0); 387 ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &k1), 0);
376 ASSERT_INT_EQ(sshkey_equal(ke, k1), 0); 388 ASSERT_INT_EQ(sshkey_equal(ke, k1), 0);
377 sshkey_free(k1); 389 sshkey_free(k1);
378#endif 390#endif /* OPENSSL_HAS_ECC */
391#endif /* WITH_OPENSSL */
379 ASSERT_INT_EQ(sshkey_generate(KEY_ED25519, 256, &k1), 0); 392 ASSERT_INT_EQ(sshkey_generate(KEY_ED25519, 256, &k1), 0);
380 ASSERT_INT_EQ(sshkey_equal(kf, k1), 0); 393 ASSERT_INT_EQ(sshkey_equal(kf, k1), 0);
381 sshkey_free(k1); 394 sshkey_free(k1);
382 TEST_DONE(); 395 TEST_DONE();
383 396
397#ifdef WITH_OPENSSL
384 sshkey_free(kr); 398 sshkey_free(kr);
385 sshkey_free(kd); 399 sshkey_free(kd);
386#ifdef OPENSSL_HAS_ECC 400#ifdef OPENSSL_HAS_ECC
387 sshkey_free(ke); 401 sshkey_free(ke);
388#endif 402#endif /* OPENSSL_HAS_ECC */
403#endif /* WITH_OPENSSL */
389 sshkey_free(kf); 404 sshkey_free(kf);
390 405
391 TEST_START("certify key"); 406 TEST_START("certify key");
@@ -434,6 +449,7 @@ sshkey_tests(void)
434 sshbuf_reset(b); 449 sshbuf_reset(b);
435 TEST_DONE(); 450 TEST_DONE();
436 451
452#ifdef WITH_OPENSSL
437 TEST_START("sign and verify RSA"); 453 TEST_START("sign and verify RSA");
438 k1 = get_private("rsa_1"); 454 k1 = get_private("rsa_1");
439 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_2.pub"), &k2, 455 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_2.pub"), &k2,
@@ -479,7 +495,8 @@ sshkey_tests(void)
479 sshkey_free(k1); 495 sshkey_free(k1);
480 sshkey_free(k2); 496 sshkey_free(k2);
481 TEST_DONE(); 497 TEST_DONE();
482#endif 498#endif /* OPENSSL_HAS_ECC */
499#endif /* WITH_OPENSSL */
483 500
484 TEST_START("sign and verify ED25519"); 501 TEST_START("sign and verify ED25519");
485 k1 = get_private("ed25519_1"); 502 k1 = get_private("ed25519_1");
@@ -490,6 +507,7 @@ sshkey_tests(void)
490 sshkey_free(k2); 507 sshkey_free(k2);
491 TEST_DONE(); 508 TEST_DONE();
492 509
510#ifdef WITH_OPENSSL
493 TEST_START("nested certificate"); 511 TEST_START("nested certificate");
494 ASSERT_INT_EQ(sshkey_load_cert(test_data_file("rsa_1"), &k1), 0); 512 ASSERT_INT_EQ(sshkey_load_cert(test_data_file("rsa_1"), &k1), 0);
495 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_1.pub"), &k2, 513 ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_1.pub"), &k2,
@@ -504,5 +522,5 @@ sshkey_tests(void)
504 sshkey_free(k3); 522 sshkey_free(k3);
505 sshbuf_free(b); 523 sshbuf_free(b);
506 TEST_DONE(); 524 TEST_DONE();
507 525#endif /* WITH_OPENSSL */
508} 526}
diff --git a/regress/unittests/sshkey/testdata/ed25519_1_pw b/regress/unittests/sshkey/testdata/ed25519_1_pw
index c3b7ae7f8..da94d2b8e 100644
--- a/regress/unittests/sshkey/testdata/ed25519_1_pw
+++ b/regress/unittests/sshkey/testdata/ed25519_1_pw
@@ -1,8 +1,8 @@
1-----BEGIN OPENSSH PRIVATE KEY----- 1-----BEGIN OPENSSH PRIVATE KEY-----
2b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jYmMAAAAGYmNyeXB0AAAAGAAAABCus+kaow 2b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABDKT56mBA
3AUjHphacvRp98dAAAAEAAAAAEAAAAzAAAAC3NzaC1lZDI1NTE5AAAAIFOG6kY7Rf4UtCFv 3tXIMsWqmuuA2gdAAAAEAAAAAEAAAAzAAAAC3NzaC1lZDI1NTE5AAAAIFOG6kY7Rf4UtCFv
4PwKgo/BztXck2xC4a2WyA34XtIwZAAAAoJaqqgiYQuElraJAmYOm7Tb4nJ3eI4oj9mQ52M 4PwKgo/BztXck2xC4a2WyA34XtIwZAAAAoC13U47yfUOSZJePNUAwWXuFOk3aOKwPM5PMvK
5/Yd+ION2Ur1v8BDewpDX+LHEYgKHo3Mlmcn2UyF+QJ+7xUCW7QCtk/4szrJzw74DlEl6mH 50zwRnMZZjgn+tsMAYPwhsT3Mx3h5QzvVGFyFEqsiK7j4vAotD+LVQeBN5TwWbUBx4lnoGs
6T8PT/f/av7PpECBD/YD3NoDlB9OWm/Q4sHcxfBEKfTGD7s2Onn71HgrdEOPqd4Sj/IQigR 63iAfYVDakO/gNvVBDDGOqv5kdCc4cgn5HacjHQLKOAx6KzHe7JFn7uCywMdVVQjlpI6LHb
7drfjtXEMlD32k9n3dd2eS9x7AHWYaGFEMkOcY= 7mHkaKiVX/C2oiRnsoe17HZ8Fxyt3vd1qNM8BE=
8-----END OPENSSH PRIVATE KEY----- 8-----END OPENSSH PRIVATE KEY-----
diff --git a/regress/unittests/test_helper/test_helper.c b/regress/unittests/test_helper/test_helper.c
index e7a47b265..9014ce8e4 100644
--- a/regress/unittests/test_helper/test_helper.c
+++ b/regress/unittests/test_helper/test_helper.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: test_helper.c,v 1.11 2018/11/23 02:53:57 dtucker Exp $ */ 1/* $OpenBSD: test_helper.c,v 1.12 2019/08/02 01:41:24 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org>
4 * 4 *
@@ -23,6 +23,7 @@
23#include <sys/param.h> 23#include <sys/param.h>
24#include <sys/uio.h> 24#include <sys/uio.h>
25 25
26#include <stdarg.h>
26#include <fcntl.h> 27#include <fcntl.h>
27#include <stdio.h> 28#include <stdio.h>
28#ifdef HAVE_STDINT_H 29#ifdef HAVE_STDINT_H
@@ -34,8 +35,10 @@
34#include <unistd.h> 35#include <unistd.h>
35#include <signal.h> 36#include <signal.h>
36 37
38#ifdef WITH_OPENSSL
37#include <openssl/bn.h> 39#include <openssl/bn.h>
38#include <openssl/err.h> 40#include <openssl/err.h>
41#endif
39 42
40#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) && !defined(BROKEN_STRNVIS) 43#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) && !defined(BROKEN_STRNVIS)
41# include <vis.h> 44# include <vis.h>
@@ -126,7 +129,9 @@ main(int argc, char **argv)
126 int ch; 129 int ch;
127 130
128 seed_rng(); 131 seed_rng();
132#ifdef WITH_OPENSSL
129 ERR_load_CRYPTO_strings(); 133 ERR_load_CRYPTO_strings();
134#endif
130 135
131 /* Handle systems without __progname */ 136 /* Handle systems without __progname */
132 if (__progname == NULL) { 137 if (__progname == NULL) {
@@ -287,6 +292,7 @@ test_subtest_info(const char *fmt, ...)
287void 292void
288ssl_err_check(const char *file, int line) 293ssl_err_check(const char *file, int line)
289{ 294{
295#ifdef WITH_OPENSSL
290 long openssl_error = ERR_get_error(); 296 long openssl_error = ERR_get_error();
291 297
292 if (openssl_error == 0) 298 if (openssl_error == 0)
@@ -294,6 +300,10 @@ ssl_err_check(const char *file, int line)
294 300
295 fprintf(stderr, "\n%s:%d: uncaught OpenSSL error: %s", 301 fprintf(stderr, "\n%s:%d: uncaught OpenSSL error: %s",
296 file, line, ERR_error_string(openssl_error, NULL)); 302 file, line, ERR_error_string(openssl_error, NULL));
303#else /* WITH_OPENSSL */
304 fprintf(stderr, "\n%s:%d: uncaught OpenSSL error ",
305 file, line);
306#endif /* WITH_OPENSSL */
297 abort(); 307 abort();
298} 308}
299 309
@@ -338,6 +348,7 @@ test_header(const char *file, int line, const char *a1, const char *a2,
338 a2 != NULL ? ", " : "", a2 != NULL ? a2 : ""); 348 a2 != NULL ? ", " : "", a2 != NULL ? a2 : "");
339} 349}
340 350
351#ifdef WITH_OPENSSL
341void 352void
342assert_bignum(const char *file, int line, const char *a1, const char *a2, 353assert_bignum(const char *file, int line, const char *a1, const char *a2,
343 const BIGNUM *aa1, const BIGNUM *aa2, enum test_predicate pred) 354 const BIGNUM *aa1, const BIGNUM *aa2, enum test_predicate pred)
@@ -350,6 +361,7 @@ assert_bignum(const char *file, int line, const char *a1, const char *a2,
350 fprintf(stderr, "%12s = 0x%s\n", a2, BN_bn2hex(aa2)); 361 fprintf(stderr, "%12s = 0x%s\n", a2, BN_bn2hex(aa2));
351 test_die(); 362 test_die();
352} 363}
364#endif
353 365
354void 366void
355assert_string(const char *file, int line, const char *a1, const char *a2, 367assert_string(const char *file, int line, const char *a1, const char *a2,
@@ -391,6 +403,8 @@ assert_mem(const char *file, int line, const char *a1, const char *a2,
391 const void *aa1, const void *aa2, size_t l, enum test_predicate pred) 403 const void *aa1, const void *aa2, size_t l, enum test_predicate pred)
392{ 404{
393 int r; 405 int r;
406 char *aa1_tohex = NULL;
407 char *aa2_tohex = NULL;
394 408
395 if (l == 0) 409 if (l == 0)
396 return; 410 return;
@@ -401,8 +415,12 @@ assert_mem(const char *file, int line, const char *a1, const char *a2,
401 r = memcmp(aa1, aa2, l); 415 r = memcmp(aa1, aa2, l);
402 TEST_CHECK_INT(r, pred); 416 TEST_CHECK_INT(r, pred);
403 test_header(file, line, a1, a2, "STRING", pred); 417 test_header(file, line, a1, a2, "STRING", pred);
404 fprintf(stderr, "%12s = %s (len %zu)\n", a1, tohex(aa1, MIN(l, 256)), l); 418 aa1_tohex = tohex(aa1, MIN(l, 256));
405 fprintf(stderr, "%12s = %s (len %zu)\n", a2, tohex(aa2, MIN(l, 256)), l); 419 aa2_tohex = tohex(aa2, MIN(l, 256));
420 fprintf(stderr, "%12s = %s (len %zu)\n", a1, aa1_tohex, l);
421 fprintf(stderr, "%12s = %s (len %zu)\n", a2, aa2_tohex, l);
422 free(aa1_tohex);
423 free(aa2_tohex);
406 test_die(); 424 test_die();
407} 425}
408 426
@@ -427,6 +445,7 @@ assert_mem_filled(const char *file, int line, const char *a1,
427 size_t where = -1; 445 size_t where = -1;
428 int r; 446 int r;
429 char tmp[64]; 447 char tmp[64];
448 char *aa1_tohex = NULL;
430 449
431 if (l == 0) 450 if (l == 0)
432 return; 451 return;
@@ -436,8 +455,10 @@ assert_mem_filled(const char *file, int line, const char *a1,
436 r = memvalcmp(aa1, v, l, &where); 455 r = memvalcmp(aa1, v, l, &where);
437 TEST_CHECK_INT(r, pred); 456 TEST_CHECK_INT(r, pred);
438 test_header(file, line, a1, NULL, "MEM_ZERO", pred); 457 test_header(file, line, a1, NULL, "MEM_ZERO", pred);
458 aa1_tohex = tohex(aa1, MIN(l, 20));
439 fprintf(stderr, "%20s = %s%s (len %zu)\n", a1, 459 fprintf(stderr, "%20s = %s%s (len %zu)\n", a1,
440 tohex(aa1, MIN(l, 20)), l > 20 ? "..." : "", l); 460 aa1_tohex, l > 20 ? "..." : "", l);
461 free(aa1_tohex);
441 snprintf(tmp, sizeof(tmp), "(%s)[%zu]", a1, where); 462 snprintf(tmp, sizeof(tmp), "(%s)[%zu]", a1, where);
442 fprintf(stderr, "%20s = 0x%02x (expected 0x%02x)\n", tmp, 463 fprintf(stderr, "%20s = 0x%02x (expected 0x%02x)\n", tmp,
443 ((u_char *)aa1)[where], v); 464 ((u_char *)aa1)[where], v);
diff --git a/regress/unittests/test_helper/test_helper.h b/regress/unittests/test_helper/test_helper.h
index 1f893c8dd..66302201c 100644
--- a/regress/unittests/test_helper/test_helper.h
+++ b/regress/unittests/test_helper/test_helper.h
@@ -27,8 +27,10 @@
27# include <stdint.h> 27# include <stdint.h>
28#endif 28#endif
29 29
30#ifdef WITH_OPENSSL
30#include <openssl/bn.h> 31#include <openssl/bn.h>
31#include <openssl/err.h> 32#include <openssl/err.h>
33#endif
32 34
33enum test_predicate { 35enum test_predicate {
34 TEST_EQ, TEST_NE, TEST_LT, TEST_LE, TEST_GT, TEST_GE 36 TEST_EQ, TEST_NE, TEST_LT, TEST_LE, TEST_GT, TEST_GE
@@ -50,9 +52,11 @@ int test_is_slow(void);
50void test_subtest_info(const char *fmt, ...) 52void test_subtest_info(const char *fmt, ...)
51 __attribute__((format(printf, 1, 2))); 53 __attribute__((format(printf, 1, 2)));
52void ssl_err_check(const char *file, int line); 54void ssl_err_check(const char *file, int line);
55#ifdef WITH_OPENSSL
53void assert_bignum(const char *file, int line, 56void assert_bignum(const char *file, int line,
54 const char *a1, const char *a2, 57 const char *a1, const char *a2,
55 const BIGNUM *aa1, const BIGNUM *aa2, enum test_predicate pred); 58 const BIGNUM *aa1, const BIGNUM *aa2, enum test_predicate pred);
59#endif
56void assert_string(const char *file, int line, 60void assert_string(const char *file, int line,
57 const char *a1, const char *a2, 61 const char *a1, const char *a2,
58 const char *aa1, const char *aa2, enum test_predicate pred); 62 const char *aa1, const char *aa2, enum test_predicate pred);
diff --git a/regress/unittests/utf8/tests.c b/regress/unittests/utf8/tests.c
index f0bbca509..8cf524ddb 100644
--- a/regress/unittests/utf8/tests.c
+++ b/regress/unittests/utf8/tests.c
@@ -9,7 +9,9 @@
9#include "includes.h" 9#include "includes.h"
10 10
11#include <locale.h> 11#include <locale.h>
12#include <stdarg.h>
12#include <string.h> 13#include <string.h>
14#include <stdio.h>
13 15
14#include "../test_helper/test_helper.h" 16#include "../test_helper/test_helper.h"
15 17