| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| |
| 6 |
|
| |
| 7 |
|
| #include <sys/types.h> |
| 8 |
|
| |
| 9 |
|
| typedef unsigned long ulong; |
| 10 |
|
| typedef unsigned char uchar; |
| 11 |
|
| |
| 12 |
2 |
| void __crypt_mysql_hash_password(ulong *result, |
| 13 |
|
| const char *password, size_t password_len) |
| 14 |
|
| { |
| 15 |
2 |
| const char *password_end = password + password_len; |
| 16 |
2 |
| register ulong nr=1345345333L, add=7, nr2=0x12345671L; |
| 17 |
|
| ulong tmp; |
| 18 |
14 |
▶ | for (; password != password_end ; password++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (; password != password_end ; password++) |
12 |
2 |
14 |
|
| 19 |
|
| { |
| 20 |
12 |
▶ | if (*password == ' ' || *password == '\t') |
Branch: 2 branches
| Branch | True | False | Total |
| if (*password == ' ' || *password == '\t') |
12 |
0 |
12 |
| if (*password == ' ' || *password == '\t') |
0 |
12 |
12 |
|
| 21 |
0 |
| continue; /* skipp space in password */ |
| 22 |
12 |
| tmp= (ulong) (uchar) *password; |
| 23 |
12 |
| nr^= (((nr & 63)+add)*tmp)+ (nr << 8); |
| 24 |
12 |
| nr2+=(nr2 << 8) ^ nr; |
| 25 |
12 |
| add+=tmp; |
| 26 |
|
| } |
| 27 |
2 |
| result[0]=nr & (((ulong) 1L << 31) -1L); /* Don't use sign bit (str2int) */; |
| 28 |
2 |
| result[1]=nr2 & (((ulong) 1L << 31) -1L); |
| 29 |
2 |
| return; |
| 30 |
|
| } |
| 31 |
|
| |
| 32 |
2 |
| void __crypt_mysql_make_scrambled_password(char *to, |
| 33 |
|
| const char *password, size_t password_len) |
| 34 |
|
| { |
| 35 |
|
| ulong hash_res[2]; |
| 36 |
2 |
| __crypt_mysql_hash_password(hash_res,password,password_len); |
| 37 |
2 |
| sprintf(to,"%08lx%08lx",hash_res[0],hash_res[1]); |
| 38 |
2 |
| } |
| 39 |
|
| |
| 40 |
|
| MODULE = Crypt::MySQL PACKAGE = Crypt::MySQL |
| 41 |
|
| |
| 42 |
|
| SV * |
| 43 |
|
| password(str) |
| 44 |
|
| SV *str; |
| 45 |
|
| CODE: |
| 46 |
|
| { |
| 47 |
|
| char to[17]; |
| 48 |
|
| STRLEN size; |
| 49 |
2 |
| char *src = SvPV(str, size); |
| 50 |
2 |
| __crypt_mysql_make_scrambled_password(to, src, size); |
| 51 |
2 |
| RETVAL = newSVpv(to, 0); |
| 52 |
|
| } |
| 53 |
|
| OUTPUT: |
| 54 |
|
| RETVAL |
| 55 |
|
| |
| 56 |
|
| |