@@ -31,19 +31,10 @@ #ifndef HAVE_ARC4RANDOM_UNIFORM extern uint32_t arc4random_uniform(uint32_t); #endif -@interface XMPPSCRAMAuth () -- (OFString*)XMPP_genNonce; -- (uint8_t*)XMPP_HMACWithKey: (OFDataArray*)key - data: (OFDataArray*)data; -- (OFDataArray*)XMPP_hiWithData: (OFDataArray *)str - salt: (OFDataArray *)salt_ - iterationCount: (intmax_t)i; -@end - @implementation XMPPSCRAMAuth + SCRAMAuthWithAuthcid: (OFString*)authcid password: (OFString*)password hash: (Class)hash; { @@ -170,10 +161,12 @@ intmax_t iterCount; OFHash *hash; OFDataArray *ret, *authMessage, *tmpArray, *salt, *saltedPassword; OFString *tmpString, *sNonce; OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFEnumerator *enumerator; + OFString *comp; enum { GOT_SNONCE, GOT_SALT, GOT_ITERCOUNT } got = 0; hash = [[[hashType alloc] init] autorelease]; @@ -182,11 +175,13 @@ OFString *chal = [OFString stringWithCString: [challenge cArray] length: [challenge count] * [challenge itemSize]]; - for (OFString *comp in [chal componentsSeparatedByString: @","]) { + enumerator = + [[chal componentsSeparatedByString: @","] objectEnumerator]; + while ((comp = [enumerator nextObject]) != nil) { OFString *entry = [comp substringFromIndex: 2 toIndex: [comp length]]; if ([comp hasPrefix: @"r="]) { if (![entry hasPrefix: cNonce]) @@ -371,18 +366,18 @@ OFDataArray *k = [OFDataArray dataArrayWithItemSize: 1]; size_t i, kSize, blockSize = [hashType blockSize]; uint8_t *kCArray, *kI = NULL, *kO = NULL; OFHash *hash; - if (key.itemSize * key.count > blockSize) { + if ([key itemSize] * [key count] > blockSize) { hash = [[[hashType alloc] init] autorelease]; [hash updateWithBuffer: [key cArray] - ofSize: key.itemSize * key.count]; + ofSize: [key itemSize] * [key count]]; [k addNItems: [hashType digestSize] fromCArray: [hash digest]]; } else - [k addNItems: key.itemSize * key.count + [k addNItems: [key itemSize] * [key count] fromCArray: [key cArray]]; @try { kI = [self allocMemoryWithSize: blockSize * sizeof(uint8_t)]; memset(kI, HMAC_IPAD, blockSize * sizeof(uint8_t)); @@ -389,25 +384,25 @@ kO = [self allocMemoryWithSize: blockSize * sizeof(uint8_t)]; memset(kO, HMAC_OPAD, blockSize * sizeof(uint8_t)); kCArray = [k cArray]; - kSize = k.count; + kSize = [k count]; for (i = 0; i < kSize; i++) { kI[i] ^= kCArray[i]; kO[i] ^= kCArray[i]; } k = [OFDataArray dataArrayWithItemSize: 1]; [k addNItems: blockSize fromCArray: kI]; - [k addNItems: data.itemSize * data.count + [k addNItems: [data itemSize] * [data count] fromCArray: [data cArray]]; hash = [[[hashType alloc] init] autorelease]; [hash updateWithBuffer: [k cArray] - ofSize: k.count]; + ofSize: [k count]]; k = [OFDataArray dataArrayWithItemSize: 1]; [k addNItems: blockSize fromCArray: kO]; [k addNItems: [hashType digestSize] fromCArray: [hash digest]]; @@ -416,11 +411,11 @@ [self freeMemory: kO]; } hash = [[[hashType alloc] init] autorelease]; [hash updateWithBuffer: [k cArray] - ofSize: k.count]; + ofSize: [k count]]; [hash retain]; [pool release]; return [hash digest];