Path: blob/main/crypto/openssl/providers/common/der/der_rsa_sig.c
48383 views
/*1* Copyright 2020-2021 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 <openssl/obj_mac.h>10#include "internal/packet.h"11#include "prov/der_rsa.h"12#include "prov/der_digests.h"1314/* Aliases so we can have a uniform MD_with_RSA_CASE */15#define ossl_der_oid_sha3_224WithRSAEncryption \16ossl_der_oid_id_rsassa_pkcs1_v1_5_with_sha3_22417#define ossl_der_oid_sha3_256WithRSAEncryption \18ossl_der_oid_id_rsassa_pkcs1_v1_5_with_sha3_25619#define ossl_der_oid_sha3_384WithRSAEncryption \20ossl_der_oid_id_rsassa_pkcs1_v1_5_with_sha3_38421#define ossl_der_oid_sha3_512WithRSAEncryption \22ossl_der_oid_id_rsassa_pkcs1_v1_5_with_sha3_51223#define ossl_der_oid_mdc2WithRSAEncryption \24ossl_der_oid_mdc2WithRSASignature2526#define MD_with_RSA_CASE(name, var) \27case NID_##name: \28var = ossl_der_oid_##name##WithRSAEncryption; \29var##_sz = sizeof(ossl_der_oid_##name##WithRSAEncryption); \30break;3132int ossl_DER_w_algorithmIdentifier_MDWithRSAEncryption(WPACKET *pkt, int tag,33int mdnid)34{35const unsigned char *precompiled = NULL;36size_t precompiled_sz = 0;3738switch (mdnid) {39#ifndef FIPS_MODULE40MD_with_RSA_CASE(md2, precompiled);41MD_with_RSA_CASE(md5, precompiled);42MD_with_RSA_CASE(md4, precompiled);43MD_with_RSA_CASE(ripemd160, precompiled);44MD_with_RSA_CASE(mdc2, precompiled);45#endif46MD_with_RSA_CASE(sha1, precompiled);47MD_with_RSA_CASE(sha224, precompiled);48MD_with_RSA_CASE(sha256, precompiled);49MD_with_RSA_CASE(sha384, precompiled);50MD_with_RSA_CASE(sha512, precompiled);51MD_with_RSA_CASE(sha512_224, precompiled);52MD_with_RSA_CASE(sha512_256, precompiled);53MD_with_RSA_CASE(sha3_224, precompiled);54MD_with_RSA_CASE(sha3_256, precompiled);55MD_with_RSA_CASE(sha3_384, precompiled);56MD_with_RSA_CASE(sha3_512, precompiled);57default:58/*59* Hash algorithms for which we do not have a valid OID60* such as md5sha1 will just fail to provide the der encoding.61* That does not prevent producing signatures if OID is not needed.62*/63return -1;64}6566return ossl_DER_w_begin_sequence(pkt, tag)67/* PARAMETERS, always NULL according to current standards */68&& ossl_DER_w_null(pkt, -1)69/* OID */70&& ossl_DER_w_precompiled(pkt, -1, precompiled, precompiled_sz)71&& ossl_DER_w_end_sequence(pkt, tag);72}737475