Lines Matching refs:mac

1 /* $OpenBSD: mac.c,v 1.28 2014/02/07 06:55:54 djm Exp $ */
40 #include "mac.h"
114 mac_setup_by_alg(Mac *mac, const struct macalg *macalg)
116 mac->type = macalg->type;
117 if (mac->type == SSH_DIGEST) {
118 if ((mac->hmac_ctx = ssh_hmac_start(macalg->alg)) == NULL)
120 mac->key_len = mac->mac_len = ssh_hmac_bytes(macalg->alg);
122 mac->mac_len = macalg->len / 8;
123 mac->key_len = macalg->key_len / 8;
124 mac->umac_ctx = NULL;
127 mac->mac_len = macalg->truncatebits / 8;
128 mac->etm = macalg->etm;
132 mac_setup(Mac *mac, char *name)
139 if (mac != NULL) {
140 mac_setup_by_alg(mac, m);
150 mac_init(Mac *mac)
152 if (mac->key == NULL)
154 switch (mac->type) {
156 if (mac->hmac_ctx == NULL ||
157 ssh_hmac_init(mac->hmac_ctx, mac->key, mac->key_len) < 0)
161 mac->umac_ctx = umac_new(mac->key);
164 mac->umac_ctx = umac128_new(mac->key);
172 mac_compute(Mac *mac, u_int32_t seqno, u_char *data, int datalen)
180 if (mac->mac_len > sizeof(u))
181 fatal("mac_compute: mac too long %u %zu",
182 mac->mac_len, sizeof(u));
184 switch (mac->type) {
188 if (ssh_hmac_init(mac->hmac_ctx, NULL, 0) < 0 ||
189 ssh_hmac_update(mac->hmac_ctx, b, sizeof(b)) < 0 ||
190 ssh_hmac_update(mac->hmac_ctx, data, datalen) < 0 ||
191 ssh_hmac_final(mac->hmac_ctx, u.m, sizeof(u.m)) < 0)
196 umac_update(mac->umac_ctx, data, datalen);
197 umac_final(mac->umac_ctx, u.m, nonce);
201 umac128_update(mac->umac_ctx, data, datalen);
202 umac128_final(mac->umac_ctx, u.m, nonce);
211 mac_clear(Mac *mac)
213 if (mac->type == SSH_UMAC) {
214 if (mac->umac_ctx != NULL)
215 umac_delete(mac->umac_ctx);
216 } else if (mac->type == SSH_UMAC128) {
217 if (mac->umac_ctx != NULL)
218 umac128_delete(mac->umac_ctx);
219 } else if (mac->hmac_ctx != NULL)
220 ssh_hmac_free(mac->hmac_ctx);
221 mac->hmac_ctx = NULL;
222 mac->umac_ctx = NULL;
238 debug("bad mac %s [%s]", p, names);