der_rsa_sig.c 2.8 KB

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