]> git.ipfire.org Git - thirdparty/openssl.git/blob - providers/common/der/der_ec.c.in
PROV: Add DERlib support for ECDSA and EC keys
[thirdparty/openssl.git] / providers / common / der / der_ec.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_ec.h"
13
14 /* Well known OIDs precompiled */
15 {-
16 $OUT = oids_to_c::process_leaves('providers/common/der/EC.asn1',
17 { dir => $config{sourcedir},
18 filter => \&oids_to_c::filter_to_C });
19 -}
20
21 int DER_w_algorithmIdentifier_EC(WPACKET *pkt, int cont, EC_KEY *ec)
22 {
23 return DER_w_begin_sequence(pkt, cont)
24 /* No parameters (yet?) */
25 && DER_w_precompiled(pkt, -1, der_oid_id_ecPublicKey,
26 sizeof(der_oid_id_ecPublicKey))
27 && DER_w_end_sequence(pkt, cont);
28 }
29
30 /* Aliases so we can have a uniform MD_CASE */
31 #define der_oid_id_ecdsa_with_sha1 der_oid_ecdsa_with_SHA1
32 #define der_oid_id_ecdsa_with_sha224 der_oid_ecdsa_with_SHA224
33 #define der_oid_id_ecdsa_with_sha256 der_oid_ecdsa_with_SHA256
34 #define der_oid_id_ecdsa_with_sha384 der_oid_ecdsa_with_SHA384
35 #define der_oid_id_ecdsa_with_sha512 der_oid_ecdsa_with_SHA512
36
37 #define MD_CASE(name) \
38 case NID_##name: \
39 precompiled = der_oid_id_ecdsa_with_##name; \
40 precompiled_sz = sizeof(der_oid_id_ecdsa_with_##name); \
41 break;
42
43 int DER_w_algorithmIdentifier_ECDSA_with(WPACKET *pkt, int cont,
44 EC_KEY *ec, int mdnid)
45 {
46 const unsigned char *precompiled = NULL;
47 size_t precompiled_sz = 0;
48
49 switch (mdnid) {
50 MD_CASE(sha1);
51 MD_CASE(sha224);
52 MD_CASE(sha256);
53 MD_CASE(sha384);
54 MD_CASE(sha512);
55 MD_CASE(sha3_224);
56 MD_CASE(sha3_256);
57 MD_CASE(sha3_384);
58 MD_CASE(sha3_512);
59 default:
60 return 0;
61 }
62
63 return DER_w_begin_sequence(pkt, cont)
64 /* No parameters (yet?) */
65 && DER_w_precompiled(pkt, -1, precompiled, precompiled_sz)
66 && DER_w_end_sequence(pkt, cont);
67 }