From patchwork Fri May 14 19:45:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Gagniuc X-Patchwork-Id: 1478667 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=QRvfIYck; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FhfDW6dd6z9sWX for ; Sat, 15 May 2021 05:46:51 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 85FDE82B48; Fri, 14 May 2021 21:46:40 +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="QRvfIYck"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8DC5682B48; Fri, 14 May 2021 21:46:17 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) (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 13BD082AE1 for ; Fri, 14 May 2021 21:46:09 +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-oo1-xc2f.google.com with SMTP id l25-20020a4a35190000b029020a54735152so121412ooa.4 for ; Fri, 14 May 2021 12:46:09 -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=ihV6kjyordNC+afmdqz3gH6BlCCw3B2/UCJOkIqwtF8=; b=QRvfIYcksMjKYNBfwKaeJMJGqBRFYuWW6baKlMb14jAHQSv2CKCPRC1rihRf7K7BpI dVqmfpWrRqBLPAH0JvLCN8FtWAST7uzsm7tQc5c+R5BgXTfUPEI8+N5fceYAQ7ZRETS2 QEHivVQ1DvW84HT5/sC9BZXTO0m0whHtSYDQEj+OgrkQuCjv3xvRNW/3W5VQcWDpe9gO 8Q7XC6bd1cBfHbsRsgpFyFlfp4SnhXDUXyEotyfSlxoynF3k4lAlglbVs5sQTZJ1E3TO YJlgVZSbQ/j1sTKUywj0H8NZLVLgEne3+13L5V8NWiVfzNjk/O/I9Y4xElDk1ZTNXJEH C9FA== 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=ihV6kjyordNC+afmdqz3gH6BlCCw3B2/UCJOkIqwtF8=; b=ec0cfRrhVng0+8iF2ICNgEb39nGQZyF1MYoWLvvgga8k+CaKjX2KdpVQ7taE3Lw7l2 ZolPnLblajpFzrSkOAvafkuL3BHxMYZrkNagKd2zci37sy6gjPnxLunNKVkerx8ptTKi Bv7J6Ea7JSfYL3lzgF/JHYqAxXZ5bG+ZMdrmFIYXqFoYIiilH/NcvzjRoZ9Ps0IHNdMX rtqQcYK4/4kgAYTm7SJJpkrqg2kcnT5x/72MklY7rWE4G80k254fFMGcI6vY3n7GFl2G iZFnA1HSPHTWRMImJX3N/k23dVKFxR1DADcg0eWzodpca6zjXBZ8Q1BaaBpfDzJJcJ/f LAjw== X-Gm-Message-State: AOAM530+2CogReLuMWGM3Ust/Ga9CkaExWIVc4+Y+5w0ZelC1rTC8TYY wl/y4k/l5hCnxm9mt50cqI9ZkY4/4XrSXw== X-Google-Smtp-Source: ABdhPJxS9YJ6dFhGJ04ZgBXie20oLBowTbFboRqT3PYF5c7rz4pzKhcuc9li4078vm+369pf2bgUfQ== X-Received: by 2002:a4a:cb95:: with SMTP id y21mr23930352ooq.68.1621021567670; Fri, 14 May 2021 12:46:07 -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 c131sm1015353oif.29.2021.05.14.12.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 12:46:07 -0700 (PDT) From: Alexandru Gagniuc To: u-boot@lists.denx.de, sjg@chromium.org Cc: Alexandru Gagniuc , trini@konsulko.com Subject: [PATCH RFC 05/10] image: rsa: Move verification algorithm to a linker list Date: Fri, 14 May 2021 14:45:57 -0500 Message-Id: <20210514194602.598322-6-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210514194602.598322-1-mr.nuke.me@gmail.com> References: <20210514194602.598322-1-mr.nuke.me@gmail.com> MIME-Version: 1.0 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 b750751144..d3be30289c 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 aee76f42d5..06b0d82e7d 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