bcrypt4 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.travis.yml +16 -0
- data/CHANGELOG +87 -0
- data/COPYING +28 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +44 -0
- data/README.md +192 -0
- data/Rakefile +93 -0
- data/bcrypt4.gemspec +29 -0
- data/ext/jruby/bcrypt_jruby/BCrypt.java +752 -0
- data/ext/mri/bcrypt_ext.c +64 -0
- data/ext/mri/crypt.c +57 -0
- data/ext/mri/crypt.h +24 -0
- data/ext/mri/crypt_blowfish.c +907 -0
- data/ext/mri/crypt_blowfish.h +27 -0
- data/ext/mri/crypt_gensalt.c +124 -0
- data/ext/mri/crypt_gensalt.h +30 -0
- data/ext/mri/extconf.rb +16 -0
- data/ext/mri/ow-crypt.h +43 -0
- data/ext/mri/wrapper.c +271 -0
- data/lib/bcrypt/engine.rb +116 -0
- data/lib/bcrypt/error.rb +22 -0
- data/lib/bcrypt/password.rb +87 -0
- data/lib/bcrypt.rb +21 -0
- data/spec/TestBCrypt.java +194 -0
- data/spec/bcrypt/engine_spec.rb +105 -0
- data/spec/bcrypt/error_spec.rb +37 -0
- data/spec/bcrypt/password_spec.rb +124 -0
- data/spec/spec_helper.rb +2 -0
- metadata +132 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <ow-crypt.h>
|
3
|
+
|
4
|
+
static VALUE mBCrypt;
|
5
|
+
static VALUE cBCryptEngine;
|
6
|
+
|
7
|
+
/* Given a logarithmic cost parameter, generates a salt for use with +bc_crypt+.
|
8
|
+
*/
|
9
|
+
static VALUE bc_salt(VALUE self, VALUE prefix, VALUE count, VALUE input) {
|
10
|
+
char * salt;
|
11
|
+
VALUE str_salt;
|
12
|
+
|
13
|
+
salt = crypt_gensalt_ra(
|
14
|
+
StringValuePtr(prefix),
|
15
|
+
NUM2ULONG(count),
|
16
|
+
NIL_P(input) ? NULL : StringValuePtr(input),
|
17
|
+
NIL_P(input) ? 0 : RSTRING_LEN(input));
|
18
|
+
|
19
|
+
if(!salt) return Qnil;
|
20
|
+
|
21
|
+
str_salt = rb_str_new2(salt);
|
22
|
+
xfree(salt);
|
23
|
+
|
24
|
+
return str_salt;
|
25
|
+
}
|
26
|
+
|
27
|
+
/* Given a secret and a salt, generates a salted hash (which you can then store safely).
|
28
|
+
*/
|
29
|
+
static VALUE bc_crypt(VALUE self, VALUE key, VALUE setting) {
|
30
|
+
char * value;
|
31
|
+
void * data;
|
32
|
+
int size;
|
33
|
+
VALUE out;
|
34
|
+
|
35
|
+
data = NULL;
|
36
|
+
size = 0xDEADBEEF;
|
37
|
+
|
38
|
+
if(NIL_P(key) || NIL_P(setting)) return Qnil;
|
39
|
+
|
40
|
+
value = crypt_ra(
|
41
|
+
NIL_P(key) ? NULL : StringValuePtr(key),
|
42
|
+
NIL_P(setting) ? NULL : StringValuePtr(setting),
|
43
|
+
&data,
|
44
|
+
&size);
|
45
|
+
|
46
|
+
if(!value) return Qnil;
|
47
|
+
|
48
|
+
out = rb_str_new(data, size - 1);
|
49
|
+
|
50
|
+
xfree(data);
|
51
|
+
|
52
|
+
return out;
|
53
|
+
}
|
54
|
+
|
55
|
+
/* Create the BCrypt and BCrypt::Engine modules, and populate them with methods. */
|
56
|
+
void Init_bcrypt_ext(){
|
57
|
+
mBCrypt = rb_define_module("BCrypt");
|
58
|
+
cBCryptEngine = rb_define_class_under(mBCrypt, "Engine", rb_cObject);
|
59
|
+
|
60
|
+
rb_define_singleton_method(cBCryptEngine, "__bc_salt", bc_salt, 3);
|
61
|
+
rb_define_singleton_method(cBCryptEngine, "__bc_crypt", bc_crypt, 2);
|
62
|
+
}
|
63
|
+
|
64
|
+
/* vim: set noet sws=4 sw=4: */
|
data/ext/mri/crypt.c
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <ow-crypt.h>
|
3
|
+
|
4
|
+
VALUE mCrypt;
|
5
|
+
|
6
|
+
static VALUE crypt_salt(VALUE self, VALUE prefix, VALUE count, VALUE input)
|
7
|
+
{
|
8
|
+
char * salt;
|
9
|
+
VALUE str_salt;
|
10
|
+
|
11
|
+
salt = crypt_gensalt_ra(
|
12
|
+
StringValuePtr(prefix),
|
13
|
+
NUM2ULONG(count),
|
14
|
+
NIL_P(input) ? NULL : StringValuePtr(input),
|
15
|
+
NIL_P(input) ? 0 : RSTRING_LEN(input));
|
16
|
+
|
17
|
+
if(!salt) return Qnil;
|
18
|
+
|
19
|
+
str_salt = rb_str_new2(salt);
|
20
|
+
free(salt);
|
21
|
+
|
22
|
+
return str_salt;
|
23
|
+
}
|
24
|
+
|
25
|
+
static VALUE ra(VALUE self, VALUE key, VALUE setting)
|
26
|
+
{
|
27
|
+
char * value;
|
28
|
+
void * data;
|
29
|
+
int size;
|
30
|
+
VALUE out;
|
31
|
+
|
32
|
+
data = NULL;
|
33
|
+
size = 0xDEADBEEF;
|
34
|
+
|
35
|
+
if(NIL_P(key) || NIL_P(setting)) return Qnil;
|
36
|
+
|
37
|
+
value = crypt_ra(
|
38
|
+
NIL_P(key) ? NULL : StringValuePtr(key),
|
39
|
+
NIL_P(setting) ? NULL : StringValuePtr(setting),
|
40
|
+
&data,
|
41
|
+
&size);
|
42
|
+
|
43
|
+
if(!value) return Qnil;
|
44
|
+
|
45
|
+
out = rb_str_new(data, size - 1);
|
46
|
+
|
47
|
+
free(data);
|
48
|
+
|
49
|
+
return out;
|
50
|
+
}
|
51
|
+
|
52
|
+
void Init_crypt()
|
53
|
+
{
|
54
|
+
mCrypt = rb_define_module("Crypt");
|
55
|
+
rb_define_singleton_method(mCrypt, "salt", crypt_salt, 3);
|
56
|
+
rb_define_singleton_method(mCrypt, "crypt", ra, 2);
|
57
|
+
}
|
data/ext/mri/crypt.h
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
/*
|
2
|
+
* Written by Solar Designer <solar at openwall.com> in 2000-2002.
|
3
|
+
* No copyright is claimed, and the software is hereby placed in the public
|
4
|
+
* domain. In case this attempt to disclaim copyright and place the software
|
5
|
+
* in the public domain is deemed null and void, then the software is
|
6
|
+
* Copyright (c) 2000-2002 Solar Designer and it is hereby released to the
|
7
|
+
* general public under the following terms:
|
8
|
+
*
|
9
|
+
* Redistribution and use in source and binary forms, with or without
|
10
|
+
* modification, are permitted.
|
11
|
+
*
|
12
|
+
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
13
|
+
*
|
14
|
+
* See crypt_blowfish.c for more information.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#include <gnu-crypt.h>
|
18
|
+
|
19
|
+
#if defined(_OW_SOURCE) || defined(__USE_OW)
|
20
|
+
#define __SKIP_GNU
|
21
|
+
#undef __SKIP_OW
|
22
|
+
#include <ow-crypt.h>
|
23
|
+
#undef __SKIP_GNU
|
24
|
+
#endif
|