diff options
author | unknown <monty@hundin.mysql.fi> | 2001-12-13 03:36:36 +0200 |
---|---|---|
committer | unknown <monty@hundin.mysql.fi> | 2001-12-13 03:36:36 +0200 |
commit | 1ad683a4ff84d6dc6e3d1649d656623a8f88069a (patch) | |
tree | a6e815e1cd4e8eae71ab4ba58d4bb2176a45d561 /sql | |
parent | eaee0ac0caae0b0c6193ca3b003b4167daf28c3e (diff) | |
download | mariadb-git-1ad683a4ff84d6dc6e3d1649d656623a8f88069a.tar.gz |
Fixes for des_crypt functions.
sql/Makefile.am:
Added missing header file
sql/des_key_file.cc:
Fixed compiler errors
sql/item_strfunc.cc:
Fixed compiler errors
sql/lex.h:
Portablity fix
sql/mysql_priv.h:
Fixed wrong type
sql/sql_yacc.yy:
Portablity fix
Diffstat (limited to 'sql')
-rw-r--r-- | sql/Makefile.am | 2 | ||||
-rw-r--r-- | sql/des_key_file.cc | 8 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 38 | ||||
-rw-r--r-- | sql/lex.h | 4 | ||||
-rw-r--r-- | sql/mysql_priv.h | 2 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 12 |
6 files changed, 35 insertions, 31 deletions
diff --git a/sql/Makefile.am b/sql/Makefile.am index d6bd4256145..8238160d652 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -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 \ diff --git a/sql/des_key_file.cc b/sql/des_key_file.cc index 164c2ab706e..c6ac9ab6059 100644 --- a/sql/des_key_file.cc +++ b/sql/des_key_file.cc @@ -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) @@ -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; @@ -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 diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 004acd2d5ec..792c76ebc0d 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -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)) @@ -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); @@ -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, @@ -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); @@ -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, diff --git a/sql/lex.h b/sql/lex.h index 744898d6b9c..d20141a560e 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -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}, diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index dad5f27a3e0..a6859e31bde 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -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 */ diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 1dbdda28ffc..ea105f3be50 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -382,8 +382,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %token DAY_SECOND_SYM %token DAY_SYM %token DECODE_SYM -%token DES_ENCRYPT -%token DES_DECRYPT +%token DES_ENCRYPT_SYM +%token DES_DECRYPT_SYM %token ELSE %token ELT_FUNC %token ENCODE_SYM @@ -1647,13 +1647,13 @@ simple_expr: { $$= new Item_func_decode($3,$5.str); } | ENCODE_SYM '(' expr ',' TEXT_STRING ')' { $$= new Item_func_encode($3,$5.str); } - | DES_DECRYPT '(' expr ')' + | DES_DECRYPT_SYM '(' expr ')' { $$= new Item_func_des_decrypt($3); } - | DES_DECRYPT '(' expr ',' expr ')' + | DES_DECRYPT_SYM '(' expr ',' expr ')' { $$= new Item_func_des_decrypt($3,$5); } - | DES_ENCRYPT '(' expr ')' + | DES_ENCRYPT_SYM '(' expr ')' { $$= new Item_func_des_encrypt($3); } - | DES_ENCRYPT '(' expr ',' expr ')' + | DES_ENCRYPT_SYM '(' expr ',' expr ')' { $$= new Item_func_des_encrypt($3,$5); } | EXPORT_SET '(' expr ',' expr ',' expr ')' { $$= new Item_func_export_set($3, $5, $7); } |