sha3-ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/ext/sha3/KeccakReferenceAndOptimized/KeccakCompact.vcproj +207 -0
- data/ext/sha3/KeccakReferenceAndOptimized/KeccakCompact8.vcproj +207 -0
- data/ext/sha3/KeccakReferenceAndOptimized/KeccakInplace.vcproj +203 -0
- data/ext/sha3/KeccakReferenceAndOptimized/KeccakInplace32BI.vcproj +201 -0
- data/ext/sha3/KeccakReferenceAndOptimized/KeccakOptimized32.vcproj +267 -0
- data/ext/sha3/KeccakReferenceAndOptimized/KeccakOptimized64.vcproj +267 -0
- data/ext/sha3/KeccakReferenceAndOptimized/KeccakReference.vcproj +243 -0
- data/ext/sha3/KeccakReferenceAndOptimized/KeccakReference32BI.vcproj +243 -0
- data/ext/sha3/KeccakReferenceAndOptimized/KeccakReferenceAndOptimized.sln +62 -0
- data/ext/sha3/KeccakReferenceAndOptimized/KeccakSimple.vcproj +203 -0
- data/ext/sha3/KeccakReferenceAndOptimized/KeccakSimple32BI.vcproj +201 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/AVR8-rotate64.h +27 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/AVR8-rotate64.s +285 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-avr8-settings.h +2 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-avr8-test.c +142 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-avr8-util.h +15 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-avr8-util.s +119 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-avr8.c +184 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-avr8.h +25 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact-settings.h +3 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact-test.c +317 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact.c +341 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact.h +50 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact8-settings.h +2 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact8-test.c +192 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact8.c +375 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-compact8.h +47 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-crypto_hash-inplace-armgcc-ARMv7A-NEON.s +406 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace-minimal-test.c +231 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace-settings.h +3 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace-test.c +221 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace.c +445 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace32BI-armgcc-ARMv6M.s +844 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace32BI-armgcc-ARMv7A.s +687 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace32BI-armgcc-ARMv7M.s +687 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-inplace32BI.c +849 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-simple-settings.h +3 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-simple-test.c +221 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-simple.c +403 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccak-simple32BI.c +673 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakDuplex.c +68 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakDuplex.h +59 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-32-rvk.macros +555 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-32-s1.macros +1187 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-32-s2.macros +1187 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-32.macros +26 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-64.macros +728 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-arm.c +123 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-armcc.s +653 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-armgcc.s +686 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-avr8.c +163 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-avr8asm-compact.s +647 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-avr8asm-fast.s +934 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-inplace-armgcc-ARMv7A-NEON.s +446 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-int-set.h +6 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-interface.h +46 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-opt32-settings.h +4 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-opt32.c +524 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-opt64-settings.h +7 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-opt64.c +504 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-reference.c +300 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-reference.h +20 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-reference.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-reference32BI.c +371 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-simd128.macros +651 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-simd64.macros +517 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-unrolling.macros +124 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-x86-64-asm.c +62 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-x86-64-gas.s +766 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-x86-64-shld-gas.s +766 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakF-1600-xop.macros +573 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakNISTInterface.c +81 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakNISTInterface.h +70 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakNISTInterface.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakSponge.c +266 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakSponge.h +76 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/KeccakSponge.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccakc1024-crypto_hash-inplace-armgcc-ARMv7A-NEON.s +296 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/Keccakc512-crypto_hash-inplace-armgcc-ARMv7A-NEON.s +429 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/brg_endian.h +142 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/crypto_hash.h +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/displayIntermediateValues.c +117 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/displayIntermediateValues.h +29 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/displayIntermediateValues.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/genKAT.c +692 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/mainARM.c +88 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/mainOptimized.c +23 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/mainReference.c +381 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/timing.c +436 -0
- data/ext/sha3/KeccakReferenceAndOptimized/Sources/timing.h +13 -0
- data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/DoublePermutation-config.h +2 -0
- data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/DoublePermutation.c +572 -0
- data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/DoublePermutation.h +38 -0
- data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/KeccakF-1600-unrolling.macros +124 -0
- data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/Keccakc256TreeD2.c +81 -0
- data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/Keccakc256TreeD2.h +18 -0
- data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/Keccakc512TreeD2.c +81 -0
- data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/Keccakc512TreeD2.h +18 -0
- data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/crypto_hash.h +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/mainOptimized.c +112 -0
- data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/timing-Double.c +225 -0
- data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/Sources/timing-Double.h +20 -0
- data/ext/sha3/KeccakReferenceAndOptimized/TreeHashing/makefile +68 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakCompact +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakOptimized32 +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakOptimized64 +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakReference +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakReference32BI +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakSimple +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/KeccakSimple32BI +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/compact/Keccak-compact-test.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/compact/Keccak-compact.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/KeccakDuplex.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/KeccakF-1600-opt32.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/KeccakNISTInterface.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/KeccakSponge.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/genKAT.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/mainOptimized.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized32/timing.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/KeccakDuplex.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/KeccakF-1600-opt64.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/KeccakNISTInterface.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/KeccakSponge.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/genKAT.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/mainOptimized.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/optimized64/timing.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/KeccakDuplex.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/KeccakF-1600-reference.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/KeccakNISTInterface.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/KeccakSponge.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/displayIntermediateValues.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/genKAT.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference/mainReference.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/KeccakDuplex.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/KeccakF-1600-reference32BI.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/KeccakNISTInterface.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/KeccakSponge.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/displayIntermediateValues.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/genKAT.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/reference32bi/mainReference.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/simple/Keccak-simple-test.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/simple/Keccak-simple.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/simple32BI/Keccak-simple-test.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/bin/simple32BI/Keccak-simple32BI.o +0 -0
- data/ext/sha3/KeccakReferenceAndOptimized/compile64.bat +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccak +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc1024 +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc256 +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc256treed2 +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc448 +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc512 +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc512treed2 +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/checksum-keccakc768 +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/hash-keccak.c +11 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/hash-keccakc1024.c +11 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/hash-keccakc256.c +11 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/hash-keccakc448.c +11 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/hash-keccakc512.c +11 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/hash-keccakc768.c +11 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/int-set-keccak.h +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/int-set-keccakc1024.h +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/int-set-keccakc256.h +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/int-set-keccakc448.h +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/int-set-keccakc512.h +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/int-set-keccakc768.h +1 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/populate.py +506 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/simple-keccak.h +2 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/simple-keccakc1024.h +2 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/simple-keccakc256.h +2 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/simple-keccakc448.h +2 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/simple-keccakc512.h +2 -0
- data/ext/sha3/KeccakReferenceAndOptimized/eBASH/simple-keccakc768.h +2 -0
- data/ext/sha3/KeccakReferenceAndOptimized/makefile +327 -0
- data/ext/sha3/Makefile +240 -0
- data/ext/sha3/depend +28 -0
- data/ext/sha3/extconf.rb +21 -0
- data/ext/sha3/sha3.c +95 -0
- data/lib/sha3-ruby.rb +27 -0
- data/lib/sha3-ruby/version.rb +5 -0
- data/sha3-ruby.gemspec +21 -0
- metadata +233 -0
@@ -0,0 +1,445 @@
|
|
1
|
+
/*
|
2
|
+
The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
|
3
|
+
Michaël Peeters and Gilles Van Assche. For more information, feedback or
|
4
|
+
questions, please refer to our website: http://keccak.noekeon.org/
|
5
|
+
|
6
|
+
Implementation by Ronny Van Keer and the designers,
|
7
|
+
hereby denoted as "the implementer".
|
8
|
+
|
9
|
+
To the extent possible under law, the implementer has waived all copyright
|
10
|
+
and related or neighboring rights to the source code in this file.
|
11
|
+
http://creativecommons.org/publicdomain/zero/1.0/
|
12
|
+
*/
|
13
|
+
|
14
|
+
// WARNING: This implementation assumes a little-endian platform. Support for big-endinanness is not yet implemented.
|
15
|
+
|
16
|
+
#include <string.h>
|
17
|
+
#include "Keccak-inplace-settings.h"
|
18
|
+
#define cKeccakR_SizeInBytes (cKeccakR / 8)
|
19
|
+
#include "crypto_hash.h"
|
20
|
+
#ifndef crypto_hash_BYTES
|
21
|
+
#ifdef cKeccakFixedOutputLengthInBytes
|
22
|
+
#define crypto_hash_BYTES cKeccakFixedOutputLengthInBytes
|
23
|
+
#else
|
24
|
+
#define crypto_hash_BYTES cKeccakR_SizeInBytes
|
25
|
+
#endif
|
26
|
+
#endif
|
27
|
+
#if (crypto_hash_BYTES > cKeccakR_SizeInBytes)
|
28
|
+
#error "Full squeezing not yet implemented"
|
29
|
+
#endif
|
30
|
+
|
31
|
+
#if (cKeccakB == 1600)
|
32
|
+
typedef unsigned long long UINT64;
|
33
|
+
typedef UINT64 tKeccakLane;
|
34
|
+
#define cKeccakNumberOfRounds 24
|
35
|
+
#else
|
36
|
+
#error "Unsupported Keccak-f width"
|
37
|
+
#endif
|
38
|
+
|
39
|
+
#define cKeccakLaneSizeInBits (sizeof(tKeccakLane) * 8)
|
40
|
+
|
41
|
+
#define ROL64(a, offset) ((((tKeccakLane)a) << ((offset) % cKeccakLaneSizeInBits)) ^ (((tKeccakLane)a) >> (cKeccakLaneSizeInBits-((offset) % cKeccakLaneSizeInBits))))
|
42
|
+
void KeccakF( tKeccakLane * state, const tKeccakLane *in, int laneCount );
|
43
|
+
|
44
|
+
int crypto_hash( unsigned char *out, const unsigned char *in, unsigned long long inlen )
|
45
|
+
{
|
46
|
+
tKeccakLane state[5 * 5];
|
47
|
+
#if (crypto_hash_BYTES >= cKeccakR_SizeInBytes)
|
48
|
+
#define temp out
|
49
|
+
#else
|
50
|
+
unsigned char temp[cKeccakR_SizeInBytes];
|
51
|
+
#endif
|
52
|
+
|
53
|
+
memset( state, 0, sizeof(state) );
|
54
|
+
|
55
|
+
for ( /* empty */; inlen >= cKeccakR_SizeInBytes; inlen -= cKeccakR_SizeInBytes, in += cKeccakR_SizeInBytes )
|
56
|
+
{
|
57
|
+
KeccakF( state, (const tKeccakLane*)in, cKeccakR_SizeInBytes / sizeof(tKeccakLane) );
|
58
|
+
}
|
59
|
+
|
60
|
+
// padding
|
61
|
+
memcpy( temp, in, (size_t)inlen );
|
62
|
+
temp[inlen++] = 1;
|
63
|
+
memset( temp+inlen, 0, cKeccakR_SizeInBytes - (size_t)inlen );
|
64
|
+
temp[cKeccakR_SizeInBytes-1] |= 0x80;
|
65
|
+
KeccakF( state, (const tKeccakLane*)temp, cKeccakR_SizeInBytes / sizeof(tKeccakLane) );
|
66
|
+
memcpy( out, state, crypto_hash_BYTES );
|
67
|
+
#if (crypto_hash_BYTES >= cKeccakR_SizeInBytes)
|
68
|
+
#undef temp
|
69
|
+
#endif
|
70
|
+
|
71
|
+
return ( 0 );
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
const tKeccakLane KeccakF1600RoundConstants[cKeccakNumberOfRounds] =
|
76
|
+
{
|
77
|
+
(tKeccakLane)0x0000000000000001ULL,
|
78
|
+
(tKeccakLane)0x0000000000008082ULL,
|
79
|
+
(tKeccakLane)0x800000000000808aULL,
|
80
|
+
(tKeccakLane)0x8000000080008000ULL,
|
81
|
+
(tKeccakLane)0x000000000000808bULL,
|
82
|
+
(tKeccakLane)0x0000000080000001ULL,
|
83
|
+
(tKeccakLane)0x8000000080008081ULL,
|
84
|
+
(tKeccakLane)0x8000000000008009ULL,
|
85
|
+
(tKeccakLane)0x000000000000008aULL,
|
86
|
+
(tKeccakLane)0x0000000000000088ULL,
|
87
|
+
(tKeccakLane)0x0000000080008009ULL,
|
88
|
+
(tKeccakLane)0x000000008000000aULL,
|
89
|
+
(tKeccakLane)0x000000008000808bULL,
|
90
|
+
(tKeccakLane)0x800000000000008bULL,
|
91
|
+
(tKeccakLane)0x8000000000008089ULL,
|
92
|
+
(tKeccakLane)0x8000000000008003ULL,
|
93
|
+
(tKeccakLane)0x8000000000008002ULL,
|
94
|
+
(tKeccakLane)0x8000000000000080ULL,
|
95
|
+
(tKeccakLane)0x000000000000800aULL,
|
96
|
+
(tKeccakLane)0x800000008000000aULL,
|
97
|
+
(tKeccakLane)0x8000000080008081ULL,
|
98
|
+
(tKeccakLane)0x8000000000008080ULL,
|
99
|
+
(tKeccakLane)0x0000000080000001ULL,
|
100
|
+
(tKeccakLane)0x8000000080008008ULL
|
101
|
+
};
|
102
|
+
|
103
|
+
void KeccakF( tKeccakLane * state, const tKeccakLane *in, int laneCount )
|
104
|
+
{
|
105
|
+
|
106
|
+
{
|
107
|
+
while ( --laneCount >= 0 )
|
108
|
+
{
|
109
|
+
state[laneCount] ^= in[laneCount];
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
{
|
114
|
+
tKeccakLane Ba, Be, Bi, Bo, Bu;
|
115
|
+
tKeccakLane Ca, Ce, Ci, Co, Cu;
|
116
|
+
tKeccakLane Da, De, Di, Do, Du;
|
117
|
+
#define i laneCount
|
118
|
+
|
119
|
+
#define Aba state[ 0]
|
120
|
+
#define Abe state[ 1]
|
121
|
+
#define Abi state[ 2]
|
122
|
+
#define Abo state[ 3]
|
123
|
+
#define Abu state[ 4]
|
124
|
+
#define Aga state[ 5]
|
125
|
+
#define Age state[ 6]
|
126
|
+
#define Agi state[ 7]
|
127
|
+
#define Ago state[ 8]
|
128
|
+
#define Agu state[ 9]
|
129
|
+
#define Aka state[10]
|
130
|
+
#define Ake state[11]
|
131
|
+
#define Aki state[12]
|
132
|
+
#define Ako state[13]
|
133
|
+
#define Aku state[14]
|
134
|
+
#define Ama state[15]
|
135
|
+
#define Ame state[16]
|
136
|
+
#define Ami state[17]
|
137
|
+
#define Amo state[18]
|
138
|
+
#define Amu state[19]
|
139
|
+
#define Asa state[20]
|
140
|
+
#define Ase state[21]
|
141
|
+
#define Asi state[22]
|
142
|
+
#define Aso state[23]
|
143
|
+
#define Asu state[24]
|
144
|
+
|
145
|
+
for( i = 0; i < cKeccakNumberOfRounds; i += 4 )
|
146
|
+
{
|
147
|
+
// --- Code for 4 rounds
|
148
|
+
// --- 64-bit lanes mapped to 64-bit words
|
149
|
+
Ca = Aba^Aga^Aka^Ama^Asa;
|
150
|
+
Ce = Abe^Age^Ake^Ame^Ase;
|
151
|
+
Ci = Abi^Agi^Aki^Ami^Asi;
|
152
|
+
Co = Abo^Ago^Ako^Amo^Aso;
|
153
|
+
Cu = Abu^Agu^Aku^Amu^Asu;
|
154
|
+
Da = Cu^ROL64(Ce, 1);
|
155
|
+
De = Ca^ROL64(Ci, 1);
|
156
|
+
Di = Ce^ROL64(Co, 1);
|
157
|
+
Do = Ci^ROL64(Cu, 1);
|
158
|
+
Du = Co^ROL64(Ca, 1);
|
159
|
+
|
160
|
+
Ba = (Aba^Da);
|
161
|
+
Be = ROL64((Age^De), 44);
|
162
|
+
Bi = ROL64((Aki^Di), 43);
|
163
|
+
Bo = ROL64((Amo^Do), 21);
|
164
|
+
Bu = ROL64((Asu^Du), 14);
|
165
|
+
Aba = Ba ^((~Be)& Bi );
|
166
|
+
Aba ^= KeccakF1600RoundConstants[i+0];
|
167
|
+
Age = Be ^((~Bi)& Bo );
|
168
|
+
Aki = Bi ^((~Bo)& Bu );
|
169
|
+
Amo = Bo ^((~Bu)& Ba );
|
170
|
+
Asu = Bu ^((~Ba)& Be );
|
171
|
+
|
172
|
+
Bi = ROL64((Aka^Da), 3);
|
173
|
+
Bo = ROL64((Ame^De), 45);
|
174
|
+
Bu = ROL64((Asi^Di), 61);
|
175
|
+
Ba = ROL64((Abo^Do), 28);
|
176
|
+
Be = ROL64((Agu^Du), 20);
|
177
|
+
Aka = Ba ^((~Be)& Bi );
|
178
|
+
Ame = Be ^((~Bi)& Bo );
|
179
|
+
Asi = Bi ^((~Bo)& Bu );
|
180
|
+
Abo = Bo ^((~Bu)& Ba );
|
181
|
+
Agu = Bu ^((~Ba)& Be );
|
182
|
+
|
183
|
+
Bu = ROL64((Asa^Da), 18);
|
184
|
+
Ba = ROL64((Abe^De), 1);
|
185
|
+
Be = ROL64((Agi^Di), 6);
|
186
|
+
Bi = ROL64((Ako^Do), 25);
|
187
|
+
Bo = ROL64((Amu^Du), 8);
|
188
|
+
Asa = Ba ^((~Be)& Bi );
|
189
|
+
Abe = Be ^((~Bi)& Bo );
|
190
|
+
Agi = Bi ^((~Bo)& Bu );
|
191
|
+
Ako = Bo ^((~Bu)& Ba );
|
192
|
+
Amu = Bu ^((~Ba)& Be );
|
193
|
+
|
194
|
+
Be = ROL64((Aga^Da), 36);
|
195
|
+
Bi = ROL64((Ake^De), 10);
|
196
|
+
Bo = ROL64((Ami^Di), 15);
|
197
|
+
Bu = ROL64((Aso^Do), 56);
|
198
|
+
Ba = ROL64((Abu^Du), 27);
|
199
|
+
Aga = Ba ^((~Be)& Bi );
|
200
|
+
Ake = Be ^((~Bi)& Bo );
|
201
|
+
Ami = Bi ^((~Bo)& Bu );
|
202
|
+
Aso = Bo ^((~Bu)& Ba );
|
203
|
+
Abu = Bu ^((~Ba)& Be );
|
204
|
+
|
205
|
+
Bo = ROL64((Ama^Da), 41);
|
206
|
+
Bu = ROL64((Ase^De), 2);
|
207
|
+
Ba = ROL64((Abi^Di), 62);
|
208
|
+
Be = ROL64((Ago^Do), 55);
|
209
|
+
Bi = ROL64((Aku^Du), 39);
|
210
|
+
Ama = Ba ^((~Be)& Bi );
|
211
|
+
Ase = Be ^((~Bi)& Bo );
|
212
|
+
Abi = Bi ^((~Bo)& Bu );
|
213
|
+
Ago = Bo ^((~Bu)& Ba );
|
214
|
+
Aku = Bu ^((~Ba)& Be );
|
215
|
+
|
216
|
+
Ca = Aba^Aka^Asa^Aga^Ama;
|
217
|
+
Ce = Age^Ame^Abe^Ake^Ase;
|
218
|
+
Ci = Aki^Asi^Agi^Ami^Abi;
|
219
|
+
Co = Amo^Abo^Ako^Aso^Ago;
|
220
|
+
Cu = Asu^Agu^Amu^Abu^Aku;
|
221
|
+
Da = Cu^ROL64(Ce, 1);
|
222
|
+
De = Ca^ROL64(Ci, 1);
|
223
|
+
Di = Ce^ROL64(Co, 1);
|
224
|
+
Do = Ci^ROL64(Cu, 1);
|
225
|
+
Du = Co^ROL64(Ca, 1);
|
226
|
+
|
227
|
+
Ba = (Aba^Da);
|
228
|
+
Be = ROL64((Ame^De), 44);
|
229
|
+
Bi = ROL64((Agi^Di), 43);
|
230
|
+
Bo = ROL64((Aso^Do), 21);
|
231
|
+
Bu = ROL64((Aku^Du), 14);
|
232
|
+
Aba = Ba ^((~Be)& Bi );
|
233
|
+
Aba ^= KeccakF1600RoundConstants[i+1];
|
234
|
+
Ame = Be ^((~Bi)& Bo );
|
235
|
+
Agi = Bi ^((~Bo)& Bu );
|
236
|
+
Aso = Bo ^((~Bu)& Ba );
|
237
|
+
Aku = Bu ^((~Ba)& Be );
|
238
|
+
|
239
|
+
Bi = ROL64((Asa^Da), 3);
|
240
|
+
Bo = ROL64((Ake^De), 45);
|
241
|
+
Bu = ROL64((Abi^Di), 61);
|
242
|
+
Ba = ROL64((Amo^Do), 28);
|
243
|
+
Be = ROL64((Agu^Du), 20);
|
244
|
+
Asa = Ba ^((~Be)& Bi );
|
245
|
+
Ake = Be ^((~Bi)& Bo );
|
246
|
+
Abi = Bi ^((~Bo)& Bu );
|
247
|
+
Amo = Bo ^((~Bu)& Ba );
|
248
|
+
Agu = Bu ^((~Ba)& Be );
|
249
|
+
|
250
|
+
Bu = ROL64((Ama^Da), 18);
|
251
|
+
Ba = ROL64((Age^De), 1);
|
252
|
+
Be = ROL64((Asi^Di), 6);
|
253
|
+
Bi = ROL64((Ako^Do), 25);
|
254
|
+
Bo = ROL64((Abu^Du), 8);
|
255
|
+
Ama = Ba ^((~Be)& Bi );
|
256
|
+
Age = Be ^((~Bi)& Bo );
|
257
|
+
Asi = Bi ^((~Bo)& Bu );
|
258
|
+
Ako = Bo ^((~Bu)& Ba );
|
259
|
+
Abu = Bu ^((~Ba)& Be );
|
260
|
+
|
261
|
+
Be = ROL64((Aka^Da), 36);
|
262
|
+
Bi = ROL64((Abe^De), 10);
|
263
|
+
Bo = ROL64((Ami^Di), 15);
|
264
|
+
Bu = ROL64((Ago^Do), 56);
|
265
|
+
Ba = ROL64((Asu^Du), 27);
|
266
|
+
Aka = Ba ^((~Be)& Bi );
|
267
|
+
Abe = Be ^((~Bi)& Bo );
|
268
|
+
Ami = Bi ^((~Bo)& Bu );
|
269
|
+
Ago = Bo ^((~Bu)& Ba );
|
270
|
+
Asu = Bu ^((~Ba)& Be );
|
271
|
+
|
272
|
+
Bo = ROL64((Aga^Da), 41);
|
273
|
+
Bu = ROL64((Ase^De), 2);
|
274
|
+
Ba = ROL64((Aki^Di), 62);
|
275
|
+
Be = ROL64((Abo^Do), 55);
|
276
|
+
Bi = ROL64((Amu^Du), 39);
|
277
|
+
Aga = Ba ^((~Be)& Bi );
|
278
|
+
Ase = Be ^((~Bi)& Bo );
|
279
|
+
Aki = Bi ^((~Bo)& Bu );
|
280
|
+
Abo = Bo ^((~Bu)& Ba );
|
281
|
+
Amu = Bu ^((~Ba)& Be );
|
282
|
+
|
283
|
+
Ca = Aba^Asa^Ama^Aka^Aga;
|
284
|
+
Ce = Ame^Ake^Age^Abe^Ase;
|
285
|
+
Ci = Agi^Abi^Asi^Ami^Aki;
|
286
|
+
Co = Aso^Amo^Ako^Ago^Abo;
|
287
|
+
Cu = Aku^Agu^Abu^Asu^Amu;
|
288
|
+
Da = Cu^ROL64(Ce, 1);
|
289
|
+
De = Ca^ROL64(Ci, 1);
|
290
|
+
Di = Ce^ROL64(Co, 1);
|
291
|
+
Do = Ci^ROL64(Cu, 1);
|
292
|
+
Du = Co^ROL64(Ca, 1);
|
293
|
+
|
294
|
+
Ba = (Aba^Da);
|
295
|
+
Be = ROL64((Ake^De), 44);
|
296
|
+
Bi = ROL64((Asi^Di), 43);
|
297
|
+
Bo = ROL64((Ago^Do), 21);
|
298
|
+
Bu = ROL64((Amu^Du), 14);
|
299
|
+
Aba = Ba ^((~Be)& Bi );
|
300
|
+
Aba ^= KeccakF1600RoundConstants[i+2];
|
301
|
+
Ake = Be ^((~Bi)& Bo );
|
302
|
+
Asi = Bi ^((~Bo)& Bu );
|
303
|
+
Ago = Bo ^((~Bu)& Ba );
|
304
|
+
Amu = Bu ^((~Ba)& Be );
|
305
|
+
|
306
|
+
Bi = ROL64((Ama^Da), 3);
|
307
|
+
Bo = ROL64((Abe^De), 45);
|
308
|
+
Bu = ROL64((Aki^Di), 61);
|
309
|
+
Ba = ROL64((Aso^Do), 28);
|
310
|
+
Be = ROL64((Agu^Du), 20);
|
311
|
+
Ama = Ba ^((~Be)& Bi );
|
312
|
+
Abe = Be ^((~Bi)& Bo );
|
313
|
+
Aki = Bi ^((~Bo)& Bu );
|
314
|
+
Aso = Bo ^((~Bu)& Ba );
|
315
|
+
Agu = Bu ^((~Ba)& Be );
|
316
|
+
|
317
|
+
Bu = ROL64((Aga^Da), 18);
|
318
|
+
Ba = ROL64((Ame^De), 1);
|
319
|
+
Be = ROL64((Abi^Di), 6);
|
320
|
+
Bi = ROL64((Ako^Do), 25);
|
321
|
+
Bo = ROL64((Asu^Du), 8);
|
322
|
+
Aga = Ba ^((~Be)& Bi );
|
323
|
+
Ame = Be ^((~Bi)& Bo );
|
324
|
+
Abi = Bi ^((~Bo)& Bu );
|
325
|
+
Ako = Bo ^((~Bu)& Ba );
|
326
|
+
Asu = Bu ^((~Ba)& Be );
|
327
|
+
|
328
|
+
Be = ROL64((Asa^Da), 36);
|
329
|
+
Bi = ROL64((Age^De), 10);
|
330
|
+
Bo = ROL64((Ami^Di), 15);
|
331
|
+
Bu = ROL64((Abo^Do), 56);
|
332
|
+
Ba = ROL64((Aku^Du), 27);
|
333
|
+
Asa = Ba ^((~Be)& Bi );
|
334
|
+
Age = Be ^((~Bi)& Bo );
|
335
|
+
Ami = Bi ^((~Bo)& Bu );
|
336
|
+
Abo = Bo ^((~Bu)& Ba );
|
337
|
+
Aku = Bu ^((~Ba)& Be );
|
338
|
+
|
339
|
+
Bo = ROL64((Aka^Da), 41);
|
340
|
+
Bu = ROL64((Ase^De), 2);
|
341
|
+
Ba = ROL64((Agi^Di), 62);
|
342
|
+
Be = ROL64((Amo^Do), 55);
|
343
|
+
Bi = ROL64((Abu^Du), 39);
|
344
|
+
Aka = Ba ^((~Be)& Bi );
|
345
|
+
Ase = Be ^((~Bi)& Bo );
|
346
|
+
Agi = Bi ^((~Bo)& Bu );
|
347
|
+
Amo = Bo ^((~Bu)& Ba );
|
348
|
+
Abu = Bu ^((~Ba)& Be );
|
349
|
+
|
350
|
+
Ca = Aba^Ama^Aga^Asa^Aka;
|
351
|
+
Ce = Ake^Abe^Ame^Age^Ase;
|
352
|
+
Ci = Asi^Aki^Abi^Ami^Agi;
|
353
|
+
Co = Ago^Aso^Ako^Abo^Amo;
|
354
|
+
Cu = Amu^Agu^Asu^Aku^Abu;
|
355
|
+
Da = Cu^ROL64(Ce, 1);
|
356
|
+
De = Ca^ROL64(Ci, 1);
|
357
|
+
Di = Ce^ROL64(Co, 1);
|
358
|
+
Do = Ci^ROL64(Cu, 1);
|
359
|
+
Du = Co^ROL64(Ca, 1);
|
360
|
+
|
361
|
+
Ba = (Aba^Da);
|
362
|
+
Be = ROL64((Abe^De), 44);
|
363
|
+
Bi = ROL64((Abi^Di), 43);
|
364
|
+
Bo = ROL64((Abo^Do), 21);
|
365
|
+
Bu = ROL64((Abu^Du), 14);
|
366
|
+
Aba = Ba ^((~Be)& Bi );
|
367
|
+
Aba ^= KeccakF1600RoundConstants[i+3];
|
368
|
+
Abe = Be ^((~Bi)& Bo );
|
369
|
+
Abi = Bi ^((~Bo)& Bu );
|
370
|
+
Abo = Bo ^((~Bu)& Ba );
|
371
|
+
Abu = Bu ^((~Ba)& Be );
|
372
|
+
|
373
|
+
Bi = ROL64((Aga^Da), 3);
|
374
|
+
Bo = ROL64((Age^De), 45);
|
375
|
+
Bu = ROL64((Agi^Di), 61);
|
376
|
+
Ba = ROL64((Ago^Do), 28);
|
377
|
+
Be = ROL64((Agu^Du), 20);
|
378
|
+
Aga = Ba ^((~Be)& Bi );
|
379
|
+
Age = Be ^((~Bi)& Bo );
|
380
|
+
Agi = Bi ^((~Bo)& Bu );
|
381
|
+
Ago = Bo ^((~Bu)& Ba );
|
382
|
+
Agu = Bu ^((~Ba)& Be );
|
383
|
+
|
384
|
+
Bu = ROL64((Aka^Da), 18);
|
385
|
+
Ba = ROL64((Ake^De), 1);
|
386
|
+
Be = ROL64((Aki^Di), 6);
|
387
|
+
Bi = ROL64((Ako^Do), 25);
|
388
|
+
Bo = ROL64((Aku^Du), 8);
|
389
|
+
Aka = Ba ^((~Be)& Bi );
|
390
|
+
Ake = Be ^((~Bi)& Bo );
|
391
|
+
Aki = Bi ^((~Bo)& Bu );
|
392
|
+
Ako = Bo ^((~Bu)& Ba );
|
393
|
+
Aku = Bu ^((~Ba)& Be );
|
394
|
+
|
395
|
+
Be = ROL64((Ama^Da), 36);
|
396
|
+
Bi = ROL64((Ame^De), 10);
|
397
|
+
Bo = ROL64((Ami^Di), 15);
|
398
|
+
Bu = ROL64((Amo^Do), 56);
|
399
|
+
Ba = ROL64((Amu^Du), 27);
|
400
|
+
Ama = Ba ^((~Be)& Bi );
|
401
|
+
Ame = Be ^((~Bi)& Bo );
|
402
|
+
Ami = Bi ^((~Bo)& Bu );
|
403
|
+
Amo = Bo ^((~Bu)& Ba );
|
404
|
+
Amu = Bu ^((~Ba)& Be );
|
405
|
+
|
406
|
+
Bo = ROL64((Asa^Da), 41);
|
407
|
+
Bu = ROL64((Ase^De), 2);
|
408
|
+
Ba = ROL64((Asi^Di), 62);
|
409
|
+
Be = ROL64((Aso^Do), 55);
|
410
|
+
Bi = ROL64((Asu^Du), 39);
|
411
|
+
Asa = Ba ^((~Be)& Bi );
|
412
|
+
Ase = Be ^((~Bi)& Bo );
|
413
|
+
Asi = Bi ^((~Bo)& Bu );
|
414
|
+
Aso = Bo ^((~Bu)& Ba );
|
415
|
+
Asu = Bu ^((~Ba)& Be );
|
416
|
+
}
|
417
|
+
#undef i
|
418
|
+
#undef Aba
|
419
|
+
#undef Abe
|
420
|
+
#undef Abi
|
421
|
+
#undef Abo
|
422
|
+
#undef Abu
|
423
|
+
#undef Aga
|
424
|
+
#undef Age
|
425
|
+
#undef Agi
|
426
|
+
#undef Ago
|
427
|
+
#undef Agu
|
428
|
+
#undef Aka
|
429
|
+
#undef Ake
|
430
|
+
#undef Aki
|
431
|
+
#undef Ako
|
432
|
+
#undef Aku
|
433
|
+
#undef Ama
|
434
|
+
#undef Ame
|
435
|
+
#undef Ami
|
436
|
+
#undef Amo
|
437
|
+
#undef Amu
|
438
|
+
#undef Asa
|
439
|
+
#undef Ase
|
440
|
+
#undef Asi
|
441
|
+
#undef Aso
|
442
|
+
#undef Asu
|
443
|
+
}
|
444
|
+
|
445
|
+
}
|
@@ -0,0 +1,844 @@
|
|
1
|
+
@ The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
|
2
|
+
@ Michaël Peeters and Gilles Van Assche. For more information, feedback or
|
3
|
+
@ questions, please refer to our website: http://keccak.noekeon.org/
|
4
|
+
@
|
5
|
+
@ Implementation by Ronny Van Keer,
|
6
|
+
@ hereby denoted as "the implementer".
|
7
|
+
@
|
8
|
+
@ To the extent possible under law, the implementer has waived all copyright
|
9
|
+
@ and related or neighboring rights to the source code in this file.
|
10
|
+
@ http://creativecommons.org/publicdomain/zero/1.0/
|
11
|
+
|
12
|
+
@ This file was created from a .asm file
|
13
|
+
@ using the ads2gas.pl script.
|
14
|
+
.equ DO1STROUNDING, 0
|
15
|
+
|
16
|
+
@ PRESERVE8
|
17
|
+
@ THUMB
|
18
|
+
.syntax unified
|
19
|
+
.cpu cortex-m1
|
20
|
+
.thumb
|
21
|
+
|
22
|
+
@// --- defines
|
23
|
+
.equ cKeccakLaneSizeInBytes , 8
|
24
|
+
.equ cKeccakR_SizeInBytes , 1024/8 @576/8 1024/8 1088/8 // populate.py, please set cKeccakR_SizeInBytes
|
25
|
+
.equ crypto_hash_BYTES , cKeccakR_SizeInBytes @// populate.py, please set crypto_hash_BYTES
|
26
|
+
|
27
|
+
|
28
|
+
@// --- offsets in state
|
29
|
+
.equ Aba0 , 0*4
|
30
|
+
.equ Aba1 , 1*4
|
31
|
+
.equ Abe0 , 2*4
|
32
|
+
.equ Abe1 , 3*4
|
33
|
+
.equ Abi0 , 4*4
|
34
|
+
.equ Abi1 , 5*4
|
35
|
+
.equ Abo0 , 6*4
|
36
|
+
.equ Abo1 , 7*4
|
37
|
+
.equ Abu0 , 8*4
|
38
|
+
.equ Abu1 , 9*4
|
39
|
+
.equ Aga0 , 10*4
|
40
|
+
.equ Aga1 , 11*4
|
41
|
+
.equ Age0 , 12*4
|
42
|
+
.equ Age1 , 13*4
|
43
|
+
.equ Agi0 , 14*4
|
44
|
+
.equ Agi1 , 15*4
|
45
|
+
.equ Ago0 , 16*4
|
46
|
+
.equ Ago1 , 17*4
|
47
|
+
.equ Agu0 , 18*4
|
48
|
+
.equ Agu1 , 19*4
|
49
|
+
.equ Aka0 , 20*4
|
50
|
+
.equ Aka1 , 21*4
|
51
|
+
.equ Ake0 , 22*4
|
52
|
+
.equ Ake1 , 23*4
|
53
|
+
.equ Aki0 , 24*4
|
54
|
+
.equ Aki1 , 25*4
|
55
|
+
.equ Ako0 , 26*4
|
56
|
+
.equ Ako1 , 27*4
|
57
|
+
.equ Aku0 , 28*4
|
58
|
+
.equ Aku1 , 29*4
|
59
|
+
.equ Ama0 , 30*4
|
60
|
+
.equ Ama1 , 31*4
|
61
|
+
.equ Ame0 , 32*4
|
62
|
+
.equ Ame1 , 33*4
|
63
|
+
.equ Ami0 , 34*4
|
64
|
+
.equ Ami1 , 35*4
|
65
|
+
.equ Amo0 , 36*4
|
66
|
+
.equ Amo1 , 37*4
|
67
|
+
.equ Amu0 , 38*4
|
68
|
+
.equ Amu1 , 39*4
|
69
|
+
.equ Asa0 , 40*4
|
70
|
+
.equ Asa1 , 41*4
|
71
|
+
.equ Ase0 , 42*4
|
72
|
+
.equ Ase1 , 43*4
|
73
|
+
.equ Asi0 , 44*4
|
74
|
+
.equ Asi1 , 45*4
|
75
|
+
.equ Aso0 , 46*4
|
76
|
+
.equ Aso1 , 47*4
|
77
|
+
.equ Asu0 , 48*4
|
78
|
+
.equ Asu1 , 49*4
|
79
|
+
|
80
|
+
@// --- offsets on stack
|
81
|
+
.equ mDo0 , 50*4
|
82
|
+
.equ mDo1 , 51*4
|
83
|
+
.equ mDi0 , 52*4
|
84
|
+
.equ mRC , 53*4
|
85
|
+
.equ mRet , 54*4
|
86
|
+
.equ mIn , 55*4
|
87
|
+
.equ mOut , 56*4
|
88
|
+
.equ mLen , 57*4
|
89
|
+
|
90
|
+
@// --- macros
|
91
|
+
|
92
|
+
@// Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
|
93
|
+
.macro interleaveLane in0,in1,out0,out1,t,tt,pMask
|
94
|
+
|
95
|
+
mov \out0, \in0
|
96
|
+
ldr \t, [\pMask, #0]
|
97
|
+
ands \out0, \out0, \t
|
98
|
+
lsrs \t, \out0, #1
|
99
|
+
orrs \out0, \out0, \t
|
100
|
+
ldr \t, [\pMask, #4]
|
101
|
+
ands \out0, \out0, \t
|
102
|
+
lsrs \t, \out0, #2
|
103
|
+
orrs \out0, \out0, \t
|
104
|
+
ldr \t, [\pMask, #8]
|
105
|
+
ands \out0, \out0, \t
|
106
|
+
lsrs \t, \out0, #4
|
107
|
+
orrs \out0, \out0, \t
|
108
|
+
ldr \t, [\pMask, #12]
|
109
|
+
ands \out0, \out0, \t
|
110
|
+
lsrs \t, \out0, #8
|
111
|
+
orrs \out0, \out0, \t
|
112
|
+
|
113
|
+
mov \out1, \in1
|
114
|
+
ldr \t, [\pMask, #0]
|
115
|
+
ands \out1, \out1, \t
|
116
|
+
lsrs \t, \out1, #1
|
117
|
+
orrs \out1, \out1, \t
|
118
|
+
ldr \t, [\pMask, #4]
|
119
|
+
ands \out1, \out1, \t
|
120
|
+
lsrs \t, \out1, #2
|
121
|
+
orrs \out1, \out1, \t
|
122
|
+
ldr \t, [\pMask, #8]
|
123
|
+
ands \out1, \out1, \t
|
124
|
+
lsrs \t, \out1, #4
|
125
|
+
orrs \out1, \out1, \t
|
126
|
+
ldr \t, [\pMask, #12]
|
127
|
+
ands \out1, \out1, \t
|
128
|
+
lsrs \t, \out1, #8
|
129
|
+
orrs \out1, \out1, \t
|
130
|
+
|
131
|
+
lsls \out0, \out0, #16
|
132
|
+
lsrs \out0, \out0, #16
|
133
|
+
lsls \out1, \out1, #16
|
134
|
+
orrs \out0, \out0, \out1
|
135
|
+
|
136
|
+
mov \out1, \in0
|
137
|
+
ldr \t, [\pMask, #16]
|
138
|
+
ands \out1, \out1, \t
|
139
|
+
lsls \t, \out1, #1
|
140
|
+
orrs \out1, \out1, \t
|
141
|
+
ldr \t, [\pMask, #20]
|
142
|
+
ands \out1, \out1, \t
|
143
|
+
lsls \t, \out1, #2
|
144
|
+
orrs \out1, \out1, \t
|
145
|
+
ldr \t, [\pMask, #24]
|
146
|
+
ands \out1, \out1, \t
|
147
|
+
lsls \t, \out1, #4
|
148
|
+
orrs \out1, \out1, \t
|
149
|
+
ldr \t, [\pMask, #28]
|
150
|
+
ands \out1, \out1, \t
|
151
|
+
lsls \t, \out1, #8
|
152
|
+
orrs \out1, \out1, \t
|
153
|
+
|
154
|
+
mov \tt, \in1
|
155
|
+
ldr \t, [\pMask, #16]
|
156
|
+
ands \tt, \tt, \t
|
157
|
+
lsls \t, \tt, #1
|
158
|
+
orrs \tt, \tt, \t
|
159
|
+
ldr \t, [\pMask, #20]
|
160
|
+
ands \tt, \tt, \t
|
161
|
+
lsls \t, \tt, #2
|
162
|
+
orrs \tt, \tt, \t
|
163
|
+
ldr \t, [\pMask, #24]
|
164
|
+
ands \tt, \tt, \t
|
165
|
+
lsls \t, \tt, #4
|
166
|
+
orrs \tt, \tt, \t
|
167
|
+
ldr \t, [\pMask, #28]
|
168
|
+
ands \tt, \tt, \t
|
169
|
+
lsls \t, \tt, #8
|
170
|
+
orrs \tt, \tt, \t
|
171
|
+
|
172
|
+
lsrs \out1,\out1, #16
|
173
|
+
lsrs \tt, \tt, #16
|
174
|
+
lsls \tt, \tt, #16
|
175
|
+
orrs \out1,\out1,\tt
|
176
|
+
.endm
|
177
|
+
|
178
|
+
@// Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
|
179
|
+
.macro uninterleaveStep x, t, tt, pMask, maskofs, shift
|
180
|
+
|
181
|
+
@// t = (x ^ (x >> shift)) & mask@ x = x ^ t ^ (t << shift)@
|
182
|
+
lsrs \t, \x, #\shift
|
183
|
+
eors \t, \t, \x
|
184
|
+
ldr \tt, [\pMask, #\maskofs]
|
185
|
+
ands \t, \t, \tt
|
186
|
+
eors \x, \x, \t
|
187
|
+
lsls \t, \t, #\shift
|
188
|
+
eors \x, \x, \t
|
189
|
+
.endm
|
190
|
+
|
191
|
+
|
192
|
+
.macro uninterleaveLane x0, x1, t, tt, pMask
|
193
|
+
|
194
|
+
movs \t, \x0 @// t = x0
|
195
|
+
lsls \x0, \x0, #16 @// x0 = (x0 & 0x0000FFFF) | (x1 << 16)@
|
196
|
+
lsrs \x0, \x0, #16
|
197
|
+
lsls \tt, \x1, #16
|
198
|
+
orrs \x0, \x0, \tt
|
199
|
+
|
200
|
+
lsrs \x1, \x1, #16 @// x1 = (t >> 16) | (x1 & 0xFFFF0000)@
|
201
|
+
lsls \x1, \x1, #16
|
202
|
+
lsrs \t, \t, #16
|
203
|
+
orrs \x1, \x1, \t
|
204
|
+
|
205
|
+
uninterleaveStep \x0, \t, \tt, \pMask, 0, 8
|
206
|
+
uninterleaveStep \x0, \t, \tt, \pMask, 4, 4
|
207
|
+
uninterleaveStep \x0, \t, \tt, \pMask, 8, 2
|
208
|
+
uninterleaveStep \x0, \t, \tt, \pMask, 12, 1
|
209
|
+
|
210
|
+
uninterleaveStep \x1, \t, \tt, \pMask, 0, 8
|
211
|
+
uninterleaveStep \x1, \t, \tt, \pMask, 4, 4
|
212
|
+
uninterleaveStep \x1, \t, \tt, \pMask, 8, 2
|
213
|
+
uninterleaveStep \x1, \t, \tt, \pMask, 12, 1
|
214
|
+
.endm
|
215
|
+
|
216
|
+
.macro xor5 result,b,g,k,m,s
|
217
|
+
|
218
|
+
ldr \result, [sp, #\b]
|
219
|
+
ldr r1, [sp, #\g]
|
220
|
+
eors \result, \result, r1
|
221
|
+
ldr r1, [sp, #\k]
|
222
|
+
eors \result, \result, r1
|
223
|
+
ldr r1, [sp, #\m]
|
224
|
+
eors \result, \result, r1
|
225
|
+
ldr r1, [sp, #\s]
|
226
|
+
eors \result, \result, r1
|
227
|
+
.endm
|
228
|
+
|
229
|
+
.macro xorrol result, aa, bb
|
230
|
+
movs \result, \bb
|
231
|
+
rors \result, r2
|
232
|
+
eors \result, \result, \aa
|
233
|
+
.endm
|
234
|
+
|
235
|
+
.macro xorrolR2 aa, bb
|
236
|
+
rors \bb, r2
|
237
|
+
eors \bb, \bb, \aa
|
238
|
+
.endm
|
239
|
+
|
240
|
+
.macro xorh result, aa, bb
|
241
|
+
mov r1, \bb
|
242
|
+
eors r1, r1, \aa
|
243
|
+
mov \result, r1
|
244
|
+
.endm
|
245
|
+
|
246
|
+
|
247
|
+
.macro xandnot resofs, aa, bb, cc
|
248
|
+
|
249
|
+
movs r1, \cc
|
250
|
+
bics r1, r1, \bb
|
251
|
+
eors r1, r1, \aa
|
252
|
+
str r1, [sp, #\resofs]
|
253
|
+
.endm
|
254
|
+
|
255
|
+
.macro xandnotR4 resofs, aa, bb, cc
|
256
|
+
|
257
|
+
bics \cc, \cc, \bb
|
258
|
+
eors \cc, \cc, \aa
|
259
|
+
str \cc, [sp, #\resofs]
|
260
|
+
.endm
|
261
|
+
|
262
|
+
.macro KeccakThetaRhoPiChiIota aA1, aDax, aA2, aDex, rot2, aA3, aDix, rot3, aA4, aDox, rot4, aA5, aDux, rot5, offset, last
|
263
|
+
ldr r3, [sp, #\aA1]
|
264
|
+
ldr r4, [sp, #\aA2]
|
265
|
+
ldr r5, [sp, #\aA3]
|
266
|
+
ldr r6, [sp, #\aA4]
|
267
|
+
ldr r7, [sp, #\aA5]
|
268
|
+
mov r1, \aDax
|
269
|
+
eors r3, r3, r1
|
270
|
+
eors r5, r5, \aDix
|
271
|
+
mov r1, \aDex
|
272
|
+
eors r4, r4, r1
|
273
|
+
eors r6, r6, \aDox
|
274
|
+
mov r1, \aDux
|
275
|
+
eors r7, r7, r1
|
276
|
+
movs r1, #32-\rot2
|
277
|
+
rors r4, r1
|
278
|
+
movs r1, #32-\rot3
|
279
|
+
rors r5, r1
|
280
|
+
movs r1, #32-\rot4
|
281
|
+
rors r6, r1
|
282
|
+
movs r1, #32-\rot5
|
283
|
+
rors r7, r1
|
284
|
+
xandnot \aA2, r4, r5, r6
|
285
|
+
xandnot \aA3, r5, r6, r7
|
286
|
+
xandnot \aA4, r6, r7, r3
|
287
|
+
xandnot \aA5, r7, r3, r4
|
288
|
+
ldr r1, [sp, #mRC]
|
289
|
+
bics r5, r5, r4
|
290
|
+
ldr r4, [r1, #\offset]
|
291
|
+
eors r3, r3, r5
|
292
|
+
eors r3, r3, r4
|
293
|
+
.if \last == 1
|
294
|
+
adds r1, #32
|
295
|
+
ldr r2, [r1]
|
296
|
+
str r1, [sp, #mRC]
|
297
|
+
cmp r2, #0xFF
|
298
|
+
.endif
|
299
|
+
str r3, [sp, #\aA1]
|
300
|
+
.endm
|
301
|
+
|
302
|
+
.macro KeccakThetaRhoPiChi aB1, aA1, aDax, rot1, aB2, aA2, aDex, rot2, aB3, aA3, aDix, rot3, aB4, aA4, aDox, rot4, aB5, aA5, aDux, rot5
|
303
|
+
ldr \aB1, [sp, #\aA1]
|
304
|
+
ldr \aB2, [sp, #\aA2]
|
305
|
+
ldr \aB3, [sp, #\aA3]
|
306
|
+
ldr \aB4, [sp, #\aA4]
|
307
|
+
ldr \aB5, [sp, #\aA5]
|
308
|
+
mov r1, \aDax
|
309
|
+
eors \aB1, \aB1, r1
|
310
|
+
eors \aB3, \aB3, \aDix
|
311
|
+
mov r1, \aDex
|
312
|
+
eors \aB2, \aB2, r1
|
313
|
+
eors \aB4, \aB4, \aDox
|
314
|
+
mov r1, \aDux
|
315
|
+
eors \aB5, \aB5, r1
|
316
|
+
movs r1, #32-\rot1
|
317
|
+
rors \aB1, r1
|
318
|
+
.if \rot2 > 0
|
319
|
+
movs r1, #32-\rot2
|
320
|
+
rors \aB2, r1
|
321
|
+
.endif
|
322
|
+
movs r1, #32-\rot3
|
323
|
+
rors \aB3, r1
|
324
|
+
movs r1, #32-\rot4
|
325
|
+
rors \aB4, r1
|
326
|
+
movs r1, #32-\rot5
|
327
|
+
rors \aB5, r1
|
328
|
+
xandnot \aA1, r3, r4, r5
|
329
|
+
xandnot \aA2, r4, r5, r6
|
330
|
+
xandnotR4 \aA5, r7, r3, r4
|
331
|
+
xandnotR4 \aA4, r6, r7, r3
|
332
|
+
xandnotR4 \aA3, r5, r6, r7
|
333
|
+
.endm
|
334
|
+
|
335
|
+
.macro KeccakRound0
|
336
|
+
|
337
|
+
movs r2, #31
|
338
|
+
xor5 r3, Abu0, Agu0, Aku0, Amu0, Asu0
|
339
|
+
xor5 r7, Abe1, Age1, Ake1, Ame1, Ase1
|
340
|
+
xorrol r6, r3, r7
|
341
|
+
mov r8, r6
|
342
|
+
xor5 r6, Abu1, Agu1, Aku1, Amu1, Asu1
|
343
|
+
xor5 r0, Abe0, Age0, Ake0, Ame0, Ase0
|
344
|
+
xorh r9, r6, r0
|
345
|
+
|
346
|
+
xor5 r5, Abi0, Agi0, Aki0, Ami0, Asi0
|
347
|
+
xorrolR2 r5, r6
|
348
|
+
str r6, [sp, #mDo0]
|
349
|
+
xor5 r4, Abi1, Agi1, Aki1, Ami1, Asi1
|
350
|
+
eors r3, r3, r4
|
351
|
+
str r3, [sp, #mDo1]
|
352
|
+
|
353
|
+
xor5 r3, Aba0, Aga0, Aka0, Ama0, Asa0
|
354
|
+
xorrolR2 r3, r4
|
355
|
+
mov r10, r4
|
356
|
+
xor5 r6, Aba1, Aga1, Aka1, Ama1, Asa1
|
357
|
+
xorh r11, r6, r5
|
358
|
+
|
359
|
+
xor5 r4, Abo1, Ago1, Ako1, Amo1, Aso1
|
360
|
+
xorrol r5, r0, r4
|
361
|
+
str r5, [sp, #mDi0]
|
362
|
+
xor5 r5, Abo0, Ago0, Ako0, Amo0, Aso0
|
363
|
+
eors r7, r7, r5
|
364
|
+
|
365
|
+
xorrolR2 r5, r6
|
366
|
+
mov r12, r6
|
367
|
+
eors r4, r4, r3
|
368
|
+
mov lr, r4
|
369
|
+
movs r2, r7
|
370
|
+
|
371
|
+
ldr r0, [sp, #mDo0]
|
372
|
+
KeccakThetaRhoPiChi r5, Aka1, r9, 2, r6, Ame1, r11, 23, r7, Asi1, r2, 31, r3, Abo0, r0, 14, r4, Agu0, r12, 10
|
373
|
+
KeccakThetaRhoPiChi r7, Asa1, r9, 9, r3, Abe0, r10, 0, r4, Agi1, r2, 3, r5, Ako0, r0, 12, r6, Amu1, lr, 4
|
374
|
+
KeccakThetaRhoPiChi r4, Aga0, r8, 18, r5, Ake0, r10, 5, r6, Ami1, r2, 8, r7, Aso0, r0, 28, r3, Abu1, lr, 14
|
375
|
+
KeccakThetaRhoPiChi r6, Ama0, r8, 20, r7, Ase1, r11, 1, r3, Abi1, r2, 31, r4, Ago0, r0, 27, r5, Aku0, r12, 19
|
376
|
+
ldr r0, [sp, #mDo1]
|
377
|
+
KeccakThetaRhoPiChiIota Aba0, r8, Age0, r10, 22, Aki1, r2, 22, Amo1, r0, 11, Asu0, r12, 7, 0, 0
|
378
|
+
|
379
|
+
ldr r2, [sp, #mDi0]
|
380
|
+
KeccakThetaRhoPiChi r5, Aka0, r8, 1, r6, Ame0, r10, 22, r7, Asi0, r2, 30, r3, Abo1, r0, 14, r4, Agu1, lr, 10
|
381
|
+
KeccakThetaRhoPiChi r7, Asa0, r8, 9, r3, Abe1, r11, 1, r4, Agi0, r2, 3, r5, Ako1, r0, 13, r6, Amu0, r12, 4
|
382
|
+
KeccakThetaRhoPiChi r4, Aga1, r9, 18, r5, Ake1, r11, 5, r6, Ami0, r2, 7, r7, Aso1, r0, 28, r3, Abu0, r12, 13
|
383
|
+
KeccakThetaRhoPiChi r6, Ama1, r9, 21, r7, Ase0, r10, 1, r3, Abi0, r2, 31, r4, Ago1, r0, 28, r5, Aku1, lr, 20
|
384
|
+
ldr r0, [sp, #mDo0]
|
385
|
+
KeccakThetaRhoPiChiIota Aba1, r9, Age1, r11, 22, Aki0, r2, 21, Amo0, r0, 10, Asu1, lr, 7, 4, 0
|
386
|
+
.endm
|
387
|
+
|
388
|
+
.macro KeccakRound1
|
389
|
+
|
390
|
+
movs r2, #31
|
391
|
+
xor5 r3, Asu0, Agu0, Amu0, Abu1, Aku1
|
392
|
+
xor5 r7, Age1, Ame0, Abe0, Ake1, Ase1
|
393
|
+
xorrol r6, r3, r7
|
394
|
+
mov r8, r6
|
395
|
+
xor5 r6, Asu1, Agu1, Amu1, Abu0, Aku0
|
396
|
+
xor5 r0, Age0, Ame1, Abe1, Ake0, Ase0
|
397
|
+
xorh r9, r6, r0
|
398
|
+
|
399
|
+
xor5 r5, Aki1, Asi1, Agi0, Ami1, Abi0
|
400
|
+
xorrolR2 r5, r6
|
401
|
+
str r6, [sp, #mDo0]
|
402
|
+
xor5 r4, Aki0, Asi0, Agi1, Ami0, Abi1
|
403
|
+
eors r3, r3, r4
|
404
|
+
str r3, [sp, #mDo1]
|
405
|
+
|
406
|
+
xor5 r3, Aba0, Aka1, Asa0, Aga0, Ama1
|
407
|
+
xorrolR2 r3, r4
|
408
|
+
mov r10, r4
|
409
|
+
xor5 r6, Aba1, Aka0, Asa1, Aga1, Ama0
|
410
|
+
xorh r11, r6, r5
|
411
|
+
|
412
|
+
xor5 r4, Amo0, Abo1, Ako0, Aso1, Ago0
|
413
|
+
xorrol r5, r0, r4
|
414
|
+
str r5, [sp, #mDi0]
|
415
|
+
xor5 r5, Amo1, Abo0, Ako1, Aso0, Ago1
|
416
|
+
eors r7, r7, r5
|
417
|
+
|
418
|
+
xorrolR2 r5, r6
|
419
|
+
mov r12, r6
|
420
|
+
eors r4, r4, r3
|
421
|
+
mov lr, r4
|
422
|
+
movs r2, r7
|
423
|
+
|
424
|
+
ldr r0, [sp, #mDo0]
|
425
|
+
KeccakThetaRhoPiChi r5, Asa1, r9, 2, r6, Ake1, r11, 23, r7, Abi1, r2, 31, r3, Amo1, r0, 14, r4, Agu0, r12, 10
|
426
|
+
KeccakThetaRhoPiChi r7, Ama0, r9, 9, r3, Age0, r10, 0, r4, Asi0, r2, 3, r5, Ako1, r0, 12, r6, Abu0, lr, 4
|
427
|
+
KeccakThetaRhoPiChi r4, Aka1, r8, 18, r5, Abe1, r10, 5, r6, Ami0, r2, 8, r7, Ago1, r0, 28, r3, Asu1, lr, 14
|
428
|
+
KeccakThetaRhoPiChi r6, Aga0, r8, 20, r7, Ase1, r11, 1, r3, Aki0, r2, 31, r4, Abo0, r0, 27, r5, Amu0, r12, 19
|
429
|
+
ldr r0, [sp, #mDo1]
|
430
|
+
KeccakThetaRhoPiChiIota Aba0, r8, Ame1, r10, 22, Agi1, r2, 22, Aso1, r0, 11, Aku1, r12, 7, 8, 0
|
431
|
+
|
432
|
+
ldr r2, [sp, #mDi0]
|
433
|
+
KeccakThetaRhoPiChi r5, Asa0, r8, 1, r6, Ake0, r10, 22, r7, Abi0, r2, 30, r3, Amo0, r0, 14, r4, Agu1, lr, 10
|
434
|
+
KeccakThetaRhoPiChi r7, Ama1, r8, 9, r3, Age1, r11, 1, r4, Asi1, r2, 3, r5, Ako0, r0, 13, r6, Abu1, r12, 4
|
435
|
+
KeccakThetaRhoPiChi r4, Aka0, r9, 18, r5, Abe0, r11, 5, r6, Ami1, r2, 7, r7, Ago0, r0, 28, r3, Asu0, r12, 13
|
436
|
+
KeccakThetaRhoPiChi r6, Aga1, r9, 21, r7, Ase0, r10, 1, r3, Aki1, r2, 31, r4, Abo1, r0, 28, r5, Amu1, lr, 20
|
437
|
+
ldr r0, [sp, #mDo0]
|
438
|
+
KeccakThetaRhoPiChiIota Aba1, r9, Ame0, r11, 22, Agi0, r2, 21, Aso0, r0, 10, Aku0, lr, 7, 12, 0
|
439
|
+
.endm
|
440
|
+
|
441
|
+
.macro KeccakRound2
|
442
|
+
|
443
|
+
movs r2, #31
|
444
|
+
xor5 r3, Aku1, Agu0, Abu1, Asu1, Amu1
|
445
|
+
xor5 r7, Ame0, Ake0, Age0, Abe0, Ase1
|
446
|
+
xorrol r6, r3, r7
|
447
|
+
mov r8, r6
|
448
|
+
xor5 r6, Aku0, Agu1, Abu0, Asu0, Amu0
|
449
|
+
xor5 r0, Ame1, Ake1, Age1, Abe1, Ase0
|
450
|
+
xorh r9, r6, r0
|
451
|
+
|
452
|
+
xor5 r5, Agi1, Abi1, Asi1, Ami0, Aki1
|
453
|
+
xorrolR2 r5, r6
|
454
|
+
str r6, [sp, #mDo0]
|
455
|
+
xor5 r4, Agi0, Abi0, Asi0, Ami1, Aki0
|
456
|
+
eors r3, r3, r4
|
457
|
+
str r3, [sp, #mDo1]
|
458
|
+
|
459
|
+
xor5 r3, Aba0, Asa1, Ama1, Aka1, Aga1
|
460
|
+
xorrolR2 r3, r4
|
461
|
+
mov r10, r4
|
462
|
+
xor5 r6, Aba1, Asa0, Ama0, Aka0, Aga0
|
463
|
+
xorh r11, r6, r5
|
464
|
+
|
465
|
+
xor5 r4, Aso0, Amo0, Ako1, Ago0, Abo0
|
466
|
+
xorrol r5, r0, r4
|
467
|
+
str r5, [sp, #mDi0]
|
468
|
+
xor5 r5, Aso1, Amo1, Ako0, Ago1, Abo1
|
469
|
+
eors r7, r7, r5
|
470
|
+
|
471
|
+
xorrolR2 r5, r6
|
472
|
+
mov r12, r6
|
473
|
+
eors r4, r4, r3
|
474
|
+
mov lr, r4
|
475
|
+
movs r2, r7
|
476
|
+
|
477
|
+
ldr r0, [sp, #mDo0]
|
478
|
+
KeccakThetaRhoPiChi r5, Ama0, r9, 2, r6, Abe0, r11, 23, r7, Aki0, r2, 31, r3, Aso1, r0, 14, r4, Agu0, r12, 10
|
479
|
+
KeccakThetaRhoPiChi r7, Aga0, r9, 9, r3, Ame1, r10, 0, r4, Abi0, r2, 3, r5, Ako0, r0, 12, r6, Asu0, lr, 4
|
480
|
+
KeccakThetaRhoPiChi r4, Asa1, r8, 18, r5, Age1, r10, 5, r6, Ami1, r2, 8, r7, Abo1, r0, 28, r3, Aku0, lr, 14
|
481
|
+
KeccakThetaRhoPiChi r6, Aka1, r8, 20, r7, Ase1, r11, 1, r3, Agi0, r2, 31, r4, Amo1, r0, 27, r5, Abu1, r12, 19
|
482
|
+
ldr r0, [sp, #mDo1]
|
483
|
+
KeccakThetaRhoPiChiIota Aba0, r8, Ake1, r10, 22, Asi0, r2, 22, Ago0, r0, 11, Amu1, r12, 7, 16, 0
|
484
|
+
|
485
|
+
ldr r2, [sp, #mDi0]
|
486
|
+
KeccakThetaRhoPiChi r5, Ama1, r8, 1, r6, Abe1, r10, 22, r7, Aki1, r2, 30, r3, Aso0, r0, 14, r4, Agu1, lr, 10
|
487
|
+
KeccakThetaRhoPiChi r7, Aga1, r8, 9, r3, Ame0, r11, 1, r4, Abi1, r2, 3, r5, Ako1, r0, 13, r6, Asu1, r12, 4
|
488
|
+
KeccakThetaRhoPiChi r4, Asa0, r9, 18, r5, Age0, r11, 5, r6, Ami0, r2, 7, r7, Abo0, r0, 28, r3, Aku1, r12, 13
|
489
|
+
KeccakThetaRhoPiChi r6, Aka0, r9, 21, r7, Ase0, r10, 1, r3, Agi1, r2, 31, r4, Amo0, r0, 28, r5, Abu0, lr, 20
|
490
|
+
ldr r0, [sp, #mDo0]
|
491
|
+
KeccakThetaRhoPiChiIota Aba1, r9, Ake0, r11, 22, Asi1, r2, 21, Ago1, r0, 10, Amu0, lr, 7, 20, 0
|
492
|
+
.endm
|
493
|
+
|
494
|
+
.macro KeccakRound3
|
495
|
+
|
496
|
+
movs r2, #31
|
497
|
+
xor5 r3, Amu1, Agu0, Asu1, Aku0, Abu0
|
498
|
+
xor5 r7, Ake0, Abe1, Ame1, Age0, Ase1
|
499
|
+
xorrol r6, r3, r7
|
500
|
+
mov r8, r6
|
501
|
+
xor5 r6, Amu0, Agu1, Asu0, Aku1, Abu1
|
502
|
+
xor5 r0, Ake1, Abe0, Ame0, Age1, Ase0
|
503
|
+
xorh r9, r6, r0
|
504
|
+
|
505
|
+
xor5 r5, Asi0, Aki0, Abi1, Ami1, Agi1
|
506
|
+
xorrolR2 r5, r6
|
507
|
+
str r6, [sp, #mDo0]
|
508
|
+
xor5 r4, Asi1, Aki1, Abi0, Ami0, Agi0
|
509
|
+
eors r3, r3, r4
|
510
|
+
str r3, [sp, #mDo1]
|
511
|
+
|
512
|
+
xor5 r3, Aba0, Ama0, Aga1, Asa1, Aka0
|
513
|
+
xorrolR2 r3, r4
|
514
|
+
mov r10, r4
|
515
|
+
xor5 r6, Aba1, Ama1, Aga0, Asa0, Aka1
|
516
|
+
xorh r11, r6, r5
|
517
|
+
|
518
|
+
xor5 r4, Ago1, Aso0, Ako0, Abo0, Amo1
|
519
|
+
xorrol r5, r0, r4
|
520
|
+
str r5, [sp, #mDi0]
|
521
|
+
xor5 r5, Ago0, Aso1, Ako1, Abo1, Amo0
|
522
|
+
eors r7, r7, r5
|
523
|
+
|
524
|
+
xorrolR2 r5, r6
|
525
|
+
mov r12, r6
|
526
|
+
eors r4, r4, r3
|
527
|
+
mov lr, r4
|
528
|
+
movs r2, r7
|
529
|
+
|
530
|
+
ldr r0, [sp, #mDo0]
|
531
|
+
KeccakThetaRhoPiChi r5, Aga0, r9, 2, r6, Age0, r11, 23, r7, Agi0, r2, 31, r3, Ago0, r0, 14, r4, Agu0, r12, 10
|
532
|
+
KeccakThetaRhoPiChi r7, Aka1, r9, 9, r3, Ake1, r10, 0, r4, Aki1, r2, 3, r5, Ako1, r0, 12, r6, Aku1, lr, 4
|
533
|
+
KeccakThetaRhoPiChi r4, Ama0, r8, 18, r5, Ame0, r10, 5, r6, Ami0, r2, 8, r7, Amo0, r0, 28, r3, Amu0, lr, 14
|
534
|
+
KeccakThetaRhoPiChi r6, Asa1, r8, 20, r7, Ase1, r11, 1, r3, Asi1, r2, 31, r4, Aso1, r0, 27, r5, Asu1, r12, 19
|
535
|
+
ldr r0, [sp, #mDo1]
|
536
|
+
KeccakThetaRhoPiChiIota Aba0, r8, Abe0, r10, 22, Abi0, r2, 22, Abo0, r0, 11, Abu0, r12, 7, 24, 0
|
537
|
+
|
538
|
+
ldr r2, [sp, #mDi0]
|
539
|
+
KeccakThetaRhoPiChi r5, Aga1, r8, 1, r6, Age1, r10, 22, r7, Agi1, r2, 30, r3, Ago1, r0, 14, r4, Agu1, lr, 10
|
540
|
+
KeccakThetaRhoPiChi r7, Aka0, r8, 9, r3, Ake0, r11, 1, r4, Aki0, r2, 3, r5, Ako0, r0, 13, r6, Aku0, r12, 4
|
541
|
+
KeccakThetaRhoPiChi r4, Ama1, r9, 18, r5, Ame1, r11, 5, r6, Ami1, r2, 7, r7, Amo1, r0, 28, r3, Amu1, r12, 13
|
542
|
+
KeccakThetaRhoPiChi r6, Asa0, r9, 21, r7, Ase0, r10, 1, r3, Asi0, r2, 31, r4, Aso0, r0, 28, r5, Asu0, lr, 20
|
543
|
+
ldr r0, [sp, #mDo0]
|
544
|
+
KeccakThetaRhoPiChiIota Aba1, r9, Abe1, r11, 22, Abi1, r2, 21, Abo1, r0, 10, Abu1, lr, 7, 28, 1
|
545
|
+
.endm
|
546
|
+
|
547
|
+
@// --- code and constants
|
548
|
+
|
549
|
+
@//int crypto_hash( unsigned char *out, const unsigned char *in, unsigned long long inlen )
|
550
|
+
@// .size ???
|
551
|
+
.align 2
|
552
|
+
.global crypto_hash @// populate.py, please update crypto_hash
|
553
|
+
.thumb
|
554
|
+
.thumb_func
|
555
|
+
.type crypto_hash, %function @// populate.py, please update crypto_hash
|
556
|
+
crypto_hash: @ @// populate.py, please update crypto_hash
|
557
|
+
|
558
|
+
push {r4-r7,lr}
|
559
|
+
mov r3, r8
|
560
|
+
mov r4, r9
|
561
|
+
mov r5, r10
|
562
|
+
mov r6, r11
|
563
|
+
mov r7, r12
|
564
|
+
push {r3-r7}
|
565
|
+
sub sp, sp, #8*4
|
566
|
+
|
567
|
+
@//allocate and clear state
|
568
|
+
movs r3, #0
|
569
|
+
movs r4, r3
|
570
|
+
movs r5, r3
|
571
|
+
movs r6, r3
|
572
|
+
movs r7, r3
|
573
|
+
push {r3-r7}
|
574
|
+
push {r3-r7}
|
575
|
+
push {r3-r7}
|
576
|
+
push {r3-r7}
|
577
|
+
push {r3-r7}
|
578
|
+
push {r3-r7}
|
579
|
+
push {r3-r7}
|
580
|
+
push {r3-r7}
|
581
|
+
push {r3-r7}
|
582
|
+
push {r3-r7}
|
583
|
+
|
584
|
+
str r0, [sp, #mOut] @// save out pointer
|
585
|
+
str r1, [sp, #mIn] @// save in pointer
|
586
|
+
|
587
|
+
@// Complete rate loop
|
588
|
+
subs r2, r2, #cKeccakR_SizeInBytes
|
589
|
+
bcc crypto_hash_LoopEnd
|
590
|
+
|
591
|
+
ldr r0, =crypto_hash_LoopRet+1
|
592
|
+
str r0, [sp, #mRet] @// save return address
|
593
|
+
crypto_hash_Loop:
|
594
|
+
ldr r0, =KeccakF1600RoundConstantsWithTerminator
|
595
|
+
str r2, [sp, #mLen] @// save inlen (ignore upper 32-bit word, since CPU address space is only 32-bit wide)
|
596
|
+
str r0, [sp, #mRC] @// save Round Constants pointer
|
597
|
+
movs r2, #cKeccakR_SizeInBytes/cKeccakLaneSizeInBytes
|
598
|
+
ldr r4, =KeccakInterleaveConstants
|
599
|
+
b KeccakF_FullRate
|
600
|
+
crypto_hash_LoopRet:
|
601
|
+
ldr r2, [sp, #mLen] @// save inlen (ignore upper 32-bit word, since CPU address space is only 32-bit wide)
|
602
|
+
subs r2, r2, #cKeccakR_SizeInBytes
|
603
|
+
bcs crypto_hash_Loop
|
604
|
+
crypto_hash_LoopEnd:
|
605
|
+
adds r2, r2, #cKeccakR_SizeInBytes
|
606
|
+
|
607
|
+
@// Last incomplete lane and padding
|
608
|
+
movs r4, r2 @// r4 nbrFullLanes = len >> 3@
|
609
|
+
lsrs r4, #3
|
610
|
+
movs r6, #7 @// r6 len &= 7@ length last incomplete lane
|
611
|
+
ands r6, r6, r2
|
612
|
+
|
613
|
+
movs r0, #1 @// XOR first padding bit into state: state[nbrFullLanes << 1] ^= 1 << (len * 4)@
|
614
|
+
lsls r1, r6, #2
|
615
|
+
lsls r0, r0, r1
|
616
|
+
lsls r1, r4, #3
|
617
|
+
mov r2, sp
|
618
|
+
adds r2, r1
|
619
|
+
ldr r1, [r2]
|
620
|
+
eors r1, r1, r0
|
621
|
+
str r1, [r2]
|
622
|
+
|
623
|
+
@// XOR last incomplete lane if needed
|
624
|
+
ldr r3, [sp, #mIn] @// get in pointer
|
625
|
+
lsls r1, r4, #3 @// p = in + nbrFullLanes << 3@
|
626
|
+
adds r3, r3, r1
|
627
|
+
lsls r1, r6, #1
|
628
|
+
add pc, pc, r1
|
629
|
+
movs r0, r1 @// dummy, not executed
|
630
|
+
crypto_hash_leftBranchTab:
|
631
|
+
b crypto_hash_IncompleteDone @// 0 bytes left
|
632
|
+
b crypto_hash_1left
|
633
|
+
b crypto_hash_2left
|
634
|
+
b crypto_hash_3left
|
635
|
+
b crypto_hash_4left
|
636
|
+
b crypto_hash_5left
|
637
|
+
b crypto_hash_6left
|
638
|
+
crypto_hash_7left:
|
639
|
+
ldrh r1, [r3, #4]
|
640
|
+
ldrb r0, [r3, #6]
|
641
|
+
lsls r0, r0, #16
|
642
|
+
orrs r1, r1, r0
|
643
|
+
ldr r0, [r3]
|
644
|
+
b crypto_hash_Interleave
|
645
|
+
|
646
|
+
crypto_hash_1left:
|
647
|
+
ldrb r0, [r3]
|
648
|
+
movs r1, #0 @// x1 = 0
|
649
|
+
b crypto_hash_Interleave
|
650
|
+
crypto_hash_2left:
|
651
|
+
ldrh r0, [r3]
|
652
|
+
movs r1, #0 @// x1 = 0
|
653
|
+
b crypto_hash_Interleave
|
654
|
+
crypto_hash_3left:
|
655
|
+
ldrh r0, [r3]
|
656
|
+
ldrb r1, [r3, #2]
|
657
|
+
lsls r1, r1, #16
|
658
|
+
orrs r0, r0, r1
|
659
|
+
movs r1, #0 @// x1 = 0
|
660
|
+
b crypto_hash_Interleave
|
661
|
+
crypto_hash_4left:
|
662
|
+
ldr r0, [r3]
|
663
|
+
movs r1, #0 @// x1 = 0
|
664
|
+
b crypto_hash_Interleave
|
665
|
+
crypto_hash_5left:
|
666
|
+
ldr r0, [r3]
|
667
|
+
ldrb r1, [r3, #4]
|
668
|
+
b crypto_hash_Interleave
|
669
|
+
crypto_hash_6left:
|
670
|
+
ldr r0, [r3]
|
671
|
+
ldrh r1, [r3, #4]
|
672
|
+
|
673
|
+
crypto_hash_Interleave:
|
674
|
+
mov r8, r0
|
675
|
+
mov r9, r1
|
676
|
+
ldr r0, =KeccakInterleaveConstants
|
677
|
+
interleaveLane r8, r9, r2, r3, r6, r1, r0
|
678
|
+
lsls r7, r4, #3
|
679
|
+
add r7, r7, sp
|
680
|
+
ldr r6, [r7]
|
681
|
+
eors r6, r6, r2
|
682
|
+
str r6, [r7]
|
683
|
+
ldr r6, [r7, #4]
|
684
|
+
eors r6, r6, r3
|
685
|
+
str r6, [r7, #4]
|
686
|
+
crypto_hash_IncompleteDone:
|
687
|
+
ldr r0, [sp, #cKeccakR_SizeInBytes-4] @// XOR second padding bit into state
|
688
|
+
movs r2, #1
|
689
|
+
lsls r2, r2, #31
|
690
|
+
eors r0, r2
|
691
|
+
str r0, [sp, #cKeccakR_SizeInBytes-4]
|
692
|
+
|
693
|
+
ldr r0, =crypto_hash_SqueezeRet+1
|
694
|
+
str r0, [sp, #mRet] @// save return address
|
695
|
+
ldr r0, =KeccakF1600RoundConstantsWithTerminator
|
696
|
+
str r0, [sp, #mRC] @// save Round Constants pointer
|
697
|
+
movs r2, r4
|
698
|
+
ldr r4, =KeccakInterleaveConstants
|
699
|
+
b KeccakF
|
700
|
+
crypto_hash_SqueezeRet:
|
701
|
+
|
702
|
+
ldr r7, [sp, #mOut] @// save return address
|
703
|
+
movs r4, #crypto_hash_BYTES/cKeccakLaneSizeInBytes @len = crypto_hash_BYTES / cKeccakLaneSizeInBytes@
|
704
|
+
mov r3, sp
|
705
|
+
ldr r6, =KeccakUninterleaveConstants
|
706
|
+
crypto_hash_OutputLoop:
|
707
|
+
ldr r0, [r3]
|
708
|
+
ldr r1, [r3, #4]
|
709
|
+
adds r3, r3, #8
|
710
|
+
uninterleaveLane r0, r1, r2, r5, r6
|
711
|
+
str r0, [r7]
|
712
|
+
str r1, [r7, #4]
|
713
|
+
adds r7, r7, #8
|
714
|
+
subs r4, r4, #1
|
715
|
+
bne crypto_hash_OutputLoop
|
716
|
+
|
717
|
+
add sp, sp, #5*5*2*4+8*4
|
718
|
+
movs r0, #0
|
719
|
+
pop {r3-r7}
|
720
|
+
mov r8, r3
|
721
|
+
mov r9, r4
|
722
|
+
mov r10, r5
|
723
|
+
mov r11, r6
|
724
|
+
mov r12, r7
|
725
|
+
pop {r4-r7,pc}
|
726
|
+
|
727
|
+
@ nop @// pad for alignment
|
728
|
+
|
729
|
+
@ ALIGN
|
730
|
+
.ltorg
|
731
|
+
KeccakInterleaveConstants:
|
732
|
+
.word 0x55555555
|
733
|
+
.word 0x33333333
|
734
|
+
.word 0x0F0F0F0F
|
735
|
+
.word 0x00FF00FF
|
736
|
+
|
737
|
+
.word 0xAAAAAAAA
|
738
|
+
.word 0xCCCCCCCC
|
739
|
+
.word 0xF0F0F0F0
|
740
|
+
.word 0xFF00FF00
|
741
|
+
|
742
|
+
KeccakUninterleaveConstants:
|
743
|
+
.word 0x0000FF00
|
744
|
+
.word 0x00F000F0
|
745
|
+
.word 0x0C0C0C0C
|
746
|
+
.word 0x22222222
|
747
|
+
|
748
|
+
|
749
|
+
KeccakF1600RoundConstantsWithTerminator:
|
750
|
+
.word 0x00000001
|
751
|
+
.word 0x00000000
|
752
|
+
.word 0x00000000
|
753
|
+
.word 0x00000089
|
754
|
+
.word 0x00000000
|
755
|
+
.word 0x8000008b
|
756
|
+
.word 0x00000000
|
757
|
+
.word 0x80008080
|
758
|
+
|
759
|
+
.word 0x00000001
|
760
|
+
.word 0x0000008b
|
761
|
+
.word 0x00000001
|
762
|
+
.word 0x00008000
|
763
|
+
.word 0x00000001
|
764
|
+
.word 0x80008088
|
765
|
+
.word 0x00000001
|
766
|
+
.word 0x80000082
|
767
|
+
|
768
|
+
.word 0x00000000
|
769
|
+
.word 0x0000000b
|
770
|
+
.word 0x00000000
|
771
|
+
.word 0x0000000a
|
772
|
+
.word 0x00000001
|
773
|
+
.word 0x00008082
|
774
|
+
.word 0x00000000
|
775
|
+
.word 0x00008003
|
776
|
+
|
777
|
+
.word 0x00000001
|
778
|
+
.word 0x0000808b
|
779
|
+
.word 0x00000001
|
780
|
+
.word 0x8000000b
|
781
|
+
.word 0x00000001
|
782
|
+
.word 0x8000008a
|
783
|
+
.word 0x00000001
|
784
|
+
.word 0x80000081
|
785
|
+
|
786
|
+
.word 0x00000000
|
787
|
+
.word 0x80000081
|
788
|
+
.word 0x00000000
|
789
|
+
.word 0x80000008
|
790
|
+
.word 0x00000000
|
791
|
+
.word 0x00000083
|
792
|
+
.word 0x00000000
|
793
|
+
.word 0x80008003
|
794
|
+
|
795
|
+
.word 0x00000001
|
796
|
+
.word 0x80008088
|
797
|
+
.word 0x00000000
|
798
|
+
.word 0x80000088
|
799
|
+
.word 0x00000001
|
800
|
+
.word 0x00008000
|
801
|
+
.word 0x00000000
|
802
|
+
.word 0x80008082
|
803
|
+
|
804
|
+
.word 0xFFFFFFFF @//terminator
|
805
|
+
|
806
|
+
KeccakF:
|
807
|
+
cmp r2, #0
|
808
|
+
beq roundLoop
|
809
|
+
KeccakF_FullRate:
|
810
|
+
mov r0, sp
|
811
|
+
ldr r1, [sp, #mIn]
|
812
|
+
interleaveLoop:
|
813
|
+
ldr r5, [r1]
|
814
|
+
mov r8, r5
|
815
|
+
ldr r5, [r1, #4]
|
816
|
+
mov r9, r5
|
817
|
+
adds r1, #8
|
818
|
+
interleaveLane r8, r9, r6, r7, r3, r5, r4
|
819
|
+
ldr r5, [r0]
|
820
|
+
eors r6, r6, r5
|
821
|
+
str r6, [r0]
|
822
|
+
ldr r5, [r0, #4]
|
823
|
+
eors r7, r7, r5
|
824
|
+
str r7, [r0, #4]
|
825
|
+
adds r0, #8
|
826
|
+
subs r2, r2, #1
|
827
|
+
bne interleaveLoop
|
828
|
+
str r1, [sp, #mIn]
|
829
|
+
|
830
|
+
roundLoop:
|
831
|
+
KeccakRound0
|
832
|
+
KeccakRound1
|
833
|
+
KeccakRound2
|
834
|
+
KeccakRound3
|
835
|
+
beq KeccakF_Done
|
836
|
+
ldr r1, =roundLoop
|
837
|
+
bx r1
|
838
|
+
KeccakF_Done:
|
839
|
+
ldr r7, [sp, #mRet]
|
840
|
+
bx r7
|
841
|
+
|
842
|
+
@
|
843
|
+
@ ALIGN
|
844
|
+
|