]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
crypto: salsa20 - export generic helpers
authorEric Biggers <ebiggers@google.com>
Fri, 5 Jan 2018 19:09:58 +0000 (11:09 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 12 Jan 2018 12:03:42 +0000 (23:03 +1100)
Export the Salsa20 constants, transform context, and initialization
functions so that they can be reused by the x86 implementation.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/salsa20_generic.c
include/crypto/salsa20.h [new file with mode: 0644]

index 8c77bc78a09f2693a1b8acf4e8748d10ced93da7..5074006a56c358c9ade929d1be3139dcc8ae77a3 100644 (file)
 
 #include <asm/unaligned.h>
 #include <crypto/internal/skcipher.h>
+#include <crypto/salsa20.h>
 #include <linux/module.h>
 
-#define SALSA20_IV_SIZE        8
-#define SALSA20_MIN_KEY_SIZE  16
-#define SALSA20_MAX_KEY_SIZE  32
-#define SALSA20_BLOCK_SIZE    64
-
-struct salsa20_ctx {
-       u32 initial_state[16];
-};
-
 static void salsa20_block(u32 *state, __le32 *stream)
 {
        u32 x[16];
@@ -101,15 +93,16 @@ static void salsa20_docrypt(u32 *state, u8 *dst, const u8 *src,
        }
 }
 
-static void salsa20_init(u32 *state, const struct salsa20_ctx *ctx,
+void crypto_salsa20_init(u32 *state, const struct salsa20_ctx *ctx,
                         const u8 *iv)
 {
        memcpy(state, ctx->initial_state, sizeof(ctx->initial_state));
        state[6] = get_unaligned_le32(iv + 0);
        state[7] = get_unaligned_le32(iv + 4);
 }
+EXPORT_SYMBOL_GPL(crypto_salsa20_init);
 
-static int salsa20_setkey(struct crypto_skcipher *tfm, const u8 *key,
+int crypto_salsa20_setkey(struct crypto_skcipher *tfm, const u8 *key,
                          unsigned int keysize)
 {
        static const char sigma[16] = "expand 32-byte k";
@@ -150,6 +143,7 @@ static int salsa20_setkey(struct crypto_skcipher *tfm, const u8 *key,
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(crypto_salsa20_setkey);
 
 static int salsa20_crypt(struct skcipher_request *req)
 {
@@ -161,7 +155,7 @@ static int salsa20_crypt(struct skcipher_request *req)
 
        err = skcipher_walk_virt(&walk, req, true);
 
-       salsa20_init(state, ctx, walk.iv);
+       crypto_salsa20_init(state, ctx, walk.iv);
 
        while (walk.nbytes > 0) {
                unsigned int nbytes = walk.nbytes;
@@ -189,7 +183,7 @@ static struct skcipher_alg alg = {
        .max_keysize            = SALSA20_MAX_KEY_SIZE,
        .ivsize                 = SALSA20_IV_SIZE,
        .chunksize              = SALSA20_BLOCK_SIZE,
-       .setkey                 = salsa20_setkey,
+       .setkey                 = crypto_salsa20_setkey,
        .encrypt                = salsa20_crypt,
        .decrypt                = salsa20_crypt,
 };
diff --git a/include/crypto/salsa20.h b/include/crypto/salsa20.h
new file mode 100644 (file)
index 0000000..19ed48a
--- /dev/null
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Common values for the Salsa20 algorithm
+ */
+
+#ifndef _CRYPTO_SALSA20_H
+#define _CRYPTO_SALSA20_H
+
+#include <linux/types.h>
+
+#define SALSA20_IV_SIZE                8
+#define SALSA20_MIN_KEY_SIZE   16
+#define SALSA20_MAX_KEY_SIZE   32
+#define SALSA20_BLOCK_SIZE     64
+
+struct crypto_skcipher;
+
+struct salsa20_ctx {
+       u32 initial_state[16];
+};
+
+void crypto_salsa20_init(u32 *state, const struct salsa20_ctx *ctx,
+                        const u8 *iv);
+int crypto_salsa20_setkey(struct crypto_skcipher *tfm, const u8 *key,
+                         unsigned int keysize);
+
+#endif /* _CRYPTO_SALSA20_H */