@ -682,12 +682,12 @@ static void encrypt_cpa(uint8_t out[KYBER_CIPHERTEXT_BYTES],
// Calls KYBER_encap_external_entropy| with random bytes from |RAND_bytes|
void KYBER_encap ( uint8_t out_ciphertext [ KYBER_CIPHERTEXT_BYTES ] ,
uint8_t * out_shared_secret , size_t out_shared_secret_len ,
uint8_t out_shared_secret [ KYBER_SHARED_SECRET_BYTES ] ,
const struct KYBER_public_key * public_key ) {
uint8_t entropy [ KYBER_ENCAP_ENTROPY ] ;
RAND_bytes ( entropy , KYBER_ENCAP_ENTROPY ) ;
KYBER_encap_external_entropy ( out_ciphertext , out_shared_secret ,
out_shared_secret_len , public_key , entropy ) ;
KYBER_encap_external_entropy ( out_ciphertext , out_shared_secret , public_key ,
entropy ) ;
}
// Algorithm 8 of the Kyber spec, safe for line 2 of the spec. The spec there
@ -697,8 +697,9 @@ void KYBER_encap(uint8_t out_ciphertext[KYBER_CIPHERTEXT_BYTES],
// number generator is used, the caller should switch to a secure one before
// calling this method.
void KYBER_encap_external_entropy (
uint8_t out_ciphertext [ KYBER_CIPHERTEXT_BYTES ] , uint8_t * out_shared_secret ,
size_t out_shared_secret_len , const struct KYBER_public_key * public_key ,
uint8_t out_ciphertext [ KYBER_CIPHERTEXT_BYTES ] ,
uint8_t out_shared_secret [ KYBER_SHARED_SECRET_BYTES ] ,
const struct KYBER_public_key * public_key ,
const uint8_t entropy [ KYBER_ENCAP_ENTROPY ] ) {
const struct public_key * pub = public_key_from_external ( public_key ) ;
uint8_t input [ 64 ] ;
@ -711,7 +712,7 @@ void KYBER_encap_external_entropy(
encrypt_cpa ( out_ciphertext , pub , entropy , prekey_and_randomness + 32 ) ;
BORINGSSL_keccak ( prekey_and_randomness + 32 , 32 , out_ciphertext ,
KYBER_CIPHERTEXT_BYTES , boringssl_sha3_256 ) ;
BORINGSSL_keccak ( out_shared_secret , out_shared_secret_len ,
BORINGSSL_keccak ( out_shared_secret , KYBER_SHARED_SECRET_BYTES ,
prekey_and_randomness , sizeof ( prekey_and_randomness ) ,
boringssl_shake256 ) ;
}
@ -739,7 +740,7 @@ static void decrypt_cpa(uint8_t out[32], const struct private_key *priv,
// failure to be passed on to the caller, and instead returns a result that is
// deterministic but unpredictable to anyone without knowledge of the private
// key.
void KYBER_decap ( uint8_t * out_shared_secret , size_t out_shared_secret_len ,
void KYBER_decap ( uint8_t out_shared_secret [ KYBER_SHARED_SECRET_BYTES ] ,
const uint8_t ciphertext [ KYBER_CIPHERTEXT_BYTES ] ,
const struct KYBER_private_key * private_key ) {
const struct private_key * priv = private_key_from_external ( private_key ) ;
@ -764,7 +765,7 @@ void KYBER_decap(uint8_t *out_shared_secret, size_t out_shared_secret_len,
}
BORINGSSL_keccak ( input + 32 , 32 , ciphertext , KYBER_CIPHERTEXT_BYTES ,
boringssl_sha3_256 ) ;
BORINGSSL_keccak ( out_shared_secret , out_shared_secret_len , input ,
BORINGSSL_keccak ( out_shared_secret , KYBER_SHARED_SECRET_BYTES , input ,
sizeof ( input ) , boringssl_shake256 ) ;
}