From 485748068f9a6204b4b61621a9770b84fb48f97f Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Fri, 10 Jul 2015 02:53:07 -0400 Subject: [PATCH] Checking the result of SecRandomCopyBytes Built and verified by @FredericJacobs --- Signal/src/crypto/CryptoTools.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Signal/src/crypto/CryptoTools.m b/Signal/src/crypto/CryptoTools.m index ce355cd72..7debcb67a 100644 --- a/Signal/src/crypto/CryptoTools.m +++ b/Signal/src/crypto/CryptoTools.m @@ -6,13 +6,17 @@ #import "Conversions.h" #import "EvpMessageDigest.h" #import "EvpSymetricUtil.h" +#import "SecurityFailure.h" #import "Util.h" @implementation CryptoTools +(NSData*)generateSecureRandomData:(NSUInteger)length { NSMutableData* d = [NSMutableData dataWithLength:length]; - SecRandomCopyBytes(kSecRandomDefault, length, [d mutableBytes]); + int err = SecRandomCopyBytes(kSecRandomDefault, length, [d mutableBytes]); + if (err != 0) { + [SecurityFailure raise:@"SecRandomCopyBytes failed"]; + } return d; }