Repository navigation
Expand file tree
/
Copy pathutil.h
More file actions
104 lines (77 loc) · 3.3 KB
/
Copy pathutil.h
File metadata and controls
104 lines (77 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef UTIL_H_INCLUDED
#define UTIL_H_INCLUDED
#include "compatible.h"
#include <openssl/evp.h>
#include <openssl/conf.h>
#include <openssl/err.h>
#include <time.h>
//** openssl headers
#include <openssl/bn.h>
#include <openssl/ecdsa.h>
#include <openssl/sha.h>
#include <openssl/ripemd.h>
#include <openssl/rand.h>
#include <openssl/obj_mac.h>
#ifndef HASH256_SIZE
#define HASH256_SIZE (32)
#endif // HASH256_SIZE
#ifndef HASH160_SIZE
#define HASH160_SIZE (20)
#endif // HASH160_SIZE
#ifndef WIN32
typedef struct _SYSTEMTIME
{
unsigned short wYear;
unsigned short wMonth;
unsigned short wDayOfWeek;
unsigned short wDay;
unsigned short wHour;
unsigned short wMinute;
unsigned short wSecond;
unsigned short wMilliseconds;
}SYSTEMTIME;
#endif
void ReverseBytes(unsigned char *begin, size_t size);
void ReverseData(void * begin, uint32_t data_size, uint32_t count);
size_t Hex2Bin(const char *begin, size_t size, unsigned char *to);
size_t Bin2Hex(const unsigned char * begin, size_t size, char *to, uint32_t fLowercase);
size_t Hash256(const unsigned char * begin, size_t size, unsigned char to[32]);
size_t Hash160(const unsigned char * begin, size_t size, unsigned char to[20]);
size_t Base58Encode(const unsigned char *begin, size_t size, char *to);
size_t Base58Decode(const char *begin, size_t size, unsigned char *to);
void Dump(const void * begin, size_t size);
void Dump2(const void * begin, size_t size, FILE * fp);
size_t HexDump(const unsigned char *data, size_t size, int fp, uint32_t nDisplayPos);
uint64_t GetTimeMicro();
uint64_t GetTime();
BOOL UnixtimeToGmtTime(uint64_t time, struct tm * p_gmt);
BOOL UnixtimeToSystemTime(uint64_t time, SYSTEMTIME * st);
int64_t GetPerformanceCounter();
void RandAndSeed();
void Lock();
void Unlock();
int RecvData(int sockfd, void * payload, int cbPayload);
int SendData(int sockfd, const void * payload, int cbPayload);
uint32_t Base64Encode(const unsigned char * from, uint32_t cbFrom, char * to);
uint32_t Base64Decode(const char * from, uint32_t cbFrom, unsigned char * to);
//************************************
//** ECKEY
EC_KEY * ECKey_new();
BOOL ECKey_Free(EC_KEY * pkey);
BOOL ECKey_Check(const unsigned char vch[32]);
uint32_t ECKey_GenKeypair(EC_KEY * pkey, unsigned char vch[32]);
uint32_t ECKey_GeneratePrivKey(EC_KEY * pkey, unsigned char vch[32]);
uint32_t ECKey_GetPubkey(EC_KEY * pkey, unsigned char * pubkey, BOOL fCompressed);
BOOL ECKey_SetPubkey(EC_KEY *pkey, const unsigned char *pubkey, size_t size);
size_t ECKey_Sign(EC_KEY *pkey, const unsigned char hash[HASH256_SIZE], unsigned char **to);
BOOL ECKey_Verify(EC_KEY *pkey, const unsigned char * dgst, int32_t dgst_len, const unsigned char *sig, size_t sig_len);
uint32_t PubkeyToAddr(const unsigned char * pubkey, size_t size, char *to);
uint32_t PrivkeyToWIF(const unsigned char vch[32], char *to, BOOL fCompressed);
int AES256_encrypt(const void * plaintext, uint32_t cbPlaintext,
const unsigned char *password, uint32_t cbPassword,
const unsigned char * iv, unsigned char * ciphertext);
int AES256_decrypt(const unsigned char *ciphertext, int cbCiphertext,
const unsigned char *password, uint32_t cbPassword,
const unsigned char *iv,
unsigned char *plaintext);
#endif // UTIL_H_INCLUDED