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");
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);
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++;
106 void account_keys::encrypt(
const crypto::chacha_key &
key)
108 m_encryption_iv = crypto::rand<crypto::chacha_iv>();
109 xor_with_key_stream(
key);
114 xor_with_key_stream(
key);
117 void account_keys::encrypt_viewkey(
const crypto::chacha_key &
key)
121 const char *ptr = key_stream.
data();
124 m_view_secret_key.data[i] ^= *ptr++;
127 void account_keys::decrypt_viewkey(
const crypto::chacha_key &
key)
129 encrypt_viewkey(
key);
132 account_base::account_base()
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());
152 void account_base::forget_spend_key()
155 m_keys.m_multisig_keys.clear();
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;
209 void account_base::create_from_device(
const std::string &device_name)
213 create_from_device(hwdev);
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;
247 create_from_keys(
address, fake, viewkey);
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;
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
std::string get_account_address_as_str(network_type nettype, bool subaddress, account_public_address const &adr)
#define KEYS_ENCRYPTION_SALT
void chacha20(const void *data, size_t length, const uint8_t *key, const uint8_t *iv, char *cipher)
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
virtual bool set_name(const std::string &name)=0
virtual bool disconnect(void)=0
for(i=1;i< 1;++i) fe_sq(t0
Holds cryptonote related classes and helpers.
std::string get_account_integrated_address_as_str(network_type nettype, account_public_address const &adr, crypto::hash8 const &payment_id)
virtual bool get_public_address(cryptonote::account_public_address &pubkey)=0
device & get_device(const std::string &device_descriptor)
unsigned __int64 uint64_t
secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key &recovery_key=secret_key(), bool recover=false)
void decrypt(const void *ciphertext, size_t length, const uint8_t *key, const uint8_t *iv, char *plaintext, size_t *plaintext_len)
virtual bool get_secret_keys(crypto::secret_key &viewkey, crypto::secret_key &spendkey)=0
void * memcpy(void *a, const void *b, size_t c)
T & unwrap(mlocked< T > &src)
void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
DISABLE_VS_WARNINGS(4244 4345 4503) using namespace crypto
bool secret_key_to_public_key(const secret_key &sec, public_key &pub)
virtual bool connect(void)=0
const char * data() const noexcept
virtual bool init(void)=0