Skip to content

Commit

Permalink
ecryptfs: remove private bin2hex implementation
Browse files Browse the repository at this point in the history
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 <[email protected]>
[tyhicks: Include <linux/kernel.h> in ecryptfs_kernel.h]
Signed-off-by: Tyler Hicks <[email protected]>
  • Loading branch information
Villemoes authored and tyhicks committed Nov 4, 2017
1 parent 0996b67 commit abbae6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
15 changes: 0 additions & 15 deletions fs/ecryptfs/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,6 @@
#define DECRYPT 0
#define ENCRYPT 1

/**
* ecryptfs_to_hex
* @dst: Buffer to take hex character representation of contents of
* src; must be at least of size (src_size * 2)
* @src: Buffer to be converted to a hex string representation
* @src_size: number of bytes to convert
*/
void ecryptfs_to_hex(char *dst, char *src, size_t src_size)
{
int x;

for (x = 0; x < src_size; x++)
sprintf(&dst[x * 2], "%.2x", (unsigned char)src[x]);
}

/**
* ecryptfs_from_hex
* @dst: Buffer to take the bytes from src hex; must be at least of
Expand Down
9 changes: 8 additions & 1 deletion fs/ecryptfs/ecryptfs_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <crypto/skcipher.h>
#include <keys/user-type.h>
#include <keys/encrypted-type.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/fs_stack.h>
#include <linux/namei.h>
Expand All @@ -51,7 +52,13 @@
#define ECRYPTFS_XATTR_NAME "user.ecryptfs"

void ecryptfs_dump_auth_tok(struct ecryptfs_auth_tok *auth_tok);
extern void ecryptfs_to_hex(char *dst, char *src, size_t src_size);
static inline void
ecryptfs_to_hex(char *dst, char *src, size_t src_size)
{
char *end = bin2hex(dst, src, src_size);
*end = '\0';
}

extern void ecryptfs_from_hex(char *dst, char *src, int dst_size);

struct ecryptfs_key_record {
Expand Down

0 comments on commit abbae6d

Please sign in to comment.