Skip to content

Commit

Permalink
Add new calculateSharedSecret with just binary password
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Oct 29, 2024
1 parent e17b51e commit 760117d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Sources/SRP/client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ public struct SRPClient<H: HashFunction> {
return SRPKey(sharedSecret)
}

/// return shared secret given a binary password, B value and salt from the server
/// - Parameters:
/// - password: password
/// - salt: salt
/// - clientKeys: client public/private keys
/// - serverPublicKey: server public key
/// - Throws: `nullServerKey`
/// - Returns: shared secret
public func calculateSharedSecret(password: [UInt8], salt: [UInt8], clientKeys: SRPKeyPair, serverPublicKey: SRPKey) throws -> SRPKey {
let message = [0x3a] + password
let sharedSecret = try calculateSharedSecret(message: message, salt: salt, clientKeys: clientKeys, serverPublicKey: serverPublicKey)
return SRPKey(sharedSecret)
}

/// calculate proof of shared secret to send to server
/// - Parameters:
Expand Down Expand Up @@ -139,7 +152,7 @@ public struct SRPClient<H: HashFunction> {
}

extension SRPClient {
/// return shared secret given the username, password, salt from server, client keys, and B value
/// return shared secret given the message (username:password), salt from server, client keys, and B value
func calculateSharedSecret(message: [UInt8], salt: [UInt8], clientKeys: SRPKeyPair, serverPublicKey: SRPKey) throws -> BigNum {
guard serverPublicKey.number % configuration.N != BigNum(0) else { throw SRPClientError.nullServerKey }

Expand Down

0 comments on commit 760117d

Please sign in to comment.