diff options
Diffstat (limited to 'openbsd-compat/bcrypt_pbkdf.c')
-rw-r--r-- | openbsd-compat/bcrypt_pbkdf.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/openbsd-compat/bcrypt_pbkdf.c b/openbsd-compat/bcrypt_pbkdf.c index 16912575a..0a07f9a0f 100644 --- a/openbsd-compat/bcrypt_pbkdf.c +++ b/openbsd-compat/bcrypt_pbkdf.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bcrypt_pbkdf.c,v 1.9 2014/07/13 21:21:25 tedu Exp $ */ | 1 | /* $OpenBSD: bcrypt_pbkdf.c,v 1.13 2015/01/12 03:20:04 tedu Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2013 Ted Unangst <tedu@openbsd.org> | 3 | * Copyright (c) 2013 Ted Unangst <tedu@openbsd.org> |
4 | * | 4 | * |
@@ -37,6 +37,8 @@ | |||
37 | #endif | 37 | #endif |
38 | #define SHA512_DIGEST_LENGTH crypto_hash_sha512_BYTES | 38 | #define SHA512_DIGEST_LENGTH crypto_hash_sha512_BYTES |
39 | 39 | ||
40 | #define MINIMUM(a,b) (((a) < (b)) ? (a) : (b)) | ||
41 | |||
40 | /* | 42 | /* |
41 | * pkcs #5 pbkdf2 implementation using the "bcrypt" hash | 43 | * pkcs #5 pbkdf2 implementation using the "bcrypt" hash |
42 | * | 44 | * |
@@ -61,8 +63,8 @@ | |||
61 | * wise caller could do; we just do it for you. | 63 | * wise caller could do; we just do it for you. |
62 | */ | 64 | */ |
63 | 65 | ||
64 | #define BCRYPT_BLOCKS 8 | 66 | #define BCRYPT_WORDS 8 |
65 | #define BCRYPT_HASHSIZE (BCRYPT_BLOCKS * 4) | 67 | #define BCRYPT_HASHSIZE (BCRYPT_WORDS * 4) |
66 | 68 | ||
67 | static void | 69 | static void |
68 | bcrypt_hash(u_int8_t *sha2pass, u_int8_t *sha2salt, u_int8_t *out) | 70 | bcrypt_hash(u_int8_t *sha2pass, u_int8_t *sha2salt, u_int8_t *out) |
@@ -70,7 +72,7 @@ bcrypt_hash(u_int8_t *sha2pass, u_int8_t *sha2salt, u_int8_t *out) | |||
70 | blf_ctx state; | 72 | blf_ctx state; |
71 | u_int8_t ciphertext[BCRYPT_HASHSIZE] = | 73 | u_int8_t ciphertext[BCRYPT_HASHSIZE] = |
72 | "OxychromaticBlowfishSwatDynamite"; | 74 | "OxychromaticBlowfishSwatDynamite"; |
73 | uint32_t cdata[BCRYPT_BLOCKS]; | 75 | uint32_t cdata[BCRYPT_WORDS]; |
74 | int i; | 76 | int i; |
75 | uint16_t j; | 77 | uint16_t j; |
76 | size_t shalen = SHA512_DIGEST_LENGTH; | 78 | size_t shalen = SHA512_DIGEST_LENGTH; |
@@ -85,14 +87,14 @@ bcrypt_hash(u_int8_t *sha2pass, u_int8_t *sha2salt, u_int8_t *out) | |||
85 | 87 | ||
86 | /* encryption */ | 88 | /* encryption */ |
87 | j = 0; | 89 | j = 0; |
88 | for (i = 0; i < BCRYPT_BLOCKS; i++) | 90 | for (i = 0; i < BCRYPT_WORDS; i++) |
89 | cdata[i] = Blowfish_stream2word(ciphertext, sizeof(ciphertext), | 91 | cdata[i] = Blowfish_stream2word(ciphertext, sizeof(ciphertext), |
90 | &j); | 92 | &j); |
91 | for (i = 0; i < 64; i++) | 93 | for (i = 0; i < 64; i++) |
92 | blf_enc(&state, cdata, sizeof(cdata) / sizeof(uint64_t)); | 94 | blf_enc(&state, cdata, sizeof(cdata) / sizeof(uint64_t)); |
93 | 95 | ||
94 | /* copy out */ | 96 | /* copy out */ |
95 | for (i = 0; i < BCRYPT_BLOCKS; i++) { | 97 | for (i = 0; i < BCRYPT_WORDS; i++) { |
96 | out[4 * i + 3] = (cdata[i] >> 24) & 0xff; | 98 | out[4 * i + 3] = (cdata[i] >> 24) & 0xff; |
97 | out[4 * i + 2] = (cdata[i] >> 16) & 0xff; | 99 | out[4 * i + 2] = (cdata[i] >> 16) & 0xff; |
98 | out[4 * i + 1] = (cdata[i] >> 8) & 0xff; | 100 | out[4 * i + 1] = (cdata[i] >> 8) & 0xff; |
@@ -156,9 +158,9 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const u_int8_t *salt, size_t salt | |||
156 | } | 158 | } |
157 | 159 | ||
158 | /* | 160 | /* |
159 | * pbkdf2 deviation: ouput the key material non-linearly. | 161 | * pbkdf2 deviation: output the key material non-linearly. |
160 | */ | 162 | */ |
161 | amt = MIN(amt, keylen); | 163 | amt = MINIMUM(amt, keylen); |
162 | for (i = 0; i < amt; i++) { | 164 | for (i = 0; i < amt; i++) { |
163 | size_t dest = i * stride + (count - 1); | 165 | size_t dest = i * stride + (count - 1); |
164 | if (dest >= origkeylen) | 166 | if (dest >= origkeylen) |