libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / libsodium / src / libsodium / crypto_stream / aes128ctr / portable / int128_aes128ctr.c
blob25894d422cf6a9d253b766680c45fd697ca3186d
1 #include "int128.h"
2 #include "common.h"
4 void xor2(int128 *r, const int128 *x)
6 r->a ^= x->a;
7 r->b ^= x->b;
10 void and2(int128 *r, const int128 *x)
12 r->a &= x->a;
13 r->b &= x->b;
16 void or2(int128 *r, const int128 *x)
18 r->a |= x->a;
19 r->b |= x->b;
22 void copy2(int128 *r, const int128 *x)
24 r->a = x->a;
25 r->b = x->b;
28 void shufb(int128 *r, const unsigned char *l)
30 int128 t;
31 copy2(&t,r);
32 unsigned char *cr = (unsigned char *)r;
33 unsigned char *ct = (unsigned char *)&t;
34 cr[0] = ct[l[0]];
35 cr[1] = ct[l[1]];
36 cr[2] = ct[l[2]];
37 cr[3] = ct[l[3]];
38 cr[4] = ct[l[4]];
39 cr[5] = ct[l[5]];
40 cr[6] = ct[l[6]];
41 cr[7] = ct[l[7]];
42 cr[8] = ct[l[8]];
43 cr[9] = ct[l[9]];
44 cr[10] = ct[l[10]];
45 cr[11] = ct[l[11]];
46 cr[12] = ct[l[12]];
47 cr[13] = ct[l[13]];
48 cr[14] = ct[l[14]];
49 cr[15] = ct[l[15]];
52 void shufd(int128 *r, const int128 *x, const unsigned int c)
54 int128 t;
55 uint32 *tp = (uint32 *)&t;
56 uint32 *xp = (uint32 *)x;
57 tp[0] = xp[c&3];
58 tp[1] = xp[(c>>2)&3];
59 tp[2] = xp[(c>>4)&3];
60 tp[3] = xp[(c>>6)&3];
61 copy2(r,&t);
64 void rshift32_littleendian(int128 *r, const unsigned int n)
66 unsigned char *rp = (unsigned char *)r;
67 uint32 t;
68 t = load32_littleendian(rp);
69 t >>= n;
70 store32_littleendian(rp, t);
71 t = load32_littleendian(rp+4);
72 t >>= n;
73 store32_littleendian(rp+4, t);
74 t = load32_littleendian(rp+8);
75 t >>= n;
76 store32_littleendian(rp+8, t);
77 t = load32_littleendian(rp+12);
78 t >>= n;
79 store32_littleendian(rp+12, t);
82 void rshift64_littleendian(int128 *r, const unsigned int n)
84 unsigned char *rp = (unsigned char *)r;
85 uint64 t;
86 t = load64_littleendian(rp);
87 t >>= n;
88 store64_littleendian(rp, t);
89 t = load64_littleendian(rp+8);
90 t >>= n;
91 store64_littleendian(rp+8, t);
94 void lshift64_littleendian(int128 *r, const unsigned int n)
96 unsigned char *rp = (unsigned char *)r;
97 uint64 t;
98 t = load64_littleendian(rp);
99 t <<= n;
100 store64_littleendian(rp, t);
101 t = load64_littleendian(rp+8);
102 t <<= n;
103 store64_littleendian(rp+8, t);
106 void toggle(int128 *r)
108 r->a ^= 0xffffffffffffffffULL;
109 r->b ^= 0xffffffffffffffffULL;
112 void xor_rcon(int128 *r)
114 unsigned char *rp = (unsigned char *)r;
115 uint32 t;
116 t = load32_littleendian(rp+12);
117 t ^= 0xffffffff;
118 store32_littleendian(rp+12, t);
121 void add_uint32_big(int128 *r, uint32 x)
123 unsigned char *rp = (unsigned char *)r;
124 uint32 t;
125 t = load32_littleendian(rp+12);
126 t += x;
127 store32_littleendian(rp+12, t);