/***********************************************************************************************************************
 * File Name    : rsa_thread_entry.c
 * Description  : Contains macros and functions used in rsa_thread_entry.c
 **********************************************************************************************************************/
/***********************************************************************************************************************
 * DISCLAIMER
 * This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. No
 * other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
 * applicable laws, including copyright laws.
 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. TO THE MAXIMUM
 * EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES
 * SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS
 * SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
 * this software. By using this software, you agree to the additional terms and conditions found by accessing the
 * following link:
 * http://www.renesas.com/disclaimer
 *
 * Copyright (C) 2020 Renesas Electronics Corporation. All rights reserved.
 ***********************************************************************************************************************/
#include "rsa_thread.h"
#include "rm_netx_secure_crypto.h"
#include "crypto_ep_definitions.h"
#include "common_utils.h"

/*******************************************************************************************************************//**
 * @addtogroup netx_crypto_ep
 * @{
 **********************************************************************************************************************/

/******************************************************************************
Macro definitions
 ******************************************************************************/

/******************************************************************************
 Exported global functions (to be accessed by other files)
 ******************************************************************************/

/******************************************************************************
 Exported global variables
 ******************************************************************************/
extern NX_CRYPTO_METHOD crypto_method_rsa;
extern NX_CRYPTO_METHOD crypto_method_sha256;

/******************************************************************************
 Private global variables and functions
 ******************************************************************************/
/* NIST vector */
/* 00010001 */
static const uint8_t public_e[] =
{
    0x00, 0x01, 0x00, 0x01,
};
/* NIST vector */
/* 13FF7429F8E851F1079CCFCE3B3CD8606ABA8607AD85CBB3057501EBD58811F3C04823171F192C048E1E883AF8CF958810151D3874AEDC8EC4F88D2065C581569F1E200852DD40B6DFD1652659085A9DD1D3B869EA3617D904D209DE156A60BA5929D02F16430273D10720C2F28D2B95684DCAA6B9F6A508EA2CBBC11B9F3F30D6201EA6CFFBBF1C44255CEC58EE70DBC872442BCCF115D8F743557B5DE5F42DDDA6CEAE7977793CC9D90ADFE65E520F5520B615CF3B8C2DC82D7AC75EDB1297CF38AB23A37EED18D4DD45D9AD051B26401BE86E8C8E53F9585A702D02F1B5BD65F6739DFA6BFFE560CA130B6F1D4779C556C06D9CD29FB72D8851904F9CDEE9 */
static const uint8_t private_e_2048[] =
{
    0x13, 0xFF, 0x74, 0x29, 0xF8, 0xE8, 0x51, 0xF1, 0x07, 0x9C, 0xCF, 0xCE, 0x3B, 0x3C, 0xD8, 0x60,
    0x6A, 0xBA, 0x86, 0x07, 0xAD, 0x85, 0xCB, 0xB3, 0x05, 0x75, 0x01, 0xEB, 0xD5, 0x88, 0x11, 0xF3,
    0xC0, 0x48, 0x23, 0x17, 0x1F, 0x19, 0x2C, 0x04, 0x8E, 0x1E, 0x88, 0x3A, 0xF8, 0xCF, 0x95, 0x88,
    0x10, 0x15, 0x1D, 0x38, 0x74, 0xAE, 0xDC, 0x8E, 0xC4, 0xF8, 0x8D, 0x20, 0x65, 0xC5, 0x81, 0x56,
    0x9F, 0x1E, 0x20, 0x08, 0x52, 0xDD, 0x40, 0xB6, 0xDF, 0xD1, 0x65, 0x26, 0x59, 0x08, 0x5A, 0x9D,
    0xD1, 0xD3, 0xB8, 0x69, 0xEA, 0x36, 0x17, 0xD9, 0x04, 0xD2, 0x09, 0xDE, 0x15, 0x6A, 0x60, 0xBA,
    0x59, 0x29, 0xD0, 0x2F, 0x16, 0x43, 0x02, 0x73, 0xD1, 0x07, 0x20, 0xC2, 0xF2, 0x8D, 0x2B, 0x95,
    0x68, 0x4D, 0xCA, 0xA6, 0xB9, 0xF6, 0xA5, 0x08, 0xEA, 0x2C, 0xBB, 0xC1, 0x1B, 0x9F, 0x3F, 0x30,
    0xD6, 0x20, 0x1E, 0xA6, 0xCF, 0xFB, 0xBF, 0x1C, 0x44, 0x25, 0x5C, 0xEC, 0x58, 0xEE, 0x70, 0xDB,
    0xC8, 0x72, 0x44, 0x2B, 0xCC, 0xF1, 0x15, 0xD8, 0xF7, 0x43, 0x55, 0x7B, 0x5D, 0xE5, 0xF4, 0x2D,
    0xDD, 0xA6, 0xCE, 0xAE, 0x79, 0x77, 0x79, 0x3C, 0xC9, 0xD9, 0x0A, 0xDF, 0xE6, 0x5E, 0x52, 0x0F,
    0x55, 0x20, 0xB6, 0x15, 0xCF, 0x3B, 0x8C, 0x2D, 0xC8, 0x2D, 0x7A, 0xC7, 0x5E, 0xDB, 0x12, 0x97,
    0xCF, 0x38, 0xAB, 0x23, 0xA3, 0x7E, 0xED, 0x18, 0xD4, 0xDD, 0x45, 0xD9, 0xAD, 0x05, 0x1B, 0x26,
    0x40, 0x1B, 0xE8, 0x6E, 0x8C, 0x8E, 0x53, 0xF9, 0x58, 0x5A, 0x70, 0x2D, 0x02, 0xF1, 0xB5, 0xBD,
    0x65, 0xF6, 0x73, 0x9D, 0xFA, 0x6B, 0xFF, 0xE5, 0x60, 0xCA, 0x13, 0x0B, 0x6F, 0x1D, 0x47, 0x79,
    0xC5, 0x56, 0xC0, 0x6D, 0x9C, 0xD2, 0x9F, 0xB7, 0x2D, 0x88, 0x51, 0x90, 0x4F, 0x9C, 0xDE, 0xE9,
};
/* NIST vector */
/* E0F5059966A8AEC4BF7CDAC8AE2430BDF61C54D09CAB9963CBF9A52AC641E384B6431D3B6A9D1811519A2904E1170A44446C80E7638A4AF2720A7654AB740D8A151FDD216F3D6933422FD9AC14AEDE9CCD021EA79E46925F4B18FD1AF2C0073CFC3A69AC71A2B3673D08136CDB01C379892601C7C857D68018DAE924CB8CD29377A14C752B92BAFF14C3A49725AE2FEFAAD4686D8A7D9F94EB11BF81E05BD5D2586526FB129E73539F9223D496B2ACA23CCACC34D5B18533BD0F5815A76F94F4F55D965FE61599B44BD8FBAD35F42B612A4C4F2765B2097A5C0090EA8166D9C6DA1E03B6119736B794600491C48433132D0F15D5DE3BB4270DF6BC9012B74931 */
static const uint8_t m_2048[] =
{
    0xE0, 0xF5, 0x05, 0x99, 0x66, 0xA8, 0xAE, 0xC4, 0xBF, 0x7C, 0xDA, 0xC8, 0xAE, 0x24, 0x30, 0xBD,
    0xF6, 0x1C, 0x54, 0xD0, 0x9C, 0xAB, 0x99, 0x63, 0xCB, 0xF9, 0xA5, 0x2A, 0xC6, 0x41, 0xE3, 0x84,
    0xB6, 0x43, 0x1D, 0x3B, 0x6A, 0x9D, 0x18, 0x11, 0x51, 0x9A, 0x29, 0x04, 0xE1, 0x17, 0x0A, 0x44,
    0x44, 0x6C, 0x80, 0xE7, 0x63, 0x8A, 0x4A, 0xF2, 0x72, 0x0A, 0x76, 0x54, 0xAB, 0x74, 0x0D, 0x8A,
    0x15, 0x1F, 0xDD, 0x21, 0x6F, 0x3D, 0x69, 0x33, 0x42, 0x2F, 0xD9, 0xAC, 0x14, 0xAE, 0xDE, 0x9C,
    0xCD, 0x02, 0x1E, 0xA7, 0x9E, 0x46, 0x92, 0x5F, 0x4B, 0x18, 0xFD, 0x1A, 0xF2, 0xC0, 0x07, 0x3C,
    0xFC, 0x3A, 0x69, 0xAC, 0x71, 0xA2, 0xB3, 0x67, 0x3D, 0x08, 0x13, 0x6C, 0xDB, 0x01, 0xC3, 0x79,
    0x89, 0x26, 0x01, 0xC7, 0xC8, 0x57, 0xD6, 0x80, 0x18, 0xDA, 0xE9, 0x24, 0xCB, 0x8C, 0xD2, 0x93,
    0x77, 0xA1, 0x4C, 0x75, 0x2B, 0x92, 0xBA, 0xFF, 0x14, 0xC3, 0xA4, 0x97, 0x25, 0xAE, 0x2F, 0xEF,
    0xAA, 0xD4, 0x68, 0x6D, 0x8A, 0x7D, 0x9F, 0x94, 0xEB, 0x11, 0xBF, 0x81, 0xE0, 0x5B, 0xD5, 0xD2,
    0x58, 0x65, 0x26, 0xFB, 0x12, 0x9E, 0x73, 0x53, 0x9F, 0x92, 0x23, 0xD4, 0x96, 0xB2, 0xAC, 0xA2,
    0x3C, 0xCA, 0xCC, 0x34, 0xD5, 0xB1, 0x85, 0x33, 0xBD, 0x0F, 0x58, 0x15, 0xA7, 0x6F, 0x94, 0xF4,
    0xF5, 0x5D, 0x96, 0x5F, 0xE6, 0x15, 0x99, 0xB4, 0x4B, 0xD8, 0xFB, 0xAD, 0x35, 0xF4, 0x2B, 0x61,
    0x2A, 0x4C, 0x4F, 0x27, 0x65, 0xB2, 0x09, 0x7A, 0x5C, 0x00, 0x90, 0xEA, 0x81, 0x66, 0xD9, 0xC6,
    0xDA, 0x1E, 0x03, 0xB6, 0x11, 0x97, 0x36, 0xB7, 0x94, 0x60, 0x04, 0x91, 0xC4, 0x84, 0x33, 0x13,
    0x2D, 0x0F, 0x15, 0xD5, 0xDE, 0x3B, 0xB4, 0x27, 0x0D, 0xF6, 0xBC, 0x90, 0x12, 0xB7, 0x49, 0x31,
};
/* NIST vector */
/* 551C2E268F7ED44D0E8B063F5B2B510CB809F53BD54E9956971E243B2363DA123C29AB4A009EDE1FCEC54625971A4E3490F3EA398BF7386AAC34720E43FB0C795445B520AEE4D7694EE1474F60F77E1B5F09FE2ED004333658D212122F040322D1564512A1540400F27E18049A762A5EDC9F072CA4F49F408252D42B31BC35523373740E90DDDA6A8CE7865EEB7C694A662C74412406AB190FE0435DA2551F0C24A48939DDA58A0239706D40B4977473689DC36CE5A4DF4EF892816CBDE2780D9389B7384674C93B1DDAF728F292B5671679FC7175AC0A3B2197B809E7CF410417010F3B1316D10D82466C62F3A01667B70A714E0499400E255D4C39EA7DE55C */
static const uint8_t plain_2048[] =
{
    0x55, 0x1C, 0x2E, 0x26, 0x8F, 0x7E, 0xD4, 0x4D, 0x0E, 0x8B, 0x06, 0x3F, 0x5B, 0x2B, 0x51, 0x0C,
    0xB8, 0x09, 0xF5, 0x3B, 0xD5, 0x4E, 0x99, 0x56, 0x97, 0x1E, 0x24, 0x3B, 0x23, 0x63, 0xDA, 0x12,
    0x3C, 0x29, 0xAB, 0x4A, 0x00, 0x9E, 0xDE, 0x1F, 0xCE, 0xC5, 0x46, 0x25, 0x97, 0x1A, 0x4E, 0x34,
    0x90, 0xF3, 0xEA, 0x39, 0x8B, 0xF7, 0x38, 0x6A, 0xAC, 0x34, 0x72, 0x0E, 0x43, 0xFB, 0x0C, 0x79,
    0x54, 0x45, 0xB5, 0x20, 0xAE, 0xE4, 0xD7, 0x69, 0x4E, 0xE1, 0x47, 0x4F, 0x60, 0xF7, 0x7E, 0x1B,
    0x5F, 0x09, 0xFE, 0x2E, 0xD0, 0x04, 0x33, 0x36, 0x58, 0xD2, 0x12, 0x12, 0x2F, 0x04, 0x03, 0x22,
    0xD1, 0x56, 0x45, 0x12, 0xA1, 0x54, 0x04, 0x00, 0xF2, 0x7E, 0x18, 0x04, 0x9A, 0x76, 0x2A, 0x5E,
    0xDC, 0x9F, 0x07, 0x2C, 0xA4, 0xF4, 0x9F, 0x40, 0x82, 0x52, 0xD4, 0x2B, 0x31, 0xBC, 0x35, 0x52,
    0x33, 0x73, 0x74, 0x0E, 0x90, 0xDD, 0xDA, 0x6A, 0x8C, 0xE7, 0x86, 0x5E, 0xEB, 0x7C, 0x69, 0x4A,
    0x66, 0x2C, 0x74, 0x41, 0x24, 0x06, 0xAB, 0x19, 0x0F, 0xE0, 0x43, 0x5D, 0xA2, 0x55, 0x1F, 0x0C,
    0x24, 0xA4, 0x89, 0x39, 0xDD, 0xA5, 0x8A, 0x02, 0x39, 0x70, 0x6D, 0x40, 0xB4, 0x97, 0x74, 0x73,
    0x68, 0x9D, 0xC3, 0x6C, 0xE5, 0xA4, 0xDF, 0x4E, 0xF8, 0x92, 0x81, 0x6C, 0xBD, 0xE2, 0x78, 0x0D,
    0x93, 0x89, 0xB7, 0x38, 0x46, 0x74, 0xC9, 0x3B, 0x1D, 0xDA, 0xF7, 0x28, 0xF2, 0x92, 0xB5, 0x67,
    0x16, 0x79, 0xFC, 0x71, 0x75, 0xAC, 0x0A, 0x3B, 0x21, 0x97, 0xB8, 0x09, 0xE7, 0xCF, 0x41, 0x04,
    0x17, 0x01, 0x0F, 0x3B, 0x13, 0x16, 0xD1, 0x0D, 0x82, 0x46, 0x6C, 0x62, 0xF3, 0xA0, 0x16, 0x67,
    0xB7, 0x0A, 0x71, 0x4E, 0x04, 0x99, 0x40, 0x0E, 0x25, 0x5D, 0x4C, 0x39, 0xEA, 0x7D, 0xE5, 0x5C,
};
/* NIST vector */
/* 10F904E071338569EC131401A7869F42F3BCAE252B5D3C8755FD24D47997A9CD4221D992B2871E05283B98841FC5C379C5D0E35B3938279B344299C3CF1566E0C994D0A9013AF64174F1379A4B5E4E9DE57491F3078F6D10011EA55535D0763E538662C9996F4FCF8B64A768685AA417ADB6978743D3D1F513CF143DD6D383AD6357728A88928D39E27EA4D0B2AF92FC7F63875F9D6A70FAE7993C1FF04DF9A2F99216874BC123D4B7DA7E7E8974CFC10ACF0C7BC8747526A8D16791F969082EA9B0C36D77B67C37B325682D74178E4234D52D5635273301A6CC35E315AE74D659B1433576DAAE6780FA39E0550D971F2CB5817CAAFC24B5220E21C8CEEE85DD */
static const uint8_t secret_2048[] =
{
    0x10, 0xF9, 0x04, 0xE0, 0x71, 0x33, 0x85, 0x69, 0xEC, 0x13, 0x14, 0x01, 0xA7, 0x86, 0x9F, 0x42,
    0xF3, 0xBC, 0xAE, 0x25, 0x2B, 0x5D, 0x3C, 0x87, 0x55, 0xFD, 0x24, 0xD4, 0x79, 0x97, 0xA9, 0xCD,
    0x42, 0x21, 0xD9, 0x92, 0xB2, 0x87, 0x1E, 0x05, 0x28, 0x3B, 0x98, 0x84, 0x1F, 0xC5, 0xC3, 0x79,
    0xC5, 0xD0, 0xE3, 0x5B, 0x39, 0x38, 0x27, 0x9B, 0x34, 0x42, 0x99, 0xC3, 0xCF, 0x15, 0x66, 0xE0,
    0xC9, 0x94, 0xD0, 0xA9, 0x01, 0x3A, 0xF6, 0x41, 0x74, 0xF1, 0x37, 0x9A, 0x4B, 0x5E, 0x4E, 0x9D,
    0xE5, 0x74, 0x91, 0xF3, 0x07, 0x8F, 0x6D, 0x10, 0x01, 0x1E, 0xA5, 0x55, 0x35, 0xD0, 0x76, 0x3E,
    0x53, 0x86, 0x62, 0xC9, 0x99, 0x6F, 0x4F, 0xCF, 0x8B, 0x64, 0xA7, 0x68, 0x68, 0x5A, 0xA4, 0x17,
    0xAD, 0xB6, 0x97, 0x87, 0x43, 0xD3, 0xD1, 0xF5, 0x13, 0xCF, 0x14, 0x3D, 0xD6, 0xD3, 0x83, 0xAD,
    0x63, 0x57, 0x72, 0x8A, 0x88, 0x92, 0x8D, 0x39, 0xE2, 0x7E, 0xA4, 0xD0, 0xB2, 0xAF, 0x92, 0xFC,
    0x7F, 0x63, 0x87, 0x5F, 0x9D, 0x6A, 0x70, 0xFA, 0xE7, 0x99, 0x3C, 0x1F, 0xF0, 0x4D, 0xF9, 0xA2,
    0xF9, 0x92, 0x16, 0x87, 0x4B, 0xC1, 0x23, 0xD4, 0xB7, 0xDA, 0x7E, 0x7E, 0x89, 0x74, 0xCF, 0xC1,
    0x0A, 0xCF, 0x0C, 0x7B, 0xC8, 0x74, 0x75, 0x26, 0xA8, 0xD1, 0x67, 0x91, 0xF9, 0x69, 0x08, 0x2E,
    0xA9, 0xB0, 0xC3, 0x6D, 0x77, 0xB6, 0x7C, 0x37, 0xB3, 0x25, 0x68, 0x2D, 0x74, 0x17, 0x8E, 0x42,
    0x34, 0xD5, 0x2D, 0x56, 0x35, 0x27, 0x33, 0x01, 0xA6, 0xCC, 0x35, 0xE3, 0x15, 0xAE, 0x74, 0xD6,
    0x59, 0xB1, 0x43, 0x35, 0x76, 0xDA, 0xAE, 0x67, 0x80, 0xFA, 0x39, 0xE0, 0x55, 0x0D, 0x97, 0x1F,
    0x2C, 0xB5, 0x81, 0x7C, 0xAA, 0xFC, 0x24, 0xB5, 0x22, 0x0E, 0x21, 0xC8, 0xCE, 0xEE, 0x85, 0xDD,
};
/* NIST vector */
/* CD0B9F926AB52E04736D716641FE6C6425E65D450FB54DB70909AA6D33CCE0CA8BC0A45DEC6D4382FCAF501420F545994FB6302D2E353B6F0CA98880AC99613253C44CB43224B29F13766831C8754BF70446343F96FCFDA0C56D7A38184FD6C82604CE5473129A2127E37FDEE76968CC667B1034342891D7E3B7973AF1947C869580A6EBC0A68369E5BC0972F18BA9CFBCBA224287B6D06E577C42631DA539EFC796B9EA8E33ED957429B3CE8766432E329EA9509205184986BAA741C646C6EACD61337410099603FCCB49B51E0088860A52BC4A087B8B2596AB6079CC27C49B6A148E825CBC7EB0BAA362F15A57E55A4ABF85CA311B90D5E578F38C1DAFA02EB9D61E465EE0D1F60352590E801C5690BBFD7690867DCC1D07ACA0C182910445E493D442710355932B8CE7263E5EEDB835934D8DF2DC8BED771332ED974A759DE21D8BD9DBB8FD5CE83177FE43C71DAB3143CE893A8438203F5E4714DBB417A7A285BDDEF0E5E6AC22591EDD151E1EC5E7FC111501F51DD7089C95C70347DC982E4BE16EDE57459A4C5130A9232CB61836DA1148AE6E5C7619A35DEC2A4F2D4C5258552EF7C95F95A95831E06D85C05DE67E4317389369DD27B208A0E2BE94A73EF46C16654FD515B61713994C3A5B33217F3F13B12E39B2C7C666A4ACB93AF9A69F5C6550E6B41E0B01894E601765AC10CE1F9E4F7888DFE67DC1AF80B073FD */
static const uint8_t m_4096[] =
{
    0xCD, 0x0B, 0x9F, 0x92, 0x6A, 0xB5, 0x2E, 0x04, 0x73, 0x6D, 0x71, 0x66, 0x41, 0xFE, 0x6C, 0x64,
    0x25, 0xE6, 0x5D, 0x45, 0x0F, 0xB5, 0x4D, 0xB7, 0x09, 0x09, 0xAA, 0x6D, 0x33, 0xCC, 0xE0, 0xCA,
    0x8B, 0xC0, 0xA4, 0x5D, 0xEC, 0x6D, 0x43, 0x82, 0xFC, 0xAF, 0x50, 0x14, 0x20, 0xF5, 0x45, 0x99,
    0x4F, 0xB6, 0x30, 0x2D, 0x2E, 0x35, 0x3B, 0x6F, 0x0C, 0xA9, 0x88, 0x80, 0xAC, 0x99, 0x61, 0x32,
    0x53, 0xC4, 0x4C, 0xB4, 0x32, 0x24, 0xB2, 0x9F, 0x13, 0x76, 0x68, 0x31, 0xC8, 0x75, 0x4B, 0xF7,
    0x04, 0x46, 0x34, 0x3F, 0x96, 0xFC, 0xFD, 0xA0, 0xC5, 0x6D, 0x7A, 0x38, 0x18, 0x4F, 0xD6, 0xC8,
    0x26, 0x04, 0xCE, 0x54, 0x73, 0x12, 0x9A, 0x21, 0x27, 0xE3, 0x7F, 0xDE, 0xE7, 0x69, 0x68, 0xCC,
    0x66, 0x7B, 0x10, 0x34, 0x34, 0x28, 0x91, 0xD7, 0xE3, 0xB7, 0x97, 0x3A, 0xF1, 0x94, 0x7C, 0x86,
    0x95, 0x80, 0xA6, 0xEB, 0xC0, 0xA6, 0x83, 0x69, 0xE5, 0xBC, 0x09, 0x72, 0xF1, 0x8B, 0xA9, 0xCF,
    0xBC, 0xBA, 0x22, 0x42, 0x87, 0xB6, 0xD0, 0x6E, 0x57, 0x7C, 0x42, 0x63, 0x1D, 0xA5, 0x39, 0xEF,
    0xC7, 0x96, 0xB9, 0xEA, 0x8E, 0x33, 0xED, 0x95, 0x74, 0x29, 0xB3, 0xCE, 0x87, 0x66, 0x43, 0x2E,
    0x32, 0x9E, 0xA9, 0x50, 0x92, 0x05, 0x18, 0x49, 0x86, 0xBA, 0xA7, 0x41, 0xC6, 0x46, 0xC6, 0xEA,
    0xCD, 0x61, 0x33, 0x74, 0x10, 0x09, 0x96, 0x03, 0xFC, 0xCB, 0x49, 0xB5, 0x1E, 0x00, 0x88, 0x86,
    0x0A, 0x52, 0xBC, 0x4A, 0x08, 0x7B, 0x8B, 0x25, 0x96, 0xAB, 0x60, 0x79, 0xCC, 0x27, 0xC4, 0x9B,
    0x6A, 0x14, 0x8E, 0x82, 0x5C, 0xBC, 0x7E, 0xB0, 0xBA, 0xA3, 0x62, 0xF1, 0x5A, 0x57, 0xE5, 0x5A,
    0x4A, 0xBF, 0x85, 0xCA, 0x31, 0x1B, 0x90, 0xD5, 0xE5, 0x78, 0xF3, 0x8C, 0x1D, 0xAF, 0xA0, 0x2E,
    0xB9, 0xD6, 0x1E, 0x46, 0x5E, 0xE0, 0xD1, 0xF6, 0x03, 0x52, 0x59, 0x0E, 0x80, 0x1C, 0x56, 0x90,
    0xBB, 0xFD, 0x76, 0x90, 0x86, 0x7D, 0xCC, 0x1D, 0x07, 0xAC, 0xA0, 0xC1, 0x82, 0x91, 0x04, 0x45,
    0xE4, 0x93, 0xD4, 0x42, 0x71, 0x03, 0x55, 0x93, 0x2B, 0x8C, 0xE7, 0x26, 0x3E, 0x5E, 0xED, 0xB8,
    0x35, 0x93, 0x4D, 0x8D, 0xF2, 0xDC, 0x8B, 0xED, 0x77, 0x13, 0x32, 0xED, 0x97, 0x4A, 0x75, 0x9D,
    0xE2, 0x1D, 0x8B, 0xD9, 0xDB, 0xB8, 0xFD, 0x5C, 0xE8, 0x31, 0x77, 0xFE, 0x43, 0xC7, 0x1D, 0xAB,
    0x31, 0x43, 0xCE, 0x89, 0x3A, 0x84, 0x38, 0x20, 0x3F, 0x5E, 0x47, 0x14, 0xDB, 0xB4, 0x17, 0xA7,
    0xA2, 0x85, 0xBD, 0xDE, 0xF0, 0xE5, 0xE6, 0xAC, 0x22, 0x59, 0x1E, 0xDD, 0x15, 0x1E, 0x1E, 0xC5,
    0xE7, 0xFC, 0x11, 0x15, 0x01, 0xF5, 0x1D, 0xD7, 0x08, 0x9C, 0x95, 0xC7, 0x03, 0x47, 0xDC, 0x98,
    0x2E, 0x4B, 0xE1, 0x6E, 0xDE, 0x57, 0x45, 0x9A, 0x4C, 0x51, 0x30, 0xA9, 0x23, 0x2C, 0xB6, 0x18,
    0x36, 0xDA, 0x11, 0x48, 0xAE, 0x6E, 0x5C, 0x76, 0x19, 0xA3, 0x5D, 0xEC, 0x2A, 0x4F, 0x2D, 0x4C,
    0x52, 0x58, 0x55, 0x2E, 0xF7, 0xC9, 0x5F, 0x95, 0xA9, 0x58, 0x31, 0xE0, 0x6D, 0x85, 0xC0, 0x5D,
    0xE6, 0x7E, 0x43, 0x17, 0x38, 0x93, 0x69, 0xDD, 0x27, 0xB2, 0x08, 0xA0, 0xE2, 0xBE, 0x94, 0xA7,
    0x3E, 0xF4, 0x6C, 0x16, 0x65, 0x4F, 0xD5, 0x15, 0xB6, 0x17, 0x13, 0x99, 0x4C, 0x3A, 0x5B, 0x33,
    0x21, 0x7F, 0x3F, 0x13, 0xB1, 0x2E, 0x39, 0xB2, 0xC7, 0xC6, 0x66, 0xA4, 0xAC, 0xB9, 0x3A, 0xF9,
    0xA6, 0x9F, 0x5C, 0x65, 0x50, 0xE6, 0xB4, 0x1E, 0x0B, 0x01, 0x89, 0x4E, 0x60, 0x17, 0x65, 0xAC,
    0x10, 0xCE, 0x1F, 0x9E, 0x4F, 0x78, 0x88, 0xDF, 0xE6, 0x7D, 0xC1, 0xAF, 0x80, 0xB0, 0x73, 0xFD,
};
/* NIST vector */
/* 77FB285B3307225D3C97072E838DBC7B1F177474A95FE063AFF0344EB9CEDD5311E7397376A5C63ED0A6DF1DA6F4D61C367F3E752641A75B063E3E34239A4D20E312AF1A9CC10A1C5CC58D301E74B904F26C843BCD787878578BC8618F3DF47D4BFDA8523AB3C77E3B422E5A3386F1724EC3230D1196FE2F81211863C5BE4C68449D200DBDB81F11494C096464B4940167180075F83C3E321D83725578FF39686EE20471ED2952731FF41005A4614366146BF94E25324F39C8FB9006F77DA869C2F3595524C11E3715F2616EB460DE10F139972F6D7D2A50449ED20E3D374002A730F24E7FE0006970BD3175F5F3155C9076FF18F1DE4958BAB26244D5132026AE97696903FF6B2839C8B42715B0695EFC3BAA5A564B277D8EAFA3466A1EAF4B43757970ADA3B44B0F80F23157E0723FD2D50305D77B83384F5E1B2994C95D5AFB3CA26F64507D17492A3C6BEC76391FD1CDA7678DC80E7A29AE792178FE99360CA90F63996BAB166DF2AF129D1F0F7C8A4AF56E28A5125772332F2239E25E582BA47E7FABFBE3494E92C83627E0285A01470B47DC416C7D92FED72544BC843789E52049A17ECA579C9CF7765CBB244E78FA4D10EBFA1220F08482287337F07F4F4B903739AFBE135FAE291F2119381FC677CD0D895CA3409917D255D320DD7022C84E57070A82687040EC6CAD1244462FAF943FE2731B0FE6F4A21E5A53133F */
static const uint8_t plain_4096[] =
{
    0x77, 0xFB, 0x28, 0x5B, 0x33, 0x07, 0x22, 0x5D, 0x3C, 0x97, 0x07, 0x2E, 0x83, 0x8D, 0xBC, 0x7B,
    0x1F, 0x17, 0x74, 0x74, 0xA9, 0x5F, 0xE0, 0x63, 0xAF, 0xF0, 0x34, 0x4E, 0xB9, 0xCE, 0xDD, 0x53,
    0x11, 0xE7, 0x39, 0x73, 0x76, 0xA5, 0xC6, 0x3E, 0xD0, 0xA6, 0xDF, 0x1D, 0xA6, 0xF4, 0xD6, 0x1C,
    0x36, 0x7F, 0x3E, 0x75, 0x26, 0x41, 0xA7, 0x5B, 0x06, 0x3E, 0x3E, 0x34, 0x23, 0x9A, 0x4D, 0x20,
    0xE3, 0x12, 0xAF, 0x1A, 0x9C, 0xC1, 0x0A, 0x1C, 0x5C, 0xC5, 0x8D, 0x30, 0x1E, 0x74, 0xB9, 0x04,
    0xF2, 0x6C, 0x84, 0x3B, 0xCD, 0x78, 0x78, 0x78, 0x57, 0x8B, 0xC8, 0x61, 0x8F, 0x3D, 0xF4, 0x7D,
    0x4B, 0xFD, 0xA8, 0x52, 0x3A, 0xB3, 0xC7, 0x7E, 0x3B, 0x42, 0x2E, 0x5A, 0x33, 0x86, 0xF1, 0x72,
    0x4E, 0xC3, 0x23, 0x0D, 0x11, 0x96, 0xFE, 0x2F, 0x81, 0x21, 0x18, 0x63, 0xC5, 0xBE, 0x4C, 0x68,
    0x44, 0x9D, 0x20, 0x0D, 0xBD, 0xB8, 0x1F, 0x11, 0x49, 0x4C, 0x09, 0x64, 0x64, 0xB4, 0x94, 0x01,
    0x67, 0x18, 0x00, 0x75, 0xF8, 0x3C, 0x3E, 0x32, 0x1D, 0x83, 0x72, 0x55, 0x78, 0xFF, 0x39, 0x68,
    0x6E, 0xE2, 0x04, 0x71, 0xED, 0x29, 0x52, 0x73, 0x1F, 0xF4, 0x10, 0x05, 0xA4, 0x61, 0x43, 0x66,
    0x14, 0x6B, 0xF9, 0x4E, 0x25, 0x32, 0x4F, 0x39, 0xC8, 0xFB, 0x90, 0x06, 0xF7, 0x7D, 0xA8, 0x69,
    0xC2, 0xF3, 0x59, 0x55, 0x24, 0xC1, 0x1E, 0x37, 0x15, 0xF2, 0x61, 0x6E, 0xB4, 0x60, 0xDE, 0x10,
    0xF1, 0x39, 0x97, 0x2F, 0x6D, 0x7D, 0x2A, 0x50, 0x44, 0x9E, 0xD2, 0x0E, 0x3D, 0x37, 0x40, 0x02,
    0xA7, 0x30, 0xF2, 0x4E, 0x7F, 0xE0, 0x00, 0x69, 0x70, 0xBD, 0x31, 0x75, 0xF5, 0xF3, 0x15, 0x5C,
    0x90, 0x76, 0xFF, 0x18, 0xF1, 0xDE, 0x49, 0x58, 0xBA, 0xB2, 0x62, 0x44, 0xD5, 0x13, 0x20, 0x26,
    0xAE, 0x97, 0x69, 0x69, 0x03, 0xFF, 0x6B, 0x28, 0x39, 0xC8, 0xB4, 0x27, 0x15, 0xB0, 0x69, 0x5E,
    0xFC, 0x3B, 0xAA, 0x5A, 0x56, 0x4B, 0x27, 0x7D, 0x8E, 0xAF, 0xA3, 0x46, 0x6A, 0x1E, 0xAF, 0x4B,
    0x43, 0x75, 0x79, 0x70, 0xAD, 0xA3, 0xB4, 0x4B, 0x0F, 0x80, 0xF2, 0x31, 0x57, 0xE0, 0x72, 0x3F,
    0xD2, 0xD5, 0x03, 0x05, 0xD7, 0x7B, 0x83, 0x38, 0x4F, 0x5E, 0x1B, 0x29, 0x94, 0xC9, 0x5D, 0x5A,
    0xFB, 0x3C, 0xA2, 0x6F, 0x64, 0x50, 0x7D, 0x17, 0x49, 0x2A, 0x3C, 0x6B, 0xEC, 0x76, 0x39, 0x1F,
    0xD1, 0xCD, 0xA7, 0x67, 0x8D, 0xC8, 0x0E, 0x7A, 0x29, 0xAE, 0x79, 0x21, 0x78, 0xFE, 0x99, 0x36,
    0x0C, 0xA9, 0x0F, 0x63, 0x99, 0x6B, 0xAB, 0x16, 0x6D, 0xF2, 0xAF, 0x12, 0x9D, 0x1F, 0x0F, 0x7C,
    0x8A, 0x4A, 0xF5, 0x6E, 0x28, 0xA5, 0x12, 0x57, 0x72, 0x33, 0x2F, 0x22, 0x39, 0xE2, 0x5E, 0x58,
    0x2B, 0xA4, 0x7E, 0x7F, 0xAB, 0xFB, 0xE3, 0x49, 0x4E, 0x92, 0xC8, 0x36, 0x27, 0xE0, 0x28, 0x5A,
    0x01, 0x47, 0x0B, 0x47, 0xDC, 0x41, 0x6C, 0x7D, 0x92, 0xFE, 0xD7, 0x25, 0x44, 0xBC, 0x84, 0x37,
    0x89, 0xE5, 0x20, 0x49, 0xA1, 0x7E, 0xCA, 0x57, 0x9C, 0x9C, 0xF7, 0x76, 0x5C, 0xBB, 0x24, 0x4E,
    0x78, 0xFA, 0x4D, 0x10, 0xEB, 0xFA, 0x12, 0x20, 0xF0, 0x84, 0x82, 0x28, 0x73, 0x37, 0xF0, 0x7F,
    0x4F, 0x4B, 0x90, 0x37, 0x39, 0xAF, 0xBE, 0x13, 0x5F, 0xAE, 0x29, 0x1F, 0x21, 0x19, 0x38, 0x1F,
    0xC6, 0x77, 0xCD, 0x0D, 0x89, 0x5C, 0xA3, 0x40, 0x99, 0x17, 0xD2, 0x55, 0xD3, 0x20, 0xDD, 0x70,
    0x22, 0xC8, 0x4E, 0x57, 0x07, 0x0A, 0x82, 0x68, 0x70, 0x40, 0xEC, 0x6C, 0xAD, 0x12, 0x44, 0x46,
    0x2F, 0xAF, 0x94, 0x3F, 0xE2, 0x73, 0x1B, 0x0F, 0xE6, 0xF4, 0xA2, 0x1E, 0x5A, 0x53, 0x13, 0x3F,
};
/* NIST vector */
/* 77D78EF257A03397F5FCDB96F13035AF7DE4886130EF5E6DD4B1C92113883E5F69260331A017344C1AF65D420491A51DF570262BD14D234495D16C900CD87843F5875BD071358D67EAB294FC160971E11F015037BF9C27FCCB41E257181021C6C9D5689AE2E5538E02D210C4274DF58E4602E5F8B30B67AB23A29BBFC7596A8CE414012302141A71B14E47DBDF716018BB1E4FF0CBEC2DD339A65F5F64FBAB3C421FD87FE377874C39064F581D41A674D5668E51E22F1E55DF201F5B68921ADA20B3B5695EDA31FC826C8EEE6C064A97780075881FCD9D63A4084B49925292DDE637958F7AE48A3701BF07E25D19FDC122C44C9656813E5A5D4DE5A66912261AA2D5A3A569CF559CDAAC02FE446EA0EAB149F40F0DD83BB026D962C162F5E48EF1DF33E2D9C3CEB3A58C18630CCCF2654FA3CEE93545DA54863781B58BAAB0FAD56C921588AEFDF60CB7E34A2E809D3C82D65DACAD72AC5E21A7FA5B6557B717FF6B8419B447C1AD4E314FAE70564614FD412CDACCABFCE15C12CE08BB0D324CC5FE5F6F36CC3B89CE2538ADC26D7AF513D6A8F6A78128F060BB8919BBEF1B59BDA6267904AA2C40304FEFCB07B6B85F591435163A656405E6C3F9D5C73C354DE66520EE8A056A64C536D15C3FD9C90516729504DD9783C4A7E622F207383F46F8E9427FA96E6C1C881313BBE99F010B2C6853F3F1ED2ED49ABCFAEFECC09BE9 */
static const uint8_t secret_4096[] =
{
    0x77, 0xD7, 0x8E, 0xF2, 0x57, 0xA0, 0x33, 0x97, 0xF5, 0xFC, 0xDB, 0x96, 0xF1, 0x30, 0x35, 0xAF,
    0x7D, 0xE4, 0x88, 0x61, 0x30, 0xEF, 0x5E, 0x6D, 0xD4, 0xB1, 0xC9, 0x21, 0x13, 0x88, 0x3E, 0x5F,
    0x69, 0x26, 0x03, 0x31, 0xA0, 0x17, 0x34, 0x4C, 0x1A, 0xF6, 0x5D, 0x42, 0x04, 0x91, 0xA5, 0x1D,
    0xF5, 0x70, 0x26, 0x2B, 0xD1, 0x4D, 0x23, 0x44, 0x95, 0xD1, 0x6C, 0x90, 0x0C, 0xD8, 0x78, 0x43,
    0xF5, 0x87, 0x5B, 0xD0, 0x71, 0x35, 0x8D, 0x67, 0xEA, 0xB2, 0x94, 0xFC, 0x16, 0x09, 0x71, 0xE1,
    0x1F, 0x01, 0x50, 0x37, 0xBF, 0x9C, 0x27, 0xFC, 0xCB, 0x41, 0xE2, 0x57, 0x18, 0x10, 0x21, 0xC6,
    0xC9, 0xD5, 0x68, 0x9A, 0xE2, 0xE5, 0x53, 0x8E, 0x02, 0xD2, 0x10, 0xC4, 0x27, 0x4D, 0xF5, 0x8E,
    0x46, 0x02, 0xE5, 0xF8, 0xB3, 0x0B, 0x67, 0xAB, 0x23, 0xA2, 0x9B, 0xBF, 0xC7, 0x59, 0x6A, 0x8C,
    0xE4, 0x14, 0x01, 0x23, 0x02, 0x14, 0x1A, 0x71, 0xB1, 0x4E, 0x47, 0xDB, 0xDF, 0x71, 0x60, 0x18,
    0xBB, 0x1E, 0x4F, 0xF0, 0xCB, 0xEC, 0x2D, 0xD3, 0x39, 0xA6, 0x5F, 0x5F, 0x64, 0xFB, 0xAB, 0x3C,
    0x42, 0x1F, 0xD8, 0x7F, 0xE3, 0x77, 0x87, 0x4C, 0x39, 0x06, 0x4F, 0x58, 0x1D, 0x41, 0xA6, 0x74,
    0xD5, 0x66, 0x8E, 0x51, 0xE2, 0x2F, 0x1E, 0x55, 0xDF, 0x20, 0x1F, 0x5B, 0x68, 0x92, 0x1A, 0xDA,
    0x20, 0xB3, 0xB5, 0x69, 0x5E, 0xDA, 0x31, 0xFC, 0x82, 0x6C, 0x8E, 0xEE, 0x6C, 0x06, 0x4A, 0x97,
    0x78, 0x00, 0x75, 0x88, 0x1F, 0xCD, 0x9D, 0x63, 0xA4, 0x08, 0x4B, 0x49, 0x92, 0x52, 0x92, 0xDD,
    0xE6, 0x37, 0x95, 0x8F, 0x7A, 0xE4, 0x8A, 0x37, 0x01, 0xBF, 0x07, 0xE2, 0x5D, 0x19, 0xFD, 0xC1,
    0x22, 0xC4, 0x4C, 0x96, 0x56, 0x81, 0x3E, 0x5A, 0x5D, 0x4D, 0xE5, 0xA6, 0x69, 0x12, 0x26, 0x1A,
    0xA2, 0xD5, 0xA3, 0xA5, 0x69, 0xCF, 0x55, 0x9C, 0xDA, 0xAC, 0x02, 0xFE, 0x44, 0x6E, 0xA0, 0xEA,
    0xB1, 0x49, 0xF4, 0x0F, 0x0D, 0xD8, 0x3B, 0xB0, 0x26, 0xD9, 0x62, 0xC1, 0x62, 0xF5, 0xE4, 0x8E,
    0xF1, 0xDF, 0x33, 0xE2, 0xD9, 0xC3, 0xCE, 0xB3, 0xA5, 0x8C, 0x18, 0x63, 0x0C, 0xCC, 0xF2, 0x65,
    0x4F, 0xA3, 0xCE, 0xE9, 0x35, 0x45, 0xDA, 0x54, 0x86, 0x37, 0x81, 0xB5, 0x8B, 0xAA, 0xB0, 0xFA,
    0xD5, 0x6C, 0x92, 0x15, 0x88, 0xAE, 0xFD, 0xF6, 0x0C, 0xB7, 0xE3, 0x4A, 0x2E, 0x80, 0x9D, 0x3C,
    0x82, 0xD6, 0x5D, 0xAC, 0xAD, 0x72, 0xAC, 0x5E, 0x21, 0xA7, 0xFA, 0x5B, 0x65, 0x57, 0xB7, 0x17,
    0xFF, 0x6B, 0x84, 0x19, 0xB4, 0x47, 0xC1, 0xAD, 0x4E, 0x31, 0x4F, 0xAE, 0x70, 0x56, 0x46, 0x14,
    0xFD, 0x41, 0x2C, 0xDA, 0xCC, 0xAB, 0xFC, 0xE1, 0x5C, 0x12, 0xCE, 0x08, 0xBB, 0x0D, 0x32, 0x4C,
    0xC5, 0xFE, 0x5F, 0x6F, 0x36, 0xCC, 0x3B, 0x89, 0xCE, 0x25, 0x38, 0xAD, 0xC2, 0x6D, 0x7A, 0xF5,
    0x13, 0xD6, 0xA8, 0xF6, 0xA7, 0x81, 0x28, 0xF0, 0x60, 0xBB, 0x89, 0x19, 0xBB, 0xEF, 0x1B, 0x59,
    0xBD, 0xA6, 0x26, 0x79, 0x04, 0xAA, 0x2C, 0x40, 0x30, 0x4F, 0xEF, 0xCB, 0x07, 0xB6, 0xB8, 0x5F,
    0x59, 0x14, 0x35, 0x16, 0x3A, 0x65, 0x64, 0x05, 0xE6, 0xC3, 0xF9, 0xD5, 0xC7, 0x3C, 0x35, 0x4D,
    0xE6, 0x65, 0x20, 0xEE, 0x8A, 0x05, 0x6A, 0x64, 0xC5, 0x36, 0xD1, 0x5C, 0x3F, 0xD9, 0xC9, 0x05,
    0x16, 0x72, 0x95, 0x04, 0xDD, 0x97, 0x83, 0xC4, 0xA7, 0xE6, 0x22, 0xF2, 0x07, 0x38, 0x3F, 0x46,
    0xF8, 0xE9, 0x42, 0x7F, 0xA9, 0x6E, 0x6C, 0x1C, 0x88, 0x13, 0x13, 0xBB, 0xE9, 0x9F, 0x01, 0x0B,
    0x2C, 0x68, 0x53, 0xF3, 0xF1, 0xED, 0x2E, 0xD4, 0x9A, 0xBC, 0xFA, 0xEF, 0xEC, 0xC0, 0x9B, 0xE9,
};
/* NIST vector */
/* sha_256 short message length */
static const uint8_t NIST_SHA256ShortMsgLen200[] =
{
    0x2e, 0x7e, 0xa8, 0x4d, 0xa4, 0xbc, 0x4d, 0x7c, 0xfb, 0x46, 0x3e, 0x3f, 0x2c, 0x86, 0x47, 0x05,
    0x7a, 0xff, 0xf3, 0xfb, 0xec, 0xec, 0xa1, 0xd2, 00
};
/* NIST vector */
/* expected sha256 short message length to compare the output of crypto algorithm*/
static const uint8_t NIST_SHA256ShortMsgLen200_expected[] =
{
    0x76, 0xe3, 0xac, 0xbc, 0x71, 0x88, 0x36, 0xf2, 0xdf, 0x8a, 0xd2, 0xd0, 0xd2, 0xd7, 0x6f, 0x0c,
    0xfa, 0x5f, 0xea, 0x09, 0x86, 0xbe, 0x91, 0x8f, 0x10, 0xbc, 0xee, 0x73, 0x0d, 0xf4, 0x41, 0xb9
};

static uint32_t netx_secure_crypto_rsa_2048_example (void);
static uint32_t netx_secure_crypto_rsa_4096_example (void);
static uint32_t netx_secure_crypto_sha256_example (void);

/* RSA Thread entry function */
void rsa_thread_entry(void)
{
    uint8_t read_data = RESET_VALUE;
    UINT status = TX_SUCCESS;
    ULONG actual_flags = RESET_VALUE;
    /* Initialize the RTT Thread.*/
    rtt_thread_init_check ();

    /* Wait for RSA event flag */
    status = tx_event_flags_get (&g_user_input_event_flags, RSA_EVENT_FLAG, TX_OR_CLEAR, &actual_flags, TX_WAIT_FOREVER);
    /* Check status. */
    if ((TX_SUCCESS == status) && (RSA_EVENT_FLAG == actual_flags))
    {
        /* Get the user input */
        status = tx_queue_receive(&g_user_input_queue,(VOID *)&read_data , TX_WAIT_TIME);
        if (TX_SUCCESS != status)
        {
            PRINT_ERR_STR("thread receive failed");
            ERROR_TRAP(status);
        }
    }
    tx_thread_sleep (THREAD_SLEEP_TIME);

    /* Validates the user input if the event flag is enabled or not */
    if(EVENT_FLAG_ENABLE == read_data)
    {

         while (true)
        {
            /* Wait for RSA event flag */
            status = tx_event_flags_get (&g_netx_crypto_event_flags, RSA_EVENT_FLAG, TX_OR_CLEAR, &actual_flags, TX_WAIT_TIME);

            /* Check status. */
            if ((TX_SUCCESS == status) && (RSA_EVENT_FLAG == actual_flags))
            {
                /* To know the time taken for an execution of each crypto algorithms and user can utilise the time variables
                 * by taking the difference of consecutive time arrays will give the exact time taken for execution */
                ULONG time[THREE] = {RESET_VALUE};
                PRINT_INFO_STR("_______________________netx crypto RSA demo start_________________________");
                /* Get the current time: */
                time[ZERO] = tx_time_get ();
                FSP_PARAMETER_NOT_USED(time);   //FSP_PARAM_NOT_USED is declared to avoid time warning
                /* Call the rsa 2048 example to execute the cypto algorithm */
                status = netx_secure_crypto_rsa_2048_example ();
                if (NX_CRYPTO_SUCCESS != status)
                {
                    PRINT_ERR_STR("netx_secure_crypto_rsa_2048_example is failed");
                    ERROR_TRAP(status);
                }
                /* Get the current time in 'time1' after executing the rsa 2048 example.
                 * By calculating the difference of time1 & time to get the actual execution time */
                time[ONE] = tx_time_get ();

                tx_thread_sleep (THREAD_SLEEP_TIME);
                /* Call the rsa 4096 example to execute the cypto algorithm */
                status = netx_secure_crypto_rsa_4096_example ();
                if (NX_CRYPTO_SUCCESS != status)
                {
                    PRINT_ERR_STR("netx_secure_crypto_rsa_4096_example is failed");
                    ERROR_TRAP(status);
                }
                /* Get the time after executing rsa 4096 example.
                 * By calculating the time difference of time2 & time1 will get the actual execution time period */
                time[TWO] = tx_time_get ();
                /* Call the sha 256 example to execute the cypto algorithm */
                status = netx_secure_crypto_sha256_example ();
                if (NX_CRYPTO_SUCCESS != status)
                {
                    PRINT_ERR_STR("netx_secure_crypto_sha256_example is failed");
                    ERROR_TRAP(status);
                }
                /* Get the time after executingsha 256 example.
                 * By calculating the time difference of time3 & time2 will get the actual execution time period */
                time[THREE] = tx_time_get ();
                /* Set ECC event flag to wakeup ecc thread. */
                status = tx_event_flags_set (&g_netx_crypto_event_flags, AES_EVENT_FLAG, TX_OR);
                PRINT_INFO_STR("_______________________netx crypto RSA demo end____________________________");
                tx_thread_sleep (THREAD_SLEEP_TIME);

            }
        }
    }
    else if(EVENT_FLAG_DISABLE == read_data) //execute without event switching
    {
        while(true)
        {
            /* Call the rsa 2048 example to execute the cypto algorithm */
            status = netx_secure_crypto_rsa_2048_example ();
            if (NX_CRYPTO_SUCCESS != status)
            {
                PRINT_ERR_STR("netx_secure_crypto_rsa_2048_example is failed");
                ERROR_TRAP(status);
            }
            tx_thread_sleep (THREAD_SLEEP_TIME);
            /* Call the rsa 4096 example to execute the cypto algorithm */
            status = netx_secure_crypto_rsa_4096_example ();
            if (NX_CRYPTO_SUCCESS != status)
            {
                PRINT_ERR_STR("netx_secure_crypto_rsa_4096_example is failed");
                ERROR_TRAP(status);
            }
            tx_thread_sleep (THREAD_SLEEP_TIME);
            /* Call the sha 256 example to execute the cypto algorithm */
            status = netx_secure_crypto_sha256_example ();
            if (NX_CRYPTO_SUCCESS != status)
            {
                PRINT_ERR_STR("netx_secure_crypto_sha256_example is failed");
                ERROR_TRAP(status);
            }
            tx_thread_sleep(THREAD_SLEEP_TIME);
        }
    }
    else
    {
        /* do nothing */
    }
}


/*******************************************************************************************************************//**
 * @brief     This is an example function for RSA on using NetX Crypto API to encrypt and decrypt the input message data
 *            of byte size of 2048.
 * @param[IN] None
 * @retval    NX_CRYPTO_SUCCESS or Any Other Error code apart from NX_CRYPTO_SUCCESS upon unsuccessful execution.
 **********************************************************************************************************************/
static uint32_t netx_secure_crypto_rsa_2048_example (void)
{
    uint8_t  metadata[sizeof(NX_CRYPTO_RSA)] = {RESET_VALUE};
    uint32_t metadata_size = sizeof(NX_CRYPTO_RSA);
    uint32_t status           = NX_CRYPTO_SUCCESS;
    void   * handler       = NX_CRYPTO_NULL;
    uint8_t  output[RM_NETX_SECURE_CRYPTO_EXAMPLE_OUTPUT_BUFFER_SIZE] = {RESET_VALUE};

    /* Setup the platform; initialize the SCE and the TRNG */
    status = _nx_crypto_initialize();
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_initialize in rsa is failed");
        return status;
    }
    PRINT_INFO_STR("RSA2048 algorithm initialized and started successfully...");
    /* Encryption. */
    status = _nx_crypto_method_rsa_init (&crypto_method_rsa, (uint8_t*) m_2048,
                                         RM_NETX_SECURE_CRYPTO_BYTES_TO_BITS(sizeof(m_2048)), &handler, metadata,
                                         metadata_size);
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_method_rsa_init in rsa is failed");
        return status;
    }
    status = _nx_crypto_method_rsa_operation (NX_CRYPTO_ENCRYPT, handler, &crypto_method_rsa, (uint8_t*) public_e,
                                              RM_NETX_SECURE_CRYPTO_BYTES_TO_BITS(sizeof(public_e)),
                                              (uint8_t*) plain_2048, sizeof(m_2048),
                                              NX_CRYPTO_NULL,
                                              output, sizeof(m_2048), metadata, metadata_size,
                                              NX_CRYPTO_NULL,
                                              NX_CRYPTO_NULL);
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_method_rsa_operation in RSA is failed");
        return status;
    }
    /* compares the output data with the expected secret key data */
    status = (uint32_t) memcmp(output, secret_2048, sizeof(m_2048));
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("key match in RSA is failed");
        return status;
    }
    /* cleanup the rsa metadata */
    status = _nx_crypto_method_rsa_cleanup(metadata);
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_method_rsa_cleanup in RSA is failed");
        return status;
    }

    memset(output, RESET_VALUE, sizeof(output));
    status = _nx_crypto_method_rsa_init (&crypto_method_rsa, (uint8_t*) m_2048,
                                         RM_NETX_SECURE_CRYPTO_BYTES_TO_BITS(sizeof(m_2048)), &handler, metadata,
                                         metadata_size);
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_method_rsa_init in RSA decrypt is failed");
        return status;
    }

    /* Decryption. */
    status = _nx_crypto_method_rsa_operation (NX_CRYPTO_DECRYPT, handler, &crypto_method_rsa, (uint8_t*) private_e_2048,
                                              RM_NETX_SECURE_CRYPTO_BYTES_TO_BITS(sizeof(private_e_2048)),
                                              (uint8_t*) secret_2048, sizeof(m_2048),
                                              NX_CRYPTO_NULL,
                                              output, sizeof(m_2048), metadata, metadata_size,
                                              NX_CRYPTO_NULL,
                                              NX_CRYPTO_NULL);
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_method_rsa_operation in RSA is failed");
        return status;
    }
    /* compare the output data with plain text of executing the decryption */
    status = (uint32_t) memcmp(output, plain_2048, sizeof(m_2048));
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("Key match in RSA decrypt is failed");
        return status;
    }
    PRINT_INFO_STR("RSA2048 algorithm executed successfully and encrypt/decrypt matches");
    /* cleanup the aes metadata */
    status = _nx_crypto_method_rsa_cleanup(metadata);
    if (NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_method_ecdsa_cleanup api is failed");
        return status;
    }
    return status;
}

/*******************************************************************************************************************//**
 * @brief     This is an example function for RSA on using NetX Crypto API to encrypt and decrypt the input message data
 *            of byte size of 4096.
 * @param[IN] None
 * @retval    NX_CRYPTO_SUCCESS or Any Other Error code apart from NX_CRYPTO_SUCCESS upon unsuccessful execution.
 **********************************************************************************************************************/
static uint32_t netx_secure_crypto_rsa_4096_example (void)
{
    uint8_t  metadata[sizeof(NX_CRYPTO_RSA)] = {RESET_VALUE};
    uint32_t metadata_size = sizeof(NX_CRYPTO_RSA);
    uint32_t status        = NX_CRYPTO_SUCCESS;
    void   * handler       = NX_CRYPTO_NULL;
    uint8_t  output[RM_NETX_SECURE_CRYPTO_EXAMPLE_OUTPUT_BUFFER_SIZE] = {RESET_VALUE};

    /* Setup the platform; initialize the SCE and the TRNG */
    status = _nx_crypto_initialize();
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_initialize in rsa4096 is failed");
        return status;
    }
    PRINT_INFO_STR("RSA4096 algorithm initialized and started successfully...");
    /* Encryption. */
    status = _nx_crypto_method_rsa_init (&crypto_method_rsa, (uint8_t*) m_4096,
                                         RM_NETX_SECURE_CRYPTO_BYTES_TO_BITS(sizeof(m_4096)), &handler, metadata,
                                         metadata_size);
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_method_rsa4096_init in rsa is failed");
        return status;
    }
    status = _nx_crypto_method_rsa_operation (NX_CRYPTO_ENCRYPT, handler, &crypto_method_rsa, (uint8_t*) public_e,
                                              RM_NETX_SECURE_CRYPTO_BYTES_TO_BITS(sizeof(public_e)),
                                              (uint8_t*) plain_4096, sizeof(m_4096),
                                              NX_CRYPTO_NULL,
                                              output, sizeof(m_4096), metadata, metadata_size,
                                              NX_CRYPTO_NULL,
                                              NX_CRYPTO_NULL);
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_method_rsa_operation in RSA4096 is failed");
        return status;
    }
    /* comapre the output of encrypted data with the expected secret key */
    status = (uint32_t) memcmp(output, secret_4096, sizeof(m_4096));
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("key match in RSA4096 is failed");
        return status;
    }
    /* clean up the rsa metadata */
    status = _nx_crypto_method_rsa_cleanup(metadata);
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_method_rsa_cleanup in RSA4096 is failed");
        return status;
    }

    PRINT_INFO_STR("RSA4096 algorithm executed successfully and encrypt matches");
    return status;
}

/*******************************************************************************************************************//**
 * @brief     This is an example function for HASH sha256 algorythm using NetX cypto API
 * @param[IN] None
 * @retval    X_CRYPTO_SUCCESS or Any Other Error code apart from NX_CRYPTO_SUCCESS upon unsuccessful execution.
 **********************************************************************************************************************/
static uint32_t netx_secure_crypto_sha256_example(void)
{
    size_t actual_hash_len = RM_NETX_SECURE_CRYPTO_EXAMPLE_SHA256_HASH_SIZE_LEN;
    uint8_t actual_hash[RM_NETX_SECURE_CRYPTO_EXAMPLE_SHA256_HASH_SIZE_BYTES] = {RESET_VALUE};
    uint8_t metadata[sizeof(NX_CRYPTO_SHA256)] = {RESET_VALUE};
    uint32_t metadata_size = sizeof(NX_CRYPTO_SHA256);
    void *handler = NX_CRYPTO_NULL;
    uint32_t status = NX_CRYPTO_SUCCESS;

    /* Setup the platform; initialize the SCE and the TRNG */
    status = _nx_crypto_initialize ();
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_initialize in sha_256 example is failed");
        return status;
    }

    PRINT_INFO_STR("SHA256 algorithm initialized and started successfully...");

    /* Nx Crypto SHA256 init */
    status = _nx_crypto_method_sha256_init (&crypto_method_sha256, NX_CRYPTO_NULL, NX_CRYPTO_NULL, &handler, metadata, metadata_size);
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_method_sha256_init in rsa is failed");
        return status;
    }
    /* Nx Crypto SHA256 operation - NX_CRYPTO_HASH_INITIALIZE */
    status = _nx_crypto_method_sha256_operation (NX_CRYPTO_HASH_INITIALIZE, handler, &crypto_method_sha256,
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL, NX_CRYPTO_NULL, metadata, metadata_size,
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL);
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_method_sha256_operation in rsa at NX_CRYPTO_HASH_INITIALIZE is failed");
        return status;
    }
    /* Nx Crypto SHA256 operation - NX_CRYPTO_HASH_UPDATE,
     * call this multiple times if needed to hash multiple data batches */
    status = _nx_crypto_method_sha256_operation (NX_CRYPTO_HASH_UPDATE, handler, &crypto_method_sha256,
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL, (uint8_t*) NIST_SHA256ShortMsgLen200,
                                                 sizeof(NIST_SHA256ShortMsgLen200),
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL, NX_CRYPTO_NULL, metadata, metadata_size,
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL);
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_method_sha256_operation in rsa at NX_CRYPTO_HASH_UPDATE is failed");
        return status;
    }
    /* Nx Crypto SHA256 operation - NX_CRYPTO_HASH_CALCULATE */
    status = _nx_crypto_method_sha256_operation (NX_CRYPTO_HASH_CALCULATE, handler, &crypto_method_sha256,
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL,
                                                 (uint8_t*) actual_hash, actual_hash_len, metadata, metadata_size,
                                                 NX_CRYPTO_NULL,
                                                 NX_CRYPTO_NULL);
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("_nx_crypto_method_sha256_operation in rsa at NX_CRYPTO_HASH_CALCULATE is failed");
        return status;
    }
    /* Ensure generated SHA256 hash matches the expected digest */
    status = (uint32_t) memcmp (&actual_hash[ZERO], &NIST_SHA256ShortMsgLen200_expected[ZERO], actual_hash_len);
    if(RESET_VALUE != status)
    {
        PRINT_ERR_STR("key match in sha 256 is failed");
        return status;
    }
    /* cleanup the sha256 metadata */
    status = _nx_crypto_method_sha256_cleanup(metadata);
    if(NX_CRYPTO_SUCCESS != status)
    {
        PRINT_ERR_STR("sha 256 cleanup api failed");
        return status;
    }
    PRINT_INFO_STR("sha256 algorithm is executed successfully!");
    return status;
}

/*******************************************************************************************************************//**
 * @} (end defgroup netx_crypto_ep)
 **********************************************************************************************************************/
