Commit 2b53313a authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

staging: lustre: remove almost all crypto layer wrappers

Almost all of these are just a straight function name rename, so fix
them all up to call the crypto layer properly, no need for a #define to
hide things.

Cc: Peng Tao <tao.peng@emc.com>
Cc: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a7f24447
...@@ -100,74 +100,18 @@ static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt, ...@@ -100,74 +100,18 @@ static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
#endif #endif
/* add a lustre compatible layer for crypto API */ /* add a lustre compatible layer for crypto API */
#include <linux/crypto.h> #include <linux/crypto.h>
#define ll_crypto_hash crypto_hash
#define ll_crypto_cipher crypto_blkcipher
#define ll_crypto_alloc_hash(name, type, mask) crypto_alloc_hash(name, type, mask)
#define ll_crypto_hash_setkey(tfm, key, keylen) crypto_hash_setkey(tfm, key, keylen)
#define ll_crypto_hash_init(desc) crypto_hash_init(desc)
#define ll_crypto_hash_update(desc, sl, bytes) crypto_hash_update(desc, sl, bytes)
#define ll_crypto_hash_final(desc, out) crypto_hash_final(desc, out)
#define ll_crypto_blkcipher_setkey(tfm, key, keylen) \
crypto_blkcipher_setkey(tfm, key, keylen)
#define ll_crypto_blkcipher_set_iv(tfm, src, len) \
crypto_blkcipher_set_iv(tfm, src, len)
#define ll_crypto_blkcipher_get_iv(tfm, dst, len) \
crypto_blkcipher_get_iv(tfm, dst, len)
#define ll_crypto_blkcipher_encrypt(desc, dst, src, bytes) \
crypto_blkcipher_encrypt(desc, dst, src, bytes)
#define ll_crypto_blkcipher_decrypt(desc, dst, src, bytes) \
crypto_blkcipher_decrypt(desc, dst, src, bytes)
#define ll_crypto_blkcipher_encrypt_iv(desc, dst, src, bytes) \
crypto_blkcipher_encrypt_iv(desc, dst, src, bytes)
#define ll_crypto_blkcipher_decrypt_iv(desc, dst, src, bytes) \
crypto_blkcipher_decrypt_iv(desc, dst, src, bytes)
static inline static inline
struct ll_crypto_cipher *ll_crypto_alloc_blkcipher(const char *name, struct crypto_blkcipher *ll_crypto_alloc_blkcipher(const char *name,
u32 type, u32 mask) u32 type, u32 mask)
{ {
struct ll_crypto_cipher *rtn = crypto_alloc_blkcipher(name, type, mask); struct crypto_blkcipher *rtn = crypto_alloc_blkcipher(name, type, mask);
return (rtn == NULL ? ERR_PTR(-ENOMEM) : rtn); return (rtn == NULL ? ERR_PTR(-ENOMEM) : rtn);
} }
static inline int ll_crypto_hmac(struct ll_crypto_hash *tfm,
u8 *key, unsigned int *keylen,
struct scatterlist *sg,
unsigned int size, u8 *result)
{
struct hash_desc desc;
int rv;
desc.tfm = tfm;
desc.flags = 0;
rv = crypto_hash_setkey(desc.tfm, key, *keylen);
if (rv) {
CERROR("failed to hash setkey: %d\n", rv);
return rv;
}
return crypto_hash_digest(&desc, sg, size, result);
}
static inline
unsigned int ll_crypto_tfm_alg_max_keysize(struct crypto_blkcipher *tfm)
{
return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.max_keysize;
}
static inline
unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
{
return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
}
#define ll_crypto_hash_blocksize(tfm) crypto_hash_blocksize(tfm)
#define ll_crypto_hash_digestsize(tfm) crypto_hash_digestsize(tfm)
#define ll_crypto_blkcipher_ivsize(tfm) crypto_blkcipher_ivsize(tfm)
#define ll_crypto_blkcipher_blocksize(tfm) crypto_blkcipher_blocksize(tfm)
#define ll_crypto_free_hash(tfm) crypto_free_hash(tfm)
#define ll_crypto_free_blkcipher(tfm) crypto_free_blkcipher(tfm)
#define ll_vfs_rmdir(dir,entry,mnt) vfs_rmdir(dir,entry) #define ll_vfs_rmdir(dir,entry,mnt) vfs_rmdir(dir,entry)
#define ll_vfs_mkdir(inode,dir,mnt,mode) vfs_mkdir(inode,dir,mode) #define ll_vfs_mkdir(inode,dir,mnt,mode) vfs_mkdir(inode,dir,mode)
#define ll_vfs_link(old,mnt,dir,new,mnt1) vfs_link(old,dir,new) #define ll_vfs_link(old,mnt,dir,new,mnt1) vfs_link(old,dir,new)
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/crypto.h>
#include <obd_class.h> #include <obd_class.h>
#include <lustre_debug.h> #include <lustre_debug.h>
...@@ -76,6 +77,12 @@ EXPORT_SYMBOL(capa_list); ...@@ -76,6 +77,12 @@ EXPORT_SYMBOL(capa_list);
EXPORT_SYMBOL(capa_lock); EXPORT_SYMBOL(capa_lock);
EXPORT_SYMBOL(capa_count); EXPORT_SYMBOL(capa_count);
static inline
unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
{
return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
}
struct hlist_head *init_capa_hash(void) struct hlist_head *init_capa_hash(void)
{ {
struct hlist_head *hash; struct hlist_head *hash;
...@@ -234,9 +241,26 @@ struct obd_capa *capa_lookup(struct hlist_head *hash, struct lustre_capa *capa, ...@@ -234,9 +241,26 @@ struct obd_capa *capa_lookup(struct hlist_head *hash, struct lustre_capa *capa,
} }
EXPORT_SYMBOL(capa_lookup); EXPORT_SYMBOL(capa_lookup);
static inline int ll_crypto_hmac(struct crypto_hash *tfm,
u8 *key, unsigned int *keylen,
struct scatterlist *sg,
unsigned int size, u8 *result)
{
struct hash_desc desc;
int rv;
desc.tfm = tfm;
desc.flags = 0;
rv = crypto_hash_setkey(desc.tfm, key, *keylen);
if (rv) {
CERROR("failed to hash setkey: %d\n", rv);
return rv;
}
return crypto_hash_digest(&desc, sg, size, result);
}
int capa_hmac(__u8 *hmac, struct lustre_capa *capa, __u8 *key) int capa_hmac(__u8 *hmac, struct lustre_capa *capa, __u8 *key)
{ {
struct ll_crypto_hash *tfm; struct crypto_hash *tfm;
struct capa_hmac_alg *alg; struct capa_hmac_alg *alg;
int keylen; int keylen;
struct scatterlist sl; struct scatterlist sl;
...@@ -248,7 +272,7 @@ int capa_hmac(__u8 *hmac, struct lustre_capa *capa, __u8 *key) ...@@ -248,7 +272,7 @@ int capa_hmac(__u8 *hmac, struct lustre_capa *capa, __u8 *key)
alg = &capa_hmac_algs[capa_alg(capa)]; alg = &capa_hmac_algs[capa_alg(capa)];
tfm = ll_crypto_alloc_hash(alg->ha_name, 0, 0); tfm = crypto_alloc_hash(alg->ha_name, 0, 0);
if (!tfm) { if (!tfm) {
CERROR("crypto_alloc_tfm failed, check whether your kernel" CERROR("crypto_alloc_tfm failed, check whether your kernel"
"has crypto support!\n"); "has crypto support!\n");
...@@ -261,7 +285,7 @@ int capa_hmac(__u8 *hmac, struct lustre_capa *capa, __u8 *key) ...@@ -261,7 +285,7 @@ int capa_hmac(__u8 *hmac, struct lustre_capa *capa, __u8 *key)
(unsigned long)(capa) % PAGE_CACHE_SIZE); (unsigned long)(capa) % PAGE_CACHE_SIZE);
ll_crypto_hmac(tfm, key, &keylen, &sl, sl.length, hmac); ll_crypto_hmac(tfm, key, &keylen, &sl, sl.length, hmac);
ll_crypto_free_hash(tfm); crypto_free_hash(tfm);
return 0; return 0;
} }
...@@ -269,7 +293,7 @@ EXPORT_SYMBOL(capa_hmac); ...@@ -269,7 +293,7 @@ EXPORT_SYMBOL(capa_hmac);
int capa_encrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen) int capa_encrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
{ {
struct ll_crypto_cipher *tfm; struct crypto_blkcipher *tfm;
struct scatterlist sd; struct scatterlist sd;
struct scatterlist ss; struct scatterlist ss;
struct blkcipher_desc desc; struct blkcipher_desc desc;
...@@ -291,7 +315,7 @@ int capa_encrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen) ...@@ -291,7 +315,7 @@ int capa_encrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
GOTO(out, rc = -EINVAL); GOTO(out, rc = -EINVAL);
} }
rc = ll_crypto_blkcipher_setkey(tfm, key, min); rc = crypto_blkcipher_setkey(tfm, key, min);
if (rc) { if (rc) {
CERROR("failed to setting key for aes\n"); CERROR("failed to setting key for aes\n");
GOTO(out, rc); GOTO(out, rc);
...@@ -305,21 +329,21 @@ int capa_encrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen) ...@@ -305,21 +329,21 @@ int capa_encrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
desc.tfm = tfm; desc.tfm = tfm;
desc.info = NULL; desc.info = NULL;
desc.flags = 0; desc.flags = 0;
rc = ll_crypto_blkcipher_encrypt(&desc, &sd, &ss, 16); rc = crypto_blkcipher_encrypt(&desc, &sd, &ss, 16);
if (rc) { if (rc) {
CERROR("failed to encrypt for aes\n"); CERROR("failed to encrypt for aes\n");
GOTO(out, rc); GOTO(out, rc);
} }
out: out:
ll_crypto_free_blkcipher(tfm); crypto_free_blkcipher(tfm);
return rc; return rc;
} }
EXPORT_SYMBOL(capa_encrypt_id); EXPORT_SYMBOL(capa_encrypt_id);
int capa_decrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen) int capa_decrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
{ {
struct ll_crypto_cipher *tfm; struct crypto_blkcipher *tfm;
struct scatterlist sd; struct scatterlist sd;
struct scatterlist ss; struct scatterlist ss;
struct blkcipher_desc desc; struct blkcipher_desc desc;
...@@ -341,7 +365,7 @@ int capa_decrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen) ...@@ -341,7 +365,7 @@ int capa_decrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
GOTO(out, rc = -EINVAL); GOTO(out, rc = -EINVAL);
} }
rc = ll_crypto_blkcipher_setkey(tfm, key, min); rc = crypto_blkcipher_setkey(tfm, key, min);
if (rc) { if (rc) {
CERROR("failed to setting key for aes\n"); CERROR("failed to setting key for aes\n");
GOTO(out, rc); GOTO(out, rc);
...@@ -356,14 +380,14 @@ int capa_decrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen) ...@@ -356,14 +380,14 @@ int capa_decrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
desc.tfm = tfm; desc.tfm = tfm;
desc.info = NULL; desc.info = NULL;
desc.flags = 0; desc.flags = 0;
rc = ll_crypto_blkcipher_decrypt(&desc, &sd, &ss, 16); rc = crypto_blkcipher_decrypt(&desc, &sd, &ss, 16);
if (rc) { if (rc) {
CERROR("failed to decrypt for aes\n"); CERROR("failed to decrypt for aes\n");
GOTO(out, rc); GOTO(out, rc);
} }
out: out:
ll_crypto_free_blkcipher(tfm); crypto_free_blkcipher(tfm);
return rc; return rc;
} }
EXPORT_SYMBOL(capa_decrypt_id); EXPORT_SYMBOL(capa_decrypt_id);
......
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