0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _CRYPTO_INTERNAL_HASH_H
0009 #define _CRYPTO_INTERNAL_HASH_H
0010
0011 #include <crypto/algapi.h>
0012 #include <crypto/hash.h>
0013
0014 struct ahash_request;
0015 struct scatterlist;
0016
0017 struct crypto_hash_walk {
0018 char *data;
0019
0020 unsigned int offset;
0021 unsigned int alignmask;
0022
0023 struct page *pg;
0024 unsigned int entrylen;
0025
0026 unsigned int total;
0027 struct scatterlist *sg;
0028
0029 unsigned int flags;
0030 };
0031
0032 struct ahash_instance {
0033 void (*free)(struct ahash_instance *inst);
0034 union {
0035 struct {
0036 char head[offsetof(struct ahash_alg, halg.base)];
0037 struct crypto_instance base;
0038 } s;
0039 struct ahash_alg alg;
0040 };
0041 };
0042
0043 struct shash_instance {
0044 void (*free)(struct shash_instance *inst);
0045 union {
0046 struct {
0047 char head[offsetof(struct shash_alg, base)];
0048 struct crypto_instance base;
0049 } s;
0050 struct shash_alg alg;
0051 };
0052 };
0053
0054 struct crypto_ahash_spawn {
0055 struct crypto_spawn base;
0056 };
0057
0058 struct crypto_shash_spawn {
0059 struct crypto_spawn base;
0060 };
0061
0062 int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err);
0063 int crypto_hash_walk_first(struct ahash_request *req,
0064 struct crypto_hash_walk *walk);
0065
0066 static inline int crypto_hash_walk_last(struct crypto_hash_walk *walk)
0067 {
0068 return !(walk->entrylen | walk->total);
0069 }
0070
0071 int crypto_register_ahash(struct ahash_alg *alg);
0072 void crypto_unregister_ahash(struct ahash_alg *alg);
0073 int crypto_register_ahashes(struct ahash_alg *algs, int count);
0074 void crypto_unregister_ahashes(struct ahash_alg *algs, int count);
0075 int ahash_register_instance(struct crypto_template *tmpl,
0076 struct ahash_instance *inst);
0077
0078 bool crypto_shash_alg_has_setkey(struct shash_alg *alg);
0079
0080 static inline bool crypto_shash_alg_needs_key(struct shash_alg *alg)
0081 {
0082 return crypto_shash_alg_has_setkey(alg) &&
0083 !(alg->base.cra_flags & CRYPTO_ALG_OPTIONAL_KEY);
0084 }
0085
0086 bool crypto_hash_alg_has_setkey(struct hash_alg_common *halg);
0087
0088 int crypto_grab_ahash(struct crypto_ahash_spawn *spawn,
0089 struct crypto_instance *inst,
0090 const char *name, u32 type, u32 mask);
0091
0092 static inline void crypto_drop_ahash(struct crypto_ahash_spawn *spawn)
0093 {
0094 crypto_drop_spawn(&spawn->base);
0095 }
0096
0097 static inline struct hash_alg_common *crypto_spawn_ahash_alg(
0098 struct crypto_ahash_spawn *spawn)
0099 {
0100 return __crypto_hash_alg_common(spawn->base.alg);
0101 }
0102
0103 int crypto_register_shash(struct shash_alg *alg);
0104 void crypto_unregister_shash(struct shash_alg *alg);
0105 int crypto_register_shashes(struct shash_alg *algs, int count);
0106 void crypto_unregister_shashes(struct shash_alg *algs, int count);
0107 int shash_register_instance(struct crypto_template *tmpl,
0108 struct shash_instance *inst);
0109 void shash_free_singlespawn_instance(struct shash_instance *inst);
0110
0111 int crypto_grab_shash(struct crypto_shash_spawn *spawn,
0112 struct crypto_instance *inst,
0113 const char *name, u32 type, u32 mask);
0114
0115 static inline void crypto_drop_shash(struct crypto_shash_spawn *spawn)
0116 {
0117 crypto_drop_spawn(&spawn->base);
0118 }
0119
0120 static inline struct shash_alg *crypto_spawn_shash_alg(
0121 struct crypto_shash_spawn *spawn)
0122 {
0123 return __crypto_shash_alg(spawn->base.alg);
0124 }
0125
0126 int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc);
0127 int shash_ahash_finup(struct ahash_request *req, struct shash_desc *desc);
0128 int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc);
0129
0130 int crypto_init_shash_ops_async(struct crypto_tfm *tfm);
0131
0132 static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm)
0133 {
0134 return crypto_tfm_ctx(crypto_ahash_tfm(tfm));
0135 }
0136
0137 static inline struct ahash_alg *__crypto_ahash_alg(struct crypto_alg *alg)
0138 {
0139 return container_of(__crypto_hash_alg_common(alg), struct ahash_alg,
0140 halg);
0141 }
0142
0143 static inline void crypto_ahash_set_reqsize(struct crypto_ahash *tfm,
0144 unsigned int reqsize)
0145 {
0146 tfm->reqsize = reqsize;
0147 }
0148
0149 static inline struct crypto_instance *ahash_crypto_instance(
0150 struct ahash_instance *inst)
0151 {
0152 return &inst->s.base;
0153 }
0154
0155 static inline struct ahash_instance *ahash_instance(
0156 struct crypto_instance *inst)
0157 {
0158 return container_of(inst, struct ahash_instance, s.base);
0159 }
0160
0161 static inline struct ahash_instance *ahash_alg_instance(
0162 struct crypto_ahash *ahash)
0163 {
0164 return ahash_instance(crypto_tfm_alg_instance(&ahash->base));
0165 }
0166
0167 static inline void *ahash_instance_ctx(struct ahash_instance *inst)
0168 {
0169 return crypto_instance_ctx(ahash_crypto_instance(inst));
0170 }
0171
0172 static inline void ahash_request_complete(struct ahash_request *req, int err)
0173 {
0174 req->base.complete(&req->base, err);
0175 }
0176
0177 static inline u32 ahash_request_flags(struct ahash_request *req)
0178 {
0179 return req->base.flags;
0180 }
0181
0182 static inline struct crypto_ahash *crypto_spawn_ahash(
0183 struct crypto_ahash_spawn *spawn)
0184 {
0185 return crypto_spawn_tfm2(&spawn->base);
0186 }
0187
0188 static inline int ahash_enqueue_request(struct crypto_queue *queue,
0189 struct ahash_request *request)
0190 {
0191 return crypto_enqueue_request(queue, &request->base);
0192 }
0193
0194 static inline struct ahash_request *ahash_dequeue_request(
0195 struct crypto_queue *queue)
0196 {
0197 return ahash_request_cast(crypto_dequeue_request(queue));
0198 }
0199
0200 static inline void *crypto_shash_ctx(struct crypto_shash *tfm)
0201 {
0202 return crypto_tfm_ctx(&tfm->base);
0203 }
0204
0205 static inline struct crypto_instance *shash_crypto_instance(
0206 struct shash_instance *inst)
0207 {
0208 return &inst->s.base;
0209 }
0210
0211 static inline struct shash_instance *shash_instance(
0212 struct crypto_instance *inst)
0213 {
0214 return container_of(inst, struct shash_instance, s.base);
0215 }
0216
0217 static inline struct shash_instance *shash_alg_instance(
0218 struct crypto_shash *shash)
0219 {
0220 return shash_instance(crypto_tfm_alg_instance(&shash->base));
0221 }
0222
0223 static inline void *shash_instance_ctx(struct shash_instance *inst)
0224 {
0225 return crypto_instance_ctx(shash_crypto_instance(inst));
0226 }
0227
0228 static inline struct crypto_shash *crypto_spawn_shash(
0229 struct crypto_shash_spawn *spawn)
0230 {
0231 return crypto_spawn_tfm2(&spawn->base);
0232 }
0233
0234 static inline void *crypto_shash_ctx_aligned(struct crypto_shash *tfm)
0235 {
0236 return crypto_tfm_ctx_aligned(&tfm->base);
0237 }
0238
0239 static inline struct crypto_shash *__crypto_shash_cast(struct crypto_tfm *tfm)
0240 {
0241 return container_of(tfm, struct crypto_shash, base);
0242 }
0243
0244 #endif
0245