summaryrefslogtreecommitdiff
path: root/regress/unittests
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2018-09-13 09:03:20 +0000
committerDamien Miller <djm@mindrot.org>2018-09-13 19:04:10 +1000
commita3fd8074e2e2f06602e25618721f9556c731312c (patch)
tree133f60fc47fe37700c5fd6fbdfbfaf6fbe6a4715 /regress/unittests
parent86e0a9f3d249d5580390daf58e015e68b01cef10 (diff)
upstream: missed a bit of openssl-1.0.x API in this unittest
OpenBSD-Regress-ID: a73a54d7f7381856a3f3a2d25947bee7a9a5dbc9
Diffstat (limited to 'regress/unittests')
-rw-r--r--regress/unittests/sshkey/common.c79
-rw-r--r--regress/unittests/sshkey/common.h11
-rw-r--r--regress/unittests/sshkey/test_file.c14
-rw-r--r--regress/unittests/sshkey/test_sshkey.c57
4 files changed, 96 insertions, 65 deletions
diff --git a/regress/unittests/sshkey/common.c b/regress/unittests/sshkey/common.c
index b598f05cb..548da6849 100644
--- a/regress/unittests/sshkey/common.c
+++ b/regress/unittests/sshkey/common.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: common.c,v 1.2 2015/01/08 13:10:58 djm Exp $ */ 1/* $OpenBSD: common.c,v 1.3 2018/09/13 09:03:20 djm Exp $ */
2/* 2/*
3 * Helpers for key API tests 3 * Helpers for key API tests
4 * 4 *
@@ -82,3 +82,80 @@ load_bignum(const char *name)
82 return ret; 82 return ret;
83} 83}
84 84
85const BIGNUM *
86rsa_n(struct sshkey *k)
87{
88 const BIGNUM *n = NULL;
89
90 ASSERT_PTR_NE(k, NULL);
91 ASSERT_PTR_NE(k->rsa, NULL);
92 RSA_get0_key(k->rsa, &n, NULL, NULL);
93 return n;
94}
95
96const BIGNUM *
97rsa_e(struct sshkey *k)
98{
99 const BIGNUM *e = NULL;
100
101 ASSERT_PTR_NE(k, NULL);
102 ASSERT_PTR_NE(k->rsa, NULL);
103 RSA_get0_key(k->rsa, NULL, &e, NULL);
104 return e;
105}
106
107const BIGNUM *
108rsa_p(struct sshkey *k)
109{
110 const BIGNUM *p = NULL;
111
112 ASSERT_PTR_NE(k, NULL);
113 ASSERT_PTR_NE(k->rsa, NULL);
114 RSA_get0_factors(k->rsa, &p, NULL);
115 return p;
116}
117
118const BIGNUM *
119rsa_q(struct sshkey *k)
120{
121 const BIGNUM *q = NULL;
122
123 ASSERT_PTR_NE(k, NULL);
124 ASSERT_PTR_NE(k->rsa, NULL);
125 RSA_get0_factors(k->rsa, NULL, &q);
126 return q;
127}
128
129const BIGNUM *
130dsa_g(struct sshkey *k)
131{
132 const BIGNUM *g = NULL;
133
134 ASSERT_PTR_NE(k, NULL);
135 ASSERT_PTR_NE(k->dsa, NULL);
136 DSA_get0_pqg(k->dsa, NULL, NULL, &g);
137 return g;
138}
139
140const BIGNUM *
141dsa_pub_key(struct sshkey *k)
142{
143 const BIGNUM *pub_key = NULL;
144
145 ASSERT_PTR_NE(k, NULL);
146 ASSERT_PTR_NE(k->dsa, NULL);
147 DSA_get0_key(k->dsa, &pub_key, NULL);
148 return pub_key;
149}
150
151const BIGNUM *
152dsa_priv_key(struct sshkey *k)
153{
154 const BIGNUM *priv_key = NULL;
155
156 ASSERT_PTR_NE(k, NULL);
157 ASSERT_PTR_NE(k->dsa, NULL);
158 DSA_get0_key(k->dsa, NULL, &priv_key);
159 return priv_key;
160}
161
diff --git a/regress/unittests/sshkey/common.h b/regress/unittests/sshkey/common.h
index bf7d19dce..7a514fdc8 100644
--- a/regress/unittests/sshkey/common.h
+++ b/regress/unittests/sshkey/common.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: common.h,v 1.1 2014/06/24 01:14:18 djm Exp $ */ 1/* $OpenBSD: common.h,v 1.2 2018/09/13 09:03:20 djm Exp $ */
2/* 2/*
3 * Helpers for key API tests 3 * Helpers for key API tests
4 * 4 *
@@ -14,3 +14,12 @@ struct sshbuf *load_text_file(const char *name);
14/* Load a bignum from a file */ 14/* Load a bignum from a file */
15BIGNUM *load_bignum(const char *name); 15BIGNUM *load_bignum(const char *name);
16 16
17/* Accessors for key components */
18const BIGNUM *rsa_n(struct sshkey *k);
19const BIGNUM *rsa_e(struct sshkey *k);
20const BIGNUM *rsa_p(struct sshkey *k);
21const BIGNUM *rsa_q(struct sshkey *k);
22const BIGNUM *dsa_g(struct sshkey *k);
23const BIGNUM *dsa_pub_key(struct sshkey *k);
24const BIGNUM *dsa_priv_key(struct sshkey *k);
25
diff --git a/regress/unittests/sshkey/test_file.c b/regress/unittests/sshkey/test_file.c
index 0636e84bb..65610dacc 100644
--- a/regress/unittests/sshkey/test_file.c
+++ b/regress/unittests/sshkey/test_file.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: test_file.c,v 1.7 2018/09/12 01:36:45 djm Exp $ */ 1/* $OpenBSD: test_file.c,v 1.8 2018/09/13 09:03:20 djm Exp $ */
2/* 2/*
3 * Regress test for sshkey.h key management API 3 * Regress test for sshkey.h key management API
4 * 4 *
@@ -60,9 +60,9 @@ sshkey_file_tests(void)
60 a = load_bignum("rsa_1.param.n"); 60 a = load_bignum("rsa_1.param.n");
61 b = load_bignum("rsa_1.param.p"); 61 b = load_bignum("rsa_1.param.p");
62 c = load_bignum("rsa_1.param.q"); 62 c = load_bignum("rsa_1.param.q");
63 ASSERT_BIGNUM_EQ(k1->rsa->n, a); 63 ASSERT_BIGNUM_EQ(rsa_n(k1), a);
64 ASSERT_BIGNUM_EQ(k1->rsa->p, b); 64 ASSERT_BIGNUM_EQ(rsa_p(k1), b);
65 ASSERT_BIGNUM_EQ(k1->rsa->q, c); 65 ASSERT_BIGNUM_EQ(rsa_q(k1), c);
66 BN_free(a); 66 BN_free(a);
67 BN_free(b); 67 BN_free(b);
68 BN_free(c); 68 BN_free(c);
@@ -169,9 +169,9 @@ sshkey_file_tests(void)
169 a = load_bignum("dsa_1.param.g"); 169 a = load_bignum("dsa_1.param.g");
170 b = load_bignum("dsa_1.param.priv"); 170 b = load_bignum("dsa_1.param.priv");
171 c = load_bignum("dsa_1.param.pub"); 171 c = load_bignum("dsa_1.param.pub");
172 ASSERT_BIGNUM_EQ(k1->dsa->g, a); 172 ASSERT_BIGNUM_EQ(dsa_g(k1), a);
173 ASSERT_BIGNUM_EQ(k1->dsa->priv_key, b); 173 ASSERT_BIGNUM_EQ(dsa_priv_key(k1), b);
174 ASSERT_BIGNUM_EQ(k1->dsa->pub_key, c); 174 ASSERT_BIGNUM_EQ(dsa_pub_key(k1), c);
175 BN_free(a); 175 BN_free(a);
176 BN_free(b); 176 BN_free(b);
177 BN_free(c); 177 BN_free(c);
diff --git a/regress/unittests/sshkey/test_sshkey.c b/regress/unittests/sshkey/test_sshkey.c
index 8e35f4417..47a03fad4 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.16 2018/09/13 05:06:51 djm Exp $ */ 1/* $OpenBSD: test_sshkey.c,v 1.17 2018/09/13 09:03:20 djm Exp $ */
2/* 2/*
3 * Regress test for sshkey.h key management API 3 * Regress test for sshkey.h key management API
4 * 4 *
@@ -173,61 +173,6 @@ get_private(const char *n)
173 return ret; 173 return ret;
174} 174}
175 175
176static const BIGNUM *
177rsa_n(struct sshkey *k)
178{
179 const BIGNUM *n = NULL;
180
181 ASSERT_PTR_NE(k, NULL);
182 ASSERT_PTR_NE(k->rsa, NULL);
183 RSA_get0_key(k->rsa, &n, NULL, NULL);
184 return n;
185}
186
187static const BIGNUM *
188rsa_e(struct sshkey *k)
189{
190 const BIGNUM *e = NULL;
191
192 ASSERT_PTR_NE(k, NULL);
193 ASSERT_PTR_NE(k->rsa, NULL);
194 RSA_get0_key(k->rsa, NULL, &e, NULL);
195 return e;
196}
197
198static const BIGNUM *
199rsa_p(struct sshkey *k)
200{
201 const BIGNUM *p = NULL;
202
203 ASSERT_PTR_NE(k, NULL);
204 ASSERT_PTR_NE(k->rsa, NULL);
205 RSA_get0_factors(k->rsa, &p, NULL);
206 return p;
207}
208
209static const BIGNUM *
210dsa_g(struct sshkey *k)
211{
212 const BIGNUM *g = NULL;
213
214 ASSERT_PTR_NE(k, NULL);
215 ASSERT_PTR_NE(k->dsa, NULL);
216 DSA_get0_pqg(k->dsa, NULL, NULL, &g);
217 return g;
218}
219
220static const BIGNUM *
221dsa_priv_key(struct sshkey *k)
222{
223 const BIGNUM *priv_key = NULL;
224
225 ASSERT_PTR_NE(k, NULL);
226 ASSERT_PTR_NE(k->dsa, NULL);
227 DSA_get0_key(k->dsa, NULL, &priv_key);
228 return priv_key;
229}
230
231void 176void
232sshkey_tests(void) 177sshkey_tests(void)
233{ 178{