From patchwork Sun Jun 16 20:17:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 'Darko Komljenovic' via swupdate X-Patchwork-Id: 1116629 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::53f; helo=mail-ed1-x53f.google.com; envelope-from=swupdate+bncbcj4pko5sipbb2ohtluakgqev7jwk7a@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=googlegroups.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="YBxupWqF"; dkim-atps=neutral Received: from mail-ed1-x53f.google.com (mail-ed1-x53f.google.com [IPv6:2a00:1450:4864:20::53f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45RlyR2Xpgz9s7h for ; Mon, 17 Jun 2019 06:17:49 +1000 (AEST) Received: by mail-ed1-x53f.google.com with SMTP id b12sf13066091eds.14 for ; Sun, 16 Jun 2019 13:17:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1560716265; cv=pass; d=google.com; s=arc-20160816; b=bXRpnaMPWnrCHHn1rTlxIrmK0hK9JlLJUnkAigzjXKpR8Y0s/E/YnaL4WJfpfYdPVq N2AvqCCXqJnmTc3wGVx52gbJtZ8jsvd4BQyQlc4HPpKkn+zF4zz6QuC0phUUPw9eHRJ2 adaLbKOtppL+9z2gCpU0tvtjJAsKBAdTO3x4fQeNBmNjvrxaIezOMuNeAIxlO+KAetv1 +7b9jc1rLQUfyQnrci6MhCn3LFZ7tytikSbXA00ej2m25Ma7jRPfKgZ2IWsP8KJvqjx2 pJ63NLuXDxLlkPiS/k4rKj48fGBimU19t09K3h7/pW7iXrhAgjXHBpnmhqbRMIku5QVB Gk6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:mime-version:message-id :date:subject:cc:to:from:dkim-signature; bh=4bDw2e2wmZzW5YjeRbjFKxmMtEaKumSRDbXGhvv9I7A=; b=GH29+HgUQ8y5Y53JLvSsMFGLZgNp0WyL2CYp1r7MT8U6MeUPYQFxQo1fkMd12orSSg XnhRUp7yaaahLykhAZP5W6l7jgKHy4Ow8SUj2RkyJnAwI4e8uMegYgsJXFQGkAnMoKzV QqEoW4Iodxaih+nU/5kimhxU+CfhcDUvd/su4StH/OPUv3b2jExAX6Dqh02mLsmVUw+6 7ACnNvhnGeFL2jpopw8i9DBdt3+mxX5j8UMKNMPqBMUX4ycocJF8a1yIZG378WvIT6bH UAlT2gd23Yjqwf2NLCO6pmYhvj/PjYCl4Yo2xcpGhwE6bWRnB+2gdPtdtb5p8E30TIVG j3qw== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@ashin.hu header.s=mail header.b=YeRjvyOO; spf=pass (google.com: domain of laszlo@ashin.hu designates 45.32.159.235 as permitted sender) smtp.mailfrom=laszlo@ashin.hu; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ashin.hu DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=4bDw2e2wmZzW5YjeRbjFKxmMtEaKumSRDbXGhvv9I7A=; b=YBxupWqFrj2xnglVgU7mbTONpjFGLeqmaroaN09hUBI54MraHELNv0v9yw6QZYvvse lJfsf5z2v43bDSW/a4I3k3+iWxt2C5ak9/NpFE1mO1mCTJG56apONR2gfEfRA7KF3TAE Rq8mkT0BYRDx73980dHonSYbsn8Cf7LDH2FkHR5iZf2RwasjxLr0Auoi4d50WVCckLfE 60/P2zyOq3XXso9om2aeOa966hagLriwTunolySiFcyqvfr5vU5JOkE+6BTElvP2b8ZZ BqAM5gbD9rFHTTkVHUFMmEwBaehiuUpYKa65mNPPHPZiyIvfUSk54JObU1Jk581bBQMd KUng== 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:mime-version :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=4bDw2e2wmZzW5YjeRbjFKxmMtEaKumSRDbXGhvv9I7A=; b=ZqnA9CvcRJXHBCiwq5cf0CuT5Ly86R0ElcxP18AU4NuuqPrxarAe4m6eiA64elqhd0 wBc+sT+UUwYMRwVw+VSJuSDVeX8s19pz3wgf+SWSxTGZZS+GYEnEVZqCxcs0B046SA4w Qv6CGmj2rUZaNF7cPHfmWhTQDHuPB5AnUS9CPrrqn3w8fk7nsc9wn1V7dXRXwWcc/lq8 STWQY+rhZivIpBitL/m9TYh0E3XicyszHofQWM9tInhTJajNtJQoosWMj93b1PL2VH1x WlC9pedBDUlnI/Jja+1ik0cf1h9e+wa7KW0ZAEXfgtK9J3/DRuPX9AX+Ry4PgdNj7B3R K7zQ== X-Gm-Message-State: APjAAAWWLTpmH30kh++LYnWYCT7+GX9n63ayHjIDpYkfKVpskCp/uplu 8ScdlwUeWWCBIMgON9NLe/E= X-Google-Smtp-Source: APXvYqyHe3GAul49eUEYn/EYFi8za5FYoAEkpPT9JPKQUfg9bTpVBSvjSxGZnnu0sx94mBEXow/tfg== X-Received: by 2002:a17:906:ce21:: with SMTP id sd1mr75020237ejb.189.1560716265576; Sun, 16 Jun 2019 13:17:45 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a50:8975:: with SMTP id f50ls1415676edf.0.gmail; Sun, 16 Jun 2019 13:17:45 -0700 (PDT) X-Received: by 2002:a50:a511:: with SMTP id y17mr94795619edb.259.1560716264996; Sun, 16 Jun 2019 13:17:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560716264; cv=none; d=google.com; s=arc-20160816; b=p9NJ77eQpBKW6FzcAuzrcAYnHdCItTLDlxRgRuQlgEPlnkaf4std3H2SQEUSioWwL8 x+fobIxyTXQnfwBCkP+s+iPKls6brNyB7qmHvVYGH8f9z9bVIV18Hmfn94O7Ou7g6oCc 1Os61gYZOP4+x62rHBSPdxz73Np6wyl660R/Ov3icD5EHhPTQWnfn4o/b6ERALP2r9Ek dqd8FAhwTndsqgT0+ZnSRkBf8euGw1fIMo9MA2dMOIXK0W6SOiVFc47mgiwTfBwU3glf S845Mthxa1jDAxcauIsMHSVpPz6huDSF+uFfCs8tW2DRuBPqKzlWhsVJGA5vkbq6BmYo 5HPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=nXLbhwHfSYhsfqCSntksAQiDs5D2JfHMNHMgNc0cefQ=; b=mgx4PTqYOnXAEQI1Kg3xFQssQ2UhitIeM4fK+oMKPvgy1rrm0xpOD804JPdAhL+BDw vQY/nAURKyiVqN7HDhNIP5XqinlEUryRMAQc/O0ok+/3klpPO+aWO9a7d3UKY/1U7nub e7yhQTeXYhtz4RrqaBEOy66uUd0cIMroy3Ogpmv3rgT7NfzoEDEgNRkio5bzR0Qgck55 AK3oFBjARneG9ZFy3WkFNIkXjDaaWqfxa18z3Gr/1I4TLKUht5BEuCK+R2Zl1bvqjini aFd6+/yU2hjgkvpARMy8Xujb9KJPm0Cu3/byZ5kfEqXKfSgf0lWRjkfbyLdoz3qzaF6P lakA== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@ashin.hu header.s=mail header.b=YeRjvyOO; spf=pass (google.com: domain of laszlo@ashin.hu designates 45.32.159.235 as permitted sender) smtp.mailfrom=laszlo@ashin.hu; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ashin.hu Received: from box.ashin.hu (box.ashin.hu. [45.32.159.235]) by gmr-mx.google.com with ESMTPS id k51si539151edd.0.2019.06.16.13.17.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Jun 2019 13:17:44 -0700 (PDT) Received-SPF: pass (google.com: domain of laszlo@ashin.hu designates 45.32.159.235 as permitted sender) client-ip=45.32.159.235; Received: from authenticated-user (box.ashin.hu [45.32.159.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by box.ashin.hu (Postfix) with ESMTPSA id 179F03E8FF; Sun, 16 Jun 2019 22:17:43 +0200 (CEST) X-Patchwork-Original-From: "'Laszlo Ashin' via swupdate" From: 'Darko Komljenovic' via swupdate To: swupdate@googlegroups.com Cc: Laszlo Ashin Subject: [swupdate] [PATCH] Remove the superfluous salt parameter Date: Sun, 16 Jun 2019 22:17:37 +0200 Message-Id: <20190616201737.16445-1-laszlo@ashin.hu> MIME-Version: 1.0 X-Original-Sender: laszlo@ashin.hu X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@ashin.hu header.s=mail header.b=YeRjvyOO; spf=pass (google.com: domain of laszlo@ashin.hu designates 45.32.159.235 as permitted sender) smtp.mailfrom=laszlo@ashin.hu; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ashin.hu X-Original-From: Laszlo Ashin Reply-To: Laszlo Ashin Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , I started working on adding mbedTLS as an alternative implementation and while running the unittest test_crypt I noticed an interesting thing. If I null out the salt argument like below then the test remains successful: ``` --- a/corelib/test/test_crypt.c +++ b/corelib/test/test_crypt.c @@ -95,6 +95,7 @@ static void test_crypt_salt(void **state) hex2bin((crypt.key = calloc(1, strlen((const char *)KEY))), KEY); hex2bin((crypt.iv = calloc(1, strlen((const char *)IV))), IV); hex2bin((crypt.salt = calloc(1, strlen((const char *)SALT))), SALT); + crypt.salt = NULL; hex2bin((crypt.crypttext = calloc(1, strlen((const char *)CRYPTTEXT))), CRYPTTEXT); do_crypt(&crypt, &CRYPTTEXT[0], &PLAINTEXT[0]); ``` Does this mean that the crypto feature doesn't even use this argument? After reading the openssl manual it looks like that salt is only an optional input for generating the key and the IV but it is not used for encryption/decryption. Once you have the key and the IV derived from the password and this optional salt, the only inputs needed for doing the actual encryption or decryption is the key and the IV. But what does the code use this salt value for? The answer can be found in corelib/swupdate_decrypt.c: ``` if (salt != NULL) { unsigned char dummy_key[EVP_MAX_KEY_LENGTH]; unsigned char dummy_iv[EVP_MAX_IV_LENGTH]; unsigned char dummy_pwd[5] = "DUMMY"; if (!EVP_BytesToKey(cipher, EVP_sha1(), salt, dummy_pwd, sizeof(dummy_pwd), 1, (unsigned char *)&dummy_key, (unsigned char *)&dummy_iv)) { ERROR("Cannot set salt."); free(dgst); return NULL; } } ``` If this salt value is not null, it gets passed to the EVP_BytesToKey function. Its manual says: > int > EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, > const unsigned char *salt, const unsigned char *data, int datal, > int count, unsigned char *key, unsigned char *iv); > > DESCRIPTION > EVP_BytesToKey() derives a key and IV from various parameters. type is > the cipher to derive the key and IV for. md is the message digest to > use. The salt parameter is used as a salt in the derivation: it should > point to an 8-byte buffer or NULL if no salt is used. data is a buffer > containing datal bytes which is used to derive the keying data. count is > the iteration count to use. The derived key and IV will be written to > key and iv, respectively. So this function produces its output to the buffers pointed to by the last two arguments. In swupdate these are dummy_key and dummy_iv and those get discarded right after the call because those are just local buffers allocated on the stack. (Not to mention we are using the hard wired value of "DUMMY" as password.) It looks like this piece of code doesn't affect the behaviour of the actual decryption algorithm, so it should be discarded. The swupdate documentation needs to be revisited as well. First, it suggests that we use the -S parameter of `openssl enc` for the encryption which is unnecessary as the command produces exactly the same result without this option. ``` $ echo abc > myfile $ openssl enc -aes-256-cbc -k mypassword -P -md sha1 salt=1182D4B32E653C85 key=F3A67C3871FEC7FF2D1772DFE0B770111A098FB53B98AEF6D69E7BFFEC90FDF1 iv =121EE144C6BE4625CA9FBD01BC386053 $ openssl enc -aes-256-cbc -in myfile -out enc1 \ -K 20FC1F26F93E4BFADB087E45CC3F30FD4749D5D9F00989EB12BFA4DFD534381C \ -iv 5389F2FCE84BFA80CC77D8C99015FD85 \ -S 768AA42EC048396D $ openssl enc -aes-256-cbc -in myfile -out enc2 \ -K 20FC1F26F93E4BFADB087E45CC3F30FD4749D5D9F00989EB12BFA4DFD534381C \ -iv 5389F2FCE84BFA80CC77D8C99015FD85 $ sha1sum enc1 enc2 6ca7157f81b056c04e452744ba85a12ab4b457f0 enc1 6ca7157f81b056c04e452744ba85a12ab4b457f0 enc2 ``` This salt parameter is only needed for the key generation from a password in the first step. Then, passing the salt parameter to swupdate in the key file as a third field is also unnecessary. The parser code of this parameter can be discarded. As an additional note, we should not reuse the same key/IV pair for encrypting files/images. See https://crypto.stackexchange.com/a/10511 Best would be to use a randomized IV for each encrypted file and image and include that IV for each ciphertext for making decryption possible. IV should be used only once but doesn't need to be kept as a secret. Only the key should be confidential. As another side note using sha1 for forming the key and IV from the password is not a best practice either. Newer version of openssl warns to use a password key derivation function like PBKDF2. Generating key and IV can be done without using passwords at all: ``` key=$(dd if=/dev/random bs=32 count=1 | xxd -ps -cols 64) iv=$(dd if=/dev/random bs=16 count=1 | xxd -ps -cols 32) ``` My current patch only copes with the superfluous salt parameter. Signed-off-by: Laszlo Ashin --- core/cpio_utils.c | 4 +--- core/util.c | 23 ++++------------------- corelib/swupdate_decrypt.c | 16 +--------------- corelib/test/test_crypt.c | 19 ++++++------------- doc/source/encrypted_images.rst | 17 +++++++---------- include/sslapi.h | 4 ++-- include/util.h | 1 - 7 files changed, 21 insertions(+), 63 deletions(-) diff --git a/core/cpio_utils.c b/core/cpio_utils.c index a464108..182ff1a 100644 --- a/core/cpio_utils.c +++ b/core/cpio_utils.c @@ -299,7 +299,6 @@ int copyfile(int fdin, void *out, unsigned int nbytes, unsigned long *offs, unsi unsigned int md_len = 0; unsigned char *aes_key = NULL; unsigned char *ivt = NULL; - unsigned char *salt; struct InputState input_state = { .fdin = fdin, @@ -348,8 +347,7 @@ int copyfile(int fdin, void *out, unsigned int nbytes, unsigned long *offs, unsi if (encrypted) { aes_key = get_aes_key(); ivt = get_aes_ivt(); - salt = get_aes_salt(); - decrypt_state.dcrypt = swupdate_DECRYPT_init(aes_key, ivt, salt); + decrypt_state.dcrypt = swupdate_DECRYPT_init(aes_key, ivt); if (!decrypt_state.dcrypt) { ERROR("decrypt initialization failure, aborting"); ret = -EFAULT; diff --git a/core/util.c b/core/util.c index ea4ad8a..3a72b29 100644 --- a/core/util.c +++ b/core/util.c @@ -30,12 +30,10 @@ /* * key is 256 bit for aes_256 * ivt is 128 bit - * salt is 64 bit */ struct decryption_key { unsigned char key[32]; unsigned char ivt[16]; - unsigned char salt[8]; }; static struct decryption_key *aes_key = NULL; @@ -416,26 +414,22 @@ int count_elem_list(struct imglist *list) int load_decryption_key(char *fname) { FILE *fp; - char *b1 = NULL, *b2 = NULL, *b3 = NULL; + char *b1 = NULL, *b2 = NULL; int ret; fp = fopen(fname, "r"); if (!fp) return -EBADF; - ret = fscanf(fp, "%ms %ms %ms", &b1, &b2, &b3); + ret = fscanf(fp, "%ms %ms", &b1, &b2); switch (ret) { case 2: - b3 = NULL; DEBUG("Read decryption key and initialization vector from file %s.", fname); break; - case 3: - DEBUG("Read decryption key, initialization vector, and salt from file %s.", fname); - break; default: if (b1 != NULL) free(b1); - fprintf(stderr, "File with decryption key is not in the format nor \n"); + fprintf(stderr, "File with decryption key is not in the format \n"); fclose(fp); return -EINVAL; } @@ -449,15 +443,12 @@ int load_decryption_key(char *fname) return -ENOMEM; ret = ascii_to_bin(aes_key->key, b1, sizeof(aes_key->key) * 2) | - ascii_to_bin(aes_key->ivt, b2, sizeof(aes_key->ivt) * 2) | - ascii_to_bin(aes_key->salt, b3, sizeof(aes_key->salt) * 2); + ascii_to_bin(aes_key->ivt, b2, sizeof(aes_key->ivt) * 2); if (b1 != NULL) free(b1); if (b2 != NULL) free(b2); - if (b3 != NULL) - free(b3); if (ret) { fprintf(stderr, "Keys are invalid\n"); @@ -479,12 +470,6 @@ unsigned char *get_aes_ivt(void) { return aes_key->ivt; } -unsigned char *get_aes_salt(void) { - if (!aes_key) - return NULL; - return aes_key->salt; -} - char** string_split(const char* in, const char d) { char** result = 0; diff --git a/corelib/swupdate_decrypt.c b/corelib/swupdate_decrypt.c index 273196e..e1043d8 100644 --- a/corelib/swupdate_decrypt.c +++ b/corelib/swupdate_decrypt.c @@ -17,7 +17,7 @@ #include "sslapi.h" #include "util.h" -struct swupdate_digest *swupdate_DECRYPT_init(unsigned char *key, unsigned char *iv, unsigned char *salt) +struct swupdate_digest *swupdate_DECRYPT_init(unsigned char *key, unsigned char *iv) { struct swupdate_digest *dgst; int ret; @@ -34,20 +34,6 @@ struct swupdate_digest *swupdate_DECRYPT_init(unsigned char *key, unsigned char return NULL; } - if (salt != NULL) { - unsigned char dummy_key[EVP_MAX_KEY_LENGTH]; - unsigned char dummy_iv[EVP_MAX_IV_LENGTH]; - unsigned char dummy_pwd[5] = "DUMMY"; - if (!EVP_BytesToKey(cipher, EVP_sha1(), salt, - dummy_pwd, sizeof(dummy_pwd), - 1, - (unsigned char *)&dummy_key, (unsigned char *)&dummy_iv)) { - ERROR("Cannot set salt."); - free(dgst); - return NULL; - } - } - #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) EVP_CIPHER_CTX_init(&dgst->ctxdec); #else diff --git a/corelib/test/test_crypt.c b/corelib/test/test_crypt.c index 84ac6ed..f3b39c6 100644 --- a/corelib/test/test_crypt.c +++ b/corelib/test/test_crypt.c @@ -28,7 +28,6 @@ struct cryptdata { unsigned char *key; unsigned char *iv; - unsigned char *salt; unsigned char *crypttext; }; @@ -44,7 +43,7 @@ static void hex2bin(unsigned char *dest, const unsigned char *source) static void do_crypt(struct cryptdata *crypt, unsigned char *CRYPTTEXT, unsigned char *PLAINTEXT) { int len; - void *dcrypt = swupdate_DECRYPT_init(crypt->key, crypt->iv, crypt->salt); + void *dcrypt = swupdate_DECRYPT_init(crypt->key, crypt->iv); assert_non_null(dcrypt); unsigned char *buffer = calloc(1, strlen((const char *)CRYPTTEXT) + EVP_MAX_BLOCK_LENGTH); @@ -59,7 +58,7 @@ static void do_crypt(struct cryptdata *crypt, unsigned char *CRYPTTEXT, unsigned free(buffer); } -static void test_crypt_nosalt(void **state) +static void test_crypt_1(void **state) { (void)state; @@ -71,7 +70,6 @@ static void test_crypt_nosalt(void **state) struct cryptdata crypt; hex2bin((crypt.key = calloc(1, strlen((const char *)KEY))), KEY); hex2bin((crypt.iv = calloc(1, strlen((const char *)IV))), IV); - crypt.salt = NULL; hex2bin((crypt.crypttext = calloc(1, strlen((const char *)CRYPTTEXT))), CRYPTTEXT); do_crypt(&crypt, &CRYPTTEXT[0], &PLAINTEXT[0]); @@ -81,27 +79,24 @@ static void test_crypt_nosalt(void **state) free(crypt.crypttext); } -static void test_crypt_salt(void **state) +static void test_crypt_2(void **state) { (void)state; unsigned char KEY[] = "69D54287F856D30B51B812FDF714556778CF31E1B104D9C68BD90C669C37D1AB"; unsigned char IV[] = "E7039ABFCA63EB8EB1D320F7918275B2"; - unsigned char SALT[] = "F75A9C11F7F63C08"; unsigned char CRYPTTEXT[] = "A17EBBB1A28459352FE3A994404E35AA"; unsigned char PLAINTEXT[] = "CRYPTTEST"; struct cryptdata crypt; hex2bin((crypt.key = calloc(1, strlen((const char *)KEY))), KEY); hex2bin((crypt.iv = calloc(1, strlen((const char *)IV))), IV); - hex2bin((crypt.salt = calloc(1, strlen((const char *)SALT))), SALT); hex2bin((crypt.crypttext = calloc(1, strlen((const char *)CRYPTTEXT))), CRYPTTEXT); do_crypt(&crypt, &CRYPTTEXT[0], &PLAINTEXT[0]); free(crypt.key); free(crypt.iv); - free(crypt.salt); free(crypt.crypttext); } @@ -116,11 +111,10 @@ static void test_crypt_failure(void **state) struct cryptdata crypt; hex2bin((crypt.key = calloc(1, strlen((const char *)KEY))), KEY); hex2bin((crypt.iv = calloc(1, strlen((const char *)IV))), IV); - crypt.salt = NULL; hex2bin((crypt.crypttext = calloc(1, strlen((const char *)CRYPTTEXT))), CRYPTTEXT); int len; - void *dcrypt = swupdate_DECRYPT_init(crypt.key, crypt.iv, crypt.salt); + void *dcrypt = swupdate_DECRYPT_init(crypt.key, crypt.iv); assert_non_null(dcrypt); unsigned char *buffer = calloc(1, strlen((const char *)CRYPTTEXT) + EVP_MAX_BLOCK_LENGTH); @@ -131,7 +125,6 @@ static void test_crypt_failure(void **state) free(crypt.key); free(crypt.iv); - free(crypt.salt); free(crypt.crypttext); } @@ -139,9 +132,9 @@ int main(void) { int error_count = 0; const struct CMUnitTest crypt_tests[] = { - cmocka_unit_test(test_crypt_nosalt), + cmocka_unit_test(test_crypt_1), cmocka_unit_test(test_crypt_failure), - cmocka_unit_test(test_crypt_salt) + cmocka_unit_test(test_crypt_2) }; error_count += cmocka_run_group_tests_name("crypt", crypt_tests, NULL, NULL); return error_count; diff --git a/doc/source/encrypted_images.rst b/doc/source/encrypted_images.rst index 113fdd3..781f484 100644 --- a/doc/source/encrypted_images.rst +++ b/doc/source/encrypted_images.rst @@ -29,28 +29,25 @@ Then, encrypt an image using this information via :: - openssl enc -aes-256-cbc -in -out -K -iv -S + openssl enc -aes-256-cbc -in -out -K -iv where ```` is the unencrypted source image file and ```` is the encrypted output image file to be referenced in ``sw-description``. ```` is the hex value part of the 2nd line of output from the key generation -command above, ```` is the hex value part of the 3rd line, and ```` is -the hex value part of the 1st line. +command above and ```` is the hex value part of the 3rd line. Then, create a key file to be supplied to SWUpdate via the `-K` switch by -putting the key, initialization vector, and salt hex values on one line +putting the key and initialization vector hex values on one line separated by whitespace, e.g., for above example values :: - B78CC67DD3DC13042A1B575184D4E16D6A09412C242CE253ACEE0F06B5AD68FC 65D793B87B6724BB27954C7664F15FF3 CE7B0488EFBF0D1B + B78CC67DD3DC13042A1B575184D4E16D6A09412C242CE253ACEE0F06B5AD68FC 65D793B87B6724BB27954C7664F15FF3 -Note that, while not recommended and for backwards compatibility, OpenSSL may be -used without salt. For disabling salt, add the ``-nosalt`` parameter to the key -generation command above. Accordingly, drop the ``-S `` parameter in the -encryption command and omit the 3rd field of the key file to be supplied to -SWUpdate being the salt. +For earlier versions of SWUpdate it was falsely noted that passing the SALT as a +3rd parameter would increase security. Key and IV are enough for maximum security, +salt doesn't add any value. Encryption of UBI volumes ------------------------- diff --git a/include/sslapi.h b/include/sslapi.h index 6f03ece..c66e005 100644 --- a/include/sslapi.h +++ b/include/sslapi.h @@ -124,7 +124,7 @@ int swupdate_HASH_compare(unsigned char *hash1, unsigned char *hash2); #endif #ifdef CONFIG_ENCRYPTED_IMAGES -struct swupdate_digest *swupdate_DECRYPT_init(unsigned char *key, unsigned char *iv, unsigned char *salt); +struct swupdate_digest *swupdate_DECRYPT_init(unsigned char *key, unsigned char *iv); int swupdate_DECRYPT_update(struct swupdate_digest *dgst, unsigned char *buf, int *outlen, unsigned char *cryptbuf, int inlen); int swupdate_DECRYPT_final(struct swupdate_digest *dgst, unsigned char *buf, @@ -135,7 +135,7 @@ void swupdate_DECRYPT_cleanup(struct swupdate_digest *dgst); * Note: macro for swupdate_DECRYPT_init is * just to avoid compiler warnings */ -#define swupdate_DECRYPT_init(key, iv, salt) (((key != NULL) | (ivt != NULL) | (salt != NULL)) ? NULL : NULL) +#define swupdate_DECRYPT_init(key, iv) (((key != NULL) | (ivt != NULL)) ? NULL : NULL) #define swupdate_DECRYPT_update(p, buf, len, cbuf, inlen) (-1) #define swupdate_DECRYPT_final(p, buf, len) (-1) #define swupdate_DECRYPT_cleanup(p) diff --git a/include/util.h b/include/util.h index 445e9f2..31c97b6 100644 --- a/include/util.h +++ b/include/util.h @@ -194,7 +194,6 @@ void free_string_array(char **nodes); int load_decryption_key(char *fname); unsigned char *get_aes_key(void); unsigned char *get_aes_ivt(void); -unsigned char *get_aes_salt(void); /* Getting global information */ int get_install_info(sourcetype *source, char *buf, size_t len);