forked from openssl/openssl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
488 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.