From patchwork Sat Jun 22 00:31:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167450 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1376871ilk; Fri, 21 Jun 2019 17:32:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+k7D6qmsK3LCIRh5fp67/6clgbl1OEA4WTJKv9O8+KZfjVcLrEE2iPBVuYLIlLEvsJ9wp X-Received: by 2002:a17:902:ac1:: with SMTP id 59mr57051849plp.168.1561163533561; Fri, 21 Jun 2019 17:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561163533; cv=none; d=google.com; s=arc-20160816; b=yalWk+ZXxi3YSxOD6quYmt0JkUwCX+DT+nP0BvZMA2SjsNAyHD9NnmJWGR0UihOsTT g5GUV6S17JVo5Fy2BxAQh83eQAsKpwoiTgEXBPfiFgmtbZGrBOjCo+ulf+TaLw5fdcwS OIZgWHIPxJwKuCW3ZFhmkszCM4QbGMBBJMMah9J3OumlbbiDu9wT1xWo9pgueVmePA/c ZM0nzaJORvoW/GveUteWjTNiiavR25rfI+eBIFoi7oA8ff1Z/DCGbu7Uefny51gtH1sF VlMdanUZAH+zDJOjr0x5WksnFHeIAE7ghMaxuzgLa4iqx8TmGxdGtdOm/4UDikOLa5Z8 4BhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KG8WnE1mm/pt8XuVucBEWIW6qbyg1qS4SYR7MAokAw0=; b=gX9UHvgohDyfbTkfHdyEhqo++5g5cMm2vLpJazhWw77pTWfJ5KRkLdNV3lgvr69nDX F/lRIbW72Pk/URGV5+gRlNsB8OFdA+uaTXdDrrUuDdL3K98IZr0tKpYDKfIocmHizyuC PzZ6NAzfl6mdE3SnFogo6VW3h/y7Vs/gAC6YIFVyiYTXpM7ke5bkGs7UTi62Vl/Hyr5N SzvmpF+60DtWYCLzTn2edz+qDzQd7HD697lUBVAnPjWm5wDizO6gMHbqxduSlBtM8JWn D2whUFwTACkP57xQjEODQilT2Zmtx7ejsiYDHTHlWpR+FLcCowwPgTe0EG5ew9KemRxr +l5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="TfhS/DaS"; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v10si4096271plg.320.2019.06.21.17.32.13; Fri, 21 Jun 2019 17:32:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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=@linaro.org header.s=google header.b="TfhS/DaS"; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726257AbfFVAcM (ORCPT + 3 others); Fri, 21 Jun 2019 20:32:12 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43592 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726246AbfFVAcM (ORCPT ); Fri, 21 Jun 2019 20:32:12 -0400 Received: by mail-wr1-f67.google.com with SMTP id p13so8087724wru.10 for ; Fri, 21 Jun 2019 17:32:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KG8WnE1mm/pt8XuVucBEWIW6qbyg1qS4SYR7MAokAw0=; b=TfhS/DaSlC9dCB66BhT5FNJX1QKZLTuaXnrT0U82MfiFZcgv0jTRrJodZWpLJxxaqh zsYOfiyUqYpGFhi993m+CjA3BK/9wDTKMo3Q2R6sKfBkKtY/lcog+f5PI/JkVpl2Suej pB32wGzfuA2oAa2ouWw5UMFMR6zgVmCW5ZVDt+dXpZuck7RJBJk3DVx0ggyQ/6ju+qL7 LuSc0wExvvjeqHYerLOa5QEXBd1OkBVnJBng9T6iiACA215kEHa+nRUgdjw1Hvyn1Fcv vZjqQCs8GeLVzpdHcHZn861cCRTxkz++x84DWjQr/JKOR6BgQmATenuxT2KmNY3XIpau LjUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KG8WnE1mm/pt8XuVucBEWIW6qbyg1qS4SYR7MAokAw0=; b=Gf9H8VPwCypj1CKFJWwAAYkzQYRSvrVEvtaCuf1/TvoNHS//WNwaje1kUF5IrKbyjw +HaxIWj0E39lfdt6XZmuVwInzMkUKYvc2Nf6zUrYb5hMKjeCtbbGS7rdMXrFBV+GDcvT tpQTFopUG1HAwgiwUeeB6fyeTpsN2g2DXjGKT++VGVE0unIyE13Bpsz9Wtb0TyFoRPLP 7fbGYpA0Df3aSIdccZECQ039xIefeATPOxsL7X3WQZfdh+TtEt+ETJQI4jsw6l8XfQ0N 22KIrDiTc9CS+2P2eN93RR9nSAO8adIrHaBjDfLUspLmVKdVUNr4Osoz+9L5WOGrqT7j PH2g== X-Gm-Message-State: APjAAAUPq3rHZwWPr6uELOBeM0lOH+lYEizFbHUVs2CNizwPPQ/MImRr YpWFWC2N7FBfHO4bTjfYtlRrc65I1Cr3BRRJ X-Received: by 2002:adf:dc45:: with SMTP id m5mr31140866wrj.148.1561163530349; Fri, 21 Jun 2019 17:32:10 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:99d4:1ff0:ed6:dfbb]) by smtp.gmail.com with ESMTPSA id v18sm4792019wrd.51.2019.06.21.17.32.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 17:32:09 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, ebiggers@google.com, Ard Biesheuvel Subject: [RFC PATCH 25/30] crypto: 3des - move verification out of exported routine Date: Sat, 22 Jun 2019 02:31:07 +0200 Message-Id: <20190622003112.31033-26-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190622003112.31033-1-ard.biesheuvel@linaro.org> References: <20190622003112.31033-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org In preparation of moving the shared key expansion routine into the DES library, move the verification done by __des3_ede_setkey() into its callers. Signed-off-by: Ard Biesheuvel --- arch/x86/crypto/des3_ede_glue.c | 4 ++++ crypto/des_generic.c | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) -- 2.20.1 diff --git a/arch/x86/crypto/des3_ede_glue.c b/arch/x86/crypto/des3_ede_glue.c index 5c610d4ef9fc..48292a2ce66d 100644 --- a/arch/x86/crypto/des3_ede_glue.c +++ b/arch/x86/crypto/des3_ede_glue.c @@ -358,6 +358,10 @@ static int des3_ede_x86_setkey(struct crypto_tfm *tfm, const u8 *key, u32 i, j, tmp; int err; + err = des3_ede_verify_key(tfm, key, keylen); + if (unlikely(err)) + return err; + /* Generate encryption context using generic implementation. */ err = __des3_ede_setkey(ctx->enc_expkey, &tfm->crt_flags, key, keylen); if (err < 0) diff --git a/crypto/des_generic.c b/crypto/des_generic.c index c94a303da4dd..34921f8004cc 100644 --- a/crypto/des_generic.c +++ b/crypto/des_generic.c @@ -851,10 +851,6 @@ int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key, { int err; - err = __des3_verify_key(flags, key); - if (unlikely(err)) - return err; - des_ekey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; dkey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; des_ekey(expkey, key); @@ -867,8 +863,12 @@ static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) { struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); - u32 *flags = &tfm->crt_flags; u32 *expkey = dctx->expkey; + int err; + + err = des3_ede_verify_key(crypto_skcipher_tfm(skcipher), key, keylen); + if (unlikely(err)) + return err; return __des3_ede_setkey(expkey, flags, key, keylen); }