2016-07-07 4 views
3

d'OpenSSL J'essaie de comprendre les paramètres de la fonction suivante dans la bibliothèque cryptographique openSSL.Détails des paramètres de AES_ctr128_encrypt()

void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, 
    size_t length, const AES_KEY *key, 
    unsigned char ivec[AES_BLOCK_SIZE], 
    unsigned char ecount_buf[AES_BLOCK_SIZE], 
    unsigned int *num); 

En travaillant à travers les suggestions données here j'ai pu comprendre:

*in - is the buffer in. 
*out - is the buffer out. 
length - is the the length of the *in buffer. 
*key - is the private key. 
ivec[0-7] - is the random IV 
ivec[8-15] - is the counter thats incremented for every block that's encrypted. 

Je ne suis pas certain sur les paramètres ecount_buf et num.

Je vois que num est défini sur length % AES_BLOCK_SIZE après l'appel revient.

Des pointeurs sur le paramètre ecount_buf?

+1

Vous ne devriez pas utiliser 'AES_encrypt' et vos amis. C'est une implémentation logicielle uniquement, de sorte que vous ne bénéficierez pas du support matériel, comme AES-NI. Vous devriez utiliser les fonctions 'EVP_ *'. Voir [EVP Symmetric Encryption and Decryption] (http://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption) sur le wiki OpenSSL. En fait, vous devriez probablement utiliser un chiffrement authentifié, car il fournit * la * confidentialité et l'authenticité. Voir [Chiffrement et décryptage authentifiés par EVP] (http://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption) sur le wiki OpenSSL. – jww

Répondre

1

Si vous regardez le code de mise en œuvre tirée de here:

/* The input encrypted as though 128bit counter mode is being 
* used. The extra state information to record how much of the 
* 128bit block we have used is contained in *num, and the 
* encrypted counter is kept in ecount_buf. Both *num and 
* ecount_buf must be initialised with zeros before the first 
* call to AES_ctr128_encrypt(). 
*/ 
void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, 
    const unsigned long length, const AES_KEY *key, 
    unsigned char counter[AES_BLOCK_SIZE], 
    unsigned char ecount_buf[AES_BLOCK_SIZE], 
    unsigned int *num) { 

    unsigned int n; 
    unsigned long l=length; 

    assert(in && out && key && counter && num); 
    assert(*num < AES_BLOCK_SIZE); 

    n = *num; 

    while (l--) { 
     if (n == 0) { 
      AES_encrypt(counter, ecount_buf, key); 
      AES_ctr128_inc(counter); 
     } 
     *(out++) = *(in++)^ecount_buf[n]; 
     n = (n+1) % AES_BLOCK_SIZE; 
    } 

    *num=n; 
} 

vous pouvez en déduire qu'il est un tampon intermédiaire pour maintenir la e NCrypted nombre er. num contient les informations d'état (dans le cas d'appels ultérieurs que nous pourrions faire pour chaîner des données supplémentaires) sous la forme du nombre d'octets utilisés sur la taille totale du bloc.