diff --git a/Makefile b/Makefile index 2149944..2da4af4 100755 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 @@ -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 @@ -172,4 +172,3 @@ include $(BOLOS_SDK)/Makefile.glyphs include $(BOLOS_SDK)/Makefile.rules dep/%.d: %.c Makefile - diff --git a/src/aes/aes-cbc.c b/src/aes/aes-cbc.c index ed3ac98..5d63cb0 100644 --- a/src/aes/aes-cbc.c +++ b/src/aes/aes-cbc.c @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/src/aes/aes-ccm.c b/src/aes/aes-ccm.c index dff35f3..99c4916 100644 --- a/src/aes/aes-ccm.c +++ b/src/aes/aes-ccm.c @@ -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); @@ -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); @@ -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); } diff --git a/src/aes/aes-ctr.c b/src/aes/aes-ctr.c index fe24f7e..866ee34 100644 --- a/src/aes/aes-ctr.c +++ b/src/aes/aes-ctr.c @@ -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); diff --git a/src/aes/aes-gcm.c b/src/aes/aes-gcm.c index 7447c01..73f7b59 100644 --- a/src/aes/aes-gcm.c +++ b/src/aes/aes-gcm.c @@ -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++) { @@ -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 */ @@ -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 */ @@ -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); @@ -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 { @@ -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); } diff --git a/src/aes/aes-internal-dec.c b/src/aes/aes-internal-dec.c index 6153c58..1d5af1e 100644 --- a/src/aes/aes-internal-dec.c +++ b/src/aes/aes-internal-dec.c @@ -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); } diff --git a/src/aes/aes-internal-enc.c b/src/aes/aes-internal-enc.c index 0701c03..76a44b0 100644 --- a/src/aes/aes-internal-enc.c +++ b/src/aes/aes-internal-enc.c @@ -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); } diff --git a/src/aes/aes-unwrap.c b/src/aes/aes-unwrap.c index 95aeca8..3f0dc3d 100644 --- a/src/aes/aes-unwrap.c +++ b/src/aes/aes-unwrap.c @@ -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) @@ -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; } } diff --git a/src/aes/aes-wrap.c b/src/aes/aes-wrap.c index 80b32d9..4c5a98e 100644 --- a/src/aes/aes-wrap.c +++ b/src/aes/aes-wrap.c @@ -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) @@ -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; } } diff --git a/src/authAndSignTxn.c b/src/authAndSignTxn.c index d67b2e7..c245bf5 100644 --- a/src/authAndSignTxn.c +++ b/src/authAndSignTxn.c @@ -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); } @@ -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){ @@ -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){ @@ -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 @@ -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; } @@ -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))) { @@ -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)); diff --git a/src/burst.c b/src/burst.c index 7c92877..9a64e50 100644 --- a/src/burst.c +++ b/src/burst.c @@ -39,7 +39,7 @@ states_t state; void sha256TwoBuffers(const uint8_t * const bufferTohash1, const uint16_t sizeOfBuffer1, const uint8_t * const bufferTohash2, const uint16_t sizeOfBuffer2, uint8_t * const output) { cx_sha256_t shaContext; - os_memset(output, 0, 32); + memset(output, 0, 32); cx_sha256_init(&shaContext); //return value has no info cx_hash(&shaContext.header, 0, bufferTohash1, sizeOfBuffer1, output, 32); @@ -62,9 +62,9 @@ void sha256Buffer(const uint8_t * const bufferTohash, const uint16_t sizeOfBuffe //@param out: sig should point to 64 bytes allocated to hold the signiture of the message void sign_msg(uint8_t * const sharedKey, const uint8_t * const msgSha256, uint8_t * const sig) { - uint8_t x[32]; os_memset(x, 0, sizeof(x)); - uint8_t y[32]; os_memset(y, 0, sizeof(y)); - uint8_t h[32]; os_memset(h, 0, sizeof(h)); + uint8_t x[32]; memset(x, 0, sizeof(x)); + uint8_t y[32]; memset(y, 0, sizeof(y)); + uint8_t h[32]; memset(h, 0, sizeof(h)); // Get x = hash(m, s) cx_sha256_init(&state.txnAuth.hashstate); @@ -80,7 +80,7 @@ void sign_msg(uint8_t * const sharedKey, const uint8_t * const msgSha256, uint8_ cx_hash(&state.txnAuth.hashstate.header, CX_LAST, y, 32, h, 32); // copy h first because sign25519 screws with parameters - os_memcpy(sig+32, h, 32); + memcpy(sig+32, h, 32); sign25519(sig, h, x, sharedKey); // clear sensitive data @@ -107,15 +107,15 @@ uint8_t burst_keys(const uint8_t * const dataBuffer, const uint8_t dataLength, u uint32_t pathPrefix[] = PATH_PREFIX; //defined in Makefile - uint8_t publicKey[32]; os_memset(publicKey, 0, sizeof(publicKey)); - uint8_t privKey[32]; os_memset(privKey, 0, sizeof(privKey)); + uint8_t publicKey[32]; memset(publicKey, 0, sizeof(publicKey)); + uint8_t privKey[32]; memset(privKey, 0, sizeof(privKey)); if(dataLength < 3) return R_NOT_ENOUGH_DERIVATION_INDEXES; // BURST keypath of 44'/30'/account'/change'/index' - uint32_t derivationPath[5]; os_memset(derivationPath, 0, sizeof(derivationPath)); - os_memmove(derivationPath, pathPrefix, 2 * sizeof(uint32_t)); + uint32_t derivationPath[5]; memset(derivationPath, 0, sizeof(derivationPath)); + memmove(derivationPath, pathPrefix, 2 * sizeof(uint32_t)); derivationPath[2] = dataBuffer[0] | 0x80000000; // account derivationPath[3] = dataBuffer[1] | 0x80000000; // change derivationPath[4] = dataBuffer[2] | 0x80000000; // index @@ -129,10 +129,10 @@ uint8_t burst_keys(const uint8_t * const dataBuffer, const uint8_t dataLength, u } if (0 != publicKeyOut) { - os_memmove(publicKeyOut, publicKey, 32); + memmove(publicKeyOut, publicKey, 32); } if (0 != privKeyOut) { - os_memmove(privKeyOut, privKey, 32); + memmove(privKeyOut, privKey, 32); } } CATCH_OTHER(exception) { diff --git a/src/burst.h b/src/burst.h index 783227f..9fafdaf 100644 --- a/src/burst.h +++ b/src/burst.h @@ -15,6 +15,9 @@ * limitations under the License. ********************************************************************************/ +#include "ux.h" +#include "cx.h" +#include "os.h" uint64_t public_key_to_id(const uint8_t * const publicKey); @@ -48,7 +51,7 @@ typedef struct { uint64_t fee; //What it says it is int32_t attachmentTempInt32Num1, attachmentTempInt32Num2; //Different attachments parse in different ways, they all need space in state, so this is how it's defined - int64_t attachmentTempInt64Num1, attachmentTempInt64Num2, attachmentTempInt64Num3; + int64_t attachmentTempInt64Num1, attachmentTempInt64Num2, attachmentTempInt64Num3; char feeText[21]; //9,223,372,036,854,775,807 is the biggest number you can hold in uint64 + the dot + null terminator means the longest text is 20 char txnTypeText[60]; //Aproximation of size diff --git a/src/curve25519_i64.c b/src/curve25519_i64.c index d5005e7..c1caeb0 100644 --- a/src/curve25519_i64.c +++ b/src/curve25519_i64.c @@ -6,6 +6,7 @@ */ #include +#include #include "curve25519_i64.h" @@ -137,7 +138,7 @@ static dstptr egcd32(dstptr x, dstptr y, dstptr a, dstptr b) { if (bn == 0) return x; mula32(y, x, temp, qn, -1); - + qn = an - bn + 1; divmod(temp, a, an, b, bn); an = numsize(a, an); @@ -565,21 +566,21 @@ static inline void x_to_y2(i25519 t, i25519 y2, const i25519 x) { void core25519(k25519 Px, k25519 s, const k25519 k, const k25519 Gx) { i25519 dx, x[2], z[2], t1, t2, t3, t4; unsigned i, j; - + /* unpack the base */ if (Gx) unpack25519(dx, Gx); else set25519(dx, 9); - + /* 0G = point-at-infinity */ set25519(x[0], 1); set25519(z[0], 0); - + /* 1G = G */ cpy25519(x[1], dx); set25519(z[1], 1); - + for (i = 32; i--; ) { for (j = 8; j--; ) { /* swap arguments depending on bit */ @@ -589,7 +590,7 @@ void core25519(k25519 Px, k25519 s, const k25519 k, const k25519 Gx) { int32_t *const az = z[bit0]; int32_t *const bx = x[bit1]; int32_t *const bz = z[bit1]; - + /* a' = a + b */ /* b' = 2 b */ mont_prep(t1, t2, ax, az); @@ -598,11 +599,11 @@ void core25519(k25519 Px, k25519 s, const k25519 k, const k25519 Gx) { mont_dbl(t1, t2, t3, t4, bx, bz); } } - + recip25519(t1, z[0], 0); mul25519(dx, x[0], t1); pack25519(dx, Px); - + /* calculate s such that s abs(P) = G .. assumes G is std base point */ if (s) { x_to_y2(t2, t1, dx); /* t1 = Py^2 */ @@ -620,11 +621,11 @@ void core25519(k25519 Px, k25519 s, const k25519 k, const k25519 Gx) { cpy32(s, k); else /* sign is -1, so negate */ mula_small(s, order_times_8, 0, k, 32, -1); - + /* reduce s mod q * (is this needed? do it just in case, it's fast anyway) */ divmod((dstptr) t1, s, 32, order25519, 32); - + /* take reciprocal of s mod q */ cpy32((dstptr) t1, order25519); cpy32(s, egcd32((dstptr) x, (dstptr) z, s, (dstptr) t1)); @@ -655,18 +656,18 @@ int sign25519(k25519 v, const k25519 h, const priv25519 x, const spriv25519 s) { unsigned w; int i; - os_memset(tmp, 0, 32); + memset(tmp, 0, 32); divmod(tmp, h, 32, order25519, 32); - os_memset(tmp, 0, 32); + memset(tmp, 0, 32); divmod(tmp, x, 32, order25519, 32); - os_memset(v, 0, sizeof(v)); + memset(v, 0, sizeof(v)); i = mula_small(v, x, 0, h, 32, -1); mula_small(v, v, 0, order25519, 32, (15-(int8_t) v[31])/16); - os_memset(tmp, 0, sizeof(tmp)); + memset(tmp, 0, sizeof(tmp)); mula32(tmp, v, s, 32, 1); divmod(tmp+32, tmp, 64, order25519, 32); @@ -683,17 +684,17 @@ void verify25519(pub25519 Y, const k25519 v, const k25519 h, const pub25519 P) { k25519 d; i25519 p[2], s[2], yx[3], yz[3], t1[3], t2[3]; unsigned vi = 0, hi = 0, di = 0, nvh, i, j, k; - + /* set p[0] to G and p[1] to P */ - + set25519(p[0], 9); unpack25519(p[1], P); - + /* set s[0] to P+G and s[1] to P-G */ - + /* s[0] = (Py^2 + Gy^2 - 2 Py Gy)/(Px - Gx)^2 - Px - Gx - 486662 */ /* s[1] = (Py^2 + Gy^2 + 2 Py Gy)/(Px - Gx)^2 - Px - Gx - 486662 */ - + x_to_y2(t1[0], t2[0], p[1]); /* t2[0] = Py^2 */ sqrt25519(t1[0], t2[0]); /* t1[0] = Py or -Py */ j = is_negative(t1[0]); /* ... check which */ @@ -713,8 +714,8 @@ void verify25519(pub25519 Y, const k25519 v, const k25519 h, const pub25519 P) { s[1][0] -= 9 + 486662; /* s[1] = X(P-G) */ mul25519small(s[0], s[0], 1); /* reduce s[0] */ mul25519small(s[1], s[1], 1); /* reduce s[1] */ - - + + /* prepare the chain */ for (i = 0; i < 32; i++) { vi = (vi >> 8) ^ v[i] ^ (v[i] << 1); @@ -730,9 +731,9 @@ void verify25519(pub25519 Y, const k25519 v, const k25519 h, const pub25519 P) { di ^= nvh & (di & 0x40) << 1; d[i] = di; } - + di = ((nvh & (di & 0x80) << 1) ^ vi) >> 8; - + /* initialize state */ set25519(yx[0], 1); cpy25519(yx[1], p[di]); @@ -740,43 +741,43 @@ void verify25519(pub25519 Y, const k25519 v, const k25519 h, const pub25519 P) { set25519(yz[0], 0); set25519(yz[1], 1); set25519(yz[2], 1); - + /* y[0] is (even)P + (even)G * y[1] is (even)P + (odd)G if current d-bit is 0 * y[1] is (odd)P + (even)G if current d-bit is 1 * y[2] is (odd)P + (odd)G */ - + vi = 0; hi = 0; - + /* and go for it! */ for (i = 32; i--; ) { vi = (vi << 8) | v[i]; hi = (hi << 8) | h[i]; di = (di << 8) | d[i]; - + for (j = 8; j--; ) { mont_prep(t1[0], t2[0], yx[0], yz[0]); mont_prep(t1[1], t2[1], yx[1], yz[1]); mont_prep(t1[2], t2[2], yx[2], yz[2]); - + k = ((vi ^ vi >> 1) >> j & 1) + ((hi ^ hi >> 1) >> j & 1); mont_dbl(yx[2], yz[2], t1[k], t2[k], yx[0], yz[0]); - + k = (di >> j & 2) ^ ((di >> j & 1) << 1); mont_add(t1[1], t2[1], t1[k], t2[k], yx[1], yz[1], p[di >> j & 1]); - + mont_add(t1[2], t2[2], t1[0], t2[0], yx[2], yz[2], s[((vi ^ hi) >> j & 2) >> 1]); } } - + k = (vi & 1) + (hi & 1); recip25519(t1[0], yz[k], 0); mul25519(t1[1], yx[k], t1[0]); - + pack25519(t1[1], Y); -} \ No newline at end of file +} diff --git a/src/getPublicKey.c b/src/getPublicKey.c index 0b6e112..3225ae1 100644 --- a/src/getPublicKey.c +++ b/src/getPublicKey.c @@ -54,7 +54,7 @@ void getPublicKeyHandlerHelper(const uint8_t p1, const uint8_t p2, const uint8_t if (R_SUCCESS == ret) { - os_memmove(G_io_apdu_buffer + *tx, publicKey, sizeof(publicKey)); + memmove(G_io_apdu_buffer + *tx, publicKey, sizeof(publicKey)); *tx += sizeof(publicKey); } else if (R_KEY_DERIVATION_EX == ret) { diff --git a/src/getVersion.c b/src/getVersion.c index 2ee03ae..742ccbd 100644 --- a/src/getVersion.c +++ b/src/getVersion.c @@ -34,7 +34,7 @@ void getVersionHandler(const uint8_t p1, const uint8_t p2, const uint8_t * const G_io_apdu_buffer[(*tx)++] = APPVERSION_P; G_io_apdu_buffer[(*tx)++] = VERSION_FLAGS; - os_memmove(G_io_apdu_buffer + (*tx), BURST_SPECIAL_IDENTIFIER, BURST_SPECIAL_IDENTIFIER_LEN); + memmove(G_io_apdu_buffer + (*tx), BURST_SPECIAL_IDENTIFIER, BURST_SPECIAL_IDENTIFIER_LEN); *tx += BURST_SPECIAL_IDENTIFIER_LEN; G_io_apdu_buffer[(*tx)++] = 0x90; diff --git a/src/reedSolomon.c b/src/reedSolomon.c index c51719e..2074d28 100644 --- a/src/reedSolomon.c +++ b/src/reedSolomon.c @@ -16,7 +16,7 @@ ********************************************************************************/ #include - +#include #define BASE_32_LENGTH 13 #define BASE_10_LENGTH 20 @@ -43,7 +43,7 @@ uint8_t gmult(const uint8_t a, const uint8_t b) { void reedSolomonEncode(uint64_t inp, char * const output) { uint8_t plain_string_32[sizeof(initial_codeword)]; - os_memset(plain_string_32, 0, sizeof(initial_codeword)); + memset(plain_string_32, 0, sizeof(initial_codeword)); uint8_t index = 0; @@ -56,7 +56,7 @@ void reedSolomonEncode(uint64_t inp, char * const output) { uint8_t p[] = {0, 0, 0, 0}; for (int8_t i = BASE_32_LENGTH - 1; i >= 0; i--) { - + uint8_t fb = plain_string_32[i] ^ p[3]; p[3] = p[2] ^ gmult(30, fb); p[2] = p[1] ^ gmult(6, fb); @@ -64,7 +64,7 @@ void reedSolomonEncode(uint64_t inp, char * const output) { p[0] = gmult(17, fb); } - os_memcpy(plain_string_32 + BASE_32_LENGTH, p, sizeof(initial_codeword) - BASE_32_LENGTH); + memcpy(plain_string_32 + BASE_32_LENGTH, p, sizeof(initial_codeword) - BASE_32_LENGTH); uint8_t stringIndex = 0; @@ -80,4 +80,3 @@ void reedSolomonEncode(uint64_t inp, char * const output) { output[stringIndex++] = 0; } - diff --git a/src/showAddress.c b/src/showAddress.c index 2d317ed..a9f7c5a 100644 --- a/src/showAddress.c +++ b/src/showAddress.c @@ -78,12 +78,12 @@ void showAddressHandlerHelper(const uint8_t p1, const uint8_t p2, const uint8_t uint16_t exception = 0; - uint8_t publicKey[32]; os_memset(publicKey, 0, sizeof(publicKey)); + uint8_t publicKey[32]; memset(publicKey, 0, sizeof(publicKey)); uint8_t ret = burst_keys(dataBuffer, dataLength, 0, publicKey, 0, &exception); if (R_SUCCESS == ret) { - os_memset(screenContent, 0, sizeof(screenContent)); + memset(screenContent, 0, sizeof(screenContent)); snprintf(screenContent, sizeof(screenContent), APP_PREFIX); reedSolomonEncode(public_key_to_id(publicKey), screenContent + strlen(screenContent)); showScreen(); @@ -92,7 +92,7 @@ void showAddressHandlerHelper(const uint8_t p1, const uint8_t p2, const uint8_t if((p1&P1_SHOW_ADDRES_RETURN_KEY) == P1_SHOW_ADDRES_RETURN_KEY){ // Also return the public key if asked - os_memmove(G_io_apdu_buffer + *tx, publicKey, sizeof(publicKey)); + memmove(G_io_apdu_buffer + *tx, publicKey, sizeof(publicKey)); *tx += sizeof(publicKey); } } else { diff --git a/unused/curveConversion.c b/unused/curveConversion.c index c8ed8e1..27b03d3 100644 --- a/unused/curveConversion.c +++ b/unused/curveConversion.c @@ -17,7 +17,7 @@ extern const uint8_t f25519_one[F25519_SIZE]; /* Copy two points */ static inline void f25519_copy(uint8_t *x, const uint8_t *a) { - os_memcpy(x, a, F25519_SIZE); + memcpy(x, a, F25519_SIZE); }