Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for (DevkitPro)libnds #7990

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ linuxkm/libwolfssl.mod.c
linuxkm/libwolfssl.lds
linuxkm/module_exports.c
linuxkm/linuxkm/get_thread_size
*.nds

# autotools generated
scripts/unit.test
Expand Down
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Fixed in github pull request https://github.com/wolfSSL/wolfssl/pull/7702
* Support for NIST 800-56C Option 1 KDF, using the macro WC_KDF_NIST_SP_800_56C added (PR 7589)
* AES-XTS streaming mode added, along with hardware acceleration and kernel module use (PR 7522, 7560, 7424)
* PlatformIO FreeRTOS with ESP build and addition of benchmark and test example applications (PR 7528, 7413, 7559, 7542)
* Add support for (DevkitPro)libnds


## Enhancements and Optimizations
Expand Down
36 changes: 36 additions & 0 deletions IDE/NDS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# wolfSSL for libnds

## Requirements

[Devkitpro](https://devkitpro.org/wiki/Getting_Started) with libnds.


## Building

```
$ ./configure \
--host=arm-none-eabi \
CC=$DEVKITARM/bin/arm-none-eabi-g++ \
AR=$DEVKITARM/bin/arm-none-eabi-ar \
STRIP=$DEVKITARM/bin/arm-none-eabi-strip \
RANLIB=$DEVKITARM/bin/arm-none-eabi-ranlib \
LIBS="-lfat -lnds9" \
LDFLAGS="-L/opt/devkitpro/libnds/lib" \
--prefix=$DEVKITPRO/portlibs/nds \
CFLAGS="-march=armv5te -mtune=arm946e-s \
--specs=ds_arm9.specs -DARM9 -DNDS \
-DWOLFSSL_USER_IO \
-I$DEVKITPRO/libnds/include" \
--enable-fastmath --disable-benchmark \
--disable-shared --disable-examples --disable-ecc
$ make
$ sudo make install
```

## Run the Tests

To run the Crypttests type the following.
1. Run `$ ndstool -9 ./wolfcrypt/test/testwolfcrypt -c ./wolfcrypt/test/testwolfcrypt.nds`
2. copy `./certs` to `your_nds_sd_card/_nds/certs`

3. Run the Rom (located in ./wolfcrypt/test/testwolfcrypt.nds) in an Emulator or real Hardware.
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Fixed in github pull request https://github.com/wolfSSL/wolfssl/pull/7702
* Support for NIST 800-56C Option 1 KDF, using the macro WC_KDF_NIST_SP_800_56C added (PR 7589)
* AES-XTS streaming mode added, along with hardware acceleration and kernel module use (PR 7522, 7560, 7424)
* PlatformIO FreeRTOS with ESP build and addition of benchmark and test example applications (PR 7528, 7413, 7559, 7542)
* Add support for (DevkitPro)libnds


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


## Enhancements and Optimizations
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -3815,7 +3815,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
return ret;
}

#elif defined(DOLPHIN_EMULATOR)
#elif defined(DOLPHIN_EMULATOR) || defined (NDS)

int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
Expand Down
30 changes: 30 additions & 0 deletions wolfcrypt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ const byte const_byte_array[] = "A+Gd\0\0\0";
#ifdef DEVKITPRO
#include <wiiuse/wpad.h>
#endif
#ifdef NDS
dgarske marked this conversation as resolved.
Show resolved Hide resolved
#include <nds/ndstypes.h>
#include <nds/arm9/console.h>
#include <nds/arm9/input.h>
#include <nds/interrupts.h>
#include <fat.h>
#endif

#ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV
/* FIPS build has replaced ecc.h. */
Expand Down Expand Up @@ -2457,6 +2464,13 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
#endif
#ifdef NDS
/* Init Console output */
dgarske marked this conversation as resolved.
Show resolved Hide resolved
consoleDemoInit();

/* Init the Filesystem */
fatInitDefault();
#endif

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

#ifdef NDS
/* in Nintendo DS returning from main shuts down the Device without letting you see the Results. */
printf("args.return_code: %d\n", args.return_code);
printf("Testing complete. Press Start to exit the Program\n");
while(1) {
swiWaitForVBlank();
scanKeys();
int keys = keysDown();
if(keys & KEY_START) break;
}
#endif

#if defined(WOLFSSL_ESPIDF)
/* ESP_LOGI to print takes up a lot less memory than printf */
ESP_LOGI(ESPIDF_TAG, "Exiting main with return code: % d\n",
Expand Down Expand Up @@ -17955,6 +17981,10 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
#elif defined(_WIN32_WCE)
#define CERT_PREFIX "\\windows\\"
#define CERT_PATH_SEP "\\"
#elif defined(NDS)
#undef CERT_PREFIX
#define CERT_PREFIX "fat:/_nds/"
#define CERT_PATH_SEP "/"
#endif

#ifndef CERT_PREFIX
Expand Down
2 changes: 1 addition & 1 deletion wolfssl/ssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3127,7 +3127,7 @@ WOLFSSL_API int wolfSSL_make_eap_keys(WOLFSSL* ssl, void* key, unsigned int len,
!defined(WOLFSSL_PICOTCP) && !defined(WOLFSSL_ROWLEY_ARM) && \
!defined(WOLFSSL_EMBOS) && !defined(WOLFSSL_FROSTED) && \
!defined(WOLFSSL_CHIBIOS) && !defined(WOLFSSL_CONTIKI) && \
!defined(WOLFSSL_ZEPHYR) && !defined(NETOS)
!defined(WOLFSSL_ZEPHYR) && !defined(NETOS) && !defined(NDS)
#include <sys/uio.h>
#endif
/* allow writev style writing */
Expand Down
4 changes: 3 additions & 1 deletion wolfssl/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#ifndef NDS
#include <sys/ioctl.h>
#endif
#include <sys/time.h>
#include <sys/socket.h>
#ifdef HAVE_PTHREAD
Expand Down
13 changes: 13 additions & 0 deletions wolfssl/wolfcrypt/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@
/* Uncomment next line if building for Dolphin Emulator */
/* #define DOLPHIN_EMULATOR */

/* Uncomment next line if building for NDS */
/* #define NDS */

/* Uncomment next line if using MAXQ1065 */
/* #define WOLFSSL_MAXQ1065 */

Expand Down Expand Up @@ -469,6 +472,16 @@
#include <nx_api.h>
#endif


#ifdef NDS
#include <stddef.h>
#define SIZEOF_LONG_LONG 8
#define socklen_t int
#define IPPROTO_UDP 17
#define IPPROTO_TCP 6
#define NO_WRITEV
#endif

#if defined(ARDUINO)
#if defined(ESP32)
#ifndef NO_ARDUINO_DEFAULT
Expand Down