2016-07-07 4 views
3

openSSL暗号ライブラリの以下の関数のパラメータを理解しようとしています。私が把握することができたhere与えられた提案を通じて協力することによりOpenSSLの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); 

*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. 

私はecount_bufnumパラメータに関する一定していません。

numは、コールが返された後にlength % AES_BLOCK_SIZEに設定されています。

ecount_bufのパラメータは何ですか?

+1

あなたは 'AES_encrypt'とフレンドを使うべきではありません。これはソフトウェアのみの実装なので、AES-NIなどのハードウェアサポートは受けられません。あなたは 'EVP_ *'関数を使っていなければなりません。 OpenSSL wikiの[EVP Symmetric Encryption and Decryption](http://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption)を参照してください。実際には、機密性と信頼性の両方を提供するため、おそらく認証された暗号化を使用するべきです。 OpenSSL wikiの[EVP Authenticated Encryption and Decryption](http://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption)を参照してください。 – jww

答えて

1

あなたは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; 
} 

あなたはそれが ER ncrypted 電子を保持するための中間バッファであることを推測することができます。 numは、合計ブロックサイズのうち使用されたバイト数の形式で状態情報を保持します(追加データを連鎖させるために後続の呼び出しを行う場合)。