123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 |
- extern "C" {
- typedef int8_t wordcount_t;
- typedef int16_t bitcount_t;
- typedef int8_t cmpresult_t;
- typedef unsigned int uECC_word_t;
- typedef uint64_t uECC_dword_t;
- struct uECC_Curve_t;
- typedef const struct uECC_Curve_t * uECC_Curve;
- struct uECC_Curve_t {
- wordcount_t num_words;
- wordcount_t num_bytes;
- bitcount_t num_n_bits;
- uECC_word_t p[NUM_ECC_WORDS];
- uECC_word_t n[NUM_ECC_WORDS];
- uECC_word_t G[NUM_ECC_WORDS * 2];
- uECC_word_t b[NUM_ECC_WORDS];
- void (*double_jacobian)(uECC_word_t * X1, uECC_word_t * Y1, uECC_word_t * Z1,
- uECC_Curve curve);
- void (*x_side)(uECC_word_t *result, const uECC_word_t *x, uECC_Curve curve);
- void (*mmod_fast)(uECC_word_t *result, uECC_word_t *product);
- };
- void double_jacobian_default(uECC_word_t * X1, uECC_word_t * Y1,
- uECC_word_t * Z1, uECC_Curve curve);
- void x_side_default(uECC_word_t *result, const uECC_word_t *x,
- uECC_Curve curve);
- void vli_mmod_fast_secp256r1(unsigned int *result, unsigned int *product);
- ((num_bits + ((uECC_WORD_SIZE * 8) - 1)) / (uECC_WORD_SIZE * 8))
- static const struct uECC_Curve_t curve_secp256r1 = {
- NUM_ECC_WORDS,
- NUM_ECC_BYTES,
- 256, {
- BYTES_TO_WORDS_8(FF, FF, FF, FF, FF, FF, FF, FF),
- BYTES_TO_WORDS_8(FF, FF, FF, FF, 00, 00, 00, 00),
- BYTES_TO_WORDS_8(00, 00, 00, 00, 00, 00, 00, 00),
- BYTES_TO_WORDS_8(01, 00, 00, 00, FF, FF, FF, FF)
- }, {
- BYTES_TO_WORDS_8(51, 25, 63, FC, C2, CA, B9, F3),
- BYTES_TO_WORDS_8(84, 9E, 17, A7, AD, FA, E6, BC),
- BYTES_TO_WORDS_8(FF, FF, FF, FF, FF, FF, FF, FF),
- BYTES_TO_WORDS_8(00, 00, 00, 00, FF, FF, FF, FF)
- }, {
- BYTES_TO_WORDS_8(96, C2, 98, D8, 45, 39, A1, F4),
- BYTES_TO_WORDS_8(A0, 33, EB, 2D, 81, 7D, 03, 77),
- BYTES_TO_WORDS_8(F2, 40, A4, 63, E5, E6, BC, F8),
- BYTES_TO_WORDS_8(47, 42, 2C, E1, F2, D1, 17, 6B),
- BYTES_TO_WORDS_8(F5, 51, BF, 37, 68, 40, B6, CB),
- BYTES_TO_WORDS_8(CE, 5E, 31, 6B, 57, 33, CE, 2B),
- BYTES_TO_WORDS_8(16, 9E, 0F, 7C, 4A, EB, E7, 8E),
- BYTES_TO_WORDS_8(9B, 7F, 1A, FE, E2, 42, E3, 4F)
- }, {
- BYTES_TO_WORDS_8(4B, 60, D2, 27, 3E, 3C, CE, 3B),
- BYTES_TO_WORDS_8(F6, B0, 53, CC, B0, 06, 1D, 65),
- BYTES_TO_WORDS_8(BC, 86, 98, 76, 55, BD, EB, B3),
- BYTES_TO_WORDS_8(E7, 93, 3A, AA, D8, 35, C6, 5A)
- },
- &double_jacobian_default,
- &x_side_default,
- &vli_mmod_fast_secp256r1
- };
- uECC_Curve uECC_secp256r1(void);
- int uECC_generate_random_int(uECC_word_t *random, const uECC_word_t *top,
- wordcount_t num_words);
- typedef int(*uECC_RNG_Function)(uint8_t *dest, unsigned int size);
- void uECC_set_rng(uECC_RNG_Function rng_function);
- uECC_RNG_Function uECC_get_rng(void);
- int uECC_curve_private_key_size(uECC_Curve curve);
- int uECC_curve_public_key_size(uECC_Curve curve);
- int uECC_compute_public_key(const uint8_t *private_key,
- uint8_t *public_key, uECC_Curve curve);
- uECC_word_t EccPoint_compute_public_key(uECC_word_t *result,
- uECC_word_t *private_key, uECC_Curve curve);
- uECC_word_t regularize_k(const uECC_word_t * const k, uECC_word_t *k0,
- uECC_word_t *k1, uECC_Curve curve);
- void EccPoint_mult(uECC_word_t * result, const uECC_word_t * point,
- const uECC_word_t * scalar, const uECC_word_t * initial_Z,
- bitcount_t num_bits, uECC_Curve curve);
- uECC_word_t uECC_vli_isZero(const uECC_word_t *vli, wordcount_t num_words);
- uECC_word_t EccPoint_isZero(const uECC_word_t *point, uECC_Curve curve);
- cmpresult_t uECC_vli_cmp(const uECC_word_t *left, const uECC_word_t *right,
- wordcount_t num_words);
- cmpresult_t uECC_vli_cmp_unsafe(const uECC_word_t *left, const uECC_word_t *right,
- wordcount_t num_words);
- void uECC_vli_modSub(uECC_word_t *result, const uECC_word_t *left,
- const uECC_word_t *right, const uECC_word_t *mod,
- wordcount_t num_words);
- void XYcZ_add(uECC_word_t * X1, uECC_word_t * Y1, uECC_word_t * X2,
- uECC_word_t * Y2, uECC_Curve curve);
- void apply_z(uECC_word_t * X1, uECC_word_t * Y1, const uECC_word_t * const Z,
- uECC_Curve curve);
- uECC_word_t uECC_vli_testBit(const uECC_word_t *vli, bitcount_t bit);
- void uECC_vli_mmod(uECC_word_t *result, uECC_word_t *product,
- const uECC_word_t *mod, wordcount_t num_words);
- void uECC_vli_modMult_fast(uECC_word_t *result, const uECC_word_t *left,
- const uECC_word_t *right, uECC_Curve curve);
- uECC_word_t uECC_vli_sub(uECC_word_t *result, const uECC_word_t *left,
- const uECC_word_t *right, wordcount_t num_words);
- uECC_word_t uECC_vli_equal(const uECC_word_t *left, const uECC_word_t *right,
- wordcount_t num_words);
- void uECC_vli_modMult(uECC_word_t *result, const uECC_word_t *left,
- const uECC_word_t *right, const uECC_word_t *mod,
- wordcount_t num_words);
- void uECC_vli_modInv(uECC_word_t *result, const uECC_word_t *input,
- const uECC_word_t *mod, wordcount_t num_words);
- void uECC_vli_set(uECC_word_t *dest, const uECC_word_t *src,
- wordcount_t num_words);
- void uECC_vli_modAdd(uECC_word_t *result, const uECC_word_t *left,
- const uECC_word_t *right, const uECC_word_t *mod,
- wordcount_t num_words);
- bitcount_t uECC_vli_numBits(const uECC_word_t *vli,
- const wordcount_t max_words);
- void uECC_vli_clear(uECC_word_t *vli, wordcount_t num_words);
- int uECC_valid_point(const uECC_word_t *point, uECC_Curve curve);
- int uECC_valid_public_key(const uint8_t *public_key, uECC_Curve curve);
-
- void uECC_vli_nativeToBytes(uint8_t *bytes, int num_bytes,
- const unsigned int *native);
- void uECC_vli_bytesToNative(unsigned int *native, const uint8_t *bytes,
- int num_bytes);
- }
|