sha3 0.2.3 → 0.2.5

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.

@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 035f7085d22a6bccff51be3775cde1b8aa61ff9a
4
+ data.tar.gz: 52abae3fab52ae7634b0ad016d81e69895f98227
5
+ SHA512:
6
+ metadata.gz: 18aeef47b4c1fb4a79ada7b4ea00323d47f9404d58c74b37586a858a2561727c944eb9ac778a6a673574c02dc4ad7e93535c4cd8ee1bf8b9b7db12c154cbdaf7
7
+ data.tar.gz: fb635f1a539f597a0b6c74d9c74f3d0eff3862349df27b7212806e93c9f1ad0e2b16a6bef17ba38f5089b52846ce2912d95d5ef6fab8084547e4e95ba42887e3
data/.gitignore CHANGED
@@ -18,4 +18,5 @@ tmp
18
18
  # YARD artifacts
19
19
  .yardoc
20
20
  _yardoc
21
- doc/
21
+ doc/
22
+ Gemfile.lock
@@ -1,13 +1,13 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.0.0
3
4
  - 1.9.3
4
5
  - 1.9.2
5
6
  - 1.8.7
6
7
  - ruby-head
7
8
  - rbx-18mode
8
9
  - rbx-19mode
9
- - ree
10
-
10
+
11
11
  gemfile: Gemfile.ci
12
12
 
13
13
  branches:
@@ -17,3 +17,11 @@
17
17
  === 0.2.3 / 2013-1-28
18
18
 
19
19
  * Added documentation file (decoupled form C source); refactored C source.
20
+
21
+ === 0.2.4 / 2013-5-20
22
+
23
+ * Fixed instance copy validation code (YANKED)
24
+
25
+ === 0.2.5 / 2013-5-21
26
+
27
+ * Fixed the fix to instance copy validation code.
@@ -1,6 +1,6 @@
1
1
  = sha3 {<img src="https://secure.travis-ci.org/johanns/sha3.png" alt="Build Status" />}[http://travis-ci.org/johanns/sha3] {<img src="https://gemnasium.com/johanns/sha3.png" alt="Dependency Status" />}[https://gemnasium.com/johanns/sha3]
2
2
 
3
- <em>SHA3 for Ruby</em> is a native (C) implementation of Keccak (SHA3) cryptographic hashing algorithm. Platform optimized reference is used, wherever possible.
3
+ <em>SHA3 for Ruby</em> is a native (C) implementation of Keccak (SHA3) cryptographic hashing algorithm.
4
4
 
5
5
  Home :: https://github.com/johanns/sha3#readme
6
6
  Issues :: https://github.com/johanns/sha3/issues
@@ -14,18 +14,18 @@ Documentation :: http://rubydoc.info/gems/sha3/frames
14
14
 
15
15
  == Installation
16
16
 
17
- $ gem install sha3
17
+ gem install sha3
18
18
 
19
19
  == Usage
20
20
 
21
21
  require 'sha3'
22
22
 
23
- Valid hash bit-lengths are: *224*, *256*, *384*, *512*. You may also use corresponding symbols when instantiating a new instance or calling the <em>SHA3::Digest.compute()</em> method:
24
-
23
+ Valid hash bit-lengths are: *224*, *256*, *384*, *512*. You may also use corresponding symbols when instantiating a new instance or calling the <em>SHA3::Digest.compute()</em> method:
24
+
25
25
  :sha224 :sha256 :sha384 :sha512
26
26
 
27
27
  # SHA3::Digest.new(224) is SHA3::Digest.new(:sha224)
28
-
28
+
29
29
  Alternatively, you can instantiate using one of four sub-classes:
30
30
 
31
31
  SHA3::Digest::SHA224.new() # 224 bits
@@ -34,35 +34,35 @@ Alternatively, you can instantiate using one of four sub-classes:
34
34
  SHA3::Digest::SHA512.new() # 512 bits
35
35
 
36
36
  === Basics
37
-
37
+
38
38
  # Instantiate a new SHA3::Digest class with 256 bit length
39
39
  s = SHA3::Digest.new(:sha256)
40
-
40
+
41
41
  # OR #
42
-
42
+
43
43
  s = SHA3::Digest::SHA256.new()
44
-
44
+
45
45
  # Update hash state, and compute new value
46
46
  s.update "Compute Me"
47
-
47
+
48
48
  # << is an .update() alias
49
49
  s << "Me too"
50
-
50
+
51
51
  # Returns digest value in bytes
52
52
  s.digest
53
- # => "\xBE\xDF\r\xD9\xA1[dt \x8BbLN\x8A\x1Eg,\xE0\xF0d\x98\xE3\xAB\xD7\xCC7\xF0\xAEiu\x92Y"
54
-
53
+ # => "\xBE\xDF\r\xD9\xA1..."
54
+
55
55
  # Returns digest value as hex string
56
56
  s.hexdigest
57
- # => "bedf0dd9a15b6474208b624c4e8a1e672ce0f06498e3abd7cc37f0ae69759259"
57
+ # => "bedf0dd9a15b647..."
58
58
 
59
59
  ### Digest class-methods: ###
60
-
60
+
61
61
  SHA3::Digest.hexdigest("Hash me, please", :sha224)
62
- # => "200e7bc18cd6132689eb8fa3f7c3a978d73215384a626c23e4508f33"
62
+ # => "200e7bc18cd613..."
63
63
 
64
64
  SHA3::Digest::SHA384.digest("Hash me, please")
65
- # => "\xF5\xCEpC\xB0eV\xA3\x92P\xF8\x93\xB8\x145\x19\x1A)\xB1\x88\xBF\a\a7\x88\f\xFETI\e\x17\x80\xEC\xA6}\xABR\xAE\xAFK\xFF|d\x81\xF7\xB5\x9Ah"
65
+ # => "\xF5\xCEpC\xB0eV..."
66
66
 
67
67
  === Hashing a file
68
68
 
@@ -71,13 +71,13 @@ Alternatively, you can instantiate using one of four sub-classes:
71
71
 
72
72
  # Calling SHA3::Digest.file(...) defaults to SHA256
73
73
  s = SHA3::Digest.file("tests.sh")
74
- # => #<SHA3::Digest: a9801db49389339bd8a62817f229f0f9394ca73b34fd7dbc7ec5ed7a99bc49f1>
74
+ # => #<SHA3::Digest: a9801db49389339...>
75
75
 
76
76
  === Bit-length hashing
77
-
77
+
78
78
  # Compute hash of "011"
79
79
  SHA3::Digest.compute(:sha224, "\xC0", 3).unpack("H*")
80
- # => ["2b695a6fd92a2b3f3ce9cfca617d22c9bb52815dd59a9719b01bad25"]
80
+ # => ["2b695a6fd92a..."]
81
81
 
82
82
  == Development
83
83
 
@@ -96,6 +96,7 @@ Only a small subset of test vectors are included in the source repository; howev
96
96
 
97
97
  Tested with Rubies:
98
98
 
99
+ - MRI 2.0.0
99
100
  - MRI 1.9.3
100
101
  - MRI 1.9.2
101
102
  - MRI 1.8.7
@@ -106,7 +107,7 @@ Tested with Rubies:
106
107
 
107
108
  On:
108
109
 
109
- - Ubuntu 12.04, 12.10
110
+ - Ubuntu 12.04, 12.10, 13.04
110
111
  - Windows 7, 8
111
112
  - Mac OS X 10.8
112
113
 
@@ -116,6 +117,8 @@ On:
116
117
  *0.2.0* :: Production worthy, but breaks API compatibility with 0.1.x. Backward-compatibility will be maintained henceforth.
117
118
  *0.2.2* :: Added sub-class for each SHA3 supported bit-lengths (example: SHA3::Digest::SHA256). Minor bug fix.
118
119
  *0.2.3* :: Added documentation file (decoupled form C source); refactored C source.
120
+ *0.2.4* :: Bug fixes. (YANKED)
121
+ *0.2.5* :: Bug fixes. (See ChangeLog.rdoc)
119
122
 
120
123
  == TO DO:
121
124
 
@@ -124,6 +127,6 @@ On:
124
127
 
125
128
  == Copyright
126
129
 
127
- Copyright (c) 2012 Johanns Gregorian (https://github.com/johanns)
130
+ Copyright (c) 2012 - 2013 Johanns Gregorian (https://github.com/johanns)
128
131
 
129
132
  See LICENSE.txt for details.
@@ -1,3 +1,5 @@
1
+ /* Copyright (c) 2012 - 2013 Johanns Gregorian <io+sha3@jsani.com> */
2
+
1
3
  #include "sha3.h"
2
4
 
3
5
  VALUE cDigest;
@@ -109,8 +111,25 @@ static VALUE c_digest_reset(VALUE self)
109
111
  return self;
110
112
  }
111
113
 
114
+ // Fix: And, permanent reminder of a rookie mistake in c_digest_copy, comparing structs with ==/!= op
115
+ // Fix: Woke-up after 2-hours of sleep, and for good reason. Fixed string comparison. Need to re-read K&R!
116
+ static int cmp_states(MDX *mdx1, MDX *mdx2)
117
+ {
118
+ return (
119
+ (mdx1->hashbitlen == mdx2->hashbitlen) &&
120
+ (strcmp((const char *) mdx1->state->state, (const char *)mdx2->state->state) == 0) &&
121
+ (strcmp((const char *) mdx1->state->dataQueue, (const char *) mdx2->state->dataQueue) == 0) &&
122
+ (mdx1->state->rate == mdx2->state->rate) &&
123
+ (mdx1->state->capacity == mdx2->state->capacity) &&
124
+ (mdx1->state->bitsInQueue == mdx2->state->bitsInQueue) &&
125
+ (mdx1->state->fixedOutputLength == mdx2->state->fixedOutputLength) &&
126
+ (mdx1->state->squeezing == mdx2->state->squeezing) &&
127
+ (mdx1->state->bitsAvailableForSqueezing == mdx2->state->bitsAvailableForSqueezing)
128
+ );
129
+ }
130
+
112
131
  // SHA3::Digest.copy(obj) -> self
113
- static VALUE c_digest_copy(VALUE self, VALUE obj)
132
+ static VALUE c_digest_copy(VALUE self, VALUE obj)
114
133
  {
115
134
  MDX *mdx1, *mdx2;
116
135
 
@@ -123,18 +142,18 @@ static VALUE c_digest_copy(VALUE self, VALUE obj)
123
142
 
124
143
  memcpy(mdx1->state, mdx2->state, sizeof(hashState));
125
144
  mdx1->hashbitlen = mdx2->hashbitlen;
126
-
145
+
127
146
  // Fetch the data again to make sure it was copied
128
147
  GETMDX(self, mdx1);
129
148
  SAFEGETMDX(obj, mdx2);
130
- if ((mdx1->state != mdx2->state) && (mdx1->hashbitlen != mdx2->hashbitlen))
149
+ if (!cmp_states(mdx1, mdx2))
131
150
  rb_raise(eDigestError, "failed to copy state");
132
151
 
133
152
  return self;
134
153
  }
135
154
 
136
155
  // SHA3::Digest.digest_length -> Integer
137
- static VALUE c_digest_length(VALUE self)
156
+ static VALUE c_digest_length(VALUE self)
138
157
  {
139
158
  MDX *mdx;
140
159
  GETMDX(self, mdx);
@@ -1,6 +1,12 @@
1
+ /* Copyright (c) 2012 - 2013 Johanns Gregorian <io+sha3@jsani.com> */
2
+
1
3
  #ifndef _DIGEST_H_
2
4
  #define _DIGEST_H_
3
5
 
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
4
10
  // From ruby/ext/openssl/ossl_digest.c
5
11
  #define GETMDX(obj, mdx) do { \
6
12
  Data_Get_Struct((obj), MDX, (mdx)); \
@@ -27,4 +33,8 @@ typedef struct {
27
33
 
28
34
  void Init_sha3_n_digest(void);
29
35
 
36
+ #ifdef __cplusplus
37
+ }
38
+ #endif
39
+
30
40
  #endif
@@ -1,14 +1,26 @@
1
1
  require 'mkmf'
2
+ require 'rbconfig'
2
3
 
3
- case 1.size
4
- when 4 # 32bit optimized code
4
+ FileUtils.rm "#{$srcdir}/KeccakF-1600-opt.c", :force => true
5
+
6
+ target_cpu = RbConfig::CONFIG['target_cpu']
7
+
8
+ if 1.size == 4 and target_cpu =~ /i386|x86_32/ # x86 32bit optimized code
9
+ Logging::message "=== Using i386 optimized Keccak code ===\n"
5
10
  FileUtils.cp "#{$srcdir}/KeccakF-1600-opt32.c-arch", "#{$srcdir}/KeccakF-1600-opt.c"
6
- when 8 # 64bit optimized code
11
+ elsif 1.size == 8 and target_cpu =~ /i686|x86_64/
12
+ Logging::message "=== Using i686 optimized Keccak code ===\n"
7
13
  FileUtils.cp "#{$srcdir}/KeccakF-1600-opt64.c-arch", "#{$srcdir}/KeccakF-1600-opt.c"
8
- else # Ha? Use reference code
14
+ else # Ha? Use reference code -- slow
15
+ Logging::message "=== Using reference Keccak code ===\n"
9
16
  FileUtils.cp "#{$srcdir}/KeccakF-1600-reference.c-arch", "#{$srcdir}/KeccakF-1600-opt.c"
10
17
  end
11
18
 
19
+ find_header("KeccakF-1600-interface.h")
20
+ find_header("KeccakSponge.h")
21
+ find_header("KeccakNISTInterface.h")
22
+ find_header("sha3.h")
23
+ find_header("digest.h")
24
+
12
25
  $CFLAGS = ' -fomit-frame-pointer -O3 -g0 -march=nocona '
13
26
  create_makefile 'sha3_n'
14
-
@@ -1,3 +1,5 @@
1
+ /* Copyright (c) 2012 - 2013 Johanns Gregorian <io+sha3@jsani.com> */
2
+
1
3
  #include "sha3.h"
2
4
 
3
5
  VALUE mSHA3;
@@ -1,3 +1,5 @@
1
+ /* Copyright (c) 2012 - 2013 Johanns Gregorian <io+sha3@jsani.com> */
2
+
1
3
  #ifndef _SHA3_H_
2
4
  #define _SHA3_H_
3
5
 
@@ -6,10 +8,18 @@
6
8
  #include "KeccakNISTInterface.h"
7
9
  #include "digest.h"
8
10
 
11
+ #ifdef __cplusplus
12
+ extern "C" {
13
+ #endif
14
+
9
15
  extern VALUE mSHA3;
10
16
  extern VALUE eSHA3Error;
11
17
 
12
18
  int get_hlen(VALUE);
13
19
  void Init_sha3_n(void);
14
20
 
21
+ #ifdef __cplusplus
22
+ }
23
+ #endif
24
+
15
25
  #endif
@@ -1,8 +1,8 @@
1
1
  module SHA3
2
2
  extend self
3
-
3
+
4
4
  # sha3 release version
5
- VERSION = "0.2.3"
5
+ VERSION = "0.2.5"
6
6
 
7
7
  # keccak version number
8
8
  KECCAK_VERSION = "3.2"
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.name = "sha3"
7
7
  gem.version = SHA3::VERSION
8
8
  gem.summary = %q{SHA3 for Ruby}
9
- gem.description = %q{SHA3 for Ruby is a native (C) implementation of Keccak (SHA3) cryptographic hashing algorithm. See https://github.com/johanns/sha3#readme for details.}
9
+ gem.description = %q{SHA3 for Ruby is a native (C) implementation of Keccak (SHA3) cryptographic hashing algorithm.}
10
10
  gem.license = "MIT"
11
11
  gem.authors = ["Johanns Gregorian"]
12
12
  gem.email = "io+sha3@jsani.com"
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sha3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
- prerelease:
4
+ version: 0.2.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Johanns Gregorian
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-28 00:00:00.000000000 Z
11
+ date: 2013-05-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake-compiler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rubygems-tasks
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: yard
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,13 +62,12 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0.8'
78
69
  description: SHA3 for Ruby is a native (C) implementation of Keccak (SHA3) cryptographic
79
- hashing algorithm. See https://github.com/johanns/sha3#readme for details.
70
+ hashing algorithm.
80
71
  email: io+sha3@jsani.com
81
72
  executables: []
82
73
  extensions:
@@ -133,27 +124,26 @@ files:
133
124
  homepage: https://github.com/johanns/sha3#readme
134
125
  licenses:
135
126
  - MIT
127
+ metadata: {}
136
128
  post_install_message:
137
129
  rdoc_options: []
138
130
  require_paths:
139
131
  - lib
140
132
  required_ruby_version: !ruby/object:Gem::Requirement
141
- none: false
142
133
  requirements:
143
- - - ! '>='
134
+ - - '>='
144
135
  - !ruby/object:Gem::Version
145
136
  version: '0'
146
137
  required_rubygems_version: !ruby/object:Gem::Requirement
147
- none: false
148
138
  requirements:
149
- - - ! '>='
139
+ - - '>='
150
140
  - !ruby/object:Gem::Version
151
141
  version: '0'
152
142
  requirements: []
153
143
  rubyforge_project:
154
- rubygems_version: 1.8.23
144
+ rubygems_version: 2.0.2
155
145
  signing_key:
156
- specification_version: 3
146
+ specification_version: 4
157
147
  summary: SHA3 for Ruby
158
148
  test_files:
159
149
  - spec/generate_tests.rb