Commit 073bfc7d authored by Ben Sartor's avatar Ben Sartor Committed by johan

new test for getter/setter of supported crypto types

Signed-off-by: johan's avatarJohan Pascal <johan.pascal@belledonne-communications.com>
parent cf63aa05
......@@ -603,3 +603,72 @@ void test_algoAgreement(void) {
CU_TEST(testAlgoType(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_2FS3, ZRTP_CIPHER_2FS2, ZRTP_CIPHER_2FS1, ZRTP_CIPHER_AES3, ZRTP_CIPHER_AES2, ZRTP_CIPHER_AES1}, 6, ZRTP_CIPHER_AES3));
CU_TEST(testAlgoType(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_2FS3, ZRTP_CIPHER_2FS2, ZRTP_CIPHER_2FS1, ZRTP_CIPHER_AES1, ZRTP_CIPHER_AES2, ZRTP_CIPHER_AES3}, 6, ZRTP_CIPHER_AES1));
}
static int compareAlgoTypes(uint8_t actualTypes[7], uint8_t actualTypesCount, uint8_t expectedTypes[7], uint8_t expectedTypesCount) {
int i;
if (actualTypesCount != expectedTypesCount) {
return 0;
}
for (i=0; i<actualTypesCount; i++) {
if (actualTypes[i] != expectedTypes[i]) {
return 0;
}
}
return 1;
}
static int testAlgoSetterGetter(uint8_t algoType, uint8_t contextTypes[7], uint8_t contextTypesCount, uint8_t expectedTypes[7], uint8_t expectedTypesCount) {
int retval;
uint8_t compareTypes[7];
uint8_t compareTypesCount;
bzrtpContext_t *zrtpContext = bzrtp_createBzrtpContext(0x12345678);
bzrtp_setSupportedCryptoTypes(zrtpContext, algoType, contextTypes, contextTypesCount);
compareTypesCount = bzrtp_getSupportedCryptoTypes(zrtpContext, algoType, compareTypes);
retval = compareAlgoTypes(compareTypes, compareTypesCount, expectedTypes, expectedTypesCount);
bzrtp_destroyBzrtpContext(zrtpContext, 0x12345678);
return retval;
}
void test_algoSetterGetter(void) {
/* key agreement type */
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_DH2k}, 1, (uint8_t []){ZRTP_KEYAGREEMENT_DH2k}, 1));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k}, 1, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k}, 1));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_EC25}, 1, NULL, 0));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_EC38}, 1, NULL, 0));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_EC52}, 1, NULL, 0));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_Prsh}, 1, NULL, 0));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_Mult}, 1, (uint8_t []){ZRTP_KEYAGREEMENT_Mult}, 1));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH2k}, 2, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH2k}, 2));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_DH2k, ZRTP_KEYAGREEMENT_DH3k}, 2, (uint8_t []){ZRTP_KEYAGREEMENT_DH2k, ZRTP_KEYAGREEMENT_DH3k}, 2));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k}, 2, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k}, 2));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_EC25}, 2, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k}, 1));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_EC25, ZRTP_KEYAGREEMENT_DH3k}, 2, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k}, 1));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_EC25, ZRTP_KEYAGREEMENT_EC52}, 2, NULL, 0));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_EC52, ZRTP_KEYAGREEMENT_EC25, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH2k}, 4, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH2k}, 2));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_Prsh, ZRTP_KEYAGREEMENT_EC52, ZRTP_KEYAGREEMENT_EC38, ZRTP_KEYAGREEMENT_EC25, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH2k}, 6, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH2k}, 2));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH2k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH2k}, 4, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH2k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH2k}, 4));
CU_TEST(testAlgoSetterGetter(ZRTP_KEYAGREEMENT_TYPE, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k}, 8, (uint8_t []){ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k, ZRTP_KEYAGREEMENT_DH3k}, 7));
/* cipher type */
CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_AES1}, 1, (uint8_t []){ZRTP_CIPHER_AES1}, 1));
CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_AES2}, 1, NULL, 0));
CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_AES3}, 1, (uint8_t []){ZRTP_CIPHER_AES3}, 1));
CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_2FS1}, 1, NULL, 0));
CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_2FS2}, 1, NULL, 0));
CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_2FS3}, 1, NULL, 0));
CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_AES3, ZRTP_CIPHER_AES3}, 2, (uint8_t []){ZRTP_CIPHER_AES3, ZRTP_CIPHER_AES3}, 2));
CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_AES3, ZRTP_CIPHER_AES1}, 2, (uint8_t []){ZRTP_CIPHER_AES3, ZRTP_CIPHER_AES1}, 2));
CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_AES1, ZRTP_CIPHER_AES3}, 2, (uint8_t []){ZRTP_CIPHER_AES1, ZRTP_CIPHER_AES3}, 2));
CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_AES1, ZRTP_CIPHER_AES2}, 2, (uint8_t []){ZRTP_CIPHER_AES1}, 1));
CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_AES1, ZRTP_CIPHER_2FS3}, 2, (uint8_t []){ZRTP_CIPHER_AES1}, 1));
CU_TEST(testAlgoSetterGetter(ZRTP_CIPHERBLOCK_TYPE, (uint8_t []){ZRTP_CIPHER_AES2, ZRTP_CIPHER_2FS3}, 2, NULL, 0));
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));
}
......@@ -28,3 +28,4 @@ void test_dhm3072(void);
void test_zrtpKDF(void);
void test_CRC32(void);
void test_algoAgreement(void);
void test_algoSetterGetter(void);
......@@ -58,6 +58,7 @@ int main(int argc, char *argv[] ) {
CU_add_test(cryptoUtilsTestSuite, "zrtpKDF", test_zrtpKDF);
CU_add_test(cryptoUtilsTestSuite, "CRC32", test_CRC32);
CU_add_test(cryptoUtilsTestSuite, "algo agreement", test_algoAgreement);
CU_add_test(cryptoUtilsTestSuite, "context algo setter and getter", test_algoSetterGetter);
/* Add the parser suite to the registry */
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