diff options
| author | Rasmus Villemoes <linux@rasmusvillemoes.dk> | 2016-09-20 19:17:24 -0400 |
|---|---|---|
| committer | Tyler Hicks <tyhicks@canonical.com> | 2017-11-04 18:16:41 -0400 |
| commit | abbae6d560c1d562c5c0d10785469734784ef961 (patch) | |
| tree | abf569213a03de67189195351d2edbf89f90c0e4 | |
| parent | 0996b67df6c1354f2df09c33ac652c37e2e2471f (diff) | |
ecryptfs: remove private bin2hex implementation
Calling sprintf in a loop is not very efficient, and in any case, we
already have an implementation of bin-to-hex conversion in lib/ which
we might as well use.
Note that ecryptfs_to_hex used to nul-terminate the destination (and
the kernel doc was wrong about the required output size), while
bin2hex doesn't. [All but one user of ecryptfs_to_hex explicitly
nul-terminates the result anyway.]
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
[tyhicks: Include <linux/kernel.h> in ecryptfs_kernel.h]
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
| -rw-r--r-- | fs/ecryptfs/crypto.c | 15 | ||||
| -rw-r--r-- | fs/ecryptfs/ecryptfs_kernel.h | 9 |
2 files changed, 8 insertions, 16 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index e5e29f8c920b..7acd57da4f14 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
| @@ -42,21 +42,6 @@ | |||
| 42 | #define ENCRYPT 1 | 42 | #define ENCRYPT 1 |
| 43 | 43 | ||
| 44 | /** | 44 | /** |
| 45 | * ecryptfs_to_hex | ||
| 46 | * @dst: Buffer to take hex character representation of contents of | ||
| 47 | * src; must be at least of size (src_size * 2) | ||
| 48 | * @src: Buffer to be converted to a hex string representation | ||
| 49 | * @src_size: number of bytes to convert | ||
| 50 | */ | ||
| 51 | void ecryptfs_to_hex(char *dst, char *src, size_t src_size) | ||
| 52 | { | ||
| 53 | int x; | ||
| 54 | |||
| 55 | for (x = 0; x < src_size; x++) | ||
| 56 | sprintf(&dst[x * 2], "%.2x", (unsigned char)src[x]); | ||
| 57 | } | ||
| 58 | |||
| 59 | /** | ||
| 60 | * ecryptfs_from_hex | 45 | * ecryptfs_from_hex |
| 61 | * @dst: Buffer to take the bytes from src hex; must be at least of | 46 | * @dst: Buffer to take the bytes from src hex; must be at least of |
| 62 | * size (src_size / 2) | 47 | * size (src_size / 2) |
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h index 3fbc0ff79699..e74cb2a0b299 100644 --- a/fs/ecryptfs/ecryptfs_kernel.h +++ b/fs/ecryptfs/ecryptfs_kernel.h | |||
| @@ -31,6 +31,7 @@ | |||
| 31 | #include <crypto/skcipher.h> | 31 | #include <crypto/skcipher.h> |
| 32 | #include <keys/user-type.h> | 32 | #include <keys/user-type.h> |
| 33 | #include <keys/encrypted-type.h> | 33 | #include <keys/encrypted-type.h> |
| 34 | #include <linux/kernel.h> | ||
| 34 | #include <linux/fs.h> | 35 | #include <linux/fs.h> |
| 35 | #include <linux/fs_stack.h> | 36 | #include <linux/fs_stack.h> |
| 36 | #include <linux/namei.h> | 37 | #include <linux/namei.h> |
| @@ -51,7 +52,13 @@ | |||
| 51 | #define ECRYPTFS_XATTR_NAME "user.ecryptfs" | 52 | #define ECRYPTFS_XATTR_NAME "user.ecryptfs" |
| 52 | 53 | ||
| 53 | void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok); | 54 | void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok); |
| 54 | extern void ecryptfs_to_hex(char *dst, char *src, size_t src_size); | 55 | static inline void |
| 56 | ecryptfs_to_hex(char *dst, char *src, size_t src_size) | ||
| 57 | { | ||
| 58 | char *end = bin2hex(dst, src, src_size); | ||
| 59 | *end = '\0'; | ||
| 60 | } | ||
| 61 | |||
| 55 | extern void ecryptfs_from_hex(char *dst, char *src, int dst_size); | 62 | extern void ecryptfs_from_hex(char *dst, char *src, int dst_size); |
| 56 | 63 | ||
| 57 | struct ecryptfs_key_record { | 64 | struct ecryptfs_key_record { |
