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.8 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,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 C86CDC2B9F7 for ; Mon, 24 May 2021 20:21:56 +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 086B7613E6 for ; Mon, 24 May 2021 20:21:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 086B7613E6 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 C092D82F0F; Mon, 24 May 2021 22:20:30 +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="vFGbyRh2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9497082EB5; Mon, 24 May 2021 22:19:56 +0200 (CEST) Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) (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 52DE582EDB for ; Mon, 24 May 2021 22:19:52 +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-x329.google.com with SMTP id 80-20020a9d08560000b0290333e9d2b247so15871900oty.7 for ; Mon, 24 May 2021 13:19:52 -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=vFGbyRh2+9gr9KLpdFMskNTQRacnH47CfhkaX0ZWXZc3+6Q7bh+2ja1m3KtiBxjTm0 SxfsGudqxSlIWprgowGTgf2ADscD6YAA4omLMHW0/ADG4dsut9I70nfxmkZza6qV8Tif BJBxDwglHR5CWGP+Mg29PzKcqUpvmYXnGfrTjderavJo50YzOyh5lesLri8GaGT3sVnu 8QlDB+nPaDn4yxZFI644cUkLfd5Y8C3Hq/qEDqPdqNbB3J81GSyw8iCta8kLNcYxwngc /kfy+0REwTpOs/Iq5RxbHGlF+Q3iYUPYVRjxMIubcixAskLHQPIdvl0TgSrVfENjeDq7 AWmQ== 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=bAaUwci/M65gdyiKfyoM7pq7YGZ55gCHt6A/hGBzr1PgmWzx35i85xiNi80IFyprkr yV/d3okwYk4NIvXQD7ru2EvMgtDjaXG9okZdEUqPH5VBO9FpxQHEWe8tu1hfmd14D18H Ag+/8nKtggxM8M9s2D6Xntk4/soAwOTFyXkwsdohD6jP4+LmZbYisAxSAUYDI6vNJEot 4m0NVmQzWKpBBYIdguzCIsk2OFfHgB2YwSr3UmR1XosmxbmEBP7Q6N4xm2PnOjLUgFZB nHyI9F6r1cWM6/EK1FYVZZZZjvYHlqor/0gOt1bQvpTTHZaZ9v5DWnLau5O1xJkM6hC4 EySA== X-Gm-Message-State: AOAM533Urc9Si1M3855k/E5m0APnftHs4sVKWkCLmQre3ruythwy/AxJ GY5Gt7c9oIal+wViJ/9cWmMIrTXHzPgFjg== X-Google-Smtp-Source: ABdhPJym1Tjlb69XpYKe+PcsELZVd17R4a+pbAnPYj7ZWi+XRh8jE2yl9Aso17MveHWuZM8uGSnKjA== X-Received: by 2002:a9d:7286:: with SMTP id t6mr10476727otj.278.1621887590774; Mon, 24 May 2021 13:19:50 -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 w13sm2816338otp.10.2021.05.24.13.19.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 13:19:50 -0700 (PDT) From: Alexandru Gagniuc To: u-boot@lists.denx.de, sjg@chromium.org Cc: Alexandru Gagniuc , trini@konsulko.com, michal.simek@xilinx.com, rasmus.villemoes@prevas.dk Subject: [PATCH v2 12/18] image: rsa: Move verification algorithm to a linker list Date: Mon, 24 May 2021 15:19:33 -0500 Message-Id: <20210524201939.1491676-13-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524201939.1491676-1-mr.nuke.me@gmail.com> References: <20210524201939.1491676-1-mr.nuke.me@gmail.com> 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.102.4 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