-
Notifications
You must be signed in to change notification settings - Fork 10
/
common.h
101 lines (84 loc) · 2.22 KB
/
common.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
90
91
92
93
94
95
96
97
98
99
100
101
/* threshcrypt common.h
* Copyright 2012 Ryan Castellucci <[email protected]>
* This software is published under the terms of the Simplified BSD License.
* Please see the 'COPYING' file for details.
*/
#ifndef THRESHCRYPT_COMMON_H_
#define THRESHCRYPT_COMMON_H_
#define THRCR_VERSION_STR "0.0.1.0"
#define MODE_UNKNOWN 0
#define MODE_ENCRYPT 1
#define MODE_DECRYPT 2
#define DEFAULT_ITERATIONS 31337
#define DEFAULT_SHARECOUNT 3
#define DEFAULT_THRESHOLD 2
#define DEFAULT_KEY_BITS 256
#define MAX_ITER_MS 60000
#define MAX_KEY_SIZE 64
#define MAX_HMAC_SIZE 32
#define MAX_SHARE_SIZE 72
#define SUBKEY_ITER 16
#define SALT_SIZE 12
#define HMAC_SIZE 16
#define HEADER_SIZE 32768
#define BUFFER_SIZE 65536
/* return codes */
#define THRCR_OK 0
#define THRCR_ERROR 1
#define THRCR_NOMAGIC 2
#define THRCR_BADMODE 3
#define THRCR_BADDATA 4
#define THRCR_BADMAC 5
#define THRCR_ENCERR 6
#define THRCR_DECERR 7
#define THRCR_IOERR 8
#define THRCR_READERR 9
#define THRCR_WRITEERR 10
#define THRCR_NOOP 64
/* macro functions */
#define pbkdf2(p, pl, s, ss, i, h, k, ks) \
pkcs_5_alg2(p, pl, s, ss, i, h, k, (unsigned long *)ks)
#ifndef MIN
#define MIN(a,b) ((a)<(b))?(a):(b)
#endif
#ifndef MAX
#define MAX(a,b) ((a)>(b))?(a):(b)
#endif
typedef struct {
unsigned char *ptr;
uint32_t off;
uint32_t pos;
uint32_t lck;
uint32_t len;
} keymem_t;
typedef struct {
unsigned char *key; /* SENSITIVE */
unsigned char *ptxt; /* SENSITIVE */
int32_t iter;
unsigned char salt[SALT_SIZE];
unsigned char *ctxt;
unsigned char *hmac;
} share_data_t;
typedef struct {
unsigned char *master_key; /* SENSITIVE */
unsigned char magic[8];
unsigned char version[4];
uint8_t cipher;
uint8_t hash;
uint8_t kdf;
uint8_t nshares;
uint8_t thresh;
/* all sizes in bytes */
uint8_t key_size;
uint8_t hmac_size;
uint8_t share_size;
int32_t master_iter;
unsigned char master_salt[SALT_SIZE];
unsigned char *master_hmac;
share_data_t *shares;
keymem_t *keymem;
unsigned char *tmp_share_key;
unsigned char *tmp_share_ptxt;
} header_data_t;
/* vim: set ts=2 sw=2 et ai si: */
#endif /* THRESHCRYPT_COMMON_H_ */