-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbcvencrypt.h
87 lines (79 loc) · 2.85 KB
/
bcvencrypt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
** 2023-06-20
**
******************************************************************************
**
** This file contains declarations for the public interface to code in
** bcvencrypt.c. Alternative encryption schemes may be supported by
** replacing bcvencrypt.c with an alternative implementation of this
** interface. The four interface functions are:
**
** bcvEncryptionKeyNew:
** Convert a 128 bit (16-byte) binary key to a compiled key object of
** type BcvEncryptionKey.
**
** bcvEncryptionKeyFree:
** Free a compiled key object created by bcvEncryptionKeyNew().
**
** bcvEncrypt:
** Encrypt a buffer using the supplied compiled key object.
**
** bcvDecrypt:
** Decrypt a buffer using the supplied compiled key object.
**
** See below for futher details.
*/
/*
** Encryption uses 16 byte (128-bit) keys. This is part of the interface
** assumed by other modules in this project. It is not possible to change
** this simply by replacing the contents of bcvencrypt.c.
*/
#define BCV_KEY_SIZE 16
/*
** BcvEncryptionKey is an opaque type used to represent a compiled
** BCV_KEY_SIZE byte binary encryption key. BcvEncryptionKey objects
** are allocated using bcvEncryptionKeyNew() and freed using
** bcvEncryptionKeyFree().
*/
typedef struct BcvEncryptionKey BcvEncryptionKey;
/*
** The argument passed to this function points to a buffer containing
** a BCV_KEY_SIZE byte binary key. This function allocates and returns a
** BcvEncryptionKey object that may be used to encrypt or decrypt buffers
** using that key. If an out-of-memory or other error occurs, NULL is
** returned.
*/
BcvEncryptionKey *bcvEncryptionKeyNew(const unsigned char *aKey);
/*
** Free an object returned by an earlier call to bcvEncryptionKeyNew().
*/
void bcvEncryptionKeyFree(BcvEncryptionKey *pKey);
/*
** Parameter aData points to a buffer nData bytes in size. This function
** encrypts the buffer in place. SQLITE_OK is returned if successful,
** or an SQLite error code otherwise.
**
** The buffer is encrypted according to the key passed as the first
** argument. Parameter aNonce points to a BCV_KEY_SIZE buffer containing
** a nonce, or initialization vector (IV), to use for the encryption.
*/
int bcvEncrypt(
BcvEncryptionKey *pKey,
const unsigned char *aNonce,
unsigned char *aData, int nData
);
/*
** Parameter aData points to a buffer nData bytes in size. This function
** decrypts the buffer in place. SQLITE_OK is returned if successful,
** or an SQLite error code otherwise.
**
** The buffer is encrypted according to the key passed as the first
** argument. Parameter aNonce points to a BCV_KEY_SIZE buffer containing
** the nonce, or initialization vector (IV), that was passed to the
** bcvEncrypt() function when the buffer was first encrypted.
*/
int bcvDecrypt(
BcvEncryptionKey *pKey,
const unsigned char *aNonce,
unsigned char *aData, int nData
);