Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lyVmf-0001RC-Q1 for mharc-grub-devel@gnu.org; Wed, 30 Jun 2021 04:41:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyVme-0001Lw-4V for grub-devel@gnu.org; Wed, 30 Jun 2021 04:41:24 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:45815) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lyVmc-0003sz-AW for grub-devel@gnu.org; Wed, 30 Jun 2021 04:41:23 -0400 Received: by mail-pf1-x42b.google.com with SMTP id j24so1729328pfi.12 for ; Wed, 30 Jun 2021 01:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dDQbm0TdaEOVBUVpON/0rBfOzbKJYQEVy+1NOXdObWI=; b=DNM6gptvcCmQFXfs6fdS8/nhKig+rqnP0pCnJB393hh7UodF5vAoCSAwCHj9Abofgp 2a8U3Xan7RDpduQqa9Ao/Z5xP/+8bHoTegfNnjwQtRGg0xq923ZqjwLI/KkRRwX4StO6 RGYAy/XKi2VPLetfP8Q8RMQSqjM0vRvb++gOc= 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=dDQbm0TdaEOVBUVpON/0rBfOzbKJYQEVy+1NOXdObWI=; b=br65V6skIjTrZzxsDojrSzD4oaw10gIV7BfsFZ+624OLJaUpAmY3EdDDw86qMQKoH3 ht1qm0dZPrk9m1w/BWjXwKftRfGwtqoQqF3jDnHIsAbnAAwH5Zkc045AHkGmZ+LkQcRj 2MTBaMImk6H8PLOFHa3tR+HBOfpoBtWZA29rvMiy8gmAKyt7fOnfbLNj2WNKOeNUQucO Qo95mhwz9Ihvdm4e3MkOuE34a43UPccl+QiwY7XyAZsP2hKto5c/tlERsozBltdDpJEB QSZmobjWbvZY3FpTPxx4hsihDfU3OXyCmjqSJFCReSMdJdp+zS78P/qY5YR6e34UKSGn bPIg== X-Gm-Message-State: AOAM530FTBeLs+N00ucosOsndbYUhxjOnOpu/VZYwB2IVnS0nfKN2zEn vxCLEzx50Huk/dToLWOtoqZ6UgNrHPrUvw== X-Google-Smtp-Source: ABdhPJyCMfmKC2M5yxzcWXij+O6/ebpe61eYHEeyWenRB1+crsrsMhb9ydXGXis06dC8+7X/scqdQg== X-Received: by 2002:a63:dc51:: with SMTP id f17mr2522099pgj.366.1625042480857; Wed, 30 Jun 2021 01:41:20 -0700 (PDT) Received: from localhost ([203.206.29.204]) by smtp.gmail.com with ESMTPSA id c18sm21267339pgf.66.2021.06.30.01.41.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 01:41:20 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Cc: rashmica.g@gmail.com, alastair@d-silva.org, nayna@linux.ibm.com, Daniel Axtens Subject: [PATCH v2 09/22] crypto: move storage for grub_crypto_pk_* to crypto.c Date: Wed, 30 Jun 2021 18:40:18 +1000 Message-Id: <20210630084031.2663622-10-dja@axtens.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210630084031.2663622-1-dja@axtens.net> References: <20210630084031.2663622-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=dja@axtens.net; helo=mail-pf1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Jun 2021 08:41:24 -0000 The way gcry_rsa and friends (the asymmetric ciphers) are loaded for the pgp module is a bit quirky. include/grub/crypto.h contains: extern struct gcry_pk_spec *grub_crypto_pk_rsa; commands/pgp.c contains the actual storage: struct gcry_pk_spec *grub_crypto_pk_rsa; And the module itself saves to the storage in pgp.c: GRUB_MOD_INIT(gcry_rsa) { grub_crypto_pk_rsa = &_gcry_pubkey_spec_rsa; } This is annoying: gcry_rsa now has a dependency on pgp! We want to be able to bring in gcry_rsa without bringing in PGP, so move the storage to crypto.c. Previously, gcry_rsa depended on pgp and mpi. Now it depends on crypto and mpi. As pgp depends on crypto, this doesn't add any new module dependencies using the PGP verfier. [FWIW, the story is different for the symmetric ciphers. cryptodisk and friends (zfs encryption etc) use grub_crypto_lookup_cipher_by_name() to get a cipher handle. That depends on grub_ciphers being populated by people calling grub_cipher_register. import_gcry.py ensures that the symmetric ciphers call it.] Signed-off-by: Daniel Axtens --- grub-core/commands/pgp.c | 4 ---- grub-core/lib/crypto.c | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/grub-core/commands/pgp.c b/grub-core/commands/pgp.c index 2408db4994f6..355a43844acc 100644 --- a/grub-core/commands/pgp.c +++ b/grub-core/commands/pgp.c @@ -147,10 +147,6 @@ const char *hashes[] = { [0x0b] = "sha224" }; -struct gcry_pk_spec *grub_crypto_pk_dsa; -struct gcry_pk_spec *grub_crypto_pk_ecdsa; -struct gcry_pk_spec *grub_crypto_pk_rsa; - static int dsa_pad (gcry_mpi_t *hmpi, grub_uint8_t *hval, const gcry_md_spec_t *hash, struct grub_public_subkey *sk); diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c index ca334d5a40e0..c578128a59db 100644 --- a/grub-core/lib/crypto.c +++ b/grub-core/lib/crypto.c @@ -121,6 +121,10 @@ grub_md_unregister (gcry_md_spec_t *cipher) } } +struct gcry_pk_spec *grub_crypto_pk_dsa; +struct gcry_pk_spec *grub_crypto_pk_ecdsa; +struct gcry_pk_spec *grub_crypto_pk_rsa; + void grub_crypto_hash (const gcry_md_spec_t *hash, void *out, const void *in, grub_size_t inlen) -- 2.30.2