digest-blake2b 0.0.4 → 0.0.5

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
  SHA256:
3
- metadata.gz: 664bd156e4290bfe01d6977508732cdaef1b950d0f1a5d632165106c4670f11a
4
- data.tar.gz: 392f665ea5dca923c1d05f4f7aa2b2b0fc4e853e115d8cf4a7b884ce335b1f83
3
+ metadata.gz: aa9d422fef855a4edaa9c46b813a70b96d50a97aa7f6c5d940bdc57f2c42b7b9
4
+ data.tar.gz: 9b1d6085a3882c9ab957e16d0b5342ac429cb3edeff0ac8e463505719f0d3c4c
5
5
  SHA512:
6
- metadata.gz: 8daabe85e4c187b61fc65edb6dffb23ee6c6bbc68199521f8a2b4eafdec7c6d35c090a48941ef17748c1e87481771dbe4124d9c8ea6b5a6213f45da6b2cda481
7
- data.tar.gz: 6434d4681b9a4d500ec861315512cec3e1233a5f7afaf376f85a999875d23259b03b1405fd8907b47675bb106ce1499f3a06d70664c13ffb7ba3248d840e684d
6
+ metadata.gz: d7712099b5d3a8cae79e41b5d88542ae033ae9c9c4cf019e6abf08d8d3f92f89eff1e819aa2a3978db67c9c50e5943bdf64fafa13a5983403b78ff2391d8d127
7
+ data.tar.gz: 190c8a94604b7d45c1a16ae7ece720eeb906fe3196f0a38f15e259facfa0f6abb0914c855aaad2059d7ccdde562788bf737bec743cca8cdefbecd3f631914683
data/.gitignore CHANGED
@@ -9,7 +9,6 @@
9
9
  !/checksums/.keep
10
10
  /lib/**/*.bundle
11
11
  /lib/digest/blake2b/ext.so
12
- /lib/digest/blake2b/sse.so
13
12
 
14
13
  *.o
15
14
  *.gem
data/Rakefile CHANGED
@@ -6,9 +6,8 @@ require 'rake/extensiontask'
6
6
 
7
7
  spec = Gem::Specification.load('digest-blake2b.gemspec')
8
8
 
9
- Rake::ExtensionTask.new "digest/blake2b/#{Digest::Blake2b::IMPL}", spec do |ext|
9
+ Rake::ExtensionTask.new 'digest/blake2b/ext', spec do |ext|
10
10
  ext.source_pattern = '*.{c,h}'
11
- ext.ext_dir = "ext/digest/blake2b/#{Digest::Blake2b::IMPL}"
12
11
  end
13
12
 
14
13
  Rake::TestTask.new do |t|
@@ -4,7 +4,6 @@ lib = File.expand_path('lib', __dir__).freeze
4
4
  $LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
5
5
 
6
6
  require 'digest/blake2b/version'
7
- require 'digest/blake2b/impl'
8
7
 
9
8
  Gem::Specification.new do |spec|
10
9
  spec.name = 'digest-blake2b'
@@ -42,7 +41,7 @@ Gem::Specification.new do |spec|
42
41
 
43
42
  spec.executables = spec.files.grep %r{^exe/}, &File.method(:basename)
44
43
 
45
- spec.extensions << "ext/digest/blake2b/#{Digest::Blake2b::IMPL}/extconf.rb"
44
+ spec.extensions << 'ext/digest/blake2b/ext/extconf.rb'
46
45
 
47
46
  spec.add_development_dependency 'bundler' , '~> 2.2'
48
47
  spec.add_development_dependency 'minitest' , '~> 5.11'
File without changes
File without changes
@@ -0,0 +1,7 @@
1
+ #ifdef IMPL_REF
2
+ #include "ref/blake2b-ref.c"
3
+ #endif
4
+
5
+ #ifdef IMPL_SSE
6
+ #include "sse/blake2b-ref.c"
7
+ #endif
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkmf'
4
+
5
+ $CFLAGS += ' -std=c99 -pedantic -Wall -Wextra'
6
+
7
+ if RUBY_PLATFORM =~ /^x86_64/
8
+ $CPPFLAGS += ' -DIMPL_SSE'
9
+ $CFLAGS += ' -Wno-long-long'
10
+ else
11
+ $CPPFLAGS += ' -DIMPL_REF'
12
+ end
13
+
14
+ create_makefile 'digest/blake2b/ext'
@@ -1,6 +1,7 @@
1
+ #include "blake2.h"
2
+
1
3
  #include <ruby/ruby.h>
2
4
  #include <ruby/encoding.h>
3
- #include "blake2.h"
4
5
 
5
6
  typedef struct {
6
7
  size_t key_length;
@@ -100,7 +101,7 @@ VALUE m_blake2_digest(VALUE self, VALUE _input, VALUE _representation) {
100
101
  return result;
101
102
  }
102
103
 
103
- void Init_sse() {
104
+ void Init_ext() {
104
105
  mDigest = rb_define_module("Digest");
105
106
 
106
107
  mDigest_cBlake2 = rb_define_class_under(mDigest, "Blake2b", rb_cObject);
@@ -303,14 +303,14 @@ int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *
303
303
  return blake2b(out, outlen, in, inlen, key, keylen);
304
304
  }
305
305
 
306
- #if defined(SUPERCOP)
306
+ #ifdef SUPERCOP
307
307
  int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen )
308
308
  {
309
309
  return blake2b( out, BLAKE2B_OUTBYTES, in, inlen, NULL, 0 );
310
310
  }
311
311
  #endif
312
312
 
313
- #if defined(BLAKE2B_SELFTEST)
313
+ #ifdef BLAKE2B_SELFTEST
314
314
  #include <string.h>
315
315
  #include "blake2-kat.h"
316
316
  int main( void )
File without changes
File without changes
File without changes
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Digest
4
4
  class Blake2b
5
- VERSION = '0.0.4'
5
+ VERSION = '0.0.5'
6
6
  end
7
7
  end
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'digest/blake2b/key'
4
3
  require 'digest/blake2b/version'
5
- require 'digest/blake2b/impl'
6
-
7
- require "digest/blake2b/#{Digest::Blake2b::IMPL}"
4
+ require 'digest/blake2b/key'
5
+ require 'digest/blake2b/ext'
8
6
 
9
7
  module Digest
10
8
  class Blake2b
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digest-blake2b
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Kotov
@@ -74,7 +74,7 @@ email:
74
74
  - mauricio@edge14.com
75
75
  executables: []
76
76
  extensions:
77
- - ext/digest/blake2b/sse/extconf.rb
77
+ - ext/digest/blake2b/ext/extconf.rb
78
78
  extra_rdoc_files: []
79
79
  files:
80
80
  - ".circleci/config.yml"
@@ -85,22 +85,18 @@ files:
85
85
  - Rakefile
86
86
  - checksums/.keep
87
87
  - digest-blake2b.gemspec
88
- - ext/digest/blake2b/ref/blake2-impl.h
89
- - ext/digest/blake2b/ref/blake2.h
90
- - ext/digest/blake2b/ref/blake2b-ref.c
91
- - ext/digest/blake2b/ref/extconf.rb
92
- - ext/digest/blake2b/ref/rbext.c
93
- - ext/digest/blake2b/sse/blake2-config.h
94
- - ext/digest/blake2b/sse/blake2-impl.h
95
- - ext/digest/blake2b/sse/blake2.h
96
- - ext/digest/blake2b/sse/blake2b-load-sse2.h
97
- - ext/digest/blake2b/sse/blake2b-load-sse41.h
98
- - ext/digest/blake2b/sse/blake2b-ref.c
99
- - ext/digest/blake2b/sse/blake2b-round.h
100
- - ext/digest/blake2b/sse/extconf.rb
101
- - ext/digest/blake2b/sse/rbext.c
88
+ - ext/digest/blake2b/ext/blake2-impl.h
89
+ - ext/digest/blake2b/ext/blake2.h
90
+ - ext/digest/blake2b/ext/blake2b-ref.c
91
+ - ext/digest/blake2b/ext/extconf.rb
92
+ - ext/digest/blake2b/ext/rbext.c
93
+ - ext/digest/blake2b/ext/ref/blake2b-ref.c
94
+ - ext/digest/blake2b/ext/sse/blake2-config.h
95
+ - ext/digest/blake2b/ext/sse/blake2b-load-sse2.h
96
+ - ext/digest/blake2b/ext/sse/blake2b-load-sse41.h
97
+ - ext/digest/blake2b/ext/sse/blake2b-ref.c
98
+ - ext/digest/blake2b/ext/sse/blake2b-round.h
102
99
  - lib/digest/blake2b.rb
103
- - lib/digest/blake2b/impl.rb
104
100
  - lib/digest/blake2b/key.rb
105
101
  - lib/digest/blake2b/version.rb
106
102
  - performance/performance_suite.rb
@@ -1,160 +0,0 @@
1
- /*
2
- BLAKE2 reference source code package - reference C implementations
3
-
4
- Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
5
- terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
6
- your option. The terms of these licenses can be found at:
7
-
8
- - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
9
- - OpenSSL license : https://www.openssl.org/source/license.html
10
- - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- More information about the BLAKE2 hash function can be found at
13
- https://blake2.net.
14
- */
15
- #ifndef BLAKE2_IMPL_H
16
- #define BLAKE2_IMPL_H
17
-
18
- #include <stdint.h>
19
- #include <string.h>
20
-
21
- #if !defined(__cplusplus) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L)
22
- #if defined(_MSC_VER)
23
- #define BLAKE2_INLINE __inline
24
- #elif defined(__GNUC__)
25
- #define BLAKE2_INLINE __inline__
26
- #else
27
- #define BLAKE2_INLINE
28
- #endif
29
- #else
30
- #define BLAKE2_INLINE inline
31
- #endif
32
-
33
- static BLAKE2_INLINE uint32_t load32( const void *src )
34
- {
35
- #if defined(NATIVE_LITTLE_ENDIAN)
36
- uint32_t w;
37
- memcpy(&w, src, sizeof w);
38
- return w;
39
- #else
40
- const uint8_t *p = ( const uint8_t * )src;
41
- return (( uint32_t )( p[0] ) << 0) |
42
- (( uint32_t )( p[1] ) << 8) |
43
- (( uint32_t )( p[2] ) << 16) |
44
- (( uint32_t )( p[3] ) << 24) ;
45
- #endif
46
- }
47
-
48
- static BLAKE2_INLINE uint64_t load64( const void *src )
49
- {
50
- #if defined(NATIVE_LITTLE_ENDIAN)
51
- uint64_t w;
52
- memcpy(&w, src, sizeof w);
53
- return w;
54
- #else
55
- const uint8_t *p = ( const uint8_t * )src;
56
- return (( uint64_t )( p[0] ) << 0) |
57
- (( uint64_t )( p[1] ) << 8) |
58
- (( uint64_t )( p[2] ) << 16) |
59
- (( uint64_t )( p[3] ) << 24) |
60
- (( uint64_t )( p[4] ) << 32) |
61
- (( uint64_t )( p[5] ) << 40) |
62
- (( uint64_t )( p[6] ) << 48) |
63
- (( uint64_t )( p[7] ) << 56) ;
64
- #endif
65
- }
66
-
67
- static BLAKE2_INLINE uint16_t load16( const void *src )
68
- {
69
- #if defined(NATIVE_LITTLE_ENDIAN)
70
- uint16_t w;
71
- memcpy(&w, src, sizeof w);
72
- return w;
73
- #else
74
- const uint8_t *p = ( const uint8_t * )src;
75
- return (( uint16_t )( p[0] ) << 0) |
76
- (( uint16_t )( p[1] ) << 8) ;
77
- #endif
78
- }
79
-
80
- static BLAKE2_INLINE void store16( void *dst, uint16_t w )
81
- {
82
- #if defined(NATIVE_LITTLE_ENDIAN)
83
- memcpy(dst, &w, sizeof w);
84
- #else
85
- uint8_t *p = ( uint8_t * )dst;
86
- *p++ = ( uint8_t )w; w >>= 8;
87
- *p++ = ( uint8_t )w;
88
- #endif
89
- }
90
-
91
- static BLAKE2_INLINE void store32( void *dst, uint32_t w )
92
- {
93
- #if defined(NATIVE_LITTLE_ENDIAN)
94
- memcpy(dst, &w, sizeof w);
95
- #else
96
- uint8_t *p = ( uint8_t * )dst;
97
- p[0] = (uint8_t)(w >> 0);
98
- p[1] = (uint8_t)(w >> 8);
99
- p[2] = (uint8_t)(w >> 16);
100
- p[3] = (uint8_t)(w >> 24);
101
- #endif
102
- }
103
-
104
- static BLAKE2_INLINE void store64( void *dst, uint64_t w )
105
- {
106
- #if defined(NATIVE_LITTLE_ENDIAN)
107
- memcpy(dst, &w, sizeof w);
108
- #else
109
- uint8_t *p = ( uint8_t * )dst;
110
- p[0] = (uint8_t)(w >> 0);
111
- p[1] = (uint8_t)(w >> 8);
112
- p[2] = (uint8_t)(w >> 16);
113
- p[3] = (uint8_t)(w >> 24);
114
- p[4] = (uint8_t)(w >> 32);
115
- p[5] = (uint8_t)(w >> 40);
116
- p[6] = (uint8_t)(w >> 48);
117
- p[7] = (uint8_t)(w >> 56);
118
- #endif
119
- }
120
-
121
- static BLAKE2_INLINE uint64_t load48( const void *src )
122
- {
123
- const uint8_t *p = ( const uint8_t * )src;
124
- return (( uint64_t )( p[0] ) << 0) |
125
- (( uint64_t )( p[1] ) << 8) |
126
- (( uint64_t )( p[2] ) << 16) |
127
- (( uint64_t )( p[3] ) << 24) |
128
- (( uint64_t )( p[4] ) << 32) |
129
- (( uint64_t )( p[5] ) << 40) ;
130
- }
131
-
132
- static BLAKE2_INLINE void store48( void *dst, uint64_t w )
133
- {
134
- uint8_t *p = ( uint8_t * )dst;
135
- p[0] = (uint8_t)(w >> 0);
136
- p[1] = (uint8_t)(w >> 8);
137
- p[2] = (uint8_t)(w >> 16);
138
- p[3] = (uint8_t)(w >> 24);
139
- p[4] = (uint8_t)(w >> 32);
140
- p[5] = (uint8_t)(w >> 40);
141
- }
142
-
143
- static BLAKE2_INLINE uint32_t rotr32( const uint32_t w, const unsigned c )
144
- {
145
- return ( w >> c ) | ( w << ( 32 - c ) );
146
- }
147
-
148
- static BLAKE2_INLINE uint64_t rotr64( const uint64_t w, const unsigned c )
149
- {
150
- return ( w >> c ) | ( w << ( 64 - c ) );
151
- }
152
-
153
- /* prevents compiler optimizing out memset() */
154
- static BLAKE2_INLINE void secure_zero_memory(void *v, size_t n)
155
- {
156
- static void *(*const volatile memset_v)(void *, int, size_t) = &memset;
157
- memset_v(v, 0, n);
158
- }
159
-
160
- #endif
@@ -1,195 +0,0 @@
1
- /*
2
- BLAKE2 reference source code package - reference C implementations
3
-
4
- Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
5
- terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
6
- your option. The terms of these licenses can be found at:
7
-
8
- - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
9
- - OpenSSL license : https://www.openssl.org/source/license.html
10
- - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
11
-
12
- More information about the BLAKE2 hash function can be found at
13
- https://blake2.net.
14
- */
15
- #ifndef BLAKE2_H
16
- #define BLAKE2_H
17
-
18
- #include <stddef.h>
19
- #include <stdint.h>
20
-
21
- #if defined(_MSC_VER)
22
- #define BLAKE2_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
23
- #else
24
- #define BLAKE2_PACKED(x) x __attribute__((packed))
25
- #endif
26
-
27
- #if defined(__cplusplus)
28
- extern "C" {
29
- #endif
30
-
31
- enum blake2s_constant
32
- {
33
- BLAKE2S_BLOCKBYTES = 64,
34
- BLAKE2S_OUTBYTES = 32,
35
- BLAKE2S_KEYBYTES = 32,
36
- BLAKE2S_SALTBYTES = 8,
37
- BLAKE2S_PERSONALBYTES = 8
38
- };
39
-
40
- enum blake2b_constant
41
- {
42
- BLAKE2B_BLOCKBYTES = 128,
43
- BLAKE2B_OUTBYTES = 64,
44
- BLAKE2B_KEYBYTES = 64,
45
- BLAKE2B_SALTBYTES = 16,
46
- BLAKE2B_PERSONALBYTES = 16
47
- };
48
-
49
- typedef struct blake2s_state__
50
- {
51
- uint32_t h[8];
52
- uint32_t t[2];
53
- uint32_t f[2];
54
- uint8_t buf[BLAKE2S_BLOCKBYTES];
55
- size_t buflen;
56
- size_t outlen;
57
- uint8_t last_node;
58
- } blake2s_state;
59
-
60
- typedef struct blake2b_state__
61
- {
62
- uint64_t h[8];
63
- uint64_t t[2];
64
- uint64_t f[2];
65
- uint8_t buf[BLAKE2B_BLOCKBYTES];
66
- size_t buflen;
67
- size_t outlen;
68
- uint8_t last_node;
69
- } blake2b_state;
70
-
71
- typedef struct blake2sp_state__
72
- {
73
- blake2s_state S[8][1];
74
- blake2s_state R[1];
75
- uint8_t buf[8 * BLAKE2S_BLOCKBYTES];
76
- size_t buflen;
77
- size_t outlen;
78
- } blake2sp_state;
79
-
80
- typedef struct blake2bp_state__
81
- {
82
- blake2b_state S[4][1];
83
- blake2b_state R[1];
84
- uint8_t buf[4 * BLAKE2B_BLOCKBYTES];
85
- size_t buflen;
86
- size_t outlen;
87
- } blake2bp_state;
88
-
89
-
90
- BLAKE2_PACKED(struct blake2s_param__
91
- {
92
- uint8_t digest_length; /* 1 */
93
- uint8_t key_length; /* 2 */
94
- uint8_t fanout; /* 3 */
95
- uint8_t depth; /* 4 */
96
- uint32_t leaf_length; /* 8 */
97
- uint32_t node_offset; /* 12 */
98
- uint16_t xof_length; /* 14 */
99
- uint8_t node_depth; /* 15 */
100
- uint8_t inner_length; /* 16 */
101
- /* uint8_t reserved[0]; */
102
- uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */
103
- uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
104
- });
105
-
106
- typedef struct blake2s_param__ blake2s_param;
107
-
108
- BLAKE2_PACKED(struct blake2b_param__
109
- {
110
- uint8_t digest_length; /* 1 */
111
- uint8_t key_length; /* 2 */
112
- uint8_t fanout; /* 3 */
113
- uint8_t depth; /* 4 */
114
- uint32_t leaf_length; /* 8 */
115
- uint32_t node_offset; /* 12 */
116
- uint32_t xof_length; /* 16 */
117
- uint8_t node_depth; /* 17 */
118
- uint8_t inner_length; /* 18 */
119
- uint8_t reserved[14]; /* 32 */
120
- uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
121
- uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
122
- });
123
-
124
- typedef struct blake2b_param__ blake2b_param;
125
-
126
- typedef struct blake2xs_state__
127
- {
128
- blake2s_state S[1];
129
- blake2s_param P[1];
130
- } blake2xs_state;
131
-
132
- typedef struct blake2xb_state__
133
- {
134
- blake2b_state S[1];
135
- blake2b_param P[1];
136
- } blake2xb_state;
137
-
138
- /* Padded structs result in a compile-time error */
139
- enum {
140
- BLAKE2_DUMMY_1 = 1/(sizeof(blake2s_param) == BLAKE2S_OUTBYTES),
141
- BLAKE2_DUMMY_2 = 1/(sizeof(blake2b_param) == BLAKE2B_OUTBYTES)
142
- };
143
-
144
- /* Streaming API */
145
- int blake2s_init( blake2s_state *S, size_t outlen );
146
- int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen );
147
- int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
148
- int blake2s_update( blake2s_state *S, const void *in, size_t inlen );
149
- int blake2s_final( blake2s_state *S, void *out, size_t outlen );
150
-
151
- int blake2b_init( blake2b_state *S, size_t outlen );
152
- int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen );
153
- int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
154
- int blake2b_update( blake2b_state *S, const void *in, size_t inlen );
155
- int blake2b_final( blake2b_state *S, void *out, size_t outlen );
156
-
157
- int blake2sp_init( blake2sp_state *S, size_t outlen );
158
- int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen );
159
- int blake2sp_update( blake2sp_state *S, const void *in, size_t inlen );
160
- int blake2sp_final( blake2sp_state *S, void *out, size_t outlen );
161
-
162
- int blake2bp_init( blake2bp_state *S, size_t outlen );
163
- int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen );
164
- int blake2bp_update( blake2bp_state *S, const void *in, size_t inlen );
165
- int blake2bp_final( blake2bp_state *S, void *out, size_t outlen );
166
-
167
- /* Variable output length API */
168
- int blake2xs_init( blake2xs_state *S, const size_t outlen );
169
- int blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen );
170
- int blake2xs_update( blake2xs_state *S, const void *in, size_t inlen );
171
- int blake2xs_final(blake2xs_state *S, void *out, size_t outlen);
172
-
173
- int blake2xb_init( blake2xb_state *S, const size_t outlen );
174
- int blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, size_t keylen );
175
- int blake2xb_update( blake2xb_state *S, const void *in, size_t inlen );
176
- int blake2xb_final(blake2xb_state *S, void *out, size_t outlen);
177
-
178
- /* Simple API */
179
- int blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
180
- int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
181
-
182
- int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
183
- int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
184
-
185
- int blake2xs( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
186
- int blake2xb( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
187
-
188
- /* This is simply an alias for blake2b */
189
- int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
190
-
191
- #if defined(__cplusplus)
192
- }
193
- #endif
194
-
195
- #endif
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'mkmf'
4
-
5
- $CFLAGS += ' -std=c99 -pedantic -Wall -Wextra'
6
-
7
- create_makefile 'digest/blake2b/ref'
@@ -1,111 +0,0 @@
1
- #include <ruby/ruby.h>
2
- #include <ruby/encoding.h>
3
- #include "blake2.h"
4
-
5
- typedef struct {
6
- size_t key_length;
7
- uint8_t *key_bytes;
8
-
9
- size_t output_length;
10
- uint8_t *output;
11
-
12
- VALUE to_hex;
13
- VALUE to_bytes;
14
- } Blake2;
15
-
16
- VALUE mDigest;
17
- VALUE mDigest_cBlake2;
18
-
19
- static void blake2_free(Blake2 *blake2) {
20
- free(blake2->key_bytes);
21
- free(blake2->output);
22
-
23
- rb_gc_mark(blake2->to_hex);
24
- rb_gc_mark(blake2->to_bytes);
25
-
26
- ruby_xfree(blake2);
27
- }
28
-
29
- static VALUE blake2_alloc(VALUE klass) {
30
- Blake2 *blake2_obj = (Blake2 *)ruby_xmalloc(sizeof(Blake2));
31
-
32
- return Data_Wrap_Struct(klass, NULL, blake2_free, blake2_obj);
33
- }
34
-
35
- VALUE m_blake2_initialize(VALUE self, VALUE _len, VALUE _key) {
36
- Blake2 *blake2;
37
- Data_Get_Struct(self, Blake2, blake2);
38
- unsigned int i;
39
-
40
- ID bytes_method = rb_intern("bytes");
41
- blake2->to_hex = ID2SYM(rb_intern("to_hex"));
42
- blake2->to_bytes = ID2SYM(rb_intern("to_bytes"));
43
-
44
- VALUE key_bytes_ary = rb_funcall(_key, bytes_method, 0);
45
- blake2->key_length = RARRAY_LEN(key_bytes_ary);
46
- blake2->key_bytes = (uint8_t*)malloc(blake2->key_length * sizeof(uint8_t));
47
-
48
- for(i = 0; i < blake2->key_length; i++) {
49
- VALUE byte = rb_ary_entry(key_bytes_ary, i);
50
- blake2->key_bytes[i] = NUM2INT(byte);
51
- }
52
-
53
- blake2->output_length = NUM2INT(_len);
54
- blake2->output = (uint8_t*)malloc(blake2->output_length * sizeof(uint8_t));
55
-
56
- return Qnil;
57
- }
58
-
59
-
60
- VALUE m_blake2_digest(VALUE self, VALUE _input, VALUE _representation) {
61
- Blake2 *blake2;
62
-
63
- char *input = RSTRING_PTR(_input);
64
- uint64_t input_length = RSTRING_LEN(_input);
65
- unsigned int i;
66
-
67
- Data_Get_Struct(self, Blake2, blake2);
68
-
69
- blake2b(blake2->output, blake2->output_length, input, input_length,
70
- blake2->key_bytes, blake2->key_length);
71
-
72
- VALUE result;
73
-
74
- if(_representation == blake2->to_bytes) {
75
- result = rb_ary_new2(blake2->output_length);
76
-
77
- for(i = 0; i < blake2->output_length; i++) {
78
- rb_ary_push(result, INT2NUM(blake2->output[i]));
79
- }
80
- } else if(_representation == blake2->to_hex) {
81
- unsigned long ary_len = blake2->output_length * (unsigned)sizeof(char) * 2;
82
- char *c_str = (char*)malloc(ary_len + 1);
83
-
84
- for(i = 0; i < blake2->output_length; i++) {
85
- sprintf(c_str + (i * 2), "%02x", blake2->output[i]);
86
- }
87
- c_str[ary_len] = 0;
88
-
89
- result = rb_str_new(c_str, ary_len);
90
-
91
- if((unsigned long)RSTRING_LEN(result) != ary_len) {
92
- rb_raise(rb_eRuntimeError, "m_blake2_digest: sizes don't match. Ary: %lu != %lu", RSTRING_LEN(result), ary_len);
93
- }
94
-
95
- free(c_str);
96
- } else {
97
- rb_raise(rb_eArgError, "unknown representation :%"PRIsVALUE"", _representation);
98
- }
99
-
100
- return result;
101
- }
102
-
103
- void Init_ref() {
104
- mDigest = rb_define_module("Digest");
105
-
106
- mDigest_cBlake2 = rb_define_class_under(mDigest, "Blake2b", rb_cObject);
107
- rb_define_alloc_func(mDigest_cBlake2, blake2_alloc);
108
-
109
- rb_define_private_method(mDigest_cBlake2, "initialize", RUBY_METHOD_FUNC(m_blake2_initialize), 2);
110
- rb_define_method(mDigest_cBlake2, "digest", RUBY_METHOD_FUNC(m_blake2_digest), 2);
111
- }
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'mkmf'
4
-
5
- $CFLAGS += ' -std=c99 -pedantic -Wall -Wextra -Wno-long-long'
6
-
7
- create_makefile 'digest/blake2b/sse'
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Digest
4
- class Blake2b
5
- if RUBY_PLATFORM =~ /^x86_64/
6
- IMPL = 'sse'
7
- else
8
- IMPL = 'ref'
9
- end
10
- end
11
- end