ENCFILEtypedef struct ENCFILE_t ENCFILE;
ENCFILE is an opaque handle to an encrypted file, equivalent to
stdio's FILE.
enc_fopen()ENCFILE *enc_fopen(const char *filename, const char *rwmode, const char *passphrase);
enc_fopen() opens an encrypted file filename, encrypted with
passphrase, for reading or writing depending on rwmode. Other
than the passphrase parameter, it is equivalent to fopen().
enc_add_indexint enc_add_index(ENCFILE *ef, const char *indexfile, const char *passphrase, int index_mode);
Adds an "encryption state index" (ENCINDEX) to a file ef which has
been opened for reading. After the successfull completion of this call, you
can randomly access any location in the file using enc_fseek().
Parameter index_mode determines the source of the encryption state
index. If it contains the INDEX_LOAD flag, an attempt will be made to
load it from file indexfile, which is assumed to be encrypted with
passphrase. If successfull, the enc_add_index will return 0.
If index_mode has the INDEX_CREATE bit set, index will
be constructed by internally decrypting the whole file ef. Finally, if
index_mode has the INDEX_SAVE bit set, the index will
be encrypted with passphrase and saved to indexfile file.
INDEX_* flags can be OR-ed, in which case first the
INDEX_LOAD flag will be tested, then INDEX_CREATE and finally
INDEX_SAVE. A typical use would be:
enc_add_index(ef, "test.txt.ix", passphrase, INDEX_LOAD | INDEX_CREATE | INDEX_SAVE);
where encio will first attempt to load the index from
test.txt.ix and if that fails it will create the index, and store it
to test.txt.ix.
stdio-like functionsint enc_fread(void *out, int size, int count, ENCFILE *ef);
int enc_fwrite(void *data, int size, int count, ENCFILE *ef);
int enc_fseek(ENCFILE *ef, long at, int dir);
int enc_ftell(ENCFILE *ef);
void enc_fflush(ENCFILE *ef);
int enc_feof(ENCFILE *ef);
int enc_fclose(ENCFILE *ef);
void enc_info(ENCFILE *ef);
All these functions function exactly like their stdio counterparts.