Skip to content

Commit

Permalink
crypto: add assertion ecdsa key gen func
Browse files Browse the repository at this point in the history
  • Loading branch information
bonedaddy committed Nov 12, 2020
1 parent b3193f2 commit 63aae49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion include/crypto/ecdsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,9 @@ int libp2p_crypto_ecdsa_free(ecdsa_private_key_t *pk);
* @return Success: pointer to an instance of an ecdsa_private_key_t type
* @return Failure: NULL pointer
*/
ecdsa_private_key_t *libp2p_crypto_ecdsa_private_key_from_file(char *path);
ecdsa_private_key_t *libp2p_crypto_ecdsa_private_key_from_file(char *path);

/*!
* @brief generates a new ecdsa key asserting there is no error
*/
ecdsa_private_key_t *assert_new_ecdsa_private_key(void);
11 changes: 11 additions & 0 deletions src/crypto/ecdsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <assert.h>

/*!
* @brief frees up resources allocated for the private key
Expand Down Expand Up @@ -312,4 +313,14 @@ unsigned char *libp2p_crypto_ecdsa_private_key_to_pem(ecdsa_private_key_t *pk) {
memcpy(ret_buf, buffer, strlen((char *)buffer));

return ret_buf;
}

/*!
* @brief generates a new ecdsa key asserting there is no error
*/
ecdsa_private_key_t *assert_new_ecdsa_private_key(void) {
ecdsa_private_key_t *pk =
libp2p_crypto_ecdsa_keypair_generation(MBEDTLS_ECP_DP_SECP256R1);
assert(pk != NULL);
return pk;
}

0 comments on commit 63aae49

Please sign in to comment.