2017-08-31 13 views
0

私の仕事では、Linuxカーネルモジュールのデータを暗号化するためにaes-gcmアルゴリズムを使いたいので、aead APIを選択します。 aes gcmでは、aadデータは0-264ビットに設定できますが、aead_request_set_ad()関数を使用すると、コードでscatterlist構造体のデータがnullになり、エラーになります。 AES-GCM algorithmLinuxカーネル暗号API、AES-GCMアルゴリズムでは、aadの長さをゼロに設定する方法は?

次は、Linuxカーネル4.10で私のコードです:

int aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad, 
       u8 *data, size_t data_len, u8 *mic) 
{ 
    struct scatterlist sg[3]; 
    struct aead_request *aead_req; 
    int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm); 
    int err; 

    if (data_len == 0) 
     return -EINVAL; 

    aead_req = kzalloc(reqsize + GCM_AAD_LEN, GFP_ATOMIC); 
    if (!aead_req) 
     return -ENOMEM; 

    sg_init_table(sg, 3); 
    sg_set_buf(&sg[0], aad,0); 
    sg_set_buf(&sg[1], data, data_len); 
    sg_set_buf(&sg[2], mic, 16); 

    aead_request_set_tfm(aead_req, tfm); 
    aead_request_set_crypt(aead_req, sg, sg, 
       data_len + 16, j_0); 
    aead_request_set_ad(aead_req, sg[0].length); 

    err = crypto_aead_decrypt(aead_req); 
    kzfree(aead_req); 

    return err; 
} 

そして、私はsg_set_page使用している場合(& SGを[0]、ZERO_PAGEは(0)、0、0)SGを設定する[0]それも間違っています。

そして、私はSGを削除する場合は[0]も間違ってさ...

aead_request_set_crypt機能ではちょうどこのような注釈:連想データがある

/** 
* aead_request_set_crypt - set data buffers 
* @req: request handle 
* @src: source scatter/gather list 
* @dst: destination scatter/gather list 
* @cryptlen: number of bytes to process from @src 
* @iv: IV for the cipher operation which must comply with the IV size defined 
*  by crypto_aead_ivsize() 
* 
* Setting the source data and destination data scatter/gather lists which 
* hold the associated data concatenated with the plaintext or ciphertext. See 
* below for the authentication tag. 
* 
* For encryption, the source is treated as the plaintext and the 
* destination is the ciphertext. For a decryption operation, the use is 
* reversed - the source is the ciphertext and the destination is the plaintext. 
* 
* The memory structure for cipher operation has the following structure: 
* 
* - AEAD encryption input: assoc data || plaintext 
* - AEAD encryption output: assoc data || cipherntext || auth tag 
* - AEAD decryption input: assoc data || ciphertext || auth tag 
* - AEAD decryption output: assoc data || plaintext 
* 
* Albeit the kernel requires the presence of the AAD buffer, however, 
* the kernel does not fill the AAD buffer in the output case. If the 
* caller wants to have that data buffer filled, the caller must either 
* use an in-place cipher operation (i.e. same memory location for 
* input/output memory location). 
*/ 

はexistenseでなければなりませんだから、どうやって長さをゼロにすることができますか?

答えて

0

私はこのように、この問題のmyself.justを解決した:

struct scatterlist sg[2]; 
... 
sg_set_buf(&sg[0], data, data_len); 
sg_set_buf(&sg[1], mic, 16); 
... 
aead_request_set_ad(aead_req, 0); 

わずか2つのscatterlist構造体を定義し、広告ゼロを設定します。

関連する問題