You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
5.8 KiB

  1. From d100d85cc797d9871e0c34a09104b02b0452b4f4 Mon Sep 17 00:00:00 2001
  2. From: "djm@openbsd.org" <djm@openbsd.org>
  3. Date: Thu, 13 Sep 2018 09:03:20 +0000
  4. Subject: [PATCH 4/5] upstream: missed a bit of openssl-1.0.x API in this
  5. unittest
  6. OpenBSD-Regress-ID: a73a54d7f7381856a3f3a2d25947bee7a9a5dbc9
  7. ---
  8. regress/unittests/sshkey/common.c | 79 +++++++++++++++++++++++++++++++++-
  9. regress/unittests/sshkey/common.h | 11 ++++-
  10. regress/unittests/sshkey/test_file.c | 13 +++---
  11. regress/unittests/sshkey/test_sshkey.c | 57 +-----------------------
  12. 4 files changed, 96 insertions(+), 64 deletions(-)
  13. diff --git a/regress/unittests/sshkey/common.c b/regress/unittests/sshkey/common.c
  14. index b598f05c..548da684 100644
  15. --- a/regress/unittests/sshkey/common.c
  16. +++ b/regress/unittests/sshkey/common.c
  17. @@ -1,4 +1,4 @@
  18. -/* $OpenBSD: common.c,v 1.2 2015/01/08 13:10:58 djm Exp $ */
  19. +/* $OpenBSD: common.c,v 1.3 2018/09/13 09:03:20 djm Exp $ */
  20. /*
  21. * Helpers for key API tests
  22. *
  23. @@ -82,3 +82,80 @@ load_bignum(const char *name)
  24. return ret;
  25. }
  26. +const BIGNUM *
  27. +rsa_n(struct sshkey *k)
  28. +{
  29. + const BIGNUM *n = NULL;
  30. +
  31. + ASSERT_PTR_NE(k, NULL);
  32. + ASSERT_PTR_NE(k->rsa, NULL);
  33. + RSA_get0_key(k->rsa, &n, NULL, NULL);
  34. + return n;
  35. +}
  36. +
  37. +const BIGNUM *
  38. +rsa_e(struct sshkey *k)
  39. +{
  40. + const BIGNUM *e = NULL;
  41. +
  42. + ASSERT_PTR_NE(k, NULL);
  43. + ASSERT_PTR_NE(k->rsa, NULL);
  44. + RSA_get0_key(k->rsa, NULL, &e, NULL);
  45. + return e;
  46. +}
  47. +
  48. +const BIGNUM *
  49. +rsa_p(struct sshkey *k)
  50. +{
  51. + const BIGNUM *p = NULL;
  52. +
  53. + ASSERT_PTR_NE(k, NULL);
  54. + ASSERT_PTR_NE(k->rsa, NULL);
  55. + RSA_get0_factors(k->rsa, &p, NULL);
  56. + return p;
  57. +}
  58. +
  59. +const BIGNUM *
  60. +rsa_q(struct sshkey *k)
  61. +{
  62. + const BIGNUM *q = NULL;
  63. +
  64. + ASSERT_PTR_NE(k, NULL);
  65. + ASSERT_PTR_NE(k->rsa, NULL);
  66. + RSA_get0_factors(k->rsa, NULL, &q);
  67. + return q;
  68. +}
  69. +
  70. +const BIGNUM *
  71. +dsa_g(struct sshkey *k)
  72. +{
  73. + const BIGNUM *g = NULL;
  74. +
  75. + ASSERT_PTR_NE(k, NULL);
  76. + ASSERT_PTR_NE(k->dsa, NULL);
  77. + DSA_get0_pqg(k->dsa, NULL, NULL, &g);
  78. + return g;
  79. +}
  80. +
  81. +const BIGNUM *
  82. +dsa_pub_key(struct sshkey *k)
  83. +{
  84. + const BIGNUM *pub_key = NULL;
  85. +
  86. + ASSERT_PTR_NE(k, NULL);
  87. + ASSERT_PTR_NE(k->dsa, NULL);
  88. + DSA_get0_key(k->dsa, &pub_key, NULL);
  89. + return pub_key;
  90. +}
  91. +
  92. +const BIGNUM *
  93. +dsa_priv_key(struct sshkey *k)
  94. +{
  95. + const BIGNUM *priv_key = NULL;
  96. +
  97. + ASSERT_PTR_NE(k, NULL);
  98. + ASSERT_PTR_NE(k->dsa, NULL);
  99. + DSA_get0_key(k->dsa, NULL, &priv_key);
  100. + return priv_key;
  101. +}
  102. +
  103. diff --git a/regress/unittests/sshkey/common.h b/regress/unittests/sshkey/common.h
  104. index bf7d19dc..7a514fdc 100644
  105. --- a/regress/unittests/sshkey/common.h
  106. +++ b/regress/unittests/sshkey/common.h
  107. @@ -1,4 +1,4 @@
  108. -/* $OpenBSD: common.h,v 1.1 2014/06/24 01:14:18 djm Exp $ */
  109. +/* $OpenBSD: common.h,v 1.2 2018/09/13 09:03:20 djm Exp $ */
  110. /*
  111. * Helpers for key API tests
  112. *
  113. @@ -14,3 +14,12 @@ struct sshbuf *load_text_file(const char *name);
  114. /* Load a bignum from a file */
  115. BIGNUM *load_bignum(const char *name);
  116. +/* Accessors for key components */
  117. +const BIGNUM *rsa_n(struct sshkey *k);
  118. +const BIGNUM *rsa_e(struct sshkey *k);
  119. +const BIGNUM *rsa_p(struct sshkey *k);
  120. +const BIGNUM *rsa_q(struct sshkey *k);
  121. +const BIGNUM *dsa_g(struct sshkey *k);
  122. +const BIGNUM *dsa_pub_key(struct sshkey *k);
  123. +const BIGNUM *dsa_priv_key(struct sshkey *k);
  124. +
  125. diff --git a/regress/unittests/sshkey/test_file.c b/regress/unittests/sshkey/test_file.c
  126. index 99b7e21c..596c166b 100644
  127. --- a/regress/unittests/sshkey/test_file.c
  128. +++ b/regress/unittests/sshkey/test_file.c
  129. @@ -1,4 +1,5 @@
  130. /* $OpenBSD: test_file.c,v 1.6 2017/04/30 23:33:48 djm Exp $ */
  131. +/* Incorporates changes from 1.8 */
  132. /*
  133. * Regress test for sshkey.h key management API
  134. *
  135. @@ -60,9 +61,9 @@ sshkey_file_tests(void)
  136. a = load_bignum("rsa_1.param.n");
  137. b = load_bignum("rsa_1.param.p");
  138. c = load_bignum("rsa_1.param.q");
  139. - ASSERT_BIGNUM_EQ(k1->rsa->n, a);
  140. - ASSERT_BIGNUM_EQ(k1->rsa->p, b);
  141. - ASSERT_BIGNUM_EQ(k1->rsa->q, c);
  142. + ASSERT_BIGNUM_EQ(rsa_n(k1), a);
  143. + ASSERT_BIGNUM_EQ(rsa_p(k1), b);
  144. + ASSERT_BIGNUM_EQ(rsa_q(k1), c);
  145. BN_free(a);
  146. BN_free(b);
  147. BN_free(c);
  148. @@ -151,9 +152,9 @@ sshkey_file_tests(void)
  149. a = load_bignum("dsa_1.param.g");
  150. b = load_bignum("dsa_1.param.priv");
  151. c = load_bignum("dsa_1.param.pub");
  152. - ASSERT_BIGNUM_EQ(k1->dsa->g, a);
  153. - ASSERT_BIGNUM_EQ(k1->dsa->priv_key, b);
  154. - ASSERT_BIGNUM_EQ(k1->dsa->pub_key, c);
  155. + ASSERT_BIGNUM_EQ(dsa_g(k1), a);
  156. + ASSERT_BIGNUM_EQ(dsa_priv_key(k1), b);
  157. + ASSERT_BIGNUM_EQ(dsa_pub_key(k1), c);
  158. BN_free(a);
  159. BN_free(b);
  160. BN_free(c);
  161. diff --git a/regress/unittests/sshkey/test_sshkey.c b/regress/unittests/sshkey/test_sshkey.c
  162. index a32d2884..deeb23a0 100644
  163. --- a/regress/unittests/sshkey/test_sshkey.c
  164. +++ b/regress/unittests/sshkey/test_sshkey.c
  165. @@ -1,5 +1,5 @@
  166. /* $OpenBSD: test_sshkey.c,v 1.14 2018/07/13 02:13:19 djm Exp $ */
  167. -/* Incorporates changes from 1.16 */
  168. +/* Incorporates changes from 1.16 and 1.17 */
  169. /*
  170. * Regress test for sshkey.h key management API
  171. *
  172. @@ -174,61 +174,6 @@ get_private(const char *n)
  173. return ret;
  174. }
  175. -static const BIGNUM *
  176. -rsa_n(struct sshkey *k)
  177. -{
  178. - const BIGNUM *n = NULL;
  179. -
  180. - ASSERT_PTR_NE(k, NULL);
  181. - ASSERT_PTR_NE(k->rsa, NULL);
  182. - RSA_get0_key(k->rsa, &n, NULL, NULL);
  183. - return n;
  184. -}
  185. -
  186. -static const BIGNUM *
  187. -rsa_e(struct sshkey *k)
  188. -{
  189. - const BIGNUM *e = NULL;
  190. -
  191. - ASSERT_PTR_NE(k, NULL);
  192. - ASSERT_PTR_NE(k->rsa, NULL);
  193. - RSA_get0_key(k->rsa, NULL, &e, NULL);
  194. - return e;
  195. -}
  196. -
  197. -static const BIGNUM *
  198. -rsa_p(struct sshkey *k)
  199. -{
  200. - const BIGNUM *p = NULL;
  201. -
  202. - ASSERT_PTR_NE(k, NULL);
  203. - ASSERT_PTR_NE(k->rsa, NULL);
  204. - RSA_get0_factors(k->rsa, &p, NULL);
  205. - return p;
  206. -}
  207. -
  208. -static const BIGNUM *
  209. -dsa_g(struct sshkey *k)
  210. -{
  211. - const BIGNUM *g = NULL;
  212. -
  213. - ASSERT_PTR_NE(k, NULL);
  214. - ASSERT_PTR_NE(k->dsa, NULL);
  215. - DSA_get0_pqg(k->dsa, NULL, NULL, &g);
  216. - return g;
  217. -}
  218. -
  219. -static const BIGNUM *
  220. -dsa_priv_key(struct sshkey *k)
  221. -{
  222. - const BIGNUM *priv_key = NULL;
  223. -
  224. - ASSERT_PTR_NE(k, NULL);
  225. - ASSERT_PTR_NE(k->dsa, NULL);
  226. - DSA_get0_key(k->dsa, NULL, &priv_key);
  227. - return priv_key;
  228. -}
  229. -
  230. void
  231. sshkey_tests(void)
  232. {
  233. --
  234. 2.16.4