Replaced system SQLite with SQLCipher to support encrypted database

This commit is contained in:
Oleksii Zghurskyi
2025-06-07 18:11:17 +03:00
parent f4198d62a7
commit 177d74700f
534 changed files with 362771 additions and 21 deletions

View File

@@ -0,0 +1,31 @@
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#include "tomcrypt_private.h"
/**
@file x25519_export.c
Export a X25519 key to a binary packet, Steffen Jaeckel
*/
#ifdef LTC_CURVE25519
/**
Export a X25519 key to a binary packet
@param out [out] The destination for the key
@param outlen [in/out] The max size and resulting size of the X25519 key
@param type Which type of key (PK_PRIVATE, PK_PUBLIC|PK_STD or PK_PUBLIC)
@param key The key you wish to export
@return CRYPT_OK if successful
*/
int x25519_export( unsigned char *out, unsigned long *outlen,
int which,
const curve25519_key *key)
{
LTC_ARGCHK(key != NULL);
if (key->pka != LTC_PKA_X25519) return CRYPT_PK_INVALID_TYPE;
return ec25519_export(out, outlen, which, key);
}
#endif

View File

@@ -0,0 +1,35 @@
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#include "tomcrypt_private.h"
/**
@file x25519_import.c
Import a X25519 key from a SubjectPublicKeyInfo, Steffen Jaeckel
*/
#ifdef LTC_CURVE25519
/**
Import a X25519 key
@param in The packet to read
@param inlen The length of the input packet
@param key [out] Where to import the key to
@return CRYPT_OK if successful, on error all allocated memory is freed automatically
*/
int x25519_import(const unsigned char *in, unsigned long inlen, curve25519_key *key)
{
int err;
unsigned long key_len;
LTC_ARGCHK(in != NULL);
LTC_ARGCHK(key != NULL);
key_len = sizeof(key->pub);
if ((err = x509_decode_subject_public_key_info(in, inlen, LTC_OID_X25519, key->pub, &key_len, LTC_ASN1_EOL, NULL, 0uL)) == CRYPT_OK) {
key->type = PK_PUBLIC;
key->pka = LTC_PKA_X25519;
}
return err;
}
#endif

View File

@@ -0,0 +1,32 @@
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#include "tomcrypt_private.h"
/**
@file x25519_import_pkcs8.c
Import a X25519 key in PKCS#8 format, Steffen Jaeckel
*/
#ifdef LTC_CURVE25519
int x25519_import_pkcs8_asn1(ltc_asn1_list *alg_id, ltc_asn1_list *priv_key,
curve25519_key *key)
{
return ec25519_import_pkcs8_asn1(alg_id, priv_key, LTC_OID_X25519, key);
}
/**
Import a X25519 private key in PKCS#8 format
@param in The packet to import from
@param inlen It's length (octets)
@param pw_ctx The password context when decrypting the private key
@param key [out] Destination for newly imported key
@return CRYPT_OK if successful, on error all allocated memory is freed automatically
*/
int x25519_import_pkcs8(const unsigned char *in, unsigned long inlen,
const password_ctx *pw_ctx,
curve25519_key *key)
{
return ec25519_import_pkcs8(in, inlen, pw_ctx, LTC_OID_X25519, key);
}
#endif

View File

@@ -0,0 +1,41 @@
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#include "tomcrypt_private.h"
/**
@file x25519_import_raw.c
Set the parameters of a X25519 key, Steffen Jaeckel
*/
#ifdef LTC_CURVE25519
/**
Set the parameters of a X25519 key
@param in The key
@param inlen The length of the key
@param which Which type of key (PK_PRIVATE or PK_PUBLIC)
@param key [out] Destination of the key
@return CRYPT_OK if successful
*/
int x25519_import_raw(const unsigned char *in, unsigned long inlen, int which, curve25519_key *key)
{
LTC_ARGCHK(in != NULL);
LTC_ARGCHK(inlen == 32uL);
LTC_ARGCHK(key != NULL);
if (which == PK_PRIVATE) {
XMEMCPY(key->priv, in, sizeof(key->priv));
tweetnacl_crypto_scalarmult_base(key->pub, key->priv);
} else if (which == PK_PUBLIC) {
XMEMCPY(key->pub, in, sizeof(key->pub));
} else {
return CRYPT_INVALID_ARG;
}
key->pka = LTC_PKA_X25519;
key->type = which;
return CRYPT_OK;
}
#endif

View File

@@ -0,0 +1,45 @@
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#include "tomcrypt_private.h"
/**
@file x25519_import_x509.c
Import a X25519 key from a X.509 certificate, Steffen Jaeckel
*/
#ifdef LTC_CURVE25519
static int s_x25519_decode(const unsigned char *in, unsigned long inlen, curve25519_key *key)
{
if (inlen != sizeof(key->pub)) return CRYPT_PK_INVALID_SIZE;
XMEMCPY(key->pub, in, sizeof(key->pub));
return CRYPT_OK;
}
/**
Import a X25519 public key from a X.509 certificate
@param in The DER encoded X.509 certificate
@param inlen The length of the certificate
@param key [out] Where to import the key to
@return CRYPT_OK if successful, on error all allocated memory is freed automatically
*/
int x25519_import_x509(const unsigned char *in, unsigned long inlen, curve25519_key *key)
{
int err;
LTC_ARGCHK(in != NULL);
LTC_ARGCHK(key != NULL);
if ((err = x509_decode_public_key_from_certificate(in, inlen,
LTC_OID_X25519,
LTC_ASN1_EOL, NULL, NULL,
(public_key_decode_cb)s_x25519_decode, key)) != CRYPT_OK) {
return err;
}
key->type = PK_PUBLIC;
key->pka = LTC_PKA_X25519;
return err;
}
#endif

View File

@@ -0,0 +1,42 @@
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#include "tomcrypt_private.h"
/**
@file x25519_make_key.c
Create a X25519 key, Steffen Jaeckel
*/
#ifdef LTC_CURVE25519
/**
Create a X25519 key
@param prng An active PRNG state
@param wprng The index of the PRNG desired
@param key [out] Destination of a newly created private key pair
@return CRYPT_OK if successful
*/
int x25519_make_key(prng_state *prng, int wprng, curve25519_key *key)
{
int err;
LTC_ARGCHK(prng != NULL);
LTC_ARGCHK(key != NULL);
if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
return err;
}
if (prng_descriptor[wprng].read(key->priv, sizeof(key->priv), prng) != sizeof(key->priv)) {
return CRYPT_ERROR_READPRNG;
}
tweetnacl_crypto_scalarmult_base(key->pub, key->priv);
key->type = PK_PRIVATE;
key->pka = LTC_PKA_X25519;
return err;
}
#endif

View File

@@ -0,0 +1,43 @@
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#include "tomcrypt_private.h"
/**
@file x25519_shared_secret.c
Create a X25519 shared secret, Steffen Jaeckel
*/
#ifdef LTC_CURVE25519
/**
Create a X25519 shared secret.
@param private_key The private X25519 key in the pair
@param public_key The public X25519 key in the pair
@param out [out] The destination of the shared data
@param outlen [in/out] The max size and resulting size of the shared data.
@return CRYPT_OK if successful
*/
int x25519_shared_secret(const curve25519_key *private_key,
const curve25519_key *public_key,
unsigned char *out, unsigned long *outlen)
{
LTC_ARGCHK(private_key != NULL);
LTC_ARGCHK(public_key != NULL);
LTC_ARGCHK(out != NULL);
LTC_ARGCHK(outlen != NULL);
if (public_key->pka != LTC_PKA_X25519) return CRYPT_PK_INVALID_TYPE;
if (private_key->type != PK_PRIVATE) return CRYPT_PK_INVALID_TYPE;
if (*outlen < 32uL) {
*outlen = 32uL;
return CRYPT_BUFFER_OVERFLOW;
}
tweetnacl_crypto_scalarmult(out, private_key->priv, public_key->pub);
*outlen = 32uL;
return CRYPT_OK;
}
#endif