diff options
author | 2016-09-10 15:55:56 +0000 | |
---|---|---|
committer | 2016-09-10 15:55:56 +0000 | |
commit | 362ad6b70c190b0df1324d0ab8d615e6821b6ef9 (patch) | |
tree | 85fed1d76c86af3b057a1bf4089a74b7db08ac78 | |
parent | Ensure that install_files() returns successful if the _tmpsrc (diff) | |
download | wireguard-openbsd-362ad6b70c190b0df1324d0ab8d615e6821b6ef9.tar.xz wireguard-openbsd-362ad6b70c190b0df1324d0ab8d615e6821b6ef9.zip |
Sync libsa pkcs5_pbkdf2() with libutil.
-rw-r--r-- | sys/lib/libsa/pbkdf2.c | 20 | ||||
-rw-r--r-- | sys/lib/libsa/pbkdf2.h | 6 |
2 files changed, 14 insertions, 12 deletions
diff --git a/sys/lib/libsa/pbkdf2.c b/sys/lib/libsa/pbkdf2.c index 16cacef5633..1bfcda9e04c 100644 --- a/sys/lib/libsa/pbkdf2.c +++ b/sys/lib/libsa/pbkdf2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pbkdf2.c,v 1.2 2015/09/02 01:52:26 yasuoka Exp $ */ +/* $OpenBSD: pbkdf2.c,v 1.3 2016/09/10 15:55:56 jsing Exp $ */ /*- * Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr> @@ -23,23 +23,25 @@ #include "pbkdf2.h" #include "hmac_sha1.h" +#define MINIMUM(a,b) (((a) < (b)) ? (a) : (b)) + /* * Password-Based Key Derivation Function 2 (PKCS #5 v2.0). * Code based on IEEE Std 802.11-2007, Annex H.4.2. */ int -pkcs5_pbkdf2(const char *pass, size_t pass_len, const char *salt, - size_t salt_len, u_int8_t *key, size_t key_len, u_int rounds) +pkcs5_pbkdf2(const char *pass, size_t pass_len, const uint8_t *salt, + size_t salt_len, uint8_t *key, size_t key_len, unsigned int rounds) { - u_int8_t *asalt, obuf[SHA1_DIGEST_LENGTH]; - u_int8_t d1[SHA1_DIGEST_LENGTH], d2[SHA1_DIGEST_LENGTH]; - u_int i, j; - u_int count; + uint8_t *asalt, obuf[SHA1_DIGEST_LENGTH]; + uint8_t d1[SHA1_DIGEST_LENGTH], d2[SHA1_DIGEST_LENGTH]; + unsigned int i, j; + unsigned int count; size_t r; if (rounds < 1 || key_len == 0) return -1; - if (salt_len == 0 || salt_len > SIZE_MAX - 1) + if (salt_len == 0 || salt_len > SIZE_MAX - 4) return -1; if ((asalt = alloc(salt_len + 4)) == NULL) return -1; @@ -61,7 +63,7 @@ pkcs5_pbkdf2(const char *pass, size_t pass_len, const char *salt, obuf[j] ^= d1[j]; } - r = MIN(key_len, SHA1_DIGEST_LENGTH); + r = MINIMUM(key_len, SHA1_DIGEST_LENGTH); memcpy(key, obuf, r); key += r; key_len -= r; diff --git a/sys/lib/libsa/pbkdf2.h b/sys/lib/libsa/pbkdf2.h index 6c292cf8f41..4f5c8cfc32b 100644 --- a/sys/lib/libsa/pbkdf2.h +++ b/sys/lib/libsa/pbkdf2.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pbkdf2.h,v 1.1 2012/10/09 12:36:50 jsing Exp $ */ +/* $OpenBSD: pbkdf2.h,v 1.2 2016/09/10 15:55:56 jsing Exp $ */ /*- * Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr> @@ -20,5 +20,5 @@ * Password-Based Key Derivation Function 2 (PKCS #5 v2.0). * Code based on IEEE Std 802.11-2007, Annex H.4.2. */ -int pkcs5_pbkdf2(const char *, size_t, const char *, size_t, - u_int8_t *, size_t, u_int); +int pkcs5_pbkdf2(const char *, size_t, const uint8_t *, size_t, + uint8_t *, size_t, unsigned int); |