Skip to content

Commit

Permalink
more changes to key_container and jamtis_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
DangerousFreedom1984 committed Feb 17, 2024
1 parent 032928d commit 4c8f18f
Show file tree
Hide file tree
Showing 7 changed files with 444 additions and 201 deletions.
67 changes: 31 additions & 36 deletions src/seraphis_wallet/jamtis_keys.cpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
// Copyright (c) 2024, The Monero Project
//
//
// All rights reserved.
//
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

//paired header
// NOT FOR PRODUCTION

// paired header
#include "jamtis_keys.h"

//local headers
// local headers
#include "crypto/chacha.h"
#include "crypto/crypto.h"
#include "crypto/x25519.h"
#include "ringct/rctOps.h"
#include "ringct/rctTypes.h"
#include "seraphis_core/jamtis_core_utils.h"
#include "seraphis_core/sp_core_enote_utils.h"

//third party headers

//standard headers
// third party headers

// standard headers

#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "seraphis_wallet"
Expand All @@ -52,8 +54,10 @@ namespace jamtis
//-------------------------------------------------------------------------------------------------------------------
void make_jamtis_keys(JamtisKeys &keys_out)
{
keys_out.k_m = rct::rct2sk(rct::skGen());
keys_out.k_vb = rct::rct2sk(rct::skGen());
keys_out.k_s_legacy = rct::rct2sk(rct::zero());
keys_out.k_v_legacy = rct::rct2sk(rct::zero());
keys_out.k_m = rct::rct2sk(rct::skGen());
keys_out.k_vb = rct::rct2sk(rct::skGen());
make_jamtis_unlockamounts_key(keys_out.k_vb, keys_out.xk_ua);
make_jamtis_findreceived_key(keys_out.k_vb, keys_out.xk_fr);
make_jamtis_generateaddress_secret(keys_out.k_vb, keys_out.s_ga);
Expand All @@ -63,33 +67,27 @@ void make_jamtis_keys(JamtisKeys &keys_out)
make_jamtis_findreceived_pubkey(keys_out.xk_fr, keys_out.xK_ua, keys_out.xK_fr);
}
//-------------------------------------------------------------------------------------------------------------------
void make_address_random(const JamtisKeys &user_keys, JamtisDestinationV1 &user_address_out)
void make_destination_random(const JamtisKeys &user_keys, JamtisDestinationV1 &user_destination_out)
{
address_index_t address_index;
address_index = gen_address_index();

make_jamtis_destination_v1(user_keys.K_1_base,
user_keys.xK_ua,
user_keys.xK_fr,
user_keys.s_ga,
address_index,
user_address_out);
make_jamtis_destination_v1(
user_keys.K_1_base, user_keys.xK_ua, user_keys.xK_fr, user_keys.s_ga, address_index, user_destination_out);
}
//-------------------------------------------------------------------------------------------------------------------
void make_address_zero(const JamtisKeys &user_keys, JamtisDestinationV1 &user_address_out)
void make_destination_zero(const JamtisKeys &user_keys, JamtisDestinationV1 &user_destination_out)
{
address_index_t address_index{};

make_jamtis_destination_v1(user_keys.K_1_base,
user_keys.xK_ua,
user_keys.xK_fr,
user_keys.s_ga,
address_index,
user_address_out);
make_jamtis_destination_v1(
user_keys.K_1_base, user_keys.xK_ua, user_keys.xK_fr, user_keys.s_ga, address_index, user_destination_out);
}
//-------------------------------------------------------------------------------------------------------------------
void JamtisKeys::encrypt(const crypto::chacha_key &key, const crypto::chacha_iv &iv)
{
crypto::chacha20(k_s_legacy.data, sizeof(k_s_legacy), key, iv, k_s_legacy.data);
crypto::chacha20(k_v_legacy.data, sizeof(k_v_legacy), key, iv, k_v_legacy.data);
crypto::chacha20(k_m.data, sizeof(k_m), key, iv, k_m.data);
crypto::chacha20(k_vb.data, sizeof(k_vb), key, iv, k_vb.data);
crypto::chacha20(xk_ua.data, sizeof(xk_ua), key, iv, (char *)xk_ua.data);
Expand All @@ -98,10 +96,7 @@ void JamtisKeys::encrypt(const crypto::chacha_key &key, const crypto::chacha_iv
crypto::chacha20(s_ct.data, sizeof(s_ct), key, iv, s_ct.data);
}
//-------------------------------------------------------------------------------------------------------------------
void JamtisKeys::decrypt(const crypto::chacha_key &key, const crypto::chacha_iv &iv)
{
encrypt(key, iv);
}
void JamtisKeys::decrypt(const crypto::chacha_key &key, const crypto::chacha_iv &iv) { encrypt(key, iv); }
//-------------------------------------------------------------------------------------------------------------------
} //namespace jamtis
} //namespace sp
} // namespace jamtis
} // namespace sp
23 changes: 20 additions & 3 deletions src/seraphis_wallet/jamtis_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ namespace sp
namespace jamtis
{

////
// Set of jamtis keys
///
struct JamtisKeys
{
crypto::secret_key k_s_legacy; //legacy spend-key
crypto::secret_key k_v_legacy; //legacy view-key
crypto::secret_key k_m; //master
crypto::secret_key k_vb; //view-balance
crypto::x25519_secret_key xk_ua; //unlock-amounts
Expand All @@ -64,7 +69,9 @@ struct JamtisKeys

bool operator==(const JamtisKeys &other) const {
// use hash?
return other.k_m == k_m &&
return other.k_s_legacy == k_s_legacy &&
other.k_v_legacy == k_v_legacy &&
other.k_m == k_m &&
other.k_vb == k_vb &&
other.xk_ua == xk_ua &&
other.xk_fr == xk_fr &&
Expand All @@ -79,10 +86,20 @@ struct JamtisKeys
void decrypt(const crypto::chacha_key &key, const crypto::chacha_iv &iv);
};

/// Legacy keys
struct LegacyKeys
{
crypto::secret_key k_s; //spend privkey
crypto::secret_key k_v; //view privkey
rct::key Ks; //main spend pubkey: Ks = k_s G
rct::key Kv; //main view pubkey: Kv = k_v G
};

/// make a set of jamtis keys
void make_jamtis_keys(JamtisKeys &keys_out);
/// make a random jamtis address for the given privkeys
void make_address_random(const JamtisKeys &user_keys, JamtisDestinationV1 &user_address_out);
void make_address_zero(const JamtisKeys &user_keys, JamtisDestinationV1 &user_address_out);
void make_destination_random(const JamtisKeys &user_keys, JamtisDestinationV1 &user_destination_out);
void make_destination_zero(const JamtisKeys &user_keys, JamtisDestinationV1 &user_destination_out);

} //namespace jamtis
} //namespace sp
Loading

0 comments on commit 4c8f18f

Please sign in to comment.