sha3 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +8 -5
- data/certs/johanns.pem +23 -22
- data/ext/sha3/config.h +26 -0
- data/ext/sha3/digest.c +6 -6
- data/ext/sha3/extconf.rb +40 -10
- data/ext/sha3/lib/common/align.h +33 -0
- data/ext/sha3/{brg_endian.h → lib/common/brg_endian.h} +8 -7
- data/ext/sha3/{KeccakHash.c → lib/high/Keccak/FIPS202/KeccakHash.c} +26 -25
- data/ext/sha3/{KeccakHash.h → lib/high/Keccak/FIPS202/KeccakHash.h} +34 -19
- data/ext/sha3/lib/high/Keccak/KeccakSponge.c +111 -0
- data/ext/sha3/lib/high/Keccak/KeccakSponge.h +76 -0
- data/ext/sha3/lib/high/Keccak/KeccakSponge.inc +316 -0
- data/ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-64.macros +748 -0
- data/ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-unrolling.macros +305 -0
- data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-SnP.h +44 -0
- data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference.h +23 -0
- data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference32BI.c +625 -0
- data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-SnP.h +44 -0
- data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.c +444 -0
- data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.h +23 -0
- data/lib/sha3/version.rb +1 -1
- data/sha3.gemspec +6 -5
- data/tests.sh +8 -7
- data.tar.gz.sig +0 -0
- metadata +50 -66
- metadata.gz.sig +0 -0
- data/ext/sha3/KeccakF-1600-interface.h +0 -40
- data/ext/sha3/KeccakSponge.c +0 -192
- data/ext/sha3/KeccakSponge.h +0 -113
- data/ext/sha3/Optimized64/KeccakF-1600-64.macros +0 -2199
- data/ext/sha3/Optimized64/KeccakF-1600-opt64-settings.h +0 -3
- data/ext/sha3/Optimized64/KeccakF-1600-opt64.c +0 -508
- data/ext/sha3/Optimized64/KeccakF-1600-unrolling.macros +0 -126
- data/ext/sha3/Optimized64/SnP-interface.h +0 -47
- data/ext/sha3/Reference/KeccakF-1600-reference.c +0 -311
- data/ext/sha3/Reference/KeccakF-reference.h +0 -26
- data/ext/sha3/Reference/SnP-FBWL-default.c +0 -96
- data/ext/sha3/Reference/SnP-FBWL-default.h +0 -26
- data/ext/sha3/Reference/SnP-interface.h +0 -42
- data/ext/sha3/Reference/displayIntermediateValues.c +0 -158
- data/ext/sha3/Reference/displayIntermediateValues.h +0 -34
- data/ext/sha3/SnP-Relaned.h +0 -249
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16edba407e859ee7afacc8a405666ec66cab0052cd7788e79089bd3f0d295844
|
4
|
+
data.tar.gz: 5552886038bbec790d086599cbbe6ad09a0c3561b58a9a2dfff2b9c9834b7154
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8e36ae984df177684d4b1a70689a80824e9d9ee70fd07812eaa50c8f0cd90a90f292dca435764842b737fb268084d09fa5f47450bdc9cf93316253c70484945
|
7
|
+
data.tar.gz: a643ded4e2f9828d732f428eba1757c6cc383797f32b52ba7427dae8234ac9bc0e158712ccf64d7be77f2538b80904efaf26a0e455ce9515f9a76679929054c0
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/sha3.svg)](https://badge.fury.io/rb/sha3) [![Ruby](https://github.com/johanns/sha3/actions/workflows/main.yml/badge.svg)](https://github.com/johanns/sha3/actions/workflows/main.yml)
|
4
4
|
|
5
|
-
**SHA3 for Ruby** is a native (C) binding to SHA3 (
|
5
|
+
**SHA3 for Ruby** is a XKCP based native (C) binding to SHA3 (FIPS 202) cryptographic hashing algorithm.
|
6
6
|
|
7
7
|
- [Home](https://github.com/johanns/sha3#readme)
|
8
8
|
- [Issues](https://github.com/johanns/sha3/issues)
|
9
9
|
- [Documentation](http://rubydoc.info/gems/sha3/frames)
|
10
|
+
- [XKCP - eXtended Keccak Code Package](https://github.com/XKCP/XKCP)
|
10
11
|
|
11
|
-
##
|
12
|
+
## Warning
|
12
13
|
|
13
14
|
- Please do NOT use SHA3 to hash passwords -- use a slow hashing function instead (e.g.: `pbkdf2`, `argon2`, `bcrypt` or `scrypt`)
|
14
15
|
- Version 1.0 introduces new API and is incompatible with previous versions (0.x).
|
@@ -92,9 +93,9 @@ s = SHA3::Digest.file("tests.sh")
|
|
92
93
|
# => #<SHA3::Digest: a9801db49389339...>
|
93
94
|
```
|
94
95
|
|
95
|
-
|
96
|
+
### Development Dependencies
|
96
97
|
|
97
|
-
* Native build tools (e.g., GCC, Minigw, etc.)
|
98
|
+
* Native build tools (e.g., Clang/LLVM, GCC, Minigw, etc.)
|
98
99
|
* Gems: rubygems-tasks, rake, rspec, yard
|
99
100
|
|
100
101
|
### Testing
|
@@ -109,9 +110,11 @@ Only a small subset of test vectors are included in the source repository; howev
|
|
109
110
|
|
110
111
|
Supported Ruby versions:
|
111
112
|
|
112
|
-
- MRI Ruby 2.
|
113
|
+
- MRI Ruby 2.6 - 3.1
|
113
114
|
|
115
|
+
## Credits
|
114
116
|
|
117
|
+
XKCP by Keccak team: [https://keccak.team/index.html]()
|
115
118
|
|
116
119
|
## Copyright
|
117
120
|
|
data/certs/johanns.pem
CHANGED
@@ -1,24 +1,25 @@
|
|
1
1
|
-----BEGIN CERTIFICATE-----
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
+
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
2
|
+
MIIETDCCArSgAwIBAgIBATANBgkqhkiG9w0BAQsFADA2MQswCQYDVQQDDAJpbzET
|
3
|
+
MBEGCgmSJomT8ixkARkWA2pzZzESMBAGCgmSJomT8ixkARkWAmlvMB4XDTIyMTAy
|
4
|
+
NDA2MzcxMVoXDTIzMTAyNDA2MzcxMVowNjELMAkGA1UEAwwCaW8xEzARBgoJkiaJ
|
5
|
+
k/IsZAEZFgNqc2cxEjAQBgoJkiaJk/IsZAEZFgJpbzCCAaIwDQYJKoZIhvcNAQEB
|
6
|
+
BQADggGPADCCAYoCggGBALQTl5BGmtYGvljWwOTxe2Uul7RoBcSOwFUh03qUvHJf
|
7
|
+
1LmWr6y1j97ogl/VffBXpbtTU4adZa+qTxfMs7GpfKDjikSIieZ7SrMNB68zCH0e
|
8
|
+
undHx+bMutN7919rviHfGyaXlQK4SsuWUl4AOlgT69VPQp6dOBYY9T78jbr/ZcG6
|
9
|
+
+mDlRpNfPVg5i67euvpR5dO9SpO1HNoHmzx5L4wYNr9QykIft1oA+Ne+SAF66ykn
|
10
|
+
agugF/R0Q7s+5Bpt3gr6SF2CvKsNJ2IS5TJO9unhLZ+h8FO7dcQw1EuJ31uHQKiD
|
11
|
+
rWUv2tnKCvLkHg0S69VeQtQv58dklJ3iFJcSen4VRtC7r5JMEd1VrdpXU4JQ54gY
|
12
|
+
tWrqWmazF9SOErbgvDlJgmlkMMkX6aoZ21/f1s6Z2myzP3KkRBjCf51BrgHTXTJD
|
13
|
+
28ANp21H0o0HhrpVFJVDjToXRLczsw0O9lnL+khzkeZoc+YTZuvJDLKokavXhb4a
|
14
|
+
vESgRttXjyN5jBKY7yFhKQIDAQABo2UwYzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
|
15
|
+
sDAdBgNVHQ4EFgQUKmyX3Q2uwTPM9S5+K/5kg7qe3ugwFAYDVR0RBA0wC4EJaW9A
|
16
|
+
anNnLmlvMBQGA1UdEgQNMAuBCWlvQGpzZy5pbzANBgkqhkiG9w0BAQsFAAOCAYEA
|
17
|
+
TexWHx3uLVObT+ylm3OE8Iue3cHdrDVE3zSjo8VlU3u1WBznH9MdoiPB7wux61Zx
|
18
|
+
jXUzBUaT7y7JnDaVGnECkpHXhfvPOYHBgkqEws6i79lAk/Va2U7EVPj0moM9d4Hv
|
19
|
+
12V8YVM1Z9QnfwBVo7YGb5o7W8lr01jj1gT+Qcw+kln7M3Y9RB+jQ4DwySHVIEMc
|
20
|
+
Ow7//MF7bhCz6T5uAOXlGe88wTHKW+fO1AmW5MIQZUojR5Ioxm80v2YdW/JnQZ1l
|
21
|
+
3VFpCutilnhDuzSw3DhgxReX7AK42aXFFclIzi11twW4KUPdt1KIvaoL/DgbZivl
|
22
|
+
PVG86dx4gfax2Mc2PiM+d1DiSllh+chh4dqRkIyhj0S4V7McQHkwW1ZBJ3kDf5rt
|
23
|
+
1O/udKquzj7egb6uceqzBB40W/1/CsNkGNpNZ8Bk8lrTmKw+3bJpj+nKWxovmF2p
|
24
|
+
VhzZDQf2jkcjBXKNA9Z5ku7g0TCR1/Y1V3ODgkTLqhw+kQZmlbQEVzcwxGk9eL8z
|
24
25
|
-----END CERTIFICATE-----
|
data/ext/sha3/config.h
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
/* File generated by ToTargetConfigFile.xsl */
|
2
|
+
|
3
|
+
#define XKCP_has_Sponge_Keccak
|
4
|
+
#define XKCP_has_FIPS202
|
5
|
+
#define XKCP_has_KeccakP1600
|
6
|
+
|
7
|
+
// #define XKCP_has_SP800_185
|
8
|
+
// #define XKCP_has_Duplex_Keccak
|
9
|
+
// #define XKCP_has_PRG_Keccak
|
10
|
+
// #define XKCP_has_Ketje
|
11
|
+
// #define XKCP_has_Keyak
|
12
|
+
// #define XKCP_has_KangarooTwelve
|
13
|
+
// #define XKCP_has_Kravatte
|
14
|
+
// #define XKCP_has_Xoofff
|
15
|
+
// #define XKCP_has_Xoodyak
|
16
|
+
// #define XKCP_has_KeccakP200
|
17
|
+
// #define XKCP_has_KeccakP400
|
18
|
+
// #define XKCP_has_KeccakP800
|
19
|
+
// #define XKCP_has_KeccakP1600
|
20
|
+
// #define XKCP_has_KeccakP1600times2
|
21
|
+
// #define XKCP_has_KeccakP1600times4
|
22
|
+
// #define XKCP_has_KeccakP1600times8
|
23
|
+
// #define XKCP_has_Xoodoo
|
24
|
+
// #define XKCP_has_Xoodootimes4
|
25
|
+
// #define XKCP_has_Xoodootimes8
|
26
|
+
// #define XKCP_has_Xoodootimes16
|
data/ext/sha3/digest.c
CHANGED
@@ -64,7 +64,7 @@ static VALUE c_digest_update(VALUE, VALUE);
|
|
64
64
|
|
65
65
|
HashReturn c_keccak_hash_initialize(MDX *mdx)
|
66
66
|
{
|
67
|
-
HashReturn r =
|
67
|
+
HashReturn r = KECCAK_FAIL;
|
68
68
|
|
69
69
|
switch (mdx->hashbitlen)
|
70
70
|
{
|
@@ -103,7 +103,7 @@ static VALUE c_digest_init(int argc, VALUE *argv, VALUE self)
|
|
103
103
|
mdx->hashbitlen = 256;
|
104
104
|
}
|
105
105
|
|
106
|
-
if (c_keccak_hash_initialize(mdx) !=
|
106
|
+
if (c_keccak_hash_initialize(mdx) != KECCAK_SUCCESS)
|
107
107
|
{
|
108
108
|
rb_raise(eSHA3DigestError, "failed to initialize algorithm state");
|
109
109
|
}
|
@@ -120,14 +120,14 @@ static VALUE c_digest_init(int argc, VALUE *argv, VALUE self)
|
|
120
120
|
static VALUE c_digest_update(VALUE self, VALUE data)
|
121
121
|
{
|
122
122
|
MDX *mdx;
|
123
|
-
|
123
|
+
BitLength dlen;
|
124
124
|
|
125
125
|
StringValue(data);
|
126
126
|
GETMDX(self, mdx);
|
127
127
|
|
128
128
|
dlen = (RSTRING_LEN(data) * 8);
|
129
129
|
|
130
|
-
if (Keccak_HashUpdate(mdx->state, (BitSequence *)RSTRING_PTR(data), dlen) !=
|
130
|
+
if (Keccak_HashUpdate(mdx->state, (BitSequence *)RSTRING_PTR(data), dlen) != KECCAK_SUCCESS)
|
131
131
|
{
|
132
132
|
rb_raise(eSHA3DigestError, "failed to update hash data");
|
133
133
|
}
|
@@ -144,7 +144,7 @@ static VALUE c_digest_reset(VALUE self)
|
|
144
144
|
|
145
145
|
memset(mdx->state, 0, sizeof(Keccak_HashInstance));
|
146
146
|
|
147
|
-
if (c_keccak_hash_initialize(mdx) !=
|
147
|
+
if (c_keccak_hash_initialize(mdx) != KECCAK_SUCCESS)
|
148
148
|
{
|
149
149
|
rb_raise(eSHA3DigestError, "failed to reset internal state");
|
150
150
|
}
|
@@ -236,7 +236,7 @@ static VALUE c_digest_finish(int argc, VALUE *argv, VALUE self)
|
|
236
236
|
rb_str_resize(str, mdx->hashbitlen / 8);
|
237
237
|
}
|
238
238
|
|
239
|
-
if (Keccak_HashFinal(mdx->state, (BitSequence *)RSTRING_PTR(str)) !=
|
239
|
+
if (Keccak_HashFinal(mdx->state, (BitSequence *)RSTRING_PTR(str)) != KECCAK_SUCCESS)
|
240
240
|
{
|
241
241
|
rb_raise(eSHA3DigestError, "failed to finalize digest");
|
242
242
|
}
|
data/ext/sha3/extconf.rb
CHANGED
@@ -1,20 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'mkmf'
|
2
4
|
require 'rbconfig'
|
3
5
|
|
4
|
-
|
6
|
+
# Maintaining XKCP lib directory structure to hopefully simplify
|
7
|
+
# future upgrades.
|
8
|
+
|
9
|
+
keccak_base_files = [
|
10
|
+
'lib/high/Keccak/KeccakSponge.c',
|
11
|
+
'lib/high/Keccak/FIPS202/KeccakHash.c'
|
12
|
+
]
|
13
|
+
|
14
|
+
if 1.size == 8
|
15
|
+
Logging.message "=== Using 64-bit reference ===\n"
|
5
16
|
|
6
|
-
|
7
|
-
Logging.message "=== Using optimized (64-bit) ===\n"
|
8
|
-
FileUtils.cp Dir["#{$srcdir}/Optimized64/*"].collect { |f| File.expand_path(f) }, "#{$srcdir}/"
|
17
|
+
keccak_base_files << 'lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.c'
|
9
18
|
else
|
10
|
-
Logging.message "=== Using reference ===\n"
|
11
|
-
|
19
|
+
Logging.message "=== Using 32-bit reference ===\n"
|
20
|
+
|
21
|
+
keccak_base_files << 'lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference32BI.c'
|
12
22
|
end
|
13
23
|
|
24
|
+
FileUtils.cp keccak_base_files.map { |f| "#{$srcdir}/#{f}" }, $srcdir
|
25
|
+
|
26
|
+
extension_name = 'sha3_n'
|
27
|
+
dir_config(extension_name)
|
28
|
+
|
29
|
+
$INCFLAGS << [
|
30
|
+
' -I$(src) ',
|
31
|
+
' -I$(srcdir)lib/ ',
|
32
|
+
' -I$(srcdir)/lib/common ',
|
33
|
+
' -I$(srcdir)/lib/high/Keccak ',
|
34
|
+
' -I$(srcdir)/lib/high/Keccak/FIPS202 ',
|
35
|
+
' -I$(srcdir)/lib/low/KeccakP-1600/common ',
|
36
|
+
' -I$(srcdir)/lib/low/KeccakP-1600/ref-32bits ',
|
37
|
+
' -I$(srcdir)/lib/low/KeccakP-1600/ref-64bits '
|
38
|
+
].join
|
39
|
+
|
40
|
+
$CFLAGS << ' -fomit-frame-pointer -O3 -g0 -fms-extensions '
|
41
|
+
$CFLAGS << ' -march=native ' if enable_config('march-tune-native', false)
|
42
|
+
|
14
43
|
find_header('sha3.h')
|
15
44
|
find_header('digest.h')
|
45
|
+
find_header('align.h')
|
46
|
+
find_header('brg_endian.h')
|
47
|
+
find_header('KeccakSponge.h')
|
48
|
+
find_header('KeccakHash.h')
|
16
49
|
|
17
|
-
|
18
|
-
$CFLAGS += ' -march=native ' if enable_config('march-tune-native', false)
|
19
|
-
|
20
|
-
create_makefile 'sha3_n'
|
50
|
+
create_makefile extension_name
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
The eXtended Keccak Code Package (XKCP)
|
3
|
+
https://github.com/XKCP/XKCP
|
4
|
+
|
5
|
+
Implementation by Gilles Van Assche and Ronny Van Keer, hereby denoted as "the implementer".
|
6
|
+
|
7
|
+
For more information, feedback or questions, please refer to the Keccak Team website:
|
8
|
+
https://keccak.team/
|
9
|
+
|
10
|
+
To the extent possible under law, the implementer has waived all copyright
|
11
|
+
and related or neighboring rights to the source code in this file.
|
12
|
+
http://creativecommons.org/publicdomain/zero/1.0/
|
13
|
+
*/
|
14
|
+
|
15
|
+
#ifndef _align_h_
|
16
|
+
#define _align_h_
|
17
|
+
|
18
|
+
/* on Mac OS-X and possibly others, ALIGN(x) is defined in param.h, and -Werror chokes on the redef. */
|
19
|
+
#ifdef ALIGN
|
20
|
+
#undef ALIGN
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#if defined(__GNUC__)
|
24
|
+
#define ALIGN(x) __attribute__ ((aligned(x)))
|
25
|
+
#elif defined(_MSC_VER)
|
26
|
+
#define ALIGN(x) __declspec(align(x))
|
27
|
+
#elif defined(__ARMCC_VERSION)
|
28
|
+
#define ALIGN(x) __align(x)
|
29
|
+
#else
|
30
|
+
#define ALIGN(x)
|
31
|
+
#endif
|
32
|
+
|
33
|
+
#endif
|
@@ -114,13 +114,14 @@
|
|
114
114
|
defined( __VMS ) || defined( _M_X64 )
|
115
115
|
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
116
116
|
|
117
|
-
#elif defined( AMIGA )
|
118
|
-
defined( _CRAY )
|
119
|
-
defined( ibm370 )
|
120
|
-
defined( __MRC__ )
|
121
|
-
defined( sparc )
|
122
|
-
defined( __VOS__ )
|
123
|
-
defined( THINK_C )
|
117
|
+
#elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \
|
118
|
+
defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \
|
119
|
+
defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \
|
120
|
+
defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \
|
121
|
+
defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \
|
122
|
+
defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \
|
123
|
+
defined( THINK_C ) || defined( __VMCMS__ ) || defined( _AIX ) || \
|
124
|
+
defined( __s390__ ) || defined( __s390x__ ) || defined( __zarch__ )
|
124
125
|
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
|
125
126
|
|
126
127
|
#elif defined(__arm__)
|
@@ -1,12 +1,13 @@
|
|
1
1
|
/*
|
2
|
-
|
3
|
-
|
4
|
-
denoted as "the implementer".
|
2
|
+
The eXtended Keccak Code Package (XKCP)
|
3
|
+
https://github.com/XKCP/XKCP
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
Keccak, designed by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche.
|
6
|
+
|
7
|
+
Implementation by the designers, hereby denoted as "the implementer".
|
8
|
+
|
9
|
+
For more information, feedback or questions, please refer to the Keccak Team website:
|
10
|
+
https://keccak.team/
|
10
11
|
|
11
12
|
To the extent possible under law, the implementer has waived all copyright
|
12
13
|
and related or neighboring rights to the source code in this file.
|
@@ -23,35 +24,35 @@ HashReturn Keccak_HashInitialize(Keccak_HashInstance *instance, unsigned int rat
|
|
23
24
|
HashReturn result;
|
24
25
|
|
25
26
|
if (delimitedSuffix == 0)
|
26
|
-
return
|
27
|
-
result = (HashReturn)
|
28
|
-
if (result !=
|
27
|
+
return KECCAK_FAIL;
|
28
|
+
result = (HashReturn)KeccakWidth1600_SpongeInitialize(&instance->sponge, rate, capacity);
|
29
|
+
if (result != KECCAK_SUCCESS)
|
29
30
|
return result;
|
30
31
|
instance->fixedOutputLength = hashbitlen;
|
31
32
|
instance->delimitedSuffix = delimitedSuffix;
|
32
|
-
return
|
33
|
+
return KECCAK_SUCCESS;
|
33
34
|
}
|
34
35
|
|
35
36
|
/* ---------------------------------------------------------------- */
|
36
37
|
|
37
|
-
HashReturn Keccak_HashUpdate(Keccak_HashInstance *instance, const BitSequence *data,
|
38
|
+
HashReturn Keccak_HashUpdate(Keccak_HashInstance *instance, const BitSequence *data, BitLength databitlen)
|
38
39
|
{
|
39
40
|
if ((databitlen % 8) == 0)
|
40
|
-
return (HashReturn)
|
41
|
+
return (HashReturn)KeccakWidth1600_SpongeAbsorb(&instance->sponge, data, databitlen/8);
|
41
42
|
else {
|
42
|
-
HashReturn ret = (HashReturn)
|
43
|
-
if (ret ==
|
44
|
-
|
43
|
+
HashReturn ret = (HashReturn)KeccakWidth1600_SpongeAbsorb(&instance->sponge, data, databitlen/8);
|
44
|
+
if (ret == KECCAK_SUCCESS) {
|
45
|
+
/* The last partial byte is assumed to be aligned on the least significant bits */
|
45
46
|
unsigned char lastByte = data[databitlen/8];
|
46
|
-
|
47
|
-
unsigned short delimitedLastBytes = (unsigned short)lastByte | ((unsigned short)instance->delimitedSuffix << (databitlen % 8));
|
47
|
+
/* Concatenate the last few bits provided here with those of the suffix */
|
48
|
+
unsigned short delimitedLastBytes = (unsigned short)((unsigned short)(lastByte & ((1 << (databitlen % 8)) - 1)) | ((unsigned short)instance->delimitedSuffix << (databitlen % 8)));
|
48
49
|
if ((delimitedLastBytes & 0xFF00) == 0x0000) {
|
49
50
|
instance->delimitedSuffix = delimitedLastBytes & 0xFF;
|
50
51
|
}
|
51
52
|
else {
|
52
53
|
unsigned char oneByte[1];
|
53
54
|
oneByte[0] = delimitedLastBytes & 0xFF;
|
54
|
-
ret = (HashReturn)
|
55
|
+
ret = (HashReturn)KeccakWidth1600_SpongeAbsorb(&instance->sponge, oneByte, 1);
|
55
56
|
instance->delimitedSuffix = (delimitedLastBytes >> 8) & 0xFF;
|
56
57
|
}
|
57
58
|
}
|
@@ -63,18 +64,18 @@ HashReturn Keccak_HashUpdate(Keccak_HashInstance *instance, const BitSequence *d
|
|
63
64
|
|
64
65
|
HashReturn Keccak_HashFinal(Keccak_HashInstance *instance, BitSequence *hashval)
|
65
66
|
{
|
66
|
-
HashReturn ret = (HashReturn)
|
67
|
-
if (ret ==
|
68
|
-
return (HashReturn)
|
67
|
+
HashReturn ret = (HashReturn)KeccakWidth1600_SpongeAbsorbLastFewBits(&instance->sponge, instance->delimitedSuffix);
|
68
|
+
if (ret == KECCAK_SUCCESS)
|
69
|
+
return (HashReturn)KeccakWidth1600_SpongeSqueeze(&instance->sponge, hashval, instance->fixedOutputLength/8);
|
69
70
|
else
|
70
71
|
return ret;
|
71
72
|
}
|
72
73
|
|
73
74
|
/* ---------------------------------------------------------------- */
|
74
75
|
|
75
|
-
HashReturn Keccak_HashSqueeze(Keccak_HashInstance *instance, BitSequence *data,
|
76
|
+
HashReturn Keccak_HashSqueeze(Keccak_HashInstance *instance, BitSequence *data, BitLength databitlen)
|
76
77
|
{
|
77
78
|
if ((databitlen % 8) != 0)
|
78
|
-
return
|
79
|
-
return (HashReturn)
|
79
|
+
return KECCAK_FAIL;
|
80
|
+
return (HashReturn)KeccakWidth1600_SpongeSqueeze(&instance->sponge, data, databitlen/8);
|
80
81
|
}
|
@@ -1,12 +1,13 @@
|
|
1
1
|
/*
|
2
|
-
|
3
|
-
|
4
|
-
denoted as "the implementer".
|
2
|
+
The eXtended Keccak Code Package (XKCP)
|
3
|
+
https://github.com/XKCP/XKCP
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
Keccak, designed by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche.
|
6
|
+
|
7
|
+
Implementation by the designers, hereby denoted as "the implementer".
|
8
|
+
|
9
|
+
For more information, feedback or questions, please refer to the Keccak Team website:
|
10
|
+
https://keccak.team/
|
10
11
|
|
11
12
|
To the extent possible under law, the implementer has waived all copyright
|
12
13
|
and related or neighboring rights to the source code in this file.
|
@@ -16,15 +17,24 @@ http://creativecommons.org/publicdomain/zero/1.0/
|
|
16
17
|
#ifndef _KeccakHashInterface_h_
|
17
18
|
#define _KeccakHashInterface_h_
|
18
19
|
|
19
|
-
#include "
|
20
|
+
#include "config.h"
|
21
|
+
#ifdef XKCP_has_KeccakP1600
|
22
|
+
|
23
|
+
#include <stdint.h>
|
20
24
|
#include <string.h>
|
25
|
+
#include "KeccakSponge.h"
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
typedef
|
27
|
+
#ifndef _Keccak_BitTypes_
|
28
|
+
#define _Keccak_BitTypes_
|
29
|
+
typedef uint8_t BitSequence;
|
30
|
+
|
31
|
+
typedef size_t BitLength;
|
32
|
+
#endif
|
33
|
+
|
34
|
+
typedef enum { KECCAK_SUCCESS = 0, KECCAK_FAIL = 1, KECCAK_BAD_HASHLEN = 2 } HashReturn;
|
25
35
|
|
26
36
|
typedef struct {
|
27
|
-
|
37
|
+
KeccakWidth1600_SpongeInstance sponge;
|
28
38
|
unsigned int fixedOutputLength;
|
29
39
|
unsigned char delimitedSuffix;
|
30
40
|
} Keccak_HashInstance;
|
@@ -42,7 +52,7 @@ typedef struct {
|
|
42
52
|
* formatted like the @a delimitedData parameter of
|
43
53
|
* the Keccak_SpongeAbsorbLastFewBits() function.
|
44
54
|
* @pre One must have r+c=1600 and the rate a multiple of 8 bits in this implementation.
|
45
|
-
* @return
|
55
|
+
* @return KECCAK_SUCCESS if successful, KECCAK_FAIL otherwise.
|
46
56
|
*/
|
47
57
|
HashReturn Keccak_HashInitialize(Keccak_HashInstance *hashInstance, unsigned int rate, unsigned int capacity, unsigned int hashbitlen, unsigned char delimitedSuffix);
|
48
58
|
|
@@ -76,11 +86,13 @@ HashReturn Keccak_HashInitialize(Keccak_HashInstance *hashInstance, unsigned int
|
|
76
86
|
* @param data Pointer to the input data.
|
77
87
|
* When @a databitLen is not a multiple of 8, the last bits of data must be
|
78
88
|
* in the least significant bits of the last byte (little-endian convention).
|
89
|
+
* In this case, the (8 - @a databitLen mod 8) most significant bits
|
90
|
+
* of the last byte are ignored.
|
79
91
|
* @param databitLen The number of input bits provided in the input data.
|
80
92
|
* @pre In the previous call to Keccak_HashUpdate(), databitlen was a multiple of 8.
|
81
|
-
* @return
|
93
|
+
* @return KECCAK_SUCCESS if successful, KECCAK_FAIL otherwise.
|
82
94
|
*/
|
83
|
-
HashReturn Keccak_HashUpdate(Keccak_HashInstance *hashInstance, const BitSequence *data,
|
95
|
+
HashReturn Keccak_HashUpdate(Keccak_HashInstance *hashInstance, const BitSequence *data, BitLength databitlen);
|
84
96
|
|
85
97
|
/**
|
86
98
|
* Function to call after all input blocks have been input and to get
|
@@ -90,9 +102,8 @@ HashReturn Keccak_HashUpdate(Keccak_HashInstance *hashInstance, const BitSequenc
|
|
90
102
|
* output bits is equal to @a hashbitlen.
|
91
103
|
* If @a hashbitlen was 0 in the call to Keccak_HashInitialize(), the output bits
|
92
104
|
* must be extracted using the Keccak_HashSqueeze() function.
|
93
|
-
* @param state Pointer to the state of the sponge function initialized by Init().
|
94
105
|
* @param hashval Pointer to the buffer where to store the output data.
|
95
|
-
* @return
|
106
|
+
* @return KECCAK_SUCCESS if successful, KECCAK_FAIL otherwise.
|
96
107
|
*/
|
97
108
|
HashReturn Keccak_HashFinal(Keccak_HashInstance *hashInstance, BitSequence *hashval);
|
98
109
|
|
@@ -103,8 +114,12 @@ HashReturn Keccak_HashFinal(Keccak_HashInstance *hashInstance, BitSequence *hash
|
|
103
114
|
* @param databitlen The number of output bits desired (must be a multiple of 8).
|
104
115
|
* @pre Keccak_HashFinal() must have been already called.
|
105
116
|
* @pre @a databitlen is a multiple of 8.
|
106
|
-
* @return
|
117
|
+
* @return KECCAK_SUCCESS if successful, KECCAK_FAIL otherwise.
|
107
118
|
*/
|
108
|
-
HashReturn Keccak_HashSqueeze(Keccak_HashInstance *hashInstance, BitSequence *data,
|
119
|
+
HashReturn Keccak_HashSqueeze(Keccak_HashInstance *hashInstance, BitSequence *data, BitLength databitlen);
|
120
|
+
|
121
|
+
#else
|
122
|
+
#error This requires an implementation of Keccak-p[1600]
|
123
|
+
#endif
|
109
124
|
|
110
125
|
#endif
|
@@ -0,0 +1,111 @@
|
|
1
|
+
/*
|
2
|
+
The eXtended Keccak Code Package (XKCP)
|
3
|
+
https://github.com/XKCP/XKCP
|
4
|
+
|
5
|
+
Keccak, designed by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche.
|
6
|
+
|
7
|
+
Implementation by the designers, hereby denoted as "the implementer".
|
8
|
+
|
9
|
+
For more information, feedback or questions, please refer to the Keccak Team website:
|
10
|
+
https://keccak.team/
|
11
|
+
|
12
|
+
To the extent possible under law, the implementer has waived all copyright
|
13
|
+
and related or neighboring rights to the source code in this file.
|
14
|
+
http://creativecommons.org/publicdomain/zero/1.0/
|
15
|
+
*/
|
16
|
+
|
17
|
+
#include "KeccakSponge.h"
|
18
|
+
|
19
|
+
#ifdef KeccakReference
|
20
|
+
#include "displayIntermediateValues.h"
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#ifdef XKCP_has_KeccakP200
|
24
|
+
#include "KeccakP-200-SnP.h"
|
25
|
+
|
26
|
+
#define prefix KeccakWidth200
|
27
|
+
#define SnP KeccakP200
|
28
|
+
#define SnP_width 200
|
29
|
+
#define SnP_Permute KeccakP200_Permute_18rounds
|
30
|
+
#if defined(KeccakF200_FastLoop_supported)
|
31
|
+
#define SnP_FastLoop_Absorb KeccakF200_FastLoop_Absorb
|
32
|
+
#endif
|
33
|
+
#include "KeccakSponge.inc"
|
34
|
+
#undef prefix
|
35
|
+
#undef SnP
|
36
|
+
#undef SnP_width
|
37
|
+
#undef SnP_Permute
|
38
|
+
#undef SnP_FastLoop_Absorb
|
39
|
+
#endif
|
40
|
+
|
41
|
+
#ifdef XKCP_has_KeccakP400
|
42
|
+
#include "KeccakP-400-SnP.h"
|
43
|
+
|
44
|
+
#define prefix KeccakWidth400
|
45
|
+
#define SnP KeccakP400
|
46
|
+
#define SnP_width 400
|
47
|
+
#define SnP_Permute KeccakP400_Permute_20rounds
|
48
|
+
#if defined(KeccakF400_FastLoop_supported)
|
49
|
+
#define SnP_FastLoop_Absorb KeccakF400_FastLoop_Absorb
|
50
|
+
#endif
|
51
|
+
#include "KeccakSponge.inc"
|
52
|
+
#undef prefix
|
53
|
+
#undef SnP
|
54
|
+
#undef SnP_width
|
55
|
+
#undef SnP_Permute
|
56
|
+
#undef SnP_FastLoop_Absorb
|
57
|
+
#endif
|
58
|
+
|
59
|
+
#ifdef XKCP_has_KeccakP800
|
60
|
+
#include "KeccakP-800-SnP.h"
|
61
|
+
|
62
|
+
#define prefix KeccakWidth800
|
63
|
+
#define SnP KeccakP800
|
64
|
+
#define SnP_width 800
|
65
|
+
#define SnP_Permute KeccakP800_Permute_22rounds
|
66
|
+
#if defined(KeccakF800_FastLoop_supported)
|
67
|
+
#define SnP_FastLoop_Absorb KeccakF800_FastLoop_Absorb
|
68
|
+
#endif
|
69
|
+
#include "KeccakSponge.inc"
|
70
|
+
#undef prefix
|
71
|
+
#undef SnP
|
72
|
+
#undef SnP_width
|
73
|
+
#undef SnP_Permute
|
74
|
+
#undef SnP_FastLoop_Absorb
|
75
|
+
#endif
|
76
|
+
|
77
|
+
#ifdef XKCP_has_KeccakP1600
|
78
|
+
#include "KeccakP-1600-SnP.h"
|
79
|
+
|
80
|
+
#define prefix KeccakWidth1600
|
81
|
+
#define SnP KeccakP1600
|
82
|
+
#define SnP_width 1600
|
83
|
+
#define SnP_Permute KeccakP1600_Permute_24rounds
|
84
|
+
#if defined(KeccakF1600_FastLoop_supported)
|
85
|
+
#define SnP_FastLoop_Absorb KeccakF1600_FastLoop_Absorb
|
86
|
+
#endif
|
87
|
+
#include "KeccakSponge.inc"
|
88
|
+
#undef prefix
|
89
|
+
#undef SnP
|
90
|
+
#undef SnP_width
|
91
|
+
#undef SnP_Permute
|
92
|
+
#undef SnP_FastLoop_Absorb
|
93
|
+
#endif
|
94
|
+
|
95
|
+
#ifdef XKCP_has_KeccakP1600
|
96
|
+
#include "KeccakP-1600-SnP.h"
|
97
|
+
|
98
|
+
#define prefix KeccakWidth1600_12rounds
|
99
|
+
#define SnP KeccakP1600
|
100
|
+
#define SnP_width 1600
|
101
|
+
#define SnP_Permute KeccakP1600_Permute_12rounds
|
102
|
+
#if defined(KeccakP1600_12rounds_FastLoop_supported)
|
103
|
+
#define SnP_FastLoop_Absorb KeccakP1600_12rounds_FastLoop_Absorb
|
104
|
+
#endif
|
105
|
+
#include "KeccakSponge.inc"
|
106
|
+
#undef prefix
|
107
|
+
#undef SnP
|
108
|
+
#undef SnP_width
|
109
|
+
#undef SnP_Permute
|
110
|
+
#undef SnP_FastLoop_Absorb
|
111
|
+
#endif
|