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