void setup() { // Set up serial port for debugging Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } // Fullfil the data array createDataArray(); // Read and set the key from the EEPROM readKey(KEYLENGTH); // Inicialization of the key time = micros(); // time start aes192_init(key, &key_init); emit = micros(); // time start Serial.print(F("Inicialisation total takes: ")); Serial.print(emit - time); Serial.println(F(" [us]")); // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards: pinMode(ledPin, OUTPUT); }
uint8_t WaspAES::init(char* Password, uint16_t keySize){ uint8_t* key; // Key Initialition switch(keySize){ case 128: key = (uint8_t*) calloc(16,sizeof(uint8_t)); if (strlen(Password) < 17) { for (uint16_t i=0; i < strlen(Password);i++){ key[i] = Password[i]; } if (strlen(Password) < 16){ for(int aux = strlen(Password); aux < 16; aux++){ key[aux] = 0; } } } aes128_init(key, &ctx128); break; case 192: key = (uint8_t*) calloc(24,sizeof(uint8_t)); if (strlen(Password) < 25) { for (uint16_t i = 0; i < strlen(Password);i++){ key[i] = Password[i]; } if (strlen(Password) < 24){ for(int aux = strlen(Password); aux < 24; aux++){ key[aux] = 0; } } } aes192_init(key, &ctx192); break; case 256: key = (uint8_t*) calloc(32,sizeof(uint8_t)); if (strlen(Password) < 33) { for (uint16_t i = 0; i < strlen(Password);i++){ key[i] = Password[i]; } if (strlen(Password) < 32){ for(int aux = strlen(Password); aux < 32; aux++){ key[aux] = 0; } } } aes256_init(key, &ctx256); break; default: return 0; } return 1; }
void testrun_testkey_aes192(void){ uint8_t key[24] = { 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b}; aes192_ctx_t ctx; uint8_t i; memset(&ctx, 0, sizeof(aes192_ctx_t)); aes192_init(key, &ctx); cli_putstr("\r\n\r\n keyschedule test (FIPS 197):\r\n key: "); cli_hexdump(key, 24); for(i=0; i<13; ++i){ cli_putstr("\r\n index: "); cli_putc('0'+i/10); cli_putc('0'+i%10); cli_putstr(" roundkey "); cli_hexdump(ctx.key[i].ks, 16); } }
/* * init * * This function sets up the password filling with zeros until it reacehs the * proper length depending on the 'keySize'. The possibilities are 128bits, * 192bits and 256bits. * * After padding with zeros, then an initialization function is called in order * to create all the round keys which are stored in the proper context struct * */ uint8_t WaspAES::init(char* password, uint16_t keySize) { uint8_t key[32]; memset( key, 0x00, sizeof(key) ); // Key Initialition with ZEROS until the proper length switch(keySize) { case 128: // key size to be used: 16 Bytes if (strlen(password) < 17) { for (uint16_t i=0; i < strlen(password);i++) { key[i] = password[i]; } if (strlen(password) < 16) { for(int aux = strlen(password); aux < 16; aux++) { key[aux] = 0; } } } // Once the password is padded with zeros // generate the round keys from the 128 bit key aes128_init(key, &ctx128); break; case 192: // key size to be used: 24 Bytes if (strlen(password) < 25) { for (uint16_t i = 0; i < strlen(password);i++) { key[i] = password[i]; } if (strlen(password) < 24) { for(int aux = strlen(password); aux < 24; aux++) { key[aux] = 0; } } } // Once the password is padded with zeros // generate the round keys from the 192 bit key aes192_init(key, &ctx192); break; case 256: // key size to be used: 32 Bytes if (strlen(password) < 33) { for (uint16_t i = 0; i < strlen(password);i++) { key[i] = password[i]; } if (strlen(password) < 32) { for(int aux = strlen(password); aux < 32; aux++) { key[aux] = 0; } } } // Once the password is padded with zeros // generate the round keys from the 256 bit key aes256_init(key, &ctx256); break; default: return 0; } return 1; }