Write private key

This commit is contained in:
2024-08-15 13:09:01 +02:00
parent 402edb44d5
commit 752bf50ad3
5 changed files with 69 additions and 9 deletions

View File

@ -1,5 +1,7 @@
#include "crypto.h"
#include "system.h"
#include "constants.h"
#include "storage.h"
#include <string.h>
#include <mbedtls/build_info.h>
@ -10,9 +12,6 @@
#include <mbedtls/sha256.h>
#include <mbedtls/pk.h>
/*
* Uncomment to force use of a specific curve
*/
#define ECPARAMS MBEDTLS_ECP_DP_SECP256R1
bool crypto_gen_priv_key()
@ -60,7 +59,23 @@ bool crypto_gen_priv_key()
reboot();
}
// Show private key
// Export private key
printf("Export private key\n");
unsigned char *key_buff = malloc(PRV_KEY_DER_MAX_BYTES);
if ((ret = mbedtls_pk_write_key_der(&key, key_buff, PRV_KEY_DER_MAX_BYTES)) < 1)
{
mbedtls_printf(" failed\n ! mbedtls_pk_write_key_der returned -0x%04x",
(unsigned int)-ret);
reboot();
}
storage_set_priv_key(key_buff + PRV_KEY_DER_MAX_BYTES - ret, ret);
return true;
}
/**
* // Show private key
printf("Show private key\n");
unsigned char *key_buff = malloc(16000);
memset(key_buff, 0, 16000);
@ -74,6 +89,4 @@ bool crypto_gen_priv_key()
printf("%s", key_buff);
free(key_buff);
printf("done\n");
return true;
}
*/