mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
ModernKeePassLib custom PCL version
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -19,13 +19,17 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using System.Security;
|
||||
|
||||
namespace ModernKeePassLib.Cryptography.Cipher
|
||||
{
|
||||
/// <summary>
|
||||
/// Pool of encryption/decryption algorithms (ciphers).
|
||||
/// </summary>
|
||||
public sealed class CipherPool
|
||||
/// <summary>
|
||||
/// Pool of encryption/decryption algorithms (ciphers).
|
||||
/// </summary>
|
||||
public sealed class CipherPool
|
||||
{
|
||||
private List<ICipherEngine> m_vCiphers = new List<ICipherEngine>();
|
||||
private static CipherPool m_poolGlobal = null;
|
||||
@@ -65,7 +69,7 @@ namespace ModernKeePassLib.Cryptography.Cipher
|
||||
|
||||
// Return if a cipher with that ID is registered already.
|
||||
for(int i = 0; i < m_vCiphers.Count; ++i)
|
||||
if(m_vCiphers[i].CipherUuid.EqualsValue(csEngine.CipherUuid))
|
||||
if(m_vCiphers[i].CipherUuid.Equals(csEngine.CipherUuid))
|
||||
return;
|
||||
|
||||
m_vCiphers.Add(csEngine);
|
||||
@@ -81,7 +85,7 @@ namespace ModernKeePassLib.Cryptography.Cipher
|
||||
{
|
||||
foreach(ICipherEngine iEngine in m_vCiphers)
|
||||
{
|
||||
if(iEngine.CipherUuid.EqualsValue(uuidCipher))
|
||||
if(iEngine.CipherUuid.Equals(uuidCipher))
|
||||
return iEngine;
|
||||
}
|
||||
|
||||
@@ -99,7 +103,7 @@ namespace ModernKeePassLib.Cryptography.Cipher
|
||||
{
|
||||
for(int i = 0; i < m_vCiphers.Count; ++i)
|
||||
{
|
||||
if(m_vCiphers[i].CipherUuid.EqualsValue(uuidCipher))
|
||||
if(m_vCiphers[i].CipherUuid.Equals(uuidCipher))
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -26,7 +26,7 @@ using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Cryptography.Cipher
|
||||
{
|
||||
public sealed class Salsa20Cipher
|
||||
public sealed class Salsa20Cipher : IDisposable
|
||||
{
|
||||
private uint[] m_state = new uint[16];
|
||||
private uint[] m_x = new uint[16]; // Working buffer
|
||||
@@ -34,7 +34,7 @@ namespace ModernKeePassLib.Cryptography.Cipher
|
||||
private byte[] m_output = new byte[64];
|
||||
private int m_outputPos = 64;
|
||||
|
||||
private static readonly uint[] m_sigma = new uint[4]{
|
||||
private static readonly uint[] m_sigma = new uint[4] {
|
||||
0x61707865, 0x3320646E, 0x79622D32, 0x6B206574
|
||||
};
|
||||
|
||||
@@ -45,6 +45,17 @@ namespace ModernKeePassLib.Cryptography.Cipher
|
||||
}
|
||||
|
||||
~Salsa20Cipher()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Dispose(bool bDisposing)
|
||||
{
|
||||
// Clear sensitive data
|
||||
Array.Clear(m_state, 0, m_state.Length);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -17,22 +17,44 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Security;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.Security.Cryptography.Core;
|
||||
#if PCL
|
||||
using Windows.Security.Cryptography;
|
||||
#else
|
||||
|
||||
#if !KeePassRT
|
||||
using System.Security.Cryptography;
|
||||
#else
|
||||
using Org.BouncyCastle.Crypto;
|
||||
using Org.BouncyCastle.Crypto.Engines;
|
||||
using Org.BouncyCastle.Crypto.IO;
|
||||
using Org.BouncyCastle.Crypto.Modes;
|
||||
using Org.BouncyCastle.Crypto.Paddings;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
using ModernKeePassLib.Resources;
|
||||
using ModernKeePassLib.Serialization;
|
||||
|
||||
namespace ModernKeePassLib.Cryptography.Cipher
|
||||
{
|
||||
/// <summary>
|
||||
/// Standard AES cipher implementation.
|
||||
/// </summary>
|
||||
public sealed class StandardAesEngine : ICipherEngine
|
||||
/// <summary>
|
||||
/// Standard AES cipher implementation.
|
||||
/// </summary>
|
||||
public sealed class StandardAesEngine : ICipherEngine
|
||||
{
|
||||
// private const CipherMode m_rCipherMode = CipherMode.CBC;
|
||||
// private const PaddingMode m_rCipherPadding = PaddingMode.PKCS7;
|
||||
#if !PCL && !KeePassRT
|
||||
private const CipherMode m_rCipherMode = CipherMode.CBC;
|
||||
private const PaddingMode m_rCipherPadding = PaddingMode.PKCS7;
|
||||
#endif
|
||||
|
||||
private static PwUuid m_uuidAes = null;
|
||||
|
||||
@@ -54,7 +76,7 @@ namespace ModernKeePassLib.Cryptography.Cipher
|
||||
return m_uuidAes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the UUID of this cipher engine as <c>PwUuid</c> object.
|
||||
/// </summary>
|
||||
@@ -92,31 +114,41 @@ namespace ModernKeePassLib.Cryptography.Cipher
|
||||
}
|
||||
}
|
||||
|
||||
private static Stream CreateStream(Stream s, bool bEncrypt, byte[] pbKey, byte[] pbIV)
|
||||
{
|
||||
StandardAesEngine.ValidateArguments(s, bEncrypt, pbKey, pbIV);
|
||||
return new CryptoStream( s, "AES_CBC_PKCS7", bEncrypt, pbKey, pbIV);
|
||||
private static Stream CreateStream(Stream s, bool bEncrypt, byte[] pbKey, byte[] pbIV)
|
||||
{
|
||||
ValidateArguments(s, bEncrypt, pbKey, pbIV);
|
||||
#if PCL
|
||||
var provider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
|
||||
var key = provider.CreateSymmetricKey(CryptographicBuffer.GenerateRandom(32));
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
s.CopyTo(ms);
|
||||
if (bEncrypt)
|
||||
{
|
||||
return CryptographicEngine.Encrypt(key, ms.GetWindowsRuntimeBuffer(), CryptographicBuffer.GenerateRandom(16)).AsStream();
|
||||
}
|
||||
/*var encryptor = CryptographicEngine.CreateEncryptor(
|
||||
key, pbLocalIV);
|
||||
return new CryptoStream(s, encryptor, CryptoStreamMode.Write);*/
|
||||
|
||||
return CryptographicEngine.Decrypt(key, ms.GetWindowsRuntimeBuffer(), CryptographicBuffer.GenerateRandom(16)).AsStream();
|
||||
/*var decryptor = CryptographicEngine.CreateDecryptor(
|
||||
key, pbLocalIV);
|
||||
return new CryptoStream(s, decryptor, CryptoStreamMode.Read);*/
|
||||
}
|
||||
#else
|
||||
|
||||
}
|
||||
#if false
|
||||
|
||||
#if !KeePassRT
|
||||
RijndaelManaged r = new RijndaelManaged();
|
||||
|
||||
if(r.BlockSize != 128) // AES block size
|
||||
{
|
||||
Debug.Assert(false);
|
||||
r.BlockSize = 128;
|
||||
}
|
||||
|
||||
byte[] pbLocalIV = new byte[16];
|
||||
Array.Copy(pbIV, pbLocalIV, 16);
|
||||
r.IV = pbLocalIV;
|
||||
|
||||
byte[] pbLocalKey = new byte[32];
|
||||
Array.Copy(pbKey, pbLocalKey, 32);
|
||||
r.KeySize = 256;
|
||||
r.Key = pbLocalKey;
|
||||
|
||||
r.Mode = m_rCipherMode;
|
||||
r.Padding = m_rCipherPadding;
|
||||
|
||||
@@ -126,11 +158,24 @@ namespace ModernKeePassLib.Cryptography.Cipher
|
||||
|
||||
return new CryptoStream(s, iTransform, bEncrypt ? CryptoStreamMode.Write :
|
||||
CryptoStreamMode.Read);
|
||||
}
|
||||
#else
|
||||
AesEngine aes = new AesEngine();
|
||||
CbcBlockCipher cbc = new CbcBlockCipher(aes);
|
||||
PaddedBufferedBlockCipher bc = new PaddedBufferedBlockCipher(cbc,
|
||||
new Pkcs7Padding());
|
||||
KeyParameter kp = new KeyParameter(pbLocalKey);
|
||||
ParametersWithIV prmIV = new ParametersWithIV(kp, pbLocalIV);
|
||||
bc.Init(bEncrypt, prmIV);
|
||||
|
||||
IBufferedCipher cpRead = (bEncrypt ? null : bc);
|
||||
IBufferedCipher cpWrite = (bEncrypt ? bc : null);
|
||||
return new CipherStream(s, cpRead, cpWrite);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
public Stream EncryptStream(Stream sPlainText, byte[] pbKey, byte[] pbIV)
|
||||
public Stream EncryptStream(Stream sPlainText, byte[] pbKey, byte[] pbIV)
|
||||
{
|
||||
return StandardAesEngine.CreateStream(sPlainText, true, pbKey, pbIV);
|
||||
}
|
||||
@@ -139,7 +184,5 @@ namespace ModernKeePassLib.Cryptography.Cipher
|
||||
{
|
||||
return StandardAesEngine.CreateStream(sEncrypted, false, pbKey, pbIV);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -18,26 +18,37 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Security;
|
||||
#if PCL
|
||||
using Windows.Security.Cryptography;
|
||||
//using System.Windows.Forms;
|
||||
//using System.Drawing;
|
||||
|
||||
#else
|
||||
using System.Security.Cryptography;
|
||||
#endif
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.Security.Cryptography.Core;
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Cryptography
|
||||
{
|
||||
/// <summary>
|
||||
/// Cryptographically strong random number generator. The returned values
|
||||
/// are unpredictable and cannot be reproduced.
|
||||
/// <c>CryptoRandom</c> is a singleton class.
|
||||
/// </summary>
|
||||
public sealed class CryptoRandom
|
||||
/// <summary>
|
||||
/// Cryptographically strong random number generator. The returned values
|
||||
/// are unpredictable and cannot be reproduced.
|
||||
/// <c>CryptoRandom</c> is a singleton class.
|
||||
/// </summary>
|
||||
public sealed class CryptoRandom
|
||||
{
|
||||
//private byte[] m_pbEntropyPool = new byte[64];
|
||||
//private uint m_uCounter;
|
||||
//private RNGCryptoServiceProvider m_rng = new RNGCryptoServiceProvider();
|
||||
//private ulong m_uGeneratedBytesCount = 0;
|
||||
private byte[] m_pbEntropyPool = new byte[64];
|
||||
private uint m_uCounter;
|
||||
#if PCL
|
||||
//private IRandomNumberGenerator m_rng = NetFxCrypto.RandomNumberGenerator;
|
||||
#else
|
||||
private RNGCryptoServiceProvider m_rng = new RNGCryptoServiceProvider();
|
||||
#endif
|
||||
private ulong m_uGeneratedBytesCount = 0;
|
||||
|
||||
// private object m_oSyncRoot = new object();
|
||||
private object m_oSyncRoot = new object();
|
||||
|
||||
private static CryptoRandom m_pInstance = null;
|
||||
public static CryptoRandom Instance
|
||||
@@ -51,44 +62,7 @@ namespace ModernKeePassLib.Cryptography
|
||||
}
|
||||
}
|
||||
|
||||
#if KeePassWinRT
|
||||
private CryptoRandom()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the internal seed of the random number generator based
|
||||
/// on entropy data.
|
||||
/// This method is thread-safe.
|
||||
/// </summary>
|
||||
/// <param name="pbEntropy">Entropy bytes.</param>
|
||||
public void AddEntropy(byte[] pbEntropy)
|
||||
{
|
||||
// Not used in WinRT version
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a number of cryptographically strong random bytes.
|
||||
/// This method is thread-safe.
|
||||
/// </summary>
|
||||
/// <param name="uRequestedBytes">Number of requested random bytes.</param>
|
||||
/// <returns>A byte array consisting of <paramref name="uRequestedBytes" />
|
||||
/// random bytes.</returns>
|
||||
public byte[] GetRandomBytes(uint uRequestedBytes)
|
||||
{
|
||||
if (uRequestedBytes == 0) return new byte[0]; // Allow zero-length array
|
||||
|
||||
byte[] pbRes;
|
||||
|
||||
Windows.Storage.Streams.IBuffer buffer = CryptographicBuffer.GenerateRandom(uRequestedBytes);
|
||||
CryptographicBuffer.CopyToByteArray(buffer, out pbRes);
|
||||
return pbRes;
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
/// <summary>
|
||||
/// Get the number of random bytes that this instance generated so far.
|
||||
/// Note that this number can be higher than the number of random bytes
|
||||
/// actually requested using the <c>GetRandomBytes</c> method.
|
||||
@@ -126,19 +100,25 @@ namespace ModernKeePassLib.Cryptography
|
||||
/// <param name="pbEntropy">Entropy bytes.</param>
|
||||
public void AddEntropy(byte[] pbEntropy)
|
||||
{
|
||||
|
||||
if(pbEntropy == null) { Debug.Assert(false); return; }
|
||||
if(pbEntropy.Length == 0) { Debug.Assert(false); return; }
|
||||
|
||||
byte[] pbNewData = pbEntropy;
|
||||
if(pbEntropy.Length >= 64)
|
||||
{
|
||||
#if !KeePassLibSD
|
||||
#if PCL
|
||||
var shaNew = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha512);
|
||||
pbNewData = shaNew.HashData(pbEntropy.AsBuffer()).ToArray();
|
||||
#else
|
||||
|
||||
#if !KeePassLibSD
|
||||
SHA512Managed shaNew = new SHA512Managed();
|
||||
#else
|
||||
SHA256Managed shaNew = new SHA256Managed();
|
||||
#endif
|
||||
pbNewData = shaNew.ComputeHash(pbEntropy);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
@@ -148,6 +128,11 @@ namespace ModernKeePassLib.Cryptography
|
||||
ms.Write(pbNewData, 0, pbNewData.Length);
|
||||
|
||||
byte[] pbFinal = ms.ToArray();
|
||||
#if PCL
|
||||
var shaPool = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha512);
|
||||
m_pbEntropyPool = shaPool.HashData(pbFinal.AsBuffer()).ToArray();
|
||||
#else
|
||||
|
||||
#if !KeePassLibSD
|
||||
Debug.Assert(pbFinal.Length == (64 + pbNewData.Length));
|
||||
SHA512Managed shaPool = new SHA512Managed();
|
||||
@@ -155,16 +140,14 @@ namespace ModernKeePassLib.Cryptography
|
||||
SHA256Managed shaPool = new SHA256Managed();
|
||||
#endif
|
||||
m_pbEntropyPool = shaPool.ComputeHash(pbFinal);
|
||||
|
||||
#endif
|
||||
}
|
||||
ms.Close();
|
||||
|
||||
ms.Dispose();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static byte[] GetSystemData(Random rWeak)
|
||||
{
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
byte[] pb;
|
||||
|
||||
@@ -174,21 +157,36 @@ namespace ModernKeePassLib.Cryptography
|
||||
pb = TimeUtil.PackTime(DateTime.Now);
|
||||
ms.Write(pb, 0, pb.Length);
|
||||
|
||||
#if !KeePassLibSD
|
||||
Point pt = Cursor.Position;
|
||||
pb = MemUtil.UInt32ToBytes((uint)pt.X);
|
||||
ms.Write(pb, 0, pb.Length);
|
||||
pb = MemUtil.UInt32ToBytes((uint)pt.Y);
|
||||
ms.Write(pb, 0, pb.Length);
|
||||
#if (!PCL && !KeePassLibSD && !KeePassRT)
|
||||
// In try-catch for systems without GUI;
|
||||
// https://sourceforge.net/p/keepass/discussion/329221/thread/20335b73/
|
||||
try
|
||||
{
|
||||
Point pt = Cursor.Position;
|
||||
pb = MemUtil.UInt32ToBytes((uint)pt.X);
|
||||
ms.Write(pb, 0, pb.Length);
|
||||
pb = MemUtil.UInt32ToBytes((uint)pt.Y);
|
||||
ms.Write(pb, 0, pb.Length);
|
||||
}
|
||||
catch(Exception) { }
|
||||
#endif
|
||||
|
||||
pb = MemUtil.UInt32ToBytes((uint)rWeak.Next());
|
||||
ms.Write(pb, 0, pb.Length);
|
||||
|
||||
pb = MemUtil.UInt32ToBytes((uint)NativeLib.GetPlatformID());
|
||||
#if PCL
|
||||
pb = MemUtil.UInt32ToBytes((uint)Environment.ProcessorCount);
|
||||
ms.Write(pb, 0, pb.Length);
|
||||
|
||||
#if !KeePassLibSD
|
||||
pb = MemUtil.UInt32ToBytes((uint)Environment.CurrentManagedThreadId);
|
||||
ms.Write(pb, 0, pb.Length);
|
||||
#else
|
||||
pb = MemUtil.UInt32ToBytes((uint)NativeLib.GetPlatformID());
|
||||
ms.Write(pb, 0, pb.Length);
|
||||
#endif
|
||||
|
||||
#if (!PCL && !KeePassLibSD && !KeePassRT)
|
||||
Process p = null;
|
||||
try
|
||||
{
|
||||
pb = MemUtil.UInt32ToBytes((uint)Environment.ProcessorCount);
|
||||
@@ -197,13 +195,11 @@ namespace ModernKeePassLib.Cryptography
|
||||
ms.Write(pb, 0, pb.Length);
|
||||
|
||||
Version v = Environment.OSVersion.Version;
|
||||
int nv = (v.Major << 28) + (v.MajorRevision << 24) +
|
||||
(v.Minor << 20) + (v.MinorRevision << 16) +
|
||||
(v.Revision << 12) + v.Build;
|
||||
pb = MemUtil.UInt32ToBytes((uint)nv);
|
||||
pb = MemUtil.UInt32ToBytes((uint)v.GetHashCode());
|
||||
ms.Write(pb, 0, pb.Length);
|
||||
|
||||
Process p = Process.GetCurrentProcess();
|
||||
p = Process.GetCurrentProcess();
|
||||
|
||||
pb = MemUtil.UInt64ToBytes((ulong)p.Handle.ToInt64());
|
||||
ms.Write(pb, 0, pb.Length);
|
||||
pb = MemUtil.UInt32ToBytes((uint)p.HandleCount);
|
||||
@@ -236,33 +232,31 @@ namespace ModernKeePassLib.Cryptography
|
||||
// ms.Write(pb, 0, pb.Length);
|
||||
}
|
||||
catch(Exception) { }
|
||||
finally
|
||||
{
|
||||
try { if(p != null) p.Dispose(); }
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
}
|
||||
#endif
|
||||
|
||||
pb = Guid.NewGuid().ToByteArray();
|
||||
ms.Write(pb, 0, pb.Length);
|
||||
|
||||
byte[] pbAll = ms.ToArray();
|
||||
ms.Close();
|
||||
ms.Dispose();
|
||||
return pbAll;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private byte[] GetCspData()
|
||||
{
|
||||
uint length = 32;
|
||||
byte[] pbCspRandom = new byte[length];
|
||||
|
||||
Windows.Storage.Streams.IBuffer buffer = CryptographicBuffer.GenerateRandom(length);
|
||||
|
||||
CryptographicBuffer.CopyToByteArray(buffer, pbCspRandom);
|
||||
//byte[] pbCspRandom = new byte[32];
|
||||
var pbCspRandom = CryptographicBuffer.GenerateRandom(32);
|
||||
//m_rng.GetBytes(pbCspRandom);
|
||||
return pbCspRandom;
|
||||
return pbCspRandom.ToArray();
|
||||
}
|
||||
|
||||
private byte[] GenerateRandom256()
|
||||
{
|
||||
|
||||
if(this.GenerateRandom256Pre != null)
|
||||
this.GenerateRandom256Pre(this, EventArgs.Empty);
|
||||
|
||||
@@ -281,16 +275,20 @@ namespace ModernKeePassLib.Cryptography
|
||||
pbFinal = ms.ToArray();
|
||||
Debug.Assert(pbFinal.Length == (m_pbEntropyPool.Length +
|
||||
pbCounter.Length + pbCspRandom.Length));
|
||||
ms.Close();
|
||||
ms.Dispose();
|
||||
|
||||
m_uGeneratedBytesCount += 32;
|
||||
}
|
||||
|
||||
#if PCL
|
||||
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
|
||||
return sha256.HashData(pbFinal.AsBuffer()).ToArray();
|
||||
#else
|
||||
SHA256Managed sha256 = new SHA256Managed();
|
||||
return sha256.ComputeHash(pbFinal);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a number of cryptographically strong random bytes.
|
||||
/// This method is thread-safe.
|
||||
@@ -312,7 +310,7 @@ namespace ModernKeePassLib.Cryptography
|
||||
|
||||
long lCopy = (long)((uRequestedBytes < 32) ? uRequestedBytes : 32);
|
||||
|
||||
#if !KeePassLibSD
|
||||
#if (!PCL && !KeePassLibSD && !KeePassRT)
|
||||
Array.Copy(pbRandom256, 0, pbRes, lPos, lCopy);
|
||||
#else
|
||||
Array.Copy(pbRandom256, 0, pbRes, (int)lPos, (int)lCopy);
|
||||
@@ -325,8 +323,5 @@ namespace ModernKeePassLib.Cryptography
|
||||
Debug.Assert((int)lPos == pbRes.Length);
|
||||
return pbRes;
|
||||
}
|
||||
|
||||
#endif // !KeePassWinRT
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -18,15 +18,23 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.Security.Cryptography.Core;
|
||||
#if PCL
|
||||
using Windows.Security.Cryptography;
|
||||
#else
|
||||
using System.Security.Cryptography;
|
||||
#endif
|
||||
|
||||
using ModernKeePassLib.Cryptography.Cipher;
|
||||
|
||||
namespace ModernKeePassLib.Cryptography
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithms supported by <c>CryptoRandomStream</c>.
|
||||
/// </summary>
|
||||
public enum CrsAlgorithm
|
||||
/// <summary>
|
||||
/// Algorithms supported by <c>CryptoRandomStream</c>.
|
||||
/// </summary>
|
||||
public enum CrsAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Not supported.
|
||||
@@ -109,13 +117,17 @@ namespace ModernKeePassLib.Cryptography
|
||||
}
|
||||
else if(genAlgorithm == CrsAlgorithm.Salsa20)
|
||||
{
|
||||
byte[] pbKey32 = SHA256Managed.Instance.ComputeHash(pbKey);
|
||||
|
||||
byte[] pbIV = new byte[]{ 0xE8, 0x30, 0x09, 0x4B,
|
||||
#if PCL
|
||||
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
|
||||
var pbKey32 = sha256.HashData(pbKey.AsBuffer()).ToArray();
|
||||
#else
|
||||
SHA256Managed sha256 = new SHA256Managed();
|
||||
byte[] pbKey32 = sha256.ComputeHash(pbKey);
|
||||
#endif
|
||||
byte[] pbIV = new byte[8] { 0xE8, 0x30, 0x09, 0x4B,
|
||||
0x97, 0x20, 0x5D, 0x2A }; // Unique constant
|
||||
|
||||
m_salsa20 = new Salsa20Cipher(pbKey32, pbIV);
|
||||
|
||||
}
|
||||
else // Unknown algorithm
|
||||
{
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -17,85 +17,80 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using ModernKeePassLib.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
#if PCL
|
||||
using Windows.Security.Cryptography;
|
||||
#else
|
||||
using System.Security.Cryptography;
|
||||
#endif
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.Security.Cryptography.Core;
|
||||
using ModernKeePassLib.Utility;
|
||||
using CryptographicHash = Windows.Security.Cryptography.Core.CryptographicHash;
|
||||
|
||||
namespace ModernKeePassLib.Cryptography
|
||||
{
|
||||
public sealed class HashingStreamEx : Stream
|
||||
{
|
||||
private Stream m_sBaseStream;
|
||||
private bool m_bWriting;
|
||||
private Queue<byte[]> m_DataToHash;
|
||||
//private HashAlgorithm m_hash;
|
||||
|
||||
public byte[] Hash
|
||||
{
|
||||
get
|
||||
{
|
||||
int len = 0;
|
||||
foreach (byte[] block in m_DataToHash)
|
||||
{
|
||||
len += block.Length;
|
||||
}
|
||||
byte[] dataToHash = new byte[len];
|
||||
int pos = 0;
|
||||
while(m_DataToHash.Count > 0)
|
||||
{
|
||||
byte[] block = m_DataToHash.Dequeue();
|
||||
Array.Copy(block, 0, dataToHash, pos, block.Length);
|
||||
pos += block.Length;
|
||||
}
|
||||
|
||||
byte[] hash = SHA256Managed.Instance.ComputeHash(dataToHash);
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return !m_bWriting; }
|
||||
}
|
||||
|
||||
public override bool CanSeek
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return m_bWriting; }
|
||||
}
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get { return m_sBaseStream.Length; }
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get { return m_sBaseStream.Position; }
|
||||
set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public HashingStreamEx(Stream sBaseStream, bool bWriting, CryptographicHash hashAlgorithm)
|
||||
{
|
||||
if (sBaseStream == null) throw new ArgumentNullException("sBaseStream");
|
||||
|
||||
m_sBaseStream = sBaseStream;
|
||||
m_bWriting = bWriting;
|
||||
|
||||
#if KeePassWinRT
|
||||
|
||||
m_DataToHash = new Queue<byte[]>();
|
||||
|
||||
|
||||
public sealed class HashingStreamEx : Stream
|
||||
{
|
||||
private Stream m_sBaseStream;
|
||||
private bool m_bWriting;
|
||||
#if PCL
|
||||
private CryptographicHash m_hash;
|
||||
#else
|
||||
#if !KeePassLibSD
|
||||
private HashAlgorithm m_hash;
|
||||
#endif
|
||||
|
||||
private byte[] m_pbFinalHash = null;
|
||||
|
||||
public byte[] Hash
|
||||
{
|
||||
get { return m_pbFinalHash; }
|
||||
}
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return !m_bWriting; }
|
||||
}
|
||||
|
||||
public override bool CanSeek
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return m_bWriting; }
|
||||
}
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get { return m_sBaseStream.Length; }
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get { return m_sBaseStream.Position; }
|
||||
set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
#if PCL
|
||||
public HashingStreamEx(Stream sBaseStream, bool bWriting, string hashAlgorithm)
|
||||
#else
|
||||
public HashingStreamEx(Stream sBaseStream, bool bWriting, HashAlgorithm hashAlgorithm)
|
||||
#endif
|
||||
{
|
||||
if(sBaseStream == null)
|
||||
throw new ArgumentNullException("sBaseStream");
|
||||
|
||||
m_sBaseStream = sBaseStream;
|
||||
m_bWriting = bWriting;
|
||||
#if PCL
|
||||
m_hash = HashAlgorithmProvider.OpenAlgorithm(hashAlgorithm ?? HashAlgorithmNames.Sha256).CreateHash();
|
||||
#elif !KeePassLibSD
|
||||
m_hash = (hashAlgorithm ?? new SHA256Managed());
|
||||
#else // KeePassLibSD
|
||||
m_hash = null;
|
||||
@@ -105,91 +100,98 @@ namespace ModernKeePassLib.Cryptography
|
||||
try { if(m_hash == null) m_hash = HashAlgorithm.Create(); }
|
||||
catch(Exception) { }
|
||||
#endif
|
||||
#endif // KeePassWinRT
|
||||
if(m_hash == null) { Debug.Assert(false); return; }
|
||||
|
||||
|
||||
#if TODO
|
||||
// Bert TODO: For the time being, only built-in Hash algorithm are supported.
|
||||
if (m_hash == null) { Debug.Assert(false); return; }
|
||||
// Validate hash algorithm
|
||||
if((!m_hash.CanReuseTransform) || (!m_hash.CanTransformMultipleBlocks) ||
|
||||
/*if((!m_hash.CanReuseTransform) || (!m_hash.CanTransformMultipleBlocks) ||
|
||||
(m_hash.InputBlockSize != 1) || (m_hash.OutputBlockSize != 1))
|
||||
{
|
||||
#if DEBUG
|
||||
#if false && DEBUG
|
||||
MessageService.ShowWarning("Broken HashAlgorithm object in HashingStreamEx.");
|
||||
#endif
|
||||
m_hash = null;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
m_sBaseStream.Flush();
|
||||
}
|
||||
|
||||
/*public override void Close()
|
||||
public override void Flush()
|
||||
{
|
||||
m_sBaseStream.Flush();
|
||||
}
|
||||
|
||||
#if PCL || KeePassRT
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if(!disposing) return;
|
||||
#else
|
||||
public override void Close()
|
||||
{
|
||||
#endif
|
||||
if(m_hash != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_hash.TransformFinalBlock(new byte[0], 0, 0);
|
||||
|
||||
//m_hash.TransformFinalBlock(new byte[0], 0, 0);
|
||||
#if PCL
|
||||
m_pbFinalHash = m_hash.GetValueAndReset().ToArray();
|
||||
#else
|
||||
m_pbFinalHash = m_hash.Hash;
|
||||
#endif
|
||||
}
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
|
||||
m_hash = null;
|
||||
}
|
||||
|
||||
m_sBaseStream.Close();
|
||||
m_sBaseStream.Dispose();
|
||||
}
|
||||
|
||||
}*/
|
||||
public override long Seek(long lOffset, SeekOrigin soOrigin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override long Seek(long lOffset, SeekOrigin soOrigin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public override void SetLength(long lValue)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void SetLength(long lValue)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public override int Read(byte[] pbBuffer, int nOffset, int nCount)
|
||||
{
|
||||
if(m_bWriting) throw new InvalidOperationException();
|
||||
|
||||
public override int Read(byte[] pbBuffer, int nOffset, int nCount)
|
||||
{
|
||||
int nRead = m_sBaseStream.Read(pbBuffer, nOffset, nCount);
|
||||
int nPartialRead = nRead;
|
||||
while((nRead < nCount) && (nPartialRead != 0))
|
||||
{
|
||||
nPartialRead = m_sBaseStream.Read(pbBuffer, nOffset + nRead,
|
||||
nCount - nRead);
|
||||
nRead += nPartialRead;
|
||||
}
|
||||
|
||||
if (m_bWriting) throw new InvalidOperationException();
|
||||
#if DEBUG
|
||||
byte[] pbOrg = new byte[pbBuffer.Length];
|
||||
Array.Copy(pbBuffer, pbOrg, pbBuffer.Length);
|
||||
#endif
|
||||
|
||||
int nRead = m_sBaseStream.Read(pbBuffer, nOffset, nCount);
|
||||
/*if((m_hash != null) && (nRead > 0))
|
||||
m_hash.TransformBlock(pbBuffer, nOffset, nRead, pbBuffer, nOffset);*/
|
||||
|
||||
// Mono bug workaround (LaunchPad 798910)
|
||||
int nPartialRead = nRead;
|
||||
while ((nRead < nCount) && (nPartialRead != 0))
|
||||
{
|
||||
nPartialRead = m_sBaseStream.Read(pbBuffer, nOffset + nRead,
|
||||
nCount - nRead);
|
||||
nRead += nPartialRead;
|
||||
}
|
||||
#if DEBUG
|
||||
Debug.Assert(MemUtil.ArraysEqual(pbBuffer, pbOrg));
|
||||
#endif
|
||||
|
||||
byte[] pbOrg = new byte[nRead];
|
||||
Array.Copy(pbBuffer, pbOrg, nRead);
|
||||
m_DataToHash.Enqueue(pbOrg);
|
||||
|
||||
return nRead;
|
||||
}
|
||||
return nRead;
|
||||
}
|
||||
|
||||
public override void Write(byte[] pbBuffer, int nOffset, int nCount)
|
||||
{
|
||||
public override void Write(byte[] pbBuffer, int nOffset, int nCount)
|
||||
{
|
||||
if(!m_bWriting) throw new InvalidOperationException();
|
||||
|
||||
#if DEBUG
|
||||
byte[] pbOrg = new byte[pbBuffer.Length];
|
||||
Array.Copy(pbBuffer, pbOrg, pbBuffer.Length);
|
||||
#endif
|
||||
// TODO: implement this
|
||||
|
||||
/*if((m_hash != null) && (nCount > 0))
|
||||
m_hash.TransformBlock(pbBuffer, nOffset, nCount, pbBuffer, nOffset);*/
|
||||
|
||||
@@ -198,7 +200,6 @@ namespace ModernKeePassLib.Cryptography
|
||||
#endif
|
||||
|
||||
m_sBaseStream.Write(pbBuffer, nOffset, nCount);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -17,15 +17,23 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
using System;
|
||||
#if PCL
|
||||
using Windows.Security.Cryptography.Core;
|
||||
#else
|
||||
using System.Security.Cryptography;
|
||||
#endif
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
|
||||
#if !KeePassLibSD
|
||||
#if (!KeePassLibSD && !KeePassRT)
|
||||
namespace ModernKeePassLib.Cryptography
|
||||
{
|
||||
/// <summary>
|
||||
/// Generate HMAC-based one-time passwords as specified in RFC 4226.
|
||||
/// </summary>
|
||||
public static class HmacOtp
|
||||
/// <summary>
|
||||
/// Generate HMAC-based one-time passwords as specified in RFC 4226.
|
||||
/// </summary>
|
||||
public static class HmacOtp
|
||||
{
|
||||
private static readonly uint[] vDigitsPower = new uint[]{ 1, 10, 100,
|
||||
1000, 10000, 100000, 1000000, 10000000, 100000000 };
|
||||
@@ -33,14 +41,17 @@ namespace ModernKeePassLib.Cryptography
|
||||
public static string Generate(byte[] pbSecret, ulong uFactor,
|
||||
uint uCodeDigits, bool bAddChecksum, int iTruncationOffset)
|
||||
{
|
||||
Debug.Assert(false, "Not yet implemented");
|
||||
return null;
|
||||
#if TODO
|
||||
byte[] pbText = MemUtil.UInt64ToBytes(uFactor);
|
||||
Array.Reverse(pbText); // Big-Endian
|
||||
|
||||
#if PCL
|
||||
var hsha1 = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha1).CreateHash(pbSecret.AsBuffer());
|
||||
hsha1.Append(pbText.AsBuffer());
|
||||
var pbHash = hsha1.GetValueAndReset().ToArray();
|
||||
#else
|
||||
HMACSHA1 hsha1 = new HMACSHA1(pbSecret);
|
||||
byte[] pbHash = hsha1.ComputeHash(pbText);
|
||||
#endif
|
||||
|
||||
uint uOffset = (uint)(pbHash[pbHash.Length - 1] & 0xF);
|
||||
if((iTruncationOffset >= 0) && (iTruncationOffset < (pbHash.Length - 4)))
|
||||
@@ -56,8 +67,8 @@ namespace ModernKeePassLib.Cryptography
|
||||
uOtp = ((uOtp * 10) + CalculateChecksum(uOtp, uCodeDigits));
|
||||
|
||||
uint uDigits = (bAddChecksum ? (uCodeDigits + 1) : uCodeDigits);
|
||||
return uOtp.ToString().PadLeft((int)uDigits, '0');
|
||||
#endif
|
||||
return uOtp.ToString(NumberFormatInfo.InvariantInfo).PadLeft(
|
||||
(int)uDigits, '0');
|
||||
}
|
||||
|
||||
private static readonly uint[] vDoubleDigits = new uint[]{ 0, 2, 4, 6, 8,
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -66,7 +66,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
|
||||
foreach(CustomPwGenerator pwg in m_vGens)
|
||||
{
|
||||
if(uuid.EqualsValue(pwg.Uuid)) return pwg;
|
||||
if(uuid.Equals(pwg.Uuid)) return pwg;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -90,7 +90,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
|
||||
for(int i = 0; i < m_vGens.Count; ++i)
|
||||
{
|
||||
if(uuid.EqualsValue(m_vGens[i].Uuid)) return i;
|
||||
if(uuid.Equals(m_vGens[i].Uuid)) return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -67,6 +67,17 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
pcsUsed.Add(ch);
|
||||
}
|
||||
}
|
||||
else if(ch == '^')
|
||||
{
|
||||
ch = csStream.ReadChar();
|
||||
if(ch == char.MinValue) // ^ at the end
|
||||
{
|
||||
vGenerated.AddLast('^');
|
||||
break;
|
||||
}
|
||||
|
||||
if(bInCharSetDef) pcsCustom.Remove(ch);
|
||||
}
|
||||
else if(ch == '[')
|
||||
{
|
||||
pcsCustom.Clear();
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -46,51 +46,87 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
public const string Invalid = "\t\r\n";
|
||||
public const string LookAlike = @"O0l1I|";
|
||||
|
||||
internal const string MenuAccels = PwCharSet.LowerCase + PwCharSet.Digits;
|
||||
|
||||
private const int CharTabSize = (0x10000 / 8);
|
||||
|
||||
private List<char> m_vChars = new List<char>();
|
||||
private byte[] m_vTab = new byte[CharTabSize];
|
||||
|
||||
private string m_strHighAnsi = string.Empty;
|
||||
private string m_strSpecial = string.Empty;
|
||||
private static string m_strHighAnsi = null;
|
||||
public static string HighAnsiChars
|
||||
{
|
||||
get
|
||||
{
|
||||
if(m_strHighAnsi == null) { new PwCharSet(); } // Create string
|
||||
Debug.Assert(m_strHighAnsi != null);
|
||||
return m_strHighAnsi;
|
||||
}
|
||||
}
|
||||
|
||||
private static string m_strSpecial = null;
|
||||
public static string SpecialChars
|
||||
{
|
||||
get
|
||||
{
|
||||
if(m_strSpecial == null) { new PwCharSet(); } // Create string
|
||||
Debug.Assert(m_strSpecial != null);
|
||||
return m_strSpecial;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new, empty character set collection object.
|
||||
/// </summary>
|
||||
public PwCharSet()
|
||||
{
|
||||
this.Initialize(true);
|
||||
Initialize(true);
|
||||
}
|
||||
|
||||
public PwCharSet(string strCharSet)
|
||||
{
|
||||
this.Initialize(true);
|
||||
this.Add(strCharSet);
|
||||
Initialize(true);
|
||||
Add(strCharSet);
|
||||
}
|
||||
|
||||
private PwCharSet(bool bFullInitialize)
|
||||
{
|
||||
this.Initialize(bFullInitialize);
|
||||
Initialize(bFullInitialize);
|
||||
}
|
||||
|
||||
private void Initialize(bool bFullInitialize)
|
||||
{
|
||||
this.Clear();
|
||||
Clear();
|
||||
|
||||
if(bFullInitialize == false) return;
|
||||
if(!bFullInitialize) return;
|
||||
|
||||
StringBuilder sbHighAnsi = new StringBuilder();
|
||||
for(char ch = '~'; ch < 255; ++ch)
|
||||
sbHighAnsi.Append(ch);
|
||||
m_strHighAnsi = sbHighAnsi.ToString();
|
||||
if(m_strHighAnsi == null)
|
||||
{
|
||||
StringBuilder sbHighAnsi = new StringBuilder();
|
||||
// [U+0080, U+009F] are C1 control characters,
|
||||
// U+00A0 is non-breaking space
|
||||
for(char ch = '\u00A1'; ch <= '\u00AC'; ++ch)
|
||||
sbHighAnsi.Append(ch);
|
||||
// U+00AD is soft hyphen (format character)
|
||||
for(char ch = '\u00AE'; ch < '\u00FF'; ++ch)
|
||||
sbHighAnsi.Append(ch);
|
||||
sbHighAnsi.Append('\u00FF');
|
||||
|
||||
PwCharSet pcs = new PwCharSet(false);
|
||||
pcs.AddRange('!', '/');
|
||||
pcs.AddRange(':', '@');
|
||||
pcs.AddRange('[', '`');
|
||||
pcs.Remove(@"-_ ");
|
||||
pcs.Remove(PwCharSet.Brackets);
|
||||
m_strSpecial = pcs.ToString();
|
||||
m_strHighAnsi = sbHighAnsi.ToString();
|
||||
}
|
||||
|
||||
if(m_strSpecial == null)
|
||||
{
|
||||
PwCharSet pcs = new PwCharSet(false);
|
||||
pcs.AddRange('!', '/');
|
||||
pcs.AddRange(':', '@');
|
||||
pcs.AddRange('[', '`');
|
||||
pcs.Add(@"|~");
|
||||
pcs.Remove(@"-_ ");
|
||||
pcs.Remove(PwCharSet.Brackets);
|
||||
|
||||
m_strSpecial = pcs.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -118,9 +154,6 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
}
|
||||
}
|
||||
|
||||
public string SpecialChars { get { return m_strSpecial; } }
|
||||
public string HighAnsiChars { get { return m_strHighAnsi; } }
|
||||
|
||||
/// <summary>
|
||||
/// Remove all characters from this set.
|
||||
/// </summary>
|
||||
@@ -142,7 +175,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
|
||||
foreach(char ch in strCharacters)
|
||||
{
|
||||
if(this.Contains(ch) == false) return false;
|
||||
if(!Contains(ch)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -156,7 +189,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
{
|
||||
if(ch == char.MinValue) { Debug.Assert(false); return; }
|
||||
|
||||
if(this.Contains(ch) == false)
|
||||
if(!Contains(ch))
|
||||
{
|
||||
m_vChars.Add(ch);
|
||||
m_vTab[ch / 8] |= (byte)(1 << (ch % 8));
|
||||
@@ -175,20 +208,20 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
m_vChars.Capacity = m_vChars.Count + strCharSet.Length;
|
||||
|
||||
foreach(char ch in strCharSet)
|
||||
this.Add(ch);
|
||||
Add(ch);
|
||||
}
|
||||
|
||||
public void Add(string strCharSet1, string strCharSet2)
|
||||
{
|
||||
this.Add(strCharSet1);
|
||||
this.Add(strCharSet2);
|
||||
Add(strCharSet1);
|
||||
Add(strCharSet2);
|
||||
}
|
||||
|
||||
public void Add(string strCharSet1, string strCharSet2, string strCharSet3)
|
||||
{
|
||||
this.Add(strCharSet1);
|
||||
this.Add(strCharSet2);
|
||||
this.Add(strCharSet3);
|
||||
Add(strCharSet1);
|
||||
Add(strCharSet2);
|
||||
Add(strCharSet3);
|
||||
}
|
||||
|
||||
public void AddRange(char chMin, char chMax)
|
||||
@@ -196,9 +229,9 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
m_vChars.Capacity = m_vChars.Count + (chMax - chMin) + 1;
|
||||
|
||||
for(char ch = chMin; ch < chMax; ++ch)
|
||||
this.Add(ch);
|
||||
Add(ch);
|
||||
|
||||
this.Add(chMax);
|
||||
Add(chMax);
|
||||
}
|
||||
|
||||
public bool AddCharSet(char chCharSetIdentifier)
|
||||
@@ -207,29 +240,29 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
|
||||
switch(chCharSetIdentifier)
|
||||
{
|
||||
case 'a': this.Add(PwCharSet.LowerCase, PwCharSet.Digits); break;
|
||||
case 'A': this.Add(PwCharSet.LowerCase, PwCharSet.UpperCase,
|
||||
case 'a': Add(PwCharSet.LowerCase, PwCharSet.Digits); break;
|
||||
case 'A': Add(PwCharSet.LowerCase, PwCharSet.UpperCase,
|
||||
PwCharSet.Digits); break;
|
||||
case 'U': this.Add(PwCharSet.UpperCase, PwCharSet.Digits); break;
|
||||
case 'c': this.Add(PwCharSet.LowerConsonants); break;
|
||||
case 'C': this.Add(PwCharSet.LowerConsonants,
|
||||
case 'U': Add(PwCharSet.UpperCase, PwCharSet.Digits); break;
|
||||
case 'c': Add(PwCharSet.LowerConsonants); break;
|
||||
case 'C': Add(PwCharSet.LowerConsonants,
|
||||
PwCharSet.UpperConsonants); break;
|
||||
case 'z': this.Add(PwCharSet.UpperConsonants); break;
|
||||
case 'd': this.Add(PwCharSet.Digits); break; // Digit
|
||||
case 'h': this.Add(PwCharSet.LowerHex); break;
|
||||
case 'H': this.Add(PwCharSet.UpperHex); break;
|
||||
case 'l': this.Add(PwCharSet.LowerCase); break;
|
||||
case 'L': this.Add(PwCharSet.LowerCase, PwCharSet.UpperCase); break;
|
||||
case 'u': this.Add(PwCharSet.UpperCase); break;
|
||||
case 'p': this.Add(PwCharSet.Punctuation); break;
|
||||
case 'b': this.Add(PwCharSet.Brackets); break;
|
||||
case 's': this.Add(PwCharSet.PrintableAsciiSpecial); break;
|
||||
case 'S': this.Add(PwCharSet.UpperCase, PwCharSet.LowerCase);
|
||||
this.Add(PwCharSet.Digits, PwCharSet.PrintableAsciiSpecial); break;
|
||||
case 'v': this.Add(PwCharSet.LowerVowels); break;
|
||||
case 'V': this.Add(PwCharSet.LowerVowels, PwCharSet.UpperVowels); break;
|
||||
case 'Z': this.Add(PwCharSet.UpperVowels); break;
|
||||
case 'x': this.Add(m_strHighAnsi); break;
|
||||
case 'z': Add(PwCharSet.UpperConsonants); break;
|
||||
case 'd': Add(PwCharSet.Digits); break; // Digit
|
||||
case 'h': Add(PwCharSet.LowerHex); break;
|
||||
case 'H': Add(PwCharSet.UpperHex); break;
|
||||
case 'l': Add(PwCharSet.LowerCase); break;
|
||||
case 'L': Add(PwCharSet.LowerCase, PwCharSet.UpperCase); break;
|
||||
case 'u': Add(PwCharSet.UpperCase); break;
|
||||
case 'p': Add(PwCharSet.Punctuation); break;
|
||||
case 'b': Add(PwCharSet.Brackets); break;
|
||||
case 's': Add(PwCharSet.PrintableAsciiSpecial); break;
|
||||
case 'S': Add(PwCharSet.UpperCase, PwCharSet.LowerCase);
|
||||
Add(PwCharSet.Digits, PwCharSet.PrintableAsciiSpecial); break;
|
||||
case 'v': Add(PwCharSet.LowerVowels); break;
|
||||
case 'V': Add(PwCharSet.LowerVowels, PwCharSet.UpperVowels); break;
|
||||
case 'Z': Add(PwCharSet.UpperVowels); break;
|
||||
case 'x': Add(m_strHighAnsi); break;
|
||||
default: bResult = false; break;
|
||||
}
|
||||
|
||||
@@ -238,7 +271,7 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
|
||||
public bool Remove(char ch)
|
||||
{
|
||||
m_vTab[ch / 8] &= (byte)~(1 << (ch % 8));
|
||||
m_vTab[ch / 8] &= (byte)(~(1 << (ch % 8)));
|
||||
return m_vChars.Remove(ch);
|
||||
}
|
||||
|
||||
@@ -261,10 +294,10 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
Debug.Assert(strCharacters != null);
|
||||
if(strCharacters == null) throw new ArgumentNullException("strCharacters");
|
||||
|
||||
if(this.Contains(strCharacters) == false)
|
||||
if(!Contains(strCharacters))
|
||||
return false;
|
||||
|
||||
return this.Remove(strCharacters);
|
||||
return Remove(strCharacters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -284,16 +317,16 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.Append(this.RemoveIfAllExist(PwCharSet.UpperCase) ? 'U' : '_');
|
||||
sb.Append(this.RemoveIfAllExist(PwCharSet.LowerCase) ? 'L' : '_');
|
||||
sb.Append(this.RemoveIfAllExist(PwCharSet.Digits) ? 'D' : '_');
|
||||
sb.Append(this.RemoveIfAllExist(m_strSpecial) ? 'S' : '_');
|
||||
sb.Append(this.RemoveIfAllExist(PwCharSet.Punctuation) ? 'P' : '_');
|
||||
sb.Append(this.RemoveIfAllExist(@"-") ? 'm' : '_');
|
||||
sb.Append(this.RemoveIfAllExist(@"_") ? 'u' : '_');
|
||||
sb.Append(this.RemoveIfAllExist(@" ") ? 's' : '_');
|
||||
sb.Append(this.RemoveIfAllExist(PwCharSet.Brackets) ? 'B' : '_');
|
||||
sb.Append(this.RemoveIfAllExist(m_strHighAnsi) ? 'H' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.UpperCase) ? 'U' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.LowerCase) ? 'L' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.Digits) ? 'D' : '_');
|
||||
sb.Append(RemoveIfAllExist(m_strSpecial) ? 'S' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.Punctuation) ? 'P' : '_');
|
||||
sb.Append(RemoveIfAllExist(@"-") ? 'm' : '_');
|
||||
sb.Append(RemoveIfAllExist(@"_") ? 'u' : '_');
|
||||
sb.Append(RemoveIfAllExist(@" ") ? 's' : '_');
|
||||
sb.Append(RemoveIfAllExist(PwCharSet.Brackets) ? 'B' : '_');
|
||||
sb.Append(RemoveIfAllExist(m_strHighAnsi) ? 'H' : '_');
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
@@ -303,16 +336,16 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
if(strRanges == null) { Debug.Assert(false); return; }
|
||||
if(strRanges.Length < 10) { Debug.Assert(false); return; }
|
||||
|
||||
if(strRanges[0] != '_') this.Add(PwCharSet.UpperCase);
|
||||
if(strRanges[1] != '_') this.Add(PwCharSet.LowerCase);
|
||||
if(strRanges[2] != '_') this.Add(PwCharSet.Digits);
|
||||
if(strRanges[3] != '_') this.Add(m_strSpecial);
|
||||
if(strRanges[4] != '_') this.Add(PwCharSet.Punctuation);
|
||||
if(strRanges[5] != '_') this.Add('-');
|
||||
if(strRanges[6] != '_') this.Add('_');
|
||||
if(strRanges[7] != '_') this.Add(' ');
|
||||
if(strRanges[8] != '_') this.Add(PwCharSet.Brackets);
|
||||
if(strRanges[9] != '_') this.Add(m_strHighAnsi);
|
||||
if(strRanges[0] != '_') Add(PwCharSet.UpperCase);
|
||||
if(strRanges[1] != '_') Add(PwCharSet.LowerCase);
|
||||
if(strRanges[2] != '_') Add(PwCharSet.Digits);
|
||||
if(strRanges[3] != '_') Add(m_strSpecial);
|
||||
if(strRanges[4] != '_') Add(PwCharSet.Punctuation);
|
||||
if(strRanges[5] != '_') Add('-');
|
||||
if(strRanges[6] != '_') Add('_');
|
||||
if(strRanges[7] != '_') Add(' ');
|
||||
if(strRanges[8] != '_') Add(PwCharSet.Brackets);
|
||||
if(strRanges[9] != '_') Add(m_strHighAnsi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -18,8 +18,11 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
|
||||
using ModernKeePassLib.Interfaces;
|
||||
using ModernKeePassLib.Security;
|
||||
@@ -27,12 +30,12 @@ using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Type of the password generator. Different types like generators
|
||||
/// based on given patterns, based on character sets, etc. are
|
||||
/// available.
|
||||
/// </summary>
|
||||
public enum PasswordGeneratorType
|
||||
/// <summary>
|
||||
/// Type of the password generator. Different types like generators
|
||||
/// based on given patterns, based on character sets, etc. are
|
||||
/// available.
|
||||
/// </summary>
|
||||
public enum PasswordGeneratorType
|
||||
{
|
||||
/// <summary>
|
||||
/// Generator based on character spaces/sets, i.e. groups
|
||||
@@ -250,14 +253,15 @@ namespace ModernKeePassLib.Cryptography.PasswordGenerator
|
||||
if((ch >= 'A') && (ch <= 'Z')) pcs.Add(PwCharSet.UpperCase);
|
||||
else if((ch >= 'a') && (ch <= 'z')) pcs.Add(PwCharSet.LowerCase);
|
||||
else if((ch >= '0') && (ch <= '9')) pcs.Add(PwCharSet.Digits);
|
||||
else if((@"!#$%&'*+,./:;=?@^").IndexOf(ch) >= 0) pcs.Add(pcs.SpecialChars);
|
||||
else if(PwCharSet.SpecialChars.IndexOf(ch) >= 0)
|
||||
pcs.Add(PwCharSet.SpecialChars);
|
||||
else if(ch == ' ') pcs.Add(' ');
|
||||
else if(ch == '-') pcs.Add('-');
|
||||
else if(ch == '_') pcs.Add('_');
|
||||
else if(ch == '\"') pcs.Add(pcs.SpecialChars);
|
||||
else if(ch == '\\') pcs.Add(pcs.SpecialChars);
|
||||
else if((@"()[]{}<>").IndexOf(ch) >= 0) pcs.Add(PwCharSet.Brackets);
|
||||
else if((ch >= '~') && (ch <= 255)) pcs.Add(pcs.HighAnsiChars);
|
||||
else if(PwCharSet.Brackets.IndexOf(ch) >= 0)
|
||||
pcs.Add(PwCharSet.Brackets);
|
||||
else if(PwCharSet.HighAnsiChars.IndexOf(ch) >= 0)
|
||||
pcs.Add(PwCharSet.HighAnsiChars);
|
||||
else pcs.Add(ch);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -18,522 +18,117 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
#if !KeePassLibSD
|
||||
namespace ModernKeePassLib.Cryptography
|
||||
{
|
||||
/// <summary>
|
||||
/// Bloom filter-based popular password checking.
|
||||
/// </summary>
|
||||
public static class PopularPasswords
|
||||
public static class PopularPasswords
|
||||
{
|
||||
private const int PpcTableSize = 8192 * 8; // Bits, multiple of 64
|
||||
private static Dictionary<int, Dictionary<string, bool>> m_dicts =
|
||||
new Dictionary<int, Dictionary<string, bool>>();
|
||||
|
||||
// Bits set: 32433 of 65536
|
||||
// Hash functions: 32
|
||||
// Phi (bits unset ratio) estimation: 0.505455388896019
|
||||
// Exact Phi: 0.505111694335938
|
||||
// False positives ratio: 1.67583063859565E-10
|
||||
private static readonly ulong[] PpcTable = {
|
||||
0x60383D3A85560B9BUL, 0x2578CE9D37C6AEB7UL, 0xF509A5743FD03228UL,
|
||||
0x19B7455E8933EE56UL, 0x5EA419ADCFD9C20EUL, 0xEA618EFC0B37A162UL,
|
||||
0xE0FD4D1FFF1CE415UL, 0x7A649E0301BB6060UL, 0x80D9CD9F9EEB603DUL,
|
||||
0x47D6010D0D6E6CDEUL, 0x2552708C589EB554UL, 0x073F1A3DB3267502UL,
|
||||
0x3313FEC2A2FEA475UL, 0x4593665C44934FEBUL, 0x410A301A23660395UL,
|
||||
0x6AD06DA533FF5659UL, 0x423DAF86F3E41F4AUL, 0x82F035A971C6FD18UL,
|
||||
0xB5E9139F28C93223UL, 0x1D07C3F4160585CAUL, 0x24B01EDB6B23E2C5UL,
|
||||
0xD52F25B724F936C9UL, 0x8018392517836928UL, 0x3AA4C0F8E181EDA2UL,
|
||||
0x8D93683EF7D52529UL, 0x6164BB6208114460UL, 0x737A04D8FEF3D88FUL,
|
||||
0x3400097098D5C2CBUL, 0x3C2B9ABE5C455B2EUL, 0x3A3819973AB32DA2UL,
|
||||
0x38ACB428510AF40BUL, 0x83320D5114B74771UL, 0xC25BEC333B90DCD1UL,
|
||||
0x0E9F412FBA3813D1UL, 0x047E31E3098EB2B8UL, 0xBB686AC643F1741FUL,
|
||||
0x0BE22E9C0EF0E8F2UL, 0x65AA9504E5F40D31UL, 0xE018DF5D64C62AC7UL,
|
||||
0x17020E9A7EFA12EDUL, 0xFC12A7C16006DE82UL, 0x8DE4747E3745346DUL,
|
||||
0x31D8C051A43CECAFUL, 0xBE9AFBEF127C1B12UL, 0xAEE94B4B808BBEE2UL,
|
||||
0x3A0099CA32835B41UL, 0x59EB3173468D8C49UL, 0x6F89DB1E6DAAE9E1UL,
|
||||
0x4C1ADAA837E968E4UL, 0x6E3593A56C682769UL, 0x022AD591689B5B82UL,
|
||||
0x4AC33861ED978032UL, 0xF6F476E4E6A1318DUL, 0x2DA690A11AA05A23UL,
|
||||
0x916FC56378C29D77UL, 0xAB3238BE22294659UL, 0x2D73A29019B28C77UL,
|
||||
0xAAF26C12EC9C3C42UL, 0x058A278A24B334F9UL, 0x033BD18FB8D9BACDUL,
|
||||
0x8B3833596008B07CUL, 0x280B6D093333E5E5UL, 0x2128DBE126CA3E1EUL,
|
||||
0xCCF09769382472D8UL, 0x0CB6E495BD90CED6UL, 0x1303A37577C01C5AUL,
|
||||
0xC8BBF4734FC34C53UL, 0x1B38B72B10F86CD5UL, 0x5098E2D6C1892E51UL,
|
||||
0x2DD8065B79DB5380UL, 0x5B9A1A6D6A2292B7UL, 0xC70F751604D0497CUL,
|
||||
0x911E08D7363B5213UL, 0x9F2E245273308D2EUL, 0x64D354827957F50EUL,
|
||||
0x09856750F560342CUL, 0xDE091F26603F0E70UL, 0xDDE6B4E76173E3B1UL,
|
||||
0xC1584AE1B26FA08EUL, 0x1EA29887837838D2UL, 0x6D7643FC67B15C54UL,
|
||||
0x921E60571ED103EAUL, 0x63EB1EB33E7AFFF1UL, 0x80BA4D1F95BFD615UL,
|
||||
0xEC8A1D4FC1A6B8E0UL, 0x2C46861B6DB17D1AUL, 0x01F05D06927E443BUL,
|
||||
0x6172EC2EABEAD454UL, 0x21B8726C6F7C4102UL, 0x3C016CD9945C72ECUL,
|
||||
0x708F77B2C0E8B665UL, 0xFC35BE2BB88974DAUL, 0x805897A33702BD61UL,
|
||||
0x9A93367A6041226CUL, 0xFDAB188B6158F6BEUL, 0x5F21014A065E918CUL,
|
||||
0xF4381DD77772D19CUL, 0xC664B6358AA85011UL, 0xF2639D7B3E2307E6UL,
|
||||
0x3FA000D4A5A9C37AUL, 0x8F45D116ED8DC70FUL, 0x8CB8758E45C140D0UL,
|
||||
0x49832B46D716236DUL, 0xCC8E4961A93065B8UL, 0x8A996533EDACEB0EUL,
|
||||
0x15B35155EC56FAC1UL, 0xE7E0C6C05A9F1885UL, 0x05914F9A1D1C79F9UL,
|
||||
0x730000A30B6725F0UL, 0xC95E671F8E543780UL, 0x47D68382400AF94EUL,
|
||||
0x1A27F2734FE2249AUL, 0x828079C332D9C0ABUL, 0x2E9BC798EA09170EUL,
|
||||
0x6B7CDAC829018C91UL, 0x7B89604901736993UL, 0xABE4EB26F47608F0UL,
|
||||
0x70D5FDC88A0FF1B1UL, 0x5A1F0BAB9AB8A158UL, 0xDC89AE0A735C51A4UL,
|
||||
0x36C1EA01E9C89B84UL, 0x3A9757AF204096DBUL, 0x1D56C8328540F963UL,
|
||||
0x910A8694692472FAUL, 0x697192C9DF145604UL, 0xB20F7A4438712AA2UL,
|
||||
0xE8C99185243F4896UL, 0xFBC8970EDBC39CA7UL, 0x33485403868C3761UL,
|
||||
0xAFA97DDEDB1D6AD8UL, 0x54A1A6F24476A3BBUL, 0xFE4E078B184BDB7FUL,
|
||||
0x5ED1543919754CD8UL, 0x86F8C775160FC08CUL, 0x9B4098F57019040DUL,
|
||||
0x039518BBE841327BUL, 0x111D0D420A3F5F6AUL, 0x0666067346AF34ACUL,
|
||||
0xD43F1D14EB239B9BUL, 0xA6BB91FEB5618F5BUL, 0xA2B5218B202409ADUL,
|
||||
0xC004FA688C3AC25EUL, 0xF0E2D9EA2935E1DCUL, 0x380B31CFA2F2AF43UL,
|
||||
0x50E050AE426250EAUL, 0x628ED94D1AA8F55BUL, 0xF8EB0654F0166311UL,
|
||||
0x1F8858D26DDA5CC5UL, 0x931425D11CB1EFEBUL, 0xF661D461DC1A05D3UL,
|
||||
0x7B75ED7EC6936DA8UL, 0x8713C59690985202UL, 0xF61D6F93F07C0E85UL,
|
||||
0xFD1771F6711D6F4FUL, 0x5835A67E1B11419FUL, 0x33EF08ABD56A1050UL,
|
||||
0x55B5D0043FA2C01CUL, 0x53316ED963B92D9DUL, 0x6A8C93744E521EDBUL,
|
||||
0x083E948062EB9543UL, 0x1C15289B3189AFB1UL, 0xA6A0A5053AE2212DUL,
|
||||
0x6573AF7F01FAFF3BUL, 0x58B6F034CFCFE843UL, 0xEB2837CA5AEA6AEDUL,
|
||||
0x633E7897097AC328UL, 0x7FA91789B6CCEE82UL, 0xBEE2402F4E7D65EEUL,
|
||||
0x616A103EC8FB0DBEUL, 0x65991F9FB25E13FCUL, 0x54EA8A3FADEC1F4BUL,
|
||||
0x6D497C5ACDEA0E7AUL, 0x5865045E8CA18527UL, 0xA406C09215ABD61FUL,
|
||||
0x68F81F5745FC9875UL, 0xE496D850CEFF3FA9UL, 0xD225C88D63212CB1UL,
|
||||
0x37676390525116D2UL, 0x415614AB14188A7DUL, 0xABE58EBC1F6DDC63UL,
|
||||
0xDE10312B2C25D28CUL, 0x86C86D7A0B847635UL, 0x408B511D584DC3DCUL,
|
||||
0x6711FCC14B303FEDUL, 0x1284DF9CC6972023UL, 0xC3CE0B33141BFA8FUL,
|
||||
0x0F3F58367D4A1819UL, 0x9313F83058FBE6D0UL, 0x6FCA5EF39B8E2F47UL,
|
||||
0xA90F5C95D887756DUL, 0x96C4E2AD85D5AF6EUL, 0x0ED68A81F526F0A0UL,
|
||||
0x53E4472DB4255A35UL, 0xAC581015134D58A6UL, 0x12C000D85C644FC7UL,
|
||||
0x124D489B2C0FE6E4UL, 0x8FF83531C6F5D61AUL, 0x132BD6488304F73BUL,
|
||||
0x110E99BC59604CB9UL, 0xC28186ACBC940C9BUL, 0x2094C07F48141230UL,
|
||||
0x65FB9881A5053589UL, 0x940A3E6D72F09D69UL, 0x972A922CB14BA66EUL,
|
||||
0x8D07E59C6DDD4327UL, 0xCB67F993F820157CUL, 0x65B7A54E5FB2ED6CUL,
|
||||
0xC235828849576653UL, 0xA695F85479467538UL, 0x9E2BA885E63C4243UL,
|
||||
0xDE64A6A5EF84C222UL, 0xC2AB9AF302080621UL, 0x88DBA09B87FA0734UL,
|
||||
0xDF002765B44D02E1UL, 0xD50D8D90587CD820UL, 0x1B68B70ED179EFE1UL,
|
||||
0xD6E77F8EC26AE95CUL, 0xEE57EB7C45051872UL, 0x4D2B445F36A7F9FDUL,
|
||||
0x5502ABB8BB14D7F1UL, 0xAF2C0DF0406FA901UL, 0x6522833444BF4A83UL,
|
||||
0xD7CB2E3FC691BE8DUL, 0x4F36F70D2E80D19AUL, 0xF6945FE911D4923BUL,
|
||||
0xE3C6FE1EA47399C1UL, 0xF09EA1B2F837702CUL, 0x5122537CF97B5CB5UL,
|
||||
0x0C8202B70E9BF154UL, 0x68B554AB58EB5E68UL, 0x7BF9B8052C9BEADEUL,
|
||||
0x33612BFCD303810DUL, 0x03E38CF67B37DC53UL, 0x2BFDFF8691F37D5CUL,
|
||||
0x4AB483D1CB1D07F6UL, 0xF071A58640639A5CUL, 0x9D6B98169B745CE1UL,
|
||||
0x5F42D3E870FDCD93UL, 0x4EDF04404F258238UL, 0x2EAB6E10D65C9BB3UL,
|
||||
0x5BB71411EF78DAD2UL, 0x0DE8128636A5D689UL, 0x18FDD1F484DC9365UL,
|
||||
0x9896B8896941DA5BUL, 0x8BEF8E3BA4448E5FUL, 0x963A1E977CB1D2CAUL,
|
||||
0x02BCF5F068D52851UL, 0x0CD783F09BFBE381UL, 0x350DA833D8C5DB47UL,
|
||||
0x8D444C914D795C43UL, 0x8A00B4DFC44D9476UL, 0x4B36CBEC089E55FDUL,
|
||||
0xD9D2FA1B0AC66211UL, 0x6C7FC30FA31A8B60UL, 0x9EF4504CC985AD6BUL,
|
||||
0x8F2E7E5E0C00EE73UL, 0x819131CFEEBEA069UL, 0xB1E406A863E7A1B4UL,
|
||||
0x501F072FF1F2AB67UL, 0xDE578BFC5ADBC264UL, 0xCDD66A09C8E13881UL,
|
||||
0x4D443460CE52957FUL, 0x3B198C267976ECFAUL, 0x6B98323D8BD26522UL,
|
||||
0x80161F6A489E4BF8UL, 0xE03A8AFCC7AE6872UL, 0x2484BD95A305AB27UL,
|
||||
0x6ADDAA46BF25DD0EUL, 0xA429D8B00100477CUL, 0x55AEDB88A074BF2CUL,
|
||||
0x63D9F9021AB8F5F3UL, 0x37858538A10C265CUL, 0xEF54C2CE9D063149UL,
|
||||
0xFA5CE5AF33E2C136UL, 0xE601A559D0C391D7UL, 0x7C4ED29BBF57DC7EUL,
|
||||
0x8FD0D4146DE9E900UL, 0xB58ABFA6CE6C0733UL, 0xF8D7F7743B33EAFFUL,
|
||||
0x453FA782F454643CUL, 0xD01752C21AF21E66UL, 0xA50BB7913EAF05DFUL,
|
||||
0x966D5B140B2F4189UL, 0x956F5638AFF3D148UL, 0x93FAA838420E8AB3UL,
|
||||
0x715E26043071EABDUL, 0x01E7B458B5FD3A41UL, 0x5CFA99C4CC0492AAUL,
|
||||
0x761FD391C3623044UL, 0xD39E44E9DB96B5BCUL, 0x8806C544F0534A07UL,
|
||||
0x9B225CAFE97EAAC1UL, 0xEAE5E18583492767UL, 0x6B4E51E4C297F096UL,
|
||||
0xFC512662EF47E41DUL, 0xB6AC60427DB46F8BUL, 0x8F137F3DB4429C9DUL,
|
||||
0x04C65FBEAE9FD8D0UL, 0xEB72305958AE5022UL, 0xAA93AA14BCA2961EUL,
|
||||
0x6C7547F9456CA37AUL, 0xEE6094871615BA34UL, 0x489BC8EDE0940402UL,
|
||||
0x1108AEFAAD892229UL, 0x673B8B1CF6BED23EUL, 0xFDB781A75FD94DEAUL,
|
||||
0x11D9E0F5D914A7BEUL, 0x02830D07F018143DUL, 0x9B3163B8188FD2BAUL,
|
||||
0x32C1BEC97D06117EUL, 0x697268B761240CFFUL, 0xBD89CE3037C2E7A9UL,
|
||||
0xF21C158125B19600UL, 0x632CB1931601B70AUL, 0x7BB3FB131338085CUL,
|
||||
0xA9C06689B8138384UL, 0x161CCBF83EBDC2A1UL, 0x2CF83C01A80B7935UL,
|
||||
0x9E51FE393B8E2FF0UL, 0xFE96E52B1606C1A7UL, 0x5E20DFB87F81ACCEUL,
|
||||
0xF95DB9602CDAE467UL, 0xDEA155CD35555FEBUL, 0xF0669B810F70CDC6UL,
|
||||
0xD36C2FBEB6A449ACUL, 0xCE500C6621C0A445UL, 0x41308909E366460AUL,
|
||||
0xAC4D8178DA0CEC24UL, 0xC69049179ED09F7DUL, 0x36B608A0BA2FD848UL,
|
||||
0xDF511894DD9568B4UL, 0xB3BFDF78EC861A6CUL, 0xCD50F39D19848153UL,
|
||||
0xD2C1BC57E78A408CUL, 0x1E6613EFBB11B5EBUL, 0xF58E30D2D90F73D3UL,
|
||||
0xCCB5E2F5E168D742UL, 0xEE97259469BDB672UL, 0x6784D35AF65935A8UL,
|
||||
0x71032765ADED1FE8UL, 0x4BBF2FE54D9B72E3UL, 0x5A1BB7831E876A05UL,
|
||||
0x12A8FC949EE91686UL, 0x8296F8FA83BD112CUL, 0xAAA7E3BFF64D34D5UL,
|
||||
0x0301655E1794EE4BUL, 0x1E547C011BBF30E1UL, 0x39D74FEC536F31D6UL,
|
||||
0x3C31A7478B1815BAUL, 0x525C774F82D5836EUL, 0xECF7186DC612FD8CUL,
|
||||
0x96B7C4EDD1F3536FUL, 0x7E8C21F19C08541CUL, 0xEE92DB0CF91E4B09UL,
|
||||
0xF666190D1591AE5DUL, 0x5E9B45102C895361UL, 0x9A95597AAE5C905DUL,
|
||||
0x6E1272E5BB93F93FUL, 0x0E39E612402BFCF8UL, 0x576C9E8CA2A3B35EUL,
|
||||
0x7E2E629996D0C35FUL, 0xC95DFF54E3524FCCUL, 0x260F9DEBDEB0E5CBUL,
|
||||
0x577B6C6640BAF1ABUL, 0xCA76677779CA358EUL, 0x9E2714BEBCFDB144UL,
|
||||
0xD660595CE30FD3EEUL, 0x72DE172D55A5706EUL, 0xB4C84D564489D420UL,
|
||||
0x160AA2B9399D5A9DUL, 0x2906ECE619DAC4D2UL, 0x12CE8E8E68A4C317UL,
|
||||
0x6BE2DFE89901CAA1UL, 0xEE1D68158102EB77UL, 0x64EB75E45BDA1AC5UL,
|
||||
0xEFECF9F98720B55DUL, 0x41CDF813931315BFUL, 0x5F1E4F50CF98FFD4UL,
|
||||
0xE69E09EED12E173BUL, 0x89A3707F0396FF65UL, 0x81E36B9DF4FFB492UL,
|
||||
0x58C32E883D4DE6DDUL, 0x2D4725C2A5F0B469UL, 0x6B2B9C27CC421CACUL,
|
||||
0x3C30F2AD966800C7UL, 0xFF74938BB76B8A7CUL, 0x52B5C99114FD93FAUL,
|
||||
0x51647EDCA6C104DAUL, 0xEB47684CF796DF4EUL, 0x376D74A5AB14BD71UL,
|
||||
0xF0871FEF8E9DAA3EUL, 0x1D65B134B2E045B6UL, 0x9DC8C0D8623BBA48UL,
|
||||
0xAD6FC3C59DBDADF4UL, 0x66F6EBA55488B569UL, 0xB00D53E0E2D38F0AUL,
|
||||
0x43A4212CEAD34593UL, 0x44724185FF7019FFUL, 0x50F46061432B3635UL,
|
||||
0x880AA4C24E6B320BUL, 0xCAFCB3409A0DB43FUL, 0xA7F1A13DEF47514BUL,
|
||||
0x3DC8A385A698220CUL, 0xFA17F82E30B85580UL, 0x430E7F0E88655F47UL,
|
||||
0x45A1566013837B47UL, 0x84B2306D2292804EUL, 0xE7A3AF21D074E419UL,
|
||||
0x09D08E2C5E569D4DUL, 0x84228F8908383FA2UL, 0xC34079610C8D3E82UL,
|
||||
0x66C96426C54A5453UL, 0xD41F164117D32C93UL, 0x7829A66BF1FEC186UL,
|
||||
0x4BB6846694BDFC18UL, 0x857D1C1C01352C01UL, 0xAB8E68BA85402A45UL,
|
||||
0x74B3C4F101FE76C8UL, 0x6CF482CFAFB29FFEUL, 0x28B174A18F4DC3D1UL,
|
||||
0x833C3425B2AA3755UL, 0x8AA58A32747F4432UL, 0xFE7B9FB4BCE3CD58UL,
|
||||
0xB0836B2C16FA5553UL, 0x1D08EE6861BF3F23UL, 0x0FAE41E914562DF3UL,
|
||||
0xB10A2E041937FC57UL, 0xDA60BB363415BF4CUL, 0xEEC67DBAB4CF4F0AUL,
|
||||
0x9A6ED59FCC923B5CUL, 0x9A913C01A8EC7A83UL, 0xAD4779F2F9C7721FUL,
|
||||
0x2BF0B7D105BE7459UL, 0x189EFA9AD5195EC6UL, 0xB5C9A2DD64B2A903UL,
|
||||
0x5BCD642B2C2FD32CUL, 0xFED3FBF78CB0891FUL, 0x1ED958EE3C36DD3FUL,
|
||||
0x030F5DE9CA65E97CUL, 0xBB5BCF8C931B85FEUL, 0xFD128759EA1D8061UL,
|
||||
0x2C0238AC416BE6BCUL, 0xBB018584EEACFA27UL, 0xCEA7288C1964DE15UL,
|
||||
0x7EA5C3840F29AA4DUL, 0x5DA841BA609E4A50UL, 0xE53AF84845985EB1UL,
|
||||
0x93264DA9487183E4UL, 0xC3A4E367AF6D8D15UL, 0xDD4EB6450577BAF8UL,
|
||||
0x2AA3093EE2C658ACUL, 0x3D036EC45055C580UL, 0xDDEDB34341C5B7DFUL,
|
||||
0x524FFBDC4A1FAC90UL, 0x1B9D63DE13D82907UL, 0x69F9BAF0E868B640UL,
|
||||
0xFC1A453A9253013CUL, 0x08B900DECAA77377UL, 0xFF24C72324153C59UL,
|
||||
0x6182C1285C507A9BUL, 0x4E6680A54A03CCC8UL, 0x7165680200B67F1FUL,
|
||||
0xC3290B26A07DCE5BUL, 0x2AD16584AA5BECE9UL, 0x5F10DF677C91B05EUL,
|
||||
0x4BE1B0E2334B198AUL, 0xEA2466E4F4E4406DUL, 0x6ECAA92FF91E6F1DUL,
|
||||
0x0267738EFA75CADDUL, 0x4282ED10A0EBFCF2UL, 0xD3F84CE8E1685271UL,
|
||||
0xB667ED35716CA215UL, 0x97B4623D70DB7FA8UL, 0xB7BA3AA5E6C2E7CBUL,
|
||||
0x8942B2F97118255BUL, 0x009050F842FB52ADUL, 0x114F5511999F5BD5UL,
|
||||
0x70C1CAAF1E83F00AUL, 0xAC8EE25D462BB1AAUL, 0x63EEF42AD4E1BED9UL,
|
||||
0x58DFBB3D22D3D1A5UL, 0x82B0027C0C63D816UL, 0x48D038F08F3D848BUL,
|
||||
0xCE262D5F9A12610EUL, 0xA54BF51C21BD0167UL, 0xF3645F6FB948397DUL,
|
||||
0x9188AE58532DA501UL, 0xEC90B0E1479DB767UL, 0x37F4886B83724F80UL,
|
||||
0x232B8FF20ACD95AFUL, 0x88A228285D6BCDF0UL, 0x321FB91600259AEEUL,
|
||||
0xA1F875F161D18E5EUL, 0x5B6087CDA21AEA0CUL, 0x0156923ED1A3D5F1UL,
|
||||
0xC2892C8A6133B5D3UL, 0x015CA4DF0EA6354DUL, 0x5E25EB261B69A7D4UL,
|
||||
0xAAA8CF0C012EFBA7UL, 0xCF3466248C37868BUL, 0x0D744514BD1D82C0UL,
|
||||
0xB00FF1431EDDF490UL, 0xC79B86A0E3A8AB08UL, 0xFC361529BC9F1252UL,
|
||||
0x869285653FB82865UL, 0x9F1C7A17546339ABUL, 0xE31AA66DBD5C4760UL,
|
||||
0x51B9D2A765E0FC31UL, 0x31F39528C4CD13D8UL, 0x16C6C35B0D3A341DUL,
|
||||
0x90296B1B0F28E2CDUL, 0x36338472A8DB5830UL, 0xA648E6D44DF14F87UL,
|
||||
0x93E231E65EB1823FUL, 0x95AA7B9D08E2B627UL, 0x7932D149374700C7UL,
|
||||
0x09EFE0A8BF245193UL, 0x742AA63BCEAFD6D8UL, 0x82D4BC5FEDF158B7UL,
|
||||
0x02CDEA673CFF150DUL, 0xD8D7B5813B602D15UL, 0xA5A7B670EF15A5EDUL,
|
||||
0x4C08E580A1D46AF2UL, 0xC3CA9B905D035647UL, 0x6A39ABB02F6F1B83UL,
|
||||
0xD2EC2169F4D02436UL, 0x8E6AEA4DF8515AF2UL, 0x7B3DD4A8693CA2DAUL,
|
||||
0xC2ABF17A50AEC383UL, 0xD4FB84F8B6D4F709UL, 0x2839A3EAA2E4C8A7UL,
|
||||
0x5D5FD278FE10E1E9UL, 0x5610DDF74125D5A7UL, 0xA484B0B83461DCEAUL,
|
||||
0xA511920C0A502369UL, 0xC53F30C6A5394CA4UL, 0x528799285D304DD4UL,
|
||||
0xF6D7914CB252BB48UL, 0x892129CB52E65D15UL, 0x15A81B70519ACE6FUL,
|
||||
0x5CFBFFD7A2A1C630UL, 0x3B900509C82DF46DUL, 0x19C3CE05D66D5FFCUL,
|
||||
0x937D521A4A4799A0UL, 0xD0AE34A6EAD7207DUL, 0x3258A69F1D1A1B38UL,
|
||||
0xB173E3255723CC02UL, 0xD7E48FEF7F414F1BUL, 0xDCEBA75F5C761ABEUL,
|
||||
0x6DA10C618DEA0D17UL, 0x423FA8B05954FBD1UL, 0x7E73C2E7D923F3C9UL,
|
||||
0xC22E21C927C684D1UL, 0x756BAA758764685FUL, 0x8C90B4C4E741D880UL,
|
||||
0x1B658C9F4B41D846UL, 0x5D80C14094366707UL, 0xB55FED3E03C00F2DUL,
|
||||
0x9B69EB7964C69C83UL, 0x356ED81C9494DADDUL, 0x7599AFF0B2A339D6UL,
|
||||
0xA5EBFD25C9B5816BUL, 0xA481DC1C8995E1EFUL, 0xE42C63DF0D402397UL,
|
||||
0x3B497B4C30873BAAUL, 0xA950B78BA8772C96UL, 0xD46308D4C76F115DUL,
|
||||
0x73714A4ACA76A857UL, 0x0DA86B958FF8CB7DUL, 0xEB61F617B90E0A75UL,
|
||||
0xD6106C9B39F51F55UL, 0xB179F73A6BD23B59UL, 0xE7F056E50104A460UL,
|
||||
0xBC5B5387634A8642UL, 0xE1678D8752996AF4UL, 0xB508F3D394664A4BUL,
|
||||
0xC88536DC4A219B0FUL, 0x39964CBB8CE367B1UL, 0xD51E211D5E9E1417UL,
|
||||
0x6821B97B496870F2UL, 0xA596257350CA0A99UL, 0x6D051EE2C49D4D1DUL,
|
||||
0xCB426AD61AA8D9B5UL, 0x5FFD3A4062B06D22UL, 0xDAD37BF2A4C594EBUL,
|
||||
0x6B9CC848E2B0C686UL, 0x19B4232F3BC622AEUL, 0x70C13C7E5950B702UL,
|
||||
0x383318CA622101ACUL, 0xD9647C028CD1C4DFUL, 0x006D123BC553B93CUL,
|
||||
0x2CA9D7D896EAE722UL, 0xF19872AC8A0BD5A8UL, 0x59838578EB9E8E5CUL,
|
||||
0xB948621EE99B27D4UL, 0x2B470E6036E0E387UL, 0xD0A7E8F0C8A32A84UL,
|
||||
0xCBF869271A8E0914UL, 0x705F76A5EA4437CFUL, 0xBAD2BF4933215152UL,
|
||||
0xE52EDE847038EA23UL, 0xB8A3EFD3D58D7607UL, 0x748472F5AD330239UL,
|
||||
0xCC079CFD428690F6UL, 0x3687450CB7534DACUL, 0x0FEF82D5CC8ACE2AUL,
|
||||
0x214653D5C552CA9AUL, 0x9FCA4E87BF6A04FDUL, 0x78D4B114D234A0D7UL,
|
||||
0x22840422BD6A5BB5UL, 0x5B9ABE0DE1B4410FUL, 0xB3B50007963FDD6BUL,
|
||||
0x53A8A46793B68E35UL, 0x8CDD8E8D188B6033UL, 0x5DD22B6E3ED49572UL,
|
||||
0xE561F5D27F5302D6UL, 0xDF89CEC3322E56CDUL, 0x87167F503D600F90UL,
|
||||
0x1698BB71C8201862UL, 0xF7BF5DFDB023108EUL, 0xA17FB15B66ACFB5FUL,
|
||||
0x2DD771987768073BUL, 0x19299D2D86E0EB29UL, 0x8B537B7F206EED29UL,
|
||||
0xE536DA153325ABFCUL, 0x30A69976796DB3B9UL, 0x8E65A2C94E2D4981UL,
|
||||
0xC301D53553BD6514UL, 0x46DF3639B9E43790UL, 0x3004CD0E5AFD0463UL,
|
||||
0x46E460B0F6ACA1A0UL, 0xCBA210E7372D9BD5UL, 0x45064274A74CA582UL,
|
||||
0xFDD57EA43CE631AEUL, 0xF2BA08FFA4A683D0UL, 0x8DA658C4DAD42999UL,
|
||||
0x7418042943E88040UL, 0x96000F72E9371FEFUL, 0xE9F1212DC8F47302UL,
|
||||
0x2AFB565ECC3553EDUL, 0xCD3D55137EFF7FD6UL, 0xD36F11059388E442UL,
|
||||
0xC4B47515DB5709DDUL, 0x5C363EFBF0BAAB67UL, 0x28C63B5A31650BBBUL,
|
||||
0x6AE54E5068061C81UL, 0xDEE62000F4E0AA21UL, 0xE8238672FE088A8BUL,
|
||||
0x9869CB6370F075B9UL, 0xBA376E2FC7DB330FUL, 0xB0F73E208487CDEEUL,
|
||||
0x359D5017BE37FE97UL, 0x684D828C7F95E2DCUL, 0x9985ECA20E46AE1FUL,
|
||||
0x8030A5137D1A21C4UL, 0xF78CDC00FC37AC39UL, 0x41CDDC8E61D9C644UL,
|
||||
0xB6F3CD1D833BAD1DUL, 0x301D0D858A23DE22UL, 0xA51FCA12AD849BC8UL,
|
||||
0x9F55E615986AB10EUL, 0x904AAA59854F2215UL, 0x12ECEA4AB40F51A7UL,
|
||||
0xB4EDF5807735E23BUL, 0x6190200F1C589478UL, 0xA3CA57F321909A5AUL,
|
||||
0x0BFAEE04B7325B63UL, 0x10C393E7FBCF826DUL, 0x4050A2CA53FDA708UL,
|
||||
0xF31114A9B462B680UL, 0x6FB9A6F121BA2006UL, 0x04550CF09389D602UL,
|
||||
0xB8C7D6D8CA8942F7UL, 0x71BB430C6436E9D1UL, 0xD9070DD5FAA0A10AUL,
|
||||
0x8FD6827757D07E5BUL, 0xD04E6C313F8FD974UL, 0x2CFDEA1187909B9AUL,
|
||||
0xC7A8E758C115F593UL, 0xA79A17663009ACC2UL, 0x8091A6B5372B141DUL,
|
||||
0xEB33B08767F5BA73UL, 0xDAC1F6823B6111C7UL, 0x697DF90C3515611BUL,
|
||||
0xCC1005F198761F48UL, 0x5067E4F5303B45A1UL, 0x04816D292A2D9AC2UL,
|
||||
0x2949C7A0874DD5E9UL, 0x25DB2547804CEE5EUL, 0x7EDC3A8946D6F229UL,
|
||||
0x00B586F67FD0C622UL, 0x3CAE5798E40324E0UL, 0x0A4F1437DE637164UL,
|
||||
0x5F59B2B715871981UL, 0x5D68FF31051E48FBUL, 0x0F2C369D73A2AA46UL,
|
||||
0xB009C6B53DD23399UL, 0xC366A81277084988UL, 0x5AF0E0CA0711E730UL,
|
||||
0x7AD831A9E9E854BAUL, 0x1DD5EDB0CA4E85AEUL, 0x54651209D259E9DDUL,
|
||||
0x3EBB1D9DAB237EADUL, 0xDA96989317AC464CUL, 0xBFCB0F8FBC52C74EUL,
|
||||
0x9597ACB9E27B692EUL, 0x6F436B1643C95B23UL, 0xB81A1253E1C3CD9DUL,
|
||||
0x7B35F37E905EC67EUL, 0x29CE62666EDA76DDUL, 0xFF2490DC1EC4014DUL,
|
||||
0x2D4FF9124DD6B5C4UL, 0xB9510FEC23E0E9D1UL, 0x8BCDBC56541ED071UL,
|
||||
0x5414E097C1B0CCB2UL, 0x82BEF8213076F5C7UL, 0xE9FC9A71BD512615UL,
|
||||
0xCF15ECC39490DF5AUL, 0x49FA9328D8EE97DBUL, 0x5F80FF0153BC2145UL,
|
||||
0xF63BA156B55BCB02UL, 0x0E3B9113109FDF36UL, 0x8FCD6528F54EDE69UL,
|
||||
0x5D6AE9C000054763UL, 0x326D873633431FBBUL, 0x380E07FFCEF7A978UL,
|
||||
0xDCAA09874A1DF230UL, 0x601494F49F6D261EUL, 0x856159486C9B60E3UL,
|
||||
0x85C7F822D07089A5UL, 0xAFFB99CF5AB836C2UL, 0x241AD414FBBB956BUL,
|
||||
0x0CFC042822831692UL, 0x382B16D049727FF2UL, 0x784F9997633C819AUL,
|
||||
0x5C40ED725F6C390AUL, 0x2CE78B7A3331BA9CUL, 0x9C80636639963B41UL,
|
||||
0x1B2D41C968355018UL, 0xD189B57691FB60E4UL, 0x3BD599A9DD85CE31UL,
|
||||
0x46FC8E2EF0B9A77CUL, 0x1A389E07D0075EA4UL, 0x1622CA52401DF2ACUL,
|
||||
0x528F3FF9B7993BFAUL, 0xF16C176CCA292DDBUL, 0x6C154010961EF542UL,
|
||||
0x04B78E92BF6C82DFUL, 0x7D9AFEA6ABB46072UL, 0x3BC573291CBFFC2EUL,
|
||||
0x277FFF096D567AF3UL, 0x1CBEB86841A6F757UL, 0xD0BCD49E76CA20A7UL,
|
||||
0x25B6024756B1FE90UL, 0xE685C04EF84881FBUL, 0xDCAB14B352FC442EUL,
|
||||
0x4FF80A521719953DUL, 0xD10425E411DBE94BUL, 0x60998D0507D6E38DUL,
|
||||
0x146AA432C981BD5EUL, 0x1729A596282AAA41UL, 0x152BE1A263BAF963UL,
|
||||
0x15278DF497D254CAUL, 0xE4B5E9891E88A5DAUL, 0x087FA3472067D0ACUL,
|
||||
0xD99C2899A0AD9158UL, 0x5040F234DC531236UL, 0x9D7E1531259EEE90UL,
|
||||
0x29AFB8B49391036EUL, 0x84B619599642D68EUL, 0xE838AAE0F249545CUL,
|
||||
0x42D524BA8BB96959UL, 0x9A5B3E817A20EE59UL, 0x584F0530EC4C566BUL,
|
||||
0xD6544FD14B47F945UL, 0x3613FB3B553A7CDEUL, 0x284E92B56831AA56UL,
|
||||
0xCEE89BA10E951A22UL, 0x476806FA1A8A44E0UL, 0xC84CEF151885C1DFUL,
|
||||
0x3DB1D5C1B0B73936UL, 0x45D2D90FDF452388UL, 0x038A7DD71BC5DD21UL,
|
||||
0x2AC90C7422C56819UL, 0x4742046638ECE0FBUL, 0x553B44360FC8495DUL,
|
||||
0xC8DBA1CF3F9A6E97UL, 0xF85919F494CAB021UL, 0x1479455C2FF236AFUL,
|
||||
0x29BCAD159F7D018DUL, 0x016DFF51CBA3BCC5UL, 0x234BF8A77F6B1CF5UL,
|
||||
0x20564C6F44F9E641UL, 0x063A550C5AA50FA8UL, 0xB063D0AAAA96DFECUL,
|
||||
0x3EC659DF42C092F8UL, 0x29D4A76A5A5F7E09UL, 0x65EFF3EE6E691D1EUL,
|
||||
0xBD1634F5721CF799UL, 0xE85BD016723B43FFUL, 0x5233E9E7AEA11022UL,
|
||||
0x8C68852EA9039B4CUL, 0x2C978ADBE885BC15UL, 0x726615ED9D497550UL,
|
||||
0x7C1E145EB8D2BD96UL, 0xC2FEFB25935A5D71UL, 0x9EE9C3E1C3DE416FUL,
|
||||
0xFFD568A03E20E0B3UL, 0xF53649AD90156F2AUL, 0x0331B91DCE54E7EDUL,
|
||||
0x67CED5A86E99392FUL, 0x16FC0A5815500B05UL, 0x030392E8D24A7C00UL,
|
||||
0x232E5E31DF32A7B5UL, 0xCC8BF22B1947DF21UL, 0x4EC2C72D9C1EEABDUL,
|
||||
0x0B1B79F45220E668UL, 0xCC3CF0EE9C4A899BUL, 0xFC260A60592EBC80UL,
|
||||
0xC1989A0382CB03EDUL, 0x35FE679A6CD800B2UL, 0x8A6B1ADE4FBB162FUL,
|
||||
0xB0FD284563625295UL, 0xCDCC1C7B2181D024UL, 0x5B8BA0C895C0BB23UL,
|
||||
0xA681FEA9ADCD43DBUL, 0x0FE30FB6876DE718UL, 0x6DDD1E27B769C494UL,
|
||||
0x83A1E58460FFE8BBUL, 0x8FAD6FD2DC90FF65UL, 0x41BB28B81201CB24UL,
|
||||
0xA148CE79B2597204UL, 0x7CB87DF97BB477A6UL, 0x9F79E6DED87DC688UL,
|
||||
0xE044D84A6C758171UL, 0x1A29E750D9EC4097UL, 0x8445FC2B80C4A0F5UL,
|
||||
0x5EFD9784AFED4ED2UL, 0x344C252BD90EB0E4UL, 0xEAD18D2E4418E5B5UL,
|
||||
0x207EF4FFC260BD24UL, 0xD2E5C3AE534EC538UL, 0x2F5A59BF3D10E7E1UL,
|
||||
0x9528E29266C2924CUL, 0x0121B6BDAB45D138UL, 0xADD0256ACBC771DDUL,
|
||||
0x7301769600C6C50DUL, 0x3E7404EA8231D497UL, 0xB39B3840B8D03117UL,
|
||||
0x56EFCEDDEF5B6634UL, 0xE6BE2C0D73B72098UL, 0x5A2841A21A5E4959UL,
|
||||
0xCFEB3586156DF6E0UL, 0xD84F58901E2D65B8UL, 0x79796786CCC59703UL,
|
||||
0x13BFA9A94DD07696UL, 0x7B63116A6B5458B6UL, 0x1406628176C932E0UL,
|
||||
0xDD7ACC4E97F91B1AUL, 0xC82B8F84A56BDBE8UL, 0x325D87D08ED8B0B0UL,
|
||||
0x3F7847B1E82002DDUL, 0x4662900D2ADAF6BFUL, 0x12AE9F58561DB1D7UL,
|
||||
0xA896E956A95CC074UL, 0xAA4FA3A2F8BA4084UL, 0x1D577E35F5DCA67FUL,
|
||||
0x796FF2D75469DEC2UL, 0xBD3F3F87E4DE894EUL, 0x3666B2262DEBFB6BUL,
|
||||
0x1E26D7AEEF976C2EUL, 0x6BC3854F867AC4A0UL, 0x743DBF8C2E95A821UL,
|
||||
0xA62A76B9AE2E645AUL, 0xB4D76561F40187C1UL, 0xD3E5F23F9FA5DB25UL,
|
||||
0x34B1F6B39E6A87E2UL, 0x7DA5C3DFF7BE72CFUL, 0xFDF46B1BE80AD4F9UL,
|
||||
0x0B21121CA9653B8AUL, 0x1199CA9D0A90F21AUL, 0x6021EA302D01E0BAUL,
|
||||
0x8101D063C05CF5D4UL, 0xE2652410DFE78F23UL, 0x84095ACF47C21A25UL,
|
||||
0xD7E29A4DB2FD3A99UL, 0x7793C0CB57959F93UL, 0x94C605308B9E5AA7UL,
|
||||
0x943DB1AC54165B8FUL, 0xC1391A544C07447CUL, 0x3FEF1A61F785D97BUL,
|
||||
0x6DFCC3152478BDE4UL, 0x312AFB0E1982933AUL, 0xB8069C2605631ED3UL,
|
||||
0x5A6076423430BED2UL, 0x34E379F09E2D4F42UL, 0x9167F5E4019573E3UL,
|
||||
0x18F81157828D2A49UL, 0xF4A8723B4955EAB8UL, 0x0BE6C0ABFEA9E8A6UL,
|
||||
0xC63ADCF2CEF25556UL, 0xC5EBD3BEAE9F364FUL, 0xA301D60CF5B6F2FCUL,
|
||||
0x8C606CA881D27A00UL, 0x826FEE13B554C18AUL, 0x8DF251716F10B776UL,
|
||||
0xB2573A33AC7D94FFUL, 0xC0E771248CB7ABB9UL, 0x753DD605DB38F4EAUL,
|
||||
0x21901664C3D92114UL, 0xA408FCB7A1892612UL, 0x3084FC64A03D6722UL,
|
||||
0xC8C9D9569AD42A34UL, 0x1FBFBAFC1694B383UL, 0x1894280CC3F94ABEUL,
|
||||
0xE14C38A7BBB54651UL, 0x23A48CC84A6EB704UL, 0xD034ADC45AABEDBDUL,
|
||||
0xC93F2C21C973C766UL, 0x66A8AEC11D743CC6UL, 0xB4F72AA52E37C145UL,
|
||||
0xB02834DF0D9266B4UL, 0xDB8E724EA1FF402FUL, 0x531E9C058112E352UL,
|
||||
0xC2F692531DB317D2UL, 0xEFC9586498D263A7UL, 0x84F2C524D2F3ADB9UL,
|
||||
0xAFAF02C27CF25D08UL, 0x385873595F9CFC09UL, 0x36DDA10D1A152B7AUL,
|
||||
0x9F9B997A0DACFB55UL, 0x10AB5EB5C4714882UL, 0x7BA4E8703E22B7EEUL,
|
||||
0x0A2BFD558607BCC8UL, 0x201D3706F74F8BA1UL, 0x3DBD573B1358F02EUL,
|
||||
0x5B37645FA93BCEBCUL, 0xC0166864BC1A7544UL, 0x45C7AA5559FC65D7UL,
|
||||
0xEFEA04AA83349B78UL, 0x607859194F9E9FD8UL, 0xA6B9AE5B53CF7710UL,
|
||||
0x73B9142ACBC50821UL, 0x8B7D67495887E65CUL, 0x39B6C4FB2B232E56UL,
|
||||
0xD212DB10E31D2A68UL, 0x629AC0A3D263DC6EUL, 0x6BC2E7FF912050BAUL,
|
||||
0xE0AD5A8FDB183F62UL, 0xF05648134F0C6F0FUL, 0x31E146F4AF980FDAUL,
|
||||
0x7FAF0078D84D62CCUL, 0xE13F044C2830D21EUL, 0x49A047AD204B4C4BUL,
|
||||
0xF3AFBE2237351A74UL, 0x32826C9217BB07EDUL, 0xD4C3AEB099319B5CUL,
|
||||
0x49CE5BD05B2B0F61UL, 0x75DD36984DCBD0A2UL, 0x84EC5D7C2F0AAC6CUL,
|
||||
0x8E59CC9B9942EDDFUL, 0x89FF85DCDF9AE895UL, 0x6F9EE0D8D9E8D414UL,
|
||||
0x10E01A59058D3904UL, 0x1DFAF567BFF55D2EUL, 0x8DD6A18C03382CD4UL,
|
||||
0xE12FD89A0CF58553UL, 0xE245DA902C0C4F5CUL, 0x8BE7566B9987520DUL,
|
||||
0x4CA1C0A4B38A3098UL, 0x81E45015BE618A72UL, 0xA80E0344FF27EFDFUL,
|
||||
0xC98DAEC6DC5005BAUL, 0xF56873F3A958AE5EUL, 0xDB88604670C794ACUL,
|
||||
0x4F68E448DDF6535FUL, 0x3443DBF1CA6031A8UL, 0x73DFA5DEEF409A41UL,
|
||||
0xA7C556941F6643B2UL, 0x424BC40D8C83D962UL, 0x6F292A325B99B726UL,
|
||||
0x6EECB1009717D65EUL, 0x899BE4CE7BB2D8EEUL, 0x25285FED3E59781DUL,
|
||||
0x14C5AEDD76E092D3UL, 0x9BB5EE10567640AEUL, 0xCD62A1D43558FD06UL,
|
||||
0x70A7B09FC5F39447UL, 0xF10064AE92EFFB99UL, 0xD55FA1A918A23082UL,
|
||||
0xD03F28AD25C73A78UL, 0x76CFFFEE094D8B0EUL, 0x4FD5A46AD5A4B4CFUL,
|
||||
0x8F3A36F9D7BF87E3UL, 0x64224315210625BEUL, 0x749A131B71B64350UL,
|
||||
0x9034FF9DAC089F48UL, 0xB58D3017E7321217UL, 0x549D818937D5CE90UL,
|
||||
0x903CE1452419E99CUL, 0xFD052F0388DB2E76UL, 0x7390051E3972480EUL,
|
||||
0x5E5F6EC3F27B3679UL, 0x3E3637D4D4EE917DUL, 0x4FE04068CA2A4309UL,
|
||||
0x98C9C17454AAE42DUL, 0x659AE0BDB113BC21UL, 0x4C0BDECB1511AF4CUL,
|
||||
0x17048BFAEAC0006DUL, 0x68F106AADAA64912UL, 0x2286234ECEB7EAF0UL,
|
||||
0x350CD42CAF697E51UL, 0x8DCDE6D1FAC19A9FUL, 0xF97E55A245A8A8A2UL,
|
||||
0xAAE86B2092DA90A3UL, 0x5123E878AA8AEF76UL, 0x022B88B9694A55F6UL,
|
||||
0xC4C1A9B1C0221985UL, 0x20056D91DD5E0FFEUL, 0xF5BF61EC225C9843UL,
|
||||
0x1A315A05BDCF4A31UL, 0x5710A21A8DF4F15FUL, 0x99BD1A0AF97AD027UL,
|
||||
0x7602C5997AD4E12CUL
|
||||
};
|
||||
internal static int MaxLength
|
||||
{
|
||||
get
|
||||
{
|
||||
Debug.Assert(m_dicts.Count > 0); // Should be initialized
|
||||
|
||||
int iMaxLen = 0;
|
||||
foreach(int iLen in m_dicts.Keys)
|
||||
{
|
||||
if(iLen > iMaxLen) iMaxLen = iLen;
|
||||
}
|
||||
|
||||
return iMaxLen;
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool ContainsLength(int nLength)
|
||||
{
|
||||
Dictionary<string, bool> dDummy;
|
||||
return m_dicts.TryGetValue(nLength, out dDummy);
|
||||
}
|
||||
|
||||
public static bool IsPopularPassword(char[] vPassword)
|
||||
{
|
||||
Debug.Assert(PpcTable.Length == (PpcTableSize / 64));
|
||||
ulong uDummy;
|
||||
return IsPopularPassword(vPassword, out uDummy);
|
||||
}
|
||||
|
||||
public static bool IsPopularPassword(char[] vPassword, out ulong uDictSize)
|
||||
{
|
||||
if(vPassword == null) throw new ArgumentNullException("vPassword");
|
||||
if(vPassword.Length == 0) return false;
|
||||
if(vPassword.Length == 0) { uDictSize = 0; return false; }
|
||||
|
||||
foreach(char ch in vPassword)
|
||||
string str = new string(vPassword);
|
||||
|
||||
try { return IsPopularPasswordPriv(str, out uDictSize); }
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
|
||||
uDictSize = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool IsPopularPasswordPriv(string str, out ulong uDictSize)
|
||||
{
|
||||
Debug.Assert(m_dicts.Count > 0); // Should be initialized with data
|
||||
|
||||
Dictionary<string, bool> d;
|
||||
if(!m_dicts.TryGetValue(str.Length, out d))
|
||||
{
|
||||
if(!IsPopularChar(ch)) return false;
|
||||
uDictSize = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
byte[] pbUtf8 = StrUtil.Utf8.GetBytes(vPassword);
|
||||
uDictSize = (ulong)d.Count;
|
||||
return d.ContainsKey(str);
|
||||
}
|
||||
|
||||
int[] vIndices = GetTableIndices(pbUtf8, PpcTableSize);
|
||||
Array.Clear(pbUtf8, 0, pbUtf8.Length);
|
||||
|
||||
foreach(int iIndex in vIndices)
|
||||
public static void Add(byte[] pbData, bool bGZipped)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(!GetTableBit(PpcTable, iIndex)) return false;
|
||||
}
|
||||
if(bGZipped)
|
||||
pbData = MemUtil.Decompress(pbData);
|
||||
|
||||
return true;
|
||||
}
|
||||
string strData = StrUtil.Utf8.GetString(pbData, 0, pbData.Length);
|
||||
if(string.IsNullOrEmpty(strData)) { Debug.Assert(false); return; }
|
||||
|
||||
private static bool IsPopularChar(char ch)
|
||||
{
|
||||
return (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')) ||
|
||||
((ch >= '0') && (ch <= '9')) || (ch == '_') || (ch == '!'));
|
||||
}
|
||||
if(!char.IsWhiteSpace(strData[strData.Length - 1]))
|
||||
strData += "\n";
|
||||
|
||||
private static int[] GetTableIndices(byte[] pbPasswordUtf8, int nTableSize)
|
||||
{
|
||||
Debug.Assert(false, "not yet implemented");
|
||||
return null;
|
||||
#if TODO
|
||||
Debug.Assert((nTableSize >= 2) && (nTableSize <= 0x10000));
|
||||
Debug.Assert((nTableSize % 64) == 0);
|
||||
|
||||
SHA512Managed sha = new SHA512Managed();
|
||||
byte[] pbHash = sha.ComputeHash(pbPasswordUtf8);
|
||||
|
||||
int[] vIndices = new int[pbHash.Length / 2];
|
||||
for(int i = 0; i < vIndices.Length; ++i)
|
||||
vIndices[i] = ((((int)pbHash[i * 2] << 8) |
|
||||
(int)pbHash[i * 2 + 1]) % nTableSize);
|
||||
|
||||
return vIndices;
|
||||
#endif
|
||||
}
|
||||
|
||||
private static bool GetTableBit(ulong[] vTable, int iBit)
|
||||
{
|
||||
return ((vTable[iBit >> 6] & (1UL << (iBit & 0x3F))) != 0UL);
|
||||
}
|
||||
|
||||
#if (DEBUG && !KeePassLibSD && TODO)
|
||||
private static bool SetTableBit(ulong[] vTable, int iBit)
|
||||
{
|
||||
if(GetTableBit(vTable, iBit)) return false;
|
||||
|
||||
vTable[iBit >> 6] = (vTable[iBit >> 6] | (1UL << (iBit & 0x3F)));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void MakeList()
|
||||
{
|
||||
|
||||
string strData = File.ReadAllText("MostPopularPasswords.txt", StrUtil.Utf8);
|
||||
strData += " ";
|
||||
CharStream cs = new CharStream(strData);
|
||||
|
||||
List<string> vPasswords = new List<string>();
|
||||
StringBuilder sbPassword = new StringBuilder();
|
||||
while(true)
|
||||
{
|
||||
char ch = cs.ReadChar();
|
||||
if(ch == char.MinValue) break;
|
||||
|
||||
if(char.IsWhiteSpace(ch))
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int i = 0; i < strData.Length; ++i)
|
||||
{
|
||||
string strPassword = sbPassword.ToString();
|
||||
strPassword = strPassword.ToLower();
|
||||
char ch = strData[i];
|
||||
|
||||
if(strPassword.Length > 3)
|
||||
if(char.IsWhiteSpace(ch))
|
||||
{
|
||||
if(vPasswords.IndexOf(strPassword) < 0)
|
||||
vPasswords.Add(strPassword);
|
||||
int cc = sb.Length;
|
||||
if(cc > 0)
|
||||
{
|
||||
string strWord = sb.ToString();
|
||||
Debug.Assert(strWord.Length == cc);
|
||||
|
||||
Dictionary<string, bool> d;
|
||||
if(!m_dicts.TryGetValue(cc, out d))
|
||||
{
|
||||
d = new Dictionary<string, bool>();
|
||||
m_dicts[cc] = d;
|
||||
}
|
||||
|
||||
d[strWord] = true;
|
||||
sb.Remove(0, cc);
|
||||
}
|
||||
}
|
||||
|
||||
sbPassword = new StringBuilder();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Assert(!char.IsControl(ch) && !char.IsHighSurrogate(ch) &&
|
||||
!char.IsLowSurrogate(ch) && !char.IsSurrogate(ch));
|
||||
Debug.Assert(IsPopularChar(ch));
|
||||
sbPassword.Append(ch);
|
||||
else sb.Append(char.ToLower(ch));
|
||||
}
|
||||
}
|
||||
|
||||
ulong[] vTable = new ulong[PpcTableSize / 64];
|
||||
Array.Clear(vTable, 0, vTable.Length);
|
||||
|
||||
long lBitsInTable = 0;
|
||||
foreach(string strPassword in vPasswords)
|
||||
{
|
||||
byte[] pbUtf8 = StrUtil.Utf8.GetBytes(strPassword);
|
||||
int[] vIndices = GetTableIndices(pbUtf8, PpcTableSize);
|
||||
|
||||
foreach(int i in vIndices)
|
||||
{
|
||||
if(SetTableBit(vTable, i)) ++lBitsInTable;
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("\t\t\t");
|
||||
for(int i = 0; i < vTable.Length; ++i)
|
||||
{
|
||||
if(i > 0)
|
||||
{
|
||||
if((i % 3) == 0)
|
||||
{
|
||||
sb.AppendLine(",");
|
||||
sb.Append("\t\t\t");
|
||||
}
|
||||
else sb.Append(", ");
|
||||
}
|
||||
|
||||
sb.Append("0x");
|
||||
sb.Append(vTable[i].ToString("X16"));
|
||||
sb.Append("UL");
|
||||
}
|
||||
|
||||
sb.AppendLine();
|
||||
sb.AppendLine();
|
||||
sb.AppendLine("Bits set: " + lBitsInTable.ToString() + " of " +
|
||||
PpcTableSize.ToString());
|
||||
int cHashFn = GetTableIndices(StrUtil.Utf8.GetBytes("Dummy"), PpcTableSize).Length;
|
||||
sb.AppendLine("Hash functions: " + cHashFn.ToString());
|
||||
double dblPhi = Math.Pow(1.0 - ((double)cHashFn / PpcTableSize),
|
||||
(double)vPasswords.Count);
|
||||
sb.AppendLine("Phi (bits unset ratio) estimation: " +
|
||||
dblPhi.ToString(CultureInfo.InvariantCulture));
|
||||
dblPhi = ((double)(PpcTableSize - lBitsInTable) / (double)PpcTableSize);
|
||||
sb.AppendLine("Exact Phi: " + dblPhi.ToString(CultureInfo.InvariantCulture));
|
||||
sb.AppendLine("False positives ratio: " + Math.Pow(1.0 - dblPhi,
|
||||
(double)cHashFn).ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
File.WriteAllText("Table.txt", sb.ToString());
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -19,9 +19,10 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
|
||||
using ModernKeePassLib.Cryptography.PasswordGenerator;
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
namespace ModernKeePassLib.Cryptography
|
||||
@@ -32,13 +33,286 @@ namespace ModernKeePassLib.Cryptography
|
||||
/// </summary>
|
||||
public static class QualityEstimation
|
||||
{
|
||||
private enum CharSpaceBits : uint
|
||||
private static class PatternID
|
||||
{
|
||||
Control = 32,
|
||||
Alpha = 26,
|
||||
Number = 10,
|
||||
Special = 33,
|
||||
High = 112
|
||||
public const char LowerAlpha = 'L';
|
||||
public const char UpperAlpha = 'U';
|
||||
public const char Digit = 'D';
|
||||
public const char Special = 'S';
|
||||
public const char High = 'H';
|
||||
public const char Other = 'X';
|
||||
|
||||
public const char Dictionary = 'W';
|
||||
public const char Repetition = 'R';
|
||||
public const char Number = 'N';
|
||||
public const char DiffSeq = 'C';
|
||||
|
||||
public const string All = "LUDSHXWRNC";
|
||||
}
|
||||
|
||||
// private static class CharDistrib
|
||||
// {
|
||||
// public static readonly ulong[] LowerAlpha = new ulong[26] {
|
||||
// 884, 211, 262, 249, 722, 98, 172, 234, 556, 124, 201, 447, 321,
|
||||
// 483, 518, 167, 18, 458, 416, 344, 231, 105, 80, 48, 238, 76
|
||||
// };
|
||||
// public static readonly ulong[] UpperAlpha = new ulong[26] {
|
||||
// 605, 188, 209, 200, 460, 81, 130, 163, 357, 122, 144, 332, 260,
|
||||
// 317, 330, 132, 18, 320, 315, 250, 137, 76, 60, 36, 161, 54
|
||||
// };
|
||||
// public static readonly ulong[] Digit = new ulong[10] {
|
||||
// 574, 673, 524, 377, 339, 336, 312, 310, 357, 386
|
||||
// };
|
||||
// }
|
||||
|
||||
private sealed class QeCharType
|
||||
{
|
||||
private readonly char m_chTypeID;
|
||||
public char TypeID { get { return m_chTypeID; } }
|
||||
|
||||
private readonly string m_strAlph;
|
||||
public string Alphabet { get { return m_strAlph; } }
|
||||
|
||||
private readonly int m_nChars;
|
||||
public int CharCount { get { return m_nChars; } }
|
||||
|
||||
private readonly char m_chFirst;
|
||||
private readonly char m_chLast;
|
||||
|
||||
private readonly double m_dblCharSize;
|
||||
public double CharSize { get { return m_dblCharSize; } }
|
||||
|
||||
public QeCharType(char chTypeID, string strAlphabet, bool bIsConsecutive)
|
||||
{
|
||||
if(strAlphabet == null) throw new ArgumentNullException();
|
||||
if(strAlphabet.Length == 0) throw new ArgumentException();
|
||||
|
||||
m_chTypeID = chTypeID;
|
||||
m_strAlph = strAlphabet;
|
||||
m_nChars = m_strAlph.Length;
|
||||
m_chFirst = (bIsConsecutive ? m_strAlph[0] : char.MinValue);
|
||||
m_chLast = (bIsConsecutive ? m_strAlph[m_nChars - 1] : char.MinValue);
|
||||
|
||||
m_dblCharSize = Log2(m_nChars);
|
||||
|
||||
Debug.Assert(((int)(m_chLast - m_chFirst) == (m_nChars - 1)) ||
|
||||
!bIsConsecutive);
|
||||
}
|
||||
|
||||
public QeCharType(char chTypeID, int nChars) // Catch-none set
|
||||
{
|
||||
if(nChars <= 0) throw new ArgumentOutOfRangeException();
|
||||
|
||||
m_chTypeID = chTypeID;
|
||||
m_strAlph = string.Empty;
|
||||
m_nChars = nChars;
|
||||
m_chFirst = char.MinValue;
|
||||
m_chLast = char.MinValue;
|
||||
|
||||
m_dblCharSize = Log2(m_nChars);
|
||||
}
|
||||
|
||||
public bool Contains(char ch)
|
||||
{
|
||||
if(m_chLast != char.MinValue)
|
||||
return ((ch >= m_chFirst) && (ch <= m_chLast));
|
||||
|
||||
Debug.Assert(m_strAlph.Length > 0); // Don't call for catch-none set
|
||||
return (m_strAlph.IndexOf(ch) >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class EntropyEncoder
|
||||
{
|
||||
private readonly string m_strAlph;
|
||||
private Dictionary<char, ulong> m_dHisto = new Dictionary<char, ulong>();
|
||||
private readonly ulong m_uBaseWeight;
|
||||
private readonly ulong m_uCharWeight;
|
||||
private readonly ulong m_uOccExclThreshold;
|
||||
|
||||
public EntropyEncoder(string strAlphabet, ulong uBaseWeight,
|
||||
ulong uCharWeight, ulong uOccExclThreshold)
|
||||
{
|
||||
if(strAlphabet == null) throw new ArgumentNullException();
|
||||
if(strAlphabet.Length == 0) throw new ArgumentException();
|
||||
|
||||
m_strAlph = strAlphabet;
|
||||
m_uBaseWeight = uBaseWeight;
|
||||
m_uCharWeight = uCharWeight;
|
||||
m_uOccExclThreshold = uOccExclThreshold;
|
||||
|
||||
#if DEBUG
|
||||
Dictionary<char, bool> d = new Dictionary<char, bool>();
|
||||
foreach(char ch in m_strAlph) { d[ch] = true; }
|
||||
Debug.Assert(d.Count == m_strAlph.Length); // No duplicates
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
m_dHisto.Clear();
|
||||
}
|
||||
|
||||
public void Write(char ch)
|
||||
{
|
||||
Debug.Assert(m_strAlph.IndexOf(ch) >= 0);
|
||||
|
||||
ulong uOcc;
|
||||
m_dHisto.TryGetValue(ch, out uOcc);
|
||||
Debug.Assert(m_dHisto.ContainsKey(ch) || (uOcc == 0));
|
||||
m_dHisto[ch] = uOcc + 1;
|
||||
}
|
||||
|
||||
public double GetOutputSize()
|
||||
{
|
||||
ulong uTotalWeight = m_uBaseWeight * (ulong)m_strAlph.Length;
|
||||
foreach(ulong u in m_dHisto.Values)
|
||||
{
|
||||
Debug.Assert(u >= 1);
|
||||
if(u > m_uOccExclThreshold)
|
||||
uTotalWeight += (u - m_uOccExclThreshold) * m_uCharWeight;
|
||||
}
|
||||
|
||||
double dSize = 0.0, dTotalWeight = (double)uTotalWeight;
|
||||
foreach(ulong u in m_dHisto.Values)
|
||||
{
|
||||
ulong uWeight = m_uBaseWeight;
|
||||
if(u > m_uOccExclThreshold)
|
||||
uWeight += (u - m_uOccExclThreshold) * m_uCharWeight;
|
||||
|
||||
dSize -= (double)u * Log2((double)uWeight / dTotalWeight);
|
||||
}
|
||||
|
||||
return dSize;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class MultiEntropyEncoder
|
||||
{
|
||||
private Dictionary<char, EntropyEncoder> m_dEncs =
|
||||
new Dictionary<char, EntropyEncoder>();
|
||||
|
||||
public MultiEntropyEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
public void AddEncoder(char chTypeID, EntropyEncoder ec)
|
||||
{
|
||||
if(ec == null) { Debug.Assert(false); return; }
|
||||
|
||||
Debug.Assert(!m_dEncs.ContainsKey(chTypeID));
|
||||
m_dEncs[chTypeID] = ec;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
foreach(EntropyEncoder ec in m_dEncs.Values) { ec.Reset(); }
|
||||
}
|
||||
|
||||
public bool Write(char chTypeID, char chData)
|
||||
{
|
||||
EntropyEncoder ec;
|
||||
if(!m_dEncs.TryGetValue(chTypeID, out ec))
|
||||
return false;
|
||||
|
||||
ec.Write(chData);
|
||||
return true;
|
||||
}
|
||||
|
||||
public double GetOutputSize()
|
||||
{
|
||||
double d = 0.0;
|
||||
|
||||
foreach(EntropyEncoder ec in m_dEncs.Values)
|
||||
{
|
||||
d += ec.GetOutputSize();
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class QePatternInstance
|
||||
{
|
||||
private readonly int m_iPos;
|
||||
public int Position { get { return m_iPos; } }
|
||||
|
||||
private readonly int m_nLen;
|
||||
public int Length { get { return m_nLen; } }
|
||||
|
||||
private readonly char m_chPatternID;
|
||||
public char PatternID { get { return m_chPatternID; } }
|
||||
|
||||
private readonly double m_dblCost;
|
||||
public double Cost { get { return m_dblCost; } }
|
||||
|
||||
private readonly QeCharType m_ctSingle;
|
||||
public QeCharType SingleCharType { get { return m_ctSingle; } }
|
||||
|
||||
public QePatternInstance(int iPosition, int nLength, char chPatternID,
|
||||
double dblCost)
|
||||
{
|
||||
m_iPos = iPosition;
|
||||
m_nLen = nLength;
|
||||
m_chPatternID = chPatternID;
|
||||
m_dblCost = dblCost;
|
||||
m_ctSingle = null;
|
||||
}
|
||||
|
||||
public QePatternInstance(int iPosition, int nLength, QeCharType ctSingle)
|
||||
{
|
||||
m_iPos = iPosition;
|
||||
m_nLen = nLength;
|
||||
m_chPatternID = ctSingle.TypeID;
|
||||
m_dblCost = ctSingle.CharSize;
|
||||
m_ctSingle = ctSingle;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class QePathState
|
||||
{
|
||||
public readonly int Position;
|
||||
public readonly List<QePatternInstance> Path;
|
||||
|
||||
public QePathState(int iPosition, List<QePatternInstance> lPath)
|
||||
{
|
||||
this.Position = iPosition;
|
||||
this.Path = lPath;
|
||||
}
|
||||
}
|
||||
|
||||
private static object m_objSyncInit = new object();
|
||||
private static List<QeCharType> m_lCharTypes = null;
|
||||
|
||||
private static void EnsureInitialized()
|
||||
{
|
||||
lock(m_objSyncInit)
|
||||
{
|
||||
if(m_lCharTypes == null)
|
||||
{
|
||||
string strSpecial = PwCharSet.PrintableAsciiSpecial;
|
||||
if(strSpecial.IndexOf(' ') >= 0) { Debug.Assert(false); }
|
||||
else strSpecial = strSpecial + " ";
|
||||
|
||||
int nSp = strSpecial.Length;
|
||||
int nHi = PwCharSet.HighAnsiChars.Length;
|
||||
|
||||
m_lCharTypes = new List<QeCharType>();
|
||||
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.LowerAlpha,
|
||||
PwCharSet.LowerCase, true));
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.UpperAlpha,
|
||||
PwCharSet.UpperCase, true));
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.Digit,
|
||||
PwCharSet.Digits, true));
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.Special,
|
||||
strSpecial, false));
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.High,
|
||||
PwCharSet.HighAnsiChars, false));
|
||||
m_lCharTypes.Add(new QeCharType(PatternID.Other,
|
||||
0x10000 - (2 * 26) - 10 - nSp - nHi));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -46,84 +320,95 @@ namespace ModernKeePassLib.Cryptography
|
||||
/// </summary>
|
||||
/// <param name="vPasswordChars">Password to check.</param>
|
||||
/// <returns>Estimated bit-strength of the password.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if the input
|
||||
/// parameter is <c>null</c>.</exception>
|
||||
public static uint EstimatePasswordBits(char[] vPasswordChars)
|
||||
{
|
||||
Debug.Assert(vPasswordChars != null);
|
||||
if(vPasswordChars == null) throw new ArgumentNullException("vPasswordChars");
|
||||
if(vPasswordChars == null) { Debug.Assert(false); return 0; }
|
||||
if(vPasswordChars.Length == 0) return 0;
|
||||
|
||||
bool bChLower = false, bChUpper = false, bChNumber = false;
|
||||
bool bChSpecial = false, bChHigh = false, bChControl = false;
|
||||
Dictionary<char, uint> vCharCounts = new Dictionary<char, uint>();
|
||||
Dictionary<int, uint> vDifferences = new Dictionary<int, uint>();
|
||||
double dblEffectiveLength = 0.0;
|
||||
EnsureInitialized();
|
||||
|
||||
for(int i = 0; i < vPasswordChars.Length; ++i) // Get character types
|
||||
int n = vPasswordChars.Length;
|
||||
List<QePatternInstance>[] vPatterns = new List<QePatternInstance>[n];
|
||||
for(int i = 0; i < n; ++i)
|
||||
{
|
||||
char tch = vPasswordChars[i];
|
||||
vPatterns[i] = new List<QePatternInstance>();
|
||||
|
||||
if(tch < ' ') bChControl = true;
|
||||
else if((tch >= 'A') && (tch <= 'Z')) bChUpper = true;
|
||||
else if((tch >= 'a') && (tch <= 'z')) bChLower = true;
|
||||
else if((tch >= '0') && (tch <= '9')) bChNumber = true;
|
||||
else if((tch >= ' ') && (tch <= '/')) bChSpecial = true;
|
||||
else if((tch >= ':') && (tch <= '@')) bChSpecial = true;
|
||||
else if((tch >= '[') && (tch <= '`')) bChSpecial = true;
|
||||
else if((tch >= '{') && (tch <= '~')) bChSpecial = true;
|
||||
else if(tch > '~') bChHigh = true;
|
||||
QePatternInstance piChar = new QePatternInstance(i, 1,
|
||||
GetCharType(vPasswordChars[i]));
|
||||
vPatterns[i].Add(piChar);
|
||||
}
|
||||
|
||||
double dblDiffFactor = 1.0;
|
||||
if(i >= 1)
|
||||
FindRepetitions(vPasswordChars, vPatterns);
|
||||
FindNumbers(vPasswordChars, vPatterns);
|
||||
FindDiffSeqs(vPasswordChars, vPatterns);
|
||||
FindPopularPasswords(vPasswordChars, vPatterns);
|
||||
|
||||
// Encoders must not be static, because the entropy estimation
|
||||
// may run concurrently in multiple threads and the encoders are
|
||||
// not read-only
|
||||
EntropyEncoder ecPattern = new EntropyEncoder(PatternID.All, 0, 1, 0);
|
||||
MultiEntropyEncoder mcData = new MultiEntropyEncoder();
|
||||
for(int i = 0; i < (m_lCharTypes.Count - 1); ++i)
|
||||
{
|
||||
// Let m be the alphabet size. In order to ensure that two same
|
||||
// characters cost at least as much as a single character, for
|
||||
// the probability p and weight w of the character it must hold:
|
||||
// -log(1/m) >= -2*log(p)
|
||||
// <=> log(1/m) <= log(p^2) <=> 1/m <= p^2 <=> p >= sqrt(1/m);
|
||||
// sqrt(1/m) = (1+w)/(m+w)
|
||||
// <=> m+w = (1+w)*sqrt(m) <=> m+w = sqrt(m) + w*sqrt(m)
|
||||
// <=> w*(1-sqrt(m)) = sqrt(m) - m <=> w = (sqrt(m)-m)/(1-sqrt(m))
|
||||
// <=> w = (sqrt(m)-m)*(1+sqrt(m))/(1-m)
|
||||
// <=> w = (sqrt(m)-m+m-m*sqrt(m))/(1-m) <=> w = sqrt(m)
|
||||
ulong uw = (ulong)Math.Sqrt((double)m_lCharTypes[i].CharCount);
|
||||
|
||||
mcData.AddEncoder(m_lCharTypes[i].TypeID, new EntropyEncoder(
|
||||
m_lCharTypes[i].Alphabet, 1, uw, 1));
|
||||
}
|
||||
|
||||
double dblMinCost = (double)int.MaxValue;
|
||||
int tStart = Environment.TickCount;
|
||||
|
||||
Stack<QePathState> sRec = new Stack<QePathState>();
|
||||
sRec.Push(new QePathState(0, new List<QePatternInstance>()));
|
||||
while(sRec.Count > 0)
|
||||
{
|
||||
int tDiff = Environment.TickCount - tStart;
|
||||
if(tDiff > 500) break;
|
||||
|
||||
QePathState s = sRec.Pop();
|
||||
|
||||
if(s.Position >= n)
|
||||
{
|
||||
int iDiff = (int)tch - (int)vPasswordChars[i - 1];
|
||||
Debug.Assert(s.Position == n);
|
||||
|
||||
uint uDiffCount;
|
||||
if(vDifferences.TryGetValue(iDiff, out uDiffCount))
|
||||
{
|
||||
++uDiffCount;
|
||||
vDifferences[iDiff] = uDiffCount;
|
||||
dblDiffFactor /= (double)uDiffCount;
|
||||
}
|
||||
else vDifferences.Add(iDiff, 1);
|
||||
}
|
||||
|
||||
uint uCharCount;
|
||||
if(vCharCounts.TryGetValue(tch, out uCharCount))
|
||||
{
|
||||
++uCharCount;
|
||||
vCharCounts[tch] = uCharCount;
|
||||
dblEffectiveLength += dblDiffFactor * (1.0 / (double)uCharCount);
|
||||
double dblCost = ComputePathCost(s.Path, vPasswordChars,
|
||||
ecPattern, mcData);
|
||||
if(dblCost < dblMinCost) dblMinCost = dblCost;
|
||||
}
|
||||
else
|
||||
{
|
||||
vCharCounts.Add(tch, 1);
|
||||
dblEffectiveLength += dblDiffFactor;
|
||||
List<QePatternInstance> lSubs = vPatterns[s.Position];
|
||||
for(int i = lSubs.Count - 1; i >= 0; --i)
|
||||
{
|
||||
QePatternInstance pi = lSubs[i];
|
||||
Debug.Assert(pi.Position == s.Position);
|
||||
Debug.Assert(pi.Length >= 1);
|
||||
|
||||
List<QePatternInstance> lNewPath =
|
||||
new List<QePatternInstance>(s.Path.Count + 1);
|
||||
lNewPath.AddRange(s.Path);
|
||||
lNewPath.Add(pi);
|
||||
Debug.Assert(lNewPath.Capacity == (s.Path.Count + 1));
|
||||
|
||||
QePathState sNew = new QePathState(s.Position +
|
||||
pi.Length, lNewPath);
|
||||
sRec.Push(sNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint uCharSpace = 0;
|
||||
if(bChControl) uCharSpace += (uint)CharSpaceBits.Control;
|
||||
if(bChUpper) uCharSpace += (uint)CharSpaceBits.Alpha;
|
||||
if(bChLower) uCharSpace += (uint)CharSpaceBits.Alpha;
|
||||
if(bChNumber) uCharSpace += (uint)CharSpaceBits.Number;
|
||||
if(bChSpecial) uCharSpace += (uint)CharSpaceBits.Special;
|
||||
if(bChHigh) uCharSpace += (uint)CharSpaceBits.High;
|
||||
|
||||
if(uCharSpace == 0) return 0;
|
||||
|
||||
double dblBitsPerChar = Math.Log((double)uCharSpace) / Math.Log(2.0);
|
||||
double dblRating = dblBitsPerChar * dblEffectiveLength;
|
||||
|
||||
#if !KeePassLibSD
|
||||
char[] vLowerCopy = new char[vPasswordChars.Length];
|
||||
for(int ilc = 0; ilc < vLowerCopy.Length; ++ilc)
|
||||
vLowerCopy[ilc] = char.ToLower(vPasswordChars[ilc]);
|
||||
if(PopularPasswords.IsPopularPassword(vLowerCopy)) dblRating /= 8.0;
|
||||
Array.Clear(vLowerCopy, 0, vLowerCopy.Length);
|
||||
#endif
|
||||
|
||||
return (uint)Math.Ceiling(dblRating);
|
||||
return (uint)Math.Ceiling(dblMinCost);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -141,5 +426,343 @@ namespace ModernKeePassLib.Cryptography
|
||||
|
||||
return uResult;
|
||||
}
|
||||
|
||||
private static QeCharType GetCharType(char ch)
|
||||
{
|
||||
int nTypes = m_lCharTypes.Count;
|
||||
Debug.Assert((nTypes > 0) && (m_lCharTypes[nTypes - 1].CharCount > 256));
|
||||
|
||||
for(int i = 0; i < (nTypes - 1); ++i)
|
||||
{
|
||||
if(m_lCharTypes[i].Contains(ch))
|
||||
return m_lCharTypes[i];
|
||||
}
|
||||
|
||||
return m_lCharTypes[nTypes - 1];
|
||||
}
|
||||
|
||||
private static double ComputePathCost(List<QePatternInstance> l,
|
||||
char[] vPassword, EntropyEncoder ecPattern, MultiEntropyEncoder mcData)
|
||||
{
|
||||
ecPattern.Reset();
|
||||
for(int i = 0; i < l.Count; ++i)
|
||||
ecPattern.Write(l[i].PatternID);
|
||||
double dblPatternCost = ecPattern.GetOutputSize();
|
||||
|
||||
mcData.Reset();
|
||||
double dblDataCost = 0.0;
|
||||
foreach(QePatternInstance pi in l)
|
||||
{
|
||||
QeCharType tChar = pi.SingleCharType;
|
||||
if(tChar != null)
|
||||
{
|
||||
char ch = vPassword[pi.Position];
|
||||
if(!mcData.Write(tChar.TypeID, ch))
|
||||
dblDataCost += pi.Cost;
|
||||
}
|
||||
else dblDataCost += pi.Cost;
|
||||
}
|
||||
dblDataCost += mcData.GetOutputSize();
|
||||
|
||||
return (dblPatternCost + dblDataCost);
|
||||
}
|
||||
|
||||
private static void FindPopularPasswords(char[] vPassword,
|
||||
List<QePatternInstance>[] vPatterns)
|
||||
{
|
||||
int n = vPassword.Length;
|
||||
|
||||
char[] vLower = new char[n];
|
||||
char[] vLeet = new char[n];
|
||||
for(int i = 0; i < n; ++i)
|
||||
{
|
||||
char ch = vPassword[i];
|
||||
|
||||
vLower[i] = char.ToLower(ch);
|
||||
vLeet[i] = char.ToLower(DecodeLeetChar(ch));
|
||||
}
|
||||
|
||||
char chErased = default(char);
|
||||
Debug.Assert(chErased == char.MinValue);
|
||||
|
||||
int nMaxLen = Math.Min(n, PopularPasswords.MaxLength);
|
||||
for(int nSubLen = nMaxLen; nSubLen >= 3; --nSubLen)
|
||||
{
|
||||
if(!PopularPasswords.ContainsLength(nSubLen)) continue;
|
||||
|
||||
char[] vSub = new char[nSubLen];
|
||||
|
||||
for(int i = 0; i <= (n - nSubLen); ++i)
|
||||
{
|
||||
if(Array.IndexOf<char>(vLower, chErased, i, nSubLen) >= 0)
|
||||
continue;
|
||||
|
||||
Array.Copy(vLower, i, vSub, 0, nSubLen);
|
||||
if(!EvalAddPopularPasswordPattern(vPatterns, vPassword,
|
||||
i, vSub, 0.0))
|
||||
{
|
||||
Array.Copy(vLeet, i, vSub, 0, nSubLen);
|
||||
if(EvalAddPopularPasswordPattern(vPatterns, vPassword,
|
||||
i, vSub, 1.5))
|
||||
{
|
||||
Array.Clear(vLower, i, nSubLen); // Not vLeet
|
||||
Debug.Assert(vLower[i] == chErased);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Clear(vLower, i, nSubLen);
|
||||
Debug.Assert(vLower[i] == chErased);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool EvalAddPopularPasswordPattern(List<QePatternInstance>[] vPatterns,
|
||||
char[] vPassword, int i, char[] vSub, double dblCostPerMod)
|
||||
{
|
||||
ulong uDictSize;
|
||||
if(!PopularPasswords.IsPopularPassword(vSub, out uDictSize))
|
||||
return false;
|
||||
|
||||
int n = vSub.Length;
|
||||
int d = HammingDist(vSub, 0, vPassword, i, n);
|
||||
|
||||
double dblCost = Log2((double)uDictSize);
|
||||
|
||||
// dblCost += log2(n binom d)
|
||||
int k = Math.Min(d, n - d);
|
||||
for(int j = n; j > (n - k); --j)
|
||||
dblCost += Log2(j);
|
||||
for(int j = k; j >= 2; --j)
|
||||
dblCost -= Log2(j);
|
||||
|
||||
dblCost += dblCostPerMod * (double)d;
|
||||
|
||||
vPatterns[i].Add(new QePatternInstance(i, n, PatternID.Dictionary,
|
||||
dblCost));
|
||||
return true;
|
||||
}
|
||||
|
||||
private static char DecodeLeetChar(char chLeet)
|
||||
{
|
||||
if((chLeet >= '\u00C0') && (chLeet <= '\u00C6')) return 'a';
|
||||
if((chLeet >= '\u00C8') && (chLeet <= '\u00CB')) return 'e';
|
||||
if((chLeet >= '\u00CC') && (chLeet <= '\u00CF')) return 'i';
|
||||
if((chLeet >= '\u00D2') && (chLeet <= '\u00D6')) return 'o';
|
||||
if((chLeet >= '\u00D9') && (chLeet <= '\u00DC')) return 'u';
|
||||
if((chLeet >= '\u00E0') && (chLeet <= '\u00E6')) return 'a';
|
||||
if((chLeet >= '\u00E8') && (chLeet <= '\u00EB')) return 'e';
|
||||
if((chLeet >= '\u00EC') && (chLeet <= '\u00EF')) return 'i';
|
||||
if((chLeet >= '\u00F2') && (chLeet <= '\u00F6')) return 'o';
|
||||
if((chLeet >= '\u00F9') && (chLeet <= '\u00FC')) return 'u';
|
||||
|
||||
char ch;
|
||||
switch(chLeet)
|
||||
{
|
||||
case '4':
|
||||
case '@':
|
||||
case '?':
|
||||
case '^':
|
||||
case '\u00AA': ch = 'a'; break;
|
||||
case '8':
|
||||
case '\u00DF': ch = 'b'; break;
|
||||
case '(':
|
||||
case '{':
|
||||
case '[':
|
||||
case '<':
|
||||
case '\u00A2':
|
||||
case '\u00A9':
|
||||
case '\u00C7':
|
||||
case '\u00E7': ch = 'c'; break;
|
||||
case '\u00D0':
|
||||
case '\u00F0': ch = 'd'; break;
|
||||
case '3':
|
||||
case '\u20AC':
|
||||
case '&':
|
||||
case '\u00A3': ch = 'e'; break;
|
||||
case '6':
|
||||
case '9': ch = 'g'; break;
|
||||
case '#': ch = 'h'; break;
|
||||
case '1':
|
||||
case '!':
|
||||
case '|':
|
||||
case '\u00A1':
|
||||
case '\u00A6': ch = 'i'; break;
|
||||
case '\u00D1':
|
||||
case '\u00F1': ch = 'n'; break;
|
||||
case '0':
|
||||
case '*':
|
||||
case '\u00A4': // Currency
|
||||
case '\u00B0': // Degree
|
||||
case '\u00D8':
|
||||
case '\u00F8': ch = 'o'; break;
|
||||
case '\u00AE': ch = 'r'; break;
|
||||
case '$':
|
||||
case '5':
|
||||
case '\u00A7': ch = 's'; break;
|
||||
case '+':
|
||||
case '7': ch = 't'; break;
|
||||
case '\u00B5': ch = 'u'; break;
|
||||
case '%':
|
||||
case '\u00D7': ch = 'x'; break;
|
||||
case '\u00A5':
|
||||
case '\u00DD':
|
||||
case '\u00FD':
|
||||
case '\u00FF': ch = 'y'; break;
|
||||
case '2': ch = 'z'; break;
|
||||
default: ch = chLeet; break;
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
private static int HammingDist(char[] v1, int iOffset1,
|
||||
char[] v2, int iOffset2, int nLength)
|
||||
{
|
||||
int nDist = 0;
|
||||
for(int i = 0; i < nLength; ++i)
|
||||
{
|
||||
if(v1[iOffset1 + i] != v2[iOffset2 + i]) ++nDist;
|
||||
}
|
||||
|
||||
return nDist;
|
||||
}
|
||||
|
||||
private static void FindRepetitions(char[] vPassword,
|
||||
List<QePatternInstance>[] vPatterns)
|
||||
{
|
||||
int n = vPassword.Length;
|
||||
char[] v = new char[n];
|
||||
Array.Copy(vPassword, v, n);
|
||||
|
||||
char chErased = char.MaxValue;
|
||||
for(int m = (n / 2); m >= 3; --m)
|
||||
{
|
||||
for(int x1 = 0; x1 <= (n - (2 * m)); ++x1)
|
||||
{
|
||||
bool bFoundRep = false;
|
||||
|
||||
for(int x2 = (x1 + m); x2 <= (n - m); ++x2)
|
||||
{
|
||||
if(PartsEqual(v, x1, x2, m))
|
||||
{
|
||||
double dblCost = Log2(x1 + 1) + Log2(m);
|
||||
vPatterns[x2].Add(new QePatternInstance(x2, m,
|
||||
PatternID.Repetition, dblCost));
|
||||
|
||||
ErasePart(v, x2, m, ref chErased);
|
||||
bFoundRep = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(bFoundRep) ErasePart(v, x1, m, ref chErased);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool PartsEqual(char[] v, int x1, int x2, int nLength)
|
||||
{
|
||||
for(int i = 0; i < nLength; ++i)
|
||||
{
|
||||
if(v[x1 + i] != v[x2 + i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void ErasePart(char[] v, int i, int n, ref char chErased)
|
||||
{
|
||||
for(int j = 0; j < n; ++j)
|
||||
{
|
||||
v[i + j] = chErased;
|
||||
--chErased;
|
||||
}
|
||||
}
|
||||
|
||||
private static void FindNumbers(char[] vPassword,
|
||||
List<QePatternInstance>[] vPatterns)
|
||||
{
|
||||
int n = vPassword.Length;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int i = 0; i < n; ++i)
|
||||
{
|
||||
char ch = vPassword[i];
|
||||
if((ch >= '0') && (ch <= '9')) sb.Append(ch);
|
||||
else
|
||||
{
|
||||
AddNumberPattern(vPatterns, sb.ToString(), i - sb.Length);
|
||||
sb.Remove(0, sb.Length);
|
||||
}
|
||||
}
|
||||
AddNumberPattern(vPatterns, sb.ToString(), n - sb.Length);
|
||||
}
|
||||
|
||||
private static void AddNumberPattern(List<QePatternInstance>[] vPatterns,
|
||||
string strNumber, int i)
|
||||
{
|
||||
if(strNumber.Length <= 2) return;
|
||||
|
||||
int nZeros = 0;
|
||||
for(int j = 0; j < strNumber.Length; ++j)
|
||||
{
|
||||
if(strNumber[j] != '0') break;
|
||||
++nZeros;
|
||||
}
|
||||
|
||||
double dblCost = Log2(nZeros + 1);
|
||||
if(nZeros < strNumber.Length)
|
||||
{
|
||||
string strNonZero = strNumber.Substring(nZeros);
|
||||
|
||||
#if KeePassLibSD
|
||||
try { dblCost += Log2(double.Parse(strNonZero)); }
|
||||
catch(Exception) { Debug.Assert(false); return; }
|
||||
#else
|
||||
double d;
|
||||
if(double.TryParse(strNonZero, out d))
|
||||
dblCost += Log2(d);
|
||||
else { Debug.Assert(false); return; }
|
||||
#endif
|
||||
}
|
||||
|
||||
vPatterns[i].Add(new QePatternInstance(i, strNumber.Length,
|
||||
PatternID.Number, dblCost));
|
||||
}
|
||||
|
||||
private static void FindDiffSeqs(char[] vPassword,
|
||||
List<QePatternInstance>[] vPatterns)
|
||||
{
|
||||
int d = int.MinValue, p = 0;
|
||||
string str = new string(vPassword) + new string(char.MaxValue, 1);
|
||||
|
||||
for(int i = 1; i < str.Length; ++i)
|
||||
{
|
||||
int dCur = (int)str[i] - (int)str[i - 1];
|
||||
if(dCur != d)
|
||||
{
|
||||
if((i - p) >= 3) // At least 3 chars involved
|
||||
{
|
||||
QeCharType ct = GetCharType(str[p]);
|
||||
double dblCost = ct.CharSize + Log2(i - p - 1);
|
||||
|
||||
vPatterns[p].Add(new QePatternInstance(p,
|
||||
i - p, PatternID.DiffSeq, dblCost));
|
||||
}
|
||||
|
||||
d = dCur;
|
||||
p = i - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double Log2(double dblValue)
|
||||
{
|
||||
#if KeePassLibSD
|
||||
return (Math.Log(dblValue) / Math.Log(2.0));
|
||||
#else
|
||||
return Math.Log(dblValue, 2.0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,48 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Security.Cryptography;
|
||||
using Windows.Security.Cryptography.Core;
|
||||
using Windows.Storage.Streams;
|
||||
|
||||
namespace ModernKeePassLib.Cryptography
|
||||
{
|
||||
// Singleton adaptor that provides a part of the .net SHA256Managed class
|
||||
|
||||
class SHA256Managed
|
||||
{
|
||||
private static SHA256Managed instance;
|
||||
private static HashAlgorithmProvider m_AlgProv;
|
||||
|
||||
private SHA256Managed()
|
||||
{
|
||||
String strAlgName = "SHA256";
|
||||
m_AlgProv = HashAlgorithmProvider.OpenAlgorithm(strAlgName);
|
||||
m_AlgProv.CreateHash();
|
||||
}
|
||||
|
||||
public static SHA256Managed Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new SHA256Managed();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] ComputeHash(byte[] buffer )
|
||||
{
|
||||
IBuffer input = CryptographicBuffer.CreateFromByteArray( buffer);
|
||||
IBuffer hashBuffer = m_AlgProv.HashData(input);
|
||||
byte[] hash;
|
||||
CryptographicBuffer.CopyToByteArray(hashBuffer, out hash);
|
||||
return hash;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -20,33 +20,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security;
|
||||
using Windows.Security.Cryptography.Core;
|
||||
#if PCL
|
||||
using Windows.Security.Cryptography;
|
||||
#else
|
||||
using System.Security.Cryptography;
|
||||
#endif
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.Diagnostics;
|
||||
|
||||
using ModernKeePassLib.Cryptography.Cipher;
|
||||
using ModernKeePassLib.Keys;
|
||||
using ModernKeePassLib.Utility;
|
||||
using ModernKeePassLib.Resources;
|
||||
using Windows.Storage.Streams;
|
||||
using Windows.Security.Cryptography;
|
||||
using ModernKeePassLib.Security;
|
||||
|
||||
namespace ModernKeePassLib.Cryptography
|
||||
{
|
||||
/* #pragma warning disable 1591
|
||||
/// <summary>
|
||||
/// Return values of the <c>SelfTest.Perform</c> method.
|
||||
/// </summary>
|
||||
public enum SelfTestResult
|
||||
{
|
||||
Success = 0,
|
||||
RijndaelEcbError = 1,
|
||||
Salsa20Error = 2,
|
||||
NativeKeyTransformationError = 3
|
||||
}
|
||||
#pragma warning restore 1591 */
|
||||
/* /// <summary>
|
||||
/// Return values of the <c>SelfTest.Perform</c> method.
|
||||
/// </summary>
|
||||
public enum SelfTestResult
|
||||
{
|
||||
Success = 0,
|
||||
RijndaelEcbError = 1,
|
||||
Salsa20Error = 2,
|
||||
NativeKeyTransformationError = 3
|
||||
} */
|
||||
|
||||
/// <summary>
|
||||
/// Class containing self-test methods.
|
||||
/// </summary>
|
||||
public static class SelfTest
|
||||
/// <summary>
|
||||
/// Class containing self-test methods.
|
||||
/// </summary>
|
||||
public static class SelfTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Perform a self-test.
|
||||
@@ -57,8 +62,10 @@ namespace ModernKeePassLib.Cryptography
|
||||
|
||||
TestRijndael();
|
||||
TestSalsa20();
|
||||
|
||||
|
||||
#if !PCL
|
||||
TestNativeKeyTransform();
|
||||
#endif
|
||||
|
||||
TestHmacOtp();
|
||||
|
||||
@@ -74,7 +81,7 @@ namespace ModernKeePassLib.Cryptography
|
||||
|
||||
internal static void TestFipsComplianceProblems()
|
||||
{
|
||||
#if !KeePassWinRT
|
||||
#if !PCL && !KeePassRT
|
||||
try { new RijndaelManaged(); }
|
||||
catch(Exception exAes)
|
||||
{
|
||||
@@ -91,7 +98,7 @@ namespace ModernKeePassLib.Cryptography
|
||||
|
||||
private static void TestRijndael()
|
||||
{
|
||||
|
||||
#if !PCL && !KeePassRT
|
||||
// Test vector (official ECB test vector #356)
|
||||
byte[] pbIV = new byte[16];
|
||||
byte[] pbTestKey = new byte[32];
|
||||
@@ -106,24 +113,6 @@ namespace ModernKeePassLib.Cryptography
|
||||
for(i = 0; i < 16; ++i) pbTestData[i] = 0;
|
||||
pbTestData[0] = 0x04;
|
||||
|
||||
String strAlgName = "AES_ECB"; // Algorithm name
|
||||
|
||||
IBuffer iv = null; // no IV used in ECB.
|
||||
IBuffer buffMsg = CryptographicBuffer.CreateFromByteArray(pbTestData);
|
||||
IBuffer keyMaterial = CryptographicBuffer.CreateFromByteArray(pbTestKey);
|
||||
SymmetricKeyAlgorithmProvider objAlg = SymmetricKeyAlgorithmProvider.OpenAlgorithm(strAlgName);
|
||||
CryptographicKey key = objAlg.CreateSymmetricKey(keyMaterial);
|
||||
|
||||
// Encrypt the data and return.
|
||||
IBuffer buffEncrypt = CryptographicEngine.Encrypt(key, buffMsg, iv);
|
||||
CryptographicBuffer.CopyToByteArray(buffEncrypt, out pbTestData);
|
||||
|
||||
if (!MemUtil.ArraysEqual(pbTestData, pbReferenceCT))
|
||||
throw new SecurityException(KLRes.EncAlgorithmAes + ".");
|
||||
|
||||
|
||||
#if false
|
||||
|
||||
RijndaelManaged r = new RijndaelManaged();
|
||||
|
||||
if(r.BlockSize != 128) // AES block size
|
||||
@@ -142,7 +131,6 @@ namespace ModernKeePassLib.Cryptography
|
||||
|
||||
if(!MemUtil.ArraysEqual(pbTestData, pbReferenceCT))
|
||||
throw new SecurityException(KLRes.EncAlgorithmAes + ".");
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -166,7 +154,7 @@ namespace ModernKeePassLib.Cryptography
|
||||
Salsa20Cipher c = new Salsa20Cipher(pbKey, pbIV);
|
||||
c.Encrypt(pb, pb.Length, false);
|
||||
if(!MemUtil.ArraysEqual(pb, pbExpected))
|
||||
throw new SecurityException("Salsa20.");
|
||||
throw new SecurityException("Salsa20-1");
|
||||
|
||||
#if DEBUG
|
||||
// Extended test in debug mode
|
||||
@@ -183,13 +171,24 @@ namespace ModernKeePassLib.Cryptography
|
||||
int nPos = Salsa20ToPos(c, r, pb.Length, 65536);
|
||||
c.Encrypt(pb, pb.Length, false);
|
||||
if(!MemUtil.ArraysEqual(pb, pbExpected2))
|
||||
throw new SecurityException("Salsa20-2.");
|
||||
throw new SecurityException("Salsa20-2");
|
||||
|
||||
nPos = Salsa20ToPos(c, r, nPos + pb.Length, 131008);
|
||||
Array.Clear(pb, 0, pb.Length);
|
||||
c.Encrypt(pb, pb.Length, true);
|
||||
if(!MemUtil.ArraysEqual(pb, pbExpected3))
|
||||
throw new SecurityException("Salsa20-3.");
|
||||
throw new SecurityException("Salsa20-3");
|
||||
|
||||
Dictionary<string, bool> d = new Dictionary<string, bool>();
|
||||
const int nRounds = 100;
|
||||
for(int i = 0; i < nRounds; ++i)
|
||||
{
|
||||
byte[] z = new byte[32];
|
||||
c = new Salsa20Cipher(z, BitConverter.GetBytes((long)i));
|
||||
c.Encrypt(z, z.Length, true);
|
||||
d[MemUtil.ByteArrayToHexString(z)] = true;
|
||||
}
|
||||
if(d.Count != nRounds) throw new SecurityException("Salsa20-4");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -211,9 +210,10 @@ namespace ModernKeePassLib.Cryptography
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !PCL
|
||||
private static void TestNativeKeyTransform()
|
||||
{
|
||||
#if DEBUG && TODO
|
||||
#if DEBUG
|
||||
byte[] pbOrgKey = CryptoRandom.Instance.GetRandomBytes(32);
|
||||
byte[] pbSeed = CryptoRandom.Instance.GetRandomBytes(32);
|
||||
ulong uRounds = (ulong)((new Random()).Next(1, 0x3FFF));
|
||||
@@ -232,11 +232,12 @@ namespace ModernKeePassLib.Cryptography
|
||||
throw new SecurityException("Native transform.");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
private static void TestMemUtil()
|
||||
{
|
||||
#if DEBUG && !KeePassWinRT
|
||||
Random r = new Random();
|
||||
{
|
||||
#if DEBUG
|
||||
Random r = new Random();
|
||||
byte[] pb = CryptoRandom.Instance.GetRandomBytes((uint)r.Next(
|
||||
0, 0x2FFFF));
|
||||
|
||||
@@ -244,35 +245,64 @@ namespace ModernKeePassLib.Cryptography
|
||||
if(!MemUtil.ArraysEqual(MemUtil.Decompress(pbCompressed), pb))
|
||||
throw new InvalidOperationException("GZip");
|
||||
|
||||
pb = Encoding.ASCII.GetBytes("012345678901234567890a");
|
||||
byte[] pbN = Encoding.ASCII.GetBytes("9012");
|
||||
Encoding enc = StrUtil.Utf8;
|
||||
pb = enc.GetBytes("012345678901234567890a");
|
||||
byte[] pbN = enc.GetBytes("9012");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 9)
|
||||
throw new InvalidOperationException("MemUtil-1");
|
||||
pbN = Encoding.ASCII.GetBytes("01234567890123");
|
||||
pbN = enc.GetBytes("01234567890123");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 0)
|
||||
throw new InvalidOperationException("MemUtil-2");
|
||||
pbN = Encoding.ASCII.GetBytes("a");
|
||||
pbN = enc.GetBytes("a");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 21)
|
||||
throw new InvalidOperationException("MemUtil-3");
|
||||
pbN = Encoding.ASCII.GetBytes("0a");
|
||||
pbN = enc.GetBytes("0a");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 20)
|
||||
throw new InvalidOperationException("MemUtil-4");
|
||||
pbN = Encoding.ASCII.GetBytes("1");
|
||||
pbN = enc.GetBytes("1");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) != 1)
|
||||
throw new InvalidOperationException("MemUtil-5");
|
||||
pbN = Encoding.ASCII.GetBytes("b");
|
||||
pbN = enc.GetBytes("b");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) >= 0)
|
||||
throw new InvalidOperationException("MemUtil-6");
|
||||
pbN = Encoding.ASCII.GetBytes("012b");
|
||||
pbN = enc.GetBytes("012b");
|
||||
if(MemUtil.IndexOf<byte>(pb, pbN) >= 0)
|
||||
throw new InvalidOperationException("MemUtil-7");
|
||||
|
||||
byte[] pbRes = MemUtil.ParseBase32("MY======");
|
||||
byte[] pbExp = Encoding.UTF8.GetBytes("f");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-1");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXQ====");
|
||||
pbExp = Encoding.UTF8.GetBytes("fo");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-2");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6===");
|
||||
pbExp = Encoding.UTF8.GetBytes("foo");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-3");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YQ=");
|
||||
pbExp = Encoding.UTF8.GetBytes("foob");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-4");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YTB");
|
||||
pbExp = Encoding.UTF8.GetBytes("fooba");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-5");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("MZXW6YTBOI======");
|
||||
pbExp = Encoding.UTF8.GetBytes("foobar");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-6");
|
||||
|
||||
pbRes = MemUtil.ParseBase32("JNSXSIDQOJXXM2LEMVZCAYTBONSWIIDPNYQG63TFFV2GS3LFEBYGC43TO5XXEZDTFY======");
|
||||
pbExp = Encoding.UTF8.GetBytes("Key provider based on one-time passwords.");
|
||||
if(!MemUtil.ArraysEqual(pbRes, pbExp)) throw new Exception("Base32-7");
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void TestHmacOtp()
|
||||
{
|
||||
#if (DEBUG && !KeePassLibSD && TODO)
|
||||
byte[] pbSecret = Encoding.ASCII.GetBytes("12345678901234567890");
|
||||
#if (DEBUG && !KeePassLibSD && !KeePassRT)
|
||||
byte[] pbSecret = StrUtil.Utf8.GetBytes("12345678901234567890");
|
||||
string[] vExp = new string[]{ "755224", "287082", "359152",
|
||||
"969429", "338314", "254676", "287922", "162583", "399871",
|
||||
"520489" };
|
||||
@@ -287,10 +317,10 @@ namespace ModernKeePassLib.Cryptography
|
||||
|
||||
private static void TestProtectedObjects()
|
||||
{
|
||||
|
||||
#if TODO
|
||||
#if DEBUG
|
||||
byte[] pbData = Encoding.UTF8.GetBytes("Test Test Test Test");
|
||||
Encoding enc = StrUtil.Utf8;
|
||||
|
||||
byte[] pbData = enc.GetBytes("Test Test Test Test");
|
||||
ProtectedBinary pb = new ProtectedBinary(true, pbData);
|
||||
if(!pb.IsProtected) throw new SecurityException("ProtectedBinary-1");
|
||||
|
||||
@@ -299,8 +329,8 @@ namespace ModernKeePassLib.Cryptography
|
||||
throw new SecurityException("ProtectedBinary-2");
|
||||
if(!pb.IsProtected) throw new SecurityException("ProtectedBinary-3");
|
||||
|
||||
byte[] pbData2 = Encoding.UTF8.GetBytes("Test Test Test Test");
|
||||
byte[] pbData3 = Encoding.UTF8.GetBytes("Test Test Test Test Test");
|
||||
byte[] pbData2 = enc.GetBytes("Test Test Test Test");
|
||||
byte[] pbData3 = enc.GetBytes("Test Test Test Test Test");
|
||||
ProtectedBinary pb2 = new ProtectedBinary(true, pbData2);
|
||||
ProtectedBinary pb3 = new ProtectedBinary(true, pbData3);
|
||||
if(!pb.Equals(pb2)) throw new SecurityException("ProtectedBinary-4");
|
||||
@@ -323,8 +353,7 @@ namespace ModernKeePassLib.Cryptography
|
||||
throw new SecurityException("ProtectedString-3");
|
||||
|
||||
ps = new ProtectedString(true, "Test");
|
||||
ProtectedString ps2 = new ProtectedString(true,
|
||||
StrUtil.Utf8.GetBytes("Test"));
|
||||
ProtectedString ps2 = new ProtectedString(true, enc.GetBytes("Test"));
|
||||
if(ps.IsEmpty) throw new SecurityException("ProtectedString-4");
|
||||
pbData = ps.ReadUtf8();
|
||||
pbData2 = ps2.ReadUtf8();
|
||||
@@ -340,7 +369,41 @@ namespace ModernKeePassLib.Cryptography
|
||||
throw new SecurityException("ProtectedString-8");
|
||||
if(!ps.IsProtected) throw new SecurityException("ProtectedString-9");
|
||||
if(!ps2.IsProtected) throw new SecurityException("ProtectedString-10");
|
||||
#endif
|
||||
|
||||
Random r = new Random();
|
||||
string str = string.Empty;
|
||||
ps = new ProtectedString();
|
||||
for(int i = 0; i < 100; ++i)
|
||||
{
|
||||
bool bProt = ((r.Next() % 4) != 0);
|
||||
ps = ps.WithProtection(bProt);
|
||||
|
||||
int x = r.Next(str.Length + 1);
|
||||
int c = r.Next(20);
|
||||
char ch = (char)r.Next(1, 256);
|
||||
|
||||
string strIns = new string(ch, c);
|
||||
str = str.Insert(x, strIns);
|
||||
ps = ps.Insert(x, strIns);
|
||||
|
||||
if(ps.IsProtected != bProt)
|
||||
throw new SecurityException("ProtectedString-11");
|
||||
if(ps.ReadString() != str)
|
||||
throw new SecurityException("ProtectedString-12");
|
||||
|
||||
ps = ps.WithProtection(bProt);
|
||||
|
||||
x = r.Next(str.Length);
|
||||
c = r.Next(str.Length - x + 1);
|
||||
|
||||
str = str.Remove(x, c);
|
||||
ps = ps.Remove(x, c);
|
||||
|
||||
if(ps.IsProtected != bProt)
|
||||
throw new SecurityException("ProtectedString-13");
|
||||
if(ps.ReadString() != str)
|
||||
throw new SecurityException("ProtectedString-14");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -381,16 +444,64 @@ namespace ModernKeePassLib.Cryptography
|
||||
throw new InvalidOperationException("StrUtil-V3");
|
||||
if(StrUtil.VersionToString(0x00FF000000000000UL) != "255")
|
||||
throw new InvalidOperationException("StrUtil-V4");
|
||||
if(StrUtil.VersionToString(0x00FF000000000000UL, true) != "255.0")
|
||||
if(StrUtil.VersionToString(0x00FF000000000000UL, 2) != "255.0")
|
||||
throw new InvalidOperationException("StrUtil-V5");
|
||||
if(StrUtil.VersionToString(0x0000000000070000UL, true) != "0.0.7")
|
||||
if(StrUtil.VersionToString(0x0000000000070000UL) != "0.0.7")
|
||||
throw new InvalidOperationException("StrUtil-V6");
|
||||
if(StrUtil.VersionToString(0x0000000000000000UL) != "0")
|
||||
throw new InvalidOperationException("StrUtil-V7");
|
||||
if(StrUtil.VersionToString(0x00000000FFFF0000UL, 4) != "0.0.65535.0")
|
||||
throw new InvalidOperationException("StrUtil-V8");
|
||||
if(StrUtil.VersionToString(0x0000000000000000UL, 4) != "0.0.0.0")
|
||||
throw new InvalidOperationException("StrUtil-V9");
|
||||
|
||||
if(StrUtil.RtfEncodeChar('\u0000') != "\\u0?")
|
||||
throw new InvalidOperationException("StrUtil-Rtf1");
|
||||
if(StrUtil.RtfEncodeChar('\u7FFF') != "\\u32767?")
|
||||
throw new InvalidOperationException("StrUtil-Rtf2");
|
||||
if(StrUtil.RtfEncodeChar('\u8000') != "\\u-32768?")
|
||||
throw new InvalidOperationException("StrUtil-Rtf3");
|
||||
if(StrUtil.RtfEncodeChar('\uFFFF') != "\\u-1?")
|
||||
throw new InvalidOperationException("StrUtil-Rtf4");
|
||||
|
||||
if(!StrUtil.StringToBool(Boolean.TrueString))
|
||||
throw new InvalidOperationException("StrUtil-Bool1");
|
||||
if(StrUtil.StringToBool(Boolean.FalseString))
|
||||
throw new InvalidOperationException("StrUtil-Bool2");
|
||||
|
||||
if(StrUtil.Count("Abracadabra", "a") != 4)
|
||||
throw new InvalidOperationException("StrUtil-Count1");
|
||||
if(StrUtil.Count("Bla", "U") != 0)
|
||||
throw new InvalidOperationException("StrUtil-Count2");
|
||||
if(StrUtil.Count("AAAAA", "AA") != 4)
|
||||
throw new InvalidOperationException("StrUtil-Count3");
|
||||
|
||||
const string sU = "data:mytype;base64,";
|
||||
if(!StrUtil.IsDataUri(sU))
|
||||
throw new InvalidOperationException("StrUtil-DataUri1");
|
||||
if(!StrUtil.IsDataUri(sU, "mytype"))
|
||||
throw new InvalidOperationException("StrUtil-DataUri2");
|
||||
if(StrUtil.IsDataUri(sU, "notmytype"))
|
||||
throw new InvalidOperationException("StrUtil-DataUri3");
|
||||
|
||||
uint u = 0x7FFFFFFFU;
|
||||
if(u.ToString(NumberFormatInfo.InvariantInfo) != "2147483647")
|
||||
throw new InvalidOperationException("StrUtil-Inv1");
|
||||
if(uint.MaxValue.ToString(NumberFormatInfo.InvariantInfo) !=
|
||||
"4294967295")
|
||||
throw new InvalidOperationException("StrUtil-Inv2");
|
||||
if(long.MinValue.ToString(NumberFormatInfo.InvariantInfo) !=
|
||||
"-9223372036854775808")
|
||||
throw new InvalidOperationException("StrUtil-Inv3");
|
||||
if(short.MinValue.ToString(NumberFormatInfo.InvariantInfo) !=
|
||||
"-32768")
|
||||
throw new InvalidOperationException("StrUtil-Inv4");
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void TestUrlUtil()
|
||||
{
|
||||
#if DEBUG && TODO
|
||||
#if DEBUG
|
||||
if(UrlUtil.GetHost(@"scheme://domain:port/path?query_string#fragment_id") !=
|
||||
"domain")
|
||||
throw new InvalidOperationException("UrlUtil-H1");
|
||||
@@ -408,7 +519,7 @@ namespace ModernKeePassLib.Cryptography
|
||||
if(UrlUtil.GetHost(@"s://u:p@d.tld:p/p?q#f") != "d.tld")
|
||||
throw new InvalidOperationException("UrlUtil-H7");
|
||||
|
||||
if(NativeLib.IsUnix()) return;
|
||||
//if(NativeLib.IsUnix()) return;
|
||||
|
||||
string strBase = "\\\\HOMESERVER\\Apps\\KeePass\\KeePass.exe";
|
||||
string strDoc = "\\\\HOMESERVER\\Documents\\KeePass\\NewDatabase.kdbx";
|
||||
@@ -419,6 +530,13 @@ namespace ModernKeePassLib.Cryptography
|
||||
|
||||
str = UrlUtil.MakeAbsolutePath(strBase, strRel);
|
||||
if(!str.Equals(strDoc)) throw new InvalidOperationException("UrlUtil-R2");
|
||||
|
||||
str = UrlUtil.GetQuotedAppPath(" \"Test\" \"%1\" ");
|
||||
if(str != "Test") throw new InvalidOperationException("UrlUtil-Q1");
|
||||
str = UrlUtil.GetQuotedAppPath("C:\\Program Files\\Test.exe");
|
||||
if(str != "C:\\Program Files\\Test.exe") throw new InvalidOperationException("UrlUtil-Q2");
|
||||
str = UrlUtil.GetQuotedAppPath("Reg.exe \"Test\" \"Test 2\"");
|
||||
if(str != "Reg.exe \"Test\" \"Test 2\"") throw new InvalidOperationException("UrlUtil-Q3");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user