rpi experiemnt
This commit is contained in:
parent
57a7e2b287
commit
3063768ac2
@ -1,22 +1,26 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include<mbedtls/config.h>
|
||||
#include "mbedtls/config.h"
|
||||
|
||||
#include <mbedtls/aes.h>
|
||||
#include <mbedtls/bignum.h>
|
||||
#include <mbedtls/ctr_drbg.h>
|
||||
#include <mbedtls/hmac_drbg.h>
|
||||
#include <mbedtls/ecdh.h>
|
||||
#include <mbedtls/ecdsa.h>
|
||||
#include <mbedtls/ecp.h>
|
||||
#include <mbedtls/rsa.h>
|
||||
#include <mbedtls/sha256.h>
|
||||
#include "mbedtls/aes.h"
|
||||
#include "mbedtls/bignum.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ecp.h"
|
||||
#include "mbedtls/ecdh.h"
|
||||
#include "mbedtls/ecdsa.h"
|
||||
#include "mbedtls/hmac_drbg.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.
|
||||
//check for deterministic consistency
|
||||
@ -32,33 +36,31 @@
|
||||
void main()
|
||||
{
|
||||
|
||||
mbedtls_pk_context key;
|
||||
mbedtls_entropy_context entropy;
|
||||
mbedtls_ctr_drbg_context ctr_drbg;
|
||||
uint8_t* UDS_ID = calloc(1,sizeof(uint8_t)*UDS_DGST_SIZE);
|
||||
uint8_t* FW_ID = calloc(1,sizeof(uint8_t)*FW_DGST_SIZE);
|
||||
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_entropy_init( &entropy );
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
mbedtls_sha256_ret( UDSbuf,UDS_SIZE,UDS_ID,0 );
|
||||
mbedtls_sha256_ret(FWbuf,100,FW_ID,0 );
|
||||
|
||||
|
||||
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,
|
||||
&entropy,
|
||||
(const unsigned char *) "ecdsa",
|
||||
strlen(pers)
|
||||
);
|
||||
|
||||
ret = mbedtls_ecp_gen_key(MBEDTLS_ECP_DP_SECP256R,
|
||||
mbedtls_pk_ec(key),
|
||||
mbedtls_ctr_drbg_random,
|
||||
&ctr_drbg
|
||||
);
|
||||
for (int i = 0; i < 32; i++)
|
||||
printf("%hhx", FW_ID[i]);
|
||||
printf(" : UDS ID\n" );
|
||||
|
||||
|
||||
printf("done\n\n");
|
||||
printf("I wonder what the key is\n\n");
|
||||
printf("key : %s", key)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
printf("SUCCESSUL EXIT\n");
|
||||
|
||||
}
|
@ -46,7 +46,7 @@ int readFWID(uint8_t* FW_M)
|
||||
// //2. Calcualte hash into arg
|
||||
|
||||
FILE *fp = NULL;
|
||||
fp = fopen("layer2.c", "r");
|
||||
fp = fopen("layer1.c", "r");
|
||||
if (!fp)
|
||||
{
|
||||
perror("File open failed\n");
|
||||
|
@ -17,6 +17,9 @@ all: main.c layer1.c
|
||||
debug:
|
||||
${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:
|
||||
rm -r $(ODIR)/*
|
||||
rm -r ./keys/*
|
||||
|
Loading…
Reference in New Issue
Block a user