From patchwork Fri Feb 19 18:45:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex G." X-Patchwork-Id: 1442429 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=85.214.62.61; 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=X4n4KfJF; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4Dj0tk1xk6z9sBJ for ; Sat, 20 Feb 2021 05:47:26 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C5ECA827D2; Fri, 19 Feb 2021 19:46:26 +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="X4n4KfJF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 441A282765; Fri, 19 Feb 2021 19:45:39 +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,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) (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 1E32982731 for ; Fri, 19 Feb 2021 19:45:32 +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-oi1-x22f.google.com with SMTP id d20so6806396oiw.10 for ; Fri, 19 Feb 2021 10:45:32 -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=2CYpLVsFmG75gWdUfwYjrm1/wxyRLKSz8IMaukyCYNo=; b=X4n4KfJFKE/htWftdUPDDVAlO/mB5oZfr8WvI1OIZPFCHpGcKCZvycylJPG9eJ2NF0 ty+5Bce8oEFQjt0sd/kwwM8eQZugiPNs8l7WNdkT+WbGebzmSR3mAPV1ZfGUZVDjOQTh Lo82yBqscFtafYSPPvjlWO82p9tKzWTQmqzpN03lbXDWyPC+IoliI10zY1turZ8MUBQf BzUv7AU4ARdfeKM/NPbYSUx4JIeKJFnAd6xzK6zlfpQv3YLJ5xaEooYGt7qF4lrGPDNs LVL3gErCoghIryyOF3nCYsLBlAlqVVF+nTYqrKUZyhrH2K4brmvHjtsCqaD5lD4mh02F tFtw== 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=2CYpLVsFmG75gWdUfwYjrm1/wxyRLKSz8IMaukyCYNo=; b=omjMVeCKKIPVX+eI/xERLn2fv9PDt4LkNOjI43gYcJSXwzKKbscStqPyeqqR0tWutr FbxcTrOyTYT0f8Rjh/zE1qWsuOks1SAGp5gtMW3Jv3UzRZS13CfE9GzHwFA6FoznpJpn y8AyQpmZoSTVVrrXpr7mL+A+kWIOGbNH9cDWSEJIZ9OJm2XWaTsRfOqqqSHm3rc3uCNj 0OouHBbfUUxBSGdj/cf1Y+AgO33h8eIIT4ITTjAcEht467zcylh6f3bD5RmXGt0dhk2K ox+yiQUGEvVGEYzMRFO4PzzV8atFbO5hy/z43hwbBszXMl2pRkWoYtDammAGBsQbam7I NR/A== X-Gm-Message-State: AOAM5318eIrdHpNfTBohfnBRwKOxgzO8vWAD6b8RjtysxhG9vOAEdLFe zph4zcVm5IEyXmbS7ORvx/0SeYsV/WY= X-Google-Smtp-Source: ABdhPJycf77pKEEWs62X1gUKcEOZ0zXaGcImKh/cQy0+bdS15GSTF5VDGc5H11Jvuax4BFHCdGl7bQ== X-Received: by 2002:aca:bf56:: with SMTP id p83mr7588436oif.38.1613760330332; Fri, 19 Feb 2021 10:45:30 -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 g14sm1860423oon.23.2021.02.19.10.45.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Feb 2021 10:45:29 -0800 (PST) From: Alexandru Gagniuc To: u-boot@lists.denx.de, trini@konsulko.com, sjg@chromium.org Cc: Alexandru Gagniuc , marex@denx.de Subject: [PATCH v6 10/11] lib/ecdsa: Use the 'keydir' argument from mkimage if appropriate Date: Fri, 19 Feb 2021 12:45:19 -0600 Message-Id: <20210219184520.616270-11-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210219184520.616270-1-mr.nuke.me@gmail.com> References: <20210219184520.616270-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)