From patchwork Thu Oct 17 19:09:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 176716 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1360275ill; Thu, 17 Oct 2019 12:10:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhJJeS3yf+zutmn7BKzwt8UK7MwkAnkRCy8BwwgpxLxfwv6dfS400HDG6w4ab4UPQB0H+a X-Received: by 2002:a17:906:1f16:: with SMTP id w22mr5152884ejj.5.1571339442590; Thu, 17 Oct 2019 12:10:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571339442; cv=none; d=google.com; s=arc-20160816; b=BZZK2B/OpUK1Lo2Skep85+D13TmTmGaqZZf9onNdNcQ311UAQa8rdFPepNbadGVk/1 o1WSPwk8YG6Z5OKCASbIYCoHzHiyYnE1qYnag/XCUPnQWXXj5MR8udYdpfiNd9RDMjMY ST8JdSpImDk2su1h802xln0/fzfkZLhlmkGh7HmNYQLnDnTFWHmAWch1rmkt5JhFWGy+ QR8EG5Ccp4z1CB93Ib8xFz0R6TzREpvf0+JBr4nggeu2PUUW2+59P024hYB11lJCmjkY V7RoY0Q+ZNxOZ9HVtFzMEPIKaWt6lBmTOmF+sR4N2B5QggzcLFaVIszqOZgxiXD46sjo hVgg== 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=/bMk1MmOJGGPQtbtRGKAUAFBf6gzwzxY0aFl7AK9OOk=; b=yrtwqN9uR1XEyCPQJ7GNZmnFXp+WgGFezMqIyULfYV6vt26nS6IDbswxS31r8dzhwv RIOjoFsEYZCIBhqRp+xfuip6pqMEfxUvWwpmtg/Wse0LDiQQs/4b9vCWOC500t5qz6O2 YOAOM71iAGXeP8Y7aT9rSkp4EupFQcPqgiCk/IlbtmTE80MEnlZZ6j/G1zwt3+Z5IEW7 6wNhmjCn5Ve3MB2apZaTVmvjAnBk+Gd11l1r8IAqEb0DlinNBRdgt5s6yb1TamXVYciL MdtCIwzRGBxd/bScDNMO+xDFtVmbq3QGT/QdRiIvrMHtv2QsMXdHTzXtspb07wVdWYbk iuTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rKm7YSOK; 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 e31si2292605ede.199.2019.10.17.12.10.42; Thu, 17 Oct 2019 12:10:42 -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=rKm7YSOK; 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 S2503405AbfJQTKl (ORCPT + 3 others); Thu, 17 Oct 2019 15:10:41 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50316 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503396AbfJQTKl (ORCPT ); Thu, 17 Oct 2019 15:10:41 -0400 Received: by mail-wm1-f68.google.com with SMTP id 5so3686272wmg.0 for ; Thu, 17 Oct 2019 12:10:40 -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=/bMk1MmOJGGPQtbtRGKAUAFBf6gzwzxY0aFl7AK9OOk=; b=rKm7YSOK6uv6vM5zZKCkn+XVLYdVQZxyfpGcnTLUK1SeRlUIb24voPhhom/j7U1mnV tuiMl2w7YcEgWltoT0XDngTC+khnrhXdXZmxc5IfU3xfXw4uKISJdP3/LJBmGyROizrQ nmf7f7Dbm5CUIFqplM9D3xY3ushe2wDrysX7n3wYPVZNZeehoA94IDR/i6O3lgv0ev2a iul+5Mx+q7hjcAI52HacWnAxbjXSdSPKYWNYly9Yqm1i4VqH5/zIhLL8EsMD9Tbw32Zb kZwQ3ATL8We63hOdtOJKPHYTQakllZBGw/u5Esolk5zqijoCEmkvhrMlqOVqBRteKf5N ueMA== 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=/bMk1MmOJGGPQtbtRGKAUAFBf6gzwzxY0aFl7AK9OOk=; b=TLtFMtuNEHneD0iYUjVRVVwQO/NLH3Jvpf2pty0+EuyMBCLxwqqLkpLb7Sir2zzJL/ F+1O/U5ZaYyDqcDO4NxKNWofzvRNS3aW2TW3vMLqM4CwCu7b4H81nsZSnwgzH0raDnej 6vp7U+HXactg/27qR4MScpYEGGqUYS+ORwUvCoo4ckJBl7RNCG3L/svpgavIeDHyZCAJ 1c1CAx3lBXzw/vmDViNUVE/6qps0Kcxao25fynp/BOY+xN46s3dJRciHxFFVE0r2W5Td 2JDJjuBnINRN2VzcWPBfP+p74NdnEy6qDWFjaDK64flciIZ4fR+TlKD54ht2kZs2PtfI AFTg== X-Gm-Message-State: APjAAAVlrWeNC/R1Vx7eNEJI71VAc1qVVkMBNUIk+bkDGEoVoo7h5oZX mfHND5ch+yUOUYG1vnkHhG0DCZRevBJ/aXbN X-Received: by 2002:a1c:5587:: with SMTP id j129mr4175379wmb.15.1571339439262; Thu, 17 Oct 2019 12:10:39 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:ccb6:e9d4:c1bc:d107]) by smtp.gmail.com with ESMTPSA id y3sm5124528wro.36.2019.10.17.12.10.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Oct 2019 12:10:38 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: Ard Biesheuvel , Herbert Xu , David Miller , "Jason A . Donenfeld" , Samuel Neves , Arnd Bergmann , Eric Biggers , Andy Lutomirski , Martin Willi , Rene van Dorst , David Sterba Subject: [PATCH v4 27/35] crypto: testmgr - implement testing for KPP failures Date: Thu, 17 Oct 2019 21:09:24 +0200 Message-Id: <20191017190932.1947-28-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191017190932.1947-1-ard.biesheuvel@linaro.org> References: <20191017190932.1947-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 The Curve25519 drivers we will be implementing will perform validation of the inputs, and in order to ensure that these checks work as expected, we need to be able to test for expected errors. So implement this in the KPP test routines in the testmgr framework. Signed-off-by: Ard Biesheuvel --- crypto/testmgr.c | 14 ++++++++++---- crypto/testmgr.h | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) -- 2.20.1 diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 767fc5444771..4548559b2f0b 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -3499,8 +3499,11 @@ static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec, /* Compute party A's public key */ err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait); if (err) { - pr_err("alg: %s: Party A: generate public key test failed. err %d\n", - alg, err); + if (err != vec->gen_pubkey_error) + pr_err("alg: %s: Party A: generate public key test failed. err %d (expected %d)\n", + alg, err, vec->gen_pubkey_error); + else + err = 0; goto free_output; } @@ -3537,8 +3540,11 @@ static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec, crypto_req_done, &wait); err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait); if (err) { - pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n", - alg, err); + if (err != vec->comp_ss_error) + pr_err("alg: %s: Party A: compute shared secret test failed. err %d (expected %d)\n", + alg, err, vec->comp_ss_error); + else + err = 0; goto free_all; } diff --git a/crypto/testmgr.h b/crypto/testmgr.h index b717afc0926e..c39be00a8125 100644 --- a/crypto/testmgr.h +++ b/crypto/testmgr.h @@ -166,6 +166,8 @@ struct kpp_testvec { unsigned short expected_a_public_size; unsigned short expected_ss_size; bool genkey; + int gen_pubkey_error; + int comp_ss_error; }; static const char zeroed_string[48];