├── .github └── workflows │ └── ci.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── TODO.md ├── apps ├── bitc-cli │ ├── bitc_ui.c │ ├── bitc_ui.h │ ├── main.c │ ├── ncui.c │ ├── ncui.h │ ├── test.c │ └── test.h ├── bitc-ios │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ │ └── Main.storyboard │ ├── BlockDetailViewController.h │ ├── BlockDetailViewController.m │ ├── BlockListController.h │ ├── BlockListController.m │ ├── DashboardController.h │ ├── DashboardController.m │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── Main.storyboard │ ├── WebViewController.h │ ├── WebViewController.m │ ├── app.c │ ├── bitc_ios.c │ ├── bitc_ios.h │ ├── bitc_ui.c │ ├── bitc_ui.h │ └── main.m └── test │ └── lldb.c ├── core ├── addrbook.c ├── addrbook.h ├── base58.c ├── base58.h ├── block-store.c ├── block-store.h ├── bloom.c ├── bloom.h ├── btc-message.c ├── btc-message.h ├── buff.h ├── crypt.c ├── crypt.h ├── hash.c ├── hash.h ├── key.c ├── key.h ├── peer.c ├── peer.h ├── peergroup.c ├── peergroup.h ├── rpc.c ├── rpc.h ├── script.c ├── script.h ├── serialize.c ├── serialize.h ├── txdb.c ├── txdb.h ├── wallet.c └── wallet.h ├── ext ├── include │ ├── build-openssl.sh │ ├── leveldb │ │ ├── c.h │ │ ├── cache.h │ │ ├── comparator.h │ │ ├── db.h │ │ ├── dumpfile.h │ │ ├── env.h │ │ ├── filter_policy.h │ │ ├── iterator.h │ │ ├── options.h │ │ ├── slice.h │ │ ├── status.h │ │ ├── table.h │ │ ├── table_builder.h │ │ └── write_batch.h │ ├── openssl │ └── openssl-1.0.1j │ │ ├── aes.h │ │ ├── asn1.h │ │ ├── asn1_mac.h │ │ ├── asn1t.h │ │ ├── bio.h │ │ ├── blowfish.h │ │ ├── bn.h │ │ ├── buffer.h │ │ ├── camellia.h │ │ ├── cast.h │ │ ├── cmac.h │ │ ├── cms.h │ │ ├── comp.h │ │ ├── conf.h │ │ ├── conf_api.h │ │ ├── crypto.h │ │ ├── des.h │ │ ├── des_old.h │ │ ├── dh.h │ │ ├── dsa.h │ │ ├── dso.h │ │ ├── dtls1.h │ │ ├── e_os2.h │ │ ├── ebcdic.h │ │ ├── ec.h │ │ ├── ecdh.h │ │ ├── ecdsa.h │ │ ├── engine.h │ │ ├── err.h │ │ ├── evp.h │ │ ├── hmac.h │ │ ├── idea.h │ │ ├── krb5_asn.h │ │ ├── kssl.h │ │ ├── lhash.h │ │ ├── md4.h │ │ ├── md5.h │ │ ├── mdc2.h │ │ ├── modes.h │ │ ├── obj_mac.h │ │ ├── objects.h │ │ ├── ocsp.h │ │ ├── opensslconf.h │ │ ├── opensslv.h │ │ ├── ossl_typ.h │ │ ├── pem.h │ │ ├── pem2.h │ │ ├── pkcs12.h │ │ ├── pkcs7.h │ │ ├── pqueue.h │ │ ├── rand.h │ │ ├── rc2.h │ │ ├── rc4.h │ │ ├── ripemd.h │ │ ├── rsa.h │ │ ├── safestack.h │ │ ├── seed.h │ │ ├── sha.h │ │ ├── srp.h │ │ ├── srtp.h │ │ ├── ssl.h │ │ ├── ssl2.h │ │ ├── ssl23.h │ │ ├── ssl3.h │ │ ├── stack.h │ │ ├── symhacks.h │ │ ├── tls1.h │ │ ├── ts.h │ │ ├── txt_db.h │ │ ├── ui.h │ │ ├── ui_compat.h │ │ ├── whrlpool.h │ │ ├── x509.h │ │ ├── x509_vfy.h │ │ └── x509v3.h ├── lib │ ├── libcrypto_iOS.a │ ├── libleveldb.a │ └── libssl_iOS.a └── src │ ├── MurmurHash3 │ └── MurmurHash3.c │ ├── cJSON │ └── cJSON.c │ └── public │ ├── MurmurHash3.h │ └── cJSON.h ├── lib ├── config │ └── config.c ├── file │ └── file.c ├── fx │ └── fx.c ├── hashtable │ └── hashtable.c ├── ip_info │ └── ip_info.c ├── netasync │ └── netasync.c ├── poll │ └── poll.c ├── poolworker │ └── poolworker.c ├── public │ ├── config.h │ ├── file.h │ ├── hashtable.h │ ├── ip_info.h │ ├── netasync.h │ ├── poll.h │ ├── poolworker.h │ └── util.h └── util │ └── util.c ├── public ├── app.h ├── atomic.h ├── basic_defs.h ├── bitc-defs.h ├── bitc.h ├── circlist.h └── fx.h └── valgrind.supp /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: install packages 17 | run: sudo apt-get install -y libleveldb-dev libcurl4-openssl-dev libssl-dev libncurses-dev libleveldb-dev libsnappy-dev 18 | - name: make 19 | run: make 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | gmon* 2 | *.o 3 | *.d 4 | .~ 5 | *.swp 6 | bitc 7 | lldb 8 | tags 9 | cscope* 10 | *core* 11 | log* 12 | vgcore* 13 | *dSYM 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Maxime Austruy 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | OS=$(shell uname -s) 3 | ARCH=$(shell uname -m) 4 | 5 | ifeq ($(ARCH), armv6l) 6 | CC = gcc 7 | else 8 | CC = clang 9 | endif 10 | ASAN = 0 11 | 12 | ### 13 | ### CFLAGS 14 | ### 15 | 16 | CFLAGS = -O1 -MMD -g 17 | CFLAGS += -Wall 18 | ifneq ($(ARCH), armv6l) 19 | CFLAGS += -Wshadow -Wextra 20 | endif 21 | CFLAGS += -Wno-unused-parameter -Wno-sign-compare -Wno-missing-field-initializers 22 | 23 | CFLAGS += -fno-omit-frame-pointer 24 | CFLAGS += -fstack-protector 25 | ifeq ($(ASAN), 1) 26 | ifneq ($(OS), Darwin) 27 | CFLAGS += -fsanitize=address 28 | endif 29 | endif 30 | 31 | ifeq ($(OS), OpenBSD) 32 | CFLAGS += -I/usr/local/include 33 | endif 34 | 35 | CFLAGS += -Ipublic -Ilib/public -Icore/ -Iapps/bitc-cli/ -Iext/src/public 36 | 37 | ### 38 | ### LDOPTS 39 | ### 40 | 41 | LDOPTS = 42 | ifneq ($(OS), Darwin) 43 | ifeq ($(ASAN), 1) 44 | LDOPTS += -fsanitize=address 45 | endif 46 | LDOPTS += -rdynamic 47 | endif 48 | 49 | ifdef P 50 | CFLAGS += -pg 51 | LDOPTS += -pg 52 | endif 53 | 54 | 55 | ### 56 | ### the rest 57 | ### 58 | 59 | LIBS = -lpthread -lssl -lcrypto -lm -lncurses -lpanel -lform -lcurl 60 | LIBS += -lleveldb -lsnappy -lstdc++ 61 | 62 | ifeq ($(OS), OpenBSD) 63 | LIBS += -L/usr/local/lib -lexecinfo 64 | LIBS := $(subst -lsnappy,,$(LIBS)) 65 | endif 66 | 67 | VGRND = valgrind --log-file=/tmp/valgrind.log --leak-check=full --error-exitcode=255 68 | BLDDIR = bld 69 | BTC_BIN = bitc 70 | ALLTARGETS = bitc 71 | 72 | ifndef V 73 | QUIET_CC = @echo ' CC ' $<; 74 | QUIET_LINK = @echo ' LINK ' $@; 75 | QUIET_TEST = >/dev/null 2>&1 76 | endif 77 | 78 | BTC_FILES = core/btc-message.c 79 | BTC_FILES += core/script.c 80 | BTC_FILES += core/peer.c 81 | BTC_FILES += core/peergroup.c 82 | BTC_FILES += core/addrbook.c 83 | BTC_FILES += core/block-store.c 84 | BTC_FILES += core/base58.c 85 | BTC_FILES += core/bloom.c 86 | BTC_FILES += core/key.c 87 | BTC_FILES += core/txdb.c 88 | BTC_FILES += core/wallet.c 89 | BTC_FILES += core/serialize.c 90 | BTC_FILES += core/crypt.c 91 | BTC_FILES += core/rpc.c 92 | BTC_FILES += core/hash.c 93 | 94 | BTC_FILES += lib/hashtable/hashtable.c 95 | BTC_FILES += lib/fx/fx.c 96 | BTC_FILES += lib/util/util.c 97 | BTC_FILES += lib/file/file.c 98 | BTC_FILES += lib/poolworker/poolworker.c 99 | BTC_FILES += lib/config/config.c 100 | BTC_FILES += lib/poll/poll.c 101 | BTC_FILES += lib/netasync/netasync.c 102 | BTC_FILES += lib/ip_info/ip_info.c 103 | 104 | BTC_FILES += ext/src/cJSON/cJSON.c 105 | BTC_FILES += ext/src/MurmurHash3/MurmurHash3.c 106 | 107 | BTC_FILES += apps/bitc-cli/main.c 108 | BTC_FILES += apps/bitc-cli/ncui.c 109 | BTC_FILES += apps/bitc-cli/bitc_ui.c 110 | BTC_FILES += apps/bitc-cli/test.c 111 | 112 | BTC_FILES := $(sort $(BTC_FILES)) 113 | BTC_OBJ := $(patsubst %.c,$(BLDDIR)/%.o,$(BTC_FILES)) 114 | BTC_DEPS := $(patsubst %.c,$(BLDDIR)/%.d,$(BTC_FILES)) 115 | 116 | $(BLDDIR)/%.o: %.c 117 | @mkdir -p $(@D) 118 | $(QUIET_CC)$(CC) $(CFLAGS) -c $< -o $@ 119 | 120 | bitc: $(BTC_OBJ) 121 | $(QUIET_LINK)$(CC) $(LDOPTS) -o $(BTC_BIN) $(BTC_OBJ) $(LIBS) 122 | 123 | # do not move the following line: 124 | -include $(BTC_DEPS) 125 | 126 | inocuoustest: 127 | $(eval VGRND :=) 128 | 129 | test: bitc inocuoustest 130 | ./bitc -t 0 131 | 132 | vg-test: bitc inocuoustest 133 | $(VGRND) ./bitc -t 0 134 | 135 | vg-run: 136 | valgrind --log-file=log --leak-check=full --gen-suppressions=all --suppressions=./valgrind.supp ./bitc 137 | 138 | ### 139 | ### Common 140 | ### 141 | 142 | all: $(ALLTARGETS) 143 | 144 | lldb: apps/test/lldb.c 145 | $(CC) -o ./lldb src/lldb.c -lleveldb 146 | 147 | lines: 148 | find . -name '*.[ch]'|xargs cat|wc -l 149 | 150 | clean: 151 | rm -f $(ALLTARGETS) *~ gmon* 152 | rm -rf $(BLDDIR) 153 | 154 | tags: 155 | rm -f tags 156 | find . -follow \( -name '*.[ch]' \) -a -print | ctags -L - 157 | 158 | cscope: 159 | rm -f cscope* 160 | find . -name '*.[ch]' -print | xargs cscope -b -q 161 | 162 | .PHONY: clean tags cscope 163 | 164 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | ### KNOWN ISSUES 2 | * if at the time the client is shutdown the current block is later orphaned, 3 | the next time we launch the app, the app will resync from the wallet's birth 4 | day. Need to fix-up the synchronization phase. 5 | 6 | --- 7 | 8 | ### CORE 9 | 10 | #### features 11 | * develop workflow and code for multisig, 12 | * stealth address, 13 | * coinjoin ability, 14 | * BIP32 deterministic wallet, 15 | * handle json style commands via socket, 16 | * editor for some kind of coin-selection tool. Consider adding a flag in 17 | wallet.cfg that says whether coins on an address are spendable. 18 | * ability to pay to P2SH/multisig address, 19 | 20 | #### P0 21 | * in case of chain re-org: make sure that only the tx on the 'best chain' are 22 | included in the calculation of the balance, 23 | * improve the algorithm used to download filtered blocks: we currently use a 24 | sliding window that is very wasteful in that it doesn't benefit from the 25 | parallelism that multiple-peers can offer. We should instead identify all 26 | the block-hash that need to be fetched via (getdata + filtered), then proceed 27 | to ask each of our connected peers for a set of merkleblocks. Once we receive 28 | a block from a peer, we send another request until all the blocks have been 29 | handled. Use a bitmap to keep track of blocks. 30 | * keep track of how long a tx we initiated is outstanding and ABORT it after 31 | some time: make sure the coins it used are back to 'unspent' afterwards. 32 | * implement daemon mode with hooks to send email/run script when a new payment 33 | is received/initiated. 34 | * make it easy to import existing keys (i.e. no full rescan needed). 35 | * make it easy to export existing keys: --export 36 | * beef-up the regression suite 37 | * misc synchronization issues: struct config accessed from both ui & main 38 | threads? 39 | * add ability to sign/verify a text message. 40 | * handle socket commands: 41 | https://pay.reddit.com/r/Bitcoin/comments/1wmzba/new_bitc_a_new_thin_spv_bitcoin_client_for/cf5c8fw 42 | 43 | #### P1 44 | * better fee computation: right now, 0.0001 for everything. 45 | https://en.bitcoin.it/wiki/Transaction_fees 46 | * refresh bloom filter used when it becomes too permissive, 47 | * use a lock file: dummy file + pid written in it? 48 | * implement init-table routine, 49 | * populate addr in version msg, 50 | * accept JSON-formatted arbitrary TX as input (sign & broadcast), 51 | 52 | #### P2 53 | * check & warn when running out of disk space, 54 | * full chain client. 55 | 56 | --- 57 | 58 | ### WALLET 59 | 60 | #### P0 61 | * add ability to manage specific wallet (from command line option?) 62 | 63 | #### P1 64 | * add watch-only addresses, 65 | * add possibility to display the available balance per address, 66 | * add a wallet name, 67 | * add ability to manage multiple wallet, 68 | * handle cold wallets, 69 | * offline transactions. 70 | * somehow prune txos: only keep around unspent ones. 71 | 72 | --- 73 | 74 | ### UI 75 | 76 | #### P0 77 | * add a ncurses panel object that can be used to store and select arbitrary 78 | lines, use this to implement: 79 | * panel block: ability to select block and display detailed info, 80 | * panel tx: ability to select tx and display detailed info, 81 | * panel contacts: show ascii qr code, 82 | 83 | #### P1 84 | * other UIs: Cocoa, Qt, Gtk? 85 | * panel peers: average ping time 86 | * add about dialog: version, contact info, web site, btc address, 87 | * improve the color scheme: make it use the colors from the theme solarized: 88 | http://ethanschoonover.com/solarized 89 | 90 | #### P2 91 | * add panel to display more stats: cmd counters, kb/sec, uptime, etc. 92 | * panel contacts: display ASCII QR code for bitcoin address, 93 | * panel wallet: add wallet name, 94 | * add panel to chart BTC/USD, 95 | * add getopt-style options to retrieve & dump a tx, block, header. 96 | * use readline(3) to handle commands typed, 97 | * add a way to hook commands/actions via the keyboard (cf kbdInputCB in 98 | ncui.c), use a vim-like syntax, 99 | 100 | --- 101 | 102 | ### MISC 103 | 104 | * sign binaries, 105 | * package as a .deb for debian/ubuntu, 106 | * test on diverse platforms: arm, big-endian ones, etc. 107 | * internationalization. 108 | -------------------------------------------------------------------------------- /apps/bitc-cli/bitc_ui.h: -------------------------------------------------------------------------------- 1 | #ifndef __BITC_UI_H__ 2 | #define __BITC_UI_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "basic_defs.h" 8 | #include "hash.h" 9 | #include "circlist.h" 10 | 11 | 12 | struct poll_loop; 13 | 14 | struct bitcui_fx { 15 | char *name; 16 | double value; 17 | char *symbol; 18 | }; 19 | 20 | 21 | struct bitcui_tx { 22 | uint256 txHash; 23 | char *src; 24 | char *dst; 25 | int64 value; 26 | uint32 blockHeight; 27 | time_t timestamp; 28 | char *desc; 29 | }; 30 | 31 | 32 | struct bitcui_peer { 33 | struct sockaddr_in saddr; 34 | char *id; 35 | char *host; 36 | char *hostname; 37 | char *versionStr; 38 | uint32 height; 39 | }; 40 | 41 | 42 | struct bitcui_block { 43 | uint32 timestamp; 44 | int height; 45 | uint256 hash; 46 | }; 47 | 48 | 49 | struct bitcui_addr { 50 | char *addr; 51 | char *desc; 52 | int idx; /* only useful when generating the struct */ 53 | }; 54 | 55 | 56 | struct btcui { 57 | bool inuse; 58 | volatile int stop; 59 | pthread_t tid; 60 | struct condvar *cv; 61 | struct poll_loop *poll; 62 | struct mutex *lock; 63 | struct circlist_item *reqList; 64 | 65 | char *statusStr; 66 | time_t statusExpiry; 67 | 68 | /* 69 | * TX. 70 | */ 71 | struct bitcui_tx *tx_info; 72 | int tx_num; 73 | 74 | /* 75 | * peers (alive). 76 | */ 77 | struct bitcui_peer *peer_info; 78 | int peer_num; 79 | 80 | /* 81 | * wallets, keys. 82 | */ 83 | int addr_num; 84 | struct bitcui_addr *addr_info; 85 | 86 | /* 87 | * btc -> ui notification. 88 | */ 89 | bool notifyInit; 90 | int eventFd; 91 | int notifyFd; 92 | 93 | /* 94 | * fx 95 | */ 96 | struct bitcui_fx *fx_pairs; 97 | int fx_num; 98 | char *fx_provider; 99 | uint32 fxPeriodMin; 100 | 101 | /* 102 | * peer info. 103 | */ 104 | int num_peers_active; 105 | int num_peers_alive; 106 | int num_addrs; 107 | int height; 108 | 109 | /* 110 | * ring of recent blocks. 111 | */ 112 | int numBlocks; 113 | int blockProdIdx; 114 | int blockConsIdx; 115 | struct bitcui_block blocks[128]; 116 | 117 | /* 118 | * catch-up stats. 119 | */ 120 | bool updating; 121 | int numhdr; 122 | int hdrtot; 123 | int blk; 124 | int blktot; 125 | }; 126 | 127 | extern struct btcui *btcui; 128 | 129 | void bitcui_set_last_block_info(const uint256 *hash, int height, uint32 ts); 130 | void bitcui_set_catchup_info(int numhdr, int hdrtot, int blk, int blktot); 131 | void bitcui_set_status(const char *fmt, ...) PRINTF_GCC_DECL(1, 2); 132 | void bitcui_set_addrs_info(int num, struct bitcui_addr *addr); 133 | void bitcui_set_tx_info(int num_tx, struct bitcui_tx *tx_info); 134 | void bitcui_set_peer_info(int peers_active, int peers_alive, int num_addrs, 135 | struct bitcui_peer *info_alive); 136 | 137 | char *bitcui_ip2name(const struct sockaddr_in *addr); 138 | void bitcui_free_fx_pairs(struct bitcui_fx *fx_pairs, int fx_num); 139 | void bitcui_fx_update(void); 140 | void bitcui_stop(void); 141 | int bitcui_start(bool withui); 142 | void bitcui_req_notify_info_update(void); 143 | 144 | #endif /* __BITC_UI_H__ */ 145 | -------------------------------------------------------------------------------- /apps/bitc-cli/ncui.h: -------------------------------------------------------------------------------- 1 | #ifndef __NCUI_H__ 2 | #define __NCUI_H__ 3 | 4 | int ncui_init(void); 5 | void ncui_exit(void); 6 | 7 | void ncui_input_cb(void *clientData); 8 | void ncui_time_cb(void *clientData); 9 | void ncui_log_cb(const char *ts, const char *str, void *clientData); 10 | 11 | void ncui_info_update(void); 12 | void ncui_status_update(bool update); 13 | void ncui_wallet_update(void); 14 | void ncui_peers_update(void); 15 | void ncui_tx_update(void); 16 | void ncui_fx_update(void); 17 | 18 | #endif /* __NCUI_H__ */ 19 | -------------------------------------------------------------------------------- /apps/bitc-cli/test.h: -------------------------------------------------------------------------------- 1 | #ifndef __TEST_H__ 2 | #define __TEST_H__ 3 | 4 | int bitc_test(const char *str); 5 | 6 | #endif /* __TEST_H__ */ 7 | -------------------------------------------------------------------------------- /apps/bitc-ios/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // SimpleTest 4 | // 5 | // Created by Maxime Austruy on 05/11/14. 6 | // Copyright (c) 2014 Maxime Austruy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /apps/bitc-ios/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // SimpleTest 4 | // 5 | // Created by Maxime Austruy on 05/11/14. 6 | // Copyright (c) 2014 Maxime Austruy. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "app.h" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "bitc_ui.h" 18 | 19 | @interface AppDelegate () 20 | 21 | @end 22 | 23 | @implementation AppDelegate 24 | 25 | /* 26 | *------------------------------------------------------------------------------ 27 | * 28 | * ReadEventCB -- 29 | * 30 | *------------------------------------------------------------------------------ 31 | */ 32 | 33 | static void 34 | ReadEventCB(CFFileDescriptorRef fdref, 35 | CFOptionFlags callBackTypes, 36 | void *info) 37 | { 38 | int data = 0; 39 | int res; 40 | int fd; 41 | 42 | fd = CFFileDescriptorGetNativeDescriptor(fdref); 43 | res = read(fd, &data, 1); 44 | if (res < 0) { 45 | printf("Failed to read ui fd: %d\n", errno); 46 | 47 | } 48 | 49 | bitcui_process_update(); 50 | 51 | CFFileDescriptorEnableCallBacks(fdref, kCFFileDescriptorReadCallBack); 52 | } 53 | 54 | 55 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 56 | CFFileDescriptorRef fdref; 57 | CFRunLoopSourceRef source; 58 | NSString *path; 59 | int res; 60 | 61 | /* make sure cocoa knows we're multithreaded */ 62 | [[NSThread new] start]; 63 | 64 | path = [ NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject ]; 65 | path = [NSString stringWithFormat:@"%@/../", path ]; 66 | path = [path stringByStandardizingPath]; 67 | 68 | NSLog(@"%@", path); 69 | 70 | res = bitc_app_init([ path UTF8String]); 71 | if (res) { 72 | NSLog(@"bitc_app_init: %d\n", res); 73 | } 74 | 75 | fdref = CFFileDescriptorCreate(kCFAllocatorDefault, btcui->eventFd, false, ReadEventCB, NULL); 76 | CFFileDescriptorEnableCallBacks(fdref, kCFFileDescriptorReadCallBack); 77 | 78 | source = CFFileDescriptorCreateRunLoopSource(kCFAllocatorDefault, fdref, 0); 79 | CFRunLoopAddSource(CFRunLoopGetMain(), source, kCFRunLoopDefaultMode); 80 | 81 | return YES; 82 | } 83 | 84 | - (void)applicationWillResignActive:(UIApplication *)application { 85 | NSLog(@"%s", __FUNCTION__); 86 | } 87 | 88 | - (void)applicationDidEnterBackground:(UIApplication *)application { 89 | NSLog(@"%s", __FUNCTION__); 90 | } 91 | 92 | - (void)applicationWillEnterForeground:(UIApplication *)application { 93 | NSLog(@"%s", __FUNCTION__); 94 | } 95 | 96 | - (void)applicationDidBecomeActive:(UIApplication *)application { 97 | NSLog(@"%s", __FUNCTION__); 98 | } 99 | 100 | - (void)applicationWillTerminate:(UIApplication *)application { 101 | NSLog(@"%s", __FUNCTION__); 102 | } 103 | 104 | @end 105 | -------------------------------------------------------------------------------- /apps/bitc-ios/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /apps/bitc-ios/BlockDetailViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BlockDetailViewController.h 3 | // bitc-ios 4 | // 5 | // Created by Maxime Austruy on 11/7/14. 6 | // Copyright (c) 2014 Maxime Austruy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BlockDetailViewController : UITableViewController 12 | 13 | @property (weak, nonatomic) IBOutlet UILabel *nonceLabel; 14 | @property (weak, nonatomic) IBOutlet UILabel *bitsLabel; 15 | @property (weak, nonatomic) IBOutlet UILabel *blockVersionLabel; 16 | @property (weak, nonatomic) IBOutlet UILabel *timestampLabel; 17 | 18 | @property (strong, nonatomic) NSNumber *blockNumber; 19 | @property (strong, nonatomic) IBOutlet UILabel *blockNumberLabel; 20 | @property (strong, nonatomic) NSString *hashStr; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /apps/bitc-ios/BlockDetailViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // BlockDetailViewController.m 3 | // bitc-ios 4 | // 5 | // Created by Maxime Austruy on 11/7/14. 6 | // Copyright (c) 2014 Maxime Austruy. All rights reserved. 7 | // 8 | 9 | #import "BlockDetailViewController.h" 10 | #import "WebViewController.h" 11 | 12 | #include "block-store.h" 13 | #include "bitc.h" 14 | #include "util.h" 15 | 16 | 17 | @interface BlockDetailViewController () 18 | 19 | @end 20 | 21 | @implementation BlockDetailViewController 22 | 23 | @synthesize blockNumber = _blockNumber; 24 | @synthesize blockNumberLabel = _blockNumberLabel; 25 | 26 | - (void)viewDidLoad { 27 | [super viewDidLoad]; 28 | btc_block_header hdr; 29 | uint256 hash = { 0 }; 30 | char hashStr[80]; 31 | char *ts; 32 | bool s; 33 | int height; 34 | 35 | height = [ _blockNumber integerValue]; 36 | self.title = [ NSString stringWithFormat:@"%u", height ]; 37 | 38 | s = blockstore_get_block_at_height(btc->blockStore, height, &hash, &hdr); 39 | ts = print_time_local(hdr.timestamp, "%a, %d %b %Y %T"); 40 | uint256_snprintf_reverse(hashStr, sizeof hashStr, &hash); 41 | 42 | _hashStr = @(hashStr); 43 | 44 | _timestampLabel.text = [NSString stringWithFormat:@"%s", ts]; 45 | _nonceLabel.text = [NSString stringWithFormat:@"0x%x", hdr.nonce]; 46 | _bitsLabel.text = [NSString stringWithFormat:@"%u", hdr.bits]; 47 | _blockVersionLabel.text = [NSString stringWithFormat:@"%u", hdr.version]; 48 | _blockNumberLabel.text = [NSString stringWithFormat:@"%s", hashStr]; 49 | 50 | free(ts); 51 | NSLog(@"%s: %@", __FUNCTION__, _blockNumber); 52 | } 53 | 54 | - (void)didReceiveMemoryWarning { 55 | [super didReceiveMemoryWarning]; 56 | } 57 | 58 | #pragma mark - Navigation 59 | 60 | -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 61 | { 62 | NSString *s = [ segue identifier ]; 63 | 64 | NSLog(@"%s: %@", __FUNCTION__, s); 65 | 66 | if ([s isEqualToString:@"ShowWebView1"] || 67 | [s isEqualToString:@"ShowWebView2"]) { 68 | WebViewController *viewController = [segue destinationViewController]; 69 | NSLog(@"%s: %@ (block#=%@)", __FUNCTION__, s, _blockNumber); 70 | viewController.hashStr = _hashStr; 71 | } 72 | } 73 | 74 | @end -------------------------------------------------------------------------------- /apps/bitc-ios/BlockListController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BlockListController.h 3 | // SimpleTest 4 | // 5 | // Created by Maxime Austruy on 05/11/14. 6 | // Copyright (c) 2014 Maxime Austruy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface BlockListController : UITableViewController 12 | 13 | @property (strong, nonatomic) IBOutlet UITableView *BlockList; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /apps/bitc-ios/BlockListController.m: -------------------------------------------------------------------------------- 1 | // 2 | // BlockListController.m 3 | // SimpleTest 4 | // 5 | // Created by Maxime Austruy on 05/11/14. 6 | // Copyright (c) 2014 Maxime Austruy. All rights reserved. 7 | // 8 | 9 | #import "BlockListController.h" 10 | #import "BlockDetailViewController.h" 11 | 12 | #include "util.h" 13 | #include "block-store.h" 14 | #include "bitc.h" 15 | 16 | @interface BlockListController () 17 | 18 | @end 19 | 20 | @implementation BlockListController 21 | 22 | static UITableView *blockList; 23 | static int maxHeight; 24 | 25 | void 26 | BlockListAddBlock(int height) 27 | { 28 | if (height == 0 || height == maxHeight) { 29 | return; 30 | } 31 | NSMutableArray *indexPaths = [NSMutableArray array]; 32 | 33 | if (height - maxHeight > 100) { 34 | [blockList reloadData]; 35 | maxHeight = height; 36 | return; 37 | } 38 | 39 | for (int i = 0; i < height - maxHeight; i++) { 40 | [indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]]; 41 | } 42 | 43 | maxHeight = MAX(maxHeight, height); 44 | 45 | [ blockList beginUpdates]; 46 | [ blockList insertRowsAtIndexPaths:indexPaths 47 | withRowAnimation:UITableViewRowAnimationRight]; 48 | [ blockList endUpdates]; 49 | } 50 | 51 | - (void)viewDidLoad { 52 | [super viewDidLoad]; 53 | blockList = _BlockList; 54 | } 55 | 56 | - (void)didReceiveMemoryWarning { 57 | [super didReceiveMemoryWarning]; 58 | } 59 | 60 | #pragma mark - Table view data source 61 | 62 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 63 | return 1; 64 | } 65 | 66 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 67 | return maxHeight; 68 | } 69 | 70 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 71 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BlockCell"]; 72 | int height = maxHeight - (long) indexPath.row; 73 | btc_block_header hdr; 74 | uint256 hash; 75 | bool s; 76 | 77 | s = blockstore_get_block_at_height(btc->blockStore, height, &hash, &hdr); 78 | if (s) { 79 | char hashStr[80]; 80 | char *ts; 81 | 82 | ts = print_time_local_short(hdr.timestamp); 83 | uint256_snprintf_reverse(hashStr, sizeof hashStr, &hash); 84 | 85 | cell.textLabel.text = [NSString stringWithFormat:@"%u -- %s", height, ts]; 86 | cell.detailTextLabel.text = [NSString stringWithFormat:@"%s", hashStr]; 87 | free(ts); 88 | } else { 89 | NSLog(@"not found"); 90 | } 91 | 92 | return cell; 93 | } 94 | 95 | - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 96 | return NO; 97 | } 98 | 99 | - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { 100 | return NO; 101 | } 102 | 103 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 104 | NSString *segueString = [ NSString stringWithFormat:@"ShowBlockDetail" ]; 105 | 106 | [self performSegueWithIdentifier:segueString sender:self]; 107 | } 108 | 109 | 110 | #pragma mark - Navigation 111 | 112 | -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 113 | { 114 | if ([[segue identifier] isEqualToString:@"ShowBlockDetail"]) { 115 | BlockDetailViewController *detailViewController = [segue destinationViewController]; 116 | NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 117 | int height = maxHeight - (long) indexPath.row; 118 | 119 | NSLog(@"%s: %@ (height=%u)", __FUNCTION__, [segue identifier], height); 120 | 121 | detailViewController.blockNumber = @(height); 122 | } 123 | } 124 | 125 | @end 126 | -------------------------------------------------------------------------------- /apps/bitc-ios/DashboardController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.h 3 | // SimpleTest 4 | // 5 | // Created by Maxime Austruy on 05/11/14. 6 | // Copyright (c) 2014 Maxime Austruy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DashboardController : UIViewController 12 | 13 | @property (weak, nonatomic) IBOutlet UILabel *addrsLabel; 14 | @property (weak, nonatomic) IBOutlet UILabel *peersLabel; 15 | @property (weak, nonatomic) IBOutlet UILabel *heightLabel; 16 | @property (weak, nonatomic) IBOutlet UILabel *dateLabel; 17 | @property (weak, nonatomic) IBOutlet UILabel *hashLabel; 18 | 19 | @end 20 | 21 | -------------------------------------------------------------------------------- /apps/bitc-ios/DashboardController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.m 3 | // SimpleTest 4 | // 5 | // Created by Maxime Austruy on 05/11/14. 6 | // Copyright (c) 2014 Maxime Austruy. All rights reserved. 7 | // 8 | 9 | #import "DashboardController.h" 10 | 11 | @interface DashboardController () 12 | 13 | @end 14 | 15 | static UILabel *addrsLbl; 16 | static UILabel *peersLbl; 17 | static UILabel *heightLbl; 18 | static UILabel *dateLbl; 19 | static UILabel *hashLbl; 20 | 21 | void 22 | DashboardUpdate(int height, 23 | const char *hash, 24 | int total, 25 | int connected, 26 | int numAddrs, 27 | const char *date) 28 | { 29 | heightLbl.text = [ NSString stringWithFormat:@"%u", height ]; 30 | dateLbl.text = [ NSString stringWithFormat:@"%s", date ]; 31 | peersLbl.text = [ NSString stringWithFormat:@"%u / %u", connected, total ]; 32 | hashLbl.text = [ NSString stringWithFormat:@"%s", hash ]; 33 | addrsLbl.text = [ NSString stringWithFormat:@"%u", numAddrs ]; 34 | } 35 | 36 | 37 | @implementation DashboardController 38 | 39 | @synthesize addrsLabel = _addrsLabel; 40 | 41 | - (void)viewDidLoad { 42 | [super viewDidLoad]; 43 | NSLog(@"%s", __FUNCTION__); 44 | addrsLbl = _addrsLabel; 45 | peersLbl = _peersLabel; 46 | heightLbl = _heightLabel; 47 | dateLbl = _dateLabel; 48 | hashLbl = _hashLabel; 49 | NSLog(@"%s", __FUNCTION__); 50 | } 51 | 52 | - (void)didReceiveMemoryWarning { 53 | [super didReceiveMemoryWarning]; 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /apps/bitc-ios/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /apps/bitc-ios/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.maustruy.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | Main 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIStatusBarStyle 34 | UIStatusBarStyleDefault 35 | UIStatusBarTintParameters 36 | 37 | UINavigationBar 38 | 39 | Style 40 | UIBarStyleDefault 41 | Translucent 42 | 43 | 44 | 45 | UISupportedInterfaceOrientations 46 | 47 | UIInterfaceOrientationPortrait 48 | UIInterfaceOrientationLandscapeLeft 49 | UIInterfaceOrientationLandscapeRight 50 | 51 | UISupportedInterfaceOrientations~ipad 52 | 53 | UIInterfaceOrientationPortrait 54 | UIInterfaceOrientationPortraitUpsideDown 55 | UIInterfaceOrientationLandscapeLeft 56 | UIInterfaceOrientationLandscapeRight 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /apps/bitc-ios/WebViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // WebViewController.h 3 | // bitc-ios 4 | // 5 | // Created by Maxime Austruy on 13/11/14. 6 | // Copyright (c) 2014 Maxime Austruy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WebViewController : UIViewController 12 | @property (weak, nonatomic) IBOutlet UIWebView *webView; 13 | 14 | @property (strong, nonatomic) NSString *hashStr; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /apps/bitc-ios/WebViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // WebViewController.m 3 | // bitc-ios 4 | // 5 | // Created by Maxime Austruy on 13/11/14. 6 | // Copyright (c) 2014 Maxime Austruy. All rights reserved. 7 | // 8 | 9 | #import "WebViewController.h" 10 | 11 | @implementation WebViewController 12 | 13 | 14 | - (void)viewDidLoad { 15 | [super viewDidLoad]; 16 | NSLog(@"%s", __FUNCTION__); 17 | NSString *urlStr = [ NSString stringWithFormat: 18 | @"http://blockchain.info/block-index/%@", _hashStr ]; 19 | NSURL *url = [NSURL URLWithString:urlStr]; 20 | NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 21 | 22 | NSLog(@"%@", urlStr); 23 | [ _webView loadRequest:requestObj]; 24 | } 25 | 26 | - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 27 | { 28 | NSLog(@"Error : %@",error); 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /apps/bitc-ios/bitc_ios.c: -------------------------------------------------------------------------------- 1 | // 2 | // bitc_ios.c 3 | // bitc-ios 4 | // 5 | // Created by Maxime Austruy on 11/11/14. 6 | // Copyright (c) 2014 Maxime Austruy. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | 12 | #include "bitc_ios.h" 13 | #include "bitc_ui.h" 14 | #include "util.h" 15 | #include "bitc.h" 16 | #include "block-store.h" 17 | 18 | 19 | /* 20 | *------------------------------------------------------------------- 21 | * 22 | * bitc_ios_log -- 23 | * 24 | *------------------------------------------------------------------- 25 | */ 26 | 27 | void 28 | bitc_ios_log(const char *pfx, 29 | const char *line) 30 | { 31 | LogViewAppend(pfx, line); 32 | } 33 | 34 | 35 | /* 36 | *------------------------------------------------------------------- 37 | * 38 | * bitc_ios_dashboard_update -- 39 | * 40 | *------------------------------------------------------------------- 41 | */ 42 | 43 | void 44 | bitc_ios_dashboard_update(void) 45 | { 46 | btc_block_header hdr; 47 | char hashStr[80]; 48 | char *ts = NULL; 49 | uint256 hash; 50 | int height; 51 | bool s; 52 | 53 | if (btc->blockStore == NULL) { 54 | return; 55 | } 56 | 57 | height = blockstore_get_height(btc->blockStore); 58 | if (height == 0) { 59 | return; 60 | } 61 | 62 | s = blockstore_get_block_at_height(btc->blockStore, height, &hash, &hdr); 63 | 64 | ASSERT(mutex_islocked(btcui->lock)); 65 | 66 | uint256_snprintf_reverse(hashStr, sizeof hashStr, &hash); 67 | ts = print_time_local(hdr.timestamp, "%c"); 68 | 69 | DashboardUpdate(height, hashStr, 70 | btcui->num_peers_active, 71 | btcui->num_peers_alive, 72 | btcui->num_addrs, 73 | ts ? ts : ""); 74 | free(ts); 75 | } 76 | 77 | 78 | /* 79 | *------------------------------------------------------------------- 80 | * 81 | * bitc_ios_blocklist_update -- 82 | * 83 | *------------------------------------------------------------------- 84 | */ 85 | 86 | void 87 | bitc_ios_blocklist_update(void) 88 | { 89 | int height; 90 | 91 | ASSERT(mutex_islocked(btcui->lock)); 92 | 93 | height = blockstore_get_height(btc->blockStore); 94 | BlockListAddBlock(height); 95 | } 96 | 97 | 98 | /* 99 | *------------------------------------------------------------------- 100 | * 101 | * bitc_ios_info_update -- 102 | * 103 | *------------------------------------------------------------------- 104 | */ 105 | 106 | void 107 | bitc_ios_info_update(void) 108 | { 109 | mutex_lock(btcui->lock); 110 | 111 | bitc_ios_dashboard_update(); 112 | bitc_ios_blocklist_update(); 113 | 114 | mutex_unlock(btcui->lock); 115 | } 116 | -------------------------------------------------------------------------------- /apps/bitc-ios/bitc_ios.h: -------------------------------------------------------------------------------- 1 | // 2 | // bitc_ios.h 3 | // bitc-ios 4 | // 5 | // Created by Maxime Austruy on 11/11/14. 6 | // Copyright (c) 2014 Maxime Austruy. All rights reserved. 7 | // 8 | 9 | #ifndef __bitc_ios__bitc_ios__ 10 | #define __bitc_ios__bitc_ios__ 11 | 12 | #include 13 | 14 | void 15 | LogViewAppend(const char *pfx, 16 | const char *line); 17 | 18 | void 19 | DashboardUpdate(int height, 20 | const char *hash, 21 | int connected, 22 | int total, int numAddrs, 23 | const char *date); 24 | 25 | void BlockListAddBlock(int height); 26 | 27 | 28 | void bitc_ios_log(const char *pfx, const char *line); 29 | void bitc_ios_info_update(void); 30 | 31 | #endif /* defined(__bitc_ios__bitc_ios__) */ 32 | -------------------------------------------------------------------------------- /apps/bitc-ios/bitc_ui.h: -------------------------------------------------------------------------------- 1 | #ifndef __BITC_UI_H__ 2 | #define __BITC_UI_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "basic_defs.h" 8 | #include "hash.h" 9 | #include "circlist.h" 10 | 11 | 12 | struct poll_loop; 13 | 14 | struct bitcui_fx { 15 | char *name; 16 | double value; 17 | char *symbol; 18 | }; 19 | 20 | 21 | struct bitcui_tx { 22 | uint256 txHash; 23 | char *src; 24 | char *dst; 25 | int64 value; 26 | uint32 blockHeight; 27 | time_t timestamp; 28 | char *desc; 29 | }; 30 | 31 | 32 | struct bitcui_peer { 33 | struct sockaddr_in saddr; 34 | char *id; 35 | char *host; 36 | char *hostname; 37 | char *versionStr; 38 | uint32 height; 39 | }; 40 | 41 | 42 | struct bitcui_block { 43 | uint32 timestamp; 44 | int height; 45 | uint256 hash; 46 | }; 47 | 48 | 49 | struct bitcui_addr { 50 | char *addr; 51 | char *desc; 52 | int idx; /* only useful when generating the struct */ 53 | }; 54 | 55 | 56 | struct btcui { 57 | bool inuse; 58 | volatile int stop; 59 | pthread_t tid; 60 | struct condvar *cv; 61 | struct poll_loop *poll; 62 | struct mutex *lock; 63 | struct circlist_item *reqList; 64 | 65 | char *statusStr; 66 | time_t statusExpiry; 67 | 68 | /* 69 | * TX. 70 | */ 71 | struct bitcui_tx *tx_info; 72 | int tx_num; 73 | 74 | /* 75 | * peers (alive). 76 | */ 77 | struct bitcui_peer *peer_info; 78 | int peer_num; 79 | 80 | /* 81 | * wallets, keys. 82 | */ 83 | int addr_num; 84 | struct bitcui_addr *addr_info; 85 | 86 | /* 87 | * btc -> ui notification. 88 | */ 89 | bool notifyInit; 90 | int eventFd; 91 | int notifyFd; 92 | 93 | /* 94 | * fx 95 | */ 96 | struct bitcui_fx *fx_pairs; 97 | int fx_num; 98 | char *fx_provider; 99 | uint32 fxPeriodMin; 100 | 101 | /* 102 | * peer info. 103 | */ 104 | int num_peers_active; 105 | int num_peers_alive; 106 | int num_addrs; 107 | int height; 108 | 109 | /* 110 | * ring of recent blocks. 111 | */ 112 | int numBlocks; 113 | int blockProdIdx; 114 | int blockConsIdx; 115 | struct bitcui_block blocks[128]; 116 | 117 | /* 118 | * catch-up stats. 119 | */ 120 | bool updating; 121 | int numhdr; 122 | int hdrtot; 123 | int blk; 124 | int blktot; 125 | }; 126 | 127 | extern struct btcui *btcui; 128 | 129 | void bitcui_set_last_block_info(const uint256 *hash, int height, uint32 ts); 130 | void bitcui_set_catchup_info(int numhdr, int hdrtot, int blk, int blktot); 131 | void bitcui_set_status(const char *fmt, ...) PRINTF_GCC_DECL(1, 2); 132 | void bitcui_set_addrs_info(int num, struct bitcui_addr *addr); 133 | void bitcui_set_tx_info(int num_tx, struct bitcui_tx *tx_info); 134 | void bitcui_set_peer_info(int peers_active, int peers_alive, int num_addrs, 135 | struct bitcui_peer *info_alive); 136 | 137 | char *bitcui_ip2name(const struct sockaddr_in *addr); 138 | void bitcui_free_fx_pairs(struct bitcui_fx *fx_pairs, int fx_num); 139 | void bitcui_fx_update(void); 140 | void bitcui_stop(void); 141 | int bitcui_start(bool withui); 142 | void bitcui_req_notify_info_update(void); 143 | int bitcui_init(void); 144 | void bitcui_process_update(void); 145 | 146 | #endif /* __BITC_UI_H__ */ 147 | -------------------------------------------------------------------------------- /apps/bitc-ios/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SimpleTest 4 | // 5 | // Created by Maxime Austruy on 05/11/14. 6 | // Copyright (c) 2014 Maxime Austruy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /apps/test/lldb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int 8 | main(int argc, char *argv[]) 9 | { 10 | char *name; 11 | int create = 0; 12 | int info = 0; 13 | int list = 0; 14 | int fill = 0; 15 | char c; 16 | 17 | while ((c = getopt(argc, argv, "chilf")) != EOF) { 18 | switch (c) { 19 | case 'c': 20 | printf("create\n"); 21 | create = 1; 22 | break; 23 | case 'f': 24 | printf("write-data\n"); 25 | fill = 1; 26 | break; 27 | case 'i': 28 | printf("get-info\n"); 29 | info = 1; 30 | break; 31 | case 'l': 32 | printf("list-contents\n"); 33 | list = 1; 34 | break; 35 | case 'h': 36 | default: 37 | printf("lldb: option chil\n"); 38 | return 1; 39 | } 40 | } 41 | leveldb_options_t *options; 42 | leveldb_t *db; 43 | char *errStr = NULL; 44 | 45 | name = argv[optind]; 46 | if (name == NULL) { 47 | printf("Specify db name on cmd line.\n"); 48 | return 1; 49 | } 50 | 51 | options = leveldb_options_create(); 52 | if (create) { 53 | leveldb_options_set_create_if_missing(options, 1); 54 | leveldb_options_set_error_if_exists(options, 1); 55 | } 56 | 57 | printf("Opening: %s\n", name); 58 | db = leveldb_open(options, name, &errStr); 59 | if (db == NULL) { 60 | printf("failed to open '%s': %s\n", name, errStr); 61 | return 1; 62 | } 63 | if (fill) { 64 | leveldb_writeoptions_t *writeopts; 65 | leveldb_writebatch_t* wb; 66 | 67 | writeopts = leveldb_writeoptions_create(); 68 | leveldb_writeoptions_set_sync(writeopts, 1); 69 | 70 | wb = leveldb_writebatch_create(); 71 | 72 | leveldb_writebatch_put(wb, "bar", 3, "b", 1); 73 | leveldb_writebatch_put(wb, "box", 3, "c", 1); 74 | leveldb_writebatch_delete(wb, "bar", 3); 75 | 76 | leveldb_writeoptions_destroy(writeopts); 77 | leveldb_write(db, writeopts, wb, &errStr); 78 | } 79 | 80 | if (list) { 81 | leveldb_readoptions_t* readopts; 82 | leveldb_iterator_t *iter; 83 | 84 | readopts = leveldb_readoptions_create(); 85 | leveldb_readoptions_set_verify_checksums(readopts, 1); 86 | leveldb_readoptions_set_fill_cache(readopts, 0); 87 | 88 | iter = leveldb_create_iterator(db, readopts); 89 | leveldb_iter_seek_to_first(iter); 90 | 91 | while (leveldb_iter_valid(iter)) { 92 | const char *key; 93 | const char *val; 94 | size_t klen; 95 | size_t vlen; 96 | 97 | key = leveldb_iter_key(iter, &klen); 98 | val = leveldb_iter_value(iter, &vlen); 99 | 100 | printf("k=%s vlen=%zu\n", key, vlen); 101 | 102 | leveldb_iter_next(iter); 103 | } 104 | 105 | leveldb_readoptions_destroy(readopts); 106 | leveldb_iter_destroy(iter); 107 | } 108 | 109 | char *prop = leveldb_property_value(db, "leveldb.stats"); 110 | if (prop) { 111 | printf("prop='%s'\n", prop); 112 | free(prop); 113 | } 114 | 115 | leveldb_options_destroy(options); 116 | leveldb_close(db); 117 | 118 | return 0; 119 | } 120 | 121 | -------------------------------------------------------------------------------- /core/addrbook.h: -------------------------------------------------------------------------------- 1 | #ifndef __ADDRBOOK_H__ 2 | #define __ADDRBOOK_H__ 3 | 4 | #include "config.h" 5 | #include "bitc-defs.h" 6 | 7 | struct addrbook; 8 | 9 | struct peer_addr { 10 | btc_msg_address addr; 11 | uint32 connected:1; 12 | uint32 triedalready:1; 13 | uint32 unused:30; 14 | }; 15 | 16 | 17 | int addrbook_open(struct config *config, struct addrbook **bookOut); 18 | int addrbook_close(struct addrbook *book); 19 | uint32 addrbook_get_count(const struct addrbook *book); 20 | bool addrbook_add_entry(struct addrbook *book, struct peer_addr *paddr); 21 | void addrbook_zap(struct config *config); 22 | struct peer_addr* addrbook_get_rand_addr(const struct addrbook *book); 23 | void addrbook_remove_entry(struct addrbook *book, const struct peer_addr *paddr); 24 | void addrbook_replace_entry(struct addrbook *book, struct peer_addr *paddr); 25 | 26 | #endif /* __ADDRBOOK_H__ */ 27 | -------------------------------------------------------------------------------- /core/base58.h: -------------------------------------------------------------------------------- 1 | #ifndef __BASE58_H__ 2 | #define __BASE58_H__ 3 | 4 | #include "hash.h" 5 | 6 | enum key_address { 7 | PUBKEY_ADDRESS = 0, 8 | SCRIPT_ADDRESS = 5, 9 | PRIVKEY_ADDRESS = 128, 10 | PUBKEY_ADDRESS_TEST = 111, 11 | SCRIPT_ADDRESS_TEST = 196, 12 | PRIVKEY_ADDRESS_TEST = 239, 13 | }; 14 | 15 | char *b58_pubkey_from_uint160(const uint160 *digest); 16 | void b58_pubkey_to_uint160(const char *addr, uint160 *digest); 17 | bool b58_pubkey_is_valid(const char *addr); 18 | bool b58_privkey_to_bytes(const char *addr, uint8 **key, size_t *keylen); 19 | char *b58_bytes_to_privkey(const uint8 *key, size_t len); 20 | char *b58_bytes_to_pubkey(const uint8 *key, size_t len); 21 | 22 | #endif /* __BASE58_H__ */ 23 | -------------------------------------------------------------------------------- /core/block-store.h: -------------------------------------------------------------------------------- 1 | #ifndef __BLOCK_STORE_H__ 2 | #define __BLOCK_STORE_H__ 3 | 4 | #include 5 | 6 | #include "hash.h" 7 | #include "btc-message.h" 8 | 9 | struct blockstore; 10 | struct config; 11 | 12 | int blockstore_init(struct config *, struct blockstore **bs); 13 | void blockstore_exit(struct blockstore *bs); 14 | void blockstore_zap(struct config *config); 15 | void blockstore_get_genesis(const struct blockstore *bs, uint256 *hash); 16 | void blockstore_get_best_hash(const struct blockstore *bs, uint256 *hash); 17 | void blockstore_get_next_hashes(struct blockstore *bs, const uint256 *start, 18 | uint256 **hash, int *n); 19 | bool blockstore_add_header(struct blockstore *bs, const btc_block_header *hdr, 20 | const uint256 *hash, bool *orphan); 21 | void blockstore_write_headers(struct blockstore *bs); 22 | bool blockstore_has_header(const struct blockstore *bs, const uint256 *hash); 23 | bool blockstore_is_orphan(const struct blockstore *bs, const uint256 *hash); 24 | bool blockstore_is_block_known(const struct blockstore *bs, const uint256 *hash); 25 | int blockstore_get_height(const struct blockstore *bs); 26 | int blockstore_get_block_height(struct blockstore *bs, const uint256 *hash); 27 | void blockstore_get_hash_from_birth(const struct blockstore *bs, uint64 b, uint256 *h); 28 | bool blockstore_is_next(struct blockstore *bs, const uint256 *p, const uint256 *n); 29 | time_t blockstore_get_timestamp(const struct blockstore *bs); 30 | time_t blockstore_get_block_timestamp(const struct blockstore *bs, 31 | const uint256 *h); 32 | void blockstore_get_highest(struct blockstore *bs, 33 | const uint256 *hash0, 34 | const uint256 *hash1, 35 | uint256 *hash); 36 | void blockstore_get_locator_hashes(const struct blockstore *bs, 37 | uint256 **hash, int *num); 38 | bool 39 | blockstore_get_block_at_height(struct blockstore *bs, int height, uint256 *hash, 40 | btc_block_header *header); 41 | 42 | #endif /* __BLOCK_STORE_H__ */ 43 | -------------------------------------------------------------------------------- /core/bloom.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "bitc-defs.h" 5 | #include "bloom.h" 6 | #include "MurmurHash3.h" 7 | #include "util.h" 8 | 9 | #define LGPFX "BLOOM:" 10 | 11 | #define LN2SQUARED 0.4804530139182014246671025263266649717305529515945455L 12 | #define LN2 0.6931471805599453094172321214581765680755001343602552L 13 | 14 | static const uint8 bit_mask[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; 15 | 16 | struct bloom_filter { 17 | uint8 *filter; 18 | uint32 filterSize; 19 | uint32 numHashFuncs; 20 | uint32 tweak; 21 | }; 22 | 23 | 24 | /* 25 | *------------------------------------------------------------------------- 26 | * 27 | * bloom_create -- 28 | * 29 | *------------------------------------------------------------------------- 30 | */ 31 | 32 | struct bloom_filter * 33 | bloom_create(int n, 34 | double fp) 35 | { 36 | struct bloom_filter *f; 37 | 38 | f = safe_malloc(sizeof *f); 39 | f->filterSize = MIN((uint32)(-1 / LN2SQUARED * n * log(fp)), 40 | MAX_BLOOM_FILTER_SIZE * 8) / 8; 41 | f->filter = safe_calloc(1, f->filterSize); 42 | ASSERT(f->filterSize <= MAX_BLOOM_FILTER_SIZE); 43 | f->numHashFuncs = MIN((uint32)(f->filterSize * 8 / n * LN2), MAX_HASH_FUNCS); 44 | ASSERT(f->numHashFuncs <= MAX_HASH_FUNCS); 45 | f->tweak = 5; /* XXX */ 46 | 47 | Log(LGPFX" filterSize=%u numHashFuncs=%u tweak=%u\n", 48 | f->filterSize, f->numHashFuncs, f->tweak); 49 | 50 | return f; 51 | } 52 | 53 | 54 | /* 55 | *------------------------------------------------------------------------- 56 | * 57 | * bloom_hash -- 58 | * 59 | *------------------------------------------------------------------------- 60 | */ 61 | 62 | static uint32 63 | bloom_hash(const struct bloom_filter *f, 64 | uint32 funIdx, 65 | const uint8 *data, 66 | size_t len) 67 | { 68 | uint32 h; 69 | 70 | h = MurmurHash3(data, len, funIdx * 0xFBA4C795 + f->tweak); 71 | 72 | return h % (f->filterSize * 8); 73 | } 74 | 75 | 76 | /* 77 | *------------------------------------------------------------------------- 78 | * 79 | * bloom_add -- 80 | * 81 | *------------------------------------------------------------------------- 82 | */ 83 | 84 | void 85 | bloom_add(struct bloom_filter *f, 86 | const void *data, 87 | size_t len) 88 | { 89 | int i; 90 | 91 | for (i = 0; i < f->numHashFuncs; i++) { 92 | uint32 idx = bloom_hash(f, i, data, len); 93 | 94 | ASSERT((idx >> 3) < f->filterSize); 95 | 96 | f->filter[idx >> 3] |= bit_mask[7 & idx]; 97 | } 98 | } 99 | 100 | 101 | /* 102 | *------------------------------------------------------------------------- 103 | * 104 | * bloom_free -- 105 | * 106 | *------------------------------------------------------------------------- 107 | */ 108 | 109 | void 110 | bloom_free(struct bloom_filter *f) 111 | { 112 | if (f == NULL) { 113 | return; 114 | } 115 | free(f->filter); 116 | free(f); 117 | } 118 | 119 | 120 | /* 121 | *------------------------------------------------------------------------- 122 | * 123 | * bloom_getinfo -- 124 | * 125 | *------------------------------------------------------------------------- 126 | */ 127 | 128 | void 129 | bloom_getinfo(const struct bloom_filter *f, 130 | uint8 **filter, 131 | uint32 *filterSize, 132 | uint32 *numHashFuncs, 133 | uint32 *tweak) 134 | { 135 | ASSERT(f); 136 | 137 | *filter = f->filter; 138 | *filterSize = f->filterSize; 139 | *numHashFuncs = f->numHashFuncs; 140 | *tweak = f->tweak; 141 | } 142 | -------------------------------------------------------------------------------- /core/bloom.h: -------------------------------------------------------------------------------- 1 | #ifndef __BLOOM_H__ 2 | #define __BLOOM_H__ 3 | 4 | #include "basic_defs.h" 5 | 6 | struct bloom_filter; 7 | 8 | struct bloom_filter * bloom_create(int n, double falsePositive); 9 | void bloom_free(struct bloom_filter *f); 10 | void bloom_add(struct bloom_filter *f, const void *data, size_t len); 11 | void bloom_getinfo(const struct bloom_filter *f, uint8 **filter, 12 | uint32 *filterSize, uint32 *numHashFuncs, uint32 *tweak); 13 | 14 | #endif /* __BLOOM_H__ */ 15 | -------------------------------------------------------------------------------- /core/btc-message.h: -------------------------------------------------------------------------------- 1 | #ifndef __BTC_MESSAGE_H__ 2 | #define __BTC_MESSAGE_H__ 3 | 4 | #include "basic_defs.h" 5 | #include "bitc-defs.h" 6 | #include "hash.h" 7 | 8 | struct buff; 9 | 10 | const char *btcmsg_type_to_str(enum btc_msg_type type); 11 | enum btc_msg_type btcmsg_str_to_type(const char str[12]); 12 | 13 | void btcmsg_print_header(const btc_block_header *header); 14 | void btcmsg_print_block(const btc_msg_block *blk); 15 | void btcmsg_print_version(const char *pfx, const btc_msg_version *v); 16 | void btcmsg_print_tx(const btc_msg_tx *tx); 17 | void btcmsg_print_txout(const btc_msg_tx_out *txOut); 18 | void btcmsg_print_txin(const btc_msg_tx_in *txIn); 19 | 20 | int btcmsg_craft_version(struct buff **buf); 21 | int btcmsg_craft_verack(struct buff **buf); 22 | int btcmsg_craft_filterload(const btc_msg_filterload *fl, struct buff **buf); 23 | int btcmsg_craft_getaddr(struct buff **buf); 24 | int btcmsg_craft_mempool(struct buff **buf); 25 | int btcmsg_craft_getblocks(const uint256 *hashes, int n, struct buff **bufOut); 26 | int btcmsg_craft_pong(uint32 protversion, uint64 nonce, struct buff **buf); 27 | int btcmsg_craft_ping(uint32 protversion, uint64 nonce, struct buff **buf); 28 | int btcmsg_craft_tx(struct buff *txBuf, struct buff **bufOut); 29 | int btcmsg_craft_addr(uint32 protversion, const struct btc_msg_address *addrs, 30 | size_t numAddrs, struct buff **buf); 31 | int btcmsg_craft_getheaders(const uint256 *hashes, int n, 32 | const uint256 *genesis, 33 | struct buff **buf); 34 | int btcmsg_craft_getdata(struct buff **bufOut, enum btc_inv_type type, 35 | const uint256 *hash, int numHash); 36 | int btcmsg_craft_inv(struct buff **bufOut, enum btc_inv_type type, 37 | const uint256 *hash, int n); 38 | 39 | int btcmsg_parse_notfound(struct buff *buf); 40 | int btcmsg_parse_version(struct buff *buf, btc_msg_version *version); 41 | int btcmsg_parse_alert(struct buff *buf); 42 | int btcmsg_parse_pingpong(uint32 protversion, struct buff *buf, uint64 *nonce); 43 | int btcmsg_parse_inv(struct buff *buf, btc_msg_inv **invOut, int *num); 44 | int btcmsg_parse_headers(struct buff *buf, btc_block_header **h, int *num); 45 | int btcmsg_parse_block(struct buff *buf, btc_msg_block *blk); 46 | int btcmsg_parse_merkleblock(struct buff *buf, btc_msg_merkleblock **blkOut); 47 | int btcmsg_parse_addr(uint32 prot, struct buff *buf, 48 | struct btc_msg_address ***addrs, size_t *numAddrs); 49 | 50 | bool btcmsg_header_valid(const btc_msg_header *hdr); 51 | bool btcmsg_payload_valid(const struct buff *recvBuf, const uint8 cksum[4]); 52 | 53 | struct btc_msg_tx * btc_msg_tx_dup(const struct btc_msg_tx *tx0); 54 | void btc_msg_tx_free(btc_msg_tx *tx); 55 | void btc_msg_tx_init(btc_msg_tx *tx); 56 | uint64 btc_msg_tx_value(const btc_msg_tx *tx); 57 | 58 | void btc_msg_block_free(btc_msg_block *blk); 59 | void btc_msg_merkleblock_free(btc_msg_merkleblock *blk); 60 | 61 | #endif /* __BTC_MESSAGE_H__ */ 62 | -------------------------------------------------------------------------------- /core/crypt.h: -------------------------------------------------------------------------------- 1 | #ifndef __CRYPT_H__ 2 | #define __CRYPT_H__ 3 | 4 | #include "basic_defs.h" 5 | 6 | #define CRYPT_KEY_LEN 32 7 | #define CRYPT_IV_LEN 32 8 | #define CRYPT_SALT_LEN 8 9 | 10 | #define CRYPT_NUM_ITERATIONS_OLD 1337 11 | #define CRYPT_NUM_ITERATIONS_MIN 25000 12 | 13 | struct secure_area { 14 | size_t alloc_len; 15 | size_t len; 16 | uint8 buf[]; 17 | }; 18 | 19 | struct secure_area* secure_alloc(size_t len); 20 | void secure_free(struct secure_area *area); 21 | 22 | struct crypt_key { 23 | uint8 key[CRYPT_KEY_LEN]; 24 | uint8 iv[CRYPT_IV_LEN]; 25 | uint8 salt[CRYPT_SALT_LEN]; 26 | }; 27 | 28 | 29 | bool 30 | crypt_encrypt(struct crypt_key *ckey, 31 | const struct secure_area *sec, 32 | uint8 **cipher, size_t *cipher_len); 33 | 34 | bool 35 | crypt_decrypt(struct crypt_key *ckey, 36 | const uint8 *cipher, size_t cipher_len, 37 | struct secure_area **plaintext); 38 | 39 | bool 40 | crypt_set_key_from_passphrase(const struct secure_area *pass, 41 | struct crypt_key *ckey, 42 | int64 *count_ptr); 43 | 44 | void 45 | crypt_hmac_sha256(const void *text, size_t text_len, 46 | const uint8 *key, size_t key_len, 47 | uint256 *digest); 48 | 49 | #endif /* __CRYPT_H__ */ 50 | -------------------------------------------------------------------------------- /core/hash.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifdef __APPLE__ 5 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 6 | #endif 7 | #include 8 | #include 9 | 10 | #include "hash.h" 11 | #include "util.h" 12 | 13 | 14 | /* 15 | *------------------------------------------------------------------------- 16 | * 17 | * uint256_from_str -- 18 | * 19 | *------------------------------------------------------------------------- 20 | */ 21 | 22 | bool 23 | uint256_from_str(const char *str, 24 | uint256 *hash) 25 | { 26 | int i; 27 | 28 | if (strlen(str) != 2 * DIGEST_SHA256_LEN) { 29 | return 0; 30 | } 31 | 32 | for (i = 0; i < DIGEST_SHA256_LEN; i++) { 33 | char str0[3] = { 0 }; 34 | uint32 v = 0; 35 | int res; 36 | 37 | memcpy(str0, str + 2 * i, 2); 38 | res = sscanf(str0, "%02x", &v); 39 | if (res != 1) { 40 | return 0; 41 | } 42 | hash->data[DIGEST_SHA256_LEN - i - 1] = v; 43 | } 44 | return 1; 45 | } 46 | 47 | 48 | /* 49 | *--------------------------------------------------- 50 | * 51 | * uint256_reverse -- 52 | * 53 | *--------------------------------------------------- 54 | */ 55 | 56 | static void 57 | uint256_reverse(uint256 *hash) 58 | { 59 | int i; 60 | 61 | for (i = 0; i < ARRAYSIZE(hash->data) / 2; i++) { 62 | uint8 v = hash->data[DIGEST_SHA256_LEN - i - 1]; 63 | hash->data[DIGEST_SHA256_LEN - i - 1] = hash->data[i]; 64 | hash->data[i] = v; 65 | } 66 | } 67 | 68 | 69 | /* 70 | *--------------------------------------------------- 71 | * 72 | * uint160_reverse -- 73 | * 74 | *--------------------------------------------------- 75 | */ 76 | 77 | static void 78 | uint160_reverse(uint160 *hash) 79 | { 80 | int i; 81 | 82 | for (i = 0; i < ARRAYSIZE(hash->data) / 2; i++) { 83 | uint8 v = hash->data[DIGEST_RIPEMD160_LEN - i - 1]; 84 | hash->data[DIGEST_RIPEMD160_LEN - i - 1] = hash->data[i]; 85 | hash->data[i] = v; 86 | } 87 | } 88 | 89 | 90 | 91 | /* 92 | *--------------------------------------------------- 93 | * 94 | * uint160_snprintf_reverse -- 95 | * 96 | *--------------------------------------------------- 97 | */ 98 | 99 | void 100 | uint160_snprintf_reverse(char *str, 101 | size_t len, 102 | const uint160 *hash) 103 | { 104 | uint160 h; 105 | 106 | memcpy(&h, hash, sizeof h); 107 | uint160_reverse(&h); 108 | 109 | str_snprintf_bytes(str, len, NULL, h.data, ARRAYSIZE(h.data)); 110 | } 111 | 112 | 113 | 114 | /* 115 | *--------------------------------------------------- 116 | * 117 | * uint256_snprintf_reverse -- 118 | * 119 | *--------------------------------------------------- 120 | */ 121 | 122 | void 123 | uint256_snprintf_reverse(char *str, 124 | size_t len, 125 | const uint256 *hash) 126 | { 127 | uint256 h; 128 | 129 | ASSERT(len >= 2 * sizeof(uint256) + 1); 130 | 131 | memcpy(&h, hash, sizeof h); 132 | uint256_reverse(&h); 133 | 134 | str_snprintf_bytes(str, len, NULL, h.data, ARRAYSIZE(h.data)); 135 | } 136 | 137 | 138 | /* 139 | *--------------------------------------------------- 140 | * 141 | * sha256_calc -- 142 | * 143 | *--------------------------------------------------- 144 | */ 145 | 146 | void 147 | sha256_calc(const void *buf, 148 | size_t bufLen, 149 | uint256 *digest) 150 | { 151 | uint32 digestLen = sizeof *digest; 152 | EVP_MD_CTX *ctx; 153 | 154 | ctx = EVP_MD_CTX_new(); 155 | 156 | EVP_DigestInit(ctx, EVP_sha256()); 157 | EVP_DigestUpdate(ctx, buf, bufLen); 158 | EVP_DigestFinal(ctx, digest->data, &digestLen); 159 | 160 | EVP_MD_CTX_free(ctx); 161 | } 162 | 163 | 164 | /* 165 | *--------------------------------------------------- 166 | * 167 | * hash160_calc -- 168 | * 169 | *--------------------------------------------------- 170 | */ 171 | 172 | void 173 | hash160_calc(const void *buf, 174 | size_t bufLen, 175 | uint160 *digest) 176 | { 177 | uint256 h; 178 | 179 | sha256_calc(buf, bufLen, &h); 180 | RIPEMD160(&h.data[0], sizeof h, digest->data); 181 | } 182 | 183 | 184 | /* 185 | *--------------------------------------------------- 186 | * 187 | * hash256_calc -- 188 | * 189 | *--------------------------------------------------- 190 | */ 191 | 192 | void 193 | hash256_calc(const void *buf, 194 | size_t len, 195 | uint256 *hash) 196 | { 197 | uint256 hash0; 198 | 199 | sha256_calc(buf, len, &hash0); 200 | sha256_calc(&hash0, sizeof hash0, hash); 201 | } 202 | 203 | 204 | /* 205 | *--------------------------------------------------- 206 | * 207 | * hash4_calc -- 208 | * 209 | *--------------------------------------------------- 210 | */ 211 | 212 | void 213 | hash4_calc(const void *buf, 214 | size_t len, 215 | uint8 hash[4]) 216 | { 217 | uint256 hash0; 218 | 219 | hash256_calc(buf, len, &hash0); 220 | memcpy(hash, &hash0.data, 4); 221 | } 222 | 223 | -------------------------------------------------------------------------------- /core/hash.h: -------------------------------------------------------------------------------- 1 | #ifndef __HASH_H__ 2 | #define __HASH_H__ 3 | 4 | #include 5 | #include "basic_defs.h" 6 | 7 | 8 | #define DIGEST_SHA256_LEN 32 9 | #define DIGEST_RIPEMD160_LEN 20 10 | 11 | 12 | typedef struct { 13 | uint8 data[DIGEST_SHA256_LEN]; 14 | } uint256; 15 | 16 | 17 | typedef struct { 18 | uint8 data[DIGEST_RIPEMD160_LEN]; 19 | } uint160; 20 | 21 | 22 | /* 23 | *--------------------------------------------------------------------- 24 | * 25 | * uint160_zero_out -- 26 | * 27 | *--------------------------------------------------------------------- 28 | */ 29 | 30 | static inline void 31 | uint160_zero_out(uint160 *h) 32 | { 33 | memset(h, 0, sizeof *h); 34 | } 35 | 36 | 37 | /* 38 | *--------------------------------------------------------------------- 39 | * 40 | * uint256_zero_out -- 41 | * 42 | *--------------------------------------------------------------------- 43 | */ 44 | 45 | static inline void 46 | uint256_zero_out(uint256 *h) 47 | { 48 | memset(h, 0, sizeof *h); 49 | } 50 | 51 | 52 | /* 53 | *--------------------------------------------------------------------- 54 | * 55 | * uint256_issame -- 56 | * 57 | *--------------------------------------------------------------------- 58 | */ 59 | 60 | static inline bool 61 | uint256_issame(const uint256 *a, 62 | const uint256 *b) 63 | { 64 | return memcmp(a->data, b->data, sizeof *a) == 0; 65 | } 66 | 67 | 68 | /* 69 | *--------------------------------------------------------------------- 70 | * 71 | * uint256_iszero -- 72 | * 73 | *--------------------------------------------------------------------- 74 | */ 75 | 76 | static inline bool 77 | uint256_iszero(const uint256 *h) 78 | { 79 | uint256 zero; 80 | 81 | if (h == NULL) { 82 | return 1; 83 | } 84 | uint256_zero_out(&zero); 85 | 86 | return uint256_issame(&zero, h); 87 | } 88 | 89 | 90 | /* 91 | *--------------------------------------------------------------------- 92 | * 93 | * uint160_issame -- 94 | * 95 | *--------------------------------------------------------------------- 96 | */ 97 | 98 | static inline bool 99 | uint160_issame(const uint160 *a, 100 | const uint160 *b) 101 | { 102 | return memcmp(a->data, b->data, sizeof *a) == 0; 103 | } 104 | 105 | 106 | /* 107 | *--------------------------------------------------------------------- 108 | * 109 | * uint160_iszero -- 110 | * 111 | *--------------------------------------------------------------------- 112 | */ 113 | 114 | static inline bool 115 | uint160_iszero(const uint160 *h) 116 | { 117 | uint160 zero; 118 | 119 | if (h == NULL) { 120 | return 1; 121 | } 122 | uint160_zero_out(&zero); 123 | 124 | return uint160_issame(&zero, h); 125 | } 126 | 127 | 128 | void uint256_snprintf_reverse(char *s, size_t len, const uint256 *h); 129 | void uint160_snprintf_reverse(char *s, size_t len, const uint160 *h); 130 | bool uint256_from_str(const char *str, uint256 *hash); 131 | 132 | void hash256_calc(const void *buf, size_t len, uint256 *hash); 133 | void hash160_calc(const void *buf, size_t bufLen, uint160 *digest); 134 | void hash4_calc(const void *buf, size_t len, uint8 hash[4]); 135 | 136 | void sha256_calc(const void *buf, size_t bufLen, uint256 *digest); 137 | 138 | #endif /* __HASH_H__ */ 139 | -------------------------------------------------------------------------------- /core/key.h: -------------------------------------------------------------------------------- 1 | #ifndef __KEY_H__ 2 | #define __KEY_H__ 3 | 4 | #include "hash.h" 5 | 6 | struct key; 7 | 8 | struct key *key_alloc(void); 9 | struct key *key_generate_new(void); 10 | void key_free(struct key *k); 11 | 12 | bool key_set_privkey(struct key *k, const void *privkey, size_t len); 13 | bool key_get_privkey(struct key *k, uint8 **privkey, size_t *len); 14 | void key_get_pubkey(struct key *k, uint8 **pubkey, size_t *len); 15 | void key_get_pubkey_hash160(const struct key *k, uint160 *hash); 16 | void key_get_pubkey(struct key *k, uint8 **pub, size_t *len); 17 | 18 | bool key_sign(struct key *k, const void *data, size_t len, 19 | uint8 **sig, size_t *siglen); 20 | bool key_verify(struct key *k, const void *data, size_t datalen, 21 | const void *sig, size_t siglen); 22 | 23 | #endif /* __KEY_H__ */ 24 | -------------------------------------------------------------------------------- /core/peer.h: -------------------------------------------------------------------------------- 1 | #ifndef __PEER_H__ 2 | #define __PEER_H__ 3 | 4 | #include "basic_defs.h" 5 | #include "bitc_ui.h" 6 | 7 | struct peer_addr; 8 | struct circlist_item; 9 | struct peer; 10 | 11 | const char *peer_name(const struct peer *peer); 12 | const char *peer_name_li(struct circlist_item *li); 13 | 14 | void peer_add(struct peer_addr *paddr, int seq); 15 | int peer_check_liveness(struct circlist_item *li, mtime_t now); 16 | void peer_destroy(struct circlist_item *li, int err); 17 | int peer_getinfo(struct circlist_item *item, struct bitcui_peer *pinfo); 18 | int peer_on_ready(struct peer *peer); 19 | int peer_on_ready_li(struct circlist_item *li); 20 | 21 | int peer_send_inv(struct circlist_item *item, struct buff *buf); 22 | int peer_send_getheaders(struct peer *peer); 23 | int peer_send_getblocks(struct peer *peer); 24 | int peer_send_mempool(struct peer *peer); 25 | int peer_send_getdata(struct peer *peer, enum btc_inv_type type, 26 | const uint256 *hash, int numHash); 27 | 28 | #endif /* __PEER_H__ */ 29 | -------------------------------------------------------------------------------- /core/peergroup.h: -------------------------------------------------------------------------------- 1 | #ifndef __PEERGROUP_H__ 2 | #define __PEERGROUP_H__ 3 | 4 | #include "basic_defs.h" 5 | #include "bitc-defs.h" 6 | 7 | struct peer; 8 | struct config; 9 | struct buff; 10 | 11 | struct peergroup { 12 | struct circlist_item *peer_list; 13 | 14 | uint32 peerSequence; 15 | uint256 lastFilteredBlockReq; 16 | 17 | bool configNeedWrite; 18 | uint256 lastBlk; 19 | 20 | struct hashtable *hash_broadcast; 21 | 22 | int numFetched; 23 | int numToFetch; 24 | int numHdrFetched; 25 | int numHdrToFetch; 26 | int heightTarget; 27 | 28 | uint32 active; 29 | uint32 maxActive; 30 | uint32 minActiveInit; 31 | 32 | mtime_t startTS; 33 | mtime_t firstConnectTS; 34 | }; 35 | 36 | 37 | 38 | void peergroup_seed(void); 39 | void peergroup_exit(struct peergroup *pg); 40 | void peergroup_zap(struct config *config); 41 | void peergroup_init(struct config *cfg, uint32 maxPeers, uint32 maxPeersInit, 42 | mtime_t peerPeriod); 43 | void peergroup_send_stats_inc(enum btc_msg_type type); 44 | void peergroup_recv_stats_inc(enum btc_msg_type type); 45 | void peergroup_refill(bool init); 46 | void peergroup_notify_destroy(void); 47 | void peergroup_dequeue_peerlist(const struct circlist_item *li); 48 | void peergroup_queue_peerlist(struct circlist_item *li); 49 | 50 | int peergroup_handle_handshake_ok(struct peer *peer, int peerStartingHeight); 51 | int peergroup_handle_merkleblock(struct peer *peer, const btc_msg_merkleblock *blk); 52 | void peergroup_handle_addr(struct peer *peer, btc_msg_address **addrs, 53 | size_t numAddrs); 54 | int peergroup_lookup_broadcast_tx(struct peergroup *pg, const uint256 *hash, 55 | struct buff **bufOut); 56 | void peergroup_stop_broadcast_tx(struct peergroup *pg, const uint256 *hash); 57 | int peergroup_handle_headers(struct peer *peer, int peerStartingHeight, 58 | const btc_block_header *headers, int n); 59 | int peergroup_new_tx_broadcast(struct peergroup *pg, const struct buff *buf, 60 | mtime_t expiry, const uint256 *hash); 61 | 62 | #endif /* __PEERGROUP_H__ */ 63 | -------------------------------------------------------------------------------- /core/rpc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "util.h" 5 | #include "netasync.h" 6 | #include "config.h" 7 | #include "bitc.h" 8 | #include "rpc.h" 9 | 10 | #define LGPFX "RPC:" 11 | 12 | static struct netasync_socket *sock; 13 | 14 | 15 | /* 16 | *------------------------------------------------------------------------- 17 | * 18 | * rpc_exit -- 19 | * 20 | *------------------------------------------------------------------------- 21 | */ 22 | 23 | void 24 | rpc_exit(void) 25 | { 26 | if (sock == NULL) { 27 | return; 28 | } 29 | 30 | netasync_close(sock); 31 | } 32 | 33 | 34 | /* 35 | *------------------------------------------------------------------------- 36 | * 37 | * rpc_accept_cb -- 38 | * 39 | *------------------------------------------------------------------------- 40 | */ 41 | 42 | static void 43 | rpc_accept_cb(struct netasync_socket *socket, 44 | void *clientdata, 45 | int err) 46 | { 47 | ASSERT(err == 0); 48 | 49 | Log(LGPFX" %s:%u -- got a connection.\n", __FUNCTION__, __LINE__); 50 | 51 | netasync_close(socket); // for now. 52 | } 53 | 54 | 55 | /* 56 | *------------------------------------------------------------------------- 57 | * 58 | * rpc_init -- 59 | * 60 | *------------------------------------------------------------------------- 61 | */ 62 | 63 | int 64 | rpc_init(void) 65 | { 66 | struct sockaddr_in addr; 67 | int err; 68 | 69 | if (config_getbool(btc->config, 0, "rpc.enable") == 0) { 70 | Log(LGPFX" %s: rpc disabled\n", __FUNCTION__); 71 | return 0; 72 | } 73 | 74 | Log(LGPFX" %s:%u\n", __FUNCTION__, __LINE__); 75 | 76 | sock = netasync_create(); 77 | 78 | err = netasync_resolve("localhost", 9990, &addr); 79 | if (err != 0) { 80 | Log(LGPFX" failed to resolve: %s (%d)\n", strerror(err), err); 81 | return err; 82 | } 83 | err = netasync_bind(sock, &addr, rpc_accept_cb, NULL); 84 | if (err != 0) { 85 | Log(LGPFX" failed to bind: %s (%d)\n", strerror(err), err); 86 | return err; 87 | } 88 | Log(LGPFX" %s: listening on localhost:999.\n", __FUNCTION__); 89 | 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /core/rpc.h: -------------------------------------------------------------------------------- 1 | #ifndef __RPC_H__ 2 | #define __RPC_H__ 3 | 4 | 5 | int rpc_init(void); 6 | void rpc_exit(void); 7 | 8 | 9 | #endif /* __RPC_H__ */ 10 | -------------------------------------------------------------------------------- /core/script.h: -------------------------------------------------------------------------------- 1 | #ifndef __SCRIPT_H__ 2 | #define __SCRIPT_H__ 3 | 4 | #include "hash.h" 5 | #include "bitc-defs.h" 6 | 7 | struct wallet; 8 | 9 | 10 | enum script_hash_type { 11 | SIGHASH_ALL = 1, 12 | SIGHASH_NONE = 2, 13 | SIGHASH_SINGLE = 3, 14 | SIGHASH_ANYONECANPAY = 0x80, 15 | }; 16 | 17 | 18 | enum script_txout_type { 19 | TX_NONSTANDARD, 20 | TX_PUBKEY, 21 | TX_PUBKEYHASH, 22 | TX_SCRIPTHASH, 23 | TX_MULTISIG, 24 | }; 25 | 26 | 27 | enum script_opcode { 28 | // push value 29 | OP_0 = 0x00, 30 | OP_FALSE = OP_0, 31 | OP_PUSHDATA1 = 0x4c, 32 | OP_PUSHDATA2 = 0x4d, 33 | OP_PUSHDATA4 = 0x4e, 34 | OP_1NEGATE = 0x4f, 35 | OP_RESERVED = 0x50, 36 | OP_1 = 0x51, 37 | OP_TRUE = OP_1, 38 | OP_2 = 0x52, 39 | OP_3 = 0x53, 40 | OP_4 = 0x54, 41 | OP_5 = 0x55, 42 | OP_6 = 0x56, 43 | OP_7 = 0x57, 44 | OP_8 = 0x58, 45 | OP_9 = 0x59, 46 | OP_10 = 0x5a, 47 | OP_11 = 0x5b, 48 | OP_12 = 0x5c, 49 | OP_13 = 0x5d, 50 | OP_14 = 0x5e, 51 | OP_15 = 0x5f, 52 | OP_16 = 0x60, 53 | 54 | // control 55 | OP_NOP = 0x61, 56 | OP_VER = 0x62, 57 | OP_IF = 0x63, 58 | OP_NOTIF = 0x64, 59 | OP_VERIF = 0x65, 60 | OP_VERNOTIF = 0x66, 61 | OP_ELSE = 0x67, 62 | OP_ENDIF = 0x68, 63 | OP_VERIFY = 0x69, 64 | OP_RETURN = 0x6a, 65 | 66 | // stack ops 67 | OP_TOALTSTACK = 0x6b, 68 | OP_FROMALTSTACK = 0x6c, 69 | OP_2DROP = 0x6d, 70 | OP_2DUP = 0x6e, 71 | OP_3DUP = 0x6f, 72 | OP_2OVER = 0x70, 73 | OP_2ROT = 0x71, 74 | OP_2SWAP = 0x72, 75 | OP_IFDUP = 0x73, 76 | OP_DEPTH = 0x74, 77 | OP_DROP = 0x75, 78 | OP_DUP = 0x76, 79 | OP_NIP = 0x77, 80 | OP_OVER = 0x78, 81 | OP_PICK = 0x79, 82 | OP_ROLL = 0x7a, 83 | OP_ROT = 0x7b, 84 | OP_SWAP = 0x7c, 85 | OP_TUCK = 0x7d, 86 | 87 | // splice ops 88 | OP_CAT = 0x7e, 89 | OP_SUBSTR = 0x7f, 90 | OP_LEFT = 0x80, 91 | OP_RIGHT = 0x81, 92 | OP_SIZE = 0x82, 93 | 94 | // bit logic 95 | OP_INVERT = 0x83, 96 | OP_AND = 0x84, 97 | OP_OR = 0x85, 98 | OP_XOR = 0x86, 99 | OP_EQUAL = 0x87, 100 | OP_EQUALVERIFY = 0x88, 101 | OP_RESERVED1 = 0x89, 102 | OP_RESERVED2 = 0x8a, 103 | 104 | // numeric 105 | OP_1ADD = 0x8b, 106 | OP_1SUB = 0x8c, 107 | OP_2MUL = 0x8d, 108 | OP_2DIV = 0x8e, 109 | OP_NEGATE = 0x8f, 110 | OP_ABS = 0x90, 111 | OP_NOT = 0x91, 112 | OP_0NOTEQUAL = 0x92, 113 | 114 | OP_ADD = 0x93, 115 | OP_SUB = 0x94, 116 | OP_MUL = 0x95, 117 | OP_DIV = 0x96, 118 | OP_MOD = 0x97, 119 | OP_LSHIFT = 0x98, 120 | OP_RSHIFT = 0x99, 121 | 122 | OP_BOOLAND = 0x9a, 123 | OP_BOOLOR = 0x9b, 124 | OP_NUMEQUAL = 0x9c, 125 | OP_NUMEQUALVERIFY = 0x9d, 126 | OP_NUMNOTEQUAL = 0x9e, 127 | OP_LESSTHAN = 0x9f, 128 | OP_GREATERTHAN = 0xa0, 129 | OP_LESSTHANOREQUAL = 0xa1, 130 | OP_GREATERTHANOREQUAL = 0xa2, 131 | OP_MIN = 0xa3, 132 | OP_MAX = 0xa4, 133 | 134 | OP_WITHIN = 0xa5, 135 | 136 | // crypto 137 | OP_RIPEMD160 = 0xa6, 138 | OP_SHA1 = 0xa7, 139 | OP_SHA256 = 0xa8, 140 | OP_HASH160 = 0xa9, 141 | OP_HASH256 = 0xaa, 142 | OP_CODESEPARATOR = 0xab, 143 | OP_CHECKSIG = 0xac, 144 | OP_CHECKSIGVERIFY = 0xad, 145 | OP_CHECKMULTISIG = 0xae, 146 | OP_CHECKMULTISIGVERIFY = 0xaf, 147 | 148 | // expansion 149 | OP_NOP1 = 0xb0, 150 | OP_NOP2 = 0xb1, 151 | OP_NOP3 = 0xb2, 152 | OP_NOP4 = 0xb3, 153 | OP_NOP5 = 0xb4, 154 | OP_NOP6 = 0xb5, 155 | OP_NOP7 = 0xb6, 156 | OP_NOP8 = 0xb7, 157 | OP_NOP9 = 0xb8, 158 | OP_NOP10 = 0xb9, 159 | 160 | // template matching params 161 | OP_SMALLINTEGER = 0xfa, 162 | OP_PUBKEYS = 0xfb, 163 | OP_PUBKEYHASH = 0xfd, 164 | OP_PUBKEY = 0xfe, 165 | 166 | OP_INVALIDOPCODE = 0xff, 167 | }; 168 | 169 | 170 | int script_txo_generate(const uint160 *pubkey, uint8 **script, uint64 *len); 171 | int script_sign(struct wallet *wallet, const struct btc_msg_tx_out *txo, 172 | struct btc_msg_tx *tx, uint32 idx, enum script_hash_type hashType); 173 | int script_parse_pubkey_hash(const uint8 *scriptPubKey, size_t scriptLength, 174 | uint160 *pubkey); 175 | 176 | 177 | #endif /* __SCRIPT_H__ */ 178 | -------------------------------------------------------------------------------- /core/serialize.h: -------------------------------------------------------------------------------- 1 | #ifndef __SERIALIZE_H__ 2 | #define __SERIALIZE_H__ 3 | 4 | #include "btc-message.h" 5 | 6 | struct buff; 7 | 8 | 9 | int deserialize_bytes(struct buff *buf, void *val, size_t len); 10 | int deserialize_uint8(struct buff *buf, uint8 *val); 11 | int deserialize_uint16(struct buff *buf, uint16 *val); 12 | int deserialize_uint32(struct buff *buf, uint32 *val); 13 | int deserialize_uint64(struct buff *buf, uint64 *val); 14 | int deserialize_uint256(struct buff *buf, uint256 *val); 15 | int deserialize_varint(struct buff *buf, uint64 *val); 16 | int deserialize_str(struct buff *buf, char *str, size_t len); 17 | int deserialize_str_alloc(struct buff *buf, char **str, size_t *len); 18 | 19 | int deserialize_addr(uint32 v, struct buff *buf, btc_msg_address *addr); 20 | int deserialize_inv(struct buff *buf, btc_msg_inv *inv); 21 | int deserialize_version(struct buff *buf, btc_msg_version *v); 22 | int deserialize_blockheader(struct buff *buf, btc_block_header *hdr); 23 | int deserialize_tx(struct buff *buf, btc_msg_tx *tx); 24 | int deserialize_block(struct buff *buf, btc_msg_block *blk); 25 | 26 | int serialize_bytes(struct buff *buf, const void *val, size_t len); 27 | int serialize_uint8(struct buff *buf, const uint8 val); 28 | int serialize_uint16(struct buff *buf, const uint16 val); 29 | int serialize_uint32(struct buff *buf, const uint32 val); 30 | int serialize_uint64(struct buff *buf, const uint64 val); 31 | int serialize_uint256(struct buff *buf, const uint256 *val); 32 | int serialize_varint(struct buff *buf, const uint64 val); 33 | int serialize_str(struct buff *buf, const char *str); 34 | 35 | int serialize_addr(struct buff *buf, const btc_msg_address *addr); 36 | int serialize_inv(struct buff *buf, const btc_msg_inv *inv); 37 | int serialize_version(struct buff *buf, const btc_msg_version *v); 38 | int serialize_msgheader(struct buff *buf, const btc_msg_header *h); 39 | int serialize_blocklocator(struct buff *buf, const btc_block_locator *bl); 40 | int serialize_tx(struct buff *buf, const btc_msg_tx *tx); 41 | 42 | 43 | #endif /* __SERIALIZE_H__ */ 44 | -------------------------------------------------------------------------------- /core/txdb.h: -------------------------------------------------------------------------------- 1 | #ifndef __TXDB_H__ 2 | #define __TXDB_H__ 3 | 4 | #include "hash.h" 5 | #include "bitc-defs.h" 6 | 7 | struct txdb; 8 | struct config; 9 | struct btc_tx_desc; 10 | 11 | int txdb_zap(struct config *config); 12 | int txdb_open(struct config *c, char **errStr, struct txdb **db); 13 | void txdb_close(struct txdb *db); 14 | bool txdb_has_tx(const struct txdb *txdb, const uint256 *hash); 15 | int txdb_handle_tx(struct txdb *db, const uint256 *blkHash, 16 | const uint8 *buf, size_t len, bool *rel); 17 | int txdb_craft_tx(struct txdb *txdb, const struct btc_tx_desc *tx, 18 | btc_msg_tx *new_tx); 19 | 20 | void txdb_export_tx_info(struct txdb *txdb); 21 | uint64 txdb_get_balance(struct txdb *txdb); 22 | void txdb_confirm_one_tx(struct txdb *txdb, const uint256 *blkHash, 23 | const uint256 *txHash); 24 | 25 | #endif /* __TXDB_H__ */ 26 | -------------------------------------------------------------------------------- /core/wallet.h: -------------------------------------------------------------------------------- 1 | #ifndef __WALLET_H__ 2 | #define __WALLET_H__ 3 | 4 | #include "hash.h" 5 | #include "bitc-defs.h" 6 | #include "bitc.h" 7 | 8 | 9 | struct btc_tx_desc; 10 | struct wallet; 11 | struct config; 12 | struct key; 13 | struct secure_area; 14 | 15 | 16 | struct wallet_pubkey { 17 | uint8 *pkey; 18 | size_t pkey_len; 19 | }; 20 | 21 | 22 | void wallet_close(struct wallet *wallet); 23 | int wallet_open(struct config *cfg, struct secure_area *pass, 24 | char **errStr, struct wallet **wallet); 25 | int wallet_zap_txdb(struct config *config); 26 | int wallet_add_key(struct wallet *wallet, const char *desc, char **btc_addr); 27 | bool wallet_has_tx(struct wallet *wlt, const uint256 *txHash); 28 | char *wallet_get_filename(void); 29 | char *wallet_get_change_addr(struct wallet *wallet); 30 | int wallet_handle_tx(struct wallet *wlt, const uint256 *blkHash, 31 | const uint8 *buf, size_t len); 32 | 33 | uint64 wallet_get_birth(const struct wallet *wallet); 34 | bool wallet_is_pubkey_hash160_mine(const struct wallet *wallet, const uint160 *pub_key); 35 | bool wallet_is_pubkey_spendable(const struct wallet *wallet, const uint160 *pub_key); 36 | int wallet_craft_tx(struct wallet *wlt, const struct btc_tx_desc *tx_desc, btc_msg_tx *tx); 37 | void wallet_confirm_tx_in_block(struct wallet *wallet, const btc_msg_merkleblock *blk); 38 | struct key * wallet_lookup_pubkey(const struct wallet *wallet, const uint160 *pub_key); 39 | bool wallet_verify(struct secure_area *pass, enum wallet_state *wlt_state); 40 | int wallet_encrypt(struct wallet *wallet, struct secure_area *pass); 41 | void wallet_get_bloom_filter_info(const struct wallet *wallet, 42 | uint8 **filter, uint32 *filterSize, 43 | uint32 *numHashFuncs, uint32 *tweak); 44 | 45 | #endif /* __WALLET_H__ */ 46 | -------------------------------------------------------------------------------- /ext/include/build-openssl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script builds the iOS and Mac openSSL libraries 4 | # Download openssl http://www.openssl.org/source/ and place the tarball next to this script 5 | 6 | # Credits: 7 | # https://github.com/st3fan/ios-openssl 8 | # https://github.com/x2on/OpenSSL-for-iPhone/blob/master/build-libssl.sh 9 | 10 | 11 | set -e 12 | 13 | usage () 14 | { 15 | echo "usage: $0 [minimum iOS SDK version (default 7.1)]" 16 | exit 127 17 | } 18 | 19 | if [ $1 -e "-h" ]; then 20 | usage 21 | fi 22 | 23 | if [ -z $1 ]; then 24 | SDK_VERSION="8.1" 25 | else 26 | SDK_VERSION=$1 27 | fi 28 | 29 | OPENSSL_VERSION="openssl-1.0.1j" 30 | DEVELOPER=`xcode-select -print-path` 31 | 32 | buildMac() 33 | { 34 | ARCH=$1 35 | 36 | echo "Building ${OPENSSL_VERSION} for ${ARCH}" 37 | 38 | TARGET="darwin-i386-cc" 39 | 40 | if [[ $ARCH == "x86_64" ]]; then 41 | TARGET="darwin64-x86_64-cc" 42 | fi 43 | 44 | pushd . > /dev/null 45 | cd "${OPENSSL_VERSION}" 46 | ./Configure ${TARGET} --openssldir="/tmp/${OPENSSL_VERSION}-${ARCH}" &> "/tmp/${OPENSSL_VERSION}-${ARCH}.log" 47 | make >> "/tmp/${OPENSSL_VERSION}-${ARCH}.log" 2>&1 48 | make install >> "/tmp/${OPENSSL_VERSION}-${ARCH}.log" 2>&1 49 | make clean >> "/tmp/${OPENSSL_VERSION}-${ARCH}.log" 2>&1 50 | popd > /dev/null 51 | } 52 | 53 | buildIOS() 54 | { 55 | ARCH=$1 56 | 57 | pushd . > /dev/null 58 | cd "${OPENSSL_VERSION}" 59 | 60 | if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; then 61 | PLATFORM="iPhoneSimulator" 62 | else 63 | PLATFORM="iPhoneOS" 64 | sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c" 65 | fi 66 | 67 | export $PLATFORM 68 | export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer" 69 | export CROSS_SDK="${PLATFORM}${SDK_VERSION}.sdk" 70 | export BUILD_TOOLS="${DEVELOPER}" 71 | export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}" 72 | 73 | echo "Building ${OPENSSL_VERSION} for ${PLATFORM} ${SDK_VERSION} ${ARCH}" 74 | 75 | if [[ "${ARCH}" == "x86_64" ]]; then 76 | ./Configure darwin64-x86_64-cc --openssldir="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" &> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log" 77 | else 78 | ./Configure iphoneos-cross --openssldir="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" &> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log" 79 | fi 80 | # add -isysroot to CC= 81 | sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=${SDK_VERSION} !" "Makefile" 82 | 83 | make >> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log" 2>&1 84 | make install >> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log" 2>&1 85 | make clean >> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log" 2>&1 86 | popd > /dev/null 87 | } 88 | 89 | echo "Cleaning up" 90 | rm -rf include/openssl/* lib/* 91 | 92 | mkdir -p lib 93 | mkdir -p include/openssl/ 94 | 95 | rm -rf "/tmp/${OPENSSL_VERSION}-*" 96 | rm -rf "/tmp/${OPENSSL_VERSION}-*.log" 97 | 98 | rm -rf "${OPENSSL_VERSION}" 99 | 100 | if [ ! -e ${OPENSSL_VERSION}.tar.gz ]; then 101 | echo "Downloading ${OPENSSL_VERSION}.tar.gz" 102 | curl -O http://www.openssl.org/source/${OPENSSL_VERSION}.tar.gz 103 | else 104 | echo "Using ${OPENSSL_VERSION}.tar.gz" 105 | fi 106 | 107 | echo "Unpacking openssl" 108 | tar xfz "${OPENSSL_VERSION}.tar.gz" 109 | 110 | 111 | 112 | buildIOS "armv7" 113 | buildIOS "armv7s" 114 | if [[ $SDK_VERSION == "8.1" ]]; then 115 | buildIOS "arm64" 116 | buildIOS "x86_64" 117 | fi 118 | buildIOS "i386" 119 | 120 | echo "Building iOS libraries" 121 | lipo \ 122 | "/tmp/${OPENSSL_VERSION}-iOS-armv7/lib/libcrypto.a" \ 123 | "/tmp/${OPENSSL_VERSION}-iOS-armv7s/lib/libcrypto.a" \ 124 | "/tmp/${OPENSSL_VERSION}-iOS-i386/lib/libcrypto.a" \ 125 | -create -output lib/libcrypto_iOS.a 126 | 127 | lipo \ 128 | "/tmp/${OPENSSL_VERSION}-iOS-armv7/lib/libssl.a" \ 129 | "/tmp/${OPENSSL_VERSION}-iOS-armv7s/lib/libssl.a" \ 130 | "/tmp/${OPENSSL_VERSION}-iOS-i386/lib/libssl.a" \ 131 | -create -output lib/libssl_iOS.a 132 | 133 | if [[ $SDK_VERSION == "8.1" ]]; then 134 | echo "Adding 64-bit libraries" 135 | lipo \ 136 | "lib/libcrypto_iOS.a" \ 137 | "/tmp/${OPENSSL_VERSION}-iOS-arm64/lib/libcrypto.a" \ 138 | "/tmp/${OPENSSL_VERSION}-iOS-x86_64/lib/libcrypto.a" \ 139 | -create -output lib/libcrypto_iOS.a 140 | 141 | lipo \ 142 | "lib/libssl_iOS.a" \ 143 | "/tmp/${OPENSSL_VERSION}-iOS-arm64/lib/libssl.a" \ 144 | "/tmp/${OPENSSL_VERSION}-iOS-x86_64/lib/libssl.a" \ 145 | -create -output lib/libssl_iOS.a 146 | 147 | fi 148 | 149 | echo "Cleaning up" 150 | rm -rf /tmp/${OPENSSL_VERSION}-* 151 | rm -rf ${OPENSSL_VERSION} 152 | 153 | echo "Done" 154 | -------------------------------------------------------------------------------- /ext/include/leveldb/cache.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // A Cache is an interface that maps keys to values. It has internal 6 | // synchronization and may be safely accessed concurrently from 7 | // multiple threads. It may automatically evict entries to make room 8 | // for new entries. Values have a specified charge against the cache 9 | // capacity. For example, a cache where the values are variable 10 | // length strings, may use the length of the string as the charge for 11 | // the string. 12 | // 13 | // A builtin cache implementation with a least-recently-used eviction 14 | // policy is provided. Clients may use their own implementations if 15 | // they want something more sophisticated (like scan-resistance, a 16 | // custom eviction policy, variable cache sizing, etc.) 17 | 18 | #ifndef STORAGE_LEVELDB_INCLUDE_CACHE_H_ 19 | #define STORAGE_LEVELDB_INCLUDE_CACHE_H_ 20 | 21 | #include 22 | #include "leveldb/slice.h" 23 | 24 | namespace leveldb { 25 | 26 | class Cache; 27 | 28 | // Create a new cache with a fixed size capacity. This implementation 29 | // of Cache uses a least-recently-used eviction policy. 30 | extern Cache* NewLRUCache(size_t capacity); 31 | 32 | class Cache { 33 | public: 34 | Cache() { } 35 | 36 | // Destroys all existing entries by calling the "deleter" 37 | // function that was passed to the constructor. 38 | virtual ~Cache(); 39 | 40 | // Opaque handle to an entry stored in the cache. 41 | struct Handle { }; 42 | 43 | // Insert a mapping from key->value into the cache and assign it 44 | // the specified charge against the total cache capacity. 45 | // 46 | // Returns a handle that corresponds to the mapping. The caller 47 | // must call this->Release(handle) when the returned mapping is no 48 | // longer needed. 49 | // 50 | // When the inserted entry is no longer needed, the key and 51 | // value will be passed to "deleter". 52 | virtual Handle* Insert(const Slice& key, void* value, size_t charge, 53 | void (*deleter)(const Slice& key, void* value)) = 0; 54 | 55 | // If the cache has no mapping for "key", returns NULL. 56 | // 57 | // Else return a handle that corresponds to the mapping. The caller 58 | // must call this->Release(handle) when the returned mapping is no 59 | // longer needed. 60 | virtual Handle* Lookup(const Slice& key) = 0; 61 | 62 | // Release a mapping returned by a previous Lookup(). 63 | // REQUIRES: handle must not have been released yet. 64 | // REQUIRES: handle must have been returned by a method on *this. 65 | virtual void Release(Handle* handle) = 0; 66 | 67 | // Return the value encapsulated in a handle returned by a 68 | // successful Lookup(). 69 | // REQUIRES: handle must not have been released yet. 70 | // REQUIRES: handle must have been returned by a method on *this. 71 | virtual void* Value(Handle* handle) = 0; 72 | 73 | // If the cache contains entry for key, erase it. Note that the 74 | // underlying entry will be kept around until all existing handles 75 | // to it have been released. 76 | virtual void Erase(const Slice& key) = 0; 77 | 78 | // Return a new numeric id. May be used by multiple clients who are 79 | // sharing the same cache to partition the key space. Typically the 80 | // client will allocate a new id at startup and prepend the id to 81 | // its cache keys. 82 | virtual uint64_t NewId() = 0; 83 | 84 | private: 85 | void LRU_Remove(Handle* e); 86 | void LRU_Append(Handle* e); 87 | void Unref(Handle* e); 88 | 89 | struct Rep; 90 | Rep* rep_; 91 | 92 | // No copying allowed 93 | Cache(const Cache&); 94 | void operator=(const Cache&); 95 | }; 96 | 97 | } // namespace leveldb 98 | 99 | #endif // STORAGE_LEVELDB_INCLUDE_CACHE_H_ 100 | -------------------------------------------------------------------------------- /ext/include/leveldb/comparator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | class Slice; 13 | 14 | // A Comparator object provides a total order across slices that are 15 | // used as keys in an sstable or a database. A Comparator implementation 16 | // must be thread-safe since leveldb may invoke its methods concurrently 17 | // from multiple threads. 18 | class Comparator { 19 | public: 20 | virtual ~Comparator(); 21 | 22 | // Three-way comparison. Returns value: 23 | // < 0 iff "a" < "b", 24 | // == 0 iff "a" == "b", 25 | // > 0 iff "a" > "b" 26 | virtual int Compare(const Slice& a, const Slice& b) const = 0; 27 | 28 | // The name of the comparator. Used to check for comparator 29 | // mismatches (i.e., a DB created with one comparator is 30 | // accessed using a different comparator. 31 | // 32 | // The client of this package should switch to a new name whenever 33 | // the comparator implementation changes in a way that will cause 34 | // the relative ordering of any two keys to change. 35 | // 36 | // Names starting with "leveldb." are reserved and should not be used 37 | // by any clients of this package. 38 | virtual const char* Name() const = 0; 39 | 40 | // Advanced functions: these are used to reduce the space requirements 41 | // for internal data structures like index blocks. 42 | 43 | // If *start < limit, changes *start to a short string in [start,limit). 44 | // Simple comparator implementations may return with *start unchanged, 45 | // i.e., an implementation of this method that does nothing is correct. 46 | virtual void FindShortestSeparator( 47 | std::string* start, 48 | const Slice& limit) const = 0; 49 | 50 | // Changes *key to a short string >= *key. 51 | // Simple comparator implementations may return with *key unchanged, 52 | // i.e., an implementation of this method that does nothing is correct. 53 | virtual void FindShortSuccessor(std::string* key) const = 0; 54 | }; 55 | 56 | // Return a builtin comparator that uses lexicographic byte-wise 57 | // ordering. The result remains the property of this module and 58 | // must not be deleted. 59 | extern const Comparator* BytewiseComparator(); 60 | 61 | } // namespace leveldb 62 | 63 | #endif // STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ 64 | -------------------------------------------------------------------------------- /ext/include/leveldb/dumpfile.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 7 | 8 | #include 9 | #include "leveldb/env.h" 10 | #include "leveldb/status.h" 11 | 12 | namespace leveldb { 13 | 14 | // Dump the contents of the file named by fname in text format to 15 | // *dst. Makes a sequence of dst->Append() calls; each call is passed 16 | // the newline-terminated text corresponding to a single item found 17 | // in the file. 18 | // 19 | // Returns a non-OK result if fname does not name a leveldb storage 20 | // file, or if the file cannot be read. 21 | Status DumpFile(Env* env, const std::string& fname, WritableFile* dst); 22 | 23 | } // namespace leveldb 24 | 25 | #endif // STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 26 | -------------------------------------------------------------------------------- /ext/include/leveldb/filter_policy.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // A database can be configured with a custom FilterPolicy object. 6 | // This object is responsible for creating a small filter from a set 7 | // of keys. These filters are stored in leveldb and are consulted 8 | // automatically by leveldb to decide whether or not to read some 9 | // information from disk. In many cases, a filter can cut down the 10 | // number of disk seeks form a handful to a single disk seek per 11 | // DB::Get() call. 12 | // 13 | // Most people will want to use the builtin bloom filter support (see 14 | // NewBloomFilterPolicy() below). 15 | 16 | #ifndef STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ 17 | #define STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ 18 | 19 | #include 20 | 21 | namespace leveldb { 22 | 23 | class Slice; 24 | 25 | class FilterPolicy { 26 | public: 27 | virtual ~FilterPolicy(); 28 | 29 | // Return the name of this policy. Note that if the filter encoding 30 | // changes in an incompatible way, the name returned by this method 31 | // must be changed. Otherwise, old incompatible filters may be 32 | // passed to methods of this type. 33 | virtual const char* Name() const = 0; 34 | 35 | // keys[0,n-1] contains a list of keys (potentially with duplicates) 36 | // that are ordered according to the user supplied comparator. 37 | // Append a filter that summarizes keys[0,n-1] to *dst. 38 | // 39 | // Warning: do not change the initial contents of *dst. Instead, 40 | // append the newly constructed filter to *dst. 41 | virtual void CreateFilter(const Slice* keys, int n, std::string* dst) 42 | const = 0; 43 | 44 | // "filter" contains the data appended by a preceding call to 45 | // CreateFilter() on this class. This method must return true if 46 | // the key was in the list of keys passed to CreateFilter(). 47 | // This method may return true or false if the key was not on the 48 | // list, but it should aim to return false with a high probability. 49 | virtual bool KeyMayMatch(const Slice& key, const Slice& filter) const = 0; 50 | }; 51 | 52 | // Return a new filter policy that uses a bloom filter with approximately 53 | // the specified number of bits per key. A good value for bits_per_key 54 | // is 10, which yields a filter with ~ 1% false positive rate. 55 | // 56 | // Callers must delete the result after any database that is using the 57 | // result has been closed. 58 | // 59 | // Note: if you are using a custom comparator that ignores some parts 60 | // of the keys being compared, you must not use NewBloomFilterPolicy() 61 | // and must provide your own FilterPolicy that also ignores the 62 | // corresponding parts of the keys. For example, if the comparator 63 | // ignores trailing spaces, it would be incorrect to use a 64 | // FilterPolicy (like NewBloomFilterPolicy) that does not ignore 65 | // trailing spaces in keys. 66 | extern const FilterPolicy* NewBloomFilterPolicy(int bits_per_key); 67 | 68 | } 69 | 70 | #endif // STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ 71 | -------------------------------------------------------------------------------- /ext/include/leveldb/iterator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // An iterator yields a sequence of key/value pairs from a source. 6 | // The following class defines the interface. Multiple implementations 7 | // are provided by this library. In particular, iterators are provided 8 | // to access the contents of a Table or a DB. 9 | // 10 | // Multiple threads can invoke const methods on an Iterator without 11 | // external synchronization, but if any of the threads may call a 12 | // non-const method, all threads accessing the same Iterator must use 13 | // external synchronization. 14 | 15 | #ifndef STORAGE_LEVELDB_INCLUDE_ITERATOR_H_ 16 | #define STORAGE_LEVELDB_INCLUDE_ITERATOR_H_ 17 | 18 | #include "leveldb/slice.h" 19 | #include "leveldb/status.h" 20 | 21 | namespace leveldb { 22 | 23 | class Iterator { 24 | public: 25 | Iterator(); 26 | virtual ~Iterator(); 27 | 28 | // An iterator is either positioned at a key/value pair, or 29 | // not valid. This method returns true iff the iterator is valid. 30 | virtual bool Valid() const = 0; 31 | 32 | // Position at the first key in the source. The iterator is Valid() 33 | // after this call iff the source is not empty. 34 | virtual void SeekToFirst() = 0; 35 | 36 | // Position at the last key in the source. The iterator is 37 | // Valid() after this call iff the source is not empty. 38 | virtual void SeekToLast() = 0; 39 | 40 | // Position at the first key in the source that at or past target 41 | // The iterator is Valid() after this call iff the source contains 42 | // an entry that comes at or past target. 43 | virtual void Seek(const Slice& target) = 0; 44 | 45 | // Moves to the next entry in the source. After this call, Valid() is 46 | // true iff the iterator was not positioned at the last entry in the source. 47 | // REQUIRES: Valid() 48 | virtual void Next() = 0; 49 | 50 | // Moves to the previous entry in the source. After this call, Valid() is 51 | // true iff the iterator was not positioned at the first entry in source. 52 | // REQUIRES: Valid() 53 | virtual void Prev() = 0; 54 | 55 | // Return the key for the current entry. The underlying storage for 56 | // the returned slice is valid only until the next modification of 57 | // the iterator. 58 | // REQUIRES: Valid() 59 | virtual Slice key() const = 0; 60 | 61 | // Return the value for the current entry. The underlying storage for 62 | // the returned slice is valid only until the next modification of 63 | // the iterator. 64 | // REQUIRES: Valid() 65 | virtual Slice value() const = 0; 66 | 67 | // If an error has occurred, return it. Else return an ok status. 68 | virtual Status status() const = 0; 69 | 70 | // Clients are allowed to register function/arg1/arg2 triples that 71 | // will be invoked when this iterator is destroyed. 72 | // 73 | // Note that unlike all of the preceding methods, this method is 74 | // not abstract and therefore clients should not override it. 75 | typedef void (*CleanupFunction)(void* arg1, void* arg2); 76 | void RegisterCleanup(CleanupFunction function, void* arg1, void* arg2); 77 | 78 | private: 79 | struct Cleanup { 80 | CleanupFunction function; 81 | void* arg1; 82 | void* arg2; 83 | Cleanup* next; 84 | }; 85 | Cleanup cleanup_; 86 | 87 | // No copying allowed 88 | Iterator(const Iterator&); 89 | void operator=(const Iterator&); 90 | }; 91 | 92 | // Return an empty iterator (yields nothing). 93 | extern Iterator* NewEmptyIterator(); 94 | 95 | // Return an empty iterator with the specified status. 96 | extern Iterator* NewErrorIterator(const Status& status); 97 | 98 | } // namespace leveldb 99 | 100 | #endif // STORAGE_LEVELDB_INCLUDE_ITERATOR_H_ 101 | -------------------------------------------------------------------------------- /ext/include/leveldb/slice.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Slice is a simple structure containing a pointer into some external 6 | // storage and a size. The user of a Slice must ensure that the slice 7 | // is not used after the corresponding external storage has been 8 | // deallocated. 9 | // 10 | // Multiple threads can invoke const methods on a Slice without 11 | // external synchronization, but if any of the threads may call a 12 | // non-const method, all threads accessing the same Slice must use 13 | // external synchronization. 14 | 15 | #ifndef STORAGE_LEVELDB_INCLUDE_SLICE_H_ 16 | #define STORAGE_LEVELDB_INCLUDE_SLICE_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace leveldb { 24 | 25 | class Slice { 26 | public: 27 | // Create an empty slice. 28 | Slice() : data_(""), size_(0) { } 29 | 30 | // Create a slice that refers to d[0,n-1]. 31 | Slice(const char* d, size_t n) : data_(d), size_(n) { } 32 | 33 | // Create a slice that refers to the contents of "s" 34 | Slice(const std::string& s) : data_(s.data()), size_(s.size()) { } 35 | 36 | // Create a slice that refers to s[0,strlen(s)-1] 37 | Slice(const char* s) : data_(s), size_(strlen(s)) { } 38 | 39 | // Return a pointer to the beginning of the referenced data 40 | const char* data() const { return data_; } 41 | 42 | // Return the length (in bytes) of the referenced data 43 | size_t size() const { return size_; } 44 | 45 | // Return true iff the length of the referenced data is zero 46 | bool empty() const { return size_ == 0; } 47 | 48 | // Return the ith byte in the referenced data. 49 | // REQUIRES: n < size() 50 | char operator[](size_t n) const { 51 | assert(n < size()); 52 | return data_[n]; 53 | } 54 | 55 | // Change this slice to refer to an empty array 56 | void clear() { data_ = ""; size_ = 0; } 57 | 58 | // Drop the first "n" bytes from this slice. 59 | void remove_prefix(size_t n) { 60 | assert(n <= size()); 61 | data_ += n; 62 | size_ -= n; 63 | } 64 | 65 | // Return a string that contains the copy of the referenced data. 66 | std::string ToString() const { return std::string(data_, size_); } 67 | 68 | // Three-way comparison. Returns value: 69 | // < 0 iff "*this" < "b", 70 | // == 0 iff "*this" == "b", 71 | // > 0 iff "*this" > "b" 72 | int compare(const Slice& b) const; 73 | 74 | // Return true iff "x" is a prefix of "*this" 75 | bool starts_with(const Slice& x) const { 76 | return ((size_ >= x.size_) && 77 | (memcmp(data_, x.data_, x.size_) == 0)); 78 | } 79 | 80 | private: 81 | const char* data_; 82 | size_t size_; 83 | 84 | // Intentionally copyable 85 | }; 86 | 87 | inline bool operator==(const Slice& x, const Slice& y) { 88 | return ((x.size() == y.size()) && 89 | (memcmp(x.data(), y.data(), x.size()) == 0)); 90 | } 91 | 92 | inline bool operator!=(const Slice& x, const Slice& y) { 93 | return !(x == y); 94 | } 95 | 96 | inline int Slice::compare(const Slice& b) const { 97 | const size_t min_len = (size_ < b.size_) ? size_ : b.size_; 98 | int r = memcmp(data_, b.data_, min_len); 99 | if (r == 0) { 100 | if (size_ < b.size_) r = -1; 101 | else if (size_ > b.size_) r = +1; 102 | } 103 | return r; 104 | } 105 | 106 | } // namespace leveldb 107 | 108 | 109 | #endif // STORAGE_LEVELDB_INCLUDE_SLICE_H_ 110 | -------------------------------------------------------------------------------- /ext/include/leveldb/status.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // A Status encapsulates the result of an operation. It may indicate success, 6 | // or it may indicate an error with an associated error message. 7 | // 8 | // Multiple threads can invoke const methods on a Status without 9 | // external synchronization, but if any of the threads may call a 10 | // non-const method, all threads accessing the same Status must use 11 | // external synchronization. 12 | 13 | #ifndef STORAGE_LEVELDB_INCLUDE_STATUS_H_ 14 | #define STORAGE_LEVELDB_INCLUDE_STATUS_H_ 15 | 16 | #include 17 | #include "leveldb/slice.h" 18 | 19 | namespace leveldb { 20 | 21 | class Status { 22 | public: 23 | // Create a success status. 24 | Status() : state_(NULL) { } 25 | ~Status() { delete[] state_; } 26 | 27 | // Copy the specified status. 28 | Status(const Status& s); 29 | void operator=(const Status& s); 30 | 31 | // Return a success status. 32 | static Status OK() { return Status(); } 33 | 34 | // Return error status of an appropriate type. 35 | static Status NotFound(const Slice& msg, const Slice& msg2 = Slice()) { 36 | return Status(kNotFound, msg, msg2); 37 | } 38 | static Status Corruption(const Slice& msg, const Slice& msg2 = Slice()) { 39 | return Status(kCorruption, msg, msg2); 40 | } 41 | static Status NotSupported(const Slice& msg, const Slice& msg2 = Slice()) { 42 | return Status(kNotSupported, msg, msg2); 43 | } 44 | static Status InvalidArgument(const Slice& msg, const Slice& msg2 = Slice()) { 45 | return Status(kInvalidArgument, msg, msg2); 46 | } 47 | static Status IOError(const Slice& msg, const Slice& msg2 = Slice()) { 48 | return Status(kIOError, msg, msg2); 49 | } 50 | 51 | // Returns true iff the status indicates success. 52 | bool ok() const { return (state_ == NULL); } 53 | 54 | // Returns true iff the status indicates a NotFound error. 55 | bool IsNotFound() const { return code() == kNotFound; } 56 | 57 | // Returns true iff the status indicates a Corruption error. 58 | bool IsCorruption() const { return code() == kCorruption; } 59 | 60 | // Returns true iff the status indicates an IOError. 61 | bool IsIOError() const { return code() == kIOError; } 62 | 63 | // Return a string representation of this status suitable for printing. 64 | // Returns the string "OK" for success. 65 | std::string ToString() const; 66 | 67 | private: 68 | // OK status has a NULL state_. Otherwise, state_ is a new[] array 69 | // of the following form: 70 | // state_[0..3] == length of message 71 | // state_[4] == code 72 | // state_[5..] == message 73 | const char* state_; 74 | 75 | enum Code { 76 | kOk = 0, 77 | kNotFound = 1, 78 | kCorruption = 2, 79 | kNotSupported = 3, 80 | kInvalidArgument = 4, 81 | kIOError = 5 82 | }; 83 | 84 | Code code() const { 85 | return (state_ == NULL) ? kOk : static_cast(state_[4]); 86 | } 87 | 88 | Status(Code code, const Slice& msg, const Slice& msg2); 89 | static const char* CopyState(const char* s); 90 | }; 91 | 92 | inline Status::Status(const Status& s) { 93 | state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_); 94 | } 95 | inline void Status::operator=(const Status& s) { 96 | // The following condition catches both aliasing (when this == &s), 97 | // and the common case where both s and *this are ok. 98 | if (state_ != s.state_) { 99 | delete[] state_; 100 | state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_); 101 | } 102 | } 103 | 104 | } // namespace leveldb 105 | 106 | #endif // STORAGE_LEVELDB_INCLUDE_STATUS_H_ 107 | -------------------------------------------------------------------------------- /ext/include/leveldb/table.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_INCLUDE_TABLE_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_TABLE_H_ 7 | 8 | #include 9 | #include "leveldb/iterator.h" 10 | 11 | namespace leveldb { 12 | 13 | class Block; 14 | class BlockHandle; 15 | class Footer; 16 | struct Options; 17 | class RandomAccessFile; 18 | struct ReadOptions; 19 | class TableCache; 20 | 21 | // A Table is a sorted map from strings to strings. Tables are 22 | // immutable and persistent. A Table may be safely accessed from 23 | // multiple threads without external synchronization. 24 | class Table { 25 | public: 26 | // Attempt to open the table that is stored in bytes [0..file_size) 27 | // of "file", and read the metadata entries necessary to allow 28 | // retrieving data from the table. 29 | // 30 | // If successful, returns ok and sets "*table" to the newly opened 31 | // table. The client should delete "*table" when no longer needed. 32 | // If there was an error while initializing the table, sets "*table" 33 | // to NULL and returns a non-ok status. Does not take ownership of 34 | // "*source", but the client must ensure that "source" remains live 35 | // for the duration of the returned table's lifetime. 36 | // 37 | // *file must remain live while this Table is in use. 38 | static Status Open(const Options& options, 39 | RandomAccessFile* file, 40 | uint64_t file_size, 41 | Table** table); 42 | 43 | ~Table(); 44 | 45 | // Returns a new iterator over the table contents. 46 | // The result of NewIterator() is initially invalid (caller must 47 | // call one of the Seek methods on the iterator before using it). 48 | Iterator* NewIterator(const ReadOptions&) const; 49 | 50 | // Given a key, return an approximate byte offset in the file where 51 | // the data for that key begins (or would begin if the key were 52 | // present in the file). The returned value is in terms of file 53 | // bytes, and so includes effects like compression of the underlying data. 54 | // E.g., the approximate offset of the last key in the table will 55 | // be close to the file length. 56 | uint64_t ApproximateOffsetOf(const Slice& key) const; 57 | 58 | private: 59 | struct Rep; 60 | Rep* rep_; 61 | 62 | explicit Table(Rep* rep) { rep_ = rep; } 63 | static Iterator* BlockReader(void*, const ReadOptions&, const Slice&); 64 | 65 | // Calls (*handle_result)(arg, ...) with the entry found after a call 66 | // to Seek(key). May not make such a call if filter policy says 67 | // that key is not present. 68 | friend class TableCache; 69 | Status InternalGet( 70 | const ReadOptions&, const Slice& key, 71 | void* arg, 72 | void (*handle_result)(void* arg, const Slice& k, const Slice& v)); 73 | 74 | 75 | void ReadMeta(const Footer& footer); 76 | void ReadFilter(const Slice& filter_handle_value); 77 | 78 | // No copying allowed 79 | Table(const Table&); 80 | void operator=(const Table&); 81 | }; 82 | 83 | } // namespace leveldb 84 | 85 | #endif // STORAGE_LEVELDB_INCLUDE_TABLE_H_ 86 | -------------------------------------------------------------------------------- /ext/include/leveldb/table_builder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // TableBuilder provides the interface used to build a Table 6 | // (an immutable and sorted map from keys to values). 7 | // 8 | // Multiple threads can invoke const methods on a TableBuilder without 9 | // external synchronization, but if any of the threads may call a 10 | // non-const method, all threads accessing the same TableBuilder must use 11 | // external synchronization. 12 | 13 | #ifndef STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_ 14 | #define STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_ 15 | 16 | #include 17 | #include "leveldb/options.h" 18 | #include "leveldb/status.h" 19 | 20 | namespace leveldb { 21 | 22 | class BlockBuilder; 23 | class BlockHandle; 24 | class WritableFile; 25 | 26 | class TableBuilder { 27 | public: 28 | // Create a builder that will store the contents of the table it is 29 | // building in *file. Does not close the file. It is up to the 30 | // caller to close the file after calling Finish(). 31 | TableBuilder(const Options& options, WritableFile* file); 32 | 33 | // REQUIRES: Either Finish() or Abandon() has been called. 34 | ~TableBuilder(); 35 | 36 | // Change the options used by this builder. Note: only some of the 37 | // option fields can be changed after construction. If a field is 38 | // not allowed to change dynamically and its value in the structure 39 | // passed to the constructor is different from its value in the 40 | // structure passed to this method, this method will return an error 41 | // without changing any fields. 42 | Status ChangeOptions(const Options& options); 43 | 44 | // Add key,value to the table being constructed. 45 | // REQUIRES: key is after any previously added key according to comparator. 46 | // REQUIRES: Finish(), Abandon() have not been called 47 | void Add(const Slice& key, const Slice& value); 48 | 49 | // Advanced operation: flush any buffered key/value pairs to file. 50 | // Can be used to ensure that two adjacent entries never live in 51 | // the same data block. Most clients should not need to use this method. 52 | // REQUIRES: Finish(), Abandon() have not been called 53 | void Flush(); 54 | 55 | // Return non-ok iff some error has been detected. 56 | Status status() const; 57 | 58 | // Finish building the table. Stops using the file passed to the 59 | // constructor after this function returns. 60 | // REQUIRES: Finish(), Abandon() have not been called 61 | Status Finish(); 62 | 63 | // Indicate that the contents of this builder should be abandoned. Stops 64 | // using the file passed to the constructor after this function returns. 65 | // If the caller is not going to call Finish(), it must call Abandon() 66 | // before destroying this builder. 67 | // REQUIRES: Finish(), Abandon() have not been called 68 | void Abandon(); 69 | 70 | // Number of calls to Add() so far. 71 | uint64_t NumEntries() const; 72 | 73 | // Size of the file generated so far. If invoked after a successful 74 | // Finish() call, returns the size of the final generated file. 75 | uint64_t FileSize() const; 76 | 77 | private: 78 | bool ok() const { return status().ok(); } 79 | void WriteBlock(BlockBuilder* block, BlockHandle* handle); 80 | void WriteRawBlock(const Slice& data, CompressionType, BlockHandle* handle); 81 | 82 | struct Rep; 83 | Rep* rep_; 84 | 85 | // No copying allowed 86 | TableBuilder(const TableBuilder&); 87 | void operator=(const TableBuilder&); 88 | }; 89 | 90 | } // namespace leveldb 91 | 92 | #endif // STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_ 93 | -------------------------------------------------------------------------------- /ext/include/leveldb/write_batch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // WriteBatch holds a collection of updates to apply atomically to a DB. 6 | // 7 | // The updates are applied in the order in which they are added 8 | // to the WriteBatch. For example, the value of "key" will be "v3" 9 | // after the following batch is written: 10 | // 11 | // batch.Put("key", "v1"); 12 | // batch.Delete("key"); 13 | // batch.Put("key", "v2"); 14 | // batch.Put("key", "v3"); 15 | // 16 | // Multiple threads can invoke const methods on a WriteBatch without 17 | // external synchronization, but if any of the threads may call a 18 | // non-const method, all threads accessing the same WriteBatch must use 19 | // external synchronization. 20 | 21 | #ifndef STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 22 | #define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 23 | 24 | #include 25 | #include "leveldb/status.h" 26 | 27 | namespace leveldb { 28 | 29 | class Slice; 30 | 31 | class WriteBatch { 32 | public: 33 | WriteBatch(); 34 | ~WriteBatch(); 35 | 36 | // Store the mapping "key->value" in the database. 37 | void Put(const Slice& key, const Slice& value); 38 | 39 | // If the database contains a mapping for "key", erase it. Else do nothing. 40 | void Delete(const Slice& key); 41 | 42 | // Clear all updates buffered in this batch. 43 | void Clear(); 44 | 45 | // Support for iterating over the contents of a batch. 46 | class Handler { 47 | public: 48 | virtual ~Handler(); 49 | virtual void Put(const Slice& key, const Slice& value) = 0; 50 | virtual void Delete(const Slice& key) = 0; 51 | }; 52 | Status Iterate(Handler* handler) const; 53 | 54 | private: 55 | friend class WriteBatchInternal; 56 | 57 | std::string rep_; // See comment in write_batch.cc for the format of rep_ 58 | 59 | // Intentionally copyable 60 | }; 61 | 62 | } // namespace leveldb 63 | 64 | #endif // STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 65 | -------------------------------------------------------------------------------- /ext/include/openssl: -------------------------------------------------------------------------------- 1 | openssl-1.0.1j -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/cast.h: -------------------------------------------------------------------------------- 1 | /* crypto/cast/cast.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_CAST_H 60 | #define HEADER_CAST_H 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | #include 67 | 68 | #ifdef OPENSSL_NO_CAST 69 | #error CAST is disabled. 70 | #endif 71 | 72 | #define CAST_ENCRYPT 1 73 | #define CAST_DECRYPT 0 74 | 75 | #define CAST_LONG unsigned int 76 | 77 | #define CAST_BLOCK 8 78 | #define CAST_KEY_LENGTH 16 79 | 80 | typedef struct cast_key_st 81 | { 82 | CAST_LONG data[32]; 83 | int short_key; /* Use reduced rounds for short key */ 84 | } CAST_KEY; 85 | 86 | #ifdef OPENSSL_FIPS 87 | void private_CAST_set_key(CAST_KEY *key, int len, const unsigned char *data); 88 | #endif 89 | void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data); 90 | void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out, const CAST_KEY *key, 91 | int enc); 92 | void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key); 93 | void CAST_decrypt(CAST_LONG *data, const CAST_KEY *key); 94 | void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, 95 | const CAST_KEY *ks, unsigned char *iv, int enc); 96 | void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out, 97 | long length, const CAST_KEY *schedule, unsigned char *ivec, 98 | int *num, int enc); 99 | void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out, 100 | long length, const CAST_KEY *schedule, unsigned char *ivec, 101 | int *num); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/cmac.h: -------------------------------------------------------------------------------- 1 | /* crypto/cmac/cmac.h */ 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 3 | * project. 4 | */ 5 | /* ==================================================================== 6 | * Copyright (c) 2010 The OpenSSL Project. All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in 17 | * the documentation and/or other materials provided with the 18 | * distribution. 19 | * 20 | * 3. All advertising materials mentioning features or use of this 21 | * software must display the following acknowledgment: 22 | * "This product includes software developed by the OpenSSL Project 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 24 | * 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26 | * endorse or promote products derived from this software without 27 | * prior written permission. For written permission, please contact 28 | * licensing@OpenSSL.org. 29 | * 30 | * 5. Products derived from this software may not be called "OpenSSL" 31 | * nor may "OpenSSL" appear in their names without prior written 32 | * permission of the OpenSSL Project. 33 | * 34 | * 6. Redistributions of any form whatsoever must retain the following 35 | * acknowledgment: 36 | * "This product includes software developed by the OpenSSL Project 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 38 | * 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. 51 | * ==================================================================== 52 | */ 53 | 54 | 55 | #ifndef HEADER_CMAC_H 56 | #define HEADER_CMAC_H 57 | 58 | #ifdef __cplusplus 59 | extern "C" { 60 | #endif 61 | 62 | #include 63 | 64 | /* Opaque */ 65 | typedef struct CMAC_CTX_st CMAC_CTX; 66 | 67 | CMAC_CTX *CMAC_CTX_new(void); 68 | void CMAC_CTX_cleanup(CMAC_CTX *ctx); 69 | void CMAC_CTX_free(CMAC_CTX *ctx); 70 | EVP_CIPHER_CTX *CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx); 71 | int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in); 72 | 73 | int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen, 74 | const EVP_CIPHER *cipher, ENGINE *impl); 75 | int CMAC_Update(CMAC_CTX *ctx, const void *data, size_t dlen); 76 | int CMAC_Final(CMAC_CTX *ctx, unsigned char *out, size_t *poutlen); 77 | int CMAC_resume(CMAC_CTX *ctx); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | #endif 83 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/comp.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef HEADER_COMP_H 3 | #define HEADER_COMP_H 4 | 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | typedef struct comp_ctx_st COMP_CTX; 12 | 13 | typedef struct comp_method_st 14 | { 15 | int type; /* NID for compression library */ 16 | const char *name; /* A text string to identify the library */ 17 | int (*init)(COMP_CTX *ctx); 18 | void (*finish)(COMP_CTX *ctx); 19 | int (*compress)(COMP_CTX *ctx, 20 | unsigned char *out, unsigned int olen, 21 | unsigned char *in, unsigned int ilen); 22 | int (*expand)(COMP_CTX *ctx, 23 | unsigned char *out, unsigned int olen, 24 | unsigned char *in, unsigned int ilen); 25 | /* The following two do NOTHING, but are kept for backward compatibility */ 26 | long (*ctrl)(void); 27 | long (*callback_ctrl)(void); 28 | } COMP_METHOD; 29 | 30 | struct comp_ctx_st 31 | { 32 | COMP_METHOD *meth; 33 | unsigned long compress_in; 34 | unsigned long compress_out; 35 | unsigned long expand_in; 36 | unsigned long expand_out; 37 | 38 | CRYPTO_EX_DATA ex_data; 39 | }; 40 | 41 | 42 | COMP_CTX *COMP_CTX_new(COMP_METHOD *meth); 43 | void COMP_CTX_free(COMP_CTX *ctx); 44 | int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, 45 | unsigned char *in, int ilen); 46 | int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, 47 | unsigned char *in, int ilen); 48 | COMP_METHOD *COMP_rle(void ); 49 | COMP_METHOD *COMP_zlib(void ); 50 | void COMP_zlib_cleanup(void); 51 | 52 | #ifdef HEADER_BIO_H 53 | #ifdef ZLIB 54 | BIO_METHOD *BIO_f_zlib(void); 55 | #endif 56 | #endif 57 | 58 | /* BEGIN ERROR CODES */ 59 | /* The following lines are auto generated by the script mkerr.pl. Any changes 60 | * made after this point may be overwritten when the script is next run. 61 | */ 62 | void ERR_load_COMP_strings(void); 63 | 64 | /* Error codes for the COMP functions. */ 65 | 66 | /* Function codes. */ 67 | #define COMP_F_BIO_ZLIB_FLUSH 99 68 | #define COMP_F_BIO_ZLIB_NEW 100 69 | #define COMP_F_BIO_ZLIB_READ 101 70 | #define COMP_F_BIO_ZLIB_WRITE 102 71 | 72 | /* Reason codes. */ 73 | #define COMP_R_ZLIB_DEFLATE_ERROR 99 74 | #define COMP_R_ZLIB_INFLATE_ERROR 100 75 | #define COMP_R_ZLIB_NOT_SUPPORTED 101 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | #endif 81 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/conf_api.h: -------------------------------------------------------------------------------- 1 | /* conf_api.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_CONF_API_H 60 | #define HEADER_CONF_API_H 61 | 62 | #include 63 | #include 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | /* Up until OpenSSL 0.9.5a, this was new_section */ 70 | CONF_VALUE *_CONF_new_section(CONF *conf, const char *section); 71 | /* Up until OpenSSL 0.9.5a, this was get_section */ 72 | CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section); 73 | /* Up until OpenSSL 0.9.5a, this was CONF_get_section */ 74 | STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf, 75 | const char *section); 76 | 77 | int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value); 78 | char *_CONF_get_string(const CONF *conf, const char *section, 79 | const char *name); 80 | long _CONF_get_number(const CONF *conf, const char *section, const char *name); 81 | 82 | int _CONF_new_data(CONF *conf); 83 | void _CONF_free_data(CONF *conf); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | #endif 89 | 90 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/ebcdic.h: -------------------------------------------------------------------------------- 1 | /* crypto/ebcdic.h */ 2 | 3 | #ifndef HEADER_EBCDIC_H 4 | #define HEADER_EBCDIC_H 5 | 6 | #include 7 | 8 | /* Avoid name clashes with other applications */ 9 | #define os_toascii _openssl_os_toascii 10 | #define os_toebcdic _openssl_os_toebcdic 11 | #define ebcdic2ascii _openssl_ebcdic2ascii 12 | #define ascii2ebcdic _openssl_ascii2ebcdic 13 | 14 | extern const unsigned char os_toascii[256]; 15 | extern const unsigned char os_toebcdic[256]; 16 | void *ebcdic2ascii(void *dest, const void *srce, size_t count); 17 | void *ascii2ebcdic(void *dest, const void *srce, size_t count); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/hmac.h: -------------------------------------------------------------------------------- 1 | /* crypto/hmac/hmac.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | #ifndef HEADER_HMAC_H 59 | #define HEADER_HMAC_H 60 | 61 | #include 62 | 63 | #ifdef OPENSSL_NO_HMAC 64 | #error HMAC is disabled. 65 | #endif 66 | 67 | #include 68 | 69 | #define HMAC_MAX_MD_CBLOCK 128 /* largest known is SHA512 */ 70 | 71 | #ifdef __cplusplus 72 | extern "C" { 73 | #endif 74 | 75 | typedef struct hmac_ctx_st 76 | { 77 | const EVP_MD *md; 78 | EVP_MD_CTX md_ctx; 79 | EVP_MD_CTX i_ctx; 80 | EVP_MD_CTX o_ctx; 81 | unsigned int key_length; 82 | unsigned char key[HMAC_MAX_MD_CBLOCK]; 83 | } HMAC_CTX; 84 | 85 | #define HMAC_size(e) (EVP_MD_size((e)->md)) 86 | 87 | 88 | void HMAC_CTX_init(HMAC_CTX *ctx); 89 | void HMAC_CTX_cleanup(HMAC_CTX *ctx); 90 | 91 | #define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) /* deprecated */ 92 | 93 | int HMAC_Init(HMAC_CTX *ctx, const void *key, int len, 94 | const EVP_MD *md); /* deprecated */ 95 | int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, 96 | const EVP_MD *md, ENGINE *impl); 97 | int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len); 98 | int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); 99 | unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, 100 | const unsigned char *d, size_t n, unsigned char *md, 101 | unsigned int *md_len); 102 | int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx); 103 | 104 | void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags); 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/idea.h: -------------------------------------------------------------------------------- 1 | /* crypto/idea/idea.h */ 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_IDEA_H 60 | #define HEADER_IDEA_H 61 | 62 | #include /* IDEA_INT, OPENSSL_NO_IDEA */ 63 | 64 | #ifdef OPENSSL_NO_IDEA 65 | #error IDEA is disabled. 66 | #endif 67 | 68 | #define IDEA_ENCRYPT 1 69 | #define IDEA_DECRYPT 0 70 | 71 | #define IDEA_BLOCK 8 72 | #define IDEA_KEY_LENGTH 16 73 | 74 | #ifdef __cplusplus 75 | extern "C" { 76 | #endif 77 | 78 | typedef struct idea_key_st 79 | { 80 | IDEA_INT data[9][6]; 81 | } IDEA_KEY_SCHEDULE; 82 | 83 | const char *idea_options(void); 84 | void idea_ecb_encrypt(const unsigned char *in, unsigned char *out, 85 | IDEA_KEY_SCHEDULE *ks); 86 | #ifdef OPENSSL_FIPS 87 | void private_idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks); 88 | #endif 89 | void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks); 90 | void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk); 91 | void idea_cbc_encrypt(const unsigned char *in, unsigned char *out, 92 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc); 93 | void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out, 94 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, 95 | int *num,int enc); 96 | void idea_ofb64_encrypt(const unsigned char *in, unsigned char *out, 97 | long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num); 98 | void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks); 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/mdc2.h: -------------------------------------------------------------------------------- 1 | /* crypto/mdc2/mdc2.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_MDC2_H 60 | #define HEADER_MDC2_H 61 | 62 | #include 63 | 64 | #ifdef __cplusplus 65 | extern "C" { 66 | #endif 67 | 68 | #ifdef OPENSSL_NO_MDC2 69 | #error MDC2 is disabled. 70 | #endif 71 | 72 | #define MDC2_BLOCK 8 73 | #define MDC2_DIGEST_LENGTH 16 74 | 75 | typedef struct mdc2_ctx_st 76 | { 77 | unsigned int num; 78 | unsigned char data[MDC2_BLOCK]; 79 | DES_cblock h,hh; 80 | int pad_type; /* either 1 or 2, default 1 */ 81 | } MDC2_CTX; 82 | 83 | 84 | #ifdef OPENSSL_FIPS 85 | int private_MDC2_Init(MDC2_CTX *c); 86 | #endif 87 | int MDC2_Init(MDC2_CTX *c); 88 | int MDC2_Update(MDC2_CTX *c, const unsigned char *data, size_t len); 89 | int MDC2_Final(unsigned char *md, MDC2_CTX *c); 90 | unsigned char *MDC2(const unsigned char *d, size_t n, 91 | unsigned char *md); 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif 98 | 99 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/opensslv.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_OPENSSLV_H 2 | #define HEADER_OPENSSLV_H 3 | 4 | /* Numeric release version identifier: 5 | * MNNFFPPS: major minor fix patch status 6 | * The status nibble has one of the values 0 for development, 1 to e for betas 7 | * 1 to 14, and f for release. The patch level is exactly that. 8 | * For example: 9 | * 0.9.3-dev 0x00903000 10 | * 0.9.3-beta1 0x00903001 11 | * 0.9.3-beta2-dev 0x00903002 12 | * 0.9.3-beta2 0x00903002 (same as ...beta2-dev) 13 | * 0.9.3 0x0090300f 14 | * 0.9.3a 0x0090301f 15 | * 0.9.4 0x0090400f 16 | * 1.2.3z 0x102031af 17 | * 18 | * For continuity reasons (because 0.9.5 is already out, and is coded 19 | * 0x00905100), between 0.9.5 and 0.9.6 the coding of the patch level 20 | * part is slightly different, by setting the highest bit. This means 21 | * that 0.9.5a looks like this: 0x0090581f. At 0.9.6, we can start 22 | * with 0x0090600S... 23 | * 24 | * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.) 25 | * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for 26 | * major minor fix final patch/beta) 27 | */ 28 | #define OPENSSL_VERSION_NUMBER 0x1000107fL 29 | #ifdef OPENSSL_FIPS 30 | #define OPENSSL_VERSION_TEXT "OpenSSL 1.0.1g-fips 7 Apr 2014" 31 | #else 32 | #define OPENSSL_VERSION_TEXT "OpenSSL 1.0.1g 7 Apr 2014" 33 | #endif 34 | #define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT 35 | 36 | 37 | /* The macros below are to be used for shared library (.so, .dll, ...) 38 | * versioning. That kind of versioning works a bit differently between 39 | * operating systems. The most usual scheme is to set a major and a minor 40 | * number, and have the runtime loader check that the major number is equal 41 | * to what it was at application link time, while the minor number has to 42 | * be greater or equal to what it was at application link time. With this 43 | * scheme, the version number is usually part of the file name, like this: 44 | * 45 | * libcrypto.so.0.9 46 | * 47 | * Some unixen also make a softlink with the major verson number only: 48 | * 49 | * libcrypto.so.0 50 | * 51 | * On Tru64 and IRIX 6.x it works a little bit differently. There, the 52 | * shared library version is stored in the file, and is actually a series 53 | * of versions, separated by colons. The rightmost version present in the 54 | * library when linking an application is stored in the application to be 55 | * matched at run time. When the application is run, a check is done to 56 | * see if the library version stored in the application matches any of the 57 | * versions in the version string of the library itself. 58 | * This version string can be constructed in any way, depending on what 59 | * kind of matching is desired. However, to implement the same scheme as 60 | * the one used in the other unixen, all compatible versions, from lowest 61 | * to highest, should be part of the string. Consecutive builds would 62 | * give the following versions strings: 63 | * 64 | * 3.0 65 | * 3.0:3.1 66 | * 3.0:3.1:3.2 67 | * 4.0 68 | * 4.0:4.1 69 | * 70 | * Notice how version 4 is completely incompatible with version, and 71 | * therefore give the breach you can see. 72 | * 73 | * There may be other schemes as well that I haven't yet discovered. 74 | * 75 | * So, here's the way it works here: first of all, the library version 76 | * number doesn't need at all to match the overall OpenSSL version. 77 | * However, it's nice and more understandable if it actually does. 78 | * The current library version is stored in the macro SHLIB_VERSION_NUMBER, 79 | * which is just a piece of text in the format "M.m.e" (Major, minor, edit). 80 | * For the sake of Tru64, IRIX, and any other OS that behaves in similar ways, 81 | * we need to keep a history of version numbers, which is done in the 82 | * macro SHLIB_VERSION_HISTORY. The numbers are separated by colons and 83 | * should only keep the versions that are binary compatible with the current. 84 | */ 85 | #define SHLIB_VERSION_HISTORY "" 86 | #define SHLIB_VERSION_NUMBER "1.0.0" 87 | 88 | 89 | #endif /* HEADER_OPENSSLV_H */ 90 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/pem2.h: -------------------------------------------------------------------------------- 1 | /* ==================================================================== 2 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. All advertising materials mentioning features or use of this 17 | * software must display the following acknowledgment: 18 | * "This product includes software developed by the OpenSSL Project 19 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 20 | * 21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 22 | * endorse or promote products derived from this software without 23 | * prior written permission. For written permission, please contact 24 | * licensing@OpenSSL.org. 25 | * 26 | * 5. Products derived from this software may not be called "OpenSSL" 27 | * nor may "OpenSSL" appear in their names without prior written 28 | * permission of the OpenSSL Project. 29 | * 30 | * 6. Redistributions of any form whatsoever must retain the following 31 | * acknowledgment: 32 | * "This product includes software developed by the OpenSSL Project 33 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 34 | * 35 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 36 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 38 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 41 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 46 | * OF THE POSSIBILITY OF SUCH DAMAGE. 47 | * ==================================================================== 48 | * 49 | * This product includes cryptographic software written by Eric Young 50 | * (eay@cryptsoft.com). This product includes software written by Tim 51 | * Hudson (tjh@cryptsoft.com). 52 | * 53 | */ 54 | 55 | /* 56 | * This header only exists to break a circular dependency between pem and err 57 | * Ben 30 Jan 1999. 58 | */ 59 | 60 | #ifdef __cplusplus 61 | extern "C" { 62 | #endif 63 | 64 | #ifndef HEADER_PEM_H 65 | void ERR_load_PEM_strings(void); 66 | #endif 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/pqueue.h: -------------------------------------------------------------------------------- 1 | /* crypto/pqueue/pqueue.h */ 2 | /* 3 | * DTLS implementation written by Nagendra Modadugu 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 5 | */ 6 | /* ==================================================================== 7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in 18 | * the documentation and/or other materials provided with the 19 | * distribution. 20 | * 21 | * 3. All advertising materials mentioning features or use of this 22 | * software must display the following acknowledgment: 23 | * "This product includes software developed by the OpenSSL Project 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 25 | * 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 27 | * endorse or promote products derived from this software without 28 | * prior written permission. For written permission, please contact 29 | * openssl-core@OpenSSL.org. 30 | * 31 | * 5. Products derived from this software may not be called "OpenSSL" 32 | * nor may "OpenSSL" appear in their names without prior written 33 | * permission of the OpenSSL Project. 34 | * 35 | * 6. Redistributions of any form whatsoever must retain the following 36 | * acknowledgment: 37 | * "This product includes software developed by the OpenSSL Project 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 39 | * 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. 52 | * ==================================================================== 53 | * 54 | * This product includes cryptographic software written by Eric Young 55 | * (eay@cryptsoft.com). This product includes software written by Tim 56 | * Hudson (tjh@cryptsoft.com). 57 | * 58 | */ 59 | 60 | #ifndef HEADER_PQUEUE_H 61 | #define HEADER_PQUEUE_H 62 | 63 | #include 64 | #include 65 | #include 66 | 67 | typedef struct _pqueue *pqueue; 68 | 69 | typedef struct _pitem 70 | { 71 | unsigned char priority[8]; /* 64-bit value in big-endian encoding */ 72 | void *data; 73 | struct _pitem *next; 74 | } pitem; 75 | 76 | typedef struct _pitem *piterator; 77 | 78 | pitem *pitem_new(unsigned char *prio64be, void *data); 79 | void pitem_free(pitem *item); 80 | 81 | pqueue pqueue_new(void); 82 | void pqueue_free(pqueue pq); 83 | 84 | pitem *pqueue_insert(pqueue pq, pitem *item); 85 | pitem *pqueue_peek(pqueue pq); 86 | pitem *pqueue_pop(pqueue pq); 87 | pitem *pqueue_find(pqueue pq, unsigned char *prio64be); 88 | pitem *pqueue_iterator(pqueue pq); 89 | pitem *pqueue_next(piterator *iter); 90 | 91 | void pqueue_print(pqueue pq); 92 | int pqueue_size(pqueue pq); 93 | 94 | #endif /* ! HEADER_PQUEUE_H */ 95 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/rc2.h: -------------------------------------------------------------------------------- 1 | /* crypto/rc2/rc2.h */ 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_RC2_H 60 | #define HEADER_RC2_H 61 | 62 | #include /* OPENSSL_NO_RC2, RC2_INT */ 63 | #ifdef OPENSSL_NO_RC2 64 | #error RC2 is disabled. 65 | #endif 66 | 67 | #define RC2_ENCRYPT 1 68 | #define RC2_DECRYPT 0 69 | 70 | #define RC2_BLOCK 8 71 | #define RC2_KEY_LENGTH 16 72 | 73 | #ifdef __cplusplus 74 | extern "C" { 75 | #endif 76 | 77 | typedef struct rc2_key_st 78 | { 79 | RC2_INT data[64]; 80 | } RC2_KEY; 81 | 82 | #ifdef OPENSSL_FIPS 83 | void private_RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,int bits); 84 | #endif 85 | void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,int bits); 86 | void RC2_ecb_encrypt(const unsigned char *in,unsigned char *out,RC2_KEY *key, 87 | int enc); 88 | void RC2_encrypt(unsigned long *data,RC2_KEY *key); 89 | void RC2_decrypt(unsigned long *data,RC2_KEY *key); 90 | void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, 91 | RC2_KEY *ks, unsigned char *iv, int enc); 92 | void RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out, 93 | long length, RC2_KEY *schedule, unsigned char *ivec, 94 | int *num, int enc); 95 | void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out, 96 | long length, RC2_KEY *schedule, unsigned char *ivec, 97 | int *num); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/rc4.h: -------------------------------------------------------------------------------- 1 | /* crypto/rc4/rc4.h */ 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_RC4_H 60 | #define HEADER_RC4_H 61 | 62 | #include /* OPENSSL_NO_RC4, RC4_INT */ 63 | #ifdef OPENSSL_NO_RC4 64 | #error RC4 is disabled. 65 | #endif 66 | 67 | #include 68 | 69 | #ifdef __cplusplus 70 | extern "C" { 71 | #endif 72 | 73 | typedef struct rc4_key_st 74 | { 75 | RC4_INT x,y; 76 | RC4_INT data[256]; 77 | } RC4_KEY; 78 | 79 | 80 | const char *RC4_options(void); 81 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); 82 | void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); 83 | void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, 84 | unsigned char *outdata); 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/ripemd.h: -------------------------------------------------------------------------------- 1 | /* crypto/ripemd/ripemd.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_RIPEMD_H 60 | #define HEADER_RIPEMD_H 61 | 62 | #include 63 | #include 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | #ifdef OPENSSL_NO_RIPEMD 70 | #error RIPEMD is disabled. 71 | #endif 72 | 73 | #if defined(__LP32__) 74 | #define RIPEMD160_LONG unsigned long 75 | #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) 76 | #define RIPEMD160_LONG unsigned long 77 | #define RIPEMD160_LONG_LOG2 3 78 | #else 79 | #define RIPEMD160_LONG unsigned int 80 | #endif 81 | 82 | #define RIPEMD160_CBLOCK 64 83 | #define RIPEMD160_LBLOCK (RIPEMD160_CBLOCK/4) 84 | #define RIPEMD160_DIGEST_LENGTH 20 85 | 86 | typedef struct RIPEMD160state_st 87 | { 88 | RIPEMD160_LONG A,B,C,D,E; 89 | RIPEMD160_LONG Nl,Nh; 90 | RIPEMD160_LONG data[RIPEMD160_LBLOCK]; 91 | unsigned int num; 92 | } RIPEMD160_CTX; 93 | 94 | #ifdef OPENSSL_FIPS 95 | int private_RIPEMD160_Init(RIPEMD160_CTX *c); 96 | #endif 97 | int RIPEMD160_Init(RIPEMD160_CTX *c); 98 | int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, size_t len); 99 | int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); 100 | unsigned char *RIPEMD160(const unsigned char *d, size_t n, 101 | unsigned char *md); 102 | void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b); 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/ssl23.h: -------------------------------------------------------------------------------- 1 | /* ssl/ssl23.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_SSL23_H 60 | #define HEADER_SSL23_H 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | /*client */ 67 | /* write to server */ 68 | #define SSL23_ST_CW_CLNT_HELLO_A (0x210|SSL_ST_CONNECT) 69 | #define SSL23_ST_CW_CLNT_HELLO_B (0x211|SSL_ST_CONNECT) 70 | /* read from server */ 71 | #define SSL23_ST_CR_SRVR_HELLO_A (0x220|SSL_ST_CONNECT) 72 | #define SSL23_ST_CR_SRVR_HELLO_B (0x221|SSL_ST_CONNECT) 73 | 74 | /* server */ 75 | /* read from client */ 76 | #define SSL23_ST_SR_CLNT_HELLO_A (0x210|SSL_ST_ACCEPT) 77 | #define SSL23_ST_SR_CLNT_HELLO_B (0x211|SSL_ST_ACCEPT) 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | #endif 83 | 84 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/stack.h: -------------------------------------------------------------------------------- 1 | /* crypto/stack/stack.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_STACK_H 60 | #define HEADER_STACK_H 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | typedef struct stack_st 67 | { 68 | int num; 69 | char **data; 70 | int sorted; 71 | 72 | int num_alloc; 73 | int (*comp)(const void *, const void *); 74 | } _STACK; /* Use STACK_OF(...) instead */ 75 | 76 | #define M_sk_num(sk) ((sk) ? (sk)->num:-1) 77 | #define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL) 78 | 79 | int sk_num(const _STACK *); 80 | void *sk_value(const _STACK *, int); 81 | 82 | void *sk_set(_STACK *, int, void *); 83 | 84 | _STACK *sk_new(int (*cmp)(const void *, const void *)); 85 | _STACK *sk_new_null(void); 86 | void sk_free(_STACK *); 87 | void sk_pop_free(_STACK *st, void (*func)(void *)); 88 | int sk_insert(_STACK *sk, void *data, int where); 89 | void *sk_delete(_STACK *st, int loc); 90 | void *sk_delete_ptr(_STACK *st, void *p); 91 | int sk_find(_STACK *st, void *data); 92 | int sk_find_ex(_STACK *st, void *data); 93 | int sk_push(_STACK *st, void *data); 94 | int sk_unshift(_STACK *st, void *data); 95 | void *sk_shift(_STACK *st); 96 | void *sk_pop(_STACK *st); 97 | void sk_zero(_STACK *st); 98 | int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *))) 99 | (const void *, const void *); 100 | _STACK *sk_dup(_STACK *st); 101 | void sk_sort(_STACK *st); 102 | int sk_is_sorted(const _STACK *st); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/txt_db.h: -------------------------------------------------------------------------------- 1 | /* crypto/txt_db/txt_db.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_TXT_DB_H 60 | #define HEADER_TXT_DB_H 61 | 62 | #include 63 | #ifndef OPENSSL_NO_BIO 64 | #include 65 | #endif 66 | #include 67 | #include 68 | 69 | #define DB_ERROR_OK 0 70 | #define DB_ERROR_MALLOC 1 71 | #define DB_ERROR_INDEX_CLASH 2 72 | #define DB_ERROR_INDEX_OUT_OF_RANGE 3 73 | #define DB_ERROR_NO_INDEX 4 74 | #define DB_ERROR_INSERT_INDEX_CLASH 5 75 | 76 | #ifdef __cplusplus 77 | extern "C" { 78 | #endif 79 | 80 | typedef OPENSSL_STRING *OPENSSL_PSTRING; 81 | DECLARE_SPECIAL_STACK_OF(OPENSSL_PSTRING, OPENSSL_STRING) 82 | 83 | typedef struct txt_db_st 84 | { 85 | int num_fields; 86 | STACK_OF(OPENSSL_PSTRING) *data; 87 | LHASH_OF(OPENSSL_STRING) **index; 88 | int (**qual)(OPENSSL_STRING *); 89 | long error; 90 | long arg1; 91 | long arg2; 92 | OPENSSL_STRING *arg_row; 93 | } TXT_DB; 94 | 95 | #ifndef OPENSSL_NO_BIO 96 | TXT_DB *TXT_DB_read(BIO *in, int num); 97 | long TXT_DB_write(BIO *out, TXT_DB *db); 98 | #else 99 | TXT_DB *TXT_DB_read(char *in, int num); 100 | long TXT_DB_write(char *out, TXT_DB *db); 101 | #endif 102 | int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(OPENSSL_STRING *), 103 | LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp); 104 | void TXT_DB_free(TXT_DB *db); 105 | OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, OPENSSL_STRING *value); 106 | int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *value); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/ui_compat.h: -------------------------------------------------------------------------------- 1 | /* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */ 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL 3 | * project 2001. 4 | */ 5 | /* ==================================================================== 6 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in 17 | * the documentation and/or other materials provided with the 18 | * distribution. 19 | * 20 | * 3. All advertising materials mentioning features or use of this 21 | * software must display the following acknowledgment: 22 | * "This product includes software developed by the OpenSSL Project 23 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 24 | * 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26 | * endorse or promote products derived from this software without 27 | * prior written permission. For written permission, please contact 28 | * openssl-core@openssl.org. 29 | * 30 | * 5. Products derived from this software may not be called "OpenSSL" 31 | * nor may "OpenSSL" appear in their names without prior written 32 | * permission of the OpenSSL Project. 33 | * 34 | * 6. Redistributions of any form whatsoever must retain the following 35 | * acknowledgment: 36 | * "This product includes software developed by the OpenSSL Project 37 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 38 | * 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. 51 | * ==================================================================== 52 | * 53 | * This product includes cryptographic software written by Eric Young 54 | * (eay@cryptsoft.com). This product includes software written by Tim 55 | * Hudson (tjh@cryptsoft.com). 56 | * 57 | */ 58 | 59 | #ifndef HEADER_UI_COMPAT_H 60 | #define HEADER_UI_COMPAT_H 61 | 62 | #include 63 | #include 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | /* The following functions were previously part of the DES section, 70 | and are provided here for backward compatibility reasons. */ 71 | 72 | #define des_read_pw_string(b,l,p,v) \ 73 | _ossl_old_des_read_pw_string((b),(l),(p),(v)) 74 | #define des_read_pw(b,bf,s,p,v) \ 75 | _ossl_old_des_read_pw((b),(bf),(s),(p),(v)) 76 | 77 | int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify); 78 | int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | #endif 84 | -------------------------------------------------------------------------------- /ext/include/openssl-1.0.1j/whrlpool.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_WHRLPOOL_H 2 | #define HEADER_WHRLPOOL_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #define WHIRLPOOL_DIGEST_LENGTH (512/8) 12 | #define WHIRLPOOL_BBLOCK 512 13 | #define WHIRLPOOL_COUNTER (256/8) 14 | 15 | typedef struct { 16 | union { 17 | unsigned char c[WHIRLPOOL_DIGEST_LENGTH]; 18 | /* double q is here to ensure 64-bit alignment */ 19 | double q[WHIRLPOOL_DIGEST_LENGTH/sizeof(double)]; 20 | } H; 21 | unsigned char data[WHIRLPOOL_BBLOCK/8]; 22 | unsigned int bitoff; 23 | size_t bitlen[WHIRLPOOL_COUNTER/sizeof(size_t)]; 24 | } WHIRLPOOL_CTX; 25 | 26 | #ifndef OPENSSL_NO_WHIRLPOOL 27 | #ifdef OPENSSL_FIPS 28 | int private_WHIRLPOOL_Init(WHIRLPOOL_CTX *c); 29 | #endif 30 | int WHIRLPOOL_Init (WHIRLPOOL_CTX *c); 31 | int WHIRLPOOL_Update (WHIRLPOOL_CTX *c,const void *inp,size_t bytes); 32 | void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c,const void *inp,size_t bits); 33 | int WHIRLPOOL_Final (unsigned char *md,WHIRLPOOL_CTX *c); 34 | unsigned char *WHIRLPOOL(const void *inp,size_t bytes,unsigned char *md); 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /ext/lib/libcrypto_iOS.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mx4/bitc/15b8b750be45657f4c93b8fa3c615157d07a328a/ext/lib/libcrypto_iOS.a -------------------------------------------------------------------------------- /ext/lib/libleveldb.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mx4/bitc/15b8b750be45657f4c93b8fa3c615157d07a328a/ext/lib/libleveldb.a -------------------------------------------------------------------------------- /ext/lib/libssl_iOS.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mx4/bitc/15b8b750be45657f4c93b8fa3c615157d07a328a/ext/lib/libssl_iOS.a -------------------------------------------------------------------------------- /ext/src/MurmurHash3/MurmurHash3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "basic_defs.h" 4 | #include "MurmurHash3.h" 5 | 6 | 7 | /* 8 | *------------------------------------------------------------------------- 9 | * 10 | * ROTL32 -- 11 | * 12 | *------------------------------------------------------------------------- 13 | */ 14 | 15 | static inline uint32 16 | ROTL32(uint32 x, int8 r) 17 | { 18 | return (x << r) | (x >> (32 - r)); 19 | } 20 | 21 | 22 | /* 23 | *------------------------------------------------------------------------- 24 | * 25 | * MurmurHash3 -- 26 | * 27 | * http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp 28 | * 29 | *------------------------------------------------------------------------- 30 | */ 31 | 32 | uint32 33 | MurmurHash3(const void *key, 34 | size_t len, 35 | uint32 seed) 36 | { 37 | const uint8 *data = (const uint8 *)key; 38 | uint32 h1 = seed; 39 | const uint32 c1 = 0xcc9e2d51; 40 | const uint32 c2 = 0x1b873593; 41 | const int nblocks = len / 4; 42 | const uint32 * blocks = (const uint32 *)(&data[0] + nblocks * 4); 43 | int i; 44 | 45 | for (i = -nblocks; i; i++) { 46 | uint32 k1 = blocks[i]; 47 | 48 | k1 *= c1; 49 | k1 = ROTL32(k1,15); 50 | k1 *= c2; 51 | 52 | h1 ^= k1; 53 | h1 = ROTL32(h1,13); 54 | h1 = h1 * 5 + 0xe6546b64; 55 | } 56 | 57 | const uint8 * tail = (const uint8*)(&data[0] + nblocks * 4); 58 | uint32 k1 = 0; 59 | 60 | switch (len & 3) { 61 | case 3: k1 ^= tail[2] << 16; 62 | case 2: k1 ^= tail[1] << 8; 63 | case 1: k1 ^= tail[0]; 64 | k1 *= c1; 65 | k1 = ROTL32(k1,15); 66 | k1 *= c2; 67 | h1 ^= k1; 68 | } 69 | 70 | h1 ^= len; 71 | h1 ^= h1 >> 16; 72 | h1 *= 0x85ebca6b; 73 | h1 ^= h1 >> 13; 74 | h1 *= 0xc2b2ae35; 75 | h1 ^= h1 >> 16; 76 | 77 | return h1; 78 | } 79 | -------------------------------------------------------------------------------- /ext/src/public/MurmurHash3.h: -------------------------------------------------------------------------------- 1 | #ifndef __MURMURHASH3_H__ 2 | #define __MURMURHASH3_H__ 3 | 4 | #include "basic_defs.h" 5 | 6 | uint32 MurmurHash3(const void *key, size_t len, uint32 seed); 7 | 8 | #endif /* __MURMURHASH3_H__ */ 9 | 10 | -------------------------------------------------------------------------------- /lib/public/config.h: -------------------------------------------------------------------------------- 1 | #ifndef __CONFIG_H__ 2 | #define __CONFIG_H__ 3 | 4 | #include "basic_defs.h" 5 | 6 | struct config; 7 | 8 | int config_load(const char *fileName, struct config **conf); 9 | int config_write(struct config *conf, const char *filename); 10 | int config_save(struct config *conf); 11 | void config_free(struct config *conf); 12 | struct config* config_create(void); 13 | 14 | char* config_getstring(struct config *config, const char *def, 15 | const char *fmt, ...) PRINTF_GCC_DECL(3, 4); 16 | int64 config_getint64(struct config *config, int64 def, 17 | const char *fmt, ...) PRINTF_GCC_DECL(3, 4); 18 | bool config_getbool(struct config *config, bool def, 19 | const char *fmt, ...) PRINTF_GCC_DECL(3, 4); 20 | 21 | void config_setstring(struct config *config, const char *s, 22 | const char *fmt, ...) PRINTF_GCC_DECL(3, 4); 23 | void config_setbool(struct config *config, bool b, 24 | const char *fmt, ...) PRINTF_GCC_DECL(3, 4); 25 | void config_setint64(struct config *config, int64 val, 26 | const char *fmt, ...) PRINTF_GCC_DECL(3, 4); 27 | bool config_isset(struct config *config, 28 | const char *fmt, ...) PRINTF_GCC_DECL(2, 3); 29 | 30 | #endif /* __CONFIG_H__ */ 31 | -------------------------------------------------------------------------------- /lib/public/file.h: -------------------------------------------------------------------------------- 1 | #ifndef __FILE_H__ 2 | #define __FILE_H__ 3 | 4 | #include "basic_defs.h" 5 | 6 | // PATH_MAX 7 | #ifdef linux 8 | #include 9 | #elif defined(__APPLE__) 10 | #include 11 | #else 12 | #include 13 | #endif 14 | 15 | 16 | struct file_descriptor; 17 | 18 | 19 | bool file_valid(const struct file_descriptor *fd); 20 | 21 | int file_create(const char *filename); 22 | int file_mkdir(const char *pathname); 23 | int file_sync(const struct file_descriptor *desc); 24 | int64 file_getsize(const struct file_descriptor *desc); 25 | int file_truncate(const struct file_descriptor *desc, uint64 offset); 26 | bool file_exists(const char *name); 27 | int file_close(struct file_descriptor *desc); 28 | int file_pread(const struct file_descriptor *desc, 29 | uint64 offset, void *buf, size_t len, size_t *num); 30 | int file_pwrite(const struct file_descriptor *desc, 31 | uint64 offset, const void *buf, size_t len, size_t *num); 32 | int file_open(const char *name, 33 | bool readOnly, 34 | bool unbuf, 35 | struct file_descriptor **desc); 36 | void file_freedirlist(char **names); 37 | int file_listdirectory(const char *directory, 38 | char ***namesOut); 39 | char *file_getcwd(void); 40 | char *file_fullpath(const char *path); 41 | char *file_getname(const char *path); 42 | 43 | int file_getline(struct file_descriptor *desc, char **line); 44 | int file_unlink(const char *filename); 45 | int file_rmdir(const char *path); 46 | int file_glob(const char *path, const char *pattern, char ***list); 47 | int file_rotate(const char *filename, uint32 n); 48 | int file_rename(const char *src, const char *dst); 49 | int file_chmod(const char *filename, uint32 mode); 50 | 51 | #endif /* __FILE_H__ */ 52 | -------------------------------------------------------------------------------- /lib/public/hashtable.h: -------------------------------------------------------------------------------- 1 | #ifndef __HASHTABLE_H__ 2 | #define __HASHTABLE_H__ 3 | 4 | #include "basic_defs.h" 5 | 6 | 7 | struct hashtable; 8 | 9 | typedef void (hashtable_callback)(const void *key, size_t keyLen, 10 | void *clientData); 11 | typedef void (hashtable_for_each_callback)(const void *key, size_t keyLen, 12 | void *cbData, void *keyData); 13 | 14 | struct hashtable *hashtable_create(void); 15 | 16 | void hashtable_clear(struct hashtable *ht); 17 | void hashtable_clear_with_free(struct hashtable *ht); 18 | void hashtable_clear_with_callback(struct hashtable *ht, 19 | hashtable_callback callback); 20 | void hashtable_destroy(struct hashtable *ht); 21 | void hashtable_insert_test(uint32 n, volatile int *stop); 22 | void hashtable_printstats(const struct hashtable *ht, const char *pfx); 23 | 24 | uint32 hashtable_getnumentries(const struct hashtable *ht); 25 | uint32 hashtable_getmaxdepth(const struct hashtable *ht); 26 | uint32 hashtable_getemptybuckets(const struct hashtable *ht); 27 | 28 | void hashtable_for_each(const struct hashtable *ht, 29 | hashtable_for_each_callback callback, 30 | void *clientdata); 31 | 32 | bool hashtable_lookup(const struct hashtable *ht, 33 | const void *key, 34 | size_t keyLen, 35 | void **clientData); 36 | bool hashtable_insert(struct hashtable *ht, 37 | const void *key, 38 | size_t keyLen, 39 | void *clientData); 40 | bool hashtable_remove(struct hashtable *ht, 41 | const void *key, 42 | size_t keyLen); 43 | void hashtable_get_entry_idx(const struct hashtable *ht, 44 | size_t idx, 45 | const void **key, 46 | size_t *keyLen, 47 | void **clientData); 48 | void hashtable_linearize(const struct hashtable *ht, 49 | size_t entry_size, void **ptr); 50 | 51 | 52 | #endif /* __HASHTABLE_H__ */ 53 | -------------------------------------------------------------------------------- /lib/public/ip_info.h: -------------------------------------------------------------------------------- 1 | #ifndef __IP_INFO_H__ 2 | #define __IP_INFO_H__ 3 | 4 | #include 5 | 6 | /* 7 | * This is what freegeoip.net returns: 8 | * { 9 | * "ip":"178.194.77.142", 10 | * "country_code":"CH", 11 | * "country_name":"Switzerland", 12 | * "region_code":"23", 13 | * "region_name":"Vaud", 14 | * "city":"Lausanne", 15 | * "zipcode":"1000", 16 | * "latitude":46.5417, 17 | * "longitude":6.6815, 18 | * "metro_code":"", 19 | * "areacode":"" 20 | * } 21 | */ 22 | 23 | struct ipinfo_entry { 24 | struct sockaddr_in addr; 25 | char *hostname; 26 | char *country_name; 27 | char *country_code; 28 | char *region_name; 29 | char *region_code; 30 | char *city; 31 | }; 32 | 33 | 34 | void ipinfo_resolve_peer(const struct sockaddr_in *addr); 35 | struct ipinfo_entry *ipinfo_get_entry(const struct sockaddr_in *addr); 36 | 37 | void ipinfo_init(void); 38 | void ipinfo_exit(void); 39 | 40 | 41 | #endif /* __IP_INFO_H__ */ 42 | -------------------------------------------------------------------------------- /lib/public/netasync.h: -------------------------------------------------------------------------------- 1 | #ifndef __NETASYNC_H__ 2 | #define __NETASYNC_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "basic_defs.h" 8 | #include "poll.h" 9 | 10 | struct netasync_socket; 11 | 12 | typedef void (netasync_callback)(struct netasync_socket *socket, 13 | void *clientdata, int err); 14 | 15 | typedef void (netasync_recv_callback)(struct netasync_socket *socket, 16 | void *buf, 17 | size_t len, 18 | void *clientdata); 19 | 20 | time_t netasync_get_connect_ts(const struct netasync_socket *sock); 21 | struct netasync_socket* netasync_create(void); 22 | void netasync_close(struct netasync_socket *socket); 23 | short int netasync_port(const struct netasync_socket *sock); 24 | char * netasync_addr2str(const struct sockaddr_in *addr); 25 | const char *netasync_hostname(const struct netasync_socket *sock); 26 | void netasync_init(struct poll_loop *poll); 27 | void netasync_exit(void); 28 | 29 | void netasync_set_errorhandler(struct netasync_socket *sock, 30 | netasync_callback *callback, 31 | void *clientData); 32 | int netasync_receive(struct netasync_socket *sock, 33 | void *buf, size_t bufLen, bool partial, 34 | netasync_recv_callback *callback, 35 | void *clientData); 36 | 37 | int netasync_send(struct netasync_socket *sock, 38 | const void *buf, 39 | size_t len, 40 | netasync_callback *cb, 41 | void *clientData); 42 | 43 | int netasync_resolve(const char *hostname, 44 | uint16 port, 45 | struct sockaddr_in *addr); 46 | 47 | int netasync_connect(struct netasync_socket *socket, 48 | const struct sockaddr_in *addr, 49 | int timeout_sec, 50 | netasync_callback *cb, 51 | void *clientData); 52 | int 53 | netasync_bind(struct netasync_socket *sock, 54 | const struct sockaddr_in *addr, 55 | netasync_callback *cb, 56 | void *clientData); 57 | void 58 | netasync_use_socks(struct netasync_socket *sock, 59 | const char *hostname, short port); 60 | 61 | #endif /* __NETASYNC_H__ */ 62 | -------------------------------------------------------------------------------- /lib/public/poll.h: -------------------------------------------------------------------------------- 1 | #ifndef __POLL_H__ 2 | #define __POLL_H__ 3 | 4 | #include "basic_defs.h" 5 | 6 | enum poll_type { 7 | POLL_CB_NONE, 8 | POLL_CB_DEVICE, 9 | POLL_CB_TIME, 10 | }; 11 | 12 | struct poll_loop; 13 | typedef void (pollcallback_fun)(void *clientdata); 14 | 15 | struct poll_loop *poll_create(void); 16 | void poll_destroy(struct poll_loop *poll); 17 | void poll_runloop(struct poll_loop *poll, volatile int *exit); 18 | 19 | bool 20 | poll_callback_device_remove(struct poll_loop *poll, 21 | int fd, 22 | bool readable, 23 | bool writeable, 24 | bool permanent, 25 | pollcallback_fun callback, 26 | void *callbackData); 27 | 28 | bool 29 | poll_callback_time_remove(struct poll_loop *poll, 30 | bool permanent, 31 | pollcallback_fun callback, 32 | void *callbackData); 33 | 34 | void poll_callback_time(struct poll_loop *poll, 35 | mtime_t delayUsec, 36 | bool periodic, 37 | pollcallback_fun func, 38 | void *clientData); 39 | 40 | void poll_callback_device(struct poll_loop *poll, 41 | int fd, 42 | bool readable, 43 | bool writeable, 44 | bool permanent, 45 | pollcallback_fun func, 46 | void *clientData); 47 | 48 | #endif /* __POLL_H__ */ 49 | -------------------------------------------------------------------------------- /lib/public/poolworker.h: -------------------------------------------------------------------------------- 1 | #ifndef __POOLWORKER_H__ 2 | #define __POOLWORKER_H__ 3 | 4 | struct poolworker_state; 5 | 6 | typedef void (poolworker_func)(void *clientData); 7 | 8 | struct poolworker_state * poolworker_create(int numThreads); 9 | void poolworker_destroy(struct poolworker_state *pw); 10 | void poolworker_wait(struct poolworker_state *pw); 11 | void poolworker_wait_for_one_cmp(struct poolworker_state *pw); 12 | 13 | void poolworker_queue_work(struct poolworker_state *pw, 14 | poolworker_func *func, void *clientData); 15 | 16 | #endif /* __POOLWORKER_H__ */ 17 | -------------------------------------------------------------------------------- /lib/public/util.h: -------------------------------------------------------------------------------- 1 | #ifndef __UTIL_H__ 2 | #define __UTIL_H__ 3 | 4 | #ifdef __CYGWIN__ 5 | #include 6 | #include 7 | #endif 8 | 9 | #include "basic_defs.h" 10 | 11 | void Panic(const char *format, ...) PRINTF_GCC_DECL(1, 2) NORETURN; 12 | void Warning(const char *format, ...) PRINTF_GCC_DECL(1, 2); 13 | 14 | typedef void (LogCB)(const char *ts, const char *str, void *clientData); 15 | void Log_SetCB(LogCB *logCB, void *clientData); 16 | void Log(const char *format, ...) PRINTF_GCC_DECL(1, 2); 17 | void Log_SetLevel(int level); 18 | void Log_Init(const char *filename); 19 | void Log_Exit(void); 20 | void Log_Bytes(const char *pfx, const void *data, size_t len); 21 | 22 | mtime_t time_get(void); 23 | 24 | char *print_time_utc(uint32 t); 25 | char *print_time_local(uint32 t, const char *fmt); 26 | char *print_time_local_short(uint32 time); 27 | char *print_size(uint64 size); 28 | char *print_latency(mtime_t latency); 29 | void print_backtrace(void); 30 | 31 | typedef void (OnPanicCB)(void *data); 32 | void panic_register_cb(OnPanicCB *callback, void *clientData); 33 | 34 | bool util_throttle(uint32 count); 35 | void util_bumpnofds(void); 36 | void util_bumpcoresize(void); 37 | uint8 util_log2(uint32 val); 38 | char *util_gethomedir(void); 39 | char *util_getusername(void); 40 | 41 | void str_trim(char *s, size_t len); 42 | void str_reverse(void *buf, size_t len); 43 | void str_copyreverse(void *dst, const void *src, size_t len); 44 | void str_printf_bytes(const char *pfx, const void *data, size_t len); 45 | void str_snprintf_bytes(char *str, size_t len, const char *pfx, 46 | const uint8 *buf, size_t buflen); 47 | void str_to_bytes(const char *str, uint8 **bytes, size_t *len); 48 | 49 | void *safe_malloc(size_t size); 50 | void *safe_calloc(size_t nmemb, size_t size); 51 | void *safe_realloc(void *buf, size_t size); 52 | char *safe_strdup(const char *str); 53 | char *safe_asprintf(const char *fmt, ...) PRINTF_GCC_DECL(1, 2); 54 | 55 | bool util_memunlock(const void *ptr, size_t len); 56 | bool util_memlock(const void *ptr, size_t len); 57 | 58 | struct mutex; 59 | 60 | struct mutex *mutex_alloc(void); 61 | void mutex_free(struct mutex *lock); 62 | void mutex_lock(struct mutex *lock); 63 | void mutex_unlock(struct mutex *lock); 64 | bool mutex_islocked(struct mutex *lock); 65 | 66 | struct condvar; 67 | 68 | struct condvar * condvar_alloc(void); 69 | void condvar_wait(struct condvar *cv, struct mutex *lock); 70 | void condvar_signal(struct condvar *cv); 71 | void condvar_free(struct condvar *cv); 72 | 73 | /* 74 | * Log, ASSERTs and NOT_TESTED. 75 | */ 76 | 77 | #define NOT_TESTED() \ 78 | Warning("NOT_TESTED -- %s:%s:%u\n", __FILE__, __FUNCTION__, __LINE__) 79 | 80 | #define NOT_TESTED_ONCE() \ 81 | do { \ 82 | static bool _done; \ 83 | if (!_done) { \ 84 | _done = 1; \ 85 | NOT_TESTED(); \ 86 | } \ 87 | } while (0) 88 | 89 | #define DOLOG(_lvl) (verbose >= _lvl) 90 | 91 | #define LOG(_lvl, _fmt) \ 92 | do { \ 93 | if (DOLOG(_lvl)) { \ 94 | Log _fmt; \ 95 | } \ 96 | } while (0) 97 | 98 | #define NOT_IMPLEMENTED() \ 99 | do { \ 100 | Panic("NOT_IMPLEMENTED: %s:%s:%u\n", \ 101 | __FILE__, __func__, __LINE__); \ 102 | } while (0) 103 | 104 | #define NOT_REACHED() \ 105 | do { \ 106 | Panic("NOT_REACHED: %s:%s:%u\n", \ 107 | __FILE__, __func__, __LINE__); \ 108 | } while (0) 109 | 110 | #define ASSERT_MEMALLOC(_x) \ 111 | do { \ 112 | if (unlikely((_x) == NULL)) { \ 113 | Panic("Failed to allocate memory at %s:%s:%u\n", \ 114 | __FILE__, __func__, __LINE__); \ 115 | } \ 116 | } while (0) 117 | 118 | #define ASSERT_NOT_TESTED(_x) \ 119 | if (unlikely(!(_x))) { \ 120 | Warning("ASSERT_NOT_TESTED failed at %s:%s:%u\n" \ 121 | "--- Expression '%s' is false.\n", \ 122 | __FILE__, __func__, __LINE__, \ 123 | STR(_x)); \ 124 | } 125 | #define ASSERT(_x) \ 126 | if (unlikely(!(_x))) { \ 127 | Panic("ASSERT failed at %s:%s:%u\n" \ 128 | "PANIC: Expression '%s' not TRUE.\n", \ 129 | __FILE__, __func__, __LINE__, \ 130 | STR(_x)); \ 131 | } 132 | 133 | #endif /* __UTIL_H__ */ 134 | -------------------------------------------------------------------------------- /public/app.h: -------------------------------------------------------------------------------- 1 | #ifndef __APP_H__ 2 | #define __APP_H__ 3 | 4 | int bitc_app_init(const char *path); 5 | void bitc_app_exit(void); 6 | 7 | #endif /* __APP_H__ */ 8 | -------------------------------------------------------------------------------- /public/basic_defs.h: -------------------------------------------------------------------------------- 1 | #ifndef __BASIC_DEFS_H__ 2 | 3 | #ifdef linux 4 | #include 5 | #else 6 | #include 7 | #endif 8 | 9 | #ifdef __OpenBSD__ 10 | #include 11 | #endif 12 | 13 | #define __BASIC_DEFS_H__ 14 | 15 | typedef unsigned long long uint64; 16 | typedef unsigned int uint32; 17 | typedef unsigned short uint16; 18 | typedef unsigned char uint8; 19 | typedef long long int64; 20 | typedef int int32; 21 | typedef short int16; 22 | typedef char int8; 23 | #ifndef bool 24 | typedef char bool; 25 | #endif 26 | typedef uint64 mtime_t; 27 | 28 | #ifndef __APPLE__ 29 | #ifdef __x86_64__ 30 | //typedef uint64 uintptr_t; 31 | #else 32 | typedef uint32 uintptr_t; 33 | #endif 34 | #endif 35 | 36 | #define FALSE 0 37 | #define TRUE 1 38 | 39 | #define likely(_e) __builtin_expect(!!(_e), 1) 40 | #define unlikely(_e) __builtin_expect((_e), 0) 41 | 42 | #define ROUNDUP(_a, _b) (((_a) + (_b) - 1) / (_b) * (_b)) 43 | #define CEILING(_a, _b) (((_a) + (_b) - 1) / (_b)) 44 | #define ARRAYSIZE(array) (sizeof(array) / sizeof((array)[0])) 45 | 46 | #ifndef MAX 47 | #define MAX(_a, _b) ((_a) > (_b) ? (_a) : (_b)) 48 | #define MIN(_a, _b) ((_a) < (_b) ? (_a) : (_b)) 49 | #endif 50 | 51 | #define DWORD(hi, lo) ((((uint32)(hi)) << 16) | ((uint16)(lo))) 52 | #define QWORD(hi, lo) ((((uint64)(hi)) << 32) | ((uint32)(lo))) 53 | 54 | #define STRINGIFY(_x) #_x 55 | #define STR(_x) STRINGIFY(_x) 56 | 57 | #ifndef offsetof 58 | #define offsetof(_t, _m) ((size_t) &((_t *)0)->_m) 59 | #endif 60 | 61 | #define PRINTF_GCC_DECL(_f, _v) __attribute__((__format__(__printf__, _f, _v))) 62 | #define NORETURN __attribute__((noreturn)) 63 | 64 | #ifdef __GNUC__ 65 | #define ASSERT_ON_COMPILE(_x) do { } while (0) 66 | #else 67 | #define ASSERT_ON_COMPILE(_x) \ 68 | do { \ 69 | enum { _v = (_x) ? 1 : -1 }; \ 70 | typedef char _bogusArray[_v]; \ 71 | } while (0) 72 | #endif 73 | 74 | /* 75 | *--------------------------------------------------------------------------- 76 | * 77 | * minimum -- 78 | * 79 | * Like the macro MIN except that a & b are only evaluated once. 80 | * 81 | *--------------------------------------------------------------------------- 82 | */ 83 | 84 | static inline uint32 85 | minimum(uint32 a, uint32 b) 86 | { 87 | return MIN(a, b); 88 | } 89 | 90 | 91 | /* 92 | *--------------------------------------------------------------------------- 93 | * 94 | * maximum -- 95 | * 96 | * Like the macro MAX except that a & b are only evaluated once. 97 | * 98 | *--------------------------------------------------------------------------- 99 | */ 100 | 101 | static inline uint32 102 | maximum(uint32 a, uint32 b) 103 | { 104 | return MAX(a, b); 105 | } 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /public/bitc.h: -------------------------------------------------------------------------------- 1 | #ifndef __BTC_H__ 2 | #define __BTC_H__ 3 | 4 | 5 | enum bitc_state { 6 | BITC_STATE_STARTING, 7 | BITC_STATE_UPDATE_HEADERS, 8 | BITC_STATE_UPDATE_TXDB, 9 | BITC_STATE_READY, 10 | BITC_STATE_EXITING, 11 | }; 12 | 13 | enum wallet_state { 14 | WALLET_UNKNOWN, 15 | WALLET_PLAIN, 16 | WALLET_ENCRYPTED_LOCKED, 17 | WALLET_ENCRYPTED_UNLOCKED, 18 | }; 19 | 20 | 21 | struct btc_tx_desc { 22 | char label[256]; 23 | uint32 num_addr; 24 | uint64 total_value; 25 | int64 fee; 26 | struct { 27 | char addr[64]; 28 | uint64 value; 29 | } dst[16]; 30 | }; 31 | 32 | 33 | struct BITCApp { 34 | enum bitc_state state; 35 | enum wallet_state wallet_state; 36 | struct poll_loop *poll; 37 | struct config *config; 38 | struct config *contactsCfg; 39 | struct config *txLabelsCfg; 40 | struct blockstore *blockStore; 41 | struct wallet *wallet; 42 | struct addrbook *book; 43 | struct ncui *ui; 44 | struct peergroup *peerGroup; 45 | struct poolworker_state *pw; 46 | struct mutex *lock; 47 | 48 | bool testnet; 49 | bool resolve_peers; 50 | volatile int stop; 51 | bool updateAndExit; 52 | bool notifyInit; 53 | int eventFd; 54 | int notifyFd; 55 | struct circlist_item *reqList; 56 | 57 | char *socks5_proxy; 58 | uint16 socks5_port; 59 | }; 60 | 61 | extern struct BITCApp *btc; 62 | extern bool bitc_testing; 63 | 64 | void bitc_req_stop(void); 65 | void bitc_req_tx(struct btc_tx_desc *tx_desc); 66 | char *bitc_get_directory(void); 67 | 68 | 69 | /* 70 | *------------------------------------------------------------------- 71 | * 72 | * bitc_state_updating_txdb -- 73 | * 74 | *------------------------------------------------------------------- 75 | */ 76 | 77 | static inline bool 78 | bitc_state_updating_txdb(void) 79 | { 80 | return btc->state == BITC_STATE_UPDATE_TXDB; 81 | } 82 | 83 | 84 | /* 85 | *------------------------------------------------------------------- 86 | * 87 | * bitc_state_ready -- 88 | * 89 | *------------------------------------------------------------------- 90 | */ 91 | 92 | static inline bool 93 | bitc_state_ready(void) 94 | { 95 | return btc->state == BITC_STATE_READY; 96 | } 97 | 98 | 99 | /* 100 | *------------------------------------------------------------------- 101 | * 102 | * bitc_starting -- 103 | * 104 | *------------------------------------------------------------------- 105 | */ 106 | 107 | static inline bool 108 | bitc_starting(void) 109 | { 110 | return btc->state < BITC_STATE_READY; 111 | } 112 | 113 | 114 | /* 115 | *------------------------------------------------------------------- 116 | * 117 | * bitc_exiting -- 118 | * 119 | *------------------------------------------------------------------- 120 | */ 121 | 122 | static inline bool 123 | bitc_exiting(void) 124 | { 125 | return btc->state > BITC_STATE_READY; 126 | } 127 | 128 | 129 | #endif /* __BTC_H__ */ 130 | -------------------------------------------------------------------------------- /public/circlist.h: -------------------------------------------------------------------------------- 1 | #ifndef __CIRCLIST_H__ 2 | #define __CIRCLIST_H__ 3 | 4 | #include "basic_defs.h" 5 | 6 | 7 | struct circlist_item { 8 | struct circlist_item *prev; 9 | struct circlist_item *next; 10 | }; 11 | 12 | 13 | #define CIRCLIST_CONTAINER(_p, _t, _m) \ 14 | ((_t *)((char *)(_p) - offsetof(_t, _m))) 15 | 16 | #define CIRCLIST_EMPTY(l) ((l) == NULL) 17 | #define CIRCLIST_FIRST(l) (l) 18 | #define CIRCLIST_LAST(l) (CIRCLIST_EMPTY(l) ? NULL : (l)->prev) 19 | 20 | #define CIRCLIST_SCAN(p, l) \ 21 | for (p = CIRCLIST_FIRST(l); \ 22 | (p) != NULL; \ 23 | p = (((p)->next == CIRCLIST_FIRST(l)) ? NULL: (p)->next)) 24 | 25 | #define CIRCLIST_SCAN_BACK(p, l) \ 26 | for (p = CIRCLIST_LAST(l); \ 27 | (p) != NULL; \ 28 | p = (((p)->prev == CIRCLIST_LAST(l)) ? NULL: (p)->prev)) 29 | 30 | #define CIRCLIST_SCAN_SAFE(p, pn, l) \ 31 | if (!circlist_empty(l)) \ 32 | for ((p) = CIRCLIST_FIRST(l), (pn) = circlist_next_item(p, l); \ 33 | (p) != NULL; \ 34 | (p) = (pn), (pn) = circlist_next_item(p, l)) 35 | 36 | 37 | /* 38 | *--------------------------------------------------------------------- 39 | * 40 | * circlist_next_item -- 41 | * 42 | *--------------------------------------------------------------------- 43 | */ 44 | 45 | static inline struct circlist_item * 46 | circlist_next_item(struct circlist_item *p, 47 | const struct circlist_item *head) 48 | { 49 | if (head == NULL || p == NULL) { 50 | return NULL; 51 | } 52 | p = p->next; 53 | return p == head ? NULL : p; 54 | } 55 | 56 | 57 | /* 58 | *--------------------------------------------------------------------- 59 | * 60 | * circlist_prev_item -- 61 | * 62 | *--------------------------------------------------------------------- 63 | */ 64 | 65 | static inline struct circlist_item * 66 | circlist_prev_item(struct circlist_item *p, 67 | const struct circlist_item *head) 68 | { 69 | if (head == NULL || p == NULL) { 70 | return NULL; 71 | } 72 | return p == head ? NULL : p->prev; 73 | } 74 | 75 | 76 | /* 77 | *--------------------------------------------------------------------- 78 | * 79 | * circlist_empty -- 80 | * 81 | *--------------------------------------------------------------------- 82 | */ 83 | 84 | static inline bool 85 | circlist_empty(const struct circlist_item *list) 86 | { 87 | return list == NULL; 88 | } 89 | 90 | 91 | /* 92 | *--------------------------------------------------------------------- 93 | * 94 | * circlist_init_item -- 95 | * 96 | *--------------------------------------------------------------------- 97 | */ 98 | 99 | static inline void 100 | circlist_init_item(struct circlist_item *li) 101 | { 102 | li->prev = NULL; 103 | li->next = NULL; 104 | } 105 | 106 | 107 | /* 108 | *--------------------------------------------------------------------- 109 | * 110 | * circlist_queue_item -- 111 | * 112 | * Adds 'item' at the END of a circular list. 113 | * 114 | *--------------------------------------------------------------------- 115 | */ 116 | 117 | static inline void 118 | circlist_queue_item(struct circlist_item **list, 119 | struct circlist_item *item) 120 | { 121 | struct circlist_item *li = *list; 122 | 123 | if (circlist_empty(li)) { 124 | item->next = item->prev = item; 125 | *list = item; 126 | } else { 127 | item->prev = li->prev; 128 | item->next = li; 129 | item->prev->next = item; 130 | li->prev = item; 131 | } 132 | } 133 | 134 | 135 | /* 136 | *--------------------------------------------------------------------- 137 | * 138 | * circlist_push_item -- 139 | * 140 | * Adds 'item' at the FRONT of a circular list. 141 | * 142 | *--------------------------------------------------------------------- 143 | */ 144 | 145 | static inline void 146 | circlist_push_item(struct circlist_item **list, 147 | struct circlist_item *item) 148 | { 149 | circlist_queue_item(list, item); 150 | *list = item; 151 | } 152 | 153 | 154 | /* 155 | *--------------------------------------------------------------------- 156 | * 157 | * circlist_delete_item -- 158 | * 159 | *--------------------------------------------------------------------- 160 | */ 161 | 162 | static inline void 163 | circlist_delete_item(struct circlist_item **list, 164 | const struct circlist_item *item) 165 | { 166 | if (item == item->next) { 167 | *list = NULL; 168 | } else { 169 | struct circlist_item *next; 170 | 171 | next = item->next; 172 | next->prev = item->prev; 173 | item->prev->next = next; 174 | if (*list == item) { 175 | *list = next; 176 | } 177 | } 178 | } 179 | 180 | #endif /* __CIRCLIST_H__ */ 181 | -------------------------------------------------------------------------------- /public/fx.h: -------------------------------------------------------------------------------- 1 | #ifndef __FX_H__ 2 | #define __FX_H__ 3 | 4 | void fx_init(void); 5 | void fx_exit(void); 6 | 7 | #endif /* __FX_H__ */ 8 | -------------------------------------------------------------------------------- /valgrind.supp: -------------------------------------------------------------------------------- 1 | { 2 | BuggyLibc 3 | Memcheck:Param 4 | sendmsg(mmsg[0].msg_hdr) 5 | fun:sendmmsg 6 | fun:__libc_res_nsend 7 | fun:__libc_res_nquery 8 | fun:__libc_res_nsearch 9 | fun:_nss_dns_gethostbyname4_r 10 | fun:gaih_inet 11 | fun:getaddrinfo 12 | obj:/usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 13 | obj:/usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 14 | obj:/usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 15 | fun:start_thread 16 | fun:clone 17 | } 18 | { 19 | OpenSSLAnnoyingThing 20 | Memcheck:Cond 21 | obj:/lib/x86_64-linux-gnu/libssl.so.1.0.0 22 | obj:/lib/x86_64-linux-gnu/libssl.so.1.0.0 23 | obj:/lib/x86_64-linux-gnu/libssl.so.1.0.0 24 | obj:/usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 25 | obj:/usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 26 | obj:/usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 27 | obj:/usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 28 | fun:curl_multi_perform 29 | fun:curl_easy_perform 30 | fun:ipinfo_resolve_geo_cb 31 | fun:poolworker_main 32 | fun:start_thread 33 | } 34 | { 35 | CurlThingy 36 | Memcheck:Cond 37 | obj:/usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 38 | obj:/usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 39 | obj:/usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 40 | fun:curl_multi_perform 41 | fun:curl_easy_perform 42 | fun:ipinfo_resolve_geo_cb 43 | fun:poolworker_main 44 | fun:start_thread 45 | fun:clone 46 | } 47 | --------------------------------------------------------------------------------