Added SILC Thread Queue API
[silc.git] / lib / silccrypt / silccipher_i.h
1 /*
2
3   silccipher_i.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2007 Pekka Riikonen
8
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.
12
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.
17
18 */
19
20 #ifndef SILCCIPHER_I_H
21 #define SILCCIPHER_I_H
22
23 #ifndef SILCCIPHER_H
24 #error "Do not include this header directly"
25 #endif
26
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, \
31                                  void *context,                         \
32                                  const unsigned char *key,              \
33                                  SilcUInt32 keylen,                     \
34                                  SilcBool encryption)
35 #define SILC_CIPHER_API_SET_IV(name)                                    \
36   void silc_##name##_set_iv(struct SilcCipherObjectStruct *cipher,      \
37                             void *context,                              \
38                             unsigned char *iv)
39 #define SILC_CIPHER_API_ENCRYPT(name)                                   \
40   SilcBool silc_##name##_encrypt(struct SilcCipherObjectStruct *cipher, \
41                                  void *context,                         \
42                                  const unsigned char *src,              \
43                                  unsigned char *dst,                    \
44                                  SilcUInt32 len,                        \
45                                  unsigned char *iv)
46 #define SILC_CIPHER_API_DECRYPT(name)                                   \
47   SilcBool silc_##name##_decrypt(struct SilcCipherObjectStruct *cipher, \
48                                  void *context,                         \
49                                  const unsigned char *src,              \
50                                  unsigned char *dst,                    \
51                                  SilcUInt32 len,                        \
52                                  unsigned char *iv)
53 #define SILC_CIPHER_API_CONTEXT_LEN(name)       \
54   SilcUInt32 silc_##name##_context_len()
55
56 /* Cipher object to represent a cipher algorithm. */
57 struct SilcCipherObjectStruct {
58   /* Cipher name */
59   char *name;
60
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);
66
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, unsigned char *iv);
71
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,
77                       unsigned char *iv);
78
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,
84                       unsigned char *iv);
85
86   /* Returns the length of the internal cipher context */
87   SilcUInt32 (*context_len)(void);
88
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 */
93 };
94
95 #endif /* SILCCIPHER_I_H */