Skip to content

Commit

Permalink
Merge pull request #83 from Zondax/style/format
Browse files Browse the repository at this point in the history
Format codebase with clang-format
  • Loading branch information
becominginsane authored Nov 10, 2023
2 parents abb6a22 + c371425 commit f2b5a70
Show file tree
Hide file tree
Showing 37 changed files with 5,052 additions and 4,758 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# clang-format whole repo
1782c0088b067ae7275c22658e326378f0481d9c
75 changes: 51 additions & 24 deletions app/rust/include/rslib.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,39 @@
/****************************** others
* ********************************************************************************/

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

void get_pkd_from_seed(const uint8_t *seed_ptr, const 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, const 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);

void get_diversifier_list_withstartindex(const uint8_t *seed_ptr, const uint32_t pos, const uint8_t *startindex, uint8_t *diversifier_list);
void get_diversifier_list_withstartindex(const uint8_t *seed_ptr,
const uint32_t pos,
const uint8_t *startindex,
uint8_t *diversifier_list);

void get_default_diversifier_list_withstartindex(const uint8_t *seed_ptr, const uint32_t pos, uint8_t *startindex, uint8_t *diversifier_list);
void get_default_diversifier_list_withstartindex(const uint8_t *seed_ptr,
const uint32_t pos,
uint8_t *startindex,
uint8_t *diversifier_list);

void get_default_diversifier_without_start_index(const uint8_t *see_ptr, const uint32_t pos, uint8_t *default_diversifier);
void get_default_diversifier_without_start_index(const uint8_t *see_ptr,
const 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 @@ -37,42 +50,56 @@ void zip32_ovk(const uint8_t *seed_ptr, uint8_t *ovk, const uint32_t pos);

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

void zip32_child_proof_key(const uint8_t *seed_ptr, uint8_t *ak_ptr, uint8_t *nsk_ptr, const uint32_t pos);
void zip32_child_proof_key(const uint8_t *seed_ptr, uint8_t *ak_ptr,
uint8_t *nsk_ptr, const 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);
// 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_rcm(const uint8_t *input, uint8_t *output_ptr);

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

void compute_note_commitment_fullpoint(uint8_t *inputptr, const uint8_t *rcmptr,const uint64_t value, const uint8_t *diversifier_ptr, const uint8_t *pkd);
void compute_note_commitment_fullpoint(uint8_t *inputptr, const uint8_t *rcmptr,
const 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
// 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
// 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);
void rsk_to_rk(const uint8_t *rsk_ptr, uint8_t *rk_ptr);

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);
// Session key
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);
130 changes: 66 additions & 64 deletions app/src/addr.c
Original file line number Diff line number Diff line change
@@ -1,79 +1,81 @@
/*******************************************************************************
* (c) 2018 - 2022 Zondax AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
* (c) 2018 - 2022 Zondax AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/

#include <stdio.h>
#include "actions.h"
#include "app_mode.h"
#include "coin.h"
#include "crypto.h"
#include "zxerror.h"
#include "zxmacros.h"
#include "zxformat.h"
#include "app_mode.h"
#include "crypto.h"
#include "actions.h"
#include "zxmacros.h"
#include <stdio.h>

zxerr_t addr_getNumItems(uint8_t *num_items) {
zemu_log_stack("addr_getNumItems");
*num_items = 1;
if (app_mode_expert()) {
*num_items = 2;
}
return zxerr_ok;
zemu_log_stack("addr_getNumItems");
*num_items = 1;
if (app_mode_expert()) {
*num_items = 2;
}
return zxerr_ok;
}

zxerr_t addr_getItem(int8_t displayIdx,
char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount) {
ZEMU_LOGF(200, "[addr_getItem] %d/%d\n", displayIdx, pageIdx)
zxerr_t addr_getItem(int8_t displayIdx, char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen, uint8_t pageIdx,
uint8_t *pageCount) {
ZEMU_LOGF(200, "[addr_getItem] %d/%d\n", displayIdx, pageIdx)

switch (displayIdx) {
case 0:
switch (action_addrResponse.kind) {
case addr_secp256k1:
snprintf(outKey, outKeyLen, "Unshielded");
pageString(outVal, outValLen, (char *) (G_io_apdu_buffer + VIEW_ADDRESS_OFFSET_SECP256K1), pageIdx,
pageCount);
return zxerr_ok;
switch (displayIdx) {
case 0:
switch (action_addrResponse.kind) {
case addr_secp256k1:
snprintf(outKey, outKeyLen, "Unshielded");
pageString(outVal, outValLen,
(char *)(G_io_apdu_buffer + VIEW_ADDRESS_OFFSET_SECP256K1),
pageIdx, pageCount);
return zxerr_ok;

case addr_sapling:
snprintf(outKey, outKeyLen, "Shielded");
pageString(outVal, outValLen, (char *) (G_io_apdu_buffer + VIEW_ADDRESS_OFFSET_SAPLING), pageIdx,
pageCount);
return zxerr_ok;
case addr_sapling:
snprintf(outKey, outKeyLen, "Shielded");
pageString(outVal, outValLen,
(char *)(G_io_apdu_buffer + VIEW_ADDRESS_OFFSET_SAPLING),
pageIdx, pageCount);
return zxerr_ok;

case addr_sapling_div:
snprintf(outKey, outKeyLen, "Shielded with div");
pageString(outVal, outValLen, (char *) (G_io_apdu_buffer + VIEW_ADDRESS_OFFSET_SAPLING), pageIdx,
pageCount);
return zxerr_ok;
case addr_sapling_div:
snprintf(outKey, outKeyLen, "Shielded with div");
pageString(outVal, outValLen,
(char *)(G_io_apdu_buffer + VIEW_ADDRESS_OFFSET_SAPLING),
pageIdx, pageCount);
return zxerr_ok;

default:
return zxerr_no_data;
}
case 1: {
if (!app_mode_expert()) {
return zxerr_no_data;
}

snprintf(outKey, outKeyLen, "Your Path");
char buffer[300];
bip32_to_str(buffer, sizeof(buffer), hdPath, HDPATH_LEN_DEFAULT);
pageString(outVal, outValLen, buffer, pageIdx, pageCount);
return zxerr_ok;
}
default:
return zxerr_no_data;
default:
return zxerr_no_data;
}
case 1: {
if (!app_mode_expert()) {
return zxerr_no_data;
}

snprintf(outKey, outKeyLen, "Your Path");
char buffer[300];
bip32_to_str(buffer, sizeof(buffer), hdPath, HDPATH_LEN_DEFAULT);
pageString(outVal, outValLen, buffer, pageIdx, pageCount);
return zxerr_ok;
}
default:
return zxerr_no_data;
}
}
35 changes: 17 additions & 18 deletions app/src/addr.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*******************************************************************************
* (c) 2018 = 2022 Zondax AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
* (c) 2018 = 2022 Zondax AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/

#pragma once

Expand All @@ -24,10 +24,9 @@ extern "C" {
zxerr_t addr_getNumItems(uint8_t *num_items);

/// Gets an specific item from the address view (including paging)
zxerr_t addr_getItem(int8_t displayIdx,
char *outKey, uint16_t outKeyLen,
char *outValue, uint16_t outValueLen,
uint8_t pageIdx, uint8_t *pageCount);
zxerr_t addr_getItem(int8_t displayIdx, char *outKey, uint16_t outKeyLen,
char *outValue, uint16_t outValueLen, uint8_t pageIdx,
uint8_t *pageCount);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit f2b5a70

Please sign in to comment.