diff --git a/trial1/layer1.c b/trial1/layer1.c index d61c72b..52697e2 100644 --- a/trial1/layer1.c +++ b/trial1/layer1.c @@ -65,7 +65,7 @@ int readUDS(uint8_t* UDS_M) BIO_printf(out,"%x,",UDSbuf[i]); BIO_printf(out, "\n"); - BIO_printf(out,"UDS digest : "); + BIO_printf(out,"UDS digest\t: "); for(i = 0; i < SHA256_DGST_SIZE; i++) BIO_printf(out,"%x",UDS_M[i]); BIO_printf(out, "\n"); @@ -109,7 +109,7 @@ int readFWID(uint8_t* FW_M) // BIO_printf(out,"%x,",source[i]); // BIO_printf(out, "\n"); - BIO_printf(out,"FW digest : "); + BIO_printf(out,"FW digest\t: "); for(i = 0; i < SHA256_DGST_SIZE; i++) BIO_printf(out,"%x",FW_M[i]); BIO_printf(out, "\n"); @@ -158,7 +158,7 @@ int calcCDID(uint8_t * UDS_M, uint8_t * FW_M, uint8_t * CDID) // BIO_printf(out,"%x",FW_M[i]); // BIO_printf(out, "\n"); - BIO_printf(out,"CDI : "); + BIO_printf(out,"CDI\t\t: "); for(int i = 0; i < SHA256_DGST_SIZE; i++) BIO_printf(out,"%x",CDID[i]); BIO_printf(out, "\n"); diff --git a/trial1/layer2.c b/trial1/layer2.c index 911278b..22b34bc 100644 --- a/trial1/layer2.c +++ b/trial1/layer2.c @@ -42,13 +42,13 @@ void startCDIProtocol() size_t KEY_LEN = KDF_KEY_SIZE; //need to pass pointer to the out key size, not the value - if(deriveKDF(KEY_OUT, &KEY_LEN, CD_ID, SHA256_DGST_SIZE, PASSPHRASE, lenofstr(PASSPHRASE))) + if(deriveKEY(KEY_OUT, &KEY_LEN, CD_ID, SHA256_DGST_SIZE, PASSPHRASE, lenofstr(PASSPHRASE))) printf("\n\nKDF call success\n");; - - for(int i = 0; i <= KDF_KEY_SIZE; i++) - printf("%x,",KEY_OUT[i]); - printf( " : KEY_OUT\n"); + printf( "KEY_OUT\t\t: "); + for(int i = 0; i < KDF_KEY_SIZE; i++) + printf("%x",KEY_OUT[i]); + printf( "\n"); //End block @@ -58,7 +58,7 @@ void startCDIProtocol() } -int deriveKDF(uint8_t * out, size_t * out_len, uint8_t * secret, int secret_len, unsigned char * passphrase, int pass_len) +int deriveKEY(uint8_t * out, size_t * out_len, uint8_t * secret, int secret_len, unsigned char * passphrase, int pass_len) { //create comtext //ctx set params @@ -80,7 +80,7 @@ int deriveKDF(uint8_t * out, size_t * out_len, uint8_t * secret, int secret_len, //uint8_t * OUT = calloc(1,sizeof(uint8_t)*KDF_KEY_SIZE); //size_t keylen = KDF_KEY_SIZE; - uint8_t salt[32] = {0x31,0xe2,0x3e,0xcc,0x28,0xc5,0x7b,0xbb,0x38,0x7d,0xe6,0x66,0xbb, + uint8_t salt[32] = {0x30,0xe2,0x3e,0xcc,0x28,0xc5,0x7b,0xbb,0x38,0x7d,0xe6,0x66,0xbb, 0xbe,0x67,0x0a,0xf8,0xf3,0x92,0x0e,0xba,0x68,0xd1,0x56,0xea,0x34,0x3f,0xbc,0x4f, 0xf1,0xd9,0x1e}; @@ -90,7 +90,7 @@ int deriveKDF(uint8_t * out, size_t * out_len, uint8_t * secret, int secret_len, perror("pkey init failed:"); // if (EVP_PKEY_CTX_hkdf_mode(pctx,EVP_PKEY_HKDEF_MODE_EXPAND_ONLY ) <= 0) //perror("set message mode failed:"); - if (EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()) <= 0) + if (EVP_PKEY_CTX_set_hkdf_md(pctx, KDF_ALG) <= 0) perror("set message digest failed:"); if (EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, sizeof(salt)) <= 0) perror("set salt failed:"); diff --git a/trial1/layer2.h b/trial1/layer2.h index 296d8a8..f2c22dd 100644 --- a/trial1/layer2.h +++ b/trial1/layer2.h @@ -7,17 +7,18 @@ #define SHA256_DGST_SIZE 32 //bytes #define PASSPHRASE "Identity" -#define KDF_KEY_SIZE 32 +#define KDF_KEY_SIZE 32 //bytes #define KDF_ALG EVP_sha256() #define EC_KEY_SIZE 32 +#define EC_CURVE NID_secp224r1 #define lenofstr(a) (sizeof(a)-1) void startCDIProtocol(); -int deriveKDF(uint8_t * out, size_t * out_len, uint8_t * secret, int secret_len, unsigned char * passphrase, int pass_len); -int deriveECC_Key(); +int deriveKEY(uint8_t * out, size_t * out_len, uint8_t * secret, int secret_len, unsigned char * passphrase, int pass_len); +int deriveECC_KeyPair(); int deriveDEVICE_Key(); int deriveALIAS_key(); int genDEVICE_cert(); diff --git a/trial1/makefile b/trial1/makefile index 526d6ba..c72a3f2 100644 --- a/trial1/makefile +++ b/trial1/makefile @@ -18,6 +18,6 @@ debug: ${CC} -g -o $(ODIR)/dbg-main main.c layer1.c layer2.c -lssl -lcrypto clean: - rm -r $(ODIR)/* + rm -r $(ODIR)/* !("RANDFILE") rm -r ./keys/* diff --git a/trial2/include/hellomake.h b/trial2/include/hellomake.h deleted file mode 100644 index fccca1b..0000000 --- a/trial2/include/hellomake.h +++ /dev/null @@ -1 +0,0 @@ -void myPrintHelloMake(void); diff --git a/trial2/src/hellofunc.c b/trial2/src/hellofunc.c deleted file mode 100644 index 356ffa7..0000000 --- a/trial2/src/hellofunc.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -void myPrintHelloMake(void) { - - printf("Hello makefiles!\n"); - - return; -} diff --git a/trial2/src/hellomake b/trial2/src/hellomake deleted file mode 100644 index 390cb17..0000000 Binary files a/trial2/src/hellomake and /dev/null differ diff --git a/trial2/src/hellomake.c b/trial2/src/hellomake.c deleted file mode 100644 index 3d673b7..0000000 --- a/trial2/src/hellomake.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int main() { - // call a function in another file - myPrintHelloMake(); - - return(0); -} diff --git a/trial2/src/makefile b/trial2/src/makefile index 95561df..e92c0fb 100644 --- a/trial2/src/makefile +++ b/trial2/src/makefile @@ -1,3 +1,4 @@ + IDIR =../include CC=gcc CFLAGS=-I$(IDIR) @@ -5,22 +6,25 @@ CFLAGS=-I$(IDIR) ODIR=obj LDIR =../lib -LIBS=-lm +LIBS=-lm -lmbedcrypto -lmbedtls -lmbedx509 -_DEPS = hellomake.h +_DEPS = functions.h ROMfunctions.h DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS)) -_OBJ = hellomake.o hellofunc.o +_OBJ = main.o functions.o ROMfunctions.o OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) $(ODIR)/%.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) -hellomake: $(OBJ) +main: $(OBJ) $(CC) -o $@ $^ $(CFLAGS) $(LIBS) -.PHONY: clean +debug: $(OBJ) + $(CC) -g -o $@ $^ $(CFLAGS) $(LIBS) + +.PHONY: clean main debug clean: rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~ diff --git a/trial2/src/obj/hellofunc.o b/trial2/src/obj/hellofunc.o deleted file mode 100644 index 7f46741..0000000 Binary files a/trial2/src/obj/hellofunc.o and /dev/null differ diff --git a/trial2/src/obj/hellomake.o b/trial2/src/obj/hellomake.o deleted file mode 100644 index 2526b2e..0000000 Binary files a/trial2/src/obj/hellomake.o and /dev/null differ