ROBODoc documented lib/silcrypt/silccipher.h. Patch by Toni
authorPekka Riikonen <priikone@silcnet.org>
Thu, 24 Oct 2002 12:18:58 +0000 (12:18 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 24 Oct 2002 12:18:58 +0000 (12:18 +0000)
Willberg.
Changed the SilcCipher to be private context.

15 files changed:
CHANGES
TODO
apps/irssi/src/silc/core/client_ops.c
apps/irssi/src/silc/core/silc-channels.c
apps/silcd/command.c
apps/silcd/packet_receive.c
apps/silcd/packet_send.c
apps/silcd/protocol.c
apps/silcd/server_util.c
lib/silcclient/client_prvmsg.c
lib/silcclient/protocol.c
lib/silccore/silcpacket.c
lib/silccore/silcprivate.c
lib/silccrypt/silccipher.c
lib/silccrypt/silccipher.h

diff --git a/CHANGES b/CHANGES
index c6aafe368b725d97e6c5d3ecb8ff8c8a9a272606..9a49a529c3f31be598d98e9cc2003c4720dae2ac 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,16 @@ Thu Oct 24 12:22:35 EEST 2002  Pekka Riikonen <priikone@silcnet.org>
          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 <priikone@silcnet.org>
 
        * Fixed unaligned access in lib/silccore/silcattrs.c.
diff --git a/TODO b/TODO
index 5bf5a171166d9da117c7764d1e9c681b284bc4a4..69513cff92b5e5b3f9787cfcdf078525b7ea8cb6 100644 (file)
--- 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
index 484c2e492b0998f829631526befd4362394ca09b..491f776d377e5a29696d648e565151c50397ee94 100644 (file)
@@ -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);
index 04dd65d7af83b9108228ffb67044ba7a1f9d569b..005763bf6439d0b636f2b89c72ecfb6b7508a0d2 100644 (file)
@@ -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, " ");
index 4e7a9c79e9989e4154cdd3e405ce1dd26be43dbf..82231d235d89b845833f7d30d1333a295d8a115b 100644 (file)
@@ -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);
     }
   }
index bb778149996cdef8143acaa207efbcb2d37d436c..ae59c11b895bea88b32fe484ad4fdbbc4219e5b8 100644 (file)
@@ -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);
 
index 49d12c7b66c747605a4ad4f33949002bdcf30467..2a5118cc015acbcc89ae1c35bd6734c6aade264f 100644 (file)
@@ -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,
index 8770fc0ff0abcdd05aa1a82b2ec737ae4887f0b6..e0d82738aa9c66c1e9b7f4d149ce7ddb3e9476ac 100644 (file)
@@ -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" : ""));
index 74a4d7e5d9801f214676e2a7e7e7deff16b6141e..da9f695f5c46d9ecb2b9569577f4aad50e50029b 100644 (file)
@@ -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));
index 2d065abe6406e005ff4f58c70cb8cd0c665cdffc..7c251d817a5b573417b101a6bc9654d436c7b8fe 100644 (file)
@@ -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++;
index b8d4c3df2dd323aa7d46e2b869413bf349b61b3a..122ffdfc70b11dab8b5b7c8f8cc10ed0aaef1757 100644 (file)
@@ -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);
 
index fa3b9cdb7131fda006c1f4b759db8f36c9c9aeae..c6cba515af1b558f8ad96060113a9c574fd56b5b 100644 (file)
@@ -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);
index e5ae3069d8cedb2651042ca59af913c93bf7ad94..67cb967b078c039c477cb4af05f687d5083ed7e0 100644 (file)
@@ -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));
   }
 
index 45a596e5197da563a884c2823dde7343028c74bf..3e2678ca2db2c601b5d0e23a7ccc41e0370807f2 100644 (file)
 #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;
+}
index 01a60393b3a54a3c98988c89b3b8d0ec2b6ec894..c9d64e42e7bb1677f5ddd5d21973fa39243dcbcd 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
 
-  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
 #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