"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/luks1/af.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.

af.c  (cryptsetup-2.0.6.tar.xz):af.c  (cryptsetup-2.1.0.tar.xz)
/* /*
* AFsplitter - Anti forensic information splitter * AFsplitter - Anti forensic information splitter
* *
* Copyright (C) 2004, Clemens Fruhwirth <clemens@endorphin.org> * Copyright (C) 2004 Clemens Fruhwirth <clemens@endorphin.org>
* Copyright (C) 2009-2018, Red Hat, Inc. All rights reserved. * Copyright (C) 2009-2019 Red Hat, Inc. All rights reserved.
* *
* AFsplitter diffuses information over a large stripe of data, * AFsplitter diffuses information over a large stripe of data,
* therefore supporting secure data destruction. * therefore supporting secure data destruction.
* *
* 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,
skipping to change at line 28 skipping to change at line 28
* GNU Library General Public License for more details. * GNU Library General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <netinet/in.h>
#include <errno.h> #include <errno.h>
#include "internal.h" #include "internal.h"
#include "af.h" #include "af.h"
static void XORblock(const char *src1, const char *src2, char *dst, size_t n) static void XORblock(const char *src1, const char *src2, char *dst, size_t n)
{ {
size_t j; size_t j;
for(j = 0; j < n; ++j) for (j = 0; j < n; j++)
dst[j] = src1[j] ^ src2[j]; dst[j] = src1[j] ^ src2[j];
} }
static int hash_buf(const char *src, char *dst, uint32_t iv, static int hash_buf(const char *src, char *dst, uint32_t iv,
size_t len, const char *hash_name) size_t len, const char *hash_name)
{ {
struct crypt_hash *hd = NULL; struct crypt_hash *hd = NULL;
char *iv_char = (char *)&iv; char *iv_char = (char *)&iv;
int r; int r;
iv = htonl(iv); iv = be32_to_cpu(iv);
if (crypt_hash_init(&hd, hash_name)) if (crypt_hash_init(&hd, hash_name))
return -EINVAL; return -EINVAL;
if ((r = crypt_hash_write(hd, iv_char, sizeof(uint32_t)))) if ((r = crypt_hash_write(hd, iv_char, sizeof(uint32_t))))
goto out; goto out;
if ((r = crypt_hash_write(hd, src, len))) if ((r = crypt_hash_write(hd, src, len)))
goto out; goto out;
r = crypt_hash_final(hd, dst, len); r = crypt_hash_final(hd, dst, len);
out: out:
crypt_hash_destroy(hd); crypt_hash_destroy(hd);
return r; return r;
} }
/* diffuse: Information spreading over the whole dataset with /*
* diffuse: Information spreading over the whole dataset with
* the help of hash function. * the help of hash function.
*/ */
static int diffuse(char *src, char *dst, size_t size, const char *hash_name) static int diffuse(char *src, char *dst, size_t size, const char *hash_name)
{ {
int r, hash_size = crypt_hash_size(hash_name); int r, hash_size = crypt_hash_size(hash_name);
unsigned int digest_size; unsigned int digest_size;
unsigned int i, blocks, padding; unsigned int i, blocks, padding;
if (hash_size <= 0) if (hash_size <= 0)
return -EINVAL; return -EINVAL;
skipping to change at line 104 skipping to change at line 104
} }
return 0; return 0;
} }
/* /*
* Information splitting. The amount of data is multiplied by * Information splitting. The amount of data is multiplied by
* blocknumbers. The same blocksize and blocknumbers values * blocknumbers. The same blocksize and blocknumbers values
* must be supplied to AF_merge to recover information. * must be supplied to AF_merge to recover information.
*/ */
int AF_split(struct crypt_device *ctx, const char *src, char *dst,
int AF_split(const char *src, char *dst, size_t blocksize, size_t blocksize, unsigned int blocknumbers, const char *hash)
unsigned int blocknumbers, const char *hash)
{ {
unsigned int i; unsigned int i;
char *bufblock; char *bufblock;
int r; int r;
if((bufblock = calloc(blocksize, 1)) == NULL) return -ENOMEM; bufblock = crypt_safe_alloc(blocksize);
if (!bufblock)
return -ENOMEM;
/* process everything except the last block */ /* process everything except the last block */
for(i=0; i<blocknumbers-1; i++) { for (i = 0; i < blocknumbers - 1; i++) {
r = crypt_random_get(NULL, dst+(blocksize*i), blocksize, CRYPT_RN r = crypt_random_get(ctx, dst + blocksize * i, blocksize, CRYPT_R
D_NORMAL); ND_NORMAL);
if (r < 0) if (r < 0)
goto out; goto out;
XORblock(dst+(blocksize*i),bufblock,bufblock,blocksize); XORblock(dst + blocksize * i, bufblock, bufblock, blocksize);
r = diffuse(bufblock, bufblock, blocksize, hash); r = diffuse(bufblock, bufblock, blocksize, hash);
if (r < 0) if (r < 0)
goto out; goto out;
} }
/* the last block is computed */ /* the last block is computed */
XORblock(src,bufblock,dst+(i*blocksize),blocksize); XORblock(src, bufblock, dst + blocksize * i, blocksize);
r = 0; r = 0;
out: out:
free(bufblock); crypt_safe_free(bufblock);
return r; return r;
} }
int AF_merge(const char *src, char *dst, size_t blocksize, int AF_merge(struct crypt_device *ctx __attribute__((unused)), const char *src,
unsigned int blocknumbers, const char *hash) char *dst,
size_t blocksize, unsigned int blocknumbers, const char *hash)
{ {
unsigned int i; unsigned int i;
char *bufblock; char *bufblock;
int r; int r;
if((bufblock = calloc(blocksize, 1)) == NULL) bufblock = crypt_safe_alloc(blocksize);
if (!bufblock)
return -ENOMEM; return -ENOMEM;
memset(bufblock,0,blocksize); for(i = 0; i < blocknumbers - 1; i++) {
for(i=0; i<blocknumbers-1; i++) { XORblock(src + blocksize * i, bufblock, bufblock, blocksize);
XORblock(src+(blocksize*i),bufblock,bufblock,blocksize);
r = diffuse(bufblock, bufblock, blocksize, hash); r = diffuse(bufblock, bufblock, blocksize, hash);
if (r < 0) if (r < 0)
goto out; goto out;
} }
XORblock(src + blocksize * i, bufblock, dst, blocksize); XORblock(src + blocksize * i, bufblock, dst, blocksize);
r = 0; r = 0;
out: out:
free(bufblock); crypt_safe_free(bufblock);
return r; return r;
} }
/* Size of final split data including sector alignment */ /* Size of final split data including sector alignment */
size_t AF_split_sectors(size_t blocksize, unsigned int blocknumbers) size_t AF_split_sectors(size_t blocksize, unsigned int blocknumbers)
{ {
size_t af_size; size_t af_size;
/* data material * stripes */ /* data material * stripes */
af_size = blocksize * blocknumbers; af_size = blocksize * blocknumbers;
 End of changes. 15 change blocks. 
23 lines changed or deleted 25 lines changed or added

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