From nobody Mon Apr 27 04:37:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D899C433EF for ; Fri, 17 Jun 2022 07:08:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380393AbiFQHIh (ORCPT ); Fri, 17 Jun 2022 03:08:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380104AbiFQHIQ (ORCPT ); Fri, 17 Jun 2022 03:08:16 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0062463530 for ; Fri, 17 Jun 2022 00:08:15 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id y13-20020a17090a154d00b001eaaa3b9b8dso3424402pja.2 for ; Fri, 17 Jun 2022 00:08:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ehUSni+ddsWxiWUC9Vsg9AFV5u1hN4XtlUBq70uM3/Y=; b=JEcTyJoTA/2JVh2/RYjQrzVcoXo3GmPS3qUuYVsm2YIjDmmx5zEovpQ+qQqUFlmgq5 fHFYbR7bAyF0B0i0G8JJ3KjD1r2qAq9SeXhlkcx/dBlVFrm0TlfeAUZhzcBrh05vjf4d SBkdq7mpkJjKe5ojfZyO3iWKzBYbRGINNFsYSi6qUlwZDFf/0ycbnKCa5ppTDG+j85Qw umZpAfcfNUvfhv5KphLUd0G/ytcU6yyu1QGCWVULPpTs0h0JI9W7akf8hCvpX5aMbib1 VmcNUUC5PpIfgLVXW6fuCJ+Jwjzj6+GYmTc1dVId2jAjMHb14E4Jk/BvHNTQGCdypH+F ZmYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ehUSni+ddsWxiWUC9Vsg9AFV5u1hN4XtlUBq70uM3/Y=; b=KBPybl8SvhroBITmL2xdwMpragDq46opDepuuGAHfYRNoSqWK8LwtmetLNqsGsIcVb 1l4VE6YMWyhZy4cAhpChvXovQWpgf/a6bKbWnj4hkgfcnd1IlFjgqDtKfb0kn23VmBge LY1fuhx/x3gsPq167LH9sI8mP1zZLKH9cwpsaojYLaTgYp4W9fpqpn+0/moRecxrcqb2 QdkDow3Pry+FnO/VCJq6LChXDTqTmA1RW+I7wrF0QKcYJl0Qc0kQIkPCSs0vR0KuWxy1 MvWwbwapdbtjvwijZ7q3Zr8n5KRg8+Bs+rgmB58EPhvPIruk0W+BcjzmTRod53mwqgbo exBw== X-Gm-Message-State: AJIora+RQ9ac7QOu+89nGnZxW4e0acJvipfy0Hku7aFlmXLcswsa74oN /WQOl5hVHUn++KGjsxPvePL5/A== X-Google-Smtp-Source: AGRyM1uA3PmYfXOy+x80Y0hzoY8VAjxQiO0hrFcAylctGH4WR2Xqa6v5eLVXVrV1/VxMcCEYtbtm9A== X-Received: by 2002:a17:903:22cb:b0:167:992f:60c3 with SMTP id y11-20020a17090322cb00b00167992f60c3mr8383332plg.59.1655449695368; Fri, 17 Jun 2022 00:08:15 -0700 (PDT) Received: from FVFDK26JP3YV.bytedance.net ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id j1-20020a170903028100b00163d4c3ffabsm2757868plr.304.2022.06.17.00.08.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jun 2022 00:08:14 -0700 (PDT) From: Lei He To: herbert@gondor.apana.org.au, davem@davemloft.net, dhowells@redhat.com, mst@redhat.com Cc: arei.gonglei@huawei.com, jasowang@redhat.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, pizhenwei@bytedance.com, helei.sig11@bytedance.com, f4bug@amsat.org, berrange@redhat.com Subject: [PATCH 1/4] crypto: fix the calculation of max_size for ECDSA Date: Fri, 17 Jun 2022 15:07:50 +0800 Message-Id: <20220617070754.73667-2-helei.sig11@bytedance.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220617070754.73667-1-helei.sig11@bytedance.com> References: <20220617070754.73667-1-helei.sig11@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: lei he The signature of ECDSA is consists of two big integers up to the size of keylen, and is DER encoded into one SEQUENCE. Calculate max_size of ECDSA signature more accurately according to the DER encoding rules. Signed-off-by: lei he Acked-by: Michael S. Tsirkin --- crypto/Kconfig | 1 + crypto/Makefile | 2 ++ crypto/ecdsa.c | 3 ++- crypto/ecdsa_helper.c | 45 +++++++++++++++++++++++++++++++++ include/crypto/internal/ecdsa.h | 15 +++++++++++ include/linux/asn1_encoder.h | 2 ++ lib/asn1_encoder.c | 3 ++- 7 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 crypto/ecdsa_helper.c create mode 100644 include/crypto/internal/ecdsa.h diff --git a/crypto/Kconfig b/crypto/Kconfig index 41068811fd0e..b54d067602cc 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -254,6 +254,7 @@ config CRYPTO_ECDSA select CRYPTO_ECC select CRYPTO_AKCIPHER select ASN1 + select ASN1_ENCODER help Elliptic Curve Digital Signature Algorithm (NIST P192, P256 etc.) is A NIST cryptographic standard algorithm. Only signature verification diff --git a/crypto/Makefile b/crypto/Makefile index f754c4d17d6b..b59b15ee087c 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -52,8 +52,10 @@ obj-$(CONFIG_CRYPTO_SM2) +=3D sm2_generic.o =20 $(obj)/ecdsasignature.asn1.o: $(obj)/ecdsasignature.asn1.c $(obj)/ecdsasig= nature.asn1.h $(obj)/ecdsa.o: $(obj)/ecdsasignature.asn1.h + ecdsa_generic-y +=3D ecdsa.o ecdsa_generic-y +=3D ecdsasignature.asn1.o +ecdsa_generic-y +=3D ecdsa_helper.o obj-$(CONFIG_CRYPTO_ECDSA) +=3D ecdsa_generic.o =20 crypto_acompress-y :=3D acompress.o diff --git a/crypto/ecdsa.c b/crypto/ecdsa.c index b3a8a6b572ba..2ba44c92d271 100644 --- a/crypto/ecdsa.c +++ b/crypto/ecdsa.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -262,7 +263,7 @@ static unsigned int ecdsa_max_size(struct crypto_akciph= er *tfm) { struct ecc_ctx *ctx =3D akcipher_tfm_ctx(tfm); =20 - return ctx->pub_key.ndigits << ECC_DIGITS_TO_BYTES_SHIFT; + return ecdsa_max_signature_size(ctx->curve); } =20 static int ecdsa_nist_p384_init_tfm(struct crypto_akcipher *tfm) diff --git a/crypto/ecdsa_helper.c b/crypto/ecdsa_helper.c new file mode 100644 index 000000000000..487c4e9c0f67 --- /dev/null +++ b/crypto/ecdsa_helper.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * RSA key extract helper + * + * Copyright 2022 Bytedance CO., LTD. + * + * Authors: lei he + */ +#include +#include +#include +#include +#include +#include + +unsigned int ecdsa_max_signature_size(const struct ecc_curve *curve) +{ + unsigned int keylen =3D curve->g.ndigits * sizeof(u64); + /* Up to one extra byte to indicate the format */ + unsigned char buffer[sizeof(size_t) + 1], *data =3D buffer; + int buffer_len =3D sizeof(buffer); + unsigned int coordinate_length, sequence_length; + + asn1_encode_length(&data, &buffer_len, keylen); + /** + * The extra cost for encoding keylen bytes as INTEGER in ASN.1: + * 1. one byte for tag + * 2. sizeof(buffer) - buffer_len bytes for length + * 3. one leading zero byte for integers whose leftmost bit is 1 + */ + coordinate_length =3D 1 + sizeof(buffer) - buffer_len + 1 + keylen; + + /** + * The extra cost for encoding coordinate_length * 2 bytes as SEQUENCE in= ASN.1: + * 1. one byte for tag + * 2. sizeof(buffer) - buffer_len bytes for length + */ + buffer_len =3D sizeof(buffer); + data =3D buffer; + asn1_encode_length(&data, &buffer_len, coordinate_length * 2); + sequence_length =3D 1 + sizeof(buffer) - buffer_len + coordinate_length *= 2; + + return sequence_length; +} +EXPORT_SYMBOL_GPL(ecdsa_max_signature_size); diff --git a/include/crypto/internal/ecdsa.h b/include/crypto/internal/ecds= a.h new file mode 100644 index 000000000000..e35638a35dc2 --- /dev/null +++ b/include/crypto/internal/ecdsa.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * ECDSA internal helpers + * + * Copyright (c) 2022 lei he + */ + + #ifndef _CRYPTO_ECDSA_H + #define _CRYPTO_ECDSA_H + +#include + +unsigned int ecdsa_max_signature_size(const struct ecc_curve *curve); + +#endif diff --git a/include/linux/asn1_encoder.h b/include/linux/asn1_encoder.h index 08cd0c2ad34f..fe439c9a73e3 100644 --- a/include/linux/asn1_encoder.h +++ b/include/linux/asn1_encoder.h @@ -29,4 +29,6 @@ unsigned char * asn1_encode_boolean(unsigned char *data, const unsigned char *end_data, bool val); =20 +int asn1_encode_length(unsigned char **data, int *data_len, int len); + #endif diff --git a/lib/asn1_encoder.c b/lib/asn1_encoder.c index 0fd3c454a468..644af3055ebb 100644 --- a/lib/asn1_encoder.c +++ b/lib/asn1_encoder.c @@ -188,7 +188,7 @@ EXPORT_SYMBOL_GPL(asn1_encode_oid); * encoder primitives to accept negative lengths as singalling the * sequence will be re-encoded when the length is known. */ -static int asn1_encode_length(unsigned char **data, int *data_len, int len) +int asn1_encode_length(unsigned char **data, int *data_len, int len) { if (*data_len < 1) return -EINVAL; @@ -239,6 +239,7 @@ static int asn1_encode_length(unsigned char **data, int= *data_len, int len) =20 return 0; } +EXPORT_SYMBOL_GPL(asn1_encode_length); =20 /** * asn1_encode_tag() - add a tag for optional or explicit value --=20 2.20.1 From nobody Mon Apr 27 04:37:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C92EC43334 for ; Fri, 17 Jun 2022 07:08:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380418AbiFQHIm (ORCPT ); Fri, 17 Jun 2022 03:08:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380362AbiFQHIa (ORCPT ); Fri, 17 Jun 2022 03:08:30 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6003863BE1 for ; Fri, 17 Jun 2022 00:08:28 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id w21so3485606pfc.0 for ; Fri, 17 Jun 2022 00:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rr6W1HmkOzqLYvFXcgRYRczNT4ybnvSLXNzzsMN6g3Q=; b=JpTFJBT1fX9DRCTHhPWB6z8Us/gWAXimLrXLSCaTPqgaxc04h48CuHFEXRXUtfjR4L 2gy0HQMZJTBJMpRvCZSPnQaPi1HTXO3bDHc5JlhR7yAcaNKchysoIWUBREQaNkCl4aRx TUMdgN0Wdl2/Z/gFVTm/dF6WAuxGVxRdVUJPp4sPa43gNrxCMLHRGak3X6PIK5Gwz5U2 TDrx1JsL/CNO4TSmxUxzfWqPMYY2mmJ/hgMzoPct14DvkDXyuWBnDaqPUcKv79B0XvHG uG4gX7N6X2681ZrdL2mg7JOK4DYTQbf5X0dRFVgW++vzTxDsHn+GnXRjrNhzWxKrHscT 5uyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rr6W1HmkOzqLYvFXcgRYRczNT4ybnvSLXNzzsMN6g3Q=; b=pE3l2o2IoPL6Rgz+4G46o8UKR5Yl1T0hllpTwvSck+Hbut8ALT5k6nzc1E0rMOXWep qTEuVv7FAJHwK5RndQ2iJsR4r3xqCnlCDNxo5U7PUBn91zqfrXcp9oqqxSI4OFyzM8G0 RUhFstJNwhYleTIPVBRwIw3tkNN7vVmRwmCvtBD43BdIWP9ibnJhD3q/JACdKcFcKZDN SpDlpKFptctcgUiaR70ofBMJSAhbitj75kv35hB0bDj36Asr2XqK2bWU4howKcpvc33L 1cQGiwvn+zrrt8Dn5hiXjqCSlKnSFyVWcAMr40K3+K3HlvkYtJqWCUMRpGkWA49Lr5HD QT1A== X-Gm-Message-State: AJIora+s3Vfikc2w/67mXb4UIq/45rWwpxMG6cTqFmBq3P4YsIDyqM8l t0wk4++gxgXLL7UGWM162b88ww== X-Google-Smtp-Source: AGRyM1sriNmviF+SWX8Fai61ZaQi7+JVfnQZUVSjacyrHsCfKtFuCMuHUuPwI5p/VyBiOVug9DEIGw== X-Received: by 2002:a05:6a00:21c8:b0:4c4:4bd:dc17 with SMTP id t8-20020a056a0021c800b004c404bddc17mr8683594pfj.57.1655449707841; Fri, 17 Jun 2022 00:08:27 -0700 (PDT) Received: from FVFDK26JP3YV.bytedance.net ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id j1-20020a170903028100b00163d4c3ffabsm2757868plr.304.2022.06.17.00.08.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jun 2022 00:08:27 -0700 (PDT) From: Lei He To: herbert@gondor.apana.org.au, davem@davemloft.net, dhowells@redhat.com, mst@redhat.com Cc: arei.gonglei@huawei.com, jasowang@redhat.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, pizhenwei@bytedance.com, helei.sig11@bytedance.com, f4bug@amsat.org, berrange@redhat.com Subject: [PATCH 2/4] crypto: pkcs8 parser support ECDSA private keys Date: Fri, 17 Jun 2022 15:07:52 +0800 Message-Id: <20220617070754.73667-4-helei.sig11@bytedance.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220617070754.73667-1-helei.sig11@bytedance.com> References: <20220617070754.73667-1-helei.sig11@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: lei he Make pkcs8_private_key_parser can identify ECDSA private keys. Signed-off-by: lei he Acked-by: Michael S. Tsirkin --- crypto/akcipher.c | 10 ++++++ crypto/asymmetric_keys/pkcs8.asn1 | 2 +- crypto/asymmetric_keys/pkcs8_parser.c | 45 +++++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/crypto/akcipher.c b/crypto/akcipher.c index f866085c8a4a..3adcdc6d48c2 100644 --- a/crypto/akcipher.c +++ b/crypto/akcipher.c @@ -120,6 +120,12 @@ static int akcipher_default_op(struct akcipher_request= *req) return -ENOSYS; } =20 +static int akcipher_default_set_key(struct crypto_akcipher *tfm, + const void *key, unsigned int keylen) +{ + return -ENOSYS; +} + int crypto_register_akcipher(struct akcipher_alg *alg) { struct crypto_alg *base =3D &alg->base; @@ -132,6 +138,10 @@ int crypto_register_akcipher(struct akcipher_alg *alg) alg->encrypt =3D akcipher_default_op; if (!alg->decrypt) alg->decrypt =3D akcipher_default_op; + if (!alg->set_pub_key) + alg->set_pub_key =3D akcipher_default_set_key; + if (!alg->set_priv_key) + alg->set_priv_key =3D akcipher_default_set_key; =20 akcipher_prepare_alg(alg); return crypto_register_alg(base); diff --git a/crypto/asymmetric_keys/pkcs8.asn1 b/crypto/asymmetric_keys/pkc= s8.asn1 index 702c41a3c713..1791ddf4168a 100644 --- a/crypto/asymmetric_keys/pkcs8.asn1 +++ b/crypto/asymmetric_keys/pkcs8.asn1 @@ -20,5 +20,5 @@ Attribute ::=3D ANY =20 AlgorithmIdentifier ::=3D SEQUENCE { algorithm OBJECT IDENTIFIER ({ pkcs8_note_OID }), - parameters ANY OPTIONAL + parameters ANY OPTIONAL ({ pkcs8_note_algo_parameter }) } diff --git a/crypto/asymmetric_keys/pkcs8_parser.c b/crypto/asymmetric_keys= /pkcs8_parser.c index 105dcce27f71..e507c635ead5 100644 --- a/crypto/asymmetric_keys/pkcs8_parser.c +++ b/crypto/asymmetric_keys/pkcs8_parser.c @@ -24,6 +24,8 @@ struct pkcs8_parse_context { enum OID algo_oid; /* Algorithm OID */ u32 key_size; const void *key; + const void *algo_param; + u32 algo_param_len; }; =20 /* @@ -47,6 +49,17 @@ int pkcs8_note_OID(void *context, size_t hdrlen, return 0; } =20 +int pkcs8_note_algo_parameter(void *context, size_t hdrlen, + unsigned char tag, + const void *value, size_t vlen) +{ + struct pkcs8_parse_context *ctx =3D context; + + ctx->algo_param =3D value; + ctx->algo_param_len =3D vlen; + return 0; +} + /* * Note the version number of the ASN.1 blob. */ @@ -69,11 +82,37 @@ int pkcs8_note_algo(void *context, size_t hdrlen, const void *value, size_t vlen) { struct pkcs8_parse_context *ctx =3D context; - - if (ctx->last_oid !=3D OID_rsaEncryption) + enum OID curve_id; + + switch (ctx->last_oid) { + case OID_id_ecPublicKey: + if (!ctx->algo_param || ctx->algo_param_len =3D=3D 0) + return -EBADMSG; + curve_id =3D look_up_OID(ctx->algo_param, ctx->algo_param_len); + + switch (curve_id) { + case OID_id_prime192v1: + ctx->pub->pkey_algo =3D "ecdsa-nist-p192"; + break; + case OID_id_prime256v1: + ctx->pub->pkey_algo =3D "ecdsa-nist-p256"; + break; + case OID_id_ansip384r1: + ctx->pub->pkey_algo =3D "ecdsa-nist-p384"; + break; + default: + return -ENOPKG; + } + break; + + case OID_rsaEncryption: + ctx->pub->pkey_algo =3D "rsa"; + break; + + default: return -ENOPKG; + } =20 - ctx->pub->pkey_algo =3D "rsa"; return 0; } =20 --=20 2.20.1 From nobody Mon Apr 27 04:37:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E020C433EF for ; Fri, 17 Jun 2022 07:09:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380442AbiFQHJA (ORCPT ); Fri, 17 Jun 2022 03:09:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380402AbiFQHIr (ORCPT ); Fri, 17 Jun 2022 03:08:47 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5878462CDE for ; Fri, 17 Jun 2022 00:08:40 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id w5-20020a17090aea0500b001ec7c45794bso187212pjy.3 for ; Fri, 17 Jun 2022 00:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tKM3xvFOU9BbHzW/2uuQbOBzRGB1RdsYKFUv60RJdxg=; b=cRelYOHqlySdg56lDY7wDD8qCGwBPr6ibudSH7Nv65Po/RJ/3CLzsfO0mgLoMjfgCD L38K4ISu+JEI74X/i0H2oH+u6N0O9BUdCrfPbBkZIZ5WjqamLz5/6/bfLLQukSkWalnF Wo5bwLmyB1OE85RLdcwEBcBAXGCIPrfSXYvpcQhXhR99s+U6YyDsAPSzz/2SIMyNjV5Q 7oH3X51UibU84QBz2HVuCsI0oYFEVf1OjU4rFhtOXnP8DFN7frZjtFAwA8Zudgaki/Xt 2SJucg4GGn6clqwKgtOB98sV2PyApzJYCqRiwb501ccwZn08pfr4/rPeJ/N6MpIYcM1I SQCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tKM3xvFOU9BbHzW/2uuQbOBzRGB1RdsYKFUv60RJdxg=; b=Yl1OX2+/R9A/CgPmtwjH5+Z0EQotx/7ZKu/6PYJajbtqlybwBSXDYLSjNoq0BuQJmr WxduoqBxuhpbaMeLIgjSOoxy4fLLguaNaNjji+RQWFg/f7Kxt/GOMmYPfTo3I+jvc0yH z0anaEeb0Z5ubuKpSH9wi3SgvmNlg46UK7dh5IsEPkj0D/VAVh+UlmgofmYc1OHEnzvr c4piZW6kKbAAz4ehF38XliSUZfGmQzUd8TDJcMEJxfJLVc2eds+Er27UV3GLkfOnXV+S y7TD1thqUFlU8y7HMsTxihXVVIuSQJalg8I1gHsWFIDBbfFWWkXf0IPNvrRrP4XHN+Sq WsLg== X-Gm-Message-State: AJIora/j1ue6hOI/rQqeMVZiIZ4ayiXtP5QftRvDl71A7I+ayYZhWtul bz/136EfvDtvZXWQ7brf4PqWFQ== X-Google-Smtp-Source: AGRyM1vh2901KtWuAh/a/NRuzghOqX+27vND6C04We/BO58wByPDazd2slZkqQgFHUupQSy9H5DqLQ== X-Received: by 2002:a17:902:728f:b0:168:b18e:9e0d with SMTP id d15-20020a170902728f00b00168b18e9e0dmr8130408pll.174.1655449719851; Fri, 17 Jun 2022 00:08:39 -0700 (PDT) Received: from FVFDK26JP3YV.bytedance.net ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id j1-20020a170903028100b00163d4c3ffabsm2757868plr.304.2022.06.17.00.08.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jun 2022 00:08:39 -0700 (PDT) From: Lei He To: herbert@gondor.apana.org.au, davem@davemloft.net, dhowells@redhat.com, mst@redhat.com Cc: arei.gonglei@huawei.com, jasowang@redhat.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, pizhenwei@bytedance.com, helei.sig11@bytedance.com, f4bug@amsat.org, berrange@redhat.com Subject: [PATCH 3/4] crypto: remove unused field in pkcs8_parse_context Date: Fri, 17 Jun 2022 15:07:53 +0800 Message-Id: <20220617070754.73667-5-helei.sig11@bytedance.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220617070754.73667-1-helei.sig11@bytedance.com> References: <20220617070754.73667-1-helei.sig11@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: lei he remove unused field 'algo_oid' in pkcs8_parse_context Signed-off-by: lei he Acked-by: Michael S. Tsirkin --- crypto/asymmetric_keys/pkcs8_parser.c | 1 - 1 file changed, 1 deletion(-) diff --git a/crypto/asymmetric_keys/pkcs8_parser.c b/crypto/asymmetric_keys= /pkcs8_parser.c index e507c635ead5..f81317234331 100644 --- a/crypto/asymmetric_keys/pkcs8_parser.c +++ b/crypto/asymmetric_keys/pkcs8_parser.c @@ -21,7 +21,6 @@ struct pkcs8_parse_context { struct public_key *pub; unsigned long data; /* Start of data */ enum OID last_oid; /* Last OID encountered */ - enum OID algo_oid; /* Algorithm OID */ u32 key_size; const void *key; const void *algo_param; --=20 2.20.1 From nobody Mon Apr 27 04:37:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68EB5C433EF for ; Fri, 17 Jun 2022 07:09:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380534AbiFQHJJ (ORCPT ); Fri, 17 Jun 2022 03:09:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380451AbiFQHIz (ORCPT ); Fri, 17 Jun 2022 03:08:55 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4315664D0B for ; Fri, 17 Jun 2022 00:08:48 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id 73-20020a17090a0fcf00b001eaee69f600so3428912pjz.1 for ; Fri, 17 Jun 2022 00:08:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mNxvf0dysPqGeqaXEmlJUiXGB4Uji2CdxJcngPXkQ8g=; b=OSwg7HQaj3nGg0ObBHiJbHdqS5ow7StJ8oxQbnKT402V9tgP76EDje+JunCqG+ghGv 5GNVVor2vJBnD8/v5SVKEGGqcvfmY0w+uwWqTfTOuBSmL5yOylBNr79Ltm9st1pAG2MN VIxp9Gx31mJRpoQv2YREMg3C+ulxbfDQid90WcFM08adz5PROqj3py3UBmOsIj8ihPWx ZnQ+FewcVR+WBPpRD3koDcAM5qEcSEFxbX3Q1gPe3mta5Kl3BVfBNsANsKDZ6aAcIAt5 Uw2Gh9hGncUho3wV9YCqgwAgr3wyF9BZbZIPRZ0BKWpeus1d3mBxcrjQ9AQ/kkDg3zfT GhwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mNxvf0dysPqGeqaXEmlJUiXGB4Uji2CdxJcngPXkQ8g=; b=5JAXicfFqarTo+vzezh2yCrBT8qvWek+puvWwKiGzvRwLA348B7UXxC0tH/1qBgpEA 0KA7Aca7gmXrV7555Q+XkMcfBaquzWQ1ZurPLiKRxZYX0yQ12mhR5xKcuWGb7BKK3j/d Aw8f4aXnDky4CKBQNfsEPX1szi2u8MkS1uqLXiGCQh8gveOV0SPd7dc4a3oakhoxzidC 0UDqg4GVTTRj4uhm/YQ7p7qtFnFMfa2rHWDoiCdxC35Ef/h4dsoy7t3Fv/p16AE0Ojmt JYzK5Z21+w2Obu8xaDO5BeWWbZLIi9FQt1HarECxuWpmEY6LIEXqroIaw4rHgI0/1EIo tUtw== X-Gm-Message-State: AJIora8jxvgl0ytNaecwZJfALy7d+AFsMzA/3NTT99RdP/t9rGcuyr1c 2EBWQIuhFUCrX87XfMAyRr1Png== X-Google-Smtp-Source: AGRyM1srWUOA5NLFVRQzpBMWPbgbVx9Yo54Z00OIZfUTL6Mhhh3sQlp36Zx1ZLmPZp5x8TPEhSH0ww== X-Received: by 2002:a17:903:234a:b0:167:997f:bc4c with SMTP id c10-20020a170903234a00b00167997fbc4cmr8039374plh.120.1655449727144; Fri, 17 Jun 2022 00:08:47 -0700 (PDT) Received: from FVFDK26JP3YV.bytedance.net ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id j1-20020a170903028100b00163d4c3ffabsm2757868plr.304.2022.06.17.00.08.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jun 2022 00:08:46 -0700 (PDT) From: Lei He To: herbert@gondor.apana.org.au, davem@davemloft.net, dhowells@redhat.com, mst@redhat.com Cc: arei.gonglei@huawei.com, jasowang@redhat.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, pizhenwei@bytedance.com, helei.sig11@bytedance.com, f4bug@amsat.org, berrange@redhat.com Subject: [PATCH 4/4] virtio-crypto: support ECDSA algorithm Date: Fri, 17 Jun 2022 15:07:54 +0800 Message-Id: <20220617070754.73667-6-helei.sig11@bytedance.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220617070754.73667-1-helei.sig11@bytedance.com> References: <20220617070754.73667-1-helei.sig11@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: lei he Support ECDSA algorithm for driver virtio-crypto Signed-off-by: lei he Acked-by: Michael S. Tsirkin Reported-by: kernel test robot --- .../virtio/virtio_crypto_akcipher_algs.c | 259 ++++++++++++++++-- 1 file changed, 238 insertions(+), 21 deletions(-) diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c b/drivers/= crypto/virtio/virtio_crypto_akcipher_algs.c index 2a60d0525cde..da628a6de696 100644 --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c @@ -10,7 +10,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -23,6 +25,10 @@ struct virtio_crypto_rsa_ctx { MPI n; }; =20 +struct virtio_crypto_ecdsa_ctx { + const struct ecc_curve *curve; +}; + struct virtio_crypto_akcipher_ctx { struct crypto_engine_ctx enginectx; struct virtio_crypto *vcrypto; @@ -31,6 +37,7 @@ struct virtio_crypto_akcipher_ctx { __u64 session_id; union { struct virtio_crypto_rsa_ctx rsa_ctx; + struct virtio_crypto_ecdsa_ctx ecdsa_ctx; }; }; =20 @@ -279,7 +286,7 @@ static int __virtio_crypto_akcipher_do_req(struct virti= o_crypto_akcipher_request return -ENOMEM; } =20 -static int virtio_crypto_rsa_do_req(struct crypto_engine *engine, void *vr= eq) +static int virtio_crypto_akcipher_do_req(struct crypto_engine *engine, voi= d *vreq, int algo) { struct akcipher_request *req =3D container_of(vreq, struct akcipher_reque= st, base); struct virtio_crypto_akcipher_request *vc_akcipher_req =3D akcipher_reque= st_ctx(req); @@ -300,7 +307,7 @@ static int virtio_crypto_rsa_do_req(struct crypto_engin= e *engine, void *vreq) /* build request header */ header =3D &vc_req->req_data->header; header->opcode =3D cpu_to_le32(vc_akcipher_req->opcode); - header->algo =3D cpu_to_le32(VIRTIO_CRYPTO_AKCIPHER_RSA); + header->algo =3D cpu_to_le32(algo); header->session_id =3D cpu_to_le64(ctx->session_id); =20 /* build request akcipher data */ @@ -318,7 +325,12 @@ static int virtio_crypto_rsa_do_req(struct crypto_engi= ne *engine, void *vreq) return 0; } =20 -static int virtio_crypto_rsa_req(struct akcipher_request *req, uint32_t op= code) +static int virtio_crypto_rsa_do_req(struct crypto_engine *engine, void *vr= eq) +{ + return virtio_crypto_akcipher_do_req(engine, vreq, VIRTIO_CRYPTO_AKCIPHER= _RSA); +} + +static int virtio_crypto_akcipher_req(struct akcipher_request *req, uint32= _t opcode) { struct crypto_akcipher *atfm =3D crypto_akcipher_reqtfm(req); struct virtio_crypto_akcipher_ctx *ctx =3D akcipher_tfm_ctx(atfm); @@ -337,24 +349,24 @@ static int virtio_crypto_rsa_req(struct akcipher_requ= est *req, uint32_t opcode) return crypto_transfer_akcipher_request_to_engine(data_vq->engine, req); } =20 -static int virtio_crypto_rsa_encrypt(struct akcipher_request *req) +static int virtio_crypto_akcipher_encrypt(struct akcipher_request *req) { - return virtio_crypto_rsa_req(req, VIRTIO_CRYPTO_AKCIPHER_ENCRYPT); + return virtio_crypto_akcipher_req(req, VIRTIO_CRYPTO_AKCIPHER_ENCRYPT); } =20 -static int virtio_crypto_rsa_decrypt(struct akcipher_request *req) +static int virtio_crypto_akcipher_decrypt(struct akcipher_request *req) { - return virtio_crypto_rsa_req(req, VIRTIO_CRYPTO_AKCIPHER_DECRYPT); + return virtio_crypto_akcipher_req(req, VIRTIO_CRYPTO_AKCIPHER_DECRYPT); } =20 -static int virtio_crypto_rsa_sign(struct akcipher_request *req) +static int virtio_crypto_akcipher_sign(struct akcipher_request *req) { - return virtio_crypto_rsa_req(req, VIRTIO_CRYPTO_AKCIPHER_SIGN); + return virtio_crypto_akcipher_req(req, VIRTIO_CRYPTO_AKCIPHER_SIGN); } =20 -static int virtio_crypto_rsa_verify(struct akcipher_request *req) +static int virtio_crypto_akcipher_verify(struct akcipher_request *req) { - return virtio_crypto_rsa_req(req, VIRTIO_CRYPTO_AKCIPHER_VERIFY); + return virtio_crypto_akcipher_req(req, VIRTIO_CRYPTO_AKCIPHER_VERIFY); } =20 static int virtio_crypto_rsa_set_key(struct crypto_akcipher *tfm, @@ -484,18 +496,161 @@ static void virtio_crypto_rsa_exit_tfm(struct crypto= _akcipher *tfm) struct virtio_crypto_rsa_ctx *rsa_ctx =3D &ctx->rsa_ctx; =20 virtio_crypto_alg_akcipher_close_session(ctx); - virtcrypto_dev_put(ctx->vcrypto); + if (ctx->vcrypto) + virtcrypto_dev_put(ctx->vcrypto); mpi_free(rsa_ctx->n); rsa_ctx->n =3D NULL; } =20 +static int virtio_crypto_ecdsa_do_req(struct crypto_engine *engine, void *= vreq) +{ + return virtio_crypto_akcipher_do_req(engine, vreq, VIRTIO_CRYPTO_AKCIPHER= _ECDSA); +} + +static int virtio_crypto_ecdsa_set_key(struct crypto_akcipher *tfm, + const void *key, + unsigned int keylen, + bool private, + int curve_id) +{ + struct virtio_crypto_akcipher_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct virtio_crypto *vcrypto; + struct virtio_crypto_ctrl_header header; + struct virtio_crypto_akcipher_session_para para; + int node =3D virtio_crypto_get_current_node(); + uint32_t keytype; + + if (private) + keytype =3D VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE; + else + keytype =3D VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PUBLIC; + + if (!ctx->vcrypto) { + vcrypto =3D virtcrypto_get_dev_node(node, VIRTIO_CRYPTO_SERVICE_AKCIPHER, + VIRTIO_CRYPTO_AKCIPHER_RSA); + if (!vcrypto) { + pr_err("virtio_crypto: Could not find a virtio device in the system or = unsupported algo\n"); + return -ENODEV; + } + + ctx->vcrypto =3D vcrypto; + } else { + virtio_crypto_alg_akcipher_close_session(ctx); + } + + /* set ctrl header */ + header.opcode =3D cpu_to_le32(VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION); + header.algo =3D cpu_to_le32(VIRTIO_CRYPTO_AKCIPHER_ECDSA); + header.queue_id =3D 0; + + /* set ECDSA para */ + para.algo =3D cpu_to_le32(VIRTIO_CRYPTO_AKCIPHER_ECDSA); + para.keytype =3D cpu_to_le32(keytype); + para.keylen =3D cpu_to_le32(keylen); + para.u.ecdsa.curve_id =3D cpu_to_le32(curve_id); + + return virtio_crypto_alg_akcipher_init_session(ctx, &header, ¶, key, = keylen); +} + +static int virtio_crypto_ecdsa_nist_p192_set_pub_key(struct crypto_akciphe= r *tfm, + const void *key, + unsigned int keylen) +{ + return virtio_crypto_ecdsa_set_key(tfm, key, keylen, 0, VIRTIO_CRYPTO_CUR= VE_NIST_P192); +} + +static int virtio_crypto_ecdsa_nist_p192_set_priv_key(struct crypto_akciph= er *tfm, + const void *key, + unsigned int keylen) +{ + return virtio_crypto_ecdsa_set_key(tfm, key, keylen, 1, VIRTIO_CRYPTO_CUR= VE_NIST_P192); +} + +static int virtio_crypto_ecdsa_nist_p256_set_pub_key(struct crypto_akciphe= r *tfm, + const void *key, + unsigned int keylen) +{ + return virtio_crypto_ecdsa_set_key(tfm, key, keylen, 0, VIRTIO_CRYPTO_CUR= VE_NIST_P256); +} + +static int virtio_crypto_ecdsa_nist_p256_set_priv_key(struct crypto_akciph= er *tfm, + const void *key, + unsigned int keylen) +{ + return virtio_crypto_ecdsa_set_key(tfm, key, keylen, 1, VIRTIO_CRYPTO_CUR= VE_NIST_P256); +} + +static int virtio_crypto_ecdsa_nist_p384_set_pub_key(struct crypto_akciphe= r *tfm, + const void *key, + unsigned int keylen) +{ + return virtio_crypto_ecdsa_set_key(tfm, key, keylen, 0, VIRTIO_CRYPTO_CUR= VE_NIST_P384); +} + +static int virtio_crypto_ecdsa_nist_p384_set_priv_key(struct crypto_akciph= er *tfm, + const void *key, + unsigned int keylen) +{ + return virtio_crypto_ecdsa_set_key(tfm, key, keylen, 1, VIRTIO_CRYPTO_CUR= VE_NIST_P384); +} + +static unsigned int virtio_crypto_ecdsa_max_size(struct crypto_akcipher *t= fm) +{ + struct virtio_crypto_akcipher_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct virtio_crypto_ecdsa_ctx *ecdsa_ctx =3D &ctx->ecdsa_ctx; + + return ecdsa_max_signature_size(ecdsa_ctx->curve); +} + +static int virtio_crypto_ecdsa_init_tfm(struct crypto_akcipher *tfm, unsig= ned int curve_id) +{ + struct virtio_crypto_akcipher_ctx *ctx =3D akcipher_tfm_ctx(tfm); + + ctx->tfm =3D tfm; + ctx->enginectx.op.do_one_request =3D virtio_crypto_ecdsa_do_req; + ctx->enginectx.op.prepare_request =3D NULL; + ctx->enginectx.op.unprepare_request =3D NULL; + ctx->ecdsa_ctx.curve =3D ecc_get_curve(curve_id); + + if (!ctx->ecdsa_ctx.curve) + return -EINVAL; + + return 0; +} + +static int virtio_crypto_ecdsa_nist_p192_init_tfm(struct crypto_akcipher *= tfm) +{ + return virtio_crypto_ecdsa_init_tfm(tfm, ECC_CURVE_NIST_P192); +} + +static int virtio_crypto_ecdsa_nist_p256_init_tfm(struct crypto_akcipher *= tfm) +{ + return virtio_crypto_ecdsa_init_tfm(tfm, ECC_CURVE_NIST_P256); +} + +static int virtio_crypto_ecdsa_nist_p384_init_tfm(struct crypto_akcipher *= tfm) +{ + return virtio_crypto_ecdsa_init_tfm(tfm, ECC_CURVE_NIST_P384); +} + +static void virtio_crypto_ecdsa_exit_tfm(struct crypto_akcipher *tfm) +{ + struct virtio_crypto_akcipher_ctx *ctx =3D akcipher_tfm_ctx(tfm); + struct virtio_crypto_ecdsa_ctx *ecdsa_ctx =3D &ctx->ecdsa_ctx; + + virtio_crypto_alg_akcipher_close_session(ctx); + ecdsa_ctx->curve =3D NULL; + if (ctx->vcrypto) + virtcrypto_dev_put(ctx->vcrypto); +} + static struct virtio_crypto_akcipher_algo virtio_crypto_akcipher_algs[] = =3D { { .algonum =3D VIRTIO_CRYPTO_AKCIPHER_RSA, .service =3D VIRTIO_CRYPTO_SERVICE_AKCIPHER, .algo =3D { - .encrypt =3D virtio_crypto_rsa_encrypt, - .decrypt =3D virtio_crypto_rsa_decrypt, + .encrypt =3D virtio_crypto_akcipher_encrypt, + .decrypt =3D virtio_crypto_akcipher_decrypt, .set_pub_key =3D virtio_crypto_rsa_raw_set_pub_key, .set_priv_key =3D virtio_crypto_rsa_raw_set_priv_key, .max_size =3D virtio_crypto_rsa_max_size, @@ -515,10 +670,10 @@ static struct virtio_crypto_akcipher_algo virtio_cryp= to_akcipher_algs[] =3D { .algonum =3D VIRTIO_CRYPTO_AKCIPHER_RSA, .service =3D VIRTIO_CRYPTO_SERVICE_AKCIPHER, .algo =3D { - .encrypt =3D virtio_crypto_rsa_encrypt, - .decrypt =3D virtio_crypto_rsa_decrypt, - .sign =3D virtio_crypto_rsa_sign, - .verify =3D virtio_crypto_rsa_verify, + .encrypt =3D virtio_crypto_akcipher_encrypt, + .decrypt =3D virtio_crypto_akcipher_decrypt, + .sign =3D virtio_crypto_akcipher_sign, + .verify =3D virtio_crypto_akcipher_verify, .set_pub_key =3D virtio_crypto_p1pad_rsa_sha1_set_pub_key, .set_priv_key =3D virtio_crypto_p1pad_rsa_sha1_set_priv_key, .max_size =3D virtio_crypto_rsa_max_size, @@ -534,6 +689,70 @@ static struct virtio_crypto_akcipher_algo virtio_crypt= o_akcipher_algs[] =3D { }, }, }, + { + .algonum =3D VIRTIO_CRYPTO_AKCIPHER_ECDSA, + .service =3D VIRTIO_CRYPTO_SERVICE_AKCIPHER, + .algo =3D { + .sign =3D virtio_crypto_akcipher_sign, + .verify =3D virtio_crypto_akcipher_verify, + .set_pub_key =3D virtio_crypto_ecdsa_nist_p192_set_pub_key, + .set_priv_key =3D virtio_crypto_ecdsa_nist_p192_set_priv_key, + .max_size =3D virtio_crypto_ecdsa_max_size, + .init =3D virtio_crypto_ecdsa_nist_p192_init_tfm, + .exit =3D virtio_crypto_ecdsa_exit_tfm, + .reqsize =3D sizeof(struct virtio_crypto_akcipher_request), + .base =3D { + .cra_name =3D "ecdsa-nist-p192", + .cra_driver_name =3D "virtio-ecdsa-nist-p192", + .cra_priority =3D 150, + .cra_module =3D THIS_MODULE, + .cra_ctxsize =3D sizeof(struct virtio_crypto_akcipher_ctx), + }, + }, + }, + { + .algonum =3D VIRTIO_CRYPTO_AKCIPHER_ECDSA, + .service =3D VIRTIO_CRYPTO_SERVICE_AKCIPHER, + .algo =3D { + .sign =3D virtio_crypto_akcipher_sign, + .verify =3D virtio_crypto_akcipher_verify, + .set_pub_key =3D virtio_crypto_ecdsa_nist_p256_set_pub_key, + .set_priv_key =3D virtio_crypto_ecdsa_nist_p256_set_priv_key, + .max_size =3D virtio_crypto_ecdsa_max_size, + .init =3D virtio_crypto_ecdsa_nist_p256_init_tfm, + .exit =3D virtio_crypto_ecdsa_exit_tfm, + .reqsize =3D sizeof(struct virtio_crypto_akcipher_request), + .base =3D { + .cra_name =3D "ecdsa-nist-p256", + .cra_driver_name =3D "virtio-ecdsa-nist-p256", + .cra_priority =3D 150, + .cra_module =3D THIS_MODULE, + .cra_ctxsize =3D sizeof(struct virtio_crypto_akcipher_ctx), + }, + }, + }, + { + .algonum =3D VIRTIO_CRYPTO_AKCIPHER_ECDSA, + .service =3D VIRTIO_CRYPTO_SERVICE_AKCIPHER, + .algo =3D { + .sign =3D virtio_crypto_akcipher_sign, + .verify =3D virtio_crypto_akcipher_verify, + .set_pub_key =3D virtio_crypto_ecdsa_nist_p384_set_pub_key, + .set_priv_key =3D virtio_crypto_ecdsa_nist_p384_set_priv_key, + .max_size =3D virtio_crypto_ecdsa_max_size, + .init =3D virtio_crypto_ecdsa_nist_p384_init_tfm, + .exit =3D virtio_crypto_ecdsa_exit_tfm, + .reqsize =3D sizeof(struct virtio_crypto_akcipher_request), + .base =3D { + .cra_name =3D "ecdsa-nist-p384", + .cra_driver_name =3D "virtio-ecdsa-nist-p384", + .cra_priority =3D 150, + .cra_module =3D THIS_MODULE, + .cra_ctxsize =3D sizeof(struct virtio_crypto_akcipher_ctx), + }, + }, + + }, }; =20 int virtio_crypto_akcipher_algs_register(struct virtio_crypto *vcrypto) @@ -552,8 +771,7 @@ int virtio_crypto_akcipher_algs_register(struct virtio_= crypto *vcrypto) =20 if (virtio_crypto_akcipher_algs[i].active_devs =3D=3D 0) { ret =3D crypto_register_akcipher(&virtio_crypto_akcipher_algs[i].algo); - if (ret) - goto unlock; + continue; } =20 virtio_crypto_akcipher_algs[i].active_devs++; @@ -561,7 +779,6 @@ int virtio_crypto_akcipher_algs_register(struct virtio_= crypto *vcrypto) virtio_crypto_akcipher_algs[i].algo.base.cra_name); } =20 -unlock: mutex_unlock(&algs_lock); return ret; } --=20 2.20.1 From nobody Mon Apr 27 04:37:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 709A9C433EF for ; Fri, 17 Jun 2022 07:08:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380375AbiFQHIc (ORCPT ); Fri, 17 Jun 2022 03:08:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380395AbiFQHIY (ORCPT ); Fri, 17 Jun 2022 03:08:24 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 689286351E for ; Fri, 17 Jun 2022 00:08:22 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id k12-20020a17090a404c00b001eaabc1fe5dso3843317pjg.1 for ; Fri, 17 Jun 2022 00:08:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cApAEWtZBNz7UY2lzjb00JFgiaDz9EH6nqt1F0MvTwA=; b=dR9rWk3waDmeKxQcyL8H0k64uqciC8n0wtkRXIZxFhuK2nVsmOkbK6xOoiGhpHSJyw WLIkpsrdUUJVIV9bKUPgx3Qzq5YEPZOFTq1kJ1lGppP5YDCSiJoqzJzKw+TLrPCsMDGQ 1nQbKEVRuNmjys9xN1xWtJsfN6+ukvj3WxfLIg2rtYrdDH9Oppe37V68QYA4t2l6wlCi InL4SP1zVFATQHq/6qDpdv2z2UnzwsjSDIkjbFJYV82BxTnotaHH80gY4XgIg4jM06Zw EXVra94ehrosHdxx5zBJL3O3jOGfDi3rs8v3rrwvqEvEIGQ5vn8fT844DhQDqBiiBT5O 4/zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cApAEWtZBNz7UY2lzjb00JFgiaDz9EH6nqt1F0MvTwA=; b=ehX2Ge8xX41tTQ1Gg2yePJnqQ0wT+2H7Wx2Rk5QTMFzp/KJ5KiASq2ZIDSYoLWYsUC Wd3e70i8xY1+DIkk3NtxCcfqT1rANopiGF1upaZXHGOXxnz3VHLtsBKlr+NHpl24Eq+g dJlHyE58Zc1uYlSnoYvRJ8ZYrMVDoiOtafdKkKy352zuqB9cmk2napM9G6yV4RirsPCS jWgKMTrK0KP9j21MRpO8uPt2uf0xUubBGiW27+m1Z08KwKEpBc4QtfFEubdYB3JZCgDN ZV5X2RvPGZd3kHNPXTT15yikorTMufEFIWb5xXASLirVxeHXFY/zicK9CC2oypfMvAcT aV+A== X-Gm-Message-State: AJIora9vHfr0TKTZaNkeF7/AOFq4pl8h6V5zN0M0YoVU4HAE6vzNYmYF iO8fwuD9xTbvc3u4TBPFTP3TAg== X-Google-Smtp-Source: AGRyM1uc6BuGBJYpgcs6b3WTSw7pXBPAi/H5+9kHNGCgpTbVpq2ef8kHRnF44eQ6TeWExmA5Q8wz5w== X-Received: by 2002:a17:902:e751:b0:163:d8d9:8440 with SMTP id p17-20020a170902e75100b00163d8d98440mr8417293plf.12.1655449702093; Fri, 17 Jun 2022 00:08:22 -0700 (PDT) Received: from FVFDK26JP3YV.bytedance.net ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id j1-20020a170903028100b00163d4c3ffabsm2757868plr.304.2022.06.17.00.08.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jun 2022 00:08:21 -0700 (PDT) From: Lei He To: herbert@gondor.apana.org.au, davem@davemloft.net, dhowells@redhat.com, mst@redhat.com Cc: arei.gonglei@huawei.com, jasowang@redhat.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, pizhenwei@bytedance.com, helei.sig11@bytedance.com, f4bug@amsat.org, berrange@redhat.com Subject: [PATCH] crypto: testmgr - fix version number of RSA tests Date: Fri, 17 Jun 2022 15:07:51 +0800 Message-Id: <20220617070754.73667-3-helei.sig11@bytedance.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220617070754.73667-1-helei.sig11@bytedance.com> References: <20220617070754.73667-1-helei.sig11@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: lei he According to PKCS#1 standard, the 'otherPrimeInfos' field contains the information for the additional primes r_3, ..., r_u, in order. It shall be omitted if the version is 0 and shall contain at least one instance of OtherPrimeInfo if the version is 1, see: https://www.rfc-editor.org/rfc/rfc3447#page-44 Replace the version number '1' with 0, otherwise, some drivers may not pass the run-time tests. Signed-off-by: lei he Acked-by: Michael S. Tsirkin --- crypto/testmgr.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crypto/testmgr.h b/crypto/testmgr.h index 4d7449fc6a65..d57f24b906f1 100644 --- a/crypto/testmgr.h +++ b/crypto/testmgr.h @@ -186,7 +186,7 @@ static const struct akcipher_testvec rsa_tv_template[] = =3D { #ifndef CONFIG_CRYPTO_FIPS .key =3D "\x30\x81\x9A" /* sequence of 154 bytes */ - "\x02\x01\x01" /* version - integer of 1 byte */ + "\x02\x01\x00" /* version - integer of 1 byte */ "\x02\x41" /* modulus - integer of 65 bytes */ "\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F" "\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5" @@ -216,7 +216,7 @@ static const struct akcipher_testvec rsa_tv_template[] = =3D { }, { .key =3D "\x30\x82\x01\x1D" /* sequence of 285 bytes */ - "\x02\x01\x01" /* version - integer of 1 byte */ + "\x02\x01\x00" /* version - integer of 1 byte */ "\x02\x81\x81" /* modulus - integer of 129 bytes */ "\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71" "\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5" @@ -260,7 +260,7 @@ static const struct akcipher_testvec rsa_tv_template[] = =3D { #endif .key =3D "\x30\x82\x02\x20" /* sequence of 544 bytes */ - "\x02\x01\x01" /* version - integer of 1 byte */ + "\x02\x01\x00" /* version - integer of 1 byte */ "\x02\x82\x01\x01\x00" /* modulus - integer of 256 bytes */ "\xDB\x10\x1A\xC2\xA3\xF1\xDC\xFF\x13\x6B\xED\x44\xDF\xF0\x02\x6D" "\x13\xC7\x88\xDA\x70\x6B\x54\xF1\xE8\x27\xDC\xC3\x0F\x99\x6A\xFA" --=20 2.20.1