eng_devcrypto: add cipher CTX copy function
[openssl.git] / test / pkey_meth_kdf_test.c
index a2ad91e40dc054eabfab5451a8768ef59ec24d02..f2abcf3ede5100828ee8072c602a98d87026d0fe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the OpenSSL license (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
 #include <openssl/kdf.h>
 #include "testutil.h"
 
+static int test_kdf_tls1_prf(void)
+{
+    EVP_PKEY_CTX *pctx;
+    unsigned char out[16];
+    size_t outlen = sizeof(out);
+    pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1_PRF, NULL);
+
+    if (EVP_PKEY_derive_init(pctx) <= 0) {
+        TEST_error("EVP_PKEY_derive_init");
+        return 0;
+    }
+    if (EVP_PKEY_CTX_set_tls1_prf_md(pctx, EVP_sha256()) <= 0) {
+        TEST_error("EVP_PKEY_CTX_set_tls1_prf_md");
+        return 0;
+    }
+    if (EVP_PKEY_CTX_set1_tls1_prf_secret(pctx, "secret", 6) <= 0) {
+        TEST_error("EVP_PKEY_CTX_set1_tls1_prf_secret");
+        return 0;
+    }
+    if (EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, "seed", 4) <= 0) {
+        TEST_error("EVP_PKEY_CTX_add1_tls1_prf_seed");
+        return 0;
+    }
+    if (EVP_PKEY_derive(pctx, out, &outlen) <= 0) {
+        TEST_error("EVP_PKEY_derive");
+        return 0;
+    }
+
+    {
+        const unsigned char expected[sizeof(out)] = {
+            0x8e, 0x4d, 0x93, 0x25, 0x30, 0xd7, 0x65, 0xa0,
+            0xaa, 0xe9, 0x74, 0xc3, 0x04, 0x73, 0x5e, 0xcc
+        };
+        if (!TEST_mem_eq(out, sizeof(out), expected, sizeof(expected))) {
+            return 0;
+        }
+    }
+    EVP_PKEY_CTX_free(pctx);
+    return 1;
+}
+
 static int test_kdf_hkdf(void)
 {
     EVP_PKEY_CTX *pctx;
@@ -60,6 +101,7 @@ static int test_kdf_hkdf(void)
     return 1;
 }
 
+#ifndef OPENSSL_NO_SCRYPT
 static int test_kdf_scrypt(void)
 {
     EVP_PKEY_CTX *pctx;
@@ -126,10 +168,14 @@ static int test_kdf_scrypt(void)
     EVP_PKEY_CTX_free(pctx);
     return 1;
 }
+#endif
 
-int setup_tests()
+int setup_tests(void)
 {
+    ADD_TEST(test_kdf_tls1_prf);
     ADD_TEST(test_kdf_hkdf);
+#ifndef OPENSSL_NO_SCRYPT
     ADD_TEST(test_kdf_scrypt);
+#endif
     return 1;
 }