/*
 * lws-api-test-gencrypto - lws-genrsa
 *
 * Written in 2010-2018 by Andy Green <andy@warmcat.com>
 *
 * This file is made available under the Creative Commons CC0 1.0
 * Universal Public Domain Dedication.
 */

 #include <libwebsockets.h>
 #include <stdlib.h>
 
 #if !defined(LWS_WITH_GNUTLS) && !(defined(LWS_WITH_MBEDTLS) && defined(MBEDTLS_VERSION_NUMBER) && MBEDTLS_VERSION_NUMBER >= 0x03000000)
 static int
 test_genrsa_roundtrips(struct lws_context *context)
 {
     static const uint8_t priv_plain[] = "private encrypt roundtrip";
     static const uint8_t pub_plain[] = "public encrypt roundtrip";
     struct lws_genrsa_ctx priv_ctx, pub_ctx;
     struct lws_gencrypto_keyelem el[LWS_GENCRYPTO_RSA_KEYEL_COUNT];
     struct lws_gencrypto_keyelem pub_el[LWS_GENCRYPTO_RSA_KEYEL_COUNT];
     uint8_t *cipher = NULL, *plain = NULL;
     size_t key_bytes;
     int n;
     int ret = 1;
 
     memset(&priv_ctx, 0, sizeof(priv_ctx));
     memset(&pub_ctx, 0, sizeof(pub_ctx));
     memset(el, 0, sizeof(el));
     memset(pub_el, 0, sizeof(pub_el));
 
     if (lws_genrsa_new_keypair(context, &priv_ctx, LGRSAM_PKCS1_1_5, el,
                    2048)) {
         lwsl_err("%s: lws_genrsa_new_keypair failed\n", __func__);
         goto bail;
     }
 
     pub_el[LWS_GENCRYPTO_RSA_KEYEL_E] = el[LWS_GENCRYPTO_RSA_KEYEL_E];
     pub_el[LWS_GENCRYPTO_RSA_KEYEL_N] = el[LWS_GENCRYPTO_RSA_KEYEL_N];
 
     if (lws_genrsa_create(&pub_ctx, pub_el, context, LGRSAM_PKCS1_1_5,
                   LWS_GENHASH_TYPE_UNKNOWN)) {
         lwsl_err("%s: lws_genrsa_create public ctx failed\n", __func__);
         goto bail;
     }
 
     key_bytes = el[LWS_GENCRYPTO_RSA_KEYEL_N].len;
     cipher = malloc(key_bytes);
     plain = malloc(key_bytes);
     if (!cipher || !plain) {
         lwsl_err("%s: OOM allocating test buffers\n", __func__);
         goto bail;
     }
 
     n = lws_genrsa_private_encrypt(&priv_ctx, priv_plain,
                        sizeof(priv_plain) - 1, cipher);
     if (n < 0) {
         lwsl_err("%s: lws_genrsa_private_encrypt failed\n", __func__);
         goto bail;
     }
 
     n = lws_genrsa_public_decrypt(&pub_ctx, cipher, (size_t)n, plain,
                       key_bytes);
     if (n != (int)(sizeof(priv_plain) - 1) ||
         lws_timingsafe_bcmp(plain, priv_plain, sizeof(priv_plain) - 1)) {
         lwsl_err("%s: private->public roundtrip mismatch\n", __func__);
         goto bail;
     }
 
     n = lws_genrsa_public_encrypt(&pub_ctx, pub_plain, sizeof(pub_plain) - 1,
                       cipher);
     if (n < 0) {
         lwsl_err("%s: lws_genrsa_public_encrypt failed\n", __func__);
         goto bail;
     }
 
     n = lws_genrsa_private_decrypt(&priv_ctx, cipher, (size_t)n, plain,
                        key_bytes);
     if (n != (int)(sizeof(pub_plain) - 1) ||
         lws_timingsafe_bcmp(plain, pub_plain, sizeof(pub_plain) - 1)) {
         lwsl_err("%s: public->private roundtrip mismatch\n", __func__);
         goto bail;
     }
 
     ret = 0;
 
 bail:
     if (cipher)
         free(cipher);
     if (plain)
         free(plain);
     lws_genrsa_destroy(&pub_ctx);
     lws_genrsa_destroy(&priv_ctx);
     lws_genrsa_destroy_elements(el);
 
     return ret;
 }
 
static const uint8_t genrsa_fixed_plain[] = {
    0x63, 0x72, 0x6F, 0x73, 0x73, 0x20, 0x62, 0x61, 0x63, 0x6B, 0x65, 0x6E, 
    0x64, 0x20, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x20, 0x65, 0x6E, 
    0x63
};


static const uint8_t genrsa_fixed_e[] = {
    0x01, 0x00, 0x01
};
static const uint8_t genrsa_fixed_n[] = {
    0xBB, 0xC6, 0x88, 0x34, 0x96, 0xAC, 0xE5, 0x7C, 0xE1, 0x5B, 0xCD, 0x0B, 
    0x7D, 0x13, 0x81, 0xBB, 0x33, 0x03, 0xB3, 0x6A, 0x7D, 0x38, 0x5A, 0xF8, 
    0xEE, 0x51, 0x56, 0x1A, 0x81, 0xE4, 0x17, 0x2F, 0x17, 0xF8, 0xD9, 0x10, 
    0xA7, 0x7A, 0x12, 0x86, 0x02, 0xD9, 0x58, 0xF6, 0x40, 0x2B, 0xA7, 0x4A, 
    0x66, 0xDE, 0x04, 0x5E, 0x1E, 0xE0, 0x95, 0xCB, 0xE6, 0xC4, 0xCC, 0x12, 
    0xB6, 0x40, 0xDB, 0x4D, 0x62, 0xA6, 0x50, 0x7A, 0x74, 0xC3, 0x48, 0xC6, 
    0xD0, 0x5B, 0x0A, 0x5D, 0x99, 0xCC, 0x4C, 0x4C, 0xDB, 0x98, 0x9F, 0xBE, 
    0x93, 0xC8, 0x70, 0xAF, 0xF9, 0xA3, 0x16, 0x02, 0x3B, 0x13, 0x8F, 0x5B, 
    0xB0, 0x67, 0x4C, 0x08, 0x5B, 0x51, 0xA2, 0x99, 0x5C, 0xB9, 0x54, 0x03, 
    0xAC, 0x01, 0x5D, 0x2D, 0xE8, 0xFB, 0x27, 0x9F, 0x45, 0xDF, 0x38, 0x06, 
    0x77, 0xCD, 0x93, 0xC2, 0x1B, 0x01, 0x22, 0x90, 0x82, 0x44, 0x6B, 0x81, 
    0x97, 0x13, 0x74, 0x3E, 0x25, 0xF1, 0xE7, 0x7B, 0xEE, 0xC8, 0xF7, 0xA7, 
    0xA3, 0x10, 0x93, 0x3A, 0x97, 0x87, 0x58, 0x97, 0xBF, 0x8D, 0x4F, 0x25, 
    0x9E, 0xDB, 0x39, 0xD2, 0xD6, 0xAE, 0x69, 0x64, 0x1E, 0x49, 0x93, 0x2E, 
    0x59, 0x51, 0x79, 0xB7, 0xED, 0x18, 0xC0, 0x7F, 0x4B, 0xBB, 0xAD, 0xDA, 
    0xC4, 0xB8, 0x76, 0x14, 0x78, 0x58, 0x6E, 0xF1, 0x33, 0xD1, 0x3C, 0xCA, 
    0xDE, 0xFB, 0x30, 0x6C, 0xD0, 0xBB, 0x8A, 0x9A, 0xBD, 0x7D, 0x24, 0x70, 
    0xC3, 0x82, 0x1B, 0x68, 0x34, 0x6A, 0xEF, 0x11, 0x77, 0x27, 0x25, 0x0B, 
    0x0F, 0x2B, 0xBC, 0xE2, 0x6F, 0xB4, 0x74, 0x96, 0xF7, 0x67, 0xE3, 0x3C, 
    0x41, 0xE8, 0x1D, 0xEB, 0x35, 0x85, 0xEC, 0x7B, 0x29, 0x32, 0x91, 0x42, 
    0x93, 0xBE, 0x5B, 0x4A, 0x36, 0x71, 0x4F, 0x0E, 0x03, 0xD6, 0x75, 0x83, 
    0xBE, 0x3A, 0x38, 0x8B
};
static const uint8_t genrsa_fixed_d[] = {
    0x3C, 0x64, 0x12, 0x0B, 0x43, 0xC8, 0x70, 0x78, 0x34, 0xEC, 0x76, 0xEA, 
    0x32, 0x7C, 0x53, 0x15, 0x77, 0x47, 0x41, 0xED, 0x46, 0x3F, 0x99, 0x36, 
    0x85, 0x43, 0x20, 0x7B, 0x9E, 0xF9, 0xD2, 0x21, 0x01, 0xC7, 0x35, 0x5C, 
    0x9F, 0x58, 0x69, 0xDB, 0xB2, 0xCF, 0xDF, 0x46, 0x37, 0x86, 0x32, 0xA4, 
    0x01, 0xA8, 0x76, 0xE4, 0x24, 0x6F, 0x1B, 0x8E, 0x3B, 0xF6, 0x60, 0x21, 
    0xC6, 0x7E, 0xDE, 0x69, 0x29, 0x88, 0x8E, 0xCA, 0x8B, 0x82, 0x01, 0x06, 
    0x7C, 0x1D, 0x43, 0x9C, 0xAD, 0xE9, 0xA0, 0x42, 0x79, 0xBF, 0xC0, 0xE4, 
    0xA4, 0x97, 0xEA, 0xF2, 0x15, 0xCA, 0x07, 0x3A, 0x89, 0x70, 0x75, 0x83, 
    0x4A, 0x1D, 0x36, 0xBD, 0x5B, 0x4D, 0x4A, 0x8B, 0xA3, 0x60, 0x31, 0x6E, 
    0x8A, 0xE3, 0xD7, 0x69, 0x7C, 0x0C, 0x46, 0x86, 0x79, 0x8C, 0xDC, 0x72, 
    0x6C, 0x16, 0x70, 0x66, 0x95, 0x93, 0xCC, 0x5E, 0xFB, 0x6F, 0x27, 0x9A, 
    0x5B, 0x4F, 0xAD, 0xF5, 0xFF, 0xB2, 0x28, 0xB6, 0x6D, 0xAE, 0x03, 0x86, 
    0x8B, 0x0D, 0x35, 0x23, 0x1D, 0xFB, 0x4A, 0xFC, 0x24, 0x4E, 0x0D, 0xBB, 
    0x75, 0x94, 0x7A, 0x8C, 0x93, 0x10, 0x34, 0xEB, 0xAE, 0x0D, 0xDD, 0x4D, 
    0x7A, 0x41, 0xAE, 0x50, 0x4E, 0xA1, 0xA9, 0xC8, 0x61, 0xB6, 0xAF, 0xB4, 
    0xA7, 0x11, 0xF8, 0x28, 0xDC, 0x98, 0xED, 0x77, 0xA6, 0x3B, 0x0B, 0xE3, 
    0xD0, 0x31, 0x9F, 0x7C, 0x2D, 0x60, 0xE4, 0x9D, 0x9A, 0x1F, 0x88, 0xAD, 
    0x34, 0xAF, 0xB7, 0xA4, 0x26, 0x1A, 0x51, 0x10, 0x92, 0x80, 0x5C, 0x66, 
    0x2F, 0x5A, 0xB9, 0x1E, 0x90, 0x02, 0xCB, 0x01, 0xDE, 0x37, 0x34, 0xBE, 
    0x1D, 0x69, 0x39, 0x18, 0xFF, 0xAD, 0x8D, 0x98, 0xB1, 0xDA, 0x9D, 0xC6, 
    0xF6, 0x67, 0x8A, 0x3D, 0x37, 0x3E, 0xE5, 0x4E, 0xBF, 0x92, 0xC1, 0x13, 
    0xCE, 0xCB, 0xAE, 0x01
};
static const uint8_t genrsa_fixed_p[] = {
    0xE5, 0xCB, 0xA6, 0x73, 0x0E, 0xBE, 0x29, 0xA5, 0x59, 0x57, 0xD6, 0x1A, 
    0xE9, 0x14, 0x28, 0xD7, 0xB7, 0xB4, 0xF5, 0xC1, 0x68, 0x95, 0xFD, 0x78, 
    0x24, 0xDF, 0x28, 0xFC, 0x16, 0xCA, 0x09, 0xFE, 0x01, 0x3B, 0xB8, 0x6F, 
    0x72, 0x2A, 0xE5, 0x1B, 0xFA, 0x8E, 0xD6, 0x3E, 0x63, 0x8E, 0xBE, 0x21, 
    0xF7, 0x0C, 0xEA, 0x2B, 0xEA, 0x77, 0x42, 0x1D, 0x6F, 0x7B, 0x76, 0xA4, 
    0x26, 0x6A, 0x6E, 0xC5, 0xED, 0xBF, 0x62, 0x0B, 0x38, 0xFB, 0xEA, 0x0C, 
    0xC6, 0xF3, 0x73, 0x57, 0xB6, 0x97, 0xB8, 0xF1, 0xBC, 0x31, 0xC8, 0xC0, 
    0x56, 0xE6, 0xB6, 0x30, 0x96, 0x0D, 0xBB, 0xD0, 0xCD, 0xEF, 0xDA, 0xD4, 
    0xF1, 0xC7, 0xAF, 0xDD, 0x7B, 0x28, 0x7D, 0xA1, 0xEE, 0x76, 0x32, 0x6D, 
    0x89, 0xF3, 0x16, 0xC4, 0xB6, 0xC8, 0x83, 0x2B, 0x69, 0x8A, 0xE4, 0x25, 
    0xD2, 0x98, 0x7C, 0x2A, 0x88, 0xB4, 0xA2, 0x8B
};
static const uint8_t genrsa_fixed_q[] = {
    0xD1, 0x30, 0x34, 0x81, 0x50, 0xEB, 0x0E, 0x5E, 0xD8, 0x26, 0x82, 0x59, 
    0xC8, 0xE7, 0xE5, 0x63, 0xE8, 0x3A, 0x31, 0xAE, 0xCE, 0x13, 0x84, 0x18, 
    0xFC, 0xC5, 0xB2, 0xF4, 0x59, 0x15, 0x1A, 0x2C, 0xCF, 0x38, 0x4E, 0xA9, 
    0x90, 0x5D, 0xD2, 0x25, 0x71, 0xB6, 0x30, 0x3C, 0xA8, 0x68, 0x5A, 0xCB, 
    0xE9, 0x32, 0xEA, 0x88, 0x68, 0x80, 0xCB, 0x7A, 0x5C, 0xC9, 0x3E, 0x9E, 
    0x07, 0xF5, 0x3C, 0x41, 0x44, 0xCD, 0x74, 0x65, 0x81, 0x5C, 0xFE, 0x0D, 
    0x45, 0x57, 0xE0, 0xFA, 0xAB, 0x75, 0xB4, 0x13, 0xBD, 0x9F, 0xB9, 0x47, 
    0xD8, 0x8C, 0xF6, 0xC7, 0xEA, 0xE4, 0x89, 0x8E, 0xE9, 0xA8, 0xEB, 0xA2, 
    0xC7, 0xD8, 0x94, 0xCF, 0x96, 0xE2, 0x6D, 0xEB, 0xED, 0xC7, 0x32, 0x17, 
    0x7D, 0xB2, 0xA9, 0x02, 0x30, 0x14, 0x3E, 0x38, 0x3A, 0x3D, 0x6D, 0xAC, 
    0xA9, 0x71, 0x06, 0xC4, 0xC7, 0x51, 0x82, 0x01
};
static const uint8_t genrsa_expected_priv_enc[] = {
    0x8E, 0x5E, 0x14, 0x60, 0xC2, 0x58, 0xD7, 0xC9, 0x6C, 0x62, 0x7F, 0x41, 
    0x79, 0x64, 0xED, 0x4D, 0x97, 0xED, 0xCB, 0xEA, 0xA4, 0xCA, 0xB2, 0xA5, 
    0x98, 0xDD, 0x34, 0x45, 0x3B, 0xAB, 0xBF, 0x3C, 0x64, 0x32, 0x51, 0x00, 
    0xB2, 0xFF, 0x76, 0xBF, 0x80, 0x6D, 0xA3, 0x1F, 0xE8, 0xB2, 0x57, 0xD3, 
    0x23, 0x37, 0x5D, 0x0B, 0x29, 0x46, 0x9B, 0xDE, 0x84, 0x00, 0xCC, 0x92, 
    0xA0, 0xC7, 0xCE, 0x41, 0x7C, 0x18, 0xC9, 0x74, 0xF0, 0x5C, 0xF9, 0xD3, 
    0x2A, 0xFC, 0x84, 0x79, 0xBA, 0x5A, 0xBA, 0xB6, 0xE9, 0x43, 0xD9, 0xE3, 
    0x00, 0xD8, 0xE5, 0xD4, 0x84, 0x94, 0xF1, 0x29, 0x10, 0x80, 0xED, 0xEF, 
    0xE5, 0xD4, 0x57, 0xBC, 0x8C, 0x48, 0x0A, 0x09, 0x0A, 0xBD, 0x75, 0x27, 
    0x45, 0x0A, 0x5C, 0x3B, 0x67, 0x1E, 0x07, 0xC1, 0xC1, 0x44, 0x70, 0xD9, 
    0x6D, 0x4F, 0x73, 0x8E, 0x3F, 0x71, 0xA5, 0xDC, 0x00, 0x25, 0xB6, 0x56, 
    0xAB, 0x2D, 0x49, 0x98, 0x68, 0x60, 0x9D, 0x14, 0x3E, 0x25, 0x1F, 0xDD, 
    0xDF, 0x1C, 0x83, 0x28, 0x4C, 0xB2, 0x6A, 0xA9, 0xC0, 0x99, 0x3B, 0x89, 
    0x2F, 0x46, 0x77, 0xAE, 0xDD, 0x50, 0xCB, 0xED, 0x32, 0xD3, 0xC4, 0xB2, 
    0x0C, 0xF1, 0xA8, 0x12, 0x9B, 0x33, 0x6A, 0x0D, 0x11, 0x37, 0xDD, 0xFC, 
    0x17, 0x31, 0xA9, 0x56, 0x9D, 0x87, 0xD3, 0xB2, 0x24, 0x39, 0xE5, 0x26, 
    0xB9, 0x42, 0x22, 0x8E, 0xEC, 0xC3, 0xB5, 0x9F, 0xF3, 0x0E, 0x73, 0xE0, 
    0x68, 0x82, 0x84, 0x72, 0x59, 0x1A, 0xC9, 0x62, 0x5E, 0x7E, 0x8B, 0xF7, 
    0x36, 0x71, 0x90, 0xD9, 0x96, 0x40, 0x07, 0x01, 0x8A, 0xAF, 0x42, 0x83, 
    0x90, 0xD2, 0x6F, 0x24, 0x48, 0xEC, 0x34, 0xF8, 0x61, 0xBF, 0x0F, 0x8A, 
    0x60, 0x1D, 0x4A, 0x54, 0xB3, 0x7D, 0x21, 0x4B, 0x29, 0xFB, 0x3B, 0x4C, 
    0xB6, 0x8D, 0x99, 0x4A
};

static void
test_genrsa_prepare_public_elements(struct lws_gencrypto_keyelem *dest,
				    const struct lws_gencrypto_keyelem *src)
{
	memset(dest, 0, sizeof(*dest) * LWS_GENCRYPTO_RSA_KEYEL_COUNT);
	dest[LWS_GENCRYPTO_RSA_KEYEL_E] = src[LWS_GENCRYPTO_RSA_KEYEL_E];
	dest[LWS_GENCRYPTO_RSA_KEYEL_N] = src[LWS_GENCRYPTO_RSA_KEYEL_N];
}

static int
test_genrsa_fixed_vectors(struct lws_context *context)
{
	struct lws_genrsa_ctx priv_ctx, pub_ctx;
	struct lws_gencrypto_keyelem priv_el[LWS_GENCRYPTO_RSA_KEYEL_COUNT];
	struct lws_gencrypto_keyelem pub_el[LWS_GENCRYPTO_RSA_KEYEL_COUNT];
	uint8_t *cipher = NULL, *plain = NULL;
	size_t key_bytes = sizeof(genrsa_fixed_n);
	int n;
	int ret = 1;

	memset(&priv_ctx, 0, sizeof(priv_ctx));
	memset(&pub_ctx, 0, sizeof(pub_ctx));
	memset(priv_el, 0, sizeof(priv_el));
	memset(pub_el, 0, sizeof(pub_el));

	priv_el[LWS_GENCRYPTO_RSA_KEYEL_E].buf = (uint8_t *)(uintptr_t)genrsa_fixed_e;
	priv_el[LWS_GENCRYPTO_RSA_KEYEL_E].len = (uint32_t)sizeof(genrsa_fixed_e);
	priv_el[LWS_GENCRYPTO_RSA_KEYEL_N].buf = (uint8_t *)(uintptr_t)genrsa_fixed_n;
	priv_el[LWS_GENCRYPTO_RSA_KEYEL_N].len = (uint32_t)sizeof(genrsa_fixed_n);
	priv_el[LWS_GENCRYPTO_RSA_KEYEL_D].buf = (uint8_t *)(uintptr_t)genrsa_fixed_d;
	priv_el[LWS_GENCRYPTO_RSA_KEYEL_D].len = (uint32_t)sizeof(genrsa_fixed_d);
	priv_el[LWS_GENCRYPTO_RSA_KEYEL_P].buf = (uint8_t *)(uintptr_t)genrsa_fixed_p;
	priv_el[LWS_GENCRYPTO_RSA_KEYEL_P].len = (uint32_t)sizeof(genrsa_fixed_p);
	priv_el[LWS_GENCRYPTO_RSA_KEYEL_Q].buf = (uint8_t *)(uintptr_t)genrsa_fixed_q;
	priv_el[LWS_GENCRYPTO_RSA_KEYEL_Q].len = (uint32_t)sizeof(genrsa_fixed_q);
	test_genrsa_prepare_public_elements(pub_el, priv_el);

	if (lws_genrsa_create(&priv_ctx, priv_el, context, LGRSAM_PKCS1_1_5,
			      LWS_GENHASH_TYPE_UNKNOWN)) {
		lwsl_err("%s: lws_genrsa_create private ctx failed\n", __func__);
		goto bail;
	}

	if (lws_genrsa_create(&pub_ctx, pub_el, context, LGRSAM_PKCS1_1_5,
			      LWS_GENHASH_TYPE_UNKNOWN)) {
		lwsl_err("%s: lws_genrsa_create public ctx failed\n", __func__);
		goto bail;
	}

	cipher = malloc(key_bytes);
	plain = malloc(key_bytes);
	if (!cipher || !plain) {
		lwsl_err("%s: OOM allocating fixed test buffers\n", __func__);
		goto bail;
	}

	n = lws_genrsa_private_encrypt(&priv_ctx, genrsa_fixed_plain,
				       sizeof(genrsa_fixed_plain) - 1, cipher);
	if (n != (int)sizeof(genrsa_expected_priv_enc) ||
	    lws_timingsafe_bcmp(cipher, genrsa_expected_priv_enc,
				sizeof(genrsa_expected_priv_enc))) {
		lwsl_err("%s: fixed private_encrypt mismatch\n", __func__);
		goto bail;
	}

	n = lws_genrsa_public_decrypt(&pub_ctx, genrsa_expected_priv_enc,
				      sizeof(genrsa_expected_priv_enc), plain,
				      key_bytes);
	if (n != (int)(sizeof(genrsa_fixed_plain) - 1) ||
	    lws_timingsafe_bcmp(plain, genrsa_fixed_plain,
				sizeof(genrsa_fixed_plain) - 1)) {
		lwsl_err("%s: fixed public_decrypt mismatch\n", __func__);
		goto bail;
	}

	ret = 0;

bail:
	if (cipher)
		free(cipher);
	if (plain)
		free(plain);
	lws_genrsa_destroy(&pub_ctx);
	lws_genrsa_destroy(&priv_ctx);

	return ret;
}
#endif

int
test_genrsa(struct lws_context *context)
{
#if !defined(LWS_WITH_GNUTLS) && !(defined(LWS_WITH_MBEDTLS) && defined(MBEDTLS_VERSION_NUMBER) && MBEDTLS_VERSION_NUMBER >= 0x03000000)
	if (test_genrsa_roundtrips(context))
		goto bail;

	if (test_genrsa_fixed_vectors(context))
		goto bail;
#else
	lwsl_notice("%s: Skipping RSA encrypt/decrypt tests (unsupported on this backend)\n", __func__);
#endif

	lwsl_notice("%s: selftest OK\n", __func__);

	return 0;

#if !defined(LWS_WITH_GNUTLS) && !(defined(LWS_WITH_MBEDTLS) && defined(MBEDTLS_VERSION_NUMBER) && MBEDTLS_VERSION_NUMBER >= 0x03000000)
bail:
	lwsl_err("%s: selftest failed ++++++++++++++++++++\n", __func__);

	return 1;
#endif
}
