-/* $OpenBSD: mac.c,v 1.12 2006/08/03 03:34:42 deraadt Exp $ */
/*
* Copyright (c) 2001 Markus Friedl. All rights reserved.
*
*/
#include "includes.h"
-
-#include <sys/types.h>
+RCSID("$OpenBSD: mac.c,v 1.2 2001/04/05 10:42:51 markus Exp $");
#include <openssl/hmac.h>
-#include <stdarg.h>
-#include <string.h>
-#include <signal.h>
-
#include "xmalloc.h"
+#include "getput.h"
#include "log.h"
#include "cipher.h"
-#include "buffer.h"
-#include "key.h"
#include "kex.h"
#include "mac.h"
-#include "misc.h"
struct {
char *name;
- const EVP_MD * (*mdfunc)(void);
+ EVP_MD * (*mdfunc)(void);
int truncatebits; /* truncate digest if != 0 */
} macs[] = {
{ "hmac-sha1", EVP_sha1, 0, },
int
mac_init(Mac *mac, char *name)
{
- int i, evp_len;
-
+ int i;
for (i = 0; macs[i].name; i++) {
if (strcmp(name, macs[i].name) == 0) {
if (mac != NULL) {
mac->md = (*macs[i].mdfunc)();
- 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;
+ mac->key_len = mac->mac_len = mac->md->md_size;
if (macs[i].truncatebits != 0)
mac->mac_len = macs[i].truncatebits/8;
}
if (mac->mac_len > sizeof(m))
fatal("mac_compute: mac too long");
HMAC_Init(&c, mac->key, mac->key_len, mac->md);
- put_u32(b, seqno);
+ PUT_32BIT(b, seqno);
HMAC_Update(&c, b, sizeof(b));
HMAC_Update(&c, data, datalen);
HMAC_Final(&c, m, NULL);
return (0);
maclist = cp = xstrdup(names);
for ((p = strsep(&cp, MAC_SEP)); p && *p != '\0';
- (p = strsep(&cp, MAC_SEP))) {
+ (p = strsep(&cp, MAC_SEP))) {
if (mac_init(NULL, p) < 0) {
debug("bad mac %s [%s]", p, names);
xfree(maclist);