Longpeng(Mike) | f0d92b5 | 2017-07-14 14:04:05 -0400 | [diff] [blame] | 1 | /* |
| 2 | * QEMU Crypto af_alg support |
| 3 | * |
| 4 | * Copyright (c) 2017 HUAWEI TECHNOLOGIES CO., LTD. |
| 5 | * |
| 6 | * Authors: |
| 7 | * Longpeng(Mike) <longpeng2@huawei.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2 or |
| 10 | * (at your option) any later version. See the COPYING file in the |
| 11 | * top-level directory. |
| 12 | */ |
| 13 | |
| 14 | #ifndef QCRYPTO_AFALGPRIV_H |
| 15 | #define QCRYPTO_AFALGPRIV_H |
| 16 | |
| 17 | #include <linux/if_alg.h> |
Richard Henderson | 3eedf5c | 2020-08-28 10:05:14 -0700 | [diff] [blame] | 18 | #include "crypto/cipher.h" |
Longpeng(Mike) | f0d92b5 | 2017-07-14 14:04:05 -0400 | [diff] [blame] | 19 | |
| 20 | #define SALG_TYPE_LEN_MAX 14 |
| 21 | #define SALG_NAME_LEN_MAX 64 |
| 22 | |
Longpeng(Mike) | 25c60df | 2017-07-14 14:04:06 -0400 | [diff] [blame] | 23 | #ifndef SOL_ALG |
| 24 | #define SOL_ALG 279 |
| 25 | #endif |
| 26 | |
| 27 | #define AFALG_TYPE_CIPHER "skcipher" |
Longpeng(Mike) | 9a05977 | 2017-07-14 14:04:07 -0400 | [diff] [blame] | 28 | #define AFALG_TYPE_HASH "hash" |
Longpeng(Mike) | 25c60df | 2017-07-14 14:04:06 -0400 | [diff] [blame] | 29 | |
| 30 | #define ALG_OPTYPE_LEN 4 |
| 31 | #define ALG_MSGIV_LEN(len) (sizeof(struct af_alg_iv) + (len)) |
| 32 | |
Longpeng(Mike) | f0d92b5 | 2017-07-14 14:04:05 -0400 | [diff] [blame] | 33 | typedef struct QCryptoAFAlg QCryptoAFAlg; |
| 34 | |
| 35 | struct QCryptoAFAlg { |
Richard Henderson | 3eedf5c | 2020-08-28 10:05:14 -0700 | [diff] [blame] | 36 | QCryptoCipher base; |
| 37 | |
Longpeng(Mike) | f0d92b5 | 2017-07-14 14:04:05 -0400 | [diff] [blame] | 38 | int tfmfd; |
| 39 | int opfd; |
| 40 | struct msghdr *msg; |
| 41 | struct cmsghdr *cmsg; |
| 42 | }; |
| 43 | |
| 44 | /** |
| 45 | * qcrypto_afalg_comm_alloc: |
| 46 | * @type: the type of crypto operation |
| 47 | * @name: the name of crypto operation |
| 48 | * |
| 49 | * Allocate a QCryptoAFAlg object and bind itself to |
| 50 | * a AF_ALG socket. |
| 51 | * |
| 52 | * Returns: |
| 53 | * a new QCryptoAFAlg object, or NULL in error. |
| 54 | */ |
| 55 | QCryptoAFAlg * |
| 56 | qcrypto_afalg_comm_alloc(const char *type, const char *name, |
| 57 | Error **errp); |
| 58 | |
| 59 | /** |
| 60 | * afalg_comm_free: |
| 61 | * @afalg: the QCryptoAFAlg object |
| 62 | * |
| 63 | * Free the @afalg. |
| 64 | */ |
| 65 | void qcrypto_afalg_comm_free(QCryptoAFAlg *afalg); |
| 66 | |
| 67 | #endif |