tests/pkg_libcose: adapt to c25519 and monocypher

This commit is contained in:
Francisco Molina 2019-08-12 14:30:53 +02:00
parent ae1c4f422c
commit 9e5416239b
2 changed files with 22 additions and 4 deletions

View File

@ -14,11 +14,20 @@ BOARD_INSUFFICIENT_MEMORY := i-nucleo-lrwan1 \
TEST_ON_CI_WHITELIST += native TEST_ON_CI_WHITELIST += native
CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(4*THREAD_STACKSIZE_DEFAULT\)
USEPKG += libcose USEPKG += libcose
# By default we use hacl as crypto backend, uncomment to use a different
# crypto backend.
USEMODULE += libcose_crypt_hacl USEMODULE += libcose_crypt_hacl
# USEMODULE += libcose_crypt_c25519
# USEMODULE += libcose_crypt_monocypher
USEMODULE += memarray USEMODULE += memarray
USEMODULE += embunit USEMODULE += embunit
ifneq (,$(filter libcose_crypt_monocypher,$(USEMODULE)))
CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(6*THREAD_STACKSIZE_DEFAULT\)
else
CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(4*THREAD_STACKSIZE_DEFAULT\)
endif
include $(RIOTBASE)/Makefile.include include $(RIOTBASE)/Makefile.include

View File

@ -40,16 +40,21 @@ static unsigned char pk[COSE_CRYPTO_SIGN_ED25519_PUBLICKEYBYTES];
static unsigned char sk[COSE_CRYPTO_SIGN_ED25519_SECRETKEYBYTES]; static unsigned char sk[COSE_CRYPTO_SIGN_ED25519_SECRETKEYBYTES];
static unsigned char pk2[COSE_CRYPTO_SIGN_ED25519_PUBLICKEYBYTES]; static unsigned char pk2[COSE_CRYPTO_SIGN_ED25519_PUBLICKEYBYTES];
static unsigned char sk2[COSE_CRYPTO_SIGN_ED25519_SECRETKEYBYTES]; static unsigned char sk2[COSE_CRYPTO_SIGN_ED25519_SECRETKEYBYTES];
static unsigned char symmkey[COSE_CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES];
static uint8_t nonce[COSE_CRYPTO_AEAD_CHACHA20POLY1305_NONCEBYTES] = { 0 };
/* COSE structs */ /* COSE structs */
static cose_sign_enc_t sign; static cose_sign_enc_t sign;
static cose_sign_dec_t verify; static cose_sign_dec_t verify;
static cose_signature_t signature1, signature2; static cose_signature_t signature1, signature2;
static cose_key_t signer1, signer2, symm; static cose_key_t signer1, signer2;
#if defined(MODULE_LIBCOSE_CRYPT_HACL) || defined(MODULE_LIBCOSE_CRYPT_MONOCYPHER)
static unsigned char symmkey[COSE_CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES];
static uint8_t nonce[COSE_CRYPTO_AEAD_CHACHA20POLY1305_NONCEBYTES] = { 0 };
static cose_key_t symm;
static cose_encrypt_t test_encrypt; static cose_encrypt_t test_encrypt;
static cose_encrypt_dec_t test_decrypt; static cose_encrypt_dec_t test_decrypt;
static cose_recp_dec_t test_derecp; static cose_recp_dec_t test_derecp;
#endif
/* COSE sign buffer */ /* COSE sign buffer */
static uint8_t buf[2048]; static uint8_t buf[2048];
/* Signature Verification buffer */ /* Signature Verification buffer */
@ -179,6 +184,7 @@ static void test_libcose_02(void)
sizeof(vbuf))); sizeof(vbuf)));
} }
#if defined(MODULE_LIBCOSE_CRYPT_HACL) || defined(MODULE_LIBCOSE_CRYPT_MONOCYPHER)
/* Untagged 1 encrypt test with chacha20poly1305*/ /* Untagged 1 encrypt test with chacha20poly1305*/
static void test_libcose_03(void) static void test_libcose_03(void)
{ {
@ -207,13 +213,16 @@ static void test_libcose_03(void)
vbuf, &plaintext_len)); vbuf, &plaintext_len));
TEST_ASSERT_EQUAL_INT( sizeof(payload) - 1, plaintext_len); TEST_ASSERT_EQUAL_INT( sizeof(payload) - 1, plaintext_len);
} }
#endif
Test *tests_libcose(void) Test *tests_libcose(void)
{ {
EMB_UNIT_TESTFIXTURES(fixtures) { EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_libcose_01), new_TestFixture(test_libcose_01),
new_TestFixture(test_libcose_02), new_TestFixture(test_libcose_02),
#if defined(MODULE_LIBCOSE_CRYPT_HACL) || defined(MODULE_LIBCOSE_CRYPT_MONOCYPHER)
new_TestFixture(test_libcose_03), new_TestFixture(test_libcose_03),
#endif
}; };
EMB_UNIT_TESTCALLER(libcose_tests, setUp, NULL, fixtures); EMB_UNIT_TESTCALLER(libcose_tests, setUp, NULL, fixtures);