github.com/platonnetwork/platon-go@v0.7.6/cases/tool/win/bls_win/include/mcl/ecdsa.h (about)

     1  #pragma once
     2  /**
     3  	@file
     4  	@brief C interface of ECDSA
     5  	@author MITSUNARI Shigeo(@herumi)
     6  	@license modified new BSD license
     7  	http://opensource.org/licenses/BSD-3-Clause
     8  */
     9  #include <stdint.h> // for uint64_t, uint8_t
    10  #include <stdlib.h> // for size_t
    11  
    12  #if defined(_MSC_VER)
    13  	#ifdef ECDSA_DLL_EXPORT
    14  		#define ECDSA_DLL_API __declspec(dllexport)
    15  	#else
    16  		#define ECDSA_DLL_API __declspec(dllimport)
    17  		#ifndef ECDSA_NO_AUTOLINK
    18  			#pragma comment(lib, "mclecdsa.lib")
    19  		#endif
    20  	#endif
    21  #elif defined(__EMSCRIPTEN__)
    22  	#define ECDSA_DLL_API __attribute__((used))
    23  #else
    24  	#define ECDSA_DLL_API
    25  #endif
    26  
    27  #ifndef mclSize
    28  	#ifdef __EMSCRIPTEN__
    29  		// avoid 64-bit integer
    30  		#define mclSize unsigned int
    31  		#define mclInt int
    32  	#else
    33  		// use #define for cgo
    34  		#define mclSize size_t
    35  		#define mclInt int64_t
    36  	#endif
    37  #endif
    38  
    39  #ifdef __cplusplus
    40  extern "C" {
    41  #endif
    42  
    43  #ifdef ECDSA_NOT_DEFINE_STRUCT
    44  
    45  typedef struct ecdsaSecretKey ecdsaSecretKey;
    46  typedef struct ecdsaPublicKey ecdsaPublicKey;
    47  typedef struct ecdsaSignature ecdsaSignature;
    48  
    49  #else
    50  
    51  typedef struct {
    52  	uint64_t d[4];
    53  } ecdsaSecretKey;
    54  
    55  typedef struct {
    56  	uint64_t d[4 * 3];
    57  } ecdsaPublicKey;
    58  
    59  typedef struct {
    60  	uint64_t d[4 * 2];
    61  } ecdsaSignature;
    62  
    63  #endif
    64  
    65  struct ecdsaPrecomputedPublicKey;
    66  
    67  /*
    68  	init library
    69  	return 0 if success
    70  	@note not threadsafe
    71  */
    72  ECDSA_DLL_API int ecdsaInit(void);
    73  
    74  // return written byte size if success else 0
    75  ECDSA_DLL_API mclSize ecdsaSecretKeySerialize(void *buf, mclSize maxBufSize, const ecdsaSecretKey *sec);
    76  ECDSA_DLL_API mclSize ecdsaPublicKeySerialize(void *buf, mclSize maxBufSize, const ecdsaPublicKey *pub);
    77  ECDSA_DLL_API mclSize ecdsaSignatureSerialize(void *buf, mclSize maxBufSize, const ecdsaSignature *sig);
    78  
    79  // return read byte size if sucess else 0
    80  ECDSA_DLL_API mclSize ecdsaSecretKeyDeserialize(ecdsaSecretKey* sec, const void *buf, mclSize bufSize);
    81  ECDSA_DLL_API mclSize ecdsaPublicKeyDeserialize(ecdsaPublicKey* pub, const void *buf, mclSize bufSize);
    82  ECDSA_DLL_API mclSize ecdsaSignatureDeserialize(ecdsaSignature* sig, const void *buf, mclSize bufSize);
    83  
    84  //	return 0 if success
    85  ECDSA_DLL_API int ecdsaSecretKeySetByCSPRNG(ecdsaSecretKey *sec);
    86  
    87  ECDSA_DLL_API void ecdsaGetPublicKey(ecdsaPublicKey *pub, const ecdsaSecretKey *sec);
    88  
    89  ECDSA_DLL_API void ecdsaSign(ecdsaSignature *sig, const ecdsaSecretKey *sec, const void *m, mclSize size);
    90  
    91  // return 1 if valid
    92  ECDSA_DLL_API int ecdsaVerify(const ecdsaSignature *sig, const ecdsaPublicKey *pub, const void *m, mclSize size);
    93  ECDSA_DLL_API int ecdsaVerifyPrecomputed(const ecdsaSignature *sig, const ecdsaPrecomputedPublicKey *pub, const void *m, mclSize size);
    94  
    95  // return nonzero if success
    96  ECDSA_DLL_API ecdsaPrecomputedPublicKey *ecdsaPrecomputedPublicKeyCreate();
    97  // call this function to avoid memory leak
    98  ECDSA_DLL_API void ecdsaPrecomputedPublicKeyDestroy(ecdsaPrecomputedPublicKey *ppub);
    99  // return 0 if success
   100  ECDSA_DLL_API int ecdsaPrecomputedPublicKeyInit(ecdsaPrecomputedPublicKey *ppub, const ecdsaPublicKey *pub);
   101  
   102  #ifdef __cplusplus
   103  }
   104  #endif
   105