Skip to content

Commit 4857480

Browse files
StrilancFredericJacobs
authored andcommitted
Checking the result of SecRandomCopyBytes
Built and verified by @FredericJacobs
1 parent 02560f8 commit 4857480

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Signal/src/crypto/CryptoTools.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
#import "Conversions.h"
77
#import "EvpMessageDigest.h"
88
#import "EvpSymetricUtil.h"
9+
#import "SecurityFailure.h"
910
#import "Util.h"
1011

1112
@implementation CryptoTools
1213

1314
+(NSData*)generateSecureRandomData:(NSUInteger)length {
1415
NSMutableData* d = [NSMutableData dataWithLength:length];
15-
SecRandomCopyBytes(kSecRandomDefault, length, [d mutableBytes]);
16+
int err = SecRandomCopyBytes(kSecRandomDefault, length, [d mutableBytes]);
17+
if (err != 0) {
18+
[SecurityFailure raise:@"SecRandomCopyBytes failed"];
19+
}
1620
return d;
1721
}
1822

0 commit comments

Comments
 (0)