Exemple #1
0
int test_kdf_sha256()
{
	u32 pDestAddr = (HI_CIPHER_BASE_ADDR_VIRT + HI_KEY_RAM_OFFSET);
	u8 right_hash[32] = {0x65,0xb9,0x30,0x04,0x64,0x47,0x0a,0x9a,0xe4,0xc2,0x30,0xf9,0xd0,0xf3,0xe4,0x03,0x60,0xc7,0x56,0x20,0xf1,0x9f,0x89,0x64,0xf5,0x29,0xc7,0x78,0x2e,0xc8,0x88,0xc8};
	int i = 0;
	u32 src_data[1024] = {0};
	u32 hashrelt[8] = {0,0,0,0,0,0,0,0};
	u32 result_hash[8] = {0};
	s32 err = 0;

	for(i = 0; i < 1024; i++)
		src_data[i] = i;
	err = kdf_sha256((u8*)&src_data[0], 512 * 4, (u8*)&hashrelt[0]);
	if(err)
	{
		//printf("ERR : kdf_sha256\n");
		return err;
	}
	#if 0
	for(i = 0;i < 8; i++)
		printf("%X\n", hashrelt[i]);
	printf("\n\n");
	#endif
	for(i = 0; i < 8; i++)
		result_hash[i] = CIPHER_BSWAP32(*((u32 *)pDestAddr + i));
	err = cipher_memcmp_ext(result_hash, right_hash, 32);
	return err;
}
s32 BSP_KDF_003_001(void)
{
    s32  s32Ret = BSP_OK;
    void *pDestAddr;
	s32 i = 0;
	u32 result_hash[KDF_DESTKEY_LENGTH / sizeof(u32)] = {0};

	if(kdf_init())
	{
		return -1;
	}
	kdf_reg_init();

    /*°ÑkeyдÈë0ºÅË÷ÒýλÖÃ*/
    for(i=0; i<KDF_SHA_KEY_LENGTH/4; i++)
    {        
        *((BSP_U32 *)(HI_CIPHER_BASE_ADDR_VIRT + HI_KEY_RAM_OFFSET + 4*i))  \
        = (((BSP_U32)u32GoldenKey[4*i])<<24) | (((BSP_U32)u32GoldenKey[4*i+1])<<16) \
          | (((BSP_U32)u32GoldenKey[4*i+2])<<8) | ((BSP_U32)u32GoldenKey[4*i+3]);
    }

	if(kdf_hash_make(u32GoldenS1, KDF_SHA_S_LENGTH))
		return -2;
	pDestAddr = (void *)(HI_CIPHER_BASE_ADDR_VIRT + HI_KEY_RAM_OFFSET + KDF_DESTKEY_OFF);
	for(i = 0; i < 256 / 32; i++)
	{
		printk("%X\n", *((u32*)pDestAddr + i));
	}
	for(i = 0; i < KDF_DESTKEY_LENGTH / sizeof(u32); i++)
		result_hash[i] = CIPHER_BSWAP32(*((u32 *)pDestAddr + i));
	s32Ret = cipher_memcmp_ext((void *)result_hash, (void *)u32GoldenResult1, KDF_DESTKEY_LENGTH);
	return s32Ret;
}
int KDF_TEST_LHK(void)
{
	s32 i = 0;
	u32 hashrelt[8] = {0,0,0,0,0,0,0,0};
	u32 src_data[1024] = {0};
	u32 pDestAddr = (HI_CIPHER_BASE_ADDR_VIRT + HI_KEY_RAM_OFFSET);
	u8 right_hash[32] = {0x65,0xb9,0x30,0x04,0x64,0x47,0x0a,0x9a,0xe4,0xc2,0x30,0xf9,0xd0,0xf3,0xe4,0x03,0x60,0xc7,0x56,0x20,0xf1,0x9f,0x89,0x64,0xf5,0x29,0xc7,0x78,0x2e,0xc8,0x88,0xc8};
	
	printk("%X\n\n",HI_CIPHER_BASE_ADDR_VIRT);

	memset(src_data, 0, sizeof(src_data));
	for(i = 0; i < 1024; i++)
		src_data[i] = i;
#if 1
	if(kdf_hash_setkey((void*)hashrelt))
		return -1;
	for(i = 0; i < 256 / 32; i++)
	{
		printk("%X\n", *((u32*)(pDestAddr + i * 4)));
	}
	printk("\n\n");
#endif

#if 0
	memset((void*)pDestAddr, 0, 32);
	for(i = 0; i < 256 / 32; i++)
	{
		printk("%X\n", *((u32*)pDestAddr + i));
	}
	printk("\n\n");
#endif
	
	kdf_hash_make(src_data, 512);
	kdf_result_hash_get(hashrelt);
	for(i = 0; i < 8; i++)
		printk("%X\n", *(hashrelt + i));

	kdf_hash_setkey(hashrelt);
	kdf_hash_make(((u8*)src_data) + 512, 512);
	kdf_result_hash_get(hashrelt);
	for(i = 0; i < 8; i++)
		printk("%X\n", *(hashrelt + i));

	kdf_hash_setkey(hashrelt);
	kdf_hash_make(((u8*)src_data) + 1024, 512);
	kdf_result_hash_get(hashrelt);
	for(i = 0; i < 8; i++)
		printk("%X\n", *(hashrelt + i));

	kdf_hash_setkey(hashrelt);
	kdf_hash_make(((u8*)src_data) + 512 + 1024, 512);
	kdf_result_hash_get(hashrelt);
	for(i = 0; i < 8; i++)
		printk("%X\n", *(hashrelt + i));
#if 0
	kdf_hash_setkey(hashrelt);
	kdf_hash_make(((u8*)src_data) + 1024 + 1024, 512);
	kdf_result_hash_get(hashrelt);
	for(i = 0; i < 8; i++)
		printk("%X\n", *(hashrelt + i));

	kdf_hash_setkey(hashrelt);
	kdf_hash_make(((u8*)src_data) + 512 + 2 * 1024, 512);
	kdf_result_hash_get(hashrelt);
	for(i = 0; i < 8; i++)
		printk("%X\n", *(hashrelt + i));

	kdf_hash_setkey(hashrelt);
	kdf_hash_make(((u8*)src_data) + 3 * 1024, 512);
	kdf_result_hash_get(hashrelt);
	for(i = 0; i < 8; i++)
		printk("%X\n", *(hashrelt + i));

	kdf_hash_setkey(hashrelt);
	kdf_hash_make(((u8*)src_data) + 512 + 3 * 1024, 512);
	kdf_result_hash_get(hashrelt);
	for(i = 0; i < 8; i++)
		printk("%X\n", *(hashrelt + i));
#endif
	for(i = 0; i < 8; i++)
		hashrelt[i] = CIPHER_BSWAP32(hashrelt[i]);
	if(cipher_memcmp_ext(hashrelt,right_hash,32))
		printk("KDF_TEST_LHK hash ERR\n");
	
	return 0;
}