23 #include <linux/module.h> 
   24 #include <linux/errno.h> 
   26 #include <linux/types.h> 
   27 #include <linux/bitops.h> 
   29 #include <asm/byteorder.h> 
   31 #define SALSA20_IV_SIZE        8U 
   32 #define SALSA20_MIN_KEY_SIZE  16U 
   33 #define SALSA20_MAX_KEY_SIZE  32U 
   46 #define U32TO8_LITTLE(p, v) \ 
   47     { (p)[0] = (v >>  0) & 0xff; (p)[1] = (v >>  8) & 0xff; \ 
   48       (p)[2] = (v >> 16) & 0xff; (p)[3] = (v >> 24) & 0xff; } 
   49 #define U8TO32_LITTLE(p)   \ 
   50     (((u32)((p)[0])      ) | ((u32)((p)[1]) <<  8) | \ 
   51      ((u32)((p)[2]) << 16) | ((u32)((p)[3]) << 24)   ) 
   58 static void salsa20_wordtobyte(
u8 output[64], 
const u32 input[16])
 
   63     memcpy(x, input, 
sizeof(x));
 
   64     for (i = 20; i > 0; i -= 2) {
 
   65         x[ 4] ^= rol32((x[ 0] + x[12]),  7);
 
   66         x[ 8] ^= rol32((x[ 4] + x[ 0]),  9);
 
   67         x[12] ^= rol32((x[ 8] + x[ 4]), 13);
 
   68         x[ 0] ^= rol32((x[12] + x[ 8]), 18);
 
   69         x[ 9] ^= rol32((x[ 5] + x[ 1]),  7);
 
   70         x[13] ^= rol32((x[ 9] + x[ 5]),  9);
 
   71         x[ 1] ^= rol32((x[13] + x[ 9]), 13);
 
   72         x[ 5] ^= rol32((x[ 1] + x[13]), 18);
 
   73         x[14] ^= rol32((x[10] + x[ 6]),  7);
 
   74         x[ 2] ^= rol32((x[14] + x[10]),  9);
 
   75         x[ 6] ^= rol32((x[ 2] + x[14]), 13);
 
   76         x[10] ^= rol32((x[ 6] + x[ 2]), 18);
 
   77         x[ 3] ^= rol32((x[15] + x[11]),  7);
 
   78         x[ 7] ^= rol32((x[ 3] + x[15]),  9);
 
   79         x[11] ^= rol32((x[ 7] + x[ 3]), 13);
 
   80         x[15] ^= rol32((x[11] + x[ 7]), 18);
 
   81         x[ 1] ^= rol32((x[ 0] + x[ 3]),  7);
 
   82         x[ 2] ^= rol32((x[ 1] + x[ 0]),  9);
 
   83         x[ 3] ^= rol32((x[ 2] + x[ 1]), 13);
 
   84         x[ 0] ^= rol32((x[ 3] + x[ 2]), 18);
 
   85         x[ 6] ^= rol32((x[ 5] + x[ 4]),  7);
 
   86         x[ 7] ^= rol32((x[ 6] + x[ 5]),  9);
 
   87         x[ 4] ^= rol32((x[ 7] + x[ 6]), 13);
 
   88         x[ 5] ^= rol32((x[ 4] + x[ 7]), 18);
 
   89         x[11] ^= rol32((x[10] + x[ 9]),  7);
 
   90         x[ 8] ^= rol32((x[11] + x[10]),  9);
 
   91         x[ 9] ^= rol32((x[ 8] + x[11]), 13);
 
   92         x[10] ^= rol32((x[ 9] + x[ 8]), 18);
 
   93         x[12] ^= rol32((x[15] + x[14]),  7);
 
   94         x[13] ^= rol32((x[12] + x[15]),  9);
 
   95         x[14] ^= rol32((x[13] + x[12]), 13);
 
   96         x[15] ^= rol32((x[14] + x[13]), 18);
 
   98     for (i = 0; i < 16; ++
i)
 
  100     for (i = 0; i < 16; ++
i)
 
  104 static const char sigma[16] = 
"expand 32-byte k";
 
  105 static const char tau[16] = 
"expand 16-byte k";
 
  109     const char *constants;
 
  148         salsa20_wordtobyte(buf, ctx->
input);
 
  183     struct salsa20_ctx *ctx = crypto_blkcipher_ctx(tfm);
 
  186     blkcipher_walk_init(&walk, dst, src, nbytes);
 
  191     if (
likely(walk.nbytes == nbytes))
 
  194                       walk.src.virt.addr, nbytes);
 
  198     while (walk.nbytes >= 64) {
 
  201                       walk.nbytes - (walk.nbytes % 64));
 
  207                       walk.src.virt.addr, walk.nbytes);
 
  215     .cra_name           =   
"salsa20",
 
  216     .cra_driver_name    =   
"salsa20-generic",
 
  236 static int __init salsa20_generic_mod_init(
void)
 
  241 static void __exit salsa20_generic_mod_fini(
void)