Skip to content

tests/sys_crypto: remove use of BOARD_BLACKLIST variable#12645

Merged
aabadie merged 4 commits intoRIOT-OS:masterfrom
aabadie:pr/tests/sys_crypto_remove_board_blacklist
Nov 23, 2019
Merged

tests/sys_crypto: remove use of BOARD_BLACKLIST variable#12645
aabadie merged 4 commits intoRIOT-OS:masterfrom
aabadie:pr/tests/sys_crypto_remove_board_blacklist

Conversation

@aabadie
Copy link
Contributor

@aabadie aabadie commented Nov 5, 2019

Contribution description

This PR tries to get rid of the BOARD_BLACKLIST variable in tests/sys_crypto application. The approach is to try to fix the integer length issues raised when building on 8/16 bit architectures instead of just blacklisting the corresponding features.

While doing, I think I found a potential bug in one of the decrypt function, see 4d214cc. On 8/16 bit architectures, the compiler was failing with "error: comparison is always false due to limited range of data type". Which makes sense when looking at the code.

After all these integer length issues were fixed, it was just a matter of moving some boards to the insufficient memory variable.

The test application now builds fine on some msp430 and AVR based boards.

I haven't tested the test script on MSP430/AVR8 boards because I don't have the hardware with me.

Testing procedure

The following commands should build and work fine (if test is supported):

$ make BOARD=z1 -C test/sys_crypto flash test
$ make BOARD=mega-xplained -C test/sys_crypto flash test
$ make BOARD=microduino-corerf -C test/sys_crypto flash test

Issues/PRs references

None

@aabadie aabadie added Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: crypto Area: Cryptographic libraries labels Nov 5, 2019
@aabadie
Copy link
Contributor Author

aabadie commented Nov 5, 2019

I could test on an 8bit board (from #12639) and one of the tests is broken.

@aabadie aabadie force-pushed the pr/tests/sys_crypto_remove_board_blacklist branch from a5a0240 to 5952a5a Compare November 5, 2019 13:58
@aabadie
Copy link
Contributor Author

aabadie commented Nov 5, 2019

With the latest version of this PR, tests/sys_crypto works on AVR. Needs careful review though because it's crypto code and because it contains a small API change (I haven't found anything better).

@bergzand
Copy link
Member

bergzand commented Nov 5, 2019

What's the exact error on the AVR platform when using a size_t for the input length?

@aabadie
Copy link
Contributor Author

aabadie commented Nov 5, 2019

What's the exact error on the AVR platform when using a size_t for the input length?

The problem is raising when testing upper bounds of the input_len parameter. If it's above 65535, an error is returned. The problem on 8/16bit architecture is that size_t is not a 32 bit integer, so the parameter value is 0 in this case, resulting in a valid value returned.
That's why using an input_len type with explicit length fixes the issue.

@aabadie
Copy link
Contributor Author

aabadie commented Nov 5, 2019

Here is the issue on AVR:

.........................
crypto_modes_ccm_tests.test_crypto_modes_ccm_check_len (tests/sys_crypto/tests-crypto-modes-ccm.c 1015) exp -4 was 8
.........
run 34 failures 1

The comes from the following function

static inline int _fits_in_nbytes(size_t value, uint8_t num_bytes)
that is not returning 0 when it should e.g. when passing it a value of 65536 (UINT16_MAX + 1): on non 32bit architecture this value is converted to 0 because of the use of size_t.

Do you have suggestions for a better fix ?

@bergzand
Copy link
Member

bergzand commented Nov 5, 2019

I strongly prefer to keep the length field here size_t. My main reason here is that size_t is meant to be used for sizes of arrays etc…, the result of a sizeof() call is of type size_t, exactly for what it is used here.

Do you have suggestions for a better fix ?

I'm wondering if the failing tests are valid for the platforms where size_t is 16 bit.

Rationale:

CCM mode contains a variable length field (length_encoding) containing the length in octets of the message. This variable length field is between 2 - 8 octets in size. The implementation checks if the supplied message length fits within the length_encoding octets. For the Cortex-M platforms, size_t is 32 bit wide, it could be enough to have length_encoding == 2, but it might require more octets for an arbitrary message. The failing test here validates whether the crypto algo correctly rejects the encrypt/decrypt call when the message size and the length_encoding argument are incompatible.

On the AVR platform (and probably also on the 16 bit platforms) size_t is 16 bit. The minimum length for length_encoding of 2 octets is thus always able to contain the maximum message size. The encrypt/decrypt call can not fail based on the length_encoding being too small for the message size.

What I would do is wrap the tests in:

/* Tests only required when the length_encoding could require more than 2 octets */
`#if SIZE_MAX > UINT16_MAX` 

And maybe add an test to verify that the call returns an error when length_encoding is smaller than 2.

@aabadie
Copy link
Contributor Author

aabadie commented Nov 6, 2019

What I would do is wrap the tests in:

/* Tests only required when the length_encoding could require more than 2 octets */
#if SIZE_MAX > UINT16_MAX

And maybe add an test to verify that the call returns an error when length_encoding is smaller than 2.

Sounds good, I'll update the PR accordingly.

@aabadie aabadie force-pushed the pr/tests/sys_crypto_remove_board_blacklist branch 2 times, most recently from 59e6a2e to 198863f Compare November 6, 2019 10:58
@aabadie
Copy link
Contributor Author

aabadie commented Nov 6, 2019

@bergzand, changed the PR following your suggestion. Directly rebased and squashed. Also tested on atmega256rfr2-xpro and now it works.

Copy link
Member

@bergzand bergzand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK¸ I haven't tested it personally, but I'm willing to trust your tests for this. Changes look good.

@aabadie
Copy link
Contributor Author

aabadie commented Nov 11, 2019

@bergzand, may I squash this one ?

@maribu
Copy link
Member

maribu commented Nov 20, 2019

On the ATmega1284P I get:

main(): This is RIOT! (Version: 2020.01-devel-768-g7aace-alex)
..................................
OK (34 tests)

@maribu maribu added the Reviewed: 3-testing The PR was tested according to the maintainer guidelines label Nov 20, 2019
@maribu
Copy link
Member

maribu commented Nov 20, 2019

@bergzand: I think this is ready to go in 😉

@aabadie aabadie force-pushed the pr/tests/sys_crypto_remove_board_blacklist branch from 7aace2c to 8baac95 Compare November 22, 2019 10:37
@aabadie
Copy link
Contributor Author

aabadie commented Nov 22, 2019

@bergzand, OK to squash ?

@bergzand
Copy link
Member

@bergzand, OK to squash ?

Yes, please squash

The tests doesn't work when length_encoding is above the maximum uint16
value.

Also add a set that checks the right error code is returned with too
small length_encoding.
@aabadie aabadie force-pushed the pr/tests/sys_crypto_remove_board_blacklist branch from 8baac95 to 607aa6f Compare November 22, 2019 18:21
@aabadie
Copy link
Contributor Author

aabadie commented Nov 22, 2019

Done!

Copy link
Member

@bergzand bergzand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, changes look good.

@aabadie aabadie merged commit 1f55cff into RIOT-OS:master Nov 23, 2019
@aabadie aabadie deleted the pr/tests/sys_crypto_remove_board_blacklist branch November 23, 2019 05:48
@aabadie
Copy link
Contributor Author

aabadie commented Nov 23, 2019

Thanks for reviewing and testing @bergzand @maribu!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: crypto Area: Cryptographic libraries Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 3-testing The PR was tested according to the maintainer guidelines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants