Extra Systems

CYPHERNET

Algoritmo di crittografia del flusso RC4


L'algoritmo di crittografia del flusso RC4 (creato da Ron Rivest nel 1987) è un classico nel suo campo, ma recentemente è stato criticato a causa della sua vulnerabilità in WEP e TLS. Da un'analisi attenta emerge però che in questi casi non era l'RC4 in sé ad essere vulnerabile, ma la sua combinazione infruttuosa con i protocolli specificati. Chi lo desidera può approfondire da solo i dettagli, ma qui notiamo solo che le vulnerabilità RC4 descritte nella letteratura crittografica insieme a WEP e TLS non hanno nulla a che fare con il nostro sistema, poiché le scappatoie attraverso le quali è stato effettuato l'hacking lì sono completamente assenti nei sistemi Extra mancano Cypher Net.

L'implementazione dell'algoritmo di crittografia del flusso RC4 nel nostro sistema viene eseguita come segue:

typedef struct rc4_key
{      
     unsigned char state[256];       
     unsigned char x;        
     unsigned char y;
} rc4_key;

void swap_byte(unsigned char *a, unsigned char *b)
{
     unsigned char swapByte; 
     swapByte = *a; 
     *a = *b;      
     *b = swapByte;
 }

void prepare_rc4_key(unsigned char *key_data_ptr, int key_data_len, rc4_key *key)
{
     unsigned char swapByte;
     unsigned char index1, index2;
     unsigned char* state;
     short counter;     
     state = &key->state[0];         
     for(counter = 0; counter < 256; counter++) state[counter] = counter;               
     key->x = 0; key->y = 0;     
     index1 = 0; index2 = 0;             
     for(counter = 0; counter < 256; counter++)      
     {               
          index2 = (key_data_ptr[index1] + state[counter] + index2) % 256;                
          swap_byte(&state[counter], &state[index2]);            
          index1 = (index1 + 1) % key_data_len;  
     }       
 }
 
void rc4_crypt_buffer(unsigned char *buffer_ptr, int buffer_len, rc4_key *key)
{ 
     unsigned char x, y;
     unsigned char* state;
     unsigned char xorIndex;
     short counter;              
     x = key->x; y = key->y;     
     state = &key->state[0];         
     for(counter = 0; counter < buffer_len; counter++)      
     {               
          x = (x + 1) % 256;                      
          y = (state[x] + y) % 256;               
          swap_byte(&state[x], &state[y]);                        
          xorIndex = (state[x] + state[y]) % 256;                 
          buffer_ptr[counter] ^= state[xorIndex];         
      }               
      key->x = x;     
      key->y = y;
}

rc4_key rc4_key_table;

void print_crypt_params(void)
{
	printf("Ключ шифрования RSA: %d бит\n", RSA_KEY_BITS);
	printf("Ключ шифрования RC4: %d бит\n\n", PACKED_SESSION_KEY_LENTH * 8);
}

void make_crypt_key_table(void) { prepare_rc4_key(common_key.packed, PACKED_SESSION_KEY_LENTH, &rc4_key_table); }
void encrypt_buffer(unsigned char *buffer_ptr, int buffer_len) { rc4_crypt_buffer(buffer_ptr, buffer_len, &rc4_key_table); }
void decrypt_buffer(unsigned char *buffer_ptr, int buffer_len) { rc4_crypt_buffer(buffer_ptr, buffer_len, &rc4_key_table); }

Il contenuto di questa pagina è disponibile anche in inglese, francese, tedesco, portoghese, spagnolo, ucraino e russo.


© Extra Systems, 2024 Extra Web Top