linux/crypto/michael_mic.c
<<
2.7< 3 /spa 2 3 /form 2 3 a 2.7< 3 href="../linux+v3.7.5/crypto/michael_mic.c">2.7< 3 img src="../.static/gfx/right.png" alt=">>">2. /spa 22. spa class="lxr_search">2.7< ="+search" method="post" onsubmit="return do_search(this);">2.7< 3 input typ 2 hidden" nam 2 navtarget" ion> 2 ">2.7< 3 input typ 2 text" nam 2 search" id2 search">2.7< 3 buttopttyp 2 submit">Search2.7< 3Prefs2 3 /a>2. /spa 27< 3 3 /div 27< 3 3 form ac > ="ajax+*" method="post" onsubmit="return false;">2. input typ 2 hidden" nam 2 ajax_lookup" id2 ajax_lookup" ion> 2 ">27< 3 3 /form 227< 3 3 div class="headingbottom">
2 div id2 file_contents"
3 31
/a>
spa  class="comment">/*
/spa  23 32
/a>
spa  class="comment"> * Cryptographic API
/spa  23 33
/a>
spa  class="comment"> *
/spa  23 34
/a>
spa  class="comment"> * Michael MIC (IEEE 802.10i/TKIP) keyed digest
/spa  23 35
/a>
spa  class="comment"> *
/spa  23 36
/a>
spa  class="comment"> * Copyright (c) 2004 Jouni Malinen <j@w1.fi>
/spa  23 37
/a>
spa  class="comment"> *
/spa  23 38
/a>
spa  class="comment"> * This program is free software; you ca  redistribute it and/or modify
/spa  23 39
/a>
spa  class="comment"> * it under the terms of the GNU General Public License vers/opt2 as
/spa  23 9"
	a>
spa  class="comment"> * published by the Free Software Founda >
 .
/spa  23 11
/a>
spa  class="comment"> */
/spa  23 12
/a>#include <crypto/internal/hash.h
/a>>23 13
/a>#include <asm/byteorder.h
/a>>23 14
/a>#include <linux/init.h
/a>>23 15
/a>#include <linux/module.h
/a>>23 16
/a>#include <linux/string.h
/a>>23 17
/a>#include <linux/typ
s.h
/a>>23 18
/a>23 19
/a>23 2"
	a>struct3
a href="+code=michael_mic_ctx" class="sref">michael_mic_ctx
	a> {23 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>;23 22
/a>};23 23
/a>23 24
	a>struct3
a href="+code=michael_mic_desc_ctx" class="sref">michael_mic_desc_ctx
	a> {23 25
/a>        
a href="+code=u8" class="sref">u8
/a> 
a href="+code=pending" class="sref">pending
/a>[4];23 26
/a>        
a href="+code=size_t" class="sref">size_t
/a> 
a href="+code=pending_len" class="sref">pending_len
/a>;23 27
/a>23 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>;23 29
/a>};23 30
/a>23 31
	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>)23 32
/a>{23 33
/a>        return ((
a href="+code=val" class="sref">val
/a> & 0x00ff00ff) << 8) | ((
a href="+code=val" class="sref">val
/a> & 0xff00ff00) >> 8);23 34
	a>}23 35
/a>23 36
/a>23 37
/a>#define3
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>)     \23 38
/a>do {                            \23 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);      \23 40
/a>        
a href="+code=l" class="sref">l
/a> += 
a href="+code=r" class="sref">r
/a>;                 \23 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>);          \23 42
/a>        
a href="+code=l" class="sref">l
/a> += 
a href="+code=r" class="sref">r
/a>;                 \23 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);       \23 44
/a>        
a href="+code=l" class="sref">l
/a> += 
a href="+code=r" class="sref">r
/a>;                 \23 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);       \23 46
/a>        
a href="+code=l" class="sref">l
/a> += 
a href="+code=r" class="sref">r
/a>;                 \23 47
/a>} while (0)23 48
/a>23 49
/a>23 50
	a>static int3
a href="+code=michael_init" class="sref">michael_init
/a>(struct3
a href="+code=shash_desc" class="sref">shash_desc
/a> *
a href="+code=desc" class="sref">desc
/a>)23 51
/a>{23 52
/a>        struct3
a href="+code=michael_mic_desc_ctx" class="sref">michael_mic_desc_ctx
	a> *
a href="+code=mctx" class="sref">mctx
	a> = 
a href="+code=shash_desc_ctx" class="sref">shash_desc_ctx
/a>(
a href="+code=desc" class="sref">desc
/a>);23 53
/a>        struct3
a href="+code=michael_mic_ctx" class="sref">michael_mic_ctx
	a> *
a href="+code=ctx" class="sref">ctx
	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>);23 54
/a>        
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=pending_len" class="sref">pending_len
/a> = 0;23 55
/a>        
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=l" class="sref">l
/a> = 
a href="+code=ctx" class="sref">ctx
	a>->
a href="+code=l" class="sref">l
/a>;23 56
/a>        
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=r" class="sref">r
/a> = 
a href="+code=ctx" class="sref">ctx
	a>->
a href="+code=r" class="sref">r
/a>;23 57
/a>23 58
/a>        return 0;23 59
	a>}23 60
/a>23 61
/a>23 62
	a>static int3
a href="+code=michael_update" class="sref">michael_update
/a>(struct3
a href="+code=shash_desc" class="sref">shash_desc
/a> *
a href="+code=desc" class="sref">desc
/a>, const3
a href="+code=u8" class="sref">u8
/a> *
a href="+code=data" class="sref">data
/a>,23 63
/a>                           unsigned int3
a href="+code=len" class="sref">len
/a>)23 64
/a>{23 65
/a>        struct3
a href="+code=michael_mic_desc_ctx" class="sref">michael_mic_desc_ctx
	a> *
a href="+code=mctx" class="sref">mctx
	a> = 
a href="+code=shash_desc_ctx" class="sref">shash_desc_ctx
/a>(
a href="+code=desc" class="sref">desc
/a>);23 66
/a>        const3
a href="+code=__le32" class="sref">__le32
	a> *
a href="+code=src" class="sref">src
/a>;23 67
/a>23 68
/a>        if (
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=pending_len" class="sref">pending_len
/a>) {23 69
/a>                int3
a href="+code=flen" class="sref">flen
/a> = 4 - 
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=pending_len" class="sref">pending_len
/a>;23 70
/a>                if (
a href="+code=flen" class="sref">flen
/a> > 
a href="+code=len" class="sref">len
/a>)23 71
/a>                        
a href="+code=flen" class="sref">flen
/a> = 
a href="+code=len" class="sref">len
/a>;23 72
/a>                
a href="+code=memcpy" class="sref">memcpy
/a>(&
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=pending" class="sref">pending
/a>[
a href="+code=mctx" class="sref">mctx
	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>);23 73
/a>                
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=pending_len" class="sref">pending_len
/a> += 
a href="+code=flen" class="sref">flen
/a>;23 74
/a>                
a href="+code=data" class="sref">data
/a> += 
a href="+code=flen" class="sref">flen
/a>;23 75
/a>                
a href="+code=len" class="sref">len
/a> -= 
a href="+code=flen" class="sref">flen
/a>;23 76
/a>23 77
/a>                if (
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=pending_len" class="sref">pending_len
/a> < 4)23 78
/a>                        return 0;23 79
/a>23 80
/a>                
a href="+code=src" class="sref">src
/a> = (const3
a href="+code=__le32" class="sref">__le32
	a> *)
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=pending" class="sref">pending
/a>;23 81
/a>                
a href="+code=mctx" class="sref">mctx
	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>);23 82
/a>                
a href="+code=michael_block" class="sref">michael_block
/a>(
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=l" class="sref">l
/a>, 
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=r" class="sref">r
/a>);23 83
/a>                
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=pending_len" class="sref">pending_len
/a> = 0;23 84
/a>        }23 85
/a>23 86
/a>        
a href="+code=src" class="sref">src
/a> = (const3
a href="+code=__le32" class="sref">__le32
	a> *)
a href="+code=data" class="sref">data
/a>;23 87
/a>23 88
/a>        while (
a href="+code=len" class="sref">len
/a> >= 4) {23 89
/a>                
a href="+code=mctx" class="sref">mctx
	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>++);23 90
/a>                
a href="+code=michael_block" class="sref">michael_block
/a>(
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=l" class="sref">l
/a>, 
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=r" class="sref">r
/a>);23 91
/a>                
a href="+code=len" class="sref">len
/a> -= 4;23 92
/a>        }23 93
/a>23 94
/a>        if (
a href="+code=len" class="sref">len
/a> > 0) {23 95
/a>                
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=pending_len" class="sref">pending_len
/a> = 
a href="+code=len" class="sref">len
/a>;23 96
/a>                
a href="+code=memcpy" class="sref">memcpy
/a>(
a href="+code=mctx" class="sref">mctx
	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>);23 97
/a>        }23 98
/a>23 99
/a>        return 0;23100
	a>}23101
/a>23102
/a>23103
	a>static int3
a href="+code=michael_final" class="sref">michael_final
/a>(struct3
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>)23104
/a>{23105
/a>        struct3
a href="+code=michael_mic_desc_ctx" class="sref">michael_mic_desc_ctx
	a> *
a href="+code=mctx" class="sref">mctx
	a> = 
a href="+code=shash_desc_ctx" class="sref">shash_desc_ctx
/a>(
a href="+code=desc" class="sref">desc
/a>);23106
/a>        
a href="+code=u8" class="sref">u8
/a> *
a href="+code=data" class="sref">data
/a> = 
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=pending" class="sref">pending
/a>;23107
/a>        
a href="+code=__le32" class="sref">__le32
	a> *
a href="+code=dst" class="sref">dst
/a> = (
a href="+code=__le32" class="sref">__le32
	a> *)
a href="+code=out" class="sref">out
/a>;23108
/a>23109
/a>        
spa  class="comment">/* Last3block and padding (0x5a, 4..7 x 0) */
/spa  23110
/a>        switch (
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=pending_len" class="sref">pending_len
/a>) {23111
/a>        case 0:23112
/a>                
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=l" class="sref">l
/a> ^= 0x5a;23113
/a>                break;23114
/a>        case 1:23115
/a>                
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=l" class="sref">l
/a> ^= 
a href="+code=data" class="sref">data
/a>[0] | 0x5a00;23116
/a>                break;23117
/a>        case 2:23118
/a>                
a href="+code=mctx" class="sref">mctx
	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;23119
/a>                break;23120
/a>        case 3:23121
/a>                
a href="+code=mctx" class="sref">mctx
	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) |23122
/a>                        0x5a000000;23123
/a>                break;23124
/a>        }23125
/a>        
a href="+code=michael_block" class="sref">michael_block
/a>(
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=l" class="sref">l
/a>, 
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=r" class="sref">r
/a>);23126
/a>        
spa  class="comment">/* l ^= 0; */
/spa  23127
/a>        
a href="+code=michael_block" class="sref">michael_block
/a>(
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=l" class="sref">l
/a>, 
a href="+code=mctx" class="sref">mctx
	a>->
a href="+code=r" class="sref">r
/a>);23128
/a>23129
/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">mctx
	a>->
a href="+code=l" class="sref">l
/a>);23130
/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">mctx
	a>->
a href="+code=r" class="sref">r
/a>);23131
/a>23132
/a>        return 0;23133
/a>}23134
	a>23135
/a>23136
/a>static int3
a href="+code=michael_setkey" class="sref">michael_setkey
/a>(struct3
a href="+code=crypto_shash" class="sref">crypto_shash
	a> *
a href="+code=tfm" class="sref">tfm
/a>, const3
a href="+code=u8" class="sref">u8
/a> *
a href="+code=key" class="sref">key
/a>,23137
/a>                          unsigned int3
a href="+code=keylen" class="sref">keylen
/a>)23138
/a>{23139
/a>        struct3
a href="+code=michael_mic_ctx" class="sref">michael_mic_ctx
	a> *
a href="+code=mctx" class="sref">mctx
	a> = 
a href="+code=crypto_shash_ctx" class="sref">crypto_shash_ctx
/a>(
a href="+code=tfm" class="sref">tfm
/a>);23140
/a>23141
/a>        const3
a href="+code=__le32" class="sref">__le32
	a> *
a href="+code=data" class="sref">data
/a> = (const3
a href="+code=__le32" class="sref">__le32
	a> *)
a href="+code=key" class="sref">key
/a>;23142
/a>23143
/a>        if (
a href="+code=keylen" class="sref">keylen
/a> != 8) {23144
/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>);23145
/a>                return -
a href="+code=EINVAL" class="sref">EINVAL
/a>;23146
/a>        }23147
/a>23148
/a>        
a href="+code=mctx" class="sref">mctx
	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]);23149
/a>        
a href="+code=mctx" class="sref">mctx
	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]);23150
/a>        return 0;23151
/a>}23152
/a>23153
	a>static struct3
a href="+code=shash_alg" class="sref">shash_alg
/a> 
a href="+code=alg" class="sref">alg
/a> = {23154
/a>        .
a href="+code=digestsize" class="sref">digestsize
/a>             =       8,23155
/a>        .
a href="+code=setkey" class="sref">setkey
/a>                 =       
a href="+code=michael_setkey" class="sref">michael_setkey
/a>,23156
/a>        .
a href="+code=init" class="sref">init
/a>                   =       
a href="+code=michael_init" class="sref">michael_init
/a>,23157
/a>        .
a href="+code=update" class="sref">update
/a>                 =       
a href="+code=michael_update" class="sref">michael_update
/a>,23158
/a>        .
a href="+code=final" class="sref">final
/a>                  =       
a href="+code=michael_final" class="sref">michael_final
/a>,23159
/a>        .
a href="+code=descsize" class="sref">descsize
/a>               =       sizeof(struct3
a href="+code=michael_mic_desc_ctx" class="sref">michael_mic_desc_ctx
/a>),23160
/a>        .
a href="+code=base" class="sref">base
/a>                   =       {23161
/a>                .
a href="+code=cra_nam
" class="sref">cra_nam

/a>               =       
spa  class="string">"michael_mic"
/spa  ,23162
/a>                .
a href="+code=cra_blocksize" class="sref">cra_blocksize
/a>          =       8,23163
/a>                .
a href="+code=cra_alignmask" class="sref">cra_alignmask
/a>          =       3,23164
/a>                .
a href="+code=cra_ctxsize" class="sref">cra_ctxsize
/a>            =       sizeof(struct3
a href="+code=michael_mic_ctx" class="sref">michael_mic_ctx
	a>),23165
/a>                .
a href="+code=cra_module" class="sref">cra_module
/a>             =       
a href="+code=THIS_MODULE" class="sref">THIS_MODULE
/a>,23166
/a>        }23167
/a>};23168
/a>23169
/a>static int3
a href="+code=__init" class="sref">__init
/a>3
a href="+code=michael_mic_init" class="sref">michael_mic_init
/a>(void)23170
/a>{23171
/a>        return 
a href="+code=crypto_register_shash" class="sref">crypto_register_shash
/a>(&
a href="+code=alg" class="sref">alg
/a>);23172
/a>}23173
/a>23174
	a>23175
/a>static void3
a href="+code=__exit" class="sref">__exit
/a>3
a href="+code=michael_mic_exit" class="sref">michael_mic_exit
/a>(void)23176
/a>{23177
/a>        
a href="+code=crypto_unregister_shash" class="sref">crypto_unregister_shash
/a>(&
a href="+code=alg" class="sref">alg
/a>);23178
/a>}23179
/a>23180
/a>23181
/a>
a href="+code=module_init" class="sref">module_init
/a>(
a href="+code=michael_mic_init" class="sref">michael_mic_init
/a>);23182
/a>
a href="+code=module_exit" class="sref">module_exit
/a>(
a href="+code=michael_mic_exit" class="sref">michael_mic_exit
/a>);23183
/a>23184
/a>
a href="+code=MODULE_LICENSE" class="sref">MODULE_LICENSE
/a>(
spa  class="string">"GPL v2"
/spa  );23185
/a>
a href="+code=MODULE_DESCRIPTION" class="sref">MODULE_DESCRIPTION
/a>(
spa  class="string">"Michael MIC"
/spa  );23186
/a>
a href="+code=MODULE_AUTHOR" class="sref">MODULE_AUTHOR
/a>(
spa  class="string">"Jouni Malinen <j@w1.fi>"
/spa  );23187
/a>
The original LXR software by the LXR community /a>, this experimental vers/optby lxr@linux.no /a>. /div 2 div class="subfooter"> lxr.linux.no kindly hostedtby Redpill Linpro AS /a>, provider of Linux consulting and opera > s services since 1995. /div 2 /body 2 /html 2