xref: /freebsd/crypto/openssl/providers/common/der/der_slh_dsa_key.c (revision e7be843b4a162e68651d3911f0357ed464915629)
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 #include <openssl/obj_mac.h>
11 #include <openssl/objects.h>
12 #include "internal/packet.h"
13 #include "prov/der_slh_dsa.h"
14 
15 #define CASE_OID(nid, name)                  \
16     case nid:                                \
17         alg = ossl_der_oid_##name;           \
18         len = sizeof(ossl_der_oid_##name);   \
19         break
20 
ossl_DER_w_algorithmIdentifier_SLH_DSA(WPACKET * pkt,int tag,SLH_DSA_KEY * key)21 int ossl_DER_w_algorithmIdentifier_SLH_DSA(WPACKET *pkt, int tag, SLH_DSA_KEY *key)
22 {
23     const uint8_t *alg;
24     size_t len;
25     int nid = ossl_slh_dsa_key_get_type(key);
26 
27     switch (nid) {
28         CASE_OID(NID_SLH_DSA_SHA2_128s, id_slh_dsa_sha2_128s);
29         CASE_OID(NID_SLH_DSA_SHA2_128f, id_slh_dsa_sha2_128f);
30         CASE_OID(NID_SLH_DSA_SHA2_192s, id_slh_dsa_sha2_192s);
31         CASE_OID(NID_SLH_DSA_SHA2_192f, id_slh_dsa_sha2_192f);
32         CASE_OID(NID_SLH_DSA_SHA2_256s, id_slh_dsa_sha2_256s);
33         CASE_OID(NID_SLH_DSA_SHA2_256f, id_slh_dsa_sha2_256f);
34         CASE_OID(NID_SLH_DSA_SHAKE_128s, id_slh_dsa_shake_128s);
35         CASE_OID(NID_SLH_DSA_SHAKE_128f, id_slh_dsa_shake_128f);
36         CASE_OID(NID_SLH_DSA_SHAKE_192s, id_slh_dsa_shake_192s);
37         CASE_OID(NID_SLH_DSA_SHAKE_192f, id_slh_dsa_shake_192f);
38         CASE_OID(NID_SLH_DSA_SHAKE_256s, id_slh_dsa_shake_256s);
39         CASE_OID(NID_SLH_DSA_SHAKE_256f, id_slh_dsa_shake_256f);
40         default:
41             return 0;
42     }
43     return ossl_DER_w_begin_sequence(pkt, tag)
44         /* No parameters */
45         && ossl_DER_w_precompiled(pkt, -1, alg, len)
46         && ossl_DER_w_end_sequence(pkt, tag);
47 }
48