diff options
Diffstat (limited to 'nacl/curvecp/crypto_block.c')
-rw-r--r-- | nacl/curvecp/crypto_block.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/nacl/curvecp/crypto_block.c b/nacl/curvecp/crypto_block.c new file mode 100644 index 00000000..5c7cf35e --- /dev/null +++ b/nacl/curvecp/crypto_block.c | |||
@@ -0,0 +1,35 @@ | |||
1 | #include "crypto_block.h" | ||
2 | #include "crypto_uint64.h" | ||
3 | #include "uint64_unpack.h" | ||
4 | #include "uint64_pack.h" | ||
5 | |||
6 | /* | ||
7 | TEA with double-size words. | ||
8 | XXX: Switch to crypto_block_aes256. | ||
9 | XXX: Build crypto_stream_aes256 on top of crypto_block_aes256. | ||
10 | */ | ||
11 | |||
12 | int crypto_block( | ||
13 | unsigned char *out, | ||
14 | const unsigned char *in, | ||
15 | const unsigned char *k | ||
16 | ) | ||
17 | { | ||
18 | crypto_uint64 v0 = uint64_unpack(in + 0); | ||
19 | crypto_uint64 v1 = uint64_unpack(in + 8); | ||
20 | crypto_uint64 k0 = uint64_unpack(k + 0); | ||
21 | crypto_uint64 k1 = uint64_unpack(k + 8); | ||
22 | crypto_uint64 k2 = uint64_unpack(k + 16); | ||
23 | crypto_uint64 k3 = uint64_unpack(k + 24); | ||
24 | crypto_uint64 sum = 0; | ||
25 | crypto_uint64 delta = 0x9e3779b97f4a7c15; | ||
26 | int i; | ||
27 | for (i = 0;i < 32;++i) { | ||
28 | sum += delta; | ||
29 | v0 += ((v1<<7) + k0) ^ (v1 + sum) ^ ((v1>>12) + k1); | ||
30 | v1 += ((v0<<16) + k2) ^ (v0 + sum) ^ ((v0>>8) + k3); | ||
31 | } | ||
32 | uint64_pack(out + 0,v0); | ||
33 | uint64_pack(out + 8,v1); | ||
34 | return 0; | ||
35 | } | ||