/* MSP430 example main.c * * Copyright (C) 2006-2022 wolfSSL Inc. * * This file is part of wolfSSL. * * wolfSSL is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * wolfSSL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ #include #include #include #include #include #include #include #include #include #include #include /* Without __root on some of the functions, IAR's "Discard Unused Publics" will optimze out some of the functions */ #if defined(__IAR_SYSTEMS_ICC__) #define IAR_KEEP __root #else #define IAR_KEEP #endif #define ECC_256_BIT_FIELD 32 /* 256-bit curve field */ #define WOLF_GEN_MEM (2*1024) #define CHACHA_TEST_LEN 1024 static byte gWolfMem[WOLF_GEN_MEM]; static byte generatedCiphertext[CHACHA_TEST_LEN]; static byte generatedPlaintext[CHACHA_TEST_LEN]; #define MCLK_FREQ_MHZ 8 /* MCLK = 8MHz */ static const byte key[] = { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f }; static const byte plaintext[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras lacus odio, pretium vel sagittis ac, facilisis quis diam. Vivamus condimentum velit sed dolor consequat interdum. Etiam eleifend ornare felis, eleifend egestas odio vulputate eu. Sed nec orci nunc. Etiam quis mi augue. Donec ullamcorper suscipit lorem, vel luctus augue cursus fermentum. Etiam a porta arcu, in convallis sem. Integer efficitur elementum diam, vel scelerisque felis posuere placerat. Donec vestibulum sit amet leo sit amet tincidunt. Etiam et vehicula turpis. Phasellus quis finibus sapien. Sed et tristique turpis. Nullam vitae sagittis tortor, et aliquet lorem. Cras a leo scelerisque, convallis lacus ut, fermentum urna. Mauris quis urna diam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam aliquam vehicula orci id pulvinar. Proin mollis, libero sollicitudin tempor ultrices, massa augue tincidunt turpis, sit amet aliquam neque nibh nec dui. Fusce finibus massa quis rutrum suscipit cras amet"; static const byte iv[] = { 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 }; static const byte aad[] = { /* additional data */ 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 }; volatile unsigned int seconds; IAR_KEEP unsigned int msp430_time(long *x) { return seconds; } static void print_secret(char* who, byte* s, int sLen) { int i; printf("%ss' Secret: ", who); for (i = 0; i < sLen; i++) { printf("%02x", s[i]); } printf("\r\n"); } /* This is a very crude RNG, do not use in production */ IAR_KEEP unsigned int msp430_rnd(void) { unsigned int result = TA0R ^ TA2R; printf("Rand generated: %d\r\n", result); return result; } static void uart_init() { P8SEL |= BIT3 + BIT2; UCA1CTLW0 = UCSWRST; /* Put eUSCI in reset */ UCA1CTLW0 |= UCSSEL__SMCLK; /* CLK = SMCLK */ /* Baud Rate calculation This was calculated to produce 115200 for a 16MHz clock, so it produces 57600 at 8MHz 16000000/(16*115200) = 8.6805 Fractional portion = 0.6805 Use Table 24-5 in Family User Guide */ UCA1BR0 = 8; UCA1BR1 = 0x00; UCA1MCTL |= UCOS16 | UCBRF_11 | UCBRS_0; UCA1CTLW0 &= ~UCSWRST; /* Initialize eUSCI */ UCA1IE |= UCRXIE; /* Enable USCI_A0 RX interrupt */ } #if defined(__IAR_SYSTEMS_ICC__) IAR_KEEP size_t __write(int fd, const unsigned char *_ptr, size_t len) #else int write(int fd, const char *_ptr, int len) #endif { size_t i; for(i=0 ; i