114
114
password_len IN password length (password may be not null-terminated)
117
void hash_password(ulong *result, const char *password, uint password_len)
117
void hash_password(uint32_t *result, const char *password, uint32_t password_len)
119
119
register ulong nr=1345345333L, add=7, nr2=0x12345671L;
121
121
const char *password_end= password + password_len;
122
122
for (; password < password_end; password++)
124
124
if (*password == ' ' || *password == '\t')
125
125
continue; /* skip space in password */
126
tmp= (ulong) (uchar) *password;
126
tmp= (uint32_t) (uchar) *password;
127
127
nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
128
128
nr2+=(nr2 << 8) ^ nr;
131
result[0]=nr & (((ulong) 1L << 31) -1L); /* Don't use sign bit (str2int) */;
132
result[1]=nr2 & (((ulong) 1L << 31) -1L);
137
Create password to be stored in user database from raw string
138
Used for pre-4.1 password handling
140
make_scrambled_password_323()
141
to OUT store scrambled password here
142
password IN user-supplied password
145
void make_scrambled_password_323(char *to, const char *password)
148
hash_password(hash_res, password, (uint) strlen(password));
149
sprintf(to, "%08lx%08lx", hash_res[0], hash_res[1]);
154
Scramble string with password.
155
Used in pre 4.1 authentication phase.
158
to OUT Store scrambled message here. Buffer must be at least
159
SCRAMBLE_LENGTH_323+1 bytes long
160
message IN Message to scramble. Message must be at least
161
SRAMBLE_LENGTH_323 bytes long.
162
password IN Password to use while scrambling
165
void scramble_323(char *to, const char *message, const char *password)
167
struct rand_struct rand_st;
168
ulong hash_pass[2], hash_message[2];
170
if (password && password[0])
172
char extra, *to_start=to;
173
const char *message_end= message + SCRAMBLE_LENGTH_323;
174
hash_password(hash_pass,password, (uint) strlen(password));
175
hash_password(hash_message, message, SCRAMBLE_LENGTH_323);
176
randominit(&rand_st,hash_pass[0] ^ hash_message[0],
177
hash_pass[1] ^ hash_message[1]);
178
for (; message < message_end; message++)
179
*to++= (char) (floor(my_rnd(&rand_st)*31)+64);
180
extra=(char) (floor(my_rnd(&rand_st)*31));
181
while (to_start != to)
182
*(to_start++)^=extra;
189
Check scrambled message
190
Used in pre 4.1 password handling
193
scrambled scrambled message to check.
194
message original random message which was used for scrambling; must
195
be exactly SCRAMBLED_LENGTH_323 bytes long and
197
hash_pass password which should be used for scrambling
202
!0 - password invalid
206
check_scramble_323(const char *scrambled, const char *message,
209
struct rand_struct rand_st;
210
ulong hash_message[2];
211
char buff[16],*to,extra; /* Big enough for check */
214
hash_password(hash_message, message, SCRAMBLE_LENGTH_323);
215
randominit(&rand_st,hash_pass[0] ^ hash_message[0],
216
hash_pass[1] ^ hash_message[1]);
218
DBUG_ASSERT(sizeof(buff) > SCRAMBLE_LENGTH_323);
219
for (pos=scrambled ; *pos && to < buff+sizeof(buff) ; pos++)
220
*to++=(char) (floor(my_rnd(&rand_st)*31)+64);
221
if (pos-scrambled != SCRAMBLE_LENGTH_323)
223
extra=(char) (floor(my_rnd(&rand_st)*31));
227
if (*scrambled++ != (char) (*to++ ^ extra))
228
return 1; /* Wrong password */
131
result[0]=nr & (((uint32_t) 1L << 31) -1L); /* Don't use sign bit (str2int) */;
132
result[1]=nr2 & (((uint32_t) 1L << 31) -1L);
233
135
static inline uint8 char_val(uint8 X)
241
Convert password from hex string (as stored in mysql.user) to binary form.
243
get_salt_from_password_323()
244
res OUT store salt here
245
password IN password string as stored in mysql.user
247
This function does not have length check for passwords. It will just crash
248
Password hashes in old format must have length divisible by 8
251
void get_salt_from_password_323(ulong *res, const char *password)
260
for (i=0 ; i < 8 ; i++)
261
val=(val << 4)+char_val(*password++);
269
Convert scrambled password from binary form to asciiz hex string.
271
make_password_from_salt_323()
272
to OUT store resulting string password here, at least 17 bytes
273
salt IN password in salt format, 2 ulongs
276
void make_password_from_salt_323(char *to, const ulong *salt)
278
sprintf(to,"%08lx%08lx", salt[0], salt[1]);
283
143
**************** MySQL 4.1.1 authentication routines *************