public EncryptedSealBfvFactory(string fileName) { referenceEnvironment = new EncryptedSealBfvEnvironment(fileName) { ParentFactory = this }; }
public EncryptedSealBfvFactory(Stream stream) { referenceEnvironment = new EncryptedSealBfvEnvironment(stream) { ParentFactory = this }; }
public IComputationEnvironment AllocateComputationEnv() { environmentQueue.TryDequeue(out EncryptedSealBfvEnvironment env); if (env == null) { env = new EncryptedSealBfvEnvironment(referenceEnvironment); } return(env); }
public EncryptedSealBfvFactory(ulong[] primes, ulong n, int DecompositionBitCount = DefaultDecompositionBitCount, int GaloisDecompositionBitCount = DefaultGaloisDecompositionBitCount, int SmallModulusCount = -1) { EncryptedSealBfvEnvironment eenv = new EncryptedSealBfvEnvironment() { ParentFactory = this }; eenv.GenerateEncryptionKeys(primes, n, DecompositionBitCount, GaloisDecompositionBitCount, SmallModulusCount); referenceEnvironment = eenv; }
static public EncryptedSealBfvVector Stack(EncryptedSealBfvVector[] vecs, EncryptedSealBfvEnvironment env) { var res = new EncryptedSealBfvVector() { eVectors = vecs[0].ForEveryEncryptedVector(i => AtomicSealBfvEncryptedVector.StackTask(vecs.Select(v => v.eVectors[i]).ToArray(), env.Environments[i])), Scale = vecs[0].Scale }; return(res); }
public EncryptedSealBfvFactory() { ulong[] primes = new ulong[] { 40961, 65537, 114689, 147457, 188417 }; EncryptedSealBfvEnvironment eenv = new EncryptedSealBfvEnvironment() { ParentFactory = this }; eenv.GenerateEncryptionKeys(primes, 4096, DefaultDecompositionBitCount, DefaultGaloisDecompositionBitCount); referenceEnvironment = eenv; }
public EncryptedSealBfvEnvironment(EncryptedSealBfvEnvironment reference) { bigFactor = reference.bigFactor; ParentFactory = reference.ParentFactory; preComputedCoefficients = reference.preComputedCoefficients; Environments = reference.Environments.Select(x => new AtomicSealBfvEncryptedEnvironment(x)).ToArray(); if (reference.environmentQueue == null) { reference.CreateQueue(); } environmentQueue = reference.environmentQueue; }
UInt64[][] SplitBigNumbers(IEnumerable <BigInteger> v, EncryptedSealBfvEnvironment leenv) { var res = new UInt64[leenv.Environments.Length][]; var z = v.Select(x => (x < 0) ? x + leenv.bigFactor : x); for (int i = 0; i < res.Length; i++) { res[i] = z.Select(x => (UInt64)(x % leenv.Environments[i].plainmodulusValue)).ToArray(); } return(res); }
/// <summary> /// test the noise budget in a vector and updates the minimal budget seen if needed /// </summary> /// <param name="res"> input vector</param> /// <param name="decryptor"> a decryptor object that is used to measure the noise level</param> public static int TestVectorBudget(EncryptedSealBfvVector v, EncryptedSealBfvEnvironment lenv) { var vectors = v.Data as AtomicSealBfvEncryptedVector[]; for (int i = 0; i < vectors.Length; i++) { var ciphers = vectors[i].Data as Ciphertext[]; foreach (var c in ciphers) { TestBudget(c, lenv.Environments[i].decryptor); } } return(MinBudgetSoFar); }
Vector <double>[] SplitBigNumbers(Vector <double> v, EncryptedSealBfvEnvironment leenv) { var res = new Vector <double> [leenv.Environments.Length]; var w = v.Multiply(Scale).PointwiseRound().Select(x => (BigInteger)x).ToArray(); var z = w.Select(x => (x < 0) ? x + leenv.bigFactor : x); for (int i = 0; i < res.Length; i++) { res[i] = Vector <double> .Build.DenseOfEnumerable(z.Select(x => (double)(x % leenv.Environments[i].plainmodulusValue))); } return(res); }
IEnumerable <BigInteger> JoinSplitNumbers(IEnumerable <BigInteger>[] split, EncryptedSealBfvEnvironment leenv) { var bigNumbers = new BigInteger[split[0].Count()]; for (int i = 0; i < split.Length; i++) { for (int j = 0; j < bigNumbers.Length; j++) { bigNumbers[j] += ((BigInteger)split[i].ElementAt(j)) * leenv.preComputedCoefficients[i]; } } for (int j = 0; j < bigNumbers.Length; j++) { bigNumbers[j] = bigNumbers[j] % leenv.bigFactor; if (IsSigned && (bigNumbers[j] * 2 > leenv.bigFactor)) { bigNumbers[j] = bigNumbers[j] - leenv.bigFactor; } } return(bigNumbers); }
Vector <double> JoinSplitNumbers(Vector <double>[] split, EncryptedSealBfvEnvironment leenv) { var bigNumbers = new BigInteger[split[0].Count]; for (int i = 0; i < split.Length; i++) { for (int j = 0; j < bigNumbers.Length; j++) { bigNumbers[j] += ((BigInteger)split[i][j]) * leenv.preComputedCoefficients[i]; } } for (int j = 0; j < bigNumbers.Length; j++) { bigNumbers[j] = bigNumbers[j] % leenv.bigFactor; if (bigNumbers[j] * 2 > leenv.bigFactor) { bigNumbers[j] = bigNumbers[j] - leenv.bigFactor; } } return(Vector <double> .Build.DenseOfEnumerable(bigNumbers.Select(x => (double)x / Scale))); }
public static EncryptedSealBfvMatrix Read(StreamReader str, EncryptedSealBfvEnvironment env) { var mtx = new EncryptedSealBfvMatrix(); var line = str.ReadLine(); if (line != "<Start LargeEncryptedMatrix>") { throw new Exception("Bad stream format."); } mtx.Format = (EMatrixFormat)Enum.Parse(mtx.Format.GetType(), str.ReadLine()); mtx.leVectors = new EncryptedSealBfvVector[int.Parse(str.ReadLine())]; for (int i = 0; i < mtx.leVectors.Length; i++) { mtx.leVectors[i] = EncryptedSealBfvVector.Read(str, env); } line = str.ReadLine(); if (line != "<End LargeEncryptedMatrix>") { throw new Exception("Bad stream format."); } return(mtx); }
public static EncryptedSealBfvVector Read(StreamReader str, EncryptedSealBfvEnvironment env) { var vct = new EncryptedSealBfvVector(); var line = str.ReadLine(); if (line != "<Start LargeEncryptedVector>") { throw new Exception("Bad stream format."); } vct.Scale = double.Parse(str.ReadLine()); vct.eVectors = new AtomicSealBfvEncryptedVector[int.Parse(str.ReadLine())]; for (int i = 0; i < vct.eVectors.Length; i++) { vct.eVectors[i] = AtomicSealBfvEncryptedVector.Read(str, env.Environments[i]); } line = str.ReadLine(); if (line != "<End LargeEncryptedVector>") { throw new Exception("Bad stream format."); } return(vct); }
static public Task <EncryptedSealBfvVector> InterleaveTask(EncryptedSealBfvVector[] vecs, int shift, EncryptedSealBfvEnvironment env) { return(Task <EncryptedSealBfvVector> .Factory.StartNew(() => Interleave(vecs, shift, env))); }
static public Task <EncryptedSealBfvVector> StackTask(EncryptedSealBfvVector[] vecs, EncryptedSealBfvEnvironment env) { return(Task <EncryptedSealBfvVector> .Factory.StartNew(() => Stack(vecs, env))); }
static public Task <EncryptedSealBfvVector> DenseMatrixBySparseVectorMultiplyTask(EncryptedSealBfvVector[] denses, EncryptedSealBfvVector sparse, EncryptedSealBfvEnvironment env) { return(Task <EncryptedSealBfvVector> .Factory.StartNew(() => DenseMatrixBySparseVectorMultiply(denses, sparse, env))); }
static public EncryptedSealBfvVector DenseMatrixBySparseVectorMultiply(EncryptedSealBfvVector[] denses, EncryptedSealBfvVector sparse, EncryptedSealBfvEnvironment env) { var res = new EncryptedSealBfvVector() { Scale = denses[0].Scale * sparse.Scale, eVectors = denses[0].ForEveryEncryptedVector(i => AtomicSealBfvEncryptedVector.DenseMatrixBySparseVectorMultiplyTask(denses.Select(d => d.eVectors[i]).ToArray(), sparse.eVectors[i], env.Environments[i])) }; return(res); }