ske->public_key = public_key;
ske->private_key = private_key;
ske->retry_timer = SILC_SKE_RETRY_MIN;
+ ske->refcnt = 1;
return ske;
}
return;
}
+ ske->refcnt--;
+ if (ske->refcnt > 0)
+ return;
+
/* Free start payload */
if (ske->start_payload)
silc_ske_payload_start_free(ske->start_payload);
SilcHash *ret_hash)
{
unsigned char iv[32];
+ SilcBool iv_included = (prop->flags & SILC_SKE_SP_FLAG_IV_INCLUDED);
/* Allocate ciphers to be used in the communication */
if (ret_send_key) {
if (silc_cipher_get_mode(*ret_send_key) == SILC_CIPHER_MODE_CTR) {
memcpy(iv, ske->hash, 4);
- memcpy(iv + 4, keymat->receive_iv, 4);
+ memcpy(iv + 4, keymat->receive_iv, iv_included ? 4 : 8);
silc_cipher_set_iv(*ret_send_key, iv);
} else {
silc_cipher_set_iv(*ret_send_key, keymat->receive_iv);
if (silc_cipher_get_mode(*ret_receive_key) == SILC_CIPHER_MODE_CTR) {
memcpy(iv, ske->hash, 4);
- memcpy(iv + 4, keymat->send_iv, 4);
+ memcpy(iv + 4, keymat->send_iv, iv_included ? 4 : 8);
silc_cipher_set_iv(*ret_receive_key, iv);
} else {
silc_cipher_set_iv(*ret_receive_key, keymat->send_iv);
if (silc_cipher_get_mode(*ret_send_key) == SILC_CIPHER_MODE_CTR) {
memcpy(iv, ske->hash, 4);
- memcpy(iv + 4, keymat->send_iv, 4);
+ memcpy(iv + 4, keymat->send_iv, iv_included ? 4 : 8);
silc_cipher_set_iv(*ret_send_key, iv);
} else {
silc_cipher_set_iv(*ret_send_key, keymat->send_iv);
if (silc_cipher_get_mode(*ret_receive_key) == SILC_CIPHER_MODE_CTR) {
memcpy(iv, ske->hash, 4);
- memcpy(iv + 4, keymat->receive_iv, 4);
+ memcpy(iv + 4, keymat->receive_iv, iv_included ? 4 : 8);
silc_cipher_set_iv(*ret_receive_key, iv);
} else {
silc_cipher_set_iv(*ret_receive_key, keymat->receive_iv);