forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/net/ppp/ppp_mppe.c
....@@ -42,9 +42,10 @@
4242 * deprecated in 2.6
4343 */
4444
45
+#include <crypto/arc4.h>
4546 #include <crypto/hash.h>
46
-#include <crypto/skcipher.h>
4747 #include <linux/err.h>
48
+#include <linux/fips.h>
4849 #include <linux/module.h>
4950 #include <linux/kernel.h>
5051 #include <linux/init.h>
....@@ -63,15 +64,7 @@
6364 MODULE_DESCRIPTION("Point-to-Point Protocol Microsoft Point-to-Point Encryption support");
6465 MODULE_LICENSE("Dual BSD/GPL");
6566 MODULE_ALIAS("ppp-compress-" __stringify(CI_MPPE));
66
-MODULE_SOFTDEP("pre: arc4");
6767 MODULE_VERSION("1.0.2");
68
-
69
-static unsigned int
70
-setup_sg(struct scatterlist *sg, const void *address, unsigned int length)
71
-{
72
- sg_set_buf(sg, address, length);
73
- return length;
74
-}
7568
7669 #define SHA1_PAD_SIZE 40
7770
....@@ -96,7 +89,7 @@
9689 * State for an MPPE (de)compressor.
9790 */
9891 struct ppp_mppe_state {
99
- struct crypto_skcipher *arc4;
92
+ struct arc4_ctx arc4;
10093 struct shash_desc *sha1;
10194 unsigned char *sha1_digest;
10295 unsigned char master_key[MPPE_MAX_KEY_LEN];
....@@ -155,24 +148,11 @@
155148 */
156149 static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
157150 {
158
- struct scatterlist sg_in[1], sg_out[1];
159
- SKCIPHER_REQUEST_ON_STACK(req, state->arc4);
160
-
161
- skcipher_request_set_tfm(req, state->arc4);
162
- skcipher_request_set_callback(req, 0, NULL, NULL);
163
-
164151 get_new_key_from_sha(state);
165152 if (!initial_key) {
166
- crypto_skcipher_setkey(state->arc4, state->sha1_digest,
167
- state->keylen);
168
- sg_init_table(sg_in, 1);
169
- sg_init_table(sg_out, 1);
170
- setup_sg(sg_in, state->sha1_digest, state->keylen);
171
- setup_sg(sg_out, state->session_key, state->keylen);
172
- skcipher_request_set_crypt(req, sg_in, sg_out, state->keylen,
173
- NULL);
174
- if (crypto_skcipher_encrypt(req))
175
- printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
153
+ arc4_setkey(&state->arc4, state->sha1_digest, state->keylen);
154
+ arc4_crypt(&state->arc4, state->session_key, state->sha1_digest,
155
+ state->keylen);
176156 } else {
177157 memcpy(state->session_key, state->sha1_digest, state->keylen);
178158 }
....@@ -182,8 +162,7 @@
182162 state->session_key[1] = 0x26;
183163 state->session_key[2] = 0x9e;
184164 }
185
- crypto_skcipher_setkey(state->arc4, state->session_key, state->keylen);
186
- skcipher_request_zero(req);
165
+ arc4_setkey(&state->arc4, state->session_key, state->keylen);
187166 }
188167
189168 /*
....@@ -196,19 +175,14 @@
196175 unsigned int digestsize;
197176
198177 if (optlen != CILEN_MPPE + sizeof(state->master_key) ||
199
- options[0] != CI_MPPE || options[1] != CILEN_MPPE)
178
+ options[0] != CI_MPPE || options[1] != CILEN_MPPE ||
179
+ fips_enabled)
200180 goto out;
201181
202182 state = kzalloc(sizeof(*state), GFP_KERNEL);
203183 if (state == NULL)
204184 goto out;
205185
206
-
207
- state->arc4 = crypto_alloc_skcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
208
- if (IS_ERR(state->arc4)) {
209
- state->arc4 = NULL;
210
- goto out_free;
211
- }
212186
213187 shash = crypto_alloc_shash("sha1", 0, 0);
214188 if (IS_ERR(shash))
....@@ -222,7 +196,6 @@
222196 goto out_free;
223197 }
224198 state->sha1->tfm = shash;
225
- state->sha1->flags = 0;
226199
227200 digestsize = crypto_shash_digestsize(shash);
228201 if (digestsize < MPPE_MAX_KEY_LEN)
....@@ -249,9 +222,8 @@
249222 kfree(state->sha1_digest);
250223 if (state->sha1) {
251224 crypto_free_shash(state->sha1->tfm);
252
- kzfree(state->sha1);
225
+ kfree_sensitive(state->sha1);
253226 }
254
- crypto_free_skcipher(state->arc4);
255227 kfree(state);
256228 out:
257229 return NULL;
....@@ -266,9 +238,8 @@
266238 if (state) {
267239 kfree(state->sha1_digest);
268240 crypto_free_shash(state->sha1->tfm);
269
- kzfree(state->sha1);
270
- crypto_free_skcipher(state->arc4);
271
- kfree(state);
241
+ kfree_sensitive(state->sha1);
242
+ kfree_sensitive(state);
272243 }
273244 }
274245
....@@ -367,10 +338,7 @@
367338 int isize, int osize)
368339 {
369340 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
370
- SKCIPHER_REQUEST_ON_STACK(req, state->arc4);
371341 int proto;
372
- int err;
373
- struct scatterlist sg_in[1], sg_out[1];
374342
375343 /*
376344 * Check that the protocol is in the range we handle.
....@@ -421,21 +389,7 @@
421389 ibuf += 2; /* skip to proto field */
422390 isize -= 2;
423391
424
- /* Encrypt packet */
425
- sg_init_table(sg_in, 1);
426
- sg_init_table(sg_out, 1);
427
- setup_sg(sg_in, ibuf, isize);
428
- setup_sg(sg_out, obuf, osize);
429
-
430
- skcipher_request_set_tfm(req, state->arc4);
431
- skcipher_request_set_callback(req, 0, NULL, NULL);
432
- skcipher_request_set_crypt(req, sg_in, sg_out, isize, NULL);
433
- err = crypto_skcipher_encrypt(req);
434
- skcipher_request_zero(req);
435
- if (err) {
436
- printk(KERN_DEBUG "crypto_cypher_encrypt failed\n");
437
- return -1;
438
- }
392
+ arc4_crypt(&state->arc4, obuf, ibuf, isize);
439393
440394 state->stats.unc_bytes += isize;
441395 state->stats.unc_packets++;
....@@ -481,10 +435,8 @@
481435 int osize)
482436 {
483437 struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
484
- SKCIPHER_REQUEST_ON_STACK(req, state->arc4);
485438 unsigned ccount;
486439 int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED;
487
- struct scatterlist sg_in[1], sg_out[1];
488440
489441 if (isize <= PPP_HDRLEN + MPPE_OVHD) {
490442 if (state->debug)
....@@ -611,19 +563,7 @@
611563 * Decrypt the first byte in order to check if it is
612564 * a compressed or uncompressed protocol field.
613565 */
614
- sg_init_table(sg_in, 1);
615
- sg_init_table(sg_out, 1);
616
- setup_sg(sg_in, ibuf, 1);
617
- setup_sg(sg_out, obuf, 1);
618
-
619
- skcipher_request_set_tfm(req, state->arc4);
620
- skcipher_request_set_callback(req, 0, NULL, NULL);
621
- skcipher_request_set_crypt(req, sg_in, sg_out, 1, NULL);
622
- if (crypto_skcipher_decrypt(req)) {
623
- printk(KERN_DEBUG "crypto_cypher_decrypt failed\n");
624
- osize = DECOMP_ERROR;
625
- goto out_zap_req;
626
- }
566
+ arc4_crypt(&state->arc4, obuf, ibuf, 1);
627567
628568 /*
629569 * Do PFC decompression.
....@@ -638,14 +578,7 @@
638578 }
639579
640580 /* And finally, decrypt the rest of the packet. */
641
- setup_sg(sg_in, ibuf + 1, isize - 1);
642
- setup_sg(sg_out, obuf + 1, osize - 1);
643
- skcipher_request_set_crypt(req, sg_in, sg_out, isize - 1, NULL);
644
- if (crypto_skcipher_decrypt(req)) {
645
- printk(KERN_DEBUG "crypto_cypher_decrypt failed\n");
646
- osize = DECOMP_ERROR;
647
- goto out_zap_req;
648
- }
581
+ arc4_crypt(&state->arc4, obuf + 1, ibuf + 1, isize - 1);
649582
650583 state->stats.unc_bytes += osize;
651584 state->stats.unc_packets++;
....@@ -655,8 +588,6 @@
655588 /* good packet credit */
656589 state->sanity_errors >>= 1;
657590
658
-out_zap_req:
659
- skcipher_request_zero(req);
660591 return osize;
661592
662593 sanity_error:
....@@ -729,8 +660,7 @@
729660 static int __init ppp_mppe_init(void)
730661 {
731662 int answer;
732
- if (!(crypto_has_skcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC) &&
733
- crypto_has_ahash("sha1", 0, CRYPTO_ALG_ASYNC)))
663
+ if (fips_enabled || !crypto_has_ahash("sha1", 0, CRYPTO_ALG_ASYNC))
734664 return -ENODEV;
735665
736666 sha_pad = kmalloc(sizeof(struct sha_pad), GFP_KERNEL);