|
| 1 | +// Copyright (c) 2024, The Monero Project |
| 2 | +// |
| 3 | +// All rights reserved. |
| 4 | +// |
| 5 | +// Redistribution and use in source and binary forms, with or without modification, are |
| 6 | +// permitted provided that the following conditions are met: |
| 7 | +// |
| 8 | +// 1. Redistributions of source code must retain the above copyright notice, this list of |
| 9 | +// conditions and the following disclaimer. |
| 10 | +// |
| 11 | +// 2. Redistributions in binary form must reproduce the above copyright notice, this list |
| 12 | +// of conditions and the following disclaimer in the documentation and/or other |
| 13 | +// materials provided with the distribution. |
| 14 | +// |
| 15 | +// 3. Neither the name of the copyright holder nor the names of its contributors may be |
| 16 | +// used to endorse or promote products derived from this software without specific |
| 17 | +// prior written permission. |
| 18 | +// |
| 19 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
| 20 | +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 | +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 22 | +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 24 | +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 26 | +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 27 | +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | + |
| 29 | +//paired header |
| 30 | +#include "account_secrets.h" |
| 31 | + |
| 32 | +//local headers |
| 33 | +#include "config.h" |
| 34 | +#include "crypto/generators.h" |
| 35 | +#include "hash_functions.h" |
| 36 | +#include "ringct/rctOps.h" |
| 37 | +#include "transcript_fixed.h" |
| 38 | + |
| 39 | +//third party headers |
| 40 | + |
| 41 | +//standard headers |
| 42 | + |
| 43 | +#undef MONERO_DEFAULT_LOG_CATEGORY |
| 44 | +#define MONERO_DEFAULT_LOG_CATEGORY "carrot" |
| 45 | + |
| 46 | +namespace carrot |
| 47 | +{ |
| 48 | +//------------------------------------------------------------------------------------------------------------------- |
| 49 | +void make_carrot_provespend_key(const crypto::secret_key &s_master, |
| 50 | + crypto::secret_key &k_prove_spend_out) |
| 51 | +{ |
| 52 | + // k_ps = H_n(s_m) |
| 53 | + const auto transcript = sp::make_fixed_transcript<CARROT_DOMAIN_SEP_PROVE_SPEND_KEY>(); |
| 54 | + derive_scalar(transcript.data(), transcript.size(), &s_master, to_bytes(k_prove_spend_out)); |
| 55 | +} |
| 56 | +//------------------------------------------------------------------------------------------------------------------- |
| 57 | +void make_carrot_viewbalance_secret(const crypto::secret_key &s_master, |
| 58 | + crypto::secret_key &s_view_balance_out) |
| 59 | +{ |
| 60 | + // s_vb = H_32(s_m) |
| 61 | + const auto transcript = sp::make_fixed_transcript<CARROT_DOMAIN_SEP_VIEW_BALANCE_SECRET>(); |
| 62 | + derive_bytes_32(transcript.data(), transcript.size(), &s_master, to_bytes(s_view_balance_out)); |
| 63 | +} |
| 64 | +//------------------------------------------------------------------------------------------------------------------- |
| 65 | +void make_carrot_generateimage_key(const crypto::secret_key &s_view_balance, |
| 66 | + crypto::secret_key &k_generate_image_out) |
| 67 | +{ |
| 68 | + // k_gi = H_n(s_vb) |
| 69 | + const auto transcript = sp::make_fixed_transcript<CARROT_DOMAIN_SEP_GENERATE_IMAGE_KEY>(); |
| 70 | + derive_scalar(transcript.data(), transcript.size(), &s_view_balance, to_bytes(k_generate_image_out)); |
| 71 | +} |
| 72 | +//------------------------------------------------------------------------------------------------------------------- |
| 73 | +void make_carrot_viewincoming_key(const crypto::secret_key &s_view_balance, |
| 74 | + crypto::secret_key &k_view_out) |
| 75 | +{ |
| 76 | + // k_v = H_n(s_vb) |
| 77 | + const auto transcript = sp::make_fixed_transcript<CARROT_DOMAIN_SEP_INCOMING_VIEW_KEY>(); |
| 78 | + derive_scalar(transcript.data(), transcript.size(), &s_view_balance, to_bytes(k_view_out)); |
| 79 | +} |
| 80 | +//------------------------------------------------------------------------------------------------------------------- |
| 81 | +void make_carrot_generateaddress_secret(const crypto::secret_key &s_view_balance, |
| 82 | + crypto::secret_key &s_generate_address_out) |
| 83 | +{ |
| 84 | + // s_ga = H_32(s_vb) |
| 85 | + const auto transcript = sp::make_fixed_transcript<CARROT_DOMAIN_SEP_GENERATE_ADDRESS_SECRET>(); |
| 86 | + derive_bytes_32(transcript.data(), transcript.size(), &s_view_balance, to_bytes(s_generate_address_out)); |
| 87 | +} |
| 88 | +//------------------------------------------------------------------------------------------------------------------- |
| 89 | +void make_carrot_spend_pubkey(const crypto::secret_key &k_generate_image, |
| 90 | + const crypto::secret_key &k_prove_spend, |
| 91 | + crypto::public_key &spend_pubkey_out) |
| 92 | +{ |
| 93 | + // k_ps T |
| 94 | + rct::key tmp; |
| 95 | + rct::scalarmultKey(tmp, rct::pk2rct(crypto::get_T()), rct::sk2rct(k_prove_spend)); |
| 96 | + |
| 97 | + // K_s = k_gi G + k_ps T |
| 98 | + rct::addKeys1(tmp, rct::sk2rct(k_generate_image), tmp); |
| 99 | + spend_pubkey_out = rct::rct2pk(tmp); |
| 100 | +} |
| 101 | +//------------------------------------------------------------------------------------------------------------------- |
| 102 | +} //namespace carrot |
0 commit comments