summaryrefslogtreecommitdiff
path: root/nacl/crypto_stream/aes128ctr/portable/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/crypto_stream/aes128ctr/portable/common.c')
-rw-r--r--nacl/crypto_stream/aes128ctr/portable/common.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/nacl/crypto_stream/aes128ctr/portable/common.c b/nacl/crypto_stream/aes128ctr/portable/common.c
new file mode 100644
index 00000000..14a28cc6
--- /dev/null
+++ b/nacl/crypto_stream/aes128ctr/portable/common.c
@@ -0,0 +1,64 @@
1#include "common.h"
2
3uint32 load32_bigendian(const unsigned char *x)
4{
5 return
6 (uint32) (x[3]) \
7 | (((uint32) (x[2])) << 8) \
8 | (((uint32) (x[1])) << 16) \
9 | (((uint32) (x[0])) << 24)
10 ;
11}
12
13void store32_bigendian(unsigned char *x,uint32 u)
14{
15 x[3] = u; u >>= 8;
16 x[2] = u; u >>= 8;
17 x[1] = u; u >>= 8;
18 x[0] = u;
19}
20
21uint32 load32_littleendian(const unsigned char *x)
22{
23 return
24 (uint32) (x[0]) \
25 | (((uint32) (x[1])) << 8) \
26 | (((uint32) (x[2])) << 16) \
27 | (((uint32) (x[3])) << 24)
28 ;
29}
30
31void store32_littleendian(unsigned char *x,uint32 u)
32{
33 x[0] = u; u >>= 8;
34 x[1] = u; u >>= 8;
35 x[2] = u; u >>= 8;
36 x[3] = u;
37}
38
39
40uint64 load64_littleendian(const unsigned char *x)
41{
42 return
43 (uint64) (x[0]) \
44 | (((uint64) (x[1])) << 8) \
45 | (((uint64) (x[2])) << 16) \
46 | (((uint64) (x[3])) << 24)
47 | (((uint64) (x[4])) << 32)
48 | (((uint64) (x[5])) << 40)
49 | (((uint64) (x[6])) << 48)
50 | (((uint64) (x[7])) << 56)
51 ;
52}
53
54void store64_littleendian(unsigned char *x,uint64 u)
55{
56 x[0] = u; u >>= 8;
57 x[1] = u; u >>= 8;
58 x[2] = u; u >>= 8;
59 x[3] = u; u >>= 8;
60 x[4] = u; u >>= 8;
61 x[5] = u; u >>= 8;
62 x[6] = u; u >>= 8;
63 x[7] = u;
64}