Added encryptio boolena indicator to silc_cipher_set_key.
[silc.git] / lib / silccrypt / silccipher.h
index 472b0ab8edeea4ffe11b6a53b1d32acf938b3387..c020d280414688a7ad0579acb3ef0ac973d5636a 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2005 Pekka Riikonen
+  Copyright (C) 1997 - 2006 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
@@ -49,16 +49,15 @@ typedef struct SilcCipherStruct *SilcCipher;
 /* The default SILC Cipher object to represent any cipher in SILC. */
 typedef struct {
   char *name;
-  SilcUInt32 block_len;
-  SilcUInt32 key_len;
-
-  SilcBool (*set_key)(void *, const unsigned char *, SilcUInt32);
-  SilcBool (*set_key_with_string)(void *, const unsigned char *, SilcUInt32);
+  SilcBool (*set_key)(void *, const unsigned char *, SilcUInt32, SilcBool);
   SilcBool (*encrypt)(void *, const unsigned char *, unsigned char *,
                  SilcUInt32, unsigned char *);
   SilcBool (*decrypt)(void *, const unsigned char *, unsigned char *,
                  SilcUInt32, unsigned char *);
   SilcUInt32 (*context_len)();
+  unsigned int key_len   : 12;
+  unsigned int block_len : 10;
+  unsigned int iv_len    : 10;
 } SilcCipherObject;
 
 #define SILC_CIPHER_MAX_IV_SIZE 16
@@ -73,7 +72,6 @@ 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
@@ -81,7 +79,6 @@ extern DLLAPI const SilcCipherObject silc_default_ciphers[];
    of the module. All SILC Crypto API compliant modules must support
    these function names (use macros below to assure this). */
 #define SILC_CIPHER_SIM_SET_KEY "set_key"
-#define SILC_CIPHER_SIM_SET_KEY_WITH_STRING "set_key_with_string"
 #define SILC_CIPHER_SIM_ENCRYPT_CBC "encrypt_cbc"
 #define SILC_CIPHER_SIM_DECRYPT_CBC "decrypt_cbc"
 #define SILC_CIPHER_SIM_CONTEXT_LEN "context_len"
@@ -91,11 +88,8 @@ extern DLLAPI const SilcCipherObject silc_default_ciphers[];
 #define SILC_CIPHER_API_SET_KEY(cipher)                        \
 SilcBool silc_##cipher##_set_key(void *context,                \
                             const unsigned char *key,  \
-                            SilcUInt32 keylen)
-#define SILC_CIPHER_API_SET_KEY_WITH_STRING(cipher)                    \
-SilcBool silc_##cipher##_set_key_with_string(void *context,                    \
-                                        const unsigned char *string,   \
-                                        SilcUInt32 stringlen)
+                            SilcUInt32 keylen,         \
+                            SilcBool encryption)
 #define SILC_CIPHER_API_ENCRYPT_CBC(cipher)                    \
 SilcBool silc_##cipher##_encrypt_cbc(void *context,                    \
                                 const unsigned char *src,      \
@@ -108,12 +102,9 @@ SilcBool 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/silc_cipher_register
@@ -274,16 +265,17 @@ SilcBool silc_cipher_decrypt(SilcCipher cipher, const unsigned char *src,
  * SYNOPSIS
  *
  *    SilcBool silc_cipher_set_key(SilcCipher cipher, const unsigned char *key,
- *                             SilcUInt32 keylen);
+ *                                 SilcUInt32 keylen, SilcBool encryption);
  *
  * DESCRIPTION
  *
  *    Sets the key for the cipher.  The `keylen' is the key length in
- *    bits.
+ *    bits.  If the `encryption' is TRUE the key is for encryption, if FALSE
+ *    the key is for decryption.
  *
  ***/
 SilcBool silc_cipher_set_key(SilcCipher cipher, const unsigned char *key,
-                            SilcUInt32 keylen);
+                            SilcUInt32 keylen, SilcBool encryption);
 
 /****f* silccrypt/SilcCipherAPI/silc_cipher_set_iv
  *
@@ -339,6 +331,19 @@ SilcUInt32 silc_cipher_get_key_len(SilcCipher cipher);
  ***/
 SilcUInt32 silc_cipher_get_block_len(SilcCipher cipher);
 
+/****f* silccrypt/SilcCipherAPI/silc_cipher_get_iv_len
+ *
+ * SYNOPSIS
+ *
+ *    SilcUInt32 silc_cipher_get_iv_len(SilcCipher cipher);
+ *
+ * DESCRIPTION
+ *
+ *    Returns the IV length of the cipher in bytes.
+ *
+ ***/
+SilcUInt32 silc_cipher_get_iv_len(SilcCipher cipher);
+
 /****f* silccrypt/SilcCipherAPI/silc_cipher_get_name
  *
  * SYNOPSIS
@@ -352,4 +357,4 @@ SilcUInt32 silc_cipher_get_block_len(SilcCipher cipher);
  ***/
 const char *silc_cipher_get_name(SilcCipher cipher);
 
-#endif
+#endif /* SILCCIPHER_H */