fastpbkdf2 0.0.1 → 0.1.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: 986b8e83bd6d157efa281fcb0e5f137153a3e67c
4
- data.tar.gz: 34841f44f77a35343122ae7891f8083febf68bfc
3
+ metadata.gz: 16883f21fbcfd33359a5aefb025f342b98a2c6da
4
+ data.tar.gz: 9b5f6000d448b714c4d4eb2866e773edc6c9e6fe
5
5
  SHA512:
6
- metadata.gz: a7a9ea8322183fe84df4037a04e9ea1c6ef2cd3a1abc218e22f0da94a3f20b934c0d8adf5a9803adb4ac7eeae4aa61a7e2f067ccf52091d08769cfaa9b6fbadd
7
- data.tar.gz: a119f1e7cb847e3a1674d37b759be06db62d0dd3925fd2c9079782a6d1ff96e190dc28bbbfb74a777da694186d993b650aa6dcbe57562f8bbdd953fdcb36a733
6
+ metadata.gz: 8390afdeded31598004738bbcd9455c2622c66a7cbb7fd811f6e1fb74ae95ede7be34138d11bce37adf928793c7a83187636abe012e1a9e76ad95a61a042af31
7
+ data.tar.gz: 1b3e26a44bb4aaf41f8bd88ddd618ba7dcea518363de3fe9b7abebbc35f3a82a933583461cb2aac0750e1325ec5b3a0dc322e1c832e7725be210a9d7f781cab5
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rake/extensiontask'
2
2
 
3
- spec = Gem::Specification.load('fastpbkdf2.gemspec')
3
+ spec = Gem::Specification.load('.gemspec')
4
4
  Rake::ExtensionTask.new('fastpbkdf2_native', spec)
5
5
 
6
6
  require 'rake/testtask'
@@ -9,3 +9,5 @@ Rake::TestTask.new do |t|
9
9
  t.test_files = FileList['test/ruby/test*.rb']
10
10
  t.verbose = true
11
11
  end
12
+
13
+ task :default => :compile
@@ -3,52 +3,55 @@
3
3
 
4
4
  static VALUE fastpbkdf2;
5
5
 
6
- static VALUE Sha1(VALUE self, VALUE _pw, VALUE _salt, VALUE _iterations, VALUE _keylen) {
7
- uint8_t *pw = NULL, *salt = NULL;
8
- size_t npw, nsalt;
9
- unsigned int iterations, keylen;
10
- unsigned char out[2048] = {0};
11
- VALUE result;
12
-
13
- Check_Type(_pw, T_STRING);
14
- pw = (unsigned char*) RSTRING_PTR(_pw);
15
- npw = RSTRING_LEN(_pw);
16
- if (npw > 1024) {
17
- rb_raise(rb_eRangeError, "password length must be between 0 and 1024");
18
- }
19
- // printf("pw: %s\n", pw);
20
-
21
- Check_Type(_salt, T_STRING);
22
- salt = (unsigned char*) RSTRING_PTR(_salt);
23
- nsalt = RSTRING_LEN(_salt);
24
- if (nsalt > 1024) {
25
- rb_raise(rb_eRangeError, "salt length must be between 0 and 1024");
26
- }
27
- // printf("salt: %s\n", salt);
28
-
29
- Check_Type(_iterations, T_FIXNUM);
30
- iterations = NUM2ULL(_iterations);
31
- if (iterations <= 0) {
32
- rb_raise(rb_eRangeError, "iterations must be greater than 0");
33
- }
34
- // printf("iterations: %d\n", iterations);
35
-
36
- Check_Type(_keylen, T_FIXNUM);
37
- keylen = NUM2ULL(_keylen);
38
- if (keylen <= 0 || keylen > 1024) {
39
- rb_raise(rb_eRangeError, "keylen must be between 1 and 1024");
40
- }
41
- // printf("keylen: %d\n", keylen);
42
-
43
- fastpbkdf2_hmac_sha1(pw, npw, salt, nsalt, iterations, out, keylen);
44
-
45
- result = rb_str_new(out, keylen);
46
-
47
- return result;
6
+ #define DECL(ALGORITHM) \
7
+ static VALUE ALGORITHM(VALUE self, VALUE _pw, VALUE _salt, VALUE _iterations, VALUE _keylen) {\
8
+ uint8_t *pw = NULL, *salt = NULL;\
9
+ size_t npw, nsalt;\
10
+ unsigned int iterations, keylen;\
11
+ unsigned char out[2048];\
12
+ VALUE result;\
13
+ \
14
+ Check_Type(_pw, T_STRING);\
15
+ pw = (uint8_t*) RSTRING_PTR(_pw);\
16
+ npw = RSTRING_LEN(_pw);\
17
+ if (npw > 1024) {\
18
+ rb_raise(rb_eRangeError, "password length must be between 0 and 1024");\
19
+ }\
20
+ \
21
+ Check_Type(_salt, T_STRING);\
22
+ salt = (uint8_t*) RSTRING_PTR(_salt);\
23
+ nsalt = RSTRING_LEN(_salt);\
24
+ if (nsalt > 1024) {\
25
+ rb_raise(rb_eRangeError, "salt length must be between 0 and 1024");\
26
+ }\
27
+ \
28
+ Check_Type(_iterations, T_FIXNUM);\
29
+ iterations = NUM2ULL(_iterations);\
30
+ if (iterations <= 0) {\
31
+ rb_raise(rb_eRangeError, "iterations must be greater than 0");\
32
+ }\
33
+ \
34
+ Check_Type(_keylen, T_FIXNUM);\
35
+ keylen = NUM2ULL(_keylen);\
36
+ if (keylen <= 0 || keylen > 1024) {\
37
+ rb_raise(rb_eRangeError, "keylen must be between 1 and 1024");\
38
+ }\
39
+ \
40
+ fastpbkdf2_hmac_##ALGORITHM(pw, npw, salt, nsalt, iterations, out, keylen);\
41
+ \
42
+ result = rb_str_new((char *)out, keylen);\
43
+ \
44
+ return result;\
48
45
  }
49
46
 
47
+ DECL(sha1)
48
+ DECL(sha256)
49
+ DECL(sha512)
50
+
50
51
  void Init_fastpbkdf2_native(void) {
51
52
  fastpbkdf2 = rb_define_module("Fastpbkdf2");
52
53
 
53
- rb_define_module_function(fastpbkdf2, "sha1", Sha1, 4);
54
+ rb_define_module_function(fastpbkdf2, "sha1", sha1, 4);
55
+ rb_define_module_function(fastpbkdf2, "sha256", sha256, 4);
56
+ rb_define_module_function(fastpbkdf2, "sha512", sha512, 4);
54
57
  }
data/lib/fastpbkdf2.rb CHANGED
@@ -1,14 +1 @@
1
- require 'fastpbkdf2_native'
2
-
3
- #"\x0c\x60\xc8\x0f\x96\x1f\x0e\x71\xf3\xa9\xb5\x24\xaf\x60\x12\x06\x2f\xe0\x37\xa6"
4
-
5
-
6
- # class LZ4
7
- # def self.compress(source)
8
- # return LZ4Native::compress(source)
9
- # end
10
-
11
- # def self.uncompress(source)
12
- # return LZ4Native::uncompress(source)
13
- # end
14
- # end
1
+ require 'fastpbkdf2_native'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastpbkdf2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - S-YOU
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-26 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler