43 {
47
49
50 const char *connector_url;
51
52 connector_url = getenv("DEFAULT_CONNECTOR_URL");
53 if (connector_url == NULL) {
55 }
56
59
62
65
67 sizeof(password),
false, &
session);
69
72
76
77 printf(
"Successfully established session %02d\n", session_id);
78
82
86
91
93
94 printf(
"Data to sign (%zu bytes) is: %s\n",
sizeof(data) - 1, data);
95
96 EVP_MD_CTX *
mdctx = NULL;
98 unsigned int hashed_data_len;
99
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);
106
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]);
110 }
112
114 size_t signature_len =
sizeof(
signature);
116 signature, &signature_len);
118
119 printf(
"Signature (%zu bytes) is:", signature_len);
120 for (unsigned int i = 0; i < signature_len; i++) {
121 printf(
" %02x", signature[i]);
122 }
124
126 size_t public_key_len = sizeof(public_key);
130
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]);
134 }
136
137 EC_KEY *eckey = EC_KEY_new();
140 EC_GROUP *group = EC_GROUP_new_by_curve_name(nid);
141
142 EC_GROUP_set_asn1_flag(group, nid);
143 EC_KEY_set_group(eckey, group);
144 point = EC_POINT_new(group);
145
146 memmove(public_key + 1, public_key, public_key_len);
147 public_key[0] = 0x04;
148 public_key_len++;
149
150 EC_POINT_oct2point(group,
point, public_key, public_key_len, NULL);
151
152 EC_KEY_set_public_key(eckey,
point);
153
154 if (ECDSA_verify(0, hashed_data, hashed_data_len, signature, signature_len,
155 eckey) == 1) {
156 printf(
"Signature successfully verified\n");
157 } else {
158 printf(
"Unable to verify signature\n");
159 }
160
161 EC_POINT_free(
point);
162 EC_KEY_free(eckey);
163 EC_GROUP_free(group);
164
167
170
173
176
177 return 0;
178}
CK_SESSION_HANDLE session
#define DEFAULT_CONNECTOR_URL
LOGGING_API void printf(Category category, const char *format,...)
fc::array< char, 72 > signature
Capabilities representation.
int algo2nid(yh_algorithm algo)
yh_rc yh_destroy_session(yh_session **session)
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)
yh_rc yh_util_close_session(yh_session *session)
yh_rc yh_authenticate_session(yh_session *session)
yh_rc yh_string_to_domains(const char *domains, uint16_t *result)
yh_rc yh_init_connector(const char *url, yh_connector **connector)
yh_rc yh_connect(yh_connector *connector, int timeout)
yh_rc yh_util_get_public_key(yh_session *session, uint16_t id, uint8_t *data, size_t *data_len, yh_algorithm *algorithm)
yh_rc yh_string_to_capabilities(const char *capability, yh_capabilities *result)
yh_rc yh_disconnect(yh_connector *connector)
yh_rc yh_get_session_id(yh_session *session, uint8_t *sid)
@ YHR_GENERIC_ERROR
Return value when encountering an unknown error.
@ YHR_SUCCESS
Returned value when function was successful.
yh_capabilities capabilities