Skip to content

Commit 72b9197

Browse files
committed
indcpa: Add missing zeroization of pkpv
mlk_indcpa_keypair_derand and mlk_indcpa_enc were missing zeroization of pkpv. This commit adds that zeroization. For easier auditing, it also reorders the zeroizations to be in the same order as the declarations. Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
1 parent e65d6b2 commit 72b9197

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

mlkem/src/indcpa.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,12 @@ void mlk_indcpa_keypair_derand(uint8_t pk[MLKEM_INDCPA_PUBLICKEYBYTES],
442442
/* Specification: Partially implements
443443
* @[FIPS203, Section 3.3, Destruction of intermediate values] */
444444
mlk_zeroize(buf, sizeof(buf));
445-
mlk_zeroize(coins_with_domain_separator, sizeof(coins_with_domain_separator));
446445
mlk_zeroize(&a, sizeof(a));
447446
mlk_zeroize(&e, sizeof(e));
447+
mlk_zeroize(&pkpv, sizeof(pkpv));
448448
mlk_zeroize(&skpv, sizeof(skpv));
449449
mlk_zeroize(&skpv_cache, sizeof(skpv_cache));
450+
mlk_zeroize(coins_with_domain_separator, sizeof(coins_with_domain_separator));
450451
}
451452

452453
/* Reference: `indcpa_enc()` in the reference implementation @[REF].
@@ -525,14 +526,15 @@ void mlk_indcpa_enc(uint8_t c[MLKEM_INDCPA_BYTES],
525526
/* Specification: Partially implements
526527
* @[FIPS203, Section 3.3, Destruction of intermediate values] */
527528
mlk_zeroize(seed, sizeof(seed));
529+
mlk_zeroize(&at, sizeof(at));
528530
mlk_zeroize(&sp, sizeof(sp));
529-
mlk_zeroize(&sp_cache, sizeof(sp_cache));
531+
mlk_zeroize(&pkpv, sizeof(pkpv));
532+
mlk_zeroize(&ep, sizeof(ep));
530533
mlk_zeroize(&b, sizeof(b));
531534
mlk_zeroize(&v, sizeof(v));
532-
mlk_zeroize(&at, sizeof(at));
533535
mlk_zeroize(&k, sizeof(k));
534-
mlk_zeroize(&ep, sizeof(ep));
535536
mlk_zeroize(&epp, sizeof(epp));
537+
mlk_zeroize(&sp_cache, sizeof(sp_cache));
536538
}
537539

538540
/* Reference: `indcpa_dec()` in the reference implementation @[REF].
@@ -562,11 +564,11 @@ void mlk_indcpa_dec(uint8_t m[MLKEM_INDCPA_MSGBYTES],
562564

563565
/* Specification: Partially implements
564566
* @[FIPS203, Section 3.3, Destruction of intermediate values] */
565-
mlk_zeroize(&skpv, sizeof(skpv));
566567
mlk_zeroize(&b, sizeof(b));
567-
mlk_zeroize(&b_cache, sizeof(b_cache));
568+
mlk_zeroize(&skpv, sizeof(skpv));
568569
mlk_zeroize(&v, sizeof(v));
569570
mlk_zeroize(&sb, sizeof(sb));
571+
mlk_zeroize(&b_cache, sizeof(b_cache));
570572
}
571573

572574
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.

0 commit comments

Comments
 (0)