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.
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)); |
| }; | ||
| 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)); |
| 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)); |
| 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)); |
| }; | ||
| 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)); |
| 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)); |
| 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)); |
|
@maribu ping 👀 |
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