diff options
| author | J08nY | 2023-10-01 22:22:38 +0200 |
|---|---|---|
| committer | J08nY | 2023-10-01 22:22:38 +0200 |
| commit | 5e83141740737d832bb19c79ff9ea371977fdbe0 (patch) | |
| tree | a8667f3234ee06f96c4fcf3775e9ecd46d4adad4 /test | |
| parent | 549b6282fe9d4d06fc69d5d0b9103338d8d99363 (diff) | |
| download | pyecsca-codegen-5e83141740737d832bb19c79ff9ea371977fdbe0.tar.gz pyecsca-codegen-5e83141740737d832bb19c79ff9ea371977fdbe0.tar.zst pyecsca-codegen-5e83141740737d832bb19c79ff9ea371977fdbe0.zip | |
Add sliding window recoding functions.
Diffstat (limited to 'test')
| -rw-r--r-- | test/Makefile | 3 | ||||
| -rw-r--r-- | test/test_bn.c | 56 |
2 files changed, 59 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..4b8fc78 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,3 @@ + +test_bn: test_bn.c ../pyecsca/codegen/bn/bn.c + gcc -o $@ $^ -I ../pyecsca/codegen/ -I ../pyecsca/codegen/tommath/ -L ../pyecsca/codegen/tommath/ -l:libtommath-HOST.a
\ No newline at end of file diff --git a/test/test_bn.c b/test/test_bn.c new file mode 100644 index 0000000..a77fe9a --- /dev/null +++ b/test/test_bn.c @@ -0,0 +1,56 @@ +#include <stdio.h> +#include "bn/bn.h" + +int test_wsliding_ltr() { + printf("test_wsliding_ltr: "); + bn_t bn; + bn_init(&bn); + bn_from_int(181, &bn); + wsliding_t *ws = bn_wsliding_ltr(&bn, 3); + if (ws == NULL) { + printf("NULL\n"); + return 1; + } + if (ws->length != 6) { + printf("Bad length (%li instead of 6)\n", ws->length); + return 1; + } + uint8_t expected[6] = {5, 0, 0, 5, 0, 1}; + for (int i = 0; i < 6; i++) { + if (ws->data[i] != expected[i]) { + printf("Bad data (%i instead of %i)\n", ws->data[i], expected[i]); + return 1; + } + } + printf("OK\n"); + return 0; +} + +int test_wsliding_rtl() { + printf("test_wsliding_rtl: "); + bn_t bn; + bn_init(&bn); + bn_from_int(181, &bn); + wsliding_t *ws = bn_wsliding_rtl(&bn, 3); + if (ws == NULL) { + printf("NULL\n"); + return 1; + } + if (ws->length != 8) { + printf("Bad length (%li instead of 8)\n", ws->length); + return 1; + } + uint8_t expected[8] = {1, 0, 0, 3, 0, 0, 0, 5}; + for (int i = 0; i < 8; i++) { + if (ws->data[i] != expected[i]) { + printf("Bad data (%i instead of %i)\n", ws->data[i], expected[i]); + return 1; + } + } + printf("OK\n"); + return 0; +} + +int main(void) { + return test_wsliding_ltr() + test_wsliding_rtl(); +}
\ No newline at end of file |
