uECC.c (75aabb0d580501618b3e59f4b0ad9f03fa6606ab) uECC.c (c824d78c0a34df89b57d535abafcc7dacf30bb06)
1/* Copyright 2014, Kenneth MacKay. Licensed under the BSD 2-clause license. */
2
3#include "uECC.h"
4
5// NULL
6#include "stddef.h"
7
8// suppress MSVC C4244: conversion from uECC_word_t to int

--- 987 unchanged lines hidden (view full) ---

996 carry -= vli_sub(result, result, curve_p);
997 }
998}
999#endif /* uECC_WORD_SIZE */
1000
1001#elif uECC_CURVE == uECC_secp256r1
1002
1003/* Computes result = product % curve_p
1/* Copyright 2014, Kenneth MacKay. Licensed under the BSD 2-clause license. */
2
3#include "uECC.h"
4
5// NULL
6#include "stddef.h"
7
8// suppress MSVC C4244: conversion from uECC_word_t to int

--- 987 unchanged lines hidden (view full) ---

996 carry -= vli_sub(result, result, curve_p);
997 }
998}
999#endif /* uECC_WORD_SIZE */
1000
1001#elif uECC_CURVE == uECC_secp256r1
1002
1003/* Computes result = product % curve_p
1004 from http://www.nsa.gov/ia/_files/nist-routines.pdf */
1004 from www.nsa.gov/ia/_files/nist-routines.pdf */
1005#if uECC_WORD_SIZE == 1
1006static void vli_mmod_fast(uint8_t *RESTRICT result, uint8_t *RESTRICT product) {
1007 uint8_t tmp[uECC_BYTES];
1008 int8_t carry;
1009
1010 /* t */
1011 vli_set(result, product);
1012

--- 473 unchanged lines hidden (view full) ---

1486#define vli_modSquare_fast(result, left) vli_modMult_fast((result), (left), (left))
1487
1488#endif /* uECC_SQUARE_FUNC */
1489
1490
1491#define EVEN(vli) (!(vli[0] & 1))
1492/* Computes result = (1 / input) % mod. All VLIs are the same size.
1493 See "From Euclid's GCD to Montgomery Multiplication to the Great Divide"
1005#if uECC_WORD_SIZE == 1
1006static void vli_mmod_fast(uint8_t *RESTRICT result, uint8_t *RESTRICT product) {
1007 uint8_t tmp[uECC_BYTES];
1008 int8_t carry;
1009
1010 /* t */
1011 vli_set(result, product);
1012

--- 473 unchanged lines hidden (view full) ---

1486#define vli_modSquare_fast(result, left) vli_modMult_fast((result), (left), (left))
1487
1488#endif /* uECC_SQUARE_FUNC */
1489
1490
1491#define EVEN(vli) (!(vli[0] & 1))
1492/* Computes result = (1 / input) % mod. All VLIs are the same size.
1493 See "From Euclid's GCD to Montgomery Multiplication to the Great Divide"
1494 https://labs.oracle.com/techrep/2001/smli_tr-2001-95.pdf */
1494 labs.oracle.com/techrep/2001/smli_tr-2001-95.pdf */
1495#if !asm_modInv
1496static void vli_modInv(uECC_word_t *result, const uECC_word_t *input, const uECC_word_t *mod) {
1497 uECC_word_t a[uECC_WORDS], b[uECC_WORDS], u[uECC_WORDS], v[uECC_WORDS];
1498 uECC_word_t carry;
1499 cmpresult_t cmpResult;
1500
1501 if (vli_isZero(input)) {
1502 vli_clear(result);

--- 62 unchanged lines hidden (view full) ---

1565/* ------ Point operations ------ */
1566
1567/* Returns 1 if 'point' is the point at infinity, 0 otherwise. */
1568static cmpresult_t EccPoint_isZero(const EccPoint *point) {
1569 return (vli_isZero(point->x) && vli_isZero(point->y));
1570}
1571
1572/* Point multiplication algorithm using Montgomery's ladder with co-Z coordinates.
1495#if !asm_modInv
1496static void vli_modInv(uECC_word_t *result, const uECC_word_t *input, const uECC_word_t *mod) {
1497 uECC_word_t a[uECC_WORDS], b[uECC_WORDS], u[uECC_WORDS], v[uECC_WORDS];
1498 uECC_word_t carry;
1499 cmpresult_t cmpResult;
1500
1501 if (vli_isZero(input)) {
1502 vli_clear(result);

--- 62 unchanged lines hidden (view full) ---

1565/* ------ Point operations ------ */
1566
1567/* Returns 1 if 'point' is the point at infinity, 0 otherwise. */
1568static cmpresult_t EccPoint_isZero(const EccPoint *point) {
1569 return (vli_isZero(point->x) && vli_isZero(point->y));
1570}
1571
1572/* Point multiplication algorithm using Montgomery's ladder with co-Z coordinates.
1573From http://eprint.iacr.org/2011/338.pdf
1573From eprint.iacr.org/2011/338.pdf
1574*/
1575
1576/* Double in place */
1577#if (uECC_CURVE == uECC_secp256k1)
1578static void EccPoint_double_jacobian(uECC_word_t * RESTRICT X1,
1579 uECC_word_t * RESTRICT Y1,
1580 uECC_word_t * RESTRICT Z1) {
1581 /* t1 = X, t2 = Y, t3 = Z */

--- 1204 unchanged lines hidden ---
1574*/
1575
1576/* Double in place */
1577#if (uECC_CURVE == uECC_secp256k1)
1578static void EccPoint_double_jacobian(uECC_word_t * RESTRICT X1,
1579 uECC_word_t * RESTRICT Y1,
1580 uECC_word_t * RESTRICT Z1) {
1581 /* t1 = X, t2 = Y, t3 = Z */

--- 1204 unchanged lines hidden ---