softmmu/runstate.c: add RunStateTransition support form COLO to PRELAUNCH
[qemu/kevin.git] / crypto / akcipher.c
blobad88379c1e7203bdd05ab6def34a022ba23b2a8a
1 /*
2 * QEMU Crypto akcipher algorithms
4 * Copyright (c) 2022 Bytedance
5 * Author: zhenwei pi <pizhenwei@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 #include "qemu/osdep.h"
23 #include "crypto/akcipher.h"
24 #include "akcipherpriv.h"
26 #if defined(CONFIG_GCRYPT)
27 #include "akcipher-gcrypt.c.inc"
28 #elif defined(CONFIG_NETTLE) && defined(CONFIG_HOGWEED)
29 #include "akcipher-nettle.c.inc"
30 #else
31 QCryptoAkCipher *qcrypto_akcipher_new(const QCryptoAkCipherOptions *opts,
32 QCryptoAkCipherKeyType type,
33 const uint8_t *key, size_t keylen,
34 Error **errp)
36 QCryptoAkCipher *akcipher = NULL;
38 return akcipher;
41 bool qcrypto_akcipher_supports(QCryptoAkCipherOptions *opts)
43 return false;
45 #endif
47 int qcrypto_akcipher_encrypt(QCryptoAkCipher *akcipher,
48 const void *in, size_t in_len,
49 void *out, size_t out_len, Error **errp)
51 const QCryptoAkCipherDriver *drv = akcipher->driver;
53 return drv->encrypt(akcipher, in, in_len, out, out_len, errp);
56 int qcrypto_akcipher_decrypt(QCryptoAkCipher *akcipher,
57 const void *in, size_t in_len,
58 void *out, size_t out_len, Error **errp)
60 const QCryptoAkCipherDriver *drv = akcipher->driver;
62 return drv->decrypt(akcipher, in, in_len, out, out_len, errp);
65 int qcrypto_akcipher_sign(QCryptoAkCipher *akcipher,
66 const void *in, size_t in_len,
67 void *out, size_t out_len, Error **errp)
69 const QCryptoAkCipherDriver *drv = akcipher->driver;
71 return drv->sign(akcipher, in, in_len, out, out_len, errp);
74 int qcrypto_akcipher_verify(QCryptoAkCipher *akcipher,
75 const void *in, size_t in_len,
76 const void *in2, size_t in2_len, Error **errp)
78 const QCryptoAkCipherDriver *drv = akcipher->driver;
80 return drv->verify(akcipher, in, in_len, in2, in2_len, errp);
83 int qcrypto_akcipher_max_plaintext_len(QCryptoAkCipher *akcipher)
85 return akcipher->max_plaintext_len;
88 int qcrypto_akcipher_max_ciphertext_len(QCryptoAkCipher *akcipher)
90 return akcipher->max_ciphertext_len;
93 int qcrypto_akcipher_max_signature_len(QCryptoAkCipher *akcipher)
95 return akcipher->max_signature_len;
98 int qcrypto_akcipher_max_dgst_len(QCryptoAkCipher *akcipher)
100 return akcipher->max_dgst_len;
103 void qcrypto_akcipher_free(QCryptoAkCipher *akcipher)
105 const QCryptoAkCipherDriver *drv = akcipher->driver;
107 drv->free(akcipher);