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,436 @@
|
|
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
|
+
|
7
|
+
|
8
|
+
#include <stdio.h>
|
9
|
+
|
10
|
+
/************** Timing routine (for performance measurements) ***********/
|
11
|
+
/* By Doug Whiting */
|
12
|
+
/* unfortunately, this is generally assembly code and not very portable */
|
13
|
+
#if defined(_M_IX86) || defined(__i386) || defined(_i386) || defined(__i386__) || defined(i386) || \
|
14
|
+
defined(_X86_) || defined(__x86_64__) || defined(_M_X64) || defined(__x86_64)
|
15
|
+
#define _Is_X86_ 1
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#if defined(_Is_X86_) && (!defined(__STRICT_ANSI__)) && (defined(__GNUC__) || !defined(__STDC__)) && \
|
19
|
+
(defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW_H) || defined(__GNUC__))
|
20
|
+
#define HI_RES_CLK_OK 1 /* it's ok to use RDTSC opcode */
|
21
|
+
|
22
|
+
#if defined(_MSC_VER) // && defined(_M_X64)
|
23
|
+
#include <intrin.h>
|
24
|
+
#pragma intrinsic(__rdtsc) /* use MSVC rdtsc call where defined */
|
25
|
+
#endif
|
26
|
+
|
27
|
+
#endif
|
28
|
+
|
29
|
+
typedef unsigned int uint_32t;
|
30
|
+
|
31
|
+
uint_32t HiResTime(void) /* return the current value of time stamp counter */
|
32
|
+
{
|
33
|
+
#if defined(HI_RES_CLK_OK)
|
34
|
+
uint_32t x[2];
|
35
|
+
#if defined(__BORLANDC__)
|
36
|
+
#define COMPILER_ID "BCC"
|
37
|
+
__emit__(0x0F,0x31); /* RDTSC instruction */
|
38
|
+
_asm { mov x[0],eax };
|
39
|
+
#elif defined(_MSC_VER)
|
40
|
+
#define COMPILER_ID "MSC"
|
41
|
+
#if defined(_MSC_VER) // && defined(_M_X64)
|
42
|
+
x[0] = (uint_32t) __rdtsc();
|
43
|
+
#else
|
44
|
+
_asm { _emit 0fh }; _asm { _emit 031h };
|
45
|
+
_asm { mov x[0],eax };
|
46
|
+
#endif
|
47
|
+
#elif defined(__MINGW_H) || defined(__GNUC__)
|
48
|
+
#define COMPILER_ID "GCC"
|
49
|
+
asm volatile("rdtsc" : "=a"(x[0]), "=d"(x[1]));
|
50
|
+
#else
|
51
|
+
#error "HI_RES_CLK_OK -- but no assembler code for this platform (?)"
|
52
|
+
#endif
|
53
|
+
return x[0];
|
54
|
+
#else
|
55
|
+
/* avoid annoying MSVC 9.0 compiler warning #4720 in ANSI mode! */
|
56
|
+
#if (!defined(_MSC_VER)) || (!defined(__STDC__)) || (_MSC_VER < 1300)
|
57
|
+
FatalError("No support for RDTSC on this CPU platform\n");
|
58
|
+
#endif
|
59
|
+
return 0;
|
60
|
+
#endif /* defined(HI_RES_CLK_OK) */
|
61
|
+
}
|
62
|
+
|
63
|
+
#define TIMER_SAMPLE_CNT (100)
|
64
|
+
|
65
|
+
uint_32t calibrate()
|
66
|
+
{
|
67
|
+
uint_32t dtMin = 0xFFFFFFFF; /* big number to start */
|
68
|
+
uint_32t t0,t1,i;
|
69
|
+
|
70
|
+
for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
|
71
|
+
{
|
72
|
+
t0 = HiResTime();
|
73
|
+
t1 = HiResTime();
|
74
|
+
if (dtMin > t1-t0) /* keep only the minimum time */
|
75
|
+
dtMin = t1-t0;
|
76
|
+
}
|
77
|
+
return dtMin;
|
78
|
+
}
|
79
|
+
|
80
|
+
#include "KeccakF-1600-interface.h"
|
81
|
+
#include "KeccakNISTInterface.h"
|
82
|
+
|
83
|
+
uint_32t measureKeccakAbsorb1024bits(uint_32t dtMin)
|
84
|
+
{
|
85
|
+
uint_32t tMin = 0xFFFFFFFF; /* big number to start */
|
86
|
+
uint_32t t0,t1,i;
|
87
|
+
ALIGN unsigned char state[KeccakPermutationSizeInBytes];
|
88
|
+
ALIGN unsigned char input[128];
|
89
|
+
|
90
|
+
for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
|
91
|
+
{
|
92
|
+
t0 = HiResTime();
|
93
|
+
#ifdef ProvideFast1024
|
94
|
+
KeccakAbsorb1024bits(state, input);
|
95
|
+
#else
|
96
|
+
KeccakAbsorb(state, input, 1024/64);
|
97
|
+
#endif
|
98
|
+
t1 = HiResTime();
|
99
|
+
if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
|
100
|
+
tMin = t1-t0 - dtMin;
|
101
|
+
}
|
102
|
+
|
103
|
+
/* now tMin = # clocks required for running RoutineToBeTimed() */
|
104
|
+
|
105
|
+
return tMin;
|
106
|
+
}
|
107
|
+
|
108
|
+
uint_32t measureKeccakAbsorb1088bits(uint_32t dtMin)
|
109
|
+
{
|
110
|
+
uint_32t tMin = 0xFFFFFFFF; /* big number to start */
|
111
|
+
uint_32t t0,t1,i;
|
112
|
+
ALIGN unsigned char state[KeccakPermutationSizeInBytes];
|
113
|
+
ALIGN unsigned char input[136];
|
114
|
+
|
115
|
+
for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
|
116
|
+
{
|
117
|
+
t0 = HiResTime();
|
118
|
+
#ifdef ProvideFast1088
|
119
|
+
KeccakAbsorb1088bits(state, input);
|
120
|
+
#else
|
121
|
+
KeccakAbsorb(state, input, 1088/64);
|
122
|
+
#endif
|
123
|
+
t1 = HiResTime();
|
124
|
+
if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
|
125
|
+
tMin = t1-t0 - dtMin;
|
126
|
+
}
|
127
|
+
|
128
|
+
/* now tMin = # clocks required for running RoutineToBeTimed() */
|
129
|
+
|
130
|
+
return tMin;
|
131
|
+
}
|
132
|
+
|
133
|
+
uint_32t measureKeccakAbsorb1344bits(uint_32t dtMin)
|
134
|
+
{
|
135
|
+
uint_32t tMin = 0xFFFFFFFF; /* big number to start */
|
136
|
+
uint_32t t0,t1,i;
|
137
|
+
ALIGN unsigned char state[KeccakPermutationSizeInBytes];
|
138
|
+
ALIGN unsigned char input[200];
|
139
|
+
|
140
|
+
for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
|
141
|
+
{
|
142
|
+
t0 = HiResTime();
|
143
|
+
#ifdef ProvideFast1344
|
144
|
+
KeccakAbsorb1344bits(state, input);
|
145
|
+
#else
|
146
|
+
KeccakAbsorb(state, input, 1344/64);
|
147
|
+
#endif
|
148
|
+
t1 = HiResTime();
|
149
|
+
if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
|
150
|
+
tMin = t1-t0 - dtMin;
|
151
|
+
}
|
152
|
+
|
153
|
+
/* now tMin = # clocks required for running RoutineToBeTimed() */
|
154
|
+
|
155
|
+
return tMin;
|
156
|
+
}
|
157
|
+
|
158
|
+
uint_32t measureKeccakAbsorb(uint_32t dtMin, unsigned int laneCount)
|
159
|
+
{
|
160
|
+
uint_32t tMin = 0xFFFFFFFF; /* big number to start */
|
161
|
+
uint_32t t0,t1,i;
|
162
|
+
ALIGN unsigned char state[KeccakPermutationSizeInBytes];
|
163
|
+
ALIGN unsigned char input[64];
|
164
|
+
|
165
|
+
for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
|
166
|
+
{
|
167
|
+
t0 = HiResTime();
|
168
|
+
KeccakAbsorb(state, input, laneCount);
|
169
|
+
t1 = HiResTime();
|
170
|
+
if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
|
171
|
+
tMin = t1-t0 - dtMin;
|
172
|
+
}
|
173
|
+
|
174
|
+
/* now tMin = # clocks required for running RoutineToBeTimed() */
|
175
|
+
|
176
|
+
return tMin;
|
177
|
+
}
|
178
|
+
|
179
|
+
uint_32t measureKeccakPermutation(uint_32t dtMin)
|
180
|
+
{
|
181
|
+
uint_32t tMin = 0xFFFFFFFF; /* big number to start */
|
182
|
+
uint_32t t0,t1,i;
|
183
|
+
ALIGN unsigned char state[KeccakPermutationSizeInBytes];
|
184
|
+
|
185
|
+
for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
|
186
|
+
{
|
187
|
+
t0 = HiResTime();
|
188
|
+
KeccakPermutation(state);
|
189
|
+
t1 = HiResTime();
|
190
|
+
if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
|
191
|
+
tMin = t1-t0 - dtMin;
|
192
|
+
}
|
193
|
+
|
194
|
+
/* now tMin = # clocks required for running RoutineToBeTimed() */
|
195
|
+
|
196
|
+
return tMin;
|
197
|
+
}
|
198
|
+
|
199
|
+
uint_32t measureKeccakHash1block(uint_32t dtMin)
|
200
|
+
{
|
201
|
+
uint_32t tMin = 0xFFFFFFFF; /* big number to start */
|
202
|
+
uint_32t t0,t1,i;
|
203
|
+
hashState state;
|
204
|
+
ALIGN unsigned char data[128];
|
205
|
+
|
206
|
+
for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
|
207
|
+
{
|
208
|
+
t0 = HiResTime();
|
209
|
+
Init(&state, 0);
|
210
|
+
Update(&state, data, 29);
|
211
|
+
Final(&state, 0);
|
212
|
+
t1 = HiResTime();
|
213
|
+
if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
|
214
|
+
tMin = t1-t0 - dtMin;
|
215
|
+
}
|
216
|
+
|
217
|
+
/* now tMin = # clocks required for running RoutineToBeTimed() */
|
218
|
+
|
219
|
+
return tMin;
|
220
|
+
}
|
221
|
+
|
222
|
+
uint_32t measureKeccakHash2blocks(uint_32t dtMin)
|
223
|
+
{
|
224
|
+
uint_32t tMin = 0xFFFFFFFF; /* big number to start */
|
225
|
+
uint_32t t0,t1,i;
|
226
|
+
hashState state;
|
227
|
+
ALIGN unsigned char data[256];
|
228
|
+
|
229
|
+
for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
|
230
|
+
{
|
231
|
+
t0 = HiResTime();
|
232
|
+
Init(&state, 0);
|
233
|
+
Update(&state, data, 1024+29);
|
234
|
+
Final(&state, 0);
|
235
|
+
t1 = HiResTime();
|
236
|
+
if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
|
237
|
+
tMin = t1-t0 - dtMin;
|
238
|
+
}
|
239
|
+
|
240
|
+
/* now tMin = # clocks required for running RoutineToBeTimed() */
|
241
|
+
|
242
|
+
return tMin;
|
243
|
+
}
|
244
|
+
|
245
|
+
uint_32t measureKeccakHash3blocks(uint_32t dtMin)
|
246
|
+
{
|
247
|
+
uint_32t tMin = 0xFFFFFFFF; /* big number to start */
|
248
|
+
uint_32t t0,t1,i;
|
249
|
+
hashState state;
|
250
|
+
ALIGN unsigned char data[384];
|
251
|
+
|
252
|
+
for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
|
253
|
+
{
|
254
|
+
t0 = HiResTime();
|
255
|
+
Init(&state, 0);
|
256
|
+
Update(&state, data, 2048+29);
|
257
|
+
Final(&state, 0);
|
258
|
+
t1 = HiResTime();
|
259
|
+
if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
|
260
|
+
tMin = t1-t0 - dtMin;
|
261
|
+
}
|
262
|
+
|
263
|
+
/* now tMin = # clocks required for running RoutineToBeTimed() */
|
264
|
+
|
265
|
+
return tMin;
|
266
|
+
}
|
267
|
+
|
268
|
+
uint_32t measureKeccakHash10blocks(uint_32t dtMin)
|
269
|
+
{
|
270
|
+
uint_32t tMin = 0xFFFFFFFF; /* big number to start */
|
271
|
+
uint_32t t0,t1,i;
|
272
|
+
hashState state;
|
273
|
+
ALIGN unsigned char data[10*128];
|
274
|
+
|
275
|
+
for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
|
276
|
+
{
|
277
|
+
t0 = HiResTime();
|
278
|
+
Init(&state, 0);
|
279
|
+
Update(&state, data, 9*1024+29);
|
280
|
+
Final(&state, 0);
|
281
|
+
t1 = HiResTime();
|
282
|
+
if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
|
283
|
+
tMin = t1-t0 - dtMin;
|
284
|
+
}
|
285
|
+
|
286
|
+
/* now tMin = # clocks required for running RoutineToBeTimed() */
|
287
|
+
|
288
|
+
return tMin;
|
289
|
+
}
|
290
|
+
|
291
|
+
uint_32t measureKeccakHash30blocks(uint_32t dtMin)
|
292
|
+
{
|
293
|
+
uint_32t tMin = 0xFFFFFFFF; /* big number to start */
|
294
|
+
uint_32t t0,t1,i;
|
295
|
+
hashState state;
|
296
|
+
ALIGN unsigned char data[30*128];
|
297
|
+
|
298
|
+
for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
|
299
|
+
{
|
300
|
+
t0 = HiResTime();
|
301
|
+
Init(&state, 0);
|
302
|
+
Update(&state, data, 29*1024+29);
|
303
|
+
Final(&state, 0);
|
304
|
+
t1 = HiResTime();
|
305
|
+
if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
|
306
|
+
tMin = t1-t0 - dtMin;
|
307
|
+
}
|
308
|
+
|
309
|
+
/* now tMin = # clocks required for running RoutineToBeTimed() */
|
310
|
+
|
311
|
+
return tMin;
|
312
|
+
}
|
313
|
+
|
314
|
+
uint_32t measureKeccakHash100blocks(uint_32t dtMin)
|
315
|
+
{
|
316
|
+
uint_32t tMin = 0xFFFFFFFF; /* big number to start */
|
317
|
+
uint_32t t0,t1,i;
|
318
|
+
hashState state;
|
319
|
+
ALIGN unsigned char data[100*128];
|
320
|
+
|
321
|
+
for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
|
322
|
+
{
|
323
|
+
t0 = HiResTime();
|
324
|
+
Init(&state, 0);
|
325
|
+
Update(&state, data, 99*1024+29);
|
326
|
+
Final(&state, 0);
|
327
|
+
t1 = HiResTime();
|
328
|
+
if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
|
329
|
+
tMin = t1-t0 - dtMin;
|
330
|
+
}
|
331
|
+
|
332
|
+
/* now tMin = # clocks required for running RoutineToBeTimed() */
|
333
|
+
|
334
|
+
return tMin;
|
335
|
+
}
|
336
|
+
|
337
|
+
uint_32t measureKeccakHash1000blocks(uint_32t dtMin)
|
338
|
+
{
|
339
|
+
uint_32t tMin = 0xFFFFFFFF; /* big number to start */
|
340
|
+
uint_32t t0,t1,i;
|
341
|
+
hashState state;
|
342
|
+
ALIGN unsigned char data[1000*128];
|
343
|
+
|
344
|
+
for (i=0;i < TIMER_SAMPLE_CNT;i++) /* calibrate the overhead for measuring time */
|
345
|
+
{
|
346
|
+
t0 = HiResTime();
|
347
|
+
Init(&state, 0);
|
348
|
+
Update(&state, data, 999*1024+29);
|
349
|
+
Final(&state, 0);
|
350
|
+
t1 = HiResTime();
|
351
|
+
if (tMin > t1-t0 - dtMin) /* keep only the minimum time */
|
352
|
+
tMin = t1-t0 - dtMin;
|
353
|
+
}
|
354
|
+
|
355
|
+
/* now tMin = # clocks required for running RoutineToBeTimed() */
|
356
|
+
|
357
|
+
return tMin;
|
358
|
+
}
|
359
|
+
|
360
|
+
void doTiming()
|
361
|
+
{
|
362
|
+
uint_32t calibration;
|
363
|
+
uint_32t measurementKeccakPermutation;
|
364
|
+
uint_32t measurementKeccakAbsorb1024bits;
|
365
|
+
uint_32t measurementKeccakAbsorb1088bits;
|
366
|
+
uint_32t measurementKeccakAbsorb1344bits;
|
367
|
+
uint_32t measurementKeccakAbsorb;
|
368
|
+
uint_32t measurementKeccakHash1block;
|
369
|
+
uint_32t measurementKeccakHash2blocks;
|
370
|
+
uint_32t measurementKeccakHash3blocks;
|
371
|
+
uint_32t measurementKeccakHash10blocks;
|
372
|
+
uint_32t measurementKeccakHash30blocks;
|
373
|
+
uint_32t measurementKeccakHash100blocks;
|
374
|
+
uint_32t measurementKeccakHash1000blocks;
|
375
|
+
|
376
|
+
calibration = calibrate();
|
377
|
+
|
378
|
+
measurementKeccakPermutation = measureKeccakPermutation(calibration);
|
379
|
+
printf("Cycles for KeccakPermutation(state): %d\n", measurementKeccakPermutation);
|
380
|
+
printf("Cycles per byte for rate 1024: %f\n", measurementKeccakPermutation/128.0);
|
381
|
+
printf("\n");
|
382
|
+
|
383
|
+
measurementKeccakAbsorb1024bits = measureKeccakAbsorb1024bits(calibration);
|
384
|
+
printf("Cycles for KeccakAbsorb1024bits(state, input): %d\n", measurementKeccakAbsorb1024bits);
|
385
|
+
printf("Cycles per byte for rate 1024: %f\n", measurementKeccakAbsorb1024bits/128.0);
|
386
|
+
printf("\n");
|
387
|
+
|
388
|
+
measurementKeccakAbsorb1088bits = measureKeccakAbsorb1088bits(calibration);
|
389
|
+
printf("Cycles for KeccakAbsorb1088bits(state, input): %d\n", measurementKeccakAbsorb1088bits);
|
390
|
+
printf("Cycles per byte for rate 1088: %f\n", measurementKeccakAbsorb1088bits/136.0);
|
391
|
+
printf("\n");
|
392
|
+
|
393
|
+
measurementKeccakAbsorb1344bits = measureKeccakAbsorb1344bits(calibration);
|
394
|
+
printf("Cycles for KeccakAbsorb1344bits(state, input): %d\n", measurementKeccakAbsorb1344bits);
|
395
|
+
printf("Cycles per byte for rate 1344: %f\n", measurementKeccakAbsorb1344bits/168.0);
|
396
|
+
printf("\n");
|
397
|
+
|
398
|
+
measurementKeccakAbsorb = measureKeccakAbsorb(calibration, 18);
|
399
|
+
printf("Cycles for KeccakAbsorb(state, input, 1152bits): %d\n", measurementKeccakAbsorb);
|
400
|
+
printf("Cycles per byte for rate 1152: %f\n", measurementKeccakAbsorb/144.0);
|
401
|
+
measurementKeccakAbsorb = measureKeccakAbsorb(calibration, 13);
|
402
|
+
printf("Cycles for KeccakAbsorb(state, input, 832bits): %d\n", measurementKeccakAbsorb);
|
403
|
+
printf("Cycles per byte for rate 832: %f\n", measurementKeccakAbsorb/104.0);
|
404
|
+
measurementKeccakAbsorb = measureKeccakAbsorb(calibration, 9);
|
405
|
+
printf("Cycles for KeccakAbsorb(state, input, 576bits): %d\n", measurementKeccakAbsorb);
|
406
|
+
printf("Cycles per byte for rate 576: %f\n", measurementKeccakAbsorb/72.0);
|
407
|
+
printf("\n");
|
408
|
+
|
409
|
+
measurementKeccakHash1block = measureKeccakHash1block(calibration);
|
410
|
+
printf("Cycles for Init, Update, Finalize (1 block): %d\n", measurementKeccakHash1block);
|
411
|
+
printf("\n");
|
412
|
+
|
413
|
+
measurementKeccakHash2blocks = measureKeccakHash2blocks(calibration);
|
414
|
+
printf("Cycles for Init, Update, Finalize (2 blocks): %d\n", measurementKeccakHash2blocks);
|
415
|
+
printf("\n");
|
416
|
+
|
417
|
+
measurementKeccakHash3blocks = measureKeccakHash3blocks(calibration);
|
418
|
+
printf("Cycles for Init, Update, Finalize (3 blocks): %d\n", measurementKeccakHash3blocks);
|
419
|
+
printf("\n");
|
420
|
+
|
421
|
+
measurementKeccakHash10blocks = measureKeccakHash10blocks(calibration);
|
422
|
+
printf("Cycles for Init, Update, Finalize (10 blocks): %d\n", measurementKeccakHash10blocks);
|
423
|
+
printf("\n");
|
424
|
+
|
425
|
+
measurementKeccakHash30blocks = measureKeccakHash30blocks(calibration);
|
426
|
+
printf("Cycles for Init, Update, Finalize (30 blocks): %d\n", measurementKeccakHash30blocks);
|
427
|
+
printf("\n");
|
428
|
+
|
429
|
+
measurementKeccakHash100blocks = measureKeccakHash100blocks(calibration);
|
430
|
+
printf("Cycles for Init, Update, Finalize (100 blocks): %d\n", measurementKeccakHash100blocks);
|
431
|
+
printf("\n");
|
432
|
+
|
433
|
+
measurementKeccakHash1000blocks = measureKeccakHash1000blocks(calibration);
|
434
|
+
printf("Cycles for Init, Update, Finalize (1000 blocks): %d\n", measurementKeccakHash1000blocks);
|
435
|
+
printf("\n");
|
436
|
+
}
|
@@ -0,0 +1,13 @@
|
|
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
|
+
|
7
|
+
#ifndef _timing_h_
|
8
|
+
#define _timing_h_
|
9
|
+
|
10
|
+
void doTiming();
|
11
|
+
|
12
|
+
#endif
|
13
|
+
|