Debian Codegraph @

crypto_nP/montgomery25519/sandy2x/scalarmult.c

raw symbols SCIP
1 /*
2 This file is adapted from ref10/scalarmult.c:
3 The code for Mongomery ladder is replace by the ladder assembly function;
4 Inversion is done in the same way as amd64-51/.
5 (fe is first converted into fe51 after Mongomery ladder)
6 */
7
8 #include "crypto_nP.h"
9
10 #include "fe.h"
11 #include "fe51.h"
12 #include "ladder.h"
13
14 #define x1 var[0]
15 #define x2 var[1]
16 #define z2 var[2]
17
18 void crypto_nP(unsigned char *q,
19 const unsigned char *n,
20 const unsigned char *p)
21 {
22 unsigned char e[32];
23 unsigned int i;
24
25 fe var[3];
26
27 fe51 x_51;
28 fe51 z_51;
29
30 for (i = 0;i < 32;++i) e[i] = n[i];
31 e[0] &= 248;
32 e[31] &= 127;
33 e[31] |= 64;
34
35 fe_frombytes(x1, p);
36
37 ladder(var, e);
38
39 z_51.v[0] = (z2[1] << 26) + z2[0];
40 z_51.v[1] = (z2[3] << 26) + z2[2];
41 z_51.v[2] = (z2[5] << 26) + z2[4];
42 z_51.v[3] = (z2[7] << 26) + z2[6];
43 z_51.v[4] = (z2[9] << 26) + z2[8];
44
45 x_51.v[0] = (x2[1] << 26) + x2[0];
46 x_51.v[1] = (x2[3] << 26) + x2[2];
47 x_51.v[2] = (x2[5] << 26) + x2[4];
48 x_51.v[3] = (x2[7] << 26) + x2[6];
49 x_51.v[4] = (x2[9] << 26) + x2[8];
50
51 fe51_invert(&z_51, &z_51);
52 fe51_mul(&x_51, &x_51, &z_51);
53 fe51_pack(q, &x_51);
54 }
55