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

Murisi/masp #32

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion app/src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ zxerr_t crypto_hashSigSection(const signature_section_t *signature_section, cons
break;
}
case Address:
CHECK_CX_OK(cx_sha256_update(&sha256, signature_section->address.ptr, signature_section->address.len));
CHECK_CX_OK(cx_sha256_update(&sha256, signature_section->addressBytes.ptr, signature_section->addressBytes.len));
break;

default:
Expand Down
65 changes: 65 additions & 0 deletions app/src/mem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Dynamic allocator that uses a fixed-length buffer that is hopefully big enough
*
* The two functions alloc & dealloc use the buffer as a simple stack.
* Especially useful when an unpredictable amount of data will be received and have to be stored
* during the transaction but discarded right after.
*/

//#ifdef HAVE_DYN_MEM_ALLOC

#include <stdint.h>
#include "mem.h"

#define SIZE_MEM_BUFFER 8192

static uint8_t mem_buffer[SIZE_MEM_BUFFER];
static size_t mem_idx;

/**
* Initializes the memory buffer index
*/
void mem_init(void) {
mem_idx = 0;
}

/**
* Resets the memory buffer index
*/
void mem_reset(void) {
mem_init();
}

/**
* Allocates (push) a chunk of the memory buffer of a given size.
*
* Checks to see if there are enough space left in the memory buffer, returns
* the current location in the memory buffer and moves the index accordingly.
*
* @param[in] size Requested allocation size in bytes
* @return Allocated memory pointer; \ref NULL if not enough space left.
*/
void *mem_alloc(size_t size) {
if ((mem_idx + size) > SIZE_MEM_BUFFER) // Buffer exceeded
{
return NULL;
}
mem_idx += size;
return &mem_buffer[mem_idx - size];
}

/**
* De-allocates (pop) a chunk of memory buffer by a given size.
*
* @param[in] size Requested deallocation size in bytes
*/
void mem_dealloc(size_t size) {
if (size > mem_idx) // More than is already allocated
{
mem_idx = 0;
} else {
mem_idx -= size;
}
}

//#endif // HAVE_DYN_MEM_ALLOC
15 changes: 15 additions & 0 deletions app/src/mem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef MEM_H_
#define MEM_H_

//#ifdef HAVE_DYN_MEM_ALLOC

#include <stdlib.h>

void mem_init(void);
void mem_reset(void);
void *mem_alloc(size_t size);
void mem_dealloc(size_t size);

//#endif // HAVE_DYN_MEM_ALLOC

#endif // MEM_H_
4 changes: 3 additions & 1 deletion app/src/parser_impl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ parser_error_t readFieldSizeU16(parser_context_t *ctx, uint16_t *size);
parser_error_t checkTag(parser_context_t *ctx, uint8_t expectedTag);
parser_error_t readPubkey(parser_context_t *ctx, bytes_t *pubkey);

parser_error_t readToken(const bytes_t *token, const char **symbol);
parser_error_t readToken(const AddressAlt *token, const char **symbol);
parser_error_t readAddress(bytes_t pubkeyHash, char *address, uint16_t addressLen);
parser_error_t readAddressAlt(parser_context_t *ctx, AddressAlt *obj);
parser_error_t encodeAddress(const AddressAlt *addr, char *address, uint16_t addressLen);
parser_error_t readVote(bytes_t *vote, yay_vote_type_e type, char *strVote, uint16_t strVoteLen);

parser_error_t readHeader(parser_context_t *ctx, parser_tx_t *v);
Expand Down
Loading
Loading