| 1 |
// Copyright (C) 1995-1998 Eric Young ([email protected]) All rights reserved. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
#include <openssl/obj.h> |
| 5 |
|
| 6 |
#include "../internal.h" |
| 7 |
|
| 8 |
|
| 9 |
typedef struct { |
| 10 |
int sign_nid; |
| 11 |
int digest_nid; |
| 12 |
int pkey_nid; |
| 13 |
} nid_triple; |
| 14 |
|
| 15 |
static const nid_triple kTriples[] = { |
| 16 |
// RSA PKCS#1. |
| 17 |
{NID_md4WithRSAEncryption, NID_md4, NID_rsaEncryption}, |
| 18 |
{NID_md5WithRSAEncryption, NID_md5, NID_rsaEncryption}, |
| 19 |
{NID_sha1WithRSAEncryption, NID_sha1, NID_rsaEncryption}, |
| 20 |
{NID_sha224WithRSAEncryption, NID_sha224, NID_rsaEncryption}, |
| 21 |
{NID_sha256WithRSAEncryption, NID_sha256, NID_rsaEncryption}, |
| 22 |
{NID_sha384WithRSAEncryption, NID_sha384, NID_rsaEncryption}, |
| 23 |
{NID_sha512WithRSAEncryption, NID_sha512, NID_rsaEncryption}, |
| 24 |
// RSA ITU-T X.509. These are rare and we map them to the more |
| 25 |
// common |NID_rsaEncryption| instead for simplicity. |
| 26 |
{NID_md5WithRSA, NID_md5, NID_rsaEncryption}, |
| 27 |
{NID_sha1WithRSA, NID_sha1, NID_rsaEncryption}, |
| 28 |
// DSA. |
| 29 |
{NID_dsaWithSHA1, NID_sha1, NID_dsa}, |
| 30 |
{NID_dsaWithSHA1_2, NID_sha1, NID_dsa_2}, |
| 31 |
{NID_dsa_with_SHA224, NID_sha224, NID_dsa}, |
| 32 |
{NID_dsa_with_SHA256, NID_sha256, NID_dsa}, |
| 33 |
// ECDSA. |
| 34 |
{NID_ecdsa_with_SHA1, NID_sha1, NID_X9_62_id_ecPublicKey}, |
| 35 |
{NID_ecdsa_with_SHA224, NID_sha224, NID_X9_62_id_ecPublicKey}, |
| 36 |
{NID_ecdsa_with_SHA256, NID_sha256, NID_X9_62_id_ecPublicKey}, |
| 37 |
{NID_ecdsa_with_SHA384, NID_sha384, NID_X9_62_id_ecPublicKey}, |
| 38 |
{NID_ecdsa_with_SHA512, NID_sha512, NID_X9_62_id_ecPublicKey}, |
| 39 |
// The following algorithms use more complex (or simpler) parameters. The |
| 40 |
// digest "undef" indicates the caller should handle this explicitly. |
| 41 |
{NID_rsassaPss, NID_undef, NID_rsaEncryption}, |
| 42 |
{NID_ED25519, NID_undef, NID_ED25519}, |
| 43 |
{NID_MLDSA44, NID_undef, NID_MLDSA44}, |
| 44 |
{NID_MLDSA65, NID_undef, NID_MLDSA65}, |
| 45 |
{NID_MLDSA87, NID_undef, NID_MLDSA87}, |
| 46 |
}; |
| 47 |
|
| 48 |
int OBJ_find_sigid_algs(int sign_nid, int *out_digest_nid, int *out_pkey_nid) { |
| 49 |
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kTriples); i++) { |
| 50 |
if (kTriples[i].sign_nid == sign_nid) { |
| 51 |
if (out_digest_nid != NULL) { |
| 52 |
*out_digest_nid = kTriples[i].digest_nid; |
| 53 |
} |
| 54 |
if (out_pkey_nid != NULL) { |
| 55 |
*out_pkey_nid = kTriples[i].pkey_nid; |
| 56 |
} |
| 57 |
return 1; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
return 0; |
| 62 |
} |
| 63 |
|
| 64 |
int OBJ_find_sigid_by_algs(int *out_sign_nid, int digest_nid, int pkey_nid) { |
| 65 |
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kTriples); i++) { |
| 66 |
if (kTriples[i].digest_nid == digest_nid && |
| 67 |
kTriples[i].pkey_nid == pkey_nid) { |
| 68 |
if (out_sign_nid != NULL) { |
| 69 |
*out_sign_nid = kTriples[i].sign_nid; |
| 70 |
} |
| 71 |
return 1; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
return 0; |
| 76 |
} |