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: ES_CW2_Starter_JIN EMBEDDED_CW2 EMBEDDED_CW2_Final Spinnybois ... more
Fork of Crypto by
cipher/BlockCipher.cpp
- Committer:
- feb11
- Date:
- 2013-09-14
- Revision:
- 8:a090264e9b2d
- Child:
- 14:f04410cef037
File content as of revision 8:a090264e9b2d:
#include "BlockCipher.h"
#include <string.h>
BlockCipher::BlockCipher(uint32_t bs, BLOCK_CIPHER_MODE m, uint8_t *iv):
Cipher(),
blockSize(bs),
mode(m),
IV(0)
{
if(mode == CBC_MODE)
{
IV = new uint8_t[blockSize];
memcpy(IV, iv, blockSize);
}
}
BlockCipher::~BlockCipher()
{
if(IV != 0)
delete[] IV;
}
CIPHER_TYPE BlockCipher::getType() const
{
return BLOCK_CIPHER;
}
uint32_t BlockCipher::getBlockSize() const
{
return blockSize;
}
void BlockCipher::encrypt(uint8_t *out, uint8_t *in, uint32_t length)
{
for(uint32_t i = 0; i < length; i += getBlockSize())
{
encryptBlock(&out[i], &in[i]);
}
}
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]);
}
}
