Permalink
Browse files

A few more style changes

  • Loading branch information...
1 parent a303d9b commit ee8ce2ed4d1180d38735d0e8a9dafb4a6dd53b14 @felixge felixge committed Sep 2, 2010
Showing with 33 additions and 48 deletions.
  1. +33 −48 lib/mysql/auth.js
View
81 lib/mysql/auth.js
@@ -34,11 +34,10 @@ exports.token = function(password, scramble) {
// This is a port of sql/password.c:hash_password which needs to be used for
// pre-4.1 passwords.
exports.hashPassword = function(password) {
-
- var nr = [0x5030, 0x5735];
- var add = 7;
- var nr2 = [0x1234, 0x5671];
- var result = new Buffer(8);
+ var nr = [0x5030, 0x5735],
+ add = 7,
+ nr2 = [0x1234, 0x5671],
+ result = new Buffer(8);
if (typeof password == 'string'){
password = new Buffer(password);
@@ -70,50 +69,44 @@ exports.hashPassword = function(password) {
};
exports.randomInit = function(seed1, seed2) {
-
return {
- max_value : 0x3FFFFFFF,
- max_value_dbl : 0x3FFFFFFF,
- seed1 : seed1 % 0x3FFFFFFF,
- seed2 : seed2 % 0x3FFFFFFF,
+ max_value: 0x3FFFFFFF,
+ max_value_dbl: 0x3FFFFFFF,
+ seed1: seed1 % 0x3FFFFFFF,
+ seed2: seed2 % 0x3FFFFFFF,
};
};
exports.myRnd = function(r){
-
r.seed1 = (r.seed1 * 3 + r.seed2) % r.max_value;
r.seed2 = (r.seed1 + r.seed2 + 33) % r.max_value;
return r.seed1 / r.max_value_dbl;
};
exports.scramble323 = function(message, password) {
-
- if (!password) return new Buffer(); // @todo, this fails, needs fixing
- var to = new Buffer(8);
-
- var hash_pass = this.hashPassword(password);
- var hash_message = this.hashPassword(message.slice(0, 8));
-
- 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);
-
- for (var i=0; i<8; i++){
- to[i] = Math.floor(this.myRnd(r)*31) + 64;
+ var to = new Buffer(8),
+ hashPass = this.hashPassword(password),
+ hashMessage = this.hashPassword(message.slice(0, 8)),
+ seed1 = this.int32Read(hashPass, 0) ^ this.int32Read(hashMessage, 0),
+ seed2 = this.int32Read(hashPass, 4) ^ this.int32Read(hashMessage, 4),
+ r = this.randomInit(seed1, seed2);
+
+ for (var i = 0; i < 8; i++){
+ to[i] = Math.floor(this.myRnd(r) * 31) + 64;
}
- var extra = (Math.floor(this.myRnd(r)*31));
+ var extra = (Math.floor(this.myRnd(r) * 31));
- for (var i=0; i<8; i++){
+ for (var i = 0; i < 8; i++){
to[i] ^= extra;
}
return to;
};
exports.fmt32 = function(x){
- var a = x[0].toString(16);
- var b = x[1].toString(16);
+ var a = x[0].toString(16),
+ b = x[1].toString(16);
if (a.length == 1) a = '000'+a;
if (a.length == 2) a = '00'+a;
@@ -129,16 +122,18 @@ exports.xor32 = function(a,b){
}
exports.add32 = function(a,b){
- var w1 = a[1] + b[1];
- var w2 = a[0] + b[0] + ((w1 & 0xFFFF0000) >> 16);
+ var w1 = a[1] + b[1],
+ w2 = a[0] + b[0] + ((w1 & 0xFFFF0000) >> 16);
+
return [w2 & 0xFFFF, w1 & 0xFFFF];
}
exports.mul32 = function(a,b){
// based on this example of multiplying 32b ints using 16b
// http://www.dsprelated.com/showmessage/89790/1.php
- var w1 = a[1] * b[1];
- var w2 = (((a[1] * b[1]) >> 16) & 0xFFFF) + ((a[0] * b[1]) & 0xFFFF) + (a[1] * b[0] & 0xFFFF);
+ var w1 = a[1] * b[1],
+ w2 = (((a[1] * b[1]) >> 16) & 0xFFFF) + ((a[0] * b[1]) & 0xFFFF) + (a[1] * b[0] & 0xFFFF);
+
return [w2 & 0xFFFF, w1 & 0xFFFF];
}
@@ -148,27 +143,17 @@ exports.and32 = function(a,b){
exports.shl32 = function(a,b){
// assume b is 16 or less
- var w1 = a[1] << b;
- var w2 = (a[0] << b) | ((w1 & 0xFFFF0000) >> 16);
+ var w1 = a[1] << b,
+ w2 = (a[0] << b) | ((w1 & 0xFFFF0000) >> 16);
+
return [w2 & 0xFFFF, w1 & 0xFFFF];
}
-exports.int32Write = function(buffer, number, offset) {
- var unsigned = (number < 0) ? (number + 0x100000000) : number;
- buffer[offset] = Math.floor(unsigned / 0xffffff);
- unsigned &= 0xffffff;
- buffer[offset + 1] = Math.floor(unsigned / 0xffff);
- unsigned &= 0xffff;
- buffer[offset + 2] = Math.floor(unsigned / 0xff);
- unsigned &= 0xff;
- buffer[offset + 3] = Math.floor(unsigned);
-};
-
exports.int31Write = function(buffer, number, offset) {
buffer[offset] = (number[0] >> 8) & 0x7F;
- buffer[offset+1] = (number[0]) & 0xFF;
- buffer[offset+2] = (number[1] >> 8) & 0xFF;
- buffer[offset+3] = (number[1]) & 0xFF;
+ buffer[offset + 1] = (number[0]) & 0xFF;
+ buffer[offset + 2] = (number[1] >> 8) & 0xFF;
+ buffer[offset + 3] = (number[1]) & 0xFF;
};
exports.int32Read = function(buffer, offset){

0 comments on commit ee8ce2e

Please sign in to comment.