public static void MyClassInitialize(TestContext testContext)
        {
            //
            // generate issuer parameters
            //
            IssuerSetupParameters isp = new IssuerSetupParameters(maxNumberOfAttributes);

            isp.UidP = new byte[] { (byte)0 };
            //isp.NumberOfAttributes = 1;
            isp.E = new byte[] { (byte)0 };  // encode xid directly has an
            IssuerKeyAndParameters ikap = isp.Generate();

            ip = ikap.IssuerParameters;

            //
            // issue a token
            //
            xid = ip.Gq.FieldZq.GetRandomElement(false);
            IssuerProtocolParameters ipp = new IssuerProtocolParameters(ikap);
            ProverProtocolParameters ppp = new ProverProtocolParameters(ip);

            attributes         = new byte[][] { xid.ToByteArray() };
            ipp.Attributes     = ppp.Attributes = attributes;
            ipp.NumberOfTokens = ppp.NumberOfTokens = 1;
            Issuer issuer = ipp.CreateIssuer();
            Prover prover = ppp.CreateProver();

            upkt = prover.GenerateTokens(issuer.GenerateThirdMessage(prover.GenerateSecondMessage(issuer.GenerateFirstMessage())))[0];
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns an array of Zero and One FieldZqElements, in Small Endian notation.
        /// So sum result[i] * 2^i = integer.  If decompositionLength is too short,
        /// returns the minimum length array with the correct decomposition.
        /// </summary>
        /// <param name="integer">Integer to decompose</param>
        /// <param name="decompositionLength">Minimum number of bits.</param>
        /// <param name="fieldZq">Field</param>
        /// <returns></returns>
        public static BitArray GetBitDecomposition(FieldZqElement integer, int decompositionLength, FieldZq fieldZq)
        {
            // get bit array
            BitArray bits = new BitArray(VerifierBitDecompositionParameters.Reverse(integer.ToByteArray()));

            // compute minimum decompositionLength
            if ((decompositionLength < IndexOfMostSignificantNonZeroBit(bits) + 1))
            {
                decompositionLength = IndexOfMostSignificantNonZeroBit(bits) + 1;
            }

            // translate bits into array of FieldZqElements
            BitArray bitDecomposition = new BitArray(decompositionLength);

            for (int bitIndex = 0; bitIndex < bitDecomposition.Length; ++bitIndex)
            {
                if ((bitIndex < bits.Length) && bits.Get(bitIndex))
                {
                    bitDecomposition.Set(bitIndex, true);
                }
                else
                {
                    bitDecomposition.Set(bitIndex, false);
                }
            }
            return(bitDecomposition);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Convert a FieldElement to a base64 representation.
 /// </summary>
 /// <param name="fieldElement">The value to convert.</param>
 /// <returns>The base64 representation.</returns>
 public static String ToBase64String(this FieldZqElement fieldElement)
 {
     if (fieldElement == null)
     {
         return(null);
     }
     return(Convert.ToBase64String(fieldElement.ToByteArray()));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Hash a FieldZqElement.
 /// </summary>
 /// <param name="value">A field Zq element to be hashed.</param>
 public void Hash(FieldZqElement value)
 {
     if (value == null)
     {
         HashNull();
         return;
     }
     Hash(value.ToByteArray());
 }
        public void EncodingTest()
        {
            // a large value
            byte[] modulus = new byte[] {
                0xef, 0x09, 0x90, 0x06, 0x1d, 0xb6, 0x7a, 0x9e,
                0xae, 0xba, 0x26, 0x5f, 0x1b, 0x8f, 0xa1, 0x2b,
                0x55, 0x33, 0x90, 0xa8, 0x17, 0x5b, 0xcb, 0x3d,
                0x0c, 0x2e, 0x5e, 0xe5, 0xdf, 0xb8, 0x26, 0xe2,
                0x29, 0xad, 0x37, 0x43, 0x11, 0x48, 0xce, 0x31,
                0xf8, 0xb0, 0xe5, 0x31, 0x77, 0x7f, 0x19, 0xc1,
                0xe3, 0x81, 0xc6, 0x23, 0xe6, 0x00, 0xbf, 0xf7,
                0xc5, 0x5a, 0x23, 0xa8, 0xe6, 0x49, 0xcc, 0xbc,
                0xf8, 0x33, 0xf2, 0xdb, 0xa9, 0x9e, 0x6a, 0xd6,
                0x6e, 0x52, 0x37, 0x8e, 0x92, 0xf7, 0x49, 0x2b,
                0x24, 0xff, 0x8c, 0x1e, 0x6f, 0xb1, 0x89, 0xfa,
                0x84, 0x34, 0xf5, 0x40, 0x2f, 0xe4, 0x15, 0x24,
                0x9a, 0xe0, 0x2b, 0xf9, 0x2b, 0x3e, 0xd8, 0xea,
                0xaa, 0xa2, 0x20, 0x2e, 0xc3, 0x41, 0x7b, 0x20,
                0x79, 0xda, 0x4f, 0x35, 0xe9, 0x85, 0xbb, 0x42,
                0xa4, 0x21, 0xcf, 0xab, 0xa8, 0x16, 0x0b, 0x66,
                0x94, 0x99, 0x83, 0x38, 0x4e, 0x56, 0x36, 0x5a,
                0x44, 0x86, 0xc0, 0x46, 0x22, 0x9f, 0xc8, 0xc8,
                0x18, 0xf9, 0x30, 0xb8, 0x0a, 0x60, 0xd6, 0xc2,
                0xc2, 0xe2, 0x0c, 0x5d, 0xf8, 0x80, 0x53, 0x4d,
                0x42, 0x40, 0xd0, 0xd8, 0x1e, 0x9a, 0x37, 0x0e,
                0xef, 0x67, 0x6a, 0x1c, 0x3b, 0x0e, 0xd1, 0xd8,
                0xff, 0x30, 0x34, 0x0a, 0x96, 0xb2, 0x1b, 0x89,
                0xf6, 0x9c, 0x54, 0xce, 0xb8, 0xf3, 0xdf, 0x17,
                0xe3, 0x1b, 0xc2, 0x0c, 0x5b, 0x60, 0x1e, 0x99,
                0x44, 0x45, 0xa1, 0xd3, 0x47, 0xa4, 0x5d, 0x95,
                0xf4, 0x1a, 0xe0, 0x71, 0x76, 0xc7, 0x38, 0x0c,
                0x60, 0xdb, 0x2a, 0xce, 0xdd, 0xee, 0xda, 0x5c,
                0x59, 0x80, 0x96, 0x43, 0x62, 0xe3, 0xa8, 0xdd,
                0x3f, 0x97, 0x3d, 0x6d, 0x4b, 0x24, 0x1b, 0xcf,
                0x91, 0x0c, 0x7f, 0x7a, 0x02, 0xed, 0x3b, 0x60,
                0x38, 0x3a, 0x01, 0x02, 0xd8, 0x06, 0x0c, 0x27
            };

            FieldZq field = FieldZq.CreateFieldZq(modulus);

            for (int i = 0; i < 20; i++)
            {
                FieldZqElement r  = field.GetRandomElement(false);
                FieldZqElement r2 = field.GetElement(r.ToByteArray());
                Assert.AreEqual <FieldZqElement>(r, r2);
            }
        }