mirror of
https://github.com/bitwarden/android.git
synced 2024-12-25 18:38:27 +03:00
load EEFLongWordList from file
This commit is contained in:
parent
0bbb549533
commit
25d02cec25
6 changed files with 7837 additions and 6 deletions
|
@ -117,9 +117,9 @@ namespace Bit.App
|
||||||
System.Diagnostics.Debug.WriteLine("XF App: OnStart");
|
System.Diagnostics.Debug.WriteLine("XF App: OnStart");
|
||||||
await ClearCacheIfNeededAsync();
|
await ClearCacheIfNeededAsync();
|
||||||
// Prime the word list
|
// Prime the word list
|
||||||
var workTask = Task.Run(() =>
|
var wordTask = Task.Run(() =>
|
||||||
{
|
{
|
||||||
var word = WordList.EEFLongWordList[1];
|
// var word = WordList.EEFLongWordList[1];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,12 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Remove="Resources\eff_long_word_list.txt" />
|
||||||
<None Remove="Resources\public_suffix_list.dat" />
|
<None Remove="Resources\public_suffix_list.dat" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="Resources\eff_long_word_list.txt" />
|
||||||
<EmbeddedResource Include="Resources\public_suffix_list.dat" />
|
<EmbeddedResource Include="Resources\public_suffix_list.dat" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
7776
src/Core/Resources/eff_long_word_list.txt
Normal file
7776
src/Core/Resources/eff_long_word_list.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -8,6 +8,7 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using Bit.Core.Utilities;
|
||||||
|
|
||||||
namespace Bit.Core.Services
|
namespace Bit.Core.Services
|
||||||
{
|
{
|
||||||
|
@ -793,7 +794,7 @@ namespace Bit.Core.Services
|
||||||
|
|
||||||
private List<string> HashPhrase(byte[] hash, int minimumEntropy = 64)
|
private List<string> HashPhrase(byte[] hash, int minimumEntropy = 64)
|
||||||
{
|
{
|
||||||
var wordLength = Utilities.WordList.EEFLongWordList.Count;
|
var wordLength = EEFLongWordList.Instance.List.Count;
|
||||||
var entropyPerWord = Math.Log(wordLength) / Math.Log(2);
|
var entropyPerWord = Math.Log(wordLength) / Math.Log(2);
|
||||||
var numWords = (int)Math.Ceiling(minimumEntropy / entropyPerWord);
|
var numWords = (int)Math.Ceiling(minimumEntropy / entropyPerWord);
|
||||||
|
|
||||||
|
@ -810,7 +811,7 @@ namespace Bit.Core.Services
|
||||||
{
|
{
|
||||||
var remainder = (int)(hashNumber % wordLength);
|
var remainder = (int)(hashNumber % wordLength);
|
||||||
hashNumber = hashNumber / wordLength;
|
hashNumber = hashNumber / wordLength;
|
||||||
phrase.Add(Utilities.WordList.EEFLongWordList[remainder]);
|
phrase.Add(EEFLongWordList.Instance.List[remainder]);
|
||||||
}
|
}
|
||||||
return phrase;
|
return phrase;
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,12 +191,12 @@ namespace Bit.Core.Services
|
||||||
{
|
{
|
||||||
options.WordSeparator = " ";
|
options.WordSeparator = " ";
|
||||||
}
|
}
|
||||||
var listLength = WordList.EEFLongWordList.Count - 1;
|
var listLength = EEFLongWordList.Instance.List.Count - 1;
|
||||||
var wordList = new List<string>();
|
var wordList = new List<string>();
|
||||||
for(int i = 0; i < options.NumWords.GetValueOrDefault(); i++)
|
for(int i = 0; i < options.NumWords.GetValueOrDefault(); i++)
|
||||||
{
|
{
|
||||||
var wordIndex = await _cryptoService.RandomNumberAsync(0, listLength);
|
var wordIndex = await _cryptoService.RandomNumberAsync(0, listLength);
|
||||||
wordList.Add(WordList.EEFLongWordList[wordIndex]);
|
wordList.Add(EEFLongWordList.Instance.List[wordIndex]);
|
||||||
}
|
}
|
||||||
return string.Join(options.WordSeparator, wordList);
|
return string.Join(options.WordSeparator, wordList);
|
||||||
}
|
}
|
||||||
|
|
52
src/Core/Utilities/EEFLongWordList.cs
Normal file
52
src/Core/Utilities/EEFLongWordList.cs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Bit.Core.Utilities
|
||||||
|
{
|
||||||
|
public class EEFLongWordList
|
||||||
|
{
|
||||||
|
private static volatile EEFLongWordList _uniqueInstance;
|
||||||
|
private static object _syncObj = new object();
|
||||||
|
|
||||||
|
private EEFLongWordList()
|
||||||
|
{
|
||||||
|
List = ReadData().ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EEFLongWordList Instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if(_uniqueInstance == null)
|
||||||
|
{
|
||||||
|
lock(_syncObj)
|
||||||
|
{
|
||||||
|
if(_uniqueInstance == null)
|
||||||
|
{
|
||||||
|
_uniqueInstance = new EEFLongWordList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (_uniqueInstance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<string> List { get; set; }
|
||||||
|
|
||||||
|
private IEnumerable<string> ReadData()
|
||||||
|
{
|
||||||
|
var assembly = typeof(EEFLongWordList).GetTypeInfo().Assembly;
|
||||||
|
var stream = assembly.GetManifestResourceStream("Bit.Core.Resources.eff_long_word_list.txt");
|
||||||
|
string line;
|
||||||
|
using(var reader = new StreamReader(stream))
|
||||||
|
{
|
||||||
|
while((line = reader.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
yield return line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue