Esempio n. 1
0
void aes_handle(uint8_t * key, uint8_t * text)
{
    nrf_ecb_set_key(key);
    bool is_successful = nrf_ecb_crypt(text, text);
    ASSERT(is_successful);
    (void)is_successful;
}
Esempio n. 2
0
void gzp_crypt(uint8_t* dst, const uint8_t* src, uint8_t length)
{
    uint8_t i;
    uint8_t key[16];
    uint8_t iv[16];

    // Build AES key based on "gzp_key_select"

    switch(gzp_key_select)
    {
    case GZP_ID_EXCHANGE:
        memcpy(key, (void const*)gzp_secret_key, 16);
        break;
    case GZP_KEY_EXCHANGE:
        memcpy(key, (void const*)gzp_secret_key, 16);
        gzp_get_host_id(key);
        break;
    case GZP_DATA_EXCHANGE:
        memcpy(key, (void const*)gzp_secret_key, 16);
        memcpy(key, (void const*)gzp_dyn_key, GZP_DYN_KEY_LENGTH);
        break;
    default:
        return;
    }  

    // Build init vector from "gzp_session_token"
    for(i = 0; i < 16; i++)
    {
        if(i < GZP_SESSION_TOKEN_LENGTH)
        {
            iv[i] = gzp_session_token[i];
        }
        else
        {
            iv[i] = 0;
        }
    }

    // Set up hal_aes using new key and init vector
    (void)nrf_ecb_init();
    nrf_ecb_set_key(key);
    //hal_aes_setup(false, ECB, key, NULL); // Note, here we skip the IV as we use ECB mode

    // Encrypt IV using ECB mode
    (void)nrf_ecb_crypt(iv, iv);

    // Encrypt data by XOR'ing with AES output
    gzp_xor_cipher(dst, src, iv, length);

}