Commit e61acd33cc691daece9560ddd9e2367cfc31fab9
* Fixed a whole bunch of gcc warnings.
* Got rid of bcrypt.h, in favor of just declaring the prototypes in bcrypt_ext.c. git-svn-id: http://bcrypt-ruby.rubyforge.org/svn/trunk@5 b1e0f299-433e-4bb3-9895-84128a6cfb6acodahale committed on 2/27/2007, 8:47:48 PM
Parent: 271e1130133565a49a6056ea4947369569cb9701
Files changed
ext/bcrypt.c | changed |
ext/bcrypt_ext.c | changed |
ext/extconf.rb | changed |
ext/bcrypt.h | deleted |
ext/bcrypt.c | ||
---|---|---|
@@ -52,15 +52,58 @@ | ||
52 | 52 … | * 6. RETURN Concatenate (salt, ctext); |
53 | 53 … | * |
54 | 54 … | */ |
55 | 55 … | |
56 … | + | |
56 | 57 … | |
58 … | + | |
59 … | + | |
60 … | + | |
57 | 61 … | |
58 | 62 … | |
59 | 63 … | |
60 | 64 … | |
61 | - | |
62 | 65 … | |
66 … | +/* This implementation is adaptable to current computing power. | |
67 … | + * You can have up to 2^31 rounds which should be enough for some | |
68 … | + * time to come. | |
69 … | + */ | |
70 … | + | |
71 … | + | |
72 … | + | |
73 … | + | |
74 … | + | |
75 … | + | |
76 … | +char *bcrypt_gensalt(u_int8_t, u_int8_t *); | |
77 … | + | |
78 … | +static void encode_salt(char *, u_int8_t *, u_int16_t, u_int8_t); | |
79 … | +static void encode_base64(u_int8_t *, u_int8_t *, u_int16_t); | |
80 … | +static void decode_base64(u_int8_t *, u_int16_t, u_int8_t *); | |
81 … | + | |
82 … | +static char encrypted[_PASSWORD_LEN]; | |
83 … | +static char gsalt[7 + (BCRYPT_MAXSALT * 4 + 2) / 3 + 1]; | |
84 … | +static char error[] = ":"; | |
85 … | + | |
86 … | +const static u_int8_t Base64Code[] = | |
87 … | +"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
88 … | + | |
89 … | +const static u_int8_t index_64[128] = { | |
90 … | + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
91 … | + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
92 … | + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
93 … | + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
94 … | + 255, 255, 255, 255, 255, 255, 0, 1, 54, 55, | |
95 … | + 56, 57, 58, 59, 60, 61, 62, 63, 255, 255, | |
96 … | + 255, 255, 255, 255, 255, 2, 3, 4, 5, 6, | |
97 … | + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, | |
98 … | + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, | |
99 … | + 255, 255, 255, 255, 255, 255, 28, 29, 30, | |
100 … | + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, | |
101 … | + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, | |
102 … | + 51, 52, 53, 255, 255, 255, 255, 255 | |
103 … | +}; | |
104 … | + | |
105 … | + | |
63 | 106 … | static void |
64 | 107 … | decode_base64(u_int8_t *buffer, u_int16_t len, u_int8_t *data) |
65 | 108 … | { |
66 | 109 … | u_int8_t *bp = buffer; |
@@ -258,4 +301,34 @@ | ||
258 | 301 … | *bp++ = Base64Code[c2 & 0x3f]; |
259 | 302 … | } |
260 | 303 … | *bp = '\0'; |
261 | 304 … | } |
305 … | + | |
306 … | +void | |
307 … | +main() | |
308 … | +{ | |
309 … | + char blubber[73]; | |
310 … | + char salt[100]; | |
311 … | + char *p; | |
312 … | + salt[0] = '$'; | |
313 … | + salt[1] = BCRYPT_VERSION; | |
314 … | + salt[2] = '$'; | |
315 … | + | |
316 … | + snprintf(salt + 3, 4, "%2.2u$", 5); | |
317 … | + | |
318 … | + printf("24 bytes of salt: "); | |
319 … | + fgets(salt + 6, sizeof(salt) - 6, stdin); | |
320 … | + salt[99] = 0; | |
321 … | + printf("72 bytes of password: "); | |
322 … | + fpurge(stdin); | |
323 … | + fgets(blubber, sizeof(blubber), stdin); | |
324 … | + blubber[72] = 0; | |
325 … | + | |
326 … | + p = crypt(blubber, salt); | |
327 … | + printf("Passwd entry: %s\n\n", p); | |
328 … | + | |
329 … | + p = bcrypt_gensalt(5); | |
330 … | + printf("Generated salt: %s\n", p); | |
331 … | + p = crypt(blubber, p); | |
332 … | + printf("Passwd entry: %s\n", p); | |
333 … | +} | |
334 … | + |
ext/bcrypt_ext.c | ||
---|---|---|
@@ -1,7 +1,9 @@ | ||
1 | 1 … | |
2 | - | |
3 | 2 … | |
3 … | +char *bcrypt_gensalt(u_int8_t, u_int8_t *); | |
4 … | +char *bcrypt(const char *, const char *); | |
5 … | + | |
4 | 6 … | VALUE mBCrypt; |
5 | 7 … | VALUE mBCryptInternals; |
6 | 8 … | |
7 | 9 … | /* Given a logarithmic cost parameter, generates a salt for use with +bc_crypt+. |
@@ -12,9 +14,9 @@ | ||
12 | 14 … | |
13 | 15 … | /* Given a secret and a salt, generates a salted hash (which you can then store safely). |
14 | 16 … | */ |
15 | 17 … | static VALUE bc_crypt(VALUE self, VALUE key, VALUE salt) { |
16 | - return rb_str_new2((char *)bcrypt(RSTRING(key)->ptr, RSTRING(salt)->ptr)); | |
18 … | + return rb_str_new2((char *)bcrypt(RSTRING(key)->ptr, (char *)RSTRING(salt)->ptr)); | |
17 | 19 … | } |
18 | 20 … | |
19 | 21 … | /* Create the BCrypt and BCrypt::Internals modules, and populate them with methods. */ |
20 | 22 … | void Init_bcrypt_ext(){ |
ext/extconf.rb | ||
---|---|---|
@@ -1,3 +1,5 @@ | ||
1 | 1 … | require "mkmf" |
2 | 2 … | dir_config("bcrypt_ext") |
3 … | +# enable this when we're feeling nitpicky | |
4 … | +# CONFIG['CC'] << " -Wall " | |
3 | 5 … | create_makefile("bcrypt_ext") |
ext/bcrypt.h | ||
---|---|---|
@@ -1,45 +1,0 @@ | ||
1 | - | |
2 | - | |
3 | - | |
4 | - | |
5 | - | |
6 | - | |
7 | -/* This implementation is adaptable to current computing power. | |
8 | - * You can have up to 2^31 rounds which should be enough for some | |
9 | - * time to come. | |
10 | - */ | |
11 | - | |
12 | - | |
13 | - | |
14 | - | |
15 | - | |
16 | - | |
17 | -char *bcrypt_gensalt(u_int8_t, u_int8_t *); | |
18 | - | |
19 | -static void encode_salt(char *, u_int8_t *, u_int16_t, u_int8_t); | |
20 | -static void encode_base64(u_int8_t *, u_int8_t *, u_int16_t); | |
21 | -static void decode_base64(u_int8_t *, u_int16_t, u_int8_t *); | |
22 | - | |
23 | -static char encrypted[_PASSWORD_LEN]; | |
24 | -static char gsalt[7 + (BCRYPT_MAXSALT * 4 + 2) / 3 + 1]; | |
25 | -static char error[] = ":"; | |
26 | - | |
27 | -const static u_int8_t Base64Code[] = | |
28 | -"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
29 | - | |
30 | -const static u_int8_t index_64[128] = { | |
31 | - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
32 | - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
33 | - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
34 | - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | |
35 | - 255, 255, 255, 255, 255, 255, 0, 1, 54, 55, | |
36 | - 56, 57, 58, 59, 60, 61, 62, 63, 255, 255, | |
37 | - 255, 255, 255, 255, 255, 2, 3, 4, 5, 6, | |
38 | - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, | |
39 | - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, | |
40 | - 255, 255, 255, 255, 255, 255, 28, 29, 30, | |
41 | - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, | |
42 | - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, | |
43 | - 51, 52, 53, 255, 255, 255, 255, 255 | |
44 | -}; | |
45 | - |
Built with git-ssb-web