View | Details | Raw Unified | Return to bug 2954
Collapse All | Expand All

(-)a/regress/unittests/bitmap/tests.c (-1 / +5 lines)
Lines 16-22 Link Here
16
#include <stdlib.h>
16
#include <stdlib.h>
17
#include <string.h>
17
#include <string.h>
18
18
19
#include <openssl/bn.h>
19
#ifdef WITH_OPENSSL
20
# include <openssl/bn.h>
21
#endif /* WITH_OPENSSL */
20
22
21
#include "../test_helper/test_helper.h"
23
#include "../test_helper/test_helper.h"
22
24
Lines 27-32 Link Here
27
void
29
void
28
tests(void)
30
tests(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;
Lines 131-135 tests(void) Link Here
131
	bitmap_free(b);
134
	bitmap_free(b);
132
	BN_free(bn);
135
	BN_free(bn);
133
	TEST_DONE();
136
	TEST_DONE();
137
#endif /* WITH_OPENSSL */
134
}
138
}
135
139
(-)a/regress/unittests/hostkeys/test_iterate.c (+15 lines)
Lines 90-95 check(struct hostkey_foreach_line *l, void *_ctx) Link Here
90
	expected_keytype = (parse_key || expected->no_parse_keytype < 0) ?
90
	expected_keytype = (parse_key || expected->no_parse_keytype < 0) ?
91
	    expected->l.keytype : expected->no_parse_keytype;
91
	    expected->l.keytype : expected->no_parse_keytype;
92
92
93
#ifndef WITH_OPENSSL
94
	if (expected->l.keytype == KEY_RSA ||
95
	    expected->l.keytype == KEY_DSA ||
96
	    expected->no_parse_keytype == KEY_RSA ||
97
	    expected->no_parse_keytype == KEY_DSA ) {
98
		expected_status = HKF_STATUS_INVALID;
99
		expected_keytype = KEY_UNSPEC;
100
		parse_key = 0;
101
	}
102
#endif /* WITH_OPENSSL */
93
#ifndef OPENSSL_HAS_ECC
103
#ifndef OPENSSL_HAS_ECC
94
	if (expected->l.keytype == KEY_ECDSA ||
104
	if (expected->l.keytype == KEY_ECDSA ||
95
	    expected->no_parse_keytype == KEY_ECDSA) {
105
	    expected->no_parse_keytype == KEY_ECDSA) {
Lines 142-147 prepare_expected(struct expected *expected, size_t n) Link Here
142
	for (i = 0; i < n; i++) {
152
	for (i = 0; i < n; i++) {
143
		if (expected[i].key_file == NULL)
153
		if (expected[i].key_file == NULL)
144
			continue;
154
			continue;
155
#ifndef WITH_OPENSSL
156
		if (expected[i].l.keytype == KEY_RSA ||
157
		    expected[i].l.keytype == KEY_DSA)
158
			continue;
159
#endif /* WITH_OPENSSL */
145
#ifndef OPENSSL_HAS_ECC
160
#ifndef OPENSSL_HAS_ECC
146
		if (expected[i].l.keytype == KEY_ECDSA)
161
		if (expected[i].l.keytype == KEY_ECDSA)
147
			continue;
162
			continue;
(-)a/regress/unittests/kex/test_kex.c (-4 / +10 lines)
Lines 144-153 do_kex_with_key(char *kex, int keytype, int bits) Link Here
144
	sshbuf_free(state);
144
	sshbuf_free(state);
145
	ASSERT_PTR_NE(server2->kex, NULL);
145
	ASSERT_PTR_NE(server2->kex, NULL);
146
	/* XXX we need to set the callbacks */
146
	/* XXX we need to set the callbacks */
147
#ifdef WITH_OPENSSL
147
	server2->kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
148
	server2->kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
148
	server2->kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server;
149
	server2->kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server;
149
	server2->kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
150
	server2->kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
150
	server2->kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
151
	server2->kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
152
#endif /* WITH_OPENSSL */
151
#ifdef OPENSSL_HAS_ECC
153
#ifdef OPENSSL_HAS_ECC
152
	server2->kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
154
	server2->kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
153
#endif
155
#endif
Lines 177-187 do_kex_with_key(char *kex, int keytype, int bits) Link Here
177
static void
179
static void
178
do_kex(char *kex)
180
do_kex(char *kex)
179
{
181
{
182
#ifdef WITH_OPENSSL
180
	do_kex_with_key(kex, KEY_RSA, 2048);
183
	do_kex_with_key(kex, KEY_RSA, 2048);
181
	do_kex_with_key(kex, KEY_DSA, 1024);
184
	do_kex_with_key(kex, KEY_DSA, 1024);
182
#ifdef OPENSSL_HAS_ECC
185
# ifdef OPENSSL_HAS_ECC
183
	do_kex_with_key(kex, KEY_ECDSA, 256);
186
	do_kex_with_key(kex, KEY_ECDSA, 256);
184
#endif
187
# endif /* OPENSSL_HAS_ECC */
188
#endif /* WITH_OPENSSL */
185
	do_kex_with_key(kex, KEY_ED25519, 256);
189
	do_kex_with_key(kex, KEY_ED25519, 256);
186
}
190
}
187
191
Lines 189-201 void Link Here
189
kex_tests(void)
193
kex_tests(void)
190
{
194
{
191
	do_kex("curve25519-sha256@libssh.org");
195
	do_kex("curve25519-sha256@libssh.org");
192
#ifdef OPENSSL_HAS_ECC
196
#ifdef WITH_OPENSSL
197
# ifdef OPENSSL_HAS_ECC
193
	do_kex("ecdh-sha2-nistp256");
198
	do_kex("ecdh-sha2-nistp256");
194
	do_kex("ecdh-sha2-nistp384");
199
	do_kex("ecdh-sha2-nistp384");
195
	do_kex("ecdh-sha2-nistp521");
200
	do_kex("ecdh-sha2-nistp521");
196
#endif
201
# endif /* OPENSSL_HAS_ECC */
197
	do_kex("diffie-hellman-group-exchange-sha256");
202
	do_kex("diffie-hellman-group-exchange-sha256");
198
	do_kex("diffie-hellman-group-exchange-sha1");
203
	do_kex("diffie-hellman-group-exchange-sha1");
199
	do_kex("diffie-hellman-group14-sha1");
204
	do_kex("diffie-hellman-group14-sha1");
200
	do_kex("diffie-hellman-group1-sha1");
205
	do_kex("diffie-hellman-group1-sha1");
206
#endif /* WITH_OPENSSL */
201
}
207
}
(-)a/regress/unittests/sshbuf/test_sshbuf_getput_crypto.c (-9 / +13 lines)
Lines 16-26 Link Here
16
#include <stdlib.h>
16
#include <stdlib.h>
17
#include <string.h>
17
#include <string.h>
18
18
19
#include <openssl/bn.h>
19
#ifdef WITH_OPENSSL
20
#include <openssl/objects.h>
20
# include <openssl/bn.h>
21
#ifdef OPENSSL_HAS_NISTP256
21
# include <openssl/objects.h>
22
# include <openssl/ec.h>
22
# ifdef OPENSSL_HAS_NISTP256
23
#endif
23
#  include <openssl/ec.h>
24
# endif
25
#endif /* WITH_OPENSSL */
24
26
25
#include "../test_helper/test_helper.h"
27
#include "../test_helper/test_helper.h"
26
#include "ssherr.h"
28
#include "ssherr.h"
Lines 31-36 void sshbuf_getput_crypto_tests(void); Link Here
31
void
33
void
32
sshbuf_getput_crypto_tests(void)
34
sshbuf_getput_crypto_tests(void)
33
{
35
{
36
#ifdef WITH_OPENSSL
34
	struct sshbuf *p1;
37
	struct sshbuf *p1;
35
	BIGNUM *bn, *bn2;
38
	BIGNUM *bn, *bn2;
36
	/* This one has num_bits != num_bytes * 8 to test bignum1 encoding */
39
	/* This one has num_bits != num_bytes * 8 to test bignum1 encoding */
Lines 46-52 sshbuf_getput_crypto_tests(void) Link Here
46
		0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10, 0x00,
49
		0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10, 0x00,
47
		0x7f, 0xff, 0x11
50
		0x7f, 0xff, 0x11
48
	};
51
	};
49
#if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256)
52
# if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256)
50
	const u_char *d;
53
	const u_char *d;
51
	size_t s;
54
	size_t s;
52
	BIGNUM *bn_x, *bn_y;
55
	BIGNUM *bn_x, *bn_y;
Lines 68-74 sshbuf_getput_crypto_tests(void) Link Here
68
	};
71
	};
69
	EC_KEY *eck;
72
	EC_KEY *eck;
70
	EC_POINT *ecp;
73
	EC_POINT *ecp;
71
#endif
74
# endif
72
	int r;
75
	int r;
73
76
74
#define MKBN(b, bnn) \
77
#define MKBN(b, bnn) \
Lines 352-358 sshbuf_getput_crypto_tests(void) Link Here
352
	sshbuf_free(p1);
355
	sshbuf_free(p1);
353
	TEST_DONE();
356
	TEST_DONE();
354
357
355
#if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256)
358
# if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256)
356
	TEST_START("sshbuf_put_ec");
359
	TEST_START("sshbuf_put_ec");
357
	eck = EC_KEY_new_by_curve_name(ec256_nid);
360
	eck = EC_KEY_new_by_curve_name(ec256_nid);
358
	ASSERT_PTR_NE(eck, NULL);
361
	ASSERT_PTR_NE(eck, NULL);
Lines 404-409 sshbuf_getput_crypto_tests(void) Link Here
404
	BN_free(bn);
407
	BN_free(bn);
405
	BN_free(bn2);
408
	BN_free(bn2);
406
	TEST_DONE();
409
	TEST_DONE();
407
#endif
410
# endif
411
#endif /* WITH_OPENSSL */
408
}
412
}
409
413
(-)a/regress/unittests/sshbuf/test_sshbuf_getput_fuzz.c (-4 / +8 lines)
Lines 32-41 static void Link Here
32
attempt_parse_blob(u_char *blob, size_t len)
32
attempt_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
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;
Lines 54-71 attempt_parse_blob(u_char *blob, size_t len) Link Here
54
		bzero(s, l);
56
		bzero(s, l);
55
		free(s);
57
		free(s);
56
	}
58
	}
59
#ifdef WITH_OPENSSL
57
	bn = BN_new();
60
	bn = BN_new();
58
	sshbuf_get_bignum1(p1, bn);
61
	sshbuf_get_bignum1(p1, bn);
59
	BN_clear_free(bn);
62
	BN_clear_free(bn);
60
	bn = BN_new();
63
	bn = BN_new();
61
	sshbuf_get_bignum2(p1, bn);
64
	sshbuf_get_bignum2(p1, bn);
62
	BN_clear_free(bn);
65
	BN_clear_free(bn);
63
#if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256)
66
# if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256)
64
	eck = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
67
	eck = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
65
	ASSERT_PTR_NE(eck, NULL);
68
	ASSERT_PTR_NE(eck, NULL);
66
	sshbuf_get_eckey(p1, eck);
69
	sshbuf_get_eckey(p1, eck);
67
	EC_KEY_free(eck);
70
	EC_KEY_free(eck);
68
#endif
71
# endif
72
#endif /* WITH_OPENSSL */
69
	sshbuf_free(p1);
73
	sshbuf_free(p1);
70
}
74
}
71
75
(-)a/regress/unittests/sshkey/common.c (-8 / +11 lines)
Lines 19-31 Link Here
19
#include <string.h>
19
#include <string.h>
20
#include <unistd.h>
20
#include <unistd.h>
21
21
22
#include <openssl/bn.h>
22
#ifdef WITH_OPENSSL
23
#include <openssl/rsa.h>
23
# include <openssl/bn.h>
24
#include <openssl/dsa.h>
24
# include <openssl/rsa.h>
25
#include <openssl/objects.h>
25
# include <openssl/dsa.h>
26
#ifdef OPENSSL_HAS_NISTP256
26
# include <openssl/objects.h>
27
# include <openssl/ec.h>
27
# ifdef OPENSSL_HAS_NISTP256
28
#endif
28
#  include <openssl/ec.h>
29
# endif
30
#endif /* WITH_OPENSSL */
29
31
30
#include "openbsd-compat/openssl-compat.h"
32
#include "openbsd-compat/openssl-compat.h"
31
33
Lines 72-77 load_text_file(const char *name) Link Here
72
	return ret;
74
	return ret;
73
}
75
}
74
76
77
#ifdef WITH_OPENSSL
75
BIGNUM *
78
BIGNUM *
76
load_bignum(const char *name)
79
load_bignum(const char *name)
77
{
80
{
Lines 160-163 dsa_priv_key(struct sshkey *k) Link Here
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
}
163
166
#endif /* WITH_OPENSSL */
(-)a/regress/unittests/sshkey/common.h (-1 / +2 lines)
Lines 11-16 struct sshbuf *load_file(const char *name); Link Here
11
/* Load a text file into a buffer */
11
/* Load a text file into a buffer */
12
struct sshbuf *load_text_file(const char *name);
12
struct sshbuf *load_text_file(const char *name);
13
13
14
#ifdef WITH_OPENSSL
14
/* Load a bignum from a file */
15
/* Load a bignum from a file */
15
BIGNUM *load_bignum(const char *name);
16
BIGNUM *load_bignum(const char *name);
16
17
Lines 22-25 const BIGNUM *rsa_q(struct sshkey *k); Link Here
22
const BIGNUM *dsa_g(struct sshkey *k);
23
const BIGNUM *dsa_g(struct sshkey *k);
23
const BIGNUM *dsa_pub_key(struct sshkey *k);
24
const BIGNUM *dsa_pub_key(struct sshkey *k);
24
const BIGNUM *dsa_priv_key(struct sshkey *k);
25
const BIGNUM *dsa_priv_key(struct sshkey *k);
25
26
#endif /* WITH_OPENSSL */
(-)a/regress/unittests/sshkey/test_file.c (-10 / +15 lines)
Lines 19-31 Link Here
19
#include <string.h>
19
#include <string.h>
20
#include <unistd.h>
20
#include <unistd.h>
21
21
22
#include <openssl/bn.h>
22
#ifdef WITH_OPENSSL
23
#include <openssl/rsa.h>
23
# include <openssl/bn.h>
24
#include <openssl/dsa.h>
24
# include <openssl/rsa.h>
25
#include <openssl/objects.h>
25
# include <openssl/dsa.h>
26
#ifdef OPENSSL_HAS_NISTP256
26
# include <openssl/objects.h>
27
# include <openssl/ec.h>
27
# ifdef OPENSSL_HAS_NISTP256
28
#endif
28
#  include <openssl/ec.h>
29
# endif
30
#endif /* WITH_OPENSSL */
29
31
30
#include "../test_helper/test_helper.h"
32
#include "../test_helper/test_helper.h"
31
33
Lines 51-57 sshkey_file_tests(void) Link Here
51
	pw = load_text_file("pw");
53
	pw = load_text_file("pw");
52
	TEST_DONE();
54
	TEST_DONE();
53
55
54
56
#ifdef WITH_OPENSSL
55
	TEST_START("parse RSA from private");
57
	TEST_START("parse RSA from private");
56
	buf = load_file("rsa_1");
58
	buf = load_file("rsa_1");
57
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
59
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
Lines 252-258 sshkey_file_tests(void) Link Here
252
254
253
	sshkey_free(k1);
255
	sshkey_free(k1);
254
256
255
#ifdef OPENSSL_HAS_ECC
257
# ifdef OPENSSL_HAS_ECC
256
	TEST_START("parse ECDSA from private");
258
	TEST_START("parse ECDSA from private");
257
	buf = load_file("ecdsa_1");
259
	buf = load_file("ecdsa_1");
258
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
260
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
Lines 349-355 sshkey_file_tests(void) Link Here
349
	TEST_DONE();
351
	TEST_DONE();
350
352
351
	sshkey_free(k1);
353
	sshkey_free(k1);
352
#endif /* OPENSSL_HAS_ECC */
354
# endif /* OPENSSL_HAS_ECC */
355
#endif /* WITH_OPENSSL */
353
356
354
	TEST_START("parse Ed25519 from private");
357
	TEST_START("parse Ed25519 from private");
355
	buf = load_file("ed25519_1");
358
	buf = load_file("ed25519_1");
Lines 360-365 sshkey_file_tests(void) Link Here
360
	/* XXX check key contents */
363
	/* XXX check key contents */
361
	TEST_DONE();
364
	TEST_DONE();
362
365
366
#ifdef WITH_OPENSSL /* The OpenSSL is needed for decryption ? */
363
	TEST_START("parse Ed25519 from private w/ passphrase");
367
	TEST_START("parse Ed25519 from private w/ passphrase");
364
	buf = load_file("ed25519_1_pw");
368
	buf = load_file("ed25519_1_pw");
365
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
369
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf,
Lines 369-374 sshkey_file_tests(void) Link Here
369
	ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
373
	ASSERT_INT_EQ(sshkey_equal(k1, k2), 1);
370
	sshkey_free(k2);
374
	sshkey_free(k2);
371
	TEST_DONE();
375
	TEST_DONE();
376
#endif /* WITH_OPENSSL */
372
377
373
	TEST_START("load Ed25519 from public");
378
	TEST_START("load Ed25519 from public");
374
	ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_1.pub"), &k2,
379
	ASSERT_INT_EQ(sshkey_load_public(test_data_file("ed25519_1.pub"), &k2,
(-)a/regress/unittests/sshkey/test_fuzz.c (-14 / +21 lines)
Lines 19-31 Link Here
19
#include <string.h>
19
#include <string.h>
20
#include <unistd.h>
20
#include <unistd.h>
21
21
22
#include <openssl/bn.h>
22
#ifdef WITH_OPENSSL
23
#include <openssl/rsa.h>
23
# include <openssl/bn.h>
24
#include <openssl/dsa.h>
24
# include <openssl/rsa.h>
25
#include <openssl/objects.h>
25
# include <openssl/dsa.h>
26
#ifdef OPENSSL_HAS_NISTP256
26
# include <openssl/objects.h>
27
# include <openssl/ec.h>
27
# ifdef OPENSSL_HAS_NISTP256
28
#endif
28
#  include <openssl/ec.h>
29
# endif
30
#endif /* WITH_OPENSSL */
29
31
30
#include "../test_helper/test_helper.h"
32
#include "../test_helper/test_helper.h"
31
33
Lines 113-119 sshkey_fuzz_tests(void) Link Here
113
	struct fuzz *fuzz;
115
	struct fuzz *fuzz;
114
	int r, i;
116
	int r, i;
115
117
116
118
#ifdef WITH_OPENSSL
117
	TEST_START("fuzz RSA private");
119
	TEST_START("fuzz RSA private");
118
	buf = load_file("rsa_1");
120
	buf = load_file("rsa_1");
119
	fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf),
121
	fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf),
Lines 202-208 sshkey_fuzz_tests(void) Link Here
202
	fuzz_cleanup(fuzz);
204
	fuzz_cleanup(fuzz);
203
	TEST_DONE();
205
	TEST_DONE();
204
206
205
#ifdef OPENSSL_HAS_ECC
207
# ifdef OPENSSL_HAS_ECC
206
	TEST_START("fuzz ECDSA private");
208
	TEST_START("fuzz ECDSA private");
207
	buf = load_file("ecdsa_1");
209
	buf = load_file("ecdsa_1");
208
	fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf),
210
	fuzz = fuzz_begin(FUZZ_BASE64, sshbuf_mutable_ptr(buf),
Lines 246-252 sshkey_fuzz_tests(void) Link Here
246
	sshbuf_free(fuzzed);
248
	sshbuf_free(fuzzed);
247
	fuzz_cleanup(fuzz);
249
	fuzz_cleanup(fuzz);
248
	TEST_DONE();
250
	TEST_DONE();
249
#endif
251
# endif /* OPENSSL_HAS_ECC */
252
#endif /* WITH_OPENSSL */
250
253
251
	TEST_START("fuzz Ed25519 private");
254
	TEST_START("fuzz Ed25519 private");
252
	buf = load_file("ed25519_1");
255
	buf = load_file("ed25519_1");
Lines 270-275 sshkey_fuzz_tests(void) Link Here
270
	fuzz_cleanup(fuzz);
273
	fuzz_cleanup(fuzz);
271
	TEST_DONE();
274
	TEST_DONE();
272
275
276
#ifdef WITH_OPENSSL
273
	TEST_START("fuzz RSA public");
277
	TEST_START("fuzz RSA public");
274
	buf = load_file("rsa_1");
278
	buf = load_file("rsa_1");
275
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
279
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
Lines 298-304 sshkey_fuzz_tests(void) Link Here
298
	sshkey_free(k1);
302
	sshkey_free(k1);
299
	TEST_DONE();
303
	TEST_DONE();
300
304
301
#ifdef OPENSSL_HAS_ECC
305
# ifdef OPENSSL_HAS_ECC
302
	TEST_START("fuzz ECDSA public");
306
	TEST_START("fuzz ECDSA public");
303
	buf = load_file("ecdsa_1");
307
	buf = load_file("ecdsa_1");
304
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
308
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
Lines 312-318 sshkey_fuzz_tests(void) Link Here
312
	public_fuzz(k1);
316
	public_fuzz(k1);
313
	sshkey_free(k1);
317
	sshkey_free(k1);
314
	TEST_DONE();
318
	TEST_DONE();
315
#endif
319
# endif /* OPENSSL_HAS_ECC */
320
#endif /* WITH_OPENSSL */
316
321
317
	TEST_START("fuzz Ed25519 public");
322
	TEST_START("fuzz Ed25519 public");
318
	buf = load_file("ed25519_1");
323
	buf = load_file("ed25519_1");
Lines 328-333 sshkey_fuzz_tests(void) Link Here
328
	sshkey_free(k1);
333
	sshkey_free(k1);
329
	TEST_DONE();
334
	TEST_DONE();
330
335
336
#ifdef WITH_OPENSSL
331
	TEST_START("fuzz RSA sig");
337
	TEST_START("fuzz RSA sig");
332
	buf = load_file("rsa_1");
338
	buf = load_file("rsa_1");
333
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
339
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
Lines 360-366 sshkey_fuzz_tests(void) Link Here
360
	sshkey_free(k1);
366
	sshkey_free(k1);
361
	TEST_DONE();
367
	TEST_DONE();
362
368
363
#ifdef OPENSSL_HAS_ECC
369
# ifdef OPENSSL_HAS_ECC
364
	TEST_START("fuzz ECDSA sig");
370
	TEST_START("fuzz ECDSA sig");
365
	buf = load_file("ecdsa_1");
371
	buf = load_file("ecdsa_1");
366
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
372
	ASSERT_INT_EQ(sshkey_parse_private_fileblob(buf, "", &k1, NULL), 0);
Lines 368-374 sshkey_fuzz_tests(void) Link Here
368
	sig_fuzz(k1, NULL);
374
	sig_fuzz(k1, NULL);
369
	sshkey_free(k1);
375
	sshkey_free(k1);
370
	TEST_DONE();
376
	TEST_DONE();
371
#endif
377
# endif /* OPENSSL_HAS_ECC */
378
#endif /* WITH_OPENSSL */
372
379
373
	TEST_START("fuzz Ed25519 sig");
380
	TEST_START("fuzz Ed25519 sig");
374
	buf = load_file("ed25519_1");
381
	buf = load_file("ed25519_1");
(-)a/regress/unittests/sshkey/test_sshkey.c (-18 / +32 lines)
Lines 16-27 Link Here
16
#include <stdlib.h>
16
#include <stdlib.h>
17
#include <string.h>
17
#include <string.h>
18
18
19
#include <openssl/bn.h>
19
#ifdef WITH_OPENSSL
20
#include <openssl/rsa.h>
20
# include <openssl/bn.h>
21
#include <openssl/dsa.h>
21
# include <openssl/rsa.h>
22
#if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256)
22
# include <openssl/dsa.h>
23
# include <openssl/ec.h>
23
# if defined(OPENSSL_HAS_ECC) && defined(OPENSSL_HAS_NISTP256)
24
#endif
24
#  include <openssl/ec.h>
25
# endif
26
#endif /* WITH_OPENSSL */
25
27
26
#include "../test_helper/test_helper.h"
28
#include "../test_helper/test_helper.h"
27
29
Lines 193-198 sshkey_tests(void) Link Here
193
	sshkey_free(k1);
195
	sshkey_free(k1);
194
	TEST_DONE();
196
	TEST_DONE();
195
197
198
#ifdef WITH_OPENSSL
196
	TEST_START("new/free KEY_RSA");
199
	TEST_START("new/free KEY_RSA");
197
	k1 = sshkey_new(KEY_RSA);
200
	k1 = sshkey_new(KEY_RSA);
198
	ASSERT_PTR_NE(k1, NULL);
201
	ASSERT_PTR_NE(k1, NULL);
Lines 207-220 sshkey_tests(void) Link Here
207
	sshkey_free(k1);
210
	sshkey_free(k1);
208
	TEST_DONE();
211
	TEST_DONE();
209
212
210
#ifdef OPENSSL_HAS_ECC
213
# ifdef OPENSSL_HAS_ECC
211
	TEST_START("new/free KEY_ECDSA");
214
	TEST_START("new/free KEY_ECDSA");
212
	k1 = sshkey_new(KEY_ECDSA);
215
	k1 = sshkey_new(KEY_ECDSA);
213
	ASSERT_PTR_NE(k1, NULL);
216
	ASSERT_PTR_NE(k1, NULL);
214
	ASSERT_PTR_EQ(k1->ecdsa, NULL);  /* Can't allocate without NID */
217
	ASSERT_PTR_EQ(k1->ecdsa, NULL);  /* Can't allocate without NID */
215
	sshkey_free(k1);
218
	sshkey_free(k1);
216
	TEST_DONE();
219
	TEST_DONE();
217
#endif
220
# endif /* OPENSSL_HAS_ECC */
221
#endif /* WITH_OPENSSL */
218
222
219
	TEST_START("new/free KEY_ED25519");
223
	TEST_START("new/free KEY_ED25519");
220
	k1 = sshkey_new(KEY_ED25519);
224
	k1 = sshkey_new(KEY_ED25519);
Lines 225-230 sshkey_tests(void) Link Here
225
	sshkey_free(k1);
229
	sshkey_free(k1);
226
	TEST_DONE();
230
	TEST_DONE();
227
231
232
#ifdef WITH_OPENSSL
228
	TEST_START("generate KEY_RSA too small modulus");
233
	TEST_START("generate KEY_RSA too small modulus");
229
	ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 128, &k1),
234
	ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 128, &k1),
230
	    SSH_ERR_KEY_LENGTH);
235
	    SSH_ERR_KEY_LENGTH);
Lines 244-257 sshkey_tests(void) Link Here
244
	sshkey_free(k1);
249
	sshkey_free(k1);
245
	TEST_DONE();
250
	TEST_DONE();
246
251
247
#ifdef OPENSSL_HAS_ECC
252
# ifdef OPENSSL_HAS_ECC
248
	TEST_START("generate KEY_ECDSA wrong bits");
253
	TEST_START("generate KEY_ECDSA wrong bits");
249
	ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 42, &k1),
254
	ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 42, &k1),
250
	    SSH_ERR_KEY_LENGTH);
255
	    SSH_ERR_KEY_LENGTH);
251
	ASSERT_PTR_EQ(k1, NULL);
256
	ASSERT_PTR_EQ(k1, NULL);
252
	sshkey_free(k1);
257
	sshkey_free(k1);
253
	TEST_DONE();
258
	TEST_DONE();
254
#endif
259
# endif /* OPENSSL_HAS_ECC */
255
260
256
	TEST_START("generate KEY_RSA");
261
	TEST_START("generate KEY_RSA");
257
	ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 767, &kr),
262
	ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 767, &kr),
Lines 273-279 sshkey_tests(void) Link Here
273
	ASSERT_PTR_NE(dsa_priv_key(kd), NULL);
278
	ASSERT_PTR_NE(dsa_priv_key(kd), NULL);
274
	TEST_DONE();
279
	TEST_DONE();
275
280
276
#ifdef OPENSSL_HAS_ECC
281
# ifdef OPENSSL_HAS_ECC
277
	TEST_START("generate KEY_ECDSA");
282
	TEST_START("generate KEY_ECDSA");
278
	ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &ke), 0);
283
	ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &ke), 0);
279
	ASSERT_PTR_NE(ke, NULL);
284
	ASSERT_PTR_NE(ke, NULL);
Lines 281-287 sshkey_tests(void) Link Here
281
	ASSERT_PTR_NE(EC_KEY_get0_public_key(ke->ecdsa), NULL);
286
	ASSERT_PTR_NE(EC_KEY_get0_public_key(ke->ecdsa), NULL);
282
	ASSERT_PTR_NE(EC_KEY_get0_private_key(ke->ecdsa), NULL);
287
	ASSERT_PTR_NE(EC_KEY_get0_private_key(ke->ecdsa), NULL);
283
	TEST_DONE();
288
	TEST_DONE();
284
#endif
289
# endif /* OPENSSL_HAS_ECC */
290
#endif /* WITH_OPENSSL */
285
291
286
	TEST_START("generate KEY_ED25519");
292
	TEST_START("generate KEY_ED25519");
287
	ASSERT_INT_EQ(sshkey_generate(KEY_ED25519, 256, &kf), 0);
293
	ASSERT_INT_EQ(sshkey_generate(KEY_ED25519, 256, &kf), 0);
Lines 291-296 sshkey_tests(void) Link Here
291
	ASSERT_PTR_NE(kf->ed25519_sk, NULL);
297
	ASSERT_PTR_NE(kf->ed25519_sk, NULL);
292
	TEST_DONE();
298
	TEST_DONE();
293
299
300
#ifdef WITH_OPENSSL
294
	TEST_START("demote KEY_RSA");
301
	TEST_START("demote KEY_RSA");
295
	ASSERT_INT_EQ(sshkey_from_private(kr, &k1), 0);
302
	ASSERT_INT_EQ(sshkey_from_private(kr, &k1), 0);
296
	ASSERT_PTR_NE(k1, NULL);
303
	ASSERT_PTR_NE(k1, NULL);
Lines 322-328 sshkey_tests(void) Link Here
322
	sshkey_free(k1);
329
	sshkey_free(k1);
323
	TEST_DONE();
330
	TEST_DONE();
324
331
325
#ifdef OPENSSL_HAS_ECC
332
# ifdef OPENSSL_HAS_ECC
326
	TEST_START("demote KEY_ECDSA");
333
	TEST_START("demote KEY_ECDSA");
327
	ASSERT_INT_EQ(sshkey_from_private(ke, &k1), 0);
334
	ASSERT_INT_EQ(sshkey_from_private(ke, &k1), 0);
328
	ASSERT_PTR_NE(k1, NULL);
335
	ASSERT_PTR_NE(k1, NULL);
Lines 338-344 sshkey_tests(void) Link Here
338
	ASSERT_INT_EQ(sshkey_equal(ke, k1), 1);
345
	ASSERT_INT_EQ(sshkey_equal(ke, k1), 1);
339
	sshkey_free(k1);
346
	sshkey_free(k1);
340
	TEST_DONE();
347
	TEST_DONE();
341
#endif
348
# endif /* OPENSSL_HAS_ECC */
349
#endif /* WITH_OPENSSL */
342
350
343
	TEST_START("demote KEY_ED25519");
351
	TEST_START("demote KEY_ED25519");
344
	ASSERT_INT_EQ(sshkey_from_private(kf, &k1), 0);
352
	ASSERT_INT_EQ(sshkey_from_private(kf, &k1), 0);
Lines 365-381 sshkey_tests(void) Link Here
365
	TEST_DONE();
373
	TEST_DONE();
366
374
367
	TEST_START("equal different keys");
375
	TEST_START("equal different keys");
376
#ifdef WITH_OPENSSL
368
	ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &k1), 0);
377
	ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &k1), 0);
369
	ASSERT_INT_EQ(sshkey_equal(kr, k1), 0);
378
	ASSERT_INT_EQ(sshkey_equal(kr, k1), 0);
370
	sshkey_free(k1);
379
	sshkey_free(k1);
371
	ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &k1), 0);
380
	ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &k1), 0);
372
	ASSERT_INT_EQ(sshkey_equal(kd, k1), 0);
381
	ASSERT_INT_EQ(sshkey_equal(kd, k1), 0);
373
	sshkey_free(k1);
382
	sshkey_free(k1);
374
#ifdef OPENSSL_HAS_ECC
383
# ifdef OPENSSL_HAS_ECC
375
	ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &k1), 0);
384
	ASSERT_INT_EQ(sshkey_generate(KEY_ECDSA, 256, &k1), 0);
376
	ASSERT_INT_EQ(sshkey_equal(ke, k1), 0);
385
	ASSERT_INT_EQ(sshkey_equal(ke, k1), 0);
377
	sshkey_free(k1);
386
	sshkey_free(k1);
378
#endif
387
# endif /* OPENSSL_HAS_ECC */
388
#endif /* WITH_OPENSSL */
379
	ASSERT_INT_EQ(sshkey_generate(KEY_ED25519, 256, &k1), 0);
389
	ASSERT_INT_EQ(sshkey_generate(KEY_ED25519, 256, &k1), 0);
380
	ASSERT_INT_EQ(sshkey_equal(kf, k1), 0);
390
	ASSERT_INT_EQ(sshkey_equal(kf, k1), 0);
381
	sshkey_free(k1);
391
	sshkey_free(k1);
Lines 434-439 sshkey_tests(void) Link Here
434
	sshbuf_reset(b);
444
	sshbuf_reset(b);
435
	TEST_DONE();
445
	TEST_DONE();
436
446
447
#ifdef WITH_OPENSSL
437
	TEST_START("sign and verify RSA");
448
	TEST_START("sign and verify RSA");
438
	k1 = get_private("rsa_1");
449
	k1 = get_private("rsa_1");
439
	ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_2.pub"), &k2,
450
	ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_2.pub"), &k2,
Lines 470-476 sshkey_tests(void) Link Here
470
	sshkey_free(k2);
481
	sshkey_free(k2);
471
	TEST_DONE();
482
	TEST_DONE();
472
483
473
#ifdef OPENSSL_HAS_ECC
484
# ifdef OPENSSL_HAS_ECC
474
	TEST_START("sign and verify ECDSA");
485
	TEST_START("sign and verify ECDSA");
475
	k1 = get_private("ecdsa_1");
486
	k1 = get_private("ecdsa_1");
476
	ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_2.pub"), &k2,
487
	ASSERT_INT_EQ(sshkey_load_public(test_data_file("ecdsa_2.pub"), &k2,
Lines 479-485 sshkey_tests(void) Link Here
479
	sshkey_free(k1);
490
	sshkey_free(k1);
480
	sshkey_free(k2);
491
	sshkey_free(k2);
481
	TEST_DONE();
492
	TEST_DONE();
482
#endif
493
# endif /* OPENSSL_HAS_ECC */
494
#endif /* WITH_OPENSSL */
483
495
484
	TEST_START("sign and verify ED25519");
496
	TEST_START("sign and verify ED25519");
485
	k1 = get_private("ed25519_1");
497
	k1 = get_private("ed25519_1");
Lines 490-495 sshkey_tests(void) Link Here
490
	sshkey_free(k2);
502
	sshkey_free(k2);
491
	TEST_DONE();
503
	TEST_DONE();
492
504
505
#ifdef WITH_OPENSSL
493
	TEST_START("nested certificate");
506
	TEST_START("nested certificate");
494
	ASSERT_INT_EQ(sshkey_load_cert(test_data_file("rsa_1"), &k1), 0);
507
	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,
508
	ASSERT_INT_EQ(sshkey_load_public(test_data_file("rsa_1.pub"), &k2,
Lines 504-508 sshkey_tests(void) Link Here
504
	sshkey_free(k3);
517
	sshkey_free(k3);
505
	sshbuf_free(b);
518
	sshbuf_free(b);
506
	TEST_DONE();
519
	TEST_DONE();
520
#endif /* WITH_OPENSSL */
507
521
508
}
522
}
(-)a/regress/unittests/test_helper/test_helper.c (+6 lines)
Lines 126-132 main(int argc, char **argv) Link Here
126
	int ch;
126
	int ch;
127
127
128
	seed_rng();
128
	seed_rng();
129
#ifdef WITH_OPENSSL
129
	ERR_load_CRYPTO_strings();
130
	ERR_load_CRYPTO_strings();
131
#endif /* WITH_OPENSSL */
130
132
131
	/* Handle systems without __progname */
133
	/* Handle systems without __progname */
132
	if (__progname == NULL) {
134
	if (__progname == NULL) {
Lines 287-292 test_subtest_info(const char *fmt, ...) Link Here
287
void
289
void
288
ssl_err_check(const char *file, int line)
290
ssl_err_check(const char *file, int line)
289
{
291
{
292
#ifdef WITH_OPENSSL
290
	long openssl_error = ERR_get_error();
293
	long openssl_error = ERR_get_error();
291
294
292
	if (openssl_error == 0)
295
	if (openssl_error == 0)
Lines 294-299 ssl_err_check(const char *file, int line) Link Here
294
297
295
	fprintf(stderr, "\n%s:%d: uncaught OpenSSL error: %s",
298
	fprintf(stderr, "\n%s:%d: uncaught OpenSSL error: %s",
296
	    file, line, ERR_error_string(openssl_error, NULL));
299
	    file, line, ERR_error_string(openssl_error, NULL));
300
#endif /* WITH_OPENSSL */
297
	abort();
301
	abort();
298
}
302
}
299
303
Lines 338-343 test_header(const char *file, int line, const char *a1, const char *a2, Link Here
338
	    a2 != NULL ? ", " : "", a2 != NULL ? a2 : "");
342
	    a2 != NULL ? ", " : "", a2 != NULL ? a2 : "");
339
}
343
}
340
344
345
#ifdef WITH_OPENSSL
341
void
346
void
342
assert_bignum(const char *file, int line, const char *a1, const char *a2,
347
assert_bignum(const char *file, int line, const char *a1, const char *a2,
343
    const BIGNUM *aa1, const BIGNUM *aa2, enum test_predicate pred)
348
    const BIGNUM *aa1, const BIGNUM *aa2, enum test_predicate pred)
Lines 350-355 assert_bignum(const char *file, int line, const char *a1, const char *a2, Link Here
350
	fprintf(stderr, "%12s = 0x%s\n", a2, BN_bn2hex(aa2));
355
	fprintf(stderr, "%12s = 0x%s\n", a2, BN_bn2hex(aa2));
351
	test_die();
356
	test_die();
352
}
357
}
358
#endif /* WITH_OPENSSL */
353
359
354
void
360
void
355
assert_string(const char *file, int line, const char *a1, const char *a2,
361
assert_string(const char *file, int line, const char *a1, const char *a2,
(-)a/sshbuf-getput-crypto.c (-8 / +12 lines)
Lines 23-36 Link Here
23
#include <stdio.h>
23
#include <stdio.h>
24
#include <string.h>
24
#include <string.h>
25
25
26
#include <openssl/bn.h>
26
#if WITH_OPENSSL
27
#ifdef OPENSSL_HAS_ECC
27
# include <openssl/bn.h>
28
# include <openssl/ec.h>
28
# ifdef OPENSSL_HAS_ECC
29
#endif /* OPENSSL_HAS_ECC */
29
#  include <openssl/ec.h>
30
# endif /* OPENSSL_HAS_ECC */
31
#endif /* WITH_OPENSSL */
30
32
31
#include "ssherr.h"
33
#include "ssherr.h"
32
#include "sshbuf.h"
34
#include "sshbuf.h"
33
35
36
#if WITH_OPENSSL
34
int
37
int
35
sshbuf_get_bignum2(struct sshbuf *buf, BIGNUM *v)
38
sshbuf_get_bignum2(struct sshbuf *buf, BIGNUM *v)
36
{
39
{
Lines 71-77 sshbuf_get_bignum1(struct sshbuf *buf, BIGNUM *v) Link Here
71
	return 0;
74
	return 0;
72
}
75
}
73
76
74
#ifdef OPENSSL_HAS_ECC
77
# ifdef OPENSSL_HAS_ECC
75
static int
78
static int
76
get_ec(const u_char *d, size_t len, EC_POINT *v, const EC_GROUP *g)
79
get_ec(const u_char *d, size_t len, EC_POINT *v, const EC_GROUP *g)
77
{
80
{
Lines 141-147 sshbuf_get_eckey(struct sshbuf *buf, EC_KEY *v) Link Here
141
	}
144
	}
142
	return 0;	
145
	return 0;	
143
}
146
}
144
#endif /* OPENSSL_HAS_ECC */
147
# endif /* OPENSSL_HAS_ECC */
145
148
146
int
149
int
147
sshbuf_put_bignum2(struct sshbuf *buf, const BIGNUM *v)
150
sshbuf_put_bignum2(struct sshbuf *buf, const BIGNUM *v)
Lines 187-193 sshbuf_put_bignum1(struct sshbuf *buf, const BIGNUM *v) Link Here
187
	return 0;
190
	return 0;
188
}
191
}
189
192
190
#ifdef OPENSSL_HAS_ECC
193
# ifdef OPENSSL_HAS_ECC
191
int
194
int
192
sshbuf_put_ec(struct sshbuf *buf, const EC_POINT *v, const EC_GROUP *g)
195
sshbuf_put_ec(struct sshbuf *buf, const EC_POINT *v, const EC_GROUP *g)
193
{
196
{
Lines 220-224 sshbuf_put_eckey(struct sshbuf *buf, const EC_KEY *v) Link Here
220
	return sshbuf_put_ec(buf, EC_KEY_get0_public_key(v),
223
	return sshbuf_put_ec(buf, EC_KEY_get0_public_key(v),
221
	    EC_KEY_get0_group(v));
224
	    EC_KEY_get0_group(v));
222
}
225
}
223
#endif /* OPENSSL_HAS_ECC */
226
# endif /* OPENSSL_HAS_ECC */
227
#endif /* WITH_OPENSSL */
224
228

Return to bug 2954