sha3 0.2.6 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sha3 might be problematic. Click here for more details.

Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +9 -1
  4. data/Gemfile.ci +4 -4
  5. data/LICENSE.txt +1 -1
  6. data/README.md +145 -0
  7. data/Rakefile +4 -5
  8. data/ext/sha3/KeccakF-1600-interface.h +28 -34
  9. data/ext/sha3/KeccakHash.c +80 -0
  10. data/ext/sha3/KeccakHash.h +110 -0
  11. data/ext/sha3/KeccakSponge.c +127 -201
  12. data/ext/sha3/KeccakSponge.h +74 -37
  13. data/ext/sha3/Optimized64/KeccakF-1600-64.macros +2199 -0
  14. data/ext/sha3/Optimized64/KeccakF-1600-opt64-settings.h +3 -0
  15. data/ext/sha3/Optimized64/KeccakF-1600-opt64.c +508 -0
  16. data/ext/sha3/{KeccakF-1600-unrolling.macros → Optimized64/KeccakF-1600-unrolling.macros} +16 -14
  17. data/ext/sha3/Optimized64/SnP-interface.h +47 -0
  18. data/ext/sha3/Reference/KeccakF-1600-reference.c +311 -0
  19. data/ext/sha3/Reference/KeccakF-reference.h +26 -0
  20. data/ext/sha3/Reference/SnP-FBWL-default.c +96 -0
  21. data/ext/sha3/Reference/SnP-FBWL-default.h +26 -0
  22. data/ext/sha3/Reference/SnP-interface.h +42 -0
  23. data/ext/sha3/{displayIntermediateValues.c → Reference/displayIntermediateValues.c} +52 -11
  24. data/ext/sha3/{displayIntermediateValues.h → Reference/displayIntermediateValues.h} +11 -6
  25. data/ext/sha3/SnP-Relaned.h +249 -0
  26. data/ext/sha3/brg_endian.h +0 -0
  27. data/ext/sha3/digest.c +67 -70
  28. data/ext/sha3/digest.h +2 -2
  29. data/ext/sha3/extconf.rb +7 -12
  30. data/ext/sha3/sha3.h +2 -2
  31. data/lib/sha3/doc.rb +26 -39
  32. data/lib/sha3/version.rb +2 -2
  33. data/sha3.gemspec +6 -6
  34. data/spec/generate_tests.rb +6 -41
  35. data/spec/sha3_core_spec.rb +111 -133
  36. data/spec/spec_helper.rb +2 -2
  37. data/tests.sh +9 -7
  38. metadata +33 -36
  39. data/README.rdoc +0 -131
  40. data/ext/sha3/KeccakF-1600-32-rvk.macros +0 -555
  41. data/ext/sha3/KeccakF-1600-32-s1.macros +0 -1187
  42. data/ext/sha3/KeccakF-1600-32-s2.macros +0 -1187
  43. data/ext/sha3/KeccakF-1600-32.macros +0 -26
  44. data/ext/sha3/KeccakF-1600-64.macros +0 -728
  45. data/ext/sha3/KeccakF-1600-int-set.h +0 -6
  46. data/ext/sha3/KeccakF-1600-opt.c +0 -504
  47. data/ext/sha3/KeccakF-1600-opt32-settings.h +0 -4
  48. data/ext/sha3/KeccakF-1600-opt32.c-arch +0 -524
  49. data/ext/sha3/KeccakF-1600-opt64-settings.h +0 -7
  50. data/ext/sha3/KeccakF-1600-opt64.c-arch +0 -504
  51. data/ext/sha3/KeccakF-1600-reference.c-arch +0 -300
  52. data/ext/sha3/KeccakF-1600-x86-64-gas.s +0 -766
  53. data/ext/sha3/KeccakF-1600-x86-64-shld-gas.s +0 -766
  54. data/ext/sha3/KeccakNISTInterface.c +0 -81
  55. data/ext/sha3/KeccakNISTInterface.h +0 -70
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 436b7ffcabd2a9189627fae92670969c380bcb32
4
- data.tar.gz: 8acf1e3317cd25aed84682f3c00859ac9bd77def
3
+ metadata.gz: 4eb74d4c4626be8751f643664a1820c0227a88dd
4
+ data.tar.gz: bb6c33da2459890eeb083874e209cbf75b3ca83e
5
5
  SHA512:
6
- metadata.gz: 1a9de0610411fca06486af4f447d8ea965726dc7e00bca1ae1ca9548c65156d34505c6aca06307a5bfec353fccad0ded756b2f446e01fbfcb57b45a25d722525
7
- data.tar.gz: 992efbc3bf525432faabde2c4ecc30435cc49718e76a7a5e9c27766f61bc3e5cf507535f42fc5efcfe3ec89d30491c4e1909a53092a58c98a0756afc868a95db
6
+ metadata.gz: ed137cc7d02d2c376b256c96f55bd430305fead1d00942cc251f7027c9651d08877b1a31372c9822cb8daf5fcebae689683b59c216d5bf3ffe413e179a5258cb
7
+ data.tar.gz: 1446633b9181a36ed9b0fa04a3d2a7593add059fbe473a496ad35b9c0837da9dd690b167d8bb2d2ea036b6dca60f83b644e8e0719e728d8883aa72064ed8a32d
data/.gitignore CHANGED
@@ -20,3 +20,5 @@ tmp
20
20
  _yardoc
21
21
  doc/
22
22
  Gemfile.lock
23
+
24
+ .idea/
@@ -1,11 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - ruby-head
3
4
  - 2.1.0
4
5
  - 2.0.0
5
6
  - 1.9.3
6
7
  - 1.9.2
7
8
  - 1.8.7
8
- - ruby-head
9
9
  - rbx-2
10
10
 
11
11
  gemfile: Gemfile.ci
@@ -13,3 +13,11 @@ gemfile: Gemfile.ci
13
13
  branches:
14
14
  only:
15
15
  - master
16
+
17
+ os:
18
+ - linux
19
+ - osx
20
+
21
+ matrix:
22
+ allow_failures:
23
+ - os: osx
data/Gemfile.ci CHANGED
@@ -2,10 +2,10 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rubygems-tasks', '> 0.2'
6
- gem 'rake', '> 0.9'
7
- gem 'rspec', '~> 2.11'
8
- gem 'yard', '~> 0.8'
5
+ gem 'rubygems-tasks'
6
+ gem 'rake'
7
+ gem 'rspec', '~> 3.3'
8
+ gem 'yard'
9
9
 
10
10
  platforms :rbx do
11
11
  gem 'racc'
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Johanns Gregorian
1
+ Copyright (c) 2015 Johanns Gregorian
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -0,0 +1,145 @@
1
+ # sha3
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/sha3.svg)](https://badge.fury.io/rb/sha3) [![CI](https://secure.travis-ci.org/johanns/sha3.png)](https://secure.travis-ci.org/johanns/sha3) [![Dependencies](https://gemnasium.com/johanns/sha3.png)](https://gemnasium.com/johanns/sha3) [![CodeClimate](https://codeclimate.com/github/johanns/sha3.png)](https://codeclimate.com/github/johanns/sha3)
4
+
5
+ **SHA3 for Ruby** is a native (C) binding to SHA3 (Keccak FIPS 202) cryptographic hashing algorithm.
6
+
7
+ - Home :: [https://github.com/johanns/sha3#readme]()
8
+ - Issues :: [https://github.com/johanns/sha3/issues]()
9
+ - Documentation :: [http://rubydoc.info/gems/sha3/frames]()
10
+
11
+ ## Warnings
12
+
13
+ - Version 1.0+ breaks compatibility with previous versions of this gem.
14
+ - Do NOT use SHA3 to hash passwords; use either ```bcrypt``` or ```scrypt``` instead!
15
+
16
+ ## Module details
17
+
18
+ **SHA3::Digest**: A standard *Digest* _subclass_. The interface, and operation of this class are parallel to digest classes bundled with MRI-based Rubies (e.g.: **Digest::SHA2**, and **OpenSSL::Digest**).
19
+
20
+ See [documentation for Ruby's **Digest** class for additional details](http://www.ruby-doc.org/stdlib-2.2.3/libdoc/digest/rdoc/Digest.html).
21
+
22
+ ## Installation
23
+
24
+ ```shell
25
+ gem install sha3
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ require 'sha3'
32
+ ```
33
+
34
+ Valid hash bit-lengths are: *224*, *256*, *384*, *512*.
35
+
36
+ ```ruby
37
+ :sha224 :sha256 :sha384 :sha512
38
+
39
+ # SHA3::Digest.new(224) is SHA3::Digest.new(:sha224)
40
+ ```
41
+
42
+ Alternatively, you can instantiate using one of four sub-classes:
43
+
44
+ ```ruby
45
+ SHA3::Digest::SHA224.new() # 224 bits
46
+ SHA3::Digest::SHA256.new() # 256 bits
47
+ SHA3::Digest::SHA384.new() # 384 bits
48
+ SHA3::Digest::SHA512.new() # 512 bits
49
+ ```
50
+
51
+ ### Basics
52
+
53
+ ```ruby
54
+ # Instantiate a new SHA3::Digest class with 256 bit length
55
+ s = SHA3::Digest.new(:sha256)
56
+
57
+ # OR #
58
+
59
+ s = SHA3::Digest::SHA256.new()
60
+
61
+ # Update hash state, and compute new value
62
+ s.update "Compute Me"
63
+
64
+ # << is an .update() alias
65
+ s << "Me too"
66
+
67
+ # Returns digest value in bytes
68
+ s.digest
69
+ # => "\xBE\xDF\r\xD9\xA1..."
70
+
71
+ # Returns digest value as hex string
72
+ s.hexdigest
73
+ # => "bedf0dd9a15b647..."
74
+
75
+ ### Digest class-methods: ###
76
+
77
+ SHA3::Digest.hexdigest(:sha224, "Hash me, please")
78
+ # => "200e7bc18cd613..."
79
+
80
+ SHA3::Digest::SHA384.digest("Hash me, please")
81
+ # => "\xF5\xCEpC\xB0eV..."
82
+ ```
83
+
84
+ ### Hashing a file
85
+
86
+ ```ruby
87
+ # Compute the hash value for given file, and return the result as hex
88
+ s = SHA3::Digest::SHA224.file("my_fantastical_file.bin").hexdigest
89
+
90
+ # Calling SHA3::Digest.file(...) defaults to SHA256
91
+ s = SHA3::Digest.file("tests.sh")
92
+ # => #<SHA3::Digest: a9801db49389339...>
93
+ ```
94
+
95
+ ## Development
96
+
97
+ * Native build tools (e.g., GCC, Minigw, etc.)
98
+ * Gems: rubygems-tasks, rake, rspec, yard
99
+
100
+ ### Testing + RSpec
101
+
102
+ Call ```rake``` to run the included RSpec tests.
103
+
104
+ Only a small subset of test vectors are included in the source repository; however, the complete test vectors suite is available for download. Simply run the ```tests.sh``` shell script (available in the root of source directory) to generate full byte-length RSpec test files.
105
+
106
+ ```sh tests.sh```
107
+
108
+ ### Rubies
109
+
110
+ Tested with Rubies:
111
+
112
+ - MRI Ruby-Head
113
+ - MRI 2.1.0
114
+ - MRI 2.0.0
115
+ - MRI 1.9.3
116
+ - MRI 1.9.2
117
+ - MRI 1.8.7
118
+ - Rubinius 2
119
+
120
+ On:
121
+
122
+ - Ubuntu 12.04, 12.10, 13.04, 14.04, 15.04
123
+ - Windows 7, 8, 8.1, 10
124
+ - Mac OS X 10.6 - 10.11
125
+
126
+ ## Releases
127
+
128
+ - *1.0.1* :: FIPS 202 compliance (breaks compatibility with earlier releases)
129
+ - *0.2.6* :: Fixed bug #4
130
+ - *0.2.5* :: Bug fixes. (See ChangeLog.rdoc)
131
+ - *0.2.4* :: Bug fixes. (YANKED)
132
+ - *0.2.3* :: Added documentation file (decoupled form C source); refactored C source.
133
+ - *0.2.2* :: Added sub-class for each SHA3 supported bit-lengths (example: SHA3::Digest::SHA256). Minor bug fix.
134
+ - *0.2.0* :: Production worthy, but breaks API compatibility with 0.1.x. Backward-compatibility will be maintained henceforth.
135
+ - *0.1.x* :: Alpha code, and not suitable for production.
136
+
137
+ ## TO DO
138
+
139
+ - Add SHAKE128/256 support
140
+
141
+ ## Copyright
142
+
143
+ Copyright (c) 2012 - 2015 Johanns Gregorian (https://github.com/johanns)
144
+
145
+ **See LICENSE.txt for details.**
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
  require 'rake'
5
5
 
6
6
  begin
7
- gem 'rubygems-tasks', '~> 0.2'
7
+ gem 'rubygems-tasks'
8
8
  require 'rubygems/tasks'
9
9
 
10
10
  Gem::Tasks.new
@@ -14,7 +14,7 @@ rescue LoadError => e
14
14
  end
15
15
 
16
16
  begin
17
- gem 'rspec', '~> 2.4'
17
+ gem 'rspec', '~> 3.3'
18
18
  require 'rspec/core/rake_task'
19
19
 
20
20
  RSpec::Core::RakeTask.new
@@ -28,10 +28,10 @@ task :test => :spec
28
28
  task :default => [:compile, :spec]
29
29
 
30
30
  begin
31
- gem 'yard', '~> 0.8'
31
+ gem 'yard'
32
32
  require 'yard'
33
33
 
34
- YARD::Rake::YardocTask.new
34
+ YARD::Rake::YardocTask.new
35
35
  rescue LoadError => e
36
36
  task :yard do
37
37
  abort "Please run `gem install yard` to install YARD."
@@ -54,4 +54,3 @@ rescue LoadError => e
54
54
  abort "Please run `gem install rake-compiler` to install Rake-Compiler."
55
55
  end
56
56
  end
57
-
@@ -1,46 +1,40 @@
1
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/
2
+ Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni,
3
+ Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby
4
+ denoted as "the implementer".
5
5
 
6
- Implementation by the designers,
7
- hereby denoted as "the implementer".
6
+ For more information, feedback or questions, please refer to our websites:
7
+ http://keccak.noekeon.org/
8
+ http://keyak.noekeon.org/
9
+ http://ketje.noekeon.org/
8
10
 
9
11
  To the extent possible under law, the implementer has waived all copyright
10
12
  and related or neighboring rights to the source code in this file.
11
13
  http://creativecommons.org/publicdomain/zero/1.0/
12
14
  */
13
15
 
14
- #ifndef _KeccakPermutationInterface_h_
15
- #define _KeccakPermutationInterface_h_
16
+ #ifndef _KeccakF1600Interface_h_
17
+ #define _KeccakF1600Interface_h_
16
18
 
17
- #include "KeccakF-1600-int-set.h"
19
+ #include <string.h>
18
20
 
19
- void KeccakInitialize( void );
20
- void KeccakInitializeState(unsigned char *state);
21
- void KeccakPermutation(unsigned char *state);
22
- #ifdef ProvideFast576
23
- void KeccakAbsorb576bits(unsigned char *state, const unsigned char *data);
24
- #endif
25
- #ifdef ProvideFast832
26
- void KeccakAbsorb832bits(unsigned char *state, const unsigned char *data);
27
- #endif
28
- #ifdef ProvideFast1024
29
- void KeccakAbsorb1024bits(unsigned char *state, const unsigned char *data);
30
- #endif
31
- #ifdef ProvideFast1088
32
- void KeccakAbsorb1088bits(unsigned char *state, const unsigned char *data);
33
- #endif
34
- #ifdef ProvideFast1152
35
- void KeccakAbsorb1152bits(unsigned char *state, const unsigned char *data);
36
- #endif
37
- #ifdef ProvideFast1344
38
- void KeccakAbsorb1344bits(unsigned char *state, const unsigned char *data);
39
- #endif
40
- void KeccakAbsorb(unsigned char *state, const unsigned char *data, unsigned int laneCount);
41
- #ifdef ProvideFast1024
42
- void KeccakExtract1024bits(const unsigned char *state, unsigned char *data);
43
- #endif
44
- void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount);
21
+ #define KeccakF_width 1600
22
+ #define KeccakF_laneInBytes 8
23
+ #define KeccakF_stateSizeInBytes (KeccakF_width/8)
24
+ #define KeccakF_1600
25
+
26
+ void KeccakF1600_Initialize( void );
27
+ void KeccakF1600_StateInitialize(void *state);
28
+ void KeccakF1600_StateXORBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length);
29
+ void KeccakF1600_StateOverwriteBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length);
30
+ void KeccakF1600_StateOverwriteWithZeroes(void *state, unsigned int byteCount);
31
+ void KeccakF1600_StateComplementBit(void *state, unsigned int position);
32
+ void KeccakF1600_StatePermute(void *state);
33
+ void KeccakF1600_StateExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length);
34
+ void KeccakF1600_StateExtractAndXORBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length);
35
+ size_t KeccakF1600_FBWL_Absorb(void *state, unsigned int laneCount, const unsigned char *data, size_t dataByteLen, unsigned char trailingBits);
36
+ size_t KeccakF1600_FBWL_Squeeze(void *state, unsigned int laneCount, unsigned char *data, size_t dataByteLen);
37
+ size_t KeccakF1600_FBWL_Wrap(void *state, unsigned int laneCount, const unsigned char *dataIn, unsigned char *dataOut, size_t dataByteLen, unsigned char trailingBits);
38
+ size_t KeccakF1600_FBWL_Unwrap(void *state, unsigned int laneCount, const unsigned char *dataIn, unsigned char *dataOut, size_t dataByteLen, unsigned char trailingBits);
45
39
 
46
40
  #endif
@@ -0,0 +1,80 @@
1
+ /*
2
+ Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni,
3
+ Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby
4
+ denoted as "the implementer".
5
+
6
+ For more information, feedback or questions, please refer to our websites:
7
+ http://keccak.noekeon.org/
8
+ http://keyak.noekeon.org/
9
+ http://ketje.noekeon.org/
10
+
11
+ To the extent possible under law, the implementer has waived all copyright
12
+ and related or neighboring rights to the source code in this file.
13
+ http://creativecommons.org/publicdomain/zero/1.0/
14
+ */
15
+
16
+ #include <string.h>
17
+ #include "KeccakHash.h"
18
+
19
+ /* ---------------------------------------------------------------- */
20
+
21
+ HashReturn Keccak_HashInitialize(Keccak_HashInstance *instance, unsigned int rate, unsigned int capacity, unsigned int hashbitlen, unsigned char delimitedSuffix)
22
+ {
23
+ HashReturn result;
24
+
25
+ if (delimitedSuffix == 0)
26
+ return FAIL;
27
+ result = (HashReturn)Keccak_SpongeInitialize(&instance->sponge, rate, capacity);
28
+ if (result != SUCCESS)
29
+ return result;
30
+ instance->fixedOutputLength = hashbitlen;
31
+ instance->delimitedSuffix = delimitedSuffix;
32
+ return SUCCESS;
33
+ }
34
+
35
+ /* ---------------------------------------------------------------- */
36
+
37
+ HashReturn Keccak_HashUpdate(Keccak_HashInstance *instance, const BitSequence *data, DataLength databitlen)
38
+ {
39
+ if ((databitlen % 8) == 0)
40
+ return (HashReturn)Keccak_SpongeAbsorb(&instance->sponge, data, databitlen/8);
41
+ else {
42
+ HashReturn ret = (HashReturn)Keccak_SpongeAbsorb(&instance->sponge, data, databitlen/8);
43
+ if (ret == SUCCESS) {
44
+ // The last partial byte is assumed to be aligned on the least significant bits
45
+ unsigned char lastByte = data[databitlen/8];
46
+ // Concatenate the last few bits provided here with those of the suffix
47
+ unsigned short delimitedLastBytes = (unsigned short)lastByte | ((unsigned short)instance->delimitedSuffix << (databitlen % 8));
48
+ if ((delimitedLastBytes & 0xFF00) == 0x0000) {
49
+ instance->delimitedSuffix = delimitedLastBytes & 0xFF;
50
+ }
51
+ else {
52
+ unsigned char oneByte[1];
53
+ oneByte[0] = delimitedLastBytes & 0xFF;
54
+ ret = (HashReturn)Keccak_SpongeAbsorb(&instance->sponge, oneByte, 1);
55
+ instance->delimitedSuffix = (delimitedLastBytes >> 8) & 0xFF;
56
+ }
57
+ }
58
+ return ret;
59
+ }
60
+ }
61
+
62
+ /* ---------------------------------------------------------------- */
63
+
64
+ HashReturn Keccak_HashFinal(Keccak_HashInstance *instance, BitSequence *hashval)
65
+ {
66
+ HashReturn ret = (HashReturn)Keccak_SpongeAbsorbLastFewBits(&instance->sponge, instance->delimitedSuffix);
67
+ if (ret == SUCCESS)
68
+ return (HashReturn)Keccak_SpongeSqueeze(&instance->sponge, hashval, instance->fixedOutputLength/8);
69
+ else
70
+ return ret;
71
+ }
72
+
73
+ /* ---------------------------------------------------------------- */
74
+
75
+ HashReturn Keccak_HashSqueeze(Keccak_HashInstance *instance, BitSequence *data, DataLength databitlen)
76
+ {
77
+ if ((databitlen % 8) != 0)
78
+ return FAIL;
79
+ return (HashReturn)Keccak_SpongeSqueeze(&instance->sponge, data, databitlen/8);
80
+ }
@@ -0,0 +1,110 @@
1
+ /*
2
+ Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni,
3
+ Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby
4
+ denoted as "the implementer".
5
+
6
+ For more information, feedback or questions, please refer to our websites:
7
+ http://keccak.noekeon.org/
8
+ http://keyak.noekeon.org/
9
+ http://ketje.noekeon.org/
10
+
11
+ To the extent possible under law, the implementer has waived all copyright
12
+ and related or neighboring rights to the source code in this file.
13
+ http://creativecommons.org/publicdomain/zero/1.0/
14
+ */
15
+
16
+ #ifndef _KeccakHashInterface_h_
17
+ #define _KeccakHashInterface_h_
18
+
19
+ #include "KeccakSponge.h"
20
+ #include <string.h>
21
+
22
+ typedef unsigned char BitSequence;
23
+ typedef size_t DataLength;
24
+ typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2 } HashReturn;
25
+
26
+ typedef struct {
27
+ Keccak_SpongeInstance sponge;
28
+ unsigned int fixedOutputLength;
29
+ unsigned char delimitedSuffix;
30
+ } Keccak_HashInstance;
31
+
32
+ /**
33
+ * Function to initialize the Keccak[r, c] sponge function instance used in sequential hashing mode.
34
+ * @param hashInstance Pointer to the hash instance to be initialized.
35
+ * @param rate The value of the rate r.
36
+ * @param capacity The value of the capacity c.
37
+ * @param hashbitlen The desired number of output bits,
38
+ * or 0 for an arbitrarily-long output.
39
+ * @param delimitedSuffix Bits that will be automatically appended to the end
40
+ * of the input message, as in domain separation.
41
+ * This is a byte containing from 0 to 7 bits
42
+ * formatted like the @a delimitedData parameter of
43
+ * the Keccak_SpongeAbsorbLastFewBits() function.
44
+ * @pre One must have r+c=1600 and the rate a multiple of 8 bits in this implementation.
45
+ * @return SUCCESS if successful, FAIL otherwise.
46
+ */
47
+ HashReturn Keccak_HashInitialize(Keccak_HashInstance *hashInstance, unsigned int rate, unsigned int capacity, unsigned int hashbitlen, unsigned char delimitedSuffix);
48
+
49
+ /** Macro to initialize a SHAKE128 instance as specified in the FIPS 202 standard.
50
+ */
51
+ #define Keccak_HashInitialize_SHAKE128(hashInstance) Keccak_HashInitialize(hashInstance, 1344, 256, 0, 0x1F)
52
+
53
+ /** Macro to initialize a SHAKE256 instance as specified in the FIPS 202 standard.
54
+ */
55
+ #define Keccak_HashInitialize_SHAKE256(hashInstance) Keccak_HashInitialize(hashInstance, 1088, 512, 0, 0x1F)
56
+
57
+ /** Macro to initialize a SHA3-224 instance as specified in the FIPS 202 standard.
58
+ */
59
+ #define Keccak_HashInitialize_SHA3_224(hashInstance) Keccak_HashInitialize(hashInstance, 1152, 448, 224, 0x06)
60
+
61
+ /** Macro to initialize a SHA3-256 instance as specified in the FIPS 202 standard.
62
+ */
63
+ #define Keccak_HashInitialize_SHA3_256(hashInstance) Keccak_HashInitialize(hashInstance, 1088, 512, 256, 0x06)
64
+
65
+ /** Macro to initialize a SHA3-384 instance as specified in the FIPS 202 standard.
66
+ */
67
+ #define Keccak_HashInitialize_SHA3_384(hashInstance) Keccak_HashInitialize(hashInstance, 832, 768, 384, 0x06)
68
+
69
+ /** Macro to initialize a SHA3-512 instance as specified in the FIPS 202 standard.
70
+ */
71
+ #define Keccak_HashInitialize_SHA3_512(hashInstance) Keccak_HashInitialize(hashInstance, 576, 1024, 512, 0x06)
72
+
73
+ /**
74
+ * Function to give input data to be absorbed.
75
+ * @param hashInstance Pointer to the hash instance initialized by Keccak_HashInitialize().
76
+ * @param data Pointer to the input data.
77
+ * When @a databitLen is not a multiple of 8, the last bits of data must be
78
+ * in the least significant bits of the last byte (little-endian convention).
79
+ * @param databitLen The number of input bits provided in the input data.
80
+ * @pre In the previous call to Keccak_HashUpdate(), databitlen was a multiple of 8.
81
+ * @return SUCCESS if successful, FAIL otherwise.
82
+ */
83
+ HashReturn Keccak_HashUpdate(Keccak_HashInstance *hashInstance, const BitSequence *data, DataLength databitlen);
84
+
85
+ /**
86
+ * Function to call after all input blocks have been input and to get
87
+ * output bits if the length was specified when calling Keccak_HashInitialize().
88
+ * @param hashInstance Pointer to the hash instance initialized by Keccak_HashInitialize().
89
+ * If @a hashbitlen was not 0 in the call to Keccak_HashInitialize(), the number of
90
+ * output bits is equal to @a hashbitlen.
91
+ * If @a hashbitlen was 0 in the call to Keccak_HashInitialize(), the output bits
92
+ * must be extracted using the Keccak_HashSqueeze() function.
93
+ * @param state Pointer to the state of the sponge function initialized by Init().
94
+ * @param hashval Pointer to the buffer where to store the output data.
95
+ * @return SUCCESS if successful, FAIL otherwise.
96
+ */
97
+ HashReturn Keccak_HashFinal(Keccak_HashInstance *hashInstance, BitSequence *hashval);
98
+
99
+ /**
100
+ * Function to squeeze output data.
101
+ * @param hashInstance Pointer to the hash instance initialized by Keccak_HashInitialize().
102
+ * @param data Pointer to the buffer where to store the output data.
103
+ * @param databitlen The number of output bits desired (must be a multiple of 8).
104
+ * @pre Keccak_HashFinal() must have been already called.
105
+ * @pre @a databitlen is a multiple of 8.
106
+ * @return SUCCESS if successful, FAIL otherwise.
107
+ */
108
+ HashReturn Keccak_HashSqueeze(Keccak_HashInstance *hashInstance, BitSequence *data, DataLength databitlen);
109
+
110
+ #endif