der_ml_dsa_key.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright 2025 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. /*
  10. * DSA low level APIs are deprecated for public use, but still ok for
  11. * internal use.
  12. */
  13. #include "internal/deprecated.h"
  14. #include "internal/packet.h"
  15. #include "prov/der_ml_dsa.h"
  16. int ossl_DER_w_algorithmIdentifier_ML_DSA(WPACKET *pkt, int tag, ML_DSA_KEY *key)
  17. {
  18. const uint8_t *alg;
  19. size_t len;
  20. const char *name = ossl_ml_dsa_key_get_name(key);
  21. if (OPENSSL_strcasecmp(name, "ML-DSA-44") == 0) {
  22. alg = ossl_der_oid_id_ml_dsa_44;
  23. len = sizeof(ossl_der_oid_id_ml_dsa_44);
  24. } else if (OPENSSL_strcasecmp(name, "ML-DSA-65") == 0) {
  25. alg = ossl_der_oid_id_ml_dsa_65;
  26. len = sizeof(ossl_der_oid_id_ml_dsa_65);
  27. } else if (OPENSSL_strcasecmp(name, "ML-DSA-87") == 0) {
  28. alg = ossl_der_oid_id_ml_dsa_87;
  29. len = sizeof(ossl_der_oid_id_ml_dsa_87);
  30. } else {
  31. return 0;
  32. }
  33. return ossl_DER_w_begin_sequence(pkt, tag)
  34. /* No parameters */
  35. && ossl_DER_w_precompiled(pkt, -1, alg, len)
  36. && ossl_DER_w_end_sequence(pkt, tag);
  37. }