API Reference | developer.brewmp.com API Reference | developer.brewmp.com

Developer

API Reference

ICIPHER1_PROCESS()

Brew Release
Brew MP 1.0.2
See Also
Error Codes ICipher1 ICipher1_ProcessLast()
Description
Encrypt or decrypt data.
Params
pICipher
[]:
Pointer to ICipher1 interface object.
pchIn
[]:
[in] Pointer to data to be encrypted/decrypted.
cbIn
[]:
[in] Input data size in bytes.
pbOut
[]:
[out] Buffer to receive encrypted/decrypted data.
pcbOut
[]:
[in/out] size of output buffer in bytes, returns number of bytes actually written.
Interface
Prototype
  •    int ICipher1_Process(ICipher1* pICipher, 
                   const byte *pchIn, unsigned cbIn,
                   byte *pbOut, unsigned* pcbOut);
    
Return
  • AEE_SUCCESS: all input bytes processed. AEE_EBADSTATE: cipher is not properly initialized/no key. AEE_EBADPARM: pointer parameter is NULL. AEE_EBUFFERTOOSMALL: output buffer not large enough.
Side Effect
  • None
Comments
The output buffer must always be the same size or larger than the input buffer. If it is not an error occurs and no processing is done at all. This requirement simplifies the buffering and error handling for the user of a cipher. The code calling the cipher can assume that all the input is always processed. The caller can also assume that if there is an error that it is catestrophic for the encryption/ decryption and abort the whole operation. The size of the input buffer does not have to be a multiple of the block size of the underlying algorithm. This frees the caller entirely of having to worry about algorithm block sizes and aligning buffers by them. For some ICipher1 implementations making the input buffer size a multiple of the block size, if it is convenient and efficient to do, may increase performance because some internal buffer copying is not invoked. Making the buffers processed large will give some throughput gain because the per-call overhead is proportionally less. Some padding modes may buffer up to 2 blocks of input before it appears in the output. The input and output buffers may point to the same buffer area. ICipher1_ProcessLast() should always be called after all the input data has been fed into ICipher1_Process() to flush out any buffered blocks. For many ICipher1 implementations, such as stream ciphers, it will not do anything because these ciphers do no buffering, however it should still always be called. The advantage of always calling it is that it allows the calling code to function correctly no matter whether the cipher used is a stream cipher or block cipher.