mbedtls extract CDI key working
This commit is contained in:
parent
7c6c959767
commit
3fb14de7ab
@ -65,7 +65,7 @@ int readUDS(uint8_t* UDS_M)
|
|||||||
BIO_printf(out,"%x,",UDSbuf[i]);
|
BIO_printf(out,"%x,",UDSbuf[i]);
|
||||||
BIO_printf(out, "\n");
|
BIO_printf(out, "\n");
|
||||||
|
|
||||||
BIO_printf(out,"UDS digest : ");
|
BIO_printf(out,"UDS digest\t: ");
|
||||||
for(i = 0; i < SHA256_DGST_SIZE; i++)
|
for(i = 0; i < SHA256_DGST_SIZE; i++)
|
||||||
BIO_printf(out,"%x",UDS_M[i]);
|
BIO_printf(out,"%x",UDS_M[i]);
|
||||||
BIO_printf(out, "\n");
|
BIO_printf(out, "\n");
|
||||||
@ -109,7 +109,7 @@ int readFWID(uint8_t* FW_M)
|
|||||||
// BIO_printf(out,"%x,",source[i]);
|
// BIO_printf(out,"%x,",source[i]);
|
||||||
// BIO_printf(out, "\n");
|
// BIO_printf(out, "\n");
|
||||||
|
|
||||||
BIO_printf(out,"FW digest : ");
|
BIO_printf(out,"FW digest\t: ");
|
||||||
for(i = 0; i < SHA256_DGST_SIZE; i++)
|
for(i = 0; i < SHA256_DGST_SIZE; i++)
|
||||||
BIO_printf(out,"%x",FW_M[i]);
|
BIO_printf(out,"%x",FW_M[i]);
|
||||||
BIO_printf(out, "\n");
|
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,"%x",FW_M[i]);
|
||||||
// BIO_printf(out, "\n");
|
// BIO_printf(out, "\n");
|
||||||
|
|
||||||
BIO_printf(out,"CDI : ");
|
BIO_printf(out,"CDI\t\t: ");
|
||||||
for(int i = 0; i < SHA256_DGST_SIZE; i++)
|
for(int i = 0; i < SHA256_DGST_SIZE; i++)
|
||||||
BIO_printf(out,"%x",CDID[i]);
|
BIO_printf(out,"%x",CDID[i]);
|
||||||
BIO_printf(out, "\n");
|
BIO_printf(out, "\n");
|
||||||
|
@ -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
|
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");;
|
printf("\n\nKDF call success\n");;
|
||||||
|
|
||||||
|
printf( "KEY_OUT\t\t: ");
|
||||||
for(int i = 0; i <= KDF_KEY_SIZE; i++)
|
for(int i = 0; i < KDF_KEY_SIZE; i++)
|
||||||
printf("%x,",KEY_OUT[i]);
|
printf("%x",KEY_OUT[i]);
|
||||||
printf( " : KEY_OUT\n");
|
printf( "\n");
|
||||||
|
|
||||||
|
|
||||||
//End block
|
//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
|
//create comtext
|
||||||
//ctx set params
|
//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);
|
//uint8_t * OUT = calloc(1,sizeof(uint8_t)*KDF_KEY_SIZE);
|
||||||
//size_t keylen = 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,
|
0xbe,0x67,0x0a,0xf8,0xf3,0x92,0x0e,0xba,0x68,0xd1,0x56,0xea,0x34,0x3f,0xbc,0x4f,
|
||||||
0xf1,0xd9,0x1e};
|
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:");
|
perror("pkey init failed:");
|
||||||
// if (EVP_PKEY_CTX_hkdf_mode(pctx,EVP_PKEY_HKDEF_MODE_EXPAND_ONLY ) <= 0)
|
// if (EVP_PKEY_CTX_hkdf_mode(pctx,EVP_PKEY_HKDEF_MODE_EXPAND_ONLY ) <= 0)
|
||||||
//perror("set message mode failed:");
|
//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:");
|
perror("set message digest failed:");
|
||||||
if (EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, sizeof(salt)) <= 0)
|
if (EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, sizeof(salt)) <= 0)
|
||||||
perror("set salt failed:");
|
perror("set salt failed:");
|
||||||
|
@ -7,17 +7,18 @@
|
|||||||
|
|
||||||
#define SHA256_DGST_SIZE 32 //bytes
|
#define SHA256_DGST_SIZE 32 //bytes
|
||||||
#define PASSPHRASE "Identity"
|
#define PASSPHRASE "Identity"
|
||||||
#define KDF_KEY_SIZE 32
|
#define KDF_KEY_SIZE 32 //bytes
|
||||||
#define KDF_ALG EVP_sha256()
|
#define KDF_ALG EVP_sha256()
|
||||||
#define EC_KEY_SIZE 32
|
#define EC_KEY_SIZE 32
|
||||||
|
#define EC_CURVE NID_secp224r1
|
||||||
|
|
||||||
#define lenofstr(a) (sizeof(a)-1)
|
#define lenofstr(a) (sizeof(a)-1)
|
||||||
|
|
||||||
|
|
||||||
void startCDIProtocol();
|
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);
|
||||||
int deriveECC_Key();
|
int deriveECC_KeyPair();
|
||||||
int deriveDEVICE_Key();
|
int deriveDEVICE_Key();
|
||||||
int deriveALIAS_key();
|
int deriveALIAS_key();
|
||||||
int genDEVICE_cert();
|
int genDEVICE_cert();
|
||||||
|
@ -18,6 +18,6 @@ debug:
|
|||||||
${CC} -g -o $(ODIR)/dbg-main main.c layer1.c layer2.c -lssl -lcrypto
|
${CC} -g -o $(ODIR)/dbg-main main.c layer1.c layer2.c -lssl -lcrypto
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -r $(ODIR)/*
|
rm -r $(ODIR)/* !("RANDFILE")
|
||||||
rm -r ./keys/*
|
rm -r ./keys/*
|
||||||
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
void myPrintHelloMake(void);
|
|
@ -1,9 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <hellomake.h>
|
|
||||||
|
|
||||||
void myPrintHelloMake(void) {
|
|
||||||
|
|
||||||
printf("Hello makefiles!\n");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
Binary file not shown.
@ -1,8 +0,0 @@
|
|||||||
#include <hellomake.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
// call a function in another file
|
|
||||||
myPrintHelloMake();
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
IDIR =../include
|
IDIR =../include
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CFLAGS=-I$(IDIR)
|
CFLAGS=-I$(IDIR)
|
||||||
@ -5,22 +6,25 @@ CFLAGS=-I$(IDIR)
|
|||||||
ODIR=obj
|
ODIR=obj
|
||||||
LDIR =../lib
|
LDIR =../lib
|
||||||
|
|
||||||
LIBS=-lm
|
LIBS=-lm -lmbedcrypto -lmbedtls -lmbedx509
|
||||||
|
|
||||||
_DEPS = hellomake.h
|
_DEPS = functions.h ROMfunctions.h
|
||||||
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
|
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
|
||||||
|
|
||||||
_OBJ = hellomake.o hellofunc.o
|
_OBJ = main.o functions.o ROMfunctions.o
|
||||||
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
|
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
|
||||||
|
|
||||||
|
|
||||||
$(ODIR)/%.o: %.c $(DEPS)
|
$(ODIR)/%.o: %.c $(DEPS)
|
||||||
$(CC) -c -o $@ $< $(CFLAGS)
|
$(CC) -c -o $@ $< $(CFLAGS)
|
||||||
|
|
||||||
hellomake: $(OBJ)
|
main: $(OBJ)
|
||||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||||
|
|
||||||
.PHONY: clean
|
debug: $(OBJ)
|
||||||
|
$(CC) -g -o $@ $^ $(CFLAGS) $(LIBS)
|
||||||
|
|
||||||
|
.PHONY: clean main debug
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
|
rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user