Merge tag 'for-f2fs-4.6' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk...
[platform/kernel/linux-exynos.git] / fs / crypto / keyinfo.c
index cb61842..06f5aa4 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/random.h>
 #include <linux/scatterlist.h>
 #include <uapi/linux/keyctl.h>
-#include <crypto/hash.h>
 #include <linux/fscrypto.h>
 
 static void derive_crypt_complete(struct crypto_async_request *req, int rc)
@@ -40,45 +39,42 @@ static int derive_key_aes(u8 deriving_key[FS_AES_128_ECB_KEY_SIZE],
                                u8 derived_key[FS_AES_256_XTS_KEY_SIZE])
 {
        int res = 0;
-       struct ablkcipher_request *req = NULL;
+       struct skcipher_request *req = NULL;
        DECLARE_FS_COMPLETION_RESULT(ecr);
        struct scatterlist src_sg, dst_sg;
-       struct crypto_ablkcipher *tfm = crypto_alloc_ablkcipher("ecb(aes)", 0,
-                                                               0);
+       struct crypto_skcipher *tfm = crypto_alloc_skcipher("ecb(aes)", 0, 0);
 
        if (IS_ERR(tfm)) {
                res = PTR_ERR(tfm);
                tfm = NULL;
                goto out;
        }
-       crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
-       req = ablkcipher_request_alloc(tfm, GFP_NOFS);
+       crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
+       req = skcipher_request_alloc(tfm, GFP_NOFS);
        if (!req) {
                res = -ENOMEM;
                goto out;
        }
-       ablkcipher_request_set_callback(req,
+       skcipher_request_set_callback(req,
                        CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
                        derive_crypt_complete, &ecr);
-       res = crypto_ablkcipher_setkey(tfm, deriving_key,
+       res = crypto_skcipher_setkey(tfm, deriving_key,
                                        FS_AES_128_ECB_KEY_SIZE);
        if (res < 0)
                goto out;
 
        sg_init_one(&src_sg, source_key, FS_AES_256_XTS_KEY_SIZE);
        sg_init_one(&dst_sg, derived_key, FS_AES_256_XTS_KEY_SIZE);
-       ablkcipher_request_set_crypt(req, &src_sg, &dst_sg,
+       skcipher_request_set_crypt(req, &src_sg, &dst_sg,
                                        FS_AES_256_XTS_KEY_SIZE, NULL);
-       res = crypto_ablkcipher_encrypt(req);
+       res = crypto_skcipher_encrypt(req);
        if (res == -EINPROGRESS || res == -EBUSY) {
                wait_for_completion(&ecr.completion);
                res = ecr.res;
        }
 out:
-       if (req)
-               ablkcipher_request_free(req);
-       if (tfm)
-               crypto_free_ablkcipher(tfm);
+       skcipher_request_free(req);
+       crypto_free_skcipher(tfm);
        return res;
 }
 
@@ -87,9 +83,8 @@ static void put_crypt_info(struct fscrypt_info *ci)
        if (!ci)
                return;
 
-       if (ci->ci_keyring_key)
-               key_put(ci->ci_keyring_key);
-       crypto_free_ablkcipher(ci->ci_ctfm);
+       key_put(ci->ci_keyring_key);
+       crypto_free_skcipher(ci->ci_ctfm);
        kmem_cache_free(fscrypt_info_cachep, ci);
 }
 
@@ -102,7 +97,7 @@ int get_crypt_info(struct inode *inode)
        struct fscrypt_key *master_key;
        struct fscrypt_context ctx;
        const struct user_key_payload *ukp;
-       struct crypto_ablkcipher *ctfm;
+       struct crypto_skcipher *ctfm;
        const char *cipher_str;
        u8 raw_key[FS_MAX_KEY_SIZE];
        u8 mode;
@@ -215,7 +210,7 @@ retry:
        if (res)
                goto out;
 got_key:
-       ctfm = crypto_alloc_ablkcipher(cipher_str, 0, 0);
+       ctfm = crypto_alloc_skcipher(cipher_str, 0, 0);
        if (!ctfm || IS_ERR(ctfm)) {
                res = ctfm ? PTR_ERR(ctfm) : -ENOMEM;
                printk(KERN_DEBUG
@@ -224,10 +219,9 @@ got_key:
                goto out;
        }
        crypt_info->ci_ctfm = ctfm;
-       crypto_ablkcipher_clear_flags(ctfm, ~0);
-       crypto_tfm_set_flags(crypto_ablkcipher_tfm(ctfm),
-                                       CRYPTO_TFM_REQ_WEAK_KEY);
-       res = crypto_ablkcipher_setkey(ctfm, raw_key, fscrypt_key_size(mode));
+       crypto_skcipher_clear_flags(ctfm, ~0);
+       crypto_skcipher_set_flags(ctfm, CRYPTO_TFM_REQ_WEAK_KEY);
+       res = crypto_skcipher_setkey(ctfm, raw_key, fscrypt_key_size(mode));
        if (res)
                goto out;