mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 22:52:26 +00:00
Use arc4random_uniform() to avoid modulo bias. (#669)
Avoid a possible modulo bias in randomCharacter by using arc4random_uniform().
This commit is contained in:
committed by
Michael Starke
parent
0161435418
commit
73149dd125
@@ -112,10 +112,7 @@ static NSString *mergeWithoutDuplicates(NSString* baseCharacters, NSString* cust
|
||||
if(self.length == 0) {
|
||||
return nil;
|
||||
}
|
||||
NSData *data = [NSData kpk_dataWithRandomBytes:sizeof(NSUInteger)];
|
||||
NSUInteger randomIndex;
|
||||
[data getBytes:&randomIndex length:data.length];
|
||||
return [self composedCharacterAtIndex:(randomIndex % self.composedCharacterLength)];
|
||||
return [self composedCharacterAtIndex:arc4random_uniform((int)[self length])];
|
||||
}
|
||||
|
||||
- (CGFloat)entropyWhithPossibleCharacterSet:(MPPasswordCharacterFlags)allowedCharacters orCustomCharacters:(NSString *)customCharacters {
|
||||
|
||||
Reference in New Issue
Block a user