+static int
+silc_client_get_public_key_auth(SilcClient client,
+ char *filepath,
+ unsigned char *auth_data,
+ unsigned int *auth_data_len,
+ SilcSKE ske)
+{
+ int len;
+ SilcPKCS pkcs;
+ SilcBuffer auth;
+ SilcPublicKey pub_key;
+
+ if (!silc_pkcs_load_public_key(filepath,&pub_key, SILC_PKCS_FILE_PEM))
+ if (!silc_pkcs_load_public_key(filepath, &pub_key, SILC_PKCS_FILE_BIN))
+ return FALSE;
+
+ silc_pkcs_alloc(pub_key->name, &pkcs);
+ if (!silc_pkcs_public_key_set(pkcs, pub_key)) {
+ silc_pkcs_free(pkcs);
+ silc_pkcs_public_key_free(pub_key);
+ return FALSE;
+ }
+
+ /* Make the authentication data. Protocol says it is HASH plus
+ KE Start Payload. */
+ len = ske->hash_len + ske->start_payload_copy->len;
+ auth = silc_buffer_alloc(len);
+ silc_buffer_pull_tail(auth, len);
+ silc_buffer_format(auth,
+ SILC_STR_UI_XNSTRING(ske->hash, ske->hash_len),
+ SILC_STR_UI_XNSTRING(ske->start_payload_copy->data,
+ ske->start_payload_copy->len),
+ SILC_STR_END);
+
+ if (silc_pkcs_sign(pkcs, auth->data, auth->len, auth_data, auth_data_len)) {
+ silc_pkcs_free(pkcs);
+ silc_buffer_free(auth);
+ silc_pkcs_public_key_free(pub_key);
+ return TRUE;
+ }
+
+ silc_pkcs_free(pkcs);
+ silc_buffer_free(auth);
+ silc_pkcs_public_key_free(pub_key);
+ return FALSE;
+}
+