git ssb

0+

dangerousbeans / %aPBe2k3ugtjBr4rrsU1…



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-84128a6cfb6a
codahale committed on 2/27/2007, 8:47:48 PM
Parent: 271e1130133565a49a6056ea4947369569cb9701

Files changed

ext/bcrypt.cchanged
ext/bcrypt_ext.cchanged
ext/extconf.rbchanged
ext/bcrypt.hdeleted
ext/bcrypt.cView
@@ -52,15 +52,58 @@
5252 * 6. RETURN Concatenate (salt, ctext);
5353 *
5454 */
5555
56 +#if 0
5657 #include <stdio.h>
58 +#endif
59 +
60 +#include <stdio.h>
5761 #include <stdlib.h>
5862 #include <sys/types.h>
5963 #include <string.h>
6064 #include "blf.h"
61-#include "bcrypt.h"
6265
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 +#define BCRYPT_VERSION '2'
72 +#define BCRYPT_MAXSALT 16 /* Precomputation is just so nice */
73 +#define BCRYPT_BLOCKS 6 /* Ciphertext blocks */
74 +#define BCRYPT_MINROUNDS 16 /* we have log2(rounds) in salt */
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 +#define CHAR64(c) ( (c) > 127 ? 255 : index_64[(c)])
105 +
63106 static void
64107 decode_base64(u_int8_t *buffer, u_int16_t len, u_int8_t *data)
65108 {
66109 u_int8_t *bp = buffer;
@@ -258,4 +301,34 @@
258301 *bp++ = Base64Code[c2 & 0x3f];
259302 }
260303 *bp = '\0';
261304 }
305 +#if 0
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 +#endif
ext/bcrypt_ext.cView
@@ -1,7 +1,9 @@
11 #include "ruby.h"
2-#include "bcrypt.h"
32
3 +char *bcrypt_gensalt(u_int8_t, u_int8_t *);
4 +char *bcrypt(const char *, const char *);
5 +
46 VALUE mBCrypt;
57 VALUE mBCryptInternals;
68
79 /* Given a logarithmic cost parameter, generates a salt for use with +bc_crypt+.
@@ -12,9 +14,9 @@
1214
1315 /* Given a secret and a salt, generates a salted hash (which you can then store safely).
1416 */
1517 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));
1719 }
1820
1921 /* Create the BCrypt and BCrypt::Internals modules, and populate them with methods. */
2022 void Init_bcrypt_ext(){
ext/extconf.rbView
@@ -1,3 +1,5 @@
11 require "mkmf"
22 dir_config("bcrypt_ext")
3 +# enable this when we're feeling nitpicky
4 +# CONFIG['CC'] << " -Wall "
35 create_makefile("bcrypt_ext")
ext/bcrypt.hView
@@ -1,45 +1,0 @@
1-#include <stdio.h>
2-#include <stdlib.h>
3-#include <sys/types.h>
4-#include <string.h>
5-#include "blf.h"
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-#define BCRYPT_VERSION '2'
13-#define BCRYPT_MAXSALT 16 /* Precomputation is just so nice */
14-#define BCRYPT_BLOCKS 6 /* Ciphertext blocks */
15-#define BCRYPT_MINROUNDS 16 /* we have log2(rounds) in salt */
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-#define CHAR64(c) ( (c) > 127 ? 255 : index_64[(c)])

Built with git-ssb-web