Lines Matching refs:mac
114 mac_setup_by_alg(struct sshmac *mac, const struct macalg *macalg) in mac_setup_by_alg() argument
116 mac->type = macalg->type; in mac_setup_by_alg()
117 if (mac->type == SSH_DIGEST) { in mac_setup_by_alg()
118 if ((mac->hmac_ctx = ssh_hmac_start(macalg->alg)) == NULL) in mac_setup_by_alg()
120 mac->key_len = mac->mac_len = ssh_hmac_bytes(macalg->alg); in mac_setup_by_alg()
122 mac->mac_len = macalg->len / 8; in mac_setup_by_alg()
123 mac->key_len = macalg->key_len / 8; in mac_setup_by_alg()
124 mac->umac_ctx = NULL; in mac_setup_by_alg()
127 mac->mac_len = macalg->truncatebits / 8; in mac_setup_by_alg()
128 mac->etm = macalg->etm; in mac_setup_by_alg()
133 mac_setup(struct sshmac *mac, char *name) in mac_setup() argument
140 if (mac != NULL) in mac_setup()
141 return mac_setup_by_alg(mac, m); in mac_setup()
148 mac_init(struct sshmac *mac) in mac_init() argument
150 if (mac->key == NULL) in mac_init()
152 switch (mac->type) { in mac_init()
154 if (mac->hmac_ctx == NULL || in mac_init()
155 ssh_hmac_init(mac->hmac_ctx, mac->key, mac->key_len) < 0) in mac_init()
159 if ((mac->umac_ctx = umac_new(mac->key)) == NULL) in mac_init()
163 if ((mac->umac_ctx = umac128_new(mac->key)) == NULL) in mac_init()
172 mac_compute(struct sshmac *mac, u_int32_t seqno, const u_char *data, int datalen, in mac_compute() argument
182 if (mac->mac_len > sizeof(u)) in mac_compute()
185 switch (mac->type) { in mac_compute()
189 if (ssh_hmac_init(mac->hmac_ctx, NULL, 0) < 0 || in mac_compute()
190 ssh_hmac_update(mac->hmac_ctx, b, sizeof(b)) < 0 || in mac_compute()
191 ssh_hmac_update(mac->hmac_ctx, data, datalen) < 0 || in mac_compute()
192 ssh_hmac_final(mac->hmac_ctx, u.m, sizeof(u.m)) < 0) in mac_compute()
197 umac_update(mac->umac_ctx, data, datalen); in mac_compute()
198 umac_final(mac->umac_ctx, u.m, nonce); in mac_compute()
202 umac128_update(mac->umac_ctx, data, datalen); in mac_compute()
203 umac128_final(mac->umac_ctx, u.m, nonce); in mac_compute()
209 if (dlen > mac->mac_len) in mac_compute()
210 dlen = mac->mac_len; in mac_compute()
217 mac_clear(struct sshmac *mac) in mac_clear() argument
219 if (mac->type == SSH_UMAC) { in mac_clear()
220 if (mac->umac_ctx != NULL) in mac_clear()
221 umac_delete(mac->umac_ctx); in mac_clear()
222 } else if (mac->type == SSH_UMAC128) { in mac_clear()
223 if (mac->umac_ctx != NULL) in mac_clear()
224 umac128_delete(mac->umac_ctx); in mac_clear()
225 } else if (mac->hmac_ctx != NULL) in mac_clear()
226 ssh_hmac_free(mac->hmac_ctx); in mac_clear()
227 mac->hmac_ctx = NULL; in mac_clear()
228 mac->umac_ctx = NULL; in mac_clear()