summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2016-09-10 15:55:57 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2016-09-10 15:55:57 +0000
commitfb1b521588396cb2b40be69dbd227b2477d72371 (patch)
tree381d7312699eed9655b388017936e4525dfeff67
parent1873de49bae0fdc3839a174bf8d952074310cc4a (diff)
Sync libsa pkcs5_pbkdf2() with libutil.
-rw-r--r--sys/lib/libsa/pbkdf2.c20
-rw-r--r--sys/lib/libsa/pbkdf2.h6
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);