-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial work on porting mysql < 4.1 authentication code
- Loading branch information
Showing
7 changed files
with
278 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <math.h> | ||
|
||
#define SCRAMBLE_LENGTH_323 8 | ||
|
||
typedef unsigned long ulong; | ||
typedef unsigned int uint; | ||
typedef unsigned char uchar; | ||
|
||
struct rand_struct { | ||
unsigned long seed1,seed2,max_value; | ||
double max_value_dbl; | ||
}; | ||
|
||
void hash_password(ulong *result, const char *password, uint password_len) | ||
{ | ||
register ulong nr=1345345333L, add=7, nr2=0x12345671L; | ||
ulong tmp; | ||
const char *password_end= password + password_len; | ||
for (; password < password_end; password++) | ||
{ | ||
if (*password == ' ' || *password == '\t') | ||
continue; /* skip space in password */ | ||
tmp= (ulong) (uchar) *password; | ||
nr^= (((nr & 63)+add)*tmp)+ (nr << 8); | ||
nr2+=(nr2 << 8) ^ nr; | ||
add+=tmp; | ||
} | ||
result[0]=nr & (((ulong) 1L << 31) -1L); /* Don't use sign bit (str2int) */; | ||
result[1]=nr2 & (((ulong) 1L << 31) -1L); | ||
} | ||
|
||
void randominit(struct rand_struct *rand_st, ulong seed1, ulong seed2) | ||
{ /* For mysql 3.21.# */ | ||
#ifdef HAVE_purify | ||
bzero((char*) rand_st,sizeof(*rand_st)); /* Avoid UMC varnings */ | ||
#endif | ||
rand_st->max_value= 0x3FFFFFFFL; | ||
rand_st->max_value_dbl=(double) rand_st->max_value; | ||
rand_st->seed1=seed1%rand_st->max_value ; | ||
rand_st->seed2=seed2%rand_st->max_value; | ||
} | ||
|
||
double my_rnd(struct rand_struct *rand_st) | ||
{ | ||
rand_st->seed1=(rand_st->seed1*3+rand_st->seed2) % rand_st->max_value; | ||
rand_st->seed2=(rand_st->seed1+rand_st->seed2+33) % rand_st->max_value; | ||
return (((double) rand_st->seed1)/rand_st->max_value_dbl); | ||
} | ||
|
||
void scramble_323(char *to, const char *message, const char *password) | ||
{ | ||
struct rand_struct rand_st; | ||
ulong hash_pass[2], hash_message[2]; | ||
|
||
if (password && password[0]) | ||
{ | ||
char extra, *to_start=to; | ||
const char *message_end= message + SCRAMBLE_LENGTH_323; | ||
hash_password(hash_pass,password, (uint) strlen(password)); | ||
hash_password(hash_message, message, SCRAMBLE_LENGTH_323); | ||
randominit(&rand_st,hash_pass[0] ^ hash_message[0], | ||
hash_pass[1] ^ hash_message[1]); | ||
for (; message < message_end; message++) | ||
*to++= (char) (floor(my_rnd(&rand_st)*31)+64); | ||
extra=(char) (floor(my_rnd(&rand_st)*31)); | ||
while (to_start != to) | ||
*(to_start++)^=extra; | ||
} | ||
*to= 0; | ||
} | ||
|
||
int main() { | ||
const char password[] = "root"; | ||
uint password_len = 4; | ||
ulong result[2]; | ||
|
||
printf("hash_password(\"%s\"):\n", password); | ||
|
||
hash_password(result, password, password_len); | ||
|
||
printf("result 1: %ld\n", result[0]); | ||
printf("result 2: %ld\n", result[1]); | ||
|
||
return 23; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters