1 /*
2 * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (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.h>
11
12 #include "../internal.h"
13
14
15 typedef struct {
16 int sign_nid;
17 int digest_nid;
18 int pkey_nid;
19 } nid_triple;
20
21 static const nid_triple kTriples[] = {
22 // RSA PKCS#1.
23 {NID_md4WithRSAEncryption, NID_md4, NID_rsaEncryption},
24 {NID_md5WithRSAEncryption, NID_md5, NID_rsaEncryption},
25 {NID_sha1WithRSAEncryption, NID_sha1, NID_rsaEncryption},
26 {NID_sha224WithRSAEncryption, NID_sha224, NID_rsaEncryption},
27 {NID_sha256WithRSAEncryption, NID_sha256, NID_rsaEncryption},
28 {NID_sha384WithRSAEncryption, NID_sha384, NID_rsaEncryption},
29 {NID_sha512WithRSAEncryption, NID_sha512, NID_rsaEncryption},
30 // DSA.
31 {NID_dsaWithSHA1, NID_sha1, NID_dsa},
32 {NID_dsaWithSHA1_2, NID_sha1, NID_dsa_2},
33 {NID_dsa_with_SHA224, NID_sha224, NID_dsa},
34 {NID_dsa_with_SHA256, NID_sha256, NID_dsa},
35 // ECDSA.
36 {NID_ecdsa_with_SHA1, NID_sha1, NID_X9_62_id_ecPublicKey},
37 {NID_ecdsa_with_SHA224, NID_sha224, NID_X9_62_id_ecPublicKey},
38 {NID_ecdsa_with_SHA256, NID_sha256, NID_X9_62_id_ecPublicKey},
39 {NID_ecdsa_with_SHA384, NID_sha384, NID_X9_62_id_ecPublicKey},
40 {NID_ecdsa_with_SHA512, NID_sha512, NID_X9_62_id_ecPublicKey},
41 // The following algorithms use more complex (or simpler) parameters. The
42 // digest "undef" indicates the caller should handle this explicitly.
43 {NID_rsassaPss, NID_undef, NID_rsaEncryption},
44 {NID_ED25519, NID_undef, NID_ED25519},
45 };
46
OBJ_find_sigid_algs(int sign_nid,int * out_digest_nid,int * out_pkey_nid)47 int OBJ_find_sigid_algs(int sign_nid, int *out_digest_nid, int *out_pkey_nid) {
48 for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kTriples); i++) {
49 if (kTriples[i].sign_nid == sign_nid) {
50 if (out_digest_nid != NULL) {
51 *out_digest_nid = kTriples[i].digest_nid;
52 }
53 if (out_pkey_nid != NULL) {
54 *out_pkey_nid = kTriples[i].pkey_nid;
55 }
56 return 1;
57 }
58 }
59
60 return 0;
61 }
62
OBJ_find_sigid_by_algs(int * out_sign_nid,int digest_nid,int pkey_nid)63 int OBJ_find_sigid_by_algs(int *out_sign_nid, int digest_nid, int pkey_nid) {
64 for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kTriples); i++) {
65 if (kTriples[i].digest_nid == digest_nid &&
66 kTriples[i].pkey_nid == pkey_nid) {
67 if (out_sign_nid != NULL) {
68 *out_sign_nid = kTriples[i].sign_nid;
69 }
70 return 1;
71 }
72 }
73
74 return 0;
75 }
76