| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright 2016 Broadcom |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 5 | | - * it under the terms of the GNU General Public License, version 2, as |
|---|
| 6 | | - * published by the Free Software Foundation (the "GPL"). |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is distributed in the hope that it will be useful, but |
|---|
| 9 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 11 | | - * General Public License version 2 (GPLv2) for more details. |
|---|
| 12 | | - * |
|---|
| 13 | | - * You should have received a copy of the GNU General Public License |
|---|
| 14 | | - * version 2 (GPLv2) along with this source code. |
|---|
| 15 | 4 | */ |
|---|
| 16 | 5 | |
|---|
| 17 | 6 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 21 | 10 | #include "spu.h" |
|---|
| 22 | 11 | #include "spum.h" |
|---|
| 23 | 12 | #include "cipher.h" |
|---|
| 24 | | - |
|---|
| 25 | | -/* This array is based on the hash algo type supported in spu.h */ |
|---|
| 26 | | -char *tag_to_hash_idx[] = { "none", "md5", "sha1", "sha224", "sha256" }; |
|---|
| 27 | 13 | |
|---|
| 28 | 14 | char *hash_alg_name[] = { "None", "md5", "sha1", "sha224", "sha256", "aes", |
|---|
| 29 | 15 | "sha384", "sha512", "sha3_224", "sha3_256", "sha3_384", "sha3_512" }; |
|---|
| .. | .. |
|---|
| 235 | 221 | case CIPHER_ALG_3DES: |
|---|
| 236 | 222 | cipher_key_len = 24; |
|---|
| 237 | 223 | name = "3DES"; |
|---|
| 238 | | - break; |
|---|
| 239 | | - case CIPHER_ALG_RC4: |
|---|
| 240 | | - cipher_key_len = 260; |
|---|
| 241 | | - name = "ARC4"; |
|---|
| 242 | 224 | break; |
|---|
| 243 | 225 | case CIPHER_ALG_AES: |
|---|
| 244 | 226 | switch (cipher_type) { |
|---|
| .. | .. |
|---|
| 933 | 915 | * @spu_req_hdr_len: Length in bytes of the SPU request header |
|---|
| 934 | 916 | * @isInbound: 0 encrypt, 1 decrypt |
|---|
| 935 | 917 | * @cipher_parms: Parameters describing cipher operation to be performed |
|---|
| 936 | | - * @update_key: If true, rewrite the cipher key in SCTX |
|---|
| 937 | 918 | * @data_size: Length of the data in the BD field |
|---|
| 938 | 919 | * |
|---|
| 939 | 920 | * Assumes much of the header was already filled in at setkey() time in |
|---|
| 940 | 921 | * spum_cipher_req_init(). |
|---|
| 941 | | - * spum_cipher_req_init() fills in the encryption key. For RC4, when submitting |
|---|
| 942 | | - * a request for a non-first chunk, we use the 260-byte SUPDT field from the |
|---|
| 943 | | - * previous response as the key. update_key is true for this case. Unused in all |
|---|
| 944 | | - * other cases. |
|---|
| 922 | + * spum_cipher_req_init() fills in the encryption key. |
|---|
| 945 | 923 | */ |
|---|
| 946 | 924 | void spum_cipher_req_finish(u8 *spu_hdr, |
|---|
| 947 | 925 | u16 spu_req_hdr_len, |
|---|
| 948 | 926 | unsigned int is_inbound, |
|---|
| 949 | 927 | struct spu_cipher_parms *cipher_parms, |
|---|
| 950 | | - bool update_key, |
|---|
| 951 | 928 | unsigned int data_size) |
|---|
| 952 | 929 | { |
|---|
| 953 | 930 | struct SPUHEADER *spuh; |
|---|
| .. | .. |
|---|
| 962 | 939 | flow_log(" in: %u\n", is_inbound); |
|---|
| 963 | 940 | flow_log(" cipher alg: %u, cipher_type: %u\n", cipher_parms->alg, |
|---|
| 964 | 941 | cipher_parms->type); |
|---|
| 965 | | - if (update_key) { |
|---|
| 966 | | - flow_log(" cipher key len: %u\n", cipher_parms->key_len); |
|---|
| 967 | | - flow_dump(" key: ", cipher_parms->key_buf, |
|---|
| 968 | | - cipher_parms->key_len); |
|---|
| 969 | | - } |
|---|
| 970 | 942 | |
|---|
| 971 | 943 | /* |
|---|
| 972 | 944 | * In XTS mode, API puts "i" parameter (block tweak) in IV. For |
|---|
| .. | .. |
|---|
| 994 | 966 | cipher_bits |= CIPHER_INBOUND; |
|---|
| 995 | 967 | else |
|---|
| 996 | 968 | cipher_bits &= ~CIPHER_INBOUND; |
|---|
| 997 | | - |
|---|
| 998 | | - /* update encryption key for RC4 on non-first chunk */ |
|---|
| 999 | | - if (update_key) { |
|---|
| 1000 | | - spuh->sa.cipher_flags |= |
|---|
| 1001 | | - cipher_parms->type << CIPHER_TYPE_SHIFT; |
|---|
| 1002 | | - memcpy(spuh + 1, cipher_parms->key_buf, cipher_parms->key_len); |
|---|
| 1003 | | - } |
|---|
| 1004 | 969 | |
|---|
| 1005 | 970 | if (cipher_parms->alg && cipher_parms->iv_buf && cipher_parms->iv_len) |
|---|
| 1006 | 971 | /* cipher iv provided so put it in here */ |
|---|