mirror of
https://github.com/henrydcase/pqc.git
synced 2024-11-22 15:39:07 +00:00
remove duplication
This commit is contained in:
parent
fd21b95a2d
commit
1120727660
@ -3,7 +3,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/*************************************************
|
/*************************************************
|
||||||
* Name: PQCLEAN_KYBER768_CLEAN_montgomery_reduce
|
* Name: kyber_montgomery_reduce
|
||||||
*
|
*
|
||||||
* Description: Montgomery reduction; given a 32-bit integer a, computes
|
* Description: Montgomery reduction; given a 32-bit integer a, computes
|
||||||
* 16-bit integer congruent to a * R^-1 mod q, where R=2^16
|
* 16-bit integer congruent to a * R^-1 mod q, where R=2^16
|
||||||
@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
* Returns: integer in {-q+1,...,q-1} congruent to a * R^-1 modulo q.
|
* Returns: integer in {-q+1,...,q-1} congruent to a * R^-1 modulo q.
|
||||||
**************************************************/
|
**************************************************/
|
||||||
int16_t PQCLEAN_KYBER768_CLEAN_montgomery_reduce(int32_t a) {
|
int16_t kyber_montgomery_reduce(int32_t a) {
|
||||||
int32_t t;
|
int32_t t;
|
||||||
int16_t u;
|
int16_t u;
|
||||||
|
|
||||||
@ -25,20 +25,19 @@ int16_t PQCLEAN_KYBER768_CLEAN_montgomery_reduce(int32_t a) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************
|
/*************************************************
|
||||||
* Name: PQCLEAN_KYBER768_CLEAN_barrett_reduce
|
* Name: kyber_barrett_reduce
|
||||||
*
|
*
|
||||||
* Description: Barrett reduction; given a 16-bit integer a, computes
|
* Description: Barrett reduction; given a 16-bit integer a, computes
|
||||||
* centered representative congruent to a mod q in {-(q-1)/2,...,(q-1)/2}
|
* centered representative congruent to a mod q in {0,q}
|
||||||
*
|
*
|
||||||
* Arguments: - int16_t a: input integer to be reduced
|
* Arguments: - int16_t a: input integer to be reduced
|
||||||
*
|
*
|
||||||
* Returns: integer in {-(q-1)/2,...,(q-1)/2} congruent to a modulo q.
|
* Returns: integer in {0,q} congruent to a modulo q.
|
||||||
**************************************************/
|
**************************************************/
|
||||||
int16_t PQCLEAN_KYBER768_CLEAN_barrett_reduce(int16_t a) {
|
int16_t kyber_barrett_reduce(int16_t a) {
|
||||||
int16_t t;
|
static const int32_t v = 20159;
|
||||||
const int16_t v = ((1U << 26) + KYBER_Q / 2) / KYBER_Q;
|
int32_t t;
|
||||||
|
t = v*a;
|
||||||
t = ((int32_t)v * a + (1 << 25)) >> 26;
|
t >>= 26;
|
||||||
t *= KYBER_Q;
|
return a - ((int16_t)t)*KYBER_Q;
|
||||||
return a - t;
|
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ set(
|
|||||||
ntt.c
|
ntt.c
|
||||||
poly.c
|
poly.c
|
||||||
polyvec.c
|
polyvec.c
|
||||||
reduce.c
|
../../common/reduce.c
|
||||||
symmetric-shake.c
|
symmetric-shake.c
|
||||||
verify.c
|
verify.c
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "ntt.h"
|
#include "ntt.h"
|
||||||
#include "params.h"
|
#include "params.h"
|
||||||
#include "reduce.h"
|
#include "../../common/reduce.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* Code to generate PQCLEAN_KYBER1024_CLEAN_zetas and zetas_inv used in the number-theoretic transform:
|
/* Code to generate PQCLEAN_KYBER1024_CLEAN_zetas and zetas_inv used in the number-theoretic transform:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "ntt.h"
|
#include "ntt.h"
|
||||||
#include "params.h"
|
#include "params.h"
|
||||||
#include "poly.h"
|
#include "poly.h"
|
||||||
#include "reduce.h"
|
#include "../../common/reduce.h"
|
||||||
#include "symmetric.h"
|
#include "symmetric.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
#include "params.h"
|
|
||||||
#include "reduce.h"
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/*************************************************
|
|
||||||
* Name: PQCLEAN_KYBER1024_CLEAN_montgomery_reduce
|
|
||||||
*
|
|
||||||
* Description: Montgomery reduction; given a 32-bit integer a, computes
|
|
||||||
* 16-bit integer congruent to a * R^-1 mod q, where R=2^16
|
|
||||||
*
|
|
||||||
* Arguments: - int32_t a: input integer to be reduced;
|
|
||||||
* has to be in {-q2^15,...,q2^15-1}
|
|
||||||
*
|
|
||||||
* Returns: integer in {-q+1,...,q-1} congruent to a * R^-1 modulo q.
|
|
||||||
**************************************************/
|
|
||||||
int16_t PQCLEAN_KYBER1024_CLEAN_montgomery_reduce(int32_t a) {
|
|
||||||
int32_t t;
|
|
||||||
int16_t u;
|
|
||||||
|
|
||||||
u = (int16_t)(a * (int64_t)QINV);
|
|
||||||
t = (int32_t)u * KYBER_Q;
|
|
||||||
t = a - t;
|
|
||||||
t >>= 16;
|
|
||||||
return (int16_t)t;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************
|
|
||||||
* Name: PQCLEAN_KYBER1024_CLEAN_barrett_reduce
|
|
||||||
*
|
|
||||||
* Description: Barrett reduction; given a 16-bit integer a, computes
|
|
||||||
* centered representative congruent to a mod q in {-(q-1)/2,...,(q-1)/2}
|
|
||||||
*
|
|
||||||
* Arguments: - int16_t a: input integer to be reduced
|
|
||||||
*
|
|
||||||
* Returns: integer in {-(q-1)/2,...,(q-1)/2} congruent to a modulo q.
|
|
||||||
**************************************************/
|
|
||||||
int16_t PQCLEAN_KYBER1024_CLEAN_barrett_reduce(int16_t a) {
|
|
||||||
int16_t t;
|
|
||||||
const int16_t v = ((1U << 26) + KYBER_Q / 2) / KYBER_Q;
|
|
||||||
|
|
||||||
t = ((int32_t)v * a + (1 << 25)) >> 26;
|
|
||||||
t *= KYBER_Q;
|
|
||||||
return a - t;
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
#ifndef PQCLEAN_KYBER1024_CLEAN_REDUCE_H
|
|
||||||
#define PQCLEAN_KYBER1024_CLEAN_REDUCE_H
|
|
||||||
#include "params.h"
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#define MONT 2285 // 2^16 mod q
|
|
||||||
#define QINV 62209 // q^-1 mod 2^16
|
|
||||||
|
|
||||||
int16_t PQCLEAN_KYBER1024_CLEAN_montgomery_reduce(int32_t a);
|
|
||||||
|
|
||||||
int16_t PQCLEAN_KYBER1024_CLEAN_barrett_reduce(int16_t a);
|
|
||||||
|
|
||||||
#endif
|
|
@ -6,7 +6,6 @@ set(
|
|||||||
ntt.c
|
ntt.c
|
||||||
poly.c
|
poly.c
|
||||||
polyvec.c
|
polyvec.c
|
||||||
reduce.c
|
|
||||||
symmetric-shake.c
|
symmetric-shake.c
|
||||||
verify.c
|
verify.c
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "ntt.h"
|
#include "ntt.h"
|
||||||
#include "params.h"
|
#include "params.h"
|
||||||
#include "reduce.h"
|
#include "../../common/reduce.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* Code to generate PQCLEAN_KYBER512_CLEAN_zetas and zetas_inv used in the number-theoretic transform:
|
/* Code to generate PQCLEAN_KYBER512_CLEAN_zetas and zetas_inv used in the number-theoretic transform:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "ntt.h"
|
#include "ntt.h"
|
||||||
#include "params.h"
|
#include "params.h"
|
||||||
#include "poly.h"
|
#include "poly.h"
|
||||||
#include "reduce.h"
|
#include "../../common/reduce.h"
|
||||||
#include "symmetric.h"
|
#include "symmetric.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
#include "params.h"
|
|
||||||
#include "reduce.h"
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/*************************************************
|
|
||||||
* Name: PQCLEAN_KYBER512_CLEAN_montgomery_reduce
|
|
||||||
*
|
|
||||||
* Description: Montgomery reduction; given a 32-bit integer a, computes
|
|
||||||
* 16-bit integer congruent to a * R^-1 mod q, where R=2^16
|
|
||||||
*
|
|
||||||
* Arguments: - int32_t a: input integer to be reduced;
|
|
||||||
* has to be in {-q2^15,...,q2^15-1}
|
|
||||||
*
|
|
||||||
* Returns: integer in {-q+1,...,q-1} congruent to a * R^-1 modulo q.
|
|
||||||
**************************************************/
|
|
||||||
int16_t PQCLEAN_KYBER512_CLEAN_montgomery_reduce(int32_t a) {
|
|
||||||
int32_t t;
|
|
||||||
int16_t u;
|
|
||||||
|
|
||||||
u = (int16_t)(a * (int64_t)QINV);
|
|
||||||
t = (int32_t)u * KYBER_Q;
|
|
||||||
t = a - t;
|
|
||||||
t >>= 16;
|
|
||||||
return (int16_t)t;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************
|
|
||||||
* Name: PQCLEAN_KYBER512_CLEAN_barrett_reduce
|
|
||||||
*
|
|
||||||
* Description: Barrett reduction; given a 16-bit integer a, computes
|
|
||||||
* centered representative congruent to a mod q in {-(q-1)/2,...,(q-1)/2}
|
|
||||||
*
|
|
||||||
* Arguments: - int16_t a: input integer to be reduced
|
|
||||||
*
|
|
||||||
* Returns: integer in {-(q-1)/2,...,(q-1)/2} congruent to a modulo q.
|
|
||||||
**************************************************/
|
|
||||||
int16_t PQCLEAN_KYBER512_CLEAN_barrett_reduce(int16_t a) {
|
|
||||||
int16_t t;
|
|
||||||
const int16_t v = ((1U << 26) + KYBER_Q / 2) / KYBER_Q;
|
|
||||||
|
|
||||||
t = ((int32_t)v * a + (1 << 25)) >> 26;
|
|
||||||
t *= KYBER_Q;
|
|
||||||
return a - t;
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
#ifndef PQCLEAN_KYBER512_CLEAN_REDUCE_H
|
|
||||||
#define PQCLEAN_KYBER512_CLEAN_REDUCE_H
|
|
||||||
#include "params.h"
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#define MONT 2285 // 2^16 mod q
|
|
||||||
#define QINV 62209 // q^-1 mod 2^16
|
|
||||||
|
|
||||||
int16_t PQCLEAN_KYBER512_CLEAN_montgomery_reduce(int32_t a);
|
|
||||||
|
|
||||||
int16_t PQCLEAN_KYBER512_CLEAN_barrett_reduce(int16_t a);
|
|
||||||
|
|
||||||
#endif
|
|
@ -6,7 +6,6 @@ set(
|
|||||||
ntt.c
|
ntt.c
|
||||||
poly.c
|
poly.c
|
||||||
polyvec.c
|
polyvec.c
|
||||||
reduce.c
|
|
||||||
symmetric-shake.c
|
symmetric-shake.c
|
||||||
verify.c
|
verify.c
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "ntt.h"
|
#include "ntt.h"
|
||||||
#include "params.h"
|
#include "params.h"
|
||||||
#include "reduce.h"
|
#include "../../common/reduce.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* Code to generate PQCLEAN_KYBER768_CLEAN_zetas and zetas_inv used in the number-theoretic transform:
|
/* Code to generate PQCLEAN_KYBER768_CLEAN_zetas and zetas_inv used in the number-theoretic transform:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "ntt.h"
|
#include "ntt.h"
|
||||||
#include "params.h"
|
#include "params.h"
|
||||||
#include "poly.h"
|
#include "poly.h"
|
||||||
#include "reduce.h"
|
#include "../../common/reduce.h"
|
||||||
#include "symmetric.h"
|
#include "symmetric.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
#ifndef PQCLEAN_KYBER768_CLEAN_REDUCE_H
|
|
||||||
#define PQCLEAN_KYBER768_CLEAN_REDUCE_H
|
|
||||||
#include "params.h"
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#define MONT 2285 // 2^16 mod q
|
|
||||||
#define QINV 62209 // q^-1 mod 2^16
|
|
||||||
|
|
||||||
int16_t PQCLEAN_KYBER768_CLEAN_montgomery_reduce(int32_t a);
|
|
||||||
|
|
||||||
int16_t PQCLEAN_KYBER768_CLEAN_barrett_reduce(int16_t a);
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user