Thanks to Ivan Stankovic
[platform/upstream/cryptsetup.git] / lib / internal.h
1 #ifndef INTERNAL_H
2 #define INTERNAL_H
3
4 #ifdef HAVE_CONFIG_H
5 #       include "config.h"
6 #endif
7
8 #include <stdint.h>
9 #include <stdarg.h>
10 #include <unistd.h>
11
12 #define SECTOR_SHIFT            9
13 #define SECTOR_SIZE             (1 << SECTOR_SHIFT)
14
15 /* private struct crypt_options flags */
16
17 #define CRYPT_FLAG_FREE_DEVICE  (1 << 24)
18 #define CRYPT_FLAG_FREE_CIPHER  (1 << 25)
19
20 #define CRYPT_FLAG_PRIVATE_MASK ((unsigned int)-1 << 24)
21
22 struct hash_type {
23         char            *name;
24         void            *private;
25         int             (*fn)(void *data, int size, char *key,
26                               int sizep, const char *passphrase);
27 };
28
29 struct hash_backend {
30         const char              *name;
31         struct hash_type *      (*get_hashes)(void);
32         void                    (*free_hashes)(struct hash_type *hashes);
33 };
34
35 struct setup_backend {
36         const char      *name;
37         int             (*init)(void);
38         void            (*exit)(void);
39         int             (*create)(int reload, struct crypt_options *options,
40                                   const char *key);
41         int             (*status)(int details, struct crypt_options *options,
42                                   char **key);
43         int             (*remove)(struct crypt_options *options);
44
45         const char *    (*dir)(void);
46 };
47
48 void set_error_va(const char *fmt, va_list va);
49 void set_error(const char *fmt, ...);
50 const char *get_error(void);
51 void *safe_alloc(size_t size);
52 void safe_free(void *data);
53 void *safe_realloc(void *data, size_t size);
54 char *safe_strdup(const char *s);
55
56 struct hash_backend *get_hash_backend(const char *name);
57 void put_hash_backend(struct hash_backend *backend);
58 int hash(const char *backend_name, const char *hash_name,
59          char *result, size_t size,
60          const char *passphrase, size_t sizep);
61
62 struct setup_backend *get_setup_backend(const char *name);
63 void put_setup_backend(struct setup_backend *backend);
64
65 void hexprint(char *d, int n);
66
67 int sector_size_for_device(const char *device);
68 ssize_t write_blockwise(int fd, const void *buf, size_t count);
69 ssize_t read_blockwise(int fd, void *_buf, size_t count);
70 ssize_t write_lseek_blockwise(int fd, const char *buf, size_t count, off_t offset);
71
72
73 int get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
74             const char *key_file, int passphrase_fd, int timeout, int how2verify);
75
76 #endif /* INTERNAL_H */