ENCCS = 0x40;//ECB // Generate Key: // In a radio application this is typically generated based on // a standard/protocol specification. However, for simplicity, // this app report does not use any particular specification // for generating it. for(i = 0; i < SIZE_OF_AES_BLOCK; i++) { key[i] = i * 2; } // Download Key (Set ENCCS.CMD = 10b), // and start corresponding AES process (ENCCS.ST = 1) ENCCS = 0x04 | 0x01; printf("key "); for (i = 0; i < SIZE_OF_AES_BLOCK; i++) { ENCDI = key[i]; printf("%x ",key[i]); } printf("\r\n"); // Monitor AES (ENCCS.RDY) to wait until key downloaded while(!(ENCCS & 0x08)); // Generate IV/NONCE: // In a radio application this is typically generated based on // a standard/protocol specification. However, for simplicity, // this app report does not use any particular specification // for generating it. //printf("IV "); //for(i = 0; i < SIZE_OF_AES_BLOCK; i++) { iv_nonce[i] = i; //printf("%x ",iv_nonce[i]); //} //printf("\r\n"); //// Dwonload IV/NONCE (Set ENCCS.CMD = 11b) //// and start corresponding AES process (ENCCS.ST = 1) //ENCCS = 0x06 | 0x01; //for (i = 0; i < SIZE_OF_AES_BLOCK; i++) { //ENCDI = iv_nonce[i]; //} //// Monitor AES (ENCCS.RDY) to wait until IV/NONCE downloaded //while(!(ENCCS & 0x08)); // //////////////////////////////////////////////////////////////// // Place code here for downloading key and IV/NONCE (see Example 5) //////////////////////////////////////////////////////////////// // Perform AES encryption/decryption on allocated AES buffer ("aes_buffer_1"): for (j = 0; j < SIZE_OF_ENC_PACKET/SIZE_OF_AES_BLOCK; j++) { // Configure and start AES coprocessor for the desired AES mode: // Encryption => ENCCS.CMD = 00b, decryption mode => ENCCS.CMD = 01b. // Use so-called Cipher Block Chaining encryption mode => ENCCS.MODE = 000b. // Start AES processing (ENCCS.ST = 1) of source buffer (aes_buffer_1). ENCCS = 0x00 | 0x01; // Only valid for encryption mode ! //ENCCS = 0x02 | 0x01; // Only valid for decryption mode ! // Download data block (16 bytes) to AES coprocessor: // In encryption mode, "aes_buffer_1" represents the data to be encrypted. // In decryption mode, "aes_buffer_1" represents the data to be decrypted. printf("text "); for (i = 0; i < SIZE_OF_AES_BLOCK; i++) { ENCDI = aes_buffer_1[i+(j*SIZE_OF_AES_BLOCK)]; printf("%x ",aes_buffer_1[i+(j*SIZE_OF_AES_BLOCK)]); } printf("\r\n"); // Wait until AES download is finished, that is; apply delay // equivalent to 40 NOPs: asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP"); asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP"); asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP"); asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP"); asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP"); asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP"); // Upload data block (16 bytes) to allocated AES buffer: // In encryption mode, "aes_buffer_2" represents the encrypted data. // In decryption mode, "aes_buffer_2" represents the decrypted data. printf("result "); for (i = 0; i < SIZE_OF_AES_BLOCK; i++) { aes_buffer_2[i+(j*SIZE_OF_AES_BLOCK)] = ENCDO; printf("%x ",aes_buffer_2[i+(j*SIZE_OF_AES_BLOCK)]); } printf("\r\n"); // Monitor AES (ENCCS.RDY) to wait until data block downloaded while(!(ENCCS & 0x08)); } printf("\r\n"); printf("\r\n"); printf("\r\n"); printf("\r\n"); //////////////////////////////////////////////////////////////// // Place code here for downloading key and IV/NONCE (see Example 5) //////////////////////////////////////////////////////////////// // Perform AES encryption/decryption on allocated AES buffer ("aes_buffer_1"): for (j = 0; j < SIZE_OF_ENC_PACKET/SIZE_OF_AES_BLOCK; j++) { // Configure and start AES coprocessor for the desired AES mode: // Encryption => ENCCS.CMD = 00b, decryption mode => ENCCS.CMD = 01b. // Use so-called Cipher Block Chaining encryption mode => ENCCS.MODE = 000b. // Start AES processing (ENCCS.ST = 1) of source buffer (aes_buffer_1). //ENCCS = 0x00 | 0x01; // Only valid for encryption mode ! ENCCS = 0x02 | 0x01; // Only valid for decryption mode ! // Download data block (16 bytes) to AES coprocessor: // In encryption mode, "aes_buffer_1" represents the data to be encrypted. // In decryption mode, "aes_buffer_1" represents the data to be decrypted. printf("text "); for (i = 0; i < SIZE_OF_AES_BLOCK; i++) { ENCDI = aes_buffer_2[i+(j*SIZE_OF_AES_BLOCK)]; printf("%x ",aes_buffer_2[i+(j*SIZE_OF_AES_BLOCK)]); } printf("\r\n"); // Wait until AES download is finished, that is; apply delay // equivalent to 40 NOPs: asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP"); asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP"); asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP"); asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP"); asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP"); asm("NOP");asm("NOP");asm("NOP");asm("NOP");asm("NOP"); // Upload data block (16 bytes) to allocated AES buffer: // In encryption mode, "aes_buffer_2" represents the encrypted data. // In decryption mode, "aes_buffer_2" represents the decrypted data. printf("result "); for (i = 0; i < SIZE_OF_AES_BLOCK; i++) { aes_buffer_1[i+(j*SIZE_OF_AES_BLOCK)] = ENCDO; printf("%x ",aes_buffer_1[i+(j*SIZE_OF_AES_BLOCK)]); } printf("\r\n"); // Monitor AES (ENCCS.RDY) to wait until data block downloaded while(!(ENCCS & 0x08)); }