2 * QEMU Crypto RSA key parser
4 * Copyright (c) 2022 Bytedance
5 * Author: lei he <helei.sig11@bytedance.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #ifndef QCRYPTO_RSAKEY_H
23 #define QCRYPTO_RSAKEY_H
25 #include "qemu/host-utils.h"
26 #include "crypto/akcipher.h"
28 typedef struct QCryptoAkCipherRSAKey QCryptoAkCipherRSAKey
;
29 typedef struct QCryptoAkCipherMPI QCryptoAkCipherMPI
;
32 * Multiple precious integer, encoded as two' complement,
33 * copied directly from DER encoded ASN.1 structures.
35 struct QCryptoAkCipherMPI
{
40 /* See rfc2437: https://datatracker.ietf.org/doc/html/rfc2437 */
41 struct QCryptoAkCipherRSAKey
{
44 /* The public exponent */
46 /* The private exponent */
48 /* The first factor */
50 /* The second factor */
52 /* The first factor's exponent */
53 QCryptoAkCipherMPI dp
;
54 /* The second factor's exponent */
55 QCryptoAkCipherMPI dq
;
56 /* The CRT coefficient */
61 * Parse DER encoded ASN.1 RSA keys, expected ASN.1 schemas:
62 * RsaPrivKey ::= SEQUENCE {
72 * otherPrimeInfos OtherPrimeInfos OPTIONAL
75 * RsaPubKey ::= SEQUENCE {
80 * Returns: On success QCryptoAkCipherRSAKey is returned, otherwise returns NULL
82 QCryptoAkCipherRSAKey
*qcrypto_akcipher_rsakey_parse(
83 QCryptoAkCipherKeyType type
,
84 const uint8_t *key
, size_t keylen
, Error
**errp
);
87 * qcrypto_akcipher_rsakey_export_as_p8info:
89 * Export RSA private key to PKCS#8 private key info.
91 void qcrypto_akcipher_rsakey_export_p8info(const uint8_t *key
,
96 void qcrypto_akcipher_rsakey_free(QCryptoAkCipherRSAKey
*key
);
98 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoAkCipherRSAKey
,
99 qcrypto_akcipher_rsakey_free
);