Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3870200pxb; Tue, 17 Nov 2020 05:51:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkyTPQGRo90PCBSzf0Z5roPW9aujQH6JTaTmOtOn26zPCPABAZAYAR6vHMlu7WqPBZmA6U X-Received: by 2002:a17:906:2342:: with SMTP id m2mr7949070eja.210.1605621090432; Tue, 17 Nov 2020 05:51:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605621090; cv=none; d=google.com; s=arc-20160816; b=bRcrrSXhN9SdW8sngarWsyZ4Lk8rwC13DRZK4hOlUd42rfqydKw4ZGzMjo+6ueNAiD ZnelPDacsAtf7YQTdMod89JXdq2Li7D8ULSAexeh63nz7GSSPxUkmvQQI7zJ9laLvqP8 gC9osbZPOSgKZznHWIPErz91Zbu5hGWFMGUow6E0zs0gpEAWijPNCfJKqen9Q6qUlDbZ rs/3Eh7dP4dYPmyeG194gyAUWDm393iLZsdCyX8FeiggYye7ox0UFwSqHnWCycYytYlW pEL2GBSnPSIwgXol12nV+uobQK1mCQQuKeWX9x0B6+ib8h7TH7EZwMzQl/7H2dlZUdeC L8MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=QJ8s73ibg8lRnVac5dWDSwwt9Q4T7kp4Yrdrb1UHRFs=; b=DJbCSIG+VxDQ7OOlk3TCfL9qUtHtRiwezl8/nVgVVoKW3yq6xlUUldpwFjtxMFJ9RE 5TqvimAwkGXdYTVHiDIjO2rfUWs7I4Go5jq76iKj2bJRqDhltjDOTy8efSEaBzeAORh0 cmPo9xagIsKcT10r5EK47t1ELDeUwWvzRPidbQmZ36890F1jekxh63Q1KJExqQ5/f2Qy /0tSweA24a8dg5Cvoh13DtRBLh/+SS+AhiE/Pr0OAsj7Kz3X+M4sF1VuiqBBIFl7/ced 9wtGuAPZ5O+/p2Fbu/707uJXNvZWL+89usEJp97AQEUnHxVJy8Ok5SSuhXUAAWvODTdv 3XgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cet0n5Jf; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a3si13277779ejx.273.2020.11.17.05.51.06; Tue, 17 Nov 2020 05:51:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cet0n5Jf; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732324AbgKQNu3 (ORCPT + 99 others); Tue, 17 Nov 2020 08:50:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:42358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732319AbgKQNch (ORCPT ); Tue, 17 Nov 2020 08:32:37 -0500 Received: from e123331-lin.nice.arm.com (lfbn-nic-1-188-42.w2-15.abo.wanadoo.fr [2.15.37.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B5ED2463D; Tue, 17 Nov 2020 13:32:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619958; bh=Iyf4Rgv1+x9PtEcqoWVcwfYPM8emMHSynQZDAw8Vlh8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cet0n5JfTryI2r5wS0lajmlBaXW1o1RRiB4pZeSqFUJRK0Wwka+h0yt1RlMiiiUbm VXdHZ6gmvmY4vFt072CdGV3xX1YatYMgxHBI6/vxVm/7DPdVepaOZ8fjkdrp92Tnmb wZ7aKg3DlscXPu8H+jZ5tdfyq2Ctp+NBCqcyRzzk= From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Ondrej Mosnacek , Eric Biggers Subject: [PATCH v3 1/4] crypto: aegis128 - wipe plaintext and tag if decryption fails Date: Tue, 17 Nov 2020 14:32:11 +0100 Message-Id: <20201117133214.29114-2-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201117133214.29114-1-ardb@kernel.org> References: <20201117133214.29114-1-ardb@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The AEGIS spec mentions explicitly that the security guarantees hold only if the resulting plaintext and tag of a failed decryption are withheld. So ensure that we abide by this. While at it, drop the unused struct aead_request *req parameter from crypto_aegis128_process_crypt(). Reviewed-by: Ondrej Mosnacek Signed-off-by: Ard Biesheuvel --- crypto/aegis128-core.c | 32 ++++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/crypto/aegis128-core.c b/crypto/aegis128-core.c index 44fb4956f0dd..3a71235892f5 100644 --- a/crypto/aegis128-core.c +++ b/crypto/aegis128-core.c @@ -154,6 +154,12 @@ static void crypto_aegis128_ad(struct aegis_state *state, } } +static void crypto_aegis128_wipe_chunk(struct aegis_state *state, u8 *dst, + const u8 *src, unsigned int size) +{ + memzero_explicit(dst, size); +} + static void crypto_aegis128_encrypt_chunk(struct aegis_state *state, u8 *dst, const u8 *src, unsigned int size) { @@ -324,7 +330,6 @@ static void crypto_aegis128_process_ad(struct aegis_state *state, static __always_inline int crypto_aegis128_process_crypt(struct aegis_state *state, - struct aead_request *req, struct skcipher_walk *walk, void (*crypt)(struct aegis_state *state, u8 *dst, const u8 *src, @@ -403,14 +408,14 @@ static int crypto_aegis128_encrypt(struct aead_request *req) if (aegis128_do_simd()) { crypto_aegis128_init_simd(&state, &ctx->key, req->iv); crypto_aegis128_process_ad(&state, req->src, req->assoclen); - crypto_aegis128_process_crypt(&state, req, &walk, + crypto_aegis128_process_crypt(&state, &walk, crypto_aegis128_encrypt_chunk_simd); crypto_aegis128_final_simd(&state, &tag, req->assoclen, cryptlen); } else { crypto_aegis128_init(&state, &ctx->key, req->iv); crypto_aegis128_process_ad(&state, req->src, req->assoclen); - crypto_aegis128_process_crypt(&state, req, &walk, + crypto_aegis128_process_crypt(&state, &walk, crypto_aegis128_encrypt_chunk); crypto_aegis128_final(&state, &tag, req->assoclen, cryptlen); } @@ -438,19 +443,34 @@ static int crypto_aegis128_decrypt(struct aead_request *req) if (aegis128_do_simd()) { crypto_aegis128_init_simd(&state, &ctx->key, req->iv); crypto_aegis128_process_ad(&state, req->src, req->assoclen); - crypto_aegis128_process_crypt(&state, req, &walk, + crypto_aegis128_process_crypt(&state, &walk, crypto_aegis128_decrypt_chunk_simd); crypto_aegis128_final_simd(&state, &tag, req->assoclen, cryptlen); } else { crypto_aegis128_init(&state, &ctx->key, req->iv); crypto_aegis128_process_ad(&state, req->src, req->assoclen); - crypto_aegis128_process_crypt(&state, req, &walk, + crypto_aegis128_process_crypt(&state, &walk, crypto_aegis128_decrypt_chunk); crypto_aegis128_final(&state, &tag, req->assoclen, cryptlen); } - return crypto_memneq(tag.bytes, zeros, authsize) ? -EBADMSG : 0; + if (unlikely(crypto_memneq(tag.bytes, zeros, authsize))) { + /* + * From Chapter 4. 'Security Analysis' of the AEGIS spec [0] + * + * "3. If verification fails, the decrypted plaintext and the + * wrong authentication tag should not be given as output." + * + * [0] https://competitions.cr.yp.to/round3/aegisv11.pdf + */ + skcipher_walk_aead_decrypt(&walk, req, false); + crypto_aegis128_process_crypt(NULL, &walk, + crypto_aegis128_wipe_chunk); + memzero_explicit(&tag, sizeof(tag)); + return -EBADMSG; + } + return 0; } static struct aead_alg crypto_aegis128_alg = { -- 2.17.1