Ejemplo n.º 1
0
        public static SecureWord Multiplex(SecureWord left, SecureWord right, SecureBoolean condition)
        {
            if (left.Builder != right.Builder || condition.Builder != right.Builder)
            {
                throw new ArgumentException("Secure words must use the same circuit builder for constructing gates.");
            }

            if (left.Length != right.Length)
            {
                throw new ArgumentException("Secure words must be of same length for multiplexing.");
            }

            Wire[] result = new Wire[right.Length];
            for (int i = 0; i < right.Length; ++i)
            {
                result[i] = right.Builder.Xor(
                    left.Wires[i],
                    right.Builder.And(
                        condition.Wire,
                        right.Builder.Xor(left.Wires[i], right.Wires[i])
                        )
                    );
            }

            return(new SecureWord(right.Builder, result));
        }
Ejemplo n.º 2
0
        public static SecureBoolean operator ==(SecureWord left, SecureWord right)
        {
            if (left.Builder != right.Builder)
            {
                throw new ArgumentException("Secure words must use the same circuit builder for constructing gates.");
            }

            CircuitBuilder builder = right.Builder;

            if (left.Length != right.Length)
            {
                return(SecureBoolean.False(builder));
            }

            Wire result = left.Wires
                          .Zip(right.Wires, (leftWire, rightWire) => builder.Not(builder.Xor(leftWire, rightWire)))
                          .ToArray()
                          .AggregateDepthEfficient((x, y) => builder.And(x, y));

            return(new SecureBoolean(right.Builder, result));
        }
Ejemplo n.º 3
0
 public static SecureInteger FromBoolean(SecureBoolean boolean)
 {
     return(new SecureInteger(boolean.Builder, boolean.Wires));
 }