| .. | .. | 
|---|
 | 1 | +// SPDX-License-Identifier: GPL-2.0-or-later  | 
|---|
| 1 | 2 |  /** | 
|---|
| 2 | 3 |   * AMCC SoC PPC4xx Crypto Driver | 
|---|
| 3 | 4 |   * | 
|---|
| 4 | 5 |   * Copyright (c) 2008 Applied Micro Circuits Corporation. | 
|---|
| 5 | 6 |   * All rights reserved. James Hsiao <jhsiao@amcc.com> | 
|---|
| 6 |  | - *  | 
|---|
| 7 |  | - * This program is free software; you can redistribute it and/or modify  | 
|---|
| 8 |  | - * it under the terms of the GNU General Public License as published by  | 
|---|
| 9 |  | - * the Free Software Foundation; either version 2 of the License, or  | 
|---|
| 10 |  | - * (at your option) any later version.  | 
|---|
| 11 |  | - *  | 
|---|
| 12 |  | - * This program is distributed in the hope that it will be useful,  | 
|---|
| 13 |  | - * but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
|---|
| 14 |  | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  | 
|---|
| 15 |  | - * GNU General Public License for more details.  | 
|---|
| 16 | 7 |   * | 
|---|
| 17 | 8 |   * This file implements the Linux crypto algorithms. | 
|---|
| 18 | 9 |   */ | 
|---|
| .. | .. | 
|---|
| 64 | 55 |  	sa->sa_command_1.w = 0; | 
|---|
| 65 | 56 |  	sa->sa_command_1.bf.crypto_mode31 = (cm & 4) >> 2; | 
|---|
| 66 | 57 |  	sa->sa_command_1.bf.crypto_mode9_8 = cm & 3; | 
|---|
| 67 |  | -	sa->sa_command_1.bf.feedback_mode = cfb,  | 
|---|
 | 58 | +	sa->sa_command_1.bf.feedback_mode = cfb;  | 
|---|
| 68 | 59 |  	sa->sa_command_1.bf.sa_rev = 1; | 
|---|
| 69 | 60 |  	sa->sa_command_1.bf.hmac_muting = hmac_mc; | 
|---|
| 70 | 61 |  	sa->sa_command_1.bf.extended_seq_num = esn; | 
|---|
| .. | .. | 
|---|
| 137 | 128 |  	struct dynamic_sa_ctl *sa; | 
|---|
| 138 | 129 |  	int    rc; | 
|---|
| 139 | 130 |   | 
|---|
| 140 |  | -	if (keylen != AES_KEYSIZE_256 &&  | 
|---|
| 141 |  | -		keylen != AES_KEYSIZE_192 && keylen != AES_KEYSIZE_128) {  | 
|---|
| 142 |  | -		crypto_skcipher_set_flags(cipher,  | 
|---|
| 143 |  | -				CRYPTO_TFM_RES_BAD_KEY_LEN);  | 
|---|
 | 131 | +	if (keylen != AES_KEYSIZE_256 && keylen != AES_KEYSIZE_192 &&  | 
|---|
 | 132 | +	    keylen != AES_KEYSIZE_128)  | 
|---|
| 144 | 133 |  		return -EINVAL; | 
|---|
| 145 |  | -	}  | 
|---|
| 146 | 134 |   | 
|---|
| 147 | 135 |  	/* Create SA */ | 
|---|
| 148 | 136 |  	if (ctx->sa_in || ctx->sa_out) | 
|---|
| .. | .. | 
|---|
| 278 | 266 |  	 * overlow. | 
|---|
| 279 | 267 |  	 */ | 
|---|
| 280 | 268 |  	if (counter + nblks < counter) { | 
|---|
| 281 |  | -		struct skcipher_request *subreq = skcipher_request_ctx(req);  | 
|---|
 | 269 | +		SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, ctx->sw_cipher.cipher);  | 
|---|
| 282 | 270 |  		int ret; | 
|---|
| 283 | 271 |   | 
|---|
| 284 |  | -		skcipher_request_set_tfm(subreq, ctx->sw_cipher.cipher);  | 
|---|
 | 272 | +		skcipher_request_set_sync_tfm(subreq, ctx->sw_cipher.cipher);  | 
|---|
| 285 | 273 |  		skcipher_request_set_callback(subreq, req->base.flags, | 
|---|
| 286 | 274 |  			NULL, NULL); | 
|---|
| 287 | 275 |  		skcipher_request_set_crypt(subreq, req->src, req->dst, | 
|---|
| .. | .. | 
|---|
| 301 | 289 |  				       const u8 *key, | 
|---|
| 302 | 290 |  				       unsigned int keylen) | 
|---|
| 303 | 291 |  { | 
|---|
| 304 |  | -	int rc;  | 
|---|
| 305 |  | -  | 
|---|
| 306 |  | -	crypto_skcipher_clear_flags(ctx->sw_cipher.cipher,  | 
|---|
 | 292 | +	crypto_sync_skcipher_clear_flags(ctx->sw_cipher.cipher,  | 
|---|
| 307 | 293 |  				    CRYPTO_TFM_REQ_MASK); | 
|---|
| 308 |  | -	crypto_skcipher_set_flags(ctx->sw_cipher.cipher,  | 
|---|
 | 294 | +	crypto_sync_skcipher_set_flags(ctx->sw_cipher.cipher,  | 
|---|
| 309 | 295 |  		crypto_skcipher_get_flags(cipher) & CRYPTO_TFM_REQ_MASK); | 
|---|
| 310 |  | -	rc = crypto_skcipher_setkey(ctx->sw_cipher.cipher, key, keylen);  | 
|---|
| 311 |  | -	crypto_skcipher_clear_flags(cipher, CRYPTO_TFM_RES_MASK);  | 
|---|
| 312 |  | -	crypto_skcipher_set_flags(cipher,  | 
|---|
| 313 |  | -		crypto_skcipher_get_flags(ctx->sw_cipher.cipher) &  | 
|---|
| 314 |  | -			CRYPTO_TFM_RES_MASK);  | 
|---|
| 315 |  | -  | 
|---|
| 316 |  | -	return rc;  | 
|---|
 | 296 | +	return crypto_sync_skcipher_setkey(ctx->sw_cipher.cipher, key, keylen);  | 
|---|
| 317 | 297 |  } | 
|---|
| 318 | 298 |   | 
|---|
| 319 | 299 |  int crypto4xx_setkey_aes_ctr(struct crypto_skcipher *cipher, | 
|---|
| .. | .. | 
|---|
| 388 | 368 |  					 const u8 *key, | 
|---|
| 389 | 369 |  					 unsigned int keylen) | 
|---|
| 390 | 370 |  { | 
|---|
| 391 |  | -	int rc;  | 
|---|
| 392 |  | -  | 
|---|
| 393 | 371 |  	crypto_aead_clear_flags(ctx->sw_cipher.aead, CRYPTO_TFM_REQ_MASK); | 
|---|
| 394 | 372 |  	crypto_aead_set_flags(ctx->sw_cipher.aead, | 
|---|
| 395 | 373 |  		crypto_aead_get_flags(cipher) & CRYPTO_TFM_REQ_MASK); | 
|---|
| 396 |  | -	rc = crypto_aead_setkey(ctx->sw_cipher.aead, key, keylen);  | 
|---|
| 397 |  | -	crypto_aead_clear_flags(cipher, CRYPTO_TFM_RES_MASK);  | 
|---|
| 398 |  | -	crypto_aead_set_flags(cipher,  | 
|---|
| 399 |  | -		crypto_aead_get_flags(ctx->sw_cipher.aead) &  | 
|---|
| 400 |  | -			CRYPTO_TFM_RES_MASK);  | 
|---|
| 401 |  | -  | 
|---|
| 402 |  | -	return rc;  | 
|---|
 | 374 | +	return crypto_aead_setkey(ctx->sw_cipher.aead, key, keylen);  | 
|---|
| 403 | 375 |  } | 
|---|
| 404 | 376 |   | 
|---|
| 405 | 377 |  /** | 
|---|
| .. | .. | 
|---|
| 536 | 508 |  static int crypto4xx_compute_gcm_hash_key_sw(__le32 *hash_start, const u8 *key, | 
|---|
| 537 | 509 |  					     unsigned int keylen) | 
|---|
| 538 | 510 |  { | 
|---|
| 539 |  | -	struct crypto_cipher *aes_tfm = NULL;  | 
|---|
 | 511 | +	struct crypto_aes_ctx ctx;  | 
|---|
| 540 | 512 |  	uint8_t src[16] = { 0 }; | 
|---|
| 541 |  | -	int rc = 0;  | 
|---|
 | 513 | +	int rc;  | 
|---|
| 542 | 514 |   | 
|---|
| 543 |  | -	aes_tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC |  | 
|---|
| 544 |  | -				      CRYPTO_ALG_NEED_FALLBACK);  | 
|---|
| 545 |  | -	if (IS_ERR(aes_tfm)) {  | 
|---|
| 546 |  | -		rc = PTR_ERR(aes_tfm);  | 
|---|
| 547 |  | -		pr_warn("could not load aes cipher driver: %d\n", rc);  | 
|---|
 | 515 | +	rc = aes_expandkey(&ctx, key, keylen);  | 
|---|
 | 516 | +	if (rc) {  | 
|---|
 | 517 | +		pr_err("aes_expandkey() failed: %d\n", rc);  | 
|---|
| 548 | 518 |  		return rc; | 
|---|
| 549 | 519 |  	} | 
|---|
| 550 | 520 |   | 
|---|
| 551 |  | -	rc = crypto_cipher_setkey(aes_tfm, key, keylen);  | 
|---|
| 552 |  | -	if (rc) {  | 
|---|
| 553 |  | -		pr_err("setkey() failed: %d\n", rc);  | 
|---|
| 554 |  | -		goto out;  | 
|---|
| 555 |  | -	}  | 
|---|
| 556 |  | -  | 
|---|
| 557 |  | -	crypto_cipher_encrypt_one(aes_tfm, src, src);  | 
|---|
 | 521 | +	aes_encrypt(&ctx, src, src);  | 
|---|
| 558 | 522 |  	crypto4xx_memcpy_to_le32(hash_start, src, 16); | 
|---|
| 559 |  | -out:  | 
|---|
| 560 |  | -	crypto_free_cipher(aes_tfm);  | 
|---|
| 561 |  | -	return rc;  | 
|---|
 | 523 | +	memzero_explicit(&ctx, sizeof(ctx));  | 
|---|
 | 524 | +	return 0;  | 
|---|
| 562 | 525 |  } | 
|---|
| 563 | 526 |   | 
|---|
| 564 | 527 |  int crypto4xx_setkey_aes_gcm(struct crypto_aead *cipher, | 
|---|
| .. | .. | 
|---|
| 569 | 532 |  	struct dynamic_sa_ctl *sa; | 
|---|
| 570 | 533 |  	int    rc = 0; | 
|---|
| 571 | 534 |   | 
|---|
| 572 |  | -	if (crypto4xx_aes_gcm_validate_keylen(keylen) != 0) {  | 
|---|
| 573 |  | -		crypto_aead_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);  | 
|---|
 | 535 | +	if (crypto4xx_aes_gcm_validate_keylen(keylen) != 0)  | 
|---|
| 574 | 536 |  		return -EINVAL; | 
|---|
| 575 |  | -	}  | 
|---|
| 576 | 537 |   | 
|---|
| 577 | 538 |  	rc = crypto4xx_aead_setup_fallback(ctx, cipher, key, keylen); | 
|---|
| 578 | 539 |  	if (rc) | 
|---|