From patchwork Fri Nov 20 01:41:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Peshkin X-Patchwork-Id: 1403423 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; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=broadcom.com header.i=@broadcom.com header.a=rsa-sha256 header.s=google header.b=OGnW5Bf1; 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 4CcfXS2QNCz9sTc for ; Fri, 20 Nov 2020 12:46:16 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 122A4825D6; Fri, 20 Nov 2020 02:41:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=broadcom.com header.i=@broadcom.com header.b="OGnW5Bf1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5F2F7825FB; Fri, 20 Nov 2020 02:41:48 +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=-1.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MIME_HEADER_CTYPE_ONLY, MIME_NO_TEXT,SPF_HELO_NONE,T_TVD_MIME_NO_HEADERS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (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 7A84C825D6 for ; Fri, 20 Nov 2020 02:41:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=joel.peshkin@broadcom.com Received: by mail-pf1-x441.google.com with SMTP id b63so6298031pfg.12 for ; Thu, 19 Nov 2020 17:41:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id; bh=gWFsqR0pgeBUPrctD837JV36iMLXkYsf1HXOV6A52R0=; b=OGnW5Bf1tlap2OkAuZcQY/MBF+XTVYz1WMU5sQQERTHXOsczVoIUHof8xuSPh4e65I tmvv5oV0rNTphNpV9O0Zygho27ScoN6xq1tde0XiMx3AHS+Ti5WoXajKL1L9Kbnmelii 7cnToItNXiZndOLmmkW78ro39Fv8JcgT0Ark0= 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; bh=gWFsqR0pgeBUPrctD837JV36iMLXkYsf1HXOV6A52R0=; b=WIZ8H0EqB3pijJmNgEBpTn22IqSxPpyGOn+OUjeysSiamGtETaG0kTKvPLWAK52CWI sU6UU3mbpNGiiT95RQ3JzV7IjUA588vlF/QN8KSoFaVjF3MCMs7gFmu6XJjYgttxdI/5 h5h6Wa6nC3XyGX//i5jkN4IEHKaBSDJ+ifC0htO8JIZW7sUb9Na8ODM8gU77Kqvecci4 GZeRBFgntjGRgzNM1K1MP8O3nOuFGkVCOzgxnXwhH/qcjBkbkttHRCbh/rtIIjxRnxwz 0ONKpz9O2/FkIIFQDWlrYRareI43OLIjzFpSfXeCSeV7FopMUAi6jIVZXVnbpnlTH5qx w2qg== X-Gm-Message-State: AOAM531Vjf+dkpIdmPRenwSdDp6z0wsE9yWpsJKOvxM32ibF7k987ITp +2AOa/11vcfN53M8xKb5U9X1fP13f/7p0MWhCMljwxEp9gqXn5Od1QNNmVTaHK8PwX10wdDo0t4 u3DGwZV2ISd8FUkGOpyrVjCyLjrRL/hYBKnRLvCjGRAhdPEBOna8tYqlnFWier9uEOQTg6073 X-Google-Smtp-Source: ABdhPJxZgufSSRF6nKe6tueLP8PFD5aeXNmR6ihCSyltqFAlo4g8hoY5g2iHWf8bIhcPDa+UUFAl3Q== X-Received: by 2002:a62:1d58:0:b029:18b:f61:4d50 with SMTP id d85-20020a621d580000b029018b0f614d50mr12186840pfd.76.1605836501042; Thu, 19 Nov 2020 17:41:41 -0800 (PST) Received: from xl-irv-13.lvn.broadcom.net ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id m9sm1281488pfh.94.2020.11.19.17.41.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Nov 2020 17:41:40 -0800 (PST) From: Joel Peshkin X-Google-Original-From: Joel Peshkin To: u-boot@lists.denx.de Cc: Joel Peshkin , Simon Glass , Bin Meng , Patrick Delaunay , Heiko Schocher , Heinrich Schuchardt Subject: [PATCH] Add optional salt to AUTOBOOT_STOP_STR_SHA256 Date: Thu, 19 Nov 2020 17:41:14 -0800 Message-Id: <20201120014114.48895-1-jp933255@xl-irv-13.lvn.broadcom.net> X-Mailer: git-send-email 2.18.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 From: Joel Peshkin Adds an optional SALT value to AUTOBOOT_STOP_STR_SHA256. If a string followed by a ":" is prepended to the sha256, the portion to the left of the colon will be used as a salt and the password will be appended to the salt before the sha256 is computed and compared. Signed-off-by: Joel Peshkin --- common/Kconfig.boot | 5 ++++- common/autoboot.c | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/common/Kconfig.boot b/common/Kconfig.boot index 3f6d9c1..8a98672 100644 --- a/common/Kconfig.boot +++ b/common/Kconfig.boot @@ -819,7 +819,10 @@ config AUTOBOOT_STOP_STR_SHA256 This option adds the feature to only stop the autobooting, and therefore boot into the U-Boot prompt, when the input string / password matches a values that is encypted via - a SHA256 hash and saved in the environment. + a SHA256 hash and saved in the environment variable + "bootstopkeysha256". If the value in that variable + includes a ":", the portion prior to the ":" will be treated + as a salt value. config AUTOBOOT_USE_MENUKEY bool "Allow a specify key to run a menu from the environment" diff --git a/common/autoboot.c b/common/autoboot.c index e628baf..0c4e6ff 100644 --- a/common/autoboot.c +++ b/common/autoboot.c @@ -80,6 +80,7 @@ static int passwd_abort_sha256(uint64_t etime) u8 sha_env[SHA256_SUM_LEN]; u8 *sha; char *presskey; + char *c; const char *algo_name = "sha256"; u_int presskey_len = 0; int abort = 0; @@ -89,6 +90,14 @@ static int passwd_abort_sha256(uint64_t etime) if (sha_env_str == NULL) sha_env_str = AUTOBOOT_STOP_STR_SHA256; + presskey = malloc_cache_aligned(MAX_DELAY_STOP_STR); + c = strstr(sha_env_str, ":"); + if (c) { + /* preload presskey with salt */ + memcpy(presskey, sha_env_str, c - sha_env_str); + presskey_len += c - sha_env_str; + sha_env_str = c + 1; + } /* * Generate the binary value from the environment hash value * so that we can compare this value with the computed hash @@ -100,7 +109,6 @@ static int passwd_abort_sha256(uint64_t etime) return 0; } - presskey = malloc_cache_aligned(MAX_DELAY_STOP_STR); sha = malloc_cache_aligned(SHA256_SUM_LEN); size = SHA256_SUM_LEN; /*