Beispiel #1
0
        //public override byte[] writeToByteArray()
        //{
        //    var bs = new BitStream();
        //    bs.writeMessageType(MessageType.MULT_STEP_BCASE);
        //    writeToBitStreamNoHeader(bs);
        //    bs.close();
        //    return bs.ByteArray;
        //}

        //public override void writeToBitStreamNoHeader(BitStream bs)
        //{
        //    writeSecret(bs, aShare);
        //    writeSecret(bs, bShare);
        //    writeSecret(bs, abShare);
        //    writeSecret(bs, rShare);
        //}

        //public static MultStepBCaseShare readFromBitStreamNoHeader(BitStream bs, int prime)
        //{
        //    var multStepBCaseShare = new MultStepBCaseShare();
        //    multStepBCaseShare.loadFromByteArrayNoHeader(bs, prime);
        //    return multStepBCaseShare;
        //}

        //public override void loadFromByteArrayNoHeader(BitStream bs, int prime)
        //{
        //    aShare = readSecret(bs, prime);
        //    bShare = readSecret(bs, prime);
        //    abShare = readSecret(bs, prime);
        //    rShare = readSecret(bs, prime);
        //}

        //private void writeSecret(BitStream bs, Zp secret)
        //{
        //    bs.writeBoolean(secret != null);
        //    if (secret != null)
        //        bs.writeInt(secret.Value, BitStream.LENGTH_OF_SECRET);
        //}

        //private Zp readSecret(BitStream bs, int prime)
        //{
        //    if (bs.readBoolean())
        //        return new Zp(prime, bs.readInt(BitStream.LENGTH_OF_SECRET));
        //    else
        //        return null;
        //}

        //public override bool Equals(object obj)
        //{
        //    if (!(obj is MultStepBCaseShare))
        //        return false;
        //    MultStepBCaseShare second = (MultStepBCaseShare)obj;
        //    return compareSecrets(aShare, second.aShare) && compareSecrets(bShare, second.bShare) && compareSecrets(abShare, second.abShare) && compareSecrets(rShare, second.rShare);
        //}

        public static MultStepBCaseShare createRandom(int prime)         //for testing
        {
            double d = (new Random(1)).NextDouble();

            if (d < 0.25)
            {
                return(null);
            }
            var multStepBCaseShare = new MultStepBCaseShare();

            multStepBCaseShare.AShare  = new Zp(prime, (int)Math.Floor(d * 20));
            multStepBCaseShare.BShare  = new Zp(prime, (int)Math.Floor(d * 40));
            multStepBCaseShare.AbShare = new Zp(prime, (int)Math.Floor(d * 60));
            multStepBCaseShare.RShare  = new Zp(prime, (int)Math.Floor(d * 80));
            return(multStepBCaseShare);
        }
Beispiel #2
0
 //for testing
 //public override byte[] writeToByteArray()
 //{
 //    var bs = new BitStream();
 //    bs.writeMessageType(MessageType.MULT_STEP_BCASE);
 //    writeToBitStreamNoHeader(bs);
 //    bs.close();
 //    return bs.ByteArray;
 //}
 //public override void writeToBitStreamNoHeader(BitStream bs)
 //{
 //    writeSecret(bs, aShare);
 //    writeSecret(bs, bShare);
 //    writeSecret(bs, abShare);
 //    writeSecret(bs, rShare);
 //}
 //public static MultStepBCaseShare readFromBitStreamNoHeader(BitStream bs, int prime)
 //{
 //    var multStepBCaseShare = new MultStepBCaseShare();
 //    multStepBCaseShare.loadFromByteArrayNoHeader(bs, prime);
 //    return multStepBCaseShare;
 //}
 //public override void loadFromByteArrayNoHeader(BitStream bs, int prime)
 //{
 //    aShare = readSecret(bs, prime);
 //    bShare = readSecret(bs, prime);
 //    abShare = readSecret(bs, prime);
 //    rShare = readSecret(bs, prime);
 //}
 //private void writeSecret(BitStream bs, Zp secret)
 //{
 //    bs.writeBoolean(secret != null);
 //    if (secret != null)
 //        bs.writeInt(secret.Value, BitStream.LENGTH_OF_SECRET);
 //}
 //private Zp readSecret(BitStream bs, int prime)
 //{
 //    if (bs.readBoolean())
 //        return new Zp(prime, bs.readInt(BitStream.LENGTH_OF_SECRET));
 //    else
 //        return null;
 //}
 //public override bool Equals(object obj)
 //{
 //    if (!(obj is MultStepBCaseShare))
 //        return false;
 //    MultStepBCaseShare second = (MultStepBCaseShare)obj;
 //    return compareSecrets(aShare, second.aShare) && compareSecrets(bShare, second.bShare) && compareSecrets(abShare, second.abShare) && compareSecrets(rShare, second.rShare);
 //}
 public static MultStepBCaseShare createRandom(int prime)
 {
     double d = (new Random(1)).NextDouble();
     if (d < 0.25)
         return null;
     var multStepBCaseShare = new MultStepBCaseShare();
     multStepBCaseShare.AShare = new Zp(prime, (int)Math.Floor(d * 20));
     multStepBCaseShare.BShare = new Zp(prime, (int)Math.Floor(d * 40));
     multStepBCaseShare.AbShare = new Zp(prime, (int)Math.Floor(d * 60));
     multStepBCaseShare.RShare = new Zp(prime, (int)Math.Floor(d * 80));
     return multStepBCaseShare;
 }
Beispiel #3
0
 private bool IsRecvShareLegal(MultStepBCaseShare recvShareFromPlayer)
 {
     if ((recvShareFromPlayer == null) ||
         (recvShareFromPlayer.AShare == null) ||
         (recvShareFromPlayer.BShare == null) ||
         (recvShareFromPlayer.AbShare == null) ||
         (recvShareFromPlayer.RShare == null))
         return false;
     return true;
 }
Beispiel #4
0
        private bool IsMultStepShareLegal(MultStepBCaseShare recvShareFromPlayer_i, MultStepVerificationPoly recvVerifcationPolynomial)
        {
            if (!IsRecvShareLegal(recvShareFromPlayer_i))
                return false;

            var RxPolynomial = recvVerifcationPolynomial.RxPolynomial;
            Zp Ratpoint0 = Zp.EvalutePolynomialAtPoint(RxPolynomial, new Zp(Prime, 0));
            if (!Ratpoint0.Equals(new Zp(Prime, 0)))
            {
                return false;
            }
            int w = NumTheoryUtils.GetFieldMinimumPrimitive(Prime);
            var w_InMyIndex = new Zp(Prime, NumTheoryUtils.ModPow(w, Party.Id, Prime));
            Zp RjFromPublicPolynomial = Zp.EvalutePolynomialAtPoint(RxPolynomial, w_InMyIndex);

            Zp temp = recvShareFromPlayer_i.AShare.ConstMul(recvShareFromPlayer_i.BShare).ConstSub(recvShareFromPlayer_i.AbShare);
            Zp RjFromRecvPrivateInfo = w_InMyIndex.ConstMul(recvShareFromPlayer_i.RShare).ConstAdd(temp);
            if (!RjFromPublicPolynomial.Equals(RjFromRecvPrivateInfo))
                return false;

            return true;
        }