Commit d656c180de4d3eacd610c414fbcfe2509cf64a99
Committed by
Herbert Xu
1 parent
bb55a4c100
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
crypto: skcipher - Don't use __crypto_dequeue_request()
Use skcipher_givcrypt_cast(crypto_dequeue_request(queue)) instead, which does the same thing in much cleaner way. The skcipher_givcrypt_cast() actually uses container_of() instead of messing around with offsetof() too. Signed-off-by: Marek Vasut <marex@denx.de> Reported-by: Arnd Bergmann <arnd@arndb.de> Cc: Pantelis Antoniou <panto@antoniou-consulting.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Showing 1 changed file with 1 additions and 2 deletions Inline Diff
include/crypto/internal/skcipher.h
1 | /* | 1 | /* |
2 | * Symmetric key ciphers. | 2 | * Symmetric key ciphers. |
3 | * | 3 | * |
4 | * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au> | 4 | * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au> |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | 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 | 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) | 8 | * Software Foundation; either version 2 of the License, or (at your option) |
9 | * any later version. | 9 | * any later version. |
10 | * | 10 | * |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #ifndef _CRYPTO_INTERNAL_SKCIPHER_H | 13 | #ifndef _CRYPTO_INTERNAL_SKCIPHER_H |
14 | #define _CRYPTO_INTERNAL_SKCIPHER_H | 14 | #define _CRYPTO_INTERNAL_SKCIPHER_H |
15 | 15 | ||
16 | #include <crypto/algapi.h> | 16 | #include <crypto/algapi.h> |
17 | #include <crypto/skcipher.h> | 17 | #include <crypto/skcipher.h> |
18 | #include <linux/types.h> | 18 | #include <linux/types.h> |
19 | 19 | ||
20 | struct rtattr; | 20 | struct rtattr; |
21 | 21 | ||
22 | struct crypto_skcipher_spawn { | 22 | struct crypto_skcipher_spawn { |
23 | struct crypto_spawn base; | 23 | struct crypto_spawn base; |
24 | }; | 24 | }; |
25 | 25 | ||
26 | extern const struct crypto_type crypto_givcipher_type; | 26 | extern const struct crypto_type crypto_givcipher_type; |
27 | 27 | ||
28 | static inline void crypto_set_skcipher_spawn( | 28 | static inline void crypto_set_skcipher_spawn( |
29 | struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst) | 29 | struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst) |
30 | { | 30 | { |
31 | crypto_set_spawn(&spawn->base, inst); | 31 | crypto_set_spawn(&spawn->base, inst); |
32 | } | 32 | } |
33 | 33 | ||
34 | int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name, | 34 | int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name, |
35 | u32 type, u32 mask); | 35 | u32 type, u32 mask); |
36 | 36 | ||
37 | struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type, u32 mask); | 37 | struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type, u32 mask); |
38 | 38 | ||
39 | static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn) | 39 | static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn) |
40 | { | 40 | { |
41 | crypto_drop_spawn(&spawn->base); | 41 | crypto_drop_spawn(&spawn->base); |
42 | } | 42 | } |
43 | 43 | ||
44 | static inline struct crypto_alg *crypto_skcipher_spawn_alg( | 44 | static inline struct crypto_alg *crypto_skcipher_spawn_alg( |
45 | struct crypto_skcipher_spawn *spawn) | 45 | struct crypto_skcipher_spawn *spawn) |
46 | { | 46 | { |
47 | return spawn->base.alg; | 47 | return spawn->base.alg; |
48 | } | 48 | } |
49 | 49 | ||
50 | static inline struct crypto_ablkcipher *crypto_spawn_skcipher( | 50 | static inline struct crypto_ablkcipher *crypto_spawn_skcipher( |
51 | struct crypto_skcipher_spawn *spawn) | 51 | struct crypto_skcipher_spawn *spawn) |
52 | { | 52 | { |
53 | return __crypto_ablkcipher_cast( | 53 | return __crypto_ablkcipher_cast( |
54 | crypto_spawn_tfm(&spawn->base, crypto_skcipher_type(0), | 54 | crypto_spawn_tfm(&spawn->base, crypto_skcipher_type(0), |
55 | crypto_skcipher_mask(0))); | 55 | crypto_skcipher_mask(0))); |
56 | } | 56 | } |
57 | 57 | ||
58 | int skcipher_null_givencrypt(struct skcipher_givcrypt_request *req); | 58 | int skcipher_null_givencrypt(struct skcipher_givcrypt_request *req); |
59 | int skcipher_null_givdecrypt(struct skcipher_givcrypt_request *req); | 59 | int skcipher_null_givdecrypt(struct skcipher_givcrypt_request *req); |
60 | const char *crypto_default_geniv(const struct crypto_alg *alg); | 60 | const char *crypto_default_geniv(const struct crypto_alg *alg); |
61 | 61 | ||
62 | struct crypto_instance *skcipher_geniv_alloc(struct crypto_template *tmpl, | 62 | struct crypto_instance *skcipher_geniv_alloc(struct crypto_template *tmpl, |
63 | struct rtattr **tb, u32 type, | 63 | struct rtattr **tb, u32 type, |
64 | u32 mask); | 64 | u32 mask); |
65 | void skcipher_geniv_free(struct crypto_instance *inst); | 65 | void skcipher_geniv_free(struct crypto_instance *inst); |
66 | int skcipher_geniv_init(struct crypto_tfm *tfm); | 66 | int skcipher_geniv_init(struct crypto_tfm *tfm); |
67 | void skcipher_geniv_exit(struct crypto_tfm *tfm); | 67 | void skcipher_geniv_exit(struct crypto_tfm *tfm); |
68 | 68 | ||
69 | static inline struct crypto_ablkcipher *skcipher_geniv_cipher( | 69 | static inline struct crypto_ablkcipher *skcipher_geniv_cipher( |
70 | struct crypto_ablkcipher *geniv) | 70 | struct crypto_ablkcipher *geniv) |
71 | { | 71 | { |
72 | return crypto_ablkcipher_crt(geniv)->base; | 72 | return crypto_ablkcipher_crt(geniv)->base; |
73 | } | 73 | } |
74 | 74 | ||
75 | static inline int skcipher_enqueue_givcrypt( | 75 | static inline int skcipher_enqueue_givcrypt( |
76 | struct crypto_queue *queue, struct skcipher_givcrypt_request *request) | 76 | struct crypto_queue *queue, struct skcipher_givcrypt_request *request) |
77 | { | 77 | { |
78 | return ablkcipher_enqueue_request(queue, &request->creq); | 78 | return ablkcipher_enqueue_request(queue, &request->creq); |
79 | } | 79 | } |
80 | 80 | ||
81 | static inline struct skcipher_givcrypt_request *skcipher_dequeue_givcrypt( | 81 | static inline struct skcipher_givcrypt_request *skcipher_dequeue_givcrypt( |
82 | struct crypto_queue *queue) | 82 | struct crypto_queue *queue) |
83 | { | 83 | { |
84 | return __crypto_dequeue_request( | 84 | return skcipher_givcrypt_cast(crypto_dequeue_request(queue)); |
85 | queue, offsetof(struct skcipher_givcrypt_request, creq.base)); | ||
86 | } | 85 | } |
87 | 86 | ||
88 | static inline void *skcipher_givcrypt_reqctx( | 87 | static inline void *skcipher_givcrypt_reqctx( |
89 | struct skcipher_givcrypt_request *req) | 88 | struct skcipher_givcrypt_request *req) |
90 | { | 89 | { |
91 | return ablkcipher_request_ctx(&req->creq); | 90 | return ablkcipher_request_ctx(&req->creq); |
92 | } | 91 | } |
93 | 92 | ||
94 | static inline void ablkcipher_request_complete(struct ablkcipher_request *req, | 93 | static inline void ablkcipher_request_complete(struct ablkcipher_request *req, |
95 | int err) | 94 | int err) |
96 | { | 95 | { |
97 | req->base.complete(&req->base, err); | 96 | req->base.complete(&req->base, err); |
98 | } | 97 | } |
99 | 98 | ||
100 | static inline void skcipher_givcrypt_complete( | 99 | static inline void skcipher_givcrypt_complete( |
101 | struct skcipher_givcrypt_request *req, int err) | 100 | struct skcipher_givcrypt_request *req, int err) |
102 | { | 101 | { |
103 | ablkcipher_request_complete(&req->creq, err); | 102 | ablkcipher_request_complete(&req->creq, err); |
104 | } | 103 | } |
105 | 104 | ||
106 | static inline u32 ablkcipher_request_flags(struct ablkcipher_request *req) | 105 | static inline u32 ablkcipher_request_flags(struct ablkcipher_request *req) |
107 | { | 106 | { |
108 | return req->base.flags; | 107 | return req->base.flags; |
109 | } | 108 | } |
110 | 109 | ||
111 | #endif /* _CRYPTO_INTERNAL_SKCIPHER_H */ | 110 | #endif /* _CRYPTO_INTERNAL_SKCIPHER_H */ |
112 | 111 | ||
113 | 112 |