(fix) handle sha512-crypt with rounds

This commit is contained in:
Ludovic Marcotte 2017-01-06 15:52:19 -05:00
parent 071c1032c1
commit 9fbc84158a

View file

@ -721,7 +721,7 @@ static void _nettle_md5_compress(uint32_t *digest, const uint8_t *input);
cryptParts = [cryptString componentsSeparatedByString: @"$"]; cryptParts = [cryptString componentsSeparatedByString: @"$"];
// correct number of elements (first one is an empty string) // correct number of elements (first one is an empty string)
if ([cryptParts count] != 4) if ([cryptParts count] < 4)
{ {
return [NSData data]; return [NSData data];
} }
@ -731,7 +731,16 @@ static void _nettle_md5_compress(uint32_t *digest, const uint8_t *input);
[[cryptParts objectAtIndex: 1] caseInsensitiveCompare: @"6"] == NSOrderedSame) [[cryptParts objectAtIndex: 1] caseInsensitiveCompare: @"6"] == NSOrderedSame)
{ {
// third is the salt; convert it to NSData // third is the salt; convert it to NSData
return [[cryptParts objectAtIndex: 2] dataUsingEncoding: NSUTF8StringEncoding]; if ([cryptParts count] == 4)
return [[cryptParts objectAtIndex: 2] dataUsingEncoding: NSUTF8StringEncoding];
else
{
NSString *saltWithRounds;
saltWithRounds = [NSString stringWithFormat: @"%@$%@", [cryptParts objectAtIndex: 2], [cryptParts objectAtIndex: 3]];
return [saltWithRounds dataUsingEncoding: NSUTF8StringEncoding];
}
} }
// nothing good // nothing good
return [NSData data]; return [NSData data];