Пример #1
0
void AES_CMAC_sign(unsigned int message_bytes, const unsigned char *message, unsigned char *signature, unsigned int key_bytes, const unsigned char *key, const unsigned char *iv) {
  unsigned char i;

  AES_CBC_encrypt(AES_BLOCK_BYTES, message, signature, key_bytes, key, iv);
  for (i = 1; i < message_bytes / AES_BLOCK_BYTES; i++) {
    AES_CBC_encrypt(AES_BLOCK_BYTES, message + i*AES_BLOCK_BYTES, signature, key_bytes, key, signature);
  }
}
Пример #2
0
int main( void )
{
  	/* Assume that everything is ok*/
  	success = true;

	/* Before using the AES it is recommended to do an AES software reset to put
	 * the module in known state, in case other parts of your code has accessed
	 * the AES module. */
	AES_software_reset();

	/* Generate last subkey. */
	AES_lastsubkey_generate(key, lastsubkey);

	/* Do AES Cipher Block Chaining encryption and decryption on three blocks. */
	
	success = AES_CBC_encrypt(); /* MODIFY THE FUNCTION CALL */
	success = AES_CBC_decrypt(); /* MODIFY THE FUNCTION CALL */


	/* Check if decrypted answer is equal to plaintext. */
	for(uint8_t i = 0; i < BLOCK_LENGTH * BLOCK_COUNT ; i++ ){
		if (data_block[i] != block_ans[i]){
			success = false;
		}
	}

	if(success){
	    	while(true){
			/* If the example ends up here every thing is ok. */
                        nop();
		}
	}else{
		while(true){
			/* If the example ends up here something is wrong. */
                        nop();
		}
	}
}
Пример #3
0
int main(void) {
  int i;
  int ret_val;
  uint8_t *output;

  /* Initialize the IV for each cbc key structure */
  for (i = 0; i < 16; i++) {
    trans_key_sched.IV[i] = CBC_IV[i];
    hash_key_sched.IV[i] = CBC_HASH_IV[i];
  }
  trans_key_sched.aeskey.nr = 14;
  hash_key_sched.aeskey.nr = 10;

  /* Generate key schedule for public hash key */
  ret_val =  AES_set_encrypt_key((unsigned char *)(&AES128_HASH_KEY),
				 128,
				 (AES_KEY *)&(hash_key_sched.aeskey));
  if (ret_val < 0) {
    printf("ERROR: Unable to generate hash key schedule");
    return ERROR;
  }

  ret_val = AES_set_encrypt_key((unsigned char *)(&AES256_TEST_KEY),
				256,
				(AES_KEY *)&(trans_key_sched.aeskey));
  if (ret_val < 0) {
    printf("ERROR: Unable to generate transformed key schedule");
    return ERROR;
  }

  AES_transform_key(trans_key_sched.aeskey.KEY);

  printf("Managed to transform trans_key_sched.\n");

  /* Before exiting clear out the value of x from the register and
   * put it back into the debug register
   */
  output = (uint8_t *)(malloc(LENGTH));
  if (output == NULL) {
    return 0;
  }

  printf("Value of output: %p\n", output);

  AES_CBC_encrypt((unsigned char *)AES_TEST_VECTOR,
		  (unsigned char *)(output),
		  (unsigned char *)(trans_key_sched.IV),
		  LENGTH,
		  trans_key_sched.aeskey.KEY,
		  trans_key_sched.aeskey.nr);

  for (i = 0; i < 64; i++) {
    if (output[i] == AES_TEST_VECTOR[i]) {
      printf("Problem with output at %d.\n", i);
      return -1;
    }
  }


  AES_CBC_encrypt((unsigned char *)(output),
		  (unsigned char *)(output),
		  (unsigned char *)(trans_key_sched.IV),
		  LENGTH,
		  trans_key_sched.aeskey.KEY,
		  trans_key_sched.aeskey.nr);


  for (i = 0; i < 64; i++) {
    if (output[i] != AES_TEST_VECTOR[i]) {
      printf("Problem at %d.\n", i);
      //return -1;
    }
  }
  return 0;
}