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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A0127C433F5 for ; Tue, 18 Jan 2022 12:50:39 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BF4C383818; Tue, 18 Jan 2022 13:50:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="rizeGM5b"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4B60F8383A; Tue, 18 Jan 2022 13:50:35 +0100 (CET) Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) (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 05D6A8326F for ; Tue, 18 Jan 2022 13:50:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ed1-x52d.google.com with SMTP id m11so2458763edi.13 for ; Tue, 18 Jan 2022 04:50:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=PIBowfEQqSvhYv5kza5DDc3BgJVBiKeW6RilPmIwsMc=; b=rizeGM5bzQWq/vRr8ayRpJ15ULvgS9Djs6Sc0JR1S63Aipp0HN2GbBwFY+OCcmFUcO tBu+aNk3OAnIHybu7gJcXWGBGHoTFR+B19zWWdn0AaYFLhuFev2XrXg+shCdv6qxQKeA ELYx1QCWShACkTCVQ07/B/QCzGfF38TgqzJXi7v2wsu68JbEJancqObZO58iiwM+ktqO 8IHRCUY1NvK65uLYBzg+wHcneZaB7anDchDj1DWmUHAi7h2LpWFMiWz9g8KiLq565/+X FT/VT/TUN25Z/opTBWKriUmq8Y6g4BUBx5iguwgdZ9keR4PBeWZ5BP8weNL2HnoAaNiN a0bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=PIBowfEQqSvhYv5kza5DDc3BgJVBiKeW6RilPmIwsMc=; b=zzaBEN8nsAY12BuYFGuMyO4WpNaU/rwOTSxrChI6wGRKwV4mvmscgSoZALau2nsT/b pQPpW6BHuEyC406itDgTCdlWcrGnlIrpVf6plbuDYBpFFN1h3m47sJ7MyIbK/x+nb6ON h+MPXa2u0IFJwRXvKcm05yvR1KSZqPHgAGUTCnRp/aws75uavcIj16uKDWLVPlwBLxcB LMbf74imjPWa0x5Pwpqu9nAm1tSpr5y0z4qrpUn25f6m1jf8jfplm53+aoqEyAg5IaWD Lgc+w3BZyjLmGcpjnT9E/fQ7ocKmyYxWXmb2TUwgli1HMv3F26mUXzLpmmSu9KAV3uBN Bfww== X-Gm-Message-State: AOAM530mwumIHyGksI6uLI2jejSFMW9xbVfvscgDSTAbLjnOZ3XPy/f7 cWjazRTPCbSEge5U1fHOo+tMBA== X-Google-Smtp-Source: ABdhPJzGHWJlDTZbUIcrKiDYtWa+EflM0BDgikdE1haaBzMJdOd7Oc+bsK6lBGkweypZQaEAbFDrrA== X-Received: by 2002:a05:6402:43c5:: with SMTP id p5mr22709601edc.95.1642510230020; Tue, 18 Jan 2022 04:50:30 -0800 (PST) Received: from hades (athedsl-4461669.home.otenet.gr. [94.71.4.85]) by smtp.gmail.com with ESMTPSA id gz19sm4194981ejb.40.2022.01.18.04.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 04:50:28 -0800 (PST) Date: Tue, 18 Jan 2022 14:50:25 +0200 From: Ilias Apalodimas To: AKASHI Takahiro , xypron.glpk@gmx.de, u-boot@lists.denx.de Subject: Re: [PATCH] lib/crypto: Enable more algorithms in cert verification Message-ID: References: <20220118111238.321742-1-ilias.apalodimas@linaro.org> <20220118123822.GC30001@laputa> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220118123822.GC30001@laputa> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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 Akashi-san, On Tue, Jan 18, 2022 at 09:38:22PM +0900, AKASHI Takahiro wrote: > Hi Ilias, > > On Tue, Jan 18, 2022 at 01:12:37PM +0200, Ilias Apalodimas wrote: > > Right now the code explicitly limits us to sha1,256 hashes with RSA2048 > > encryption. But the limitation is artificial since U-Boot supports > > a wider range of algorithms. > > > > The internal image_get_[checksum|crypto]_algo() functions expect an > > argument in the format of ,. So let's remove the size > > checking and create the needed string on the fly in order to support > > more hash/signing combinations. > > > > Signed-off-by: Ilias Apalodimas > > --- > > lib/crypto/public_key.c | 27 +++++++++++++-------------- > > 1 file changed, 13 insertions(+), 14 deletions(-) > > > > diff --git a/lib/crypto/public_key.c b/lib/crypto/public_key.c > > index df6033cdb499..b783c63f5a51 100644 > > --- a/lib/crypto/public_key.c > > +++ b/lib/crypto/public_key.c > > @@ -97,6 +97,7 @@ int public_key_verify_signature(const struct public_key *pkey, > > const struct public_key_signature *sig) > > { > > struct image_sign_info info; > > + char algo[256]; > > int ret; > > > > pr_devel("==>%s()\n", __func__); > > @@ -108,29 +109,27 @@ int public_key_verify_signature(const struct public_key *pkey, > > return -EINVAL; > > > > memset(&info, '\0', sizeof(info)); > > + memset(algo, 0, sizeof(algo)); > > info.padding = image_get_padding_algo("pkcs-1.5"); > > /* > > * Note: image_get_[checksum|crypto]_algo takes a string > > * argument like "," > > * TODO: support other hash algorithms > > */ > > If this patch is applied, the TODO comment above will make no sense :) We are still only handle SHA, but there's a printable error now, so i'll get rid of the comment. > > > - if (strcmp(sig->pkey_algo, "rsa") || (sig->s_size * 8) != 2048) { > > - pr_warn("Encryption is not RSA2048: %s%d\n", > > - sig->pkey_algo, sig->s_size * 8); > > - return -ENOPKG; > > - } > > - if (!strcmp(sig->hash_algo, "sha1")) { > > - info.checksum = image_get_checksum_algo("sha1,rsa2048"); > > - info.name = "sha1,rsa2048"; > > - } else if (!strcmp(sig->hash_algo, "sha256")) { > > - info.checksum = image_get_checksum_algo("sha256,rsa2048"); > > - info.name = "sha256,rsa2048"; > > - } else { > > - pr_warn("unknown msg digest algo: %s\n", sig->hash_algo); > > + if (strcmp(sig->pkey_algo, "rsa")) { > > + pr_err("Encryption is not RSA: %s\n", sig->pkey_algo); > > return -ENOPKG; > > } > > + ret = snprintf(algo, sizeof(algo), "%s,%s%d", sig->hash_algo, > > + sig->pkey_algo, sig->s_size * 8); > > I'm not sure that this naming rule, in particular the latter part, will > always hold in the future while all the existing algo's observe it. > (Maybe we need some note somewhere?) The if a few lines below will shield us and return -EINVAL. How about adding an error message there? Cheers /Ilias > > -Takahiro Akashi > > > + > > + if (ret >= sizeof(algo)) > > + return -EINVAL; > > + > > + info.checksum = image_get_checksum_algo((const char *)algo); > > + info.name = (const char *)algo; > > info.crypto = image_get_crypto_algo(info.name); > > - if (IS_ERR(info.checksum) || IS_ERR(info.crypto)) > > + if (!info.checksum || !info.crypto) > > return -ENOPKG; > > > > info.key = pkey->key; > > -- > > 2.30.2 > >