Move PRNG initialization to namespace level
This commit is contained in:
parent
821cf66d79
commit
8be0f14aa9
|
@ -205,7 +205,7 @@ open class TunnelKitProvider: NEPacketTunnelProvider {
|
|||
log.info("Starting tunnel...")
|
||||
cfg.clearLastError(in: appGroup)
|
||||
|
||||
guard OpenVPN.EncryptionBridge.prepareRandomNumberGenerator(seedLength: prngSeedLength) else {
|
||||
guard OpenVPN.prepareRandomNumberGenerator(seedLength: prngSeedLength) else {
|
||||
completionHandler(ProviderConfigurationError.prngInitialization)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -39,28 +39,11 @@ import __TunnelKitCore
|
|||
import __TunnelKitOpenVPN
|
||||
|
||||
extension OpenVPN {
|
||||
|
||||
/// Bridges native encryption for high-level operations.
|
||||
public class EncryptionBridge {
|
||||
class EncryptionBridge {
|
||||
private static let maxHmacLength = 100
|
||||
|
||||
private let box: CryptoBox
|
||||
|
||||
/**
|
||||
Initializes the PRNG. Must be issued before using `OpenVPNSession`.
|
||||
|
||||
- Parameter seedLength: The length in bytes of the pseudorandom seed that will feed the PRNG.
|
||||
*/
|
||||
public static func prepareRandomNumberGenerator(seedLength: Int) -> Bool {
|
||||
let seed: ZeroingData
|
||||
do {
|
||||
seed = try SecureRandom.safeData(length: seedLength)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
return CryptoBox.preparePRNG(withSeed: seed.bytes, length: seed.count)
|
||||
}
|
||||
|
||||
// Ruby: keys_prf
|
||||
private static func keysPRF(
|
||||
_ label: String,
|
||||
|
|
|
@ -24,7 +24,25 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import __TunnelKitCore
|
||||
import __TunnelKitOpenVPN
|
||||
|
||||
/// Container for OpenVPN classes.
|
||||
public class OpenVPN {
|
||||
|
||||
/**
|
||||
Initializes the PRNG. Must be issued before using `OpenVPNSession`.
|
||||
|
||||
- Parameter seedLength: The length in bytes of the pseudorandom seed that will feed the PRNG.
|
||||
*/
|
||||
public static func prepareRandomNumberGenerator(seedLength: Int) -> Bool {
|
||||
let seed: ZeroingData
|
||||
do {
|
||||
seed = try SecureRandom.safeData(length: seedLength)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
return CryptoBox.preparePRNG(withSeed: seed.bytes, length: seed.count)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue