Index: contrib/pgcrypto/openssl.c =================================================================== RCS file: /opt/arc/cvs2/pgsql/contrib/pgcrypto/openssl.c,v retrieving revision 1.22 diff -u -c -r1.22 openssl.c *** contrib/pgcrypto/openssl.c 10 Jul 2005 13:54:34 -0000 1.22 --- contrib/pgcrypto/openssl.c 11 Jul 2005 13:02:00 -0000 *************** *** 44,53 **** /* * Does OpenSSL support AES? */ - #undef GOT_AES #if OPENSSL_VERSION_NUMBER >= 0x00907000L ! #define GOT_AES #include #endif /* --- 44,89 ---- /* * Does OpenSSL support AES? */ #if OPENSSL_VERSION_NUMBER >= 0x00907000L ! ! /* Yes, it does. */ #include + + #else + + /* + * 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 /* *************** *** 205,213 **** 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]; --- 241,247 ---- *************** *** 549,556 **** /* AES */ - #ifdef GOT_AES - static int ossl_aes_init(PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv) { --- 583,588 ---- *************** *** 642,648 **** AES_cbc_encrypt(data, res, dlen, &od->u.aes_key, od->iv, AES_DECRYPT); return 0; } - #endif /* * aliases --- 674,679 ---- *************** *** 711,717 **** 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 --- 742,747 ---- *************** *** 721,727 **** ossl_aes_init, ossl_aes_cbc_encrypt, ossl_aes_cbc_decrypt, 128 / 8, 256 / 8, 0 }; - #endif /* * Special handlers --- 751,756 ---- *************** *** 742,751 **** {"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} }; --- 771,778 ----