From patchwork Fri Oct 19 23:01:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 10650211 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B1B9190 for ; Fri, 19 Oct 2018 23:01:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A267728534 for ; Fri, 19 Oct 2018 23:01:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95D2428538; Fri, 19 Oct 2018 23:01:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E08028534 for ; Fri, 19 Oct 2018 23:01:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726964AbeJTHKC (ORCPT ); Sat, 20 Oct 2018 03:10:02 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:46435 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726403AbeJTHKC (ORCPT ); Sat, 20 Oct 2018 03:10:02 -0400 Received: by mail-lf1-f68.google.com with SMTP id p143-v6so15349971lfp.13; Fri, 19 Oct 2018 16:01:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JUDsKVEpFI2WSrEK4ymBlDWGBvyZbz/NUcx+7+FSjp4=; b=fuj9s2EZTXWHj29ukWHh7PNzDXcrFLQF/lbDPCXYMwVBs4TgjlMKEMxp8C9zI6uvay MegVEjv6y43IbzJrVOJ63rI6TXvaJvdHW/kDGQq8Nz7tKCKJVEzBHGBP2p8F8509yMqE WggKKD/CO8weBc7CIK0rJDTloFcEIXMb/SW9V08c/NdlcdcjNN4EHfT/h+eJ86iM4YUZ ETck4qYV/NmAaIXQM1jo09trLrYiVIWYZI8YfB9cpt5cbKKK+ZVMSuOUhS/e8HHbr0Ap Wk8mOJnpWNgixHXlcXOvC7x9iv4YUVWXvobesW5/ooRQ49HN4hsBgBFcfMwW0EBfc4CY Q9jA== 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:mime-version :content-transfer-encoding; bh=JUDsKVEpFI2WSrEK4ymBlDWGBvyZbz/NUcx+7+FSjp4=; b=D4mqZIuHH6Ke/32jEhHrhlIkK7GlqqNGZpiNjvV9Pk0czGUbY52dE91noAs4X1h8BT TRd3JZVWkcTZ27UX/HwkBsjqDcSLCG5CTAbHsdQkX/iE2cQWKJnrAna9aFUOy6xIb0Cz DudzQrWwnV6uvN7BE3C5fRCxtLHH6vU59P2HtgDa9EvsuG8TjEs7swjJZwf3JaJ4+ykN 9yrJUNtYts4/p+hk5rwzkYAmyJXXKOC2HptisJreQMQZlqVycbtApSnGa7JXv2KYooVk lT5bdaO6QFO3o4L9Rd0m2Iprf5E/OewFfCGiwKXY90yHjCW7tbvYtIWL2N3ZU/6XubEt h/xA== X-Gm-Message-State: ABuFfoiP73tzH/mUjavHmNpQ7Qe2QIsMf8Lj9G4zs7lcqmvNqmtlAyNA mvU8srWyihqKdltpmUoonsBdgz9uVpE= X-Google-Smtp-Source: ACcGV63wY6MeflnXKHMbndXt6Rieo0ZXgCkl4wAmapuCb3m4NeNoskWTXKevv/eHXEmp88IFfNo7JA== X-Received: by 2002:a19:4e9a:: with SMTP id u26-v6mr4015036lfk.91.1539990115675; Fri, 19 Oct 2018 16:01:55 -0700 (PDT) Received: from rhovanion.lumag.spb.ru ([188.162.65.177]) by smtp.gmail.com with ESMTPSA id x141-v6sm5392701lff.32.2018.10.19.16.01.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 16:01:54 -0700 (PDT) From: Dmitry Eremin-Solenikov To: linux-crypto@vger.kernel.org Cc: "David S. Miller" , Herbert Xu , stable@vger.kernel.org Subject: [PATCH 1/2] crypto: fix cfb mode decryption Date: Sat, 20 Oct 2018 02:01:52 +0300 Message-Id: <20181019230153.28201-1-dbaryshkov@gmail.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP crypto_cfb_decrypt_segment() incorrectly XOR'ed generated keystream with IV, rather than with data stream, resulting in incorrect decryption. Test vectors will be added in the next patch. Signed-off-by: Dmitry Eremin-Solenikov Cc: stable@vger.kernel.org --- crypto/cfb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/cfb.c b/crypto/cfb.c index a0d68c09e1b9..fd4e8500e121 100644 --- a/crypto/cfb.c +++ b/crypto/cfb.c @@ -144,7 +144,7 @@ static int crypto_cfb_decrypt_segment(struct skcipher_walk *walk, do { crypto_cfb_encrypt_one(tfm, iv, dst); - crypto_xor(dst, iv, bsize); + crypto_xor(dst, src, bsize); iv = src; src += bsize; From patchwork Fri Oct 19 23:01:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 10650213 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3FAAD109C for ; Fri, 19 Oct 2018 23:02:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 300DD28534 for ; Fri, 19 Oct 2018 23:02:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24AAC28538; Fri, 19 Oct 2018 23:02:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95C7228534 for ; Fri, 19 Oct 2018 23:02:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726758AbeJTHKE (ORCPT ); Sat, 20 Oct 2018 03:10:04 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:33363 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726698AbeJTHKE (ORCPT ); Sat, 20 Oct 2018 03:10:04 -0400 Received: by mail-lf1-f67.google.com with SMTP id o21-v6so26414911lfe.0; Fri, 19 Oct 2018 16:01:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tksC6ZT6nvSKWq+fpwpwO2Aguegsql45I96d/s2m8U0=; b=e9K0inu9kcb/tSq3xzfSwRRZgSxmwa484UHqr77tGHzi+ZHJjZ21VvtqNOpiagZ7z/ fUR9ILz0i7efbn/ayqLgi0hUliWSsKAUm8oDMfidduUxw1G53HgzzHElRqo3tLtVGmjF G/lcQr6lvDpF6U9SdEthmQiC9DTLOZCJAxsZtYKP7POVwcyUDKp4622cxV1WZYdfF8Mn bhxK84v/BJuXqR8QyGxgmTsmOgI0ED6iW0bDrHf6eXSCVzGY1r2qcGPJLWdJQmYxB77W mv9w0pqK1LLL1nDdIDVK5l35E2ml2o4YvaoLQTilHxArvaYE23y7RGTt5ZP8wqo3vIjx P9IQ== 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=tksC6ZT6nvSKWq+fpwpwO2Aguegsql45I96d/s2m8U0=; b=HgPMfzyJ/pWUwXWl2XO1UWRxiuMidbxz8Z1+YhpsM5JY5DyHQqzBeCn3yjQb6qdqIZ +hPMliWessrQWwy8btwsWj/Tht4qhtMNtlfQOv+wy8ameJpzlqEPVUOEBtYm7HyU4PN1 r5GUxd5YUrbE1thlE06yo37jg7RQ3qKl63jqbIGJMTiJRTZW1RtzDPIaNag+yU4w7o67 q5uKjwAS/1gAJSGDzLxIK+qrYQiZYZxD3J81nxlcM+oTpDQqB3YDbEoHBv5wv20tobwH /ozruAWVFGMX1hTctfHLhUyhBiHtJyFIGV7fTHQT20RRdR/+g6VduFISyhAab/Xhslek gRMg== X-Gm-Message-State: ABuFfohuIl1ccbbnoUWp20/ItfNfbQLjNkdkrHO06M24ZJKn3mDXcESX VN9VO69vcnReYnKO16ngyxR1s9jkLYc= X-Google-Smtp-Source: ACcGV62Kop4zmAWzDb0wjRqTZRVnG5Vd9QJVRtfD33R+RDa2gCHKYpTwWXbsf+VQ3WNybVBgbo/I8w== X-Received: by 2002:a19:17d8:: with SMTP id 85mr1956270lfx.5.1539990116845; Fri, 19 Oct 2018 16:01:56 -0700 (PDT) Received: from rhovanion.lumag.spb.ru ([188.162.65.177]) by smtp.gmail.com with ESMTPSA id x141-v6sm5392701lff.32.2018.10.19.16.01.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 16:01:56 -0700 (PDT) From: Dmitry Eremin-Solenikov To: linux-crypto@vger.kernel.org Cc: "David S. Miller" , Herbert Xu , stable@vger.kernel.org Subject: [PATCH 2/2] crypto: testmgr: add AES-CFB tests Date: Sat, 20 Oct 2018 02:01:53 +0300 Message-Id: <20181019230153.28201-2-dbaryshkov@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181019230153.28201-1-dbaryshkov@gmail.com> References: <20181019230153.28201-1-dbaryshkov@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add AES128/192/256-CFB testvectors from NIST SP800-38A. Signed-off-by: Dmitry Eremin-Solenikov Cc: stable@vger.kernel.org Signed-off-by: Dmitry Eremin-Solenikov --- crypto/tcrypt.c | 5 ++++ crypto/testmgr.c | 7 +++++ crypto/testmgr.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index bdde95e8d369..a6315827d240 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c @@ -1733,6 +1733,7 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) ret += tcrypt_test("xts(aes)"); ret += tcrypt_test("ctr(aes)"); ret += tcrypt_test("rfc3686(ctr(aes))"); + ret += tcrypt_test("cfb(aes)"); break; case 11: @@ -2059,6 +2060,10 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) speed_template_16_24_32); test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0, speed_template_16_24_32); + test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0, + speed_template_16_24_32); + test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0, + speed_template_16_24_32); break; case 201: diff --git a/crypto/testmgr.c b/crypto/testmgr.c index a1d42245082a..016d61c419fc 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -2684,6 +2684,13 @@ static const struct alg_test_desc alg_test_descs[] = { .dec = __VECS(aes_ccm_dec_tv_template) } } + }, { + .alg = "cfb(aes)", + .test = alg_test_skcipher, + .fips_allowed = 1, + .suite = { + .cipher = __VECS(aes_cfb_tv_template) + }, }, { .alg = "chacha20", .test = alg_test_skcipher, diff --git a/crypto/testmgr.h b/crypto/testmgr.h index 173111c70746..19b6d184c8fb 100644 --- a/crypto/testmgr.h +++ b/crypto/testmgr.h @@ -12081,6 +12081,82 @@ static const struct cipher_testvec aes_cbc_tv_template[] = { }, }; +static const struct cipher_testvec aes_cfb_tv_template[] = { + { /* From NIST SP800-38A */ + .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6" + "\xab\xf7\x15\x88\x09\xcf\x4f\x3c", + .klen = 16, + .iv = "\x00\x01\x02\x03\x04\x05\x06\x07" + "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", + .ptext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96" + "\xe9\x3d\x7e\x11\x73\x93\x17\x2a" + "\xae\x2d\x8a\x57\x1e\x03\xac\x9c" + "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51" + "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11" + "\xe5\xfb\xc1\x19\x1a\x0a\x52\xef" + "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17" + "\xad\x2b\x41\x7b\xe6\x6c\x37\x10", + .ctext = "\x3b\x3f\xd9\x2e\xb7\x2d\xad\x20" + "\x33\x34\x49\xf8\xe8\x3c\xfb\x4a" + "\xc8\xa6\x45\x37\xa0\xb3\xa9\x3f" + "\xcd\xe3\xcd\xad\x9f\x1c\xe5\x8b" + "\x26\x75\x1f\x67\xa3\xcb\xb1\x40" + "\xb1\x80\x8c\xf1\x87\xa4\xf4\xdf" + "\xc0\x4b\x05\x35\x7c\x5d\x1c\x0e" + "\xea\xc4\xc6\x6f\x9f\xf7\xf2\xe6", + .len = 64, + }, { + .key = "\x8e\x73\xb0\xf7\xda\x0e\x64\x52" + "\xc8\x10\xf3\x2b\x80\x90\x79\xe5" + "\x62\xf8\xea\xd2\x52\x2c\x6b\x7b", + .klen = 24, + .iv = "\x00\x01\x02\x03\x04\x05\x06\x07" + "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", + .ptext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96" + "\xe9\x3d\x7e\x11\x73\x93\x17\x2a" + "\xae\x2d\x8a\x57\x1e\x03\xac\x9c" + "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51" + "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11" + "\xe5\xfb\xc1\x19\x1a\x0a\x52\xef" + "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17" + "\xad\x2b\x41\x7b\xe6\x6c\x37\x10", + .ctext = "\xcd\xc8\x0d\x6f\xdd\xf1\x8c\xab" + "\x34\xc2\x59\x09\xc9\x9a\x41\x74" + "\x67\xce\x7f\x7f\x81\x17\x36\x21" + "\x96\x1a\x2b\x70\x17\x1d\x3d\x7a" + "\x2e\x1e\x8a\x1d\xd5\x9b\x88\xb1" + "\xc8\xe6\x0f\xed\x1e\xfa\xc4\xc9" + "\xc0\x5f\x9f\x9c\xa9\x83\x4f\xa0" + "\x42\xae\x8f\xba\x58\x4b\x09\xff", + .len = 64, + }, { + .key = "\x60\x3d\xeb\x10\x15\xca\x71\xbe" + "\x2b\x73\xae\xf0\x85\x7d\x77\x81" + "\x1f\x35\x2c\x07\x3b\x61\x08\xd7" + "\x2d\x98\x10\xa3\x09\x14\xdf\xf4", + .klen = 32, + .iv = "\x00\x01\x02\x03\x04\x05\x06\x07" + "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", + .ptext = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96" + "\xe9\x3d\x7e\x11\x73\x93\x17\x2a" + "\xae\x2d\x8a\x57\x1e\x03\xac\x9c" + "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51" + "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11" + "\xe5\xfb\xc1\x19\x1a\x0a\x52\xef" + "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17" + "\xad\x2b\x41\x7b\xe6\x6c\x37\x10", + .ctext = "\xdc\x7e\x84\xbf\xda\x79\x16\x4b" + "\x7e\xcd\x84\x86\x98\x5d\x38\x60" + "\x39\xff\xed\x14\x3b\x28\xb1\xc8" + "\x32\x11\x3c\x63\x31\xe5\x40\x7b" + "\xdf\x10\x13\x24\x15\xe5\x4b\x92" + "\xa1\x3e\xd0\xa8\x26\x7a\xe2\xf9" + "\x75\xa3\x85\x74\x1a\xb9\xce\xf8" + "\x20\x31\x62\x3d\x55\xb1\xe4\x71", + .len = 64, + }, +}; + static const struct aead_testvec hmac_md5_ecb_cipher_null_enc_tv_template[] = { { /* Input data from RFC 2410 Case 1 */ #ifdef __LITTLE_ENDIAN