From f5b4a4f330ca2d93709ce26fa02f4e2cd4553a66 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Wed, 25 May 2022 14:54:21 +0200 Subject: [PATCH] fix typos --- .../main/java/im/status/keycard/applet/BLS.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/im/status/keycard/applet/BLS.java b/lib/src/main/java/im/status/keycard/applet/BLS.java index f277ab1..4ce7c3b 100644 --- a/lib/src/main/java/im/status/keycard/applet/BLS.java +++ b/lib/src/main/java/im/status/keycard/applet/BLS.java @@ -5,6 +5,9 @@ import java.security.DigestException; import java.security.MessageDigest; import org.bouncycastle.util.Arrays; +import org.bouncycastle.util.encoders.Hex; + +import im.status.keycard.globalplatform.Crypto; public class BLS { private BLS() {} @@ -143,7 +146,7 @@ public class BLS { byte[] uniformBytes = expandMessage(msg, DST, count * M * L); Fp[][] u = new Fp[count][M]; for (int i = 0; i < count; i++) { - for (int j = 0; i < M; j++) { + for (int j = 0; j < M; j++) { int off = (L * (j + (i * M))); u[i][j] = new Fp(Arrays.copyOfRange(uniformBytes, off, off + L)); } @@ -243,7 +246,7 @@ public class BLS { return new PointG2(numerator, y, denominator); } - static byte[] hash(byte[] msg) { + public static byte[] hash(byte[] msg) { Fp[][] u = hashToField(msg, 2); PointG2 q0 = isogenyMapG2(mapToCurveSimpleSWU9mod16(new Fp2(u[0][0], u[0][1]))); PointG2 q1 = isogenyMapG2(mapToCurveSimpleSWU9mod16(new Fp2(u[1][0], u[1][1]))); @@ -251,6 +254,11 @@ public class BLS { return r.toAffine().toByteArray(); } + public static void main(String[] args) { + Crypto.addBouncyCastleProvider(); + System.out.println(Hex.toHexString(BLS.hash(new byte[]{0x09}))); + } + static class Fp { final static BigInteger FP = new BigInteger(new byte[] { (byte) 0x1a, (byte) 0x01, (byte) 0x11, (byte) 0xea, (byte) 0x39, (byte) 0x7f, (byte) 0xe6, (byte) 0x9a, @@ -382,7 +390,7 @@ public class BLS { Fp2 pow(BigInteger n) { if (n.signum() == 0) return Fp2.ONE; - if (n.intValueExact() == 1) return this; + if (n.equals(BigInteger.ONE)) return this; Fp2 p = Fp2.ONE; Fp2 d = this;