aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/Crypto
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-12-08 18:52:11 +0530
committerRoopesh Chander <roop@roopc.net>2018-12-09 14:07:03 +0530
commit60e13ddbf6e0d9fc03b57806043dbf0266a8cf70 (patch)
tree6a77e77358b5d9b25231d70058732aafaf7b486f /WireGuard/WireGuard/Crypto
parentTunnelsManager: Observe status for all tunnels in one block (diff)
downloadwireguard-apple-60e13ddbf6e0d9fc03b57806043dbf0266a8cf70.tar.xz
wireguard-apple-60e13ddbf6e0d9fc03b57806043dbf0266a8cf70.zip
Model: Declare keyLength constant and use that wherever applicable
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/Crypto')
-rw-r--r--WireGuard/WireGuard/Crypto/Curve25519.swift13
1 files changed, 8 insertions, 5 deletions
diff --git a/WireGuard/WireGuard/Crypto/Curve25519.swift b/WireGuard/WireGuard/Crypto/Curve25519.swift
index 84c35d3b..43d9b00d 100644
--- a/WireGuard/WireGuard/Crypto/Curve25519.swift
+++ b/WireGuard/WireGuard/Crypto/Curve25519.swift
@@ -4,24 +4,27 @@
import UIKit
struct Curve25519 {
+
+ static let keyLength: Int = 32
+
static func generatePrivateKey() -> Data {
- var privateKey = Data(repeating: 0, count: 32)
+ var privateKey = Data(repeating: 0, count: TunnelConfiguration.keyLength)
privateKey.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) in
curve25519_generate_private_key(bytes)
}
- assert(privateKey.count == 32)
+ assert(privateKey.count == TunnelConfiguration.keyLength)
return privateKey
}
static func generatePublicKey(fromPrivateKey privateKey: Data) -> Data {
- assert(privateKey.count == 32)
- var publicKey = Data(repeating: 0, count: 32)
+ assert(privateKey.count == TunnelConfiguration.keyLength)
+ var publicKey = Data(repeating: 0, count: TunnelConfiguration.keyLength)
privateKey.withUnsafeBytes { (privateKeyBytes: UnsafePointer<UInt8>) in
publicKey.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) in
curve25519_derive_public_key(bytes, privateKeyBytes)
}
}
- assert(publicKey.count == 32)
+ assert(publicKey.count == TunnelConfiguration.keyLength)
return publicKey
}
}