linux/crypto/michael_mic.c
<<
d="s /spapti /formti a d="s href="../linux+v3.9.6/crypto/michael_mic.c">d="s img src="../.static/gfx/right.png" alt=">>">d= /spaptid= spap class="lxr_search">d="sd="s input typvalhidden" namvalnavtarget" ion val">d="s input typvaltext" namvalsearch" idalsearch">d="s buttopttypvalsubmit">Searchd="s Prefsi /a>d= /spapti"s /divti"s form acd= input typvalhidden" namvalajax_lookup" idalajax_lookup" ion val">d"s /formtid"s div class="headingbottom">i div idalfile_contents"t
   1 /a> spap class="comment">/* /spapti   2 /a> spap class="comment"> * Cryptographic API /spapti   3 /a> spap class="comment"> * /spapti   4 /a> spap class="comment"> * Michael MIC (IEEE 80 v3.i/TKIP) keyed digest /spapti   5 /a> spap class="comment"> * /spapti   6 /a> spap class="comment"> * Copyright (c) 2004 Jouni Malinen <j@w1.fi> /spapti   7 /a> spap class="comment"> * /spapti   8 /a> spap class="comment"> * This program is free software; you cap redistribute it and/or modify /spapti   9 /a> spap class="comment"> * it under the terms of the GNU General Public License vers   v3.a> spap class="comment"> * published by the Free Software Founda  11 /a> spap class="comment"> */ /spapti  12 /a>#include <crypto/internal/hash.h /a>>i  13 /a>#include <asm/byteorder.h /a>>i  14 /a>#include <linux/init.h /a>>i  15 /a>#include <linux/module.h /a>>i  16 /a>#include <linux/string.h /a>>i  17 /a>#include <linux/typvs.h /a>>i  18 /a>i  19 /a>i  2v3.a>struct  a href="+code=michael_mic_ctx" class="sref">michael_mic_ctx3.a> {i  21 /a>         a href="+code=u32" class="sref">u32 /a>  a href="+code=l" class="sref">l /a>,  a href="+code=r" class="sref">r /a>;i  22 /a>};i  23 /a>i  243.a>struct  a href="+code=michael_mic_desc_ctx" class="sref">michael_mic_desc_ctx3.a> {i  25 /a>         a href="+code=u8" class="sref">u8 /a>  a href="+code=pending" class="sref">pending /a>[4];i  26 /a>         a href="+code=size_t" class="sref">size_t /a>  a href="+code=pending_len" class="sref">pending_len /a>;i  27 /a>i  28 /a>         a href="+code=u32" class="sref">u32 /a>  a href="+code=l" class="sref">l /a>,  a href="+code=r" class="sref">r /a>;i  29 /a>};i  30 /a>i  313.a>static  a href="+code=inline" class="sref">inline /a>  a href="+code=u32" class="sref">u32 /a>  a href="+code=xswap" class="sref">xswap /a>( a href="+code=u32" class="sref">u32 /a>  a href="+code=val" class="sref">val /a>)i  32 /a>{i  33 /a>        return (( a href="+code=val" class="sref">val /a> & 0x00ff00ff) << 8) | (( a href="+code=val" class="sref">val /a> & 0xff00ff00) >> 8);i  343.a>}i  35 /a>i  36 /a>i  37 /a>#define  a href="+code=michael_block" class="sref">michael_block /a>( a href="+code=l" class="sref">l /a>,  a href="+code=r" class="sref">r /a>)     \i  38 /a>do {                            \i  39 /a>         a href="+code=r" class="sref">r /a> ^=  a href="+code=rol32" class="sref">rol32 /a>( a href="+code=l" class="sref">l /a>, 17);      \i  40 /a>         a href="+code=l" class="sref">l /a> +=  a href="+code=r" class="sref">r /a>;                 \i  41 /a>         a href="+code=r" class="sref">r /a> ^=  a href="+code=xswap" class="sref">xswap /a>( a href="+code=l" class="sref">l /a>);          \i  42 /a>         a href="+code=l" class="sref">l /a> +=  a href="+code=r" class="sref">r /a>;                 \i  43 /a>         a href="+code=r" class="sref">r /a> ^=  a href="+code=rol32" class="sref">rol32 /a>( a href="+code=l" class="sref">l /a>, 3);       \i  44 /a>         a href="+code=l" class="sref">l /a> +=  a href="+code=r" class="sref">r /a>;                 \i  45 /a>         a href="+code=r" class="sref">r /a> ^=  a href="+code=ror32" class="sref">ror32 /a>( a href="+code=l" class="sref">l /a>, 2);       \i  46 /a>         a href="+code=l" class="sref">l /a> +=  a href="+code=r" class="sref">r /a>;                 \i  47 /a>} while (0)i  48 /a>i  49 /a>i  503.a>static int  a href="+code=michael_init" class="sref">michael_init /a>(struct  a href="+code=shash_desc" class="sref">shash_desc /a> * a href="+code=desc" class="sref">desc /a>)i  51 /a>{i  52 /a>        struct  a href="+code=michael_mic_desc_ctx" class="sref">michael_mic_desc_ctx3.a> * a href="+code=mctx" class="sref">mctx3.a> =  a href="+code=shash_desc_ctx" class="sref">shash_desc_ctx /a>( a href="+code=desc" class="sref">desc /a>);i  53 /a>        struct  a href="+code=michael_mic_ctx" class="sref">michael_mic_ctx3.a> * a href="+code=ctx" class="sref">ctx3.a> =  a href="+code=crypto_shash_ctx" class="sref">crypto_shash_ctx /a>( a href="+code=desc" class="sref">desc /a>-> a href="+code=tfm" class="sref">tfm /a>);i  54 /a>         a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=pending_len" class="sref">pending_len /a> = 0;i  55 /a>         a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=l" class="sref">l /a> =  a href="+code=ctx" class="sref">ctx3.a>-> a href="+code=l" class="sref">l /a>;i  56 /a>         a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=r" class="sref">r /a> =  a href="+code=ctx" class="sref">ctx3.a>-> a href="+code=r" class="sref">r /a>;i  57 /a>i  58 /a>        return 0;i  593.a>}i  60 /a>i  61 /a>i  623.a>static int  a href="+code=michael_update" class="sref">michael_update /a>(struct  a href="+code=shash_desc" class="sref">shash_desc /a> * a href="+code=desc" class="sref">desc /a>, const  a href="+code=u8" class="sref">u8 /a> * a href="+code=data" class="sref">data /a>,i  63 /a>                           unsigned int  a href="+code=len" class="sref">len /a>)i  64 /a>{i  65 /a>        struct  a href="+code=michael_mic_desc_ctx" class="sref">michael_mic_desc_ctx3.a> * a href="+code=mctx" class="sref">mctx3.a> =  a href="+code=shash_desc_ctx" class="sref">shash_desc_ctx /a>( a href="+code=desc" class="sref">desc /a>);i  66 /a>        const  a href="+code=__le32" class="sref">__le323.a> * a href="+code=src" class="sref">src /a>;i  67 /a>i  68 /a>        if ( a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=pending_len" class="sref">pending_len /a>) {i  69 /a>                int  a href="+code=flen" class="sref">flen /a> = 4 -  a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=pending_len" class="sref">pending_len /a>;i  70 /a>                if ( a href="+code=flen" class="sref">flen /a> >  a href="+code=len" class="sref">len /a>)i  71 /a>                         a href="+code=flen" class="sref">flen /a> =  a href="+code=len" class="sref">len /a>;i  72 /a>                 a href="+code=memcpy" class="sref">memcpy /a>(& a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=pending" class="sref">pending /a>[ a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=pending_len" class="sref">pending_len /a>],  a href="+code=data" class="sref">data /a>,  a href="+code=flen" class="sref">flen /a>);i  73 /a>                 a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=pending_len" class="sref">pending_len /a> +=  a href="+code=flen" class="sref">flen /a>;i  74 /a>                 a href="+code=data" class="sref">data /a> +=  a href="+code=flen" class="sref">flen /a>;i  75 /a>                 a href="+code=len" class="sref">len /a> -=  a href="+code=flen" class="sref">flen /a>;i  76 /a>i  77 /a>                if ( a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=pending_len" class="sref">pending_len /a> < 4)i  78 /a>                        return 0;i  79 /a>i  80 /a>                 a href="+code=src" class="sref">src /a> = (const  a href="+code=__le32" class="sref">__le323.a> *) a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=pending" class="sref">pending /a>;i  81 /a>                 a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=l" class="sref">l /a> ^=  a href="+code=le32_to_cpup" class="sref">le32_to_cpup /a>( a href="+code=src" class="sref">src /a>);i  82 /a>                 a href="+code=michael_block" class="sref">michael_block /a>( a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=l" class="sref">l /a>,  a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=r" class="sref">r /a>);i  83 /a>                 a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=pending_len" class="sref">pending_len /a> = 0;i  84 /a>        }i  85 /a>i  86 /a>         a href="+code=src" class="sref">src /a> = (const  a href="+code=__le32" class="sref">__le323.a> *) a href="+code=data" class="sref">data /a>;i  87 /a>i  88 /a>        while ( a href="+code=len" class="sref">len /a> >= 4) {i  89 /a>                 a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=l" class="sref">l /a> ^=  a href="+code=le32_to_cpup" class="sref">le32_to_cpup /a>( a href="+code=src" class="sref">src /a>++);i  90 /a>                 a href="+code=michael_block" class="sref">michael_block /a>( a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=l" class="sref">l /a>,  a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=r" class="sref">r /a>);i  91 /a>                 a href="+code=len" class="sref">len /a> -= 4;i  92 /a>        }i  93 /a>i  94 /a>        if ( a href="+code=len" class="sref">len /a> > 0) {i  95 /a>                 a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=pending_len" class="sref">pending_len /a> =  a href="+code=len" class="sref">len /a>;i  96 /a>                 a href="+code=memcpy" class="sref">memcpy /a>( a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=pending" class="sref">pending /a>,  a href="+code=src" class="sref">src /a>,  a href="+code=len" class="sref">len /a>);i  97 /a>        }i  98 /a>i  99 /a>        return 0;i 1003.a>}i 101 /a>i 102 /a>i 1033.a>static int  a href="+code=michael_final" class="sref">michael_final /a>(struct  a href="+code=shash_desc" class="sref">shash_desc /a> * a href="+code=desc" class="sref">desc /a>,  a href="+code=u8" class="sref">u8 /a> * a href="+code=out" class="sref">out /a>)i 104 /a>{i 105 /a>        struct  a href="+code=michael_mic_desc_ctx" class="sref">michael_mic_desc_ctx3.a> * a href="+code=mctx" class="sref">mctx3.a> =  a href="+code=shash_desc_ctx" class="sref">shash_desc_ctx /a>( a href="+code=desc" class="sref">desc /a>);i 106 /a>         a href="+code=u8" class="sref">u8 /a> * a href="+code=data" class="sref">data /a> =  a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=pending" class="sref">pending /a>;i 107 /a>         a href="+code=__le32" class="sref">__le323.a> * a href="+code=dst" class="sref">dst /a> = ( a href="+code=__le32" class="sref">__le323.a> *) a href="+code=out" class="sref">out /a>;i 108 /a>i 109 /a>         spap class="comment">/* Last block and padding (0x5a, 4..7 x 0) */ /spapti 110 /a>        switch ( a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=pending_len" class="sref">pending_len /a>) {i 111 /a>        case 0:i 112 /a>                 a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=l" class="sref">l /a> ^= 0x5a;i 113 /a>                break;i 114 /a>        case 1:i 115 /a>                 a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=l" class="sref">l /a> ^=  a href="+code=data" class="sref">data /a>[0] | 0x5a00;i 116 /a>                break;i 117 /a>        case 2:i 118 /a>                 a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=l" class="sref">l /a> ^=  a href="+code=data" class="sref">data /a>[0] | ( a href="+code=data" class="sref">data /a>[1] << 8) | 0x5a0000;i 119 /a>                break;i 120 /a>        case 3:i 121 /a>                 a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=l" class="sref">l /a> ^=  a href="+code=data" class="sref">data /a>[0] | ( a href="+code=data" class="sref">data /a>[1] << 8) | ( a href="+code=data" class="sref">data /a>[2] << 16) |i 122 /a>                        0x5a000000;i 123 /a>                break;i 124 /a>        }i 125 /a>         a href="+code=michael_block" class="sref">michael_block /a>( a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=l" class="sref">l /a>,  a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=r" class="sref">r /a>);i 126 /a>         spap class="comment">/* l ^= 0; */ /spapti 127 /a>         a href="+code=michael_block" class="sref">michael_block /a>( a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=l" class="sref">l /a>,  a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=r" class="sref">r /a>);i 128 /a>i 129 /a>         a href="+code=dst" class="sref">dst /a>[0] =  a href="+code=cpu_to_le32" class="sref">cpu_to_le32 /a>( a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=l" class="sref">l /a>);i 130 /a>         a href="+code=dst" class="sref">dst /a>[1] =  a href="+code=cpu_to_le32" class="sref">cpu_to_le32 /a>( a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=r" class="sref">r /a>);i 131 /a>i 132 /a>        return 0;i 133 /a>}i 1343.a>i 135 /a>i 136 /a>static int  a href="+code=michael_setkey" class="sref">michael_setkey /a>(struct  a href="+code=crypto_shash" class="sref">crypto_shash3.a> * a href="+code=tfm" class="sref">tfm /a>, const  a href="+code=u8" class="sref">u8 /a> * a href="+code=key" class="sref">key /a>,i 137 /a>                          unsigned int  a href="+code=keylen" class="sref">keylen /a>)i 138 /a>{i 139 /a>        struct  a href="+code=michael_mic_ctx" class="sref">michael_mic_ctx3.a> * a href="+code=mctx" class="sref">mctx3.a> =  a href="+code=crypto_shash_ctx" class="sref">crypto_shash_ctx /a>( a href="+code=tfm" class="sref">tfm /a>);i 140 /a>i 141 /a>        const  a href="+code=__le32" class="sref">__le323.a> * a href="+code=data" class="sref">data /a> = (const  a href="+code=__le32" class="sref">__le323.a> *) a href="+code=key" class="sref">key /a>;i 142 /a>i 143 /a>        if ( a href="+code=keylen" class="sref">keylen /a> != 8) {i 144 /a>                 a href="+code=crypto_shash_set_flags" class="sref">crypto_shash_set_flags /a>( a href="+code=tfm" class="sref">tfm /a>,  a href="+code=CRYPTO_TFM_RES_BAD_KEY_LEN" class="sref">CRYPTO_TFM_RES_BAD_KEY_LEN /a>);i 145 /a>                return - a href="+code=EINVAL" class="sref">EINVAL /a>;i 146 /a>        }i 147 /a>i 148 /a>         a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=l" class="sref">l /a> =  a href="+code=le32_to_cpu" class="sref">le32_to_cpu /a>( a href="+code=data" class="sref">data /a>[0]);i 149 /a>         a href="+code=mctx" class="sref">mctx3.a>-> a href="+code=r" class="sref">r /a> =  a href="+code=le32_to_cpu" class="sref">le32_to_cpu /a>( a href="+code=data" class="sref">data /a>[1]);i 150 /a>        return 0;i 151 /a>}i 152 /a>i 1533.a>static struct  a href="+code=shash_alg" class="sref">shash_alg /a>  a href="+code=alg" class="sref">alg /a> = {i 154 /a>        . a href="+code=digestsize" class="sref">digestsize /a>             =       8,i 155 /a>        . a href="+code=setkey" class="sref">setkey /a>                 =        a href="+code=michael_setkey" class="sref">michael_setkey /a>,i 156 /a>        . a href="+code=init" class="sref">init /a>                   =        a href="+code=michael_init" class="sref">michael_init /a>,i 157 /a>        . a href="+code=update" class="sref">update /a>                 =        a href="+code=michael_update" class="sref">michael_update /a>,i 158 /a>        . a href="+code=final" class="sref">final /a>                  =        a href="+code=michael_final" class="sref">michael_final /a>,i 159 /a>        . a href="+code=descsize" class="sref">descsize /a>               =       sizeof(struct  a href="+code=michael_mic_desc_ctx" class="sref">michael_mic_desc_ctx /a>),i 160 /a>        . a href="+code=base" class="sref">base /a>                   =       {i 161 /a>                . a href="+code=cra_namv" class="sref">cra_namv /a>               =        spap class="string">"michael_mic" /spapt,i 162 /a>                . a href="+code=cra_blocksize" class="sref">cra_blocksize /a>          =       8,i 163 /a>                . a href="+code=cra_alignmask" class="sref">cra_alignmask /a>          =       3,i 164 /a>                . a href="+code=cra_ctxsize" class="sref">cra_ctxsize /a>            =       sizeof(struct  a href="+code=michael_mic_ctx" class="sref">michael_mic_ctx3.a>),i 165 /a>                . a href="+code=cra_module" class="sref">cra_module /a>             =        a href="+code=THIS_MODULE" class="sref">THIS_MODULE /a>,i 166 /a>        }i 167 /a>};i 168 /a>i 169 /a>static int  a href="+code=__init" class="sref">__init /a>  a href="+code=michael_mic_init" class="sref">michael_mic_init /a>(void)i 170 /a>{i 171 /a>        return  a href="+code=crypto_register_shash" class="sref">crypto_register_shash /a>(& a href="+code=alg" class="sref">alg /a>);i 172 /a>}i 173 /a>i 1743.a>i 175 /a>static void  a href="+code=__exit" class="sref">__exit /a>  a href="+code=michael_mic_exit" class="sref">michael_mic_exit /a>(void)i 176 /a>{i 177 /a>         a href="+code=crypto_unregister_shash" class="sref">crypto_unregister_shash /a>(& a href="+code=alg" class="sref">alg /a>);i 178 /a>}i 179 /a>i 180 /a>i 181 /a> a href="+code=module_init" class="sref">module_init /a>( a href="+code=michael_mic_init" class="sref">michael_mic_init /a>);i 182 /a> a href="+code=module_exit" class="sref">module_exit /a>( a href="+code=michael_mic_exit" class="sref">michael_mic_exit /a>);i 183 /a>i 184 /a> a href="+code=MODULE_LICENSE" class="sref">MODULE_LICENSE /a>( spap class="string">"GPL v2" /spapt);i 185 /a> a href="+code=MODULE_DESCRIPTION" class="sref">MODULE_DESCRIPTION /a>( spap class="string">"Michael MIC" /spapt);i 186 /a> a href="+code=MODULE_AUTHOR" class="sref">MODULE_AUTHOR /a>( spap class="string">"Jouni Malinen <j@w1.fi>" /spapt);i 187 /a>
The original LXR software by the LXR community /a>, this experimental verslxr@linux.no /a>. /divti div class="subfooter"> lxr.linux.no kindly hostedtby Redpill Linpro AS /a>, provider of Linux consulting and opera