rpi experiemnt

This commit is contained in:
atul.jha 2020-09-02 12:48:23 +02:00
parent 57a7e2b287
commit 3063768ac2
3 changed files with 41 additions and 36 deletions

View File

@ -1,22 +1,26 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include<mbedtls/config.h> #include "mbedtls/config.h"
#include <mbedtls/aes.h> #include "mbedtls/aes.h"
#include <mbedtls/bignum.h> #include "mbedtls/bignum.h"
#include <mbedtls/ctr_drbg.h> #include "mbedtls/ctr_drbg.h"
#include <mbedtls/hmac_drbg.h> #include "mbedtls/entropy.h"
#include <mbedtls/ecdh.h> #include "mbedtls/ecp.h"
#include <mbedtls/ecdsa.h> #include "mbedtls/ecdh.h"
#include <mbedtls/ecp.h> #include "mbedtls/ecdsa.h"
#include <mbedtls/rsa.h> #include "mbedtls/hmac_drbg.h"
#include <mbedtls/sha256.h> #include "mbedtls/hkdf.h"
#include "mbedtls/md.h"
#include "mbedtls/pk.h"
#include "mbedtls/rsa.h"
#include "mbedtls/sha1.h"
#include "mbedtls/sha256.h"
#include <mbedtls/md.h>
#include <mbedtls/pk.h>
#include <mbedtls/entropy.h>
#include "defines.h"
//firt generate ECC/RA key. //firt generate ECC/RA key.
//check for deterministic consistency //check for deterministic consistency
@ -32,33 +36,31 @@
void main() void main()
{ {
mbedtls_pk_context key; uint8_t* UDS_ID = calloc(1,sizeof(uint8_t)*UDS_DGST_SIZE);
mbedtls_entropy_context entropy; uint8_t* FW_ID = calloc(1,sizeof(uint8_t)*FW_DGST_SIZE);
mbedtls_ctr_drbg_context ctr_drbg; uint8_t* CD_ID = calloc(1,sizeof(uint8_t)*CDI_DGST_SIZE);
mbedtls_pk_type_t pk_alg = MBEDTLS_PK_ECKEY; uint8_t UDSbuf[UDS_SIZE] = {0Xe3,0xc5,0x58,0xaa,0x2f,0xd2,0x19,0x25};
uint8_t FWbuf[100] = {0Xe3,0xc5,0x58,0xaa,0x2f,0xd2,0x19,0x25,0Xe3,0xc5,0x58,0xaa,0x2f,0xd2,0x19,0x25,0Xe3,0xc5,0x58,0xaa,0x2f,0xd2,0x19,0x25,0Xe3,0xc5,0x58,0xaa,0x2f,0xd2,0x19,0x25,0Xe3,0xc5,0x58,0xaa,0x2f,0xd2,0x19,0x25,0Xe3,0xc5,0x58,0xaa,0x2f,0xd2,0x19,0x25,0Xe3,0xc5,0x58,0xaa,0x2f,0xd2,0x19,0x25,0Xe3,0xc5,0x58,0xaa,0x2f,0xd2,0x19,0x25,0Xe3,0xc5,0x58,0xaa,0x2f,0xd2,0x19,0x25,0Xe3,0xc5,0x58,0xaa,0x2f,0xd2,0x19,0x25,0Xe3,0xc5,0x58,0xaa,0x2f,0xd2,0x19,0x25,0Xe3,0xc5,0x58,0xaa,0x2f,0xd2,0x19,0x25};
mbedtls_pk_init(&key); mbedtls_sha256_ret( UDSbuf,UDS_SIZE,UDS_ID,0 );
mbedtls_entropy_init( &entropy ); mbedtls_sha256_ret(FWbuf,100,FW_ID,0 );
mbedtls_ctr_drbg_init(&ctr_drbg);
int ret = mbedtls_pk_setup(&key, mbedtls_pk_info_from_type(pk_alg)); for (int i = 0; i < 32; i++)
printf("%hhx", UDS_ID[i]);
printf(" : UDS ID\n" );
ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, for (int i = 0; i < 32; i++)
&entropy, printf("%hhx", FW_ID[i]);
(const unsigned char *) "ecdsa", printf(" : UDS ID\n" );
strlen(pers)
);
ret = mbedtls_ecp_gen_key(MBEDTLS_ECP_DP_SECP256R,
mbedtls_pk_ec(key),
mbedtls_ctr_drbg_random,
&ctr_drbg
);
printf("done\n\n");
printf("I wonder what the key is\n\n");
printf("key : %s", key)
printf("SUCCESSUL EXIT\n");
} }

View File

@ -46,7 +46,7 @@ int readFWID(uint8_t* FW_M)
// //2. Calcualte hash into arg // //2. Calcualte hash into arg
FILE *fp = NULL; FILE *fp = NULL;
fp = fopen("layer2.c", "r"); fp = fopen("layer1.c", "r");
if (!fp) if (!fp)
{ {
perror("File open failed\n"); perror("File open failed\n");

View File

@ -17,6 +17,9 @@ all: main.c layer1.c
debug: debug:
${CC} -g -o $(ODIR)/dbg-main main.c layer1.c layer2.c -lm -lmbedcrypto -lmbedtls -lmbedx509 ${CC} -g -o $(ODIR)/dbg-main main.c layer1.c layer2.c -lm -lmbedcrypto -lmbedtls -lmbedx509
trial:
${CC} -g -o $(ODIR)/trial ECCtrial.c layer1.c layer2.c -lm -lmbedcrypto -lmbedtls -lmbedx509
clean: clean:
rm -r $(ODIR)/* rm -r $(ODIR)/*
rm -r ./keys/* rm -r ./keys/*