fake_rsaprov.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. /*
  2. * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. * https://www.openssl.org/source/license.html
  8. * or in the file LICENSE in the source distribution.
  9. */
  10. #include <string.h>
  11. #include <openssl/core_names.h>
  12. #include <openssl/core_object.h>
  13. #include <openssl/rand.h>
  14. #include <openssl/provider.h>
  15. #include "testutil.h"
  16. #include "fake_rsaprov.h"
  17. static OSSL_FUNC_keymgmt_new_fn fake_rsa_keymgmt_new;
  18. static OSSL_FUNC_keymgmt_free_fn fake_rsa_keymgmt_free;
  19. static OSSL_FUNC_keymgmt_has_fn fake_rsa_keymgmt_has;
  20. static OSSL_FUNC_keymgmt_query_operation_name_fn fake_rsa_keymgmt_query;
  21. static OSSL_FUNC_keymgmt_import_fn fake_rsa_keymgmt_import;
  22. static OSSL_FUNC_keymgmt_import_types_fn fake_rsa_keymgmt_imptypes;
  23. static OSSL_FUNC_keymgmt_export_fn fake_rsa_keymgmt_export;
  24. static OSSL_FUNC_keymgmt_export_types_fn fake_rsa_keymgmt_exptypes;
  25. static OSSL_FUNC_keymgmt_load_fn fake_rsa_keymgmt_load;
  26. static int has_selection;
  27. static int imptypes_selection;
  28. static int exptypes_selection;
  29. static int query_id;
  30. struct fake_rsa_keydata {
  31. int selection;
  32. int status;
  33. };
  34. static void *fake_rsa_keymgmt_new(void *provctx)
  35. {
  36. struct fake_rsa_keydata *key;
  37. if (!TEST_ptr(key = OPENSSL_zalloc(sizeof(struct fake_rsa_keydata))))
  38. return NULL;
  39. /* clear test globals */
  40. has_selection = 0;
  41. imptypes_selection = 0;
  42. exptypes_selection = 0;
  43. query_id = 0;
  44. return key;
  45. }
  46. static void fake_rsa_keymgmt_free(void *keydata)
  47. {
  48. OPENSSL_free(keydata);
  49. }
  50. static int fake_rsa_keymgmt_has(const void *key, int selection)
  51. {
  52. /* record global for checking */
  53. has_selection = selection;
  54. return 1;
  55. }
  56. static const char *fake_rsa_keymgmt_query(int id)
  57. {
  58. /* record global for checking */
  59. query_id = id;
  60. return "RSA";
  61. }
  62. static int fake_rsa_keymgmt_import(void *keydata, int selection,
  63. const OSSL_PARAM *p)
  64. {
  65. struct fake_rsa_keydata *fake_rsa_key = keydata;
  66. /* key was imported */
  67. fake_rsa_key->status = 1;
  68. return 1;
  69. }
  70. static unsigned char fake_rsa_n[] =
  71. "\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F"
  72. "\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5"
  73. "\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93"
  74. "\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1"
  75. "\xF5";
  76. static unsigned char fake_rsa_e[] = "\x11";
  77. static unsigned char fake_rsa_d[] =
  78. "\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44"
  79. "\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64"
  80. "\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9"
  81. "\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51";
  82. static unsigned char fake_rsa_p[] =
  83. "\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
  84. "\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12"
  85. "\x0D";
  86. static unsigned char fake_rsa_q[] =
  87. "\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
  88. "\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
  89. "\x89";
  90. static unsigned char fake_rsa_dmp1[] =
  91. "\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF"
  92. "\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05";
  93. static unsigned char fake_rsa_dmq1[] =
  94. "\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99"
  95. "\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D"
  96. "\x51";
  97. static unsigned char fake_rsa_iqmp[] =
  98. "\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8"
  99. "\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26";
  100. OSSL_PARAM *fake_rsa_key_params(int priv)
  101. {
  102. if (priv) {
  103. OSSL_PARAM params[] = {
  104. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_N, fake_rsa_n,
  105. sizeof(fake_rsa_n) -1),
  106. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, fake_rsa_e,
  107. sizeof(fake_rsa_e) -1),
  108. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_D, fake_rsa_d,
  109. sizeof(fake_rsa_d) -1),
  110. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR1, fake_rsa_p,
  111. sizeof(fake_rsa_p) -1),
  112. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR2, fake_rsa_q,
  113. sizeof(fake_rsa_q) -1),
  114. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT1, fake_rsa_dmp1,
  115. sizeof(fake_rsa_dmp1) -1),
  116. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT2, fake_rsa_dmq1,
  117. sizeof(fake_rsa_dmq1) -1),
  118. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT1, fake_rsa_iqmp,
  119. sizeof(fake_rsa_iqmp) -1),
  120. OSSL_PARAM_END
  121. };
  122. return OSSL_PARAM_dup(params);
  123. } else {
  124. OSSL_PARAM params[] = {
  125. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_N, fake_rsa_n,
  126. sizeof(fake_rsa_n) -1),
  127. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, fake_rsa_e,
  128. sizeof(fake_rsa_e) -1),
  129. OSSL_PARAM_END
  130. };
  131. return OSSL_PARAM_dup(params);
  132. }
  133. }
  134. static int fake_rsa_keymgmt_export(void *keydata, int selection,
  135. OSSL_CALLBACK *param_callback, void *cbarg)
  136. {
  137. OSSL_PARAM *params = NULL;
  138. int ret;
  139. if (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY)
  140. return 0;
  141. if (!TEST_ptr(params = fake_rsa_key_params(0)))
  142. return 0;
  143. ret = param_callback(params, cbarg);
  144. OSSL_PARAM_free(params);
  145. return ret;
  146. }
  147. static const OSSL_PARAM fake_rsa_import_key_types[] = {
  148. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_N, NULL, 0),
  149. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, NULL, 0),
  150. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_D, NULL, 0),
  151. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR1, NULL, 0),
  152. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_FACTOR2, NULL, 0),
  153. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT1, NULL, 0),
  154. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_EXPONENT2, NULL, 0),
  155. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_COEFFICIENT1, NULL, 0),
  156. OSSL_PARAM_END
  157. };
  158. static const OSSL_PARAM *fake_rsa_keymgmt_imptypes(int selection)
  159. {
  160. /* record global for checking */
  161. imptypes_selection = selection;
  162. return fake_rsa_import_key_types;
  163. }
  164. static const OSSL_PARAM fake_rsa_export_key_types[] = {
  165. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_N, NULL, 0),
  166. OSSL_PARAM_BN(OSSL_PKEY_PARAM_RSA_E, NULL, 0),
  167. OSSL_PARAM_END
  168. };
  169. static const OSSL_PARAM *fake_rsa_keymgmt_exptypes(int selection)
  170. {
  171. /* record global for checking */
  172. exptypes_selection = selection;
  173. return fake_rsa_export_key_types;
  174. }
  175. static void *fake_rsa_keymgmt_load(const void *reference, size_t reference_sz)
  176. {
  177. struct fake_rsa_keydata *key = NULL;
  178. if (reference_sz != sizeof(*key))
  179. return NULL;
  180. key = *(struct fake_rsa_keydata **)reference;
  181. if (key->status != 1)
  182. return NULL;
  183. /* detach the reference */
  184. *(struct fake_rsa_keydata **)reference = NULL;
  185. return key;
  186. }
  187. static void *fake_rsa_gen_init(void *provctx, int selection,
  188. const OSSL_PARAM params[])
  189. {
  190. unsigned char *gctx = NULL;
  191. if (!TEST_ptr(gctx = OPENSSL_malloc(1)))
  192. return NULL;
  193. *gctx = 1;
  194. return gctx;
  195. }
  196. static void *fake_rsa_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg)
  197. {
  198. unsigned char *gctx = genctx;
  199. static const unsigned char inited[] = { 1 };
  200. struct fake_rsa_keydata *keydata;
  201. if (!TEST_ptr(gctx)
  202. || !TEST_mem_eq(gctx, sizeof(*gctx), inited, sizeof(inited)))
  203. return NULL;
  204. if (!TEST_ptr(keydata = fake_rsa_keymgmt_new(NULL)))
  205. return NULL;
  206. keydata->status = 2;
  207. return keydata;
  208. }
  209. static void fake_rsa_gen_cleanup(void *genctx)
  210. {
  211. OPENSSL_free(genctx);
  212. }
  213. static const OSSL_DISPATCH fake_rsa_keymgmt_funcs[] = {
  214. { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))fake_rsa_keymgmt_new },
  215. { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))fake_rsa_keymgmt_free} ,
  216. { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))fake_rsa_keymgmt_has },
  217. { OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME,
  218. (void (*)(void))fake_rsa_keymgmt_query },
  219. { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))fake_rsa_keymgmt_import },
  220. { OSSL_FUNC_KEYMGMT_IMPORT_TYPES,
  221. (void (*)(void))fake_rsa_keymgmt_imptypes },
  222. { OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))fake_rsa_keymgmt_export },
  223. { OSSL_FUNC_KEYMGMT_EXPORT_TYPES,
  224. (void (*)(void))fake_rsa_keymgmt_exptypes },
  225. { OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))fake_rsa_keymgmt_load },
  226. { OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))fake_rsa_gen_init },
  227. { OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))fake_rsa_gen },
  228. { OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))fake_rsa_gen_cleanup },
  229. { 0, NULL }
  230. };
  231. static const OSSL_ALGORITHM fake_rsa_keymgmt_algs[] = {
  232. { "RSA:rsaEncryption", "provider=fake-rsa", fake_rsa_keymgmt_funcs, "Fake RSA Key Management" },
  233. { NULL, NULL, NULL, NULL }
  234. };
  235. static OSSL_FUNC_signature_newctx_fn fake_rsa_sig_newctx;
  236. static OSSL_FUNC_signature_freectx_fn fake_rsa_sig_freectx;
  237. static OSSL_FUNC_signature_sign_init_fn fake_rsa_sig_sign_init;
  238. static OSSL_FUNC_signature_sign_fn fake_rsa_sig_sign;
  239. static void *fake_rsa_sig_newctx(void *provctx, const char *propq)
  240. {
  241. unsigned char *sigctx = OPENSSL_zalloc(1);
  242. TEST_ptr(sigctx);
  243. return sigctx;
  244. }
  245. static void fake_rsa_sig_freectx(void *sigctx)
  246. {
  247. OPENSSL_free(sigctx);
  248. }
  249. static int fake_rsa_sig_sign_init(void *ctx, void *provkey,
  250. const OSSL_PARAM params[])
  251. {
  252. unsigned char *sigctx = ctx;
  253. struct fake_rsa_keydata *keydata = provkey;
  254. /* we must have a ctx */
  255. if (!TEST_ptr(sigctx))
  256. return 0;
  257. /* we must have some initialized key */
  258. if (!TEST_ptr(keydata) || !TEST_int_gt(keydata->status, 0))
  259. return 0;
  260. /* record that sign init was called */
  261. *sigctx = 1;
  262. return 1;
  263. }
  264. static int fake_rsa_sig_sign(void *ctx, unsigned char *sig,
  265. size_t *siglen, size_t sigsize,
  266. const unsigned char *tbs, size_t tbslen)
  267. {
  268. unsigned char *sigctx = ctx;
  269. /* we must have a ctx and init was called upon it */
  270. if (!TEST_ptr(sigctx) || !TEST_int_eq(*sigctx, 1))
  271. return 0;
  272. *siglen = 256;
  273. /* record that the real sign operation was called */
  274. if (sig != NULL) {
  275. if (!TEST_int_ge(sigsize, *siglen))
  276. return 0;
  277. *sigctx = 2;
  278. /* produce a fake signature */
  279. memset(sig, 'a', *siglen);
  280. }
  281. return 1;
  282. }
  283. static const OSSL_DISPATCH fake_rsa_sig_funcs[] = {
  284. { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))fake_rsa_sig_newctx },
  285. { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))fake_rsa_sig_freectx },
  286. { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))fake_rsa_sig_sign_init },
  287. { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))fake_rsa_sig_sign },
  288. { 0, NULL }
  289. };
  290. static const OSSL_ALGORITHM fake_rsa_sig_algs[] = {
  291. { "RSA:rsaEncryption", "provider=fake-rsa", fake_rsa_sig_funcs, "Fake RSA Signature" },
  292. { NULL, NULL, NULL, NULL }
  293. };
  294. static OSSL_FUNC_store_open_fn fake_rsa_st_open;
  295. static OSSL_FUNC_store_settable_ctx_params_fn fake_rsa_st_settable_ctx_params;
  296. static OSSL_FUNC_store_set_ctx_params_fn fake_rsa_st_set_ctx_params;
  297. static OSSL_FUNC_store_load_fn fake_rsa_st_load;
  298. static OSSL_FUNC_store_eof_fn fake_rsa_st_eof;
  299. static OSSL_FUNC_store_close_fn fake_rsa_st_close;
  300. static const char fake_rsa_scheme[] = "fake_rsa:";
  301. static void *fake_rsa_st_open(void *provctx, const char *uri)
  302. {
  303. unsigned char *storectx = NULL;
  304. /* First check whether the uri is ours */
  305. if (strncmp(uri, fake_rsa_scheme, sizeof(fake_rsa_scheme) - 1) != 0)
  306. return NULL;
  307. storectx = OPENSSL_zalloc(1);
  308. if (!TEST_ptr(storectx))
  309. return NULL;
  310. TEST_info("fake_rsa_open called");
  311. return storectx;
  312. }
  313. static const OSSL_PARAM *fake_rsa_st_settable_ctx_params(void *provctx)
  314. {
  315. static const OSSL_PARAM known_settable_ctx_params[] = {
  316. OSSL_PARAM_END
  317. };
  318. return known_settable_ctx_params;
  319. }
  320. static int fake_rsa_st_set_ctx_params(void *loaderctx,
  321. const OSSL_PARAM params[])
  322. {
  323. return 1;
  324. }
  325. static int fake_rsa_st_load(void *loaderctx,
  326. OSSL_CALLBACK *object_cb, void *object_cbarg,
  327. OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg)
  328. {
  329. unsigned char *storectx = loaderctx;
  330. OSSL_PARAM params[4];
  331. int object_type = OSSL_OBJECT_PKEY;
  332. struct fake_rsa_keydata *key = NULL;
  333. int rv = 0;
  334. switch (*storectx) {
  335. case 0:
  336. /* Construct a new key using our keymgmt functions */
  337. if (!TEST_ptr(key = fake_rsa_keymgmt_new(NULL)))
  338. break;
  339. if (!TEST_int_gt(fake_rsa_keymgmt_import(key, 0, NULL), 0))
  340. break;
  341. params[0] =
  342. OSSL_PARAM_construct_int(OSSL_OBJECT_PARAM_TYPE, &object_type);
  343. params[1] =
  344. OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE,
  345. "RSA", 0);
  346. /* The address of the key becomes the octet string */
  347. params[2] =
  348. OSSL_PARAM_construct_octet_string(OSSL_OBJECT_PARAM_REFERENCE,
  349. &key, sizeof(*key));
  350. params[3] = OSSL_PARAM_construct_end();
  351. rv = object_cb(params, object_cbarg);
  352. *storectx = 1;
  353. break;
  354. case 2:
  355. TEST_info("fake_rsa_load() called in error state");
  356. break;
  357. default:
  358. TEST_info("fake_rsa_load() called in eof state");
  359. break;
  360. }
  361. TEST_info("fake_rsa_load called - rv: %d", rv);
  362. if (rv == 0) {
  363. fake_rsa_keymgmt_free(key);
  364. *storectx = 2;
  365. }
  366. return rv;
  367. }
  368. static int fake_rsa_st_eof(void *loaderctx)
  369. {
  370. unsigned char *storectx = loaderctx;
  371. /* just one key for now in the fake_rsa store */
  372. return *storectx != 0;
  373. }
  374. static int fake_rsa_st_close(void *loaderctx)
  375. {
  376. OPENSSL_free(loaderctx);
  377. return 1;
  378. }
  379. static const OSSL_DISPATCH fake_rsa_store_funcs[] = {
  380. { OSSL_FUNC_STORE_OPEN, (void (*)(void))fake_rsa_st_open },
  381. { OSSL_FUNC_STORE_SETTABLE_CTX_PARAMS,
  382. (void (*)(void))fake_rsa_st_settable_ctx_params },
  383. { OSSL_FUNC_STORE_SET_CTX_PARAMS, (void (*)(void))fake_rsa_st_set_ctx_params },
  384. { OSSL_FUNC_STORE_LOAD, (void (*)(void))fake_rsa_st_load },
  385. { OSSL_FUNC_STORE_EOF, (void (*)(void))fake_rsa_st_eof },
  386. { OSSL_FUNC_STORE_CLOSE, (void (*)(void))fake_rsa_st_close },
  387. { 0, NULL },
  388. };
  389. static const OSSL_ALGORITHM fake_rsa_store_algs[] = {
  390. { "fake_rsa", "provider=fake-rsa", fake_rsa_store_funcs },
  391. { NULL, NULL, NULL }
  392. };
  393. static const OSSL_ALGORITHM *fake_rsa_query(void *provctx,
  394. int operation_id,
  395. int *no_cache)
  396. {
  397. *no_cache = 0;
  398. switch (operation_id) {
  399. case OSSL_OP_SIGNATURE:
  400. return fake_rsa_sig_algs;
  401. case OSSL_OP_KEYMGMT:
  402. return fake_rsa_keymgmt_algs;
  403. case OSSL_OP_STORE:
  404. return fake_rsa_store_algs;
  405. }
  406. return NULL;
  407. }
  408. /* Functions we provide to the core */
  409. static const OSSL_DISPATCH fake_rsa_method[] = {
  410. { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))OSSL_LIB_CTX_free },
  411. { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))fake_rsa_query },
  412. { 0, NULL }
  413. };
  414. static int fake_rsa_provider_init(const OSSL_CORE_HANDLE *handle,
  415. const OSSL_DISPATCH *in,
  416. const OSSL_DISPATCH **out, void **provctx)
  417. {
  418. if (!TEST_ptr(*provctx = OSSL_LIB_CTX_new()))
  419. return 0;
  420. *out = fake_rsa_method;
  421. return 1;
  422. }
  423. OSSL_PROVIDER *fake_rsa_start(OSSL_LIB_CTX *libctx)
  424. {
  425. OSSL_PROVIDER *p;
  426. if (!TEST_true(OSSL_PROVIDER_add_builtin(libctx, "fake-rsa",
  427. fake_rsa_provider_init))
  428. || !TEST_ptr(p = OSSL_PROVIDER_try_load(libctx, "fake-rsa", 1)))
  429. return NULL;
  430. return p;
  431. }
  432. void fake_rsa_finish(OSSL_PROVIDER *p)
  433. {
  434. OSSL_PROVIDER_unload(p);
  435. }