diff options
| author | J08nY | 2017-11-26 23:50:00 +0100 |
|---|---|---|
| committer | J08nY | 2017-11-26 23:50:00 +0100 |
| commit | 7737039d8c1ad743ed1f5dc5e40224e297acd08d (patch) | |
| tree | 273d9e4895797c419a4a1fc26e489b2b0808fdf1 /src/cz/crcs/ectester/common/util/ECUtil.java | |
| parent | 83943c809c56c1856038b21fd91f50cc709310aa (diff) | |
| download | ECTester-7737039d8c1ad743ed1f5dc5e40224e297acd08d.tar.gz ECTester-7737039d8c1ad743ed1f5dc5e40224e297acd08d.tar.zst ECTester-7737039d8c1ad743ed1f5dc5e40224e297acd08d.zip | |
Diffstat (limited to 'src/cz/crcs/ectester/common/util/ECUtil.java')
| -rw-r--r-- | src/cz/crcs/ectester/common/util/ECUtil.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/cz/crcs/ectester/common/util/ECUtil.java b/src/cz/crcs/ectester/common/util/ECUtil.java new file mode 100644 index 0000000..713effe --- /dev/null +++ b/src/cz/crcs/ectester/common/util/ECUtil.java @@ -0,0 +1,37 @@ +package cz.crcs.ectester.common.util; + +import java.math.BigInteger; +import java.security.spec.ECPoint; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public class ECUtil { + public static byte[] toX962Compressed(ECPoint point) { + if (point.equals(ECPoint.POINT_INFINITY)) { + return new byte[]{0}; + } + byte[] x = point.getAffineX().toByteArray(); + byte marker = (byte) (0x02 | point.getAffineY().mod(BigInteger.valueOf(2)).byteValue()); + return ByteUtil.concatenate(new byte[]{marker}, x); + } + + public static byte[] toX962Uncompressed(ECPoint point) { + if (point.equals(ECPoint.POINT_INFINITY)) { + return new byte[]{0}; + } + byte[] x = point.getAffineX().toByteArray(); + byte[] y = point.getAffineY().toByteArray(); + return ByteUtil.concatenate(new byte[]{0x04}, x, y); + } + + public static byte[] toX962Hybrid(ECPoint point) { + if (point.equals(ECPoint.POINT_INFINITY)) { + return new byte[]{0}; + } + byte[] x = point.getAffineX().toByteArray(); + byte[] y = point.getAffineY().toByteArray(); + byte marker = (byte) (0x06 | point.getAffineY().mod(BigInteger.valueOf(2)).byteValue()); + return ByteUtil.concatenate(new byte[]{marker}, x, y); + } +} |
