-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from cryptimeleon/develop
Merge into main for Release 4.0.0
- Loading branch information
Showing
77 changed files
with
7,203 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/org/cryptimeleon/craco/commitment/CommitmentKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.cryptimeleon.craco.commitment; | ||
|
||
import org.cryptimeleon.math.hash.UniqueByteRepresentable; | ||
import org.cryptimeleon.math.serialization.Representable; | ||
|
||
/** | ||
* Commitment key used to commit to messages | ||
*/ | ||
public interface CommitmentKey extends Representable, UniqueByteRepresentable { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/org/cryptimeleon/craco/sig/ecdsa/ECDSASignature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.cryptimeleon.craco.sig.ecdsa; | ||
|
||
import org.cryptimeleon.craco.sig.Signature; | ||
import org.cryptimeleon.math.serialization.ByteArrayRepresentation; | ||
import org.cryptimeleon.math.serialization.Representation; | ||
import org.cryptimeleon.math.serialization.StandaloneRepresentable; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* Class for a signature of the {@link ECDSASignatureScheme}. | ||
*/ | ||
public class ECDSASignature implements Signature, StandaloneRepresentable { | ||
|
||
final byte[] bytes; | ||
|
||
public ECDSASignature(byte[] signatureBytes) { | ||
this.bytes = signatureBytes; | ||
} | ||
|
||
public ECDSASignature(Representation repr) { | ||
this.bytes = ((ByteArrayRepresentation) repr).get(); | ||
} | ||
|
||
|
||
@Override | ||
public Representation getRepresentation() { | ||
return new ByteArrayRepresentation(bytes); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ECDSASignature that = (ECDSASignature) o; | ||
return Arrays.equals(bytes, that.bytes); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.hashCode(bytes); | ||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
src/main/java/org/cryptimeleon/craco/sig/ecdsa/ECDSASignatureScheme.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package org.cryptimeleon.craco.sig.ecdsa; | ||
|
||
import org.cryptimeleon.craco.common.ByteArrayImplementation; | ||
import org.cryptimeleon.craco.common.plaintexts.MessageBlock; | ||
import org.cryptimeleon.craco.common.plaintexts.PlainText; | ||
import org.cryptimeleon.craco.sig.SignatureKeyPair; | ||
import org.cryptimeleon.craco.sig.SignatureScheme; | ||
import org.cryptimeleon.craco.sig.SigningKey; | ||
import org.cryptimeleon.craco.sig.VerificationKey; | ||
import org.cryptimeleon.math.serialization.Representation; | ||
import org.cryptimeleon.math.serialization.StringRepresentation; | ||
|
||
import java.security.*; | ||
import java.security.spec.ECGenParameterSpec; | ||
import java.util.Objects; | ||
|
||
|
||
/** | ||
* Cryptimeleon wrapper for the ECDSA signature scheme. | ||
* Uses the curve and algorithms specified in the constants below. | ||
*/ | ||
public class ECDSASignatureScheme implements SignatureScheme { | ||
|
||
static final String ALGORITHM = "EC"; | ||
static final String CURVE = "secp256k1"; | ||
private static final String SIGNING_ALGORITHM = "SHA256withECDSA"; | ||
private final Signature signer; | ||
|
||
public ECDSASignatureScheme() { | ||
try { | ||
signer = Signature.getInstance(SIGNING_ALGORITHM); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public SignatureKeyPair<ECDSAVerificationKey, ECDSASigningKey> generateKeyPair() { | ||
try { | ||
ECGenParameterSpec ecSpec = new ECGenParameterSpec(CURVE); | ||
KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM); | ||
keyGen.initialize(ecSpec); | ||
KeyPair keyPair = keyGen.generateKeyPair(); | ||
return new SignatureKeyPair<>(new ECDSAVerificationKey(keyPair.getPublic()), new ECDSASigningKey(keyPair.getPrivate())); | ||
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException e) { | ||
e.printStackTrace(); | ||
throw new RuntimeException(e); | ||
} | ||
|
||
} | ||
|
||
|
||
@Override | ||
public org.cryptimeleon.craco.sig.Signature sign(PlainText plainText, SigningKey secretKey) { | ||
ECDSASigningKey ecdsaSigningKey = (ECDSASigningKey) secretKey; | ||
|
||
try { | ||
signer.initSign(ecdsaSigningKey.getKey()); | ||
signer.update(plainText.getUniqueByteRepresentation()); | ||
return new ECDSASignature(signer.sign()); | ||
} catch (InvalidKeyException e ) { | ||
e.printStackTrace(); | ||
throw new IllegalArgumentException("Input secretKey must a valid " + ALGORITHM + " secret key"); | ||
} catch (SignatureException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public Boolean verify(PlainText plainText, org.cryptimeleon.craco.sig.Signature signature, VerificationKey publicKey) { | ||
ECDSAVerificationKey ecdsaVerificationKey = (ECDSAVerificationKey) publicKey; | ||
ECDSASignature ecdsaSignature = (ECDSASignature) signature; | ||
|
||
try { | ||
signer.initVerify(ecdsaVerificationKey.getKey()); | ||
signer.update(plainText.getUniqueByteRepresentation()); | ||
return signer.verify(ecdsaSignature.bytes); | ||
} catch (InvalidKeyException e ) { | ||
e.printStackTrace(); | ||
throw new IllegalArgumentException("Input publicKey must a valid " + ALGORITHM + " public key"); | ||
} catch (SignatureException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public PlainText restorePlainText(Representation repr) { | ||
return new MessageBlock(repr, ByteArrayImplementation::new); | ||
} | ||
|
||
@Override | ||
public org.cryptimeleon.craco.sig.Signature restoreSignature(Representation repr) { | ||
return new ECDSASignature(repr); | ||
} | ||
|
||
@Override | ||
public SigningKey restoreSigningKey(Representation repr) { | ||
return new ECDSASigningKey(repr); | ||
} | ||
|
||
@Override | ||
public VerificationKey restoreVerificationKey(Representation repr) { | ||
return new ECDSAVerificationKey(repr); | ||
} | ||
|
||
@Override | ||
public PlainText mapToPlaintext(byte[] bytes, VerificationKey pk) { | ||
return new ByteArrayImplementation(bytes); | ||
} | ||
|
||
@Override | ||
public PlainText mapToPlaintext(byte[] bytes, SigningKey sk) { | ||
return new ByteArrayImplementation(bytes); | ||
} | ||
|
||
@Override | ||
public int getMaxNumberOfBytesForMapToPlaintext() { | ||
return Integer.MAX_VALUE; | ||
} | ||
|
||
@Override | ||
public Representation getRepresentation() { | ||
return new StringRepresentation(""); | ||
} | ||
|
||
/* | ||
* We need equals, hashcode and the Representation constructor to satisfy the SignatureScheme bounds for automated tests | ||
* All instances of ECDSASignatureSchemer are 'equal'. | ||
*/ | ||
|
||
public ECDSASignatureScheme(Representation repr) { | ||
this(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
return o != null && getClass() == o.getClass(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(19817349853L); | ||
} | ||
} |
Oops, something went wrong.