diff --git a/src/Common/crypto/lib_dep/cyclone/key_manager_cyclone.c b/src/Common/crypto/lib_dep/cyclone/key_manager_cyclone.c index 5d84441d34a38505ca7401037703e3b04aaaf36f..7cb72df18bd293643b6e4f19dff37f00eee749d6 100644 --- a/src/Common/crypto/lib_dep/cyclone/key_manager_cyclone.c +++ b/src/Common/crypto/lib_dep/cyclone/key_manager_cyclone.c @@ -49,6 +49,23 @@ #include "pkix/x509_key_parse.h" #include "pkix/x509_sign_verify.h" +#if (CYCLONE_CRYPTO_MAJOR_VERSION == 2 && CYCLONE_CRYPTO_MINOR_VERSION >= 5) +#define CYCLONE_CRYPTO_API_V25X +#endif + +// Macro for API compatibility between Cyclone Crypto v2.4.X and v2.5.X +#if defined(CYCLONE_CRYPTO_API_V25X) +#define pemImportRsaPublicKeyCompat(input, len, publicKey) pemImportRsaPublicKey(publicKey, input, len) +#define pemImportRsaPrivateKeyCompat(input, len, pwd, privateKey) pemImportRsaPrivateKey(privateKey, input, len, pwd) +#define pkcs8ImportRsaPrivateKeyCompat(privateKeyInfo, privateKey) pkcs8ImportRsaPrivateKey(privateKey, privateKeyInfo) +#define x509ImportRsaPublicKeyCompat(publicKeyInfo, publicKey) x509ImportRsaPublicKey(publicKey, publicKeyInfo) +#else +#define pemImportRsaPublicKeyCompat(input, len, publicKey) pemImportRsaPublicKey(input, len, publicKey) +#define pemImportRsaPrivateKeyCompat(input, len, pwd, privateKey) pemImportRsaPrivateKey(input, len, pwd, privateKey) +#define pkcs8ImportRsaPrivateKeyCompat(privateKeyInfo, privateKey) pkcs8ImportRsaPrivateKey(privateKeyInfo, privateKey) +#define x509ImportRsaPublicKeyCompat(publicKeyInfo, publicKey) x509ImportRsaPublicKey(publicKeyInfo, publicKey) +#endif + #define SOPC_KEY_MANAGER_SHA1_SIZE 20 /* ------------------------------------------------------------------------------------------------ @@ -84,7 +101,7 @@ SOPC_ReturnStatus SOPC_KeyManager_AsymmetricKey_CreateFromBuffer(const uint8_t* if (is_public) { - errLib = pemImportRsaPublicKey((const char_t*) buffer, (size_t) lenBuf, &key->pubKey); + errLib = pemImportRsaPublicKeyCompat((const char_t*) buffer, (size_t) lenBuf, &key->pubKey); if (0 != errLib) // The buffer is probably in DER format... { @@ -97,13 +114,13 @@ SOPC_ReturnStatus SOPC_KeyManager_AsymmetricKey_CreateFromBuffer(const uint8_t* // If no error, continue... if (0 == errLib) { - errLib = x509ImportRsaPublicKey(&publicKeyInfo, &key->pubKey); + errLib = x509ImportRsaPublicKeyCompat(&publicKeyInfo, &key->pubKey); } } } else // Key is private { - errLib = pemImportRsaPrivateKey((const char_t*) buffer, (size_t) lenBuf, NULL, &key->privKey); + errLib = pemImportRsaPrivateKeyCompat((const char_t*) buffer, (size_t) lenBuf, NULL, &key->privKey); if (0 != errLib) // The buffer is probably in DER format... { @@ -117,7 +134,7 @@ SOPC_ReturnStatus SOPC_KeyManager_AsymmetricKey_CreateFromBuffer(const uint8_t* { privateKeyInfo.oid.value = RSA_ENCRYPTION_OID; privateKeyInfo.oid.length = sizeof(RSA_ENCRYPTION_OID); - errLib = pkcs8ImportRsaPrivateKey(&privateKeyInfo, &key->privKey); + errLib = pkcs8ImportRsaPrivateKeyCompat(&privateKeyInfo, &key->privKey); } // Clear private key info @@ -359,7 +376,7 @@ SOPC_ReturnStatus SOPC_KeyManager_SerializedAsymmetricKey_CreateFromKey(const SO return SOPC_STATUS_NOK; } - uint32_t lenBytes = (uint32_t)(lenBits / 8); + uint32_t lenBytes = (uint32_t) (lenBits / 8); uint8_t* buffer = SOPC_Malloc(sizeof(uint8_t) * lenBytes * 8); // a value of 8 times the key length in bytes is recommended if (NULL == buffer) @@ -434,7 +451,7 @@ SOPC_ReturnStatus SOPC_KeyManager_Certificate_CreateOrAddFromDER(const uint8_t* { /* Allocate and fill the public key of the cert */ rsaInitPublicKey(&pCertNew->pubKey); - errLib = x509ImportRsaPublicKey(&pCertNew->crt.tbsCert.subjectPublicKeyInfo, &pCertNew->pubKey); + errLib = x509ImportRsaPublicKeyCompat(&pCertNew->crt.tbsCert.subjectPublicKeyInfo, &pCertNew->pubKey); if (0 != errLib) { status = SOPC_STATUS_NOK;