Skip to content

Commit 642455f

Browse files
authored
Merge pull request #3 from xtruan/develop
Wallet storage, code formatting, & touch ups
2 parents 87cf393 + 8957be9 commit 642455f

File tree

170 files changed

+20498
-17769
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+20498
-17769
lines changed

README.md

+20-10
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ The goal of this project is to see how much crypto functionality can be brought
1010
## How to install on Flipper Zero
1111
- If you do not have one, download a Flipper Zero firmware to get the `fbt` build tool
1212
- Plug your Flipper Zero in via USB
13-
- Copy the contents of this folder into the applications_user folder of your firmware
14-
- Modify the `site_scons/cc.scons` file in the Flipper Zero firmware to remove the `"-Wdouble-promotion"` warning and add the `"-Os"` flag
13+
- Copy the contents of this folder into the `applications_user` folder of your firmware
14+
- Modify the `site_scons/cc.scons` file in the Flipper Zero firmware to add the `"-Os"` flag
1515

1616
Then run the command:
1717
```
18-
.\fbt COMPACT=1 DEBUG=0 launch_app APPSRC=applications_user/FlipBIP
18+
./fbt COMPACT=1 DEBUG=0 launch_app APPSRC=applications_user/FlipBIP
1919
```
2020
The application will be compiled and copied onto your device
2121

@@ -34,16 +34,26 @@ The application will be compiled and copied onto your device
3434
- Generation of offline `m/44'/0'/0'/0` BTC wallet
3535
- Generation of offline `m/44'/60'/0'/0` ETH wallet (coded from the $SPORK Castle of ETHDenver 2023!)
3636
- Similar features to: https://iancoleman.io/bip39/
37+
- Saving wallets to SD card
38+
- Wallets are saved to SD card upon creation in `apps_data/flipbip`
39+
- NOTE: `apps_data` folder must already exist on SD card!
40+
- Saved wallets can be viewed between app runs
41+
- Wallets are encrypted with a randomly generated key, and that key is also encrypted
42+
- `.flipbip.dat` and `.flipbip.key` files are both required to be in `apps_data/flipbip`
43+
- Backups of both these files `.flipbip.dat.bak` and `.flipbip.key.bak` are also maintained
44+
- If you want to externally back up your wallet, I recommend copying all these files, and storing the `key` and `dat` files seperately
45+
- NOTE: The wallets should be decently tough to crack off of a Flipper, however any Flipper with the app installed can load a wallet in the `apps_data/flipbip` directory if both the `key` and `dat` file are present
3746

3847
### Work in Progress
3948

40-
- Support for BIP39 passphrase
41-
- Currently blank
42-
- Support for more custom BIP32 wallet paths
43-
- Currently hardcoded to `m/44'/0'/0'/0` or `m/44'/60'/0'/0`
49+
- More coin types
50+
- Support for more custom BIP32 wallet paths
51+
- Currently hardcoded to `m/44'/0'/0'/0` and `m/44'/60'/0'/0`
4452

4553
### (FAR) Future
4654

47-
- More coin types
48-
- Saving wallets to disk
49-
- USB/Bluetooth wallet functionality
55+
- Custom wallet security
56+
- User specified password
57+
- Support for BIP39 passphrase
58+
- Currently blank
59+
- USB/Bluetooth wallet functionality

application.fam

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ App(
1313
fap_icon_assets="icons",
1414
fap_category="Misc",
1515
fap_description="Crypto toolkit for Flipper",
16-
fap_author="Struan Clark",
16+
fap_author="Struan Clark (xtruan)",
1717
fap_weburl="https://github.com/xtruan/FlipBIP",
1818
)

crypto/.gitignore

-9
This file was deleted.

crypto/.gitrepo

-12
This file was deleted.

crypto/Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ SRCS += sha2.c
9797
SRCS += sha3.c
9898
SRCS += hasher.c
9999
SRCS += aes/aescrypt.c aes/aeskey.c aes/aestab.c aes/aes_modes.c
100-
SRCS += ed25519-donna/curve25519-donna-32bit.c ed25519-donna/curve25519-donna-helpers.c ed25519-donna/modm-donna-32bit.c
101-
SRCS += ed25519-donna/ed25519-donna-basepoint-table.c ed25519-donna/ed25519-donna-32bit-tables.c ed25519-donna/ed25519-donna-impl-base.c
102-
SRCS += ed25519-donna/ed25519.c ed25519-donna/curve25519-donna-scalarmult-base.c ed25519-donna/ed25519-sha3.c ed25519-donna/ed25519-keccak.c
100+
SRCS += ed25519_donna/curve25519-donna-32bit.c ed25519_donna/curve25519-donna-helpers.c ed25519_donna/modm-donna-32bit.c
101+
SRCS += ed25519_donna/ed25519_donna-basepoint-table.c ed25519_donna/ed25519_donna-32bit-tables.c ed25519_donna/ed25519_donna-impl-base.c
102+
SRCS += ed25519_donna/ed25519.c ed25519_donna/curve25519-donna-scalarmult-base.c ed25519_donna/ed25519-sha3.c ed25519_donna/ed25519-keccak.c
103103
SRCS += monero/base58.c
104104
SRCS += monero/serialize.c
105105
SRCS += monero/xmr.c
@@ -177,7 +177,7 @@ secp256k1-zkp.o:
177177
$(CC) $(CFLAGS) -Wno-unused-function $(ZKP_CFLAGS) -fPIC -I$(ZKP_PATH) -I$(ZKP_PATH)/src -c $(ZKP_PATH)/src/secp256k1.c -o secp256k1-zkp.o
178178

179179
clean:
180-
rm -f *.o aes/*.o chacha20poly1305/*.o ed25519-donna/*.o monero/*.o
180+
rm -f *.o aes/*.o chacha20poly1305/*.o ed25519_donna/*.o monero/*.o
181181
rm -f tests/*.o tests/test_check tests/test_speed tests/test_openssl tests/libtrezor-crypto.so tests/aestst
182182
rm -f tools/*.o tools/xpubaddrgen tools/mktable tools/bip39bruteforce
183183
rm -f fuzzer/*.o fuzzer/fuzzer

crypto/README.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# trezor-crypto
22

3-
[![Build Status](https://travis-ci.org/trezor/trezor-crypto.svg?branch=master)](https://travis-ci.org/trezor/trezor-crypto) [![gitter](https://badges.gitter.im/trezor/community.svg)](https://gitter.im/trezor/community)
4-
53
Heavily optimized cryptography algorithms for embedded devices.
64

75
These include:
@@ -40,6 +38,17 @@ Distibuted under MIT License.
4038
- SHA1/SHA2: http://www.aarongifford.com/computers/sha.html
4139
- SHA3: https://github.com/rhash/RHash
4240
- Curve25519: https://github.com/agl/curve25519-donna
43-
- Ed25519: https://github.com/floodyberry/ed25519-donna
41+
- Ed25519: https://github.com/floodyberry/ed25519_donna
4442
- Chacha20: https://github.com/wg/c20p1305
4543
- Poly1305: https://github.com/floodyberry/poly1305-donna
44+
45+
## Repo source:
46+
47+
```
48+
remote = git+ssh://git@github.com/trezor/trezor-crypto
49+
branch = master
50+
commit = 915b3dbbbf58c262865647728a3463b8785fc965
51+
parent = 6ad3294f31a1e7484b43c104ff2880b965198cad
52+
method = rebase
53+
cmdver = 0.4.0
54+
```

crypto/address.c

+49-53
Original file line numberDiff line numberDiff line change
@@ -25,70 +25,66 @@
2525
#include "bignum.h"
2626

2727
size_t address_prefix_bytes_len(uint32_t address_type) {
28-
if (address_type <= 0xFF) return 1;
29-
if (address_type <= 0xFFFF) return 2;
30-
if (address_type <= 0xFFFFFF) return 3;
31-
return 4;
28+
if(address_type <= 0xFF) return 1;
29+
if(address_type <= 0xFFFF) return 2;
30+
if(address_type <= 0xFFFFFF) return 3;
31+
return 4;
3232
}
3333

34-
void address_write_prefix_bytes(uint32_t address_type, uint8_t *out) {
35-
if (address_type > 0xFFFFFF) *(out++) = address_type >> 24;
36-
if (address_type > 0xFFFF) *(out++) = (address_type >> 16) & 0xFF;
37-
if (address_type > 0xFF) *(out++) = (address_type >> 8) & 0xFF;
38-
*(out++) = address_type & 0xFF;
34+
void address_write_prefix_bytes(uint32_t address_type, uint8_t* out) {
35+
if(address_type > 0xFFFFFF) *(out++) = address_type >> 24;
36+
if(address_type > 0xFFFF) *(out++) = (address_type >> 16) & 0xFF;
37+
if(address_type > 0xFF) *(out++) = (address_type >> 8) & 0xFF;
38+
*(out++) = address_type & 0xFF;
3939
}
4040

41-
bool address_check_prefix(const uint8_t *addr, uint32_t address_type) {
42-
if (address_type <= 0xFF) {
43-
return address_type == (uint32_t)(addr[0]);
44-
}
45-
if (address_type <= 0xFFFF) {
46-
return address_type == (((uint32_t)addr[0] << 8) | ((uint32_t)addr[1]));
47-
}
48-
if (address_type <= 0xFFFFFF) {
49-
return address_type == (((uint32_t)addr[0] << 16) |
50-
((uint32_t)addr[1] << 8) | ((uint32_t)addr[2]));
51-
}
52-
return address_type ==
53-
(((uint32_t)addr[0] << 24) | ((uint32_t)addr[1] << 16) |
54-
((uint32_t)addr[2] << 8) | ((uint32_t)addr[3]));
41+
bool address_check_prefix(const uint8_t* addr, uint32_t address_type) {
42+
if(address_type <= 0xFF) {
43+
return address_type == (uint32_t)(addr[0]);
44+
}
45+
if(address_type <= 0xFFFF) {
46+
return address_type == (((uint32_t)addr[0] << 8) | ((uint32_t)addr[1]));
47+
}
48+
if(address_type <= 0xFFFFFF) {
49+
return address_type ==
50+
(((uint32_t)addr[0] << 16) | ((uint32_t)addr[1] << 8) | ((uint32_t)addr[2]));
51+
}
52+
return address_type == (((uint32_t)addr[0] << 24) | ((uint32_t)addr[1] << 16) |
53+
((uint32_t)addr[2] << 8) | ((uint32_t)addr[3]));
5554
}
5655

5756
#if USE_ETHEREUM
5857
#include "sha3.h"
5958

60-
void ethereum_address_checksum(const uint8_t *addr, char *address, bool rskip60,
61-
uint64_t chain_id) {
62-
const char *hex = "0123456789abcdef";
63-
address[0] = '0';
64-
address[1] = 'x';
65-
for (int i = 0; i < 20; i++) {
66-
address[2 + i * 2] = hex[(addr[i] >> 4) & 0xF];
67-
address[2 + i * 2 + 1] = hex[addr[i] & 0xF];
68-
}
69-
address[42] = 0;
70-
71-
SHA3_CTX ctx = {0};
72-
uint8_t hash[32] = {0};
73-
keccak_256_Init(&ctx);
74-
if (rskip60) {
75-
char prefix[16] = {0};
76-
int prefix_size = bn_format_uint64(chain_id, NULL, "0x", 0, 0, false, 0,
77-
prefix, sizeof(prefix));
78-
keccak_Update(&ctx, (const uint8_t *)prefix, prefix_size);
79-
}
80-
keccak_Update(&ctx, (const uint8_t *)(address + 2), 40);
81-
keccak_Final(&ctx, hash);
59+
void ethereum_address_checksum(const uint8_t* addr, char* address, bool rskip60, uint64_t chain_id) {
60+
const char* hex = "0123456789abcdef";
61+
address[0] = '0';
62+
address[1] = 'x';
63+
for(int i = 0; i < 20; i++) {
64+
address[2 + i * 2] = hex[(addr[i] >> 4) & 0xF];
65+
address[2 + i * 2 + 1] = hex[addr[i] & 0xF];
66+
}
67+
address[42] = 0;
8268

83-
for (int i = 0; i < 20; i++) {
84-
if ((hash[i] & 0x80) && address[2 + i * 2] >= 'a' &&
85-
address[2 + i * 2] <= 'f') {
86-
address[2 + i * 2] -= 0x20;
69+
SHA3_CTX ctx = {0};
70+
uint8_t hash[32] = {0};
71+
keccak_256_Init(&ctx);
72+
if(rskip60) {
73+
char prefix[16] = {0};
74+
int prefix_size =
75+
bn_format_uint64(chain_id, NULL, "0x", 0, 0, false, 0, prefix, sizeof(prefix));
76+
keccak_Update(&ctx, (const uint8_t*)prefix, prefix_size);
8777
}
88-
if ((hash[i] & 0x08) && address[2 + i * 2 + 1] >= 'a' &&
89-
address[2 + i * 2 + 1] <= 'f') {
90-
address[2 + i * 2 + 1] -= 0x20;
78+
keccak_Update(&ctx, (const uint8_t*)(address + 2), 40);
79+
keccak_Final(&ctx, hash);
80+
81+
for(int i = 0; i < 20; i++) {
82+
if((hash[i] & 0x80) && address[2 + i * 2] >= 'a' && address[2 + i * 2] <= 'f') {
83+
address[2 + i * 2] -= 0x20;
84+
}
85+
if((hash[i] & 0x08) && address[2 + i * 2 + 1] >= 'a' && address[2 + i * 2 + 1] <= 'f') {
86+
address[2 + i * 2 + 1] -= 0x20;
87+
}
9188
}
92-
}
9389
}
9490
#endif

crypto/address.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@
3030
#include "options.h"
3131

3232
size_t address_prefix_bytes_len(uint32_t address_type);
33-
void address_write_prefix_bytes(uint32_t address_type, uint8_t *out);
34-
bool address_check_prefix(const uint8_t *addr, uint32_t address_type);
33+
void address_write_prefix_bytes(uint32_t address_type, uint8_t* out);
34+
bool address_check_prefix(const uint8_t* addr, uint32_t address_type);
3535
#if USE_ETHEREUM
36-
void ethereum_address_checksum(const uint8_t *addr, char *address, bool rskip60,
37-
uint64_t chain_id);
36+
void ethereum_address_checksum(const uint8_t* addr, char* address, bool rskip60, uint64_t chain_id);
3837
#endif
3938

4039
#endif

0 commit comments

Comments
 (0)