Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

applying clang format #110

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 19 additions & 37 deletions app/rust/include/rslib.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>

#include "parser_common.h"
#include "parser_txdef.h"
Expand All @@ -10,17 +10,14 @@
* ********************************************************************************/

// ZIP32 functions
void get_pkd(const uint8_t *seed_ptr, uint32_t pos,
const uint8_t *diversifier_ptr, uint8_t *pkd);
void get_pkd(const uint8_t *seed_ptr, uint32_t pos, const uint8_t *diversifier_ptr, uint8_t *pkd);

void get_pkd_from_seed(const uint8_t *seed_ptr, uint32_t pos,
const uint8_t *start_index, uint8_t *diversifier_ptr,
uint8_t *pkd);
void get_pkd_from_seed(
const uint8_t *seed_ptr, uint32_t pos, const uint8_t *start_index, uint8_t *diversifier_ptr, uint8_t *pkd);

void get_diversifier_list(const uint8_t *sk_ptr, uint8_t *diversifier_list);

void get_diversifier_fromlist(const uint8_t *diversifier_list,
uint8_t *diversifier);
void get_diversifier_fromlist(const uint8_t *diversifier_list, uint8_t *diversifier);

bool is_valid_diversifier(const uint8_t *diversifier);

Expand All @@ -34,14 +31,11 @@ void get_default_diversifier_list_withstartindex(const uint8_t *seed_ptr,
uint8_t *startindex,
uint8_t *diversifier_list);

void get_default_diversifier_without_start_index(const uint8_t *see_ptr,
uint32_t pos,
uint8_t *default_diversifier);
void get_default_diversifier_without_start_index(const uint8_t *see_ptr, uint32_t pos, uint8_t *default_diversifier);

void zip32_master(const uint8_t *seed_ptr, uint8_t *sk_ptr, uint8_t *dk_ptr);

void zip32_child_ask_nsk(const uint8_t *seed_ptr, uint8_t *ask, uint8_t *nsk,
const uint32_t pos);
void zip32_child_ask_nsk(const uint8_t *seed_ptr, uint8_t *ask, uint8_t *nsk, const uint32_t pos);

void zip32_nsk_from_seed(const uint8_t *seed_ptr, uint8_t *nsk);

Expand All @@ -51,46 +45,35 @@ void zip32_ovk(const uint8_t *seed_ptr, uint8_t *ovk, uint32_t pos);

void zip32_fvk(const uint8_t *seed_ptr, uint8_t *fvk, uint32_t pos);

void zip32_child_proof_key(const uint8_t *seed_ptr, uint8_t *ak_ptr,
uint8_t *nsk_ptr, uint32_t pos);
void zip32_child_proof_key(const uint8_t *seed_ptr, uint8_t *ak_ptr, uint8_t *nsk_ptr, uint32_t pos);

// Rseed
void rseed_get_esk_epk(const uint8_t *seed_ptr, uint8_t *d_ptr,
uint8_t *output_esk_ptr, uint8_t *output_epk_ptr);
void rseed_get_esk_epk(const uint8_t *seed_ptr, uint8_t *d_ptr, uint8_t *output_esk_ptr, uint8_t *output_epk_ptr);

void rseed_get_rcm(const uint8_t *input, uint8_t *output_ptr);

// Commitments
void compute_note_commitment(uint8_t *inputptr, const uint8_t *rcmptr,
uint64_t value,
const uint8_t *diversifier_ptr,
const uint8_t *pkd);
void compute_note_commitment(
uint8_t *inputptr, const uint8_t *rcmptr, uint64_t value, const uint8_t *diversifier_ptr, const uint8_t *pkd);

void compute_note_commitment_fullpoint(uint8_t *inputptr, const uint8_t *rcmptr,
uint64_t value,
const uint8_t *diversifier_ptr,
const uint8_t *pkd);
void compute_note_commitment_fullpoint(
uint8_t *inputptr, const uint8_t *rcmptr, uint64_t value, const uint8_t *diversifier_ptr, const uint8_t *pkd);

void compute_value_commitment(const uint64_t value, const uint8_t *rcmptr,
uint8_t *output);
void compute_value_commitment(const uint64_t value, const uint8_t *rcmptr, uint8_t *output);

void compute_nullifier(uint8_t *ncmptr, uint64_t pos, const uint8_t *nsk_ptr,
uint8_t *outputptr);
void compute_nullifier(uint8_t *ncmptr, uint64_t pos, const uint8_t *nsk_ptr, uint8_t *outputptr);

// Note encryption
void blake2b_prf(uint8_t *inputptr, uint8_t *outptr);

void ka_to_key(uint8_t *esk_ptr, uint8_t *pkd_ptr, uint8_t *epk_ptr,
uint8_t *output_ptr);
void ka_to_key(uint8_t *esk_ptr, uint8_t *pkd_ptr, uint8_t *epk_ptr, uint8_t *output_ptr);

void prepare_enccompact_input(uint8_t *d, uint64_t value, uint8_t *rcm,
uint8_t memotype, uint8_t *output);
void prepare_enccompact_input(uint8_t *d, uint64_t value, uint8_t *rcm, uint8_t memotype, uint8_t *output);

// RedJubjub
void random_fr(uint8_t *alpha_ptr);

void randomized_secret_from_seed(uint8_t *seed_ptr, uint32_t pos,
uint8_t *alpha_ptr, uint8_t *output_ptr);
void randomized_secret_from_seed(uint8_t *seed_ptr, uint32_t pos, uint8_t *alpha_ptr, uint8_t *output_ptr);

void get_rk(uint8_t *ask_ptr, uint8_t *alpha_ptr, uint8_t *output_ptr);
void rsk_to_rk(const uint8_t *rsk_ptr, uint8_t *rk_ptr);
Expand All @@ -100,7 +83,6 @@ void randomize_pk(uint8_t *alpha_ptr, uint8_t *pk_ptr);
void sign_redjubjub(uint8_t *key_ptr, uint8_t *msg_ptr, uint8_t *out_ptr);

// Session key
void sessionkey_agree(uint8_t *scalar_ptr, uint8_t *point_ptr,
uint8_t *output_ptr);
void sessionkey_agree(uint8_t *scalar_ptr, uint8_t *point_ptr, uint8_t *output_ptr);

void pubkey_gen(uint8_t *scalar_ptr, uint8_t *output_ptr);
52 changes: 26 additions & 26 deletions app/rust/src/commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::bolos::c_zemu_log_stack;
use crate::pedersen::*;
use crate::redjubjub::*;
use crate::zeccrypto::prf_ock;
use crate::zip32::{group_hash_from_div, nsk_to_nk,zip32_nsk_from_seed};
use crate::zip32::{group_hash_from_div, nsk_to_nk, zip32_nsk_from_seed};

pub const PEDERSEN_RANDOMNESS_BASE: AffineNielsPoint = AffinePoint::from_raw_unchecked(
Fq::from_raw([
Expand Down Expand Up @@ -180,15 +180,14 @@ pub fn prepare_and_hash_input_commitment(
g_d_ptr: *const [u8; 32],
pkd_ptr: *const [u8; 32],
output_ptr: *mut [u8; 32],
) {
) {
let gd = unsafe { &*g_d_ptr };
let pkd = unsafe { &*pkd_ptr };

let mut prepared_msg = [0u8; 73];
let mut prepared_msg = [0u8; 73];
let mut input_hash = [0u8; 73];
let output_msg = unsafe { &mut *output_ptr };


let vbytes = write_u64_tobytes(value);
input_hash[0..8].copy_from_slice(&vbytes);

Expand Down Expand Up @@ -282,12 +281,13 @@ pub extern "C" fn compute_nullifier(
}

#[no_mangle]
pub extern "C" fn compute_note_commitment(input_ptr: *mut [u8; 32],
rcm_ptr: *const [u8; 32],
value: u64,
diversifier_ptr: *const [u8; 11],
pkd_ptr: *const [u8; 32]) {

pub extern "C" fn compute_note_commitment(
input_ptr: *mut [u8; 32],
rcm_ptr: *const [u8; 32],
value: u64,
diversifier_ptr: *const [u8; 11],
pkd_ptr: *const [u8; 32],
) {
let mut gd = [0u8; 32];
let diversifier = unsafe { &*diversifier_ptr };
group_hash_from_div(diversifier, &mut gd);
Expand All @@ -303,14 +303,14 @@ pub extern "C" fn compute_note_commitment(input_ptr: *mut [u8; 32],
out.copy_from_slice(&extended_to_u_bytes(&e));
}


#[no_mangle]
pub extern "C" fn compute_note_commitment_fullpoint(
input_ptr: *mut [u8; 32],
rcm_ptr: *const [u8; 32],
value: u64,
diversifier_ptr: *const [u8; 11],
pkd_ptr: *const [u8; 32]) {
pkd_ptr: *const [u8; 32],
) {
let mut gd = [0u8; 32];
let diversifier = unsafe { &*diversifier_ptr };

Expand All @@ -333,7 +333,6 @@ pub extern "C" fn compute_value_commitment(
rcm_ptr: *const [u8; 32],
output_ptr: *mut [u8; 32],
) {

let rc = unsafe { &*rcm_ptr };
let output_msg = unsafe { &mut *output_ptr };

Expand Down Expand Up @@ -366,7 +365,7 @@ mod tests {
let rcm = [0u8; 32];
let output = [0u8; 32];

let div = &div_ptr ;
let div = &div_ptr;

group_hash_from_div(div, &mut gd);

Expand All @@ -382,14 +381,14 @@ mod tests {
rcm.as_ptr() as *const [u8; 32],
v,
div.as_ptr() as *const [u8; 11],
pkd.as_ptr() as *const [u8; 32]
pkd.as_ptr() as *const [u8; 32],
);

assert_eq!(
output,
[
51, 107, 65, 49, 174, 10, 181, 105, 255, 123, 174, 149, 217, 191, 95,
76, 7, 90, 151, 132, 85, 143, 180, 30, 26, 35, 160, 160, 197, 140, 21, 95
51, 107, 65, 49, 174, 10, 181, 105, 255, 123, 174, 149, 217, 191, 95, 76, 7, 90,
151, 132, 85, 143, 180, 30, 26, 35, 160, 160, 197, 140, 21, 95
]
);
}
Expand Down Expand Up @@ -512,26 +511,27 @@ mod tests {
let pos: u64 = 2578461368;

let seed: [u8; 32] = [
176,142,61,152,218,67,28,239,69,102,161,60,27,179,72,185,
130,247,216,231,67,180,59,182,37,87,186,81,153,75,18,87,
176, 142, 61, 152, 218, 67, 28, 239, 69, 102, 161, 60, 27, 179, 72, 185, 130, 247, 216,
231, 67, 180, 59, 182, 37, 87, 186, 81, 153, 75, 18, 87,
];

let cm: [u8; 32] = [
0x21, 0xc9, 0x46, 0x98, 0xca, 0x32, 0x4b, 0x4c, 0xba, 0xce, 0x29, 0x1d, 0x27, 0xab,
0xb6, 0x8a, 0xa, 0xaf, 0x27, 0x37, 0xdc, 0x45, 0x56, 0x54, 0x1c, 0x7f, 0xcd, 0xe8,
0xce, 0x11, 0xdd, 0xe8];
0xce, 0x11, 0xdd, 0xe8,
];

let mut nsk = [0u8; 32];
zip32_nsk_from_seed(&seed,&mut nsk);
zip32_nsk_from_seed(&seed, &mut nsk);

let mut nf = [0u8; 32];
compute_nullifier(&cm, pos, &nsk,&mut nf);

compute_nullifier(&cm, pos, &nsk, &mut nf);

let nftest: [u8; 32] = [
0x25,0xf1,0xf2,0xcf,0x5e,0x2c,0x2b,0xc3,0x1d,0x7,0xb6,0x6f,
0x4d,0x54,0xf0,0x90,0xad,0x89,0xb1,0x98,0x89,0x3f,0x12,0xad,
0xae,0x44,0x7d,0xdf,0x84,0xe2,0x14,0x5a];
0x25, 0xf1, 0xf2, 0xcf, 0x5e, 0x2c, 0x2b, 0xc3, 0x1d, 0x7, 0xb6, 0x6f, 0x4d, 0x54,
0xf0, 0x90, 0xad, 0x89, 0xb1, 0x98, 0x89, 0x3f, 0x12, 0xad, 0xae, 0x44, 0x7d, 0xdf,
0x84, 0xe2, 0x14, 0x5a,
];
assert_eq!(nf, nftest);
}

Expand Down
8 changes: 4 additions & 4 deletions app/rust/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ pub const ENC_COMPACT_SIZE: usize = COMPACT_NOTE_SIZE + 16;
pub const ENC_CIPHERTEXT_SIZE: usize = NOTE_PLAINTEXT_SIZE + 16;
pub const OUT_CIPHERTEXT_SIZE: usize = OUT_PLAINTEXT_SIZE + 16;

pub const DIV_SIZE: usize = 11;
pub const DIV_SIZE: usize = 11;
pub const DIV_DEFAULT_LIST_LEN: usize = 4;
pub const MAX_SIZE_BUF_ADDR: usize = 143;
pub const MAX_SIZE_BUF_ADDR: usize = 143;

pub const FIRSTVALUE: u32 = 32 ^ 0x8000_0000;
pub const COIN_TYPE: u32 = 133 ^ 0x8000_0000;
pub const FIRSTVALUE: u32 = 32 ^ 0x8000_0000;
pub const COIN_TYPE: u32 = 133 ^ 0x8000_0000;

pub const CRH_IVK_PERSONALIZATION: &[u8; 8] = b"Zcashivk";

Expand Down
Loading
Loading