From d7ddcc076899951adee5cb5e9ef06860eafb117c Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Tue, 20 Nov 2018 16:08:38 +0100 Subject: [PATCH] Reformat AF implementation, use secure allocation for buffer. --- lib/luks1/af.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/luks1/af.c b/lib/luks1/af.c index 3d7cf0b6..f7a17ea5 100644 --- a/lib/luks1/af.c +++ b/lib/luks1/af.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #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,7 +60,8 @@ 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) @@ -101,7 +101,6 @@ 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(const char *src, char *dst, size_t blocksize, unsigned int blocknumbers, const char *hash) { @@ -109,24 +108,26 @@ int AF_split(const char *src, char *dst, size_t blocksize, char *bufblock; 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