Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jjos2372 committed Dec 21, 2022
2 parents c6dab74 + 12e14fb commit b19e8cd
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 110 deletions.
15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ endif
include $(BOLOS_SDK)/Makefile.defines

APPNAME = Signum
DEFINES = "PATH_PREFIX={44|0x80000000,30|0x80000000}"
DEFINES += "PATH_PREFIX={44|0x80000000,30|0x80000000}"
PATH_PREFIX = "44'/30'"
DEFINES += APP_PREFIX=\"S-\"

ifeq ($(TARGET_NAME),TARGET_NANOX)
ICONNAME = icons/nanox_app_signum.gif
else
Expand All @@ -46,22 +46,22 @@ $(info Building $(APPNAME) app...)

#This inits the SDK_SOURCE_PATH variable, moving this will screw up the build, because the next if does +=
SDK_SOURCE_PATH = lib_stusb lib_stusb_impl lib_u2f lib_ux
APP_LOAD_PARAMS = --curve ed25519 $(COMMON_LOAD_PARAMS)
APP_LOAD_PARAMS = --curve ed25519 $(COMMON_LOAD_PARAMS)

# Ledger: add the "Pending security review" disclaimer
APP_LOAD_PARAMS += --tlvraw 9F:01

ifeq ($(TARGET_NAME),TARGET_NANOX)
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl

# The --appFlags param gives permision to open bluetooth
APP_LOAD_PARAMS += --appFlags 0x0200

DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000
DEFINES += HAVE_BLE_APDU # basic ledger apdu transport over BLE

DEFINES += HAVE_GLO096
DEFINES += BAGL_WIDTH=128 BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS # long label truncation feature
Expand All @@ -71,7 +71,7 @@ ifeq ($(TARGET_NAME),TARGET_NANOX)
else
# Since we don't have bluetooth in NanoS we set --appFlags to 0
APP_LOAD_PARAMS += --appFlags 0x0000

DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
endif

Expand Down Expand Up @@ -172,4 +172,3 @@ include $(BOLOS_SDK)/Makefile.glyphs
include $(BOLOS_SDK)/Makefile.rules

dep/%.d: %.c Makefile

20 changes: 10 additions & 10 deletions src/aes/aes-cbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ int aes_128_cbc_encrypt(const aes_uchar *key, const aes_uchar *iv, aes_uchar *da
ctx = aes_encrypt_init(key, 16);
if (ctx == NULL)
return -1;
os_memcpy(cbc, iv, AES_BLOCK_SIZE);
memcpy(cbc, iv, AES_BLOCK_SIZE);

blocks = data_len / AES_BLOCK_SIZE;
for (i = 0; i < blocks; i++) {
for (j = 0; j < AES_BLOCK_SIZE; j++)
cbc[j] ^= pos[j];
aes_encrypt(ctx, cbc, cbc);
os_memcpy(pos, cbc, AES_BLOCK_SIZE);
memcpy(pos, cbc, AES_BLOCK_SIZE);
pos += AES_BLOCK_SIZE;
}
aes_encrypt_deinit(ctx);
Expand All @@ -56,14 +56,14 @@ int aes_256_cbc_encrypt(const aes_uchar *key, const aes_uchar *iv, aes_uchar *da
ctx = aes_encrypt_init(key, 32);
if (ctx == NULL)
return -1;
os_memcpy(cbc, iv, AES_BLOCK_SIZE);
memcpy(cbc, iv, AES_BLOCK_SIZE);

blocks = data_len / AES_BLOCK_SIZE;
for (i = 0; i < blocks; i++) {
for (j = 0; j < AES_BLOCK_SIZE; j++)
cbc[j] ^= pos[j];
aes_encrypt(ctx, cbc, cbc);
os_memcpy(pos, cbc, AES_BLOCK_SIZE);
memcpy(pos, cbc, AES_BLOCK_SIZE);
pos += AES_BLOCK_SIZE;
}
aes_encrypt_deinit(ctx);
Expand All @@ -88,15 +88,15 @@ int aes_128_cbc_decrypt(const aes_uchar *key, const aes_uchar *iv, aes_uchar *da
ctx = aes_decrypt_init(key, 16);
if (ctx == NULL)
return -1;
os_memcpy(cbc, iv, AES_BLOCK_SIZE);
memcpy(cbc, iv, AES_BLOCK_SIZE);

blocks = data_len / AES_BLOCK_SIZE;
for (i = 0; i < blocks; i++) {
os_memcpy(tmp, pos, AES_BLOCK_SIZE);
memcpy(tmp, pos, AES_BLOCK_SIZE);
aes_decrypt(ctx, pos, pos);
for (j = 0; j < AES_BLOCK_SIZE; j++)
pos[j] ^= cbc[j];
os_memcpy(cbc, tmp, AES_BLOCK_SIZE);
memcpy(cbc, tmp, AES_BLOCK_SIZE);
pos += AES_BLOCK_SIZE;
}
aes_decrypt_deinit(ctx);
Expand All @@ -113,15 +113,15 @@ int aes_256_cbc_decrypt(const aes_uchar *key, const aes_uchar *iv, aes_uchar *da
ctx = aes_decrypt_init(key, 32);
if (ctx == NULL)
return -1;
os_memcpy(cbc, iv, AES_BLOCK_SIZE);
memcpy(cbc, iv, AES_BLOCK_SIZE);

blocks = data_len / AES_BLOCK_SIZE;
for (i = 0; i < blocks; i++) {
os_memcpy(tmp, pos, AES_BLOCK_SIZE);
memcpy(tmp, pos, AES_BLOCK_SIZE);
aes_decrypt(ctx, pos, pos);
for (j = 0; j < AES_BLOCK_SIZE; j++)
pos[j] ^= cbc[j];
os_memcpy(cbc, tmp, AES_BLOCK_SIZE);
memcpy(cbc, tmp, AES_BLOCK_SIZE);
pos += AES_BLOCK_SIZE;
}
aes_decrypt_deinit(ctx);
Expand Down
6 changes: 3 additions & 3 deletions src/aes/aes-ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void aes_ccm_auth_start(void *aes, size_t M, size_t L, const aes_uchar *n
b[0] = aad_len ? 0x40 : 0 /* Adata */;
b[0] |= (((M - 2) / 2) /* M' */ << 3);
b[0] |= (L - 1) /* L' */;
os_memcpy(&b[1], nonce, 15 - L);
memcpy(&b[1], nonce, 15 - L);
AES_PUT_BE16(&b[AES_BLOCK_SIZE - L], plain_len);

aes_hexdump_key(MSG_EXCESSIVE, "CCM B_0", b, AES_BLOCK_SIZE);
Expand All @@ -44,7 +44,7 @@ static void aes_ccm_auth_start(void *aes, size_t M, size_t L, const aes_uchar *n
return;

AES_PUT_BE16(aad_buf, aad_len);
os_memcpy(aad_buf + 2, aad, aad_len);
memcpy(aad_buf + 2, aad, aad_len);
memset(aad_buf + 2 + aad_len, 0, sizeof(aad_buf) - 2 - aad_len);

xor_aes_block(aad_buf, x);
Expand Down Expand Up @@ -82,7 +82,7 @@ static void aes_ccm_encr_start(size_t L, const aes_uchar *nonce, aes_uchar *a)
{
/* A_i = Flags | Nonce N | Counter i */
a[0] = L - 1; /* Flags = L' */
os_memcpy(&a[1], nonce, 15 - L);
memcpy(&a[1], nonce, 15 - L);
}


Expand Down
2 changes: 1 addition & 1 deletion src/aes/aes-ctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int aes_128_ctr_encrypt(const aes_uchar *key, const aes_uchar *nonce,
ctx = aes_encrypt_init(key, 16);
if (ctx == NULL)
return -1;
os_memcpy(counter, nonce, AES_BLOCK_SIZE);
memcpy(counter, nonce, AES_BLOCK_SIZE);

while (left > 0) {
aes_encrypt(ctx, counter, buf);
Expand Down
14 changes: 7 additions & 7 deletions src/aes/aes-gcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void gf_mult(const aes_uchar *x, const aes_uchar *y, aes_uchar *z)
int i, j;

memset(z, 0, 16); /* Z_0 = 0^128 */
os_memcpy(v, y, 16); /* V_0 = Y */
memcpy(v, y, 16); /* V_0 = Y */

for (i = 0; i < 16; i++) {
for (j = 0; j < 8; j++) {
Expand Down Expand Up @@ -114,13 +114,13 @@ static void ghash(const aes_uchar *h, const aes_uchar *x, size_t xlen, aes_uchar
* multiplication operation for binary Galois (finite) field of
* 2^128 elements */
gf_mult(y, h, tmp);
os_memcpy(y, tmp, 16);
memcpy(y, tmp, 16);
}

if (x + xlen > xpos) {
/* Add zero padded last block */
size_t last = x + xlen - xpos;
os_memcpy(tmp, xpos, last);
memcpy(tmp, xpos, last);
memset(tmp + last, 0, sizeof(tmp) - last);

/* Y_i = (Y^(i-1) XOR X_i) dot H */
Expand All @@ -130,7 +130,7 @@ static void ghash(const aes_uchar *h, const aes_uchar *x, size_t xlen, aes_uchar
* multiplication operation for binary Galois (finite) field of
* 2^128 elements */
gf_mult(y, h, tmp);
os_memcpy(y, tmp, 16);
memcpy(y, tmp, 16);
}

/* Return Y_m */
Expand All @@ -149,7 +149,7 @@ static void aes_gctr(void *aes, const aes_uchar *icb, const aes_uchar *x, size_t

n = xlen / 16;

os_memcpy(cb, icb, AES_BLOCK_SIZE);
memcpy(cb, icb, AES_BLOCK_SIZE);
/* Full blocks */
for (i = 0; i < n; i++) {
aes_encrypt(aes, cb, ypos);
Expand Down Expand Up @@ -191,7 +191,7 @@ static void aes_gcm_prepare_j0(const aes_uchar *iv, size_t iv_len, const aes_uch

if (iv_len == 12) {
/* Prepare block J_0 = IV || 0^31 || 1 [len(IV) = 96] */
os_memcpy(J0, iv, iv_len);
memcpy(J0, iv, iv_len);
memset(J0 + iv_len, 0, AES_BLOCK_SIZE - iv_len);
J0[AES_BLOCK_SIZE - 1] = 0x01;
} else {
Expand All @@ -216,7 +216,7 @@ static void aes_gcm_gctr(void *aes, const aes_uchar *J0, const aes_uchar *in, si
if (len == 0)
return;

os_memcpy(J0inc, J0, AES_BLOCK_SIZE);
memcpy(J0inc, J0, AES_BLOCK_SIZE);
inc32(J0inc);
aes_gctr(aes, J0inc, in, len, out);
}
Expand Down
2 changes: 1 addition & 1 deletion src/aes/aes-internal-dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ void aes_decrypt(void *ctx, const aes_uchar *crypt, aes_uchar *plain)

void aes_decrypt_deinit(void *ctx)
{
os_memset(ctx, 0, AES_PRIV_SIZE);
memset(ctx, 0, AES_PRIV_SIZE);
}
2 changes: 1 addition & 1 deletion src/aes/aes-internal-enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,6 @@ void aes_encrypt(void *ctx, const aes_uchar *plain, aes_uchar *crypt)

void aes_encrypt_deinit(void *ctx)
{
os_memset(ctx, 0, AES_PRIV_SIZE);
memset(ctx, 0, AES_PRIV_SIZE);
}

12 changes: 6 additions & 6 deletions src/aes/aes-unwrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ int aes_unwrap(const aes_uchar *kek, int n, const aes_uchar *cipher, aes_uchar *
void *ctx;

/* 1) Initialize variables. */
os_memcpy(a, cipher, 8);
memcpy(a, cipher, 8);
r = plain;
os_memcpy(r, cipher + 8, 8 * n);
memcpy(r, cipher + 8, 8 * n);

ctx = aes_decrypt_init(kek, 16);
if (ctx == NULL)
Expand All @@ -44,13 +44,13 @@ int aes_unwrap(const aes_uchar *kek, int n, const aes_uchar *cipher, aes_uchar *
for (j = 5; j >= 0; j--) {
r = plain + (n - 1) * 8;
for (i = n; i >= 1; i--) {
os_memcpy(b, a, 8);
memcpy(b, a, 8);
b[7] ^= n * j + i;

os_memcpy(b + 8, r, 8);
memcpy(b + 8, r, 8);
aes_decrypt(ctx, b, b);
os_memcpy(a, b, 8);
os_memcpy(r, b + 8, 8);
memcpy(a, b, 8);
memcpy(r, b + 8, 8);
r -= 8;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/aes/aes-wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int aes_wrap(const aes_uchar *kek, int n, const aes_uchar *plain, aes_uchar *cip

/* 1) Initialize variables. */
memset(a, 0xa6, 8);
os_memcpy(r, plain, 8 * n);
memcpy(r, plain, 8 * n);

ctx = aes_encrypt_init(kek, 16);
if (ctx == NULL)
Expand All @@ -46,12 +46,12 @@ int aes_wrap(const aes_uchar *kek, int n, const aes_uchar *plain, aes_uchar *cip
for (j = 0; j <= 5; j++) {
r = cipher + 8;
for (i = 1; i <= n; i++) {
os_memcpy(b, a, 8);
os_memcpy(b + 8, r, 8);
memcpy(b, a, 8);
memcpy(b + 8, r, 8);
aes_encrypt(ctx, b, b);
os_memcpy(a, b, 8);
memcpy(a, b, 8);
a[7] ^= n * j + i;
os_memcpy(r, b + 8, 8);
memcpy(r, b + 8, 8);
r += 8;
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/authAndSignTxn.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,19 @@ void addRecipientText() {

// Reads a uint8_t from buffer
void read_u8(uint8_t *val, uint8_t **ptr){
os_memmove(val, *ptr, sizeof(uint8_t));
memmove(val, *ptr, sizeof(uint8_t));
*ptr += sizeof(uint8_t);
}

// Reads a uint16_t from buffer
void read_u16(uint16_t *val, uint8_t **ptr){
os_memmove(val, *ptr, sizeof(uint16_t));
memmove(val, *ptr, sizeof(uint16_t));
*ptr += sizeof(uint16_t);
}

// Reads a uint64_t from buffer and put the resulting value on val
void read_u64(uint64_t *val, uint8_t **ptr){
os_memmove(val, *ptr, sizeof(uint64_t));
memmove(val, *ptr, sizeof(uint64_t));
*ptr += sizeof(uint64_t);
}

Expand Down Expand Up @@ -428,9 +428,9 @@ uint8_t parseTxnData() {
if (ptr == 0)
return R_TXN_SIZE_TOO_SMALL;
ptr += 1; //version
os_memmove(&(state.txnAuth.attachmentTempInt64Num1), ptr, sizeof(state.txnAuth.attachmentTempInt64Num1)); // assetID
memmove(&(state.txnAuth.attachmentTempInt64Num1), ptr, sizeof(state.txnAuth.attachmentTempInt64Num1)); // assetID
ptr += sizeof(state.txnAuth.attachmentTempInt64Num1);
os_memmove(&(state.txnAuth.attachmentTempInt64Num2), ptr, sizeof(state.txnAuth.attachmentTempInt64Num2)); // quantity
memmove(&(state.txnAuth.attachmentTempInt64Num2), ptr, sizeof(state.txnAuth.attachmentTempInt64Num2)); // quantity
ptr += sizeof(state.txnAuth.attachmentTempInt64Num2);

if(state.txnAuth.attachmentTempInt64Num1 == TRT_TOKEN){
Expand Down Expand Up @@ -459,11 +459,11 @@ uint8_t parseTxnData() {
return R_TXN_SIZE_TOO_SMALL;
ptr += 1; //version

os_memmove(&(state.txnAuth.attachmentTempInt64Num1), ptr, sizeof(state.txnAuth.attachmentTempInt64Num1)); // assetID
memmove(&(state.txnAuth.attachmentTempInt64Num1), ptr, sizeof(state.txnAuth.attachmentTempInt64Num1)); // assetID
ptr += sizeof(state.txnAuth.attachmentTempInt64Num1);
os_memmove(&(state.txnAuth.attachmentTempInt64Num2), ptr, sizeof(state.txnAuth.attachmentTempInt64Num2)); // quantity
memmove(&(state.txnAuth.attachmentTempInt64Num2), ptr, sizeof(state.txnAuth.attachmentTempInt64Num2)); // quantity
ptr += sizeof(state.txnAuth.attachmentTempInt64Num2);
os_memmove(&(state.txnAuth.attachmentTempInt64Num3), ptr, sizeof(state.txnAuth.attachmentTempInt64Num3)); // price
memmove(&(state.txnAuth.attachmentTempInt64Num3), ptr, sizeof(state.txnAuth.attachmentTempInt64Num3)); // price
ptr += sizeof(state.txnAuth.attachmentTempInt64Num3);

if(state.txnAuth.attachmentTempInt64Num1 == TRT_TOKEN){
Expand Down Expand Up @@ -499,7 +499,7 @@ uint8_t parseTxnData() {
if (ptr == 0)
return R_TXN_SIZE_TOO_SMALL;
ptr += 1; //version
os_memmove(&(state.txnAuth.attachmentTempInt64Num1), ptr, sizeof(state.txnAuth.attachmentTempInt64Num1)); // assetID
memmove(&(state.txnAuth.attachmentTempInt64Num1), ptr, sizeof(state.txnAuth.attachmentTempInt64Num1)); // assetID
ptr += sizeof(state.txnAuth.attachmentTempInt64Num1);

// Window 1 is order ID
Expand Down Expand Up @@ -548,7 +548,7 @@ uint8_t parseReferencedTxn() {
void addToReadBuffer(const uint8_t * const newData, const uint8_t numBytes) {
cx_hash(&state.txnAuth.hashstate.header, 0, newData, numBytes, 0, 0);

os_memcpy(state.txnAuth.readBuffer, newData, numBytes);
memcpy(state.txnAuth.readBuffer, newData, numBytes);
state.txnAuth.readBufferReadOffset = 0;
state.txnAuth.readBufferEndPos = numBytes;
}
Expand All @@ -561,7 +561,7 @@ void addToReadBuffer(const uint8_t * const newData, const uint8_t numBytes) {

uint8_t signTxn(const uint8_t * const dataBuffer, const uint8_t dataLength, uint8_t * const destBuffer, uint16_t * const outException) {

uint8_t sharedKey[32]; os_memset(sharedKey, 0, sizeof(sharedKey));
uint8_t sharedKey[32]; memset(sharedKey, 0, sizeof(sharedKey));
uint8_t ret = 0;

if (R_SUCCESS != (ret = burst_keys(dataBuffer, dataLength, NULL, NULL, sharedKey, outException))) {
Expand All @@ -574,7 +574,7 @@ uint8_t signTxn(const uint8_t * const dataBuffer, const uint8_t dataLength, uint
cx_hash(&state.txnAuth.hashstate.header, CX_LAST, NULL, 0, messageSha256, sizeof(messageSha256));

sign_msg(sharedKey, messageSha256, destBuffer); //is a void function, no ret value to check against
//os_memcpy(destBuffer+32, messageSha256, 32);
//memcpy(destBuffer+32, messageSha256, 32);

//clear
explicit_bzero(messageSha256, sizeof(messageSha256));
Expand Down
Loading

0 comments on commit b19e8cd

Please sign in to comment.