Debian Codegraph @

crypto_pow/inv25519/sandy2x/fe_frombytes.c

raw
1 // linker define fe_frombytes
2
3 /*
4 This file is basically ref10/fe_frombytes.h.
5 */
6
7 #include "fe.h"
8 #include "crypto_uint64.h"
9
10 static crypto_uint64 load_3(const unsigned char *in)
11 {
12 crypto_uint64 result;
13 result = (crypto_uint64) in[0];
14 result |= ((crypto_uint64) in[1]) << 8;
15 result |= ((crypto_uint64) in[2]) << 16;
16 return result;
17 }
18
19 static crypto_uint64 load_4(const unsigned char *in)
20 {
21 crypto_uint64 result;
22 result = (crypto_uint64) in[0];
23 result |= ((crypto_uint64) in[1]) << 8;
24 result |= ((crypto_uint64) in[2]) << 16;
25 result |= ((crypto_uint64) in[3]) << 24;
26 return result;
27 }
28
29 void fe_frombytes(fe h,const unsigned char *s)
30 {
31 crypto_uint64 h0 = load_4(s);
32 crypto_uint64 h1 = load_3(s + 4) << 6;
33 crypto_uint64 h2 = load_3(s + 7) << 5;
34 crypto_uint64 h3 = load_3(s + 10) << 3;
35 crypto_uint64 h4 = load_3(s + 13) << 2;
36 crypto_uint64 h5 = load_4(s + 16);
37 crypto_uint64 h6 = load_3(s + 20) << 7;
38 crypto_uint64 h7 = load_3(s + 23) << 5;
39 crypto_uint64 h8 = load_3(s + 26) << 4;
40 crypto_uint64 h9 = (load_3(s + 29) & 8388607) << 2;
41 crypto_uint64 carry0;
42 crypto_uint64 carry1;
43 crypto_uint64 carry2;
44 crypto_uint64 carry3;
45 crypto_uint64 carry4;
46 crypto_uint64 carry5;
47 crypto_uint64 carry6;
48 crypto_uint64 carry7;
49 crypto_uint64 carry8;
50 crypto_uint64 carry9;
51
52 carry9 = h9 >> 25; h0 += carry9 * 19; h9 &= 0x1FFFFFF;
53 carry1 = h1 >> 25; h2 += carry1; h1 &= 0x1FFFFFF;
54 carry3 = h3 >> 25; h4 += carry3; h3 &= 0x1FFFFFF;
55 carry5 = h5 >> 25; h6 += carry5; h5 &= 0x1FFFFFF;
56 carry7 = h7 >> 25; h8 += carry7; h7 &= 0x1FFFFFF;
57
58 carry0 = h0 >> 26; h1 += carry0; h0 &= 0x3FFFFFF;
59 carry2 = h2 >> 26; h3 += carry2; h2 &= 0x3FFFFFF;
60 carry4 = h4 >> 26; h5 += carry4; h4 &= 0x3FFFFFF;
61 carry6 = h6 >> 26; h7 += carry6; h6 &= 0x3FFFFFF;
62 carry8 = h8 >> 26; h9 += carry8; h8 &= 0x3FFFFFF;
63
64 h[0] = h0;
65 h[1] = h1;
66 h[2] = h2;
67 h[3] = h3;
68 h[4] = h4;
69 h[5] = h5;
70 h[6] = h6;
71 h[7] = h7;
72 h[8] = h8;
73 h[9] = h9;
74 }