- /* Decode the HEX string to integer */
- silc_mp_init(&payload->e);
- silc_mp_bin2mp(e, e_len, &payload->e);
- memset(e, 0, sizeof(e_len));
- silc_free(e);
-
- /* Return the payload */
- *return_payload = payload;
-
- return SILC_SKE_STATUS_OK;
-
- err:
- silc_free(payload);
- return status;
-}
-
-/* Free's KE1 Payload */
-
-void silc_ske_payload_one_free(SilcSKEOnePayload *payload)
-{
- if (payload) {
- if (payload->pk_data)
- silc_free(payload->pk_data);
- silc_free(payload);
- }
-}
-
-/* Encodes Key Exchange 2 Payload into a SILC Buffer to be sent
- to the other end. */
-
-SilcSKEStatus silc_ske_payload_two_encode(SilcSKE ske,
- SilcSKETwoPayload *payload,
- SilcBuffer *return_buffer)
-{
- SilcBuffer buf;
- unsigned char *f_str;
- unsigned int f_len;
- unsigned int len;
-
- SILC_LOG_DEBUG(("Encoding KE 2 Payload"));
-
- if (!payload)
- return SILC_SKE_STATUS_ERROR;
-
- /* Encode the integer into HEX string */
- f_str = silc_mp_mp2bin(&payload->f, &f_len);
-
- /* Allocate channel payload buffer. The length of the buffer
- is 2 + 2 + public key + 2 + f + 2 + signature. */
- len = payload->pk_len + 2 + 2 + f_len + 2 + payload->sign_len + 2;
- buf = silc_buffer_alloc(len);
-
- silc_buffer_pull_tail(buf, len);
-
- /* Encode the payload */
- silc_buffer_format(buf,
- SILC_STR_UI_SHORT(payload->pk_len),
- SILC_STR_UI_SHORT(payload->pk_type),
- SILC_STR_UI_XNSTRING(payload->pk_data,
- payload->pk_len),
- SILC_STR_UI_SHORT(f_len),
- SILC_STR_UI_XNSTRING(f_str, f_len),
- SILC_STR_UI_SHORT(payload->sign_len),
- SILC_STR_UI_XNSTRING(payload->sign_data,
- payload->sign_len),
- SILC_STR_END);
-
- /* Return encoded buffer */
- *return_buffer = buf;
-
- memset(f_str, 'F', f_len);
- silc_free(f_str);
-
- return SILC_SKE_STATUS_OK;
-}
-
-/* Parses the Key Exchange 2 Payload. Parsed data is returned
- to allocated payload structure. */
-
-SilcSKEStatus silc_ske_payload_two_decode(SilcSKE ske,
- SilcBuffer buffer,
- SilcSKETwoPayload **return_payload)
-{
- SilcSKEStatus status = SILC_SKE_STATUS_ERROR;
- SilcSKETwoPayload *payload;
- unsigned char *f;
- unsigned short f_len;
- unsigned int tot_len = 0, len2;
-
- SILC_LOG_DEBUG(("Decoding Key Exchange 2 Payload"));
-
- SILC_LOG_HEXDUMP(("KE 2 Payload"), buffer->data, buffer->len);
-
- payload = silc_calloc(1, sizeof(*payload));
- memset(buf, 0, sizeof(buf));
-
- len2 = buffer->len;
-
- /* Parse the payload */
- silc_buffer_unformat(buffer,
- SILC_STR_UI_SHORT(&payload->pk_len),
- SILC_STR_UI_SHORT(&payload->pk_type),
- SILC_STR_END);