with all security checks in place, the code is now accepting protocol_tx outputs as valid in-wallet; only the asset_type is misreported now

This commit is contained in:
Some Random Crypto Guy
2023-11-27 23:06:35 +00:00
parent be8e0f7327
commit ccdbfbe397
16 changed files with 586 additions and 842 deletions
+61
View File
@@ -261,6 +261,67 @@ namespace crypto {
return true;
}
/**
* The following functions are designed to perform the correct encoding / decoding for protocol_tx outputs,
* which use a hash of a crypto::key_image for uniqueness
*/
void crypto_ops::derivation_to_scalar(const key_derivation &derivation, const hash& uniqueness, ec_scalar &res) {
struct {
hash uniqueness;
key_derivation derivation;
} buf;
buf.uniqueness = uniqueness;
buf.derivation = derivation;
hash_to_scalar(&buf, sizeof(buf), res);
}
bool crypto_ops::derive_public_key(const key_derivation &derivation, const hash& uniqueness,
const public_key &base, public_key &derived_key) {
ec_scalar scalar;
ge_p3 point1;
ge_p3 point2;
ge_cached point3;
ge_p1p1 point4;
ge_p2 point5;
if (ge_frombytes_vartime(&point1, &base) != 0) {
return false;
}
derivation_to_scalar(derivation, uniqueness, scalar);
ge_scalarmult_base(&point2, &scalar);
ge_p3_to_cached(&point3, &point2);
ge_add(&point4, &point1, &point3);
ge_p1p1_to_p2(&point5, &point4);
ge_tobytes(&derived_key, &point5);
return true;
}
void crypto_ops::derive_secret_key(const key_derivation &derivation, const hash& uniqueness,
const secret_key &base, secret_key &derived_key) {
ec_scalar scalar;
assert(sc_check(&base) == 0);
derivation_to_scalar(derivation, uniqueness, scalar);
sc_add(&unwrap(derived_key), &unwrap(base), &scalar);
}
bool crypto_ops::derive_subaddress_public_key(const public_key &out_key, const key_derivation &derivation, const hash& uniqueness, public_key &derived_key) {
ec_scalar scalar;
ge_p3 point1;
ge_p3 point2;
ge_cached point3;
ge_p1p1 point4;
ge_p2 point5;
if (ge_frombytes_vartime(&point1, &out_key) != 0) {
return false;
}
derivation_to_scalar(derivation, uniqueness, scalar);
ge_scalarmult_base(&point2, &scalar);
ge_p3_to_cached(&point3, &point2);
ge_sub(&point4, &point1, &point3);
ge_p1p1_to_p2(&point5, &point4);
ge_tobytes(&derived_key, &point5);
return true;
}
struct s_comm {
hash h;
ec_point key;