diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2016-01-24 08:19:01 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2016-01-27 07:36:06 -0500 |
commit | 1afe593b423918ffd5e449cec858b1591cd31781 (patch) | |
tree | 0378fce1f48fb3491c9e581ca1fe8e6a4178e40e | |
parent | 96953718623eb7ee8839ae667dfecad7b257d400 (diff) |
rxrpc: Use skcipher
This patch replaces uses of blkcipher with skcipher.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | net/rxrpc/ar-internal.h | 2 | ||||
-rw-r--r-- | net/rxrpc/ar-key.c | 12 | ||||
-rw-r--r-- | net/rxrpc/rxkad.c | 172 |
3 files changed, 114 insertions, 72 deletions
diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h index 2934a73a5981..71598f5b11b7 100644 --- a/net/rxrpc/ar-internal.h +++ b/net/rxrpc/ar-internal.h | |||
@@ -252,7 +252,7 @@ struct rxrpc_connection { | |||
252 | struct rxrpc_security *security; /* applied security module */ | 252 | struct rxrpc_security *security; /* applied security module */ |
253 | struct key *key; /* security for this connection (client) */ | 253 | struct key *key; /* security for this connection (client) */ |
254 | struct key *server_key; /* security for this service */ | 254 | struct key *server_key; /* security for this service */ |
255 | struct crypto_blkcipher *cipher; /* encryption handle */ | 255 | struct crypto_skcipher *cipher; /* encryption handle */ |
256 | struct rxrpc_crypt csum_iv; /* packet checksum base */ | 256 | struct rxrpc_crypt csum_iv; /* packet checksum base */ |
257 | unsigned long events; | 257 | unsigned long events; |
258 | #define RXRPC_CONN_CHALLENGE 0 /* send challenge packet */ | 258 | #define RXRPC_CONN_CHALLENGE 0 /* send challenge packet */ |
diff --git a/net/rxrpc/ar-key.c b/net/rxrpc/ar-key.c index 3f6571651d32..3fb492eedeb9 100644 --- a/net/rxrpc/ar-key.c +++ b/net/rxrpc/ar-key.c | |||
@@ -12,11 +12,11 @@ | |||
12 | * "afs@CAMBRIDGE.REDHAT.COM> | 12 | * "afs@CAMBRIDGE.REDHAT.COM> |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <crypto/skcipher.h> | ||
15 | #include <linux/module.h> | 16 | #include <linux/module.h> |
16 | #include <linux/net.h> | 17 | #include <linux/net.h> |
17 | #include <linux/skbuff.h> | 18 | #include <linux/skbuff.h> |
18 | #include <linux/key-type.h> | 19 | #include <linux/key-type.h> |
19 | #include <linux/crypto.h> | ||
20 | #include <linux/ctype.h> | 20 | #include <linux/ctype.h> |
21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
22 | #include <net/sock.h> | 22 | #include <net/sock.h> |
@@ -824,7 +824,7 @@ static void rxrpc_free_preparse(struct key_preparsed_payload *prep) | |||
824 | */ | 824 | */ |
825 | static int rxrpc_preparse_s(struct key_preparsed_payload *prep) | 825 | static int rxrpc_preparse_s(struct key_preparsed_payload *prep) |
826 | { | 826 | { |
827 | struct crypto_blkcipher *ci; | 827 | struct crypto_skcipher *ci; |
828 | 828 | ||
829 | _enter("%zu", prep->datalen); | 829 | _enter("%zu", prep->datalen); |
830 | 830 | ||
@@ -833,13 +833,13 @@ static int rxrpc_preparse_s(struct key_preparsed_payload *prep) | |||
833 | 833 | ||
834 | memcpy(&prep->payload.data[2], prep->data, 8); | 834 | memcpy(&prep->payload.data[2], prep->data, 8); |
835 | 835 | ||
836 | ci = crypto_alloc_blkcipher("pcbc(des)", 0, CRYPTO_ALG_ASYNC); | 836 | ci = crypto_alloc_skcipher("pcbc(des)", 0, CRYPTO_ALG_ASYNC); |
837 | if (IS_ERR(ci)) { | 837 | if (IS_ERR(ci)) { |
838 | _leave(" = %ld", PTR_ERR(ci)); | 838 | _leave(" = %ld", PTR_ERR(ci)); |
839 | return PTR_ERR(ci); | 839 | return PTR_ERR(ci); |
840 | } | 840 | } |
841 | 841 | ||
842 | if (crypto_blkcipher_setkey(ci, prep->data, 8) < 0) | 842 | if (crypto_skcipher_setkey(ci, prep->data, 8) < 0) |
843 | BUG(); | 843 | BUG(); |
844 | 844 | ||
845 | prep->payload.data[0] = ci; | 845 | prep->payload.data[0] = ci; |
@@ -853,7 +853,7 @@ static int rxrpc_preparse_s(struct key_preparsed_payload *prep) | |||
853 | static void rxrpc_free_preparse_s(struct key_preparsed_payload *prep) | 853 | static void rxrpc_free_preparse_s(struct key_preparsed_payload *prep) |
854 | { | 854 | { |
855 | if (prep->payload.data[0]) | 855 | if (prep->payload.data[0]) |
856 | crypto_free_blkcipher(prep->payload.data[0]); | 856 | crypto_free_skcipher(prep->payload.data[0]); |
857 | } | 857 | } |
858 | 858 | ||
859 | /* | 859 | /* |
@@ -870,7 +870,7 @@ static void rxrpc_destroy(struct key *key) | |||
870 | static void rxrpc_destroy_s(struct key *key) | 870 | static void rxrpc_destroy_s(struct key *key) |
871 | { | 871 | { |
872 | if (key->payload.data[0]) { | 872 | if (key->payload.data[0]) { |
873 | crypto_free_blkcipher(key->payload.data[0]); | 873 | crypto_free_skcipher(key->payload.data[0]); |
874 | key->payload.data[0] = NULL; | 874 | key->payload.data[0] = NULL; |
875 | } | 875 | } |
876 | } | 876 | } |
diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c index d7a9ab5a9d9c..0d96b48a6492 100644 --- a/net/rxrpc/rxkad.c +++ b/net/rxrpc/rxkad.c | |||
@@ -9,11 +9,11 @@ | |||
9 | * 2 of the License, or (at your option) any later version. | 9 | * 2 of the License, or (at your option) any later version. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <crypto/skcipher.h> | ||
12 | #include <linux/module.h> | 13 | #include <linux/module.h> |
13 | #include <linux/net.h> | 14 | #include <linux/net.h> |
14 | #include <linux/skbuff.h> | 15 | #include <linux/skbuff.h> |
15 | #include <linux/udp.h> | 16 | #include <linux/udp.h> |
16 | #include <linux/crypto.h> | ||
17 | #include <linux/scatterlist.h> | 17 | #include <linux/scatterlist.h> |
18 | #include <linux/ctype.h> | 18 | #include <linux/ctype.h> |
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
@@ -53,7 +53,7 @@ MODULE_LICENSE("GPL"); | |||
53 | * alloc routine, but since we have it to hand, we use it to decrypt RESPONSE | 53 | * alloc routine, but since we have it to hand, we use it to decrypt RESPONSE |
54 | * packets | 54 | * packets |
55 | */ | 55 | */ |
56 | static struct crypto_blkcipher *rxkad_ci; | 56 | static struct crypto_skcipher *rxkad_ci; |
57 | static DEFINE_MUTEX(rxkad_ci_mutex); | 57 | static DEFINE_MUTEX(rxkad_ci_mutex); |
58 | 58 | ||
59 | /* | 59 | /* |
@@ -61,7 +61,7 @@ static DEFINE_MUTEX(rxkad_ci_mutex); | |||
61 | */ | 61 | */ |
62 | static int rxkad_init_connection_security(struct rxrpc_connection *conn) | 62 | static int rxkad_init_connection_security(struct rxrpc_connection *conn) |
63 | { | 63 | { |
64 | struct crypto_blkcipher *ci; | 64 | struct crypto_skcipher *ci; |
65 | struct rxrpc_key_token *token; | 65 | struct rxrpc_key_token *token; |
66 | int ret; | 66 | int ret; |
67 | 67 | ||
@@ -70,15 +70,15 @@ static int rxkad_init_connection_security(struct rxrpc_connection *conn) | |||
70 | token = conn->key->payload.data[0]; | 70 | token = conn->key->payload.data[0]; |
71 | conn->security_ix = token->security_index; | 71 | conn->security_ix = token->security_index; |
72 | 72 | ||
73 | ci = crypto_alloc_blkcipher("pcbc(fcrypt)", 0, CRYPTO_ALG_ASYNC); | 73 | ci = crypto_alloc_skcipher("pcbc(fcrypt)", 0, CRYPTO_ALG_ASYNC); |
74 | if (IS_ERR(ci)) { | 74 | if (IS_ERR(ci)) { |
75 | _debug("no cipher"); | 75 | _debug("no cipher"); |
76 | ret = PTR_ERR(ci); | 76 | ret = PTR_ERR(ci); |
77 | goto error; | 77 | goto error; |
78 | } | 78 | } |
79 | 79 | ||
80 | if (crypto_blkcipher_setkey(ci, token->kad->session_key, | 80 | if (crypto_skcipher_setkey(ci, token->kad->session_key, |
81 | sizeof(token->kad->session_key)) < 0) | 81 | sizeof(token->kad->session_key)) < 0) |
82 | BUG(); | 82 | BUG(); |
83 | 83 | ||
84 | switch (conn->security_level) { | 84 | switch (conn->security_level) { |
@@ -113,7 +113,7 @@ error: | |||
113 | static void rxkad_prime_packet_security(struct rxrpc_connection *conn) | 113 | static void rxkad_prime_packet_security(struct rxrpc_connection *conn) |
114 | { | 114 | { |
115 | struct rxrpc_key_token *token; | 115 | struct rxrpc_key_token *token; |
116 | struct blkcipher_desc desc; | 116 | SKCIPHER_REQUEST_ON_STACK(req, conn->cipher); |
117 | struct scatterlist sg[2]; | 117 | struct scatterlist sg[2]; |
118 | struct rxrpc_crypt iv; | 118 | struct rxrpc_crypt iv; |
119 | struct { | 119 | struct { |
@@ -128,10 +128,6 @@ static void rxkad_prime_packet_security(struct rxrpc_connection *conn) | |||
128 | token = conn->key->payload.data[0]; | 128 | token = conn->key->payload.data[0]; |
129 | memcpy(&iv, token->kad->session_key, sizeof(iv)); | 129 | memcpy(&iv, token->kad->session_key, sizeof(iv)); |
130 | 130 | ||
131 | desc.tfm = conn->cipher; | ||
132 | desc.info = iv.x; | ||
133 | desc.flags = 0; | ||
134 | |||
135 | tmpbuf.x[0] = conn->epoch; | 131 | tmpbuf.x[0] = conn->epoch; |
136 | tmpbuf.x[1] = conn->cid; | 132 | tmpbuf.x[1] = conn->cid; |
137 | tmpbuf.x[2] = 0; | 133 | tmpbuf.x[2] = 0; |
@@ -139,7 +135,13 @@ static void rxkad_prime_packet_security(struct rxrpc_connection *conn) | |||
139 | 135 | ||
140 | sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf)); | 136 | sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf)); |
141 | sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf)); | 137 | sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf)); |
142 | crypto_blkcipher_encrypt_iv(&desc, &sg[0], &sg[1], sizeof(tmpbuf)); | 138 | |
139 | skcipher_request_set_tfm(req, conn->cipher); | ||
140 | skcipher_request_set_callback(req, 0, NULL, NULL); | ||
141 | skcipher_request_set_crypt(req, &sg[1], &sg[0], sizeof(tmpbuf), iv.x); | ||
142 | |||
143 | crypto_skcipher_encrypt(req); | ||
144 | skcipher_request_zero(req); | ||
143 | 145 | ||
144 | memcpy(&conn->csum_iv, &tmpbuf.x[2], sizeof(conn->csum_iv)); | 146 | memcpy(&conn->csum_iv, &tmpbuf.x[2], sizeof(conn->csum_iv)); |
145 | ASSERTCMP(conn->csum_iv.n[0], ==, tmpbuf.x[2]); | 147 | ASSERTCMP(conn->csum_iv.n[0], ==, tmpbuf.x[2]); |
@@ -156,7 +158,7 @@ static int rxkad_secure_packet_auth(const struct rxrpc_call *call, | |||
156 | void *sechdr) | 158 | void *sechdr) |
157 | { | 159 | { |
158 | struct rxrpc_skb_priv *sp; | 160 | struct rxrpc_skb_priv *sp; |
159 | struct blkcipher_desc desc; | 161 | SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher); |
160 | struct rxrpc_crypt iv; | 162 | struct rxrpc_crypt iv; |
161 | struct scatterlist sg[2]; | 163 | struct scatterlist sg[2]; |
162 | struct { | 164 | struct { |
@@ -177,13 +179,16 @@ static int rxkad_secure_packet_auth(const struct rxrpc_call *call, | |||
177 | 179 | ||
178 | /* start the encryption afresh */ | 180 | /* start the encryption afresh */ |
179 | memset(&iv, 0, sizeof(iv)); | 181 | memset(&iv, 0, sizeof(iv)); |
180 | desc.tfm = call->conn->cipher; | ||
181 | desc.info = iv.x; | ||
182 | desc.flags = 0; | ||
183 | 182 | ||
184 | sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf)); | 183 | sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf)); |
185 | sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf)); | 184 | sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf)); |
186 | crypto_blkcipher_encrypt_iv(&desc, &sg[0], &sg[1], sizeof(tmpbuf)); | 185 | |
186 | skcipher_request_set_tfm(req, call->conn->cipher); | ||
187 | skcipher_request_set_callback(req, 0, NULL, NULL); | ||
188 | skcipher_request_set_crypt(req, &sg[1], &sg[0], sizeof(tmpbuf), iv.x); | ||
189 | |||
190 | crypto_skcipher_encrypt(req); | ||
191 | skcipher_request_zero(req); | ||
187 | 192 | ||
188 | memcpy(sechdr, &tmpbuf, sizeof(tmpbuf)); | 193 | memcpy(sechdr, &tmpbuf, sizeof(tmpbuf)); |
189 | 194 | ||
@@ -203,13 +208,14 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call, | |||
203 | struct rxkad_level2_hdr rxkhdr | 208 | struct rxkad_level2_hdr rxkhdr |
204 | __attribute__((aligned(8))); /* must be all on one page */ | 209 | __attribute__((aligned(8))); /* must be all on one page */ |
205 | struct rxrpc_skb_priv *sp; | 210 | struct rxrpc_skb_priv *sp; |
206 | struct blkcipher_desc desc; | 211 | SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher); |
207 | struct rxrpc_crypt iv; | 212 | struct rxrpc_crypt iv; |
208 | struct scatterlist sg[16]; | 213 | struct scatterlist sg[16]; |
209 | struct sk_buff *trailer; | 214 | struct sk_buff *trailer; |
210 | unsigned int len; | 215 | unsigned int len; |
211 | u16 check; | 216 | u16 check; |
212 | int nsg; | 217 | int nsg; |
218 | int err; | ||
213 | 219 | ||
214 | sp = rxrpc_skb(skb); | 220 | sp = rxrpc_skb(skb); |
215 | 221 | ||
@@ -223,28 +229,38 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call, | |||
223 | /* encrypt from the session key */ | 229 | /* encrypt from the session key */ |
224 | token = call->conn->key->payload.data[0]; | 230 | token = call->conn->key->payload.data[0]; |
225 | memcpy(&iv, token->kad->session_key, sizeof(iv)); | 231 | memcpy(&iv, token->kad->session_key, sizeof(iv)); |
226 | desc.tfm = call->conn->cipher; | ||
227 | desc.info = iv.x; | ||
228 | desc.flags = 0; | ||
229 | 232 | ||
230 | sg_init_one(&sg[0], sechdr, sizeof(rxkhdr)); | 233 | sg_init_one(&sg[0], sechdr, sizeof(rxkhdr)); |
231 | sg_init_one(&sg[1], &rxkhdr, sizeof(rxkhdr)); | 234 | sg_init_one(&sg[1], &rxkhdr, sizeof(rxkhdr)); |
232 | crypto_blkcipher_encrypt_iv(&desc, &sg[0], &sg[1], sizeof(rxkhdr)); | 235 | |
236 | skcipher_request_set_tfm(req, call->conn->cipher); | ||
237 | skcipher_request_set_callback(req, 0, NULL, NULL); | ||
238 | skcipher_request_set_crypt(req, &sg[1], &sg[0], sizeof(rxkhdr), iv.x); | ||
239 | |||
240 | crypto_skcipher_encrypt(req); | ||
233 | 241 | ||
234 | /* we want to encrypt the skbuff in-place */ | 242 | /* we want to encrypt the skbuff in-place */ |
235 | nsg = skb_cow_data(skb, 0, &trailer); | 243 | nsg = skb_cow_data(skb, 0, &trailer); |
244 | err = -ENOMEM; | ||
236 | if (nsg < 0 || nsg > 16) | 245 | if (nsg < 0 || nsg > 16) |
237 | return -ENOMEM; | 246 | goto out; |
238 | 247 | ||
239 | len = data_size + call->conn->size_align - 1; | 248 | len = data_size + call->conn->size_align - 1; |
240 | len &= ~(call->conn->size_align - 1); | 249 | len &= ~(call->conn->size_align - 1); |
241 | 250 | ||
242 | sg_init_table(sg, nsg); | 251 | sg_init_table(sg, nsg); |
243 | skb_to_sgvec(skb, sg, 0, len); | 252 | skb_to_sgvec(skb, sg, 0, len); |
244 | crypto_blkcipher_encrypt_iv(&desc, sg, sg, len); | 253 | |
254 | skcipher_request_set_crypt(req, sg, sg, len, iv.x); | ||
255 | |||
256 | crypto_skcipher_encrypt(req); | ||
245 | 257 | ||
246 | _leave(" = 0"); | 258 | _leave(" = 0"); |
247 | return 0; | 259 | err = 0; |
260 | |||
261 | out: | ||
262 | skcipher_request_zero(req); | ||
263 | return err; | ||
248 | } | 264 | } |
249 | 265 | ||
250 | /* | 266 | /* |
@@ -256,7 +272,7 @@ static int rxkad_secure_packet(const struct rxrpc_call *call, | |||
256 | void *sechdr) | 272 | void *sechdr) |
257 | { | 273 | { |
258 | struct rxrpc_skb_priv *sp; | 274 | struct rxrpc_skb_priv *sp; |
259 | struct blkcipher_desc desc; | 275 | SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher); |
260 | struct rxrpc_crypt iv; | 276 | struct rxrpc_crypt iv; |
261 | struct scatterlist sg[2]; | 277 | struct scatterlist sg[2]; |
262 | struct { | 278 | struct { |
@@ -281,9 +297,6 @@ static int rxkad_secure_packet(const struct rxrpc_call *call, | |||
281 | 297 | ||
282 | /* continue encrypting from where we left off */ | 298 | /* continue encrypting from where we left off */ |
283 | memcpy(&iv, call->conn->csum_iv.x, sizeof(iv)); | 299 | memcpy(&iv, call->conn->csum_iv.x, sizeof(iv)); |
284 | desc.tfm = call->conn->cipher; | ||
285 | desc.info = iv.x; | ||
286 | desc.flags = 0; | ||
287 | 300 | ||
288 | /* calculate the security checksum */ | 301 | /* calculate the security checksum */ |
289 | x = htonl(call->channel << (32 - RXRPC_CIDSHIFT)); | 302 | x = htonl(call->channel << (32 - RXRPC_CIDSHIFT)); |
@@ -293,7 +306,13 @@ static int rxkad_secure_packet(const struct rxrpc_call *call, | |||
293 | 306 | ||
294 | sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf)); | 307 | sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf)); |
295 | sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf)); | 308 | sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf)); |
296 | crypto_blkcipher_encrypt_iv(&desc, &sg[0], &sg[1], sizeof(tmpbuf)); | 309 | |
310 | skcipher_request_set_tfm(req, call->conn->cipher); | ||
311 | skcipher_request_set_callback(req, 0, NULL, NULL); | ||
312 | skcipher_request_set_crypt(req, &sg[1], &sg[0], sizeof(tmpbuf), iv.x); | ||
313 | |||
314 | crypto_skcipher_encrypt(req); | ||
315 | skcipher_request_zero(req); | ||
297 | 316 | ||
298 | y = ntohl(tmpbuf.x[1]); | 317 | y = ntohl(tmpbuf.x[1]); |
299 | y = (y >> 16) & 0xffff; | 318 | y = (y >> 16) & 0xffff; |
@@ -330,7 +349,7 @@ static int rxkad_verify_packet_auth(const struct rxrpc_call *call, | |||
330 | { | 349 | { |
331 | struct rxkad_level1_hdr sechdr; | 350 | struct rxkad_level1_hdr sechdr; |
332 | struct rxrpc_skb_priv *sp; | 351 | struct rxrpc_skb_priv *sp; |
333 | struct blkcipher_desc desc; | 352 | SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher); |
334 | struct rxrpc_crypt iv; | 353 | struct rxrpc_crypt iv; |
335 | struct scatterlist sg[16]; | 354 | struct scatterlist sg[16]; |
336 | struct sk_buff *trailer; | 355 | struct sk_buff *trailer; |
@@ -352,11 +371,13 @@ static int rxkad_verify_packet_auth(const struct rxrpc_call *call, | |||
352 | 371 | ||
353 | /* start the decryption afresh */ | 372 | /* start the decryption afresh */ |
354 | memset(&iv, 0, sizeof(iv)); | 373 | memset(&iv, 0, sizeof(iv)); |
355 | desc.tfm = call->conn->cipher; | ||
356 | desc.info = iv.x; | ||
357 | desc.flags = 0; | ||
358 | 374 | ||
359 | crypto_blkcipher_decrypt_iv(&desc, sg, sg, 8); | 375 | skcipher_request_set_tfm(req, call->conn->cipher); |
376 | skcipher_request_set_callback(req, 0, NULL, NULL); | ||
377 | skcipher_request_set_crypt(req, sg, sg, 8, iv.x); | ||
378 | |||
379 | crypto_skcipher_decrypt(req); | ||
380 | skcipher_request_zero(req); | ||
360 | 381 | ||
361 | /* remove the decrypted packet length */ | 382 | /* remove the decrypted packet length */ |
362 | if (skb_copy_bits(skb, 0, &sechdr, sizeof(sechdr)) < 0) | 383 | if (skb_copy_bits(skb, 0, &sechdr, sizeof(sechdr)) < 0) |
@@ -405,7 +426,7 @@ static int rxkad_verify_packet_encrypt(const struct rxrpc_call *call, | |||
405 | const struct rxrpc_key_token *token; | 426 | const struct rxrpc_key_token *token; |
406 | struct rxkad_level2_hdr sechdr; | 427 | struct rxkad_level2_hdr sechdr; |
407 | struct rxrpc_skb_priv *sp; | 428 | struct rxrpc_skb_priv *sp; |
408 | struct blkcipher_desc desc; | 429 | SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher); |
409 | struct rxrpc_crypt iv; | 430 | struct rxrpc_crypt iv; |
410 | struct scatterlist _sg[4], *sg; | 431 | struct scatterlist _sg[4], *sg; |
411 | struct sk_buff *trailer; | 432 | struct sk_buff *trailer; |
@@ -435,11 +456,13 @@ static int rxkad_verify_packet_encrypt(const struct rxrpc_call *call, | |||
435 | /* decrypt from the session key */ | 456 | /* decrypt from the session key */ |
436 | token = call->conn->key->payload.data[0]; | 457 | token = call->conn->key->payload.data[0]; |
437 | memcpy(&iv, token->kad->session_key, sizeof(iv)); | 458 | memcpy(&iv, token->kad->session_key, sizeof(iv)); |
438 | desc.tfm = call->conn->cipher; | ||
439 | desc.info = iv.x; | ||
440 | desc.flags = 0; | ||
441 | 459 | ||
442 | crypto_blkcipher_decrypt_iv(&desc, sg, sg, skb->len); | 460 | skcipher_request_set_tfm(req, call->conn->cipher); |
461 | skcipher_request_set_callback(req, 0, NULL, NULL); | ||
462 | skcipher_request_set_crypt(req, sg, sg, skb->len, iv.x); | ||
463 | |||
464 | crypto_skcipher_decrypt(req); | ||
465 | skcipher_request_zero(req); | ||
443 | if (sg != _sg) | 466 | if (sg != _sg) |
444 | kfree(sg); | 467 | kfree(sg); |
445 | 468 | ||
@@ -487,7 +510,7 @@ static int rxkad_verify_packet(const struct rxrpc_call *call, | |||
487 | struct sk_buff *skb, | 510 | struct sk_buff *skb, |
488 | u32 *_abort_code) | 511 | u32 *_abort_code) |
489 | { | 512 | { |
490 | struct blkcipher_desc desc; | 513 | SKCIPHER_REQUEST_ON_STACK(req, call->conn->cipher); |
491 | struct rxrpc_skb_priv *sp; | 514 | struct rxrpc_skb_priv *sp; |
492 | struct rxrpc_crypt iv; | 515 | struct rxrpc_crypt iv; |
493 | struct scatterlist sg[2]; | 516 | struct scatterlist sg[2]; |
@@ -516,9 +539,6 @@ static int rxkad_verify_packet(const struct rxrpc_call *call, | |||
516 | 539 | ||
517 | /* continue encrypting from where we left off */ | 540 | /* continue encrypting from where we left off */ |
518 | memcpy(&iv, call->conn->csum_iv.x, sizeof(iv)); | 541 | memcpy(&iv, call->conn->csum_iv.x, sizeof(iv)); |
519 | desc.tfm = call->conn->cipher; | ||
520 | desc.info = iv.x; | ||
521 | desc.flags = 0; | ||
522 | 542 | ||
523 | /* validate the security checksum */ | 543 | /* validate the security checksum */ |
524 | x = htonl(call->channel << (32 - RXRPC_CIDSHIFT)); | 544 | x = htonl(call->channel << (32 - RXRPC_CIDSHIFT)); |
@@ -528,7 +548,13 @@ static int rxkad_verify_packet(const struct rxrpc_call *call, | |||
528 | 548 | ||
529 | sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf)); | 549 | sg_init_one(&sg[0], &tmpbuf, sizeof(tmpbuf)); |
530 | sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf)); | 550 | sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf)); |
531 | crypto_blkcipher_encrypt_iv(&desc, &sg[0], &sg[1], sizeof(tmpbuf)); | 551 | |
552 | skcipher_request_set_tfm(req, call->conn->cipher); | ||
553 | skcipher_request_set_callback(req, 0, NULL, NULL); | ||
554 | skcipher_request_set_crypt(req, &sg[1], &sg[0], sizeof(tmpbuf), iv.x); | ||
555 | |||
556 | crypto_skcipher_encrypt(req); | ||
557 | skcipher_request_zero(req); | ||
532 | 558 | ||
533 | y = ntohl(tmpbuf.x[1]); | 559 | y = ntohl(tmpbuf.x[1]); |
534 | y = (y >> 16) & 0xffff; | 560 | y = (y >> 16) & 0xffff; |
@@ -718,18 +744,21 @@ static void rxkad_encrypt_response(struct rxrpc_connection *conn, | |||
718 | struct rxkad_response *resp, | 744 | struct rxkad_response *resp, |
719 | const struct rxkad_key *s2) | 745 | const struct rxkad_key *s2) |
720 | { | 746 | { |
721 | struct blkcipher_desc desc; | 747 | SKCIPHER_REQUEST_ON_STACK(req, conn->cipher); |
722 | struct rxrpc_crypt iv; | 748 | struct rxrpc_crypt iv; |
723 | struct scatterlist sg[2]; | 749 | struct scatterlist sg[2]; |
724 | 750 | ||
725 | /* continue encrypting from where we left off */ | 751 | /* continue encrypting from where we left off */ |
726 | memcpy(&iv, s2->session_key, sizeof(iv)); | 752 | memcpy(&iv, s2->session_key, sizeof(iv)); |
727 | desc.tfm = conn->cipher; | ||
728 | desc.info = iv.x; | ||
729 | desc.flags = 0; | ||
730 | 753 | ||
731 | rxkad_sg_set_buf2(sg, &resp->encrypted, sizeof(resp->encrypted)); | 754 | rxkad_sg_set_buf2(sg, &resp->encrypted, sizeof(resp->encrypted)); |
732 | crypto_blkcipher_encrypt_iv(&desc, sg, sg, sizeof(resp->encrypted)); | 755 | |
756 | skcipher_request_set_tfm(req, conn->cipher); | ||
757 | skcipher_request_set_callback(req, 0, NULL, NULL); | ||
758 | skcipher_request_set_crypt(req, sg, sg, sizeof(resp->encrypted), iv.x); | ||
759 | |||
760 | crypto_skcipher_encrypt(req); | ||
761 | skcipher_request_zero(req); | ||
733 | } | 762 | } |
734 | 763 | ||
735 | /* | 764 | /* |
@@ -822,7 +851,7 @@ static int rxkad_decrypt_ticket(struct rxrpc_connection *conn, | |||
822 | time_t *_expiry, | 851 | time_t *_expiry, |
823 | u32 *_abort_code) | 852 | u32 *_abort_code) |
824 | { | 853 | { |
825 | struct blkcipher_desc desc; | 854 | struct skcipher_request *req; |
826 | struct rxrpc_crypt iv, key; | 855 | struct rxrpc_crypt iv, key; |
827 | struct scatterlist sg[1]; | 856 | struct scatterlist sg[1]; |
828 | struct in_addr addr; | 857 | struct in_addr addr; |
@@ -853,12 +882,21 @@ static int rxkad_decrypt_ticket(struct rxrpc_connection *conn, | |||
853 | 882 | ||
854 | memcpy(&iv, &conn->server_key->payload.data[2], sizeof(iv)); | 883 | memcpy(&iv, &conn->server_key->payload.data[2], sizeof(iv)); |
855 | 884 | ||
856 | desc.tfm = conn->server_key->payload.data[0]; | 885 | req = skcipher_request_alloc(conn->server_key->payload.data[0], |
857 | desc.info = iv.x; | 886 | GFP_NOFS); |
858 | desc.flags = 0; | 887 | if (!req) { |
888 | *_abort_code = RXKADNOAUTH; | ||
889 | ret = -ENOMEM; | ||
890 | goto error; | ||
891 | } | ||
859 | 892 | ||
860 | sg_init_one(&sg[0], ticket, ticket_len); | 893 | sg_init_one(&sg[0], ticket, ticket_len); |
861 | crypto_blkcipher_decrypt_iv(&desc, sg, sg, ticket_len); | 894 | |
895 | skcipher_request_set_callback(req, 0, NULL, NULL); | ||
896 | skcipher_request_set_crypt(req, sg, sg, ticket_len, iv.x); | ||
897 | |||
898 | crypto_skcipher_decrypt(req); | ||
899 | skcipher_request_free(req); | ||
862 | 900 | ||
863 | p = ticket; | 901 | p = ticket; |
864 | end = p + ticket_len; | 902 | end = p + ticket_len; |
@@ -966,7 +1004,7 @@ static void rxkad_decrypt_response(struct rxrpc_connection *conn, | |||
966 | struct rxkad_response *resp, | 1004 | struct rxkad_response *resp, |
967 | const struct rxrpc_crypt *session_key) | 1005 | const struct rxrpc_crypt *session_key) |
968 | { | 1006 | { |
969 | struct blkcipher_desc desc; | 1007 | SKCIPHER_REQUEST_ON_STACK(req, rxkad_ci); |
970 | struct scatterlist sg[2]; | 1008 | struct scatterlist sg[2]; |
971 | struct rxrpc_crypt iv; | 1009 | struct rxrpc_crypt iv; |
972 | 1010 | ||
@@ -976,17 +1014,21 @@ static void rxkad_decrypt_response(struct rxrpc_connection *conn, | |||
976 | ASSERT(rxkad_ci != NULL); | 1014 | ASSERT(rxkad_ci != NULL); |
977 | 1015 | ||
978 | mutex_lock(&rxkad_ci_mutex); | 1016 | mutex_lock(&rxkad_ci_mutex); |
979 | if (crypto_blkcipher_setkey(rxkad_ci, session_key->x, | 1017 | if (crypto_skcipher_setkey(rxkad_ci, session_key->x, |
980 | sizeof(*session_key)) < 0) | 1018 | sizeof(*session_key)) < 0) |
981 | BUG(); | 1019 | BUG(); |
982 | 1020 | ||
983 | memcpy(&iv, session_key, sizeof(iv)); | 1021 | memcpy(&iv, session_key, sizeof(iv)); |
984 | desc.tfm = rxkad_ci; | ||
985 | desc.info = iv.x; | ||
986 | desc.flags = 0; | ||
987 | 1022 | ||
988 | rxkad_sg_set_buf2(sg, &resp->encrypted, sizeof(resp->encrypted)); | 1023 | rxkad_sg_set_buf2(sg, &resp->encrypted, sizeof(resp->encrypted)); |
989 | crypto_blkcipher_decrypt_iv(&desc, sg, sg, sizeof(resp->encrypted)); | 1024 | |
1025 | skcipher_request_set_tfm(req, rxkad_ci); | ||
1026 | skcipher_request_set_callback(req, 0, NULL, NULL); | ||
1027 | skcipher_request_set_crypt(req, sg, sg, sizeof(resp->encrypted), iv.x); | ||
1028 | |||
1029 | crypto_skcipher_decrypt(req); | ||
1030 | skcipher_request_zero(req); | ||
1031 | |||
990 | mutex_unlock(&rxkad_ci_mutex); | 1032 | mutex_unlock(&rxkad_ci_mutex); |
991 | 1033 | ||
992 | _leave(""); | 1034 | _leave(""); |
@@ -1115,7 +1157,7 @@ static void rxkad_clear(struct rxrpc_connection *conn) | |||
1115 | _enter(""); | 1157 | _enter(""); |
1116 | 1158 | ||
1117 | if (conn->cipher) | 1159 | if (conn->cipher) |
1118 | crypto_free_blkcipher(conn->cipher); | 1160 | crypto_free_skcipher(conn->cipher); |
1119 | } | 1161 | } |
1120 | 1162 | ||
1121 | /* | 1163 | /* |
@@ -1141,7 +1183,7 @@ static __init int rxkad_init(void) | |||
1141 | 1183 | ||
1142 | /* pin the cipher we need so that the crypto layer doesn't invoke | 1184 | /* pin the cipher we need so that the crypto layer doesn't invoke |
1143 | * keventd to go get it */ | 1185 | * keventd to go get it */ |
1144 | rxkad_ci = crypto_alloc_blkcipher("pcbc(fcrypt)", 0, CRYPTO_ALG_ASYNC); | 1186 | rxkad_ci = crypto_alloc_skcipher("pcbc(fcrypt)", 0, CRYPTO_ALG_ASYNC); |
1145 | if (IS_ERR(rxkad_ci)) | 1187 | if (IS_ERR(rxkad_ci)) |
1146 | return PTR_ERR(rxkad_ci); | 1188 | return PTR_ERR(rxkad_ci); |
1147 | 1189 | ||
@@ -1155,7 +1197,7 @@ static __exit void rxkad_exit(void) | |||
1155 | _enter(""); | 1197 | _enter(""); |
1156 | 1198 | ||
1157 | rxrpc_unregister_security(&rxkad); | 1199 | rxrpc_unregister_security(&rxkad); |
1158 | crypto_free_blkcipher(rxkad_ci); | 1200 | crypto_free_skcipher(rxkad_ci); |
1159 | } | 1201 | } |
1160 | 1202 | ||
1161 | module_exit(rxkad_exit); | 1203 | module_exit(rxkad_exit); |