forked from mirrors/linux
		
	[CRYPTO] salsa20: Salsa20 stream cipher
This patch implements the Salsa20 stream cipher using the blkcipher interface. The core cipher code comes from Daniel Bernstein's submission to eSTREAM: http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/ecrypt/trunk/submissions/salsa20/full/ref/ The test vectors comes from: http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/ecrypt/trunk/submissions/salsa20/full/ It has been tested successfully with "modprobe tcrypt mode=34" on an UML instance. Signed-off-by: Tan Swee Heng <thesweeheng@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
		
							parent
							
								
									332f8840f7
								
							
						
					
					
						commit
						2407d60872
					
				
					 5 changed files with 424 additions and 1 deletions
				
			
		| 
						 | 
					@ -454,6 +454,18 @@ config CRYPTO_SEED
 | 
				
			||||||
	  See also:
 | 
						  See also:
 | 
				
			||||||
	  <http://www.kisa.or.kr/kisa/seed/jsp/seed_eng.jsp>
 | 
						  <http://www.kisa.or.kr/kisa/seed/jsp/seed_eng.jsp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					config CRYPTO_SALSA20
 | 
				
			||||||
 | 
						tristate "Salsa20 stream cipher algorithm (EXPERIMENTAL)"
 | 
				
			||||||
 | 
						depends on EXPERIMENTAL
 | 
				
			||||||
 | 
						select CRYPTO_BLKCIPHER
 | 
				
			||||||
 | 
						help
 | 
				
			||||||
 | 
						  Salsa20 stream cipher algorithm.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						  Salsa20 is a stream cipher submitted to eSTREAM, the ECRYPT
 | 
				
			||||||
 | 
						  Stream Cipher Project. See <http://www.ecrypt.eu.org/stream/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						  The Salsa20 stream cipher algorithm is designed by Daniel J.
 | 
				
			||||||
 | 
						  Bernstein <djb@cr.yp.to>. See <http://cr.yp.to/snuffle.html>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
config CRYPTO_DEFLATE
 | 
					config CRYPTO_DEFLATE
 | 
				
			||||||
	tristate "Deflate compression algorithm"
 | 
						tristate "Deflate compression algorithm"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,6 +49,7 @@ obj-$(CONFIG_CRYPTO_TEA) += tea.o
 | 
				
			||||||
obj-$(CONFIG_CRYPTO_KHAZAD) += khazad.o
 | 
					obj-$(CONFIG_CRYPTO_KHAZAD) += khazad.o
 | 
				
			||||||
obj-$(CONFIG_CRYPTO_ANUBIS) += anubis.o
 | 
					obj-$(CONFIG_CRYPTO_ANUBIS) += anubis.o
 | 
				
			||||||
obj-$(CONFIG_CRYPTO_SEED) += seed.o
 | 
					obj-$(CONFIG_CRYPTO_SEED) += seed.o
 | 
				
			||||||
 | 
					obj-$(CONFIG_CRYPTO_SALSA20) += salsa20_generic.o
 | 
				
			||||||
obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
 | 
					obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
 | 
				
			||||||
obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
 | 
					obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
 | 
				
			||||||
obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
 | 
					obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										243
									
								
								crypto/salsa20_generic.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										243
									
								
								crypto/salsa20_generic.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,243 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Salsa20: Salsa20 stream cipher algorithm
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (c) 2007 Tan Swee Heng <thesweeheng@gmail.com>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Derived from:
 | 
				
			||||||
 | 
					 * - salsa20.c: Public domain C code by Daniel J. Bernstein <djb@cr.yp.to>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Salsa20 is a stream cipher candidate in eSTREAM, the ECRYPT Stream
 | 
				
			||||||
 | 
					 * Cipher Project. It is designed by Daniel J. Bernstein <djb@cr.yp.to>.
 | 
				
			||||||
 | 
					 * More information about eSTREAM and Salsa20 can be found here:
 | 
				
			||||||
 | 
					 *   http://www.ecrypt.eu.org/stream/
 | 
				
			||||||
 | 
					 *   http://cr.yp.to/snuffle.html
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * 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/init.h>
 | 
				
			||||||
 | 
					#include <linux/module.h>
 | 
				
			||||||
 | 
					#include <linux/errno.h>
 | 
				
			||||||
 | 
					#include <linux/crypto.h>
 | 
				
			||||||
 | 
					#include <linux/types.h>
 | 
				
			||||||
 | 
					#include <crypto/algapi.h>
 | 
				
			||||||
 | 
					#include <asm/byteorder.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define SALSA20_IV_SIZE        8U
 | 
				
			||||||
 | 
					#define SALSA20_MIN_KEY_SIZE  16U
 | 
				
			||||||
 | 
					#define SALSA20_MAX_KEY_SIZE  32U
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Start of code taken from D. J. Bernstein's reference implementation.
 | 
				
			||||||
 | 
					 * With some modifications and optimizations made to suit our needs.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					salsa20-ref.c version 20051118
 | 
				
			||||||
 | 
					D. J. Bernstein
 | 
				
			||||||
 | 
					Public domain.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ROTATE(v,n) (((v) << (n)) | ((v) >> (32 - (n))))
 | 
				
			||||||
 | 
					#define XOR(v,w) ((v) ^ (w))
 | 
				
			||||||
 | 
					#define PLUS(v,w) (((v) + (w)))
 | 
				
			||||||
 | 
					#define PLUSONE(v) (PLUS((v),1))
 | 
				
			||||||
 | 
					#define U32TO8_LITTLE(p, v) \
 | 
				
			||||||
 | 
						{ (p)[0] = (v >>  0) & 0xff; (p)[1] = (v >>  8) & 0xff; \
 | 
				
			||||||
 | 
						  (p)[2] = (v >> 16) & 0xff; (p)[3] = (v >> 24) & 0xff; }
 | 
				
			||||||
 | 
					#define U8TO32_LITTLE(p)   \
 | 
				
			||||||
 | 
						(((u32)((p)[0])      ) | ((u32)((p)[1]) <<  8) | \
 | 
				
			||||||
 | 
						 ((u32)((p)[2]) << 16) | ((u32)((p)[3]) << 24)   )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct salsa20_ctx
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						u32 input[16];
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void salsa20_wordtobyte(u8 output[64], const u32 input[16])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						u32 x[16];
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memcpy(x, input, sizeof(x));
 | 
				
			||||||
 | 
						for (i = 20; i > 0; i -= 2) {
 | 
				
			||||||
 | 
							x[ 4] = XOR(x[ 4],ROTATE(PLUS(x[ 0],x[12]), 7));
 | 
				
			||||||
 | 
							x[ 8] = XOR(x[ 8],ROTATE(PLUS(x[ 4],x[ 0]), 9));
 | 
				
			||||||
 | 
							x[12] = XOR(x[12],ROTATE(PLUS(x[ 8],x[ 4]),13));
 | 
				
			||||||
 | 
							x[ 0] = XOR(x[ 0],ROTATE(PLUS(x[12],x[ 8]),18));
 | 
				
			||||||
 | 
							x[ 9] = XOR(x[ 9],ROTATE(PLUS(x[ 5],x[ 1]), 7));
 | 
				
			||||||
 | 
							x[13] = XOR(x[13],ROTATE(PLUS(x[ 9],x[ 5]), 9));
 | 
				
			||||||
 | 
							x[ 1] = XOR(x[ 1],ROTATE(PLUS(x[13],x[ 9]),13));
 | 
				
			||||||
 | 
							x[ 5] = XOR(x[ 5],ROTATE(PLUS(x[ 1],x[13]),18));
 | 
				
			||||||
 | 
							x[14] = XOR(x[14],ROTATE(PLUS(x[10],x[ 6]), 7));
 | 
				
			||||||
 | 
							x[ 2] = XOR(x[ 2],ROTATE(PLUS(x[14],x[10]), 9));
 | 
				
			||||||
 | 
							x[ 6] = XOR(x[ 6],ROTATE(PLUS(x[ 2],x[14]),13));
 | 
				
			||||||
 | 
							x[10] = XOR(x[10],ROTATE(PLUS(x[ 6],x[ 2]),18));
 | 
				
			||||||
 | 
							x[ 3] = XOR(x[ 3],ROTATE(PLUS(x[15],x[11]), 7));
 | 
				
			||||||
 | 
							x[ 7] = XOR(x[ 7],ROTATE(PLUS(x[ 3],x[15]), 9));
 | 
				
			||||||
 | 
							x[11] = XOR(x[11],ROTATE(PLUS(x[ 7],x[ 3]),13));
 | 
				
			||||||
 | 
							x[15] = XOR(x[15],ROTATE(PLUS(x[11],x[ 7]),18));
 | 
				
			||||||
 | 
							x[ 1] = XOR(x[ 1],ROTATE(PLUS(x[ 0],x[ 3]), 7));
 | 
				
			||||||
 | 
							x[ 2] = XOR(x[ 2],ROTATE(PLUS(x[ 1],x[ 0]), 9));
 | 
				
			||||||
 | 
							x[ 3] = XOR(x[ 3],ROTATE(PLUS(x[ 2],x[ 1]),13));
 | 
				
			||||||
 | 
							x[ 0] = XOR(x[ 0],ROTATE(PLUS(x[ 3],x[ 2]),18));
 | 
				
			||||||
 | 
							x[ 6] = XOR(x[ 6],ROTATE(PLUS(x[ 5],x[ 4]), 7));
 | 
				
			||||||
 | 
							x[ 7] = XOR(x[ 7],ROTATE(PLUS(x[ 6],x[ 5]), 9));
 | 
				
			||||||
 | 
							x[ 4] = XOR(x[ 4],ROTATE(PLUS(x[ 7],x[ 6]),13));
 | 
				
			||||||
 | 
							x[ 5] = XOR(x[ 5],ROTATE(PLUS(x[ 4],x[ 7]),18));
 | 
				
			||||||
 | 
							x[11] = XOR(x[11],ROTATE(PLUS(x[10],x[ 9]), 7));
 | 
				
			||||||
 | 
							x[ 8] = XOR(x[ 8],ROTATE(PLUS(x[11],x[10]), 9));
 | 
				
			||||||
 | 
							x[ 9] = XOR(x[ 9],ROTATE(PLUS(x[ 8],x[11]),13));
 | 
				
			||||||
 | 
							x[10] = XOR(x[10],ROTATE(PLUS(x[ 9],x[ 8]),18));
 | 
				
			||||||
 | 
							x[12] = XOR(x[12],ROTATE(PLUS(x[15],x[14]), 7));
 | 
				
			||||||
 | 
							x[13] = XOR(x[13],ROTATE(PLUS(x[12],x[15]), 9));
 | 
				
			||||||
 | 
							x[14] = XOR(x[14],ROTATE(PLUS(x[13],x[12]),13));
 | 
				
			||||||
 | 
							x[15] = XOR(x[15],ROTATE(PLUS(x[14],x[13]),18));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for (i = 0; i < 16; ++i)
 | 
				
			||||||
 | 
							x[i] = PLUS(x[i],input[i]);
 | 
				
			||||||
 | 
						for (i = 0; i < 16; ++i)
 | 
				
			||||||
 | 
							U32TO8_LITTLE(output + 4 * i,x[i]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const char sigma[16] = "expand 32-byte k";
 | 
				
			||||||
 | 
					static const char tau[16] = "expand 16-byte k";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void salsa20_keysetup(struct salsa20_ctx *ctx, const u8 *k, u32 kbytes)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						const char *constants;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ctx->input[1] = U8TO32_LITTLE(k + 0);
 | 
				
			||||||
 | 
						ctx->input[2] = U8TO32_LITTLE(k + 4);
 | 
				
			||||||
 | 
						ctx->input[3] = U8TO32_LITTLE(k + 8);
 | 
				
			||||||
 | 
						ctx->input[4] = U8TO32_LITTLE(k + 12);
 | 
				
			||||||
 | 
						if (kbytes == 32) { /* recommended */
 | 
				
			||||||
 | 
							k += 16;
 | 
				
			||||||
 | 
							constants = sigma;
 | 
				
			||||||
 | 
						} else { /* kbytes == 16 */
 | 
				
			||||||
 | 
							constants = tau;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						ctx->input[11] = U8TO32_LITTLE(k + 0);
 | 
				
			||||||
 | 
						ctx->input[12] = U8TO32_LITTLE(k + 4);
 | 
				
			||||||
 | 
						ctx->input[13] = U8TO32_LITTLE(k + 8);
 | 
				
			||||||
 | 
						ctx->input[14] = U8TO32_LITTLE(k + 12);
 | 
				
			||||||
 | 
						ctx->input[0] = U8TO32_LITTLE(constants + 0);
 | 
				
			||||||
 | 
						ctx->input[5] = U8TO32_LITTLE(constants + 4);
 | 
				
			||||||
 | 
						ctx->input[10] = U8TO32_LITTLE(constants + 8);
 | 
				
			||||||
 | 
						ctx->input[15] = U8TO32_LITTLE(constants + 12);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void salsa20_ivsetup(struct salsa20_ctx *ctx, const u8 *iv)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						ctx->input[6] = U8TO32_LITTLE(iv + 0);
 | 
				
			||||||
 | 
						ctx->input[7] = U8TO32_LITTLE(iv + 4);
 | 
				
			||||||
 | 
						ctx->input[8] = 0;
 | 
				
			||||||
 | 
						ctx->input[9] = 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void salsa20_encrypt_bytes(struct salsa20_ctx *ctx, u8 *dst,
 | 
				
			||||||
 | 
									  const u8 *src, unsigned int bytes)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						u8 buf[64];
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (dst != src)
 | 
				
			||||||
 | 
							memcpy(dst, src, bytes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (bytes) {
 | 
				
			||||||
 | 
							salsa20_wordtobyte(buf, ctx->input);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ctx->input[8] = PLUSONE(ctx->input[8]);
 | 
				
			||||||
 | 
							if (!ctx->input[8])
 | 
				
			||||||
 | 
								ctx->input[9] = PLUSONE(ctx->input[9]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (bytes <= 64) {
 | 
				
			||||||
 | 
								for (i = 0; i < bytes/4; ++i)
 | 
				
			||||||
 | 
									((u32*)dst)[i] ^= ((u32*)buf)[i];
 | 
				
			||||||
 | 
								for (i = bytes - bytes % 4; i < bytes; ++i)
 | 
				
			||||||
 | 
									dst[i] ^= buf[i];
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							for (i = 0; i < 64/4; ++i)
 | 
				
			||||||
 | 
								((u32*)dst)[i] ^= ((u32*)buf)[i];
 | 
				
			||||||
 | 
							bytes -= 64;
 | 
				
			||||||
 | 
							dst += 64;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * End of code taken from D. J. Bernstein's reference implementation.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int setkey(struct crypto_tfm *tfm, const u8 *key,
 | 
				
			||||||
 | 
							  unsigned int keysize)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct salsa20_ctx *ctx = crypto_tfm_ctx(tfm);
 | 
				
			||||||
 | 
						salsa20_keysetup(ctx, key, keysize);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int encrypt(struct blkcipher_desc *desc,
 | 
				
			||||||
 | 
							   struct scatterlist *dst, struct scatterlist *src,
 | 
				
			||||||
 | 
							   unsigned int nbytes)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct blkcipher_walk walk;
 | 
				
			||||||
 | 
						struct crypto_blkcipher *tfm = desc->tfm;
 | 
				
			||||||
 | 
						struct salsa20_ctx *ctx = crypto_blkcipher_ctx(tfm);
 | 
				
			||||||
 | 
						int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						blkcipher_walk_init(&walk, dst, src, nbytes);
 | 
				
			||||||
 | 
						err = blkcipher_walk_virt(desc, &walk);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						salsa20_ivsetup(ctx, walk.iv);
 | 
				
			||||||
 | 
						salsa20_encrypt_bytes(ctx, walk.dst.virt.addr,
 | 
				
			||||||
 | 
								      walk.src.virt.addr, nbytes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = blkcipher_walk_done(desc, &walk, 0);
 | 
				
			||||||
 | 
						return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static struct crypto_alg alg = {
 | 
				
			||||||
 | 
						.cra_name           =   "salsa20",
 | 
				
			||||||
 | 
						.cra_driver_name    =   "salsa20-generic",
 | 
				
			||||||
 | 
						.cra_priority       =   100,
 | 
				
			||||||
 | 
						.cra_flags          =   CRYPTO_ALG_TYPE_BLKCIPHER,
 | 
				
			||||||
 | 
						.cra_type           =   &crypto_blkcipher_type,
 | 
				
			||||||
 | 
						.cra_blocksize      =   1,
 | 
				
			||||||
 | 
						.cra_ctxsize        =   sizeof(struct salsa20_ctx),
 | 
				
			||||||
 | 
						.cra_alignmask      =	3,
 | 
				
			||||||
 | 
						.cra_module         =   THIS_MODULE,
 | 
				
			||||||
 | 
						.cra_list           =   LIST_HEAD_INIT(alg.cra_list),
 | 
				
			||||||
 | 
						.cra_u              =   {
 | 
				
			||||||
 | 
							.blkcipher = {
 | 
				
			||||||
 | 
								.setkey         =   setkey,
 | 
				
			||||||
 | 
								.encrypt        =   encrypt,
 | 
				
			||||||
 | 
								.decrypt        =   encrypt,
 | 
				
			||||||
 | 
								.min_keysize    =   SALSA20_MIN_KEY_SIZE,
 | 
				
			||||||
 | 
								.max_keysize    =   SALSA20_MAX_KEY_SIZE,
 | 
				
			||||||
 | 
								.ivsize         =   SALSA20_IV_SIZE,
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int __init init(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return crypto_register_alg(&alg);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void __exit fini(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						crypto_unregister_alg(&alg);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module_init(init);
 | 
				
			||||||
 | 
					module_exit(fini);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					MODULE_LICENSE("GPL");
 | 
				
			||||||
 | 
					MODULE_DESCRIPTION ("Salsa20 stream cipher algorithm");
 | 
				
			||||||
 | 
					MODULE_ALIAS("salsa20");
 | 
				
			||||||
| 
						 | 
					@ -80,7 +80,7 @@ static char *check[] = {
 | 
				
			||||||
	"cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
 | 
						"cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
 | 
				
			||||||
	"arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
 | 
						"arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
 | 
				
			||||||
	"khazad", "wp512", "wp384", "wp256", "tnepres", "xeta",  "fcrypt",
 | 
						"khazad", "wp512", "wp384", "wp256", "tnepres", "xeta",  "fcrypt",
 | 
				
			||||||
	"camellia", "seed", NULL
 | 
						"camellia", "seed", "salsa20", NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void hexdump(unsigned char *buf, unsigned int len)
 | 
					static void hexdump(unsigned char *buf, unsigned int len)
 | 
				
			||||||
| 
						 | 
					@ -1309,6 +1309,12 @@ static void do_test(void)
 | 
				
			||||||
		test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
 | 
							test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						case 34:
 | 
				
			||||||
 | 
							test_cipher("salsa20", ENCRYPT,
 | 
				
			||||||
 | 
								    salsa20_stream_enc_tv_template,
 | 
				
			||||||
 | 
								    SALSA20_STREAM_ENC_TEST_VECTORS);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	case 100:
 | 
						case 100:
 | 
				
			||||||
		test_hash("hmac(md5)", hmac_md5_tv_template,
 | 
							test_hash("hmac(md5)", hmac_md5_tv_template,
 | 
				
			||||||
			  HMAC_MD5_TEST_VECTORS);
 | 
								  HMAC_MD5_TEST_VECTORS);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										161
									
								
								crypto/tcrypt.h
									
									
									
									
									
								
							
							
						
						
									
										161
									
								
								crypto/tcrypt.h
									
									
									
									
									
								
							| 
						 | 
					@ -4644,6 +4644,167 @@ static struct cipher_testvec seed_dec_tv_template[] = {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define SALSA20_STREAM_ENC_TEST_VECTORS 4
 | 
				
			||||||
 | 
					static struct cipher_testvec salsa20_stream_enc_tv_template[] = {
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						* Testvectors from verified.test-vectors submitted to ECRYPT.
 | 
				
			||||||
 | 
						* They are truncated to size 39, 64, 111, 129 to test a variety
 | 
				
			||||||
 | 
						* of input length.
 | 
				
			||||||
 | 
						*/
 | 
				
			||||||
 | 
						{ /* Set 3, vector 0 */
 | 
				
			||||||
 | 
							.key	= {
 | 
				
			||||||
 | 
								    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
 | 
				
			||||||
 | 
								    0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
 | 
				
			||||||
 | 
								  },
 | 
				
			||||||
 | 
							.klen	= 16,
 | 
				
			||||||
 | 
							.iv     = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
 | 
				
			||||||
 | 
							.input	= {
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								  },
 | 
				
			||||||
 | 
							.ilen	= 39,
 | 
				
			||||||
 | 
							.result	= {
 | 
				
			||||||
 | 
								    0x2D, 0xD5, 0xC3, 0xF7, 0xBA, 0x2B, 0x20, 0xF7,
 | 
				
			||||||
 | 
					                            0x68, 0x02, 0x41, 0x0C, 0x68, 0x86, 0x88, 0x89,
 | 
				
			||||||
 | 
					                            0x5A, 0xD8, 0xC1, 0xBD, 0x4E, 0xA6, 0xC9, 0xB1,
 | 
				
			||||||
 | 
					                            0x40, 0xFB, 0x9B, 0x90, 0xE2, 0x10, 0x49, 0xBF,
 | 
				
			||||||
 | 
					                            0x58, 0x3F, 0x52, 0x79, 0x70, 0xEB, 0xC1,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							.rlen	= 39,
 | 
				
			||||||
 | 
						}, { /* Set 5, vector 0 */
 | 
				
			||||||
 | 
							.key	= {
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 | 
				
			||||||
 | 
								  },
 | 
				
			||||||
 | 
							.klen	= 16,
 | 
				
			||||||
 | 
							.iv     = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
 | 
				
			||||||
 | 
							.input	= {
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								  },
 | 
				
			||||||
 | 
							.ilen	= 64,
 | 
				
			||||||
 | 
							.result	= {
 | 
				
			||||||
 | 
								    0xB6, 0x6C, 0x1E, 0x44, 0x46, 0xDD, 0x95, 0x57,
 | 
				
			||||||
 | 
					                            0xE5, 0x78, 0xE2, 0x23, 0xB0, 0xB7, 0x68, 0x01,
 | 
				
			||||||
 | 
					                            0x7B, 0x23, 0xB2, 0x67, 0xBB, 0x02, 0x34, 0xAE,
 | 
				
			||||||
 | 
					                            0x46, 0x26, 0xBF, 0x44, 0x3F, 0x21, 0x97, 0x76,
 | 
				
			||||||
 | 
					                            0x43, 0x6F, 0xB1, 0x9F, 0xD0, 0xE8, 0x86, 0x6F,
 | 
				
			||||||
 | 
					                            0xCD, 0x0D, 0xE9, 0xA9, 0x53, 0x8F, 0x4A, 0x09,
 | 
				
			||||||
 | 
					                            0xCA, 0x9A, 0xC0, 0x73, 0x2E, 0x30, 0xBC, 0xF9,
 | 
				
			||||||
 | 
					                            0x8E, 0x4F, 0x13, 0xE4, 0xB9, 0xE2, 0x01, 0xD9,
 | 
				
			||||||
 | 
								  },
 | 
				
			||||||
 | 
							.rlen	= 64,
 | 
				
			||||||
 | 
						}, { /* Set 3, vector 27 */
 | 
				
			||||||
 | 
							.key	= {
 | 
				
			||||||
 | 
								    0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22,
 | 
				
			||||||
 | 
								    0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A,
 | 
				
			||||||
 | 
					                            0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32,
 | 
				
			||||||
 | 
								    0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A
 | 
				
			||||||
 | 
								  },
 | 
				
			||||||
 | 
							.klen	= 32,
 | 
				
			||||||
 | 
							.iv     = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
 | 
				
			||||||
 | 
							.input	= {
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								  },
 | 
				
			||||||
 | 
							.ilen	= 111,
 | 
				
			||||||
 | 
							.result	= {
 | 
				
			||||||
 | 
								    0xAE, 0x39, 0x50, 0x8E, 0xAC, 0x9A, 0xEC, 0xE7,
 | 
				
			||||||
 | 
					                            0xBF, 0x97, 0xBB, 0x20, 0xB9, 0xDE, 0xE4, 0x1F,
 | 
				
			||||||
 | 
					                            0x87, 0xD9, 0x47, 0xF8, 0x28, 0x91, 0x35, 0x98,
 | 
				
			||||||
 | 
					                            0xDB, 0x72, 0xCC, 0x23, 0x29, 0x48, 0x56, 0x5E,
 | 
				
			||||||
 | 
					                            0x83, 0x7E, 0x0B, 0xF3, 0x7D, 0x5D, 0x38, 0x7B,
 | 
				
			||||||
 | 
					                            0x2D, 0x71, 0x02, 0xB4, 0x3B, 0xB5, 0xD8, 0x23,
 | 
				
			||||||
 | 
					                            0xB0, 0x4A, 0xDF, 0x3C, 0xEC, 0xB6, 0xD9, 0x3B,
 | 
				
			||||||
 | 
					                            0x9B, 0xA7, 0x52, 0xBE, 0xC5, 0xD4, 0x50, 0x59,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            0x15, 0x14, 0xB4, 0x0E, 0x40, 0xE6, 0x53, 0xD1,
 | 
				
			||||||
 | 
					                            0x83, 0x9C, 0x5B, 0xA0, 0x92, 0x29, 0x6B, 0x5E,
 | 
				
			||||||
 | 
					                            0x96, 0x5B, 0x1E, 0x2F, 0xD3, 0xAC, 0xC1, 0x92,
 | 
				
			||||||
 | 
					                            0xB1, 0x41, 0x3F, 0x19, 0x2F, 0xC4, 0x3B, 0xC6,
 | 
				
			||||||
 | 
					                            0x95, 0x46, 0x45, 0x54, 0xE9, 0x75, 0x03, 0x08,
 | 
				
			||||||
 | 
					                            0x44, 0xAF, 0xE5, 0x8A, 0x81, 0x12, 0x09,
 | 
				
			||||||
 | 
								  },
 | 
				
			||||||
 | 
							.rlen	= 111,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}, { /* Set 5, vector 27 */
 | 
				
			||||||
 | 
							.key	= {
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 | 
				
			||||||
 | 
								  },
 | 
				
			||||||
 | 
							.klen	= 32,
 | 
				
			||||||
 | 
							.iv     = { 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00 },
 | 
				
			||||||
 | 
							.input	= {
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
								    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								    0x00,
 | 
				
			||||||
 | 
								  },
 | 
				
			||||||
 | 
							.ilen	= 129,
 | 
				
			||||||
 | 
							.result	= {
 | 
				
			||||||
 | 
								    0xD2, 0xDB, 0x1A, 0x5C, 0xF1, 0xC1, 0xAC, 0xDB,
 | 
				
			||||||
 | 
					                            0xE8, 0x1A, 0x7A, 0x43, 0x40, 0xEF, 0x53, 0x43,
 | 
				
			||||||
 | 
					                            0x5E, 0x7F, 0x4B, 0x1A, 0x50, 0x52, 0x3F, 0x8D,
 | 
				
			||||||
 | 
					                            0x28, 0x3D, 0xCF, 0x85, 0x1D, 0x69, 0x6E, 0x60,
 | 
				
			||||||
 | 
					                            0xF2, 0xDE, 0x74, 0x56, 0x18, 0x1B, 0x84, 0x10,
 | 
				
			||||||
 | 
					                            0xD4, 0x62, 0xBA, 0x60, 0x50, 0xF0, 0x61, 0xF2,
 | 
				
			||||||
 | 
					                            0x1C, 0x78, 0x7F, 0xC1, 0x24, 0x34, 0xAF, 0x58,
 | 
				
			||||||
 | 
					                            0xBF, 0x2C, 0x59, 0xCA, 0x90, 0x77, 0xF3, 0xB0,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            0x5B, 0x4A, 0xDF, 0x89, 0xCE, 0x2C, 0x2F, 0xFC,
 | 
				
			||||||
 | 
					                            0x67, 0xF0, 0xE3, 0x45, 0xE8, 0xB3, 0xB3, 0x75,
 | 
				
			||||||
 | 
					                            0xA0, 0x95, 0x71, 0xA1, 0x29, 0x39, 0x94, 0xCA,
 | 
				
			||||||
 | 
					                            0x45, 0x2F, 0xBD, 0xCB, 0x10, 0xB6, 0xBE, 0x9F,
 | 
				
			||||||
 | 
					                            0x8E, 0xF9, 0xB2, 0x01, 0x0A, 0x5A, 0x0A, 0xB7,
 | 
				
			||||||
 | 
					                            0x6B, 0x9D, 0x70, 0x8E, 0x4B, 0xD6, 0x2F, 0xCD,
 | 
				
			||||||
 | 
					                            0x2E, 0x40, 0x48, 0x75, 0xE9, 0xE2, 0x21, 0x45,
 | 
				
			||||||
 | 
					                            0x0B, 0xC9, 0xB6, 0xB5, 0x66, 0xBC, 0x9A, 0x59,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            0x5A,
 | 
				
			||||||
 | 
								  },
 | 
				
			||||||
 | 
							.rlen	= 129,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Compression stuff.
 | 
					 * Compression stuff.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue