2 * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
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
12 #include <openssl/objects.h>
13 #include "crypto/ec.h"
15 #define ASN1_SEQUENCE 0x30
17 #define OID_FIRST(a, b) a * 40 + b
18 #define DER_840() 0x86, 0x48 /* DER encoding of number 840 is 2 bytes */
19 #define DER_10045() 0xCE, 0x3D /* DER encoding of number 10045 is 2 bytes */
26 * ansi-X9-62 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) 10045 }
27 * id-ecSigType OBJECT IDENTIFIER ::= { ansi-X9-62 signatures(4) }
29 * ecdsa-with-SHA1 OBJECT IDENTIFIER ::= { id-ecSigType 1 }
31 #define ENCODE_ALGORITHMIDENTIFIER_SHA1(name) \
32 static const unsigned char algorithmidentifier_##name##_der[] = { \
33 ASN1_SEQUENCE, 2 + SHA1_SZ, \
34 ASN1_OID, SHA1_SZ, OID_FIRST(1, 2), DER_840(), DER_10045(), 4, 1 \
40 * ecdsa-with-SHA224 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
41 * us(840) ansi-X9-62(10045) signatures(4) ecdsa-with-SHA2(3) 1 }
43 * ecdsa-with-SHA256 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
44 * us(840) ansi-X9-62(10045) signatures(4) ecdsa-with-SHA2(3) 2 }
46 * ecdsa-with-SHA384 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
47 * us(840) ansi-X9-62(10045) signatures(4) ecdsa-with-SHA2(3) 3 }
49 * ecdsa-with-SHA512 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
50 * us(840) ansi-X9-62(10045) signatures(4) ecdsa-with-SHA2(3) 4 }
52 #define ENCODE_ALGORITHMIDENTIFIER_SHA2(name, n) \
53 static const unsigned char algorithmidentifier_##name##_der[] = { \
54 ASN1_SEQUENCE, 2 + SHA2_SZ, \
55 ASN1_OID, SHA2_SZ, OID_FIRST(1, 2), DER_840(), DER_10045(), 4, 3, n \
59 * https://csrc.nist.gov/projects/computer-security-objects-register/algorithm-registration
61 * sigAlgs OBJECT IDENTIFIER ::= { 2 16 840 1 101 3 4 3 }
63 * id-ecdsa-with-sha3-224 ::= { sigAlgs 9 }
64 * id-ecdsa-with-sha3-256 ::= { sigAlgs 10 }
65 * id-ecdsa-with-sha3-384 ::= { sigAlgs 11 }
66 * id-ecdsa-with-sha3-512 ::= { sigAlgs 12 }
68 #define ENCODE_ALGORITHMIDENTIFIER_SHA3(name, n) \
69 static const unsigned char algorithmidentifier_##name##_der[] = { \
70 ASN1_SEQUENCE, 2 + SHA3_SZ, \
71 ASN1_OID, SHA3_SZ, OID_FIRST(2, 16), DER_840(), 1, 101, 3, 4, 3, n \
74 ENCODE_ALGORITHMIDENTIFIER_SHA1(sha1);
75 ENCODE_ALGORITHMIDENTIFIER_SHA2(sha224, 1);
76 ENCODE_ALGORITHMIDENTIFIER_SHA2(sha256, 2);
77 ENCODE_ALGORITHMIDENTIFIER_SHA2(sha384, 3);
78 ENCODE_ALGORITHMIDENTIFIER_SHA2(sha512, 4);
79 ENCODE_ALGORITHMIDENTIFIER_SHA3(sha3_224, 9);
80 ENCODE_ALGORITHMIDENTIFIER_SHA3(sha3_256, 10);
81 ENCODE_ALGORITHMIDENTIFIER_SHA3(sha3_384, 11);
82 ENCODE_ALGORITHMIDENTIFIER_SHA3(sha3_512, 12);
83 /* TODO - Add SHAKE OIDS when they are standardized */
85 #define MD_CASE(name) \
87 *len = sizeof(algorithmidentifier_##name##_der); \
88 return algorithmidentifier_##name##_der
90 const unsigned char *ecdsa_algorithmidentifier_encoding(int md_nid, size_t *len)