Skip to content

Commit

Permalink
add vector parameters support
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyBel committed Nov 14, 2021
1 parent 1fb1d9d commit 1412f57
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 19 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ c = aes.EncryptECB(plain, plainLen, key, outLen);
//now variable c contains outLen bytes - ciphertext
...
```
Or for vectors:
```c++
...
vector<unsigned char> plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; //plaintext example
vector<unsigned char> key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; //key example
AES aes(128);
c = aes.EncryptECB(plain, key);
//now vector c contains ciphertext
...
```
ECB, CBC, CFB modes are supported.


Expand Down
67 changes: 67 additions & 0 deletions src/AES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ AES::AES(int keyLen)
blockBytesLen = 4 * this->Nb * sizeof(unsigned char);
}


unsigned char * AES::EncryptECB(unsigned char in[], unsigned int inLen, unsigned char key[], unsigned int &outLen)
{
outLen = GetPaddingLength(inLen);
Expand Down Expand Up @@ -524,9 +525,75 @@ void AES::printHexArray (unsigned char a[], unsigned int n)
}
}

void AES::printHexVector (vector<unsigned char> a)
{
for (unsigned int i = 0; i < a.size(); i++) {
printf("%02x ", a[i]);
}
}

vector<unsigned char> AES::ArrayToVector(unsigned char *a, unsigned char len)
{
vector<unsigned char> v(a, a + len * sizeof(unsigned char));
return v;
}

unsigned char *AES::VectorToArray(vector<unsigned char> a)
{
return a.data();
}


vector<unsigned char> AES::EncryptECB(vector<unsigned char> in, vector<unsigned char> key)
{
unsigned int outLen = 0;;
unsigned char *out = EncryptECB(VectorToArray(in), (unsigned int)in.size(), VectorToArray(key), outLen);
vector<unsigned char> v = ArrayToVector(out, outLen);
delete []out;
return v;
}

vector<unsigned char> AES::DecryptECB(vector<unsigned char> in, vector<unsigned char> key)
{
unsigned char *out = DecryptECB(VectorToArray(in), (unsigned int)in.size(), VectorToArray(key));
vector<unsigned char> v = ArrayToVector(out, (unsigned int)in.size());
delete []out;
return v;
}


vector<unsigned char> AES::EncryptCBC(vector<unsigned char> in, vector<unsigned char> key, vector<unsigned char> iv)
{
unsigned int outLen = 0;
unsigned char *out = EncryptCBC(VectorToArray(in), (unsigned int)in.size(), VectorToArray(key), VectorToArray(iv), outLen);
vector<unsigned char> v = ArrayToVector(out, outLen);
delete [] out;
return v;
}

vector<unsigned char> AES::DecryptCBC(vector<unsigned char> in, vector<unsigned char> key, vector<unsigned char> iv)
{
unsigned char *out = DecryptCBC(VectorToArray(in), (unsigned int)in.size(), VectorToArray(key), VectorToArray(iv));
vector<unsigned char> v = ArrayToVector(out, (unsigned int)in.size());
delete [] out;
return v;
}

vector<unsigned char> AES::EncryptCFB(vector<unsigned char> in, vector<unsigned char> key, vector<unsigned char> iv)
{
unsigned int outLen = 0;
unsigned char *out = EncryptCFB(VectorToArray(in), (unsigned int)in.size(), VectorToArray(key), VectorToArray(iv), outLen);
vector<unsigned char> v = ArrayToVector(out, outLen);
delete [] out;
return v;
}

vector<unsigned char> AES::DecryptCFB(vector<unsigned char> in, vector<unsigned char> key, vector<unsigned char> iv)
{
unsigned char *out = DecryptCFB(VectorToArray(in), (unsigned int)in.size(), VectorToArray(key), VectorToArray(iv));
vector<unsigned char> v = ArrayToVector(out, (unsigned int)in.size());
delete [] out;
return v;

}

38 changes: 29 additions & 9 deletions src/AES.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef _AES_H_
#define _AES_H_

#include<cstring>
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

Expand Down Expand Up @@ -58,24 +59,43 @@ class AES

void XorBlocks(unsigned char *a, unsigned char * b, unsigned char *c, unsigned int len);

vector<unsigned char> ArrayToVector(unsigned char *a, unsigned char len);

unsigned char *VectorToArray(vector<unsigned char> a);

public:
AES(int keyLen = 256);

unsigned char *EncryptECB(unsigned char in[], unsigned int inLen, unsigned char key[], unsigned int &outLen);
unsigned char *EncryptECB(unsigned char in[], unsigned int inLen, unsigned char key[], unsigned int &outLen);

unsigned char *DecryptECB(unsigned char in[], unsigned int inLen, unsigned char key[]);
unsigned char *DecryptECB(unsigned char in[], unsigned int inLen, unsigned char key[]);

unsigned char *EncryptCBC(unsigned char in[], unsigned int inLen, unsigned char key[], unsigned char * iv, unsigned int &outLen);
unsigned char *EncryptCBC(unsigned char in[], unsigned int inLen, unsigned char key[], unsigned char *iv, unsigned int &outLen);

unsigned char *DecryptCBC(unsigned char in[], unsigned int inLen, unsigned char key[], unsigned char * iv);
unsigned char *DecryptCBC(unsigned char in[], unsigned int inLen, unsigned char key[], unsigned char *iv);

unsigned char *EncryptCFB(unsigned char in[], unsigned int inLen, unsigned char key[], unsigned char * iv, unsigned int &outLen);
unsigned char *EncryptCFB(unsigned char in[], unsigned int inLen, unsigned char key[], unsigned char *iv, unsigned int &outLen);

unsigned char *DecryptCFB(unsigned char in[], unsigned int inLen, unsigned char key[], unsigned char *iv);



vector<unsigned char> EncryptECB(vector<unsigned char> in, vector<unsigned char> key);

vector<unsigned char> DecryptECB(vector<unsigned char> in, vector<unsigned char> key);

vector<unsigned char> EncryptCBC(vector<unsigned char> in, vector<unsigned char> key, vector<unsigned char> iv);

vector<unsigned char> DecryptCBC(vector<unsigned char> in, vector<unsigned char> key, vector<unsigned char> iv);

vector<unsigned char> EncryptCFB(vector<unsigned char> in, vector<unsigned char> key, vector<unsigned char> iv);

vector<unsigned char> DecryptCFB(vector<unsigned char> in, vector<unsigned char> key, vector<unsigned char> iv);

unsigned char *DecryptCFB(unsigned char in[], unsigned int inLen, unsigned char key[], unsigned char * iv);

void printHexArray (unsigned char a[], unsigned int n);

void printHexArray(unsigned char a[], unsigned int n);

void printHexVector(vector<unsigned char> a);
};

const unsigned char sbox[16][16] = {
Expand Down
158 changes: 148 additions & 10 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "gtest/gtest.h"
#include <iostream>
#include <vector>
#include "../src/AES.h"

const unsigned int BLOCK_BYTES_LENGTH = 16 * sizeof(unsigned char);
Expand Down Expand Up @@ -66,6 +67,47 @@ TEST(ECB, EncryptDecrypt)
delete[] innew;
}

TEST(ECB, EncryptDecryptVector)
{
AES aes(256);
vector<unsigned char> plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };

vector<unsigned char> key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f };

vector<unsigned char> out = aes.EncryptECB(plain, key);
vector<unsigned char> innew = aes.DecryptECB(out, key);
ASSERT_EQ(innew, plain);
}

TEST(ECB, OneBlockEncrypt)
{
AES aes(128);
unsigned char plain[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
unsigned char key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
unsigned char right[] = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a};
unsigned int len = 0;
unsigned char *out = aes.EncryptECB(plain, BLOCK_BYTES_LENGTH, key, len);

ASSERT_FALSE(memcmp(right, out, len));

delete[] out;
}

TEST(ECB, OneBlockEncryptVector)
{
AES aes(128);
vector<unsigned char> plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
vector<unsigned char> key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
vector<unsigned char> right = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a};
vector<unsigned char> out = aes.EncryptECB(plain, key);


ASSERT_EQ(BLOCK_BYTES_LENGTH, out.size());
ASSERT_EQ(right, out);

}

TEST(ECB, OneBlockWithoutByteEncrypt)
{
AES aes(128);
Expand Down Expand Up @@ -122,29 +164,39 @@ TEST(ECB, TwoBlocksEncrypt)
TEST(ECB, OneBlockDecrypt)
{
AES aes(128);
unsigned char encrypted[] = { 0x7c, 0x99, 0xf4, 0x2b, 0x6e, 0xe5, 0x03, 0x30, 0x9c, 0x6c, 0x1a, 0x67, 0xe9, 0x7a, 0xc2, 0x42 };
unsigned char encrypted[] = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a };
unsigned char key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
unsigned char right[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
unsigned int len = 0;
unsigned char *out = aes.DecryptECB(encrypted, BLOCK_BYTES_LENGTH, key);

ASSERT_FALSE(memcmp(right, out, len));
ASSERT_FALSE(memcmp(right, out, BLOCK_BYTES_LENGTH));

delete[] out;
}

TEST(ECB, OneBlockDecryptVector)
{
AES aes(128);
vector<unsigned char> encrypted = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a };
vector<unsigned char> key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
vector<unsigned char> right = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
vector<unsigned char> out = aes.DecryptECB(encrypted, key);

ASSERT_EQ(right, out);
}

TEST(ECB, TwoBlocksDecrypt)
{
AES aes(128);
unsigned char encrypted[] = { 0x7c, 0x99, 0xf4, 0x2b, 0x6e, 0xe5, 0x03, 0x30, 0x9c, 0x6c, 0x1a, 0x67, 0xe9, 0x7a, 0xc2, 0x42,
0x7c, 0x99, 0xf4, 0x2b, 0x6e, 0xe5, 0x03, 0x30, 0x9c, 0x6c, 0x1a, 0x67, 0xe9, 0x7a, 0xc2, 0x42};
unsigned char encrypted[] = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a,
0x07, 0xfe, 0xef, 0x74, 0xe1, 0xd5, 0x03, 0x6e, 0x90, 0x0e, 0xee, 0x11, 0x8e, 0x94, 0x92, 0x93,
};
unsigned char key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
unsigned char right[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0x00};
unsigned int len = 0;
unsigned char *out = aes.DecryptECB(encrypted, BLOCK_BYTES_LENGTH, key);
unsigned char right[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f};
unsigned char *out = aes.DecryptECB(encrypted, 2 * BLOCK_BYTES_LENGTH, key);

ASSERT_FALSE(memcmp(right, out, len));
ASSERT_FALSE(memcmp(right, out, 2 * BLOCK_BYTES_LENGTH));

delete[] out;
}
Expand All @@ -169,6 +221,19 @@ TEST(CBC, EncryptDecrypt)
delete[] innew;
}

TEST(CBC, EncryptDecryptVector)
{
AES aes(256);
vector<unsigned char> plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
vector<unsigned char> iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
vector<unsigned char> key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f };

vector<unsigned char> out = aes.EncryptCBC(plain, key, iv);
vector<unsigned char> innew = aes.DecryptCBC(out, key, iv);
ASSERT_EQ(innew, plain);
}

TEST(CBC, TwoBlocksEncrypt)
{
AES aes(128);
Expand All @@ -186,6 +251,21 @@ TEST(CBC, TwoBlocksEncrypt)
delete[] out;
}

TEST(CBC, TwoBlocksEncryptVector)
{
AES aes(128);
vector<unsigned char> plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
vector<unsigned char> iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
vector<unsigned char> key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
vector<unsigned char> right = {0x1b, 0x87, 0x23, 0x78, 0x79, 0x5f, 0x4f, 0xfd, 0x77, 0x28, 0x55, 0xfc, 0x87, 0xca, 0x96, 0x4d,
0x4c, 0x5b, 0xca, 0x1c, 0x48, 0xcd, 0x88, 0x00, 0x3a, 0x10, 0x52, 0x11, 0x88, 0x12, 0x5e, 0x00};

vector<unsigned char> out = aes.EncryptCBC(plain, key, iv);

ASSERT_EQ(out, right);
}

TEST(CBC, TwoBlocksDecrypt)
{
AES aes(128);
Expand All @@ -204,6 +284,23 @@ TEST(CBC, TwoBlocksDecrypt)
delete[] out;
}

TEST(CBC, TwoBlocksDecryptVector)
{
AES aes(128);
vector<unsigned char>encrypted = {0x1b, 0x87, 0x23, 0x78, 0x79, 0x5f, 0x4f, 0xfd, 0x77, 0x28, 0x55, 0xfc, 0x87, 0xca, 0x96, 0x4d,
0x4c, 0x5b, 0xca, 0x1c, 0x48, 0xcd, 0x88, 0x00, 0x3a, 0x10, 0x52, 0x11, 0x88, 0x12, 0x5e, 0x00};

vector<unsigned char> iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
vector<unsigned char> key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
vector<unsigned char> right = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };


vector<unsigned char> out = aes.DecryptCBC(encrypted, key, iv);

ASSERT_EQ(out, right);
}



TEST(CFB, EncryptDecrypt)
Expand All @@ -222,6 +319,19 @@ TEST(CFB, EncryptDecrypt)
delete[] innew;
}

TEST(CFB, EncryptDecryptVector)
{
AES aes(256);
vector<unsigned char> plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
vector<unsigned char> iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
vector<unsigned char> key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f };

vector<unsigned char> out = aes.EncryptCFB(plain, key, iv);
vector<unsigned char> innew = aes.DecryptCFB(out, key, iv);
ASSERT_EQ(innew, plain);
}

TEST(CFB, EncryptTwoBlocks)
{
AES aes(128);
Expand All @@ -239,8 +349,36 @@ TEST(CFB, EncryptTwoBlocks)
delete[] out;
}

TEST(CFB, EncryptTwoBlocksVector)
{
AES aes(128);
vector<unsigned char> plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
vector<unsigned char> iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
vector<unsigned char> key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
vector<unsigned char> right = {0x3c, 0x55, 0x3d, 0x01, 0x8a, 0x52, 0xe4, 0x54, 0xec, 0x4e, 0x08, 0x22, 0xc2, 0x8d, 0x55, 0xec,
0xe3, 0x5a, 0x40, 0xab, 0x30, 0x29, 0xf3, 0x0c, 0xe1, 0xdb, 0x30, 0x6c, 0xa1, 0x05, 0xcb, 0xa9};

vector<unsigned char> out = aes.EncryptCFB(plain, key, iv);
ASSERT_EQ(right, out);
}


TEST(CFB, DecryptTwoBlocks)
{
AES aes(128);
vector<unsigned char> encrypted = {0x3c, 0x55, 0x3d, 0x01, 0x8a, 0x52, 0xe4, 0x54, 0xec, 0x4e, 0x08, 0x22, 0xc2, 0x8d, 0x55, 0xec,
0xe3, 0x5a, 0x40, 0xab, 0x30, 0x29, 0xf3, 0x0c, 0xe1, 0xdb, 0x30, 0x6c, 0xa1, 0x05, 0xcb, 0xa9};
vector<unsigned char> iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
vector<unsigned char> key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
vector<unsigned char> right = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };

vector<unsigned char> out = aes.DecryptCFB(encrypted, key, iv);
ASSERT_EQ(right, out);
}

TEST(CFB, DecryptTwoBlocksVector)
{
AES aes(128);
unsigned char encrypted[] = {0x3c, 0x55, 0x3d, 0x01, 0x8a, 0x52, 0xe4, 0x54, 0xec, 0x4e, 0x08, 0x22, 0xc2, 0x8d, 0x55, 0xec,
Expand Down

0 comments on commit 1412f57

Please sign in to comment.