Detect negative return values from base64_decode().
[easyotp.git] / libotp.h
blob433e6cc9cd67440c2546eb9274e85cf339a91c2c
1 /** Practical One-time Pad Library
3 * Created:20080514
4 * By Jeff Connelly
5 */
7 #define MARKER_TO "to:"
8 #define MARKER_BEGIN "--EMOTP_BEGIN--"
9 #define MARKER_END "--EMOTP_END--"
11 /** Pad messages to a multiple of this many bytes, to hide the true
12 * message length. Higher obscures more information but burns more pad.
13 * For the best security, this should be the length of the longest message
14 * you'll ever send, then all messages will be the same length and an attacker
15 * can tell nothing by the length of the message!.
17 #define PADDING_MULTIPLE 16
19 #define OFFSET_FILE_EXTENSION ".off"
20 #define OFFSET_SIZE 11 /* strlen("4294967296") + 1 */
21 #define PAD_NAME_LENGTH 4
22 #define MAX_CONFIG_LINE 1024 /* should be enough, >MAX_PATH */
24 /* One-time pad. */
25 typedef struct _PAD {
26 char *local_filename;
27 char *name;
28 FILE *fp;
29 struct _PAD *next;
30 /* Use read_offset() and write_offset() to access offset. */
31 } PAD;
34 /** Packaged up encrypted message, ready for transport. */
35 typedef struct _MESSAGE {
36 unsigned long offset;
37 PAD *pad;
38 unsigned long length;
39 char *cipher_text;
40 } MESSAGE;
42 void load_config(char *config_filename);
43 void show_pads();
44 FILE *open_offset_file(PAD *p, char *mode);
45 unsigned long read_offset(PAD *p);
46 void write_offset(PAD *p, unsigned long offset);
47 void load_pad(char *local_filename, char *pad_name);
48 void free_pads();
49 MESSAGE *unpackage(char *input);
50 void free_message(MESSAGE *);
51 char *otp_encrypt(char *input, unsigned int length, char *to, unsigned int *out_length);
52 unsigned int otp_decrypt(char *input, char **out);