// Path: wallet_lib/src/main/java/de/uni_bonn/bit/wallet_protocol/EncryptedSignatureWithProof.java
// public class EncryptedSignatureWithProof {
// 
//     @Stringable
//     private BigInteger sigma;
//     @Stringable
//     private BigInteger alphaPhone;
//     private ZKProofPhone proof;
// 
//     public EncryptedSignatureWithProof(){}
// 
//     public EncryptedSignatureWithProof(BigInteger sigma, BigInteger alphaPhone, ZKProofPhone proof) {
//         this.sigma = sigma;
//         this.alphaPhone = alphaPhone;
//         this.proof = proof;
//     }
// 
//     public BigInteger getSigma() {
//         return sigma;
//     }
// 
//     public BigInteger getAlphaPhone() {
//         return alphaPhone;
//     }
// 
//     public ZKProofPhone getProof() {
//         return proof;
//     }
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/wallet_protocol/EphemeralPublicValueWithProof.java
// public class EphemeralPublicValueWithProof {
//     private byte[] R;
//     private ZKProofDesktop proof;
// 
//     private EphemeralPublicValueWithProof(){ }
// 
//     public EphemeralPublicValueWithProof(ECPoint R, ZKProofDesktop proof) {
//         this.R = R.getEncoded(true);
//         this.proof = proof;
//     }
// 
//     public ECPoint getR() {
//         return ECKey.CURVE.getCurve().decodePoint(this.R);
//     }
// 
//     public ZKProofDesktop getProof() {
//         return proof;
//     }
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/wallet_protocol/EphemeralValueShare.java
// public class EphemeralValueShare {
//     private byte[] RPhone;
// 
// 
//     private EphemeralValueShare(){ }
// 
//     public EphemeralValueShare(ECPoint RPhone){
//         setRPhone(RPhone);
//     }
// 
//     public ECPoint getRPhone() {
//         return ECKey.CURVE.getCurve().decodePoint(this.RPhone);
//     }
// 
//     public void setRPhone(ECPoint RPhone) {
//         this.RPhone = RPhone.getEncoded(true);
//     }
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/wallet_protocol/SignatureParts.java
// public class SignatureParts {
// 
//     @Stringable
//     BigInteger alphaDesktop;
//     @Stringable
//     BigInteger beta;
// 
//     public SignatureParts() {}
//     public SignatureParts(BigInteger alphaDesktop, BigInteger beta) {
//         this.alphaDesktop = alphaDesktop;
//         this.beta = beta;
//     }
// 
//     public BigInteger getAlphaDesktop() {
//         return alphaDesktop;
//     }
// 
//     public void setAlphaDesktop(BigInteger alphaDesktop) {
//         this.alphaDesktop = alphaDesktop;
//     }
// 
//     public BigInteger getBeta() {
//         return beta;
//     }
// 
//     public void setBeta(BigInteger beta) {
//         this.beta = beta;
//     }
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/BitcoinECMathHelper.java
// public static ECKey convertPointToPubKEy(ECPoint point){
//     return ECKey.fromPublicOnly(point);
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/BitcoinECMathHelper.java
// public static BigInteger convertPrivKeyToBigInt(ECKey ecKey){
//     checkArgument(ecKey.hasPrivKey(), "Private key expected, but ecKey only contains a public key.");
//     return new BigInteger(1, ecKey.getPrivKeyBytes());
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/BitcoinECMathHelper.java
// public static ECPoint convertPubKeyToPoint(ECKey ecKey){
//     return ECKey.CURVE.getCurve().decodePoint(ecKey.getPubKey()).normalize();
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/BitcoinECMathHelper.java
// public static ECKey convertBigIntToPrivKey(BigInteger bigInt){
//     checkArgument(bigInt.compareTo(BigInteger.ONE) >= 0, "A private key must be >= 1");
//     checkArgument(bigInt.compareTo(ECKey.CURVE.getN()) < 0, "A private key must be <= N_EC");
//     return ECKey.fromPrivate(bigInt);
// }


import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.Sha256Hash;
import com.google.common.collect.Lists;
import com.google.common.math.DoubleMath;
import de.uni_bonn.bit.wallet_protocol.EncryptedSignatureWithProof;
import de.uni_bonn.bit.wallet_protocol.EphemeralPublicValueWithProof;
import de.uni_bonn.bit.wallet_protocol.EphemeralValueShare;
import de.uni_bonn.bit.wallet_protocol.SignatureParts;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.spongycastle.math.ec.ECPoint;
import org.spongycastle.pqc.math.linearalgebra.IntegerFunctions;
import java.math.BigInteger;
import java.util.List;
import static de.uni_bonn.bit.BitcoinECMathHelper.convertPointToPubKEy;
import static de.uni_bonn.bit.BitcoinECMathHelper.convertPrivKeyToBigInt;
import static de.uni_bonn.bit.BitcoinECMathHelper.convertPubKeyToPoint;
import static de.uni_bonn.bit.BitcoinECMathHelper.convertBigIntToPrivKey;
/*
* Copyright 2014 Christopher Mann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.uni_bonn.bit;




/**
 * This class contains the implementations of two basic attacks on the two-party ECDSA signature protocol. The attacks
 * must not succeed if the protocol is correctly implemented.
 */
public class ProtocolAttackTest {

    ECKey desktopKeyShare = convertBigIntToPrivKey(new BigInteger("41"));
    ECKey phoneKeyShare = convertBigIntToPrivKey(new BigInteger("42"));

    ECKey commonPublicKey;
    BCParameters desktopBCParameters;
    BCParameters phoneBCParameters;

    @Before
    public void setUp() {
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/wallet_protocol/EncryptedSignatureWithProof.java
// public class EncryptedSignatureWithProof {
// 
//     @Stringable
//     private BigInteger sigma;
//     @Stringable
//     private BigInteger alphaPhone;
//     private ZKProofPhone proof;
// 
//     public EncryptedSignatureWithProof(){}
// 
//     public EncryptedSignatureWithProof(BigInteger sigma, BigInteger alphaPhone, ZKProofPhone proof) {
//         this.sigma = sigma;
//         this.alphaPhone = alphaPhone;
//         this.proof = proof;
//     }
// 
//     public BigInteger getSigma() {
//         return sigma;
//     }
// 
//     public BigInteger getAlphaPhone() {
//         return alphaPhone;
//     }
// 
//     public ZKProofPhone getProof() {
//         return proof;
//     }
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/wallet_protocol/EphemeralPublicValueWithProof.java
// public class EphemeralPublicValueWithProof {
//     private byte[] R;
//     private ZKProofDesktop proof;
// 
//     private EphemeralPublicValueWithProof(){ }
// 
//     public EphemeralPublicValueWithProof(ECPoint R, ZKProofDesktop proof) {
//         this.R = R.getEncoded(true);
//         this.proof = proof;
//     }
// 
//     public ECPoint getR() {
//         return ECKey.CURVE.getCurve().decodePoint(this.R);
//     }
// 
//     public ZKProofDesktop getProof() {
//         return proof;
//     }
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/wallet_protocol/EphemeralValueShare.java
// public class EphemeralValueShare {
//     private byte[] RPhone;
// 
// 
//     private EphemeralValueShare(){ }
// 
//     public EphemeralValueShare(ECPoint RPhone){
//         setRPhone(RPhone);
//     }
// 
//     public ECPoint getRPhone() {
//         return ECKey.CURVE.getCurve().decodePoint(this.RPhone);
//     }
// 
//     public void setRPhone(ECPoint RPhone) {
//         this.RPhone = RPhone.getEncoded(true);
//     }
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/wallet_protocol/SignatureParts.java
// public class SignatureParts {
// 
//     @Stringable
//     BigInteger alphaDesktop;
//     @Stringable
//     BigInteger beta;
// 
//     public SignatureParts() {}
//     public SignatureParts(BigInteger alphaDesktop, BigInteger beta) {
//         this.alphaDesktop = alphaDesktop;
//         this.beta = beta;
//     }
// 
//     public BigInteger getAlphaDesktop() {
//         return alphaDesktop;
//     }
// 
//     public void setAlphaDesktop(BigInteger alphaDesktop) {
//         this.alphaDesktop = alphaDesktop;
//     }
// 
//     public BigInteger getBeta() {
//         return beta;
//     }
// 
//     public void setBeta(BigInteger beta) {
//         this.beta = beta;
//     }
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/BitcoinECMathHelper.java
// public static ECKey convertPointToPubKEy(ECPoint point){
//     return ECKey.fromPublicOnly(point);
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/BitcoinECMathHelper.java
// public static BigInteger convertPrivKeyToBigInt(ECKey ecKey){
//     checkArgument(ecKey.hasPrivKey(), "Private key expected, but ecKey only contains a public key.");
//     return new BigInteger(1, ecKey.getPrivKeyBytes());
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/BitcoinECMathHelper.java
// public static ECPoint convertPubKeyToPoint(ECKey ecKey){
//     return ECKey.CURVE.getCurve().decodePoint(ecKey.getPubKey()).normalize();
// }
// 
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/BitcoinECMathHelper.java
// public static ECKey convertBigIntToPrivKey(BigInteger bigInt){
//     checkArgument(bigInt.compareTo(BigInteger.ONE) >= 0, "A private key must be >= 1");
//     checkArgument(bigInt.compareTo(ECKey.CURVE.getN()) < 0, "A private key must be <= N_EC");
//     return ECKey.fromPrivate(bigInt);
// }


// Path: wallet_lib/src/test/java/de/uni_bonn/bit/ProtocolAttackTest.java
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.Sha256Hash;
import com.google.common.collect.Lists;
import com.google.common.math.DoubleMath;
import de.uni_bonn.bit.wallet_protocol.EncryptedSignatureWithProof;
import de.uni_bonn.bit.wallet_protocol.EphemeralPublicValueWithProof;
import de.uni_bonn.bit.wallet_protocol.EphemeralValueShare;
import de.uni_bonn.bit.wallet_protocol.SignatureParts;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.spongycastle.math.ec.ECPoint;
import org.spongycastle.pqc.math.linearalgebra.IntegerFunctions;
import java.math.BigInteger;
import java.util.List;
import static de.uni_bonn.bit.BitcoinECMathHelper.convertPointToPubKEy;
import static de.uni_bonn.bit.BitcoinECMathHelper.convertPrivKeyToBigInt;
import static de.uni_bonn.bit.BitcoinECMathHelper.convertPubKeyToPoint;
import static de.uni_bonn.bit.BitcoinECMathHelper.convertBigIntToPrivKey;

/*
* Copyright 2014 Christopher Mann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.uni_bonn.bit;




/**
 * This class contains the implementations of two basic attacks on the two-party ECDSA signature protocol. The attacks
 * must not succeed if the protocol is correctly implemented.
 */
public class ProtocolAttackTest {

    ECKey desktopKeyShare = convertBigIntToPrivKey(new BigInteger("41"));
    ECKey phoneKeyShare = convertBigIntToPrivKey(new BigInteger("42"));

    ECKey commonPublicKey;
    BCParameters desktopBCParameters;
    BCParameters phoneBCParameters;

    @Before
    public void setUp() {
        commonPublicKey = convertPointToPubKEy(