libsodium: updated to 1.0.10
[tomato.git] / release / src / router / libsodium / src / libsodium / crypto_scalarmult / curve25519 / sandy2x / fe_frombytes_sandy2x.c
blobf1a29a34f4a6e16b3b7344825f36aeb454655ae2
1 /*
2 This file is basically ref10/fe_frombytes.h.
3 */
5 #include "fe.h"
7 #ifdef HAVE_AVX_ASM
9 static uint64_t load_3(const unsigned char *in)
11 uint64_t result;
12 result = (uint64_t) in[0];
13 result |= ((uint64_t) in[1]) << 8;
14 result |= ((uint64_t) in[2]) << 16;
15 return result;
18 static uint64_t load_4(const unsigned char *in)
20 uint64_t result;
21 result = (uint64_t) in[0];
22 result |= ((uint64_t) in[1]) << 8;
23 result |= ((uint64_t) in[2]) << 16;
24 result |= ((uint64_t) in[3]) << 24;
25 return result;
28 void fe_frombytes(fe h,const unsigned char *s)
30 uint64_t h0 = load_4(s);
31 uint64_t h1 = load_3(s + 4) << 6;
32 uint64_t h2 = load_3(s + 7) << 5;
33 uint64_t h3 = load_3(s + 10) << 3;
34 uint64_t h4 = load_3(s + 13) << 2;
35 uint64_t h5 = load_4(s + 16);
36 uint64_t h6 = load_3(s + 20) << 7;
37 uint64_t h7 = load_3(s + 23) << 5;
38 uint64_t h8 = load_3(s + 26) << 4;
39 uint64_t h9 = (load_3(s + 29) & 8388607) << 2;
40 uint64_t carry0;
41 uint64_t carry1;
42 uint64_t carry2;
43 uint64_t carry3;
44 uint64_t carry4;
45 uint64_t carry5;
46 uint64_t carry6;
47 uint64_t carry7;
48 uint64_t carry8;
49 uint64_t carry9;
51 carry9 = h9 >> 25; h0 += carry9 * 19; h9 &= 0x1FFFFFF;
52 carry1 = h1 >> 25; h2 += carry1; h1 &= 0x1FFFFFF;
53 carry3 = h3 >> 25; h4 += carry3; h3 &= 0x1FFFFFF;
54 carry5 = h5 >> 25; h6 += carry5; h5 &= 0x1FFFFFF;
55 carry7 = h7 >> 25; h8 += carry7; h7 &= 0x1FFFFFF;
57 carry0 = h0 >> 26; h1 += carry0; h0 &= 0x3FFFFFF;
58 carry2 = h2 >> 26; h3 += carry2; h2 &= 0x3FFFFFF;
59 carry4 = h4 >> 26; h5 += carry4; h4 &= 0x3FFFFFF;
60 carry6 = h6 >> 26; h7 += carry6; h6 &= 0x3FFFFFF;
61 carry8 = h8 >> 26; h9 += carry8; h8 &= 0x3FFFFFF;
63 h[0] = h0;
64 h[1] = h1;
65 h[2] = h2;
66 h[3] = h3;
67 h[4] = h4;
68 h[5] = h5;
69 h[6] = h6;
70 h[7] = h7;
71 h[8] = h8;
72 h[9] = h9;
75 #endif