mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-28 20:57:13 +09:00
More C89 compat
This commit is contained in:
+8
-5
@@ -100,11 +100,12 @@ void fe25519_unpack(fe25519 *r, const unsigned char x[32])
|
||||
void fe25519_pack(unsigned char r[32], const fe25519 *x)
|
||||
{
|
||||
int i;
|
||||
unsigned int m;
|
||||
for(i=0;i<32;i++)
|
||||
r[i] = x->v[i];
|
||||
|
||||
/* freeze byte array */
|
||||
unsigned int m = (r[31] == 127); /* XXX: some compilers might use branches; fix */
|
||||
m = (r[31] == 127); /* XXX: some compilers might use branches; fix */
|
||||
for(i=30;i>1;i--)
|
||||
m *= (r[i] == 255);
|
||||
m *= (r[0] >= 237);
|
||||
@@ -212,11 +213,12 @@ void fe25519_pow(fe25519 *r, const fe25519 *x, const unsigned char *e)
|
||||
for(i=0;i<32;i++) r->v[i] = g.v[i];
|
||||
*/
|
||||
fe25519 g;
|
||||
fe25519_setone(&g);
|
||||
int i,j,k;
|
||||
fe25519 pre[(1 << WINDOWSIZE)];
|
||||
fe25519 t;
|
||||
unsigned char w;
|
||||
fe25519 pre[(1 << WINDOWSIZE)];
|
||||
|
||||
fe25519_setone(&g);
|
||||
|
||||
// Precomputation
|
||||
fe25519_setone(pre);
|
||||
@@ -248,14 +250,15 @@ void fe25519_pow(fe25519 *r, const fe25519 *x, const unsigned char *e)
|
||||
/* Return 0 on success, 1 otherwise */
|
||||
int fe25519_sqrt_vartime(fe25519 *r, const fe25519 *x, unsigned char parity)
|
||||
{
|
||||
/* See HAC, Alg. 3.37 */
|
||||
if (!issquare(x)) return -1;
|
||||
unsigned char e[32] = {0xfb,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1f}; /* (p-1)/4 */
|
||||
unsigned char e2[32] = {0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0f}; /* (p+3)/8 */
|
||||
unsigned char e3[32] = {0xfd,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0f}; /* (p-5)/8 */
|
||||
fe25519 p = {{0}};
|
||||
fe25519 d;
|
||||
int i;
|
||||
|
||||
/* See HAC, Alg. 3.37 */
|
||||
if (!issquare(x)) return -1;
|
||||
fe25519_pow(&d,x,e);
|
||||
freeze(&d);
|
||||
if(isone(&d))
|
||||
|
||||
+9
-6
@@ -120,9 +120,11 @@ int ge25519_unpack_vartime(ge25519_p3 *r, const unsigned char p[32])
|
||||
{
|
||||
int ret;
|
||||
fe25519 t, fd;
|
||||
unsigned char par;
|
||||
|
||||
fe25519_setone(&r->z);
|
||||
fe25519_unpack(&fd, ecd);
|
||||
unsigned char par = p[31] >> 7;
|
||||
par = p[31] >> 7;
|
||||
fe25519_unpack(&r->y, p);
|
||||
fe25519_square(&r->x, &r->y);
|
||||
fe25519_mul(&t, &r->x, &fd);
|
||||
@@ -163,16 +165,17 @@ void ge25519_scalarmult(ge25519_p3 *r, const ge25519_p3 *p, const sc25519 *s)
|
||||
{
|
||||
int i,j,k;
|
||||
ge25519_p3 g;
|
||||
fe25519_unpack(&g.x, ge25519_neutral_x);
|
||||
fe25519_unpack(&g.y, ge25519_neutral_y);
|
||||
fe25519_unpack(&g.z, ge25519_neutral_z);
|
||||
fe25519_unpack(&g.t, ge25519_neutral_t);
|
||||
|
||||
ge25519_p3 pre[(1 << WINDOWSIZE)];
|
||||
ge25519_p3 t;
|
||||
ge25519_p1p1 tp1p1;
|
||||
unsigned char w;
|
||||
unsigned char sb[32];
|
||||
|
||||
fe25519_unpack(&g.x, ge25519_neutral_x);
|
||||
fe25519_unpack(&g.y, ge25519_neutral_y);
|
||||
fe25519_unpack(&g.z, ge25519_neutral_z);
|
||||
fe25519_unpack(&g.t, ge25519_neutral_t);
|
||||
|
||||
sc25519_to32bytes(sb, s);
|
||||
|
||||
// Precomputation
|
||||
|
||||
@@ -32,13 +32,14 @@ int crypto_stream_afternm(unsigned char *outp, unsigned long long len, const uns
|
||||
unsigned long long lensav;
|
||||
unsigned char bl[128];
|
||||
unsigned char *blp;
|
||||
unsigned char *np;
|
||||
unsigned char b;
|
||||
|
||||
uint32 tmp;
|
||||
|
||||
/* Copy nonce on the stack */
|
||||
copy2(&nonce_stack, (const int128 *) (noncep + 0));
|
||||
unsigned char *np = (unsigned char *)&nonce_stack;
|
||||
np = (unsigned char *)&nonce_stack;
|
||||
|
||||
enc_block:
|
||||
|
||||
|
||||
@@ -28,9 +28,12 @@ void copy2(int128 *r, const int128 *x)
|
||||
void shufb(int128 *r, const unsigned char *l)
|
||||
{
|
||||
int128 t;
|
||||
unsigned char *cr;
|
||||
unsigned char *ct;
|
||||
|
||||
copy2(&t,r);
|
||||
unsigned char *cr = (unsigned char *)r;
|
||||
unsigned char *ct = (unsigned char *)&t;
|
||||
cr = (unsigned char *)r;
|
||||
ct = (unsigned char *)&t;
|
||||
cr[0] = ct[l[0]];
|
||||
cr[1] = ct[l[1]];
|
||||
cr[2] = ct[l[2]];
|
||||
|
||||
@@ -33,13 +33,14 @@ int crypto_stream_xor_afternm(unsigned char *outp, const unsigned char *inp, uns
|
||||
unsigned long long lensav;
|
||||
unsigned char bl[128];
|
||||
unsigned char *blp;
|
||||
unsigned char *np;
|
||||
unsigned char b;
|
||||
|
||||
uint32 tmp;
|
||||
|
||||
/* Copy nonce on the stack */
|
||||
copy2(&nonce_stack, (const int128 *) (noncep + 0));
|
||||
unsigned char *np = (unsigned char *)&nonce_stack;
|
||||
np = (unsigned char *)&nonce_stack;
|
||||
|
||||
enc_block:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user