5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2007 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; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 #ifndef SILCCIPHER_I_H
21 #define SILCCIPHER_I_H
24 #error "Do not include this header directly"
27 /* These macros can be used to implement the SILC Crypto API and to avoid
28 errors in the API these macros should be used always. */
29 #define SILC_CIPHER_API_SET_KEY(name) \
30 SilcBool silc_##name##_set_key(struct SilcCipherObjectStruct *cipher, \
32 const unsigned char *key, \
35 #define SILC_CIPHER_API_SET_IV(name) \
36 void silc_##name##_set_iv(struct SilcCipherObjectStruct *cipher, \
38 const unsigned char *iv)
39 #define SILC_CIPHER_API_ENCRYPT(name) \
40 SilcBool silc_##name##_encrypt(struct SilcCipherObjectStruct *cipher, \
42 const unsigned char *src, \
46 #define SILC_CIPHER_API_DECRYPT(name) \
47 SilcBool silc_##name##_decrypt(struct SilcCipherObjectStruct *cipher, \
49 const unsigned char *src, \
53 #define SILC_CIPHER_API_CONTEXT_LEN(name) \
54 SilcUInt32 silc_##name##_context_len()
56 /* Cipher object to represent a cipher algorithm. */
57 struct SilcCipherObjectStruct {
61 /* Set new key. If `encryption' is TRUE the key is for encryption,
62 FALSE for decryption. The `keylen' is in bits. */
63 SilcBool (*set_key)(struct SilcCipherObjectStruct *cipher,
64 void *context, const unsigned char *key,
65 SilcUInt32 keylen, SilcBool encryption);
67 /* Set IV. The upper layer (SilcCipher) maintains the IV. If the algorithm
68 needs to set the IV itself, this should be implemented. */
69 void (*set_iv)(struct SilcCipherObjectStruct *cipher,
70 void *context, const unsigned char *iv);
72 /* Encrypt. The `src' and `dst' may be same pointer. The `iv' may be
73 edited inside this function. */
74 SilcBool (*encrypt)(struct SilcCipherObjectStruct *cipher,
75 void *context, const unsigned char *src,
76 unsigned char *dst, SilcUInt32 len,
79 /* Decrypt. The `src' and `dst' may be same pointer. The `iv' may be
80 edited inside this function. */
81 SilcBool (*decrypt)(struct SilcCipherObjectStruct *cipher,
82 void *context, const unsigned char *src,
83 unsigned char *dst, SilcUInt32 len,
86 /* Returns the length of the internal cipher context */
87 SilcUInt32 (*context_len)(void);
89 unsigned int key_len : 10; /* Key length in bits */
90 unsigned int block_len : 8; /* Block size in bytes */
91 unsigned int iv_len : 8; /* IV length in bytes */
92 unsigned int mode : 6; /* SilcCipherMode */
95 #endif /* SILCCIPHER_I_H */