sha3 0.2.5 → 1.0.3

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 (57) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +232 -20
  3. data/.travis.yml +18 -12
  4. data/Gemfile +1 -1
  5. data/Gemfile.ci +5 -5
  6. data/LICENSE.txt +1 -1
  7. data/README.md +120 -0
  8. data/Rakefile +15 -18
  9. data/ext/sha3/KeccakF-1600-interface.h +28 -34
  10. data/ext/sha3/KeccakHash.c +80 -0
  11. data/ext/sha3/KeccakHash.h +110 -0
  12. data/ext/sha3/KeccakSponge.c +127 -201
  13. data/ext/sha3/KeccakSponge.h +74 -37
  14. data/ext/sha3/Optimized64/KeccakF-1600-64.macros +2199 -0
  15. data/ext/sha3/Optimized64/KeccakF-1600-opt64-settings.h +3 -0
  16. data/ext/sha3/Optimized64/KeccakF-1600-opt64.c +508 -0
  17. data/ext/sha3/{KeccakF-1600-unrolling.macros → Optimized64/KeccakF-1600-unrolling.macros} +16 -14
  18. data/ext/sha3/Optimized64/SnP-interface.h +47 -0
  19. data/ext/sha3/Reference/KeccakF-1600-reference.c +311 -0
  20. data/ext/sha3/Reference/KeccakF-reference.h +26 -0
  21. data/ext/sha3/Reference/SnP-FBWL-default.c +96 -0
  22. data/ext/sha3/Reference/SnP-FBWL-default.h +26 -0
  23. data/ext/sha3/Reference/SnP-interface.h +42 -0
  24. data/ext/sha3/{displayIntermediateValues.c → Reference/displayIntermediateValues.c} +52 -11
  25. data/ext/sha3/{displayIntermediateValues.h → Reference/displayIntermediateValues.h} +11 -6
  26. data/ext/sha3/SnP-Relaned.h +249 -0
  27. data/ext/sha3/brg_endian.h +0 -0
  28. data/ext/sha3/digest.c +182 -167
  29. data/ext/sha3/digest.h +37 -29
  30. data/ext/sha3/extconf.rb +13 -13
  31. data/ext/sha3/sha3.c +46 -30
  32. data/ext/sha3/sha3.h +10 -9
  33. data/lib/sha3/doc.rb +26 -39
  34. data/lib/sha3/version.rb +2 -3
  35. data/sha3.gemspec +13 -15
  36. data/spec/generate_tests.rb +22 -57
  37. data/spec/sha3_core_spec.rb +111 -133
  38. data/spec/spec_helper.rb +2 -2
  39. data/tests.sh +11 -9
  40. metadata +46 -51
  41. data/README.rdoc +0 -132
  42. data/ext/sha3/KeccakF-1600-32-rvk.macros +0 -555
  43. data/ext/sha3/KeccakF-1600-32-s1.macros +0 -1187
  44. data/ext/sha3/KeccakF-1600-32-s2.macros +0 -1187
  45. data/ext/sha3/KeccakF-1600-32.macros +0 -26
  46. data/ext/sha3/KeccakF-1600-64.macros +0 -728
  47. data/ext/sha3/KeccakF-1600-int-set.h +0 -6
  48. data/ext/sha3/KeccakF-1600-opt.c +0 -504
  49. data/ext/sha3/KeccakF-1600-opt32-settings.h +0 -4
  50. data/ext/sha3/KeccakF-1600-opt32.c-arch +0 -524
  51. data/ext/sha3/KeccakF-1600-opt64-settings.h +0 -7
  52. data/ext/sha3/KeccakF-1600-opt64.c-arch +0 -504
  53. data/ext/sha3/KeccakF-1600-reference.c-arch +0 -300
  54. data/ext/sha3/KeccakF-1600-x86-64-gas.s +0 -766
  55. data/ext/sha3/KeccakF-1600-x86-64-shld-gas.s +0 -766
  56. data/ext/sha3/KeccakNISTInterface.c +0 -81
  57. data/ext/sha3/KeccakNISTInterface.h +0 -70
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 035f7085d22a6bccff51be3775cde1b8aa61ff9a
4
- data.tar.gz: 52abae3fab52ae7634b0ad016d81e69895f98227
2
+ SHA256:
3
+ metadata.gz: 2abc34b466bf79618721bac7202c2e4c2617175a74843ae4e059e698da1bb813
4
+ data.tar.gz: c805b46df9491e191022164606330d1b4d8bb709470399558da0d8272041e210
5
5
  SHA512:
6
- metadata.gz: 18aeef47b4c1fb4a79ada7b4ea00323d47f9404d58c74b37586a858a2561727c944eb9ac778a6a673574c02dc4ad7e93535c4cd8ee1bf8b9b7db12c154cbdaf7
7
- data.tar.gz: fb635f1a539f597a0b6c74d9c74f3d0eff3862349df27b7212806e93c9f1ad0e2b16a6bef17ba38f5089b52846ce2912d95d5ef6fab8084547e4e95ba42887e3
6
+ metadata.gz: 61f430b210275ae079d8ce0baf13841b02fe817ff4ee80215eb99578920d1bff3131b453ec7bf80426b11607302404705cc55a017a0e19bded58485755f9d492
7
+ data.tar.gz: 475662e0c8a0d74b9222152a9b98bfed02bcb385551f212cac5cdc23e5e9a2eccc99ffb1c7bb101b1ca50fb55c3614d4e17d63b267a1ef4864339998df90f2c7
data/.gitignore CHANGED
@@ -1,22 +1,234 @@
1
+
2
+ # Created by https://www.toptal.com/developers/gitignore/api/c,clion,visualstudiocode,ruby
3
+ # Edit at https://www.toptal.com/developers/gitignore?templates=c,clion,visualstudiocode,ruby
4
+
5
+ ### C ###
6
+ # Prerequisites
7
+ *.d
8
+
9
+ # Object files
10
+ *.o
11
+ *.ko
12
+ *.obj
13
+ *.elf
14
+
15
+ # Linker output
16
+ *.ilk
17
+ *.map
18
+ *.exp
19
+
20
+ # Precompiled Headers
21
+ *.gch
22
+ *.pch
23
+
24
+ # Libraries
25
+ *.lib
26
+ *.a
27
+ *.la
28
+ *.lo
29
+
30
+ # Shared objects (inc. Windows DLLs)
31
+ *.dll
32
+ *.so
33
+ *.so.*
34
+ *.dylib
35
+
36
+ # Executables
37
+ *.exe
38
+ *.out
39
+ *.app
40
+ *.i*86
41
+ *.x86_64
42
+ *.hex
43
+
44
+ # Debug files
45
+ *.dSYM/
46
+ *.su
47
+ *.idb
48
+ *.pdb
49
+
50
+ # Kernel Module Compile Results
51
+ *.mod*
52
+ *.cmd
53
+ .tmp_versions/
54
+ modules.order
55
+ Module.symvers
56
+ Mkfile.old
57
+ dkms.conf
58
+
59
+ ### CLion ###
60
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
61
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
62
+
63
+ # User-specific stuff
64
+ .idea/**/workspace.xml
65
+ .idea/**/tasks.xml
66
+ .idea/**/usage.statistics.xml
67
+ .idea/**/dictionaries
68
+ .idea/**/shelf
69
+
70
+ # Generated files
71
+ .idea/**/contentModel.xml
72
+
73
+ # Sensitive or high-churn files
74
+ .idea/**/dataSources/
75
+ .idea/**/dataSources.ids
76
+ .idea/**/dataSources.local.xml
77
+ .idea/**/sqlDataSources.xml
78
+ .idea/**/dynamic.xml
79
+ .idea/**/uiDesigner.xml
80
+ .idea/**/dbnavigator.xml
81
+
82
+ # Gradle
83
+ .idea/**/gradle.xml
84
+ .idea/**/libraries
85
+
86
+ # Gradle and Maven with auto-import
87
+ # When using Gradle or Maven with auto-import, you should exclude module files,
88
+ # since they will be recreated, and may cause churn. Uncomment if using
89
+ # auto-import.
90
+ # .idea/artifacts
91
+ # .idea/compiler.xml
92
+ # .idea/jarRepositories.xml
93
+ # .idea/modules.xml
94
+ # .idea/*.iml
95
+ # .idea/modules
96
+ # *.iml
97
+ # *.ipr
98
+
99
+ # CMake
100
+ cmake-build-*/
101
+
102
+ # Mongo Explorer plugin
103
+ .idea/**/mongoSettings.xml
104
+
105
+ # File-based project format
106
+ *.iws
107
+
108
+ # IntelliJ
109
+ out/
110
+
111
+ # mpeltonen/sbt-idea plugin
112
+ .idea_modules/
113
+
114
+ # JIRA plugin
115
+ atlassian-ide-plugin.xml
116
+
117
+ # Cursive Clojure plugin
118
+ .idea/replstate.xml
119
+
120
+ # Crashlytics plugin (for Android Studio and IntelliJ)
121
+ com_crashlytics_export_strings.xml
122
+ crashlytics.properties
123
+ crashlytics-build.properties
124
+ fabric.properties
125
+
126
+ # Editor-based Rest Client
127
+ .idea/httpRequests
128
+
129
+ # Android studio 3.1+ serialized cache file
130
+ .idea/caches/build_file_checksums.ser
131
+
132
+ ### CLion Patch ###
133
+ # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
134
+
135
+ # *.iml
136
+ # modules.xml
137
+ # .idea/misc.xml
138
+ # *.ipr
139
+
140
+ # Sonarlint plugin
141
+ # https://plugins.jetbrains.com/plugin/7973-sonarlint
142
+ .idea/**/sonarlint/
143
+
144
+ # SonarQube Plugin
145
+ # https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
146
+ .idea/**/sonarIssues.xml
147
+
148
+ # Markdown Navigator plugin
149
+ # https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
150
+ .idea/**/markdown-navigator.xml
151
+ .idea/**/markdown-navigator-enh.xml
152
+ .idea/**/markdown-navigator/
153
+
154
+ # Cache file creation bug
155
+ # See https://youtrack.jetbrains.com/issue/JBR-2257
156
+ .idea/$CACHE_FILE$
157
+
158
+ # CodeStream plugin
159
+ # https://plugins.jetbrains.com/plugin/12206-codestream
160
+ .idea/codestream.xml
161
+
162
+ ### Ruby ###
1
163
  *.gem
2
164
  *.rbc
3
- *.rbx
4
- *.bundle
5
- *.so
6
- *.dll
7
- .config
8
- coverage
9
- InstalledFiles
10
- lib/bundler/man
11
- pkg
12
- rdoc
13
- spec/reports
14
- test/tmp
15
- test/version_tmp
16
- tmp
17
-
18
- # YARD artifacts
19
- .yardoc
20
- _yardoc
21
- doc/
22
- Gemfile.lock
165
+ /.config
166
+ /coverage/
167
+ /InstalledFiles
168
+ /pkg/
169
+ /spec/reports/
170
+ /spec/examples.txt
171
+ /test/tmp/
172
+ /test/version_tmp/
173
+ /tmp/
174
+
175
+ # Used by dotenv library to load environment variables.
176
+ # .env
177
+
178
+ # Ignore Byebug command history file.
179
+ .byebug_history
180
+
181
+ ## Specific to RubyMotion:
182
+ .dat*
183
+ .repl_history
184
+ build/
185
+ *.bridgesupport
186
+ build-iPhoneOS/
187
+ build-iPhoneSimulator/
188
+
189
+ ## Specific to RubyMotion (use of CocoaPods):
190
+ #
191
+ # We recommend against adding the Pods directory to your .gitignore. However
192
+ # you should judge for yourself, the pros and cons are mentioned at:
193
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
194
+ # vendor/Pods/
195
+
196
+ ## Documentation cache and generated files:
197
+ /.yardoc/
198
+ /_yardoc/
199
+ /doc/
200
+ /rdoc/
201
+
202
+ ## Environment normalization:
203
+ /.bundle/
204
+ /vendor/bundle
205
+ /lib/bundler/man/
206
+
207
+ # for a library or gem, you might want to ignore these files since the code is
208
+ # intended to run in multiple environments; otherwise, check them in:
209
+ # Gemfile.lock
210
+ # .ruby-version
211
+ # .ruby-gemset
212
+
213
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
214
+ .rvmrc
215
+
216
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
217
+ # .rubocop-https?--*
218
+
219
+ ### Ruby Patch ###
220
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
221
+ # .rubocop-https?--*
222
+
223
+ ### VisualStudioCode ###
224
+ .vscode/*
225
+ !.vscode/tasks.json
226
+ !.vscode/launch.json
227
+ *.code-workspace
228
+
229
+ ### VisualStudioCode Patch ###
230
+ # Ignore all local history of files
231
+ .history
232
+ .ionide
233
+
234
+ # End of https://www.toptal.com/developers/gitignore/api/c,clion,visualstudiocode,ruby
data/.travis.yml CHANGED
@@ -1,15 +1,21 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
4
- - 1.9.3
5
- - 1.9.2
6
- - 1.8.7
7
- - ruby-head
8
- - rbx-18mode
9
- - rbx-19mode
10
-
11
- gemfile: Gemfile.ci
1
+ arch:
2
+ - amd64
3
+ - arm64
12
4
 
13
5
  branches:
14
6
  only:
15
- - master
7
+ - master
8
+ - develop
9
+
10
+ gemfile: Gemfile.ci
11
+
12
+ language: ruby
13
+
14
+ os:
15
+ - linux
16
+
17
+ rvm:
18
+ - ruby-head
19
+ - 2.7
20
+ - 2.6
21
+ - 2.5
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  gemspec
data/Gemfile.ci CHANGED
@@ -1,8 +1,8 @@
1
- source "http://rubygems.org"
1
+ 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 'rake'
6
+ gem 'rspec'
7
+ gem 'rubygems-tasks'
8
+ gem 'yard'
data/LICENSE.txt CHANGED
@@ -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
data/README.md ADDED
@@ -0,0 +1,120 @@
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) [![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
+ - Please do NOT use SHA3 to hash passwords -- use a slow hashing function instead (e.g.: `pbkdf2`, `argon2`, `bcrypt` or `scrypt`)
14
+ - Version 1.0 introduces new API and is incompatible with previous versions (0.x).
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
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
+ Supported Ruby versions:
111
+
112
+ - MRI Ruby 2.4 - 3.0
113
+
114
+
115
+
116
+ ## Copyright
117
+
118
+ Copyright (c) 2012 - 2020 Johanns Gregorian (https://github.com/johanns)
119
+
120
+ **See LICENSE.txt for details.**
data/Rakefile CHANGED
@@ -1,43 +1,41 @@
1
- # encoding: utf-8
2
-
3
1
  require 'rubygems'
4
2
  require 'rake'
5
3
 
6
4
  begin
7
- gem 'rubygems-tasks', '~> 0.2'
5
+ gem 'rubygems-tasks'
8
6
  require 'rubygems/tasks'
9
7
 
10
8
  Gem::Tasks.new
11
9
  rescue LoadError => e
12
10
  warn e.message
13
- warn "Run `gem install rubygems-tasks` to install Gem::Tasks."
11
+ warn 'Run `gem install rubygems-tasks` to install Gem::Tasks.'
14
12
  end
15
13
 
16
14
  begin
17
- gem 'rspec', '~> 2.4'
15
+ gem 'rspec'
18
16
  require 'rspec/core/rake_task'
19
17
 
20
18
  RSpec::Core::RakeTask.new
21
- rescue LoadError => e
19
+ rescue LoadError
22
20
  task :spec do
23
- abort "Please run `gem install rspec` to install RSpec."
21
+ abort 'Please run `gem install rspec` to install RSpec.'
24
22
  end
25
23
  end
26
24
 
27
- task :test => :spec
28
- task :default => [:compile, :spec]
25
+ task test: :spec
26
+ task default: %i[compile spec]
29
27
 
30
28
  begin
31
- gem 'yard', '~> 0.8'
29
+ gem 'yard'
32
30
  require 'yard'
33
31
 
34
- YARD::Rake::YardocTask.new
35
- rescue LoadError => e
32
+ YARD::Rake::YardocTask.new
33
+ rescue LoadError
36
34
  task :yard do
37
- abort "Please run `gem install yard` to install YARD."
35
+ abort 'Please run `gem install yard` to install YARD.'
38
36
  end
39
37
  end
40
- task :doc => :yard
38
+ task doc: :yard
41
39
 
42
40
  begin
43
41
  gem 'rake-compiler'
@@ -47,11 +45,10 @@ begin
47
45
  ext.name = 'sha3_n'
48
46
  ext.ext_dir = 'ext/sha3'
49
47
  ext.tmp_dir = 'tmp'
50
- ext.source_pattern = "*.{c}"
48
+ ext.source_pattern = '*.{c}'
51
49
  end
52
- rescue LoadError => e
50
+ rescue LoadError
53
51
  task :compile do
54
- abort "Please run `gem install rake-compiler` to install Rake-Compiler."
52
+ abort 'Please run `gem install rake-compiler` to install Rake-Compiler.'
55
53
  end
56
54
  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
+ }