#include <item_strfunc.h>
Inheritance diagram for Item_func_des_decrypt:


Public Member Functions | |
| Item_func_des_decrypt (Item *a) | |
| Item_func_des_decrypt (Item *a, Item *b) | |
| String * | val_str (String *) |
| void | fix_length_and_dec () |
| const char * | func_name () const |
Private Attributes | |
| String | tmp_value |
Definition at line 322 of file item_strfunc.h.
| Item_func_des_decrypt::Item_func_des_decrypt | ( | Item * | a | ) | [inline] |
| void Item_func_des_decrypt::fix_length_and_dec | ( | ) | [inline, virtual] |
Implements Item_result_field.
Definition at line 329 of file item_strfunc.h.
References Item_func::args, Item::max_length, and Item::maybe_null.
00329 { maybe_null=1; max_length = args[0]->max_length; }
| const char* Item_func_des_decrypt::func_name | ( | ) | const [inline, virtual] |
Implements Item.
Definition at line 530 of file item_strfunc.cc.
References String::alloc(), Item_func::arg_count, Item_func::args, bzero, current_thd, DBUG_ASSERT, DES_ede3_cbc_encrypt, DES_set_key_unchecked, ER, ER_FEATURE_DISABLED, ER_OUT_OF_RESOURCES, ER_WRONG_PARAMETERS_TO_PROCEDURE, error, EVP_BytesToKey, EVP_des_ede3_cbc, EVP_md5, FALSE, Item::fixed, int(), String::length(), NULL, Item::null_value, pthread_mutex_lock, pthread_mutex_unlock, String::ptr(), push_warning_printf(), SUPER_ACL, tmp_value, Item::val_str(), VOID, and MYSQL_ERROR::WARN_LEVEL_ERROR.
00531 { 00532 DBUG_ASSERT(fixed == 1); 00533 #ifdef HAVE_OPENSSL 00534 uint code= ER_WRONG_PARAMETERS_TO_PROCEDURE; 00535 DES_cblock ivec; 00536 struct st_des_keyblock keyblock; 00537 struct st_des_keyschedule keyschedule; 00538 String *res= args[0]->val_str(str); 00539 uint length,tail; 00540 00541 if ((null_value= args[0]->null_value)) 00542 return 0; 00543 length= res->length(); 00544 if (length < 9 || (length % 8) != 1 || !((*res)[0] & 128)) 00545 return res; // Skip decryption if not encrypted 00546 00547 if (arg_count == 1) // If automatic uncompression 00548 { 00549 uint key_number=(uint) (*res)[0] & 127; 00550 // Check if automatic key and that we have privilege to uncompress using it 00551 if (!(current_thd->security_ctx->master_access & SUPER_ACL) || 00552 key_number > 9) 00553 goto error; 00554 00555 VOID(pthread_mutex_lock(&LOCK_des_key_file)); 00556 keyschedule= des_keyschedule[key_number]; 00557 VOID(pthread_mutex_unlock(&LOCK_des_key_file)); 00558 } 00559 else 00560 { 00561 // We make good 24-byte (168 bit) key from given plaintext key with MD5 00562 String *keystr=args[1]->val_str(&tmp_value); 00563 if (!keystr) 00564 goto error; 00565 00566 bzero((char*) &ivec,sizeof(ivec)); 00567 EVP_BytesToKey(EVP_des_ede3_cbc(),EVP_md5(),NULL, 00568 (uchar*) keystr->ptr(),(int) keystr->length(), 00569 1,(uchar*) &keyblock,ivec); 00570 // Here we set all 64-bit keys (56 effective) one by one 00571 DES_set_key_unchecked(&keyblock.key1,&keyschedule.ks1); 00572 DES_set_key_unchecked(&keyblock.key2,&keyschedule.ks2); 00573 DES_set_key_unchecked(&keyblock.key3,&keyschedule.ks3); 00574 } 00575 code= ER_OUT_OF_RESOURCES; 00576 if (tmp_value.alloc(length-1)) 00577 goto error; 00578 00579 bzero((char*) &ivec,sizeof(ivec)); 00580 DES_ede3_cbc_encrypt((const uchar*) res->ptr()+1, 00581 (uchar*) (tmp_value.ptr()), 00582 length-1, 00583 &keyschedule.ks1, 00584 &keyschedule.ks2, 00585 &keyschedule.ks3, 00586 &ivec, FALSE); 00587 /* Restore old length of key */ 00588 if ((tail=(uint) (uchar) tmp_value[length-2]) > 8) 00589 goto wrong_key; // Wrong key 00590 tmp_value.length(length-1-tail); 00591 return &tmp_value; 00592 00593 error: 00594 push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_ERROR, 00595 code, ER(code), 00596 "des_decrypt"); 00597 wrong_key: 00598 #else 00599 push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_ERROR, 00600 ER_FEATURE_DISABLED, ER(ER_FEATURE_DISABLED), 00601 "des_decrypt","--with-openssl"); 00602 #endif /* HAVE_OPENSSL */ 00603 null_value=1; 00604 return 0; 00605 }
Here is the call graph for this function:

String Item_func_des_decrypt::tmp_value [private] |
1.4.7

