Question

I have tried both ProfessionalCard 7.5 rev. B and D in settings. (according to a ZeitControl email it should be D, but in an example EC-p project they have it is B)

Here is the code:

#Include EC-P.DEF

#Stack 120

Const curveFile = "secp256k1.bin"

Call ECpSetCurveFromFile(curveFile)

Command &H20 &H07 TestCommand(returnvalue$)
    Public test$
    test$ = "Init Value"
    Rem test$ = "101318078082651670995624611882601919371611236582435493534525386006923988435104"
    Call ECpMakePublicKey("101318078082651670995624611882601919371611236582435493534525386006923988435104",test$)
    returnvalue$ = test$ + "Test?"

The command returns, but the test$ variable is blank. (I made my own hex converter to make sure the private key was valid, but still the same issue)

-Any ideas to solve this? -Do I need leading zeros in the key if the number is under 256 or 512 bit? -Am I misunderstanding how this should work?

(as I read the manual I give a private key and should get a public key - both as positive integers expressed with strings.)

Was it helpful?

Solution

Ok so there was a few problems with my initial attempt, but after banging my head against the manual answers fell out:

  1. The curve file is a file path.
  2. The curve file path refers to files ON THE CARD.
  3. You must load the file into the card and read it there.
  4. You must use the .bin, not the .def file for this.
  5. The private key uses a 32 byte format and the public key will be the full 64 byte key. (X AND Y position).
  6. The format is base 256, meaning each char value in the string keys can be an extended ASCII code between 0-255. (Hence my initial tries with decimal and hexadecimal integers were too long!)

This is the card file definition:

Dir "\"
    File "CurveFile" Len=0
        input "C:\Users\mcb\Dropbox\Hobby stuff\75Branch\secp256k1.16.bin"
End Dir

Here is how to refer to it:

Call ECpSetCurveFromFile("\CurveFile")
If LibError <> 0 Then SW1SW2 = LibError : LibError = 0 : exit command

Here is the key definition, the Chr$ is native and converts the byte array to string:

Eeprom prk$ = Chr$( &H79,&H33,&HBC,&H95,&HD3,&H03,&H9F,&H94,_
                    &H9F,&H25,&H14,&H0C,&HAA,&H62,&H45,&HC7,_
                    &H16,&H08,&HBF,&H93,&H43,&H96,&HC6,&HDC,_
                    &HE4,&HCD,&HB0,&H87,&H5C,&H6A,&H72,&HE8)

(Const type is also allowed) Here is how to use the key for generating a public key:

Call ECpMakePublicKey(Key1, puk$)
If LibError <> 0 Then SW1SW2 = LibError : LibError = 0 : exit command
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top