Merge branch 'acpi-pnp'
[firefly-linux-kernel-4.4.55.git] / crypto / echainiv.c
index 62a817faec8c4d47858ea1b542ca8647ff0c42ef..b6e43dc6135653eddb3e31f9659d54bc774bc6d1 100644 (file)
@@ -187,29 +187,6 @@ static int echainiv_decrypt(struct aead_request *req)
        return crypto_aead_decrypt(subreq);
 }
 
-static int echainiv_encrypt_first(struct aead_request *req)
-{
-       struct crypto_aead *geniv = crypto_aead_reqtfm(req);
-       struct echainiv_ctx *ctx = crypto_aead_ctx(geniv);
-       int err = 0;
-
-       spin_lock_bh(&ctx->geniv.lock);
-       if (geniv->encrypt != echainiv_encrypt_first)
-               goto unlock;
-
-       geniv->encrypt = echainiv_encrypt;
-       err = crypto_rng_get_bytes(crypto_default_rng, ctx->salt,
-                                  crypto_aead_ivsize(geniv));
-
-unlock:
-       spin_unlock_bh(&ctx->geniv.lock);
-
-       if (err)
-               return err;
-
-       return echainiv_encrypt(req);
-}
-
 static int echainiv_init(struct crypto_tfm *tfm)
 {
        struct crypto_aead *geniv = __crypto_aead_cast(tfm);
@@ -220,6 +197,16 @@ static int echainiv_init(struct crypto_tfm *tfm)
 
        crypto_aead_set_reqsize(geniv, sizeof(struct aead_request));
 
+       err = crypto_get_default_rng();
+       if (err)
+               goto out;
+
+       err = crypto_rng_get_bytes(crypto_default_rng, ctx->salt,
+                                  crypto_aead_ivsize(geniv));
+       crypto_put_default_rng();
+       if (err)
+               goto out;
+
        ctx->null = crypto_get_default_null_skcipher();
        err = PTR_ERR(ctx->null);
        if (IS_ERR(ctx->null))
@@ -272,7 +259,7 @@ static int echainiv_aead_create(struct crypto_template *tmpl,
            inst->alg.ivsize > MAX_IV_SIZE)
                goto free_inst;
 
-       inst->alg.encrypt = echainiv_encrypt_first;
+       inst->alg.encrypt = echainiv_encrypt;
        inst->alg.decrypt = echainiv_decrypt;
 
        inst->alg.base.cra_init = echainiv_init;
@@ -295,35 +282,14 @@ free_inst:
        goto out;
 }
 
-static int echainiv_create(struct crypto_template *tmpl, struct rtattr **tb)
-{
-       int err;
-
-       err = crypto_get_default_rng();
-       if (err)
-               goto out;
-
-       err = echainiv_aead_create(tmpl, tb);
-       if (err)
-               goto put_rng;
-
-out:
-       return err;
-
-put_rng:
-       crypto_put_default_rng();
-       goto out;
-}
-
 static void echainiv_free(struct crypto_instance *inst)
 {
        aead_geniv_free(aead_instance(inst));
-       crypto_put_default_rng();
 }
 
 static struct crypto_template echainiv_tmpl = {
        .name = "echainiv",
-       .create = echainiv_create,
+       .create = echainiv_aead_create,
        .free = echainiv_free,
        .module = THIS_MODULE,
 };