I have to implement a group key encryption scheme involving plain text encryption, bitwise XOR operations. I have run the following code. Now my question is how can I encrypt some string consisting of node ids, timestamp, and a random nonce. I have encrypted the above in other libraries but not sure how to do them for embedded and RIOT. Also, I have to implement the bitwise XOR operation. Can someone help me solve this?
#include <stdio.h>
#include <string.h>
#include <crypto/aes.h>
static uint8_t TEST_1_KEY[] = {
0x23, 0xA0, 0x18, 0x53, 0xFA, 0xB3, 0x89, 0x23,
0x65, 0x89, 0x2A, 0xBC, 0x43, 0x99, 0xCC, 0x00
};
static uint8_t TEST_1_INP[] = {
0x11, 0x53, 0x81, 0xE2, 0x5F, 0x33, 0xE7, 0x41,
0xBB, 0x12, 0x67, 0x38, 0xE9, 0x12, 0x54, 0x23
};
int main(void)
{
uint8_t data_enc[16]={0};
uint8_t data_dec[16]={0};
cipher_context_t ctx_riot;
aes_init(&ctx_riot, TEST_1_KEY, sizeof(TEST_1_KEY));
aes_encrypt(&ctx_riot, TEST_1_INP, data_enc);
aes_decrypt(&ctx_riot, data_enc, data_dec);
if (memcmp(TEST_1_INP, data_dec, sizeof(data_dec)) != 0) {
printf("ERROR\n"); }
else
{
printf("SUCCESS \n");
}
return 0;
}
I have also looked at the following code
#include "crypto/ciphers.h" cipher_t cipher; uint8_t key[AES_KEY_SIZE] = {0}, plain_text[AES_BLOCK_SIZE] = {0}, cipher_text[AES_BLOCK_SIZE] = {0}; if (cipher_init(&cipher, CIPHER_AES_128, key, AES_KEY_SIZE) < 0) printf("Cipher init failed!\n"); if (cipher_encrypt(&cipher, plain_text, cipher_text) < 0) printf("Cipher encryption failed!\n"); else od_hex_dump(cipher_text, AES_BLOCK_SIZE, 0);