-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtwofish.h
89 lines (76 loc) · 2.35 KB
/
twofish.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Copyright (c) 2009, Markus Peloquin <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
#ifndef FLUKS_TWOFISH_H
#define FLUKS_TWOFISH_H
#include <features.h>
#ifdef __cplusplus
# include <cstddef>
# include <cstdint>
const size_t TWOFISH_KEYMIN = 16;
const size_t TWOFISH_KEYMAX = 32;
const size_t TWOFISH_KEYSTEP = 8;
const size_t TWOFISH_BLOCK = 16;
#else
# include <stdbool.h>
# include <stddef.h>
# include <stdint.h>
# define TWOFISH_KEYMIN 16
# define TWOFISH_KEYMAX 32
# define TWOFISH_KEYSTEP 8
# define TWOFISH_BLOCK 16
#endif
struct twofish_ctx {
uint32_t K[40];
uint32_t QF[4][256];
};
#ifdef __cplusplus
extern "C" {
#endif
/** Set the %key for en/decryption
*
* \param key Twofish %key structure
* \param keydata The %key for en/decryption
* \param sz The size in bytes of the %key
* \retval true iff key size is fine
*/
bool twofish_init(struct twofish_ctx *key, const uint8_t *keydata,
size_t sz);
/** Encrypt a block of plaintext
*
* Both the input and output buffers should be of size
* <code>TWOFISH_BLOCK</code>.
*
* \param[in] key The encryption %key
* \param[in] in The plaintext
* \param[out] out The ciphertext buffer
*/
void twofish_encrypt(struct twofish_ctx *key,
const uint8_t in[TWOFISH_BLOCK],
uint8_t out[TWOFISH_BLOCK]);
/** Decrypt a block of ciphertext
*
* Both the input and output buffers should be of size
* <code>TWOFISH_BLOCK</code>.
*
* \param[in] key The decryption %key
* \param[in] in The ciphertext
* \param[out] out The plaintext buffer
*/
void twofish_decrypt(struct twofish_ctx *key,
const uint8_t in[TWOFISH_BLOCK],
uint8_t out[TWOFISH_BLOCK]);
#ifdef __cplusplus
}
#endif
#endif