diff options
| author | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-14 00:28:26 -0400 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2009-07-14 03:54:07 -0400 |
| commit | 88056ec346ccf41f63dbc7080b24b5fd19d1358d (patch) | |
| tree | b78a82cbce49183e587ab8a1a5a5922611468361 /include/crypto | |
| parent | 2ca33da1dea3ba53d1425226a6bac073c5e8568c (diff) | |
crypto: ahash - Convert to new style algorithms
This patch converts crypto_ahash to the new style. The old ahash
algorithm type is retained until the existing ahash implementations
are also converted. All ahash users will automatically get the
new crypto_ahash type.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include/crypto')
| -rw-r--r-- | include/crypto/hash.h | 109 | ||||
| -rw-r--r-- | include/crypto/internal/hash.h | 11 |
2 files changed, 86 insertions, 34 deletions
diff --git a/include/crypto/hash.h b/include/crypto/hash.h index fcc02d978231..262861d8f0cb 100644 --- a/include/crypto/hash.h +++ b/include/crypto/hash.h | |||
| @@ -15,6 +15,39 @@ | |||
| 15 | 15 | ||
| 16 | #include <linux/crypto.h> | 16 | #include <linux/crypto.h> |
| 17 | 17 | ||
| 18 | struct crypto_ahash; | ||
| 19 | |||
| 20 | struct hash_alg_common { | ||
| 21 | unsigned int digestsize; | ||
| 22 | unsigned int statesize; | ||
| 23 | |||
| 24 | struct crypto_alg base; | ||
| 25 | }; | ||
| 26 | |||
| 27 | struct ahash_request { | ||
| 28 | struct crypto_async_request base; | ||
| 29 | |||
| 30 | unsigned int nbytes; | ||
| 31 | struct scatterlist *src; | ||
| 32 | u8 *result; | ||
| 33 | |||
| 34 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | ||
| 35 | }; | ||
| 36 | |||
| 37 | struct ahash_alg { | ||
| 38 | int (*init)(struct ahash_request *req); | ||
| 39 | int (*update)(struct ahash_request *req); | ||
| 40 | int (*final)(struct ahash_request *req); | ||
| 41 | int (*finup)(struct ahash_request *req); | ||
| 42 | int (*digest)(struct ahash_request *req); | ||
| 43 | int (*export)(struct ahash_request *req, void *out); | ||
| 44 | int (*import)(struct ahash_request *req, const void *in); | ||
| 45 | int (*setkey)(struct crypto_ahash *tfm, const u8 *key, | ||
| 46 | unsigned int keylen); | ||
| 47 | |||
| 48 | struct hash_alg_common halg; | ||
| 49 | }; | ||
| 50 | |||
| 18 | struct shash_desc { | 51 | struct shash_desc { |
| 19 | struct crypto_shash *tfm; | 52 | struct crypto_shash *tfm; |
| 20 | u32 flags; | 53 | u32 flags; |
| @@ -37,6 +70,8 @@ struct shash_alg { | |||
| 37 | unsigned int keylen); | 70 | unsigned int keylen); |
| 38 | 71 | ||
| 39 | unsigned int descsize; | 72 | unsigned int descsize; |
| 73 | |||
| 74 | /* These fields must match hash_alg_common. */ | ||
| 40 | unsigned int digestsize; | 75 | unsigned int digestsize; |
| 41 | unsigned int statesize; | 76 | unsigned int statesize; |
| 42 | 77 | ||
| @@ -44,6 +79,18 @@ struct shash_alg { | |||
| 44 | }; | 79 | }; |
| 45 | 80 | ||
| 46 | struct crypto_ahash { | 81 | struct crypto_ahash { |
| 82 | int (*init)(struct ahash_request *req); | ||
| 83 | int (*update)(struct ahash_request *req); | ||
| 84 | int (*final)(struct ahash_request *req); | ||
| 85 | int (*finup)(struct ahash_request *req); | ||
| 86 | int (*digest)(struct ahash_request *req); | ||
| 87 | int (*export)(struct ahash_request *req, void *out); | ||
| 88 | int (*import)(struct ahash_request *req, const void *in); | ||
| 89 | int (*setkey)(struct crypto_ahash *tfm, const u8 *key, | ||
| 90 | unsigned int keylen); | ||
| 91 | |||
| 92 | unsigned int digestsize; | ||
| 93 | unsigned int reqsize; | ||
| 47 | struct crypto_tfm base; | 94 | struct crypto_tfm base; |
| 48 | }; | 95 | }; |
| 49 | 96 | ||
| @@ -54,19 +101,11 @@ struct crypto_shash { | |||
| 54 | 101 | ||
| 55 | static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) | 102 | static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) |
| 56 | { | 103 | { |
| 57 | return (struct crypto_ahash *)tfm; | 104 | return container_of(tfm, struct crypto_ahash, base); |
| 58 | } | 105 | } |
| 59 | 106 | ||
| 60 | static inline struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, | 107 | struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, u32 type, |
| 61 | u32 type, u32 mask) | 108 | u32 mask); |
| 62 | { | ||
| 63 | type &= ~CRYPTO_ALG_TYPE_MASK; | ||
| 64 | mask &= ~CRYPTO_ALG_TYPE_MASK; | ||
| 65 | type |= CRYPTO_ALG_TYPE_AHASH; | ||
| 66 | mask |= CRYPTO_ALG_TYPE_AHASH_MASK; | ||
| 67 | |||
| 68 | return __crypto_ahash_cast(crypto_alloc_base(alg_name, type, mask)); | ||
| 69 | } | ||
| 70 | 109 | ||
| 71 | static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm) | 110 | static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm) |
| 72 | { | 111 | { |
| @@ -75,7 +114,7 @@ static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm) | |||
| 75 | 114 | ||
| 76 | static inline void crypto_free_ahash(struct crypto_ahash *tfm) | 115 | static inline void crypto_free_ahash(struct crypto_ahash *tfm) |
| 77 | { | 116 | { |
| 78 | crypto_free_tfm(crypto_ahash_tfm(tfm)); | 117 | crypto_destroy_tfm(tfm, crypto_ahash_tfm(tfm)); |
| 79 | } | 118 | } |
| 80 | 119 | ||
| 81 | static inline unsigned int crypto_ahash_alignmask( | 120 | static inline unsigned int crypto_ahash_alignmask( |
| @@ -84,14 +123,26 @@ static inline unsigned int crypto_ahash_alignmask( | |||
| 84 | return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm)); | 123 | return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm)); |
| 85 | } | 124 | } |
| 86 | 125 | ||
| 87 | static inline struct ahash_tfm *crypto_ahash_crt(struct crypto_ahash *tfm) | 126 | static inline struct hash_alg_common *__crypto_hash_alg_common( |
| 127 | struct crypto_alg *alg) | ||
| 88 | { | 128 | { |
| 89 | return &crypto_ahash_tfm(tfm)->crt_ahash; | 129 | return container_of(alg, struct hash_alg_common, base); |
| 130 | } | ||
| 131 | |||
| 132 | static inline struct hash_alg_common *crypto_hash_alg_common( | ||
| 133 | struct crypto_ahash *tfm) | ||
| 134 | { | ||
| 135 | return __crypto_hash_alg_common(crypto_ahash_tfm(tfm)->__crt_alg); | ||
| 90 | } | 136 | } |
| 91 | 137 | ||
| 92 | static inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm) | 138 | static inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm) |
| 93 | { | 139 | { |
| 94 | return crypto_ahash_crt(tfm)->digestsize; | 140 | return tfm->digestsize; |
| 141 | } | ||
| 142 | |||
| 143 | static inline unsigned int crypto_ahash_statesize(struct crypto_ahash *tfm) | ||
| 144 | { | ||
| 145 | return crypto_hash_alg_common(tfm)->statesize; | ||
| 95 | } | 146 | } |
| 96 | 147 | ||
| 97 | static inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm) | 148 | static inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm) |
| @@ -117,7 +168,7 @@ static inline struct crypto_ahash *crypto_ahash_reqtfm( | |||
| 117 | 168 | ||
| 118 | static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm) | 169 | static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm) |
| 119 | { | 170 | { |
| 120 | return crypto_ahash_crt(tfm)->reqsize; | 171 | return tfm->reqsize; |
| 121 | } | 172 | } |
| 122 | 173 | ||
| 123 | static inline void *ahash_request_ctx(struct ahash_request *req) | 174 | static inline void *ahash_request_ctx(struct ahash_request *req) |
| @@ -128,41 +179,37 @@ static inline void *ahash_request_ctx(struct ahash_request *req) | |||
| 128 | static inline int crypto_ahash_setkey(struct crypto_ahash *tfm, | 179 | static inline int crypto_ahash_setkey(struct crypto_ahash *tfm, |
| 129 | const u8 *key, unsigned int keylen) | 180 | const u8 *key, unsigned int keylen) |
| 130 | { | 181 | { |
| 131 | struct ahash_tfm *crt = crypto_ahash_crt(tfm); | 182 | return tfm->setkey(tfm, key, keylen); |
| 132 | |||
| 133 | return crt->setkey(tfm, key, keylen); | ||
| 134 | } | 183 | } |
| 135 | 184 | ||
| 136 | static inline int crypto_ahash_digest(struct ahash_request *req) | 185 | static inline int crypto_ahash_digest(struct ahash_request *req) |
| 137 | { | 186 | { |
| 138 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); | 187 | return crypto_ahash_reqtfm(req)->digest(req); |
| 139 | return crt->digest(req); | ||
| 140 | } | 188 | } |
| 141 | 189 | ||
| 142 | static inline void crypto_ahash_export(struct ahash_request *req, u8 *out) | 190 | static inline int crypto_ahash_export(struct ahash_request *req, void *out) |
| 143 | { | 191 | { |
| 144 | memcpy(out, ahash_request_ctx(req), | 192 | return crypto_ahash_reqtfm(req)->export(req, out); |
| 145 | crypto_ahash_reqsize(crypto_ahash_reqtfm(req))); | ||
| 146 | } | 193 | } |
| 147 | 194 | ||
| 148 | int crypto_ahash_import(struct ahash_request *req, const u8 *in); | 195 | static inline int crypto_ahash_import(struct ahash_request *req, const void *in) |
| 196 | { | ||
| 197 | return crypto_ahash_reqtfm(req)->import(req, in); | ||
| 198 | } | ||
| 149 | 199 | ||
| 150 | static inline int crypto_ahash_init(struct ahash_request *req) | 200 | static inline int crypto_ahash_init(struct ahash_request *req) |
| 151 | { | 201 | { |
| 152 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); | 202 | return crypto_ahash_reqtfm(req)->init(req); |
| 153 | return crt->init(req); | ||
| 154 | } | 203 | } |
| 155 | 204 | ||
| 156 | static inline int crypto_ahash_update(struct ahash_request *req) | 205 | static inline int crypto_ahash_update(struct ahash_request *req) |
| 157 | { | 206 | { |
| 158 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); | 207 | return crypto_ahash_reqtfm(req)->update(req); |
| 159 | return crt->update(req); | ||
| 160 | } | 208 | } |
| 161 | 209 | ||
| 162 | static inline int crypto_ahash_final(struct ahash_request *req) | 210 | static inline int crypto_ahash_final(struct ahash_request *req) |
| 163 | { | 211 | { |
| 164 | struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); | 212 | return crypto_ahash_reqtfm(req)->final(req); |
| 165 | return crt->final(req); | ||
| 166 | } | 213 | } |
| 167 | 214 | ||
| 168 | static inline void ahash_request_set_tfm(struct ahash_request *req, | 215 | static inline void ahash_request_set_tfm(struct ahash_request *req, |
diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h index 5e45818f3351..08bdffafefad 100644 --- a/include/crypto/internal/hash.h +++ b/include/crypto/internal/hash.h | |||
| @@ -51,6 +51,9 @@ int crypto_hash_walk_first_compat(struct hash_desc *hdesc, | |||
| 51 | struct crypto_hash_walk *walk, | 51 | struct crypto_hash_walk *walk, |
| 52 | struct scatterlist *sg, unsigned int len); | 52 | struct scatterlist *sg, unsigned int len); |
| 53 | 53 | ||
| 54 | int crypto_register_ahash(struct ahash_alg *alg); | ||
| 55 | int crypto_unregister_ahash(struct ahash_alg *alg); | ||
| 56 | |||
| 54 | int crypto_register_shash(struct shash_alg *alg); | 57 | int crypto_register_shash(struct shash_alg *alg); |
| 55 | int crypto_unregister_shash(struct shash_alg *alg); | 58 | int crypto_unregister_shash(struct shash_alg *alg); |
| 56 | int shash_register_instance(struct crypto_template *tmpl, | 59 | int shash_register_instance(struct crypto_template *tmpl, |
| @@ -66,12 +69,14 @@ struct shash_alg *shash_attr_alg(struct rtattr *rta, u32 type, u32 mask); | |||
| 66 | int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc); | 69 | int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc); |
| 67 | int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc); | 70 | int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc); |
| 68 | 71 | ||
| 72 | int crypto_init_shash_ops_async(struct crypto_tfm *tfm); | ||
| 73 | |||
| 69 | static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm) | 74 | static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm) |
| 70 | { | 75 | { |
| 71 | return crypto_tfm_ctx(&tfm->base); | 76 | return crypto_tfm_ctx(crypto_ahash_tfm(tfm)); |
| 72 | } | 77 | } |
| 73 | 78 | ||
| 74 | static inline struct ahash_alg *crypto_ahash_alg( | 79 | static inline struct old_ahash_alg *crypto_old_ahash_alg( |
| 75 | struct crypto_ahash *tfm) | 80 | struct crypto_ahash *tfm) |
| 76 | { | 81 | { |
| 77 | return &crypto_ahash_tfm(tfm)->__crt_alg->cra_ahash; | 82 | return &crypto_ahash_tfm(tfm)->__crt_alg->cra_ahash; |
| @@ -80,7 +85,7 @@ static inline struct ahash_alg *crypto_ahash_alg( | |||
| 80 | static inline void crypto_ahash_set_reqsize(struct crypto_ahash *tfm, | 85 | static inline void crypto_ahash_set_reqsize(struct crypto_ahash *tfm, |
| 81 | unsigned int reqsize) | 86 | unsigned int reqsize) |
| 82 | { | 87 | { |
| 83 | crypto_ahash_crt(tfm)->reqsize = reqsize; | 88 | tfm->reqsize = reqsize; |
| 84 | } | 89 | } |
| 85 | 90 | ||
| 86 | static inline int ahash_enqueue_request(struct crypto_queue *queue, | 91 | static inline int ahash_enqueue_request(struct crypto_queue *queue, |
