Debian Codegraph @

ref10/crypto_scalarmult/scalarmult.c

raw symbols SCIP
1 #include "crypto_scalarmult.h"
2 #include "fe.h"
3
4 int crypto_scalarmult(unsigned char *q,
5 const unsigned char *n,
6 const unsigned char *p)
7 {
8 unsigned char e[32];
9 unsigned int i;
10 fe x1;
11 fe x2;
12 fe z2;
13 fe x3;
14 fe z3;
15 fe tmp0;
16 fe tmp1;
17 int pos;
18 unsigned int swap;
19 unsigned int b;
20
21 for (i = 0;i < 32;++i) e[i] = n[i];
22 e[0] &= 248;
23 e[31] &= 127;
24 e[31] |= 64;
25 fe_frombytes(x1,p);
26 fe_1(x2);
27 fe_0(z2);
28 fe_copy(x3,x1);
29 fe_1(z3);
30
31 swap = 0;
32 for (pos = 254;pos >= 0;--pos) {
33 b = e[pos / 8] >> (pos & 7);
34 b &= 1;
35 swap ^= b;
36 fe_cswap(x2,x3,swap);
37 fe_cswap(z2,z3,swap);
38 swap = b;
39 #include "montgomery.h"
40 }
41 fe_cswap(x2,x3,swap);
42 fe_cswap(z2,z3,swap);
43
44 fe_invert(z2,z2);
45 fe_mul(x2,x2,z2);
46 fe_tobytes(q,x2);
47 return 0;
48 }