Move seed

pull/1/head
Michael Kirk 7 years ago
parent 4704c6751a
commit 0bc03b0fd4

@ -99,7 +99,6 @@
3461284B1FD0B94000532771 /* SAELoadViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3461284A1FD0B93F00532771 /* SAELoadViewController.swift */; };
346129391FD1B47300532771 /* OWSPreferences.h in Headers */ = {isa = PBXBuildFile; fileRef = 346129371FD1B47200532771 /* OWSPreferences.h */; settings = {ATTRIBUTES = (Public, ); }; };
3461293A1FD1B47300532771 /* OWSPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 346129381FD1B47200532771 /* OWSPreferences.m */; };
3461293C1FD1D46A00532771 /* OWSMath.m in Sources */ = {isa = PBXBuildFile; fileRef = 3461293B1FD1D46900532771 /* OWSMath.m */; };
3461293E1FD1D72B00532771 /* ExperienceUpgradeFinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3461293D1FD1D72B00532771 /* ExperienceUpgradeFinder.swift */; };
3461295A1FD1D74C00532771 /* Environment.h in Headers */ = {isa = PBXBuildFile; fileRef = 346129401FD1D74B00532771 /* Environment.h */; settings = {ATTRIBUTES = (Public, ); }; };
3461295B1FD1D74C00532771 /* Environment.m in Sources */ = {isa = PBXBuildFile; fileRef = 346129411FD1D74B00532771 /* Environment.m */; };
@ -734,7 +733,6 @@
3461284A1FD0B93F00532771 /* SAELoadViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SAELoadViewController.swift; sourceTree = "<group>"; };
346129371FD1B47200532771 /* OWSPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSPreferences.h; sourceTree = "<group>"; };
346129381FD1B47200532771 /* OWSPreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSPreferences.m; sourceTree = "<group>"; };
3461293B1FD1D46900532771 /* OWSMath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSMath.m; sourceTree = "<group>"; };
3461293D1FD1D72B00532771 /* ExperienceUpgradeFinder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ExperienceUpgradeFinder.swift; path = ExperienceUpgrades/ExperienceUpgradeFinder.swift; sourceTree = "<group>"; };
346129401FD1D74B00532771 /* Environment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Environment.h; sourceTree = "<group>"; };
346129411FD1D74B00532771 /* Environment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Environment.m; sourceTree = "<group>"; };
@ -1548,7 +1546,6 @@
45666EC71D994C0D008FE134 /* OWSGroupAvatarBuilder.h */,
45666EC81D994C0D008FE134 /* OWSGroupAvatarBuilder.m */,
34480B481FD0A60200BC14EF /* OWSMath.h */,
3461293B1FD1D46900532771 /* OWSMath.m */,
346129371FD1B47200532771 /* OWSPreferences.h */,
346129381FD1B47200532771 /* OWSPreferences.m */,
34641E172088D7E900E2EDE5 /* OWSScreenLock.swift */,
@ -3264,7 +3261,6 @@
34ABB2C42090C59700C727A6 /* OWSResaveCollectionDBMigration.m in Sources */,
4551DB5A205C562300C8AE75 /* Collection+OWS.swift in Sources */,
450C800E20AD1A6500F3A091 /* OWSNavigationBar.swift in Sources */,
3461293C1FD1D46A00532771 /* OWSMath.m in Sources */,
451F8A391FD711D6005CB9DA /* ContactsViewHelper.m in Sources */,
346129AF1FD1F5D900532771 /* SystemContactsFetcher.swift in Sources */,
344F248B20069F0600CFB4F4 /* ViewControllerUtils.m in Sources */,

@ -123,7 +123,7 @@ static NSTimeInterval launchStartedAt;
DDLogWarn(@"%@ application: didFinishLaunchingWithOptions.", self.logTag);
SetRandFunctionSeed();
[Cryptography seedRandom];
// XXX - careful when moving this. It must happen before we initialize OWSPrimaryStorage.
[self verifyDBKeysAvailableBeforeBackgroundLaunch];

@ -33,6 +33,4 @@ static inline CGFloat CeilEven(CGFloat value)
return 2.f * (CGFloat)ceil(value * 0.5f);
}
void SetRandFunctionSeed(void);
NS_ASSUME_NONNULL_END

@ -1,19 +0,0 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSMath.h"
NS_ASSUME_NONNULL_BEGIN
void SetRandFunctionSeed(void)
{
// Set the seed the generator for rand().
//
// We should always use arc4random() instead of rand(), but we
// still want to ensure that any third-party code that uses rand()
// gets random values.
srand((unsigned int)time(NULL));
}
NS_ASSUME_NONNULL_END

@ -55,6 +55,7 @@ typedef NS_ENUM(NSInteger, TSMACType) {
+ (uint32_t)randomUInt32;
+ (uint64_t)randomUInt64;
+ (unsigned)randomUnsigned;
#pragma mark - SHA and HMAC methods
@ -95,6 +96,8 @@ typedef NS_ENUM(NSInteger, TSMACType) {
+ (nullable NSData *)encryptAESGCMWithProfileData:(NSData *)plaintextData key:(OWSAES256Key *)key;
+ (nullable NSData *)decryptAESGCMWithProfileData:(NSData *)encryptedData key:(OWSAES256Key *)key;
+ (void)seedRandom;
@end
NS_ASSUME_NONNULL_END

@ -151,6 +151,15 @@ const NSUInteger kAES256_KeyByteLength = 32;
return result;
}
+ (unsigned)randomUnsigned
{
size_t size = sizeof(unsigned);
NSData *data = [self generateRandomBytes:size];
unsigned result = 0;
[data getBytes:&result range:NSMakeRange(0, size)];
return result;
}
#pragma mark - SHA1
// Used by TSContactManager to send hashed/truncated contact list to server.
@ -777,6 +786,12 @@ const NSUInteger kAES256_KeyByteLength = 32;
key:key];
}
+ (void)seedRandom
{
unsigned seed = [Cryptography randomUnsigned];
srand(seed);
}
@end
NS_ASSUME_NONNULL_END

@ -48,7 +48,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
startupLogging()
SetRandFunctionSeed()
Cryptography.seedRandom()
// We don't need to use DeviceSleepManager in the SAE.

Loading…
Cancel
Save