internal void Encrypt(string InputPath, string OutputPath) { byte[] hashKey = KeyHeader.GetMessageKey(this.KeyPath); byte[] checkSum = new byte[64]; MemoryStream header = new MemoryStream(MessageHeader.Create(this.KeyPath, Path.GetExtension(InputPath), checkSum)); this.FileSize = GetFileSize(InputPath); this.IsEncryption = true; //calculate progress interval CalculateInterval(); if (this.Engine == Engines.ChaCha || this.Engine == Engines.DCS || this.Engine == Engines.Salsa || this.Engine == Engines.Fusion) { // stream cipher ProcessStream(InputPath, OutputPath, header); } else { // init block cipher this.Mode.Init(true, new KeyParams(this.Key, this.IV)); if (this.Mode.Name == "CTR" && this.IsParallel) { ParallelCTR(InputPath, OutputPath, header); } else { EncryptFile(InputPath, OutputPath, header); } } // create checksum and sign checkSum = GetChecksum(OutputPath, hashKey); MessageHeader.SetMessageHash(OutputPath, checkSum); }
public override Task <GetWorkerResponse> Get(GetWorkerRequest request, ServerCallContext context) { this.faster.StartSession(); this.headers.StartSession(); var result = new GetWorkerResponse(); var hits = 0; foreach (var key in request.Key) { var x = new Common.KeyValuePair() { Key = key, Value = ByteString.Empty }; //first lets figure out if the key exists and stil valid var k = new KeyHeader(); var v = new ValueHeader(); var o = new KeyHeader(); k.key = key; headers.Read(ref k, ref o, ref v, default, 0);
/// <summary> /// Verify the hash value for a file /// </summary> /// <param name="InputPath">Encrypted file path</param> /// <param name="OutputPath">Decrypted file path</param> /// <param name="KeyPath">Full path to key file</param> /// <returns>Verified [bool]</returns> internal bool Verify(string InputPath, string KeyPath) { byte[] hashKey = KeyHeader.GetMessageKey(KeyPath); byte[] msgHash = MessageHeader.GetMessageHash(InputPath); byte[] hash = GetChecksum(InputPath, hashKey); return(IsEqual(msgHash, hash)); }
private int GetIvSize(string KeyPath) { IVSizes ivSize = KeyHeader.GetIvSize(KeyPath); if (ivSize == IVSizes.V128) { return(16); } else if (ivSize == IVSizes.V256) { return(32); } else { return(8); } }
internal Transform(string KeyPath) { if (!File.Exists(KeyPath)) { return; } // get key and algorithm this.ProgressInterval = PRG_INTV; this.KeyPath = KeyPath; this.Engine = KeyHeader.GetEngineType(KeyPath); this.Key = GetKey(KeyPath); int rounds = GetRoundsSize(KeyPath); // stream ciphers if (this.Engine == Engines.ChaCha) { StreamCipher = new ChaCha(rounds); } else if (this.Engine == Engines.DCS) { StreamCipher = new DCS(); } if (this.Engine == Engines.Salsa) { StreamCipher = new Salsa20(rounds); } if (this.Engine == Engines.Fusion) { StreamCipher = new Fusion(rounds); } this.BlockSize = 64; // get iv if (this.Engine != Engines.DCS) { this.IV = GetIV(KeyPath); } else { this.BlockSize = (DCS_BLOCK * 4); } // dcs, chacha and salsa are stream ciphers if (this.Engine == Engines.DCS || this.Engine == Engines.ChaCha || this.Engine == Engines.Salsa || this.Engine == Engines.Fusion) { return; } this.IsParallel = Environment.ProcessorCount > 1; // set params from key data this.BlockSize = KeyHeader.GetBlockSize(KeyPath) == BlockSizes.B128 ? 16 : 32; this.CipherMode = KeyHeader.GetCipherType(KeyPath); this.PaddingMode = KeyHeader.GetPaddingType(KeyPath); // block size if (this.IV != null && this.IV.Length > 0) { this.BlockSize = this.IV.Length; } else { this.CipherMode = CipherModes.ECB; } // padding selection if (this.PaddingMode == PaddingModes.PKCS7) { Padding = new PKCS7(); } else if (this.PaddingMode == PaddingModes.X923) { Padding = new X923(); } else if (this.PaddingMode == PaddingModes.Zeros) { Padding = new ZeroPad(); } // create engine if (this.Engine == Engines.RDX) { this.BlockCipher = new RDX(this.BlockSize); } else if (this.Engine == Engines.RSM) { this.BlockCipher = new RSM(rounds, this.BlockSize); } else if (this.Engine == Engines.RSX) { this.BlockCipher = new RSX(this.BlockSize); } else if (this.Engine == Engines.RHX) { this.BlockCipher = new RHX(rounds, this.BlockSize); } else if (this.Engine == Engines.SPX) { this.BlockCipher = new SPX(rounds); } else if (this.Engine == Engines.SHX) { this.BlockCipher = new SHX(rounds); } else if (this.Engine == Engines.TFX) { this.BlockCipher = new TFX(rounds); } else if (this.Engine == Engines.THX) { this.BlockCipher = new THX(rounds); } else if (this.Engine == Engines.TSM) { this.BlockCipher = new TSM(rounds); } // create cipher if (this.CipherMode == CipherModes.CBC) { this.Mode = new CBC(this.BlockCipher); } else if (this.CipherMode == CipherModes.CTR) { this.Mode = new CTR(this.BlockCipher); } else if (this.CipherMode == CipherModes.ECB) { this.Mode = new ECB(this.BlockCipher); } }
private int GetRoundsSize(string KeyPath) { this.RoundCount = KeyHeader.GetRoundCount(KeyPath); if (this.RoundCount == RoundCounts.R8) { return(8); } else if (this.RoundCount == RoundCounts.R10) { return(10); } else if (this.RoundCount == RoundCounts.R12) { return(12); } else if (this.RoundCount == RoundCounts.R14) { return(14); } else if (this.RoundCount == RoundCounts.R16) { return(16); } else if (this.RoundCount == RoundCounts.R18) { return(18); } else if (this.RoundCount == RoundCounts.R20) { return(20); } else if (this.RoundCount == RoundCounts.R22) { return(22); } else if (this.RoundCount == RoundCounts.R24) { return(24); } else if (this.RoundCount == RoundCounts.R26) { return(26); } else if (this.RoundCount == RoundCounts.R28) { return(28); } else if (this.RoundCount == RoundCounts.R30) { return(30); } else if (this.RoundCount == RoundCounts.R32) { return(32); } else if (this.RoundCount == RoundCounts.R34) { return(34); } else if (this.RoundCount == RoundCounts.R38) { return(38); } else if (this.RoundCount == RoundCounts.R40) { return(40); } else if (this.RoundCount == RoundCounts.R42) { return(42); } else if (this.RoundCount == RoundCounts.R48) { return(48); } else if (this.RoundCount == RoundCounts.R56) { return(56); } else if (this.RoundCount == RoundCounts.R64) { return(64); } else if (this.RoundCount == RoundCounts.R80) { return(80); } else if (this.RoundCount == RoundCounts.R96) { return(96); } else if (this.RoundCount == RoundCounts.R128) { return(128); } else { return(20); } }
private int GetKeySize(string KeyPath) { KeySizes keySize = KeyHeader.GetKeySize(KeyPath); if (this.Engine == Engines.DCS) { return(96); } if (keySize == KeySizes.K128) { return(16); } else if (keySize == KeySizes.K192) { return(24); } else if (keySize == KeySizes.K192) { return(24); } else if (keySize == KeySizes.K256) { return(32); } else if (keySize == KeySizes.K384) { return(48); } else if (keySize == KeySizes.K448) { return(56); } else if (keySize == KeySizes.K512) { return(64); } else if (keySize == KeySizes.K1024) { return(128); } else if (keySize == KeySizes.K1536) { return(192); } else if (keySize == KeySizes.K2560) { return(320); } else if (keySize == KeySizes.K3584) { return(448); } else if (keySize == KeySizes.K4608) { return(576); } else { return(32); } }