X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilccrypt%2Fsilccipher.c;h=35155c5103379a048a8063340d4aba7892129a0c;hb=a818c5b5411bbc4436d1c5f011236985c96bb787;hp=fea377743ace559b038e2c6adf0f8e56d6baeb9a;hpb=fb8dbc2d9cd7ff5d197654f873ac18aa6ef9c5e3;p=silc.git diff --git a/lib/silccrypt/silccipher.c b/lib/silccrypt/silccipher.c index fea37774..35155c51 100644 --- a/lib/silccrypt/silccipher.c +++ b/lib/silccrypt/silccipher.c @@ -68,6 +68,15 @@ SilcCipherObject silc_default_ciphers[] = { "mars-128-cbc", 16, 128, silc_mars_set_key, silc_mars_set_key_with_string, silc_mars_encrypt_cbc, silc_mars_decrypt_cbc, silc_mars_context_len }, + { "cast-256-cbc", 16, 256, silc_cast_set_key, silc_cast_set_key_with_string, + silc_cast_encrypt_cbc, silc_cast_decrypt_cbc, + silc_cast_context_len }, + { "cast-192-cbc", 16, 192, silc_cast_set_key, silc_cast_set_key_with_string, + silc_cast_encrypt_cbc, silc_cast_decrypt_cbc, + silc_cast_context_len }, + { "cast-128-cbc", 16, 128, silc_cast_set_key, silc_cast_set_key_with_string, + silc_cast_encrypt_cbc, silc_cast_decrypt_cbc, + silc_cast_context_len }, { "none", 0, 0, silc_none_set_key, silc_none_set_key_with_string, silc_none_encrypt_cbc, silc_none_decrypt_cbc, silc_none_context_len }, @@ -86,6 +95,16 @@ bool silc_cipher_register(SilcCipherObject *cipher) SILC_LOG_DEBUG(("Registering new cipher `%s'", cipher->name)); + /* Check if exists already */ + if (silc_cipher_list) { + SilcCipherObject *entry; + silc_dlist_start(silc_cipher_list); + while ((entry = silc_dlist_get(silc_cipher_list)) != SILC_LIST_END) { + if (!strcmp(entry->name, cipher->name)) + return FALSE; + } + } + new = silc_calloc(1, sizeof(*new)); new->name = strdup(cipher->name); new->block_len = cipher->block_len; @@ -119,6 +138,8 @@ bool silc_cipher_unregister(SilcCipherObject *cipher) while ((entry = silc_dlist_get(silc_cipher_list)) != SILC_LIST_END) { if (cipher == SILC_ALL_CIPHERS || entry == cipher) { silc_dlist_del(silc_cipher_list, entry); + silc_free(entry->name); + silc_free(entry); if (silc_dlist_count(silc_cipher_list) == 0) { silc_dlist_uninit(silc_cipher_list); @@ -223,17 +244,16 @@ char *silc_cipher_get_supported(void) memcpy(list + len, ",", 1); len++; } + list[len - 1] = 0; } - list[len - 1] = 0; - return list; } /* Encrypts */ bool silc_cipher_encrypt(SilcCipher cipher, const unsigned char *src, - unsigned char *dst, uint32 len, + unsigned char *dst, SilcUInt32 len, unsigned char *iv) { return cipher->cipher->encrypt(cipher->context, src, dst, len, iv); @@ -242,7 +262,7 @@ bool silc_cipher_encrypt(SilcCipher cipher, const unsigned char *src, /* Decrypts */ bool silc_cipher_decrypt(SilcCipher cipher, const unsigned char *src, - unsigned char *dst, uint32 len, + unsigned char *dst, SilcUInt32 len, unsigned char *iv) { return cipher->cipher->decrypt(cipher->context, src, dst, len, iv); @@ -251,7 +271,7 @@ bool silc_cipher_decrypt(SilcCipher cipher, const unsigned char *src, /* Sets the key for the cipher */ bool silc_cipher_set_key(SilcCipher cipher, const unsigned char *key, - uint32 keylen) + SilcUInt32 keylen) { return cipher->cipher->set_key(cipher->context, key, keylen); } @@ -274,14 +294,14 @@ void silc_cipher_get_iv(SilcCipher cipher, unsigned char *iv) /* Returns the key length of the cipher. */ -uint32 silc_cipher_get_key_len(SilcCipher cipher) +SilcUInt32 silc_cipher_get_key_len(SilcCipher cipher) { return cipher->cipher->key_len; } /* Returns the block size of the cipher. */ -uint32 silc_cipher_get_block_len(SilcCipher cipher) +SilcUInt32 silc_cipher_get_block_len(SilcCipher cipher) { return cipher->cipher->block_len; }