* @remarks For RSA operations the default padding used is #YACA_PADDING_PKCS1. It can be
* changed using yaca_context_set_property() with #YACA_PROPERTY_PADDING.
*
+ * @remarks For #YACA_DIGEST_SHA384 and #YACA_DIGEST_SHA512 the RSA key size must be bigger than
+ * #YACA_KEY_LENGTH_512BIT.
+ *
+ * @remarks Using of #YACA_DIGEST_MD5 algorithm for DSA and ECDSA operations is prohibited.
+ *
+ * @remarks Using of #YACA_DIGEST_MD5 or #YACA_DIGEST_SHA224 with #YACA_PADDING_X931 is prohibited.
+ *
* @remarks The @a ctx should be released using yaca_context_destroy()
*
* @param[out] ctx Newly created context
case ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH):
case ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_WRONG_FINAL_BLOCK_LENGTH):
case ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_PKEY_DERIVE_SET_PEER, EVP_R_DIFFERENT_PARAMETERS):
+ case ERR_PACK(ERR_LIB_EC, EC_F_PKEY_EC_CTRL, EC_R_INVALID_DIGEST_TYPE):
+ case ERR_PACK(ERR_LIB_DSA, DSA_F_PKEY_DSA_CTRL, DSA_R_INVALID_DIGEST_TYPE):
ret = YACA_ERROR_INVALID_PARAMETER;
break;
case ERR_PACK(ERR_LIB_ASN1, ASN1_F_ASN1_GET_OBJECT, ASN1_R_TOO_LONG):
/* known rsa padding errors */
if (ret == YACA_ERROR_NONE && ERR_GET_LIB(err) == ERR_LIB_RSA) {
switch (ERR_GET_FUNC(err)) {
+ case RSA_F_CHECK_PADDING_MD:
case RSA_F_RSA_PADDING_CHECK_NONE:
case RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP:
case RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1:
ret = EVP_PKEY_CTX_set_rsa_padding(pctx, pad);
if (ret <= 0) {
- ret = YACA_ERROR_INTERNAL;
- ERROR_DUMP(ret);
+ ret = ERROR_HANDLE();
return ret;
}
if (ctx == NULL || evp_key == NULL)
return YACA_ERROR_INVALID_PARAMETER;
+ ret = digest_get_algorithm(algo, &md);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
+
switch (prv_key->type) {
case YACA_KEY_TYPE_RSA_PRIV:
+ if (EVP_MD_size(md) >= EVP_PKEY_size(evp_key->evp) ||
+ (algo == YACA_DIGEST_SHA384 && (EVP_PKEY_size(evp_key->evp) <= YACA_KEY_LENGTH_512BIT / 8)))
+ return YACA_ERROR_INVALID_PARAMETER;
+ break;
case YACA_KEY_TYPE_DSA_PRIV:
case YACA_KEY_TYPE_EC_PRIV:
break;
nc->ctx.set_property = set_sign_property;
nc->ctx.get_property = NULL;
- ret = digest_get_algorithm(algo, &md);
- if (ret != YACA_ERROR_NONE)
- goto exit;
-
nc->md_ctx = EVP_MD_CTX_create();
if (nc->md_ctx == NULL) {
ret = YACA_ERROR_INTERNAL;
ret = EVP_DigestSignInit(nc->md_ctx, NULL, md, NULL, evp_key->evp);
if (ret != 1) {
- ret = YACA_ERROR_INTERNAL;
- ERROR_DUMP(ret);
+ ret = ERROR_HANDLE();
goto exit;
}
if (ctx == NULL || evp_key == NULL)
return YACA_ERROR_INVALID_PARAMETER;
+ ret = digest_get_algorithm(algo, &md);
+ if (ret != YACA_ERROR_NONE)
+ return ret;
+
switch (pub_key->type) {
case YACA_KEY_TYPE_RSA_PUB:
+ if (EVP_MD_size(md) >= EVP_PKEY_size(evp_key->evp) ||
+ (algo == YACA_DIGEST_SHA384 && (EVP_PKEY_size(evp_key->evp) <= YACA_KEY_LENGTH_512BIT / 8)))
+ return YACA_ERROR_INVALID_PARAMETER;
+ break;
case YACA_KEY_TYPE_DSA_PUB:
case YACA_KEY_TYPE_EC_PUB:
break;
nc->ctx.set_property = set_sign_property;
nc->ctx.get_property = NULL;
- ret = digest_get_algorithm(algo, &md);
- if (ret != YACA_ERROR_NONE)
- goto exit;
-
nc->md_ctx = EVP_MD_CTX_create();
if (nc->md_ctx == NULL) {
ret = YACA_ERROR_INTERNAL;
ret = EVP_DigestVerifyInit(nc->md_ctx, NULL, md, NULL, evp_key->evp);
if (ret != 1) {
- ret = YACA_ERROR_INTERNAL;
- ERROR_DUMP(ret);
+ ret = ERROR_HANDLE();
goto exit;
}