- /* Return encoded buffer */
- *return_buffer = buf;
-
- memset(e_str, 'F', e_len);
- silc_free(e_str);
-
- return SILC_SKE_STATUS_OK;
-}
-
-/* Parses the Key Exchange 1 Payload. Parsed data is returned
- to allocated payload structure. */
-
-SilcSKEStatus silc_ske_payload_one_decode(SilcSKE ske,
- SilcBuffer buffer,
- SilcSKEOnePayload **return_payload)
-{
- SilcSKEOnePayload *payload;
- SilcSKEStatus status = SILC_SKE_STATUS_ERROR;
- unsigned char *e;
- unsigned short e_len;
- int ret;
-
- SILC_LOG_DEBUG(("Decoding Key Exchange 1 Payload"));
-
- SILC_LOG_HEXDUMP(("KE 1 Payload"), buffer->data, buffer->len);
-
- payload = silc_calloc(1, sizeof(*payload));
-
- /* Parse start of the payload */
- ret = silc_buffer_unformat(buffer,
- SILC_STR_UI_SHORT(&payload->pk_len),
- SILC_STR_UI_SHORT(&payload->pk_type),
- SILC_STR_END);
- if (ret == -1) {
- status = SILC_SKE_STATUS_ERROR;
- goto err;
- }
-
- if (payload->pk_len < 5) {
- status = SILC_SKE_STATUS_BAD_PAYLOAD;
- goto err;
- }
-
- /* Parse public key data */
- silc_buffer_pull(buffer, 2 + 2);
- ret = silc_buffer_unformat(buffer,
- SILC_STR_UI_XNSTRING_ALLOC(&payload->pk_data,
- payload->pk_len),
- SILC_STR_UI16_NSTRING_ALLOC(&e, &e_len),
- SILC_STR_END);
- if (ret == -1) {
- status = SILC_SKE_STATUS_ERROR;
- goto err;
- }
-
- if (e_len < 3) {
- status = SILC_SKE_STATUS_BAD_PAYLOAD;
- goto err;
- }
-
- silc_buffer_push(buffer, 2 + 2);
-
- if (payload->pk_len + 2 + 2 + 2 + e_len != buffer->len) {
- status = SILC_SKE_STATUS_BAD_PAYLOAD;
- goto err;
- }
-
- /* 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);
- ske->status = status;
- 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;
- int ret;
-
- 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, 0, &f_len);