1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * Crypto engine API 4 * 5 * Copyright (c) 2016 Baolin Wang <baolin.wang@linaro.org> 6 */ 7 #ifndef _CRYPTO_ENGINE_H 8 #define _CRYPTO_ENGINE_H 9 10 #include <crypto/aead.h> 11 #include <crypto/akcipher.h> 12 #include <crypto/hash.h> 13 #include <crypto/kpp.h> 14 #include <crypto/skcipher.h> 15 #include <linux/types.h> 16 17 struct crypto_engine; 18 struct device; 19 20 /* 21 * struct crypto_engine_op - crypto hardware engine operations 22 * @do_one_request: do encryption for current request 23 */ 24 struct crypto_engine_op { 25 int (*do_one_request)(struct crypto_engine *engine, 26 void *areq); 27 }; 28 29 struct crypto_engine_ctx { 30 struct crypto_engine_op op; 31 }; 32 33 struct aead_engine_alg { 34 struct aead_alg base; 35 struct crypto_engine_op op; 36 }; 37 38 struct ahash_engine_alg { 39 struct ahash_alg base; 40 struct crypto_engine_op op; 41 }; 42 43 struct akcipher_engine_alg { 44 struct akcipher_alg base; 45 struct crypto_engine_op op; 46 }; 47 48 struct kpp_engine_alg { 49 struct kpp_alg base; 50 struct crypto_engine_op op; 51 }; 52 53 struct skcipher_engine_alg { 54 struct skcipher_alg base; 55 struct crypto_engine_op op; 56 }; 57 58 int crypto_transfer_aead_request_to_engine(struct crypto_engine *engine, 59 struct aead_request *req); 60 int crypto_transfer_akcipher_request_to_engine(struct crypto_engine *engine, 61 struct akcipher_request *req); 62 int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine, 63 struct ahash_request *req); 64 int crypto_transfer_kpp_request_to_engine(struct crypto_engine *engine, 65 struct kpp_request *req); 66 int crypto_transfer_skcipher_request_to_engine(struct crypto_engine *engine, 67 struct skcipher_request *req); 68 void crypto_finalize_aead_request(struct crypto_engine *engine, 69 struct aead_request *req, int err); 70 void crypto_finalize_akcipher_request(struct crypto_engine *engine, 71 struct akcipher_request *req, int err); 72 void crypto_finalize_hash_request(struct crypto_engine *engine, 73 struct ahash_request *req, int err); 74 void crypto_finalize_kpp_request(struct crypto_engine *engine, 75 struct kpp_request *req, int err); 76 void crypto_finalize_skcipher_request(struct crypto_engine *engine, 77 struct skcipher_request *req, int err); 78 int crypto_engine_start(struct crypto_engine *engine); 79 int crypto_engine_stop(struct crypto_engine *engine); 80 struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt); 81 struct crypto_engine *crypto_engine_alloc_init_and_set(struct device *dev, 82 bool retry_support, 83 int (*cbk_do_batch)(struct crypto_engine *engine), 84 bool rt, int qlen); 85 int crypto_engine_exit(struct crypto_engine *engine); 86 87 int crypto_engine_register_aead(struct aead_engine_alg *alg); 88 void crypto_engine_unregister_aead(struct aead_engine_alg *alg); 89 int crypto_engine_register_aeads(struct aead_engine_alg *algs, int count); 90 void crypto_engine_unregister_aeads(struct aead_engine_alg *algs, int count); 91 92 int crypto_engine_register_ahash(struct ahash_engine_alg *alg); 93 void crypto_engine_unregister_ahash(struct ahash_engine_alg *alg); 94 int crypto_engine_register_ahashes(struct ahash_engine_alg *algs, int count); 95 void crypto_engine_unregister_ahashes(struct ahash_engine_alg *algs, 96 int count); 97 98 int crypto_engine_register_akcipher(struct akcipher_engine_alg *alg); 99 void crypto_engine_unregister_akcipher(struct akcipher_engine_alg *alg); 100 101 int crypto_engine_register_kpp(struct kpp_engine_alg *alg); 102 void crypto_engine_unregister_kpp(struct kpp_engine_alg *alg); 103 104 int crypto_engine_register_skcipher(struct skcipher_engine_alg *alg); 105 void crypto_engine_unregister_skcipher(struct skcipher_engine_alg *alg); 106 int crypto_engine_register_skciphers(struct skcipher_engine_alg *algs, 107 int count); 108 void crypto_engine_unregister_skciphers(struct skcipher_engine_alg *algs, 109 int count); 110 111 #endif /* _CRYPTO_ENGINE_H */ 112