Skip to content

Commit

Permalink
partially working scramble323 - the hashes and randominit work. slow …
Browse files Browse the repository at this point in the history
…progress
  • Loading branch information
iamcal authored and felixge committed Sep 2, 2010
1 parent 0ee929b commit f920b2b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
32 changes: 31 additions & 1 deletion lib/mysql/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ exports.hashPassword = function(password) {
var nr2 = [0x1234, 0x5671];
var result = new Buffer(8);

password = new Buffer(password);
if (typeof password == 'string'){
password = new Buffer(password);
}

for (var i = 0; i < password.length; i++) {
var c = password[i];
if (c == 32 || c == 9) {
Expand Down Expand Up @@ -85,6 +88,26 @@ exports.myRnd = function(r){
};

exports.scramble323 = function(message, password) {

if (!password) return new Buffer();
var to = new Buffer(8);

var hash_pass = this.hashPassword(password);
var hash_message = this.hashPassword(message.slice(0, 8));
console.log(hash_pass);
console.log(hash_message);

var seed1 = this.int32Read(hash_pass, 0) ^ this.int32Read(hash_message, 0);
var seed2 = this.int32Read(hash_pass, 4) ^ this.int32Read(hash_message, 4);
var r = this.randomInit(seed1, seed2);

console.log(r);

for (var i=0; i<8; i++){
to[i] = Math.floor(this.myRnd(r)*31) + 64;
}

return to;
};

exports.fmt32 = function(x){
Expand Down Expand Up @@ -146,3 +169,10 @@ exports.int31Write = function(buffer, number, offset) {
buffer[offset+2] = (number[1] >> 8) & 0xFF;
buffer[offset+3] = (number[1]) & 0xFF;
};

exports.int32Read = function(buffer, offset){
return (buffer[offset] << 24)
+ (buffer[offset+1] << 16)
+ (buffer[offset+2] << 8)
+ (buffer[offset+3]);
};
14 changes: 14 additions & 0 deletions test/fixture/libmysql_password.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@ void scramble_323(char *to, const char *message, const char *password)
const char *message_end= message + SCRAMBLE_LENGTH_323;
hash_password(hash_pass,password, (uint) strlen(password));
hash_password(hash_message, message, SCRAMBLE_LENGTH_323);

printf("hash_pass = %08x%08x\n", hash_pass[0], hash_pass[1]);
printf("hash_message = %08x%08x\n", hash_message[0], hash_message[1]);

randominit(&rand_st,hash_pass[0] ^ hash_message[0],
hash_pass[1] ^ hash_message[1]);

printf("rs.seed1: %d\n", rand_st.seed1);
printf("rs.seed2: %d\n", rand_st.seed2);

for (; message < message_end; message++)
*to++= (char) (floor(my_rnd(&rand_st)*31)+64);
extra=(char) (floor(my_rnd(&rand_st)*31));
Expand All @@ -76,6 +84,7 @@ int main() {
const char password2[] = "long password test";
const char password3[] = "saf789yasfbsd89f";
ulong result[2];
char scrm[9]; // SCRAMBLE_LENGTH_323+1
struct rand_struct rand_st;
int i;

Expand Down Expand Up @@ -111,6 +120,11 @@ int main() {
printf("my_rnd() : %.16f\n", my_rnd(&rand_st));
}


// test scramble_323
scramble_323(scrm, "8bytesofstuff", "root");
printf("scramble: %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", scrm[0], scrm[1], scrm[2], scrm[3], scrm[4], scrm[5], scrm[6], scrm[7], scrm[8]);

return 23;
}

5 changes: 4 additions & 1 deletion test/simple/test-auth-old.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ test_myrnd_sequence(3252345, 7149734, [
0.2488940062456708,
0.2570431151027261,
0.5385335875102631,
0.9215386229767824,
0.9215386229767824,
]);


var b = auth.scramble323(new Buffer("8bytesofstuff"), "root");
console.log(b);

0 comments on commit f920b2b

Please sign in to comment.