diff --git a/.gitignore b/.gitignore index b8e2457f..fc13b2b0 100644 --- a/.gitignore +++ b/.gitignore @@ -213,6 +213,7 @@ pk/ed448/ed448_sign pk/ed448/ed448_pub pk/ed448/ed448_keys pk/ed448/*.der +pk/curve25519/curve25519_test embedded/tls-client-server embedded/tls-server-size diff --git a/pk/curve25519/Makefile b/pk/curve25519/Makefile new file mode 100644 index 00000000..f696238f --- /dev/null +++ b/pk/curve25519/Makefile @@ -0,0 +1,12 @@ +CC=gcc +LIB_PATH=/usr/local +CFLAGS= -I$(LIB_PATH)/include -Wall +LIBS= -L$(LIB_PATH)/lib -lwolfssl + +curve25519_test: curve25519_test.o + $(CC) -o $@ $^ $(CFLAGS) $(LIBS) + +.PHONY: clean + +clean: + rm -f *.o curve25519_test diff --git a/pk/curve25519/curve25519_test.c b/pk/curve25519/curve25519_test.c new file mode 100644 index 00000000..8ade7d75 --- /dev/null +++ b/pk/curve25519/curve25519_test.c @@ -0,0 +1,157 @@ +/* curve25519_test.c + * + * Copyright (C) 2006-2021 wolfSSL Inc. + * + * This file is part of wolfSSL. (formerly known as CyaSSL) + * + * 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-1301, USA + */ + +#include +#include +#include +#include +#include + +/* +./configure --enable-curve25519 --enable-ed25519 && make && sudo make install +gcc -o curve25519_test -lwolfssl curve25519_test.c + +./configure --enable-curve25519 --enable-ed25519 --enable-debug --disable-shared && make +gcc -g -o curve25519_test -I. ./src/.libs/libwolfssl.a curve25519_test.c + */ + +#ifdef HAVE_CURVE25519 +static size_t hex2bin(byte* p, const char* hex) +{ + size_t len, i; + int x; + + len = strlen(hex); + if ((len & 1) != 0) { + return 0; + } + + for (i=0; i