Skip to contentSkip to conversation

staging: skein: CryptoAPI and Module Support

PATCH Superseded Eric Rost 2 participants 10 messages Oct 24, 2014 Staging

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Eric Rost

author
#0 lore raw

v5 cover staging: skein: CryptoAPI and Module Support

Adds CryptoAPI and Module support to Skein Hash Algorithm. Also inlines rotl_64 macro, and removes nonexistent header references.

Eric Rost (7):
staging: skein: Collapses threefish module
staging: skein: Renames skein to skein_base
staging: skein: Adds CryptoAPI Support
staging: skein: Adds Loadable Module Support
staging: skein: Inlines rotl_64
staging: skein: Removes unneeded #define
staging: skein: Removes skein_debug include

 drivers/staging/skein/Kconfig         |  24 +-
 drivers/staging/skein/Makefile        |  13 +-
 drivers/staging/skein/skein.c         | 883 ----------------------------------
 drivers/staging/skein/skein.h         | 346 -------------
 drivers/staging/skein/skein_api.h     |   2 +-
 drivers/staging/skein/skein_base.c    | 882 +++++++++++++++++++++++++++++++++
 drivers/staging/skein/skein_base.h    | 345 +++++++++++++
 drivers/staging/skein/skein_block.c   |   2 +-
 drivers/staging/skein/skein_block.h   |   2 +-
 drivers/staging/skein/skein_generic.c | 208 ++++++++
 drivers/staging/skein/skein_iv.h      |   2 +-
 drivers/staging/skein/threefish_api.h |   2 +-
 12 files changed, 1451 insertions(+), 1260 deletions(-)
 delete mode 100644 drivers/staging/skein/skein.c
 delete mode 100644 drivers/staging/skein/skein.h
 create mode 100644 drivers/staging/skein/skein_base.c
 create mode 100644 drivers/staging/skein/skein_base.h
 create mode 100644 drivers/staging/skein/skein_generic.c
Signature · 1 line
2.1.1
author
#1 lore raw

PATCH v5 1/7 staging: skein: Collapses threefish module

Collapses threefish module into skein module.

---
 drivers/staging/skein/Kconfig  | 22 +++-------------------
 drivers/staging/skein/Makefile | 11 +++++------
 2 files changed, 8 insertions(+), 25 deletions(-)
drivers/staging/skein/Kconfig +3 -19
index b9172bf..de8bdd7 100644
@@ -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.
drivers/staging/skein/Makefile +5 -6
index a14aadd..4b60171 100644
@@ -1,9 +1,8 @@
 #
 # 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.o \
+			      skein_api.o \
+			      skein_block.o \
+			      threefish_block.o \
+			      threefish_api.o
Signature · 1 line
2.1.1
author
#2 lore raw

PATCH v5 2/7 staging: skein: Renames skein to skein_base

In reply to Eric Rost

Renames skein.c to skein_base.c and skein.h to skein_base.h

---
 drivers/staging/skein/Makefile        |   2 +-
 drivers/staging/skein/skein.c         | 883 ---------------------------------
 drivers/staging/skein/skein.h         | 346 -------------
 drivers/staging/skein/skein_api.h     |   2 +-
 drivers/staging/skein/skein_base.c    | 884 ++++++++++++++++++++++++++++++++++
 drivers/staging/skein/skein_base.h    | 351 ++++++++++++++
 drivers/staging/skein/skein_block.c   |   2 +-
 drivers/staging/skein/skein_block.h   |   2 +-
 drivers/staging/skein/skein_iv.h      |   2 +-
 drivers/staging/skein/threefish_api.h |   2 +-
 10 files changed, 1241 insertions(+), 1235 deletions(-)
 delete mode 100644 drivers/staging/skein/skein.c
 delete mode 100644 drivers/staging/skein/skein.h
 create mode 100644 drivers/staging/skein/skein_base.c
 create mode 100644 drivers/staging/skein/skein_base.h
drivers/staging/skein/Makefile +1 -1
index 4b60171..ca746a9 100644
@@ -1,7 +1,7 @@
 #
 # Makefile for the skein secure hash algorithm
 #
-obj-$(CONFIG_CRYPTO_SKEIN) += skein.o \
+obj-$(CONFIG_CRYPTO_SKEIN) += skein_base.o \
 			      skein_api.o \
 			      skein_block.o \
 			      threefish_block.o \
drivers/staging/skein/skein.c deleted +0 -883

883 lines not on this page · raw message

drivers/staging/skein/skein.h deleted +0 -346

346 lines not on this page · raw message

drivers/staging/skein/skein_api.h +1 -1
index e02fa19..171b875 100644
@@ -79,7 +79,7 @@ OTHER DEALINGS IN THE SOFTWARE.
  */
 
 #include <linux/types.h>
-#include "skein.h"
+#include "skein_base.h"
 
 /**
  * Which Skein size to use
drivers/staging/skein/skein_base.c new file +884 -0

884 lines not on this page · raw message

drivers/staging/skein/skein_base.h new file +351 -0

351 lines not on this page · raw message

drivers/staging/skein/skein_block.c +1 -1
index 88bc718..36b0b40 100644
@@ -15,7 +15,7 @@
 ************************************************************************/
 
 #include <linux/string.h>
-#include "skein.h"
+#include "skein_base.h"
 #include "skein_block.h"
 
 #ifndef SKEIN_USE_ASM
drivers/staging/skein/skein_block.h +1 -1
index bd7bdc3..9d40f4a 100644
@@ -10,7 +10,7 @@
 #ifndef _SKEIN_BLOCK_H_
 #define _SKEIN_BLOCK_H_
 
-#include "skein.h" /* get the Skein API definitions   */
+#include "skein_base.h" /* get the Skein API definitions   */
 
 void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blk_ptr,
 			     size_t blk_cnt, size_t byte_cnt_add);
drivers/staging/skein/skein_iv.h +1 -1
index d9dc1d5..8a06314 100644
@@ -1,7 +1,7 @@
 #ifndef _SKEIN_IV_H_
 #define _SKEIN_IV_H_
 
-#include "skein.h"    /* get Skein macros and types */
+#include "skein_base.h"    /* get Skein macros and types */
 
 /*
 ***************** Pre-computed Skein IVs *******************
drivers/staging/skein/threefish_api.h +1 -1
index 8d5ddf8..8e0a0b7 100644
@@ -29,7 +29,7 @@
  */
 
 #include <linux/types.h>
-#include "skein.h"
+#include "skein_base.h"
 
 #define KEY_SCHEDULE_CONST 0x1BD11BDAA9FC1A22L
 
Signature · 1 line
2.1.1
#3 lore raw

Re: [PATCH v5 2/7] staging: skein: Renames skein to skein_base

Quoted 1 line · Eric Rost

Renames skein.c to skein_base.c and skein.h to skein_base.h

It's worth a mention in here that this is in preparation for skein.ko.

Quoted 17 lines
---
 drivers/staging/skein/Makefile        |   2 +-
 drivers/staging/skein/skein.c         | 883 ---------------------------------
 drivers/staging/skein/skein.h         | 346 -------------
 drivers/staging/skein/skein_api.h     |   2 +-
 drivers/staging/skein/skein_base.c    | 884 ++++++++++++++++++++++++++++++++++
 drivers/staging/skein/skein_base.h    | 351 ++++++++++++++
 drivers/staging/skein/skein_block.c   |   2 +-
 drivers/staging/skein/skein_block.h   |   2 +-
 drivers/staging/skein/skein_iv.h      |   2 +-
 drivers/staging/skein/threefish_api.h |   2 +-
 10 files changed, 1241 insertions(+), 1235 deletions(-)
 delete mode 100644 drivers/staging/skein/skein.c
 delete mode 100644 drivers/staging/skein/skein.h
 create mode 100644 drivers/staging/skein/skein_base.c
 create mode 100644 drivers/staging/skein/skein_base.h

you can add '-M' to diff or format-patch to detect renames. It'll make this patch a *lot* smaller, and allow us to see more easily that nothing changed. Well, other than the #include rename inside {skein.c ->skein_base.c}.

thx,

Jason.

author
#4 lore raw

PATCH v5 3/7 staging: skein: Adds CryptoAPI Support

In reply to Eric Rost

Adds CryptoAPI support to the Skein Hashing Algorithm driver.

---
 drivers/staging/skein/Makefile        |   3 +-
 drivers/staging/skein/skein_generic.c | 191 ++++++++++++++++++++++++++++++++++
 2 files changed, 193 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/skein/skein_generic.c
drivers/staging/skein/Makefile +2 -1
index ca746a9..d8177cc 100644
@@ -5,4 +5,5 @@ obj-$(CONFIG_CRYPTO_SKEIN) += skein_base.o \
 			      skein_api.o \
 			      skein_block.o \
 			      threefish_block.o \
-			      threefish_api.o
+			      threefish_api.o \
+			      skein_generic.o
drivers/staging/skein/skein_generic.c new file +191 -0

191 lines not on this page · raw message

Signature · 1 line
2.1.1
#5 lore raw

Re: [PATCH v5 3/7] staging: skein: Adds CryptoAPI Support

Eric,

We're almost there... :)

Quoted 25 lines · Eric Rost

Adds CryptoAPI support to the Skein Hashing Algorithm driver.

---
 drivers/staging/skein/Makefile        |   3 +-
 drivers/staging/skein/skein_generic.c | 191 ++++++++++++++++++++++++++++++++++
 2 files changed, 193 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/skein/skein_generic.c
drivers/staging/skein/Makefile +2 -1
index ca746a9..d8177cc 100644
@@ -5,4 +5,5 @@ obj-$(CONFIG_CRYPTO_SKEIN) += skein_base.o \
 			      skein_api.o \
 			      skein_block.o \
 			      threefish_block.o \
-			      threefish_api.o
+			      threefish_api.o \
+			      skein_generic.o
drivers/staging/skein/skein_generic.c new file +0 -0
new file mode 100644
index 0000000..39332e8

...

drivers/staging/skein/skein_generic.c line 189

Quoted 11 lines
drivers/staging/skein/skein_generic.c new file +11 -0
+static int __init skein_generic_init(void)
+{
+	if (crypto_register_shash(&alg256) || crypto_register_shash(&alg512)
+		|| crypto_register_shash(&alg1024)) {
+		crypto_unregister_shash(&alg256);
+		crypto_unregister_shash(&alg512);
+		crypto_unregister_shash(&alg1024);
+		return -1;
+	}
+	return 0;
+}

This really needs to be something like:

	if (crypto_register_shash(&alg256))
		goto bail;
	if (crypto_register_shash(&alg512))
		goto unreg256;
	if (crypto_register_shash(&alg1024))
		goto unreg512;

	return 0;

unreg512:

	crypto_unregister_shash(&alg512);
unreg256:
	crypto_unregister_shash(&alg256);
bail:
	return -1;

thx,

Jason.

author
#6 lore raw

PATCH v5 4/7 staging: skein: Adds Loadable Module Support

In reply to Eric Rost

Adds loadable module support to the Skein Hashing Algorithm driver.

---
 drivers/staging/skein/Kconfig         |  2 +-
 drivers/staging/skein/Makefile        | 13 +++++++------
 drivers/staging/skein/skein_generic.c | 19 ++++++++++++++++++-
 3 files changed, 26 insertions(+), 8 deletions(-)
drivers/staging/skein/Kconfig +1 -1
index de8bdd7..012a823 100644
@@ -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
drivers/staging/skein/Makefile +7 -6
index d8177cc..b7f947f 100644
@@ -1,9 +1,10 @@
 #
 # Makefile for the skein secure hash algorithm
 #
-obj-$(CONFIG_CRYPTO_SKEIN) += skein_base.o \
-			      skein_api.o \
-			      skein_block.o \
-			      threefish_block.o \
-			      threefish_api.o \
-			      skein_generic.o
+obj-$(CONFIG_CRYPTO_SKEIN) += skein.o
+skein-y := skein_base.o \
+	   skein_api.o \
+	   skein_block.o \
+	   threefish_block.o \
+	   threefish_api.o \
+	   skein_generic.o
drivers/staging/skein/skein_generic.c +18 -1
index 39332e8..46466d0 100644
@@ -16,6 +16,7 @@
  */
 #include <linux/types.h>
 #include <linux/init.h>
+#include <linux/module.h>
 #include <crypto/internal/hash.h>
 #include "skein_base.h"
 
@@ -139,6 +140,7 @@ static struct shash_alg alg256 = {
 		.cra_driver_name	=	"skein",
 		.cra_flags		=	CRYPTO_ALG_TYPE_SHASH,
 		.cra_blocksize		=	SKEIN_256_BLOCK_BYTES,
+		.cra_module		=	THIS_MODULE,
 	}
 };
 
@@ -156,6 +158,7 @@ static struct shash_alg alg512 = {
 		.cra_driver_name	=	"skein",
 		.cra_flags		=	CRYPTO_ALG_TYPE_SHASH,
 		.cra_blocksize		=	SKEIN_512_BLOCK_BYTES,
+		.cra_module		=	THIS_MODULE,
 	}
 };
 
@@ -173,6 +176,7 @@ static struct shash_alg alg1024 = {
 		.cra_driver_name	=	"skein",
 		.cra_flags		=	CRYPTO_ALG_TYPE_SHASH,
 		.cra_blocksize		=	SKEIN_1024_BLOCK_BYTES,
+		.cra_module		=	THIS_MODULE,
 	}
 };
 
@@ -188,4 +192,17 @@ static int __init skein_generic_init(void)
 	return 0;
 }
 
-device_initcall(skein_generic_init);
+static void __exit skein_generic_fini(void)
+{
+	crypto_unregister_shash(&alg256);
+	crypto_unregister_shash(&alg512);
+	crypto_unregister_shash(&alg1024);
+}
+
+module_init(skein_generic_init);
+module_exit(skein_generic_fini);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Skein Hash Algorithm");
+
+MODULE_ALIAS("skein");
Signature · 1 line
2.1.1
author
#7 lore raw

PATCH v5 5/7 staging: skein: Inlines rotl_64

In reply to Eric Rost

Inlines the rotl_64 macro.

---
 drivers/staging/skein/skein_base.h | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/staging/skein/skein_base.h +10 -9
index 9f10af9..0111fa4 100644
@@ -33,10 +33,6 @@
 #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
-
 /* below two prototype assume we are handed aligned data */
 #define skein_put64_lsb_first(dst08, src64, b_cnt) memcpy(dst08, src64, b_cnt)
 #define skein_get64_lsb_first(dst64, src08, w_cnt) \
@@ -49,12 +45,12 @@ enum {
 	SKEIN_BAD_HASHLEN     =      2
 };
 
-#define  SKEIN_MODIFIER_WORDS   (2) /* number of modifier (tweak) words */
+#define  SKEIN_MODIFIER_WORDS   2 /* number of modifier (tweak) words */
 
-#define  SKEIN_256_STATE_WORDS  (4)
-#define  SKEIN_512_STATE_WORDS  (8)
-#define  SKEIN_1024_STATE_WORDS (16)
-#define  SKEIN_MAX_STATE_WORDS (16)
+#define  SKEIN_256_STATE_WORDS  4
+#define  SKEIN_512_STATE_WORDS  8
+#define  SKEIN_1024_STATE_WORDS 16
+#define  SKEIN_MAX_STATE_WORDS	16
 
 #define  SKEIN_256_STATE_BYTES  (8*SKEIN_256_STATE_WORDS)
 #define  SKEIN_512_STATE_BYTES  (8*SKEIN_512_STATE_WORDS)
@@ -92,6 +88,11 @@ struct skein_1024_ctx { /* 1024-bit Skein hash context structure */
 	u8 b[SKEIN_1024_BLOCK_BYTES];	/* partial block buf (8-byte aligned) */
 };
 
+static inline int rotl_64(int x, int N)
+{
+	return (x << N) | (x >> (64 - N));
+}
+
 /* Skein APIs for (incremental) "straight hashing" */
 int skein_256_init(struct skein_256_ctx *ctx, size_t hash_bit_len);
 int skein_512_init(struct skein_512_ctx *ctx, size_t hash_bit_len);
Signature · 1 line
2.1.1
author
#8 lore raw

PATCH v5 6/7 staging: skein: Removes unneeded #define

In reply to Eric Rost

Removes unneeded #define SKEIN_PORT_CODE since skein_port.h is nonexistent.

---
 drivers/staging/skein/skein_base.c | 2 --
 1 file changed, 2 deletions(-)
drivers/staging/skein/skein_base.c +0 -2
index e0994ea..ebc436a 100644
@@ -8,8 +8,6 @@
 **
 ************************************************************************/
 
-#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_base.h" /* get the Skein API definitions   */
Signature · 1 line
2.1.1
author
#9 lore raw

PATCH v5 7/7 staging: skein: Removes skein_debug include

In reply to Eric Rost

Removes skein_debug.h include since skein_debug.h is nonexistent.

---
 drivers/staging/skein/skein_base.h | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/staging/skein/skein_base.h +1 -8
index 0111fa4..5b69e5a 100644
@@ -15,10 +15,6 @@
 **
 ** The "default" note explains what happens when the switch is not defined.
 **
-**  SKEIN_DEBUG            -- make callouts from inside Skein code
-**                            to examine/display intermediate values.
-**                            [default: no callouts (no overhead)]
-**
 **  SKEIN_ERR_CHECK        -- how error checking is handled inside Skein
 **                            code. If not defined, most error checking
 **                            is disabled (for performance). Otherwise,
@@ -282,15 +278,12 @@ int skein_1024_output(struct skein_1024_ctx *ctx, u8 *hash_val);
 /*****************************************************************
 ** "Internal" Skein definitions for debugging and error checking
 ******************************************************************/
-#ifdef SKEIN_DEBUG             /* examine/display intermediate values? */
-#include "skein_debug.h"
-#else                           /* default is no callouts */
 #define skein_show_block(bits, ctx, x, blk_ptr, w_ptr, ks_event_ptr, ks_odd_ptr)
 #define skein_show_round(bits, ctx, r, x)
 #define skein_show_r_ptr(bits, ctx, r, x_ptr)
 #define skein_show_final(bits, ctx, cnt, out_ptr)
 #define skein_show_key(bits, ctx, key, key_bytes)
-#endif
+
 
 /* ignore all asserts, for performance */
 #define skein_assert_ret(x, ret_code)
Signature · 1 line
2.1.1