etnt commented on code in PR #932:
URL: https://github.com/apache/mina-sshd/pull/932#discussion_r4336485701


##########
sshd-common/src/main/java/org/apache/sshd/common/util/security/mldsa/MLDSAUtils.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.util.security.mldsa;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.security.Key;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.X509EncodedKeySpec;
+import java.util.Arrays;
+import java.util.Objects;
+
+import org.apache.sshd.common.util.ValidateUtils;
+import org.apache.sshd.common.util.io.der.ASN1Object;
+import org.apache.sshd.common.util.io.der.DERParser;
+import org.apache.sshd.common.util.io.der.DERWriter;
+import org.apache.sshd.common.util.security.MLDSAParameterSets;
+import org.apache.sshd.common.util.security.SecurityUtils;
+
+/**
+ * Utilities to extract ML-DSA key bytes and construct keys using RFC 9881 
encodings.
+ *
+ * @see    <a href="https://www.rfc-editor.org/rfc/rfc9881";>RFC 9881</a>
+ * @author <a href="mailto:[email protected]";>Apache MINA SSHD Project</a>
+ */
+public final class MLDSAUtils {
+    private static final byte[] OID_PREFIX = { 0x60, (byte) 0x86, 0x48, 0x01, 
0x65, 0x03, 0x04, 0x03 };
+
+    private MLDSAUtils() {
+        throw new UnsupportedOperationException("No instance allowed");
+    }
+
+    /**
+     * Retrieves the parameter set of an ML-DSA key.
+     *
+     * @param  key                     the key
+     * @return                         the parameter set
+     * @throws InvalidKeySpecException if the key is not an ML-DSA key or its 
encoding is invalid
+     */
+    public static MLDSAParameterSets getParameters(Key key) throws 
InvalidKeySpecException {
+        Objects.requireNonNull(key, "No key provided");
+        MLDSAParameterSets named = 
MLDSAParameterSets.fromJceName(key.getAlgorithm());
+        if (named != null) {
+            return named;
+        }

Review Comment:
   for a recognised ML-DSA algorithm name, it now parses the key's encoding and 
throws if the OID disagrees with the name. It still returns the name-based 
parameters when the key has no encoding.



-- 
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