2

将 Botan 加密与 botansqlite3 一起使用时,性能的最佳配置设置是什么?

或者

如何配置 Botansqlite3 以使用 CAST5?

我目前正在使用 AES,它太慢了。我的用例是游戏。

我正在寻找弱或适度的加密来保护我的游戏数据(而不是最终用户数据),因此安全性与其说是性能相比,不如说是一个考虑因素。

这是我当前的 BotanSqlite3 codec.h

/*These constants can be used to tweak the codec behavior as follows */

//BLOCK_CIPHER_STR: Cipher and mode used for encrypting the database
//make sure to add "/NoPadding" for modes that use padding schemes
const string BLOCK_CIPHER_STR = "Twofish/XTS";

//PBKDF_STR: Key derivation function used to derive both the encryption
//and IV derivation keys from the given database passphrase
const string PBKDF_STR = "PBKDF2(SHA-160)";

//SALT_STR: Hard coded salt used to derive the key from the passphrase.
const string SALT_STR = "&g#nB'9]";

//SALT_SIZE: Size of the salt in bytes (as given in SALT_STR)
const int SALT_SIZE = 64/8; //64 bit, 8 byte salt

//MAC_STR: CMAC used to derive the IV that is used for db page
//encryption
const string MAC_STR = "CMAC(Twofish)";

//PBKDF_ITERATIONS: Number of hash iterations used in the key derivation
//process.
const int PBKDF_ITERATIONS = 10000;

//KEY_SIZE: Size of the encryption key. Note that XTS splits the key
//between two ciphers, so if you're using XTS, double the intended key
//size. (ie, "AES-128/XTS" should have a 256 bit KEY_SIZE)
const int KEY_SIZE = 512/8; //512 bit, 64 byte key. (256 bit XTS key)

//IV_DERIVATION_KEY_SIZE: Size of the key used with the CMAC (MAC_STR)
//above.
const int IV_DERIVATION_KEY_SIZE = 256/8; //256 bit, 32 byte key

//This is definited in sqlite.h and very unlikely to change
#define SQLITE_MAX_PAGE_SIZE 32768

我相信我需要找到 BLOCK_CIPHER_STR、PBKDF_STR、MAC_STR、KEY_SIZE 和 IV_DERIVATION_KEY_SIZE 的替代品来重新配置 BotanSqlite3 以使用不同的编解码器。

我在这里找到了对 Botan 编解码器性能的广泛比较测试:http: //panthema.net/2008/0714-cryptography-speedtest-comparison/crypto-speedtest-0.1/results/cpu-sidebyside-comparison-3x2.pdf#page= 5

但是,测试是直接使用 Botan 完成的,而不是我打算使用的 botansqlite3。从图表来看,从性能角度来看,一个好的候选者似乎是 CAST5。

  • 有问题的数据库是 300KB,主要是带有一些文本块的 INTEGER 字段。
  • 我正在按照botansqlite3名声的OlivierJG的建议配置Botan,使用合并

    './configure.py --no-autoload --enable-modules=twofish,xts,pbkdf2,cmac,sha1 --gen-amalgamation --cc=msvc --os=win32 --cpu=x86 --disable-共享--禁用-asm'

参考:

http://github.com/OlivierJG/botansqlite3 - botansqlite3 是 SQLite3 的加密编解码器,可以使用 Botan 中的任何算法进行加密

http://www.sqlite.org - sqlite3 是一个跨平台的 SQL 数据库

http://botan.randombit.net/ - botan 是一个 C++ 加密库,支持多种编解码器

4

1 回答 1

2

你可以让 CAST-128(或者我称之为 CAST5)工作,它是一个分组密码。

最好的选择是上面有不同的密钥大小配置。

双鱼的速度非常快。

感谢“Olivier JG”提供的所有优秀代码。

于 2013-11-02T19:52:28.480 回答