Skip to content

Commit 8493c0d

Browse files
committed
[ADD] init project
1 parent 4f97091 commit 8493c0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+4216
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
# generate-key
2-
Private phrase generates a valid bitcoin key
1+
# Generate Key
2+
----------
3+
generate-key is a use custom phrases to create public and private keys that match the bitcoin specification..
4+
5+
6+
# Testing
7+
----------
8+
9+
Multiple test cases are provided, under the "tests" directory.
10+
11+
Under their respective directories, they have their own use-case documents。
12+

depends/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bepal

depends/include/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bepal

depends/lib/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bepal

doc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bepal

src/compat/byteswap.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2014 The Bitcoin developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_COMPAT_BYTESWAP_H
6+
#define BITCOIN_COMPAT_BYTESWAP_H
7+
8+
#if defined(HAVE_CONFIG_H)
9+
#include "config/bitcoin-config.h"
10+
#endif
11+
12+
#include <stdint.h>
13+
14+
#if defined(HAVE_BYTESWAP_H)
15+
#include <byteswap.h>
16+
#endif
17+
18+
#if HAVE_DECL_BSWAP_16 == 0
19+
inline uint16_t bswap_16(uint16_t x)
20+
{
21+
return (x >> 8) | ((x & 0x00ff) << 8);
22+
}
23+
#endif // HAVE_DECL_BSWAP16
24+
25+
#if HAVE_DECL_BSWAP_32 == 0
26+
inline uint32_t bswap_32(uint32_t x)
27+
{
28+
return (((x & 0xff000000U) >> 24) | ((x & 0x00ff0000U) >> 8) |
29+
((x & 0x0000ff00U) << 8) | ((x & 0x000000ffU) << 24));
30+
}
31+
#endif // HAVE_DECL_BSWAP32
32+
33+
#if HAVE_DECL_BSWAP_64 == 0
34+
inline uint64_t bswap_64(uint64_t x)
35+
{
36+
return (((x & 0xff00000000000000ull) >> 56)
37+
| ((x & 0x00ff000000000000ull) >> 40)
38+
| ((x & 0x0000ff0000000000ull) >> 24)
39+
| ((x & 0x000000ff00000000ull) >> 8)
40+
| ((x & 0x00000000ff000000ull) << 8)
41+
| ((x & 0x0000000000ff0000ull) << 24)
42+
| ((x & 0x000000000000ff00ull) << 40)
43+
| ((x & 0x00000000000000ffull) << 56));
44+
}
45+
#endif // HAVE_DECL_BSWAP64
46+
47+
#endif // BITCOIN_COMPAT_BYTESWAP_H

src/compat/endian.h

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
// Copyright (c) 2014-2015 The Bitcoin developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_COMPAT_ENDIAN_H
6+
#define BITCOIN_COMPAT_ENDIAN_H
7+
8+
#if defined(HAVE_CONFIG_H)
9+
#include "config/bitcoin-config.h"
10+
#endif
11+
12+
#include <stdint.h>
13+
14+
#include "compat/byteswap.h"
15+
16+
#if defined(HAVE_ENDIAN_H)
17+
#include <endian.h>
18+
#elif defined(HAVE_SYS_ENDIAN_H)
19+
#include <sys/endian.h>
20+
#endif
21+
22+
#if defined(WORDS_BIGENDIAN)
23+
24+
#if HAVE_DECL_HTOBE16 == 0
25+
inline uint16_t htobe16(uint16_t host_16bits)
26+
{
27+
return host_16bits;
28+
}
29+
#endif // HAVE_DECL_HTOBE16
30+
31+
#if HAVE_DECL_HTOLE16 == 0
32+
inline uint16_t htole16(uint16_t host_16bits)
33+
{
34+
return bswap_16(host_16bits);
35+
}
36+
#endif // HAVE_DECL_HTOLE16
37+
38+
#if HAVE_DECL_BE16TOH == 0
39+
inline uint16_t be16toh(uint16_t big_endian_16bits)
40+
{
41+
return big_endian_16bits;
42+
}
43+
#endif // HAVE_DECL_BE16TOH
44+
45+
#if HAVE_DECL_LE16TOH == 0
46+
inline uint16_t le16toh(uint16_t little_endian_16bits)
47+
{
48+
return bswap_16(little_endian_16bits);
49+
}
50+
#endif // HAVE_DECL_LE16TOH
51+
52+
#if HAVE_DECL_HTOBE32 == 0
53+
inline uint32_t htobe32(uint32_t host_32bits)
54+
{
55+
return host_32bits;
56+
}
57+
#endif // HAVE_DECL_HTOBE32
58+
59+
#if HAVE_DECL_HTOLE32 == 0
60+
inline uint32_t htole32(uint32_t host_32bits)
61+
{
62+
return bswap_32(host_32bits);
63+
}
64+
#endif // HAVE_DECL_HTOLE32
65+
66+
#if HAVE_DECL_BE32TOH == 0
67+
inline uint32_t be32toh(uint32_t big_endian_32bits)
68+
{
69+
return big_endian_32bits;
70+
}
71+
#endif // HAVE_DECL_BE32TOH
72+
73+
#if HAVE_DECL_LE32TOH == 0
74+
inline uint32_t le32toh(uint32_t little_endian_32bits)
75+
{
76+
return bswap_32(little_endian_32bits);
77+
}
78+
#endif // HAVE_DECL_LE32TOH
79+
80+
#if HAVE_DECL_HTOBE64 == 0
81+
inline uint64_t htobe64(uint64_t host_64bits)
82+
{
83+
return host_64bits;
84+
}
85+
#endif // HAVE_DECL_HTOBE64
86+
87+
#if HAVE_DECL_HTOLE64 == 0
88+
inline uint64_t htole64(uint64_t host_64bits)
89+
{
90+
return bswap_64(host_64bits);
91+
}
92+
#endif // HAVE_DECL_HTOLE64
93+
94+
#if HAVE_DECL_BE64TOH == 0
95+
inline uint64_t be64toh(uint64_t big_endian_64bits)
96+
{
97+
return big_endian_64bits;
98+
}
99+
#endif // HAVE_DECL_BE64TOH
100+
101+
#if HAVE_DECL_LE64TOH == 0
102+
inline uint64_t le64toh(uint64_t little_endian_64bits)
103+
{
104+
return bswap_64(little_endian_64bits);
105+
}
106+
#endif // HAVE_DECL_LE64TOH
107+
108+
#else // WORDS_BIGENDIAN
109+
110+
#if HAVE_DECL_HTOBE16 == 0
111+
inline uint16_t htobe16(uint16_t host_16bits)
112+
{
113+
return bswap_16(host_16bits);
114+
}
115+
#endif // HAVE_DECL_HTOBE16
116+
117+
#if HAVE_DECL_HTOLE16 == 0
118+
inline uint16_t htole16(uint16_t host_16bits)
119+
{
120+
return host_16bits;
121+
}
122+
#endif // HAVE_DECL_HTOLE16
123+
124+
#if HAVE_DECL_BE16TOH == 0
125+
inline uint16_t be16toh(uint16_t big_endian_16bits)
126+
{
127+
return bswap_16(big_endian_16bits);
128+
}
129+
#endif // HAVE_DECL_BE16TOH
130+
131+
#if HAVE_DECL_LE16TOH == 0
132+
inline uint16_t le16toh(uint16_t little_endian_16bits)
133+
{
134+
return little_endian_16bits;
135+
}
136+
#endif // HAVE_DECL_LE16TOH
137+
138+
#if HAVE_DECL_HTOBE32 == 0
139+
inline uint32_t htobe32(uint32_t host_32bits)
140+
{
141+
return bswap_32(host_32bits);
142+
}
143+
#endif // HAVE_DECL_HTOBE32
144+
145+
#if HAVE_DECL_HTOLE32 == 0
146+
inline uint32_t htole32(uint32_t host_32bits)
147+
{
148+
return host_32bits;
149+
}
150+
#endif // HAVE_DECL_HTOLE32
151+
152+
#if HAVE_DECL_BE32TOH == 0
153+
inline uint32_t be32toh(uint32_t big_endian_32bits)
154+
{
155+
return bswap_32(big_endian_32bits);
156+
}
157+
#endif // HAVE_DECL_BE32TOH
158+
159+
#if HAVE_DECL_LE32TOH == 0
160+
inline uint32_t le32toh(uint32_t little_endian_32bits)
161+
{
162+
return little_endian_32bits;
163+
}
164+
#endif // HAVE_DECL_LE32TOH
165+
166+
#if HAVE_DECL_HTOBE64 == 0
167+
inline uint64_t htobe64(uint64_t host_64bits)
168+
{
169+
return bswap_64(host_64bits);
170+
}
171+
#endif // HAVE_DECL_HTOBE64
172+
173+
#if HAVE_DECL_HTOLE64 == 0
174+
inline uint64_t htole64(uint64_t host_64bits)
175+
{
176+
return host_64bits;
177+
}
178+
#endif // HAVE_DECL_HTOLE64
179+
180+
#if HAVE_DECL_BE64TOH == 0
181+
inline uint64_t be64toh(uint64_t big_endian_64bits)
182+
{
183+
return bswap_64(big_endian_64bits);
184+
}
185+
#endif // HAVE_DECL_BE64TOH
186+
187+
#if HAVE_DECL_LE64TOH == 0
188+
inline uint64_t le64toh(uint64_t little_endian_64bits)
189+
{
190+
return little_endian_64bits;
191+
}
192+
#endif // HAVE_DECL_LE64TOH
193+
194+
#endif // WORDS_BIGENDIAN
195+
196+
#endif // BITCOIN_COMPAT_ENDIAN_H

src/crypto/common.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) 2014 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_CRYPTO_COMMON_H
6+
#define BITCOIN_CRYPTO_COMMON_H
7+
8+
#if defined(HAVE_CONFIG_H)
9+
#include "bitcoin-config.h"
10+
#endif
11+
12+
#include <stdint.h>
13+
14+
#include "compat/endian.h"
15+
16+
uint16_t static inline ReadLE16(const unsigned char* ptr)
17+
{
18+
return le16toh(*((uint16_t*)ptr));
19+
}
20+
21+
uint32_t static inline ReadLE32(const unsigned char* ptr)
22+
{
23+
return le32toh(*((uint32_t*)ptr));
24+
}
25+
26+
uint64_t static inline ReadLE64(const unsigned char* ptr)
27+
{
28+
return le64toh(*((uint64_t*)ptr));
29+
}
30+
31+
void static inline WriteLE16(unsigned char* ptr, uint16_t x)
32+
{
33+
*((uint16_t*)ptr) = htole16(x);
34+
}
35+
36+
void static inline WriteLE32(unsigned char* ptr, uint32_t x)
37+
{
38+
*((uint32_t*)ptr) = htole32(x);
39+
}
40+
41+
void static inline WriteLE64(unsigned char* ptr, uint64_t x)
42+
{
43+
*((uint64_t*)ptr) = htole64(x);
44+
}
45+
46+
uint32_t static inline ReadBE32(const unsigned char* ptr)
47+
{
48+
return be32toh(*((uint32_t*)ptr));
49+
}
50+
51+
uint64_t static inline ReadBE64(const unsigned char* ptr)
52+
{
53+
return be64toh(*((uint64_t*)ptr));
54+
}
55+
56+
void static inline WriteBE32(unsigned char* ptr, uint32_t x)
57+
{
58+
*((uint32_t*)ptr) = htobe32(x);
59+
}
60+
61+
void static inline WriteBE64(unsigned char* ptr, uint64_t x)
62+
{
63+
*((uint64_t*)ptr) = htobe64(x);
64+
}
65+
66+
#endif // BITCOIN_CRYPTO_COMMON_H

src/crypto/hmac_sha512.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2014 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include "crypto/hmac_sha512.h"
6+
7+
#include <string.h>
8+
9+
CHMAC_SHA512::CHMAC_SHA512(const unsigned char* key, size_t keylen)
10+
{
11+
unsigned char rkey[128];
12+
if (keylen <= 128) {
13+
memcpy(rkey, key, keylen);
14+
memset(rkey + keylen, 0, 128 - keylen);
15+
} else {
16+
CSHA512().Write(key, keylen).Finalize(rkey);
17+
memset(rkey + 64, 0, 64);
18+
}
19+
20+
for (int n = 0; n < 128; n++)
21+
rkey[n] ^= 0x5c;
22+
outer.Write(rkey, 128);
23+
24+
for (int n = 0; n < 128; n++)
25+
rkey[n] ^= 0x5c ^ 0x36;
26+
inner.Write(rkey, 128);
27+
}
28+
29+
void CHMAC_SHA512::Finalize(unsigned char hash[OUTPUT_SIZE])
30+
{
31+
unsigned char temp[64];
32+
inner.Finalize(temp);
33+
outer.Write(temp, 64).Finalize(hash);
34+
}

0 commit comments

Comments
 (0)