Fixing issue #4 - leading zeroes must be omitted on writing the coordinate components
This commit is contained in:
parent
0566b27ce3
commit
effb2ac2fb
@ -28,6 +28,7 @@ import org.bouncycastle.crypto.paddings.PKCS7Padding;
|
|||||||
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
|
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
|
||||||
import org.bouncycastle.crypto.params.KeyParameter;
|
import org.bouncycastle.crypto.params.KeyParameter;
|
||||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||||
|
import org.bouncycastle.math.ec.ECFieldElement;
|
||||||
import org.bouncycastle.math.ec.ECPoint;
|
import org.bouncycastle.math.ec.ECPoint;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -152,16 +153,20 @@ public class CryptoBox implements Streamable {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeWithoutMAC(OutputStream stream) throws IOException {
|
private void writeWithoutMAC(OutputStream out) throws IOException {
|
||||||
stream.write(initializationVector);
|
out.write(initializationVector);
|
||||||
Encode.int16(curveType, stream);
|
Encode.int16(curveType, out);
|
||||||
byte[] x = R.getXCoord().getEncoded();
|
writeCoordinateComponent(out, R.getXCoord());
|
||||||
byte[] y = R.getYCoord().getEncoded();
|
writeCoordinateComponent(out, R.getYCoord());
|
||||||
Encode.int16(x.length, stream);
|
out.write(encrypted);
|
||||||
stream.write(x);
|
}
|
||||||
Encode.int16(y.length, stream);
|
|
||||||
stream.write(y);
|
private void writeCoordinateComponent(OutputStream out, ECFieldElement coord) throws IOException {
|
||||||
stream.write(encrypted);
|
byte[] x = coord.getEncoded();
|
||||||
|
int offset = Bytes.numberOfLeadingZeros(x);
|
||||||
|
int length = x.length - offset;
|
||||||
|
Encode.int16(length, out);
|
||||||
|
out.write(x, offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -31,9 +31,6 @@ import static ch.dissem.bitmessage.entity.Plaintext.Type.MSG;
|
|||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by chris on 28.04.15.
|
|
||||||
*/
|
|
||||||
public class SerializationTest {
|
public class SerializationTest {
|
||||||
@Test
|
@Test
|
||||||
public void ensureGetPubkeyIsDeserializedAndSerializedCorrectly() throws IOException {
|
public void ensureGetPubkeyIsDeserializedAndSerializedCorrectly() throws IOException {
|
||||||
|
Loading…
Reference in New Issue
Block a user