[PATCH] uml: fix sleep length bug
[pandora-kernel.git] / crypto / api.c
index 1e4692a..2e84d4b 100644 (file)
@@ -226,17 +226,18 @@ static int crypto_init_flags(struct crypto_tfm *tfm, u32 flags)
                
        case CRYPTO_ALG_TYPE_COMPRESS:
                return crypto_init_compress_flags(tfm, flags);
-       
-       default:
-               break;
        }
        
-       BUG();
-       return -EINVAL;
+       return 0;
 }
 
 static int crypto_init_ops(struct crypto_tfm *tfm)
 {
+       const struct crypto_type *type = tfm->__crt_alg->cra_type;
+
+       if (type)
+               return type->init(tfm);
+
        switch (crypto_tfm_alg_type(tfm)) {
        case CRYPTO_ALG_TYPE_CIPHER:
                return crypto_init_cipher_ops(tfm);
@@ -257,6 +258,14 @@ static int crypto_init_ops(struct crypto_tfm *tfm)
 
 static void crypto_exit_ops(struct crypto_tfm *tfm)
 {
+       const struct crypto_type *type = tfm->__crt_alg->cra_type;
+
+       if (type) {
+               if (type->exit)
+                       type->exit(tfm);
+               return;
+       }
+
        switch (crypto_tfm_alg_type(tfm)) {
        case CRYPTO_ALG_TYPE_CIPHER:
                crypto_exit_cipher_ops(tfm);
@@ -278,26 +287,31 @@ static void crypto_exit_ops(struct crypto_tfm *tfm)
 
 static unsigned int crypto_ctxsize(struct crypto_alg *alg, int flags)
 {
+       const struct crypto_type *type = alg->cra_type;
        unsigned int len;
 
+       len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1);
+       if (type)
+               return len + type->ctxsize(alg);
+
        switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
        default:
                BUG();
 
        case CRYPTO_ALG_TYPE_CIPHER:
-               len = crypto_cipher_ctxsize(alg, flags);
+               len += crypto_cipher_ctxsize(alg, flags);
                break;
                
        case CRYPTO_ALG_TYPE_DIGEST:
-               len = crypto_digest_ctxsize(alg, flags);
+               len += crypto_digest_ctxsize(alg, flags);
                break;
                
        case CRYPTO_ALG_TYPE_COMPRESS:
-               len = crypto_compress_ctxsize(alg, flags);
+               len += crypto_compress_ctxsize(alg, flags);
                break;
        }
 
-       return len + (alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1));
+       return len;
 }
 
 void crypto_shoot_alg(struct crypto_alg *alg)
@@ -372,6 +386,66 @@ struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
        return tfm;
 }
 
+/*
+ *     crypto_alloc_base - Locate algorithm and allocate transform
+ *     @alg_name: Name of algorithm
+ *     @type: Type of algorithm
+ *     @mask: Mask for type comparison
+ *
+ *     crypto_alloc_base() will first attempt to locate an already loaded
+ *     algorithm.  If that fails and the kernel supports dynamically loadable
+ *     modules, it will then attempt to load a module of the same name or
+ *     alias.  If that fails it will send a query to any loaded crypto manager
+ *     to construct an algorithm on the fly.  A refcount is grabbed on the
+ *     algorithm which is then associated with the new transform.
+ *
+ *     The returned transform is of a non-determinate type.  Most people
+ *     should use one of the more specific allocation functions such as
+ *     crypto_alloc_blkcipher.
+ *
+ *     In case of error the return value is an error pointer.
+ */
+struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask)
+{
+       struct crypto_tfm *tfm;
+       int err;
+
+       for (;;) {
+               struct crypto_alg *alg;
+
+               alg = crypto_alg_mod_lookup(alg_name, type, mask);
+               err = PTR_ERR(alg);
+               tfm = ERR_PTR(err);
+               if (IS_ERR(alg))
+                       goto err;
+
+               tfm = __crypto_alloc_tfm(alg, 0);
+               if (!IS_ERR(tfm))
+                       break;
+
+               crypto_mod_put(alg);
+               err = PTR_ERR(tfm);
+
+err:
+               if (err != -EAGAIN)
+                       break;
+               if (signal_pending(current)) {
+                       err = -EINTR;
+                       break;
+               }
+       };
+
+       return tfm;
+}
+EXPORT_SYMBOL_GPL(crypto_alloc_base);
+/*
+ *     crypto_free_tfm - Free crypto transform
+ *     @tfm: Transform to free
+ *
+ *     crypto_free_tfm() frees up the transform and any associated resources,
+ *     then drops the refcount on the associated algorithm.
+ */
 void crypto_free_tfm(struct crypto_tfm *tfm)
 {
        struct crypto_alg *alg;
@@ -408,3 +482,17 @@ int crypto_alg_available(const char *name, u32 flags)
 EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
 EXPORT_SYMBOL_GPL(crypto_free_tfm);
 EXPORT_SYMBOL_GPL(crypto_alg_available);
+
+int crypto_has_alg(const char *name, u32 type, u32 mask)
+{
+       int ret = 0;
+       struct crypto_alg *alg = crypto_alg_mod_lookup(name, type, mask);
+       
+       if (!IS_ERR(alg)) {
+               crypto_mod_put(alg);
+               ret = 1;
+       }
+       
+       return ret;
+}
+EXPORT_SYMBOL_GPL(crypto_has_alg);