cc1110 aes加密问题
时间:12-23
整理:3721RD
点击:
// Define size of AES block #define SIZE_OF_AES_BLOCK 16 // Allocate source buffers for AES key and IV/NONCE static uint8 key[SIZE_OF_AES_BLOCK] = {"simpliciti's key"}; static uint8 iv_nonce[SIZE_OF_AES_BLOCK] = {"longjing's smart"}; void aesInit(void) { uint8 i; // Generate Key: ENCCS = 0x04 | 0x01; for (i = 0; i < SIZE_OF_AES_BLOCK; i++) { ENCDI = key[i]; } // Monitor AES (ENCCS.RDY) to wait until key downloaded while(!(ENCCS & 0x08)); // Generate IV: 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)); } uint8 encryptDecrypt(uint8* source,uint8 length,uint8* targ,uint8 type) { uint16 i, j; uint8 nBlock = 0; nBlock = length / 16; if((length % 2) != 0 )//less than 128 bits nBlock++; if(type) ENCCS = 0x00; // Only valid for encryption mode ! else ENCCS = 0x02; // Only valid for decryption mode ! ENCCS |= 0X01; for (j = 0; j < nBlock; j++) { // In encryption mode "aes_buffer_1" represents the data to be encrypted. // In decryption mode "aes_buffer_1" represents the data to be decrypted. for (i = 0; i < SIZE_OF_AES_BLOCK; i++) { ENCDI = ((i+j*SIZE_OF_AES_BLOCK) < length)?source[i+(j*SIZE_OF_AES_BLOCK)]:0x00; // ENCDI = source[i+(j*SIZE_OF_AES_BLOCK)]; } // while(!(ENCCS & 0x08)); // 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. for (i = 0; i < SIZE_OF_AES_BLOCK; i++) { targ[i+(j*SIZE_OF_AES_BLOCK)] = ENCDO; } // Monitor AES (ENCCS.RDY) to wait until data block downloaded while(!(ENCCS & 0x08)); } }
卡在红色地方,高手指点下
能不能描述下来龙去脉啊?毕竟能花时间去读代码的人还是很少。而且问题也不一定在这段代码里面。
这个问题我直接解决了 ,你可以帮我解决下这个问题呢?cc1110 使用simpliciTI 协议栈,我打开SMPL_SECURE宏后,ap发送出的加密数据,ed可以接收到并正确进行解密;而ED发送的加密数据AP却不能?