Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PipelinedSimpleModulusEncryptor" /> class.
 /// </summary>
 /// <param name="target">The target pipe writer.</param>
 /// <param name="encryptionKeys">The encryption keys.</param>
 public PipelinedSimpleModulusEncryptor(PipeWriter target, SimpleModulusKeys encryptionKeys)
 {
     this.target         = target;
     this.encryptionKeys = encryptionKeys;
     this.Source         = this.Pipe.Reader;
     this.ReadSource().ConfigureAwait(false);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PipelinedSimpleModulusDecryptor"/> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="decryptionKeys">The decryption keys.</param>
 public PipelinedSimpleModulusDecryptor(PipeReader source, SimpleModulusKeys decryptionKeys)
     : base(decryptionKeys.DecryptKey.Length == 4 ? Variant.New : Variant.Old)
 {
     this.Source         = source;
     this.decryptionKeys = decryptionKeys;
     this.inputBuffer    = new byte[this.EncryptedBlockSize];
     this.ReadSource().ConfigureAwait(false);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PipelinedSimpleModulusEncryptor" /> class.
 /// </summary>
 /// <param name="target">The target pipe writer.</param>
 /// <param name="encryptionKeys">The encryption keys.</param>
 public PipelinedSimpleModulusEncryptor(PipeWriter target, SimpleModulusKeys encryptionKeys)
     : base(encryptionKeys.DecryptKey.Length == 4 ? Variant.New : Variant.Old)
 {
     this.target         = target;
     this.encryptionKeys = encryptionKeys;
     this.Source         = this.Pipe.Reader;
     this.inputBuffer    = new byte[this.DecryptedBlockSize];
     this.ReadSource().ConfigureAwait(false);
 }
        /// <summary>
        /// Generates a new pair of keys.
        /// </summary>
        /// <returns>The generated pair of new keys.</returns>
        public async Task <SimpleModulusKeys> GenerateKeys()
        {
            var result = new SimpleModulusKeys();

            do
            {
                for (int i = 0; i < 4; i++)
                {
                    this.FindKeys(out uint xorKey, out uint modulusKey, out uint encryptKey, out uint decryptKey);
                    result.ModulusKey[i] = modulusKey;
                    result.DecryptKey[i] = decryptKey;
                    result.EncryptKey[i] = encryptKey;
                    result.XorKey[i]     = xorKey;
                }
            }while (!await this.ValidateResult(result).ConfigureAwait(false));

            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates an instance of <see cref="SimpleModulusKeys"/> with the crypt key as <see cref="EncryptKey"/>.
        /// </summary>
        /// <param name="encryptionKey">The decryption key with 12 integers.</param>
        /// <returns>An instance of <see cref="SimpleModulusKeys"/> with the crypt key as <see cref="EncryptKey"/>.</returns>
        public static SimpleModulusKeys CreateEncryptionKeys(uint[] encryptionKey)
        {
            var keys = new SimpleModulusKeys();

            keys.ModulusKey[0] = encryptionKey[0];
            keys.ModulusKey[1] = encryptionKey[1];
            keys.ModulusKey[2] = encryptionKey[2];
            keys.ModulusKey[3] = encryptionKey[3];
            keys.EncryptKey[0] = encryptionKey[4];
            keys.EncryptKey[1] = encryptionKey[5];
            keys.EncryptKey[2] = encryptionKey[6];
            keys.EncryptKey[3] = encryptionKey[7];
            keys.XorKey[0]     = encryptionKey[8];
            keys.XorKey[1]     = encryptionKey[9];
            keys.XorKey[2]     = encryptionKey[10];
            keys.XorKey[3]     = encryptionKey[11];
            return(keys);
        }
Esempio n. 6
0
        /// <summary>
        /// Generates a new pair of keys.
        /// </summary>
        /// <returns>The generated pair of new keys.</returns>
        public SimpleModulusKeys GenerateKeys()
        {
            var result = new SimpleModulusKeys();

            do
            {
                for (int i = 0; i < 4; i++)
                {
                    this.FindKeys(out uint xorKey, out uint modulusKey, out uint encryptKey, out uint decryptKey);
                    result.ModulusKey[i] = modulusKey;
                    result.DecryptKey[i] = decryptKey;
                    result.EncryptKey[i] = encryptKey;
                    result.XorKey[i]     = xorKey;
                }
            }while (!this.ValidateResult(result));

            return(result);
        }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PipelinedSimpleModulusEncryptor"/> class.
 /// </summary>
 /// <param name="target">The target pipe writer.</param>
 /// <param name="encryptionKeys">The encryption keys.</param>
 public PipelinedSimpleModulusEncryptor(PipeWriter target, uint[] encryptionKeys)
     : this(target, SimpleModulusKeys.CreateEncryptionKeys(encryptionKeys))
 {
 }
 private async Task <bool> ValidateResult(SimpleModulusKeys result)
 {
     return(await this.ValidateKeys(result.GetEncryptionKeys(), result.GetDecryptionKeys()).ConfigureAwait(false));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PipelinedSimpleModulusDecryptor"/> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="decryptionKey">The decryption key.</param>
 public PipelinedSimpleModulusDecryptor(PipeReader source, uint[] decryptionKey)
     : this(source, SimpleModulusKeys.CreateDecryptionKeys(decryptionKey))
 {
 }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleModulusEncryptor" /> class.
 /// </summary>
 /// <param name="encryptionKeys">The encryption keys.</param>
 public SimpleModulusEncryptor(SimpleModulusKeys encryptionKeys)
 {
     this.encryptionKeys = encryptionKeys;
 }
Esempio n. 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleModulusEncryptor"/> class.
 /// </summary>
 /// <param name="encryptionKey">The encryption key.</param>
 public SimpleModulusEncryptor(uint[] encryptionKey)
     : this(SimpleModulusKeys.CreateEncryptionKeys(encryptionKey))
 {
 }
Esempio n. 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleModulusDecryptor"/> class.
 /// </summary>
 /// <param name="decryptionKeys">The decryption keys.</param>
 public SimpleModulusDecryptor(SimpleModulusKeys decryptionKeys)
 {
     this.decryptionKeys = decryptionKeys;
 }
Esempio n. 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleModulusDecryptor"/> class.
 /// </summary>
 /// <param name="decryptionKey">The decryption key.</param>
 public SimpleModulusDecryptor(uint[] decryptionKey)
     : this(SimpleModulusKeys.CreateDecryptionKeys(decryptionKey))
 {
 }
Esempio n. 14
0
 private bool ValidateResult(SimpleModulusKeys result)
 {
     return(this.ValidateKeys(result.GetEncryptionKeys(), result.GetDecryptionKeys()));
 }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PipelinedSimpleModulusDecryptor"/> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="decryptionKeys">The decryption keys.</param>
 public PipelinedSimpleModulusDecryptor(PipeReader source, SimpleModulusKeys decryptionKeys)
 {
     this.Source         = source;
     this.decryptionKeys = decryptionKeys;
     this.ReadSource().ConfigureAwait(false);
 }