Comments (2)
See the discussion here: #65 (comment)
from micro-ecc.
ok so if understand correctly, the additional bit in recoverable signatures is just the recid appended to the whole thing - but then something else is wrong on my side too, since it just doesn't add up eventually.
when i use uECC with the same hash
and privateKey
as above, the output signature differs too from the expected one, and I can't recover the correct address using the ECDSA smart contract (I'm appending "1c" or "1b" as recIds for Ethereum instead of 00-03).
#include <uECC.h>
// private key: 0xbdb51a16eb6461ec16f84a7b6f19e20d0b9aa558fa0e9ae4bb493ff779f14255
static const uint8_t privateKey[] = {
0xbd, 0xb5, 0x1a, 0x16, 0xeb, 0x64, 0x61, 0xec,
0x16, 0xf8, 0x4a, 0x7b, 0x6f, 0x19, 0xe2, 0x0d,
0x0b, 0x9a, 0xa5, 0x58, 0xfa, 0x0e, 0x9a, 0xe4,
0xbb, 0x49, 0x3f, 0xf7, 0x79, 0xf1, 0x42, 0x55
};
// keccak256 of "1234": 0x387a8233c96e1fc0ad5e284353276177af2186e7afa85296f106336e376669f7
uint8_t hash[32] = {
0x38, 0x7a, 0x82, 0x33, 0xc9, 0x6e, 0x1f, 0xc0,
0xad, 0x5e, 0x28, 0x43, 0x53, 0x27, 0x61, 0x77,
0xaf, 0x21, 0x86, 0xe7, 0xaf, 0xa8, 0x52, 0x96,
0xf1, 0x06, 0x33, 0x6e, 0x37, 0x66, 0x69, 0xf7
};
bool eth_sign_hashed_message(const uint8_t *privateKey, const uint8_t *digest, uint8_t *result) {
int success = uECC_sign(
(const uint8_t*)(privateKey),
(const uint8_t*)(digest),
32,
(uint8_t*)result,
uECC_secp256k1()
);
return (success == 1);
}
uint8_t signatureRegular[64];
eth_sign_hashed_message(privateKey, hash, signatureRegular);
// expected sig:
// 65f333960946f37b57336199fd98826f4b334f70137f5f3a7ef2b2622007c6d77905672bd78dce53e37eb3ddef0c2219296db1795b466b5a89ffecda9d2106fc (+1c recId)
// uECC sig
// 45d6243b60fc6f589e7c40d597ee4664c0fec8a6121f72dcc67ce10015d9dc760b545ac2c0fc49561e9b5643f19a89670d1c9c572e469578fa79dfb08fb2d110 (+1b|1c recId -> both not valid)
the contract looks like this and validates the expected signature perfectly (returns wallet address 0x77baedd3f1aab1e8415bb6445cdaf418aa1924d5
), but returns random addresses for the signature created using uECC:
pragma solidity ^0.8.13;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
contract TestECDSA {
using ECDSA for bytes32;
function recover(bytes memory signature, bytes32 hashedPayload) public pure returns (address) {
bytes32 signedHash = hashedPayload.toEthSignedMessageHash();
return (signedHash.recover(signature));
}
}
any idea of what i might be doing wrong or how to get me on the right track? I've tried 4 different libraries by now and I'm close to giving up :(
from micro-ecc.
Related Issues (20)
- cannot build with LLVM-embedded-toolchain-for-Arm HOT 1
- Problem validating C509 test vectors -- ECC signature does not validate HOT 1
- Support for P-384?
- Interoperability with python-ecdsa regarding the SECP160r1 curve HOT 2
- uECC_decompress() gives garbage when passed an already-decompressed key
- P-256 failing cases HOT 5
- asm_mult for uECC_PLATFORM == uECC_arm_thumb
- Arduino compatibility
- Does micro-ecc works with signature (secp256r1) where R or S is lower than 32 bytes? HOT 2
- Contact for responsible disclosure HOT 2
- Check for identity element is missing during verification
- Question about the public private key generation using secp160r1
- how to set the RNG function? HOT 2
- HASH out value differnet on same file? HOT 6
- Hard fault on cortex M0+
- With latest IAR ARM Embedded workbench version 9.32 not able to compile this code HOT 2
- Earlyclobber inline asm input registers
- easy-ecc compatability?
- secp160r1 incorrect signatures on ARM Cortex M0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from micro-ecc.