sleeping_kangaroo12 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +127 -0
- data/ext/Rakefile +73 -0
- data/ext/binding/sleeping_kangaroo12.c +39 -0
- data/ext/config/xkcp.build +17 -0
- data/ext/xkcp/LICENSE +1 -0
- data/ext/xkcp/Makefile +15 -0
- data/ext/xkcp/Makefile.build +200 -0
- data/ext/xkcp/README.markdown +296 -0
- data/ext/xkcp/lib/HighLevel.build +143 -0
- data/ext/xkcp/lib/LowLevel.build +757 -0
- data/ext/xkcp/lib/common/align.h +33 -0
- data/ext/xkcp/lib/common/brg_endian.h +143 -0
- data/ext/xkcp/lib/high/KangarooTwelve/KangarooTwelve.c +301 -0
- data/ext/xkcp/lib/high/KangarooTwelve/KangarooTwelve.h +97 -0
- data/ext/xkcp/lib/high/Keccak/FIPS202/KeccakHash.c +81 -0
- data/ext/xkcp/lib/high/Keccak/FIPS202/KeccakHash.h +125 -0
- data/ext/xkcp/lib/high/Keccak/FIPS202/SimpleFIPS202.c +48 -0
- data/ext/xkcp/lib/high/Keccak/FIPS202/SimpleFIPS202.h +79 -0
- data/ext/xkcp/lib/high/Keccak/KeccakDuplex.c +81 -0
- data/ext/xkcp/lib/high/Keccak/KeccakDuplex.h +73 -0
- data/ext/xkcp/lib/high/Keccak/KeccakDuplex.inc +195 -0
- data/ext/xkcp/lib/high/Keccak/KeccakSponge.c +111 -0
- data/ext/xkcp/lib/high/Keccak/KeccakSponge.h +76 -0
- data/ext/xkcp/lib/high/Keccak/KeccakSponge.inc +314 -0
- data/ext/xkcp/lib/high/Keccak/PRG/KeccakPRG.c +61 -0
- data/ext/xkcp/lib/high/Keccak/PRG/KeccakPRG.h +67 -0
- data/ext/xkcp/lib/high/Keccak/PRG/KeccakPRG.inc +128 -0
- data/ext/xkcp/lib/high/Keccak/SP800-185/SP800-185.c +93 -0
- data/ext/xkcp/lib/high/Keccak/SP800-185/SP800-185.h +599 -0
- data/ext/xkcp/lib/high/Keccak/SP800-185/SP800-185.inc +573 -0
- data/ext/xkcp/lib/high/Ketje/Ketjev2.c +87 -0
- data/ext/xkcp/lib/high/Ketje/Ketjev2.h +88 -0
- data/ext/xkcp/lib/high/Ketje/Ketjev2.inc +274 -0
- data/ext/xkcp/lib/high/Keyak/Keyakv2.c +132 -0
- data/ext/xkcp/lib/high/Keyak/Keyakv2.h +217 -0
- data/ext/xkcp/lib/high/Keyak/Keyakv2.inc +81 -0
- data/ext/xkcp/lib/high/Keyak/Motorist.inc +953 -0
- data/ext/xkcp/lib/high/Kravatte/Kravatte.c +533 -0
- data/ext/xkcp/lib/high/Kravatte/Kravatte.h +115 -0
- data/ext/xkcp/lib/high/Kravatte/KravatteModes.c +557 -0
- data/ext/xkcp/lib/high/Kravatte/KravatteModes.h +247 -0
- data/ext/xkcp/lib/high/Xoodyak/Cyclist.h +66 -0
- data/ext/xkcp/lib/high/Xoodyak/Cyclist.inc +336 -0
- data/ext/xkcp/lib/high/Xoodyak/Xoodyak-parameters.h +26 -0
- data/ext/xkcp/lib/high/Xoodyak/Xoodyak.c +55 -0
- data/ext/xkcp/lib/high/Xoodyak/Xoodyak.h +35 -0
- data/ext/xkcp/lib/high/Xoofff/Xoofff.c +634 -0
- data/ext/xkcp/lib/high/Xoofff/Xoofff.h +147 -0
- data/ext/xkcp/lib/high/Xoofff/XoofffModes.c +483 -0
- data/ext/xkcp/lib/high/Xoofff/XoofffModes.h +241 -0
- data/ext/xkcp/lib/high/common/Phases.h +25 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARM/KeccakP-1600-SnP.h +41 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARM/KeccakP-1600-inplace-32bi-armv6m-le-armcc.s +1666 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARM/KeccakP-1600-inplace-32bi-armv6m-le-gcc.s +1655 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARM/KeccakP-1600-inplace-32bi-armv7a-le-armcc.s +1268 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARM/KeccakP-1600-inplace-32bi-armv7a-le-gcc.s +1264 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARM/KeccakP-1600-inplace-32bi-armv7m-le-armcc.s +1178 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARM/KeccakP-1600-inplace-32bi-armv7m-le-gcc.s +1175 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARM/KeccakP-1600-u1-32bi-armv6m-le-armcc.s +1338 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARM/KeccakP-1600-u1-32bi-armv6m-le-gcc.s +1336 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARM/KeccakP-1600-u2-32bi-armv6m-le-armcc.s +1343 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARM/KeccakP-1600-u2-32bi-armv6m-le-gcc.s +1339 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARMv7A-NEON/KeccakP-1600-SnP.h +42 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARMv7A-NEON/KeccakP-1600-armv7a-le-neon-armcc.s +823 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARMv7A-NEON/KeccakP-1600-armv7a-le-neon-gcc.s +831 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARMv8A/KeccakP-1600-SnP.h +31 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ARMv8A/KeccakP-1600-armv8a-neon.s +540 -0
- data/ext/xkcp/lib/low/KeccakP-1600/AVR8/KeccakP-1600-SnP.h +42 -0
- data/ext/xkcp/lib/low/KeccakP-1600/AVR8/KeccakP-1600-avr8-compact.s +733 -0
- data/ext/xkcp/lib/low/KeccakP-1600/AVR8/KeccakP-1600-avr8-fast.s +1121 -0
- data/ext/xkcp/lib/low/KeccakP-1600/AVX2/KeccakP-1600-AVX2.s +1100 -0
- data/ext/xkcp/lib/low/KeccakP-1600/AVX2/KeccakP-1600-SnP.h +52 -0
- data/ext/xkcp/lib/low/KeccakP-1600/AVX512/C/KeccakP-1600-AVX512.c +623 -0
- data/ext/xkcp/lib/low/KeccakP-1600/AVX512/C/KeccakP-1600-SnP.h +47 -0
- data/ext/xkcp/lib/low/KeccakP-1600/AVX512/C/u12/KeccakP-1600-AVX512-config.h +6 -0
- data/ext/xkcp/lib/low/KeccakP-1600/AVX512/C/u6/KeccakP-1600-AVX512-config.h +6 -0
- data/ext/xkcp/lib/low/KeccakP-1600/AVX512/C/ua/KeccakP-1600-AVX512-config.h +6 -0
- data/ext/xkcp/lib/low/KeccakP-1600/AVX512/KeccakP-1600-AVX512.s +1031 -0
- data/ext/xkcp/lib/low/KeccakP-1600/AVX512/KeccakP-1600-SnP.h +53 -0
- data/ext/xkcp/lib/low/KeccakP-1600/XOP/KeccakP-1600-SnP.h +44 -0
- data/ext/xkcp/lib/low/KeccakP-1600/XOP/KeccakP-1600-XOP.c +476 -0
- data/ext/xkcp/lib/low/KeccakP-1600/XOP/u6/KeccakP-1600-XOP-config.h +6 -0
- data/ext/xkcp/lib/low/KeccakP-1600/XOP/ua/KeccakP-1600-XOP-config.h +6 -0
- data/ext/xkcp/lib/low/KeccakP-1600/common/KeccakP-1600-64.macros +748 -0
- data/ext/xkcp/lib/low/KeccakP-1600/common/KeccakP-1600-unrolling.macros +305 -0
- data/ext/xkcp/lib/low/KeccakP-1600/compact/KeccakP-1600-SnP.h +40 -0
- data/ext/xkcp/lib/low/KeccakP-1600/compact/KeccakP-1600-compact64.c +420 -0
- data/ext/xkcp/lib/low/KeccakP-1600/plain-32bits-inplace/KeccakP-1600-SnP.h +43 -0
- data/ext/xkcp/lib/low/KeccakP-1600/plain-32bits-inplace/KeccakP-1600-inplace32BI.c +1163 -0
- data/ext/xkcp/lib/low/KeccakP-1600/plain-64bits/KeccakP-1600-SnP.h +54 -0
- data/ext/xkcp/lib/low/KeccakP-1600/plain-64bits/KeccakP-1600-opt64.c +565 -0
- data/ext/xkcp/lib/low/KeccakP-1600/plain-64bits/lcu6/KeccakP-1600-opt64-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600/plain-64bits/lcua/KeccakP-1600-opt64-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600/plain-64bits/lcua-shld/KeccakP-1600-opt64-config.h +8 -0
- data/ext/xkcp/lib/low/KeccakP-1600/plain-64bits/u6/KeccakP-1600-opt64-config.h +6 -0
- data/ext/xkcp/lib/low/KeccakP-1600/plain-64bits/ua/KeccakP-1600-opt64-config.h +6 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-SnP.h +44 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference.h +23 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference32BI.c +625 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-SnP.h +44 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.c +440 -0
- data/ext/xkcp/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.h +23 -0
- data/ext/xkcp/lib/low/KeccakP-1600/x86-64/KeccakP-1600-SnP.h +42 -0
- data/ext/xkcp/lib/low/KeccakP-1600/x86-64/KeccakP-1600-x86-64-gas.s +1196 -0
- data/ext/xkcp/lib/low/KeccakP-1600/x86-64/KeccakP-1600-x86-64-gas_Apple.s +1124 -0
- data/ext/xkcp/lib/low/KeccakP-1600/x86-64/KeccakP-1600-x86-64-shld-gas.s +1196 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/ARMv7A-NEON/KeccakP-1600-inplace-pl2-armv7a-neon-le-armcc.s +1392 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/ARMv7A-NEON/KeccakP-1600-inplace-pl2-armv7a-neon-le-gcc.s +1394 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/ARMv7A-NEON/KeccakP-1600-times2-SnP.h +42 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/AVX512/AVX512u12/SIMD512-2-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/AVX512/AVX512u4/SIMD512-2-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/AVX512/AVX512ufull/SIMD512-2-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/AVX512/KeccakP-1600-times2-SIMD512.c +850 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/AVX512/KeccakP-1600-times2-SnP.h +51 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/SIMD128/KeccakP-1600-times2-SIMD128.c +957 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/SIMD128/KeccakP-1600-times2-SnP.h +49 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/SIMD128/SSSE3-u2/SIMD128-config.h +8 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/SIMD128/SSSE3-ua/SIMD128-config.h +8 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/SIMD128/XOP-u2/SIMD128-config.h +9 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/SIMD128/XOP-ua/SIMD128-config.h +9 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/fallback-on1/KeccakP-1600-times2-SnP.h +45 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times2/fallback-on1/KeccakP-1600-times2-on1.c +37 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/AVX2/KeccakP-1600-times4-SIMD256.c +1321 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/AVX2/KeccakP-1600-times4-SnP.h +55 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/AVX2/u12/SIMD256-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/AVX2/u6/SIMD256-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/AVX2/ua/SIMD256-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/AVX512/AVX512u12/SIMD512-4-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/AVX512/AVX512u4/SIMD512-4-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/AVX512/AVX512ufull/SIMD512-4-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/AVX512/KeccakP-1600-times4-SIMD512.c +881 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/AVX512/KeccakP-1600-times4-SnP.h +51 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/fallback-on1/KeccakP-1600-times4-SnP.h +45 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/fallback-on1/KeccakP-1600-times4-on1.c +37 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/fallback-on2/KeccakP-1600-times4-SnP.h +45 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times4/fallback-on2/KeccakP-1600-times4-on2.c +38 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times8/AVX512/KeccakP-1600-times8-SIMD512.c +1615 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times8/AVX512/KeccakP-1600-times8-SnP.h +57 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times8/AVX512/u12/SIMD512-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times8/AVX512/u4/SIMD512-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times8/AVX512/ua/SIMD512-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times8/fallback-on1/KeccakP-1600-times8-SnP.h +45 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times8/fallback-on1/KeccakP-1600-times8-on1.c +37 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times8/fallback-on2/KeccakP-1600-times8-SnP.h +45 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times8/fallback-on2/KeccakP-1600-times8-on2.c +38 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times8/fallback-on4/KeccakP-1600-times8-SnP.h +45 -0
- data/ext/xkcp/lib/low/KeccakP-1600-times8/fallback-on4/KeccakP-1600-times8-on4.c +38 -0
- data/ext/xkcp/lib/low/KeccakP-200/ARM/KeccakP-200-SnP.h +41 -0
- data/ext/xkcp/lib/low/KeccakP-200/ARM/KeccakP-200-armv6m-le-armcc.s +442 -0
- data/ext/xkcp/lib/low/KeccakP-200/ARM/KeccakP-200-armv6m-le-gcc.s +446 -0
- data/ext/xkcp/lib/low/KeccakP-200/ARM/KeccakP-200-armv7m-le-armcc.s +419 -0
- data/ext/xkcp/lib/low/KeccakP-200/ARM/KeccakP-200-armv7m-le-gcc.s +427 -0
- data/ext/xkcp/lib/low/KeccakP-200/AVR8/KeccakP-200-SnP.h +41 -0
- data/ext/xkcp/lib/low/KeccakP-200/AVR8/KeccakP-200-avr8-fast.s +647 -0
- data/ext/xkcp/lib/low/KeccakP-200/compact/KeccakP-200-SnP.h +39 -0
- data/ext/xkcp/lib/low/KeccakP-200/compact/KeccakP-200-compact.c +190 -0
- data/ext/xkcp/lib/low/KeccakP-200/ref/KeccakP-200-SnP.h +43 -0
- data/ext/xkcp/lib/low/KeccakP-200/ref/KeccakP-200-reference.c +412 -0
- data/ext/xkcp/lib/low/KeccakP-200/ref/KeccakP-200-reference.h +23 -0
- data/ext/xkcp/lib/low/KeccakP-400/ARM/KeccakP-400-SnP.h +41 -0
- data/ext/xkcp/lib/low/KeccakP-400/ARM/KeccakP-400-armv6m-le-armcc.s +454 -0
- data/ext/xkcp/lib/low/KeccakP-400/ARM/KeccakP-400-armv6m-le-gcc.s +458 -0
- data/ext/xkcp/lib/low/KeccakP-400/ARM/KeccakP-400-armv7m-le-armcc.s +455 -0
- data/ext/xkcp/lib/low/KeccakP-400/ARM/KeccakP-400-armv7m-le-gcc.s +458 -0
- data/ext/xkcp/lib/low/KeccakP-400/AVR8/KeccakP-400-SnP.h +41 -0
- data/ext/xkcp/lib/low/KeccakP-400/AVR8/KeccakP-400-avr8-fast.s +728 -0
- data/ext/xkcp/lib/low/KeccakP-400/ref/KeccakP-400-SnP.h +43 -0
- data/ext/xkcp/lib/low/KeccakP-400/ref/KeccakP-400-reference.c +414 -0
- data/ext/xkcp/lib/low/KeccakP-400/ref/KeccakP-400-reference.h +23 -0
- data/ext/xkcp/lib/low/KeccakP-800/ARM/KeccakP-800-SnP.h +42 -0
- data/ext/xkcp/lib/low/KeccakP-800/ARM/KeccakP-800-u1-armv6m-le-armcc.s +527 -0
- data/ext/xkcp/lib/low/KeccakP-800/ARM/KeccakP-800-u1-armv6m-le-gcc.s +533 -0
- data/ext/xkcp/lib/low/KeccakP-800/ARM/KeccakP-800-u2-armv6m-le-armcc.s +528 -0
- data/ext/xkcp/lib/low/KeccakP-800/ARM/KeccakP-800-u2-armv6m-le-gcc.s +534 -0
- data/ext/xkcp/lib/low/KeccakP-800/ARM/KeccakP-800-u2-armv7a-le-armcc.s +521 -0
- data/ext/xkcp/lib/low/KeccakP-800/ARM/KeccakP-800-u2-armv7a-le-gcc.s +527 -0
- data/ext/xkcp/lib/low/KeccakP-800/ARM/KeccakP-800-u2-armv7m-le-armcc.s +517 -0
- data/ext/xkcp/lib/low/KeccakP-800/ARM/KeccakP-800-u2-armv7m-le-gcc.s +523 -0
- data/ext/xkcp/lib/low/KeccakP-800/ARM/KeccakP-800-uf-armv7m-le-armcc.s +550 -0
- data/ext/xkcp/lib/low/KeccakP-800/ARM/KeccakP-800-uf-armv7m-le-gcc.s +556 -0
- data/ext/xkcp/lib/low/KeccakP-800/ARMv8A/KeccakP-800-SnP.h +32 -0
- data/ext/xkcp/lib/low/KeccakP-800/ARMv8A/KeccakP-800-armv8a-neon.s +432 -0
- data/ext/xkcp/lib/low/KeccakP-800/AVR8/KeccakP-800-SnP.h +42 -0
- data/ext/xkcp/lib/low/KeccakP-800/AVR8/KeccakP-800-avr8-fast.s +929 -0
- data/ext/xkcp/lib/low/KeccakP-800/compact/KeccakP-800-SnP.h +40 -0
- data/ext/xkcp/lib/low/KeccakP-800/compact/KeccakP-800-compact.c +244 -0
- data/ext/xkcp/lib/low/KeccakP-800/plain/KeccakP-800-SnP.h +46 -0
- data/ext/xkcp/lib/low/KeccakP-800/plain/KeccakP-800-opt32-bis.macros +184 -0
- data/ext/xkcp/lib/low/KeccakP-800/plain/KeccakP-800-opt32.c +454 -0
- data/ext/xkcp/lib/low/KeccakP-800/plain/KeccakP-800-opt32.macros +459 -0
- data/ext/xkcp/lib/low/KeccakP-800/plain/KeccakP-800-unrolling-bis.macros +83 -0
- data/ext/xkcp/lib/low/KeccakP-800/plain/KeccakP-800-unrolling.macros +88 -0
- data/ext/xkcp/lib/low/KeccakP-800/plain/lcu2/KeccakP-800-opt32-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-800/plain/lcua/KeccakP-800-opt32-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-800/plain/u2/KeccakP-800-opt32-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-800/plain/ua/KeccakP-800-opt32-config.h +7 -0
- data/ext/xkcp/lib/low/KeccakP-800/ref/KeccakP-800-SnP.h +44 -0
- data/ext/xkcp/lib/low/KeccakP-800/ref/KeccakP-800-reference.c +437 -0
- data/ext/xkcp/lib/low/KeccakP-800/ref/KeccakP-800-reference.h +23 -0
- data/ext/xkcp/lib/low/Ketje/OptimizedAsmARM/Ket.h +57 -0
- data/ext/xkcp/lib/low/Ketje/OptimizedAsmARM/KetjeJr-armv7m-le-armcc.s +475 -0
- data/ext/xkcp/lib/low/Ketje/OptimizedAsmARM/KetjeJr-armv7m-le-gcc.s +480 -0
- data/ext/xkcp/lib/low/Ketje/OptimizedAsmARM/KetjeSr-armv7m-le-armcc.s +590 -0
- data/ext/xkcp/lib/low/Ketje/OptimizedAsmARM/KetjeSr-armv7m-le-gcc.s +590 -0
- data/ext/xkcp/lib/low/Ketje/OptimizedLE/Ket.c +126 -0
- data/ext/xkcp/lib/low/Ketje/OptimizedLE/Ket.h +68 -0
- data/ext/xkcp/lib/low/Ketje/OptimizedLE/Ket.inc +174 -0
- data/ext/xkcp/lib/low/Ketje/SnP-compliant/Ket.c +80 -0
- data/ext/xkcp/lib/low/Ketje/SnP-compliant/Ket.h +68 -0
- data/ext/xkcp/lib/low/Ketje/SnP-compliant/Ket.inc +142 -0
- data/ext/xkcp/lib/low/Xoodoo/ARM/Xoodoo-SnP.h +55 -0
- data/ext/xkcp/lib/low/Xoodoo/ARM/Xoodoo-u1-armv6m-le-armcc.s +1086 -0
- data/ext/xkcp/lib/low/Xoodoo/ARM/Xoodoo-u1-armv6m-le-gcc.s +1092 -0
- data/ext/xkcp/lib/low/Xoodoo/ARM/Xoodoo-uf-armv6-le-armcc.s +721 -0
- data/ext/xkcp/lib/low/Xoodoo/ARM/Xoodoo-uf-armv6-le-gcc.s +726 -0
- data/ext/xkcp/lib/low/Xoodoo/ARM/Xoodoo-uf-armv7m-le-armcc.s +723 -0
- data/ext/xkcp/lib/low/Xoodoo/ARM/Xoodoo-uf-armv7m-le-gcc.s +729 -0
- data/ext/xkcp/lib/low/Xoodoo/ARM/Xoodyak-u1-armv6m-le-armcc.s +1164 -0
- data/ext/xkcp/lib/low/Xoodoo/ARM/Xoodyak-u1-armv6m-le-gcc.s +1165 -0
- data/ext/xkcp/lib/low/Xoodoo/ARM/Xoodyak-uf-armv6-le-armcc.s +562 -0
- data/ext/xkcp/lib/low/Xoodoo/ARM/Xoodyak-uf-armv6-le-gcc.s +563 -0
- data/ext/xkcp/lib/low/Xoodoo/ARM/Xoodyak-uf-armv7m-le-armcc.s +563 -0
- data/ext/xkcp/lib/low/Xoodoo/ARM/Xoodyak-uf-armv7m-le-gcc.s +565 -0
- data/ext/xkcp/lib/low/Xoodoo/ARMv7A-NEON/Xoodoo-SnP.h +55 -0
- data/ext/xkcp/lib/low/Xoodoo/ARMv7A-NEON/Xoodoo-uf-armv7a-neon-le-armcc.s +476 -0
- data/ext/xkcp/lib/low/Xoodoo/ARMv7A-NEON/Xoodoo-uf-armv7a-neon-le-gcc.s +485 -0
- data/ext/xkcp/lib/low/Xoodoo/ARMv7A-NEON/Xoodyak-uf-armv7a-neon-le-armcc.s +362 -0
- data/ext/xkcp/lib/low/Xoodoo/ARMv7A-NEON/Xoodyak-uf-armv7a-neon-le-gcc.s +367 -0
- data/ext/xkcp/lib/low/Xoodoo/AVR8/Xoodoo-SnP.h +43 -0
- data/ext/xkcp/lib/low/Xoodoo/AVR8/Xoodoo-avr8-u1.s +1341 -0
- data/ext/xkcp/lib/low/Xoodoo/AVX512/Xoodoo-SIMD512.c +581 -0
- data/ext/xkcp/lib/low/Xoodoo/AVX512/Xoodoo-SnP.h +58 -0
- data/ext/xkcp/lib/low/Xoodoo/AVX512/Xoodyak-full-block-SIMD512.c +332 -0
- data/ext/xkcp/lib/low/Xoodoo/SSE2/Xoodoo-SIMD128.c +329 -0
- data/ext/xkcp/lib/low/Xoodoo/SSE2/Xoodoo-SnP.h +53 -0
- data/ext/xkcp/lib/low/Xoodoo/SSE2/Xoodyak-full-block-SIMD128.c +355 -0
- data/ext/xkcp/lib/low/Xoodoo/Xoodoo.h +79 -0
- data/ext/xkcp/lib/low/Xoodoo/plain/Xoodoo-SnP.h +56 -0
- data/ext/xkcp/lib/low/Xoodoo/plain/Xoodoo-optimized.c +399 -0
- data/ext/xkcp/lib/low/Xoodoo/plain/Xoodyak-full-blocks.c +127 -0
- data/ext/xkcp/lib/low/Xoodoo/ref/Xoodoo-SnP.h +43 -0
- data/ext/xkcp/lib/low/Xoodoo/ref/Xoodoo-reference.c +253 -0
- data/ext/xkcp/lib/low/Xoodoo-times16/AVX512/Xoodoo-times16-SIMD512.c +1044 -0
- data/ext/xkcp/lib/low/Xoodoo-times16/AVX512/Xoodoo-times16-SnP.h +49 -0
- data/ext/xkcp/lib/low/Xoodoo-times16/fallback-on1/Xoodoo-times16-SnP.h +45 -0
- data/ext/xkcp/lib/low/Xoodoo-times16/fallback-on1/Xoodoo-times16-on1.c +37 -0
- data/ext/xkcp/lib/low/Xoodoo-times4/ARMv7A-NEON/Xoodoo-times4-ARMv7A.s +1587 -0
- data/ext/xkcp/lib/low/Xoodoo-times4/ARMv7A-NEON/Xoodoo-times4-SnP.h +48 -0
- data/ext/xkcp/lib/low/Xoodoo-times4/AVX512/Xoodoo-times4-SIMD512.c +1202 -0
- data/ext/xkcp/lib/low/Xoodoo-times4/AVX512/Xoodoo-times4-SnP.h +48 -0
- data/ext/xkcp/lib/low/Xoodoo-times4/SSSE3/Xoodoo-times4-SIMD128.c +484 -0
- data/ext/xkcp/lib/low/Xoodoo-times4/SSSE3/Xoodoo-times4-SnP.h +44 -0
- data/ext/xkcp/lib/low/Xoodoo-times4/fallback-on1/Xoodoo-times4-SnP.h +45 -0
- data/ext/xkcp/lib/low/Xoodoo-times4/fallback-on1/Xoodoo-times4-on1.c +37 -0
- data/ext/xkcp/lib/low/Xoodoo-times8/AVX2/Xoodoo-times8-SIMD256.c +939 -0
- data/ext/xkcp/lib/low/Xoodoo-times8/AVX2/Xoodoo-times8-SnP.h +49 -0
- data/ext/xkcp/lib/low/Xoodoo-times8/AVX512/Xoodoo-times8-SIMD512.c +1216 -0
- data/ext/xkcp/lib/low/Xoodoo-times8/AVX512/Xoodoo-times8-SnP.h +48 -0
- data/ext/xkcp/lib/low/Xoodoo-times8/fallback-on1/Xoodoo-times8-SnP.h +45 -0
- data/ext/xkcp/lib/low/Xoodoo-times8/fallback-on1/Xoodoo-times8-on1.c +37 -0
- data/ext/xkcp/lib/low/common/PlSnP-Fallback.inc +290 -0
- data/ext/xkcp/lib/low/common/SnP-Relaned.h +141 -0
- data/ext/xkcp/support/Build/ExpandProducts.xsl +79 -0
- data/ext/xkcp/support/Build/ToGlobalMakefile.xsl +206 -0
- data/ext/xkcp/support/Build/ToOneTarget.xsl +89 -0
- data/ext/xkcp/support/Build/ToTargetConfigFile.xsl +37 -0
- data/ext/xkcp/support/Build/ToTargetMakefile.xsl +298 -0
- data/ext/xkcp/support/Build/ToVCXProj.xsl +198 -0
- data/ext/xkcp/support/Kernel-PMU/Kernel-pmu.md +133 -0
- data/ext/xkcp/support/Kernel-PMU/Makefile +8 -0
- data/ext/xkcp/support/Kernel-PMU/enable_arm_pmu.c +129 -0
- data/ext/xkcp/support/Kernel-PMU/load-module +1 -0
- data/ext/xkcp/util/KeccakSum/KeccakSum.c +394 -0
- data/ext/xkcp/util/KeccakSum/base64.c +86 -0
- data/ext/xkcp/util/KeccakSum/base64.h +12 -0
- data/lib/sleeping_kangaroo12/binding.rb +15 -0
- data/lib/sleeping_kangaroo12/build/loader.rb +40 -0
- data/lib/sleeping_kangaroo12/build/platform.rb +37 -0
- data/lib/sleeping_kangaroo12/build.rb +4 -0
- data/lib/sleeping_kangaroo12/digest.rb +103 -0
- data/lib/sleeping_kangaroo12/version.rb +5 -0
- data/lib/sleeping_kangaroo12.rb +7 -0
- metadata +372 -0
@@ -0,0 +1,394 @@
|
|
1
|
+
/*
|
2
|
+
Implementation by Gilles Van Assche and Ronny Van Keer, hereby denoted as "the implementer".
|
3
|
+
|
4
|
+
For more information, feedback or questions, please refer to our website:
|
5
|
+
https://keccak.team/
|
6
|
+
|
7
|
+
To the extent possible under law, the implementer has waived all copyright
|
8
|
+
and related or neighboring rights to the source code in this file.
|
9
|
+
http://creativecommons.org/publicdomain/zero/1.0/
|
10
|
+
*/
|
11
|
+
|
12
|
+
#include <stdint.h>
|
13
|
+
#include <stdio.h>
|
14
|
+
#include <stdlib.h>
|
15
|
+
#include <string.h>
|
16
|
+
#include "base64.h"
|
17
|
+
#include "KeccakHash.h"
|
18
|
+
#include "KangarooTwelve.h"
|
19
|
+
#include "SP800-185.h"
|
20
|
+
|
21
|
+
int hexencode(const void* data_buf, size_t dataLength, char* result, size_t resultSize)
|
22
|
+
{
|
23
|
+
const char hexchars[] = "0123456789abcdef";
|
24
|
+
const uint8_t *data = (const uint8_t *)data_buf;
|
25
|
+
size_t resultIndex = 0;
|
26
|
+
size_t x;
|
27
|
+
|
28
|
+
for(x=0; x<dataLength; x++) {
|
29
|
+
if (resultIndex >= resultSize) return 1; /* indicate failure: buffer too small */
|
30
|
+
result[resultIndex++] = hexchars[(data[x] / 16) % 16];
|
31
|
+
if (resultIndex >= resultSize) return 1; /* indicate failure: buffer too small */
|
32
|
+
result[resultIndex++] = hexchars[data[x] % 16];
|
33
|
+
}
|
34
|
+
if(resultIndex >= resultSize) return 1; /* indicate failure: buffer too small */
|
35
|
+
result[resultIndex] = 0;
|
36
|
+
return 0; /* indicate success */
|
37
|
+
}
|
38
|
+
|
39
|
+
#define bufferSize 65536
|
40
|
+
#define algorithm_Keccak 0
|
41
|
+
#define algorithm_K12 1
|
42
|
+
#define algorithm_ParallelHash 2
|
43
|
+
|
44
|
+
typedef struct {
|
45
|
+
unsigned int algorithm;
|
46
|
+
unsigned int rate;
|
47
|
+
unsigned int capacity;
|
48
|
+
unsigned int hashbitlen;
|
49
|
+
unsigned char delimitedSuffix;
|
50
|
+
unsigned int blockByteLen;
|
51
|
+
} Specifications;
|
52
|
+
|
53
|
+
typedef union {
|
54
|
+
Keccak_HashInstance keccak;
|
55
|
+
KangarooTwelve_Instance k12;
|
56
|
+
ParallelHash_Instance ph;
|
57
|
+
} Instance;
|
58
|
+
|
59
|
+
int hashInitialize(Instance *instance, const Specifications *specs)
|
60
|
+
{
|
61
|
+
if (specs->algorithm == algorithm_Keccak) {
|
62
|
+
if (Keccak_HashInitialize(&instance->keccak, specs->rate, specs->capacity, specs->hashbitlen, specs->delimitedSuffix)) {
|
63
|
+
printf("Incorrect Keccak parameters (%d, %d, %d, 0x%02x).\n", specs->rate, specs->capacity, specs->hashbitlen, specs->delimitedSuffix);
|
64
|
+
return -1;
|
65
|
+
}
|
66
|
+
else
|
67
|
+
return 0;
|
68
|
+
}
|
69
|
+
else if (specs->algorithm == algorithm_K12) {
|
70
|
+
if (KangarooTwelve_Initialize(&instance->k12, specs->hashbitlen/8)) {
|
71
|
+
printf("Incorrect KangarooTwelve parameters.\n");
|
72
|
+
return -1;
|
73
|
+
}
|
74
|
+
else
|
75
|
+
return 0;
|
76
|
+
}
|
77
|
+
else if (specs->algorithm == algorithm_ParallelHash) {
|
78
|
+
if (specs->capacity == 256) {
|
79
|
+
if (ParallelHash128_Initialize(&instance->ph, specs->blockByteLen, specs->hashbitlen, "", 0)) {
|
80
|
+
printf("Incorrect ParallelHash128 parameters.\n");
|
81
|
+
return -1;
|
82
|
+
}
|
83
|
+
else
|
84
|
+
return 0;
|
85
|
+
}
|
86
|
+
else if (specs->capacity == 512) {
|
87
|
+
if (ParallelHash256_Initialize(&instance->ph, specs->blockByteLen, specs->hashbitlen, "", 0)) {
|
88
|
+
printf("Incorrect ParallelHash256 parameters.\n");
|
89
|
+
return -1;
|
90
|
+
}
|
91
|
+
else
|
92
|
+
return 0;
|
93
|
+
}
|
94
|
+
else {
|
95
|
+
printf("Incorrect ParallelHash parameters.\n");
|
96
|
+
return -1;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
else
|
100
|
+
return -1;
|
101
|
+
}
|
102
|
+
|
103
|
+
int hashUpdate(Instance *instance, const Specifications *specs, const unsigned char *buffer, size_t size)
|
104
|
+
{
|
105
|
+
if (specs->algorithm == algorithm_Keccak)
|
106
|
+
Keccak_HashUpdate(&instance->keccak, buffer, size*8);
|
107
|
+
else if (specs->algorithm == algorithm_K12)
|
108
|
+
KangarooTwelve_Update(&instance->k12, buffer, size);
|
109
|
+
else if ((specs->algorithm == algorithm_ParallelHash) && (specs->capacity == 256))
|
110
|
+
ParallelHash128_Update(&instance->ph, buffer, size*8);
|
111
|
+
else if ((specs->algorithm == algorithm_ParallelHash) && (specs->capacity == 512))
|
112
|
+
ParallelHash256_Update(&instance->ph, buffer, size*8);
|
113
|
+
return 0;
|
114
|
+
}
|
115
|
+
|
116
|
+
int hashFinal(Instance *instance, const Specifications *specs, unsigned char *buffer)
|
117
|
+
{
|
118
|
+
if (specs->algorithm == algorithm_Keccak)
|
119
|
+
Keccak_HashFinal(&instance->keccak, buffer);
|
120
|
+
else if (specs->algorithm == algorithm_K12)
|
121
|
+
KangarooTwelve_Final(&instance->k12, buffer, "", 0);
|
122
|
+
else if ((specs->algorithm == algorithm_ParallelHash) && (specs->capacity == 256))
|
123
|
+
ParallelHash128_Final(&instance->ph, buffer);
|
124
|
+
else if ((specs->algorithm == algorithm_ParallelHash) && (specs->capacity == 512))
|
125
|
+
ParallelHash256_Final(&instance->ph, buffer);
|
126
|
+
return 0;
|
127
|
+
}
|
128
|
+
|
129
|
+
int processFile(const char *fileName, const Specifications *specs, int base64)
|
130
|
+
{
|
131
|
+
FILE *fp;
|
132
|
+
Instance instance;
|
133
|
+
size_t read;
|
134
|
+
unsigned char buffer[bufferSize];
|
135
|
+
char display[bufferSize*2+1];
|
136
|
+
|
137
|
+
if (specs->hashbitlen > (bufferSize*8)) {
|
138
|
+
printf("The requested digest length (%d bits) does not fit in the buffer.\n", specs->hashbitlen);
|
139
|
+
return -1;
|
140
|
+
}
|
141
|
+
if (strcmp("-", fileName) == 0) {
|
142
|
+
fp = stdin;
|
143
|
+
}
|
144
|
+
else {
|
145
|
+
fp = fopen(fileName, "rb");
|
146
|
+
if (fp == NULL) {
|
147
|
+
printf("File '%s' could not be opened.\n", fileName);
|
148
|
+
return -1;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
if (hashInitialize(&instance, specs)) {
|
152
|
+
fclose(fp);
|
153
|
+
return -1;
|
154
|
+
}
|
155
|
+
do {
|
156
|
+
read = fread(buffer, 1, bufferSize, fp);
|
157
|
+
if (read > 0)
|
158
|
+
hashUpdate(&instance, specs, buffer, read);
|
159
|
+
} while(read>0);
|
160
|
+
if (fp != stdin) {
|
161
|
+
fclose(fp);
|
162
|
+
}
|
163
|
+
hashFinal(&instance, specs, buffer);
|
164
|
+
if (base64) {
|
165
|
+
if (base64encode(buffer, (specs->hashbitlen+7)/8, display, bufferSize*2)) {
|
166
|
+
printf("Error while converting to base64.\n");
|
167
|
+
return -1;
|
168
|
+
}
|
169
|
+
}
|
170
|
+
else {
|
171
|
+
if (hexencode(buffer, (specs->hashbitlen+7)/8, display, bufferSize*2)) {
|
172
|
+
printf("Error while converting to hex.\n");
|
173
|
+
return -1;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
printf("%s ", display);
|
177
|
+
printf("%s\n", fileName);
|
178
|
+
return 0;
|
179
|
+
}
|
180
|
+
|
181
|
+
int processString(const char *input, const Specifications *specs, int base64)
|
182
|
+
{
|
183
|
+
Instance instance;
|
184
|
+
unsigned char buffer[bufferSize];
|
185
|
+
char display[bufferSize*2+1];
|
186
|
+
|
187
|
+
if (specs->hashbitlen > (bufferSize*8)) {
|
188
|
+
printf("The requested digest length (%d bits) does not fit in the buffer.\n", specs->hashbitlen);
|
189
|
+
return -1;
|
190
|
+
}
|
191
|
+
if (hashInitialize(&instance, specs)) {
|
192
|
+
return -1;
|
193
|
+
}
|
194
|
+
hashUpdate(&instance, specs, input, strlen(input));
|
195
|
+
hashFinal(&instance, specs, buffer);
|
196
|
+
if (base64) {
|
197
|
+
if (base64encode(buffer, (specs->hashbitlen+7)/8, display, bufferSize*2)) {
|
198
|
+
printf("Error while converting to base64.\n");
|
199
|
+
return -1;
|
200
|
+
}
|
201
|
+
}
|
202
|
+
else {
|
203
|
+
if (hexencode(buffer, (specs->hashbitlen+7)/8, display, bufferSize*2)) {
|
204
|
+
printf("Error while converting to hex.\n");
|
205
|
+
return -1;
|
206
|
+
}
|
207
|
+
}
|
208
|
+
printf("%s ", display);
|
209
|
+
printf("\"%s\"\n", input);
|
210
|
+
return 0;
|
211
|
+
}
|
212
|
+
|
213
|
+
void printHelp()
|
214
|
+
{
|
215
|
+
printf("Usage: KeccakSum [options] [file names] [options] [file names] ...\n\n");
|
216
|
+
printf(" --help or -h To display this page\n");
|
217
|
+
printf(" --base64 Print in base64\n");
|
218
|
+
printf(" --hex Print in hexadecimal\n");
|
219
|
+
printf(" --outputbits <numberOfBits> Number of bits as output\n");
|
220
|
+
printf(" --shake128 Use SHAKE128\n");
|
221
|
+
printf(" --shake256 Use SHAKE256\n");
|
222
|
+
printf(" --sha3-224 Use SHA3-224\n");
|
223
|
+
printf(" --sha3-256 Use SHA3-256\n");
|
224
|
+
printf(" --sha3-384 Use SHA3-384\n");
|
225
|
+
printf(" --sha3-512 Use SHA3-512\n");
|
226
|
+
printf(" --no-suffix Use 0x01 as delimited suffix (pure Keccak)\n");
|
227
|
+
printf(" --ethereum Equivalent to --sha3-256 --no-suffix\n");
|
228
|
+
printf(" --kangarootwelve or --k12 Use KangarooTwelve\n");
|
229
|
+
printf(" --ph128 Use ParallelHash128\n");
|
230
|
+
printf(" --ph256 Use ParallelHash256\n");
|
231
|
+
printf(" -B <block size in bytes> ParallelHash's B parameter\n");
|
232
|
+
printf(" --string <string> String to hash\n");
|
233
|
+
printf(" <file name> File to hash\n\n");
|
234
|
+
printf("The options are processed in order.\nBy default, it uses SHAKE128 and base64 display.\n");
|
235
|
+
printf("With no file names, or when file name is -, it reads standard input.\n");
|
236
|
+
}
|
237
|
+
|
238
|
+
int process(int argc, char* argv[])
|
239
|
+
{
|
240
|
+
Specifications specs;
|
241
|
+
int base64 = 1;
|
242
|
+
int i, r;
|
243
|
+
int was_filename = 0;
|
244
|
+
specs.algorithm = algorithm_Keccak;
|
245
|
+
specs.rate = 1344;
|
246
|
+
specs.capacity = 256;
|
247
|
+
specs.hashbitlen = 264;
|
248
|
+
specs.delimitedSuffix = 0x1F;
|
249
|
+
|
250
|
+
for(i=1; i<argc; i++) {
|
251
|
+
int outputbits;
|
252
|
+
if (strcmp("--base64", argv[i]) == 0)
|
253
|
+
base64 = 1;
|
254
|
+
else if (strcmp("--hex", argv[i]) == 0)
|
255
|
+
base64 = 0;
|
256
|
+
else if ((strcmp("--outputbits", argv[i]) == 0) || (strcmp("-n", argv[i]) == 0)) {
|
257
|
+
if ((i+1) >= argc) {
|
258
|
+
printf("Error: missing argument for --outputbits\n");
|
259
|
+
return -1;
|
260
|
+
}
|
261
|
+
outputbits = 0;
|
262
|
+
if (sscanf(argv[i+1], "%d", &outputbits) && (outputbits > 0) && ((outputbits % 8) == 0)) {
|
263
|
+
specs.hashbitlen = outputbits;
|
264
|
+
i++;
|
265
|
+
}
|
266
|
+
else {
|
267
|
+
printf("Error: argument for --outputbits option must be a positive integer multiple of 8\n");
|
268
|
+
return -1;
|
269
|
+
}
|
270
|
+
}
|
271
|
+
else if (strcmp("--shake128", argv[i]) == 0) {
|
272
|
+
specs.rate = 1344;
|
273
|
+
specs.capacity = 256;
|
274
|
+
specs.hashbitlen = 264;
|
275
|
+
specs.delimitedSuffix = 0x1F;
|
276
|
+
base64 = 1;
|
277
|
+
}
|
278
|
+
else if (strcmp("--shake256", argv[i]) == 0) {
|
279
|
+
specs.rate = 1088;
|
280
|
+
specs.capacity = 512;
|
281
|
+
specs.hashbitlen = 528;
|
282
|
+
specs.delimitedSuffix = 0x1F;
|
283
|
+
base64 = 1;
|
284
|
+
}
|
285
|
+
else if (strcmp("--sha3-224", argv[i]) == 0) {
|
286
|
+
specs.rate = 1152;
|
287
|
+
specs.capacity = 448;
|
288
|
+
specs.hashbitlen = 224;
|
289
|
+
specs.delimitedSuffix = 0x06;
|
290
|
+
base64 = 0;
|
291
|
+
}
|
292
|
+
else if (strcmp("--sha3-256", argv[i]) == 0) {
|
293
|
+
specs.rate = 1088;
|
294
|
+
specs.capacity = 512;
|
295
|
+
specs.hashbitlen = 256;
|
296
|
+
specs.delimitedSuffix = 0x06;
|
297
|
+
base64 = 0;
|
298
|
+
}
|
299
|
+
else if (strcmp("--sha3-384", argv[i]) == 0) {
|
300
|
+
specs.rate = 832;
|
301
|
+
specs.capacity = 768;
|
302
|
+
specs.hashbitlen = 384;
|
303
|
+
specs.delimitedSuffix = 0x06;
|
304
|
+
base64 = 0;
|
305
|
+
}
|
306
|
+
else if (strcmp("--sha3-512", argv[i]) == 0) {
|
307
|
+
specs.rate = 576;
|
308
|
+
specs.capacity = 1024;
|
309
|
+
specs.hashbitlen = 512;
|
310
|
+
specs.delimitedSuffix = 0x06;
|
311
|
+
base64 = 0;
|
312
|
+
}
|
313
|
+
else if (strcmp("--no-suffix", argv[i]) == 0) {
|
314
|
+
specs.delimitedSuffix = 0x01;
|
315
|
+
}
|
316
|
+
else if (strcmp("--ethereum", argv[i]) == 0) {
|
317
|
+
specs.rate = 1088;
|
318
|
+
specs.capacity = 512;
|
319
|
+
specs.hashbitlen = 256;
|
320
|
+
specs.delimitedSuffix = 0x01;
|
321
|
+
base64 = 0;
|
322
|
+
}
|
323
|
+
else if ((strcmp("--kangarootwelve", argv[i]) == 0) || (strcmp("--k12", argv[i]) == 0)) {
|
324
|
+
specs.algorithm = algorithm_K12;
|
325
|
+
specs.hashbitlen = 264;
|
326
|
+
base64 = 1;
|
327
|
+
}
|
328
|
+
else if (strcmp("--ph128", argv[i]) == 0) {
|
329
|
+
specs.algorithm = algorithm_ParallelHash;
|
330
|
+
specs.capacity = 256;
|
331
|
+
specs.hashbitlen = 264;
|
332
|
+
specs.blockByteLen = 8192;
|
333
|
+
base64 = 1;
|
334
|
+
}
|
335
|
+
else if (strcmp("--ph256", argv[i]) == 0) {
|
336
|
+
specs.algorithm = algorithm_ParallelHash;
|
337
|
+
specs.capacity = 512;
|
338
|
+
specs.hashbitlen = 528;
|
339
|
+
specs.blockByteLen = 8192;
|
340
|
+
base64 = 1;
|
341
|
+
}
|
342
|
+
else if (strcmp("-B", argv[i]) == 0) {
|
343
|
+
int blockByteLen;
|
344
|
+
if ((i+1) >= argc) {
|
345
|
+
printf("Error: missing argument for -B\n");
|
346
|
+
return -1;
|
347
|
+
}
|
348
|
+
blockByteLen = 0;
|
349
|
+
if (sscanf(argv[i+1], "%d", &blockByteLen) && (blockByteLen > 0)) {
|
350
|
+
specs.blockByteLen = blockByteLen;
|
351
|
+
i++;
|
352
|
+
}
|
353
|
+
else {
|
354
|
+
printf("Error: argument for -B option must be a positive power of 2\n");
|
355
|
+
return -1;
|
356
|
+
}
|
357
|
+
}
|
358
|
+
else if (strcmp("--string", argv[i]) == 0) {
|
359
|
+
if ((i+1) >= argc) {
|
360
|
+
printf("Error: missing argument for --string\n");
|
361
|
+
return -1;
|
362
|
+
}
|
363
|
+
i++;
|
364
|
+
processString(argv[i], &specs, base64);
|
365
|
+
}
|
366
|
+
else if (strcmp("--help", argv[i]) == 0 || strcmp("-h", argv[i]) == 0) {
|
367
|
+
printHelp();
|
368
|
+
return 0;
|
369
|
+
}
|
370
|
+
else {
|
371
|
+
if (strlen(argv[i]) > 2) {
|
372
|
+
if ((argv[i][0] == '-') && (argv[i][1] == '-')) {
|
373
|
+
printf("Unrecognized command '%s'\n", argv[i]);
|
374
|
+
return -1;
|
375
|
+
}
|
376
|
+
}
|
377
|
+
was_filename = 1;
|
378
|
+
r = processFile(argv[i], &specs, base64);
|
379
|
+
if (r)
|
380
|
+
return r;
|
381
|
+
}
|
382
|
+
}
|
383
|
+
if (was_filename == 0) {
|
384
|
+
r = processFile("-", &specs, base64);
|
385
|
+
if (r)
|
386
|
+
return r;
|
387
|
+
}
|
388
|
+
return 0;
|
389
|
+
}
|
390
|
+
|
391
|
+
int main(int argc, char* argv[])
|
392
|
+
{
|
393
|
+
return process(argc, argv);
|
394
|
+
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
/*
|
2
|
+
Implementation taken from:
|
3
|
+
https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64
|
4
|
+
(2015-12-16)
|
5
|
+
|
6
|
+
Available under the Creative Commons Attribution-ShareAlike License:
|
7
|
+
https://creativecommons.org/licenses/by-sa/3.0/
|
8
|
+
*/
|
9
|
+
|
10
|
+
#include <stdint.h>
|
11
|
+
#include <string.h>
|
12
|
+
|
13
|
+
int base64encode(const void* data_buf, size_t dataLength, char* result, size_t resultSize)
|
14
|
+
{
|
15
|
+
const char base64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
16
|
+
const uint8_t *data = (const uint8_t *)data_buf;
|
17
|
+
size_t resultIndex = 0;
|
18
|
+
size_t x;
|
19
|
+
uint32_t n = 0;
|
20
|
+
int padCount = dataLength % 3;
|
21
|
+
uint8_t n0, n1, n2, n3;
|
22
|
+
|
23
|
+
/* increment over the length of the string, three characters at a time */
|
24
|
+
for (x = 0; x < dataLength; x += 3)
|
25
|
+
{
|
26
|
+
/* these three 8-bit (ASCII) characters become one 24-bit number */
|
27
|
+
n = ((uint32_t)data[x]) << 16; /* parenthesis needed, compiler depending on flags can do the shifting before conversion to uint32_t, resulting to 0 */
|
28
|
+
|
29
|
+
if((x+1) < dataLength)
|
30
|
+
n += ((uint32_t)data[x+1]) << 8; /* parenthesis needed, compiler depending on flags can do the shifting before conversion to uint32_t, resulting to 0 */
|
31
|
+
|
32
|
+
if((x+2) < dataLength)
|
33
|
+
n += data[x+2];
|
34
|
+
|
35
|
+
/* this 24-bit number gets separated into four 6-bit numbers */
|
36
|
+
n0 = (uint8_t)(n >> 18) & 63;
|
37
|
+
n1 = (uint8_t)(n >> 12) & 63;
|
38
|
+
n2 = (uint8_t)(n >> 6) & 63;
|
39
|
+
n3 = (uint8_t)n & 63;
|
40
|
+
|
41
|
+
/*
|
42
|
+
* if we have one byte available, then its encoding is spread
|
43
|
+
* out over two characters
|
44
|
+
*/
|
45
|
+
if(resultIndex >= resultSize) return 1; /* indicate failure: buffer too small */
|
46
|
+
result[resultIndex++] = base64chars[n0];
|
47
|
+
if(resultIndex >= resultSize) return 1; /* indicate failure: buffer too small */
|
48
|
+
result[resultIndex++] = base64chars[n1];
|
49
|
+
|
50
|
+
/*
|
51
|
+
* if we have only two bytes available, then their encoding is
|
52
|
+
* spread out over three chars
|
53
|
+
*/
|
54
|
+
if((x+1) < dataLength)
|
55
|
+
{
|
56
|
+
if(resultIndex >= resultSize) return 1; /* indicate failure: buffer too small */
|
57
|
+
result[resultIndex++] = base64chars[n2];
|
58
|
+
}
|
59
|
+
|
60
|
+
/*
|
61
|
+
* if we have all three bytes available, then their encoding is spread
|
62
|
+
* out over four characters
|
63
|
+
*/
|
64
|
+
if((x+2) < dataLength)
|
65
|
+
{
|
66
|
+
if(resultIndex >= resultSize) return 1; /* indicate failure: buffer too small */
|
67
|
+
result[resultIndex++] = base64chars[n3];
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
/*
|
72
|
+
* create and add padding that is required if we did not have a multiple of 3
|
73
|
+
* number of characters available
|
74
|
+
*/
|
75
|
+
if (padCount > 0)
|
76
|
+
{
|
77
|
+
for (; padCount < 3; padCount++)
|
78
|
+
{
|
79
|
+
if(resultIndex >= resultSize) return 1; /* indicate failure: buffer too small */
|
80
|
+
result[resultIndex++] = '=';
|
81
|
+
}
|
82
|
+
}
|
83
|
+
if(resultIndex >= resultSize) return 1; /* indicate failure: buffer too small */
|
84
|
+
result[resultIndex] = 0;
|
85
|
+
return 0; /* indicate success */
|
86
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/*
|
2
|
+
Implementation taken from:
|
3
|
+
https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64
|
4
|
+
(2015-12-16)
|
5
|
+
|
6
|
+
Available under the Creative Commons Attribution-ShareAlike License:
|
7
|
+
https://creativecommons.org/licenses/by-sa/3.0/
|
8
|
+
*/
|
9
|
+
|
10
|
+
#include <string.h>
|
11
|
+
|
12
|
+
int base64encode(const void* data_buf, size_t dataLength, char* result, size_t resultSize);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'build/loader'
|
4
|
+
|
5
|
+
module SleepingKangaroo12
|
6
|
+
module Binding
|
7
|
+
extend ::FFI::Library
|
8
|
+
ffi_lib Build::Loader.find('SleepingKangaroo12')
|
9
|
+
|
10
|
+
attach_function :init, :SleepingKangaroo12_Init, [:int], :pointer
|
11
|
+
attach_function :update, :SleepingKangaroo12_Update, %i[pointer pointer size_t], :int
|
12
|
+
attach_function :final, :SleepingKangaroo12_Final, %i[pointer pointer pointer size_t], :int
|
13
|
+
attach_function :destroy, :SleepingKangaroo12_Destroy, %i[pointer], :void
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ffi'
|
4
|
+
require 'pathname'
|
5
|
+
require_relative 'platform'
|
6
|
+
|
7
|
+
module SleepingKangaroo12
|
8
|
+
module Build
|
9
|
+
# taken from:
|
10
|
+
# https://github.com/ffi/ffi-compiler/blob/master/lib/ffi-compiler/loader.rb
|
11
|
+
module Loader
|
12
|
+
def self.find(name, start_path = nil)
|
13
|
+
library = Platform.instance.map_library_name(name)
|
14
|
+
root = false
|
15
|
+
::Pathname.new(start_path || caller_path(caller[0])).ascend do |path|
|
16
|
+
Dir.glob("#{path}/**/{#{::FFI::Platform::ARCH}-#{::FFI::Platform::OS}/#{library},#{library}}") do |f|
|
17
|
+
return f
|
18
|
+
end
|
19
|
+
|
20
|
+
break if root
|
21
|
+
|
22
|
+
# Next iteration will be the root of the gem if this is the lib/ dir - stop after that
|
23
|
+
root = ::File.basename(path) == 'lib'
|
24
|
+
end
|
25
|
+
raise ::LoadError, "cannot find '#{name}' library"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.caller_path(line = caller[0])
|
29
|
+
if ::FFI::Platform::OS == 'windows'
|
30
|
+
drive = line[0..1]
|
31
|
+
path = line[2..].split(/:/)[0]
|
32
|
+
full_path = drive + path
|
33
|
+
else
|
34
|
+
full_path = line.split(/:/)[0]
|
35
|
+
end
|
36
|
+
::File.dirname full_path
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ffi'
|
4
|
+
require 'singleton'
|
5
|
+
|
6
|
+
module SleepingKangaroo12
|
7
|
+
module Build
|
8
|
+
# mostly taken from:
|
9
|
+
# https://github.com/ffi/ffi-compiler/blob/master/lib/ffi-compiler/platform.rb
|
10
|
+
|
11
|
+
class Platform
|
12
|
+
include ::Singleton
|
13
|
+
|
14
|
+
LIBSUFFIX = ::FFI::Platform.mac? ? 'bundle' : ::FFI::Platform::LIBSUFFIX
|
15
|
+
|
16
|
+
def map_library_name(name)
|
17
|
+
"#{::FFI::Platform::LIBPREFIX}#{name}.#{LIBSUFFIX}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def arch
|
21
|
+
::FFI::Platform::ARCH
|
22
|
+
end
|
23
|
+
|
24
|
+
def os
|
25
|
+
::FFI::Platform::OS
|
26
|
+
end
|
27
|
+
|
28
|
+
def name
|
29
|
+
::FFI::Platform.name
|
30
|
+
end
|
31
|
+
|
32
|
+
def mac?
|
33
|
+
::FFI::Platform.mac?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'binding'
|
4
|
+
|
5
|
+
module SleepingKangaroo12
|
6
|
+
class Digest
|
7
|
+
class UpdatingFailed < ::StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
class FinalizationFailed < ::StandardError
|
11
|
+
end
|
12
|
+
|
13
|
+
class Finalized < ::StandardError
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(output_length: 32, key: nil)
|
17
|
+
raise ::TypeError, 'Hash length is not an Integer' unless output_length.is_a?(::Integer)
|
18
|
+
raise ::ArgumentError, 'Hash length out of range' unless (1...(1 << 20)).include?(output_length)
|
19
|
+
raise ::TypeError, 'Key is not a String' if !key.nil? && !key.is_a?(::String)
|
20
|
+
|
21
|
+
# id = SecureRandom.uuid
|
22
|
+
@native_instance = Binding.init(output_length).tap do |pointer|
|
23
|
+
::ObjectSpace.define_finalizer(self, self.class._create_finalizer(pointer))
|
24
|
+
end
|
25
|
+
@output_length = output_length
|
26
|
+
@key = key
|
27
|
+
@finalized = false
|
28
|
+
@result = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def update(data)
|
32
|
+
raise Finalized if @finalized
|
33
|
+
|
34
|
+
data_size = data.bytesize
|
35
|
+
data_buffer = ::FFI::MemoryPointer.new(:char, data_size)
|
36
|
+
data_buffer.put_bytes(0, data)
|
37
|
+
Binding.update(@native_instance, data_buffer, data_size).tap do |result|
|
38
|
+
raise UpdatingFailed unless result.zero?
|
39
|
+
end
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def <<(*args, **kwargs)
|
44
|
+
update(*args, **kwargs)
|
45
|
+
end
|
46
|
+
|
47
|
+
def digest
|
48
|
+
@finalized = true
|
49
|
+
return @_digest if @_digest
|
50
|
+
|
51
|
+
data_buffer = ::FFI::MemoryPointer.new(:char, @output_length)
|
52
|
+
customization_buffer, customization_size = @key.then do |key|
|
53
|
+
next [::FFI::MemoryPointer.new(:char, 0), 0] unless key
|
54
|
+
|
55
|
+
size = key.bytesize
|
56
|
+
[::FFI::MemoryPointer.new(:char, size).tap do |buffer|
|
57
|
+
buffer.put_bytes(0, key)
|
58
|
+
end, size]
|
59
|
+
end
|
60
|
+
Binding.final(@native_instance, data_buffer, customization_buffer, customization_size).tap do |result|
|
61
|
+
raise FinalizationFailed unless result.zero?
|
62
|
+
end
|
63
|
+
@_digest = data_buffer.get_bytes(0, @output_length)
|
64
|
+
end
|
65
|
+
|
66
|
+
def hexdigest
|
67
|
+
@_hexdigest ||= digest.unpack1('H*')
|
68
|
+
end
|
69
|
+
|
70
|
+
def base64digest
|
71
|
+
@_base64digest ||= ::Base64.strict_encode64(digest)
|
72
|
+
end
|
73
|
+
|
74
|
+
class << self
|
75
|
+
# https://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/
|
76
|
+
def _create_finalizer(instance)
|
77
|
+
proc {
|
78
|
+
Binding.destroy(instance)
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def digest(*args, **kwargs)
|
83
|
+
_generic_digest(*args, **kwargs, &:digest)
|
84
|
+
end
|
85
|
+
|
86
|
+
def hexdigest(*args, **kwargs)
|
87
|
+
_generic_digest(*args, **kwargs, &:hexdigest)
|
88
|
+
end
|
89
|
+
|
90
|
+
def base64digest(*args, **kwargs)
|
91
|
+
_generic_digest(*args, **kwargs, &:base64digest)
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def _generic_digest(data, output_length: nil, key: nil, &hash_finalizer)
|
97
|
+
instance = new(**{ output_length: output_length, key: key }.compact)
|
98
|
+
instance.update(data)
|
99
|
+
hash_finalizer.call(instance)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|