pandora: defconfig: update
[pandora-kernel.git] / crypto / algif_hash.c
index 7a70b07..3aa8890 100644 (file)
@@ -34,11 +34,6 @@ struct hash_ctx {
        struct ahash_request req;
 };
 
-struct algif_hash_tfm {
-       struct crypto_ahash *hash;
-       bool has_key;
-};
-
 static int hash_sendmsg(struct kiocb *unused, struct socket *sock,
                        struct msghdr *msg, size_t ignored)
 {
@@ -56,7 +51,8 @@ static int hash_sendmsg(struct kiocb *unused, struct socket *sock,
 
        lock_sock(sk);
        if (!ctx->more) {
-               err = crypto_ahash_init(&ctx->req);
+               err = af_alg_wait_for_completion(crypto_ahash_init(&ctx->req),
+                                               &ctx->completion);
                if (err)
                        goto unlock;
        }
@@ -136,6 +132,7 @@ static ssize_t hash_sendpage(struct socket *sock, struct page *page,
        } else {
                if (!ctx->more) {
                        err = crypto_ahash_init(&ctx->req);
+                       err = af_alg_wait_for_completion(err, &ctx->completion);
                        if (err)
                                goto unlock;
                }
@@ -253,23 +250,24 @@ static struct proto_ops algif_hash_ops = {
 
 static int hash_check_key(struct socket *sock)
 {
-       int err;
+       int err = 0;
        struct sock *psk;
        struct alg_sock *pask;
-       struct algif_hash_tfm *tfm;
+       struct crypto_ahash *tfm;
        struct sock *sk = sock->sk;
        struct alg_sock *ask = alg_sk(sk);
 
+       lock_sock(sk);
        if (ask->refcnt)
-               return 0;
+               goto unlock_child;
 
        psk = ask->parent;
        pask = alg_sk(ask->parent);
        tfm = pask->private;
 
        err = -ENOKEY;
-       lock_sock(psk);
-       if (!tfm->has_key)
+       lock_sock_nested(psk, SINGLE_DEPTH_NESTING);
+       if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
                goto unlock;
 
        if (!pask->refcnt++)
@@ -282,6 +280,8 @@ static int hash_check_key(struct socket *sock)
 
 unlock:
        release_sock(psk);
+unlock_child:
+       release_sock(sk);
 
        return err;
 }
@@ -358,44 +358,20 @@ static struct proto_ops algif_hash_ops_nokey = {
 
 static void *hash_bind(const char *name, u32 type, u32 mask)
 {
-       struct algif_hash_tfm *tfm;
-       struct crypto_ahash *hash;
-
-       tfm = kzalloc(sizeof(*tfm), GFP_KERNEL);
-       if (!tfm)
-               return ERR_PTR(-ENOMEM);
-
-       hash = crypto_alloc_ahash(name, type, mask);
-       if (IS_ERR(hash)) {
-               kfree(tfm);
-               return ERR_CAST(hash);
-       }
-
-       tfm->hash = hash;
-
-       return tfm;
+       return crypto_alloc_ahash(name, type, mask);
 }
 
 static void hash_release(void *private)
 {
-       struct algif_hash_tfm *tfm = private;
-
-       crypto_free_ahash(tfm->hash);
-       kfree(tfm);
+       crypto_free_ahash(private);
 }
 
 static int hash_setkey(void *private, const u8 *key, unsigned int keylen)
 {
-       struct algif_hash_tfm *tfm = private;
-       int err;
-
-       err = crypto_ahash_setkey(tfm->hash, key, keylen);
-       tfm->has_key = !err;
-
-       return err;
+       return crypto_ahash_setkey(private, key, keylen);
 }
 
-static void hash_sock_destruct_common(struct sock *sk)
+static void hash_sock_destruct(struct sock *sk)
 {
        struct alg_sock *ask = alg_sk(sk);
        struct hash_ctx *ctx = ask->private;
@@ -403,40 +379,16 @@ static void hash_sock_destruct_common(struct sock *sk)
        sock_kfree_s(sk, ctx->result,
                     crypto_ahash_digestsize(crypto_ahash_reqtfm(&ctx->req)));
        sock_kfree_s(sk, ctx, ctx->len);
-}
-
-static void hash_sock_destruct(struct sock *sk)
-{
-       hash_sock_destruct_common(sk);
        af_alg_release_parent(sk);
 }
 
-static void hash_release_parent_nokey(struct sock *sk)
+static int hash_accept_parent_nokey(void *private, struct sock *sk)
 {
+       struct crypto_ahash *tfm = private;
        struct alg_sock *ask = alg_sk(sk);
-
-       if (!ask->refcnt) {
-               sock_put(ask->parent);
-               return;
-       }
-
-       af_alg_release_parent(sk);
-}
-
-static void hash_sock_destruct_nokey(struct sock *sk)
-{
-       hash_sock_destruct_common(sk);
-       hash_release_parent_nokey(sk);
-}
-
-static int hash_accept_parent_common(void *private, struct sock *sk)
-{
        struct hash_ctx *ctx;
-       struct alg_sock *ask = alg_sk(sk);
-       struct algif_hash_tfm *tfm = private;
-       struct crypto_ahash *hash = tfm->hash;
-       unsigned len = sizeof(*ctx) + crypto_ahash_reqsize(hash);
-       unsigned ds = crypto_ahash_digestsize(hash);
+       unsigned int len = sizeof(*ctx) + crypto_ahash_reqsize(tfm);
+       unsigned ds = crypto_ahash_digestsize(tfm);
 
        ctx = sock_kmalloc(sk, len, GFP_KERNEL);
        if (!ctx)
@@ -456,7 +408,7 @@ static int hash_accept_parent_common(void *private, struct sock *sk)
 
        ask->private = ctx;
 
-       ahash_request_set_tfm(&ctx->req, hash);
+       ahash_request_set_tfm(&ctx->req, tfm);
        ahash_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_BACKLOG,
                                   af_alg_complete, &ctx->completion);
 
@@ -467,26 +419,12 @@ static int hash_accept_parent_common(void *private, struct sock *sk)
 
 static int hash_accept_parent(void *private, struct sock *sk)
 {
-       struct algif_hash_tfm *tfm = private;
+       struct crypto_ahash *tfm = private;
 
-       if (!tfm->has_key && crypto_ahash_has_setkey(tfm->hash))
+       if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
                return -ENOKEY;
 
-       return hash_accept_parent_common(private, sk);
-}
-
-static int hash_accept_parent_nokey(void *private, struct sock *sk)
-{
-       int err;
-
-       err = hash_accept_parent_common(private, sk);
-       if (err)
-               goto out;
-
-       sk->sk_destruct = hash_sock_destruct_nokey;
-
-out:
-       return err;
+       return hash_accept_parent_nokey(private, sk);
 }
 
 static const struct af_alg_type algif_type_hash = {