Skip to content
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
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ build-waku-nat:
@echo "Start building waku nat-libs"
$(MAKE) -C vendor/nwaku nat-libs
@echo "Completed building nat-libs"

.PHONY: tests
tests: | build-waku-librln build-waku-nat nim_chat_poc.nims
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim tests $(NIM_PARAMS) nim_chat_poc.nims


##########
## Example ##
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ make update
# Build executables
make all

# Run tests
make tests

# Run the Text Interface
./build/tui --name=<unique_id>
```
Expand Down
7 changes: 7 additions & 0 deletions nim_chat_poc.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =

exec "nim " & lang & " --out:build/" & name & " --mm:refc " & extra_params & " " &
srcDir & name & ".nim"

proc test(name: string, params = "-d:chronicles_log_level=DEBUG", lang = "c") =
buildBinary name, "tests/", params
exec "build/" & name

task tests, "Build & run tests":
test "all_tests", "-d:chronicles_log_level=ERROR -d:chronosStrictException"

task waku_example, "Build Waku based simple example":
let name = "waku_example"
Expand Down
2 changes: 1 addition & 1 deletion src/naxolotl/naxolotl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ proc skipMessageKeys(self: var Doubleratchet, until: MsgCount): Result[(), strin
proc encrypt(self: var Doubleratchet, plaintext: var seq[byte], associatedData: openArray[byte]): (DrHeader, CipherText) =

let (msgKey, chainKey) = self.kdfChain(self.chainKeySend)

self.chainKeySend = chainKey
let header = DrHeader(
dhPublic: self.dhSelf.public, #TODO Serialize
msgNumber: self.msgCountSend,
Expand Down
4 changes: 4 additions & 0 deletions tests/all_tests.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# import individual test suites

import ./test_curve25519
import ./test_naxolotl
17 changes: 8 additions & 9 deletions tests/test_curve25519.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# test_example.nim
import unittest
import ../src/crypto/ecdh # TODO use config.nims
import results
import ../src/utils
import unittest

import ../src/chat_sdk/crypto/ecdh # TODO use config.nims
import ../src/chat_sdk/utils

# Key share test from RFC-7748:
const ks7748_a_priv = "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a"
Expand All @@ -26,29 +26,28 @@ proc hexToArray*[N: static[int]](hexStr: string): array[N, byte] =
if parseHex(hexStr[i*2..i*2+1], result[i]) == 0:
raise newException(ValueError, "Invalid hex pair: " & hexStr[i*2..i*2+1])

# Usage

suite "X25519":
test "Key Loading":

let a_priv = loadKeyFromBytes(hexToArray[32](ks7748_a_priv)).get()
let a_priv = loadPrivateKeyFromBytes(hexToArray[32](ks7748_a_priv)).get()
let a_pub = a_priv.getPublicKey()

check bytesToHex(a_pub.bytes, lowercase = true) == ks7748_a_pub
check bytesToHex(a_pub.bytes, lowercase = true) != ks7748_b_pub

let b_priv = loadKeyFromBytes(hexToArray[32](ks7748_b_priv)).get()
let b_priv = loadPrivateKeyFromBytes(hexToArray[32](ks7748_b_priv)).get()
let b_pub = b_priv.getPublicKey()

check bytesToHex(b_pub.bytes, lowercase = true) != ks7748_a_pub
check bytesToHex(b_pub.bytes, lowercase = true) == ks7748_b_pub

test "ECDH":

let a_priv = loadKeyFromBytes(hexToArray[32](ks7748_a_priv)).get()
let a_priv = loadPrivateKeyFromBytes(hexToArray[32](ks7748_a_priv)).get()
let a_pub = a_priv.getPublicKey()

let b_priv = loadKeyFromBytes(hexToArray[32](ks7748_b_priv)).get()
let b_priv = loadPrivateKeyFromBytes(hexToArray[32](ks7748_b_priv)).get()
let b_pub = b_priv.getPublicKey()


Expand Down
5 changes: 3 additions & 2 deletions tests/test_naxolotl.nim
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

import unittest
import naxolotl
import results
import random
import sequtils

import strutils

import naxolotl/utils
import ../src/naxolotl
import ../src/naxolotl/utils



# Key share test from RFC-7748:
Expand Down