Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp962750ybm; Tue, 21 May 2019 06:37:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVko8qBi+X6VADZB7AZzd+1XMYcJ+m7VSzF0jM3dm/DosDoaTuswh7RBHSyaankV/0OsjO X-Received: by 2002:a65:52c3:: with SMTP id z3mr29496612pgp.56.1558445845175; Tue, 21 May 2019 06:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558445845; cv=none; d=google.com; s=arc-20160816; b=g3Lv7h1LhiD5xe1N++CxmGStgpIfkHz08QlYTvnohd4pU1GSus4i9MxB9LQxG2GDLv vXs6L6uzEB1U/51777qI1tr/8SS04xg3pn1X8jcEaZv4uYtwzByaZVl6hXprAJWYlLOR yapJu6mkZsfw/h80ZhA4XoIAxlK7fKUirbtZ5Qcj0tOaep3+e8gl+kozPwf4gE1A3tJy K+0BmWNE1bfVVx7oFnOsqElHyEx9Jm1wypR9Fe4S7gEsLGPI9Tr5pAgdZJfPKlNr5p4O U6sBLXANMU0bstyM2XFMqm/u3J9DDv9/MfI5NJvHmX7AMEEHvoGP4peGyHYL4yVLzQ41 xsrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:dkim-signature; bh=1o48F/RCvOFMIOazQ2qnKlLn8191AY4vZ9Mdu/TThzU=; b=KrEyleGTlQEJMLJh6KjHq/WFuHRCJT1pNhax/69VxwJdrZg+daX0Wo63tve66lK4D0 aipVHRPtR721/CnaKc9FRH7BRNSBA8NEb//ixda39aRzogIZ2DFdDa6VxR9vWiy5pZk3 hXJGeZE9kK9+o0Ujnl+gV2VSB/i/s+k/Z0V3djGDkDEHFhDONF7TDaDNlxInpVEL6Her MHbvWILgx0qMMdozKXo79wt4fQlr6xachteMAOwvBk1tHRp/npkLGcOcB4MD9vxYOVGu HfBzKjfWoYeNluRBsBRxh/sUpCHRb4RBg8e4S6cxrW6W/MmmxyUSXNDcJFWa/AoBQNbV n/rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=gy0LY0ZC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9si19957119plo.395.2019.05.21.06.37.10; Tue, 21 May 2019 06:37:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=gy0LY0ZC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728458AbfEUNeQ (ORCPT + 99 others); Tue, 21 May 2019 09:34:16 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:59399 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728075AbfEUNeN (ORCPT ); Tue, 21 May 2019 09:34:13 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 457cDf0xPzz9v2Xb; Tue, 21 May 2019 15:34:10 +0200 (CEST) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=gy0LY0ZC; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id byM8bp_Gm7Ak; Tue, 21 May 2019 15:34:10 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 457cDd6zmwz9v2XY; Tue, 21 May 2019 15:34:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1558445650; bh=1o48F/RCvOFMIOazQ2qnKlLn8191AY4vZ9Mdu/TThzU=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=gy0LY0ZCEqUDQ2MjU5FJhFfvBuAlBGYM9izPHvWn0klDirKlX6Vn+KLAvg7L1tkkT Q1jIW1ACWGaF8UwAsDylnoRkukd9nvJHjNpg2ZQnA1DNX51ZfKLwipIa3D7Xrxze5N H7Pbje56A1M9CnM/ExZvIfZVVAf5EYR37ZMHZQqM= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 695558B803; Tue, 21 May 2019 15:34:11 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id KK2d7DxAwGjO; Tue, 21 May 2019 15:34:11 +0200 (CEST) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 0E11F8B80C; Tue, 21 May 2019 15:34:11 +0200 (CEST) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id D360F68458; Tue, 21 May 2019 13:34:10 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v1 04/15] crypto: talitos - check AES key size To: Herbert Xu , "David S. Miller" , horia.geanta@nxp.com Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Tue, 21 May 2019 13:34:10 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Although the HW accepts any size and silently truncates it to the correct length, the extra tests expects EINVAL to be returned when the key size is not valid. Signed-off-by: Christophe Leroy Fixes: 4de9d0b547b9 ("crypto: talitos - Add ablkcipher algorithms") --- drivers/crypto/talitos.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 6312f8d501b1..95f71e18bf55 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -1622,6 +1622,18 @@ static int ablkcipher_des3_setkey(struct crypto_ablkcipher *cipher, return ablkcipher_setkey(cipher, key, keylen); } +static int ablkcipher_aes_setkey(struct crypto_ablkcipher *cipher, + const u8 *key, unsigned int keylen) +{ + if (keylen == AES_KEYSIZE_128 || keylen == AES_KEYSIZE_192 || + keylen == AES_KEYSIZE_256) + return ablkcipher_setkey(cipher, key, keylen); + + crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN); + + return -EINVAL; +} + static void common_nonsnoop_unmap(struct device *dev, struct talitos_edesc *edesc, struct ablkcipher_request *areq) @@ -2782,6 +2794,7 @@ static struct talitos_alg_template driver_algs[] = { .min_keysize = AES_MIN_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE, .ivsize = AES_BLOCK_SIZE, + .setkey = ablkcipher_aes_setkey, } }, .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | @@ -2798,6 +2811,7 @@ static struct talitos_alg_template driver_algs[] = { .min_keysize = AES_MIN_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE, .ivsize = AES_BLOCK_SIZE, + .setkey = ablkcipher_aes_setkey, } }, .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU | @@ -2815,6 +2829,7 @@ static struct talitos_alg_template driver_algs[] = { .min_keysize = AES_MIN_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE, .ivsize = AES_BLOCK_SIZE, + .setkey = ablkcipher_aes_setkey, } }, .desc_hdr_template = DESC_HDR_TYPE_AESU_CTR_NONSNOOP | -- 2.13.3