@@ -93,22 +93,39 @@ public struct SRPClient<H: HashFunction> {
9393 return SRP< H> . calculateClientProof( configuration: configuration, username: username, salt: salt, clientPublicKey: clientPublicKey, serverPublicKey: serverPublicKey, hashSharedSecret: hashSharedSecret)
9494 }
9595
96- /// If the server returns that the client verification code was valiid it will also return a server verification code that the client can use to verify the server is correct
96+ /// If the server returns that the client verification code was valid it will also return a server
97+ /// verification code that the client can use to verify the server is correct. This is the calculation
98+ /// to verify it is correct
9799 ///
98100 /// - Parameters:
99- /// - code: Verification code returned by server
100- /// - state: Authentication state
101- /// - Throws: `requiresVerificationKey`, `invalidServerCode`
102- public func verifyServerProof ( serverProof : [ UInt8 ] , clientProof: [ UInt8 ] , clientKeys : SRPKeyPair , sharedSecret: SRPKey ) throws {
101+ /// - clientPublicKey: Client public key
102+ /// - clientProof: Client proof
103+ /// - sharedSecret: Shared secret
104+ public func calculateServerProof ( clientPublicKey : SRPKey , clientProof: [ UInt8 ] , sharedSecret: SRPKey ) -> [ UInt8 ] {
103105 let hashSharedSecret = [ UInt8] ( H . hash ( data: sharedSecret. bytes) )
104106 // get out version of server proof
105- let HAMK = SRP< H> . calculateServerVerification( clientPublicKey: clientKeys. public, clientProof: clientProof, sharedSecret: hashSharedSecret)
107+ return SRP< H> . calculateServerVerification( clientPublicKey: clientPublicKey, clientProof: clientProof, sharedSecret: hashSharedSecret)
108+ }
109+
110+ /// If the server returns that the client verification code was valid it will also return a server
111+ /// verification code that the client can use to verify the server is correct
112+ ///
113+ /// - Parameters:
114+ /// - clientProof: Server proof
115+ /// - clientProof: Client proof
116+ /// - clientKeys: Client keys
117+ /// - sharedSecret: Shared secret
118+ /// - Throws: `requiresVerificationKey`, `invalidServerCode`
119+ public func verifyServerProof( serverProof: [ UInt8 ] , clientProof: [ UInt8 ] , clientKeys: SRPKeyPair , sharedSecret: SRPKey ) throws {
120+ // get our version of server proof
121+ let HAMK = calculateServerProof ( clientPublicKey: clientKeys. public, clientProof: clientProof, sharedSecret: sharedSecret)
106122 // is it the same
107123 guard serverProof == HAMK else { throw SRPClientError . invalidServerCode }
108124 }
109125
110- /// Generate salt and password verifier from username and password. When creating your user instead of passing your password to the server, you
111- /// pass the salt and password verifier values. In this way the server never knows your password so can never leak it.
126+ /// Generate salt and password verifier from username and password. When creating your user instead of
127+ /// passing your password to the server, you pass the salt and password verifier values. In this way the
128+ /// server never knows your password so can never leak it.
112129 ///
113130 /// - Parameters:
114131 /// - username: username
0 commit comments