Debian Codegraph @

crypto_nG/merged25519/ref10/ge_scalarmult_base.c

raw symbols SCIP
1 // 20240926 djb: use crypto_int8, crypto_uint8
2
3 // linker define ge_scalarmult_base
4 // linker use base
5 // linker use fe_cmov
6 // linker use ge_precomp_0
7 // linker use fe_copy
8 // linker use fe_neg
9 // linker use ge_p3_0
10 // linker use ge_madd
11 // linker use ge_p1p1_to_p3
12 // linker use ge_p3_dbl
13 // linker use ge_p1p1_to_p2
14 // linker use ge_p2_dbl
15
16 #include "ge.h"
17 #include "B.h"
18 #include "crypto_int8.h"
19 #include "crypto_uint8.h"
20
21 static void cmov(ge_precomp *t,const ge_precomp *u,unsigned char b)
22 {
23 fe_cmov(t->yplusx,u->yplusx,b);
24 fe_cmov(t->yminusx,u->yminusx,b);
25 fe_cmov(t->xy2d,u->xy2d,b);
26 }
27
28 static void select(ge_precomp *t,int pos,signed char b)
29 {
30 ge_precomp minust;
31 unsigned char bnegative = crypto_int8_negative_01(b);
32 unsigned char babs = b - (((-bnegative) & b) << 1);
33
34 ge_precomp_0(t);
35 cmov(t,&base[pos][0],crypto_uint8_equal_01(babs,1));
36 cmov(t,&base[pos][1],crypto_uint8_equal_01(babs,2));
37 cmov(t,&base[pos][2],crypto_uint8_equal_01(babs,3));
38 cmov(t,&base[pos][3],crypto_uint8_equal_01(babs,4));
39 cmov(t,&base[pos][4],crypto_uint8_equal_01(babs,5));
40 cmov(t,&base[pos][5],crypto_uint8_equal_01(babs,6));
41 cmov(t,&base[pos][6],crypto_uint8_equal_01(babs,7));
42 cmov(t,&base[pos][7],crypto_uint8_equal_01(babs,8));
43 fe_copy(minust.yplusx,t->yminusx);
44 fe_copy(minust.yminusx,t->yplusx);
45 fe_neg(minust.xy2d,t->xy2d);
46 cmov(t,&minust,bnegative);
47 }
48
49 /*
50 h = a * B
51 where a = a[0]+256*a[1]+...+256^31 a[31]
52 B is the Ed25519 base point (x,4/5) with x positive.
53
54 Preconditions:
55 a[31] <= 127
56 */
57
58 void ge_scalarmult_base(ge_p3 *h,const unsigned char *a)
59 {
60 signed char e[64];
61 signed char carry;
62 ge_p1p1 r;
63 ge_p2 s;
64 ge_precomp t;
65 int i;
66
67 for (i = 0;i < 32;++i) {
68 e[2 * i + 0] = (a[i] >> 0) & 15;
69 e[2 * i + 1] = (a[i] >> 4) & 15;
70 }
71 /* each e[i] is between 0 and 15 */
72 /* e[63] is between 0 and 7 */
73
74 carry = 0;
75 for (i = 0;i < 63;++i) {
76 e[i] += carry;
77 carry = e[i] + 8;
78 carry >>= 4;
79 e[i] -= carry << 4;
80 }
81 e[63] += carry;
82 /* each e[i] is between -8 and 8 */
83
84 ge_p3_0(h);
85 for (i = 1;i < 64;i += 2) {
86 select(&t,i / 2,e[i]);
87 ge_madd(&r,h,&t); ge_p1p1_to_p3(h,&r);
88 }
89
90 ge_p3_dbl(&r,h); ge_p1p1_to_p2(&s,&r);
91 ge_p2_dbl(&r,&s); ge_p1p1_to_p2(&s,&r);
92 ge_p2_dbl(&r,&s); ge_p1p1_to_p2(&s,&r);
93 ge_p2_dbl(&r,&s); ge_p1p1_to_p3(h,&r);
94
95 for (i = 0;i < 64;i += 2) {
96 select(&t,i / 2,e[i]);
97 ge_madd(&r,h,&t); ge_p1p1_to_p3(h,&r);
98 }
99 }