Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
b147f169
Commit
b147f169
authored
Nov 06, 2001
by
tonu@volk.internalnet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
des_encrypt(), des_decrypt() functions added. Not finally ready yet, so I will clean it up later.
parent
eac7e9f2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
154 additions
and
1 deletion
+154
-1
sql/item_strfunc.cc
sql/item_strfunc.cc
+132
-1
sql/item_strfunc.h
sql/item_strfunc.h
+20
-0
sql/lex.h
sql/lex.h
+2
-0
No files found.
sql/item_strfunc.cc
View file @
b147f169
...
...
@@ -30,6 +30,9 @@
#ifdef HAVE_CRYPT_H
#include <crypt.h>
#endif
#ifdef HAVE_OPENSSL
#include <openssl/des.h>
#endif
/* HAVE_OPENSSL */
#include "md5.h"
String
empty_string
(
""
);
...
...
@@ -198,6 +201,135 @@ void Item_func_concat::fix_length_and_dec()
}
}
#define bin_to_ascii(c) ((c)>=38?((c)-38+'a'):(c)>=12?((c)-12+'A'):(c)+'.')
String
*
Item_func_des_encrypt
::
val_str
(
String
*
str
)
{
String
*
res
=
args
[
0
]
->
val_str
(
str
);
#ifdef HAVE_OPENSSL
des_key_schedule
ks1
,
ks2
,
ks3
;
des_cblock
ivec
=
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
};
union
{
des_cblock
allkeys
[
3
];
des_cblock
key1
;
des_cblock
key2
;
des_cblock
key3
;
}
key
;
if
((
null_value
=
args
[
0
]
->
null_value
))
return
0
;
if
(
res
->
length
()
==
0
)
return
&
empty_string
;
String
*
in_str
=
args
[
1
]
->
val_str
(
&
tmp_value
);
char
*
tmp
=
my_malloc
(
res
->
length
()
+
8
,
MYF
(
0
));
DBUG_PRINT
(
"info"
,(
"DES: key string='%s'"
,
in_str
->
c_ptr
()));
DBUG_PRINT
(
"info"
,(
"DES: data string='%s'"
,
res
->
c_ptr
()));
DBUG_PRINT
(
"info"
,(
"DES: cipher pointer='%x'"
,
EVP_get_cipherbyname
(
"DES-EDE3-CBC"
)));
EVP_BytesToKey
(
EVP_get_cipherbyname
(
"DES-EDE3-CBC"
),
EVP_md5
(),
NULL
,
(
unsigned
char
*
)
in_str
->
c_ptr
(),
in_str
->
length
(),
1
,(
uchar
*
)
&
key
.
allkeys
,
ivec
);
des_set_key_unchecked
(
&
key
.
key1
,
ks1
);
des_set_key_unchecked
(
&
key
.
key2
,
ks2
);
des_set_key_unchecked
(
&
key
.
key3
,
ks3
);
DBUG_PRINT
(
"info"
,(
"DES: checkpoint"
));
des_ede3_cbc_encrypt
(
(
const
unsigned
char
*
)(
res
->
c_ptr
())
,
(
uchar
*
)
tmp
,
res
->
length
(),
ks1
,
ks2
,
ks3
,
&
ivec
,
TRUE
);
res
->
length
(
res
->
length
()
+
8
-
(
res
->
length
()
%
8
));
DBUG_PRINT
(
"info"
,(
"DES: checkpoint"
));
DBUG_PRINT
(
"info"
,(
"DES: string length='%d' versus '%d'"
,
res
->
length
(),
strlen
(
res
->
c_ptr
())));
DBUG_PRINT
(
"info"
,(
"DES: crypted data string='%s'"
,
tmp
));
str
->
set
((
const
char
*
)
0
,(
uint
)
0
);
for
(
uint
i
=
0
;
i
<
res
->
length
()
;
++
i
)
{
str
->
append
(
tmp
[
i
]);
// str->append(bin_to_ascii(tmp[i] & 0x3f));
// str->append(bin_to_ascii((tmp[i] >> 5) & 0x3f));
}
DBUG_PRINT
(
"info"
,(
"DES: crypted data plain string='%s'"
,
str
->
c_ptr
()));
str
->
copy
();
DBUG_PRINT
(
"info"
,(
"DES: crypted data plain string='%s'"
,
str
->
c_ptr
()));
my_free
(
tmp
,
MYF
(
0
));
return
str
;
#else
null_value
=
1
;
return
0
;
#endif
/* HAVE_OPENSSL */
}
String
*
Item_func_des_decrypt
::
val_str
(
String
*
str
)
{
String
*
res
=
args
[
0
]
->
val_str
(
str
);
#ifdef HAVE_OPENSSL
des_key_schedule
ks1
,
ks2
,
ks3
;
des_cblock
ivec
=
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
};
union
{
des_cblock
allkeys
[
3
];
des_cblock
key1
;
des_cblock
key2
;
des_cblock
key3
;
}
key
;
if
((
null_value
=
args
[
0
]
->
null_value
))
return
0
;
if
(
res
->
length
()
==
0
)
return
&
empty_string
;
String
*
in_str
=
args
[
1
]
->
val_str
(
&
tmp_value
);
char
*
tmp
=
my_malloc
(
res
->
length
()
+
8
,
MYF
(
0
));
DBUG_PRINT
(
"info"
,(
"DES: key string='%s'"
,
in_str
->
c_ptr
()));
DBUG_PRINT
(
"info"
,(
"DES: data string='%s'"
,
res
->
c_ptr
()));
/* int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md,
const unsigned char *salt, const unsigned char *data, int datal,
int count, unsigned char *key, unsigned char *iv)
*/
EVP_BytesToKey
(
EVP_get_cipherbyname
(
"DES-EDE3-CBC"
),
EVP_md5
(),
NULL
,
(
unsigned
char
*
)
in_str
->
c_ptr
(),
in_str
->
length
(),
1
,(
uchar
*
)
&
key
.
allkeys
,
ivec
);
des_set_key_unchecked
(
&
key
.
key1
,
ks1
);
des_set_key_unchecked
(
&
key
.
key2
,
ks2
);
des_set_key_unchecked
(
&
key
.
key3
,
ks3
);
DBUG_PRINT
(
"info"
,(
"DES: cipher pointer='%x'"
,
EVP_get_cipherbyname
(
"DES-EDE3-CBC"
)));
EVP_BytesToKey
(
EVP_get_cipherbyname
(
"DES-EDE3-CBC"
),
EVP_md5
(),
NULL
,
(
unsigned
char
*
)
in_str
->
c_ptr
(),
in_str
->
length
(),
1
,(
uchar
*
)
&
key
.
allkeys
,
ivec
);
DBUG_PRINT
(
"info"
,(
"DES: checkpoint"
));
des_ede3_cbc_encrypt
(
(
const
unsigned
char
*
)(
res
->
c_ptr
())
,
(
uchar
*
)
tmp
,
res
->
length
(),
ks1
,
ks2
,
ks3
,
&
ivec
,
FALSE
);
DBUG_PRINT
(
"info"
,(
"DES: checkpoint"
));
DBUG_PRINT
(
"info"
,(
"DES: string length='%d' versus '%d'"
,
res
->
length
(),
strlen
(
res
->
c_ptr
())));
DBUG_PRINT
(
"info"
,(
"DES: crypted data string='%s'"
,
tmp
));
str
->
set
((
const
char
*
)
0
,(
uint
)
0
);
for
(
uint
i
=
0
;
i
<
res
->
length
()
;
++
i
)
{
str
->
append
(
tmp
[
i
]);
// str->append(bin_to_ascii(tmp[i] & 0x3f));
// str->append(bin_to_ascii((tmp[i] >> 5) & 0x3f));
}
DBUG_PRINT
(
"info"
,(
"DES: crypted data plain string='%s'"
,
str
->
c_ptr
()));
str
->
copy
();
DBUG_PRINT
(
"info"
,(
"DES: crypted data plain string='%s'"
,
str
->
c_ptr
()));
my_free
(
tmp
,
MYF
(
0
));
return
str
;
#else
null_value
=
1
;
return
0
;
#endif
/* HAVE_OPENSSL */
}
/*
...
...
@@ -992,7 +1124,6 @@ String *Item_func_password::val_str(String *str)
return
str
;
}
#define bin_to_ascii(c) ((c)>=38?((c)-38+'a'):(c)>=12?((c)-12+'A'):(c)+'.')
String
*
Item_func_encrypt
::
val_str
(
String
*
str
)
{
...
...
sql/item_strfunc.h
View file @
b147f169
...
...
@@ -222,6 +222,26 @@ public:
const
char
*
func_name
()
const
{
return
"password"
;
}
};
class
Item_func_des_encrypt
:
public
Item_str_func
{
String
tmp_value
;
public:
Item_func_des_encrypt
(
Item
*
a
)
:
Item_str_func
(
a
)
{}
Item_func_des_encrypt
(
Item
*
a
,
Item
*
b
)
:
Item_str_func
(
a
,
b
)
{}
String
*
val_str
(
String
*
);
void
fix_length_and_dec
()
{
maybe_null
=
1
;
max_length
=
13
;
}
};
class
Item_func_des_decrypt
:
public
Item_str_func
{
String
tmp_value
;
public:
Item_func_des_decrypt
(
Item
*
a
)
:
Item_str_func
(
a
)
{}
Item_func_des_decrypt
(
Item
*
a
,
Item
*
b
)
:
Item_str_func
(
a
,
b
)
{}
String
*
val_str
(
String
*
);
void
fix_length_and_dec
()
{
maybe_null
=
1
;
max_length
=
13
;
}
};
class
Item_func_encrypt
:
public
Item_str_func
{
String
tmp_value
;
...
...
sql/lex.h
View file @
b147f169
...
...
@@ -405,6 +405,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
},
{
"ELT"
,
SYM
(
ELT_FUNC
),
0
,
0
},
{
"ENCODE"
,
SYM
(
ENCODE_SYM
),
0
,
0
},
{
"ENCRYPT"
,
SYM
(
ENCRYPT
),
0
,
0
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment