0

I'm having this error trying to understand how to implement this constructor.

I stripped the call out of the function I did have it in, and reached a pretty minimal demonstration of my issue:

uint32_t p=0, c;
uint8_t k=0x00;
c = p.AES::AES(AES_128, k);

I expect the plaintext p to be encrypted by AES with key k to ciphertext c.

Instead, I get the error Expression must have class type, due to my inexperience with OOP no doubt.

Unfortunately the library is not well documented at all, so I cannot even learn by example (without the help of SO!) - what have I done wrong here?

OJFord
  • 10,522
  • 8
  • 64
  • 98

2 Answers2

5

You have multiple problems: First that you use p as an object, but it's a variable of a primitive type. Secondly, you try to call the constructor as a static method.

You should do e.g.

AES c(AES::AES_128, k);

That declares c as a variable of type AES, and you can use the member functions in the class like

c.encryptBlock(someArray, someOtherArray);

It seems to me that you need to learn some basic (and I mean really basic) C++. I suggest you check out The Definitive C++ Book Guide and List.

Community
  • 1
  • 1
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Thank you - and you're certainly right on the last point. I have Savitch, but haven't read the chapters on (or used C++ for) OOP yet. – OJFord Jun 30 '14 at 23:38
1

You need to scope the enum

AES crypt = AES(AES_TYPE::AES_128, k);

Also to encrypt/decrypt you need to use the following functions, respectively.

void AES::encryptBlock(uint8_t *out, uint8_t *in);
void AES::decryptBlock(uint8_t *out, uint8_t *in);

So you would call it from your crypt object, for example

crypt.encryptBlock();
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218