diff options
author | Steve French <sfrench@us.ibm.com> | 2011-01-25 14:28:43 -0500 |
---|---|---|
committer | Steve French <sfrench@us.ibm.com> | 2011-01-25 14:28:43 -0500 |
commit | 93c100c0b423266c0ee28497e90fdf27c05e6b8e (patch) | |
tree | d62879296fdcb482ba4f3995e8e9177f6ec17599 /fs/cifs/link.c | |
parent | c723fdab8aa728dc2bf0da6a0de8bb9c3f588d84 (diff) |
[CIFS] Replace cifs md5 hashing functions with kernel crypto APIs
Replace remaining use of md5 hash functions local to cifs module
with kernel crypto APIs.
Remove header and source file containing those local functions.
Signed-off-by: Shirish Pargaonkar <shirishpargaonkar@gmail.com>
Reviewed-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>
Diffstat (limited to 'fs/cifs/link.c')
-rw-r--r-- | fs/cifs/link.c | 59 |
1 files changed, 50 insertions, 9 deletions
diff --git a/fs/cifs/link.c b/fs/cifs/link.c index 306769de2fb5..d3444ea6ac71 100644 --- a/fs/cifs/link.c +++ b/fs/cifs/link.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include "cifsproto.h" | 28 | #include "cifsproto.h" |
29 | #include "cifs_debug.h" | 29 | #include "cifs_debug.h" |
30 | #include "cifs_fs_sb.h" | 30 | #include "cifs_fs_sb.h" |
31 | #include "md5.h" | ||
32 | 31 | ||
33 | #define CIFS_MF_SYMLINK_LEN_OFFSET (4+1) | 32 | #define CIFS_MF_SYMLINK_LEN_OFFSET (4+1) |
34 | #define CIFS_MF_SYMLINK_MD5_OFFSET (CIFS_MF_SYMLINK_LEN_OFFSET+(4+1)) | 33 | #define CIFS_MF_SYMLINK_MD5_OFFSET (CIFS_MF_SYMLINK_LEN_OFFSET+(4+1)) |
@@ -47,6 +46,45 @@ | |||
47 | md5_hash[12], md5_hash[13], md5_hash[14], md5_hash[15] | 46 | md5_hash[12], md5_hash[13], md5_hash[14], md5_hash[15] |
48 | 47 | ||
49 | static int | 48 | static int |
49 | symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash) | ||
50 | { | ||
51 | int rc; | ||
52 | unsigned int size; | ||
53 | struct crypto_shash *md5; | ||
54 | struct sdesc *sdescmd5; | ||
55 | |||
56 | md5 = crypto_alloc_shash("md5", 0, 0); | ||
57 | if (!md5 || IS_ERR(md5)) { | ||
58 | rc = PTR_ERR(md5); | ||
59 | cERROR(1, "%s: Crypto md5 allocation error %d\n", __func__, rc); | ||
60 | return rc; | ||
61 | } | ||
62 | size = sizeof(struct shash_desc) + crypto_shash_descsize(md5); | ||
63 | sdescmd5 = kmalloc(size, GFP_KERNEL); | ||
64 | if (!sdescmd5) { | ||
65 | rc = -ENOMEM; | ||
66 | cERROR(1, "%s: Memory allocation failure\n", __func__); | ||
67 | goto symlink_hash_err; | ||
68 | } | ||
69 | sdescmd5->shash.tfm = md5; | ||
70 | sdescmd5->shash.flags = 0x0; | ||
71 | |||
72 | rc = crypto_shash_init(&sdescmd5->shash); | ||
73 | if (rc) { | ||
74 | cERROR(1, "%s: Could not init md5 shash\n", __func__); | ||
75 | goto symlink_hash_err; | ||
76 | } | ||
77 | crypto_shash_update(&sdescmd5->shash, link_str, link_len); | ||
78 | rc = crypto_shash_final(&sdescmd5->shash, md5_hash); | ||
79 | |||
80 | symlink_hash_err: | ||
81 | crypto_free_shash(md5); | ||
82 | kfree(sdescmd5); | ||
83 | |||
84 | return rc; | ||
85 | } | ||
86 | |||
87 | static int | ||
50 | CIFSParseMFSymlink(const u8 *buf, | 88 | CIFSParseMFSymlink(const u8 *buf, |
51 | unsigned int buf_len, | 89 | unsigned int buf_len, |
52 | unsigned int *_link_len, | 90 | unsigned int *_link_len, |
@@ -56,7 +94,6 @@ CIFSParseMFSymlink(const u8 *buf, | |||
56 | unsigned int link_len; | 94 | unsigned int link_len; |
57 | const char *md5_str1; | 95 | const char *md5_str1; |
58 | const char *link_str; | 96 | const char *link_str; |
59 | struct MD5Context md5_ctx; | ||
60 | u8 md5_hash[16]; | 97 | u8 md5_hash[16]; |
61 | char md5_str2[34]; | 98 | char md5_str2[34]; |
62 | 99 | ||
@@ -70,9 +107,11 @@ CIFSParseMFSymlink(const u8 *buf, | |||
70 | if (rc != 1) | 107 | if (rc != 1) |
71 | return -EINVAL; | 108 | return -EINVAL; |
72 | 109 | ||
73 | cifs_MD5_init(&md5_ctx); | 110 | rc = symlink_hash(link_len, link_str, md5_hash); |
74 | cifs_MD5_update(&md5_ctx, (const u8 *)link_str, link_len); | 111 | if (rc) { |
75 | cifs_MD5_final(md5_hash, &md5_ctx); | 112 | cFYI(1, "%s: MD5 hash failure: %d\n", __func__, rc); |
113 | return rc; | ||
114 | } | ||
76 | 115 | ||
77 | snprintf(md5_str2, sizeof(md5_str2), | 116 | snprintf(md5_str2, sizeof(md5_str2), |
78 | CIFS_MF_SYMLINK_MD5_FORMAT, | 117 | CIFS_MF_SYMLINK_MD5_FORMAT, |
@@ -94,9 +133,9 @@ CIFSParseMFSymlink(const u8 *buf, | |||
94 | static int | 133 | static int |
95 | CIFSFormatMFSymlink(u8 *buf, unsigned int buf_len, const char *link_str) | 134 | CIFSFormatMFSymlink(u8 *buf, unsigned int buf_len, const char *link_str) |
96 | { | 135 | { |
136 | int rc; | ||
97 | unsigned int link_len; | 137 | unsigned int link_len; |
98 | unsigned int ofs; | 138 | unsigned int ofs; |
99 | struct MD5Context md5_ctx; | ||
100 | u8 md5_hash[16]; | 139 | u8 md5_hash[16]; |
101 | 140 | ||
102 | if (buf_len != CIFS_MF_SYMLINK_FILE_SIZE) | 141 | if (buf_len != CIFS_MF_SYMLINK_FILE_SIZE) |
@@ -107,9 +146,11 @@ CIFSFormatMFSymlink(u8 *buf, unsigned int buf_len, const char *link_str) | |||
107 | if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN) | 146 | if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN) |
108 | return -ENAMETOOLONG; | 147 | return -ENAMETOOLONG; |
109 | 148 | ||
110 | cifs_MD5_init(&md5_ctx); | 149 | rc = symlink_hash(link_len, link_str, md5_hash); |
111 | cifs_MD5_update(&md5_ctx, (const u8 *)link_str, link_len); | 150 | if (rc) { |
112 | cifs_MD5_final(md5_hash, &md5_ctx); | 151 | cFYI(1, "%s: MD5 hash failure: %d\n", __func__, rc); |
152 | return rc; | ||
153 | } | ||
113 | 154 | ||
114 | snprintf(buf, buf_len, | 155 | snprintf(buf, buf_len, |
115 | CIFS_MF_SYMLINK_LEN_FORMAT CIFS_MF_SYMLINK_MD5_FORMAT, | 156 | CIFS_MF_SYMLINK_LEN_FORMAT CIFS_MF_SYMLINK_MD5_FORMAT, |