45#undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
46#define ELECTRONEUM_DEFAULT_LOG_CATEGORY "account"
48#define KEYS_ENCRYPTION_SALT 'k'
65 MCDEBUG(
"device",
"account_keys::set_device device type: "<<
typeid(hwdev).name());
68 static void derive_key(
const crypto::chacha_key &base_key, crypto::chacha_key &
key)
70 static_assert(
sizeof(base_key) ==
sizeof(
crypto::hash),
"chacha key and hash should be the same size");
71 epee::mlocked<tools::scrubbed_arr<char,
sizeof(base_key)+1>> data;
72 memcpy(data.data(), &base_key,
sizeof(base_key));
74 crypto::generate_chacha_key(data.data(),
sizeof(data),
key, 1);
77 static epee::wipeable_string get_key_stream(
const crypto::chacha_key &base_key,
const crypto::chacha_iv &iv,
size_t bytes)
80 crypto::chacha_key
key;
81 derive_key(base_key,
key);
86 crypto::chacha20(buffer0.data(), buffer0.size(),
key, iv, buffer1.
data());
90 void account_keys::xor_with_key_stream(
const crypto::chacha_key &
key)
94 const char *ptr = key_stream.
data();
96 m_spend_secret_key.data[i] ^= *ptr++;
98 m_view_secret_key.data[i] ^= *ptr++;
109 xor_with_key_stream(
key);
114 xor_with_key_stream(
key);
121 const char *ptr = key_stream.
data();
137 void account_base::set_null()
140 m_creation_timestamp = 0;
146 m_keys.get_device().disconnect();
147 }
catch (
const std::exception &e){
148 MERROR(
"Device disconnect exception: " << e.what());
155 m_keys.m_multisig_keys.clear();
160 crypto::secret_key first = generate_keys(m_keys.m_account_address.m_spend_public_key, m_keys.m_spend_secret_key, recovery_key, recover);
166 generate_keys(m_keys.m_account_address.m_view_public_key, m_keys.m_view_secret_key, second, two_random ?
false :
true);
168 struct tm timestamp = {0};
169 timestamp.tm_year = 2014 - 1900;
170 timestamp.tm_mon = 6 - 1;
171 timestamp.tm_mday = 8;
172 timestamp.tm_hour = 0;
173 timestamp.tm_min = 0;
174 timestamp.tm_sec = 0;
178 m_creation_timestamp = mktime(×tamp);
179 if (m_creation_timestamp == (
uint64_t)-1)
180 m_creation_timestamp = 0;
184 m_creation_timestamp =
time(NULL);
191 m_keys.m_account_address =
address;
192 m_keys.m_spend_secret_key =
spendkey;
193 m_keys.m_view_secret_key = viewkey;
195 struct tm timestamp = {0};
196 timestamp.tm_year = 2014 - 1900;
197 timestamp.tm_mon = 4 - 1;
198 timestamp.tm_mday = 15;
199 timestamp.tm_hour = 0;
200 timestamp.tm_min = 0;
201 timestamp.tm_sec = 0;
203 m_creation_timestamp = mktime(×tamp);
204 if (m_creation_timestamp == (
uint64_t)-1)
205 m_creation_timestamp = 0;
218 m_keys.set_device(hwdev);
219 MCDEBUG(
"device",
"device type: "<<
typeid(hwdev).name());
225 }
catch (
const std::exception &e){
229 struct tm timestamp = {0};
230 timestamp.tm_year = 2014 - 1900;
231 timestamp.tm_mon = 4 - 1;
232 timestamp.tm_mday = 15;
233 timestamp.tm_hour = 0;
234 timestamp.tm_min = 0;
235 timestamp.tm_sec = 0;
237 m_creation_timestamp = mktime(×tamp);
238 if (m_creation_timestamp == (
uint64_t)-1)
239 m_creation_timestamp = 0;
246 memset(&unwrap(unwrap(fake)), 0,
sizeof(fake));
252 m_keys.m_account_address.m_spend_public_key = spend_public_key;
253 m_keys.m_view_secret_key = view_secret_key;
254 m_keys.m_spend_secret_key = spend_secret_key;
255 m_keys.m_multisig_keys = multisig_keys;
261 m_keys.m_account_address.m_spend_public_key = spend_public_key;
void finalize_multisig(const crypto::public_key &spend_public_key)
std::string get_public_address_str(network_type nettype) const
bool make_multisig(const crypto::secret_key &view_secret_key, const crypto::secret_key &spend_secret_key, const crypto::public_key &spend_public_key, const std::vector< crypto::secret_key > &multisig_keys)
void create_from_viewkey(const cryptonote::account_public_address &address, const crypto::secret_key &viewkey)
crypto::secret_key generate(const crypto::secret_key &recovery_key=crypto::secret_key(), bool recover=false, bool two_random=false)
void create_from_keys(const cryptonote::account_public_address &address, const crypto::secret_key &spendkey, const crypto::secret_key &viewkey)
void create_from_device(const std::string &device_name)
const account_keys & get_keys() const
std::string get_public_integrated_address_str(const crypto::hash8 &payment_id, network_type nettype) const
const char * data() const noexcept
virtual bool connect(void)=0
virtual bool disconnect(void)=0
virtual bool init(void)=0
virtual bool get_secret_keys(crypto::secret_key &viewkey, crypto::secret_key &spendkey)=0
virtual bool set_name(const std::string &name)=0
virtual bool get_public_address(cryptonote::account_public_address &pubkey)=0
void * memcpy(void *a, const void *b, size_t c)
void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
std::enable_if< std::is_pod< T >::value, T >::type rand()
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
bool secret_key_to_public_key(const secret_key &sec, public_key &pub)
Holds cryptonote related classes and helpers.
std::string get_account_address_as_str(network_type nettype, bool subaddress, account_public_address const &adr)
std::string get_account_integrated_address_as_str(network_type nettype, account_public_address const &adr, crypto::hash8 const &payment_id)
device & get_device(const std::string &device_descriptor)
#define KEYS_ENCRYPTION_SALT
unsigned __int64 uint64_t
crypto::secret_key m_view_secret_key
hw::device & get_device() const
crypto::chacha_iv m_encryption_iv
void encrypt_viewkey(const crypto::chacha_key &key)
void set_device(hw::device &hwdev)
void decrypt_viewkey(const crypto::chacha_key &key)
void decrypt(const crypto::chacha_key &key)
void encrypt(const crypto::chacha_key &key)
#define DISABLE_VS_WARNINGS(w)