public static byte[] KeyEncryptionKey(byte[] sharedSecret, byte[] ephemeralSharedSecret, byte[] salt) { byte[] inputKeyingMaterial = Utilities.ConcatArrays(sharedSecret, ephemeralSharedSecret); byte[] keyEncryptionKey = Blake2.KeyDerivation(inputKeyingMaterial, salt, Constants.EncryptionKeyLength); Utilities.ZeroArray(ephemeralSharedSecret); Utilities.ZeroArray(inputKeyingMaterial); return(keyEncryptionKey); }
public static byte[] KeyEncryptionKey(byte[] sharedSecret, byte[] ephemeralSharedSecret, byte[] salt) { byte[] inputKeyingMaterial = Arrays.Concat(sharedSecret, ephemeralSharedSecret); byte[] keyEncryptionKey = Blake2.KeyDerivation(inputKeyingMaterial, salt, Constants.EncryptionKeyLength); CryptographicOperations.ZeroMemory(ephemeralSharedSecret); CryptographicOperations.ZeroMemory(inputKeyingMaterial); return(keyEncryptionKey); }
public static byte[] Hash(char[] password) { if (password.Length == 0) { return(null); } byte[] passwordBytes = GetPasswordBytes(password); return(Blake2.Hash(passwordBytes)); }
private static byte[] GetFileBytes(string filePath, bool preHash) { if (!preHash) { return(File.ReadAllBytes(filePath)); } using var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, Constants.FileStreamBufferSize, FileOptions.SequentialScan); return(Blake2.Hash(fileStream)); }
public static byte[] ReadKeyfile(string keyfilePath) { using var keyfile = new FileStream(keyfilePath, FileMode.Open, FileAccess.Read, FileShare.Read, Constants.FileStreamBufferSize, FileOptions.SequentialScan); if (keyfile.Length == Constants.KeyfileLength) { byte[] keyfileBytes = new byte[Constants.KeyfileLength]; keyfile.Read(keyfileBytes, offset: 0, keyfileBytes.Length); return(keyfileBytes); } return(Blake2.Hash(keyfile)); }
private static byte[] GetFileBytes(string filePath, bool preHashed) { int oneGibibyte = 1024 * Constants.Mebibyte; long fileSize = FileHandling.GetFileLength(filePath); if (fileSize >= oneGibibyte || preHashed) { using var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, Constants.FileStreamBufferSize, FileOptions.SequentialScan); return(Blake2.Hash(fileStream)); } return(File.ReadAllBytes(filePath)); }
public static bool Compare(char[] a, char[] b) { // Constant time comparison byte[] aBytes = Encoding.UTF8.GetBytes(a); byte[] aHash = Blake2.Hash(aBytes); CryptographicOperations.ZeroMemory(aBytes); byte[] bBytes = Encoding.UTF8.GetBytes(b); byte[] bHash = Blake2.Hash(bBytes); CryptographicOperations.ZeroMemory(bBytes); bool equal = Utilities.Compare(aHash, bHash); CryptographicOperations.ZeroMemory(aHash); CryptographicOperations.ZeroMemory(bHash); return(equal); }
private static byte[] CombineKeyfileAndPassword(byte[] passwordBytes, byte[] keyfileBytes) { passwordBytes = Blake2.KeyedHash(passwordBytes, keyfileBytes); Utilities.ZeroArray(keyfileBytes); return(passwordBytes); }
private static byte[] CombineKeyfileAndPassword(byte[] passwordBytes, byte[] keyfileBytes) { passwordBytes = Blake2.KeyedHash(passwordBytes, keyfileBytes); CryptographicOperations.ZeroMemory(keyfileBytes); return(passwordBytes); }
public static byte[] ReadKeyfile(string keyfilePath) { using var keyfile = new FileStream(keyfilePath, FileMode.Open, FileAccess.Read, FileShare.Read, Constants.FileStreamBufferSize, FileOptions.SequentialScan); return Blake2.Hash(keyfile); }
public static byte[] KeyEncryptionKey(byte[] ephemeralSharedSecret, byte[] salt) { byte[] keyEncryptionKey = Blake2.KeyDerivation(ephemeralSharedSecret, salt, Constants.EncryptionKeyLength); Utilities.ZeroArray(ephemeralSharedSecret); return(keyEncryptionKey); }
public static byte[] KeyEncryptionKey(byte[] ephemeralSharedSecret, byte[] salt) { byte[] keyEncryptionKey = Blake2.KeyDerivation(ephemeralSharedSecret, salt, Constants.EncryptionKeyLength); CryptographicOperations.ZeroMemory(ephemeralSharedSecret); return(keyEncryptionKey); }