"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/crypt_plain.c" between
cryptsetup-2.0.6.tar.xz and cryptsetup-2.1.0.tar.xz

About: cryptsetup is a utility used to conveniently setup disk encryption based on the dm-crypt kernel module. These include plain dm-crypt volumes, LUKS volumes, loop-AES and TrueCrypt compatible format.

crypt_plain.c  (cryptsetup-2.0.6.tar.xz):crypt_plain.c  (cryptsetup-2.1.0.tar.xz)
/* /*
* cryptsetup plain device helper functions * cryptsetup plain device helper functions
* *
* Copyright (C) 2004, Jana Saout <jana@saout.de> * Copyright (C) 2004 Jana Saout <jana@saout.de>
* Copyright (C) 2010-2018 Red Hat, Inc. All rights reserved. * Copyright (C) 2010-2019 Red Hat, Inc. All rights reserved.
* Copyright (C) 2010-2018, Milan Broz * Copyright (C) 2010-2019 Milan Broz
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
skipping to change at line 67 skipping to change at line 67
key += len; key += len;
key_size -= len; key_size -= len;
} }
crypt_hash_destroy(md); crypt_hash_destroy(md);
return r; return r;
} }
#define PLAIN_HASH_LEN_MAX 256 #define PLAIN_HASH_LEN_MAX 256
int crypt_plain_hash(struct crypt_device *ctx __attribute__((unused)), int crypt_plain_hash(struct crypt_device *cd,
const char *hash_name, const char *hash_name,
char *key, size_t key_size, char *key, size_t key_size,
const char *passphrase, size_t passphrase_size) const char *passphrase, size_t passphrase_size)
{ {
char hash_name_buf[PLAIN_HASH_LEN_MAX], *s; char hash_name_buf[PLAIN_HASH_LEN_MAX], *s;
size_t hash_size, pad_size; size_t hash_size, pad_size;
int r; int r;
log_dbg("Plain: hashing passphrase using %s.", hash_name); log_dbg(cd, "Plain: hashing passphrase using %s.", hash_name);
if (strlen(hash_name) >= PLAIN_HASH_LEN_MAX) if (strlen(hash_name) >= PLAIN_HASH_LEN_MAX)
return -EINVAL; return -EINVAL;
strncpy(hash_name_buf, hash_name, PLAIN_HASH_LEN_MAX); strncpy(hash_name_buf, hash_name, PLAIN_HASH_LEN_MAX);
hash_name_buf[PLAIN_HASH_LEN_MAX - 1] = '\0'; hash_name_buf[PLAIN_HASH_LEN_MAX - 1] = '\0';
/* hash[:hash_length] */ /* hash[:hash_length] */
if ((s = strchr(hash_name_buf, ':'))) { if ((s = strchr(hash_name_buf, ':'))) {
*s = '\0'; *s = '\0';
s++; s++;
if (!*s || sscanf(s, "%zd", &hash_size) != 1) { if (!*s || sscanf(s, "%zd", &hash_size) != 1) {
log_dbg("Hash length is not a number"); log_dbg(cd, "Hash length is not a number");
return -EINVAL; return -EINVAL;
} }
if (hash_size > key_size) { if (hash_size > key_size) {
log_dbg("Hash length %zd > key length %zd", log_dbg(cd, "Hash length %zd > key length %zd",
hash_size, key_size); hash_size, key_size);
return -EINVAL; return -EINVAL;
} }
pad_size = key_size - hash_size; pad_size = key_size - hash_size;
} else { } else {
hash_size = key_size; hash_size = key_size;
pad_size = 0; pad_size = 0;
} }
/* No hash, copy passphrase directly */ /* No hash, copy passphrase directly */
if (!strcmp(hash_name_buf, "plain")) { if (!strcmp(hash_name_buf, "plain")) {
if (passphrase_size < hash_size) { if (passphrase_size < hash_size) {
log_dbg("Too short plain passphrase."); log_dbg(cd, "Too short plain passphrase.");
return -EINVAL; return -EINVAL;
} }
memcpy(key, passphrase, hash_size); memcpy(key, passphrase, hash_size);
r = 0; r = 0;
} else } else
r = hash(hash_name_buf, hash_size, key, passphrase_size, passphra se); r = hash(hash_name_buf, hash_size, key, passphrase_size, passphra se);
if (r == 0 && pad_size) if (r == 0 && pad_size)
memset(key + hash_size, 0, pad_size); memset(key + hash_size, 0, pad_size);
 End of changes. 6 change blocks. 
8 lines changed or deleted 8 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)