@@ -35,12 +35,11 @@ #define HMAC_IPAD 0x36 #define HMAC_OPAD 0x5c @interface XMPPSCRAMAuth () - (OFString *)xmpp_genNonce; -- (const uint8_t *)xmpp_HMACWithKey: (OFData *)key - data: (OFData *)data; +- (const uint8_t *)xmpp_HMACWithKey: (OFData *)key data: (OFData *)data; - (OFData *)xmpp_hiWithData: (OFData *)str salt: (OFData *)salt iterationCount: (intmax_t)i; - (OFData *)xmpp_parseServerFirstMessage: (OFData *)data; - (OFData *)xmpp_parseServerFinalMessage: (OFData *)data; @@ -135,14 +134,12 @@ { OFString *old = _authzid; if (authzid) { OFMutableString *new = [[authzid mutableCopy] autorelease]; - [new replaceOccurrencesOfString: @"=" - withString: @"=3D"]; - [new replaceOccurrencesOfString: @"," - withString: @"=2C"]; + [new replaceOccurrencesOfString: @"=" withString: @"=3D"]; + [new replaceOccurrencesOfString: @"," withString: @"=2C"]; [new makeImmutable]; _authzid = [new copy]; } else _authzid = nil; @@ -153,14 +150,12 @@ { OFString *old = _authcid; if (authcid) { OFMutableString *new = [[authcid mutableCopy] autorelease]; - [new replaceOccurrencesOfString: @"=" - withString: @"=3D"]; - [new replaceOccurrencesOfString: @"," - withString: @"=2C"]; + [new replaceOccurrencesOfString: @"=" withString: @"=3D"]; + [new replaceOccurrencesOfString: @"," withString: @"=2C"]; [new makeImmutable]; _authcid = [new copy]; } else _authcid = nil; @@ -279,21 +274,17 @@ channelBindingDataWithType: @"tls-unique"]; [tmpArray addItems: channelBinding.items count: channelBinding.count]; } tmpString = tmpArray.stringByBase64Encoding; - [ret addItems: "c=" - count: 2]; - [ret addItems: tmpString.UTF8String - count: tmpString.UTF8StringLength]; + [ret addItems: "c=" count: 2]; + [ret addItems: tmpString.UTF8String count: tmpString.UTF8StringLength]; // Add r= [ret addItem: ","]; - [ret addItems: "r=" - count: 2]; - [ret addItems: sNonce.UTF8String - count: sNonce.UTF8StringLength]; + [ret addItems: "r=" count: 2]; + [ret addItems: sNonce.UTF8String count: sNonce.UTF8StringLength]; /* * IETF RFC 5802: * SaltedPassword := Hi(Normalize(password), salt, i) */ @@ -310,23 +301,21 @@ * client-final-message-without-proof */ [authMessage addItems: _clientFirstMessageBare.UTF8String count: _clientFirstMessageBare.UTF8StringLength]; [authMessage addItem: ","]; - [authMessage addItems: data.items - count: data.count * data.itemSize]; + [authMessage addItems: data.items count: data.count * data.itemSize]; [authMessage addItem: ","]; - [authMessage addItems: ret.items - count: ret.count]; + [authMessage addItems: ret.items count: ret.count]; /* * IETF RFC 5802: * ClientKey := HMAC(SaltedPassword, "Client Key") */ - clientKey = [self xmpp_HMACWithKey: saltedPassword - data: [OFData dataWithItems: "Client Key" - count: 10]]; + clientKey = [self + xmpp_HMACWithKey: saltedPassword + data: [OFData dataWithItems: "Client Key" count: 10]]; /* * IETF RFC 5802: * StoredKey := H(ClientKey) */ @@ -344,13 +333,13 @@ /* * IETF RFC 5802: * ServerKey := HMAC(SaltedPassword, "Server Key") */ - serverKey = [self xmpp_HMACWithKey: saltedPassword - data: [OFData dataWithItems: "Server Key" - count: 10]]; + serverKey = [self + xmpp_HMACWithKey: saltedPassword + data: [OFData dataWithItems: "Server Key" count: 10]]; /* * IETF RFC 5802: * ServerSignature := HMAC(ServerKey, AuthMessage) */ @@ -357,12 +346,11 @@ tmpArray = [OFMutableData dataWithItems: serverKey count: [_hashType digestSize]]; [_serverSignature release]; _serverSignature = [[OFData alloc] - initWithItems: [self xmpp_HMACWithKey: tmpArray - data: authMessage] + initWithItems: [self xmpp_HMACWithKey: tmpArray data: authMessage] count: [_hashType digestSize]]; /* * IETF RFC 5802: * ClientProof := ClientKey XOR ClientSignature @@ -373,15 +361,13 @@ [tmpArray addItem: &c]; } // Add p= [ret addItem: ","]; - [ret addItems: "p=" - count: 2]; + [ret addItems: "p=" count: 2]; tmpString = tmpArray.stringByBase64Encoding; - [ret addItems: tmpString.UTF8String - count: tmpString.UTF8StringLength]; + [ret addItems: tmpString.UTF8String count: tmpString.UTF8StringLength]; return ret; } - (OFData *)xmpp_parseServerFinalMessage: (OFData *)data @@ -445,15 +431,13 @@ if (key.itemSize * key.count > blockSize) { hashI = [[[_hashType alloc] init] autorelease]; [hashI updateWithBuffer: key.items length: key.itemSize * key.count]; - [k addItems: hashI.digest - count: hashI.digestSize]; + [k addItems: hashI.digest count: hashI.digestSize]; } else - [k addItems: key.items - count: key.itemSize * key.count]; + [k addItems: key.items count: key.itemSize * key.count]; @try { kI = OFAllocMemory(1, blockSize); kO = OFAllocMemory(1, blockSize); @@ -506,37 +490,33 @@ salty = [[salt mutableCopy] autorelease]; [salty addItems: "\0\0\0\1" count: 4]; - uOld = [self xmpp_HMACWithKey: str - data: salty]; + uOld = [self xmpp_HMACWithKey: str data: salty]; for (j = 0; j < digestSize; j++) result[j] ^= uOld[j]; for (j = 0; j < i - 1; j++) { tmp = [[OFMutableData alloc] init]; - [tmp addItems: uOld - count: digestSize]; + [tmp addItems: uOld count: digestSize]; /* releases uOld and previous tmp */ objc_autoreleasePoolPop(pool); pool = objc_autoreleasePoolPush(); [tmp autorelease]; - u = [self xmpp_HMACWithKey: str - data: tmp]; + u = [self xmpp_HMACWithKey: str data: tmp]; for (k = 0; k < digestSize; k++) result[k] ^= u[k]; uOld = u; } - ret = [OFData dataWithItems: result - count: digestSize]; + ret = [OFData dataWithItems: result count: digestSize]; } @finally { OFFreeMemory(result); } [ret retain];