2000-10-31 16:11:28 +03:00
|
|
|
/*
|
|
|
|
* openssl.c
|
|
|
|
* Wrapper for OpenSSL library.
|
2001-03-22 07:01:46 +03:00
|
|
|
*
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
* Copyright (c) 2001 Marko Kreen
|
2000-10-31 16:11:28 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
2001-03-22 07:01:46 +03:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2000-10-31 16:11:28 +03:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
2001-03-22 07:01:46 +03:00
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2000-10-31 16:11:28 +03:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2014-05-06 20:12:18 +04:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
2000-10-31 16:11:28 +03:00
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
2010-09-21 00:08:53 +04:00
|
|
|
* contrib/pgcrypto/openssl.c
|
2000-10-31 16:11:28 +03:00
|
|
|
*/
|
|
|
|
|
2005-07-11 19:07:59 +04:00
|
|
|
#include "postgres.h"
|
2001-02-10 05:31:31 +03:00
|
|
|
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
#include "px.h"
|
2000-10-31 16:11:28 +03:00
|
|
|
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
#include <openssl/evp.h>
|
2005-07-10 07:55:28 +04:00
|
|
|
#include <openssl/err.h>
|
2016-10-17 17:29:33 +03:00
|
|
|
#include <openssl/rand.h>
|
2005-07-10 07:55:28 +04:00
|
|
|
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
#include "utils/memutils.h"
|
|
|
|
#include "utils/resowner.h"
|
|
|
|
|
2005-07-13 00:27:45 +04:00
|
|
|
/*
|
|
|
|
* Max lengths we might want to handle.
|
|
|
|
*/
|
|
|
|
#define MAX_KEY (512/8)
|
|
|
|
#define MAX_IV (128/8)
|
2000-10-31 16:11:28 +03:00
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
/*
|
|
|
|
* Hashes
|
|
|
|
*/
|
2006-02-18 23:48:51 +03:00
|
|
|
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
/*
|
|
|
|
* To make sure we don't leak OpenSSL handles on abort, we keep OSSLDigest
|
|
|
|
* objects in a linked list, allocated in TopMemoryContext. We use the
|
|
|
|
* ResourceOwner mechanism to free them on abort.
|
|
|
|
*/
|
2006-10-04 04:30:14 +04:00
|
|
|
typedef struct OSSLDigest
|
|
|
|
{
|
2006-02-18 23:48:51 +03:00
|
|
|
const EVP_MD *algo;
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
EVP_MD_CTX *ctx;
|
|
|
|
|
|
|
|
ResourceOwner owner;
|
|
|
|
struct OSSLDigest *next;
|
|
|
|
struct OSSLDigest *prev;
|
2009-06-11 18:49:15 +04:00
|
|
|
} OSSLDigest;
|
2006-02-18 23:48:51 +03:00
|
|
|
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
static OSSLDigest *open_digests = NULL;
|
2016-12-12 12:14:44 +03:00
|
|
|
static bool digest_resowner_callback_registered = false;
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
|
|
|
|
static void
|
2016-12-12 12:14:44 +03:00
|
|
|
free_openssl_digest(OSSLDigest *digest)
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
{
|
|
|
|
EVP_MD_CTX_destroy(digest->ctx);
|
|
|
|
if (digest->prev)
|
|
|
|
digest->prev->next = digest->next;
|
|
|
|
else
|
|
|
|
open_digests = digest->next;
|
|
|
|
if (digest->next)
|
|
|
|
digest->next->prev = digest->prev;
|
|
|
|
pfree(digest);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close any open OpenSSL handles on abort.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
digest_free_callback(ResourceReleasePhase phase,
|
|
|
|
bool isCommit,
|
|
|
|
bool isTopLevel,
|
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
OSSLDigest *curr;
|
|
|
|
OSSLDigest *next;
|
|
|
|
|
|
|
|
if (phase != RESOURCE_RELEASE_AFTER_LOCKS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
next = open_digests;
|
|
|
|
while (next)
|
|
|
|
{
|
|
|
|
curr = next;
|
|
|
|
next = curr->next;
|
|
|
|
|
|
|
|
if (curr->owner == CurrentResourceOwner)
|
|
|
|
{
|
|
|
|
if (isCommit)
|
|
|
|
elog(WARNING, "pgcrypto digest reference leak: digest %p still referenced", curr);
|
2016-12-12 12:14:44 +03:00
|
|
|
free_openssl_digest(curr);
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-20 21:54:07 +03:00
|
|
|
static unsigned
|
2009-06-11 18:49:15 +04:00
|
|
|
digest_result_size(PX_MD *h)
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
{
|
2006-10-04 04:30:14 +04:00
|
|
|
OSSLDigest *digest = (OSSLDigest *) h->p.ptr;
|
|
|
|
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
return EVP_MD_CTX_size(digest->ctx);
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
}
|
2000-10-31 16:11:28 +03:00
|
|
|
|
2001-11-20 21:54:07 +03:00
|
|
|
static unsigned
|
2009-06-11 18:49:15 +04:00
|
|
|
digest_block_size(PX_MD *h)
|
2001-03-22 07:01:46 +03:00
|
|
|
{
|
2006-10-04 04:30:14 +04:00
|
|
|
OSSLDigest *digest = (OSSLDigest *) h->p.ptr;
|
|
|
|
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
return EVP_MD_CTX_block_size(digest->ctx);
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-11 18:49:15 +04:00
|
|
|
digest_reset(PX_MD *h)
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
{
|
2006-10-04 04:30:14 +04:00
|
|
|
OSSLDigest *digest = (OSSLDigest *) h->p.ptr;
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
EVP_DigestInit_ex(digest->ctx, digest->algo, NULL);
|
2000-10-31 16:11:28 +03:00
|
|
|
}
|
|
|
|
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
static void
|
2009-06-11 18:49:15 +04:00
|
|
|
digest_update(PX_MD *h, const uint8 *data, unsigned dlen)
|
2000-10-31 16:11:28 +03:00
|
|
|
{
|
2006-10-04 04:30:14 +04:00
|
|
|
OSSLDigest *digest = (OSSLDigest *) h->p.ptr;
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
EVP_DigestUpdate(digest->ctx, data, dlen);
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
}
|
2000-10-31 16:11:28 +03:00
|
|
|
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
static void
|
2009-06-11 18:49:15 +04:00
|
|
|
digest_finish(PX_MD *h, uint8 *dst)
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
{
|
2006-10-04 04:30:14 +04:00
|
|
|
OSSLDigest *digest = (OSSLDigest *) h->p.ptr;
|
2005-03-12 09:53:54 +03:00
|
|
|
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
EVP_DigestFinal_ex(digest->ctx, dst, NULL);
|
2000-10-31 16:11:28 +03:00
|
|
|
}
|
|
|
|
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
static void
|
2009-06-11 18:49:15 +04:00
|
|
|
digest_free(PX_MD *h)
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
{
|
2006-10-04 04:30:14 +04:00
|
|
|
OSSLDigest *digest = (OSSLDigest *) h->p.ptr;
|
2006-02-18 23:48:51 +03:00
|
|
|
|
2016-12-12 12:14:44 +03:00
|
|
|
free_openssl_digest(digest);
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
px_free(h);
|
|
|
|
}
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
static int px_openssl_initialized = 0;
|
|
|
|
|
|
|
|
/* PUBLIC functions */
|
|
|
|
|
|
|
|
int
|
2009-06-11 18:49:15 +04:00
|
|
|
px_find_digest(const char *name, PX_MD **res)
|
2002-11-15 05:54:44 +03:00
|
|
|
{
|
|
|
|
const EVP_MD *md;
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
EVP_MD_CTX *ctx;
|
2002-11-15 05:54:44 +03:00
|
|
|
PX_MD *h;
|
2006-02-18 23:48:51 +03:00
|
|
|
OSSLDigest *digest;
|
2002-11-15 05:54:44 +03:00
|
|
|
|
|
|
|
if (!px_openssl_initialized)
|
|
|
|
{
|
|
|
|
px_openssl_initialized = 1;
|
|
|
|
OpenSSL_add_all_algorithms();
|
|
|
|
}
|
|
|
|
|
2016-12-12 12:14:44 +03:00
|
|
|
if (!digest_resowner_callback_registered)
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
{
|
|
|
|
RegisterResourceReleaseCallback(digest_free_callback, NULL);
|
2016-12-12 12:14:44 +03:00
|
|
|
digest_resowner_callback_registered = true;
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
}
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
md = EVP_get_digestbyname(name);
|
|
|
|
if (md == NULL)
|
2016-08-29 20:16:02 +03:00
|
|
|
return PXE_NO_HASH;
|
2002-11-15 05:54:44 +03:00
|
|
|
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
/*
|
|
|
|
* Create an OSSLDigest object, an OpenSSL MD object, and a PX_MD object.
|
|
|
|
* The order is crucial, to make sure we don't leak anything on
|
|
|
|
* out-of-memory or other error.
|
|
|
|
*/
|
|
|
|
digest = MemoryContextAlloc(TopMemoryContext, sizeof(*digest));
|
2006-02-18 23:48:51 +03:00
|
|
|
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
ctx = EVP_MD_CTX_create();
|
|
|
|
if (!ctx)
|
|
|
|
{
|
|
|
|
pfree(digest);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (EVP_DigestInit_ex(ctx, md, NULL) == 0)
|
|
|
|
{
|
|
|
|
pfree(digest);
|
2006-02-18 23:48:51 +03:00
|
|
|
return -1;
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
}
|
2002-11-15 05:54:44 +03:00
|
|
|
|
Support OpenSSL 1.1.0.
Changes needed to build at all:
- Check for SSL_new in configure, now that SSL_library_init is a macro.
- Do not access struct members directly. This includes some new code in
pgcrypto, to use the resource owner mechanism to ensure that we don't
leak OpenSSL handles, now that we can't embed them in other structs
anymore.
- RAND_SSLeay() -> RAND_OpenSSL()
Changes that were needed to silence deprecation warnings, but were not
strictly necessary:
- RAND_pseudo_bytes() -> RAND_bytes().
- SSL_library_init() and OpenSSL_config() -> OPENSSL_init_ssl()
- ASN1_STRING_data() -> ASN1_STRING_get0_data()
- DH_generate_parameters() -> DH_generate_parameters()
- Locking callbacks are not needed with OpenSSL 1.1.0 anymore. (Good
riddance!)
Also change references to SSLEAY_VERSION_NUMBER with OPENSSL_VERSION_NUMBER,
for the sake of consistency. OPENSSL_VERSION_NUMBER has existed since time
immemorial.
Fix SSL test suite to work with OpenSSL 1.1.0. CA certificates must have
the "CA:true" basic constraint extension now, or OpenSSL will refuse them.
Regenerate the test certificates with that. The "openssl" binary, used to
generate the certificates, is also now more picky, and throws an error
if an X509 extension is specified in "req_extensions", but that section
is empty.
Backpatch to all supported branches, per popular demand. In back-branches,
we still support OpenSSL 0.9.7 and above. OpenSSL 0.9.6 should still work
too, but I didn't test it. In master, we only support 0.9.8 and above.
Patch by Andreas Karlsson, with additional changes by me.
Discussion: <20160627151604.GD1051@msg.df7cb.de>
2016-09-15 12:36:21 +03:00
|
|
|
digest->algo = md;
|
|
|
|
digest->ctx = ctx;
|
|
|
|
digest->owner = CurrentResourceOwner;
|
|
|
|
digest->next = open_digests;
|
|
|
|
digest->prev = NULL;
|
|
|
|
open_digests = digest;
|
|
|
|
|
|
|
|
/* The PX_MD object is allocated in the current memory context. */
|
2002-11-15 05:54:44 +03:00
|
|
|
h = px_alloc(sizeof(*h));
|
|
|
|
h->result_size = digest_result_size;
|
|
|
|
h->block_size = digest_block_size;
|
|
|
|
h->reset = digest_reset;
|
|
|
|
h->update = digest_update;
|
|
|
|
h->finish = digest_finish;
|
|
|
|
h->free = digest_free;
|
2006-02-18 23:48:51 +03:00
|
|
|
h->p.ptr = (void *) digest;
|
2002-11-15 05:54:44 +03:00
|
|
|
|
|
|
|
*res = h;
|
|
|
|
return 0;
|
|
|
|
}
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
|
|
|
|
/*
|
2002-11-15 05:54:44 +03:00
|
|
|
* Ciphers
|
|
|
|
*
|
2016-10-17 17:29:33 +03:00
|
|
|
* We use OpenSSL's EVP* family of functions for these.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prototype for the EVP functions that return an algorithm, e.g.
|
|
|
|
* EVP_aes_128_cbc().
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
*/
|
2017-05-17 23:31:56 +03:00
|
|
|
typedef const EVP_CIPHER *(*ossl_EVP_cipher_func) (void);
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
|
2016-12-12 12:14:44 +03:00
|
|
|
/*
|
|
|
|
* ossl_cipher contains the static information about each cipher.
|
|
|
|
*/
|
2003-08-04 04:43:34 +04:00
|
|
|
struct ossl_cipher
|
|
|
|
{
|
2009-06-11 18:49:15 +04:00
|
|
|
int (*init) (PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv);
|
2016-10-17 17:29:33 +03:00
|
|
|
ossl_EVP_cipher_func cipher_func;
|
2003-08-04 04:43:34 +04:00
|
|
|
int block_size;
|
|
|
|
int max_key_size;
|
2002-11-15 05:54:44 +03:00
|
|
|
};
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
|
2016-12-12 12:14:44 +03:00
|
|
|
/*
|
|
|
|
* OSSLCipher contains the state for using a cipher. A separate OSSLCipher
|
|
|
|
* object is allocated in each px_find_cipher() call.
|
|
|
|
*
|
|
|
|
* To make sure we don't leak OpenSSL handles on abort, we keep OSSLCipher
|
|
|
|
* objects in a linked list, allocated in TopMemoryContext. We use the
|
|
|
|
* ResourceOwner mechanism to free them on abort.
|
|
|
|
*/
|
|
|
|
typedef struct OSSLCipher
|
2001-10-25 09:50:21 +04:00
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
EVP_CIPHER_CTX *evp_ctx;
|
2016-10-17 17:29:33 +03:00
|
|
|
const EVP_CIPHER *evp_ciph;
|
2005-07-13 00:27:45 +04:00
|
|
|
uint8 key[MAX_KEY];
|
|
|
|
uint8 iv[MAX_IV];
|
2001-11-20 18:50:53 +03:00
|
|
|
unsigned klen;
|
|
|
|
unsigned init;
|
2002-11-15 05:54:44 +03:00
|
|
|
const struct ossl_cipher *ciph;
|
2016-12-12 12:14:44 +03:00
|
|
|
|
|
|
|
ResourceOwner owner;
|
|
|
|
struct OSSLCipher *next;
|
|
|
|
struct OSSLCipher *prev;
|
|
|
|
} OSSLCipher;
|
|
|
|
|
|
|
|
static OSSLCipher *open_ciphers = NULL;
|
|
|
|
static bool cipher_resowner_callback_registered = false;
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_openssl_cipher(OSSLCipher *od)
|
|
|
|
{
|
|
|
|
EVP_CIPHER_CTX_free(od->evp_ctx);
|
|
|
|
if (od->prev)
|
|
|
|
od->prev->next = od->next;
|
|
|
|
else
|
|
|
|
open_ciphers = od->next;
|
|
|
|
if (od->next)
|
|
|
|
od->next->prev = od->prev;
|
|
|
|
pfree(od);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close any open OpenSSL cipher handles on abort.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cipher_free_callback(ResourceReleasePhase phase,
|
|
|
|
bool isCommit,
|
|
|
|
bool isTopLevel,
|
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
OSSLCipher *curr;
|
|
|
|
OSSLCipher *next;
|
|
|
|
|
|
|
|
if (phase != RESOURCE_RELEASE_AFTER_LOCKS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
next = open_ciphers;
|
|
|
|
while (next)
|
|
|
|
{
|
|
|
|
curr = next;
|
|
|
|
next = curr->next;
|
|
|
|
|
|
|
|
if (curr->owner == CurrentResourceOwner)
|
|
|
|
{
|
|
|
|
if (isCommit)
|
|
|
|
elog(WARNING, "pgcrypto cipher reference leak: cipher %p still referenced", curr);
|
|
|
|
free_openssl_cipher(curr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
|
2016-10-17 17:29:33 +03:00
|
|
|
/* Common routines for all algorithms */
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
|
2001-11-20 21:54:07 +03:00
|
|
|
static unsigned
|
2009-06-11 18:49:15 +04:00
|
|
|
gen_ossl_block_size(PX_Cipher *c)
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
OSSLCipher *od = (OSSLCipher *) c->ptr;
|
2001-10-25 09:50:21 +04:00
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
return od->ciph->block_size;
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
}
|
|
|
|
|
2001-11-20 21:54:07 +03:00
|
|
|
static unsigned
|
2009-06-11 18:49:15 +04:00
|
|
|
gen_ossl_key_size(PX_Cipher *c)
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
OSSLCipher *od = (OSSLCipher *) c->ptr;
|
2001-10-25 09:50:21 +04:00
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
return od->ciph->max_key_size;
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
}
|
|
|
|
|
2001-11-20 21:54:07 +03:00
|
|
|
static unsigned
|
2009-06-11 18:49:15 +04:00
|
|
|
gen_ossl_iv_size(PX_Cipher *c)
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
{
|
2001-11-20 18:50:53 +03:00
|
|
|
unsigned ivlen;
|
2016-12-12 12:14:44 +03:00
|
|
|
OSSLCipher *od = (OSSLCipher *) c->ptr;
|
2001-10-25 09:50:21 +04:00
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
ivlen = od->ciph->block_size;
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
return ivlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-11 18:49:15 +04:00
|
|
|
gen_ossl_free(PX_Cipher *c)
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
OSSLCipher *od = (OSSLCipher *) c->ptr;
|
2001-10-25 09:50:21 +04:00
|
|
|
|
2016-12-12 12:14:44 +03:00
|
|
|
free_openssl_cipher(od);
|
2005-03-21 08:18:46 +03:00
|
|
|
px_free(c);
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
}
|
|
|
|
|
2016-10-17 17:29:33 +03:00
|
|
|
static int
|
|
|
|
gen_ossl_decrypt(PX_Cipher *c, const uint8 *data, unsigned dlen,
|
|
|
|
uint8 *res)
|
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
OSSLCipher *od = c->ptr;
|
2016-10-17 17:29:33 +03:00
|
|
|
int outlen;
|
|
|
|
|
|
|
|
if (!od->init)
|
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
if (!EVP_DecryptInit_ex(od->evp_ctx, od->evp_ciph, NULL, NULL, NULL))
|
2016-10-17 17:29:33 +03:00
|
|
|
return PXE_CIPHER_INIT;
|
2016-12-12 12:14:44 +03:00
|
|
|
if (!EVP_CIPHER_CTX_set_key_length(od->evp_ctx, od->klen))
|
2016-10-17 17:29:33 +03:00
|
|
|
return PXE_CIPHER_INIT;
|
2016-12-12 12:14:44 +03:00
|
|
|
if (!EVP_DecryptInit_ex(od->evp_ctx, NULL, NULL, od->key, od->iv))
|
2016-10-17 17:29:33 +03:00
|
|
|
return PXE_CIPHER_INIT;
|
|
|
|
od->init = true;
|
|
|
|
}
|
|
|
|
|
2016-12-12 12:14:44 +03:00
|
|
|
if (!EVP_DecryptUpdate(od->evp_ctx, res, &outlen, data, dlen))
|
2016-10-17 17:29:33 +03:00
|
|
|
return PXE_DECRYPT_FAILED;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gen_ossl_encrypt(PX_Cipher *c, const uint8 *data, unsigned dlen,
|
|
|
|
uint8 *res)
|
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
OSSLCipher *od = c->ptr;
|
2016-10-17 17:29:33 +03:00
|
|
|
int outlen;
|
|
|
|
|
|
|
|
if (!od->init)
|
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
if (!EVP_EncryptInit_ex(od->evp_ctx, od->evp_ciph, NULL, NULL, NULL))
|
2016-10-17 17:29:33 +03:00
|
|
|
return PXE_CIPHER_INIT;
|
2016-12-12 12:14:44 +03:00
|
|
|
if (!EVP_CIPHER_CTX_set_key_length(od->evp_ctx, od->klen))
|
2016-10-17 17:29:33 +03:00
|
|
|
return PXE_CIPHER_INIT;
|
2016-12-12 12:14:44 +03:00
|
|
|
if (!EVP_EncryptInit_ex(od->evp_ctx, NULL, NULL, od->key, od->iv))
|
2016-10-17 17:29:33 +03:00
|
|
|
return PXE_CIPHER_INIT;
|
|
|
|
od->init = true;
|
|
|
|
}
|
|
|
|
|
2016-12-12 12:14:44 +03:00
|
|
|
if (!EVP_EncryptUpdate(od->evp_ctx, res, &outlen, data, dlen))
|
2016-10-17 17:29:33 +03:00
|
|
|
return PXE_ERR_GENERIC;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
/* Blowfish */
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
|
2007-09-29 06:18:15 +04:00
|
|
|
/*
|
2018-06-29 03:45:44 +03:00
|
|
|
* Check if strong crypto is supported. Some OpenSSL installations
|
2007-09-29 06:18:15 +04:00
|
|
|
* support only short keys and unfortunately BF_set_key does not return any
|
|
|
|
* error value. This function tests if is possible to use strong key.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
bf_check_supported_key_len(void)
|
|
|
|
{
|
|
|
|
static const uint8 key[56] = {
|
2007-11-16 00:14:46 +03:00
|
|
|
0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, 0x78, 0x69,
|
|
|
|
0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f, 0x00, 0x11, 0x22, 0x33,
|
|
|
|
0x44, 0x55, 0x66, 0x77, 0x04, 0x68, 0x91, 0x04, 0xc2, 0xfd,
|
|
|
|
0x3b, 0x2f, 0x58, 0x40, 0x23, 0x64, 0x1a, 0xba, 0x61, 0x76,
|
|
|
|
0x1f, 0x1f, 0x1f, 0x1f, 0x0e, 0x0e, 0x0e, 0x0e, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
2007-09-29 06:18:15 +04:00
|
|
|
};
|
|
|
|
|
2007-11-16 00:14:46 +03:00
|
|
|
static const uint8 data[8] = {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10};
|
|
|
|
static const uint8 res[8] = {0xc0, 0x45, 0x04, 0x01, 0x2e, 0x4e, 0x1f, 0x53};
|
2016-10-17 17:29:33 +03:00
|
|
|
uint8 out[8];
|
2016-12-12 12:14:44 +03:00
|
|
|
EVP_CIPHER_CTX *evp_ctx;
|
2016-10-17 17:29:33 +03:00
|
|
|
int outlen;
|
2016-12-12 12:14:44 +03:00
|
|
|
int status = 0;
|
2007-09-29 06:18:15 +04:00
|
|
|
|
|
|
|
/* encrypt with 448bits key and verify output */
|
2016-12-12 12:14:44 +03:00
|
|
|
evp_ctx = EVP_CIPHER_CTX_new();
|
|
|
|
if (!evp_ctx)
|
2016-10-17 17:29:33 +03:00
|
|
|
return 0;
|
2016-12-12 12:14:44 +03:00
|
|
|
if (!EVP_EncryptInit_ex(evp_ctx, EVP_bf_ecb(), NULL, NULL, NULL))
|
|
|
|
goto leave;
|
|
|
|
if (!EVP_CIPHER_CTX_set_key_length(evp_ctx, 56))
|
|
|
|
goto leave;
|
|
|
|
if (!EVP_EncryptInit_ex(evp_ctx, NULL, NULL, key, NULL))
|
|
|
|
goto leave;
|
2016-10-17 17:29:33 +03:00
|
|
|
|
2016-12-12 12:14:44 +03:00
|
|
|
if (!EVP_EncryptUpdate(evp_ctx, out, &outlen, data, 8))
|
|
|
|
goto leave;
|
2007-09-29 06:18:15 +04:00
|
|
|
|
2007-11-16 00:14:46 +03:00
|
|
|
if (memcmp(out, res, 8) != 0)
|
2016-12-12 12:14:44 +03:00
|
|
|
goto leave; /* Output does not match -> strong cipher is
|
2007-11-16 00:14:46 +03:00
|
|
|
* not supported */
|
2016-12-12 12:14:44 +03:00
|
|
|
status = 1;
|
|
|
|
|
|
|
|
leave:
|
|
|
|
EVP_CIPHER_CTX_free(evp_ctx);
|
|
|
|
return status;
|
2007-09-29 06:18:15 +04:00
|
|
|
}
|
|
|
|
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
static int
|
2009-06-11 18:49:15 +04:00
|
|
|
bf_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
OSSLCipher *od = c->ptr;
|
2016-10-17 17:29:33 +03:00
|
|
|
unsigned bs = gen_ossl_block_size(c);
|
2007-11-16 00:14:46 +03:00
|
|
|
static int bf_is_strong = -1;
|
2007-09-29 06:18:15 +04:00
|
|
|
|
|
|
|
/*
|
2007-11-16 00:14:46 +03:00
|
|
|
* Test if key len is supported. BF_set_key silently cut large keys and it
|
2014-05-06 20:12:18 +04:00
|
|
|
* could be a problem when user transfer crypted data from one server to
|
|
|
|
* another.
|
2007-09-29 06:18:15 +04:00
|
|
|
*/
|
2007-11-16 00:14:46 +03:00
|
|
|
|
|
|
|
if (bf_is_strong == -1)
|
2007-09-29 06:18:15 +04:00
|
|
|
bf_is_strong = bf_check_supported_key_len();
|
|
|
|
|
2007-11-16 00:14:46 +03:00
|
|
|
if (!bf_is_strong && klen > 16)
|
|
|
|
return PXE_KEY_TOO_BIG;
|
2001-10-25 09:50:21 +04:00
|
|
|
|
2007-09-29 06:18:15 +04:00
|
|
|
/* Key len is supported. We can use it. */
|
2016-10-17 17:29:33 +03:00
|
|
|
od->klen = klen;
|
|
|
|
memcpy(od->key, key, klen);
|
|
|
|
|
2001-10-25 09:50:21 +04:00
|
|
|
if (iv)
|
2016-10-17 17:29:33 +03:00
|
|
|
memcpy(od->iv, iv, bs);
|
2001-10-25 09:50:21 +04:00
|
|
|
else
|
2016-10-17 17:29:33 +03:00
|
|
|
memset(od->iv, 0, bs);
|
2002-11-15 05:54:44 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DES */
|
|
|
|
|
|
|
|
static int
|
2009-06-11 18:49:15 +04:00
|
|
|
ossl_des_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
|
2002-11-15 05:54:44 +03:00
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
OSSLCipher *od = c->ptr;
|
2016-10-17 17:29:33 +03:00
|
|
|
unsigned bs = gen_ossl_block_size(c);
|
2002-11-15 05:54:44 +03:00
|
|
|
|
2016-10-17 17:29:33 +03:00
|
|
|
od->klen = 8;
|
|
|
|
memset(od->key, 0, 8);
|
|
|
|
memcpy(od->key, key, klen > 8 ? 8 : klen);
|
2003-08-04 04:43:34 +04:00
|
|
|
|
2001-10-25 09:50:21 +04:00
|
|
|
if (iv)
|
2016-10-17 17:29:33 +03:00
|
|
|
memcpy(od->iv, iv, bs);
|
2001-10-25 09:50:21 +04:00
|
|
|
else
|
2016-10-17 17:29:33 +03:00
|
|
|
memset(od->iv, 0, bs);
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-03-21 08:21:04 +03:00
|
|
|
/* DES3 */
|
|
|
|
|
|
|
|
static int
|
2009-06-11 18:49:15 +04:00
|
|
|
ossl_des3_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
|
2005-03-21 08:21:04 +03:00
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
OSSLCipher *od = c->ptr;
|
2005-03-21 08:21:04 +03:00
|
|
|
unsigned bs = gen_ossl_block_size(c);
|
|
|
|
|
2016-10-17 17:29:33 +03:00
|
|
|
od->klen = 24;
|
|
|
|
memset(od->key, 0, 24);
|
|
|
|
memcpy(od->key, key, klen > 24 ? 24 : klen);
|
2005-03-21 08:21:04 +03:00
|
|
|
|
2016-10-17 17:29:33 +03:00
|
|
|
if (iv)
|
|
|
|
memcpy(od->iv, iv, bs);
|
|
|
|
else
|
|
|
|
memset(od->iv, 0, bs);
|
2005-03-21 08:21:04 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
/* CAST5 */
|
|
|
|
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
static int
|
2009-06-11 18:49:15 +04:00
|
|
|
ossl_cast_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
OSSLCipher *od = c->ptr;
|
2002-11-15 05:54:44 +03:00
|
|
|
unsigned bs = gen_ossl_block_size(c);
|
2001-10-25 09:50:21 +04:00
|
|
|
|
2016-10-17 17:29:33 +03:00
|
|
|
od->klen = klen;
|
|
|
|
memcpy(od->key, key, klen);
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
if (iv)
|
|
|
|
memcpy(od->iv, iv, bs);
|
|
|
|
else
|
|
|
|
memset(od->iv, 0, bs);
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-03-21 08:21:04 +03:00
|
|
|
/* AES */
|
|
|
|
|
|
|
|
static int
|
2009-06-11 18:49:15 +04:00
|
|
|
ossl_aes_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
|
2005-03-21 08:21:04 +03:00
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
OSSLCipher *od = c->ptr;
|
2005-03-21 08:21:04 +03:00
|
|
|
unsigned bs = gen_ossl_block_size(c);
|
|
|
|
|
2005-10-15 06:49:52 +04:00
|
|
|
if (klen <= 128 / 8)
|
|
|
|
od->klen = 128 / 8;
|
|
|
|
else if (klen <= 192 / 8)
|
|
|
|
od->klen = 192 / 8;
|
|
|
|
else if (klen <= 256 / 8)
|
|
|
|
od->klen = 256 / 8;
|
2005-03-21 08:21:04 +03:00
|
|
|
else
|
|
|
|
return PXE_KEY_TOO_BIG;
|
|
|
|
|
|
|
|
memcpy(od->key, key, klen);
|
|
|
|
|
|
|
|
if (iv)
|
|
|
|
memcpy(od->iv, iv, bs);
|
|
|
|
else
|
|
|
|
memset(od->iv, 0, bs);
|
2016-10-17 17:29:33 +03:00
|
|
|
|
2005-03-21 08:21:04 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-29 06:18:15 +04:00
|
|
|
static int
|
2016-10-17 17:29:33 +03:00
|
|
|
ossl_aes_ecb_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
|
2005-03-21 08:21:04 +03:00
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
OSSLCipher *od = c->ptr;
|
2007-11-16 00:14:46 +03:00
|
|
|
int err;
|
|
|
|
|
2016-10-17 17:29:33 +03:00
|
|
|
err = ossl_aes_init(c, key, klen, iv);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2007-09-29 06:18:15 +04:00
|
|
|
|
2016-10-17 17:29:33 +03:00
|
|
|
switch (od->klen)
|
2007-09-29 06:18:15 +04:00
|
|
|
{
|
2016-10-17 17:29:33 +03:00
|
|
|
case 128 / 8:
|
|
|
|
od->evp_ciph = EVP_aes_128_ecb();
|
|
|
|
break;
|
|
|
|
case 192 / 8:
|
|
|
|
od->evp_ciph = EVP_aes_192_ecb();
|
|
|
|
break;
|
|
|
|
case 256 / 8:
|
|
|
|
od->evp_ciph = EVP_aes_256_ecb();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* shouldn't happen */
|
|
|
|
err = PXE_CIPHER_INIT;
|
|
|
|
break;
|
2007-09-29 06:18:15 +04:00
|
|
|
}
|
2005-03-21 08:21:04 +03:00
|
|
|
|
2016-10-17 17:29:33 +03:00
|
|
|
return err;
|
2005-03-21 08:21:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-10-17 17:29:33 +03:00
|
|
|
ossl_aes_cbc_init(PX_Cipher *c, const uint8 *key, unsigned klen, const uint8 *iv)
|
2005-03-21 08:21:04 +03:00
|
|
|
{
|
2016-12-12 12:14:44 +03:00
|
|
|
OSSLCipher *od = c->ptr;
|
2007-11-16 00:14:46 +03:00
|
|
|
int err;
|
2005-03-21 08:21:04 +03:00
|
|
|
|
2016-10-17 17:29:33 +03:00
|
|
|
err = ossl_aes_init(c, key, klen, iv);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2005-03-21 08:21:04 +03:00
|
|
|
|
2016-10-17 17:29:33 +03:00
|
|
|
switch (od->klen)
|
|
|
|
{
|
|
|
|
case 128 / 8:
|
|
|
|
od->evp_ciph = EVP_aes_128_cbc();
|
|
|
|
break;
|
|
|
|
case 192 / 8:
|
|
|
|
od->evp_ciph = EVP_aes_192_cbc();
|
|
|
|
break;
|
|
|
|
case 256 / 8:
|
|
|
|
od->evp_ciph = EVP_aes_256_cbc();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* shouldn't happen */
|
|
|
|
err = PXE_CIPHER_INIT;
|
|
|
|
break;
|
|
|
|
}
|
2005-03-21 08:21:04 +03:00
|
|
|
|
2016-10-17 17:29:33 +03:00
|
|
|
return err;
|
2005-03-21 08:21:04 +03:00
|
|
|
}
|
|
|
|
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
/*
|
|
|
|
* aliases
|
|
|
|
*/
|
|
|
|
|
2001-10-25 09:50:21 +04:00
|
|
|
static PX_Alias ossl_aliases[] = {
|
|
|
|
{"bf", "bf-cbc"},
|
|
|
|
{"blowfish", "bf-cbc"},
|
|
|
|
{"blowfish-cbc", "bf-cbc"},
|
|
|
|
{"blowfish-ecb", "bf-ecb"},
|
|
|
|
{"blowfish-cfb", "bf-cfb"},
|
2002-11-15 05:54:44 +03:00
|
|
|
{"des", "des-cbc"},
|
2005-03-21 08:21:04 +03:00
|
|
|
{"3des", "des3-cbc"},
|
|
|
|
{"3des-ecb", "des3-ecb"},
|
|
|
|
{"3des-cbc", "des3-cbc"},
|
2002-11-15 05:54:44 +03:00
|
|
|
{"cast5", "cast5-cbc"},
|
2005-03-21 08:21:04 +03:00
|
|
|
{"aes", "aes-cbc"},
|
|
|
|
{"rijndael", "aes-cbc"},
|
|
|
|
{"rijndael-cbc", "aes-cbc"},
|
|
|
|
{"rijndael-ecb", "aes-ecb"},
|
2001-10-25 09:50:21 +04:00
|
|
|
{NULL}
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
};
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
static const struct ossl_cipher ossl_bf_cbc = {
|
2016-10-17 17:29:33 +03:00
|
|
|
bf_init,
|
|
|
|
EVP_bf_cbc,
|
|
|
|
64 / 8, 448 / 8
|
2002-11-15 05:54:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ossl_cipher ossl_bf_ecb = {
|
2016-10-17 17:29:33 +03:00
|
|
|
bf_init,
|
|
|
|
EVP_bf_ecb,
|
|
|
|
64 / 8, 448 / 8
|
2002-11-15 05:54:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ossl_cipher ossl_bf_cfb = {
|
2016-10-17 17:29:33 +03:00
|
|
|
bf_init,
|
|
|
|
EVP_bf_cfb,
|
|
|
|
64 / 8, 448 / 8
|
2002-11-15 05:54:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ossl_cipher ossl_des_ecb = {
|
2016-10-17 17:29:33 +03:00
|
|
|
ossl_des_init,
|
|
|
|
EVP_des_ecb,
|
|
|
|
64 / 8, 64 / 8
|
2002-11-15 05:54:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ossl_cipher ossl_des_cbc = {
|
2016-10-17 17:29:33 +03:00
|
|
|
ossl_des_init,
|
|
|
|
EVP_des_cbc,
|
|
|
|
64 / 8, 64 / 8
|
2002-11-15 05:54:44 +03:00
|
|
|
};
|
|
|
|
|
2005-03-21 08:21:04 +03:00
|
|
|
static const struct ossl_cipher ossl_des3_ecb = {
|
2016-10-17 17:29:33 +03:00
|
|
|
ossl_des3_init,
|
|
|
|
EVP_des_ede3_ecb,
|
|
|
|
64 / 8, 192 / 8
|
2005-03-21 08:21:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ossl_cipher ossl_des3_cbc = {
|
2016-10-17 17:29:33 +03:00
|
|
|
ossl_des3_init,
|
|
|
|
EVP_des_ede3_cbc,
|
|
|
|
64 / 8, 192 / 8
|
2005-03-21 08:21:04 +03:00
|
|
|
};
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
static const struct ossl_cipher ossl_cast_ecb = {
|
2016-10-17 17:29:33 +03:00
|
|
|
ossl_cast_init,
|
|
|
|
EVP_cast5_ecb,
|
|
|
|
64 / 8, 128 / 8
|
2002-11-15 05:54:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ossl_cipher ossl_cast_cbc = {
|
2016-10-17 17:29:33 +03:00
|
|
|
ossl_cast_init,
|
|
|
|
EVP_cast5_cbc,
|
|
|
|
64 / 8, 128 / 8
|
2002-11-15 05:54:44 +03:00
|
|
|
};
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
|
2005-03-21 08:21:04 +03:00
|
|
|
static const struct ossl_cipher ossl_aes_ecb = {
|
2016-10-17 17:29:33 +03:00
|
|
|
ossl_aes_ecb_init,
|
2017-05-17 23:31:56 +03:00
|
|
|
NULL, /* EVP_aes_XXX_ecb(), determined in init
|
|
|
|
* function */
|
2016-10-17 17:29:33 +03:00
|
|
|
128 / 8, 256 / 8
|
2005-03-21 08:21:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ossl_cipher ossl_aes_cbc = {
|
2016-10-17 17:29:33 +03:00
|
|
|
ossl_aes_cbc_init,
|
2017-05-17 23:31:56 +03:00
|
|
|
NULL, /* EVP_aes_XXX_cbc(), determined in init
|
|
|
|
* function */
|
2016-10-17 17:29:33 +03:00
|
|
|
128 / 8, 256 / 8
|
2005-03-21 08:21:04 +03:00
|
|
|
};
|
|
|
|
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
/*
|
|
|
|
* Special handlers
|
|
|
|
*/
|
2005-03-21 08:18:46 +03:00
|
|
|
struct ossl_cipher_lookup
|
2001-10-25 09:50:21 +04:00
|
|
|
{
|
2003-08-04 04:43:34 +04:00
|
|
|
const char *name;
|
2002-11-15 05:54:44 +03:00
|
|
|
const struct ossl_cipher *ciph;
|
2005-03-21 08:18:46 +03:00
|
|
|
};
|
2001-10-25 09:50:21 +04:00
|
|
|
|
2005-03-21 08:18:46 +03:00
|
|
|
static const struct ossl_cipher_lookup ossl_cipher_types[] = {
|
|
|
|
{"bf-cbc", &ossl_bf_cbc},
|
|
|
|
{"bf-ecb", &ossl_bf_ecb},
|
|
|
|
{"bf-cfb", &ossl_bf_cfb},
|
|
|
|
{"des-ecb", &ossl_des_ecb},
|
|
|
|
{"des-cbc", &ossl_des_cbc},
|
2005-03-21 08:21:04 +03:00
|
|
|
{"des3-ecb", &ossl_des3_ecb},
|
|
|
|
{"des3-cbc", &ossl_des3_cbc},
|
2005-03-21 08:18:46 +03:00
|
|
|
{"cast5-ecb", &ossl_cast_ecb},
|
|
|
|
{"cast5-cbc", &ossl_cast_cbc},
|
2005-03-21 08:21:04 +03:00
|
|
|
{"aes-ecb", &ossl_aes_ecb},
|
|
|
|
{"aes-cbc", &ossl_aes_cbc},
|
2005-03-21 08:18:46 +03:00
|
|
|
{NULL}
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* PUBLIC functions */
|
|
|
|
|
|
|
|
int
|
2009-06-11 18:49:15 +04:00
|
|
|
px_find_cipher(const char *name, PX_Cipher **res)
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
{
|
2005-03-21 08:18:46 +03:00
|
|
|
const struct ossl_cipher_lookup *i;
|
|
|
|
PX_Cipher *c = NULL;
|
2016-12-12 12:14:44 +03:00
|
|
|
EVP_CIPHER_CTX *ctx;
|
|
|
|
OSSLCipher *od;
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
|
|
|
|
name = px_resolve_alias(ossl_aliases, name);
|
2005-03-21 08:18:46 +03:00
|
|
|
for (i = ossl_cipher_types; i->name; i++)
|
2011-12-27 23:19:09 +04:00
|
|
|
if (strcmp(i->name, name) == 0)
|
2002-11-15 05:54:44 +03:00
|
|
|
break;
|
2005-03-21 08:18:46 +03:00
|
|
|
if (i->name == NULL)
|
2005-03-21 08:19:55 +03:00
|
|
|
return PXE_NO_CIPHER;
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
|
2016-12-12 12:14:44 +03:00
|
|
|
if (!cipher_resowner_callback_registered)
|
|
|
|
{
|
|
|
|
RegisterResourceReleaseCallback(cipher_free_callback, NULL);
|
|
|
|
cipher_resowner_callback_registered = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create an OSSLCipher object, an EVP_CIPHER_CTX object and a PX_Cipher.
|
|
|
|
* The order is crucial, to make sure we don't leak anything on
|
|
|
|
* out-of-memory or other error.
|
|
|
|
*/
|
|
|
|
od = MemoryContextAllocZero(TopMemoryContext, sizeof(*od));
|
2005-03-21 08:18:46 +03:00
|
|
|
od->ciph = i->ciph;
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
|
2016-12-12 12:14:44 +03:00
|
|
|
/* Allocate an EVP_CIPHER_CTX object. */
|
|
|
|
ctx = EVP_CIPHER_CTX_new();
|
|
|
|
if (!ctx)
|
|
|
|
{
|
|
|
|
pfree(od);
|
|
|
|
return PXE_CIPHER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
od->evp_ctx = ctx;
|
|
|
|
od->owner = CurrentResourceOwner;
|
|
|
|
od->next = open_ciphers;
|
|
|
|
od->prev = NULL;
|
|
|
|
open_ciphers = od;
|
|
|
|
|
2016-10-17 17:29:33 +03:00
|
|
|
if (i->ciph->cipher_func)
|
|
|
|
od->evp_ciph = i->ciph->cipher_func();
|
|
|
|
|
2016-12-12 12:14:44 +03:00
|
|
|
/* The PX_Cipher is allocated in current memory context */
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
c = px_alloc(sizeof(*c));
|
2002-11-15 05:54:44 +03:00
|
|
|
c->block_size = gen_ossl_block_size;
|
|
|
|
c->key_size = gen_ossl_key_size;
|
|
|
|
c->iv_size = gen_ossl_iv_size;
|
|
|
|
c->free = gen_ossl_free;
|
2005-03-21 08:18:46 +03:00
|
|
|
c->init = od->ciph->init;
|
2016-10-17 17:29:33 +03:00
|
|
|
c->encrypt = gen_ossl_encrypt;
|
|
|
|
c->decrypt = gen_ossl_decrypt;
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
c->ptr = od;
|
2001-10-25 09:50:21 +04:00
|
|
|
|
/contrib/pgcrypto:
* remove support for encode() as it is in main tree now
* remove krb5.c
* new 'PX library' architecture
* remove BSD license from my code to let the general
PostgreSQL one to apply
* md5, sha1: ANSIfy, use const where appropriate
* various other formatting and clarity changes
* hmac()
* UN*X-like crypt() - system or internal crypt
* Internal crypt: DES, Extended DES, MD5, Blowfish
crypt-des.c, crypt-md5.c from FreeBSD
crypt-blowfish.c from Solar Designer
* gen_salt() for crypt() - Blowfish, MD5, DES, Extended DES
* encrypt(), decrypt(), encrypt_iv(), decrypt_iv()
* Cipher support in mhash.c, openssl.c
* internal: Blowfish, Rijndael-128 ciphers
* blf.[ch], rijndael.[ch] from OpenBSD
* there will be generated file rijndael-tbl.inc.
Marko Kreen
2001-08-21 04:42:41 +04:00
|
|
|
*res = c;
|
|
|
|
return 0;
|
|
|
|
}
|