digest-sha3 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.asc +7 -3
- data/Makefile +1 -1
- data/ext/digest/extconf.rb +4 -0
- data/ext/digest/sha3.c +85 -92
- data/lib/digest/sha3/version.rb +1 -1
- metadata +2 -3
- metadata.gz.asc +7 -3
- data/lib/digest/sha3/helpers.rb +0 -20
data.tar.gz.asc
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
|
3
3
|
Comment: GPGTools - http://gpgtools.org
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
iQEcBAABAgAGBQJRnfcdAAoJECrHRaUKISqMiYIH/AoNOUG3VBjW9BJWSkRjJr7H
|
6
|
+
QyweWpKE+H7AEAzIyZnMH4qICKBfNfRgMVL6H07Ie+xX8Tm2YBOoHWYXvn2So5bL
|
7
|
+
SULpEktHsbc0QSEEWnMUb9oA91qM3e514oJ+xhGQokvVZoFeG6q/WSunuY3TE7Y/
|
8
|
+
nxe5PiYCkwCCWdPRtMhgOKgPjK9RDmINml58NI46CL4wscbduXzrv0U91CjVkzsj
|
9
|
+
WkCiXCoYQ0hb7vzofbtMppFEhBtO9XlfUoAfl6u7OQOyh553swIP4xoVTKEQ9DMz
|
10
|
+
RL6MAzaMtmzCgijT7JYGza/Cmezg0dRzrwWtLPpX43RIk4jWdFCBcwNSHHB5CXA=
|
11
|
+
=zd36
|
8
12
|
-----END PGP SIGNATURE-----
|
data/Makefile
CHANGED
@@ -7,7 +7,7 @@ ext/digest/Makefile: ext/digest/extconf.rb
|
|
7
7
|
cd ext/digest && ruby extconf.rb
|
8
8
|
|
9
9
|
clean:
|
10
|
-
if [
|
10
|
+
if [ -f ext/digest/Makefile ]; then make -C ext/digest clean; fi
|
11
11
|
rm -f ext/digest/Makefile
|
12
12
|
rm -f test/test_vectors.rb
|
13
13
|
|
data/ext/digest/extconf.rb
CHANGED
data/ext/digest/sha3.c
CHANGED
@@ -1,137 +1,130 @@
|
|
1
1
|
#include "ruby.h"
|
2
|
+
#ifdef HAVE_RUBY_DIGEST_H
|
3
|
+
#include "ruby/digest.h"
|
4
|
+
#else
|
5
|
+
#include "digest.h"
|
6
|
+
#endif
|
2
7
|
#include "KeccakNISTInterface.h"
|
3
8
|
|
4
9
|
#define MAX_DIGEST_SIZE 64
|
10
|
+
#define DEFAULT_DIGEST_LEN 512
|
11
|
+
|
12
|
+
static void sha3_init_func(hashState *ctx);
|
13
|
+
static void sha3_update_func(hashState *ctx, unsigned char *str, size_t len);
|
14
|
+
|
15
|
+
static rb_digest_metadata_t sha3 = {
|
16
|
+
RUBY_DIGEST_API_VERSION,
|
17
|
+
DEFAULT_DIGEST_LEN,
|
18
|
+
KeccakPermutationSize - (2 * DEFAULT_DIGEST_LEN),
|
19
|
+
sizeof(hashState),
|
20
|
+
(rb_digest_hash_init_func_t)sha3_init_func,
|
21
|
+
(rb_digest_hash_update_func_t)sha3_update_func,
|
22
|
+
NULL,
|
23
|
+
};
|
24
|
+
|
25
|
+
static void
|
26
|
+
sha3_init(hashState *ctx, size_t bitlen) {
|
27
|
+
switch (Init(ctx, bitlen)) {
|
28
|
+
case SUCCESS:
|
29
|
+
return;
|
30
|
+
case FAIL:
|
31
|
+
rb_raise(rb_eRuntimeError, "Unknown error");
|
32
|
+
case BAD_HASHLEN:
|
33
|
+
rb_raise(rb_eArgError, "Bad hash length (must be 0, 224, 256, 384 or 512)");
|
34
|
+
default:
|
35
|
+
rb_raise(rb_eRuntimeError, "Unknown error code");
|
36
|
+
}
|
37
|
+
}
|
5
38
|
|
6
|
-
static
|
39
|
+
static void
|
40
|
+
sha3_init_func(hashState *ctx) {
|
41
|
+
Init(ctx, ctx->capacity / 2);
|
42
|
+
}
|
7
43
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
44
|
+
static void
|
45
|
+
sha3_update_func(hashState *ctx, unsigned char *str, size_t len) {
|
46
|
+
Update(ctx, str, len * 8);
|
47
|
+
}
|
12
48
|
|
13
49
|
static VALUE
|
14
50
|
rb_sha3_alloc(VALUE klass) {
|
15
|
-
|
16
|
-
|
17
|
-
ctx = (
|
18
|
-
ctx
|
51
|
+
hashState *ctx;
|
52
|
+
|
53
|
+
ctx = (hashState *) xmalloc(sizeof(hashState));
|
54
|
+
sha3_init(ctx, DEFAULT_DIGEST_LEN);
|
19
55
|
return Data_Wrap_Struct(klass, 0, xfree, ctx);
|
20
56
|
}
|
21
57
|
|
22
58
|
static VALUE
|
23
59
|
rb_sha3_initialize(int argc, VALUE *argv, VALUE self) {
|
24
|
-
|
60
|
+
hashState *ctx;
|
25
61
|
VALUE hashlen;
|
26
62
|
int i_hashlen;
|
27
63
|
|
28
64
|
if (rb_scan_args(argc, argv, "01", &hashlen) == 0) {
|
29
|
-
i_hashlen =
|
65
|
+
i_hashlen = DEFAULT_DIGEST_LEN;
|
30
66
|
} else {
|
31
67
|
i_hashlen = NUM2INT(hashlen);
|
32
68
|
}
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
ctx->bitlen = i_hashlen;
|
39
|
-
|
40
|
-
switch (Init(&ctx->state, i_hashlen)) {
|
41
|
-
case SUCCESS:
|
42
|
-
return self;
|
43
|
-
case FAIL:
|
44
|
-
rb_raise(rb_eRuntimeError, "Unknown error");
|
45
|
-
return Qnil;
|
46
|
-
case BAD_HASHLEN:
|
47
|
-
rb_raise(rb_eRuntimeError, "Bad hash length (must be 0, 224, 256, 384 or 512)");
|
48
|
-
return Qnil;
|
69
|
+
switch (i_hashlen) {
|
70
|
+
case 0:
|
71
|
+
rb_raise(rb_eArgError, "Unsupported hash length");
|
72
|
+
case DEFAULT_DIGEST_LEN:
|
73
|
+
break;
|
49
74
|
default:
|
50
|
-
|
51
|
-
|
75
|
+
Data_Get_Struct(self, hashState, ctx);
|
76
|
+
sha3_init(ctx, i_hashlen);
|
52
77
|
}
|
53
|
-
}
|
54
78
|
|
55
|
-
static VALUE
|
56
|
-
rb_sha3_initialize_copy(VALUE self, VALUE other) {
|
57
|
-
RbSHA3 *ctx_self, *ctx_other;
|
58
|
-
|
59
|
-
rb_check_frozen(self);
|
60
|
-
Data_Get_Struct(self, RbSHA3, ctx_self);
|
61
|
-
Data_Get_Struct(other, RbSHA3, ctx_other);
|
62
|
-
memcpy(&ctx_self->state, &ctx_other->state, sizeof(hashState));
|
63
|
-
ctx_self->bitlen = ctx_other->bitlen;
|
64
79
|
return self;
|
65
80
|
}
|
66
81
|
|
67
82
|
static VALUE
|
68
|
-
|
69
|
-
|
83
|
+
rb_sha3_finish(VALUE self) {
|
84
|
+
hashState *ctx;
|
85
|
+
VALUE digest;
|
70
86
|
|
71
|
-
Data_Get_Struct(self,
|
72
|
-
Init(&ctx->state, ctx->bitlen);
|
73
|
-
return self;
|
74
|
-
}
|
87
|
+
Data_Get_Struct(self, hashState, ctx);
|
75
88
|
|
76
|
-
|
77
|
-
rb_sha3_update(VALUE self, VALUE str) {
|
78
|
-
RbSHA3 *ctx;
|
89
|
+
digest = rb_str_new(0, ctx->capacity / 2 / 8);
|
79
90
|
|
80
|
-
|
81
|
-
|
82
|
-
return
|
91
|
+
Final(ctx, (unsigned char *)RSTRING_PTR(digest));
|
92
|
+
|
93
|
+
return digest;
|
83
94
|
}
|
84
95
|
|
85
96
|
static VALUE
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
Data_Get_Struct(self, RbSHA3, ctx);
|
92
|
-
memcpy(&state, &ctx->state, sizeof(hashState));
|
93
|
-
Final(&state, digest);
|
94
|
-
return rb_str_new((const char *) digest, ctx->bitlen / 8);
|
97
|
+
rb_sha3_digest_length(VALUE self) {
|
98
|
+
hashState *ctx;
|
99
|
+
|
100
|
+
Data_Get_Struct(self, hashState, ctx);
|
101
|
+
return INT2FIX(ctx->capacity / 2 / 8);
|
95
102
|
}
|
96
103
|
|
97
104
|
static VALUE
|
98
|
-
|
99
|
-
|
100
|
-
int i_hashlen;
|
101
|
-
unsigned char digest[MAX_DIGEST_SIZE];
|
105
|
+
rb_sha3_block_length(VALUE self) {
|
106
|
+
hashState *ctx;
|
102
107
|
|
103
|
-
|
104
|
-
|
105
|
-
} else {
|
106
|
-
i_hashlen = NUM2INT(hashlen);
|
107
|
-
}
|
108
|
-
|
109
|
-
switch (Hash(i_hashlen, RSTRING_PTR(data), RSTRING_LEN(data) * 8, digest)) {
|
110
|
-
case SUCCESS:
|
111
|
-
return rb_str_new(digest, i_hashlen / 8);
|
112
|
-
case FAIL:
|
113
|
-
rb_raise(rb_eRuntimeError, "Unknown error");
|
114
|
-
return Qnil;
|
115
|
-
case BAD_HASHLEN:
|
116
|
-
rb_raise(rb_eRuntimeError, "Bad hash length (must be 0, 224, 256, 384 or 512)");
|
117
|
-
return Qnil;
|
118
|
-
default:
|
119
|
-
rb_raise(rb_eRuntimeError, "Unknown error code");
|
120
|
-
return Qnil;
|
121
|
-
}
|
108
|
+
Data_Get_Struct(self, hashState, ctx);
|
109
|
+
return INT2FIX(ctx->rate / 8);
|
122
110
|
}
|
123
111
|
|
124
112
|
void __attribute__((visibility("default")))
|
125
113
|
Init_sha3() {
|
126
|
-
mDigest
|
127
|
-
|
114
|
+
VALUE mDigest, cDigest_Base, cSHA3;
|
115
|
+
|
116
|
+
rb_require("digest");
|
117
|
+
|
118
|
+
mDigest = rb_path2class("Digest");
|
119
|
+
cDigest_Base = rb_path2class("Digest::Base");
|
120
|
+
|
121
|
+
cSHA3 = rb_define_class_under(mDigest, "SHA3", cDigest_Base);
|
122
|
+
|
123
|
+
rb_ivar_set(cSHA3, rb_intern("metadata"), Data_Wrap_Struct(rb_cObject, 0, 0, &sha3));
|
124
|
+
|
128
125
|
rb_define_alloc_func(cSHA3, rb_sha3_alloc);
|
129
126
|
rb_define_method(cSHA3, "initialize", rb_sha3_initialize, -1);
|
130
|
-
|
131
|
-
rb_define_method(cSHA3, "
|
132
|
-
rb_define_method(cSHA3, "
|
133
|
-
rb_define_method(cSHA3, "<<", rb_sha3_update, 1);
|
134
|
-
rb_define_method(cSHA3, "digest", rb_sha3_digest, 0);
|
135
|
-
rb_define_singleton_method(cSHA3, "digest", rb_sha3_singleton_digest, -1);
|
136
|
-
rb_require("digest/sha3/helpers");
|
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);
|
137
130
|
}
|
data/lib/digest/sha3/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: digest-sha3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: The SHA-3 (Keccak) hash.
|
16
16
|
email: software-signing@phusion.nl
|
@@ -35,7 +35,6 @@ files:
|
|
35
35
|
- ext/digest/KeccakNISTInterface.h
|
36
36
|
- ext/digest/KeccakSponge.h
|
37
37
|
- ext/digest/extconf.rb
|
38
|
-
- lib/digest/sha3/helpers.rb
|
39
38
|
- lib/digest/sha3/version.rb
|
40
39
|
homepage: https://github.com/phusion/digest-sha3-ruby
|
41
40
|
licenses: []
|
metadata.gz.asc
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
|
3
3
|
Comment: GPGTools - http://gpgtools.org
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
iQEcBAABAgAGBQJRnfcdAAoJECrHRaUKISqM52QH/2XN6fviuj7l8v5IMTgp6taA
|
6
|
+
oFdoPqVRcyJA+lU7gPK6goHJLPF62f/M0GBaRmpmnjVi0af5nUjB4kCgZC4aOe6t
|
7
|
+
N6eCV7We7nT+bSGZN33keaIceGa/V/b7xeK3o9tNbCxv01iMvigmCi86SXjpydvT
|
8
|
+
j9hFedYxGmwpkxAiNeoK7fqyChx3AUbNTcHAh9p+uA0liTvXaH8a7Ot+3R4itCdQ
|
9
|
+
fKA73NvVGSoIfD9Vs36obCAZeIQp1E9IIHsEODa+ogBRUNcJbclaNZF9XxUEukq9
|
10
|
+
gN9i1Anlf9Y3I9MO2NbZUi58PJg8VFl/bG98OHSbim5e8XYWz3Bfkcvojxtbldc=
|
11
|
+
=LIg6
|
8
12
|
-----END PGP SIGNATURE-----
|
data/lib/digest/sha3/helpers.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: ascii
|
2
|
-
Digest::SHA3.class_eval do
|
3
|
-
def self.hexdigest(*args)
|
4
|
-
force_ascii(digest(*args).unpack("H*").first)
|
5
|
-
end
|
6
|
-
|
7
|
-
def hexdigest
|
8
|
-
Digest::SHA3.force_ascii(digest.unpack("H*").first)
|
9
|
-
end
|
10
|
-
|
11
|
-
if ''.respond_to?(:force_encoding)
|
12
|
-
def self.force_ascii(str)
|
13
|
-
str.force_encoding('ascii')
|
14
|
-
end
|
15
|
-
else
|
16
|
-
def self.force_ascii(str)
|
17
|
-
str
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|