1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved 4e1051a39Sopenharmony_ci * 5e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 6e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 7e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 8e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 9e1051a39Sopenharmony_ci */ 10e1051a39Sopenharmony_ci 11e1051a39Sopenharmony_ci/* We need to use some engine deprecated APIs */ 12e1051a39Sopenharmony_ci#define OPENSSL_SUPPRESS_DEPRECATED 13e1051a39Sopenharmony_ci 14e1051a39Sopenharmony_ci/* 15e1051a39Sopenharmony_ci * RC4 and SHA-1 low level APIs and EVP _meth_ APISs are deprecated for public 16e1051a39Sopenharmony_ci * use, but still ok for internal use. 17e1051a39Sopenharmony_ci */ 18e1051a39Sopenharmony_ci#include "internal/deprecated.h" 19e1051a39Sopenharmony_ci 20e1051a39Sopenharmony_ci#include <stdio.h> 21e1051a39Sopenharmony_ci#include <openssl/crypto.h> 22e1051a39Sopenharmony_ci#include "internal/cryptlib.h" 23e1051a39Sopenharmony_ci#include "crypto/engine.h" 24e1051a39Sopenharmony_ci#include <openssl/pem.h> 25e1051a39Sopenharmony_ci#include <openssl/evp.h> 26e1051a39Sopenharmony_ci#include <openssl/rand.h> 27e1051a39Sopenharmony_ci#include <openssl/rsa.h> 28e1051a39Sopenharmony_ci#include <openssl/dsa.h> 29e1051a39Sopenharmony_ci#include <openssl/dh.h> 30e1051a39Sopenharmony_ci 31e1051a39Sopenharmony_ci#include <openssl/hmac.h> 32e1051a39Sopenharmony_ci#include <openssl/x509v3.h> 33e1051a39Sopenharmony_ci 34e1051a39Sopenharmony_ci/* 35e1051a39Sopenharmony_ci * This testing gunk is implemented (and explained) lower down. It also 36e1051a39Sopenharmony_ci * assumes the application explicitly calls "ENGINE_load_openssl()" because 37e1051a39Sopenharmony_ci * this is no longer automatic in ENGINE_load_builtin_engines(). 38e1051a39Sopenharmony_ci */ 39e1051a39Sopenharmony_ci#define TEST_ENG_OPENSSL_RC4 40e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_STDIO 41e1051a39Sopenharmony_ci# define TEST_ENG_OPENSSL_PKEY 42e1051a39Sopenharmony_ci#endif 43e1051a39Sopenharmony_ci/* #define TEST_ENG_OPENSSL_HMAC */ 44e1051a39Sopenharmony_ci/* #define TEST_ENG_OPENSSL_HMAC_INIT */ 45e1051a39Sopenharmony_ci/* #define TEST_ENG_OPENSSL_RC4_OTHERS */ 46e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_STDIO 47e1051a39Sopenharmony_ci# define TEST_ENG_OPENSSL_RC4_P_INIT 48e1051a39Sopenharmony_ci#endif 49e1051a39Sopenharmony_ci/* #define TEST_ENG_OPENSSL_RC4_P_CIPHER */ 50e1051a39Sopenharmony_ci#define TEST_ENG_OPENSSL_SHA 51e1051a39Sopenharmony_ci/* #define TEST_ENG_OPENSSL_SHA_OTHERS */ 52e1051a39Sopenharmony_ci/* #define TEST_ENG_OPENSSL_SHA_P_INIT */ 53e1051a39Sopenharmony_ci/* #define TEST_ENG_OPENSSL_SHA_P_UPDATE */ 54e1051a39Sopenharmony_ci/* #define TEST_ENG_OPENSSL_SHA_P_FINAL */ 55e1051a39Sopenharmony_ci 56e1051a39Sopenharmony_ci/* Now check what of those algorithms are actually enabled */ 57e1051a39Sopenharmony_ci#ifdef OPENSSL_NO_RC4 58e1051a39Sopenharmony_ci# undef TEST_ENG_OPENSSL_RC4 59e1051a39Sopenharmony_ci# undef TEST_ENG_OPENSSL_RC4_OTHERS 60e1051a39Sopenharmony_ci# undef TEST_ENG_OPENSSL_RC4_P_INIT 61e1051a39Sopenharmony_ci# undef TEST_ENG_OPENSSL_RC4_P_CIPHER 62e1051a39Sopenharmony_ci#endif 63e1051a39Sopenharmony_ci 64e1051a39Sopenharmony_cistatic int openssl_destroy(ENGINE *e); 65e1051a39Sopenharmony_ci 66e1051a39Sopenharmony_ci#ifdef TEST_ENG_OPENSSL_RC4 67e1051a39Sopenharmony_cistatic int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher, 68e1051a39Sopenharmony_ci const int **nids, int nid); 69e1051a39Sopenharmony_ci#endif 70e1051a39Sopenharmony_ci#ifdef TEST_ENG_OPENSSL_SHA 71e1051a39Sopenharmony_cistatic int openssl_digests(ENGINE *e, const EVP_MD **digest, 72e1051a39Sopenharmony_ci const int **nids, int nid); 73e1051a39Sopenharmony_ci#endif 74e1051a39Sopenharmony_ci 75e1051a39Sopenharmony_ci#ifdef TEST_ENG_OPENSSL_PKEY 76e1051a39Sopenharmony_cistatic EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id, 77e1051a39Sopenharmony_ci UI_METHOD *ui_method, 78e1051a39Sopenharmony_ci void *callback_data); 79e1051a39Sopenharmony_ci#endif 80e1051a39Sopenharmony_ci 81e1051a39Sopenharmony_ci#ifdef TEST_ENG_OPENSSL_HMAC 82e1051a39Sopenharmony_cistatic int ossl_register_hmac_meth(void); 83e1051a39Sopenharmony_cistatic int ossl_pkey_meths(ENGINE *e, EVP_PKEY_METHOD **pmeth, 84e1051a39Sopenharmony_ci const int **nids, int nid); 85e1051a39Sopenharmony_ci#endif 86e1051a39Sopenharmony_ci 87e1051a39Sopenharmony_ci/* The constants used when creating the ENGINE */ 88e1051a39Sopenharmony_cistatic const char *engine_openssl_id = "openssl"; 89e1051a39Sopenharmony_cistatic const char *engine_openssl_name = "Software engine support"; 90e1051a39Sopenharmony_ci 91e1051a39Sopenharmony_ci/* 92e1051a39Sopenharmony_ci * This internal function is used by ENGINE_openssl() and possibly by the 93e1051a39Sopenharmony_ci * "dynamic" ENGINE support too 94e1051a39Sopenharmony_ci */ 95e1051a39Sopenharmony_cistatic int bind_helper(ENGINE *e) 96e1051a39Sopenharmony_ci{ 97e1051a39Sopenharmony_ci if (!ENGINE_set_id(e, engine_openssl_id) 98e1051a39Sopenharmony_ci || !ENGINE_set_name(e, engine_openssl_name) 99e1051a39Sopenharmony_ci || !ENGINE_set_destroy_function(e, openssl_destroy) 100e1051a39Sopenharmony_ci#ifndef TEST_ENG_OPENSSL_NO_ALGORITHMS 101e1051a39Sopenharmony_ci || !ENGINE_set_RSA(e, RSA_get_default_method()) 102e1051a39Sopenharmony_ci# ifndef OPENSSL_NO_DSA 103e1051a39Sopenharmony_ci || !ENGINE_set_DSA(e, DSA_get_default_method()) 104e1051a39Sopenharmony_ci# endif 105e1051a39Sopenharmony_ci# ifndef OPENSSL_NO_EC 106e1051a39Sopenharmony_ci || !ENGINE_set_EC(e, EC_KEY_OpenSSL()) 107e1051a39Sopenharmony_ci# endif 108e1051a39Sopenharmony_ci# ifndef OPENSSL_NO_DH 109e1051a39Sopenharmony_ci || !ENGINE_set_DH(e, DH_get_default_method()) 110e1051a39Sopenharmony_ci# endif 111e1051a39Sopenharmony_ci || !ENGINE_set_RAND(e, RAND_OpenSSL()) 112e1051a39Sopenharmony_ci# ifdef TEST_ENG_OPENSSL_RC4 113e1051a39Sopenharmony_ci || !ENGINE_set_ciphers(e, openssl_ciphers) 114e1051a39Sopenharmony_ci# endif 115e1051a39Sopenharmony_ci# ifdef TEST_ENG_OPENSSL_SHA 116e1051a39Sopenharmony_ci || !ENGINE_set_digests(e, openssl_digests) 117e1051a39Sopenharmony_ci# endif 118e1051a39Sopenharmony_ci#endif 119e1051a39Sopenharmony_ci#ifdef TEST_ENG_OPENSSL_PKEY 120e1051a39Sopenharmony_ci || !ENGINE_set_load_privkey_function(e, openssl_load_privkey) 121e1051a39Sopenharmony_ci#endif 122e1051a39Sopenharmony_ci#ifdef TEST_ENG_OPENSSL_HMAC 123e1051a39Sopenharmony_ci || !ossl_register_hmac_meth() 124e1051a39Sopenharmony_ci || !ENGINE_set_pkey_meths(e, ossl_pkey_meths) 125e1051a39Sopenharmony_ci#endif 126e1051a39Sopenharmony_ci ) 127e1051a39Sopenharmony_ci return 0; 128e1051a39Sopenharmony_ci /* 129e1051a39Sopenharmony_ci * If we add errors to this ENGINE, ensure the error handling is setup 130e1051a39Sopenharmony_ci * here 131e1051a39Sopenharmony_ci */ 132e1051a39Sopenharmony_ci /* openssl_load_error_strings(); */ 133e1051a39Sopenharmony_ci return 1; 134e1051a39Sopenharmony_ci} 135e1051a39Sopenharmony_ci 136e1051a39Sopenharmony_cistatic ENGINE *engine_openssl(void) 137e1051a39Sopenharmony_ci{ 138e1051a39Sopenharmony_ci ENGINE *ret = ENGINE_new(); 139e1051a39Sopenharmony_ci if (ret == NULL) 140e1051a39Sopenharmony_ci return NULL; 141e1051a39Sopenharmony_ci if (!bind_helper(ret)) { 142e1051a39Sopenharmony_ci ENGINE_free(ret); 143e1051a39Sopenharmony_ci return NULL; 144e1051a39Sopenharmony_ci } 145e1051a39Sopenharmony_ci return ret; 146e1051a39Sopenharmony_ci} 147e1051a39Sopenharmony_ci 148e1051a39Sopenharmony_civoid engine_load_openssl_int(void) 149e1051a39Sopenharmony_ci{ 150e1051a39Sopenharmony_ci ENGINE *toadd = engine_openssl(); 151e1051a39Sopenharmony_ci if (!toadd) 152e1051a39Sopenharmony_ci return; 153e1051a39Sopenharmony_ci 154e1051a39Sopenharmony_ci ERR_set_mark(); 155e1051a39Sopenharmony_ci ENGINE_add(toadd); 156e1051a39Sopenharmony_ci /* 157e1051a39Sopenharmony_ci * If the "add" worked, it gets a structural reference. So either way, we 158e1051a39Sopenharmony_ci * release our just-created reference. 159e1051a39Sopenharmony_ci */ 160e1051a39Sopenharmony_ci ENGINE_free(toadd); 161e1051a39Sopenharmony_ci /* 162e1051a39Sopenharmony_ci * If the "add" didn't work, it was probably a conflict because it was 163e1051a39Sopenharmony_ci * already added (eg. someone calling ENGINE_load_blah then calling 164e1051a39Sopenharmony_ci * ENGINE_load_builtin_engines() perhaps). 165e1051a39Sopenharmony_ci */ 166e1051a39Sopenharmony_ci ERR_pop_to_mark(); 167e1051a39Sopenharmony_ci} 168e1051a39Sopenharmony_ci 169e1051a39Sopenharmony_ci/* 170e1051a39Sopenharmony_ci * This stuff is needed if this ENGINE is being compiled into a 171e1051a39Sopenharmony_ci * self-contained shared-library. 172e1051a39Sopenharmony_ci */ 173e1051a39Sopenharmony_ci#ifdef ENGINE_DYNAMIC_SUPPORT 174e1051a39Sopenharmony_cistatic int bind_fn(ENGINE *e, const char *id) 175e1051a39Sopenharmony_ci{ 176e1051a39Sopenharmony_ci if (id && (strcmp(id, engine_openssl_id) != 0)) 177e1051a39Sopenharmony_ci return 0; 178e1051a39Sopenharmony_ci if (!bind_helper(e)) 179e1051a39Sopenharmony_ci return 0; 180e1051a39Sopenharmony_ci return 1; 181e1051a39Sopenharmony_ci} 182e1051a39Sopenharmony_ci 183e1051a39Sopenharmony_ciIMPLEMENT_DYNAMIC_CHECK_FN() 184e1051a39Sopenharmony_ci IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) 185e1051a39Sopenharmony_ci#endif /* ENGINE_DYNAMIC_SUPPORT */ 186e1051a39Sopenharmony_ci#ifdef TEST_ENG_OPENSSL_RC4 187e1051a39Sopenharmony_ci/*- 188e1051a39Sopenharmony_ci * This section of code compiles an "alternative implementation" of two modes of 189e1051a39Sopenharmony_ci * RC4 into this ENGINE. The result is that EVP_CIPHER operation for "rc4" 190e1051a39Sopenharmony_ci * should under normal circumstances go via this support rather than the default 191e1051a39Sopenharmony_ci * EVP support. There are other symbols to tweak the testing; 192e1051a39Sopenharmony_ci * TEST_ENC_OPENSSL_RC4_OTHERS - print a one line message to stderr each time 193e1051a39Sopenharmony_ci * we're asked for a cipher we don't support (should not happen). 194e1051a39Sopenharmony_ci * TEST_ENG_OPENSSL_RC4_P_INIT - print a one line message to stderr each time 195e1051a39Sopenharmony_ci * the "init_key" handler is called. 196e1051a39Sopenharmony_ci * TEST_ENG_OPENSSL_RC4_P_CIPHER - ditto for the "cipher" handler. 197e1051a39Sopenharmony_ci */ 198e1051a39Sopenharmony_ci# include <openssl/rc4.h> 199e1051a39Sopenharmony_ci# define TEST_RC4_KEY_SIZE 16 200e1051a39Sopenharmony_citypedef struct { 201e1051a39Sopenharmony_ci unsigned char key[TEST_RC4_KEY_SIZE]; 202e1051a39Sopenharmony_ci RC4_KEY ks; 203e1051a39Sopenharmony_ci} TEST_RC4_KEY; 204e1051a39Sopenharmony_ci# define test(ctx) ((TEST_RC4_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx)) 205e1051a39Sopenharmony_cistatic int test_rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 206e1051a39Sopenharmony_ci const unsigned char *iv, int enc) 207e1051a39Sopenharmony_ci{ 208e1051a39Sopenharmony_ci const int n = EVP_CIPHER_CTX_get_key_length(ctx); 209e1051a39Sopenharmony_ci 210e1051a39Sopenharmony_ci# ifdef TEST_ENG_OPENSSL_RC4_P_INIT 211e1051a39Sopenharmony_ci fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_init_key() called\n"); 212e1051a39Sopenharmony_ci# endif 213e1051a39Sopenharmony_ci if (n <= 0) 214e1051a39Sopenharmony_ci return n; 215e1051a39Sopenharmony_ci memcpy(&test(ctx)->key[0], key, n); 216e1051a39Sopenharmony_ci RC4_set_key(&test(ctx)->ks, n, test(ctx)->key); 217e1051a39Sopenharmony_ci return 1; 218e1051a39Sopenharmony_ci} 219e1051a39Sopenharmony_ci 220e1051a39Sopenharmony_cistatic int test_rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 221e1051a39Sopenharmony_ci const unsigned char *in, size_t inl) 222e1051a39Sopenharmony_ci{ 223e1051a39Sopenharmony_ci# ifdef TEST_ENG_OPENSSL_RC4_P_CIPHER 224e1051a39Sopenharmony_ci fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_cipher() called\n"); 225e1051a39Sopenharmony_ci# endif 226e1051a39Sopenharmony_ci RC4(&test(ctx)->ks, inl, in, out); 227e1051a39Sopenharmony_ci return 1; 228e1051a39Sopenharmony_ci} 229e1051a39Sopenharmony_ci 230e1051a39Sopenharmony_cistatic EVP_CIPHER *r4_cipher = NULL; 231e1051a39Sopenharmony_cistatic const EVP_CIPHER *test_r4_cipher(void) 232e1051a39Sopenharmony_ci{ 233e1051a39Sopenharmony_ci if (r4_cipher == NULL) { 234e1051a39Sopenharmony_ci EVP_CIPHER *cipher; 235e1051a39Sopenharmony_ci 236e1051a39Sopenharmony_ci if ((cipher = EVP_CIPHER_meth_new(NID_rc4, 1, TEST_RC4_KEY_SIZE)) == NULL 237e1051a39Sopenharmony_ci || !EVP_CIPHER_meth_set_iv_length(cipher, 0) 238e1051a39Sopenharmony_ci || !EVP_CIPHER_meth_set_flags(cipher, EVP_CIPH_VARIABLE_LENGTH) 239e1051a39Sopenharmony_ci || !EVP_CIPHER_meth_set_init(cipher, test_rc4_init_key) 240e1051a39Sopenharmony_ci || !EVP_CIPHER_meth_set_do_cipher(cipher, test_rc4_cipher) 241e1051a39Sopenharmony_ci || !EVP_CIPHER_meth_set_impl_ctx_size(cipher, sizeof(TEST_RC4_KEY))) { 242e1051a39Sopenharmony_ci EVP_CIPHER_meth_free(cipher); 243e1051a39Sopenharmony_ci cipher = NULL; 244e1051a39Sopenharmony_ci } 245e1051a39Sopenharmony_ci r4_cipher = cipher; 246e1051a39Sopenharmony_ci } 247e1051a39Sopenharmony_ci return r4_cipher; 248e1051a39Sopenharmony_ci} 249e1051a39Sopenharmony_cistatic void test_r4_cipher_destroy(void) 250e1051a39Sopenharmony_ci{ 251e1051a39Sopenharmony_ci EVP_CIPHER_meth_free(r4_cipher); 252e1051a39Sopenharmony_ci r4_cipher = NULL; 253e1051a39Sopenharmony_ci} 254e1051a39Sopenharmony_ci 255e1051a39Sopenharmony_cistatic EVP_CIPHER *r4_40_cipher = NULL; 256e1051a39Sopenharmony_cistatic const EVP_CIPHER *test_r4_40_cipher(void) 257e1051a39Sopenharmony_ci{ 258e1051a39Sopenharmony_ci if (r4_40_cipher == NULL) { 259e1051a39Sopenharmony_ci EVP_CIPHER *cipher; 260e1051a39Sopenharmony_ci 261e1051a39Sopenharmony_ci if ((cipher = EVP_CIPHER_meth_new(NID_rc4, 1, 5 /* 40 bits */)) == NULL 262e1051a39Sopenharmony_ci || !EVP_CIPHER_meth_set_iv_length(cipher, 0) 263e1051a39Sopenharmony_ci || !EVP_CIPHER_meth_set_flags(cipher, EVP_CIPH_VARIABLE_LENGTH) 264e1051a39Sopenharmony_ci || !EVP_CIPHER_meth_set_init(cipher, test_rc4_init_key) 265e1051a39Sopenharmony_ci || !EVP_CIPHER_meth_set_do_cipher(cipher, test_rc4_cipher) 266e1051a39Sopenharmony_ci || !EVP_CIPHER_meth_set_impl_ctx_size(cipher, sizeof(TEST_RC4_KEY))) { 267e1051a39Sopenharmony_ci EVP_CIPHER_meth_free(cipher); 268e1051a39Sopenharmony_ci cipher = NULL; 269e1051a39Sopenharmony_ci } 270e1051a39Sopenharmony_ci r4_40_cipher = cipher; 271e1051a39Sopenharmony_ci } 272e1051a39Sopenharmony_ci return r4_40_cipher; 273e1051a39Sopenharmony_ci} 274e1051a39Sopenharmony_cistatic void test_r4_40_cipher_destroy(void) 275e1051a39Sopenharmony_ci{ 276e1051a39Sopenharmony_ci EVP_CIPHER_meth_free(r4_40_cipher); 277e1051a39Sopenharmony_ci r4_40_cipher = NULL; 278e1051a39Sopenharmony_ci} 279e1051a39Sopenharmony_cistatic int test_cipher_nids(const int **nids) 280e1051a39Sopenharmony_ci{ 281e1051a39Sopenharmony_ci static int cipher_nids[4] = { 0, 0, 0, 0 }; 282e1051a39Sopenharmony_ci static int pos = 0; 283e1051a39Sopenharmony_ci static int init = 0; 284e1051a39Sopenharmony_ci 285e1051a39Sopenharmony_ci if (!init) { 286e1051a39Sopenharmony_ci const EVP_CIPHER *cipher; 287e1051a39Sopenharmony_ci if ((cipher = test_r4_cipher()) != NULL) 288e1051a39Sopenharmony_ci cipher_nids[pos++] = EVP_CIPHER_get_nid(cipher); 289e1051a39Sopenharmony_ci if ((cipher = test_r4_40_cipher()) != NULL) 290e1051a39Sopenharmony_ci cipher_nids[pos++] = EVP_CIPHER_get_nid(cipher); 291e1051a39Sopenharmony_ci cipher_nids[pos] = 0; 292e1051a39Sopenharmony_ci init = 1; 293e1051a39Sopenharmony_ci } 294e1051a39Sopenharmony_ci *nids = cipher_nids; 295e1051a39Sopenharmony_ci return pos; 296e1051a39Sopenharmony_ci} 297e1051a39Sopenharmony_ci 298e1051a39Sopenharmony_cistatic int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher, 299e1051a39Sopenharmony_ci const int **nids, int nid) 300e1051a39Sopenharmony_ci{ 301e1051a39Sopenharmony_ci if (!cipher) { 302e1051a39Sopenharmony_ci /* We are returning a list of supported nids */ 303e1051a39Sopenharmony_ci return test_cipher_nids(nids); 304e1051a39Sopenharmony_ci } 305e1051a39Sopenharmony_ci /* We are being asked for a specific cipher */ 306e1051a39Sopenharmony_ci if (nid == NID_rc4) 307e1051a39Sopenharmony_ci *cipher = test_r4_cipher(); 308e1051a39Sopenharmony_ci else if (nid == NID_rc4_40) 309e1051a39Sopenharmony_ci *cipher = test_r4_40_cipher(); 310e1051a39Sopenharmony_ci else { 311e1051a39Sopenharmony_ci# ifdef TEST_ENG_OPENSSL_RC4_OTHERS 312e1051a39Sopenharmony_ci fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) returning NULL for " 313e1051a39Sopenharmony_ci "nid %d\n", nid); 314e1051a39Sopenharmony_ci# endif 315e1051a39Sopenharmony_ci *cipher = NULL; 316e1051a39Sopenharmony_ci return 0; 317e1051a39Sopenharmony_ci } 318e1051a39Sopenharmony_ci return 1; 319e1051a39Sopenharmony_ci} 320e1051a39Sopenharmony_ci#endif 321e1051a39Sopenharmony_ci 322e1051a39Sopenharmony_ci#ifdef TEST_ENG_OPENSSL_SHA 323e1051a39Sopenharmony_ci/* Much the same sort of comment as for TEST_ENG_OPENSSL_RC4 */ 324e1051a39Sopenharmony_ci# include <openssl/sha.h> 325e1051a39Sopenharmony_ci 326e1051a39Sopenharmony_cistatic int test_sha1_init(EVP_MD_CTX *ctx) 327e1051a39Sopenharmony_ci{ 328e1051a39Sopenharmony_ci# ifdef TEST_ENG_OPENSSL_SHA_P_INIT 329e1051a39Sopenharmony_ci fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_init() called\n"); 330e1051a39Sopenharmony_ci# endif 331e1051a39Sopenharmony_ci return SHA1_Init(EVP_MD_CTX_get0_md_data(ctx)); 332e1051a39Sopenharmony_ci} 333e1051a39Sopenharmony_ci 334e1051a39Sopenharmony_cistatic int test_sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count) 335e1051a39Sopenharmony_ci{ 336e1051a39Sopenharmony_ci# ifdef TEST_ENG_OPENSSL_SHA_P_UPDATE 337e1051a39Sopenharmony_ci fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_update() called\n"); 338e1051a39Sopenharmony_ci# endif 339e1051a39Sopenharmony_ci return SHA1_Update(EVP_MD_CTX_get0_md_data(ctx), data, count); 340e1051a39Sopenharmony_ci} 341e1051a39Sopenharmony_ci 342e1051a39Sopenharmony_cistatic int test_sha1_final(EVP_MD_CTX *ctx, unsigned char *md) 343e1051a39Sopenharmony_ci{ 344e1051a39Sopenharmony_ci# ifdef TEST_ENG_OPENSSL_SHA_P_FINAL 345e1051a39Sopenharmony_ci fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_final() called\n"); 346e1051a39Sopenharmony_ci# endif 347e1051a39Sopenharmony_ci return SHA1_Final(md, EVP_MD_CTX_get0_md_data(ctx)); 348e1051a39Sopenharmony_ci} 349e1051a39Sopenharmony_ci 350e1051a39Sopenharmony_cistatic EVP_MD *sha1_md = NULL; 351e1051a39Sopenharmony_cistatic const EVP_MD *test_sha_md(void) 352e1051a39Sopenharmony_ci{ 353e1051a39Sopenharmony_ci if (sha1_md == NULL) { 354e1051a39Sopenharmony_ci EVP_MD *md; 355e1051a39Sopenharmony_ci 356e1051a39Sopenharmony_ci if ((md = EVP_MD_meth_new(NID_sha1, NID_sha1WithRSAEncryption)) == NULL 357e1051a39Sopenharmony_ci || !EVP_MD_meth_set_result_size(md, SHA_DIGEST_LENGTH) 358e1051a39Sopenharmony_ci || !EVP_MD_meth_set_input_blocksize(md, SHA_CBLOCK) 359e1051a39Sopenharmony_ci || !EVP_MD_meth_set_app_datasize(md, 360e1051a39Sopenharmony_ci sizeof(EVP_MD *) + sizeof(SHA_CTX)) 361e1051a39Sopenharmony_ci || !EVP_MD_meth_set_flags(md, 0) 362e1051a39Sopenharmony_ci || !EVP_MD_meth_set_init(md, test_sha1_init) 363e1051a39Sopenharmony_ci || !EVP_MD_meth_set_update(md, test_sha1_update) 364e1051a39Sopenharmony_ci || !EVP_MD_meth_set_final(md, test_sha1_final)) { 365e1051a39Sopenharmony_ci EVP_MD_meth_free(md); 366e1051a39Sopenharmony_ci md = NULL; 367e1051a39Sopenharmony_ci } 368e1051a39Sopenharmony_ci sha1_md = md; 369e1051a39Sopenharmony_ci } 370e1051a39Sopenharmony_ci return sha1_md; 371e1051a39Sopenharmony_ci} 372e1051a39Sopenharmony_cistatic void test_sha_md_destroy(void) 373e1051a39Sopenharmony_ci{ 374e1051a39Sopenharmony_ci EVP_MD_meth_free(sha1_md); 375e1051a39Sopenharmony_ci sha1_md = NULL; 376e1051a39Sopenharmony_ci} 377e1051a39Sopenharmony_cistatic int test_digest_nids(const int **nids) 378e1051a39Sopenharmony_ci{ 379e1051a39Sopenharmony_ci static int digest_nids[2] = { 0, 0 }; 380e1051a39Sopenharmony_ci static int pos = 0; 381e1051a39Sopenharmony_ci static int init = 0; 382e1051a39Sopenharmony_ci 383e1051a39Sopenharmony_ci if (!init) { 384e1051a39Sopenharmony_ci const EVP_MD *md; 385e1051a39Sopenharmony_ci if ((md = test_sha_md()) != NULL) 386e1051a39Sopenharmony_ci digest_nids[pos++] = EVP_MD_get_type(md); 387e1051a39Sopenharmony_ci digest_nids[pos] = 0; 388e1051a39Sopenharmony_ci init = 1; 389e1051a39Sopenharmony_ci } 390e1051a39Sopenharmony_ci *nids = digest_nids; 391e1051a39Sopenharmony_ci return pos; 392e1051a39Sopenharmony_ci} 393e1051a39Sopenharmony_ci 394e1051a39Sopenharmony_cistatic int openssl_digests(ENGINE *e, const EVP_MD **digest, 395e1051a39Sopenharmony_ci const int **nids, int nid) 396e1051a39Sopenharmony_ci{ 397e1051a39Sopenharmony_ci if (!digest) { 398e1051a39Sopenharmony_ci /* We are returning a list of supported nids */ 399e1051a39Sopenharmony_ci return test_digest_nids(nids); 400e1051a39Sopenharmony_ci } 401e1051a39Sopenharmony_ci /* We are being asked for a specific digest */ 402e1051a39Sopenharmony_ci if (nid == NID_sha1) 403e1051a39Sopenharmony_ci *digest = test_sha_md(); 404e1051a39Sopenharmony_ci else { 405e1051a39Sopenharmony_ci# ifdef TEST_ENG_OPENSSL_SHA_OTHERS 406e1051a39Sopenharmony_ci fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) returning NULL for " 407e1051a39Sopenharmony_ci "nid %d\n", nid); 408e1051a39Sopenharmony_ci# endif 409e1051a39Sopenharmony_ci *digest = NULL; 410e1051a39Sopenharmony_ci return 0; 411e1051a39Sopenharmony_ci } 412e1051a39Sopenharmony_ci return 1; 413e1051a39Sopenharmony_ci} 414e1051a39Sopenharmony_ci#endif 415e1051a39Sopenharmony_ci 416e1051a39Sopenharmony_ci#ifdef TEST_ENG_OPENSSL_PKEY 417e1051a39Sopenharmony_cistatic EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id, 418e1051a39Sopenharmony_ci UI_METHOD *ui_method, 419e1051a39Sopenharmony_ci void *callback_data) 420e1051a39Sopenharmony_ci{ 421e1051a39Sopenharmony_ci BIO *in; 422e1051a39Sopenharmony_ci EVP_PKEY *key; 423e1051a39Sopenharmony_ci fprintf(stderr, "(TEST_ENG_OPENSSL_PKEY)Loading Private key %s\n", 424e1051a39Sopenharmony_ci key_id); 425e1051a39Sopenharmony_ci in = BIO_new_file(key_id, "r"); 426e1051a39Sopenharmony_ci if (!in) 427e1051a39Sopenharmony_ci return NULL; 428e1051a39Sopenharmony_ci key = PEM_read_bio_PrivateKey(in, NULL, 0, NULL); 429e1051a39Sopenharmony_ci BIO_free(in); 430e1051a39Sopenharmony_ci return key; 431e1051a39Sopenharmony_ci} 432e1051a39Sopenharmony_ci#endif 433e1051a39Sopenharmony_ci 434e1051a39Sopenharmony_ci#ifdef TEST_ENG_OPENSSL_HMAC 435e1051a39Sopenharmony_ci 436e1051a39Sopenharmony_ci/* 437e1051a39Sopenharmony_ci * Experimental HMAC redirection implementation: mainly copied from 438e1051a39Sopenharmony_ci * hm_pmeth.c 439e1051a39Sopenharmony_ci */ 440e1051a39Sopenharmony_ci 441e1051a39Sopenharmony_ci/* HMAC pkey context structure */ 442e1051a39Sopenharmony_ci 443e1051a39Sopenharmony_citypedef struct { 444e1051a39Sopenharmony_ci const EVP_MD *md; /* MD for HMAC use */ 445e1051a39Sopenharmony_ci ASN1_OCTET_STRING ktmp; /* Temp storage for key */ 446e1051a39Sopenharmony_ci HMAC_CTX *ctx; 447e1051a39Sopenharmony_ci} OSSL_HMAC_PKEY_CTX; 448e1051a39Sopenharmony_ci 449e1051a39Sopenharmony_cistatic int ossl_hmac_init(EVP_PKEY_CTX *ctx) 450e1051a39Sopenharmony_ci{ 451e1051a39Sopenharmony_ci OSSL_HMAC_PKEY_CTX *hctx; 452e1051a39Sopenharmony_ci 453e1051a39Sopenharmony_ci if ((hctx = OPENSSL_zalloc(sizeof(*hctx))) == NULL) { 454e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_ENGINE, ERR_R_MALLOC_FAILURE); 455e1051a39Sopenharmony_ci return 0; 456e1051a39Sopenharmony_ci } 457e1051a39Sopenharmony_ci hctx->ktmp.type = V_ASN1_OCTET_STRING; 458e1051a39Sopenharmony_ci hctx->ctx = HMAC_CTX_new(); 459e1051a39Sopenharmony_ci if (hctx->ctx == NULL) { 460e1051a39Sopenharmony_ci OPENSSL_free(hctx); 461e1051a39Sopenharmony_ci return 0; 462e1051a39Sopenharmony_ci } 463e1051a39Sopenharmony_ci EVP_PKEY_CTX_set_data(ctx, hctx); 464e1051a39Sopenharmony_ci EVP_PKEY_CTX_set0_keygen_info(ctx, NULL, 0); 465e1051a39Sopenharmony_ci# ifdef TEST_ENG_OPENSSL_HMAC_INIT 466e1051a39Sopenharmony_ci fprintf(stderr, "(TEST_ENG_OPENSSL_HMAC) ossl_hmac_init() called\n"); 467e1051a39Sopenharmony_ci# endif 468e1051a39Sopenharmony_ci return 1; 469e1051a39Sopenharmony_ci} 470e1051a39Sopenharmony_ci 471e1051a39Sopenharmony_cistatic void ossl_hmac_cleanup(EVP_PKEY_CTX *ctx); 472e1051a39Sopenharmony_ci 473e1051a39Sopenharmony_cistatic int ossl_hmac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) 474e1051a39Sopenharmony_ci{ 475e1051a39Sopenharmony_ci OSSL_HMAC_PKEY_CTX *sctx, *dctx; 476e1051a39Sopenharmony_ci 477e1051a39Sopenharmony_ci /* allocate memory for dst->data and a new HMAC_CTX in dst->data->ctx */ 478e1051a39Sopenharmony_ci if (!ossl_hmac_init(dst)) 479e1051a39Sopenharmony_ci return 0; 480e1051a39Sopenharmony_ci sctx = EVP_PKEY_CTX_get_data(src); 481e1051a39Sopenharmony_ci dctx = EVP_PKEY_CTX_get_data(dst); 482e1051a39Sopenharmony_ci dctx->md = sctx->md; 483e1051a39Sopenharmony_ci if (!HMAC_CTX_copy(dctx->ctx, sctx->ctx)) 484e1051a39Sopenharmony_ci goto err; 485e1051a39Sopenharmony_ci if (sctx->ktmp.data) { 486e1051a39Sopenharmony_ci if (!ASN1_OCTET_STRING_set(&dctx->ktmp, 487e1051a39Sopenharmony_ci sctx->ktmp.data, sctx->ktmp.length)) 488e1051a39Sopenharmony_ci goto err; 489e1051a39Sopenharmony_ci } 490e1051a39Sopenharmony_ci return 1; 491e1051a39Sopenharmony_cierr: 492e1051a39Sopenharmony_ci /* release HMAC_CTX in dst->data->ctx and memory allocated for dst->data */ 493e1051a39Sopenharmony_ci ossl_hmac_cleanup(dst); 494e1051a39Sopenharmony_ci return 0; 495e1051a39Sopenharmony_ci} 496e1051a39Sopenharmony_ci 497e1051a39Sopenharmony_cistatic void ossl_hmac_cleanup(EVP_PKEY_CTX *ctx) 498e1051a39Sopenharmony_ci{ 499e1051a39Sopenharmony_ci OSSL_HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx); 500e1051a39Sopenharmony_ci 501e1051a39Sopenharmony_ci if (hctx) { 502e1051a39Sopenharmony_ci HMAC_CTX_free(hctx->ctx); 503e1051a39Sopenharmony_ci OPENSSL_clear_free(hctx->ktmp.data, hctx->ktmp.length); 504e1051a39Sopenharmony_ci OPENSSL_free(hctx); 505e1051a39Sopenharmony_ci EVP_PKEY_CTX_set_data(ctx, NULL); 506e1051a39Sopenharmony_ci } 507e1051a39Sopenharmony_ci} 508e1051a39Sopenharmony_ci 509e1051a39Sopenharmony_cistatic int ossl_hmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) 510e1051a39Sopenharmony_ci{ 511e1051a39Sopenharmony_ci ASN1_OCTET_STRING *hkey = NULL; 512e1051a39Sopenharmony_ci OSSL_HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx); 513e1051a39Sopenharmony_ci if (!hctx->ktmp.data) 514e1051a39Sopenharmony_ci return 0; 515e1051a39Sopenharmony_ci hkey = ASN1_OCTET_STRING_dup(&hctx->ktmp); 516e1051a39Sopenharmony_ci if (!hkey) 517e1051a39Sopenharmony_ci return 0; 518e1051a39Sopenharmony_ci EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, hkey); 519e1051a39Sopenharmony_ci 520e1051a39Sopenharmony_ci return 1; 521e1051a39Sopenharmony_ci} 522e1051a39Sopenharmony_ci 523e1051a39Sopenharmony_cistatic int ossl_int_update(EVP_MD_CTX *ctx, const void *data, size_t count) 524e1051a39Sopenharmony_ci{ 525e1051a39Sopenharmony_ci OSSL_HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(EVP_MD_CTX_get_pkey_ctx(ctx)); 526e1051a39Sopenharmony_ci if (!HMAC_Update(hctx->ctx, data, count)) 527e1051a39Sopenharmony_ci return 0; 528e1051a39Sopenharmony_ci return 1; 529e1051a39Sopenharmony_ci} 530e1051a39Sopenharmony_ci 531e1051a39Sopenharmony_cistatic int ossl_hmac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx) 532e1051a39Sopenharmony_ci{ 533e1051a39Sopenharmony_ci EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_NO_INIT); 534e1051a39Sopenharmony_ci EVP_MD_CTX_set_update_fn(mctx, ossl_int_update); 535e1051a39Sopenharmony_ci return 1; 536e1051a39Sopenharmony_ci} 537e1051a39Sopenharmony_ci 538e1051a39Sopenharmony_cistatic int ossl_hmac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, 539e1051a39Sopenharmony_ci size_t *siglen, EVP_MD_CTX *mctx) 540e1051a39Sopenharmony_ci{ 541e1051a39Sopenharmony_ci unsigned int hlen; 542e1051a39Sopenharmony_ci OSSL_HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx); 543e1051a39Sopenharmony_ci int l = EVP_MD_CTX_get_size(mctx); 544e1051a39Sopenharmony_ci 545e1051a39Sopenharmony_ci if (l < 0) 546e1051a39Sopenharmony_ci return 0; 547e1051a39Sopenharmony_ci *siglen = l; 548e1051a39Sopenharmony_ci if (!sig) 549e1051a39Sopenharmony_ci return 1; 550e1051a39Sopenharmony_ci 551e1051a39Sopenharmony_ci if (!HMAC_Final(hctx->ctx, sig, &hlen)) 552e1051a39Sopenharmony_ci return 0; 553e1051a39Sopenharmony_ci *siglen = (size_t)hlen; 554e1051a39Sopenharmony_ci return 1; 555e1051a39Sopenharmony_ci} 556e1051a39Sopenharmony_ci 557e1051a39Sopenharmony_cistatic int ossl_hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) 558e1051a39Sopenharmony_ci{ 559e1051a39Sopenharmony_ci OSSL_HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx); 560e1051a39Sopenharmony_ci EVP_PKEY *pk; 561e1051a39Sopenharmony_ci ASN1_OCTET_STRING *key; 562e1051a39Sopenharmony_ci switch (type) { 563e1051a39Sopenharmony_ci 564e1051a39Sopenharmony_ci case EVP_PKEY_CTRL_SET_MAC_KEY: 565e1051a39Sopenharmony_ci if ((!p2 && p1 > 0) || (p1 < -1)) 566e1051a39Sopenharmony_ci return 0; 567e1051a39Sopenharmony_ci if (!ASN1_OCTET_STRING_set(&hctx->ktmp, p2, p1)) 568e1051a39Sopenharmony_ci return 0; 569e1051a39Sopenharmony_ci break; 570e1051a39Sopenharmony_ci 571e1051a39Sopenharmony_ci case EVP_PKEY_CTRL_MD: 572e1051a39Sopenharmony_ci hctx->md = p2; 573e1051a39Sopenharmony_ci break; 574e1051a39Sopenharmony_ci 575e1051a39Sopenharmony_ci case EVP_PKEY_CTRL_DIGESTINIT: 576e1051a39Sopenharmony_ci pk = EVP_PKEY_CTX_get0_pkey(ctx); 577e1051a39Sopenharmony_ci key = EVP_PKEY_get0(pk); 578e1051a39Sopenharmony_ci if (!HMAC_Init_ex(hctx->ctx, key->data, key->length, hctx->md, NULL)) 579e1051a39Sopenharmony_ci return 0; 580e1051a39Sopenharmony_ci break; 581e1051a39Sopenharmony_ci 582e1051a39Sopenharmony_ci default: 583e1051a39Sopenharmony_ci return -2; 584e1051a39Sopenharmony_ci 585e1051a39Sopenharmony_ci } 586e1051a39Sopenharmony_ci return 1; 587e1051a39Sopenharmony_ci} 588e1051a39Sopenharmony_ci 589e1051a39Sopenharmony_cistatic int ossl_hmac_ctrl_str(EVP_PKEY_CTX *ctx, 590e1051a39Sopenharmony_ci const char *type, const char *value) 591e1051a39Sopenharmony_ci{ 592e1051a39Sopenharmony_ci if (!value) { 593e1051a39Sopenharmony_ci return 0; 594e1051a39Sopenharmony_ci } 595e1051a39Sopenharmony_ci if (strcmp(type, "key") == 0) { 596e1051a39Sopenharmony_ci void *p = (void *)value; 597e1051a39Sopenharmony_ci return ossl_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, -1, p); 598e1051a39Sopenharmony_ci } 599e1051a39Sopenharmony_ci if (strcmp(type, "hexkey") == 0) { 600e1051a39Sopenharmony_ci unsigned char *key; 601e1051a39Sopenharmony_ci int r; 602e1051a39Sopenharmony_ci long keylen; 603e1051a39Sopenharmony_ci key = OPENSSL_hexstr2buf(value, &keylen); 604e1051a39Sopenharmony_ci if (!key) 605e1051a39Sopenharmony_ci return 0; 606e1051a39Sopenharmony_ci r = ossl_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key); 607e1051a39Sopenharmony_ci OPENSSL_free(key); 608e1051a39Sopenharmony_ci return r; 609e1051a39Sopenharmony_ci } 610e1051a39Sopenharmony_ci return -2; 611e1051a39Sopenharmony_ci} 612e1051a39Sopenharmony_ci 613e1051a39Sopenharmony_cistatic EVP_PKEY_METHOD *ossl_hmac_meth; 614e1051a39Sopenharmony_ci 615e1051a39Sopenharmony_cistatic int ossl_register_hmac_meth(void) 616e1051a39Sopenharmony_ci{ 617e1051a39Sopenharmony_ci EVP_PKEY_METHOD *meth; 618e1051a39Sopenharmony_ci meth = EVP_PKEY_meth_new(EVP_PKEY_HMAC, 0); 619e1051a39Sopenharmony_ci if (meth == NULL) 620e1051a39Sopenharmony_ci return 0; 621e1051a39Sopenharmony_ci EVP_PKEY_meth_set_init(meth, ossl_hmac_init); 622e1051a39Sopenharmony_ci EVP_PKEY_meth_set_copy(meth, ossl_hmac_copy); 623e1051a39Sopenharmony_ci EVP_PKEY_meth_set_cleanup(meth, ossl_hmac_cleanup); 624e1051a39Sopenharmony_ci 625e1051a39Sopenharmony_ci EVP_PKEY_meth_set_keygen(meth, 0, ossl_hmac_keygen); 626e1051a39Sopenharmony_ci 627e1051a39Sopenharmony_ci EVP_PKEY_meth_set_signctx(meth, ossl_hmac_signctx_init, 628e1051a39Sopenharmony_ci ossl_hmac_signctx); 629e1051a39Sopenharmony_ci 630e1051a39Sopenharmony_ci EVP_PKEY_meth_set_ctrl(meth, ossl_hmac_ctrl, ossl_hmac_ctrl_str); 631e1051a39Sopenharmony_ci ossl_hmac_meth = meth; 632e1051a39Sopenharmony_ci return 1; 633e1051a39Sopenharmony_ci} 634e1051a39Sopenharmony_ci 635e1051a39Sopenharmony_cistatic int ossl_pkey_meths(ENGINE *e, EVP_PKEY_METHOD **pmeth, 636e1051a39Sopenharmony_ci const int **nids, int nid) 637e1051a39Sopenharmony_ci{ 638e1051a39Sopenharmony_ci static int ossl_pkey_nids[] = { 639e1051a39Sopenharmony_ci EVP_PKEY_HMAC, 640e1051a39Sopenharmony_ci 0 641e1051a39Sopenharmony_ci }; 642e1051a39Sopenharmony_ci 643e1051a39Sopenharmony_ci if (pmeth == NULL) { 644e1051a39Sopenharmony_ci *nids = ossl_pkey_nids; 645e1051a39Sopenharmony_ci return 1; 646e1051a39Sopenharmony_ci } 647e1051a39Sopenharmony_ci 648e1051a39Sopenharmony_ci if (nid == EVP_PKEY_HMAC) { 649e1051a39Sopenharmony_ci *pmeth = ossl_hmac_meth; 650e1051a39Sopenharmony_ci return 1; 651e1051a39Sopenharmony_ci } 652e1051a39Sopenharmony_ci 653e1051a39Sopenharmony_ci *pmeth = NULL; 654e1051a39Sopenharmony_ci return 0; 655e1051a39Sopenharmony_ci} 656e1051a39Sopenharmony_ci 657e1051a39Sopenharmony_ci#endif 658e1051a39Sopenharmony_ci 659e1051a39Sopenharmony_ciint openssl_destroy(ENGINE *e) 660e1051a39Sopenharmony_ci{ 661e1051a39Sopenharmony_ci test_sha_md_destroy(); 662e1051a39Sopenharmony_ci#ifdef TEST_ENG_OPENSSL_RC4 663e1051a39Sopenharmony_ci test_r4_cipher_destroy(); 664e1051a39Sopenharmony_ci test_r4_40_cipher_destroy(); 665e1051a39Sopenharmony_ci#endif 666e1051a39Sopenharmony_ci return 1; 667e1051a39Sopenharmony_ci} 668e1051a39Sopenharmony_ci 669