Example #1
0
        public static byte[] decrypt(BFCText c, BFUserPrivateKey sk)
        {
            BFMasterPublicKey msk = sk.Param;
            Pairing           e   = msk.Pairing;

            //e(sQ,U), sQ is the user private key
            FieldElement temp = e.Compute(sk.Key, c.U);

            //sigma = V xor hash(temp)
            byte[] hash = BFUtil.HashToLength(temp.ToUByteArray(), c.V.Length); //This could fail

            byte[] sigma = BFUtil.XorTwoByteArrays(c.V, hash);

            hash = BFUtil.HashToLength(sigma, c.W.Length);

            byte[] m = BFUtil.XorTwoByteArrays(hash, c.W);

            //sigma||m
            byte[] toHash = new byte[sigma.Length + m.Length];
            Array.Copy(sigma, 0, toHash, 0, sigma.Length);
            Array.Copy(m, 0, toHash, sigma.Length, m.Length);

            //hash(sigma||m) to biginteger r;
            Field  field = e.Curve2.Field;
            BigInt r     = BFUtil.HashToField(toHash, field);

            if (c.U.Equals(e.Curve2.Multiply(msk.P, r)))
            {
                return(m);
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        public KeysController()
        {
            TatePairing        e             = Predefined.ssTate();
            BigInt             s             = new BigInt("505589879806357574715819689796588537146433291440", 10);
            BFMasterPrivateKey masterPrivate = new BFMasterPrivateKey(s);
            BigInt             xP            = new BigInt("4291662186182105785020055031256275922735182686564035226466395653970413755358824903482223509624549595190077490704367257937172972896431165061643256253841639", 10);
            BigInt             yP            = new BigInt("4734655302033019638724717069550998600270840147458147624263679086394750166097273830456518097912007100893265204858608788227968249694875877762941090121639110", 10);
            BigInt             xPpub         = new BigInt("3321521420324942690122656396767763795495870232445101779865981146134484022298665464121724898190544088107820667943606314446170142017782563402275554873870099", 10);
            BigInt             yPpub         = new BigInt("5811060153287472925206265749794945978469077668029247862550354611572579518279518356217273453987945241447730233617290283194068671621572534510817890943208269", 10);
            Point             P            = new Point(xP, yP);
            Point             Ppub         = new Point(xPpub, yPpub);
            BFMasterPublicKey masterPublic = new BFMasterPublicKey(e, P, Ppub);

            master = new KeyPair(masterPublic, masterPrivate);
        }
Example #3
0
        public static KeyPair Setup(Pairing e, Random rnd)
        {
            Point  P = e.Curve2.RandomPoint(rnd);
            BigInt s = new BigInt(e.GroupOrder.BitLength(), rnd);

            while (s.CompareTo(e.GroupOrder) >= 0)
            {
                s = s.ShiftRight(1);
            }

            Point Ppub = e.Curve2.Multiply(P, s);

            BFMasterPublicKey pk = new BFMasterPublicKey(e, P, Ppub);

            BFMasterPrivateKey sk = new BFMasterPrivateKey(s);

            //return new KeyPair(pk, sk);
            return(new KeyPair(null, null));
        }
Example #4
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var mappedObj = new BFUserPrivateKey();
            //get an array of the object's props so I can check if the JSON prop s/b mapped to it
            var   objProps = objectType.GetProperties().Select(p => p.Name.ToLower()).ToArray();
            Point pPrivate, pPoint, pPub;

            pPub = pPrivate = pPoint = null;
            TatePairing       e = null;;
            BFMasterPublicKey pKey;
            bool rPPrivate, rPairing, rP, rPPub, rKey, rParam;

            rPPub = rPairing = rP = rPPrivate = rKey = rParam = false;

            //loop through my JSON string
            while (reader.Read())
            {
                //if I'm at a property...
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    //convert the property to lower case
                    string readerValue = reader.Value.ToString().ToLower();
                    if (readerValue == "key")   //We are expecting point with X and Y coordinates
                    {
                        pPrivate  = ReadPoint(reader);
                        rPPrivate = true;
                        rKey      = true;
                    }
                    else if (readerValue == "param") //We are expecting a pairing a 2 points
                    {
                        while (reader.Read() && rParam == false)
                        {
                            if (reader.TokenType == JsonToken.PropertyName)
                            {
                                string rValue = reader.Value.ToString().ToLower();
                                if (rValue == "pairing")
                                {
                                    e        = ReadPairing(reader);
                                    rPairing = true;
                                }
                                else if (rValue == "p")
                                {
                                    pPoint = ReadPoint(reader);
                                    rP     = true;
                                }
                                else if (rValue == "ppub")
                                {
                                    pPub  = ReadPoint(reader);
                                    rPPub = true;
                                }
                            }
                            if (rP && rPPub && rPairing)
                            {
                                rParam = true;
                            }
                        }
                    }
                }
                if (rParam && rKey)
                {
                    pKey = new BFMasterPublicKey(e, pPoint, pPub);
                    while (reader.Read())
                    {
                        reader.Read();
                    }
                    return(new BFUserPrivateKey(pPrivate, pKey));
                }
            }
            return(mappedObj);
        }