Support for native key transformation based on the method of Keepassdroid (performance improvement)
This commit is contained in:
@@ -149,4 +149,10 @@
|
||||
<AndroidResource Include="Resources\values\Strings.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\kp2akeytransform\kp2akeytransform.csproj">
|
||||
<Project>{A57B3ACE-5634-469A-88C4-858BB409F356}</Project>
|
||||
<Name>kp2akeytransform</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -246,22 +246,35 @@ namespace KeePassLib.Keys
|
||||
ulong uNumRounds)
|
||||
{
|
||||
Debug.Assert((pbOriginalKey32 != null) && (pbOriginalKey32.Length == 32));
|
||||
if(pbOriginalKey32 == null) throw new ArgumentNullException("pbOriginalKey32");
|
||||
if(pbOriginalKey32.Length != 32) throw new ArgumentException();
|
||||
if (pbOriginalKey32 == null)
|
||||
throw new ArgumentNullException("pbOriginalKey32");
|
||||
if (pbOriginalKey32.Length != 32)
|
||||
throw new ArgumentException();
|
||||
|
||||
Debug.Assert((pbKeySeed32 != null) && (pbKeySeed32.Length == 32));
|
||||
if(pbKeySeed32 == null) throw new ArgumentNullException("pbKeySeed32");
|
||||
if(pbKeySeed32.Length != 32) throw new ArgumentException();
|
||||
if (pbKeySeed32 == null)
|
||||
throw new ArgumentNullException("pbKeySeed32");
|
||||
if (pbKeySeed32.Length != 32)
|
||||
throw new ArgumentException();
|
||||
|
||||
byte[] pbNewKey = new byte[32];
|
||||
Array.Copy(pbOriginalKey32, pbNewKey, pbNewKey.Length);
|
||||
|
||||
// Try to use the native library first
|
||||
if(NativeLib.TransformKey256(pbNewKey, pbKeySeed32, uNumRounds))
|
||||
return (new SHA256Managed()).ComputeHash(pbNewKey);
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
if (NativeLib.TransformKey256(pbNewKey, pbKeySeed32, uNumRounds))
|
||||
{
|
||||
sw.Stop();
|
||||
Android.Util.Log.Debug("DEBUG", "Native transform:" +sw.ElapsedMilliseconds+"ms");
|
||||
return pbNewKey;
|
||||
}
|
||||
|
||||
sw.Restart();
|
||||
if(TransformKeyManaged(pbNewKey, pbKeySeed32, uNumRounds) == false)
|
||||
return null;
|
||||
sw.Stop();
|
||||
Android.Util.Log.Debug("DEBUG", "Managed transform:" +sw.ElapsedMilliseconds+"ms");
|
||||
|
||||
SHA256Managed sha256 = new SHA256Managed();
|
||||
return sha256.ComputeHash(pbNewKey);
|
||||
|
||||
@@ -162,19 +162,20 @@ namespace KeePassLib.Native
|
||||
{
|
||||
if(m_bAllowNative == false) return false;
|
||||
|
||||
KeyValuePair<IntPtr, IntPtr> kvp = PrepareArrays256(pBuf256, pKey256);
|
||||
bool bResult = false;
|
||||
|
||||
try
|
||||
{
|
||||
bResult = NativeMethods.TransformKey(kvp.Key, kvp.Value, uRounds);
|
||||
//Android.Util.Log.Debug("DEBUG", "4+1"+new Kp2atest.TestClass().Add1(4));
|
||||
Com.Keepassdroid.Crypto.Finalkey.NativeFinalKey key = new Com.Keepassdroid.Crypto.Finalkey.NativeFinalKey();
|
||||
|
||||
byte[] newKey = key.TransformMasterKey(pKey256, pBuf256, (int)uRounds);
|
||||
Array.Copy(newKey, pBuf256, newKey.Length);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch(Exception) { bResult = false; }
|
||||
|
||||
if(bResult) GetBuffers256(kvp, pBuf256, pKey256);
|
||||
|
||||
NativeLib.FreeArrays(kvp);
|
||||
return bResult;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user