@@ -1681,9 +1681,6 @@ int wc_MlKemKey_DecodePrivateKey(MlKemKey* key, const unsigned char* in,
16811681 }
16821682
16831683 if (ret == 0 ) {
1684- byte computedHash [WC_ML_KEM_SYM_SZ ];
1685- XMEMSET (computedHash , 0 , WC_ML_KEM_SYM_SZ );
1686-
16871684 /* Decode private key that is vector of polynomials.
16881685 * Alg 18 Step 1: dk_PKE <- dk[0 : 384k]
16891686 * Alg 15 Step 5: s_hat <- ByteDecode_12(dk_PKE) */
@@ -1693,23 +1690,23 @@ int wc_MlKemKey_DecodePrivateKey(MlKemKey* key, const unsigned char* in,
16931690 /* Decode the public key that is after the private key. */
16941691 mlkemkey_decode_public (key -> pub , key -> pubSeed , p , k );
16951692 /* Compute the hash of the public key. */
1696- MLKEM_HASH_H (& key -> hash , p , pubLen , computedHash );
1693+ ret = MLKEM_HASH_H (& key -> hash , p , pubLen , key -> h );
16971694 p += pubLen ;
1695+ }
1696+
1697+ if (ret == 0 ) {
1698+ /* Compare computed public key hash with stored hash */
1699+ if (XMEMCMP (key -> h , p , WC_ML_KEM_SYM_SZ ) != 0 )
1700+ ret = MLKEM_PUB_HASH_E ;
16981701
16991702 /* Copy the hash of the encoded public key that is after public key. */
17001703 XMEMCPY (key -> h , p , sizeof (key -> h ));
17011704 p += WC_ML_KEM_SYM_SZ ;
1702-
17031705 /* Copy the z (randomizer) that is after hash. */
17041706 XMEMCPY (key -> z , p , sizeof (key -> z ));
17051707
17061708 /* Set flags */
17071709 key -> flags |= MLKEM_FLAG_H_SET | MLKEM_FLAG_BOTH_SET ;
1708-
1709- /* Compare computed public key hash with stored hash */
1710- if (XMEMCMP (key -> h , computedHash , WC_ML_KEM_SYM_SZ ) != 0 )
1711- ret = MLKEM_PUB_HASH_E ;
1712-
17131710 }
17141711
17151712 return ret ;
0 commit comments