From patchwork Thu Feb 4 19:57:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Gagniuc X-Patchwork-Id: 1436282 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=lNmNnuUl; 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 4DWq9G3WbJz9sWg for ; Fri, 5 Feb 2021 06:58:10 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5434F82948; Thu, 4 Feb 2021 20:57:44 +0100 (CET) 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="lNmNnuUl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D77DF8290E; Thu, 4 Feb 2021 20:57:22 +0100 (CET) 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,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) (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 35A32828FD for ; Thu, 4 Feb 2021 20:57:16 +0100 (CET) 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-x332.google.com with SMTP id o12so4595091ote.12 for ; Thu, 04 Feb 2021 11:57:16 -0800 (PST) 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=bhenPV4kwqvvmyI5iSho2VUxfZALVecNgYrvieQ6hz8=; b=lNmNnuUlsjHbqhb/r4nB9TTd6zDQE5Tf3yPIUSErk77vpWsl+pM3SE/7YL9g36njlF gat3ig1mMZ+EIBZbC1+xihvR77oydUSR42/EfKOVF4ZJftBkQ72hNCypg4o1t11dnkOS 7jhPpuZBXmFyW6hRuFdf+g+8rAhcBg5831T38qsIdHmDh861ggY55qgUsTKuEWhZDqTa 6WxpbaYAKp4L7e1aUYz0FSeuqv+vOTHR/gT7ke24I1eSKZnZlCmkHWkrkQVBMazHLT6l x6kfMdpDXch37i8PHO3u+NhvbbHzrynZsAqb4rU7+Uft4KkvT1RUbegKYlcsras1uvBb m4rQ== 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=bhenPV4kwqvvmyI5iSho2VUxfZALVecNgYrvieQ6hz8=; b=NF4u5RNxXdcxS1wH3eSfJ1v7Cy5uSY7P97yZ85JHJHjy0+mEjtwrP7XM0DfPzGkzAv jTUMEFeo6UDAC3ip/wmMlbmMvvpOZaLfa1gFmk/y2UKjWxI0GUT1lGWM48/K91IZ9/eK T1aM1ba7qnZIqB9kPjih0ye9z49aSlJr4Z8sz59DkSXu8uXiWDWS3Zd05vnv5TUEymH1 u3yCQxXf5TUFpAm6WKCiC17tUoyG2lUeohM9w1tHVEfcNpQspUu2D+ny9lUfQmirdb5k 6UiTMdlc5xxlJRzxdHURpdFa6YBILGGzMAXWH27Uexnno12usKKju2YaFrUgwWCAqy9P nfHQ== X-Gm-Message-State: AOAM533Vc9E5k+eCbOVnQYETUm5Z7Ek+9dGugQrn4YZGOylWBV2kdxrw /Lrqi2tP2dZG6KYYw7e448lrO25n4LI= X-Google-Smtp-Source: ABdhPJz8N8e56QR4VHtWzPNg7a7+QvzrthLJ9MOaD2h0omwOpdvXfhUEoIT2kdy5anHtWOF1v3tOmQ== X-Received: by 2002:a05:6830:24a2:: with SMTP id v2mr782092ots.298.1612468634738; Thu, 04 Feb 2021 11:57:14 -0800 (PST) Received: from nuclearis2-1.lan (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id d17sm1309672oic.12.2021.02.04.11.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 11:57:14 -0800 (PST) From: Alexandru Gagniuc To: u-boot@lists.denx.de, sjg@chromium.org Cc: Alexandru Gagniuc , trini@konsulko.com, marex@denx.de Subject: [PATCH 4/4] lib/ecdsa: Use the 'keydir' argument from mkimage if appropriate Date: Thu, 4 Feb 2021 13:57:05 -0600 Message-Id: <20210204195705.2057081-5-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210204195705.2057081-1-mr.nuke.me@gmail.com> References: <20210204195705.2057081-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.3 at phobos.denx.de X-Virus-Status: Clean Keys can be derived from keydir, and the "key-name-hint" property of the FIT. They can also be specified ad-literam via 'keyfile'. Update the ECDSA signing path to use the appropriate one. Signed-off-by: Alexandru Gagniuc Reviewed-by: Simon Glass --- lib/ecdsa/ecdsa-libcrypto.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/ecdsa/ecdsa-libcrypto.c b/lib/ecdsa/ecdsa-libcrypto.c index 322880963f..1757a14562 100644 --- a/lib/ecdsa/ecdsa-libcrypto.c +++ b/lib/ecdsa/ecdsa-libcrypto.c @@ -140,8 +140,20 @@ static int read_key(struct signer *ctx, const char *key_name) /* Prepare a 'signer' context that's ready to sign and verify. */ static int prepare_ctx(struct signer *ctx, const struct image_sign_info *info) { - const char *kname = info->keydir; int key_len_bytes, ret; + char kname[1024]; + + memset(ctx, 0, sizeof(*ctx)); + + if (info->keyfile) { + snprintf(kname, sizeof(kname), "%s", info->keyfile); + } else if (info->keydir && info->keyname) { + snprintf(kname, sizeof(kname), "%s/%s.pem", info->keydir, + info->keyname); + } else { + fprintf(stderr, "keyfile, keyname, or key-name-hint missing\n"); + return -EINVAL; + } ret = alloc_ctx(ctx, info); if (ret)