| 1 | |
| 2 | * Software async multibuffer crypto daemon headers
|
| 3 | *
|
| 4 | * Author:
|
| 5 | * Tim Chen <[email protected]>
|
| 6 | *
|
| 7 | * Copyright (c) 2014, Intel Corporation.
|
| 8 |
|
| 9 |
|
| 10 | #ifndef _CRYPTO_MCRYPT_H
|
| 11 | #define _CRYPTO_MCRYPT_H
|
| 12 |
|
| 13 | #include <linux/crypto.h>
|
| 14 | #include <linux/kernel.h>
|
| 15 | #include <crypto/hash.h>
|
| 16 |
|
| 17 | struct mcryptd_ahash {
|
| 18 | struct crypto_ahash base;
|
| 19 | };
|
| 20 |
|
| 21 | static inline struct mcryptd_ahash *__mcryptd_ahash_cast(
|
| 22 | struct crypto_ahash *tfm)
|
| 23 | {
|
| 24 | return (struct mcryptd_ahash *)tfm;
|
| 25 | }
|
| 26 |
|
| 27 | struct mcryptd_cpu_queue {
|
| 28 | struct crypto_queue queue;
|
| 29 | struct work_struct work;
|
| 30 | };
|
| 31 |
|
| 32 | struct mcryptd_queue {
|
| 33 | struct mcryptd_cpu_queue __percpu *cpu_queue;
|
| 34 | };
|
| 35 |
|
| 36 | struct mcryptd_instance_ctx {
|
| 37 | struct crypto_spawn spawn;
|
| 38 | struct mcryptd_queue *queue;
|
| 39 | };
|
| 40 |
|
| 41 | struct mcryptd_hash_ctx {
|
| 42 | struct crypto_shash *child;
|
| 43 | struct mcryptd_alg_state *alg_state;
|
| 44 | };
|
| 45 |
|
| 46 | struct mcryptd_tag {
|
| 47 |
|
| 48 | unsigned seq_num;
|
| 49 |
|
| 50 | unsigned long arrival;
|
| 51 | unsigned long expire;
|
| 52 | int cpu;
|
| 53 | };
|
| 54 |
|
| 55 | struct mcryptd_hash_request_ctx {
|
| 56 | struct list_head waiter;
|
| 57 | crypto_completion_t complete;
|
| 58 | struct mcryptd_tag tag;
|
| 59 | struct crypto_hash_walk walk;
|
| 60 | u8 *out;
|
| 61 | int flag;
|
| 62 | struct shash_desc desc;
|
| 63 | };
|
| 64 |
|
| 65 | struct mcryptd_ahash *mcryptd_alloc_ahash(const char *alg_name,
|
| 66 | u32 type, u32 mask);
|
| 67 | struct crypto_shash *mcryptd_ahash_child(struct mcryptd_ahash *tfm);
|
| 68 | struct shash_desc *mcryptd_shash_desc(struct ahash_request *req);
|
| 69 | void mcryptd_free_ahash(struct mcryptd_ahash *tfm);
|
| 70 | void mcryptd_flusher(struct work_struct *work);
|
| 71 |
|
| 72 | enum mcryptd_req_type {
|
| 73 | MCRYPTD_NONE,
|
| 74 | MCRYPTD_UPDATE,
|
| 75 | MCRYPTD_FINUP,
|
| 76 | MCRYPTD_DIGEST,
|
| 77 | MCRYPTD_FINAL
|
| 78 | };
|
| 79 |
|
| 80 | struct mcryptd_alg_cstate {
|
| 81 | unsigned long next_flush;
|
| 82 | unsigned next_seq_num;
|
| 83 | bool flusher_engaged;
|
| 84 | struct delayed_work flush;
|
| 85 | int cpu;
|
| 86 | struct mcryptd_alg_state *alg_state;
|
| 87 | void *mgr;
|
| 88 | spinlock_t work_lock;
|
| 89 | struct list_head work_list;
|
| 90 | struct list_head flush_list;
|
| 91 | };
|
| 92 |
|
| 93 | struct mcryptd_alg_state {
|
| 94 | struct mcryptd_alg_cstate __percpu *alg_cstate;
|
| 95 | unsigned long (*flusher)(struct mcryptd_alg_cstate *cstate);
|
| 96 | };
|
| 97 |
|
| 98 |
|
| 99 | static inline unsigned long get_delay(unsigned long t)
|
| 100 | {
|
| 101 | long delay;
|
| 102 |
|
| 103 | delay = (long) t - (long) jiffies;
|
| 104 | if (delay <= 0)
|
| 105 | return 0;
|
| 106 | else
|
| 107 | return (unsigned long) delay;
|
| 108 | }
|
| 109 |
|
| 110 | void mcryptd_arm_flusher(struct mcryptd_alg_cstate *cstate, unsigned long delay);
|
| 111 |
|
| 112 | #endif
|