linux/crypto/arc4.c
<<
n> 4.2/spa="v 4.2/form"v 4.2a n> 4. href="../linux+v3.7.7/crypto/arc4.c">n> 4.2img src="../.static/gfx/right.png" alt=">>">n>2/spa="vn>2spa= class="lxr_search">n> n> 4.2input typ3.1hidden" nam3.1navtarget" v3.1">n> 4.2input typ3.1text" nam3.1search" id.1search">n> 4.2butt >typ3.1submit">Search 4. onclick="return ajax_prefs();">n> 4.Prefsv 4.2/a>n>2/spa="v 4. .2/div"v 4. .2form aclue=="ajax+*" method="post" onsubmit="return false;">n>2input typ3.1hidden" nam3.1ajax_lookup" id.1ajax_lookup" v3.1">n 4. .2/form"vn 4. .2div class="headingbott m">v 2div id.1file_contents""
. .12/a>2spa= class="comment">/*2/spa="v. .22/a>2spa= class="comment"> * Cryptographic API2/spa="v. .32/a>2spa= class="comment"> *2/spa="v. .42/a>2spa= class="comment"> * ARC4 Cipher Algorithm2/spa="v. .52/a>2spa= class="comment"> *2/spa="v. .62/a>2spa= class="comment"> * J  >Oberheide <jon@oberheide.org>2/spa="v. .72/a>2spa= class="comment"> *2/spa="v. .82/a>2spa= class="comment"> * This program is free software; you ca= redistribute it and/or modify2/spa="v. .92/a>2spa= class="comment"> * it under the terms of the GNU General Public License as published by2/spa="v. ion a>2spa= class="comment"> * the Free Software Foundalue=; either vers	  >2 of the License, or2/spa="v. 112/a>2spa= class="comment"> * (at your value=) any later vers	  .2/spa="v. 122/a>2spa= class="comment"> *2/spa="v. 132/a>2spa= class="comment"> */2/spa="v. 142/a>v. 152/a>#include <linux/module.h2/a>>v. 162/a>#include <linux/init.h2/a>>v. 172/a>#include <linux/crypto.h2/a>>v. 182/a>#include <crypto/algapi.h2/a>>v. 192/a>v. 2on a>#define.2a href="+code=ARC4_MIN_KEY_SIZE" class="sref">ARC4_MIN_KEY_SIZEn a>
 4. . 1v. 21n a>#define.2a href="+code=ARC4_MAX_KEY_SIZE" class="sref">ARC4_MAX_KEY_SIZEn a>
 4. . 256v. 22n a>#define.2a href="+code=ARC4_BLOCK_SIZE" class="sref">ARC4_BLOCK_SIZEn a>
 4. . . 1v. 232/a>v. 242/a>struct.2a href="+code=arc4_ctx" class="sref">arc4_ctxn a>
{v. 25n a>
 4. . .2a href="+code=u32" class="sref">u32n a>.2a href="+code=S" class="sref">Sn a>[256];v. 26n a>
 4. . .2a href="+code=u32" class="sref">u32n a>.2a href="+code=x" class="sref">xn a>,.2a href="+code=y" class="sref">yn a>;v. 272/a>};v. 282/a>v. 292/a>static int.2a href="+code=arc4_set_key" class="sref">arc4_set_key2/a>(struct.2a href="+code=crypto_tfm" class="sref">crypto_tfmn a>.*2a href="+code=tfm" class="sref">tfmn a>, const.2a href="+code=u8" class="sref">u8n a>.*2a href="+code=in_key" class="sref">in_keyn a>,v. 30n a>
 4. . .                unsigned int.2a href="+code=key_len" class="sref">key_lenn a>)v. 31n a>{v. 32n a>........struct.2a href="+code=arc4_ctx" class="sref">arc4_ctxn a>
*2a href="+code=ctx" class="sref">ctxn a>
=.2a href="+code=crypto_tfm_ctx" class="sref">crypto_tfm_ctx2/a>(2a href="+code=tfm" class="sref">tfmn a>);v. 33n a>........int.2a href="+code=i" class="sref">in a>,.2a href="+code=j" class="sref">jn a>
=.0,.2a href="+code=k" class="sref">kn a>
=.0;v. 342/a>v. 35n a>
 4. . .2a href="+code=ctx" class="sref">ctxn a>->2a href="+code=x" class="sref">xn a>
=.1;v. 36n a>
 4. . .2a href="+code=ctx" class="sref">ctxn a>->2a href="+code=y" class="sref">yn a>
=.0;v. 372/a>v. 38n a>
 4. . .for (2a href="+code=i" class="sref">in a>
=.0;.2a href="+code=i" class="sref">in a> < 256;.2a href="+code=i" class="sref">in a>++)v. 39n a>
 4. . .        2a href="+code=ctx" class="sref">ctxn a>->2a href="+code=S" class="sref">Sn a>[2a href="+code=i" class="sref">in a>]
=.2a href="+code=i" class="sref">in a>;v. 402/a>v. 41n a>
 4. . .for (2a href="+code=i" class="sref">in a>
=.0;.2a href="+code=i" class="sref">in a> < 256;.2a href="+code=i" class="sref">in a>++)
{v. 42n a>
 4. . .        2a href="+code=u32" class="sref">u32n a>.2a href="+code=a" class="sref">an a>
=.2a href="+code=ctx" class="sref">ctxn a>->2a href="+code=S" class="sref">Sn a>[2a href="+code=i" class="sref">in a>];v. 43n a>
 4. . .        2a href="+code=j" class="sref">jn a>
=.(2a href="+code=j" class="sref">jn a>
+.2a href="+code=in_key" class="sref">in_keyn a>[2a href="+code=k" class="sref">kn a>]
+.2a href="+code=a" class="sref">an a>) & 0xff;v. 44n a>
 4. . .        2a href="+code=ctx" class="sref">ctxn a>->2a href="+code=S" class="sref">Sn a>[2a href="+code=i" class="sref">in a>]
=.2a href="+code=ctx" class="sref">ctxn a>->2a href="+code=S" class="sref">Sn a>[2a href="+code=j" class="sref">jn a>];v. 45n a>
 4. . .        2a href="+code=ctx" class="sref">ctxn a>->2a href="+code=S" class="sref">Sn a>[2a href="+code=j" class="sref">jn a>]
=.2a href="+code=a" class="sref">an a>;v. 46n a>
 4. . .        if (++2a href="+code=k" class="sref">kn a>
>=.2a href="+code=key_len" class="sref">key_lenn a>)v. 47n a>
 4. . .                2a href="+code=k" class="sref">kn a>
=.0;v. 48n a>
 4. . .}v. 492/a>v. 50n a>
 4. . .return 0;v. 51n a>}v. 522/a>v. 532/a>static void.2a href="+code=arc4_crypt" class="sref">arc4_crypt2/a>(struct.2a href="+code=arc4_ctx" class="sref">arc4_ctxn a>
*2a href="+code=ctx" class="sref">ctxn a>,.2a href="+code=u8" class="sref">u8n a>.*2a href="+code=out" class="sref">outn a>, const.2a href="+code=u8" class="sref">u8n a>.*2a href="+code=in" class="sref">inn a>,v. 54n a>
 4. . .               unsigned int.2a href="+code=len" class="sref">lenn a>)v. 55n a>{v. 56n a>
 4. . .2a href="+code=u32" class="sref">u32n a>.*const.2a href="+code=S" class="sref">Sn a>
=.2a href="+code=ctx" class="sref">ctxn a>->2a href="+code=S" class="sref">Sn a>;v. 57n a>
 4. . .2a href="+code=u32" class="sref">u32n a>.2a href="+code=x" class="sref">xn a>,.2a href="+code=y" class="sref">yn a>,.2a href="+code=a" class="sref">an a>,.2a href="+code=b" class="sref">bn a>;v. 58n a>
 4. . .2a href="+code=u32" class="sref">u32n a>.2a href="+code=ty" class="sref">tyn a>,.2a href="+code=ta" class="sref">tan a>,.2a href="+code=tb" class="sref">tbn a>;v. 592/a>v. 60n a>
 4. . .if (2a href="+code=len" class="sref">lenn a> ==.0)v. 61n a>
 4. . .        return;v. 622/a>v. 63n a>
 4. . .2a href="+code=x" class="sref">xn a>
=.2a href="+code=ctx" class="sref">ctxn a>->2a href="+code=x" class="sref">xn a>;v. 64n a>
 4. . .2a href="+code=y" class="sref">yn a>
=.2a href="+code=ctx" class="sref">ctxn a>->2a href="+code=y" class="sref">yn a>;v. 652/a>v. 66n a>
 4. . .2a href="+code=a" class="sref">an a>
=.2a href="+code=S" class="sref">Sn a>[2a href="+code=x" class="sref">xn a>];v. 67n a>
 4. . .2a href="+code=y" class="sref">yn a>
=.(2a href="+code=y" class="sref">yn a>
+.2a href="+code=a" class="sref">an a>) & 0xff;v. 68n a>
 4. . .2a href="+code=b" class="sref">bn a>
=.2a href="+code=S" class="sref">Sn a>[2a href="+code=y" class="sref">yn a>];v. 692/a>v. 70n a>
 4. . .do
{v. 71n a>
 4. . .        2a href="+code=S" class="sref">Sn a>[2a href="+code=y" class="sref">yn a>]
=.2a href="+code=a" class="sref">an a>;v. 72n a>
 4. . .        2a href="+code=a" class="sref">an a>
=.(2a href="+code=a" class="sref">an a>
+.2a href="+code=b" class="sref">bn a>) & 0xff;v. 73n a>
 4. . .        2a href="+code=S" class="sref">Sn a>[2a href="+code=x" class="sref">xn a>]
=.2a href="+code=b" class="sref">bn a>;v. 74n a>
 4. . .        2a href="+code=x" class="sref">xn a>
=.(2a href="+code=x" class="sref">xn a>
+ 1) & 0xff;v. 75n a>
 4. . .        2a href="+code=ta" class="sref">tan a>
=.2a href="+code=S" class="sref">Sn a>[2a href="+code=x" class="sref">xn a>];v. 76n a>
 4. . .        2a href="+code=ty" class="sref">tyn a>
=.(2a href="+code=y" class="sref">yn a>
+.2a href="+code=ta" class="sref">tan a>) & 0xff;v. 77n a>
 4. . .        2a href="+code=tb" class="sref">tbn a>
=.2a href="+code=S" class="sref">Sn a>[2a href="+code=ty" class="sref">tyn a>];v. 78n a>
 4. . .        *2a href="+code=out" class="sref">outn a>++
=.*2a href="+code=in" class="sref">inn a>++
^.2a href="+code=S" class="sref">Sn a>[2a href="+code=a" class="sref">an a>];v. 79n a>
 4. . .        if (--2a href="+code=len" class="sref">lenn a> ==.0)v. 80n a>
 4. . .                break;v. 81n a>
 4. . .        2a href="+code=y" class="sref">yn a>
=.2a href="+code=ty" class="sref">tyn a>;v. 82n a>
 4. . .        2a href="+code=a" class="sref">an a>
=.2a href="+code=ta" class="sref">tan a>;v. 83n a>
 4. . .        2a href="+code=b" class="sref">bn a>
=.2a href="+code=tb" class="sref">tbn a>;v. 84n a>
 4. . .} while.(2a href="+code=true" class="sref">truen a>);v. 852/a>v. 86n a>
 4. . .2a href="+code=ctx" class="sref">ctxn a>->2a href="+code=x" class="sref">xn a>
=.2a href="+code=x" class="sref">xn a>;v. 87n a>
 4. . .2a href="+code=ctx" class="sref">ctxn a>->2a href="+code=y" class="sref">yn a>
=.2a href="+code=y" class="sref">yn a>;v. 88n a>}v. 892/a>v. 902/a>static void.2a href="+code=arc4_crypt_one" class="sref">arc4_crypt_one2/a>(struct.2a href="+code=crypto_tfm" class="sref">crypto_tfmn a>.*2a href="+code=tfm" class="sref">tfmn a>, 2a href="+code=u8" class="sref">u8n a>.*2a href="+code=out" class="sref">outn a>, const.2a href="+code=u8" class="sref">u8n a>.*2a href="+code=in" class="sref">inn a>)v. 91n a>{v. 92n a>
 4. . .2a href="+code=arc4_crypt" class="sref">arc4_crypt2/a>(2a href="+code=crypto_tfm_ctx" class="sref">crypto_tfm_ctx2/a>(2a href="+code=tfm" class="sref">tfmn a>), 2a href="+code=out" class="sref">outn a>, 2a href="+code=in" class="sref">inn a>, 1);v. 93n a>}v. 942/a>v. 952/a>static int.2a href="+code=ecb_arc4_crypt" class="sref">ecb_arc4_crypt2/a>(struct.2a href="+code=blkcipher_desc" class="sref">blkcipher_descn a>.*2a href="+code=desc" class="sref">descn a>,.struct.2a href="+code=scatterlist" class="sref">scatterlistn a>.*2a href="+code=dst" class="sref">dstn a>,v. 96n a>
 4. . .                  struct.2a href="+code=scatterlist" class="sref">scatterlistn a>.*2a href="+code=src" class="sref">srcn a>,.unsigned int.2a href="+code=nbytes" class="sref">nbytesn a>)v. 97n a>{v. 98n a>
 4. . .struct.2a href="+code=arc4_ctx" class="sref">arc4_ctxn a>
*2a href="+code=ctx" class="sref">ctxn a>
=.2a href="+code=crypto_blkcipher_ctx" class="sref">crypto_blkcipher_ctx2/a>(2a href="+code=desc" class="sref">descn a>->2a href="+code=tfm" class="sref">tfmn a>);v. 99n a>
 4. . .struct.2a href="+code=blkcipher_walk" class="sref">blkcipher_walkn a>.2a href="+code=walk" class="sref">walkn a>;v.100n a>
 4. . .int.2a href="+code=err" class="sref">errn a>;v.1012/a>v.102n a>
 4. . .2a href="+code=blkcipher_walk_init" class="sref">blkcipher_walk_init2/a>(&2a href="+code=walk" class="sref">walkn a>, 2a href="+code=dst" class="sref">dstn a>,.2a href="+code=src" class="sref">srcn a>,.2a href="+code=nbytes" class="sref">nbytesn a>);v.1032/a>v.104n a>
 4. . .2a href="+code=err" class="sref">errn a>
=.2a href="+code=blkcipher_walk_virt" class="sref">blkcipher_walk_virt2/a>(2a href="+code=desc" class="sref">descn a>, &2a href="+code=walk" class="sref">walkn a>);v.1052/a>v.106n a>
 4. . .while.(2a href="+code=walk" class="sref">walkn a>.2a href="+code=nbytes" class="sref">nbytesn a>
> 0)
{v.107n a>
 4. . .        2a href="+code=u8" class="sref">u8n a>.*2a href="+code=wsrc" class="sref">wsrcn a>
=.2a href="+code=walk" class="sref">walkn a>.2a href="+code=src" class="sref">srcn a>.2a href="+code=virt" class="sref">virt2/a>.2a href="+code=addr" class="sref">addrn a>;v.108n a>
 4. . .        2a href="+code=u8" class="sref">u8n a>.*2a href="+code=wdst" class="sref">wdstn a>
=.2a href="+code=walk" class="sref">walkn a>.2a href="+code=dst" class="sref">dstn a>.2a href="+code=virt" class="sref">virt2/a>.2a href="+code=addr" class="sref">addrn a>;v.1092/a>v.110n a>
 4. . .        2a href="+code=arc4_crypt" class="sref">arc4_crypt2/a>(2a href="+code=ctx" class="sref">ctxn a>,.2a href="+code=wdst" class="sref">wdstn a>,.2a href="+code=wsrc" class="sref">wsrcn a>,.2a href="+code=walk" class="sref">walkn a>.2a href="+code=nbytes" class="sref">nbytesn a>);v.1112/a>v.112n a>
 4. . .        2a href="+code=err" class="sref">errn a>
=.2a href="+code=blkcipher_walk_done" class="sref">blkcipher_walk_done2/a>(2a href="+code=desc" class="sref">descn a>, &2a href="+code=walk" class="sref">walkn a>, 0);v.113n a>
 4. . .}v.1142/a>v.115n a>
 4. . .return 2a href="+code=err" class="sref">errn a>;v.1162/a>}v.1172/a>v.1182/a>static struct.2a href="+code=crypto_alg" class="sref">crypto_algn a>.2a href="+code=arc4_algs" class="sref">arc4_algsn a>[2]
=.{
{v.119n a>
 4. . ..2a href="+code=cra_nam3" class="sref">cra_nam3n a>
 4. . .       =       2spa= class="string">"arc4"2/spa=",v.120n a>
 4. . ..2a href="+code=cra_flags" class="sref">cra_flagsn a>
 4. . .      =       2a href="+code=CRYPTO_ALG_TYPE_CIPHER" class="sref">CRYPTO_ALG_TYPE_CIPHERn a>,v.121n a>
 4. . ..2a href="+code=cra_blocksiz3" class="sref">cra_blocksiz3n a>
 4. . .  =       2a href="+code=ARC4_BLOCK_SIZE" class="sref">ARC4_BLOCK_SIZEn a>,v.122n a>
 4. . ..2a href="+code=cra_ctxsiz3" class="sref">cra_ctxsiz3n a>
 4. . .    =       siz3of(struct.2a href="+code=arc4_ctx" class="sref">arc4_ctxn a>),v.123n a>
 4. . ..2a href="+code=cra_module" class="sref">cra_modulen a>
 4. . .     =       2a href="+code=THIS_MODULE" class="sref">THIS_MODULEn a>,v.124n a>
 4. . ..2a href="+code=cra_u" class="sref">cra_un a>
 4. . .          =       {v.125n a>
 4. . .        .2a href="+code=cipher" class="sref">ciphern a>
=.{v.126n a>
 4. . .                .2a href="+code=cia_min_keysiz3" class="sref">cia_min_keysiz3n a>
 4. . .=       2a href="+code=ARC4_MIN_KEY_SIZE" class="sref">ARC4_MIN_KEY_SIZEn a>,v.127n a>
 4. . .                .2a href="+code=cia_max_keysiz3" class="sref">cia_max_keysiz3n a>
 4. . .=       2a href="+code=ARC4_MAX_KEY_SIZE" class="sref">ARC4_MAX_KEY_SIZEn a>,v.128n a>
 4. . .                .2a href="+code=cia_setkey" class="sref">cia_setkeyn a>
 4. . .     =       2a href="+code=arc4_set_key" class="sref">arc4_set_key2/a>,v.129n a>
 4. . .                .2a href="+code=cia_encrypt" class="sref">cia_encryptn a>
 4. . .    =       2a href="+code=arc4_crypt_one" class="sref">arc4_crypt_one2/a>,v.130n a>
 4. . .                .2a href="+code=cia_decrypt" class="sref">cia_decryptn a>
 4. . .    =       2a href="+code=arc4_crypt_one" class="sref">arc4_crypt_one2/a>,v.131n a>
 4. . .        },v.132n a>........},v.133n a>},.{v.134n a>
 4. . ..2a href="+code=cra_nam3" class="sref">cra_nam3n a>
 4. . .       =       2spa= class="string">"ecb(arc4)"2/spa=",v.135n a>
 4. . ..2a href="+code=cra_priority" class="sref">cra_priorityn a>
 4. . .   =       100,v.136n a>
 4. . ..2a href="+code=cra_flags" class="sref">cra_flagsn a>
 4. . .      =       2a href="+code=CRYPTO_ALG_TYPE_BLKCIPHER" class="sref">CRYPTO_ALG_TYPE_BLKCIPHER2/a>,v.137n a>
 4. . ..2a href="+code=cra_blocksiz3" class="sref">cra_blocksiz3n a>
 4. . .  =       2a href="+code=ARC4_BLOCK_SIZE" class="sref">ARC4_BLOCK_SIZEn a>,v.138n a>
 4. . ..2a href="+code=cra_ctxsiz3" class="sref">cra_ctxsiz3n a>
 4. . .    =       siz3of(struct.2a href="+code=arc4_ctx" class="sref">arc4_ctxn a>),v.139n a>
 4. . ..2a href="+code=cra_alignmask" class="sref">cra_alignmaskn a>
 4. . .  =       0,v.140n a>
 4. . ..2a href="+code=cra_typ3" class="sref">cra_typ3n a>
 4. . .       =       &2a href="+code=crypto_blkcipher_typ3" class="sref">crypto_blkcipher_typ3n a>,v.141n a>
 4. . ..2a href="+code=cra_module" class="sref">cra_modulen a>
 4. . .     =       2a href="+code=THIS_MODULE" class="sref">THIS_MODULEn a>,v.142n a>
 4. . ..2a href="+code=cra_u" class="sref">cra_un a>
 4. . .          =       {v.143n a>
 4. . .        .2a href="+code=blkcipher" class="sref">blkciphern a>
=.{v.144n a>
 4. . .                .2a href="+code=min_keysiz3" class="sref">min_keysiz3n a>
 4.=       2a href="+code=ARC4_MIN_KEY_SIZE" class="sref">ARC4_MIN_KEY_SIZEn a>,v.145n a>
 4. . .                .2a href="+code=max_keysiz3" class="sref">max_keysiz3n a>
 4.=       2a href="+code=ARC4_MAX_KEY_SIZE" class="sref">ARC4_MAX_KEY_SIZEn a>,v.146n a>
 4. . .                .2a href="+code=setkey" class="sref">setkeyn a>
 4. . . =       2a href="+code=arc4_set_key" class="sref">arc4_set_key2/a>,v.147n a>
 4. . .                .2a href="+code=encrypt" class="sref">encryptn a>
 4. . .=       2a href="+code=ecb_arc4_crypt" class="sref">ecb_arc4_crypt2/a>,v.148n a>
 4. . .                .2a href="+code=decrypt" class="sref">decryptn a>
 4. . .=       2a href="+code=ecb_arc4_crypt" class="sref">ecb_arc4_crypt2/a>,v.149n a>
 4. . .        },v.150n a>
 4. . .},v.151n a>} };v.1522/a>v.1532/a>static int.2a href="+code=__init" class="sref">__init2/a> 2a href="+code=arc4_init" class="sref">arc4_init2/a>(void)v.154n a>{v.155n a>
 4. . .return 2a href="+code=crypto_register_algs" class="sref">crypto_register_algs2/a>(2a href="+code=arc4_algs" class="sref">arc4_algsn a>,.2a href="+code=ARRAY_SIZE" class="sref">ARRAY_SIZE2/a>(2a href="+code=arc4_algs" class="sref">arc4_algsn a>));v.1562/a>}v.1572/a>v.1582/a>static void.2a href="+code=__exit" class="sref">__exit2/a> 2a href="+code=arc4_exit" class="sref">arc4_exit2/a>(void)v.1592/a>{v.160n a>
 4. . .2a href="+code=crypto_unregister_algs" class="sref">crypto_unregister_algs2/a>(2a href="+code=arc4_algs" class="sref">arc4_algsn a>,.2a href="+code=ARRAY_SIZE" class="sref">ARRAY_SIZE2/a>(2a href="+code=arc4_algs" class="sref">arc4_algsn a>));v.161n a>}v.1622/a>v.163n a>2a href="+code=module_init" class="sref">module_init2/a>(2a href="+code=arc4_init" class="sref">arc4_init2/a>);v.164n a>2a href="+code=module_exit" class="sref">module_exit2/a>(2a href="+code=arc4_exit" class="sref">arc4_exit2/a>);v.1652/a>v.166n a>2a href="+code=MODULE_LICENSE" class="sref">MODULE_LICENSE2/a>(2spa= class="string">"GPL"2/spa=");v.167n a>2a href="+code=MODULE_DESCRIPTION" class="sref">MODULE_DESCRIPTION2/a>(2spa= class="string">"ARC4 Cipher Algorithm"2/spa=");v.168n a>2a href="+code=MODULE_AUTHOR" class="sref">MODULE_AUTHOR2/a>(2spa= class="string">"J  >Oberheide <jon@oberheide.org>"2/spa=");v.1692/a>
The original LXR software by the LXR communityn a>,.this experimental vers >by lxr@linux.non a>. 2/div"v2div class="subfooter"> lxr.linux.no kindly hosted>by Redpill Linpro ASn a>,.provider of Linux consulting and operalue=s services since 1995. 2/div"v 2/body"v2/html"v