1 | /** @file
|
---|
2 | * IPRT - Crypto - RSA Public Key Cryptosystem .
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * The contents of this file may alternatively be used under the terms
|
---|
25 | * of the Common Development and Distribution License Version 1.0
|
---|
26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
28 | * CDDL are applicable instead of those of the GPL.
|
---|
29 | *
|
---|
30 | * You may elect to license modified versions of this file under the
|
---|
31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | *
|
---|
33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef IPRT_INCLUDED_crypto_rsa_h
|
---|
37 | #define IPRT_INCLUDED_crypto_rsa_h
|
---|
38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
39 | # pragma once
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <iprt/asn1.h>
|
---|
43 | #include <iprt/crypto/x509.h>
|
---|
44 | #include <iprt/crypto/pkcs7.h>
|
---|
45 | #include <iprt/md5.h>
|
---|
46 | #include <iprt/sha.h>
|
---|
47 |
|
---|
48 |
|
---|
49 | RT_C_DECLS_BEGIN
|
---|
50 |
|
---|
51 | /** @defgroup grp_rt_cr_rsa RTCrRsa - RSA Public Key Cryptosystem
|
---|
52 | * @ingroup grp_rt_crypto
|
---|
53 | * @{
|
---|
54 | */
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * RSA public key - ASN.1 IPRT representation.
|
---|
58 | */
|
---|
59 | typedef struct RTCRRSAPUBLICKEY
|
---|
60 | {
|
---|
61 | /** Sequence core for the structure. */
|
---|
62 | RTASN1SEQUENCECORE SeqCore;
|
---|
63 | /** The modulus (n). */
|
---|
64 | RTASN1INTEGER Modulus;
|
---|
65 | /** The public exponent (e). */
|
---|
66 | RTASN1INTEGER PublicExponent;
|
---|
67 | } RTCRRSAPUBLICKEY;
|
---|
68 | /** Pointer to the ASN.1 IPRT representation of an RSA public key. */
|
---|
69 | typedef RTCRRSAPUBLICKEY *PRTCRRSAPUBLICKEY;
|
---|
70 | /** Pointer to the const ASN.1 IPRT representation of an RSA public key. */
|
---|
71 | typedef RTCRRSAPUBLICKEY const *PCRTCRRSAPUBLICKEY;
|
---|
72 | RTASN1TYPE_STANDARD_PROTOTYPES(RTCRRSAPUBLICKEY, RTDECL, RTCrRsaPublicKey, SeqCore.Asn1Core);
|
---|
73 |
|
---|
74 | RTDECL(bool) RTCrRsaPublicKey_CanHandleDigestType(PCRTCRRSAPUBLICKEY pRsaPublicKey, RTDIGESTTYPE enmDigestType,
|
---|
75 | PRTERRINFO pErrInfo);
|
---|
76 |
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * RSA other prime info (ASN.1 IPRT representation).
|
---|
80 | */
|
---|
81 | typedef struct RTCRRSAOTHERPRIMEINFO
|
---|
82 | {
|
---|
83 | /** Sequence core for the structure. */
|
---|
84 | RTASN1SEQUENCECORE SeqCore;
|
---|
85 | /** The prime (ri). */
|
---|
86 | RTASN1INTEGER Prime;
|
---|
87 | /** The exponent (di). */
|
---|
88 | RTASN1INTEGER Exponent;
|
---|
89 | /** The coefficient (ti). */
|
---|
90 | RTASN1INTEGER Coefficient;
|
---|
91 | } RTCRRSAOTHERPRIMEINFO;
|
---|
92 | /** Pointer to the ASN.1 IPRT representation of RSA other prime info. */
|
---|
93 | typedef RTCRRSAOTHERPRIMEINFO *PRTCRRSAOTHERPRIMEINFO;
|
---|
94 | /** Pointer to the const ASN.1 IPRT representation of RSA other prime info. */
|
---|
95 | typedef RTCRRSAOTHERPRIMEINFO const *PCRTCRRSAOTHERPRIMEINFO;
|
---|
96 | RTASN1TYPE_STANDARD_PROTOTYPES(RTCRRSAOTHERPRIMEINFO, RTDECL, RTCrRsaOtherPrimeInfo, SeqCore.Asn1Core);
|
---|
97 | RTASN1_IMPL_GEN_SEQ_OF_TYPEDEFS_AND_PROTOS(RTCRRSAOTHERPRIMEINFOS, RTCRRSAOTHERPRIMEINFO, RTDECL, RTCrRsaOtherPrimeInfos);
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * RSA private key - ASN.1 IPRT representation.
|
---|
101 | */
|
---|
102 | typedef struct RTCRRSAPRIVATEKEY
|
---|
103 | {
|
---|
104 | /** Sequence core for the structure. */
|
---|
105 | RTASN1SEQUENCECORE SeqCore;
|
---|
106 | /** Key version number. */
|
---|
107 | RTASN1INTEGER Version;
|
---|
108 | /** The modulus (n). */
|
---|
109 | RTASN1INTEGER Modulus;
|
---|
110 | /** The public exponent (e). */
|
---|
111 | RTASN1INTEGER PublicExponent;
|
---|
112 | /** The private exponent (d). */
|
---|
113 | RTASN1INTEGER PrivateExponent;
|
---|
114 | /** The first prime factor (p) of the modulus (n). */
|
---|
115 | RTASN1INTEGER Prime1;
|
---|
116 | /** The second prime factor (q) of the modulus (n). */
|
---|
117 | RTASN1INTEGER Prime2;
|
---|
118 | /** The first exponent (d mod (p-1)). */
|
---|
119 | RTASN1INTEGER Exponent1;
|
---|
120 | /** The second exponent (d mod (q-1)). */
|
---|
121 | RTASN1INTEGER Exponent2;
|
---|
122 | /** The coefficient ((inverse of q) mod p). */
|
---|
123 | RTASN1INTEGER Coefficient;
|
---|
124 | /** Optional other prime information (version must be 'multi' if present). */
|
---|
125 | RTCRRSAOTHERPRIMEINFOS OtherPrimeInfos;
|
---|
126 | } RTCRRSAPRIVATEKEY;
|
---|
127 | /** Pointer to the ASN.1 IPRT representation of an RSA private key. */
|
---|
128 | typedef RTCRRSAPRIVATEKEY *PRTCRRSAPRIVATEKEY;
|
---|
129 | /** Pointer to the const ASN.1 IPRT representation of an RSA private key. */
|
---|
130 | typedef RTCRRSAPRIVATEKEY const *PCRTCRRSAPRIVATEKEY;
|
---|
131 | RTASN1TYPE_STANDARD_PROTOTYPES(RTCRRSAPRIVATEKEY, RTDECL, RTCrRsaPrivateKey, SeqCore.Asn1Core);
|
---|
132 |
|
---|
133 | /** @name RSA Private Key Versions
|
---|
134 | * @{ */
|
---|
135 | #define RTCRRSAPRIVATEKEY_VERSION_TWO_PRIME 0
|
---|
136 | #define RTCRRSAPRIVATEKEY_VERSION_MULTI 1
|
---|
137 | /** @} */
|
---|
138 |
|
---|
139 | RTDECL(bool) RTCrRsaPrivateKey_CanHandleDigestType(PCRTCRRSAPRIVATEKEY pRsaPrivateKey, RTDIGESTTYPE enmDigestType,
|
---|
140 | PRTERRINFO pErrInfo);
|
---|
141 |
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * RSA DigestInfo used by the EMSA-PKCS1-v1_5 encoding method.
|
---|
145 | */
|
---|
146 | typedef struct RTCRRSADIGESTINFO
|
---|
147 | {
|
---|
148 | /** Sequence core for the structure. */
|
---|
149 | RTASN1SEQUENCECORE SeqCore;
|
---|
150 | /** The digest algorithm. */
|
---|
151 | RTCRX509ALGORITHMIDENTIFIER DigestAlgorithm;
|
---|
152 | /** The digest. */
|
---|
153 | RTASN1OCTETSTRING Digest;
|
---|
154 | } RTCRRSADIGESTINFO;
|
---|
155 | /** Pointer to the ASN.1 IPRT representation of RSA digest info. */
|
---|
156 | typedef RTCRRSADIGESTINFO *PRTCRRSADIGESTINFO;
|
---|
157 | /** Pointer to the const ASN.1 IPRT representation of RSA digest info. */
|
---|
158 | typedef RTCRRSADIGESTINFO const *PCRTCRRSADIGESTINFO;
|
---|
159 | RTASN1TYPE_STANDARD_PROTOTYPES(RTCRRSADIGESTINFO, RTDECL, RTCrRsaDigestInfo, SeqCore.Asn1Core);
|
---|
160 |
|
---|
161 | /** @} */
|
---|
162 |
|
---|
163 | RT_C_DECLS_END
|
---|
164 |
|
---|
165 | #endif /* !IPRT_INCLUDED_crypto_rsa_h */
|
---|
166 |
|
---|