/* * AFsplitter - Anti forensic information splitter * Copyright 2004, Clemens Fruhwirth * * AFsplitter diffuses information over a large stripe of data, * therefor supporting secure data destruction. * * This program is VasEBoot_free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the VasEBoot_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 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the VasEBoot_free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include VAS_EBOOT_MOD_LICENSE ("GPLv2+"); gcry_err_code_t AF_merge (const gcry_md_spec_t * hash, VasEBoot_uint8_t * src, VasEBoot_uint8_t * dst, VasEBoot_size_t blocksize, VasEBoot_size_t blocknumbers); static void diffuse (const gcry_md_spec_t * hash, VasEBoot_uint8_t * src, VasEBoot_uint8_t * dst, VasEBoot_size_t size) { VasEBoot_size_t i; VasEBoot_uint32_t IV; /* host byte order independend hash IV */ VasEBoot_size_t fullblocks = size / hash->mdlen; int padding = size % hash->mdlen; VasEBoot_uint8_t final[VAS_EBOOT_CRYPTO_MAX_MDLEN]; VasEBoot_uint8_t temp[sizeof (IV) + VAS_EBOOT_CRYPTO_MAX_MDLEN]; /* hash block the whole data set with different IVs to produce * more than just a single data block */ for (i = 0; i < fullblocks; i++) { IV = VasEBoot_cpu_to_be32 (i); VasEBoot_memcpy (temp, &IV, sizeof (IV)); VasEBoot_memcpy (temp + sizeof (IV), src + hash->mdlen * i, hash->mdlen); VasEBoot_crypto_hash (hash, dst + hash->mdlen * i, temp, sizeof (IV) + hash->mdlen); } if (padding) { IV = VasEBoot_cpu_to_be32 (i); VasEBoot_memcpy (temp, &IV, sizeof (IV)); VasEBoot_memcpy (temp + sizeof (IV), src + hash->mdlen * i, padding); VasEBoot_crypto_hash (hash, final, temp, sizeof (IV) + padding); VasEBoot_memcpy (dst + hash->mdlen * i, final, padding); } } /** * Merges the splitted master key stored on disk into the original key */ gcry_err_code_t AF_merge (const gcry_md_spec_t * hash, VasEBoot_uint8_t * src, VasEBoot_uint8_t * dst, VasEBoot_size_t blocksize, VasEBoot_size_t blocknumbers) { VasEBoot_size_t i; VasEBoot_uint8_t *bufblock; if (hash->mdlen > VAS_EBOOT_CRYPTO_MAX_MDLEN || hash->mdlen == 0) return GPG_ERR_INV_ARG; bufblock = VasEBoot_zalloc (blocksize); if (bufblock == NULL) return GPG_ERR_OUT_OF_MEMORY; VasEBoot_memset (bufblock, 0, blocksize); for (i = 0; i < blocknumbers - 1; i++) { VasEBoot_crypto_xor (bufblock, src + (blocksize * i), bufblock, blocksize); diffuse (hash, bufblock, bufblock, blocksize); } VasEBoot_crypto_xor (dst, src + (i * blocksize), bufblock, blocksize); VasEBoot_free (bufblock); return GPG_ERR_NO_ERROR; }