SEcube open-source SDK
SEfile_C_interface.h
Go to the documentation of this file.
1 
9 #ifndef SEFILE_C_INTERFACE_H_
10 #define SEFILE_C_INTERFACE_H_
11 
12 #include <stdint.h>
13 
14 #ifdef __linux__
15  #include <sys/types.h> /* open, seek */
17  #include <sys/stat.h> /* open, create */
18  #include <fcntl.h> /* open, create */
19  #include <unistd.h> /* write, read, seek, close */
20  #include <libgen.h>
21  #include <dirent.h>
23 #elif _WIN32
24  #undef UNICODE
25  #undef _UNICODE
26  #ifdef __MINGW32__
27  #include <windows.h>
28  #else
29  #include <Windows.h>
30  #endif
31 #elif __APPLE__
32  #include <fcntl.h> /* open, create */
33  #include <sys/stat.h> /* open */
34  #include <unistd.h> /* write, read, seek, close */
35  #include <sys/types.h> /* open, read */
36  #include <sys/uio.h> /* read */
37  #include <dirent.h>
38 #endif
39 
46  #ifdef __linux__
48  #define SEFILE_READ O_RDONLY
49  #define SEFILE_WRITE O_RDWR
50  #elif _WIN32
51  #define SEFILE_READ GENERIC_READ
52  #define SEFILE_WRITE GENERIC_READ | GENERIC_WRITE
53  #elif __APPLE__
54  #define SEFILE_READ O_RDONLY
55  #define SEFILE_WRITE O_RDWR
56  #endif
57 
66  #ifdef __linux__
68  #define SEFILE_NEWFILE O_CREAT | O_TRUNC
69  #define SEFILE_OPEN 0
70  #elif _WIN32
71  #define SEFILE_NEWFILE CREATE_ALWAYS
72  #define SEFILE_OPEN OPEN_EXISTING
73  #elif __APPLE__
74  #define SEFILE_NEWFILE O_CREAT | O_TRUNC
75  #define SEFILE_OPEN 0
76  #endif
77 
86  #ifdef __linux__
88  #define SEFILE_BEGIN SEEK_SET
89  #define SEFILE_CURRENT SEEK_CUR
90  #define SEFILE_END SEEK_END
91  #elif _WIN32
92  #define SEFILE_BEGIN FILE_BEGIN
93  #define SEFILE_CURRENT FILE_CURRENT
94  #define SEFILE_END FILE_END
95  #elif __APPLE__
96  #define SEFILE_BEGIN SEEK_SET
97  #define SEFILE_CURRENT SEEK_CUR
98  #define SEFILE_END SEEK_END
99  #endif
100 
108  #define SEFILE_ENV_ALREADY_SET 15
110  #define SEFILE_ENV_WRONG_PARAMETER 16
111  #define SEFILE_ENV_MALLOC_ERROR 17
112  #define SEFILE_ENV_NOT_SET 18
113  #define SEFILE_SECTOR_MALLOC_ERR 19
114  #define SEFILE_GET_FILEPOINTER_ERR 20
115  #define SEFILE_HANDLE_MALLOC_ERR 21
116  #define SEFILE_CLOSE_HANDLE_ERR 22
117  #define SEFILE_CREATE_ERROR 23
118  #define SEFILE_OPEN_ERROR 24
119  #define SEFILE_WRITE_ERROR 25
120  #define SEFILE_SEEK_ERROR 26
121  #define SEFILE_READ_ERROR 27
122  #define SEFILE_ILLEGAL_SEEK 28
123  #define SEFILE_FILESIZE_ERROR 29
124  #define SEFILE_BUFFER_MALLOC_ERR 30
125  #define SEFILE_FILENAME_DEC_ERROR 31
126  #define SEFILE_FILENAME_ENC_ERROR 32
127  #define SEFILE_DIRNAME_ENC_ERROR 33
128  #define SEFILE_DIRNAME_DEC_ERROR 34
129  #define SEFILE_DIRNAME_TOO_LONG 35
130  #define SEFILE_MKDIR_ERROR 36
131  #define SEFILE_LS_ERROR 37
132  #define SEFILE_ENV_INIT_ERROR 38
133  #define SEFILE_ENV_UPDATE_ERROR 39
134  #define SEFILE_INTEGRITY_ERROR 40
135  #define SEFILE_NAME_NOT_VALID 41
136  #define SEFILE_TRUNCATE_ERROR 42
137  #define SEFILE_DEVICE_SN_MISMATCH 43
138  #define SEFILE_KEYID_NOT_PRESENT 44
139  #define SEFILE_ALGID_NOT_PRESENT 45
140  #define SEFILE_PATH_TOO_LONG 46
141  #define SEFILE_SYNC_ERR 47
142  #define SEFILE_SIGNATURE_MISMATCH 48
143  #define SEFILE_RECRYPT_ERROR 49
144 
154  #ifndef SEFILE_SECTOR_SIZE
156  #define SEFILE_SECTOR_SIZE 512
157  #endif
158  #define SEFILE_BLOCK_SIZE B5_AES_BLK_SIZE
159  #define SEFILE_SECTOR_DATA_SIZE (SEFILE_SECTOR_SIZE - B5_SHA256_DIGEST_SIZE)
160  #define SEFILE_LOGIC_DATA (SEFILE_SECTOR_DATA_SIZE-2)
161  #define SEFILE_SECTOR_OVERHEAD (SEFILE_SECTOR_SIZE-SEFILE_LOGIC_DATA)
162 
165 #define MAX_PATHNAME 256
166 typedef struct SEFILE_HANDLE* SEFILE_FHANDLE;
168 #ifdef __cplusplus // these functions must be callable from C (SQLite)
169 extern "C" {
170 #endif
171 
180 uint16_t crypto_filename(char *path, char *enc_name, uint16_t *encoded_length);
181 
191  uint16_t c_sql_secure_open(char *path, SEFILE_FHANDLE *hFile, int32_t mode, int32_t creation);
193  uint16_t c_sql_secure_write(SEFILE_FHANDLE *hFile, uint8_t * dataIn, uint32_t dataIn_len);
194  uint16_t c_sql_secure_read(SEFILE_FHANDLE *hFile, uint8_t * dataOut, uint32_t dataOut_len, uint32_t * bytesRead);
195  uint16_t c_sql_secure_seek(SEFILE_FHANDLE *hFile, int32_t offset, int32_t *position, uint8_t whence);
196  uint16_t c_sql_secure_truncate(SEFILE_FHANDLE *hFile, uint32_t size);
197  uint16_t c_sql_secure_getfilesize(char *path, uint32_t * position);
198  uint16_t c_secure_sync(SEFILE_FHANDLE *hFile);
199  uint16_t c_secure_close(SEFILE_FHANDLE *hFile);
201 
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 #endif
SEFILE_HANDLE
The SEFILE_HANDLE struct This abstract data type is used to hide from higher level of abstraction its...
Definition: SEfile.h:27
crypto_filename
uint16_t crypto_filename(char *path, char *enc_name, uint16_t *encoded_length)
This function computes the encrypted name of the file specified as path.
Definition: SEfile.cpp:1410