dgst.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /*
  2. * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include "apps.h"
  13. #include "progs.h"
  14. #include <openssl/bio.h>
  15. #include <openssl/err.h>
  16. #include <openssl/evp.h>
  17. #include <openssl/objects.h>
  18. #include <openssl/x509.h>
  19. #include <openssl/pem.h>
  20. #include <openssl/hmac.h>
  21. #include <ctype.h>
  22. #undef BUFSIZE
  23. #define BUFSIZE 1024*8
  24. int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
  25. EVP_PKEY *key, unsigned char *sigin, int siglen,
  26. const char *sig_name, const char *md_name,
  27. const char *file);
  28. static void show_digests(const OBJ_NAME *name, void *bio_);
  29. struct doall_dgst_digests {
  30. BIO *bio;
  31. int n;
  32. };
  33. typedef enum OPTION_choice {
  34. OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_LIST,
  35. OPT_C, OPT_R, OPT_OUT, OPT_SIGN, OPT_PASSIN, OPT_VERIFY,
  36. OPT_PRVERIFY, OPT_SIGNATURE, OPT_KEYFORM, OPT_ENGINE, OPT_ENGINE_IMPL,
  37. OPT_HEX, OPT_BINARY, OPT_DEBUG, OPT_FIPS_FINGERPRINT,
  38. OPT_HMAC, OPT_MAC, OPT_SIGOPT, OPT_MACOPT,
  39. OPT_DIGEST,
  40. OPT_R_ENUM
  41. } OPTION_CHOICE;
  42. const OPTIONS dgst_options[] = {
  43. {OPT_HELP_STR, 1, '-', "Usage: %s [options] [file...]\n"},
  44. OPT_SECTION("General"),
  45. {"help", OPT_HELP, '-', "Display this summary"},
  46. {"list", OPT_LIST, '-', "List digests"},
  47. #ifndef OPENSSL_NO_ENGINE
  48. {"engine", OPT_ENGINE, 's', "Use engine e, possibly a hardware device"},
  49. {"engine_impl", OPT_ENGINE_IMPL, '-',
  50. "Also use engine given by -engine for digest operations"},
  51. #endif
  52. {"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
  53. OPT_SECTION("Output"),
  54. {"c", OPT_C, '-', "Print the digest with separating colons"},
  55. {"r", OPT_R, '-', "Print the digest in coreutils format"},
  56. {"out", OPT_OUT, '>', "Output to filename rather than stdout"},
  57. {"keyform", OPT_KEYFORM, 'f', "Key file format (PEM or ENGINE)"},
  58. {"hex", OPT_HEX, '-', "Print as hex dump"},
  59. {"binary", OPT_BINARY, '-', "Print in binary form"},
  60. {"d", OPT_DEBUG, '-', "Print debug info"},
  61. {"debug", OPT_DEBUG, '-', "Print debug info"},
  62. OPT_SECTION("Signing"),
  63. {"sign", OPT_SIGN, 's', "Sign digest using private key"},
  64. {"verify", OPT_VERIFY, 's', "Verify a signature using public key"},
  65. {"prverify", OPT_PRVERIFY, 's', "Verify a signature using private key"},
  66. {"sigopt", OPT_SIGOPT, 's', "Signature parameter in n:v form"},
  67. {"signature", OPT_SIGNATURE, '<', "File with signature to verify"},
  68. {"hmac", OPT_HMAC, 's', "Create hashed MAC with key"},
  69. {"mac", OPT_MAC, 's', "Create MAC (not necessarily HMAC)"},
  70. {"macopt", OPT_MACOPT, 's', "MAC algorithm parameters in n:v form or key"},
  71. {"", OPT_DIGEST, '-', "Any supported digest"},
  72. {"fips-fingerprint", OPT_FIPS_FINGERPRINT, '-',
  73. "Compute HMAC with the key used in OpenSSL-FIPS fingerprint"},
  74. OPT_R_OPTIONS,
  75. OPT_PARAMETERS(),
  76. {"file", 0, 0, "Files to digest (optional; default is stdin)"},
  77. {NULL}
  78. };
  79. int dgst_main(int argc, char **argv)
  80. {
  81. BIO *in = NULL, *inp, *bmd = NULL, *out = NULL;
  82. ENGINE *e = NULL, *impl = NULL;
  83. EVP_PKEY *sigkey = NULL;
  84. STACK_OF(OPENSSL_STRING) *sigopts = NULL, *macopts = NULL;
  85. char *hmac_key = NULL;
  86. char *mac_name = NULL;
  87. char *passinarg = NULL, *passin = NULL;
  88. const EVP_MD *md = NULL, *m;
  89. const char *outfile = NULL, *keyfile = NULL, *prog = NULL;
  90. const char *sigfile = NULL;
  91. const char *md_name = NULL;
  92. OPTION_CHOICE o;
  93. int separator = 0, debug = 0, keyform = FORMAT_PEM, siglen = 0;
  94. int i, ret = 1, out_bin = -1, want_pub = 0, do_verify = 0;
  95. unsigned char *buf = NULL, *sigbuf = NULL;
  96. int engine_impl = 0;
  97. struct doall_dgst_digests dec;
  98. prog = opt_progname(argv[0]);
  99. buf = app_malloc(BUFSIZE, "I/O buffer");
  100. md = EVP_get_digestbyname(prog);
  101. prog = opt_init(argc, argv, dgst_options);
  102. while ((o = opt_next()) != OPT_EOF) {
  103. switch (o) {
  104. case OPT_EOF:
  105. case OPT_ERR:
  106. opthelp:
  107. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  108. goto end;
  109. case OPT_HELP:
  110. opt_help(dgst_options);
  111. ret = 0;
  112. goto end;
  113. case OPT_LIST:
  114. BIO_printf(bio_out, "Supported digests:\n");
  115. dec.bio = bio_out;
  116. dec.n = 0;
  117. OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_MD_METH,
  118. show_digests, &dec);
  119. BIO_printf(bio_out, "\n");
  120. ret = 0;
  121. goto end;
  122. case OPT_C:
  123. separator = 1;
  124. break;
  125. case OPT_R:
  126. separator = 2;
  127. break;
  128. case OPT_R_CASES:
  129. if (!opt_rand(o))
  130. goto end;
  131. break;
  132. case OPT_OUT:
  133. outfile = opt_arg();
  134. break;
  135. case OPT_SIGN:
  136. keyfile = opt_arg();
  137. break;
  138. case OPT_PASSIN:
  139. passinarg = opt_arg();
  140. break;
  141. case OPT_VERIFY:
  142. keyfile = opt_arg();
  143. want_pub = do_verify = 1;
  144. break;
  145. case OPT_PRVERIFY:
  146. keyfile = opt_arg();
  147. do_verify = 1;
  148. break;
  149. case OPT_SIGNATURE:
  150. sigfile = opt_arg();
  151. break;
  152. case OPT_KEYFORM:
  153. if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyform))
  154. goto opthelp;
  155. break;
  156. case OPT_ENGINE:
  157. e = setup_engine(opt_arg(), 0);
  158. break;
  159. case OPT_ENGINE_IMPL:
  160. engine_impl = 1;
  161. break;
  162. case OPT_HEX:
  163. out_bin = 0;
  164. break;
  165. case OPT_BINARY:
  166. out_bin = 1;
  167. break;
  168. case OPT_DEBUG:
  169. debug = 1;
  170. break;
  171. case OPT_FIPS_FINGERPRINT:
  172. hmac_key = "etaonrishdlcupfm";
  173. break;
  174. case OPT_HMAC:
  175. hmac_key = opt_arg();
  176. break;
  177. case OPT_MAC:
  178. mac_name = opt_arg();
  179. break;
  180. case OPT_SIGOPT:
  181. if (!sigopts)
  182. sigopts = sk_OPENSSL_STRING_new_null();
  183. if (!sigopts || !sk_OPENSSL_STRING_push(sigopts, opt_arg()))
  184. goto opthelp;
  185. break;
  186. case OPT_MACOPT:
  187. if (!macopts)
  188. macopts = sk_OPENSSL_STRING_new_null();
  189. if (!macopts || !sk_OPENSSL_STRING_push(macopts, opt_arg()))
  190. goto opthelp;
  191. break;
  192. case OPT_DIGEST:
  193. if (!opt_md(opt_unknown(), &m))
  194. goto opthelp;
  195. md = m;
  196. break;
  197. }
  198. }
  199. argc = opt_num_rest();
  200. argv = opt_rest();
  201. if (keyfile != NULL && argc > 1) {
  202. BIO_printf(bio_err, "%s: Can only sign or verify one file.\n", prog);
  203. goto end;
  204. }
  205. if (do_verify && sigfile == NULL) {
  206. BIO_printf(bio_err,
  207. "No signature to verify: use the -signature option\n");
  208. goto end;
  209. }
  210. if (engine_impl)
  211. impl = e;
  212. in = BIO_new(BIO_s_file());
  213. bmd = BIO_new(BIO_f_md());
  214. if ((in == NULL) || (bmd == NULL)) {
  215. ERR_print_errors(bio_err);
  216. goto end;
  217. }
  218. if (debug) {
  219. BIO_set_callback(in, BIO_debug_callback);
  220. /* needed for windows 3.1 */
  221. BIO_set_callback_arg(in, (char *)bio_err);
  222. }
  223. if (!app_passwd(passinarg, NULL, &passin, NULL)) {
  224. BIO_printf(bio_err, "Error getting password\n");
  225. goto end;
  226. }
  227. if (out_bin == -1) {
  228. if (keyfile != NULL)
  229. out_bin = 1;
  230. else
  231. out_bin = 0;
  232. }
  233. out = bio_open_default(outfile, 'w', out_bin ? FORMAT_BINARY : FORMAT_TEXT);
  234. if (out == NULL)
  235. goto end;
  236. if ((!(mac_name == NULL) + !(keyfile == NULL) + !(hmac_key == NULL)) > 1) {
  237. BIO_printf(bio_err, "MAC and Signing key cannot both be specified\n");
  238. goto end;
  239. }
  240. if (keyfile != NULL) {
  241. int type;
  242. if (want_pub)
  243. sigkey = load_pubkey(keyfile, keyform, 0, NULL, e, "key file");
  244. else
  245. sigkey = load_key(keyfile, keyform, 0, passin, e, "key file");
  246. if (sigkey == NULL) {
  247. /*
  248. * load_[pub]key() has already printed an appropriate message
  249. */
  250. goto end;
  251. }
  252. type = EVP_PKEY_id(sigkey);
  253. if (type == EVP_PKEY_ED25519 || type == EVP_PKEY_ED448) {
  254. /*
  255. * We implement PureEdDSA for these which doesn't have a separate
  256. * digest, and only supports one shot.
  257. */
  258. BIO_printf(bio_err, "Key type not supported for this operation\n");
  259. goto end;
  260. }
  261. }
  262. if (mac_name != NULL) {
  263. EVP_PKEY_CTX *mac_ctx = NULL;
  264. int r = 0;
  265. if (!init_gen_str(&mac_ctx, mac_name, impl, 0))
  266. goto mac_end;
  267. if (macopts != NULL) {
  268. char *macopt;
  269. for (i = 0; i < sk_OPENSSL_STRING_num(macopts); i++) {
  270. macopt = sk_OPENSSL_STRING_value(macopts, i);
  271. if (pkey_ctrl_string(mac_ctx, macopt) <= 0) {
  272. BIO_printf(bio_err,
  273. "MAC parameter error \"%s\"\n", macopt);
  274. ERR_print_errors(bio_err);
  275. goto mac_end;
  276. }
  277. }
  278. }
  279. if (EVP_PKEY_keygen(mac_ctx, &sigkey) <= 0) {
  280. BIO_puts(bio_err, "Error generating key\n");
  281. ERR_print_errors(bio_err);
  282. goto mac_end;
  283. }
  284. r = 1;
  285. mac_end:
  286. EVP_PKEY_CTX_free(mac_ctx);
  287. if (r == 0)
  288. goto end;
  289. }
  290. if (hmac_key != NULL) {
  291. sigkey = EVP_PKEY_new_raw_private_key(EVP_PKEY_HMAC, impl,
  292. (unsigned char *)hmac_key, -1);
  293. if (sigkey == NULL)
  294. goto end;
  295. }
  296. if (sigkey != NULL) {
  297. EVP_MD_CTX *mctx = NULL;
  298. EVP_PKEY_CTX *pctx = NULL;
  299. int r;
  300. if (!BIO_get_md_ctx(bmd, &mctx)) {
  301. BIO_printf(bio_err, "Error getting context\n");
  302. ERR_print_errors(bio_err);
  303. goto end;
  304. }
  305. if (do_verify)
  306. r = EVP_DigestVerifyInit(mctx, &pctx, md, impl, sigkey);
  307. else
  308. r = EVP_DigestSignInit(mctx, &pctx, md, impl, sigkey);
  309. if (!r) {
  310. BIO_printf(bio_err, "Error setting context\n");
  311. ERR_print_errors(bio_err);
  312. goto end;
  313. }
  314. if (sigopts != NULL) {
  315. char *sigopt;
  316. for (i = 0; i < sk_OPENSSL_STRING_num(sigopts); i++) {
  317. sigopt = sk_OPENSSL_STRING_value(sigopts, i);
  318. if (pkey_ctrl_string(pctx, sigopt) <= 0) {
  319. BIO_printf(bio_err, "parameter error \"%s\"\n", sigopt);
  320. ERR_print_errors(bio_err);
  321. goto end;
  322. }
  323. }
  324. }
  325. }
  326. /* we use md as a filter, reading from 'in' */
  327. else {
  328. EVP_MD_CTX *mctx = NULL;
  329. if (!BIO_get_md_ctx(bmd, &mctx)) {
  330. BIO_printf(bio_err, "Error getting context\n");
  331. ERR_print_errors(bio_err);
  332. goto end;
  333. }
  334. if (md == NULL)
  335. md = EVP_sha256();
  336. if (!EVP_DigestInit_ex(mctx, md, impl)) {
  337. BIO_printf(bio_err, "Error setting digest\n");
  338. ERR_print_errors(bio_err);
  339. goto end;
  340. }
  341. }
  342. if (sigfile != NULL && sigkey != NULL) {
  343. BIO *sigbio = BIO_new_file(sigfile, "rb");
  344. if (sigbio == NULL) {
  345. BIO_printf(bio_err, "Error opening signature file %s\n", sigfile);
  346. ERR_print_errors(bio_err);
  347. goto end;
  348. }
  349. siglen = EVP_PKEY_size(sigkey);
  350. sigbuf = app_malloc(siglen, "signature buffer");
  351. siglen = BIO_read(sigbio, sigbuf, siglen);
  352. BIO_free(sigbio);
  353. if (siglen <= 0) {
  354. BIO_printf(bio_err, "Error reading signature file %s\n", sigfile);
  355. ERR_print_errors(bio_err);
  356. goto end;
  357. }
  358. }
  359. inp = BIO_push(bmd, in);
  360. if (md == NULL) {
  361. EVP_MD_CTX *tctx;
  362. BIO_get_md_ctx(bmd, &tctx);
  363. md = EVP_MD_CTX_md(tctx);
  364. }
  365. if (md != NULL)
  366. md_name = EVP_MD_name(md);
  367. if (argc == 0) {
  368. BIO_set_fp(in, stdin, BIO_NOCLOSE);
  369. ret = do_fp(out, buf, inp, separator, out_bin, sigkey, sigbuf,
  370. siglen, NULL, md_name, "stdin");
  371. } else {
  372. const char *sig_name = NULL;
  373. if (!out_bin) {
  374. if (sigkey != NULL) {
  375. const EVP_PKEY_ASN1_METHOD *ameth;
  376. ameth = EVP_PKEY_get0_asn1(sigkey);
  377. if (ameth)
  378. EVP_PKEY_asn1_get0_info(NULL, NULL,
  379. NULL, NULL, &sig_name, ameth);
  380. }
  381. }
  382. ret = 0;
  383. for (i = 0; i < argc; i++) {
  384. int r;
  385. if (BIO_read_filename(in, argv[i]) <= 0) {
  386. perror(argv[i]);
  387. ret++;
  388. continue;
  389. } else {
  390. r = do_fp(out, buf, inp, separator, out_bin, sigkey, sigbuf,
  391. siglen, sig_name, md_name, argv[i]);
  392. }
  393. if (r)
  394. ret = r;
  395. (void)BIO_reset(bmd);
  396. }
  397. }
  398. end:
  399. OPENSSL_clear_free(buf, BUFSIZE);
  400. BIO_free(in);
  401. OPENSSL_free(passin);
  402. BIO_free_all(out);
  403. EVP_PKEY_free(sigkey);
  404. sk_OPENSSL_STRING_free(sigopts);
  405. sk_OPENSSL_STRING_free(macopts);
  406. OPENSSL_free(sigbuf);
  407. BIO_free(bmd);
  408. release_engine(e);
  409. return ret;
  410. }
  411. static void show_digests(const OBJ_NAME *name, void *arg)
  412. {
  413. struct doall_dgst_digests *dec = (struct doall_dgst_digests *)arg;
  414. const EVP_MD *md = NULL;
  415. /* Filter out signed digests (a.k.a signature algorithms) */
  416. if (strstr(name->name, "rsa") != NULL || strstr(name->name, "RSA") != NULL)
  417. return;
  418. if (!islower((unsigned char)*name->name))
  419. return;
  420. /* Filter out message digests that we cannot use */
  421. md = EVP_get_digestbyname(name->name);
  422. if (md == NULL)
  423. return;
  424. BIO_printf(dec->bio, "-%-25s", name->name);
  425. if (++dec->n == 3) {
  426. BIO_printf(dec->bio, "\n");
  427. dec->n = 0;
  428. } else {
  429. BIO_printf(dec->bio, " ");
  430. }
  431. }
  432. /*
  433. * The newline_escape_filename function performs newline escaping for any
  434. * filename that contains a newline. This function also takes a pointer
  435. * to backslash. The backslash pointer is a flag to indicating whether a newline
  436. * is present in the filename. If a newline is present, the backslash flag is
  437. * set and the output format will contain a backslash at the beginning of the
  438. * digest output. This output format is to replicate the output format found
  439. * in the '*sum' checksum programs. This aims to preserve backward
  440. * compatibility.
  441. */
  442. static const char *newline_escape_filename(const char *file, int * backslash)
  443. {
  444. size_t i, e = 0, length = strlen(file), newline_count = 0, mem_len = 0;
  445. char *file_cpy = NULL;
  446. for (i = 0; i < length; i++)
  447. if (file[i] == '\n')
  448. newline_count++;
  449. mem_len = length + newline_count + 1;
  450. file_cpy = app_malloc(mem_len, file);
  451. i = 0;
  452. while(e < length) {
  453. const char c = file[e];
  454. if (c == '\n') {
  455. file_cpy[i++] = '\\';
  456. file_cpy[i++] = 'n';
  457. *backslash = 1;
  458. } else {
  459. file_cpy[i++] = c;
  460. }
  461. e++;
  462. }
  463. file_cpy[i] = '\0';
  464. return (const char*)file_cpy;
  465. }
  466. int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
  467. EVP_PKEY *key, unsigned char *sigin, int siglen,
  468. const char *sig_name, const char *md_name,
  469. const char *file)
  470. {
  471. size_t len = BUFSIZE;
  472. int i, backslash = 0, ret = 1;
  473. unsigned char *sigbuf = NULL;
  474. while (BIO_pending(bp) || !BIO_eof(bp)) {
  475. i = BIO_read(bp, (char *)buf, BUFSIZE);
  476. if (i < 0) {
  477. BIO_printf(bio_err, "Read Error in %s\n", file);
  478. ERR_print_errors(bio_err);
  479. goto end;
  480. }
  481. if (i == 0)
  482. break;
  483. }
  484. if (sigin != NULL) {
  485. EVP_MD_CTX *ctx;
  486. BIO_get_md_ctx(bp, &ctx);
  487. i = EVP_DigestVerifyFinal(ctx, sigin, (unsigned int)siglen);
  488. if (i > 0) {
  489. BIO_printf(out, "Verified OK\n");
  490. } else if (i == 0) {
  491. BIO_printf(out, "Verification Failure\n");
  492. goto end;
  493. } else {
  494. BIO_printf(bio_err, "Error Verifying Data\n");
  495. ERR_print_errors(bio_err);
  496. goto end;
  497. }
  498. ret = 0;
  499. goto end;
  500. }
  501. if (key != NULL) {
  502. EVP_MD_CTX *ctx;
  503. size_t tmplen;
  504. BIO_get_md_ctx(bp, &ctx);
  505. if (!EVP_DigestSignFinal(ctx, NULL, &tmplen)) {
  506. BIO_printf(bio_err, "Error Signing Data\n");
  507. ERR_print_errors(bio_err);
  508. goto end;
  509. }
  510. if (tmplen > BUFSIZE) {
  511. len = tmplen;
  512. sigbuf = app_malloc(len, "Signature buffer");
  513. buf = sigbuf;
  514. }
  515. if (!EVP_DigestSignFinal(ctx, buf, &len)) {
  516. BIO_printf(bio_err, "Error Signing Data\n");
  517. ERR_print_errors(bio_err);
  518. goto end;
  519. }
  520. } else {
  521. len = BIO_gets(bp, (char *)buf, BUFSIZE);
  522. if ((int)len < 0) {
  523. ERR_print_errors(bio_err);
  524. goto end;
  525. }
  526. }
  527. if (binout) {
  528. BIO_write(out, buf, len);
  529. } else if (sep == 2) {
  530. file = newline_escape_filename(file, &backslash);
  531. if (backslash == 1)
  532. BIO_puts(out, "\\");
  533. for (i = 0; i < (int)len; i++)
  534. BIO_printf(out, "%02x", buf[i]);
  535. BIO_printf(out, " *%s\n", file);
  536. OPENSSL_free((char *)file);
  537. } else {
  538. if (sig_name != NULL) {
  539. BIO_puts(out, sig_name);
  540. if (md_name != NULL)
  541. BIO_printf(out, "-%s", md_name);
  542. BIO_printf(out, "(%s)= ", file);
  543. } else if (md_name != NULL) {
  544. BIO_printf(out, "%s(%s)= ", md_name, file);
  545. } else {
  546. BIO_printf(out, "(%s)= ", file);
  547. }
  548. for (i = 0; i < (int)len; i++) {
  549. if (sep && (i != 0))
  550. BIO_printf(out, ":");
  551. BIO_printf(out, "%02x", buf[i]);
  552. }
  553. BIO_printf(out, "\n");
  554. }
  555. ret = 0;
  556. end:
  557. if (sigbuf != NULL)
  558. OPENSSL_clear_free(sigbuf, len);
  559. return ret;
  560. }