Re: [PATCH RFC v6 1/3] crypto: add PKE API
On Tue, Jun 16, 2015 at 01:01:59AM -0700, Tadeusz Struk wrote: > > @@ -28,6 +28,7 @@ crypto_hash-y += shash.o > obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o > > obj-$(CONFIG_CRYPTO_PCOMP2) += pcompress.o > +obj-$(CONFIG_CRYPTO_AKCIPHER) += akcipher.o s/AKCIPHER/AKCIPHER2/ > +/** > + * struct akcipher_request - public key request > + * > + * @base:Common attributes for async crypto requests > + * @src: Pointer to memory containing the input parameters > + * The format of the parameter(s) is expeted to be Octet String > + * @dst: Pointer to memory whare the result will be stored > + * @src_len: Size of the input parameter > + * @dst_len: Size of the output buffer. It needs to be at leaset > + * as big as the expected result depending on the operation > + * After operation it will be updated with the acctual size of the > + * result. In case of error, where the dst_len was insufficient, > + * it will be updated to the size required for the operation. > + * @result_len: If not NULL this will be updated by the implementation to > + * reflect the acctual size of the result result_len is still here. > + * @__ctx: Start of private context data > + */ > +struct akcipher_request { > + struct crypto_async_request base; > + void *src; > + void *dst; > + unsigned int src_len; > + unsigned int *dst_len; dst_len doesn't need to be a pointer. A simple int will do. > +static inline int crypto_akcipher_encrypt(struct akcipher_request *req) > +{ > + struct crypto_akcipher *tfm = __crypto_akcipher_tfm(req->base.tfm); You should add a reqtfm helper like crypto_aead_reqtfm so that implementors don't need to do this ugly __crypto_akcipher_tfm. In fact you already have that helper so you just need to use it. Thanks, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH RFC v6 1/3] crypto: add PKE API
Add Public Key Encryption API. Signed-off-by: Tadeusz Struk --- crypto/Kconfig | 11 + crypto/Makefile|1 crypto/akcipher.c | 100 +++ crypto/crypto_user.c | 22 ++ include/crypto/akcipher.h | 323 include/crypto/internal/akcipher.h | 66 +++ include/linux/crypto.h |1 include/linux/cryptouser.h |5 + 8 files changed, 529 insertions(+) create mode 100644 crypto/akcipher.c create mode 100644 include/crypto/akcipher.h create mode 100644 include/crypto/internal/akcipher.h diff --git a/crypto/Kconfig b/crypto/Kconfig index f6fc054..264dadb 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -91,6 +91,17 @@ config CRYPTO_PCOMP2 tristate select CRYPTO_ALGAPI2 +config CRYPTO_AKCIPHER2 + tristate + select CRYPTO_ALGAPI2 + +config CRYPTO_AKCIPHER + tristate "Public Key Algorithms API" + select CRYPTO_AKCIPHER2 + select CRYPTO_ALGAPI + help + Crypto API interface for public key algorithms. + config CRYPTO_MANAGER tristate "Cryptographic algorithm manager" select CRYPTO_MANAGER2 diff --git a/crypto/Makefile b/crypto/Makefile index c842035..6f2940a 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -28,6 +28,7 @@ crypto_hash-y += shash.o obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o obj-$(CONFIG_CRYPTO_PCOMP2) += pcompress.o +obj-$(CONFIG_CRYPTO_AKCIPHER) += akcipher.o cryptomgr-y := algboss.o testmgr.o diff --git a/crypto/akcipher.c b/crypto/akcipher.c new file mode 100644 index 000..eefcc49 --- /dev/null +++ b/crypto/akcipher.c @@ -0,0 +1,100 @@ +/* + * Public Key Encryption + * + * Copyright (c) 2015, Intel Corporation + * Authors: Tadeusz Struk + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "internal.h" + +#ifdef CONFIG_NET +static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg) +{ + struct crypto_report_akcipher rakcipher; + + strncpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); + + if (nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER, + sizeof(struct crypto_report_akcipher), )) + goto nla_put_failure; + return 0; + +nla_put_failure: + return -EMSGSIZE; +} +#else +static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg) +{ + return -ENOSYS; +} +#endif + +static void crypto_akcipher_show(struct seq_file *m, struct crypto_alg *alg) + __attribute__ ((unused)); + +static void crypto_akcipher_show(struct seq_file *m, struct crypto_alg *alg) +{ + seq_puts(m, "type : akcipher\n"); +} + +static int crypto_akcipher_init_tfm(struct crypto_tfm *tfm) +{ + return 0; +} + +static const struct crypto_type crypto_akcipher_type = { + .extsize = crypto_alg_extsize, + .init_tfm = crypto_akcipher_init_tfm, +#ifdef CONFIG_PROC_FS + .show = crypto_akcipher_show, +#endif + .report = crypto_akcipher_report, + .maskclear = ~CRYPTO_ALG_TYPE_MASK, + .maskset = CRYPTO_ALG_TYPE_MASK, + .type = CRYPTO_ALG_TYPE_AKCIPHER, + .tfmsize = offsetof(struct crypto_akcipher, base), +}; + +struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type, + u32 mask) +{ + return crypto_alloc_tfm(alg_name, _akcipher_type, type, mask); +} +EXPORT_SYMBOL_GPL(crypto_alloc_akcipher); + +int crypto_register_akcipher(struct akcipher_alg *alg) +{ + struct crypto_alg *base = >base; + + base->cra_type = _akcipher_type; + base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK; + base->cra_flags |= CRYPTO_ALG_TYPE_AKCIPHER; + return crypto_register_alg(base); +} +EXPORT_SYMBOL_GPL(crypto_register_akcipher); + +void crypto_unregister_akcipher(struct akcipher_alg *alg) +{ + crypto_unregister_alg(>base); +} +EXPORT_SYMBOL_GPL(crypto_unregister_akcipher); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Generic public key cihper type"); diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c index 41dfe76..11dbd5a 100644 --- a/crypto/crypto_user.c +++ b/crypto/crypto_user.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "internal.h" @@ -110,6 +111,21 @@ nla_put_failure: return -EMSGSIZE; } +static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg) +{ + struct crypto_report_akcipher rakcipher; + + strncpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); + + if (nla_put(skb,
[PATCH RFC v6 1/3] crypto: add PKE API
Add Public Key Encryption API. Signed-off-by: Tadeusz Struk tadeusz.st...@intel.com --- crypto/Kconfig | 11 + crypto/Makefile|1 crypto/akcipher.c | 100 +++ crypto/crypto_user.c | 22 ++ include/crypto/akcipher.h | 323 include/crypto/internal/akcipher.h | 66 +++ include/linux/crypto.h |1 include/linux/cryptouser.h |5 + 8 files changed, 529 insertions(+) create mode 100644 crypto/akcipher.c create mode 100644 include/crypto/akcipher.h create mode 100644 include/crypto/internal/akcipher.h diff --git a/crypto/Kconfig b/crypto/Kconfig index f6fc054..264dadb 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -91,6 +91,17 @@ config CRYPTO_PCOMP2 tristate select CRYPTO_ALGAPI2 +config CRYPTO_AKCIPHER2 + tristate + select CRYPTO_ALGAPI2 + +config CRYPTO_AKCIPHER + tristate Public Key Algorithms API + select CRYPTO_AKCIPHER2 + select CRYPTO_ALGAPI + help + Crypto API interface for public key algorithms. + config CRYPTO_MANAGER tristate Cryptographic algorithm manager select CRYPTO_MANAGER2 diff --git a/crypto/Makefile b/crypto/Makefile index c842035..6f2940a 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -28,6 +28,7 @@ crypto_hash-y += shash.o obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o obj-$(CONFIG_CRYPTO_PCOMP2) += pcompress.o +obj-$(CONFIG_CRYPTO_AKCIPHER) += akcipher.o cryptomgr-y := algboss.o testmgr.o diff --git a/crypto/akcipher.c b/crypto/akcipher.c new file mode 100644 index 000..eefcc49 --- /dev/null +++ b/crypto/akcipher.c @@ -0,0 +1,100 @@ +/* + * Public Key Encryption + * + * Copyright (c) 2015, Intel Corporation + * Authors: Tadeusz Struk tadeusz.st...@intel.com + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + */ +#include linux/errno.h +#include linux/kernel.h +#include linux/module.h +#include linux/seq_file.h +#include linux/slab.h +#include linux/string.h +#include linux/crypto.h +#include crypto/algapi.h +#include linux/cryptouser.h +#include net/netlink.h +#include crypto/akcipher.h +#include crypto/public_key.h +#include internal.h + +#ifdef CONFIG_NET +static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg) +{ + struct crypto_report_akcipher rakcipher; + + strncpy(rakcipher.type, akcipher, sizeof(rakcipher.type)); + + if (nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER, + sizeof(struct crypto_report_akcipher), rakcipher)) + goto nla_put_failure; + return 0; + +nla_put_failure: + return -EMSGSIZE; +} +#else +static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg) +{ + return -ENOSYS; +} +#endif + +static void crypto_akcipher_show(struct seq_file *m, struct crypto_alg *alg) + __attribute__ ((unused)); + +static void crypto_akcipher_show(struct seq_file *m, struct crypto_alg *alg) +{ + seq_puts(m, type : akcipher\n); +} + +static int crypto_akcipher_init_tfm(struct crypto_tfm *tfm) +{ + return 0; +} + +static const struct crypto_type crypto_akcipher_type = { + .extsize = crypto_alg_extsize, + .init_tfm = crypto_akcipher_init_tfm, +#ifdef CONFIG_PROC_FS + .show = crypto_akcipher_show, +#endif + .report = crypto_akcipher_report, + .maskclear = ~CRYPTO_ALG_TYPE_MASK, + .maskset = CRYPTO_ALG_TYPE_MASK, + .type = CRYPTO_ALG_TYPE_AKCIPHER, + .tfmsize = offsetof(struct crypto_akcipher, base), +}; + +struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type, + u32 mask) +{ + return crypto_alloc_tfm(alg_name, crypto_akcipher_type, type, mask); +} +EXPORT_SYMBOL_GPL(crypto_alloc_akcipher); + +int crypto_register_akcipher(struct akcipher_alg *alg) +{ + struct crypto_alg *base = alg-base; + + base-cra_type = crypto_akcipher_type; + base-cra_flags = ~CRYPTO_ALG_TYPE_MASK; + base-cra_flags |= CRYPTO_ALG_TYPE_AKCIPHER; + return crypto_register_alg(base); +} +EXPORT_SYMBOL_GPL(crypto_register_akcipher); + +void crypto_unregister_akcipher(struct akcipher_alg *alg) +{ + crypto_unregister_alg(alg-base); +} +EXPORT_SYMBOL_GPL(crypto_unregister_akcipher); + +MODULE_LICENSE(GPL); +MODULE_DESCRIPTION(Generic public key cihper type); diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c index 41dfe76..11dbd5a 100644 --- a/crypto/crypto_user.c +++ b/crypto/crypto_user.c @@ -27,6 +27,7 @@ #include net/net_namespace.h #include crypto/internal/aead.h #include crypto/internal/skcipher.h +#include crypto/akcipher.h #include internal.h @@ -110,6
Re: [PATCH RFC v6 1/3] crypto: add PKE API
On Tue, Jun 16, 2015 at 01:01:59AM -0700, Tadeusz Struk wrote: @@ -28,6 +28,7 @@ crypto_hash-y += shash.o obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o obj-$(CONFIG_CRYPTO_PCOMP2) += pcompress.o +obj-$(CONFIG_CRYPTO_AKCIPHER) += akcipher.o s/AKCIPHER/AKCIPHER2/ +/** + * struct akcipher_request - public key request + * + * @base:Common attributes for async crypto requests + * @src: Pointer to memory containing the input parameters + * The format of the parameter(s) is expeted to be Octet String + * @dst: Pointer to memory whare the result will be stored + * @src_len: Size of the input parameter + * @dst_len: Size of the output buffer. It needs to be at leaset + * as big as the expected result depending on the operation + * After operation it will be updated with the acctual size of the + * result. In case of error, where the dst_len was insufficient, + * it will be updated to the size required for the operation. + * @result_len: If not NULL this will be updated by the implementation to + * reflect the acctual size of the result result_len is still here. + * @__ctx: Start of private context data + */ +struct akcipher_request { + struct crypto_async_request base; + void *src; + void *dst; + unsigned int src_len; + unsigned int *dst_len; dst_len doesn't need to be a pointer. A simple int will do. +static inline int crypto_akcipher_encrypt(struct akcipher_request *req) +{ + struct crypto_akcipher *tfm = __crypto_akcipher_tfm(req-base.tfm); You should add a reqtfm helper like crypto_aead_reqtfm so that implementors don't need to do this ugly __crypto_akcipher_tfm. In fact you already have that helper so you just need to use it. Thanks, -- Email: Herbert Xu herb...@gondor.apana.org.au Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/