|
| 1 | +/* example_main.c |
| 2 | + * |
| 3 | + * Copyright (C) 2006-2025 wolfSSL Inc. |
| 4 | + * |
| 5 | + * This file is part of wolfSSL. |
| 6 | + * |
| 7 | + * wolfSSL is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * wolfSSL is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| 20 | + */ |
| 21 | +#include <wolfssl/wolfcrypt/types.h> |
| 22 | +#include <wolfssl/wolfcrypt/aes.h> |
| 23 | +#include <wolfssl/wolfcrypt/cmac.h> |
| 24 | +#include "iodefine.h" |
| 25 | +#include "rh_string.h" |
| 26 | +#include "r_system.h" |
| 27 | +#include "r_intc.h" |
| 28 | + |
| 29 | +void R_LIN_Init(void); |
| 30 | +void R_UART_Init(void); |
| 31 | +void R_UART_SendString(char string[]); |
| 32 | + |
| 33 | +#define INTC2ICOSTM0 INTC2.ICOSTM0.UINT16 |
| 34 | + |
| 35 | +#define MSG_LEN 128 |
| 36 | + |
| 37 | +char msg_buf[MSG_LEN + 1]; |
| 38 | +size_t msg_offset = 0; |
| 39 | + |
| 40 | +int rsapss_sign_verify(); |
| 41 | + |
| 42 | +/* 1ms tick timer */ |
| 43 | +static long tick = 0; |
| 44 | +#define NUMINTCOSTM0 0x54 |
| 45 | +#pragma interrupt INTCOSTM0(enable=true, channel=NUMINTCOSTM0) |
| 46 | +void INTCOSTM0(void) |
| 47 | +{ |
| 48 | + tick++; |
| 49 | +} |
| 50 | + |
| 51 | +#define YEAR ( \ |
| 52 | + ((__DATE__)[7] - '0') * 1000 + \ |
| 53 | + ((__DATE__)[8] - '0') * 100 + \ |
| 54 | + ((__DATE__)[9] - '0') * 10 + \ |
| 55 | + ((__DATE__)[10] - '0') * 1 \ |
| 56 | +) |
| 57 | + |
| 58 | +#define MONTH ( \ |
| 59 | + __DATE__[2] == 'n' ? (__DATE__[1] == 'a' ? 1 : 6) \ |
| 60 | + : __DATE__[2] == 'b' ? 2 \ |
| 61 | + : __DATE__[2] == 'r' ? (__DATE__[0] == 'M' ? 3 : 4) \ |
| 62 | + : __DATE__[2] == 'y' ? 5 \ |
| 63 | + : __DATE__[2] == 'l' ? 7 \ |
| 64 | + : __DATE__[2] == 'g' ? 8 \ |
| 65 | + : __DATE__[2] == 'p' ? 9 \ |
| 66 | + : __DATE__[2] == 't' ? 10 \ |
| 67 | + : __DATE__[2] == 'v' ? 11 \ |
| 68 | + : 12 \ |
| 69 | + ) |
| 70 | + |
| 71 | +time_t time(time_t *t) |
| 72 | +{ |
| 73 | + (void)t; |
| 74 | + return ((YEAR-1970)*365+30*MONTH)*24*60*60 + tick++; |
| 75 | +} |
| 76 | + |
| 77 | +void PrintTextln(char* TextArray) |
| 78 | +{ |
| 79 | + R_UART_SendString(TextArray); |
| 80 | + R_UART_SendString("\r\n"); |
| 81 | +} |
| 82 | + |
| 83 | +void main(void); |
| 84 | + |
| 85 | +#if !defined(WOLFSSL_STATIC_MEMORY) |
| 86 | +#include <stddef.h> |
| 87 | +#define SIZEOF_HEAP 0xB000 |
| 88 | +int _REL_sysheap[SIZEOF_HEAP >> 2]; |
| 89 | +size_t _REL_sizeof_sysheap = SIZEOF_HEAP; |
| 90 | +#endif |
| 91 | + |
| 92 | +void main(void) |
| 93 | +{ |
| 94 | + byte ret; |
| 95 | + |
| 96 | + R_SYSTEM_ClockInit(); |
| 97 | + R_SYSTEM_TimerInit(); |
| 98 | + R_SYSTEM_TimerStart(); |
| 99 | + R_UART_Init(); |
| 100 | + R_LIN_Init(); |
| 101 | + /* Enable Table Interrupt */ |
| 102 | + R_INTC_SetTableBit((uint16_t*)R_ICOSTM0); |
| 103 | + R_INTC_UnmaskInterrupt((uint16_t*)R_ICOSTM0); |
| 104 | + /* Enable interrupts */ |
| 105 | + __EI(); |
| 106 | + |
| 107 | + rh_string_init(MSG_LEN + 1, &msg_offset, msg_buf); |
| 108 | + printf("System Initialization finish."); |
| 109 | + printf("RSA Sign and Verify Example"); |
| 110 | + |
| 111 | + ret = rsapss_sign_verify(); |
| 112 | + if (ret != 0) { |
| 113 | + printf("rsapss_sign_verify failed ret=%d.", ret); |
| 114 | + } |
| 115 | +} |
0 commit comments