2 * Cryptographic API for algorithms (i.e., low-level API).
4 * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
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)
12 #ifndef _CRYPTO_ALGAPI_H
13 #define _CRYPTO_ALGAPI_H
15 #include <linux/crypto.h>
22 unsigned int (*ctxsize)(struct crypto_alg *alg, u32 type, u32 mask);
23 int (*init)(struct crypto_tfm *tfm, u32 type, u32 mask);
24 void (*exit)(struct crypto_tfm *tfm);
25 void (*show)(struct seq_file *m, struct crypto_alg *alg);
28 struct crypto_instance {
29 struct crypto_alg alg;
31 struct crypto_template *tmpl;
32 struct hlist_node list;
34 void *__ctx[] CRYPTO_MINALIGN_ATTR;
37 struct crypto_template {
38 struct list_head list;
39 struct hlist_head instances;
40 struct module *module;
42 struct crypto_instance *(*alloc)(struct rtattr **tb);
43 void (*free)(struct crypto_instance *inst);
45 char name[CRYPTO_MAX_ALG_NAME];
49 struct list_head list;
50 struct crypto_alg *alg;
51 struct crypto_instance *inst;
55 struct scatterlist *sg;
59 struct blkcipher_walk {
72 struct scatter_walk in;
75 struct scatter_walk out;
85 extern const struct crypto_type crypto_blkcipher_type;
86 extern const struct crypto_type crypto_hash_type;
88 void crypto_mod_put(struct crypto_alg *alg);
90 int crypto_register_template(struct crypto_template *tmpl);
91 void crypto_unregister_template(struct crypto_template *tmpl);
92 struct crypto_template *crypto_lookup_template(const char *name);
94 int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg,
95 struct crypto_instance *inst);
96 void crypto_drop_spawn(struct crypto_spawn *spawn);
97 struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,
100 struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb);
101 int crypto_check_attr_type(struct rtattr **tb, u32 type);
102 struct crypto_alg *crypto_get_attr_alg(struct rtattr **tb, u32 type, u32 mask);
103 struct crypto_instance *crypto_alloc_instance(const char *name,
104 struct crypto_alg *alg);
106 int blkcipher_walk_done(struct blkcipher_desc *desc,
107 struct blkcipher_walk *walk, int err);
108 int blkcipher_walk_virt(struct blkcipher_desc *desc,
109 struct blkcipher_walk *walk);
110 int blkcipher_walk_phys(struct blkcipher_desc *desc,
111 struct blkcipher_walk *walk);
113 static inline void *crypto_tfm_ctx_aligned(struct crypto_tfm *tfm)
115 unsigned long addr = (unsigned long)crypto_tfm_ctx(tfm);
116 unsigned long align = crypto_tfm_alg_alignmask(tfm);
118 if (align <= crypto_tfm_ctx_alignment())
120 return (void *)ALIGN(addr, align);
123 static inline void *crypto_instance_ctx(struct crypto_instance *inst)
128 static inline void *crypto_blkcipher_ctx(struct crypto_blkcipher *tfm)
130 return crypto_tfm_ctx(&tfm->base);
133 static inline void *crypto_blkcipher_ctx_aligned(struct crypto_blkcipher *tfm)
135 return crypto_tfm_ctx_aligned(&tfm->base);
138 static inline struct crypto_cipher *crypto_spawn_cipher(
139 struct crypto_spawn *spawn)
141 u32 type = CRYPTO_ALG_TYPE_CIPHER;
142 u32 mask = CRYPTO_ALG_TYPE_MASK;
144 return __crypto_cipher_cast(crypto_spawn_tfm(spawn, type, mask));
147 static inline struct cipher_alg *crypto_cipher_alg(struct crypto_cipher *tfm)
149 return &crypto_cipher_tfm(tfm)->__crt_alg->cra_cipher;
152 static inline struct crypto_hash *crypto_spawn_hash(struct crypto_spawn *spawn)
154 u32 type = CRYPTO_ALG_TYPE_HASH;
155 u32 mask = CRYPTO_ALG_TYPE_HASH_MASK;
157 return __crypto_hash_cast(crypto_spawn_tfm(spawn, type, mask));
160 static inline void *crypto_hash_ctx_aligned(struct crypto_hash *tfm)
162 return crypto_tfm_ctx_aligned(&tfm->base);
165 static inline void blkcipher_walk_init(struct blkcipher_walk *walk,
166 struct scatterlist *dst,
167 struct scatterlist *src,
172 walk->total = nbytes;
175 #endif /* _CRYPTO_ALGAPI_H */