bcrypt_pbkdf 1.0.0.alpha1-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +3 -0
- data/COPYING +23 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +36 -0
- data/README.md +15 -0
- data/Rakefile +68 -0
- data/bcrypt_pbkdf.gemspec +30 -0
- data/ext/mri/bcrypt_pbkdf.c +169 -0
- data/ext/mri/bcrypt_pbkdf_ext.c +44 -0
- data/ext/mri/blf.h +90 -0
- data/ext/mri/blowfish.c +698 -0
- data/ext/mri/crypto_api.h +3 -0
- data/ext/mri/crypto_hash_sha512.h +19 -0
- data/ext/mri/explicit_bzero.c +20 -0
- data/ext/mri/extconf.rb +3 -0
- data/ext/mri/hash_sha512.c +320 -0
- data/ext/mri/includes.h +27 -0
- data/ext/mri/sha2.h +13 -0
- data/ext/mri/util.h +0 -0
- data/ext/mri/utils.h +5 -0
- data/lib/2.0/bcrypt_pbkdf_ext.so +0 -0
- data/lib/2.1/bcrypt_pbkdf_ext.so +0 -0
- data/lib/2.2/bcrypt_pbkdf_ext.so +0 -0
- data/lib/2.3/bcrypt_pbkdf_ext.so +0 -0
- data/lib/bcrypt_pbkdf.rb +24 -0
- data/test/bcrypt_pnkdf/engine_test.rb +78 -0
- data/test/test_helper.rb +2 -0
- metadata +166 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
# bcrypt_pbkdf in ruby using libsodium
|
5
|
+
require 'rbnacl/libsodium'
|
6
|
+
require 'rbnacl'
|
7
|
+
require 'rbnacl/hash'
|
8
|
+
|
9
|
+
BCRYPT_BLOCKS = 8
|
10
|
+
BCRYPT_HASHSIZE = BCRYPT_BLOCKS * 4
|
11
|
+
|
12
|
+
def bcrypt_pbkdf(password, salt, keylen, rounds)
|
13
|
+
stride = (keylen + BCRYPT_HASHSIZE - 1) / BCRYPT_HASHSIZE
|
14
|
+
amt = (keylen + stride - 1) / stride
|
15
|
+
|
16
|
+
sha2pass = RbNaCl::Hash.sha512(password)
|
17
|
+
#puts "[RB] sha2pass:#{sha2pass.inspect} #{sha2pass.size}"
|
18
|
+
|
19
|
+
remlen = keylen
|
20
|
+
|
21
|
+
countsalt = salt + "\x00"*4
|
22
|
+
saltlen = salt.size
|
23
|
+
|
24
|
+
key = "\x00"*keylen
|
25
|
+
|
26
|
+
# generate key in BCRYPT_HASHSIZE pieces
|
27
|
+
count = 1
|
28
|
+
while remlen > 0
|
29
|
+
countsalt[saltlen + 0] = ((count >> 24) & 0xff).chr
|
30
|
+
countsalt[saltlen + 1] = ((count >> 16) & 0xff).chr
|
31
|
+
countsalt[saltlen + 2] = ((count >> 8) & 0xff).chr
|
32
|
+
countsalt[saltlen + 3] = (count & 0xff).chr
|
33
|
+
#puts "[RC] countsalt: #{countsalt.inspect} len:#{countsalt.size}"
|
34
|
+
|
35
|
+
sha2salt = RbNaCl::Hash.sha512(countsalt)
|
36
|
+
tmpout = BCryptPbkdf::Engine::__bc_crypt_hash(sha2pass, sha2salt)
|
37
|
+
out = tmpout.clone
|
38
|
+
|
39
|
+
#puts "[RB] out: #{out.inspect} keylen:#{remlen} count:#{count}"
|
40
|
+
(1...rounds).each do |i|
|
41
|
+
sha2salt = RbNaCl::Hash.sha512(tmpout)
|
42
|
+
tmpout = BCryptPbkdf::Engine::__bc_crypt_hash(sha2pass, sha2salt)
|
43
|
+
out.bytes.each_with_index {|o,j| out.setbyte(j,o ^ tmpout[j].ord) }
|
44
|
+
end
|
45
|
+
|
46
|
+
amt = [amt, remlen].min
|
47
|
+
(0...amt).each do |i|
|
48
|
+
dest = i * stride + (count - 1)
|
49
|
+
key[dest] = out[i] if (dest < keylen)
|
50
|
+
end
|
51
|
+
|
52
|
+
remlen -= amt
|
53
|
+
count += 1
|
54
|
+
end
|
55
|
+
key
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
class TestExt < MiniTest::Unit::TestCase
|
60
|
+
def test_table
|
61
|
+
assert_equal table, table.map{ |p,s,l,r| [p,s,l,r,BCryptPbkdf::Engine::__bc_crypt_pbkdf(p,s,l,r).bytes] }
|
62
|
+
end
|
63
|
+
def test_ruby_and_native_returns_the_same
|
64
|
+
table.each do |p,s,l,r|
|
65
|
+
assert_equal bcrypt_pbkdf(p,s,l,r), BCryptPbkdf::Engine::__bc_crypt_pbkdf(p,s,l,r)
|
66
|
+
assert_equal bcrypt_pbkdf(p,s,l,r), BCryptPbkdf::key(p,s,l,r)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def table
|
72
|
+
[
|
73
|
+
["pass2", "salt2", 12, 2, [214, 14, 48, 162, 131, 206, 121, 176, 50, 104, 231, 252]],
|
74
|
+
["\u0000\u0001foo", "\u0001\u0002fooo3", 14, 5, [46, 189, 32, 185, 94, 85, 232, 10, 84, 26, 44, 161, 49, 126]],
|
75
|
+
["doozoasd", "fooo$AS!", 14, 22, [57, 62, 50, 107, 70, 155, 65, 5, 129, 211, 189, 169, 188, 65]]
|
76
|
+
]
|
77
|
+
end
|
78
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bcrypt_pbkdf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.alpha1
|
5
|
+
platform: x64-mingw32
|
6
|
+
authors:
|
7
|
+
- Miklos Fazekas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake-compiler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.7
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rbnacl
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rbnacl-libsodium
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.8
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.0.8
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rdoc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.12'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.12'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake-compiler-dock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.5.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.5.0
|
97
|
+
description: " This gem implements bcrypt_pdkfd (a variant of PBKDF2 with bcrypt-based
|
98
|
+
PRF)\n"
|
99
|
+
email: mfazekas@szemafor.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files:
|
103
|
+
- README.md
|
104
|
+
- COPYING
|
105
|
+
- CHANGELOG.md
|
106
|
+
- lib/bcrypt_pbkdf.rb
|
107
|
+
files:
|
108
|
+
- ".travis.yml"
|
109
|
+
- CHANGELOG.md
|
110
|
+
- COPYING
|
111
|
+
- Gemfile
|
112
|
+
- Gemfile.lock
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- bcrypt_pbkdf.gemspec
|
116
|
+
- ext/mri/bcrypt_pbkdf.c
|
117
|
+
- ext/mri/bcrypt_pbkdf_ext.c
|
118
|
+
- ext/mri/blf.h
|
119
|
+
- ext/mri/blowfish.c
|
120
|
+
- ext/mri/crypto_api.h
|
121
|
+
- ext/mri/crypto_hash_sha512.h
|
122
|
+
- ext/mri/explicit_bzero.c
|
123
|
+
- ext/mri/extconf.rb
|
124
|
+
- ext/mri/hash_sha512.c
|
125
|
+
- ext/mri/includes.h
|
126
|
+
- ext/mri/sha2.h
|
127
|
+
- ext/mri/util.h
|
128
|
+
- ext/mri/utils.h
|
129
|
+
- lib/2.0/bcrypt_pbkdf_ext.so
|
130
|
+
- lib/2.1/bcrypt_pbkdf_ext.so
|
131
|
+
- lib/2.2/bcrypt_pbkdf_ext.so
|
132
|
+
- lib/2.3/bcrypt_pbkdf_ext.so
|
133
|
+
- lib/bcrypt_pbkdf.rb
|
134
|
+
- test/bcrypt_pnkdf/engine_test.rb
|
135
|
+
- test/test_helper.rb
|
136
|
+
homepage: https://github.com/mfazekas/bcrypt_pbkdf-ruby
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options:
|
142
|
+
- "--title"
|
143
|
+
- bcrypt_pbkdf
|
144
|
+
- "--line-numbers"
|
145
|
+
- "--inline-source"
|
146
|
+
- "--main"
|
147
|
+
- README.md
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 1.3.1
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 2.5.1
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: OpenBSD's bcrypt_pdkfd (a variant of PBKDF2 with bcrypt-based PRF)
|
166
|
+
test_files: []
|