Index: src/XMPPSCRAMAuth.m ================================================================== --- src/XMPPSCRAMAuth.m +++ src/XMPPSCRAMAuth.m @@ -40,11 +40,11 @@ OF_ASSUME_NONNULL_BEGIN @interface XMPPSCRAMAuth () - (OFString *)XMPP_genNonce; - (const uint8_t *)XMPP_HMACWithKey: (OFData *)key - data: (OFData *)data; + 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; @@ -264,13 +264,12 @@ if (got != (GOT_SNONCE | GOT_SALT | GOT_ITERCOUNT)) @throw [OFInvalidServerReplyException exception]; // Add c= - tmpArray = [OFMutableData data]; - [tmpArray addItems: [_GS2Header UTF8String] - count: [_GS2Header UTF8StringLength]]; + tmpArray = [OFMutableData dataWithItems: [_GS2Header UTF8String] + count: [_GS2Header UTF8StringLength]]; if (_plusAvailable && [_connection encrypted]) { OFData *channelBinding = [((SSLSocket *)[_connection socket]) channelBindingDataWithType: @"tls-unique"]; [tmpArray addItems: [channelBinding items] count: [channelBinding count]]; @@ -316,56 +315,55 @@ /* * IETF RFC 5802: * ClientKey := HMAC(SaltedPassword, "Client Key") */ clientKey = [self XMPP_HMACWithKey: saltedPassword - data: [OFData dataWithItems: @"Client key" + data: [OFData dataWithItems: "Client Key" count: 10]]; /* * IETF RFC 5802: * StoredKey := H(ClientKey) */ [hash updateWithBuffer: (void *)clientKey length: [_hashType digestSize]]; - tmpArray = [OFMutableData dataWithItems: [hash digest] - count: [_hashType digestSize]]; /* * IETF RFC 5802: * ClientSignature := HMAC(StoredKey, AuthMessage) */ - clientSignature = [self XMPP_HMACWithKey: tmpArray - data: authMessage]; + clientSignature = [self + XMPP_HMACWithKey: [OFData dataWithItems: [hash digest] + count: [_hashType digestSize]] + data: authMessage]; /* * IETF RFC 5802: * ServerKey := HMAC(SaltedPassword, "Server Key") */ - tmpArray = [OFMutableData dataWithItems: "Server Key" - count: 10]; serverKey = [self XMPP_HMACWithKey: saltedPassword - data: tmpArray]; + data: [OFData dataWithItems: "Server Key" + count: 10]]; /* * IETF RFC 5802: * ServerSignature := HMAC(ServerKey, AuthMessage) */ tmpArray = [OFMutableData dataWithItems: serverKey count: [_hashType digestSize]]; [_serverSignature release]; - _serverSignature = [[OFMutableData alloc] + _serverSignature = [[OFData alloc] initWithItems: [self XMPP_HMACWithKey: tmpArray data: authMessage] count: [_hashType digestSize]]; /* * IETF RFC 5802: * ClientProof := ClientKey XOR ClientSignature */ - tmpArray = [OFMutableData data]; + tmpArray = [OFMutableData dataWithCapacity: [_hashType digestSize]]; for (i = 0; i < [_hashType digestSize]; i++) { uint8_t c = clientKey[i] ^ clientSignature[i]; [tmpArray addItem: &c]; } @@ -493,18 +491,19 @@ void *pool = objc_autoreleasePoolPush(); size_t digestSize = [_hashType digestSize]; uint8_t *result = NULL; const uint8_t *u, *uOld; intmax_t j, k; - OFMutableData *salty, *tmp, *ret; + OFMutableData *salty, *tmp; + OFData *ret; result = [self allocMemoryWithSize: digestSize]; @try { memset(result, 0, digestSize); - salty = [[salt copy] autorelease]; + salty = [[salt mutableCopy] autorelease]; [salty addItems: "\0\0\0\1" count: 4]; uOld = [self XMPP_HMACWithKey: str data: salty]; @@ -529,12 +528,12 @@ result[k] ^= u[k]; uOld = u; } - ret = [OFMutableData dataWithItems: result - count: digestSize]; + ret = [OFData dataWithItems: result + count: digestSize]; } @finally { [self freeMemory: result]; } [ret retain];