-
Notifications
You must be signed in to change notification settings - Fork 2.1k
tests/pkg/micro-ecc: add unit tests #21921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This hacks in some unit tests that will narrow down what part of uECC failed, if the test fails.
Why would we not want this? |
|
It contains a nasty hack to access an internal function for unit testing. There are btw also tests upstream: https://github.com/kmackay/micro-ecc/blob/master/test/test_compress.c They won't catch any issues in our integration, though. We could try to PR changes to the upstream tests that would allow embedding them into an external application - such as a RIOT app - and then do that instead. |
|
I mean IMO that looks fine to me. Clearly they left the access there for such cases, given that they also use it but I get your point |
|
One benefit of this is that a catastrophic bug that would cause an all zero shared key to be generated would be caught, but not by the "do both parties arrive at the same shared key" test that follows. |
AnnsAnns
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favour of adding this, I see nothing wrong with having a backup test for this. But I'm open to other opinions.
Also, a few long lines in there ;)
| }; | ||
| uint8_t alignas(uECC_word_t) result_got[sizeof(result_expected)]; | ||
| uECC_vli_modMult_fast((void *)result_got, (void *)input1, (void *)input2, curve); | ||
| return _test_compare("uECC_vli_modMult_fast()", result_got, result_expected, sizeof(result_expected)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long line
| }; | ||
| uint8_t alignas(uECC_word_t) result_got[sizeof(result_expected)]; | ||
| uECC_vli_modSquare_fast((void *)result_got, (void *)input, curve); | ||
| return _test_compare("uECC_vli_modSquare_fast()", result_got, result_expected, sizeof(result_expected)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long line
| uECC_vli_mult((void *)result_got, (void *)input1, (void *)input2, sizeof(input1) / sizeof(uECC_word_t)); | ||
| return _test_compare("uECC_vli_mult()", result_got, result_expected, sizeof(result_expected)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long lines
| uECC_word_t carry_got = uECC_vli_add((void *)result_got, (void *)input1, (void *)input2, sizeof(input1)/sizeof(uECC_word_t)); | ||
| return _test_compare("uECC_vli_add()", result_got, result_expected, sizeof(result_expected)) | ||
| && _test_compare("uECC_vli_add() carry", &carry_got, &carry_expected, sizeof(carry_expected)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long lines
| }; | ||
| const uECC_word_t borrow_expected = 1; | ||
| uint8_t alignas(uECC_word_t) result_got[sizeof(result_expected)]; | ||
| uECC_word_t borrow_got = uECC_vli_sub((void *)result_got, (void *)input1, (void *)input2, sizeof(input1)/sizeof(uECC_word_t)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long line
| uECC_vli_mmod((void *)result_got, (void *)product, (void *)mod, sizeof(mmod_result_expected) / sizeof(uECC_word_t)); | ||
| return _test_compare("uECC_vli_mmod()", result_got, mmod_result_expected, sizeof(mmod_result_expected)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long lines
| alignas(uECC_word_t) uint8_t product[sizeof(mmod_input)]; | ||
| memcpy(product, mmod_input, sizeof(product)); | ||
| curve->mmod_fast((void *)result_got, (void *)product); | ||
| return _test_compare("curve->mmod_fast()", result_got, mmod_result_expected, sizeof(mmod_result_expected)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long line
Contribution description
This hacks in some unit tests that will narrow down what part of uECC failed, if the test fails.
Not sure if we actually want this. It has been useful to narrow down what was causing the AVR test to fail, though.
Testing procedure
The test should still pass, but provide a bit more output.
Issues/PRs references
This was helpful for #21920