2
0

410-eng_devcrypto-add-configuration-options.patch 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Eneas U de Queiroz <[email protected]>
  3. Date: Sat, 3 Nov 2018 15:41:10 -0300
  4. Subject: eng_devcrypto: add configuration options
  5. USE_SOFTDRIVERS: whether to use software (not accelerated) drivers
  6. CIPHERS: list of ciphers to enable
  7. DIGESTS: list of digests to enable
  8. Signed-off-by: Eneas U de Queiroz <[email protected]>
  9. Reviewed-by: Matthias St. Pierre <[email protected]>
  10. Reviewed-by: Richard Levitte <[email protected]>
  11. (Merged from https://github.com/openssl/openssl/pull/7585)
  12. --- a/crypto/engine/eng_devcrypto.c
  13. +++ b/crypto/engine/eng_devcrypto.c
  14. @@ -16,6 +16,7 @@
  15. #include <unistd.h>
  16. #include <assert.h>
  17. +#include <openssl/conf.h>
  18. #include <openssl/evp.h>
  19. #include <openssl/err.h>
  20. #include <openssl/engine.h>
  21. @@ -36,6 +37,30 @@
  22. * saner... why re-open /dev/crypto for every session?
  23. */
  24. static int cfd;
  25. +#define DEVCRYPTO_REQUIRE_ACCELERATED 0 /* require confirmation of acceleration */
  26. +#define DEVCRYPTO_USE_SOFTWARE 1 /* allow software drivers */
  27. +#define DEVCRYPTO_REJECT_SOFTWARE 2 /* only disallow confirmed software drivers */
  28. +
  29. +#define DEVCRYPTO_DEFAULT_USE_SOFDTRIVERS DEVCRYPTO_REJECT_SOFTWARE
  30. +static int use_softdrivers = DEVCRYPTO_DEFAULT_USE_SOFDTRIVERS;
  31. +
  32. +/*
  33. + * cipher/digest status & acceleration definitions
  34. + * Make sure the defaults are set to 0
  35. + */
  36. +struct driver_info_st {
  37. + enum devcrypto_status_t {
  38. + DEVCRYPTO_STATUS_UNUSABLE = -1, /* session open failed */
  39. + DEVCRYPTO_STATUS_UNKNOWN = 0, /* not tested yet */
  40. + DEVCRYPTO_STATUS_USABLE = 1 /* algo can be used */
  41. + } status;
  42. +
  43. + enum devcrypto_accelerated_t {
  44. + DEVCRYPTO_NOT_ACCELERATED = -1, /* software implemented */
  45. + DEVCRYPTO_ACCELERATION_UNKNOWN = 0, /* acceleration support unkown */
  46. + DEVCRYPTO_ACCELERATED = 1 /* hardware accelerated */
  47. + } accelerated;
  48. +};
  49. static int clean_devcrypto_session(struct session_op *sess) {
  50. if (ioctl(cfd, CIOCFSESSION, &sess->ses) < 0) {
  51. @@ -119,13 +144,22 @@ static const struct cipher_data_st {
  52. #endif
  53. };
  54. -static size_t get_cipher_data_index(int nid)
  55. +static size_t find_cipher_data_index(int nid)
  56. {
  57. size_t i;
  58. for (i = 0; i < OSSL_NELEM(cipher_data); i++)
  59. if (nid == cipher_data[i].nid)
  60. return i;
  61. + return (size_t)-1;
  62. +}
  63. +
  64. +static size_t get_cipher_data_index(int nid)
  65. +{
  66. + size_t i = find_cipher_data_index(nid);
  67. +
  68. + if (i != (size_t)-1)
  69. + return i;
  70. /*
  71. * Code further down must make sure that only NIDs in the table above
  72. @@ -333,19 +367,40 @@ static int cipher_cleanup(EVP_CIPHER_CTX
  73. }
  74. /*
  75. - * Keep a table of known nids and associated methods.
  76. + * Keep tables of known nids, associated methods, selected ciphers, and driver
  77. + * info.
  78. * Note that known_cipher_nids[] isn't necessarily indexed the same way as
  79. - * cipher_data[] above, which known_cipher_methods[] is.
  80. + * cipher_data[] above, which the other tables are.
  81. */
  82. static int known_cipher_nids[OSSL_NELEM(cipher_data)];
  83. static int known_cipher_nids_amount = -1; /* -1 indicates not yet initialised */
  84. static EVP_CIPHER *known_cipher_methods[OSSL_NELEM(cipher_data)] = { NULL, };
  85. +static int selected_ciphers[OSSL_NELEM(cipher_data)];
  86. +static struct driver_info_st cipher_driver_info[OSSL_NELEM(cipher_data)];
  87. +
  88. +
  89. +static int devcrypto_test_cipher(size_t cipher_data_index)
  90. +{
  91. + return (cipher_driver_info[cipher_data_index].status == DEVCRYPTO_STATUS_USABLE
  92. + && selected_ciphers[cipher_data_index] == 1
  93. + && (cipher_driver_info[cipher_data_index].accelerated
  94. + == DEVCRYPTO_ACCELERATED
  95. + || use_softdrivers == DEVCRYPTO_USE_SOFTWARE
  96. + || (cipher_driver_info[cipher_data_index].accelerated
  97. + != DEVCRYPTO_NOT_ACCELERATED
  98. + && use_softdrivers == DEVCRYPTO_REJECT_SOFTWARE)));
  99. +}
  100. static void prepare_cipher_methods(void)
  101. {
  102. size_t i;
  103. struct session_op sess;
  104. unsigned long cipher_mode;
  105. +#ifdef CIOCGSESSINFO
  106. + struct session_info_op siop;
  107. +#endif
  108. +
  109. + memset(&cipher_driver_info, 0, sizeof(cipher_driver_info));
  110. memset(&sess, 0, sizeof(sess));
  111. sess.key = (void *)"01234567890123456789012345678901234567890123456789";
  112. @@ -353,15 +408,16 @@ static void prepare_cipher_methods(void)
  113. for (i = 0, known_cipher_nids_amount = 0;
  114. i < OSSL_NELEM(cipher_data); i++) {
  115. + selected_ciphers[i] = 1;
  116. /*
  117. - * Check that the algo is really availably by trying to open and close
  118. - * a session.
  119. + * Check that the cipher is usable
  120. */
  121. sess.cipher = cipher_data[i].devcryptoid;
  122. sess.keylen = cipher_data[i].keylen;
  123. - if (ioctl(cfd, CIOCGSESSION, &sess) < 0
  124. - || ioctl(cfd, CIOCFSESSION, &sess.ses) < 0)
  125. + if (ioctl(cfd, CIOCGSESSION, &sess) < 0) {
  126. + cipher_driver_info[i].status = DEVCRYPTO_STATUS_UNUSABLE;
  127. continue;
  128. + }
  129. cipher_mode = cipher_data[i].flags & EVP_CIPH_MODE;
  130. @@ -387,15 +443,41 @@ static void prepare_cipher_methods(void)
  131. cipher_cleanup)
  132. || !EVP_CIPHER_meth_set_impl_ctx_size(known_cipher_methods[i],
  133. sizeof(struct cipher_ctx))) {
  134. + cipher_driver_info[i].status = DEVCRYPTO_STATUS_UNUSABLE;
  135. EVP_CIPHER_meth_free(known_cipher_methods[i]);
  136. known_cipher_methods[i] = NULL;
  137. } else {
  138. + cipher_driver_info[i].status = DEVCRYPTO_STATUS_USABLE;
  139. +#ifdef CIOCGSESSINFO
  140. + siop.ses = sess.ses;
  141. + if (ioctl(cfd, CIOCGSESSINFO, &siop) < 0)
  142. + cipher_driver_info[i].accelerated = DEVCRYPTO_ACCELERATION_UNKNOWN;
  143. + else if (!(siop.flags & SIOP_FLAG_KERNEL_DRIVER_ONLY))
  144. + cipher_driver_info[i].accelerated = DEVCRYPTO_NOT_ACCELERATED;
  145. + else
  146. + cipher_driver_info[i].accelerated = DEVCRYPTO_ACCELERATED;
  147. +#endif /* CIOCGSESSINFO */
  148. + }
  149. + ioctl(cfd, CIOCFSESSION, &sess.ses);
  150. + if (devcrypto_test_cipher(i)) {
  151. known_cipher_nids[known_cipher_nids_amount++] =
  152. cipher_data[i].nid;
  153. }
  154. }
  155. }
  156. +static void rebuild_known_cipher_nids(ENGINE *e)
  157. +{
  158. + size_t i;
  159. +
  160. + for (i = 0, known_cipher_nids_amount = 0; i < OSSL_NELEM(cipher_data); i++) {
  161. + if (devcrypto_test_cipher(i))
  162. + known_cipher_nids[known_cipher_nids_amount++] = cipher_data[i].nid;
  163. + }
  164. + ENGINE_unregister_ciphers(e);
  165. + ENGINE_register_ciphers(e);
  166. +}
  167. +
  168. static const EVP_CIPHER *get_cipher_method(int nid)
  169. {
  170. size_t i = get_cipher_data_index(nid);
  171. @@ -438,6 +520,36 @@ static int devcrypto_ciphers(ENGINE *e,
  172. return *cipher != NULL;
  173. }
  174. +static void devcrypto_select_all_ciphers(int *cipher_list)
  175. +{
  176. + size_t i;
  177. +
  178. + for (i = 0; i < OSSL_NELEM(cipher_data); i++)
  179. + cipher_list[i] = 1;
  180. +}
  181. +
  182. +static int cryptodev_select_cipher_cb(const char *str, int len, void *usr)
  183. +{
  184. + int *cipher_list = (int *)usr;
  185. + char *name;
  186. + const EVP_CIPHER *EVP;
  187. + size_t i;
  188. +
  189. + if (len == 0)
  190. + return 1;
  191. + if (usr == NULL || (name = OPENSSL_strndup(str, len)) == NULL)
  192. + return 0;
  193. + EVP = EVP_get_cipherbyname(name);
  194. + if (EVP == NULL)
  195. + fprintf(stderr, "devcrypto: unknown cipher %s\n", name);
  196. + else if ((i = find_cipher_data_index(EVP_CIPHER_nid(EVP))) != (size_t)-1)
  197. + cipher_list[i] = 1;
  198. + else
  199. + fprintf(stderr, "devcrypto: cipher %s not available\n", name);
  200. + OPENSSL_free(name);
  201. + return 1;
  202. +}
  203. +
  204. /*
  205. * We only support digests if the cryptodev implementation supports multiple
  206. * data updates and session copying. Otherwise, we would be forced to maintain
  207. @@ -493,13 +605,22 @@ static const struct digest_data_st {
  208. #endif
  209. };
  210. -static size_t get_digest_data_index(int nid)
  211. +static size_t find_digest_data_index(int nid)
  212. {
  213. size_t i;
  214. for (i = 0; i < OSSL_NELEM(digest_data); i++)
  215. if (nid == digest_data[i].nid)
  216. return i;
  217. + return (size_t)-1;
  218. +}
  219. +
  220. +static size_t get_digest_data_index(int nid)
  221. +{
  222. + size_t i = find_digest_data_index(nid);
  223. +
  224. + if (i != (size_t)-1)
  225. + return i;
  226. /*
  227. * Code further down must make sure that only NIDs in the table above
  228. @@ -516,8 +637,8 @@ static const struct digest_data_st *get_
  229. }
  230. /*
  231. - * Following are the four necessary functions to map OpenSSL functionality
  232. - * with cryptodev.
  233. + * Following are the five necessary functions to map OpenSSL functionality
  234. + * with cryptodev: init, update, final, cleanup, and copy.
  235. */
  236. static int digest_init(EVP_MD_CTX *ctx)
  237. @@ -630,52 +751,94 @@ static int digest_cleanup(EVP_MD_CTX *ct
  238. return clean_devcrypto_session(&digest_ctx->sess);
  239. }
  240. -static int devcrypto_test_digest(size_t digest_data_index)
  241. -{
  242. - struct session_op sess1, sess2;
  243. - struct cphash_op cphash;
  244. - int ret=0;
  245. -
  246. - memset(&sess1, 0, sizeof(sess1));
  247. - memset(&sess2, 0, sizeof(sess2));
  248. - sess1.mac = digest_data[digest_data_index].devcryptoid;
  249. - if (ioctl(cfd, CIOCGSESSION, &sess1) < 0)
  250. - return 0;
  251. - /* Make sure the driver is capable of hash state copy */
  252. - sess2.mac = sess1.mac;
  253. - if (ioctl(cfd, CIOCGSESSION, &sess2) >= 0) {
  254. - cphash.src_ses = sess1.ses;
  255. - cphash.dst_ses = sess2.ses;
  256. - if (ioctl(cfd, CIOCCPHASH, &cphash) >= 0)
  257. - ret = 1;
  258. - ioctl(cfd, CIOCFSESSION, &sess2.ses);
  259. - }
  260. - ioctl(cfd, CIOCFSESSION, &sess1.ses);
  261. - return ret;
  262. -}
  263. -
  264. /*
  265. - * Keep a table of known nids and associated methods.
  266. + * Keep tables of known nids, associated methods, selected digests, and
  267. + * driver info.
  268. * Note that known_digest_nids[] isn't necessarily indexed the same way as
  269. - * digest_data[] above, which known_digest_methods[] is.
  270. + * digest_data[] above, which the other tables are.
  271. */
  272. static int known_digest_nids[OSSL_NELEM(digest_data)];
  273. static int known_digest_nids_amount = -1; /* -1 indicates not yet initialised */
  274. static EVP_MD *known_digest_methods[OSSL_NELEM(digest_data)] = { NULL, };
  275. +static int selected_digests[OSSL_NELEM(digest_data)];
  276. +static struct driver_info_st digest_driver_info[OSSL_NELEM(digest_data)];
  277. +
  278. +static int devcrypto_test_digest(size_t digest_data_index)
  279. +{
  280. + return (digest_driver_info[digest_data_index].status == DEVCRYPTO_STATUS_USABLE
  281. + && selected_digests[digest_data_index] == 1
  282. + && (digest_driver_info[digest_data_index].accelerated
  283. + == DEVCRYPTO_ACCELERATED
  284. + || use_softdrivers == DEVCRYPTO_USE_SOFTWARE
  285. + || (digest_driver_info[digest_data_index].accelerated
  286. + != DEVCRYPTO_NOT_ACCELERATED
  287. + && use_softdrivers == DEVCRYPTO_REJECT_SOFTWARE)));
  288. +}
  289. +
  290. +static void rebuild_known_digest_nids(ENGINE *e)
  291. +{
  292. + size_t i;
  293. +
  294. + for (i = 0, known_digest_nids_amount = 0; i < OSSL_NELEM(digest_data); i++) {
  295. + if (devcrypto_test_digest(i))
  296. + known_digest_nids[known_digest_nids_amount++] = digest_data[i].nid;
  297. + }
  298. + ENGINE_unregister_digests(e);
  299. + ENGINE_register_digests(e);
  300. +}
  301. static void prepare_digest_methods(void)
  302. {
  303. size_t i;
  304. + struct session_op sess1, sess2;
  305. +#ifdef CIOCGSESSINFO
  306. + struct session_info_op siop;
  307. +#endif
  308. + struct cphash_op cphash;
  309. +
  310. + memset(&digest_driver_info, 0, sizeof(digest_driver_info));
  311. +
  312. + memset(&sess1, 0, sizeof(sess1));
  313. + memset(&sess2, 0, sizeof(sess2));
  314. for (i = 0, known_digest_nids_amount = 0; i < OSSL_NELEM(digest_data);
  315. i++) {
  316. + selected_digests[i] = 1;
  317. +
  318. /*
  319. - * Check that the algo is usable
  320. + * Check that the digest is usable
  321. */
  322. - if (!devcrypto_test_digest(i))
  323. - continue;
  324. + sess1.mac = digest_data[i].devcryptoid;
  325. + sess2.ses = 0;
  326. + if (ioctl(cfd, CIOCGSESSION, &sess1) < 0) {
  327. + digest_driver_info[i].status = DEVCRYPTO_STATUS_UNUSABLE;
  328. + goto finish;
  329. + }
  330. +#ifdef CIOCGSESSINFO
  331. + /* gather hardware acceleration info from the driver */
  332. + siop.ses = sess1.ses;
  333. + if (ioctl(cfd, CIOCGSESSINFO, &siop) < 0)
  334. + digest_driver_info[i].accelerated = DEVCRYPTO_ACCELERATION_UNKNOWN;
  335. + else if (siop.flags & SIOP_FLAG_KERNEL_DRIVER_ONLY)
  336. + digest_driver_info[i].accelerated = DEVCRYPTO_ACCELERATED;
  337. + else
  338. + digest_driver_info[i].accelerated = DEVCRYPTO_NOT_ACCELERATED;
  339. +#endif
  340. +
  341. + /* digest must be capable of hash state copy */
  342. + sess2.mac = sess1.mac;
  343. + if (ioctl(cfd, CIOCGSESSION, &sess2) < 0) {
  344. + digest_driver_info[i].status = DEVCRYPTO_STATUS_UNUSABLE;
  345. + goto finish;
  346. + }
  347. + cphash.src_ses = sess1.ses;
  348. + cphash.dst_ses = sess2.ses;
  349. + if (ioctl(cfd, CIOCCPHASH, &cphash) < 0) {
  350. + digest_driver_info[i].status = DEVCRYPTO_STATUS_UNUSABLE;
  351. + goto finish;
  352. + }
  353. if ((known_digest_methods[i] = EVP_MD_meth_new(digest_data[i].nid,
  354. NID_undef)) == NULL
  355. || !EVP_MD_meth_set_input_blocksize(known_digest_methods[i],
  356. @@ -689,11 +852,18 @@ static void prepare_digest_methods(void)
  357. || !EVP_MD_meth_set_cleanup(known_digest_methods[i], digest_cleanup)
  358. || !EVP_MD_meth_set_app_datasize(known_digest_methods[i],
  359. sizeof(struct digest_ctx))) {
  360. + digest_driver_info[i].status = DEVCRYPTO_STATUS_UNUSABLE;
  361. EVP_MD_meth_free(known_digest_methods[i]);
  362. known_digest_methods[i] = NULL;
  363. - } else {
  364. - known_digest_nids[known_digest_nids_amount++] = digest_data[i].nid;
  365. + goto finish;
  366. }
  367. + digest_driver_info[i].status = DEVCRYPTO_STATUS_USABLE;
  368. +finish:
  369. + ioctl(cfd, CIOCFSESSION, &sess1.ses);
  370. + if (sess2.ses != 0)
  371. + ioctl(cfd, CIOCFSESSION, &sess2.ses);
  372. + if (devcrypto_test_digest(i))
  373. + known_digest_nids[known_digest_nids_amount++] = digest_data[i].nid;
  374. }
  375. }
  376. @@ -739,7 +909,153 @@ static int devcrypto_digests(ENGINE *e,
  377. return *digest != NULL;
  378. }
  379. +static void devcrypto_select_all_digests(int *digest_list)
  380. +{
  381. + size_t i;
  382. +
  383. + for (i = 0; i < OSSL_NELEM(digest_data); i++)
  384. + digest_list[i] = 1;
  385. +}
  386. +
  387. +static int cryptodev_select_digest_cb(const char *str, int len, void *usr)
  388. +{
  389. + int *digest_list = (int *)usr;
  390. + char *name;
  391. + const EVP_MD *EVP;
  392. + size_t i;
  393. +
  394. + if (len == 0)
  395. + return 1;
  396. + if (usr == NULL || (name = OPENSSL_strndup(str, len)) == NULL)
  397. + return 0;
  398. + EVP = EVP_get_digestbyname(name);
  399. + if (EVP == NULL)
  400. + fprintf(stderr, "devcrypto: unknown digest %s\n", name);
  401. + else if ((i = find_digest_data_index(EVP_MD_type(EVP))) != (size_t)-1)
  402. + digest_list[i] = 1;
  403. + else
  404. + fprintf(stderr, "devcrypto: digest %s not available\n", name);
  405. + OPENSSL_free(name);
  406. + return 1;
  407. +}
  408. +
  409. +#endif
  410. +
  411. +/******************************************************************************
  412. + *
  413. + * CONTROL COMMANDS
  414. + *
  415. + *****/
  416. +
  417. +#define DEVCRYPTO_CMD_USE_SOFTDRIVERS ENGINE_CMD_BASE
  418. +#define DEVCRYPTO_CMD_CIPHERS (ENGINE_CMD_BASE + 1)
  419. +#define DEVCRYPTO_CMD_DIGESTS (ENGINE_CMD_BASE + 2)
  420. +#define DEVCRYPTO_CMD_DUMP_INFO (ENGINE_CMD_BASE + 3)
  421. +
  422. +/* Helper macros for CPP string composition */
  423. +#ifndef OPENSSL_MSTR
  424. +# define OPENSSL_MSTR_HELPER(x) #x
  425. +# define OPENSSL_MSTR(x) OPENSSL_MSTR_HELPER(x)
  426. +#endif
  427. +
  428. +static const ENGINE_CMD_DEFN devcrypto_cmds[] = {
  429. +#ifdef CIOCGSESSINFO
  430. + {DEVCRYPTO_CMD_USE_SOFTDRIVERS,
  431. + "USE_SOFTDRIVERS",
  432. + "specifies whether to use software (not accelerated) drivers ("
  433. + OPENSSL_MSTR(DEVCRYPTO_REQUIRE_ACCELERATED) "=use only accelerated drivers, "
  434. + OPENSSL_MSTR(DEVCRYPTO_USE_SOFTWARE) "=allow all drivers, "
  435. + OPENSSL_MSTR(DEVCRYPTO_REJECT_SOFTWARE)
  436. + "=use if acceleration can't be determined) [default="
  437. + OPENSSL_MSTR(DEVCRYPTO_DEFAULT_USE_SOFDTRIVERS) "]",
  438. + ENGINE_CMD_FLAG_NUMERIC},
  439. +#endif
  440. +
  441. + {DEVCRYPTO_CMD_CIPHERS,
  442. + "CIPHERS",
  443. + "either ALL, NONE, or a comma-separated list of ciphers to enable [default=ALL]",
  444. + ENGINE_CMD_FLAG_STRING},
  445. +
  446. +#ifdef IMPLEMENT_DIGEST
  447. + {DEVCRYPTO_CMD_DIGESTS,
  448. + "DIGESTS",
  449. + "either ALL, NONE, or a comma-separated list of digests to enable [default=ALL]",
  450. + ENGINE_CMD_FLAG_STRING},
  451. +#endif
  452. +
  453. + {0, NULL, NULL, 0}
  454. +};
  455. +
  456. +static int devcrypto_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
  457. +{
  458. + int *new_list;
  459. + switch (cmd) {
  460. +#ifdef CIOCGSESSINFO
  461. + case DEVCRYPTO_CMD_USE_SOFTDRIVERS:
  462. + switch (i) {
  463. + case DEVCRYPTO_REQUIRE_ACCELERATED:
  464. + case DEVCRYPTO_USE_SOFTWARE:
  465. + case DEVCRYPTO_REJECT_SOFTWARE:
  466. + break;
  467. + default:
  468. + fprintf(stderr, "devcrypto: invalid value (%ld) for USE_SOFTDRIVERS\n", i);
  469. + return 0;
  470. + }
  471. + if (use_softdrivers == i)
  472. + return 1;
  473. + use_softdrivers = i;
  474. +#ifdef IMPLEMENT_DIGEST
  475. + rebuild_known_digest_nids(e);
  476. #endif
  477. + rebuild_known_cipher_nids(e);
  478. + return 1;
  479. +#endif /* CIOCGSESSINFO */
  480. +
  481. + case DEVCRYPTO_CMD_CIPHERS:
  482. + if (p == NULL)
  483. + return 1;
  484. + if (strcasecmp((const char *)p, "ALL") == 0) {
  485. + devcrypto_select_all_ciphers(selected_ciphers);
  486. + } else if (strcasecmp((const char*)p, "NONE") == 0) {
  487. + memset(selected_ciphers, 0, sizeof(selected_ciphers));
  488. + } else {
  489. + new_list=OPENSSL_zalloc(sizeof(selected_ciphers));
  490. + if (!CONF_parse_list(p, ',', 1, cryptodev_select_cipher_cb, new_list)) {
  491. + OPENSSL_free(new_list);
  492. + return 0;
  493. + }
  494. + memcpy(selected_ciphers, new_list, sizeof(selected_ciphers));
  495. + OPENSSL_free(new_list);
  496. + }
  497. + rebuild_known_cipher_nids(e);
  498. + return 1;
  499. +
  500. +#ifdef IMPLEMENT_DIGEST
  501. + case DEVCRYPTO_CMD_DIGESTS:
  502. + if (p == NULL)
  503. + return 1;
  504. + if (strcasecmp((const char *)p, "ALL") == 0) {
  505. + devcrypto_select_all_digests(selected_digests);
  506. + } else if (strcasecmp((const char*)p, "NONE") == 0) {
  507. + memset(selected_digests, 0, sizeof(selected_digests));
  508. + } else {
  509. + new_list=OPENSSL_zalloc(sizeof(selected_digests));
  510. + if (!CONF_parse_list(p, ',', 1, cryptodev_select_digest_cb, new_list)) {
  511. + OPENSSL_free(new_list);
  512. + return 0;
  513. + }
  514. + memcpy(selected_digests, new_list, sizeof(selected_digests));
  515. + OPENSSL_free(new_list);
  516. + }
  517. + rebuild_known_digest_nids(e);
  518. + return 1;
  519. +#endif /* IMPLEMENT_DIGEST */
  520. +
  521. + default:
  522. + break;
  523. + }
  524. + return 0;
  525. +}
  526. /******************************************************************************
  527. *
  528. @@ -806,6 +1122,8 @@ void engine_load_devcrypto_int()
  529. if (!ENGINE_set_id(e, "devcrypto")
  530. || !ENGINE_set_name(e, "/dev/crypto engine")
  531. + || !ENGINE_set_cmd_defns(e, devcrypto_cmds)
  532. + || !ENGINE_set_ctrl_function(e, devcrypto_ctrl)
  533. /*
  534. * Asymmetric ciphers aren't well supported with /dev/crypto. Among the BSD