1224210c558390bef008b8d193c6c84e6a6aac5c
[tinc] / src / cipher.h
1 #ifndef TINC_CIPHER_H
2 #define TINC_CIPHER_H
3
4 /*
5     cipher.h -- header file cipher.c
6     Copyright (C) 2007-2016 Guus Sliepen <guus@tinc-vpn.org>
7
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
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     You should have received a copy of the GNU General Public License along
19     with this program; if not, write to the Free Software Foundation, Inc.,
20     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #include "system.h"
24
25 #define CIPHER_MAX_BLOCK_SIZE 32
26 #define CIPHER_MAX_IV_SIZE 16
27 #define CIPHER_MAX_KEY_SIZE 32
28
29 #ifndef DISABLE_LEGACY
30
31 #ifdef HAVE_OPENSSL
32 #include "openssl/cipher.h"
33 #elif HAVE_LIBGCRYPT
34 #include "gcrypt/cipher.h"
35 #else
36 #error Incorrect cryptographic library, please reconfigure.
37 #endif
38
39 typedef struct cipher cipher_t;
40
41 extern cipher_t *cipher_alloc() __attribute__((__malloc__));
42 extern void cipher_free(cipher_t **cipher);
43 extern bool cipher_open_by_name(cipher_t *cipher, const char *name);
44 extern bool cipher_open_by_nid(cipher_t *cipher, int nid);
45 extern void cipher_close(cipher_t *cipher);
46 extern size_t cipher_keylength(const cipher_t *cipher);
47 extern size_t cipher_blocksize(const cipher_t *cipher);
48 extern uint64_t cipher_budget(const cipher_t *cipher);
49 extern bool cipher_set_key(cipher_t *cipher, void *key, bool encrypt) __attribute__((__warn_unused_result__));
50 extern bool cipher_set_key_from_rsa(cipher_t *cipher, void *rsa, size_t len, bool encrypt) __attribute__((__warn_unused_result__));
51 extern bool cipher_encrypt(cipher_t *cipher, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) __attribute__((__warn_unused_result__));
52 extern bool cipher_decrypt(cipher_t *cipher, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) __attribute__((__warn_unused_result__));
53 extern int cipher_get_nid(const cipher_t *cipher);
54 extern bool cipher_active(const cipher_t *cipher);
55
56 #endif // DISABLE_LEGACY
57
58 #endif // TINC_CIPHER_H