Version v0.3.37 - Implement ChaCha20 nonce extension to support pads larger than 256GB
This commit is contained in:
@@ -63,10 +63,10 @@ int chacha20_block(const uint8_t key[32], uint32_t counter,
|
||||
|
||||
/**
|
||||
* ChaCha20 encryption/decryption
|
||||
*
|
||||
*
|
||||
* Encrypts or decrypts data using ChaCha20 stream cipher.
|
||||
* Since ChaCha20 is a stream cipher, encryption and decryption are the same operation.
|
||||
*
|
||||
*
|
||||
* @param key[in] 32-byte key
|
||||
* @param counter[in] Initial 32-bit counter value
|
||||
* @param nonce[in] 12-byte nonce
|
||||
@@ -75,10 +75,29 @@ int chacha20_block(const uint8_t key[32], uint32_t counter,
|
||||
* @param length[in] Length of input data in bytes
|
||||
* @return 0 on success, negative on error
|
||||
*/
|
||||
int chacha20_encrypt(const uint8_t key[32], uint32_t counter,
|
||||
const uint8_t nonce[12], const uint8_t* input,
|
||||
int chacha20_encrypt(const uint8_t key[32], uint32_t counter,
|
||||
const uint8_t nonce[12], const uint8_t* input,
|
||||
uint8_t* output, size_t length);
|
||||
|
||||
/**
|
||||
* ChaCha20 encryption/decryption with extended counter (64-bit)
|
||||
*
|
||||
* Extended version that supports files larger than 256GB by using
|
||||
* part of the nonce as a high-order counter extension.
|
||||
*
|
||||
* @param key[in] 32-byte key
|
||||
* @param counter_low[in] Initial 32-bit counter value (low bits)
|
||||
* @param counter_high[in] Initial 32-bit counter value (high bits)
|
||||
* @param nonce[in] 8-byte reduced nonce (instead of 12)
|
||||
* @param input[in] Input data to encrypt/decrypt
|
||||
* @param output[out] Output buffer (can be same as input)
|
||||
* @param length[in] Length of input data in bytes
|
||||
* @return 0 on success, negative on error
|
||||
*/
|
||||
int chacha20_encrypt_extended(const uint8_t key[32], uint32_t counter_low,
|
||||
uint32_t counter_high, const uint8_t nonce[8],
|
||||
const uint8_t* input, uint8_t* output, size_t length);
|
||||
|
||||
/*
|
||||
* ============================================================================
|
||||
* UTILITY FUNCTIONS
|
||||
|
||||
Reference in New Issue
Block a user