| 65 | |
| 66 | template <class S> |
| 67 | void AdditiveCipherTemplate<S>::ProcessData(byte *outString, const byte *inString, size_t length) |
| 68 | { |
| 69 | if (m_leftOver > 0) |
| 70 | { |
| 71 | size_t len = STDMIN(m_leftOver, length); |
| 72 | xorbuf(outString, inString, KeystreamBufferEnd()-m_leftOver, len); |
| 73 | length -= len; |
| 74 | m_leftOver -= len; |
| 75 | inString += len; |
| 76 | outString += len; |
| 77 | |
| 78 | if (!length) |
| 79 | return; |
| 80 | } |
| 81 | CRYPTOPP_ASSERT(m_leftOver == 0); |
| 82 | |
| 83 | PolicyInterface &policy = this->AccessPolicy(); |
| 84 | unsigned int bytesPerIteration = policy.GetBytesPerIteration(); |
| 85 | |
| 86 | if (policy.CanOperateKeystream() && length >= bytesPerIteration) |
| 87 | { |
| 88 | size_t iterations = length / bytesPerIteration; |
| 89 | unsigned int alignment = policy.GetAlignment(); |
| 90 | KeystreamOperation operation = KeystreamOperation((IsAlignedOn(inString, alignment) * 2) | (int)IsAlignedOn(outString, alignment)); |
| 91 | |
| 92 | policy.OperateKeystream(operation, outString, inString, iterations); |
| 93 | |
| 94 | inString += iterations * bytesPerIteration; |
| 95 | outString += iterations * bytesPerIteration; |
| 96 | length -= iterations * bytesPerIteration; |
| 97 | |
| 98 | if (!length) |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | size_t bufferByteSize = m_buffer.size(); |
| 103 | size_t bufferIterations = bufferByteSize / bytesPerIteration; |
| 104 | |
| 105 | while (length >= bufferByteSize) |
| 106 | { |
| 107 | policy.WriteKeystream(m_buffer, bufferIterations); |
| 108 | xorbuf(outString, inString, KeystreamBufferBegin(), bufferByteSize); |
| 109 | length -= bufferByteSize; |
| 110 | inString += bufferByteSize; |
| 111 | outString += bufferByteSize; |
| 112 | } |
| 113 | |
| 114 | if (length > 0) |
| 115 | { |
| 116 | bufferByteSize = RoundUpToMultipleOf(length, bytesPerIteration); |
| 117 | bufferIterations = bufferByteSize / bytesPerIteration; |
| 118 | |
| 119 | policy.WriteKeystream(KeystreamBufferEnd()-bufferByteSize, bufferIterations); |
| 120 | xorbuf(outString, inString, KeystreamBufferEnd()-bufferByteSize, length); |
| 121 | m_leftOver = bufferByteSize - length; |
| 122 | } |
| 123 | } |
| 124 |
nothing calls this directly
no test coverage detected