-static void silc_ske_packet_receive(SilcPacketEngine engine,
- SilcPacketStream stream,
- SilcPacket packet,
- void *callback_context,
- void *app_context);
-static void silc_ske_packet_eos(SilcPacketEngine engine,
- SilcPacketStream stream,
- void *callback_context,
- void *app_context);
-static void silc_ske_packet_error(SilcPacketEngine engine,
- SilcPacketStream stream,
- SilcPacketError error,
- void *callback_context,
- void *app_context);
-
-/* Structure to hold all SKE callbacks. */
-struct SilcSKECallbacksStruct {
- SilcSKEVerifyCb verify_key;
- SilcSKECheckVersionCb check_version;
- SilcSKECompletionCb completed;
- void *context;
-};
-
-/* Packet stream callbacks */
-static SilcPacketCallbacks silc_ske_stream_cbs =
-{
- silc_ske_packet_receive,
- silc_ske_packet_eos,
- silc_ske_packet_error
-};
-
-/* Allocates new SKE object. */
-
-SilcSKE silc_ske_alloc(SilcRng rng, SilcSchedule schedule, void *context)
-{
- SilcSKE ske;
-
- SILC_LOG_DEBUG(("Allocating new Key Exchange object"));
-
- if (!rng || !schedule)
- return NULL;
-
- ske = silc_calloc(1, sizeof(*ske));
- if (!ske)
- return NULL;
- ske->status = SILC_SKE_STATUS_OK;
- ske->rng = rng;
- ske->user_data = context;
- ske->schedule = schedule;
- ske->users = 1;
-
- return ske;
-}
-
-/* Free's SKE object. */
-
-void silc_ske_free(SilcSKE ske)
-{
- ske->users--;
- if (ske->users > 0) {
- SILC_LOG_DEBUG(("Key Exchange set to FREED status"));
- ske->status = SILC_SKE_STATUS_FREED;
- return;
- }
-
- SILC_LOG_DEBUG(("Freeing Key Exchange object"));
-
- if (ske) {
- /* Free start payload */
- if (ske->start_payload)
- silc_ske_payload_start_free(ske->start_payload);
-
- /* Free KE payload */
- if (ske->ke1_payload)
- silc_ske_payload_ke_free(ske->ke1_payload);
- if (ske->ke2_payload)
- silc_ske_payload_ke_free(ske->ke2_payload);
- silc_free(ske->remote_version);
-
- /* Free rest */
- if (ske->prop) {
- if (ske->prop->group)
- silc_ske_group_free(ske->prop->group);
- if (ske->prop->pkcs)
- silc_pkcs_free(ske->prop->pkcs);
- if (ske->prop->cipher)
- silc_cipher_free(ske->prop->cipher);
- if (ske->prop->hash)
- silc_hash_free(ske->prop->hash);
- if (ske->prop->hmac)
- silc_hmac_free(ske->prop->hmac);
- silc_free(ske->prop);
- }
- if (ske->start_payload_copy)
- silc_buffer_free(ske->start_payload_copy);
- if (ske->x) {
- silc_mp_uninit(ske->x);
- silc_free(ske->x);
- }
- if (ske->KEY) {
- silc_mp_uninit(ske->KEY);
- silc_free(ske->KEY);
- }
- silc_free(ske->hash);
- silc_free(ske->callbacks);