From 285b6f2d2e6c4552fbcd529c910da1822e07dd6d Mon Sep 17 00:00:00 2001 From: Jazz Turner-Baggs <473256+jazzz@users.noreply.github.com> Date: Wed, 8 Oct 2025 17:52:43 -0700 Subject: [PATCH] Add tests + requirements --- .gitmodules | 10 +++ src/naxolotl.nim | 3 +- tests/config.nims | 1 + tests/test_naxolotl.nim | 158 +++++++++++++++++++++++++++++++++++ vendor/constantine | 1 + vendor/nim_chacha20_poly1305 | 1 + 6 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 tests/test_naxolotl.nim create mode 160000 vendor/constantine create mode 160000 vendor/nim_chacha20_poly1305 diff --git a/.gitmodules b/.gitmodules index 1b05c61..44e4b4a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -31,3 +31,13 @@ url = https://github.com/johnnovak/illwill.git ignore = untracked branch = master +[submodule "vendor/nim_chacha20_poly1305"] + path = vendor/nim_chacha20_poly1305 + url = https://github.com/lantos-lgtm/nim_chacha20_poly1305.git + ignore = untracked + branch = master +[submodule "vendor/constantine"] + path = vendor/constantine + url = https://github.com/mratsim/constantine.git + ignore = untracked + branch = master diff --git a/src/naxolotl.nim b/src/naxolotl.nim index 7880e6e..f6410de 100644 --- a/src/naxolotl.nim +++ b/src/naxolotl.nim @@ -1,6 +1,7 @@ import naxolotl/[ naxolotl, - curve25519 + curve25519, + types ] export naxolotl, curve25519 \ No newline at end of file diff --git a/tests/config.nims b/tests/config.nims index e69de29..0a0c126 100644 --- a/tests/config.nims +++ b/tests/config.nims @@ -0,0 +1 @@ +switch("path", "$projectDir/src") \ No newline at end of file diff --git a/tests/test_naxolotl.nim b/tests/test_naxolotl.nim new file mode 100644 index 0000000..26ef5e2 --- /dev/null +++ b/tests/test_naxolotl.nim @@ -0,0 +1,158 @@ + +import unittest +import naxolotl +import results +import random +import sequtils + +import strutils + +import naxolotl/utils + + +# Key share test from RFC-7748: +const ks7748_a_priv = "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a" +const ks7748_a_pub = "8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a" # Public key point (x co-ord) + +const ks7748_b_priv = "5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb" +const ks7748_b_pub = "de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f" # Public key point (x co-ord)s + +const ks7748_shared_key = "4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742" + +# import parseutils + +proc hexToArray*[N: static[int]](hexStr: string): array[N, byte] = + ## Converts hex string to fixed-size byte array + if hexStr.len != N * 2: + raise newException(ValueError, + "Hex string length (" & $hexStr.len & ") doesn't match array size (" & $( + N*2) & ")") + + var result: array[N, byte] + for i in 0..