37 {
41
43
44 const char *connector_url;
45
46 connector_url = getenv("DEFAULT_CONNECTOR_URL");
47 if (connector_url == NULL) {
49 }
50
53
56
59
61 sizeof(password),
false, &
session);
63
66
70
71 printf(
"Successfully established session %02d using Authentication Key "
72 "%04x\n",
73 session_id, authkey);
74
78
82
87
88 printf(
"Generated HMAC-SHA256 key with ID %04x\n",
key_id);
89
91 size_t hmac_data_len = sizeof(hmac_data);
93 &hmac_data_len);
95
96 printf(
"HMAC of data (%zu bytes) is:", hmac_data_len);
97 for (
uint16_t i = 0; i < hmac_data_len; i++) {
98 printf(
" %02x", hmac_data[i]);
99 }
101
102 bool verified;
104 sizeof(data) - 1, &verified);
106
107 if (verified == true) {
108 printf(
"Successfully verified HMAC\n");
109 } else {
110 printf(
"Unable to verify HMAC\n");
111 }
112
113 hmac_data[0] += 1;
115 sizeof(data) - 1, &verified);
117
118 if (verified == true) {
119 printf(
"Successfully verified HMAC\n");
120 } else {
121 printf(
"Unable to verify HMAC\n");
122 }
123
126
129
132
135
136 return 0;
137}
CK_SESSION_HANDLE session
#define DEFAULT_CONNECTOR_URL
LOGGING_API void printf(Category category, const char *format,...)
Capabilities representation.
yh_rc yh_destroy_session(yh_session **session)
yh_rc yh_util_generate_hmac_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_close_session(yh_session *session)
yh_rc yh_authenticate_session(yh_session *session)
yh_rc yh_util_sign_hmac(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_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_string_to_capabilities(const char *capability, yh_capabilities *result)
yh_rc yh_disconnect(yh_connector *connector)
yh_rc yh_util_verify_hmac(yh_session *session, uint16_t key_id, const uint8_t *signature, size_t signature_len, const uint8_t *data, size_t data_len, bool *verified)
yh_rc yh_get_session_id(yh_session *session, uint8_t *sid)
@ YH_ALGO_HMAC_SHA256
hmac-sha256
@ YHR_GENERIC_ERROR
Return value when encountering an unknown error.
@ YHR_SUCCESS
Returned value when function was successful.
yh_capabilities capabilities