mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 2.6.18] crypto/api:  optional cleanup functionalitiy
@ 2006-10-31  2:16 Era Scarecrow
  2006-10-31  3:06 ` Randy Dunlap
  2006-10-31  8:21 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Era Scarecrow @ 2006-10-31  2:16 UTC (permalink / raw)
  To: jmorris; +Cc: linux-kernel

From: Ryan Cecil <rtcvb32@coffey.com>

 Adds the function call cleanup to all crypto/cipher/digest calls. Certain
select ciphers require a larger dynamic memory allocation, which isn't cleaned
when closed. The cleanup code will be called to clean those up before being
released.

 Signed-off-by: Ryan Cecil <rtcvb32@coffey.com>
---
 I made this patch primarily because i was developing a cipher and it would
crash the UML/kernel. But when it did memory allocation using tcrypt
it sucked all the memory out. This fixes that problem.

diff -ur linux-2.6.18/crypto/api.c linux-2.6.18-modified/crypto/api.c
--- linux-2.6.18/crypto/api.c   2006-09-19 23:42:06.000000000 -0400
+++ linux-2.6.18-modified/crypto/api.c  2006-10-08 22:27:37.000000000 -0400
@@ -211,10 +211,26 @@
 {
        struct crypto_alg *alg;
        int size;
+       void (*misc_cleanup)(struct crypto_tfm *)=NULL;

        if (unlikely(!tfm))
                return;

+       switch(crypto_tfm_alg_type(tfm))
+       {
+               case CRYPTO_ALG_TYPE_CIPHER:
+               misc_cleanup = tfm->__crt_alg->cra_u.cipher.cia_cleanup;
+               break;
+               case CRYPTO_ALG_TYPE_DIGEST:
+               misc_cleanup = tfm->__crt_alg->cra_u.digest.dia_cleanup;
+               break;
+               case CRYPTO_ALG_TYPE_COMPRESS:
+               misc_cleanup = tfm->__crt_alg->cra_u.compress.coa_cleanup;
+               break;
+       }
+       if (misc_cleanup)       //only a select few need this.
+               (*misc_cleanup)(tfm);
+
        alg = tfm->__crt_alg;
        size = sizeof(*tfm) + alg->cra_ctxsize;

diff -ur linux-2.6.18/include/linux/crypto.h
linux-2.6.18-modified/include/linux/crypto.h
--- linux-2.6.18/include/linux/crypto.h 2006-09-19 23:42:06.000000000 -0400
+++ linux-2.6.18-modified/include/linux/crypto.h        2006-10-08
22:17:26.000000000 -0400
@@ -83,6 +83,7 @@
                          unsigned int keylen, u32 *flags);
        void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
        void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
+       void (*cia_cleanup)(struct crypto_tfm *tfm);

        unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc,
                                        u8 *dst, const u8 *src,
@@ -104,6 +105,8 @@
        void (*dia_update)(struct crypto_tfm *tfm, const u8 *data,
                           unsigned int len);
        void (*dia_final)(struct crypto_tfm *tfm, u8 *out);
+       void (*dia_cleanup)(struct crypto_tfm *tfm);
+
        int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key,
                          unsigned int keylen, u32 *flags);
 };
@@ -113,6 +116,7 @@
                            unsigned int slen, u8 *dst, unsigned int *dlen);
        int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src,
                              unsigned int slen, u8 *dst, unsigned int *dlen);
+       void (*coa_cleanup)(struct crypto_tfm *tfm);
 };

 #define cra_cipher     cra_u.cipher





 
____________________________________________________________________________________
Access over 1 million songs - Yahoo! Music Unlimited 
(http://music.yahoo.com/unlimited)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2.6.18] crypto/api:  optional cleanup functionalitiy
  2006-10-31  2:16 [PATCH 2.6.18] crypto/api: optional cleanup functionalitiy Era Scarecrow
@ 2006-10-31  3:06 ` Randy Dunlap
  2006-10-31  8:21 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Randy Dunlap @ 2006-10-31  3:06 UTC (permalink / raw)
  To: rtcvb32; +Cc: jmorris, linux-kernel

On Mon, 30 Oct 2006 18:16:55 -0800 (PST) Era Scarecrow wrote:

> From: Ryan Cecil <rtcvb32@coffey.com>
> 
>  Adds the function call cleanup to all crypto/cipher/digest calls. Certain
> select ciphers require a larger dynamic memory allocation, which isn't cleaned
> when closed. The cleanup code will be called to clean those up before being
> released.
> 
>  Signed-off-by: Ryan Cecil <rtcvb32@coffey.com>
> ---
>  I made this patch primarily because i was developing a cipher and it would
> crash the UML/kernel. But when it did memory allocation using tcrypt
> it sucked all the memory out. This fixes that problem.

Please fix the coding style as indicated below.
Thanks.

> diff -ur linux-2.6.18/crypto/api.c linux-2.6.18-modified/crypto/api.c
> --- linux-2.6.18/crypto/api.c   2006-09-19 23:42:06.000000000 -0400
> +++ linux-2.6.18-modified/crypto/api.c  2006-10-08 22:27:37.000000000 -0400
> @@ -211,10 +211,26 @@
>  {
>         struct crypto_alg *alg;
>         int size;
> +       void (*misc_cleanup)(struct crypto_tfm *)=NULL;

s/=/ = /

> 
>         if (unlikely(!tfm))
>                 return;
> 
> +       switch(crypto_tfm_alg_type(tfm))
> +       {

Align 'case' with 'switch'.  Space after 'switch'.

> +               case CRYPTO_ALG_TYPE_CIPHER:
> +               misc_cleanup = tfm->__crt_alg->cra_u.cipher.cia_cleanup;
> +               break;
> +               case CRYPTO_ALG_TYPE_DIGEST:
> +               misc_cleanup = tfm->__crt_alg->cra_u.digest.dia_cleanup;
> +               break;
> +               case CRYPTO_ALG_TYPE_COMPRESS:
> +               misc_cleanup = tfm->__crt_alg->cra_u.compress.coa_cleanup;
> +               break;
> +       }
> +       if (misc_cleanup)       //only a select few need this.

Use /* ... */ instead of // style comments.

> +               (*misc_cleanup)(tfm);
> +
>         alg = tfm->__crt_alg;
>         size = sizeof(*tfm) + alg->cra_ctxsize;
> 
> diff -ur linux-2.6.18/include/linux/crypto.h
> linux-2.6.18-modified/include/linux/crypto.h
> --- linux-2.6.18/include/linux/crypto.h 2006-09-19 23:42:06.000000000 -0400
> +++ linux-2.6.18-modified/include/linux/crypto.h        2006-10-08
> 22:17:26.000000000 -0400
> @@ -83,6 +83,7 @@
>                           unsigned int keylen, u32 *flags);
>         void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
>         void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
> +       void (*cia_cleanup)(struct crypto_tfm *tfm);
> 
>         unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc,
>                                         u8 *dst, const u8 *src,
> @@ -104,6 +105,8 @@
>         void (*dia_update)(struct crypto_tfm *tfm, const u8 *data,
>                            unsigned int len);
>         void (*dia_final)(struct crypto_tfm *tfm, u8 *out);
> +       void (*dia_cleanup)(struct crypto_tfm *tfm);
> +
>         int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key,
>                           unsigned int keylen, u32 *flags);
>  };
> @@ -113,6 +116,7 @@
>                             unsigned int slen, u8 *dst, unsigned int *dlen);
>         int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src,
>                               unsigned int slen, u8 *dst, unsigned int *dlen);
> +       void (*coa_cleanup)(struct crypto_tfm *tfm);
>  };
> 
>  #define cra_cipher     cra_u.cipher

---
~Randy

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2.6.18] crypto/api:  optional cleanup functionalitiy
  2006-10-31  2:16 [PATCH 2.6.18] crypto/api: optional cleanup functionalitiy Era Scarecrow
  2006-10-31  3:06 ` Randy Dunlap
@ 2006-10-31  8:21 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2006-10-31  8:21 UTC (permalink / raw)
  To: rtcvb32; +Cc: jmorris, linux-kernel

Era Scarecrow <rtcvb32@yahoo.com> wrote:
> From: Ryan Cecil <rtcvb32@coffey.com>
> 
> Adds the function call cleanup to all crypto/cipher/digest calls. Certain
> select ciphers require a larger dynamic memory allocation, which isn't cleaned
> when closed. The cleanup code will be called to clean those up before being
> released.
> 
> Signed-off-by: Ryan Cecil <rtcvb32@coffey.com>

We have the cra_exit hook which already does this.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-10-31  8:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-31  2:16 [PATCH 2.6.18] crypto/api: optional cleanup functionalitiy Era Scarecrow
2006-10-31  3:06 ` Randy Dunlap
2006-10-31  8:21 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®