upstream: remove whitespace at EOL from code extracted from SUPERCOP

OpenBSD-Commit-ID: 1ec524ff2fbb9387d731601437c82008f35a60f4
This commit is contained in:
djm@openbsd.org 2023-01-11 02:13:52 +00:00 committed by Damien Miller
parent d888de06c5
commit 36b00d3183
No known key found for this signature in database
2 changed files with 24 additions and 23 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: sntrup761.c,v 1.5 2021/01/08 02:33:13 dtucker Exp $ */ /* $OpenBSD: sntrup761.c,v 1.6 2023/01/11 02:13:52 djm Exp $ */
/* /*
* Public Domain, Authors: * Public Domain, Authors:
@ -119,7 +119,7 @@ This software is designed to take time independent of x.
Time still varies depending on m; user must ensure that m is constant. Time still varies depending on m; user must ensure that m is constant.
Time also varies on CPUs where multiplication is variable-time. Time also varies on CPUs where multiplication is variable-time.
There could be more CPU issues. There could be more CPU issues.
There could also be compiler issues. There could also be compiler issues.
*/ */
static void uint32_divmod_uint14(uint32 *q,uint16 *r,uint32 x,uint16 m) static void uint32_divmod_uint14(uint32 *q,uint16 *r,uint32 x,uint16 m)
@ -447,7 +447,7 @@ static Fq Fq_freeze(int32 x)
#ifndef LPR #ifndef LPR
static Fq Fq_recip(Fq a1) static Fq Fq_recip(Fq a1)
{ {
int i = 1; int i = 1;
Fq ai = a1; Fq ai = a1;
@ -456,7 +456,7 @@ static Fq Fq_recip(Fq a1)
i += 1; i += 1;
} }
return ai; return ai;
} }
#endif #endif
@ -525,11 +525,11 @@ static void R3_mult(small *h,const small *f,const small *g)
/* returns 0 if recip succeeded; else -1 */ /* returns 0 if recip succeeded; else -1 */
static int R3_recip(small *out,const small *in) static int R3_recip(small *out,const small *in)
{ {
small f[p+1],g[p+1],v[p+1],r[p+1]; small f[p+1],g[p+1],v[p+1],r[p+1];
int i,loop,delta; int i,loop,delta;
int sign,swap,t; int sign,swap,t;
for (i = 0;i < p+1;++i) v[i] = 0; for (i = 0;i < p+1;++i) v[i] = 0;
for (i = 0;i < p+1;++i) r[i] = 0; for (i = 0;i < p+1;++i) r[i] = 0;
r[0] = 1; r[0] = 1;
@ -537,35 +537,35 @@ static int R3_recip(small *out,const small *in)
f[0] = 1; f[p-1] = f[p] = -1; f[0] = 1; f[p-1] = f[p] = -1;
for (i = 0;i < p;++i) g[p-1-i] = in[i]; for (i = 0;i < p;++i) g[p-1-i] = in[i];
g[p] = 0; g[p] = 0;
delta = 1; delta = 1;
for (loop = 0;loop < 2*p-1;++loop) { for (loop = 0;loop < 2*p-1;++loop) {
for (i = p;i > 0;--i) v[i] = v[i-1]; for (i = p;i > 0;--i) v[i] = v[i-1];
v[0] = 0; v[0] = 0;
sign = -g[0]*f[0]; sign = -g[0]*f[0];
swap = int16_negative_mask(-delta) & int16_nonzero_mask(g[0]); swap = int16_negative_mask(-delta) & int16_nonzero_mask(g[0]);
delta ^= swap&(delta^-delta); delta ^= swap&(delta^-delta);
delta += 1; delta += 1;
for (i = 0;i < p+1;++i) { for (i = 0;i < p+1;++i) {
t = swap&(f[i]^g[i]); f[i] ^= t; g[i] ^= t; t = swap&(f[i]^g[i]); f[i] ^= t; g[i] ^= t;
t = swap&(v[i]^r[i]); v[i] ^= t; r[i] ^= t; t = swap&(v[i]^r[i]); v[i] ^= t; r[i] ^= t;
} }
for (i = 0;i < p+1;++i) g[i] = F3_freeze(g[i]+sign*f[i]); for (i = 0;i < p+1;++i) g[i] = F3_freeze(g[i]+sign*f[i]);
for (i = 0;i < p+1;++i) r[i] = F3_freeze(r[i]+sign*v[i]); for (i = 0;i < p+1;++i) r[i] = F3_freeze(r[i]+sign*v[i]);
for (i = 0;i < p;++i) g[i] = g[i+1]; for (i = 0;i < p;++i) g[i] = g[i+1];
g[p] = 0; g[p] = 0;
} }
sign = f[0]; sign = f[0];
for (i = 0;i < p;++i) out[i] = sign*v[p-1-i]; for (i = 0;i < p;++i) out[i] = sign*v[p-1-i];
return int16_nonzero_mask(delta); return int16_nonzero_mask(delta);
} }
#endif #endif
@ -603,14 +603,14 @@ static void Rq_mult_small(Fq *h,const Fq *f,const small *g)
static void Rq_mult3(Fq *h,const Fq *f) static void Rq_mult3(Fq *h,const Fq *f)
{ {
int i; int i;
for (i = 0;i < p;++i) h[i] = Fq_freeze(3*f[i]); for (i = 0;i < p;++i) h[i] = Fq_freeze(3*f[i]);
} }
/* out = 1/(3*in) in Rq */ /* out = 1/(3*in) in Rq */
/* returns 0 if recip succeeded; else -1 */ /* returns 0 if recip succeeded; else -1 */
static int Rq_recip3(Fq *out,const small *in) static int Rq_recip3(Fq *out,const small *in)
{ {
Fq f[p+1],g[p+1],v[p+1],r[p+1]; Fq f[p+1],g[p+1],v[p+1],r[p+1];
int i,loop,delta; int i,loop,delta;
int swap,t; int swap,t;
@ -739,7 +739,7 @@ static void KeyGen(Fq *h,small *f,small *ginv)
{ {
small g[p]; small g[p];
Fq finv[p]; Fq finv[p];
for (;;) { for (;;) {
Small_random(g); Small_random(g);
if (R3_recip(ginv,g) == 0) break; if (R3_recip(ginv,g) == 0) break;
@ -777,7 +777,7 @@ static void Decrypt(small *r,const Fq *c,const small *f,const small *ginv)
for (i = 0;i < w;++i) r[i] = ((ev[i]^1)&~mask)^1; for (i = 0;i < w;++i) r[i] = ((ev[i]^1)&~mask)^1;
for (i = w;i < p;++i) r[i] = ev[i]&~mask; for (i = w;i < p;++i) r[i] = ev[i]&~mask;
} }
#endif #endif
/* ----- NTRU LPRime Core */ /* ----- NTRU LPRime Core */
@ -817,7 +817,7 @@ static void Decrypt(int8 *r,const Fq *B,const int8 *T,const small *a)
for (i = 0;i < I;++i) for (i = 0;i < I;++i)
r[i] = -int16_negative_mask(Fq_freeze(Right(T[i])-aB[i]+4*w+1)); r[i] = -int16_negative_mask(Fq_freeze(Right(T[i])-aB[i]+4*w+1));
} }
#endif #endif
/* ----- encoding I-bit inputs */ /* ----- encoding I-bit inputs */
@ -898,7 +898,7 @@ static void HashShort(small *out,const Inputs r)
} }
#endif #endif
/* ----- NTRU LPRime Expand */ /* ----- NTRU LPRime Expand */
#ifdef LPR #ifdef LPR
@ -974,7 +974,7 @@ static void Rq_encode(unsigned char *s,const Fq *r)
{ {
uint16 R[p],M[p]; uint16 R[p],M[p];
int i; int i;
for (i = 0;i < p;++i) R[i] = r[i]+q12; for (i = 0;i < p;++i) R[i] = r[i]+q12;
for (i = 0;i < p;++i) M[i] = q; for (i = 0;i < p;++i) M[i] = q;
Encode(s,R,M,p); Encode(s,R,M,p);
@ -989,7 +989,7 @@ static void Rq_decode(Fq *r,const unsigned char *s)
Decode(R,s,M,p); Decode(R,s,M,p);
for (i = 0;i < p;++i) r[i] = ((Fq)R[i])-q12; for (i = 0;i < p;++i) r[i] = ((Fq)R[i])-q12;
} }
#endif #endif
/* ----- encoding rounded polynomials */ /* ----- encoding rounded polynomials */

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# $OpenBSD: sntrup761.sh,v 1.6 2022/12/26 19:16:03 jmc Exp $ # $OpenBSD: sntrup761.sh,v 1.7 2023/01/11 02:13:52 djm Exp $
# Placed in the Public Domain. # Placed in the Public Domain.
# #
AUTHOR="supercop-20201130/crypto_kem/sntrup761/ref/implementors" AUTHOR="supercop-20201130/crypto_kem/sntrup761/ref/implementors"
@ -54,6 +54,7 @@ for i in $FILES; do
-e "/^extern /d" \ -e "/^extern /d" \
-e '/CRYPTO_NAMESPACE/d' \ -e '/CRYPTO_NAMESPACE/d' \
-e "/^#define int32 crypto_int32/d" \ -e "/^#define int32 crypto_int32/d" \
-e 's/[ ]*$//' \
$i | \ $i | \
case "$i" in case "$i" in
# Use int64_t for intermediate values in int32_MINMAX to prevent signed # Use int64_t for intermediate values in int32_MINMAX to prevent signed