Apps Components Interfaces All Files Source Tree | source: tos.lib.TinySec.CBCModeM.nc |
Implements CBC Mode using Cipher Text Stealing (CBC-CTS) as described in
Schneir's Applied Cryptography (195-6) and RFC-2040.
Plain CBC mode is pretty simple; using CTS complicates things. CTS allows
the ciphertext to be the same size as the plaintext, even for plaintexts
which aren't a multiple of the block size.
C_0 == E[IV]
C_i == E[ C_{i-1} ^ P_i ] 0 < i < n-2
C_{n-1} == E[ C_{n-2} ^ P_{n-1} ]
== E[ C_{n-2} ^ (P_{n-1} || 0/-L) ]
== C_{n-1}/+L || C_{n-1}/-L (naming of ciphertext block
into left and right pieces)
C_n == E[ C_{n-1}/+L ^ P_n || C_{n-1}/-L ]
Where 0 = the zero block
n = number of blocks. the last block may be length 1..blockSize bytes
L = |P_n|, the length of the last block and
/+L refers to the first L bytes of a block and
/-L refers to the last (blockSize - L) bytes of a block
We then output C_0 || ... || C_{n-2} || C_n || C_{n-1}/+L so that the
ciphertext is the same size as the input.
Author: | Naveen Sastry |
Required Interfaces |
Provided Interfaces |
Variables |
Function Index |
Function Descriptions |
Parameters: |
plainBlocks - a plaintext block numBlocks, where each block is of blockSize bytes cipherBlocks - an array of numBlocks * blockSize bytes to hold the resulting cyphertext numBlocks - number of data blocks to encrypt IV - an array of the initialization vector. It should be of blockSize bytes |
Returns: | Whether the encryption was successful. Possible failure reasons include not calling init(). |
Parameters: |
cipherBlocks - an array of numBlocks * blockSize bytes that holds the cipher text plainBlocks - an array of numBlocks * blockSize bytes to hold the resulting plaintext. numBlocks - number of data blocks to encrypt IV - an array of the initialization vector. It should be of blockSize bytes |
Returns: | Whether the decryption was successful. Possible failure reasons include not calling init(). |
Parameters: |
context - holds the module specific opaque data related to the key (perhaps key expansions) and other internal state. IV - The initialization vector that was used to encrypt this particular data stream. This array must have a length equal to one block size. The - exact length of the data stream in bytes; this must be at least the underlying block cipher size. |
Returns: | Whether the initialization was successful. Possible failure reasons include not calling init() or an underlying failure in the block cipher. |
Parameters: |
context - holds the module specific opaque data related to the key (perhaps key expansions) and other internal state. ciphertext - Pointer to the start of the next ciphertext buffer. plaintext - Pointer to the start of the buffer which is large enough to hold the entire ciphertext. This buffer must be passed in every time to the incrementalDecrypt function. After this call, done bytes of the plaintext buffer will be available for consumption. length - The number of bytes that is being provided in the ciphertext done - A pointer to an int which will be filled in after the call completes with the number of bytes of plaintext which is available. |
Returns: | Whether the call was successful or not. Possible failure reasons include not calling init(), an underlying failure in the block cipher, or providing more ciphertext than is expected. |