Pages:
Author

Topic: [CANCELLED] C# guru's - Need signmessage & verifymessage fill in the blanks (Read 3151 times)

hero member
Activity: 765
Merit: 503
i think doof deserve the bounty.

Thanks guys.

Well, I got it to compile (remove uncommented code) and cast to c#.  However, the requirements are a lot more than that.  Without unit tests to compare its very hard to confirm.
legendary
Activity: 1260
Merit: 1000
Drunk Posts
I messed with it a bit but couldn't get it to work... most of the ecdsa stuff just goes over my head, i just followed examples and tested till it worked for the existing code
tfk
newbie
Activity: 39
Merit: 0
I think that this is a wise choice. Skipping over something like that is never a good idea. It's there for a reason. So indeed I recommend you to retain the longer sig.

You could ofcourse contact the author to ask why he seems to be skipping this part. Maybe he can give you some extra insight.

TFK
sr. member
Activity: 369
Merit: 250
I don't intend to earn the bounty but I know of a .NET bitcoin implementation, which maybe already works for you: https://github.com/jkoberg/FCoin

Thanks knocte, that looks like what I'm after, although not f# but it might not be hard to translate. I'll test it out tonight.

The project I have up on GitHub is very close to having a working solution, the only bit I cant get working is the function "recoverFromSignature" which also includes "decompressKey".. they contain some pretty funky crypto arithmetic which was why I offered up this bounty, for someone to finish it off.

The amusing part, is that F# implementation by jkoberg looks to have completely skipped the recoverFromSignature routine and he simply loops through the 4 recId iterations doing a verifyMessage call each pass to see if the hashes match and assuming the current recId is correct..  Not exactly optimized when you have to perform 4 ECDSA verification calls to sign one message.

To be honest this Bitcoin specific compressed signature format is proving to be more trouble than its worth, i'm thinking it may be better to retain a longer signature just to be more standard complient and compatible with existing ECDSA libraries.
sr. member
Activity: 369
Merit: 250
I don't intend to earn the bounty but I know of a .NET bitcoin implementation, which maybe already works for you: https://github.com/jkoberg/FCoin

Thanks knocte, that looks like what I'm after, although not f# but it might not be hard to translate. I'll test it out tonight.

Hi!

I've also taken a look at this code.

You need to get a whole bunch of classes translated. Classes from SpongyCastle ( https://github.com/rtyley/spongycastle ) which is a repackage of Bouncy Castle ( http://www.bouncycastle.org ) for Android and various classes from jbitcoin itself ( https://code.google.com/p/bitcoinj/source/browse/core/src/main/java/com/google/bitcoin/ )

Where Bouncy Castle has C# libraries availlable, SpongyCastle hasn't. Here lies the huge amount of work.

Do you know this library? http://bitcoincs.codeplex.com/SourceControl/latest

Before going further -and loose a good bitcoin on this- it may be a good thing to look around for solutions that are further in development. Do you need specifically jbitcoin translated?

TFK

Thanks tfk, I hadn't heard of spongy castle.
tfk
newbie
Activity: 39
Merit: 0
Hi!

I've also taken a look at this code.

You need to get a whole bunch of classes translated. Classes from SpongyCastle ( https://github.com/rtyley/spongycastle ) which is a repackage of Bouncy Castle ( http://www.bouncycastle.org ) for Android and various classes from jbitcoin itself ( https://code.google.com/p/bitcoinj/source/browse/core/src/main/java/com/google/bitcoin/ )

Where Bouncy Castle has C# libraries availlable, SpongyCastle hasn't. Here lies the huge amount of work.

Do you know this library? http://bitcoincs.codeplex.com/SourceControl/latest

Before going further -and loose a good bitcoin on this- it may be a good thing to look around for solutions that are further in development. Do you need specifically jbitcoin translated?

TFK
full member
Activity: 196
Merit: 100
You want working solution right ?
newbie
Activity: 44
Merit: 0
I don't intend to earn the bounty but I know of a .NET bitcoin implementation, which maybe already works for you: https://github.com/jkoberg/FCoin

Let me know if it is helpful to you! I cannot test it now due to lack of time*
Cheers


* However, in some months I will be much more free, and I'm interested on having some developer contacts interested around Bitcoin in the .NET/Mono framework, PM me!
sr. member
Activity: 369
Merit: 250
I was hoping to use the bitcoin-qt style message sign & verify with compressed signatures... but for the time being I think I can use the signData, verifySignature from mb300sb' library to achieve what I need (albeit with much longer signatures).

Nevertheless, It would be nice to have a working C# implementation somewhere, so the bounty remains if any C# crypto experts want to take a crack at it.
sr. member
Activity: 369
Merit: 250
Doof's submission is not complete, I haven't heard from him so thought I'd open it back up.
hero member
Activity: 686
Merit: 504
always the student, never the master.
i think doof deserve the bounty.
sr. member
Activity: 369
Merit: 250
Bounty still available for any takers.
sr. member
Activity: 369
Merit: 250
byte array or string is not a big deal.. not hard to convert to base64 string..
hero member
Activity: 765
Merit: 503
It builds, but looking at the java code, there's a lot that's different.

For example SignMessage on the java return is string, this is byte[]
hero member
Activity: 765
Merit: 503
All good

Method on Line 393 needs adding too.
public ECDSASignature sign(Sha256Hash input, KeyParameter aesKey)

sr. member
Activity: 369
Merit: 250
The commented out part I could have stuffed up... safest to delete it and re-translate the BitcoinJ version.
hero member
Activity: 765
Merit: 503
Ok, ill take a look.

Who did the original conversion?  The commented out code creates a BigInt type on "sig".

Java creates an ECDSASignature  class.   Not sure which way to go.

ECDSASignature sig = sign(hash, aesKey);
 
        // Now we have to work backwards to figure out the recId needed to recover the signature.
 
        int recId = -1;
 
        for (int i = 0; i < 4; i++) {
 
            ECKey k = ECKey.recoverFromSignature(i, sig, hash, isCompressed());
 
            if (k != null && Arrays.equals(k.pub, pub)) {
 
                recId = i;
 
                break;
 
            }
 
        }
sr. member
Activity: 369
Merit: 250
Done.  Slothbag, can you pm me your email?  I cant commit to github until tonight.  Ill email you the .cs files.

Also, ill look at bitcoinj and see if he has any unit tests.  there's a few (logical) assumptions to be made, but I cant verify the implementation performs exactly the same without unit tests.

Here is a very simple C++ message sign verify program https://github.com/Bobalot/bitcoin-signature-tools

I was just planning to generate 100 random addresses and get the C++ and the C# programs to run through them all and compare the results.  Not super thorough but probably enough for my purposes
hero member
Activity: 765
Merit: 503
Done.  Slothbag, can you pm me your email?  I cant commit to github until tonight.  Ill email you the .cs files.

Also, ill look at bitcoinj and see if he has any unit tests.  there's a few (logical) assumptions to be made, but I cant verify the implementation performs exactly the same without unit tests.
sr. member
Activity: 369
Merit: 250

From memory the one or two Util functions I needed I just moved into the class that needed them.  Not fussed if you want to keep them in a separate Util file or not.
Pages:
Jump to: