Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ref/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define pqcrystals_kyber512_SECRETKEYBYTES 1632
#define pqcrystals_kyber512_PUBLICKEYBYTES 800
#define pqcrystals_kyber512_CIPHERTEXTBYTES 768
Expand Down Expand Up @@ -63,4 +67,8 @@ int pqcrystals_kyber1024_ref_enc_derand(uint8_t *ct, uint8_t *ss, const uint8_t
int pqcrystals_kyber1024_ref_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
int pqcrystals_kyber1024_ref_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions ref/cbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
#include "params.h"
#include "poly.h"

#ifdef __cplusplus
extern "C" {
#endif

#define poly_cbd_eta1 KYBER_NAMESPACE(poly_cbd_eta1)
void poly_cbd_eta1(poly *r, const uint8_t buf[KYBER_ETA1*KYBER_N/4]);

#define poly_cbd_eta2 KYBER_NAMESPACE(poly_cbd_eta2)
void poly_cbd_eta2(poly *r, const uint8_t buf[KYBER_ETA2*KYBER_N/4]);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions ref/fips202.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define SHAKE128_RATE 168
#define SHAKE256_RATE 136
#define SHA3_256_RATE 136
Expand Down Expand Up @@ -51,4 +55,8 @@ void sha3_256(uint8_t h[32], const uint8_t *in, size_t inlen);
#define sha3_512 FIPS202_NAMESPACE(sha3_512)
void sha3_512(uint8_t h[64], const uint8_t *in, size_t inlen);

#ifdef __cplusplus
}
#endif

#endif
16 changes: 16 additions & 0 deletions ref/indcpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,19 @@ void indcpa_dec(uint8_t m[KYBER_INDCPA_MSGBYTES],

poly_tomsg(m, &mp);
}

/* FUNCIÓN PARA REALIZAR LA DIFERENCIA EN EL DOMINIO CIFRADO*/

void compareCiphertexts(uint8_t c1[KYBER_INDCPA_BYTES], uint8_t c2[KYBER_INDCPA_BYTES], uint8_t cDiff[KYBER_INDCPA_BYTES]) {
polyvec b1, b2, b;
poly v1, v2, v;

// Primero de desempaquetan
unpack_ciphertext(&b1, &v1, c1);
unpack_ciphertext(&b2, &v2, c2);

poly_sub(&v, &v1, &v2);
polyvec_sub(&b, &b1, &b2);

pack_ciphertext(cDiff, &b, &v);
}
11 changes: 11 additions & 0 deletions ref/indcpa.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "params.h"
#include "polyvec.h"

#ifdef __cplusplus
extern "C" {
#endif

#define gen_matrix KYBER_NAMESPACE(gen_matrix)
void gen_matrix(polyvec *a, const uint8_t seed[KYBER_SYMBYTES], int transposed);

Expand All @@ -24,4 +28,11 @@ void indcpa_dec(uint8_t m[KYBER_INDCPA_MSGBYTES],
const uint8_t c[KYBER_INDCPA_BYTES],
const uint8_t sk[KYBER_INDCPA_SECRETKEYBYTES]);

void compareCiphertexts(uint8_t c1[KYBER_INDCPA_BYTES], uint8_t c2[KYBER_INDCPA_BYTES], uint8_t cDiff[KYBER_INDCPA_BYTES]);

#ifdef __cplusplus
}
#endif


#endif
4 changes: 2 additions & 2 deletions ref/kem.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ int crypto_kem_dec(uint8_t *ss,
uint8_t buf[2*KYBER_SYMBYTES];
/* Will contain key, coins */
uint8_t kr[2*KYBER_SYMBYTES];
// uint8_t cmp[KYBER_CIPHERTEXTBYTES+KYBER_SYMBYTES];
uint8_t cmp[KYBER_CIPHERTEXTBYTES];
uint8_t cmp[KYBER_CIPHERTEXTBYTES+KYBER_SYMBYTES];
// uint8_t cmp[KYBER_CIPHERTEXTBYTES];
const uint8_t *pk = sk+KYBER_INDCPA_SECRETKEYBYTES;

indcpa_dec(buf, ct, sk);
Expand Down
8 changes: 8 additions & 0 deletions ref/kem.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <stdint.h>
#include "params.h"

#ifdef __cplusplus
extern "C" {
#endif

#define CRYPTO_SECRETKEYBYTES KYBER_SECRETKEYBYTES
#define CRYPTO_PUBLICKEYBYTES KYBER_PUBLICKEYBYTES
#define CRYPTO_CIPHERTEXTBYTES KYBER_CIPHERTEXTBYTES
Expand Down Expand Up @@ -32,4 +36,8 @@ int crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
#define crypto_kem_dec KYBER_NAMESPACE(dec)
int crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions ref/ntt.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <stdint.h>
#include "params.h"

#ifdef __cplusplus
extern "C" {
#endif

#define zetas KYBER_NAMESPACE(zetas)
extern const int16_t zetas[128];

Expand All @@ -16,4 +20,8 @@ void invntt(int16_t poly[256]);
#define basemul KYBER_NAMESPACE(basemul)
void basemul(int16_t r[2], const int16_t a[2], const int16_t b[2], int16_t zeta);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions ref/poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <stdint.h>
#include "params.h"

#ifdef __cplusplus
extern "C" {
#endif

/*
* Elements of R_q = Z_q[X]/(X^n + 1). Represents polynomial
* coeffs[0] + X*coeffs[1] + X^2*coeffs[2] + ... + X^{n-1}*coeffs[n-1]
Expand Down Expand Up @@ -50,4 +54,8 @@ void poly_add(poly *r, const poly *a, const poly *b);
#define poly_sub KYBER_NAMESPACE(poly_sub)
void poly_sub(poly *r, const poly *a, const poly *b);

#ifdef __cplusplus
}
#endif

#endif
16 changes: 16 additions & 0 deletions ref/polyvec.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,19 @@ void polyvec_add(polyvec *r, const polyvec *a, const polyvec *b)
for(i=0;i<KYBER_K;i++)
poly_add(&r->vec[i], &a->vec[i], &b->vec[i]);
}

/*************************************************
* Name: polyvec_sub
*
* Description: Add vectors of polynomials
*
* Arguments: - polyvec *r: pointer to output vector of polynomials
* - const polyvec *a: pointer to first input vector of polynomials
* - const polyvec *b: pointer to second input vector of polynomials
**************************************************/
void polyvec_sub(polyvec *r, const polyvec *a, const polyvec *b)
{
unsigned int i;
for(i=0;i<KYBER_K;i++)
poly_sub(&r->vec[i], &a->vec[i], &b->vec[i]);
}
8 changes: 8 additions & 0 deletions ref/polyvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "params.h"
#include "poly.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct{
poly vec[KYBER_K];
} polyvec;
Expand Down Expand Up @@ -33,4 +37,8 @@ void polyvec_reduce(polyvec *r);
#define polyvec_add KYBER_NAMESPACE(polyvec_add)
void polyvec_add(polyvec *r, const polyvec *a, const polyvec *b);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions ref/randombytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

void randombytes(uint8_t *out, size_t outlen);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions ref/reduce.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <stdint.h>
#include "params.h"

#ifdef __cplusplus
extern "C" {
#endif

#define MONT -1044 // 2^16 mod q
#define QINV -3327 // q^-1 mod 2^16

Expand All @@ -13,4 +17,8 @@ int16_t montgomery_reduce(int32_t a);
#define barrett_reduce KYBER_NAMESPACE(barrett_reduce)
int16_t barrett_reduce(int16_t a);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions ref/symmetric.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

#include "fips202.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef keccak_state xof_state;

#define kyber_shake128_absorb KYBER_NAMESPACE(kyber_shake128_absorb)
Expand All @@ -30,4 +34,8 @@ void kyber_shake256_rkprf(uint8_t out[KYBER_SSBYTES], const uint8_t key[KYBER_SY
#define prf(OUT, OUTBYTES, KEY, NONCE) kyber_shake256_prf(OUT, OUTBYTES, KEY, NONCE)
#define rkprf(OUT, KEY, INPUT) kyber_shake256_rkprf(OUT, KEY, INPUT)

#ifdef __cplusplus
}
#endif

#endif /* SYMMETRIC_H */
8 changes: 8 additions & 0 deletions ref/verify.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <stdint.h>
#include "params.h"

#ifdef __cplusplus
extern "C" {
#endif

#define verify KYBER_NAMESPACE(verify)
int verify(const uint8_t *a, const uint8_t *b, size_t len);

Expand All @@ -14,4 +18,8 @@ void cmov(uint8_t *r, const uint8_t *x, size_t len, uint8_t b);
#define cmov_int16 KYBER_NAMESPACE(cmov_int16)
void cmov_int16(int16_t *r, int16_t v, uint16_t b);

#ifdef __cplusplus
}
#endif

#endif