diff options
author | Eric Biggers <ebiggers@google.com> | 2016-09-30 01:46:18 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2016-09-30 01:46:18 -0400 |
commit | 55be3145d174c04c44f1996eca8eb3a4476b1063 (patch) | |
tree | 3a9d01b2de2ad95061aa108f49bf832516091482 /fs | |
parent | cc91542ac8f29d8446ef59234796b95f0fbce09a (diff) | |
download | talos-obmc-linux-55be3145d174c04c44f1996eca8eb3a4476b1063.tar.gz talos-obmc-linux-55be3145d174c04c44f1996eca8eb3a4476b1063.zip |
fscrypto: use standard macros to compute length of fname ciphertext
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/crypto/fname.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c index 90697c70c23b..9a28133ac3b8 100644 --- a/fs/crypto/fname.c +++ b/fs/crypto/fname.c @@ -14,11 +14,6 @@ #include <linux/ratelimit.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 * @req: The asynchronous cipher request context @@ -60,10 +55,9 @@ static int fname_encrypt(struct inode *inode, if (iname->len <= 0 || iname->len > lim) return -EIO; - ciphertext_len = (iname->len < FS_CRYPTO_BLOCK_SIZE) ? - FS_CRYPTO_BLOCK_SIZE : iname->len; - ciphertext_len = size_round_up(ciphertext_len, padding); - ciphertext_len = (ciphertext_len > lim) ? lim : ciphertext_len; + ciphertext_len = max(iname->len, (u32)FS_CRYPTO_BLOCK_SIZE); + ciphertext_len = round_up(ciphertext_len, padding); + ciphertext_len = min(ciphertext_len, lim); if (ciphertext_len <= sizeof(buf)) { workbuf = buf; @@ -233,9 +227,8 @@ u32 fscrypt_fname_encrypted_size(struct inode *inode, u32 ilen) if (ci) padding = 4 << (ci->ci_flags & FS_POLICY_FLAGS_PAD_MASK); - if (ilen < FS_CRYPTO_BLOCK_SIZE) - ilen = FS_CRYPTO_BLOCK_SIZE; - return size_round_up(ilen, padding); + ilen = max(ilen, (u32)FS_CRYPTO_BLOCK_SIZE); + return round_up(ilen, padding); } EXPORT_SYMBOL(fscrypt_fname_encrypted_size); |