Skip to content

Commit 5fa5b64

Browse files
committed
Simplify aliases for DH factories
Avoid code duplication.
1 parent 81d3ea5 commit 5fa5b64

1 file changed

Lines changed: 8 additions & 33 deletions

File tree

sshd-core/src/main/java/org/apache/sshd/common/kex/BuiltinDHFactories.java

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -270,23 +270,13 @@ public boolean isSupported() {
270270
},
271271
curve25519_libssh(Constants.CURVE25519_SHA256_LIBSSH) {
272272
@Override
273-
public XDH create(Object... params) throws Exception {
274-
if (!GenericUtils.isEmpty(params)) {
275-
throw new IllegalArgumentException("No accepted parameters for " + getName());
276-
}
277-
return new XDH(MontgomeryCurve.x25519, false) {
278-
279-
@Override
280-
public Digest getHash() throws Exception {
281-
return BuiltinDigests.sha256.create();
282-
}
283-
284-
};
273+
public AbstractDH create(Object... params) throws Exception {
274+
return curve25519.create(params);
285275
}
286276

287277
@Override
288278
public boolean isSupported() {
289-
return MontgomeryCurve.x25519.isSupported() && BuiltinDigests.sha256.isSupported();
279+
return curve25519.isSupported();
290280
}
291281
},
292282
/**
@@ -348,28 +338,13 @@ public boolean isSupported() {
348338
*/
349339
sntrup761x25519_openssh(Constants.SNTRUP761_25519_SHA512_OPENSSH) {
350340
@Override
351-
public XDH create(Object... params) throws Exception {
352-
if (!GenericUtils.isEmpty(params)) {
353-
throw new IllegalArgumentException("No accepted parameters for " + getName());
354-
}
355-
return new XDH(MontgomeryCurve.x25519, true) {
356-
357-
@Override
358-
public KeyEncapsulationMethod getKeyEncapsulation() {
359-
return BuiltinKEM.sntrup761;
360-
}
361-
362-
@Override
363-
public Digest getHash() throws Exception {
364-
return BuiltinDigests.sha512.create();
365-
}
366-
};
341+
public AbstractDH create(Object... params) throws Exception {
342+
return sntrup761x25519.create(params);
367343
}
368344

369345
@Override
370346
public boolean isSupported() {
371-
return MontgomeryCurve.x25519.isSupported() && BuiltinDigests.sha512.isSupported()
372-
&& BuiltinKEM.sntrup761.isSupported();
347+
return sntrup761x25519.isSupported();
373348
}
374349
};
375350

@@ -547,10 +522,10 @@ public static final class Constants {
547522
public static final String ECDH_SHA2_NISTP384 = "ecdh-sha2-nistp384";
548523
public static final String ECDH_SHA2_NISTP521 = "ecdh-sha2-nistp521";
549524
public static final String CURVE25519_SHA256 = "curve25519-sha256";
550-
public static final String CURVE25519_SHA256_LIBSSH = "curve25519-sha256@libssh.org";
525+
public static final String CURVE25519_SHA256_LIBSSH = CURVE25519_SHA256 + "@libssh.org";
551526
public static final String CURVE448_SHA512 = "curve448-sha512";
552527
public static final String SNTRUP761_25519_SHA512 = "sntrup761x25519-sha512";
553-
public static final String SNTRUP761_25519_SHA512_OPENSSH = "sntrup761x25519-sha512@openssh.com";
528+
public static final String SNTRUP761_25519_SHA512_OPENSSH = SNTRUP761_25519_SHA512 + "@openssh.com";
554529

555530
private Constants() {
556531
throw new UnsupportedOperationException("No instance allowed");

0 commit comments

Comments
 (0)