~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/crypto/salsa20_glue.c

Version: ~ [ linux-6.2-rc3 ] ~ [ linux-6.1.5 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.87 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.162 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.228 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.269 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.302 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Glue code for optimized assembly version of  Salsa20.
  3  *
  4  * Copyright (c) 2007 Tan Swee Heng <thesweeheng@gmail.com>
  5  *
  6  * The assembly codes are public domain assembly codes written by Daniel. J.
  7  * Bernstein <djb@cr.yp.to>. The codes are modified to include indentation
  8  * and to remove extraneous comments and functions that are not needed.
  9  * - i586 version, renamed as salsa20-i586-asm_32.S
 10  *   available from <http://cr.yp.to/snuffle/salsa20/x86-pm/salsa20.s>
 11  * - x86-64 version, renamed as salsa20-x86_64-asm_64.S
 12  *   available from <http://cr.yp.to/snuffle/salsa20/amd64-3/salsa20.s>
 13  *
 14  * Also modified to set up the initial state using the generic C code rather
 15  * than in assembly.
 16  *
 17  * This program is free software; you can redistribute it and/or modify it
 18  * under the terms of the GNU General Public License as published by the Free
 19  * Software Foundation; either version 2 of the License, or (at your option)
 20  * any later version.
 21  *
 22  */
 23 
 24 #include <asm/unaligned.h>
 25 #include <crypto/internal/skcipher.h>
 26 #include <crypto/salsa20.h>
 27 #include <linux/module.h>
 28 
 29 asmlinkage void salsa20_encrypt_bytes(u32 state[16], const u8 *src, u8 *dst,
 30                                       u32 bytes);
 31 
 32 static int salsa20_asm_crypt(struct skcipher_request *req)
 33 {
 34         struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
 35         const struct salsa20_ctx *ctx = crypto_skcipher_ctx(tfm);
 36         struct skcipher_walk walk;
 37         u32 state[16];
 38         int err;
 39 
 40         err = skcipher_walk_virt(&walk, req, true);
 41 
 42         crypto_salsa20_init(state, ctx, walk.iv);
 43 
 44         while (walk.nbytes > 0) {
 45                 unsigned int nbytes = walk.nbytes;
 46 
 47                 if (nbytes < walk.total)
 48                         nbytes = round_down(nbytes, walk.stride);
 49 
 50                 salsa20_encrypt_bytes(state, walk.src.virt.addr,
 51                                       walk.dst.virt.addr, nbytes);
 52                 err = skcipher_walk_done(&walk, walk.nbytes - nbytes);
 53         }
 54 
 55         return err;
 56 }
 57 
 58 static struct skcipher_alg alg = {
 59         .base.cra_name          = "salsa20",
 60         .base.cra_driver_name   = "salsa20-asm",
 61         .base.cra_priority      = 200,
 62         .base.cra_blocksize     = 1,
 63         .base.cra_ctxsize       = sizeof(struct salsa20_ctx),
 64         .base.cra_module        = THIS_MODULE,
 65 
 66         .min_keysize            = SALSA20_MIN_KEY_SIZE,
 67         .max_keysize            = SALSA20_MAX_KEY_SIZE,
 68         .ivsize                 = SALSA20_IV_SIZE,
 69         .chunksize              = SALSA20_BLOCK_SIZE,
 70         .setkey                 = crypto_salsa20_setkey,
 71         .encrypt                = salsa20_asm_crypt,
 72         .decrypt                = salsa20_asm_crypt,
 73 };
 74 
 75 static int __init init(void)
 76 {
 77         return crypto_register_skcipher(&alg);
 78 }
 79 
 80 static void __exit fini(void)
 81 {
 82         crypto_unregister_skcipher(&alg);
 83 }
 84 
 85 module_init(init);
 86 module_exit(fini);
 87 
 88 MODULE_LICENSE("GPL");
 89 MODULE_DESCRIPTION ("Salsa20 stream cipher algorithm (optimized assembly version)");
 90 MODULE_ALIAS_CRYPTO("salsa20");
 91 MODULE_ALIAS_CRYPTO("salsa20-asm");
 92 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp