Skip to content

Commit

Permalink
Refactor derivation path prefix validation
Browse files Browse the repository at this point in the history
  • Loading branch information
refi93 committed Dec 14, 2020
1 parent b21bf81 commit 6e06ad8
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/bip44.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool bip44_hasShelleyPrefix(const bip44_path_t* pathSpec)
#undef CHECK
}

bool bip44_hasValidCardanoPrefix(const bip44_path_t* pathSpec)
bool bip44_hasValidCardanoWalletPrefix(const bip44_path_t* pathSpec)
{
return bip44_hasByronPrefix(pathSpec) || bip44_hasShelleyPrefix(pathSpec);
}
Expand Down
2 changes: 1 addition & 1 deletion src/bip44.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum {
bool bip44_hasByronPrefix(const bip44_path_t* pathSpec);
bool bip44_hasShelleyPrefix(const bip44_path_t* pathSpec);
bool bip44_hasPoolColdKeyPrefix(const bip44_path_t* pathSpec);
bool bip44_hasValidCardanoPrefix(const bip44_path_t* pathSpec);
bool bip44_hasValidCardanoWalletPrefix(const bip44_path_t* pathSpec);

bool bip44_containsAccount(const bip44_path_t* pathSpec);
uint32_t bip44_getAccount(const bip44_path_t* pathSpec);
Expand Down
2 changes: 1 addition & 1 deletion src/keyDerivation.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void derivePrivateKey(
privateKey_t* privateKey
)
{
if (!bip44_hasValidCardanoPrefix(pathSpec) && !bip44_isValidPoolColdKeyPath(pathSpec)) {
if (!bip44_hasValidCardanoWalletPrefix(pathSpec) && !bip44_isValidPoolColdKeyPath(pathSpec)) {
THROW(ERR_INVALID_BIP44_PATH);
}
// Sanity check
Expand Down
3 changes: 3 additions & 0 deletions src/messageSigning.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "messageSigning.h"
#include "cardano.h"
#include "keyDerivation.h"
#include "bip44.h"

void signRawMessage(privateKey_t* privateKey,
const uint8_t* messageBuffer, size_t messageSize,
Expand Down Expand Up @@ -61,6 +62,7 @@ void getTxWitness(bip44_path_t* pathSpec,
uint8_t* outBuffer, size_t outSize)
{
ASSERT(txHashSize == TX_HASH_LENGTH);
ASSERT(bip44_hasValidCardanoWalletPrefix(pathSpec));
signRawMessageWithPath(pathSpec, txHashBuffer, txHashSize, outBuffer, outSize);
}

Expand All @@ -69,5 +71,6 @@ void getOpCertSignature(bip44_path_t* pathSpec,
uint8_t* outBuffer, size_t outSize)
{
ASSERT(opCertBodySize == OP_CERT_BODY_LENGTH);
ASSERT(bip44_isValidPoolColdKeyPath(pathSpec));
signRawMessageWithPath(pathSpec, opCertBodyBuffer, opCertBodySize, outBuffer, outSize);
}
4 changes: 2 additions & 2 deletions src/securityPolicy.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static inline bool staking_info_is_valid(const addressParams_t* addressParams)

static inline bool has_cardano_prefix_and_any_account(const bip44_path_t* pathSpec)
{
return bip44_hasValidCardanoPrefix(pathSpec) &&
return bip44_hasValidCardanoWalletPrefix(pathSpec) &&
bip44_containsAccount(pathSpec);
}

Expand All @@ -70,7 +70,7 @@ static inline bool is_valid_stake_pool_owner_path(const bip44_path_t* pathSpec)
// general requirements on witnesses
static inline bool is_valid_witness(const bip44_path_t* pathSpec)
{
if (!bip44_hasValidCardanoPrefix(pathSpec))
if (!bip44_hasValidCardanoWalletPrefix(pathSpec))
return false;

if (bip44_isValidStakingKeyPath(pathSpec))
Expand Down
2 changes: 1 addition & 1 deletion src/uiScreens.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void ui_displayAccountScreen(
ASSERT(strlen(screenHeader) > 0);
ASSERT(strlen(screenHeader) < BUFFER_SIZE_PARANOIA);

ASSERT(bip44_hasValidCardanoPrefix(path));
ASSERT(bip44_hasValidCardanoWalletPrefix(path));
ASSERT(bip44_containsAccount(path));

char accountDescription[160];
Expand Down

0 comments on commit 6e06ad8

Please sign in to comment.