Linux Audio

Check our new training course

Loading...
v6.8
  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
 17struct crypto_engine;
 18struct device;
 19
 
 20/*
 21 * struct crypto_engine_op - crypto hardware engine operations
 22 * @do_one_request: do encryption for current request
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 23 */
 24struct crypto_engine_op {
 25	int (*do_one_request)(struct crypto_engine *engine,
 26			      void *areq);
 27};
 28
 29struct aead_engine_alg {
 30	struct aead_alg base;
 31	struct crypto_engine_op op;
 32};
 33
 34struct ahash_engine_alg {
 35	struct ahash_alg base;
 36	struct crypto_engine_op op;
 37};
 38
 39struct akcipher_engine_alg {
 40	struct akcipher_alg base;
 41	struct crypto_engine_op op;
 42};
 43
 44struct kpp_engine_alg {
 45	struct kpp_alg base;
 46	struct crypto_engine_op op;
 47};
 48
 49struct skcipher_engine_alg {
 50	struct skcipher_alg base;
 51	struct crypto_engine_op op;
 52};
 53
 54int crypto_transfer_aead_request_to_engine(struct crypto_engine *engine,
 55					   struct aead_request *req);
 56int crypto_transfer_akcipher_request_to_engine(struct crypto_engine *engine,
 57					       struct akcipher_request *req);
 
 
 
 
 
 
 
 
 
 58int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine,
 59					       struct ahash_request *req);
 60int crypto_transfer_kpp_request_to_engine(struct crypto_engine *engine,
 61					  struct kpp_request *req);
 62int crypto_transfer_skcipher_request_to_engine(struct crypto_engine *engine,
 63					       struct skcipher_request *req);
 64void crypto_finalize_aead_request(struct crypto_engine *engine,
 65				  struct aead_request *req, int err);
 66void crypto_finalize_akcipher_request(struct crypto_engine *engine,
 67				      struct akcipher_request *req, int err);
 68void crypto_finalize_hash_request(struct crypto_engine *engine,
 69				  struct ahash_request *req, int err);
 70void crypto_finalize_kpp_request(struct crypto_engine *engine,
 71				 struct kpp_request *req, int err);
 72void crypto_finalize_skcipher_request(struct crypto_engine *engine,
 73				      struct skcipher_request *req, int err);
 74int crypto_engine_start(struct crypto_engine *engine);
 75int crypto_engine_stop(struct crypto_engine *engine);
 76struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt);
 77struct crypto_engine *crypto_engine_alloc_init_and_set(struct device *dev,
 78						       bool retry_support,
 79						       int (*cbk_do_batch)(struct crypto_engine *engine),
 80						       bool rt, int qlen);
 81void crypto_engine_exit(struct crypto_engine *engine);
 82
 83int crypto_engine_register_aead(struct aead_engine_alg *alg);
 84void crypto_engine_unregister_aead(struct aead_engine_alg *alg);
 85int crypto_engine_register_aeads(struct aead_engine_alg *algs, int count);
 86void crypto_engine_unregister_aeads(struct aead_engine_alg *algs, int count);
 87
 88int crypto_engine_register_ahash(struct ahash_engine_alg *alg);
 89void crypto_engine_unregister_ahash(struct ahash_engine_alg *alg);
 90int crypto_engine_register_ahashes(struct ahash_engine_alg *algs, int count);
 91void crypto_engine_unregister_ahashes(struct ahash_engine_alg *algs,
 92				      int count);
 93
 94int crypto_engine_register_akcipher(struct akcipher_engine_alg *alg);
 95void crypto_engine_unregister_akcipher(struct akcipher_engine_alg *alg);
 96
 97int crypto_engine_register_kpp(struct kpp_engine_alg *alg);
 98void crypto_engine_unregister_kpp(struct kpp_engine_alg *alg);
 99
100int crypto_engine_register_skcipher(struct skcipher_engine_alg *alg);
101void crypto_engine_unregister_skcipher(struct skcipher_engine_alg *alg);
102int crypto_engine_register_skciphers(struct skcipher_engine_alg *algs,
103				     int count);
104void crypto_engine_unregister_skciphers(struct skcipher_engine_alg *algs,
105					int count);
106
107#endif /* _CRYPTO_ENGINE_H */
v4.10.11
 
  1/*
  2 * Crypto engine API
  3 *
  4 * Copyright (c) 2016 Baolin Wang <baolin.wang@linaro.org>
  5 *
  6 * This program is free software; you can redistribute it and/or modify it
  7 * under the terms of the GNU General Public License as published by the Free
  8 * Software Foundation; either version 2 of the License, or (at your option)
  9 * any later version.
 10 *
 11 */
 12#ifndef _CRYPTO_ENGINE_H
 13#define _CRYPTO_ENGINE_H
 14
 15#include <linux/crypto.h>
 16#include <linux/list.h>
 17#include <linux/kernel.h>
 18#include <linux/kthread.h>
 19#include <crypto/algapi.h>
 20#include <crypto/hash.h>
 
 
 
 
 
 
 21
 22#define ENGINE_NAME_LEN	30
 23/*
 24 * struct crypto_engine - crypto hardware engine
 25 * @name: the engine name
 26 * @idling: the engine is entering idle state
 27 * @busy: request pump is busy
 28 * @running: the engine is on working
 29 * @cur_req_prepared: current request is prepared
 30 * @list: link with the global crypto engine list
 31 * @queue_lock: spinlock to syncronise access to request queue
 32 * @queue: the crypto queue of the engine
 33 * @rt: whether this queue is set to run as a realtime task
 34 * @prepare_crypt_hardware: a request will soon arrive from the queue
 35 * so the subsystem requests the driver to prepare the hardware
 36 * by issuing this call
 37 * @unprepare_crypt_hardware: there are currently no more requests on the
 38 * queue so the subsystem notifies the driver that it may relax the
 39 * hardware by issuing this call
 40 * @prepare_cipher_request: do some prepare if need before handle the current request
 41 * @unprepare_cipher_request: undo any work done by prepare_cipher_request()
 42 * @cipher_one_request: do encryption for current request
 43 * @prepare_hash_request: do some prepare if need before handle the current request
 44 * @unprepare_hash_request: undo any work done by prepare_hash_request()
 45 * @hash_one_request: do hash for current request
 46 * @kworker: kthread worker struct for request pump
 47 * @pump_requests: work struct for scheduling work to the request pump
 48 * @priv_data: the engine private data
 49 * @cur_req: the current request which is on processing
 50 */
 51struct crypto_engine {
 52	char			name[ENGINE_NAME_LEN];
 53	bool			idling;
 54	bool			busy;
 55	bool			running;
 56	bool			cur_req_prepared;
 57
 58	struct list_head	list;
 59	spinlock_t		queue_lock;
 60	struct crypto_queue	queue;
 61
 62	bool			rt;
 63
 64	int (*prepare_crypt_hardware)(struct crypto_engine *engine);
 65	int (*unprepare_crypt_hardware)(struct crypto_engine *engine);
 66
 67	int (*prepare_cipher_request)(struct crypto_engine *engine,
 68				      struct ablkcipher_request *req);
 69	int (*unprepare_cipher_request)(struct crypto_engine *engine,
 70					struct ablkcipher_request *req);
 71	int (*prepare_hash_request)(struct crypto_engine *engine,
 72				    struct ahash_request *req);
 73	int (*unprepare_hash_request)(struct crypto_engine *engine,
 74				      struct ahash_request *req);
 75	int (*cipher_one_request)(struct crypto_engine *engine,
 76				  struct ablkcipher_request *req);
 77	int (*hash_one_request)(struct crypto_engine *engine,
 78				struct ahash_request *req);
 79
 80	struct kthread_worker           *kworker;
 81	struct kthread_work             pump_requests;
 82
 83	void				*priv_data;
 84	struct crypto_async_request	*cur_req;
 85};
 86
 87int crypto_transfer_cipher_request(struct crypto_engine *engine,
 88				   struct ablkcipher_request *req,
 89				   bool need_pump);
 90int crypto_transfer_cipher_request_to_engine(struct crypto_engine *engine,
 91					     struct ablkcipher_request *req);
 92int crypto_transfer_hash_request(struct crypto_engine *engine,
 93				 struct ahash_request *req, bool need_pump);
 94int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine,
 95					   struct ahash_request *req);
 96void crypto_finalize_cipher_request(struct crypto_engine *engine,
 97				    struct ablkcipher_request *req, int err);
 
 
 
 
 
 
 98void crypto_finalize_hash_request(struct crypto_engine *engine,
 99				  struct ahash_request *req, int err);
 
 
 
 
100int crypto_engine_start(struct crypto_engine *engine);
101int crypto_engine_stop(struct crypto_engine *engine);
102struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt);
103int crypto_engine_exit(struct crypto_engine *engine);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
105#endif /* _CRYPTO_ENGINE_H */