1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-05 00:28:52 +02:00

Define cipher magic size with sizeof() rather than using a constant.

This commit is contained in:
David Steele
2018-08-14 16:08:58 -04:00
parent 6643afe9a8
commit 9e3273fdf9
3 changed files with 7 additions and 3 deletions

View File

@ -146,6 +146,10 @@
<release-item> <release-item>
<p>Remove redundant lines from embedded Perl by combining blank lines.</p> <p>Remove redundant lines from embedded Perl by combining blank lines.</p>
</release-item> </release-item>
<release-item>
<p>Define cipher magic size with <code>sizeof()</code> rather than using a constant.</p>
</release-item>
</release-development-list> </release-development-list>
</release-core-list> </release-core-list>

View File

@ -19,7 +19,7 @@ Header constants and sizes
// Magic constant for salted encrypt. Only salted encrypt is done here, but this constant is required for compatibility with the // Magic constant for salted encrypt. Only salted encrypt is done here, but this constant is required for compatibility with the
// openssl command-line tool. // openssl command-line tool.
#define CIPHER_BLOCK_MAGIC "Salted__" #define CIPHER_BLOCK_MAGIC "Salted__"
#define CIPHER_BLOCK_MAGIC_SIZE 8 #define CIPHER_BLOCK_MAGIC_SIZE (sizeof(CIPHER_BLOCK_MAGIC) - 1)
// Total length of cipher header // Total length of cipher header
#define CIPHER_BLOCK_HEADER_SIZE (CIPHER_BLOCK_MAGIC_SIZE + PKCS5_SALT_LEN) #define CIPHER_BLOCK_HEADER_SIZE (CIPHER_BLOCK_MAGIC_SIZE + PKCS5_SALT_LEN)

View File

@ -81,12 +81,12 @@ testRun(void)
encryptSize += cipherBlockProcess( encryptSize += cipherBlockProcess(
blockEncrypt, (unsigned char *)TEST_PLAINTEXT, strlen(TEST_PLAINTEXT), encryptBuffer + encryptSize); blockEncrypt, (unsigned char *)TEST_PLAINTEXT, strlen(TEST_PLAINTEXT), encryptBuffer + encryptSize);
TEST_RESULT_INT( TEST_RESULT_INT(
encryptSize, CIPHER_BLOCK_HEADER_SIZE + EVP_CIPHER_block_size(blockEncrypt->cipher), encryptSize, CIPHER_BLOCK_HEADER_SIZE + (size_t)EVP_CIPHER_block_size(blockEncrypt->cipher),
"cipher size increases by one block"); "cipher size increases by one block");
encryptSize += cipherBlockFlush(blockEncrypt, encryptBuffer + encryptSize); encryptSize += cipherBlockFlush(blockEncrypt, encryptBuffer + encryptSize);
TEST_RESULT_INT( TEST_RESULT_INT(
encryptSize, CIPHER_BLOCK_HEADER_SIZE + (EVP_CIPHER_block_size(blockEncrypt->cipher) * 2), encryptSize, CIPHER_BLOCK_HEADER_SIZE + (size_t)(EVP_CIPHER_block_size(blockEncrypt->cipher) * 2),
"cipher size increases by one block on flush"); "cipher size increases by one block on flush");
cipherBlockFree(blockEncrypt); cipherBlockFree(blockEncrypt);