Skip to content

Commit d72c0b3

Browse files
Merge pull request #7990 from buchstabenwurst/master
Add support for (DevkitPro)libnds
2 parents efd4127 + 6c5b174 commit d72c0b3

10 files changed

Lines changed: 88 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ linuxkm/libwolfssl.mod.c
245245
linuxkm/libwolfssl.lds
246246
linuxkm/module_exports.c
247247
linuxkm/linuxkm/get_thread_size
248+
*.nds
248249

249250
# autotools generated
250251
scripts/unit.test

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Fixed in github pull request https://github.com/wolfSSL/wolfssl/pull/7702
4949
* Support for NIST 800-56C Option 1 KDF, using the macro WC_KDF_NIST_SP_800_56C added (PR 7589)
5050
* AES-XTS streaming mode added, along with hardware acceleration and kernel module use (PR 7522, 7560, 7424)
5151
* PlatformIO FreeRTOS with ESP build and addition of benchmark and test example applications (PR 7528, 7413, 7559, 7542)
52+
* Add support for (DevkitPro)libnds
5253

5354

5455
## Enhancements and Optimizations

IDE/NDS/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# wolfSSL for libnds
2+
3+
## Requirements
4+
5+
[Devkitpro](https://devkitpro.org/wiki/Getting_Started) with libnds.
6+
7+
8+
## Building
9+
10+
```
11+
$ ./configure \
12+
--host=arm-none-eabi \
13+
CC=$DEVKITARM/bin/arm-none-eabi-g++ \
14+
AR=$DEVKITARM/bin/arm-none-eabi-ar \
15+
STRIP=$DEVKITARM/bin/arm-none-eabi-strip \
16+
RANLIB=$DEVKITARM/bin/arm-none-eabi-ranlib \
17+
LIBS="-lfat -lnds9" \
18+
LDFLAGS="-L/opt/devkitpro/libnds/lib" \
19+
--prefix=$DEVKITPRO/portlibs/nds \
20+
CFLAGS="-march=armv5te -mtune=arm946e-s \
21+
--specs=ds_arm9.specs -DARM9 -DNDS \
22+
-DWOLFSSL_USER_IO \
23+
-I$DEVKITPRO/libnds/include" \
24+
--enable-fastmath --disable-benchmark \
25+
--disable-shared --disable-examples --disable-ecc
26+
$ make
27+
$ sudo make install
28+
```
29+
30+
## Run the Tests
31+
32+
To run the Crypttests type the following.
33+
1. Run `$ ndstool -9 ./wolfcrypt/test/testwolfcrypt -c ./wolfcrypt/test/testwolfcrypt.nds`
34+
2. copy `./certs` to `your_nds_sd_card/_nds/certs`
35+
36+
3. Run the Rom (located in ./wolfcrypt/test/testwolfcrypt.nds) in an Emulator or real Hardware.

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Fixed in github pull request https://github.com/wolfSSL/wolfssl/pull/7702
121121
* Support for NIST 800-56C Option 1 KDF, using the macro WC_KDF_NIST_SP_800_56C added (PR 7589)
122122
* AES-XTS streaming mode added, along with hardware acceleration and kernel module use (PR 7522, 7560, 7424)
123123
* PlatformIO FreeRTOS with ESP build and addition of benchmark and test example applications (PR 7528, 7413, 7559, 7542)
124+
* Add support for (DevkitPro)libnds
124125

125126

126127
## Enhancements and Optimizations

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Fixed in github pull request https://github.com/wolfSSL/wolfssl/pull/7702
126126
* Support for NIST 800-56C Option 1 KDF, using the macro WC_KDF_NIST_SP_800_56C added (PR 7589)
127127
* AES-XTS streaming mode added, along with hardware acceleration and kernel module use (PR 7522, 7560, 7424)
128128
* PlatformIO FreeRTOS with ESP build and addition of benchmark and test example applications (PR 7528, 7413, 7559, 7542)
129+
* Add support for (DevkitPro)libnds
129130
130131
131132
## Enhancements and Optimizations

wolfcrypt/src/random.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3817,7 +3817,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
38173817
return ret;
38183818
}
38193819

3820-
#elif defined(DOLPHIN_EMULATOR)
3820+
#elif defined(DOLPHIN_EMULATOR) || defined (NDS)
38213821

38223822
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
38233823
{

wolfcrypt/test/test.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,13 @@ const byte const_byte_array[] = "A+Gd\0\0\0";
429429
#ifdef DEVKITPRO
430430
#include <wiiuse/wpad.h>
431431
#endif
432+
#ifdef NDS
433+
#include <nds/ndstypes.h>
434+
#include <nds/arm9/console.h>
435+
#include <nds/arm9/input.h>
436+
#include <nds/interrupts.h>
437+
#include <fat.h>
438+
#endif
432439

433440
#ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV
434441
/* FIPS build has replaced ecc.h. */
@@ -2466,6 +2473,13 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
24662473
VIDEO_WaitVSync();
24672474
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
24682475
#endif
2476+
#ifdef NDS
2477+
/* Init Console output */
2478+
consoleDemoInit();
2479+
2480+
/* Init the Filesystem */
2481+
fatInitDefault();
2482+
#endif
24692483

24702484
#ifdef HAVE_WNR
24712485
if ((ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000)) != 0) {
@@ -2511,6 +2525,18 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
25112525
while (1);
25122526
#endif
25132527

2528+
#ifdef NDS
2529+
/* in Nintendo DS returning from main shuts down the Device without letting you see the Results. */
2530+
printf("args.return_code: %d\n", args.return_code);
2531+
printf("Testing complete. Press Start to exit the Program\n");
2532+
while(1) {
2533+
swiWaitForVBlank();
2534+
scanKeys();
2535+
int keys = keysDown();
2536+
if(keys & KEY_START) break;
2537+
}
2538+
#endif
2539+
25142540
#if defined(WOLFSSL_ESPIDF)
25152541
/* ESP_LOGI to print takes up a lot less memory than printf */
25162542
ESP_LOGI(ESPIDF_TAG, "Exiting main with return code: % d\n",
@@ -18083,6 +18109,10 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
1808318109
#elif defined(_WIN32_WCE)
1808418110
#define CERT_PREFIX "\\windows\\"
1808518111
#define CERT_PATH_SEP "\\"
18112+
#elif defined(NDS)
18113+
#undef CERT_PREFIX
18114+
#define CERT_PREFIX "fat:/_nds/"
18115+
#define CERT_PATH_SEP "/"
1808618116
#endif
1808718117

1808818118
#ifndef CERT_PREFIX

wolfssl/ssl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3164,7 +3164,7 @@ WOLFSSL_API int wolfSSL_make_eap_keys(WOLFSSL* ssl, void* key, unsigned int len,
31643164
!defined(WOLFSSL_PICOTCP) && !defined(WOLFSSL_ROWLEY_ARM) && \
31653165
!defined(WOLFSSL_EMBOS) && !defined(WOLFSSL_FROSTED) && \
31663166
!defined(WOLFSSL_CHIBIOS) && !defined(WOLFSSL_CONTIKI) && \
3167-
!defined(WOLFSSL_ZEPHYR) && !defined(NETOS)
3167+
!defined(WOLFSSL_ZEPHYR) && !defined(NETOS) && !defined(NDS)
31683168
#include <sys/uio.h>
31693169
#endif
31703170
/* allow writev style writing */

wolfssl/test.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@
203203
#include <netinet/in.h>
204204
#include <netinet/tcp.h>
205205
#include <arpa/inet.h>
206-
#include <sys/ioctl.h>
206+
#ifndef NDS
207+
#include <sys/ioctl.h>
208+
#endif
207209
#include <sys/time.h>
208210
#include <sys/socket.h>
209211
#ifdef HAVE_PTHREAD

wolfssl/wolfcrypt/settings.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@
262262
/* Uncomment next line if building for Dolphin Emulator */
263263
/* #define DOLPHIN_EMULATOR */
264264

265+
/* Uncomment next line if building for NDS */
266+
/* #define NDS */
267+
265268
/* Uncomment next line if using MAXQ1065 */
266269
/* #define WOLFSSL_MAXQ1065 */
267270

@@ -470,6 +473,16 @@
470473
#include <nx_api.h>
471474
#endif
472475

476+
477+
#ifdef NDS
478+
#include <stddef.h>
479+
#define SIZEOF_LONG_LONG 8
480+
#define socklen_t int
481+
#define IPPROTO_UDP 17
482+
#define IPPROTO_TCP 6
483+
#define NO_WRITEV
484+
#endif
485+
473486
#if defined(ARDUINO)
474487
#if defined(ESP32)
475488
#ifndef NO_ARDUINO_DEFAULT

0 commit comments

Comments
 (0)