Commit 55be3145 authored by Eric Biggers's avatar Eric Biggers Committed by Theodore Ts'o

fscrypto: use standard macros to compute length of fname ciphertext

Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent cc91542a
...@@ -14,11 +14,6 @@ ...@@ -14,11 +14,6 @@
#include <linux/ratelimit.h> #include <linux/ratelimit.h>
#include <linux/fscrypto.h> #include <linux/fscrypto.h>
static u32 size_round_up(size_t size, size_t blksize)
{
return ((size + blksize - 1) / blksize) * blksize;
}
/** /**
* fname_crypt_complete() - completion callback for filename crypto * fname_crypt_complete() - completion callback for filename crypto
* @req: The asynchronous cipher request context * @req: The asynchronous cipher request context
...@@ -60,10 +55,9 @@ static int fname_encrypt(struct inode *inode, ...@@ -60,10 +55,9 @@ static int fname_encrypt(struct inode *inode,
if (iname->len <= 0 || iname->len > lim) if (iname->len <= 0 || iname->len > lim)
return -EIO; return -EIO;
ciphertext_len = (iname->len < FS_CRYPTO_BLOCK_SIZE) ? ciphertext_len = max(iname->len, (u32)FS_CRYPTO_BLOCK_SIZE);
FS_CRYPTO_BLOCK_SIZE : iname->len; ciphertext_len = round_up(ciphertext_len, padding);
ciphertext_len = size_round_up(ciphertext_len, padding); ciphertext_len = min(ciphertext_len, lim);
ciphertext_len = (ciphertext_len > lim) ? lim : ciphertext_len;
if (ciphertext_len <= sizeof(buf)) { if (ciphertext_len <= sizeof(buf)) {
workbuf = buf; workbuf = buf;
...@@ -233,9 +227,8 @@ u32 fscrypt_fname_encrypted_size(struct inode *inode, u32 ilen) ...@@ -233,9 +227,8 @@ u32 fscrypt_fname_encrypted_size(struct inode *inode, u32 ilen)
if (ci) if (ci)
padding = 4 << (ci->ci_flags & FS_POLICY_FLAGS_PAD_MASK); padding = 4 << (ci->ci_flags & FS_POLICY_FLAGS_PAD_MASK);
if (ilen < FS_CRYPTO_BLOCK_SIZE) ilen = max(ilen, (u32)FS_CRYPTO_BLOCK_SIZE);
ilen = FS_CRYPTO_BLOCK_SIZE; return round_up(ilen, padding);
return size_round_up(ilen, padding);
} }
EXPORT_SYMBOL(fscrypt_fname_encrypted_size); EXPORT_SYMBOL(fscrypt_fname_encrypted_size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment