mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
667 B
Matlab
25 lines
667 B
Matlab
5 years ago
|
//
|
||
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "Randomness.h"
|
||
|
#import <SessionProtocolKit/OWSAsserts.h>
|
||
|
|
||
|
@implementation Randomness
|
||
|
|
||
|
+ (NSData *)generateRandomBytes:(int)numberBytes
|
||
|
{
|
||
|
NSMutableData *_Nullable randomBytes = [NSMutableData dataWithLength:numberBytes];
|
||
|
if (!randomBytes) {
|
||
|
OWSFail(@"Could not allocate buffer for random bytes.");
|
||
|
}
|
||
|
int err = 0;
|
||
|
err = SecRandomCopyBytes(kSecRandomDefault, numberBytes, [randomBytes mutableBytes]);
|
||
|
if (err != noErr || randomBytes.length != numberBytes) {
|
||
|
OWSFail(@"Could not generate random bytes.");
|
||
|
}
|
||
|
return [randomBytes copy];
|
||
|
}
|
||
|
|
||
|
@end
|