Multos Forums

   

ECC Addition

Rank

Total Posts: 2

Joined 2014-07-01

PM

Dear Ladies and Gentlemen,

I’m trying to use the ECC Addition primitive (on a Ubivelox card where this should be supported / implemented).
Unfortunately it seems that in the multos.h headers this primitive is not supported, so I tried to extend the headers by myself. From the documentation (MULTOS Developer’s Reference Manual) I found that the addresses domainAddr,
point1Addr, point2Addr, outAddr have to be placed on the stack. What is not quite clear to me however is what I have actually to place at the corresponding addresses in the memory.
From the example for “ECC Generate Key Pair” (MULTOS Developer’s Reference Manual) I copied the domain parameters (together with the corresponding structure) however what format do I need for the points (how many bytes?)?
In addition is seems to me that the primitives don’t just accept any random byte combination as points (I tried 48 random bytes per point) but one needs points that “make sense” (in my first test I always get “exchange error SCardTransmit unknown pcsc error 0x8010002f”). Is this correct?

Is there any extended documentation on this topic?

Best regards,
Felix Riek

 

     
RankRankRank

Total Posts: 74

Joined 2012-02-21

PM

Hi Felix,

This primitive is one of those that has never really been used all that much. Hence why its not in multos.h and you’ll find isn’t in the current simulator either. For most applications the higher level ECC primitives are used. I’ve certainly never used it so don’t have any examples to hand.

Having said that I’ll be happy to put an example together for you. Give me a few days.

Thanks,
Chris.

     
Rank

Total Posts: 2

Joined 2014-07-01

PM

Dear Chris,

thank you very much for the fast reply and the offer to write an example. Perhaps it might be interesting for you to see what I already did.
I added the following to the header file (multos.h):


/*
**——————————————————————————————————————-
** void multosEccAdd(BYTE *domain, BYTE *point1, BYTE *point2, BYTE *outPoint)
**——————————————————————————————————————-
*/
#ifdef __FUNCTION_PROTOTYPES
void multosEccAdd(BYTE *domain, BYTE *point1, BYTE *point2, BYTE *outPoint);
#else
#define multosEccAdd(domain, point1, point2, outPoint) \
do \
{ \
__push (__typechk(BYTE *, domain)); \
__push (__typechk(BYTE *, point1)); \
__push (__typechk(BYTE *, point2)); \
__push (__typechk(BYTE *, outPoint)); \
__code (__PRIM, __PRIM_ECC_ADD); \
} while (0)
#endif

and started a first example:

#define SHORT_KEY_LEN 24

........

typedef struct
{
BYTE x[SHORT_KEY_LEN];
BYTE y[SHORT_KEY_LEN];
} ecc_point;


.........


#pragma melpublic
union
{
  BYTE pub[1];
} apdu_data;


.......


ecc_point point1;
ecc_point point2;
ecc_point outPoint;

.......

  switch (INS)
  {

          ...........

  case CMD_ECC_ADD:
  if (!CheckCase(3))
  ExitSW(ERR_WRONGCLASS);

  // Copy in information from APDU
  memcpy(&point1;,apdu_data.pub,2*SHORT_KEY_LEN);
  memcpy(&point2;,apdu_data.pub + 2*SHORT_KEY_LEN,2*SHORT_KEY_LEN);

  // Blank results
  memcpy(&outPoint;,0,2*SHORT_KEY_LEN);
  memcpy(apdu_data.pub,0,4*SHORT_KEY_LEN);

  multosEccAdd((BYTE*)&domainParams;, (BYTE*)&point1;, (BYTE*)&point2;, (BYTE*)&outPoint;);

  memcpy(apdu_data.pub,&outPoint;,2*SHORT_KEY_LEN);

  ExitLa(2*SHORT_KEY_LEN);

                ..........

  }

.......

Best regards,
Felix

     
RankRankRank

Total Posts: 74

Joined 2012-02-21

PM

Hi Felix,

The eccpoint structure needs to start with a single byte which gives the representation. For affine points the value is 0x04, for projective points it is 0x84. It should say this in the MDRM, but doesn’t. Next time I do an update I’ll include that.

Having said that, I haven’t managed to get my example app to work. I’ve requested some help from the guys at Ubivelox.

Chris

     
RankRankRank

Total Posts: 74

Joined 2012-02-21

PM

Hi Felix,

Click here for an example that will work on your Ubivelox card.

Regards,
Chris.