aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDataAdditions.m
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-10-13 14:55:04 +0200
committerMax <post@wickenrode.com>2015-10-13 14:56:00 +0200
commit63b23073b99097f03a57eb8f0e11a906cc4313d6 (patch)
tree795fec945a2f6a9cebfc2cfca3a88969086d993b /Source/SPDataAdditions.m
parent8c7fc9deaa3d005e0bf2afd6db5d5fa9bb63cf62 (diff)
downloadsequelpro-63b23073b99097f03a57eb8f0e11a906cc4313d6.tar.gz
sequelpro-63b23073b99097f03a57eb8f0e11a906cc4313d6.tar.bz2
sequelpro-63b23073b99097f03a57eb8f0e11a906cc4313d6.zip
Use a better RNG for IV when encrypting session files
Diffstat (limited to 'Source/SPDataAdditions.m')
-rw-r--r--Source/SPDataAdditions.m10
1 files changed, 6 insertions, 4 deletions
diff --git a/Source/SPDataAdditions.m b/Source/SPDataAdditions.m
index 8002595c..8b2207c5 100644
--- a/Source/SPDataAdditions.m
+++ b/Source/SPDataAdditions.m
@@ -37,6 +37,7 @@
#include <zlib.h>
#include <CommonCrypto/CommonCrypto.h>
#include <stdlib.h>
+#import "SPFunctions.h"
uint32_t LimitUInt32(NSUInteger i);
@@ -74,11 +75,12 @@ uint32_t LimitUInt32(NSUInteger i);
{
// Create a random 128-bit initialization vector
// IV is block "-1" of plaintext data, therefore it is blockSize long
- srand((unsigned int)time(NULL));
- NSInteger ivIndex;
unsigned char iv[kCCBlockSizeAES128];
- for (ivIndex = 0; ivIndex < kCCBlockSizeAES128; ivIndex++)
- iv[ivIndex] = rand() & 0xff;
+ if(SPBetterRandomBytes(iv,sizeof(iv)) != 0)
+ @throw [NSException exceptionWithName:NSInternalInconsistencyException
+ reason:@"Getting random data bytes failed!"
+ userInfo:@{@"errno":@(errno)}];
+
NSData *ivData = [NSData dataWithBytes:iv length:sizeof(iv)];
// Create the key from first 128-bits of the 160-bit password hash