Rich Salz | 440e5d8 | 2016-05-17 14:20:24 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 3 | * |
Rich Salz | 440e5d8 | 2016-05-17 14:20:24 -0400 | [diff] [blame] | 4 | * Licensed under the OpenSSL license (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 |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | #include <string.h> |
| 12 | #include <stdlib.h> |
Ulf Möller | f5d7a03 | 1999-04-27 01:14:46 +0000 | [diff] [blame] | 13 | |
Richard Levitte | 55f78ba | 2002-11-28 18:54:30 +0000 | [diff] [blame] | 14 | #include "../e_os.h" |
| 15 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 16 | # include <openssl/hmac.h> |
Emilia Kasper | b1413d9 | 2015-09-10 15:17:58 +0200 | [diff] [blame] | 17 | # include <openssl/sha.h> |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 18 | # ifndef OPENSSL_NO_MD5 |
| 19 | # include <openssl/md5.h> |
| 20 | # endif |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 21 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 22 | # ifdef CHARSET_EBCDIC |
| 23 | # include <openssl/ebcdic.h> |
| 24 | # endif |
Ulf Möller | a53955d | 1999-06-04 21:35:58 +0000 | [diff] [blame] | 25 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 26 | # ifndef OPENSSL_NO_MD5 |
| 27 | static struct test_st { |
| 28 | unsigned char key[16]; |
| 29 | int key_len; |
| 30 | unsigned char data[64]; |
| 31 | int data_len; |
| 32 | unsigned char *digest; |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 33 | } test[8] = { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 34 | { |
| 35 | "", 0, "More text test vectors to stuff up EBCDIC machines :-)", 54, |
| 36 | (unsigned char *)"e9139d1e6ee064ef8cf514fc7dc83e86", |
| 37 | }, |
| 38 | { |
| 39 | { |
| 40 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, |
| 41 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, |
| 42 | }, 16, "Hi There", 8, |
| 43 | (unsigned char *)"9294727a3638bb1c13f48ef8158bfc9d", |
| 44 | }, |
| 45 | { |
| 46 | "Jefe", 4, "what do ya want for nothing?", 28, |
| 47 | (unsigned char *)"750c783e6ab0b503eaa86e310a5db738", |
| 48 | }, |
| 49 | { |
| 50 | { |
| 51 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
| 52 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
| 53 | }, 16, { |
| 54 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, |
| 55 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, |
| 56 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, |
| 57 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, |
| 58 | 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd |
| 59 | }, 50, (unsigned char *)"56be34521d144c88dbb8c733f0e8b3f6", |
| 60 | }, |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 61 | { |
| 62 | "", 0, "My test data", 12, |
| 63 | (unsigned char *)"61afdecb95429ef494d61fdee15990cabf0826fc" |
| 64 | }, |
| 65 | { |
| 66 | "", 0, "My test data", 12, |
| 67 | (unsigned char *)"2274b195d90ce8e03406f4b526a47e0787a88a65479938f1a5baa3ce0f079776" |
| 68 | }, |
| 69 | { |
| 70 | "123456", 6, "My test data", 12, |
| 71 | (unsigned char *)"bab53058ae861a7f191abe2d0145cbb123776a6369ee3f9d79ce455667e411dd" |
| 72 | }, |
| 73 | { |
Kurt Cancemi | 8a3c000 | 2016-06-29 07:03:28 -0400 | [diff] [blame] | 74 | "12345", 5, "My test data again", 18, |
| 75 | (unsigned char *)"a12396ceddd2a85f4c656bc1e0aa50c78cffde3e" |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 76 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 77 | }; |
| 78 | # endif |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 79 | |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 80 | static char *pt(unsigned char *md, unsigned int len); |
| 81 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 82 | int main(int argc, char *argv[]) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 83 | { |
| 84 | # ifndef OPENSSL_NO_MD5 |
| 85 | int i; |
| 86 | char *p; |
| 87 | # endif |
| 88 | int err = 0; |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 89 | HMAC_CTX *ctx = NULL, *ctx2 = NULL; |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 90 | unsigned char buf[EVP_MAX_MD_SIZE]; |
| 91 | unsigned int len; |
Richard Levitte | 8cbcced | 2002-12-05 01:55:48 +0000 | [diff] [blame] | 92 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 93 | # ifdef OPENSSL_NO_MD5 |
| 94 | printf("test skipped: MD5 disabled\n"); |
| 95 | # else |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 96 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 97 | # ifdef CHARSET_EBCDIC |
| 98 | ebcdic2ascii(test[0].data, test[0].data, test[0].data_len); |
| 99 | ebcdic2ascii(test[1].data, test[1].data, test[1].data_len); |
| 100 | ebcdic2ascii(test[2].key, test[2].key, test[2].key_len); |
| 101 | ebcdic2ascii(test[2].data, test[2].data, test[2].data_len); |
| 102 | # endif |
Ulf Möller | a53955d | 1999-06-04 21:35:58 +0000 | [diff] [blame] | 103 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 104 | for (i = 0; i < 4; i++) { |
| 105 | p = pt(HMAC(EVP_md5(), |
| 106 | test[i].key, test[i].key_len, |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 107 | test[i].data, test[i].data_len, NULL, NULL), |
| 108 | MD5_DIGEST_LENGTH); |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 109 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 110 | if (strcmp(p, (char *)test[i].digest) != 0) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 111 | printf("Error calculating HMAC on %d entry'\n", i); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 112 | printf("got %s instead of %s\n", p, test[i].digest); |
| 113 | err++; |
| 114 | } else |
| 115 | printf("test %d ok\n", i); |
| 116 | } |
| 117 | # endif /* OPENSSL_NO_MD5 */ |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 118 | |
| 119 | /* test4 */ |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 120 | ctx = HMAC_CTX_new(); |
| 121 | if (ctx == NULL) { |
| 122 | printf("HMAC malloc failure (test 4)\n"); |
| 123 | err++; |
| 124 | goto end; |
| 125 | } |
Matt Caswell | a621181 | 2016-06-20 09:08:10 +0100 | [diff] [blame] | 126 | if (HMAC_CTX_get_md(ctx) != NULL) { |
| 127 | printf("Message digest not NULL for HMAC (test 4)\n"); |
| 128 | err++; |
| 129 | goto test5; |
| 130 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 131 | if (HMAC_Init_ex(ctx, NULL, 0, NULL, NULL)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 132 | printf("Should fail to initialise HMAC with empty MD and key (test 4)\n"); |
| 133 | err++; |
| 134 | goto test5; |
| 135 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 136 | if (HMAC_Update(ctx, test[4].data, test[4].data_len)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 137 | printf("Should fail HMAC_Update with ctx not set up (test 4)\n"); |
| 138 | err++; |
| 139 | goto test5; |
| 140 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 141 | if (HMAC_Init_ex(ctx, NULL, 0, EVP_sha1(), NULL)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 142 | printf("Should fail to initialise HMAC with empty key (test 4)\n"); |
| 143 | err++; |
| 144 | goto test5; |
| 145 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 146 | if (HMAC_Update(ctx, test[4].data, test[4].data_len)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 147 | printf("Should fail HMAC_Update with ctx not set up (test 4)\n"); |
| 148 | err++; |
| 149 | goto test5; |
| 150 | } |
| 151 | printf("test 4 ok\n"); |
| 152 | test5: |
Emilia Kasper | b1413d9 | 2015-09-10 15:17:58 +0200 | [diff] [blame] | 153 | /* Test 5 has empty key; test that single-shot accepts a NULL key. */ |
| 154 | p = pt(HMAC(EVP_sha1(), NULL, 0, test[4].data, test[4].data_len, |
| 155 | NULL, NULL), SHA_DIGEST_LENGTH); |
| 156 | if (strcmp(p, (char *)test[4].digest) != 0) { |
| 157 | printf("Error calculating HMAC on %d entry'\n", i); |
| 158 | printf("got %s instead of %s\n", p, test[4].digest); |
| 159 | err++; |
| 160 | } |
| 161 | |
Richard Levitte | a87a0a6 | 2015-12-02 22:49:24 +0100 | [diff] [blame] | 162 | HMAC_CTX_reset(ctx); |
Matt Caswell | a621181 | 2016-06-20 09:08:10 +0100 | [diff] [blame] | 163 | if (HMAC_CTX_get_md(ctx) != NULL) { |
| 164 | printf("Message digest not NULL for HMAC (test 5)\n"); |
| 165 | err++; |
| 166 | goto test6; |
| 167 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 168 | if (HMAC_Init_ex(ctx, test[4].key, test[4].key_len, NULL, NULL)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 169 | printf("Should fail to initialise HMAC with empty MD (test 5)\n"); |
| 170 | err++; |
| 171 | goto test6; |
| 172 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 173 | if (HMAC_Update(ctx, test[4].data, test[4].data_len)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 174 | printf("Should fail HMAC_Update with ctx not set up (test 5)\n"); |
| 175 | err++; |
| 176 | goto test6; |
| 177 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 178 | if (HMAC_Init_ex(ctx, test[4].key, -1, EVP_sha1(), NULL)) { |
Matt Caswell | b352160 | 2015-02-10 13:15:05 +0000 | [diff] [blame] | 179 | printf("Should fail to initialise HMAC with invalid key len(test 5)\n"); |
| 180 | err++; |
| 181 | goto test6; |
| 182 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 183 | if (!HMAC_Init_ex(ctx, test[4].key, test[4].key_len, EVP_sha1(), NULL)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 184 | printf("Failed to initialise HMAC (test 5)\n"); |
| 185 | err++; |
| 186 | goto test6; |
| 187 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 188 | if (!HMAC_Update(ctx, test[4].data, test[4].data_len)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 189 | printf("Error updating HMAC with data (test 5)\n"); |
| 190 | err++; |
| 191 | goto test6; |
| 192 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 193 | if (!HMAC_Final(ctx, buf, &len)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 194 | printf("Error finalising data (test 5)\n"); |
| 195 | err++; |
| 196 | goto test6; |
| 197 | } |
| 198 | p = pt(buf, len); |
| 199 | if (strcmp(p, (char *)test[4].digest) != 0) { |
| 200 | printf("Error calculating interim HMAC on test 5\n"); |
| 201 | printf("got %s instead of %s\n", p, test[4].digest); |
| 202 | err++; |
| 203 | goto test6; |
| 204 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 205 | if (HMAC_Init_ex(ctx, NULL, 0, EVP_sha256(), NULL)) { |
Matt Caswell | 4b464e7 | 2015-06-12 13:08:04 +0100 | [diff] [blame] | 206 | printf("Should disallow changing MD without a new key (test 5)\n"); |
| 207 | err++; |
| 208 | goto test6; |
| 209 | } |
Emilia Kasper | b1413d9 | 2015-09-10 15:17:58 +0200 | [diff] [blame] | 210 | if (!HMAC_Init_ex(ctx, test[5].key, test[5].key_len, EVP_sha256(), NULL)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 211 | printf("Failed to reinitialise HMAC (test 5)\n"); |
| 212 | err++; |
| 213 | goto test6; |
| 214 | } |
Matt Caswell | a621181 | 2016-06-20 09:08:10 +0100 | [diff] [blame] | 215 | if (HMAC_CTX_get_md(ctx) != EVP_sha256()) { |
| 216 | printf("Unexpected message digest for HMAC (test 5)\n"); |
| 217 | err++; |
| 218 | goto test6; |
| 219 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 220 | if (!HMAC_Update(ctx, test[5].data, test[5].data_len)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 221 | printf("Error updating HMAC with data (sha256) (test 5)\n"); |
| 222 | err++; |
| 223 | goto test6; |
| 224 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 225 | if (!HMAC_Final(ctx, buf, &len)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 226 | printf("Error finalising data (sha256) (test 5)\n"); |
| 227 | err++; |
| 228 | goto test6; |
| 229 | } |
| 230 | p = pt(buf, len); |
| 231 | if (strcmp(p, (char *)test[5].digest) != 0) { |
| 232 | printf("Error calculating 2nd interim HMAC on test 5\n"); |
| 233 | printf("got %s instead of %s\n", p, test[5].digest); |
| 234 | err++; |
| 235 | goto test6; |
| 236 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 237 | if (!HMAC_Init_ex(ctx, test[6].key, test[6].key_len, NULL, NULL)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 238 | printf("Failed to reinitialise HMAC with key (test 5)\n"); |
| 239 | err++; |
| 240 | goto test6; |
| 241 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 242 | if (!HMAC_Update(ctx, test[6].data, test[6].data_len)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 243 | printf("Error updating HMAC with data (new key) (test 5)\n"); |
| 244 | err++; |
| 245 | goto test6; |
| 246 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 247 | if (!HMAC_Final(ctx, buf, &len)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 248 | printf("Error finalising data (new key) (test 5)\n"); |
| 249 | err++; |
| 250 | goto test6; |
| 251 | } |
| 252 | p = pt(buf, len); |
| 253 | if (strcmp(p, (char *)test[6].digest) != 0) { |
| 254 | printf("error calculating HMAC on test 5\n"); |
| 255 | printf("got %s instead of %s\n", p, test[6].digest); |
| 256 | err++; |
| 257 | } else { |
| 258 | printf("test 5 ok\n"); |
| 259 | } |
| 260 | test6: |
Richard Levitte | a87a0a6 | 2015-12-02 22:49:24 +0100 | [diff] [blame] | 261 | HMAC_CTX_reset(ctx); |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 262 | ctx2 = HMAC_CTX_new(); |
| 263 | if (ctx2 == NULL) { |
| 264 | printf("HMAC malloc failure (test 6)\n"); |
| 265 | err++; |
| 266 | goto end; |
| 267 | } |
| 268 | if (!HMAC_Init_ex(ctx, test[7].key, test[7].key_len, EVP_sha1(), NULL)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 269 | printf("Failed to initialise HMAC (test 6)\n"); |
| 270 | err++; |
| 271 | goto end; |
| 272 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 273 | if (!HMAC_Update(ctx, test[7].data, test[7].data_len)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 274 | printf("Error updating HMAC with data (test 6)\n"); |
| 275 | err++; |
| 276 | goto end; |
| 277 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 278 | if (!HMAC_CTX_copy(ctx2, ctx)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 279 | printf("Failed to copy HMAC_CTX (test 6)\n"); |
| 280 | err++; |
| 281 | goto end; |
| 282 | } |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 283 | if (!HMAC_Final(ctx2, buf, &len)) { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 284 | printf("Error finalising data (test 6)\n"); |
| 285 | err++; |
| 286 | goto end; |
| 287 | } |
| 288 | p = pt(buf, len); |
| 289 | if (strcmp(p, (char *)test[7].digest) != 0) { |
| 290 | printf("Error calculating HMAC on test 6\n"); |
| 291 | printf("got %s instead of %s\n", p, test[7].digest); |
| 292 | err++; |
| 293 | } else { |
| 294 | printf("test 6 ok\n"); |
| 295 | } |
| 296 | end: |
Richard Levitte | bf7c681 | 2015-11-30 13:44:28 +0100 | [diff] [blame] | 297 | HMAC_CTX_free(ctx2); |
| 298 | HMAC_CTX_free(ctx); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 299 | EXIT(err); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 300 | } |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 301 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 302 | # ifndef OPENSSL_NO_MD5 |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 303 | static char *pt(unsigned char *md, unsigned int len) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 304 | { |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 305 | unsigned int i; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 306 | static char buf[80]; |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 307 | |
Matt Caswell | 2cfbdd7 | 2015-02-10 12:38:04 +0000 | [diff] [blame] | 308 | for (i = 0; i < len; i++) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 309 | sprintf(&(buf[i * 2]), "%02x", md[i]); |
| 310 | return (buf); |
| 311 | } |
| 312 | # endif |