mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
When integers are converted to fixed length, ensure any padding is zero.
This commit is contained in:
@@ -17,7 +17,7 @@ class Sec1PrivateKey implements PrivateKey {
|
|||||||
public byte[] getEncoded() {
|
public byte[] getEncoded() {
|
||||||
byte[] encodedKey = new byte[bytesPerInt];
|
byte[] encodedKey = new byte[bytesPerInt];
|
||||||
byte[] d = key.getD().toByteArray();
|
byte[] d = key.getD().toByteArray();
|
||||||
Sec1Utils.convertToFixedLength(d, encodedKey, bytesPerInt, 0);
|
Sec1Utils.convertToFixedLength(d, encodedKey, 0, bytesPerInt);
|
||||||
return encodedKey;
|
return encodedKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ class Sec1PublicKey implements PublicKey {
|
|||||||
byte[] encodedKey = new byte[publicKeyBytes];
|
byte[] encodedKey = new byte[publicKeyBytes];
|
||||||
encodedKey[0] = 4;
|
encodedKey[0] = 4;
|
||||||
byte[] x = key.getQ().getX().toBigInteger().toByteArray();
|
byte[] x = key.getQ().getX().toBigInteger().toByteArray();
|
||||||
Sec1Utils.convertToFixedLength(x, encodedKey, bytesPerInt, 1);
|
Sec1Utils.convertToFixedLength(x, encodedKey, 1, bytesPerInt);
|
||||||
byte[] y = key.getQ().getY().toBigInteger().toByteArray();
|
byte[] y = key.getQ().getY().toBigInteger().toByteArray();
|
||||||
Sec1Utils.convertToFixedLength(y, encodedKey, bytesPerInt,
|
Sec1Utils.convertToFixedLength(y, encodedKey, 1 + bytesPerInt,
|
||||||
1 + bytesPerInt);
|
bytesPerInt);
|
||||||
return encodedKey;
|
return encodedKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ package org.briarproject.crypto;
|
|||||||
|
|
||||||
class Sec1Utils {
|
class Sec1Utils {
|
||||||
|
|
||||||
static void convertToFixedLength(byte[] src, byte[] dest, int destLen,
|
static void convertToFixedLength(byte[] src, byte[] dest, int destOff,
|
||||||
int destOff) {
|
int destLen) {
|
||||||
if(src.length < destLen) {
|
if(src.length < destLen) {
|
||||||
destOff += destLen - src.length;
|
int padding = destLen - src.length;
|
||||||
System.arraycopy(src, 0, dest, destOff, src.length);
|
for(int i = destOff; i < destOff + padding; i++) dest[i] = 0;
|
||||||
|
System.arraycopy(src, 0, dest, destOff + padding, src.length);
|
||||||
} else {
|
} else {
|
||||||
int srcOff = src.length - destLen;
|
int srcOff = src.length - destLen;
|
||||||
System.arraycopy(src, srcOff, dest, destOff, destLen);
|
System.arraycopy(src, srcOff, dest, destOff, destLen);
|
||||||
|
|||||||
Reference in New Issue
Block a user