version 1.6, 2003/09/18 13:02:21 |
version 1.6.6.1, 2005/09/04 18:40:02 |
|
|
int |
int |
mac_init(Mac *mac, char *name) |
mac_init(Mac *mac, char *name) |
{ |
{ |
int i; |
int i, evp_len; |
|
|
for (i = 0; macs[i].name; i++) { |
for (i = 0; macs[i].name; i++) { |
if (strcmp(name, macs[i].name) == 0) { |
if (strcmp(name, macs[i].name) == 0) { |
if (mac != NULL) { |
if (mac != NULL) { |
mac->md = (*macs[i].mdfunc)(); |
mac->md = (*macs[i].mdfunc)(); |
mac->key_len = mac->mac_len = EVP_MD_size(mac->md); |
if ((evp_len = EVP_MD_size(mac->md)) <= 0) |
|
fatal("mac %s len %d", name, evp_len); |
|
mac->key_len = mac->mac_len = (u_int)evp_len; |
if (macs[i].truncatebits != 0) |
if (macs[i].truncatebits != 0) |
mac->mac_len = macs[i].truncatebits/8; |
mac->mac_len = macs[i].truncatebits/8; |
} |
} |
|
|
|
|
if (mac->key == NULL) |
if (mac->key == NULL) |
fatal("mac_compute: no key"); |
fatal("mac_compute: no key"); |
if ((u_int)mac->mac_len > sizeof(m)) |
if (mac->mac_len > sizeof(m)) |
fatal("mac_compute: mac too long"); |
fatal("mac_compute: mac too long"); |
HMAC_Init(&c, mac->key, mac->key_len, mac->md); |
HMAC_Init(&c, mac->key, mac->key_len, mac->md); |
PUT_32BIT(b, seqno); |
PUT_32BIT(b, seqno); |