Debian Codegraph @

crypto_nP/montgomery25519/ref10/scalarmult.c

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