#include "ROMprotocol.h" /* DIMASTATUS ret = 0; int len = 0; if(DEBUG) {printf("PASS \n");} if(ret < DIMASUCCESS) { perror("\n"); //other cleanup exit(); } */ DIMASTATUS ROMprotocol() { DIMASTATUS ret = 0; int len = 0; if(DEBUG) {printf("PASS 1\n");} //Calculate DIMA RTM hash //this should be calculated on the DIMA bin and remain static. //how to do that? //hardcoding junk value for now uint8_t RTM_ID[SHA256_DGST_SIZE] = {0xbe,0x67,0x0a,0xf8,0xf3,0x92,0x0e,0xba,0x68,0xd1,0x56,0xea,0x34,0x3f,0xbc,0x4f, 0xf1,0xd9,0x30,0xe2,0x3e,0xcc,0x28,0xc5,0x7b,0xbb,0x38,0x7d,0xe6,0x66,0xbb,0x1e}; //Calculating UDS hash FILE *fp = NULL; fp = fopen("RANDFILE", "rb"); if(!fp) { perror("DIMAFILENOTFOUND: Unable to access UDS\n"); fclose(fp); exit(DIMAFILENOTFOUND); } if(DEBUG) {printf("PASS 2\n");} uint8_t *UDSbuf = calloc(1, sizeof(uint8_t)*SHA256_DGST_SIZE); fread(UDSbuf,UDS_SIZE,1,fp); { perror("File read error: Unable to read UDS\n"); fclose(fp); free(UDSbuf); exit(DIMAFAILUREUNKWN); } fclose(fp); if(DEBUG) {printf("PASS 3\n");} uint8_t* UDS_ID = calloc(1,sizeof(uint8_t)*SHA256_DGST_SIZE); ret = mbedtls_sha256_ret( UDSbuf,UDS_SIZE,UDS_ID,0 ); if(ret < DIMASUCCESS) { perror("DIMASHAFAILUE:\n"); free(UDSbuf); free(UDS_ID); exit(DIMAFAILUREUNKWN); } //UDS_ID contains the UDS hash //Printer if(DEBUG) { for (int i = 0; i < UDS_SIZE; i++) printf("%hhx", UDSbuf[i]); printf(" : fuse secret\n" ); for (int i = 0; i < SHA256_DGST_SIZE; i++) printf("%hhx", UDS_ID[i]); printf(" : UDS ID\n" ); } if(DEBUG) {printf("PASS 100\n");} return DIMASUCCESS; }