SEcube open-source SDK
Classes | Macros | Functions
SEcureDB.h File Reference

This header contains prototypes, constants and structures that are needed to implement the encrypted SQLite database (a.k.a. SEcure Database) based on SEfile. More...

#include "SEfile.h"

Go to the source code of this file.

Classes

struct  SEFILE_SQL_SECTOR
 The SEFILE_SQL_SECTOR struct This data struct is the actual sector organization for encrypted SQLite databases. The total size should ALWAYS be equal to SEFILE_SQL_SECTOR_SIZE. The first sector is used to hold ONLY the header. Thanks to the union data type, the developer can simply declare a sector and then choose if it is the header sector or not. This sector is similar to the original one but with higher overhead. More...
 

Macros

#define SEFILE_SQL_SECTOR_SIZE   4096
 
#define SEFILE_SQL_LOGIC_DATA   (SEFILE_SQL_SECTOR_SIZE/2)
 
#define SEFILE_LEN_FIELD   2
 
#define SEFILE_SQL_PADDING_LEN   14
 
#define SEFILE_SQL_OVERHEAD_LEN   (SEFILE_SQL_SECTOR_SIZE - SEFILE_SQL_LOGIC_DATA - B5_SHA256_DIGEST_SIZE - SEFILE_LEN_FIELD - SEFILE_SQL_PADDING_LEN)
 
#define SEFILE_SQL_SECTOR_DATA_SIZE   (SEFILE_SQL_SECTOR_SIZE - B5_SHA256_DIGEST_SIZE - SEFILE_SQL_OVERHEAD_LEN)
 
#define SEFILE_SQL_SECTOR_OVERHEAD   (SEFILE_SQL_SECTOR_SIZE - SEFILE_SQL_LOGIC_DATA)
 

Functions

uint16_t securedb_get_secure_context (std::string &filename, std::string *keyid, uint16_t *algo)
 Same as get_secure_context() but for encrypted SQLite databases.
 
uint16_t securedb_ls (std::string &path, std::vector< std::pair< std::string, std::string >> &list, L1 *SEcubeptr)
 Same as secure_ls() but for encrypted SQLite databases.
 
uint16_t securedb_decrypt_filename (std::string &path, char *filename, L1 *SEcubeptr)
 Same as decrypt_filename() but for encrypted SQLite databases.
 
uint16_t securedb_recrypt (std::string &path, uint32_t key, L1 *SEcubeptr)
 Same as secure_recrypt() but for encrypted SQLite databases.
 
size_t securedb_pos_to_cipher_block (size_t current_position)
 Same as pos_to_cipher_block() but for encrypted SQLite databases.
 
uint16_t securedb_secure_getfilesize (char *path, uint32_t *position)
 Same as secure_getfilesize() but for encrypted SQLite databases.
 

Detailed Description

This header contains prototypes, constants and structures that are needed to implement the encrypted SQLite database (a.k.a. SEcure Database) based on SEfile.

Author
Fornero Matteo
Date
25/11/2019

Macro Definition Documentation

◆ SEFILE_LEN_FIELD

#define SEFILE_LEN_FIELD   2

This is the dimension of the len attribute in a SEfile sector. It is an uint16_t value so it is 2 bytes.

◆ SEFILE_SQL_LOGIC_DATA

#define SEFILE_SQL_LOGIC_DATA   (SEFILE_SQL_SECTOR_SIZE/2)

This is the amount of data reserved to SQLite in the SEfile implementation customized to work with SQLite. It must be a power of 2, the closest power of 2 which is smaller than the dimension of the SEfile sector is the dimension of the sector itself divided by 2.

◆ SEFILE_SQL_OVERHEAD_LEN

#define SEFILE_SQL_OVERHEAD_LEN   (SEFILE_SQL_SECTOR_SIZE - SEFILE_SQL_LOGIC_DATA - B5_SHA256_DIGEST_SIZE - SEFILE_LEN_FIELD - SEFILE_SQL_PADDING_LEN)

This is the length of the overhead field that is included in each SEfile sector when SEfile is used for SQLite (this field does not exists in standard SEfile). The overhead field is used as "padding" to reach a sector dimension which is a power of 2 (because the sector itself must include a field reserved for SQLite data which is a power of 2, but it must also include the signature and the len attribute so we must go from the power of 2 reserved for SQLite data up to the next power of two).

◆ SEFILE_SQL_PADDING_LEN

#define SEFILE_SQL_PADDING_LEN   14

This is a fixed-length padding that must be added to each SEfile sector to make it a multiple of 16 (which is the block length of AES used for encryption by SEfile). This is required only by the SEfile version customized to work with SQLite, it is not needed for the standard SEfile implementation. The value is 14 because the actual SQLite data inside the sector are always a power of 2 (so they are a multiple of 16) but we must also encrypt the len attribute which is 2 bytes so we need other 14 bytes to reach a new size which is a multiple of 16.

◆ SEFILE_SQL_SECTOR_DATA_SIZE

#define SEFILE_SQL_SECTOR_DATA_SIZE   (SEFILE_SQL_SECTOR_SIZE - B5_SHA256_DIGEST_SIZE - SEFILE_SQL_OVERHEAD_LEN)

This is the amount of data which will be encoded/decoded by SEfile. Therefore it includes the SQLite data, the len field and the padding used to reach a size that is multiple of the basic encryption block size.

◆ SEFILE_SQL_SECTOR_OVERHEAD

#define SEFILE_SQL_SECTOR_OVERHEAD   (SEFILE_SQL_SECTOR_SIZE - SEFILE_SQL_LOGIC_DATA)

This is the quantity of bytes of a sector which is not strictly reserved to the actual file content.

◆ SEFILE_SQL_SECTOR_SIZE

#define SEFILE_SQL_SECTOR_SIZE   4096

This is the size of the sector used by SEfile when the file itself contains a SQLite database. This value must be a power of 2 (512, 1024, 2048, 4096 recommended values). If you change this value, you MUST also change the same value defined at the very beginning of the file sqlite3.c.