/// <summary>
 /// Deserialize.
 /// </summary>
 /// <param name="context"></param>
 public override void FinishDeserializing()
 {
     base.FinishDeserializing();
     if ((_witnesses != null) && (AreWitnessesSerializable))
     {
         if (this.AreWitnessBasesSerializable)
         {
             this.Witnesses = CryptoSerializer.Deserialize <DLRepOfGroupElement>(_witnesses, this.Group);
         }
         else
         {
             this.Witnesses = CryptoSerializer.Deserialize <DLRepOfGroupElement>(_witnesses, this.Group, this.Generators);
         }
     }
     if ((_publicValues != null) && ArePublicValuesSerializable)
     {
         this.PublicValues = CryptoSerializer.DeserializeGroupElementArray(_publicValues, "PublicValues", this.Group);
     }
     if ((this.PublicValues == null) && (this.Witnesses != null))
     {
         this.PublicValues = new GroupElement[this.Witnesses.Length];
         for (int i = 0; i < this.PublicValues.Length; ++i)
         {
             this.PublicValues[i] = this.Witnesses[i].Value;
         }
     }
 }
Example #2
0
        /// <summary>
        /// Serializes an array of IStatements.
        /// </summary>
        /// <param name="statements">statements</param>
        /// <param name="serializeGroup">If true, will serialize statements[0].Group.  If false, will  not serialize group.</param>
        /// <param name="serializeBases">If true, will serialize all bases.  If false, will not serialize bases.</param>
        /// <returns>Array of strings.  String[2i] is the serialized statement, String[2i+1] is the actual class name</returns>
        public static string[] Serialize(IStatement[] statements, bool serializeGroup = true, bool serializeBases = true)
        {
            string[] output = new string[statements.Length * 2];
            for (int i = 0; i < statements.Length; ++i)
            {
                if ((i == 0) && (serializeGroup))
                {
                    statements[i].IsGroupSerializable = true;
                }
                else
                {
                    statements[i].IsGroupSerializable = false;
                }

                if (serializeBases == true)
                {
                    statements[i].AreBasesSerializable = true;
                }
                else
                {
                    statements[i].AreBasesSerializable = false;
                }
                output[2 * i]     = CryptoSerializer.Serialize <IStatement>(statements[i]);
                output[2 * i + 1] = statements[i].GetType().FullName;
            }
            return(output);
        }
 internal void OnSerializing(StreamingContext context)
 {
     // serialize b, responseEqual, and responseUnequal
     this._b               = CryptoSerializer.SerializeGroupElementArray(b, "b");
     this._responseEqual   = CryptoSerializer.SerializeFieldZqElementArray(responseEqual, "responseEqual");
     this._responseUnequal = CryptoSerializer.SerializeFieldZqElementArray(responseUnequal, "responseUnequal");
 }
Example #4
0
 public void VerifierOnDeserialized(StreamingContext context)
 {
     if (this._closedEq == null)
     {
         return;
     }
     this.Statements = CryptoSerializer.Deserialize <IStatement>(_closedEq, this.Group);
 }
Example #5
0
 public void VerifierOnSerializing(StreamingContext context)
 {
     _closedEq = null;
     if (AreStatementsSerializable)
     {
         _closedEq = CryptoSerializer.Serialize(this.Statements, false, true);
     }
 }
Example #6
0
        public void ProverOnDeserialized(StreamingContext context)
        {
            this.Witnesses = (IWitness [])CryptoSerializer.Deserialize <IWitness>(_witnesses, this.Group);

            this.Statements = new IStatement[this.Witnesses.Length];
            for (int i = 0; i < Witnesses.Length; ++i)
            {
                this.Statements[i] = this.Witnesses[i].GetStatement();
            }
        }
 internal void OnVIPDeserialized(StreamingContext context)
 {
     if (this.CompareToKnownValue)
     {
         this.Value = CryptoSerializer.DeserializeFieldZqElement(this._value, this.Group);
     }
     else
     {
         this.Value = null;
     }
 }
        /// <summary>
        /// Finishes deserializing once json deserialization is complete.
        /// </summary>
        /// <param name="group">May be null. Used only if group was not serialized.</param>
        /// <param name="bases">May be null.  Used only if group was not serialized.</param>
        public void FinishDeserializing(Group group, GroupElement[] bases)
        {
            // get group
            if (this.Group == null)
            {
                if (group == null)
                {
                    throw new SerializationException("Cannot deserialize because serialized group and group argument are both null.");
                }
                this.Group = group;
            }

            // get value
            this.Value = CryptoSerializer.DeserializeGroupElement(_value, this.Group);

            // get bases
            if (this._bases == null)
            {
                if (bases == null)
                {
                    throw new SerializationException("Cannot deserialize because serialized bases and bases argument are both null.");
                }
                if (bases.Length == this._representationLength)
                {
                    this.Bases = bases;
                }
                else
                {
                    this.Bases = new GroupElement[this._representationLength];
                    for (int i = 0; i < this.Bases.Length; ++i)
                    {
                        this.Bases[i] = bases[i];
                    }
                }
            }
            else
            {
                this.Bases = CryptoSerializer.DeserializeGroupElementArray(this._bases, "bases", this.Group);
            }

            // get exponents
            if (this._exponents == null)
            {
                this.Exponents = null;
            }
            else
            {
                this.Exponents = CryptoSerializer.DeserializeFieldZqElementArray(this._exponents, "Exponents", this.Group);
                if (this.Exponents.Length != this.Bases.Length)
                {
                    throw new SerializationException("Cannot Deserialize. Must have equal number of exponents and bases.");
                }
            }
        }
        internal void OnSerializing(StreamingContext context)
        {
            // we assume that the arrays a, c, and r have the same length
            int length = a.Length;

            if (length - 1 != c.Length || length != r.Length)
            {
                throw new SerializationException("Arrays a and r must have the same length, while c must be one element shorter.");
            }
            _a = CryptoSerializer.SerializeGroupElementArray(this.a, "a");
            _c = CryptoSerializer.SerializeFieldZqElementArray(this.c, "c");
            _r = CryptoSerializer.SerializeFieldZqElementArray(this.r, "r");
        }
Example #10
0
        /// <summary>
        /// Deserialize A and B. Finish deserialing Proof.
        /// </summary>
        public override void FinishDeserializing()
        {
            GroupElement[] AB = CryptoSerializer.DeserializeGroupElementArray(this._AB, 0, 2, "AB", this.Group);
            this.A = AB[0];
            this.B = AB[1];

            if (this.Proof != null)
            {
                this.Proof.FinishDeserializing(this.Group);
            }
            if (this.UPIProof != null)
            {
                this.UPIProof.FinishDeserializing(this.Group);
            }
        }
        /// <summary>
        /// Deserialize a,c,r.
        /// </summary>
        public override void FinishDeserializing()
        {
            a = CryptoSerializer.DeserializeGroupElementArray(_a, "a", this.Group);
            c = CryptoSerializer.DeserializeFieldZqElementArray(_c, "c", this.Group);
            r = CryptoSerializer.DeserializeFieldZqElementArray(_r, "r", this.Group);

            if (a.Length - 1 != c.Length || a.Length != r.Length)
            {
                throw new SerializationException("Arrays a, and r must have the same length, while c must be one element shorter.");
            }

            if (this.UPIProof != null)
            {
                this.UPIProof.FinishDeserializing(this.Group);
            }
        }
        internal void OnPPSerializing(StreamingContext context)
        {
            if ((PublicValues == null) || (!ArePublicValuesSerializable))
            {
                _publicValues = null;
            }
            else
            {
                _publicValues = CryptoSerializer.SerializeGroupElementArray(this.PublicValues, "PublicValues");
            }

            if ((Witnesses == null) || (!AreWitnessesSerializable))
            {
                _witnesses = null;
            }
            else
            {
                _witnesses = CryptoSerializer.Serialize(this.Witnesses, false, this.AreWitnessBasesSerializable);
            }
        }
Example #13
0
        internal void OnSerializing(StreamingContext context)
        {
            // check lengths of arrays A, B, X, D
            if ((A == null) || (X == null) || (D == null) ||
                (A.Length != X.Length) ||
                (A.Length != D.Length) ||
                ((B != null) && (B.Length != A.Length)))
            {
                throw new SerializationException("Arrays A, B, X, and D must have the same length.");
            }

            // serialize A
            _a = CryptoSerializer.SerializeGroupElementArray(A, "A");
            if (this.B != null)
            {
                _b = CryptoSerializer.SerializeGroupElementArray(B, "B");
            }
            _x = CryptoSerializer.SerializeGroupElementArray(X, 1, X.Length - 1, "X");
            _d = CryptoSerializer.SerializeGroupElementArray(D, 1, D.Length - 1, "D");
        }
Example #14
0
        /// <summary>
        /// Deserialize A,B,X,D, as well as all proofs.
        /// </summary>
        public override void FinishDeserializing()
        {
            // deserialize A
            this.A = CryptoSerializer.DeserializeGroupElementArray(_a, "A", this.Group);
            int length = A.Length;

            if (this._b != null)
            {
                this.B = CryptoSerializer.DeserializeGroupElementArray(_b, "B", this.Group);
            }
            this.X = CryptoSerializer.DeserializeGroupElementArray(_x, 1, _x.Length + 1, "X", this.Group);
            this.D = CryptoSerializer.DeserializeGroupElementArray(_d, 1, _d.Length + 1, "D", this.Group);

            if (this.ProofBitDecompositionOfA != null)
            {
                this.ProofBitDecompositionOfA.FinishDeserializing(this.Group);
            }
            if (this.ProofBitDecompositionOfB != null)
            {
                this.ProofBitDecompositionOfB.FinishDeserializing(this.Group);
            }
            if (this.FullRangeProof != null)
            {
                this.FullRangeProof.FinishDeserializing(this.Group);
            }
            if (this.OrEqualToProof != null)
            {
                this.OrEqualToProof.FinishDeserializing(this.Group);
            }
            if (this.StrictlyThanProof != null)
            {
                this.StrictlyThanProof.FinishDeserializing(this.Group);
            }
            if (this.UPIProof != null)
            {
                this.UPIProof.FinishDeserializing(this.Group);
            }
        }
        public void OnSerializing(StreamingContext context)
        {
            this._representationLength = this.RepresentationLength;
            this._value = CryptoSerializer.Serialize(this.Value);

            if (this.AreBasesSerializable)
            {
                this._bases = CryptoSerializer.SerializeGroupElementArray(this.Bases, "Bases");
            }
            else
            {
                this._bases = null;
            }

            if (this.IsWitness)
            {
                this._exponents = CryptoSerializer.SerializeFieldZqElementArray(this.Exponents, "exponents");
            }
            else
            {
                this._exponents = null;
            }
        }
 public void VSMDeserialized(StreamingContext context)
 {
     MemberSet = CryptoSerializer.DeserializeFieldZqElementArray(_memberSet, "MemberSet", this.Group);
 }
 public void VSMSerializing(StreamingContext context)
 {
     _memberSet = CryptoSerializer.SerializeFieldZqElementArray(MemberSet, "MemberSet");
 }
Example #18
0
 public void ProverOnSerializing(StreamingContext context)
 {
     _witnesses = CryptoSerializer.Serialize(this.Witnesses, false, true);
 }
 /// <summary>
 /// Deserialize generators.
 /// </summary>
 public override void FinishDeserializing()
 {
     this.Generators = CryptoSerializer.DeserializeGroupElementArray(_generators, "Generators", this.Group);
 }
 internal void OnSerializing(StreamingContext context)
 {
     _generators = CryptoSerializer.SerializeGroupElementArray(this.Generators, "Generators");
 }
 /// <summary>
 /// Deserialize b, responseEqual, responseUnequal
 /// </summary>
 public override void FinishDeserializing()
 {
     this.b               = CryptoSerializer.DeserializeGroupElementArray(this._b, "b", this.Group);
     this.responseEqual   = CryptoSerializer.DeserializeFieldZqElementArray(this._responseEqual, "responseEqual", this.Group);
     this.responseUnequal = CryptoSerializer.DeserializeFieldZqElementArray(this._responseUnequal, "responseUnequal", this.Group);
 }
Example #22
0
 internal void OnSerializing(StreamingContext context)
 {
     _AB = CryptoSerializer.SerializeGroupElementArray(new GroupElement[2] {
         this.A, this.B
     }, "AB");
 }