13 const unsigned char *ikm,
16 unsigned int salt_len,
20 const cx_hash_info_t *hash_info;
23 hash_info = cx_hash_get_info(hash_id);
24 md_len = hash_info->output_size;
26 hmac_ctx = &
G_cx.hmac;
29 memset(hmac_ctx->key, 0, md_len);
33 if (cx_hmac_init(hmac_ctx, hash_id, salt, salt_len) != CX_OK
34 || cx_hmac_update(hmac_ctx, ikm, ikm_len) != CX_OK
35 || cx_hmac_final(hmac_ctx, prk, &md_len) != CX_OK) {
41 const unsigned char *prk,
44 unsigned int info_len,
49 unsigned int offset = 0;
50 unsigned char T[MAX_HASH_SIZE];
52 const cx_hash_info_t *hash_info;
55 hash_info = cx_hash_get_info(hash_id);
56 md_len = hash_info->output_size;
58 hmac_ctx = &
G_cx.hmac;
60 for (i = 1; okm_len > 0; i++) {
61 if (cx_hmac_init(hmac_ctx, hash_id, prk, prk_len) != CX_OK) {
65 if (cx_hmac_update(hmac_ctx, T, offset) != CX_OK) {
69 if (cx_hmac_update(hmac_ctx, info, info_len) != CX_OK
70 || cx_hmac_update(hmac_ctx, &i,
sizeof(i)) != CX_OK
71 || cx_hmac_final(hmac_ctx, T, &md_len) != CX_OK) {
75 offset = (okm_len < md_len) ? okm_len : md_len;
76 memcpy(okm + (i - 1) * md_len, T, offset);
void cx_hkdf_extract(const cx_md_t hash_id, const unsigned char *ikm, unsigned int ikm_len, unsigned char *salt, unsigned int salt_len, unsigned char *prk)
void cx_hkdf_expand(const cx_md_t hash_id, const unsigned char *prk, unsigned int prk_len, unsigned char *info, unsigned int info_len, unsigned char *okm, unsigned int okm_len)