diff options
Diffstat (limited to 'WireGuard/WireGuard/Crypto')
-rw-r--r-- | WireGuard/WireGuard/Crypto/Curve25519.swift | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/WireGuard/WireGuard/Crypto/Curve25519.swift b/WireGuard/WireGuard/Crypto/Curve25519.swift index 84c35d3..43d9b00 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 } } |