Format of the hex array public key for the ATECC508A crypto chip. Importing the key.

Does anyone know much about the public key generated by the ATECC508A? I am having trouble using it in libraries. Is it truly in the uncompressed P-256 format? {x point, y-point}.

I posted an issue in the fastecdsa library when I tried to paste the public key in here. In this issue, I have a link to a blog post and a github gist. Please let me know if you need any clarification.

Thank you.

This is the same person as viper49946. A quick update. I may have my method wrong.

I start with the public key from the cryptochip:

uint8_t publicKeyExternal[64] = {

0xF9, 0xC3, 0x6F, 0x89, 0x64, 0x62, 0x33, 0x78, 0xBD, 0xC0, 0x68, 0xD4, 0xBC, 0xE0, 0x7E, 0xD1,

0x7C, 0x8F, 0xA4, 0x86, 0xF9, 0xAC, 0x0C, 0x26, 0x13, 0xCA, 0x3C, 0x8C, 0x30, 0x6D, 0x7B, 0xB6,

0x1C, 0xD3, 0x67, 0x17, 0xB8, 0xAC, 0x5E, 0x4F, 0xEA, 0x8A, 0xD2, 0x3D, 0xC8, 0xD0, 0x78, 0x3C,

0x23, 0x18, 0xEE, 0x4A, 0xD7, 0xA8, 0x0D, 0xB6, 0xE0, 0x02, 0x6A, 0xD0, 0xB0, 0x72, 0xA2, 0x4F

};

I compress the byte array in hex to two 32 byte hex strings:

[‘f9c36f8964623378bdc068d4bce07ed17c8fa486f9acc2613ca3c8c306d7bb6’, ‘1cd36717b8ac5e4fea8ad23dc8d0783c2318ee4ad7a8db6e026ad0b072a24f’]

I guess that these are the {x,y} coordinates of an uncompressed public key. I convert them to int values

{7060700267049620596356235336501166570879242195065472674169415375238145604534 , 50930765665627190067685409014485724477345323970126409943904502612080370255}

I they feed them into a library. In this case, the fastecdsa SEC1Encoder.encode_public_key method.

fastecdsa tells me that the point is not on the curve. Pulling in a public key for the P-256 curve from a stackoverflow post does not produce this error message (suggesting that it is on the curve, the library is working, but there is something

wrong with the input in the form Point(x,y,Curve=P256)

Point(7060700267049620596356235336501166570879242195065472674169415375238145604534 , 50930765665627190067685409014485724477345323970126409943904502612080370255,Curve=P256)

Assuming that the public key from the cryptochip is a good one (whatever good means) then there must be something wrong in my method of compressing the byte array into a hex string and then an x,y integer .

Here is a link to a gist where I describe things in more detail:

https://gist.github.com/bshambaugh/6f0f … 4cc103e9c4

Solved.

I fixed the code so that I see no complaints about the public key not being on the P256 curve. It turns out the hex() function in python as I was using it strips off placeholders if they are not being used in hex representation.

i.e. 0F becomes F

I need two placeholders, as in 0F, for the point to be valid.

Code that breaks the public key into an {x,y} where x and y are of type int.

brokenKey = []

def printarray(l,u,a,concat):
 while l < u:
    # with the hex method I do not always get two placeholders
    # see https://stackoverflow.com/questions/2269827/how-to-convert-an-int-to-a-hex-string
    # print("current:",l,hex(a[l]))
    #  print("current elem",l,a[l])
     print("current element:",l,"%0.2X" % a[l])
     concat = concat + ("%0.2X" % a[l])
    # concat = concat + hex(a[l]).lstrip("0x").rstrip("L")
     print concat
     l += 1
     if(l == u):
        brokenKey.append(concat)

publicKey = [
0xF9, 0xC3, 0x6F, 0x89, 0x64, 0x62, 0x33, 0x78, 0xBD, 0xC0, 0x68, 0xD4, 0xBC, 0xE0, 0x7E, 0xD1,
0x7C, 0x8F, 0xA4, 0x86, 0xF9, 0xAC, 0x0C, 0x26, 0x13, 0xCA, 0x3C, 0x8C, 0x30, 0x6D, 0x7B, 0xB6,
0x1C, 0xD3, 0x67, 0x17, 0xB8, 0xAC, 0x5E, 0x4F, 0xEA, 0x8A, 0xD2, 0x3D, 0xC8, 0xD0, 0x78, 0x3C,
0x23, 0x18, 0xEE, 0x4A, 0xD7, 0xA8, 0x0D, 0xB6, 0xE0, 0x02, 0x6A, 0xD0, 0xB0, 0x72, 0xA2, 0x4F
];

concat = ""
n = 2
count = 0

if ( len(publicKey) % n == 0):
   k = len(publicKey) / n
else:
   # dump the entire array if it is not divisible by n
   k = len(publicKey)

while (count < len(publicKey)):
   # print ('The count is:', count)
   u = count + k
   print ("The lower:",count,"The upper:",u)
   printarray(count,u,publicKey,concat)
   count = u

print brokenKey

print "----------------- the int x,y --------------"

print(int(brokenKey[0],16))

print(int(brokenKey[1],16))

Code that reads in the public key:

import fastecdsa as fec
import binascii

from binascii import hexlify, unhexlify

from fastecdsa.curve import * 
from fastecdsa.encoding.sec1 import InvalidSEC1PublicKey, SEC1Encoder
from fastecdsa.point import Point

# this is the public key referenced in the SparkFun Forum https://forum.sparkfun.com/viewtopic.php?f=102&t=53408 after I changed the formatting like in Grey Bray's comment https://stackoverflow.com/questions/2269827/how-to-convert-an-int-to-a-hex-string
SEC1Encoder.encode_public_key(Point(112971204272793929541699765384018665134067875121047561926148644683187420494774,13038276010400560657327464707708345466200402936352359974176190171319880557135,curve=P256),True)