bcgit / pc-dart

Pointy Castle - Dart Derived Bouncy Castle APIs
MIT License
237 stars 122 forks source link

secp256k1 - public key hash not ok #96

Closed redDwarf03 closed 3 years ago

redDwarf03 commented 3 years ago

Hello

Actually I have different results between secp256k1 library on pub.dev and PC

When I code with PC:

final secp256k1 = ECCurve_secp256k1();
final point = secp256k1.G;
final bigInt = BigInt.parse(hex.encode(pvBuf), radix: 16);
var curvePoint = point * bigInt;
Uint8List pubBuf = curvePoint!.getEncoded();

i have

Expected: '04350d90092eeaaba2607ee2d307ce4e2130b5d9d567e20764b742c7133b0e1ad9af1d1e5d4a2e831bde9cbecd14864f5dd3e08bdf6621f36600ff3beeb0fdda8d'
Actual: '03350d90092eeaaba2607ee2d307ce4e2130b5d9d567e20764b742c7133b0e1ad9'

-> the 2nd character is wrong and the length of result is not good

and when I code with the secp256k1 library

var pubBuf = secp256k1.PrivateKey.fromHex(uint8ListToHex(pvBuf)).publicKey;
pubBuf.toHex());

i have

Expected: '04350d90092eeaaba2607ee2d307ce4e2130b5d9d567e20764b742c7133b0e1ad9af1d1e5d4a2e831bde9cbecd14864f5dd3e08bdf6621f36600ff3beeb0fdda8d'
Actual: '04350d90092eeaaba2607ee2d307ce4e2130b5d9d567e20764b742c7133b0e1ad9af1d1e5d4a2e831bde9cbecd14864f5dd3e08bdf6621f36600ff3beeb0fdda8d'

-> the result is good

Do you know why I haven’t the good result with pc?

Sorry if my issue is not an issue... :)

pedrofneves commented 3 years ago

same here, after update to the nullsafety version all my unit tests using EC fails...

AKushWarrior commented 3 years ago

@redDwarf03 is this fixed? Why did you close the issue?

redDwarf03 commented 3 years ago

I close this issue because it's better to use this library: https://pub.dev/packages/elliptic For 2 reasons: this lib works and the project is more reactive than PointyCastle