Skip to content

Commit 57986fd

Browse files
committed
running flipper fmt
1 parent f3280c2 commit 57986fd

File tree

158 files changed

+20053
-16321
lines changed

Some content is hidden

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

158 files changed

+20053
-16321
lines changed

crypto/Makefile

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ Distibuted under MIT License.
4040
- SHA1/SHA2: http://www.aarongifford.com/computers/sha.html
4141
- SHA3: https://github.com/rhash/RHash
4242
- Curve25519: https://github.com/agl/curve25519-donna
43-
- Ed25519: https://github.com/floodyberry/ed25519-donna
43+
- Ed25519: https://github.com/floodyberry/ed25519_donna
4444
- Chacha20: https://github.com/wg/c20p1305
4545
- Poly1305: https://github.com/floodyberry/poly1305-donna

crypto/address.c

Lines changed: 49 additions & 53 deletions
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

Lines changed: 3 additions & 4 deletions
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)