Skip to content

Commit 9933e15

Browse files
committed
Revert previous commit, instead add SRPKey.unpaddedBytes
1 parent a3b0fca commit 9933e15

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

Sources/SRP/client.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public struct SRPClient<H: HashFunction> {
9696
) -> [UInt8] {
9797
let clientPublicKey = clientPublicKey.with(padding: configuration.sizeN)
9898
let serverPublicKey = serverPublicKey.with(padding: configuration.sizeN)
99-
let sharedSecret = sharedSecret.with(padding: configuration.sizeN)
10099
let hashSharedSecret = [UInt8](H.hash(data: sharedSecret.bytes))
101100
// get verification code
102101
return SRP<H>.calculateClientProof(
@@ -198,7 +197,7 @@ public extension SRPClient {
198197
// calculate S = (B - k*g^x)^(a+u*x)
199198
let S = (serverPublicKey.number - configuration.k * configuration.g.power(x, modulus: configuration.N)).power(clientKeys.private.number + u * x, modulus: configuration.N)
200199

201-
return SRPKey(S)
200+
return SRPKey(S, padding: configuration.sizeN)
202201
}
203202

204203
/// generate password verifier

Sources/SRP/keys.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ public struct SRPKey {
1010
public let padding: Int
1111
/// Representation as a byte array
1212
public var bytes: [UInt8] { number.bytes.pad(to: padding) }
13+
/// Representation as a byte array without padding
14+
public var unpaddedBytes: [UInt8] { number.bytes }
1315
/// Representation as a hex string
1416
public var hex: String { number.bytes.pad(to: padding).hexdigest() }
17+
/// Representation as a hex string without padding
18+
public var unpaddedHex: String { number.bytes.hexdigest() }
1519

1620
/// Initialize with an array of bytes
1721
@inlinable public init<C: Collection & ContiguousBytes>(_ bytes: C, padding: Int? = nil) {

Sources/SRP/server.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public struct SRPServer<H: HashFunction> {
5959
// calculate S
6060
let S = ((clientPublicKey.number * verifier.number.power(u, modulus: configuration.N)).power(serverKeys.private.number, modulus: configuration.N))
6161

62-
return SRPKey(S)
62+
return SRPKey(S, padding: configuration.sizeN)
6363
}
6464

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

0 commit comments

Comments
 (0)