Commit e62461f2 authored by Gijs Van Laer's avatar Gijs Van Laer
Browse files

partially blind signatures

parent 6c765645
......@@ -21,10 +21,10 @@
*/
package edu.jhu.isi.CLSign;
import edu.jhu.isi.CLSign.entities.KeyPair;
import edu.jhu.isi.CLSign.entities.PublicKey;
import edu.jhu.isi.CLSign.entities.SecretKey;
import edu.jhu.isi.CLSign.entities.Signature;
import edu.jhu.isi.CLSign.keygen.KeyPair;
import edu.jhu.isi.CLSign.keygen.PublicKey;
import edu.jhu.isi.CLSign.keygen.SecretKey;
import edu.jhu.isi.CLSign.sign.Signature;
import edu.jhu.isi.CLSign.keygen.KeyGen;
import edu.jhu.isi.CLSign.sign.Sign;
import edu.jhu.isi.CLSign.verify.Verify;
......@@ -43,11 +43,17 @@ public class CLSign {
}
public static Element commit(final List<ZrElement> messages, final PublicKey pk) {
Element commitment = pk.getGenerator().powZn(messages.get(0));
for (int i = 1; i < messages.size(); i++) {
commitment = commitment.mul(pk.getZ(i).powZn(messages.get(i)));
if (messages.size() != pk.getZ().size()) {
throw new IllegalStateException("Public key should be generated with the correct message size");
}
return commitment.getImmutable();
return doCommit(messages, pk);
}
public static Element partialCommit(final List<ZrElement> messages, final PublicKey pk) {
if (messages.size() > pk.getZ().size()) {
throw new IllegalStateException("Public key should be generated with a larger message size");
}
return doCommit(messages, pk);
}
public static Signature sign(final List<ZrElement> messages, final KeyPair keys) {
......@@ -59,9 +65,27 @@ public class CLSign {
return Sign.sign(commitment, keys);
}
public static Signature signPartiallyBlind(final List<ZrElement> messages, final Element commitment, final KeyPair keys) {
final List<Element> Z = keys.getPk().getZ();
final List<Element> subKey = Z.subList(Z.size() - messages.size(), Z.size());
final Element extendCommitment = keys.getPk().getPairing().getG1().newOneElement();
for (int i = 0; i < messages.size(); i++) {
extendCommitment.mul(subKey.get(i).powZn(messages.get(i)));
}
return Sign.sign(commitment.mul(extendCommitment), keys);
}
public static boolean verify(final List<ZrElement> messages, final Signature sigma, final PublicKey pk) {
return Verify.aFormedCorrectly(sigma, pk)
&& Verify.bFormedCorrectly(sigma, pk)
&& Verify.cFormedCorrectly(messages, sigma, pk);
}
private static Element doCommit(final List<ZrElement> messages, final PublicKey pk) {
Element commitment = pk.getGenerator().powZn(messages.get(0));
for (int i = 1; i < messages.size(); i++) {
commitment = commitment.mul(pk.getZ(i).powZn(messages.get(i)));
}
return commitment.getImmutable();
}
}
package edu.jhu.isi.CLSign.keygen;
import edu.jhu.isi.CLSign.entities.PublicKey;
import edu.jhu.isi.CLSign.entities.SecretKey;
import it.unisa.dia.gas.jpbc.Element;
import it.unisa.dia.gas.jpbc.Pairing;
import it.unisa.dia.gas.jpbc.PairingParameters;
......
......@@ -19,7 +19,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package edu.jhu.isi.CLSign.entities;
package edu.jhu.isi.CLSign.keygen;
public class KeyPair {
......
......@@ -19,7 +19,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package edu.jhu.isi.CLSign.entities;
package edu.jhu.isi.CLSign.keygen;
import it.unisa.dia.gas.jpbc.Element;
import it.unisa.dia.gas.jpbc.Pairing;
......
......@@ -19,7 +19,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package edu.jhu.isi.CLSign.entities;
package edu.jhu.isi.CLSign.keygen;
import it.unisa.dia.gas.plaf.jpbc.field.z.ZrElement;
......
package edu.jhu.isi.CLSign.sign;
import edu.jhu.isi.CLSign.entities.KeyPair;
import edu.jhu.isi.CLSign.entities.PublicKey;
import edu.jhu.isi.CLSign.entities.SecretKey;
import edu.jhu.isi.CLSign.entities.Signature;
import edu.jhu.isi.CLSign.keygen.KeyPair;
import edu.jhu.isi.CLSign.keygen.PublicKey;
import edu.jhu.isi.CLSign.keygen.SecretKey;
import it.unisa.dia.gas.jpbc.Element;
import it.unisa.dia.gas.plaf.jpbc.field.z.ZrElement;
......
......@@ -19,7 +19,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package edu.jhu.isi.CLSign.entities;
package edu.jhu.isi.CLSign.sign;
import it.unisa.dia.gas.jpbc.Element;
......
package edu.jhu.isi.CLSign.verify;
import edu.jhu.isi.CLSign.entities.PublicKey;
import edu.jhu.isi.CLSign.entities.Signature;
import edu.jhu.isi.CLSign.keygen.PublicKey;
import edu.jhu.isi.CLSign.sign.Signature;
import it.unisa.dia.gas.jpbc.Element;
import it.unisa.dia.gas.jpbc.Pairing;
import it.unisa.dia.gas.plaf.jpbc.field.z.ZrElement;
......
package edu.jhu.isi.CLSign;
import edu.jhu.isi.CLSign.entities.KeyPair;
import edu.jhu.isi.CLSign.entities.PublicKey;
import edu.jhu.isi.CLSign.entities.SecretKey;
import edu.jhu.isi.CLSign.entities.Signature;
import edu.jhu.isi.CLSign.keygen.KeyPair;
import edu.jhu.isi.CLSign.keygen.PublicKey;
import edu.jhu.isi.CLSign.keygen.SecretKey;
import edu.jhu.isi.CLSign.sign.Signature;
import it.unisa.dia.gas.jpbc.Element;
import it.unisa.dia.gas.plaf.jpbc.field.z.ZrElement;
import org.junit.Test;
......@@ -103,4 +104,49 @@ public class CLSignTest {
final CLSign clSign = new CLSign();
assertNotNull(clSign);
}
@Test(expected = IllegalStateException.class)
public void testCommit_wrongMessageSize() throws Exception {
final int messageSize = 5;
final KeyPair keyPair = CLSign.keyGen(messageSize);
final List<ZrElement> messages = IntStream.range(0, messageSize + 1)
.mapToObj(i -> (ZrElement) keyPair.getPk().getPairing().getZr().newRandomElement().getImmutable())
.collect(Collectors.toList());
CLSign.commit(messages, keyPair.getPk());
}
@Test(expected = IllegalStateException.class)
public void testPartialCommit_wrongMessageSize() throws Exception {
final int messageSize = 5;
final KeyPair keyPair = CLSign.keyGen(messageSize);
final List<ZrElement> messages = IntStream.range(0, messageSize + 1)
.mapToObj(i -> (ZrElement) keyPair.getPk().getPairing().getZr().newRandomElement().getImmutable())
.collect(Collectors.toList());
CLSign.partialCommit(messages, keyPair.getPk());
}
@Test
public void testBlindSignature() throws Exception {
final int messageSize = 5;
final KeyPair keyPair = CLSign.keyGen(messageSize);
final List<ZrElement> messages = IntStream.range(0, messageSize)
.mapToObj(i -> (ZrElement) keyPair.getPk().getPairing().getZr().newRandomElement().getImmutable())
.collect(Collectors.toList());
final Element commitment = CLSign.commit(messages, keyPair.getPk());
final Signature sigma = CLSign.signBlind(commitment, keyPair);
assertTrue(CLSign.verify(messages, sigma, keyPair.getPk()));
}
@Test
public void testPartiallyBlindSignature() throws Exception {
final int messageSize = 5;
final KeyPair keyPair = CLSign.keyGen(messageSize);
final List<ZrElement> messages = IntStream.range(0, messageSize)
.mapToObj(i -> (ZrElement) keyPair.getPk().getPairing().getZr().newRandomElement().getImmutable())
.collect(Collectors.toList());
final Element partialCommitment = CLSign.partialCommit(messages.subList(0, messageSize - 2), keyPair.getPk());
final Signature sigma = CLSign.signPartiallyBlind(messages.subList(messageSize - 2, messageSize),
partialCommitment, keyPair);
assertTrue(CLSign.verify(messages, sigma, keyPair.getPk()));
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment