Commit e71dfbb9 authored by YannGarcia's avatar YannGarcia
Browse files

mBug fixed in lib_its_security, Enhancement of lib_its_security

parent 3c7f9b9c
......@@ -106,6 +106,10 @@ typedef struct lib_its_security_context_ {
*/
LIBITSSECURITY_API int32_t initialize(const ecc_elliptic_curves_t p_elliptic_curve, lib_its_security_context_t** p_lib_its_security_context);
LIBITSSECURITY_API int32_t initialize_with_public_key(const ecc_elliptic_curves_t p_elliptic_curve, const uint8_t* p_public_key, const ecc_compressed_mode_t p_compressed_mode, lib_its_security_context_t** p_lib_its_security_context);
LIBITSSECURITY_API int32_t initialize_with_private_key(const ecc_elliptic_curves_t p_elliptic_curve, const uint8_t* p_private_key, lib_its_security_context_t** p_lib_its_security_context);
/**
* \fn int32_t uninitialize(lib_its_security_context_t** p_lib_its_security_context);
* \brief Release resources allocated by initialize fiunction
......@@ -297,22 +301,22 @@ LIBITSSECURITY_API int32_t verify_with_ecdsa_brainpoolp384r1_with_sha384(
* \see http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf
*/
LIBITSSECURITY_API int32_t encrypt_with_ecies_nistp256_with_sha256(
lib_its_security_context_t* p_lib_its_security_context,
const uint8_t* p_to_be_encrypted_secured_message,
const size_t p_to_be_encrypted_secured_message_length,
const uint8_t* p_recipients_public_key_compressed,
const ecc_compressed_mode_t p_compressed_mode,
const uint8_t* p_salt,
const size_t p_salt_length,
uint8_t** p_public_ephemeral_key_compressed,
ecc_compressed_mode_t* p_ephemeral_compressed_mode,
uint8_t** p_aes_sym_key,
uint8_t** p_encrypted_sym_key,
uint8_t** p_authentication_vector,
uint8_t** p_nonce,
uint8_t** p_encrypted_secured_message,
size_t* p_encrypted_secured_message_length
);
lib_its_security_context_t* p_lib_its_security_context,
const uint8_t* p_to_be_encrypted_secured_message,
const size_t p_to_be_encrypted_secured_message_length,
const uint8_t* p_recipients_public_key_compressed,
const ecc_compressed_mode_t p_compressed_mode,
const uint8_t* p_salt,
const size_t p_salt_length,
uint8_t** p_public_ephemeral_key_compressed,
ecc_compressed_mode_t* p_ephemeral_compressed_mode,
uint8_t** p_aes_sym_key,
uint8_t** p_encrypted_sym_key,
uint8_t** p_authentication_vector,
uint8_t** p_nonce,
uint8_t** p_encrypted_secured_message,
size_t* p_encrypted_secured_message_length
);
/**
* \brief Decrypt the message using ECIES algorithm to decrypt AES 128 CCM symmetric key,as defined in IEEE Std 1609.2-2017
......@@ -330,39 +334,39 @@ LIBITSSECURITY_API int32_t encrypt_with_ecies_nistp256_with_sha256(
* \see http://digital.csic.es/bitstream/10261/32671/1/V2-I2-P7-13.pdf
*/
LIBITSSECURITY_API int32_t decrypt_with_ecies_nistp256_with_sha256(
lib_its_security_context_t* p_lib_its_security_context,
const uint8_t* p_encrypted_secured_message,
const size_t p_encrypted_secured_message_length,
const uint8_t* p_private_enc_key,
const uint8_t* p_public_ephemeral_key_compressed,
const ecc_compressed_mode_t p_ephemeral_compressed_mode,
const uint8_t* p_encrypted_sym_key,
const uint8_t* p_authentication_vector,
const uint8_t* p_nonce,
const uint8_t* p_salt,
const size_t p_salt_length,
uint8_t** p_aes_sym_enc_key,
uint8_t** p_plain_text_message,
size_t* p_plain_text_message_length
);
lib_its_security_context_t* p_lib_its_security_context,
const uint8_t* p_encrypted_secured_message,
const size_t p_encrypted_secured_message_length,
const uint8_t* p_private_enc_key,
const uint8_t* p_public_ephemeral_key_compressed,
const ecc_compressed_mode_t p_ephemeral_compressed_mode,
const uint8_t* p_encrypted_sym_key,
const uint8_t* p_authentication_vector,
const uint8_t* p_nonce,
const uint8_t* p_salt,
const size_t p_salt_length,
uint8_t** p_aes_sym_enc_key,
uint8_t** p_plain_text_message,
size_t* p_plain_text_message_length
);
LIBITSSECURITY_API int32_t encrypt_with_ecies_brainpoolp256r1_with_sha256(
lib_its_security_context_t* p_lib_its_security_context,
const uint8_t* p_to_be_encrypted_secured_message,
const size_t p_to_be_encrypted_secured_message_length,
const uint8_t* p_recipients_public_key_compressed,
const ecc_compressed_mode_t p_compressed_mode,
const uint8_t* p_salt,
const size_t p_salt_length,
uint8_t** p_public_ephemeral_key_compressed,
ecc_compressed_mode_t* p_ephemeral_compressed_mode,
uint8_t** p_aes_sym_key,
uint8_t** p_encrypted_sym_key,
uint8_t** p_authentication_vector,
uint8_t** p_nonce,
uint8_t** p_encrypted_secured_message,
size_t* p_encrypted_secured_message_length
);
lib_its_security_context_t* p_lib_its_security_context,
const uint8_t* p_to_be_encrypted_secured_message,
const size_t p_to_be_encrypted_secured_message_length,
const uint8_t* p_recipients_public_key_compressed,
const ecc_compressed_mode_t p_compressed_mode,
const uint8_t* p_salt,
const size_t p_salt_length,
uint8_t** p_public_ephemeral_key_compressed,
ecc_compressed_mode_t* p_ephemeral_compressed_mode,
uint8_t** p_aes_sym_key,
uint8_t** p_encrypted_sym_key,
uint8_t** p_authentication_vector,
uint8_t** p_nonce,
uint8_t** p_encrypted_secured_message,
size_t* p_encrypted_secured_message_length
);
LIBITSSECURITY_API int32_t decrypt_with_ecies_brainpoolp256r1_with_sha256(
lib_its_security_context_t* p_lib_its_security_context,
......@@ -381,6 +385,42 @@ LIBITSSECURITY_API int32_t decrypt_with_ecies_brainpoolp256r1_with_sha256(
size_t* p_plain_text_message_length
);
/**
* \fn int32_t encrypt_(p_lib_its_security_context_t* p_lib_its_security_context, const uint8_t* p_plain_text_message, const size_t p_plain_text_message_length, uint8_t** p_cipher_message, size_t* p_cipher_message_length);
* \brief Encryption function using algorithm specified in the internal context.
* \param[in/out] p_lib_its_security_context The internal context
* \param[out] p_plain_text_message The plain text message to be ciphered
* \param[out] p_plain_text_message_length The plain text message length
* \param[out] p_cipher_message The ciphered message
* \param[out] p_cipher_message_length The ciphered message length
* \return 0 on success, -1 otherwise
*/
LIBITSSECURITY_API int32_t encrypt_( // Conflict with unistd.h
lib_its_security_context_t* p_lib_its_security_context,
const uint8_t* p_plain_text_message,
const size_t p_plain_text_message_length,
uint8_t** p_cipher_message,
size_t* p_cipher_message_length
);
/**
* \fn int32_t decrypt(lib_its_security_context_t* p_lib_its_security_context, const uint8_t* p_cipher_message, const size_t p_cipher_message_length, uint8_t** p_plain_text_message, size_t* p_plain_text_message_length);
* \brief Decryption function using algorithm specified in the internal context.
* \param[in/out] p_lib_its_security_context The internal context
* \param[out] p_cipher_message The ciphered message to be decrypted
* \param[out] p_cipher_message_length The ciphered message length
* \param[out] p_plain_text_message The plain text message
* \param[out] p_plain_text_message_length The plain text message length
* \return 0 on success, -1 otherwise
*/
LIBITSSECURITY_API int32_t decrypt(
lib_its_security_context_t* p_lib_its_security_context,
const uint8_t* p_cipher_message,
const size_t p_cipher_message_length,
uint8_t** p_plain_text_message,
size_t* p_plain_text_message_length
);
/**
* \fn int32_t generate_key_pair(lib_its_security_context_t* p_lib_its_security_context, uint8_t** p_private_key,uint8_t** p_public_key_x,uint8_t** p_public_key_y,uint8_t** p_public_key_compressed, ecc_compressed_mode_t* p_compressed_mode);
* \brief Produce a new public/private key pair based on Elliptic Curve Digital Signature Algorithm (ECDSA) algorithm.
......
......@@ -499,6 +499,32 @@ TEST(lib_its_security_test_suite, sign_with_ecdsa_nistp256_with_sha256_4) {
EXPECT_TRUE(lib_its_security_context == NULL);
}
TEST(lib_its_security_test_suite, sign_with_ecdsa_nistp256_with_sha256_5) {
// Preamble
lib_its_security_context_t* lib_its_security_context = NULL;
EXPECT_TRUE(initialize(nist_p_256, &lib_its_security_context) == 0);
size_t l;
uint8_t* issuer = hex_to_bin((const int8_t*)"4CC9D9FECC22775705A4B15929A3B01BEEE0BE6903AC3524EFEB473043DD2B88", &l);
uint8_t* sig = hex_to_bin((const int8_t*)"208F312F000D528C45E05A8BD9BC40A3627AA423FC5E8979068646B2C7A55449232B3FFEA13D9C73B2936CA4C037F984FB1FA6ACC34CD9D4C5C9C41B804C47A6", &l);
uint8_t* public_key_compressed = hex_to_bin((const int8_t*)"311038D31EF3A6201EEFC8CE75220F83FB18783923C7A31093DDED24F8123C8F", &l);
ecc_compressed_mode_t public_key_compressed_mode = compressed_y_1;
uint8_t* message = hex_to_bin((const int8_t*)"4003805320508000002F0A00BC21001C6B0D0201CBF4D9FB15E761B5FD48CC8D000000000000000007D1000002020010F43DDDE14059718956ADC020AE600200200030D41E0000012016840310A50733FFE1FFFA0010004001240001D00CB48315C1", &l);
// Test body
EXPECT_TRUE(verify_with_ecdsa_nistp256_with_sha256(lib_its_security_context, message, l, issuer, sig, public_key_compressed, public_key_compressed_mode) == 0);
*(sig + 1) = 0xaa; *(sig + 2) = 0xaa;
EXPECT_TRUE(verify_with_ecdsa_nistp256_with_sha256(lib_its_security_context, message, l, issuer, sig, public_key_compressed, public_key_compressed_mode) == -1);
// Postamble
free(message);
free(public_key_compressed);
free(sig);
free(issuer);
EXPECT_TRUE(lib_its_security_context->ec_key != NULL);
EXPECT_TRUE(uninitialize(&lib_its_security_context) == 0);
EXPECT_TRUE(lib_its_security_context == NULL);
}
TEST(lib_its_security_test_suite, sign_with_ecdsa_brainpoolp256r1_with_sha256_1) {
// Preamble
lib_its_security_context_t* lib_its_security_context = NULL;
......@@ -729,6 +755,214 @@ TEST(lib_its_security_test_suite, sign_with_ecdsa_brainpoolp384r1_with_sha384_4)
EXPECT_TRUE(lib_its_security_context == NULL);
}
TEST(lib_its_security_test_suite, encrypt_aes_ccm_1) {
// Preamble
lib_its_security_context_t* lib_its_security_context = NULL;
EXPECT_TRUE(initialize(nist_p_256, &lib_its_security_context) == 0);
lib_its_security_context->encryption_algorithm = aes_128_ccm;
lib_its_security_context->sym_key = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->sym_key_length));
lib_its_security_context->nonce = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->nonce_length));
// Test body
size_t plain_text_message_length;
uint8_t* plain_text_message = hex_to_bin((const int8_t*)"03810040038081BC01800381004003806400104553435259505400000000000000001101008082671439CBFB6E69370113B14E077A6097AACC62945C122D402A6975AF6FF3DAA77C8110455343525950540000000000000000111DCCE0F98400788301028000FA80017C00010180012481030201C04002026F0001C6B773D2F2B0828080217B7AA6442D85721A9DB6F0C2E307BEC1795B33E6957055F504F8F7A5DD1A956788F6A1146998DA44EC4756C8DB2AB46EBD1D3BAB6894FE8667594FAE2B24374002026F0001C6B773D33130828080AE1B9F9D16A35646C4C84CE4A4C3B50C84125356A74A94B009750941DC94A9DB6D91A2B75633AB573B3369C0DE7CCBD44EC08ABB268EA341FCBB53757E5B7589", &plain_text_message_length);
size_t encrypted_secured_message_length = 0;
uint8_t* encrypted_secured_message = NULL;
EXPECT_TRUE(encrypt_(NULL, plain_text_message, plain_text_message_length, &encrypted_secured_message, &encrypted_secured_message_length) == -1);
EXPECT_TRUE(encrypt_(lib_its_security_context, NULL, plain_text_message_length, &encrypted_secured_message, &encrypted_secured_message_length) == -1);
EXPECT_TRUE(encrypt_(lib_its_security_context, plain_text_message, plain_text_message_length, NULL, &encrypted_secured_message_length) == -1);
// Postamble
free(plain_text_message);
free(encrypted_secured_message);
EXPECT_TRUE(lib_its_security_context->ec_key != NULL);
EXPECT_TRUE(uninitialize(&lib_its_security_context) == 0);
EXPECT_TRUE(lib_its_security_context == NULL);
}
TEST(lib_its_security_test_suite, encrypt_aes_ccm_2) {
// Preamble
lib_its_security_context_t* lib_its_security_context = NULL;
EXPECT_TRUE(initialize(nist_p_256, &lib_its_security_context) == 0);
lib_its_security_context->encryption_algorithm = aes_128_ccm;
lib_its_security_context->nonce = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->nonce_length));
// Test body
size_t plain_text_message_length;
uint8_t* plain_text_message = hex_to_bin((const int8_t*)"03810040038081BC01800381004003806400104553435259505400000000000000001101008082671439CBFB6E69370113B14E077A6097AACC62945C122D402A6975AF6FF3DAA77C8110455343525950540000000000000000111DCCE0F98400788301028000FA80017C00010180012481030201C04002026F0001C6B773D2F2B0828080217B7AA6442D85721A9DB6F0C2E307BEC1795B33E6957055F504F8F7A5DD1A956788F6A1146998DA44EC4756C8DB2AB46EBD1D3BAB6894FE8667594FAE2B24374002026F0001C6B773D33130828080AE1B9F9D16A35646C4C84CE4A4C3B50C84125356A74A94B009750941DC94A9DB6D91A2B75633AB573B3369C0DE7CCBD44EC08ABB268EA341FCBB53757E5B7589", &plain_text_message_length);
size_t encrypted_secured_message_length = 0;
uint8_t* encrypted_secured_message = NULL;
EXPECT_TRUE(encrypt_(lib_its_security_context, plain_text_message, plain_text_message_length, &encrypted_secured_message, &encrypted_secured_message_length) == -1);
// Postamble
free(plain_text_message);
free(encrypted_secured_message);
EXPECT_TRUE(lib_its_security_context->ec_key != NULL);
EXPECT_TRUE(uninitialize(&lib_its_security_context) == 0);
EXPECT_TRUE(lib_its_security_context == NULL);
}
TEST(lib_its_security_test_suite, encrypt_aes_ccm_3) {
// Preamble
lib_its_security_context_t* lib_its_security_context = NULL;
EXPECT_TRUE(initialize(nist_p_256, &lib_its_security_context) == 0);
lib_its_security_context->encryption_algorithm = aes_128_ccm;
lib_its_security_context->sym_key = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->sym_key_length));
// Test body
size_t plain_text_message_length;
uint8_t* plain_text_message = hex_to_bin((const int8_t*)"03810040038081BC01800381004003806400104553435259505400000000000000001101008082671439CBFB6E69370113B14E077A6097AACC62945C122D402A6975AF6FF3DAA77C8110455343525950540000000000000000111DCCE0F98400788301028000FA80017C00010180012481030201C04002026F0001C6B773D2F2B0828080217B7AA6442D85721A9DB6F0C2E307BEC1795B33E6957055F504F8F7A5DD1A956788F6A1146998DA44EC4756C8DB2AB46EBD1D3BAB6894FE8667594FAE2B24374002026F0001C6B773D33130828080AE1B9F9D16A35646C4C84CE4A4C3B50C84125356A74A94B009750941DC94A9DB6D91A2B75633AB573B3369C0DE7CCBD44EC08ABB268EA341FCBB53757E5B7589", &plain_text_message_length);
size_t encrypted_secured_message_length = 0;
uint8_t* encrypted_secured_message = NULL;
EXPECT_TRUE(encrypt_(lib_its_security_context, plain_text_message, plain_text_message_length, &encrypted_secured_message, &encrypted_secured_message_length) == -1);
// Postamble
free(plain_text_message);
free(encrypted_secured_message);
EXPECT_TRUE(lib_its_security_context->ec_key != NULL);
EXPECT_TRUE(uninitialize(&lib_its_security_context) == 0);
EXPECT_TRUE(lib_its_security_context == NULL);
}
TEST(lib_its_security_test_suite, encrypt_aes_ccm_4) {
// Preamble
lib_its_security_context_t* lib_its_security_context = NULL;
EXPECT_TRUE(initialize(nist_p_256, &lib_its_security_context) == 0);
lib_its_security_context->encryption_algorithm = aes_128_ccm;
lib_its_security_context->sym_key = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->sym_key_length));
lib_its_security_context->nonce = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->nonce_length));
// Test body
size_t plain_text_message_length;
uint8_t* plain_text_message = hex_to_bin((const int8_t*)"03810040038081BC01800381004003806400104553435259505400000000000000001101008082671439CBFB6E69370113B14E077A6097AACC62945C122D402A6975AF6FF3DAA77C8110455343525950540000000000000000111DCCE0F98400788301028000FA80017C00010180012481030201C04002026F0001C6B773D2F2B0828080217B7AA6442D85721A9DB6F0C2E307BEC1795B33E6957055F504F8F7A5DD1A956788F6A1146998DA44EC4756C8DB2AB46EBD1D3BAB6894FE8667594FAE2B24374002026F0001C6B773D33130828080AE1B9F9D16A35646C4C84CE4A4C3B50C84125356A74A94B009750941DC94A9DB6D91A2B75633AB573B3369C0DE7CCBD44EC08ABB268EA341FCBB53757E5B7589", &plain_text_message_length);
size_t encrypted_secured_message_length = 0;
uint8_t* encrypted_secured_message = NULL;
EXPECT_TRUE(encrypt_(lib_its_security_context, plain_text_message, plain_text_message_length, &encrypted_secured_message, &encrypted_secured_message_length) == 0);
EXPECT_TRUE(encrypted_secured_message != NULL);
EXPECT_TRUE(encrypted_secured_message_length == plain_text_message_length);
// Postamble
free(plain_text_message);
free(encrypted_secured_message);
EXPECT_TRUE(lib_its_security_context->ec_key != NULL);
EXPECT_TRUE(uninitialize(&lib_its_security_context) == 0);
EXPECT_TRUE(lib_its_security_context == NULL);
}
TEST(lib_its_security_test_suite, decrypt_aes_ccm_1) {
// Preamble
lib_its_security_context_t* lib_its_security_context = NULL;
EXPECT_TRUE(initialize(nist_p_256, &lib_its_security_context) == 0);
lib_its_security_context->encryption_algorithm = aes_128_ccm;
lib_its_security_context->sym_key = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->sym_key_length));
lib_its_security_context->nonce = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->nonce_length));
// Test body
size_t encrypted_secured_message_length = 0;
uint8_t* encrypted_secured_message = hex_to_bin((const int8_t*)"ABABABAB", &encrypted_secured_message_length);
size_t plain_text_message_length = 0;
uint8_t* plain_text_message = NULL;
EXPECT_TRUE(decrypt(NULL, encrypted_secured_message, encrypted_secured_message_length, &plain_text_message, &plain_text_message_length) == -1);
EXPECT_TRUE(decrypt(lib_its_security_context, NULL, encrypted_secured_message_length, &plain_text_message, &plain_text_message_length) == -1);
EXPECT_TRUE(decrypt(lib_its_security_context, encrypted_secured_message, encrypted_secured_message_length, &plain_text_message, &plain_text_message_length) == -1);
// Postamble
free(plain_text_message);
free(encrypted_secured_message);
EXPECT_TRUE(lib_its_security_context->ec_key != NULL);
EXPECT_TRUE(uninitialize(&lib_its_security_context) == 0);
EXPECT_TRUE(lib_its_security_context == NULL);
}
TEST(lib_its_security_test_suite, decrypt_aes_ccm_2) {
// Preamble
lib_its_security_context_t* lib_its_security_context = NULL;
EXPECT_TRUE(initialize(nist_p_256, &lib_its_security_context) == 0);
lib_its_security_context->encryption_algorithm = aes_128_ccm;
lib_its_security_context->sym_key = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->sym_key_length));
lib_its_security_context->nonce = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->nonce_length));
size_t plain_text_message_length;
uint8_t* plain_text_message = hex_to_bin((const int8_t*)"03810040038081BC01800381004003806400104553435259505400000000000000001101008082671439CBFB6E69370113B14E077A6097AACC62945C122D402A6975AF6FF3DAA77C8110455343525950540000000000000000111DCCE0F98400788301028000FA80017C00010180012481030201C04002026F0001C6B773D2F2B0828080217B7AA6442D85721A9DB6F0C2E307BEC1795B33E6957055F504F8F7A5DD1A956788F6A1146998DA44EC4756C8DB2AB46EBD1D3BAB6894FE8667594FAE2B24374002026F0001C6B773D33130828080AE1B9F9D16A35646C4C84CE4A4C3B50C84125356A74A94B009750941DC94A9DB6D91A2B75633AB573B3369C0DE7CCBD44EC08ABB268EA341FCBB53757E5B7589", &plain_text_message_length);
size_t encrypted_secured_message_length = 0;
uint8_t* encrypted_secured_message = NULL;
EXPECT_TRUE(encrypt_(lib_its_security_context, plain_text_message, plain_text_message_length, &encrypted_secured_message, &encrypted_secured_message_length) == 0);
// Test body
free(lib_its_security_context->sym_key);
lib_its_security_context->sym_key = NULL;
size_t new_plain_text_message_length;
uint8_t* new_plain_text_message = NULL;
EXPECT_TRUE(decrypt(lib_its_security_context, encrypted_secured_message, encrypted_secured_message_length, &new_plain_text_message, &new_plain_text_message_length) == -1);
// Postamble
free(plain_text_message);
free(encrypted_secured_message);
EXPECT_TRUE(lib_its_security_context->ec_key != NULL);
EXPECT_TRUE(uninitialize(&lib_its_security_context) == 0);
EXPECT_TRUE(lib_its_security_context == NULL);
}
TEST(lib_its_security_test_suite, decrypt_aes_ccm_3) {
// Preamble
lib_its_security_context_t* lib_its_security_context = NULL;
EXPECT_TRUE(initialize(nist_p_256, &lib_its_security_context) == 0);
lib_its_security_context->encryption_algorithm = aes_128_ccm;
lib_its_security_context->sym_key = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->sym_key_length));
lib_its_security_context->nonce = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->nonce_length));
size_t plain_text_message_length;
uint8_t* plain_text_message = hex_to_bin((const int8_t*)"03810040038081BC01800381004003806400104553435259505400000000000000001101008082671439CBFB6E69370113B14E077A6097AACC62945C122D402A6975AF6FF3DAA77C8110455343525950540000000000000000111DCCE0F98400788301028000FA80017C00010180012481030201C04002026F0001C6B773D2F2B0828080217B7AA6442D85721A9DB6F0C2E307BEC1795B33E6957055F504F8F7A5DD1A956788F6A1146998DA44EC4756C8DB2AB46EBD1D3BAB6894FE8667594FAE2B24374002026F0001C6B773D33130828080AE1B9F9D16A35646C4C84CE4A4C3B50C84125356A74A94B009750941DC94A9DB6D91A2B75633AB573B3369C0DE7CCBD44EC08ABB268EA341FCBB53757E5B7589", &plain_text_message_length);
size_t encrypted_secured_message_length = 0;
uint8_t* encrypted_secured_message = NULL;
EXPECT_TRUE(encrypt_(lib_its_security_context, plain_text_message, plain_text_message_length, &encrypted_secured_message, &encrypted_secured_message_length) == 0);
// Test body
free(lib_its_security_context->nonce);
lib_its_security_context->nonce = NULL;
size_t new_plain_text_message_length;
uint8_t* new_plain_text_message = NULL;
EXPECT_TRUE(decrypt(lib_its_security_context, encrypted_secured_message, encrypted_secured_message_length, &new_plain_text_message, &new_plain_text_message_length) == -1);
// Postamble
free(plain_text_message);
free(encrypted_secured_message);
EXPECT_TRUE(lib_its_security_context->ec_key != NULL);
EXPECT_TRUE(uninitialize(&lib_its_security_context) == 0);
EXPECT_TRUE(lib_its_security_context == NULL);
}
TEST(lib_its_security_test_suite, decrypt_aes_ccm_4) {
// Preamble
lib_its_security_context_t* lib_its_security_context = NULL;
EXPECT_TRUE(initialize(nist_p_256, &lib_its_security_context) == 0);
lib_its_security_context->encryption_algorithm = aes_128_ccm;
lib_its_security_context->sym_key = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->sym_key_length));
lib_its_security_context->nonce = hex_to_bin((const int8_t*)"CAFEDECA", &(lib_its_security_context->nonce_length));
size_t plain_text_message_length;
uint8_t* plain_text_message = hex_to_bin((const int8_t*)"03810040038081BC01800381004003806400104553435259505400000000000000001101008082671439CBFB6E69370113B14E077A6097AACC62945C122D402A6975AF6FF3DAA77C8110455343525950540000000000000000111DCCE0F98400788301028000FA80017C00010180012481030201C04002026F0001C6B773D2F2B0828080217B7AA6442D85721A9DB6F0C2E307BEC1795B33E6957055F504F8F7A5DD1A956788F6A1146998DA44EC4756C8DB2AB46EBD1D3BAB6894FE8667594FAE2B24374002026F0001C6B773D33130828080AE1B9F9D16A35646C4C84CE4A4C3B50C84125356A74A94B009750941DC94A9DB6D91A2B75633AB573B3369C0DE7CCBD44EC08ABB268EA341FCBB53757E5B7589", &plain_text_message_length);
size_t encrypted_secured_message_length = 0;
uint8_t* encrypted_secured_message = NULL;
EXPECT_TRUE(encrypt_(lib_its_security_context, plain_text_message, plain_text_message_length, &encrypted_secured_message, &encrypted_secured_message_length) == 0);
EXPECT_TRUE(encrypted_secured_message != NULL);
// Test body
size_t new_plain_text_message_length;
uint8_t* new_plain_text_message = NULL;
EXPECT_TRUE(decrypt(lib_its_security_context, encrypted_secured_message, encrypted_secured_message_length, &new_plain_text_message, &new_plain_text_message_length) == 0);
EXPECT_TRUE(new_plain_text_message != NULL);
EXPECT_TRUE(plain_text_message_length == new_plain_text_message_length);
for(size_t i = 0; i < new_plain_text_message_length; i++) {
EXPECT_TRUE(*(new_plain_text_message + i) == *(plain_text_message + i));
}
// Postamble
free(plain_text_message);
free(encrypted_secured_message);
free(new_plain_text_message);
EXPECT_TRUE(lib_its_security_context->ec_key != NULL);
EXPECT_TRUE(uninitialize(&lib_its_security_context) == 0);
EXPECT_TRUE(lib_its_security_context == NULL);
}
TEST(lib_its_security_test_suite, encrypt_with_ecies_nistp256_with_sha256_1) {
// Preamble
lib_its_security_context_t* lib_its_security_context = 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