X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Fluks1%2Faf.c;h=a781376b5f8a13cc60a95d2b6d6028ac6a4aaefa;hb=322b430a2589cdc7985e98a14ec12322b91c9d5e;hp=9d64915b10e0768a0d262e460f2957734e6a002c;hpb=7835b365a730ebc721460166cce9a03cabde4677;p=platform%2Fupstream%2Fcryptsetup.git diff --git a/lib/luks1/af.c b/lib/luks1/af.c index 9d64915..a781376 100644 --- a/lib/luks1/af.c +++ b/lib/luks1/af.c @@ -1,15 +1,16 @@ /* * AFsplitter - Anti forensic information splitter * - * Copyright (C) 2004, Clemens Fruhwirth - * Copyright (C) 2009-2011, Red Hat, Inc. All rights reserved. + * Copyright (C) 2004 Clemens Fruhwirth + * Copyright (C) 2009-2020 Red Hat, Inc. All rights reserved. * * AFsplitter diffuses information over a large stripe of data, - * therefor supporting secure data destruction. + * therefore supporting secure data destruction. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License - * version 2 as published by the Free Software Foundation. + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -24,9 +25,7 @@ #include #include #include -#include #include -#include "crypto_backend.h" #include "internal.h" #include "af.h" @@ -34,7 +33,7 @@ static void XORblock(const char *src1, const char *src2, char *dst, size_t n) { size_t j; - for(j = 0; j < n; ++j) + for (j = 0; j < n; j++) dst[j] = src1[j] ^ src2[j]; } @@ -45,7 +44,7 @@ static int hash_buf(const char *src, char *dst, uint32_t iv, char *iv_char = (char *)&iv; int r; - iv = htonl(iv); + iv = be32_to_cpu(iv); if (crypt_hash_init(&hd, hash_name)) return -EINVAL; @@ -61,29 +60,38 @@ out: return r; } -/* diffuse: Information spreading over the whole dataset with +/* + * diffuse: Information spreading over the whole dataset with * the help of hash function. */ - static int diffuse(char *src, char *dst, size_t size, const char *hash_name) { - unsigned int digest_size = crypt_hash_size(hash_name); + int r, hash_size = crypt_hash_size(hash_name); + unsigned int digest_size; unsigned int i, blocks, padding; + if (hash_size <= 0) + return -EINVAL; + digest_size = hash_size; + blocks = size / digest_size; padding = size % digest_size; - for (i = 0; i < blocks; i++) - if(hash_buf(src + digest_size * i, + for (i = 0; i < blocks; i++) { + r = hash_buf(src + digest_size * i, dst + digest_size * i, - i, (size_t)digest_size, hash_name)) - return 1; + i, (size_t)digest_size, hash_name); + if (r < 0) + return r; + } - if(padding) - if(hash_buf(src + digest_size * i, + if (padding) { + r = hash_buf(src + digest_size * i, dst + digest_size * i, - i, (size_t)padding, hash_name)) - return 1; + i, (size_t)padding, hash_name); + if (r < 0) + return r; + } return 0; } @@ -93,52 +101,70 @@ static int diffuse(char *src, char *dst, size_t size, const char *hash_name) * blocknumbers. The same blocksize and blocknumbers values * must be supplied to AF_merge to recover information. */ - -int AF_split(char *src, char *dst, size_t blocksize, - unsigned int blocknumbers, const char *hash) +int AF_split(struct crypt_device *ctx, const char *src, char *dst, + size_t blocksize, unsigned int blocknumbers, const char *hash) { unsigned int i; char *bufblock; - int r = -EINVAL; + 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 */ - for(i=0; i