add bit if X is odd in ed25519 public key writing

This commit is contained in:
Jörg Prante 2024-05-29 13:19:34 +02:00
parent bac77bbd0f
commit 4c66383a05
3 changed files with 15 additions and 4 deletions

View file

@ -24,7 +24,7 @@ public class SftpWithPrivateKeyReaderTest {
public void testXbib() throws Exception { public void testXbib() throws Exception {
Map<String, String> env = new HashMap<>(); Map<String, String> env = new HashMap<>();
env.put("username", "joerg"); env.put("username", "joerg");
URI uri = URI.create("sftp://xbib.org"); URI uri = URI.create("sftp://alkmene");
try (SshClient sshClient = ClientBuilder.builder() try (SshClient sshClient = ClientBuilder.builder()
.build()) { .build()) {
sshClient.setNioWorkers(1); sshClient.setNioWorkers(1);

View file

@ -5,6 +5,14 @@ public class ArrayUtil {
private ArrayUtil() { private ArrayUtil() {
} }
public static String toHex(byte[] data) {
StringBuilder sb = new StringBuilder();
for (byte b : data) {
sb.append(Character.forDigit((b & 240) >> 4, 16)).append(Character.forDigit((b & 15), 16));
}
return sb.toString();
}
public static void reverse(byte[] arr) { public static void reverse(byte[] arr) {
int i = 0; int i = 0;
int j = arr.length - 1; int j = arr.length - 1;

View file

@ -919,9 +919,12 @@ public abstract class Buffer implements Readable {
putBytes(cert.getSignature()); putBytes(cert.getSignature());
} }
case EdECPublicKey edECPublicKey -> { case EdECPublicKey edECPublicKey -> {
byte[] b = edECPublicKey.getPoint().getY().toByteArray(); byte[] arr = edECPublicKey.getPoint().getY().toByteArray();
ArrayUtil.reverse(b); ArrayUtil.reverse(arr);
putBytes(b); if (edECPublicKey.getPoint().isXOdd()) {
arr[arr.length - 1] |= (byte) 0x80;
}
putBytes(arr);
} }
default -> throw new BufferException("Unsupported raw public key algorithm: " + key.getAlgorithm()); default -> throw new BufferException("Unsupported raw public key algorithm: " + key.getAlgorithm());
} }