Skip to content

Commit

Permalink
EVP_SKEY tests
Browse files Browse the repository at this point in the history
  • Loading branch information
beldmit committed Nov 13, 2024
1 parent f79d9e8 commit a9c5a71
Show file tree
Hide file tree
Showing 5 changed files with 488 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/build.info
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,11 @@ IF[{- !$disabled{tests} -}]
INCLUDE[provider_pkey_test]=../include ../apps/include
DEPEND[provider_pkey_test]=../libcrypto libtestutil.a

PROGRAMS{noinst}=evp_skey_test
SOURCE[evp_skey_test]=evp_skey_test.c fake_cipherprov.c
INCLUDE[evp_skey_test]=../include ../apps/include
DEPEND[evp_skey_test]=../libcrypto libtestutil.a

PROGRAMS{noinst}=provider_default_search_path_test
SOURCE[provider_default_search_path_test]=provider_default_search_path_test.c
INCLUDE[provider_default_search_path_test]=../include ../apps/include
Expand Down
75 changes: 75 additions & 0 deletions test/evp_skey_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/

#include <openssl/provider.h>
#include <openssl/params.h>
#include <openssl/core_names.h>
#include <openssl/evp.h>
#include "testutil.h"
#include "fake_cipherprov.h"

static OSSL_LIB_CTX *libctx = NULL;

static int test_skey_cipher(void)
{
int ret = 0;
OSSL_PROVIDER *fake_prov = NULL;
EVP_SKEY *key = NULL;
EVP_CIPHER *fake_cipher = NULL;
EVP_CIPHER_CTX *ctx = NULL;
const OSSL_PARAM params[] = {{FAKE_CIPHER_PARAM_KEY_NAME, OSSL_PARAM_UTF8_STRING, "fake key name", 14, 0}, OSSL_PARAM_END};

if (!TEST_ptr(fake_prov = fake_cipher_start(libctx)))
return 0;

/* Do a direct fetch to see it works */
fake_cipher = EVP_CIPHER_fetch(libctx, "fake_cipher", FAKE_CIPHER_FETCH_PROPS);
if (!TEST_ptr(fake_cipher))
goto end;

/* Create EVP_SKEY*/
key = EVP_SKEY_new(libctx, "fake_cipher", FAKE_CIPHER_FETCH_PROPS);
if (!TEST_ptr(key))
goto end;

/* Import params */
if(!TEST_int_gt(EVP_SKEY_import(key, params), 0))
goto end;

/* Init cipher */
if(!TEST_ptr(ctx = EVP_CIPHER_CTX_new())
|| !TEST_int_gt(EVP_CipherInit_skey(ctx, fake_cipher, key, NULL, 1, NULL), 0))
goto end;

ret = 1;

end:
EVP_SKEY_free(key);
EVP_CIPHER_free(fake_cipher);
EVP_CIPHER_CTX_free(ctx);
fake_cipher_finish(fake_prov);

return ret;
}

int setup_tests(void)
{
libctx = OSSL_LIB_CTX_new();
if (libctx == NULL)
return 0;

ADD_TEST(test_skey_cipher);

return 1;
}

void cleanup_tests(void)
{
OSSL_LIB_CTX_free(libctx);
}
Loading

0 comments on commit a9c5a71

Please sign in to comment.