Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: inside-secure/eip93 - unregister only available algorithm

EIP93 has an options register. This register indicates which crypto
algorithms are implemented in silicon. Supported algorithms are
registered on this basis. Unregister algorithms on the same basis.
Currently, all algorithms are unregistered, even those not supported
by HW. This results in panic on platforms that don't have all options
implemented in silicon.

Fixes: 9739f5f93b78 ("crypto: eip93 - Add Inside Secure SafeXcel EIP-93 crypto engine support")
Signed-off-by: Aleksander Jan Bajkowski <olek2@wp.pl>
Acked-by: Antoine Tenart <atenart@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Aleksander Jan Bajkowski and committed by
Herbert Xu
0ceeadc7 d5abcc33

+53 -39
+53 -39
drivers/crypto/inside-secure/eip93/eip93-main.c
··· 77 77 __raw_writel(mask, eip93->base + EIP93_REG_INT_CLR); 78 78 } 79 79 80 - static void eip93_unregister_algs(unsigned int i) 80 + static int eip93_algo_is_supported(u32 alg_flags, u32 supported_algo_flags) 81 + { 82 + if ((IS_DES(alg_flags) || IS_3DES(alg_flags)) && 83 + !(supported_algo_flags & EIP93_PE_OPTION_TDES)) 84 + return 0; 85 + 86 + if (IS_AES(alg_flags) && 87 + !(supported_algo_flags & EIP93_PE_OPTION_AES)) 88 + return 0; 89 + 90 + if (IS_HASH_MD5(alg_flags) && 91 + !(supported_algo_flags & EIP93_PE_OPTION_MD5)) 92 + return 0; 93 + 94 + if (IS_HASH_SHA1(alg_flags) && 95 + !(supported_algo_flags & EIP93_PE_OPTION_SHA_1)) 96 + return 0; 97 + 98 + if (IS_HASH_SHA224(alg_flags) && 99 + !(supported_algo_flags & EIP93_PE_OPTION_SHA_224)) 100 + return 0; 101 + 102 + if (IS_HASH_SHA256(alg_flags) && 103 + !(supported_algo_flags & EIP93_PE_OPTION_SHA_256)) 104 + return 0; 105 + 106 + return 1; 107 + } 108 + 109 + static void eip93_unregister_algs(u32 supported_algo_flags, unsigned int i) 81 110 { 82 111 unsigned int j; 83 112 84 113 for (j = 0; j < i; j++) { 114 + if (!eip93_algo_is_supported(eip93_algs[j]->flags, 115 + supported_algo_flags)) 116 + continue; 117 + 85 118 switch (eip93_algs[j]->type) { 86 119 case EIP93_ALG_TYPE_SKCIPHER: 87 120 crypto_unregister_skcipher(&eip93_algs[j]->alg.skcipher); ··· 139 106 140 107 eip93_algs[i]->eip93 = eip93; 141 108 142 - if ((IS_DES(alg_flags) || IS_3DES(alg_flags)) && 143 - !(supported_algo_flags & EIP93_PE_OPTION_TDES)) 109 + if (!eip93_algo_is_supported(alg_flags, supported_algo_flags)) 144 110 continue; 145 111 146 - if (IS_AES(alg_flags)) { 147 - if (!(supported_algo_flags & EIP93_PE_OPTION_AES)) 148 - continue; 112 + if (IS_AES(alg_flags) && !IS_HMAC(alg_flags)) { 113 + if (supported_algo_flags & EIP93_PE_OPTION_AES_KEY128) 114 + eip93_algs[i]->alg.skcipher.max_keysize = 115 + AES_KEYSIZE_128; 149 116 150 - if (!IS_HMAC(alg_flags)) { 151 - if (supported_algo_flags & EIP93_PE_OPTION_AES_KEY128) 152 - eip93_algs[i]->alg.skcipher.max_keysize = 153 - AES_KEYSIZE_128; 117 + if (supported_algo_flags & EIP93_PE_OPTION_AES_KEY192) 118 + eip93_algs[i]->alg.skcipher.max_keysize = 119 + AES_KEYSIZE_192; 154 120 155 - if (supported_algo_flags & EIP93_PE_OPTION_AES_KEY192) 156 - eip93_algs[i]->alg.skcipher.max_keysize = 157 - AES_KEYSIZE_192; 121 + if (supported_algo_flags & EIP93_PE_OPTION_AES_KEY256) 122 + eip93_algs[i]->alg.skcipher.max_keysize = 123 + AES_KEYSIZE_256; 158 124 159 - if (supported_algo_flags & EIP93_PE_OPTION_AES_KEY256) 160 - eip93_algs[i]->alg.skcipher.max_keysize = 161 - AES_KEYSIZE_256; 162 - 163 - if (IS_RFC3686(alg_flags)) 164 - eip93_algs[i]->alg.skcipher.max_keysize += 165 - CTR_RFC3686_NONCE_SIZE; 166 - } 125 + if (IS_RFC3686(alg_flags)) 126 + eip93_algs[i]->alg.skcipher.max_keysize += 127 + CTR_RFC3686_NONCE_SIZE; 167 128 } 168 - 169 - if (IS_HASH_MD5(alg_flags) && 170 - !(supported_algo_flags & EIP93_PE_OPTION_MD5)) 171 - continue; 172 - 173 - if (IS_HASH_SHA1(alg_flags) && 174 - !(supported_algo_flags & EIP93_PE_OPTION_SHA_1)) 175 - continue; 176 - 177 - if (IS_HASH_SHA224(alg_flags) && 178 - !(supported_algo_flags & EIP93_PE_OPTION_SHA_224)) 179 - continue; 180 - 181 - if (IS_HASH_SHA256(alg_flags) && 182 - !(supported_algo_flags & EIP93_PE_OPTION_SHA_256)) 183 - continue; 184 129 185 130 switch (eip93_algs[i]->type) { 186 131 case EIP93_ALG_TYPE_SKCIPHER: ··· 178 167 return 0; 179 168 180 169 fail: 181 - eip93_unregister_algs(i); 170 + eip93_unregister_algs(supported_algo_flags, i); 182 171 183 172 return ret; 184 173 } ··· 480 469 static void eip93_crypto_remove(struct platform_device *pdev) 481 470 { 482 471 struct eip93_device *eip93 = platform_get_drvdata(pdev); 472 + u32 algo_flags; 483 473 484 - eip93_unregister_algs(ARRAY_SIZE(eip93_algs)); 474 + algo_flags = readl(eip93->base + EIP93_REG_PE_OPTION_1); 475 + 476 + eip93_unregister_algs(algo_flags, ARRAY_SIZE(eip93_algs)); 485 477 eip93_cleanup(eip93); 486 478 } 487 479