blake2 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cacd5c7a8696d2e3c9bf9ba76e2c8cc54c3a47db
4
- data.tar.gz: 19f4df0b42ed8bd82bc9101b7830e7570805e826
3
+ metadata.gz: 4250cbe6cd64da1a6b5a975ad4723dc257cb08b3
4
+ data.tar.gz: 06f89ae5b24e3a63536cf7718490c12624e0b05b
5
5
  SHA512:
6
- metadata.gz: cc5451f87f530f02b6d30cacb31dddf12b1f35216ce49a1c8563aa1c5ff67fe0d660b3b759df15ac47c9449f8ad0c6ad79f5d0ee8b7c711f6e9f6558ae24f895
7
- data.tar.gz: 2213fe41d9e0880a8051f8caad57d09958443ad08b64b2e838971b0677dcec765b2dee6e2aaba22c6cbeeb06eaa617256a2c76e5d0f1e7f209b1397ff1a29dac
6
+ metadata.gz: 6c963fd93b7772aa6c39e476b635568b10d521959b67b8d6ee1019707b2a18e3c66c9b09c2047f009785caf47fac9069ce40669fde646909fbceeac3a564e00a
7
+ data.tar.gz: 37fefa3f64d105717495ac62c10a12b3f85e551146c8d455be2d0e3577a41e3cc2fdd7d8cc21b27cc80ef8bcd0df71556c2f2a007bb01dc6fa46edf5873adf6b
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
1
  # Releases
2
2
 
3
- ## UNRELEASED (0.1.0)
3
+ ## UNRELEASED (0.3.0)
4
+
5
+ ## 0.2.0
6
+
7
+ * Prevent memory leaks
8
+ * Update the gem's certificate
9
+
10
+ ## 0.1.0
11
+
12
+ * Initial release
data/blake2.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "blake2"
4
- spec.version = "0.1.0"
4
+ spec.version = "0.2.0"
5
5
  spec.authors = ["Franck Verrot"]
6
6
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+ rTx4uCkHJszIocIZiKE/Ntk6xooQVTC/L95K/yycDCyss2c8JF2wdg/+q38u7rOS
17
+ fAbV2IGNLTPYWX+M2B08a6lVVRMD386TGrk0/ROjgZIhuHah4dY+ObAUyUv1oiyb
18
+ PEaDVSbqqbtwQAsY87Vam7GUcH/IJnhdLadvNOJlLr8jxW+gm1ZFE9MOlsSmHeGe
19
+ Z7BoH/Mfxw3P4yyir173p9JWvVqLiQE13XBeD13NPA8neoWpLJxm6k03PcTElT/E
20
+ QrOSgKrHAb/fFJma
21
21
  -----END CERTIFICATE-----
@@ -4,89 +4,101 @@
4
4
 
5
5
  typedef struct {
6
6
  uint8_t key_length;
7
- uint8_t *key;
7
+ uint8_t *key_bytes;
8
8
 
9
9
  uint8_t output_length;
10
10
  uint8_t *output;
11
+
12
+ VALUE to_hex;
13
+ VALUE to_bytes;
11
14
  } Blake2;
12
15
 
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
- }
16
+ VALUE cBlake2;
21
17
 
22
18
  static void blake2_free(Blake2 *blake2) {
23
- rb_gc_mark(blake2->key);
19
+ if(blake2->key_length > 0) {
20
+ ruby_xfree(blake2->key_bytes);
21
+ }
22
+
23
+ if(blake2->output_length > 0) {
24
+ ruby_xfree(blake2->output);
25
+ }
24
26
  }
25
27
 
26
- static VALUE blake2_alloc(VALUE klass) {
27
- return Data_Wrap_Struct(klass, NULL, blake2_free, ruby_xmalloc(sizeof(Blake2)));
28
+ VALUE blake2_alloc(VALUE klass) {
29
+ VALUE blake2_obj = ruby_xmalloc(sizeof(Blake2));
30
+
31
+ return Data_Wrap_Struct(klass, NULL, blake2_free, blake2_obj);
28
32
  }
29
33
 
30
34
  VALUE m_blake2_initialize(VALUE self, VALUE _len, VALUE _key) {
31
- Blake2 *blake2;
32
- Data_Get_Struct(self, Blake2, blake2);
35
+ Blake2 *blake2;
36
+ Data_Get_Struct(self, Blake2, blake2);
37
+ int i;
38
+
39
+ ID bytes_method = rb_intern("bytes");
40
+ blake2->to_hex = ID2SYM(rb_intern("to_hex"));
41
+ blake2->to_bytes = ID2SYM(rb_intern("to_bytes"));
33
42
 
34
- blake2->key = _key;
35
- blake2->output_length = NUM2INT(_len);
36
- blake2->output = (uint8_t*)ruby_xmalloc(blake2->output_length * sizeof(uint8_t));
43
+ VALUE key_bytes_ary = rb_funcall(_key, bytes_method, 0);
44
+ blake2->key_length = RARRAY_LEN(key_bytes_ary);
45
+ blake2->key_bytes = (uint8_t*)ruby_xmalloc(blake2->key_length * sizeof(uint8_t));
37
46
 
38
- return Qnil;
47
+ for(i = 0; i < blake2->key_length; i++) {
48
+ VALUE byte = rb_ary_entry(key_bytes_ary, i);
49
+ blake2->key_bytes[i] = NUM2INT(byte);
50
+ }
51
+
52
+ blake2->output_length = NUM2INT(_len);
53
+ blake2->output = (uint8_t*)ruby_xmalloc(blake2->output_length * sizeof(uint8_t));
54
+
55
+ return Qnil;
39
56
  }
40
57
 
58
+
41
59
  VALUE m_blake2_digest(VALUE self, VALUE _input, VALUE _representation) {
42
60
  Blake2 *blake2;
43
61
 
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);
62
+ char * input = RSTRING_PTR(_input);
48
63
  int input_length = RSTRING_LEN(_input);
49
64
  int i;
50
65
 
51
66
  Data_Get_Struct(self, Blake2, blake2);
52
67
 
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
- }
68
+ blake2s(blake2->output, input, blake2->key_bytes,
69
+ blake2->output_length, input_length, blake2->key_length);
63
70
 
64
- blake2s(blake2->output, input, key_bytes,
65
- blake2->output_length, input_length, key_len);
71
+ VALUE result;
66
72
 
67
- if(_representation == to_bytes) {
68
- VALUE result = rb_ary_new2(blake2->output_length);
73
+ if(_representation == blake2->to_bytes) {
74
+ result = rb_ary_new2(blake2->output_length);
69
75
 
70
76
  for(i = 0; i < blake2->output_length; i++) {
71
77
  rb_ary_push(result, INT2NUM(blake2->output[i]));
72
78
  }
73
79
 
74
80
  return result;
75
- } else if(_representation == to_hex) {
81
+ } else if(_representation == blake2->to_hex) {
76
82
  char * c_str = (char*)ruby_xmalloc(blake2->output_length * sizeof(char) * 2);
77
83
 
78
84
  for(i = 0; i < blake2->output_length; i++) {
79
85
  sprintf(c_str + (i * 2), "%02x", blake2->output[i]);
80
86
  }
81
- return rb_str_new2(c_str);
87
+
88
+ result = rb_str_new2(c_str);
89
+
90
+ ruby_xfree(c_str);
91
+
92
+ return result;
82
93
  } else {
83
94
  rb_raise(rb_eArgError, "Unknown representation", _representation);
84
95
  }
85
96
  }
97
+
86
98
  void Init_blake2_ext() {
87
- VALUE blake2 = rb_define_class("Blake2", rb_cObject);
88
- rb_define_alloc_func(blake2, blake2_alloc);
99
+ cBlake2 = rb_define_class("Blake2", rb_cObject);
100
+ rb_define_alloc_func(cBlake2, blake2_alloc);
89
101
 
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);
102
+ rb_define_private_method(cBlake2, "initialize", RUBY_METHOD_FUNC(m_blake2_initialize), 2);
103
+ rb_define_method(cBlake2, "digest", RUBY_METHOD_FUNC(m_blake2_digest), 2);
92
104
  }
data/lib/blake2/key.rb CHANGED
@@ -9,15 +9,15 @@ class Blake2
9
9
  end
10
10
 
11
11
  def self.from_string(str)
12
- new(@bytes = str.bytes)
12
+ new(str.bytes)
13
13
  end
14
14
 
15
15
  def self.from_hex(hex_str)
16
- new(@bytes = [hex_str].pack("H*").bytes)
16
+ new([hex_str].pack("H*").bytes)
17
17
  end
18
18
 
19
19
  def self.none
20
- new(@bytes = [])
20
+ new([])
21
21
  end
22
22
  end
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blake2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franck Verrot
@@ -12,25 +12,25 @@ cert_chain:
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIDaDCCAlCgAwIBAgIBATANBgkqhkiG9w0BAQUFADA9MQ8wDQYDVQQDDAZmcmFu
14
14
  Y2sxFjAUBgoJkiaJk/IsZAEZFgZ2ZXJyb3QxEjAQBgoJkiaJk/IsZAEZFgJmcjAe
15
- Fw0xNDA5MDcwODE4MDRaFw0xNTA5MDcwODE4MDRaMD0xDzANBgNVBAMMBmZyYW5j
15
+ Fw0xNjA1MTMxOTQ3NTlaFw0xNzA1MTMxOTQ3NTlaMD0xDzANBgNVBAMMBmZyYW5j
16
16
  azEWMBQGCgmSJomT8ixkARkWBnZlcnJvdDESMBAGCgmSJomT8ixkARkWAmZyMIIB
17
- IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw8Sqy/b4OzhODXkAqv/Ve7hp
18
- oH5irjrS20ebbzWqefcHCybwqcmePUs4BtWnGMkGl+fe4Dxfh55m7EXbmbcLBqPJ
19
- 3Q5bqIgXqmkzHU6oBpkY/fdcP0dLyYBTAo8jZsx6XE1NoC5MBFfHQ8GFzEox7ca7
20
- eoRPETTFkrlOU8fQQvRMZV8cO9XbzX8PFsJ9iE7CSrZ3+78oFBrj+WslkdU/pR5g
21
- CYU7eNmWPBbJsgWy9T63K4QkwMElJRvlge3dzAZBEktaxdbiPTQeBtLugIZV2nWA
22
- mNVMXQ9FzDeSF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GA1UdDwQEAwIEsDAdBgNVHQ4EFgQU7Ygnr1Sx
24
+ 42iryVPwtuJC/acw2TAwGwYDVR0RBBQwEoEQZnJhbmNrQHZlcnJvdC5mcjAbBgNV
25
+ HRIEFDASgRBmcmFuY2tAdmVycm90LmZyMA0GCSqGSIb3DQEBBQUAA4IBAQBdZVhZ
26
+ dhXujOsiysxAqtixFFXH9wSQNIltYQ8zuRLA/FgwqrNUQq+Qdiib5Kqj5hUK4okl
27
+ rTx4uCkHJszIocIZiKE/Ntk6xooQVTC/L95K/yycDCyss2c8JF2wdg/+q38u7rOS
28
+ fAbV2IGNLTPYWX+M2B08a6lVVRMD386TGrk0/ROjgZIhuHah4dY+ObAUyUv1oiyb
29
+ PEaDVSbqqbtwQAsY87Vam7GUcH/IJnhdLadvNOJlLr8jxW+gm1ZFE9MOlsSmHeGe
30
+ Z7BoH/Mfxw3P4yyir173p9JWvVqLiQE13XBeD13NPA8neoWpLJxm6k03PcTElT/E
31
+ QrOSgKrHAb/fFJma
32
32
  -----END CERTIFICATE-----
33
- date: 2014-10-05 00:00:00.000000000 Z
33
+ date: 2016-05-13 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: rake-compiler
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
- rubygems_version: 2.2.0
139
+ rubygems_version: 2.6.4
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: BLAKE2 - fast secure hashing - for Ruby
@@ -144,4 +144,3 @@ test_files:
144
144
  - test/blake2/key_test.rb
145
145
  - test/blake2_test.rb
146
146
  - test/test_helper.rb
147
- has_rdoc:
metadata.gz.sig CHANGED
Binary file