Lines Matching refs:mac

1 /* $OpenBSD: mac.c,v 1.35 2019/09/06 04:53:27 djm Exp $ */
37 #include "mac.h"
106 mac_setup_by_alg(struct sshmac *mac, const struct macalg *macalg)
108 mac->type = macalg->type;
109 if (mac->type == SSH_DIGEST) {
110 if ((mac->hmac_ctx = ssh_hmac_start(macalg->alg)) == NULL)
112 mac->key_len = mac->mac_len = ssh_hmac_bytes(macalg->alg);
114 mac->mac_len = macalg->len / 8;
115 mac->key_len = macalg->key_len / 8;
116 mac->umac_ctx = NULL;
119 mac->mac_len = macalg->truncatebits / 8;
120 mac->etm = macalg->etm;
125 mac_setup(struct sshmac *mac, char *name)
132 if (mac != NULL)
133 return mac_setup_by_alg(mac, m);
140 mac_init(struct sshmac *mac)
142 if (mac->key == NULL)
144 switch (mac->type) {
146 if (mac->hmac_ctx == NULL ||
147 ssh_hmac_init(mac->hmac_ctx, mac->key, mac->key_len) < 0)
151 if ((mac->umac_ctx = umac_new(mac->key)) == NULL)
155 if ((mac->umac_ctx = umac128_new(mac->key)) == NULL)
164 mac_compute(struct sshmac *mac, u_int32_t seqno,
175 if (mac->mac_len > sizeof(u))
178 switch (mac->type) {
182 if (ssh_hmac_init(mac->hmac_ctx, NULL, 0) < 0 ||
183 ssh_hmac_update(mac->hmac_ctx, b, sizeof(b)) < 0 ||
184 ssh_hmac_update(mac->hmac_ctx, data, datalen) < 0 ||
185 ssh_hmac_final(mac->hmac_ctx, u.m, sizeof(u.m)) < 0)
190 umac_update(mac->umac_ctx, data, datalen);
191 umac_final(mac->umac_ctx, u.m, nonce);
195 umac128_update(mac->umac_ctx, data, datalen);
196 umac128_final(mac->umac_ctx, u.m, nonce);
202 if (dlen > mac->mac_len)
203 dlen = mac->mac_len;
210 mac_check(struct sshmac *mac, u_int32_t seqno,
217 if (mac->mac_len > mlen)
219 if ((r = mac_compute(mac, seqno, data, dlen,
222 if (timingsafe_bcmp(ourmac, theirmac, mac->mac_len) != 0)
228 mac_clear(struct sshmac *mac)
230 if (mac->type == SSH_UMAC) {
231 if (mac->umac_ctx != NULL)
232 umac_delete(mac->umac_ctx);
233 } else if (mac->type == SSH_UMAC128) {
234 if (mac->umac_ctx != NULL)
235 umac128_delete(mac->umac_ctx);
236 } else if (mac->hmac_ctx != NULL)
237 ssh_hmac_free(mac->hmac_ctx);
238 mac->hmac_ctx = NULL;
239 mac->umac_ctx = NULL;