]> pd.if.org Git - zpackage/blob - crypto/ref10/fe_frombytes.c
remove stray debug fprintf
[zpackage] / crypto / ref10 / fe_frombytes.c
1 #include <stdint.h>
2
3 static uint64_t load_3(const unsigned char *in) {
4         uint64_t result;
5         result = (uint64_t) in[0];
6         result |= ((uint64_t) in[1]) << 8;
7         result |= ((uint64_t) in[2]) << 16;
8         return result;
9 }
10
11 static uint64_t load_4(const unsigned char *in) {
12         uint64_t result;
13         result = (uint64_t) in[0];
14         result |= ((uint64_t) in[1]) << 8;
15         result |= ((uint64_t) in[2]) << 16;
16         result |= ((uint64_t) in[3]) << 24;
17         return result;
18 }
19
20 void fe_frombytes(uint32_t h[10], const unsigned char *s) {
21         int64_t h0 = load_4(s);
22         int64_t h1 = load_3(s + 4) << 6;
23         int64_t h2 = load_3(s + 7) << 5;
24         int64_t h3 = load_3(s + 10) << 3;
25         int64_t h4 = load_3(s + 13) << 2;
26         int64_t h5 = load_4(s + 16);
27         int64_t h6 = load_3(s + 20) << 7;
28         int64_t h7 = load_3(s + 23) << 5;
29         int64_t h8 = load_3(s + 26) << 4;
30         int64_t h9 = (load_3(s + 29) & 8388607) << 2;
31         int64_t carry0;
32         int64_t carry1;
33         int64_t carry2;
34         int64_t carry3;
35         int64_t carry4;
36         int64_t carry5;
37         int64_t carry6;
38         int64_t carry7;
39         int64_t carry8;
40         int64_t carry9;
41
42         carry9 = (h9 + (int64_t) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
43         carry1 = (h1 + (int64_t) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
44         carry3 = (h3 + (int64_t) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
45         carry5 = (h5 + (int64_t) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
46         carry7 = (h7 + (int64_t) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25;
47
48         carry0 = (h0 + (int64_t) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
49         carry2 = (h2 + (int64_t) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
50         carry4 = (h4 + (int64_t) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
51         carry6 = (h6 + (int64_t) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
52         carry8 = (h8 + (int64_t) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26;
53
54         h[0] = h0;
55         h[1] = h1;
56         h[2] = h2;
57         h[3] = h3;
58         h[4] = h4;
59         h[5] = h5;
60         h[6] = h6;
61         h[7] = h7;
62         h[8] = h8;
63         h[9] = h9;
64 }