Commit 50091275 authored by Ben Sartor's avatar Ben Sartor Committed by johan

added test for addMandatoryCryptoTypesIfNeeded

Signed-off-by: johan's avatarJohan Pascal <johan.pascal@belledonne-communications.com>
parent cb7e6ab5
...@@ -676,3 +676,47 @@ void test_algoSetterGetter(void) { ...@@ -676,3 +676,47 @@ void test_algoSetterGetter(void) {
CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_2FS3, ZRTP_CIPHER_2FS2, ZRTP_CIPHER_2FS1, ZRTP_CIPHER_AES3, ZRTP_CIPHER_AES2, ZRTP_CIPHER_AES1}, 6, (uint8_t []){ZRTP_CIPHER_AES3, ZRTP_CIPHER_AES1}, 2)); CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_2FS3, ZRTP_CIPHER_2FS2, ZRTP_CIPHER_2FS1, ZRTP_CIPHER_AES3, ZRTP_CIPHER_AES2, ZRTP_CIPHER_AES1}, 6, (uint8_t []){ZRTP_CIPHER_AES3, ZRTP_CIPHER_AES1}, 2));
} }
#define ZRTP_AUTHTAG_FAKE_1 0x41
#define ZRTP_AUTHTAG_FAKE_2 0x42
#define ZRTP_AUTHTAG_FAKE_3 0x43
#define ZRTP_AUTHTAG_FAKE_4 0x44
#define ZRTP_AUTHTAG_FAKE_5 0x45
static int testAddMandatoryCryptoTypesIfNeeded(uint8_t algoType, uint8_t algoTypes[7], uint8_t algoTypesCount, uint8_t expectedTypes[7], uint8_t expectedTypesCount) {
addMandatoryCryptoTypesIfNeeded(algoType, algoTypes, &algoTypesCount);
return compareAlgoTypes(algoTypes, algoTypesCount, expectedTypes, expectedTypesCount);
}
void test_addMandatoryCryptoTypesIfNeeded(void) {
/* mandatory types */
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_HASH_TYPE, (uint8_t [7]){}, 0, (uint8_t []){ZRTP_HASH_S256}, 1));
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_CIPHERBLOCK_TYPE, (uint8_t [7]){}, 0, (uint8_t []){ZRTP_CIPHER_AES1}, 1));
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_AUTHTAG_TYPE, (uint8_t [7]){}, 0, (uint8_t []){ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS80}, 2));
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_KEYAGREEMENT_TYPE, (uint8_t [7]){}, 0, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k}, 1));
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_SAS_TYPE, (uint8_t [7]){}, 0, (uint8_t []){ZRTP_SAS_B32}, 1));
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_AUTHTAG_TYPE, (uint8_t [7]){ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS80}, 2, (uint8_t []){ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS80}, 2));
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_AUTHTAG_TYPE, (uint8_t [7]){ZRTP_AUTHTAG_HS80, ZRTP_AUTHTAG_HS32}, 2, (uint8_t []){ZRTP_AUTHTAG_HS80, ZRTP_AUTHTAG_HS32}, 2));
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_AUTHTAG_TYPE, (uint8_t [7]){ZRTP_AUTHTAG_HS80, ZRTP_AUTHTAG_SK64}, 2, (uint8_t []){ZRTP_AUTHTAG_HS80, ZRTP_AUTHTAG_SK64, ZRTP_AUTHTAG_HS32}, 3));
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_AUTHTAG_TYPE, (uint8_t [7]){ZRTP_AUTHTAG_SK32, ZRTP_AUTHTAG_SK64}, 2, (uint8_t []){ZRTP_AUTHTAG_SK32, ZRTP_AUTHTAG_SK64, ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS80}, 4));
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_AUTHTAG_TYPE, (uint8_t [7]){ZRTP_AUTHTAG_SK32, ZRTP_AUTHTAG_SK64, ZRTP_AUTHTAG_FAKE_1, ZRTP_AUTHTAG_FAKE_2, ZRTP_AUTHTAG_FAKE_3}, 5, (uint8_t []){ZRTP_AUTHTAG_SK32, ZRTP_AUTHTAG_SK64, ZRTP_AUTHTAG_FAKE_1, ZRTP_AUTHTAG_FAKE_2, ZRTP_AUTHTAG_FAKE_3, ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS80}, 7));
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_AUTHTAG_TYPE, (uint8_t [7]){ZRTP_AUTHTAG_SK32, ZRTP_AUTHTAG_SK64, ZRTP_AUTHTAG_FAKE_1, ZRTP_AUTHTAG_FAKE_2, ZRTP_AUTHTAG_FAKE_3, ZRTP_AUTHTAG_HS80}, 6, (uint8_t []){ZRTP_AUTHTAG_SK32, ZRTP_AUTHTAG_SK64, ZRTP_AUTHTAG_FAKE_1, ZRTP_AUTHTAG_FAKE_2, ZRTP_AUTHTAG_FAKE_3, ZRTP_AUTHTAG_HS80, ZRTP_AUTHTAG_HS32}, 7));
/* overrride */
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_AUTHTAG_TYPE, (uint8_t [7]){ZRTP_AUTHTAG_SK32, ZRTP_AUTHTAG_SK64, ZRTP_AUTHTAG_FAKE_1, ZRTP_AUTHTAG_FAKE_2, ZRTP_AUTHTAG_FAKE_3, ZRTP_AUTHTAG_FAKE_4, ZRTP_AUTHTAG_FAKE_5}, 7, (uint8_t []){ZRTP_AUTHTAG_SK32, ZRTP_AUTHTAG_SK64, ZRTP_AUTHTAG_FAKE_1, ZRTP_AUTHTAG_FAKE_2, ZRTP_AUTHTAG_FAKE_3, ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS80}, 7));
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_AUTHTA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U_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_AUTHTAG_TYPE, (uint8_t [7]){ZRTP_AUTHTAG_SK32, ZRTP_AUTHTAG_SK64, ZRTP_AUTHTAG_FAKE_1, ZRTP_AUTHTAG_FAKE_2, ZRTP_AUTHTAG_FAKE_3, ZRTP_AUTHTAG_FAKE_4, ZRTP_AUTHTAG_HS80}, 7, (uint8_t []){ZRTP_AUTHTAG_SK32, ZRTP_AUTHTAG_SK64, ZRTP_AUTHTAG_FAKE_1, ZRTP_AUTHTAG_FAKE_2, ZRTP_AUTHTAG_FAKE_3, ZRTP_AUTHTAG_HS80, ZRTP_AUTHTAG_HS32}, 7));
/* uniqueness */
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_AUTHTAG_TYPE, (uint8_t [7]){ZRTP_AUTHTAG_SK32, ZRTP_AUTHTAG_SK64, ZRTP_AUTHTAG_SK32, ZRTP_AUTHTAG_SK64}, 4, (uint8_t []){ZRTP_AUTHTAG_SK32, ZRTP_AUTHTAG_SK64, ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS80}, 4));
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_AUTHTAG_TYPE, (uint8_t [7]){ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS32}, 4, (uint8_t []){ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS80}, 2));
CU_TEST(testAddMandatoryCryptoTypesIfNeeded(ZRTP_AUTHTAG_TYPE, (uint8_t [7]){ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS80, ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS80}, 4, (uint8_t []){ZRTP_AUTHTAG_HS32, ZRTP_AUTHTAG_HS80}, 2));
}
...@@ -29,3 +29,4 @@ void test_zrtpKDF(void); ...@@ -29,3 +29,4 @@ void test_zrtpKDF(void);
void test_CRC32(void); void test_CRC32(void);
void test_algoAgreement(void); void test_algoAgreement(void);
void test_algoSetterGetter(void); void test_algoSetterGetter(void);
void test_addMandatoryCryptoTypesIfNeeded(void);
...@@ -59,6 +59,7 @@ int main(int argc, char *argv[] ) { ...@@ -59,6 +59,7 @@ int main(int argc, char *argv[] ) {
CU_add_test(cryptoUtilsTestSuite, "CRC32", test_CRC32); CU_add_test(cryptoUtilsTestSuite, "CRC32", test_CRC32);
CU_add_test(cryptoUtilsTestSuite, "algo agreement", test_algoAgreement); CU_add_test(cryptoUtilsTestSuite, "algo agreement", test_algoAgreement);
CU_add_test(cryptoUtilsTestSuite, "context algo setter and getter", test_algoSetterGetter); CU_add_test(cryptoUtilsTestSuite, "context algo setter and getter", test_algoSetterGetter);
CU_add_test(cryptoUtilsTestSuite, "adding mandatory crypto algorithms if needed", test_addMandatoryCryptoTypesIfNeeded);
/* Add the parser suite to the registry */ /* Add the parser suite to the registry */
parserTestSuite = CU_add_suite("Bzrtp ZRTP Packet Parser", NULL, NULL); parserTestSuite = CU_add_suite("Bzrtp ZRTP Packet Parser", NULL, NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment