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

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

Version: ~ [ linux-5.5-rc6 ] ~ [ linux-5.4.11 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.95 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.164 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.209 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.209 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.81 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ 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  * This program is free software; you can redistribute it and/or modify it
 15  * under the terms of the GNU General Public License as published by the Free
 16  * Software Foundation; either version 2 of the License, or (at your option)
 17  * any later version.
 18  *
 19  */
 20 
 21 #include <crypto/algapi.h>
 22 #include <linux/module.h>
 23 #include <linux/crypto.h>
 24 
 25 #define SALSA20_IV_SIZE        8U
 26 #define SALSA20_MIN_KEY_SIZE  16U
 27 #define SALSA20_MAX_KEY_SIZE  32U
 28 
 29 struct salsa20_ctx
 30 {
 31         u32 input[16];
 32 };
 33 
 34 asmlinkage void salsa20_keysetup(struct salsa20_ctx *ctx, const u8 *k,
 35                                  u32 keysize, u32 ivsize);
 36 asmlinkage void salsa20_ivsetup(struct salsa20_ctx *ctx, const u8 *iv);
 37 asmlinkage void salsa20_encrypt_bytes(struct salsa20_ctx *ctx,
 38                                       const u8 *src, u8 *dst, u32 bytes);
 39 
 40 static int setkey(struct crypto_tfm *tfm, const u8 *key,
 41                   unsigned int keysize)
 42 {
 43         struct salsa20_ctx *ctx = crypto_tfm_ctx(tfm);
 44         salsa20_keysetup(ctx, key, keysize*8, SALSA20_IV_SIZE*8);
 45         return 0;
 46 }
 47 
 48 static int encrypt(struct blkcipher_desc *desc,
 49                    struct scatterlist *dst, struct scatterlist *src,
 50                    unsigned int nbytes)
 51 {
 52         struct blkcipher_walk walk;
 53         struct crypto_blkcipher *tfm = desc->tfm;
 54         struct salsa20_ctx *ctx = crypto_blkcipher_ctx(tfm);
 55         int err;
 56 
 57         blkcipher_walk_init(&walk, dst, src, nbytes);
 58         err = blkcipher_walk_virt_block(desc, &walk, 64);
 59 
 60         salsa20_ivsetup(ctx, walk.iv);
 61 
 62         if (likely(walk.nbytes == nbytes))
 63         {
 64                 salsa20_encrypt_bytes(ctx, walk.src.virt.addr,
 65                                       walk.dst.virt.addr, nbytes);
 66                 return blkcipher_walk_done(desc, &walk, 0);
 67         }
 68 
 69         while (walk.nbytes >= 64) {
 70                 salsa20_encrypt_bytes(ctx, walk.src.virt.addr,
 71                                       walk.dst.virt.addr,
 72                                       walk.nbytes - (walk.nbytes % 64));
 73                 err = blkcipher_walk_done(desc, &walk, walk.nbytes % 64);
 74         }
 75 
 76         if (walk.nbytes) {
 77                 salsa20_encrypt_bytes(ctx, walk.src.virt.addr,
 78                                       walk.dst.virt.addr, walk.nbytes);
 79                 err = blkcipher_walk_done(desc, &walk, 0);
 80         }
 81 
 82         return err;
 83 }
 84 
 85 static struct crypto_alg alg = {
 86         .cra_name           =   "salsa20",
 87         .cra_driver_name    =   "salsa20-asm",
 88         .cra_priority       =   200,
 89         .cra_flags          =   CRYPTO_ALG_TYPE_BLKCIPHER,
 90         .cra_type           =   &crypto_blkcipher_type,
 91         .cra_blocksize      =   1,
 92         .cra_ctxsize        =   sizeof(struct salsa20_ctx),
 93         .cra_alignmask      =   3,
 94         .cra_module         =   THIS_MODULE,
 95         .cra_u              =   {
 96                 .blkcipher = {
 97                         .setkey         =   setkey,
 98                         .encrypt        =   encrypt,
 99                         .decrypt        =   encrypt,
100                         .min_keysize    =   SALSA20_MIN_KEY_SIZE,
101                         .max_keysize    =   SALSA20_MAX_KEY_SIZE,
102                         .ivsize         =   SALSA20_IV_SIZE,
103                 }
104         }
105 };
106 
107 static int __init init(void)
108 {
109         return crypto_register_alg(&alg);
110 }
111 
112 static void __exit fini(void)
113 {
114         crypto_unregister_alg(&alg);
115 }
116 
117 module_init(init);
118 module_exit(fini);
119 
120 MODULE_LICENSE("GPL");
121 MODULE_DESCRIPTION ("Salsa20 stream cipher algorithm (optimized assembly version)");
122 MODULE_ALIAS_CRYPTO("salsa20");
123 MODULE_ALIAS_CRYPTO("salsa20-asm");
124 

~ [ 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