Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
- Copyright (C) 1997 - 2000 Pekka Riikonen
+ Copyright (C) 1997 - 2001 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
GNU General Public License for more details.
*/
-/*
- * $Id$
- * $Log$
- * Revision 1.1.1.1 2000/06/27 11:36:54 priikone
- * Importet from internal CVS/Added Log headers.
- *
- *
- */
+/* $Id$ */
#include "silcincludes.h"
/* Dynamically registered list of ciphers. */
struct SilcCipherListStruct *silc_cipher_list = NULL;
-/* XXX: add the other good ciphers here as well */
-
/* Staticly declared list of ciphers. This is used if system doesn't
support SIM's. */
SilcCipherObject silc_cipher_builtin_list[] =
{
- { "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 },
- { "twofish", 16, 16, silc_twofish_set_key, silc_twofish_set_key_with_string,
+ { "aes-256-cbc", 16, 256, silc_aes_set_key,
+ silc_aes_set_key_with_string, silc_aes_encrypt_cbc,
+ silc_aes_decrypt_cbc, silc_aes_context_len },
+ { "aes-192-cbc", 16, 192, silc_aes_set_key,
+ silc_aes_set_key_with_string, silc_aes_encrypt_cbc,
+ silc_aes_decrypt_cbc, silc_aes_context_len },
+ { "aes-128-cbc", 16, 128, silc_aes_set_key,
+ silc_aes_set_key_with_string, silc_aes_encrypt_cbc,
+ silc_aes_decrypt_cbc, silc_aes_context_len },
+ { "twofish-256-cbc", 16, 256, silc_twofish_set_key,
+ silc_twofish_set_key_with_string,
silc_twofish_encrypt_cbc, silc_twofish_decrypt_cbc,
silc_twofish_context_len },
- { "rc6", 16, 16, silc_rc6_set_key, silc_rc6_set_key_with_string,
+ { "twofish-192-cbc", 16, 192, silc_twofish_set_key,
+ silc_twofish_set_key_with_string,
+ silc_twofish_encrypt_cbc, silc_twofish_decrypt_cbc,
+ silc_twofish_context_len },
+ { "twofish-128-cbc", 16, 128, silc_twofish_set_key,
+ silc_twofish_set_key_with_string,
+ silc_twofish_encrypt_cbc, silc_twofish_decrypt_cbc,
+ silc_twofish_context_len },
+ { "rc6-256-cbc", 16, 256, silc_rc6_set_key, silc_rc6_set_key_with_string,
+ silc_rc6_encrypt_cbc, silc_rc6_decrypt_cbc,
+ silc_rc6_context_len },
+ { "rc6-192-cbc", 16, 192, silc_rc6_set_key, silc_rc6_set_key_with_string,
silc_rc6_encrypt_cbc, silc_rc6_decrypt_cbc,
silc_rc6_context_len },
- { "mars", 16, 16, silc_mars_set_key, silc_mars_set_key_with_string,
+ { "rc6-128-cbc", 16, 128, silc_rc6_set_key, silc_rc6_set_key_with_string,
+ silc_rc6_encrypt_cbc, silc_rc6_decrypt_cbc,
+ silc_rc6_context_len },
+ { "mars-256-cbc", 16, 256, silc_mars_set_key, silc_mars_set_key_with_string,
+ silc_mars_encrypt_cbc, silc_mars_decrypt_cbc,
+ silc_mars_context_len },
+ { "mars-192-cbc", 16, 192, silc_mars_set_key, silc_mars_set_key_with_string,
+ silc_mars_encrypt_cbc, silc_mars_decrypt_cbc,
+ silc_mars_context_len },
+ { "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 },
+ { "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 },
{ NULL, 0, 0, NULL, NULL, NULL, NULL, NULL }
};
{
struct SilcCipherListStruct *new, *c;
- SILC_LOG_DEBUG(("Registering new cipher"));
+ SILC_LOG_DEBUG(("Registering new cipher `%s'", cipher->name));
new = silc_calloc(1, sizeof(*new));
- if (!new) {
- SILC_LOG_ERROR(("Could not allocate new cipher list object: %s",
- strerror(errno)));
- return FALSE;
- }
-
new->cipher = silc_calloc(1, sizeof(*new->cipher));
- if (!new->cipher) {
- SILC_LOG_ERROR(("Could not allocate new cipher object: %s",
- strerror(errno)));
- return FALSE;
- }
/* Set the pointers */
new->cipher->name = strdup(cipher->name);
/* Allocate the new object */
*new_cipher = silc_calloc(1, sizeof(**new_cipher));
- if (*new_cipher == NULL) {
- SILC_LOG_ERROR(("Could not allocate new cipher object"));
- return FALSE;
- }
if (silc_cipher_list) {
c = c->next;
}
- if (!c)
+ if (!c || !c->cipher->context_len)
goto check_builtin;
/* Set the pointers */
if (silc_cipher_builtin_list[i].name == NULL) {
silc_free(*new_cipher);
+ *new_cipher = NULL;
return FALSE;
}
return list;
}
+/* Encrypts */
+
+int silc_cipher_encrypt(SilcCipher cipher, const unsigned char *src,
+ unsigned char *dst, uint32 len,
+ unsigned char *iv)
+{
+ return cipher->cipher->encrypt(cipher->context, src, dst, len, iv);
+}
+
+/* Decrypts */
+
+int silc_cipher_decrypt(SilcCipher cipher, const unsigned char *src,
+ unsigned char *dst, uint32 len,
+ unsigned char *iv)
+{
+ return cipher->cipher->decrypt(cipher->context, src, dst, len, iv);
+}
+
+/* Sets the key for the cipher */
+
+int silc_cipher_set_key(SilcCipher cipher, const unsigned char *key,
+ uint32 keylen)
+{
+ return cipher->cipher->set_key(cipher->context, key, keylen);
+}
+
/* Sets the IV (initial vector) for the cipher. */
-void silc_cipher_set_iv(SilcCipher itself, const unsigned char *iv)
+void silc_cipher_set_iv(SilcCipher cipher, const unsigned char *iv)
{
- memset(&itself->iv, 0, sizeof(itself->iv));
- memcpy(&itself->iv, iv, itself->cipher->block_len);
+ memset(&cipher->iv, 0, sizeof(cipher->iv));
+ memcpy(&cipher->iv, iv, cipher->cipher->block_len);
}
/* Returns the IV (initial vector) of the cipher. The IV is returned
to 'iv' argument. */
-void silc_cipher_get_iv(SilcCipher itself, unsigned char *iv)
+void silc_cipher_get_iv(SilcCipher cipher, unsigned char *iv)
{
- memcpy(iv, &itself->iv, itself->cipher->block_len);
+ memcpy(iv, &cipher->iv, cipher->cipher->block_len);
}
/* Returns the key length of the cipher. */
-/* XXX */
-unsigned int silc_cipher_get_key_len(SilcCipher itself,
- const unsigned char *name)
+uint32 silc_cipher_get_key_len(SilcCipher cipher)
{
-
- return TRUE;
+ return cipher->cipher->key_len;
}
/* Returns the block size of the cipher. */
-/* XXX */
-unsigned int silc_cipher_get_block_len(SilcCipher itself)
+uint32 silc_cipher_get_block_len(SilcCipher cipher)
{
-
- return TRUE;
+ return cipher->cipher->block_len;
}