Path: blob/main/crypto/openssl/providers/common/securitycheck_fips.c
48266 views
/*1* Copyright 2020-2025 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89#include "internal/deprecated.h"1011#include <openssl/rsa.h>12#include <openssl/dsa.h>13#include <openssl/dh.h>14#include <openssl/ec.h>15#include <openssl/err.h>16#include <openssl/proverr.h>17#include <openssl/core_names.h>18#include <openssl/obj_mac.h>19#include "prov/securitycheck.h"2021int ossl_fips_config_securitycheck_enabled(OSSL_LIB_CTX *libctx)22{23#if !defined(OPENSSL_NO_FIPS_SECURITYCHECKS)24return ossl_fips_config_security_checks(libctx);25#else26return 0;27#endif /* OPENSSL_NO_FIPS_SECURITYCHECKS */28}2930int ossl_digest_rsa_sign_get_md_nid(const EVP_MD *md)31{32return ossl_digest_get_approved_nid(md);33}3435int ossl_fips_ind_rsa_key_check(OSSL_FIPS_IND *ind, int id,36OSSL_LIB_CTX *libctx,37const RSA *rsa, const char *desc, int protect)38{39int key_approved = ossl_rsa_check_key_size(rsa, protect);4041if (!key_approved) {42if (!ossl_FIPS_IND_on_unapproved(ind, id, libctx, desc, "Key size",43ossl_fips_config_securitycheck_enabled)) {44ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH,45"operation: %s", desc);46return 0;47}48}49return 1;50}5152# ifndef OPENSSL_NO_EC53int ossl_fips_ind_ec_key_check(OSSL_FIPS_IND *ind, int id,54OSSL_LIB_CTX *libctx,55const EC_GROUP *group, const char *desc,56int protect)57{58int curve_allowed, strength_allowed;5960if (group == NULL)61return 0;6263curve_allowed = ossl_ec_check_curve_allowed(group);64strength_allowed = ossl_ec_check_security_strength(group, protect);6566if (!strength_allowed || !curve_allowed) {67if (!ossl_FIPS_IND_on_unapproved(ind, id, libctx, desc, "EC Key",68ossl_fips_config_securitycheck_enabled)) {69if (!curve_allowed)70ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_CURVE);71if (!strength_allowed)72ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);73return 0;74}75}76return 1;77}78#endif7980int ossl_fips_ind_digest_exch_check(OSSL_FIPS_IND *ind, int id,81OSSL_LIB_CTX *libctx,82const EVP_MD *md, const char *desc)83{84int nid = ossl_digest_get_approved_nid(md);85int approved = (nid != NID_undef && nid != NID_sha1);8687if (!approved) {88if (!ossl_FIPS_IND_on_unapproved(ind, id, libctx, desc, "Digest",89ossl_fips_config_securitycheck_enabled)) {90ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST);91return 0;92}93}94return 1;95}9697int ossl_fips_ind_digest_sign_check(OSSL_FIPS_IND *ind, int id,98OSSL_LIB_CTX *libctx,99int nid, int sha1_allowed,100int sha512_trunc_allowed,101const char *desc,102OSSL_FIPS_IND_CHECK_CB *config_check_f)103{104int approved;105const char *op = "none";106107switch (nid) {108case NID_undef:109approved = 0;110break;111case NID_sha512_224:112case NID_sha512_256:113approved = sha512_trunc_allowed;114op = "Digest Truncated SHA512";115break;116case NID_sha1:117approved = sha1_allowed;118op = "Digest SHA1";119break;120default:121approved = 1;122break;123}124125if (!approved) {126if (!ossl_FIPS_IND_on_unapproved(ind, id, libctx, desc, op,127config_check_f)) {128ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST);129return 0;130}131}132return 1;133}134135136