/*===========================================================================
   Copyright (c) 2011, 2023 by Qualcomm Technologies, Incorporated.  All Rights Reserved.
===========================================================================*/

/*===========================================================================

                            EDIT HISTORY FOR FILE
# when       who        what, where, why
# --------   ---        ---------------------------------------------------------
4/4/2023    cbhupala    created a new header file containing openssl test vectors
================================================================================*/
#pragma once

#include <stdint.h>
#include "hwkm_tests.h"


uint8_t iv[16] =      { 0x28, 0xaa, 0xf0, 0x28, 0x57, 0x0b, 0x7c, 0x5d, 0xa2, 0x13, 0xd5, 0x9f, 0x28, 0xaa, 0xf0, 0x28 };

uint8_t iv_gcm[12] =  { 0x28, 0xaa, 0xf0, 0x28, 0x57, 0x0b, 0x7c, 0x5d, 0xa2, 0x13, 0xd5, 0x9f };

uint8_t iv_ccm[8] =   { 0x28, 0xaa, 0xf0, 0x28, 0x57, 0x0b, 0x7c, 0x5d };

uint8_t aad[16] =     { 0xFF, 0x76, 0x28, 0xF6, 0x42, 0x7F, 0xBC, 0xEF, 0x1F, 0x3B, 0x82, 0xB3, 0x74, 0x04, 0xE1, 0x16 };

uint8_t pt[16] =      { 0xb7, 0x06, 0x19, 0x4b, 0xb0, 0xb1, 0x0c, 0x47, 0x4e, 0x1b, 0x2d, 0x7b, 0x22, 0x78, 0x22, 0x4c };

uint8_t pt_key_128[16] =  { 0x25, 0x90, 0x1E, 0x01, 0x41, 0xEC, 0x73, 0x4D, 0x89, 0xB6, 0xD5, 0xAE, 0x5A, 0xE5, 0x79, 0xD3 };

uint8_t pt_key_256[32] = { 0x25, 0x90, 0x1E, 0x01, 0x41, 0xEC, 0x73, 0x4D, 0x89, 0xB6, 0xD5, 0xAE, 0x5A, 0xE5, 0x79, 0xD3,
                           0x25, 0x90, 0x1E, 0x01, 0x41, 0xEC, 0x73, 0x4D, 0x89, 0xB6, 0xD5, 0xAE, 0x5A, 0xE5, 0x79, 0xD3 };

/* ==========================Expected outputs====================================================================*/

//Expected cipher texts for 128 bit key
uint8_t expected_128_aes_gcm[16] = { 0xf5, 0xa7, 0x58, 0x99, 0x2d, 0x92, 0x76, 0x6a, 0x35, 0xb1, 0x37, 0xe2, 0xa5,
                                     0xbe, 0x2e, 0x73 };

uint8_t expected_128_aes_ccm[16] = { 0xbd, 0x9f, 0xc4, 0x7d, 0x2c, 0xc8, 0x92, 0xc4, 0x54, 0xac, 0x77, 0xdb, 0xf8,
                                     0x28, 0x2e, 0x44 };

uint8_t expected_128_aes_cbc[16] = { 0x5d, 0x55, 0x41, 0x0e, 0xf3, 0xbf, 0x98, 0xa9, 0x5f, 0x54, 0x44, 0x79, 0x12,
                                     0x2a, 0x97, 0x89 };

uint8_t expected_128_aes_ctr[16] = { 0x1b, 0x63, 0xe0, 0x07, 0x72, 0x00, 0xc3, 0xe8, 0xe8, 0xee, 0x62, 0xb2, 0xe6,
                                     0x6e, 0x5b, 0xd5 };

uint8_t expected_128_aes_ecb[16] = { 0x98, 0x78, 0xe0, 0xb5, 0x38, 0x5b, 0xda, 0x0e, 0xb2, 0x2b, 0x4b, 0xb8, 0x6e,
                                     0x08, 0x4d, 0x26 };

uint8_t expected_128_aes_cmac[16] = { 0xff, 0xc0, 0x96, 0xfc, 0x8e, 0xec, 0x54, 0xc7, 0x20, 0xbe, 0x50, 0x02, 0x27,
                                      0xe5, 0x73, 0x2a };

//Expected cipher texts for 256 bit key 
uint8_t expected_256_aes_gcm[16] = { 0x47, 0x67, 0x8f, 0xc0, 0x2c, 0x46, 0xb7, 0x51, 0xb7, 0xab, 0x55, 0x87, 0xd0,
                                     0xd2, 0xae, 0x75 };

uint8_t expected_256_aes_ccm[16] = { 0x21, 0x0a, 0x5a, 0x11, 0xb1, 0xe3, 0x30, 0xdb, 0xc9, 0x6d, 0x7b, 0xb7, 0xc7,
                                     0x2a, 0x9b, 0x7f };

uint8_t expected_256_aes_cbc[16] = { 0xb7, 0x29, 0x5b, 0xe9, 0xd4, 0xb8, 0xdc, 0xe3, 0xe9, 0x02, 0xbe, 0xb1, 0x46,
                                     0x0e, 0xeb, 0x10 };

uint8_t expected_256_aes_ctr[16] = { 0x05, 0xc5, 0xd6, 0x19, 0xdc, 0x9e, 0x25, 0x3c, 0x08, 0x8c, 0x4c, 0x15, 0xb4,
                                     0x6e, 0x80, 0x62 };

uint8_t expected_256_aes_ecb[16] = { 0x5a, 0xb2, 0x5f, 0x0c, 0x76, 0x2d, 0xc1, 0xb3, 0x8b, 0x3c, 0x20, 0x7a, 0xab,
                                     0x15, 0x0b, 0xba };

uint8_t expected_256_aes_cmac[16] = { 0x44, 0xc5, 0xa2, 0xab, 0x3f, 0xd8, 0x9e, 0xbd, 0xd6, 0x90, 0x24, 0xed, 0xe6,
                                      0x21, 0x84, 0x42 };

typedef struct {
    const char*        test_string;
    uint32_t           alg;
    uint32_t           cipher_mode;
    uint8_t*           pt_key;
    uint8_t            pt_key_size;
    uint32_t           uid;
    uint8_t*           expected_result;
    uint32_t           expected_result_size;
} __attribute__((packed)) test_vector_type;

//GCM Test Vectors
test_vector_type gcm_test_vectors[] = {
    {"GCM Mode - 128 bit Key", IHWKey_ALGORITHM_AES128_GCM, ICipher_MODE_GCM, pt_key_128, sizeof(pt_key_128),
    CCipherAES128_UID, expected_128_aes_gcm, sizeof(expected_128_aes_gcm)}
    ,
    {"GCM Mode - 256 bit Key",IHWKey_ALGORITHM_AES256_GCM, ICipher_MODE_GCM, pt_key_256, sizeof(pt_key_256),
    CCipherAES256_UID, expected_256_aes_gcm, sizeof(expected_256_aes_gcm)}
};

//CCM Test Vectors
test_vector_type ccm_test_vectors[] = {
    {"CCM Mode - 128 bit Key", IHWKey_ALGORITHM_AES128_CCM, ICipher_MODE_CCM, pt_key_128, sizeof(pt_key_128),
    CCipherAES128_UID, expected_128_aes_ccm, sizeof(expected_128_aes_ccm)}
    ,
    {"CCM Mode - 256 bit Key", IHWKey_ALGORITHM_AES256_CCM, ICipher_MODE_CCM, pt_key_256, sizeof(pt_key_256),
    CCipherAES256_UID, expected_256_aes_ccm, sizeof(expected_256_aes_ccm)}
};

//CBC Test Vectors
test_vector_type cbc_test_vectors[] = {
    {"CBC Mode - 128 bit Key", IHWKey_ALGORITHM_AES128_CBC, ICipher_MODE_CBC, pt_key_128, sizeof(pt_key_128),
    CCipherAES128_UID, expected_128_aes_cbc, sizeof(expected_128_aes_cbc)}
    ,
    {"CBC Mode - 256 bit Key", IHWKey_ALGORITHM_AES256_CBC, ICipher_MODE_CBC, pt_key_256, sizeof(pt_key_256),
    CCipherAES256_UID, expected_256_aes_cbc, sizeof(expected_256_aes_cbc)}
};

//CTR Test Vectors
test_vector_type ctr_test_vectors[] = {
    {"CTR Mode - 128 bit Key", IHWKey_ALGORITHM_AES128_CTR, ICipher_MODE_CTR, pt_key_128, sizeof(pt_key_128),
    CCipherAES128_UID, expected_128_aes_ctr, sizeof(expected_128_aes_ctr)}
    ,
    {"CTR Mode - 256 bit Key", IHWKey_ALGORITHM_AES256_CTR, ICipher_MODE_CTR, pt_key_256, sizeof(pt_key_256),
    CCipherAES256_UID, expected_256_aes_ctr, sizeof(expected_256_aes_ctr)}
};

//ECB Test Vectors
test_vector_type ecb_test_vectors[] = {
    {"ECB Mode - 128 bit Key", IHWKey_ALGORITHM_AES128_ECB, ICipher_MODE_ECB, pt_key_128, sizeof(pt_key_128),
    CCipherAES128_UID, expected_128_aes_ecb, sizeof(expected_128_aes_ecb)}
    ,
    {"ECB Mode - 256 bit Key", IHWKey_ALGORITHM_AES256_ECB, ICipher_MODE_ECB, pt_key_256, sizeof(pt_key_256),
    CCipherAES256_UID, expected_256_aes_ecb, sizeof(expected_256_aes_ecb)}

};

//CMAC Test Vectors
test_vector_type cmac_test_vectors[] = {
    {"CMAC Mode - 128 bit Key", IHWKey_ALGORITHM_AES128_CMAC, ICrypto_CMAC_ALGO_AES_128, pt_key_128, sizeof(pt_key_128),
    CCrypto_UID, expected_128_aes_cmac, sizeof(expected_128_aes_cmac)}
    ,
    {"CMAC Mode - 256 bit Key", IHWKey_ALGORITHM_AES256_CMAC, ICrypto_CMAC_ALGO_AES_256, pt_key_256, sizeof(pt_key_256),
    CCrypto_UID, expected_256_aes_cmac, sizeof(expected_256_aes_cmac)}

};