int mac_init(struct sshmac *mac) { if (mac->key == NULL) return SSH_ERR_INVALID_ARGUMENT; switch (mac->type) { case SSH_EVP: if (mac->evp_md == NULL) return SSH_ERR_INVALID_ARGUMENT; HMAC_CTX_init(&mac->evp_ctx); if (HMAC_Init(&mac->evp_ctx, mac->key, mac->key_len, mac->evp_md) != 1) { HMAC_CTX_cleanup(&mac->evp_ctx); return SSH_ERR_LIBCRYPTO_ERROR; } return 0; case SSH_UMAC: if ((mac->umac_ctx = umac_new(mac->key)) == NULL) return SSH_ERR_ALLOC_FAIL; return 0; case SSH_UMAC128: mac->umac_ctx = umac128_new(mac->key); return 0; default: return SSH_ERR_INVALID_ARGUMENT; } }
int mac_init(Mac *mac) { if (mac->key == NULL) fatal("%s: no key", __func__); switch (mac->type) { case SSH_DIGEST: if (mac->hmac_ctx == NULL || ssh_hmac_init(mac->hmac_ctx, mac->key, mac->key_len) < 0) return -1; return 0; case SSH_UMAC: mac->umac_ctx = umac_new(mac->key); return 0; case SSH_UMAC128: mac->umac_ctx = umac128_new(mac->key); return 0; default: return -1; } }
int mac_init(Mac *mac) { if (mac->key == NULL) fatal("mac_init: no key"); switch (mac->type) { case SSH_EVP: if (mac->evp_md == NULL) return -1; HMAC_CTX_init(&mac->evp_ctx); HMAC_Init(&mac->evp_ctx, mac->key, mac->key_len, mac->evp_md); return 0; case SSH_UMAC: mac->umac_ctx = umac_new(mac->key); return 0; case SSH_UMAC128: mac->umac_ctx = umac128_new(mac->key); return 0; default: return -1; } }