Skip to content

Commit

Permalink
Merge pull request #12 from p3root/fix/bip32-encoding
Browse files Browse the repository at this point in the history
fix big32 encoding + add unit tests
  • Loading branch information
p3root authored Apr 16, 2021
2 parents 0d05df7 + d6966c0 commit 5943c9d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/src/utils/ecurve.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ Uint8List _encodeBigInt(BigInt number) {
if (number > BigInt.zero) {
rawSize = (number.bitLength + 7) >> 3;
needsPaddingByte = ((number >> (rawSize - 1) * 8) & negativeFlag) == negativeFlag ? 1 : 0;

if (rawSize < 32) {
needsPaddingByte = 1;
}
} else {
needsPaddingByte = 0;
rawSize = (number.bitLength + 8) >> 3;
Expand Down
24 changes: 24 additions & 0 deletions test/ecc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,28 @@ void main() {
ecc.sign(HEX.decode("b11d3d5e4ae12b89d5e3872ccc7d1f96d29b0ab888b67dccf1be5164b811cdbe"), HEX.decode("55b18e96ce3964ef2c81ad69249eca6d42682c11fbe525df6671fcbf0c2be902"));
});
});

group('Failing ecc test', () {
test('Should fail with the third set of key-msg', () {
var key, msg, sig;

key = 'f92ca9fe5f77afa489214a7ba2bd6b36d30dd4acdb55c70d1378b5c45c831820';
msg = '045a7448dffff67c08023d16279c57c0bd16af6467580c183cc4672e768b8a77';

sig = ecc.sign(HEX.decode(msg), HEX.decode(key));
print(HEX.encode(sig));

key = '8c39fb3d889b6be22850254dc7ce3247c559d9f968785d88251ee4457633e335';
msg = '6ad99bc30926fd79cf5a977044088fd298a59728c5b0c1040713d3a8e1c1e69b';

sig = ecc.sign(HEX.decode(msg), HEX.decode(key));
print(HEX.encode(sig));

key = '2de619ea940d31927e0a7bbd5ebf855ab66f488b94a65cf929a1eb70b54ec771';
msg = 'd82a6db2583353856dd4dadc38cdb6373b092ea1f026fa04f03aa3c4e972454f';

sig = ecc.sign(HEX.decode(msg), HEX.decode(key));
print(HEX.encode(sig));
});
});
}

0 comments on commit 5943c9d

Please sign in to comment.