1*b077aed3SPierre Pronchery /*
2*b077aed3SPierre Pronchery * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
3*b077aed3SPierre Pronchery *
4*b077aed3SPierre Pronchery * Licensed under the Apache License 2.0 (the "License"). You may not use
5*b077aed3SPierre Pronchery * this file except in compliance with the License. You can obtain a copy
6*b077aed3SPierre Pronchery * in the file LICENSE in the source distribution or at
7*b077aed3SPierre Pronchery * https://www.openssl.org/source/license.html
8*b077aed3SPierre Pronchery */
9*b077aed3SPierre Pronchery
10*b077aed3SPierre Pronchery #include <openssl/obj_mac.h>
11*b077aed3SPierre Pronchery #include "internal/packet.h"
12*b077aed3SPierre Pronchery #include "prov/der_rsa.h"
13*b077aed3SPierre Pronchery #include "prov/der_digests.h"
14*b077aed3SPierre Pronchery
15*b077aed3SPierre Pronchery /* Aliases so we can have a uniform MD_with_RSA_CASE */
16*b077aed3SPierre Pronchery #define ossl_der_oid_sha3_224WithRSAEncryption \
17*b077aed3SPierre Pronchery ossl_der_oid_id_rsassa_pkcs1_v1_5_with_sha3_224
18*b077aed3SPierre Pronchery #define ossl_der_oid_sha3_256WithRSAEncryption \
19*b077aed3SPierre Pronchery ossl_der_oid_id_rsassa_pkcs1_v1_5_with_sha3_256
20*b077aed3SPierre Pronchery #define ossl_der_oid_sha3_384WithRSAEncryption \
21*b077aed3SPierre Pronchery ossl_der_oid_id_rsassa_pkcs1_v1_5_with_sha3_384
22*b077aed3SPierre Pronchery #define ossl_der_oid_sha3_512WithRSAEncryption \
23*b077aed3SPierre Pronchery ossl_der_oid_id_rsassa_pkcs1_v1_5_with_sha3_512
24*b077aed3SPierre Pronchery #define ossl_der_oid_mdc2WithRSAEncryption \
25*b077aed3SPierre Pronchery ossl_der_oid_mdc2WithRSASignature
26*b077aed3SPierre Pronchery
27*b077aed3SPierre Pronchery #define MD_with_RSA_CASE(name, var) \
28*b077aed3SPierre Pronchery case NID_##name: \
29*b077aed3SPierre Pronchery var = ossl_der_oid_##name##WithRSAEncryption; \
30*b077aed3SPierre Pronchery var##_sz = sizeof(ossl_der_oid_##name##WithRSAEncryption); \
31*b077aed3SPierre Pronchery break;
32*b077aed3SPierre Pronchery
ossl_DER_w_algorithmIdentifier_MDWithRSAEncryption(WPACKET * pkt,int tag,int mdnid)33*b077aed3SPierre Pronchery int ossl_DER_w_algorithmIdentifier_MDWithRSAEncryption(WPACKET *pkt, int tag,
34*b077aed3SPierre Pronchery int mdnid)
35*b077aed3SPierre Pronchery {
36*b077aed3SPierre Pronchery const unsigned char *precompiled = NULL;
37*b077aed3SPierre Pronchery size_t precompiled_sz = 0;
38*b077aed3SPierre Pronchery
39*b077aed3SPierre Pronchery switch (mdnid) {
40*b077aed3SPierre Pronchery #ifndef FIPS_MODULE
41*b077aed3SPierre Pronchery MD_with_RSA_CASE(md2, precompiled);
42*b077aed3SPierre Pronchery MD_with_RSA_CASE(md5, precompiled);
43*b077aed3SPierre Pronchery MD_with_RSA_CASE(md4, precompiled);
44*b077aed3SPierre Pronchery MD_with_RSA_CASE(ripemd160, precompiled);
45*b077aed3SPierre Pronchery MD_with_RSA_CASE(mdc2, precompiled);
46*b077aed3SPierre Pronchery #endif
47*b077aed3SPierre Pronchery MD_with_RSA_CASE(sha1, precompiled);
48*b077aed3SPierre Pronchery MD_with_RSA_CASE(sha224, precompiled);
49*b077aed3SPierre Pronchery MD_with_RSA_CASE(sha256, precompiled);
50*b077aed3SPierre Pronchery MD_with_RSA_CASE(sha384, precompiled);
51*b077aed3SPierre Pronchery MD_with_RSA_CASE(sha512, precompiled);
52*b077aed3SPierre Pronchery MD_with_RSA_CASE(sha512_224, precompiled);
53*b077aed3SPierre Pronchery MD_with_RSA_CASE(sha512_256, precompiled);
54*b077aed3SPierre Pronchery MD_with_RSA_CASE(sha3_224, precompiled);
55*b077aed3SPierre Pronchery MD_with_RSA_CASE(sha3_256, precompiled);
56*b077aed3SPierre Pronchery MD_with_RSA_CASE(sha3_384, precompiled);
57*b077aed3SPierre Pronchery MD_with_RSA_CASE(sha3_512, precompiled);
58*b077aed3SPierre Pronchery default:
59*b077aed3SPierre Pronchery /*
60*b077aed3SPierre Pronchery * Hash algorithms for which we do not have a valid OID
61*b077aed3SPierre Pronchery * such as md5sha1 will just fail to provide the der encoding.
62*b077aed3SPierre Pronchery * That does not prevent producing signatures if OID is not needed.
63*b077aed3SPierre Pronchery */
64*b077aed3SPierre Pronchery return -1;
65*b077aed3SPierre Pronchery }
66*b077aed3SPierre Pronchery
67*b077aed3SPierre Pronchery return ossl_DER_w_begin_sequence(pkt, tag)
68*b077aed3SPierre Pronchery /* PARAMETERS, always NULL according to current standards */
69*b077aed3SPierre Pronchery && ossl_DER_w_null(pkt, -1)
70*b077aed3SPierre Pronchery /* OID */
71*b077aed3SPierre Pronchery && ossl_DER_w_precompiled(pkt, -1, precompiled, precompiled_sz)
72*b077aed3SPierre Pronchery && ossl_DER_w_end_sequence(pkt, tag);
73*b077aed3SPierre Pronchery }
74