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

crypto: qce/des - switch to new verification routines

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Ard Biesheuvel and committed by
Herbert Xu
f96c897c 0157fb26

+27 -28
+27 -28
drivers/crypto/qce/ablkcipher.c
··· 7 7 #include <linux/interrupt.h> 8 8 #include <linux/types.h> 9 9 #include <crypto/aes.h> 10 - #include <crypto/des.h> 10 + #include <crypto/internal/des.h> 11 11 #include <crypto/internal/skcipher.h> 12 12 13 13 #include "cipher.h" ··· 154 154 { 155 155 struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablk); 156 156 struct qce_cipher_ctx *ctx = crypto_tfm_ctx(tfm); 157 - unsigned long flags = to_cipher_tmpl(tfm)->alg_flags; 158 157 int ret; 159 158 160 159 if (!key || !keylen) 161 160 return -EINVAL; 162 161 163 - if (IS_AES(flags)) { 164 - switch (keylen) { 165 - case AES_KEYSIZE_128: 166 - case AES_KEYSIZE_256: 167 - break; 168 - default: 169 - goto fallback; 170 - } 171 - } else if (IS_DES(flags)) { 172 - u32 tmp[DES_EXPKEY_WORDS]; 173 - 174 - ret = des_ekey(tmp, key); 175 - if (!ret && (crypto_ablkcipher_get_flags(ablk) & 176 - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) 177 - goto weakkey; 162 + switch (keylen) { 163 + case AES_KEYSIZE_128: 164 + case AES_KEYSIZE_256: 165 + break; 166 + default: 167 + goto fallback; 178 168 } 179 169 180 170 ctx->enc_keylen = keylen; ··· 175 185 if (!ret) 176 186 ctx->enc_keylen = keylen; 177 187 return ret; 178 - weakkey: 179 - crypto_ablkcipher_set_flags(ablk, CRYPTO_TFM_RES_WEAK_KEY); 180 - return -EINVAL; 188 + } 189 + 190 + static int qce_des_setkey(struct crypto_ablkcipher *ablk, const u8 *key, 191 + unsigned int keylen) 192 + { 193 + struct qce_cipher_ctx *ctx = crypto_ablkcipher_ctx(ablk); 194 + int err; 195 + 196 + err = verify_ablkcipher_des_key(ablk, key); 197 + if (err) 198 + return err; 199 + 200 + ctx->enc_keylen = keylen; 201 + memcpy(ctx->enc_key, key, keylen); 202 + return 0; 181 203 } 182 204 183 205 static int qce_des3_setkey(struct crypto_ablkcipher *ablk, const u8 *key, 184 206 unsigned int keylen) 185 207 { 186 208 struct qce_cipher_ctx *ctx = crypto_ablkcipher_ctx(ablk); 187 - u32 flags; 188 209 int err; 189 210 190 - flags = crypto_ablkcipher_get_flags(ablk); 191 - err = __des3_verify_key(&flags, key); 192 - if (unlikely(err)) { 193 - crypto_ablkcipher_set_flags(ablk, flags); 211 + err = verify_ablkcipher_des3_key(ablk, key); 212 + if (err) 194 213 return err; 195 - } 196 214 197 215 ctx->enc_keylen = keylen; 198 216 memcpy(ctx->enc_key, key, keylen); ··· 372 374 alg->cra_ablkcipher.ivsize = def->ivsize; 373 375 alg->cra_ablkcipher.min_keysize = def->min_keysize; 374 376 alg->cra_ablkcipher.max_keysize = def->max_keysize; 375 - alg->cra_ablkcipher.setkey = IS_3DES(def->flags) ? 376 - qce_des3_setkey : qce_ablkcipher_setkey; 377 + alg->cra_ablkcipher.setkey = IS_3DES(def->flags) ? qce_des3_setkey : 378 + IS_DES(def->flags) ? qce_des_setkey : 379 + qce_ablkcipher_setkey; 377 380 alg->cra_ablkcipher.encrypt = qce_ablkcipher_encrypt; 378 381 alg->cra_ablkcipher.decrypt = qce_ablkcipher_decrypt; 379 382