Skip to content

Commit 337456c

Browse files
Add support for (DevkitPro)libnds
1 parent 1c8f1e6 commit 337456c

10 files changed

Lines changed: 95 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
@@ -3815,7 +3815,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
38153815
return ret;
38163816
}
38173817

3818-
#elif defined(DOLPHIN_EMULATOR)
3818+
#elif defined(DOLPHIN_EMULATOR) || defined (NDS)
38193819

38203820
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
38213821
{

wolfcrypt/test/test.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,13 @@ const byte const_byte_array[] = "A+Gd\0\0\0";
426426
#ifdef DEVKITPRO
427427
#include <wiiuse/wpad.h>
428428
#endif
429+
#ifdef NDS
430+
#include <nds/ndstypes.h>
431+
#include <nds/arm9/console.h>
432+
#include <nds/arm9/input.h>
433+
#include <nds/interrupts.h>
434+
#include <fat.h>
435+
#endif
429436

430437
#ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV
431438
/* FIPS build has replaced ecc.h. */
@@ -2457,6 +2464,13 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
24572464
VIDEO_WaitVSync();
24582465
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
24592466
#endif
2467+
#ifdef NDS
2468+
// Init Console output
2469+
consoleDemoInit();
2470+
2471+
// Init the Filesystem
2472+
fatInitDefault();
2473+
#endif
24602474

24612475
#ifdef HAVE_WNR
24622476
if ((ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000)) != 0) {
@@ -2502,6 +2516,18 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
25022516
while (1);
25032517
#endif
25042518

2519+
#ifdef NDS
2520+
// in Nintendo DS returning from main shuts down the Device without letting you see the Results.
2521+
printf("args.return_code: %d\n", args.return_code);
2522+
printf("Testing complete. Press Start to exit the Program\n");
2523+
while(1) {
2524+
swiWaitForVBlank();
2525+
scanKeys();
2526+
int keys = keysDown();
2527+
if(keys & KEY_START) break;
2528+
}
2529+
#endif
2530+
25052531
#if defined(WOLFSSL_ESPIDF)
25062532
/* ESP_LOGI to print takes up a lot less memory than printf */
25072533
ESP_LOGI(ESPIDF_TAG, "Exiting main with return code: % d\n",
@@ -17955,6 +17981,10 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
1795517981
#elif defined(_WIN32_WCE)
1795617982
#define CERT_PREFIX "\\windows\\"
1795717983
#define CERT_PATH_SEP "\\"
17984+
#elif defined(NDS)
17985+
#undef CERT_PREFIX
17986+
#define CERT_PREFIX "fat:/_nds/"
17987+
#define CERT_PATH_SEP "/"
1795817988
#endif
1795917989

1796017990
#ifndef CERT_PREFIX

wolfssl/ssl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3127,7 +3127,7 @@ WOLFSSL_API int wolfSSL_make_eap_keys(WOLFSSL* ssl, void* key, unsigned int len,
31273127
!defined(WOLFSSL_PICOTCP) && !defined(WOLFSSL_ROWLEY_ARM) && \
31283128
!defined(WOLFSSL_EMBOS) && !defined(WOLFSSL_FROSTED) && \
31293129
!defined(WOLFSSL_CHIBIOS) && !defined(WOLFSSL_CONTIKI) && \
3130-
!defined(WOLFSSL_ZEPHYR) && !defined(NETOS)
3130+
!defined(WOLFSSL_ZEPHYR) && !defined(NETOS) && !defined(NDS)
31313131
#include <sys/uio.h>
31323132
#endif
31333133
/* 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: 20 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

@@ -469,6 +472,23 @@
469472
#include <nx_api.h>
470473
#endif
471474

475+
476+
#ifdef NDS
477+
#include <stddef.h>
478+
#define SIZEOF_LONG_LONG 8
479+
#define socklen_t int
480+
#define IPPROTO_UDP 17
481+
#define IPPROTO_TCP 6
482+
483+
/* Libnds doesn't include sys/uio.h. */
484+
/* Structure for scatter/gather I/O. */
485+
struct iovec
486+
{
487+
void *iov_base; /* Pointer to data. */
488+
size_t iov_len; /* Length of data. */
489+
};
490+
#endif
491+
472492
#if defined(ARDUINO)
473493
#if defined(ESP32)
474494
#ifndef NO_ARDUINO_DEFAULT

0 commit comments

Comments
 (0)