diff --git a/.github/workflows/gcc_m32_toolchain.txt b/.github/workflows/gcc_m32_toolchain.txt new file mode 100644 index 000000000..f2735d2aa --- /dev/null +++ b/.github/workflows/gcc_m32_toolchain.txt @@ -0,0 +1,18 @@ +# Specify the CMake version +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR i386) +set(CMAKE_C_COMPILER gcc) + +# Specify the compiler flags +set(CMAKE_C_FLAGS "-m32") +set(CMAKE_CXX_FLAGS "-m32") + +# Specify the linker flags +set(CMAKE_SHARED_LINKER_FLAGS "-m32") +set(CMAKE_EXE_LINKER_FLAGS "-m32") + +# Specify the paths to search for libraries and includes +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index fc2547733..c3faa317f 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -13,13 +13,13 @@ jobs: include: - python-version: 2.7 cffi: no - os: macos-10.15 + os: macos-12 - python-version: 2.7 cffi: yes - os: macos-10.15 + os: macos-12 - python-version: "3.11" cffi: yes - os: macos-10.15 + os: macos-12 - python-version: 2.7 cffi: no os: windows-latest @@ -90,34 +90,48 @@ jobs: run: | mypy lib/ - test_c: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Test - run: | - cd src/test - make - - test_c_i386: + test_c_linux: runs-on: ubuntu-latest + strategy: + matrix: + sse: [0, 1] + arch: [x64, x32] steps: - uses: actions/checkout@v3 - name: Install dependencies run: | sudo apt-get update sudo apt-get install libc6-dev-i386 - - name: Test + - name: Test Linux x32 and x64 run: | cd src/test - CFLAGS="-m32" UNDEFS="-UHAVE_UINT128" make + mkdir build + GCC_M32_TOOLCHAIN=${{ github.workspace }}/.github/workflows/gcc_m32_toolchain.txt + EXTRA=$([ ${{ matrix.arch }} = x32 ] && echo "-DCMAKE_TOOLCHAIN_FILE=$GCC_M32_TOOLCHAIN" || true) + cmake -B build -DSSE=${{ matrix.sse }} $EXTRA + make -C build all test - test_c_sse2: - runs-on: ubuntu-latest + test_c_windows: + runs-on: windows-latest + strategy: + matrix: + arch: + - x64 + - win32 steps: - uses: actions/checkout@v3 - - name: Test + - name: Set up Python "3.11" + uses: actions/setup-python@v4 + with: + python-version: "3.11" + - name: Install MSVC + uses: ilammy/msvc-dev-cmd@f456b805b3f63911738cb71d4f255e4e129c7e7a + with: + arch: ${{ matrix.arch }} + - name: Test Windows 32 and 64 run: | cd src/test - CPPFLAGS="-DHAVE_X86INTRIN_H" make - + mkdir build + cmake -B build -G "NMake Makefiles" + cd build + nmake all test diff --git a/Doc/src/cipher/chacha20.rst b/Doc/src/cipher/chacha20.rst index 2c794b058..192802fbf 100644 --- a/Doc/src/cipher/chacha20.rst +++ b/Doc/src/cipher/chacha20.rst @@ -67,7 +67,7 @@ you need to explicitly generate and pass a 96 bit (12 byte) ``nonce`` parameter Code* (such as :doc:`HMAC <../hash/hmac>`) to authenticate the ciphertext (*encrypt-then-mac*). Alternatively, you can use :doc:`ChaCha20_Poly1305 `. -.. _ChaCha20: http://http://cr.yp.to/chacha.html +.. _ChaCha20: https://cr.yp.to/chacha.html .. _RFC7539: https://tools.ietf.org/html/rfc7539 .. automodule:: Crypto.Cipher.ChaCha20 diff --git a/lib/Crypto/PublicKey/ECC.py b/lib/Crypto/PublicKey/ECC.py index acac73ee7..5472df97c 100644 --- a/lib/Crypto/PublicKey/ECC.py +++ b/lib/Crypto/PublicKey/ECC.py @@ -101,7 +101,7 @@ int ed25519_get_xy(uint8_t *xb, uint8_t *yb, size_t modsize, Point *p); int ed25519_double(Point *p); int ed25519_add(Point *P1, const Point *P2); -int ed25519_scalar(Point *P, uint8_t *scalar, size_t scalar_len, uint64_t seed); +int ed25519_scalar(Point *P, const uint8_t *scalar, size_t scalar_len, uint64_t seed); """) _ed448_lib = load_pycryptodome_raw_lib("Crypto.PublicKey._ed448", """ diff --git a/lib/Crypto/Util/asn1.py b/lib/Crypto/Util/asn1.py index 4510e0bda..59d5956b1 100644 --- a/lib/Crypto/Util/asn1.py +++ b/lib/Crypto/Util/asn1.py @@ -530,6 +530,10 @@ def append(self, item): self._seq.append(item) return self + def insert(self, index, item): + self._seq.insert(index, item) + return self + def hasInts(self, only_non_negative=True): """Return the number of items in this sequence that are integers. diff --git a/src/bignum.c b/src/bignum.c index 0af06568e..f74c87ae8 100644 --- a/src/bignum.c +++ b/src/bignum.c @@ -164,7 +164,7 @@ STATIC int mod_select(uint64_t *out, const uint64_t *a, const uint64_t *b, unsig pairs = (unsigned)words / 2; mask = (uint64_t)((cond != 0) - 1); /* 0 for a, 1s for b */ -#if SYSBITS == 64 +#if SYS_BITS == 64 r0 = _mm_set1_epi64x(mask); #else r0 = _mm_loadl_epi64((__m128i*)&mask); diff --git a/src/common.h b/src/common.h index 5abcec5d5..d0d9aa940 100644 --- a/src/common.h +++ b/src/common.h @@ -75,10 +75,17 @@ typedef unsigned __int64 uint64_t; #define UINT32_MAX 0xFFFFFFFFUL #endif +#ifndef UINT64_MAX +#define UINT64_MAX 0xFFFFFFFFFFFFFFFFUL +#endif + #endif /* HAVE_STDINT_H */ #ifdef _MSC_VER +/** Fix for warning C4668 **/ +#define WIN32_LEAN_AND_MEAN + #define inline _inline #define RESTRICT __restrict @@ -109,15 +116,17 @@ typedef unsigned __int64 uint64_t; /* * On Windows, distutils expects that a CPython module always exports the symbol init${MODNAME} */ -#if defined(_MSC_VER) || defined(__MINGW32__) -#include -#if PY_MAJOR_VERSION >= 3 -#define FAKE_INIT(x) PyMODINIT_FUNC _PASTE2(PyInit__,x) (void) { return NULL; } -#else -#define FAKE_INIT(x) PyMODINIT_FUNC _PASTE2(init_,x) (void) { return; } -#endif +#if defined(NO_CPYTHON_MODULE) + #define FAKE_INIT(x) +#elif defined(_MSC_VER) || defined(__MINGW32__) + #include + #if PY_MAJOR_VERSION >= 3 + #define FAKE_INIT(x) PyMODINIT_FUNC _PASTE2(PyInit__,x) (void) { return NULL; } + #else + #define FAKE_INIT(x) PyMODINIT_FUNC _PASTE2(init_,x) (void) { return; } + #endif #else -#define FAKE_INIT(x) + #define FAKE_INIT(x) #endif /* diff --git a/src/ed25519.c b/src/ed25519.c index 8895557d1..43906e6ce 100644 --- a/src/ed25519.c +++ b/src/ed25519.c @@ -322,7 +322,7 @@ EXPORT_SYM int ed25519_add(Point *P1, const Point *P2) return 0; } -EXPORT_SYM int ed25519_scalar(Point *P, uint8_t *scalar, size_t scalar_len, uint64_t seed) +EXPORT_SYM int ed25519_scalar(Point *P, const uint8_t *scalar, size_t scalar_len, uint64_t seed) { if ((NULL == P) || (NULL == scalar)) return ERR_NULL; diff --git a/src/ed25519.h b/src/ed25519.h index 21cb0e452..7cf4de535 100644 --- a/src/ed25519.h +++ b/src/ed25519.h @@ -18,6 +18,6 @@ EXPORT_SYM int ed25519_neg(Point *p); EXPORT_SYM int ed25519_get_xy(uint8_t *xb, uint8_t *yb, size_t modsize, Point *p); EXPORT_SYM int ed25519_double(Point *p); EXPORT_SYM int ed25519_add(Point *P1, const Point *P2); -EXPORT_SYM int ed25519_scalar(Point *P, uint8_t *scalar, size_t scalar_len, uint64_t seed); +EXPORT_SYM int ed25519_scalar(Point *P, const uint8_t *scalar, size_t scalar_len, uint64_t seed); #endif diff --git a/src/ed448.c b/src/ed448.c index 5fdcc63be..e98661500 100644 --- a/src/ed448.c +++ b/src/ed448.c @@ -297,8 +297,20 @@ EXPORT_SYM int ed448_new_context(EcContext **pec_ctx) EcContext *ec_ctx = NULL; int res; MontContext *ctx; - const uint8_t mod448_be[56] = "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; - const uint8_t d448_be[56] = "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x67\x56"; + const uint8_t mod448_be[56] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + const uint8_t d448_be[56] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x67, 0x56}; if (NULL == pec_ctx) return ERR_NULL; diff --git a/src/mont.c b/src/mont.c index 2c887a9ed..9cac791dd 100644 --- a/src/mont.c +++ b/src/mont.c @@ -312,7 +312,7 @@ STATIC void mont_mult_p256(uint64_t *out, const uint64_t *a, const uint64_t *b, k = t[i]; /* n[0] = 2⁶⁴ - 1 */ - prod_lo = -k; + prod_lo = (uint64_t)(0 - k); prod_hi = k - (k!=0); t[i+0] += prod_lo; prod_hi += t[i+0] < prod_lo; @@ -474,7 +474,7 @@ STATIC void mont_mult_p384(uint64_t *out, const uint64_t *a, const uint64_t *b, uint64_t prod_lo, prod_hi; k = t[i] + (t[i] << 32); - k2_lo = -k; + k2_lo = (uint64_t)(0 - k); k2_hi = k - (k!=0); /* n[0] = 2³² - 1 */ @@ -628,7 +628,7 @@ STATIC void mont_mult_ed448(uint64_t *out, const uint64_t *a, const uint64_t *b, uint64_t prod_lo, prod_hi; k = t[i]; - k2_lo = -k; + k2_lo = (uint64_t)(0 - k); k2_hi = k - (k!=0); /* n[0] = 2⁶⁴ - 1 */ @@ -1047,7 +1047,7 @@ int mont_inv_prime(uint64_t *out, uint64_t *a, const MontContext *ctx) } /* - * Assign a value to a number in Montgomer form. + * Assign a value to a number in Montgomery form. * * @param out The location where the result is stored at; it must have been created with mont_number(&p,1,ctx). * @param x The value to set. @@ -1123,10 +1123,32 @@ static int cmp_modulus(const uint8_t *mod1, size_t mod1_len, const uint8_t *mod2 */ int mont_context_init(MontContext **out, const uint8_t *modulus, size_t mod_len) { - const uint8_t p256_mod[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; - const uint8_t p384_mod[48] = "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff"; - const uint8_t p521_mod[66] = "\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; - const uint8_t ed448_mod[56] = "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; + const uint8_t p256_mod[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + const uint8_t p384_mod[48] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF}; + const uint8_t p521_mod[66] = {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF}; + const uint8_t ed448_mod[56] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint64_t *scratchpad = NULL; MontContext *ctx; int res; diff --git a/src/multiply_32.c b/src/multiply_32.c index f1cd8c0f6..86147d71d 100644 --- a/src/multiply_32.c +++ b/src/multiply_32.c @@ -132,7 +132,7 @@ void static inline addmul32(uint32_t* t, size_t offset, const uint32_t *a, uint3 * t[] and a[] are little-endian. * Return the number of 64-bit words that we wrote into t[] */ -void inline addmul128(uint64_t *t, uint64_t *scratchpad, const uint64_t *a, uint64_t b0, uint64_t b1, size_t t_nw, size_t a_nw) +void addmul128(uint64_t *t, uint64_t *scratchpad, const uint64_t *a, uint64_t b0, uint64_t b1, size_t t_nw, size_t a_nw) { uint32_t b0l, b0h, b1l, b1h; uint32_t *t32, *a32; @@ -249,7 +249,7 @@ void static inline square_32(uint32_t *t, const uint32_t *a, size_t nw) assert(carry == 0); } -void inline square(uint64_t *t, uint64_t *scratchpad, const uint64_t *a, size_t nw) +void square(uint64_t *t, uint64_t *scratchpad, const uint64_t *a, size_t nw) { uint32_t *t32, *a32; #ifndef PYCRYPTO_LITTLE_ENDIAN diff --git a/src/multiply_64.c b/src/multiply_64.c index 080e516ce..e9d517613 100644 --- a/src/multiply_64.c +++ b/src/multiply_64.c @@ -59,7 +59,7 @@ #endif -void inline addmul128(uint64_t *t, uint64_t *scratchpad, const uint64_t *a, uint64_t b0, uint64_t b1, size_t t_words, size_t a_nw) +void addmul128(uint64_t *t, uint64_t *scratchpad, const uint64_t *a, uint64_t b0, uint64_t b1, size_t t_words, size_t a_nw) { uint64_t sum_low, sum_mid, sum_hi; uint64_t pr_low, pr_high, aim1; @@ -195,7 +195,7 @@ void inline addmul128(uint64_t *t, uint64_t *scratchpad, const uint64_t *a, uint } -void inline square(uint64_t *t, uint64_t *scratchpad, const uint64_t *a, size_t nw) +void square(uint64_t *t, uint64_t *scratchpad, const uint64_t *a, size_t nw) { size_t i, j; uint64_t carry; diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt new file mode 100644 index 000000000..0a2ea6377 --- /dev/null +++ b/src/test/CMakeLists.txt @@ -0,0 +1,179 @@ +cmake_minimum_required(VERSION 3.13) +project(test_crypto LANGUAGES C) +include(CMakePrintHelpers) +enable_testing() + +cmake_print_variables(CMAKE_CXX_COMPILER_ID CMAKE_CXX_COMPILER_VERSION CMAKE_SIZEOF_VOID_P SSE) + +option(SSE "Enable SSE instructions on Intel targets" ON) + +if (DEFINED ENV{PYTHON}) + set(PYTHON $ENV{PYTHON}) +else() + set(PYTHON python) +endif() + +include_directories("${CMAKE_SOURCE_DIR}/..") + +# Disable any code related to CPython modules +# This is only required for MSVC, and it avoids a dependency on the CPython libraries +add_compile_definitions(NO_CPYTHON_MODULE) + +# Ensure that private functions can be accessed +add_compile_definitions(STATIC=) + +# TODO: add check for big endianess too +add_compile_definitions(PYCRYPTO_LITTLE_ENDIAN) + +if (MSVC) + add_compile_options(/Wall /sdl) + # Disable certain warnings + add_compile_options(/wd4100 /wd4820 /wd5045) +else() + add_compile_definitions(HAVE_STDINT_H) + add_compile_definitions(HAVE_POSIX_MEMALIGN) + add_compile_options(-O2 -g -fstrict-aliasing -Wall -Werror) + if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) + # Macro HAVE_UINT128 should be defined when __uint128_t type is available, + # that is, only on Unix 64 bits. It is not available with MSVC or with Unix 32 bits. + add_compile_definitions(HAVE_UINT128) + else() + # On 32-bit x86 platforms, gcc assumes the stack to be aligned to 16 + # bytes, but the caller may actually only align it to 4 bytes, which + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838 + add_compile_options(-mstackrealign) + endif() +endif() + +if (CMAKE_SIZEOF_VOID_P EQUAL 8) + add_compile_definitions(SYS_BITS=64) +else() + add_compile_definitions(SYS_BITS=32) +endif() + +# Use processor extensions +# TODO: add exception if non-x86 platform +if (MSVC) + add_compile_definitions(HAVE_INTRIN_H) + add_compile_definitions(USE_SSE2) + add_compile_definitions(HAVE_WMMINTRIN_H) + add_compile_definitions(HAVE_TMMINTRIN_H) +else() + if (SSE) + message(STATUS "Using SSE instructions") + add_compile_definitions(HAVE_X86INTRIN_H) + add_compile_definitions(HAVE_WMMINTRIN_H) + add_compile_definitions(HAVE_TMMINTRIN_H) + add_compile_options(-mssse3 -mpclmul) + endif() +endif() + +# ------------------------------------------------------------------------- + +# montgomery +add_library(mont OBJECT ../mont.c) + +add_executable(test_mont test_mont.c $) +add_test(NAME test_mont COMMAND test_mont) + +add_custom_command( + OUTPUT test_addmul.c + COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_addmul.py > test_addmul.c + DEPENDS make_tests_addmul.py +) +add_executable(test_addmul test_addmul.c $) +add_test(NAME test_addmul COMMAND test_addmul) + +add_custom_command( + OUTPUT test_addmul_128.c + COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_addmul128.py > test_addmul_128.c + DEPENDS make_tests_addmul128.py +) +add_executable(test_addmul128 ${CMAKE_BINARY_DIR}/test_addmul_128.c) +if (CMAKE_SIZEOF_VOID_P EQUAL 8) + target_sources(test_addmul128 PUBLIC ../multiply_64.c) +else() + target_sources(test_addmul128 PUBLIC ../multiply_32.c) +endif() +add_test(NAME test_addmul128 COMMAND test_addmul128) + +add_custom_command( + OUTPUT test_product.c + COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_product.py > test_product.c + DEPENDS make_tests_product.py +) +add_executable(test_product test_product.c $) +add_test(NAME test_product COMMAND test_product) + +add_custom_command( + OUTPUT test_mont_mult.c + COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_mont_mult.py > test_mont_mult.c + DEPENDS make_tests_mont_mult.py +) +add_executable(test_mont_mult test_mont_mult.c $) +add_test(NAME test_mont_mult COMMAND test_mont_mult) + +# ec_ws +add_library(tables OBJECT ../p256_table.c ../p384_table.c ../p521_table.c) +add_executable(test_ec_ws test_ec_ws.c ../ec_ws.c $ $) +add_test(NAME test_ec_ws COMMAND test_ec_ws) + +# endianess +add_executable(test_endianess test_endianess.c) +add_test(NAME endianess COMMAND test_endianess) + +# clmul +if (SSE) + add_executable(test_clmul test_clmul.c ../ghash_clmul.c) + add_test(NAME test_clmul COMMAND test_clmul) +endif() + +# poly1305 +add_library(poly1305 OBJECT ../poly1305.c) +foreach (f reduce load_r load_m multiply accumulate) + add_custom_command( + OUTPUT test_poly1305_${f}.c + COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_poly1305_${f}.py > test_poly1305_${f}.c + DEPENDS make_tests_poly1305_${f}.py + ) + add_executable(test_poly1305_${f} ${CMAKE_BINARY_DIR}/test_poly1305_${f}.c $) + add_test(NAME test_poly1305_${f} COMMAND test_poly1305_${f}) +endforeach() + +# pkcs1 +add_executable(test_pkcs1 test_pkcs1.c ../pkcs1_decode.c) +add_test(NAME test_pkcs1 COMMAND test_pkcs1) + +# curve25519 +add_library(mod25519 OBJECT ../mod25519.c ../multiply_32.c) +add_library(x25519 OBJECT ../x25519.c ../multiply_32.c) + +add_executable(test_mod25519 test_mod25519.c $) +add_test(NAME test_mod25519 COMMAND test_mod25519) + +add_custom_command( + OUTPUT test_mul_25519.c + COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_mul_25519.py > test_mul_25519.c + DEPENDS make_tests_mul_25519.py +) +add_executable(test_mul_25519 test_mul_25519.c $) +add_test(NAME test_mul_25519 COMMAND test_mul_25519) + +add_executable(test_x25519 test_x25519.c $) +add_test(NAME test_x25519 COMMAND test_x25519) + +add_custom_command( + OUTPUT tests_ladder_step.c + COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/make_tests_ladder_step.py > tests_ladder_step.c + DEPENDS make_tests_ladder_step.py +) +add_executable(tests_ladder_step tests_ladder_step.c $) +add_test(NAME tests_ladder_step COMMAND tests_ladder_step) + +# ed25519 +add_executable(test_ed25519 test_ed25519.c ../ed25519.c ../multiply_32.c) +add_test(NAME test_ed25519 COMMAND test_ed25519) + +# ed448 +add_executable(test_ed448 test_ed448.c ../ed448.c $) +add_test(NAME test_ed448 COMMAND test_ed448) diff --git a/src/test/Makefile b/src/test/Makefile deleted file mode 100644 index e173bdbe7..000000000 --- a/src/test/Makefile +++ /dev/null @@ -1,183 +0,0 @@ -PYTHON ?= python -CPPFLAGS += -I.. $(shell $(PYTHON) -c "from __future__ import print_function; import sys; print('-DPYCRYPTO_' + sys.byteorder.upper() + '_ENDIAN')") -CPPFLAGS += -DHAVE_POSIX_MEMALIGN -DHAVE_STDINT_H -CPPFLAGS += -DSTATIC="" -CFLAGS += -O3 -g -fstrict-aliasing -Wall -Werror - -TAPPS:=tests_addmul128_32 tests_addmul128_64 tests_square_32 tests_square_64 tests_product tests_addmul test_endianess\ - test_poly1305_reduce test_poly1305_load_r test_poly1305_load_m test_poly1305_multiply test_poly1305_accumulate\ - test_mont tests_mont_mult tests_ec_ws_64 tests_ec_ws_32 test_pkcs1\ - test_mod25519 test_x25519 tests_mul_25519 tests_ladder_step test_ed25519 test_ed448 - -ifneq (,$(filter $(shell uname -m),x86_64 i386 i686)) -CPPFLAGS += -DHAVE_X86INTRIN_H -DUSE_SSE2 -DHAVE_WMMINTRIN_H -DHAVE_TMMINTRIN_H -CFLAGS += -msse2 -TAPPS += test_clmul -endif - -ifeq (64bit, $(shell $(PYTHON) -c "from __future__ import print_function; import platform; print(platform.architecture()[0])")) -CPPFLAGS += -DHAVE_UINT128 -endif - -CPPFLAGS += $(UNDEFS) - -TGTS:=$(foreach t,$(TAPPS),build/$t) - -test: build ${TGTS} - set -e && for t in ${TGTS}; do $$t; done - -build: - mkdir build - -all: ${$TGTS} - -clean: - rm -fr build common.pyc __pycache__ - -# ECC -TABLES = build/p256_table.o build/p384_table.o build/p521_table.o - -build/p256_table.o: ../p256_table.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -c -o $@ $^ - -build/p384_table.o: ../p384_table.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -c -o $@ $^ - -build/p521_table.o: ../p521_table.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -c -o $@ $^ - -build/tests_ec_ws_64: test_ec_ws.c ../ec_ws.c build/mont_64.o $(TABLES) - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ - -build/tests_ec_ws_32: test_ec_ws.c ../ec_ws.c build/mont_32.o $(TABLES) - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ -DSYS_BITS=32 -UHAVE_UINT128 - -# addmul128 - -build/tests_addmul128.c: make_tests_addmul128.py - $(PYTHON) $^ > $@ - -build/tests_addmul128_32: build/tests_addmul128.c ../multiply_32.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ - -build/tests_addmul128_64: build/tests_addmul128.c ../multiply_64.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ - -# square - -build/tests_square.c: make_tests_square.py - $(PYTHON) $^ > $@ - -build/tests_square_32: build/tests_square.c ../multiply_32.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ - -build/tests_square_64: build/tests_square.c ../multiply_64.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ - -# endianess - -build/test_endianess: test_endianess.c ../common.h - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $< - -# clmul - -build/clmul.o: ../ghash_clmul.c - $(CC) $(CFLAGS) -mssse3 -mpclmul $(CPPFLAGS) -o $@ $< -c - -build/test_clmul: test_clmul.c ../common.h build/clmul.o - $(CC) $(CFLAGS) -mssse3 -mpclmul $(CPPFLAGS) $(LDFLAGS) -o $@ $(filter %.c %.o, $^) - -# Poly1305 - -build/poly1305.o: ../poly1305.c - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ -c - -build/test_poly1305_reduce.c: make_tests_poly1305_reduce.py - $(PYTHON) $^ > $@ - -build/test_poly1305_load_r.c: make_tests_poly1305_load_r.py - $(PYTHON) $^ > $@ - -build/test_poly1305_load_m.c: make_tests_poly1305_load_m.py - $(PYTHON) $^ > $@ - -build/test_poly1305_multiply.c: make_tests_poly1305_multiply.py - $(PYTHON) $^ > $@ - -build/test_poly1305_accumulate.c: make_tests_poly1305_accumulate.py - $(PYTHON) $^ > $@ - -build/test_poly1305_reduce: build/test_poly1305_reduce.c ../common.h build/poly1305.o - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(filter %.c %.o, $^) - -build/test_poly1305_load_r: build/test_poly1305_load_r.c ../common.h build/poly1305.o - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(filter %.c %.o, $^) - -build/test_poly1305_load_m: build/test_poly1305_load_m.c ../common.h build/poly1305.o - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(filter %.c %.o, $^) - -build/test_poly1305_multiply: build/test_poly1305_multiply.c ../common.h build/poly1305.o - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(filter %.c %.o, $^) - -build/test_poly1305_accumulate: build/test_poly1305_accumulate.c ../common.h build/poly1305.o - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(filter %.c %.o, $^) - -# Montgomery - -build/mont_32.o: ../mont.c - $(CC) -c $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ -DSYS_BITS=32 -UHAVE_UINT128 - -build/mont_64.o: ../mont.c - $(CC) -c $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ -DSYS_BITS=64 - -build/test_mont: test_mont.c ../common.h build/mont_32.o - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(filter %.c %.o, $^) - -build/tests_addmul.c: make_tests_addmul.py - $(PYTHON) $^ > $@ - -build/tests_addmul: build/tests_addmul.c build/mont_32.o - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ - -build/tests_product.c: make_tests_product.py - $(PYTHON) $^ > $@ - -build/tests_product: build/tests_product.c build/mont_32.o - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ - -build/tests_mont_mult.c: make_tests_mont_mult.py - $(PYTHON) $^ > $@ - -build/tests_mont_mult: build/tests_mont_mult.c build/mont_32.o - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ - -# pkcs1 -build/test_pkcs1: test_pkcs1.c ../common.h ../pkcs1_decode.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ - -# Curve25519 -build/test_mod25519: test_mod25519.c ../mod25519.c ../multiply_32.c - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ - -build/tests_mul_25519.c: make_tests_mul_25519.py - $(PYTHON) $^ > $@ - -build/tests_mul_25519: build/tests_mul_25519.c ../mod25519.c ../multiply_32.c - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ - -build/test_x25519: test_x25519.c ../x25519.c ../multiply_32.c - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ - -build/tests_ladder_step.c: make_tests_ladder_step.py - $(PYTHON) $^ > $@ - -build/tests_ladder_step: build/tests_ladder_step.c ../x25519.c ../multiply_32.c - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ - -# Ed25519 -build/test_ed25519: test_ed25519.c ../ed25519.c ../multiply_32.c - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ - -# Ed448 -build/test_ed448: test_ed448.c ../ed448.c build/mont_64.o - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ diff --git a/src/test/make_tests_addmul.py b/src/test/make_tests_addmul.py index b2c035a28..a4e836b87 100644 --- a/src/test/make_tests_addmul.py +++ b/src/test/make_tests_addmul.py @@ -28,7 +28,7 @@ def make_test(t, a, k): test_nr = next(counter) print("") - print("void test_%d() {" % test_nr) + print("void test_%d(void) {" % test_nr) #print ' printf("Test #%d\\n");' % test_nr print(" const uint64_t a[] = {" + ", ".join(a) + "};") print(" uint64_t t[] = {" + ", ".join(t_in) + ", 0xAAAAAAAAAAAAAAAAULL};") diff --git a/src/test/make_tests_addmul128.py b/src/test/make_tests_addmul128.py index bbd715f48..98b51fd81 100644 --- a/src/test/make_tests_addmul128.py +++ b/src/test/make_tests_addmul128.py @@ -27,7 +27,7 @@ def make_test(t, a, b0, b1): result.append("0") print("") - print("void test_%d() {" % next(counter)) + print("void test_%d(void) {" % next(counter)) print(" const uint64_t a[] = {" + ", ".join(a) + "};") print(" uint64_t t[] = {" + ", ".join(t_in) + ", 0xAAAAAAAAAAAAAAAAULL};") print(" uint64_t scratchpad[%d];" % (len(t_in) + len(a))) diff --git a/src/test/make_tests_ladder_step.py b/src/test/make_tests_ladder_step.py index 711347200..d51363810 100644 --- a/src/test/make_tests_ladder_step.py +++ b/src/test/make_tests_ladder_step.py @@ -39,7 +39,7 @@ def make_test_max(): z3outx = words + ["0"] * (4 - len(words)) print("") - print("void test_%d() {" % next(counter)) + print("void test_%d(void) {" % next(counter)) print(" uint32_t x2[10] = { " + ",".join(v) + " };") print(" uint32_t z2[10] = { " + ",".join(v) + " };") print(" uint32_t x3[10] = { " + ",".join(v) + " };") @@ -102,7 +102,7 @@ def make_test(x2, z2, x3, z3, xp): z3outx = words + ["0"] * (4 - len(words)) print("") - print("void test_%d() {" % next(counter)) + print("void test_%d(void) {" % next(counter)) print(" const uint64_t x2_in[4] = {" + ", ".join(x2x) + "};") print(" const uint64_t z2_in[4] = {" + ", ".join(z2x) + "};") print(" const uint64_t x3_in[4] = {" + ", ".join(x3x) + "};") diff --git a/src/test/make_tests_mont_mult.py b/src/test/make_tests_mont_mult.py index c8d6d1489..74588fe29 100644 --- a/src/test/make_tests_mont_mult.py +++ b/src/test/make_tests_mont_mult.py @@ -49,7 +49,7 @@ def make_test(a, b, modulus, use_mont=True): if use_mont: test_nr = next(counter) print("") - print("void test_%d() {" % test_nr) + print("void test_%d(void) {" % test_nr) print(" const uint64_t a[] = {" + ", ".join(a_m_s) + "};") print(" const uint64_t b[] = {" + ", ".join(b_m_s) + "};") print(" const uint64_t n[] = {" + ", ".join(modulus_s) + "};") @@ -66,7 +66,7 @@ def make_test(a, b, modulus, use_mont=True): test_nr = next(counter) print("") - print("void test_%d() {" % test_nr) + print("void test_%d(void) {" % test_nr) print(" const uint64_t a[] = {" + ", ".join(a_m_s) + "};") print(" const uint64_t b[] = {" + ", ".join(b_m_s) + "};") print(" const uint8_t modulus[] = {" + ", ".join(modulus_b) + "};") diff --git a/src/test/make_tests_mul_25519.py b/src/test/make_tests_mul_25519.py index d6cc2a80e..ed11d5961 100644 --- a/src/test/make_tests_mul_25519.py +++ b/src/test/make_tests_mul_25519.py @@ -38,7 +38,7 @@ def make_test(f, g): results_hex.append(words) print("") - print("void test_%d() {" % next(counter)) + print("void test_%d(void) {" % next(counter)) print(" const uint32_t f[10] = {" + ", ".join(fx) + "};") print(" const uint32_t g[10] = {" + ", ".join(gx) + "};") print(" uint32_t out[10];") diff --git a/src/test/make_tests_poly1305_accumulate.py b/src/test/make_tests_poly1305_accumulate.py index 02e6a9efe..8c68331c8 100644 --- a/src/test/make_tests_poly1305_accumulate.py +++ b/src/test/make_tests_poly1305_accumulate.py @@ -17,7 +17,7 @@ def make_test(term1, term2): res_split = split32(term1 + term2, 5) print("") - print("void test_%d() {" % next(counter)) + print("void test_%d(void) {" % next(counter)) print(" uint32_t h[5] = {" + ",".join(t1_split) + "};") print(" uint32_t m[5] = {" + ",".join(t2_split) + "};") print(" uint32_t w[5] = {" + ",".join(res_split) + "};") diff --git a/src/test/make_tests_poly1305_load_m.py b/src/test/make_tests_poly1305_load_m.py index fa6915f39..3e8f1935a 100644 --- a/src/test/make_tests_poly1305_load_m.py +++ b/src/test/make_tests_poly1305_load_m.py @@ -13,7 +13,7 @@ def make_test(secret): m_out = [ "0x%08xUL" % x for x in split ] print("") - print("void test_%d() {" % next(counter)) + print("void test_%d(void) {" % next(counter)) print(" uint8_t secret[%d] = {" % len(secret), end=' ') print(",".join([str(x) for x in secret]) + "};") print(" uint32_t m[5] = { 0 };") diff --git a/src/test/make_tests_poly1305_load_r.py b/src/test/make_tests_poly1305_load_r.py index 9152ced71..f8b6c57f4 100644 --- a/src/test/make_tests_poly1305_load_r.py +++ b/src/test/make_tests_poly1305_load_r.py @@ -20,7 +20,7 @@ def make_test(secret): rr_out = [ "0x%08xUL" % ((x>>2)*5) for x in split ] print("") - print("void test_%d() {" % next(counter)) + print("void test_%d(void) {" % next(counter)) print(" uint8_t secret[16] = {" + ",".join([str(x) for x in secret]) + "};") print(" uint32_t r[5] = { 0 };") print(" uint32_t rr[5] = { 0 };") diff --git a/src/test/make_tests_poly1305_multiply.py b/src/test/make_tests_poly1305_multiply.py index 73e829a11..9a500a1b7 100644 --- a/src/test/make_tests_poly1305_multiply.py +++ b/src/test/make_tests_poly1305_multiply.py @@ -37,7 +37,7 @@ def make_test(term, secret): h_split = split32(term, 5) print("") - print("void test_%d() {" % next(counter)) + print("void test_%d(void) {" % next(counter)) print(" uint8_t secret[16] = {" + ",".join([str(x) for x in secret]) + "};") print(" uint32_t r[4], rr[4];") print(" uint32_t h[5] = {" + ",".join(h_split) + "};") diff --git a/src/test/make_tests_poly1305_reduce.py b/src/test/make_tests_poly1305_reduce.py index e0340ad8c..f9fe11d5b 100644 --- a/src/test/make_tests_poly1305_reduce.py +++ b/src/test/make_tests_poly1305_reduce.py @@ -11,7 +11,7 @@ def make_test(value): h_out = split32(result, 5) print("") - print("void test_%d() {" % next(counter)) + print("void test_%d(void) {" % next(counter)) print(" uint32_t h[5] = {" + ", ".join(h_in) + "};") print(" const uint32_t expected_h[5] = {" + ", ".join(h_out) + "};") print("") diff --git a/src/test/make_tests_product.py b/src/test/make_tests_product.py index 6423feaca..e9f5fb6ab 100644 --- a/src/test/make_tests_product.py +++ b/src/test/make_tests_product.py @@ -25,7 +25,7 @@ def make_test(a, b): t = [ "0xCCCCCCCCCCCCCCCCULL" ] * result_len print("") - print("void test_%d() {" % next(counter)) + print("void test_%d(void) {" % next(counter)) print(" const uint64_t a[] = {" + ", ".join(a) + "};") print(" const uint64_t b[] = {" + ", ".join(b) + "};") print(" uint64_t t[] = {" + ", ".join(t) + ", 0xAAAAAAAAAAAAAAAAULL};") diff --git a/src/test/make_tests_square.py b/src/test/make_tests_square.py index 94b40e0e5..7b52143b5 100644 --- a/src/test/make_tests_square.py +++ b/src/test/make_tests_square.py @@ -21,7 +21,7 @@ def make_test(a): t = [ "0xCCCCCCCCCCCCCCCCULL" ] * result_len print("") - print("void test_%d() {" % next(counter)) + print("void test_%d(void) {" % next(counter)) print(" const uint64_t a[] = {" + ", ".join(a) + "};") print(" uint64_t t[] = {" + ", ".join(t) + ", 0xAAAAAAAAAAAAAAAAULL};") print(" uint64_t scratchpad[%d];" % (3*len(a))) diff --git a/src/test/test_clmul.c b/src/test/test_clmul.c index e94a56f5e..260365925 100644 --- a/src/test/test_clmul.c +++ b/src/test/test_clmul.c @@ -1,5 +1,10 @@ -#include "../common.h" +#include "common.h" + +#ifdef _MSC_VER +#include +#else #include +#endif __m128i reduce(__m128i prod_high, __m128i prod_low); void clmult(__m128i *prod_high, __m128i *prod_low, __m128i a, __m128i b); diff --git a/src/test/test_ec_ws.c b/src/test/test_ec_ws.c index 1f3d6a1e0..478df2533 100644 --- a/src/test/test_ec_ws.c +++ b/src/test/test_ec_ws.c @@ -80,7 +80,10 @@ void test_ec_projective_to_affine(void) { Workplace *wp; MontContext *ctx; - const uint8_t modulus[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; + const uint8_t modulus[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint64_t *x, *y, *z; uint8_t buffer[32]; uint64_t zero[4] = { 0 }; @@ -118,7 +121,10 @@ void test_ec_full_double(void) { Workplace *wp; MontContext *ctx; - const uint8_t modulus[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; + const uint8_t modulus[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint64_t *x, *y, *z; uint64_t *b; uint8_t buffer[32]; @@ -173,7 +179,10 @@ void test_ec_mix_add(void) { Workplace *wp; MontContext *ctx; - const uint8_t modulus[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; + const uint8_t modulus[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint64_t *x1, *y1, *z1; uint64_t *x2, *y2; uint64_t *b; @@ -258,7 +267,10 @@ void test_ec_full_add(void) { Workplace *wp; MontContext *ctx; - const uint8_t modulus[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; + const uint8_t modulus[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint64_t *x1, *y1, *z1; uint64_t *x2, *y2, *z2; uint64_t *x3, *y3, *z3; @@ -364,7 +376,10 @@ void test_ec_scalar(void) { Workplace *wp1, *wp2; MontContext *ctx; - const uint8_t modulus[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; + const uint8_t modulus[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint64_t *x1, *y1, *z1; uint64_t *x2, *y2, *z2; uint64_t *b; @@ -441,9 +456,18 @@ void test_ec_scalar_g_p256(void) { Workplace *wp1, *wp2; MontContext *ctx; - const uint8_t modulus[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; - const uint8_t Gx[32] = "\x6b\x17\xd1\xf2\xe1\x2c\x42\x47\xf8\xbc\xe6\xe5\x63\xa4\x40\xf2\x77\x03\x7d\x81\x2d\xeb\x33\xa0\xf4\xa1\x39\x45\xd8\x98\xc2\x96"; - const uint8_t Gy[32] = "\x4f\xe3\x42\xe2\xfe\x1a\x7f\x9b\x8e\xe7\xeb\x4a\x7c\x0f\x9e\x16\x2b\xce\x33\x57\x6b\x31\x5e\xce\xcb\xb6\x40\x68\x37\xbf\x51\xf5"; + const uint8_t modulus[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + const uint8_t Gx[32] = {0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, + 0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, + 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0, + 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96}; + const uint8_t Gy[32] = {0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, + 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16, + 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, + 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5}; uint64_t *b; int res; @@ -544,12 +568,30 @@ void test_ec_ws_new_point(void) EcContext *ec_ctx; EcPoint *ecp; int res; - uint8_t Gx[32] = "\x6b\x17\xd1\xf2\xe1\x2c\x42\x47\xf8\xbc\xe6\xe5\x63\xa4\x40\xf2\x77\x03\x7d\x81\x2d\xeb\x33\xa0\xf4\xa1\x39\x45\xd8\x98\xc2\x96"; - uint8_t Gx_wrong[32] = "\x6b\x17\xd1\xf2\xe1\x2c\x42\x47\xf8\xbc\xe6\xe5\x63\xa4\x40\xf2\x77\x03\x7d\x81\x2d\xeb\x33\xa0\xf4\xa1\x39\x45\xd8\x98\xc2\x97"; - uint8_t Gy[32] = "\x4f\xe3\x42\xe2\xfe\x1a\x7f\x9b\x8e\xe7\xeb\x4a\x7c\x0f\x9e\x16\x2b\xce\x33\x57\x6b\x31\x5e\xce\xcb\xb6\x40\x68\x37\xbf\x51\xf5"; - const uint8_t b[32] = "\x5a\xc6\x35\xd8\xaa\x3a\x93\xe7\xb3\xeb\xbd\x55\x76\x98\x86\xbc\x65\x1d\x06\xb0\xcc\x53\xb0\xf6\x3b\xce\x3c\x3e\x27\xd2\x60\x4b"; - const uint8_t order[32] = "\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xbc\xe6\xfa\xad\xa7\x17\x9e\x84\xf3\xb9\xca\xc2\xfc\x63\x25\x51"; - uint8_t modulus[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; + const uint8_t Gx[32] = {0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, + 0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, + 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0, + 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96}; + const uint8_t Gx_wrong[32] = {0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, + 0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, + 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0, + 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x97}; + const uint8_t Gy[32] = {0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, + 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16, + 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, + 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5}; + const uint8_t b[32] = {0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7, + 0xB3, 0xEB, 0xBD, 0x55, 0x76, 0x98, 0x86, 0xBC, + 0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6, + 0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B}; + const uint8_t order[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, + 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51}; + const uint8_t modulus[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint8_t zero[32] = { 0 }; res = ec_ws_new_context(&ec_ctx, modulus, b, order, 32, 0); @@ -585,11 +627,26 @@ void test_ec_ws_get_xy(void) EcContext *ec_ctx; EcPoint *ecp; int res; - uint8_t Gx[32] = "\x6b\x17\xd1\xf2\xe1\x2c\x42\x47\xf8\xbc\xe6\xe5\x63\xa4\x40\xf2\x77\x03\x7d\x81\x2d\xeb\x33\xa0\xf4\xa1\x39\x45\xd8\x98\xc2\x96"; - uint8_t Gy[32] = "\x4f\xe3\x42\xe2\xfe\x1a\x7f\x9b\x8e\xe7\xeb\x4a\x7c\x0f\x9e\x16\x2b\xce\x33\x57\x6b\x31\x5e\xce\xcb\xb6\x40\x68\x37\xbf\x51\xf5"; - uint8_t b[32] = "\x5a\xc6\x35\xd8\xaa\x3a\x93\xe7\xb3\xeb\xbd\x55\x76\x98\x86\xbc\x65\x1d\x06\xb0\xcc\x53\xb0\xf6\x3b\xce\x3c\x3e\x27\xd2\x60\x4b"; - const uint8_t order[32] = "\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xbc\xe6\xfa\xad\xa7\x17\x9e\x84\xf3\xb9\xca\xc2\xfc\x63\x25\x51"; - uint8_t modulus[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; + const uint8_t Gx[32] = {0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, + 0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, + 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0, + 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96}; + const uint8_t Gy[32] = {0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, + 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16, + 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, + 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5}; + const uint8_t b[32] = {0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7, + 0xB3, 0xEB, 0xBD, 0x55, 0x76, 0x98, 0x86, 0xBC, + 0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6, + 0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B}; + const uint8_t order[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, + 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51}; + const uint8_t modulus[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint8_t bufx[32], bufy[32]; res = ec_ws_new_context(&ec_ctx, modulus, b, order, 32, 0); @@ -623,11 +680,26 @@ void test_ec_ws_double_p256(void) EcContext *ec_ctx; EcPoint *ecp; int res; - uint8_t Gx[32] = "\x6b\x17\xd1\xf2\xe1\x2c\x42\x47\xf8\xbc\xe6\xe5\x63\xa4\x40\xf2\x77\x03\x7d\x81\x2d\xeb\x33\xa0\xf4\xa1\x39\x45\xd8\x98\xc2\x96"; - uint8_t Gy[32] = "\x4f\xe3\x42\xe2\xfe\x1a\x7f\x9b\x8e\xe7\xeb\x4a\x7c\x0f\x9e\x16\x2b\xce\x33\x57\x6b\x31\x5e\xce\xcb\xb6\x40\x68\x37\xbf\x51\xf5"; - uint8_t b[32] = "\x5a\xc6\x35\xd8\xaa\x3a\x93\xe7\xb3\xeb\xbd\x55\x76\x98\x86\xbc\x65\x1d\x06\xb0\xcc\x53\xb0\xf6\x3b\xce\x3c\x3e\x27\xd2\x60\x4b"; - const uint8_t order[32] = "\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xbc\xe6\xfa\xad\xa7\x17\x9e\x84\xf3\xb9\xca\xc2\xfc\x63\x25\x51"; - uint8_t modulus[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; + const uint8_t Gx[32] = {0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, + 0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, + 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0, + 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96}; + const uint8_t Gy[32] = {0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, + 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16, + 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, + 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5}; + const uint8_t b[32] = {0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7, + 0xB3, 0xEB, 0xBD, 0x55, 0x76, 0x98, 0x86, 0xBC, + 0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6, + 0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B}; + const uint8_t order[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, + 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51}; + const uint8_t modulus[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint8_t bufx[32], bufy[32]; ec_ws_new_context(&ec_ctx, modulus, b, order, 32, 0); @@ -651,11 +723,51 @@ void test_ec_ws_double_p521(void) EcContext *ec_ctx; EcPoint *ecp; int res; - uint8_t Px[66] = "\x01\xD5\xC6\x93\xF6\x6C\x08\xED\x03\xAD\x0F\x03\x1F\x93\x74\x43\x45\x8F\x60\x1F\xD0\x98\xD3\xD0\x22\x7B\x4B\xF6\x28\x73\xAF\x50\x74\x0B\x0B\xB8\x4A\xA1\x57\xFC\x84\x7B\xCF\x8D\xC1\x6A\x8B\x2B\x8B\xFD\x8E\x2D\x0A\x7D\x39\xAF\x04\xB0\x89\x93\x0E\xF6\xDA\xD5\xC1\xB4"; - uint8_t Py[66] = "\x01\x44\xB7\x77\x09\x63\xC6\x3A\x39\x24\x88\x65\xFF\x36\xB0\x74\x15\x1E\xAC\x33\x54\x9B\x22\x4A\xF5\xC8\x66\x4C\x54\x01\x2B\x81\x8E\xD0\x37\xB2\xB7\xC1\xA6\x3A\xC8\x9E\xBA\xA1\x1E\x07\xDB\x89\xFC\xEE\x5B\x55\x6E\x49\x76\x4E\xE3\xFA\x66\xEA\x7A\xE6\x1A\xC0\x18\x23"; - uint8_t b[66] = "\x00\x51\x95\x3E\xB9\x61\x8E\x1C\x9A\x1F\x92\x9A\x21\xA0\xB6\x85\x40\xEE\xA2\xDA\x72\x5B\x99\xB3\x15\xF3\xB8\xB4\x89\x91\x8E\xF1\x09\xE1\x56\x19\x39\x51\xEC\x7E\x93\x7B\x16\x52\xC0\xBD\x3B\xB1\xBF\x07\x35\x73\xDF\x88\x3D\x2C\x34\xF1\xEF\x45\x1F\xD4\x6B\x50\x3F\x00"; - const uint8_t order[66] = "\x01\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFA\x51\x86\x87\x83\xBF\x2F\x96\x6B\x7F\xCC\x01\x48\xF7\x09\xA5\xD0\x3B\xB5\xC9\xB8\x89\x9C\x47\xAE\xBB\x6F\xB7\x1E\x91\x38\x64\x09"; - uint8_t modulus[66] = "\x01\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"; + const uint8_t Px[66] = {0x01, 0xD5, 0xC6, 0x93, 0xF6, 0x6C, 0x08, 0xED, + 0x03, 0xAD, 0x0F, 0x03, 0x1F, 0x93, 0x74, 0x43, + 0x45, 0x8F, 0x60, 0x1F, 0xD0, 0x98, 0xD3, 0xD0, + 0x22, 0x7B, 0x4B, 0xF6, 0x28, 0x73, 0xAF, 0x50, + 0x74, 0x0B, 0x0B, 0xB8, 0x4A, 0xA1, 0x57, 0xFC, + 0x84, 0x7B, 0xCF, 0x8D, 0xC1, 0x6A, 0x8B, 0x2B, + 0x8B, 0xFD, 0x8E, 0x2D, 0x0A, 0x7D, 0x39, 0xAF, + 0x04, 0xB0, 0x89, 0x93, 0x0E, 0xF6, 0xDA, 0xD5, + 0xC1, 0xB4}; + const uint8_t Py[66] = {0x01, 0x44, 0xB7, 0x77, 0x09, 0x63, 0xC6, 0x3A, + 0x39, 0x24, 0x88, 0x65, 0xFF, 0x36, 0xB0, 0x74, + 0x15, 0x1E, 0xAC, 0x33, 0x54, 0x9B, 0x22, 0x4A, + 0xF5, 0xC8, 0x66, 0x4C, 0x54, 0x01, 0x2B, 0x81, + 0x8E, 0xD0, 0x37, 0xB2, 0xB7, 0xC1, 0xA6, 0x3A, + 0xC8, 0x9E, 0xBA, 0xA1, 0x1E, 0x07, 0xDB, 0x89, + 0xFC, 0xEE, 0x5B, 0x55, 0x6E, 0x49, 0x76, 0x4E, + 0xE3, 0xFA, 0x66, 0xEA, 0x7A, 0xE6, 0x1A, 0xC0, + 0x18, 0x23}; + const uint8_t b[66] = {0x00, 0x51, 0x95, 0x3E, 0xB9, 0x61, 0x8E, 0x1C, + 0x9A, 0x1F, 0x92, 0x9A, 0x21, 0xA0, 0xB6, 0x85, + 0x40, 0xEE, 0xA2, 0xDA, 0x72, 0x5B, 0x99, 0xB3, + 0x15, 0xF3, 0xB8, 0xB4, 0x89, 0x91, 0x8E, 0xF1, + 0x09, 0xE1, 0x56, 0x19, 0x39, 0x51, 0xEC, 0x7E, + 0x93, 0x7B, 0x16, 0x52, 0xC0, 0xBD, 0x3B, 0xB1, + 0xBF, 0x07, 0x35, 0x73, 0xDF, 0x88, 0x3D, 0x2C, + 0x34, 0xF1, 0xEF, 0x45, 0x1F, 0xD4, 0x6B, 0x50, + 0x3F, 0x00}; + const uint8_t order[66] = {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFA, 0x51, 0x86, 0x87, 0x83, 0xBF, 0x2F, + 0x96, 0x6B, 0x7F, 0xCC, 0x01, 0x48, 0xF7, 0x09, + 0xA5, 0xD0, 0x3B, 0xB5, 0xC9, 0xB8, 0x89, 0x9C, + 0x47, 0xAE, 0xBB, 0x6F, 0xB7, 0x1E, 0x91, 0x38, + 0x64, 0x09}; + const uint8_t modulus[66] = {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF}; uint8_t bufx[66], bufy[66]; ec_ws_new_context(&ec_ctx, modulus, b, order, 66, 0); @@ -679,11 +791,26 @@ void test_ec_ws_add(void) EcContext *ec_ctx; EcPoint *ecp, *ecp2; int res; - uint8_t Gx[32] = "\x6b\x17\xd1\xf2\xe1\x2c\x42\x47\xf8\xbc\xe6\xe5\x63\xa4\x40\xf2\x77\x03\x7d\x81\x2d\xeb\x33\xa0\xf4\xa1\x39\x45\xd8\x98\xc2\x96"; - uint8_t Gy[32] = "\x4f\xe3\x42\xe2\xfe\x1a\x7f\x9b\x8e\xe7\xeb\x4a\x7c\x0f\x9e\x16\x2b\xce\x33\x57\x6b\x31\x5e\xce\xcb\xb6\x40\x68\x37\xbf\x51\xf5"; - uint8_t b[32] = "\x5a\xc6\x35\xd8\xaa\x3a\x93\xe7\xb3\xeb\xbd\x55\x76\x98\x86\xbc\x65\x1d\x06\xb0\xcc\x53\xb0\xf6\x3b\xce\x3c\x3e\x27\xd2\x60\x4b"; - const uint8_t order[32] = "\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xbc\xe6\xfa\xad\xa7\x17\x9e\x84\xf3\xb9\xca\xc2\xfc\x63\x25\x51"; - uint8_t modulus[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; + const uint8_t Gx[32] = {0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, + 0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, + 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0, + 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96}; + const uint8_t Gy[32] = {0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, + 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16, + 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, + 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5}; + const uint8_t b[32] = {0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7, + 0xB3, 0xEB, 0xBD, 0x55, 0x76, 0x98, 0x86, 0xBC, + 0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6, + 0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B}; + const uint8_t order[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, + 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51}; + const uint8_t modulus[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint8_t bufx[32], bufy[32]; ec_ws_new_context(&ec_ctx, modulus, b, order, 32, 0); @@ -712,11 +839,26 @@ void test_ec_ws_scalar(void) EcContext *ec_ctx; EcPoint *ecp; int res; - uint8_t Gx[32] = "\x6b\x17\xd1\xf2\xe1\x2c\x42\x47\xf8\xbc\xe6\xe5\x63\xa4\x40\xf2\x77\x03\x7d\x81\x2d\xeb\x33\xa0\xf4\xa1\x39\x45\xd8\x98\xc2\x96"; - uint8_t Gy[32] = "\x4f\xe3\x42\xe2\xfe\x1a\x7f\x9b\x8e\xe7\xeb\x4a\x7c\x0f\x9e\x16\x2b\xce\x33\x57\x6b\x31\x5e\xce\xcb\xb6\x40\x68\x37\xbf\x51\xf5"; - uint8_t b[32] = "\x5a\xc6\x35\xd8\xaa\x3a\x93\xe7\xb3\xeb\xbd\x55\x76\x98\x86\xbc\x65\x1d\x06\xb0\xcc\x53\xb0\xf6\x3b\xce\x3c\x3e\x27\xd2\x60\x4b"; - const uint8_t order[32] = "\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xbc\xe6\xfa\xad\xa7\x17\x9e\x84\xf3\xb9\xca\xc2\xfc\x63\x25\x51"; - uint8_t modulus[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; + const uint8_t Gx[32] = {0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, + 0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, + 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0, + 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96}; + const uint8_t Gy[32] = {0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, + 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16, + 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, + 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5}; + const uint8_t b[32] = {0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7, + 0xB3, 0xEB, 0xBD, 0x55, 0x76, 0x98, 0x86, 0xBC, + 0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6, + 0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B}; + const uint8_t order[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, + 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51}; + const uint8_t modulus[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint8_t bufx[32], bufy[32]; ec_ws_new_context(&ec_ctx, modulus, b, order, 32, 0x5EED); @@ -742,11 +884,26 @@ void test_ec_ws_neg(void) EcContext *ec_ctx; EcPoint *ecp; int res; - uint8_t Gx[32] = "\x6b\x17\xd1\xf2\xe1\x2c\x42\x47\xf8\xbc\xe6\xe5\x63\xa4\x40\xf2\x77\x03\x7d\x81\x2d\xeb\x33\xa0\xf4\xa1\x39\x45\xd8\x98\xc2\x96"; - uint8_t Gy[32] = "\x4f\xe3\x42\xe2\xfe\x1a\x7f\x9b\x8e\xe7\xeb\x4a\x7c\x0f\x9e\x16\x2b\xce\x33\x57\x6b\x31\x5e\xce\xcb\xb6\x40\x68\x37\xbf\x51\xf5"; - uint8_t b[32] = "\x5a\xc6\x35\xd8\xaa\x3a\x93\xe7\xb3\xeb\xbd\x55\x76\x98\x86\xbc\x65\x1d\x06\xb0\xcc\x53\xb0\xf6\x3b\xce\x3c\x3e\x27\xd2\x60\x4b"; - const uint8_t order[32] = "\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xbc\xe6\xfa\xad\xa7\x17\x9e\x84\xf3\xb9\xca\xc2\xfc\x63\x25\x51"; - uint8_t modulus[32] = "\xff\xff\xff\xff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; + const uint8_t Gx[32] = {0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, + 0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2, + 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0, + 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96}; + const uint8_t Gy[32] = {0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, + 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16, + 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, + 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5}; + const uint8_t b[32] = {0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7, + 0xB3, 0xEB, 0xBD, 0x55, 0x76, 0x98, 0x86, 0xBC, + 0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6, + 0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B}; + const uint8_t order[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, + 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51}; + const uint8_t modulus[32] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint8_t bufx[32], bufy[32]; ec_ws_new_context(&ec_ctx, modulus, b, order, 32, 0); diff --git a/src/test/test_ed25519.c b/src/test/test_ed25519.c index 1bb2e2fde..3aa6782d4 100644 --- a/src/test/test_ed25519.c +++ b/src/test/test_ed25519.c @@ -237,15 +237,38 @@ void test_scalar_mult(void) { uint8_t xout[32], yout[32]; - uint8_t G0x[32] = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; - uint8_t G0y[32] = "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; - uint8_t Gx[32] = "\x1a\xd5\x25\x8f\x60\x2d\x56\xc9\xb2\xa7\x25\x95\x60\xc7\x2c\x69\x5c\xdc\xd6\xfd\x31\xe2\xa4\xc0\xfe\x53\x6e\xcd\xd3\x36\x69\x21"; - uint8_t Gy[32] = "\x58\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66"; - uint8_t G2x[32] = "\x0e\xce\x43\x28\x4e\xa1\xc5\x83\x5f\xa4\xd7\x15\x45\x8e\x0d\x08\xac\xe7\x33\x18\x7d\x3b\x04\x3d\x6c\x04\x5a\x9f\x4c\x38\xab\x36"; - uint8_t G2y[32] = "\xc9\xa3\xf8\x6a\xae\x46\x5f\x0e\x56\x51\x38\x64\x51\x0f\x39\x97\x56\x1f\xa2\xc9\xe8\x5e\xa2\x1d\xc2\x29\x23\x09\xf3\xcd\x60\x22"; - uint8_t G5y[32] = "\xED\xC8\x76\xD6\x83\x1F\xD2\x10\x5D\x0B\x43\x89\xCA\x2E\x28\x31\x66\x46\x92\x89\x14\x6E\x2C\xE0\x6F\xAE\xFE\x98\xB2\x25\x48\x5F"; - uint8_t Gry[32] = "\xC9\x72\x8D\x51\x1D\xF5\xB3\x05\x12\xD4\x81\xCC\x41\xDE\x72\x0E\x73\x90\xF1\x53\xFE\xF6\xF0\x59\xDC\xF4\xB8\xAF\xEE\x92\x77\x16"; - + const uint8_t G0x[32] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + const uint8_t G0y[32] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + const uint8_t Gx[32] = {0x1A, 0xD5, 0x25, 0x8F, 0x60, 0x2D, 0x56, 0xC9, + 0xB2, 0xA7, 0x25, 0x95, 0x60, 0xC7, 0x2C, 0x69, + 0x5C, 0xDC, 0xD6, 0xFD, 0x31, 0xE2, 0xA4, 0xC0, + 0xFE, 0x53, 0x6E, 0xCD, 0xD3, 0x36, 0x69, 0x21}; + const uint8_t Gy[32] = {0x58, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, + 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, + 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, + 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66}; + const uint8_t G2x[32] = {0x0E, 0xCE, 0x43, 0x28, 0x4E, 0xA1, 0xC5, 0x83, + 0x5F, 0xA4, 0xD7, 0x15, 0x45, 0x8E, 0x0D, 0x08, + 0xAC, 0xE7, 0x33, 0x18, 0x7D, 0x3B, 0x04, 0x3D, + 0x6C, 0x04, 0x5A, 0x9F, 0x4C, 0x38, 0xAB, 0x36}; + const uint8_t G2y[32] = {0xC9, 0xA3, 0xF8, 0x6A, 0xAE, 0x46, 0x5F, 0x0E, + 0x56, 0x51, 0x38, 0x64, 0x51, 0x0F, 0x39, 0x97, + 0x56, 0x1F, 0xA2, 0xC9, 0xE8, 0x5E, 0xA2, 0x1D, + 0xC2, 0x29, 0x23, 0x09, 0xF3, 0xCD, 0x60, 0x22}; + const uint8_t G5y[32] = {0xED, 0xC8, 0x76, 0xD6, 0x83, 0x1F, 0xD2, 0x10, + 0x5D, 0x0B, 0x43, 0x89, 0xCA, 0x2E, 0x28, 0x31, + 0x66, 0x46, 0x92, 0x89, 0x14, 0x6E, 0x2C, 0xE0, + 0x6F, 0xAE, 0xFE, 0x98, 0xB2, 0x25, 0x48, 0x5F}; + const uint8_t Gry[32] = {0xC9, 0x72, 0x8D, 0x51, 0x1D, 0xF5, 0xB3, 0x05, + 0x12, 0xD4, 0x81, 0xCC, 0x41, 0xDE, 0x72, 0x0E, + 0x73, 0x90, 0xF1, 0x53, 0xFE, 0xF6, 0xF0, 0x59, + 0xDC, 0xF4, 0xB8, 0xAF, 0xEE, 0x92, 0x77, 0x16}; Point Q; int res; @@ -281,7 +304,10 @@ void test_scalar_mult(void) assert(0 == memcmp(G5y, yout, sizeof G5y)); /* random */ - uint8_t r[32] = "\x08\x68\xba\x7a\x34\x73\x4f\x3e\x93\xdd\x24\x26\x32\x7f\x0f\x34\x14\x5c\xd9\x43\x02\xe4\xd5\xdd\x95\x00\xee\x1b\x57\x11\x39\xdd"; + const uint8_t r[32] = {0x08, 0x68, 0xBA, 0x7A, 0x34, 0x73, 0x4F, 0x3E, + 0x93, 0xDD, 0x24, 0x26, 0x32, 0x7F, 0x0F, 0x34, + 0x14, 0x5C, 0xD9, 0x43, 0x02, 0xE4, 0xD5, 0xDD, + 0x95, 0x00, 0xEE, 0x1B, 0x57, 0x11, 0x39, 0xDD}; from_affine(&Q, Gx, Gy); res = ed25519_scalar(&Q, r, 32, 0); diff --git a/src/test/test_ed448.c b/src/test/test_ed448.c index 5bf9d5ac4..5d475fa23 100644 --- a/src/test/test_ed448.c +++ b/src/test/test_ed448.c @@ -2,14 +2,14 @@ #include "mont.h" #include -const uint8_t Gx[56] = "\x4f\x19\x70\xc6\x6b\xed\x0d\xed\x22\x1d\x15\xa6\x22\xbf\x36\xda\x9e\x14\x65\x70\x47\x0f\x17\x67\xea\x6d\xe3\x24\xa3\xd3\xa4\x64\x12\xae\x1a\xf7\x2a\xb6\x65\x11\x43\x3b\x80\xe1\x8b\x00\x93\x8e\x26\x26\xa8\x2b\xc7\x0c\xc0\x5e"; -const uint8_t Gy[56] = "\x69\x3f\x46\x71\x6e\xb6\xbc\x24\x88\x76\x20\x37\x56\xc9\xc7\x62\x4b\xea\x73\x73\x6c\xa3\x98\x40\x87\x78\x9c\x1e\x05\xa0\xc2\xd7\x3a\xd3\xff\x1c\xe6\x7c\x39\xc4\xfd\xbd\x13\x2c\x4e\xd7\xc8\xad\x98\x08\x79\x5b\xf2\x30\xfa\x14"; -const uint8_t PAIx[56] = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; -const uint8_t PAIy[56] = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"; -const uint8_t G2x[56] = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xa9\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"; -const uint8_t G2y[56] = "\xae\x05\xe9\x63\x4a\xd7\x04\x8d\xb3\x59\xd6\x20\x50\x86\xc2\xb0\x03\x6e\xd7\xa0\x35\x88\x4d\xd7\xb7\xe3\x6d\x72\x8a\xd8\xc4\xb8\x0d\x65\x65\x83\x3a\x2a\x30\x98\xbb\xbc\xb2\xbe\xd1\xcd\xa0\x6b\xda\xea\xfb\xcd\xea\x93\x86\xed"; -const uint8_t G3x[56] = "\x08\x65\x88\x6b\x91\x08\xaf\x64\x55\xbd\x64\x31\x6c\xb6\x94\x33\x32\x24\x1b\x8b\x8c\xda\x82\xc7\xe2\xba\x07\x7a\x4a\x3f\xcf\xe8\xda\xa9\xcb\xf7\xf6\x27\x1f\xd6\xe8\x62\xb7\x69\x46\x5d\xa8\x57\x57\x28\x17\x32\x86\xff\x2f\x8f"; -const uint8_t G3y[56] = "\xe0\x05\xa8\xdb\xd5\x12\x5c\xf7\x06\xcb\xda\x7a\xd4\x3a\xa6\x44\x9a\x4a\x8d\x95\x23\x56\xc3\xb9\xfc\xe4\x3c\x82\xec\x4e\x1d\x58\xbb\x3a\x33\x1b\xdb\x67\x67\xf0\xbf\xfa\x9a\x68\xfe\xd0\x2d\xaf\xb8\x22\xac\x13\x58\x8e\xd6\xfc"; +const uint8_t Gx[56] = {0x4F, 0x19, 0x70, 0xC6, 0x6B, 0xED, 0x0D, 0xED, 0x22, 0x1D, 0x15, 0xA6, 0x22, 0xBF, 0x36, 0xDA, 0x9E, 0x14, 0x65, 0x70, 0x47, 0x0F, 0x17, 0x67, 0xEA, 0x6D, 0xE3, 0x24, 0xA3, 0xD3, 0xA4, 0x64, 0x12, 0xAE, 0x1A, 0xF7, 0x2A, 0xB6, 0x65, 0x11, 0x43, 0x3B, 0x80, 0xE1, 0x8B, 0x00, 0x93, 0x8E, 0x26, 0x26, 0xA8, 0x2B, 0xC7, 0x0C, 0xC0, 0x5E}; +const uint8_t Gy[56] = {0x69, 0x3F, 0x46, 0x71, 0x6E, 0xB6, 0xBC, 0x24, 0x88, 0x76, 0x20, 0x37, 0x56, 0xC9, 0xC7, 0x62, 0x4B, 0xEA, 0x73, 0x73, 0x6C, 0xA3, 0x98, 0x40, 0x87, 0x78, 0x9C, 0x1E, 0x05, 0xA0, 0xC2, 0xD7, 0x3A, 0xD3, 0xFF, 0x1C, 0xE6, 0x7C, 0x39, 0xC4, 0xFD, 0xBD, 0x13, 0x2C, 0x4E, 0xD7, 0xC8, 0xAD, 0x98, 0x08, 0x79, 0x5B, 0xF2, 0x30, 0xFA, 0x14}; +const uint8_t PAIx[56] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +const uint8_t PAIy[56] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; +const uint8_t G2x[56] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xA9, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55}; +const uint8_t G2y[56] = {0xAE, 0x05, 0xE9, 0x63, 0x4A, 0xD7, 0x04, 0x8D, 0xB3, 0x59, 0xD6, 0x20, 0x50, 0x86, 0xC2, 0xB0, 0x03, 0x6E, 0xD7, 0xA0, 0x35, 0x88, 0x4D, 0xD7, 0xB7, 0xE3, 0x6D, 0x72, 0x8A, 0xD8, 0xC4, 0xB8, 0x0D, 0x65, 0x65, 0x83, 0x3A, 0x2A, 0x30, 0x98, 0xBB, 0xBC, 0xB2, 0xBE, 0xD1, 0xCD, 0xA0, 0x6B, 0xDA, 0xEA, 0xFB, 0xCD, 0xEA, 0x93, 0x86, 0xED}; +const uint8_t G3x[56] = {0x08, 0x65, 0x88, 0x6B, 0x91, 0x08, 0xAF, 0x64, 0x55, 0xBD, 0x64, 0x31, 0x6C, 0xB6, 0x94, 0x33, 0x32, 0x24, 0x1B, 0x8B, 0x8C, 0xDA, 0x82, 0xC7, 0xE2, 0xBA, 0x07, 0x7A, 0x4A, 0x3F, 0xCF, 0xE8, 0xDA, 0xA9, 0xCB, 0xF7, 0xF6, 0x27, 0x1F, 0xD6, 0xE8, 0x62, 0xB7, 0x69, 0x46, 0x5D, 0xA8, 0x57, 0x57, 0x28, 0x17, 0x32, 0x86, 0xFF, 0x2F, 0x8F}; +const uint8_t G3y[56] = {0xE0, 0x05, 0xA8, 0xDB, 0xD5, 0x12, 0x5C, 0xF7, 0x06, 0xCB, 0xDA, 0x7A, 0xD4, 0x3A, 0xA6, 0x44, 0x9A, 0x4A, 0x8D, 0x95, 0x23, 0x56, 0xC3, 0xB9, 0xFC, 0xE4, 0x3C, 0x82, 0xEC, 0x4E, 0x1D, 0x58, 0xBB, 0x3A, 0x33, 0x1B, 0xDB, 0x67, 0x67, 0xF0, 0xBF, 0xFA, 0x9A, 0x68, 0xFE, 0xD0, 0x2D, 0xAF, 0xB8, 0x22, 0xAC, 0x13, 0x58, 0x8E, 0xD6, 0xFC}; /** Double the generator **/ void test_point_double_1(void) @@ -46,7 +46,7 @@ void test_point_double_1(void) } /** Double the PAI **/ -void test_point_double_2() +void test_point_double_2(void) { uint8_t outx[56], outy[56]; int res; diff --git a/src/test/test_mont.c b/src/test/test_mont.c index 1cd110ef0..a83373ab9 100644 --- a/src/test/test_mont.c +++ b/src/test/test_mont.c @@ -163,7 +163,7 @@ void test_mont_add(void) uint64_t *tmp; uint8_t modulus[16] = { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; // 0x01000001000000000000000000000001 uint8_t modulus2[16]; - uint64_t a[2] = { -1, -1 }; + uint64_t a[2] = { UINT64_MAX, UINT64_MAX }; uint64_t b[2] = { 1, 0 }; uint64_t out[2]; @@ -281,7 +281,15 @@ void test_mont_inv_prime(void) uint64_t *p; uint8_t buf[16]; - uint8_t modulus_p521[66] = "\x01\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"; + const uint8_t modulus_p521[66] = {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF}; uint64_t out_p521[9]; uint8_t buf_p521[66]; @@ -371,7 +379,7 @@ void test_mont_set(void) mont_context_free(ctx); } -void test_mod_select() +void test_mod_select(void) { int res; MontContext *ctx; diff --git a/src/test/test_pkcs1.c b/src/test/test_pkcs1.c index 6ef63cb9c..82cfc3888 100644 --- a/src/test/test_pkcs1.c +++ b/src/test/test_pkcs1.c @@ -1,4 +1,4 @@ -#include "../common.h" +#include "common.h" size_t propagate_ones(uint8_t x); void set_if_match(uint8_t *flag, size_t term1, size_t term2); @@ -17,7 +17,7 @@ const uint8_t oneone[] = "11"; const uint8_t zeroone[] = "01"; const uint8_t zerozero[] = "00"; -void test_propagate_ones() +void test_propagate_ones(void) { unsigned i; @@ -29,7 +29,7 @@ void test_propagate_ones() } } -void test_set_if_match() +void test_set_if_match(void) { uint8_t x; @@ -42,7 +42,7 @@ void test_set_if_match() assert(x == 1); } -void test_set_if_no_match() +void test_set_if_no_match(void) { uint8_t x; @@ -55,7 +55,7 @@ void test_set_if_no_match() assert(x == 1); } -void test_safe_select() +void test_safe_select(void) { uint8_t out[10]; @@ -72,7 +72,7 @@ void test_safe_select() assert(memcmp(zerozero, out, 1) == 0); } -void test_safe_select_idx() +void test_safe_select_idx(void) { assert(safe_select_idx(0, 1, 0) == 0); assert(safe_select_idx(0, 1, 1) == 1); @@ -80,7 +80,7 @@ void test_safe_select_idx() assert(safe_select_idx(0x100004, 0x223344, 1) == 0x223344); } -void test_safe_cmp() +void test_safe_cmp(void) { uint8_t res; @@ -137,7 +137,7 @@ void test_safe_cmp() assert(res == 0); } -void test_safe_search() +void test_safe_search(void) { size_t res; diff --git a/src/test/test_x25519.c b/src/test/test_x25519.c index 7ffe46b65..57ad729bd 100644 --- a/src/test/test_x25519.c +++ b/src/test/test_x25519.c @@ -5,9 +5,18 @@ void ladder(uint8_t shared_secret[32], const uint8_t *k, size_t len, const uint8 void test_ladder(void) { - uint8_t scalar[32] = "\xa5\x46\xe3\x6b\xf0\x52\x7c\x9d\x3b\x16\x15\x4b\x82\x46\x5e\xdd\x62\x14\x4c\x0a\xc1\xfc\x5a\x18\x50\x6a\x22\x44\xba\x44\x9a\xc4"; - uint8_t pubkey[32] = "\xe6\xdb\x68\x67\x58\x30\x30\xdb\x35\x94\xc1\xa4\x24\xb1\x5f\x7c\x72\x66\x24\xec\x26\xb3\x35\x3b\x10\xa9\x03\xa6\xd0\xab\x1c\x4c"; - uint8_t expout[32] = "\xc3\xda\x55\x37\x9d\xe9\xc6\x90\x8e\x94\xea\x4d\xf2\x8d\x08\x4f\x32\xec\xcf\x03\x49\x1c\x71\xf7\x54\xb4\x07\x55\x77\xa2\x85\x52"; + uint8_t scalar[32] = {0xA5, 0x46, 0xE3, 0x6B, 0xF0, 0x52, 0x7C, 0x9D, + 0x3B, 0x16, 0x15, 0x4B, 0x82, 0x46, 0x5E, 0xDD, + 0x62, 0x14, 0x4C, 0x0A, 0xC1, 0xFC, 0x5A, 0x18, + 0x50, 0x6A, 0x22, 0x44, 0xBA, 0x44, 0x9A, 0xC4}; + uint8_t pubkey[32] = {0xE6, 0xDB, 0x68, 0x67, 0x58, 0x30, 0x30, 0xDB, + 0x35, 0x94, 0xC1, 0xA4, 0x24, 0xB1, 0x5F, 0x7C, + 0x72, 0x66, 0x24, 0xEC, 0x26, 0xB3, 0x35, 0x3B, + 0x10, 0xA9, 0x03, 0xA6, 0xD0, 0xAB, 0x1C, 0x4C}; + uint8_t expout[32] = {0xC3, 0xDA, 0x55, 0x37, 0x9D, 0xE9, 0xC6, 0x90, + 0x8E, 0x94, 0xEA, 0x4D, 0xF2, 0x8D, 0x08, 0x4F, + 0x32, 0xEC, 0xCF, 0x03, 0x49, 0x1C, 0x71, 0xF7, + 0x54, 0xB4, 0x07, 0x55, 0x77, 0xA2, 0x85, 0x52}; uint8_t out[32]; scalar[0] &= 248;