xref: /freebsd/crypto/openssl/providers/common/der/der_slh_dsa_key.c (revision e7be843b4a162e68651d3911f0357ed464915629)
1*e7be843bSPierre Pronchery /*
2*e7be843bSPierre Pronchery  * Copyright 2025 The OpenSSL Project Authors. All Rights Reserved.
3*e7be843bSPierre Pronchery  *
4*e7be843bSPierre Pronchery  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*e7be843bSPierre Pronchery  * this file except in compliance with the License.  You can obtain a copy
6*e7be843bSPierre Pronchery  * in the file LICENSE in the source distribution or at
7*e7be843bSPierre Pronchery  * https://www.openssl.org/source/license.html
8*e7be843bSPierre Pronchery  */
9*e7be843bSPierre Pronchery 
10*e7be843bSPierre Pronchery #include <openssl/obj_mac.h>
11*e7be843bSPierre Pronchery #include <openssl/objects.h>
12*e7be843bSPierre Pronchery #include "internal/packet.h"
13*e7be843bSPierre Pronchery #include "prov/der_slh_dsa.h"
14*e7be843bSPierre Pronchery 
15*e7be843bSPierre Pronchery #define CASE_OID(nid, name)                  \
16*e7be843bSPierre Pronchery     case nid:                                \
17*e7be843bSPierre Pronchery         alg = ossl_der_oid_##name;           \
18*e7be843bSPierre Pronchery         len = sizeof(ossl_der_oid_##name);   \
19*e7be843bSPierre Pronchery         break
20*e7be843bSPierre Pronchery 
ossl_DER_w_algorithmIdentifier_SLH_DSA(WPACKET * pkt,int tag,SLH_DSA_KEY * key)21*e7be843bSPierre Pronchery int ossl_DER_w_algorithmIdentifier_SLH_DSA(WPACKET *pkt, int tag, SLH_DSA_KEY *key)
22*e7be843bSPierre Pronchery {
23*e7be843bSPierre Pronchery     const uint8_t *alg;
24*e7be843bSPierre Pronchery     size_t len;
25*e7be843bSPierre Pronchery     int nid = ossl_slh_dsa_key_get_type(key);
26*e7be843bSPierre Pronchery 
27*e7be843bSPierre Pronchery     switch (nid) {
28*e7be843bSPierre Pronchery         CASE_OID(NID_SLH_DSA_SHA2_128s, id_slh_dsa_sha2_128s);
29*e7be843bSPierre Pronchery         CASE_OID(NID_SLH_DSA_SHA2_128f, id_slh_dsa_sha2_128f);
30*e7be843bSPierre Pronchery         CASE_OID(NID_SLH_DSA_SHA2_192s, id_slh_dsa_sha2_192s);
31*e7be843bSPierre Pronchery         CASE_OID(NID_SLH_DSA_SHA2_192f, id_slh_dsa_sha2_192f);
32*e7be843bSPierre Pronchery         CASE_OID(NID_SLH_DSA_SHA2_256s, id_slh_dsa_sha2_256s);
33*e7be843bSPierre Pronchery         CASE_OID(NID_SLH_DSA_SHA2_256f, id_slh_dsa_sha2_256f);
34*e7be843bSPierre Pronchery         CASE_OID(NID_SLH_DSA_SHAKE_128s, id_slh_dsa_shake_128s);
35*e7be843bSPierre Pronchery         CASE_OID(NID_SLH_DSA_SHAKE_128f, id_slh_dsa_shake_128f);
36*e7be843bSPierre Pronchery         CASE_OID(NID_SLH_DSA_SHAKE_192s, id_slh_dsa_shake_192s);
37*e7be843bSPierre Pronchery         CASE_OID(NID_SLH_DSA_SHAKE_192f, id_slh_dsa_shake_192f);
38*e7be843bSPierre Pronchery         CASE_OID(NID_SLH_DSA_SHAKE_256s, id_slh_dsa_shake_256s);
39*e7be843bSPierre Pronchery         CASE_OID(NID_SLH_DSA_SHAKE_256f, id_slh_dsa_shake_256f);
40*e7be843bSPierre Pronchery         default:
41*e7be843bSPierre Pronchery             return 0;
42*e7be843bSPierre Pronchery     }
43*e7be843bSPierre Pronchery     return ossl_DER_w_begin_sequence(pkt, tag)
44*e7be843bSPierre Pronchery         /* No parameters */
45*e7be843bSPierre Pronchery         && ossl_DER_w_precompiled(pkt, -1, alg, len)
46*e7be843bSPierre Pronchery         && ossl_DER_w_end_sequence(pkt, tag);
47*e7be843bSPierre Pronchery }
48