linux/crypto/cipher.c
<<
.6.2tio/spa" tio/form tioa .6.2ti href="../linux+v3.8.3/crypto/cipher.c">.6.2tioimg src="../.static/gfx/right.png" alt=">>">.6o/spa" .6ospa" class="lxr_search">.6.2.6.2tioinput typt27hidden" namt27navtarget" .6.2tioinput typt27text" namt27search" id27search">.6.2tiobutt typt27submit">Search.6.2tiPrefs tio/a>.6o/spa" .2ti io/div .2ti ioform ac265"="ajax+*" method="post" onsubmit="return false;">.6oinput typt27hidden" namt27ajax_lookup" id27ajax_lookup" ..2ti io/form ..2ti iodiv class="headingbott m">
odiv id27file_contents"
i i1o/a>ospa" class="comment">/*o/spa"
	i i2o/a>ospa" class="comment"> * Cryptographic API.o/spa"
	i i3o/a>ospa" class="comment"> *o/spa"
	i i4o/a>ospa" class="comment"> * Cipher opera265"s.o/spa"
	i i5o/a>ospa" class="comment"> *o/spa"
	i i6o/a>ospa" class="comment"> * Copyright (c) 2002 Jamts Morris <jmorris@intercode.com.au>o/spa"
	i i7o/a>ospa" class="comment"> * Copyright (c) 2005 Herbert Xu <herbert@gondor.apa"a.org.au>o/spa"
	i i8o/a>ospa" class="comment"> *o/spa"
	i i9o/a>ospa" class="comment"> * This program is free software; you ca" redistribute it and/or modify ito/spa"
	i 8ospa" class="comment"> * under the terms of the GNU General Public License as published by the Freeo/spa"
	i 11o/a>ospa" class="comment"> * Software Founda265"; either vers  
 2 of the License, or (at your op265")o/spa"
	i 12o/a>ospa" class="comment"> * any later vers  
.o/spa"
	i 13o/a>ospa" class="comment"> *o/spa"
	i 14o/a>ospa" class="comment"> */o/spa"
	i 15o/a>	i 16o/a>#include <linux/kernel.ho/a>>	i 17o/a>#include <linux/crypto.ho/a>>	i 18o/a>#include <linux/errno.ho/a>>	i 19o/a>#include <linux/slab.ho/a>>	i 20o/a>#include <linux/string.ho/a>>	i 21o/a>#include "internal.ho/a>"	i 22o/a>	i 23o/a>static intioa href="+code=setkey_unaligned" class="sref">setkey_unalignedo/a>(structioa href="+code=crypto_tfm" class="sref">crypto_tfmo/a> *oa href="+code=tfm" class="sref">tfmo/a>, constioa href="+code=u8" class="sref">u8o/a> *oa href="+code=key" class="sref">keyo/a>,	i 24o/a>                            unsigned intioa href="+code=keylen" class="sref">keyleno/a>)	i 25o/a>{	i 26o/a>        structioa href="+code=cipher_alg" class="sref">cipher_algo/a> *oa href="+code=cia" class="sref">ciao/a> = &oa href="+code=tfm" class="sref">tfmo/a>->oa href="+code=__crt_alg" class="sref">__crt_algo/a>->oa href="+code=cra_cipher" class="sref">cra_ciphero/a>;	i 27o/a>        unsigned longioa href="+code=alignmask" class="sref">alignmasko/a> = oa href="+code=crypto_tfm_alg_alignmask" class="sref">crypto_tfm_alg_alignmasko/a>(oa href="+code=tfm" class="sref">tfmo/a>);	i 28o/a>        intioa href="+code=ret" class="sref">reto/a>;	i 29o/a>        oa href="+code=u8" class="sref">u8o/a> *oa href="+code=buffer" class="sref">buffero/a>, *oa href="+code=alignbuffer" class="sref">alignbuffero/a>;	i 30o/a>        unsigned longioa href="+code=absize" class="sref">absizeo/a>;	i 31o/a>	i 32o/a>        oa href="+code=absize" class="sref">absizeo/a> = oa href="+code=keylen" class="sref">keyleno/a> +ioa href="+code=alignmask" class="sref">alignmasko/a>;	i 33o/a>        oa href="+code=buffer" class="sref">buffero/a> = oa href="+code=kmalloc" class="sref">kmalloco/a>(oa href="+code=absize" class="sref">absizeo/a>, oa href="+code=GFP_ATOMIC" class="sref">GFP_ATOMICo/a>);	i 34o/a>        if (!oa href="+code=buffer" class="sref">buffero/a>)	i 35o/a>                return -oa href="+code=ENOMEM" class="sref">ENOMEMo/a>;	i 36o/a>	i 37o/a>        oa href="+code=alignbuffer" class="sref">alignbuffero/a> = (oa href="+code=u8" class="sref">u8o/a> *)oa href="+code=ALIGN" class="sref">ALIGNo/a>((unsigned long)oa href="+code=buffer" class="sref">buffero/a>, oa href="+code=alignmask" class="sref">alignmasko/a> + 1);	i 38o/a>        oa href="+code=memcpy" class="sref">memcpyo/a>(oa href="+code=alignbuffer" class="sref">alignbuffero/a>, oa href="+code=key" class="sref">keyo/a>,ioa href="+code=keylen" class="sref">keyleno/a>);	i 39o/a>        oa href="+code=ret" class="sref">reto/a> = oa href="+code=cia" class="sref">ciao/a>->oa href="+code=cia_setkey" class="sref">cia_setkeyo/a>(oa href="+code=tfm" class="sref">tfmo/a>, oa href="+code=alignbuffer" class="sref">alignbuffero/a>, oa href="+code=keylen" class="sref">keyleno/a>);	i 40o/a>        oa href="+code=memset" class="sref">memseto/a>(oa href="+code=alignbuffer" class="sref">alignbuffero/a>, 0, oa href="+code=keylen" class="sref">keyleno/a>);	i 41o/a>        oa href="+code=kfree" class="sref">kfreeo/a>(oa href="+code=buffer" class="sref">buffero/a>);	i 42o/a>        return oa href="+code=ret" class="sref">reto/a>;	i 43o/a>	i 44o/a>}	i 45o/a>	i 46o/a>static intioa href="+code=setkey" class="sref">setkeyo/a>(structioa href="+code=crypto_tfm" class="sref">crypto_tfmo/a> *oa href="+code=tfm" class="sref">tfmo/a>, constioa href="+code=u8" class="sref">u8o/a> *oa href="+code=key" class="sref">keyo/a>, unsigned intioa href="+code=keylen" class="sref">keyleno/a>)	i 47o/a>{	i 48o/a>        structioa href="+code=cipher_alg" class="sref">cipher_algo/a> *oa href="+code=cia" class="sref">ciao/a> = &oa href="+code=tfm" class="sref">tfmo/a>->oa href="+code=__crt_alg" class="sref">__crt_algo/a>->oa href="+code=cra_cipher" class="sref">cra_ciphero/a>;	i 49o/a>        unsigned longioa href="+code=alignmask" class="sref">alignmasko/a> = oa href="+code=crypto_tfm_alg_alignmask" class="sref">crypto_tfm_alg_alignmasko/a>(oa href="+code=tfm" class="sref">tfmo/a>);	i 50o/a>	i 51o/a>        oa href="+code=tfm" class="sref">tfmo/a>->oa href="+code=crt_flags" class="sref">crt_flagso/a> &= ~oa href="+code=CRYPTO_TFM_RES_MASK" class="sref">CRYPTO_TFM_RES_MASKo/a>;	i 52o/a>        if (oa href="+code=keylen" class="sref">keyleno/a> < oa href="+code=cia" class="sref">ciao/a>->oa href="+code=cia_min_keysize" class="sref">cia_min_keysizeo/a> || oa href="+code=keylen" class="sref">keyleno/a> > oa href="+code=cia" class="sref">ciao/a>->oa href="+code=cia_max_keysize" class="sref">cia_max_keysizeo/a>) {	i 53o/a>                oa href="+code=tfm" class="sref">tfmo/a>->oa href="+code=crt_flags" class="sref">crt_flagso/a> |= oa href="+code=CRYPTO_TFM_RES_BAD_KEY_LEN" class="sref">CRYPTO_TFM_RES_BAD_KEY_LENo/a>;	i 54o/a>                return -oa href="+code=EINVAL" class="sref">EINVALo/a>;	i 55o/a>        }	i 56o/a>	i 57o/a>        if ((unsigned long)oa href="+code=key" class="sref">keyo/a> &ioa href="+code=alignmask" class="sref">alignmasko/a>)	i 58o/a>                return oa href="+code=setkey_unaligned" class="sref">setkey_unalignedo/a>(oa href="+code=tfm" class="sref">tfmo/a>, oa href="+code=key" class="sref">keyo/a>,ioa href="+code=keylen" class="sref">keyleno/a>);	i 59o/a>	i 60o/a>        return oa href="+code=cia" class="sref">ciao/a>->oa href="+code=cia_setkey" class="sref">cia_setkeyo/a>(oa href="+code=tfm" class="sref">tfmo/a>, oa href="+code=key" class="sref">keyo/a>,ioa href="+code=keylen" class="sref">keyleno/a>);	i 61o/a>}	i 62o/a>	i 63o/a>static voidioa href="+code=cipher_crypt_unaligned" class="sref">cipher_crypt_unalignedo/a>(voidi(*oa href="+code=fn" class="sref">fno/a>)(structioa href="+code=crypto_tfm" class="sref">crypto_tfmo/a> *,ioa href="+code=u8" class="sref">u8o/a> *,	i 64o/a>                                              constioa href="+code=u8" class="sref">u8o/a> *),	i 65o/a>                                   structioa href="+code=crypto_tfm" class="sref">crypto_tfmo/a> *oa href="+code=tfm" class="sref">tfmo/a>,	i 66o/a>                                   oa href="+code=u8" class="sref">u8o/a> *oa href="+code=dst" class="sref">dsto/a>, constioa href="+code=u8" class="sref">u8o/a> *oa href="+code=src" class="sref">srco/a>)	i 67o/a>{	i 68o/a>        unsigned longioa href="+code=alignmask" class="sref">alignmasko/a> = oa href="+code=crypto_tfm_alg_alignmask" class="sref">crypto_tfm_alg_alignmasko/a>(oa href="+code=tfm" class="sref">tfmo/a>);	i 69o/a>        unsigned intioa href="+code=size" class="sref">sizeo/a> = oa href="+code=crypto_tfm_alg_blocksize" class="sref">crypto_tfm_alg_blocksizeo/a>(oa href="+code=tfm" class="sref">tfmo/a>);	i 70o/a>        oa href="+code=u8" class="sref">u8o/a> oa href="+code=buffer" class="sref">buffero/a>[oa href="+code=size" class="sref">sizeo/a> +ioa href="+code=alignmask" class="sref">alignmasko/a>];	i 71o/a>        oa href="+code=u8" class="sref">u8o/a> *oa href="+code=tmp" class="sref">tmpo/a> = (oa href="+code=u8" class="sref">u8o/a> *)oa href="+code=ALIGN" class="sref">ALIGNo/a>((unsigned long)oa href="+code=buffer" class="sref">buffero/a>, oa href="+code=alignmask" class="sref">alignmasko/a> + 1);	i 72o/a>	i 73o/a>        oa href="+code=memcpy" class="sref">memcpyo/a>(oa href="+code=tmp" class="sref">tmpo/a>, oa href="+code=src" class="sref">srco/a>, oa href="+code=size" class="sref">sizeo/a>);	i 74o/a>        oa href="+code=fn" class="sref">fno/a>(oa href="+code=tfm" class="sref">tfmo/a>, oa href="+code=tmp" class="sref">tmpo/a>, oa href="+code=tmp" class="sref">tmpo/a>);	i 75o/a>        oa href="+code=memcpy" class="sref">memcpyo/a>(oa href="+code=dst" class="sref">dsto/a>, oa href="+code=tmp" class="sref">tmpo/a>, oa href="+code=size" class="sref">sizeo/a>);	i 76o/a>}	i 77o/a>	i 78o/a>static voidioa href="+code=cipher_encrypt_unaligned" class="sref">cipher_encrypt_unalignedo/a>(structioa href="+code=crypto_tfm" class="sref">crypto_tfmo/a> *oa href="+code=tfm" class="sref">tfmo/a>,	i 79o/a>                                     oa href="+code=u8" class="sref">u8o/a> *oa href="+code=dst" class="sref">dsto/a>, constioa href="+code=u8" class="sref">u8o/a> *oa href="+code=src" class="sref">srco/a>)	i 80o/a>{	i 81o/a>        unsigned longioa href="+code=alignmask" class="sref">alignmasko/a> = oa href="+code=crypto_tfm_alg_alignmask" class="sref">crypto_tfm_alg_alignmasko/a>(oa href="+code=tfm" class="sref">tfmo/a>);	i 82o/a>        structioa href="+code=cipher_alg" class="sref">cipher_algo/a> *oa href="+code=cipher" class="sref">ciphero/a> = &oa href="+code=tfm" class="sref">tfmo/a>->oa href="+code=__crt_alg" class="sref">__crt_algo/a>->oa href="+code=cra_cipher" class="sref">cra_ciphero/a>;	i 83o/a>	i 84o/a>        if (oa href="+code=unlikely" class="sref">unlikelyo/a>(((unsigned long)oa href="+code=dst" class="sref">dsto/a> | (unsigned long)oa href="+code=src" class="sref">srco/a>) &ioa href="+code=alignmask" class="sref">alignmasko/a>)) {	i 85o/a>                oa href="+code=cipher_crypt_unaligned" class="sref">cipher_crypt_unalignedo/a>(oa href="+code=cipher" class="sref">ciphero/a>->oa href="+code=cia_encrypt" class="sref">cia_encrypto/a>, oa href="+code=tfm" class="sref">tfmo/a>, oa href="+code=dst" class="sref">dsto/a>, oa href="+code=src" class="sref">srco/a>);	i 86o/a>                return;	i 87o/a>        }	i 88o/a>	i 89o/a>        oa href="+code=cipher" class="sref">ciphero/a>->oa href="+code=cia_encrypt" class="sref">cia_encrypto/a>(oa href="+code=tfm" class="sref">tfmo/a>, oa href="+code=dst" class="sref">dsto/a>, oa href="+code=src" class="sref">srco/a>);	i 90o/a>}	i 91o/a>	i 92o/a>static voidioa href="+code=cipher_decrypt_unaligned" class="sref">cipher_decrypt_unalignedo/a>(structioa href="+code=crypto_tfm" class="sref">crypto_tfmo/a> *oa href="+code=tfm" class="sref">tfmo/a>,	i 93o/a>                                     oa href="+code=u8" class="sref">u8o/a> *oa href="+code=dst" class="sref">dsto/a>, constioa href="+code=u8" class="sref">u8o/a> *oa href="+code=src" class="sref">srco/a>)	i 94o/a>{	i 95o/a>        unsigned longioa href="+code=alignmask" class="sref">alignmasko/a> = oa href="+code=crypto_tfm_alg_alignmask" class="sref">crypto_tfm_alg_alignmasko/a>(oa href="+code=tfm" class="sref">tfmo/a>);	i 96o/a>        structioa href="+code=cipher_alg" class="sref">cipher_algo/a> *oa href="+code=cipher" class="sref">ciphero/a> = &oa href="+code=tfm" class="sref">tfmo/a>->oa href="+code=__crt_alg" class="sref">__crt_algo/a>->oa href="+code=cra_cipher" class="sref">cra_ciphero/a>;	i 97o/a>	i 98o/a>        if (oa href="+code=unlikely" class="sref">unlikelyo/a>(((unsigned long)oa href="+code=dst" class="sref">dsto/a> | (unsigned long)oa href="+code=src" class="sref">srco/a>) &ioa href="+code=alignmask" class="sref">alignmasko/a>)) {	i 99o/a>                oa href="+code=cipher_crypt_unaligned" class="sref">cipher_crypt_unalignedo/a>(oa href="+code=cipher" class="sref">ciphero/a>->oa href="+code=cia_decrypt" class="sref">cia_decrypto/a>, oa href="+code=tfm" class="sref">tfmo/a>, oa href="+code=dst" class="sref">dsto/a>, oa href="+code=src" class="sref">srco/a>);	i100o/a>                return;	i101o/a>        }	i102o/a>	i103o/a>        oa href="+code=cipher" class="sref">ciphero/a>->oa href="+code=cia_decrypt" class="sref">cia_decrypto/a>(oa href="+code=tfm" class="sref">tfmo/a>, oa href="+code=dst" class="sref">dsto/a>, oa href="+code=src" class="sref">srco/a>);	i104o/a>}	i105o/a>	i106o/a>intioa href="+code=crypto_init_cipher_ops" class="sref">crypto_init_cipher_opso/a>(structioa href="+code=crypto_tfm" class="sref">crypto_tfmo/a> *oa href="+code=tfm" class="sref">tfmo/a>)	i107o/a>{	i108o/a>        structioa href="+code=cipher_tfm" class="sref">cipher_tfmo/a> *oa href="+code=ops" class="sref">opso/a> = &oa href="+code=tfm" class="sref">tfmo/a>->oa href="+code=crt_cipher" class="sref">crt_ciphero/a>;	i109o/a>        structioa href="+code=cipher_alg" class="sref">cipher_algo/a> *oa href="+code=cipher" class="sref">ciphero/a> = &oa href="+code=tfm" class="sref">tfmo/a>->oa href="+code=__crt_alg" class="sref">__crt_algo/a>->oa href="+code=cra_cipher" class="sref">cra_ciphero/a>;	i110o/a>	i111o/a>        oa href="+code=ops" class="sref">opso/a>->oa href="+code=cit_setkey" class="sref">cit_setkeyo/a> = oa href="+code=setkey" class="sref">setkeyo/a>;	i112o/a>        oa href="+code=ops" class="sref">opso/a>->oa href="+code=cit_encrypt_one" class="sref">cit_encrypt_oneo/a> = oa href="+code=crypto_tfm_alg_alignmask" class="sref">crypto_tfm_alg_alignmasko/a>(oa href="+code=tfm" class="sref">tfmo/a>) ?	i113o/a>                oa href="+code=cipher_encrypt_unaligned" class="sref">cipher_encrypt_unalignedo/a> : oa href="+code=cipher" class="sref">ciphero/a>->oa href="+code=cia_encrypt" class="sref">cia_encrypto/a>;	i114o/a>        oa href="+code=ops" class="sref">opso/a>->oa href="+code=cit_decrypt_one" class="sref">cit_decrypt_oneo/a> = oa href="+code=crypto_tfm_alg_alignmask" class="sref">crypto_tfm_alg_alignmasko/a>(oa href="+code=tfm" class="sref">tfmo/a>) ?	i115o/a>                oa href="+code=cipher_decrypt_unaligned" class="sref">cipher_decrypt_unalignedo/a> : oa href="+code=cipher" class="sref">ciphero/a>->oa href="+code=cia_decrypt" class="sref">cia_decrypto/a>;	i116o/a>	i117o/a>        return 0;	i118o/a>}	i119o/a>	i120o/a>voidioa href="+code=crypto_exit_cipher_ops" class="sref">crypto_exit_cipher_opso/a>(structioa href="+code=crypto_tfm" class="sref">crypto_tfmo/a> *oa href="+code=tfm" class="sref">tfmo/a>)	i121o/a>{	i122o/a>}	i123o/a>
The original LXR software by the LXR communityo/a>,ithis experimental vers by lxr@linux.noo/a>. o/div odiv class="subfooter"> lxr.linux.no kindly hosted by Redpill Linpro ASo/a>,iprovider of Linux consulting and opera265"s services since 1995. o/div o/body o/html