@@ -1,8 +1,8 @@ /* * Copyright (c) 2011, Florian Zeitz - * Copyright (c) 2011, 2019, Jonathan Schleifer + * Copyright (c) 2011, 2019, 2021, Jonathan Schleifer * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -224,12 +224,12 @@ - (OFData *)xmpp_parseServerFirstMessage: (OFData *)data { size_t i; const uint8_t *clientKey, *serverKey, *clientSignature; - intmax_t iterCount = 0; - id hash; + long long iterCount = 0; + id hash; OFMutableData *ret, *authMessage, *tmpArray; OFData *salt = nil, *saltedPassword; OFString *tmpString, *sNonce = nil; enum { GOT_SNONCE = 0x01, @@ -246,11 +246,11 @@ data.itemSize]; for (OFString *component in [challenge componentsSeparatedByString: @","]) { OFString *entry = [component substringWithRange: - of_range(2, component.length - 2)]; + OFRangeMake(2, component.length - 2)]; if ([component hasPrefix: @"r="]) { if (![entry hasPrefix: _cNonce]) @throw [XMPPAuthFailedException exceptionWithConnection: nil @@ -261,11 +261,11 @@ got |= GOT_SNONCE; } else if ([component hasPrefix: @"s="]) { salt = [OFData dataWithBase64EncodedString: entry]; got |= GOT_SALT; } else if ([component hasPrefix: @"i="]) { - iterCount = entry.decimalValue; + iterCount = [entry longLongValueWithBase: 10]; got |= GOT_ITERCOUNT; } } if (got != (GOT_SNONCE | GOT_SALT | GOT_ITERCOUNT)) @@ -395,11 +395,11 @@ if (_authenticated) return nil; mess = [OFString stringWithUTF8String: data.items length: data.count * data.itemSize]; - value = [mess substringWithRange: of_range(2, mess.length - 2)]; + value = [mess substringWithRange: OFRangeMake(2, mess.length - 2)]; if ([mess hasPrefix: @"v="]) { if (![value isEqual: _serverSignature.stringByBase64Encoding]) @throw [XMPPAuthFailedException exceptionWithConnection: nil @@ -428,11 +428,11 @@ if (buf[i] == ',') buf[i] = '~'; } return [OFString stringWithCString: (char *)buf - encoding: OF_STRING_ENCODING_ASCII + encoding: OFStringEncodingASCII length: 64]; } - (const uint8_t *)xmpp_HMACWithKey: (OFData *)key data: (OFData *)data @@ -439,11 +439,11 @@ { void *pool = objc_autoreleasePoolPush(); OFMutableData *k = [OFMutableData data]; size_t i, kSize, blockSize = [_hashType blockSize]; uint8_t *kI = NULL, *kO = NULL; - id hashI, hashO; + id hashI, hashO; if (key.itemSize * key.count > blockSize) { hashI = [[[_hashType alloc] init] autorelease]; [hashI updateWithBuffer: key.items length: key.itemSize * key.count]; @@ -452,12 +452,12 @@ } else [k addItems: key.items count: key.itemSize * key.count]; @try { - kI = [self allocMemoryWithSize: blockSize]; - kO = [self allocMemoryWithSize: blockSize]; + kI = OFAllocMemory(1, blockSize); + kO = OFAllocMemory(1, blockSize); kSize = k.count; memcpy(kI, k.items, kSize); memset(kI + kSize, 0, blockSize - kSize); memcpy(kO, kI, blockSize); @@ -466,23 +466,20 @@ kI[i] ^= HMAC_IPAD; kO[i] ^= HMAC_OPAD; } hashI = [[[_hashType alloc] init] autorelease]; - [hashI updateWithBuffer: kI - length: blockSize]; + [hashI updateWithBuffer: kI length: blockSize]; [hashI updateWithBuffer: data.items length: data.itemSize * data.count]; hashO = [[[_hashType alloc] init] autorelease]; - [hashO updateWithBuffer: kO - length: blockSize]; - [hashO updateWithBuffer: hashI.digest - length: hashI.digestSize]; + [hashO updateWithBuffer: kO length: blockSize]; + [hashO updateWithBuffer: hashI.digest length: hashI.digestSize]; } @finally { - [self freeMemory: kI]; - [self freeMemory: kO]; + OFFreeMemory(kI); + OFFreeMemory(kO); } [hashO retain]; objc_autoreleasePoolPop(pool); @@ -500,11 +497,11 @@ const uint8_t *u, *uOld; intmax_t j, k; OFMutableData *salty, *tmp; OFData *ret; - result = [self allocMemoryWithSize: digestSize]; + result = OFAllocMemory(1, digestSize); @try { memset(result, 0, digestSize); salty = [[salt mutableCopy] autorelease]; @@ -537,15 +534,15 @@ } ret = [OFData dataWithItems: result count: digestSize]; } @finally { - [self freeMemory: result]; + OFFreeMemory(result); } [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end