SHA256
ESP32: новая derivation ключей
This commit is contained in:
+24
-10
@@ -392,6 +392,8 @@ struct DerivedKeyInfo {
|
||||
|
||||
static String gRootPubB58;
|
||||
static String gRootPrivB58;
|
||||
static String gRecoveryPubB58;
|
||||
static String gRecoveryPrivB58;
|
||||
static String gBlockchainPubB58;
|
||||
static String gBlockchainPrivB58;
|
||||
static String gDevicePubB58;
|
||||
@@ -1206,10 +1208,17 @@ static void deriveKeyPairFromSecretSuffix(const uint8_t *secret32, const String
|
||||
if (!secret32) {
|
||||
return;
|
||||
}
|
||||
String material = base64Std(secret32, 32) + "|" + suffix;
|
||||
const char *prefix = "SHiNE-key";
|
||||
uint8_t seed[32] = {};
|
||||
uint8_t pub[32] = {};
|
||||
sha256calc(reinterpret_cast<const uint8_t *>(material.c_str()), material.length(), seed);
|
||||
std::vector<uint8_t> material;
|
||||
material.reserve(10 + 1 + 32 + 1 + suffix.length());
|
||||
material.insert(material.end(), prefix, prefix + strlen(prefix));
|
||||
material.push_back(0);
|
||||
material.insert(material.end(), secret32, secret32 + 32);
|
||||
material.push_back(0);
|
||||
material.insert(material.end(), suffix.c_str(), suffix.c_str() + suffix.length());
|
||||
sha256calc(material.data(), material.size(), seed);
|
||||
Ed25519::derivePublicKey(pub, seed);
|
||||
privB58 = base58From32(seed);
|
||||
pubB58 = base58From32(pub);
|
||||
@@ -1218,6 +1227,8 @@ static void deriveKeyPairFromSecretSuffix(const uint8_t *secret32, const String
|
||||
static void clearDerivedKeys() {
|
||||
gRootPubB58 = "";
|
||||
gRootPrivB58 = "";
|
||||
gRecoveryPubB58 = "";
|
||||
gRecoveryPrivB58 = "";
|
||||
gBlockchainPubB58 = "";
|
||||
gBlockchainPrivB58 = "";
|
||||
gDevicePubB58 = "";
|
||||
@@ -1233,6 +1244,7 @@ static void refreshDerivedKeys() {
|
||||
if (!gSecretConfigured) {
|
||||
return;
|
||||
}
|
||||
deriveKeyPairFromSecretSuffix(gSecretBytes, "recovery.key", gRecoveryPubB58, gRecoveryPrivB58);
|
||||
deriveKeyPairFromSecretSuffix(gSecretBytes, "root.key", gRootPubB58, gRootPrivB58);
|
||||
deriveKeyPairFromSecretSuffix(gSecretBytes, "blockchain.key", gBlockchainPubB58, gBlockchainPrivB58);
|
||||
deriveKeyPairFromSecretSuffix(gSecretBytes, "client.key", gDevicePubB58, gDevicePrivB58);
|
||||
@@ -6297,14 +6309,16 @@ static void drawSecretShowScreen() {
|
||||
};
|
||||
|
||||
addKeyBlock("Secret (base58)", "master secret", gSecretBase58);
|
||||
addKeyBlock("Root key (base58)", "pub from sha256(base64(secret)|root.key)", gRootPubB58);
|
||||
addKeyBlock("Root key priv (base58)", "sha256(base64(secret)|root.key)", gRootPrivB58);
|
||||
addKeyBlock("Blockchain key (base58)", "pub from sha256(base64(secret)|bch.key)", gBlockchainPubB58);
|
||||
addKeyBlock("Blockchain key priv (base58)", "sha256(base64(secret)|bch.key)", gBlockchainPrivB58);
|
||||
addKeyBlock("Client key (base58)", "pub from sha256(base64(secret)|client.key)", gDevicePubB58);
|
||||
addKeyBlock("Client key priv (base58)", "sha256(base64(secret)|client.key)", gDevicePrivB58);
|
||||
addKeyBlock("Homeserver key (base58)", String("pub from sha256(base64(secret)|") + homeserverKeySuffix() + ")", gHomeserverPubB58);
|
||||
addKeyBlock("Homeserver key priv (base58)", String("sha256(base64(secret)|") + homeserverKeySuffix() + ")", gHomeserverPrivB58);
|
||||
addKeyBlock("Recovery key (base58)", "pub from SHA-256(SHiNE-key||secret||recovery.key)", gRecoveryPubB58);
|
||||
addKeyBlock("Recovery key priv (base58)", "SHA-256(SHiNE-key||secret||recovery.key)", gRecoveryPrivB58);
|
||||
addKeyBlock("Root key (base58)", "pub from SHA-256(SHiNE-key||secret||root.key)", gRootPubB58);
|
||||
addKeyBlock("Root key priv (base58)", "SHA-256(SHiNE-key||secret||root.key)", gRootPrivB58);
|
||||
addKeyBlock("Blockchain key (base58)", "pub from SHA-256(SHiNE-key||secret||blockchain.key)", gBlockchainPubB58);
|
||||
addKeyBlock("Blockchain key priv (base58)", "SHA-256(SHiNE-key||secret||blockchain.key)", gBlockchainPrivB58);
|
||||
addKeyBlock("Client key (base58)", "pub from SHA-256(SHiNE-key||secret||client.key)", gDevicePubB58);
|
||||
addKeyBlock("Client key priv (base58)", "SHA-256(SHiNE-key||secret||client.key)", gDevicePrivB58);
|
||||
addKeyBlock("Homeserver key (base58)", String("pub from SHA-256(SHiNE-key||secret||") + homeserverKeySuffix() + ")", gHomeserverPubB58);
|
||||
addKeyBlock("Homeserver key priv (base58)", String("SHA-256(SHiNE-key||secret||") + homeserverKeySuffix() + ")", gHomeserverPrivB58);
|
||||
} else {
|
||||
showMessageAt("Secret not set", 96);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user