Commit f46ca5fb authored by unknown's avatar unknown

Merge bk-internal.mysql.com:/home/bk/mysql-4.0

into mysql.com:/home/dlenev/src/mysql-4.0-opssl

parents 0a58c2ae 867aec2f
...@@ -1105,4 +1105,14 @@ typedef union { ...@@ -1105,4 +1105,14 @@ typedef union {
#define statistic_add(V,C,L) (V)+=(C) #define statistic_add(V,C,L) (V)+=(C)
#endif #endif
#ifdef HAVE_OPENSSL
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_NUMBER < 0x0090700f
#define DES_cblock des_cblock
#define DES_key_schedule des_key_schedule
#define DES_set_key_unchecked(k,ks) des_set_key_unchecked((k),*(ks))
#define DES_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e) des_ede3_cbc_encrypt((i),(o),(l),*(k1),*(k2),*(k3),(iv),(e))
#endif
#endif
#endif /* my_global_h */ #endif /* my_global_h */
...@@ -76,16 +76,16 @@ load_des_key_file(const char *file_name) ...@@ -76,16 +76,16 @@ load_des_key_file(const char *file_name)
if (start != end) if (start != end)
{ {
des_cblock ivec; DES_cblock ivec;
bzero((char*) &ivec,sizeof(ivec)); bzero((char*) &ivec,sizeof(ivec));
// We make good 24-byte (168 bit) key from given plaintext key with MD5 // We make good 24-byte (168 bit) key from given plaintext key with MD5
EVP_BytesToKey(EVP_des_ede3_cbc(),EVP_md5(),NULL, EVP_BytesToKey(EVP_des_ede3_cbc(),EVP_md5(),NULL,
(uchar *) start, (int) (end-start),1, (uchar *) start, (int) (end-start),1,
(uchar *) &keyblock, (uchar *) &keyblock,
ivec); ivec);
des_set_key_unchecked(&keyblock.key1,des_keyschedule[(int)offset].ks1); DES_set_key_unchecked(&keyblock.key1,&(des_keyschedule[(int)offset].ks1));
des_set_key_unchecked(&keyblock.key2,des_keyschedule[(int)offset].ks2); DES_set_key_unchecked(&keyblock.key2,&(des_keyschedule[(int)offset].ks2));
des_set_key_unchecked(&keyblock.key3,des_keyschedule[(int)offset].ks3); DES_set_key_unchecked(&keyblock.key3,&(des_keyschedule[(int)offset].ks3));
if (des_default_key == 15) if (des_default_key == 15)
des_default_key= (uint) offset; // use first as def. des_default_key= (uint) offset; // use first as def.
} }
......
...@@ -330,7 +330,7 @@ void Item_func_concat::fix_length_and_dec() ...@@ -330,7 +330,7 @@ void Item_func_concat::fix_length_and_dec()
String *Item_func_des_encrypt::val_str(String *str) String *Item_func_des_encrypt::val_str(String *str)
{ {
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
des_cblock ivec; DES_cblock ivec;
struct st_des_keyblock keyblock; struct st_des_keyblock keyblock;
struct st_des_keyschedule keyschedule; struct st_des_keyschedule keyschedule;
const char *append_str="********"; const char *append_str="********";
...@@ -370,9 +370,9 @@ String *Item_func_des_encrypt::val_str(String *str) ...@@ -370,9 +370,9 @@ String *Item_func_des_encrypt::val_str(String *str)
EVP_BytesToKey(EVP_des_ede3_cbc(),EVP_md5(),NULL, EVP_BytesToKey(EVP_des_ede3_cbc(),EVP_md5(),NULL,
(uchar*) keystr->ptr(), (int) keystr->length(), (uchar*) keystr->ptr(), (int) keystr->length(),
1, (uchar*) &keyblock,ivec); 1, (uchar*) &keyblock,ivec);
des_set_key_unchecked(&keyblock.key1,keyschedule.ks1); DES_set_key_unchecked(&keyblock.key1,&keyschedule.ks1);
des_set_key_unchecked(&keyblock.key2,keyschedule.ks2); DES_set_key_unchecked(&keyblock.key2,&keyschedule.ks2);
des_set_key_unchecked(&keyblock.key3,keyschedule.ks3); DES_set_key_unchecked(&keyblock.key3,&keyschedule.ks3);
} }
/* /*
...@@ -393,12 +393,12 @@ String *Item_func_des_encrypt::val_str(String *str) ...@@ -393,12 +393,12 @@ String *Item_func_des_encrypt::val_str(String *str)
tmp_value[0]=(char) (128 | key_number); tmp_value[0]=(char) (128 | key_number);
// Real encryption // Real encryption
bzero((char*) &ivec,sizeof(ivec)); bzero((char*) &ivec,sizeof(ivec));
des_ede3_cbc_encrypt((const uchar*) (res->ptr()), DES_ede3_cbc_encrypt((const uchar*) (res->ptr()),
(uchar*) (tmp_value.ptr()+1), (uchar*) (tmp_value.ptr()+1),
res_length, res_length,
keyschedule.ks1, &keyschedule.ks1,
keyschedule.ks2, &keyschedule.ks2,
keyschedule.ks3, &keyschedule.ks3,
&ivec, TRUE); &ivec, TRUE);
return &tmp_value; return &tmp_value;
...@@ -412,8 +412,8 @@ String *Item_func_des_encrypt::val_str(String *str) ...@@ -412,8 +412,8 @@ String *Item_func_des_encrypt::val_str(String *str)
String *Item_func_des_decrypt::val_str(String *str) String *Item_func_des_decrypt::val_str(String *str)
{ {
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
des_key_schedule ks1, ks2, ks3; DES_key_schedule ks1, ks2, ks3;
des_cblock ivec; DES_cblock ivec;
struct st_des_keyblock keyblock; struct st_des_keyblock keyblock;
struct st_des_keyschedule keyschedule; struct st_des_keyschedule keyschedule;
String *res= args[0]->val_str(str); String *res= args[0]->val_str(str);
...@@ -447,20 +447,20 @@ String *Item_func_des_decrypt::val_str(String *str) ...@@ -447,20 +447,20 @@ String *Item_func_des_decrypt::val_str(String *str)
(uchar*) keystr->ptr(),(int) keystr->length(), (uchar*) keystr->ptr(),(int) keystr->length(),
1,(uchar*) &keyblock,ivec); 1,(uchar*) &keyblock,ivec);
// Here we set all 64-bit keys (56 effective) one by one // Here we set all 64-bit keys (56 effective) one by one
des_set_key_unchecked(&keyblock.key1,keyschedule.ks1); DES_set_key_unchecked(&keyblock.key1,&keyschedule.ks1);
des_set_key_unchecked(&keyblock.key2,keyschedule.ks2); DES_set_key_unchecked(&keyblock.key2,&keyschedule.ks2);
des_set_key_unchecked(&keyblock.key3,keyschedule.ks3); DES_set_key_unchecked(&keyblock.key3,&keyschedule.ks3);
} }
if (tmp_value.alloc(length-1)) if (tmp_value.alloc(length-1))
goto error; goto error;
bzero((char*) &ivec,sizeof(ivec)); bzero((char*) &ivec,sizeof(ivec));
des_ede3_cbc_encrypt((const uchar*) res->ptr()+1, DES_ede3_cbc_encrypt((const uchar*) res->ptr()+1,
(uchar*) (tmp_value.ptr()), (uchar*) (tmp_value.ptr()),
length-1, length-1,
keyschedule.ks1, &keyschedule.ks1,
keyschedule.ks2, &keyschedule.ks2,
keyschedule.ks3, &keyschedule.ks3,
&ivec, FALSE); &ivec, FALSE);
/* Restore old length of key */ /* Restore old length of key */
if ((tail=(uint) (uchar) tmp_value[length-2]) > 8) if ((tail=(uint) (uchar) tmp_value[length-2]) > 8)
......
...@@ -474,11 +474,11 @@ Field *find_field_in_table(THD *thd,TABLE *table,const char *name,uint length, ...@@ -474,11 +474,11 @@ Field *find_field_in_table(THD *thd,TABLE *table,const char *name,uint length,
#include <openssl/des.h> #include <openssl/des.h>
struct st_des_keyblock struct st_des_keyblock
{ {
des_cblock key1, key2, key3; DES_cblock key1, key2, key3;
}; };
struct st_des_keyschedule struct st_des_keyschedule
{ {
des_key_schedule ks1, ks2, ks3; DES_key_schedule ks1, ks2, ks3;
}; };
extern char *des_key_file; extern char *des_key_file;
extern struct st_des_keyschedule des_keyschedule[10]; extern struct st_des_keyschedule des_keyschedule[10];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment