Exemplo n.º 1
0
        public static void VerifySmartCard(SmartCardDevice smartCardDevice, byte[] com, byte[] response, string hashFunctionName, byte[] proofSession, byte[] challangeMgs)
        {
            BigInteger resp = new BigInteger(1, response);
            //BigInteger comBig = new BigInteger(1, com);
            HashFunction hash = new HashFunction(hashFunctionName);

            //hash.Hash(new byte[1] {0x1});
            //hash.Hash(1);
            byte[] proofSessionFoo = new byte[1 + proofSession.Length];
            proofSessionFoo[0] = 1;
            Buffer.BlockCopy(proofSession, 0, proofSessionFoo, 1, proofSession.Length);
            hash.Hash(proofSessionFoo);
            hash.Hash(challangeMgs);
            byte[]     cByte = hash.Digest;
            BigInteger c     = new BigInteger(1, cByte);

            byte[] devicePubKeyByte = smartCardDevice.Device.GetDevicePublicKey(true);
            //BigInteger devicePubKey = new BigInteger(1, devicePubKeyByte);
            SubgroupGroupDescription subGq     = (SubgroupGroupDescription)smartCardDevice.getGroupDescription();
            SubgroupGroupElement     leftSide  = (SubgroupGroupElement)smartCardDevice.getGroupElement().Exponentiate(resp);
            SubgroupGroupElement     pk        = (SubgroupGroupElement)subGq.CreateGroupElement(devicePubKeyByte);
            SubgroupGroupElement     pkc       = (SubgroupGroupElement)pk.Exponentiate(c.Negate());
            SubgroupGroupElement     rightSide = (SubgroupGroupElement)pkc.Multiply(smartCardDevice.getGroupDescription().CreateGroupElement(com));

            Console.Out.WriteLine("Printing left and right side");
            Utils.PrintByteArrayToConsole(leftSide.GetEncoded());
            Utils.PrintByteArrayToConsole(rightSide.GetEncoded());
        }
Exemplo n.º 2
0
        public static GroupDescription convertSubgroupDescription(SubgroupGroupDescriptionComposite sGroupComp)
        {
            SubgroupGroupDescription sGroup = new SubgroupGroupDescription();

            // TODO add error handling here.
            sGroup.P = new BigInteger(1, sGroupComp.P);
            sGroup.Q = new BigInteger(1, sGroupComp.Q);
            sGroup.G = new SubgroupGroupElement(new BigInteger(1, sGroupComp.G), sGroup.P);

            return(sGroup);
        }
Exemplo n.º 3
0
        public static SubgroupGroupDescriptionComposite convertSubgroupDescription(GroupDescription Gq)
        {
            SubgroupGroupDescription sGroup = (SubgroupGroupDescription)Gq;
            //TODO add error handling here.
            SubgroupGroupDescriptionComposite sGroupComp = new SubgroupGroupDescriptionComposite();

            sGroupComp.P = sGroup.P.ToByteArray();
            sGroupComp.Q = sGroup.Q.ToByteArray();
            sGroupComp.G = sGroup.G.GetEncoded();
            return(sGroupComp);
        }
Exemplo n.º 4
0
    public static GroupDescription convertSubgroupDescription(SubgroupGroupDescriptionComposite sGroupComp)
    {
      SubgroupGroupDescription sGroup = new SubgroupGroupDescription();
      // TODO add error handling here.
      sGroup.P = new BigInteger(1, sGroupComp.P);
      sGroup.Q = new BigInteger(1, sGroupComp.Q);
      sGroup.G = new SubgroupGroupElement(new BigInteger(1, sGroupComp.G), sGroup.P);

      return sGroup;
    }