1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-23 07:59:01 +00:00
pqcrypto/crypto_kem/kyber768/clean/kex.c

59 lines
2.4 KiB
C
Raw Normal View History

#include "kex.h"
#include "fips202.h"
#include "verify.h"
2019-01-22 16:38:22 +00:00
void PQCLEAN_KYBER768_kyber_uake_initA(u8 *send, u8 *tk, u8 *sk,
const u8 *pkb) {
PQCLEAN_KYBER768_crypto_kem_keypair(send, sk);
PQCLEAN_KYBER768_crypto_kem_enc(send + KYBER_PUBLICKEYBYTES, tk, pkb);
}
2019-01-22 16:38:22 +00:00
void PQCLEAN_KYBER768_kyber_uake_sharedB(u8 *send, u8 *k, const u8 *recv,
const u8 *skb) {
2019-01-16 10:02:32 +00:00
unsigned char buf[2 * KYBER_SYMBYTES];
2019-01-22 16:38:22 +00:00
PQCLEAN_KYBER768_crypto_kem_enc(send, buf, recv);
PQCLEAN_KYBER768_crypto_kem_dec(buf + KYBER_SYMBYTES,
recv + KYBER_PUBLICKEYBYTES, skb);
2019-01-16 10:02:32 +00:00
shake256(k, KYBER_SYMBYTES, buf, 2 * KYBER_SYMBYTES);
}
2019-01-22 16:38:22 +00:00
void PQCLEAN_KYBER768_kyber_uake_sharedA(u8 *k, const u8 *recv, const u8 *tk,
const u8 *sk) {
2019-01-16 10:02:32 +00:00
unsigned char buf[2 * KYBER_SYMBYTES];
int i;
2019-01-22 16:38:22 +00:00
PQCLEAN_KYBER768_crypto_kem_dec(buf, recv, sk);
2019-01-16 10:02:32 +00:00
for (i = 0; i < KYBER_SYMBYTES; i++) {
buf[i + KYBER_SYMBYTES] = tk[i];
}
shake256(k, KYBER_SYMBYTES, buf, 2 * KYBER_SYMBYTES);
}
2019-01-22 16:38:22 +00:00
void PQCLEAN_KYBER768_kyber_ake_initA(u8 *send, u8 *tk, u8 *sk, const u8 *pkb) {
PQCLEAN_KYBER768_crypto_kem_keypair(send, sk);
PQCLEAN_KYBER768_crypto_kem_enc(send + KYBER_PUBLICKEYBYTES, tk, pkb);
}
2019-01-22 16:38:22 +00:00
void PQCLEAN_KYBER768_kyber_ake_sharedB(u8 *send, u8 *k, const u8 *recv,
const u8 *skb, const u8 *pka) {
2019-01-16 10:02:32 +00:00
unsigned char buf[3 * KYBER_SYMBYTES];
2019-01-22 16:38:22 +00:00
PQCLEAN_KYBER768_crypto_kem_enc(send, buf, recv);
PQCLEAN_KYBER768_crypto_kem_enc(send + KYBER_CIPHERTEXTBYTES,
buf + KYBER_SYMBYTES, pka);
PQCLEAN_KYBER768_crypto_kem_dec(buf + 2 * KYBER_SYMBYTES,
recv + KYBER_PUBLICKEYBYTES, skb);
2019-01-16 10:02:32 +00:00
shake256(k, KYBER_SYMBYTES, buf, 3 * KYBER_SYMBYTES);
}
2019-01-22 16:38:22 +00:00
void PQCLEAN_KYBER768_kyber_ake_sharedA(u8 *k, const u8 *recv, const u8 *tk,
const u8 *sk, const u8 *ska) {
2019-01-16 10:02:32 +00:00
unsigned char buf[3 * KYBER_SYMBYTES];
int i;
2019-01-22 16:38:22 +00:00
PQCLEAN_KYBER768_crypto_kem_dec(buf, recv, sk);
PQCLEAN_KYBER768_crypto_kem_dec(buf + KYBER_SYMBYTES,
recv + KYBER_CIPHERTEXTBYTES, ska);
2019-01-16 10:02:32 +00:00
for (i = 0; i < KYBER_SYMBYTES; i++) {
buf[i + 2 * KYBER_SYMBYTES] = tk[i];
}
shake256(k, KYBER_SYMBYTES, buf, 3 * KYBER_SYMBYTES);
}