dgst.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /* apps/dgst.c */
  2. /* Copyright (C) 1995-1998 Eric Young ([email protected])
  3. * All rights reserved.
  4. *
  5. * This package is an SSL implementation written
  6. * by Eric Young ([email protected]).
  7. * The implementation was written so as to conform with Netscapes SSL.
  8. *
  9. * This library is free for commercial and non-commercial use as long as
  10. * the following conditions are aheared to. The following conditions
  11. * apply to all code found in this distribution, be it the RC4, RSA,
  12. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  13. * included with this distribution is covered by the same copyright terms
  14. * except that the holder is Tim Hudson ([email protected]).
  15. *
  16. * Copyright remains Eric Young's, and as such any Copyright notices in
  17. * the code are not to be removed.
  18. * If this package is used in a product, Eric Young should be given attribution
  19. * as the author of the parts of the library used.
  20. * This can be in the form of a textual message at program startup or
  21. * in documentation (online or textual) provided with the package.
  22. *
  23. * Redistribution and use in source and binary forms, with or without
  24. * modification, are permitted provided that the following conditions
  25. * are met:
  26. * 1. Redistributions of source code must retain the copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * 2. Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in the
  30. * documentation and/or other materials provided with the distribution.
  31. * 3. All advertising materials mentioning features or use of this software
  32. * must display the following acknowledgement:
  33. * "This product includes cryptographic software written by
  34. * Eric Young ([email protected])"
  35. * The word 'cryptographic' can be left out if the rouines from the library
  36. * being used are not cryptographic related :-).
  37. * 4. If you include any Windows specific code (or a derivative thereof) from
  38. * the apps directory (application code) you must include an acknowledgement:
  39. * "This product includes software written by Tim Hudson ([email protected])"
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  42. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  43. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  45. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  46. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  47. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  49. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  51. * SUCH DAMAGE.
  52. *
  53. * The licence and distribution terms for any publically available version or
  54. * derivative of this code cannot be changed. i.e. this code cannot simply be
  55. * copied and put under another distribution licence
  56. * [including the GNU Public Licence.]
  57. */
  58. #include <stdio.h>
  59. #include <string.h>
  60. #include <stdlib.h>
  61. #include "apps.h"
  62. #include <openssl/bio.h>
  63. #include <openssl/err.h>
  64. #include <openssl/evp.h>
  65. #include <openssl/objects.h>
  66. #include <openssl/x509.h>
  67. #include <openssl/pem.h>
  68. #include <openssl/hmac.h>
  69. #undef BUFSIZE
  70. #define BUFSIZE 1024*8
  71. #undef PROG
  72. #define PROG dgst_main
  73. int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
  74. EVP_PKEY *key, unsigned char *sigin, int siglen,
  75. const char *sig_name, const char *md_name,
  76. const char *file, BIO *bmd);
  77. static void list_md_fn(const EVP_MD *m,
  78. const char *from, const char *to, void *arg)
  79. {
  80. const char *mname;
  81. /* Skip aliases */
  82. if (!m)
  83. return;
  84. mname = OBJ_nid2ln(EVP_MD_type(m));
  85. /* Skip shortnames */
  86. if (strcmp(from, mname))
  87. return;
  88. /* Skip clones */
  89. if (EVP_MD_flags(m) & EVP_MD_FLAG_PKEY_DIGEST)
  90. return;
  91. if (strchr(mname, ' '))
  92. mname = EVP_MD_name(m);
  93. BIO_printf(arg, "-%-14s to use the %s message digest algorithm\n",
  94. mname, mname);
  95. }
  96. int MAIN(int, char **);
  97. int MAIN(int argc, char **argv)
  98. {
  99. ENGINE *e = NULL;
  100. unsigned char *buf = NULL;
  101. int i, err = 1;
  102. const EVP_MD *md = NULL, *m;
  103. BIO *in = NULL, *inp;
  104. BIO *bmd = NULL;
  105. BIO *out = NULL;
  106. #define PROG_NAME_SIZE 39
  107. char pname[PROG_NAME_SIZE + 1];
  108. int separator = 0;
  109. int debug = 0;
  110. int keyform = FORMAT_PEM;
  111. const char *outfile = NULL, *keyfile = NULL;
  112. const char *sigfile = NULL, *randfile = NULL;
  113. int out_bin = -1, want_pub = 0, do_verify = 0;
  114. EVP_PKEY *sigkey = NULL;
  115. unsigned char *sigbuf = NULL;
  116. int siglen = 0;
  117. char *passargin = NULL, *passin = NULL;
  118. #ifndef OPENSSL_NO_ENGINE
  119. char *engine = NULL;
  120. #endif
  121. char *hmac_key = NULL;
  122. char *mac_name = NULL;
  123. int non_fips_allow = 0;
  124. STACK_OF(OPENSSL_STRING) *sigopts = NULL, *macopts = NULL;
  125. apps_startup();
  126. if ((buf = (unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL) {
  127. BIO_printf(bio_err, "out of memory\n");
  128. goto end;
  129. }
  130. if (bio_err == NULL)
  131. if ((bio_err = BIO_new(BIO_s_file())) != NULL)
  132. BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
  133. if (!load_config(bio_err, NULL))
  134. goto end;
  135. /* first check the program name */
  136. program_name(argv[0], pname, sizeof pname);
  137. md = EVP_get_digestbyname(pname);
  138. argc--;
  139. argv++;
  140. while (argc > 0) {
  141. if ((*argv)[0] != '-')
  142. break;
  143. if (strcmp(*argv, "-c") == 0)
  144. separator = 1;
  145. else if (strcmp(*argv, "-r") == 0)
  146. separator = 2;
  147. else if (strcmp(*argv, "-rand") == 0) {
  148. if (--argc < 1)
  149. break;
  150. randfile = *(++argv);
  151. } else if (strcmp(*argv, "-out") == 0) {
  152. if (--argc < 1)
  153. break;
  154. outfile = *(++argv);
  155. } else if (strcmp(*argv, "-sign") == 0) {
  156. if (--argc < 1)
  157. break;
  158. keyfile = *(++argv);
  159. } else if (!strcmp(*argv, "-passin")) {
  160. if (--argc < 1)
  161. break;
  162. passargin = *++argv;
  163. } else if (strcmp(*argv, "-verify") == 0) {
  164. if (--argc < 1)
  165. break;
  166. keyfile = *(++argv);
  167. want_pub = 1;
  168. do_verify = 1;
  169. } else if (strcmp(*argv, "-prverify") == 0) {
  170. if (--argc < 1)
  171. break;
  172. keyfile = *(++argv);
  173. do_verify = 1;
  174. } else if (strcmp(*argv, "-signature") == 0) {
  175. if (--argc < 1)
  176. break;
  177. sigfile = *(++argv);
  178. } else if (strcmp(*argv, "-keyform") == 0) {
  179. if (--argc < 1)
  180. break;
  181. keyform = str2fmt(*(++argv));
  182. }
  183. #ifndef OPENSSL_NO_ENGINE
  184. else if (strcmp(*argv, "-engine") == 0) {
  185. if (--argc < 1)
  186. break;
  187. engine = *(++argv);
  188. e = setup_engine(bio_err, engine, 0);
  189. }
  190. #endif
  191. else if (strcmp(*argv, "-hex") == 0)
  192. out_bin = 0;
  193. else if (strcmp(*argv, "-binary") == 0)
  194. out_bin = 1;
  195. else if (strcmp(*argv, "-d") == 0)
  196. debug = 1;
  197. else if (!strcmp(*argv, "-fips-fingerprint"))
  198. hmac_key = "etaonrishdlcupfm";
  199. else if (strcmp(*argv, "-non-fips-allow") == 0)
  200. non_fips_allow = 1;
  201. else if (!strcmp(*argv, "-hmac")) {
  202. if (--argc < 1)
  203. break;
  204. hmac_key = *++argv;
  205. } else if (!strcmp(*argv, "-mac")) {
  206. if (--argc < 1)
  207. break;
  208. mac_name = *++argv;
  209. } else if (strcmp(*argv, "-sigopt") == 0) {
  210. if (--argc < 1)
  211. break;
  212. if (!sigopts)
  213. sigopts = sk_OPENSSL_STRING_new_null();
  214. if (!sigopts || !sk_OPENSSL_STRING_push(sigopts, *(++argv)))
  215. break;
  216. } else if (strcmp(*argv, "-macopt") == 0) {
  217. if (--argc < 1)
  218. break;
  219. if (!macopts)
  220. macopts = sk_OPENSSL_STRING_new_null();
  221. if (!macopts || !sk_OPENSSL_STRING_push(macopts, *(++argv)))
  222. break;
  223. } else if ((m = EVP_get_digestbyname(&((*argv)[1]))) != NULL)
  224. md = m;
  225. else
  226. break;
  227. argc--;
  228. argv++;
  229. }
  230. if (do_verify && !sigfile) {
  231. BIO_printf(bio_err,
  232. "No signature to verify: use the -signature option\n");
  233. goto end;
  234. }
  235. if ((argc > 0) && (argv[0][0] == '-')) { /* bad option */
  236. BIO_printf(bio_err, "unknown option '%s'\n", *argv);
  237. BIO_printf(bio_err, "options are\n");
  238. BIO_printf(bio_err,
  239. "-c to output the digest with separating colons\n");
  240. BIO_printf(bio_err,
  241. "-r to output the digest in coreutils format\n");
  242. BIO_printf(bio_err, "-d to output debug info\n");
  243. BIO_printf(bio_err, "-hex output as hex dump\n");
  244. BIO_printf(bio_err, "-binary output in binary form\n");
  245. BIO_printf(bio_err, "-hmac arg set the HMAC key to arg\n");
  246. BIO_printf(bio_err, "-non-fips-allow allow use of non FIPS digest\n");
  247. BIO_printf(bio_err,
  248. "-sign file sign digest using private key in file\n");
  249. BIO_printf(bio_err,
  250. "-verify file verify a signature using public key in file\n");
  251. BIO_printf(bio_err,
  252. "-prverify file verify a signature using private key in file\n");
  253. BIO_printf(bio_err,
  254. "-keyform arg key file format (PEM or ENGINE)\n");
  255. BIO_printf(bio_err,
  256. "-out filename output to filename rather than stdout\n");
  257. BIO_printf(bio_err, "-signature file signature to verify\n");
  258. BIO_printf(bio_err, "-sigopt nm:v signature parameter\n");
  259. BIO_printf(bio_err, "-hmac key create hashed MAC with key\n");
  260. BIO_printf(bio_err,
  261. "-mac algorithm create MAC (not neccessarily HMAC)\n");
  262. BIO_printf(bio_err,
  263. "-macopt nm:v MAC algorithm parameters or key\n");
  264. #ifndef OPENSSL_NO_ENGINE
  265. BIO_printf(bio_err,
  266. "-engine e use engine e, possibly a hardware device.\n");
  267. #endif
  268. EVP_MD_do_all_sorted(list_md_fn, bio_err);
  269. goto end;
  270. }
  271. in = BIO_new(BIO_s_file());
  272. bmd = BIO_new(BIO_f_md());
  273. if ((in == NULL) || (bmd == NULL)) {
  274. ERR_print_errors(bio_err);
  275. goto end;
  276. }
  277. if (debug) {
  278. BIO_set_callback(in, BIO_debug_callback);
  279. /* needed for windows 3.1 */
  280. BIO_set_callback_arg(in, (char *)bio_err);
  281. }
  282. if (!app_passwd(bio_err, passargin, NULL, &passin, NULL)) {
  283. BIO_printf(bio_err, "Error getting password\n");
  284. goto end;
  285. }
  286. if (out_bin == -1) {
  287. if (keyfile)
  288. out_bin = 1;
  289. else
  290. out_bin = 0;
  291. }
  292. if (randfile)
  293. app_RAND_load_file(randfile, bio_err, 0);
  294. if (outfile) {
  295. if (out_bin)
  296. out = BIO_new_file(outfile, "wb");
  297. else
  298. out = BIO_new_file(outfile, "w");
  299. } else {
  300. out = BIO_new_fp(stdout, BIO_NOCLOSE);
  301. #ifdef OPENSSL_SYS_VMS
  302. {
  303. BIO *tmpbio = BIO_new(BIO_f_linebuffer());
  304. out = BIO_push(tmpbio, out);
  305. }
  306. #endif
  307. }
  308. if (!out) {
  309. BIO_printf(bio_err, "Error opening output file %s\n",
  310. outfile ? outfile : "(stdout)");
  311. ERR_print_errors(bio_err);
  312. goto end;
  313. }
  314. if ((! !mac_name + ! !keyfile + ! !hmac_key) > 1) {
  315. BIO_printf(bio_err, "MAC and Signing key cannot both be specified\n");
  316. goto end;
  317. }
  318. if (keyfile) {
  319. if (want_pub)
  320. sigkey = load_pubkey(bio_err, keyfile, keyform, 0, NULL,
  321. e, "key file");
  322. else
  323. sigkey = load_key(bio_err, keyfile, keyform, 0, passin,
  324. e, "key file");
  325. if (!sigkey) {
  326. /*
  327. * load_[pub]key() has already printed an appropriate message
  328. */
  329. goto end;
  330. }
  331. }
  332. if (mac_name) {
  333. EVP_PKEY_CTX *mac_ctx = NULL;
  334. int r = 0;
  335. if (!init_gen_str(bio_err, &mac_ctx, mac_name, e, 0))
  336. goto mac_end;
  337. if (macopts) {
  338. char *macopt;
  339. for (i = 0; i < sk_OPENSSL_STRING_num(macopts); i++) {
  340. macopt = sk_OPENSSL_STRING_value(macopts, i);
  341. if (pkey_ctrl_string(mac_ctx, macopt) <= 0) {
  342. BIO_printf(bio_err,
  343. "MAC parameter error \"%s\"\n", macopt);
  344. ERR_print_errors(bio_err);
  345. goto mac_end;
  346. }
  347. }
  348. }
  349. if (EVP_PKEY_keygen(mac_ctx, &sigkey) <= 0) {
  350. BIO_puts(bio_err, "Error generating key\n");
  351. ERR_print_errors(bio_err);
  352. goto mac_end;
  353. }
  354. r = 1;
  355. mac_end:
  356. if (mac_ctx)
  357. EVP_PKEY_CTX_free(mac_ctx);
  358. if (r == 0)
  359. goto end;
  360. }
  361. if (non_fips_allow) {
  362. EVP_MD_CTX *md_ctx;
  363. BIO_get_md_ctx(bmd, &md_ctx);
  364. EVP_MD_CTX_set_flags(md_ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
  365. }
  366. if (hmac_key) {
  367. sigkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, e,
  368. (unsigned char *)hmac_key, -1);
  369. if (!sigkey)
  370. goto end;
  371. }
  372. if (sigkey) {
  373. EVP_MD_CTX *mctx = NULL;
  374. EVP_PKEY_CTX *pctx = NULL;
  375. int r;
  376. if (!BIO_get_md_ctx(bmd, &mctx)) {
  377. BIO_printf(bio_err, "Error getting context\n");
  378. ERR_print_errors(bio_err);
  379. goto end;
  380. }
  381. if (do_verify)
  382. r = EVP_DigestVerifyInit(mctx, &pctx, md, NULL, sigkey);
  383. else
  384. r = EVP_DigestSignInit(mctx, &pctx, md, NULL, sigkey);
  385. if (!r) {
  386. BIO_printf(bio_err, "Error setting context\n");
  387. ERR_print_errors(bio_err);
  388. goto end;
  389. }
  390. if (sigopts) {
  391. char *sigopt;
  392. for (i = 0; i < sk_OPENSSL_STRING_num(sigopts); i++) {
  393. sigopt = sk_OPENSSL_STRING_value(sigopts, i);
  394. if (pkey_ctrl_string(pctx, sigopt) <= 0) {
  395. BIO_printf(bio_err, "parameter error \"%s\"\n", sigopt);
  396. ERR_print_errors(bio_err);
  397. goto end;
  398. }
  399. }
  400. }
  401. }
  402. /* we use md as a filter, reading from 'in' */
  403. else {
  404. if (md == NULL)
  405. md = EVP_md5();
  406. if (!BIO_set_md(bmd, md)) {
  407. BIO_printf(bio_err, "Error setting digest %s\n", pname);
  408. ERR_print_errors(bio_err);
  409. goto end;
  410. }
  411. }
  412. if (sigfile && sigkey) {
  413. BIO *sigbio;
  414. sigbio = BIO_new_file(sigfile, "rb");
  415. siglen = EVP_PKEY_size(sigkey);
  416. sigbuf = OPENSSL_malloc(siglen);
  417. if (!sigbio) {
  418. BIO_printf(bio_err, "Error opening signature file %s\n", sigfile);
  419. ERR_print_errors(bio_err);
  420. goto end;
  421. }
  422. if (!sigbuf) {
  423. BIO_printf(bio_err, "Out of memory\n");
  424. ERR_print_errors(bio_err);
  425. goto end;
  426. }
  427. siglen = BIO_read(sigbio, sigbuf, siglen);
  428. BIO_free(sigbio);
  429. if (siglen <= 0) {
  430. BIO_printf(bio_err, "Error reading signature file %s\n", sigfile);
  431. ERR_print_errors(bio_err);
  432. goto end;
  433. }
  434. }
  435. inp = BIO_push(bmd, in);
  436. if (md == NULL) {
  437. EVP_MD_CTX *tctx;
  438. BIO_get_md_ctx(bmd, &tctx);
  439. md = EVP_MD_CTX_md(tctx);
  440. }
  441. if (argc == 0) {
  442. BIO_set_fp(in, stdin, BIO_NOCLOSE);
  443. err = do_fp(out, buf, inp, separator, out_bin, sigkey, sigbuf,
  444. siglen, NULL, NULL, "stdin", bmd);
  445. } else {
  446. const char *md_name = NULL, *sig_name = NULL;
  447. if (!out_bin) {
  448. if (sigkey) {
  449. const EVP_PKEY_ASN1_METHOD *ameth;
  450. ameth = EVP_PKEY_get0_asn1(sigkey);
  451. if (ameth)
  452. EVP_PKEY_asn1_get0_info(NULL, NULL,
  453. NULL, NULL, &sig_name, ameth);
  454. }
  455. md_name = EVP_MD_name(md);
  456. }
  457. err = 0;
  458. for (i = 0; i < argc; i++) {
  459. int r;
  460. if (BIO_read_filename(in, argv[i]) <= 0) {
  461. perror(argv[i]);
  462. err++;
  463. continue;
  464. } else
  465. r = do_fp(out, buf, inp, separator, out_bin, sigkey, sigbuf,
  466. siglen, sig_name, md_name, argv[i], bmd);
  467. if (r)
  468. err = r;
  469. (void)BIO_reset(bmd);
  470. }
  471. }
  472. end:
  473. if (buf != NULL) {
  474. OPENSSL_cleanse(buf, BUFSIZE);
  475. OPENSSL_free(buf);
  476. }
  477. if (in != NULL)
  478. BIO_free(in);
  479. if (passin)
  480. OPENSSL_free(passin);
  481. BIO_free_all(out);
  482. EVP_PKEY_free(sigkey);
  483. if (sigopts)
  484. sk_OPENSSL_STRING_free(sigopts);
  485. if (macopts)
  486. sk_OPENSSL_STRING_free(macopts);
  487. if (sigbuf)
  488. OPENSSL_free(sigbuf);
  489. if (bmd != NULL)
  490. BIO_free(bmd);
  491. apps_shutdown();
  492. OPENSSL_EXIT(err);
  493. }
  494. int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
  495. EVP_PKEY *key, unsigned char *sigin, int siglen,
  496. const char *sig_name, const char *md_name,
  497. const char *file, BIO *bmd)
  498. {
  499. size_t len;
  500. int i;
  501. for (;;) {
  502. i = BIO_read(bp, (char *)buf, BUFSIZE);
  503. if (i < 0) {
  504. BIO_printf(bio_err, "Read Error in %s\n", file);
  505. ERR_print_errors(bio_err);
  506. return 1;
  507. }
  508. if (i == 0)
  509. break;
  510. }
  511. if (sigin) {
  512. EVP_MD_CTX *ctx;
  513. BIO_get_md_ctx(bp, &ctx);
  514. i = EVP_DigestVerifyFinal(ctx, sigin, (unsigned int)siglen);
  515. if (i > 0)
  516. BIO_printf(out, "Verified OK\n");
  517. else if (i == 0) {
  518. BIO_printf(out, "Verification Failure\n");
  519. return 1;
  520. } else {
  521. BIO_printf(bio_err, "Error Verifying Data\n");
  522. ERR_print_errors(bio_err);
  523. return 1;
  524. }
  525. return 0;
  526. }
  527. if (key) {
  528. EVP_MD_CTX *ctx;
  529. BIO_get_md_ctx(bp, &ctx);
  530. len = BUFSIZE;
  531. if (!EVP_DigestSignFinal(ctx, buf, &len)) {
  532. BIO_printf(bio_err, "Error Signing Data\n");
  533. ERR_print_errors(bio_err);
  534. return 1;
  535. }
  536. } else {
  537. len = BIO_gets(bp, (char *)buf, BUFSIZE);
  538. if ((int)len < 0) {
  539. ERR_print_errors(bio_err);
  540. return 1;
  541. }
  542. }
  543. if (binout)
  544. BIO_write(out, buf, len);
  545. else if (sep == 2) {
  546. for (i = 0; i < (int)len; i++)
  547. BIO_printf(out, "%02x", buf[i]);
  548. BIO_printf(out, " *%s\n", file);
  549. } else {
  550. if (sig_name)
  551. BIO_printf(out, "%s-%s(%s)= ", sig_name, md_name, file);
  552. else if (md_name)
  553. BIO_printf(out, "%s(%s)= ", md_name, file);
  554. else
  555. BIO_printf(out, "(%s)= ", file);
  556. for (i = 0; i < (int)len; i++) {
  557. if (sep && (i != 0))
  558. BIO_printf(out, ":");
  559. BIO_printf(out, "%02x", buf[i]);
  560. }
  561. BIO_printf(out, "\n");
  562. }
  563. return 0;
  564. }