digest-sha3 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 12bda300d0395d0e05c8e6cebf8820790451f238
4
+ data.tar.gz: 0938f5e9d49f152d2cd905a0bd80a3b9cce92203
5
+ SHA512:
6
+ metadata.gz: 9fad069c73d041038890a3fa59ac220f8970f392cb9e5fe93db9ad39908ecc9a73b90de7883ff1df56635e95f27451d5c2fadc9f96ed97ef22e0898be7ba66ec
7
+ data.tar.gz: d09ea65383a9c91858c5427fb425fa3ee34200d9698dc7c8baa4ddb6f567a66d6400bea41cc0d84e334e129e8f49c1610ee63cc4bb947e3a7e2a709e66da31ef
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Phusion
1
+ Copyright (c) 2012-2015 Phusion B.V.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
data/README.md CHANGED
@@ -8,9 +8,7 @@ This Ruby extension implements the SHA-3 ([Keccak](http://keccak.noekeon.org/))
8
8
 
9
9
  gem install digest-sha3
10
10
 
11
- Our gem is signed using PGP with the [Phusion Software Signing key](http://www.phusion.nl/about/gpg). That key in turn is signed by [the rubygems-openpgp Certificate Authority](http://www.rubygems-openpgp-ca.org/).
12
-
13
- You can verify the authenticity of the gem by following [The Complete Guide to Verifying Gems with rubygems-openpgp](http://www.rubygems-openpgp-ca.org/blog/the-complete-guide-to-verifying-gems-with-rubygems-openpgp.html).
11
+ **Note**: as of version 1.1.0, digest-sha3 requires Ruby 2.2. The last version that worked on older versions was 1.0.2.
14
12
 
15
13
  ## Usage
16
14
 
@@ -9,6 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.description = "The SHA-3 (Keccak) hash."
10
10
  s.authors = ["Hongli Lai (Phusion)", "Keccak authors"]
11
11
  s.extensions << "ext/digest/extconf.rb"
12
+ s.required_ruby_version = "~> 2.2"
13
+ s.license = "MIT"
12
14
 
13
15
  s.files = Dir[
14
16
  "README.md",
@@ -9,19 +9,69 @@
9
9
  #define MAX_DIGEST_SIZE 64
10
10
  #define DEFAULT_DIGEST_LEN 512
11
11
 
12
- static void sha3_init_func(hashState *ctx);
12
+ static int sha3_init_func(hashState *ctx);
13
13
  static void sha3_update_func(hashState *ctx, unsigned char *str, size_t len);
14
+ static int sha3_finish_func(hashState *ctx, unsigned char *digest);
14
15
 
16
+ /*
17
+ Metadata definition for the SHA3 algorithm.
18
+ Defines the Version, sizes for block and digest as well as
19
+ the entry points for the algorithms
20
+ */
15
21
  static rb_digest_metadata_t sha3 = {
16
22
  RUBY_DIGEST_API_VERSION,
17
23
  DEFAULT_DIGEST_LEN,
18
- KeccakPermutationSize - (2 * DEFAULT_DIGEST_LEN),
19
- sizeof(hashState),
24
+ KeccakPermutationSize - (2 * DEFAULT_DIGEST_LEN), //size of blocks
25
+ sizeof(hashState), //size of context for the object we'll be passed in below functions.
20
26
  (rb_digest_hash_init_func_t)sha3_init_func,
21
27
  (rb_digest_hash_update_func_t)sha3_update_func,
22
- NULL,
28
+ (rb_digest_hash_finish_func_t)sha3_finish_func,
23
29
  };
24
30
 
31
+ /* Initialization function for the algorithm,
32
+ gets called during allocation of the digest object.
33
+ we override initialize to do custom hash size, so we don't care too much here.
34
+ */
35
+ static int
36
+ sha3_init_func(hashState *ctx) {
37
+ // Just return a 1 ' successful' we override the init function
38
+ // so this is not necessary
39
+ // the base class alloc calls this to initialize the algorithm
40
+ return 1;
41
+ }
42
+
43
+ /* Update function, take the current context and add str to it */
44
+ static void
45
+ sha3_update_func(hashState *ctx, unsigned char *str, size_t len) {
46
+ Update(ctx, str, len * 8);
47
+ }
48
+
49
+ /* Finish the hash calculation and return the finished string */
50
+ static int
51
+ sha3_finish_func(hashState *ctx, unsigned char *digest) {
52
+ Final(ctx, digest);
53
+ return 1;
54
+ }
55
+
56
+ /* Ruby method. Digest::SHA3#finish()
57
+ * No Arguments
58
+ * @returns [String] Encoded Digest String
59
+ */
60
+ static VALUE
61
+ rb_sha3_finish(VALUE self) {
62
+ hashState *ctx;
63
+ VALUE digest;
64
+
65
+ ctx = (hashState *)RTYPEDDATA_DATA(self);
66
+ digest = rb_str_new(0, ctx->capacity / 2 / 8);
67
+ sha3_finish_func(ctx, (unsigned char *)RSTRING_PTR(digest));
68
+
69
+ return digest;
70
+ }
71
+
72
+ /* :nodoc: private method
73
+ * initialize the ctx with the bitlength
74
+ */
25
75
  static void
26
76
  sha3_init(hashState *ctx, size_t bitlen) {
27
77
  switch (Init(ctx, bitlen)) {
@@ -36,25 +86,10 @@ sha3_init(hashState *ctx, size_t bitlen) {
36
86
  }
37
87
  }
38
88
 
39
- static void
40
- sha3_init_func(hashState *ctx) {
41
- Init(ctx, ctx->capacity / 2);
42
- }
43
-
44
- static void
45
- sha3_update_func(hashState *ctx, unsigned char *str, size_t len) {
46
- Update(ctx, str, len * 8);
47
- }
48
-
49
- static VALUE
50
- rb_sha3_alloc(VALUE klass) {
51
- hashState *ctx;
52
-
53
- ctx = (hashState *) xmalloc(sizeof(hashState));
54
- sha3_init(ctx, DEFAULT_DIGEST_LEN);
55
- return Data_Wrap_Struct(klass, 0, xfree, ctx);
56
- }
57
-
89
+ /* Ruby method. Digest::SHA3.new(hashlen)
90
+ * @param hashlen The length of hash, only supports 224, 256, 384 or 512
91
+ * @returns [Digest::SHA3] new object.
92
+ */
58
93
  static VALUE
59
94
  rb_sha3_initialize(int argc, VALUE *argv, VALUE self) {
60
95
  hashState *ctx;
@@ -66,46 +101,35 @@ rb_sha3_initialize(int argc, VALUE *argv, VALUE self) {
66
101
  } else {
67
102
  i_hashlen = NUM2INT(hashlen);
68
103
  }
69
- switch (i_hashlen) {
70
- case 0:
104
+ if ( i_hashlen == 0) {
71
105
  rb_raise(rb_eArgError, "Unsupported hash length");
72
- case DEFAULT_DIGEST_LEN:
73
- break;
74
- default:
75
- Data_Get_Struct(self, hashState, ctx);
76
- sha3_init(ctx, i_hashlen);
77
- }
78
-
79
- return self;
80
- }
81
-
82
- static VALUE
83
- rb_sha3_finish(VALUE self) {
84
- hashState *ctx;
85
- VALUE digest;
86
-
87
- Data_Get_Struct(self, hashState, ctx);
88
-
89
- digest = rb_str_new(0, ctx->capacity / 2 / 8);
106
+ }
90
107
 
91
- Final(ctx, (unsigned char *)RSTRING_PTR(digest));
108
+ ctx = (hashState *)RTYPEDDATA_DATA(self);
109
+ sha3_init(ctx, i_hashlen);
92
110
 
93
- return digest;
111
+ return rb_call_super(0, NULL);
94
112
  }
95
113
 
114
+ /* Ruby method. Digest::SHA3#digest_length
115
+ * @returns [Numeric] Length of the digest.
116
+ */
96
117
  static VALUE
97
118
  rb_sha3_digest_length(VALUE self) {
98
119
  hashState *ctx;
99
120
 
100
- Data_Get_Struct(self, hashState, ctx);
121
+ ctx = (hashState *)RTYPEDDATA_DATA(self);
101
122
  return INT2FIX(ctx->capacity / 2 / 8);
102
123
  }
103
124
 
125
+ /* Ruby method. Digest::SHA3#block_length
126
+ * @returns [Numeric] Length of blocks in this digest.
127
+ */
104
128
  static VALUE
105
129
  rb_sha3_block_length(VALUE self) {
106
130
  hashState *ctx;
107
131
 
108
- Data_Get_Struct(self, hashState, ctx);
132
+ ctx = (hashState *)RTYPEDDATA_DATA(self);
109
133
  return INT2FIX(ctx->rate / 8);
110
134
  }
111
135
 
@@ -120,11 +144,10 @@ Init_sha3() {
120
144
 
121
145
  cSHA3 = rb_define_class_under(mDigest, "SHA3", cDigest_Base);
122
146
 
123
- rb_ivar_set(cSHA3, rb_intern("metadata"), Data_Wrap_Struct(rb_cObject, 0, 0, &sha3));
147
+ rb_iv_set(cSHA3, "metadata", Data_Wrap_Struct(0, 0, 0, (void *)&sha3));
124
148
 
125
- rb_define_alloc_func(cSHA3, rb_sha3_alloc);
126
- rb_define_method(cSHA3, "initialize", rb_sha3_initialize, -1);
127
- rb_define_private_method(cSHA3, "finish", rb_sha3_finish, 0);
128
- rb_define_method(cSHA3, "digest_length", rb_sha3_digest_length, 0);
129
- rb_define_method(cSHA3, "block_length", rb_sha3_block_length, 0);
149
+ rb_define_method(cSHA3, "initialize", rb_sha3_initialize, -1);
150
+ rb_define_method(cSHA3, "digest_length", rb_sha3_digest_length, 0);
151
+ rb_define_method(cSHA3, "block_length", rb_sha3_block_length, 0);
152
+ rb_define_method(cSHA3, "finish", rb_sha3_finish, 0);
130
153
  }
@@ -1,7 +1,7 @@
1
1
  module Digest
2
2
  class SHA3
3
3
  module Version
4
- STRING = "1.0.2"
4
+ STRING = "1.1.0"
5
5
  end
6
6
  end
7
- end
7
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digest-sha3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Hongli Lai (Phusion)
@@ -10,7 +9,7 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-05-23 00:00:00.000000000 Z
12
+ date: 2015-06-24 00:00:00.000000000 Z
14
13
  dependencies: []
15
14
  description: The SHA-3 (Keccak) hash.
16
15
  email: software-signing@phusion.nl
@@ -19,45 +18,45 @@ extensions:
19
18
  - ext/digest/extconf.rb
20
19
  extra_rdoc_files: []
21
20
  files:
22
- - README.md
23
21
  - LICENSE
24
22
  - Makefile
23
+ - README.md
25
24
  - digest-sha3.gemspec
26
- - ext/digest/displayIntermediateValues.c
25
+ - ext/digest/KeccakF-1600-int-set.h
26
+ - ext/digest/KeccakF-1600-interface.h
27
27
  - ext/digest/KeccakF-1600-reference.c
28
28
  - ext/digest/KeccakNISTInterface.c
29
+ - ext/digest/KeccakNISTInterface.h
29
30
  - ext/digest/KeccakSponge.c
30
- - ext/digest/sha3.c
31
+ - ext/digest/KeccakSponge.h
31
32
  - ext/digest/brg_endian.h
33
+ - ext/digest/displayIntermediateValues.c
32
34
  - ext/digest/displayIntermediateValues.h
33
- - ext/digest/KeccakF-1600-int-set.h
34
- - ext/digest/KeccakF-1600-interface.h
35
- - ext/digest/KeccakNISTInterface.h
36
- - ext/digest/KeccakSponge.h
37
35
  - ext/digest/extconf.rb
36
+ - ext/digest/sha3.c
38
37
  - lib/digest/sha3/version.rb
39
38
  homepage: https://github.com/phusion/digest-sha3-ruby
40
- licenses: []
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
41
42
  post_install_message:
42
43
  rdoc_options: []
43
44
  require_paths:
44
45
  - lib
45
46
  required_ruby_version: !ruby/object:Gem::Requirement
46
- none: false
47
47
  requirements:
48
- - - ! '>='
48
+ - - "~>"
49
49
  - !ruby/object:Gem::Version
50
- version: '0'
50
+ version: '2.2'
51
51
  required_rubygems_version: !ruby/object:Gem::Requirement
52
- none: false
53
52
  requirements:
54
- - - ! '>='
53
+ - - ">="
55
54
  - !ruby/object:Gem::Version
56
55
  version: '0'
57
56
  requirements: []
58
57
  rubyforge_project:
59
- rubygems_version: 1.8.25
58
+ rubygems_version: 2.4.8
60
59
  signing_key:
61
- specification_version: 3
60
+ specification_version: 4
62
61
  summary: The SHA-3 (Keccak) hash
63
62
  test_files: []
data.tar.gz.asc DELETED
@@ -1,12 +0,0 @@
1
- -----BEGIN PGP SIGNATURE-----
2
- Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
3
- Comment: GPGTools - http://gpgtools.org
4
-
5
- iQEcBAABAgAGBQJRnfcdAAoJECrHRaUKISqMiYIH/AoNOUG3VBjW9BJWSkRjJr7H
6
- QyweWpKE+H7AEAzIyZnMH4qICKBfNfRgMVL6H07Ie+xX8Tm2YBOoHWYXvn2So5bL
7
- SULpEktHsbc0QSEEWnMUb9oA91qM3e514oJ+xhGQokvVZoFeG6q/WSunuY3TE7Y/
8
- nxe5PiYCkwCCWdPRtMhgOKgPjK9RDmINml58NI46CL4wscbduXzrv0U91CjVkzsj
9
- WkCiXCoYQ0hb7vzofbtMppFEhBtO9XlfUoAfl6u7OQOyh553swIP4xoVTKEQ9DMz
10
- RL6MAzaMtmzCgijT7JYGza/Cmezg0dRzrwWtLPpX43RIk4jWdFCBcwNSHHB5CXA=
11
- =zd36
12
- -----END PGP SIGNATURE-----
metadata.gz.asc DELETED
@@ -1,12 +0,0 @@
1
- -----BEGIN PGP SIGNATURE-----
2
- Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
3
- Comment: GPGTools - http://gpgtools.org
4
-
5
- iQEcBAABAgAGBQJRnfcdAAoJECrHRaUKISqM52QH/2XN6fviuj7l8v5IMTgp6taA
6
- oFdoPqVRcyJA+lU7gPK6goHJLPF62f/M0GBaRmpmnjVi0af5nUjB4kCgZC4aOe6t
7
- N6eCV7We7nT+bSGZN33keaIceGa/V/b7xeK3o9tNbCxv01iMvigmCi86SXjpydvT
8
- j9hFedYxGmwpkxAiNeoK7fqyChx3AUbNTcHAh9p+uA0liTvXaH8a7Ot+3R4itCdQ
9
- fKA73NvVGSoIfD9Vs36obCAZeIQp1E9IIHsEODa+ogBRUNcJbclaNZF9XxUEukq9
10
- gN9i1Anlf9Y3I9MO2NbZUi58PJg8VFl/bG98OHSbim5e8XYWz3Bfkcvojxtbldc=
11
- =LIg6
12
- -----END PGP SIGNATURE-----