Debian Codegraph @

crypto_encode/953xfreeze3/ref/encode.c

raw
1 // 20250302 djb: port to -Wc++-compat
2 #include "crypto_encode.h"
3 #include "crypto_int16.h"
4 #define int16 crypto_int16
5
6 #define p 953
7
8 /* valid inputs: -16384 <= x < 16384 */
9 /* then 3 divides x-F3_freeze(x) */
10 /* and F3_freeze(x) is in {-1,0,1} */
11
12 /* all inputs: 3 divides x-F3_freeze(x) */
13 /* and F3_freeze(x) is in {-2,-1,0,1,2} */
14
15 static inline char F3_freeze(int16 x)
16 {
17 return x-3*((10923*x+16384)>>15);
18 }
19
20 void crypto_encode(unsigned char *s,const void *v)
21 {
22 const int16 *r = (const int16 *) v;
23
24 int i;
25 for (i = 0;i < p;++i)
26 s[i] = F3_freeze(r[i]);
27 }