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

TOMOYO Linux Cross Reference
Linux/crypto/michael_mic.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /crypto/michael_mic.c (Version linux-6.11.5) and /crypto/michael_mic.c (Version policy-sample)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 
  2 /*                                                
  3  * Cryptographic API                              
  4  *                                                
  5  * Michael MIC (IEEE 802.11i/TKIP) keyed diges    
  6  *                                                
  7  * Copyright (c) 2004 Jouni Malinen <j@w1.fi>     
  8  */                                               
  9 #include <crypto/internal/hash.h>                 
 10 #include <asm/unaligned.h>                        
 11 #include <linux/init.h>                           
 12 #include <linux/module.h>                         
 13 #include <linux/string.h>                         
 14 #include <linux/types.h>                          
 15                                                   
 16                                                   
 17 struct michael_mic_ctx {                          
 18         u32 l, r;                                 
 19 };                                                
 20                                                   
 21 struct michael_mic_desc_ctx {                     
 22         __le32 pending;                           
 23         size_t pending_len;                       
 24                                                   
 25         u32 l, r;                                 
 26 };                                                
 27                                                   
 28 static inline u32 xswap(u32 val)                  
 29 {                                                 
 30         return ((val & 0x00ff00ff) << 8) | ((v    
 31 }                                                 
 32                                                   
 33                                                   
 34 #define michael_block(l, r)     \                 
 35 do {                            \                 
 36         r ^= rol32(l, 17);      \                 
 37         l += r;                 \                 
 38         r ^= xswap(l);          \                 
 39         l += r;                 \                 
 40         r ^= rol32(l, 3);       \                 
 41         l += r;                 \                 
 42         r ^= ror32(l, 2);       \                 
 43         l += r;                 \                 
 44 } while (0)                                       
 45                                                   
 46                                                   
 47 static int michael_init(struct shash_desc *des    
 48 {                                                 
 49         struct michael_mic_desc_ctx *mctx = sh    
 50         struct michael_mic_ctx *ctx = crypto_s    
 51         mctx->pending_len = 0;                    
 52         mctx->l = ctx->l;                         
 53         mctx->r = ctx->r;                         
 54                                                   
 55         return 0;                                 
 56 }                                                 
 57                                                   
 58                                                   
 59 static int michael_update(struct shash_desc *d    
 60                            unsigned int len)      
 61 {                                                 
 62         struct michael_mic_desc_ctx *mctx = sh    
 63                                                   
 64         if (mctx->pending_len) {                  
 65                 int flen = 4 - mctx->pending_l    
 66                 if (flen > len)                   
 67                         flen = len;               
 68                 memcpy((u8 *)&mctx->pending +     
 69                 mctx->pending_len += flen;        
 70                 data += flen;                     
 71                 len -= flen;                      
 72                                                   
 73                 if (mctx->pending_len < 4)        
 74                         return 0;                 
 75                                                   
 76                 mctx->l ^= le32_to_cpu(mctx->p    
 77                 michael_block(mctx->l, mctx->r    
 78                 mctx->pending_len = 0;            
 79         }                                         
 80                                                   
 81         while (len >= 4) {                        
 82                 mctx->l ^= get_unaligned_le32(    
 83                 michael_block(mctx->l, mctx->r    
 84                 data += 4;                        
 85                 len -= 4;                         
 86         }                                         
 87                                                   
 88         if (len > 0) {                            
 89                 mctx->pending_len = len;          
 90                 memcpy(&mctx->pending, data, l    
 91         }                                         
 92                                                   
 93         return 0;                                 
 94 }                                                 
 95                                                   
 96                                                   
 97 static int michael_final(struct shash_desc *de    
 98 {                                                 
 99         struct michael_mic_desc_ctx *mctx = sh    
100         u8 *data = (u8 *)&mctx->pending;          
101                                                   
102         /* Last block and padding (0x5a, 4..7     
103         switch (mctx->pending_len) {              
104         case 0:                                   
105                 mctx->l ^= 0x5a;                  
106                 break;                            
107         case 1:                                   
108                 mctx->l ^= data[0] | 0x5a00;      
109                 break;                            
110         case 2:                                   
111                 mctx->l ^= data[0] | (data[1]     
112                 break;                            
113         case 3:                                   
114                 mctx->l ^= data[0] | (data[1]     
115                         0x5a000000;               
116                 break;                            
117         }                                         
118         michael_block(mctx->l, mctx->r);          
119         /* l ^= 0; */                             
120         michael_block(mctx->l, mctx->r);          
121                                                   
122         put_unaligned_le32(mctx->l, out);         
123         put_unaligned_le32(mctx->r, out + 4);     
124                                                   
125         return 0;                                 
126 }                                                 
127                                                   
128                                                   
129 static int michael_setkey(struct crypto_shash     
130                           unsigned int keylen)    
131 {                                                 
132         struct michael_mic_ctx *mctx = crypto_    
133                                                   
134         if (keylen != 8)                          
135                 return -EINVAL;                   
136                                                   
137         mctx->l = get_unaligned_le32(key);        
138         mctx->r = get_unaligned_le32(key + 4);    
139         return 0;                                 
140 }                                                 
141                                                   
142 static struct shash_alg alg = {                   
143         .digestsize             =       8,        
144         .setkey                 =       michae    
145         .init                   =       michae    
146         .update                 =       michae    
147         .final                  =       michae    
148         .descsize               =       sizeof    
149         .base                   =       {         
150                 .cra_name               =         
151                 .cra_driver_name        =         
152                 .cra_blocksize          =         
153                 .cra_ctxsize            =         
154                 .cra_module             =         
155         }                                         
156 };                                                
157                                                   
158 static int __init michael_mic_init(void)          
159 {                                                 
160         return crypto_register_shash(&alg);       
161 }                                                 
162                                                   
163                                                   
164 static void __exit michael_mic_exit(void)         
165 {                                                 
166         crypto_unregister_shash(&alg);            
167 }                                                 
168                                                   
169                                                   
170 subsys_initcall(michael_mic_init);                
171 module_exit(michael_mic_exit);                    
172                                                   
173 MODULE_LICENSE("GPL v2");                         
174 MODULE_DESCRIPTION("Michael MIC");                
175 MODULE_AUTHOR("Jouni Malinen <j@w1.fi>");         
176 MODULE_ALIAS_CRYPTO("michael_mic");               
177                                                   

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php