Coverage Report

Created: 2026-02-16 07:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/boringssl/crypto/obj/obj_xref.cc
Line
Count
Source
1
// Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include <openssl/obj.h>
16
17
#include "../internal.h"
18
19
20
typedef struct {
21
  int sign_nid;
22
  int digest_nid;
23
  int pkey_nid;
24
} nid_triple;
25
26
static const nid_triple kTriples[] = {
27
    // RSA PKCS#1.
28
    {NID_md4WithRSAEncryption, NID_md4, NID_rsaEncryption},
29
    {NID_md5WithRSAEncryption, NID_md5, NID_rsaEncryption},
30
    {NID_sha1WithRSAEncryption, NID_sha1, NID_rsaEncryption},
31
    {NID_sha224WithRSAEncryption, NID_sha224, NID_rsaEncryption},
32
    {NID_sha256WithRSAEncryption, NID_sha256, NID_rsaEncryption},
33
    {NID_sha384WithRSAEncryption, NID_sha384, NID_rsaEncryption},
34
    {NID_sha512WithRSAEncryption, NID_sha512, NID_rsaEncryption},
35
    // DSA.
36
    {NID_dsaWithSHA1, NID_sha1, NID_dsa},
37
    {NID_dsaWithSHA1_2, NID_sha1, NID_dsa_2},
38
    {NID_dsa_with_SHA224, NID_sha224, NID_dsa},
39
    {NID_dsa_with_SHA256, NID_sha256, NID_dsa},
40
    // ECDSA.
41
    {NID_ecdsa_with_SHA1, NID_sha1, NID_X9_62_id_ecPublicKey},
42
    {NID_ecdsa_with_SHA224, NID_sha224, NID_X9_62_id_ecPublicKey},
43
    {NID_ecdsa_with_SHA256, NID_sha256, NID_X9_62_id_ecPublicKey},
44
    {NID_ecdsa_with_SHA384, NID_sha384, NID_X9_62_id_ecPublicKey},
45
    {NID_ecdsa_with_SHA512, NID_sha512, NID_X9_62_id_ecPublicKey},
46
    // The following algorithms use more complex (or simpler) parameters. The
47
    // digest "undef" indicates the caller should handle this explicitly.
48
    {NID_rsassaPss, NID_undef, NID_rsaEncryption},
49
    {NID_ED25519, NID_undef, NID_ED25519},
50
    {NID_ML_DSA_44, NID_undef, NID_ML_DSA_44},
51
    {NID_ML_DSA_65, NID_undef, NID_ML_DSA_65},
52
    {NID_ML_DSA_87, NID_undef, NID_ML_DSA_87},
53
};
54
55
0
int OBJ_find_sigid_algs(int sign_nid, int *out_digest_nid, int *out_pkey_nid) {
56
0
  for (const auto &triple : kTriples) {
57
0
    if (triple.sign_nid == sign_nid) {
58
0
      if (out_digest_nid != nullptr) {
59
0
        *out_digest_nid = triple.digest_nid;
60
0
      }
61
0
      if (out_pkey_nid != nullptr) {
62
0
        *out_pkey_nid = triple.pkey_nid;
63
0
      }
64
0
      return 1;
65
0
    }
66
0
  }
67
68
0
  return 0;
69
0
}
70
71
0
int OBJ_find_sigid_by_algs(int *out_sign_nid, int digest_nid, int pkey_nid) {
72
0
  for (const auto &triple : kTriples) {
73
0
    if (triple.digest_nid == digest_nid &&
74
0
        triple.pkey_nid == pkey_nid) {
75
0
      if (out_sign_nid != nullptr) {
76
0
        *out_sign_nid = triple.sign_nid;
77
0
      }
78
0
      return 1;
79
0
    }
80
0
  }
81
82
0
  return 0;
83
0
}