1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 3 #ifndef CIPHERAPI_H 4 # define CIPHERAPI_H 5 6 #include <linux/version.h> 7 8 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0)) 9 # include <linux/crypto.h> 10 11 typedef struct crypto_ablkcipher cryptodev_crypto_blkcipher_t; 12 typedef struct ablkcipher_request cryptodev_blkcipher_request_t; 13 14 # define cryptodev_crypto_alloc_blkcipher crypto_alloc_ablkcipher 15 # define cryptodev_crypto_blkcipher_blocksize crypto_ablkcipher_blocksize 16 # define cryptodev_crypto_blkcipher_ivsize crypto_ablkcipher_ivsize 17 # define cryptodev_crypto_blkcipher_alignmask crypto_ablkcipher_alignmask 18 # define cryptodev_crypto_blkcipher_setkey crypto_ablkcipher_setkey 19 cryptodev_crypto_free_blkcipher(cryptodev_crypto_blkcipher_t * c)20static inline void cryptodev_crypto_free_blkcipher(cryptodev_crypto_blkcipher_t *c) { 21 if (c) 22 crypto_free_ablkcipher(c); 23 } 24 25 # define cryptodev_blkcipher_request_alloc ablkcipher_request_alloc 26 # define cryptodev_blkcipher_request_set_callback ablkcipher_request_set_callback 27 cryptodev_blkcipher_request_free(cryptodev_blkcipher_request_t * r)28static inline void cryptodev_blkcipher_request_free(cryptodev_blkcipher_request_t *r) { 29 if (r) 30 ablkcipher_request_free(r); 31 } 32 33 # define cryptodev_blkcipher_request_set_crypt ablkcipher_request_set_crypt 34 # define cryptodev_crypto_blkcipher_encrypt crypto_ablkcipher_encrypt 35 # define cryptodev_crypto_blkcipher_decrypt crypto_ablkcipher_decrypt 36 # define cryptodev_crypto_blkcipher_tfm crypto_ablkcipher_tfm 37 #else 38 #include <crypto/skcipher.h> 39 40 typedef struct crypto_skcipher cryptodev_crypto_blkcipher_t; 41 typedef struct skcipher_request cryptodev_blkcipher_request_t; 42 43 # define cryptodev_crypto_alloc_blkcipher crypto_alloc_skcipher 44 # define cryptodev_crypto_blkcipher_blocksize crypto_skcipher_blocksize 45 # define cryptodev_crypto_blkcipher_ivsize crypto_skcipher_ivsize 46 # define cryptodev_crypto_blkcipher_alignmask crypto_skcipher_alignmask 47 # define cryptodev_crypto_blkcipher_setkey crypto_skcipher_setkey 48 # define cryptodev_crypto_free_blkcipher crypto_free_skcipher 49 # define cryptodev_blkcipher_request_alloc skcipher_request_alloc 50 # define cryptodev_blkcipher_request_set_callback skcipher_request_set_callback 51 # define cryptodev_blkcipher_request_free skcipher_request_free 52 # define cryptodev_blkcipher_request_set_crypt skcipher_request_set_crypt 53 # define cryptodev_crypto_blkcipher_encrypt crypto_skcipher_encrypt 54 # define cryptodev_crypto_blkcipher_decrypt crypto_skcipher_decrypt 55 # define cryptodev_crypto_blkcipher_tfm crypto_skcipher_tfm 56 #endif 57 58 #endif 59