Contiki 3.x
Macros | Functions
ecc.h File Reference

 Calculations on elliptic curve secp256r1
More...

#include <stdint.h>

Go to the source code of this file.

Macros

#define ecc_is_valid_key(key, order)   (ecc_compare(order, key) == 1)
 Checks if a (random) number is valid as scalar on elliptic curve secp256r1. More...
 

Functions

int32_t ecc_compare (const uint32_t *a, const uint32_t *b)
 Compares the value of a with the value of b. More...
 
void ecc_ec_mult (uint32_t *resultx, uint32_t *resulty, const uint32_t *px, const uint32_t *py, const uint32_t *secret)
 ECC scalar multiplication on elliptic curve secp256r1. More...
 

Detailed Description

 Calculations on elliptic curve secp256r1

This is a efficient ECC implementation on the secp256r1 curve for 32 Bit CPU architectures. It provides basic operations on the secp256r1 curve and support for ECDH and ECDSA.

Author
Lars Schmertmann Small.nosp@m.Lars.nosp@m.@t-on.nosp@m.line.nosp@m..de Jens Trillmann jtril.nosp@m.lma@.nosp@m.infor.nosp@m.mati.nosp@m.k.uni.nosp@m.-bre.nosp@m.men.d.nosp@m.e

Definition in file ecc.h.

Macro Definition Documentation

#define ecc_is_valid_key (   key,
  order 
)    (ecc_compare(order, key) == 1)

Checks if a (random) number is valid as scalar on elliptic curve secp256r1.

A (random) number is only usable as scalar on elliptic curve secp256r1 if it is lower than the order of the curve. For the check, you need to provide the order of elliptic curve secp256r1.

uint32_t order[8] = {0xFC632551, 0xF3B9CAC2, 0xA7179E84, 0xBCE6FAAD, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF};

Parameters
keyThe (random) number to check for usability
orderThe order of elliptic curve secp256r1
Returns
1 if key is valid

Definition at line 68 of file ecc.h.

Function Documentation

int32_t ecc_compare ( const uint32_t *  a,
const uint32_t *  b 
)

Compares the value of a with the value of b.

This function is only public because its needed for the macro ecc_is_valid_key. It does a comparison of two 256 bit numbers. The return values are 1, 0 or -1.

Parameters
aFirst number
bSecond number
Returns
1 if a is greater than b 0 if a is equal to b -1 if a is less than b

Definition at line 112 of file ecc.c.

void ecc_ec_mult ( uint32_t *  resultx,
uint32_t *  resulty,
const uint32_t *  px,
const uint32_t *  py,
const uint32_t *  secret 
)

ECC scalar multiplication on elliptic curve secp256r1.

This function does a scalar multiplication on elliptic curve secp256r1. For an Elliptic curve Diffie–Hellman you need two multiplications. First one with the base point of elliptic curve secp256r1 you need to provide.

uint32_t base_x[8] = {0xd898c296, 0xf4a13945, 0x2deb33a0, 0x77037d81, 0x63a440f2, 0xf8bce6e5, 0xe12c4247, 0x6b17d1f2}; uint32_t base_y[8] = {0x37bf51f5, 0xcbb64068, 0x6b315ece, 0x2bce3357, 0x7c0f9e16, 0x8ee7eb4a, 0xfe1a7f9b, 0x4fe342e2};

Parameters
resultxPointer to memory to store the x-coordinate of the result
resultyPointer to memory to store the y-coordinate of the result
pxx-coordinate of the point to multiply with scalar
pyy-coordinate of the point to multiply with scalar
secretScalar for multiplication with elliptic curve point

Definition at line 124 of file ecc.c.