#include <my_global.h>#include <my_sys.h>#include <m_string.h>#include <sha1.h>#include "mysql.h"Include dependency graph for password.c:

Go to the source code of this file.
Defines | |
| #define | PVERSION41_CHAR '*' |
Functions | |
| void | randominit (struct rand_struct *rand_st, ulong seed1, ulong seed2) |
| double | my_rnd (struct rand_struct *rand_st) |
| void | hash_password (ulong *result, const char *password, uint password_len) |
| void | make_scrambled_password_323 (char *to, const char *password) |
| void | scramble_323 (char *to, const char *message, const char *password) |
| my_bool | check_scramble_323 (const char *scrambled, const char *message, ulong *hash_pass) |
| static uint8 | char_val (uint8 X) |
| void | get_salt_from_password_323 (ulong *res, const char *password) |
| void | make_password_from_salt_323 (char *to, const ulong *salt) |
| void | create_random_string (char *to, uint length, struct rand_struct *rand_st) |
| char * | octet2hex (char *to, const char *str, uint len) |
| static void | hex2octet (uint8 *to, const char *str, uint len) |
| static void | my_crypt (char *to, const uchar *s1, const uchar *s2, uint len) |
| void | make_scrambled_password (char *to, const char *password) |
| void | scramble (char *to, const char *message, const char *password) |
| my_bool | check_scramble (const char *scramble, const char *message, const uint8 *hash_stage2) |
| void | get_salt_from_password (uint8 *hash_stage2, const char *password) |
| void | make_password_from_salt (char *to, const uint8 *hash_stage2) |
| #define PVERSION41_CHAR '*' |
Definition at line 309 of file password.c.
Definition at line 234 of file password.c.
00235 { 00236 return (uint) (X >= '0' && X <= '9' ? X-'0' : 00237 X >= 'A' && X <= 'Z' ? X-'A'+10 : X-'a'+10); 00238 }
Definition at line 476 of file password.c.
References buf, memcmp(), my_crypt(), mysql_sha1_input(), mysql_sha1_reset(), mysql_sha1_result(), SCRAMBLE_LENGTH, and SHA1_HASH_SIZE.
00478 { 00479 SHA1_CONTEXT sha1_context; 00480 uint8 buf[SHA1_HASH_SIZE]; 00481 uint8 hash_stage2_reassured[SHA1_HASH_SIZE]; 00482 00483 mysql_sha1_reset(&sha1_context); 00484 /* create key to encrypt scramble */ 00485 mysql_sha1_input(&sha1_context, (const uint8 *) message, SCRAMBLE_LENGTH); 00486 mysql_sha1_input(&sha1_context, hash_stage2, SHA1_HASH_SIZE); 00487 mysql_sha1_result(&sha1_context, buf); 00488 /* encrypt scramble */ 00489 my_crypt((char *) buf, buf, (const uchar *) scramble, SCRAMBLE_LENGTH); 00490 /* now buf supposedly contains hash_stage1: so we can get hash_stage2 */ 00491 mysql_sha1_reset(&sha1_context); 00492 mysql_sha1_input(&sha1_context, buf, SHA1_HASH_SIZE); 00493 mysql_sha1_result(&sha1_context, hash_stage2_reassured); 00494 return memcmp(hash_stage2, hash_stage2_reassured, SHA1_HASH_SIZE); 00495 }
Here is the call graph for this function:

Definition at line 207 of file password.c.
References DBUG_ASSERT, hash_password(), my_rnd(), pos(), randominit(), SCRAMBLE_LENGTH_323, and to.
00209 { 00210 struct rand_struct rand_st; 00211 ulong hash_message[2]; 00212 char buff[16],*to,extra; /* Big enough for check */ 00213 const char *pos; 00214 00215 hash_password(hash_message, message, SCRAMBLE_LENGTH_323); 00216 randominit(&rand_st,hash_pass[0] ^ hash_message[0], 00217 hash_pass[1] ^ hash_message[1]); 00218 to=buff; 00219 DBUG_ASSERT(sizeof(buff) > SCRAMBLE_LENGTH_323); 00220 for (pos=scrambled ; *pos && to < buff+sizeof(buff) ; pos++) 00221 *to++=(char) (floor(my_rnd(&rand_st)*31)+64); 00222 if (pos-scrambled != SCRAMBLE_LENGTH_323) 00223 return 1; 00224 extra=(char) (floor(my_rnd(&rand_st)*31)); 00225 to=buff; 00226 while (*scrambled) 00227 { 00228 if (*scrambled++ != (char) (*to++ ^ extra)) 00229 return 1; /* Wrong password */ 00230 } 00231 return 0; 00232 }
Here is the call graph for this function:

| void create_random_string | ( | char * | to, | |
| uint | length, | |||
| struct rand_struct * | rand_st | |||
| ) |
Definition at line 297 of file password.c.
References my_rnd().
00298 { 00299 char *end= to + length; 00300 /* Use pointer arithmetics as it is faster way to do so. */ 00301 for (; to < end; to++) 00302 *to= (char) (my_rnd(rand_st)*94+33); 00303 *to= '\0'; 00304 }
Here is the call graph for this function:

| void get_salt_from_password | ( | uint8 * | hash_stage2, | |
| const char * | password | |||
| ) |
Definition at line 507 of file password.c.
References hex2octet(), and SHA1_HASH_SIZE.
00508 { 00509 hex2octet(hash_stage2, password+1 /* skip '*' */, SHA1_HASH_SIZE * 2); 00510 }
Here is the call graph for this function:

| void get_salt_from_password_323 | ( | ulong * | res, | |
| const char * | password | |||
| ) |
Definition at line 252 of file password.c.
References char_val.
00253 { 00254 res[0]= res[1]= 0; 00255 if (password) 00256 { 00257 while (*password) 00258 { 00259 ulong val=0; 00260 uint i; 00261 for (i=0 ; i < 8 ; i++) 00262 val=(val << 4)+char_val(*password++); 00263 *res++=val; 00264 } 00265 } 00266 }
Definition at line 118 of file password.c.
00119 { 00120 register ulong nr=1345345333L, add=7, nr2=0x12345671L; 00121 ulong tmp; 00122 const char *password_end= password + password_len; 00123 for (; password < password_end; password++) 00124 { 00125 if (*password == ' ' || *password == '\t') 00126 continue; /* skip space in password */ 00127 tmp= (ulong) (uchar) *password; 00128 nr^= (((nr & 63)+add)*tmp)+ (nr << 8); 00129 nr2+=(nr2 << 8) ^ nr; 00130 add+=tmp; 00131 } 00132 result[0]=nr & (((ulong) 1L << 31) -1L); /* Don't use sign bit (str2int) */; 00133 result[1]=nr2 & (((ulong) 1L << 31) -1L); 00134 }
| void make_password_from_salt | ( | char * | to, | |
| const uint8 * | hash_stage2 | |||
| ) |
Definition at line 520 of file password.c.
References octet2hex(), PVERSION41_CHAR, and SHA1_HASH_SIZE.
00521 { 00522 *to++= PVERSION41_CHAR; 00523 octet2hex(to, (const char*) hash_stage2, SHA1_HASH_SIZE); 00524 }
Here is the call graph for this function:

| void make_password_from_salt_323 | ( | char * | to, | |
| const ulong * | salt | |||
| ) |
Definition at line 277 of file password.c.
00278 { 00279 sprintf(to,"%08lx%08lx", salt[0], salt[1]); 00280 }
| void make_scrambled_password | ( | char * | to, | |
| const char * | password | |||
| ) |
Definition at line 393 of file password.c.
References mysql_sha1_input(), mysql_sha1_reset(), mysql_sha1_result(), octet2hex(), PVERSION41_CHAR, SHA1_HASH_SIZE, and strlen().
00394 { 00395 SHA1_CONTEXT sha1_context; 00396 uint8 hash_stage2[SHA1_HASH_SIZE]; 00397 00398 mysql_sha1_reset(&sha1_context); 00399 /* stage 1: hash password */ 00400 mysql_sha1_input(&sha1_context, (uint8 *) password, (uint) strlen(password)); 00401 mysql_sha1_result(&sha1_context, (uint8 *) to); 00402 /* stage 2: hash stage1 output */ 00403 mysql_sha1_reset(&sha1_context); 00404 mysql_sha1_input(&sha1_context, (uint8 *) to, SHA1_HASH_SIZE); 00405 /* separate buffer is used to pass 'to' in octet2hex */ 00406 mysql_sha1_result(&sha1_context, hash_stage2); 00407 /* convert hash_stage2 to hex string */ 00408 *to++= PVERSION41_CHAR; 00409 octet2hex(to, (const char*) hash_stage2, SHA1_HASH_SIZE); 00410 }
Here is the call graph for this function:

| void make_scrambled_password_323 | ( | char * | to, | |
| const char * | password | |||
| ) |
Definition at line 146 of file password.c.
References hash_password(), and strlen().
00147 { 00148 ulong hash_res[2]; 00149 hash_password(hash_res, password, (uint) strlen(password)); 00150 sprintf(to, "%08lx%08lx", hash_res[0], hash_res[1]); 00151 }
Here is the call graph for this function:

Definition at line 372 of file password.c.
00373 { 00374 const uint8 *s1_end= s1 + len; 00375 while (s1 < s1_end) 00376 *to++= *s1++ ^ *s2++; 00377 }
| double my_rnd | ( | struct rand_struct * | rand_st | ) |
Definition at line 100 of file password.c.
References rand_struct::max_value, rand_struct::max_value_dbl, rand_struct::seed1, and rand_struct::seed2.
00101 { 00102 rand_st->seed1=(rand_st->seed1*3+rand_st->seed2) % rand_st->max_value; 00103 rand_st->seed2=(rand_st->seed1+rand_st->seed2+33) % rand_st->max_value; 00104 return (((double) rand_st->seed1)/rand_st->max_value_dbl); 00105 }
| char* octet2hex | ( | char * | to, | |
| const char * | str, | |||
| uint | len | |||
| ) |
Definition at line 324 of file password.c.
References _dig_vec_upper.
00325 { 00326 const char *str_end= str + len; 00327 for (; str != str_end; ++str) 00328 { 00329 *to++= _dig_vec_upper[((uchar) *str) >> 4]; 00330 *to++= _dig_vec_upper[((uchar) *str) & 0x0F]; 00331 } 00332 *to= '\0'; 00333 return to; 00334 }
| void randominit | ( | struct rand_struct * | rand_st, | |
| ulong | seed1, | |||
| ulong | seed2 | |||
| ) |
Definition at line 79 of file password.c.
References bzero.
00080 { /* For mysql 3.21.# */ 00081 #ifdef HAVE_purify 00082 bzero((char*) rand_st,sizeof(*rand_st)); /* Avoid UMC varnings */ 00083 #endif 00084 rand_st->max_value= 0x3FFFFFFFL; 00085 rand_st->max_value_dbl=(double) rand_st->max_value; 00086 rand_st->seed1=seed1%rand_st->max_value ; 00087 rand_st->seed2=seed2%rand_st->max_value; 00088 }
| void scramble | ( | char * | to, | |
| const char * | message, | |||
| const char * | password | |||
| ) |
Definition at line 431 of file password.c.
References my_crypt(), mysql_sha1_input(), mysql_sha1_reset(), mysql_sha1_result(), SCRAMBLE_LENGTH, SHA1_HASH_SIZE, and strlen().
00432 { 00433 SHA1_CONTEXT sha1_context; 00434 uint8 hash_stage1[SHA1_HASH_SIZE]; 00435 uint8 hash_stage2[SHA1_HASH_SIZE]; 00436 00437 mysql_sha1_reset(&sha1_context); 00438 /* stage 1: hash password */ 00439 mysql_sha1_input(&sha1_context, (uint8 *) password, (uint) strlen(password)); 00440 mysql_sha1_result(&sha1_context, hash_stage1); 00441 /* stage 2: hash stage 1; note that hash_stage2 is stored in the database */ 00442 mysql_sha1_reset(&sha1_context); 00443 mysql_sha1_input(&sha1_context, hash_stage1, SHA1_HASH_SIZE); 00444 mysql_sha1_result(&sha1_context, hash_stage2); 00445 /* create crypt string as sha1(message, hash_stage2) */; 00446 mysql_sha1_reset(&sha1_context); 00447 mysql_sha1_input(&sha1_context, (const uint8 *) message, SCRAMBLE_LENGTH); 00448 mysql_sha1_input(&sha1_context, hash_stage2, SHA1_HASH_SIZE); 00449 /* xor allows 'from' and 'to' overlap: lets take advantage of it */ 00450 mysql_sha1_result(&sha1_context, (uint8 *) to); 00451 my_crypt(to, (const uchar *) to, hash_stage1, SCRAMBLE_LENGTH); 00452 }
Here is the call graph for this function:

| void scramble_323 | ( | char * | to, | |
| const char * | message, | |||
| const char * | password | |||
| ) |
Definition at line 166 of file password.c.
References hash_password(), my_rnd(), randominit(), SCRAMBLE_LENGTH_323, and strlen().
00167 { 00168 struct rand_struct rand_st; 00169 ulong hash_pass[2], hash_message[2]; 00170 00171 if (password && password[0]) 00172 { 00173 char extra, *to_start=to; 00174 const char *message_end= message + SCRAMBLE_LENGTH_323; 00175 hash_password(hash_pass,password, (uint) strlen(password)); 00176 hash_password(hash_message, message, SCRAMBLE_LENGTH_323); 00177 randominit(&rand_st,hash_pass[0] ^ hash_message[0], 00178 hash_pass[1] ^ hash_message[1]); 00179 for (; message < message_end; message++) 00180 *to++= (char) (floor(my_rnd(&rand_st)*31)+64); 00181 extra=(char) (floor(my_rnd(&rand_st)*31)); 00182 while (to_start != to) 00183 *(to_start++)^=extra; 00184 } 00185 *to= 0; 00186 }
Here is the call graph for this function:

1.4.7
