-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tools.h
57 lines (41 loc) · 1.7 KB
/
Tools.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
//
// Tools.h
// encrypt_One
//
// Copyleft (ɔ) 2014 Mailden
// Use of this source code is governed by a GNU AFFERO GENERAL PUBLIC
// license (AGPL) that can be found in the LICENSE file.
#include <stdio.h>
#include <gcrypt.h>
#include <assert.h>
#include <errno.h>
#include <ctype.h>
#ifndef encrypt_One_Tools_h
#define encrypt_One_Tools_h
#define MAX_BUFF_SIZE 4096
#define tohex(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'A'))
#define digitp(p) (*(p) >= '0' && *(p) <= '9')
#define hexdigitp(a) (digitp (a) || (*(a) >= 'A' && *(a) <= 'F') || (*(a) >= 'a' && *(a) <= 'f'))
/* The atoi macros assume that the buffer has only valid digits. */
#define atoi_1(p) (*(p) - '0' )
#define atoi_2(p) ((atoi_1(p) * 10) + atoi_1((p)+1))
#define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
#define HEADER_SIZE 20
/* Maximum buffer size in bytes - do not allow it to grow larger than this. */
#define BUFFMAX_SIZE 37748736 // ~20Mo = max authorized email size at postfix's gate
typedef struct {
char version[9];
size_t key_size;
size_t email_size;
} header_t;
void libgcrypt_initialize (void);
void die(char *str);
void charTosexp(const unsigned char *plain, gcry_sexp_t *s_exp);
size_t outputSexp (gcry_sexp_t s_exp, char **txtexp);
char *convert_char_to_hexstring (const void *char_string, size_t length, char *hex_string);
int convert_hexstring_to_char (const char *hex_string, size_t length, void *char_string);
char *convert_hexstr_to_charstr (const char *hex_string, size_t length);
char *build_unlock_key (const char *user_pass, const char *phrase_completion);
int parse_header(char *input, header_t *header);
#endif