| OLD | NEW |
| 1 /* Modified by Rich Felker in for inclusion in musl libc, based on | 1 /* Modified by Rich Felker in for inclusion in musl libc, based on |
| 2 * Solar Designer's second size-optimized version sent to the musl | 2 * Solar Designer's second size-optimized version sent to the musl |
| 3 * mailing list. */ | 3 * mailing list. */ |
| 4 | 4 |
| 5 /* | 5 /* |
| 6 * The crypt_blowfish homepage is: | 6 * The crypt_blowfish homepage is: |
| 7 * | 7 * |
| 8 *» http://www.openwall.com/crypt/ | 8 * http://www.openwall.com/crypt/ |
| 9 * | 9 * |
| 10 * This code comes from John the Ripper password cracker, with reentrant | 10 * This code comes from John the Ripper password cracker, with reentrant |
| 11 * and crypt(3) interfaces added, but optimizations specific to password | 11 * and crypt(3) interfaces added, but optimizations specific to password |
| 12 * cracking removed. | 12 * cracking removed. |
| 13 * | 13 * |
| 14 * Written by Solar Designer <solar at openwall.com> in 1998-2012. | 14 * Written by Solar Designer <solar at openwall.com> in 1998-2012. |
| 15 * No copyright is claimed, and the software is hereby placed in the public | 15 * No copyright is claimed, and the software is hereby placed in the public |
| 16 * domain. In case this attempt to disclaim copyright and place the software | 16 * domain. In case this attempt to disclaim copyright and place the software |
| 17 * in the public domain is deemed null and void, then the software is | 17 * in the public domain is deemed null and void, then the software is |
| 18 * Copyright (c) 1998-2012 Solar Designer and it is hereby released to the | 18 * Copyright (c) 1998-2012 Solar Designer and it is hereby released to the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 33 * | 33 * |
| 34 * This implementation is mostly compatible with OpenBSD's bcrypt.c (prefix | 34 * This implementation is mostly compatible with OpenBSD's bcrypt.c (prefix |
| 35 * "$2a$") by Niels Provos <provos at citi.umich.edu>, and uses some of his | 35 * "$2a$") by Niels Provos <provos at citi.umich.edu>, and uses some of his |
| 36 * ideas. The password hashing algorithm was designed by David Mazieres | 36 * ideas. The password hashing algorithm was designed by David Mazieres |
| 37 * <dm at lcs.mit.edu>. For more information on the level of compatibility, | 37 * <dm at lcs.mit.edu>. For more information on the level of compatibility, |
| 38 * please refer to the comments in BF_set_key() below and to the included | 38 * please refer to the comments in BF_set_key() below and to the included |
| 39 * crypt(3) man page. | 39 * crypt(3) man page. |
| 40 * | 40 * |
| 41 * There's a paper on the algorithm that explains its design decisions: | 41 * There's a paper on the algorithm that explains its design decisions: |
| 42 * | 42 * |
| 43 *» http://www.usenix.org/events/usenix99/provos.html | 43 * http://www.usenix.org/events/usenix99/provos.html |
| 44 * | 44 * |
| 45 * Some of the tricks in BF_ROUND might be inspired by Eric Young's | 45 * Some of the tricks in BF_ROUND might be inspired by Eric Young's |
| 46 * Blowfish library (I can't be sure if I would think of something if I | 46 * Blowfish library (I can't be sure if I would think of something if I |
| 47 * hadn't seen his code). | 47 * hadn't seen his code). |
| 48 */ | 48 */ |
| 49 | 49 |
| 50 #include <string.h> | 50 #include <string.h> |
| 51 #include <stdint.h> | 51 #include <stdint.h> |
| 52 | 52 |
| 53 typedef uint32_t BF_word; | 53 typedef uint32_t BF_word; |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 static BF_word BF_encrypt(BF_ctx* ctx, | 363 static BF_word BF_encrypt(BF_ctx* ctx, |
| 364 BF_word L, | 364 BF_word L, |
| 365 BF_word R, | 365 BF_word R, |
| 366 BF_word* start, | 366 BF_word* start, |
| 367 BF_word* end) { | 367 BF_word* end) { |
| 368 BF_word tmp1, tmp2, tmp3, tmp4; | 368 BF_word tmp1, tmp2, tmp3, tmp4; |
| 369 BF_word* ptr = start; | 369 BF_word* ptr = start; |
| 370 | 370 |
| 371 do { | 371 do { |
| 372 L ^= ctx->s.P[0]; | 372 L ^= ctx->s.P[0]; |
| 373 #if 0 | |
| 374 BF_ROUND(L, R, 0); | |
| 375 BF_ROUND(R, L, 1); | |
| 376 BF_ROUND(L, R, 2); | |
| 377 BF_ROUND(R, L, 3); | |
| 378 BF_ROUND(L, R, 4); | |
| 379 BF_ROUND(R, L, 5); | |
| 380 BF_ROUND(L, R, 6); | |
| 381 BF_ROUND(R, L, 7); | |
| 382 BF_ROUND(L, R, 8); | |
| 383 BF_ROUND(R, L, 9); | |
| 384 BF_ROUND(L, R, 10); | |
| 385 BF_ROUND(R, L, 11); | |
| 386 BF_ROUND(L, R, 12); | |
| 387 BF_ROUND(R, L, 13); | |
| 388 BF_ROUND(L, R, 14); | |
| 389 BF_ROUND(R, L, 15); | |
| 390 #else | |
| 391 for (int i = 0; i < 16; i += 2) { | 373 for (int i = 0; i < 16; i += 2) { |
| 392 BF_ROUND(L, R, i); | 374 BF_ROUND(L, R, i); |
| 393 BF_ROUND(R, L, i + 1); | 375 BF_ROUND(R, L, i + 1); |
| 394 } | 376 } |
| 395 #endif | |
| 396 tmp4 = R; | 377 tmp4 = R; |
| 397 R = L; | 378 R = L; |
| 398 L = tmp4 ^ ctx->s.P[BF_N + 1]; | 379 L = tmp4 ^ ctx->s.P[BF_N + 1]; |
| 399 *ptr++ = L; | 380 *ptr++ = L; |
| 400 *ptr++ = R; | 381 *ptr++ = R; |
| 401 } while (ptr < end); | 382 } while (ptr < end); |
| 402 | 383 |
| 403 return L; | 384 return L; |
| 404 } | 385 } |
| 405 | 386 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 ai[0] ^= 0x10000; /* undo the safety (for comparison) */ | 677 ai[0] ^= 0x10000; /* undo the safety (for comparison) */ |
| 697 ok = ok && ai[0] == 0xdb9c59bc && ye[17] == 0x33343500 && | 678 ok = ok && ai[0] == 0xdb9c59bc && ye[17] == 0x33343500 && |
| 698 !memcmp(ae, ye, sizeof(ae)) && !memcmp(ai, yi, sizeof(ai)); | 679 !memcmp(ae, ye, sizeof(ae)) && !memcmp(ai, yi, sizeof(ai)); |
| 699 } | 680 } |
| 700 | 681 |
| 701 if (ok && retval) | 682 if (ok && retval) |
| 702 return retval; | 683 return retval; |
| 703 | 684 |
| 704 return "*"; | 685 return "*"; |
| 705 } | 686 } |
| OLD | NEW |