sc-hsm: Check the operation first

This commit is contained in:
Jakub Jelen 2019-05-20 16:03:07 +02:00 committed by Frank Morgner
parent df0bbc110e
commit 86fd200462

View File

@ -1001,7 +1001,9 @@ static int sc_hsm_set_security_env(sc_card_t *card,
} }
break; break;
case SC_ALGORITHM_EC: case SC_ALGORITHM_EC:
if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_NONE) { if (env->operation == SC_SEC_OPERATION_DERIVE) {
priv->algorithm = ALGO_EC_DH;
} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_NONE) {
priv->algorithm = ALGO_EC_RAW; priv->algorithm = ALGO_EC_RAW;
} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA1) { } else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA1) {
priv->algorithm = ALGO_EC_SHA1; priv->algorithm = ALGO_EC_SHA1;
@ -1009,12 +1011,8 @@ static int sc_hsm_set_security_env(sc_card_t *card,
priv->algorithm = ALGO_EC_SHA224; priv->algorithm = ALGO_EC_SHA224;
} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA256) { } else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA256) {
priv->algorithm = ALGO_EC_SHA256; priv->algorithm = ALGO_EC_SHA256;
} else if (env->algorithm_flags & SC_ALGORITHM_ECDH_CDH_RAW) { } else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_RAW) {
if (env->operation == SC_SEC_OPERATION_DERIVE) { priv->algorithm = ALGO_EC_RAW;
priv->algorithm = ALGO_EC_DH;
} else {
priv->algorithm = ALGO_EC_RAW;
}
} else { } else {
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS); LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
} }