Re: [PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-31 Thread Steffen Klassert
On Fri, Jan 26, 2018 at 11:43:28PM +0800, Herbert Xu wrote:
> On Thu, Jan 18, 2018 at 09:58:13AM +0100, LABBE Corentin wrote:
> >
> > I have two way of adding a new netlink request
> > - keep the current patch and simply add a new CRYPTO_MSG_GETSTAT which use 
> > the same function than CRYPTO_MSG_GETALG
> > => minimal changes, in fact CRYPTO_MSG_GETSTAT and CRYPTO_MSG_GETALG 
> > would be the same, but it is easy for userspace to test presence of stat.
> > - Create a new CRYPTO_MSG_GETSTAT which imply lot of code and add a new 
> > crypto_user_stat.c
> > => this imply also to change makefile (rename crypto_user.c to 
> > crypto_user_base.c) since crypto_user.ko is made of two files.
> > 
> > Which one do you prefer ?
> 
> I think you should check with the crconf author, Steffen Klassert
> since that will be affected by this change.

I still haven't had time to look into the details, but I'm
fine with everything that does not break existing userspace.
Everything else would be a 'no go'.


Re: [PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-31 Thread Steffen Klassert
On Fri, Jan 26, 2018 at 11:43:28PM +0800, Herbert Xu wrote:
> On Thu, Jan 18, 2018 at 09:58:13AM +0100, LABBE Corentin wrote:
> >
> > I have two way of adding a new netlink request
> > - keep the current patch and simply add a new CRYPTO_MSG_GETSTAT which use 
> > the same function than CRYPTO_MSG_GETALG
> > => minimal changes, in fact CRYPTO_MSG_GETSTAT and CRYPTO_MSG_GETALG 
> > would be the same, but it is easy for userspace to test presence of stat.
> > - Create a new CRYPTO_MSG_GETSTAT which imply lot of code and add a new 
> > crypto_user_stat.c
> > => this imply also to change makefile (rename crypto_user.c to 
> > crypto_user_base.c) since crypto_user.ko is made of two files.
> > 
> > Which one do you prefer ?
> 
> I think you should check with the crconf author, Steffen Klassert
> since that will be affected by this change.

I still haven't had time to look into the details, but I'm
fine with everything that does not break existing userspace.
Everything else would be a 'no go'.


Re: [PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-26 Thread Herbert Xu
On Thu, Jan 18, 2018 at 09:58:13AM +0100, LABBE Corentin wrote:
>
> I have two way of adding a new netlink request
> - keep the current patch and simply add a new CRYPTO_MSG_GETSTAT which use 
> the same function than CRYPTO_MSG_GETALG
>   => minimal changes, in fact CRYPTO_MSG_GETSTAT and CRYPTO_MSG_GETALG 
> would be the same, but it is easy for userspace to test presence of stat.
> - Create a new CRYPTO_MSG_GETSTAT which imply lot of code and add a new 
> crypto_user_stat.c
>   => this imply also to change makefile (rename crypto_user.c to 
> crypto_user_base.c) since crypto_user.ko is made of two files.
> 
> Which one do you prefer ?

I think you should check with the crconf author, Steffen Klassert
since that will be affected by this change.

Thanks,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: [PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-26 Thread Herbert Xu
On Thu, Jan 18, 2018 at 09:58:13AM +0100, LABBE Corentin wrote:
>
> I have two way of adding a new netlink request
> - keep the current patch and simply add a new CRYPTO_MSG_GETSTAT which use 
> the same function than CRYPTO_MSG_GETALG
>   => minimal changes, in fact CRYPTO_MSG_GETSTAT and CRYPTO_MSG_GETALG 
> would be the same, but it is easy for userspace to test presence of stat.
> - Create a new CRYPTO_MSG_GETSTAT which imply lot of code and add a new 
> crypto_user_stat.c
>   => this imply also to change makefile (rename crypto_user.c to 
> crypto_user_base.c) since crypto_user.ko is made of two files.
> 
> Which one do you prefer ?

I think you should check with the crconf author, Steffen Klassert
since that will be affected by this change.

Thanks,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: [PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-18 Thread LABBE Corentin
On Fri, Jan 12, 2018 at 10:11:18AM +0100, Stephan Mueller wrote:
> Am Freitag, 12. Januar 2018, 10:07:30 CET schrieb LABBE Corentin:
> 
> > > > +   __u64 stat_hash_tlen;
> > > > 
> > > >  };
> > > 
> > > What I am slightly unsure here is: how should user space detect whether
> > > these additional parameters are part of the NETLINK_USER API or not? I
> > > use that interface in my libkcapi whose binary may be used on multiple
> > > different kernel versions. How should that library operate if one kernel
> > > has these parameters and another does not?
> > 
> > Userspace could check for kernel version and know if stat are present or
> > not. Another way is to add a new netlink request.
> 
> Well, I am not sure that checking the kernel version is good enough. Distros 
> and other vendors may backport this patch. This means that for some older 
> kernel versions this interface is present.
> 
> Hence I would rather opt for a separate stat message where the user spacee 
> caller receives an error on kernels that does not support it.
> 
Herbert,
I have two way of adding a new netlink request
- keep the current patch and simply add a new CRYPTO_MSG_GETSTAT which use the 
same function than CRYPTO_MSG_GETALG
=> minimal changes, in fact CRYPTO_MSG_GETSTAT and CRYPTO_MSG_GETALG 
would be the same, but it is easy for userspace to test presence of stat.
- Create a new CRYPTO_MSG_GETSTAT which imply lot of code and add a new 
crypto_user_stat.c
=> this imply also to change makefile (rename crypto_user.c to 
crypto_user_base.c) since crypto_user.ko is made of two files.

Which one do you prefer ?

Regards


Re: [PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-18 Thread LABBE Corentin
On Fri, Jan 12, 2018 at 10:11:18AM +0100, Stephan Mueller wrote:
> Am Freitag, 12. Januar 2018, 10:07:30 CET schrieb LABBE Corentin:
> 
> > > > +   __u64 stat_hash_tlen;
> > > > 
> > > >  };
> > > 
> > > What I am slightly unsure here is: how should user space detect whether
> > > these additional parameters are part of the NETLINK_USER API or not? I
> > > use that interface in my libkcapi whose binary may be used on multiple
> > > different kernel versions. How should that library operate if one kernel
> > > has these parameters and another does not?
> > 
> > Userspace could check for kernel version and know if stat are present or
> > not. Another way is to add a new netlink request.
> 
> Well, I am not sure that checking the kernel version is good enough. Distros 
> and other vendors may backport this patch. This means that for some older 
> kernel versions this interface is present.
> 
> Hence I would rather opt for a separate stat message where the user spacee 
> caller receives an error on kernels that does not support it.
> 
Herbert,
I have two way of adding a new netlink request
- keep the current patch and simply add a new CRYPTO_MSG_GETSTAT which use the 
same function than CRYPTO_MSG_GETALG
=> minimal changes, in fact CRYPTO_MSG_GETSTAT and CRYPTO_MSG_GETALG 
would be the same, but it is easy for userspace to test presence of stat.
- Create a new CRYPTO_MSG_GETSTAT which imply lot of code and add a new 
crypto_user_stat.c
=> this imply also to change makefile (rename crypto_user.c to 
crypto_user_base.c) since crypto_user.ko is made of two files.

Which one do you prefer ?

Regards


Re: [PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-12 Thread Stephan Mueller
Am Freitag, 12. Januar 2018, 10:07:30 CET schrieb LABBE Corentin:

Hi LABBE,

> 
> > > diff --git a/include/uapi/linux/cryptouser.h
> > > b/include/uapi/linux/cryptouser.h index 19bf0ca6d635..15e51ccb3679
> > > 100644
> > > --- a/include/uapi/linux/cryptouser.h
> > > +++ b/include/uapi/linux/cryptouser.h
> > > @@ -73,6 +73,8 @@ struct crypto_report_hash {
> > > 
> > >   char type[CRYPTO_MAX_NAME];
> > >   unsigned int blocksize;
> > >   unsigned int digestsize;
> > > 
> > > + __u64 stat_hash;
> > 
> > Why do you use __u64? The atomic_t variable is an int, i.e. 32 bit. Thus I
> > would think that __u32 would suffice?
> 
> You are right, I will downgrade to __u32
> But I think I will set len stats to atomic64/__u64 and keep count on
> atomic_t/__u32.

Fine with me.

> > > + __u64 stat_hash_tlen;
> > > 
> > >  };
> > 
> > What I am slightly unsure here is: how should user space detect whether
> > these additional parameters are part of the NETLINK_USER API or not? I
> > use that interface in my libkcapi whose binary may be used on multiple
> > different kernel versions. How should that library operate if one kernel
> > has these parameters and another does not?
> 
> Userspace could check for kernel version and know if stat are present or
> not. Another way is to add a new netlink request.

Well, I am not sure that checking the kernel version is good enough. Distros 
and other vendors may backport this patch. This means that for some older 
kernel versions this interface is present.

Hence I would rather opt for a separate stat message where the user spacee 
caller receives an error on kernels that does not support it.

Ciao
Stephan




Re: [PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-12 Thread Stephan Mueller
Am Freitag, 12. Januar 2018, 10:07:30 CET schrieb LABBE Corentin:

Hi LABBE,

> 
> > > diff --git a/include/uapi/linux/cryptouser.h
> > > b/include/uapi/linux/cryptouser.h index 19bf0ca6d635..15e51ccb3679
> > > 100644
> > > --- a/include/uapi/linux/cryptouser.h
> > > +++ b/include/uapi/linux/cryptouser.h
> > > @@ -73,6 +73,8 @@ struct crypto_report_hash {
> > > 
> > >   char type[CRYPTO_MAX_NAME];
> > >   unsigned int blocksize;
> > >   unsigned int digestsize;
> > > 
> > > + __u64 stat_hash;
> > 
> > Why do you use __u64? The atomic_t variable is an int, i.e. 32 bit. Thus I
> > would think that __u32 would suffice?
> 
> You are right, I will downgrade to __u32
> But I think I will set len stats to atomic64/__u64 and keep count on
> atomic_t/__u32.

Fine with me.

> > > + __u64 stat_hash_tlen;
> > > 
> > >  };
> > 
> > What I am slightly unsure here is: how should user space detect whether
> > these additional parameters are part of the NETLINK_USER API or not? I
> > use that interface in my libkcapi whose binary may be used on multiple
> > different kernel versions. How should that library operate if one kernel
> > has these parameters and another does not?
> 
> Userspace could check for kernel version and know if stat are present or
> not. Another way is to add a new netlink request.

Well, I am not sure that checking the kernel version is good enough. Distros 
and other vendors may backport this patch. This means that for some older 
kernel versions this interface is present.

Hence I would rather opt for a separate stat message where the user spacee 
caller receives an error on kernels that does not support it.

Ciao
Stephan




Re: [PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-12 Thread LABBE Corentin
On Fri, Jan 12, 2018 at 07:49:43AM +0100, Stephan Mueller wrote:
> Am Donnerstag, 11. Januar 2018, 20:56:56 CET schrieb Corentin Labbe:
> 
> Hi Corentin,
> 
> > This patch implement a generic way to get statistics about all crypto
> > usages.
> > 
> > Signed-off-by: Corentin Labbe 
> > ---
> >  crypto/Kconfig  | 11 
> >  crypto/ablkcipher.c |  9 +++
> >  crypto/acompress.c  |  9 +++
> >  crypto/aead.c   | 10 
> >  crypto/ahash.c  |  8 ++
> >  crypto/akcipher.c   | 13 ++
> >  crypto/algapi.c |  6 +
> >  crypto/blkcipher.c  |  9 +++
> >  crypto/crypto_user.c| 28 +
> >  crypto/kpp.c|  7 ++
> >  crypto/rng.c|  8 ++
> >  crypto/scompress.c  |  9 +++
> >  crypto/shash.c  |  5 
> >  crypto/skcipher.c   |  9 +++
> >  include/crypto/acompress.h  | 22 
> >  include/crypto/aead.h   | 22 
> >  include/crypto/akcipher.h   | 42 +++
> >  include/crypto/hash.h   | 21 
> >  include/crypto/kpp.h| 28 +
> >  include/crypto/rng.h| 17 +
> >  include/crypto/skcipher.h   | 22 
> >  include/linux/crypto.h  | 56
> > + include/uapi/linux/cryptouser.h |
> > 34 +
> >  23 files changed, 405 insertions(+)
> > 
> > diff --git a/crypto/Kconfig b/crypto/Kconfig
> > index 971d558494c3..3b88fba14b59 100644
> > --- a/crypto/Kconfig
> > +++ b/crypto/Kconfig
> > @@ -1780,6 +1780,17 @@ config CRYPTO_USER_API_AEAD
> >   This option enables the user-spaces interface for AEAD
> >   cipher algorithms.
> > 
> > +config CRYPTO_STATS
> > +   bool "Crypto usage statistics for User-space"
> > +   help
> > + This option enables the gathering of crypto stats.
> > + This will collect:
> > + - encrypt/decrypt size and numbers of symmeric operations
> > + - compress/decompress size and numbers of compress operations
> > + - size and numbers of hash operations
> > + - encrypt/decrypt/sign/verify numbers for asymmetric operations
> > + - generate/seed numbers for rng operations
> > +
> >  config CRYPTO_HASH_INFO
> > bool
> > 

[...]
> >   * crypto_acomp_compress() -- Invoke asynchronous compress operation
> >   *
> > @@ -247,6 +267,7 @@ static inline int crypto_acomp_compress(struct acomp_req
> > *req) {
> > struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
> > 
> > +   crypto_stat_compress(req);
> > return tfm->compress(req);
> 
> In general: should'nt the statistics increment only happen if the associated 
> operation was successful?
> 

I will do it.
This bring also a possibility to get errors counters.

> >  /**
> >   * crypto_ahash_finup() - update and finalize message digest
> >   * @req: reference to the ahash_request handle that holds all information
> > @@ -519,6 +538,8 @@ static inline int crypto_ahash_init(struct ahash_request
> > *req) */
> >  static inline int crypto_ahash_update(struct ahash_request *req)
> >  {
> > +
> > +   crypto_stat_ahash_update(req);
> > return crypto_ahash_reqtfm(req)->update(req);
> 
> In case you roll another update: please remove the blank line.

Ok
 
> > diff --git a/include/uapi/linux/cryptouser.h
> > b/include/uapi/linux/cryptouser.h index 19bf0ca6d635..15e51ccb3679 100644
> > --- a/include/uapi/linux/cryptouser.h
> > +++ b/include/uapi/linux/cryptouser.h
> > @@ -73,6 +73,8 @@ struct crypto_report_hash {
> > char type[CRYPTO_MAX_NAME];
> > unsigned int blocksize;
> > unsigned int digestsize;
> > +   __u64 stat_hash;
> 
> Why do you use __u64? The atomic_t variable is an int, i.e. 32 bit. Thus I 
> would think that __u32 would suffice?

You are right, I will downgrade to __u32
But I think I will set len stats to atomic64/__u64 and keep count on 
atomic_t/__u32.

> 
> 
> > +   __u64 stat_hash_tlen;
> >  };
> 
> What I am slightly unsure here is: how should user space detect whether these 
> additional parameters are part of the NETLINK_USER API or not? I use that 
> interface in my libkcapi whose binary may be used on multiple different 
> kernel 
> versions. How should that library operate if one kernel has these parameters 
> and another does not?
> 

Userspace could check for kernel version and know if stat are present or not.
Another way is to add a new netlink request.

Thanks for your review.
Regards
Corentin Labbe


Re: [PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-12 Thread LABBE Corentin
On Fri, Jan 12, 2018 at 07:49:43AM +0100, Stephan Mueller wrote:
> Am Donnerstag, 11. Januar 2018, 20:56:56 CET schrieb Corentin Labbe:
> 
> Hi Corentin,
> 
> > This patch implement a generic way to get statistics about all crypto
> > usages.
> > 
> > Signed-off-by: Corentin Labbe 
> > ---
> >  crypto/Kconfig  | 11 
> >  crypto/ablkcipher.c |  9 +++
> >  crypto/acompress.c  |  9 +++
> >  crypto/aead.c   | 10 
> >  crypto/ahash.c  |  8 ++
> >  crypto/akcipher.c   | 13 ++
> >  crypto/algapi.c |  6 +
> >  crypto/blkcipher.c  |  9 +++
> >  crypto/crypto_user.c| 28 +
> >  crypto/kpp.c|  7 ++
> >  crypto/rng.c|  8 ++
> >  crypto/scompress.c  |  9 +++
> >  crypto/shash.c  |  5 
> >  crypto/skcipher.c   |  9 +++
> >  include/crypto/acompress.h  | 22 
> >  include/crypto/aead.h   | 22 
> >  include/crypto/akcipher.h   | 42 +++
> >  include/crypto/hash.h   | 21 
> >  include/crypto/kpp.h| 28 +
> >  include/crypto/rng.h| 17 +
> >  include/crypto/skcipher.h   | 22 
> >  include/linux/crypto.h  | 56
> > + include/uapi/linux/cryptouser.h |
> > 34 +
> >  23 files changed, 405 insertions(+)
> > 
> > diff --git a/crypto/Kconfig b/crypto/Kconfig
> > index 971d558494c3..3b88fba14b59 100644
> > --- a/crypto/Kconfig
> > +++ b/crypto/Kconfig
> > @@ -1780,6 +1780,17 @@ config CRYPTO_USER_API_AEAD
> >   This option enables the user-spaces interface for AEAD
> >   cipher algorithms.
> > 
> > +config CRYPTO_STATS
> > +   bool "Crypto usage statistics for User-space"
> > +   help
> > + This option enables the gathering of crypto stats.
> > + This will collect:
> > + - encrypt/decrypt size and numbers of symmeric operations
> > + - compress/decompress size and numbers of compress operations
> > + - size and numbers of hash operations
> > + - encrypt/decrypt/sign/verify numbers for asymmetric operations
> > + - generate/seed numbers for rng operations
> > +
> >  config CRYPTO_HASH_INFO
> > bool
> > 

[...]
> >   * crypto_acomp_compress() -- Invoke asynchronous compress operation
> >   *
> > @@ -247,6 +267,7 @@ static inline int crypto_acomp_compress(struct acomp_req
> > *req) {
> > struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
> > 
> > +   crypto_stat_compress(req);
> > return tfm->compress(req);
> 
> In general: should'nt the statistics increment only happen if the associated 
> operation was successful?
> 

I will do it.
This bring also a possibility to get errors counters.

> >  /**
> >   * crypto_ahash_finup() - update and finalize message digest
> >   * @req: reference to the ahash_request handle that holds all information
> > @@ -519,6 +538,8 @@ static inline int crypto_ahash_init(struct ahash_request
> > *req) */
> >  static inline int crypto_ahash_update(struct ahash_request *req)
> >  {
> > +
> > +   crypto_stat_ahash_update(req);
> > return crypto_ahash_reqtfm(req)->update(req);
> 
> In case you roll another update: please remove the blank line.

Ok
 
> > diff --git a/include/uapi/linux/cryptouser.h
> > b/include/uapi/linux/cryptouser.h index 19bf0ca6d635..15e51ccb3679 100644
> > --- a/include/uapi/linux/cryptouser.h
> > +++ b/include/uapi/linux/cryptouser.h
> > @@ -73,6 +73,8 @@ struct crypto_report_hash {
> > char type[CRYPTO_MAX_NAME];
> > unsigned int blocksize;
> > unsigned int digestsize;
> > +   __u64 stat_hash;
> 
> Why do you use __u64? The atomic_t variable is an int, i.e. 32 bit. Thus I 
> would think that __u32 would suffice?

You are right, I will downgrade to __u32
But I think I will set len stats to atomic64/__u64 and keep count on 
atomic_t/__u32.

> 
> 
> > +   __u64 stat_hash_tlen;
> >  };
> 
> What I am slightly unsure here is: how should user space detect whether these 
> additional parameters are part of the NETLINK_USER API or not? I use that 
> interface in my libkcapi whose binary may be used on multiple different 
> kernel 
> versions. How should that library operate if one kernel has these parameters 
> and another does not?
> 

Userspace could check for kernel version and know if stat are present or not.
Another way is to add a new netlink request.

Thanks for your review.
Regards
Corentin Labbe


Re: [PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-11 Thread Stephan Mueller
Am Donnerstag, 11. Januar 2018, 20:56:56 CET schrieb Corentin Labbe:

Hi Corentin,

> This patch implement a generic way to get statistics about all crypto
> usages.
> 
> Signed-off-by: Corentin Labbe 
> ---
>  crypto/Kconfig  | 11 
>  crypto/ablkcipher.c |  9 +++
>  crypto/acompress.c  |  9 +++
>  crypto/aead.c   | 10 
>  crypto/ahash.c  |  8 ++
>  crypto/akcipher.c   | 13 ++
>  crypto/algapi.c |  6 +
>  crypto/blkcipher.c  |  9 +++
>  crypto/crypto_user.c| 28 +
>  crypto/kpp.c|  7 ++
>  crypto/rng.c|  8 ++
>  crypto/scompress.c  |  9 +++
>  crypto/shash.c  |  5 
>  crypto/skcipher.c   |  9 +++
>  include/crypto/acompress.h  | 22 
>  include/crypto/aead.h   | 22 
>  include/crypto/akcipher.h   | 42 +++
>  include/crypto/hash.h   | 21 
>  include/crypto/kpp.h| 28 +
>  include/crypto/rng.h| 17 +
>  include/crypto/skcipher.h   | 22 
>  include/linux/crypto.h  | 56
> + include/uapi/linux/cryptouser.h |
> 34 +
>  23 files changed, 405 insertions(+)
> 
> diff --git a/crypto/Kconfig b/crypto/Kconfig
> index 971d558494c3..3b88fba14b59 100644
> --- a/crypto/Kconfig
> +++ b/crypto/Kconfig
> @@ -1780,6 +1780,17 @@ config CRYPTO_USER_API_AEAD
> This option enables the user-spaces interface for AEAD
> cipher algorithms.
> 
> +config CRYPTO_STATS
> + bool "Crypto usage statistics for User-space"
> + help
> +   This option enables the gathering of crypto stats.
> +   This will collect:
> +   - encrypt/decrypt size and numbers of symmeric operations
> +   - compress/decompress size and numbers of compress operations
> +   - size and numbers of hash operations
> +   - encrypt/decrypt/sign/verify numbers for asymmetric operations
> +   - generate/seed numbers for rng operations
> +
>  config CRYPTO_HASH_INFO
>   bool
> 
> diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
> index d880a4897159..f6d20e4ca977 100644
> --- a/crypto/ablkcipher.c
> +++ b/crypto/ablkcipher.c
> @@ -369,6 +369,7 @@ static int crypto_init_ablkcipher_ops(struct crypto_tfm
> *tfm, u32 type, static int crypto_ablkcipher_report(struct sk_buff *skb,
> struct crypto_alg *alg) {
>   struct crypto_report_blkcipher rblkcipher;
> + u64 v;
> 
>   strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
>   strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "",
> @@ -378,6 +379,14 @@ static int crypto_ablkcipher_report(struct sk_buff
> *skb, struct crypto_alg *alg) rblkcipher.min_keysize =
> alg->cra_ablkcipher.min_keysize;
>   rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
>   rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
> + v = atomic_read(>encrypt_cnt);
> + rblkcipher.stat_encrypt_cnt = v;
> + v = atomic_read(>encrypt_tlen);
> + rblkcipher.stat_encrypt_tlen = v;
> + v = atomic_read(>decrypt_cnt);
> + rblkcipher.stat_decrypt_cnt = v;
> + v = atomic_read(>decrypt_tlen);
> + rblkcipher.stat_decrypt_tlen = v;
> 
>   if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
>   sizeof(struct crypto_report_blkcipher), ))
> diff --git a/crypto/acompress.c b/crypto/acompress.c
> index 1544b7c057fb..524c8a3e3f80 100644
> --- a/crypto/acompress.c
> +++ b/crypto/acompress.c
> @@ -32,8 +32,17 @@ static const struct crypto_type crypto_acomp_type;
>  static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)
> {
>   struct crypto_report_acomp racomp;
> + u64 v;
> 
>   strncpy(racomp.type, "acomp", sizeof(racomp.type));
> + v = atomic_read(>compress_cnt);
> + racomp.stat_compress_cnt = v;
> + v = atomic_read(>compress_tlen);
> + racomp.stat_compress_tlen = v;
> + v = atomic_read(>decompress_cnt);
> + racomp.stat_decompress_cnt = v;
> + v = atomic_read(>decompress_tlen);
> + racomp.stat_decompress_tlen = v;
> 
>   if (nla_put(skb, CRYPTOCFGA_REPORT_ACOMP,
>   sizeof(struct crypto_report_acomp), ))
> diff --git a/crypto/aead.c b/crypto/aead.c
> index fe00cbd7243d..de13bd345d8b 100644
> --- a/crypto/aead.c
> +++ b/crypto/aead.c
> @@ -109,6 +109,7 @@ static int crypto_aead_report(struct sk_buff *skb,
> struct crypto_alg *alg) {
>   struct crypto_report_aead raead;
>   struct aead_alg *aead = container_of(alg, struct aead_alg, base);
> + u64 v;
> 
>   strncpy(raead.type, "aead", sizeof(raead.type));
>   strncpy(raead.geniv, "", sizeof(raead.geniv));
> @@ -116,6 +117,15 @@ static int 

Re: [PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-11 Thread Stephan Mueller
Am Donnerstag, 11. Januar 2018, 20:56:56 CET schrieb Corentin Labbe:

Hi Corentin,

> This patch implement a generic way to get statistics about all crypto
> usages.
> 
> Signed-off-by: Corentin Labbe 
> ---
>  crypto/Kconfig  | 11 
>  crypto/ablkcipher.c |  9 +++
>  crypto/acompress.c  |  9 +++
>  crypto/aead.c   | 10 
>  crypto/ahash.c  |  8 ++
>  crypto/akcipher.c   | 13 ++
>  crypto/algapi.c |  6 +
>  crypto/blkcipher.c  |  9 +++
>  crypto/crypto_user.c| 28 +
>  crypto/kpp.c|  7 ++
>  crypto/rng.c|  8 ++
>  crypto/scompress.c  |  9 +++
>  crypto/shash.c  |  5 
>  crypto/skcipher.c   |  9 +++
>  include/crypto/acompress.h  | 22 
>  include/crypto/aead.h   | 22 
>  include/crypto/akcipher.h   | 42 +++
>  include/crypto/hash.h   | 21 
>  include/crypto/kpp.h| 28 +
>  include/crypto/rng.h| 17 +
>  include/crypto/skcipher.h   | 22 
>  include/linux/crypto.h  | 56
> + include/uapi/linux/cryptouser.h |
> 34 +
>  23 files changed, 405 insertions(+)
> 
> diff --git a/crypto/Kconfig b/crypto/Kconfig
> index 971d558494c3..3b88fba14b59 100644
> --- a/crypto/Kconfig
> +++ b/crypto/Kconfig
> @@ -1780,6 +1780,17 @@ config CRYPTO_USER_API_AEAD
> This option enables the user-spaces interface for AEAD
> cipher algorithms.
> 
> +config CRYPTO_STATS
> + bool "Crypto usage statistics for User-space"
> + help
> +   This option enables the gathering of crypto stats.
> +   This will collect:
> +   - encrypt/decrypt size and numbers of symmeric operations
> +   - compress/decompress size and numbers of compress operations
> +   - size and numbers of hash operations
> +   - encrypt/decrypt/sign/verify numbers for asymmetric operations
> +   - generate/seed numbers for rng operations
> +
>  config CRYPTO_HASH_INFO
>   bool
> 
> diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
> index d880a4897159..f6d20e4ca977 100644
> --- a/crypto/ablkcipher.c
> +++ b/crypto/ablkcipher.c
> @@ -369,6 +369,7 @@ static int crypto_init_ablkcipher_ops(struct crypto_tfm
> *tfm, u32 type, static int crypto_ablkcipher_report(struct sk_buff *skb,
> struct crypto_alg *alg) {
>   struct crypto_report_blkcipher rblkcipher;
> + u64 v;
> 
>   strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
>   strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "",
> @@ -378,6 +379,14 @@ static int crypto_ablkcipher_report(struct sk_buff
> *skb, struct crypto_alg *alg) rblkcipher.min_keysize =
> alg->cra_ablkcipher.min_keysize;
>   rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
>   rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
> + v = atomic_read(>encrypt_cnt);
> + rblkcipher.stat_encrypt_cnt = v;
> + v = atomic_read(>encrypt_tlen);
> + rblkcipher.stat_encrypt_tlen = v;
> + v = atomic_read(>decrypt_cnt);
> + rblkcipher.stat_decrypt_cnt = v;
> + v = atomic_read(>decrypt_tlen);
> + rblkcipher.stat_decrypt_tlen = v;
> 
>   if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
>   sizeof(struct crypto_report_blkcipher), ))
> diff --git a/crypto/acompress.c b/crypto/acompress.c
> index 1544b7c057fb..524c8a3e3f80 100644
> --- a/crypto/acompress.c
> +++ b/crypto/acompress.c
> @@ -32,8 +32,17 @@ static const struct crypto_type crypto_acomp_type;
>  static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)
> {
>   struct crypto_report_acomp racomp;
> + u64 v;
> 
>   strncpy(racomp.type, "acomp", sizeof(racomp.type));
> + v = atomic_read(>compress_cnt);
> + racomp.stat_compress_cnt = v;
> + v = atomic_read(>compress_tlen);
> + racomp.stat_compress_tlen = v;
> + v = atomic_read(>decompress_cnt);
> + racomp.stat_decompress_cnt = v;
> + v = atomic_read(>decompress_tlen);
> + racomp.stat_decompress_tlen = v;
> 
>   if (nla_put(skb, CRYPTOCFGA_REPORT_ACOMP,
>   sizeof(struct crypto_report_acomp), ))
> diff --git a/crypto/aead.c b/crypto/aead.c
> index fe00cbd7243d..de13bd345d8b 100644
> --- a/crypto/aead.c
> +++ b/crypto/aead.c
> @@ -109,6 +109,7 @@ static int crypto_aead_report(struct sk_buff *skb,
> struct crypto_alg *alg) {
>   struct crypto_report_aead raead;
>   struct aead_alg *aead = container_of(alg, struct aead_alg, base);
> + u64 v;
> 
>   strncpy(raead.type, "aead", sizeof(raead.type));
>   strncpy(raead.geniv, "", sizeof(raead.geniv));
> @@ -116,6 +117,15 @@ static int 

[PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-11 Thread Corentin Labbe
This patch implement a generic way to get statistics about all crypto
usages.

Signed-off-by: Corentin Labbe 
---
 crypto/Kconfig  | 11 
 crypto/ablkcipher.c |  9 +++
 crypto/acompress.c  |  9 +++
 crypto/aead.c   | 10 
 crypto/ahash.c  |  8 ++
 crypto/akcipher.c   | 13 ++
 crypto/algapi.c |  6 +
 crypto/blkcipher.c  |  9 +++
 crypto/crypto_user.c| 28 +
 crypto/kpp.c|  7 ++
 crypto/rng.c|  8 ++
 crypto/scompress.c  |  9 +++
 crypto/shash.c  |  5 
 crypto/skcipher.c   |  9 +++
 include/crypto/acompress.h  | 22 
 include/crypto/aead.h   | 22 
 include/crypto/akcipher.h   | 42 +++
 include/crypto/hash.h   | 21 
 include/crypto/kpp.h| 28 +
 include/crypto/rng.h| 17 +
 include/crypto/skcipher.h   | 22 
 include/linux/crypto.h  | 56 +
 include/uapi/linux/cryptouser.h | 34 +
 23 files changed, 405 insertions(+)

diff --git a/crypto/Kconfig b/crypto/Kconfig
index 971d558494c3..3b88fba14b59 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -1780,6 +1780,17 @@ config CRYPTO_USER_API_AEAD
  This option enables the user-spaces interface for AEAD
  cipher algorithms.
 
+config CRYPTO_STATS
+   bool "Crypto usage statistics for User-space"
+   help
+ This option enables the gathering of crypto stats.
+ This will collect:
+ - encrypt/decrypt size and numbers of symmeric operations
+ - compress/decompress size and numbers of compress operations
+ - size and numbers of hash operations
+ - encrypt/decrypt/sign/verify numbers for asymmetric operations
+ - generate/seed numbers for rng operations
+
 config CRYPTO_HASH_INFO
bool
 
diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
index d880a4897159..f6d20e4ca977 100644
--- a/crypto/ablkcipher.c
+++ b/crypto/ablkcipher.c
@@ -369,6 +369,7 @@ static int crypto_init_ablkcipher_ops(struct crypto_tfm 
*tfm, u32 type,
 static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg 
*alg)
 {
struct crypto_report_blkcipher rblkcipher;
+   u64 v;
 
strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "",
@@ -378,6 +379,14 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, 
struct crypto_alg *alg)
rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
+   v = atomic_read(>encrypt_cnt);
+   rblkcipher.stat_encrypt_cnt = v;
+   v = atomic_read(>encrypt_tlen);
+   rblkcipher.stat_encrypt_tlen = v;
+   v = atomic_read(>decrypt_cnt);
+   rblkcipher.stat_decrypt_cnt = v;
+   v = atomic_read(>decrypt_tlen);
+   rblkcipher.stat_decrypt_tlen = v;
 
if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
sizeof(struct crypto_report_blkcipher), ))
diff --git a/crypto/acompress.c b/crypto/acompress.c
index 1544b7c057fb..524c8a3e3f80 100644
--- a/crypto/acompress.c
+++ b/crypto/acompress.c
@@ -32,8 +32,17 @@ static const struct crypto_type crypto_acomp_type;
 static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)
 {
struct crypto_report_acomp racomp;
+   u64 v;
 
strncpy(racomp.type, "acomp", sizeof(racomp.type));
+   v = atomic_read(>compress_cnt);
+   racomp.stat_compress_cnt = v;
+   v = atomic_read(>compress_tlen);
+   racomp.stat_compress_tlen = v;
+   v = atomic_read(>decompress_cnt);
+   racomp.stat_decompress_cnt = v;
+   v = atomic_read(>decompress_tlen);
+   racomp.stat_decompress_tlen = v;
 
if (nla_put(skb, CRYPTOCFGA_REPORT_ACOMP,
sizeof(struct crypto_report_acomp), ))
diff --git a/crypto/aead.c b/crypto/aead.c
index fe00cbd7243d..de13bd345d8b 100644
--- a/crypto/aead.c
+++ b/crypto/aead.c
@@ -109,6 +109,7 @@ static int crypto_aead_report(struct sk_buff *skb, struct 
crypto_alg *alg)
 {
struct crypto_report_aead raead;
struct aead_alg *aead = container_of(alg, struct aead_alg, base);
+   u64 v;
 
strncpy(raead.type, "aead", sizeof(raead.type));
strncpy(raead.geniv, "", sizeof(raead.geniv));
@@ -116,6 +117,15 @@ static int crypto_aead_report(struct sk_buff *skb, struct 
crypto_alg *alg)
raead.blocksize = alg->cra_blocksize;
raead.maxauthsize = aead->maxauthsize;
raead.ivsize = aead->ivsize;
+  

[PATCH 1/2] crypto: Implement a generic crypto statistics

2018-01-11 Thread Corentin Labbe
This patch implement a generic way to get statistics about all crypto
usages.

Signed-off-by: Corentin Labbe 
---
 crypto/Kconfig  | 11 
 crypto/ablkcipher.c |  9 +++
 crypto/acompress.c  |  9 +++
 crypto/aead.c   | 10 
 crypto/ahash.c  |  8 ++
 crypto/akcipher.c   | 13 ++
 crypto/algapi.c |  6 +
 crypto/blkcipher.c  |  9 +++
 crypto/crypto_user.c| 28 +
 crypto/kpp.c|  7 ++
 crypto/rng.c|  8 ++
 crypto/scompress.c  |  9 +++
 crypto/shash.c  |  5 
 crypto/skcipher.c   |  9 +++
 include/crypto/acompress.h  | 22 
 include/crypto/aead.h   | 22 
 include/crypto/akcipher.h   | 42 +++
 include/crypto/hash.h   | 21 
 include/crypto/kpp.h| 28 +
 include/crypto/rng.h| 17 +
 include/crypto/skcipher.h   | 22 
 include/linux/crypto.h  | 56 +
 include/uapi/linux/cryptouser.h | 34 +
 23 files changed, 405 insertions(+)

diff --git a/crypto/Kconfig b/crypto/Kconfig
index 971d558494c3..3b88fba14b59 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -1780,6 +1780,17 @@ config CRYPTO_USER_API_AEAD
  This option enables the user-spaces interface for AEAD
  cipher algorithms.
 
+config CRYPTO_STATS
+   bool "Crypto usage statistics for User-space"
+   help
+ This option enables the gathering of crypto stats.
+ This will collect:
+ - encrypt/decrypt size and numbers of symmeric operations
+ - compress/decompress size and numbers of compress operations
+ - size and numbers of hash operations
+ - encrypt/decrypt/sign/verify numbers for asymmetric operations
+ - generate/seed numbers for rng operations
+
 config CRYPTO_HASH_INFO
bool
 
diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
index d880a4897159..f6d20e4ca977 100644
--- a/crypto/ablkcipher.c
+++ b/crypto/ablkcipher.c
@@ -369,6 +369,7 @@ static int crypto_init_ablkcipher_ops(struct crypto_tfm 
*tfm, u32 type,
 static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg 
*alg)
 {
struct crypto_report_blkcipher rblkcipher;
+   u64 v;
 
strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "",
@@ -378,6 +379,14 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, 
struct crypto_alg *alg)
rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
rblkcipher.max_keysize = alg->cra_ablkcipher.max_keysize;
rblkcipher.ivsize = alg->cra_ablkcipher.ivsize;
+   v = atomic_read(>encrypt_cnt);
+   rblkcipher.stat_encrypt_cnt = v;
+   v = atomic_read(>encrypt_tlen);
+   rblkcipher.stat_encrypt_tlen = v;
+   v = atomic_read(>decrypt_cnt);
+   rblkcipher.stat_decrypt_cnt = v;
+   v = atomic_read(>decrypt_tlen);
+   rblkcipher.stat_decrypt_tlen = v;
 
if (nla_put(skb, CRYPTOCFGA_REPORT_BLKCIPHER,
sizeof(struct crypto_report_blkcipher), ))
diff --git a/crypto/acompress.c b/crypto/acompress.c
index 1544b7c057fb..524c8a3e3f80 100644
--- a/crypto/acompress.c
+++ b/crypto/acompress.c
@@ -32,8 +32,17 @@ static const struct crypto_type crypto_acomp_type;
 static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)
 {
struct crypto_report_acomp racomp;
+   u64 v;
 
strncpy(racomp.type, "acomp", sizeof(racomp.type));
+   v = atomic_read(>compress_cnt);
+   racomp.stat_compress_cnt = v;
+   v = atomic_read(>compress_tlen);
+   racomp.stat_compress_tlen = v;
+   v = atomic_read(>decompress_cnt);
+   racomp.stat_decompress_cnt = v;
+   v = atomic_read(>decompress_tlen);
+   racomp.stat_decompress_tlen = v;
 
if (nla_put(skb, CRYPTOCFGA_REPORT_ACOMP,
sizeof(struct crypto_report_acomp), ))
diff --git a/crypto/aead.c b/crypto/aead.c
index fe00cbd7243d..de13bd345d8b 100644
--- a/crypto/aead.c
+++ b/crypto/aead.c
@@ -109,6 +109,7 @@ static int crypto_aead_report(struct sk_buff *skb, struct 
crypto_alg *alg)
 {
struct crypto_report_aead raead;
struct aead_alg *aead = container_of(alg, struct aead_alg, base);
+   u64 v;
 
strncpy(raead.type, "aead", sizeof(raead.type));
strncpy(raead.geniv, "", sizeof(raead.geniv));
@@ -116,6 +117,15 @@ static int crypto_aead_report(struct sk_buff *skb, struct 
crypto_alg *alg)
raead.blocksize = alg->cra_blocksize;
raead.maxauthsize = aead->maxauthsize;
raead.ivsize = aead->ivsize;
+   v =