public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] staging: skein: Add Crypto API and Loadable Module support
@ 2014-10-23  2:22 Eric Rost
  2014-10-23  2:23 ` [PATCH v2 1/2] staging: skein: Add Crypto API support Eric Rost
  2014-10-23  2:24 ` [PATCH v2 2/2] staging: skein: Add Loadable Module Support Eric Rost
  0 siblings, 2 replies; 7+ messages in thread
From: Eric Rost @ 2014-10-23  2:22 UTC (permalink / raw)
  To: gregkh, jason, jake, antonysaraev; +Cc: devel, linux-kernel

This patchset adds crypto api support and loadable module support to the
skein driver.

Eric Rost (2):
  staging: skein: Add Crypto API support
  staging: skein: Add Loadable Module Support

 drivers/staging/skein/Kconfig         |  24 +---
 drivers/staging/skein/Makefile        |  13 +-
 drivers/staging/skein/skein.c         |   1 +
 drivers/staging/skein/skein.h         |   5 +
 drivers/staging/skein/skein_generic.c | 231 ++++++++++++++++++++++++++++++++++
 5 files changed, 248 insertions(+), 26 deletions(-)
 create mode 100644 drivers/staging/skein/skein_generic.c

-- 
2.1.1


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

* [PATCH v2 1/2] staging: skein: Add Crypto API support
  2014-10-23  2:22 [PATCH v2 0/2] staging: skein: Add Crypto API and Loadable Module support Eric Rost
@ 2014-10-23  2:23 ` Eric Rost
  2014-10-23 12:28   ` Dan Carpenter
  2014-10-23 12:42   ` Jason Cooper
  2014-10-23  2:24 ` [PATCH v2 2/2] staging: skein: Add Loadable Module Support Eric Rost
  1 sibling, 2 replies; 7+ messages in thread
From: Eric Rost @ 2014-10-23  2:23 UTC (permalink / raw)
  To: gregkh, jason, jake, antonysaraev; +Cc: devel, linux-kernel

Adds crypto API support for the skein module. Also collapses the
threefish module into the skein module.

Signed-off-by: Eric Rost <eric.rost@mybabylon.net>
---
 drivers/staging/skein/Kconfig         |  22 +------
 drivers/staging/skein/Makefile        |  13 ++--
 drivers/staging/skein/skein.c         |   1 +
 drivers/staging/skein/skein.h         |   5 ++
 drivers/staging/skein/skein_generic.c | 109 ++++++++++++++++++++++++++++++++++
 5 files changed, 125 insertions(+), 25 deletions(-)
 create mode 100644 drivers/staging/skein/skein_generic.c

diff --git a/drivers/staging/skein/Kconfig b/drivers/staging/skein/Kconfig
index b9172bf..de8bdd7 100644
--- a/drivers/staging/skein/Kconfig
+++ b/drivers/staging/skein/Kconfig
@@ -1,8 +1,8 @@
 config CRYPTO_SKEIN
 	bool "Skein digest algorithm"
 	depends on (X86 || UML_X86) && 64BIT && CRYPTO
-	select CRYPTO_THREEFISH
 	select CRYPTO_HASH
+	select CRYPTO_ALGAPI
 	help
 	  Skein secure hash algorithm is one of 5 finalists from the NIST SHA3
 	  competition.
@@ -12,21 +12,5 @@ config CRYPTO_SKEIN
 
 	  http://www.skein-hash.info/sites/default/files/skein1.3.pdf
 
-	  for more information.  This module depends on the threefish block
-	  cipher module.
-
-config CRYPTO_THREEFISH
-	bool "Threefish tweakable block cipher"
-	depends on (X86 || UML_X86) && 64BIT && CRYPTO
-	select CRYPTO_ALGAPI
-	help
-	  Threefish cipher algorithm is the tweakable block cipher underneath
-	  the Skein family of secure hash algorithms.  Skein is one of 5
-	  finalists from the NIST SHA3 competition.
-
-	  Skein is optimized for modern, 64bit processors and is highly
-	  customizable.  See:
-
-	  http://www.skein-hash.info/sites/default/files/skein1.3.pdf
-
-	  for more information.
+	  for more information. This module also contains the threefish block
+	  cipher algorithm.
diff --git a/drivers/staging/skein/Makefile b/drivers/staging/skein/Makefile
index a14aadd..382b041 100644
--- a/drivers/staging/skein/Makefile
+++ b/drivers/staging/skein/Makefile
@@ -1,9 +1,10 @@
 #
 # Makefile for the skein secure hash algorithm
 #
-obj-$(CONFIG_CRYPTO_SKEIN) +=   skein.o \
-				skein_api.o \
-				skein_block.o
-
-obj-$(CONFIG_CRYPTO_THREEFISH) += threefish_block.o \
-				  threefish_api.o
+obj-$(CONFIG_CRYPTO_SKEIN) += skein_mod.o
+skein_mod-y := skein.o \
+	skein_api.o \
+	skein_block.o \
+	threefish_block.o \
+	threefish_api.o \
+	skein_generic.o
diff --git a/drivers/staging/skein/skein.c b/drivers/staging/skein/skein.c
index 8cc8358..1c3933d 100644
--- a/drivers/staging/skein/skein.c
+++ b/drivers/staging/skein/skein.c
@@ -11,6 +11,7 @@
 #define  SKEIN_PORT_CODE /* instantiate any code in skein_port.h */
 
 #include <linux/string.h>       /* get the memcpy/memset functions */
+#include <linux/export.h>
 #include "skein.h" /* get the Skein API definitions   */
 #include "skein_iv.h"    /* get precomputed IVs */
 #include "skein_block.h"
diff --git a/drivers/staging/skein/skein.h b/drivers/staging/skein/skein.h
index e6669f1..79fac00 100644
--- a/drivers/staging/skein/skein.h
+++ b/drivers/staging/skein/skein.h
@@ -28,6 +28,11 @@
 **
 ***************************************************************************/
 
+/*Skein digest sizes for crypto api*/
+#define SKEIN256_DIGEST_BIT_SIZE (256)
+#define SKEIN512_DIGEST_BIT_SIZE (512)
+#define SKEIN1024_DIGEST_BIT_SIZE (1024)
+
 #ifndef rotl_64
 #define rotl_64(x, N)    (((x) << (N)) | ((x) >> (64-(N))))
 #endif
diff --git a/drivers/staging/skein/skein_generic.c b/drivers/staging/skein/skein_generic.c
new file mode 100644
index 0000000..14cc5bd
--- /dev/null
+++ b/drivers/staging/skein/skein_generic.c
@@ -0,0 +1,109 @@
+/*
+ * Cryptographic API.
+ *
+ * Skein256 Hash Algorithm.
+ *
+ * Derived from cryptoapi implementation, adapted for in-place
+ * scatterlist interface.
+ *
+ * Copyright (c) Eric Rost <eric.rost@mybabylon.net>
+ *
+ * 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 <crypto/internal/hash.h>
+#include <linux/init.h>
+#include <linux/mm.h>
+#include <linux/cryptohash.h>
+#include <linux/types.h>
+#include "skein.h"
+#include <asm/byteorder.h>
+
+static int skein256_init(struct shash_desc *desc)
+{
+	struct skein_256_ctx *sctx = shash_desc_ctx(desc);
+
+	int ret = skein_256_init(sctx, SKEIN256_DIGEST_BIT_SIZE);
+
+	return ret;
+}
+
+int skein256_update(struct shash_desc *desc, const u8 *data,
+			unsigned int len)
+{
+	struct skein_256_ctx *sctx = shash_desc_ctx(desc);
+	size_t hbl = (size_t) len;
+	int ret = skein_256_update(sctx, data, hbl);
+
+	return ret;
+}
+EXPORT_SYMBOL(skein256_update);
+
+/* Add padding and return the message digest. */
+static int skein256_final(struct shash_desc *desc, u8 *out)
+{
+	struct skein_256_ctx *sctx = shash_desc_ctx(desc);
+	int ret = skein_256_final(sctx, out);
+	return ret;
+}
+
+static int skein512_init(struct shash_desc *desc)
+{
+	struct skein_512_ctx *sctx = shash_desc_ctx(desc);
+
+	int ret = skein_512_init(sctx, SKEIN512_DIGEST_BIT_SIZE);
+
+	return ret;
+}
+
+int skein512_update(struct shash_desc *desc, const u8 *data,
+			unsigned int len)
+{
+	struct skein_512_ctx *sctx = shash_desc_ctx(desc);
+	size_t hbl = (size_t) len;
+	int ret = skein_512_update(sctx, data, hbl);
+
+	return ret;
+}
+EXPORT_SYMBOL(skein512_update);
+
+/* Add padding and return the message digest. */
+static int skein512_final(struct shash_desc *desc, u8 *out)
+{
+	struct skein_512_ctx *sctx = shash_desc_ctx(desc);
+	int ret = skein_512_final(sctx, out);
+	return ret;
+}
+
+static int skein1024_init(struct shash_desc *desc)
+{
+	struct skein_1024_ctx *sctx = shash_desc_ctx(desc);
+
+	int ret = skein_1024_init(sctx, SKEIN1024_DIGEST_BIT_SIZE);
+
+	return ret;
+}
+
+int skein1024_update(struct shash_desc *desc, const u8 *data,
+			unsigned int len)
+{
+	struct skein_1024_ctx *sctx = shash_desc_ctx(desc);
+	size_t hbl = (size_t) len;
+	int ret = skein_1024_update(sctx, data, hbl);
+
+	return ret;
+}
+EXPORT_SYMBOL(skein1024_update);
+
+/* Add padding and return the message digest. */
+static int skein1024_final(struct shash_desc *desc, u8 *out)
+{
+	struct skein_1024_ctx *sctx = shash_desc_ctx(desc);
+	int ret = skein_1024_final(sctx, out);
+	return ret;
+}
+
+
-- 
2.1.1


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

* [PATCH v2 2/2] staging: skein: Add Loadable Module Support
  2014-10-23  2:22 [PATCH v2 0/2] staging: skein: Add Crypto API and Loadable Module support Eric Rost
  2014-10-23  2:23 ` [PATCH v2 1/2] staging: skein: Add Crypto API support Eric Rost
@ 2014-10-23  2:24 ` Eric Rost
  2014-10-23 12:33   ` Dan Carpenter
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Rost @ 2014-10-23  2:24 UTC (permalink / raw)
  To: gregkh, jason, jake, antonysaraev; +Cc: devel, linux-kernel

Adds loadable module support for skein_mod, containing skein256,
skein512, and skein1024 algorithms.

Signed-off-by: Eric Rost <eric.rost@mybabylon.net>
---
 drivers/staging/skein/Kconfig         |   2 +-
 drivers/staging/skein/skein_generic.c | 122 ++++++++++++++++++++++++++++++++++
 2 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/skein/Kconfig b/drivers/staging/skein/Kconfig
index de8bdd7..012a823 100644
--- a/drivers/staging/skein/Kconfig
+++ b/drivers/staging/skein/Kconfig
@@ -1,5 +1,5 @@
 config CRYPTO_SKEIN
-	bool "Skein digest algorithm"
+	tristate "Skein digest algorithm"
 	depends on (X86 || UML_X86) && 64BIT && CRYPTO
 	select CRYPTO_HASH
 	select CRYPTO_ALGAPI
diff --git a/drivers/staging/skein/skein_generic.c b/drivers/staging/skein/skein_generic.c
index 14cc5bd..43e3cdf 100644
--- a/drivers/staging/skein/skein_generic.c
+++ b/drivers/staging/skein/skein_generic.c
@@ -16,6 +16,7 @@
  */
 #include <crypto/internal/hash.h>
 #include <linux/init.h>
+#include <linux/module.h>
 #include <linux/mm.h>
 #include <linux/cryptohash.h>
 #include <linux/types.h>
@@ -50,6 +51,22 @@ static int skein256_final(struct shash_desc *desc, u8 *out)
 	return ret;
 }
 
+static int skein256_export(struct shash_desc *desc, void *out)
+{
+	struct skein_256_ctx *sctx = shash_desc_ctx(desc);
+
+	memcpy(out, sctx, sizeof(*sctx));
+	return 0;
+}
+
+static int skein256_import(struct shash_desc *desc, const void *in)
+{
+	struct skein_256_ctx *sctx = shash_desc_ctx(desc);
+
+	memcpy(sctx, in, sizeof(*sctx));
+	return 0;
+}
+
 static int skein512_init(struct shash_desc *desc)
 {
 	struct skein_512_ctx *sctx = shash_desc_ctx(desc);
@@ -78,6 +95,22 @@ static int skein512_final(struct shash_desc *desc, u8 *out)
 	return ret;
 }
 
+static int skein512_export(struct shash_desc *desc, void *out)
+{
+	struct skein_512_ctx *sctx = shash_desc_ctx(desc);
+
+	memcpy(out, sctx, sizeof(*sctx));
+	return 0;
+}
+
+static int skein512_import(struct shash_desc *desc, const void *in)
+{
+	struct skein_512_ctx *sctx = shash_desc_ctx(desc);
+
+	memcpy(sctx, in, sizeof(*sctx));
+	return 0;
+}
+
 static int skein1024_init(struct shash_desc *desc)
 {
 	struct skein_1024_ctx *sctx = shash_desc_ctx(desc);
@@ -106,4 +139,93 @@ static int skein1024_final(struct shash_desc *desc, u8 *out)
 	return ret;
 }
 
+static int skein1024_export(struct shash_desc *desc, void *out)
+{
+	struct skein_1024_ctx *sctx = shash_desc_ctx(desc);
+
+	memcpy(out, sctx, sizeof(*sctx));
+	return 0;
+}
+
+static int skein1024_import(struct shash_desc *desc, const void *in)
+{
+	struct skein_1024_ctx *sctx = shash_desc_ctx(desc);
+
+	memcpy(sctx, in, sizeof(*sctx));
+	return 0;
+}
+
+static struct shash_alg alg256 = {
+	.digestsize	=	(SKEIN256_DIGEST_BIT_SIZE / 8),
+	.init		=	skein256_init,
+	.update		=	skein256_update,
+	.final		=	skein256_final,
+	.export		=	skein256_export,
+	.import		=	skein256_import,
+	.descsize	=	sizeof(struct skein_256_ctx),
+	.statesize	=	sizeof(struct skein_256_ctx),
+	.base		=	{
+		.cra_name		=	"skein256",
+		.cra_driver_name	=	"skein-mod",
+		.cra_flags		=	CRYPTO_ALG_TYPE_SHASH,
+		.cra_blocksize		=	SKEIN_256_BLOCK_BYTES,
+		.cra_module		=	THIS_MODULE,
+	}
+};
+
+static struct shash_alg alg512 = {
+	.digestsize	=	(SKEIN512_DIGEST_BIT_SIZE / 8),
+	.init		=	skein512_init,
+	.update		=	skein512_update,
+	.final		=	skein512_final,
+	.export		=	skein512_export,
+	.import		=	skein512_import,
+	.descsize	=	sizeof(struct skein_512_ctx),
+	.statesize	=	sizeof(struct skein_512_ctx),
+	.base		=	{
+		.cra_name		=	"skein512",
+		.cra_driver_name	=	"skein-mod",
+		.cra_flags		=	CRYPTO_ALG_TYPE_SHASH,
+		.cra_blocksize		=	SKEIN_512_BLOCK_BYTES,
+		.cra_module		=	THIS_MODULE,
+	}
+};
+
+static struct shash_alg alg1024 = {
+	.digestsize	=	(SKEIN1024_DIGEST_BIT_SIZE / 8),
+	.init		=	skein1024_init,
+	.update		=	skein1024_update,
+	.final		=	skein1024_final,
+	.export		=	skein1024_export,
+	.import		=	skein1024_import,
+	.descsize	=	sizeof(struct skein_1024_ctx),
+	.statesize	=	sizeof(struct skein_1024_ctx),
+	.base		=	{
+		.cra_name		=	"skein1024",
+		.cra_driver_name	=	"skein-mod",
+		.cra_flags		=	CRYPTO_ALG_TYPE_SHASH,
+		.cra_blocksize		=	SKEIN_1024_BLOCK_BYTES,
+		.cra_module		=	THIS_MODULE,
+	}
+};
+
+static int __init skein_generic_mod_init(void)
+{
+	return crypto_register_shash(&alg256) || crypto_register_shash(&alg512)
+		|| crypto_register_shash(&alg1024);
+}
+
+static void __exit skein_generic_mod_fini(void)
+{
+	crypto_unregister_shash(&alg256);
+	crypto_unregister_shash(&alg512);
+	crypto_unregister_shash(&alg1024);
+}
+
+module_init(skein_generic_mod_init);
+module_exit(skein_generic_mod_fini);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Skein Hash Algorithm");
 
+MODULE_ALIAS("skein");
-- 
2.1.1


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

* Re: [PATCH v2 1/2] staging: skein: Add Crypto API support
  2014-10-23  2:23 ` [PATCH v2 1/2] staging: skein: Add Crypto API support Eric Rost
@ 2014-10-23 12:28   ` Dan Carpenter
  2014-10-23 12:51     ` Jason Cooper
  2014-10-23 12:42   ` Jason Cooper
  1 sibling, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2014-10-23 12:28 UTC (permalink / raw)
  To: Eric Rost; +Cc: gregkh, jason, jake, antonysaraev, devel, linux-kernel

On Wed, Oct 22, 2014 at 09:23:51PM -0500, Eric Rost wrote:
> Adds crypto API support for the skein module. Also collapses the
> threefish module into the skein module.
> 

Why is this in staging anyway?  It seems very small and not terrible
code.  It could easily be sent to the main kernel.

> diff --git a/drivers/staging/skein/skein.h b/drivers/staging/skein/skein.h
> index e6669f1..79fac00 100644
> --- a/drivers/staging/skein/skein.h
> +++ b/drivers/staging/skein/skein.h
> @@ -28,6 +28,11 @@
>  **
>  ***************************************************************************/
>  
> +/*Skein digest sizes for crypto api*/
> +#define SKEIN256_DIGEST_BIT_SIZE (256)
> +#define SKEIN512_DIGEST_BIT_SIZE (512)
> +#define SKEIN1024_DIGEST_BIT_SIZE (1024)

Superfulous parens.

> +
>  #ifndef rotl_64
>  #define rotl_64(x, N)    (((x) << (N)) | ((x) >> (64-(N))))

Missing spaces.

#define rotl_64(x, N)    (((x) << (N)) | ((x) >> (64 - (N))))

Also this should be a function.  N and x are evaulated twice so it could
be a bug depending on how it's called.


>  #endif
> diff --git a/drivers/staging/skein/skein_generic.c b/drivers/staging/skein/skein_generic.c
> new file mode 100644
> index 0000000..14cc5bd
> --- /dev/null
> +++ b/drivers/staging/skein/skein_generic.c
> @@ -0,0 +1,109 @@
> +/*
> + * Cryptographic API.
> + *
> + * Skein256 Hash Algorithm.
> + *
> + * Derived from cryptoapi implementation, adapted for in-place
> + * scatterlist interface.
> + *
> + * Copyright (c) Eric Rost <eric.rost@mybabylon.net>
> + *
> + * 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 <crypto/internal/hash.h>
> +#include <linux/init.h>
> +#include <linux/mm.h>
> +#include <linux/cryptohash.h>
> +#include <linux/types.h>
> +#include "skein.h"
> +#include <asm/byteorder.h>
> +
> +static int skein256_init(struct shash_desc *desc)
> +{
> +	struct skein_256_ctx *sctx = shash_desc_ctx(desc);
> +

Don't put a blank line in the middle of the declaration block.

> +	int ret = skein_256_init(sctx, SKEIN256_DIGEST_BIT_SIZE);
> +
> +	return ret;
> +}

This should be:

static int skein256_init(struct shash_desc *desc)
{
	struct skein_256_ctx *sctx = shash_desc_ctx(desc);

	return skein_256_init(sctx, SKEIN256_DIGEST_BIT_SIZE);
}

> +
> +int skein256_update(struct shash_desc *desc, const u8 *data,
> +			unsigned int len)
> +{
> +	struct skein_256_ctx *sctx = shash_desc_ctx(desc);
> +	size_t hbl = (size_t) len;

Pointless case.  Pointless assignment.

> +	int ret = skein_256_update(sctx, data, hbl);
> +
> +	return ret;
> +}

This should be:

int skein256_update(struct shash_desc *desc, const u8 *data,
			unsigned int len)
{
	struct skein_256_ctx *sctx = shash_desc_ctx(desc);

	return skein_256_update(sctx, data, len);
}

> +EXPORT_SYMBOL(skein256_update);
> +
> +/* Add padding and return the message digest. */
> +static int skein256_final(struct shash_desc *desc, u8 *out)
> +{
> +	struct skein_256_ctx *sctx = shash_desc_ctx(desc);
> +	int ret = skein_256_final(sctx, out);
> +	return ret;
> +}

Same.

> +
> +static int skein512_init(struct shash_desc *desc)
> +{
> +	struct skein_512_ctx *sctx = shash_desc_ctx(desc);
> +
> +	int ret = skein_512_init(sctx, SKEIN512_DIGEST_BIT_SIZE);
> +
> +	return ret;
> +}

Same.

> +
> +int skein512_update(struct shash_desc *desc, const u8 *data,
> +			unsigned int len)
> +{
> +	struct skein_512_ctx *sctx = shash_desc_ctx(desc);
> +	size_t hbl = (size_t) len;
> +	int ret = skein_512_update(sctx, data, hbl);
> +
> +	return ret;
> +}

Same.

> +EXPORT_SYMBOL(skein512_update);
> +
> +/* Add padding and return the message digest. */
> +static int skein512_final(struct shash_desc *desc, u8 *out)
> +{
> +	struct skein_512_ctx *sctx = shash_desc_ctx(desc);
> +	int ret = skein_512_final(sctx, out);
> +	return ret;
> +}

Same.

> +
> +static int skein1024_init(struct shash_desc *desc)
> +{
> +	struct skein_1024_ctx *sctx = shash_desc_ctx(desc);
> +
> +	int ret = skein_1024_init(sctx, SKEIN1024_DIGEST_BIT_SIZE);
> +
> +	return ret;
> +}

Same.

> +
> +int skein1024_update(struct shash_desc *desc, const u8 *data,
> +			unsigned int len)
> +{
> +	struct skein_1024_ctx *sctx = shash_desc_ctx(desc);
> +	size_t hbl = (size_t) len;
> +	int ret = skein_1024_update(sctx, data, hbl);
> +
> +	return ret;
> +}

Same.

> +EXPORT_SYMBOL(skein1024_update);
> +
> +/* Add padding and return the message digest. */
> +static int skein1024_final(struct shash_desc *desc, u8 *out)
> +{
> +	struct skein_1024_ctx *sctx = shash_desc_ctx(desc);
> +	int ret = skein_1024_final(sctx, out);
> +	return ret;
> +}

Same.

regarsd,
dan carpenter



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

* Re: [PATCH v2 2/2] staging: skein: Add Loadable Module Support
  2014-10-23  2:24 ` [PATCH v2 2/2] staging: skein: Add Loadable Module Support Eric Rost
@ 2014-10-23 12:33   ` Dan Carpenter
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2014-10-23 12:33 UTC (permalink / raw)
  To: Eric Rost; +Cc: gregkh, jason, jake, antonysaraev, devel, linux-kernel

On Wed, Oct 22, 2014 at 09:24:37PM -0500, Eric Rost wrote:
> +static int __init skein_generic_mod_init(void)
> +{
> +	return crypto_register_shash(&alg256) || crypto_register_shash(&alg512)
> +		|| crypto_register_shash(&alg1024);

Shouldn't it unwind on error?

> +}

regards,
dan carpenter

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

* Re: [PATCH v2 1/2] staging: skein: Add Crypto API support
  2014-10-23  2:23 ` [PATCH v2 1/2] staging: skein: Add Crypto API support Eric Rost
  2014-10-23 12:28   ` Dan Carpenter
@ 2014-10-23 12:42   ` Jason Cooper
  1 sibling, 0 replies; 7+ messages in thread
From: Jason Cooper @ 2014-10-23 12:42 UTC (permalink / raw)
  To: Eric Rost; +Cc: gregkh, jake, antonysaraev, devel, linux-kernel

On Wed, Oct 22, 2014 at 09:23:51PM -0500, Eric Rost wrote:
> Adds crypto API support for the skein module. Also collapses the
> threefish module into the skein module.
> 
> Signed-off-by: Eric Rost <eric.rost@mybabylon.net>
> ---
>  drivers/staging/skein/Kconfig         |  22 +------
>  drivers/staging/skein/Makefile        |  13 ++--
>  drivers/staging/skein/skein.c         |   1 +
>  drivers/staging/skein/skein.h         |   5 ++
>  drivers/staging/skein/skein_generic.c | 109 ++++++++++++++++++++++++++++++++++
>  5 files changed, 125 insertions(+), 25 deletions(-)
>  create mode 100644 drivers/staging/skein/skein_generic.c
> 
> diff --git a/drivers/staging/skein/Kconfig b/drivers/staging/skein/Kconfig
> index b9172bf..de8bdd7 100644
> --- a/drivers/staging/skein/Kconfig
> +++ b/drivers/staging/skein/Kconfig
> @@ -1,8 +1,8 @@
>  config CRYPTO_SKEIN
>  	bool "Skein digest algorithm"
>  	depends on (X86 || UML_X86) && 64BIT && CRYPTO
> -	select CRYPTO_THREEFISH
>  	select CRYPTO_HASH
> +	select CRYPTO_ALGAPI
>  	help
>  	  Skein secure hash algorithm is one of 5 finalists from the NIST SHA3
>  	  competition.
> @@ -12,21 +12,5 @@ config CRYPTO_SKEIN
>  
>  	  http://www.skein-hash.info/sites/default/files/skein1.3.pdf
>  
> -	  for more information.  This module depends on the threefish block
> -	  cipher module.
> -
> -config CRYPTO_THREEFISH
> -	bool "Threefish tweakable block cipher"
> -	depends on (X86 || UML_X86) && 64BIT && CRYPTO
> -	select CRYPTO_ALGAPI
> -	help
> -	  Threefish cipher algorithm is the tweakable block cipher underneath
> -	  the Skein family of secure hash algorithms.  Skein is one of 5
> -	  finalists from the NIST SHA3 competition.
> -
> -	  Skein is optimized for modern, 64bit processors and is highly
> -	  customizable.  See:
> -
> -	  http://www.skein-hash.info/sites/default/files/skein1.3.pdf
> -
> -	  for more information.
> +	  for more information. This module also contains the threefish block
> +	  cipher algorithm.
> diff --git a/drivers/staging/skein/Makefile b/drivers/staging/skein/Makefile
> index a14aadd..382b041 100644
> --- a/drivers/staging/skein/Makefile
> +++ b/drivers/staging/skein/Makefile
> @@ -1,9 +1,10 @@
>  #
>  # Makefile for the skein secure hash algorithm
>  #
> -obj-$(CONFIG_CRYPTO_SKEIN) +=   skein.o \
> -				skein_api.o \
> -				skein_block.o
> -
> -obj-$(CONFIG_CRYPTO_THREEFISH) += threefish_block.o \
> -				  threefish_api.o
> +obj-$(CONFIG_CRYPTO_SKEIN) += skein_mod.o
> +skein_mod-y := skein.o \
> +	skein_api.o \
> +	skein_block.o \
> +	threefish_block.o \
> +	threefish_api.o \
> +	skein_generic.o

I'd prefer to rename skein.c so that we can do skein.ko.

> diff --git a/drivers/staging/skein/skein.c b/drivers/staging/skein/skein.c
> index 8cc8358..1c3933d 100644
> --- a/drivers/staging/skein/skein.c
> +++ b/drivers/staging/skein/skein.c
> @@ -11,6 +11,7 @@
>  #define  SKEIN_PORT_CODE /* instantiate any code in skein_port.h */
>  
>  #include <linux/string.h>       /* get the memcpy/memset functions */
> +#include <linux/export.h>

This shouldn't be needed anymore.

>  #include "skein.h" /* get the Skein API definitions   */
>  #include "skein_iv.h"    /* get precomputed IVs */
>  #include "skein_block.h"
> diff --git a/drivers/staging/skein/skein.h b/drivers/staging/skein/skein.h
> index e6669f1..79fac00 100644
> --- a/drivers/staging/skein/skein.h
> +++ b/drivers/staging/skein/skein.h
> @@ -28,6 +28,11 @@
>  **
>  ***************************************************************************/
>  
> +/*Skein digest sizes for crypto api*/
> +#define SKEIN256_DIGEST_BIT_SIZE (256)
> +#define SKEIN512_DIGEST_BIT_SIZE (512)
> +#define SKEIN1024_DIGEST_BIT_SIZE (1024)
> +
>  #ifndef rotl_64
>  #define rotl_64(x, N)    (((x) << (N)) | ((x) >> (64-(N))))
>  #endif
> diff --git a/drivers/staging/skein/skein_generic.c b/drivers/staging/skein/skein_generic.c
> new file mode 100644
> index 0000000..14cc5bd
> --- /dev/null
> +++ b/drivers/staging/skein/skein_generic.c
> @@ -0,0 +1,109 @@
> +/*
> + * Cryptographic API.
> + *
> + * Skein256 Hash Algorithm.
> + *
> + * Derived from cryptoapi implementation, adapted for in-place
> + * scatterlist interface.
> + *
> + * Copyright (c) Eric Rost <eric.rost@mybabylon.net>
> + *
> + * 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 <crypto/internal/hash.h>
> +#include <linux/init.h>
> +#include <linux/mm.h>
> +#include <linux/cryptohash.h>
> +#include <linux/types.h>
> +#include "skein.h"
> +#include <asm/byteorder.h>

I forgot to mention this last time.  Please put local includes last.
Also, please double check that all of these are need in this file.

> +
> +static int skein256_init(struct shash_desc *desc)
> +{
> +	struct skein_256_ctx *sctx = shash_desc_ctx(desc);
> +
> +	int ret = skein_256_init(sctx, SKEIN256_DIGEST_BIT_SIZE);
> +
> +	return ret;
> +}
> +
> +int skein256_update(struct shash_desc *desc, const u8 *data,
> +			unsigned int len)
> +{
> +	struct skein_256_ctx *sctx = shash_desc_ctx(desc);
> +	size_t hbl = (size_t) len;
> +	int ret = skein_256_update(sctx, data, hbl);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL(skein256_update);

Why export this symbol if it's registered with the crypto API?

Same the others after this one.

thx,

Jason.

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

* Re: [PATCH v2 1/2] staging: skein: Add Crypto API support
  2014-10-23 12:28   ` Dan Carpenter
@ 2014-10-23 12:51     ` Jason Cooper
  0 siblings, 0 replies; 7+ messages in thread
From: Jason Cooper @ 2014-10-23 12:51 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Eric Rost, gregkh, jake, antonysaraev, devel, linux-kernel

On Thu, Oct 23, 2014 at 03:28:45PM +0300, Dan Carpenter wrote:
> On Wed, Oct 22, 2014 at 09:23:51PM -0500, Eric Rost wrote:
> > Adds crypto API support for the skein module. Also collapses the
> > threefish module into the skein module.
> 
> Why is this in staging anyway?  It seems very small and not terrible
> code.  It could easily be sent to the main kernel.

Yes, we're almost there.  Loadable module support and integration into
the crypto API were what was blocking my proposal to move into mainline.
It might even happen this cycle if we can get this series into -next for
a bit.

thx,

Jason.

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

end of thread, other threads:[~2014-10-23 12:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-23  2:22 [PATCH v2 0/2] staging: skein: Add Crypto API and Loadable Module support Eric Rost
2014-10-23  2:23 ` [PATCH v2 1/2] staging: skein: Add Crypto API support Eric Rost
2014-10-23 12:28   ` Dan Carpenter
2014-10-23 12:51     ` Jason Cooper
2014-10-23 12:42   ` Jason Cooper
2014-10-23  2:24 ` [PATCH v2 2/2] staging: skein: Add Loadable Module Support Eric Rost
2014-10-23 12:33   ` Dan Carpenter

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