| 108 | } |
| 109 | |
| 110 | void CTR_ModePolicy::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount) |
| 111 | { |
| 112 | assert(m_cipher->IsForwardTransformation()); // CTR mode needs the "encrypt" direction of the underlying block cipher, even to decrypt |
| 113 | unsigned int s = BlockSize(); |
| 114 | unsigned int inputIncrement = input ? s : 0; |
| 115 | |
| 116 | while (iterationCount) |
| 117 | { |
| 118 | byte lsb = m_counterArray[s-1]; |
| 119 | size_t blocks = UnsignedMin(iterationCount, 256U-lsb); |
| 120 | m_cipher->AdvancedProcessBlocks(m_counterArray, input, output, blocks*s, BlockTransformation::BT_InBlockIsCounter|BlockTransformation::BT_AllowParallel); |
| 121 | if ((m_counterArray[s-1] = lsb + (byte)blocks) == 0) |
| 122 | IncrementCounterBy256(); |
| 123 | |
| 124 | output += blocks*s; |
| 125 | input += blocks*inputIncrement; |
| 126 | iterationCount -= blocks; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | void CTR_ModePolicy::CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length) |
| 131 | { |
nothing calls this directly
no test coverage detected