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

GH-525: Fix sntrup761x25519-sha512 #528

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

## Bug Fixes

* [GH-525](https://github.com/apache/mina-sshd/issues/525) Fix sntrup761x25519-sha512 key exchange

## New Features

## Potential compatibility issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public XDH create(Object... params) throws Exception {
if (!GenericUtils.isEmpty(params)) {
throw new IllegalArgumentException("No accepted parameters for " + getName());
}
return new XDH(MontgomeryCurve.x25519) {
return new XDH(MontgomeryCurve.x25519, false) {

@Override
public Digest getHash() throws Exception {
Expand All @@ -274,7 +274,7 @@ public XDH create(Object... params) throws Exception {
if (!GenericUtils.isEmpty(params)) {
throw new IllegalArgumentException("No accepted parameters for " + getName());
}
return new XDH(MontgomeryCurve.x25519) {
return new XDH(MontgomeryCurve.x25519, false) {

@Override
public Digest getHash() throws Exception {
Expand All @@ -298,7 +298,7 @@ public XDH create(Object... params) throws Exception {
if (!GenericUtils.isEmpty(params)) {
throw new IllegalArgumentException("No accepted parameters for " + getName());
}
return new XDH(MontgomeryCurve.x448) {
return new XDH(MontgomeryCurve.x448, false) {

@Override
public Digest getHash() throws Exception {
Expand All @@ -322,7 +322,7 @@ public XDH create(Object... params) throws Exception {
if (!GenericUtils.isEmpty(params)) {
throw new IllegalArgumentException("No accepted parameters for " + getName());
}
return new XDH(MontgomeryCurve.x25519) {
return new XDH(MontgomeryCurve.x25519, true) {

@Override
public KeyEncapsulationMethod getKeyEncapsulation() {
Expand Down
9 changes: 6 additions & 3 deletions sshd-core/src/main/java/org/apache/sshd/common/kex/XDH.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
*/
public abstract class XDH extends AbstractDH {

protected MontgomeryCurve curve;
protected final MontgomeryCurve curve;
protected final boolean raw;
protected byte[] f;

public XDH(MontgomeryCurve curve) throws Exception {
public XDH(MontgomeryCurve curve, boolean raw) throws Exception {
this.curve = Objects.requireNonNull(curve, "No MontgomeryCurve provided");
this.raw = raw;
myKeyAgree = curve.createKeyAgreement();
}

Expand Down Expand Up @@ -77,6 +79,7 @@ public void putF(Buffer buffer, byte[] f) {
protected byte[] calculateK() throws Exception {
Objects.requireNonNull(f, "Missing 'f' value");
myKeyAgree.doPhase(curve.decode(f), true);
return stripLeadingZeroes(myKeyAgree.generateSecret());
byte[] secret = myKeyAgree.generateSecret();
return raw ? secret : stripLeadingZeroes(secret);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ protected byte[] resizeKey(
buffer = new ByteArrayBuffer();
}

buffer.putMPInt(k);
buffer.putBytes(k);
buffer.putRawBytes(h);
buffer.putRawBytes(e);
hash.update(buffer.array(), 0, buffer.available());
Expand Down