372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
|
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
-
-
+
+
-
-
+
+
-
+
-
+
-
-
-
+
-
-
+
+
+
+
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
-
+
-
-
+
+
-
-
-
-
-
-
+
-
+
|
- (uint8_t*)XMPP_HMACWithKey: (OFDataArray*)key
data: (OFDataArray*)data
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
OFDataArray *k = [OFDataArray dataArrayWithItemSize: 1];
size_t i, kSize, blockSize = [hashType blockSize];
uint8_t *kCArray, *kI = NULL, *kO = NULL;
OFHash *hash;
uint8_t *kI = NULL, *kO = NULL;
OFHash *hashI, *hashO;
if ([key itemSize] * [key count] > blockSize) {
hash = [[[hashType alloc] init] autorelease];
[hash updateWithBuffer: [key cArray]
hashI = [[[hashType alloc] init] autorelease];
[hashI updateWithBuffer: [key cArray]
length: [key itemSize] * [key count]];
[k addNItems: [hashType digestSize]
fromCArray: [hash digest]];
fromCArray: [hashI digest]];
} else
[k addNItems: [key itemSize] * [key count]
fromCArray: [key cArray]];
@try {
kI = [self allocMemoryWithSize: blockSize * sizeof(uint8_t)];
kI = [self allocMemoryWithSize: blockSize];
memset(kI, HMAC_IPAD, blockSize * sizeof(uint8_t));
kO = [self allocMemoryWithSize: blockSize * sizeof(uint8_t)];
kO = [self allocMemoryWithSize: blockSize];
memset(kO, HMAC_OPAD, blockSize * sizeof(uint8_t));
kCArray = [k cArray];
kSize = [k count];
memcpy(kI, [k cArray], kSize);
memset(kI + kSize, 0, blockSize - kSize);
memcpy(kO, kI, blockSize);
for (i = 0; i < kSize; i++) {
kI[i] ^= kCArray[i];
kO[i] ^= kCArray[i];
for (i = 0; i < blockSize; i++) {
kI[i] ^= HMAC_IPAD;
kO[i] ^= HMAC_OPAD;
}
hashI = [[[hashType alloc] init] autorelease];
k = [OFDataArray dataArrayWithItemSize: 1];
[k addNItems: blockSize
fromCArray: kI];
[k addNItems: [data itemSize] * [data count]
[hashI updateWithBuffer: (char*)kI
length: blockSize];
[hashI updateWithBuffer: [data cArray]
length: [data itemSize] * [data count]];
fromCArray: [data cArray]];
hash = [[[hashType alloc] init] autorelease];
[hash updateWithBuffer: [k cArray]
hashO = [[hashType alloc] init];
[hashO updateWithBuffer: (char*)kO
length: [k count]];
k = [OFDataArray dataArrayWithItemSize: 1];
[k addNItems: blockSize
length: blockSize];
fromCArray: kO];
[k addNItems: [hashType digestSize]
[hashO updateWithBuffer: (char*)[hashI digest]
length: [hashType digestSize]];
fromCArray: [hash digest]];
} @finally {
[self freeMemory: kI];
[self freeMemory: kO];
}
hash = [[[hashType alloc] init] autorelease];
[hash updateWithBuffer: [k cArray]
length: [k count]];
[hash retain];
[pool release];
[hashO autorelease];
return [hash digest];
return [hashO digest];
}
- (OFDataArray*)XMPP_hiWithData: (OFDataArray *)str
salt: (OFDataArray *)salt_
iterationCount: (intmax_t)i
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
|