From patchwork Tue Apr 19 20:43:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Fenkart X-Patchwork-Id: 612299 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3qqH6x5chSz9t73 for ; Wed, 20 Apr 2016 06:44:09 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7BB0EA7647; Tue, 19 Apr 2016 22:44:03 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nKr_EVMw4Kyf; Tue, 19 Apr 2016 22:44:03 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 08E56A7665; Tue, 19 Apr 2016 22:44:02 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F17D3A765E for ; Tue, 19 Apr 2016 22:43:57 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aPkcD1Fw50hs for ; Tue, 19 Apr 2016 22:43:57 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail.newtechgroup.ch (mail.newtechgroup.ch [83.144.237.166]) by theia.denx.de (Postfix) with ESMTPS id 1330BA7498 for ; Tue, 19 Apr 2016 22:43:54 +0200 (CEST) Received: from localhost (192.168.1.1) by vsrv-mailch01.newtechgroup.local (192.168.1.208) with Microsoft SMTP Server (TLS) id 15.0.775.38; Tue, 19 Apr 2016 22:43:50 +0200 From: Andreas Fenkart To: Date: Tue, 19 Apr 2016 22:43:39 +0200 Message-ID: <1461098623-5297-2-git-send-email-andreas.fenkart@digitalstrom.com> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1461098623-5297-1-git-send-email-andreas.fenkart@digitalstrom.com> References: <1461098623-5297-1-git-send-email-andreas.fenkart@digitalstrom.com> MIME-Version: 1.0 X-Originating-IP: [192.168.1.1] X-ClientProxiedBy: VSRV-MAILCH01.newtechgroup.local (192.168.1.208) To vsrv-mailch01.newtechgroup.local (192.168.1.208) X-Brightmail-Tracker: H4sIAAAAAAAAC+NgFvrLosTGxXJgBSOjbtsMsXCDcwdOvmS3OPfuLbPFgX5+i69Nxg7MAQxRrJl5SfkVCawZjyatZi9YKlgx41dUA+MH3i5GLg4hgfWMEteeHGPtYuTkYBOwkHh4ZwoLiC0iICHxq/8qI4jNLBAhcfJeOzOILSzgIzH96w+gGg4OFgFViR97qkBMXgF/iVvLfUAqJASUJDY8uMAEEuYUCJB4c8YVJCwEVLH7eifYQF4BQYmTM5+wQAyXkDj44gUzSLmQgK5E/3ZpiCmBEkf7tzFC2O4Ss1/fZoaw7SXWvfjGClIuIeAo8eRDKEzJ520rWSFsbYntr/ZB2ToSy/dNZ4ew5SV+bl3CBGFXSlx8fBkqHi/RdPQLVH2oxK+jE5gmMErMQnLoLCSHLmBkWsWoUFZcVKabm5iZk5xhYKiXl1pekpqckV6UX1qgl5OfnJiziRESNRd2MDa/dj/EKMnBpCTKa1UsFi7El5SfUpmRWJwRX1Sak1p8iFGCg0dJhFd+OlCOt7ggMbc4Mx0mJcPBoSTBe3UaUEqwKDU9tSItM6cktQgifYpRUkqc9zRIUgCkL6M0Dy53iVFUSphXciJQjqcgtSg3swQifotRmOMhkxBLXn5eqhTQiQxAoMH4ilGcg1FJmFcL5AaezLwSuBNeAV3HBHQd/11RkOtKEhFSUg2MG58YHneUrGVxvL8qtcuw5+e/EwYXOM/1W20zvNCzkLNWwH9J5NqarY85FzJ155SJ3Z5+YS6XNr+SWILa8/fnVr7dkOE618FI8+C11X/flAmdWJMwxdfDUKLVrrPSwb37dNzRX3L6Rxi7jZOedM3afECtY9ovHYElLb1SfBHXVLfcmGV/MP+HEktxRqKhFnNRcSIASOmipxADAAA= Subject: [U-Boot] [PATCH v2 1/5] tools/env: pass key as argument to env_aes_cbc_crypt X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 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" Signed-off-by: Andreas Fenkart --- tools/env/fw_env.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 1420ac5..e5b2e8f 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -106,7 +106,7 @@ static struct environment environment = { .flag_scheme = FLAG_NONE, }; -static int env_aes_cbc_crypt(char *data, const int enc); +static int env_aes_cbc_crypt(char *data, const int enc, uint8_t *key); static int HaveRedundEnv = 0; @@ -304,7 +304,8 @@ int fw_env_close(void) { int ret; if (common_args.aes_flag) { - ret = env_aes_cbc_crypt(environment.data, 1); + ret = env_aes_cbc_crypt(environment.data, 1, + common_args.aes_key); if (ret) { fprintf(stderr, "Error: can't encrypt env for flash\n"); @@ -949,7 +950,7 @@ static int flash_flag_obsolete (int dev, int fd, off_t offset) } /* Encrypt or decrypt the environment before writing or reading it. */ -static int env_aes_cbc_crypt(char *payload, const int enc) +static int env_aes_cbc_crypt(char *payload, const int enc, uint8_t *key) { uint8_t *data = (uint8_t *)payload; const int len = getenvsize(); @@ -957,7 +958,7 @@ static int env_aes_cbc_crypt(char *payload, const int enc) uint32_t aes_blocks; /* First we expand the key. */ - aes_expand_key(common_args.aes_key, key_exp); + aes_expand_key(key, key_exp); /* Calculate the number of AES blocks to encrypt. */ aes_blocks = DIV_ROUND_UP(len, AES_KEY_LENGTH); @@ -1186,7 +1187,8 @@ int fw_env_open(void) crc0 = crc32 (0, (uint8_t *) environment.data, ENV_SIZE); if (common_args.aes_flag) { - ret = env_aes_cbc_crypt(environment.data, 0); + ret = env_aes_cbc_crypt(environment.data, 0, + common_args.aes_key); if (ret) return ret; } @@ -1243,7 +1245,8 @@ int fw_env_open(void) crc1 = crc32 (0, (uint8_t *) redundant->data, ENV_SIZE); if (common_args.aes_flag) { - ret = env_aes_cbc_crypt(redundant->data, 0); + ret = env_aes_cbc_crypt(redundant->data, 0, + common_args.aes_key); if (ret) return ret; }