Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mBuinoBlinky PB_Emma_Ethernet SLOTrashHTTP Garagem ... more
Revision 14:f04410cef037, committed 2014-05-11
- Comitter:
- feb11
- Date:
- Sun May 11 13:36:45 2014 +0000
- Parent:
- 13:ac8e23b98dae
- Commit message:
- CBC mode completed
Changed in this revision
| cipher/BlockCipher.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/cipher/BlockCipher.cpp Sun May 11 11:14:51 2014 +0000
+++ b/cipher/BlockCipher.cpp Sun May 11 13:36:45 2014 +0000
@@ -32,19 +32,41 @@
void BlockCipher::encrypt(uint8_t *out, uint8_t *in, uint32_t length)
{
+ uint8_t *tmp = 0;
+ if(mode == CBC_MODE)
+ tmp = new uint8_t[getBlockSize()];
for(uint32_t i = 0; i < length; i += getBlockSize())
{
- encryptBlock(&out[i], &in[i]);
+ if(mode == CBC_MODE)
+ {
+ memcpy(tmp, &in[i], getBlockSize());
+ for(int j = 0; j < (int)getBlockSize(); ++j)
+ tmp[j] ^= IV[j];
+
+ encryptBlock(&out[i], tmp);
+ memcpy(IV, &out[i], getBlockSize());
+ }
+ else
+ encryptBlock(&out[i], &in[i]);
}
+ if(mode == CBC_MODE)
+ delete[] tmp;
}
void BlockCipher::decrypt(uint8_t *out, uint8_t *in, uint32_t length)
{
for(uint32_t i = 0; i < length; i += getBlockSize())
{
- decryptBlock(&out[i], &in[i]);
+ if(mode == CBC_MODE)
+ {
+ decryptBlock(&out[i], &in[i]);
+ for(int j = 0; j < (int)getBlockSize(); ++j)
+ out[i+j] ^= IV[j];
+ memcpy(IV, &in[i], getBlockSize());
+ }
+ else
+ decryptBlock(&out[i], &in[i]);
}
}
-