0

We need a method to sign messages using signatures that are as short as possible and came across the BLS scheme, which promises rather short-ish signatures. Trying the JPBC implementation, the examples are easy to set up and run, but they lack a rather crucial part: storing and loading the private keys.

  • The example from the current JPBC BLS website 1 does not contain any storage whatsoever, it just verifies a message using the instances in RAM.
  • An older example from the same website 2 which is no longer linked on the website but can be found using search engines refers to a store method which seems to have since been removed from the library in favour of an implementation that does not contain any storage capabilities.
  • The AsymmetricCipherKeyPair instances (which are what I get from the keygen) are not serializable by themselves, neither are instances of BLS01PublicKeyParameters or BLS01PrivateKeyParameters, with the fields that contain the keys (sk and pk) being private and typed only to the Element interface that doesn't really say much about the contents.

As a workaround, I have implemented a store method, that (stripped of all exception handling) roughly looks like this:

public static void storePrivateKey(AsymmetricCipherKeyPair key, String filename)
        throws FileNotFoundException, IOException {
    Field f = null;
    f = key.getPrivate().getClass().getDeclaredField("sk");
    if (f != null) {
        f.setAccessible(true);
        Object fieldContent = null;
        fieldContent = f.get(key.getPrivate());
        if (fieldContent != null) {
            byte[] data = null;
            if (fieldContent instanceof ImmutableZrElement) {
                ImmutableZrElement izr = (ImmutableZrElement)fieldContent;
                data = izr.toBytes();
            }
            try (FileOutputStream fos = new FileOutputStream(filename)) {
                fos.write(data);
            }
        }
    }
}

With a similar approach for public keys. That means, I'm now down to using reflection to retrieve the contents of a private field in order to store it somewhere. That solution is obviously a hackish collection of all sorts of bad smells, but it's so far the best that I've come up with. I know that writing some bytes to disk shouldn't really be that hard, but I really can't seem to find the proper way to do this. Also, to be blunt, I'm not into crypto: I want to apply this scheme to sign and verify some messages, that is all. I understand that I should dig deeper into the math of the whole approach, but time is limited - which is why I picked a library in the first place.

Slaw
  • 37,820
  • 8
  • 53
  • 80
Eadilu
  • 91
  • 1
  • 5

0 Answers0