int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length) { if (length > (size_t)ctx->hash->length) return -EINVAL; ctx->hash->hmac_digest(&ctx->nettle_ctx, length, (uint8_t *)buffer); crypt_hmac_restart(ctx); return 0; }
int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length) { unsigned char *hash; if (length > (size_t)ctx->hash_len) return -EINVAL; hash = gcry_md_read(ctx->hd, ctx->hash_id); if (!hash) return -EINVAL; memcpy(buffer, hash, length); crypt_hmac_restart(ctx); return 0; }
int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length) { unsigned char tmp[EVP_MAX_MD_SIZE]; unsigned int tmp_len = 0; if (length > (size_t)ctx->hash_len) return -EINVAL; HMAC_Final(&ctx->md, tmp, &tmp_len); memcpy(buffer, tmp, length); memset(tmp, 0, sizeof(tmp)); if (tmp_len < length) return -EINVAL; crypt_hmac_restart(ctx); return 0; }