aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/crypto.cpp
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2022-04-19 22:14:03 -0500
committerluigi1111 <luigi1111w@gmail.com>2022-04-19 22:14:03 -0500
commit96758a7d05bb1747951ffac87a307d592f882655 (patch)
tree20900ece7aacd538bb3bacba72e7592e03bd915f /src/crypto/crypto.cpp
parent53bf62d11457b011ac77d6d2947e662259cfec5e (diff)
parentea87b30f8907ee11252433811e7a7d0c46758cca (diff)
downloadmonzero-core-96758a7d05bb1747951ffac87a307d592f882655.tar.gz
monzero-core-96758a7d05bb1747951ffac87a307d592f882655.tar.xz
monzero-core-96758a7d05bb1747951ffac87a307d592f882655.zip
Merge pull request #8061
ea87b30 Add view tags to outputs to reduce wallet scanning time (j-berman)
Diffstat (limited to 'src/crypto/crypto.cpp')
-rw-r--r--src/crypto/crypto.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp
index 1f46164d7..77a36069a 100644
--- a/src/crypto/crypto.cpp
+++ b/src/crypto/crypto.cpp
@@ -749,4 +749,28 @@ POP_WARNINGS
sc_sub(&h, &h, &sum);
return sc_isnonzero(&h) == 0;
}
+
+ void crypto_ops::derive_view_tag(const key_derivation &derivation, size_t output_index, view_tag &view_tag) {
+ #pragma pack(push, 1)
+ struct {
+ char salt[8]; // view tag domain-separator
+ key_derivation derivation;
+ char output_index[(sizeof(size_t) * 8 + 6) / 7];
+ } buf;
+ #pragma pack(pop)
+
+ char *end = buf.output_index;
+ memcpy(buf.salt, "view_tag", 8); // leave off null terminator
+ buf.derivation = derivation;
+ tools::write_varint(end, output_index);
+ assert(end <= buf.output_index + sizeof buf.output_index);
+
+ // view_tag_full = H[salt|derivation|output_index]
+ hash view_tag_full;
+ cn_fast_hash(&buf, end - reinterpret_cast<char *>(&buf), view_tag_full);
+
+ // only need a slice of view_tag_full to realize optimal perf/space efficiency
+ static_assert(sizeof(crypto::view_tag) <= sizeof(view_tag_full), "view tag should not be larger than hash result");
+ memcpy(&view_tag, &view_tag_full, sizeof(crypto::view_tag));
+ }
}