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/osdep.h"
26 #include "qemu/host-utils.h"
27 #include "crypto/akcipher.h"
29 typedef struct QCryptoAkCipherRSAKey QCryptoAkCipherRSAKey
;
30 typedef struct QCryptoAkCipherMPI QCryptoAkCipherMPI
;
33 * Multiple precious integer, encoded as two' complement,
34 * copied directly from DER encoded ASN.1 structures.
36 struct QCryptoAkCipherMPI
{
41 /* See rfc2437: https://datatracker.ietf.org/doc/html/rfc2437 */
42 struct QCryptoAkCipherRSAKey
{
45 /* The public exponent */
47 /* The private exponent */
49 /* The first factor */
51 /* The second factor */
53 /* The first factor's exponent */
54 QCryptoAkCipherMPI dp
;
55 /* The second factor's exponent */
56 QCryptoAkCipherMPI dq
;
57 /* The CRT coefficient */
62 * Parse DER encoded ASN.1 RSA keys, expected ASN.1 schemas:
63 * RsaPrivKey ::= SEQUENCE {
73 * otherPrimeInfos OtherPrimeInfos OPTIONAL
76 * RsaPubKey ::= SEQUENCE {
81 * Returns: On success QCryptoAkCipherRSAKey is returned, otherwise returns NULL
83 QCryptoAkCipherRSAKey
*qcrypto_akcipher_rsakey_parse(
84 QCryptoAkCipherKeyType type
,
85 const uint8_t *key
, size_t keylen
, Error
**errp
);
87 void qcrypto_akcipher_rsakey_free(QCryptoAkCipherRSAKey
*key
);
89 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoAkCipherRSAKey
,
90 qcrypto_akcipher_rsakey_free
);