codahale / shamir

A Java implementation of Shamir's Secret Sharing algorithm over GF(256).
Apache License 2.0
207 stars 84 forks source link

Issue in combining the shares generated on iOS Platform #13 #2

Closed preetigaur closed 6 years ago

preetigaur commented 6 years ago

Hi

I've been trying to use this library to work with iOS. I keep facing an issue in combining the shares which are generated on iOS platform. Each share generated on iOS is an unsigned integer array, whereas in Java it's in form of signed bytes. I have been converting the unsigned integer array from iOS to signed bytes.

The Scheme.join() method works fine if I provide all the shares generated on iOS but fails if the number of shares are less than the total number number of shares.

public void testCrossPlatform() {
    String secretString = "Hi";
    final byte[] secret = secretString.getBytes(StandardCharsets.UTF_8);
    final Map<Integer, byte[]> parts = scheme.split(secret);

    HashMap<Integer, byte[]> allParts = new HashMap<>();
    allParts.put(1, new byte[]{(byte)43, (byte)9});
    allParts.put(2, new byte[]{(byte)37, (byte)145});
    allParts.put(3, new byte[]{(byte)70, (byte)241});

        HashMap<Integer, byte[]> halfParts = new HashMap<>();
    halfParts.put(1, new byte[]{(byte)43, (byte)9});
    halfParts.put(2, new byte[]{(byte)37, (byte)145});

    final byte[] recovered = scheme.join(halfParts);
    Log.d("msg", "Recovered String : " + new String(recovered,StandardCharsets.UTF_8));
}

I have been using this library in iOS.

Could you please help me with resolving the issue. Thanks in advance.

codahale commented 6 years ago

Off-hand, I’d say they’re probably generating a polynomial that’s a byte short, so their threshold is actually k+1, but I don’t know Swift so it’s hard for me to tell. Can you combine halfParts using that library?

preetigaur commented 6 years ago

Both the libraries are not able to combine the half parts generated from the other library but can combine all the parts

codahale commented 6 years ago

It sounds like either your threshold with the iOS app is too high (i.e. should be 2 but is 3) or the iOS library has a bug in it. If you determine that it’s a bug in this library, please open a new issue with a reproduction case.