Permalink
Browse files

Fix some corner cases (that the old loops covered)

  • Loading branch information...
1 parent 0c542d0 commit ec9f17627396e5e906b4235f868fd61fbaf7c157 @spouliot spouliot committed Sep 2, 2012
Showing with 8 additions and 3 deletions.
  1. +8 −3 class/Crimson.CryptoDev/Crimson.CryptoDev/CryptoDevTransform.cs
@@ -330,10 +330,13 @@ private byte[] FinalEncrypt (byte[] inputBuffer, int inputOffset, int inputCount
}
byte[] res = new byte [total];
+ int outputOffset = 0;
// process all blocks except the last (final) block
- int outputOffset = InternalTransformBlock (inputBuffer, inputOffset, total - BlockSizeByte, res, 0);
- inputOffset += outputOffset;
+ if (total > BlockSizeByte) {
+ outputOffset = InternalTransformBlock (inputBuffer, inputOffset, total - BlockSizeByte, res, 0);
+ inputOffset += outputOffset;
+ }
// now we only have a single last block to encrypt
byte pad = (byte) (BlockSizeByte - rem);
@@ -378,8 +381,10 @@ private byte[] FinalDecrypt (byte[] inputBuffer, int inputOffset, int inputCount
total += BlockSizeByte;
byte[] res = new byte [total];
+ int outputOffset = 0;
- int outputOffset = InternalTransformBlock (inputBuffer, inputOffset, inputCount, res, 0);
+ if (inputCount > 0)
+ outputOffset = InternalTransformBlock (inputBuffer, inputOffset, inputCount, res, 0);
if (lastBlock) {
Transform (workBuff, 0, res, outputOffset, BlockSizeByte);

0 comments on commit ec9f176

Please sign in to comment.