5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2001 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
27 Default SILC cipher object to represent any cipher. The function
28 pointers are the stub functions for each implemented cipher. Following
29 short description of the fields:
33 Logical name of the cipher.
35 unsigned int block_len
37 Block size of the cipher.
41 Length of the key of the cipher (in bits).
46 unsigned int block_len;
49 int (*set_key)(void *, const unsigned char *, unsigned int);
50 int (*set_key_with_string)(void *, const unsigned char *, unsigned int);
51 int (*encrypt)(void *, const unsigned char *, unsigned char *,
52 unsigned int, unsigned char *);
53 int (*decrypt)(void *, const unsigned char *, unsigned char *,
54 unsigned int, unsigned char *);
55 unsigned int (*context_len)();
58 #define SILC_CIPHER_MAX_IV_SIZE 16
60 /* The main SilcCipher structure. Use SilcCipher instead of SilcCipherStruct.
61 Also remember that SilcCipher is a pointer. */
62 typedef struct SilcCipherStruct {
63 SilcCipherObject *cipher;
65 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
67 void (*set_iv)(struct SilcCipherStruct *, const unsigned char *);
68 void (*get_iv)(struct SilcCipherStruct *, unsigned char *);
69 unsigned int (*get_key_len)(struct SilcCipherStruct *,
70 const unsigned char *);
71 unsigned int (*get_block_len)(struct SilcCipherStruct *);
74 /* List of all registered ciphers. */
75 extern struct SilcCipherListStruct *silc_cipher_list;
77 /* Marks for all ciphers in silc. This can be used in silc_cipher_unregister
78 to unregister all ciphers at once. */
79 #define SILC_ALL_CIPHERS ((SilcCipherObject *)1)
83 /* Function names in SILC Crypto modules. The name of the cipher
84 is appended into these names and used to the get correct symbol out
85 of the module. All SILC Crypto API compliant modules must support
86 these function names (use macros below to assure this). */
87 #define SILC_CIPHER_SIM_SET_KEY "set_key"
88 #define SILC_CIPHER_SIM_SET_KEY_WITH_STRING "set_key_with_string"
89 #define SILC_CIPHER_SIM_ENCRYPT_CBC "encrypt_cbc"
90 #define SILC_CIPHER_SIM_DECRYPT_CBC "decrypt_cbc"
91 #define SILC_CIPHER_SIM_CONTEXT_LEN "context_len"
93 /* These macros can be used to implement the SILC Crypto API and to avoid
94 errors in the API these macros should be used always. */
95 #define SILC_CIPHER_API_SET_KEY(cipher) \
96 int silc_##cipher##_set_key(void *context, \
97 const unsigned char *key, \
99 #define SILC_CIPHER_API_SET_KEY_WITH_STRING(cipher) \
100 int silc_##cipher##_set_key_with_string(void *context, \
101 const unsigned char *string, \
102 unsigned int stringlen)
103 #define SILC_CIPHER_API_ENCRYPT_CBC(cipher) \
104 int silc_##cipher##_encrypt_cbc(void *context, \
105 const unsigned char *src, \
106 unsigned char *dst, \
109 #define SILC_CIPHER_API_DECRYPT_CBC(cipher) \
110 int silc_##cipher##_decrypt_cbc(void *context, \
111 const unsigned char *src, \
112 unsigned char *dst, \
115 #define SILC_CIPHER_API_CONTEXT_LEN(cipher) \
116 unsigned int silc_##cipher##_context_len()
119 int silc_cipher_register(SilcCipherObject *cipher);
120 int silc_cipher_unregister(SilcCipherObject *cipher);
121 int silc_cipher_alloc(const unsigned char *name, SilcCipher *new_cipher);
122 void silc_cipher_free(SilcCipher cipher);
123 int silc_cipher_is_supported(const unsigned char *name);
124 char *silc_cipher_get_supported();
125 int silc_cipher_set_key(SilcCipher cipher, const unsigned char *key,
126 unsigned int keylen);
127 void silc_cipher_set_iv(SilcCipher cipher, const unsigned char *iv);
128 void silc_cipher_get_iv(SilcCipher cipher, unsigned char *iv);
129 unsigned int silc_cipher_get_key_len(SilcCipher cipher,
130 const unsigned char *name);
131 unsigned int silc_cipher_get_block_len(SilcCipher cipher);