mirror of
https://github.com/bitwarden/mobile.git
synced 2024-12-18 15:37:42 +01:00
hash phrase fixes
This commit is contained in:
parent
67e458833f
commit
d4ed276684
@ -7,6 +7,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
namespace Bit.Core.Services
|
namespace Bit.Core.Services
|
||||||
{
|
{
|
||||||
@ -790,10 +791,8 @@ namespace Bit.Core.Services
|
|||||||
|
|
||||||
private List<string> HashPhrase(byte[] hash, int minimumEntropy = 64)
|
private List<string> HashPhrase(byte[] hash, int minimumEntropy = 64)
|
||||||
{
|
{
|
||||||
// TODO: word list
|
var wordLength = Utilities.WordList.EEFLongWordList.Count;
|
||||||
var EEFLongWordList = new string[] { };
|
var entropyPerWord = Math.Log(wordLength) / Math.Log(2);
|
||||||
|
|
||||||
var entropyPerWord = Math.Log(EEFLongWordList.Length) / Math.Log(2);
|
|
||||||
var numWords = (int)Math.Ceiling(minimumEntropy / entropyPerWord);
|
var numWords = (int)Math.Ceiling(minimumEntropy / entropyPerWord);
|
||||||
|
|
||||||
var entropyAvailable = hash.Length * 4;
|
var entropyAvailable = hash.Length * 4;
|
||||||
@ -803,13 +802,13 @@ namespace Bit.Core.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
var phrase = new List<string>();
|
var phrase = new List<string>();
|
||||||
// TODO: big int from array
|
var hashHex = string.Concat("0", BitConverter.ToString(hash).Replace("-", ""));
|
||||||
var hashNumber = 123; // bigInt.fromArray(hash, 256);
|
var hashNumber = BigInteger.Parse(hashHex, System.Globalization.NumberStyles.HexNumber);
|
||||||
while(numWords-- > 0)
|
while(numWords-- > 0)
|
||||||
{
|
{
|
||||||
// var remainder = hashNumber.mod(EEFLongWordList.Length);
|
var remainder = (int)(hashNumber % wordLength);
|
||||||
// hashNumber = hashNumber.divide(EEFLongWordList.Length);
|
hashNumber = hashNumber / wordLength;
|
||||||
// phrase.Add(EEFLongWordList[remainder]);
|
phrase.Add(Utilities.WordList.EEFLongWordList[remainder]);
|
||||||
}
|
}
|
||||||
return phrase;
|
return phrase;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user