PROV: Add DERlib support for RSA
[openssl.git] / crypto / dsa / dsa_aid.c
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 <stdlib.h>
11
12 #include <openssl/objects.h>
13 #include "crypto/dsa.h"
14
15 #define ASN1_SEQUENCE 0x30
16 #define ASN1_OID 0x06
17
18 /*
19  * id-dsa-with-sha1 OBJECT IDENTIFIER ::=  {
20  *     iso(1) member-body(2) us(840) x9-57(10040) x9cm(4) 3
21  * }
22  */
23 #define ENCODE_ALGORITHMIDENTIFIER_RFC3279(name, n)                     \
24     static const unsigned char algorithmidentifier_##name##_der[] = {   \
25         ASN1_SEQUENCE, 0x09,                                            \
26           ASN1_OID, 0x07, 1 * 40 + 2, 134, 72, 206, 56, 4, n            \
27 }
28
29 ENCODE_ALGORITHMIDENTIFIER_RFC3279(sha1, 3);
30
31 /*
32  * dsaWithSHAx OIDs are of the form: (sigAlgs |n|)
33  * where sigAlgs OBJECT IDENTIFIER ::= { 2 16 840 1 101 3 4 3 }
34  */
35 #define ENCODE_ALGORITHMIDENTIFIER_SIGALGS(name, n)                     \
36     static const unsigned char algorithmidentifier_##name##_der[] = {   \
37         ASN1_SEQUENCE, 0x0b,                                            \
38           ASN1_OID, 0x09, 2 * 40 + 16, 0x86, 0x48, 1, 101, 3, 4, 3, n   \
39 }
40
41 ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha224, 1);
42 ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha256, 2);
43 ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha384, 3);
44 ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha512, 4);
45 ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_224, 5);
46 ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_256, 6);
47 ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_384, 7);
48 ENCODE_ALGORITHMIDENTIFIER_SIGALGS(sha3_512, 8);
49
50 #define MD_CASE(name)                                                   \
51     case NID_##name:                                                    \
52         *len = sizeof(algorithmidentifier_##name##_der);                \
53         return algorithmidentifier_##name##_der
54
55 const unsigned char *dsa_algorithmidentifier_encoding(int md_nid, size_t *len)
56 {
57     switch (md_nid) {
58         MD_CASE(sha1);
59         MD_CASE(sha224);
60         MD_CASE(sha256);
61         MD_CASE(sha384);
62         MD_CASE(sha512);
63         MD_CASE(sha3_224);
64         MD_CASE(sha3_256);
65         MD_CASE(sha3_384);
66         MD_CASE(sha3_512);
67     default:
68         return NULL;
69     }
70 }