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>
21 unsigned int (*ctxsize
)(struct crypto_alg
*alg
);
22 int (*init
)(struct crypto_tfm
*tfm
);
23 void (*exit
)(struct crypto_tfm
*tfm
);
24 void (*show
)(struct seq_file
*m
, struct crypto_alg
*alg
);
27 struct crypto_instance
{
28 struct crypto_alg alg
;
30 struct crypto_template
*tmpl
;
31 struct hlist_node list
;
33 void *__ctx
[] CRYPTO_MINALIGN_ATTR
;
36 struct crypto_template
{
37 struct list_head list
;
38 struct hlist_head instances
;
39 struct module
*module
;
41 struct crypto_instance
*(*alloc
)(void *param
, unsigned int len
);
42 void (*free
)(struct crypto_instance
*inst
);
44 char name
[CRYPTO_MAX_ALG_NAME
];
48 struct list_head list
;
49 struct crypto_alg
*alg
;
50 struct crypto_instance
*inst
;
54 struct scatterlist
*sg
;
58 struct blkcipher_walk
{
71 struct scatter_walk in
;
74 struct scatter_walk out
;
84 extern const struct crypto_type crypto_blkcipher_type
;
85 extern const struct crypto_type crypto_hash_type
;
87 void crypto_mod_put(struct crypto_alg
*alg
);
89 int crypto_register_template(struct crypto_template
*tmpl
);
90 void crypto_unregister_template(struct crypto_template
*tmpl
);
91 struct crypto_template
*crypto_lookup_template(const char *name
);
93 int crypto_init_spawn(struct crypto_spawn
*spawn
, struct crypto_alg
*alg
,
94 struct crypto_instance
*inst
);
95 void crypto_drop_spawn(struct crypto_spawn
*spawn
);
96 struct crypto_tfm
*crypto_spawn_tfm(struct crypto_spawn
*spawn
);
98 struct crypto_alg
*crypto_get_attr_alg(void *param
, unsigned int len
,
100 struct crypto_instance
*crypto_alloc_instance(const char *name
,
101 struct crypto_alg
*alg
);
103 int blkcipher_walk_done(struct blkcipher_desc
*desc
,
104 struct blkcipher_walk
*walk
, int err
);
105 int blkcipher_walk_virt(struct blkcipher_desc
*desc
,
106 struct blkcipher_walk
*walk
);
107 int blkcipher_walk_phys(struct blkcipher_desc
*desc
,
108 struct blkcipher_walk
*walk
);
110 static inline void *crypto_tfm_ctx_aligned(struct crypto_tfm
*tfm
)
112 unsigned long addr
= (unsigned long)crypto_tfm_ctx(tfm
);
113 unsigned long align
= crypto_tfm_alg_alignmask(tfm
);
115 if (align
<= crypto_tfm_ctx_alignment())
117 return (void *)ALIGN(addr
, align
);
120 static inline void *crypto_instance_ctx(struct crypto_instance
*inst
)
125 static inline void *crypto_blkcipher_ctx(struct crypto_blkcipher
*tfm
)
127 return crypto_tfm_ctx(&tfm
->base
);
130 static inline void *crypto_blkcipher_ctx_aligned(struct crypto_blkcipher
*tfm
)
132 return crypto_tfm_ctx_aligned(&tfm
->base
);
135 static inline struct cipher_alg
*crypto_cipher_alg(struct crypto_cipher
*tfm
)
137 return &crypto_cipher_tfm(tfm
)->__crt_alg
->cra_cipher
;
140 static inline void *crypto_hash_ctx_aligned(struct crypto_hash
*tfm
)
142 return crypto_tfm_ctx_aligned(&tfm
->base
);
145 static inline void blkcipher_walk_init(struct blkcipher_walk
*walk
,
146 struct scatterlist
*dst
,
147 struct scatterlist
*src
,
152 walk
->total
= nbytes
;
155 #endif /* _CRYPTO_ALGAPI_H */