Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is K computed properly? #55

Closed
jbis9051 opened this issue May 13, 2021 · 5 comments
Closed

Is K computed properly? #55

jbis9051 opened this issue May 13, 2021 · 5 comments

Comments

@jbis9051
Copy link
Contributor

The code for computing K is:

tssrp6a/src/routines.ts

Lines 47 to 54 in 4c88ce7

public computeK(): BigInteger {
return wordArrayToBigInteger(
this.hashPadded(
bigIntegerToWordArray(this.parameters.N),
bigIntegerToWordArray(this.parameters.g),
),
);
}

However, [RFC5054](https://datatracker.ietf.org/doc/html/rfc5054#section-2.6 says the following:

k = SHA1(N | PAD(g))

In the RFC, only g is padded however in the library both N and g are padded.

Is this incorrect or am I missing something?


Nimbus seems to do the same thing: https://bitbucket.org/connect2id/nimbus-srp/src/7a28da95af0317f99a9bcb88479e56fcf7b2a5cf/src/main/java/com/nimbusds/srp6/SRP6Routines.java#lines-50

As well as Mozilla https://github.com/mozilla/node-srp/blob/dd55cab369d811fb814484e3c60d72e0e8f868dc/lib/srp.js#L135

1Password pads nothing and notes it as a bug

https://github.com/1Password/srp/blob/c06b30ed95c1485878b18d85749e36013e78e024/internal.go#L43

@bgrosse-midokura
Copy link
Contributor

This library was developed against Nimbus, that would be the reason why it follows its behavior.
This could be configurable, though.

@jbis9051
Copy link
Contributor Author

@bgrosse-midokura Hmm. Maybe I should open an issue over there.

@jbis9051
Copy link
Contributor Author

@bufistov
Copy link

It seems that N == PAD(N) by the PAD() definition in RFC?

@jbis9051
Copy link
Contributor Author

It seems that N == PAD(N) by the PAD() definition in RFC?

Seems so:

test("#pad N test", async (t) => {
  const srpRoutines = new SRPRoutines(new SRPParameters());
  t.equals(
    arrayBufferToBigInt(
      await srpRoutines.hash(
        bigIntToArrayBuffer(srpRoutines.parameters.primeGroup.N),
      ),
    ),
    arrayBufferToBigInt(
      await srpRoutines.hashPadded(
        bigIntToArrayBuffer(srpRoutines.parameters.primeGroup.N),
      ),
    ),
  );
});

passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants