From 2d5d70b15559f9813054ddb11b30b816daf62ebe Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Tue, 16 Jun 2015 12:59:37 +0100 Subject: [PATCH] Add OSSLTest Engine This engine is for testing purposes only. It provides crippled crypto implementations and therefore must not be used in any instance where security is required. This will be used by the forthcoming libssl test harness which will operate as a man-in-the-middle proxy. The test harness will be able to modify TLS packets and read their contents. By using this test engine packets are not encrypted and MAC codes always verify. Reviewed-by: Richard Levitte --- engines/Makefile | 23 +- engines/e_ossltest.c | 542 +++++++++++++++++++++++++++++++++++++++ engines/e_ossltest.ec | 1 + engines/e_ossltest_err.c | 133 ++++++++++ engines/e_ossltest_err.h | 83 ++++++ 5 files changed, 779 insertions(+), 3 deletions(-) create mode 100644 engines/e_ossltest.c create mode 100644 engines/e_ossltest.ec create mode 100644 engines/e_ossltest_err.c create mode 100644 engines/e_ossltest_err.h diff --git a/engines/Makefile b/engines/Makefile index e9dc1c47cc..c0b7c03493 100644 --- a/engines/Makefile +++ b/engines/Makefile @@ -31,16 +31,18 @@ AFLAGS= $(ASFLAGS) GENERAL=Makefile engines.com install.com engine_vector.mar LIB=$(TOP)/libcrypto.a -LIBNAMES= 4758cca gmp padlock capi +LIBNAMES= 4758cca gmp padlock capi ossltest LIBSRC= e_4758cca.c \ e_gmp.c \ e_padlock.c \ - e_capi.c + e_capi.c \ + e_ossltest.c LIBOBJ= e_4758cca.o \ e_gmp.o \ e_padlock.o \ e_capi.o \ + e_ossltest.o \ $(ENGINES_ASM_OBJ) SRC= $(LIBSRC) @@ -51,7 +53,8 @@ HEADER= e_4758cca_err.c e_4758cca_err.h \ e_nuron_err.c e_nuron_err.h \ e_sureware_err.c e_sureware_err.h \ e_ubsec_err.c e_ubsec_err.h \ - e_capi_err.c e_capi_err.h + e_capi_err.c e_capi_err.h \ + e_ossltest_err.c e_ossltest_err.h ALL= $(GENERAL) $(SRC) $(HEADER) @@ -183,6 +186,20 @@ e_capi.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h e_capi.o: ../include/openssl/sha.h ../include/openssl/stack.h e_capi.o: ../include/openssl/symhacks.h ../include/openssl/x509.h e_capi.o: ../include/openssl/x509_vfy.h e_capi.c +e_ossltest.o: ../include/openssl/asn1.h ../include/openssl/bio.h +e_ossltest.o: ../include/openssl/buffer.h ../include/openssl/crypto.h +e_ossltest.o: ../include/openssl/e_os2.h ../include/openssl/ec.h +e_ossltest.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h +e_ossltest.o: ../include/openssl/engine.h ../include/openssl/err.h +e_ossltest.o: ../include/openssl/evp.h ../include/openssl/lhash.h +e_ossltest.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h +e_ossltest.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +e_ossltest.o: ../include/openssl/ossl_typ.h ../include/openssl/pkcs7.h +e_ossltest.o: ../include/openssl/rsa.h ../include/openssl/safestack.h +e_ossltest.o: ../include/openssl/sha.h ../include/openssl/stack.h +e_ossltest.o: ../include/openssl/symhacks.h ../include/openssl/x509.h +e_ossltest.o: ../include/openssl/x509_vfy.h e_ossltest.c e_ossltest_err.c +e_ossltest.o: e_ossltest_err.h e_gmp.o: ../include/openssl/asn1.h ../include/openssl/bio.h e_gmp.o: ../include/openssl/bn.h ../include/openssl/buffer.h e_gmp.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h diff --git a/engines/e_ossltest.c b/engines/e_ossltest.c new file mode 100644 index 0000000000..689e5321ca --- /dev/null +++ b/engines/e_ossltest.c @@ -0,0 +1,542 @@ +/* engines/e_ossltest.c */ +/* + * Written by Matt Caswell (matt@openssl.org) for the OpenSSL project. + */ +/* ==================================================================== + * Copyright (c) 2015 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ + +/* + * This is the OSSLTEST engine. It provides deliberately crippled digest + * implementations for test purposes. It is highly insecure and must NOT be + * used for any purpose except testing + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define OSSLTEST_LIB_NAME "OSSLTEST" +#include "e_ossltest_err.c" + +/* Engine Id and Name */ +static const char *engine_ossltest_id = "ossltest"; +static const char *engine_ossltest_name = "OpenSSL Test engine support"; + + +/* Engine Lifetime functions */ +static int ossltest_destroy(ENGINE *e); +static int ossltest_init(ENGINE *e); +static int ossltest_finish(ENGINE *e); +void ENGINE_load_ossltest(void); + + +/* Set up digests */ +static int ossltest_digests(ENGINE *e, const EVP_MD **digest, + const int **nids, int nid); + +static int ossltest_digest_nids[] = { + NID_md5, NID_sha1, NID_sha256, NID_sha384, NID_sha512, 0 +}; + +/* MD5 */ +static int digest_md5_init(EVP_MD_CTX *ctx); +static int digest_md5_update(EVP_MD_CTX *ctx, const void *data, + unsigned long count); +static int digest_md5_final(EVP_MD_CTX *ctx, unsigned char *md); + +static const EVP_MD digest_md5 = { + NID_md5, + NID_md5WithRSAEncryption, + MD5_DIGEST_LENGTH, + 0, + digest_md5_init, + digest_md5_update, + digest_md5_final, + NULL, + NULL, + EVP_PKEY_RSA_method, + MD5_CBLOCK, + sizeof(EVP_MD *) + sizeof(MD5_CTX), +}; + +/* SHA1 */ +static int digest_sha1_init(EVP_MD_CTX *ctx); +static int digest_sha1_update(EVP_MD_CTX *ctx, const void *data, + unsigned long count); +static int digest_sha1_final(EVP_MD_CTX *ctx, unsigned char *md); + +static const EVP_MD digest_sha1 = { + NID_sha1, + NID_sha1WithRSAEncryption, + SHA_DIGEST_LENGTH, + EVP_MD_FLAG_PKEY_METHOD_SIGNATURE | EVP_MD_FLAG_DIGALGID_ABSENT, + digest_sha1_init, + digest_sha1_update, + digest_sha1_final, + NULL, + NULL, + EVP_PKEY_NULL_method, + SHA_CBLOCK, + sizeof(EVP_MD *) + sizeof(SHA_CTX), +}; + +/* SHA256 */ +static int digest_sha256_init(EVP_MD_CTX *ctx); +static int digest_sha256_update(EVP_MD_CTX *ctx, const void *data, + unsigned long count); +static int digest_sha256_final(EVP_MD_CTX *ctx, unsigned char *md); + +static const EVP_MD digest_sha256 = { + NID_sha256, + NID_sha256WithRSAEncryption, + SHA256_DIGEST_LENGTH, + EVP_MD_FLAG_PKEY_METHOD_SIGNATURE | EVP_MD_FLAG_DIGALGID_ABSENT, + digest_sha256_init, + digest_sha256_update, + digest_sha256_final, + NULL, + NULL, + EVP_PKEY_NULL_method, + SHA256_CBLOCK, + sizeof(EVP_MD *) + sizeof(SHA256_CTX), +}; + +/* SHA384/SHA512 */ +static int digest_sha384_init(EVP_MD_CTX *ctx); +static int digest_sha512_init(EVP_MD_CTX *ctx); +static int digest_sha512_update(EVP_MD_CTX *ctx, const void *data, + unsigned long count); +static int digest_sha384_final(EVP_MD_CTX *ctx, unsigned char *md); +static int digest_sha512_final(EVP_MD_CTX *ctx, unsigned char *md); + +static const EVP_MD digest_sha384 = { + NID_sha384, + NID_sha384WithRSAEncryption, + SHA384_DIGEST_LENGTH, + EVP_MD_FLAG_PKEY_METHOD_SIGNATURE | EVP_MD_FLAG_DIGALGID_ABSENT, + digest_sha384_init, + digest_sha512_update, + digest_sha384_final, + NULL, + NULL, + EVP_PKEY_NULL_method, + SHA512_CBLOCK, + sizeof(EVP_MD *) + sizeof(SHA512_CTX), +}; + +static const EVP_MD digest_sha512 = { + NID_sha512, + NID_sha512WithRSAEncryption, + SHA512_DIGEST_LENGTH, + EVP_MD_FLAG_PKEY_METHOD_SIGNATURE | EVP_MD_FLAG_DIGALGID_ABSENT, + digest_sha512_init, + digest_sha512_update, + digest_sha512_final, + NULL, + NULL, + EVP_PKEY_NULL_method, + SHA512_CBLOCK, + sizeof(EVP_MD *) + sizeof(SHA512_CTX), +}; + +/* Setup ciphers */ +static int ossltest_ciphers(ENGINE *, const EVP_CIPHER **, + const int **, int); + +static int ossltest_cipher_nids[] = { + NID_aes_128_cbc, 0 +}; + +/* AES128 */ + +int ossltest_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, + const unsigned char *iv, int enc); +int ossltest_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + const unsigned char *in, size_t inl); + +/* + * Copy of the definition in crypto/evp/e_aes.c. Only used for the "sizeof" + * below + */ +typedef struct { + union { + double align; + AES_KEY ks; + } ks; + block128_f block; + union { + cbc128_f cbc; + ctr128_f ctr; + } stream; +} EVP_AES_KEY; + + +static const EVP_CIPHER ossltest_aes_128_cbc = { \ + NID_aes_128_cbc, + 16, /* block size */ + 16, /* key len */ + 16, /* iv len */ + EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CBC_MODE, + ossltest_aes128_init_key, + ossltest_aes128_cbc_cipher, + NULL, + sizeof(EVP_AES_KEY), + NULL,NULL,NULL,NULL +}; + + +static int bind_ossltest(ENGINE *e) +{ + /* Ensure the ossltest error handling is set up */ + ERR_load_OSSLTEST_strings(); + + if (!ENGINE_set_id(e, engine_ossltest_id) + || !ENGINE_set_name(e, engine_ossltest_name) + || !ENGINE_set_digests(e, ossltest_digests) + || !ENGINE_set_ciphers(e, ossltest_ciphers) + || !ENGINE_set_destroy_function(e, ossltest_destroy) + || !ENGINE_set_init_function(e, ossltest_init) + || !ENGINE_set_finish_function(e, ossltest_finish)) { + OSSLTESTerr(OSSLTEST_F_BIND_OSSLTEST, OSSLTEST_R_INIT_FAILED); + return 0; + } + + return 1; +} + +#ifdef ENGINE_DYNAMIC_SUPPORT +static int bind_helper(ENGINE *e, const char *id) +{ + if (id && (strcmp(id, engine_ossltest_id) != 0)) + return 0; + if (!bind_ossltest(e)) + return 0; + return 1; +} + +IMPLEMENT_DYNAMIC_CHECK_FN() + IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) +#else +static ENGINE *engine_ossltest(void) +{ + ENGINE *ret = ENGINE_new(); + if (!ret) + return NULL; + if (!bind_ossltest(ret)) { + ENGINE_free(ret); + return NULL; + } + return ret; +} + +void ENGINE_load_ossltest(void) +{ + /* Copied from eng_[openssl|dyn].c */ + ENGINE *toadd = engine_ossltest(); + if (!toadd) + return; + ENGINE_add(toadd); + ENGINE_free(toadd); + ERR_clear_error(); +} +#endif + + +static int ossltest_init(ENGINE *e) +{ + return 1; +} + + +static int ossltest_finish(ENGINE *e) +{ + return 1; +} + + +static int ossltest_destroy(ENGINE *e) +{ + ERR_unload_OSSLTEST_strings(); + return 1; +} + +static int ossltest_digests(ENGINE *e, const EVP_MD **digest, + const int **nids, int nid) +{ + int ok = 1; + if (!digest) { + /* We are returning a list of supported nids */ + *nids = ossltest_digest_nids; + return (sizeof(ossltest_digest_nids) - + 1) / sizeof(ossltest_digest_nids[0]); + } + /* We are being asked for a specific digest */ + switch (nid) { + case NID_md5: + *digest = &digest_md5; + break; + case NID_sha1: + *digest = &digest_sha1; + break; + case NID_sha256: + *digest = &digest_sha256; + break; + case NID_sha384: + *digest = &digest_sha384; + break; + case NID_sha512: + *digest = &digest_sha512; + break; + default: + ok = 0; + *digest = NULL; + break; + } + return ok; +} + +static int ossltest_ciphers(ENGINE *e, const EVP_CIPHER **cipher, + const int **nids, int nid) +{ + int ok = 1; + if (!cipher) { + /* We are returning a list of supported nids */ + *nids = ossltest_cipher_nids; + return (sizeof(ossltest_cipher_nids) - 1) + / sizeof(ossltest_cipher_nids[0]); + } + /* We are being asked for a specific cipher */ + switch (nid) { + case NID_aes_128_cbc: + *cipher = &ossltest_aes_128_cbc; + break; + default: + ok = 0; + *cipher = NULL; + break; + } + return ok; +} + +static void fill_known_data(unsigned char *md, unsigned int len) +{ + unsigned int i; + + for (i=0; imd_data) +static int digest_md5_init(EVP_MD_CTX *ctx) +{ + return MD5_Init(data(ctx)); +} + +static int digest_md5_update(EVP_MD_CTX *ctx, const void *data, + unsigned long count) +{ + return MD5_Update(data(ctx), data, (size_t)count); +} + +static int digest_md5_final(EVP_MD_CTX *ctx, unsigned char *md) +{ + int ret; + ret = MD5_Final(md, data(ctx)); + + if (ret > 0) { + fill_known_data(md, MD5_DIGEST_LENGTH); + } + return ret; +} + +/* + * SHA1 implementation. + */ +#undef data +#define data(ctx) ((SHA_CTX *)(ctx)->md_data) +static int digest_sha1_init(EVP_MD_CTX *ctx) +{ + return SHA1_Init(data(ctx)); +} + +static int digest_sha1_update(EVP_MD_CTX *ctx, const void *data, + unsigned long count) +{ + return SHA1_Update(data(ctx), data, (size_t)count); +} + +static int digest_sha1_final(EVP_MD_CTX *ctx, unsigned char *md) +{ + int ret; + ret = SHA1_Final(md, data(ctx)); + + if (ret > 0) { + fill_known_data(md, SHA_DIGEST_LENGTH); + } + return ret; +} + +/* + * SHA256 implementation. + */ +#undef data +#define data(ctx) ((SHA256_CTX *)(ctx)->md_data) +static int digest_sha256_init(EVP_MD_CTX *ctx) +{ + return SHA256_Init(data(ctx)); +} + +static int digest_sha256_update(EVP_MD_CTX *ctx, const void *data, + unsigned long count) +{ + return SHA256_Update(data(ctx), data, (size_t)count); +} + +static int digest_sha256_final(EVP_MD_CTX *ctx, unsigned char *md) +{ + int ret; + ret = SHA256_Final(md, data(ctx)); + + if (ret > 0) { + fill_known_data(md, SHA256_DIGEST_LENGTH); + } + return ret; +} + +/* + * SHA384/512 implementation. + */ +#undef data +#define data(ctx) ((SHA512_CTX *)(ctx)->md_data) +static int digest_sha384_init(EVP_MD_CTX *ctx) +{ + return SHA384_Init(data(ctx)); +} + +static int digest_sha512_init(EVP_MD_CTX *ctx) +{ + return SHA512_Init(data(ctx)); +} + +static int digest_sha512_update(EVP_MD_CTX *ctx, const void *data, + unsigned long count) +{ + return SHA512_Update(data(ctx), data, (size_t)count); +} + +static int digest_sha384_final(EVP_MD_CTX *ctx, unsigned char *md) +{ + int ret; + /* Actually uses SHA512_Final! */ + ret = SHA512_Final(md, data(ctx)); + + if (ret > 0) { + fill_known_data(md, SHA384_DIGEST_LENGTH); + } + return ret; +} + +static int digest_sha512_final(EVP_MD_CTX *ctx, unsigned char *md) +{ + int ret; + ret = SHA512_Final(md, data(ctx)); + + if (ret > 0) { + fill_known_data(md, SHA512_DIGEST_LENGTH); + } + return ret; +} + +/* + * AES128 Implementation + */ + +int ossltest_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, + const unsigned char *iv, int enc) +{ + return EVP_aes_128_cbc()->init(ctx, key, iv, enc); +} + +int ossltest_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + const unsigned char *in, size_t inl) +{ + unsigned char *tmpbuf; + int ret; + + tmpbuf = OPENSSL_malloc(inl); + if (tmpbuf == NULL) + return -1; + + /* Remember what we were asked to encrypt */ + memcpy(tmpbuf, in, inl); + + /* Go through the motions of encrypting it */ + ret = EVP_aes_128_cbc()->do_cipher(ctx, out, in, inl); + + /* Throw it all away and just use the plaintext as the output */ + memcpy(out, tmpbuf, inl); + OPENSSL_free(tmpbuf); + + return ret; +} diff --git a/engines/e_ossltest.ec b/engines/e_ossltest.ec new file mode 100644 index 0000000000..d8a1befa20 --- /dev/null +++ b/engines/e_ossltest.ec @@ -0,0 +1 @@ +L OSSLTEST e_ossltest_err.h e_ossltest_err.c diff --git a/engines/e_ossltest_err.c b/engines/e_ossltest_err.c new file mode 100644 index 0000000000..c1b0063b9d --- /dev/null +++ b/engines/e_ossltest_err.c @@ -0,0 +1,133 @@ +/* e_ossltest_err.c */ +/* ==================================================================== + * Copyright (c) 1999-2015 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* + * NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file, + * only reason strings will be preserved. + */ + +#include +#include +#include "e_ossltest_err.h" + +/* BEGIN ERROR CODES */ +#ifndef OPENSSL_NO_ERR + +# define ERR_FUNC(func) ERR_PACK(0,func,0) +# define ERR_REASON(reason) ERR_PACK(0,0,reason) + +static ERR_STRING_DATA OSSLTEST_str_functs[] = { + {ERR_FUNC(OSSLTEST_F_BIND_OSSLTEST), "BIND_OSSLTEST"}, + {0, NULL} +}; + +static ERR_STRING_DATA OSSLTEST_str_reasons[] = { + {ERR_REASON(OSSLTEST_R_INIT_FAILED), "init failed"}, + {0, NULL} +}; + +#endif + +#ifdef OSSLTEST_LIB_NAME +static ERR_STRING_DATA OSSLTEST_lib_name[] = { + {0, OSSLTEST_LIB_NAME}, + {0, NULL} +}; +#endif + +static int OSSLTEST_lib_error_code = 0; +static int OSSLTEST_error_init = 1; + +static void ERR_load_OSSLTEST_strings(void) +{ + if (OSSLTEST_lib_error_code == 0) + OSSLTEST_lib_error_code = ERR_get_next_error_library(); + + if (OSSLTEST_error_init) { + OSSLTEST_error_init = 0; +#ifndef OPENSSL_NO_ERR + ERR_load_strings(OSSLTEST_lib_error_code, OSSLTEST_str_functs); + ERR_load_strings(OSSLTEST_lib_error_code, OSSLTEST_str_reasons); +#endif + +#ifdef OSSLTEST_LIB_NAME + OSSLTEST_lib_name->error = ERR_PACK(OSSLTEST_lib_error_code, 0, 0); + ERR_load_strings(0, OSSLTEST_lib_name); +#endif + } +} + +static void ERR_unload_OSSLTEST_strings(void) +{ + if (OSSLTEST_error_init == 0) { +#ifndef OPENSSL_NO_ERR + ERR_unload_strings(OSSLTEST_lib_error_code, OSSLTEST_str_functs); + ERR_unload_strings(OSSLTEST_lib_error_code, OSSLTEST_str_reasons); +#endif + +#ifdef OSSLTEST_LIB_NAME + ERR_unload_strings(0, OSSLTEST_lib_name); +#endif + OSSLTEST_error_init = 1; + } +} + +static void ERR_OSSLTEST_error(int function, int reason, char *file, int line) +{ + if (OSSLTEST_lib_error_code == 0) + OSSLTEST_lib_error_code = ERR_get_next_error_library(); + ERR_PUT_error(OSSLTEST_lib_error_code, function, reason, file, line); +} diff --git a/engines/e_ossltest_err.h b/engines/e_ossltest_err.h new file mode 100644 index 0000000000..8f874e00a0 --- /dev/null +++ b/engines/e_ossltest_err.h @@ -0,0 +1,83 @@ +/* ==================================================================== + * Copyright (c) 2015 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_OSSLTEST_ERR_H +# define HEADER_OSSLTEST_ERR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* BEGIN ERROR CODES */ +/* + * The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ +static void ERR_load_OSSLTEST_strings(void); +static void ERR_unload_OSSLTEST_strings(void); +static void ERR_OSSLTEST_error(int function, int reason, char *file, int line); +# define OSSLTESTerr(f,r) ERR_OSSLTEST_error((f),(r),__FILE__,__LINE__) + +/* Error codes for the OSSLTEST functions. */ + +/* Function codes. */ +# define OSSLTEST_F_BIND_OSSLTEST 100 + +/* Reason codes. */ +# define OSSLTEST_R_INIT_FAILED 100 + +#ifdef __cplusplus +} +#endif +#endif -- 2.34.1