/Documentation/sparc/

1/ieee80211_crypt_tkip.c?h=master' type='application/atom+xml'/>
aboutsummaryrefslogblamecommitdiffstats
path: root/net/ieee80211/ieee80211_crypt_tkip.c
blob: 5a48d8e0aec1a98a73761cfe9626d32c4fd47383 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11


                                                                              
                                                   






                                                                        
                      





                            
                     





                           






























                                               



                                             


                                                             
 
                            

  














                                                                              


                                         
                                                  

                          
 

                                
                                                                  
                                                                  
                                        

                                                                             
                                         


                          


                                                                   

                                                                             
                                            


                          


                                                                  

                                                                             
                                         


                          


                                                                   

                                                                             
                                            




                          
           
                   
                                         
                                                               
                                      
                                                                 
                                         
                                                               
                                      
                                                                 





                            


                                                 

                                          
                                                                
                                       
                                                                  
                                          
                                                                
                                       
                                                                  
         


                    




                                        




                             




                             




                               




                               




                                      
                                  



                               
                              

































                                                                       





                                                    

                           

                                                                        



















                                                                         
                                                                             



                                                                             
                                        









                                                          








                                                            









                                                                        
                                                                   









                                                               

                                                                  


                                                
                
                                        
 
                                                      
 
                                                        



                                          
 










                                                                            
 


                               
                                                                        




                                              




                                         
 
                 




                                                                               
                                                                  
                

                                  

                              
                                                                  


                                                                    
                                                                            
                                                            
                                                    









                                                        
                                                                     

                          







                                      
                                                               


                                        
                                                                  

 












                                                           


                                                                               
                                                                  



                        
                                        




                              
                                                      
 
                                                                  
                                      
                                                                            
                                                                    
                                                    



                          


                                       


























                                                                                
                                                                          
                                      
                                                                                  















                                                                               
                                                               


                                        







                                                                      












                                                                               
                                                                             


















                                                                       
                                                                           
                                                            
 
                              

                                 
                                  










                                                                          
                                                    
                          
 
                               

                                                                 

 
                                                          
 
                                          
                  
 
                                                        

                                                                  


                                                                

                                                                        

                                   

                                                                        

                                                         

                                                                        

                      

                                                                        


                      


                                                                   
                                                                            


                                                      
                                                              

 

                                                                      












                                                                       
                                                                           





                                                                          
                                                                 

                                                                          














                                                                  
                                                                            
 

                                                                        
                                                                







                                                
                                                                           


                                                                          

                                                              



















                                                                              
                                                                           


                                                



                                                          



                                       



                                    


                                                     
                                                                     

                                                                         
                                                   









                                                               
                                                                           



























                                                                               
                                                            
























                                                                        
                                                           


                                        
                                       






                                                     


                                                        

                                              
                             

  




                                                                    




                                                               

                                        
/*
 * Host AP crypt: host-based TKIP encryption implementation for Host AP driver
 *
 * Copyright (c) 2003-2004, Jouni Malinen <j@w1.fi>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation. See README and COPYING for
 * more details.
 */

#include <linux/err.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/random.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/mm.h>
#include <linux/if_ether.h>
#include <linux/if_arp.h>
#include <asm/string.h>

#include <net/ieee80211.h>

#include <linux/crypto.h>
#include <asm/scatterlist.h>
#include <linux/crc32.h>

MODULE_AUTHOR("Jouni Malinen");
MODULE_DESCRIPTION("Host AP crypt: TKIP");
MODULE_LICENSE("GPL");

struct ieee80211_tkip_data {
#define TKIP_KEY_LEN 32
	u8 key[TKIP_KEY_LEN];
	int key_set;

	u32 tx_iv32;
	u16 tx_iv16;
	u16 tx_ttak[5];
	int tx_phase1_done;

	u32 rx_iv32;
	u16 rx_iv16;
	u16 rx_ttak[5];
	int rx_phase1_done;
	u32 rx_iv32_new;
	u16 rx_iv16_new;

	u32 dot11RSNAStatsTKIPReplays;
	u32 dot11RSNAStatsTKIPICVErrors;
	u32 dot11RSNAStatsTKIPLocalMICFailures;

	int key_idx;

	struct crypto_blkcipher *rx_tfm_arc4;
	struct crypto_hash *rx_tfm_michael;
	struct crypto_blkcipher *tx_tfm_arc4;
	struct crypto_hash *tx_tfm_michael;

	/* scratch buffers for virt_to_page() (crypto API) */
	u8 rx_hdr[16], tx_hdr[16];

	unsigned long flags;
};

static unsigned long ieee80211_tkip_set_flags(unsigned long flags, void *priv)
{
	struct ieee80211_tkip_data *_priv = priv;
	unsigned long old_flags = _priv->flags;
	_priv->flags = flags;
	return old_flags;
}

static unsigned long ieee80211_tkip_get_flags(void *priv)
{
	struct ieee80211_tkip_data *_priv = priv;
	return _priv->flags;
}

static void *ieee80211_tkip_init(int key_idx)
{
	struct ieee80211_tkip_data *priv;

	priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
	if (priv == NULL)
		goto fail;

	priv->key_idx = key_idx;

	priv->tx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0,
						CRYPTO_ALG_ASYNC);
	if (IS_ERR(priv->tx_tfm_arc4)) {
		printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
		       "crypto API arc4\n");
		priv->tx_tfm_arc4 = NULL;
		goto fail;
	}

	priv->tx_tfm_michael = crypto_alloc_hash("michael_mic", 0,
						 CRYPTO_ALG_ASYNC);
	if (IS_ERR(priv->tx_tfm_michael)) {
		printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
		       "crypto API michael_mic\n");
		priv->tx_tfm_michael = NULL;
		goto fail;
	}

	priv->rx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0,
						CRYPTO_ALG_ASYNC);
	if (IS_ERR(priv->rx_tfm_arc4)) {
		printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
		       "crypto API arc4\n");
		priv->rx_tfm_arc4 = NULL;
		goto fail;
	}

	priv->rx_tfm_michael = crypto_alloc_hash("michael_mic", 0,
						 CRYPTO_ALG_ASYNC);
	if (IS_ERR(priv->rx_tfm_michael)) {
		printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
		       "crypto API michael_mic\n");
		priv->rx_tfm_michael = NULL;
		goto fail;
	}

	return priv;

      fail:
	if (priv) {
		if (priv->tx_tfm_michael)
			crypto_free_hash(priv->tx_tfm_michael);
		if (priv->tx_tfm_arc4)
			crypto_free_blkcipher(priv->tx_tfm_arc4);
		if (priv->rx_tfm_michael)
			crypto_free_hash(priv->rx_tfm_michael);
		if (priv->rx_tfm_arc4)
			crypto_free_blkcipher(priv->rx_tfm_arc4);
		kfree(priv);
	}

	return NULL;
}

static void ieee80211_tkip_deinit(void *priv)
{
	struct ieee80211_tkip_data *_priv = priv;
	if (_priv) {
		if (_priv->tx_tfm_michael)
			crypto_free_hash(_priv->tx_tfm_michael);
		if (_priv->tx_tfm_arc4)
			crypto_free_blkcipher(_priv->tx_tfm_arc4);
		if (_priv->rx_tfm_michael)
			crypto_free_hash(_priv->rx_tfm_michael);
		if (_priv->rx_tfm_arc4)
			crypto_free_blkcipher(_priv->rx_tfm_arc4);
	}
	kfree(priv);
}

static inline u16 RotR1(u16 val)
{
	return (val >> 1) | (val << 15);
}

static inline u8 Lo8(u16 val)
{
	return val & 0xff;
}

static inline u8 Hi8(u16 val)
{
	return val >> 8;
}

static inline u16 Lo16(u32 val)
{
	return val & 0xffff;
}

static inline u16 Hi16(u32 val)
{
	return val >> 16;
}

static inline u16 Mk16(u8 hi, u8 lo)
{
	return lo | (((u16) hi) << 8);
}

static inline u16 Mk16_le(u16 * v)
{
	return le16_to_cpu(*v);
}

static const u16 Sbox[256] = {