5 cipher.h -- header file cipher.c
6 Copyright (C) 2007-2022 Guus Sliepen <guus@tinc-vpn.org>
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.
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.
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.
25 #define CIPHER_MAX_BLOCK_SIZE 32
26 #define CIPHER_MAX_IV_SIZE 16
27 #define CIPHER_MAX_KEY_SIZE 32
29 #ifndef DISABLE_LEGACY
32 #include "openssl/cipher.h"
34 #include "gcrypt/cipher.h"
36 #error Incorrect cryptographic library, please reconfigure.
39 extern void cipher_free(cipher_t *cipher);
40 extern cipher_t *cipher_alloc(void) ATTR_MALLOC ATTR_DEALLOCATOR(cipher_free);
41 extern bool cipher_open_by_name(cipher_t *cipher, const char *name);
42 extern bool cipher_open_by_nid(cipher_t *cipher, nid_t nid);
43 extern void cipher_close(cipher_t *cipher);
44 extern size_t cipher_keylength(const cipher_t *cipher);
45 extern size_t cipher_blocksize(const cipher_t *cipher);
46 extern uint64_t cipher_budget(const cipher_t *cipher);
47 extern bool cipher_set_key(cipher_t *cipher, void *key, bool encrypt) ATTR_WARN_UNUSED;
48 extern bool cipher_set_key_from_rsa(cipher_t *cipher, void *rsa, size_t len, bool encrypt) ATTR_WARN_UNUSED;
49 extern bool cipher_encrypt(cipher_t *cipher, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) ATTR_WARN_UNUSED;
50 extern bool cipher_decrypt(cipher_t *cipher, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) ATTR_WARN_UNUSED;
51 extern nid_t cipher_get_nid(const cipher_t *cipher);
52 extern bool cipher_active(const cipher_t *cipher);
54 #endif // DISABLE_LEGACY
56 #endif // TINC_CIPHER_H