#include "ROMprotocol.h" void main() { printf("Hello World!\n"); DIMASTATUS ret = 0; /*lock all resources, no interruptons*/ ret = ROMprotocol(); /*release resources*/ //ALIAS and session keys, firmware execution //measure firmware.bin //measure firmware.conf //measure .... //calculate FW_ID - composite hash of all above measurements //create ALIAS KD_ctx //keygen //publish keys //placeholder FW_ID uint8_t FW_ID[SHA256_DGST_SIZE] = { 0xf3,0x92,0x0e,0x4f,0xbe,0x67,0x0a,0xf8, 0xf1,0xd9,0x30,0xe2,0x33,0xcc,0x28,0xc5, 0xba,0x68,0xd1,0x56,0xea,0x34,0x3f,0xbc, 0xe6,0x66,0xbb,0x1e,0x7b,0xbb,0x38,0x7d }; const mbedtls_md_info_t * md_info; if(!(md_info = mbedtls_md_info_from_type(HKDF_ALG))) { perror("DIMAHKDFFAILURE: MD alg type def failed\n"); exit(DIMAHKDFFAILURE); } uint8_t salt[32] = { 0x68, 0x5e, 0x4e, 0xbe, 0xf2, 0xbe, 0xb9, 0xd5, 0x13, 0x7c, 0x14, 0x71, 0x20, 0xfb, 0x42, 0x32, 0x54, 0x12, 0x3e, 0x31, 0xa6, 0x89, 0x4c, 0xe0, 0x58, 0x51, 0x0e, 0x26, 0xb0, 0xdd, 0x78, 0x55 }; uint8_t * FWKEY = calloc(1, sizeof(uint8_t)*HKDF_KEY_SIZE); ret = mbedtls_hkdf(md_info, salt, sizeof(salt), FW_ID, SHA256_DGST_SIZE, ALIAS, sizeof(ALIAS), FWKEY, HKDF_KEY_SIZE); if(ret < DIMASUCCESS) { perror("DIMAHKDFFAILURE\n"); exit(DIMAHKDFFAILURE); } KeyDrv_context ALIAS_ctx; ALIAS_ctx.ENT_MODE = DFL_ENT; ALIAS_ctx.PKC_MODE = DFL_PKC; ALIAS_ctx.seed = FWKEY; ALIAS_ctx.phrase = ALIAS; ALIAS_ctx.KEY_FORM = DFL_FORM; printf("Generating Alias keys\n"); ret = AsymmKeyGen(&ALIAS_ctx); if(ret < DIMASUCCESS) { perror("DIMAFAILURE : ALIAS key gen failed\n"); exit(DIMAFAILURE); } //Session key creation //receive session nonce from verifier? //placeholder char * NONCE = "session1"; KeyDrv_context SSN1_ctx; SSN1_ctx.ENT_MODE = SW_PRNG; //non determ, gen new key for every session SSN1_ctx.PKC_MODE = DFL_PKC; SSN1_ctx.seed = NULL; SSN1_ctx.phrase = NONCE; SSN1_ctx.KEY_FORM = DFL_FORM; printf("Generating Session keys\n"); ret = AsymmKeyGen(&SSN1_ctx); if(ret < DIMASUCCESS) { perror("DIMAFAILURE : SESSION key gen failed\n"); exit(DIMAFAILURE); } printf("Successful exit\n"); return; }