int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length) { if (length > (size_t)ctx->hash->length) return -EINVAL; ctx->hash->digest(&ctx->nettle_ctx, length, (uint8_t *)buffer); crypt_hash_restart(ctx); return 0; }
int crypt_hash_final(struct crypt_hash *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_hash_restart(ctx); return 0; }
int crypt_hash_final(struct crypt_hash *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; if (EVP_DigestFinal_ex(&ctx->md, tmp, &tmp_len) != 1) return -EINVAL; memcpy(buffer, tmp, length); memset(tmp, 0, sizeof(tmp)); if (tmp_len < length) return -EINVAL; if (crypt_hash_restart(ctx)) return -EINVAL; return 0; }