dgst.c 18 KB

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