gh-XcodesOrg-XcodesApp/swift-srp-main/Sources/SRP/Array.swift
Anand Biligiri 9b107ec98c SRP Login works now
- Switch to use https://github.com/adam-fowler/swift-srp with some modifications
  that are local
  - Pad g value to equal size of N while calculating clientProof
- Use SHA256(plain-text-password) while computing key using PBKDF2
- Added a unit test with some sample values
2024-10-28 13:25:17 -07:00

29 lines
926 B
Swift

extension Array where Element: FixedWidthInteger {
/// create array of random bytes
static func random(count: Int) -> [Element] {
var array = self.init()
for _ in 0..<count {
array.append(.random(in: Element.min..<Element.max))
}
return array
}
/// generate a hexdigest of the array of bytes
func hexdigest() -> String {
return self.map({
let characters = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]
return "\(characters[Int($0 >> 4)])\(characters[Int($0 & 0xf)])"
}).joined()
}
}
/// xor together the contents of two byte arrays
func ^ (lhs: [UInt8], rhs: [UInt8]) -> [UInt8] {
precondition(lhs.count == rhs.count, "Arrays are required to be the same size")
var result = lhs
for i in 0..<lhs.count {
result[i] = result[i] ^ rhs[i]
}
return result
}