1 /****************************************************************************** 2 * 3 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by 4 * Analog Devices, Inc.), 5 * Copyright (C) 2023-2024 Analog Devices, Inc. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 ******************************************************************************/ 20 21 #include "ctb.h" 22 #include "ctb_common.h" 23 24 /* ************************************************************************* */ 25 MXC_CTB_Common_Hash_GetBlockSize(mxc_ctb_hash_func_t function)26unsigned int MXC_CTB_Common_Hash_GetBlockSize(mxc_ctb_hash_func_t function) 27 { 28 // Block size in bytes indexed by hash function 29 switch (function) { 30 case MXC_CTB_HASH_DIS: 31 return 0; 32 33 case MXC_CTB_HASH_SHA1: 34 return 64; 35 36 case MXC_CTB_HASH_SHA224: 37 return 64; 38 39 case MXC_CTB_HASH_SHA256: 40 return 64; 41 42 case MXC_CTB_HASH_SHA384: 43 return 128; 44 45 case MXC_CTB_HASH_SHA512: 46 return 128; 47 } 48 49 // if returns this bad param was passed in or disable. 50 return 0; 51 } 52 MXC_CTB_Common_Hash_GetDigestSize(mxc_ctb_hash_func_t function)53unsigned int MXC_CTB_Common_Hash_GetDigestSize(mxc_ctb_hash_func_t function) 54 { 55 // Digest length in bytes indexed by hash function 56 switch (function) { 57 case MXC_CTB_HASH_DIS: 58 return 0; 59 60 case MXC_CTB_HASH_SHA1: 61 return 20; 62 63 case MXC_CTB_HASH_SHA224: 64 return 28; 65 66 case MXC_CTB_HASH_SHA256: 67 return 32; 68 69 case MXC_CTB_HASH_SHA384: 70 return 48; 71 72 case MXC_CTB_HASH_SHA512: 73 return 64; 74 } 75 76 // if returns this bad param was passed in or disable. 77 return 0; 78 } 79 MXC_CTB_Common_Cipher_GetKeySize(mxc_ctb_cipher_t cipher)80unsigned int MXC_CTB_Common_Cipher_GetKeySize(mxc_ctb_cipher_t cipher) 81 { 82 switch (cipher) { 83 case MXC_CTB_CIPHER_DIS: 84 return 0; 85 86 case MXC_CTB_CIPHER_AES128: 87 return 16; 88 89 case MXC_CTB_CIPHER_AES192: 90 return 24; 91 92 case MXC_CTB_CIPHER_AES256: 93 return 32; 94 95 case MXC_CTB_CIPHER_DES: 96 return 8; 97 98 case MXC_CTB_CIPHER_TDES: 99 return 24; 100 } 101 102 // if returns this bad param was passed in or disable. 103 return 0; 104 } 105 MXC_CTB_Common_Cipher_GetBlockSize(mxc_ctb_cipher_t cipher)106unsigned int MXC_CTB_Common_Cipher_GetBlockSize(mxc_ctb_cipher_t cipher) 107 { 108 switch (cipher) { 109 case MXC_CTB_CIPHER_DIS: 110 return 0; 111 112 case MXC_CTB_CIPHER_AES128: 113 return 16; 114 115 case MXC_CTB_CIPHER_AES192: 116 return 16; 117 118 case MXC_CTB_CIPHER_AES256: 119 return 16; 120 121 case MXC_CTB_CIPHER_DES: 122 return 8; 123 124 case MXC_CTB_CIPHER_TDES: 125 return 8; 126 } 127 128 // if returns this bad param was passed in or disable. 129 return 0; 130 } 131