tomaswolf commented on a change in pull request #177:
URL: https://github.com/apache/mina-sshd/pull/177#discussion_r744308139



##########
File path: 
sshd-core/src/main/java/org/apache/sshd/common/kex/MontgomeryCurve.java
##########
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sshd.common.kex;
+
+import java.io.IOException;
+import java.io.StreamCorruptedException;
+import java.io.UncheckedIOException;
+import java.security.GeneralSecurityException;
+import java.security.InvalidKeyException;
+import java.security.KeyFactory;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.PublicKey;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.X509EncodedKeySpec;
+
+import javax.crypto.KeyAgreement;
+
+import org.apache.sshd.common.OptionalFeature;
+import org.apache.sshd.common.digest.BuiltinDigests;
+import org.apache.sshd.common.digest.Digest;
+import org.apache.sshd.common.digest.DigestFactory;
+import org.apache.sshd.common.keyprovider.KeySizeIndicator;
+import org.apache.sshd.common.util.io.der.ASN1Object;
+import org.apache.sshd.common.util.io.der.DERParser;
+import org.apache.sshd.common.util.security.SecurityUtils;
+
+/**
+ * Provides implementation details for Montgomery curves and their key 
exchange algorithms Curve25519/X25519 and
+ * Curve448/X448 specified in RFC 7748 and RFC 8731. Montgomery curves provide 
improved security and flexibility over
+ * Weierstrass curves used in ECDH.
+ *
+ * @see <a href="https://www.rfc-editor.org/info/rfc7748";>RFC 7748</a>
+ * @see <a href="https://www.rfc-editor.org/info/rfc8731";>RFC 8731</a>
+ */
+public enum MontgomeryCurve implements KeySizeIndicator, OptionalFeature {
+
+    /**
+     * X25519 uses Curve25519 and SHA-256 with a 32-byte key size.
+     */
+    x25519("X25519", 32, BuiltinDigests.sha256,
+           new byte[] { 0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 
0x03, 0x21, 0x00 }),

Review comment:
       Added comments in the source explaining what these magic constants are. 
(Beginning of a X.509 DER encoding for x25519 or x448 public key 
SubjectPublicKeyInfo.) We might know it now, but someone else looking at this a 
few years down the road might not.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to