0

Anybody that can tell me why I have problems with this piece of testkode, GWAN crash when it gets called.

gwan API help: void aes_init(aes_t *ctx, u32 mode, u8 *key, u32 keylen);

My test code:

aes_t *testaes = 0;
u32 ed = 0;  
u32 keylen = 128;
u8 *testkey = 0;
testkey = (u8*)strdup("B00DDF9D93E199EFEAE967805E0A5228");
aes_init( testaes, ed, testkey , keylen );

I really would hate to implement another encryption library just because I do not understand the already included.

Gil
  • 3,279
  • 1
  • 15
  • 25
H.J.
  • 25
  • 4

1 Answers1

4

Your aes_t testaes is a pointer to null.

The correct call should be:

aes_t ctx;
u32   mode = 0; // decrypt
u32   keylen = 128;
u8   *testkey = (u8 *)strdup("B00DDF9D93E199EFEAE967805E0A5228");
aes_init(&ctx, mode, testkey, keylen);
Paulo Melo
  • 176
  • 1
  • 1
  • Thanks a lot. I was reading aes_t *cts, as it had to be declared a a pointer and my "= 0" is only no to used un initialised. And clearly I do not understand C pointers fully yet. When I stop learning, I'll hope I die..... – H.J. Jan 20 '13 at 14:51
  • 1
    +1 for Paulo. While we are at it, I would remove the **strdup()** which is completely useless (its only merit is to waste memory and CPU time). Also, the **key** is *not random* (use hw_rand() to generate a key) and 256-bit long (while a 128-bit keylen is defined). Don't forget that crypto can quickly go wrong if misused. – Gil Jan 20 '13 at 16:32
  • Thank again Paulo for your help and Gil for your observations. The 256 key for a 128 keylen was not on my to-do list, other vice the key are random generated and unique and normally I handle any string with G-WAN's own xbuf. This is NOT the thread, but a list of "G-WAN Team's Approved" C standard functions would help newbies as me to keep my code clean, it guess it would make my life hard but that is OK - as long it has least damaging affect on a G-WAN environment. We do not fall short of wrong options, it the lack of creativity with the bare minimum that kill's the valuable progress. – H.J. Jan 21 '13 at 12:58
  • There's nothing wrong with the C standard C library, as long as its functions are used properly. Here strdup() served no purpose. – Gil Jan 23 '13 at 14:02