mirror of
https://git.code.sf.net/p/linux-ima/ima-evm-utils
synced 2025-07-02 05:33:15 +02:00
ima-evm-utils: Support SM2/3 algorithm for sign and verify
Keep in sync with the kernel IMA, IMA signature tool supports SM2/3 algorithm combination. Because in the current version of OpenSSL 1.1.1, the SM2 algorithm and the public key using the EC algorithm share the same ID 'EVP_PKEY_EC', and the specific algorithm can only be distinguished by the curve name used. This patch supports this feature. Secondly, the openssl 1.1.1 tool does not fully support the signature of SM2/3 algorithm combination, so the openssl3 tool is used in the test case, and there is no this problem with directly calling the openssl 1.1.1 API in evmctl. Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com> [zohar@linux.ibm.com: "COMPILE_SSL: " -> "COMPILE_SSL=" in .travis.yml Reviewed-by: Petr Vorel <pvorel@suse.cz> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
This commit is contained in:

committed by
Mimi Zohar

parent
40621b2259
commit
a5f5dd7c8e
@ -448,6 +448,16 @@ static int verify_hash_v2(const char *file, const unsigned char *hash, int size,
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(EVP_PKEY_SM2) && OPENSSL_VERSION_NUMBER < 0x30000000
|
||||
/* If EC key are used, check whether it is SM2 key */
|
||||
if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) {
|
||||
EC_KEY *ec = EVP_PKEY_get0_EC_KEY(pkey);
|
||||
int curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
|
||||
if (curve == NID_sm2)
|
||||
EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
|
||||
}
|
||||
#endif
|
||||
|
||||
st = "EVP_PKEY_CTX_new";
|
||||
if (!(ctx = EVP_PKEY_CTX_new(pkey, NULL)))
|
||||
goto err;
|
||||
@ -974,6 +984,16 @@ static int sign_hash_v2(const char *algo, const unsigned char *hash,
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(EVP_PKEY_SM2) && OPENSSL_VERSION_NUMBER < 0x30000000
|
||||
/* If EC key are used, check whether it is SM2 key */
|
||||
if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) {
|
||||
EC_KEY *ec = EVP_PKEY_get0_EC_KEY(pkey);
|
||||
int curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
|
||||
if (curve == NID_sm2)
|
||||
EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (imaevm_params.keyid)
|
||||
keyid = htonl(imaevm_params.keyid);
|
||||
else {
|
||||
|
Reference in New Issue
Block a user