1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-24 06:01:07 +03:00

pgcrypto: Add support for CFB mode in AES encryption

Cipher Feedback Mode, CFB, is a self-synchronizing stream cipher which
is very similar to CBC performed in reverse. Since OpenSSL supports it,
we can easily plug it into the existing cipher selection code without
any need for infrastructure changes.

This patch was simultaneously submitted by Umar Hayat and Vladyslav
Nebozhyn, the latter whom suggested the feauture. The committed patch
is Umar's version.

Author: Umar Hayat <postgresql.wizard@gmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/CAPBGcbxo9ASzq14VTpQp3mnUJ5omdgTWUJOvWV0L6nNigWE5jw@mail.gmail.com
This commit is contained in:
Daniel Gustafsson
2025-02-14 21:18:37 +01:00
parent 760bf588de
commit 9ad1b3d01f
4 changed files with 217 additions and 1 deletions

View File

@@ -617,6 +617,36 @@ ossl_aes_cbc_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv
return err;
}
static int
ossl_aes_cfb_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
{
OSSLCipher *od = c->ptr;
int err;
err = ossl_aes_init(c, key, klen, iv);
if (err)
return err;
switch (od->klen)
{
case 128 / 8:
od->evp_ciph = EVP_aes_128_cfb();
break;
case 192 / 8:
od->evp_ciph = EVP_aes_192_cfb();
break;
case 256 / 8:
od->evp_ciph = EVP_aes_256_cfb();
break;
default:
/* shouldn't happen */
err = PXE_CIPHER_INIT;
break;
}
return err;
}
/*
* aliases
*/
@@ -636,6 +666,7 @@ static PX_Alias ossl_aliases[] = {
{"rijndael", "aes-cbc"},
{"rijndael-cbc", "aes-cbc"},
{"rijndael-ecb", "aes-ecb"},
{"rijndael-cfb", "aes-cfb"},
{NULL}
};
@@ -707,6 +738,13 @@ static const struct ossl_cipher ossl_aes_cbc = {
128 / 8, 256 / 8
};
static const struct ossl_cipher ossl_aes_cfb = {
ossl_aes_cfb_init,
NULL, /* EVP_aes_XXX_cfb(), determined in init
* function */
128 / 8, 256 / 8
};
/*
* Special handlers
*/
@@ -728,6 +766,7 @@ static const struct ossl_cipher_lookup ossl_cipher_types[] = {
{"cast5-cbc", &ossl_cast_cbc},
{"aes-ecb", &ossl_aes_ecb},
{"aes-cbc", &ossl_aes_cbc},
{"aes-cfb", &ossl_aes_cfb},
{NULL}
};