summaryrefslogtreecommitdiffstats
path: root/test/evp_test.c
diff options
context:
space:
mode:
authorPéter Budai <buc@peterbudai.eu>2016-10-11 19:26:23 +0200
committerRich Salz <rsalz@openssl.org>2017-03-17 08:47:11 -0400
commitfa013b65241dfed9b7d9e10e0adfedc9869c797e (patch)
tree484147798c49c20544b9d79bb71146ed21b9557d /test/evp_test.c
parent9998b32cb63b0bdd3d014abfa1d70e9a2c20a283 (diff)
Fixed PKCS5_PBKDF2_HMAC() to adhere to the documentation.
The documentation of this function states that the password parameter can be NULL. However, the implementation returns an error in this case due to the inner workings of the HMAC_Init_ex() function. With this change, NULL password will be treated as an empty string and PKCS5_PBKDF2_HMAC() no longer fails on this input. I have also added two new test cases that tests the handling of the special values NULL and -1 of the password and passlen parameters, respectively. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/1692)
Diffstat (limited to 'test/evp_test.c')
-rw-r--r--test/evp_test.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/test/evp_test.c b/test/evp_test.c
index d924e3f6fc..f9dafec23a 100644
--- a/test/evp_test.c
+++ b/test/evp_test.c
@@ -127,6 +127,8 @@ static int test_bin(const char *value, unsigned char **buf, size_t *buflen)
long len;
*buflen = 0;
+
+ /* Check for empty value */
if (!*value) {
/*
* Don't return NULL for zero length buffer.
@@ -141,6 +143,14 @@ static int test_bin(const char *value, unsigned char **buf, size_t *buflen)
*buflen = 0;
return 1;
}
+
+ /* Check for NULL literal */
+ if (strcmp(value, "NULL") == 0) {
+ *buf = NULL;
+ *buflen = 0;
+ return 1;
+ }
+
/* Check for string literal */
if (value[0] == '"') {
size_t vlen;
@@ -155,6 +165,7 @@ static int test_bin(const char *value, unsigned char **buf, size_t *buflen)
return 1;
}
+ /* Otherwise assume as hex literal and convert it to binary buffer */
*buf = OPENSSL_hexstr2buf(value, &len);
if (!*buf) {
fprintf(stderr, "Value=%s\n", value);
@@ -640,7 +651,7 @@ int main(int argc, char **argv)
memset(&t, 0, sizeof(t));
t.start_line = -1;
- in = BIO_new_file(argv[1], "r");
+ in = BIO_new_file(argv[1], "rb");
if (in == NULL) {
fprintf(stderr, "Can't open %s for reading\n", argv[1]);
return 1;