Skip to content

Commit

Permalink
Revert previous commit, instead add SRPKey.unpaddedBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Oct 31, 2024
1 parent a3b0fca commit 9933e15
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions Sources/SRP/client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public struct SRPClient<H: HashFunction> {
) -> [UInt8] {
let clientPublicKey = clientPublicKey.with(padding: configuration.sizeN)
let serverPublicKey = serverPublicKey.with(padding: configuration.sizeN)
let sharedSecret = sharedSecret.with(padding: configuration.sizeN)
let hashSharedSecret = [UInt8](H.hash(data: sharedSecret.bytes))
// get verification code
return SRP<H>.calculateClientProof(
Expand Down Expand Up @@ -198,7 +197,7 @@ public extension SRPClient {
// calculate S = (B - k*g^x)^(a+u*x)
let S = (serverPublicKey.number - configuration.k * configuration.g.power(x, modulus: configuration.N)).power(clientKeys.private.number + u * x, modulus: configuration.N)

return SRPKey(S)
return SRPKey(S, padding: configuration.sizeN)
}

/// generate password verifier
Expand Down
4 changes: 4 additions & 0 deletions Sources/SRP/keys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ public struct SRPKey {
public let padding: Int
/// Representation as a byte array
public var bytes: [UInt8] { number.bytes.pad(to: padding) }
/// Representation as a byte array without padding
public var unpaddedBytes: [UInt8] { number.bytes }
/// Representation as a hex string
public var hex: String { number.bytes.pad(to: padding).hexdigest() }
/// Representation as a hex string without padding
public var unpaddedHex: String { number.bytes.hexdigest() }

/// Initialize with an array of bytes
@inlinable public init<C: Collection & ContiguousBytes>(_ bytes: C, padding: Int? = nil) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SRP/server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public struct SRPServer<H: HashFunction> {
// calculate S
let S = ((clientPublicKey.number * verifier.number.power(u, modulus: configuration.N)).power(serverKeys.private.number, modulus: configuration.N))

return SRPKey(S)
return SRPKey(S, padding: configuration.sizeN)
}

/// verify proof that client has shared secret and return a server verification proof. If verification fails a `invalidClientCode` error is thrown
Expand Down

0 comments on commit 9933e15

Please sign in to comment.