Skip to content

Commit ff298d6

Browse files
authored
release: 2.0.1 (#67)
1 parent 6fe0df0 commit ff298d6

File tree

7 files changed

+264
-86
lines changed

7 files changed

+264
-86
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [2.0.1] - 2020-02-08
9+
10+
### Changed
11+
- use optimized Base58 implementation from Ledger BTC app ([#66])
12+
813
## [2.0.0] - 2020-02-05
914

1015
### Added
@@ -32,3 +37,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3237
[#53]: https://github.com/ArkEcosystem/ledger/pull/53
3338
[#55]: https://github.com/ArkEcosystem/ledger/pull/53
3439
[2.0.0]: https://github.com/ArkEcosystem/ledger/compare/master...2.0.0
40+
[#66]: https://github.com/ArkEcosystem/ledger/pull/66
41+
[2.0.1]: https://github.com/ArkEcosystem/ledger/compare/master...2.0.1

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,22 @@ limitations under the License.
237237
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
238238
See the License for the specific language governing permissions and
239239
limitations under the License.
240+
241+
-----
242+
243+
Parts of this software are based on the Ledger Bitcoin Wallet App
244+
245+
Ledger App - Bitcoin Wallet
246+
(c) 2016-2019 Ledger
247+
248+
Licensed under the Apache License, Version 2.0 (the "License");
249+
you may not use this file except in compliance with the License.
250+
You may obtain a copy of the License at
251+
252+
http://www.apache.org/licenses/LICENSE-2.0
253+
254+
Unless required by applicable law or agreed to in writing, software
255+
distributed under the License is distributed on an "AS IS" BASIS,
256+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
257+
See the License for the specific language governing permissions and
258+
limitations under the License.

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ APP_LOAD_PARAMS=--appFlags 0x240 --curve secp256k1 --path "44'/111'" --path "44'
5252

5353
APPVERSION_M=2
5454
APPVERSION_N=0
55-
APPVERSION_P=0
55+
APPVERSION_P=1
5656
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)
5757

5858
ifeq ($(TARGET_NAME),TARGET_BLUE)

docs/PAYLOADS.md

+158
Large diffs are not rendered by default.

src/operations/transactions/ux/ipfs_ux.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ void displayIpfs(const Transaction *transaction) {
5757
TOKEN_NAME, TOKEN_NAME_SIZE, TOKEN_DECIMALS);
5858

5959
// DAG
60-
encodeBase58((uint8_t *)transaction->asset.ipfs.dag,
61-
transaction->asset.ipfs.length,
62-
(uint8_t *)displayCtx.extended_text,
63-
MAX_TEXT_LEN);
60+
size_t dagLen = MAX_TEXT_LEN;
61+
btchip_encode_base58(transaction->asset.ipfs.dag,
62+
transaction->asset.ipfs.length,
63+
displayCtx.extended_text,
64+
&dagLen);
6465
}

src/utils/base58.c

+56-59
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,22 @@
2525
*
2626
* -----
2727
*
28-
* Parts of this software are based on Ledger Nano SDK
29-
*
30-
* (c) 2017 Ledger
28+
* Parts of this software are based on the Ledger Bitcoin Wallet App
29+
*
30+
* Ledger App - Bitcoin Wallet
31+
* (c) 2016-2019 Ledger
3132
*
32-
* Licensed under the Apache License, Version 2.0 (the "License");
33-
* you may not use this file except in compliance with the License.
34-
* You may obtain a copy of the License at
33+
* Licensed under the Apache License, Version 2.0 (the "License");
34+
* you may not use this file except in compliance with the License.
35+
* You may obtain a copy of the License at
3536
*
36-
* http://www.apache.org/licenses/LICENSE-2.0
37+
* http://www.apache.org/licenses/LICENSE-2.0
3738
*
38-
* Unless required by applicable law or agreed to in writing, software
39-
* distributed under the License is distributed on an "AS IS" BASIS,
40-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41-
* See the License for the specific language governing permissions and
42-
* limitations under the License.
39+
* Unless required by applicable law or agreed to in writing, software
40+
* distributed under the License is distributed on an "AS IS" BASIS,
41+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42+
* See the License for the specific language governing permissions and
43+
* limitations under the License.
4344
******************************************************************************/
4445

4546
#include "utils/base58.h"
@@ -54,6 +55,9 @@
5455

5556
#include "utils/utils.h"
5657

58+
////////////////////////////////////////////////////////////////////////////////
59+
#define MAX_ENC_INPUT_SIZE 120
60+
5761
////////////////////////////////////////////////////////////////////////////////
5862
static const uint8_t BASE58ALPHABET[] = {
5963
'1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
@@ -63,71 +67,64 @@ static const uint8_t BASE58ALPHABET[] = {
6367
};
6468

6569
////////////////////////////////////////////////////////////////////////////////
66-
uint8_t encodeBase58(uint8_t *in,
67-
size_t inSize,
68-
uint8_t *out,
69-
size_t maxOutSize) {
70-
uint8_t tmp[164];
71-
uint8_t buffer[164];
72-
size_t j;
73-
size_t startAt;
70+
// src: https://github.com/LedgerHQ/ledger-app-btc/blob/master/src/btchip_base58.c#L79
71+
int btchip_encode_base58(const unsigned char *in, size_t length,
72+
unsigned char *out, size_t *outlen) {
73+
unsigned char buffer[MAX_ENC_INPUT_SIZE * 138 / 100 + 1] = {0};
74+
size_t i = 0, j;
75+
size_t startAt, stopAt;
7476
size_t zeroCount = 0;
77+
size_t outputSize;
7578

76-
if (inSize > sizeof(tmp)) {
77-
return 0;
79+
if (length > MAX_ENC_INPUT_SIZE) {
80+
return -1;
7881
}
7982

80-
bytecpy(tmp, in, inSize);
81-
while ((zeroCount < inSize) && (tmp[zeroCount] == 0U)) {
83+
while ((zeroCount < length) && (in[zeroCount] == 0)) {
8284
++zeroCount;
8385
}
8486

85-
j = 2 * inSize;
86-
startAt = zeroCount;
87-
while (startAt < inSize) {
88-
size_t remainder = 0;
89-
size_t divLoop;
90-
91-
for (divLoop = startAt; divLoop < inSize; divLoop++) {
92-
size_t digit256 = (size_t)(tmp[divLoop] & 0xff);
93-
size_t tmpDiv = remainder * 256 + digit256;
94-
tmp[divLoop] = (uint8_t)(tmpDiv / 58);
95-
remainder = (tmpDiv % 58);
87+
outputSize = (length - zeroCount) * 138 / 100 + 1;
88+
stopAt = outputSize - 1;
89+
for (startAt = zeroCount; startAt < length; startAt++) {
90+
int carry = in[startAt];
91+
for (j = outputSize - 1; (int)j >= 0; j--) {
92+
carry += 256 * buffer[j];
93+
buffer[j] = carry % 58;
94+
carry /= 58;
95+
96+
if (j <= stopAt - 1 && carry == 0) {
97+
break;
98+
}
9699
}
97-
98-
if (tmp[startAt] == 0) {
99-
++startAt;
100-
}
101-
102-
buffer[--j] = (uint8_t)BASE58ALPHABET[remainder];
100+
stopAt = j;
103101
}
104102

105-
while ((j < (2 * inSize)) && (buffer[j] == BASE58ALPHABET[0])) {
106-
++j;
103+
j = 0;
104+
while (j < outputSize && buffer[j] == 0) {
105+
j += 1;
107106
}
108107

109-
while (zeroCount-- > 0) {
110-
buffer[--j] = BASE58ALPHABET[0];
108+
if (*outlen < zeroCount + outputSize - j) {
109+
*outlen = zeroCount + outputSize - j;
110+
return -1;
111111
}
112112

113-
inSize = 2 * inSize - j;
114-
if (maxOutSize < inSize) {
115-
explicit_bzero(out, sizeof(out));
116-
return 0;
117-
}
113+
os_memset(out, BASE58ALPHABET[0], zeroCount);
118114

119-
bytecpy(out, (buffer + j), inSize);
115+
i = zeroCount;
116+
while (j < outputSize) {
117+
out[i++] = BASE58ALPHABET[buffer[j++]];
118+
}
119+
*outlen = i;
120120

121-
return inSize;
121+
return 0;
122122
}
123123

124124
////////////////////////////////////////////////////////////////////////////////
125-
uint16_t encodeBase58PublicKey(uint8_t *in,
126-
size_t inSize,
127-
uint8_t *out,
128-
size_t outSize,
129-
uint16_t version,
130-
uint8_t alreadyHashed) {
125+
int encodeBase58PublicKey(uint8_t *in, size_t inSize,
126+
uint8_t *out, size_t outSize,
127+
uint16_t version, uint8_t alreadyHashed) {
131128
uint8_t temp[inSize + 4];
132129
uint8_t checksum[HASH_32_LEN];
133130
size_t versionSize = (version > 255U ? 2 : 1);
@@ -153,5 +150,5 @@ uint16_t encodeBase58PublicKey(uint8_t *in,
153150

154151
bytecpy(&temp[ripeLength], checksum, 4);
155152

156-
return encodeBase58(temp, ripeLength + 4, out, outSize);
153+
return btchip_encode_base58(temp, ripeLength + 4, out, &outSize);
157154
}

src/utils/base58.h

+18-22
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,22 @@
2525
*
2626
* -----
2727
*
28-
* Parts of this software are based on Ledger Nano SDK
28+
* Parts of this software are based on the Ledger Bitcoin Wallet App
2929
*
30-
* (c) 2017 Ledger
30+
* Ledger App - Bitcoin Wallet
31+
* (c) 2016-2019 Ledger
3132
*
32-
* Licensed under the Apache License, Version 2.0 (the "License");
33-
* you may not use this file except in compliance with the License.
34-
* You may obtain a copy of the License at
33+
* Licensed under the Apache License, Version 2.0 (the "License");
34+
* you may not use this file except in compliance with the License.
35+
* You may obtain a copy of the License at
3536
*
36-
* http://www.apache.org/licenses/LICENSE-2.0
37+
* http://www.apache.org/licenses/LICENSE-2.0
3738
*
38-
* Unless required by applicable law or agreed to in writing, software
39-
* distributed under the License is distributed on an "AS IS" BASIS,
40-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41-
* See the License for the specific language governing permissions and
42-
* limitations under the License.
39+
* Unless required by applicable law or agreed to in writing, software
40+
* distributed under the License is distributed on an "AS IS" BASIS,
41+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42+
* See the License for the specific language governing permissions and
43+
* limitations under the License.
4344
******************************************************************************/
4445

4546
#ifndef ARK_UTILS_BASE58_H
@@ -49,16 +50,11 @@
4950
#include <stdint.h>
5051

5152
////////////////////////////////////////////////////////////////////////////////
52-
uint8_t encodeBase58(uint8_t *in,
53-
size_t inSize,
54-
uint8_t *out,
55-
size_t maxOutSize);
53+
int btchip_encode_base58(const unsigned char *in, size_t length,
54+
unsigned char *out, size_t *outlen);
5655

57-
uint16_t encodeBase58PublicKey(uint8_t *in,
58-
size_t inSize,
59-
uint8_t *out,
60-
size_t outSize,
61-
uint16_t version,
62-
uint8_t alreadyHashed);
56+
int encodeBase58PublicKey(uint8_t *in, size_t inSize,
57+
uint8_t *out, size_t outSize,
58+
uint16_t version, uint8_t alreadyHashed);
6359

64-
#endif // #ifndef ARK_UTILS_BASE58_H
60+
#endif // ARK_UTILS_BASE58_H

0 commit comments

Comments
 (0)