|
|
|
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include "aes.h" |
|
|
|
|
|
|
|
|
|
namespace i2p |
|
|
|
@ -15,16 +16,33 @@ namespace crypto
@@ -15,16 +16,33 @@ namespace crypto
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool CBCEncryption::Encrypt (const uint8_t * in, std::size_t len, uint8_t * out) |
|
|
|
|
{ |
|
|
|
|
div_t d = div (len, 16); |
|
|
|
|
if (d.rem) return false; // len is not multipple of 16
|
|
|
|
|
Encrypt (d.quot, (const ChipherBlock *)in, (ChipherBlock *)out); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CBCDecryption::Decrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < numBlocks; i++) |
|
|
|
|
{ |
|
|
|
|
ChipherBlock tmp = in[i]; |
|
|
|
|
m_ECBDecryption.ProcessData (out[i].buf, in[i].buf, 16); |
|
|
|
|
out[i].ll[0] ^= m_IV.ll[0]; |
|
|
|
|
out[i].ll[1] ^= m_IV.ll[1]; |
|
|
|
|
m_IV = in[i]; |
|
|
|
|
m_IV = tmp; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool CBCDecryption::Decrypt (const uint8_t * in, std::size_t len, uint8_t * out) |
|
|
|
|
{ |
|
|
|
|
div_t d = div (len, 16); |
|
|
|
|
if (d.rem) return false; // len is not multipple of 16
|
|
|
|
|
Decrypt (d.quot, (const ChipherBlock *)in, (ChipherBlock *)out); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|