add bit if X is odd in ed25519 public key writing

main
Jörg Prante 1 month ago
parent bac77bbd0f
commit 4c66383a05

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

@ -5,6 +5,14 @@ public class 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) {
int i = 0;
int j = arr.length - 1;

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

Loading…
Cancel
Save