Skip to content

Commit

Permalink
re-add some code comments about the variable names
Browse files Browse the repository at this point in the history
the variable names can be a bit confusing without any context, but they
match the RFC so it makes it easier to verify
  • Loading branch information
bgrosse-midokura committed May 14, 2021
1 parent cbd839d commit eb824ea
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 5 deletions.
42 changes: 40 additions & 2 deletions src/session-client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { SRPRoutines } from "./routines";
import { HashWordArray } from "./utils";

// Variable names match the RFC (I, IH, S, b, B, salt, b, A, M1, M2...)

export class SRPClientSession {
constructor(private readonly routines: SRPRoutines) {}
public step1(userId: string, userPassword: string): SRPClientSessionStep1 {

public step1(
/**
* User identity
*/
userId: string,
/**
* User password (not kept in state)
*/
userPassword: string,
): SRPClientSessionStep1 {
if (!userId || !userId.trim()) {
throw new Error("User identity must not be null nor empty");
}
Expand All @@ -19,10 +31,26 @@ export class SRPClientSession {
class SRPClientSessionStep1 {
constructor(
private readonly routines: SRPRoutines,
/**
* User identity
*/
private readonly I: string,
/**
* User identity/password hash
*/
public readonly IH: HashWordArray,
) {}
public step2(salt: bigint, B: bigint): SRPClientSessionStep2 {

public step2(
/**
* Some generated salt (see createVerifierAndSalt)
*/
salt: bigint,
/**
* Server public key "B"
*/
B: bigint,
): SRPClientSessionStep2 {
if (!salt) {
throw new Error("Salt (s) must not be null");
}
Expand All @@ -46,10 +74,20 @@ class SRPClientSessionStep1 {
class SRPClientSessionStep2 {
constructor(
private readonly routines: SRPRoutines,
/**
* Client public value "A"
*/
public readonly A: bigint,
/**
* Client evidence message "M1"
*/
public readonly M1: bigint,
/**
* Shared session key "S"
*/
public readonly S: bigint,
) {}

public step3(M2: bigint): void {
if (!M2) {
throw new Error("Server evidence (M2) must not be null");
Expand Down
50 changes: 47 additions & 3 deletions src/session-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@ import { modPow } from "bigint-mod-arith";
import { SRPParameters } from "./parameters";
import { SRPRoutines } from "./routines";

// Variable names match the RFC (I, IH, S, b, B, salt, b, A, M1, M2...)

export class SRPServerSession {
constructor(private readonly routines: SRPRoutines) {}

public step1(identifier: string, salt: bigint, verifier: bigint) {
public step1(
/**
* User identity
*/
identifier: string,
/**
* User salt
*/
salt: bigint,
/**
* User verifier
*/
verifier: bigint,
) {
const b = this.routines.generatePrivateValue();
const k = this.routines.computeK();
const B = computeServerPublicValue(
Expand All @@ -28,17 +43,37 @@ export class SRPServerSession {
class SRPServerSessionStep1 {
constructor(
public readonly routines: SRPRoutines,
/**
* User identity
*/
private readonly identifier: string,
/**
* User salt
*/
private readonly salt: bigint,
/**
* User verifier
*/
private readonly verifier: bigint,
/**
* Server private key "b"
*/
private readonly b: bigint,
/**
* Serve public key "B"
*/
public readonly B: bigint,
) {}

/**
* Compute the session key "S" without computing or checking client evidence
*/
public sessionKey(A: bigint): bigint {
public sessionKey(
/**
* Client public key "A"
*/
A: bigint,
): bigint {
if (A === null) {
throw new Error("Client public value (A) must not be null");
}
Expand All @@ -58,7 +93,16 @@ class SRPServerSessionStep1 {
return S;
}

public step2(A: bigint, M1: bigint) {
public step2(
/**
* Client public key "A"
*/
A: bigint,
/**
* Client message "M1"
*/
M1: bigint,
) {
if (!M1) {
throw new Error("Client evidence (M1) must not be null");
}
Expand Down

0 comments on commit eb824ea

Please sign in to comment.