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
|
2001-03-22 07:01:46 +03: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.
|
|
|
|
*
|
2002-11-15 05:54:44 +03:00
|
|
|
* $Id: openssl.c,v 1.11 2002/11/15 02:54:44 momjian Exp $
|
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 <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>
|
2000-10-31 16:11:28 +03:00
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
/*
|
|
|
|
* Hashes
|
|
|
|
*/
|
2001-11-20 21:54:07 +03:00
|
|
|
static unsigned
|
/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
|
|
|
digest_result_size(PX_MD * h)
|
|
|
|
{
|
|
|
|
return EVP_MD_CTX_size((EVP_MD_CTX *) h->p.ptr);
|
|
|
|
}
|
2000-10-31 16:11:28 +03:00
|
|
|
|
2001-11-20 21:54:07 +03:00
|
|
|
static unsigned
|
/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
|
|
|
digest_block_size(PX_MD * h)
|
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
|
|
|
return EVP_MD_CTX_block_size((EVP_MD_CTX *) h->p.ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
digest_reset(PX_MD * h)
|
|
|
|
{
|
|
|
|
EVP_MD_CTX *ctx = (EVP_MD_CTX *) h->p.ptr;
|
|
|
|
const EVP_MD *md;
|
|
|
|
|
|
|
|
md = EVP_MD_CTX_md(ctx);
|
|
|
|
|
|
|
|
EVP_DigestInit(ctx, md);
|
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
|
2001-11-20 18:50:53 +03:00
|
|
|
digest_update(PX_MD * h, const uint8 *data, unsigned dlen)
|
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
|
|
|
EVP_MD_CTX *ctx = (EVP_MD_CTX *) h->p.ptr;
|
|
|
|
|
|
|
|
EVP_DigestUpdate(ctx, data, dlen);
|
|
|
|
}
|
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
|
2001-10-25 09:50:21 +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
|
|
|
{
|
|
|
|
EVP_MD_CTX *ctx = (EVP_MD_CTX *) h->p.ptr;
|
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
|
|
|
EVP_DigestFinal(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
|
|
|
|
digest_free(PX_MD * h)
|
|
|
|
{
|
|
|
|
EVP_MD_CTX *ctx = (EVP_MD_CTX *) h->p.ptr;
|
|
|
|
|
|
|
|
px_free(ctx);
|
|
|
|
px_free(h);
|
|
|
|
}
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
static int px_openssl_initialized = 0;
|
|
|
|
|
|
|
|
/* PUBLIC functions */
|
|
|
|
|
|
|
|
int
|
|
|
|
px_find_digest(const char *name, PX_MD ** res)
|
|
|
|
{
|
|
|
|
const EVP_MD *md;
|
|
|
|
EVP_MD_CTX *ctx;
|
|
|
|
PX_MD *h;
|
|
|
|
|
|
|
|
if (!px_openssl_initialized)
|
|
|
|
{
|
|
|
|
px_openssl_initialized = 1;
|
|
|
|
OpenSSL_add_all_algorithms();
|
|
|
|
}
|
|
|
|
|
|
|
|
md = EVP_get_digestbyname(name);
|
|
|
|
if (md == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ctx = px_alloc(sizeof(*ctx));
|
|
|
|
EVP_DigestInit(ctx, md);
|
|
|
|
|
|
|
|
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;
|
|
|
|
h->p.ptr = (void *) ctx;
|
|
|
|
|
|
|
|
*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
|
|
|
|
*
|
/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
|
|
|
* The problem with OpenSSL is that the EVP* family
|
|
|
|
* of functions does not allow enough flexibility
|
|
|
|
* and forces some of the parameters (keylen,
|
|
|
|
* padding) to SSL defaults.
|
2002-11-15 05:54:44 +03:00
|
|
|
*
|
|
|
|
* So need to manage ciphers ourselves.
|
/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
|
|
|
struct ossl_cipher {
|
|
|
|
int (*init) (PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv);
|
|
|
|
int (*encrypt) (PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res);
|
|
|
|
int (*decrypt) (PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res);
|
|
|
|
|
|
|
|
int block_size;
|
|
|
|
int max_key_size;
|
|
|
|
int stream_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
|
|
|
|
2001-10-25 09:50:21 +04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
BF_KEY key;
|
|
|
|
int num;
|
|
|
|
} bf;
|
2002-11-15 05:54:44 +03:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
des_key_schedule key_schedule;
|
|
|
|
} des;
|
|
|
|
CAST_KEY cast_key;
|
2001-10-25 09:50:21 +04:00
|
|
|
} u;
|
|
|
|
uint8 key[EVP_MAX_KEY_LENGTH];
|
|
|
|
uint8 iv[EVP_MAX_IV_LENGTH];
|
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;
|
2001-11-05 20:46:40 +03:00
|
|
|
} ossldata;
|
/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
|
|
|
/* generic */
|
/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
|
2002-11-15 05:54:44 +03: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
|
|
|
{
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = (ossldata *) c->ptr;
|
|
|
|
|
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
|
2002-11-15 05:54:44 +03: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
|
|
|
{
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = (ossldata *) c->ptr;
|
|
|
|
|
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
|
2002-11-15 05:54:44 +03: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;
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = (ossldata *) c->ptr;
|
|
|
|
|
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
|
2002-11-15 05:54:44 +03: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
|
|
|
{
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = (ossldata *) c->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
|
|
|
memset(od, 0, sizeof(*od));
|
|
|
|
pfree(od);
|
|
|
|
pfree(c);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
static int
|
2002-11-15 05:54:44 +03: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
|
|
|
{
|
2002-11-15 05:54:44 +03:00
|
|
|
ossldata *od = c->ptr;
|
2001-10-25 09:50:21 +04:00
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
BF_set_key(&od->u.bf.key, klen, key);
|
2001-10-25 09:50:21 +04:00
|
|
|
if (iv)
|
2002-11-15 05:54:44 +03:00
|
|
|
memcpy(od->iv, iv, BF_BLOCK);
|
2001-10-25 09:50:21 +04:00
|
|
|
else
|
2002-11-15 05:54:44 +03:00
|
|
|
memset(od->iv, 0, BF_BLOCK);
|
|
|
|
od->u.bf.num = 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
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
static int
|
|
|
|
bf_ecb_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *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
|
|
|
{
|
2002-11-15 05:54:44 +03:00
|
|
|
unsigned bs = gen_ossl_block_size(c);
|
|
|
|
unsigned i;
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = c->ptr;
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
for (i = 0; i < dlen / bs; i++)
|
|
|
|
BF_ecb_encrypt(data + i * bs, res + i * bs, &od->u.bf.key, BF_ENCRYPT);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-15 05:54:44 +03:00
|
|
|
bf_ecb_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *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
|
|
|
{
|
2002-11-15 05:54:44 +03:00
|
|
|
unsigned bs = gen_ossl_block_size(c),
|
|
|
|
i;
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = c->ptr;
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
for (i = 0; i < dlen / bs; i++)
|
|
|
|
BF_ecb_encrypt(data + i * bs, res + i * bs, &od->u.bf.key, BF_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
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-15 05:54:44 +03:00
|
|
|
bf_cbc_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *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
|
|
|
{
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = c->ptr;
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
BF_cbc_encrypt(data, res, dlen, &od->u.bf.key, od->iv, BF_ENCRYPT);
|
/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;
|
|
|
|
}
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
static int
|
|
|
|
bf_cbc_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
|
|
|
|
{
|
|
|
|
ossldata *od = c->ptr;
|
|
|
|
|
|
|
|
BF_cbc_encrypt(data, res, dlen, &od->u.bf.key, od->iv, BF_DECRYPT);
|
|
|
|
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
|
|
|
|
|
|
|
static int
|
2002-11-15 05:54:44 +03:00
|
|
|
bf_cfb64_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *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
|
|
|
{
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = c->ptr;
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
BF_cfb64_encrypt(data, res, dlen, &od->u.bf.key, od->iv,
|
|
|
|
&od->u.bf.num, BF_ENCRYPT);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bf_cfb64_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
|
|
|
|
{
|
|
|
|
ossldata *od = c->ptr;
|
|
|
|
|
|
|
|
BF_cfb64_encrypt(data, res, dlen, &od->u.bf.key, od->iv,
|
|
|
|
&od->u.bf.num, BF_DECRYPT);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DES */
|
|
|
|
|
|
|
|
static int
|
|
|
|
ossl_des_init(PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv)
|
|
|
|
{
|
|
|
|
ossldata *od = c->ptr;
|
|
|
|
des_cblock xkey;
|
|
|
|
|
|
|
|
memset(&xkey, 0, sizeof(xkey));
|
|
|
|
memcpy(&xkey, key, klen > 8 ? 8 : klen);
|
|
|
|
des_set_key(&xkey, od->u.des.key_schedule);
|
|
|
|
memset(&xkey, 0, sizeof(xkey));
|
|
|
|
|
2001-10-25 09:50:21 +04:00
|
|
|
if (iv)
|
2002-11-15 05:54:44 +03:00
|
|
|
memcpy(od->iv, iv, 8);
|
2001-10-25 09:50:21 +04:00
|
|
|
else
|
2002-11-15 05:54:44 +03:00
|
|
|
memset(od->iv, 0, 8);
|
/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;
|
|
|
|
}
|
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 int
|
2002-11-15 05:54:44 +03:00
|
|
|
ossl_des_ecb_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen,
|
|
|
|
uint8 *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
|
|
|
{
|
2002-11-15 05:54:44 +03:00
|
|
|
unsigned bs = gen_ossl_block_size(c);
|
|
|
|
unsigned i;
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = c->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
|
|
|
for (i = 0; i < dlen / bs; i++)
|
2002-11-15 05:54:44 +03:00
|
|
|
des_ecb_encrypt((des_cblock*)(data + i * bs),
|
|
|
|
(des_cblock*)(res + i * bs),
|
|
|
|
od->u.des.key_schedule, 1);
|
/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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-15 05:54:44 +03:00
|
|
|
ossl_des_ecb_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen,
|
|
|
|
uint8 *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
|
|
|
{
|
2002-11-15 05:54:44 +03:00
|
|
|
unsigned bs = gen_ossl_block_size(c);
|
|
|
|
unsigned i;
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = c->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
|
|
|
for (i = 0; i < dlen / bs; i++)
|
2002-11-15 05:54:44 +03:00
|
|
|
des_ecb_encrypt((des_cblock*)(data + i * bs),
|
|
|
|
(des_cblock*)(res + i * bs),
|
|
|
|
od->u.des.key_schedule, 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
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-15 05:54:44 +03:00
|
|
|
ossl_des_cbc_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen,
|
|
|
|
uint8 *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
|
|
|
{
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = c->ptr;
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
des_ncbc_encrypt(data, res, dlen, od->u.des.key_schedule,
|
|
|
|
(des_cblock*)od->iv, 1);
|
/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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-15 05:54:44 +03:00
|
|
|
ossl_des_cbc_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen,
|
|
|
|
uint8 *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
|
|
|
{
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = c->ptr;
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
des_ncbc_encrypt(data, res, dlen, od->u.des.key_schedule,
|
|
|
|
(des_cblock*)od->iv, 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
|
|
|
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
|
2002-11-15 05:54:44 +03: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
|
|
|
{
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *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
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
CAST_set_key(&od->u.cast_key, klen, key);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-15 05:54:44 +03:00
|
|
|
ossl_cast_ecb_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *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
|
|
|
{
|
2002-11-15 05:54:44 +03:00
|
|
|
unsigned bs = gen_ossl_block_size(c);
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = c->ptr;
|
2002-11-15 05:54:44 +03:00
|
|
|
const uint8 *end = data + dlen - bs;
|
2001-10-25 09:50:21 +04:00
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
for (; data <= end; data += bs, res += bs)
|
|
|
|
CAST_ecb_encrypt(data, res, &od->u.cast_key, CAST_ENCRYPT);
|
/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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-15 05:54:44 +03:00
|
|
|
ossl_cast_ecb_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *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
|
|
|
{
|
2002-11-15 05:54:44 +03:00
|
|
|
unsigned bs = gen_ossl_block_size(c);
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = c->ptr;
|
2002-11-15 05:54:44 +03:00
|
|
|
const uint8 *end = data + dlen - bs;
|
2001-10-25 09:50:21 +04:00
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
for (; data <= end; data += bs, res += bs)
|
|
|
|
CAST_ecb_encrypt(data, res, &od->u.cast_key, CAST_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
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-15 05:54:44 +03:00
|
|
|
ossl_cast_cbc_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *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
|
|
|
{
|
2001-10-25 09:50:21 +04:00
|
|
|
ossldata *od = c->ptr;
|
|
|
|
|
2002-11-15 05:54:44 +03:00
|
|
|
CAST_cbc_encrypt(data, res, dlen, &od->u.cast_key, od->iv, CAST_ENCRYPT);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ossl_cast_cbc_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *res)
|
|
|
|
{
|
|
|
|
ossldata *od = c->ptr;
|
|
|
|
|
|
|
|
CAST_cbc_encrypt(data, res, dlen, &od->u.cast_key, od->iv, CAST_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
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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"},
|
|
|
|
{"cast5", "cast5-cbc"},
|
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 = {
|
|
|
|
bf_init, bf_cbc_encrypt, bf_cbc_decrypt,
|
|
|
|
64/8, 448/8, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ossl_cipher ossl_bf_ecb = {
|
|
|
|
bf_init, bf_ecb_encrypt, bf_ecb_decrypt,
|
|
|
|
64/8, 448/8, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ossl_cipher ossl_bf_cfb = {
|
|
|
|
bf_init, bf_cfb64_encrypt, bf_cfb64_decrypt,
|
|
|
|
64/8, 448/8, 1
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ossl_cipher ossl_des_ecb = {
|
|
|
|
ossl_des_init, ossl_des_ecb_encrypt, ossl_des_ecb_decrypt,
|
|
|
|
64/8, 64/8, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ossl_cipher ossl_des_cbc = {
|
|
|
|
ossl_des_init, ossl_des_cbc_encrypt, ossl_des_cbc_decrypt,
|
|
|
|
64/8, 64/8, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ossl_cipher ossl_cast_ecb = {
|
|
|
|
ossl_cast_init, ossl_cast_ecb_encrypt, ossl_cast_ecb_decrypt,
|
|
|
|
64/8, 128/8, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ossl_cipher ossl_cast_cbc = {
|
|
|
|
ossl_cast_init, ossl_cast_cbc_encrypt, ossl_cast_cbc_decrypt,
|
|
|
|
64/8, 128/8, 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
|
|
|
|
|
|
|
/*
|
|
|
|
* Special handlers
|
|
|
|
*/
|
2002-11-15 05:54:44 +03:00
|
|
|
static const struct
|
2001-10-25 09:50:21 +04:00
|
|
|
{
|
2002-11-15 05:54:44 +03:00
|
|
|
const char *name;
|
|
|
|
const struct ossl_cipher *ciph;
|
|
|
|
} ossl_cipher_types[] =
|
2001-10-25 09:50:21 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
{
|
2002-11-15 05:54:44 +03:00
|
|
|
"bf-cbc", &ossl_bf_cbc
|
2001-10-25 09:50:21 +04:00
|
|
|
},
|
|
|
|
{
|
2002-11-15 05:54:44 +03:00
|
|
|
"bf-ecb", &ossl_bf_ecb
|
2001-10-25 09:50:21 +04:00
|
|
|
},
|
|
|
|
{
|
2002-11-15 05:54:44 +03:00
|
|
|
"bf-cfb", &ossl_bf_cfb
|
2001-10-25 09:50:21 +04:00
|
|
|
},
|
|
|
|
{
|
2002-11-15 05:54:44 +03:00
|
|
|
"des-ecb", &ossl_des_ecb
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"des-cbc", &ossl_des_cbc
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cast5-ecb", &ossl_cast_ecb
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cast5-cbc", &ossl_cast_cbc
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/* PUBLIC functions */
|
|
|
|
|
|
|
|
int
|
2001-10-25 09:50:21 +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
|
|
|
{
|
2001-11-20 18:50:53 +03:00
|
|
|
unsigned i;
|
2001-10-25 09:50:21 +04:00
|
|
|
PX_Cipher *c = NULL,
|
|
|
|
*csrc;
|
|
|
|
ossldata *od;
|
2002-11-15 05:54:44 +03:00
|
|
|
const struct ossl_cipher *ossl_ciph = 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
|
|
|
|
|
|
|
name = px_resolve_alias(ossl_aliases, name);
|
2002-11-15 05:54:44 +03:00
|
|
|
for (i = 0; ossl_cipher_types[i].name; i++) {
|
|
|
|
if (!strcmp(ossl_cipher_types[i].name, name)) {
|
|
|
|
ossl_ciph = ossl_cipher_types[i].ciph;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ossl_ciph == 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
|
|
|
return -1;
|
|
|
|
|
|
|
|
od = px_alloc(sizeof(*od));
|
|
|
|
memset(od, 0, sizeof(*od));
|
2002-11-15 05:54:44 +03:00
|
|
|
od->ciph = ossl_ciph;
|
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
|
|
|
csrc = NULL;
|
|
|
|
|
|
|
|
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;
|
|
|
|
c->init = ossl_ciph->init;
|
|
|
|
c->encrypt = ossl_ciph->encrypt;
|
|
|
|
c->decrypt = ossl_ciph->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;
|
|
|
|
}
|