50 const char *connector_url;
52 connector_url = getenv(
"DEFAULT_CONNECTOR_URL");
53 if (connector_url == NULL) {
67 sizeof(password),
false, &
session);
77 printf(
"Successfully established session %02d\n", session_id);
92 printf(
"Generated key with ID %04x\n",
key_id);
94 printf(
"Data to sign (%zu bytes) is: %s\n",
sizeof(data) - 1, data);
96 EVP_MD_CTX *
mdctx = NULL;
98 unsigned int hashed_data_len;
100 mdctx = EVP_MD_CTX_create();
101 assert(
mdctx != NULL);
102 EVP_DigestInit_ex(
mdctx, EVP_sha256(), NULL);
103 EVP_DigestUpdate(
mdctx, data,
sizeof(data) - 1);
104 EVP_DigestFinal_ex(
mdctx, hashed_data, &hashed_data_len);
105 EVP_MD_CTX_destroy(
mdctx);
107 printf(
"Hash of data (%d bytes) is:", EVP_MD_size(EVP_sha256()));
108 for (
unsigned int i = 0; i < hashed_data_len; i++) {
109 printf(
" %02x", hashed_data[i]);
114 size_t signature_len =
sizeof(signature);
116 signature, &signature_len);
119 printf(
"Signature (%zu bytes) is:", signature_len);
120 for (
unsigned int i = 0; i < signature_len; i++) {
121 printf(
" %02x", signature[i]);
126 size_t public_key_len =
sizeof(public_key);
131 printf(
"Public key (%zu bytes) is:", public_key_len);
132 for (
unsigned int i = 0; i < public_key_len; i++) {
133 printf(
" %02x", public_key[i]);
137 EC_KEY *eckey = EC_KEY_new();
140 EC_GROUP *group = EC_GROUP_new_by_curve_name(nid);
142 EC_GROUP_set_asn1_flag(group, nid);
143 EC_KEY_set_group(eckey, group);
144 point = EC_POINT_new(group);
146 memmove(public_key + 1, public_key, public_key_len);
147 public_key[0] = 0x04;
150 EC_POINT_oct2point(group,
point, public_key, public_key_len, NULL);
152 EC_KEY_set_public_key(eckey,
point);
154 if (ECDSA_verify(0, hashed_data, hashed_data_len, signature, signature_len,
156 printf(
"Signature successfully verified\n");
158 printf(
"Unable to verify signature\n");
161 EC_POINT_free(
point);
163 EC_GROUP_free(group);
yh_rc yh_util_generate_ec_key(yh_session *session, uint16_t *key_id, const char *label, uint16_t domains, const yh_capabilities *capabilities, yh_algorithm algorithm)
yh_rc yh_create_session_derived(yh_connector *connector, uint16_t authkey_id, const uint8_t *password, size_t password_len, bool recreate, yh_session **session)
yh_rc yh_util_sign_ecdsa(yh_session *session, uint16_t key_id, const uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len)