Loading sql/Makefile.am +1 −1 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ sql_select.h structs.h table.h sql_udf.h hash_filo.h\ lex.h lex_symbol.h sql_acl.h sql_crypt.h \ log_event.h mini_client.h sql_repl.h slave.h \ stacktrace.h sql_sort.h stacktrace.h sql_sort.h sql_cache.h mysqld_SOURCES = sql_lex.cc sql_handler.cc \ item.cc item_sum.cc item_buff.cc item_func.cc \ item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \ Loading sql/des_key_file.cc +4 −4 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ */ struct st_des_keyschedule des_keyschedule[10]; uint default_des_key; uint des_default_key; void load_des_key_file(const char *file_name) Loading @@ -43,7 +43,7 @@ load_des_key_file(const char *file_name) goto error; bzero((char*) des_keyschedule,sizeof(struct st_des_keyschedule) * 10); default_des_key=15; // Impossible key des_default_key=15; // Impossible key for (;;) { char *start, *end; Loading Loading @@ -72,8 +72,8 @@ load_des_key_file(const char *file_name) 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.key3,des_keyschedule[(int)offset].ks3); if (default_des_key == 15) default_des_key= (uint) offset; // use first as def. if (des_default_key == 15) des_default_key= (uint) offset; // use first as def. } } else Loading sql/item_strfunc.cc +21 −17 Original line number Diff line number Diff line Loading @@ -221,8 +221,9 @@ String *Item_func_des_encrypt::val_str(String *str) des_cblock ivec={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; struct st_des_keyblock keyblock; struct st_des_keyschedule keyschedule; struct st_des_keyschedule *keyschedule_ptr=&keyschedule; uint key_number=15; struct st_des_keyschedule *keyschedule_ptr; const char *append_str="********"; uint key_number, res_length, tail; String *res= args[0]->val_str(str); if ((null_value=args[0]->null_value)) Loading @@ -231,23 +232,24 @@ String *Item_func_des_encrypt::val_str(String *str) return &empty_string; if (arg_count == 1) keyschedule_ptr=des_keyschedule[key_number=default_des_key]; else if (args[1]->result_type == INT_RESULT) keyschedule_ptr= &des_keyschedule[key_number=des_default_key]; else if (args[1]->result_type() == INT_RESULT) { key_number= (uint) args[1]->val_int(); if (key_number > 9) goto error; keyschedule_ptr= des_keyschedule[key_number]; keyschedule_ptr= &des_keyschedule[key_number]; } else { const char *append_str="********"; uint tail,res_length; String *keystr=args[1]->val_str(&tmp_value); if (!keystr) goto error; key_number=15; // User key string /* We make good 24-byte (168 bit) key from given plaintext key with MD5 */ keyschedule_ptr= &keyschedule; EVP_BytesToKey(EVP_des_ede3_cbc(),EVP_md5(),NULL, (uchar*) keystr->ptr(), (int) keystr->length(), 1, (uchar*) &keyblock,ivec); Loading @@ -268,13 +270,13 @@ String *Item_func_des_encrypt::val_str(String *str) tail= (7-(res->length()+7) % 8); // 0..7 marking extra length res_length=res->length()+tail+1; if (tail && res->append(append_str, tail) || tmp_value.alloc(res_length)) goto err; goto error; tmp_value.length(res_length); tmp_value.[0]=(char) (128 | tail << 4 | key_number); tmp_value[0]=(char) (128 | tail << 4 | key_number); // Real encryption des_ede3_cbc_encrypt((const uchar*) (res->ptr()), (uchar*) (tmp_value->ptr()+1), (uchar*) (tmp_value.ptr()+1), res->length(), keyschedule_ptr->ks1, keyschedule_ptr->ks2, Loading @@ -296,28 +298,30 @@ String *Item_func_des_decrypt::val_str(String *str) des_cblock ivec={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; struct st_des_keyblock keyblock; struct st_des_keyschedule keyschedule; struct st_des_keyschedule *keyschedule_ptr=&keyschedule; struct st_des_keyschedule *keyschedule_ptr; String *res= args[0]->val_str(str); if ((null_value=args[0]->null_value)) return 0; if (res->length(0) < 9 || (res->length()) % 8 != 1 || !(res->[0] & 128)) if (res->length() < 9 || (res->length() % 8) != 1 || !((*res)[0] & 128)) return res; // Skip decryption if not encrypted if (arg_count == 1) // If automatic uncompression { uint key_number=res->[0] & 15; uint key_number=(uint) (*res)[0] & 15; // Check if automatic key and that we have privilege to uncompress using it if (!(current_thd->master_access & PROCESS_ACL) || key_number > 9) goto error; keyschedule_ptr=des_keyschedule[key_number-1]; keyschedule_ptr= &des_keyschedule[key_number]; } else { // We make good 24-byte (168 bit) key from given plaintext key with MD5 String *keystr=args[1]->val_str(&tmp_value); if (!key_str) if (!keystr) goto error; keyschedule_ptr= &keyschedule; EVP_BytesToKey(EVP_des_ede3_cbc(),EVP_md5(),NULL, (uchar*) keystr->ptr(),(int) keystr->length(), 1,(uchar*) &keyblock,ivec); Loading @@ -327,11 +331,11 @@ String *Item_func_des_decrypt::val_str(String *str) des_set_key_unchecked(&keyblock.key3,keyschedule_ptr->ks3); } if (tmp_value.alloc(res->length()-1)) goto err; goto error; /* Restore old length of key */ tmp_value.length(res->length()-1-(((uchar) res->[0] >> 4) & 7)); tmp_value.length(res->length()-1-(((uchar) (*res)[0] >> 4) & 7)); des_ede3_cbc_encrypt((const uchar*) res->ptr()+1, (uchar*) (tmp_value->ptr()), (uchar*) (tmp_value.ptr()), res->length()-1, keyschedule_ptr->ks1, keyschedule_ptr->ks2, Loading sql/lex.h +2 −2 Original line number Diff line number Diff line Loading @@ -412,8 +412,8 @@ static SYMBOL sql_functions[] = { { "DAYOFYEAR", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_dayofyear)}, { "DECODE", SYM(DECODE_SYM),0,0}, { "DEGREES", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_degrees)}, { "DES_ENCRYPT", SYM(DES_ENCRYPT),0,0}, { "DES_DECRYPT", SYM(DES_DECRYPT),0,0}, { "DES_ENCRYPT", SYM(DES_ENCRYPT_SYM),0,0}, { "DES_DECRYPT", SYM(DES_DECRYPT_SYM),0,0}, { "ELT", SYM(ELT_FUNC),0,0}, { "ENCODE", SYM(ENCODE_SYM),0,0}, { "ENCRYPT", SYM(ENCRYPT),0,0}, Loading sql/mysql_priv.h +1 −1 Original line number Diff line number Diff line Loading @@ -405,7 +405,7 @@ struct st_des_keyschedule { des_key_schedule ks1, ks2, ks3; }; extern struct st_des_keyschedule des_keyschedule[9]; extern struct st_des_keyschedule des_keyschedule[10]; extern uint des_default_key; void load_des_key_file(const char *file_name); #endif /* HAVE_OPENSSL */ Loading Loading
sql/Makefile.am +1 −1 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ sql_select.h structs.h table.h sql_udf.h hash_filo.h\ lex.h lex_symbol.h sql_acl.h sql_crypt.h \ log_event.h mini_client.h sql_repl.h slave.h \ stacktrace.h sql_sort.h stacktrace.h sql_sort.h sql_cache.h mysqld_SOURCES = sql_lex.cc sql_handler.cc \ item.cc item_sum.cc item_buff.cc item_func.cc \ item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \ Loading
sql/des_key_file.cc +4 −4 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ */ struct st_des_keyschedule des_keyschedule[10]; uint default_des_key; uint des_default_key; void load_des_key_file(const char *file_name) Loading @@ -43,7 +43,7 @@ load_des_key_file(const char *file_name) goto error; bzero((char*) des_keyschedule,sizeof(struct st_des_keyschedule) * 10); default_des_key=15; // Impossible key des_default_key=15; // Impossible key for (;;) { char *start, *end; Loading Loading @@ -72,8 +72,8 @@ load_des_key_file(const char *file_name) 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.key3,des_keyschedule[(int)offset].ks3); if (default_des_key == 15) default_des_key= (uint) offset; // use first as def. if (des_default_key == 15) des_default_key= (uint) offset; // use first as def. } } else Loading
sql/item_strfunc.cc +21 −17 Original line number Diff line number Diff line Loading @@ -221,8 +221,9 @@ String *Item_func_des_encrypt::val_str(String *str) des_cblock ivec={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; struct st_des_keyblock keyblock; struct st_des_keyschedule keyschedule; struct st_des_keyschedule *keyschedule_ptr=&keyschedule; uint key_number=15; struct st_des_keyschedule *keyschedule_ptr; const char *append_str="********"; uint key_number, res_length, tail; String *res= args[0]->val_str(str); if ((null_value=args[0]->null_value)) Loading @@ -231,23 +232,24 @@ String *Item_func_des_encrypt::val_str(String *str) return &empty_string; if (arg_count == 1) keyschedule_ptr=des_keyschedule[key_number=default_des_key]; else if (args[1]->result_type == INT_RESULT) keyschedule_ptr= &des_keyschedule[key_number=des_default_key]; else if (args[1]->result_type() == INT_RESULT) { key_number= (uint) args[1]->val_int(); if (key_number > 9) goto error; keyschedule_ptr= des_keyschedule[key_number]; keyschedule_ptr= &des_keyschedule[key_number]; } else { const char *append_str="********"; uint tail,res_length; String *keystr=args[1]->val_str(&tmp_value); if (!keystr) goto error; key_number=15; // User key string /* We make good 24-byte (168 bit) key from given plaintext key with MD5 */ keyschedule_ptr= &keyschedule; EVP_BytesToKey(EVP_des_ede3_cbc(),EVP_md5(),NULL, (uchar*) keystr->ptr(), (int) keystr->length(), 1, (uchar*) &keyblock,ivec); Loading @@ -268,13 +270,13 @@ String *Item_func_des_encrypt::val_str(String *str) tail= (7-(res->length()+7) % 8); // 0..7 marking extra length res_length=res->length()+tail+1; if (tail && res->append(append_str, tail) || tmp_value.alloc(res_length)) goto err; goto error; tmp_value.length(res_length); tmp_value.[0]=(char) (128 | tail << 4 | key_number); tmp_value[0]=(char) (128 | tail << 4 | key_number); // Real encryption des_ede3_cbc_encrypt((const uchar*) (res->ptr()), (uchar*) (tmp_value->ptr()+1), (uchar*) (tmp_value.ptr()+1), res->length(), keyschedule_ptr->ks1, keyschedule_ptr->ks2, Loading @@ -296,28 +298,30 @@ String *Item_func_des_decrypt::val_str(String *str) des_cblock ivec={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; struct st_des_keyblock keyblock; struct st_des_keyschedule keyschedule; struct st_des_keyschedule *keyschedule_ptr=&keyschedule; struct st_des_keyschedule *keyschedule_ptr; String *res= args[0]->val_str(str); if ((null_value=args[0]->null_value)) return 0; if (res->length(0) < 9 || (res->length()) % 8 != 1 || !(res->[0] & 128)) if (res->length() < 9 || (res->length() % 8) != 1 || !((*res)[0] & 128)) return res; // Skip decryption if not encrypted if (arg_count == 1) // If automatic uncompression { uint key_number=res->[0] & 15; uint key_number=(uint) (*res)[0] & 15; // Check if automatic key and that we have privilege to uncompress using it if (!(current_thd->master_access & PROCESS_ACL) || key_number > 9) goto error; keyschedule_ptr=des_keyschedule[key_number-1]; keyschedule_ptr= &des_keyschedule[key_number]; } else { // We make good 24-byte (168 bit) key from given plaintext key with MD5 String *keystr=args[1]->val_str(&tmp_value); if (!key_str) if (!keystr) goto error; keyschedule_ptr= &keyschedule; EVP_BytesToKey(EVP_des_ede3_cbc(),EVP_md5(),NULL, (uchar*) keystr->ptr(),(int) keystr->length(), 1,(uchar*) &keyblock,ivec); Loading @@ -327,11 +331,11 @@ String *Item_func_des_decrypt::val_str(String *str) des_set_key_unchecked(&keyblock.key3,keyschedule_ptr->ks3); } if (tmp_value.alloc(res->length()-1)) goto err; goto error; /* Restore old length of key */ tmp_value.length(res->length()-1-(((uchar) res->[0] >> 4) & 7)); tmp_value.length(res->length()-1-(((uchar) (*res)[0] >> 4) & 7)); des_ede3_cbc_encrypt((const uchar*) res->ptr()+1, (uchar*) (tmp_value->ptr()), (uchar*) (tmp_value.ptr()), res->length()-1, keyschedule_ptr->ks1, keyschedule_ptr->ks2, Loading
sql/lex.h +2 −2 Original line number Diff line number Diff line Loading @@ -412,8 +412,8 @@ static SYMBOL sql_functions[] = { { "DAYOFYEAR", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_dayofyear)}, { "DECODE", SYM(DECODE_SYM),0,0}, { "DEGREES", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_degrees)}, { "DES_ENCRYPT", SYM(DES_ENCRYPT),0,0}, { "DES_DECRYPT", SYM(DES_DECRYPT),0,0}, { "DES_ENCRYPT", SYM(DES_ENCRYPT_SYM),0,0}, { "DES_DECRYPT", SYM(DES_DECRYPT_SYM),0,0}, { "ELT", SYM(ELT_FUNC),0,0}, { "ENCODE", SYM(ENCODE_SYM),0,0}, { "ENCRYPT", SYM(ENCRYPT),0,0}, Loading
sql/mysql_priv.h +1 −1 Original line number Diff line number Diff line Loading @@ -405,7 +405,7 @@ struct st_des_keyschedule { des_key_schedule ks1, ks2, ks3; }; extern struct st_des_keyschedule des_keyschedule[9]; extern struct st_des_keyschedule des_keyschedule[10]; extern uint des_default_key; void load_des_key_file(const char *file_name); #endif /* HAVE_OPENSSL */ Loading