38a03a86687aa5cda143682d6f7957ff7dbea09b
[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 #define DEFAULT_ALIGNMENT       4096
15
16 /* private struct crypt_options flags */
17
18 #define CRYPT_FLAG_FREE_DEVICE  (1 << 24)
19 #define CRYPT_FLAG_FREE_CIPHER  (1 << 25)
20
21 #define CRYPT_FLAG_PRIVATE_MASK ((unsigned int)-1 << 24)
22
23 struct hash_type {
24         char            *name;
25         void            *private;
26         int             (*fn)(void *data, int size, char *key,
27                               int sizep, const char *passphrase);
28 };
29
30 struct hash_backend {
31         const char              *name;
32         struct hash_type *      (*get_hashes)(void);
33         void                    (*free_hashes)(struct hash_type *hashes);
34 };
35
36 struct setup_backend {
37         const char      *name;
38         int             (*init)(void);
39         void            (*exit)(void);
40         int             (*create)(int reload, struct crypt_options *options,
41                                   const char *key, const char *uuid);
42         int             (*status)(int details, struct crypt_options *options,
43                                   char **key);
44         int             (*remove)(int force, struct crypt_options *options);
45
46         const char *    (*dir)(void);
47 };
48
49 void set_error_va(const char *fmt, va_list va);
50 void set_error(const char *fmt, ...);
51 const char *get_error(void);
52 void *safe_alloc(size_t size);
53 void safe_free(void *data);
54 void *safe_realloc(void *data, size_t size);
55 char *safe_strdup(const char *s);
56
57 struct hash_backend *get_hash_backend(const char *name);
58 void put_hash_backend(struct hash_backend *backend);
59 int hash(const char *backend_name, const char *hash_name,
60          char *result, size_t size,
61          const char *passphrase, size_t sizep);
62
63 struct setup_backend *get_setup_backend(const char *name);
64 void put_setup_backend(struct setup_backend *backend);
65
66 void hexprint(char *d, int n);
67
68 int sector_size_for_device(const char *device);
69 ssize_t write_blockwise(int fd, const void *buf, size_t count);
70 ssize_t read_blockwise(int fd, void *_buf, size_t count);
71 ssize_t write_lseek_blockwise(int fd, const char *buf, size_t count, off_t offset);
72
73
74 int get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
75             const char *key_file, int passphrase_fd, int timeout, int how2verify);
76
77 #endif /* INTERNAL_H */