Tuesday, July 14, 2020

scratch work for cryptography 3

The ATECC508A is in the SparkFun Tutorial (1). This tutorial outputs a 64 byte public key as a hex string grouped by byte (for the form, see 2).

An example public key is:

uint8_t publicKey[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
};


When working with a few cryptography libraries both 3rd party and those produced by the manufacturer I discovered a library called CryptoAuthTools.

In a filed called ecdh.py in the CryptoAuthTools library I found out about the structure of the data.

    # Convert device public key to a cryptography public key object
    device_pub = ec.EllipticCurvePublicNumbers(
        curve=ec.SECP256R1(),
        x=int_from_bytes(device_pub[0:32], byteorder='big'),
        y=int_from_bytes(device_pub[32:64], byteorder='big'),
    ).public_key(default_backend())


https://github.com/MicrochipTech/cryptoauthtools/blob/master/python/examples/ecdh.py#L101-L105


I noticed that the first 32 (or 33 bytes?) represented the x par of the key and the last 32 (or 31 bytes?) represented the y part of the key.

It is a curve over a prime field with:


Order n =
115792089210356248762697446949407573530086143415290314195533631308867097853951

and generator points

G x = 6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296





and



G y = 4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5




but really the generator points can be anything as long as they are of order n.

These bytes are in the P-256 curve referenced in the ATECC508A data sheet and described mathematically in the Digital Signature Standard.

https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf


(1)https://www.sparkfun.com/products/15573(2) https://cryptii.com/pipes/base64-to-hex

Other key [it looks like R34-35 and ecc608a] -- R34-35 uses a CryptoChip.
https://www.mouser.com/datasheet/2/268/SAMR34-R35-Low-Power-LoRa-Sub-GHz-SiP-Data-Sheet-D-1507280.pdf

https://github.com/MicrochipTech/atsamr34_ecc608a_actility

https://www.microchip.com/Developmenttools/ProductDetails/DM320111





No comments:

Post a Comment