SEcube open-source SDK
Macros | Typedefs | Functions
SEfile_C_interface.h File Reference

This file includes some of the constants, return values and public functions used for implementing a secure file system. More...

#include <stdint.h>
#include <Windows.h>

Go to the source code of this file.

Macros

#define MAX_PATHNAME   256
 
Use this values as mode parameter for secure_open().
#define SEFILE_READ   GENERIC_READ
 
#define SEFILE_WRITE   GENERIC_READ | GENERIC_WRITE
 
Use this values as creation parameter for secure_open().
#define SEFILE_NEWFILE   CREATE_ALWAYS
 
#define SEFILE_OPEN   OPEN_EXISTING
 
Use this values as whence parameter for secure_seek().
#define SEFILE_BEGIN   FILE_BEGIN
 
#define SEFILE_CURRENT   FILE_CURRENT
 
#define SEFILE_END   FILE_END
 
Returned error values.
#define SEFILE_ENV_ALREADY_SET   15
 
#define SEFILE_ENV_WRONG_PARAMETER   16
 
#define SEFILE_ENV_MALLOC_ERROR   17
 
#define SEFILE_ENV_NOT_SET   18
 
#define SEFILE_SECTOR_MALLOC_ERR   19
 
#define SEFILE_GET_FILEPOINTER_ERR   20
 
#define SEFILE_HANDLE_MALLOC_ERR   21
 
#define SEFILE_CLOSE_HANDLE_ERR   22
 
#define SEFILE_CREATE_ERROR   23
 
#define SEFILE_OPEN_ERROR   24
 
#define SEFILE_WRITE_ERROR   25
 
#define SEFILE_SEEK_ERROR   26
 
#define SEFILE_READ_ERROR   27
 
#define SEFILE_ILLEGAL_SEEK   28
 
#define SEFILE_FILESIZE_ERROR   29
 
#define SEFILE_BUFFER_MALLOC_ERR   30
 
#define SEFILE_FILENAME_DEC_ERROR   31
 
#define SEFILE_FILENAME_ENC_ERROR   32
 
#define SEFILE_DIRNAME_ENC_ERROR   33
 
#define SEFILE_DIRNAME_DEC_ERROR   34
 
#define SEFILE_DIRNAME_TOO_LONG   35
 
#define SEFILE_MKDIR_ERROR   36
 
#define SEFILE_LS_ERROR   37
 
#define SEFILE_ENV_INIT_ERROR   38
 
#define SEFILE_ENV_UPDATE_ERROR   39
 
#define SEFILE_INTEGRITY_ERROR   40
 
#define SEFILE_NAME_NOT_VALID   41
 
#define SEFILE_TRUNCATE_ERROR   42
 
#define SEFILE_DEVICE_SN_MISMATCH   43
 
#define SEFILE_KEYID_NOT_PRESENT   44
 
#define SEFILE_ALGID_NOT_PRESENT   45
 
#define SEFILE_PATH_TOO_LONG   46
 
#define SEFILE_SYNC_ERR   47
 
#define SEFILE_SIGNATURE_MISMATCH   48
 
#define SEFILE_RECRYPT_ERROR   49
 
Constant used to define sector structure.
#define SEFILE_SECTOR_SIZE   512
 
#define SEFILE_BLOCK_SIZE   B5_AES_BLK_SIZE
 
#define SEFILE_SECTOR_DATA_SIZE   (SEFILE_SECTOR_SIZE - B5_SHA256_DIGEST_SIZE)
 
#define SEFILE_LOGIC_DATA   (SEFILE_SECTOR_DATA_SIZE-2)
 
#define SEFILE_SECTOR_OVERHEAD   (SEFILE_SECTOR_SIZE-SEFILE_LOGIC_DATA)
 

Typedefs

typedef struct SEFILE_HANDLESEFILE_FHANDLE
 

Functions

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. More...
 
Wrappers of SEfile APIs for the SQLite DB engine.

These APIs are C wrappers around the C++ APIs of the SEcure Database library. They are called automatically by the custom VFS of SQLite; they are required by SEkey and by the SEcure Database library. They must not be used directly.

uint16_t c_sql_secure_open (char *path, SEFILE_FHANDLE *hFile, int32_t mode, int32_t creation)
 
uint16_t c_sql_secure_write (SEFILE_FHANDLE *hFile, uint8_t *dataIn, uint32_t dataIn_len)
 
uint16_t c_sql_secure_read (SEFILE_FHANDLE *hFile, uint8_t *dataOut, uint32_t dataOut_len, uint32_t *bytesRead)
 
uint16_t c_sql_secure_seek (SEFILE_FHANDLE *hFile, int32_t offset, int32_t *position, uint8_t whence)
 
uint16_t c_sql_secure_truncate (SEFILE_FHANDLE *hFile, uint32_t size)
 
uint16_t c_sql_secure_getfilesize (char *path, uint32_t *position)
 
uint16_t c_secure_sync (SEFILE_FHANDLE *hFile)
 
uint16_t c_secure_close (SEFILE_FHANDLE *hFile)
 

Detailed Description

This file includes some of the constants, return values and public functions used for implementing a secure file system.

Authors
Matteo Fornero, Francesco Giavatto, Nicolo Maunero, Giulio Scalia
Date
17/09/2016

This header file was created moving part of the content of SEfile.h here. This separate header file is required because it must be included by SQLite in order to implement SEkey and to support encrypted SQLite databases based on SEfile.

Macro Definition Documentation

◆ MAX_PATHNAME

#define MAX_PATHNAME   256

Maximum length for path in OS.

Typedef Documentation

◆ SEFILE_FHANDLE

typedef struct SEFILE_HANDLE* SEFILE_FHANDLE

Pointer to the data structure used by SEfile to wrap a traditional OS-dependent file descriptor taking into account the overhead of SEfile.

Function Documentation

◆ 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.

Parameters
[in]pathAbsolute or relative path of a file (it must be plaintext, it cannot be a directory).
[out]enc_namePre-allocated char array where the encrypted filename should be stored.
[out]encoded_lengthLength of the encrypted filename.
Returns
The function returns 0 in case of success. See error values for error list.

The encrypted filename is the SHA-256 digest of the original name. It is expressed as a string of 64 characters (HEX format).