From patchwork Wed Jun 22 09:15:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lei He X-Patchwork-Id: 12890383 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36C29C43334 for ; Wed, 22 Jun 2022 09:19:10 +0000 (UTC) Received: from localhost ([::1]:48420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3wVx-0003Jx-4o for qemu-devel@archiver.kernel.org; Wed, 22 Jun 2022 05:19:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3wTX-0000WK-28 for qemu-devel@nongnu.org; Wed, 22 Jun 2022 05:16:40 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:40094) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o3wTU-0007MN-IP for qemu-devel@nongnu.org; Wed, 22 Jun 2022 05:16:38 -0400 Received: by mail-pj1-x102c.google.com with SMTP id g16-20020a17090a7d1000b001ea9f820449so16156395pjl.5 for ; Wed, 22 Jun 2022 02:16:35 -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=sBVor08NdXhCCzfIIm0IvMraTkqQ6DPScc7YYNMOwWo=; b=B5Y48Y0aqborH4GXIaN5ZDOBc+la5/OGOUT6HblP8+srAkxwO5oM9POU/P/Rcpx6PY r+jBqlk1GtkX+BpJ9U6AR8RZ3NbVFylOJbaw2iDXxTL1AhwTde7V6oWw1YR8iMs5AWVF ymSkrj+sdIVJwN/yC5p45m3q2U1yXJ4aiVpzeGGf2bvQIZ5o7EAhpiqLNGxlprr/5lBC LjkUUoJZj0jlD3r/N/3BQKKFNZe1N5ZznF4zP0pbeu0h2kdUtJc4SwaVWRQvjNjfeRSM MHqCw0UELk1fZGR0obqzOOpdstCw9qJ2ZDXmRxQzZDrIEBcwqam9M/5eor3bxXodf166 EDWQ== 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=sBVor08NdXhCCzfIIm0IvMraTkqQ6DPScc7YYNMOwWo=; b=IATfcIAnICth7HEBiqRu5E/InyWZYj9+m+cHxz/jrw/Po/n+CANM+mV9Pxbx1h+vjy dp4tDSrV8DleTn9Nknfub/lciafkXRgKTS6YYGHnmjYQWAQYQa4AQxxnsH/SWnn5k9aK qJYQD9DafngXhhqIbTFphwnvW2IUHiyxOJV4p5GwBBdQr9hVAJdEd2N29La/Q6yUH3uW VVahD0qtsZqYIUm6QPk6nyG26nD4EAg1hOceOUubJl6itjPajS4FSXjGuSOY6MjXXB2Z itizfsrpiDgdBpFqc60ErcPxexAw6DT9z3E1gv1lTsp2t0l7vy9VreyNRx5yaMhew9jw jgOQ== X-Gm-Message-State: AJIora/AhfaXWLAwCdjkWkz9IOv6SHdGFVG/bkbuBV2nMHXh5UtPw3v6 8dAcbazMqzTahl186kVDjIwDp7k6rQw6ug== X-Google-Smtp-Source: AGRyM1uphq5kUdKQ90jiFJFTTKh9hykqkd1whN5GRviyW2JylILkdBo3RK5IS5NIncMDifuzZxOXsg== X-Received: by 2002:a17:90a:17a6:b0:1ec:74e4:d7a3 with SMTP id q35-20020a17090a17a600b001ec74e4d7a3mr30218602pja.115.1655889394282; Wed, 22 Jun 2022 02:16:34 -0700 (PDT) Received: from FVFDK26JP3YV.bytedance.net ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id ja13-20020a170902efcd00b0016a087cfad8sm9833900plb.264.2022.06.22.02.16.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Jun 2022 02:16:33 -0700 (PDT) From: Lei He To: qemu-devel@nongnu.org, berrange@redhat.com, f4bug@amsat.org Cc: mst@redhat.com, pizhenwei@bytedance.com, jasowang@redhat.com, helei.sig11@bytedance.com Subject: [PATCH v2 7/7] crypto: Add test suite for ECDSA algorithm Date: Wed, 22 Jun 2022 17:15:49 +0800 Message-Id: <20220622091549.31115-8-helei.sig11@bytedance.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220622091549.31115-1-helei.sig11@bytedance.com> References: <20220622091549.31115-1-helei.sig11@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=helei.sig11@bytedance.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 1. add test suite for ecdsa algorithm. 2. use qcrypto_akcihper_max_xxx_len to help create buffers in Signed-off-by: lei he Reviewed-by: Daniel P. Berrangé --- tests/unit/test-crypto-akcipher.c | 338 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 323 insertions(+), 15 deletions(-) diff --git a/tests/unit/test-crypto-akcipher.c b/tests/unit/test-crypto-akcipher.c index 4f1f4214dd..414387cfb4 100644 --- a/tests/unit/test-crypto-akcipher.c +++ b/tests/unit/test-crypto-akcipher.c @@ -314,12 +314,117 @@ static const uint8_t rsa2048_public_key[] = { 0xed, 0x02, 0x03, 0x01, 0x00, 0x01 }; +static const uint8_t ecdsa_p192_public_key[] = { + 0x04, 0xc4, 0x16, 0xb3, 0xff, 0xac, 0xd5, 0x87, + 0x98, 0xf7, 0xd9, 0x45, 0xfe, 0xd3, 0x5c, 0x17, + 0x9d, 0xb2, 0x36, 0x22, 0xcc, 0x07, 0xb3, 0x6d, + 0x3c, 0x4e, 0x04, 0x5f, 0xeb, 0xb6, 0x52, 0x58, + 0xfb, 0x36, 0x10, 0x52, 0xb7, 0x01, 0x62, 0x0e, + 0x94, 0x51, 0x1d, 0xe2, 0xef, 0x10, 0x82, 0x88, + 0x78, +}; + +static const uint8_t ecdsa_p192_private_key[] = { + 0x30, 0x53, 0x02, 0x01, 0x01, 0x04, 0x18, 0xcb, + 0xc8, 0x86, 0x0e, 0x66, 0x3c, 0xf7, 0x5a, 0x44, + 0x13, 0xb8, 0xef, 0xea, 0x1d, 0x7b, 0xa6, 0x1c, + 0xda, 0xf4, 0x1b, 0xc7, 0x67, 0x6b, 0x35, 0xa1, + 0x34, 0x03, 0x32, 0x00, 0x04, 0xc4, 0x16, 0xb3, + 0xff, 0xac, 0xd5, 0x87, 0x98, 0xf7, 0xd9, 0x45, + 0xfe, 0xd3, 0x5c, 0x17, 0x9d, 0xb2, 0x36, 0x22, + 0xcc, 0x07, 0xb3, 0x6d, 0x3c, 0x4e, 0x04, 0x5f, + 0xeb, 0xb6, 0x52, 0x58, 0xfb, 0x36, 0x10, 0x52, + 0xb7, 0x01, 0x62, 0x0e, 0x94, 0x51, 0x1d, 0xe2, + 0xef, 0x10, 0x82, 0x88, 0x78, +}; + +static const uint8_t ecdsa_p256_private_key[] = { + 0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0xf6, + 0x92, 0xdd, 0x29, 0x1c, 0x6e, 0xef, 0xb6, 0xb2, + 0x73, 0x9f, 0x40, 0x1b, 0xb3, 0x2a, 0x28, 0xd2, + 0x37, 0xd6, 0x4a, 0x5b, 0xe4, 0x40, 0x4c, 0x6a, + 0x95, 0x99, 0xfa, 0xf7, 0x92, 0x49, 0xbe, 0xa0, + 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, + 0x03, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42, 0x00, + 0x04, 0xed, 0x42, 0x9c, 0x67, 0x79, 0xbe, 0x46, + 0x83, 0x88, 0x3e, 0x8c, 0xc1, 0x33, 0xf3, 0xc3, + 0xf6, 0x2c, 0xf3, 0x13, 0x6a, 0x00, 0xc2, 0xc9, + 0x3e, 0x87, 0x7f, 0x86, 0x39, 0xe6, 0xae, 0xe3, + 0xb9, 0xba, 0x2f, 0x58, 0x63, 0x32, 0x62, 0x62, + 0x54, 0x07, 0x27, 0xf9, 0x5a, 0x3a, 0xc7, 0x3a, + 0x6b, 0x5b, 0xbc, 0x0d, 0x33, 0xba, 0xbb, 0xd4, + 0xa3, 0xff, 0x4f, 0x9e, 0xdd, 0xf5, 0x59, 0xc0, + 0xf6, +}; + +static const uint8_t ecdsa_p256_public_key[] = { + 0x04, 0xed, 0x42, 0x9c, 0x67, 0x79, 0xbe, 0x46, + 0x83, 0x88, 0x3e, 0x8c, 0xc1, 0x33, 0xf3, 0xc3, + 0xf6, 0x2c, 0xf3, 0x13, 0x6a, 0x00, 0xc2, 0xc9, + 0x3e, 0x87, 0x7f, 0x86, 0x39, 0xe6, 0xae, 0xe3, + 0xb9, 0xba, 0x2f, 0x58, 0x63, 0x32, 0x62, 0x62, + 0x54, 0x07, 0x27, 0xf9, 0x5a, 0x3a, 0xc7, 0x3a, + 0x6b, 0x5b, 0xbc, 0x0d, 0x33, 0xba, 0xbb, 0xd4, + 0xa3, 0xff, 0x4f, 0x9e, 0xdd, 0xf5, 0x59, 0xc0, + 0xf6, +}; + +static const uint8_t ecdsa_p384_public_key[] = { + 0x04, 0xab, 0xd5, 0xf8, 0x87, 0x1d, 0x23, 0x9b, + 0x26, 0xb9, 0x57, 0x7e, 0x97, 0x78, 0x10, 0xcd, + 0x13, 0xe3, 0x98, 0x25, 0xa8, 0xd6, 0xab, 0x66, + 0x35, 0x26, 0x68, 0x8a, 0x0e, 0x49, 0xd9, 0x4a, + 0x91, 0x7d, 0x6c, 0x94, 0x06, 0x06, 0x99, 0xf1, + 0x8d, 0x2a, 0x25, 0x8d, 0xf9, 0xbf, 0x40, 0xfa, + 0xb7, 0xcb, 0xe1, 0x14, 0x22, 0x0a, 0xa7, 0xfb, + 0x0a, 0xb4, 0x02, 0x05, 0x8b, 0x98, 0xaa, 0x78, + 0xcd, 0x53, 0x00, 0x1e, 0xd1, 0x79, 0x6a, 0x5f, + 0x09, 0x01, 0x88, 0xb4, 0xbc, 0x32, 0x62, 0x83, + 0x92, 0x84, 0x2d, 0xc6, 0xf8, 0xda, 0xc4, 0x7f, + 0x10, 0xa3, 0x18, 0x1d, 0xae, 0x0d, 0xa4, 0x41, + 0x9f, +}; + +static const uint8_t ecdsa_p384_private_key[] = { + 0x30, 0x81, 0x9b, 0x02, 0x01, 0x01, 0x04, 0x30, + 0xb6, 0x04, 0xef, 0xb1, 0x2c, 0x98, 0xdf, 0xcf, + 0xd4, 0x16, 0x31, 0xd4, 0x69, 0x0c, 0x27, 0x81, + 0x4a, 0xac, 0x1a, 0x83, 0x3c, 0xe4, 0xef, 0x65, + 0xe1, 0x7a, 0x6a, 0xc6, 0xd6, 0xf7, 0xea, 0x79, + 0xbe, 0xf1, 0x00, 0x3c, 0xdf, 0x6e, 0x9d, 0x10, + 0x22, 0x61, 0x1b, 0x11, 0xcf, 0x49, 0x6e, 0x62, + 0xa1, 0x64, 0x03, 0x62, 0x00, 0x04, 0xab, 0xd5, + 0xf8, 0x87, 0x1d, 0x23, 0x9b, 0x26, 0xb9, 0x57, + 0x7e, 0x97, 0x78, 0x10, 0xcd, 0x13, 0xe3, 0x98, + 0x25, 0xa8, 0xd6, 0xab, 0x66, 0x35, 0x26, 0x68, + 0x8a, 0x0e, 0x49, 0xd9, 0x4a, 0x91, 0x7d, 0x6c, + 0x94, 0x06, 0x06, 0x99, 0xf1, 0x8d, 0x2a, 0x25, + 0x8d, 0xf9, 0xbf, 0x40, 0xfa, 0xb7, 0xcb, 0xe1, + 0x14, 0x22, 0x0a, 0xa7, 0xfb, 0x0a, 0xb4, 0x02, + 0x05, 0x8b, 0x98, 0xaa, 0x78, 0xcd, 0x53, 0x00, + 0x1e, 0xd1, 0x79, 0x6a, 0x5f, 0x09, 0x01, 0x88, + 0xb4, 0xbc, 0x32, 0x62, 0x83, 0x92, 0x84, 0x2d, + 0xc6, 0xf8, 0xda, 0xc4, 0x7f, 0x10, 0xa3, 0x18, + 0x1d, 0xae, 0x0d, 0xa4, 0x41, 0x9f, +}; + static const uint8_t test_sha1_dgst[] = { 0x3c, 0x05, 0x19, 0x34, 0x29, 0x19, 0xc7, 0xe0, 0x87, 0xb6, 0x24, 0xf9, 0x58, 0xac, 0xa4, 0xd4, 0xb2, 0xd9, 0x03, 0x9e, }; +static const uint8_t test_sha512_dgst[] = { + 0x8b, 0x79, 0xc0, 0x3c, 0xcb, 0x15, 0x26, 0x51, + 0x50, 0xca, 0xb1, 0xa7, 0xf3, 0xf6, 0x1e, 0x0a, + 0xbb, 0x39, 0x7c, 0x97, 0x7f, 0xad, 0x9e, 0x51, + 0xb4, 0xa0, 0xb0, 0xd8, 0xd6, 0xb9, 0xd8, 0x81, + 0xac, 0x8a, 0xb3, 0x30, 0x07, 0xea, 0x6e, 0x63, + 0x2f, 0xda, 0x8f, 0x2c, 0x4b, 0xa0, 0xee, 0x9a, + 0xda, 0x32, 0x2d, 0x6c, 0xb1, 0x8b, 0xe2, 0xd8, + 0x79, 0x48, 0xd4, 0xf9, 0xb1, 0xfa, 0xf1, 0xa2, +}; + static const uint8_t exp_signature_rsa2048_pkcs1[] = { 0x4e, 0x82, 0x56, 0x4c, 0x84, 0x66, 0xca, 0x1e, 0xc6, 0x92, 0x46, 0x20, 0x02, 0x6b, 0x64, 0x46, @@ -374,6 +479,82 @@ static const uint8_t exp_signature_rsa1024_pkcs1[] = { 0xab, 0x0d, 0xc6, 0x59, 0x1d, 0xc7, 0x33, 0x7b, }; +static const uint8_t exp_signature_ecdsa_p192[] = { + 0x30, 0x35, 0x02, 0x19, 0x00, 0xba, 0xf7, 0xc0, + 0xc1, 0x7e, 0xf5, 0x69, 0xd5, 0xb7, 0x5d, 0x06, + 0xcb, 0x92, 0x28, 0x57, 0x52, 0x96, 0x9a, 0xdc, + 0xc9, 0xf9, 0xd5, 0x2c, 0x51, 0x02, 0x18, 0x26, + 0x21, 0x5d, 0x16, 0xba, 0xff, 0x19, 0x74, 0x56, + 0x8e, 0xdf, 0x51, 0x2b, 0x2c, 0xce, 0xc2, 0x7b, + 0x5b, 0x03, 0x10, 0x56, 0x57, 0x63, 0x47, +}; + +static const uint8_t exp_signature_ecdsa_p192_sha512[] = { + 0x30, 0x35, 0x02, 0x19, 0x00, 0xbb, 0x03, 0x61, + 0x98, 0x28, 0xb3, 0x02, 0xca, 0x61, 0x08, 0xce, + 0x98, 0xfd, 0x57, 0x6e, 0x60, 0xfa, 0xa0, 0x06, + 0x03, 0xe2, 0xb2, 0x07, 0x22, 0x02, 0x18, 0x26, + 0xdc, 0x17, 0x3b, 0xf1, 0x88, 0x0a, 0x2c, 0xd5, + 0x51, 0x23, 0xbc, 0x83, 0x54, 0x05, 0x77, 0x28, + 0xd5, 0x84, 0xdf, 0x16, 0x4f, 0x50, 0x20, +}; + +static const uint8_t exp_signature_ecdsa_p256[] = { + 0x30, 0x45, 0x02, 0x21, 0x00, 0xac, 0x09, 0xf3, + 0x32, 0xb6, 0xf6, 0x7e, 0x12, 0x4f, 0x68, 0xdb, + 0x10, 0x14, 0x61, 0xf6, 0x29, 0xbd, 0xdd, 0x72, + 0x9f, 0x81, 0xf8, 0x83, 0x8a, 0xf3, 0x29, 0x87, + 0x7b, 0xbb, 0xcf, 0xea, 0x64, 0x02, 0x20, 0x14, + 0xfc, 0x2e, 0x2f, 0x3e, 0x06, 0xb1, 0xd0, 0xbb, + 0x91, 0x44, 0xd5, 0x53, 0xb4, 0x72, 0xa1, 0x83, + 0xc7, 0x3a, 0xa8, 0xfc, 0x43, 0x1b, 0x2e, 0xbb, + 0xb0, 0xe9, 0xef, 0x0b, 0x03, 0x32, 0x74, +}; + +static const uint8_t exp_signature_ecdsa_p256_sha512[] = { + 0x30, 0x46, 0x02, 0x21, 0x00, 0xe0, 0x48, 0x74, + 0x65, 0xaa, 0x63, 0x97, 0x68, 0x45, 0x68, 0xfa, + 0xec, 0x51, 0x64, 0xfe, 0x09, 0xc7, 0x5c, 0x65, + 0x5d, 0x93, 0x04, 0x17, 0x23, 0xbe, 0x1b, 0x2f, + 0x89, 0x5e, 0x02, 0xcd, 0x55, 0x02, 0x21, 0x00, + 0xe9, 0x24, 0xbd, 0x7a, 0xbd, 0x05, 0x89, 0x04, + 0x92, 0x2d, 0x67, 0x8d, 0x66, 0xa8, 0x9d, 0x7b, + 0xb1, 0x5b, 0xae, 0xd1, 0xd4, 0x7b, 0xe8, 0x72, + 0xe9, 0xd9, 0x45, 0xfd, 0xd3, 0x76, 0xbe, 0xfb, +}; + +static const uint8_t exp_signature_ecdsa_p384[] = { + 0x30, 0x64, 0x02, 0x30, 0x3c, 0x79, 0x7f, 0x5a, + 0x91, 0x08, 0x79, 0xde, 0x6e, 0x03, 0x19, 0x39, + 0xcb, 0x94, 0x9c, 0xc6, 0x09, 0x12, 0xfa, 0xbd, + 0xa8, 0x35, 0x5e, 0x3f, 0x74, 0x05, 0x12, 0xd1, + 0x8e, 0xd9, 0x3c, 0x79, 0x9d, 0x7c, 0x1a, 0xae, + 0x96, 0x05, 0x0e, 0x35, 0x21, 0x73, 0xd8, 0xfe, + 0x1b, 0x43, 0x06, 0xb9, 0x02, 0x30, 0x11, 0xdf, + 0xa7, 0xba, 0x70, 0x84, 0x4b, 0x74, 0xab, 0x1e, + 0x9e, 0x6a, 0xc1, 0x46, 0xe3, 0x98, 0x0a, 0x25, + 0x82, 0xf5, 0xff, 0xb5, 0x6f, 0x04, 0xda, 0xc3, + 0xfd, 0x3e, 0xea, 0x96, 0x03, 0x0c, 0x22, 0xf2, + 0xda, 0x86, 0xeb, 0x91, 0x2f, 0x36, 0x13, 0xba, + 0x37, 0xcd, 0xe7, 0x91, 0x85, 0xf3, +}; + +static const uint8_t exp_signature_ecdsa_p384_sha512[] = { + 0x30, 0x64, 0x02, 0x30, 0x04, 0xa2, 0x3e, 0xb0, + 0xc0, 0x1f, 0xa0, 0xbb, 0x19, 0x60, 0x56, 0x04, + 0x11, 0x95, 0xa9, 0x34, 0x0d, 0x0a, 0x80, 0x7f, + 0x5b, 0x08, 0xb3, 0xf9, 0x33, 0xc2, 0xd4, 0x6d, + 0x23, 0x0a, 0xed, 0x29, 0xca, 0x93, 0xba, 0x8c, + 0xee, 0xbf, 0x2d, 0xb8, 0x45, 0xda, 0xaf, 0x2f, + 0x2e, 0x5b, 0xda, 0x62, 0x02, 0x30, 0x2e, 0x6f, + 0xa4, 0x24, 0xf7, 0xcf, 0x58, 0xc3, 0xca, 0x29, + 0xd8, 0x0b, 0xe7, 0xb5, 0x88, 0xeb, 0x81, 0xbe, + 0x50, 0x2a, 0xd3, 0x37, 0xeb, 0x23, 0xcc, 0x55, + 0x6f, 0xf5, 0x02, 0xb9, 0xf9, 0xa1, 0x58, 0x2a, + 0x35, 0x00, 0xe9, 0x2f, 0xc8, 0x73, 0x5c, 0x27, + 0xbc, 0x4b, 0x8c, 0x0e, 0x4d, 0xde, +}; + static const uint8_t test_plaintext[] = { 0x00, 0x44, 0xbc, 0x6f, 0x77, 0xfb, 0xe2, 0xa4, 0x98, 0x9e, 0xf5, 0x33, 0xa0, 0xbd, 0x81, 0xb9, @@ -870,7 +1051,114 @@ static QCryptoAkCipherTestData akcipher_test_data[] = { .signature = exp_signature_rsa2048_pkcs1, .slen = sizeof(exp_signature_rsa2048_pkcs1), }, + { + .path = "/crypto/akcipher/ecdsa-nist-p192-with-sha1", + .opt = { + .alg = QCRYPTO_AKCIPHER_ALG_ECDSA, + .u.ecdsa = { + .curve_id = QCRYPTO_CURVE_ID_NIST_P192, + }, + }, + .pub_key = ecdsa_p192_public_key, + .pub_key_len = sizeof(ecdsa_p192_public_key), + .priv_key = ecdsa_p192_private_key, + .priv_key_len = sizeof(ecdsa_p192_private_key), + + .dgst = test_sha1_dgst, + .dlen = sizeof(test_sha1_dgst), + .signature = exp_signature_ecdsa_p192, + .slen = sizeof(exp_signature_ecdsa_p192), + }, + { + .path = "/crypto/akcipher/ecdsa-nist-p192-with-sha512", + .opt = { + .alg = QCRYPTO_AKCIPHER_ALG_ECDSA, + .u.ecdsa = { + .curve_id = QCRYPTO_CURVE_ID_NIST_P192, + }, + }, + .pub_key = ecdsa_p192_public_key, + .pub_key_len = sizeof(ecdsa_p192_public_key), + .priv_key = ecdsa_p192_private_key, + .priv_key_len = sizeof(ecdsa_p192_private_key), + + .dgst = test_sha512_dgst, + .dlen = sizeof(test_sha512_dgst), + .signature = exp_signature_ecdsa_p192_sha512, + .slen = sizeof(exp_signature_ecdsa_p192_sha512), + }, + { + .path = "/crypto/akcipher/ecdsa-nist-p256-with-sha1", + .opt = { + .alg = QCRYPTO_AKCIPHER_ALG_ECDSA, + .u.ecdsa = { + .curve_id = QCRYPTO_CURVE_ID_NIST_P256, + }, + }, + .pub_key = ecdsa_p256_public_key, + .pub_key_len = sizeof(ecdsa_p256_public_key), + .priv_key = ecdsa_p256_private_key, + .priv_key_len = sizeof(ecdsa_p256_private_key), + .dgst = test_sha1_dgst, + .dlen = sizeof(test_sha1_dgst), + .signature = exp_signature_ecdsa_p256, + .slen = sizeof(exp_signature_ecdsa_p256), + }, + { + .path = "/crypto/akcipher/ecdsa-nist-p256-with-sha512", + .opt = { + .alg = QCRYPTO_AKCIPHER_ALG_ECDSA, + .u.ecdsa = { + .curve_id = QCRYPTO_CURVE_ID_NIST_P256, + }, + }, + .pub_key = ecdsa_p256_public_key, + .pub_key_len = sizeof(ecdsa_p256_public_key), + .priv_key = ecdsa_p256_private_key, + .priv_key_len = sizeof(ecdsa_p256_private_key), + + .dgst = test_sha512_dgst, + .dlen = sizeof(test_sha512_dgst), + .signature = exp_signature_ecdsa_p256_sha512, + .slen = sizeof(exp_signature_ecdsa_p256_sha512), + }, + { + .path = "/crypto/akcipher/ecdsa-nist-p384-with-sha1", + .opt = { + .alg = QCRYPTO_AKCIPHER_ALG_ECDSA, + .u.ecdsa = { + .curve_id = QCRYPTO_CURVE_ID_NIST_P384, + }, + }, + .pub_key = ecdsa_p384_public_key, + .pub_key_len = sizeof(ecdsa_p384_public_key), + .priv_key = ecdsa_p384_private_key, + .priv_key_len = sizeof(ecdsa_p384_private_key), + + .dgst = test_sha1_dgst, + .dlen = sizeof(test_sha1_dgst), + .signature = exp_signature_ecdsa_p384, + .slen = sizeof(exp_signature_ecdsa_p384), + }, + { + .path = "/crypto/akcipher/ecdsa-nist-p384-with-sha512", + .opt = { + .alg = QCRYPTO_AKCIPHER_ALG_ECDSA, + .u.ecdsa = { + .curve_id = QCRYPTO_CURVE_ID_NIST_P384, + }, + }, + .pub_key = ecdsa_p384_public_key, + .pub_key_len = sizeof(ecdsa_p384_public_key), + .priv_key = ecdsa_p384_private_key, + .priv_key_len = sizeof(ecdsa_p384_private_key), + + .dgst = test_sha512_dgst, + .dlen = sizeof(test_sha512_dgst), + .signature = exp_signature_ecdsa_p384_sha512, + .slen = sizeof(exp_signature_ecdsa_p384_sha512), + }, }; static void test_akcipher(const void *opaque) @@ -879,6 +1167,8 @@ static void test_akcipher(const void *opaque) g_autofree uint8_t *plaintext = NULL; g_autofree uint8_t *ciphertext = NULL; g_autofree uint8_t *signature = NULL; + int signature_len, ciphertext_len, plaintext_len; + int max_plen, max_slen, max_clen; QCryptoAkCipher *pub_key, *priv_key; if (!qcrypto_akcipher_supports((QCryptoAkCipherOptions *)&data->opt)) { @@ -894,32 +1184,41 @@ static void test_akcipher(const void *opaque) data->priv_key, data->priv_key_len, &error_abort); g_assert(priv_key != NULL); + max_plen = qcrypto_akcipher_max_plaintext_len(pub_key); + max_clen = qcrypto_akcipher_max_plaintext_len(pub_key); + max_slen = qcrypto_akcipher_max_signature_len(priv_key); if (data->plaintext != NULL) { - ciphertext = g_new0(uint8_t, data->clen); - g_assert(qcrypto_akcipher_encrypt(pub_key, data->plaintext, data->plen, - ciphertext, data->clen, - &error_abort) > 0); + ciphertext = g_new0(uint8_t, max_clen); + ciphertext_len = qcrypto_akcipher_encrypt(pub_key, + data->plaintext, data->plen, + ciphertext, max_clen, + &error_abort); + g_assert(ciphertext_len > 0); /** * In the asymmetric encryption algorithms, the ciphertext generated * each time may be different, here only compare the decrypted * plaintext */ - plaintext = g_new0(uint8_t, data->clen); - g_assert(qcrypto_akcipher_decrypt(priv_key, ciphertext, - data->clen, plaintext, - data->plen, - &error_abort) == data->plen); + plaintext = g_new0(uint8_t, max_plen); + plaintext_len = qcrypto_akcipher_decrypt(priv_key, + ciphertext, ciphertext_len, + plaintext, max_plen, + &error_abort); + g_assert(plaintext_len == data->plen); g_assert(!memcmp(plaintext, data->plaintext, data->plen)); } if (data->signature != NULL) { - signature = g_new(uint8_t, data->slen); - g_assert(qcrypto_akcipher_sign(priv_key, data->dgst, data->dlen, - signature, data->slen, - &error_abort) > 0); + signature = g_new(uint8_t, max_slen); + signature_len = qcrypto_akcipher_sign(priv_key, + data->dgst, data->dlen, + signature, max_slen, + &error_abort); + g_assert(signature_len > 0); + /** * The signature generated each time may be different, here only check * the verification. @@ -927,12 +1226,21 @@ static void test_akcipher(const void *opaque) g_assert(qcrypto_akcipher_verify(pub_key, data->signature, data->slen, data->dgst, data->dlen, &error_abort) == 0); - g_assert(qcrypto_akcipher_verify(pub_key, signature, data->slen, + g_assert(qcrypto_akcipher_verify(pub_key, signature, signature_len, + data->dgst, data->dlen, + &error_abort) == 0); + + g_assert(qcrypto_akcipher_verify(priv_key, data->signature, data->slen, + data->dgst, data->dlen, + &error_abort) == 0); + g_assert(qcrypto_akcipher_verify(priv_key, signature, signature_len, data->dgst, data->dlen, &error_abort) == 0); ++signature[0]; /* Here error should be ignored */ - g_assert(qcrypto_akcipher_verify(pub_key, signature, data->slen, + g_assert(qcrypto_akcipher_verify(pub_key, signature, signature_len, + data->dgst, data->dlen, NULL) != 0); + g_assert(qcrypto_akcipher_verify(priv_key, signature, signature_len, data->dgst, data->dlen, NULL) != 0); }