26 #include "BigNumberUtil.h"
34 static bool eval(uint8_t result[132],
const uint8_t f[66],
const uint8_t point[132]);
36 static void dh1(uint8_t k[132], uint8_t f[66]);
37 static bool dh2(
const uint8_t k[132], uint8_t f[66]);
39 static void sign(uint8_t signature[132],
const uint8_t privateKey[66],
40 const void *message,
size_t len,
Hash *hash = 0);
41 static bool verify(
const uint8_t signature[132],
42 const uint8_t publicKey[132],
43 const void *message,
size_t len,
Hash *hash = 0);
46 static void derivePublicKey(uint8_t publicKey[132],
const uint8_t privateKey[66]);
56 #if defined(TEST_P521_FIELD_OPS)
61 static void evaluate(limb_t *x, limb_t *y,
const uint8_t f[66]);
63 static void addAffine(limb_t *x1, limb_t *y1,
64 const limb_t *x2,
const limb_t *y2);
66 static bool validate(
const limb_t *x,
const limb_t *y);
67 static bool inRange(
const limb_t *x);
69 static void reduce(limb_t *result,
const limb_t *x);
70 static void reduceQuick(limb_t *x);
72 static void mulNoReduce(limb_t *result,
const limb_t *x,
const limb_t *y);
74 static void mul(limb_t *result,
const limb_t *x,
const limb_t *y);
75 static void square(limb_t *result,
const limb_t *x)
80 static void mulLiteral(limb_t *result,
const limb_t *x, limb_t y);
82 static void add(limb_t *result,
const limb_t *x,
const limb_t *y);
83 static void sub(limb_t *result,
const limb_t *x,
const limb_t *y);
85 static void dblPoint(limb_t *xout, limb_t *yout, limb_t *zout,
86 const limb_t *xin,
const limb_t *yin,
88 static void addPoint(limb_t *xout, limb_t *yout, limb_t *zout,
89 const limb_t *x1,
const limb_t *y1,
90 const limb_t *z1,
const limb_t *x2,
93 static void cmove(limb_t select, limb_t *x,
const limb_t *y);
94 static void cmove1(limb_t select, limb_t *x);
96 static void recip(limb_t *result,
const limb_t *x);
98 static void reduceQ(limb_t *result,
const limb_t *r);
99 static void mulQ(limb_t *result,
const limb_t *x,
const limb_t *y);
100 static void recipQ(limb_t *result,
const limb_t *x);
102 static void generateK(uint8_t k[66],
const uint8_t hm[66],
103 const uint8_t x[66],
Hash *hash, uint64_t count);
104 static void generateK(uint8_t k[66],
const uint8_t hm[66],
105 const uint8_t x[66], uint64_t count);
Abstract base class for cryptographic hash algorithms.
Elliptic curve operations with the NIST P-521 curve.
static void derivePublicKey(uint8_t publicKey[132], const uint8_t privateKey[66])
Derives the public key from a private key for P-521 signing operations.
static bool isValidCurvePoint(const uint8_t point[132])
Validates a point to ensure that it is on the curve.
static bool isValidPrivateKey(const uint8_t privateKey[66])
Validates a private key value to ensure that it is between 1 and q - 1.
static bool dh2(const uint8_t k[132], uint8_t f[66])
Performs phase 2 of an ECDH key exchange using P-521.
static void sign(uint8_t signature[132], const uint8_t privateKey[66], const void *message, size_t len, Hash *hash=0)
Signs a message using a specific P-521 private key.
static bool verify(const uint8_t signature[132], const uint8_t publicKey[132], const void *message, size_t len, Hash *hash=0)
Verifies a signature using a specific P-521 public key.
static bool eval(uint8_t result[132], const uint8_t f[66], const uint8_t point[132])
Evaluates the curve function.
static void dh1(uint8_t k[132], uint8_t f[66])
Performs phase 1 of an ECDH key exchange using P-521.
static void generatePrivateKey(uint8_t privateKey[66])
Generates a private key for P-521 signing operations.
static bool isValidPublicKey(const uint8_t publicKey[132])
Validates a public key to ensure that it is a valid curve point.