spb/os-vault Public
Self-custody, multi-chain crypto wallet for macOS. One recovery phrase, six chain families, zero API keys — nothing leaves your Mac.
Swift 96%
Shell 3.4%
Makefile 0.6%
1import CommonCrypto2import Foundation34func pbkdf2(hash: CCPBKDFAlgorithm, password: String, salt: Data, keyByteCount: Int, rounds: Int) -> Data? {5 let passwordData = password.data(using: String.Encoding.utf8)!6 var derivedKeyData = Data(repeating: 0, count: keyByteCount)7 let derivedKeyDataCount = derivedKeyData.count8 let derivationStatus = derivedKeyData.withUnsafeMutableBytes { derivedKeyBytes in9 salt.withUnsafeBytes { saltBytes in10 CCKeyDerivationPBKDF(11 CCPBKDFAlgorithm(kCCPBKDF2),12 password, passwordData.count,13 saltBytes, salt.count,14 hash,15 UInt32(rounds),16 derivedKeyBytes, derivedKeyDataCount17 )18 }19 }2021 if derivationStatus != 0 {22 print("Error: \(derivationStatus)")23 return nil24 }2526 return derivedKeyData27}28