From b380893d96cb8d673cdd57a2383195903078ce7d Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Thu, 24 Oct 2002 12:18:58 +0000 Subject: [PATCH] ROBODoc documented lib/silcrypt/silccipher.h. Patch by Toni Willberg. Changed the SilcCipher to be private context. --- CHANGES | 10 + TODO | 4 - apps/irssi/src/silc/core/client_ops.c | 5 +- apps/irssi/src/silc/core/silc-channels.c | 5 +- apps/silcd/command.c | 10 +- apps/silcd/packet_receive.c | 22 +- apps/silcd/packet_send.c | 7 +- apps/silcd/protocol.c | 11 +- apps/silcd/server_util.c | 4 +- lib/silcclient/client_prvmsg.c | 8 +- lib/silcclient/protocol.c | 5 +- lib/silccore/silcpacket.c | 13 +- lib/silccore/silcprivate.c | 4 +- lib/silccrypt/silccipher.c | 25 ++- lib/silccrypt/silccipher.h | 274 ++++++++++++++++++++--- 15 files changed, 321 insertions(+), 86 deletions(-) diff --git a/CHANGES b/CHANGES index c6aafe36..9a49a529 100644 --- a/CHANGES +++ b/CHANGES @@ -11,6 +11,16 @@ Thu Oct 24 12:22:35 EEST 2002 Pekka Riikonen channel message with wrong key during backup resuming protocol. Affected file silcd/packet_send.c. + * ROBODoc documented lib/silccrypt/silccipher.h. A patch by + Toni Willberg (toniw@iki.fi) + + * Changed the SilcCipher context to be private. Changed the + silc_cipher_get_iv to just return pointer to the IV. Added + silc_cipher_get_name to return the name of the cipher. + Fixed code all around to support these changes. Affected + files are lib/silccrypt/silccipher.[ch], client library and + server. + Wed Oct 23 19:01:41 EEST 2002 Pekka Riikonen * Fixed unaligned access in lib/silccore/silcattrs.c. diff --git a/TODO b/TODO index 5bf5a171..69513cff 100644 --- a/TODO +++ b/TODO @@ -44,10 +44,6 @@ TODO in Toolkit Documentation Stuff that needs to be done in order to complete the Tooolkit Reference Manual (Do these to 0.9.x). - o ROBOdoc documenting missing from lib/silcutil/silcfileutil.h. - - o ROBOdoc documenting missing from lib/silccrypt/silccipher.h. - o Write "Programming with Toolkit" document, describing how to build Toolkit, how the build system works, where is everything, how new (external) projects can be glued into Toolkit (use irssi as an diff --git a/apps/irssi/src/silc/core/client_ops.c b/apps/irssi/src/silc/core/client_ops.c index 484c2e49..491f776d 100644 --- a/apps/irssi/src/silc/core/client_ops.c +++ b/apps/irssi/src/silc/core/client_ops.c @@ -486,7 +486,7 @@ void silc_notify(SilcClient client, SilcClientConnection conn, tmp = silc_client_chmode(mode, channel->channel_key ? - channel->channel_key->cipher->name : "", + silc_cipher_get_name(channel->channel_key) : "", channel->hmac ? silc_hmac_get_name(channel->hmac) : ""); @@ -1314,7 +1314,8 @@ silc_command_reply(SilcClient client, SilcClientConnection conn, mode = silc_client_chmode(modei, channel_entry->channel_key ? - channel_entry->channel_key->cipher->name : "", + silc_cipher_get_name(channel_entry-> + channel_key) : "", channel_entry->hmac ? silc_hmac_get_name(channel_entry->hmac) : ""); g_free_not_null(chanrec->mode); diff --git a/apps/irssi/src/silc/core/silc-channels.c b/apps/irssi/src/silc/core/silc-channels.c index 04dd65d7..005763bf 100644 --- a/apps/irssi/src/silc/core/silc-channels.c +++ b/apps/irssi/src/silc/core/silc-channels.c @@ -811,8 +811,9 @@ static void command_key(const char *data, SILC_SERVER_REC *server, memset(buf, 0, sizeof(buf)); strncat(buf, " ", 2); - len = strlen(keys[k]->cipher->cipher->name); - strncat(buf, keys[k]->cipher->cipher->name, len > 16 ? 16 : len); + len = strlen(silc_cipher_get_name(keys[k]->cipher)); + strncat(buf, silc_cipher_get_name(keys[k]->cipher), + len > 16 ? 16 : len); if (len < 16) for (i = 0; i < 16 - len; i++) strcat(buf, " "); diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 4e7a9c79..82231d23 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -1707,6 +1707,7 @@ static void silc_server_command_join_channel(SilcServer server, bool resolve; unsigned char *fkey = NULL; SilcUInt32 fkey_len = 0; + const char *cipher; SILC_LOG_DEBUG(("Joining client to channel")); @@ -1917,12 +1918,11 @@ static void silc_server_command_join_channel(SilcServer server, if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) { tmp = silc_id_id2str(channel->id, SILC_ID_CHANNEL); + cipher = silc_cipher_get_name(channel->channel_key); keyp = silc_channel_key_payload_encode(silc_id_get_len(channel->id, SILC_ID_CHANNEL), tmp, - strlen(channel->channel_key-> - cipher->name), - channel->channel_key->cipher->name, + strlen(cipher), cipher, channel->key_len / 8, channel->key); silc_free(tmp); } @@ -2611,8 +2611,8 @@ SILC_SERVER_CMD_FUNC(cmode) silc_server_send_channel_key(server, NULL, channel, server->server_type == SILC_ROUTER ? FALSE : !server->standalone); - - cipher = channel->channel_key->cipher->name; + + cipher = (char *)silc_cipher_get_name(channel->channel_key); hmac = (char *)silc_hmac_get_name(channel->hmac); } } diff --git a/apps/silcd/packet_receive.c b/apps/silcd/packet_receive.c index bb778149..ae59c11b 100644 --- a/apps/silcd/packet_receive.c +++ b/apps/silcd/packet_receive.c @@ -2860,9 +2860,10 @@ void silc_server_new_channel(SilcServer server, char *channel_name; SilcUInt32 name_len; unsigned char *id; - SilcUInt32 id_len; + SilcUInt32 id_len, cipher_len; SilcServerEntry server_entry; SilcChannelEntry channel; + const char *cipher; if (sock->type == SILC_SOCKET_TYPE_CLIENT || packet->src_id_type != SILC_ID_SERVER || @@ -2983,10 +2984,10 @@ void silc_server_new_channel(SilcServer server, /* Send the new channel key to the server */ id = silc_id_id2str(channel->id, SILC_ID_CHANNEL); id_len = silc_id_get_len(channel->id, SILC_ID_CHANNEL); + cipher = silc_cipher_get_name(channel->channel_key); + cipher_len = strlen(cipher); chk = silc_channel_key_payload_encode(id_len, id, - strlen(channel->channel_key-> - cipher->name), - channel->channel_key->cipher->name, + cipher_len, cipher, channel->key_len / 8, channel->key); silc_server_packet_send(server, sock, SILC_PACKET_CHANNEL_KEY, 0, @@ -3049,11 +3050,10 @@ void silc_server_new_channel(SilcServer server, /* Send to the server */ id = silc_id_id2str(channel->id, SILC_ID_CHANNEL); id_len = silc_id_get_len(channel->id, SILC_ID_CHANNEL); + cipher = silc_cipher_get_name(channel->channel_key); + cipher_len = strlen(cipher); chk = silc_channel_key_payload_encode(id_len, id, - strlen(channel->channel_key-> - cipher->name), - channel->channel_key-> - cipher->name, + cipher_len, cipher, channel->key_len / 8, channel->key); silc_server_packet_send(server, sock, SILC_PACKET_CHANNEL_KEY, 0, @@ -3436,6 +3436,7 @@ void silc_server_resume_client(SilcServer server, SilcHashTableList htl; SilcChannelClientEntry chl; SilcServerResumeResolve r; + const char *cipher; ret = silc_buffer_unformat(buffer, SILC_STR_UI16_NSTRING(&id_string, &id_len), @@ -3764,13 +3765,12 @@ void silc_server_resume_client(SilcServer server, } id_string = silc_id_id2str(channel->id, SILC_ID_CHANNEL); + cipher = silc_cipher_get_name(channel->channel_key); keyp = silc_channel_key_payload_encode(silc_id_get_len(channel->id, SILC_ID_CHANNEL), id_string, - strlen(channel->channel_key-> - cipher->name), - channel->channel_key->cipher->name, + strlen(cipher), cipher, channel->key_len / 8, channel->key); silc_free(id_string); diff --git a/apps/silcd/packet_send.c b/apps/silcd/packet_send.c index 49d12c7b..2a5118cc 100644 --- a/apps/silcd/packet_send.c +++ b/apps/silcd/packet_send.c @@ -1780,6 +1780,7 @@ void silc_server_send_channel_key(SilcServer server, SilcBuffer packet; unsigned char *chid; SilcUInt32 tmp_len; + const char *cipher; SILC_LOG_DEBUG(("Sending key to channel %s", channel->channel_name)); @@ -1791,11 +1792,11 @@ void silc_server_send_channel_key(SilcServer server, return; /* Encode channel key packet */ - tmp_len = strlen(channel->channel_key->cipher->name); + cipher = silc_cipher_get_name(channel->channel_key); + tmp_len = strlen(cipher); packet = silc_channel_key_payload_encode(silc_id_get_len(channel->id, SILC_ID_CHANNEL), - chid, tmp_len, - channel->channel_key->cipher->name, + chid, tmp_len, cipher, channel->key_len / 8, channel->key); silc_server_packet_send_to_channel(server, sender, channel, SILC_PACKET_CHANNEL_KEY, diff --git a/apps/silcd/protocol.c b/apps/silcd/protocol.c index 8770fc0f..e0d82738 100644 --- a/apps/silcd/protocol.c +++ b/apps/silcd/protocol.c @@ -219,6 +219,7 @@ int silc_server_protocol_ke_set_keys(SilcServer server, { SilcUnknownEntry conn_data; SilcIDListData idata; + const char *cname = silc_cipher_get_name(cipher); SILC_LOG_DEBUG(("Setting new keys into use")); @@ -226,14 +227,14 @@ int silc_server_protocol_ke_set_keys(SilcServer server, idata = (SilcIDListData)conn_data; /* Allocate cipher to be used in the communication */ - if (!silc_cipher_alloc(cipher->cipher->name, &idata->send_key)) { + if (!silc_cipher_alloc((char *)cname, &idata->send_key)) { silc_free(conn_data); - SILC_LOG_ERROR(("Cannot allocate algorithm: %s", cipher->cipher->name)); + SILC_LOG_ERROR(("Cannot allocate algorithm: %s", cname)); return FALSE; } - if (!silc_cipher_alloc(cipher->cipher->name, &idata->receive_key)) { + if (!silc_cipher_alloc((char *)cname, &idata->receive_key)) { silc_free(conn_data); - SILC_LOG_ERROR(("Cannot allocate algorithm: %s", cipher->cipher->name)); + SILC_LOG_ERROR(("Cannot allocate algorithm: %s", cname)); return FALSE; } @@ -314,7 +315,7 @@ int silc_server_protocol_ke_set_keys(SilcServer server, SILC_LOG_INFO(("%s (%s) security properties: %s %s %s %s", sock->hostname, sock->ip, - idata->send_key->cipher->name, + silc_cipher_get_name(idata->send_key), (char *)silc_hmac_get_name(idata->hmac_send), silc_hash_get_name(idata->hash), ske->prop->flags & SILC_SKE_SP_FLAG_PFS ? "PFS" : "")); diff --git a/apps/silcd/server_util.c b/apps/silcd/server_util.c index 74a4d7e5..da9f695f 100644 --- a/apps/silcd/server_util.c +++ b/apps/silcd/server_util.c @@ -1456,8 +1456,8 @@ void silc_server_send_connect_notifys(SilcServer server, SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE, ("Your connection is secured with %s cipher, " "key length %d bits", - idata->send_key->cipher->name, - idata->send_key->cipher->key_len)); + silc_cipher_get_name(idata->send_key), + silc_cipher_get_key_len(idata->send_key))); SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE, ("Your current nickname is %s", client->nickname)); diff --git a/lib/silcclient/client_prvmsg.c b/lib/silcclient/client_prvmsg.c index 2d065abe..7c251d81 100644 --- a/lib/silcclient/client_prvmsg.c +++ b/lib/silcclient/client_prvmsg.c @@ -456,13 +456,15 @@ int silc_client_send_private_message_key(SilcClient client, SilcSocketConnection sock = conn->sock; SilcBuffer buffer; int cipher_len; + const char *cipher; if (!client_entry->send_key || !client_entry->key) return FALSE; SILC_LOG_DEBUG(("Sending private message key")); - cipher_len = strlen(client_entry->send_key->cipher->name); + cipher = silc_cipher_get_name(client_entry->send_key); + cipher_len = strlen(cipher); /* Create private message key payload */ buffer = silc_buffer_alloc(2 + client_entry->key_len); @@ -472,7 +474,7 @@ int silc_client_send_private_message_key(SilcClient client, SILC_STR_UI_XNSTRING(client_entry->key, client_entry->key_len), SILC_STR_UI_SHORT(cipher_len), - SILC_STR_UI_XNSTRING(client_entry->send_key->cipher->name, + SILC_STR_UI_XNSTRING(cipher, cipher_len), SILC_STR_END); @@ -548,7 +550,7 @@ silc_client_list_private_message_keys(SilcClient client, if (entry->send_key) { keys[count].client_entry = entry; - keys[count].cipher = entry->send_key->cipher->name; + keys[count].cipher = (char *)silc_cipher_get_name(entry->send_key); keys[count].key = entry->generated == FALSE ? entry->key : NULL; keys[count].key_len = entry->generated == FALSE ? entry->key_len : 0; count++; diff --git a/lib/silcclient/protocol.c b/lib/silcclient/protocol.c index b8d4c3df..122ffdfc 100644 --- a/lib/silcclient/protocol.c +++ b/lib/silcclient/protocol.c @@ -117,12 +117,13 @@ void silc_client_protocol_ke_set_keys(SilcSKE ske, bool is_responder) { SilcClientConnection conn = (SilcClientConnection)sock->user_data; + const char *cname = silc_cipher_get_name(cipher); SILC_LOG_DEBUG(("Setting new keys into use")); /* Allocate cipher to be used in the communication */ - silc_cipher_alloc(cipher->cipher->name, &conn->send_key); - silc_cipher_alloc(cipher->cipher->name, &conn->receive_key); + silc_cipher_alloc((char *)cname, &conn->send_key); + silc_cipher_alloc((char *)cname, &conn->receive_key); silc_hmac_alloc((char *)silc_hmac_get_name(hmac), NULL, &conn->hmac_send); silc_hmac_alloc((char *)silc_hmac_get_name(hmac), NULL, &conn->hmac_receive); diff --git a/lib/silccore/silcpacket.c b/lib/silccore/silcpacket.c index fa3b9cdb..c6cba515 100644 --- a/lib/silccore/silcpacket.c +++ b/lib/silccore/silcpacket.c @@ -101,8 +101,9 @@ void silc_packet_encrypt(SilcCipher cipher, SilcHmac hmac, SilcUInt32 sequence, /* Encrypt the data area of the packet. */ if (cipher) { SILC_LOG_DEBUG(("Encrypting packet, cipher %s, len %d", - cipher->cipher->name, len)); - silc_cipher_encrypt(cipher, buffer->data, buffer->data, len, cipher->iv); + silc_cipher_get_name(cipher), len)); + silc_cipher_encrypt(cipher, buffer->data, buffer->data, len, + silc_cipher_get_iv(cipher)); } /* Pull the HMAC into the visible data area in the buffer */ @@ -326,7 +327,8 @@ bool silc_packet_receive_process(SilcSocketConnection sock, /* Decrypt first 16 bytes of the packet */ if (!SILC_IS_INBUF_PENDING(sock) && cipher) silc_cipher_decrypt(cipher, sock->inbuf->data, sock->inbuf->data, - SILC_PACKET_MIN_HEADER_LEN, cipher->iv); + SILC_PACKET_MIN_HEADER_LEN, + silc_cipher_get_iv(cipher)); /* Get packet lenght and full packet length with padding */ SILC_PACKET_LENGTH(sock->inbuf, packetlen, paddedlen); @@ -477,7 +479,7 @@ static int silc_packet_decrypt_rest(SilcCipher cipher, SilcHmac hmac, /* Decrypt rest of the packet */ silc_buffer_pull(buffer, SILC_PACKET_MIN_HEADER_LEN); silc_cipher_decrypt(cipher, buffer->data, buffer->data, buffer->len, - cipher->iv); + silc_cipher_get_iv(cipher)); silc_buffer_push(buffer, SILC_PACKET_MIN_HEADER_LEN); SILC_LOG_HEXDUMP(("Fully decrypted packet, len %d", buffer->len), @@ -525,7 +527,8 @@ static int silc_packet_decrypt_rest_special(SilcCipher cipher, "packet dropped")); return FALSE; } - silc_cipher_decrypt(cipher, buffer->data, buffer->data, len, cipher->iv); + silc_cipher_decrypt(cipher, buffer->data, buffer->data, len, + silc_cipher_get_iv(cipher)); silc_buffer_push(buffer, SILC_PACKET_MIN_HEADER_LEN); SILC_LOG_HEXDUMP(("packet, len %d", buffer->len), buffer->data, buffer->len); diff --git a/lib/silccore/silcprivate.c b/lib/silccore/silcprivate.c index e5ae3069..67cb967b 100644 --- a/lib/silccore/silcprivate.c +++ b/lib/silccore/silcprivate.c @@ -69,7 +69,7 @@ silc_private_message_payload_parse(unsigned char *payload, /* Decrypt the payload */ if (cipher) silc_cipher_decrypt(cipher, buffer.data, buffer.data, - buffer.len, cipher->iv); + buffer.len, silc_cipher_get_iv(cipher)); newp = silc_calloc(1, sizeof(*newp)); if (!newp) @@ -144,7 +144,7 @@ SilcBuffer silc_private_message_payload_encode(SilcUInt16 flags, if (cipher) { /* Encrypt payload of the packet. */ silc_cipher_encrypt(cipher, buffer->data, buffer->data, - buffer->len, cipher->iv); + buffer->len, silc_cipher_get_iv(cipher)); memset(pad, 0, sizeof(pad)); } diff --git a/lib/silccrypt/silccipher.c b/lib/silccrypt/silccipher.c index 45a596e5..3e2678ca 100644 --- a/lib/silccrypt/silccipher.c +++ b/lib/silccrypt/silccipher.c @@ -22,6 +22,13 @@ #include "silcincludes.h" #include "ciphers.h" /* Includes cipher definitions */ +/* The SilcCipher context */ +struct SilcCipherStruct { + SilcCipherObject *cipher; + void *context; + unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; +}; + #ifndef SILC_EPOC /* Dynamically registered list of ciphers. */ SilcDList silc_cipher_list = NULL; @@ -228,10 +235,6 @@ bool silc_cipher_alloc(const unsigned char *name, SilcCipher *new_cipher) *new_cipher = silc_calloc(1, sizeof(**new_cipher)); (*new_cipher)->cipher = entry; (*new_cipher)->context = silc_calloc(1, entry->context_len()); - (*new_cipher)->set_iv = silc_cipher_set_iv; - (*new_cipher)->get_iv = silc_cipher_get_iv; - (*new_cipher)->get_key_len = silc_cipher_get_key_len; - (*new_cipher)->get_block_len = silc_cipher_get_block_len; return TRUE; } @@ -349,12 +352,11 @@ void silc_cipher_set_iv(SilcCipher cipher, const unsigned char *iv) memcpy(&cipher->iv, iv, cipher->cipher->block_len); } -/* Returns the IV (initial vector) of the cipher. The IV is returned - to 'iv' argument. */ +/* Returns the IV (initial vector) of the cipher. */ -void silc_cipher_get_iv(SilcCipher cipher, unsigned char *iv) +unsigned char *silc_cipher_get_iv(SilcCipher cipher) { - memcpy(iv, &cipher->iv, cipher->cipher->block_len); + return cipher->iv; } /* Returns the key length of the cipher. */ @@ -370,3 +372,10 @@ SilcUInt32 silc_cipher_get_block_len(SilcCipher cipher) { return cipher->cipher->block_len; } + +/* Returns the name of the cipher */ + +const char *silc_cipher_get_name(SilcCipher cipher) +{ + return (const char *)cipher->cipher->name; +} diff --git a/lib/silccrypt/silccipher.h b/lib/silccrypt/silccipher.h index 01a60393..c9d64e42 100644 --- a/lib/silccrypt/silccipher.h +++ b/lib/silccrypt/silccipher.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2001 Pekka Riikonen + Copyright (C) 1997 - 2002 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 @@ -21,26 +21,33 @@ #ifndef SILCCIPHER_H #define SILCCIPHER_H -/* - SILC Cipher object. +/****h* silccrypt/SILC Cipher Interface + * + * DESCRIPTION + * + * This is the interface for cipher functions. It provides cipher + * registering and unregistering routines, encryption and decryption + * routines. + * + ***/ - Default SILC cipher object to represent any cipher. The function - pointers are the stub functions for each implemented cipher. Following - short description of the fields: +/****s* silccrypt/SilcCipherAPI/SilcCipher + * + * NAME + * + * typedef struct { ... } SilcCipher; + * + * DESCRIPTION + * + * This context is the actual cipher context and is allocated + * by silc_cipher_alloc and given as argument usually to all + * silc_cipher _* functions. It is freed by the silc_cipher_free + * function. + * + ***/ +typedef struct SilcCipherStruct *SilcCipher; - char *name - - Logical name of the cipher. - - SilcUInt32 block_len - - Block size of the cipher. - - SilcUInt32 key_len - - Length of the key of the cipher (in bits). - -*/ +/* The default SILC Cipher object to represent any cipher in SILC. */ typedef struct { char *name; SilcUInt32 block_len; @@ -57,18 +64,6 @@ typedef struct { #define SILC_CIPHER_MAX_IV_SIZE 16 -/* The main SilcCipher structure. Use SilcCipher instead of SilcCipherStruct. - Also remember that SilcCipher is a pointer. */ -typedef struct SilcCipherStruct { - SilcCipherObject *cipher; - void *context; - unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; - void (*set_iv)(struct SilcCipherStruct *, const unsigned char *); - void (*get_iv)(struct SilcCipherStruct *, unsigned char *); - SilcUInt32 (*get_key_len)(struct SilcCipherStruct *); - SilcUInt32 (*get_block_len)(struct SilcCipherStruct *); -} *SilcCipher; - /* Marks for all ciphers in silc. This can be used in silc_cipher_unregister to unregister all ciphers at once. */ #define SILC_ALL_CIPHERS ((SilcCipherObject *)1) @@ -79,6 +74,7 @@ extern DLLAPI const SilcCipherObject silc_default_ciphers[]; /* Default cipher in the SILC protocol */ #define SILC_DEFAULT_CIPHER "aes-256-cbc" + /* Macros */ /* Function names in SILC Crypto modules. The name of the cipher @@ -113,29 +109,243 @@ bool silc_##cipher##_decrypt_cbc(void *context, \ unsigned char *dst, \ SilcUInt32 len, \ unsigned char *iv) + + #define SILC_CIPHER_API_CONTEXT_LEN(cipher) \ SilcUInt32 silc_##cipher##_context_len() + /* Prototypes */ + +/****f* silccrypt/SilcCipherAPI/ + * + * SYNOPSIS + * + * bool silc_cipher_register(const SilcCipherObject *cipher); + * + * DESCRIPTION + * + * Register a new cipher into SILC. This is used at the initialization of + * the SILC. This function allocates a new object for the cipher to be + * registered. Therefore, if memory has been allocated for the object sent + * as argument it has to be free'd after this function returns succesfully. + * + ***/ bool silc_cipher_register(const SilcCipherObject *cipher); + +/****f* silccrypt/SilcCipherAPI/silc_cipher_unregister + * + * SYNOPSIS + * + * bool silc_cipher_unregister(SilcCipherObject *cipher); + * + * DESCRIPTION + * + * Unregister a cipher from the SILC. + * + ***/ bool silc_cipher_unregister(SilcCipherObject *cipher); + +/****f* silccrypt/SilcCipherAPI/ + * + * SYNOPSIS + * + * bool silc_cipher_register_default(void); + * + * DESCRIPTION + * + * Function that registers all the default ciphers (all builtin ciphers). + * The application may use this to register the default ciphers if specific + * ciphers in any specific order is not wanted. + * + ***/ bool silc_cipher_register_default(void); + +/****f* silccrypt/SilcCipherAPI/silc_cipher_unregister_all + * + * SYNOPSIS + * + * bool silc_cipher_unregister_all(void); + * + * DESCRIPTION + * + * Unregisters all ciphers. + * + ***/ bool silc_cipher_unregister_all(void); + +/****f* silccrypt/SilcCipherAPI/silc_cipher_alloc + * + * SYNOPSIS + * + * bool silc_cipher_alloc(const unsigned char *name, SilcCipher *new_cipher); + * + * DESCRIPTION + * + * Allocates a new SILC cipher object. Function returns 1 on succes and 0 + * on error. The allocated cipher is returned in new_cipher argument. The + * caller must set the key to the cipher after this function has returned + * by calling the ciphers set_key function. + * + ***/ bool silc_cipher_alloc(const unsigned char *name, SilcCipher *new_cipher); + +/****f* silccrypt/SilcCipherAPI/silc_cipher_free + * + * SYNOPSIS + * + * void silc_cipher_free(SilcCipher cipher); + * + * DESCRIPTION + * + * Frees the given cipher. + * + ***/ void silc_cipher_free(SilcCipher cipher); + +/****f* silccrypt/SilcCipherAPI/silc_cipher_is_supported( + * + * SYNOPSIS + * + * bool silc_cipher_is_supported(const unsigned char *name); + * + * DESCRIPTION + * + * Returns TRUE if cipher `name' is supported. + * + ***/ bool silc_cipher_is_supported(const unsigned char *name); + +/****f* silccrypt/SilcCipherAPI/silc_cipher_get_supported + * + * SYNOPSIS + * + * char *silc_cipher_get_supported(void); + * + * DESCRIPTION + * + * Returns comma separated list of supported ciphers. + * + ***/ char *silc_cipher_get_supported(void); + +/****f* silccrypt/SilcCipherAPI/silc_cipher_encrypt + * + * SYNOPSIS + * + * bool silc_cipher_encrypt(SilcCipher cipher, const unsigned char *src, + * unsigned char *dst, SilcUInt32 len, + * unsigned char *iv); + * + * DESCRIPTION + * + * Encrypts data from `src' into `dst' with the specified cipher and + * Initial Vector (IV). The `src' and `dst' maybe same buffer. + * + ***/ bool silc_cipher_encrypt(SilcCipher cipher, const unsigned char *src, unsigned char *dst, SilcUInt32 len, unsigned char *iv); + +/****f* silccrypt/SilcCipherAPI/silc_cipher_decrypt + * + * SYNOPSIS + * + * bool silc_cipher_decrypt(SilcCipher cipher, const unsigned char *src, + * unsigned char *dst, SilcUInt32 len, + * unsigned char *iv); + * + * DESCRIPTION + * + * Decrypts data from `src' into `dst' with the specified cipher and + * Initial Vector (IV). The `src' and `dst' maybe same buffer. + * + ***/ bool silc_cipher_decrypt(SilcCipher cipher, const unsigned char *src, unsigned char *dst, SilcUInt32 len, unsigned char *iv); + +/****f* silccrypt/SilcCipherAPI/ + * + * SYNOPSIS + * + * bool silc_cipher_set_key(SilcCipher cipher, const unsigned char *key, + * SilcUInt32 keylen); + * + * DESCRIPTION + * + * Sets the key for the cipher. The `keylen' is the key length in + * bits. + * + ***/ bool silc_cipher_set_key(SilcCipher cipher, const unsigned char *key, SilcUInt32 keylen); + +/****f* silccrypt/SilcCipherAPI/silc_cipher_set_iv + * + * SYNOPSIS + * + * void silc_cipher_set_iv(SilcCipher cipher, const unsigned char *iv); + * + * DESCRIPTION + * + * Sets the IV (initial vector) for the cipher. The `iv' must be + * the size of the block size of the cipher. + * + ***/ void silc_cipher_set_iv(SilcCipher cipher, const unsigned char *iv); -void silc_cipher_get_iv(SilcCipher cipher, unsigned char *iv); + +/****f* silccrypt/SilcCipherAPI/silc_cipher_get_iv + * + * SYNOPSIS + * + * unsigned char *silc_cipher_get_iv(SilcCipher cipher); + * + * DESCRIPTION + * + * Returns the IV (initial vector) of the cipher. The returned + * pointer must not be freed by the caller. + * + ***/ +unsigned char *silc_cipher_get_iv(SilcCipher cipher); + +/****f* silccrypt/SilcCipherAPI/SilcUInt32 silc_cipher_get_key_len + * + * SYNOPSIS + * + * SilcUInt32 silc_cipher_get_key_len(SilcCipher cipher); + * + * DESCRIPTION + * + * Returns the key length of the cipher in bits. + * + ***/ SilcUInt32 silc_cipher_get_key_len(SilcCipher cipher); + +/****f* silccrypt/SilcCipherAPI/silc_cipher_get_block_len + * + * SYNOPSIS + * + * SilcUInt32 silc_cipher_get_block_len(SilcCipher cipher); + * + * DESCRIPTION + * + * Returns the block size of the cipher in bytes. + * + ***/ SilcUInt32 silc_cipher_get_block_len(SilcCipher cipher); +/****f* silccrypt/SilcCipherAPI/silc_cipher_get_name + * + * SYNOPSIS + * + * const char *silc_cipher_get_name(SilcCipher cipher); + * + * DESCRIPTION + * + * Returns the name of the cipher. + * + ***/ +const char *silc_cipher_get_name(SilcCipher cipher); + #endif -- 2.24.0