csecp256k1

Haskell FFI bindings to bitcoin-core/secp256k1 (docs.ppad.tech/csecp256k1).
git clone git://git.ppad.tech/csecp256k1.git
Log | Files | Refs | README | LICENSE

ecmult.h (2875B)


      1 /***********************************************************************
      2  * Copyright (c) 2013, 2014, 2017 Pieter Wuille, Andrew Poelstra       *
      3  * Distributed under the MIT software license, see the accompanying    *
      4  * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
      5  ***********************************************************************/
      6 
      7 #ifndef SECP256K1_ECMULT_H
      8 #define SECP256K1_ECMULT_H
      9 
     10 #include "group.h"
     11 #include "scalar.h"
     12 #include "scratch.h"
     13 
     14 #ifndef ECMULT_WINDOW_SIZE
     15 #  define ECMULT_WINDOW_SIZE 15
     16 #  ifdef DEBUG_CONFIG
     17 #     pragma message DEBUG_CONFIG_MSG("ECMULT_WINDOW_SIZE undefined, assuming default value")
     18 #  endif
     19 #endif
     20 
     21 #ifdef DEBUG_CONFIG
     22 #  pragma message DEBUG_CONFIG_DEF(ECMULT_WINDOW_SIZE)
     23 #endif
     24 
     25 /* No one will ever need more than a window size of 24. The code might
     26  * be correct for larger values of ECMULT_WINDOW_SIZE but this is not
     27  * tested.
     28  *
     29  * The following limitations are known, and there are probably more:
     30  * If WINDOW_G > 27 and size_t has 32 bits, then the code is incorrect
     31  * because the size of the memory object that we allocate (in bytes)
     32  * will not fit in a size_t.
     33  * If WINDOW_G > 31 and int has 32 bits, then the code is incorrect
     34  * because certain expressions will overflow.
     35  */
     36 #if ECMULT_WINDOW_SIZE < 2 || ECMULT_WINDOW_SIZE > 24
     37 #  error Set ECMULT_WINDOW_SIZE to an integer in range [2..24].
     38 #endif
     39 
     40 /** The number of entries a table with precomputed multiples needs to have. */
     41 #define ECMULT_TABLE_SIZE(w) (1L << ((w)-2))
     42 
     43 /** Double multiply: R = na*A + ng*G */
     44 static void haskellsecp256k1_v0_1_0_ecmult(haskellsecp256k1_v0_1_0_gej *r, const haskellsecp256k1_v0_1_0_gej *a, const haskellsecp256k1_v0_1_0_scalar *na, const haskellsecp256k1_v0_1_0_scalar *ng);
     45 
     46 typedef int (haskellsecp256k1_v0_1_0_ecmult_multi_callback)(haskellsecp256k1_v0_1_0_scalar *sc, haskellsecp256k1_v0_1_0_ge *pt, size_t idx, void *data);
     47 
     48 /**
     49  * Multi-multiply: R = inp_g_sc * G + sum_i ni * Ai.
     50  * Chooses the right algorithm for a given number of points and scratch space
     51  * size. Resets and overwrites the given scratch space. If the points do not
     52  * fit in the scratch space the algorithm is repeatedly run with batches of
     53  * points. If no scratch space is given then a simple algorithm is used that
     54  * simply multiplies the points with the corresponding scalars and adds them up.
     55  * Returns: 1 on success (including when inp_g_sc is NULL and n is 0)
     56  *          0 if there is not enough scratch space for a single point or
     57  *          callback returns 0
     58  */
     59 static int haskellsecp256k1_v0_1_0_ecmult_multi_var(const haskellsecp256k1_v0_1_0_callback* error_callback, haskellsecp256k1_v0_1_0_scratch *scratch, haskellsecp256k1_v0_1_0_gej *r, const haskellsecp256k1_v0_1_0_scalar *inp_g_sc, haskellsecp256k1_v0_1_0_ecmult_multi_callback cb, void *cbdata, size_t n);
     60 
     61 #endif /* SECP256K1_ECMULT_H */