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

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