Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
3c52d17f
Commit
3c52d17f
authored
Jul 11, 2005
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for AES cipher with older OpenSSL libraries.
Marko Kreen
parent
8826fe85
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
14 deletions
+41
-14
contrib/pgcrypto/openssl.c
contrib/pgcrypto/openssl.c
+41
-14
No files found.
contrib/pgcrypto/openssl.c
View file @
3c52d17f
...
...
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $PostgreSQL: pgsql/contrib/pgcrypto/openssl.c,v 1.2
2 2005/07/10 13:54:34 momjian
Exp $
* $PostgreSQL: pgsql/contrib/pgcrypto/openssl.c,v 1.2
3 2005/07/11 14:38:05 tgl
Exp $
*/
#include <postgres.h>
...
...
@@ -44,11 +44,47 @@
/*
* Does OpenSSL support AES?
*/
#undef GOT_AES
#if OPENSSL_VERSION_NUMBER >= 0x00907000L
#define GOT_AES
/* Yes, it does. */
#include <openssl/aes.h>
#endif
#else
/* old OPENSSL */
/*
* No, it does not. So use included rijndael code to emulate it.
*/
#include "rijndael.c"
#define AES_ENCRYPT 1
#define AES_DECRYPT 0
#define AES_KEY rijndael_ctx
#define AES_set_encrypt_key(key, kbits, ctx) \
aes_set_key((ctx), (key), (kbits), 1)
#define AES_set_decrypt_key(key, kbits, ctx) \
aes_set_key((ctx), (key), (kbits), 0)
#define AES_ecb_encrypt(src, dst, ctx, enc) \
do { \
memcpy((dst), (src), 16); \
if (enc) \
aes_ecb_encrypt((ctx), (dst), 16); \
else \
aes_ecb_decrypt((ctx), (dst), 16); \
} while (0)
#define AES_cbc_encrypt(src, dst, len, ctx, iv, enc) \
do { \
memcpy((dst), (src), (len)); \
if (enc) \
aes_cbc_encrypt((ctx), (iv), (dst), (len)); \
else \
aes_cbc_decrypt((ctx), (iv), (dst), (len)); \
} while (0)
#endif
/* old OPENSSL */
/*
* Compatibility with older OpenSSL API for DES.
...
...
@@ -205,9 +241,7 @@ typedef struct
DES_key_schedule
k1
,
k2
,
k3
;
}
des3
;
CAST_KEY
cast_key
;
#ifdef GOT_AES
AES_KEY
aes_key
;
#endif
}
u
;
uint8
key
[
EVP_MAX_KEY_LENGTH
];
uint8
iv
[
EVP_MAX_IV_LENGTH
];
...
...
@@ -549,8 +583,6 @@ ossl_cast_cbc_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen, uint8 *re
/* AES */
#ifdef GOT_AES
static
int
ossl_aes_init
(
PX_Cipher
*
c
,
const
uint8
*
key
,
unsigned
klen
,
const
uint8
*
iv
)
{
...
...
@@ -642,7 +674,6 @@ ossl_aes_cbc_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen,
AES_cbc_encrypt
(
data
,
res
,
dlen
,
&
od
->
u
.
aes_key
,
od
->
iv
,
AES_DECRYPT
);
return
0
;
}
#endif
/*
* aliases
...
...
@@ -711,7 +742,6 @@ static const struct ossl_cipher ossl_cast_cbc = {
64
/
8
,
128
/
8
,
0
};
#ifdef GOT_AES
static
const
struct
ossl_cipher
ossl_aes_ecb
=
{
ossl_aes_init
,
ossl_aes_ecb_encrypt
,
ossl_aes_ecb_decrypt
,
128
/
8
,
256
/
8
,
0
...
...
@@ -721,7 +751,6 @@ static const struct ossl_cipher ossl_aes_cbc = {
ossl_aes_init
,
ossl_aes_cbc_encrypt
,
ossl_aes_cbc_decrypt
,
128
/
8
,
256
/
8
,
0
};
#endif
/*
* Special handlers
...
...
@@ -742,10 +771,8 @@ static const struct ossl_cipher_lookup ossl_cipher_types[] = {
{
"des3-cbc"
,
&
ossl_des3_cbc
},
{
"cast5-ecb"
,
&
ossl_cast_ecb
},
{
"cast5-cbc"
,
&
ossl_cast_cbc
},
#ifdef GOT_AES
{
"aes-ecb"
,
&
ossl_aes_ecb
},
{
"aes-cbc"
,
&
ossl_aes_cbc
},
#endif
{
NULL
}
};
...
...
@@ -790,7 +817,7 @@ static int openssl_random_init = 0;
* OpenSSL random should re-feeded occasionally. From /dev/urandom
* preferably.
*/
static
void
init_openssl_rand
()
static
void
init_openssl_rand
(
void
)
{
if
(
RAND_get_rand_method
()
==
NULL
)
RAND_set_rand_method
(
RAND_SSLeay
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment