PROV: Add DERlib support for ECDSA and EC keys
[openssl.git] / providers / common / der / der_dsa.c.in
1 /*
2  * Copyright 2020 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/bn.h>
11 #include <openssl/obj_mac.h>
12 #include "prov/der_dsa.h"
13
14 /* Well known OIDs precompiled */
15 {-
16     $OUT = oids_to_c::process_leaves('providers/common/der/DSA.asn1',
17                                      { dir => $config{sourcedir},
18                                        filter => \&oids_to_c::filter_to_C });
19 -}
20
21 int DER_w_algorithmIdentifier_DSA(WPACKET *pkt, int tag, DSA *dsa)
22 {
23     return DER_w_begin_sequence(pkt, tag)
24         /* No parameters (yet?) */
25         && DER_w_precompiled(pkt, -1, der_oid_id_dsa, sizeof(der_oid_id_dsa))
26         && DER_w_end_sequence(pkt, tag);
27 }
28
29 #define MD_CASE(name)                                                   \
30     case NID_##name:                                                    \
31         precompiled = der_oid_id_dsa_with_##name;                \
32         precompiled_sz = sizeof(der_oid_id_dsa_with_##name);     \
33         break;
34
35 int DER_w_algorithmIdentifier_DSA_with(WPACKET *pkt, int tag,
36                                        DSA *dsa, int mdnid)
37 {
38     const unsigned char *precompiled = NULL;
39     size_t precompiled_sz = 0;
40
41     switch (mdnid) {
42         MD_CASE(sha1);
43         MD_CASE(sha224);
44         MD_CASE(sha256);
45         MD_CASE(sha384);
46         MD_CASE(sha512);
47         MD_CASE(sha3_224);
48         MD_CASE(sha3_256);
49         MD_CASE(sha3_384);
50         MD_CASE(sha3_512);
51     default:
52         return 0;
53     }
54
55     return DER_w_begin_sequence(pkt, tag)
56         /* No parameters (yet?) */
57         && DER_w_precompiled(pkt, -1, precompiled, precompiled_sz)
58         && DER_w_end_sequence(pkt, tag);
59 }