diff options
Diffstat (limited to 'mac.c')
-rw-r--r-- | mac.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -23,7 +23,7 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | RCSID("$OpenBSD: mac.c,v 1.6 2003/09/18 13:02:21 miod Exp $"); | 26 | RCSID("$OpenBSD: mac.c,v 1.7 2005/06/17 02:44:32 djm Exp $"); |
27 | 27 | ||
28 | #include <openssl/hmac.h> | 28 | #include <openssl/hmac.h> |
29 | 29 | ||
@@ -51,12 +51,15 @@ struct { | |||
51 | int | 51 | int |
52 | mac_init(Mac *mac, char *name) | 52 | mac_init(Mac *mac, char *name) |
53 | { | 53 | { |
54 | int i; | 54 | int i, evp_len; |
55 | |||
55 | for (i = 0; macs[i].name; i++) { | 56 | for (i = 0; macs[i].name; i++) { |
56 | if (strcmp(name, macs[i].name) == 0) { | 57 | if (strcmp(name, macs[i].name) == 0) { |
57 | if (mac != NULL) { | 58 | if (mac != NULL) { |
58 | mac->md = (*macs[i].mdfunc)(); | 59 | mac->md = (*macs[i].mdfunc)(); |
59 | mac->key_len = mac->mac_len = EVP_MD_size(mac->md); | 60 | if ((evp_len = EVP_MD_size(mac->md)) <= 0) |
61 | fatal("mac %s len %d", name, evp_len); | ||
62 | mac->key_len = mac->mac_len = (u_int)evp_len; | ||
60 | if (macs[i].truncatebits != 0) | 63 | if (macs[i].truncatebits != 0) |
61 | mac->mac_len = macs[i].truncatebits/8; | 64 | mac->mac_len = macs[i].truncatebits/8; |
62 | } | 65 | } |
@@ -77,7 +80,7 @@ mac_compute(Mac *mac, u_int32_t seqno, u_char *data, int datalen) | |||
77 | 80 | ||
78 | if (mac->key == NULL) | 81 | if (mac->key == NULL) |
79 | fatal("mac_compute: no key"); | 82 | fatal("mac_compute: no key"); |
80 | if ((u_int)mac->mac_len > sizeof(m)) | 83 | if (mac->mac_len > sizeof(m)) |
81 | fatal("mac_compute: mac too long"); | 84 | fatal("mac_compute: mac too long"); |
82 | HMAC_Init(&c, mac->key, mac->key_len, mac->md); | 85 | HMAC_Init(&c, mac->key, mac->key_len, mac->md); |
83 | PUT_32BIT(b, seqno); | 86 | PUT_32BIT(b, seqno); |