From 9754d6631d99e8b8f2d540af96d43e52f63c0860 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 24 Nov 2002 16:28:06 +0000 Subject: [PATCH] If if argument is NULL, use cipher's internal IV automatically. --- CHANGES | 6 ++++++ lib/silccore/silcmessage.c | 5 ++--- lib/silccore/silcpacket.c | 10 ++++------ lib/silccrypt/silccipher.c | 6 ++++-- lib/silccrypt/silccipher.h | 6 ++++-- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGES b/CHANGES index 69d1d07f..8985607d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +Sun Nov 24 18:26:42 EET 2002 Pekka Riikonen + + * If iv argument to silc_cipher_[encrypt/decrypt] is NULL, use + automatically the cipher's internal IV. Affected files + lib/silccrypt/silccipher.[ch]. + Fri Nov 22 18:34:20 EET 2002 Pekka Riikonen * Added support to backup router protocol for backup to tell diff --git a/lib/silccore/silcmessage.c b/lib/silccore/silcmessage.c index f1fbe932..e3fd64f9 100644 --- a/lib/silccore/silcmessage.c +++ b/lib/silccore/silcmessage.c @@ -98,8 +98,7 @@ bool silc_message_payload_decrypt(unsigned char *data, /* Decrypt the message */ silc_cipher_decrypt(cipher, data, data, data_len - iv_len - mac_len, - (iv_len ? data + (data_len - iv_len - mac_len) : - silc_cipher_get_iv(cipher))); + (iv_len ? data + (data_len - iv_len - mac_len) : NULL)); return TRUE; } @@ -191,7 +190,7 @@ bool silc_message_payload_encrypt(unsigned char *data, /* Encrypt payload of the packet. If the IV is added to packet do not encrypt that. */ silc_cipher_encrypt(cipher, data, data, data_len - iv_len, - iv_len ? iv : silc_cipher_get_iv(cipher)); + iv_len ? iv : NULL); /* Compute the MAC of the encrypted message data */ silc_hmac_init(hmac); diff --git a/lib/silccore/silcpacket.c b/lib/silccore/silcpacket.c index fbbb4a69..0c3bcb91 100644 --- a/lib/silccore/silcpacket.c +++ b/lib/silccore/silcpacket.c @@ -85,8 +85,7 @@ void silc_packet_encrypt(SilcCipher cipher, SilcHmac hmac, SilcUInt32 sequence, if (cipher) { SILC_LOG_DEBUG(("Encrypting packet, cipher %s, len %d", silc_cipher_get_name(cipher), len)); - silc_cipher_encrypt(cipher, buffer->data, buffer->data, len, - silc_cipher_get_iv(cipher)); + silc_cipher_encrypt(cipher, buffer->data, buffer->data, len, NULL); } /* Compute HMAC. This assumes that MAC is computed from the entire @@ -502,8 +501,8 @@ static int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac, if (cipher) { /* Decrypt rest of the packet */ SILC_LOG_DEBUG(("Decrypting the packet")); - silc_cipher_decrypt(cipher, buffer->data, buffer->data, buffer->len, - silc_cipher_get_iv(cipher)); + silc_cipher_decrypt(cipher, buffer->data, buffer->data, buffer->len, + NULL); } return 0; @@ -528,8 +527,7 @@ static int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac, return -1; } silc_buffer_pull(buffer, block_len); - silc_cipher_decrypt(cipher, buffer->data, buffer->data, len, - silc_cipher_get_iv(cipher)); + silc_cipher_decrypt(cipher, buffer->data, buffer->data, len, NULL); } return 1; diff --git a/lib/silccrypt/silccipher.c b/lib/silccrypt/silccipher.c index b233e3f9..72d984b3 100644 --- a/lib/silccrypt/silccipher.c +++ b/lib/silccrypt/silccipher.c @@ -315,7 +315,8 @@ bool silc_cipher_encrypt(SilcCipher cipher, const unsigned char *src, unsigned char *dst, SilcUInt32 len, unsigned char *iv) { - return cipher->cipher->encrypt(cipher->context, src, dst, len, iv); + return cipher->cipher->encrypt(cipher->context, src, dst, len, + iv ? iv : cipher->iv); } /* Decrypts */ @@ -324,7 +325,8 @@ bool silc_cipher_decrypt(SilcCipher cipher, const unsigned char *src, unsigned char *dst, SilcUInt32 len, unsigned char *iv) { - return cipher->cipher->decrypt(cipher->context, src, dst, len, iv); + return cipher->cipher->decrypt(cipher->context, src, dst, len, + iv ? iv : cipher->iv); } /* Sets the key for the cipher */ diff --git a/lib/silccrypt/silccipher.h b/lib/silccrypt/silccipher.h index dd5541a7..95478d2e 100644 --- a/lib/silccrypt/silccipher.h +++ b/lib/silccrypt/silccipher.h @@ -241,7 +241,8 @@ char *silc_cipher_get_supported(void); * DESCRIPTION * * Encrypts data from `src' into `dst' with the specified cipher and - * Initial Vector (IV). The `src' and `dst' maybe same buffer. + * Initial Vector (IV). If the `iv' is NULL then the cipher's internal + * IV is used. The `src' and `dst' maybe same buffer. * ***/ bool silc_cipher_encrypt(SilcCipher cipher, const unsigned char *src, @@ -259,7 +260,8 @@ bool silc_cipher_encrypt(SilcCipher cipher, const unsigned char *src, * DESCRIPTION * * Decrypts data from `src' into `dst' with the specified cipher and - * Initial Vector (IV). The `src' and `dst' maybe same buffer. + * Initial Vector (IV). If the `iv' is NULL then the cipher's internal + * IV is used. The `src' and `dst' maybe same buffer. * ***/ bool silc_cipher_decrypt(SilcCipher cipher, const unsigned char *src, -- 2.24.0