blake2 0.1.0
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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +2 -0
- data/.gitignore +4 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +674 -0
- data/README.md +45 -0
- data/Rakefile +18 -0
- data/blake2.gemspec +26 -0
- data/certs/franckverrot.pem +21 -0
- data/checksums/0.1.0.sha512 +1 -0
- data/ext/blake2_ext/blake2-impl.h +136 -0
- data/ext/blake2_ext/blake2.h +156 -0
- data/ext/blake2_ext/blake2s-ref.c +383 -0
- data/ext/blake2_ext/extconf.rb +3 -0
- data/ext/blake2_ext/rbext.c +92 -0
- data/lib/blake2.rb +2 -0
- data/lib/blake2/key.rb +23 -0
- data/test/blake2/key_test.rb +18 -0
- data/test/blake2_test.rb +25 -0
- data/test/test_helper.rb +11 -0
- metadata +147 -0
- metadata.gz.sig +1 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
#include <ruby/ruby.h>
|
2
|
+
#include <ruby/encoding.h>
|
3
|
+
#include "blake2.h"
|
4
|
+
|
5
|
+
typedef struct {
|
6
|
+
uint8_t key_length;
|
7
|
+
uint8_t *key;
|
8
|
+
|
9
|
+
uint8_t output_length;
|
10
|
+
uint8_t *output;
|
11
|
+
} Blake2;
|
12
|
+
|
13
|
+
void _hexdump(char * data, int len)
|
14
|
+
{
|
15
|
+
int i;
|
16
|
+
for (i = 0; i < len; i++) {
|
17
|
+
printf("%02X", (unsigned char)data[i]);
|
18
|
+
}
|
19
|
+
printf("\n");
|
20
|
+
}
|
21
|
+
|
22
|
+
static void blake2_free(Blake2 *blake2) {
|
23
|
+
rb_gc_mark(blake2->key);
|
24
|
+
}
|
25
|
+
|
26
|
+
static VALUE blake2_alloc(VALUE klass) {
|
27
|
+
return Data_Wrap_Struct(klass, NULL, blake2_free, ruby_xmalloc(sizeof(Blake2)));
|
28
|
+
}
|
29
|
+
|
30
|
+
VALUE m_blake2_initialize(VALUE self, VALUE _len, VALUE _key) {
|
31
|
+
Blake2 *blake2;
|
32
|
+
Data_Get_Struct(self, Blake2, blake2);
|
33
|
+
|
34
|
+
blake2->key = _key;
|
35
|
+
blake2->output_length = NUM2INT(_len);
|
36
|
+
blake2->output = (uint8_t*)ruby_xmalloc(blake2->output_length * sizeof(uint8_t));
|
37
|
+
|
38
|
+
return Qnil;
|
39
|
+
}
|
40
|
+
|
41
|
+
VALUE m_blake2_digest(VALUE self, VALUE _input, VALUE _representation) {
|
42
|
+
Blake2 *blake2;
|
43
|
+
|
44
|
+
VALUE to_hex = ID2SYM(rb_intern("to_hex"));
|
45
|
+
VALUE to_bytes = ID2SYM(rb_intern("to_bytes"));
|
46
|
+
|
47
|
+
char * input = RSTRING_PTR(_input);
|
48
|
+
int input_length = RSTRING_LEN(_input);
|
49
|
+
int i;
|
50
|
+
|
51
|
+
Data_Get_Struct(self, Blake2, blake2);
|
52
|
+
|
53
|
+
ID bytes_method = rb_intern("bytes");
|
54
|
+
VALUE bytes_ary = rb_funcall(blake2->key, bytes_method, 0);
|
55
|
+
int key_len = RARRAY_LEN(bytes_ary);
|
56
|
+
|
57
|
+
uint8_t * key_bytes = (uint8_t*)ruby_xmalloc(key_len * sizeof(uint8_t));
|
58
|
+
|
59
|
+
for(i = 0; i < key_len; i++) {
|
60
|
+
VALUE byte = rb_ary_entry(bytes_ary, i);
|
61
|
+
key_bytes[i] = NUM2INT(byte);
|
62
|
+
}
|
63
|
+
|
64
|
+
blake2s(blake2->output, input, key_bytes,
|
65
|
+
blake2->output_length, input_length, key_len);
|
66
|
+
|
67
|
+
if(_representation == to_bytes) {
|
68
|
+
VALUE result = rb_ary_new2(blake2->output_length);
|
69
|
+
|
70
|
+
for(i = 0; i < blake2->output_length; i++) {
|
71
|
+
rb_ary_push(result, INT2NUM(blake2->output[i]));
|
72
|
+
}
|
73
|
+
|
74
|
+
return result;
|
75
|
+
} else if(_representation == to_hex) {
|
76
|
+
char * c_str = (char*)ruby_xmalloc(blake2->output_length * sizeof(char) * 2);
|
77
|
+
|
78
|
+
for(i = 0; i < blake2->output_length; i++) {
|
79
|
+
sprintf(c_str + (i * 2), "%02x", blake2->output[i]);
|
80
|
+
}
|
81
|
+
return rb_str_new2(c_str);
|
82
|
+
} else {
|
83
|
+
rb_raise(rb_eArgError, "Unknown representation", _representation);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
void Init_blake2_ext() {
|
87
|
+
VALUE blake2 = rb_define_class("Blake2", rb_cObject);
|
88
|
+
rb_define_alloc_func(blake2, blake2_alloc);
|
89
|
+
|
90
|
+
rb_define_private_method(blake2 , "initialize", RUBY_METHOD_FUNC(m_blake2_initialize), 2);
|
91
|
+
rb_define_method(blake2 , "digest", RUBY_METHOD_FUNC(m_blake2_digest), 2);
|
92
|
+
}
|
data/lib/blake2.rb
ADDED
data/lib/blake2/key.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
class Blake2
|
2
|
+
class Key
|
3
|
+
def bytes
|
4
|
+
@bytes
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(bytes)
|
8
|
+
@bytes = bytes
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.from_string(str)
|
12
|
+
new(@bytes = str.bytes)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.from_hex(hex_str)
|
16
|
+
new(@bytes = [hex_str].pack("H*").bytes)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.none
|
20
|
+
new(@bytes = [])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class KeyTest < MiniTest::Test
|
4
|
+
def test_from_string
|
5
|
+
key = Blake2::Key.from_string("foo bar baz")
|
6
|
+
assert_equal [102, 111, 111, 32, 98, 97, 114, 32, 98, 97, 122], key.bytes
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_none
|
10
|
+
key = Blake2::Key.none
|
11
|
+
assert_equal [], key.bytes
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_from_hex
|
15
|
+
key = Blake2::Key.from_hex("DEADBEAF")
|
16
|
+
assert_equal [0XDE, 0xAD, 0xBE, 0xAF], key.bytes
|
17
|
+
end
|
18
|
+
end
|
data/test/blake2_test.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Blake2Test < MiniTest::Test
|
4
|
+
def setup
|
5
|
+
out_len = 32
|
6
|
+
key = Blake2::Key.from_string("foo bar baz") # or `Key.none`, or `Key.from_hex("0xDEADBEAF")`
|
7
|
+
|
8
|
+
@digestor = Blake2.new(out_len, key)
|
9
|
+
|
10
|
+
@input = "hello world"
|
11
|
+
@expected = "95670379036532875f58bf23fbcb549675b656bd639a6124a614ccd8a980b180"
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_to_hex
|
15
|
+
res = @digestor.digest(@input, :to_hex) # => 9567...b180
|
16
|
+
assert_kind_of String, res
|
17
|
+
assert_equal @expected, res
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_bytes
|
21
|
+
res = @digestor.digest(@input, :to_bytes) # => [0x95, 0x67, <28 bytes later...>, 0xb1, 0x80]
|
22
|
+
assert_kind_of Array, res
|
23
|
+
assert_equal @expected.pack("H*").bytes, res
|
24
|
+
end
|
25
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blake2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Franck Verrot
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDaDCCAlCgAwIBAgIB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sI9kwrDgoAd7qnSmb
|
28
|
+
Udf49ZrzniqaFR7OiBia2oXrYynD8Q4mRMzLTMdtdf8oy69DjCrrpzQvEcfHnxML
|
29
|
+
MY7zkhoLIwqbZ+/yfSm26+3h91WoEKEdK+caiHotdq1goqlBDIsLSR65siB2yna3
|
30
|
+
UeH0jxnbT6lYw622u74Z7Dd6iQfaOy1h+iJxnCQglf70rs9bS665Nr0QvvrbW8Hz
|
31
|
+
Vr/YT3S8RkdBsIdM
|
32
|
+
-----END CERTIFICATE-----
|
33
|
+
date: 2014-10-05 00:00:00.000000000 Z
|
34
|
+
dependencies:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rake-compiler
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
type: :development
|
43
|
+
prerelease: false
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: bundler
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.5'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.5'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rake
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: minitest
|
79
|
+
requirement: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
type: :development
|
85
|
+
prerelease: false
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
description: BLAKE2 - fast secure hashing - for Ruby
|
92
|
+
email:
|
93
|
+
- franck@verrot.fr
|
94
|
+
executables: []
|
95
|
+
extensions:
|
96
|
+
- ext/blake2_ext/extconf.rb
|
97
|
+
extra_rdoc_files: []
|
98
|
+
files:
|
99
|
+
- ".gitignore"
|
100
|
+
- ".travis.yml"
|
101
|
+
- CHANGELOG.md
|
102
|
+
- Gemfile
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- blake2.gemspec
|
107
|
+
- certs/franckverrot.pem
|
108
|
+
- checksums/0.1.0.sha512
|
109
|
+
- ext/blake2_ext/blake2-impl.h
|
110
|
+
- ext/blake2_ext/blake2.h
|
111
|
+
- ext/blake2_ext/blake2s-ref.c
|
112
|
+
- ext/blake2_ext/extconf.rb
|
113
|
+
- ext/blake2_ext/rbext.c
|
114
|
+
- lib/blake2.rb
|
115
|
+
- lib/blake2/key.rb
|
116
|
+
- test/blake2/key_test.rb
|
117
|
+
- test/blake2_test.rb
|
118
|
+
- test/test_helper.rb
|
119
|
+
homepage: https://github.com/franckverrot/blake2
|
120
|
+
licenses:
|
121
|
+
- GPLv3
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.2.0
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: BLAKE2 - fast secure hashing - for Ruby
|
143
|
+
test_files:
|
144
|
+
- test/blake2/key_test.rb
|
145
|
+
- test/blake2_test.rb
|
146
|
+
- test/test_helper.rb
|
147
|
+
has_rdoc:
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
i�;�ڭ�1�=��0��*`I����@������<� �G�\f-���qNO�/��ᜯ\q�my�DICwZCL����{���F�5J1\��]q2���=�W�����+�®�}�j7����6�xR�?q8��a`m�=�)WR(�\��*k�¥�ze��qj��HFF��Ԋ%�����ϙ�:��s�];�^1m��T�ю^0��¹��-���k��b���eI�-�)�*R�v�()L{�Z.���Uۋҗ
|