From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D96EC12002 for ; Wed, 14 Jul 2021 22:07:25 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8FC9A613A9 for ; Wed, 14 Jul 2021 22:07:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FC9A613A9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8F94A80214; Thu, 15 Jul 2021 00:07:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XUQXlV6W"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 928DD829E7; Thu, 15 Jul 2021 00:06:15 +0200 (CEST) Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E3103829B7 for ; Thu, 15 Jul 2021 00:06:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mr.nuke.me@gmail.com Received: by mail-ot1-x335.google.com with SMTP id o72-20020a9d224e0000b02904bb9756274cso4110669ota.6 for ; Wed, 14 Jul 2021 15:06:04 -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=vQ6qRuz65FqaOThpOomG4ummFJamKbuoXhPgSb2goPs=; b=XUQXlV6WUjRdrXOfhOXyDvr7xQZehLsgELk1B0ldJmwpuEUl/ZWNzeJyd5LsDBl/iR 4yMsePZ058YstdDadOiVy5djvgsDzdXBAYlipPnsI43naTNR5809EI4+w8c+QyDK91l0 lz4t7lp+LQ8NInBZbAgWedKfP9z14uhV5fi4iJsgvlF5ojmgllN38UcO0vqNGnLbSP7M bttdp1Vp7Z+kpEY/m1iul4kib1j+wnwS8s9EbedM3Sjn2vFp6IoGEFRmYehqDZ1lt51q meyjh4zoR7yejTeRq3bHre4tv+eum2hUSXg/iSo4AYjvVoEg6jF1KtRJChUXmNAUFnRV QjZA== 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=vQ6qRuz65FqaOThpOomG4ummFJamKbuoXhPgSb2goPs=; b=jdFG+cYoe7PbI7eNp1HUyatT2Nf4vIUHffAJD448H31vb+fKoSJL6NC4Q33ksn9nm+ RZqnP1thdKzo7jpatBmwIy/Wqd7HlObevc0+6qY4+A1w6qARL2ovesfnlHacUX8oBscT n9cunb5qE8qxvG2cVrHeiPOeK1Lvzfmyp2wcYjOphR9eiT8BAD7OrEc9cSvz9wAJxbk6 +MIK7DbHoyLcj15hppoz5Zr1Jax0jJ/hvVaJ80FJsgb2u12KStrmXQUVtHwk5JyNVIWI 3SMNXXuQA5SEXjH3+HlMTKtUZZtlStOMSBttVDAVlgrmByoB5i60XItihsYvBZgzM0YD DwbQ== X-Gm-Message-State: AOAM532q23UzQqmcRGCTyOEzvT2zea4fGxaPA67zBYNHedFUXnRKo/hw 3svsYiNY4/jJ9tHdrnBUWqoz0xRX3ck= X-Google-Smtp-Source: ABdhPJxrmqGMVskqSdaai99FVY4Hp9tnKI9l7gU53guEs6UMx23VLzrpBt87CSM34p9MORWP9IWmQg== X-Received: by 2002:a9d:8c7:: with SMTP id 65mr287396otf.25.1626300363195; Wed, 14 Jul 2021 15:06:03 -0700 (PDT) Received: from nuclearis3.lan (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id w64sm687278otb.45.2021.07.14.15.06.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 15:06:02 -0700 (PDT) From: Alexandru Gagniuc To: u-boot@lists.denx.de, trini@konsulko.com Cc: Alexandru Gagniuc , Simon Glass Subject: [PATCH v3 12/19] image: rsa: Move verification algorithm to a linker list Date: Wed, 14 Jul 2021 17:05:40 -0500 Message-Id: <20210714220547.170371-13-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210714211138.GA25256@bill-the-cat> References: <20210714211138.GA25256@bill-the-cat> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Move the RSA verification crytpo_algo structure out of the crypto_algos array, and into a linker list. Although it appears we are adding an #ifdef to rsa-verify.c, the gains outweigh this small inconvenience. This is because rsa_verify() is defined differently based on #ifdefs. This change allows us to have a single definition of rsa_verify(). Signed-off-by: Alexandru Gagniuc Reviewed-by: Simon Glass --- common/image-sig.c | 9 --------- lib/rsa/rsa-verify.c | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/common/image-sig.c b/common/image-sig.c index 81a3b739fe..d996b7ba50 100644 --- a/common/image-sig.c +++ b/common/image-sig.c @@ -53,15 +53,6 @@ struct checksum_algo checksum_algos[] = { struct crypto_algo crypto_algos[] = { { - .name = "rsa2048", - .key_len = RSA2048_BYTES, - .verify = rsa_verify, - }, - { - .name = "rsa4096", - .key_len = RSA4096_BYTES, - .verify = rsa_verify, - }, }; struct padding_algo padding_algos[] = { diff --git a/lib/rsa/rsa-verify.c b/lib/rsa/rsa-verify.c index 1998c773fc..bb8cc61d94 100644 --- a/lib/rsa/rsa-verify.c +++ b/lib/rsa/rsa-verify.c @@ -571,3 +571,19 @@ int rsa_verify(struct image_sign_info *info, return rsa_verify_hash(info, hash, sig, sig_len); } + +#ifndef USE_HOSTCC + +U_BOOT_CRYPTO_ALGO(rsa2048) = { + .name = "rsa2048", + .key_len = RSA2048_BYTES, + .verify = rsa_verify, +}; + +U_BOOT_CRYPTO_ALGO(rsa4096) = { + .name = "rsa4096", + .key_len = RSA4096_BYTES, + .verify = rsa_verify, +}; + +#endif -- 2.31.1