示例#1
0
        private ICSequence[] EncBlock(ICSequence codes)
        {
            var toKH  = new ICSequence();
            var toEVH = new ICSequence();

            foreach (var ic in codes.GetCodes())
            {
                if (ic is ICAssignment)
                {
                    ICAssignment ica = (ICAssignment)ic;
                    Numeric      key1 = null, key2 = null;
                    toKH.Add(new ICAssignment(ica, ref key1, ref key2, PartyType.KH));
                    toEVH.Add(new ICAssignment(ica, ref key1, ref key2, PartyType.EVH));
                }
                else if (ic is ICWhile)
                {
                    ICWhile icw = (ICWhile)ic, icwEVH = new ICWhile(), icwKH = new ICWhile();
                    icwEVH.index = icw.index;
                    icwKH.index  = icw.index;
                    if (icw.condition is ENumericLiteral)
                    {
                        var cond = (ENumericLiteral)icw.condition;
                        if (!cond.needEnc)
                        {
                            var val = new Numeric(cond.GetValue());
                            val.SetEncType(EncryptionType.None);
                            icwEVH.condition = new ENumericLiteral(val);
                            ((ENumericLiteral)icwEVH.condition).needEnc = false;
                            icwKH.condition = new ENumericLiteral(val);
                            ((ENumericLiteral)icwKH.condition).needEnc = false;
                        }
                        else
                        {
                            var keyTemp = Utility.NextUnsignedNumeric(0, 1);
                            icwEVH.condition = new ENumericLiteral(GetValue(icw.condition) ^ keyTemp);
                            icwKH.condition  = new ENumericLiteral(keyTemp);
                        }
                    }
                    else
                    {
                        icwEVH.condition = icw.condition;
                        icwKH.condition  = icw.condition;
                    }
                    var encCondCodes = EncBlock(icw.conditionCodes);
                    icwEVH.conditionCodes.AddRange(encCondCodes[0]);
                    icwKH.conditionCodes.AddRange(encCondCodes[1]);
                    var encCodes = EncBlock(icw.codes);
                    icwEVH.codes.AddRange(encCodes[0]);
                    icwKH.codes.AddRange(encCodes[1]);
                    toEVH.Add(icwEVH);
                    toKH.Add(icwKH);
                }
                else
                {
                    ICIfElse icie = (ICIfElse)ic, icieEVH = new ICIfElse(), icieKH = new ICIfElse();
                    icieEVH.revealCond = icie.revealCond;
                    icieKH.revealCond  = icie.revealCond;
                    icieEVH.prob       = icie.prob;
                    icieKH.prob        = icie.prob;
                    icieEVH.index      = icie.index;
                    icieKH.index       = icie.index;
                    if (icie.condition is ENumericLiteral)
                    {
                        var cond = (ENumericLiteral)icie.condition;
                        if (!cond.needEnc)
                        {
                            var val = new Numeric(cond.GetValue());
                            val.SetEncType(EncryptionType.None);
                            icieEVH.condition = new ENumericLiteral(val);
                            ((ENumericLiteral)icieEVH.condition).needEnc = false;
                            icieKH.condition = new ENumericLiteral(val);
                            ((ENumericLiteral)icieKH.condition).needEnc = false;
                        }
                        else
                        {
                            var keyTemp = Utility.NextUnsignedNumeric(0, 1);
                            icieEVH.condition = new ENumericLiteral(GetValue(icie.condition) ^ keyTemp);
                            icieKH.condition  = new ENumericLiteral(keyTemp);
                        }
                    }
                    else
                    {
                        icieEVH.condition = icie.condition;
                        icieKH.condition  = icie.condition;
                    }
                    var encCondCodes = EncBlock(icie.conditionCodes);
                    icieEVH.conditionCodes.AddRange(encCondCodes[0]);
                    icieKH.conditionCodes.AddRange(encCondCodes[1]);
                    var encIfCodes = EncBlock(icie.codesIf);
                    icieEVH.codesIf = encIfCodes[0];
                    icieKH.codesIf  = encIfCodes[1];
                    var encElseCodes = EncBlock(icie.codesElse);
                    icieEVH.codesElse = encElseCodes[0];
                    icieKH.codesElse  = encElseCodes[1];
                    toEVH.Add(icieEVH);
                    toKH.Add(icieKH);
                }
            }
            return(new ICSequence[] { toEVH, toKH });
        }
示例#2
0
 public void AddRange(ICSequence codes)
 {
     icCodes.AddRange(codes.GetCodes());
 }