mirror of
https://github.com/gchq/CyberChef.git
synced 2025-06-15 18:54:56 -04:00
Updated SeedToMPK to not require seed length.
This commit is contained in:
parent
2233127f43
commit
a060ec446e
2 changed files with 49 additions and 5 deletions
|
@ -48,16 +48,17 @@ class SeedToMPK extends Operation {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
input = input.trim();
|
input = input.trim();
|
||||||
|
|
||||||
|
|
||||||
// We check to see if the input is hex or not.
|
// We check to see if the input is hex or not.
|
||||||
// If it is not, we convert it back to hex
|
// If it is not, we convert it back to hex
|
||||||
const re = /[0-9A-Fa-f]{2,}/g;
|
const re = /^[0-9A-Fa-f]{2,}$/g;
|
||||||
if (!(input.length === 128 && re.test(input)) && !(input.length === 64)) {
|
const isHex = re.test(input) && input.length %2 === 0;
|
||||||
return "Must pass a hex string of length 128, or a byte string of length 64. Got length: " + input.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Create the hmac.
|
||||||
const hmac = forge.hmac.create();
|
const hmac = forge.hmac.create();
|
||||||
hmac.start("sha512", Utils.convertToByteString("Bitcoin seed", "UTF8"));
|
hmac.start("sha512", Utils.convertToByteString("Bitcoin seed", "UTF8"));
|
||||||
if (input.length === 128) {
|
if (isHex) {
|
||||||
hmac.update(Utils.convertToByteString(input, "hex"));
|
hmac.update(Utils.convertToByteString(input, "hex"));
|
||||||
} else {
|
} else {
|
||||||
hmac.update(input);
|
hmac.update(input);
|
||||||
|
|
|
@ -57,6 +57,49 @@ TestRegister.addTests([
|
||||||
"args": ["Ltpv"]
|
"args": ["Ltpv"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Seed To Master Private Key (XPrv, short seed)",
|
||||||
|
input: "1ed5b6f0dcf88085add90fbb138d5e16f661d5b738f842232fce5980fc4592",
|
||||||
|
expectedOutput: "xprv9s21ZrQH143K3mvkwf3aiiCQ6mpTnAh5ZPvhHFLXSaSRxAg5uAuHVvaFVSGoyE7U3UJ3knZM12AvNcF9a9xoARWCkCF9MYXjyN1ZJUC6ssa",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "Seed To Master Key",
|
||||||
|
"args": ["xprv"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Seed to Master Private Key (XPrv, decoded Chinese)",
|
||||||
|
input: "霍 里 攻 繁 混 注 杀 侦 具 涤 涤 手",
|
||||||
|
expectedOutput: "xprv9s21ZrQH143K3NGAQKJovUKk9ty8HFDxoK2A8kseKUEQnQA2xuS1UiXj67d7jPS153aBSeqbJpGC4etDSmAJrD2MuN3pncdjFNh85PEPwS2",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "Normalise Unicode",
|
||||||
|
"args": ["NFKD"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"op": "To Hex",
|
||||||
|
"args": ["None", 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"op": "Seed To Master Key",
|
||||||
|
"args": ["xprv"]
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Seed to Master Private Key (XPrv, Non-Hex Dealing With Raw Bytes)",
|
||||||
|
input: "abc=_*~$%^$^*&^$%@#$^^%&*^&(YIU%^$#@",
|
||||||
|
expectedOutput: "xprv9s21ZrQH143K2zVX3HhaQJZPeunqrxitrCQh5ZaUzyv9uHtZu86AVigehGy2ZCfGcAmp7wJUSb4GMGsbH8qqJawZEz2mdUVV8q7VH2AqgH6",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "Seed To Master Key",
|
||||||
|
"args": ["xprv"]
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue