Lines Matching refs:mac

1 /* $OpenBSD: mac.c,v 1.32 2015/01/15 18:32:54 naddy Exp $ */
36 #include "mac.h"
114 mac_setup_by_alg(struct sshmac *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;
133 mac_setup(struct sshmac *mac, char *name)
140 if (mac != NULL)
141 return mac_setup_by_alg(mac, m);
148 mac_init(struct sshmac *mac)
150 if (mac->key == NULL)
152 switch (mac->type) {
154 if (mac->hmac_ctx == NULL ||
155 ssh_hmac_init(mac->hmac_ctx, mac->key, mac->key_len) < 0)
159 if ((mac->umac_ctx = umac_new(mac->key)) == NULL)
163 if ((mac->umac_ctx = umac128_new(mac->key)) == NULL)
172 mac_compute(struct sshmac *mac, u_int32_t seqno, const u_char *data, int datalen,
182 if (mac->mac_len > sizeof(u))
185 switch (mac->type) {
189 if (ssh_hmac_init(mac->hmac_ctx, NULL, 0) < 0 ||
190 ssh_hmac_update(mac->hmac_ctx, b, sizeof(b)) < 0 ||
191 ssh_hmac_update(mac->hmac_ctx, data, datalen) < 0 ||
192 ssh_hmac_final(mac->hmac_ctx, u.m, sizeof(u.m)) < 0)
197 umac_update(mac->umac_ctx, data, datalen);
198 umac_final(mac->umac_ctx, u.m, nonce);
202 umac128_update(mac->umac_ctx, data, datalen);
203 umac128_final(mac->umac_ctx, u.m, nonce);
209 if (dlen > mac->mac_len)
210 dlen = mac->mac_len;
217 mac_clear(struct sshmac *mac)
219 if (mac->type == SSH_UMAC) {
220 if (mac->umac_ctx != NULL)
221 umac_delete(mac->umac_ctx);
222 } else if (mac->type == SSH_UMAC128) {
223 if (mac->umac_ctx != NULL)
224 umac128_delete(mac->umac_ctx);
225 } else if (mac->hmac_ctx != NULL)
226 ssh_hmac_free(mac->hmac_ctx);
227 mac->hmac_ctx = NULL;
228 mac->umac_ctx = NULL;