-int ecdsa_signature_create(uint8_t *key_d, uint8_t *key_xy, uint8_t *input, int length, uint8_t *signature, size_t *signaturelen) {
+
+int ecdsa_public_key_from_pk(mbedtls_pk_context *pk, mbedtls_ecp_group_id curveID, uint8_t *key, size_t keylen) {
+ int res = 0;
+ size_t realkeylen = 0;
+
+ mbedtls_ecdsa_context ctx;
+ mbedtls_ecdsa_init(&ctx);
+
+ res = mbedtls_ecp_group_load(&ctx.grp, curveID);
+ if (res)
+ goto exit;
+
+ size_t private_keylen = (ctx.grp.nbits + 7) / 8;
+ if (keylen < 1 + 2 * private_keylen) {
+ res = 1;
+ goto exit;
+ }
+
+ res = mbedtls_ecdsa_from_keypair(&ctx, mbedtls_pk_ec(*pk) );
+ if (res)
+ goto exit;
+
+ res = mbedtls_ecp_point_write_binary(&ctx.grp, &ctx.Q, MBEDTLS_ECP_PF_UNCOMPRESSED, &realkeylen, key, keylen);
+ if (realkeylen != 1 + 2 * private_keylen)
+ res = 2;
+exit:
+ mbedtls_ecdsa_free(&ctx);
+ return res;
+}
+
+
+int ecdsa_signature_create(mbedtls_ecp_group_id curveID, uint8_t *key_d, uint8_t *key_xy, uint8_t *input, int length, uint8_t *signature, size_t *signaturelen, bool hash) {