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=-14.5 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,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 11124C432BE for ; Wed, 28 Jul 2021 20:00:58 +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 238AA601FC for ; Wed, 28 Jul 2021 20:00:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 238AA601FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8A16582CDA; Wed, 28 Jul 2021 22:00:54 +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="vIjYZkEh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9CDB582D73; Wed, 28 Jul 2021 22:00:51 +0200 (CEST) Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) (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 8C16982A01 for ; Wed, 28 Jul 2021 22:00:47 +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-oi1-x233.google.com with SMTP id o20so5169825oiw.12 for ; Wed, 28 Jul 2021 13:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=dXdB12asaaI98dtW4IbIhlcNsFIb5JEH4iMtoX9yJz8=; b=vIjYZkEhq9QrJeZbWqeYuKpyt7zHSES8JARFcMOH6ztcJeBIqcJgW18GoJOVlkX1xR OkmC3FFC36/qxZTgtSysgihYcyzC8yuPH7QsRzpd7vF04nEoiPYY6QD2MqUN4JNNuase V7bohDOV2mt0qJtADuNChsJ0KnzWV9JDOul5UzZo+yVQrz35QFhpFavtDPEfE0+uluMn HUfIOSIGqXN53YbejYBEzKy7dn1jukgm3+aub7O5upsT8xTsABx481/OUL3ZaK+GLHt5 KAZKqdB4sh3QJXYLu33RTQVovB8tHzywhQiJrwT1VdiXDmGzkkKzMsgLJtx3DTqOTskn 6f8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=dXdB12asaaI98dtW4IbIhlcNsFIb5JEH4iMtoX9yJz8=; b=aRs88M1CdoyfqtPiZiBYFlFXauygSIxgMtG+acke17kADSp/Aov+4DLkDqeD+juPST SecuhB5nF/LVvpO5N59U0vUgz1ZXA0ngzEPi5mNPowmWOZ0RfM6b9zZlONBFoTPLXgE/ bE9SP/axw5Cc9pxmQb2fMMkF7oO1JyjwG3lVy9pJaS+SDWmHe3L55obGsJt3kO/1XOZY p654VlpdE+mCcHd/aLDJyTRZ0tVgtQZ8JSTO27BTCPP42FrjqeihW5aGVvb3LSfGhlzJ Uzmji0T9zmbicUIpFyEk20D8MgkX06YGASa0SvAQFNLQv5lEwNRhPTCRwGYkmsgGbORK DU8w== X-Gm-Message-State: AOAM532YHJ/xCMt4GaOhkaIWsr6TxW1pRFNI/+PnHAbpQhdXrzItigNB ATHWuWSZEe13sNzfXjSFeGU= X-Google-Smtp-Source: ABdhPJz7zGcf0u3g1X4QpZkxTRBoLp+K1YuVrE8W+K1SZdOhhSKm/cd551nvqXM4yV9AMx+s8ZLsBg== X-Received: by 2002:a05:6808:1790:: with SMTP id bg16mr2548263oib.120.1627502446081; Wed, 28 Jul 2021 13:00:46 -0700 (PDT) Received: from nuclearis3.gtech (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id n7sm190575otf.45.2021.07.28.13.00.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Jul 2021 13:00:45 -0700 (PDT) Subject: Re: [PATCH 1/1] lib/ecdsa: Fix LibreSSL before v2.7.0 To: Artem Panfilov , "u-boot@lists.denx.de" , Tom Rini References: <20210728181023.25067-1-panfilov.artyom@gmail.com> From: "Alex G." Message-ID: <21fa035a-7ab5-7045-dd47-90670eb8be14@gmail.com> Date: Wed, 28 Jul 2021 15:00:44 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US 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 Hi Artem, I'm re-adding the u-boot mailing list to the CC field, as I see your email contains no sensitive information. On 7/28/21 2:30 PM, Artem Panfilov wrote: > We have broken CI builds on your bare-metal CentOS 7 servers with latest > master. I think it is good reason to have  a support. Our corporate > clients have CentOS 7 too. I thought we solved problems associated with bare builds on ancient OSes by using containerized builds. There's is CI infrastructure based on this on source.denx.de that uses docker. As things change, and we eventually move to GNU TLS, a lot more things might break for old build hosts. I believe it's worth looking at containerized builds. Given that a solution exists for your problem, I think the argument for this patch quite weak. > There is no nice way to handle openssl difference. You could check other > commits related to openssl compatibility. They all looks ugly. > Another solution is to disable CONFIG_TOOLS_LIBCRYPTO by default that > broke our builds. Do you need cryptographic features in mkimage? If not just disable TOOLS_LIBCRYPTO in your builds. Alex > Best regards, > Artem > > ср, 28 июл. 2021 г., 22:16 Alex G. >: > > > > On 7/28/21 1:10 PM, Artem Panfilov wrote: > > Fix LibreSSL compilation for versions before v2.7.0. > > > > Fix following compilation issue when CONFIG_TOOLS_LIBCRYPTO is > enabled: > > tools/lib/ecdsa/ecdsa-libcrypto.o: In function `prepare_ctx': > > ecdsa-libcrypto.c:(.text+0x94): undefined reference to > > `OPENSSL_init_ssl' > > ecdsa-libcrypto.c:(.text+0x148): undefined reference to > > `EC_GROUP_order_bits' > > tools/lib/ecdsa/ecdsa-libcrypto.o: In function > > `ecdsa_check_signature.isra.0': > > ecdsa-libcrypto.c:(.text+0x32c): undefined reference to > `ECDSA_SIG_set0' > > tools/lib/ecdsa/ecdsa-libcrypto.o: In function `ecdsa_sign': > > ecdsa-libcrypto.c:(.text+0x42c): undefined reference to > `ECDSA_SIG_get0' > > ecdsa-libcrypto.c:(.text+0x443): undefined reference to > `BN_bn2binpad' > > ecdsa-libcrypto.c:(.text+0x455): undefined reference to > `BN_bn2binpad' > > tools/lib/ecdsa/ecdsa-libcrypto.o: In function > `ecdsa_add_verify_data': > > ecdsa-libcrypto.c:(.text+0x5fa): undefined reference to > > `EC_GROUP_order_bits' > > ecdsa-libcrypto.c:(.text+0x642): undefined reference to > > `EC_POINT_get_affine_coordinates' > > > > Signed-off-by: Artem Panfilov > > > --- > >   lib/ecdsa/ecdsa-libcrypto.c | 80 > ++++++++++++++++++++++++++++++++++++- > >   1 file changed, 79 insertions(+), 1 deletion(-) > > > > diff --git a/lib/ecdsa/ecdsa-libcrypto.c > b/lib/ecdsa/ecdsa-libcrypto.c > > index 1757a14562..50aa093acd 100644 > > --- a/lib/ecdsa/ecdsa-libcrypto.c > > +++ b/lib/ecdsa/ecdsa-libcrypto.c > > @@ -24,6 +24,70 @@ > >   #include > >   #include > > > > +#if OPENSSL_VERSION_NUMBER < 0x10100000L || \ > > +     (defined(LIBRESSL_VERSION_NUMBER) && > LIBRESSL_VERSION_NUMBER < 0x02070000fL) > > > Is there a reasonable use case for supporting an external library that > is more than three years old at this point? > > Otherwise NAK, as such #ifdefs don't really help with readability. I > think Simon will agree here. > > There's also the issue of deciding what version we have at compile > time, > which ignores the dynamic linking nature of .so libs. This leads into > soname versioning territory. Let's not go there. > > Alex > > > +#include > > + > > +static int EC_GROUP_order_bits(const EC_GROUP *group) > > +{ > > +     int ret = 0; > > +     BIGNUM *order; > > + > > +     if (!group) > > +             return ret; > > + > > +     order = BN_new(); > > + > > +     if (!order) { > > +             ERR_clear_error(); > > +             return ret; > > +     } > > + > > +     if (!EC_GROUP_get_order(group, order, NULL)) { > > +             ERR_clear_error(); > > +             BN_free(order); > > +             return ret; > > +     } > > + > > +     ret = BN_num_bits(order); > > +     BN_free(order); > > +     return ret; > > +} > > + > > +static void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM > **pr, const BIGNUM **ps) > > +{ > > +     if (pr != NULL) > > +             *pr = sig->r; > > +     if (ps != NULL) > > +             *ps = sig->s; > > +} > > + > > +static int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s) > > +{ > > +     if (r == NULL || s == NULL) > > +             return 0; > > +     BN_clear_free(sig->r); > > +     BN_clear_free(sig->s); > > +     sig->r = r; > > +     sig->s = s; > > +     return 1; > > +} > > + > > +int BN_bn2binpad(const BIGNUM *a, unsigned char *to, int tolen) > > +{ > > +     int n = BN_num_bytes(a); > > + > > +     if (n < 0 || n > tolen) > > +             return -1; > > + > > +     memset(to, 0, tolen - n); > > +     if (BN_bn2bin(a, to + tolen - n) < 0) > > +             return -1; > > + > > +     return tolen; > > +}tures in mkimage? If not just disable TOOLS_LIBCRYPTO in your builds. > > +#endif > > + > >   /* Image signing context for openssl-libcrypto */ > >   struct signer { > >       EVP_PKEY *evp_key;      /* Pointer to EVP_PKEY object */ > > @@ -34,9 +98,18 @@ struct signer { > > > >   static int alloc_ctx(struct signer *ctx, const struct > image_sign_info *info) > >   { > > +     int ret = 0; > > + > >       memset(ctx, 0, sizeof(*ctx)); > > > > -     if (!OPENSSL_init_ssl(0, NULL)) { > > +#if OPENSSL_VERSION_NUMBER < 0x10100000L || \ > > +(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < > 0x02070000fL) > > +     ret = SSL_library_init(); > > +#else > > +     ret = OPENSSL_init_ssl(0, NULL); > > +#endif > > + > > +     if (!ret) { > >               fprintf(stderr, "Failure to init SSL library\n"); > >               return -1; > >       } > > @@ -285,7 +358,12 @@ static int do_add(struct signer *ctx, void > *fdt, const char *key_node_name) > >       x = BN_new(); > >       y = BN_new(); > >       point = EC_KEY_get0_public_key(ctx->ecdsa_key); > > +#if OPENSSL_VERSION_NUMBER < 0x10100000L || \ > > +(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < > 0x02070000fL) > > +     EC_POINT_get_affine_coordinates_GFp(group, point, x, y, NULL); > > +#else > >       EC_POINT_get_affine_coordinates(group, point, x, y, NULL); > > +#endif > > > >       ret = fdt_setprop_string(fdt, key_node, "ecdsa,curve", > curve_name); > >       if (ret < 0) > > >