diff --git a/.gitignore b/.gitignore
index 408d59085..03f81cc82 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
*.deb
src/bitcoin
src/test/test_bitcoin
+src/core
*zcashTest.pk
*zcashTest.vk
@@ -156,7 +157,9 @@ src/Makefile.in
doc/man/Makefile.in
Makefile.in
src/libcc.so
+src/libcc.dll
src/cc/customcc.so
+src/cc/customcc.dll
src/HUSH3_7776
REGTEST_7776
src/cc/librogue.so
diff --git a/COPYING b/COPYING
index a03819aee..875deb660 100644
--- a/COPYING
+++ b/COPYING
@@ -1,322 +1,21 @@
+Copyright (c) 2018-2020 The Hush developers
Copyright (c) 2009-2017 The Bitcoin Core developers
Copyright (c) 2009-2018 Bitcoin Developers
Copyright (c) 2016-2017 The Zcash developers
Copyright (c) 2016-2019 The Komodo developers
-Copyright (c) 2018-2020 The Hush developers
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+This is Free Software released under GPLv3. Any misuse of this software
+will be followed up with GPL enforcement via Software Freedom Law Center:
+https://www.softwarefreedom.org/
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+If you incorporate any code from the Hush Full Node (this software), your
+code must be licensed as GPLv3 (not GPLv2 or MIT).
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
-
-The MIT software license (http://www.opensource.org/licenses/mit-license.php)
-above applies to the code directly included in this source distribution.
+The GPLv3 software license applies to the code directly included in this source distribution.
+See the LICENSE file for full information.
Dependencies downloaded as part of the build process may be covered by other
open-source licenses. For further details see 'contrib/debian/copyright'.
-
This product includes software developed by the OpenSSL Project for use in the
OpenSSL Toolkit (https://www.openssl.org/). This product includes cryptographic
software written by Eric Young (eay@cryptsoft.com).
-
-
-Although almost all of this code is licensed under open source
-licenses, users and distributors should note that when built using the default
-build options, it depends on Oracle Berkeley DB 6.2.x, which is licensed
-under the GNU Affero General Public License. Free Software, Fuck Yeah!!!
-
-SuperNET COPYING terms:
-GNU GENERAL PUBLIC LICENSE
-Version 2, June 1991
-
-Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-Everyone is permitted to copy and distribute verbatim copies
-of this license document, but changing it is not allowed.
-
-Preamble
-
-The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.) You can apply it to
-your programs, too.
-
-When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
-We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-The precise terms and conditions for copying, distribution and
-modification follow.
-
-GNU GENERAL PUBLIC LICENSE
-TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-a) You must cause the modified files to carry prominent notices
-stating that you changed the files and the date of any change.
-
-b) You must cause any work that you distribute or publish, that in
-whole or in part contains or is derived from the Program or any
-part thereof, to be licensed as a whole at no charge to all third
-parties under the terms of this License.
-
-c) If the modified program normally reads commands interactively
-when run, you must cause it, when started running for such
-interactive use in the most ordinary way, to print or display an
-announcement including an appropriate copyright notice and a
-notice that there is no warranty (or else, saying that you provide
-a warranty) and that users may redistribute the program under
-these conditions, and telling the user how to view a copy of this
-License. (Exception: if the Program itself is interactive but
-does not normally print such an announcement, your work based on
-the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-a) Accompany it with the complete corresponding machine-readable
-source code, which must be distributed under the terms of Sections
-1 and 2 above on a medium customarily used for software interchange; or,
-
-b) Accompany it with a written offer, valid for at least three
-years, to give any third party, for a charge no more than your
-cost of physically performing source distribution, a complete
-machine-readable copy of the corresponding source code, to be
-distributed under the terms of Sections 1 and 2 above on a medium
-customarily used for software interchange; or,
-
-c) Accompany it with the information you received as to the offer
-to distribute corresponding source code. (This alternative is
-allowed only for noncommercial distribution and only if you
-received the program in object code or executable form with such
-an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-NO WARRANTY
-
-11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-END OF TERMS AND CONDITIONS
diff --git a/DEVELOPER-AGREEMENT b/DEVELOPER-AGREEMENT
new file mode 100644
index 000000000..85d69b4f3
--- /dev/null
+++ b/DEVELOPER-AGREEMENT
@@ -0,0 +1 @@
+You must agree that Duke Leto is the Elder of jl777.
diff --git a/INSTALL.md b/INSTALL.md
index c47c6ddfe..bb667b7be 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -39,7 +39,7 @@ sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib \
git clone https://github.com/MyHush/hush3.git
cd hush3
# Build
-./zcutil/build.sh -j$(nproc)
+./build.sh -j$(nproc)
```
## Run a HUSH Node
@@ -63,10 +63,8 @@ Downloading Git source repo, building and running Hush:
# pull
git clone https://github.com/MyHush/hush3.git
cd hush
-# fetch key
-./zcutil/fetch-params.sh
# Build
-./zcutil/build-win.sh -j$(nproc)
+./build-win.sh -j$(nproc)
# Run a HUSH node
./src/hushd
```
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 000000000..febd8b6d9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,619 @@
+ GENERAL GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GENERAL General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GENERAL General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GENERAL General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GENERAL GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GENERAL General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GENERAL Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GENERAL Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GENERAL Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GENERAL General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GENERAL General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GENERAL General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GENERAL General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
diff --git a/README.md b/README.md
index 1ec5dd7b1..95c8999fe 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# HUSH 3
+# HUSH
## What is HUSH?
diff --git a/build.sh b/build.sh
new file mode 100755
index 000000000..2ae8514c3
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+# Copyright (c) 2019-2020 The Hush developers
+
+set -eu -o pipefail
+./zcutil/build.sh $@
diff --git a/configure.ac b/configure.ac
index cf712cc67..a579081fb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,8 +1,8 @@
dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 3)
-define(_CLIENT_VERSION_MINOR, 3)
-define(_CLIENT_VERSION_REVISION, 2)
+define(_CLIENT_VERSION_MINOR, 5)
+define(_CLIENT_VERSION_REVISION, 1)
define(_CLIENT_VERSION_BUILD, 50)
define(_ZC_BUILD_VAL, m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, m4_incr(_CLIENT_VERSION_BUILD), m4_eval(_CLIENT_VERSION_BUILD < 50), 1, m4_eval(_CLIENT_VERSION_BUILD - 24), m4_eval(_CLIENT_VERSION_BUILD == 50), 1, , m4_eval(_CLIENT_VERSION_BUILD - 50)))
define(_CLIENT_VERSION_SUFFIX, m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, _CLIENT_VERSION_REVISION-beta$1, m4_eval(_CLIENT_VERSION_BUILD < 50), 1, _CLIENT_VERSION_REVISION-rc$1, m4_eval(_CLIENT_VERSION_BUILD == 50), 1, _CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION-$1)))
@@ -96,12 +96,6 @@ AC_ARG_ENABLE([mining],
[enable_mining=$enableval],
[enable_mining=yes])
-AC_ARG_ENABLE([proton],
- [AS_HELP_STRING([--disable-proton],
- [disable Proton (AMQP messaging)])],
- [use_proton=$enableval],
- [use_proton=yes])
-
AC_ARG_ENABLE(tests,
AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
[use_tests=$enableval],
@@ -507,15 +501,24 @@ if test x$use_hardening != xno; then
HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -D_FORTIFY_SOURCE=2"
],[AC_MSG_ERROR(Cannot enable -D_FORTIFY_SOURCE=2)])
- #AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_ERROR(Cannot enable RELRO)])
- #AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_ERROR(Cannot enable BIND_NOW)])
+ if test x$BUILD_OS = xdarwin || test x$TARGET_OS = xwindows; then
+ # Xcode's ld (at least ld64-302.3) doesn't support -z
+ # mingw-w64's ld (at least mingw-w64 4.0.4-2) also appears to not support -z
+ AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_WARN(Cannot enable RELRO)])
+ AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_WARN(Cannot enable BIND_NOW)])
+ else
+ AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_ERROR(Cannot enable RELRO)])
+ AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_ERROR(Cannot enable BIND_NOW)])
+ fi
if test x$TARGET_OS != xwindows; then
# All windows code is PIC, forcing it on just adds useless compile warnings
- AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_ERROR(Cannot enable RELRO)])
- AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_ERROR(Cannot enable BIND_NOW)])
- AX_CHECK_COMPILE_FLAG([-fPIE],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"],[AC_MSG_ERROR(Cannot enable -fPIE)])
- AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"],[AC_MSG_ERROR(Cannot enable -pie)])
+ AX_CHECK_COMPILE_FLAG([-fPIE],[PIE_FLAGS="-fPIE"],[AC_MSG_ERROR(Cannot enable -fPIE)])
+ if test x$BUILD_OS = xdarwin; then
+ AX_CHECK_LINK_FLAG([[-Wl,-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-pie"],[AC_MSG_ERROR(Cannot enable -Wl,-pie)])
+ else
+ AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"],[AC_MSG_ERROR(Cannot enable -pie)])
+ fi
else
# These are only available on Windows.
AX_CHECK_LINK_FLAG([[-Wl,--dynamicbase]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--dynamicbase"],[AC_MSG_ERROR(Cannot enable --dynamicbase)])
@@ -596,23 +599,6 @@ if test x$enable_wallet != xno; then
BITCOIN_FIND_BDB62
fi
-dnl Check Qpid Proton headers and library exist
-if test x$use_proton = xyes; then
- AC_CHECK_HEADERS([proton/connection.hpp],
- [],
- [AC_MSG_WARN([Proton headers not found, disabling Proton support])
- use_proton=no])
- AC_CHECK_LIB([qpid-proton-cpp], [main],
- [PROTON_LIBS="-lqpid-proton-cpp -lqpid-proton"],
- [AC_MSG_WARN([Proton libraries not found, disabling Proton support])
- use_proton=no])
-fi
-if test x$use_proton = xyes; then
- AC_DEFINE(ENABLE_PROTON, 1, [Define to 1 to enable Proton functions])
-else
- AC_DEFINE(ENABLE_PROTON, 0, [Define to 1 to enable Proton functions])
-fi
-
if test x$build_bitcoin_utils$build_bitcoind$use_tests = xnonono; then
use_boost=no
else
@@ -756,6 +742,14 @@ fi
fi
fi
+# These packages don't provide pkgconfig config files across all
+# platforms, so we use older autoconf detection mechanisms:
+AC_CHECK_HEADER([gmp.h],,AC_MSG_ERROR(libgmp headers missing))
+AC_CHECK_LIB([gmp],[[__gmpn_sub_n]],GMP_LIBS=-lgmp, [AC_MSG_ERROR(libgmp missing)])
+
+AC_CHECK_HEADER([gmpxx.h],,AC_MSG_ERROR(libgmpxx headers missing))
+AC_CHECK_LIB([gmpxx],[main],GMPXX_LIBS=-lgmpxx, [AC_MSG_ERROR(libgmpxx missing)])
+
RUST_LIBS="-lrustzcash"
case $host in
*mingw*)
@@ -832,8 +826,6 @@ fi
AM_CONDITIONAL([ENABLE_ZMQ], [test "x$use_zmq" = "xyes"])
-AM_CONDITIONAL([ENABLE_PROTON], [test "x$use_proton" = "xyes"])
-
AC_MSG_CHECKING([whether to build test_bitcoin])
if test x$use_tests = xyes; then
AC_MSG_RESULT([yes])
@@ -906,7 +898,6 @@ AC_SUBST(ZMQ_LIBS)
AC_SUBST(GMP_LIBS)
AC_SUBST(GMPXX_LIBS)
AC_SUBST(LIBZCASH_LIBS)
-AC_SUBST(PROTON_LIBS)
AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile src/test/buildenv.py])
AC_CONFIG_FILES([qa/pull-tester/run-bitcoind-for-test.sh],[chmod +x qa/pull-tester/run-bitcoind-for-test.sh])
AC_CONFIG_FILES([qa/pull-tester/tests-config.sh],[chmod +x qa/pull-tester/tests-config.sh])
@@ -953,7 +944,6 @@ esac
echo
echo "Options used to compile and link:"
echo " with wallet = $enable_wallet"
-echo " with proton = $use_proton"
echo " with zmq = $use_zmq"
echo " with test = $use_tests"
echo " debug enabled = $enable_debug"
diff --git a/contrib/amqp/amqp_sub.py b/contrib/amqp/amqp_sub.py
deleted file mode 100644
index bc51e8428..000000000
--- a/contrib/amqp/amqp_sub.py
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/usr/bin/env python2
-# Copyright (c) 2017 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-# Requirements:
-# pip install python-qpid-proton
-
-import binascii
-from proton.handlers import MessagingHandler
-from proton.reactor import Container
-
-port = 5672
-
-class Server(MessagingHandler):
- def __init__(self, url):
- super(Server, self).__init__()
- self.url = url
- self.senders = {}
-
- def on_start(self, event):
- print "Listening on:", self.url
- self.container = event.container
- self.acceptor = event.container.listen(self.url)
-
- def on_message(self, event):
- m = event.message
- topic = m.subject
- body = m.body
- sequence = str( m.properties['x-opt-sequence-number'] )
- if topic == "hashablock":
- print '- HASH BLOCK ('+sequence+') -'
- print binascii.hexlify(body)
- elif topic == "hashtx":
- print '- HASH TX ('+sequence+') -'
- print binascii.hexlify(body)
- elif topic == "rawblock":
- print '- RAW BLOCK HEADER ('+sequence+') -'
- print binascii.hexlify(body[:80])
- elif topic == "rawtx":
- print '- RAW TX ('+sequence+') -'
- print binascii.hexlify(body)
-
-try:
- Container(Server("127.0.0.1:%i" % port)).run()
-except KeyboardInterrupt:
- pass
-
diff --git a/contrib/block_time.pl b/contrib/block_time.pl
index dff43ea4e..17da3c461 100755
--- a/contrib/block_time.pl
+++ b/contrib/block_time.pl
@@ -1,5 +1,5 @@
#!/usr/bin/perl
-# Copyright 2019 The Hush developers
+# Copyright 2019-2020 The Hush developers
# Released under the GPLv3
use warnings;
use strict;
@@ -9,6 +9,11 @@ my $block = shift || die "Usage: $0 123";
my $hush = "./src/hush-cli";
my $blockcount = qx{$hush getblockcount};
+unless ($blockcount = int($blockcount)) {
+ print "Invalid response from hush-cli\n";
+ exit 1;
+}
+
if ($block <= $blockcount) {
die "That block has already happened!";
} else {
diff --git a/contrib/checkpoints.pl b/contrib/checkpoints.pl
index 99a84f2c2..bf11a8f7f 100755
--- a/contrib/checkpoints.pl
+++ b/contrib/checkpoints.pl
@@ -1,5 +1,5 @@
#!/usr/bin/perl
-# Copyright 2019 The Hush developers
+# Copyright 2019-2020 The Hush developers
# Released under the GPLv3
use warnings;
use strict;
@@ -9,9 +9,13 @@ use strict;
my $perday = 576;
my $hush = "./src/hush-cli";
my $gethash = "$hush getblockhash";
-my $stride = shift || 1000;
+my $stride = shift || 5000;
my $count = 0;
my $blocks = qx{$hush getblockcount};
+if($?) {
+ print "ERROR, exiting...\n";
+ exit 1;
+}
my $prev = $blocks - $perday;
my $last = 0;
my $now = time();
@@ -53,4 +57,4 @@ if ($line1 =~ m/tx=(\d+)/) {
}
print "(int64_t) $time, // time of last checkpointed block\n";
print "(int64_t) $total_txs, // total txs\n";
-print "(double) $txs_per_day, // txs in the last day before block $blocks\n";
+print "(double) $txs_per_day // txs in the last day before block $blocks\n";
diff --git a/contrib/debian/copyright b/contrib/debian/copyright
index 9371b7022..2f51f4a4c 100644
--- a/contrib/debian/copyright
+++ b/contrib/debian/copyright
@@ -52,10 +52,6 @@ Files: depends/sources/google*.tar.gz
Copyright: 2008 Google Inc.
License: BSD-3clause-Google
-Files: depends/sources/qpid-proton-*.tar.gz
-Copyright: 2012-2017 The Apache Software Foundation
-License: Apache-Qpid-Proton-with-BSD-Subcomponents
-
Files: src/secp256k1/build-aux/m4/ax_jni_include_dir.m4
Copyright: 2008 Don Anderson
License: GNU-All-permissive-License
@@ -1101,222 +1097,6 @@ Comment:
You should have received a copy of the GNU General Public License
along with this program. If not, see .
-License: Apache-Qpid-Proton-with-BSD-Subcomponents
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
- .
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
- .
- 1. Definitions.
- .
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
- .
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
- .
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
- .
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
- .
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
- .
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
- .
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
- .
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
- .
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
- .
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
- .
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
- .
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
- .
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
- .
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
- .
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
- .
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
- .
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
- .
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
- .
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
- .
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
- .
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
- .
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
- .
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
- .
- END OF TERMS AND CONDITIONS
- .
- APPENDIX: How to apply the Apache License to your work.
- .
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
- .
- Copyright [yyyy] [name of copyright owner]
- .
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- .
- http://www.apache.org/licenses/LICENSE-2.0
- .
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- .
- .
- PROTON SUBCOMPONENTS:
- .
- Proton includes freegetopt with a separate BSD license. Your use
- of the source code for freegetopt is subject to the terms and
- conditions of its license in examples/include/pncompat/internal/LICENSE.
- .
- The setup scripts for the python bindings include files derived by
- PyZMQ and are licensed with a separate Modified BSD license. Use of
- the source code in these setup files are subject to the terms and
- conditions in the license:
- proton-c/bindings/python/setuputils/PYZMQ_LICENSE.BSD.
-
License: GNU-All-permissive-License
Copying and distribution of this file, with or without modification, are
permitted in any medium without royalty provided the copyright notice
diff --git a/contrib/devtools/gen-linux-binary-release.sh b/contrib/devtools/gen-linux-binary-release.sh
new file mode 100644
index 000000000..21d4d70b9
--- /dev/null
+++ b/contrib/devtools/gen-linux-binary-release.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+# Copyright (c) 2019-2020 The Hush developers
+# Released under the GPLv3
+
+
+#TODO: autodect version number, error handling
+FILE="hush-3.5.0-linux-amd64.tar"
+
+mkdir build
+cp sapling*.params build/
+cd src
+cp komodod komodo-cli komodo-tx hushd hush-cli hush-tx hush-smart-chain ../build
+cd ../build
+tar -f $FILE -c *
+gzip $FILE
+
diff --git a/contrib/devtools/symbol-check.py b/contrib/devtools/symbol-check.py
index 52b48ef74..ea671d774 100755
--- a/contrib/devtools/symbol-check.py
+++ b/contrib/devtools/symbol-check.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# Copyright (c) 2014 Wladimir J. van der Laan
# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
'''
A script to check that the (Linux) executables produced by gitian only contain
allowed gcc, glibc and libstdc++ version symbols. This makes sure they are
diff --git a/contrib/gitian-descriptors/gitian-linux.yml b/contrib/gitian-descriptors/gitian-linux.yml
index c619cf270..317bd8694 100644
--- a/contrib/gitian-descriptors/gitian-linux.yml
+++ b/contrib/gitian-descriptors/gitian-linux.yml
@@ -85,7 +85,7 @@ script: |
BASEPREFIX=`pwd`/depends
# Build dependencies for each host
for i in $HOSTS; do
- NO_PROTON="x" make ${MAKEOPTS} -C ${BASEPREFIX} HOST="${i}"
+ make ${MAKEOPTS} -C ${BASEPREFIX} HOST="${i}"
done
# Faketime for binaries
diff --git a/contrib/hush-cli.bash-completion b/contrib/hush-cli.bash-completion
index 32cfe6b22..b750e4ae9 100644
--- a/contrib/hush-cli.bash-completion
+++ b/contrib/hush-cli.bash-completion
@@ -2,7 +2,7 @@
# Copyright (c) 2012-2016 The Bitcoin Core developers
# Copyright (c) 2018 The Hush developers
# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
# call $hush-cli for RPC
_hush_rpc() {
diff --git a/contrib/hush-tx.bash-completion b/contrib/hush-tx.bash-completion
index d43d0cba3..b49ada489 100644
--- a/contrib/hush-tx.bash-completion
+++ b/contrib/hush-tx.bash-completion
@@ -1,7 +1,7 @@
# bash programmable completion for hush-tx(1)
# Copyright (c) 2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
_hush_tx() {
local cur prev words=() cword
diff --git a/contrib/hush_block_subsidy_per_halving b/contrib/hush_block_subsidy_per_halving
new file mode 100755
index 000000000..7e7b05b4b
--- /dev/null
+++ b/contrib/hush_block_subsidy_per_halving
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+# Copyright 2019-2020 The Hush developers
+# Released under the GPLv3
+
+use strict;
+use warnings;
+
+my $x = 12.5 * 100000000;
+my $n = 0;
+while ($n<=31) {
+ #printf "$n,%.16g,%.16g,%.16g\n", $x, $x*0.90, $x*0.1;
+ printf "$n,%d,%d,%d\n", $x, $x*0.90, $x*0.1;
+ $x = $x / 2;
+ $n++;
+ exit if ($x <= 0);
+}
+
diff --git a/contrib/hush_halvings b/contrib/hush_halvings
new file mode 100755
index 000000000..67246bb13
--- /dev/null
+++ b/contrib/hush_halvings
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+# Copyright 2019-2020 The Hush developers
+# Released under the GPLv3
+
+use strict;
+use warnings;
+
+my $x = 340_000;
+my $n = 0;
+my $r = 12_500_000_000;
+while ($n<=32) {
+ printf "%d,%d,%d\n", $n+1, $r, $x + 1680000*$n;
+ # blocktime halving at block 340000
+ if ($n==0) {
+ $r = 3.125 * 100_000_000;
+ } else {
+ $r /= 2;
+ }
+
+ $n++;
+}
+
diff --git a/contrib/hush_supply b/contrib/hush_supply
index 92e917055..fcf4460dc 100755
--- a/contrib/hush_supply
+++ b/contrib/hush_supply
@@ -1,33 +1,218 @@
#!/usr/bin/env perl
-# Copyright 2019 The Hush developers
+# Copyright 2019-2020 The Hush developers
# Released under the GPLv3
use warnings;
use strict;
+
my $supply = 0.0;
-my $block = 0;
-my $satoshis = 100_000_000;
-my $amount = int(12.5*$satoshis);
+my $block = 0; # Block 0 in Hush Smart chains is the BTC genesis block
+my $puposhis = 100_000_000;
+my $subsidy0 = 1_250_000_000;
my $halvings = 0;
+my $initial = 6178674 * $puposhis;
+my $interval = 1_680_000; # ~4 years of 75s blocks
+my $stop = shift || -1;
+my $totalfr = 0; # total paid out to FR address
-# Usage: ./hush_supply &> supply.csv
-# Use this to calculate when supply hits a certain value
-#while ($supply <= 21_000_000*$satoshis) {
-# Use this to calculate when block rewards end
-while ($halvings <= 64 && $amount >= 1) {
- $block++;
- if ($block < 5) {
- $amount = 40_000 * $satoshis;
- } else {
- # Halving every 840000 blocks
- if ($block % 840_000 == 0) {
- $amount /= 2;
- $halvings++;
- }
- $amount = int(12.5*$satoshis) / (2**$halvings);
- }
- $supply += $amount;
- # block, current supply, block reward amount, number of halvings
- printf "%s,%s,%s,%s\n", $block,$supply / $satoshis, $amount / $satoshis, $halvings;
+if ($stop eq 'help' or $stop =~ m/-h/) {
+ die < supply.csv
+ ./hush_supply HEIGHT &> supply.csv # stop at HEIGHT
+# This will generate CSV in the form of:
+# block, supply, reward, subsidy, fr, totalfr, halvings
+HELP
+}
+
+
+printf "# block, supply, reward, subsidy, fr, totalfr, halvings\n";
+
+# Block Reward Amounts in puposhis
+# The non-integral amounts cannot be represented exactly
+# 12.5 * 100000000 = 1250000000
+# 12.5 * 100000000 / 2 = 625000000
+# 12.5 * 100000000 / 4 = 312500000
+# 12.5 * 100000000 / 8 = 156250000
+# 12.5 * 100000000 / 16 = 78125000
+# 12.5 * 100000000 / 32 = 39062500
+# 12.5 * 100000000 / 64 = 19531250
+# 12.5 * 100000000 / 128 = 9765625
+# 12.5 * 100000000 / 256 = 4882812.5
+# 12.5 * 100000000 / 512 = 2441406.25
+# 12.5 * 100000000 / 1024 = 1220703.125
+# 12.5 * 100000000 / 2048 = 610351.5625
+# 12.5 * 100000000 / 4096 = 305175.78125
+# 12.5 * 100000000 / 8192 = 152587.890625
+# 12.5 * 100000000 / 16384 = 76293.9453125
+# 12.5 * 100000000 / 32768 = 38146.97265625
+# 12.5 * 100000000 / 65536 = 19073.486328125
+
+# Hush Halving Heights and Block Rewards
+# 1,12500000000,340000
+# 2,312500000,2020000
+# 3,156250000,3700000
+# 4,78125000,5380000
+# 5,39062500,7060000
+# 6,19531250,8740000
+# 7,9765625,10420000
+# 8,4882812,12100000
+# 9,2441406,13780000
+# 10,1220703,15460000
+# 11,610351,17140000
+# 12,305175,18820000
+# 13,152587,20500000
+# 14,76293,22180000
+# 15,38146,23860000
+# 16,19073,25540000
+# 17,9536,27220000
+# 18,4768,28900000
+# 19,2384,30580000
+# 20,1192,32260000
+# 21,596,33940000
+# 22,298,35620000
+# 23,149,37300000
+# 24,74,38980000
+# 25,37,40660000
+# 26,18,42340000
+# 27,9,44020000
+# 28,4,45700000
+# 29,2,47380000
+# 30,1,49060000
+# 31,0,50740000
+
+
+sub hush_block_reward
+{
+ my $reward = 0;
+ my $height = shift;
+ my $halvings = 0;
+
+ if ($height >= 50740000) {
+ $reward = 0;
+ $halvings = 31;
+ } elsif ($height >= 49060000) {
+ $reward = 1;
+ $halvings = 30;
+ } elsif ($height >= 47380000) {
+ $reward = 1;
+ $halvings = 29;
+ } elsif ($height >= 45700000) {
+ $reward = 2;
+ $halvings = 28;
+ } elsif ($height >= 44020000) {
+ $reward = 4;
+ $halvings = 27;
+ } elsif ($height >= 42340000) {
+ $reward = 9;
+ $halvings = 26;
+ } elsif ($height >= 40660000) {
+ $reward = 18;
+ $halvings = 25;
+ } elsif ($height >= 38980000) {
+ $reward = 37;
+ $halvings = 24;
+ } elsif ($height >= 37380000) {
+ $reward = 74;
+ $halvings = 23;
+ } elsif ($height >= 35620000) {
+ $reward = 149;
+ $halvings = 22;
+ } elsif ($height >= 33940000) {
+ $reward = 298;
+ $halvings = 21;
+ } elsif ($height >= 32260001) {
+ $reward = 596;
+ $halvings = 20;
+ } elsif ($height >= 30580000) {
+ $reward = 1192;
+ $halvings = 19;
+ } elsif ($height >= 28900000) {
+ $reward = 2384;
+ $halvings = 18;
+ } elsif ($height >= 27220000) {
+ $reward = 4768;
+ $halvings = 17;
+ } elsif ($height >= 25540000) {
+ $reward = 9536;
+ $halvings = 16;
+ } elsif ($height >= 23860000) {
+ $reward = 19073; # 0.486328125 deviation
+ $halvings = 15;
+ } elsif ($height >= 22180000) {
+ $reward = 38146; # 0.97265625 deviation
+ $halvings = 14;
+ } elsif ($height >= 20500000) {
+ $reward = 76293; # 0.9453125 deviation
+ $halvings = 13;
+ } elsif ($height >= 18820000) {
+ $reward = 152587; # 0.890625 deviation
+ $halvings = 12;
+ } elsif ($height >= 17140000) {
+ $reward = 305175; # 0.78125sat deviation
+ $halvings = 11;
+ } elsif ($height >= 15460000) {
+ $reward = 610351; # 0.5625sat deviation
+ $halvings = 10;
+ } elsif ($height >= 13780000) {
+ $reward = 1220703; # 0.125sat deviation
+ $halvings = 9
+ } elsif ($height >= 12100000) {
+ $reward = 2441406; # 0.25sat deviation
+ $halvings = 8
+ } elsif ($height >= 10420000) {
+ $reward = 4882812; # 0.5sat deviation
+ $halvings = 7;
+ } elsif ($height >= 8740000) {
+ $reward = 9765625; # last exact reward
+ $halvings = 6;
+ } elsif ($height >= 7060000) {
+ $reward = 19531250; # 0.1953125 HUSH
+ $halvings = 5;
+ } elsif ($height >= 5380000) {
+ $reward = 39062500; # 0.390625 HUSH
+ $halvings = 4;
+ } elsif ($height >= 3700000) {
+ $reward = 78125000; # 0.78125 HUSH
+ $halvings = 3;
+ } elsif ($height >= 2020000) {
+ $reward = 156250000; # 1.5625 HUSH
+ $halvings = 2;
+ } elsif ($height >= 340000) {
+ $reward = 312500000; # 3.125 HUSH
+ $halvings = 1;
+ } elsif ($height >= 128) {
+ $reward = 1250000000; # 12.5 HUSH
+ }
+
+ return ($reward,$halvings);
+}
+
+# Block reward is 0 at the 31st halving
+while ($halvings <= 30) {
+ $block++;
+ my ($reward,$halvings) = hush_block_reward($block);
+ my $fr = int($reward / 10);
+ my $subsidy = $reward - $fr;
+
+ if($block == 1) {
+ # initial airdrop of funds from HUSH v2 network @ Block 500000
+ $reward = $initial;
+ $subsidy= $reward;
+ $fr = 0;
+ }
+ $supply += $reward;
+ $totalfr += $fr;
+
+ # all values in puposhis
+ # block, current supply, block reward amount, fr, totalfr, number of halvings
+ printf "%d,%d,%d,%d,%d,%d,%d\n", $block, $supply, $reward, $subsidy, $fr, $totalfr, $halvings;
+ exit(0) if $block == $stop;
+ exit(0) if ($block > 128 && $reward == 0);
+ exit(-1) if ($supply >= 21_000_000*$puposhis);
}
diff --git a/contrib/hush_supply_old b/contrib/hush_supply_old
new file mode 100755
index 000000000..674424073
--- /dev/null
+++ b/contrib/hush_supply_old
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+# Copyright 2019-2020 The Hush developers
+# Released under the GPLv3
+use warnings;
+use strict;
+
+my $supply = 0.0;
+my $block = 0;
+my $satoshis = 100_000_000;
+my $amount = int(12.5*$satoshis);
+my $halvings = 0;
+
+# Usage: ./hush_supply &> supply.csv
+
+# Use this to calculate when supply hits a certain value
+#while ($supply <= 21_000_000*$satoshis) {
+# Use this to calculate when block rewards end
+while ($halvings <= 64 && $amount >= 1) {
+ $block++;
+ if ($block < 5) {
+ $amount = 40_000 * $satoshis;
+ } else {
+ # Halving every 840000 blocks
+ if ($block % 840_000 == 0) {
+ $amount /= 2;
+ $halvings++;
+ }
+ $amount = int(12.5*$satoshis) / (2**$halvings);
+ }
+ $supply += $amount;
+ # block, current supply, block reward amount, number of halvings
+ printf "%s,%s,%s,%s\n", $block,$supply / $satoshis, $amount / $satoshis, $halvings;
+}
diff --git a/contrib/hushd.bash-completion b/contrib/hushd.bash-completion
index 8a80c96a0..418659a16 100644
--- a/contrib/hushd.bash-completion
+++ b/contrib/hushd.bash-completion
@@ -3,7 +3,7 @@
# Copyright (c) 2016-2017 The Zcash developers
# Copyright (c) 2018 The Hush developers
# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
_hushd() {
local cur prev words=() cword
diff --git a/contrib/komodo-cli.bash-completion b/contrib/komodo-cli.bash-completion
index 1efc05d46..784e5c807 100644
--- a/contrib/komodo-cli.bash-completion
+++ b/contrib/komodo-cli.bash-completion
@@ -1,7 +1,7 @@
# bash programmable completion for komodo-cli(1)
# Copyright (c) 2012-2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
# call $komodo-cli for RPC
_komodo_rpc() {
diff --git a/contrib/komodo-tx.bash-completion b/contrib/komodo-tx.bash-completion
index 69e259381..aa80cfd6c 100644
--- a/contrib/komodo-tx.bash-completion
+++ b/contrib/komodo-tx.bash-completion
@@ -1,7 +1,7 @@
# bash programmable completion for komodo-tx(1)
# Copyright (c) 2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
_komodo_tx() {
local cur prev words=() cword
diff --git a/contrib/komodod.bash-completion b/contrib/komodod.bash-completion
index 4c1ec516f..ad73f5fbf 100644
--- a/contrib/komodod.bash-completion
+++ b/contrib/komodod.bash-completion
@@ -2,7 +2,7 @@
# Copyright (c) 2012-2017 The Bitcoin Core developers
# Copyright (c) 2016-2017 The komodo developers
# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
_komodod() {
local cur prev words=() cword
diff --git a/contrib/linearize/linearize-data.py b/contrib/linearize/linearize-data.py
index 8badb4b31..54a460a44 100755
--- a/contrib/linearize/linearize-data.py
+++ b/contrib/linearize/linearize-data.py
@@ -4,7 +4,7 @@
#
# Copyright (c) 2013-2014 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
from __future__ import print_function, division
diff --git a/contrib/linearize/linearize-hashes.py b/contrib/linearize/linearize-hashes.py
index 7e9cf8898..17afd4e2a 100755
--- a/contrib/linearize/linearize-hashes.py
+++ b/contrib/linearize/linearize-hashes.py
@@ -4,7 +4,7 @@
#
# Copyright (c) 2013-2014 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
from __future__ import print_function
diff --git a/contrib/seeds/generate-seeds.py b/contrib/seeds/generate-seeds.py
index c6a2ce636..1772c07e6 100755
--- a/contrib/seeds/generate-seeds.py
+++ b/contrib/seeds/generate-seeds.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# Copyright (c) 2014 Wladimir J. van der Laan
# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
'''
Script to generate list of seed nodes for chainparams.cpp.
diff --git a/contrib/zmq/zmq_sub.py b/contrib/zmq/zmq_sub.py
index 3dea5e3c1..b1603e3d0 100755
--- a/contrib/zmq/zmq_sub.py
+++ b/contrib/zmq/zmq_sub.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014-2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
import array
import binascii
diff --git a/depends/.gitignore b/depends/.gitignore
index 1f163897b..3cb4b9ac1 100644
--- a/depends/.gitignore
+++ b/depends/.gitignore
@@ -7,3 +7,4 @@ x86_64*
i686*
mips*
arm*
+aarch64*
diff --git a/depends/Makefile b/depends/Makefile
index 636577d13..82acde0ac 100644
--- a/depends/Makefile
+++ b/depends/Makefile
@@ -74,9 +74,8 @@ include builders/default.mk
include packages/packages.mk
wallet_packages_$(NO_WALLET) = $(wallet_packages)
-proton_packages_$(NO_PROTON) = $(proton_packages)
-packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(rust_packages) $(proton_packages_) $(wallet_packages_)
+packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(rust_packages) $(wallet_packages_)
native_packages += $($(host_arch)_$(host_os)_native_packages) $($(host_os)_native_packages)
all_packages = $(packages) $(native_packages)
@@ -112,6 +111,7 @@ $(host_prefix)/share/config.site : config.site.in $(host_prefix)/.stamp_$(final_
-e 's|@CXXFLAGS@|$(strip $(host_CXXFLAGS) $(host_$(release_type)_CXXFLAGS))|' \
-e 's|@CPPFLAGS@|$(strip $(host_CPPFLAGS) $(host_$(release_type)_CPPFLAGS))|' \
-e 's|@LDFLAGS@|$(strip $(host_LDFLAGS) $(host_$(release_type)_LDFLAGS))|' \
+ -e 's|@rust_target@|$(call rust_target,rust,$(canonical_host),$(host_os))|' \
-e 's|@no_wallet@|$(NO_WALLET)|' \
-e 's|@debug@|$(DEBUG)|' \
$< > $@
diff --git a/depends/config.site.in b/depends/config.site.in
index 8cdbcd2e4..dbcb7a6e4 100644
--- a/depends/config.site.in
+++ b/depends/config.site.in
@@ -13,6 +13,9 @@ if test -z $enable_wallet && test -n "@no_wallet@"; then
enable_wallet=no
fi
+RUST_TARGET="@rust_target@"
+RUST_VENDORED_SOURCES="$depends_prefix/vendored-sources"
+
if test x@host_os@ = xdarwin; then
BREW=no
PORT=no
diff --git a/depends/funcs.mk b/depends/funcs.mk
index 3d89de8a7..35ca5abcf 100644
--- a/depends/funcs.mk
+++ b/depends/funcs.mk
@@ -40,7 +40,7 @@ endef
define vendor_crate_source
mkdir -p $($(1)_staging_prefix_dir)/$(CRATE_REGISTRY) && \
-cp -r $($(1)_extract_dir) $($(1)_staging_prefix_dir)/$(CRATE_REGISTRY)/$($(1)_crate_name) && \
+cp -r $($(1)_extract_dir) $($(1)_staging_prefix_dir)/$(CRATE_REGISTRY)/$($(1)_crate_versioned_name) && \
cd $($(1)_staging_prefix_dir)/$(CRATE_REGISTRY)/$($(1)_crate_versioned_name) && \
rm -r `basename $($(1)_patch_dir)` .stamp_* .$($(1)_file_name).hash
endef
@@ -59,8 +59,8 @@ $(eval $(1)_build_id:=$(shell echo -n "$($(1)_build_id_long)" | $(build_SHA256SU
final_build_id_long+=$($(package)_build_id_long)
#override platform specific files and hashes
-$(eval $(1)_file_name=$(if $($(1)_file_name_$(host_os)),$($(1)_file_name_$(host_os)),$($(1)_file_name)))
-$(eval $(1)_sha256_hash=$(if $($(1)_sha256_hash_$(host_os)),$($(1)_sha256_hash_$(host_os)),$($(1)_sha256_hash)))
+$(eval $(1)_file_name=$(if $($(1)_exact_file_name),$($(1)_exact_file_name),$(if $($(1)_file_name_$(host_os)),$($(1)_file_name_$(host_os)),$($(1)_file_name))))
+$(eval $(1)_sha256_hash=$(if $($(1)_exact_sha256_hash),$($(1)_exact_sha256_hash),$(if $($(1)_sha256_hash_$(host_os)),$($(1)_sha256_hash_$(host_os)),$($(1)_sha256_hash))))
#compute package-specific paths
$(1)_build_subdir?=.
@@ -91,8 +91,9 @@ $(1)_download_path_fixed=$(subst :,\:,$$($(1)_download_path))
#default commands
+# The default behavior for tar will try to set ownership when running as uid 0 and may not succeed, --no-same-owner disables this behavior
$(1)_fetch_cmds ?= $(call fetch_file,$(1),$(subst \:,:,$$($(1)_download_path_fixed)),$$($(1)_download_file),$($(1)_file_name),$($(1)_sha256_hash))
-$(1)_extract_cmds ?= mkdir -p $$($(1)_extract_dir) && echo "$$($(1)_sha256_hash) $$($(1)_source)" > $$($(1)_extract_dir)/.$$($(1)_file_name).hash && $(build_SHA256SUM) -c $$($(1)_extract_dir)/.$$($(1)_file_name).hash && tar --strip-components=1 -xf $$($(1)_source)
+$(1)_extract_cmds ?= mkdir -p $$($(1)_extract_dir) && echo "$$($(1)_sha256_hash) $$($(1)_source)" > $$($(1)_extract_dir)/.$$($(1)_file_name).hash && $(build_SHA256SUM) -c $$($(1)_extract_dir)/.$$($(1)_file_name).hash && tar --no-same-owner --strip-components=1 -xf $$($(1)_source)
$(1)_preprocess_cmds ?=
$(1)_build_cmds ?=
$(1)_config_cmds ?=
@@ -193,7 +194,7 @@ $($(1)_preprocessed): | $($(1)_dependencies) $($(1)_extracted)
$(AT)touch $$@
$($(1)_configured): | $($(1)_preprocessed)
$(AT)echo Configuring $(1)...
- $(AT)rm -rf $(host_prefix); mkdir -p $(host_prefix)/lib; cd $(host_prefix); $(foreach package,$($(1)_all_dependencies), tar xf $($(package)_cached); )
+ $(AT)rm -rf $(host_prefix); mkdir -p $(host_prefix)/lib; cd $(host_prefix); $(foreach package,$($(1)_all_dependencies), tar --no-same-owner -xf $($(package)_cached); )
$(AT)mkdir -p $$(@D)
$(AT)+cd $$(@D); $($(1)_config_env) $(call $(1)_config_cmds, $(1))
$(AT)touch $$@
diff --git a/depends/packages/bdb.mk b/depends/packages/bdb.mk
index 404d94c51..c8f677490 100644
--- a/depends/packages/bdb.mk
+++ b/depends/packages/bdb.mk
@@ -9,6 +9,11 @@ define $(package)_set_vars
$(package)_config_opts=--disable-shared --enable-cxx --disable-replication
$(package)_config_opts_mingw32=--enable-mingw
$(package)_config_opts_linux=--with-pic
+$(package)_config_opts_freebsd=--with-pic
+ifneq ($(build_os),darwin)
+$(package)_config_opts_darwin=--disable-atomicsupport
+endif
+$(package)_config_opts_aarch64=--disable-atomicsupport
$(package)_cxxflags=-std=c++11
endef
diff --git a/depends/packages/boost.mk b/depends/packages/boost.mk
index 48c60710d..3112ca7be 100644
--- a/depends/packages/boost.mk
+++ b/depends/packages/boost.mk
@@ -1,7 +1,7 @@
package=boost
$(package)_version=1_72_0
-$(package)_download_path=https://dl.bintray.com/boostorg/release/1.72.0/source/
+$(package)_download_path=https://github.com/MyHush/boost/releases/download/v1.72.0/
$(package)_sha256_hash=59c9b274bc451cf91a9ba1dd2c7fdcaf5d60b1b3aa83f2c9fa143417cc660722
$(package)_file_name=$(package)_$($(package)_version).tar.bz2
diff --git a/depends/packages/libcurl.mk b/depends/packages/libcurl.mk
index fd82dc4e0..91ff1c0f1 100644
--- a/depends/packages/libcurl.mk
+++ b/depends/packages/libcurl.mk
@@ -4,7 +4,7 @@ $(package)_dependencies=openssl
$(package)_download_path=https://curl.haxx.se/download
$(package)_file_name=curl-$($(package)_version).tar.gz
$(package)_sha256_hash=52af3361cf806330b88b4fe6f483b6844209d47ae196ac46da4de59bb361ab02
-$(package)_config_opts_linux=--disable-shared --enable-static --prefix=$(host_prefix) --host=x86_64-unknown-linux-gnu
+$(package)_config_opts_linux=--disable-shared --enable-static --prefix=$(host_prefix) --host=$(host)
$(package)_config_opts_mingw32=--enable-mingw --disable-shared --enable-static --prefix=$(host_prefix) --host=x86_64-w64-mingw32
$(package)_config_opts_darwin=--disable-shared --enable-static --prefix=$(host_prefix)
$(package)_cflags_darwin=-mmacosx-version-min=10.9
diff --git a/depends/packages/librustzcash.mk b/depends/packages/librustzcash.mk
index 8612ac05a..fe6ef8a58 100644
--- a/depends/packages/librustzcash.mk
+++ b/depends/packages/librustzcash.mk
@@ -8,15 +8,29 @@ $(package)_git_commit=06da3b9ac8f278e5d4ae13088cf0a4c03d2c13f5
$(package)_dependencies=rust $(rust_crates)
$(package)_patches=cargo.config 0001-Start-using-cargo-clippy-for-CI.patch remove-dev-dependencies.diff no-groth16.patch
+$(package)_rust_target=$(if $(rust_rust_target_$(canonical_host)),$(rust_rust_target_$(canonical_host)),$(canonical_host))
+
ifeq ($(host_os),mingw32)
$(package)_library_file=target/x86_64-pc-windows-gnu/release/rustzcash.lib
+else ifneq ($(canonical_host),$(build))
+ifeq ($(host_os),darwin)
+$(package)_library_file=target/x86_64-apple-darwin/release/librustzcash.a
+else
+$(package)_library_file=target/$($(package)_rust_target)/release/librustzcash.a
+endif
else
$(package)_library_file=target/release/librustzcash.a
endif
define $(package)_set_vars
$(package)_build_opts=--frozen --release
-$(package)_build_opts_mingw32=--target=x86_64-pc-windows-gnu
+ifneq ($(canonical_host),$(build))
+ifeq ($(host_os),darwin)
+$(package)_build_opts+=--target=x86_64-apple-darwin
+else
+$(package)_build_opts+=--target=$($(package)_rust_target)
+endif
+endif
endef
define $(package)_preprocess_cmds
@@ -27,7 +41,7 @@ define $(package)_preprocess_cmds
endef
define $(package)_build_cmds
- cargo build --package librustzcash $($(package)_build_opts)
+ $(host_prefix)/native/bin/cargo build --package librustzcash $($(package)_build_opts)
endef
define $(package)_stage_cmds
diff --git a/depends/packages/openssl.mk b/depends/packages/openssl.mk
index 276e887a7..6f939f0fa 100644
--- a/depends/packages/openssl.mk
+++ b/depends/packages/openssl.mk
@@ -1,9 +1,8 @@
package=openssl
-$(package)_version=1.1.1a
-$(package)_download_path=https://www.openssl.org/source/old/1.1.1
+$(package)_version=1.1.1h
+$(package)_download_path=https://www.openssl.org/source
$(package)_file_name=$(package)-$($(package)_version).tar.gz
-$(package)_sha256_hash=fc20130f8b7cbd2fb918b2f14e2f429e109c31ddd0fb38fc5d71d9ffed3f9f41
-$(package)_patches=ssl_fix.patch
+$(package)_sha256_hash=5c9ca8774bd7b03e5784f26ae9e9e6d749c9da2438545077e6b3d755a06595d9
define $(package)_set_vars
$(package)_config_env=AR="$($(package)_ar)" RANLIB="$($(package)_ranlib)" CC="$($(package)_cc)"
@@ -14,39 +13,40 @@ $(package)_config_opts+=no-async
$(package)_config_opts+=no-bf
$(package)_config_opts+=no-blake2
$(package)_config_opts+=no-camellia
-$(package)_config_opts+=no-capieng
+#$(package)_config_opts+=no-capieng
$(package)_config_opts+=no-cast
-$(package)_config_opts+=no-chacha
+#$(package)_config_opts+=no-chacha
$(package)_config_opts+=no-cmac
$(package)_config_opts+=no-cms
-$(package)_config_opts+=no-comp
+#$(package)_config_opts+=no-comp
$(package)_config_opts+=no-crypto-mdebug
$(package)_config_opts+=no-crypto-mdebug-backtrace
-$(package)_config_opts+=no-ct
+#$(package)_config_opts+=no-ct
+#$(package)_config_opts+=no-des
$(package)_config_opts+=no-dgram
-$(package)_config_opts+=no-dsa
+#$(package)_config_opts+=no-dsa
$(package)_config_opts+=no-dso
$(package)_config_opts+=no-dtls
$(package)_config_opts+=no-dtls1
$(package)_config_opts+=no-dtls1-method
$(package)_config_opts+=no-dynamic-engine
-$(package)_config_opts+=no-ec2m
-$(package)_config_opts+=no-ec_nistp_64_gcc_128
+#$(package)_config_opts+=no-ec2m
+#$(package)_config_opts+=no-ec_nistp_64_gcc_128
$(package)_config_opts+=no-egd
$(package)_config_opts+=no-engine
-$(package)_config_opts+=no-err
+#$(package)_config_opts+=no-err
$(package)_config_opts+=no-gost
$(package)_config_opts+=no-heartbeats
-$(package)_config_opts+=no-idea
+#$(package)_config_opts+=no-idea
$(package)_config_opts+=no-md2
$(package)_config_opts+=no-md4
$(package)_config_opts+=no-mdc2
$(package)_config_opts+=no-multiblock
$(package)_config_opts+=no-nextprotoneg
$(package)_config_opts+=no-ocb
-$(package)_config_opts+=no-ocsp
-$(package)_config_opts+=no-poly1305
-$(package)_config_opts+=no-posix-io
+#$(package)_config_opts+=no-ocsp
+#$(package)_config_opts+=no-poly1305
+#$(package)_config_opts+=no-posix-io
$(package)_config_opts+=no-psk
$(package)_config_opts+=no-rc2
$(package)_config_opts+=no-rc4
@@ -58,21 +58,24 @@ $(package)_config_opts+=no-scrypt
$(package)_config_opts+=no-sctp
$(package)_config_opts+=no-seed
$(package)_config_opts+=no-shared
+#$(package)_config_opts+=no-sock
$(package)_config_opts+=no-srp
$(package)_config_opts+=no-srtp
+$(package)_config_opts+=no-ssl
$(package)_config_opts+=no-ssl3
$(package)_config_opts+=no-ssl3-method
$(package)_config_opts+=no-ssl-trace
-$(package)_config_opts+=no-stdio
-$(package)_config_opts+=no-tls1
-$(package)_config_opts+=no-tls1-method
+#$(package)_config_opts+=no-stdio
+#$(package)_config_opts+=no-tls
+#$(package)_config_opts+=no-tls1
+#$(package)_config_opts+=no-tls1-method
$(package)_config_opts+=no-ts
$(package)_config_opts+=no-ui
$(package)_config_opts+=no-unit-test
$(package)_config_opts+=no-weak-ssl-ciphers
$(package)_config_opts+=no-whirlpool
-$(package)_config_opts+=no-zlib
-$(package)_config_opts+=no-zlib-dynamic
+#$(package)_config_opts+=no-zlib
+#$(package)_config_opts+=no-zlib-dynamic
$(package)_config_opts+=$($(package)_cflags) $($(package)_cppflags)
$(package)_config_opts+=-DPURIFY
$(package)_config_opts_linux=-fPIC -Wa,--noexecstack
@@ -89,9 +92,8 @@ $(package)_config_opts_i686_mingw32=mingw
endef
define $(package)_preprocess_cmds
- sed -i.old 's/built on: $date/built on: not available/' util/mkbuildinf.pl && \
- sed -i.old "s|\"engines\", \"apps\", \"test\"|\"engines\"|" Configure && \
- patch -p1 < $($(package)_patch_dir)/ssl_fix.patch
+ sed -i.old 's/built on: $$$$date/built on: date not available/' util/mkbuildinf.pl && \
+ sed -i.old "s|\"engines\", \"apps\", \"test\"|\"engines\"|" Configure
endef
define $(package)_config_cmds
diff --git a/depends/packages/packages.mk b/depends/packages/packages.mk
index 8abb7c708..9c76166af 100644
--- a/depends/packages/packages.mk
+++ b/depends/packages/packages.mk
@@ -1,12 +1,4 @@
-rust_packages := rust librustzcash
-
-ifeq ($(build_os),darwin)
- zcash_packages := libgmp libsodium utfcpp
-else
- proton_packages := proton
- zcash_packages := libgmp libsodium utfcpp
-endif
-
+zcash_packages := libgmp libsodium utfcpp
rust_crates := \
crate_aes \
crate_aesni \
diff --git a/depends/packages/proton.mk b/depends/packages/proton.mk
deleted file mode 100644
index 1bb5c8865..000000000
--- a/depends/packages/proton.mk
+++ /dev/null
@@ -1,23 +0,0 @@
-package=proton
-$(package)_version=0.26.0
-$(package)_download_path=https://archive.apache.org/dist/qpid/proton/$($(package)_version)
-$(package)_file_name=qpid-proton-$($(package)_version).tar.gz
-$(package)_sha256_hash=0eddac870f0085b9aeb0c9da333bd3f53fedb7c872164171a7cc06761ddbbd75
-$(package)_patches=minimal-build.patch
-
-define $(package)_preprocess_cmds
- patch -p1 < $($(package)_patch_dir)/minimal-build.patch && \
- mkdir -p build/proton-c/src
-endef
-
-define $(package)_config_cmds
- cd build; cmake .. -DCMAKE_CXX_STANDARD=11 -DCMAKE_INSTALL_PREFIX=/ -DSYSINSTALL_BINDINGS=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_PYTHON=OFF -DBUILD_PHP=OFF -DBUILD_JAVA=OFF -DBUILD_PERL=OFF -DBUILD_RUBY=OFF -DBUILD_JAVASCRIPT=OFF -DBUILD_GO=OFF -DBUILD_STATIC_LIBS=ON
-endef
-
-define $(package)_build_cmds
- cd build; $(MAKE) VERBOSE=1
-endef
-
-define $(package)_stage_cmds
- cd build; $(MAKE) VERBOSE=1 DESTDIR=$($(package)_staging_prefix_dir) install
-endef
diff --git a/depends/packages/rust.mk b/depends/packages/rust.mk
index 9cfb95054..6fbdda037 100644
--- a/depends/packages/rust.mk
+++ b/depends/packages/rust.mk
@@ -1,7 +1,6 @@
package=rust
$(package)_version=1.32.0
$(package)_download_path=https://static.rust-lang.org/dist
-
$(package)_file_name_linux=rust-$($(package)_version)-x86_64-unknown-linux-gnu.tar.gz
$(package)_sha256_hash_linux=e024698320d76b74daf0e6e71be3681a1e7923122e3ebd03673fcac3ecc23810
$(package)_file_name_darwin=rust-$($(package)_version)-x86_64-apple-darwin.tar.gz
@@ -9,20 +8,26 @@ $(package)_sha256_hash_darwin=f0dfba507192f9b5c330b5984ba71d57d434475f3d62bd44a3
$(package)_file_name_mingw32=rust-$($(package)_version)-x86_64-pc-windows-gnu.tar.gz
$(package)_sha256_hash_mingw32=358e1435347c67dbf33aa9cad6fe501a833d6633ed5d5aa1863d5dffa0349be9
-ifeq ($(build_os),darwin)
-$(package)_file_name=$($(package)_file_name_darwin)
-$(package)_sha256_hash=$($(package)_sha256_hash_darwin)
-else ifeq ($(host_os),mingw32)
-$(package)_file_name=$($(package)_file_name_mingw32)
-$(package)_sha256_hash=$($(package)_sha256_hash_mingw32)
-else
-$(package)_file_name=$($(package)_file_name_linux)
-$(package)_sha256_hash=$($(package)_sha256_hash_linux)
-endif
+# Mapping from GCC canonical hosts to Rust targets
+# If a mapping is not present, we assume they are identical, unless $host_os is
+# "darwin", in which case we assume x86_64-apple-darwin.
+$(package)_rust_target_x86_64-w64-mingw32=x86_64-pc-windows-gnu
-ifeq ($(host_os),mingw32)
+# Mapping from Rust targets to SHA-256 hashes
+$(package)_rust_std_sha256_hash_aarch64-unknown-linux-gnu=346efe3aef2aff7b71a611bf7661bcec5f9bc4025a599c2866ec5fd330247cb9
+$(package)_rust_std_sha256_hash_x86_64-apple-darwin=b736d035a97f830585360e54e3f8877b68c942211cf0a75e805f34bfb36103a6
+$(package)_rust_std_sha256_hash_x86_64-pc-windows-gnu=cad5f1454d591c13eeb3657f1c9dbfeb30e648f59680bd0765b94c63e7afc49e
+
+define rust_target
+$(if $($(1)_rust_target_$(2)),$($(1)_rust_target_$(2)),$(if $(findstring darwin,$(3)),x86_64-apple-darwin,$(2)))
+endef
+
+ifneq ($(canonical_host),$(build))
+$(package)_rust_target=$(call rust_target,$(package),$(canonical_host),$(host_os))
+$(package)_exact_file_name=rust-std-$($(package)_version)-$($(package)_rust_target).tar.gz
+$(package)_exact_sha256_hash=$($(package)_rust_std_sha256_hash_$($(package)_rust_target))
$(package)_build_subdir=buildos
-$(package)_extra_sources = $($(package)_file_name_$(build_os))
+$(package)_extra_sources=$($(package)_file_name_$(build_os))
define $(package)_fetch_cmds
$(call fetch_file,$(package),$($(package)_download_path),$($(package)_download_file),$($(package)_file_name),$($(package)_sha256_hash)) && \
@@ -34,19 +39,19 @@ define $(package)_extract_cmds
echo "$($(package)_sha256_hash) $($(package)_source)" > $($(package)_extract_dir)/.$($(package)_file_name).hash && \
echo "$($(package)_sha256_hash_$(build_os)) $($(package)_source_dir)/$($(package)_file_name_$(build_os))" >> $($(package)_extract_dir)/.$($(package)_file_name).hash && \
$(build_SHA256SUM) -c $($(package)_extract_dir)/.$($(package)_file_name).hash && \
- mkdir mingw32 && \
- tar --strip-components=1 -xf $($(package)_source) -C mingw32 && \
+ mkdir $(canonical_host) && \
+ tar --strip-components=1 -xf $($(package)_source) -C $(canonical_host) && \
mkdir buildos && \
tar --strip-components=1 -xf $($(package)_source_dir)/$($(package)_file_name_$(build_os)) -C buildos
endef
define $(package)_stage_cmds
- ./install.sh --destdir=$($(package)_staging_dir) --prefix=$(host_prefix)/native --disable-ldconfig && \
- cp -r ../mingw32/rust-std-x86_64-pc-windows-gnu/lib/rustlib/x86_64-pc-windows-gnu $($(package)_staging_dir)$(host_prefix)/native/lib/rustlib
+ bash ./install.sh --destdir=$($(package)_staging_dir) --prefix=$(host_prefix)/native --disable-ldconfig && \
+ ../$(canonical_host)/install.sh --destdir=$($(package)_staging_dir) --prefix=$(host_prefix)/native --disable-ldconfig
endef
else
define $(package)_stage_cmds
- ./install.sh --destdir=$($(package)_staging_dir) --prefix=$(host_prefix)/native --disable-ldconfig
+ bash ./install.sh --destdir=$($(package)_staging_dir) --prefix=$(host_prefix)/native --disable-ldconfig
endef
endif
diff --git a/depends/patches/openssl/ssl_fix.patch b/depends/patches/openssl/ssl_fix.patch
deleted file mode 100644
index d7f79fed5..000000000
--- a/depends/patches/openssl/ssl_fix.patch
+++ /dev/null
@@ -1,273 +0,0 @@
-From f725fe5b4b6504df08e30f5194d321c3025e2336 Mon Sep 17 00:00:00 2001
-From: Matt Caswell
-Date: Tue, 20 Nov 2018 15:32:55 +0000
-Subject: [PATCH] Fix a RUN_ONCE bug
-
-We have a number of instances where there are multiple "init" functions for
-a single CRYPTO_ONCE variable, e.g. to load config automatically or to not
-load config automatically. Unfortunately the RUN_ONCE mechanism was not
-correctly giving the right return value where an alternative init function
-was being used.
-
-Reviewed-by: Tim Hudson
-(Merged from https://github.com/openssl/openssl/pull/7983)
----
- crypto/init.c | 38 +++++++++-----
- include/internal/thread_once.h | 92 ++++++++++++++++++++++++++++++++++
- ssl/ssl_init.c | 6 ++-
- 3 files changed, 121 insertions(+), 15 deletions(-)
-
-diff --git a/crypto/init.c b/crypto/init.c
-index 209d1a483da..f20a12f069a 100644
---- a/crypto/init.c
-+++ b/crypto/init.c
-@@ -177,12 +177,6 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_nodelete)
-
- static CRYPTO_ONCE load_crypto_strings = CRYPTO_ONCE_STATIC_INIT;
- static int load_crypto_strings_inited = 0;
--DEFINE_RUN_ONCE_STATIC(ossl_init_no_load_crypto_strings)
--{
-- /* Do nothing in this case */
-- return 1;
--}
--
- DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_strings)
- {
- int ret = 1;
-@@ -201,6 +195,13 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_strings)
- return ret;
- }
-
-+DEFINE_RUN_ONCE_STATIC_ALT(ossl_init_no_load_crypto_strings,
-+ ossl_init_load_crypto_strings)
-+{
-+ /* Do nothing in this case */
-+ return 1;
-+}
-+
- static CRYPTO_ONCE add_all_ciphers = CRYPTO_ONCE_STATIC_INIT;
- DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_ciphers)
- {
-@@ -218,6 +219,13 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_ciphers)
- return 1;
- }
-
-+DEFINE_RUN_ONCE_STATIC_ALT(ossl_init_no_add_all_ciphers,
-+ ossl_init_add_all_ciphers)
-+{
-+ /* Do nothing */
-+ return 1;
-+}
-+
- static CRYPTO_ONCE add_all_digests = CRYPTO_ONCE_STATIC_INIT;
- DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_digests)
- {
-@@ -235,7 +243,8 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_digests)
- return 1;
- }
-
--DEFINE_RUN_ONCE_STATIC(ossl_init_no_add_algs)
-+DEFINE_RUN_ONCE_STATIC_ALT(ossl_init_no_add_all_digests,
-+ ossl_init_add_all_digests)
- {
- /* Do nothing */
- return 1;
-@@ -255,7 +264,7 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_config)
- config_inited = 1;
- return 1;
- }
--DEFINE_RUN_ONCE_STATIC(ossl_init_no_config)
-+DEFINE_RUN_ONCE_STATIC_ALT(ossl_init_no_config, ossl_init_config)
- {
- #ifdef OPENSSL_INIT_DEBUG
- fprintf(stderr,
-@@ -595,8 +604,9 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
- return 0;
-
- if ((opts & OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS)
-- && !RUN_ONCE(&load_crypto_strings,
-- ossl_init_no_load_crypto_strings))
-+ && !RUN_ONCE_ALT(&load_crypto_strings,
-+ ossl_init_no_load_crypto_strings,
-+ ossl_init_load_crypto_strings))
- return 0;
-
- if ((opts & OPENSSL_INIT_LOAD_CRYPTO_STRINGS)
-@@ -604,7 +614,8 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
- return 0;
-
- if ((opts & OPENSSL_INIT_NO_ADD_ALL_CIPHERS)
-- && !RUN_ONCE(&add_all_ciphers, ossl_init_no_add_algs))
-+ && !RUN_ONCE_ALT(&add_all_ciphers, ossl_init_no_add_all_ciphers,
-+ ossl_init_add_all_ciphers))
- return 0;
-
- if ((opts & OPENSSL_INIT_ADD_ALL_CIPHERS)
-@@ -612,7 +623,8 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
- return 0;
-
- if ((opts & OPENSSL_INIT_NO_ADD_ALL_DIGESTS)
-- && !RUN_ONCE(&add_all_digests, ossl_init_no_add_algs))
-+ && !RUN_ONCE_ALT(&add_all_digests, ossl_init_no_add_all_digests,
-+ ossl_init_add_all_digests))
- return 0;
-
- if ((opts & OPENSSL_INIT_ADD_ALL_DIGESTS)
-@@ -624,7 +636,7 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
- return 0;
-
- if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG)
-- && !RUN_ONCE(&config, ossl_init_no_config))
-+ && !RUN_ONCE_ALT(&config, ossl_init_no_config, ossl_init_config))
- return 0;
-
- if (opts & OPENSSL_INIT_LOAD_CONFIG) {
-diff --git a/include/internal/thread_once.h b/include/internal/thread_once.h
-index 224244353ab..e268a959ef3 100644
---- a/include/internal/thread_once.h
-+++ b/include/internal/thread_once.h
-@@ -9,6 +9,20 @@
-
- #include
-
-+/*
-+ * DEFINE_RUN_ONCE: Define an initialiser function that should be run exactly
-+ * once. It takes no arguments and returns and int result (1 for success or
-+ * 0 for failure). Typical usage might be:
-+ *
-+ * DEFINE_RUN_ONCE(myinitfunc)
-+ * {
-+ * do_some_initialisation();
-+ * if (init_is_successful())
-+ * return 1;
-+ *
-+ * return 0;
-+ * }
-+ */
- #define DEFINE_RUN_ONCE(init) \
- static int init(void); \
- int init##_ossl_ret_ = 0; \
-@@ -17,10 +31,30 @@
- init##_ossl_ret_ = init(); \
- } \
- static int init(void)
-+
-+/*
-+ * DECLARE_RUN_ONCE: Declare an initialiser function that should be run exactly
-+ * once that has been defined in another file via DEFINE_RUN_ONCE().
-+ */
- #define DECLARE_RUN_ONCE(init) \
- extern int init##_ossl_ret_; \
- void init##_ossl_(void);
-
-+/*
-+ * DEFINE_RUN_ONCE_STATIC: Define an initialiser function that should be run
-+ * exactly once. This function will be declared as static within the file. It
-+ * takes no arguments and returns and int result (1 for success or 0 for
-+ * failure). Typical usage might be:
-+ *
-+ * DEFINE_RUN_ONCE_STATIC(myinitfunc)
-+ * {
-+ * do_some_initialisation();
-+ * if (init_is_successful())
-+ * return 1;
-+ *
-+ * return 0;
-+ * }
-+ */
- #define DEFINE_RUN_ONCE_STATIC(init) \
- static int init(void); \
- static int init##_ossl_ret_ = 0; \
-@@ -30,6 +64,46 @@
- } \
- static int init(void)
-
-+/*
-+ * DEFINE_RUN_ONCE_STATIC_ALT: Define an alternative initialiser function. This
-+ * function will be declared as static within the file. It takes no arguments
-+ * and returns an int result (1 for success or 0 for failure). An alternative
-+ * initialiser function is expected to be associated with a primary initialiser
-+ * function defined via DEFINE_ONCE_STATIC where both functions use the same
-+ * CRYPTO_ONCE object to synchronise. Where an alternative initialiser function
-+ * is used only one of the primary or the alternative initialiser function will
-+ * ever be called - and that function will be called exactly once. Definitition
-+ * of an alternative initialiser function MUST occur AFTER the definition of the
-+ * primary initialiser function.
-+ *
-+ * Typical usage might be:
-+ *
-+ * DEFINE_RUN_ONCE_STATIC(myinitfunc)
-+ * {
-+ * do_some_initialisation();
-+ * if (init_is_successful())
-+ * return 1;
-+ *
-+ * return 0;
-+ * }
-+ *
-+ * DEFINE_RUN_ONCE_STATIC_ALT(myaltinitfunc, myinitfunc)
-+ * {
-+ * do_some_alternative_initialisation();
-+ * if (init_is_successful())
-+ * return 1;
-+ *
-+ * return 0;
-+ * }
-+ */
-+#define DEFINE_RUN_ONCE_STATIC_ALT(initalt, init) \
-+ static int initalt(void); \
-+ static void initalt##_ossl_(void) \
-+ { \
-+ init##_ossl_ret_ = initalt(); \
-+ } \
-+ static int initalt(void)
-+
- /*
- * RUN_ONCE - use CRYPTO_THREAD_run_once, and check if the init succeeded
- * @once: pointer to static object of type CRYPTO_ONCE
-@@ -43,3 +117,21 @@
- */
- #define RUN_ONCE(once, init) \
- (CRYPTO_THREAD_run_once(once, init##_ossl_) ? init##_ossl_ret_ : 0)
-+
-+/*
-+ * RUN_ONCE_ALT - use CRYPTO_THREAD_run_once, to run an alternative initialiser
-+ * function and check if that initialisation succeeded
-+ * @once: pointer to static object of type CRYPTO_ONCE
-+ * @initalt: alternative initialiser function name that was previously given to
-+ * DEFINE_RUN_ONCE_STATIC_ALT. This function must return 1 for
-+ * success or 0 for failure.
-+ * @init: primary initialiser function name that was previously given to
-+ * DEFINE_RUN_ONCE_STATIC. This function must return 1 for success or
-+ * 0 for failure.
-+ *
-+ * The return value is 1 on success (*) or 0 in case of error.
-+ *
-+ * (*) by convention, since the init function must return 1 on success.
-+ */
-+#define RUN_ONCE_ALT(once, initalt, init) \
-+ (CRYPTO_THREAD_run_once(once, initalt##_ossl_) ? init##_ossl_ret_ : 0)
-diff --git a/ssl/ssl_init.c b/ssl/ssl_init.c
-index c0ccb9304a6..96526472c57 100644
---- a/ssl/ssl_init.c
-+++ b/ssl/ssl_init.c
-@@ -134,7 +134,8 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_load_ssl_strings)
- return 1;
- }
-
--DEFINE_RUN_ONCE_STATIC(ossl_init_no_load_ssl_strings)
-+DEFINE_RUN_ONCE_STATIC_ALT(ossl_init_no_load_ssl_strings,
-+ ossl_init_load_ssl_strings)
- {
- /* Do nothing in this case */
- return 1;
-@@ -207,7 +208,8 @@ int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS * settings)
- return 0;
-
- if ((opts & OPENSSL_INIT_NO_LOAD_SSL_STRINGS)
-- && !RUN_ONCE(&ssl_strings, ossl_init_no_load_ssl_strings))
-+ && !RUN_ONCE_ALT(&ssl_strings, ossl_init_no_load_ssl_strings,
-+ ossl_init_load_ssl_strings))
- return 0;
-
- if ((opts & OPENSSL_INIT_LOAD_SSL_STRINGS)
diff --git a/depends/patches/proton/minimal-build.patch b/depends/patches/proton/minimal-build.patch
deleted file mode 100644
index 90588929f..000000000
--- a/depends/patches/proton/minimal-build.patch
+++ /dev/null
@@ -1,288 +0,0 @@
-From 03f5fc0826115edbfca468261b70c0daf627f488 Mon Sep 17 00:00:00 2001
-From: Simon
-Date: Thu, 27 Apr 2017 17:15:59 -0700
-Subject: [PATCH] Enable C++11, build static library and cpp bindings with minimal dependencies.
-
----
- CMakeLists.txt | 13 +++++++------
- examples/cpp/CMakeLists.txt | 1 +
- proton-c/CMakeLists.txt | 32 +++++++++++++++----------------
- proton-c/bindings/CMakeLists.txt | 6 +++---
- proton-c/bindings/cpp/CMakeLists.txt | 24 +++++++++++------------
- proton-c/bindings/cpp/docs/CMakeLists.txt | 2 +-
- proton-c/docs/api/CMakeLists.txt | 2 +-
- 7 files changed, 41 insertions(+), 39 deletions(-)
-
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index b538ffd..4a5e787 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -18,14 +18,15 @@
- #
- cmake_minimum_required (VERSION 2.8.7)
-
-+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
- project (Proton C)
-
- # Enable C++ now for examples and bindings subdirectories, but make it optional.
- enable_language(CXX OPTIONAL)
-
- # Enable testing
--enable_testing()
--include (CTest)
-+#enable_testing()
-+#include (CTest)
-
- # Pull in local cmake modules
- set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tools/cmake/Modules/")
-@@ -141,7 +142,7 @@ set (BINDINGS_DIR ${LIB_INSTALL_DIR}/proton/bindings)
-
- set (SYSINSTALL_BINDINGS OFF CACHE BOOL "If SYSINSTALL_BINDINGS is OFF then proton bindings will be installed underneath ${BINDINGS_DIR} and each user will need to modify their interpreter configuration to load the appropriate binding. If SYSINSTALL_BINDINGS is ON, then each language interpreter will be queried for the appropriate directory and proton bindings will be installed and available system wide with no additional per user configuration.")
-
--set (BINDING_LANGS PERL PHP PYTHON RUBY)
-+#set (BINDING_LANGS PERL PHP PYTHON RUBY)
-
- foreach (LANG ${BINDING_LANGS})
- set (SYSINSTALL_${LANG} OFF CACHE BOOL "Install ${LANG} bindings into interpreter specified location.")
-@@ -156,10 +157,10 @@ set (PROTON_SHARE ${SHARE_INSTALL_DIR}/proton-${PN_VERSION})
- # End of variables used during install
-
- # Check for valgrind here so tests under proton-c/ and examples/ can use it.
--find_program(VALGRIND_EXE valgrind DOC "Location of the valgrind program")
-+#find_program(VALGRIND_EXE valgrind DOC "Location of the valgrind program")
- mark_as_advanced (VALGRIND_EXE)
-
--option(ENABLE_VALGRIND "Use valgrind to detect run-time problems" ON)
-+#option(ENABLE_VALGRIND "Use valgrind to detect run-time problems" ON)
- if (ENABLE_VALGRIND)
- if (NOT VALGRIND_EXE)
- message(STATUS "Can't locate the valgrind command; no run-time error detection")
-@@ -171,7 +172,7 @@ if (ENABLE_VALGRIND)
- endif (ENABLE_VALGRIND)
-
- add_subdirectory(proton-c)
--add_subdirectory(examples)
-+#add_subdirectory(examples)
-
- install (FILES LICENSE README.md
- DESTINATION ${PROTON_SHARE})
-diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt
-index 304d899..f4877b4 100644
---- a/examples/cpp/CMakeLists.txt
-+++ b/examples/cpp/CMakeLists.txt
-@@ -17,6 +17,7 @@
- # under the License.
- #
-
-+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
- find_package(ProtonCpp REQUIRED)
-
- include_directories(${ProtonCpp_INCLUDE_DIRS})
-diff --git a/proton-c/CMakeLists.txt b/proton-c/CMakeLists.txt
-index 8edb661..dc7b99c 100644
---- a/proton-c/CMakeLists.txt
-+++ b/proton-c/CMakeLists.txt
-@@ -22,24 +22,24 @@ include(CheckSymbolExists)
-
- include(soversion.cmake)
-
--add_custom_target(docs)
--add_custom_target(doc DEPENDS docs)
-+#add_custom_target(docs)
-+#add_custom_target(doc DEPENDS docs)
-
- # Set the default SSL/TLS implementation
--find_package(OpenSSL)
-+#find_package(OpenSSL)
- find_package(PythonInterp REQUIRED)
--find_package(SWIG)
-+#find_package(SWIG)
- # FindSwig.cmake "forgets" make its outputs advanced like a good citizen
- mark_as_advanced(SWIG_DIR SWIG_EXECUTABLE SWIG_VERSION)
-
- # See if Cyrus SASL is available
--find_library(CYRUS_SASL_LIBRARY sasl2)
--find_path(CYRUS_SASL_INCLUDE_DIR sasl/sasl.h PATH_SUFFIXES include)
--find_package_handle_standard_args(CyrusSASL DEFAULT_MSG CYRUS_SASL_LIBRARY CYRUS_SASL_INCLUDE_DIR)
-+#find_library(CYRUS_SASL_LIBRARY sasl2)
-+#find_path(CYRUS_SASL_INCLUDE_DIR sasl/sasl.h PATH_SUFFIXES include)
-+#find_package_handle_standard_args(CyrusSASL DEFAULT_MSG CYRUS_SASL_LIBRARY CYRUS_SASL_INCLUDE_DIR)
- mark_as_advanced(CYRUS_SASL_LIBRARY CYRUS_SASL_INCLUDE_DIR)
-
- # Find saslpasswd2 executable to generate test config
--find_program(SASLPASSWD_EXE saslpasswd2 DOC "Program used to make SASL user db for testing")
-+#find_program(SASLPASSWD_EXE saslpasswd2 DOC "Program used to make SASL user db for testing")
- mark_as_advanced(SASLPASSWD_EXE)
-
- if(WIN32 AND NOT CYGWIN)
-@@ -315,8 +315,8 @@ pn_absolute_install_dir(EXEC_PREFIX "." ${CMAKE_INSTALL_PREFIX})
- pn_absolute_install_dir(LIBDIR ${LIB_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX})
- pn_absolute_install_dir(INCLUDEDIR ${INCLUDE_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX})
-
--add_subdirectory(docs/api)
--add_subdirectory(../tests/tools/apps/c ../tests/tools/apps/c)
-+#add_subdirectory(docs/api)
-+#add_subdirectory(../tests/tools/apps/c ../tests/tools/apps/c)
-
- # for full source distribution:
- set (qpid-proton-platform-all
-@@ -507,7 +507,7 @@ if (BUILD_WITH_CXX)
- endif (BUILD_WITH_CXX)
-
- add_library (
-- qpid-proton-core SHARED
-+ qpid-proton-core STATIC
- ${qpid-proton-core}
- ${qpid-proton-layers}
- ${qpid-proton-platform}
-@@ -527,7 +527,7 @@ set_target_properties (
- )
-
- add_library(
-- qpid-proton SHARED
-+ qpid-proton STATIC
- # Proton Core
- ${qpid-proton-core}
- ${qpid-proton-layers}
-@@ -629,7 +629,7 @@ install (FILES
-
- # c tests:
-
--add_subdirectory(src/tests)
-+#add_subdirectory(src/tests)
-
- if (CMAKE_SYSTEM_NAME STREQUAL Windows)
- # No change needed for windows already use correct separator
-@@ -712,7 +712,7 @@ if (BUILD_PYTHON)
-
- endif (BUILD_PYTHON)
-
--find_program(RUBY_EXE "ruby")
-+#find_program(RUBY_EXE "ruby")
- if (RUBY_EXE AND BUILD_RUBY)
- set (rb_root "${pn_test_root}/ruby")
- set (rb_src "${CMAKE_CURRENT_SOURCE_DIR}/bindings/ruby")
-@@ -751,8 +751,8 @@ if (RUBY_EXE AND BUILD_RUBY)
- else (DEFAULT_RUBY_TESTING)
- message(STATUS "Skipping Ruby tests: missing dependencies")
- endif (DEFAULT_RUBY_TESTING)
--else (RUBY_EXE)
-- message (STATUS "Cannot find ruby, skipping ruby tests")
-+#else (RUBY_EXE)
-+# message (STATUS "Cannot find ruby, skipping ruby tests")
- endif()
-
- mark_as_advanced (RUBY_EXE RSPEC_EXE)
-diff --git a/proton-c/bindings/CMakeLists.txt b/proton-c/bindings/CMakeLists.txt
-index 6b88384..d1a50a5 100644
---- a/proton-c/bindings/CMakeLists.txt
-+++ b/proton-c/bindings/CMakeLists.txt
-@@ -19,14 +19,14 @@
-
- # Add bindings that do not require swig here - the directory name must be the same as the binding name
- # See below for swig bindings
--set(BINDINGS javascript cpp go)
-+set(BINDINGS cpp)
-
- # Prerequisites for javascript.
- #
- # It uses a C/C++ to JavaScript cross-compiler called emscripten (https://github.com/kripken/emscripten). Emscripten takes C/C++
- # and compiles it into a highly optimisable subset of JavaScript called asm.js (http://asmjs.org/) that can be
- # aggressively optimised and run at near-native speed (usually between 1.5 to 10 times slower than native C/C++).
--find_package(Emscripten)
-+#find_package(Emscripten)
- if (EMSCRIPTEN_FOUND)
- set (DEFAULT_JAVASCRIPT ON)
- endif (EMSCRIPTEN_FOUND)
-@@ -37,7 +37,7 @@ if (CMAKE_CXX_COMPILER)
- endif (CMAKE_CXX_COMPILER)
-
- # Prerequisites for Go
--find_program(GO_EXE go)
-+#find_program(GO_EXE go)
- mark_as_advanced(GO_EXE)
- if (GO_EXE)
- if(WIN32)
-diff --git a/proton-c/bindings/cpp/CMakeLists.txt b/proton-c/bindings/cpp/CMakeLists.txt
-index 0cc4024..796fe29 100644
---- a/proton-c/bindings/cpp/CMakeLists.txt
-+++ b/proton-c/bindings/cpp/CMakeLists.txt
-@@ -16,7 +16,7 @@
- # specific language governing permissions and limitations
- # under the License.
- #
--
-+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
- include(cpp.cmake) # Compiler checks
-
- include_directories(
-@@ -89,7 +89,7 @@ set_source_files_properties (
- COMPILE_FLAGS "${LTO}"
- )
-
--add_library(qpid-proton-cpp SHARED ${qpid-proton-cpp-source})
-+add_library(qpid-proton-cpp STATIC ${qpid-proton-cpp-source})
-
- target_link_libraries (qpid-proton-cpp ${PLATFORM_LIBS} qpid-proton)
-
-@@ -120,8 +120,8 @@ endif (MSVC)
-
- install (DIRECTORY "include/proton" DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.hpp")
-
--add_subdirectory(docs)
--add_subdirectory(${CMAKE_SOURCE_DIR}/tests/tools/apps/cpp ${CMAKE_BINARY_DIR}/tests/tools/apps/cpp)
-+#add_subdirectory(docs)
-+#add_subdirectory(${CMAKE_SOURCE_DIR}/tests/tools/apps/cpp ${CMAKE_BINARY_DIR}/tests/tools/apps/cpp)
-
- # Pkg config file
- configure_file(
-@@ -171,12 +171,12 @@ macro(add_cpp_test test)
- endif ()
- endmacro(add_cpp_test)
-
--add_cpp_test(codec_test)
-+#add_cpp_test(codec_test)
- #add_cpp_test(engine_test)
--add_cpp_test(thread_safe_test)
--add_cpp_test(interop_test ${CMAKE_SOURCE_DIR}/tests)
--add_cpp_test(message_test)
--add_cpp_test(scalar_test)
--add_cpp_test(value_test)
--add_cpp_test(container_test)
--add_cpp_test(url_test)
-+#add_cpp_test(thread_safe_test)
-+#add_cpp_test(interop_test ${CMAKE_SOURCE_DIR}/tests)
-+#add_cpp_test(message_test)
-+#add_cpp_test(scalar_test)
-+#add_cpp_test(value_test)
-+#add_cpp_test(container_test)
-+#add_cpp_test(url_test)
-diff --git a/proton-c/bindings/cpp/docs/CMakeLists.txt b/proton-c/bindings/cpp/docs/CMakeLists.txt
-index d512d15..8576867 100644
---- a/proton-c/bindings/cpp/docs/CMakeLists.txt
-+++ b/proton-c/bindings/cpp/docs/CMakeLists.txt
-@@ -17,7 +17,7 @@
- # under the License.
- #
-
--find_package(Doxygen)
-+#find_package(Doxygen)
-
- if (DOXYGEN_FOUND)
- configure_file (
-diff --git a/proton-c/docs/api/CMakeLists.txt b/proton-c/docs/api/CMakeLists.txt
-index 7756e48..71ebb93 100644
---- a/proton-c/docs/api/CMakeLists.txt
-+++ b/proton-c/docs/api/CMakeLists.txt
-@@ -17,7 +17,7 @@
- # under the License.
- #
-
--find_package(Doxygen)
-+#find_package(Doxygen)
- if (DOXYGEN_FOUND)
- configure_file (${CMAKE_CURRENT_SOURCE_DIR}/user.doxygen.in
- ${CMAKE_CURRENT_BINARY_DIR}/user.doxygen)
---
-2.7.4
-
diff --git a/doc/amqp.md b/doc/amqp.md
deleted file mode 100644
index 431fa55b1..000000000
--- a/doc/amqp.md
+++ /dev/null
@@ -1,123 +0,0 @@
-# Block and Transaction Broadcasting With AMQP 1.0 (Experimental Feature)
-
-[AMQP](https://www.amqp.org/) is an enterprise-level message queuing
-protocol for the reliable passing of real-time data and business
-transactions between applications. AMQP supports both broker and
-brokerless messaging. AMQP 1.0 is an open standard and has been
-ratified as ISO/IEC 19464.
-
-The Hush daemon can be configured to act as a trusted "border
-router", implementing the Hush P2P protocol and relay, making
-consensus decisions, maintaining the local blockchain database,
-broadcasting locally generated transactions into the network, and
-providing a queryable RPC interface to interact on a polled basis for
-requesting blockchain related data. However, there exists only a
-limited service to notify external software of events like the arrival
-of new blocks or transactions.
-
-The AMQP facility implements a notification interface through a set
-of specific notifiers. Currently there are notifiers that publish
-blocks and transactions. This read-only facility requires only the
-connection of a corresponding AMQP subscriber port in receiving
-software.
-
-Currently the facility is not authenticated nor is there any two-way
-protocol involvement. Therefore, subscribers should validate the
-received data since it may be out of date, incomplete or even invalid.
-
-Because AMQP is message oriented, subscribers receive transactions
-and blocks all-at-once and do not need to implement any sort of
-buffering or reassembly.
-
-## Prerequisites
-
-The AMQP feature in Hush requires [Qpid Proton](https://qpid.apache.org/proton/)
-version 0.17 or newer, which you will need to install if you are not
-using the depends system. Typically, it is packaged by distributions as
-something like *libqpid-proton*. The C++ wrapper for AMQP *is* required.
-
-In order to run the example Python client scripts in contrib/ one must
-also install *python-qpid-proton*, though this is not necessary for
-daemon operation.
-
-## Enabling
-
-By default, the AMQP feature is automatically compiled in if the
-necessary prerequisites are found. To disable, use --disable-proton
-during the *configure* step of building zcashd:
-
- $ ./configure --disable-proton (other options)
-
-To actually enable operation, one must set the appropriate options on
-the commandline or in the configuration file.
-
-## Usage
-
-AMQP support is currently an experimental feature, so you must pass
-the option:
-
- -experimentalfeatures
-
-Currently, the following notifications are supported:
-
- -amqppubhashtx=address
- -amqppubhashblock=address
- -amqppubrawblock=address
- -amqppubrawtx=address
-
-The address must be a valid AMQP address, where the same address can be
-used in more than notification. Note that SSL and SASL addresses are
-not currently supported.
-
-Launch zcashd like this:
-
- $ zcashd -amqppubhashtx=amqp://127.0.0.1:5672
-
-Or this:
-
- $ zcashd -amqppubhashtx=amqp://127.0.0.1:5672 \
- -amqppubrawtx=amqp://127.0.0.1:5672 \
- -amqppubrawblock=amqp://127.0.0.1:5672 \
- -amqppubhashblock=amqp://127.0.0.1:5672 \
- -debug=amqp
-
-The debug category `amqp` enables AMQP-related logging.
-
-Each notification has a topic and body, where the header corresponds
-to the notification type. For instance, for the notification `-amqpubhashtx`
-the topic is `hashtx` (no null terminator) and the body is the hexadecimal
-transaction hash (32 bytes). This transaction hash and the block hash
-found in `hashblock` are in RPC byte order.
-
-These options can also be provided in zcash.conf.
-
-Please see `contrib/amqp/amqp_sub.py` for a working example of an
-AMQP server listening for messages.
-
-## Remarks
-
-From the perspective of zcashd, the local end of an AMQP link is write-only.
-
-No information is broadcast that wasn't already received from the public
-P2P network.
-
-No authentication or authorization is done on peers that zcashd connects
-to; it is assumed that the AMQP link is exposed only to trusted entities,
-using other means such as firewalling.
-
-TLS support may be added once OpenSSL has been removed from the Hush
-project and alternative TLS implementations have been evaluated.
-
-SASL support may be added in a future update for secure communication.
-
-Note that when the block chain tip changes, a reorganisation may occur
-and just the tip will be notified. It is up to the subscriber to
-retrieve the chain from the last known block to the new tip.
-
-At present, zcashd does not try to resend a notification if there was
-a problem confirming receipt. Support for delivery guarantees such as
-*at-least-once* and *exactly-once* will be added in in a future update.
-
-Currently, zcashd appends an up-counting sequence number to each notification
-which allows listeners to detect lost notifications.
-
diff --git a/doc/man/hush-cli.1 b/doc/man/hush-cli.1
index 0c9080b59..87714f8ee 100644
--- a/doc/man/hush-cli.1
+++ b/doc/man/hush-cli.1
@@ -1,21 +1,21 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.10.
-.TH HUSH-CLI "1" "March 2020" "hush-cli v3.3.2" "User Commands"
+.TH HUSH-CLI "1" "October 2020" "hush-cli v3.5.1" "User Commands"
.SH NAME
-hush-cli \- manual page for hush-cli v3.3.2
+hush-cli \- manual page for hush-cli v3.5.1
.SH DESCRIPTION
-Komodo RPC client version v3.3.2\-699b59037
+Hush RPC client version v3.5.1\-dd8ab3df6
.PP
In order to ensure you are adequately protecting your privacy when using Hush,
please see .
.SS "Usage:"
.TP
-komodo\-cli [options] [params]
-Send command to Komodo
+hush\-cli [options] [params]
+Send command to Hush
.TP
-komodo\-cli [options] help
+hush\-cli [options] help
List commands
.TP
-komodo\-cli [options] help
+hush\-cli [options] help
Get help for a command
.SH OPTIONS
.HP
@@ -71,7 +71,7 @@ Timeout in seconds during HTTP requests, or 0 for no timeout. (default:
Read extra arguments from standard input, one per line until EOF/Ctrl\-D
(recommended for sensitive information such as passphrases)
.SH COPYRIGHT
-Hush Daemon version v3.3.2-699b59037
+Hush Daemon version v3.5.1-dd8ab3df6
In order to ensure you are adequately protecting your privacy when using Hush,
please see .
@@ -84,7 +84,7 @@ Copyright (C) 2018-2020 The Hush developers
This is experimental software!!!
Distributed under the MIT software license, see the accompanying file COPYING
-or .
+or .
This product includes software developed by the OpenSSL Project for use in the
OpenSSL Toolkit and cryptographic software written
diff --git a/doc/man/hush-tx.1 b/doc/man/hush-tx.1
index 9004dcade..31353841f 100644
--- a/doc/man/hush-tx.1
+++ b/doc/man/hush-tx.1
@@ -1,9 +1,9 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.10.
-.TH HUSH-TX "1" "March 2020" "hush-tx v3.3.2" "User Commands"
+.TH HUSH-TX "1" "October 2020" "hush-tx v3.5.1" "User Commands"
.SH NAME
-hush-tx \- manual page for hush-tx v3.3.2
+hush-tx \- manual page for hush-tx v3.5.1
.SH DESCRIPTION
-Hush komodo\-tx utility version v3.3.2\-699b59037
+Hush komodo\-tx utility version v3.5.1\-dd8ab3df6
.SS "Usage:"
.TP
komodo\-tx [options] [commands]
@@ -84,7 +84,7 @@ set=NAME:JSON\-STRING
.IP
Set register NAME to given JSON\-STRING
.SH COPYRIGHT
-Hush Daemon version v3.3.2-699b59037
+Hush Daemon version v3.5.1-dd8ab3df6
In order to ensure you are adequately protecting your privacy when using Hush,
please see .
@@ -97,7 +97,7 @@ Copyright (C) 2018-2020 The Hush developers
This is experimental software!!!
Distributed under the MIT software license, see the accompanying file COPYING
-or .
+or .
This product includes software developed by the OpenSSL Project for use in the
OpenSSL Toolkit and cryptographic software written
diff --git a/doc/man/hushd.1 b/doc/man/hushd.1
index 0cde080df..66ba54c0b 100644
--- a/doc/man/hushd.1
+++ b/doc/man/hushd.1
@@ -1,10 +1,10 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.10.
-.TH HUSHD "1" "March 2020" "hushd v3.3.2" "User Commands"
+.TH HUSHD "1" "October 2020" "hushd v3.5.1" "User Commands"
.SH NAME
-hushd \- manual page for hushd v3.3.2
+hushd \- manual page for hushd v3.5.1
.SH DESCRIPTION
Found binary: ./komodod
-Hush Daemon version v3.3.2\-699b59037
+Hush Daemon version v3.5.1\-dd8ab3df6
.PP
In order to ensure you are adequately protecting your privacy when using Hush,
please see .
@@ -87,6 +87,11 @@ leave that many cores free, default: 0)
.IP
Specify pid file (default: komodod.pid)
.HP
+\fB\-txexpirynotify=\fR
+.IP
+Execute command when transaction expires (%s in cmd is replaced by
+transaction id)
+.HP
\fB\-prune=\fR
.IP
Reduce storage requirements by pruning (deleting) old blocks. This mode
@@ -109,6 +114,11 @@ Create new files with system default permissions, instead of umask 077
Maintain a full transaction index, used by the getrawtransaction rpc
call (default: 0)
.HP
+\fB\-txsend=\fR
+.IP
+Execute command to send a transaction instead of broadcasting (%s in cmd
+is replaced by transaction hex)
+.HP
\fB\-addressindex\fR
.IP
Maintain a full address index, used to query for the balance, txids and
@@ -135,6 +145,12 @@ Connection options:
.IP
Add a node to connect to and attempt to keep the connection open
.HP
+\fB\-asmap=\fR
+.IP
+Specify asn mapping used for bucketing of the peers (default:
+ip_asn.map). Relative paths will be prefixed by the net\-specific datadir
+location.
+.HP
\fB\-banscore=\fR
.IP
Threshold for disconnecting misbehaving peers (default: 100)
@@ -243,6 +259,28 @@ Tor control port to use if onion listening enabled (default:
.IP
Tor control port password (default: empty)
.HP
+\fB\-tls=\fR
+.IP
+Specify TLS usage (default: 1 => enabled and preferred, yet compatible);
+other options are \fB\-tls\fR=\fI\,0\/\fR to disable TLS and \fB\-tls\fR=\fI\,only\/\fR to enforce it
+.HP
+\fB\-tlskeypath=\fR
+.IP
+Full path to a private key
+.HP
+\fB\-tlskeypwd=\fR
+.IP
+Password for a private key encryption (default: not set, i.e. private
+key will be stored unencrypted)
+.HP
+\fB\-tlscertpath=\fR
+.IP
+Full path to a certificate
+.HP
+\fB\-tlstrustdir=\fR
+.IP
+Full path to a trusted certificates directory
+.HP
\fB\-whitebind=\fR
.IP
Bind to given address and whitelist peers connecting to it. Use
@@ -295,6 +333,11 @@ Keep the last transactions (default: 200)
.IP
Keep transactions for at least blocks (default: 10000)
.HP
+\fB\-opretmintxfee=\fR
+.IP
+Minimum fee (in KMD/kB) to allow for OP_RETURN transactions (default:
+400000)
+.HP
\fB\-paytxfee=\fR
.IP
Fee (in KMD/kB) to add to transactions you send (default: 0.00)
@@ -336,7 +379,8 @@ Upgrade wallet to latest format on startup
.HP
\fB\-wallet=\fR
.IP
-Specify wallet file (within data directory) (default: wallet.dat)
+Specify wallet file absolute path or a path relative to the data
+directory (default: wallet.dat)
.HP
\fB\-walletbroadcast\fR
.IP
@@ -531,7 +575,7 @@ output (default: 1 if running in a console, 0 otherwise)
Number of seconds between metrics refreshes (default: 1 if running in a
console, 600 otherwise)
.PP
-Komodo Asset Chain options:
+Hush Smart Chain options:
.HP
\fB\-ac_algo\fR
.IP
@@ -629,7 +673,7 @@ Starting supply, default is 0
.IP
Enforce transaction\-rate limit, default 0
.SH COPYRIGHT
-Hush Daemon version v3.3.2-699b59037
+Hush Daemon version v3.5.1-dd8ab3df6
In order to ensure you are adequately protecting your privacy when using Hush,
please see .
@@ -642,7 +686,7 @@ Copyright (C) 2018-2020 The Hush developers
This is experimental software!!!
Distributed under the MIT software license, see the accompanying file COPYING
-or .
+or .
This product includes software developed by the OpenSSL Project for use in the
OpenSSL Toolkit and cryptographic software written
diff --git a/doc/payment-disclosure.md b/doc/payment-disclosure.md
deleted file mode 100644
index 02b4167da..000000000
--- a/doc/payment-disclosure.md
+++ /dev/null
@@ -1,107 +0,0 @@
-# Payment Disclosure (Experimental Feature)
-
-**Summary**
-
-Use RPC calls `z_getpaymentdisclosure` and `z_validatepaymentdisclosure` to reveal details of a shielded payment.
-
-**Who should read this document**
-
-Frequent users of shielded transactions, payment processors, exchanges, block explorer
-
-### Experimental Feature
-
-This is an experimental feature. Enable it by launching `zcashd` with flags:
-
- zcashd -experimentalfeatures -paymentdisclosure -debug=paymentdisclosure -txindex=1
-
-These flags can also be set as options in `zcash.conf`.
-
-All nodes that generate or validate payment disclosures must run with `txindex=1` enabled.
-
-### Background
-
-Payment Disclosure is an implementation of the work-in-progress Payment Disclosure ZIP [1].
-
-The ZIP describes a method of proving that a payment was sent to a shielded address. In the typical case, this means enabling a sender to present a proof that they transferred funds to a recipient's shielded address.
-
-[1] https://github.com/zcash/zips/pull/119
-
-### Example Use Case
-
-Alice the customer sends 10 HUSH to Bob the merchant at the shielded address shown on their website. However, Bob is not sure if he received the funds.
-
-Alice's node is running with payment disclosure enabled, so Alice generates a payment disclosure and provides it to Bob, who verifies the payment was made.
-
-If Bob is a bad merchant, Alice can present the payment disclosure to a third party to validate that payment was indeed made.
-
-### Solution
-
-A payment disclosure can be generated for any output of a JoinSplit using the RPC call:
-
- z_getpaymentdisclosure txid js_index output_index (message)
-
-An optional message can be supplied. This could be used for a refund address or some other reference, as currently it is not common practice to (ahead of time) include a refund address in the memo field when making a payment.
-
-To validate a payment disclosure, the following RPC call can be used:
-
- z_validatepaymentdisclosure hexdata
-
-### Example
-
-Generate a payment disclosure for the first joinsplit, second output (index starts from zero):
-
- hush-cli z_getpaymentdisclosure 79189528d611e811a1c7bb0358dd31343033d14b4c1e998d7c4799c40f8b652b 0 1 "Hello"
-
-This returns a payment disclosure in the form of a hex string:
-
- 706462ff000a3722aafa8190cdf9710bfad6da2af6d3a74262c1fc96ad47df814b0cd5641c2b658b0fc499477c8d991e4c4bd133303431dd5803bbc7a111e811d6289518790000000000000000017e861adb829d8cb1cbcf6330b8c2e25fb0d08041a67a857815a136f0227f8a5342bce5b3c0d894e2983000eb594702d3c1580817d0374e15078528e56bb6f80c0548656c6c6f59a7085395c9e706d82afe3157c54ad4ae5bf144fcc774a8d9c921c58471402019c156ec5641e2173c4fb6467df5f28530dc4636fa71f4d0e48fc5c560fac500
-
-To validate the payment disclosure:
-
- hush-cli z_validatepaymentdisclosure HEXDATA
-
-This returns data related to the payment and the payment disclosure:
-
- {
- "txid": "79189528d611e811a1c7bb0358dd31343033d14b4c1e998d7c4799c40f8b652b",
- "jsIndex": 0,
- "outputIndex": 1,
- "version": 0,
- "onetimePrivKey": "1c64d50c4b81df47ad96fcc16242a7d3f62adad6fa0b71f9cd9081faaa22370a",
- "message": "Hello",
- "joinSplitPubKey": "d1c465d16166b602992479acfac18e87dc18065f6cefde6a002e70bc371b9faf",
- "signatureVerified": true,
- "paymentAddress": "ztaZJXy8iX8nrk2ytXKDBoTWqPkhQcj6E2ifARnD3wfkFwsxXs5SoX7NGmrjkzSiSKn8VtLHTJae48vX5NakvmDhtGNY5eb",
- "memo": "f600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "value": 12.49900000,
- "commitmentMatch": true,
- "valid": true
- }
-
-The `signatureVerified` field confirms that the payment disclosure was generated and signed with the joinSplitPrivKey, which should only be known by the node generating and sending the transaction 7918...652b in question.
-
-### Where is the data stored?
-
-For all nodes, payment disclosure does not touch `wallet.dat` in any way.
-
-For nodes that only validate payment disclosures, no data is stored locally.
-
-For nodes that generate payment disclosures, a LevelDB database is created in the node's datadir. For most users, this would be in the folder:
-
- $HOME/.zcash/paymentdisclosure
-
-If you decide you don't want to use payment disclosure, it is safe to shut down your node and delete the database folder.
-
-### Security Properties
-
-Please consult the work-in-progress ZIP for details about the protocol, security properties and caveats.
-
-### Reminder
-
-Feedback is most welcome!
-
-This is an experimental feature so there are no guarantees that the protocol, database format, RPC interface etc. will remain the same in the future.
-
-### Notes
-
-Currently there is no user friendly way to help senders identify which joinsplit output index maps to a given payment they made. It is possible to construct this from `debug.log`. Ideas and feedback are most welcome on how to improve the user experience.
diff --git a/qa/hush/create_wallet_200k_utxos.py b/qa/hush/create_wallet_200k_utxos.py
index d4a1d9d48..ee0139950 100644
--- a/qa/hush/create_wallet_200k_utxos.py
+++ b/qa/hush/create_wallet_200k_utxos.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2017 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Create a large wallet
diff --git a/qa/hush/full_test_suite.py b/qa/hush/full_test_suite.py
index fcbdf0cd8..deee55881 100755
--- a/qa/hush/full_test_suite.py
+++ b/qa/hush/full_test_suite.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python2
+# Copyright (c) 2019-2020 Hush developers
+# Released under the GPLv3
#
-# Execute all of the automated tests related to Zcash.
+# Execute all of the automated tests related to Hush
#
import argparse
@@ -32,7 +34,7 @@ RE_FORTIFY_USED = re.compile('Binary compiled with FORTIFY_SOURCE support.*Yes')
def test_rpath_runpath(filename):
output = subprocess.check_output(
- [repofile('qa/zcash/checksec.sh'), '--file', repofile(filename)]
+ [repofile('qa/hush/checksec.sh'), '--file', repofile(filename)]
)
if RE_RPATH_RUNPATH.search(output):
print('PASS: %s has no RPATH or RUNPATH.' % filename)
@@ -44,7 +46,7 @@ def test_rpath_runpath(filename):
def test_fortify_source(filename):
proc = subprocess.Popen(
- [repofile('qa/zcash/checksec.sh'), '--fortify-file', repofile(filename)],
+ [repofile('qa/hush/checksec.sh'), '--fortify-file', repofile(filename)],
stdout=subprocess.PIPE,
)
line1 = proc.stdout.readline()
@@ -64,24 +66,24 @@ def check_security_hardening():
ret &= subprocess.call(['make', '-C', repofile('src'), 'check-security']) == 0
# The remaining checks are only for ELF binaries
- # Assume that if zcashd is an ELF binary, they all are
- with open(repofile('src/zcashd'), 'rb') as f:
+ # Assume that if hushd is an ELF binary, they all are
+ with open(repofile('src/hushd'), 'rb') as f:
magic = f.read(4)
if not magic.startswith(b'\x7fELF'):
return ret
- ret &= test_rpath_runpath('src/zcashd')
- ret &= test_rpath_runpath('src/zcash-cli')
- ret &= test_rpath_runpath('src/zcash-gtest')
- ret &= test_rpath_runpath('src/zcash-tx')
+ ret &= test_rpath_runpath('src/hushd')
+ ret &= test_rpath_runpath('src/hush-cli')
+ ret &= test_rpath_runpath('src/hush-gtest')
+ ret &= test_rpath_runpath('src/hush-tx')
ret &= test_rpath_runpath('src/test/test_bitcoin')
# NOTE: checksec.sh does not reliably determine whether FORTIFY_SOURCE
# is enabled for the entire binary. See issue #915.
- ret &= test_fortify_source('src/zcashd')
- ret &= test_fortify_source('src/zcash-cli')
- ret &= test_fortify_source('src/zcash-gtest')
- ret &= test_fortify_source('src/zcash-tx')
+ ret &= test_fortify_source('src/hushd')
+ ret &= test_fortify_source('src/hush-cli')
+ ret &= test_fortify_source('src/hush-gtest')
+ ret &= test_fortify_source('src/hush-tx')
ret &= test_fortify_source('src/test/test_bitcoin')
return ret
@@ -144,7 +146,7 @@ STAGES = [
STAGE_COMMANDS = {
'btest': [repofile('src/test/test_bitcoin'), '-p'],
- 'gtest': [repofile('src/zcash-gtest')],
+ 'gtest': [repofile('src/komodo-gtest')],
'sec-hard': check_security_hardening,
'no-dot-so': ensure_no_dot_so_in_depends,
'util-test': util_test,
diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh
index a23f2908d..4af883ea3 100755
--- a/qa/pull-tester/rpc-tests.sh
+++ b/qa/pull-tester/rpc-tests.sh
@@ -17,14 +17,12 @@ testScripts=(
'dpow.py'
'dpowconfs.py'
'ac_private.py'
- 'paymentdisclosure.py'
'prioritisetransaction.py'
'wallet_treestate.py'
'wallet_anchorfork.py'
'wallet_changeindicator.py'
'wallet_import_export.py'
'wallet_protectcoinbase.py'
- 'wallet_shieldcoinbase_sprout.py'
'wallet_shieldcoinbase_sapling.py'
'wallet_listreceived.py'
'wallet_mergetoaddress.py'
@@ -65,14 +63,11 @@ testScripts=(
'decodescript.py'
'blockchain.py'
'disablewallet.py'
- 'zcjoinsplit.py'
- 'zcjoinsplitdoublespend.py'
'ivk_import_export.py'
'zkey_import_export.py'
'getblocktemplate.py'
'bip65-cltv-p2p.py'
'bipdersig-p2p.py'
- 'p2p_nu_peer_management.py'
'rewind_index.py'
'p2p_txexpiry_dos.py'
'p2p_node_bloom.py'
@@ -101,10 +96,6 @@ if [ "x$ENABLE_ZMQ" = "x1" ]; then
testScripts+=('zmq_test.py')
fi
-if [ "x$ENABLE_PROTON" = "x1" ]; then
- testScripts+=('proton_test.py')
-fi
-
extArg="-extended"
passOn=${@#$extArg}
diff --git a/qa/rpc-tests/ac_private.py b/qa/rpc-tests/ac_private.py
index 9b462f50d..9d4e376f5 100755
--- a/qa/rpc-tests/ac_private.py
+++ b/qa/rpc-tests/ac_private.py
@@ -3,8 +3,8 @@
# Copyright (c) 2018 SuperNET developers
# Released under the GPLv3
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
diff --git a/qa/rpc-tests/addressindex.py b/qa/rpc-tests/addressindex.py
index 11fa7ffdb..c0fbc107f 100755
--- a/qa/rpc-tests/addressindex.py
+++ b/qa/rpc-tests/addressindex.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014-2015 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test addressindex generation and fetching
diff --git a/qa/rpc-tests/bip65-cltv-p2p.py b/qa/rpc-tests/bip65-cltv-p2p.py
index cfd2df01e..c0665777a 100755
--- a/qa/rpc-tests/bip65-cltv-p2p.py
+++ b/qa/rpc-tests/bip65-cltv-p2p.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
#
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3/X11 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
from test_framework.test_framework import ComparisonTestFramework
diff --git a/qa/rpc-tests/bipdersig-p2p.py b/qa/rpc-tests/bipdersig-p2p.py
index f254843f1..595e23180 100755
--- a/qa/rpc-tests/bipdersig-p2p.py
+++ b/qa/rpc-tests/bipdersig-p2p.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
#
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3/X11 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
from test_framework.test_framework import ComparisonTestFramework
diff --git a/qa/rpc-tests/blockchain.py b/qa/rpc-tests/blockchain.py
index c37db8b84..affd50a37 100755
--- a/qa/rpc-tests/blockchain.py
+++ b/qa/rpc-tests/blockchain.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test RPC calls related to blockchain state. Tests correspond to code in
diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py
index d5456e801..cfed77a4b 100755
--- a/qa/rpc-tests/cryptoconditions.py
+++ b/qa/rpc-tests/cryptoconditions.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 SuperNET developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
diff --git a/qa/rpc-tests/cryptoconditions_channels.py b/qa/rpc-tests/cryptoconditions_channels.py
index 7f82f2f3c..086eb2eb8 100755
--- a/qa/rpc-tests/cryptoconditions_channels.py
+++ b/qa/rpc-tests/cryptoconditions_channels.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 SuperNET developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
import time
diff --git a/qa/rpc-tests/cryptoconditions_dice.py b/qa/rpc-tests/cryptoconditions_dice.py
index 7b9d3fbae..3a4e87333 100755
--- a/qa/rpc-tests/cryptoconditions_dice.py
+++ b/qa/rpc-tests/cryptoconditions_dice.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 SuperNET developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import CryptoconditionsTestFramework
diff --git a/qa/rpc-tests/cryptoconditions_faucet.py b/qa/rpc-tests/cryptoconditions_faucet.py
index 27c5fce4e..99cf673a4 100755
--- a/qa/rpc-tests/cryptoconditions_faucet.py
+++ b/qa/rpc-tests/cryptoconditions_faucet.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 SuperNET developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import CryptoconditionsTestFramework
diff --git a/qa/rpc-tests/cryptoconditions_gateways.py b/qa/rpc-tests/cryptoconditions_gateways.py
index b12ea9f7e..52d5a2ab4 100755
--- a/qa/rpc-tests/cryptoconditions_gateways.py
+++ b/qa/rpc-tests/cryptoconditions_gateways.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 SuperNET developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import CryptoconditionsTestFramework
diff --git a/qa/rpc-tests/cryptoconditions_heir.py b/qa/rpc-tests/cryptoconditions_heir.py
index 12ca8b3da..9e07e283a 100755
--- a/qa/rpc-tests/cryptoconditions_heir.py
+++ b/qa/rpc-tests/cryptoconditions_heir.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 SuperNET developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
import time
diff --git a/qa/rpc-tests/cryptoconditions_oracles.py b/qa/rpc-tests/cryptoconditions_oracles.py
index 1db33bef7..e916d5002 100755
--- a/qa/rpc-tests/cryptoconditions_oracles.py
+++ b/qa/rpc-tests/cryptoconditions_oracles.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 SuperNET developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import CryptoconditionsTestFramework
from test_framework.authproxy import JSONRPCException
diff --git a/qa/rpc-tests/cryptoconditions_rewards.py b/qa/rpc-tests/cryptoconditions_rewards.py
index 57d3032b8..86ee97753 100755
--- a/qa/rpc-tests/cryptoconditions_rewards.py
+++ b/qa/rpc-tests/cryptoconditions_rewards.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 SuperNET developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import CryptoconditionsTestFramework
diff --git a/qa/rpc-tests/cryptoconditions_token.py b/qa/rpc-tests/cryptoconditions_token.py
index 263d85dde..e2da04f41 100755
--- a/qa/rpc-tests/cryptoconditions_token.py
+++ b/qa/rpc-tests/cryptoconditions_token.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 SuperNET developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import CryptoconditionsTestFramework
diff --git a/qa/rpc-tests/decodescript.py b/qa/rpc-tests/decodescript.py
index 293fd0ebb..0a46413f9 100755
--- a/qa/rpc-tests/decodescript.py
+++ b/qa/rpc-tests/decodescript.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2015 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
diff --git a/qa/rpc-tests/disablewallet.py b/qa/rpc-tests/disablewallet.py
index 339c6a8f6..db7260741 100755
--- a/qa/rpc-tests/disablewallet.py
+++ b/qa/rpc-tests/disablewallet.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Exercise API with -disablewallet.
diff --git a/qa/rpc-tests/dpowconfs.py b/qa/rpc-tests/dpowconfs.py
index 24b328da6..633d734be 100755
--- a/qa/rpc-tests/dpowconfs.py
+++ b/qa/rpc-tests/dpowconfs.py
@@ -1,8 +1,8 @@
#!/usr/bin/env python2
# Copyright (c) 2018-2019 The Hush developers
# Copyright (c) 2019 The SuperNET developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
diff --git a/qa/rpc-tests/feature_walletfile.py b/qa/rpc-tests/feature_walletfile.py
new file mode 100755
index 000000000..f5e4b44fd
--- /dev/null
+++ b/qa/rpc-tests/feature_walletfile.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+# Copyright (c) 2017 The Bitcoin Core developers
+# Copyright (c) 2019-2020 The Hush developers
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
+"""Test wallet file location."""
+
+import os
+
+from test_framework.util import start_node, stop_node, assert_start_raises_init_error
+
+from test_framework.test_framework import BitcoinTestFramework
+
+class WalletFileTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.num_nodes = 1
+ self.setup_clean_chain = True
+
+ def run_test(self):
+ # test default wallet location
+ assert os.path.isfile(os.path.join(self.options.tmpdir, "node0", "regtest", "wallet.dat"))
+
+ # test alternative wallet file name in datadir
+ stop_node(self.nodes[0], 0)
+ self.nodes[0] = start_node(0, self.options.tmpdir, ["-wallet=altwallet.dat"])
+ assert os.path.isfile(os.path.join(self.options.tmpdir, "node0", "regtest", "altwallet.dat"))
+
+ # test wallet file outside datadir
+ tempname = os.path.join(self.options.tmpdir, "outsidewallet.dat")
+ stop_node(self.nodes[0], 0)
+ self.nodes[0] = start_node(0, self.options.tmpdir, ["-wallet=%s" % tempname])
+ assert os.path.isfile(tempname)
+
+ # test the case where absolute path does not exist
+ assert not os.path.isdir("/this_directory_must_not_exist")
+ invalidpath = os.path.join("/this_directory_must_not_exist/", "foo.dat")
+ stop_node(self.nodes[0], 0)
+ assert_start_raises_init_error(0, "-wallet=%s" % invalidpath,
+ "Error: Absolute path %s does not exist")
+
+ # relative path does not exist
+ invalidpath = os.path.join("wallet", "foo.dat")
+ assert_start_raises_init_error(0, "-wallet=%s" % invalidpath,
+ "Error: Relative path %s does not exist")
+
+ # create dir and retry
+ os.mkdir(os.path.join(self.options.tmpdir, "node0", "regtest", "wallet"))
+ self.nodes[0] = start_node(0, self.options.tmpdir, ["-wallet=%s" % invalidpath])
+
+if __name__ == '__main__':
+ WalletFileTest().main()
diff --git a/qa/rpc-tests/finalsaplingroot.py b/qa/rpc-tests/finalsaplingroot.py
index 83f16edec..491bdbc4b 100755
--- a/qa/rpc-tests/finalsaplingroot.py
+++ b/qa/rpc-tests/finalsaplingroot.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
diff --git a/qa/rpc-tests/forknotify.py b/qa/rpc-tests/forknotify.py
index 1be750a64..c571d1243 100755
--- a/qa/rpc-tests/forknotify.py
+++ b/qa/rpc-tests/forknotify.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test -alertnotify
diff --git a/qa/rpc-tests/fundrawtransaction.py b/qa/rpc-tests/fundrawtransaction.py
index 42896be4f..dd19b267e 100755
--- a/qa/rpc-tests/fundrawtransaction.py
+++ b/qa/rpc-tests/fundrawtransaction.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
diff --git a/qa/rpc-tests/getblocktemplate.py b/qa/rpc-tests/getblocktemplate.py
index af050110e..77517d6b3 100755
--- a/qa/rpc-tests/getblocktemplate.py
+++ b/qa/rpc-tests/getblocktemplate.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2016 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, connect_nodes_bi, \
diff --git a/qa/rpc-tests/getblocktemplate_longpoll.py b/qa/rpc-tests/getblocktemplate_longpoll.py
index 37a40384b..a078f0c2d 100755
--- a/qa/rpc-tests/getblocktemplate_longpoll.py
+++ b/qa/rpc-tests/getblocktemplate_longpoll.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import AuthServiceProxy
diff --git a/qa/rpc-tests/getblocktemplate_proposals.py b/qa/rpc-tests/getblocktemplate_proposals.py
index 16b2e9b94..3687e3c23 100755
--- a/qa/rpc-tests/getblocktemplate_proposals.py
+++ b/qa/rpc-tests/getblocktemplate_proposals.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
diff --git a/qa/rpc-tests/getchaintips.py b/qa/rpc-tests/getchaintips.py
index 6a2bcb296..121be3fb5 100755
--- a/qa/rpc-tests/getchaintips.py
+++ b/qa/rpc-tests/getchaintips.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
# Exercise the getchaintips API. We introduce a network split, work
# on chains of different lengths, and join the network together again.
diff --git a/qa/rpc-tests/httpbasics.py b/qa/rpc-tests/httpbasics.py
index b1a4623bd..e739428df 100755
--- a/qa/rpc-tests/httpbasics.py
+++ b/qa/rpc-tests/httpbasics.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test rpc http basics
diff --git a/qa/rpc-tests/invalidateblock.py b/qa/rpc-tests/invalidateblock.py
index 5cbd1ea98..45623e2a7 100755
--- a/qa/rpc-tests/invalidateblock.py
+++ b/qa/rpc-tests/invalidateblock.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test InvalidateBlock code
diff --git a/qa/rpc-tests/invalidblockrequest.py b/qa/rpc-tests/invalidblockrequest.py
index 05b33d772..1bb85c905 100755
--- a/qa/rpc-tests/invalidblockrequest.py
+++ b/qa/rpc-tests/invalidblockrequest.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
#
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3/X11 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
from test_framework.test_framework import ComparisonTestFramework
diff --git a/qa/rpc-tests/ivk_import_export.py b/qa/rpc-tests/ivk_import_export.py
index 0546b0a44..30765744d 100755
--- a/qa/rpc-tests/ivk_import_export.py
+++ b/qa/rpc-tests/ivk_import_export.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2019 Bartlomiej Lisiecki
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from decimal import Decimal
from test_framework.test_framework import BitcoinTestFramework
diff --git a/qa/rpc-tests/key_import_export.py b/qa/rpc-tests/key_import_export.py
index 87b2daa2b..1e4afe9a7 100755
--- a/qa/rpc-tests/key_import_export.py
+++ b/qa/rpc-tests/key_import_export.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2017 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from decimal import Decimal
from test_framework.test_framework import BitcoinTestFramework
diff --git a/qa/rpc-tests/keypool.py b/qa/rpc-tests/keypool.py
index a7b32e13f..e3cdf203a 100755
--- a/qa/rpc-tests/keypool.py
+++ b/qa/rpc-tests/keypool.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
# Exercise the wallet keypool, and interaction with wallet encryption/locking
diff --git a/qa/rpc-tests/listtransactions.py b/qa/rpc-tests/listtransactions.py
index a735f41ab..808578f8c 100755
--- a/qa/rpc-tests/listtransactions.py
+++ b/qa/rpc-tests/listtransactions.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
# Exercise the listtransactions API
diff --git a/qa/rpc-tests/maxblocksinflight.py b/qa/rpc-tests/maxblocksinflight.py
index beef3d2ea..a083bcaa8 100755
--- a/qa/rpc-tests/maxblocksinflight.py
+++ b/qa/rpc-tests/maxblocksinflight.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
#
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3/X11 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
from test_framework.mininode import NodeConn, NodeConnCB, NetworkThread, \
diff --git a/qa/rpc-tests/mempool_nu_activation.py b/qa/rpc-tests/mempool_nu_activation.py
index 2ed238c65..d45b3e430 100755
--- a/qa/rpc-tests/mempool_nu_activation.py
+++ b/qa/rpc-tests/mempool_nu_activation.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
diff --git a/qa/rpc-tests/mempool_reorg.py b/qa/rpc-tests/mempool_reorg.py
index ad12dadf2..57e06f0bd 100755
--- a/qa/rpc-tests/mempool_reorg.py
+++ b/qa/rpc-tests/mempool_reorg.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test re-org scenarios with a mempool that contains transactions
diff --git a/qa/rpc-tests/mempool_resurrect_test.py b/qa/rpc-tests/mempool_resurrect_test.py
index faa97d461..b5a9f8704 100755
--- a/qa/rpc-tests/mempool_resurrect_test.py
+++ b/qa/rpc-tests/mempool_resurrect_test.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test resurrection of mined transactions when
diff --git a/qa/rpc-tests/mempool_spendcoinbase.py b/qa/rpc-tests/mempool_spendcoinbase.py
index 5366fb955..53c3625ca 100755
--- a/qa/rpc-tests/mempool_spendcoinbase.py
+++ b/qa/rpc-tests/mempool_spendcoinbase.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test spending coinbase transactions.
diff --git a/qa/rpc-tests/mempool_tx_expiry.py b/qa/rpc-tests/mempool_tx_expiry.py
index b5ee4bd2a..f96055386 100755
--- a/qa/rpc-tests/mempool_tx_expiry.py
+++ b/qa/rpc-tests/mempool_tx_expiry.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test proper expiry for transactions >= version 3
diff --git a/qa/rpc-tests/mempool_tx_input_limit.py b/qa/rpc-tests/mempool_tx_input_limit.py
index 9a7131cfe..7f6ed446a 100755
--- a/qa/rpc-tests/mempool_tx_input_limit.py
+++ b/qa/rpc-tests/mempool_tx_input_limit.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2017 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
diff --git a/qa/rpc-tests/merkle_blocks.py b/qa/rpc-tests/merkle_blocks.py
index 13b98e140..9a593afe5 100755
--- a/qa/rpc-tests/merkle_blocks.py
+++ b/qa/rpc-tests/merkle_blocks.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test merkleblock fetch/validation
diff --git a/qa/rpc-tests/nodehandling.py b/qa/rpc-tests/nodehandling.py
index 391a935d0..e26c9da83 100755
--- a/qa/rpc-tests/nodehandling.py
+++ b/qa/rpc-tests/nodehandling.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test node handling
diff --git a/qa/rpc-tests/p2p-acceptblock.py b/qa/rpc-tests/p2p-acceptblock.py
index 25221fbed..4fd47cf33 100755
--- a/qa/rpc-tests/p2p-acceptblock.py
+++ b/qa/rpc-tests/p2p-acceptblock.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
#
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3/X11 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
from test_framework.mininode import CBlockHeader, CInv, NodeConn, NodeConnCB, \
diff --git a/qa/rpc-tests/p2p_node_bloom.py b/qa/rpc-tests/p2p_node_bloom.py
index 18476a981..fac89cb6c 100755
--- a/qa/rpc-tests/p2p_node_bloom.py
+++ b/qa/rpc-tests/p2p_node_bloom.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.mininode import NodeConn, NodeConnCB, NetworkThread, \
msg_filteradd, msg_filterclear, mininode_lock, SPROUT_PROTO_VERSION
diff --git a/qa/rpc-tests/p2p_nu_peer_management.py b/qa/rpc-tests/p2p_nu_peer_management.py
deleted file mode 100755
index 6cedf66bb..000000000
--- a/qa/rpc-tests/p2p_nu_peer_management.py
+++ /dev/null
@@ -1,192 +0,0 @@
-#!/usr/bin/env python2
-# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-from test_framework.mininode import (
- NodeConn,
- NodeConnCB,
- NetworkThread,
- msg_ping,
- SPROUT_PROTO_VERSION,
- OVERWINTER_PROTO_VERSION,
- SAPLING_PROTO_VERSION,
-)
-from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import initialize_chain_clean, start_nodes, \
- p2p_port, assert_equal
-
-import time
-
-#
-# In this test we connect Sprout, Overwinter, and Sapling mininodes to a Zcashd
-# node which will activate Overwinter at block 10 and Sapling at block 15.
-#
-# We test:
-# 1. the mininodes stay connected to Zcash with Sprout consensus rules
-# 2. when Overwinter activates, the Sprout mininodes are dropped
-# 3. new Overwinter and Sapling nodes can connect to Zcash
-# 4. new Sprout nodes cannot connect to Zcash
-# 5. when Sapling activates, the Overwinter mininodes are dropped
-# 6. new Sapling nodes can connect to Zcash
-# 7. new Sprout and Overwinter nodes cannot connect to Zcash
-#
-# This test *does not* verify that prior to each activation, the Zcashd
-# node will prefer connections with NU-aware nodes, with an eviction process
-# that prioritizes non-NU-aware connections.
-#
-
-
-class TestManager(NodeConnCB):
- def __init__(self):
- NodeConnCB.__init__(self)
- self.create_callback_map()
-
- def on_close(self, conn):
- pass
-
- def on_reject(self, conn, message):
- conn.rejectMessage = message
-
-
-class NUPeerManagementTest(BitcoinTestFramework):
-
- def setup_chain(self):
- print "Initializing test directory "+self.options.tmpdir
- initialize_chain_clean(self.options.tmpdir, 1)
-
- def setup_network(self):
- self.nodes = start_nodes(1, self.options.tmpdir, extra_args=[[
- '-nuparams=5ba81b19:10', # Overwinter
- '-nuparams=76b809bb:15', # Sapling
- '-debug',
- '-whitelist=127.0.0.1',
- ]])
-
- def run_test(self):
- test = TestManager()
-
- # Launch Sprout, Overwinter, and Sapling mininodes
- nodes = []
- for x in xrange(10):
- nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0],
- test, "regtest", SPROUT_PROTO_VERSION))
- nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0],
- test, "regtest", OVERWINTER_PROTO_VERSION))
- nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0],
- test, "regtest", SAPLING_PROTO_VERSION))
-
- # Start up network handling in another thread
- NetworkThread().start()
-
- # Sprout consensus rules apply at block height 9
- self.nodes[0].generate(9)
- assert_equal(9, self.nodes[0].getblockcount())
-
- # Verify mininodes are still connected to zcashd node
- peerinfo = self.nodes[0].getpeerinfo()
- versions = [x["version"] for x in peerinfo]
- assert_equal(10, versions.count(SPROUT_PROTO_VERSION))
- assert_equal(10, versions.count(OVERWINTER_PROTO_VERSION))
- assert_equal(10, versions.count(SAPLING_PROTO_VERSION))
-
- # Overwinter consensus rules activate at block height 10
- self.nodes[0].generate(1)
- assert_equal(10, self.nodes[0].getblockcount())
- print('Overwinter active')
-
- # Mininodes send ping message to zcashd node.
- pingCounter = 1
- for node in nodes:
- node.send_message(msg_ping(pingCounter))
- pingCounter = pingCounter + 1
-
- time.sleep(3)
-
- # Verify Sprout mininodes have been dropped, while Overwinter and
- # Sapling mininodes are still connected.
- peerinfo = self.nodes[0].getpeerinfo()
- versions = [x["version"] for x in peerinfo]
- assert_equal(0, versions.count(SPROUT_PROTO_VERSION))
- assert_equal(10, versions.count(OVERWINTER_PROTO_VERSION))
- assert_equal(10, versions.count(SAPLING_PROTO_VERSION))
-
- # Extend the Overwinter chain with another block.
- self.nodes[0].generate(1)
-
- # Connect a new Overwinter mininode to the zcashd node, which is accepted.
- nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", OVERWINTER_PROTO_VERSION))
- time.sleep(3)
- assert_equal(21, len(self.nodes[0].getpeerinfo()))
-
- # Connect a new Sapling mininode to the zcashd node, which is accepted.
- nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", SAPLING_PROTO_VERSION))
- time.sleep(3)
- assert_equal(22, len(self.nodes[0].getpeerinfo()))
-
- # Try to connect a new Sprout mininode to the zcashd node, which is rejected.
- sprout = NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", SPROUT_PROTO_VERSION)
- nodes.append(sprout)
- time.sleep(3)
- assert("Version must be 170003 or greater" in str(sprout.rejectMessage))
-
- # Verify that only Overwinter and Sapling mininodes are connected.
- peerinfo = self.nodes[0].getpeerinfo()
- versions = [x["version"] for x in peerinfo]
- assert_equal(0, versions.count(SPROUT_PROTO_VERSION))
- assert_equal(11, versions.count(OVERWINTER_PROTO_VERSION))
- assert_equal(11, versions.count(SAPLING_PROTO_VERSION))
-
- # Sapling consensus rules activate at block height 15
- self.nodes[0].generate(4)
- assert_equal(15, self.nodes[0].getblockcount())
- print('Sapling active')
-
- # Mininodes send ping message to zcashd node.
- pingCounter = 1
- for node in nodes:
- node.send_message(msg_ping(pingCounter))
- pingCounter = pingCounter + 1
-
- time.sleep(3)
-
- # Verify Sprout and Overwinter mininodes have been dropped, while
- # Sapling mininodes are still connected.
- peerinfo = self.nodes[0].getpeerinfo()
- versions = [x["version"] for x in peerinfo]
- assert_equal(0, versions.count(SPROUT_PROTO_VERSION))
- assert_equal(0, versions.count(OVERWINTER_PROTO_VERSION))
- assert_equal(11, versions.count(SAPLING_PROTO_VERSION))
-
- # Extend the Sapling chain with another block.
- self.nodes[0].generate(1)
-
- # Connect a new Sapling mininode to the zcashd node, which is accepted.
- nodes.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", SAPLING_PROTO_VERSION))
- time.sleep(3)
- assert_equal(12, len(self.nodes[0].getpeerinfo()))
-
- # Try to connect a new Sprout mininode to the zcashd node, which is rejected.
- sprout = NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", SPROUT_PROTO_VERSION)
- nodes.append(sprout)
- time.sleep(3)
- assert("Version must be 170006 or greater" in str(sprout.rejectMessage))
-
- # Try to connect a new Overwinter mininode to the zcashd node, which is rejected.
- sprout = NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test, "regtest", OVERWINTER_PROTO_VERSION)
- nodes.append(sprout)
- time.sleep(3)
- assert("Version must be 170006 or greater" in str(sprout.rejectMessage))
-
- # Verify that only Sapling mininodes are connected.
- peerinfo = self.nodes[0].getpeerinfo()
- versions = [x["version"] for x in peerinfo]
- assert_equal(0, versions.count(SPROUT_PROTO_VERSION))
- assert_equal(0, versions.count(OVERWINTER_PROTO_VERSION))
- assert_equal(12, versions.count(SAPLING_PROTO_VERSION))
-
- for node in nodes:
- node.disconnect_node()
-
-if __name__ == '__main__':
- NUPeerManagementTest().main()
diff --git a/qa/rpc-tests/p2p_txexpiry_dos.py b/qa/rpc-tests/p2p_txexpiry_dos.py
index ec970435a..582cafd6b 100755
--- a/qa/rpc-tests/p2p_txexpiry_dos.py
+++ b/qa/rpc-tests/p2p_txexpiry_dos.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.mininode import NodeConn, NodeConnCB, NetworkThread, \
CTransaction, msg_tx, mininode_lock, OVERWINTER_PROTO_VERSION
diff --git a/qa/rpc-tests/paymentdisclosure.py b/qa/rpc-tests/paymentdisclosure.py
deleted file mode 100755
index 48d4712a9..000000000
--- a/qa/rpc-tests/paymentdisclosure.py
+++ /dev/null
@@ -1,215 +0,0 @@
-#!/usr/bin/env python2
-# Copyright (c) 2017 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-from test_framework.test_framework import BitcoinTestFramework
-from test_framework.authproxy import JSONRPCException
-from test_framework.util import assert_equal, initialize_chain_clean, \
- start_node, connect_nodes_bi, wait_and_assert_operationid_status
-
-from decimal import Decimal
-
-class PaymentDisclosureTest (BitcoinTestFramework):
-
- def setup_chain(self):
- print("Initializing test directory "+self.options.tmpdir)
- initialize_chain_clean(self.options.tmpdir, 4)
-
- def setup_network(self, split=False):
- args = ['-debug=zrpcunsafe,paymentdisclosure', '-experimentalfeatures', '-paymentdisclosure', '-txindex=1']
- self.nodes = []
- self.nodes.append(start_node(0, self.options.tmpdir, args))
- self.nodes.append(start_node(1, self.options.tmpdir, args))
- # node 2 does not enable payment disclosure
- args2 = ['-debug=zrpcunsafe', '-experimentalfeatures', '-txindex=1']
- self.nodes.append(start_node(2, self.options.tmpdir, args2))
- connect_nodes_bi(self.nodes,0,1)
- connect_nodes_bi(self.nodes,1,2)
- connect_nodes_bi(self.nodes,0,2)
- self.is_network_split=False
- self.sync_all()
-
- def run_test (self):
- print "Mining blocks..."
-
- self.nodes[0].generate(4)
- walletinfo = self.nodes[0].getwalletinfo()
- assert_equal(walletinfo['immature_balance'], 40)
- assert_equal(walletinfo['balance'], 0)
- self.sync_all()
- self.nodes[2].generate(3)
- self.sync_all()
- self.nodes[1].generate(101)
- self.sync_all()
- assert_equal(self.nodes[0].getbalance(), 40)
- assert_equal(self.nodes[1].getbalance(), 10)
- assert_equal(self.nodes[2].getbalance(), 30)
-
- mytaddr = self.nodes[0].getnewaddress()
- myzaddr = self.nodes[0].z_getnewaddress()
-
- # Check that Node 2 has payment disclosure disabled.
- try:
- self.nodes[2].z_getpaymentdisclosure("invalidtxid", 0, 0)
- assert(False)
- except JSONRPCException as e:
- errorString = e.error['message']
- assert("payment disclosure is disabled" in errorString)
-
- # Check that Node 0 returns an error for an unknown txid
- try:
- self.nodes[0].z_getpaymentdisclosure("invalidtxid", 0, 0)
- assert(False)
- except JSONRPCException as e:
- errorString = e.error['message']
- assert("No information available about transaction" in errorString)
-
- # Shield coinbase utxos from node 0 of value 40, standard fee of 0.00010000
- recipients = [{"address":myzaddr, "amount":Decimal('40.0')-Decimal('0.0001')}]
- myopid = self.nodes[0].z_sendmany(mytaddr, recipients)
- txid = wait_and_assert_operationid_status(self.nodes[0], myopid)
-
- # Check the tx has joinsplits
- assert( len(self.nodes[0].getrawtransaction("" + txid, 1)["vjoinsplit"]) > 0 )
-
- # Sync mempools
- self.sync_all()
-
- # Confirm that you can't create a payment disclosure for an unconfirmed tx
- try:
- self.nodes[0].z_getpaymentdisclosure(txid, 0, 0)
- assert(False)
- except JSONRPCException as e:
- errorString = e.error['message']
- assert("Transaction has not been confirmed yet" in errorString)
-
- try:
- self.nodes[1].z_getpaymentdisclosure(txid, 0, 0)
- assert(False)
- except JSONRPCException as e:
- errorString = e.error['message']
- assert("Transaction has not been confirmed yet" in errorString)
-
- # Mine tx
- self.nodes[0].generate(1)
- self.sync_all()
-
- # Confirm that Node 1 cannot create a payment disclosure for a transaction which does not impact its wallet
- try:
- self.nodes[1].z_getpaymentdisclosure(txid, 0, 0)
- assert(False)
- except JSONRPCException as e:
- errorString = e.error['message']
- assert("Transaction does not belong to the wallet" in errorString)
-
- # Check that an invalid joinsplit index is rejected
- try:
- self.nodes[0].z_getpaymentdisclosure(txid, 1, 0)
- assert(False)
- except JSONRPCException as e:
- errorString = e.error['message']
- assert("Invalid js_index" in errorString)
-
- try:
- self.nodes[0].z_getpaymentdisclosure(txid, -1, 0)
- assert(False)
- except JSONRPCException as e:
- errorString = e.error['message']
- assert("Invalid js_index" in errorString)
-
- # Check that an invalid output index is rejected
- try:
- self.nodes[0].z_getpaymentdisclosure(txid, 0, 2)
- assert(False)
- except JSONRPCException as e:
- errorString = e.error['message']
- assert("Invalid output_index" in errorString)
-
- try:
- self.nodes[0].z_getpaymentdisclosure(txid, 0, -1)
- assert(False)
- except JSONRPCException as e:
- errorString = e.error['message']
- assert("Invalid output_index" in errorString)
-
- # Ask Node 0 to create and validate a payment disclosure for output 0
- message = "Here is proof of my payment!"
- pd = self.nodes[0].z_getpaymentdisclosure(txid, 0, 0, message)
- result = self.nodes[0].z_validatepaymentdisclosure(pd)
- assert(result["valid"])
- output_value_sum = Decimal(result["value"])
-
- # Ask Node 1 to confirm the payment disclosure is valid
- result = self.nodes[1].z_validatepaymentdisclosure(pd)
- assert(result["valid"])
- assert_equal(result["message"], message)
- assert_equal(result["value"], output_value_sum)
-
- # Confirm that payment disclosure begins with prefix zpd:
- assert(pd.startswith("zpd:"))
-
- # Confirm that payment disclosure without prefix zpd: fails validation
- try:
- self.nodes[1].z_validatepaymentdisclosure(pd[4:])
- assert(False)
- except JSONRPCException as e:
- errorString = e.error['message']
- assert("payment disclosure prefix not found" in errorString)
-
- # Check that total value of output index 0 and index 1 should equal shielding amount of 40 less standard fee.
- pd = self.nodes[0].z_getpaymentdisclosure(txid, 0, 1)
- result = self.nodes[0].z_validatepaymentdisclosure(pd)
- output_value_sum += Decimal(result["value"])
- assert_equal(output_value_sum, Decimal('39.99990000'))
-
- # Create a z->z transaction, sending shielded funds from node 0 to node 1
- node1zaddr = self.nodes[1].z_getnewaddress()
- recipients = [{"address":node1zaddr, "amount":Decimal('1')}]
- myopid = self.nodes[0].z_sendmany(myzaddr, recipients)
- txid = wait_and_assert_operationid_status(self.nodes[0], myopid)
- self.sync_all()
- self.nodes[0].generate(1)
- self.sync_all()
-
- # Confirm that Node 0 can create a valid payment disclosure
- pd = self.nodes[0].z_getpaymentdisclosure(txid, 0, 0, "a message of your choice")
- result = self.nodes[0].z_validatepaymentdisclosure(pd)
- assert(result["valid"])
-
- # Confirm that Node 1, even as recipient of shielded funds, cannot create a payment disclosure
- # as the transaction was created by Node 0 and Node 1's payment disclosure database does not
- # contain the necessary data to do so, where the data would only have been available on Node 0
- # when executing z_shieldcoinbase.
- try:
- self.nodes[1].z_getpaymentdisclosure(txid, 0, 0)
- assert(False)
- except JSONRPCException as e:
- errorString = e.error['message']
- assert("Could not find payment disclosure info for the given joinsplit output" in errorString)
-
- # Payment disclosures cannot be created for transparent transactions.
- txid = self.nodes[2].sendtoaddress(mytaddr, 1.0)
- self.sync_all()
-
- # No matter the type of transaction, if it has not been confirmed, it is ignored.
- try:
- self.nodes[0].z_getpaymentdisclosure(txid, 0, 0)
- assert(False)
- except JSONRPCException as e:
- errorString = e.error['message']
- assert("Transaction has not been confirmed yet" in errorString)
-
- self.nodes[0].generate(1)
- self.sync_all()
-
- # Confirm that a payment disclosure can only be generated for a shielded transaction.
- try:
- self.nodes[0].z_getpaymentdisclosure(txid, 0, 0)
- assert(False)
- except JSONRPCException as e:
- errorString = e.error['message']
- assert("Transaction is not a shielded transaction" in errorString)
-
-if __name__ == '__main__':
- PaymentDisclosureTest().main()
diff --git a/qa/rpc-tests/prioritisetransaction.py b/qa/rpc-tests/prioritisetransaction.py
index 134b9b160..09647ebd1 100755
--- a/qa/rpc-tests/prioritisetransaction.py
+++ b/qa/rpc-tests/prioritisetransaction.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2017 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
diff --git a/qa/rpc-tests/proton_test.py b/qa/rpc-tests/proton_test.py
deleted file mode 100755
index d9fb27bd3..000000000
--- a/qa/rpc-tests/proton_test.py
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/usr/bin/env python2
-# Copyright (c) 2017 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#
-# Test Proton interface (provides AMQP 1.0 messaging support).
-#
-# Requirements:
-# Python library for Qpid Proton:
-# https://pypi.python.org/pypi/python-qpid-proton
-# To install:
-# pip install python-qpid-proton
-#
-
-from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import assert_equal, bytes_to_hex_str, \
- start_nodes
-
-from proton.handlers import MessagingHandler
-from proton.reactor import Container
-
-import threading
-
-
-class Server(MessagingHandler):
-
- def __init__(self, url, limit):
- super(Server, self).__init__()
- self.url = url
- self.counter = limit
- self.blockhashes = []
- self.txids = []
- self.blockseq = -1
- self.txidseq = -1
-
- def on_start(self, event):
- print "Proton listening on:", self.url
- self.container = event.container
- self.acceptor = event.container.listen(self.url)
-
- def on_message(self, event):
- m = event.message
- hash = bytes_to_hex_str(m.body)
- sequence = m.properties['x-opt-sequence-number']
- if m.subject == "hashtx":
- self.txids.append(hash)
-
- # Test that sequence id is incrementing
- assert(sequence == 1 + self.txidseq)
- self.txidseq = sequence
- elif m.subject == "hashblock":
- self.blockhashes.append(hash)
-
- # Test that sequence id is incrementing
- assert(sequence == 1 + self.blockseq)
- self.blockseq = sequence
-
- self.counter = self.counter - 1
- if self.counter == 0:
- self.container.stop()
-
-
-class ProtonTest (BitcoinTestFramework):
-
- port = 25672
- numblocks = 10 # must be even, as two nodes generate equal number
- assert(numblocks % 2 == 0)
-
- def setup_nodes(self):
-
- # Launch proton server in background thread
- # It terminates after receiving numblocks * 2 messages (one for coinbase, one for block)
- self.server = Server("127.0.0.1:%i" % self.port, self.numblocks * 2)
- self.container = Container(self.server)
- self.t1 = threading.Thread(target=self.container.run)
- self.t1.start()
-
- return start_nodes(4, self.options.tmpdir, extra_args=[
- ['-experimentalfeatures', '-debug=amqp', '-amqppubhashtx=amqp://127.0.0.1:'+str(self.port),
- '-amqppubhashblock=amqp://127.0.0.1:'+str(self.port)],
- [],
- [],
- []
- ])
-
- def run_test(self):
- self.sync_all()
- baseheight = self.nodes[0].getblockcount() # 200 blocks already mined
-
- # generate some blocks
- self.nodes[0].generate(self.numblocks/2)
- self.sync_all()
- self.nodes[1].generate(self.numblocks/2)
- self.sync_all()
-
- # wait for server to finish
- self.t1.join()
-
- # sequence numbers have already been checked in the server's message handler
-
- # sanity check that we have the right number of block hashes and coinbase txids
- assert_equal(len(self.server.blockhashes), self.numblocks)
- assert_equal(len(self.server.txids), self.numblocks)
-
- # verify that each block has the correct coinbase txid
- for i in xrange(0, self.numblocks):
- height = baseheight + i + 1
- blockhash = self.nodes[0].getblockhash(height)
- assert_equal(blockhash, self.server.blockhashes[i])
- resp = self.nodes[0].getblock(blockhash)
- coinbase = resp["tx"][0]
- assert_equal(coinbase, self.server.txids[i])
-
-
-if __name__ == '__main__':
- ProtonTest().main()
diff --git a/qa/rpc-tests/proxy_test.py b/qa/rpc-tests/proxy_test.py
index e4fb48820..31b96f594 100755
--- a/qa/rpc-tests/proxy_test.py
+++ b/qa/rpc-tests/proxy_test.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2015 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.socks5 import Socks5Configuration, Socks5Command, Socks5Server, AddressType
from test_framework.test_framework import BitcoinTestFramework
diff --git a/qa/rpc-tests/pruning.py b/qa/rpc-tests/pruning.py
index 2639060fa..c6a61f6c4 100755
--- a/qa/rpc-tests/pruning.py
+++ b/qa/rpc-tests/pruning.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test pruning code
diff --git a/qa/rpc-tests/rawtransactions.py b/qa/rpc-tests/rawtransactions.py
index 182f87f08..d70352e2a 100755
--- a/qa/rpc-tests/rawtransactions.py
+++ b/qa/rpc-tests/rawtransactions.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test re-org scenarios with a mempool that contains transactions
diff --git a/qa/rpc-tests/receivedby.py b/qa/rpc-tests/receivedby.py
index 59f7bf258..0374381cf 100755
--- a/qa/rpc-tests/receivedby.py
+++ b/qa/rpc-tests/receivedby.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
# Exercise the listreceivedbyaddress API
diff --git a/qa/rpc-tests/regtest_signrawtransaction.py b/qa/rpc-tests/regtest_signrawtransaction.py
index 2e0273677..f892b9751 100755
--- a/qa/rpc-tests/regtest_signrawtransaction.py
+++ b/qa/rpc-tests/regtest_signrawtransaction.py
@@ -1,7 +1,8 @@
#!/usr/bin/env python2
+# Copyright (c) 2019-2020 The Hush developers
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import start_nodes, wait_and_assert_operationid_status
@@ -18,7 +19,7 @@ class RegtestSignrawtransactionTest (BitcoinTestFramework):
self.nodes[0].generate(1)
self.sync_all()
taddr = self.nodes[1].getnewaddress()
- zaddr1 = self.nodes[1].z_getnewaddress('sprout')
+ zaddr1 = self.nodes[1].z_getnewaddress('sapling')
self.nodes[0].sendtoaddress(taddr, 2.0)
self.nodes[0].generate(1)
diff --git a/qa/rpc-tests/rest.py b/qa/rpc-tests/rest.py
index b14ec765d..aee67ffa1 100755
--- a/qa/rpc-tests/rest.py
+++ b/qa/rpc-tests/rest.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test REST interface
diff --git a/qa/rpc-tests/rewind_index.py b/qa/rpc-tests/rewind_index.py
index 8c5c606df..de2ed966c 100755
--- a/qa/rpc-tests/rewind_index.py
+++ b/qa/rpc-tests/rewind_index.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
diff --git a/qa/rpc-tests/rpcbind_test.py b/qa/rpc-tests/rpcbind_test.py
index 72e14d655..09fb630f3 100755
--- a/qa/rpc-tests/rpcbind_test.py
+++ b/qa/rpc-tests/rpcbind_test.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
# Test for -rpcbind, as well as -rpcallowip and -rpcconnect
diff --git a/qa/rpc-tests/script_test.py b/qa/rpc-tests/script_test.py
index c3ad541e5..ea61a04d0 100755
--- a/qa/rpc-tests/script_test.py
+++ b/qa/rpc-tests/script_test.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
#
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3/X11 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
'''
diff --git a/qa/rpc-tests/signrawtransactions.py b/qa/rpc-tests/signrawtransactions.py
index 95d242854..4508784d6 100755
--- a/qa/rpc-tests/signrawtransactions.py
+++ b/qa/rpc-tests/signrawtransactions.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2015 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
diff --git a/qa/rpc-tests/smartfees.py b/qa/rpc-tests/smartfees.py
index e111a406b..b072f224f 100755
--- a/qa/rpc-tests/smartfees.py
+++ b/qa/rpc-tests/smartfees.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014-2015 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test fee estimation code
diff --git a/qa/rpc-tests/spentindex.py b/qa/rpc-tests/spentindex.py
index ebe2b8cc2..a2ce5f2b8 100755
--- a/qa/rpc-tests/spentindex.py
+++ b/qa/rpc-tests/spentindex.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014-2015 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test addressindex generation and fetching
diff --git a/qa/rpc-tests/test_framework/bignum.py b/qa/rpc-tests/test_framework/bignum.py
index b0c58ccd4..7343ac920 100644
--- a/qa/rpc-tests/test_framework/bignum.py
+++ b/qa/rpc-tests/test_framework/bignum.py
@@ -4,8 +4,8 @@
#
# This file is copied from python-bitcoinlib.
#
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
"""Bignum routines"""
diff --git a/qa/rpc-tests/test_framework/blocktools.py b/qa/rpc-tests/test_framework/blocktools.py
index 1fe2a5dda..c546e63eb 100644
--- a/qa/rpc-tests/test_framework/blocktools.py
+++ b/qa/rpc-tests/test_framework/blocktools.py
@@ -1,7 +1,7 @@
# blocktools.py - utilities for manipulating blocks and transactions
#
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
from mininode import CBlock, CTransaction, CTxIn, CTxOut, COutPoint
diff --git a/qa/rpc-tests/test_framework/comptool.py b/qa/rpc-tests/test_framework/comptool.py
index 7f9a97d68..b956690dd 100755
--- a/qa/rpc-tests/test_framework/comptool.py
+++ b/qa/rpc-tests/test_framework/comptool.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
#
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
from mininode import CBlock, CTransaction, CInv, NodeConn, NodeConnCB, \
diff --git a/qa/rpc-tests/test_framework/netutil.py b/qa/rpc-tests/test_framework/netutil.py
index b30a88a4f..59ffe9fc0 100644
--- a/qa/rpc-tests/test_framework/netutil.py
+++ b/qa/rpc-tests/test_framework/netutil.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
# Linux network utilities
import sys
diff --git a/qa/rpc-tests/test_framework/script.py b/qa/rpc-tests/test_framework/script.py
index 55a7f8e51..93c161162 100644
--- a/qa/rpc-tests/test_framework/script.py
+++ b/qa/rpc-tests/test_framework/script.py
@@ -3,8 +3,8 @@
#
# This file is modified from python-bitcoinlib.
#
-# Distributed under the MIT/X11 software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
"""Scripts
diff --git a/qa/rpc-tests/test_framework/socks5.py b/qa/rpc-tests/test_framework/socks5.py
index 1dbfb98d5..1ec159d05 100644
--- a/qa/rpc-tests/test_framework/socks5.py
+++ b/qa/rpc-tests/test_framework/socks5.py
@@ -1,6 +1,6 @@
# Copyright (c) 2015 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
'''
Dummy Socks5 server for testing.
'''
diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py
index 78c66089a..0d1eb40f3 100644
--- a/qa/rpc-tests/test_framework/util.py
+++ b/qa/rpc-tests/test_framework/util.py
@@ -1,8 +1,8 @@
# Copyright (c) 2014 The Bitcoin Core developers
# Copyright (c) 2018-2019 The SuperNET developers
# Copyright (c) 2018-2020 The Hush developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Helpful routines for regression testing
#
diff --git a/qa/rpc-tests/txindex.py b/qa/rpc-tests/txindex.py
index e59b6d7d9..587766fdd 100755
--- a/qa/rpc-tests/txindex.py
+++ b/qa/rpc-tests/txindex.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014-2015 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test txindex generation and fetching
diff --git a/qa/rpc-tests/txn_doublespend.py b/qa/rpc-tests/txn_doublespend.py
index bbe383d16..adb24787b 100755
--- a/qa/rpc-tests/txn_doublespend.py
+++ b/qa/rpc-tests/txn_doublespend.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test proper accounting with malleable transactions
diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py
index 0268dd292..3c891396c 100755
--- a/qa/rpc-tests/wallet.py
+++ b/qa/rpc-tests/wallet.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
diff --git a/qa/rpc-tests/wallet_1941.py b/qa/rpc-tests/wallet_1941.py
index 6f90f33bd..cc741caa7 100755
--- a/qa/rpc-tests/wallet_1941.py
+++ b/qa/rpc-tests/wallet_1941.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2016 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
# This is a regression test for #1941.
diff --git a/qa/rpc-tests/wallet_addresses.py b/qa/rpc-tests/wallet_addresses.py
index 0b9669972..479c42157 100755
--- a/qa/rpc-tests/wallet_addresses.py
+++ b/qa/rpc-tests/wallet_addresses.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, start_nodes
diff --git a/qa/rpc-tests/wallet_anchorfork.py b/qa/rpc-tests/wallet_anchorfork.py
index 1cb16e152..2ef372e9a 100755
--- a/qa/rpc-tests/wallet_anchorfork.py
+++ b/qa/rpc-tests/wallet_anchorfork.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
diff --git a/qa/rpc-tests/wallet_changeindicator.py b/qa/rpc-tests/wallet_changeindicator.py
index 428d0c508..61a15be8f 100755
--- a/qa/rpc-tests/wallet_changeindicator.py
+++ b/qa/rpc-tests/wallet_changeindicator.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_true, assert_false, wait_and_assert_operationid_status
diff --git a/qa/rpc-tests/wallet_import_export.py b/qa/rpc-tests/wallet_import_export.py
index cdcc01d1f..21a06e737 100755
--- a/qa/rpc-tests/wallet_import_export.py
+++ b/qa/rpc-tests/wallet_import_export.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_true, start_nodes
diff --git a/qa/rpc-tests/wallet_listnotes.py b/qa/rpc-tests/wallet_listnotes.py
index 5cd89c661..61a03e3a5 100755
--- a/qa/rpc-tests/wallet_listnotes.py
+++ b/qa/rpc-tests/wallet_listnotes.py
@@ -1,7 +1,8 @@
#!/usr/bin/env python2
+# Copyright (c) 2019-2020 The Hush developers
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, start_nodes, wait_and_assert_operationid_status
@@ -20,89 +21,9 @@ class WalletListNotes(BitcoinTestFramework):
def run_test(self):
# Current height = 200 -> Sprout
assert_equal(200, self.nodes[0].getblockcount())
- sproutzaddr = self.nodes[0].z_getnewaddress('sprout')
# test that we can create a sapling zaddr before sapling activates
saplingzaddr = self.nodes[0].z_getnewaddress('sapling')
-
- # we've got lots of coinbase (taddr) but no shielded funds yet
- assert_equal(0, Decimal(self.nodes[0].z_gettotalbalance()['private']))
-
- # Set current height to 201 -> Sprout
- self.nodes[0].generate(1)
- self.sync_all()
- assert_equal(201, self.nodes[0].getblockcount())
-
- mining_addr = self.nodes[0].listunspent()[0]['address']
-
- # Shield coinbase funds (must be a multiple of 10, no change allowed pre-sapling)
- receive_amount_10 = Decimal('10.0') - Decimal('0.0001')
- recipients = [{"address":sproutzaddr, "amount":receive_amount_10}]
- myopid = self.nodes[0].z_sendmany(mining_addr, recipients)
- txid_1 = wait_and_assert_operationid_status(self.nodes[0], myopid)
- self.sync_all()
-
- # No funds (with (default) one or more confirmations) in sproutzaddr yet
- assert_equal(0, len(self.nodes[0].z_listunspent()))
- assert_equal(0, len(self.nodes[0].z_listunspent(1)))
-
- # no private balance because no confirmations yet
- assert_equal(0, Decimal(self.nodes[0].z_gettotalbalance()['private']))
-
- # list private unspent, this time allowing 0 confirmations
- unspent_cb = self.nodes[0].z_listunspent(0)
- assert_equal(1, len(unspent_cb))
- assert_equal(False, unspent_cb[0]['change'])
- assert_equal(txid_1, unspent_cb[0]['txid'])
- assert_equal(True, unspent_cb[0]['spendable'])
- assert_equal(sproutzaddr, unspent_cb[0]['address'])
- assert_equal(receive_amount_10, unspent_cb[0]['amount'])
-
- # list unspent, filtering by address, should produce same result
- unspent_cb_filter = self.nodes[0].z_listunspent(0, 9999, False, [sproutzaddr])
- assert_equal(unspent_cb, unspent_cb_filter)
-
- # Generate a block to confirm shield coinbase tx
- self.nodes[0].generate(1)
- self.sync_all()
-
- # Current height = 202 -> Overwinter. Default address type remains Sprout
- assert_equal(202, self.nodes[0].getblockcount())
-
- # Send 1.0 (actually 0.9999) from sproutzaddr to a new zaddr
- sproutzaddr2 = self.nodes[0].z_getnewaddress()
- receive_amount_1 = Decimal('1.0') - Decimal('0.0001')
- change_amount_9 = receive_amount_10 - Decimal('1.0')
- assert_equal('sprout', self.nodes[0].z_validateaddress(sproutzaddr2)['type'])
- recipients = [{"address": sproutzaddr2, "amount":receive_amount_1}]
- myopid = self.nodes[0].z_sendmany(sproutzaddr, recipients)
- txid_2 = wait_and_assert_operationid_status(self.nodes[0], myopid)
- self.sync_all()
-
- # list unspent, allowing 0conf txs
- unspent_tx = self.nodes[0].z_listunspent(0)
- assert_equal(len(unspent_tx), 2)
- # sort low-to-high by amount (order of returned entries is not guaranteed)
- unspent_tx = sorted(unspent_tx, key=lambda k: k['amount'])
- assert_equal(False, unspent_tx[0]['change'])
- assert_equal(txid_2, unspent_tx[0]['txid'])
- assert_equal(True, unspent_tx[0]['spendable'])
- assert_equal(sproutzaddr2, unspent_tx[0]['address'])
- assert_equal(receive_amount_1, unspent_tx[0]['amount'])
-
- assert_equal(True, unspent_tx[1]['change'])
- assert_equal(txid_2, unspent_tx[1]['txid'])
- assert_equal(True, unspent_tx[1]['spendable'])
- assert_equal(sproutzaddr, unspent_tx[1]['address'])
- assert_equal(change_amount_9, unspent_tx[1]['amount'])
-
- unspent_tx_filter = self.nodes[0].z_listunspent(0, 9999, False, [sproutzaddr2])
- assert_equal(1, len(unspent_tx_filter))
- assert_equal(unspent_tx[0], unspent_tx_filter[0])
-
- unspent_tx_filter = self.nodes[0].z_listunspent(0, 9999, False, [sproutzaddr])
- assert_equal(1, len(unspent_tx_filter))
- assert_equal(unspent_tx[1], unspent_tx_filter[0])
# Set current height to 204 -> Sapling
self.nodes[0].generate(2)
diff --git a/qa/rpc-tests/wallet_listreceived.py b/qa/rpc-tests/wallet_listreceived.py
index ec9ac9371..8a6b67e96 100755
--- a/qa/rpc-tests/wallet_listreceived.py
+++ b/qa/rpc-tests/wallet_listreceived.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_true, assert_false
diff --git a/qa/rpc-tests/wallet_mergetoaddress.py b/qa/rpc-tests/wallet_mergetoaddress.py
index e5d5089a4..e084d7815 100755
--- a/qa/rpc-tests/wallet_mergetoaddress.py
+++ b/qa/rpc-tests/wallet_mergetoaddress.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2017 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
diff --git a/qa/rpc-tests/wallet_nullifiers.py b/qa/rpc-tests/wallet_nullifiers.py
index 9b4e5649c..f4288fb31 100755
--- a/qa/rpc-tests/wallet_nullifiers.py
+++ b/qa/rpc-tests/wallet_nullifiers.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2016 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
diff --git a/qa/rpc-tests/wallet_overwintertx.py b/qa/rpc-tests/wallet_overwintertx.py
index d77a114db..f02beab75 100755
--- a/qa/rpc-tests/wallet_overwintertx.py
+++ b/qa/rpc-tests/wallet_overwintertx.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
diff --git a/qa/rpc-tests/wallet_persistence.py b/qa/rpc-tests/wallet_persistence.py
index 581cad473..8f3f10ddc 100755
--- a/qa/rpc-tests/wallet_persistence.py
+++ b/qa/rpc-tests/wallet_persistence.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2018 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
diff --git a/qa/rpc-tests/wallet_protectcoinbase.py b/qa/rpc-tests/wallet_protectcoinbase.py
index 71512840d..62dbdc579 100755
--- a/qa/rpc-tests/wallet_protectcoinbase.py
+++ b/qa/rpc-tests/wallet_protectcoinbase.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2016 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
diff --git a/qa/rpc-tests/wallet_shieldcoinbase.py b/qa/rpc-tests/wallet_shieldcoinbase.py
index f325b29ca..4cb6893e8 100755
--- a/qa/rpc-tests/wallet_shieldcoinbase.py
+++ b/qa/rpc-tests/wallet_shieldcoinbase.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2017 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
diff --git a/qa/rpc-tests/wallet_treestate.py b/qa/rpc-tests/wallet_treestate.py
index b3edcd7c5..d8f7aaf74 100755
--- a/qa/rpc-tests/wallet_treestate.py
+++ b/qa/rpc-tests/wallet_treestate.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2016 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
diff --git a/qa/rpc-tests/walletbackup.py b/qa/rpc-tests/walletbackup.py
index 78128ad49..99f1cc4e1 100755
--- a/qa/rpc-tests/walletbackup.py
+++ b/qa/rpc-tests/walletbackup.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
"""
Exercise the wallet backup code. Ported from walletbackup.sh.
diff --git a/qa/rpc-tests/zapwallettxes.py b/qa/rpc-tests/zapwallettxes.py
index 5da4ba125..a8db2eb4c 100755
--- a/qa/rpc-tests/zapwallettxes.py
+++ b/qa/rpc-tests/zapwallettxes.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2014 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
diff --git a/qa/rpc-tests/zcjoinsplit.py b/qa/rpc-tests/zcjoinsplit.py
deleted file mode 100755
index b3ca745f8..000000000
--- a/qa/rpc-tests/zcjoinsplit.py
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/usr/bin/env python2
-
-#
-# Test joinsplit semantics
-#
-
-from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import assert_equal, start_node, \
- gather_inputs
-
-
-class JoinSplitTest(BitcoinTestFramework):
- def setup_network(self):
- self.nodes = []
- self.is_network_split = False
- self.nodes.append(start_node(0, self.options.tmpdir))
-
- def run_test(self):
- zckeypair = self.nodes[0].zcrawkeygen()
- zcsecretkey = zckeypair["zcsecretkey"]
- zcaddress = zckeypair["zcaddress"]
-
- (total_in, inputs) = gather_inputs(self.nodes[0], 40)
- protect_tx = self.nodes[0].createrawtransaction(inputs, {})
- joinsplit_result = self.nodes[0].zcrawjoinsplit(protect_tx, {}, {zcaddress:39.99}, 39.99, 0)
-
- receive_result = self.nodes[0].zcrawreceive(zcsecretkey, joinsplit_result["encryptednote1"])
- assert_equal(receive_result["exists"], False)
-
- protect_tx = self.nodes[0].signrawtransaction(joinsplit_result["rawtxn"])
- self.nodes[0].sendrawtransaction(protect_tx["hex"])
- self.nodes[0].generate(1)
- self.sync_all()
-
- receive_result = self.nodes[0].zcrawreceive(zcsecretkey, joinsplit_result["encryptednote1"])
- assert_equal(receive_result["exists"], True)
-
- # The pure joinsplit we create should be mined in the next block
- # despite other transactions being in the mempool.
- addrtest = self.nodes[0].getnewaddress()
- for xx in range(0,10):
- self.nodes[0].generate(1)
- self.sync_all()
- for x in range(0,50):
- self.nodes[0].sendtoaddress(addrtest, 0.01);
-
- joinsplit_tx = self.nodes[0].createrawtransaction([], {})
- joinsplit_result = self.nodes[0].zcrawjoinsplit(joinsplit_tx, {receive_result["note"] : zcsecretkey}, {zcaddress: 39.98}, 0, 0.01)
-
- self.nodes[0].sendrawtransaction(joinsplit_result["rawtxn"])
- self.nodes[0].generate(1)
- self.sync_all()
-
- print "Done!"
- receive_result = self.nodes[0].zcrawreceive(zcsecretkey, joinsplit_result["encryptednote1"])
- assert_equal(receive_result["exists"], True)
-
-if __name__ == '__main__':
- JoinSplitTest().main()
diff --git a/qa/rpc-tests/zcjoinsplitdoublespend.py b/qa/rpc-tests/zcjoinsplitdoublespend.py
deleted file mode 100755
index b56e7475a..000000000
--- a/qa/rpc-tests/zcjoinsplitdoublespend.py
+++ /dev/null
@@ -1,182 +0,0 @@
-#!/usr/bin/env python2
-
-#
-# Tests a joinsplit double-spend and a subsequent reorg.
-#
-
-from test_framework.test_framework import BitcoinTestFramework
-from test_framework.authproxy import JSONRPCException
-from test_framework.util import assert_equal, connect_nodes, \
- gather_inputs, sync_blocks
-
-import time
-
-class JoinSplitTest(BitcoinTestFramework):
- def setup_network(self):
- # Start with split network:
- return super(JoinSplitTest, self).setup_network(True)
-
- def txid_in_mempool(self, node, txid):
- exception_triggered = False
-
- try:
- node.getrawtransaction(txid)
- except JSONRPCException:
- exception_triggered = True
-
- return not exception_triggered
-
- def cannot_joinsplit(self, node, txn):
- exception_triggered = False
-
- try:
- node.sendrawtransaction(txn)
- except JSONRPCException:
- exception_triggered = True
-
- return exception_triggered
-
- def expect_cannot_joinsplit(self, node, txn):
- assert_equal(self.cannot_joinsplit(node, txn), True)
-
- def run_test(self):
- # All nodes should start with 250 HUSH:
- starting_balance = 250
- for i in range(4):
- assert_equal(self.nodes[i].getbalance(), starting_balance)
- self.nodes[i].getnewaddress("") # bug workaround, coins generated assigned to first getnewaddress!
-
- # Generate zcaddress keypairs
- zckeypair = self.nodes[0].zcrawkeygen()
- zcsecretkey = zckeypair["zcsecretkey"]
- zcaddress = zckeypair["zcaddress"]
-
- pool = [0, 1, 2, 3]
- for i in range(4):
- (total_in, inputs) = gather_inputs(self.nodes[i], 40)
- pool[i] = self.nodes[i].createrawtransaction(inputs, {})
- pool[i] = self.nodes[i].zcrawjoinsplit(pool[i], {}, {zcaddress:39.99}, 39.99, 0)
- signed = self.nodes[i].signrawtransaction(pool[i]["rawtxn"])
-
- # send the tx to both halves of the network
- self.nodes[0].sendrawtransaction(signed["hex"])
- self.nodes[0].generate(1)
- self.nodes[2].sendrawtransaction(signed["hex"])
- self.nodes[2].generate(1)
- pool[i] = pool[i]["encryptednote1"]
-
- sync_blocks(self.nodes[0:2])
- sync_blocks(self.nodes[2:4])
-
- # Confirm that the protects have taken place
- for i in range(4):
- enc_note = pool[i]
- receive_result = self.nodes[0].zcrawreceive(zcsecretkey, enc_note)
- assert_equal(receive_result["exists"], True)
- pool[i] = receive_result["note"]
-
- # Extra confirmations
- receive_result = self.nodes[1].zcrawreceive(zcsecretkey, enc_note)
- assert_equal(receive_result["exists"], True)
-
- receive_result = self.nodes[2].zcrawreceive(zcsecretkey, enc_note)
- assert_equal(receive_result["exists"], True)
-
- receive_result = self.nodes[3].zcrawreceive(zcsecretkey, enc_note)
- assert_equal(receive_result["exists"], True)
-
- blank_tx = self.nodes[0].createrawtransaction([], {})
- # Create joinsplit {A, B}->{*}
- joinsplit_AB = self.nodes[0].zcrawjoinsplit(blank_tx,
- {pool[0] : zcsecretkey, pool[1] : zcsecretkey},
- {zcaddress:(39.99*2)-0.01},
- 0, 0.01)
-
- # Create joinsplit {B, C}->{*}
- joinsplit_BC = self.nodes[0].zcrawjoinsplit(blank_tx,
- {pool[1] : zcsecretkey, pool[2] : zcsecretkey},
- {zcaddress:(39.99*2)-0.01},
- 0, 0.01)
-
- # Create joinsplit {C, D}->{*}
- joinsplit_CD = self.nodes[0].zcrawjoinsplit(blank_tx,
- {pool[2] : zcsecretkey, pool[3] : zcsecretkey},
- {zcaddress:(39.99*2)-0.01},
- 0, 0.01)
-
- # Create joinsplit {A, D}->{*}
- joinsplit_AD = self.nodes[0].zcrawjoinsplit(blank_tx,
- {pool[0] : zcsecretkey, pool[3] : zcsecretkey},
- {zcaddress:(39.99*2)-0.01},
- 0, 0.01)
-
- # (a) Node 0 will spend joinsplit AB, then attempt to
- # double-spend it with BC. It should fail before and
- # after Node 0 mines blocks.
- #
- # (b) Then, Node 2 will spend BC, and mine 5 blocks.
- # Node 1 connects, and AB will be reorg'd from the chain.
- # Any attempts to spend AB or CD should fail for
- # both nodes.
- #
- # (c) Then, Node 0 will spend AD, which should work
- # because the previous spend for A (AB) is considered
- # invalid due to the reorg.
-
- # (a)
-
- AB_txid = self.nodes[0].sendrawtransaction(joinsplit_AB["rawtxn"])
-
- self.expect_cannot_joinsplit(self.nodes[0], joinsplit_BC["rawtxn"])
-
- # Wait until node[1] receives AB before we attempt to double-spend
- # with BC.
- print "Waiting for AB_txid...\n"
- while True:
- if self.txid_in_mempool(self.nodes[1], AB_txid):
- break
- time.sleep(0.2)
- print "Done!\n"
-
- self.expect_cannot_joinsplit(self.nodes[1], joinsplit_BC["rawtxn"])
-
- # Generate a block
- self.nodes[0].generate(1)
- sync_blocks(self.nodes[0:2])
-
- self.expect_cannot_joinsplit(self.nodes[0], joinsplit_BC["rawtxn"])
- self.expect_cannot_joinsplit(self.nodes[1], joinsplit_BC["rawtxn"])
-
- # (b)
- self.nodes[2].sendrawtransaction(joinsplit_BC["rawtxn"])
- self.nodes[2].generate(5)
-
- # Connect the two nodes
-
- connect_nodes(self.nodes[1], 2)
- sync_blocks(self.nodes)
-
- # AB and CD should all be impossible to spend for each node.
- self.expect_cannot_joinsplit(self.nodes[0], joinsplit_AB["rawtxn"])
- self.expect_cannot_joinsplit(self.nodes[0], joinsplit_CD["rawtxn"])
-
- self.expect_cannot_joinsplit(self.nodes[1], joinsplit_AB["rawtxn"])
- self.expect_cannot_joinsplit(self.nodes[1], joinsplit_CD["rawtxn"])
-
- self.expect_cannot_joinsplit(self.nodes[2], joinsplit_AB["rawtxn"])
- self.expect_cannot_joinsplit(self.nodes[2], joinsplit_CD["rawtxn"])
-
- self.expect_cannot_joinsplit(self.nodes[3], joinsplit_AB["rawtxn"])
- self.expect_cannot_joinsplit(self.nodes[3], joinsplit_CD["rawtxn"])
-
- # (c)
- # AD should be possible to send due to the reorg that
- # tossed out AB.
-
- self.nodes[0].sendrawtransaction(joinsplit_AD["rawtxn"])
- self.nodes[0].generate(1)
-
- sync_blocks(self.nodes)
-
-if __name__ == '__main__':
- JoinSplitTest().main()
diff --git a/qa/rpc-tests/zkey_import_export.py b/qa/rpc-tests/zkey_import_export.py
index 775233b6d..49927107f 100755
--- a/qa/rpc-tests/zkey_import_export.py
+++ b/qa/rpc-tests/zkey_import_export.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2017 The Zcash developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from decimal import Decimal
from test_framework.test_framework import BitcoinTestFramework
diff --git a/qa/rpc-tests/zmq_test.py b/qa/rpc-tests/zmq_test.py
index dcb899861..6725a2778 100755
--- a/qa/rpc-tests/zmq_test.py
+++ b/qa/rpc-tests/zmq_test.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# Copyright (c) 2015 The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+# Distributed under the GPLv3 software license, see the accompanying
+# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#
# Test ZMQ interface
diff --git a/src/Makefile.am b/src/Makefile.am
index 6277e0f98..87bed1375 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,3 +1,5 @@
+# Copyright 2019-2020 The Hush developers
+
DIST_SUBDIRS = secp256k1 univalue cryptoconditions
AM_LDFLAGS = $(PTHREAD_CFLAGS) $(LIBTOOL_LDFLAGS) $(SAN_LDFLAGS) $(HARDENED_LDFLAGS)
@@ -48,13 +50,11 @@ LIBSECP256K1=secp256k1/libsecp256k1.la
LIBCRYPTOCONDITIONS=cryptoconditions/libcryptoconditions_core.la
LIBUNIVALUE=univalue/libunivalue.la
LIBZCASH=libzcash.a
+LIBHUSH=libhush.a
if ENABLE_ZMQ
LIBBITCOIN_ZMQ=libbitcoin_zmq.a
endif
-if ENABLE_PROTON
-LIBBITCOIN_PROTON=libbitcoin_proton.a
-endif
if BUILD_BITCOIN_LIBS
LIBZCASH_CONSENSUS=libzcashconsensus.la
endif
@@ -63,13 +63,13 @@ LIBBITCOIN_WALLET=libbitcoin_wallet.a
endif
$(LIBSECP256K1): $(wildcard secp256k1/src/*) $(wildcard secp256k1/include/*)
- $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) OPTFLAGS="-O2 -march=x86-64 -g "
+ $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) OPTFLAGS="-O2 -g "
$(LIBUNIVALUE): $(wildcard univalue/lib/*)
- $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) OPTFLAGS="-O2 -march=x86-64 -g "
+ $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) OPTFLAGS="-O2 -g "
$(LIBCRYPTOCONDITIONS): $(wildcard cryptoconditions/src/*) $(wildcard cryptoconditions/include/*)
- $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) OPTFLAGS="-O2 -march=x86-64 -g "
+ $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) OPTFLAGS="-O2 -g "
# Make is not made aware of per-object dependencies to avoid limiting building parallelization
# But to build the less dependent modules first, we manually select their order here:
@@ -79,7 +79,8 @@ EXTRA_LIBRARIES += \
$(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_CLI) \
- libzcash.a
+ libzcash.a \
+ libhush.a
if ENABLE_WALLET
BITCOIN_INCLUDES += $(BDB_CPPFLAGS)
EXTRA_LIBRARIES += $(LIBBITCOIN_WALLET)
@@ -87,9 +88,6 @@ endif
if ENABLE_ZMQ
EXTRA_LIBRARIES += $(LIBBITCOIN_ZMQ)
endif
-if ENABLE_PROTON
-EXTRA_LIBRARIES += $(LIBBITCOIN_PROTON)
-endif
lib_LTLIBRARIES = $(LIBZCASH_CONSENSUS)
@@ -162,6 +160,7 @@ BITCOIN_CORE_H = \
core_io.h \
core_memusage.h \
deprecation.h \
+ fs.h \
hash.h \
httprpc.h \
httpserver.h \
@@ -181,14 +180,11 @@ BITCOIN_CORE_H = \
netbase.h \
notaries_staked.h \
noui.h \
- paymentdisclosure.h \
- paymentdisclosuredb.h \
policy/fees.h \
pow.h \
prevector.h \
primitives/block.h \
primitives/transaction.h \
- primitives/nonce.h \
protocol.h \
pubkey.h \
random.h \
@@ -220,6 +216,7 @@ BITCOIN_CORE_H = \
txdb.h \
txmempool.h \
ui_interface.h \
+ util/asmap.h \
uint256.h \
uint252.h \
undo.h \
@@ -245,6 +242,8 @@ BITCOIN_CORE_H = \
zmq/zmqnotificationinterface.h \
zmq/zmqpublishnotifier.h
+LIBHUSH_H = \
+ hush/utiltls.h
obj/build.h: FORCE
@$(MKDIR_P) $(builddir)/obj
@@ -288,6 +287,7 @@ libbitcoin_server_a_SOURCES = \
cc/betprotocol.cpp \
chain.cpp \
checkpoints.cpp \
+ fs.cpp \
crosschain.cpp \
crosschain_authority.cpp \
deprecation.cpp \
@@ -303,8 +303,6 @@ libbitcoin_server_a_SOURCES = \
notaries_staked.cpp \
noui.cpp \
notarisationdb.cpp \
- paymentdisclosure.cpp \
- paymentdisclosuredb.cpp \
policy/fees.cpp \
pow.cpp \
rest.cpp \
@@ -323,7 +321,8 @@ libbitcoin_server_a_SOURCES = \
txmempool.cpp \
validationinterface.cpp \
$(BITCOIN_CORE_H) \
- $(LIBZCASH_H)
+ $(LIBZCASH_H) \
+ $(LIBHUSH_H)
if ENABLE_ZMQ
libbitcoin_zmq_a_CPPFLAGS = $(BITCOIN_INCLUDES) $(ZMQ_CFLAGS)
@@ -334,21 +333,10 @@ libbitcoin_zmq_a_SOURCES = \
zmq/zmqpublishnotifier.cpp
endif
-if ENABLE_PROTON
-libbitcoin_proton_a_CPPFLAGS = $(BITCOIN_INCLUDES)
-libbitcoin_proton_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
-libbitcoin_proton_a_SOURCES = \
- amqp/amqpabstractnotifier.cpp \
- amqp/amqpnotificationinterface.cpp \
- amqp/amqppublishnotifier.cpp
-endif
-
-# wallet: zcashd, but only linked when wallet enabled
+# wallet: komodod, but only linked when wallet enabled
libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_wallet_a_SOURCES = \
- utiltest.cpp \
- utiltest.h \
zcbenchmarks.cpp \
zcbenchmarks.h \
wallet/asyncrpcoperation_mergetoaddress.cpp \
@@ -357,10 +345,8 @@ libbitcoin_wallet_a_SOURCES = \
wallet/asyncrpcoperation_shieldcoinbase.cpp \
wallet/crypter.cpp \
wallet/db.cpp \
- paymentdisclosure.cpp \
- paymentdisclosuredb.cpp \
+ zcash/Note.cpp \
transaction_builder.cpp \
- wallet/rpcdisclosure.cpp \
wallet/rpcdump.cpp \
cc/CCtokens.cpp \
cc/CCassetsCore.cpp \
@@ -400,7 +386,6 @@ if EXPERIMENTAL_ASM
crypto_libbitcoin_crypto_a_SOURCES += crypto/sha256_sse4.cpp
endif
-
if ENABLE_MINING
EQUIHASH_TROMP_SOURCES = \
pow/tromp/equi_miner.h \
@@ -436,7 +421,6 @@ libbitcoin_common_a_SOURCES = \
metrics.cpp \
primitives/block.cpp \
primitives/transaction.cpp \
- primitives/nonce.cpp \
protocol.cpp \
pubkey.cpp \
scheduler.cpp \
@@ -473,6 +457,7 @@ libbitcoin_util_a_SOURCES = \
utilmoneystr.cpp \
utilstrencodings.cpp \
utiltime.cpp \
+ util/asmap.cpp \
$(BITCOIN_CORE_H) \
$(LIBZCASH_H)
@@ -485,7 +470,7 @@ libbitcoin_server_a_SOURCES += rpc/testtransactions.cpp
endif
-# cli: zcash-cli
+# cli
libbitcoin_cli_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_cli_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_cli_a_SOURCES = \
@@ -496,7 +481,7 @@ libbitcoin_cli_a_SOURCES = \
nodist_libbitcoin_util_a_SOURCES = $(srcdir)/obj/build.h
#
-# bitcoind binary #
+# komodod binary #
komodod_SOURCES = bitcoind.cpp
komodod_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
komodod_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
@@ -512,9 +497,9 @@ komodod_LDADD = \
$(LIBUNIVALUE) \
$(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_ZMQ) \
- $(LIBBITCOIN_PROTON) \
$(LIBBITCOIN_CRYPTO) \
$(LIBZCASH) \
+ $(LIBHUSH) \
$(LIBLEVELDB) \
$(LIBMEMENV) \
$(LIBSECP256K1) \
@@ -532,7 +517,6 @@ komodod_LDADD += \
$(EVENT_PTHREADS_LIBS) \
$(EVENT_LIBS) \
$(ZMQ_LIBS) \
- $(PROTON_LIBS) \
$(LIBBITCOIN_CRYPTO) \
$(LIBZCASH_LIBS)
@@ -546,16 +530,12 @@ if TARGET_LINUX
komodod_LDADD += libcc.so $(LIBSECP256K1)
endif
-if ENABLE_PROTON
-komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS)
-endif
-
# [+] Decker: use static linking for libstdc++.6.dylib, libgomp.1.dylib, libgcc_s.1.dylib
if TARGET_DARWIN
komodod_LDFLAGS += -static-libgcc
endif
-# bitcoin-cli binary #
+# komodo-cli binary #
komodo_cli_SOURCES = bitcoin-cli.cpp
komodo_cli_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS)
komodo_cli_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
@@ -585,6 +565,7 @@ komodo_cli_LDADD = \
$(CRYPTO_LIBS) \
$(EVENT_LIBS) \
$(LIBZCASH) \
+ $(LIBHUSH) \
$(LIBBITCOIN_CRYPTO) \
$(LIBZCASH_LIBS)
@@ -603,7 +584,7 @@ wallet_utility_LDADD = \
$(LIBCRYPTOCONDITIONS)
endif
-# zcash-tx binary #
+# komodo-tx binary #
komodo_tx_SOURCES = komodo-tx.cpp
komodo_tx_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
komodo_tx_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
@@ -613,19 +594,18 @@ if TARGET_WINDOWS
komodo_tx_SOURCES += bitcoin-tx-res.rc
endif
-# FIXME: Is libzcash needed for hush-tx ?
komodo_tx_LDADD = \
$(LIBUNIVALUE) \
$(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_UTIL) \
$(LIBSECP256K1) \
$(LIBZCASH) \
+ $(LIBHUSH) \
$(LIBBITCOIN_CRYPTO) \
$(LIBZCASH_LIBS) \
$(LIBCRYPTOCONDITIONS)
komodo_tx_LDADD += $(BOOST_LIBS) $(CRYPTO_LIBS)
-#
# zcash protocol primitives #
libzcash_a_SOURCES = \
@@ -661,7 +641,6 @@ libzcashconsensus_la_SOURCES = \
crypto/sha512.cpp \
hash.cpp \
primitives/transaction.cpp \
- primitives/nonce.cpp \
pubkey.cpp \
script/zcashconsensus.cpp \
script/interpreter.cpp \
@@ -681,6 +660,20 @@ libzcashconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
endif
#
+# hush-specific sources #
+libhush_a_SOURCES = \
+ hush/utiltls.cpp\
+ hush/tlsmanager.cpp
+
+libhush_a_CPPFLAGS = -DMULTICORE -fopenmp -fPIC -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS $(HARDENED_CPPFLAGS) -pipe -O1 -g -Wstack-protector -fstack-protector-all -fPIE -fvisibility=hidden -DSTATIC $(BITCOIN_INCLUDES)
+
+libhush_a_CXXFLAGS = $(HARDENED_CXXFLAGS) -fwrapv -fno-strict-aliasing
+
+libhush_a_LDFLAGS = $(HARDENED_LDFLAGS)
+
+libhush_a_CPPFLAGS += -DMONTGOMERY_OUTPUT
+#
+
CLEANFILES = leveldb/libleveldb.a leveldb/libmemenv.a *.gcda *.gcno */*.gcno wallet/*/*.gcno
DISTCLEANFILES = obj/build.h
diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include
index 1f1b511db..bcf2ddaf9 100644
--- a/src/Makefile.gtest.include
+++ b/src/Makefile.gtest.include
@@ -1,4 +1,5 @@
-
+# Copyright (c) 2019-2020 Hush developers
+# Released under the GPLv3
TESTS += komodo-gtest
bin_PROGRAMS += komodo-gtest
@@ -9,7 +10,6 @@ komodo_gtest_SOURCES = \
gtest/test_checktransaction.cpp \
gtest/json_test_vectors.cpp \
gtest/json_test_vectors.h \
- # gtest/test_foundersreward.cpp \
gtest/test_wallet_zkeys.cpp \
# These tests are order-dependent, because they
# depend on global state (see #1539)
@@ -65,11 +65,6 @@ endif
komodo_gtest_LDADD += $(LIBZCASH_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(LIBZCASH) $(LIBZCASH_LIBS)
-if ENABLE_PROTON
-komodo_gtest_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS)
-endif
-
-
komodo_gtest_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
komodo_gtest_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
diff --git a/src/Makefile.ktest.include b/src/Makefile.ktest.include
index 640c154e4..18b808eef 100644
--- a/src/Makefile.ktest.include
+++ b/src/Makefile.ktest.include
@@ -10,7 +10,9 @@ komodo_test_SOURCES = \
test-komodo/test_coinimport.cpp \
test-komodo/test_eval_bet.cpp \
test-komodo/test_eval_notarisation.cpp \
- test-komodo/test_parse_notarisation.cpp
+ test-komodo/test_parse_notarisation.cpp \
+ test-komodo/test_addrman.cpp \
+ test-komodo/test_netbase_tests.cpp
komodo_test_CPPFLAGS = $(komodod_CPPFLAGS)
diff --git a/src/Makefile.test.include b/src/Makefile.test.include
index 14324b02b..0e2433bfd 100644
--- a/src/Makefile.test.include
+++ b/src/Makefile.test.include
@@ -130,10 +130,6 @@ if ENABLE_ZMQ
test_test_bitcoin_LDADD += $(ZMQ_LIBS)
endif
-if ENABLE_PROTON
-test_test_bitcoin_LDADD += $(PROTON_LIBS)
-endif
-
nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)
$(BITCOIN_TESTS): $(GENERATED_TEST_FILES)
diff --git a/src/addressindex.h b/src/addressindex.h
index 643f06e13..b39f36c12 100644
--- a/src/addressindex.h
+++ b/src/addressindex.h
@@ -1,7 +1,8 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_ADDRESSINDEX_H
#define BITCOIN_ADDRESSINDEX_H
@@ -79,4 +80,4 @@ struct CMempoolAddressDeltaKeyCompare
}
};
-#endif // BITCOIN_ADDRESSINDEX_H
\ No newline at end of file
+#endif // BITCOIN_ADDRESSINDEX_H
diff --git a/src/addrman.cpp b/src/addrman.cpp
index 1c8bf4b7c..9b9227aa0 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -1,6 +1,7 @@
// Copyright (c) 2012 Pieter Wuille
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
@@ -23,19 +24,25 @@
#include "serialize.h"
#include "streams.h"
-int CAddrInfo::GetTriedBucket(const uint256& nKey) const
+int CAddrInfo::GetTriedBucket(const uint256& nKey, const std::vector &asmap) const
{
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetKey()).GetHash().GetCheapHash();
- uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup() << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetHash().GetCheapHash();
- return hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
+ uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup(asmap) << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetHash().GetCheapHash();
+ int tried_bucket = hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
+ uint32_t mapped_as = GetMappedAS(asmap);
+ LogPrint("net", "IP %s mapped to AS%i belongs to tried bucket %i\n", ToStringIP(), mapped_as, tried_bucket);
+ return tried_bucket;
}
-int CAddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src) const
+int CAddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const std::vector &asmap) const
{
- std::vector vchSourceGroupKey = src.GetGroup();
- uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup() << vchSourceGroupKey).GetHash().GetCheapHash();
+ std::vector vchSourceGroupKey = src.GetGroup(asmap);
+ uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup(asmap) << vchSourceGroupKey).GetHash().GetCheapHash();
uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP)).GetHash().GetCheapHash();
- return hash2 % ADDRMAN_NEW_BUCKET_COUNT;
+ int new_bucket = hash2 % ADDRMAN_NEW_BUCKET_COUNT;
+ uint32_t mapped_as = GetMappedAS(asmap);
+ LogPrint("net", "IP %s mapped to AS%i belongs to new bucket %i\n", ToStringIP(), mapped_as, new_bucket);
+ return new_bucket;
}
int CAddrInfo::GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const
@@ -175,7 +182,7 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)
assert(info.nRefCount == 0);
// which tried bucket to move the entry to
- int nKBucket = info.GetTriedBucket(nKey);
+ int nKBucket = info.GetTriedBucket(nKey, m_asmap);
int nKBucketPos = info.GetBucketPosition(nKey, false, nKBucket);
// first make space to add it (the existing tried entry there is moved to new, deleting whatever is there).
@@ -191,7 +198,7 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)
nTried--;
// find which new bucket it belongs to
- int nUBucket = infoOld.GetNewBucket(nKey);
+ int nUBucket = infoOld.GetNewBucket(nKey, m_asmap);
int nUBucketPos = infoOld.GetBucketPosition(nKey, true, nUBucket);
ClearNew(nUBucket, nUBucketPos);
assert(vvNew[nUBucket][nUBucketPos] == -1);
@@ -268,7 +275,7 @@ bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimeP
if (pinfo) {
// periodically update nTime
- bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60);
+ bool fCurrentlyOnline = (GetTime() - addr.nTime < 24 * 60 * 60);
int64_t nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60);
if (addr.nTime && (!pinfo->nTime || pinfo->nTime < addr.nTime - nUpdateInterval - nTimePenalty))
pinfo->nTime = std::max((int64_t)0, addr.nTime - nTimePenalty);
@@ -301,7 +308,7 @@ bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimeP
fNew = true;
}
- int nUBucket = pinfo->GetNewBucket(nKey, source);
+ int nUBucket = pinfo->GetNewBucket(nKey, source, m_asmap);
int nUBucketPos = pinfo->GetBucketPosition(nKey, true, nUBucket);
if (vvNew[nUBucket][nUBucketPos] != nId) {
bool fInsert = vvNew[nUBucket][nUBucketPos] == -1;
@@ -453,7 +460,7 @@ int CAddrMan::Check_()
if (vvTried[n][i] != -1) {
if (!setTried.count(vvTried[n][i]))
return -11;
- if (mapInfo[vvTried[n][i]].GetTriedBucket(nKey) != n)
+ if (mapInfo[vvTried[n][i]].GetTriedBucket(nKey, m_asmap) != n)
return -17;
if (mapInfo[vvTried[n][i]].GetBucketPosition(nKey, false, n) != i)
return -18;
@@ -530,3 +537,30 @@ void CAddrMan::Connected_(const CService& addr, int64_t nTime)
int CAddrMan::RandomInt(int nMax){
return GetRandInt(nMax);
}
+
+std::vector CAddrMan::DecodeAsmap(fs::path path)
+{
+ std::vector bits;
+ FILE *filestr = fsbridge::fopen(path, "rb");
+ CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
+ if (file.IsNull()) {
+ LogPrintf("Failed to open asmap file from disk\n");
+ return bits;
+ }
+ fseek(filestr, 0, SEEK_END);
+ int length = ftell(filestr);
+ LogPrintf("Opened asmap file %s (%d bytes) from disk\n", path, length);
+ fseek(filestr, 0, SEEK_SET);
+ char cur_byte;
+ for (int i = 0; i < length; ++i) {
+ file >> cur_byte;
+ for (int bit = 0; bit < 8; ++bit) {
+ bits.push_back((cur_byte >> bit) & 1);
+ }
+ }
+ if (!SanityCheckASMap(bits)) {
+ LogPrintf("Sanity check of asmap file %s failed\n", path);
+ return {};
+ }
+ return bits;
+}
diff --git a/src/addrman.h b/src/addrman.h
index 0390b4e9b..752abb27c 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -1,6 +1,7 @@
// Copyright (c) 2012 Pieter Wuille
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
@@ -26,6 +27,10 @@
#include "sync.h"
#include "timedata.h"
#include "util.h"
+#include "fs.h"
+#include "clientversion.h"
+#include "hash.h"
+#include "netbase.h"
#include
#include
@@ -97,25 +102,25 @@ public:
}
//! Calculate in which "tried" bucket this entry belongs
- int GetTriedBucket(const uint256 &nKey) const;
+ int GetTriedBucket(const uint256 &nKey, const std::vector &asmap) const;
//! Calculate in which "new" bucket this entry belongs, given a certain source
- int GetNewBucket(const uint256 &nKey, const CNetAddr& src) const;
+ int GetNewBucket(const uint256 &nKey, const CNetAddr& src, const std::vector &asmap) const;
//! Calculate in which "new" bucket this entry belongs, using its default source
- int GetNewBucket(const uint256 &nKey) const
+ int GetNewBucket(const uint256 &nKey, const std::vector &asmap) const
{
- return GetNewBucket(nKey, source);
+ return GetNewBucket(nKey, source, asmap);
}
//! Calculate in which position of a bucket to store this entry.
int GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const;
//! Determine whether the statistics about this entry are bad enough so that it can just be deleted
- bool IsTerrible(int64_t nNow = GetAdjustedTime()) const;
+ bool IsTerrible(int64_t nNow = GetTime()) const;
//! Calculate the relative chance this entry should be given when selecting nodes to connect to
- double GetChance(int64_t nNow = GetAdjustedTime()) const;
+ double GetChance(int64_t nNow = GetTime()) const;
};
@@ -186,6 +191,7 @@ public:
*/
class CAddrMan
{
+friend class CAddrManTest;
private:
//! critical section to protect the inner data structures
mutable CCriticalSection cs;
@@ -264,9 +270,29 @@ protected:
void Connected_(const CService &addr, int64_t nTime);
public:
+ // Compressed IP->ASN mapping, loaded from a file when a node starts.
+ // Should be always empty if no file was provided.
+ // This mapping is then used for bucketing nodes in Addrman.
+ //
+ // If asmap is provided, nodes will be bucketed by
+ // AS they belong to, in order to make impossible for a node
+ // to connect to several nodes hosted in a single AS.
+ // This is done in response to Erebus attack, but also to generally
+ // diversify the connections every node creates,
+ // especially useful when a large fraction of nodes
+ // operate under a couple of cloud providers.
+ //
+ // If a new asmap was provided, the existing records
+ // would be re-bucketed accordingly.
+ std::vector m_asmap;
+
+ // Read asmap from provided binary file
+ static std::vector DecodeAsmap(fs::path path);
+
+
/**
* serialized format:
- * * version byte (currently 1)
+ * * version byte (1 for pre-asmap files, 2 for files including asmap version)
* * 0x20 + nKey (serialized as if it were a vector, for backward compatibility)
* * nNew
* * nTried
@@ -293,12 +319,12 @@ public:
* We don't use ADD_SERIALIZE_METHODS since the serialization and deserialization code has
* very little in common.
*/
- template
- void Serialize(Stream &s) const
+ template
+ void Serialize(Stream &s) const
{
LOCK(cs);
- unsigned char nVersion = 1;
+ unsigned char nVersion = 2;
s << nVersion;
s << ((unsigned char)32);
s << nKey;
@@ -309,9 +335,9 @@ public:
s << nUBuckets;
std::map mapUnkIds;
int nIds = 0;
- for (std::map::const_iterator it = mapInfo.begin(); it != mapInfo.end(); it++) {
- mapUnkIds[(*it).first] = nIds;
- const CAddrInfo &info = (*it).second;
+ for (const auto& entry : mapInfo) {
+ mapUnkIds[entry.first] = nIds;
+ const CAddrInfo &info = entry.second;
if (info.nRefCount) {
assert(nIds != nNew); // this means nNew was wrong, oh ow
s << info;
@@ -319,8 +345,8 @@ public:
}
}
nIds = 0;
- for (std::map::const_iterator it = mapInfo.begin(); it != mapInfo.end(); it++) {
- const CAddrInfo &info = (*it).second;
+ for (const auto& entry : mapInfo) {
+ const CAddrInfo &info = entry.second;
if (info.fInTried) {
assert(nIds != nTried); // this means nTried was wrong, oh ow
s << info;
@@ -341,6 +367,13 @@ public:
}
}
}
+ // Store asmap version after bucket entries so that it
+ // can be ignored by older clients for backward compatibility.
+ uint256 asmap_version;
+ if (m_asmap.size() != 0) {
+ asmap_version = SerializeHash(m_asmap);
+ }
+ s << asmap_version;
}
template
@@ -349,7 +382,6 @@ public:
LOCK(cs);
Clear();
-
unsigned char nVersion;
s >> nVersion;
unsigned char nKeySize;
@@ -379,16 +411,6 @@ public:
mapAddr[info] = n;
info.nRandomPos = vRandom.size();
vRandom.push_back(n);
- if (nVersion != 1 || nUBuckets != ADDRMAN_NEW_BUCKET_COUNT) {
- // In case the new table data cannot be used (nVersion unknown, or bucket count wrong),
- // immediately try to give them a reference based on their primary source address.
- int nUBucket = info.GetNewBucket(nKey);
- int nUBucketPos = info.GetBucketPosition(nKey, true, nUBucket);
- if (vvNew[nUBucket][nUBucketPos] == -1) {
- vvNew[nUBucket][nUBucketPos] = n;
- info.nRefCount++;
- }
- }
}
nIdCount = nNew;
@@ -397,7 +419,7 @@ public:
for (int n = 0; n < nTried; n++) {
CAddrInfo info;
s >> info;
- int nKBucket = info.GetTriedBucket(nKey);
+ int nKBucket = info.GetTriedBucket(nKey, m_asmap);
int nKBucketPos = info.GetBucketPosition(nKey, false, nKBucket);
if (vvTried[nKBucket][nKBucketPos] == -1) {
info.nRandomPos = vRandom.size();
@@ -413,7 +435,9 @@ public:
}
nTried -= nLost;
- // Deserialize positions in the new table (if possible).
+ // Store positions in the new table buckets to apply later (if possible).
+ std::map entryToBucket; // Represents which entry belonged to which bucket when serializing
+
for (int bucket = 0; bucket < nUBuckets; bucket++) {
int nSize = 0;
s >> nSize;
@@ -421,12 +445,38 @@ public:
int nIndex = 0;
s >> nIndex;
if (nIndex >= 0 && nIndex < nNew) {
- CAddrInfo &info = mapInfo[nIndex];
+ entryToBucket[nIndex] = bucket;
+ }
+ }
+ }
+
+ uint256 supplied_asmap_version;
+ if (m_asmap.size() != 0) {
+ supplied_asmap_version = SerializeHash(m_asmap);
+ }
+ uint256 serialized_asmap_version;
+ if (nVersion > 1) {
+ s >> serialized_asmap_version;
+ }
+
+ for (int n = 0; n < nNew; n++) {
+ CAddrInfo &info = mapInfo[n];
+ int bucket = entryToBucket[n];
int nUBucketPos = info.GetBucketPosition(nKey, true, bucket);
- if (nVersion == 1 && nUBuckets == ADDRMAN_NEW_BUCKET_COUNT && vvNew[bucket][nUBucketPos] == -1 && info.nRefCount < ADDRMAN_NEW_BUCKETS_PER_ADDRESS) {
+ if (nVersion == 2 && nUBuckets == ADDRMAN_NEW_BUCKET_COUNT && vvNew[bucket][nUBucketPos] == -1 &&
+ info.nRefCount < ADDRMAN_NEW_BUCKETS_PER_ADDRESS && serialized_asmap_version == supplied_asmap_version) {
+ // Bucketing has not changed, using existing bucket positions for the new table
+ vvNew[bucket][nUBucketPos] = n;
info.nRefCount++;
- vvNew[bucket][nUBucketPos] = nIndex;
- }
+ } else {
+ // In case the new table data cannot be used (nVersion unknown, bucket count wrong or new asmap),
+ // try to give them a reference based on their primary source address.
+ LogPrint("addrman", "Bucketing method was updated, re-bucketing addrman entries from disk\n");
+ bucket = info.GetNewBucket(nKey, m_asmap);
+ nUBucketPos = info.GetBucketPosition(nKey, true, bucket);
+ if (vvNew[bucket][nUBucketPos] == -1) {
+ vvNew[bucket][nUBucketPos] = n;
+ info.nRefCount++;
}
}
}
@@ -451,6 +501,7 @@ public:
void Clear()
{
+ LOCK(cs);
std::vector().swap(vRandom);
nKey = GetRandHash();
for (size_t bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
@@ -467,6 +518,8 @@ public:
nIdCount = 0;
nTried = 0;
nNew = 0;
+ mapInfo.clear();
+ mapAddr.clear();
}
CAddrMan()
@@ -530,7 +583,7 @@ public:
}
//! Mark an entry as accessible.
- void Good(const CService &addr, int64_t nTime = GetAdjustedTime())
+ void Good(const CService &addr, int64_t nTime = GetTime())
{
{
LOCK(cs);
@@ -541,7 +594,7 @@ public:
}
//! Mark an entry as connection attempted to.
- void Attempt(const CService &addr, int64_t nTime = GetAdjustedTime())
+ void Attempt(const CService &addr, int64_t nTime = GetTime())
{
{
LOCK(cs);
@@ -580,7 +633,7 @@ public:
}
//! Mark an entry as currently-connected-to.
- void Connected(const CService &addr, int64_t nTime = GetAdjustedTime())
+ void Connected(const CService &addr, int64_t nTime = GetTime())
{
{
LOCK(cs);
diff --git a/src/alert.cpp b/src/alert.cpp
index 99f6472e9..22300216c 100644
--- a/src/alert.cpp
+++ b/src/alert.cpp
@@ -1,7 +1,8 @@
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
@@ -117,7 +118,7 @@ uint256 CAlert::GetHash() const
bool CAlert::IsInEffect() const
{
- return (GetAdjustedTime() < nExpiration);
+ return (GetTime() < nExpiration);
}
bool CAlert::Cancels(const CAlert& alert) const
@@ -152,7 +153,7 @@ bool CAlert::RelayTo(CNode* pnode) const
{
if (AppliesTo(pnode->nVersion, pnode->strSubVer) ||
AppliesToMe() ||
- GetAdjustedTime() < nRelayUntil)
+ GetTime() < nRelayUntil)
{
pnode->PushMessage("alert", *this);
return true;
diff --git a/src/alert.h b/src/alert.h
index 16204c9c5..9f10d3781 100644
--- a/src/alert.h
+++ b/src/alert.h
@@ -1,7 +1,8 @@
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2013 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/alertkeys.h b/src/alertkeys.h
index 106576add..1c4bcbc2c 100644
--- a/src/alertkeys.h
+++ b/src/alertkeys.h
@@ -1,3 +1,4 @@
+// Copyright (c) 2019-2020 The Hush developers
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -16,7 +17,7 @@
#ifndef BITCOIN_ALERTKEYS_H
#define BITCOIN_ALERTKEYS_H
-// REMINDER: DO NOT COMMIT YOUR PRIVATE KEYS TO THE GIT REPOSITORY!
+// REMINDER: DO NOT COMMIT YOUR PRIVATE KEYS TO THE GIT REPOSITORY, lulz
const char* pszPrivKey = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
const char* pszTestNetPrivKey = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
diff --git a/src/amount.cpp b/src/amount.cpp
index 3feb37ccc..338a06dc5 100644
--- a/src/amount.cpp
+++ b/src/amount.cpp
@@ -1,7 +1,7 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/amount.h b/src/amount.h
index be1c39a6e..56eecf78f 100644
--- a/src/amount.h
+++ b/src/amount.h
@@ -1,7 +1,8 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/amqp/amqpabstractnotifier.cpp b/src/amqp/amqpabstractnotifier.cpp
deleted file mode 100644
index 57686ef1d..000000000
--- a/src/amqp/amqpabstractnotifier.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (c) 2017 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#include "amqpabstractnotifier.h"
-#include "util.h"
-
-
-AMQPAbstractNotifier::~AMQPAbstractNotifier()
-{
-}
-
-bool AMQPAbstractNotifier::NotifyBlock(const CBlockIndex * /*CBlockIndex*/)
-{
- return true;
-}
-
-bool AMQPAbstractNotifier::NotifyTransaction(const CTransaction &/*transaction*/)
-{
- return true;
-}
diff --git a/src/amqp/amqpabstractnotifier.h b/src/amqp/amqpabstractnotifier.h
deleted file mode 100644
index c993a2b3e..000000000
--- a/src/amqp/amqpabstractnotifier.h
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (c) 2017 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#ifndef ZCASH_AMQP_AMQPABSTRACTNOTIFIER_H
-#define ZCASH_AMQP_AMQPABSTRACTNOTIFIER_H
-
-#include "amqpconfig.h"
-
-class CBlockIndex;
-class AMQPAbstractNotifier;
-
-typedef AMQPAbstractNotifier* (*AMQPNotifierFactory)();
-
-class AMQPAbstractNotifier
-{
-public:
- AMQPAbstractNotifier() { }
- virtual ~AMQPAbstractNotifier();
-
- template
- static AMQPAbstractNotifier* Create()
- {
- return new T();
- }
-
- std::string GetType() const { return type; }
- void SetType(const std::string &t) { type = t; }
- std::string GetAddress() const { return address; }
- void SetAddress(const std::string &a) { address = a; }
-
- virtual bool Initialize() = 0;
- virtual void Shutdown() = 0;
-
- virtual bool NotifyBlock(const CBlockIndex *pindex);
- virtual bool NotifyTransaction(const CTransaction &transaction);
-
-protected:
- std::string type;
- std::string address;
-};
-
-#endif // ZCASH_AMQP_AMQPABSTRACTNOTIFIER_H
diff --git a/src/amqp/amqpconfig.h b/src/amqp/amqpconfig.h
deleted file mode 100644
index dcc5f7709..000000000
--- a/src/amqp/amqpconfig.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) 2017 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#ifndef ZCASH_AMQP_AMQPCONFIG_H
-#define ZCASH_AMQP_AMQPCONFIG_H
-
-#if defined(HAVE_CONFIG_H)
-#include "config/bitcoin-config.h"
-#endif
-
-#include
-#include
-
-#if ENABLE_PROTON
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#endif
-
-#include "primitives/block.h"
-#include "primitives/transaction.h"
-
-#endif // ZCASH_AMQP_AMQPCONFIG_H
diff --git a/src/amqp/amqpnotificationinterface.cpp b/src/amqp/amqpnotificationinterface.cpp
deleted file mode 100644
index 66f5398ca..000000000
--- a/src/amqp/amqpnotificationinterface.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (c) 2017 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#include "amqpnotificationinterface.h"
-#include "amqppublishnotifier.h"
-
-#include "version.h"
-#include "main.h"
-#include "streams.h"
-#include "util.h"
-
-// AMQP 1.0 Support
-//
-// The boost::signals2 signals and slot system is thread safe, so CValidationInterface listeners
-// can be invoked from any thread.
-//
-// Currently signals are fired from main.cpp so the callbacks should be invoked on the same thread.
-// It should be safe to share objects responsible for sending, as they should not be run concurrently
-// across different threads.
-//
-// Developers should be mindful of where notifications are fired to avoid potential race conditions.
-// For example, different signals targeting the same address could be fired from different threads
-// in different parts of the system around the same time.
-//
-// Like the ZMQ notification interface, if a notifier fails to send a message, the notifier is shut down.
-//
-
-AMQPNotificationInterface::AMQPNotificationInterface()
-{
-}
-
-AMQPNotificationInterface::~AMQPNotificationInterface()
-{
- Shutdown();
-
- for (std::list::iterator i = notifiers.begin(); i != notifiers.end(); ++i) {
- delete *i;
- }
-}
-
-AMQPNotificationInterface* AMQPNotificationInterface::CreateWithArguments(const std::map &args)
-{
- AMQPNotificationInterface* notificationInterface = nullptr;
- std::map factories;
- std::list notifiers;
-
- factories["pubhashblock"] = AMQPAbstractNotifier::Create;
- factories["pubhashtx"] = AMQPAbstractNotifier::Create;
- factories["pubrawblock"] = AMQPAbstractNotifier::Create;
- factories["pubrawtx"] = AMQPAbstractNotifier::Create;
-
- for (std::map::const_iterator i=factories.begin(); i!=factories.end(); ++i) {
- std::map::const_iterator j = args.find("-amqp" + i->first);
- if (j!=args.end()) {
- AMQPNotifierFactory factory = i->second;
- std::string address = j->second;
- AMQPAbstractNotifier *notifier = factory();
- notifier->SetType(i->first);
- notifier->SetAddress(address);
- notifiers.push_back(notifier);
- }
- }
-
- if (!notifiers.empty()) {
- notificationInterface = new AMQPNotificationInterface();
- notificationInterface->notifiers = notifiers;
-
- if (!notificationInterface->Initialize()) {
- delete notificationInterface;
- notificationInterface = nullptr;
- }
- }
-
- return notificationInterface;
-}
-
-// Called at startup to conditionally set up
-bool AMQPNotificationInterface::Initialize()
-{
- LogPrint("amqp", "amqp: Initialize notification interface\n");
-
- std::list::iterator i = notifiers.begin();
- for (; i != notifiers.end(); ++i) {
- AMQPAbstractNotifier *notifier = *i;
- if (notifier->Initialize()) {
- LogPrint("amqp", "amqp: Notifier %s ready (address = %s)\n", notifier->GetType(), notifier->GetAddress());
- } else {
- LogPrint("amqp", "amqp: Notifier %s failed (address = %s)\n", notifier->GetType(), notifier->GetAddress());
- break;
- }
- }
-
- if (i != notifiers.end()) {
- return false;
- }
-
- return true;
-}
-
-// Called during shutdown sequence
-void AMQPNotificationInterface::Shutdown()
-{
- LogPrint("amqp", "amqp: Shutdown notification interface\n");
-
- for (std::list::iterator i = notifiers.begin(); i != notifiers.end(); ++i) {
- AMQPAbstractNotifier *notifier = *i;
- notifier->Shutdown();
- }
-}
-
-void AMQPNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindex)
-{
- for (std::list::iterator i = notifiers.begin(); i != notifiers.end(); ) {
- AMQPAbstractNotifier *notifier = *i;
- if (notifier->NotifyBlock(pindex)) {
- i++;
- } else {
- notifier->Shutdown();
- i = notifiers.erase(i);
- }
- }
-}
-
-void AMQPNotificationInterface::SyncTransaction(const CTransaction &tx, const CBlock *pblock)
-{
- for (std::list::iterator i = notifiers.begin(); i != notifiers.end(); ) {
- AMQPAbstractNotifier *notifier = *i;
- if (notifier->NotifyTransaction(tx)) {
- i++;
- } else {
- notifier->Shutdown();
- i = notifiers.erase(i);
- }
- }
-}
diff --git a/src/amqp/amqpnotificationinterface.h b/src/amqp/amqpnotificationinterface.h
deleted file mode 100644
index 0c07ce235..000000000
--- a/src/amqp/amqpnotificationinterface.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (c) 2017 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#ifndef ZCASH_AMQP_AMQPNOTIFICATIONINTERFACE_H
-#define ZCASH_AMQP_AMQPNOTIFICATIONINTERFACE_H
-
-#include "validationinterface.h"
-#include
-#include
-
-class CBlockIndex;
-class AMQPAbstractNotifier;
-
-class AMQPNotificationInterface : public CValidationInterface
-{
-public:
- virtual ~AMQPNotificationInterface();
-
- static AMQPNotificationInterface* CreateWithArguments(const std::map &args);
-
-protected:
- bool Initialize();
- void Shutdown();
-
- // CValidationInterface
- void SyncTransaction(const CTransaction &tx, const CBlock *pblock);
- void UpdatedBlockTip(const CBlockIndex *pindex);
-
-private:
- AMQPNotificationInterface();
-
- std::list notifiers;
-};
-
-#endif // ZCASH_AMQP_AMQPNOTIFICATIONINTERFACE_H
diff --git a/src/amqp/amqppublishnotifier.cpp b/src/amqp/amqppublishnotifier.cpp
deleted file mode 100644
index 589eb151f..000000000
--- a/src/amqp/amqppublishnotifier.cpp
+++ /dev/null
@@ -1,177 +0,0 @@
-// Copyright (c) 2017 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#include "amqppublishnotifier.h"
-#include "main.h"
-#include "util.h"
-
-#include "amqpsender.h"
-
-#include
-#include
-
-static std::multimap mapPublishNotifiers;
-
-static const char *MSG_HASHBLOCK = "hashblock";
-static const char *MSG_HASHTX = "hashtx";
-static const char *MSG_RAWBLOCK = "rawblock";
-static const char *MSG_RAWTX = "rawtx";
-
-// Invoke this method from a new thread to run the proton container event loop.
-void AMQPAbstractPublishNotifier::SpawnProtonContainer()
-{
- try {
- proton::default_container(*handler_).run();
- }
- catch (const proton::error_condition &e) {
- LogPrint("amqp", "amqp: container error: %s\n", e.what());
- }
- catch (const std::runtime_error &e) {
- LogPrint("amqp", "amqp: runtime error: %s\n", e.what());
- }
- catch (const std::exception &e) {
- LogPrint("amqp", "amqp: exception: %s\n", e.what());
- }
- catch (...) {
- LogPrint("amqp", "amqp: unknown error\n");
- }
- handler_->terminate();
-}
-
-bool AMQPAbstractPublishNotifier::Initialize()
-{
- std::multimap::iterator i = mapPublishNotifiers.find(address);
-
- if (i == mapPublishNotifiers.end()) {
- try {
- handler_ = std::make_shared(address);
- thread_ = std::make_shared(&AMQPAbstractPublishNotifier::SpawnProtonContainer, this);
- }
- catch (std::exception &e) {
- LogPrint("amqp", "amqp: initialization error: %s\n", e.what());
- return false;
- }
- mapPublishNotifiers.insert(std::make_pair(address, this));
- } else {
- // copy the shared ptrs to the message handler and the thread where the proton container is running
- handler_ = i->second->handler_;
- thread_ = i->second->thread_;
- mapPublishNotifiers.insert(std::make_pair(address, this));
- }
-
- return true;
-}
-
-
-void AMQPAbstractPublishNotifier::Shutdown()
-{
- LogPrint("amqp", "amqp: Shutdown notifier %s at %s\n", GetType(), GetAddress());
-
- int count = mapPublishNotifiers.count(address);
-
- // remove this notifier from the list of publishers using this address
- typedef std::multimap::iterator iterator;
- std::pair iterpair = mapPublishNotifiers.equal_range(address);
-
- for (iterator it = iterpair.first; it != iterpair.second; ++it) {
- if (it->second == this) {
- mapPublishNotifiers.erase(it);
- break;
- }
- }
-
- // terminate the connection if this is the last publisher using this address
- if (count == 1) {
- handler_->terminate();
- if (thread_.get() != nullptr) {
- if (thread_->joinable()) {
- thread_->join();
- }
- }
- }
-}
-
-
-bool AMQPAbstractPublishNotifier::SendMessage(const char *command, const void* data, size_t size)
-{
- try {
- proton::binary content;
- const char *p = (const char *)data;
- content.assign(p, p + size);
-
- proton::message message(content);
- message.subject(std::string(command));
- proton::message::property_map & props = message.properties();
- props.put("x-opt-sequence-number", sequence_);
- handler_->publish(message);
-
- } catch (proton::error_condition &e) {
- LogPrint("amqp", "amqp: error : %s\n", e.what());
- return false;
- }
- catch (const std::runtime_error &e) {
- LogPrint("amqp", "amqp: runtime error: %s\n", e.what());
- return false;
- }
- catch (const std::exception &e) {
- LogPrint("amqp", "amqp: exception: %s\n", e.what());
- return false;
- }
- catch (...) {
- LogPrint("amqp", "amqp: unknown error\n");
- return false;
- }
-
- sequence_++;
-
- return true;
-}
-
-bool AMQPPublishHashBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
-{
- uint256 hash = pindex->GetBlockHash();
- LogPrint("amqp", "amqp: Publish hashblock %s\n", hash.GetHex());
- char data[32];
- for (unsigned int i = 0; i < 32; i++)
- data[31 - i] = hash.begin()[i];
- return SendMessage(MSG_HASHBLOCK, data, 32);
-}
-
-bool AMQPPublishHashTransactionNotifier::NotifyTransaction(const CTransaction &transaction)
-{
- uint256 hash = transaction.GetHash();
- LogPrint("amqp", "amqp: Publish hashtx %s\n", hash.GetHex());
- char data[32];
- for (unsigned int i = 0; i < 32; i++)
- data[31 - i] = hash.begin()[i];
- return SendMessage(MSG_HASHTX, data, 32);
-}
-
-bool AMQPPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
-{
- LogPrint("amqp", "amqp: Publish rawblock %s\n", pindex->GetBlockHash().GetHex());
-
- CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
- {
- LOCK(cs_main);
- CBlock block;
- if(!ReadBlockFromDisk(block, pindex)) {
- LogPrint("amqp", "amqp: Can't read block from disk");
- return false;
- }
-
- ss << block;
- }
-
- return SendMessage(MSG_RAWBLOCK, &(*ss.begin()), ss.size());
-}
-
-bool AMQPPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &transaction)
-{
- uint256 hash = transaction.GetHash();
- LogPrint("amqp", "amqp: Publish rawtx %s\n", hash.GetHex());
- CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
- ss << transaction;
- return SendMessage(MSG_RAWTX, &(*ss.begin()), ss.size());
-}
diff --git a/src/amqp/amqppublishnotifier.h b/src/amqp/amqppublishnotifier.h
deleted file mode 100644
index 08b3aba08..000000000
--- a/src/amqp/amqppublishnotifier.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2017 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#ifndef ZCASH_AMQP_AMQPPUBLISHNOTIFIER_H
-#define ZCASH_AMQP_AMQPPUBLISHNOTIFIER_H
-
-#include "amqpabstractnotifier.h"
-#include "amqpconfig.h"
-#include "amqpsender.h"
-
-#include
-#include
-
-class CBlockIndex;
-
-class AMQPAbstractPublishNotifier : public AMQPAbstractNotifier
-{
-private:
- uint64_t sequence_; // memory only, per notifier instance: upcounting message sequence number
-
- std::shared_ptr thread_; // proton container thread, may be shared between notifiers
- std::shared_ptr handler_; // proton container message handler, may be shared between notifiers
-
-public:
- bool SendMessage(const char *command, const void* data, size_t size);
- bool Initialize();
- void Shutdown();
- void SpawnProtonContainer();
-};
-
-class AMQPPublishHashBlockNotifier : public AMQPAbstractPublishNotifier
-{
-public:
- bool NotifyBlock(const CBlockIndex *pindex);
-};
-
-class AMQPPublishHashTransactionNotifier : public AMQPAbstractPublishNotifier
-{
-public:
- bool NotifyTransaction(const CTransaction &transaction);
-};
-
-class AMQPPublishRawBlockNotifier : public AMQPAbstractPublishNotifier
-{
-public:
- bool NotifyBlock(const CBlockIndex *pindex);
-};
-
-class AMQPPublishRawTransactionNotifier : public AMQPAbstractPublishNotifier
-{
-public:
- bool NotifyTransaction(const CTransaction &transaction);
-};
-
-#endif // ZCASH_AMQP_AMQPPUBLISHNOTIFIER_H
diff --git a/src/amqp/amqpsender.h b/src/amqp/amqpsender.h
deleted file mode 100644
index 7fa85d89c..000000000
--- a/src/amqp/amqpsender.h
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright (c) 2017 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#ifndef ZCASH_AMQP_AMQPSENDER_H
-#define ZCASH_AMQP_AMQPSENDER_H
-
-#include "amqpconfig.h"
-
-#include
-#include
-#include
-#include
-
-class AMQPSender : public proton::messaging_handler {
- private:
- std::deque messages_;
- proton::url url_;
- proton::connection conn_;
- proton::sender sender_;
- std::mutex lock_;
- std::atomic terminated_ = {false};
-
- public:
-
- AMQPSender(const std::string& url) : url_(url) {}
-
- // Callback to initialize the container when run() is invoked
- void on_container_start(proton::container& c) override {
- proton::duration t(10000); // milliseconds
- proton::connection_options opts = proton::connection_options().idle_timeout(t);
- conn_ = c.connect(url_, opts);
- sender_ = conn_.open_sender(url_.path());
- }
-
- // Remote end signals when the local end can send (i.e. has credit)
- void on_sendable(proton::sender &s) override {
- dispatch();
- }
-
- // Publish message by adding to queue and trying to dispatch it
- void publish(const proton::message &m) {
- add_message(m);
- dispatch();
- }
-
- // Add message to queue
- void add_message(const proton::message &m) {
- std::lock_guard guard(lock_);
- messages_.push_back(m);
- }
-
- // Send messages in queue
- void dispatch() {
- std::lock_guard guard(lock_);
-
- if (isTerminated()) {
- throw std::runtime_error("amqp connection was terminated");
- }
-
- if (!conn_.active()) {
- throw std::runtime_error("amqp connection is not active");
- }
-
- while (messages_.size() > 0) {
- if (sender_.credit()) {
- const proton::message& m = messages_.front();
- sender_.send(m);
- messages_.pop_front();
- } else {
- break;
- }
- }
- }
-
- // Close connection to remote end. Container event-loop, by default, will auto-stop.
- void terminate() {
- std::lock_guard guard(lock_);
- conn_.close();
- terminated_.store(true);
- }
-
- bool isTerminated() const {
- return terminated_.load();
- }
-
- void on_transport_error(proton::transport &t) override {
- t.connection().close();
- throw t.error();
- }
-
- void on_connection_error(proton::connection &c) override {
- c.close();
- throw c.error();
- }
-
- void on_session_error(proton::session &s) override {
- s.connection().close();
- throw s.error();
- }
-
- void on_receiver_error(proton::receiver &r) override {
- r.connection().close();
- throw r.error();
- }
-
- void on_sender_error(proton::sender &s) override {
- s.connection().close();
- throw s.error();
- }
-
-};
-
-
-#endif //ZCASH_AMQP_AMQPSENDER_H
diff --git a/src/arith_uint256.cpp b/src/arith_uint256.cpp
index d7a5c0afe..e0e25011e 100644
--- a/src/arith_uint256.cpp
+++ b/src/arith_uint256.cpp
@@ -1,7 +1,7 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/arith_uint256.h b/src/arith_uint256.h
index b51f82f14..437b95c74 100644
--- a/src/arith_uint256.h
+++ b/src/arith_uint256.h
@@ -1,7 +1,8 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/asyncrpcoperation.cpp b/src/asyncrpcoperation.cpp
index 75c8da9e6..47aae3b82 100644
--- a/src/asyncrpcoperation.cpp
+++ b/src/asyncrpcoperation.cpp
@@ -1,7 +1,7 @@
// Copyright (c) 2016 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
diff --git a/src/asyncrpcoperation.h b/src/asyncrpcoperation.h
index 3fe966977..9a6b7c48b 100644
--- a/src/asyncrpcoperation.h
+++ b/src/asyncrpcoperation.h
@@ -1,6 +1,7 @@
// Copyright (c) 2016 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/asyncrpcqueue.cpp b/src/asyncrpcqueue.cpp
index 5bcb20f8d..529667508 100644
--- a/src/asyncrpcqueue.cpp
+++ b/src/asyncrpcqueue.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2016 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/asyncrpcqueue.h b/src/asyncrpcqueue.h
index 0d228564f..b39d682d6 100644
--- a/src/asyncrpcqueue.h
+++ b/src/asyncrpcqueue.h
@@ -1,6 +1,7 @@
// Copyright (c) 2016 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/base58.cpp b/src/base58.cpp
index 383666d82..d46894ea0 100644
--- a/src/base58.cpp
+++ b/src/base58.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/base58.h b/src/base58.h
index 8be0247e0..48badc597 100644
--- a/src/base58.h
+++ b/src/base58.h
@@ -1,7 +1,7 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/bech32.cpp b/src/bech32.cpp
index 78c35b976..d42a40d74 100644
--- a/src/bech32.cpp
+++ b/src/bech32.cpp
@@ -1,6 +1,7 @@
// Copyright (c) 2017 Pieter Wuille
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include "bech32.h"
diff --git a/src/bech32.h b/src/bech32.h
index 2e2823e97..081fd2f46 100644
--- a/src/bech32.h
+++ b/src/bech32.h
@@ -1,8 +1,9 @@
// Copyright (c) 2017 Pieter Wuille
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
-// Bech32 is a string encoding format used in newer address types.
+// Bech32 is a string encoding format used in Sapling zaddrs
// The output consists of a human-readable part (alphanumeric), a
// separator character (1), and a base32 data section, the last
// 6 characters of which are a checksum.
diff --git a/src/bitcoin-cli-res.rc b/src/bitcoin-cli-res.rc
index 3e46f5a16..c2149ad24 100644
--- a/src/bitcoin-cli-res.rc
+++ b/src/bitcoin-cli-res.rc
@@ -16,12 +16,12 @@ BEGIN
BEGIN
BLOCK "040904E4" // U.S. English - multilingual (hex)
BEGIN
- VALUE "CompanyName", "Komodo"
- VALUE "FileDescription", "komodo-cli (JSON-RPC client for Komodo)"
+ VALUE "CompanyName", "Hush"
+ VALUE "FileDescription", "komodo-cli (JSON-RPC client for Hush-flavored Komodo)"
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", "komodo-cli"
VALUE "LegalCopyright", COPYRIGHT_STR
- VALUE "LegalTrademarks1", "Distributed under the MIT software license, see the accompanying file COPYING or http://www.opensource.org/licenses/mit-license.php."
+ VALUE "LegalTrademarks1", "Distributed under the GPLv3 software license, see the accompanying file COPYING or https://www.opensource.org/licenses/mit-license.php"
VALUE "OriginalFilename", "komodo-cli.exe"
VALUE "ProductName", "komodo-cli"
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index 544972586..aaafcc0cc 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -1,7 +1,8 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2013 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
@@ -101,12 +102,12 @@ static int AppInitRPC(int argc, char* argv[])
strncpy(ASSETCHAINS_SYMBOL,name.c_str(),sizeof(ASSETCHAINS_SYMBOL)-1);
if (argc<2 || mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version")) {
- std::string strUsage = _("Komodo RPC client version") + " " + FormatFullVersion() + "\n" + PrivacyInfo();
+ std::string strUsage = _("Hush RPC client version") + " " + FormatFullVersion() + "\n" + PrivacyInfo();
if (!mapArgs.count("-version")) {
strUsage += "\n" + _("Usage:") + "\n" +
- " komodo-cli [options] [params] " + _("Send command to Komodo") + "\n" +
- " komodo-cli [options] help " + _("List commands") + "\n" +
- " komodo-cli [options] help " + _("Get help for a command") + "\n";
+ " hush-cli [options] [params] " + _("Send command to Hush") + "\n" +
+ " hush-cli [options] help " + _("List commands") + "\n" +
+ " hush-cli [options] help " + _("Get help for a command") + "\n";
strUsage += "\n" + HelpMessageCli();
} else {
diff --git a/src/bitcoin-tx-res.rc b/src/bitcoin-tx-res.rc
index cb540fdc1..53ce67942 100644
--- a/src/bitcoin-tx-res.rc
+++ b/src/bitcoin-tx-res.rc
@@ -21,7 +21,7 @@ BEGIN
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", "hush-tx"
VALUE "LegalCopyright", COPYRIGHT_STR
- VALUE "LegalTrademarks1", "Distributed under the MIT software license, see the accompanying file COPYING or http://www.opensource.org/licenses/mit-license.php."
+ VALUE "LegalTrademarks1", "Distributed under the GPLv3 software license, see the accompanying file COPYING or https://www.opensource.org/licenses/mit-license.php"
VALUE "OriginalFilename", "hush-tx.exe"
VALUE "ProductName", "hush-tx"
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
diff --git a/src/bitcoind-res.rc b/src/bitcoind-res.rc
index 246ba98ac..c72d3769a 100644
--- a/src/bitcoind-res.rc
+++ b/src/bitcoind-res.rc
@@ -21,7 +21,7 @@ BEGIN
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", "komodod"
VALUE "LegalCopyright", COPYRIGHT_STR
- VALUE "LegalTrademarks1", "Distributed under the MIT software license, see the accompanying file COPYING or http://www.opensource.org/licenses/mit-license.php."
+ VALUE "LegalTrademarks1", "Distributed under the GPLv3 software license, see the accompanying file COPYING or https://www.opensource.org/licenses/mit-license.php"
VALUE "OriginalFilename", "komodod.exe"
VALUE "ProductName", "komodod"
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
index f8dac619b..f8531b2cc 100644
--- a/src/bitcoind.cpp
+++ b/src/bitcoind.cpp
@@ -1,8 +1,8 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2013 The Bitcoin Core developers
// Copyright (c) 2019 The Hush developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
@@ -50,7 +50,7 @@
* which enables instant payments to anyone, anywhere in the world. Bitcoin uses peer-to-peer technology to operate
* with no central authority: managing transactions and issuing money are carried out collectively by the network.
*
- * The software is a community-driven open source project, released under the MIT license.
+ * The software is a community-driven open source project, released under the GPLv3 license.
*
* \section Navigation
* Use the buttons Namespaces, Classes or Files at the top of the page to start navigating the code.
diff --git a/src/bloom.cpp b/src/bloom.cpp
index d7a7742fe..51c06cba5 100644
--- a/src/bloom.cpp
+++ b/src/bloom.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2012-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/bloom.h b/src/bloom.h
index e4677d6d0..69e507943 100644
--- a/src/bloom.h
+++ b/src/bloom.h
@@ -1,6 +1,6 @@
// Copyright (c) 2012-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/cc/Makefile_custom b/src/cc/Makefile_custom
old mode 100755
new mode 100644
index 79219ec96..3989eefa3
--- a/src/cc/Makefile_custom
+++ b/src/cc/Makefile_custom
@@ -2,6 +2,7 @@ SHELL = /bin/sh
CC = gcc
CC_DARWIN = g++-8
CC_WIN = x86_64-w64-mingw32-gcc-posix
+CC_AARCH64 = aarch64-linux-gnu-g++
CFLAGS_DARWIN = -DBUILD_CUSTOMCC -std=c++11 -arch x86_64 -I../secp256k1/include -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -Wl,-undefined -Wl,dynamic_lookup -Wno-write-strings -shared -dynamiclib
CFLAGS = -Wno-write-strings -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared
CFLAGS_WIN = -Wno-write-strings -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../../depends/x86_64-w64-mingw32/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared
@@ -28,6 +29,10 @@ else ifeq ($(HOST),x86_64-w64-mingw32)
$(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) -c $(SOURCES)
cp $(TARGET_WIN) ../libcc.dll
#else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host
+else ifeq ($(HOST),aarch64-linux-gnu)
+ $(info LINUX ARM 64bit )
+ $(CC_AARCH64) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) -c $(SOURCES)
+ cp $(TARGET) ../libcc.so
else
$(info LINUX)
$(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) -c $(SOURCES)
diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp
index 364953148..67440f3da 100644
--- a/src/cc/cclib.cpp
+++ b/src/cc/cclib.cpp
@@ -1,3 +1,4 @@
+// Copyright © 2019-2020 The Hush Developers
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
diff --git a/src/cc/dapps/Makefile b/src/cc/dapps/Makefile
index 6e7874788..1fea27084 100644
--- a/src/cc/dapps/Makefile
+++ b/src/cc/dapps/Makefile
@@ -1,6 +1,10 @@
+# Copyright 2020 The Hush Developers
# just type make to compile all dapps
all: zmigrate oraclefeed
+subatomic:
+ $(CC) subatomic.c -o subatomic -lm
+
zmigrate:
$(CC) zmigrate.c -o zmigrate -lm
@@ -9,3 +13,4 @@ oraclefeed:
clean:
rm zmigrate oraclefeed
+
diff --git a/src/cc/dapps/dappinc.h b/src/cc/dapps/dappinc.h
new file mode 100644
index 000000000..3c71dfdec
--- /dev/null
+++ b/src/cc/dapps/dappinc.h
@@ -0,0 +1,1599 @@
+/******************************************************************************
+ * Copyright © 2014-2020 The SuperNET Developers. *
+ * *
+ * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
+ * the top-level directory of this distribution for the individual copyright *
+ * holder information and the developer policies on copyright and licensing. *
+ * *
+ * Unless otherwise agreed in a custom licensing agreement, no part of the *
+ * SuperNET software, including this file may be copied, modified, propagated *
+ * or distributed except according to the terms contained in the LICENSE file *
+ * *
+ * Removal or modification of this copyright notice is prohibited. *
+ * *
+ ******************************************************************************/
+
+#include
+#include
+#include
+#include
+#include "cJSON.c"
+
+bits256 zeroid;
+
+int32_t unstringbits(char *buf,uint64_t bits)
+{
+ int32_t i;
+ for (i=0; i<8; i++,bits>>=8)
+ if ( (buf[i]= (char)(bits & 0xff)) == 0 )
+ break;
+ buf[i] = 0;
+ return(i);
+}
+
+uint64_t stringbits(char *str)
+{
+ uint64_t bits = 0;
+ if ( str == 0 )
+ return(0);
+ int32_t i,n = (int32_t)strlen(str);
+ if ( n > 8 )
+ n = 8;
+ for (i=n-1; i>=0; i--)
+ bits = (bits << 8) | (str[i] & 0xff);
+ //printf("(%s) -> %llx %llu\n",str,(long long)bits,(long long)bits);
+ return(bits);
+}
+
+char hexbyte(int32_t c)
+{
+ c &= 0xf;
+ if ( c < 10 )
+ return('0'+c);
+ else if ( c < 16 )
+ return('a'+c-10);
+ else return(0);
+}
+
+int32_t _unhex(char c)
+{
+ if ( c >= '0' && c <= '9' )
+ return(c - '0');
+ else if ( c >= 'a' && c <= 'f' )
+ return(c - 'a' + 10);
+ else if ( c >= 'A' && c <= 'F' )
+ return(c - 'A' + 10);
+ return(-1);
+}
+
+int32_t is_hexstr(char *str,int32_t n)
+{
+ int32_t i;
+ if ( str == 0 || str[0] == 0 )
+ return(0);
+ for (i=0; str[i]!=0; i++)
+ {
+ if ( n > 0 && i >= n )
+ break;
+ if ( _unhex(str[i]) < 0 )
+ break;
+ }
+ if ( n == 0 )
+ return(i);
+ return(i == n);
+}
+
+int32_t unhex(char c)
+{
+ int32_t hex;
+ if ( (hex= _unhex(c)) < 0 )
+ {
+ //printf("unhex: illegal hexchar.(%c)\n",c);
+ }
+ return(hex);
+}
+
+unsigned char _decode_hex(char *hex) { return((unhex(hex[0])<<4) | unhex(hex[1])); }
+
+int32_t decode_hex(unsigned char *bytes,int32_t n,char *hex)
+{
+ int32_t adjust,i = 0;
+ //printf("decode.(%s)\n",hex);
+ if ( is_hexstr(hex,n) <= 0 )
+ {
+ memset(bytes,0,n);
+ return(n);
+ }
+ if ( hex[n-1] == '\n' || hex[n-1] == '\r' )
+ hex[--n] = 0;
+ if ( hex[n-1] == '\n' || hex[n-1] == '\r' )
+ hex[--n] = 0;
+ if ( n == 0 || (hex[n*2+1] == 0 && hex[n*2] != 0) )
+ {
+ if ( n > 0 )
+ {
+ bytes[0] = unhex(hex[0]);
+ printf("decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex));
+ }
+ bytes++;
+ hex++;
+ adjust = 1;
+ } else adjust = 0;
+ if ( n > 0 )
+ {
+ for (i=0; i>4) & 0xf);
+ hexbytes[i*2 + 1] = hexbyte(message[i] & 0xf);
+ //printf("i.%d (%02x) [%c%c]\n",i,message[i],hexbytes[i*2],hexbytes[i*2+1]);
+ }
+ hexbytes[len*2] = 0;
+ //printf("len.%ld\n",len*2+1);
+ return((int32_t)len*2+1);
+}
+
+long _stripwhite(char *buf,int accept)
+{
+ int32_t i,j,c;
+ if ( buf == 0 || buf[0] == 0 )
+ return(0);
+ for (i=j=0; buf[i]!=0; i++)
+ {
+ buf[j] = c = buf[i];
+ if ( c == accept || (c != ' ' && c != '\n' && c != '\r' && c != '\t' && c != '\b') )
+ j++;
+ }
+ buf[j] = 0;
+ return(j);
+}
+
+char *clonestr(char *str)
+{
+ char *clone;
+ if ( str == 0 || str[0]==0)
+ {
+ printf("warning cloning nullstr.%p\n",str);
+ //#ifdef __APPLE__
+ // while ( 1 ) sleep(1);
+ //#endif
+ str = (char *)"";
+ }
+ clone = (char *)malloc(strlen(str)+16);
+ strcpy(clone,str);
+ return(clone);
+}
+
+int32_t safecopy(char *dest,char *src,long len)
+{
+ int32_t i = -1;
+ if ( src != 0 && dest != 0 && src != dest )
+ {
+ if ( dest != 0 )
+ memset(dest,0,len);
+ for (i=0; i0; i--)
+ str[i] = str[i-1];
+ str[0] = '/';
+ str[n+1] = 0;
+ }*/
+#endif
+ return(str);
+#endif
+}
+
+void *loadfile(char *fname,uint8_t **bufp,long *lenp,long *allocsizep)
+{
+ FILE *fp;
+ long filesize,buflen = *allocsizep;
+ uint8_t *buf = *bufp;
+ *lenp = 0;
+ if ( (fp= fopen(portable_path(fname),"rb")) != 0 )
+ {
+ fseek(fp,0,SEEK_END);
+ filesize = ftell(fp);
+ if ( filesize == 0 )
+ {
+ fclose(fp);
+ *lenp = 0;
+ //printf("loadfile null size.(%s)\n",fname);
+ return(0);
+ }
+ if ( filesize > buflen )
+ {
+ *allocsizep = filesize;
+ *bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep+64);
+ }
+ rewind(fp);
+ if ( buf == 0 )
+ printf("Null buf ???\n");
+ else
+ {
+ if ( fread(buf,1,(long)filesize,fp) != (unsigned long)filesize )
+ printf("error reading filesize.%ld\n",(long)filesize);
+ buf[filesize] = 0;
+ }
+ fclose(fp);
+ *lenp = filesize;
+ //printf("loaded.(%s)\n",buf);
+ } //else printf("OS_loadfile couldnt load.(%s)\n",fname);
+ return(buf);
+}
+
+void *filestr(long *allocsizep,char *_fname)
+{
+ long filesize = 0; char *fname,*buf = 0; void *retptr;
+ *allocsizep = 0;
+ fname = malloc(strlen(_fname)+1);
+ strcpy(fname,_fname);
+ retptr = loadfile(fname,(uint8_t **)&buf,&filesize,allocsizep);
+ free(fname);
+ return(retptr);
+}
+
+char *send_curl(char *url,char *fname)
+{
+ long fsize; char curlstr[1024];
+ sprintf(curlstr,"curl --url \"%s\" > %s",url,fname);
+ system(curlstr);
+ return(filestr(&fsize,fname));
+}
+
+cJSON *get_urljson(char *url,char *fname)
+{
+ char *jsonstr; cJSON *json = 0;
+ if ( (jsonstr= send_curl(url,fname)) != 0 )
+ {
+ //printf("(%s) -> (%s)\n",url,jsonstr);
+ json = cJSON_Parse(jsonstr);
+ free(jsonstr);
+ }
+ return(json);
+}
+
+//////////////////////////////////////////////
+// start of dapp
+//////////////////////////////////////////////
+int md_unlink(char *file)
+{
+#ifdef _WIN32
+ _chmod(file, 0600);
+ return( _unlink(file) );
+#else
+ return(unlink(file));
+#endif
+}
+
+char *REFCOIN_CLI,DPOW_pubkeystr[67],DPOW_secpkeystr[67],DPOW_handle[67],DPOW_recvaddr[64],DPOW_recvZaddr[128];
+
+cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char *arg0,char *arg1,char *arg2,char *arg3,char *arg4,char *arg5,char *arg6)
+{
+ long fsize; cJSON *retjson = 0; char cmdstr[32768],*jsonstr,fname[32768];
+ sprintf(fname,"/tmp/notarizer_%s_%d",method,(rand() >> 17) % 10000);
+ //if ( (acname == 0 || acname[0] == 0) && strcmp(refcoin,"KMD") != 0 )
+ // acname = refcoin;
+ if ( acname[0] != 0 )
+ {
+ if ( refcoin[0] != 0 && strcmp(refcoin,"KMD") != 0 && strcmp(refcoin,acname) != 0 )
+ printf("unexpected: refcoin.(%s) acname.(%s)\n",refcoin,acname);
+ sprintf(cmdstr,"komodo-cli -ac_name=%s %s %s %s %s %s %s %s %s > %s\n",acname,method,arg0,arg1,arg2,arg3,arg4,arg5,arg6,fname);
+ }
+ else if ( strcmp(refcoin,"KMD") == 0 )
+ sprintf(cmdstr,"komodo-cli %s %s %s %s %s %s %s %s > %s\n",method,arg0,arg1,arg2,arg3,arg4,arg5,arg6,fname);
+ else if ( REFCOIN_CLI != 0 && REFCOIN_CLI[0] != 0 )
+ {
+ sprintf(cmdstr,"%s %s %s %s %s %s %s %s %s > %s\n",REFCOIN_CLI,method,arg0,arg1,arg2,arg3,arg4,arg5,arg6,fname);
+ //printf("ref.(%s) REFCOIN_CLI (%s)\n",refcoin,cmdstr);
+ }
+//fprintf(stderr,"system(%s)\n",cmdstr);
+ system(cmdstr);
+ *retstrp = 0;
+ if ( (jsonstr= filestr(&fsize,fname)) != 0 )
+ {
+ jsonstr[strlen(jsonstr)-1]='\0';
+ //fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr);
+ if ( (jsonstr[0] != '{' && jsonstr[0] != '[') || (retjson= cJSON_Parse(jsonstr)) == 0 )
+ *retstrp = jsonstr;
+ else free(jsonstr);
+ md_unlink(fname);
+ } //else fprintf(stderr,"system(%s) -> NULL\n",cmdstr);
+ return(retjson);
+}
+
+cJSON *subatomic_cli(char *clistr,char **retstrp,char *method,char *arg0,char *arg1,char *arg2,char *arg3,char *arg4,char *arg5,char *arg6)
+{
+ long fsize; cJSON *retjson = 0; char cmdstr[32768],*jsonstr,fname[32768];
+ sprintf(fname,"/tmp/subatomic_%s_%d",method,(rand() >> 17) % 10000);
+ sprintf(cmdstr,"%s %s %s %s %s %s %s %s %s > %s\n",clistr,method,arg0,arg1,arg2,arg3,arg4,arg5,arg6,fname);
+//fprintf(stderr,"system(%s)\n",cmdstr);
+ system(cmdstr);
+ *retstrp = 0;
+ if ( (jsonstr= filestr(&fsize,fname)) != 0 )
+ {
+ jsonstr[strlen(jsonstr)-1]='\0';
+ //fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr);
+ if ( (jsonstr[0] != '{' && jsonstr[0] != '[') || (retjson= cJSON_Parse(jsonstr)) == 0 )
+ *retstrp = jsonstr;
+ else free(jsonstr);
+ md_unlink(fname);
+ } //else fprintf(stderr,"system(%s) -> NULL\n",cmdstr);
+ return(retjson);
+}
+
+bits256 komodobroadcast(char *refcoin,char *acname,cJSON *hexjson)
+{
+ char *hexstr,*retstr,str[65]; cJSON *retjson; bits256 txid;
+ memset(txid.bytes,0,sizeof(txid));
+ if ( (hexstr= jstr(hexjson,"hex")) != 0 )
+ {
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendrawtransaction",hexstr,"","","","","","")) != 0 )
+ {
+ //fprintf(stderr,"broadcast.(%s)\n",jprint(retjson,0));
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ if ( strlen(retstr) >= 64 )
+ {
+ retstr[64] = 0;
+ decode_hex(txid.bytes,32,retstr);
+ }
+ fprintf(stderr,"broadcast %s txid.(%s)\n",strlen(acname)>0?acname:refcoin,bits256_str(str,txid));
+ free(retstr);
+ }
+ }
+ return(txid);
+}
+
+bits256 sendtoaddress(char *refcoin,char *acname,char *destaddr,int64_t satoshis,char *oprethexstr)
+{
+ char numstr[32],*retstr,str[65]; cJSON *retjson; bits256 txid;
+ memset(txid.bytes,0,sizeof(txid));
+ sprintf(numstr,"%.8f",(double)satoshis/SATOSHIDEN);
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendtoaddress",destaddr,numstr,"false","","",oprethexstr,"")) != 0 )
+ {
+ fprintf(stderr,"unexpected sendrawtransaction json.(%s)\n",jprint(retjson,0));
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ if ( strlen(retstr) >= 64 )
+ {
+ retstr[64] = 0;
+ decode_hex(txid.bytes,32,retstr);
+ }
+ fprintf(stderr,"sendtoaddress %s %.8f txid.(%s)\n",destaddr,(double)satoshis/SATOSHIDEN,bits256_str(str,txid));
+ free(retstr);
+ }
+ return(txid);
+}
+
+bits256 tokentransfer(char *refcoin,char *acname,char *tokenid,char *destpub,int64_t units)
+{
+ char numstr[32],*retstr,str[65]; cJSON *retjson; bits256 txid;
+ memset(txid.bytes,0,sizeof(txid));
+ sprintf(numstr,"%llu",(long long)units);
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"tokentransfer",tokenid,destpub,numstr,"","","","")) != 0 )
+ {
+ txid = komodobroadcast(refcoin,acname,retjson);
+ fprintf(stderr,"tokentransfer returned (%s)\n",jprint(retjson,0));
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"tokentransfer.(%s) error.(%s)\n",acname,retstr);
+ free(retstr);
+ }
+ return(txid);
+}
+
+char *get_tokenaddress(char *refcoin,char *acname,char *tokenaddr)
+{
+ char *retstr,*str; cJSON *retjson;
+ tokenaddr[0] = 0;
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"tokenaddress","","","","","","","")) != 0 )
+ {
+ if ( (str= jstr(retjson,"myCCAddress(Tokens)")) != 0 )
+ {
+ strcpy(tokenaddr,str);
+ fprintf(stderr,"tokenaddress returned (%s)\n",tokenaddr);
+ free_json(retjson);
+ return(tokenaddr);
+ }
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ //fprintf(stderr,"tokentransfer.(%s) error.(%s)\n",acname,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+int64_t get_tokenbalance(char *refcoin,char *acname,char *tokenid)
+{
+ cJSON *retjson; char *retstr,cmpstr[64]; int64_t amount=0;
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"tokenbalance",tokenid,"","","","","","")) != 0 )
+ {
+ amount = j64bits(retjson,"balance");
+ fprintf(stderr,"tokenbalance %llu\n",(long long)amount);
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ //printf("retstr %s -> %.8f\n",retstr,dstr(amount));
+ free(retstr);
+ }
+ return (amount);
+}
+
+cJSON *get_decodescript(char *refcoin,char *acname,char *script)
+{
+ cJSON *retjson; char *retstr;
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"decodescript",script,"","","","","","")) != 0 )
+ {
+ return(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"get_decodescript.(%s) error.(%s)\n",acname,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+char *get_createmultisig2(char *refcoin,char *acname,char *msigaddr,char *redeemscript,char *pubkeyA,char *pubkeyB)
+{
+ //char para 2 '["02c3af47b51a506b08b4ededb156cb4c3f9db9e0ac7ad27b8623c08a056fdcc220", "038e61fbface549a850862f12ed99b7cbeef5c2bd2d8f1daddb34809416f0259e1"]'
+ cJSON *retjson; char *retstr,*str,params[256]; int32_t height=0;
+ msigaddr[0] = 0;
+ redeemscript[0] = 0;
+ sprintf(params,"'[\"%s\", \"%s\"]'",pubkeyA,pubkeyB);
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"createmultisig","2",params,"","","","","")) != 0 )
+ {
+ if ( (str= jstr(retjson,"address")) != 0 )
+ strcpy(msigaddr,str);
+ if ( (str= jstr(retjson,"redeemScript")) != 0 )
+ strcpy(redeemscript,str);
+ free_json(retjson);
+ if ( msigaddr[0] != 0 && redeemscript[0] != 0 )
+ return(msigaddr);
+ else return(0);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"%s get_createmultisig2.(%s) error.(%s)\n",refcoin,acname,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+int32_t get_coinheight(char *refcoin,char *acname,bits256 *blockhashp)
+{
+ cJSON *retjson; char *retstr; int32_t height=0;
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockchaininfo","","","","","","","")) != 0 )
+ {
+ height = jint(retjson,"blocks");
+ *blockhashp = jbits256(retjson,"bestblockhash");
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"%s get_coinheight.(%s) error.(%s)\n",refcoin,acname,retstr);
+ free(retstr);
+ }
+ return(height);
+}
+
+bits256 get_coinblockhash(char *refcoin,char *acname,int32_t height)
+{
+ cJSON *retjson; char *retstr,heightstr[32]; bits256 hash;
+ memset(hash.bytes,0,sizeof(hash));
+ sprintf(heightstr,"%d",height);
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockhash",heightstr,"","","","","","")) != 0 )
+ {
+ fprintf(stderr,"unexpected blockhash json.(%s)\n",jprint(retjson,0));
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ if ( strlen(retstr) >= 64 )
+ {
+ retstr[64] = 0;
+ decode_hex(hash.bytes,32,retstr);
+ }
+ free(retstr);
+ }
+ return(hash);
+}
+
+bits256 get_coinmerkleroot(char *refcoin,char *acname,bits256 blockhash,uint32_t *blocktimep)
+{
+ cJSON *retjson; char *retstr,str[65]; bits256 merkleroot;
+ memset(merkleroot.bytes,0,sizeof(merkleroot));
+ *blocktimep = 0;
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockheader",bits256_str(str,blockhash),"","","","","","")) != 0 )
+ {
+ merkleroot = jbits256(retjson,"merkleroot");
+ *blocktimep = juint(retjson,"time");
+ //fprintf(stderr,"got merkleroot.(%s)\n",bits256_str(str,merkleroot));
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"%s %s get_coinmerkleroot error.(%s)\n",refcoin,acname,retstr);
+ free(retstr);
+ }
+ return(merkleroot);
+}
+
+uint32_t get_heighttime(char *refcoin,char *acname,int32_t height)
+{
+ bits256 blockhash; uint32_t blocktime;
+ blockhash = get_coinblockhash(refcoin,acname,height);
+ get_coinmerkleroot(refcoin,acname,blockhash,&blocktime);
+ return(blocktime);
+}
+
+int32_t get_coinheader(char *refcoin,char *acname,bits256 *blockhashp,bits256 *merklerootp,int32_t prevheight)
+{
+ int32_t height = 0; char str[65]; bits256 bhash; uint32_t blocktime;
+ if ( prevheight == 0 )
+ height = get_coinheight(refcoin,acname,&bhash) - 20;
+ else height = prevheight + 1;
+ if ( height > 0 )
+ {
+ *blockhashp = get_coinblockhash(refcoin,acname,height);
+ if ( bits256_nonz(*blockhashp) != 0 )
+ {
+ *merklerootp = get_coinmerkleroot(refcoin,acname,*blockhashp,&blocktime);
+ if ( bits256_nonz(*merklerootp) != 0 )
+ return(height);
+ }
+ }
+ memset(blockhashp,0,sizeof(*blockhashp));
+ memset(merklerootp,0,sizeof(*merklerootp));
+ return(0);
+}
+
+cJSON *get_rawmempool(char *refcoin,char *acname)
+{
+ cJSON *retjson; char *retstr;
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawmempool","","","","","","","")) != 0 )
+ {
+ //printf("mempool.(%s)\n",jprint(retjson,0));
+ return(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"get_rawmempool.(%s) error.(%s)\n",acname,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+cJSON *get_addressutxos(char *refcoin,char *acname,char *coinaddr)
+{
+ cJSON *retjson; char *retstr,jsonbuf[256];
+ if ( refcoin[0] != 0 && strcmp(refcoin,"KMD") != 0 )
+ printf("warning: assumes %s has addressindex enabled\n",refcoin);
+ sprintf(jsonbuf,"{\\\"addresses\\\":[\\\"%s\\\"]}",coinaddr);
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getaddressutxos",jsonbuf,"","","","","","")) != 0 )
+ {
+ //printf("addressutxos.(%s)\n",jprint(retjson,0));
+ return(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"get_addressutxos.(%s) error.(%s)\n",acname,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid)
+{
+ cJSON *retjson; char *retstr,str[65];
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","","","","","")) != 0 )
+ {
+ return(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"get_rawtransaction.(%s) %s error.(%s)\n",refcoin,acname,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+cJSON *get_z_viewtransaction(char *refcoin,char *acname,bits256 txid)
+{
+ cJSON *retjson; char *retstr,str[65];
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_viewtransaction",bits256_str(str,txid),"","","","","","")) != 0 )
+ {
+ return(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"get_z_viewtransaction.(%s) %s error.(%s)\n",refcoin,acname,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+cJSON *get_listunspent(char *refcoin,char *acname)
+{
+ cJSON *retjson; char *retstr,str[65];
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","","","","","","","")) != 0 )
+ {
+ return(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"get_listunspent.(%s) %s error.(%s)\n",refcoin,acname,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+cJSON *get_getinfo(char *refcoin,char *acname)
+{
+ cJSON *retjson; char *retstr,str[65];
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getinfo","","","","","","","")) != 0 )
+ {
+ return(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"get_getinfo.(%s) %s error.(%s)\n",refcoin,acname,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+cJSON *z_listunspent(char *refcoin,char *acname)
+{
+ cJSON *retjson; char *retstr,str[65];
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_listunspent","","","","","","","")) != 0 )
+ {
+ return(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"z_listunspent.(%s) %s error.(%s)\n",refcoin,acname,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+cJSON *z_listoperationids(char *refcoin,char *acname)
+{
+ cJSON *retjson; char *retstr,str[65];
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_listoperationids","","","","","","","")) != 0 )
+ {
+ return(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"z_listoperationids.(%s) %s error.(%s)\n",refcoin,acname,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+cJSON *z_getoperationstatus(char *refcoin,char *acname,char *opid)
+{
+ cJSON *retjson; char *retstr,str[65],params[512];
+ sprintf(params,"'[\"%s\"]'",opid);
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getoperationstatus",params,"","","","","","")) != 0 )
+ {
+ //printf("got status (%s)\n",jprint(retjson,0));
+ return(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"z_getoperationstatus.(%s) %s error.(%s)\n",refcoin,acname,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+cJSON *z_getoperationresult(char *refcoin,char *acname,char *opid)
+{
+ cJSON *retjson; char *retstr,str[65],params[512];
+ sprintf(params,"'[\"%s\"]'",opid);
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getoperationresult",params,"","","","","","")) != 0 )
+ {
+ return(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"z_getoperationresult.(%s) %s error.(%s)\n",refcoin,acname,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+int32_t validateaddress(char *refcoin,char *acname,char *depositaddr, char* compare)
+{
+ cJSON *retjson; char *retstr; int32_t res=0;
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"validateaddress",depositaddr,"","","","","","")) != 0 )
+ {
+ if (is_cJSON_True(jobj(retjson,compare)) != 0 ) res=1;
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"validateaddress.(%s) %s error.(%s)\n",refcoin,acname,retstr);
+ free(retstr);
+ }
+ return (res);
+}
+
+int32_t z_validateaddress(char *refcoin,char *acname,char *depositaddr, char *compare)
+{
+ cJSON *retjson; char *retstr; int32_t res=0;
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_validateaddress",depositaddr,"","","","","","")) != 0 )
+ {
+ if (is_cJSON_True(jobj(retjson,compare)) != 0 )
+ res=1;
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"z_validateaddress.(%s) %s error.(%s)\n",refcoin,acname,retstr);
+ free(retstr);
+ }
+ return (res);
+}
+
+int64_t get_getbalance(char *refcoin,char *acname)
+{
+ cJSON *retjson; char *retstr,cmpstr[64]; int64_t amount=0;
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getbalance","","","","","","","")) != 0 )
+ {
+ fprintf(stderr,"get_getbalance.(%s) %s returned json!\n",refcoin,acname);
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ amount = atof(retstr) * SATOSHIDEN;
+ sprintf(cmpstr,"%.8f",dstr(amount));
+ if ( strcmp(retstr,cmpstr) != 0 )
+ amount++;
+ //printf("retstr %s -> %.8f\n",retstr,dstr(amount));
+ free(retstr);
+ }
+ return (amount);
+}
+
+int64_t z_getbalance(char *refcoin,char *acname,char *coinaddr)
+{
+ cJSON *retjson; char *retstr,cmpstr[64]; int64_t amount=0;
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getbalance",coinaddr,"","","","","","")) != 0 )
+ {
+ fprintf(stderr,"z_getbalance.(%s) %s returned json!\n",refcoin,acname);
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ amount = atof(retstr) * SATOSHIDEN;
+ sprintf(cmpstr,"%.8f",dstr(amount));
+ if ( strcmp(retstr,cmpstr) != 0 )
+ amount++;
+ //printf("retstr %s -> %.8f\n",retstr,dstr(amount));
+ free(retstr);
+ }
+ return (amount);
+}
+
+int32_t z_exportkey(char *privkey,char *refcoin,char *acname,char *zaddr)
+{
+ cJSON *retjson; char *retstr,cmpstr[64]; int64_t amount=0;
+ privkey[0] = 0;
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_exportkey",zaddr,"","","","","","")) != 0 )
+ {
+ fprintf(stderr,"z_exportkey.(%s) %s returned json!\n",refcoin,acname);
+ free_json(retjson);
+ return(-1);
+ }
+ else if ( retstr != 0 )
+ {
+ //printf("retstr %s -> %.8f\n",retstr,dstr(amount));
+ strcpy(privkey,retstr);
+ free(retstr);
+ return(0);
+ }
+ return(-1);
+}
+
+int32_t getnewaddress(char *coinaddr,char *refcoin,char *acname)
+{
+ cJSON *retjson; char *retstr; int64_t amount=0; int32_t retval = -1;
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getnewaddress","","","","","","","")) != 0 )
+ {
+ fprintf(stderr,"getnewaddress.(%s) %s returned json!\n",refcoin,acname);
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ strcpy(coinaddr,retstr);
+ free(retstr);
+ retval = 0;
+ }
+ return(retval);
+}
+
+int32_t z_getnewaddress(char *coinaddr,char *refcoin,char *acname,char *typestr)
+{
+ cJSON *retjson; char *retstr; int64_t amount=0; int32_t retval = -1;
+ if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getnewaddress",typestr,"","","","","","")) != 0 )
+ {
+ fprintf(stderr,"z_getnewaddress.(%s) %s returned json!\n",refcoin,acname);
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ strcpy(coinaddr,retstr);
+ free(retstr);
+ retval = 0;
+ }
+ return(retval);
+}
+
+int64_t find_onetime_amount(char *coinstr,char *coinaddr)
+{
+ cJSON *array,*item; int32_t i,n; char *addr; int64_t amount = 0;
+ coinaddr[0] = 0;
+ if ( (array= get_listunspent(coinstr,"")) != 0 )
+ {
+ //printf("got listunspent.(%s)\n",jprint(array,0));
+ if ( (n= cJSON_GetArraySize(array)) > 0 )
+ {
+ for (i=0; i 0 )
+ {
+ for (i=0; i %s\n",coinstr,acname,srcaddr,params);
+ if ( (retjson= get_komodocli(coinstr,&retstr,acname,"z_sendmany",addr,params,"","","","","")) != 0 )
+ {
+ printf("unexpected json z_sendmany.(%s)\n",jprint(retjson,0));
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"z_sendmany.(%s) -> opid.(%s)\n",coinstr,retstr);
+ strcpy(opidstr,retstr);
+ free(retstr);
+ retval = 0;
+ }
+ return(retval);
+}
+
+int32_t z_mergetoaddress(char *opidstr,char *coinstr,char *acname,char *destaddr)
+{
+ cJSON *retjson; char *retstr,addr[128],*opstr; int32_t retval = -1;
+ sprintf(addr,"[\\\"ANY_SPROUT\\\"]");
+ if ( (retjson= get_komodocli(coinstr,&retstr,acname,"z_mergetoaddress",addr,destaddr,"","","","","")) != 0 )
+ {
+ if ( (opstr= jstr(retjson,"opid")) != 0 )
+ strcpy(opidstr,opstr);
+ retval = jint(retjson,"remainingNotes");
+ fprintf(stderr,"%s\n",jprint(retjson,0));
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"z_mergetoaddress.(%s) -> opid.(%s)\n",coinstr,retstr);
+ strcpy(opidstr,retstr);
+ free(retstr);
+ }
+ return(retval);
+}
+
+int32_t empty_mempool(char *coinstr,char *acname)
+{
+ cJSON *array; int32_t n;
+ if ( (array= get_rawmempool(coinstr,acname)) != 0 )
+ {
+ if ( (n= cJSON_GetArraySize(array)) > 0 )
+ return(0);
+ free_json(array);
+ return(1);
+ }
+ return(-1);
+}
+
+cJSON *getinputarray(int64_t *totalp,cJSON *unspents,int64_t required)
+{
+ cJSON *vin,*item,*vins = cJSON_CreateArray(); int32_t i,n,v; int64_t satoshis; bits256 txid;
+ *totalp = 0;
+ if ( (n= cJSON_GetArraySize(unspents)) > 0 )
+ {
+ for (i=0; i= required )
+ break;
+ }
+ }
+ }
+ return(vins);
+}
+
+int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinaddr)
+{
+ cJSON *txobj,*vouts,*vout,*vins,*vin,*sobj,*addresses; char *addr,str[65]; int32_t i,j,n,numarray,retval = 0, hasvout=0;
+ if ( (txobj= get_rawtransaction(refcoin,acname,txid)) != 0 )
+ {
+ if ( (vouts= jarray(&numarray,txobj,"vout")) != 0 )
+ {
+ for (i=0; i 0 )
+ {
+ for (i=0; i 0 )
+ {
+ for (j=0; j 0 && strcmp(vinaddr,cmpaddr) == 0 )
+ return(0);
+ printf("mismatched vinaddr.(%s) vs %s\n",vinaddr,cmpaddr);
+ }
+ }
+ return(-1);
+}
+
+int32_t txid_in_vins(char *refcoin,bits256 txid,bits256 cmptxid)
+{
+ cJSON *txjson,*vins,*vin; int32_t numvins,v,vinvout; bits256 vintxid; char str[65];
+ if ( (txjson= get_rawtransaction(refcoin,"",txid)) != 0 )
+ {
+ if ( (vins= jarray(&numvins,txjson,"vin")) != 0 )
+ {
+ for (v=0; v n.%d retval.%d\n",tagA,tagB,pubkeystr,n,retval);
+ }
+ free_json(retjson);
+ }
+ return(retval);
+}
+
+int32_t dpow_hasmessage(char *payload,char *tagA,char *tagB,char *pubkeystr)
+{
+ cJSON *retjson,*item,*array; char *retstr,*pstr; int32_t i,n,retval = 0;
+ if ( (retjson= get_komodocli((char *)"",&retstr,DEXP2P_CHAIN,"DEX_list","0","0",tagA,tagB,pubkeystr,"","")) != 0 )
+ {
+ if ( (array= jarray(&n,retjson,"matches")) != 0 )
+ {
+ for (i=0; i 0 )
+ {
+ ptrs = calloc(n,sizeof(*ptrs));
+ for (i=0; ishorthash = juint(item,"id");
+ ptrs[m]->jsonstr = ptr;
+ strcpy(ptrs[m]->senderpub,senderpub);
+ m++;
+ }
+ }
+ }
+ *nump = m;
+ }
+ free_json(retjson);
+ }
+ return(ptrs);
+}
+
+
diff --git a/src/cc/dapps/subatomic.c b/src/cc/dapps/subatomic.c
new file mode 100644
index 000000000..2f6ebf824
--- /dev/null
+++ b/src/cc/dapps/subatomic.c
@@ -0,0 +1,1429 @@
+/******************************************************************************
+ * Copyright © 2014-2020 The SuperNET Developers. *
+ * *
+ * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
+ * the top-level directory of this distribution for the individual copyright *
+ * holder information and the developer policies on copyright and licensing. *
+ * *
+ * Unless otherwise agreed in a custom licensing agreement, no part of the *
+ * SuperNET software, including this file may be copied, modified, propagated *
+ * or distributed except according to the terms contained in the LICENSE file *
+ * *
+ * Removal or modification of this copyright notice is prohibited. *
+ * *
+ ******************************************************************************/
+
+// build subatomic and put in path: git pull; gcc cc/dapps/subatomic.c -lm -o subatomic; cp subatomic /usr/bin
+// alice sends relcoin and gets basecoin
+
+#define DEXP2P_CHAIN ((char *)"DEX")
+#define DEXP2P_PUBKEYS ((char *)"subatomic")
+#include "dappinc.h"
+
+// for OTC mode, the following 4 functions are the only ones that should be needed to support a new "coin"
+//int64_t subatomic_getbalance(char *coin);
+//bits256 subatomic_coinpayment(int32_t OTCmode,char *coin,char *destaddr,uint64_t paytoshis,char *memostr);
+//cJSON *subatomic_txidwait(char *coin,bits256 txid,char *hexstr,int32_t numseconds);
+//int64_t subatomic_verifypayment(char *coin,cJSON *rawtx,uint64_t destsatoshis,char *destaddr);
+
+// TODO:
+// address conversion
+// new inventory types:
+// anonsend
+
+// bob nodes:
+// mutex for bob instances
+// "deposits" messages and approved bobs
+// volume caps per coin and non-notarized exposure
+
+// later:
+// sharded storage
+
+#define SUBATOMIC_OTCDEFAULT 1
+#define SUBATOMIC_TIMEOUT 60
+#define SUBATOMIC_LOCKTIME 3600
+#define SUBATOMIC_TXFEE 10000
+
+#define SUBATOMIC_PRIORITY 5
+
+#define SUBATOMIC_OPENREQUEST 1
+#define SUBATOMIC_APPROVED 2
+#define SUBATOMIC_OPENED 3
+#define SUBATOMIC_PAYMENT 4
+#define SUBATOMIC_PAIDINFULL 5
+#define SUBATOMIC_CLOSED 6
+
+cJSON *SUBATOMIC_json;
+int32_t SUBATOMIC_retval = -1;
+
+struct abinfo
+{
+ char pubkey[67],recvaddr[64],recvZaddr[128],secp[67];
+};
+
+struct coininfo
+{
+ uint64_t satoshis,txfee,maxamount;
+ char istoken,iszaddr,isfile,isexternal,tokenid[65],coin[16],name[16],cli[256],acname[16],coinstr[16];
+};
+
+struct msginfo
+{
+ UT_hash_handle hh;
+ bits256 bobpayment,alicepayment;
+ double price;
+ uint64_t gotpayment;
+ uint32_t origid,openrequestid,approvalid,openedid,paymentids[100],paidid,closedid,locktime;
+ int32_t bobflag,status,OTCmode;
+ char payload[128],approval[128],senderpub[67],msigaddr[64],redeemscript[256];
+ struct coininfo base,rel;
+ struct abinfo alice,bob;
+} *Messages;
+
+uint64_t subatomic_txfee(char *coin)
+{
+ return(SUBATOMIC_TXFEE);
+}
+
+char *subatomic_checkname(char *tmpstr,struct msginfo *mp,int32_t baserel,char *coin)
+{
+ int32_t i,n; cJSON *external,*item; char *coinstr,*clistr; struct coininfo *ptr;
+ ptr = (baserel == 0) ? &mp->base : &mp->rel;
+ if ( coin[0] == 0 )
+ return(coin);
+ if ( (external= jarray(&n,SUBATOMIC_json,"externalcoins")) != 0 && n > 0 )
+ {
+ for (i=0; icli) )
+ {
+ ptr->isexternal = 1;
+ strcpy(ptr->cli,clistr);
+ //fprintf(stderr,"found external coin %s %s\n",coin,clistr);
+ }
+ }
+ }
+ if ( coin[0] == '#' )
+ {
+ strcpy(ptr->coinstr,coin);
+ strcpy(ptr->acname,"");
+ ptr->isfile = 1;
+ return(coin);
+ }
+ else if ( coin[0] != 'z' )
+ {
+ for (i=1; coin[i]!=0; i++)
+ if ( coin[i] == '.' )
+ {
+ dpow_tokenregister(ptr->tokenid,0,coin,0);
+ if ( ptr->tokenid[0] != 0 )
+ {
+ strcpy(tmpstr,coin);
+ tmpstr[i] = 0;
+ //fprintf(stderr,"found a tokenmap %s -> %s %s\n",coin,tmpstr,ptr->tokenid);
+ ptr->istoken = 1;
+ strcpy(ptr->acname,coin);
+ strcpy(ptr->coinstr,"");
+ return(tmpstr);
+ }
+ }
+ if ( ptr->isexternal == 0 )
+ {
+ if ( strcmp(coin,"KMD") != 0 )
+ {
+ strcpy(ptr->acname,coin);
+ strcpy(ptr->coinstr,"");
+ }
+ else
+ {
+ strcpy(ptr->coinstr,coin);
+ strcpy(ptr->acname,"");
+ }
+ }
+ else
+ {
+ strcpy(ptr->coinstr,coin);
+ strcpy(ptr->acname,"");
+ }
+ return(coin);
+ }
+ else
+ {
+ for (i=1; coin[i]!=0; i++)
+ if ( isupper(coin[i]) == 0 )
+ return(coin);
+ if ( strcmp(coin+1,"KMD") != 0 )
+ ptr->iszaddr = 1;
+ return(coin+1);
+ }
+}
+
+int32_t subatomic_zonly(struct coininfo *coin)
+{
+ if ( strcmp(coin->coin,"PIRATE") == 0 )
+ return(1);
+ else return(coin->iszaddr);
+}
+
+// //////////////////////////////// the four key functions needed to support a new item for subatomics
+
+int64_t _subatomic_getbalance(struct coininfo *coin)
+{
+ cJSON *retjson; char *retstr,cmpstr[64]; int64_t amount=0;
+ if ( (retjson= subatomic_cli(coin->cli,&retstr,"getbalance","","","","","","","")) != 0 )
+ {
+ fprintf(stderr,"_subatomic_getbalance.(%s) %s returned json!\n",coin->coinstr,coin->cli);
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ amount = atof(retstr) * SATOSHIDEN;
+ sprintf(cmpstr,"%.8f",dstr(amount));
+ if ( strcmp(retstr,cmpstr) != 0 )
+ amount++;
+ //printf("retstr %s -> %.8f\n",retstr,dstr(amount));
+ free(retstr);
+ }
+ return (amount);
+}
+
+bits256 _subatomic_sendtoaddress(struct coininfo *coin,char *destaddr,int64_t satoshis)
+{
+ char numstr[32],*retstr,str[65]; cJSON *retjson; bits256 txid;
+ memset(txid.bytes,0,sizeof(txid));
+ sprintf(numstr,"%.8f",(double)satoshis/SATOSHIDEN);
+ if ( (retjson= subatomic_cli(coin->cli,&retstr,"sendtoaddress",destaddr,numstr,"false","","","","")) != 0 )
+ {
+ fprintf(stderr,"unexpected _subatomic_sendtoaddress json.(%s)\n",jprint(retjson,0));
+ free_json(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ if ( strlen(retstr) >= 64 )
+ {
+ retstr[64] = 0;
+ decode_hex(txid.bytes,32,retstr);
+ }
+ fprintf(stderr,"_subatomic_sendtoaddress %s %.8f txid.(%s)\n",destaddr,(double)satoshis/SATOSHIDEN,bits256_str(str,txid));
+ free(retstr);
+ }
+ return(txid);
+}
+
+cJSON *_subatomic_rawtransaction(struct coininfo *coin,bits256 txid)
+{
+ cJSON *retjson; char *retstr,str[65];
+ if ( (retjson= subatomic_cli(coin->cli,&retstr,"getrawtransaction",bits256_str(str,txid),"1","","","","","")) != 0 )
+ {
+ return(retjson);
+ }
+ else if ( retstr != 0 )
+ {
+ fprintf(stderr,"_subatomic_rawtransaction.(%s) %s error.(%s)\n",coin->coin,coin->name,retstr);
+ free(retstr);
+ }
+ return(0);
+}
+
+int64_t subatomic_getbalance(struct coininfo *coin)
+{
+ char *coinstr,*acname=""; FILE *fp; int64_t retval = 0;
+ if ( strcmp(coin->coin,"KMD") != 0 )
+ {
+ acname = coin->coin;
+ coinstr = "";
+ } else coinstr = coin->coin;
+ if ( coin->isfile != 0 )
+ {
+ if ( (fp= fopen(coin->name+1,"rb")) != 0 ) // if alice, add bob pubkey to fname
+ {
+ fclose(fp);
+ retval = SATOSHIDEN;
+ }
+ return(retval);
+ }
+ else if ( subatomic_zonly(coin) != 0 )
+ return(z_getbalance(coinstr,acname,DPOW_recvZaddr));
+ else
+ {
+ if ( coin->istoken != 0 )
+ {
+ if ( get_getbalance(coinstr,acname) < SUBATOMIC_TXFEE )
+ {
+ fprintf(stderr,"not enough balance to send token\n");
+ return(0);
+ }
+ //fprintf(stderr,"token balance %s\n",coin->tokenid);
+ return(get_tokenbalance(coinstr,acname,coin->tokenid) * SATOSHIDEN);
+ }
+ else if ( coin->isexternal == 0 )
+ return(get_getbalance(coinstr,acname));
+ else return(_subatomic_getbalance(coin));
+ }
+}
+
+bits256 subatomic_coinpayment(uint32_t origid,int32_t OTCmode,struct coininfo *coin,char *destaddr,uint64_t paytoshis,char *memostr,char *destpub,char *senderpub)
+{
+ bits256 txid; char opidstr[128],opretstr[32],str[65],*status,*coinstr,*acname=""; cJSON *retjson,*retjson2,*item,*res; int32_t i,pending=0;
+ memset(&txid,0,sizeof(txid));
+ if ( OTCmode == 0 )
+ {
+ fprintf(stderr,"micropayment channels are not supported yet\n");
+ return(txid);
+ }
+ if ( coin->isfile != 0 )
+ {
+ fprintf(stderr,"start broadcast of (%s)\n",coin->coin+1);
+ if ( (retjson= dpow_publish(SUBATOMIC_PRIORITY,coin->coin+1)) != 0 ) // spawn thread
+ {
+ sprintf(opretstr,"%08x",juint(retjson,"id"));
+ sprintf(opidstr,"%u",origid);
+ if ( (retjson2= dpow_broadcast(SUBATOMIC_PRIORITY,opretstr,"inbox",opidstr,senderpub,"","")) != 0 )
+ free_json(retjson2);
+ fprintf(stderr,"broadcast file.(%s) and send id.%u to alice (%s)\n",coin->coin+1,juint(retjson,"id"),jprint(retjson,0));
+ txid = jbits256(retjson,"filehash");
+ free_json(retjson);
+ }
+ fprintf(stderr,"end broadcast of (%s) to %s\n",coin->coin+1,senderpub);
+ return(txid);
+ }
+ else if ( subatomic_zonly(coin) != 0 )
+ {
+ if ( memostr[0] == 0 )
+ memostr = "beef";
+ z_sendmany(opidstr,"",coin->coin,DPOW_recvZaddr,destaddr,paytoshis,memostr);
+ for (i=0; icoin,opidstr)) != 0 )
+ {
+ item = jitem(retjson,0);
+ if ( (status= jstr(item,"status")) != 0 )
+ {
+ if ( strcmp(status,"executing") == 0 )
+ pending++;
+ else
+ {
+ res = jobj(item,"result");
+ txid = jbits256(res,"txid");
+ //fprintf(stderr,"got Ztx txid.%s\n",bits256_str(str,txid));
+ free_json(retjson);
+ break;
+ }
+ /*else if ( clearresults != 0 )
+ {
+ if ( (result= z_getoperationresult(coinstr,"",jstri(array,i))) != 0 )
+ {
+ free_json(result);
+ }
+ }*/
+ }
+ free_json(retjson);
+ }
+ sleep(1);
+ }
+ if ( i == 60 )
+ printf("%u timed out waiting for opid to finish\n",origid);
+ }
+ else
+ {
+ if ( strcmp(coin->coin,"KMD") != 0 )
+ {
+ acname = coin->coin;
+ coinstr = "";
+ } else coinstr = coin->coin;
+ if ( coin->istoken != 0 )
+ txid = tokentransfer(coinstr,acname,coin->tokenid,destpub,paytoshis/SATOSHIDEN);
+ else if ( coin->isexternal == 0 )
+ {
+ sprintf(opretstr,"%08x",origid);
+ txid = sendtoaddress(coinstr,acname,destaddr,paytoshis,opretstr);
+ } else txid = _subatomic_sendtoaddress(coin,destaddr,paytoshis);
+ printf("%u got txid.%s\n",origid,bits256_str(str,txid));
+ }
+ return(txid);
+}
+
+cJSON *subatomic_txidwait(struct coininfo *coin,bits256 txid,char *hexstr,int32_t numseconds,char *senderpub)
+{
+ int32_t i,zflag; char *coinstr,str[65],*acname=""; cJSON *rawtx; bits256 z; bits256 filehash;
+ memset(&z,0,sizeof(z));
+ if ( memcmp(&z,&txid,sizeof(txid)) == 0 )
+ return(0);
+ if ( hexstr != 0 && hexstr[0] != 0 ) // probably not worth doing and zaddr is a problem to decode
+ {
+ // compare against txid
+ // if matches, sendrawtransaction if OTC mode, decoode and return if channels mode
+ }
+ zflag = (subatomic_zonly(coin) != 0);
+ if ( strcmp(coin->coin,"KMD") != 0 )
+ {
+ acname = coin->coin;
+ coinstr = "";
+ } else coinstr = coin->coin;
+ for (i=0; iisfile != 0 )
+ {
+ if ( (rawtx= dpow_subscribe(SUBATOMIC_PRIORITY,coin->coin+1,senderpub)) != 0 )
+ {
+ filehash = jbits256(rawtx,"filehash");
+ if ( memcmp(&filehash,&txid,sizeof(filehash)) != 0 )
+ {
+ fprintf(stderr,"waiting (%s) (%s)\n",coin->coin+1,jprint(rawtx,0));
+ free_json(rawtx);
+ rawtx = 0;
+ } else return(rawtx);
+ }
+ }
+ else if ( zflag != 0 )
+ rawtx = get_z_viewtransaction(coinstr,acname,txid);
+ else if ( coin->isexternal == 0 )
+ rawtx = get_rawtransaction(coinstr,acname,txid);
+ else rawtx = _subatomic_rawtransaction(coin,txid);
+ if ( rawtx != 0 )
+ return(rawtx);
+ sleep(1);
+ }
+ printf("%s/%s timeout waiting for %s\n",coin->name,coin->coin,bits256_str(str,txid));
+ return(0);
+}
+
+int64_t subatomic_verifypayment(struct coininfo *coin,cJSON *rawtx,uint64_t destsatoshis,char *destaddr,bits256 txid)
+{
+ int32_t i,n,m,valid=0; bits256 tokenid,filehash,checkhash; cJSON *array,*item,*sobj,*a; char *addr,*acname,*coinstr,tokenaddr[64],*hex; uint8_t hexbuf[512],pub33[33]; uint64_t netval,recvsatoshis = 0;
+ if ( coin->isfile != 0 )
+ {
+ filehash = jbits256(rawtx,"filehash");
+ checkhash = jbits256(rawtx,"checkhash");
+ if ( memcmp(&txid,&filehash,sizeof(txid)) == 0 && memcmp(&txid,&checkhash,sizeof(txid)) == 0 )
+ {
+ fprintf(stderr,"verified file is matching the filehash (%s)\n",jprint(rawtx,0));
+ return(SATOSHIDEN);
+ } else return(0);
+ }
+ else if ( subatomic_zonly(coin) != 0 )
+ {
+ if ( (array= jarray(&n,rawtx,"outputs")) != 0 && n > 0 )
+ {
+ for (i=0; iistoken != 0 )
+ {
+ if ( (array= jarray(&n,rawtx,"vout")) != 0 && n > 0 )
+ {
+ item = jitem(array,0);
+ if ( (sobj= jobj(item,"scriptPubKey")) != 0 && (a= jarray(&m,sobj,"addresses")) != 0 && m == 1 )
+ {
+ if ( strcmp(coin->coin,"KMD") != 0 )
+ {
+ acname = coin->coin;
+ coinstr = "";
+ } else coinstr = coin->coin;
+ if ( get_tokenaddress(coinstr,acname,tokenaddr) != 0 )
+ {
+ //fprintf(stderr,"tokenaddr.%s\n",tokenaddr);
+ if ( (addr= jstri(a,0)) != 0 && strcmp(addr,tokenaddr) == 0 )
+ recvsatoshis += SATOSHIDEN * (uint64_t)(jdouble(item,"value")*SATOSHIDEN + 0.000000004999);
+ else fprintf(stderr,"miscompare (%s) vs %s\n",jprint(sobj,0),addr);
+ }
+ }
+ item = jitem(array,n-1);
+ if ( (sobj= jobj(item,"scriptPubKey")) != 0 && (hex= jstr(sobj,"hex")) != 0 && (m= is_hexstr(hex,0)) > 1 && m/2 < sizeof(hexbuf) )
+ {
+ m >>= 1;
+ decode_hex(hexbuf,m,hex);
+ decode_hex(tokenid.bytes,32,coin->tokenid);
+ decode_hex(pub33,33,DPOW_secpkeystr);
+ // opret 69len EVAL_TOKENS 't' tokenid 1 33 pub33
+ if ( hexbuf[0] == 0x6a && hexbuf[1] == 0x45 && hexbuf[2] == 0xf2 && hexbuf[3] == 't' && memcmp(&hexbuf[4],&tokenid,sizeof(tokenid)) == 0 && hexbuf[4+32] == 1 && hexbuf[4+32+1] == 33 && memcmp(&hexbuf[4+32+2],pub33,33) == 0 )
+ {
+ valid = 1;
+ //fprintf(stderr,"validated it is a token transfer!\n");
+ } else fprintf(stderr,"need to validate tokentransfer.(%s) %s %d\n",hex,DPOW_secpkeystr,memcmp(&hexbuf[4+32+2],pub33,33) == 0);
+ //6a 45 f2 74 2b1feef719ecb526b07416dd432bce603ac6dc8bfe794cddf105cb52f6aae3cd 01 21 02b27de3ee5335518b06f69f4fbabb029cfc737613b100996841d5532b324a5a61
+
+ }
+ recvsatoshis *= valid;
+ }
+ }
+ else
+ {
+ if ( (array= jarray(&n,rawtx,"vout")) != 0 && n > 0 )
+ {
+ for (i=0; iorigid = origid;
+ HASH_ADD(hh,Messages,origid,sizeof(origid),mp);
+ return(mp);
+}
+
+int32_t subatomic_status(struct msginfo *mp,int32_t status)
+{
+ static FILE *fp;
+ if ( fp == 0 )
+ {
+ int32_t i,oid,s,n,num,count; struct msginfo *m; long fsize;
+ if ( (fp= fopen("SUBATOMIC.DB","rb+")) == 0 )
+ {
+ if ( (fp= fopen("SUBATOMIC.DB","wb")) == 0 )
+ {
+ fprintf(stderr,"cant create SUBATOMIC.DB\n");
+ exit(-1);
+ }
+ }
+ else
+ {
+ fseek(fp,0,SEEK_END);
+ fsize = ftell(fp);
+ if ( (fsize % (sizeof(uint32_t)*2)) != 0 )
+ {
+ fprintf(stderr,"SUBATOMIC.DB illegal filesize.%ld\n",fsize);
+ exit(-1);
+ }
+ n = (int32_t)(fsize / (sizeof(uint32_t)*2));
+ rewind(fp);
+ for (i=num=count=0; i SUBATOMIC_CLOSED )
+ {
+ fprintf(stderr,"SUBATOMIC.DB corrupted at filepos.%ld: illegal status.%d\n",ftell(fp),s);
+ exit(-1);
+ }
+ //fprintf(stderr,"%u <- %d\n",oid,s);
+ if ( (m= subatomic_find(oid)) == 0 )
+ {
+ m = subatomic_add(oid);
+ count++;
+ }
+ if ( s > m->status )
+ {
+ m->status = s;
+ num++;
+ }
+ }
+ fprintf(stderr,"initialized %d messages, updated %d out of total.%d\n",count,num,n);
+ }
+ }
+ if ( mp->status >= status )
+ return(-1);
+ if ( fwrite(&mp->origid,1,sizeof(mp->origid),fp) != sizeof(mp->origid) || fwrite(&status,1,sizeof(status),fp) != sizeof(status) )
+ fprintf(stderr,"error updating SUBATOMIC.DB, risk of double spends\n");
+ fflush(fp);
+ mp->status = status;
+ return(0);
+}
+
+struct msginfo *subatomic_tracker(uint32_t origid)
+{
+ struct msginfo *mp;
+ if ( (mp= subatomic_find(origid)) == 0 )
+ {
+ mp = subatomic_add(origid);
+ subatomic_status(mp,0);
+ }
+ return(mp);
+}
+
+char *subatomic_hexstr(char *jsonstr)
+{
+ char *hexstr; int32_t i,c,n = (int32_t)strlen(jsonstr);
+ hexstr = malloc(2*n + 3);
+ strcpy(hexstr,jsonstr);
+ for (i=0; iorigid);
+ jaddnum(item,"price",mp->price);
+ jaddnum(item,"openrequest",mp->openrequestid);
+ jaddstr(item,"base",mp->base.name);
+ jaddstr(item,"basecoin",mp->base.coin);
+ jadd64bits(item,"basesatoshis",mp->base.satoshis);
+ jadd64bits(item,"basetxfee",mp->base.txfee);
+ jadd64bits(item,"maxbaseamount",mp->base.maxamount);
+ jaddstr(item,"rel",mp->rel.name);
+ jaddstr(item,"relcoin",mp->rel.coin);
+ jadd64bits(item,"relsatoshis",mp->rel.satoshis);
+ jadd64bits(item,"reltxfee",mp->rel.txfee);
+ jadd64bits(item,"maxrelamount",mp->rel.maxamount);
+ jaddstr(item,"alice",mp->alice.pubkey);
+ jaddstr(item,"alicesecp",mp->alice.secp);
+ jaddstr(item,"bob",mp->bob.pubkey);
+ jaddstr(item,"bobsecp",mp->bob.secp);
+ if ( subatomic_zonly(&mp->rel) != 0 )
+ jaddstr(item,"bobZaddr",mp->bob.recvZaddr);
+ else jaddstr(item,"bobaddr",mp->bob.recvaddr);
+ if ( mp->rel.istoken != 0 )
+ jaddstr(item,"bobtoken",mp->rel.tokenid);
+ if ( subatomic_zonly(&mp->base) != 0 )
+ jaddstr(item,"aliceZaddr",mp->alice.recvZaddr);
+ else jaddstr(item,"aliceaddr",mp->alice.recvaddr);
+ if ( mp->base.istoken != 0 )
+ jaddstr(item,"alicetoken",mp->base.tokenid);
+ return(item);
+}
+
+uint64_t subatomic_orderbook_mpset(struct msginfo *mp,char *basecheck)
+{
+ cJSON *retjson; char *tagA,*tagB,*senderpub,*str,tmpstr[32]; int32_t matches=0; double volA,volB; int64_t txfee=0;
+ strcpy(mp->base.name,basecheck);
+ strcpy(mp->base.coin,subatomic_checkname(tmpstr,mp,0,basecheck));
+ mp->rel.txfee = subatomic_txfee(mp->rel.coin);
+ if ( (retjson= dpow_get(mp->origid)) != 0 )
+ {
+ //fprintf(stderr,"dpow_get.(%s) (%s/%s)\n",jprint(retjson,0),mp->base.coin,mp->rel.coin);
+ if ( (senderpub= jstr(retjson,"senderpub")) != 0 && is_hexstr(senderpub,0) == 66 && (tagA= jstr(retjson,"tagA")) != 0 && (tagB= jstr(retjson,"tagB")) != 0 && strncmp(tagB,mp->rel.name,strlen(mp->rel.name)) == 0 && strlen(tagA) < sizeof(mp->base.name) )
+ {
+ strcpy(mp->base.name,tagA);
+ strcpy(mp->base.coin,subatomic_checkname(tmpstr,mp,0,tagA));
+ if ( basecheck[0] == 0 || strncmp(basecheck,tagA,strlen(basecheck)) == 0 )
+ matches = 1;
+ else if ( strcmp(tagA,mp->base.name) == 0 )
+ matches = 1;
+ else if ( mp->bobflag != 0 && tagA[0] == '#' && strcmp(mp->base.name,"#allfiles") == 0 )
+ matches = 1;
+ if ( matches != 0 )
+ {
+ if ( (str= jstr(retjson,"decrypted")) != 0 && strlen(str) < 128 )
+ strcpy(mp->payload,str);
+ mp->locktime = juint(retjson,"timestamp") + SUBATOMIC_LOCKTIME;
+ mp->base.txfee = subatomic_txfee(mp->base.coin);
+ strcpy(mp->senderpub,senderpub);
+ volB = jdouble(retjson,"amountB");
+ volA = jdouble(retjson,"amountA");
+ mp->base.maxamount = volA*SATOSHIDEN + 0.0000000049999;
+ mp->rel.maxamount = volB*SATOSHIDEN + 0.0000000049999;
+ if ( 0 && mp->rel.istoken == 0 )
+ txfee = mp->rel.txfee;
+ if ( mp->base.maxamount != 0 && mp->rel.maxamount != 0 && volA > SMALLVAL && volB > SMALLVAL && mp->rel.satoshis <= mp->rel.maxamount )
+ {
+ mp->price = volA / volB;
+ mp->base.satoshis = (mp->rel.satoshis - txfee) * mp->price;
+ //fprintf(stderr,"base satoshis.%llu\n",(long long)mp->base.satoshis);
+ } else fprintf(stderr,"%u rel %llu vs (%llu %llu)\n",mp->origid,(long long)mp->rel.satoshis,(long long)mp->base.maxamount,(long long)mp->rel.maxamount);
+ } else printf("%u didnt match (%s) tagA.%s %s, tagB.%s %s %d %d\n",mp->origid,basecheck,tagA,mp->base.name,tagB,mp->rel.name,tagA[0] == '#', strcmp(mp->base.name,"#allfiles") == 0);
+ } else printf("%u didnt compare tagA.%s %s, tagB.%s %s\n",mp->origid,tagA,mp->base.name,tagB,mp->rel.name);
+ free_json(retjson);
+ }
+ return(mp->base.satoshis);
+}
+
+char *randhashstr(char *str)
+{
+ bits256 rands; int32_t i;
+ for (i=0; i<32; i++)
+ rands.bytes[i] = rand() >> 17;
+ bits256_str(str,rands);
+ return(str);
+}
+
+void subatomic_extrafields(cJSON *dest,cJSON *src)
+{
+ char *str;
+ if ( (str= jstr(src,"approval")) != 0 )
+ jaddstr(dest,"approval",str);
+ if ( (str= jstr(src,"opened")) != 0 )
+ jaddstr(dest,"opened",str);
+ if ( (str= jstr(src,"payamount")) != 0 )
+ jaddstr(dest,"payamount",str);
+ if ( (str= jstr(src,"destaddr")) != 0 )
+ jaddstr(dest,"destaddr",str);
+ if ( (str= jstr(src,"bobpayment")) != 0 )
+ jaddstr(dest,"bobpayment",str);
+ if ( (str= jstr(src,"alicepayment")) != 0 )
+ jaddstr(dest,"alicepayment",str);
+ if ( (str= jstr(src,"bobaddr")) != 0 )
+ jaddstr(dest,"bobaddr",str);
+ if ( (str= jstr(src,"bobZaddr")) != 0 )
+ jaddstr(dest,"bobZaddr",str);
+ if ( (str= jstr(src,"aliceaddr")) != 0 )
+ jaddstr(dest,"aliceaddr",str);
+ if ( (str= jstr(src,"aliceZaddr")) != 0 )
+ jaddstr(dest,"aliceZaddr",str);
+ if ( (str= jstr(src,"alicetoken")) != 0 )
+ jaddstr(dest,"alicetoken",str);
+ if ( (str= jstr(src,"bobtoken")) != 0 )
+ jaddstr(dest,"bobtoken",str);
+}
+
+char *subatomic_submit(cJSON *argjson,int32_t tobob)
+{
+ char *jsonstr,*hexstr;
+ jaddnum(argjson,"tobob",tobob != 0);
+ jsonstr = jprint(argjson,1);
+ hexstr = subatomic_hexstr(jsonstr);
+ free(jsonstr);
+ return(hexstr);
+}
+
+#define SCRIPT_OP_IF 0x63
+#define SCRIPT_OP_ELSE 0x67
+#define SCRIPT_OP_DUP 0x76
+#define SCRIPT_OP_ENDIF 0x68
+#define SCRIPT_OP_TRUE 0x51
+#define SCRIPT_OP_2 0x52
+#define SCRIPT_OP_3 0x53
+#define SCRIPT_OP_DROP 0x75
+#define SCRIPT_OP_EQUALVERIFY 0x88
+#define SCRIPT_OP_HASH160 0xa9
+#define SCRIPT_OP_EQUAL 0x87
+#define SCRIPT_OP_CHECKSIG 0xac
+#define SCRIPT_OP_CHECKMULTISIG 0xae
+#define SCRIPT_OP_CHECKMULTISIGVERIFY 0xaf
+#define SCRIPT_OP_CHECKLOCKTIMEVERIFY 0xb1
+
+int32_t subatomic_redeemscript(char *redeemscript,uint32_t locktime,char *pubkeyA,char *pubkeyB) // not needed
+{
+ // if ( refund ) OP_HASH160 <2of2 multisig hash> OP_EQUAL // standard multisig
+ // else CLTV OP_DROP OP_CHECKSIG // standard spend
+ uint8_t pubkeyAbytes[33],pubkeyBbytes[33],hex[4096]; int32_t i,n = 0;
+ decode_hex(pubkeyAbytes,33,pubkeyA);
+ decode_hex(pubkeyBbytes,33,pubkeyB);
+ hex[n++] = SCRIPT_OP_IF;
+ hex[n++] = SCRIPT_OP_2;
+ hex[n++] = 33, memcpy(&hex[n],pubkeyAbytes,33), n += 33;
+ hex[n++] = 33, memcpy(&hex[n],pubkeyBbytes,33), n += 33;
+ hex[n++] = SCRIPT_OP_2;
+ hex[n++] = SCRIPT_OP_CHECKMULTISIG;
+ hex[n++] = SCRIPT_OP_ELSE;
+ hex[n++] = 4;
+ hex[n++] = locktime & 0xff, locktime >>= 8;
+ hex[n++] = locktime & 0xff, locktime >>= 8;
+ hex[n++] = locktime & 0xff, locktime >>= 8;
+ hex[n++] = locktime & 0xff;
+ hex[n++] = SCRIPT_OP_CHECKLOCKTIMEVERIFY;
+ hex[n++] = SCRIPT_OP_DROP;
+ hex[n++] = 33; memcpy(&hex[n],pubkeyAbytes,33); n += 33;
+ hex[n++] = SCRIPT_OP_CHECKSIG;
+ hex[n++] = SCRIPT_OP_ENDIF;
+ for (i=0; i>4) & 0xf);
+ redeemscript[i*2 + 1] = hexbyte(hex[i] & 0xf);
+ }
+ redeemscript[n*2] = 0;
+ /*tmpbuf[0] = SCRIPT_OP_HASH160;
+ tmpbuf[1] = 20;
+ calc_OP_HASH160(scriptPubKey,tmpbuf+2,redeemscript);
+ tmpbuf[22] = SCRIPT_OP_EQUAL;
+ init_hexbytes_noT(scriptPubKey,tmpbuf,23);
+ if ( p2shaddr != 0 )
+ {
+ p2shaddr[0] = 0;
+ if ( (btc_addr= base58_encode_check(addrtype,true,tmpbuf+2,20)) != 0 )
+ {
+ if ( strlen(btc_addr->str) < 36 )
+ strcpy(p2shaddr,btc_addr->str);
+ cstr_free(btc_addr,true);
+ }
+ }*/
+ return(n);
+}
+
+int32_t subatomic_approved(struct msginfo *mp,cJSON *approval,cJSON *msgjson,char *senderpub)
+{
+ char *hexstr,numstr[32],redeemscript[1024],*coin,*acname=""; cJSON *retjson,*decodejson; int32_t i,retval = 0;
+ subatomic_extrafields(approval,msgjson);
+ if ( mp->OTCmode == 0 )
+ {
+ coin = (mp->bobflag != 0) ? mp->base.coin : mp->rel.coin; // the other side gets this coin
+ if ( strcmp(coin,"KMD") != 0 )
+ {
+ acname = coin;
+ coin = "";
+ }
+ if ( get_createmultisig2(coin,acname,mp->msigaddr,mp->redeemscript,mp->alice.secp,mp->bob.secp) != 0 )
+ {
+ subatomic_redeemscript(redeemscript,mp->locktime,mp->alice.secp,mp->bob.secp);
+ if ( (decodejson= get_decodescript(coin,acname,redeemscript)) != 0 )
+ {
+ fprintf(stderr,"%s %s msigaddr.%s %s -> %s %s\n",mp->bobflag!=0?"bob":"alice",(mp->bobflag != 0) ? mp->base.coin : mp->rel.coin,mp->msigaddr,mp->redeemscript,redeemscript,jprint(decodejson,0));
+ free(decodejson);
+ }
+ }
+ }
+ sprintf(numstr,"%u",mp->origid);
+ for (i=0; numstr[i]!=0; i++)
+ sprintf(&mp->approval[i<<1],"%02x",numstr[i]);
+ sprintf(&mp->approval[i<<1],"%02x",' ');
+ i++;
+ mp->approval[i<<1] = 0;
+ jaddstr(approval,"approval",mp->approval);
+ hexstr = subatomic_submit(approval,!mp->bobflag);
+ if ( (retjson= dpow_broadcast(SUBATOMIC_PRIORITY,hexstr,(char *)"inbox",(char *)"approved",senderpub,"","")) != 0 )
+ {
+ if ( (mp->approvalid= juint(retjson,"id")) != 0 )
+ retval = 1;
+ printf("%u approvalid.%u (%s)\n",mp->origid,mp->approvalid,senderpub);
+ subatomic_status(mp,SUBATOMIC_APPROVED);
+ free_json(retjson);
+ }
+ free(hexstr);
+ return(retval);
+}
+
+int32_t subatomic_opened(struct msginfo *mp,cJSON *opened,cJSON *msgjson,char *senderpub)
+{
+ char *hexstr,channelstr[65]; cJSON *retjson; int32_t retval = 0;
+ subatomic_extrafields(opened,msgjson);
+ jaddstr(opened,"opened",randhashstr(channelstr));
+ hexstr = subatomic_submit(opened,!mp->bobflag);
+ if ( (retjson= dpow_broadcast(SUBATOMIC_PRIORITY,hexstr,(char *)"inbox",(char *)"opened",senderpub,"","")) != 0 )
+ {
+ if ( (mp->openedid= juint(retjson,"id")) != 0 )
+ retval = 1;
+ printf("%u openedid.%u\n",mp->origid,mp->openedid);
+ subatomic_status(mp,SUBATOMIC_OPENED);
+ free_json(retjson);
+ }
+ free(hexstr);
+ return(retval);
+}
+
+int32_t subatomic_payment(struct msginfo *mp,cJSON *payment,cJSON *msgjson,char *senderpub)
+{
+ bits256 txid; uint64_t paytoshis; cJSON *retjson; char numstr[32],*coin,*dest,*hexstr; int32_t retval = 0;
+ if ( mp->bobflag == 0 )
+ {
+ coin = mp->rel.name;
+ paytoshis = mp->rel.satoshis;
+ if ( subatomic_zonly(&mp->rel) != 0 )
+ dest = mp->bob.recvZaddr;
+ else dest = mp->bob.recvaddr;
+ sprintf(numstr,"%llu",(long long)paytoshis);
+ jaddstr(payment,"alicepays",numstr);
+ jaddstr(payment,"bobdestaddr",dest);
+ txid = subatomic_coinpayment(mp->origid,mp->OTCmode,&mp->rel,dest,paytoshis,mp->approval,mp->bob.secp,senderpub);
+ jaddbits256(payment,"alicepayment",txid);
+ mp->alicepayment = txid;
+ hexstr = 0; // get it from rawtransaction of txid
+ jaddstr(payment,"alicetx",hexstr);
+ }
+ else
+ {
+ coin = mp->base.name;
+ paytoshis = mp->base.satoshis;
+ if ( subatomic_zonly(&mp->base) != 0 )
+ dest = mp->alice.recvZaddr;
+ else dest = mp->alice.recvaddr;
+ sprintf(numstr,"%llu",(long long)paytoshis);
+ jaddstr(payment,"bobpays",numstr);
+ jaddstr(payment,"alicedestaddr",dest);
+ txid = subatomic_coinpayment(mp->origid,mp->OTCmode,&mp->base,dest,paytoshis,mp->approval,mp->alice.secp,senderpub);
+ jaddbits256(payment,"bobpayment",txid);
+ mp->bobpayment = txid;
+ hexstr = 0; // get it from rawtransaction of txid
+ jaddstr(payment,"bobtx",hexstr);
+ }
+ hexstr = subatomic_submit(payment,!mp->bobflag);
+ if ( (retjson= dpow_broadcast(SUBATOMIC_PRIORITY,hexstr,(char *)"inbox",(char *)"payment",senderpub,"","")) != 0 )
+ {
+ if ( (mp->paymentids[0]= juint(retjson,"id")) != 0 )
+ retval = 1;
+ printf("%u: %.8f %s -> %s, paymentid[0] %u\n",mp->origid,dstr(paytoshis),coin,dest,mp->paymentids[0]);
+ subatomic_status(mp,SUBATOMIC_PAYMENT);
+ free_json(retjson);
+ }
+ free(hexstr);
+ return(retval);
+}
+
+int32_t subatomic_paidinfull(struct msginfo *mp,cJSON *paid,cJSON *msgjson,char *senderpub)
+{
+ char *hexstr; cJSON *retjson; int32_t retval = 0;
+ jaddstr(paid,"paid","in full");
+ subatomic_extrafields(paid,msgjson);
+ hexstr = subatomic_submit(paid,!mp->bobflag);
+ if ( (retjson= dpow_broadcast(SUBATOMIC_PRIORITY,hexstr,(char *)"inbox",(char *)"paid",senderpub,"","")) != 0 )
+ {
+ if ( (mp->paidid= juint(retjson,"id")) != 0 )
+ retval = 1;
+ printf("%u paidid.%u\n",mp->origid,mp->paidid);
+ subatomic_status(mp,SUBATOMIC_PAIDINFULL);
+ free_json(retjson);
+ }
+ free(hexstr);
+ return(retval);
+}
+
+int32_t subatomic_closed(struct msginfo *mp,cJSON *closed,cJSON *msgjson,char *senderpub)
+{
+ char *hexstr; cJSON *retjson; int32_t retval = 0;
+ jaddnum(closed,"closed",mp->origid);
+ subatomic_extrafields(closed,msgjson);
+ hexstr = subatomic_submit(closed,!mp->bobflag);
+ if ( (retjson= dpow_broadcast(SUBATOMIC_PRIORITY,hexstr,(char *)"inbox",(char *)"closed",senderpub,"","")) != 0 )
+ {
+ if ( (mp->closedid= juint(retjson,"id")) != 0 )
+ retval = 1;
+ subatomic_status(mp,SUBATOMIC_CLOSED);
+ printf("%u closedid.%u\n",mp->origid,mp->closedid);
+ free_json(retjson);
+ }
+ free(hexstr);
+ return(retval);
+}
+
+uint32_t subatomic_alice_openrequest(struct msginfo *origmp)
+{
+ struct msginfo *mp; cJSON *retjson,*openrequest; char *hexstr,*str,tmpstr[32];
+ mp = subatomic_tracker(origmp->origid);
+ mp->origid = origmp->origid;
+ mp->rel.satoshis = origmp->rel.satoshis;
+ mp->rel.istoken = origmp->rel.istoken;
+ strcpy(mp->rel.tokenid,origmp->rel.tokenid);
+ strcpy(mp->rel.name,origmp->rel.name);
+ strcpy(mp->rel.coin,subatomic_checkname(tmpstr,mp,1,origmp->rel.name));
+ strcpy(mp->alice.pubkey,DPOW_pubkeystr);
+ strcpy(mp->alice.secp,DPOW_secpkeystr);
+ strcpy(mp->alice.recvZaddr,DPOW_recvZaddr);
+ strcpy(mp->alice.recvaddr,DPOW_recvaddr);
+ printf("rel.%s/%s %s openrequest %u status.%d (%s/%s)\n",mp->rel.name,mp->rel.coin,mp->rel.tokenid,mp->origid,mp->status,mp->alice.recvaddr,mp->alice.recvZaddr);
+ if ( mp->status == 0 && subatomic_orderbook_mpset(mp,"") != 0 )
+ {
+ strcpy(mp->bob.pubkey,mp->senderpub);
+ if ( subatomic_zonly(&mp->base) != 0 || subatomic_zonly(&mp->rel) != 0 )
+ mp->OTCmode = 1;
+ else mp->OTCmode = SUBATOMIC_OTCDEFAULT;
+ strcpy(origmp->base.name,mp->base.name);
+ strcpy(origmp->base.coin,mp->base.coin);
+ origmp->base.istoken = mp->base.istoken;
+ strcpy(origmp->base.tokenid,mp->base.tokenid);
+ origmp->OTCmode = mp->OTCmode;
+ if ( mp->rel.istoken != 0 && ((mp->rel.satoshis % SATOSHIDEN) != 0 || mp->rel.iszaddr != 0) )
+ {
+ printf("%u cant do zaddr or fractional rel %s.%s tokens %.8f\n",mp->origid,mp->rel.coin,mp->rel.tokenid,dstr(mp->rel.satoshis));
+ return(0);
+ }
+ else if ( mp->base.istoken != 0 && ((mp->base.satoshis % SATOSHIDEN) != 0 || mp->base.iszaddr != 0 ) )
+ {
+ printf("%u cant do zaddr or fractional base %s.%s tokens %.8f\n",mp->origid,mp->base.coin,mp->base.tokenid,dstr(mp->base.satoshis));
+ return(0);
+ }
+ else if ( (openrequest= subatomic_mpjson(mp)) != 0 )
+ {
+ hexstr = subatomic_submit(openrequest,!mp->bobflag);
+ if ( (retjson= dpow_broadcast(SUBATOMIC_PRIORITY,hexstr,(char *)"inbox",(char *)"openrequest",mp->bob.pubkey,"","")) != 0 )
+ {
+ mp->openrequestid = juint(retjson,"id");
+ printf("%u openrequest.%u -> (%s)\n",mp->origid,mp->openrequestid,mp->bob.pubkey);
+ subatomic_status(mp,SUBATOMIC_OPENREQUEST);
+ free_json(retjson);
+ }
+ free(hexstr);
+ }
+ }
+ return(mp->openrequestid);
+}
+
+void subatomic_bob_gotopenrequest(uint32_t inboxid,char *senderpub,cJSON *msgjson,char *basename,char *relname)
+{
+ struct msginfo *mp; cJSON *approval; int32_t origid; char *addr,tmpstr[32],*coin,*acname="";
+ origid = juint(msgjson,"origid");
+ mp = subatomic_tracker(origid);
+ strcpy(mp->base.name,basename);
+ strcpy(mp->base.coin,subatomic_checkname(tmpstr,mp,0,basename));
+ strcpy(mp->rel.name,relname);
+ strcpy(mp->rel.coin,subatomic_checkname(tmpstr,mp,1,relname));
+ mp->origid = origid;
+ mp->rel.satoshis = j64bits(msgjson,"relsatoshis");
+ mp->bobflag = 1;
+ strcpy(mp->bob.pubkey,DPOW_pubkeystr);
+ strcpy(mp->bob.secp,DPOW_secpkeystr);
+ strcpy(mp->bob.recvZaddr,DPOW_recvZaddr);
+ strcpy(mp->bob.recvaddr,DPOW_recvaddr);
+ if ( (addr= jstr(msgjson,"aliceaddr")) != 0 )
+ strcpy(mp->alice.recvaddr,addr);
+ if ( (addr= jstr(msgjson,"aliceZaddr")) != 0 )
+ strcpy(mp->alice.recvZaddr,addr);
+ if ( (addr= jstr(msgjson,"alicesecp")) != 0 )
+ strcpy(mp->alice.secp,addr);
+ if ( subatomic_zonly(&mp->base) != 0 || subatomic_zonly(&mp->rel) != 0 )
+ mp->OTCmode = 1;
+ else mp->OTCmode = SUBATOMIC_OTCDEFAULT;
+ printf("%u got open request\n",mp->origid);
+ if ( mp->status == 0 && subatomic_orderbook_mpset(mp,basename) != 0 && (approval= subatomic_mpjson(mp)) != 0 )
+ {
+ if ( mp->rel.istoken != 0 && ((mp->rel.satoshis % SATOSHIDEN) != 0 || mp->rel.iszaddr != 0) )
+ {
+ printf("%u cant do zaddr or fractional rel %s.%s tokens %.8f\n",mp->origid,mp->rel.coin,mp->rel.tokenid,dstr(mp->rel.satoshis));
+ subatomic_closed(mp,approval,msgjson,senderpub);
+ return;
+ }
+ else if ( mp->base.istoken != 0 && ((mp->base.satoshis % SATOSHIDEN) != 0 || mp->base.iszaddr != 0 ) )
+ {
+ printf("%u cant do zaddr or fractional base %s.%s tokens %.8f\n",mp->origid,mp->base.coin,mp->base.tokenid,dstr(mp->base.satoshis));
+ subatomic_closed(mp,approval,msgjson,senderpub);
+ return;
+ }
+ else if ( subatomic_getbalance(&mp->base) < mp->base.satoshis )
+ {
+ printf("%u bob node low on %s funds! %.8f not enough for %.8f\n",mp->origid,mp->base.coin,dstr(subatomic_getbalance(&mp->base)),dstr(mp->base.satoshis));
+ subatomic_closed(mp,approval,msgjson,senderpub);
+ }
+ else
+ {
+ printf("%u bob (%s/%s) gotopenrequest origid.%u status.%d (%s/%s) SENDERPUB.(%s)\n",mp->origid,mp->base.name,mp->rel.name,mp->origid,mp->status,mp->bob.recvaddr,mp->bob.recvZaddr,senderpub);
+ subatomic_approved(mp,approval,msgjson,senderpub);
+ }
+ }
+}
+
+int32_t subatomic_channelapproved(uint32_t inboxid,char *senderpub,cJSON *msgjson,struct msginfo *origmp)
+{
+ struct msginfo *mp; cJSON *approval; char *addr,*coin,*acname; int32_t retval = 0;
+ mp = subatomic_tracker(juint(msgjson,"origid"));
+ if ( subatomic_orderbook_mpset(mp,mp->base.name) != 0 && (approval= subatomic_mpjson(mp)) != 0 )
+ {
+ printf("%u iambob.%d (%s/%s) channelapproved origid.%u status.%d\n",mp->origid,mp->bobflag,mp->base.name,mp->rel.name,mp->origid,mp->status);
+ if ( mp->bobflag == 0 && mp->status == SUBATOMIC_OPENREQUEST )
+ {
+ if ( (addr= jstr(msgjson,"bobaddr")) != 0 )
+ strcpy(mp->bob.recvaddr,addr);
+ if ( (addr= jstr(msgjson,"bobZaddr")) != 0 )
+ strcpy(mp->bob.recvZaddr,addr);
+ if ( (addr= jstr(msgjson,"bobsecp")) != 0 )
+ strcpy(mp->bob.secp,addr);
+ retval = subatomic_approved(mp,approval,msgjson,senderpub);
+ }
+ else if ( mp->bobflag != 0 && mp->status == SUBATOMIC_APPROVED )
+ retval = subatomic_opened(mp,approval,msgjson,senderpub);
+ }
+ return(retval);
+}
+
+int32_t subatomic_incomingopened(uint32_t inboxid,char *senderpub,cJSON *msgjson,struct msginfo *origmp)
+{
+ struct msginfo *mp; cJSON *payment; int32_t retval = 0;
+ mp = subatomic_tracker(juint(msgjson,"origid"));
+ if ( subatomic_orderbook_mpset(mp,mp->base.name) != 0 && (payment= subatomic_mpjson(mp)) != 0 )
+ {
+ printf("%u iambob.%d (%s/%s) incomingchannel status.%d\n",mp->origid,mp->bobflag,mp->base.name,mp->rel.name,mp->status);
+ if ( mp->bobflag == 0 && mp->status == SUBATOMIC_APPROVED )
+ retval = subatomic_payment(mp,payment,msgjson,senderpub);
+ else if ( mp->bobflag != 0 && mp->status == SUBATOMIC_OPENED )
+ retval = 1; // nothing to do
+ }
+ return(retval);
+}
+
+int32_t subatomic_incomingpayment(uint32_t inboxid,char *senderpub,cJSON *msgjson,struct msginfo *origmp)
+{
+ static FILE *fp;
+ struct msginfo *mp; cJSON *pay,*rawtx,*retjson; bits256 txid; char str[65],*hexstr; int32_t retval = 0;
+ mp = subatomic_tracker(juint(msgjson,"origid"));
+ if ( subatomic_orderbook_mpset(mp,mp->base.name) != 0 && (pay= subatomic_mpjson(mp)) != 0 )
+ {
+ printf("%u iambob.%d (%s/%s) incomingpayment status.%d\n",mp->origid,mp->bobflag,mp->base.name,mp->rel.name,mp->status);
+ if ( mp->bobflag == 0 )
+ {
+ txid = jbits256(msgjson,"bobpayment");
+ jaddbits256(msgjson,"alicepayment",mp->alicepayment);
+ printf("%u alice waits for %s.%s to be in mempool (%.8f -> %s)\n",mp->origid,mp->base.name,bits256_str(str,txid),dstr(mp->base.satoshis),subatomic_zonly(&mp->base) == 0 ? mp->alice.recvaddr : mp->alice.recvZaddr);
+ hexstr = jstr(msgjson,"bobtx");
+ if ( (rawtx= subatomic_txidwait(&mp->base,txid,hexstr,SUBATOMIC_TIMEOUT,senderpub)) != 0 )
+ {
+ if ( subatomic_verifypayment(&mp->base,rawtx,mp->base.satoshis,subatomic_zonly(&mp->base) == 0 ? mp->alice.recvaddr : mp->alice.recvZaddr,txid) >= 0 )
+ mp->gotpayment = 1;
+ free_json(rawtx);
+ }
+ if ( mp->gotpayment != 0 )
+ {
+ printf("%u SWAP COMPLETE <<<<<<<<<<<<<<<<\n",mp->origid);
+ SUBATOMIC_retval = 0;
+ if ( mp->base.iszaddr == 0 )
+ {
+ sprintf(str,"%u",mp->origid);
+ if ( (retjson= dpow_broadcast(SUBATOMIC_PRIORITY,bits256_str(str,mp->alicepayment),(char *)"completed",str,DPOW_pubkeystr,"","")) != 0 )
+ free_json(retjson);
+ }
+ }
+ else
+ {
+ printf("%u SWAP INCOMPLETE, waiting on %s.%s\n",mp->origid,mp->base.name,bits256_str(str,txid));
+ if ( (fp= fopen("SUBATOMIC.incomplete","a+")) != 0 )
+ {
+ char *jsonstr = jprint(msgjson,0);
+ fwrite(jsonstr,1,strlen(jsonstr),fp);
+ fputc('\n',fp);
+ fclose(fp);
+ free(jsonstr);
+ }
+ if ( mp->base.iszaddr == 0 )
+ {
+ sprintf(str,"%u",mp->origid);
+ if ( (retjson= dpow_broadcast(SUBATOMIC_PRIORITY,bits256_str(str,mp->alicepayment),(char *)"incomplete",str,DPOW_pubkeystr,"","")) != 0 )
+ free_json(retjson);
+ }
+ subatomic_closed(mp,pay,msgjson,senderpub);
+ exit(-1);
+ }
+ }
+ if ( mp->gotpayment != 0 )
+ retval = subatomic_paidinfull(mp,pay,msgjson,senderpub);
+ else
+ {
+ if ( mp->bobflag != 0 && mp->status == SUBATOMIC_OPENED )
+ {
+ txid = jbits256(msgjson,"alicepayment");
+ printf("%u bob waits for %s.%s to be in mempool (%.8f -> %s)\n",mp->origid,mp->rel.name,bits256_str(str,txid),dstr(mp->rel.satoshis),subatomic_zonly(&mp->rel) == 0 ? mp->bob.recvaddr : mp->bob.recvZaddr);
+ hexstr = jstr(msgjson,"alicetx");
+ if ( (rawtx= subatomic_txidwait(&mp->rel,txid,hexstr,SUBATOMIC_TIMEOUT,senderpub)) != 0 )
+ {
+ if ( subatomic_verifypayment(&mp->rel,rawtx,mp->rel.satoshis,subatomic_zonly(&mp->rel) == 0 ? mp->bob.recvaddr : mp->bob.recvZaddr,txid) >= 0 )
+ mp->gotpayment = 1;
+ free_json(rawtx);
+ }
+ if ( mp->gotpayment != 0 )
+ {
+ retval = subatomic_payment(mp,pay,msgjson,senderpub);
+ jaddbits256(msgjson,"bobpayment",mp->bobpayment);
+ if ( mp->rel.iszaddr == 0 )
+ {
+ sprintf(str,"%u",mp->origid);
+ if ( (retjson= dpow_broadcast(SUBATOMIC_PRIORITY,bits256_str(str,mp->bobpayment),(char *)"completed",str,DPOW_pubkeystr,"","")) != 0 )
+ free_json(retjson);
+ }
+ printf("%u SWAP COMPLETE <<<<<<<<<<<<<<<<\n",mp->origid);
+ if ( (fp= fopen("SUBATOMIC.proof","rb+")) == 0 )
+ fp = fopen("SUBATOMIC.proof","wb");
+ if ( fp != 0 )
+ {
+ char *jsonstr = jprint(msgjson,0);
+ fseek(fp,0,SEEK_END);
+ fwrite(jsonstr,1,strlen(jsonstr),fp);
+ fputc('\n',fp);
+ fflush(fp);
+ free(jsonstr);
+ }
+ } else printf("%u SWAP INCOMPLETE: %s\n",mp->origid,jprint(msgjson,0));
+ }
+ }
+ }
+ return(retval);
+}
+
+int32_t subatomic_incomingfullypaid(uint32_t inboxid,char *senderpub,cJSON *msgjson,struct msginfo *origmp)
+{
+ struct msginfo *mp; cJSON *closed; int32_t retval = 0;
+ mp = subatomic_tracker(juint(msgjson,"origid"));
+ if ( subatomic_orderbook_mpset(mp,mp->base.name) != 0 && (closed= subatomic_mpjson(mp)) != 0 )
+ {
+ printf("%u iambob.%d (%s/%s) incomingfullypaid status.%d\n",mp->origid,mp->bobflag,mp->base.name,mp->rel.name,mp->status);
+ // error check msgjson vs M
+ if ( mp->bobflag == 0 && mp->status == SUBATOMIC_PAIDINFULL )
+ retval = subatomic_closed(mp,closed,msgjson,senderpub);
+ else if ( mp->bobflag != 0 && mp->status == SUBATOMIC_PAYMENT )
+ retval = subatomic_paidinfull(mp,closed,msgjson,senderpub);
+ }
+ return(retval);
+}
+
+int32_t subatomic_incomingclosed(uint32_t inboxid,char *senderpub,cJSON *msgjson,struct msginfo *origmp)
+{
+ struct msginfo *mp; cJSON *closed; int32_t retval = 0;
+ mp = subatomic_tracker(juint(msgjson,"origid"));
+ if ( subatomic_orderbook_mpset(mp,mp->base.name) != 0 && (closed= subatomic_mpjson(mp)) != 0 )
+ {
+ printf("%u iambob.%d (%s/%s) incomingclose status.%d\n",mp->origid,mp->bobflag,mp->base.name,mp->rel.name,mp->status);
+ if ( mp->bobflag != 0 )
+ dpow_cancel(mp->origid);
+ if ( mp->status < SUBATOMIC_CLOSED )
+ {
+ retval = subatomic_closed(mp,closed,msgjson,senderpub);
+ subatomic_status(mp,SUBATOMIC_CLOSED);
+ }
+ retval = 1;
+ }
+ return(retval);
+}
+
+int32_t subatomic_ismine(int32_t bobflag,cJSON *json,char *basename,char *relname)
+{
+ char *base,*rel;
+ if ( (base= jstr(json,"base")) != 0 && (rel= jstr(json,"rel")) != 0 )
+ {
+ if ( strcmp(base,basename) == 0 && strcmp(rel,relname) == 0 )
+ return(1);
+ if ( bobflag != 0 )
+ {
+ if ( strcmp(basename,"#allfiles") == 0 && base[0] == '#' )
+ return(1);
+ fprintf(stderr,"skip ismine (%s/%s) vs (%s/%s)\n",basename,relname,base,rel);
+ }
+ }
+ return(0);
+}
+
+void subatomic_tokensregister(int32_t priority)
+{
+ char *token_name,*tokenid,existing[65]; cJSON *tokens,*token; int32_t i,numtokens;
+ if ( SUBATOMIC_json != 0 && (tokens= jarray(&numtokens,SUBATOMIC_json,"tokens")) != 0 )
+ {
+ for (i=0; i 0 )
+ {
+ for (j=0; j %s, %u %llu %u\n",mp->bobflag,mp->base.name,mp->rel.name,mp->origid,(long long)mp->rel.satoshis,mp->openrequestid);
+ while ( 1 )
+ {
+ if ( msgs == 0 )
+ {
+ sleep(1);
+ fflush(stdout);
+ if ( mp->bobflag != 0 )
+ {
+ dpow_pubkeyregister(SUBATOMIC_PRIORITY);
+ subatomic_tokensregister(SUBATOMIC_PRIORITY);
+ subatomic_filesregister(SUBATOMIC_PRIORITY);
+ }
+ }
+ msgs = 0;
+ for (iter=0; iter<(int32_t)(sizeof(tagBs)/sizeof(*tagBs)); iter++)
+ {
+ tagB = tagBs[iter];
+ if ( (ptrs= dpow_inboxcheck(&n,&stopats[iter],tagB)) != 0 )
+ {
+ for (i=0; ijsonstr)) != 0 )
+ {
+ if ( jint(inboxjson,"tobob") != mp->bobflag )
+ continue;
+ if ( subatomic_ismine(mp->bobflag,inboxjson,mp->base.name,mp->rel.name) != 0 )
+ {
+ if ( strcmp(tagB,"openrequest") == 0 && mp->bobflag != 0 )
+ subatomic_bob_gotopenrequest(ptr->shorthash,ptr->senderpub,inboxjson,mp->base.name,mp->rel.name);
+ else if ( strcmp(tagB,"approved") == 0 )
+ mask |= subatomic_channelapproved(ptr->shorthash,ptr->senderpub,inboxjson,mp) << 0;
+ else if ( strcmp(tagB,"opened") == 0 )
+ mask |= subatomic_incomingopened(ptr->shorthash,ptr->senderpub,inboxjson,mp) << 1;
+ else if ( strcmp(tagB,"payment") == 0 )
+ mask |= subatomic_incomingpayment(ptr->shorthash,ptr->senderpub,inboxjson,mp) << 2;
+ else if ( strcmp(tagB,"paid") == 0 )
+ mask |= subatomic_incomingfullypaid(ptr->shorthash,ptr->senderpub,inboxjson,mp) << 3;
+ else if ( strcmp(tagB,"closed") == 0 )
+ mask |= subatomic_incomingclosed(ptr->shorthash,ptr->senderpub,inboxjson,mp) * 0x1f;
+ else fprintf(stderr,"iambob.%d unknown unexpected tagB.(%s)\n",mp->bobflag,tagB);
+ }
+ free_json(inboxjson);
+ } else fprintf(stderr,"subatomic iambob.%d loop got unparseable(%s)\n",mp->bobflag,ptr->jsonstr);
+ free(ptr);
+ ptrs[i] = 0;
+ }
+ }
+ free(ptrs);
+ }
+ }
+ if ( mp->bobflag == 0 && (mask & 0x1f) == 0x1f )
+ {
+ printf("alice %u %llu %u finished\n",mp->origid,(long long)mp->rel.satoshis,mp->openrequestid);
+ break;
+ }
+ }
+}
+
+int32_t main(int32_t argc,char **argv)
+{
+ char *fname = "subatomic.json";
+ int32_t i,height; char *coin,*kcli,*subatomic,*hashstr,*acname=(char *)""; cJSON *retjson; bits256 blockhash; char checkstr[65],str[65],str2[65],tmpstr[32]; long fsize; struct msginfo M;
+ memset(&M,0,sizeof(M));
+ srand((int32_t)time(NULL));
+ if ( (subatomic= filestr(&fsize,fname)) == 0 )
+ {
+ fprintf(stderr,"cant load %s file\n",fname);
+ exit(-1);
+ }
+ if ( (SUBATOMIC_json= cJSON_Parse(subatomic)) == 0 )
+ {
+ fprintf(stderr,"cant parse subatomic.json file (%s)\n",subatomic);
+ exit(-1);
+ }
+ free(subatomic);
+ if ( argc >= 4 )
+ {
+ if ( dpow_pubkey() < 0 )
+ {
+ fprintf(stderr,"couldnt set pubkey for DEX\n");
+ return(-1);
+ }
+ coin = (char *)argv[1];
+ if ( argv[2][0] != 0 )
+ REFCOIN_CLI = (char *)argv[2];
+ else
+ {
+ if ( strcmp(coin,"KMD") != 0 )
+ {
+ acname = coin;
+ }
+ }
+ hashstr = (char *)argv[3];
+ strcpy(M.rel.coin,subatomic_checkname(tmpstr,&M,1,coin));
+ strcpy(M.rel.name,coin);
+ if ( argc == 4 && strlen(hashstr) == 64 ) // for blocknotify usage, seems not needed
+ {
+ height = get_coinheight(coin,acname,&blockhash);
+ bits256_str(checkstr,blockhash);
+ if ( strcmp(checkstr,hashstr) == 0 )
+ {
+ fprintf(stderr,"%s: (%s) %s height.%d\n",coin,REFCOIN_CLI!=0?REFCOIN_CLI:"",checkstr,height);
+ if ( (retjson= dpow_ntzdata(coin,SUBATOMIC_PRIORITY,height,blockhash)) != 0 )
+ free_json(retjson);
+ } else fprintf(stderr,"coin.%s (%s) %s vs %s, height.%d\n",coin,REFCOIN_CLI!=0?REFCOIN_CLI:"",checkstr,hashstr,height);
+ if ( strcmp("BTC",coin) != 0 )
+ {
+ bits256 prevntzhash,ntzhash; int32_t prevntzheight,ntzheight; uint32_t ntztime,prevntztime; char hexstr[81]; cJSON *retjson2;
+ prevntzhash = dpow_ntzhash(coin,&prevntzheight,&prevntztime);
+ if ( (retjson= get_getinfo(coin,acname)) != 0 )
+ {
+ ntzheight = juint(retjson,"notarized");
+ ntzhash = jbits256(retjson,"notarizedhash");
+ if ( ntzheight > prevntzheight )
+ {
+ get_coinmerkleroot(coin,acname,ntzhash,&ntztime);
+ fprintf(stderr,"NOTARIZATION %s.%d %s t.%u\n",coin,ntzheight,bits256_str(str,ntzhash),ntztime);
+ bits256_str(hexstr,ntzhash);
+ sprintf(&hexstr[64],"%08x",ntzheight);
+ sprintf(&hexstr[72],"%08x",ntztime);
+ hexstr[80] = 0;
+ if ( (retjson2= dpow_broadcast(SUBATOMIC_PRIORITY,hexstr,coin,"notarizations",DPOW_pubkeystr,"","")) != 0 )
+ free_json(retjson2);
+ }
+ else if ( ntzheight == prevntzheight && memcmp(&prevntzhash,&ntzhash,32) != 0 )
+ fprintf(stderr,"NTZ ERROR %s.%d %s != %s\n",coin,ntzheight,bits256_str(str,ntzhash),bits256_str(str2,prevntzhash));
+ free_json(retjson);
+ }
+ }
+ }
+ else if ( argc == 5 && atol(hashstr) > 10000 )
+ {
+ char checkstr[32]; uint64_t mult = 1;
+ M.origid = (uint32_t)atol(hashstr);
+ sprintf(checkstr,"%u",M.origid);
+ if ( strcmp(checkstr,hashstr) == 0 ) // alice
+ {
+ M.rel.satoshis = (uint64_t)(atof(argv[4])*SATOSHIDEN+0.0000000049999);
+ for (i=0; M.rel.name[i]!=0; i++)
+ if ( M.rel.name[i] == '.' )
+ {
+ mult = SATOSHIDEN;
+ break;
+ }
+ if ( subatomic_getbalance(&M.rel) < M.rel.satoshis/mult )
+ {
+ fprintf(stderr,"not enough balance %s %.8f for %.8f\n",M.rel.coin,dstr(subatomic_getbalance(&M.rel)),dstr(M.rel.satoshis/mult));
+ return(-1);
+ }
+ fprintf(stderr,"subatomic_channel_alice (%s/%s) %s %u with %.8f %llu\n",M.rel.name,M.rel.coin,hashstr,M.origid,atof(argv[4]),(long long)M.rel.satoshis);
+ dpow_pubkeyregister(SUBATOMIC_PRIORITY);
+ M.openrequestid = subatomic_alice_openrequest(&M);
+ if ( M.openrequestid != 0 )
+ subatomic_loop(&M);
+ } else fprintf(stderr,"checkstr mismatch %s %s != %s\n",coin,hashstr,checkstr);
+ }
+ else
+ {
+ M.bobflag = 1;
+ strcpy(M.base.name,hashstr);
+ strcpy(M.base.coin,subatomic_checkname(tmpstr,&M,0,hashstr));
+ subatomic_loop(&M); // while ( 1 ) loop for each relcoin -> basecoin
+ }
+ }
+ return(SUBATOMIC_retval);
+}
+
diff --git a/src/cc/dapps/subatomic.json b/src/cc/dapps/subatomic.json
new file mode 100644
index 000000000..7832fdb9e
--- /dev/null
+++ b/src/cc/dapps/subatomic.json
@@ -0,0 +1,27 @@
+{
+"authorized": [
+ {"chmex":"030754bffcf6dfcb34a20c486ff5a5be5546b9cc16fba9692165272b3f8e98c4af" },
+ {"SHossain":"03c8657bd57b6ceb14514a10e99fe8a0cec5a9bc24592df7f66f050e670e4f6bac" },
+ {"satinder":"03732f8ef851ff234c74d0df575c2c5b159e2bab3faca4ec52b3f217d5cda5361d" },
+ {"ml777":"02453d028c74cb9551e1aaf35113383b6ecbd9f06ff23a4ab1a953429b9763e345" },
+ {"tonylhub":"0218e0f435d4544404c25a7759b7f7174d821215085ef936218c5569d975af468b" },
+ {"gthub":"036c7de9a5090fbad78b9eea41549ccacc07bd0e9e7f8d290c88f470f3569e1a35" },
+ {"zkTrader":"026c6b0b35ec0adc2f8a5c648da1fce634f798c69d5e9fe518400447e88398b830" },
+ {"nutellalicka":"03aee08860e0340f0f490a3ef3718d6676882f2d63d4f536dfebb1d348b82c79ee" },
+ {"gcharang":"02d3431950c2f0f9654217b6ce3d44468d3a9ca7255741767fdeee7c5ec6b47567" },
+ {"jl777":"02b27de3ee5335518b06f69f4fbabb029cfc737613b100996841d5532b324a5a61" }
+],
+"tokens":[
+ {"RICK.demo":"2b1feef719ecb526b07416dd432bce603ac6dc8bfe794cddf105cb52f6aae3cd"}
+],
+"files":[
+ {"filename":"hushd","prices":[{"HUSH":0.1}, {"PIRATE":1}]}
+],
+"externalcoins":[
+ { "BTC":"bitcoin-cli" },
+ { "KMD":"komodod-cli" },
+ { "CHIPS":"chips-cli" },
+ { "PIRATE":"pirate-cli" }
+]
+}
+
diff --git a/src/cc/makecustom b/src/cc/makecustom
index 7f1c789c9..3516b4023 100755
--- a/src/cc/makecustom
+++ b/src/cc/makecustom
@@ -1,5 +1,5 @@
#!/bin/sh
-if make -f Makefile_custom "$@"; then
+if HOST="$HOST" make -B -f Makefile_custom "$@"; then
echo CUSTOMCC BUILD SUCCESSFUL
else
echo CUSTOMCC BUILD FAILED
diff --git a/src/chain.cpp b/src/chain.cpp
index f8530056d..bd2a01c82 100644
--- a/src/chain.cpp
+++ b/src/chain.cpp
@@ -2,8 +2,8 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
// Copyright (c) 2019-2020 The Hush developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/chain.h b/src/chain.h
index 03fc75660..548c9327c 100644
--- a/src/chain.h
+++ b/src/chain.h
@@ -1,8 +1,8 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Copyright (c) 2019 The Hush developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
@@ -276,9 +276,12 @@ public:
//! inputs and outputs.
int64_t nShieldedTx;
- //! (memory only) Number of shielded outputs in the block up to and including this block.
+ //! (memory only) Number of shielded outputs
int64_t nShieldedOutputs;
+ //! (memory only) Number of shielded spends
+ int64_t nShieldedSpends;
+
//! (memory only) Number of fully shielded transactions. A fully shielded transaction is defined
//! as a transaction containing JoinSplits and only shielded inputs and outputs, i.e. no transparent
// inputs or outputs: z->z or z->(z,z) or z->(z,z,z,) etc...
@@ -332,6 +335,9 @@ public:
//! (memory only) Number of shielded outputs in the chain up to and including this block.
int64_t nChainShieldedOutputs;
+ //! (memory only) Number of shielded spends in the chain up to and including this block.
+ int64_t nChainShieldedSpends;
+
//! (memory only) Number of fully shielded transactions. A fully shielded transaction is defined
//! as a transaction containing JoinSplits and only shielded inputs and outputs, i.e. no transparent
// inputs or outputs: z->z or z->(z,z) or z->(z,z,z,) etc...
@@ -429,18 +435,20 @@ public:
nChainNotarizations = 0;
nChainFullyShieldedTx = 0;
nChainShieldedOutputs = 0;
+ nChainShieldedSpends = 0;
nChainShieldedPayments = 0;
nChainShieldingPayments = 0;
nChainDeshieldingPayments = 0;
nChainFullyShieldedPayments = 0;
- // Shieldex Index stats
+ // Shielded Index stats
nPayments = 0;
nShieldedTx = 0;
nShieldingTx = 0;
nNotarizations = 0;
nDeshieldingTx = 0;
nShieldedOutputs = 0;
+ nShieldedSpends = 0;
nFullyShieldedTx = 0;
nShieldedPayments = 0;
nShieldingPayments = 0;
@@ -679,6 +687,7 @@ public:
READWRITE(nDeshieldingPayments);
READWRITE(nFullyShieldedPayments);
READWRITE(nShieldedOutputs);
+ READWRITE(nShieldedSpends);
}
}
diff --git a/src/chainparams.cpp b/src/chainparams.cpp
index 0a2b819e7..d8a82f27b 100644
--- a/src/chainparams.cpp
+++ b/src/chainparams.cpp
@@ -1,8 +1,8 @@
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
// Copyright (c) 2019-2020 The Hush developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
@@ -544,6 +544,14 @@ int32_t MAX_BLOCK_SIZE(int32_t height)
else return(2000000);
}
+// Change the Hush blocktime at run-time(!)
+void hush_changeblocktime()
+{
+ pCurrentParams->consensus.nMaxFutureBlockTime = 7 * ASSETCHAINS_BLOCKTIME;
+ pCurrentParams->consensus.nPowTargetSpacing = ASSETCHAINS_BLOCKTIME;
+ fprintf(stderr,"HUSH blocktime changing to %d seconds\n",ASSETCHAINS_BLOCKTIME);
+}
+
void komodo_setactivation(int32_t height)
{
pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = height;
@@ -585,153 +593,79 @@ void *chainparams_commandline()
pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = ASSETCHAINS_OVERWINTER;
// Generated at 1575831755 via hush3 contrib/checkpoints.pl by Duke Leto
if (strcmp(ASSETCHAINS_SYMBOL,"HUSH3") == 0) {
+ // Generated at 1596199654 via hush3 contrib/checkpoints.pl by Duke Leto
checkpointData = //(Checkpoints::CCheckpointData)
{
boost::assign::map_list_of
(0, pCurrentParams->consensus.hashGenesisBlock)
- (1000, uint256S("0x0000001893130f005d2e90fcdf40057ae06390bd0490740aae2843e62aeb7bc2"))
- (2000, uint256S("0x00000003003e6c8fa176ef293d1322514778343601fa21dfdb0c9aacef189576"))
- (3000, uint256S("0x00000005c1419d252bc59d77c06e07aad61702c8b3e76d2070577a18159ab59d"))
- (4000, uint256S("0x00000008bc4094ea475a871302361ffdc6bfd63ded049d172c8dad01ed67fd3c"))
- (5000, uint256S("0x000000018f8543066baa9c5f83e981749da4cb625fad02c187b4a9c4693ebd60"))
- (6000, uint256S("0x0000000567191591911b33b852e4b87de119df2c773bc800b5a3655be18eb98e"))
- (7000, uint256S("0x000000082e7b000480d0317d9115f0d0737e78fa2381a2d6456f598bf83fe2f0"))
- (8000, uint256S("0x0000000415226fff123cd868e255a23d72e204d61bb405fb9dde0810e7721ebf"))
- (9000, uint256S("0x00000000bd26f7b8d6d80230aad06c0cd590758176b8558da7dfc14161a23ab7"))
+ // Generated at 1600532337 via hush3 contrib/checkpoints.pl by Duke Leto
+ (5000, uint256S("0x000000018f8543066baa9c5f83e981749da4cb625fad02c187b4a9c4693ebd60"))
(10000, uint256S("0x00000002d177d1cbfeaf7c27a2a32766ea9063d222cbcc7623dc08355b07a3ad"))
- (11000, uint256S("0x0000000284bcffa3bef4097178a94b6b9a788261981253cb8cd6db6b47634732"))
- (12000, uint256S("0x000000006cf15fdb94253a9389d95ef607c3484c635fe0c8a1f1ec1e5a1c6865"))
- (13000, uint256S("0x00000001cdc66e08f7f13c775aa1220a801a33df90edba7bbcffac8d06181207"))
- (14000, uint256S("0x0000000443e432c7dbf0707a12c5671dd1ca606f962368a847bbcff2f5fc2135"))
(15000, uint256S("0x000000008dbfbd5d5e27d819bf2989c5658c3494608bfa1320ad0b090660cd44"))
- (16000, uint256S("0x00000003c6a59e5b10e1a1c6bef08dee4d33d1841156bf97e26c3e4df789b128"))
- (17000, uint256S("0x00000001debe3734ef4b6aacedde4a6b04cd1c60d4cf37b9f4689f2225ff7c24"))
- (18000, uint256S("0x00000002e37eccfa7bacd9c201468c754cbef50be9411e3f907891755eef4c6d"))
- (19000, uint256S("0x000000044636331c0277abb5592529cae1303d2bd43981a8382b4cc152a8d024"))
(20000, uint256S("0x00000000a7840e1fccedb13672804e94fcaa87c0360ee4f7353a6b93e5a59da8"))
- (21000, uint256S("0x00000003a89b17d0cd489045ad62531c4211ee17c3609ed3e4291a067636d526"))
- (22000, uint256S("0x0000000352a7a25b3fe5f1a32a2c42260d32345487b92b6e520eecec0ee6aca4"))
- (23000, uint256S("0x00000002c1fdc5cc1211b7adff3b7e755059638fd98bd9da1cdd86bd9a0af1fd"))
- (24000, uint256S("0x0000000603a6190bbfdcdc5da9645d069aebd7a0b29607077470089c7b4a1188"))
(25000, uint256S("0x0000000519d6ab6ca9c705ebafa9946bce34934709621bc22227567e90608667"))
- (26000, uint256S("0x0000000146e7314e2ebb2bfc10b9fe0fdd744734910a3971bbc4e970fe2c4cb9"))
- (27000, uint256S("0x000000047060e4173b4edd6374c3580580981dea20d0b49ea15c9fdfa97ba104"))
- (28000, uint256S("0x000000065eea521cccf6b1f99e1a77683717d02ddaed654a4c85d717e1e8c957"))
- (29000, uint256S("0x00000001ecdbcd195e04f792721262dc79bb070e73b6606b389825b5ae8e4791"))
(30000, uint256S("0x0000000240de901e9e70d2db5badf62886ab0e8c442107d571bc04b3bdd43052"))
- (31000, uint256S("0x00000002d39f4f3504660e13e956c12aa3411a0ba392b3797d95f15e8fbd1958"))
- (32000, uint256S("0x0000000130cd781ed559d553f35a6bc99ed252aadd92b2a461bd332ca2d69a96"))
- (33000, uint256S("0x000000035ad950b0e78bbaf19f7a97865f29edd600e7aee4a3fce2e42db29d38"))
- (34000, uint256S("0x00000004f33b5ff97c128bfbef656aa10341e2606f54e198d5280016d2578eca"))
(35000, uint256S("0x00000000ad1ef91eb70011a94646c148f1b8949b464a0de82adf1ba1ce6175a5"))
- (36000, uint256S("0x00000003b1450e1cf9f4e5f53534777b24039fcde81ec7ac1c2ea754a26fcd78"))
- (37000, uint256S("0x0000000337c4407954be01dcaf75a660e4b5b69e9e923bd62e74b0e44f01d9df"))
- (38000, uint256S("0x00000002b5d6f83f8d2ef7d88c3cdff1e444882819a70a7c7281d1d92f81bc9a"))
- (39000, uint256S("0x00000001a1eb6a530b065c873f65219de3282c4f386ba68bc2a0b88dc2b4c5cd"))
(40000, uint256S("0x000000013b65e22d0bb6a9103dc71da5a1b7fa2acbc1c7d7a4d8f7730c37d4ab"))
- (41000, uint256S("0x000000027dbc2315769690cf93c79c54e0591c808d83decb66302492f0f79f1c"))
- (42000, uint256S("0x00000000ca09a12162a92b9ecbf6bf00a2bb822a77dd142df26d81db95c21bed"))
- (43000, uint256S("0x000000050c4c80b9e53b960a638bd231c193a383f0df162c720e4594ba427a4b"))
- (44000, uint256S("0x00000000f42d6c43703dbb47847298cedcbef8a27018baed8f4a217e7d5d823c"))
(45000, uint256S("0x00000004da449923c218bd3e69745ebafca41c32e0c81ab6b485ae6c4c80df18"))
- (46000, uint256S("0x00000006e4bdf2707158e266d2d54294b20063c0f1723abed97fafe7ecf4b2de"))
- (47000, uint256S("0x0000000015d099357b0c8cbc24d8e2bd18e5e47eabe6ff89c09c9837bb071cd8"))
- (48000, uint256S("0x00000009c9ddaffefc5d5c78a6f89b872fdd732c16a5311debed6b92255f340b"))
- (49000, uint256S("0x00000008447d907ddc1d87df0ea235636baaaf34bc1000620e8173f1d8f7758c"))
(50000, uint256S("0x000000027470e84cd195242f199b90fde40b70f80fac7a7080b1517c95cf56c6"))
- (51000, uint256S("0x000000015190913dec8a508bc219b0a0a1587b50acb23b48343010015cb5ec69"))
- (52000, uint256S("0x000000071608ad395dc31dc3011d5cad7f7a7296e34490a1e9e2dcf060bcc649"))
- (53000, uint256S("0x0000000608fa8a454c3c0e5e06bf091c4cfa131e7b91eb6622087cfc3fa4c149"))
- (54000, uint256S("0x0000000455eac130c205512cc0bffaa3ecb2d393cbf0d9e943c3d5911ea06a4b"))
(55000, uint256S("0x00000000a20b276ed95b261a51681fb2d0d58e528cc8cd2e5fb7fdeb732b1861"))
- (56000, uint256S("0x000000016057dfbf2fc59650b63b7c2dc2379af75cf00c0ee3f3835e992ec11e"))
- (57000, uint256S("0x00000003a1eff8b5160655111ff1c0f1426b2b879c1f6fd761332b82c8640c67"))
- (58000, uint256S("0x00000001b0ac789061a277b553de1aae373533f5b6b1330326744ac7087c87c9"))
- (59000, uint256S("0x0000000a0dee07bdf593a68e5463cb5553f9bce3367a39d88f07ea43709eba87"))
(60000, uint256S("0x000000060382850eadef184b67f38c0b2de27157296f3d9d8e2b7b70b1f76127"))
- (61000, uint256S("0x0000000492a93fd6c9eb080f3398517b39c8eaf835440d2571e515f76a931bf2"))
- (62000, uint256S("0x00000005ee0b8f7fcae8e6b17b12ab66f17cf34697182afc29d863d9844a84a9"))
- (63000, uint256S("0x000000045842b1c05c7e9a1a887e9a6ecdcaea2f4e03b9476031ed609ace91d2"))
- (64000, uint256S("0x00000004259921159c0714b90b1950fbae7eee2a14687dcfc57ab22b39c8123c"))
(65000, uint256S("0x0000000618eb1c909301585f6b8f17ee6d09da97c580fe70d59babcd7864b556"))
- (66000, uint256S("0x000000049c85139efb1694525b5cf864a6021e49a412aaea9ff2b2b6ee04e1ca"))
- (67000, uint256S("0x0000000141358b3ae2c4ab2a384f963f4fdc925060c42de5578aec82c1de3189"))
- (68000, uint256S("0x0000000405b0273ba96d1e83e27e50ecf5f123c2e3e05b56524cc2cd79ea18e7"))
- (69000, uint256S("0x0000000764c8a434a1583b2578155a18720bbad67cc2c06e2fb013e872b1b10e"))
(70000, uint256S("0x00000006d11cf168399c719b2bb036eadd09e740c98764d82adf75f5a800e90d"))
- (71000, uint256S("0x00000002339c3cf62fc4716899a0e341969d85146dcb98854607332f81e5f258"))
- (72000, uint256S("0x000000055e39f9cd963bac08c9c10ab982491d50b66486099675b015016dad7a"))
- (73000, uint256S("0x0000000766261dbd9e48a0d544d012f57ab7890a761d893851b63e0e5b5e47dc"))
- (74000, uint256S("0x000000058bd8080674ffb086704fbfde45e91172d0784416ed5356d20bd60fd7"))
(75000, uint256S("0x00000007abb9cb521244c988f0ace53bf230bdf9c9db75d0102472a721c6b038"))
- (76000, uint256S("0x000000071789d7ecf5e8c7e1a982e119d0b9d6748cb01426a5b8fff77a54f76b"))
- (77000, uint256S("0x00000007364be847b08481f87bbe4db69a79f5c4388e3c898ea140011a121ca7"))
- (78000, uint256S("0x000000031b7afd1aa244d78056606bf718cb96cb1fe1656070d37ed9d4031ebf"))
- (79000, uint256S("0x00000003125d8e62fa215c1797229d271db705299f43e1db85edb7ac68349127"))
(80000, uint256S("0x000000031c23c3a1828b3a432ab27c6b34a93741f5711507abeb34a822ba5311"))
- (81000, uint256S("0x0000000212aab2361322e29a1037b82624fc2acdb61dd457ae25e4dffca14b42"))
- (82000, uint256S("0x00000003140442a0d3b5ba57d2e51ed4a2ec39fb6ee8c9e2d70d530f46843f57"))
- (83000, uint256S("0x0000000404e963d87db2ccd709377d5fd8b28c67c51ffcace62290844b895ba0"))
- (84000, uint256S("0x00000003076c29391d9a5910e287d5319f4bf29f92eb309a8dd72cbf98847102"))
(85000, uint256S("0x00000006fc5823857bdd44f89f4a97838a9f735c7bdf81bd89f50110dc16fbab"))
- (86000, uint256S("0x00000002247705c4f02ab4a672686dadba9de55fcf71433388a4250af6d1154d"))
- (87000, uint256S("0x00000000302718129c873c0ba6e571512ab5c4216e0d978ed3ef1d4dccddbb26"))
- (88000, uint256S("0x00000002129732e7d8d99d78eef4ed3318cdbd73883d88e7c2b9534d11284486"))
- (89000, uint256S("0x00000001513759a2e2b6e6c30ee8db631957511adcefa518ad31e0b1ec4e789d"))
(90000, uint256S("0x00000003e62dcb81fe33178e2dc45c70ca04733542179ac5d93bceb7c456f365"))
- (91000, uint256S("0x00000000674963dd8d6d7dab67d1df8c6e9455cef55014aa15082722f9d7f115"))
- (92000, uint256S("0x00000004f4e1151df0905baf82bd29ece0fc7db8d96a2ae6c0efad0e0e68e55e"))
- (93000, uint256S("0x00000002876b9eb7b41e025d55d7dd740b5dc811eae0909169081e705c61b6b5"))
- (94000, uint256S("0x00000001efdcd19bf060a424cd0cef2d04f0d206fae21a72a57b4cc8d1019421"))
(95000, uint256S("0x00000002a22cae35b32e31ffbe55d2d56ef04f010aebd19f1536b7582c1ea4d9"))
- (96000, uint256S("0x0000000433d2385e8260c26dabec1c5f7376ed63b478c5d94bc15ee521a86ee3"))
- (97000, uint256S("0x00000003112c73fd4cf10604e1a44b7acd698e196cbe16e63abdcd34008f4b36"))
- (98000, uint256S("0x0000000179fb7ea8e68c54de5d09e531b5cbbfe7f5d128f3f93f55576673ddc7"))
- (99000, uint256S("0x00000002e8e3a9f26154b941837d42ad62ea153d75be61a13c04e2249a781243"))
- (100000, uint256S("0x00000001bc1c40d120bf2df1654f3fb5e4d28d4ff292d05667cf5610042c794a"))
- (101000, uint256S("0x00000003a52ec72d58bdb88096334a29eddb17fd454a7c15aba815358f3b4285"))
- (102000, uint256S("0x00000002a602644eb8765aab158112307f25bc6e8f82c1220be08642be6d12ca"))
- (103000, uint256S("0x000000044a6a0aca758af879fee5bbbfc4ac75287f63cc91ad26bc921d3c44ac"))
- (104000, uint256S("0x000000013fe4abb66862573821938d8e203da577e8c15055249a5fc4d6ca28f6"))
- (105000, uint256S("0x0000000175182a7f9c46aaae8723a664168af4be37c5d73e8f773df6b67a458b"))
- (106000, uint256S("0x000000005426bdc52efa996e5bd44f0d5f075fdd865063a1c5c341f4b37aa8d7"))
- (107000, uint256S("0x000000026ce5ee0c6f81786838f502ab3ac4b52371716b3956bb58f91fe2a79e"))
- (108000, uint256S("0x000000042a0f660df6ef24e237b4010749b7cc7ba402fe7f6af98643df62cb0b"))
- (109000, uint256S("0x000000020debe96d90bc1d317036404c4518309e93c45303f86bdef7fac213df"))
- (110000, uint256S("0x000000030ba3cdbb85d5028379dfe50fbf28c04f8add3300814c2f649ec53594"))
- (111000, uint256S("0x000000030d9aa7e30990157616d54e5c32a26a0fbb5db1a7fde7e192bb2bd992"))
- (112000, uint256S("0x00000003885472c246e7f5cc5c9982ce0d1ed292ff0b09451c272f201ff1bd3a"))
- (113000, uint256S("0x000000027d6d7f782a510fa9b2a41f8f1a713fa4ff12906e453ba59af911cbfc"))
- (114000, uint256S("0x000000046020cd15a3803db747ec6811bee5703c9b67b54185d8fae23f7617cf"))
- (115000, uint256S("0x000000019fd1a317c649c83c6b2a3f6bca7e82fac2fc89ce69de4b6d5715050b"))
- (116000, uint256S("0x00000002cad5e312f8553c3ca053f3588d53561722ce3bf20d55eb4654707668"))
- (117000, uint256S("0x0000000339f55a289fabf4881ab5d89739779bc0e1ab5650830b4fec8870d183"))
- (118000, uint256S("0x000000027bc70600ad7355ee66e6ca0b9d2fd24b7778014bb464a7bbc37627de"))
- (119000, uint256S("0x00000001ddca829e3480f45ec3f7291fe9d611dd4600c047516729052a881058"))
- (120000, uint256S("0x0000000217decb42c4ea26cbee700e728a558ae648393b8014f035566ef2a456"))
- (121000, uint256S("0x00000000f2798338531f5a39201960a80ec28203cdd5dcd27718f6a7fd6723bf"))
- (122000, uint256S("0x00000001204dfcde9f95ef04a25f54553329a48fe34078e213d93199dfe0c26b"))
- (123000, uint256S("0x0000000220091729c30ec5a296a5218e0500bff2dfe10a5d9e5ceca2ea39482b"))
- (124000, uint256S("0x00000002415360bf949d8e96362ce7b0aada6adbcfb73aba536fa7a329fec49f"))
- (125000, uint256S("0x000000002aeab45f5e399d027976c49f4c7732ddbb78d7dc729fb226346ea3f1"))
- (126000, uint256S("0x0000000067f239b6b78180145dc4ccbda1c71d506201f807912ddc170683808d"))
- (127000, uint256S("0x00000001962a64e4e5a9e9c6cc286e2bcf155734c24f2c9481128e37ac6d9712"))
- (128000, uint256S("0x000000011dfac6f7447ae6de5002dd3bf5ddc94faadb706f45e0b4724257dfe5"))
- (129000, uint256S("0x0000000014f4aa454784a182645fa425834f8f9464abea319ea0afe5d3ccd91a"))
- (130000, uint256S("0x000000001c4a5aa11e6c142931463fcf7a9f5b9fb41061d26c18ff1860431881"))
- (131000, uint256S("0x000000003c44e490a60f7aa1941835277230706cfbf58dc8113610cc9c3582eb"))
- (132000, uint256S("0x0000000041bef6adaff29263986224bd5a2999e2aec38aa07b52fa67eed1402f"))
- (133000, uint256S("0x0000000162eb0ea1633481197a8ddc3743ff32ce2e8ecc249f9a8e9912459e05"))
- (134000, uint256S("0x00000002a34611317b4b1d8bc8640282ffb7d7c86fc858af7e0abb0bca6b720d"))
- (135000, uint256S("0x000000025f9502fc7474d62a0a23417cc5b77f3a049260e65b5b810d71074743"))
- (136000, uint256S("0x00000000af2a19997fde28b70235070f627f3b5900a9ee13c927529a11110bc6")),
- (int64_t) 1575741799, // time of last checkpointed block
- (int64_t) 274689, // total txs
- (double) 1065 // txs in the last day before block 136590
+ (100000, uint256S("0x00000001bc1c40d120bf2df1654f3fb5e4d28d4ff292d05667cf5610042c794a"))
+ (105000, uint256S("0x0000000175182a7f9c46aaae8723a664168af4be37c5d73e8f773df6b67a458b"))
+ (110000, uint256S("0x000000030ba3cdbb85d5028379dfe50fbf28c04f8add3300814c2f649ec53594"))
+ (115000, uint256S("0x000000019fd1a317c649c83c6b2a3f6bca7e82fac2fc89ce69de4b6d5715050b"))
+ (120000, uint256S("0x0000000217decb42c4ea26cbee700e728a558ae648393b8014f035566ef2a456"))
+ (125000, uint256S("0x000000002aeab45f5e399d027976c49f4c7732ddbb78d7dc729fb226346ea3f1"))
+ (130000, uint256S("0x000000001c4a5aa11e6c142931463fcf7a9f5b9fb41061d26c18ff1860431881"))
+ (135000, uint256S("0x000000025f9502fc7474d62a0a23417cc5b77f3a049260e65b5b810d71074743"))
+ (140000, uint256S("0x00000000ea91b31e677db9f506e9de4ce03b609275212072759aada24b4654bf"))
+ (145000, uint256S("0x000000003f623cfbe83830077ce9d79f692cb1cd39f027d2bbfba0861dc050d7"))
+ (150000, uint256S("0x00000001850c65319eb4048f175e9540091dad9e4a7f8aeb5c989137e15a8524"))
+ (155000, uint256S("0x00000003c30e0e03841c63a47e934c0ba7f42578c6065ca03436dca8c99918da"))
+ (160000, uint256S("0x0000000553274de0e5f07bf3a63bdb6ab71158a3506829fd6f7df2cd51d5b2a3"))
+ (165000, uint256S("0x00000002c72ab9752b4f605b303f5c006600eb8e62baab7016af2e0454894c9b"))
+ (170000, uint256S("0x0000000191d6e3c5473215ab1e28a8fa8db6172eb4ec6fed371d4bd71224adb0"))
+ (175000, uint256S("0x00000000ac73f67cdc92b225e0895054ba4349d68ddca707ba536d9946f14a2b"))
+ (180000, uint256S("0x00000003119d28eed1fd0c2e2a33510b2b740c1227a9e0e59157228f8e9e1666"))
+ (185000, uint256S("0x000000032f71875bf21794a8aa44720e10bef77c12af1aec30951999a4d190d7"))
+ (190000, uint256S("0x000000002beb4cc8e79a3aed7b1b8329b31a55a3e1556b0933953450a0c185b9"))
+ (195000, uint256S("0x00000001f2fec10089b395c2df2edbfd15e67077ea48706a43bedaf5eae0e5ca"))
+ (200000, uint256S("0x00000003d57cdb7fba2f3b641d288737945de2434adeb0b3b3f2ef35a66e45ab"))
+ (205000, uint256S("0x000000011c8311c289958290444111ffc33261773cc171bfe9a492f59dd2be01"))
+ (210000, uint256S("0x000000006e43c9650b62ae15d05ada7d12be75df37a8b600b636268b144e2aab"))
+ (215000, uint256S("0x0000000385861debdf375a584fc33c6da0a13b9ae41cb904483903f29b8f423c"))
+ (220000, uint256S("0x00000000dd40d7372e60da03205bfc9bd796cc467737e093a58ab08b688014a4"))
+ (225000, uint256S("0x0000000216ec6bc7a702846ac429ff9e9b1dc14c0528689e810f663a05045f24"))
+ (230000, uint256S("0x000000015b0545acc87aa652a8d8d5aac1ecfc5e15d9e3a9e4171d472fdfa9b4"))
+ (235000, uint256S("0x00000000b841e412b8828fe64693bec0a6922d048f8ae061ba547fcad93f7e8f"))
+ (240000, uint256S("0x000000013e22209c4587e7fce090b7219f2d96640172697d276b606cf53ce07b"))
+ (245000, uint256S("0x00000002c0b1deff663826669c4a5bbfcba9cf7029598a35bb999afb27cce854"))
+ (250000, uint256S("0x00000003cba3713646dc533b75fba6f6fe02779e4fb934cda4fe2109c9403268"))
+ (255000, uint256S("0x00000000b76f444f3f5258a2d20d2639c0bffebb6ee0217caa56fcd0404337d5"))
+ (260000, uint256S("0x00000001f2dc5f292d9ee232d463faf1bc59362b9b3432f5bd1f72ffc76716f8"))
+ (265000, uint256S("0x00000003c2dc488c16fc1d73b288065e89bfb9e38dd08cc543867b0b7aa26047"))
+ (270000, uint256S("0x000000026cc545eed18b508c3368cd20256c012bfa10f5f115b21ad0101c02cb"))
+ (275000, uint256S("0x0000000376ee6074814c8274238f88e48f96a87ee6ba63e7d349554128087014"))
+ (280000, uint256S("0x000000036b2c0edb762736b4243cdba4d5b576456cc4c6b6a29ed69d27f0c4d9"))
+ (285000, uint256S("0x000000064ca1b27d679ffc9e25af53d531d9f80bc00fd130f5a71054b2f96124"))
+ (290000, uint256S("0x00000000c9bd5248099f4caca2a5b1da88548cd1824bb22a0efa6c30cf6ccfce"))
+ (295000, uint256S("0x00000002fb6bbf41e4f17f88301895c9143ea93e628523b97e5bd5765070d803"))
+ (300000, uint256S("0x000000033322d90275a09f4094e5c43db1f7017f788145d5a0edfa8200ecedad")),
+ (int64_t) 1600695750, // time of last checkpointed block
+ (int64_t) 576831, // total txs
+ (double) 1134 // txs in the last day before block 300768
};
} else {
checkpointData = //(Checkpoints::CCheckpointData)
- {
+ {
boost::assign::map_list_of
(0, pCurrentParams->consensus.hashGenesisBlock),
(int64_t)1231006505,
@@ -742,6 +676,7 @@ void *chainparams_commandline()
}
pCurrentParams->SetCheckpointData(checkpointData);
+ fprintf(stderr,"%s: Set checkpoint data\n", __func__);
ASSETCHAIN_INIT = 1;
return(0);
diff --git a/src/chainparams.h b/src/chainparams.h
index daa16af8c..d56f8d095 100644
--- a/src/chainparams.h
+++ b/src/chainparams.h
@@ -1,7 +1,8 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp
index 4ec957ba1..2c15f8ffc 100644
--- a/src/chainparamsbase.cpp
+++ b/src/chainparamsbase.cpp
@@ -1,7 +1,7 @@
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/chainparamsbase.h b/src/chainparamsbase.h
index 94e3a4238..88e928e14 100644
--- a/src/chainparamsbase.h
+++ b/src/chainparamsbase.h
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp
index 7fd94e4e7..210eb3659 100644
--- a/src/checkpoints.cpp
+++ b/src/checkpoints.cpp
@@ -1,6 +1,7 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
@@ -74,7 +75,7 @@ namespace Checkpoints {
fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
}
- return fWorkBefore / (fWorkBefore + fWorkAfter);
+ return std::min(fWorkBefore / (fWorkBefore + fWorkAfter), 1.0);
}
int GetTotalBlocksEstimate(const CChainParams::CCheckpointData& data)
diff --git a/src/checkpoints.h b/src/checkpoints.h
index 1b21755f0..d25db20b4 100644
--- a/src/checkpoints.h
+++ b/src/checkpoints.h
@@ -1,6 +1,7 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/checkqueue.h b/src/checkqueue.h
index fc3cdb610..0480d2cb3 100644
--- a/src/checkqueue.h
+++ b/src/checkqueue.h
@@ -1,6 +1,7 @@
// Copyright (c) 2012-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/clientversion.cpp b/src/clientversion.cpp
index 084bbd5ce..7763ed738 100644
--- a/src/clientversion.cpp
+++ b/src/clientversion.cpp
@@ -1,6 +1,7 @@
// Copyright (c) 2012-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
@@ -64,6 +65,7 @@ const std::string CLIENT_NAME = GetArg("-clientname", "MagicBean");
#include "build.h"
#endif
+//TODO: clean up this stuff
//! git will put "#define GIT_ARCHIVE 1" on the next line inside archives.
#define GIT_ARCHIVE 1
#ifdef GIT_ARCHIVE
diff --git a/src/clientversion.h b/src/clientversion.h
index 71fcee16f..b0df8cc3e 100644
--- a/src/clientversion.h
+++ b/src/clientversion.h
@@ -1,8 +1,8 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
// Copyright (c) 2016-2017 The Zcash developers
// Copyright (c) 2019-2020 The Hush developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
@@ -33,8 +33,8 @@
//! These need to be macros, as clientversion.cpp's and bitcoin*-res.rc's voodoo requires it
// Must be kept in sync with configure.ac !
#define CLIENT_VERSION_MAJOR 3
-#define CLIENT_VERSION_MINOR 3
-#define CLIENT_VERSION_REVISION 2
+#define CLIENT_VERSION_MINOR 5
+#define CLIENT_VERSION_REVISION 1
#define CLIENT_VERSION_BUILD 50
//! Set to true for release, false for prerelease or test build
@@ -56,7 +56,7 @@
#define DO_STRINGIZE(X) #X
//! Copyright string used in Windows .rc files
-#define COPYRIGHT_STR "2009-" STRINGIZE(COPYRIGHT_YEAR) " The Bitcoin Core Developers, The Zcash developers, Komodo developers, Hush developers"
+#define COPYRIGHT_STR "2009-" STRINGIZE(COPYRIGHT_YEAR) " The Bitcoin Core, Zcash, Komodo, Hush Developers"
/**
* bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
diff --git a/src/coincontrol.h b/src/coincontrol.h
index 02d487a4c..24228d529 100644
--- a/src/coincontrol.h
+++ b/src/coincontrol.h
@@ -1,6 +1,7 @@
// Copyright (c) 2011-2013 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/coins.cpp b/src/coins.cpp
index 38fac8252..26ad75027 100644
--- a/src/coins.cpp
+++ b/src/coins.cpp
@@ -1,7 +1,7 @@
// Copyright (c) 2012-2014 The Bitcoin Core developers
-// Copyright (c) 2019 The Hush developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
@@ -65,7 +65,6 @@ bool CCoins::Spend(uint32_t nPos)
Cleanup();
return true;
}
-bool CCoinsView::GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const { return false; }
bool CCoinsView::GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const { return false; }
bool CCoinsView::GetNullifier(const uint256 &nullifier, ShieldedType type) const { return false; }
bool CCoinsView::GetCoins(const uint256 &txid, CCoins &coins) const { return false; }
@@ -85,7 +84,6 @@ bool CCoinsView::GetStats(CCoinsStats &stats) const { return false; }
CCoinsViewBacked::CCoinsViewBacked(CCoinsView *viewIn) : base(viewIn) { }
-bool CCoinsViewBacked::GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const { return base->GetSproutAnchorAt(rt, tree); }
bool CCoinsViewBacked::GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const { return base->GetSaplingAnchorAt(rt, tree); }
bool CCoinsViewBacked::GetNullifier(const uint256 &nullifier, ShieldedType type) const { return base->GetNullifier(nullifier, type); }
bool CCoinsViewBacked::GetCoins(const uint256 &txid, CCoins &coins) const { return base->GetCoins(txid, coins); }
@@ -139,30 +137,6 @@ CCoinsMap::const_iterator CCoinsViewCache::FetchCoins(const uint256 &txid) const
return ret;
}
-
-bool CCoinsViewCache::GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const {
- CAnchorsSproutMap::const_iterator it = cacheSproutAnchors.find(rt);
- if (it != cacheSproutAnchors.end()) {
- if (it->second.entered) {
- tree = it->second.tree;
- return true;
- } else {
- return false;
- }
- }
-
- if (!base->GetSproutAnchorAt(rt, tree)) {
- return false;
- }
-
- CAnchorsSproutMap::iterator ret = cacheSproutAnchors.insert(std::make_pair(rt, CAnchorsSproutCacheEntry())).first;
- ret->second.entered = true;
- ret->second.tree = tree;
- cachedCoinsUsage += ret->second.tree.DynamicMemoryUsage();
-
- return true;
-}
-
bool CCoinsViewCache::GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const {
CAnchorsSaplingMap::const_iterator it = cacheSaplingAnchors.find(rt);
if (it != cacheSaplingAnchors.end()) {
@@ -271,7 +245,6 @@ void CCoinsViewCache::BringBestAnchorIntoCache(
SproutMerkleTree &tree
)
{
- assert(GetSproutAnchorAt(currentRoot, tree));
}
template<>
@@ -550,9 +523,9 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins,
bool CCoinsViewCache::Flush() {
bool fOk = base->BatchWrite(cacheCoins, hashBlock, hashSproutAnchor, hashSaplingAnchor, cacheSproutAnchors, cacheSaplingAnchors, cacheSproutNullifiers, cacheSaplingNullifiers);
cacheCoins.clear();
- cacheSproutAnchors.clear();
+ //cacheSproutAnchors.clear();
cacheSaplingAnchors.clear();
- cacheSproutNullifiers.clear();
+ //cacheSproutNullifiers.clear();
cacheSaplingNullifiers.clear();
cachedCoinsUsage = 0;
return fOk;
@@ -624,37 +597,8 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr
}
-bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const
+bool CCoinsViewCache::HaveShieldedRequirements(const CTransaction& tx) const
{
- boost::unordered_map intermediates;
-
- BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit)
- {
- BOOST_FOREACH(const uint256& nullifier, joinsplit.nullifiers)
- {
- if (GetNullifier(nullifier, SPROUT)) {
- // If the nullifier is set, this transaction
- // double-spends!
- return false;
- }
- }
-
- SproutMerkleTree tree;
- auto it = intermediates.find(joinsplit.anchor);
- if (it != intermediates.end()) {
- tree = it->second;
- } else if (!GetSproutAnchorAt(joinsplit.anchor, tree)) {
- return false;
- }
-
- BOOST_FOREACH(const uint256& commitment, joinsplit.commitments)
- {
- tree.append(commitment);
- }
-
- intermediates.insert(std::make_pair(tree.root(), tree));
- }
-
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
if (GetNullifier(spendDescription.nullifier, SAPLING)) { // Prevent double spends
LogPrintf("%s: sapling nullifier %s exists, preventing double spend\n", __FUNCTION__, spendDescription.nullifier.GetHex().c_str());
diff --git a/src/coins.h b/src/coins.h
index cc8b19f68..1c735336c 100644
--- a/src/coins.h
+++ b/src/coins.h
@@ -1,8 +1,8 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
// Copyright (c) 2019-2020 The Hush developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
@@ -372,9 +372,6 @@ struct CCoinsStats
class CCoinsView
{
public:
- //! Retrieve the tree (Sprout) at a particular anchored root in the chain
- virtual bool GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const;
-
//! Retrieve the tree (Sapling) at a particular anchored root in the chain
virtual bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const;
@@ -421,7 +418,6 @@ protected:
public:
CCoinsViewBacked(CCoinsView *viewIn);
- bool GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const;
bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const;
bool GetNullifier(const uint256 &nullifier, ShieldedType type) const;
bool GetCoins(const uint256 &txid, CCoins &coins) const;
@@ -493,7 +489,6 @@ public:
CNullifiersMap getNullifiers();
// Standard CCoinsView methods
- bool GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const;
bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const;
bool GetNullifier(const uint256 &nullifier, ShieldedType type) const;
bool GetCoins(const uint256 &txid, CCoins &coins) const;
@@ -550,7 +545,7 @@ public:
size_t DynamicMemoryUsage() const;
/**
- * Amount of bitcoins coming in to a transaction
+ * Amount of HUSH coming in to a transaction
* Note that lightweight clients may not know anything besides the hash of previous transactions,
* so may not be able to calculate this.
*
@@ -562,8 +557,8 @@ public:
//! Check whether all prevouts of the transaction are present in the UTXO set represented by this view
bool HaveInputs(const CTransaction& tx) const;
- //! Check whether all joinsplit requirements (anchors/nullifiers) are satisfied
- bool HaveJoinSplitRequirements(const CTransaction& tx) const;
+ //! Check whether all shielded requirements (anchors/nullifiers) are satisfied
+ bool HaveShieldedRequirements(const CTransaction& tx) const;
//! Return priority of tx at height nHeight
double GetPriority(const CTransaction &tx, int nHeight) const;
diff --git a/src/compat.h b/src/compat.h
index 44b7dcee2..25f81eccd 100644
--- a/src/compat.h
+++ b/src/compat.h
@@ -1,7 +1,7 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/compat/byteswap.h b/src/compat/byteswap.h
index 899220bdc..fcff3f443 100644
--- a/src/compat/byteswap.h
+++ b/src/compat/byteswap.h
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_COMPAT_BYTESWAP_H
#define BITCOIN_COMPAT_BYTESWAP_H
diff --git a/src/compat/endian.h b/src/compat/endian.h
index 9fec2a07f..79cbf5ce8 100644
--- a/src/compat/endian.h
+++ b/src/compat/endian.h
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_COMPAT_ENDIAN_H
#define BITCOIN_COMPAT_ENDIAN_H
diff --git a/src/compat/glibc_compat.cpp b/src/compat/glibc_compat.cpp
index 3b9c70df7..9f36feb8a 100644
--- a/src/compat/glibc_compat.cpp
+++ b/src/compat/glibc_compat.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
diff --git a/src/compat/glibc_sanity.cpp b/src/compat/glibc_sanity.cpp
index d62d74d46..95936346a 100644
--- a/src/compat/glibc_sanity.cpp
+++ b/src/compat/glibc_sanity.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
diff --git a/src/compat/glibcxx_sanity.cpp b/src/compat/glibcxx_sanity.cpp
index cee8a98c7..cb335c090 100644
--- a/src/compat/glibcxx_sanity.cpp
+++ b/src/compat/glibcxx_sanity.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include
#include
diff --git a/src/compat/sanity.h b/src/compat/sanity.h
index 909c4f6da..7b9e0815f 100644
--- a/src/compat/sanity.h
+++ b/src/compat/sanity.h
@@ -1,6 +1,6 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_COMPAT_SANITY_H
#define BITCOIN_COMPAT_SANITY_H
diff --git a/src/compat/strnlen.cpp b/src/compat/strnlen.cpp
index 1ac266c2d..df03f29f1 100644
--- a/src/compat/strnlen.cpp
+++ b/src/compat/strnlen.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
diff --git a/src/compressor.cpp b/src/compressor.cpp
index e3479474d..ae7fe02ba 100644
--- a/src/compressor.cpp
+++ b/src/compressor.cpp
@@ -1,7 +1,7 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/compressor.h b/src/compressor.h
index f4e4a256d..d1b4e9fda 100644
--- a/src/compressor.h
+++ b/src/compressor.h
@@ -1,7 +1,7 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h
index eba39b644..f9c9e9650 100644
--- a/src/consensus/consensus.h
+++ b/src/consensus/consensus.h
@@ -1,7 +1,7 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/consensus/params.h b/src/consensus/params.h
index 67d84af0b..4cda50068 100644
--- a/src/consensus/params.h
+++ b/src/consensus/params.h
@@ -1,7 +1,8 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/consensus/upgrades.cpp b/src/consensus/upgrades.cpp
index b75e0c002..973b4fca2 100644
--- a/src/consensus/upgrades.cpp
+++ b/src/consensus/upgrades.cpp
@@ -1,6 +1,7 @@
+// Copyright (c) 2019-2020 The Hush developers
// Copyright (c) 2018 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/consensus/upgrades.h b/src/consensus/upgrades.h
index 38eadc9ef..7a72e798b 100644
--- a/src/consensus/upgrades.h
+++ b/src/consensus/upgrades.h
@@ -1,6 +1,6 @@
// Copyright (c) 2018 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/consensus/validation.h b/src/consensus/validation.h
index a3d718c05..1779cdd55 100644
--- a/src/consensus/validation.h
+++ b/src/consensus/validation.h
@@ -1,7 +1,7 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/core_io.h b/src/core_io.h
index dbf30b9e9..51c7c2a28 100644
--- a/src/core_io.h
+++ b/src/core_io.h
@@ -1,6 +1,6 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/core_memusage.h b/src/core_memusage.h
index b2f4a28ae..bf3ccfaaa 100644
--- a/src/core_memusage.h
+++ b/src/core_memusage.h
@@ -1,6 +1,6 @@
// Copyright (c) 2015 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_CORE_MEMUSAGE_H
#define BITCOIN_CORE_MEMUSAGE_H
diff --git a/src/core_read.cpp b/src/core_read.cpp
index 9817a2165..679d221f4 100644
--- a/src/core_read.cpp
+++ b/src/core_read.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/core_write.cpp b/src/core_write.cpp
index 780540027..bb996c700 100644
--- a/src/core_write.cpp
+++ b/src/core_write.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2009-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/crypto/bip39/Makefile b/src/crypto/bip39/Makefile
new file mode 100644
index 000000000..4a5dec3d8
--- /dev/null
+++ b/src/crypto/bip39/Makefile
@@ -0,0 +1,66 @@
+CC ?= gcc
+
+OPTFLAGS ?= -O3 -g
+
+CFLAGS += $(OPTFLAGS) \
+ -std=gnu99 \
+ -W \
+ -Wall \
+ -Wextra \
+ -Wimplicit-function-declaration \
+ -Wredundant-decls \
+ -Wstrict-prototypes \
+ -Wundef \
+ -Wshadow \
+ -Wpointer-arith \
+ -Wformat \
+ -Wreturn-type \
+ -Wsign-compare \
+ -Wmultichar \
+ -Wformat-nonliteral \
+ -Winit-self \
+ -Wuninitialized \
+ -Wformat-security \
+ -Werror
+
+VALGRIND ?= 1
+
+CFLAGS += -I.
+CFLAGS += -DVALGRIND=$(VALGRIND)
+CFLAGS += $(shell pkg-config --cflags openssl)
+
+# disable certain optimizations and features when small footprint is required
+ifdef SMALL
+CFLAGS += -DUSE_PRECOMPUTED_CP=0
+endif
+
+SRCS = bignum.c ecdsa.c curves.c secp256k1.c nist256p1.c rand.c hmac.c bip32.c bip39.c pbkdf2.c base58.c base32.c
+#SRCS += address.c
+#SRCS += script.c
+SRCS += ripemd160.c
+SRCS += sha2.c
+SRCS += sha3.c
+SRCS += hasher.c
+#SRCS += aes/aescrypt.c aes/aeskey.c aes/aestab.c aes/aes_modes.c
+#SRCS += ed25519-donna/curve25519-donna-32bit.c ed25519-donna/curve25519-donna-helpers.c ed25519-donna/modm-donna-32bit.c
+#SRCS += ed25519-donna/ed25519-donna-basepoint-table.c ed25519-donna/ed25519-donna-32bit-tables.c ed25519-donna/ed25519-donna-impl-base.c
+#SRCS += ed25519-donna/ed25519.c ed25519-donna/curve25519-donna-scalarmult-base.c ed25519-donna/ed25519-sha3.c ed25519-donna/ed25519-keccak.c
+#SRCS += blake256.c
+#SRCS += blake2b.c blake2s.c
+#SRCS += chacha20poly1305/chacha20poly1305.c chacha20poly1305/chacha_merged.c chacha20poly1305/poly1305-donna.c chacha20poly1305/rfc7539.c
+SRCS += memzero.c
+
+OBJS = $(SRCS:.c=.o)
+
+TESTLIBS = $(shell pkg-config --libs check) -lpthread -lm
+TESTSSLLIBS = $(shell pkg-config --libs openssl)
+
+all: hasher.o bip39.o memzero.o pbkdf2.o base58.o base32.o
+ @echo "Created object files, donezo"
+
+%.o: %.c %.h options.h
+ $(CC) $(CFLAGS) -o $@ -c $<
+
+clean:
+ rm -rf *.o
+
diff --git a/src/crypto/bip39/README.md b/src/crypto/bip39/README.md
new file mode 100644
index 000000000..b8e03fc93
--- /dev/null
+++ b/src/crypto/bip39/README.md
@@ -0,0 +1,3 @@
+# trezor-firmware bip39
+
+Imported from https://github.com/trezor/trezor-firmware/commit/047fcffde1f8530d3aee279b731e5e5f5901590a
diff --git a/src/crypto/bip39/base32.c b/src/crypto/bip39/base32.c
new file mode 100644
index 000000000..06760ccae
--- /dev/null
+++ b/src/crypto/bip39/base32.c
@@ -0,0 +1,233 @@
+/**
+ * Copyright (c) 2017 Saleem Rashid
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, E1PRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "base32.h"
+
+#include
+
+const char *BASE32_ALPHABET_RFC4648 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ23456789";
+
+static inline void base32_5to8(const uint8_t *in, uint8_t length, uint8_t *out);
+static inline bool base32_8to5(const uint8_t *in, uint8_t length, uint8_t *out, const char *alphabet);
+static inline void base32_8to5_raw(const uint8_t *in, uint8_t length, uint8_t *out);
+
+static inline int base32_encode_character(uint8_t decoded, const char *alphabet);
+static inline int base32_decode_character(char encoded, const char *alphabet);
+
+char *base32_encode(const uint8_t *in, size_t inlen, char *out, size_t outlen, const char *alphabet) {
+ size_t length = base32_encoded_length(inlen);
+ if (outlen <= length) {
+ return NULL;
+ }
+
+ base32_encode_unsafe(in, inlen, (uint8_t *) out);
+
+ for (size_t i = 0; i < length; i++) {
+ int ret = base32_encode_character(out[i], alphabet);
+
+ if (ret == -1) {
+ return false;
+ } else {
+ out[i] = ret;
+ }
+ }
+
+ out[length] = '\0';
+ return &out[length];
+}
+
+uint8_t *base32_decode(const char *in, size_t inlen, uint8_t *out, size_t outlen, const char *alphabet) {
+ size_t length = base32_decoded_length(inlen);
+ if (outlen < length) {
+ return NULL;
+ }
+
+ if (!base32_decode_unsafe((uint8_t *) in, inlen, (uint8_t *) out, alphabet)) {
+ return NULL;
+ }
+
+ return &out[length];
+}
+
+void base32_encode_unsafe(const uint8_t *in, size_t inlen, uint8_t *out) {
+ uint8_t remainder = inlen % 5;
+ size_t limit = inlen - remainder;
+
+ size_t i, j;
+ for (i = 0, j = 0; i < limit; i += 5, j += 8) {
+ base32_5to8(&in[i], 5, &out[j]);
+ }
+
+ if (remainder) base32_5to8(&in[i], remainder, &out[j]);
+}
+
+bool base32_decode_unsafe(const uint8_t *in, size_t inlen, uint8_t *out, const char *alphabet) {
+ uint8_t remainder = inlen % 8;
+ size_t limit = inlen - remainder;
+
+ size_t i, j;
+ for (i = 0, j = 0; i < limit; i += 8, j += 5) {
+ if (!base32_8to5(&in[i], 8, &out[j], alphabet)) {
+ return false;
+ }
+ }
+
+ if (remainder && !base32_8to5(&in[i], remainder, &out[j], alphabet)) {
+ return false;
+ }
+
+ return true;
+}
+
+size_t base32_encoded_length(size_t inlen) {
+ uint8_t remainder = inlen % 5;
+
+ return (inlen / 5) * 8 + (remainder * 8 + 4) / 5;
+}
+
+size_t base32_decoded_length(size_t inlen) {
+ uint8_t remainder = inlen % 8;
+
+ return (inlen / 8) * 5 + (remainder * 5) / 8;
+}
+
+void base32_5to8(const uint8_t *in, uint8_t length, uint8_t *out) {
+ if (length >= 1) {
+ out[0] = (in[0] >> 3);
+ out[1] = (in[0] & 7) << 2;
+ }
+
+ if (length >= 2) {
+ out[1] |= (in[1] >> 6);
+ out[2] = (in[1] >> 1) & 31;
+ out[3] = (in[1] & 1) << 4;
+ }
+
+ if (length >= 3) {
+ out[3] |= (in[2] >> 4);
+ out[4] = (in[2] & 15) << 1;
+ }
+
+ if (length >= 4) {
+ out[4] |= (in[3] >> 7);
+ out[5] = (in[3] >> 2) & 31;
+ out[6] = (in[3] & 3) << 3;
+ }
+
+ if (length >= 5) {
+ out[6] |= (in[4] >> 5);
+ out[7] = (in[4] & 31);
+ }
+}
+
+bool base32_8to5(const uint8_t *in, uint8_t length, uint8_t *out, const char *alphabet) {
+ if (length == 1 || length == 3 || length == 6 || length > 8) {
+ return false;
+ }
+
+ if (alphabet) {
+ uint8_t decoded[length];
+
+ for (size_t i = 0; i < length; i++) {
+ int ret = base32_decode_character(in[i], alphabet);
+
+ if (ret == -1) {
+ return false;
+ } else {
+ decoded[i] = ret;
+ }
+ }
+
+ base32_8to5_raw(decoded, length, out);
+ } else {
+ base32_8to5_raw(in, length, out);
+ }
+
+ return true;
+}
+
+void base32_8to5_raw(const uint8_t *in, uint8_t length, uint8_t *out) {
+ if (length >= 2) {
+ out[0] = (in[0] << 3);
+ out[0] |= (in[1] >> 2);
+ }
+
+ if (length >= 4) {
+ out[1] = (in[1] & 3) << 6;
+ out[1] |= (in[2] << 1);
+ out[1] |= (in[3] >> 4);
+ }
+
+ if (length >= 5) {
+ out[2] = (in[3] & 15) << 4;
+ out[2] |= (in[4] >> 1);
+ }
+
+ if (length >= 7) {
+ out[3] = (in[4] & 1) << 7;
+ out[3] |= (in[5] << 2);
+ out[3] |= (in[6] >> 3);
+ }
+
+ if (length >= 8) {
+ out[4] = (in[6] & 7) << 5;
+ out[4] |= (in[7] & 31);
+ }
+}
+
+int base32_encode_character(uint8_t decoded, const char *alphabet) {
+ if (decoded >> 5) {
+ return -1;
+ }
+
+ if (alphabet == BASE32_ALPHABET_RFC4648) {
+ if (decoded < 26) {
+ return 'A' + decoded;
+ } else {
+ return '2' - 26 + decoded;
+ }
+ }
+
+ return alphabet[decoded];
+}
+
+int base32_decode_character(char encoded, const char *alphabet) {
+ if (alphabet == BASE32_ALPHABET_RFC4648) {
+ if (encoded >= 'A' && encoded <= 'Z') {
+ return encoded - 'A';
+ } else if (encoded >= 'a' && encoded <= 'z') {
+ return encoded - 'a';
+ } else if (encoded >= '2' && encoded <= '7') {
+ return encoded - '2' + 26;
+ } else {
+ return -1;
+ }
+ }
+
+ const char *occurrence = strchr(alphabet, encoded);
+
+ if (occurrence) {
+ return occurrence - alphabet;
+ } else {
+ return -1;
+ }
+}
diff --git a/src/crypto/bip39/base32.h b/src/crypto/bip39/base32.h
new file mode 100644
index 000000000..250997967
--- /dev/null
+++ b/src/crypto/bip39/base32.h
@@ -0,0 +1,41 @@
+/**
+ * Copyright (c) 2017 Saleem Rashid
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __BASE32_H__
+#define __BASE32_H__
+
+#include
+#include
+#include
+
+extern const char *BASE32_ALPHABET_RFC4648;
+
+char *base32_encode(const uint8_t *in, size_t inlen, char *out, size_t outlen, const char *alphabet);
+void base32_encode_unsafe(const uint8_t *in, size_t inlen, uint8_t *out);
+
+uint8_t *base32_decode(const char *in, size_t inlen, uint8_t *out, size_t outlen, const char *alphabet);
+bool base32_decode_unsafe(const uint8_t *in, size_t inlen, uint8_t *out, const char *alphabet);
+
+size_t base32_encoded_length(size_t inlen);
+size_t base32_decoded_length(size_t inlen);
+
+#endif
diff --git a/src/crypto/bip39/base58.c b/src/crypto/bip39/base58.c
new file mode 100644
index 000000000..cd74617b8
--- /dev/null
+++ b/src/crypto/bip39/base58.c
@@ -0,0 +1,285 @@
+/**
+ * Copyright (c) 2012-2014 Luke Dashjr
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include
+#include
+#include
+#include "base58.h"
+#include "sha2.h"
+#include "ripemd160.h"
+#include "memzero.h"
+
+const char b58digits_ordered[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
+const int8_t b58digits_map[] = {
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,-1,-1,-1,-1,-1,-1,
+ -1, 9,10,11,12,13,14,15,16,-1,17,18,19,20,21,-1,
+ 22,23,24,25,26,27,28,29,30,31,32,-1,-1,-1,-1,-1,
+ -1,33,34,35,36,37,38,39,40,41,42,43,-1,44,45,46,
+ 47,48,49,50,51,52,53,54,55,56,57,-1,-1,-1,-1,-1,
+};
+
+bool b58tobin(void *bin, size_t *binszp, const char *b58)
+{
+ size_t binsz = *binszp;
+
+ if (binsz == 0) {
+ return false;
+ }
+
+ const unsigned char *b58u = (const unsigned char*)b58;
+ unsigned char *binu = bin;
+ size_t outisz = (binsz + 3) / 4;
+ uint32_t outi[outisz];
+ uint64_t t;
+ uint32_t c;
+ size_t i, j;
+ uint8_t bytesleft = binsz % 4;
+ uint32_t zeromask = bytesleft ? (0xffffffff << (bytesleft * 8)) : 0;
+ unsigned zerocount = 0;
+ size_t b58sz;
+
+ b58sz = strlen(b58);
+
+ memzero(outi, sizeof(outi));
+
+ // Leading zeros, just count
+ for (i = 0; i < b58sz && b58u[i] == '1'; ++i)
+ ++zerocount;
+
+ for ( ; i < b58sz; ++i)
+ {
+ if (b58u[i] & 0x80)
+ // High-bit set on invalid digit
+ return false;
+ if (b58digits_map[b58u[i]] == -1)
+ // Invalid base58 digit
+ return false;
+ c = (unsigned)b58digits_map[b58u[i]];
+ for (j = outisz; j--; )
+ {
+ t = ((uint64_t)outi[j]) * 58 + c;
+ c = (t & 0x3f00000000) >> 32;
+ outi[j] = t & 0xffffffff;
+ }
+ if (c)
+ // Output number too big (carry to the next int32)
+ return false;
+ if (outi[0] & zeromask)
+ // Output number too big (last int32 filled too far)
+ return false;
+ }
+
+ j = 0;
+ switch (bytesleft) {
+ case 3:
+ *(binu++) = (outi[0] & 0xff0000) >> 16;
+ //-fallthrough
+ case 2:
+ *(binu++) = (outi[0] & 0xff00) >> 8;
+ //-fallthrough
+ case 1:
+ *(binu++) = (outi[0] & 0xff);
+ ++j;
+ //-fallthrough
+ default:
+ break;
+ }
+
+ for (; j < outisz; ++j)
+ {
+ *(binu++) = (outi[j] >> 0x18) & 0xff;
+ *(binu++) = (outi[j] >> 0x10) & 0xff;
+ *(binu++) = (outi[j] >> 8) & 0xff;
+ *(binu++) = (outi[j] >> 0) & 0xff;
+ }
+
+ // Count canonical base58 byte count
+ binu = bin;
+ for (i = 0; i < binsz; ++i)
+ {
+ if (binu[i]) {
+ if (zerocount > i) {
+ /* result too large */
+ return false;
+ }
+ break;
+ }
+ --*binszp;
+ }
+ *binszp += zerocount;
+
+ return true;
+}
+
+int b58check(const void *bin, size_t binsz, HasherType hasher_type, const char *base58str)
+{
+ unsigned char buf[32];
+ const uint8_t *binc = bin;
+ unsigned i;
+ if (binsz < 4)
+ return -4;
+ hasher_Raw(hasher_type, bin, binsz - 4, buf);
+ if (memcmp(&binc[binsz - 4], buf, 4))
+ return -1;
+
+ // Check number of zeros is correct AFTER verifying checksum (to avoid possibility of accessing base58str beyond the end)
+ for (i = 0; binc[i] == '\0' && base58str[i] == '1'; ++i)
+ {} // Just finding the end of zeros, nothing to do in loop
+ if (binc[i] == '\0' || base58str[i] == '1')
+ return -3;
+
+ return binc[0];
+}
+
+bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz)
+{
+ const uint8_t *bin = data;
+ int carry;
+ ssize_t i, j, high, zcount = 0;
+ size_t size;
+
+ while (zcount < (ssize_t)binsz && !bin[zcount])
+ ++zcount;
+
+ size = (binsz - zcount) * 138 / 100 + 1;
+ uint8_t buf[size];
+ memzero(buf, size);
+
+ for (i = zcount, high = size - 1; i < (ssize_t)binsz; ++i, high = j)
+ {
+ for (carry = bin[i], j = size - 1; (j > high) || carry; --j)
+ {
+ carry += 256 * buf[j];
+ buf[j] = carry % 58;
+ carry /= 58;
+ }
+ }
+
+ for (j = 0; j < (ssize_t)size && !buf[j]; ++j);
+
+ if (*b58sz <= zcount + size - j)
+ {
+ *b58sz = zcount + size - j + 1;
+ return false;
+ }
+
+ if (zcount)
+ memset(b58, '1', zcount);
+ for (i = zcount; j < (ssize_t)size; ++i, ++j)
+ b58[i] = b58digits_ordered[buf[j]];
+ b58[i] = '\0';
+ *b58sz = i + 1;
+
+ return true;
+}
+
+int base58_encode_check(const uint8_t *data, int datalen, HasherType hasher_type, char *str, int strsize)
+{
+ if (datalen > 128) {
+ return 0;
+ }
+ uint8_t buf[datalen + 32];
+ uint8_t *hash = buf + datalen;
+ memcpy(buf, data, datalen);
+ hasher_Raw(hasher_type, data, datalen, hash);
+ size_t res = strsize;
+ bool success = b58enc(str, &res, buf, datalen + 4);
+ memzero(buf, sizeof(buf));
+ return success ? res : 0;
+}
+
+int base58_decode_check(const char *str, HasherType hasher_type, uint8_t *data, int datalen)
+{
+ if (datalen > 128) {
+ return 0;
+ }
+ uint8_t d[datalen + 4];
+ size_t res = datalen + 4;
+ if (b58tobin(d, &res, str) != true) {
+ return 0;
+ }
+ uint8_t *nd = d + datalen + 4 - res;
+ if (b58check(nd, res, hasher_type, str) < 0) {
+ return 0;
+ }
+ memcpy(data, nd, res - 4);
+ return res - 4;
+}
+
+#if USE_GRAPHENE
+int b58gphcheck(const void *bin, size_t binsz, const char *base58str)
+{
+ unsigned char buf[32];
+ const uint8_t *binc = bin;
+ unsigned i;
+ if (binsz < 4)
+ return -4;
+ ripemd160(bin, binsz - 4, buf); // No double SHA256, but a single RIPEMD160
+ if (memcmp(&binc[binsz - 4], buf, 4))
+ return -1;
+
+ // Check number of zeros is correct AFTER verifying checksum (to avoid possibility of accessing base58str beyond the end)
+ for (i = 0; binc[i] == '\0' && base58str[i] == '1'; ++i)
+ {} // Just finding the end of zeros, nothing to do in loop
+ if (binc[i] == '\0' || base58str[i] == '1')
+ return -3;
+
+ return binc[0];
+}
+
+int base58gph_encode_check(const uint8_t *data, int datalen, char *str, int strsize)
+{
+ if (datalen > 128) {
+ return 0;
+ }
+ uint8_t buf[datalen + 32];
+ uint8_t *hash = buf + datalen;
+ memcpy(buf, data, datalen);
+ ripemd160(data, datalen, hash); // No double SHA256, but a single RIPEMD160
+ size_t res = strsize;
+ bool success = b58enc(str, &res, buf, datalen + 4);
+ memzero(buf, sizeof(buf));
+ return success ? res : 0;
+}
+
+int base58gph_decode_check(const char *str, uint8_t *data, int datalen)
+{
+ if (datalen > 128) {
+ return 0;
+ }
+ uint8_t d[datalen + 4];
+ size_t res = datalen + 4;
+ if (b58tobin(d, &res, str) != true) {
+ return 0;
+ }
+ uint8_t *nd = d + datalen + 4 - res;
+ if (b58gphcheck(nd, res, str) < 0) {
+ return 0;
+ }
+ memcpy(data, nd, res - 4);
+ return res - 4;
+}
+#endif
diff --git a/src/crypto/bip39/base58.h b/src/crypto/bip39/base58.h
new file mode 100644
index 000000000..0fa9167bf
--- /dev/null
+++ b/src/crypto/bip39/base58.h
@@ -0,0 +1,49 @@
+/**
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __BASE58_H__
+#define __BASE58_H__
+
+#include
+#include
+#include "hasher.h"
+#include "options.h"
+
+extern const char b58digits_ordered[];
+extern const int8_t b58digits_map[];
+
+int base58_encode_check(const uint8_t *data, int len, HasherType hasher_type, char *str, int strsize);
+int base58_decode_check(const char *str, HasherType hasher_type, uint8_t *data, int datalen);
+
+// Private
+bool b58tobin(void *bin, size_t *binszp, const char *b58);
+int b58check(const void *bin, size_t binsz, HasherType hasher_type, const char *base58str);
+bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz);
+
+#if USE_GRAPHENE
+int base58gph_encode_check(const uint8_t *data, int datalen, char *str, int strsize);
+int base58gph_decode_check(const char *str, uint8_t *data, int datalen);
+int b58gphcheck(const void *bin, size_t binsz, const char *base58str);
+#endif
+
+#endif
diff --git a/src/crypto/bip39/bip32.h b/src/crypto/bip39/bip32.h
new file mode 100644
index 000000000..c0a04b5f8
--- /dev/null
+++ b/src/crypto/bip39/bip32.h
@@ -0,0 +1,112 @@
+/**
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __BIP32_H__
+#define __BIP32_H__
+
+#include
+#include
+#include
+#include "ecdsa.h"
+#include "ed25519-donna/ed25519.h"
+#include "options.h"
+
+typedef struct {
+ const char *bip32_name; // string for generating BIP32 xprv from seed
+ const ecdsa_curve *params; // ecdsa curve parameters, null for ed25519
+
+ HasherType hasher_base58;
+ HasherType hasher_sign;
+ HasherType hasher_pubkey;
+ HasherType hasher_script;
+} curve_info;
+
+typedef struct {
+ uint32_t depth;
+ uint32_t child_num;
+ uint8_t chain_code[32];
+
+ uint8_t private_key[32];
+ uint8_t private_key_extension[32];
+
+ uint8_t public_key[33];
+ const curve_info *curve;
+} HDNode;
+
+int hdnode_from_xpub(uint32_t depth, uint32_t child_num, const uint8_t *chain_code, const uint8_t *public_key, const char *curve, HDNode *out);
+
+int hdnode_from_xprv(uint32_t depth, uint32_t child_num, const uint8_t *chain_code, const uint8_t *private_key, const char *curve, HDNode *out);
+
+int hdnode_from_seed(const uint8_t *seed, int seed_len, const char *curve, HDNode *out);
+
+#define hdnode_private_ckd_prime(X, I) hdnode_private_ckd((X), ((I) | 0x80000000))
+
+int hdnode_private_ckd(HDNode *inout, uint32_t i);
+
+#if USE_CARDANO
+int hdnode_private_ckd_cardano(HDNode *inout, uint32_t i);
+int hdnode_from_seed_cardano(const uint8_t *pass, int pass_len, const uint8_t *seed, int seed_len, HDNode *out);
+#endif
+
+int hdnode_public_ckd_cp(const ecdsa_curve *curve, const curve_point *parent, const uint8_t *parent_chain_code, uint32_t i, curve_point *child, uint8_t *child_chain_code);
+
+int hdnode_public_ckd(HDNode *inout, uint32_t i);
+
+void hdnode_public_ckd_address_optimized(const curve_point *pub, const uint8_t *chain_code, uint32_t i, uint32_t version, HasherType hasher_pubkey, HasherType hasher_base58, char *addr, int addrsize, int addrformat);
+
+#if USE_BIP32_CACHE
+int hdnode_private_ckd_cached(HDNode *inout, const uint32_t *i, size_t i_count, uint32_t *fingerprint);
+#endif
+
+uint32_t hdnode_fingerprint(HDNode *node);
+
+void hdnode_fill_public_key(HDNode *node);
+
+#if USE_ETHEREUM
+int hdnode_get_ethereum_pubkeyhash(const HDNode *node, uint8_t *pubkeyhash);
+#endif
+
+#if USE_NEM
+int hdnode_get_nem_address(HDNode *node, uint8_t version, char *address);
+int hdnode_get_nem_shared_key(const HDNode *node, const ed25519_public_key peer_public_key, const uint8_t *salt, ed25519_public_key mul, uint8_t *shared_key);
+int hdnode_nem_encrypt(const HDNode *node, const ed25519_public_key public_key, const uint8_t *iv, const uint8_t *salt, const uint8_t *payload, size_t size, uint8_t *buffer);
+int hdnode_nem_decrypt(const HDNode *node, const ed25519_public_key public_key, uint8_t *iv, const uint8_t *salt, const uint8_t *payload, size_t size, uint8_t *buffer);
+#endif
+
+int hdnode_sign(HDNode *node, const uint8_t *msg, uint32_t msg_len, HasherType hasher_sign, uint8_t *sig, uint8_t *pby, int (*is_canonical)(uint8_t by, uint8_t sig[64]));
+int hdnode_sign_digest(HDNode *node, const uint8_t *digest, uint8_t *sig, uint8_t *pby, int (*is_canonical)(uint8_t by, uint8_t sig[64]));
+
+int hdnode_get_shared_key(const HDNode *node, const uint8_t *peer_public_key, uint8_t *session_key, int *result_size);
+
+int hdnode_serialize_public(const HDNode *node, uint32_t fingerprint, uint32_t version, char *str, int strsize);
+
+int hdnode_serialize_private(const HDNode *node, uint32_t fingerprint, uint32_t version, char *str, int strsize);
+
+int hdnode_deserialize(const char *str, uint32_t version_public, uint32_t version_private, const char *curve, HDNode *node, uint32_t *fingerprint);
+
+void hdnode_get_address_raw(HDNode *node, uint32_t version, uint8_t *addr_raw);
+void hdnode_get_address(HDNode *node, uint32_t version, char *addr, int addrsize);
+
+const curve_info *get_curve_by_name(const char *curve_name);
+
+#endif
diff --git a/src/crypto/bip39/bip39.c b/src/crypto/bip39/bip39.c
new file mode 100644
index 000000000..76e0792ad
--- /dev/null
+++ b/src/crypto/bip39/bip39.c
@@ -0,0 +1,283 @@
+/**
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include
+#include
+
+#include "bip39.h"
+#include "bip39_english.h"
+#include "hmac.h"
+#include "memzero.h"
+#include "options.h"
+#include "pbkdf2.h"
+#include "rand.h"
+#include "sha2.h"
+
+#if USE_BIP39_CACHE
+
+int BIP39_WORDS = 2048;
+
+static int bip39_cache_index = 0;
+
+static CONFIDENTIAL struct {
+ bool set;
+ char mnemonic[256];
+ char passphrase[64];
+ uint8_t seed[512 / 8];
+} bip39_cache[BIP39_CACHE_SIZE];
+
+#endif
+
+const char *mnemonic_generate(int strength) {
+ if (strength % 32 || strength < 128 || strength > 256) {
+ return 0;
+ }
+ uint8_t data[32] = {0};
+ random_buffer(data, 32);
+ const char *r = mnemonic_from_data(data, strength / 8);
+ memzero(data, sizeof(data));
+ return r;
+}
+
+static CONFIDENTIAL char mnemo[24 * 10];
+
+const char *mnemonic_from_data(const uint8_t *data, int len) {
+ if (len % 4 || len < 16 || len > 32) {
+ return 0;
+ }
+
+ uint8_t bits[32 + 1] = {0};
+
+ sha256_Raw(data, len, bits);
+ // checksum
+ bits[len] = bits[0];
+ // data
+ memcpy(bits, data, len);
+
+ int mlen = len * 3 / 4;
+
+ int i = 0, j = 0, idx = 0;
+ char *p = mnemo;
+ for (i = 0; i < mlen; i++) {
+ idx = 0;
+ for (j = 0; j < 11; j++) {
+ idx <<= 1;
+ idx += (bits[(i * 11 + j) / 8] & (1 << (7 - ((i * 11 + j) % 8)))) > 0;
+ }
+ strcpy(p, wordlist[idx]);
+ p += strlen(wordlist[idx]);
+ *p = (i < mlen - 1) ? ' ' : 0;
+ p++;
+ }
+ memzero(bits, sizeof(bits));
+
+ return mnemo;
+}
+
+void mnemonic_clear(void) { memzero(mnemo, sizeof(mnemo)); }
+
+int mnemonic_to_entropy(const char *mnemonic, uint8_t *entropy) {
+ if (!mnemonic) {
+ return 0;
+ }
+
+ uint32_t i = 0, n = 0;
+
+ while (mnemonic[i]) {
+ if (mnemonic[i] == ' ') {
+ n++;
+ }
+ i++;
+ }
+ n++;
+
+ // check number of words
+ if (n != 12 && n != 18 && n != 24) {
+ return 0;
+ }
+
+ char current_word[10] = {0};
+ uint32_t j = 0, k = 0, ki = 0, bi = 0;
+ uint8_t bits[32 + 1] = {0};
+
+ memzero(bits, sizeof(bits));
+ i = 0;
+ while (mnemonic[i]) {
+ j = 0;
+ while (mnemonic[i] != ' ' && mnemonic[i] != 0) {
+ if (j >= sizeof(current_word) - 1) {
+ return 0;
+ }
+ current_word[j] = mnemonic[i];
+ i++;
+ j++;
+ }
+ current_word[j] = 0;
+ if (mnemonic[i] != 0) {
+ i++;
+ }
+ k = 0;
+ for (;;) {
+ if (!wordlist[k]) { // word not found
+ return 0;
+ }
+ if (strcmp(current_word, wordlist[k]) == 0) { // word found on index k
+ for (ki = 0; ki < 11; ki++) {
+ if (k & (1 << (10 - ki))) {
+ bits[bi / 8] |= 1 << (7 - (bi % 8));
+ }
+ bi++;
+ }
+ break;
+ }
+ k++;
+ }
+ }
+ if (bi != n * 11) {
+ return 0;
+ }
+ memcpy(entropy, bits, sizeof(bits));
+ return n * 11;
+}
+
+int mnemonic_check(const char *mnemonic) {
+ uint8_t bits[32 + 1] = {0};
+ int seed_len = mnemonic_to_entropy(mnemonic, bits);
+ if (seed_len != (12 * 11) && seed_len != (18 * 11) && seed_len != (24 * 11)) {
+ return 0;
+ }
+ int words = seed_len / 11;
+
+ uint8_t checksum = bits[words * 4 / 3];
+ sha256_Raw(bits, words * 4 / 3, bits);
+ if (words == 12) {
+ return (bits[0] & 0xF0) == (checksum & 0xF0); // compare first 4 bits
+ } else if (words == 18) {
+ return (bits[0] & 0xFC) == (checksum & 0xFC); // compare first 6 bits
+ } else if (words == 24) {
+ return bits[0] == checksum; // compare 8 bits
+ }
+ return 0;
+}
+
+// passphrase must be at most 256 characters otherwise it would be truncated
+void mnemonic_to_seed(const char *mnemonic, const char *passphrase,
+ uint8_t seed[512 / 8],
+ void (*progress_callback)(uint32_t current,
+ uint32_t total)) {
+ int mnemoniclen = strlen(mnemonic);
+ int passphraselen = strnlen(passphrase, 256);
+#if USE_BIP39_CACHE
+ // check cache
+ if (mnemoniclen < 256 && passphraselen < 64) {
+ for (int i = 0; i < BIP39_CACHE_SIZE; i++) {
+ if (!bip39_cache[i].set) continue;
+ if (strcmp(bip39_cache[i].mnemonic, mnemonic) != 0) continue;
+ if (strcmp(bip39_cache[i].passphrase, passphrase) != 0) continue;
+ // found the correct entry
+ memcpy(seed, bip39_cache[i].seed, 512 / 8);
+ return;
+ }
+ }
+#endif
+ uint8_t salt[8 + 256] = {0};
+ memcpy(salt, "mnemonic", 8);
+ memcpy(salt + 8, passphrase, passphraselen);
+ static CONFIDENTIAL PBKDF2_HMAC_SHA512_CTX pctx;
+ pbkdf2_hmac_sha512_Init(&pctx, (const uint8_t *)mnemonic, mnemoniclen, salt,
+ passphraselen + 8, 1);
+ if (progress_callback) {
+ progress_callback(0, BIP39_PBKDF2_ROUNDS);
+ }
+ for (int i = 0; i < 16; i++) {
+ pbkdf2_hmac_sha512_Update(&pctx, BIP39_PBKDF2_ROUNDS / 16);
+ if (progress_callback) {
+ progress_callback((i + 1) * BIP39_PBKDF2_ROUNDS / 16,
+ BIP39_PBKDF2_ROUNDS);
+ }
+ }
+ pbkdf2_hmac_sha512_Final(&pctx, seed);
+ memzero(salt, sizeof(salt));
+#if USE_BIP39_CACHE
+ // store to cache
+ if (mnemoniclen < 256 && passphraselen < 64) {
+ bip39_cache[bip39_cache_index].set = true;
+ strcpy(bip39_cache[bip39_cache_index].mnemonic, mnemonic);
+ strcpy(bip39_cache[bip39_cache_index].passphrase, passphrase);
+ memcpy(bip39_cache[bip39_cache_index].seed, seed, 512 / 8);
+ bip39_cache_index = (bip39_cache_index + 1) % BIP39_CACHE_SIZE;
+ }
+#endif
+}
+
+// binary search for finding the word in the wordlist
+int mnemonic_find_word(const char *word) {
+ int lo = 0, hi = BIP39_WORDS - 1;
+ while (lo <= hi) {
+ int mid = lo + (hi - lo) / 2;
+ int cmp = strcmp(word, wordlist[mid]);
+ if (cmp == 0) {
+ return mid;
+ }
+ if (cmp > 0) {
+ lo = mid + 1;
+ } else {
+ hi = mid - 1;
+ }
+ }
+ return -1;
+}
+
+const char *mnemonic_complete_word(const char *prefix, int len) {
+ // we need to perform linear search,
+ // because we want to return the first match
+ for (const char *const *w = wordlist; *w != 0; w++) {
+ if (strncmp(*w, prefix, len) == 0) {
+ return *w;
+ }
+ }
+ return NULL;
+}
+
+const char *mnemonic_get_word(int index) {
+ if (index >= 0 && index < BIP39_WORDS) {
+ return wordlist[index];
+ } else {
+ return NULL;
+ }
+}
+
+uint32_t mnemonic_word_completion_mask(const char *prefix, int len) {
+ if (len <= 0) {
+ return 0x3ffffff; // all letters (bits 1-26 set)
+ }
+ uint32_t res = 0;
+ for (const char *const *w = wordlist; *w != 0; w++) {
+ const char *word = *w;
+ if (strncmp(word, prefix, len) == 0 && word[len] >= 'a' &&
+ word[len] <= 'z') {
+ res |= 1 << (word[len] - 'a');
+ }
+ }
+ return res;
+}
diff --git a/src/crypto/bip39/bip39.h b/src/crypto/bip39/bip39.h
new file mode 100644
index 000000000..ac76101d7
--- /dev/null
+++ b/src/crypto/bip39/bip39.h
@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __BIP39_H__
+#define __BIP39_H__
+
+#include
+
+#define BIP39_PBKDF2_ROUNDS 2048
+
+const char *mnemonic_generate(int strength); // strength in bits
+const char *mnemonic_from_data(const uint8_t *data, int len);
+void mnemonic_clear(void);
+
+int mnemonic_check(const char *mnemonic);
+
+int mnemonic_to_entropy(const char *mnemonic, uint8_t *entropy);
+
+// passphrase must be at most 256 characters otherwise it would be truncated
+void mnemonic_to_seed(const char *mnemonic, const char *passphrase, uint8_t seed[512 / 8], void (*progress_callback)(uint32_t current, uint32_t total));
+
+const char * const *mnemonic_wordlist(void);
+
+#endif
diff --git a/src/crypto/bip39/bip39_english.h b/src/crypto/bip39/bip39_english.h
new file mode 100644
index 000000000..77607ba7f
--- /dev/null
+++ b/src/crypto/bip39/bip39_english.h
@@ -0,0 +1,2074 @@
+/**
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+static const char * const wordlist[] = {
+"abandon",
+"ability",
+"able",
+"about",
+"above",
+"absent",
+"absorb",
+"abstract",
+"absurd",
+"abuse",
+"access",
+"accident",
+"account",
+"accuse",
+"achieve",
+"acid",
+"acoustic",
+"acquire",
+"across",
+"act",
+"action",
+"actor",
+"actress",
+"actual",
+"adapt",
+"add",
+"addict",
+"address",
+"adjust",
+"admit",
+"adult",
+"advance",
+"advice",
+"aerobic",
+"affair",
+"afford",
+"afraid",
+"again",
+"age",
+"agent",
+"agree",
+"ahead",
+"aim",
+"air",
+"airport",
+"aisle",
+"alarm",
+"album",
+"alcohol",
+"alert",
+"alien",
+"all",
+"alley",
+"allow",
+"almost",
+"alone",
+"alpha",
+"already",
+"also",
+"alter",
+"always",
+"amateur",
+"amazing",
+"among",
+"amount",
+"amused",
+"analyst",
+"anchor",
+"ancient",
+"anger",
+"angle",
+"angry",
+"animal",
+"ankle",
+"announce",
+"annual",
+"another",
+"answer",
+"antenna",
+"antique",
+"anxiety",
+"any",
+"apart",
+"apology",
+"appear",
+"apple",
+"approve",
+"april",
+"arch",
+"arctic",
+"area",
+"arena",
+"argue",
+"arm",
+"armed",
+"armor",
+"army",
+"around",
+"arrange",
+"arrest",
+"arrive",
+"arrow",
+"art",
+"artefact",
+"artist",
+"artwork",
+"ask",
+"aspect",
+"assault",
+"asset",
+"assist",
+"assume",
+"asthma",
+"athlete",
+"atom",
+"attack",
+"attend",
+"attitude",
+"attract",
+"auction",
+"audit",
+"august",
+"aunt",
+"author",
+"auto",
+"autumn",
+"average",
+"avocado",
+"avoid",
+"awake",
+"aware",
+"away",
+"awesome",
+"awful",
+"awkward",
+"axis",
+"baby",
+"bachelor",
+"bacon",
+"badge",
+"bag",
+"balance",
+"balcony",
+"ball",
+"bamboo",
+"banana",
+"banner",
+"bar",
+"barely",
+"bargain",
+"barrel",
+"base",
+"basic",
+"basket",
+"battle",
+"beach",
+"bean",
+"beauty",
+"because",
+"become",
+"beef",
+"before",
+"begin",
+"behave",
+"behind",
+"believe",
+"below",
+"belt",
+"bench",
+"benefit",
+"best",
+"betray",
+"better",
+"between",
+"beyond",
+"bicycle",
+"bid",
+"bike",
+"bind",
+"biology",
+"bird",
+"birth",
+"bitter",
+"black",
+"blade",
+"blame",
+"blanket",
+"blast",
+"bleak",
+"bless",
+"blind",
+"blood",
+"blossom",
+"blouse",
+"blue",
+"blur",
+"blush",
+"board",
+"boat",
+"body",
+"boil",
+"bomb",
+"bone",
+"bonus",
+"book",
+"boost",
+"border",
+"boring",
+"borrow",
+"boss",
+"bottom",
+"bounce",
+"box",
+"boy",
+"bracket",
+"brain",
+"brand",
+"brass",
+"brave",
+"bread",
+"breeze",
+"brick",
+"bridge",
+"brief",
+"bright",
+"bring",
+"brisk",
+"broccoli",
+"broken",
+"bronze",
+"broom",
+"brother",
+"brown",
+"brush",
+"bubble",
+"buddy",
+"budget",
+"buffalo",
+"build",
+"bulb",
+"bulk",
+"bullet",
+"bundle",
+"bunker",
+"burden",
+"burger",
+"burst",
+"bus",
+"business",
+"busy",
+"butter",
+"buyer",
+"buzz",
+"cabbage",
+"cabin",
+"cable",
+"cactus",
+"cage",
+"cake",
+"call",
+"calm",
+"camera",
+"camp",
+"can",
+"canal",
+"cancel",
+"candy",
+"cannon",
+"canoe",
+"canvas",
+"canyon",
+"capable",
+"capital",
+"captain",
+"car",
+"carbon",
+"card",
+"cargo",
+"carpet",
+"carry",
+"cart",
+"case",
+"cash",
+"casino",
+"castle",
+"casual",
+"cat",
+"catalog",
+"catch",
+"category",
+"cattle",
+"caught",
+"cause",
+"caution",
+"cave",
+"ceiling",
+"celery",
+"cement",
+"census",
+"century",
+"cereal",
+"certain",
+"chair",
+"chalk",
+"champion",
+"change",
+"chaos",
+"chapter",
+"charge",
+"chase",
+"chat",
+"cheap",
+"check",
+"cheese",
+"chef",
+"cherry",
+"chest",
+"chicken",
+"chief",
+"child",
+"chimney",
+"choice",
+"choose",
+"chronic",
+"chuckle",
+"chunk",
+"churn",
+"cigar",
+"cinnamon",
+"circle",
+"citizen",
+"city",
+"civil",
+"claim",
+"clap",
+"clarify",
+"claw",
+"clay",
+"clean",
+"clerk",
+"clever",
+"click",
+"client",
+"cliff",
+"climb",
+"clinic",
+"clip",
+"clock",
+"clog",
+"close",
+"cloth",
+"cloud",
+"clown",
+"club",
+"clump",
+"cluster",
+"clutch",
+"coach",
+"coast",
+"coconut",
+"code",
+"coffee",
+"coil",
+"coin",
+"collect",
+"color",
+"column",
+"combine",
+"come",
+"comfort",
+"comic",
+"common",
+"company",
+"concert",
+"conduct",
+"confirm",
+"congress",
+"connect",
+"consider",
+"control",
+"convince",
+"cook",
+"cool",
+"copper",
+"copy",
+"coral",
+"core",
+"corn",
+"correct",
+"cost",
+"cotton",
+"couch",
+"country",
+"couple",
+"course",
+"cousin",
+"cover",
+"coyote",
+"crack",
+"cradle",
+"craft",
+"cram",
+"crane",
+"crash",
+"crater",
+"crawl",
+"crazy",
+"cream",
+"credit",
+"creek",
+"crew",
+"cricket",
+"crime",
+"crisp",
+"critic",
+"crop",
+"cross",
+"crouch",
+"crowd",
+"crucial",
+"cruel",
+"cruise",
+"crumble",
+"crunch",
+"crush",
+"cry",
+"crystal",
+"cube",
+"culture",
+"cup",
+"cupboard",
+"curious",
+"current",
+"curtain",
+"curve",
+"cushion",
+"custom",
+"cute",
+"cycle",
+"dad",
+"damage",
+"damp",
+"dance",
+"danger",
+"daring",
+"dash",
+"daughter",
+"dawn",
+"day",
+"deal",
+"debate",
+"debris",
+"decade",
+"december",
+"decide",
+"decline",
+"decorate",
+"decrease",
+"deer",
+"defense",
+"define",
+"defy",
+"degree",
+"delay",
+"deliver",
+"demand",
+"demise",
+"denial",
+"dentist",
+"deny",
+"depart",
+"depend",
+"deposit",
+"depth",
+"deputy",
+"derive",
+"describe",
+"desert",
+"design",
+"desk",
+"despair",
+"destroy",
+"detail",
+"detect",
+"develop",
+"device",
+"devote",
+"diagram",
+"dial",
+"diamond",
+"diary",
+"dice",
+"diesel",
+"diet",
+"differ",
+"digital",
+"dignity",
+"dilemma",
+"dinner",
+"dinosaur",
+"direct",
+"dirt",
+"disagree",
+"discover",
+"disease",
+"dish",
+"dismiss",
+"disorder",
+"display",
+"distance",
+"divert",
+"divide",
+"divorce",
+"dizzy",
+"doctor",
+"document",
+"dog",
+"doll",
+"dolphin",
+"domain",
+"donate",
+"donkey",
+"donor",
+"door",
+"dose",
+"double",
+"dove",
+"draft",
+"dragon",
+"drama",
+"drastic",
+"draw",
+"dream",
+"dress",
+"drift",
+"drill",
+"drink",
+"drip",
+"drive",
+"drop",
+"drum",
+"dry",
+"duck",
+"dumb",
+"dune",
+"during",
+"dust",
+"dutch",
+"duty",
+"dwarf",
+"dynamic",
+"eager",
+"eagle",
+"early",
+"earn",
+"earth",
+"easily",
+"east",
+"easy",
+"echo",
+"ecology",
+"economy",
+"edge",
+"edit",
+"educate",
+"effort",
+"egg",
+"eight",
+"either",
+"elbow",
+"elder",
+"electric",
+"elegant",
+"element",
+"elephant",
+"elevator",
+"elite",
+"else",
+"embark",
+"embody",
+"embrace",
+"emerge",
+"emotion",
+"employ",
+"empower",
+"empty",
+"enable",
+"enact",
+"end",
+"endless",
+"endorse",
+"enemy",
+"energy",
+"enforce",
+"engage",
+"engine",
+"enhance",
+"enjoy",
+"enlist",
+"enough",
+"enrich",
+"enroll",
+"ensure",
+"enter",
+"entire",
+"entry",
+"envelope",
+"episode",
+"equal",
+"equip",
+"era",
+"erase",
+"erode",
+"erosion",
+"error",
+"erupt",
+"escape",
+"essay",
+"essence",
+"estate",
+"eternal",
+"ethics",
+"evidence",
+"evil",
+"evoke",
+"evolve",
+"exact",
+"example",
+"excess",
+"exchange",
+"excite",
+"exclude",
+"excuse",
+"execute",
+"exercise",
+"exhaust",
+"exhibit",
+"exile",
+"exist",
+"exit",
+"exotic",
+"expand",
+"expect",
+"expire",
+"explain",
+"expose",
+"express",
+"extend",
+"extra",
+"eye",
+"eyebrow",
+"fabric",
+"face",
+"faculty",
+"fade",
+"faint",
+"faith",
+"fall",
+"false",
+"fame",
+"family",
+"famous",
+"fan",
+"fancy",
+"fantasy",
+"farm",
+"fashion",
+"fat",
+"fatal",
+"father",
+"fatigue",
+"fault",
+"favorite",
+"feature",
+"february",
+"federal",
+"fee",
+"feed",
+"feel",
+"female",
+"fence",
+"festival",
+"fetch",
+"fever",
+"few",
+"fiber",
+"fiction",
+"field",
+"figure",
+"file",
+"film",
+"filter",
+"final",
+"find",
+"fine",
+"finger",
+"finish",
+"fire",
+"firm",
+"first",
+"fiscal",
+"fish",
+"fit",
+"fitness",
+"fix",
+"flag",
+"flame",
+"flash",
+"flat",
+"flavor",
+"flee",
+"flight",
+"flip",
+"float",
+"flock",
+"floor",
+"flower",
+"fluid",
+"flush",
+"fly",
+"foam",
+"focus",
+"fog",
+"foil",
+"fold",
+"follow",
+"food",
+"foot",
+"force",
+"forest",
+"forget",
+"fork",
+"fortune",
+"forum",
+"forward",
+"fossil",
+"foster",
+"found",
+"fox",
+"fragile",
+"frame",
+"frequent",
+"fresh",
+"friend",
+"fringe",
+"frog",
+"front",
+"frost",
+"frown",
+"frozen",
+"fruit",
+"fuel",
+"fun",
+"funny",
+"furnace",
+"fury",
+"future",
+"gadget",
+"gain",
+"galaxy",
+"gallery",
+"game",
+"gap",
+"garage",
+"garbage",
+"garden",
+"garlic",
+"garment",
+"gas",
+"gasp",
+"gate",
+"gather",
+"gauge",
+"gaze",
+"general",
+"genius",
+"genre",
+"gentle",
+"genuine",
+"gesture",
+"ghost",
+"giant",
+"gift",
+"giggle",
+"ginger",
+"giraffe",
+"girl",
+"give",
+"glad",
+"glance",
+"glare",
+"glass",
+"glide",
+"glimpse",
+"globe",
+"gloom",
+"glory",
+"glove",
+"glow",
+"glue",
+"goat",
+"goddess",
+"gold",
+"good",
+"goose",
+"gorilla",
+"gospel",
+"gossip",
+"govern",
+"gown",
+"grab",
+"grace",
+"grain",
+"grant",
+"grape",
+"grass",
+"gravity",
+"great",
+"green",
+"grid",
+"grief",
+"grit",
+"grocery",
+"group",
+"grow",
+"grunt",
+"guard",
+"guess",
+"guide",
+"guilt",
+"guitar",
+"gun",
+"gym",
+"habit",
+"hair",
+"half",
+"hammer",
+"hamster",
+"hand",
+"happy",
+"harbor",
+"hard",
+"harsh",
+"harvest",
+"hat",
+"have",
+"hawk",
+"hazard",
+"head",
+"health",
+"heart",
+"heavy",
+"hedgehog",
+"height",
+"hello",
+"helmet",
+"help",
+"hen",
+"hero",
+"hidden",
+"high",
+"hill",
+"hint",
+"hip",
+"hire",
+"history",
+"hobby",
+"hockey",
+"hold",
+"hole",
+"holiday",
+"hollow",
+"home",
+"honey",
+"hood",
+"hope",
+"horn",
+"horror",
+"horse",
+"hospital",
+"host",
+"hotel",
+"hour",
+"hover",
+"hub",
+"huge",
+"human",
+"humble",
+"humor",
+"hundred",
+"hungry",
+"hunt",
+"hurdle",
+"hurry",
+"hurt",
+"husband",
+"hybrid",
+"ice",
+"icon",
+"idea",
+"identify",
+"idle",
+"ignore",
+"ill",
+"illegal",
+"illness",
+"image",
+"imitate",
+"immense",
+"immune",
+"impact",
+"impose",
+"improve",
+"impulse",
+"inch",
+"include",
+"income",
+"increase",
+"index",
+"indicate",
+"indoor",
+"industry",
+"infant",
+"inflict",
+"inform",
+"inhale",
+"inherit",
+"initial",
+"inject",
+"injury",
+"inmate",
+"inner",
+"innocent",
+"input",
+"inquiry",
+"insane",
+"insect",
+"inside",
+"inspire",
+"install",
+"intact",
+"interest",
+"into",
+"invest",
+"invite",
+"involve",
+"iron",
+"island",
+"isolate",
+"issue",
+"item",
+"ivory",
+"jacket",
+"jaguar",
+"jar",
+"jazz",
+"jealous",
+"jeans",
+"jelly",
+"jewel",
+"job",
+"join",
+"joke",
+"journey",
+"joy",
+"judge",
+"juice",
+"jump",
+"jungle",
+"junior",
+"junk",
+"just",
+"kangaroo",
+"keen",
+"keep",
+"ketchup",
+"key",
+"kick",
+"kid",
+"kidney",
+"kind",
+"kingdom",
+"kiss",
+"kit",
+"kitchen",
+"kite",
+"kitten",
+"kiwi",
+"knee",
+"knife",
+"knock",
+"know",
+"lab",
+"label",
+"labor",
+"ladder",
+"lady",
+"lake",
+"lamp",
+"language",
+"laptop",
+"large",
+"later",
+"latin",
+"laugh",
+"laundry",
+"lava",
+"law",
+"lawn",
+"lawsuit",
+"layer",
+"lazy",
+"leader",
+"leaf",
+"learn",
+"leave",
+"lecture",
+"left",
+"leg",
+"legal",
+"legend",
+"leisure",
+"lemon",
+"lend",
+"length",
+"lens",
+"leopard",
+"lesson",
+"letter",
+"level",
+"liar",
+"liberty",
+"library",
+"license",
+"life",
+"lift",
+"light",
+"like",
+"limb",
+"limit",
+"link",
+"lion",
+"liquid",
+"list",
+"little",
+"live",
+"lizard",
+"load",
+"loan",
+"lobster",
+"local",
+"lock",
+"logic",
+"lonely",
+"long",
+"loop",
+"lottery",
+"loud",
+"lounge",
+"love",
+"loyal",
+"lucky",
+"luggage",
+"lumber",
+"lunar",
+"lunch",
+"luxury",
+"lyrics",
+"machine",
+"mad",
+"magic",
+"magnet",
+"maid",
+"mail",
+"main",
+"major",
+"make",
+"mammal",
+"man",
+"manage",
+"mandate",
+"mango",
+"mansion",
+"manual",
+"maple",
+"marble",
+"march",
+"margin",
+"marine",
+"market",
+"marriage",
+"mask",
+"mass",
+"master",
+"match",
+"material",
+"math",
+"matrix",
+"matter",
+"maximum",
+"maze",
+"meadow",
+"mean",
+"measure",
+"meat",
+"mechanic",
+"medal",
+"media",
+"melody",
+"melt",
+"member",
+"memory",
+"mention",
+"menu",
+"mercy",
+"merge",
+"merit",
+"merry",
+"mesh",
+"message",
+"metal",
+"method",
+"middle",
+"midnight",
+"milk",
+"million",
+"mimic",
+"mind",
+"minimum",
+"minor",
+"minute",
+"miracle",
+"mirror",
+"misery",
+"miss",
+"mistake",
+"mix",
+"mixed",
+"mixture",
+"mobile",
+"model",
+"modify",
+"mom",
+"moment",
+"monitor",
+"monkey",
+"monster",
+"month",
+"moon",
+"moral",
+"more",
+"morning",
+"mosquito",
+"mother",
+"motion",
+"motor",
+"mountain",
+"mouse",
+"move",
+"movie",
+"much",
+"muffin",
+"mule",
+"multiply",
+"muscle",
+"museum",
+"mushroom",
+"music",
+"must",
+"mutual",
+"myself",
+"mystery",
+"myth",
+"naive",
+"name",
+"napkin",
+"narrow",
+"nasty",
+"nation",
+"nature",
+"near",
+"neck",
+"need",
+"negative",
+"neglect",
+"neither",
+"nephew",
+"nerve",
+"nest",
+"net",
+"network",
+"neutral",
+"never",
+"news",
+"next",
+"nice",
+"night",
+"noble",
+"noise",
+"nominee",
+"noodle",
+"normal",
+"north",
+"nose",
+"notable",
+"note",
+"nothing",
+"notice",
+"novel",
+"now",
+"nuclear",
+"number",
+"nurse",
+"nut",
+"oak",
+"obey",
+"object",
+"oblige",
+"obscure",
+"observe",
+"obtain",
+"obvious",
+"occur",
+"ocean",
+"october",
+"odor",
+"off",
+"offer",
+"office",
+"often",
+"oil",
+"okay",
+"old",
+"olive",
+"olympic",
+"omit",
+"once",
+"one",
+"onion",
+"online",
+"only",
+"open",
+"opera",
+"opinion",
+"oppose",
+"option",
+"orange",
+"orbit",
+"orchard",
+"order",
+"ordinary",
+"organ",
+"orient",
+"original",
+"orphan",
+"ostrich",
+"other",
+"outdoor",
+"outer",
+"output",
+"outside",
+"oval",
+"oven",
+"over",
+"own",
+"owner",
+"oxygen",
+"oyster",
+"ozone",
+"pact",
+"paddle",
+"page",
+"pair",
+"palace",
+"palm",
+"panda",
+"panel",
+"panic",
+"panther",
+"paper",
+"parade",
+"parent",
+"park",
+"parrot",
+"party",
+"pass",
+"patch",
+"path",
+"patient",
+"patrol",
+"pattern",
+"pause",
+"pave",
+"payment",
+"peace",
+"peanut",
+"pear",
+"peasant",
+"pelican",
+"pen",
+"penalty",
+"pencil",
+"people",
+"pepper",
+"perfect",
+"permit",
+"person",
+"pet",
+"phone",
+"photo",
+"phrase",
+"physical",
+"piano",
+"picnic",
+"picture",
+"piece",
+"pig",
+"pigeon",
+"pill",
+"pilot",
+"pink",
+"pioneer",
+"pipe",
+"pistol",
+"pitch",
+"pizza",
+"place",
+"planet",
+"plastic",
+"plate",
+"play",
+"please",
+"pledge",
+"pluck",
+"plug",
+"plunge",
+"poem",
+"poet",
+"point",
+"polar",
+"pole",
+"police",
+"pond",
+"pony",
+"pool",
+"popular",
+"portion",
+"position",
+"possible",
+"post",
+"potato",
+"pottery",
+"poverty",
+"powder",
+"power",
+"practice",
+"praise",
+"predict",
+"prefer",
+"prepare",
+"present",
+"pretty",
+"prevent",
+"price",
+"pride",
+"primary",
+"print",
+"priority",
+"prison",
+"private",
+"prize",
+"problem",
+"process",
+"produce",
+"profit",
+"program",
+"project",
+"promote",
+"proof",
+"property",
+"prosper",
+"protect",
+"proud",
+"provide",
+"public",
+"pudding",
+"pull",
+"pulp",
+"pulse",
+"pumpkin",
+"punch",
+"pupil",
+"puppy",
+"purchase",
+"purity",
+"purpose",
+"purse",
+"push",
+"put",
+"puzzle",
+"pyramid",
+"quality",
+"quantum",
+"quarter",
+"question",
+"quick",
+"quit",
+"quiz",
+"quote",
+"rabbit",
+"raccoon",
+"race",
+"rack",
+"radar",
+"radio",
+"rail",
+"rain",
+"raise",
+"rally",
+"ramp",
+"ranch",
+"random",
+"range",
+"rapid",
+"rare",
+"rate",
+"rather",
+"raven",
+"raw",
+"razor",
+"ready",
+"real",
+"reason",
+"rebel",
+"rebuild",
+"recall",
+"receive",
+"recipe",
+"record",
+"recycle",
+"reduce",
+"reflect",
+"reform",
+"refuse",
+"region",
+"regret",
+"regular",
+"reject",
+"relax",
+"release",
+"relief",
+"rely",
+"remain",
+"remember",
+"remind",
+"remove",
+"render",
+"renew",
+"rent",
+"reopen",
+"repair",
+"repeat",
+"replace",
+"report",
+"require",
+"rescue",
+"resemble",
+"resist",
+"resource",
+"response",
+"result",
+"retire",
+"retreat",
+"return",
+"reunion",
+"reveal",
+"review",
+"reward",
+"rhythm",
+"rib",
+"ribbon",
+"rice",
+"rich",
+"ride",
+"ridge",
+"rifle",
+"right",
+"rigid",
+"ring",
+"riot",
+"ripple",
+"risk",
+"ritual",
+"rival",
+"river",
+"road",
+"roast",
+"robot",
+"robust",
+"rocket",
+"romance",
+"roof",
+"rookie",
+"room",
+"rose",
+"rotate",
+"rough",
+"round",
+"route",
+"royal",
+"rubber",
+"rude",
+"rug",
+"rule",
+"run",
+"runway",
+"rural",
+"sad",
+"saddle",
+"sadness",
+"safe",
+"sail",
+"salad",
+"salmon",
+"salon",
+"salt",
+"salute",
+"same",
+"sample",
+"sand",
+"satisfy",
+"satoshi",
+"sauce",
+"sausage",
+"save",
+"say",
+"scale",
+"scan",
+"scare",
+"scatter",
+"scene",
+"scheme",
+"school",
+"science",
+"scissors",
+"scorpion",
+"scout",
+"scrap",
+"screen",
+"script",
+"scrub",
+"sea",
+"search",
+"season",
+"seat",
+"second",
+"secret",
+"section",
+"security",
+"seed",
+"seek",
+"segment",
+"select",
+"sell",
+"seminar",
+"senior",
+"sense",
+"sentence",
+"series",
+"service",
+"session",
+"settle",
+"setup",
+"seven",
+"shadow",
+"shaft",
+"shallow",
+"share",
+"shed",
+"shell",
+"sheriff",
+"shield",
+"shift",
+"shine",
+"ship",
+"shiver",
+"shock",
+"shoe",
+"shoot",
+"shop",
+"short",
+"shoulder",
+"shove",
+"shrimp",
+"shrug",
+"shuffle",
+"shy",
+"sibling",
+"sick",
+"side",
+"siege",
+"sight",
+"sign",
+"silent",
+"silk",
+"silly",
+"silver",
+"similar",
+"simple",
+"since",
+"sing",
+"siren",
+"sister",
+"situate",
+"six",
+"size",
+"skate",
+"sketch",
+"ski",
+"skill",
+"skin",
+"skirt",
+"skull",
+"slab",
+"slam",
+"sleep",
+"slender",
+"slice",
+"slide",
+"slight",
+"slim",
+"slogan",
+"slot",
+"slow",
+"slush",
+"small",
+"smart",
+"smile",
+"smoke",
+"smooth",
+"snack",
+"snake",
+"snap",
+"sniff",
+"snow",
+"soap",
+"soccer",
+"social",
+"sock",
+"soda",
+"soft",
+"solar",
+"soldier",
+"solid",
+"solution",
+"solve",
+"someone",
+"song",
+"soon",
+"sorry",
+"sort",
+"soul",
+"sound",
+"soup",
+"source",
+"south",
+"space",
+"spare",
+"spatial",
+"spawn",
+"speak",
+"special",
+"speed",
+"spell",
+"spend",
+"sphere",
+"spice",
+"spider",
+"spike",
+"spin",
+"spirit",
+"split",
+"spoil",
+"sponsor",
+"spoon",
+"sport",
+"spot",
+"spray",
+"spread",
+"spring",
+"spy",
+"square",
+"squeeze",
+"squirrel",
+"stable",
+"stadium",
+"staff",
+"stage",
+"stairs",
+"stamp",
+"stand",
+"start",
+"state",
+"stay",
+"steak",
+"steel",
+"stem",
+"step",
+"stereo",
+"stick",
+"still",
+"sting",
+"stock",
+"stomach",
+"stone",
+"stool",
+"story",
+"stove",
+"strategy",
+"street",
+"strike",
+"strong",
+"struggle",
+"student",
+"stuff",
+"stumble",
+"style",
+"subject",
+"submit",
+"subway",
+"success",
+"such",
+"sudden",
+"suffer",
+"sugar",
+"suggest",
+"suit",
+"summer",
+"sun",
+"sunny",
+"sunset",
+"super",
+"supply",
+"supreme",
+"sure",
+"surface",
+"surge",
+"surprise",
+"surround",
+"survey",
+"suspect",
+"sustain",
+"swallow",
+"swamp",
+"swap",
+"swarm",
+"swear",
+"sweet",
+"swift",
+"swim",
+"swing",
+"switch",
+"sword",
+"symbol",
+"symptom",
+"syrup",
+"system",
+"table",
+"tackle",
+"tag",
+"tail",
+"talent",
+"talk",
+"tank",
+"tape",
+"target",
+"task",
+"taste",
+"tattoo",
+"taxi",
+"teach",
+"team",
+"tell",
+"ten",
+"tenant",
+"tennis",
+"tent",
+"term",
+"test",
+"text",
+"thank",
+"that",
+"theme",
+"then",
+"theory",
+"there",
+"they",
+"thing",
+"this",
+"thought",
+"three",
+"thrive",
+"throw",
+"thumb",
+"thunder",
+"ticket",
+"tide",
+"tiger",
+"tilt",
+"timber",
+"time",
+"tiny",
+"tip",
+"tired",
+"tissue",
+"title",
+"toast",
+"tobacco",
+"today",
+"toddler",
+"toe",
+"together",
+"toilet",
+"token",
+"tomato",
+"tomorrow",
+"tone",
+"tongue",
+"tonight",
+"tool",
+"tooth",
+"top",
+"topic",
+"topple",
+"torch",
+"tornado",
+"tortoise",
+"toss",
+"total",
+"tourist",
+"toward",
+"tower",
+"town",
+"toy",
+"track",
+"trade",
+"traffic",
+"tragic",
+"train",
+"transfer",
+"trap",
+"trash",
+"travel",
+"tray",
+"treat",
+"tree",
+"trend",
+"trial",
+"tribe",
+"trick",
+"trigger",
+"trim",
+"trip",
+"trophy",
+"trouble",
+"truck",
+"true",
+"truly",
+"trumpet",
+"trust",
+"truth",
+"try",
+"tube",
+"tuition",
+"tumble",
+"tuna",
+"tunnel",
+"turkey",
+"turn",
+"turtle",
+"twelve",
+"twenty",
+"twice",
+"twin",
+"twist",
+"two",
+"type",
+"typical",
+"ugly",
+"umbrella",
+"unable",
+"unaware",
+"uncle",
+"uncover",
+"under",
+"undo",
+"unfair",
+"unfold",
+"unhappy",
+"uniform",
+"unique",
+"unit",
+"universe",
+"unknown",
+"unlock",
+"until",
+"unusual",
+"unveil",
+"update",
+"upgrade",
+"uphold",
+"upon",
+"upper",
+"upset",
+"urban",
+"urge",
+"usage",
+"use",
+"used",
+"useful",
+"useless",
+"usual",
+"utility",
+"vacant",
+"vacuum",
+"vague",
+"valid",
+"valley",
+"valve",
+"van",
+"vanish",
+"vapor",
+"various",
+"vast",
+"vault",
+"vehicle",
+"velvet",
+"vendor",
+"venture",
+"venue",
+"verb",
+"verify",
+"version",
+"very",
+"vessel",
+"veteran",
+"viable",
+"vibrant",
+"vicious",
+"victory",
+"video",
+"view",
+"village",
+"vintage",
+"violin",
+"virtual",
+"virus",
+"visa",
+"visit",
+"visual",
+"vital",
+"vivid",
+"vocal",
+"voice",
+"void",
+"volcano",
+"volume",
+"vote",
+"voyage",
+"wage",
+"wagon",
+"wait",
+"walk",
+"wall",
+"walnut",
+"want",
+"warfare",
+"warm",
+"warrior",
+"wash",
+"wasp",
+"waste",
+"water",
+"wave",
+"way",
+"wealth",
+"weapon",
+"wear",
+"weasel",
+"weather",
+"web",
+"wedding",
+"weekend",
+"weird",
+"welcome",
+"west",
+"wet",
+"whale",
+"what",
+"wheat",
+"wheel",
+"when",
+"where",
+"whip",
+"whisper",
+"wide",
+"width",
+"wife",
+"wild",
+"will",
+"win",
+"window",
+"wine",
+"wing",
+"wink",
+"winner",
+"winter",
+"wire",
+"wisdom",
+"wise",
+"wish",
+"witness",
+"wolf",
+"woman",
+"wonder",
+"wood",
+"wool",
+"word",
+"work",
+"world",
+"worry",
+"worth",
+"wrap",
+"wreck",
+"wrestle",
+"wrist",
+"write",
+"wrong",
+"yard",
+"year",
+"yellow",
+"you",
+"young",
+"youth",
+"zebra",
+"zero",
+"zone",
+"zoo",
+0,
+};
diff --git a/src/crypto/bip39/bip39_mnemonic.c b/src/crypto/bip39/bip39_mnemonic.c
new file mode 100644
index 000000000..a4dc27b86
--- /dev/null
+++ b/src/crypto/bip39/bip39_mnemonic.c
@@ -0,0 +1,29 @@
+#include
+#include
+#include
+#include "bip39.h"
+#include
+
+// NOTE: We must override this to implement actual RNG!
+void random_buffer(uint8_t *buf, size_t len) {
+ if( len > 0 ) {
+ randombytes_buf(buf, len);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ char *this = argv[0];
+ if (argc > 1) {
+ fprintf(stderr, "Usage: %s\n", this);
+ return 1;
+ }
+ if (sodium_init() == -1) {
+ fprintf(stderr, "libsodium init failed! :(\n");
+ return 1;
+ }
+ int strength = 256;
+ const char *mnemonic = mnemonic_generate(strength);
+ printf("%s\n", mnemonic);
+ return 0;
+}
diff --git a/src/crypto/bip39/bip39bruteforce.c b/src/crypto/bip39/bip39bruteforce.c
new file mode 100644
index 000000000..10fd69da7
--- /dev/null
+++ b/src/crypto/bip39/bip39bruteforce.c
@@ -0,0 +1,87 @@
+#include
+#include
+#include
+#include "bip39.h"
+#include "bip32.h"
+#include "ecdsa.h"
+#include "curves.h"
+
+char iter[256];
+uint8_t seed[512 / 8];
+uint8_t addr[21], pubkeyhash[20];
+int count = 0, found = 0;
+HDNode node;
+clock_t start;
+
+// around 280 tries per second
+
+// testing data:
+//
+// mnemonic: "all all all all all all all all all all all all"
+// address: "1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL"
+// passphrase: ""
+//
+// mnemonic: "all all all all all all all all all all all all"
+// address: "1N3uJ5AU3FTYQ1ZQgTMtYmgSvMBmQiGVBS"
+// passphrase: "testing"
+
+int main(int argc, char **argv)
+{
+ if (argc != 2 && argc != 3) {
+ fprintf(stderr, "Usage: bip39bruteforce address [mnemonic]\n");
+ return 1;
+ }
+ const char *address = argv[1];
+ const char *mnemonic, *item;
+ if (argc == 3) {
+ mnemonic = argv[2];
+ item = "passphrase";
+ } else {
+ mnemonic = NULL;
+ item = "mnemonic";
+ }
+ if (mnemonic && !mnemonic_check(mnemonic)) {
+ fprintf(stderr, "\"%s\" is not a valid mnemonic\n", mnemonic);
+ return 2;
+ }
+ if (!ecdsa_address_decode(address, 0, HASHER_SHA2, addr)) {
+ fprintf(stderr, "\"%s\" is not a valid address\n", address);
+ return 3;
+ }
+ printf("Reading %ss from stdin ...\n", item);
+ start = clock();
+ for (;;) {
+ if (fgets(iter, 256, stdin) == NULL) break;
+ int len = strlen(iter);
+ if (len <= 0) {
+ continue;
+ }
+ count++;
+ iter[len - 1] = 0;
+ if (mnemonic) {
+ mnemonic_to_seed(mnemonic, iter, seed, NULL);
+ } else {
+ mnemonic_to_seed(iter, "", seed, NULL);
+ }
+ hdnode_from_seed(seed, 512 / 8, SECP256K1_NAME, &node);
+ hdnode_private_ckd_prime(&node, 44);
+ hdnode_private_ckd_prime(&node, 0);
+ hdnode_private_ckd_prime(&node, 0);
+ hdnode_private_ckd(&node, 0);
+ hdnode_private_ckd(&node, 0);
+ hdnode_fill_public_key(&node);
+ ecdsa_get_pubkeyhash(node.public_key, HASHER_SHA2, pubkeyhash);
+ if (memcmp(addr + 1, pubkeyhash, 20) == 0) {
+ found = 1;
+ break;
+ }
+ }
+ float dur = (float)(clock() - start) / CLOCKS_PER_SEC;
+ printf("Tried %d %ss in %f seconds = %f tries/second\n", count, item, dur, (float)count/dur);
+ if (found) {
+ printf("Correct %s found! :-)\n\"%s\"\n", item, iter);
+ return 0;
+ }
+ printf("Correct %s not found. :-(\n", item);
+ return 4;
+}
diff --git a/src/crypto/bip39/blake256.h b/src/crypto/bip39/blake256.h
new file mode 100644
index 000000000..313b6260e
--- /dev/null
+++ b/src/crypto/bip39/blake256.h
@@ -0,0 +1,53 @@
+// Copyright (c) 2014-2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#ifndef __BLAKE256_H__
+#define __BLAKE256_H__
+
+#include
+#include
+
+#define BLAKE256_DIGEST_LENGTH 32
+#define BLAKE256_BLOCK_LENGTH 64
+
+typedef struct {
+ uint32_t h[8], s[4], t[2];
+ size_t buflen;
+ uint8_t nullt;
+ uint8_t buf[64];
+} BLAKE256_CTX;
+
+void blake256_Init(BLAKE256_CTX *);
+void blake256_Update(BLAKE256_CTX *, const uint8_t *, size_t);
+void blake256_Final(BLAKE256_CTX *, uint8_t *);
+
+void blake256(const uint8_t *, size_t, uint8_t *);
+
+#endif /* __BLAKE256_H__ */
diff --git a/src/crypto/bip39/blake2_common.h b/src/crypto/bip39/blake2_common.h
new file mode 100644
index 000000000..40c6da3b5
--- /dev/null
+++ b/src/crypto/bip39/blake2_common.h
@@ -0,0 +1,39 @@
+static inline uint32_t load32( const void *src )
+{
+ uint32_t w;
+ memcpy(&w, src, sizeof w);
+ return w;
+}
+
+static inline uint64_t load64( const void *src )
+{
+ uint64_t w;
+ memcpy(&w, src, sizeof w);
+ return w;
+}
+
+static inline void store16( void *dst, uint16_t w )
+{
+ memcpy(dst, &w, sizeof w);
+}
+
+static inline void store32( void *dst, uint32_t w )
+{
+ memcpy(dst, &w, sizeof w);
+}
+
+static inline void store64( void *dst, uint64_t w )
+{
+ memcpy(dst, &w, sizeof w);
+}
+
+static inline uint32_t rotr32( const uint32_t w, const unsigned c )
+{
+ return ( w >> c ) | ( w << ( 32 - c ) );
+}
+
+static inline uint64_t rotr64( const uint64_t w, const unsigned c )
+{
+ return ( w >> c ) | ( w << ( 64 - c ) );
+}
+
diff --git a/src/crypto/bip39/blake2b.h b/src/crypto/bip39/blake2b.h
new file mode 100644
index 000000000..1a43e92d1
--- /dev/null
+++ b/src/crypto/bip39/blake2b.h
@@ -0,0 +1,41 @@
+#ifndef __BLAKE2B_H__
+#define __BLAKE2B_H__
+
+#include
+#include
+
+enum blake2b_constant
+{
+ BLAKE2B_BLOCKBYTES = 128,
+ BLAKE2B_OUTBYTES = 64,
+ BLAKE2B_KEYBYTES = 64,
+ BLAKE2B_SALTBYTES = 16,
+ BLAKE2B_PERSONALBYTES = 16
+};
+
+typedef struct __blake2b_state
+{
+ uint64_t h[8];
+ uint64_t t[2];
+ uint64_t f[2];
+ uint8_t buf[BLAKE2B_BLOCKBYTES];
+ size_t buflen;
+ size_t outlen;
+ uint8_t last_node;
+} blake2b_state;
+
+#define BLAKE2B_CTX blake2b_state
+#define BLAKE2B_BLOCK_LENGTH BLAKE2B_BLOCKBYTES
+#define BLAKE2B_DIGEST_LENGTH BLAKE2B_OUTBYTES
+#define BLAKE2B_KEY_LENGTH BLAKE2B_KEYBYTES
+
+int blake2b_Init(blake2b_state *S, size_t outlen);
+int blake2b_InitKey(blake2b_state *S, size_t outlen, const void *key, size_t keylen);
+int blake2b_InitPersonal(blake2b_state *S, size_t outlen, const void *personal, size_t personal_len);
+int blake2b_Update(blake2b_state *S, const void *pin, size_t inlen);
+int blake2b_Final(blake2b_state *S, void *out, size_t outlen);
+
+int blake2b(const uint8_t *msg, uint32_t msg_len, void *out, size_t outlen);
+int blake2b_Key(const uint8_t *msg, uint32_t msg_len, const void *key, size_t keylen, void *out, size_t outlen);
+
+#endif
diff --git a/src/crypto/bip39/blake2s.h b/src/crypto/bip39/blake2s.h
new file mode 100644
index 000000000..57991bc91
--- /dev/null
+++ b/src/crypto/bip39/blake2s.h
@@ -0,0 +1,41 @@
+#ifndef __BLAKE2S_H__
+#define __BLAKE2S_H__
+
+#include
+#include
+
+enum blake2s_constant
+{
+ BLAKE2S_BLOCKBYTES = 64,
+ BLAKE2S_OUTBYTES = 32,
+ BLAKE2S_KEYBYTES = 32,
+ BLAKE2S_SALTBYTES = 8,
+ BLAKE2S_PERSONALBYTES = 8
+};
+
+typedef struct __blake2s_state
+{
+ uint32_t h[8];
+ uint32_t t[2];
+ uint32_t f[2];
+ uint8_t buf[BLAKE2S_BLOCKBYTES];
+ uint32_t buflen;
+ uint8_t outlen;
+ uint8_t last_node;
+} blake2s_state;
+
+#define BLAKE2S_CTX blake2s_state
+#define BLAKE2S_BLOCK_LENGTH BLAKE2S_BLOCKBYTES
+#define BLAKE2S_DIGEST_LENGTH BLAKE2S_OUTBYTES
+#define BLAKE2S_KEY_LENGTH BLAKE2S_KEYBYTES
+
+int blake2s_Init(blake2s_state *S, size_t outlen);
+int blake2s_InitKey(blake2s_state *S, size_t outlen, const void *key, size_t keylen);
+int blake2s_InitPersonal(blake2s_state *S, size_t outlen, const void *personal, size_t personal_len);
+int blake2s_Update(blake2s_state *S, const void *pin, size_t inlen);
+int blake2s_Final(blake2s_state *S, void *out, size_t outlen);
+
+int blake2s(const uint8_t *msg, uint32_t msg_len, void *out, size_t outlen);
+int blake2s_Key(const uint8_t *msg, uint32_t msg_len, const void *key, size_t keylen, void *out, size_t outlen);
+
+#endif
diff --git a/src/crypto/bip39/hasher.c b/src/crypto/bip39/hasher.c
new file mode 100644
index 000000000..dac3e9bf5
--- /dev/null
+++ b/src/crypto/bip39/hasher.c
@@ -0,0 +1,144 @@
+/**
+ * Copyright (c) 2017 Saleem Rashid
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "hasher.h"
+#include "ripemd160.h"
+
+void hasher_InitParam(Hasher *hasher, HasherType type, const void *param, uint32_t param_size) {
+ hasher->type = type;
+ hasher->param = param;
+ hasher->param_size = param_size;
+
+ switch (hasher->type) {
+ case HASHER_SHA2:
+ case HASHER_SHA2D:
+ case HASHER_SHA2_RIPEMD:
+ sha256_Init(&hasher->ctx.sha2);
+ break;
+ case HASHER_SHA3:
+#if USE_KECCAK
+ case HASHER_SHA3K:
+#endif
+ sha3_256_Init(&hasher->ctx.sha3);
+ break;
+ case HASHER_BLAKE:
+ case HASHER_BLAKED:
+ case HASHER_BLAKE_RIPEMD:
+ blake256_Init(&hasher->ctx.blake);
+ break;
+ case HASHER_GROESTLD_TRUNC:
+ groestl512_Init(&hasher->ctx.groestl);
+ break;
+ case HASHER_BLAKE2B:
+ blake2b_Init(&hasher->ctx.blake2b, 32);
+ break;
+ case HASHER_BLAKE2B_PERSONAL:
+ blake2b_InitPersonal(&hasher->ctx.blake2b, 32, hasher->param, hasher->param_size);
+ break;
+ }
+}
+
+void hasher_Init(Hasher *hasher, HasherType type) {
+ hasher_InitParam(hasher, type, NULL, 0);
+}
+
+void hasher_Reset(Hasher *hasher) {
+ hasher_InitParam(hasher, hasher->type, hasher->param, hasher->param_size);
+}
+
+void hasher_Update(Hasher *hasher, const uint8_t *data, size_t length) {
+ switch (hasher->type) {
+ case HASHER_SHA2:
+ case HASHER_SHA2D:
+ case HASHER_SHA2_RIPEMD:
+ sha256_Update(&hasher->ctx.sha2, data, length);
+ break;
+ case HASHER_SHA3:
+#if USE_KECCAK
+ case HASHER_SHA3K:
+#endif
+ sha3_Update(&hasher->ctx.sha3, data, length);
+ break;
+ case HASHER_BLAKE:
+ case HASHER_BLAKED:
+ case HASHER_BLAKE_RIPEMD:
+ blake256_Update(&hasher->ctx.blake, data, length);
+ break;
+ case HASHER_GROESTLD_TRUNC:
+ groestl512_Update(&hasher->ctx.groestl, data, length);
+ break;
+ case HASHER_BLAKE2B:
+ case HASHER_BLAKE2B_PERSONAL:
+ blake2b_Update(&hasher->ctx.blake2b, data, length);
+ break;
+ }
+}
+
+void hasher_Final(Hasher *hasher, uint8_t hash[HASHER_DIGEST_LENGTH]) {
+ switch (hasher->type) {
+ case HASHER_SHA2:
+ sha256_Final(&hasher->ctx.sha2, hash);
+ break;
+ case HASHER_SHA2D:
+ sha256_Final(&hasher->ctx.sha2, hash);
+ hasher_Raw(HASHER_SHA2, hash, HASHER_DIGEST_LENGTH, hash);
+ break;
+ case HASHER_SHA2_RIPEMD:
+ sha256_Final(&hasher->ctx.sha2, hash);
+ ripemd160(hash, HASHER_DIGEST_LENGTH, hash);
+ break;
+ case HASHER_SHA3:
+ sha3_Final(&hasher->ctx.sha3, hash);
+ break;
+#if USE_KECCAK
+ case HASHER_SHA3K:
+ keccak_Final(&hasher->ctx.sha3, hash);
+ break;
+#endif
+ case HASHER_BLAKE:
+ blake256_Final(&hasher->ctx.blake, hash);
+ break;
+ case HASHER_BLAKED:
+ blake256_Final(&hasher->ctx.blake, hash);
+ hasher_Raw(HASHER_BLAKE, hash, HASHER_DIGEST_LENGTH, hash);
+ break;
+ case HASHER_BLAKE_RIPEMD:
+ blake256_Final(&hasher->ctx.blake, hash);
+ ripemd160(hash, HASHER_DIGEST_LENGTH, hash);
+ break;
+ case HASHER_GROESTLD_TRUNC:
+ groestl512_DoubleTrunc(&hasher->ctx.groestl, hash);
+ break;
+ case HASHER_BLAKE2B:
+ case HASHER_BLAKE2B_PERSONAL:
+ blake2b_Final(&hasher->ctx.blake2b, hash, 32);
+ break;
+ }
+}
+
+void hasher_Raw(HasherType type, const uint8_t *data, size_t length, uint8_t hash[HASHER_DIGEST_LENGTH]) {
+ Hasher hasher;
+
+ hasher_Init(&hasher, type);
+ hasher_Update(&hasher, data, length);
+ hasher_Final(&hasher, hash);
+}
diff --git a/src/crypto/bip39/hasher.h b/src/crypto/bip39/hasher.h
new file mode 100644
index 000000000..0cde1df8b
--- /dev/null
+++ b/src/crypto/bip39/hasher.h
@@ -0,0 +1,80 @@
+/**
+ * Copyright (c) 2017 Saleem Rashid
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __HASHER_H__
+#define __HASHER_H__
+
+#include
+#include
+
+#include "sha2.h"
+#include "sha3.h"
+#include "blake256.h"
+#include "groestl.h"
+#include "blake2b.h"
+
+#define HASHER_DIGEST_LENGTH 32
+
+typedef enum {
+ HASHER_SHA2,
+ HASHER_SHA2D,
+ HASHER_SHA2_RIPEMD,
+
+ HASHER_SHA3,
+#if USE_KECCAK
+ HASHER_SHA3K,
+#endif
+
+ HASHER_BLAKE,
+ HASHER_BLAKED,
+ HASHER_BLAKE_RIPEMD,
+
+ HASHER_GROESTLD_TRUNC, /* Double Groestl512 hasher truncated to 256 bits */
+
+ HASHER_BLAKE2B,
+ HASHER_BLAKE2B_PERSONAL,
+} HasherType;
+
+typedef struct {
+ HasherType type;
+
+ union {
+ SHA256_CTX sha2; // for HASHER_SHA2{,D}
+ SHA3_CTX sha3; // for HASHER_SHA3{,K}
+ BLAKE256_CTX blake; // for HASHER_BLAKE{,D}
+ GROESTL512_CTX groestl; // for HASHER_GROESTLD_TRUNC
+ BLAKE2B_CTX blake2b; // for HASHER_BLAKE2B{,_PERSONAL}
+ } ctx;
+
+ const void *param;
+ uint32_t param_size;
+} Hasher;
+
+void hasher_InitParam(Hasher *hasher, HasherType type, const void *param, uint32_t param_size);
+void hasher_Init(Hasher *hasher, HasherType type);
+void hasher_Reset(Hasher *hasher);
+void hasher_Update(Hasher *hasher, const uint8_t *data, size_t length);
+void hasher_Final(Hasher *hasher, uint8_t hash[HASHER_DIGEST_LENGTH]);
+
+void hasher_Raw(HasherType type, const uint8_t *data, size_t length, uint8_t hash[HASHER_DIGEST_LENGTH]);
+
+#endif
diff --git a/src/crypto/bip39/hmac.c b/src/crypto/bip39/hmac.c
new file mode 100644
index 000000000..654f2d6e8
--- /dev/null
+++ b/src/crypto/bip39/hmac.c
@@ -0,0 +1,176 @@
+/**
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include
+
+#include "hmac.h"
+#include "memzero.h"
+#include "options.h"
+
+void hmac_sha256_Init(HMAC_SHA256_CTX *hctx, const uint8_t *key,
+ const uint32_t keylen) {
+ static CONFIDENTIAL uint8_t i_key_pad[SHA256_BLOCK_LENGTH];
+ memzero(i_key_pad, SHA256_BLOCK_LENGTH);
+ if (keylen > SHA256_BLOCK_LENGTH) {
+ sha256_Raw(key, keylen, i_key_pad);
+ } else {
+ memcpy(i_key_pad, key, keylen);
+ }
+ for (int i = 0; i < SHA256_BLOCK_LENGTH; i++) {
+ hctx->o_key_pad[i] = i_key_pad[i] ^ 0x5c;
+ i_key_pad[i] ^= 0x36;
+ }
+ sha256_Init(&(hctx->ctx));
+ sha256_Update(&(hctx->ctx), i_key_pad, SHA256_BLOCK_LENGTH);
+ memzero(i_key_pad, sizeof(i_key_pad));
+}
+
+void hmac_sha256_Update(HMAC_SHA256_CTX *hctx, const uint8_t *msg,
+ const uint32_t msglen) {
+ sha256_Update(&(hctx->ctx), msg, msglen);
+}
+
+void hmac_sha256_Final(HMAC_SHA256_CTX *hctx, uint8_t *hmac) {
+ sha256_Final(&(hctx->ctx), hmac);
+ sha256_Init(&(hctx->ctx));
+ sha256_Update(&(hctx->ctx), hctx->o_key_pad, SHA256_BLOCK_LENGTH);
+ sha256_Update(&(hctx->ctx), hmac, SHA256_DIGEST_LENGTH);
+ sha256_Final(&(hctx->ctx), hmac);
+ memzero(hctx, sizeof(HMAC_SHA256_CTX));
+}
+
+void hmac_sha256(const uint8_t *key, const uint32_t keylen, const uint8_t *msg,
+ const uint32_t msglen, uint8_t *hmac) {
+ static CONFIDENTIAL HMAC_SHA256_CTX hctx;
+ hmac_sha256_Init(&hctx, key, keylen);
+ hmac_sha256_Update(&hctx, msg, msglen);
+ hmac_sha256_Final(&hctx, hmac);
+}
+
+void hmac_sha256_prepare(const uint8_t *key, const uint32_t keylen,
+ uint32_t *opad_digest, uint32_t *ipad_digest) {
+ static CONFIDENTIAL uint32_t key_pad[SHA256_BLOCK_LENGTH / sizeof(uint32_t)];
+
+ memzero(key_pad, sizeof(key_pad));
+ if (keylen > SHA256_BLOCK_LENGTH) {
+ static CONFIDENTIAL SHA256_CTX context;
+ sha256_Init(&context);
+ sha256_Update(&context, key, keylen);
+ sha256_Final(&context, (uint8_t *)key_pad);
+ } else {
+ memcpy(key_pad, key, keylen);
+ }
+
+ /* compute o_key_pad and its digest */
+ for (int i = 0; i < SHA256_BLOCK_LENGTH / (int)sizeof(uint32_t); i++) {
+ uint32_t data = 0;
+#if BYTE_ORDER == LITTLE_ENDIAN
+ REVERSE32(key_pad[i], data);
+#else
+ data = key_pad[i];
+#endif
+ key_pad[i] = data ^ 0x5c5c5c5c;
+ }
+ sha256_Transform(sha256_initial_hash_value, key_pad, opad_digest);
+
+ /* convert o_key_pad to i_key_pad and compute its digest */
+ for (int i = 0; i < SHA256_BLOCK_LENGTH / (int)sizeof(uint32_t); i++) {
+ key_pad[i] = key_pad[i] ^ 0x5c5c5c5c ^ 0x36363636;
+ }
+ sha256_Transform(sha256_initial_hash_value, key_pad, ipad_digest);
+ memzero(key_pad, sizeof(key_pad));
+}
+
+void hmac_sha512_Init(HMAC_SHA512_CTX *hctx, const uint8_t *key,
+ const uint32_t keylen) {
+ static CONFIDENTIAL uint8_t i_key_pad[SHA512_BLOCK_LENGTH];
+ memzero(i_key_pad, SHA512_BLOCK_LENGTH);
+ if (keylen > SHA512_BLOCK_LENGTH) {
+ sha512_Raw(key, keylen, i_key_pad);
+ } else {
+ memcpy(i_key_pad, key, keylen);
+ }
+ for (int i = 0; i < SHA512_BLOCK_LENGTH; i++) {
+ hctx->o_key_pad[i] = i_key_pad[i] ^ 0x5c;
+ i_key_pad[i] ^= 0x36;
+ }
+ sha512_Init(&(hctx->ctx));
+ sha512_Update(&(hctx->ctx), i_key_pad, SHA512_BLOCK_LENGTH);
+ memzero(i_key_pad, sizeof(i_key_pad));
+}
+
+void hmac_sha512_Update(HMAC_SHA512_CTX *hctx, const uint8_t *msg,
+ const uint32_t msglen) {
+ sha512_Update(&(hctx->ctx), msg, msglen);
+}
+
+void hmac_sha512_Final(HMAC_SHA512_CTX *hctx, uint8_t *hmac) {
+ sha512_Final(&(hctx->ctx), hmac);
+ sha512_Init(&(hctx->ctx));
+ sha512_Update(&(hctx->ctx), hctx->o_key_pad, SHA512_BLOCK_LENGTH);
+ sha512_Update(&(hctx->ctx), hmac, SHA512_DIGEST_LENGTH);
+ sha512_Final(&(hctx->ctx), hmac);
+ memzero(hctx, sizeof(HMAC_SHA512_CTX));
+}
+
+void hmac_sha512(const uint8_t *key, const uint32_t keylen, const uint8_t *msg,
+ const uint32_t msglen, uint8_t *hmac) {
+ HMAC_SHA512_CTX hctx = {0};
+ hmac_sha512_Init(&hctx, key, keylen);
+ hmac_sha512_Update(&hctx, msg, msglen);
+ hmac_sha512_Final(&hctx, hmac);
+}
+
+void hmac_sha512_prepare(const uint8_t *key, const uint32_t keylen,
+ uint64_t *opad_digest, uint64_t *ipad_digest) {
+ static CONFIDENTIAL uint64_t key_pad[SHA512_BLOCK_LENGTH / sizeof(uint64_t)];
+
+ memzero(key_pad, sizeof(key_pad));
+ if (keylen > SHA512_BLOCK_LENGTH) {
+ static CONFIDENTIAL SHA512_CTX context;
+ sha512_Init(&context);
+ sha512_Update(&context, key, keylen);
+ sha512_Final(&context, (uint8_t *)key_pad);
+ } else {
+ memcpy(key_pad, key, keylen);
+ }
+
+ /* compute o_key_pad and its digest */
+ for (int i = 0; i < SHA512_BLOCK_LENGTH / (int)sizeof(uint64_t); i++) {
+ uint64_t data = 0;
+#if BYTE_ORDER == LITTLE_ENDIAN
+ REVERSE64(key_pad[i], data);
+#else
+ data = key_pad[i];
+#endif
+ key_pad[i] = data ^ 0x5c5c5c5c5c5c5c5c;
+ }
+ sha512_Transform(sha512_initial_hash_value, key_pad, opad_digest);
+
+ /* convert o_key_pad to i_key_pad and compute its digest */
+ for (int i = 0; i < SHA512_BLOCK_LENGTH / (int)sizeof(uint64_t); i++) {
+ key_pad[i] = key_pad[i] ^ 0x5c5c5c5c5c5c5c5c ^ 0x3636363636363636;
+ }
+ sha512_Transform(sha512_initial_hash_value, key_pad, ipad_digest);
+ memzero(key_pad, sizeof(key_pad));
+}
diff --git a/src/crypto/bip39/hmac.h b/src/crypto/bip39/hmac.h
new file mode 100644
index 000000000..3cfc0cd0f
--- /dev/null
+++ b/src/crypto/bip39/hmac.h
@@ -0,0 +1,52 @@
+/**
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT HMAC_SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __HMAC_H__
+#define __HMAC_H__
+
+#include
+#include "sha2.h"
+
+typedef struct _HMAC_SHA256_CTX {
+ uint8_t o_key_pad[SHA256_BLOCK_LENGTH];
+ SHA256_CTX ctx;
+} HMAC_SHA256_CTX;
+
+typedef struct _HMAC_SHA512_CTX {
+ uint8_t o_key_pad[SHA512_BLOCK_LENGTH];
+ SHA512_CTX ctx;
+} HMAC_SHA512_CTX;
+
+void hmac_sha256_Init(HMAC_SHA256_CTX *hctx, const uint8_t *key, const uint32_t keylen);
+void hmac_sha256_Update(HMAC_SHA256_CTX *hctx, const uint8_t *msg, const uint32_t msglen);
+void hmac_sha256_Final(HMAC_SHA256_CTX *hctx, uint8_t *hmac);
+void hmac_sha256(const uint8_t *key, const uint32_t keylen, const uint8_t *msg, const uint32_t msglen, uint8_t *hmac);
+void hmac_sha256_prepare(const uint8_t *key, const uint32_t keylen, uint32_t *opad_digest, uint32_t *ipad_digest);
+
+void hmac_sha512_Init(HMAC_SHA512_CTX *hctx, const uint8_t *key, const uint32_t keylen);
+void hmac_sha512_Update(HMAC_SHA512_CTX *hctx, const uint8_t *msg, const uint32_t msglen);
+void hmac_sha512_Final(HMAC_SHA512_CTX *hctx, uint8_t *hmac);
+void hmac_sha512(const uint8_t *key, const uint32_t keylen, const uint8_t *msg, const uint32_t msglen, uint8_t *hmac);
+void hmac_sha512_prepare(const uint8_t *key, const uint32_t keylen, uint64_t *opad_digest, uint64_t *ipad_digest);
+
+#endif
diff --git a/src/crypto/bip39/hmac_drbg.c b/src/crypto/bip39/hmac_drbg.c
new file mode 100644
index 000000000..1ed1401b8
--- /dev/null
+++ b/src/crypto/bip39/hmac_drbg.c
@@ -0,0 +1,130 @@
+/**
+ * Copyright (c) 2019 Andrew R. Kozlik
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "hmac_drbg.h"
+#include
+#include "memzero.h"
+#include "sha2.h"
+
+static void update_k(HMAC_DRBG_CTX *ctx, uint8_t domain, const uint8_t *data1,
+ size_t len1, const uint8_t *data2, size_t len2) {
+ // Computes K = HMAC(K, V || domain || data1 || data 2).
+
+ // First hash operation of HMAC.
+ uint32_t h[SHA256_BLOCK_LENGTH / sizeof(uint32_t)] = {0};
+ if (len1 + len2 == 0) {
+ ctx->v[8] = 0x00800000;
+ ctx->v[15] = (SHA256_BLOCK_LENGTH + SHA256_DIGEST_LENGTH + 1) * 8;
+ sha256_Transform(ctx->idig, ctx->v, h);
+ ctx->v[8] = 0x80000000;
+ ctx->v[15] = (SHA256_BLOCK_LENGTH + SHA256_DIGEST_LENGTH) * 8;
+ } else {
+ SHA256_CTX sha_ctx = {0};
+ memcpy(sha_ctx.state, ctx->idig, SHA256_DIGEST_LENGTH);
+ for (size_t i = 0; i < SHA256_DIGEST_LENGTH / sizeof(uint32_t); i++) {
+#if BYTE_ORDER == LITTLE_ENDIAN
+ REVERSE32(ctx->v[i], sha_ctx.buffer[i]);
+#else
+ sha_ctx.buffer[i] = ctx->v[i];
+#endif
+ }
+ ((uint8_t *)sha_ctx.buffer)[SHA256_DIGEST_LENGTH] = domain;
+ sha_ctx.bitcount = (SHA256_BLOCK_LENGTH + SHA256_DIGEST_LENGTH + 1) * 8;
+ sha256_Update(&sha_ctx, data1, len1);
+ sha256_Update(&sha_ctx, data2, len2);
+ sha256_Final(&sha_ctx, (uint8_t *)h);
+#if BYTE_ORDER == LITTLE_ENDIAN
+ for (size_t i = 0; i < SHA256_DIGEST_LENGTH / sizeof(uint32_t); i++)
+ REVERSE32(h[i], h[i]);
+#endif
+ }
+
+ // Second hash operation of HMAC.
+ h[8] = 0x80000000;
+ h[15] = (SHA256_BLOCK_LENGTH + SHA256_DIGEST_LENGTH) * 8;
+ sha256_Transform(ctx->odig, h, h);
+
+ // Precompute the inner digest and outer digest of K.
+ h[8] = 0;
+ h[15] = 0;
+ for (size_t i = 0; i < SHA256_BLOCK_LENGTH / sizeof(uint32_t); i++) {
+ h[i] ^= 0x36363636;
+ }
+ sha256_Transform(sha256_initial_hash_value, h, ctx->idig);
+
+ for (size_t i = 0; i < SHA256_BLOCK_LENGTH / sizeof(uint32_t); i++) {
+ h[i] = h[i] ^ 0x36363636 ^ 0x5c5c5c5c;
+ }
+ sha256_Transform(sha256_initial_hash_value, h, ctx->odig);
+ memzero(h, sizeof(h));
+}
+
+static void update_v(HMAC_DRBG_CTX *ctx) {
+ sha256_Transform(ctx->idig, ctx->v, ctx->v);
+ sha256_Transform(ctx->odig, ctx->v, ctx->v);
+}
+
+void hmac_drbg_init(HMAC_DRBG_CTX *ctx, const uint8_t *entropy,
+ size_t entropy_len, const uint8_t *nonce,
+ size_t nonce_len) {
+ uint32_t h[SHA256_BLOCK_LENGTH / sizeof(uint32_t)] = {0};
+
+ // Precompute the inner digest and outer digest of K = 0x00 ... 0x00.
+ memset(h, 0x36, sizeof(h));
+ sha256_Transform(sha256_initial_hash_value, h, ctx->idig);
+ memset(h, 0x5c, sizeof(h));
+ sha256_Transform(sha256_initial_hash_value, h, ctx->odig);
+
+ // Let V = 0x01 ... 0x01.
+ memset(ctx->v, 1, SHA256_DIGEST_LENGTH);
+ for (size_t i = 9; i < 15; i++) ctx->v[i] = 0;
+ ctx->v[8] = 0x80000000;
+ ctx->v[15] = (SHA256_BLOCK_LENGTH + SHA256_DIGEST_LENGTH) * 8;
+
+ hmac_drbg_reseed(ctx, entropy, entropy_len, nonce, nonce_len);
+
+ memzero(h, sizeof(h));
+}
+
+void hmac_drbg_reseed(HMAC_DRBG_CTX *ctx, const uint8_t *entropy, size_t len,
+ const uint8_t *addin, size_t addin_len) {
+ update_k(ctx, 0, entropy, len, addin, addin_len);
+ update_v(ctx);
+ if (len == 0) return;
+ update_k(ctx, 1, entropy, len, addin, addin_len);
+ update_v(ctx);
+}
+
+void hmac_drbg_generate(HMAC_DRBG_CTX *ctx, uint8_t *buf, size_t len) {
+ size_t i = 0;
+ while (i < len) {
+ update_v(ctx);
+ for (size_t j = 0; j < 8 && i < len; j++) {
+ uint32_t r = ctx->v[j];
+ for (int k = 24; k >= 0 && i < len; k -= 8) {
+ buf[i++] = (r >> k) & 0xFF;
+ }
+ }
+ }
+ update_k(ctx, 0, NULL, 0, NULL, 0);
+ update_v(ctx);
+}
diff --git a/src/crypto/bip39/hmac_drbg.h b/src/crypto/bip39/hmac_drbg.h
new file mode 100644
index 000000000..4b969dedb
--- /dev/null
+++ b/src/crypto/bip39/hmac_drbg.h
@@ -0,0 +1,43 @@
+/**
+ * Copyright (c) 2019 Andrew R. Kozlik
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __HMAC_DRBG_H__
+#define __HMAC_DRBG_H__
+
+#include
+#include
+
+// HMAC based Deterministic Random Bit Generator with SHA-256
+
+typedef struct _HMAC_DRBG_CTX {
+ uint32_t odig[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
+ uint32_t idig[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
+ uint32_t v[SHA256_BLOCK_LENGTH / sizeof(uint32_t)];
+} HMAC_DRBG_CTX;
+
+void hmac_drbg_init(HMAC_DRBG_CTX *ctx, const uint8_t *buf, size_t len,
+ const uint8_t *nonce, size_t nonce_len);
+void hmac_drbg_reseed(HMAC_DRBG_CTX *ctx, const uint8_t *buf, size_t len,
+ const uint8_t *addin, size_t addin_len);
+void hmac_drbg_generate(HMAC_DRBG_CTX *ctx, uint8_t *buf, size_t len);
+
+#endif
diff --git a/src/crypto/bip39/memzero.c b/src/crypto/bip39/memzero.c
new file mode 100644
index 000000000..3c3a7383d
--- /dev/null
+++ b/src/crypto/bip39/memzero.c
@@ -0,0 +1,66 @@
+#ifndef __STDC_WANT_LIB_EXT1__
+#define __STDC_WANT_LIB_EXT1__ 1 // C11's bounds-checking interface.
+#endif
+#include
+
+#ifdef _WIN32
+#include
+#endif
+
+#ifdef __unix__
+#include
+#include
+#endif
+
+// C11's bounds-checking interface.
+#if defined(__STDC_LIB_EXT1__)
+#define HAVE_MEMSET_S 1
+#endif
+
+// GNU C Library version 2.25 or later.
+#if defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))
+#define HAVE_EXPLICIT_BZERO 1
+#endif
+
+// Newlib
+#if defined( __NEWLIB__)
+#define HAVE_EXPLICIT_BZERO 1
+#endif
+
+// FreeBSD version 11.0 or later.
+#if defined(__FreeBSD__) && __FreeBSD_version >= 1100037
+#define HAVE_EXPLICIT_BZERO 1
+#endif
+
+// OpenBSD version 5.5 or later.
+#if defined(__OpenBSD__) && OpenBSD >= 201405
+#define HAVE_EXPLICIT_BZERO 1
+#endif
+
+// NetBSD version 7.2 or later.
+#if defined(__NetBSD__) && __NetBSD_Version__ >= 702000000
+#define HAVE_EXPLICIT_MEMSET 1
+#endif
+
+// Adapted from https://github.com/jedisct1/libsodium/blob/1647f0d53ae0e370378a9195477e3df0a792408f/src/libsodium/sodium/utils.c#L102-L130
+
+void memzero(void *const pnt, const size_t len)
+{
+#ifdef _WIN32
+ SecureZeroMemory(pnt, len);
+#elif defined(HAVE_MEMSET_S)
+ memset_s(pnt, (rsize_t) len, 0, (rsize_t) len);
+#elif defined(HAVE_EXPLICIT_BZERO)
+ explicit_bzero(pnt, len);
+#elif defined(HAVE_EXPLICIT_MEMSET)
+ explicit_memset(pnt, 0, len);
+#else
+ volatile unsigned char *volatile pnt_ =
+ (volatile unsigned char *volatile) pnt;
+ size_t i = (size_t) 0U;
+
+ while (i < len) {
+ pnt_[i++] = 0U;
+ }
+#endif
+}
diff --git a/src/crypto/bip39/memzero.h b/src/crypto/bip39/memzero.h
new file mode 100644
index 000000000..a7797d2b3
--- /dev/null
+++ b/src/crypto/bip39/memzero.h
@@ -0,0 +1,8 @@
+#ifndef __MEMZERO_H__
+#define __MEMZERO_H__
+
+#include
+
+void memzero(void * const pnt, const size_t len);
+
+#endif
diff --git a/src/crypto/bip39/options.h b/src/crypto/bip39/options.h
new file mode 100644
index 000000000..e57654e6c
--- /dev/null
+++ b/src/crypto/bip39/options.h
@@ -0,0 +1,99 @@
+/**
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __OPTIONS_H__
+#define __OPTIONS_H__
+
+// use precomputed Curve Points (some scalar multiples of curve base point G)
+#ifndef USE_PRECOMPUTED_CP
+#define USE_PRECOMPUTED_CP 1
+#endif
+
+// use fast inverse method
+#ifndef USE_INVERSE_FAST
+#define USE_INVERSE_FAST 1
+#endif
+
+// support for printing bignum256 structures via printf
+#ifndef USE_BN_PRINT
+#define USE_BN_PRINT 0
+#endif
+
+// use deterministic signatures
+#ifndef USE_RFC6979
+#define USE_RFC6979 1
+#endif
+
+// implement BIP32 caching
+#ifndef USE_BIP32_CACHE
+#define USE_BIP32_CACHE 1
+#define BIP32_CACHE_SIZE 10
+#define BIP32_CACHE_MAXDEPTH 8
+#endif
+
+// support constructing BIP32 nodes from ed25519 and curve25519 curves.
+#ifndef USE_BIP32_25519_CURVES
+#define USE_BIP32_25519_CURVES 1
+#endif
+
+// implement BIP39 caching
+#ifndef USE_BIP39_CACHE
+#define USE_BIP39_CACHE 1
+#define BIP39_CACHE_SIZE 4
+#endif
+
+// support Ethereum operations
+#ifndef USE_ETHEREUM
+#define USE_ETHEREUM 0
+#endif
+
+// support Graphene operations (STEEM, BitShares)
+#ifndef USE_GRAPHENE
+#define USE_GRAPHENE 0
+#endif
+
+// support NEM operations
+#ifndef USE_NEM
+#define USE_NEM 0
+#endif
+
+// support MONERO operations
+#ifndef USE_MONERO
+#define USE_MONERO 0
+#endif
+
+// support CARDANO operations
+#ifndef USE_CARDANO
+#define USE_CARDANO 0
+#endif
+
+// support Keccak hashing
+#ifndef USE_KECCAK
+#define USE_KECCAK 1
+#endif
+
+// add way how to mark confidential data
+#ifndef CONFIDENTIAL
+#define CONFIDENTIAL
+#endif
+
+#endif
diff --git a/src/crypto/bip39/pbkdf2.c b/src/crypto/bip39/pbkdf2.c
new file mode 100644
index 000000000..d9e142297
--- /dev/null
+++ b/src/crypto/bip39/pbkdf2.c
@@ -0,0 +1,179 @@
+/**
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "pbkdf2.h"
+#include
+#include "hmac.h"
+#include "memzero.h"
+#include "sha2.h"
+
+void pbkdf2_hmac_sha256_Init(PBKDF2_HMAC_SHA256_CTX *pctx, const uint8_t *pass,
+ int passlen, const uint8_t *salt, int saltlen,
+ uint32_t blocknr) {
+ SHA256_CTX ctx = {0};
+#if BYTE_ORDER == LITTLE_ENDIAN
+ REVERSE32(blocknr, blocknr);
+#endif
+
+ hmac_sha256_prepare(pass, passlen, pctx->odig, pctx->idig);
+ memzero(pctx->g, sizeof(pctx->g));
+ pctx->g[8] = 0x80000000;
+ pctx->g[15] = (SHA256_BLOCK_LENGTH + SHA256_DIGEST_LENGTH) * 8;
+
+ memcpy(ctx.state, pctx->idig, sizeof(pctx->idig));
+ ctx.bitcount = SHA256_BLOCK_LENGTH * 8;
+ sha256_Update(&ctx, salt, saltlen);
+ sha256_Update(&ctx, (uint8_t *)&blocknr, sizeof(blocknr));
+ sha256_Final(&ctx, (uint8_t *)pctx->g);
+#if BYTE_ORDER == LITTLE_ENDIAN
+ for (uint32_t k = 0; k < SHA256_DIGEST_LENGTH / sizeof(uint32_t); k++) {
+ REVERSE32(pctx->g[k], pctx->g[k]);
+ }
+#endif
+ sha256_Transform(pctx->odig, pctx->g, pctx->g);
+ memcpy(pctx->f, pctx->g, SHA256_DIGEST_LENGTH);
+ pctx->first = 1;
+}
+
+void pbkdf2_hmac_sha256_Update(PBKDF2_HMAC_SHA256_CTX *pctx,
+ uint32_t iterations) {
+ for (uint32_t i = pctx->first; i < iterations; i++) {
+ sha256_Transform(pctx->idig, pctx->g, pctx->g);
+ sha256_Transform(pctx->odig, pctx->g, pctx->g);
+ for (uint32_t j = 0; j < SHA256_DIGEST_LENGTH / sizeof(uint32_t); j++) {
+ pctx->f[j] ^= pctx->g[j];
+ }
+ }
+ pctx->first = 0;
+}
+
+void pbkdf2_hmac_sha256_Final(PBKDF2_HMAC_SHA256_CTX *pctx, uint8_t *key) {
+#if BYTE_ORDER == LITTLE_ENDIAN
+ for (uint32_t k = 0; k < SHA256_DIGEST_LENGTH / sizeof(uint32_t); k++) {
+ REVERSE32(pctx->f[k], pctx->f[k]);
+ }
+#endif
+ memcpy(key, pctx->f, SHA256_DIGEST_LENGTH);
+ memzero(pctx, sizeof(PBKDF2_HMAC_SHA256_CTX));
+}
+
+void pbkdf2_hmac_sha256(const uint8_t *pass, int passlen, const uint8_t *salt,
+ int saltlen, uint32_t iterations, uint8_t *key,
+ int keylen) {
+ uint32_t last_block_size = keylen % SHA256_DIGEST_LENGTH;
+ uint32_t blocks_count = keylen / SHA256_DIGEST_LENGTH;
+ if (last_block_size) {
+ blocks_count++;
+ } else {
+ last_block_size = SHA256_DIGEST_LENGTH;
+ }
+ for (uint32_t blocknr = 1; blocknr <= blocks_count; blocknr++) {
+ PBKDF2_HMAC_SHA256_CTX pctx = {0};
+ pbkdf2_hmac_sha256_Init(&pctx, pass, passlen, salt, saltlen, blocknr);
+ pbkdf2_hmac_sha256_Update(&pctx, iterations);
+ uint8_t digest[SHA256_DIGEST_LENGTH] = {0};
+ pbkdf2_hmac_sha256_Final(&pctx, digest);
+ uint32_t key_offset = (blocknr - 1) * SHA256_DIGEST_LENGTH;
+ if (blocknr < blocks_count) {
+ memcpy(key + key_offset, digest, SHA256_DIGEST_LENGTH);
+ } else {
+ memcpy(key + key_offset, digest, last_block_size);
+ }
+ }
+}
+
+void pbkdf2_hmac_sha512_Init(PBKDF2_HMAC_SHA512_CTX *pctx, const uint8_t *pass,
+ int passlen, const uint8_t *salt, int saltlen,
+ uint32_t blocknr) {
+ SHA512_CTX ctx = {0};
+#if BYTE_ORDER == LITTLE_ENDIAN
+ REVERSE32(blocknr, blocknr);
+#endif
+
+ hmac_sha512_prepare(pass, passlen, pctx->odig, pctx->idig);
+ memzero(pctx->g, sizeof(pctx->g));
+ pctx->g[8] = 0x8000000000000000;
+ pctx->g[15] = (SHA512_BLOCK_LENGTH + SHA512_DIGEST_LENGTH) * 8;
+
+ memcpy(ctx.state, pctx->idig, sizeof(pctx->idig));
+ ctx.bitcount[0] = SHA512_BLOCK_LENGTH * 8;
+ ctx.bitcount[1] = 0;
+ sha512_Update(&ctx, salt, saltlen);
+ sha512_Update(&ctx, (uint8_t *)&blocknr, sizeof(blocknr));
+ sha512_Final(&ctx, (uint8_t *)pctx->g);
+#if BYTE_ORDER == LITTLE_ENDIAN
+ for (uint32_t k = 0; k < SHA512_DIGEST_LENGTH / sizeof(uint64_t); k++) {
+ REVERSE64(pctx->g[k], pctx->g[k]);
+ }
+#endif
+ sha512_Transform(pctx->odig, pctx->g, pctx->g);
+ memcpy(pctx->f, pctx->g, SHA512_DIGEST_LENGTH);
+ pctx->first = 1;
+}
+
+void pbkdf2_hmac_sha512_Update(PBKDF2_HMAC_SHA512_CTX *pctx,
+ uint32_t iterations) {
+ for (uint32_t i = pctx->first; i < iterations; i++) {
+ sha512_Transform(pctx->idig, pctx->g, pctx->g);
+ sha512_Transform(pctx->odig, pctx->g, pctx->g);
+ for (uint32_t j = 0; j < SHA512_DIGEST_LENGTH / sizeof(uint64_t); j++) {
+ pctx->f[j] ^= pctx->g[j];
+ }
+ }
+ pctx->first = 0;
+}
+
+void pbkdf2_hmac_sha512_Final(PBKDF2_HMAC_SHA512_CTX *pctx, uint8_t *key) {
+#if BYTE_ORDER == LITTLE_ENDIAN
+ for (uint32_t k = 0; k < SHA512_DIGEST_LENGTH / sizeof(uint64_t); k++) {
+ REVERSE64(pctx->f[k], pctx->f[k]);
+ }
+#endif
+ memcpy(key, pctx->f, SHA512_DIGEST_LENGTH);
+ memzero(pctx, sizeof(PBKDF2_HMAC_SHA512_CTX));
+}
+
+void pbkdf2_hmac_sha512(const uint8_t *pass, int passlen, const uint8_t *salt,
+ int saltlen, uint32_t iterations, uint8_t *key,
+ int keylen) {
+ uint32_t last_block_size = keylen % SHA512_DIGEST_LENGTH;
+ uint32_t blocks_count = keylen / SHA512_DIGEST_LENGTH;
+ if (last_block_size) {
+ blocks_count++;
+ } else {
+ last_block_size = SHA512_DIGEST_LENGTH;
+ }
+ for (uint32_t blocknr = 1; blocknr <= blocks_count; blocknr++) {
+ PBKDF2_HMAC_SHA512_CTX pctx = {0};
+ pbkdf2_hmac_sha512_Init(&pctx, pass, passlen, salt, saltlen, blocknr);
+ pbkdf2_hmac_sha512_Update(&pctx, iterations);
+ uint8_t digest[SHA512_DIGEST_LENGTH] = {0};
+ pbkdf2_hmac_sha512_Final(&pctx, digest);
+ uint32_t key_offset = (blocknr - 1) * SHA512_DIGEST_LENGTH;
+ if (blocknr < blocks_count) {
+ memcpy(key + key_offset, digest, SHA512_DIGEST_LENGTH);
+ } else {
+ memcpy(key + key_offset, digest, last_block_size);
+ }
+ }
+}
diff --git a/src/crypto/bip39/pbkdf2.h b/src/crypto/bip39/pbkdf2.h
new file mode 100644
index 000000000..e3f440c8f
--- /dev/null
+++ b/src/crypto/bip39/pbkdf2.h
@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __PBKDF2_H__
+#define __PBKDF2_H__
+
+#include
+#include "sha2.h"
+
+typedef struct _PBKDF2_HMAC_SHA256_CTX {
+ uint32_t odig[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
+ uint32_t idig[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
+ uint32_t f[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
+ uint32_t g[SHA256_BLOCK_LENGTH / sizeof(uint32_t)];
+ char first;
+} PBKDF2_HMAC_SHA256_CTX;
+
+typedef struct _PBKDF2_HMAC_SHA512_CTX {
+ uint64_t odig[SHA512_DIGEST_LENGTH / sizeof(uint64_t)];
+ uint64_t idig[SHA512_DIGEST_LENGTH / sizeof(uint64_t)];
+ uint64_t f[SHA512_DIGEST_LENGTH / sizeof(uint64_t)];
+ uint64_t g[SHA512_BLOCK_LENGTH / sizeof(uint64_t)];
+ char first;
+} PBKDF2_HMAC_SHA512_CTX;
+
+void pbkdf2_hmac_sha256_Init(PBKDF2_HMAC_SHA256_CTX *pctx, const uint8_t *pass, int passlen, const uint8_t *salt, int saltlen, uint32_t blocknr);
+void pbkdf2_hmac_sha256_Update(PBKDF2_HMAC_SHA256_CTX *pctx, uint32_t iterations);
+void pbkdf2_hmac_sha256_Final(PBKDF2_HMAC_SHA256_CTX *pctx, uint8_t *key);
+void pbkdf2_hmac_sha256(const uint8_t *pass, int passlen, const uint8_t *salt, int saltlen, uint32_t iterations, uint8_t *key, int keylen);
+
+void pbkdf2_hmac_sha512_Init(PBKDF2_HMAC_SHA512_CTX *pctx, const uint8_t *pass, int passlen, const uint8_t *salt, int saltlen, uint32_t blocknr);
+void pbkdf2_hmac_sha512_Update(PBKDF2_HMAC_SHA512_CTX *pctx, uint32_t iterations);
+void pbkdf2_hmac_sha512_Final(PBKDF2_HMAC_SHA512_CTX *pctx, uint8_t *key);
+void pbkdf2_hmac_sha512(const uint8_t *pass, int passlen, const uint8_t *salt, int saltlen, uint32_t iterations, uint8_t *key, int keylen);
+
+#endif
diff --git a/src/crypto/bip39/rand.c b/src/crypto/bip39/rand.c
new file mode 100644
index 000000000..ea95d143b
--- /dev/null
+++ b/src/crypto/bip39/rand.c
@@ -0,0 +1,81 @@
+/**
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "rand.h"
+
+#ifndef RAND_PLATFORM_INDEPENDENT
+
+#pragma message( \
+ "NOT SUITABLE FOR PRODUCTION USE! Replace random32() function with your own secure code.")
+
+// The following code is not supposed to be used in a production environment.
+// It's included only to make the library testable.
+// The message above tries to prevent any accidental use outside of the test
+// environment.
+//
+// You are supposed to replace the random8() and random32() function with your
+// own secure code. There is also a possibility to replace the random_buffer()
+// function as it is defined as a weak symbol.
+
+static uint32_t seed = 0;
+
+void random_reseed(const uint32_t value) { seed = value; }
+
+uint32_t random32(void) {
+ // Linear congruential generator from Numerical Recipes
+ // https://en.wikipedia.org/wiki/Linear_congruential_generator
+ seed = 1664525 * seed + 1013904223;
+ return seed;
+}
+
+#endif /* RAND_PLATFORM_INDEPENDENT */
+
+//
+// The following code is platform independent
+//
+
+void __attribute__((weak)) random_buffer(uint8_t *buf, size_t len) {
+ uint32_t r = 0;
+ for (size_t i = 0; i < len; i++) {
+ if (i % 4 == 0) {
+ r = random32();
+ }
+ buf[i] = (r >> ((i % 4) * 8)) & 0xFF;
+ }
+}
+
+uint32_t random_uniform(uint32_t n) {
+ uint32_t x = 0, max = 0xFFFFFFFF - (0xFFFFFFFF % n);
+ while ((x = random32()) >= max)
+ ;
+ return x / (max / n);
+}
+
+void random_permute(char *str, size_t len) {
+ for (int i = len - 1; i >= 1; i--) {
+ int j = random_uniform(i + 1);
+ char t = str[j];
+ str[j] = str[i];
+ str[i] = t;
+ }
+}
diff --git a/src/crypto/bip39/rand.h b/src/crypto/bip39/rand.h
new file mode 100644
index 000000000..49d9cfaf2
--- /dev/null
+++ b/src/crypto/bip39/rand.h
@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __RAND_H__
+#define __RAND_H__
+
+#include
+#include
+
+void random_reseed(const uint32_t value);
+uint32_t random32(void);
+void random_buffer(uint8_t *buf, size_t len);
+
+uint32_t random_uniform(uint32_t n);
+void random_permute(char *buf, size_t len);
+
+#endif
diff --git a/src/crypto/bip39/secp256k1.h b/src/crypto/bip39/secp256k1.h
new file mode 100644
index 000000000..234ca97a9
--- /dev/null
+++ b/src/crypto/bip39/secp256k1.h
@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __SECP256K1_H__
+#define __SECP256K1_H__
+
+#include
+
+#include "ecdsa.h"
+#include "bip32.h"
+
+extern const ecdsa_curve secp256k1;
+extern const curve_info secp256k1_info;
+extern const curve_info secp256k1_decred_info;
+extern const curve_info secp256k1_groestl_info;
+extern const curve_info secp256k1_smart_info;
+
+#endif
diff --git a/src/crypto/bip39/sha2.c b/src/crypto/bip39/sha2.c
new file mode 100644
index 000000000..b37e5cb41
--- /dev/null
+++ b/src/crypto/bip39/sha2.c
@@ -0,0 +1,1283 @@
+/**
+ * Copyright (c) 2000-2001 Aaron D. Gifford
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include
+#include
+#include "sha2.h"
+#include "memzero.h"
+
+/*
+ * ASSERT NOTE:
+ * Some sanity checking code is included using assert(). On my FreeBSD
+ * system, this additional code can be removed by compiling with NDEBUG
+ * defined. Check your own systems manpage on assert() to see how to
+ * compile WITHOUT the sanity checking code on your system.
+ *
+ * UNROLLED TRANSFORM LOOP NOTE:
+ * You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform
+ * loop version for the hash transform rounds (defined using macros
+ * later in this file). Either define on the command line, for example:
+ *
+ * cc -DSHA2_UNROLL_TRANSFORM -o sha2 sha2.c sha2prog.c
+ *
+ * or define below:
+ *
+ * #define SHA2_UNROLL_TRANSFORM
+ *
+ */
+
+
+/*** SHA-256/384/512 Machine Architecture Definitions *****************/
+/*
+ * BYTE_ORDER NOTE:
+ *
+ * Please make sure that your system defines BYTE_ORDER. If your
+ * architecture is little-endian, make sure it also defines
+ * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are
+ * equivilent.
+ *
+ * If your system does not define the above, then you can do so by
+ * hand like this:
+ *
+ * #define LITTLE_ENDIAN 1234
+ * #define BIG_ENDIAN 4321
+ *
+ * And for little-endian machines, add:
+ *
+ * #define BYTE_ORDER LITTLE_ENDIAN
+ *
+ * Or for big-endian machines:
+ *
+ * #define BYTE_ORDER BIG_ENDIAN
+ *
+ * The FreeBSD machine this was written on defines BYTE_ORDER
+ * appropriately by including (which in turn includes
+ * where the appropriate definitions are actually
+ * made).
+ */
+
+#if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
+#error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN
+#endif
+
+typedef uint8_t sha2_byte; /* Exactly 1 byte */
+typedef uint32_t sha2_word32; /* Exactly 4 bytes */
+typedef uint64_t sha2_word64; /* Exactly 8 bytes */
+
+/*** SHA-256/384/512 Various Length Definitions ***********************/
+/* NOTE: Most of these are in sha2.h */
+#define SHA1_SHORT_BLOCK_LENGTH (SHA1_BLOCK_LENGTH - 8)
+#define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8)
+#define SHA512_SHORT_BLOCK_LENGTH (SHA512_BLOCK_LENGTH - 16)
+
+/*
+ * Macro for incrementally adding the unsigned 64-bit integer n to the
+ * unsigned 128-bit integer (represented using a two-element array of
+ * 64-bit words):
+ */
+#define ADDINC128(w,n) { \
+ (w)[0] += (sha2_word64)(n); \
+ if ((w)[0] < (n)) { \
+ (w)[1]++; \
+ } \
+}
+
+#define MEMCPY_BCOPY(d,s,l) memcpy((d), (s), (l))
+
+/*** THE SIX LOGICAL FUNCTIONS ****************************************/
+/*
+ * Bit shifting and rotation (used by the six SHA-XYZ logical functions:
+ *
+ * NOTE: In the original SHA-256/384/512 document, the shift-right
+ * function was named R and the rotate-right function was called S.
+ * (See: http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf on the
+ * web.)
+ *
+ * The newer NIST FIPS 180-2 document uses a much clearer naming
+ * scheme, SHR for shift-right, ROTR for rotate-right, and ROTL for
+ * rotate-left. (See:
+ * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
+ * on the web.)
+ *
+ * WARNING: These macros must be used cautiously, since they reference
+ * supplied parameters sometimes more than once, and thus could have
+ * unexpected side-effects if used without taking this into account.
+ */
+
+/* Shift-right (used in SHA-256, SHA-384, and SHA-512): */
+#define SHR(b,x) ((x) >> (b))
+/* 32-bit Rotate-right (used in SHA-256): */
+#define ROTR32(b,x) (((x) >> (b)) | ((x) << (32 - (b))))
+/* 64-bit Rotate-right (used in SHA-384 and SHA-512): */
+#define ROTR64(b,x) (((x) >> (b)) | ((x) << (64 - (b))))
+/* 32-bit Rotate-left (used in SHA-1): */
+#define ROTL32(b,x) (((x) << (b)) | ((x) >> (32 - (b))))
+
+/* Two of six logical functions used in SHA-1, SHA-256, SHA-384, and SHA-512: */
+#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
+#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
+
+/* Function used in SHA-1: */
+#define Parity(x,y,z) ((x) ^ (y) ^ (z))
+
+/* Four of six logical functions used in SHA-256: */
+#define Sigma0_256(x) (ROTR32(2, (x)) ^ ROTR32(13, (x)) ^ ROTR32(22, (x)))
+#define Sigma1_256(x) (ROTR32(6, (x)) ^ ROTR32(11, (x)) ^ ROTR32(25, (x)))
+#define sigma0_256(x) (ROTR32(7, (x)) ^ ROTR32(18, (x)) ^ SHR(3 , (x)))
+#define sigma1_256(x) (ROTR32(17, (x)) ^ ROTR32(19, (x)) ^ SHR(10, (x)))
+
+/* Four of six logical functions used in SHA-384 and SHA-512: */
+#define Sigma0_512(x) (ROTR64(28, (x)) ^ ROTR64(34, (x)) ^ ROTR64(39, (x)))
+#define Sigma1_512(x) (ROTR64(14, (x)) ^ ROTR64(18, (x)) ^ ROTR64(41, (x)))
+#define sigma0_512(x) (ROTR64( 1, (x)) ^ ROTR64( 8, (x)) ^ SHR( 7, (x)))
+#define sigma1_512(x) (ROTR64(19, (x)) ^ ROTR64(61, (x)) ^ SHR( 6, (x)))
+
+/*** INTERNAL FUNCTION PROTOTYPES *************************************/
+/* NOTE: These should not be accessed directly from outside this
+ * library -- they are intended for private internal visibility/use
+ * only.
+ */
+static void sha512_Last(SHA512_CTX*);
+
+
+/*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/
+
+/* Hash constant words K for SHA-1: */
+#define K1_0_TO_19 0x5a827999UL
+#define K1_20_TO_39 0x6ed9eba1UL
+#define K1_40_TO_59 0x8f1bbcdcUL
+#define K1_60_TO_79 0xca62c1d6UL
+
+/* Initial hash value H for SHA-1: */
+const sha2_word32 sha1_initial_hash_value[SHA1_DIGEST_LENGTH / sizeof(sha2_word32)] = {
+ 0x67452301UL,
+ 0xefcdab89UL,
+ 0x98badcfeUL,
+ 0x10325476UL,
+ 0xc3d2e1f0UL
+};
+
+/* Hash constant words K for SHA-256: */
+static const sha2_word32 K256[64] = {
+ 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
+ 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
+ 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL,
+ 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL,
+ 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
+ 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL,
+ 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL,
+ 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL,
+ 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL,
+ 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
+ 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL,
+ 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL,
+ 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL,
+ 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL,
+ 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
+ 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
+};
+
+/* Initial hash value H for SHA-256: */
+const sha2_word32 sha256_initial_hash_value[8] = {
+ 0x6a09e667UL,
+ 0xbb67ae85UL,
+ 0x3c6ef372UL,
+ 0xa54ff53aUL,
+ 0x510e527fUL,
+ 0x9b05688cUL,
+ 0x1f83d9abUL,
+ 0x5be0cd19UL
+};
+
+/* Hash constant words K for SHA-384 and SHA-512: */
+static const sha2_word64 K512[80] = {
+ 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL,
+ 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL,
+ 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
+ 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL,
+ 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL,
+ 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
+ 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL,
+ 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL,
+ 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
+ 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL,
+ 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL,
+ 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
+ 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL,
+ 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL,
+ 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
+ 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL,
+ 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL,
+ 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
+ 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL,
+ 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL,
+ 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
+ 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL,
+ 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL,
+ 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
+ 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL,
+ 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL,
+ 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
+ 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL,
+ 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL,
+ 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
+ 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL,
+ 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL,
+ 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
+ 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL,
+ 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL,
+ 0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
+ 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL,
+ 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL,
+ 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
+ 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL
+};
+
+/* Initial hash value H for SHA-512 */
+const sha2_word64 sha512_initial_hash_value[8] = {
+ 0x6a09e667f3bcc908ULL,
+ 0xbb67ae8584caa73bULL,
+ 0x3c6ef372fe94f82bULL,
+ 0xa54ff53a5f1d36f1ULL,
+ 0x510e527fade682d1ULL,
+ 0x9b05688c2b3e6c1fULL,
+ 0x1f83d9abfb41bd6bULL,
+ 0x5be0cd19137e2179ULL
+};
+
+/*
+ * Constant used by SHA256/384/512_End() functions for converting the
+ * digest to a readable hexadecimal character string:
+ */
+static const char *sha2_hex_digits = "0123456789abcdef";
+
+
+/*** SHA-1: ***********************************************************/
+void sha1_Init(SHA1_CTX* context) {
+ MEMCPY_BCOPY(context->state, sha1_initial_hash_value, SHA1_DIGEST_LENGTH);
+ memzero(context->buffer, SHA1_BLOCK_LENGTH);
+ context->bitcount = 0;
+}
+
+#ifdef SHA2_UNROLL_TRANSFORM
+
+/* Unrolled SHA-1 round macros: */
+
+#define ROUND1_0_TO_15(a,b,c,d,e) \
+ (e) = ROTL32(5, (a)) + Ch((b), (c), (d)) + (e) + \
+ K1_0_TO_19 + ( W1[j] = *data++ ); \
+ (b) = ROTL32(30, (b)); \
+ j++;
+
+#define ROUND1_16_TO_19(a,b,c,d,e) \
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f]; \
+ (e) = ROTL32(5, a) + Ch(b,c,d) + e + K1_0_TO_19 + ( W1[j&0x0f] = ROTL32(1, T1) ); \
+ (b) = ROTL32(30, b); \
+ j++;
+
+#define ROUND1_20_TO_39(a,b,c,d,e) \
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f]; \
+ (e) = ROTL32(5, a) + Parity(b,c,d) + e + K1_20_TO_39 + ( W1[j&0x0f] = ROTL32(1, T1) ); \
+ (b) = ROTL32(30, b); \
+ j++;
+
+#define ROUND1_40_TO_59(a,b,c,d,e) \
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f]; \
+ (e) = ROTL32(5, a) + Maj(b,c,d) + e + K1_40_TO_59 + ( W1[j&0x0f] = ROTL32(1, T1) ); \
+ (b) = ROTL32(30, b); \
+ j++;
+
+#define ROUND1_60_TO_79(a,b,c,d,e) \
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f]; \
+ (e) = ROTL32(5, a) + Parity(b,c,d) + e + K1_60_TO_79 + ( W1[j&0x0f] = ROTL32(1, T1) ); \
+ (b) = ROTL32(30, b); \
+ j++;
+
+void sha1_Transform(const sha2_word32* state_in, const sha2_word32* data, sha2_word32* state_out) {
+ sha2_word32 a = 0, b = 0, c = 0, d = 0, e = 0;
+ sha2_word32 T1 = 0;
+ sha2_word32 W1[16] = {0};
+ int j = 0;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = state_in[0];
+ b = state_in[1];
+ c = state_in[2];
+ d = state_in[3];
+ e = state_in[4];
+
+ j = 0;
+
+ /* Rounds 0 to 15 unrolled: */
+ ROUND1_0_TO_15(a,b,c,d,e);
+ ROUND1_0_TO_15(e,a,b,c,d);
+ ROUND1_0_TO_15(d,e,a,b,c);
+ ROUND1_0_TO_15(c,d,e,a,b);
+ ROUND1_0_TO_15(b,c,d,e,a);
+ ROUND1_0_TO_15(a,b,c,d,e);
+ ROUND1_0_TO_15(e,a,b,c,d);
+ ROUND1_0_TO_15(d,e,a,b,c);
+ ROUND1_0_TO_15(c,d,e,a,b);
+ ROUND1_0_TO_15(b,c,d,e,a);
+ ROUND1_0_TO_15(a,b,c,d,e);
+ ROUND1_0_TO_15(e,a,b,c,d);
+ ROUND1_0_TO_15(d,e,a,b,c);
+ ROUND1_0_TO_15(c,d,e,a,b);
+ ROUND1_0_TO_15(b,c,d,e,a);
+ ROUND1_0_TO_15(a,b,c,d,e);
+
+ /* Rounds 16 to 19 unrolled: */
+ ROUND1_16_TO_19(e,a,b,c,d);
+ ROUND1_16_TO_19(d,e,a,b,c);
+ ROUND1_16_TO_19(c,d,e,a,b);
+ ROUND1_16_TO_19(b,c,d,e,a);
+
+ /* Rounds 20 to 39 unrolled: */
+ ROUND1_20_TO_39(a,b,c,d,e);
+ ROUND1_20_TO_39(e,a,b,c,d);
+ ROUND1_20_TO_39(d,e,a,b,c);
+ ROUND1_20_TO_39(c,d,e,a,b);
+ ROUND1_20_TO_39(b,c,d,e,a);
+ ROUND1_20_TO_39(a,b,c,d,e);
+ ROUND1_20_TO_39(e,a,b,c,d);
+ ROUND1_20_TO_39(d,e,a,b,c);
+ ROUND1_20_TO_39(c,d,e,a,b);
+ ROUND1_20_TO_39(b,c,d,e,a);
+ ROUND1_20_TO_39(a,b,c,d,e);
+ ROUND1_20_TO_39(e,a,b,c,d);
+ ROUND1_20_TO_39(d,e,a,b,c);
+ ROUND1_20_TO_39(c,d,e,a,b);
+ ROUND1_20_TO_39(b,c,d,e,a);
+ ROUND1_20_TO_39(a,b,c,d,e);
+ ROUND1_20_TO_39(e,a,b,c,d);
+ ROUND1_20_TO_39(d,e,a,b,c);
+ ROUND1_20_TO_39(c,d,e,a,b);
+ ROUND1_20_TO_39(b,c,d,e,a);
+
+ /* Rounds 40 to 59 unrolled: */
+ ROUND1_40_TO_59(a,b,c,d,e);
+ ROUND1_40_TO_59(e,a,b,c,d);
+ ROUND1_40_TO_59(d,e,a,b,c);
+ ROUND1_40_TO_59(c,d,e,a,b);
+ ROUND1_40_TO_59(b,c,d,e,a);
+ ROUND1_40_TO_59(a,b,c,d,e);
+ ROUND1_40_TO_59(e,a,b,c,d);
+ ROUND1_40_TO_59(d,e,a,b,c);
+ ROUND1_40_TO_59(c,d,e,a,b);
+ ROUND1_40_TO_59(b,c,d,e,a);
+ ROUND1_40_TO_59(a,b,c,d,e);
+ ROUND1_40_TO_59(e,a,b,c,d);
+ ROUND1_40_TO_59(d,e,a,b,c);
+ ROUND1_40_TO_59(c,d,e,a,b);
+ ROUND1_40_TO_59(b,c,d,e,a);
+ ROUND1_40_TO_59(a,b,c,d,e);
+ ROUND1_40_TO_59(e,a,b,c,d);
+ ROUND1_40_TO_59(d,e,a,b,c);
+ ROUND1_40_TO_59(c,d,e,a,b);
+ ROUND1_40_TO_59(b,c,d,e,a);
+
+ /* Rounds 60 to 79 unrolled: */
+ ROUND1_60_TO_79(a,b,c,d,e);
+ ROUND1_60_TO_79(e,a,b,c,d);
+ ROUND1_60_TO_79(d,e,a,b,c);
+ ROUND1_60_TO_79(c,d,e,a,b);
+ ROUND1_60_TO_79(b,c,d,e,a);
+ ROUND1_60_TO_79(a,b,c,d,e);
+ ROUND1_60_TO_79(e,a,b,c,d);
+ ROUND1_60_TO_79(d,e,a,b,c);
+ ROUND1_60_TO_79(c,d,e,a,b);
+ ROUND1_60_TO_79(b,c,d,e,a);
+ ROUND1_60_TO_79(a,b,c,d,e);
+ ROUND1_60_TO_79(e,a,b,c,d);
+ ROUND1_60_TO_79(d,e,a,b,c);
+ ROUND1_60_TO_79(c,d,e,a,b);
+ ROUND1_60_TO_79(b,c,d,e,a);
+ ROUND1_60_TO_79(a,b,c,d,e);
+ ROUND1_60_TO_79(e,a,b,c,d);
+ ROUND1_60_TO_79(d,e,a,b,c);
+ ROUND1_60_TO_79(c,d,e,a,b);
+ ROUND1_60_TO_79(b,c,d,e,a);
+
+ /* Compute the current intermediate hash value */
+ state_out[0] = state_in[0] + a;
+ state_out[1] = state_in[1] + b;
+ state_out[2] = state_in[2] + c;
+ state_out[3] = state_in[3] + d;
+ state_out[4] = state_in[4] + e;
+
+ /* Clean up */
+ a = b = c = d = e = T1 = 0;
+}
+
+#else /* SHA2_UNROLL_TRANSFORM */
+
+void sha1_Transform(const sha2_word32* state_in, const sha2_word32* data, sha2_word32* state_out) {
+ sha2_word32 a = 0, b = 0, c = 0, d = 0, e = 0;
+ sha2_word32 T1 = 0;
+ sha2_word32 W1[16] = {0};
+ int j = 0;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = state_in[0];
+ b = state_in[1];
+ c = state_in[2];
+ d = state_in[3];
+ e = state_in[4];
+ j = 0;
+ do {
+ T1 = ROTL32(5, a) + Ch(b, c, d) + e + K1_0_TO_19 + (W1[j] = *data++);
+ e = d;
+ d = c;
+ c = ROTL32(30, b);
+ b = a;
+ a = T1;
+ j++;
+ } while (j < 16);
+
+ do {
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
+ T1 = ROTL32(5, a) + Ch(b,c,d) + e + K1_0_TO_19 + (W1[j&0x0f] = ROTL32(1, T1));
+ e = d;
+ d = c;
+ c = ROTL32(30, b);
+ b = a;
+ a = T1;
+ j++;
+ } while (j < 20);
+
+ do {
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
+ T1 = ROTL32(5, a) + Parity(b,c,d) + e + K1_20_TO_39 + (W1[j&0x0f] = ROTL32(1, T1));
+ e = d;
+ d = c;
+ c = ROTL32(30, b);
+ b = a;
+ a = T1;
+ j++;
+ } while (j < 40);
+
+ do {
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
+ T1 = ROTL32(5, a) + Maj(b,c,d) + e + K1_40_TO_59 + (W1[j&0x0f] = ROTL32(1, T1));
+ e = d;
+ d = c;
+ c = ROTL32(30, b);
+ b = a;
+ a = T1;
+ j++;
+ } while (j < 60);
+
+ do {
+ T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
+ T1 = ROTL32(5, a) + Parity(b,c,d) + e + K1_60_TO_79 + (W1[j&0x0f] = ROTL32(1, T1));
+ e = d;
+ d = c;
+ c = ROTL32(30, b);
+ b = a;
+ a = T1;
+ j++;
+ } while (j < 80);
+
+
+ /* Compute the current intermediate hash value */
+ state_out[0] = state_in[0] + a;
+ state_out[1] = state_in[1] + b;
+ state_out[2] = state_in[2] + c;
+ state_out[3] = state_in[3] + d;
+ state_out[4] = state_in[4] + e;
+
+ /* Clean up */
+ a = b = c = d = e = T1 = 0;
+}
+
+#endif /* SHA2_UNROLL_TRANSFORM */
+
+void sha1_Update(SHA1_CTX* context, const sha2_byte *data, size_t len) {
+ unsigned int freespace = 0, usedspace = 0;
+
+ if (len == 0) {
+ /* Calling with no data is valid - we do nothing */
+ return;
+ }
+
+ usedspace = (context->bitcount >> 3) % SHA1_BLOCK_LENGTH;
+ if (usedspace > 0) {
+ /* Calculate how much free space is available in the buffer */
+ freespace = SHA1_BLOCK_LENGTH - usedspace;
+
+ if (len >= freespace) {
+ /* Fill the buffer completely and process it */
+ MEMCPY_BCOPY(((uint8_t*)context->buffer) + usedspace, data, freespace);
+ context->bitcount += freespace << 3;
+ len -= freespace;
+ data += freespace;
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert TO host byte order */
+ for (int j = 0; j < 16; j++) {
+ REVERSE32(context->buffer[j],context->buffer[j]);
+ }
+#endif
+ sha1_Transform(context->state, context->buffer, context->state);
+ } else {
+ /* The buffer is not yet full */
+ MEMCPY_BCOPY(((uint8_t*)context->buffer) + usedspace, data, len);
+ context->bitcount += len << 3;
+ /* Clean up: */
+ usedspace = freespace = 0;
+ return;
+ }
+ }
+ while (len >= SHA1_BLOCK_LENGTH) {
+ /* Process as many complete blocks as we can */
+ MEMCPY_BCOPY(context->buffer, data, SHA1_BLOCK_LENGTH);
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert TO host byte order */
+ for (int j = 0; j < 16; j++) {
+ REVERSE32(context->buffer[j],context->buffer[j]);
+ }
+#endif
+ sha1_Transform(context->state, context->buffer, context->state);
+ context->bitcount += SHA1_BLOCK_LENGTH << 3;
+ len -= SHA1_BLOCK_LENGTH;
+ data += SHA1_BLOCK_LENGTH;
+ }
+ if (len > 0) {
+ /* There's left-overs, so save 'em */
+ MEMCPY_BCOPY(context->buffer, data, len);
+ context->bitcount += len << 3;
+ }
+ /* Clean up: */
+ usedspace = freespace = 0;
+}
+
+void sha1_Final(SHA1_CTX* context, sha2_byte digest[]) {
+ unsigned int usedspace = 0;
+
+ /* If no digest buffer is passed, we don't bother doing this: */
+ if (digest != (sha2_byte*)0) {
+ usedspace = (context->bitcount >> 3) % SHA1_BLOCK_LENGTH;
+ /* Begin padding with a 1 bit: */
+ ((uint8_t*)context->buffer)[usedspace++] = 0x80;
+
+ if (usedspace > SHA1_SHORT_BLOCK_LENGTH) {
+ memzero(((uint8_t*)context->buffer) + usedspace, SHA1_BLOCK_LENGTH - usedspace);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert TO host byte order */
+ for (int j = 0; j < 16; j++) {
+ REVERSE32(context->buffer[j],context->buffer[j]);
+ }
+#endif
+ /* Do second-to-last transform: */
+ sha1_Transform(context->state, context->buffer, context->state);
+
+ /* And prepare the last transform: */
+ usedspace = 0;
+ }
+ /* Set-up for the last transform: */
+ memzero(((uint8_t*)context->buffer) + usedspace, SHA1_SHORT_BLOCK_LENGTH - usedspace);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert TO host byte order */
+ for (int j = 0; j < 14; j++) {
+ REVERSE32(context->buffer[j],context->buffer[j]);
+ }
+#endif
+ /* Set the bit count: */
+ context->buffer[14] = context->bitcount >> 32;
+ context->buffer[15] = context->bitcount & 0xffffffff;
+
+ /* Final transform: */
+ sha1_Transform(context->state, context->buffer, context->state);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert FROM host byte order */
+ for (int j = 0; j < 5; j++) {
+ REVERSE32(context->state[j],context->state[j]);
+ }
+#endif
+ MEMCPY_BCOPY(digest, context->state, SHA1_DIGEST_LENGTH);
+ }
+
+ /* Clean up state data: */
+ memzero(context, sizeof(SHA1_CTX));
+ usedspace = 0;
+}
+
+char *sha1_End(SHA1_CTX* context, char buffer[]) {
+ sha2_byte digest[SHA1_DIGEST_LENGTH] = {0}, *d = digest;
+ int i = 0;
+
+ if (buffer != (char*)0) {
+ sha1_Final(context, digest);
+
+ for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
+ *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
+ *buffer++ = sha2_hex_digits[*d & 0x0f];
+ d++;
+ }
+ *buffer = (char)0;
+ } else {
+ memzero(context, sizeof(SHA1_CTX));
+ }
+ memzero(digest, SHA1_DIGEST_LENGTH);
+ return buffer;
+}
+
+void sha1_Raw(const sha2_byte* data, size_t len, uint8_t digest[SHA1_DIGEST_LENGTH]) {
+ SHA1_CTX context = {0};
+ sha1_Init(&context);
+ sha1_Update(&context, data, len);
+ sha1_Final(&context, digest);
+}
+
+char* sha1_Data(const sha2_byte* data, size_t len, char digest[SHA1_DIGEST_STRING_LENGTH]) {
+ SHA1_CTX context = {0};
+
+ sha1_Init(&context);
+ sha1_Update(&context, data, len);
+ return sha1_End(&context, digest);
+}
+
+/*** SHA-256: *********************************************************/
+void sha256_Init(SHA256_CTX* context) {
+ if (context == (SHA256_CTX*)0) {
+ return;
+ }
+ MEMCPY_BCOPY(context->state, sha256_initial_hash_value, SHA256_DIGEST_LENGTH);
+ memzero(context->buffer, SHA256_BLOCK_LENGTH);
+ context->bitcount = 0;
+}
+
+#ifdef SHA2_UNROLL_TRANSFORM
+
+/* Unrolled SHA-256 round macros: */
+
+#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) \
+ T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + \
+ K256[j] + (W256[j] = *data++); \
+ (d) += T1; \
+ (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
+ j++
+
+#define ROUND256(a,b,c,d,e,f,g,h) \
+ s0 = W256[(j+1)&0x0f]; \
+ s0 = sigma0_256(s0); \
+ s1 = W256[(j+14)&0x0f]; \
+ s1 = sigma1_256(s1); \
+ T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + K256[j] + \
+ (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0); \
+ (d) += T1; \
+ (h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
+ j++
+
+void sha256_Transform(const sha2_word32* state_in, const sha2_word32* data, sha2_word32* state_out) {
+ sha2_word32 a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, s0 = 0, s1 = 0;
+ sha2_word32 T1 = 0;
+ sha2_word32 W256[16] = {0};
+ int j = 0;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = state_in[0];
+ b = state_in[1];
+ c = state_in[2];
+ d = state_in[3];
+ e = state_in[4];
+ f = state_in[5];
+ g = state_in[6];
+ h = state_in[7];
+
+ j = 0;
+ do {
+ /* Rounds 0 to 15 (unrolled): */
+ ROUND256_0_TO_15(a,b,c,d,e,f,g,h);
+ ROUND256_0_TO_15(h,a,b,c,d,e,f,g);
+ ROUND256_0_TO_15(g,h,a,b,c,d,e,f);
+ ROUND256_0_TO_15(f,g,h,a,b,c,d,e);
+ ROUND256_0_TO_15(e,f,g,h,a,b,c,d);
+ ROUND256_0_TO_15(d,e,f,g,h,a,b,c);
+ ROUND256_0_TO_15(c,d,e,f,g,h,a,b);
+ ROUND256_0_TO_15(b,c,d,e,f,g,h,a);
+ } while (j < 16);
+
+ /* Now for the remaining rounds to 64: */
+ do {
+ ROUND256(a,b,c,d,e,f,g,h);
+ ROUND256(h,a,b,c,d,e,f,g);
+ ROUND256(g,h,a,b,c,d,e,f);
+ ROUND256(f,g,h,a,b,c,d,e);
+ ROUND256(e,f,g,h,a,b,c,d);
+ ROUND256(d,e,f,g,h,a,b,c);
+ ROUND256(c,d,e,f,g,h,a,b);
+ ROUND256(b,c,d,e,f,g,h,a);
+ } while (j < 64);
+
+ /* Compute the current intermediate hash value */
+ state_out[0] = state_in[0] + a;
+ state_out[1] = state_in[1] + b;
+ state_out[2] = state_in[2] + c;
+ state_out[3] = state_in[3] + d;
+ state_out[4] = state_in[4] + e;
+ state_out[5] = state_in[5] + f;
+ state_out[6] = state_in[6] + g;
+ state_out[7] = state_in[7] + h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = 0;
+}
+
+#else /* SHA2_UNROLL_TRANSFORM */
+
+void sha256_Transform(const sha2_word32* state_in, const sha2_word32* data, sha2_word32* state_out) {
+ sha2_word32 a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, s0 = 0, s1 = 0;
+ sha2_word32 T1 = 0, T2 = 0 , W256[16] = {0};
+ int j = 0;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = state_in[0];
+ b = state_in[1];
+ c = state_in[2];
+ d = state_in[3];
+ e = state_in[4];
+ f = state_in[5];
+ g = state_in[6];
+ h = state_in[7];
+
+ j = 0;
+ do {
+ /* Apply the SHA-256 compression function to update a..h with copy */
+ T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + (W256[j] = *data++);
+ T2 = Sigma0_256(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 16);
+
+ do {
+ /* Part of the message block expansion: */
+ s0 = W256[(j+1)&0x0f];
+ s0 = sigma0_256(s0);
+ s1 = W256[(j+14)&0x0f];
+ s1 = sigma1_256(s1);
+
+ /* Apply the SHA-256 compression function to update a..h */
+ T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] +
+ (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0);
+ T2 = Sigma0_256(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 64);
+
+ /* Compute the current intermediate hash value */
+ state_out[0] = state_in[0] + a;
+ state_out[1] = state_in[1] + b;
+ state_out[2] = state_in[2] + c;
+ state_out[3] = state_in[3] + d;
+ state_out[4] = state_in[4] + e;
+ state_out[5] = state_in[5] + f;
+ state_out[6] = state_in[6] + g;
+ state_out[7] = state_in[7] + h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = T2 = 0;
+}
+
+#endif /* SHA2_UNROLL_TRANSFORM */
+
+void sha256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
+ unsigned int freespace = 0, usedspace = 0;
+
+ if (len == 0) {
+ /* Calling with no data is valid - we do nothing */
+ return;
+ }
+
+ usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
+ if (usedspace > 0) {
+ /* Calculate how much free space is available in the buffer */
+ freespace = SHA256_BLOCK_LENGTH - usedspace;
+
+ if (len >= freespace) {
+ /* Fill the buffer completely and process it */
+ MEMCPY_BCOPY(((uint8_t*)context->buffer) + usedspace, data, freespace);
+ context->bitcount += freespace << 3;
+ len -= freespace;
+ data += freespace;
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert TO host byte order */
+ for (int j = 0; j < 16; j++) {
+ REVERSE32(context->buffer[j],context->buffer[j]);
+ }
+#endif
+ sha256_Transform(context->state, context->buffer, context->state);
+ } else {
+ /* The buffer is not yet full */
+ MEMCPY_BCOPY(((uint8_t*)context->buffer) + usedspace, data, len);
+ context->bitcount += len << 3;
+ /* Clean up: */
+ usedspace = freespace = 0;
+ return;
+ }
+ }
+ while (len >= SHA256_BLOCK_LENGTH) {
+ /* Process as many complete blocks as we can */
+ MEMCPY_BCOPY(context->buffer, data, SHA256_BLOCK_LENGTH);
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert TO host byte order */
+ for (int j = 0; j < 16; j++) {
+ REVERSE32(context->buffer[j],context->buffer[j]);
+ }
+#endif
+ sha256_Transform(context->state, context->buffer, context->state);
+ context->bitcount += SHA256_BLOCK_LENGTH << 3;
+ len -= SHA256_BLOCK_LENGTH;
+ data += SHA256_BLOCK_LENGTH;
+ }
+ if (len > 0) {
+ /* There's left-overs, so save 'em */
+ MEMCPY_BCOPY(context->buffer, data, len);
+ context->bitcount += len << 3;
+ }
+ /* Clean up: */
+ usedspace = freespace = 0;
+}
+
+void sha256_Final(SHA256_CTX* context, sha2_byte digest[]) {
+ unsigned int usedspace = 0;
+
+ /* If no digest buffer is passed, we don't bother doing this: */
+ if (digest != (sha2_byte*)0) {
+ usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
+ /* Begin padding with a 1 bit: */
+ ((uint8_t*)context->buffer)[usedspace++] = 0x80;
+
+ if (usedspace > SHA256_SHORT_BLOCK_LENGTH) {
+ memzero(((uint8_t*)context->buffer) + usedspace, SHA256_BLOCK_LENGTH - usedspace);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert TO host byte order */
+ for (int j = 0; j < 16; j++) {
+ REVERSE32(context->buffer[j],context->buffer[j]);
+ }
+#endif
+ /* Do second-to-last transform: */
+ sha256_Transform(context->state, context->buffer, context->state);
+
+ /* And prepare the last transform: */
+ usedspace = 0;
+ }
+ /* Set-up for the last transform: */
+ memzero(((uint8_t*)context->buffer) + usedspace, SHA256_SHORT_BLOCK_LENGTH - usedspace);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert TO host byte order */
+ for (int j = 0; j < 14; j++) {
+ REVERSE32(context->buffer[j],context->buffer[j]);
+ }
+#endif
+ /* Set the bit count: */
+ context->buffer[14] = context->bitcount >> 32;
+ context->buffer[15] = context->bitcount & 0xffffffff;
+
+ /* Final transform: */
+ sha256_Transform(context->state, context->buffer, context->state);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert FROM host byte order */
+ for (int j = 0; j < 8; j++) {
+ REVERSE32(context->state[j],context->state[j]);
+ }
+#endif
+ MEMCPY_BCOPY(digest, context->state, SHA256_DIGEST_LENGTH);
+ }
+
+ /* Clean up state data: */
+ memzero(context, sizeof(SHA256_CTX));
+ usedspace = 0;
+}
+
+char *sha256_End(SHA256_CTX* context, char buffer[]) {
+ sha2_byte digest[SHA256_DIGEST_LENGTH] = {0}, *d = digest;
+ int i = 0;
+
+ if (buffer != (char*)0) {
+ sha256_Final(context, digest);
+
+ for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
+ *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
+ *buffer++ = sha2_hex_digits[*d & 0x0f];
+ d++;
+ }
+ *buffer = (char)0;
+ } else {
+ memzero(context, sizeof(SHA256_CTX));
+ }
+ memzero(digest, SHA256_DIGEST_LENGTH);
+ return buffer;
+}
+
+void sha256_Raw(const sha2_byte* data, size_t len, uint8_t digest[SHA256_DIGEST_LENGTH]) {
+ SHA256_CTX context = {0};
+ sha256_Init(&context);
+ sha256_Update(&context, data, len);
+ sha256_Final(&context, digest);
+}
+
+char* sha256_Data(const sha2_byte* data, size_t len, char digest[SHA256_DIGEST_STRING_LENGTH]) {
+ SHA256_CTX context = {0};
+
+ sha256_Init(&context);
+ sha256_Update(&context, data, len);
+ return sha256_End(&context, digest);
+}
+
+
+/*** SHA-512: *********************************************************/
+void sha512_Init(SHA512_CTX* context) {
+ if (context == (SHA512_CTX*)0) {
+ return;
+ }
+ MEMCPY_BCOPY(context->state, sha512_initial_hash_value, SHA512_DIGEST_LENGTH);
+ memzero(context->buffer, SHA512_BLOCK_LENGTH);
+ context->bitcount[0] = context->bitcount[1] = 0;
+}
+
+#ifdef SHA2_UNROLL_TRANSFORM
+
+/* Unrolled SHA-512 round macros: */
+#define ROUND512_0_TO_15(a,b,c,d,e,f,g,h) \
+ T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + \
+ K512[j] + (W512[j] = *data++); \
+ (d) += T1; \
+ (h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \
+ j++
+
+#define ROUND512(a,b,c,d,e,f,g,h) \
+ s0 = W512[(j+1)&0x0f]; \
+ s0 = sigma0_512(s0); \
+ s1 = W512[(j+14)&0x0f]; \
+ s1 = sigma1_512(s1); \
+ T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + K512[j] + \
+ (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0); \
+ (d) += T1; \
+ (h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \
+ j++
+
+void sha512_Transform(const sha2_word64* state_in, const sha2_word64* data, sha2_word64* state_out) {
+ sha2_word64 a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, s0 = 0, s1 = 0;
+ sha2_word64 T1 = 0, W512[16] = {0};
+ int j = 0;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = state_in[0];
+ b = state_in[1];
+ c = state_in[2];
+ d = state_in[3];
+ e = state_in[4];
+ f = state_in[5];
+ g = state_in[6];
+ h = state_in[7];
+
+ j = 0;
+ do {
+ ROUND512_0_TO_15(a,b,c,d,e,f,g,h);
+ ROUND512_0_TO_15(h,a,b,c,d,e,f,g);
+ ROUND512_0_TO_15(g,h,a,b,c,d,e,f);
+ ROUND512_0_TO_15(f,g,h,a,b,c,d,e);
+ ROUND512_0_TO_15(e,f,g,h,a,b,c,d);
+ ROUND512_0_TO_15(d,e,f,g,h,a,b,c);
+ ROUND512_0_TO_15(c,d,e,f,g,h,a,b);
+ ROUND512_0_TO_15(b,c,d,e,f,g,h,a);
+ } while (j < 16);
+
+ /* Now for the remaining rounds up to 79: */
+ do {
+ ROUND512(a,b,c,d,e,f,g,h);
+ ROUND512(h,a,b,c,d,e,f,g);
+ ROUND512(g,h,a,b,c,d,e,f);
+ ROUND512(f,g,h,a,b,c,d,e);
+ ROUND512(e,f,g,h,a,b,c,d);
+ ROUND512(d,e,f,g,h,a,b,c);
+ ROUND512(c,d,e,f,g,h,a,b);
+ ROUND512(b,c,d,e,f,g,h,a);
+ } while (j < 80);
+
+ /* Compute the current intermediate hash value */
+ state_out[0] = state_in[0] + a;
+ state_out[1] = state_in[1] + b;
+ state_out[2] = state_in[2] + c;
+ state_out[3] = state_in[3] + d;
+ state_out[4] = state_in[4] + e;
+ state_out[5] = state_in[5] + f;
+ state_out[6] = state_in[6] + g;
+ state_out[7] = state_in[7] + h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = 0;
+}
+
+#else /* SHA2_UNROLL_TRANSFORM */
+
+void sha512_Transform(const sha2_word64* state_in, const sha2_word64* data, sha2_word64* state_out) {
+ sha2_word64 a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, s0 = 0, s1 = 0;
+ sha2_word64 T1 = 0, T2 = 0, W512[16] = {0};
+ int j = 0;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = state_in[0];
+ b = state_in[1];
+ c = state_in[2];
+ d = state_in[3];
+ e = state_in[4];
+ f = state_in[5];
+ g = state_in[6];
+ h = state_in[7];
+
+ j = 0;
+ do {
+ /* Apply the SHA-512 compression function to update a..h with copy */
+ T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + (W512[j] = *data++);
+ T2 = Sigma0_512(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 16);
+
+ do {
+ /* Part of the message block expansion: */
+ s0 = W512[(j+1)&0x0f];
+ s0 = sigma0_512(s0);
+ s1 = W512[(j+14)&0x0f];
+ s1 = sigma1_512(s1);
+
+ /* Apply the SHA-512 compression function to update a..h */
+ T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] +
+ (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0);
+ T2 = Sigma0_512(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 80);
+
+ /* Compute the current intermediate hash value */
+ state_out[0] = state_in[0] + a;
+ state_out[1] = state_in[1] + b;
+ state_out[2] = state_in[2] + c;
+ state_out[3] = state_in[3] + d;
+ state_out[4] = state_in[4] + e;
+ state_out[5] = state_in[5] + f;
+ state_out[6] = state_in[6] + g;
+ state_out[7] = state_in[7] + h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = T2 = 0;
+}
+
+#endif /* SHA2_UNROLL_TRANSFORM */
+
+void sha512_Update(SHA512_CTX* context, const sha2_byte *data, size_t len) {
+ unsigned int freespace = 0, usedspace = 0;
+
+ if (len == 0) {
+ /* Calling with no data is valid - we do nothing */
+ return;
+ }
+
+ usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
+ if (usedspace > 0) {
+ /* Calculate how much free space is available in the buffer */
+ freespace = SHA512_BLOCK_LENGTH - usedspace;
+
+ if (len >= freespace) {
+ /* Fill the buffer completely and process it */
+ MEMCPY_BCOPY(((uint8_t*)context->buffer) + usedspace, data, freespace);
+ ADDINC128(context->bitcount, freespace << 3);
+ len -= freespace;
+ data += freespace;
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert TO host byte order */
+ for (int j = 0; j < 16; j++) {
+ REVERSE64(context->buffer[j],context->buffer[j]);
+ }
+#endif
+ sha512_Transform(context->state, context->buffer, context->state);
+ } else {
+ /* The buffer is not yet full */
+ MEMCPY_BCOPY(((uint8_t*)context->buffer) + usedspace, data, len);
+ ADDINC128(context->bitcount, len << 3);
+ /* Clean up: */
+ usedspace = freespace = 0;
+ return;
+ }
+ }
+ while (len >= SHA512_BLOCK_LENGTH) {
+ /* Process as many complete blocks as we can */
+ MEMCPY_BCOPY(context->buffer, data, SHA512_BLOCK_LENGTH);
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert TO host byte order */
+ for (int j = 0; j < 16; j++) {
+ REVERSE64(context->buffer[j],context->buffer[j]);
+ }
+#endif
+ sha512_Transform(context->state, context->buffer, context->state);
+ ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3);
+ len -= SHA512_BLOCK_LENGTH;
+ data += SHA512_BLOCK_LENGTH;
+ }
+ if (len > 0) {
+ /* There's left-overs, so save 'em */
+ MEMCPY_BCOPY(context->buffer, data, len);
+ ADDINC128(context->bitcount, len << 3);
+ }
+ /* Clean up: */
+ usedspace = freespace = 0;
+}
+
+static void sha512_Last(SHA512_CTX* context) {
+ unsigned int usedspace = 0;
+
+ usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
+ /* Begin padding with a 1 bit: */
+ ((uint8_t*)context->buffer)[usedspace++] = 0x80;
+
+ if (usedspace > SHA512_SHORT_BLOCK_LENGTH) {
+ memzero(((uint8_t*)context->buffer) + usedspace, SHA512_BLOCK_LENGTH - usedspace);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert TO host byte order */
+ for (int j = 0; j < 16; j++) {
+ REVERSE64(context->buffer[j],context->buffer[j]);
+ }
+#endif
+ /* Do second-to-last transform: */
+ sha512_Transform(context->state, context->buffer, context->state);
+
+ /* And prepare the last transform: */
+ usedspace = 0;
+ }
+ /* Set-up for the last transform: */
+ memzero(((uint8_t*)context->buffer) + usedspace, SHA512_SHORT_BLOCK_LENGTH - usedspace);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert TO host byte order */
+ for (int j = 0; j < 14; j++) {
+ REVERSE64(context->buffer[j],context->buffer[j]);
+ }
+#endif
+ /* Store the length of input data (in bits): */
+ context->buffer[14] = context->bitcount[1];
+ context->buffer[15] = context->bitcount[0];
+
+ /* Final transform: */
+ sha512_Transform(context->state, context->buffer, context->state);
+}
+
+void sha512_Final(SHA512_CTX* context, sha2_byte digest[]) {
+ /* If no digest buffer is passed, we don't bother doing this: */
+ if (digest != (sha2_byte*)0) {
+ sha512_Last(context);
+
+ /* Save the hash data for output: */
+#if BYTE_ORDER == LITTLE_ENDIAN
+ /* Convert FROM host byte order */
+ for (int j = 0; j < 8; j++) {
+ REVERSE64(context->state[j],context->state[j]);
+ }
+#endif
+ MEMCPY_BCOPY(digest, context->state, SHA512_DIGEST_LENGTH);
+ }
+
+ /* Zero out state data */
+ memzero(context, sizeof(SHA512_CTX));
+}
+
+char *sha512_End(SHA512_CTX* context, char buffer[]) {
+ sha2_byte digest[SHA512_DIGEST_LENGTH] = {0}, *d = digest;
+ int i = 0;
+
+ if (buffer != (char*)0) {
+ sha512_Final(context, digest);
+
+ for (i = 0; i < SHA512_DIGEST_LENGTH; i++) {
+ *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
+ *buffer++ = sha2_hex_digits[*d & 0x0f];
+ d++;
+ }
+ *buffer = (char)0;
+ } else {
+ memzero(context, sizeof(SHA512_CTX));
+ }
+ memzero(digest, SHA512_DIGEST_LENGTH);
+ return buffer;
+}
+
+void sha512_Raw(const sha2_byte* data, size_t len, uint8_t digest[SHA512_DIGEST_LENGTH]) {
+ SHA512_CTX context = {0};
+ sha512_Init(&context);
+ sha512_Update(&context, data, len);
+ sha512_Final(&context, digest);
+}
+
+char* sha512_Data(const sha2_byte* data, size_t len, char digest[SHA512_DIGEST_STRING_LENGTH]) {
+ SHA512_CTX context = {0};
+
+ sha512_Init(&context);
+ sha512_Update(&context, data, len);
+ return sha512_End(&context, digest);
+}
diff --git a/src/crypto/bip39/sha2.h b/src/crypto/bip39/sha2.h
new file mode 100644
index 000000000..7f519c50b
--- /dev/null
+++ b/src/crypto/bip39/sha2.h
@@ -0,0 +1,116 @@
+/**
+ * Copyright (c) 2000-2001 Aaron D. Gifford
+ * Copyright (c) 2013-2014 Pavol Rusnak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __SHA2_H__
+#define __SHA2_H__
+
+#include
+#include
+
+#define SHA1_BLOCK_LENGTH 64
+#define SHA1_DIGEST_LENGTH 20
+#define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
+#define SHA256_BLOCK_LENGTH 64
+#define SHA256_DIGEST_LENGTH 32
+#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
+#define SHA512_BLOCK_LENGTH 128
+#define SHA512_DIGEST_LENGTH 64
+#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
+
+typedef struct _SHA1_CTX {
+ uint32_t state[5];
+ uint64_t bitcount;
+ uint32_t buffer[SHA1_BLOCK_LENGTH/sizeof(uint32_t)];
+} SHA1_CTX;
+typedef struct _SHA256_CTX {
+ uint32_t state[8];
+ uint64_t bitcount;
+ uint32_t buffer[SHA256_BLOCK_LENGTH/sizeof(uint32_t)];
+} SHA256_CTX;
+typedef struct _SHA512_CTX {
+ uint64_t state[8];
+ uint64_t bitcount[2];
+ uint64_t buffer[SHA512_BLOCK_LENGTH/sizeof(uint64_t)];
+} SHA512_CTX;
+
+/*** ENDIAN REVERSAL MACROS *******************************************/
+#ifndef LITTLE_ENDIAN
+#define LITTLE_ENDIAN 1234
+#define BIG_ENDIAN 4321
+#endif
+
+#ifndef BYTE_ORDER
+#define BYTE_ORDER LITTLE_ENDIAN
+#endif
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define REVERSE32(w,x) { \
+ uint32_t tmp = (w); \
+ tmp = (tmp >> 16) | (tmp << 16); \
+ (x) = ((tmp & 0xff00ff00UL) >> 8) | ((tmp & 0x00ff00ffUL) << 8); \
+}
+#define REVERSE64(w,x) { \
+ uint64_t tmp = (w); \
+ tmp = (tmp >> 32) | (tmp << 32); \
+ tmp = ((tmp & 0xff00ff00ff00ff00ULL) >> 8) | \
+ ((tmp & 0x00ff00ff00ff00ffULL) << 8); \
+ (x) = ((tmp & 0xffff0000ffff0000ULL) >> 16) | \
+ ((tmp & 0x0000ffff0000ffffULL) << 16); \
+}
+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+
+extern const uint32_t sha256_initial_hash_value[8];
+extern const uint64_t sha512_initial_hash_value[8];
+
+void sha1_Transform(const uint32_t* state_in, const uint32_t* data, uint32_t* state_out);
+void sha1_Init(SHA1_CTX *);
+void sha1_Update(SHA1_CTX*, const uint8_t*, size_t);
+void sha1_Final(SHA1_CTX*, uint8_t[SHA1_DIGEST_LENGTH]);
+char* sha1_End(SHA1_CTX*, char[SHA1_DIGEST_STRING_LENGTH]);
+void sha1_Raw(const uint8_t*, size_t, uint8_t[SHA1_DIGEST_LENGTH]);
+char* sha1_Data(const uint8_t*, size_t, char[SHA1_DIGEST_STRING_LENGTH]);
+
+void sha256_Transform(const uint32_t* state_in, const uint32_t* data, uint32_t* state_out);
+void sha256_Init(SHA256_CTX *);
+void sha256_Update(SHA256_CTX*, const uint8_t*, size_t);
+void sha256_Final(SHA256_CTX*, uint8_t[SHA256_DIGEST_LENGTH]);
+char* sha256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
+void sha256_Raw(const uint8_t*, size_t, uint8_t[SHA256_DIGEST_LENGTH]);
+char* sha256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
+
+void sha512_Transform(const uint64_t* state_in, const uint64_t* data, uint64_t* state_out);
+void sha512_Init(SHA512_CTX*);
+void sha512_Update(SHA512_CTX*, const uint8_t*, size_t);
+void sha512_Final(SHA512_CTX*, uint8_t[SHA512_DIGEST_LENGTH]);
+char* sha512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
+void sha512_Raw(const uint8_t*, size_t, uint8_t[SHA512_DIGEST_LENGTH]);
+char* sha512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
+
+#endif
diff --git a/src/crypto/bip39/sha3.c b/src/crypto/bip39/sha3.c
new file mode 100644
index 000000000..80ac28ff6
--- /dev/null
+++ b/src/crypto/bip39/sha3.c
@@ -0,0 +1,397 @@
+/* sha3.c - an implementation of Secure Hash Algorithm 3 (Keccak).
+ * based on the
+ * The Keccak SHA-3 submission. Submission to NIST (Round 3), 2011
+ * by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche
+ *
+ * Copyright: 2013 Aleksey Kravchenko
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk!
+ */
+
+#include
+#include
+
+#include "sha3.h"
+#include "memzero.h"
+
+#define I64(x) x##LL
+#define ROTL64(qword, n) ((qword) << (n) ^ ((qword) >> (64 - (n))))
+#define le2me_64(x) (x)
+#define IS_ALIGNED_64(p) (0 == (7 & ((const char*)(p) - (const char*)0)))
+# define me64_to_le_str(to, from, length) memcpy((to), (from), (length))
+
+/* constants */
+#define NumberOfRounds 24
+
+/* SHA3 (Keccak) constants for 24 rounds */
+static uint64_t keccak_round_constants[NumberOfRounds] = {
+ I64(0x0000000000000001), I64(0x0000000000008082), I64(0x800000000000808A), I64(0x8000000080008000),
+ I64(0x000000000000808B), I64(0x0000000080000001), I64(0x8000000080008081), I64(0x8000000000008009),
+ I64(0x000000000000008A), I64(0x0000000000000088), I64(0x0000000080008009), I64(0x000000008000000A),
+ I64(0x000000008000808B), I64(0x800000000000008B), I64(0x8000000000008089), I64(0x8000000000008003),
+ I64(0x8000000000008002), I64(0x8000000000000080), I64(0x000000000000800A), I64(0x800000008000000A),
+ I64(0x8000000080008081), I64(0x8000000000008080), I64(0x0000000080000001), I64(0x8000000080008008)
+};
+
+/* Initializing a sha3 context for given number of output bits */
+static void keccak_Init(SHA3_CTX *ctx, unsigned bits)
+{
+ /* NB: The Keccak capacity parameter = bits * 2 */
+ unsigned rate = 1600 - bits * 2;
+
+ memzero(ctx, sizeof(SHA3_CTX));
+ ctx->block_size = rate / 8;
+ assert(rate <= 1600 && (rate % 64) == 0);
+}
+
+/**
+ * Initialize context before calculating hash.
+ *
+ * @param ctx context to initialize
+ */
+void sha3_224_Init(SHA3_CTX *ctx)
+{
+ keccak_Init(ctx, 224);
+}
+
+/**
+ * Initialize context before calculating hash.
+ *
+ * @param ctx context to initialize
+ */
+void sha3_256_Init(SHA3_CTX *ctx)
+{
+ keccak_Init(ctx, 256);
+}
+
+/**
+ * Initialize context before calculating hash.
+ *
+ * @param ctx context to initialize
+ */
+void sha3_384_Init(SHA3_CTX *ctx)
+{
+ keccak_Init(ctx, 384);
+}
+
+/**
+ * Initialize context before calculating hash.
+ *
+ * @param ctx context to initialize
+ */
+void sha3_512_Init(SHA3_CTX *ctx)
+{
+ keccak_Init(ctx, 512);
+}
+
+/* Keccak theta() transformation */
+static void keccak_theta(uint64_t *A)
+{
+ unsigned int x = 0;
+ uint64_t C[5] = {0}, D[5] = {0};
+
+ for (x = 0; x < 5; x++) {
+ C[x] = A[x] ^ A[x + 5] ^ A[x + 10] ^ A[x + 15] ^ A[x + 20];
+ }
+ D[0] = ROTL64(C[1], 1) ^ C[4];
+ D[1] = ROTL64(C[2], 1) ^ C[0];
+ D[2] = ROTL64(C[3], 1) ^ C[1];
+ D[3] = ROTL64(C[4], 1) ^ C[2];
+ D[4] = ROTL64(C[0], 1) ^ C[3];
+
+ for (x = 0; x < 5; x++) {
+ A[x] ^= D[x];
+ A[x + 5] ^= D[x];
+ A[x + 10] ^= D[x];
+ A[x + 15] ^= D[x];
+ A[x + 20] ^= D[x];
+ }
+}
+
+/* Keccak pi() transformation */
+static void keccak_pi(uint64_t *A)
+{
+ uint64_t A1 = 0;
+ A1 = A[1];
+ A[ 1] = A[ 6];
+ A[ 6] = A[ 9];
+ A[ 9] = A[22];
+ A[22] = A[14];
+ A[14] = A[20];
+ A[20] = A[ 2];
+ A[ 2] = A[12];
+ A[12] = A[13];
+ A[13] = A[19];
+ A[19] = A[23];
+ A[23] = A[15];
+ A[15] = A[ 4];
+ A[ 4] = A[24];
+ A[24] = A[21];
+ A[21] = A[ 8];
+ A[ 8] = A[16];
+ A[16] = A[ 5];
+ A[ 5] = A[ 3];
+ A[ 3] = A[18];
+ A[18] = A[17];
+ A[17] = A[11];
+ A[11] = A[ 7];
+ A[ 7] = A[10];
+ A[10] = A1;
+ /* note: A[ 0] is left as is */
+}
+
+/* Keccak chi() transformation */
+static void keccak_chi(uint64_t *A)
+{
+ int i = 0;
+ for (i = 0; i < 25; i += 5) {
+ uint64_t A0 = A[0 + i], A1 = A[1 + i];
+ A[0 + i] ^= ~A1 & A[2 + i];
+ A[1 + i] ^= ~A[2 + i] & A[3 + i];
+ A[2 + i] ^= ~A[3 + i] & A[4 + i];
+ A[3 + i] ^= ~A[4 + i] & A0;
+ A[4 + i] ^= ~A0 & A1;
+ }
+}
+
+static void sha3_permutation(uint64_t *state)
+{
+ int round = 0;
+ for (round = 0; round < NumberOfRounds; round++)
+ {
+ keccak_theta(state);
+
+ /* apply Keccak rho() transformation */
+ state[ 1] = ROTL64(state[ 1], 1);
+ state[ 2] = ROTL64(state[ 2], 62);
+ state[ 3] = ROTL64(state[ 3], 28);
+ state[ 4] = ROTL64(state[ 4], 27);
+ state[ 5] = ROTL64(state[ 5], 36);
+ state[ 6] = ROTL64(state[ 6], 44);
+ state[ 7] = ROTL64(state[ 7], 6);
+ state[ 8] = ROTL64(state[ 8], 55);
+ state[ 9] = ROTL64(state[ 9], 20);
+ state[10] = ROTL64(state[10], 3);
+ state[11] = ROTL64(state[11], 10);
+ state[12] = ROTL64(state[12], 43);
+ state[13] = ROTL64(state[13], 25);
+ state[14] = ROTL64(state[14], 39);
+ state[15] = ROTL64(state[15], 41);
+ state[16] = ROTL64(state[16], 45);
+ state[17] = ROTL64(state[17], 15);
+ state[18] = ROTL64(state[18], 21);
+ state[19] = ROTL64(state[19], 8);
+ state[20] = ROTL64(state[20], 18);
+ state[21] = ROTL64(state[21], 2);
+ state[22] = ROTL64(state[22], 61);
+ state[23] = ROTL64(state[23], 56);
+ state[24] = ROTL64(state[24], 14);
+
+ keccak_pi(state);
+ keccak_chi(state);
+
+ /* apply iota(state, round) */
+ *state ^= keccak_round_constants[round];
+ }
+}
+
+/**
+ * The core transformation. Process the specified block of data.
+ *
+ * @param hash the algorithm state
+ * @param block the message block to process
+ * @param block_size the size of the processed block in bytes
+ */
+static void sha3_process_block(uint64_t hash[25], const uint64_t *block, size_t block_size)
+{
+ /* expanded loop */
+ hash[ 0] ^= le2me_64(block[ 0]);
+ hash[ 1] ^= le2me_64(block[ 1]);
+ hash[ 2] ^= le2me_64(block[ 2]);
+ hash[ 3] ^= le2me_64(block[ 3]);
+ hash[ 4] ^= le2me_64(block[ 4]);
+ hash[ 5] ^= le2me_64(block[ 5]);
+ hash[ 6] ^= le2me_64(block[ 6]);
+ hash[ 7] ^= le2me_64(block[ 7]);
+ hash[ 8] ^= le2me_64(block[ 8]);
+ /* if not sha3-512 */
+ if (block_size > 72) {
+ hash[ 9] ^= le2me_64(block[ 9]);
+ hash[10] ^= le2me_64(block[10]);
+ hash[11] ^= le2me_64(block[11]);
+ hash[12] ^= le2me_64(block[12]);
+ /* if not sha3-384 */
+ if (block_size > 104) {
+ hash[13] ^= le2me_64(block[13]);
+ hash[14] ^= le2me_64(block[14]);
+ hash[15] ^= le2me_64(block[15]);
+ hash[16] ^= le2me_64(block[16]);
+ /* if not sha3-256 */
+ if (block_size > 136) {
+ hash[17] ^= le2me_64(block[17]);
+#ifdef FULL_SHA3_FAMILY_SUPPORT
+ /* if not sha3-224 */
+ if (block_size > 144) {
+ hash[18] ^= le2me_64(block[18]);
+ hash[19] ^= le2me_64(block[19]);
+ hash[20] ^= le2me_64(block[20]);
+ hash[21] ^= le2me_64(block[21]);
+ hash[22] ^= le2me_64(block[22]);
+ hash[23] ^= le2me_64(block[23]);
+ hash[24] ^= le2me_64(block[24]);
+ }
+#endif
+ }
+ }
+ }
+ /* make a permutation of the hash */
+ sha3_permutation(hash);
+}
+
+#define SHA3_FINALIZED 0x80000000
+
+/**
+ * Calculate message hash.
+ * Can be called repeatedly with chunks of the message to be hashed.
+ *
+ * @param ctx the algorithm context containing current hashing state
+ * @param msg message chunk
+ * @param size length of the message chunk
+ */
+void sha3_Update(SHA3_CTX *ctx, const unsigned char *msg, size_t size)
+{
+ size_t idx = (size_t)ctx->rest;
+ size_t block_size = (size_t)ctx->block_size;
+
+ if (ctx->rest & SHA3_FINALIZED) return; /* too late for additional input */
+ ctx->rest = (unsigned)((ctx->rest + size) % block_size);
+
+ /* fill partial block */
+ if (idx) {
+ size_t left = block_size - idx;
+ memcpy((char*)ctx->message + idx, msg, (size < left ? size : left));
+ if (size < left) return;
+
+ /* process partial block */
+ sha3_process_block(ctx->hash, ctx->message, block_size);
+ msg += left;
+ size -= left;
+ }
+ while (size >= block_size) {
+ uint64_t *aligned_message_block = NULL;
+ if (IS_ALIGNED_64(msg)) {
+ /* the most common case is processing of an already aligned message
+ without copying it */
+ aligned_message_block = (uint64_t*)(void*)msg;
+ } else {
+ memcpy(ctx->message, msg, block_size);
+ aligned_message_block = ctx->message;
+ }
+
+ sha3_process_block(ctx->hash, aligned_message_block, block_size);
+ msg += block_size;
+ size -= block_size;
+ }
+ if (size) {
+ memcpy(ctx->message, msg, size); /* save leftovers */
+ }
+}
+
+/**
+ * Store calculated hash into the given array.
+ *
+ * @param ctx the algorithm context containing current hashing state
+ * @param result calculated hash in binary form
+ */
+void sha3_Final(SHA3_CTX *ctx, unsigned char* result)
+{
+ size_t digest_length = 100 - ctx->block_size / 2;
+ const size_t block_size = ctx->block_size;
+
+ if (!(ctx->rest & SHA3_FINALIZED))
+ {
+ /* clear the rest of the data queue */
+ memzero((char*)ctx->message + ctx->rest, block_size - ctx->rest);
+ ((char*)ctx->message)[ctx->rest] |= 0x06;
+ ((char*)ctx->message)[block_size - 1] |= 0x80;
+
+ /* process final block */
+ sha3_process_block(ctx->hash, ctx->message, block_size);
+ ctx->rest = SHA3_FINALIZED; /* mark context as finalized */
+ }
+
+ assert(block_size > digest_length);
+ if (result) me64_to_le_str(result, ctx->hash, digest_length);
+ memzero(ctx, sizeof(SHA3_CTX));
+}
+
+#if USE_KECCAK
+/**
+* Store calculated hash into the given array.
+*
+* @param ctx the algorithm context containing current hashing state
+* @param result calculated hash in binary form
+*/
+void keccak_Final(SHA3_CTX *ctx, unsigned char* result)
+{
+ size_t digest_length = 100 - ctx->block_size / 2;
+ const size_t block_size = ctx->block_size;
+
+ if (!(ctx->rest & SHA3_FINALIZED))
+ {
+ /* clear the rest of the data queue */
+ memzero((char*)ctx->message + ctx->rest, block_size - ctx->rest);
+ ((char*)ctx->message)[ctx->rest] |= 0x01;
+ ((char*)ctx->message)[block_size - 1] |= 0x80;
+
+ /* process final block */
+ sha3_process_block(ctx->hash, ctx->message, block_size);
+ ctx->rest = SHA3_FINALIZED; /* mark context as finalized */
+ }
+
+ assert(block_size > digest_length);
+ if (result) me64_to_le_str(result, ctx->hash, digest_length);
+ memzero(ctx, sizeof(SHA3_CTX));
+}
+
+void keccak_256(const unsigned char* data, size_t len, unsigned char* digest)
+{
+ SHA3_CTX ctx = {0};
+ keccak_256_Init(&ctx);
+ keccak_Update(&ctx, data, len);
+ keccak_Final(&ctx, digest);
+}
+
+void keccak_512(const unsigned char* data, size_t len, unsigned char* digest)
+{
+ SHA3_CTX ctx = {0};
+ keccak_512_Init(&ctx);
+ keccak_Update(&ctx, data, len);
+ keccak_Final(&ctx, digest);
+}
+#endif /* USE_KECCAK */
+
+void sha3_256(const unsigned char* data, size_t len, unsigned char* digest)
+{
+ SHA3_CTX ctx = {0};
+ sha3_256_Init(&ctx);
+ sha3_Update(&ctx, data, len);
+ sha3_Final(&ctx, digest);
+}
+
+void sha3_512(const unsigned char* data, size_t len, unsigned char* digest)
+{
+ SHA3_CTX ctx = {0};
+ sha3_512_Init(&ctx);
+ sha3_Update(&ctx, data, len);
+ sha3_Final(&ctx, digest);
+}
diff --git a/src/crypto/bip39/sha3.h b/src/crypto/bip39/sha3.h
new file mode 100644
index 000000000..367369d4d
--- /dev/null
+++ b/src/crypto/bip39/sha3.h
@@ -0,0 +1,89 @@
+/* sha3.h - an implementation of Secure Hash Algorithm 3 (Keccak).
+ * based on the
+ * The Keccak SHA-3 submission. Submission to NIST (Round 3), 2011
+ * by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche
+ *
+ * Copyright: 2013 Aleksey Kravchenko
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk!
+ */
+
+#ifndef __SHA3_H__
+#define __SHA3_H__
+
+#include
+#include "options.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define sha3_224_hash_size 28
+#define sha3_256_hash_size 32
+#define sha3_384_hash_size 48
+#define sha3_512_hash_size 64
+#define sha3_max_permutation_size 25
+#define sha3_max_rate_in_qwords 24
+
+#define SHA3_224_BLOCK_LENGTH 144
+#define SHA3_256_BLOCK_LENGTH 136
+#define SHA3_384_BLOCK_LENGTH 104
+#define SHA3_512_BLOCK_LENGTH 72
+
+#define SHA3_224_DIGEST_LENGTH sha3_224_hash_size
+#define SHA3_256_DIGEST_LENGTH sha3_256_hash_size
+#define SHA3_384_DIGEST_LENGTH sha3_384_hash_size
+#define SHA3_512_DIGEST_LENGTH sha3_512_hash_size
+
+/**
+ * SHA3 Algorithm context.
+ */
+typedef struct SHA3_CTX
+{
+ /* 1600 bits algorithm hashing state */
+ uint64_t hash[sha3_max_permutation_size];
+ /* 1536-bit buffer for leftovers */
+ uint64_t message[sha3_max_rate_in_qwords];
+ /* count of bytes in the message[] buffer */
+ unsigned rest;
+ /* size of a message block processed at once */
+ unsigned block_size;
+} SHA3_CTX;
+
+/* methods for calculating the hash function */
+
+void sha3_224_Init(SHA3_CTX *ctx);
+void sha3_256_Init(SHA3_CTX *ctx);
+void sha3_384_Init(SHA3_CTX *ctx);
+void sha3_512_Init(SHA3_CTX *ctx);
+void sha3_Update(SHA3_CTX *ctx, const unsigned char* msg, size_t size);
+void sha3_Final(SHA3_CTX *ctx, unsigned char* result);
+
+#if USE_KECCAK
+#define keccak_224_Init sha3_224_Init
+#define keccak_256_Init sha3_256_Init
+#define keccak_384_Init sha3_384_Init
+#define keccak_512_Init sha3_512_Init
+#define keccak_Update sha3_Update
+void keccak_Final(SHA3_CTX *ctx, unsigned char* result);
+void keccak_256(const unsigned char* data, size_t len, unsigned char* digest);
+void keccak_512(const unsigned char* data, size_t len, unsigned char* digest);
+#endif
+
+void sha3_256(const unsigned char* data, size_t len, unsigned char* digest);
+void sha3_512(const unsigned char* data, size_t len, unsigned char* digest);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif /* __cplusplus */
+
+#endif /* __SHA3_H__ */
diff --git a/src/crypto/common.h b/src/crypto/common.h
index 12bdbec19..14a143a54 100644
--- a/src/crypto/common.h
+++ b/src/crypto/common.h
@@ -1,8 +1,8 @@
// Copyright (c) 2014 The Bitcoin Core developers
// Copyright (c) 2019-2020 The Hush developers
// Released under the GPLv3
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_CRYPTO_COMMON_H
#define BITCOIN_CRYPTO_COMMON_H
@@ -87,6 +87,27 @@ void static inline WriteBE64(unsigned char* ptr, uint64_t x)
memcpy(ptr, (char*)&v, 8);
}
+/** Return the smallest number n such that (x >> n) == 0 (or 64 if the highest bit in x is set. */
+uint64_t static inline CountBits(uint64_t x)
+{
+#if HAVE_DECL___BUILTIN_CLZL
+ if (sizeof(unsigned long) >= sizeof(uint64_t)) {
+ return x ? 8 * sizeof(unsigned long) - __builtin_clzl(x) : 0;
+ }
+#endif
+#if HAVE_DECL___BUILTIN_CLZLL
+ if (sizeof(unsigned long long) >= sizeof(uint64_t)) {
+ return x ? 8 * sizeof(unsigned long long) - __builtin_clzll(x) : 0;
+ }
+#endif
+ int ret = 0;
+ while (x) {
+ x >>= 1;
+ ++ret;
+ }
+ return ret;
+}
+
int inline init_and_check_sodium()
{
if (sodium_init() == -1) {
@@ -124,5 +145,4 @@ int inline init_and_check_sodium()
return 0;
}
-
#endif // BITCOIN_CRYPTO_COMMON_H
diff --git a/src/crypto/ctaes/COPYING b/src/crypto/ctaes/COPYING
new file mode 100644
index 000000000..415b202a2
--- /dev/null
+++ b/src/crypto/ctaes/COPYING
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 Pieter Wuille
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/src/crypto/ctaes/README.md b/src/crypto/ctaes/README.md
new file mode 100644
index 000000000..0e7fe1775
--- /dev/null
+++ b/src/crypto/ctaes/README.md
@@ -0,0 +1,41 @@
+ctaes
+=====
+
+Simple C module for constant-time AES encryption and decryption.
+
+Features:
+* Simple, pure C code without any dependencies.
+* No tables or data-dependent branches whatsoever, but using bit sliced approach from https://eprint.iacr.org/2009/129.pdf.
+* Very small object code: slightly over 4k of executable code when compiled with -Os.
+* Slower than implementations based on precomputed tables or specialized instructions, but can do ~15 MB/s on modern CPUs.
+
+Performance
+-----------
+
+Compiled with GCC 5.3.1 with -O3, on an Intel(R) Core(TM) i7-4800MQ CPU, numbers in CPU cycles:
+
+| Algorithm | Key schedule | Encryption per byte | Decryption per byte |
+| --------- | ------------:| -------------------:| -------------------:|
+| AES-128 | 2.8k | 154 | 161 |
+| AES-192 | 3.1k | 169 | 181 |
+| AES-256 | 4.0k | 191 | 203 |
+
+Build steps
+-----------
+
+Object code:
+
+ $ gcc -O3 ctaes.c -c -o ctaes.o
+
+Tests:
+
+ $ gcc -O3 ctaes.c test.c -o test
+
+Benchmark:
+
+ $ gcc -O3 ctaes.c bench.c -o bench
+
+Review
+------
+
+Results of a formal review of the code can be found in http://bitcoin.sipa.be/ctaes/review.zip
diff --git a/src/crypto/ctaes/bench.c b/src/crypto/ctaes/bench.c
new file mode 100644
index 000000000..a86df496c
--- /dev/null
+++ b/src/crypto/ctaes/bench.c
@@ -0,0 +1,170 @@
+#include
+#include
+#include "sys/time.h"
+
+#include "ctaes.h"
+
+static double gettimedouble(void) {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_usec * 0.000001 + tv.tv_sec;
+}
+
+static void print_number(double x) {
+ double y = x;
+ int c = 0;
+ if (y < 0.0) {
+ y = -y;
+ }
+ while (y < 100.0) {
+ y *= 10.0;
+ c++;
+ }
+ printf("%.*f", c, x);
+}
+
+static void run_benchmark(char *name, void (*benchmark)(void*), void (*setup)(void*), void (*teardown)(void*), void* data, int count, int iter) {
+ int i;
+ double min = HUGE_VAL;
+ double sum = 0.0;
+ double max = 0.0;
+ for (i = 0; i < count; i++) {
+ double begin, total;
+ if (setup != NULL) {
+ setup(data);
+ }
+ begin = gettimedouble();
+ benchmark(data);
+ total = gettimedouble() - begin;
+ if (teardown != NULL) {
+ teardown(data);
+ }
+ if (total < min) {
+ min = total;
+ }
+ if (total > max) {
+ max = total;
+ }
+ sum += total;
+ }
+ printf("%s: min ", name);
+ print_number(min * 1000000000.0 / iter);
+ printf("ns / avg ");
+ print_number((sum / count) * 1000000000.0 / iter);
+ printf("ns / max ");
+ print_number(max * 1000000000.0 / iter);
+ printf("ns\n");
+}
+
+static void bench_AES128_init(void* data) {
+ AES128_ctx* ctx = (AES128_ctx*)data;
+ int i;
+ for (i = 0; i < 50000; i++) {
+ AES128_init(ctx, (unsigned char*)ctx);
+ }
+}
+
+static void bench_AES128_encrypt_setup(void* data) {
+ AES128_ctx* ctx = (AES128_ctx*)data;
+ static const unsigned char key[16] = {0};
+ AES128_init(ctx, key);
+}
+
+static void bench_AES128_encrypt(void* data) {
+ const AES128_ctx* ctx = (const AES128_ctx*)data;
+ unsigned char scratch[16] = {0};
+ int i;
+ for (i = 0; i < 4000000 / 16; i++) {
+ AES128_encrypt(ctx, 1, scratch, scratch);
+ }
+}
+
+static void bench_AES128_decrypt(void* data) {
+ const AES128_ctx* ctx = (const AES128_ctx*)data;
+ unsigned char scratch[16] = {0};
+ int i;
+ for (i = 0; i < 4000000 / 16; i++) {
+ AES128_decrypt(ctx, 1, scratch, scratch);
+ }
+}
+
+static void bench_AES192_init(void* data) {
+ AES192_ctx* ctx = (AES192_ctx*)data;
+ int i;
+ for (i = 0; i < 50000; i++) {
+ AES192_init(ctx, (unsigned char*)ctx);
+ }
+}
+
+static void bench_AES192_encrypt_setup(void* data) {
+ AES192_ctx* ctx = (AES192_ctx*)data;
+ static const unsigned char key[16] = {0};
+ AES192_init(ctx, key);
+}
+
+static void bench_AES192_encrypt(void* data) {
+ const AES192_ctx* ctx = (const AES192_ctx*)data;
+ unsigned char scratch[16] = {0};
+ int i;
+ for (i = 0; i < 4000000 / 16; i++) {
+ AES192_encrypt(ctx, 1, scratch, scratch);
+ }
+}
+
+static void bench_AES192_decrypt(void* data) {
+ const AES192_ctx* ctx = (const AES192_ctx*)data;
+ unsigned char scratch[16] = {0};
+ int i;
+ for (i = 0; i < 4000000 / 16; i++) {
+ AES192_decrypt(ctx, 1, scratch, scratch);
+ }
+}
+
+static void bench_AES256_init(void* data) {
+ AES256_ctx* ctx = (AES256_ctx*)data;
+ int i;
+ for (i = 0; i < 50000; i++) {
+ AES256_init(ctx, (unsigned char*)ctx);
+ }
+}
+
+
+static void bench_AES256_encrypt_setup(void* data) {
+ AES256_ctx* ctx = (AES256_ctx*)data;
+ static const unsigned char key[16] = {0};
+ AES256_init(ctx, key);
+}
+
+static void bench_AES256_encrypt(void* data) {
+ const AES256_ctx* ctx = (const AES256_ctx*)data;
+ unsigned char scratch[16] = {0};
+ int i;
+ for (i = 0; i < 4000000 / 16; i++) {
+ AES256_encrypt(ctx, 1, scratch, scratch);
+ }
+}
+
+static void bench_AES256_decrypt(void* data) {
+ const AES256_ctx* ctx = (const AES256_ctx*)data;
+ unsigned char scratch[16] = {0};
+ int i;
+ for (i = 0; i < 4000000 / 16; i++) {
+ AES256_decrypt(ctx, 1, scratch, scratch);
+ }
+}
+
+int main(void) {
+ AES128_ctx ctx128;
+ AES192_ctx ctx192;
+ AES256_ctx ctx256;
+ run_benchmark("aes128_init", bench_AES128_init, NULL, NULL, &ctx128, 20, 50000);
+ run_benchmark("aes128_encrypt_byte", bench_AES128_encrypt, bench_AES128_encrypt_setup, NULL, &ctx128, 20, 4000000);
+ run_benchmark("aes128_decrypt_byte", bench_AES128_decrypt, bench_AES128_encrypt_setup, NULL, &ctx128, 20, 4000000);
+ run_benchmark("aes192_init", bench_AES192_init, NULL, NULL, &ctx192, 20, 50000);
+ run_benchmark("aes192_encrypt_byte", bench_AES192_encrypt, bench_AES192_encrypt_setup, NULL, &ctx192, 20, 4000000);
+ run_benchmark("aes192_decrypt_byte", bench_AES192_decrypt, bench_AES192_encrypt_setup, NULL, &ctx192, 20, 4000000);
+ run_benchmark("aes256_init", bench_AES256_init, NULL, NULL, &ctx256, 20, 50000);
+ run_benchmark("aes256_encrypt_byte", bench_AES256_encrypt, bench_AES256_encrypt_setup, NULL, &ctx256, 20, 4000000);
+ run_benchmark("aes256_decrypt_byte", bench_AES256_decrypt, bench_AES256_encrypt_setup, NULL, &ctx256, 20, 4000000);
+ return 0;
+}
diff --git a/src/crypto/ctaes/ctaes.c b/src/crypto/ctaes/ctaes.c
new file mode 100644
index 000000000..a21b9f3ee
--- /dev/null
+++ b/src/crypto/ctaes/ctaes.c
@@ -0,0 +1,556 @@
+ /*********************************************************************
+ * Copyright (c) 2016 Pieter Wuille *
+ * Distributed under the MIT software license, see the accompanying *
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
+ **********************************************************************/
+
+/* Constant time, unoptimized, concise, plain C, AES implementation
+ * Based On:
+ * Emilia Kasper and Peter Schwabe, Faster and Timing-Attack Resistant AES-GCM
+ * http://www.iacr.org/archive/ches2009/57470001/57470001.pdf
+ * But using 8 16-bit integers representing a single AES state rather than 8 128-bit
+ * integers representing 8 AES states.
+ */
+
+#include "ctaes.h"
+
+/* Slice variable slice_i contains the i'th bit of the 16 state variables in this order:
+ * 0 1 2 3
+ * 4 5 6 7
+ * 8 9 10 11
+ * 12 13 14 15
+ */
+
+/** Convert a byte to sliced form, storing it corresponding to given row and column in s */
+static void LoadByte(AES_state* s, unsigned char byte, int r, int c) {
+ int i;
+ for (i = 0; i < 8; i++) {
+ s->slice[i] |= (byte & 1) << (r * 4 + c);
+ byte >>= 1;
+ }
+}
+
+/** Load 16 bytes of data into 8 sliced integers */
+static void LoadBytes(AES_state *s, const unsigned char* data16) {
+ int c;
+ for (c = 0; c < 4; c++) {
+ int r;
+ for (r = 0; r < 4; r++) {
+ LoadByte(s, *(data16++), r, c);
+ }
+ }
+}
+
+/** Convert 8 sliced integers into 16 bytes of data */
+static void SaveBytes(unsigned char* data16, const AES_state *s) {
+ int c;
+ for (c = 0; c < 4; c++) {
+ int r;
+ for (r = 0; r < 4; r++) {
+ int b;
+ uint8_t v = 0;
+ for (b = 0; b < 8; b++) {
+ v |= ((s->slice[b] >> (r * 4 + c)) & 1) << b;
+ }
+ *(data16++) = v;
+ }
+ }
+}
+
+/* S-box implementation based on the gate logic from:
+ * Joan Boyar and Rene Peralta, A depth-16 circuit for the AES S-box.
+ * https://eprint.iacr.org/2011/332.pdf
+*/
+static void SubBytes(AES_state *s, int inv) {
+ /* Load the bit slices */
+ uint16_t U0 = s->slice[7], U1 = s->slice[6], U2 = s->slice[5], U3 = s->slice[4];
+ uint16_t U4 = s->slice[3], U5 = s->slice[2], U6 = s->slice[1], U7 = s->slice[0];
+
+ uint16_t T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16;
+ uint16_t T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, D;
+ uint16_t M1, M6, M11, M13, M15, M20, M21, M22, M23, M25, M37, M38, M39, M40;
+ uint16_t M41, M42, M43, M44, M45, M46, M47, M48, M49, M50, M51, M52, M53, M54;
+ uint16_t M55, M56, M57, M58, M59, M60, M61, M62, M63;
+
+ if (inv) {
+ uint16_t R5, R13, R17, R18, R19;
+ /* Undo linear postprocessing */
+ T23 = U0 ^ U3;
+ T22 = ~(U1 ^ U3);
+ T2 = ~(U0 ^ U1);
+ T1 = U3 ^ U4;
+ T24 = ~(U4 ^ U7);
+ R5 = U6 ^ U7;
+ T8 = ~(U1 ^ T23);
+ T19 = T22 ^ R5;
+ T9 = ~(U7 ^ T1);
+ T10 = T2 ^ T24;
+ T13 = T2 ^ R5;
+ T3 = T1 ^ R5;
+ T25 = ~(U2 ^ T1);
+ R13 = U1 ^ U6;
+ T17 = ~(U2 ^ T19);
+ T20 = T24 ^ R13;
+ T4 = U4 ^ T8;
+ R17 = ~(U2 ^ U5);
+ R18 = ~(U5 ^ U6);
+ R19 = ~(U2 ^ U4);
+ D = U0 ^ R17;
+ T6 = T22 ^ R17;
+ T16 = R13 ^ R19;
+ T27 = T1 ^ R18;
+ T15 = T10 ^ T27;
+ T14 = T10 ^ R18;
+ T26 = T3 ^ T16;
+ } else {
+ /* Linear preprocessing. */
+ T1 = U0 ^ U3;
+ T2 = U0 ^ U5;
+ T3 = U0 ^ U6;
+ T4 = U3 ^ U5;
+ T5 = U4 ^ U6;
+ T6 = T1 ^ T5;
+ T7 = U1 ^ U2;
+ T8 = U7 ^ T6;
+ T9 = U7 ^ T7;
+ T10 = T6 ^ T7;
+ T11 = U1 ^ U5;
+ T12 = U2 ^ U5;
+ T13 = T3 ^ T4;
+ T14 = T6 ^ T11;
+ T15 = T5 ^ T11;
+ T16 = T5 ^ T12;
+ T17 = T9 ^ T16;
+ T18 = U3 ^ U7;
+ T19 = T7 ^ T18;
+ T20 = T1 ^ T19;
+ T21 = U6 ^ U7;
+ T22 = T7 ^ T21;
+ T23 = T2 ^ T22;
+ T24 = T2 ^ T10;
+ T25 = T20 ^ T17;
+ T26 = T3 ^ T16;
+ T27 = T1 ^ T12;
+ D = U7;
+ }
+
+ /* Non-linear transformation (shared between the forward and backward case) */
+ M1 = T13 & T6;
+ M6 = T3 & T16;
+ M11 = T1 & T15;
+ M13 = (T4 & T27) ^ M11;
+ M15 = (T2 & T10) ^ M11;
+ M20 = T14 ^ M1 ^ (T23 & T8) ^ M13;
+ M21 = (T19 & D) ^ M1 ^ T24 ^ M15;
+ M22 = T26 ^ M6 ^ (T22 & T9) ^ M13;
+ M23 = (T20 & T17) ^ M6 ^ M15 ^ T25;
+ M25 = M22 & M20;
+ M37 = M21 ^ ((M20 ^ M21) & (M23 ^ M25));
+ M38 = M20 ^ M25 ^ (M21 | (M20 & M23));
+ M39 = M23 ^ ((M22 ^ M23) & (M21 ^ M25));
+ M40 = M22 ^ M25 ^ (M23 | (M21 & M22));
+ M41 = M38 ^ M40;
+ M42 = M37 ^ M39;
+ M43 = M37 ^ M38;
+ M44 = M39 ^ M40;
+ M45 = M42 ^ M41;
+ M46 = M44 & T6;
+ M47 = M40 & T8;
+ M48 = M39 & D;
+ M49 = M43 & T16;
+ M50 = M38 & T9;
+ M51 = M37 & T17;
+ M52 = M42 & T15;
+ M53 = M45 & T27;
+ M54 = M41 & T10;
+ M55 = M44 & T13;
+ M56 = M40 & T23;
+ M57 = M39 & T19;
+ M58 = M43 & T3;
+ M59 = M38 & T22;
+ M60 = M37 & T20;
+ M61 = M42 & T1;
+ M62 = M45 & T4;
+ M63 = M41 & T2;
+
+ if (inv){
+ /* Undo linear preprocessing */
+ uint16_t P0 = M52 ^ M61;
+ uint16_t P1 = M58 ^ M59;
+ uint16_t P2 = M54 ^ M62;
+ uint16_t P3 = M47 ^ M50;
+ uint16_t P4 = M48 ^ M56;
+ uint16_t P5 = M46 ^ M51;
+ uint16_t P6 = M49 ^ M60;
+ uint16_t P7 = P0 ^ P1;
+ uint16_t P8 = M50 ^ M53;
+ uint16_t P9 = M55 ^ M63;
+ uint16_t P10 = M57 ^ P4;
+ uint16_t P11 = P0 ^ P3;
+ uint16_t P12 = M46 ^ M48;
+ uint16_t P13 = M49 ^ M51;
+ uint16_t P14 = M49 ^ M62;
+ uint16_t P15 = M54 ^ M59;
+ uint16_t P16 = M57 ^ M61;
+ uint16_t P17 = M58 ^ P2;
+ uint16_t P18 = M63 ^ P5;
+ uint16_t P19 = P2 ^ P3;
+ uint16_t P20 = P4 ^ P6;
+ uint16_t P22 = P2 ^ P7;
+ uint16_t P23 = P7 ^ P8;
+ uint16_t P24 = P5 ^ P7;
+ uint16_t P25 = P6 ^ P10;
+ uint16_t P26 = P9 ^ P11;
+ uint16_t P27 = P10 ^ P18;
+ uint16_t P28 = P11 ^ P25;
+ uint16_t P29 = P15 ^ P20;
+ s->slice[7] = P13 ^ P22;
+ s->slice[6] = P26 ^ P29;
+ s->slice[5] = P17 ^ P28;
+ s->slice[4] = P12 ^ P22;
+ s->slice[3] = P23 ^ P27;
+ s->slice[2] = P19 ^ P24;
+ s->slice[1] = P14 ^ P23;
+ s->slice[0] = P9 ^ P16;
+ } else {
+ /* Linear postprocessing */
+ uint16_t L0 = M61 ^ M62;
+ uint16_t L1 = M50 ^ M56;
+ uint16_t L2 = M46 ^ M48;
+ uint16_t L3 = M47 ^ M55;
+ uint16_t L4 = M54 ^ M58;
+ uint16_t L5 = M49 ^ M61;
+ uint16_t L6 = M62 ^ L5;
+ uint16_t L7 = M46 ^ L3;
+ uint16_t L8 = M51 ^ M59;
+ uint16_t L9 = M52 ^ M53;
+ uint16_t L10 = M53 ^ L4;
+ uint16_t L11 = M60 ^ L2;
+ uint16_t L12 = M48 ^ M51;
+ uint16_t L13 = M50 ^ L0;
+ uint16_t L14 = M52 ^ M61;
+ uint16_t L15 = M55 ^ L1;
+ uint16_t L16 = M56 ^ L0;
+ uint16_t L17 = M57 ^ L1;
+ uint16_t L18 = M58 ^ L8;
+ uint16_t L19 = M63 ^ L4;
+ uint16_t L20 = L0 ^ L1;
+ uint16_t L21 = L1 ^ L7;
+ uint16_t L22 = L3 ^ L12;
+ uint16_t L23 = L18 ^ L2;
+ uint16_t L24 = L15 ^ L9;
+ uint16_t L25 = L6 ^ L10;
+ uint16_t L26 = L7 ^ L9;
+ uint16_t L27 = L8 ^ L10;
+ uint16_t L28 = L11 ^ L14;
+ uint16_t L29 = L11 ^ L17;
+ s->slice[7] = L6 ^ L24;
+ s->slice[6] = ~(L16 ^ L26);
+ s->slice[5] = ~(L19 ^ L28);
+ s->slice[4] = L6 ^ L21;
+ s->slice[3] = L20 ^ L22;
+ s->slice[2] = L25 ^ L29;
+ s->slice[1] = ~(L13 ^ L27);
+ s->slice[0] = ~(L6 ^ L23);
+ }
+}
+
+#define BIT_RANGE(from,to) (((1 << ((to) - (from))) - 1) << (from))
+
+#define BIT_RANGE_LEFT(x,from,to,shift) (((x) & BIT_RANGE((from), (to))) << (shift))
+#define BIT_RANGE_RIGHT(x,from,to,shift) (((x) & BIT_RANGE((from), (to))) >> (shift))
+
+static void ShiftRows(AES_state* s) {
+ int i;
+ for (i = 0; i < 8; i++) {
+ uint16_t v = s->slice[i];
+ s->slice[i] =
+ (v & BIT_RANGE(0, 4)) |
+ BIT_RANGE_LEFT(v, 4, 5, 3) | BIT_RANGE_RIGHT(v, 5, 8, 1) |
+ BIT_RANGE_LEFT(v, 8, 10, 2) | BIT_RANGE_RIGHT(v, 10, 12, 2) |
+ BIT_RANGE_LEFT(v, 12, 15, 1) | BIT_RANGE_RIGHT(v, 15, 16, 3);
+ }
+}
+
+static void InvShiftRows(AES_state* s) {
+ int i;
+ for (i = 0; i < 8; i++) {
+ uint16_t v = s->slice[i];
+ s->slice[i] =
+ (v & BIT_RANGE(0, 4)) |
+ BIT_RANGE_LEFT(v, 4, 7, 1) | BIT_RANGE_RIGHT(v, 7, 8, 3) |
+ BIT_RANGE_LEFT(v, 8, 10, 2) | BIT_RANGE_RIGHT(v, 10, 12, 2) |
+ BIT_RANGE_LEFT(v, 12, 13, 3) | BIT_RANGE_RIGHT(v, 13, 16, 1);
+ }
+}
+
+#define ROT(x,b) (((x) >> ((b) * 4)) | ((x) << ((4-(b)) * 4)))
+
+static void MixColumns(AES_state* s, int inv) {
+ /* The MixColumns transform treats the bytes of the columns of the state as
+ * coefficients of a 3rd degree polynomial over GF(2^8) and multiplies them
+ * by the fixed polynomial a(x) = {03}x^3 + {01}x^2 + {01}x + {02}, modulo
+ * x^4 + {01}.
+ *
+ * In the inverse transform, we multiply by the inverse of a(x),
+ * a^-1(x) = {0b}x^3 + {0d}x^2 + {09}x + {0e}. This is equal to
+ * a(x) * ({04}x^2 + {05}), so we can reuse the forward transform's code
+ * (found in OpenSSL's bsaes-x86_64.pl, attributed to Jussi Kivilinna)
+ *
+ * In the bitsliced representation, a multiplication of every column by x
+ * mod x^4 + 1 is simply a right rotation.
+ */
+
+ /* Shared for both directions is a multiplication by a(x), which can be
+ * rewritten as (x^3 + x^2 + x) + {02}*(x^3 + {01}).
+ *
+ * First compute s into the s? variables, (x^3 + {01}) * s into the s?_01
+ * variables and (x^3 + x^2 + x)*s into the s?_123 variables.
+ */
+ uint16_t s0 = s->slice[0], s1 = s->slice[1], s2 = s->slice[2], s3 = s->slice[3];
+ uint16_t s4 = s->slice[4], s5 = s->slice[5], s6 = s->slice[6], s7 = s->slice[7];
+ uint16_t s0_01 = s0 ^ ROT(s0, 1), s0_123 = ROT(s0_01, 1) ^ ROT(s0, 3);
+ uint16_t s1_01 = s1 ^ ROT(s1, 1), s1_123 = ROT(s1_01, 1) ^ ROT(s1, 3);
+ uint16_t s2_01 = s2 ^ ROT(s2, 1), s2_123 = ROT(s2_01, 1) ^ ROT(s2, 3);
+ uint16_t s3_01 = s3 ^ ROT(s3, 1), s3_123 = ROT(s3_01, 1) ^ ROT(s3, 3);
+ uint16_t s4_01 = s4 ^ ROT(s4, 1), s4_123 = ROT(s4_01, 1) ^ ROT(s4, 3);
+ uint16_t s5_01 = s5 ^ ROT(s5, 1), s5_123 = ROT(s5_01, 1) ^ ROT(s5, 3);
+ uint16_t s6_01 = s6 ^ ROT(s6, 1), s6_123 = ROT(s6_01, 1) ^ ROT(s6, 3);
+ uint16_t s7_01 = s7 ^ ROT(s7, 1), s7_123 = ROT(s7_01, 1) ^ ROT(s7, 3);
+ /* Now compute s = s?_123 + {02} * s?_01. */
+ s->slice[0] = s7_01 ^ s0_123;
+ s->slice[1] = s7_01 ^ s0_01 ^ s1_123;
+ s->slice[2] = s1_01 ^ s2_123;
+ s->slice[3] = s7_01 ^ s2_01 ^ s3_123;
+ s->slice[4] = s7_01 ^ s3_01 ^ s4_123;
+ s->slice[5] = s4_01 ^ s5_123;
+ s->slice[6] = s5_01 ^ s6_123;
+ s->slice[7] = s6_01 ^ s7_123;
+ if (inv) {
+ /* In the reverse direction, we further need to multiply by
+ * {04}x^2 + {05}, which can be written as {04} * (x^2 + {01}) + {01}.
+ *
+ * First compute (x^2 + {01}) * s into the t?_02 variables: */
+ uint16_t t0_02 = s->slice[0] ^ ROT(s->slice[0], 2);
+ uint16_t t1_02 = s->slice[1] ^ ROT(s->slice[1], 2);
+ uint16_t t2_02 = s->slice[2] ^ ROT(s->slice[2], 2);
+ uint16_t t3_02 = s->slice[3] ^ ROT(s->slice[3], 2);
+ uint16_t t4_02 = s->slice[4] ^ ROT(s->slice[4], 2);
+ uint16_t t5_02 = s->slice[5] ^ ROT(s->slice[5], 2);
+ uint16_t t6_02 = s->slice[6] ^ ROT(s->slice[6], 2);
+ uint16_t t7_02 = s->slice[7] ^ ROT(s->slice[7], 2);
+ /* And then update s += {04} * t?_02 */
+ s->slice[0] ^= t6_02;
+ s->slice[1] ^= t6_02 ^ t7_02;
+ s->slice[2] ^= t0_02 ^ t7_02;
+ s->slice[3] ^= t1_02 ^ t6_02;
+ s->slice[4] ^= t2_02 ^ t6_02 ^ t7_02;
+ s->slice[5] ^= t3_02 ^ t7_02;
+ s->slice[6] ^= t4_02;
+ s->slice[7] ^= t5_02;
+ }
+}
+
+static void AddRoundKey(AES_state* s, const AES_state* round) {
+ int b;
+ for (b = 0; b < 8; b++) {
+ s->slice[b] ^= round->slice[b];
+ }
+}
+
+/** column_0(s) = column_c(a) */
+static void GetOneColumn(AES_state* s, const AES_state* a, int c) {
+ int b;
+ for (b = 0; b < 8; b++) {
+ s->slice[b] = (a->slice[b] >> c) & 0x1111;
+ }
+}
+
+/** column_c1(r) |= (column_0(s) ^= column_c2(a)) */
+static void KeySetupColumnMix(AES_state* s, AES_state* r, const AES_state* a, int c1, int c2) {
+ int b;
+ for (b = 0; b < 8; b++) {
+ r->slice[b] |= ((s->slice[b] ^= ((a->slice[b] >> c2) & 0x1111)) & 0x1111) << c1;
+ }
+}
+
+/** Rotate the rows in s one position upwards, and xor in r */
+static void KeySetupTransform(AES_state* s, const AES_state* r) {
+ int b;
+ for (b = 0; b < 8; b++) {
+ s->slice[b] = ((s->slice[b] >> 4) | (s->slice[b] << 12)) ^ r->slice[b];
+ }
+}
+
+/* Multiply the cells in s by x, as polynomials over GF(2) mod x^8 + x^4 + x^3 + x + 1 */
+static void MultX(AES_state* s) {
+ uint16_t top = s->slice[7];
+ s->slice[7] = s->slice[6];
+ s->slice[6] = s->slice[5];
+ s->slice[5] = s->slice[4];
+ s->slice[4] = s->slice[3] ^ top;
+ s->slice[3] = s->slice[2] ^ top;
+ s->slice[2] = s->slice[1];
+ s->slice[1] = s->slice[0] ^ top;
+ s->slice[0] = top;
+}
+
+/** Expand the cipher key into the key schedule.
+ *
+ * state must be a pointer to an array of size nrounds + 1.
+ * key must be a pointer to 4 * nkeywords bytes.
+ *
+ * AES128 uses nkeywords = 4, nrounds = 10
+ * AES192 uses nkeywords = 6, nrounds = 12
+ * AES256 uses nkeywords = 8, nrounds = 14
+ */
+static void AES_setup(AES_state* rounds, const uint8_t* key, int nkeywords, int nrounds)
+{
+ int i;
+
+ /* The one-byte round constant */
+ AES_state rcon = {{1,0,0,0,0,0,0,0}};
+ /* The number of the word being generated, modulo nkeywords */
+ int pos = 0;
+ /* The column representing the word currently being processed */
+ AES_state column;
+
+ for (i = 0; i < nrounds + 1; i++) {
+ int b;
+ for (b = 0; b < 8; b++) {
+ rounds[i].slice[b] = 0;
+ }
+ }
+
+ /* The first nkeywords round columns are just taken from the key directly. */
+ for (i = 0; i < nkeywords; i++) {
+ int r;
+ for (r = 0; r < 4; r++) {
+ LoadByte(&rounds[i >> 2], *(key++), r, i & 3);
+ }
+ }
+
+ GetOneColumn(&column, &rounds[(nkeywords - 1) >> 2], (nkeywords - 1) & 3);
+
+ for (i = nkeywords; i < 4 * (nrounds + 1); i++) {
+ /* Transform column */
+ if (pos == 0) {
+ SubBytes(&column, 0);
+ KeySetupTransform(&column, &rcon);
+ MultX(&rcon);
+ } else if (nkeywords > 6 && pos == 4) {
+ SubBytes(&column, 0);
+ }
+ if (++pos == nkeywords) pos = 0;
+ KeySetupColumnMix(&column, &rounds[i >> 2], &rounds[(i - nkeywords) >> 2], i & 3, (i - nkeywords) & 3);
+ }
+}
+
+static void AES_encrypt(const AES_state* rounds, int nrounds, unsigned char* cipher16, const unsigned char* plain16) {
+ AES_state s = {{0}};
+ int round;
+
+ LoadBytes(&s, plain16);
+ AddRoundKey(&s, rounds++);
+
+ for (round = 1; round < nrounds; round++) {
+ SubBytes(&s, 0);
+ ShiftRows(&s);
+ MixColumns(&s, 0);
+ AddRoundKey(&s, rounds++);
+ }
+
+ SubBytes(&s, 0);
+ ShiftRows(&s);
+ AddRoundKey(&s, rounds);
+
+ SaveBytes(cipher16, &s);
+}
+
+static void AES_decrypt(const AES_state* rounds, int nrounds, unsigned char* plain16, const unsigned char* cipher16) {
+ /* Most AES decryption implementations use the alternate scheme
+ * (the Equivalent Inverse Cipher), which allows for more code reuse between
+ * the encryption and decryption code, but requires separate setup for both.
+ */
+ AES_state s = {{0}};
+ int round;
+
+ rounds += nrounds;
+
+ LoadBytes(&s, cipher16);
+ AddRoundKey(&s, rounds--);
+
+ for (round = 1; round < nrounds; round++) {
+ InvShiftRows(&s);
+ SubBytes(&s, 1);
+ AddRoundKey(&s, rounds--);
+ MixColumns(&s, 1);
+ }
+
+ InvShiftRows(&s);
+ SubBytes(&s, 1);
+ AddRoundKey(&s, rounds);
+
+ SaveBytes(plain16, &s);
+}
+
+void AES128_init(AES128_ctx* ctx, const unsigned char* key16) {
+ AES_setup(ctx->rk, key16, 4, 10);
+}
+
+void AES128_encrypt(const AES128_ctx* ctx, size_t blocks, unsigned char* cipher16, const unsigned char* plain16) {
+ while (blocks--) {
+ AES_encrypt(ctx->rk, 10, cipher16, plain16);
+ cipher16 += 16;
+ plain16 += 16;
+ }
+}
+
+void AES128_decrypt(const AES128_ctx* ctx, size_t blocks, unsigned char* plain16, const unsigned char* cipher16) {
+ while (blocks--) {
+ AES_decrypt(ctx->rk, 10, plain16, cipher16);
+ cipher16 += 16;
+ plain16 += 16;
+ }
+}
+
+void AES192_init(AES192_ctx* ctx, const unsigned char* key24) {
+ AES_setup(ctx->rk, key24, 6, 12);
+}
+
+void AES192_encrypt(const AES192_ctx* ctx, size_t blocks, unsigned char* cipher16, const unsigned char* plain16) {
+ while (blocks--) {
+ AES_encrypt(ctx->rk, 12, cipher16, plain16);
+ cipher16 += 16;
+ plain16 += 16;
+ }
+
+}
+
+void AES192_decrypt(const AES192_ctx* ctx, size_t blocks, unsigned char* plain16, const unsigned char* cipher16) {
+ while (blocks--) {
+ AES_decrypt(ctx->rk, 12, plain16, cipher16);
+ cipher16 += 16;
+ plain16 += 16;
+ }
+}
+
+void AES256_init(AES256_ctx* ctx, const unsigned char* key32) {
+ AES_setup(ctx->rk, key32, 8, 14);
+}
+
+void AES256_encrypt(const AES256_ctx* ctx, size_t blocks, unsigned char* cipher16, const unsigned char* plain16) {
+ while (blocks--) {
+ AES_encrypt(ctx->rk, 14, cipher16, plain16);
+ cipher16 += 16;
+ plain16 += 16;
+ }
+}
+
+void AES256_decrypt(const AES256_ctx* ctx, size_t blocks, unsigned char* plain16, const unsigned char* cipher16) {
+ while (blocks--) {
+ AES_decrypt(ctx->rk, 14, plain16, cipher16);
+ cipher16 += 16;
+ plain16 += 16;
+ }
+}
diff --git a/src/crypto/ctaes/ctaes.h b/src/crypto/ctaes/ctaes.h
new file mode 100644
index 000000000..29d1f9d36
--- /dev/null
+++ b/src/crypto/ctaes/ctaes.h
@@ -0,0 +1,41 @@
+ /*********************************************************************
+ * Copyright (c) 2016 Pieter Wuille *
+ * Distributed under the MIT software license, see the accompanying *
+ * file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html*
+ **********************************************************************/
+
+#ifndef _CTAES_H_
+#define _CTAES_H_ 1
+
+#include
+#include
+
+typedef struct {
+ uint16_t slice[8];
+} AES_state;
+
+typedef struct {
+ AES_state rk[11];
+} AES128_ctx;
+
+typedef struct {
+ AES_state rk[13];
+} AES192_ctx;
+
+typedef struct {
+ AES_state rk[15];
+} AES256_ctx;
+
+void AES128_init(AES128_ctx* ctx, const unsigned char* key16);
+void AES128_encrypt(const AES128_ctx* ctx, size_t blocks, unsigned char* cipher16, const unsigned char* plain16);
+void AES128_decrypt(const AES128_ctx* ctx, size_t blocks, unsigned char* plain16, const unsigned char* cipher16);
+
+void AES192_init(AES192_ctx* ctx, const unsigned char* key24);
+void AES192_encrypt(const AES192_ctx* ctx, size_t blocks, unsigned char* cipher16, const unsigned char* plain16);
+void AES192_decrypt(const AES192_ctx* ctx, size_t blocks, unsigned char* plain16, const unsigned char* cipher16);
+
+void AES256_init(AES256_ctx* ctx, const unsigned char* key32);
+void AES256_encrypt(const AES256_ctx* ctx, size_t blocks, unsigned char* cipher16, const unsigned char* plain16);
+void AES256_decrypt(const AES256_ctx* ctx, size_t blocks, unsigned char* plain16, const unsigned char* cipher16);
+
+#endif
diff --git a/src/crypto/ctaes/test.c b/src/crypto/ctaes/test.c
new file mode 100644
index 000000000..f13d02685
--- /dev/null
+++ b/src/crypto/ctaes/test.c
@@ -0,0 +1,110 @@
+ /*********************************************************************
+ * Copyright (c) 2016 Pieter Wuille *
+ * Distributed under the MIT software license, see the accompanying *
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
+ **********************************************************************/
+
+#include "ctaes.h"
+
+#include
+#include
+#include
+
+typedef struct {
+ int keysize;
+ const char* key;
+ const char* plain;
+ const char* cipher;
+} ctaes_test;
+
+static const ctaes_test ctaes_tests[] = {
+ /* AES test vectors from FIPS 197. */
+ {128, "000102030405060708090a0b0c0d0e0f", "00112233445566778899aabbccddeeff", "69c4e0d86a7b0430d8cdb78070b4c55a"},
+ {192, "000102030405060708090a0b0c0d0e0f1011121314151617", "00112233445566778899aabbccddeeff", "dda97ca4864cdfe06eaf70a0ec0d7191"},
+ {256, "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", "00112233445566778899aabbccddeeff", "8ea2b7ca516745bfeafc49904b496089"},
+
+ /* AES-ECB test vectors from NIST sp800-38a. */
+ {128, "2b7e151628aed2a6abf7158809cf4f3c", "6bc1bee22e409f96e93d7e117393172a", "3ad77bb40d7a3660a89ecaf32466ef97"},
+ {128, "2b7e151628aed2a6abf7158809cf4f3c", "ae2d8a571e03ac9c9eb76fac45af8e51", "f5d3d58503b9699de785895a96fdbaaf"},
+ {128, "2b7e151628aed2a6abf7158809cf4f3c", "30c81c46a35ce411e5fbc1191a0a52ef", "43b1cd7f598ece23881b00e3ed030688"},
+ {128, "2b7e151628aed2a6abf7158809cf4f3c", "f69f2445df4f9b17ad2b417be66c3710", "7b0c785e27e8ad3f8223207104725dd4"},
+ {192, "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", "6bc1bee22e409f96e93d7e117393172a", "bd334f1d6e45f25ff712a214571fa5cc"},
+ {192, "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", "ae2d8a571e03ac9c9eb76fac45af8e51", "974104846d0ad3ad7734ecb3ecee4eef"},
+ {192, "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", "30c81c46a35ce411e5fbc1191a0a52ef", "ef7afd2270e2e60adce0ba2face6444e"},
+ {192, "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", "f69f2445df4f9b17ad2b417be66c3710", "9a4b41ba738d6c72fb16691603c18e0e"},
+ {256, "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", "6bc1bee22e409f96e93d7e117393172a", "f3eed1bdb5d2a03c064b5a7e3db181f8"},
+ {256, "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", "ae2d8a571e03ac9c9eb76fac45af8e51", "591ccb10d410ed26dc5ba74a31362870"},
+ {256, "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", "30c81c46a35ce411e5fbc1191a0a52ef", "b6ed21b99ca6f4f9f153e7b1beafed1d"},
+ {256, "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", "f69f2445df4f9b17ad2b417be66c3710", "23304b7a39f9f3ff067d8d8f9e24ecc7"}
+};
+
+static void from_hex(unsigned char* data, int len, const char* hex) {
+ int p;
+ for (p = 0; p < len; p++) {
+ int v = 0;
+ int n;
+ for (n = 0; n < 2; n++) {
+ assert((*hex >= '0' && *hex <= '9') || (*hex >= 'a' && *hex <= 'f'));
+ if (*hex >= '0' && *hex <= '9') {
+ v |= (*hex - '0') << (4 * (1 - n));
+ } else {
+ v |= (*hex - 'a' + 10) << (4 * (1 - n));
+ }
+ hex++;
+ }
+ *(data++) = v;
+ }
+ assert(*hex == 0);
+}
+
+int main(void) {
+ int i;
+ int fail = 0;
+ for (i = 0; i < sizeof(ctaes_tests) / sizeof(ctaes_tests[0]); i++) {
+ unsigned char key[32], plain[16], cipher[16], ciphered[16], deciphered[16];
+ const ctaes_test* test = &ctaes_tests[i];
+ assert(test->keysize == 128 || test->keysize == 192 || test->keysize == 256);
+ from_hex(plain, 16, test->plain);
+ from_hex(cipher, 16, test->cipher);
+ switch (test->keysize) {
+ case 128: {
+ AES128_ctx ctx;
+ from_hex(key, 16, test->key);
+ AES128_init(&ctx, key);
+ AES128_encrypt(&ctx, 1, ciphered, plain);
+ AES128_decrypt(&ctx, 1, deciphered, cipher);
+ break;
+ }
+ case 192: {
+ AES192_ctx ctx;
+ from_hex(key, 24, test->key);
+ AES192_init(&ctx, key);
+ AES192_encrypt(&ctx, 1, ciphered, plain);
+ AES192_decrypt(&ctx, 1, deciphered, cipher);
+ break;
+ }
+ case 256: {
+ AES256_ctx ctx;
+ from_hex(key, 32, test->key);
+ AES256_init(&ctx, key);
+ AES256_encrypt(&ctx, 1, ciphered, plain);
+ AES256_decrypt(&ctx, 1, deciphered, cipher);
+ break;
+ }
+ }
+ if (memcmp(cipher, ciphered, 16)) {
+ fprintf(stderr, "E(key=\"%s\", plain=\"%s\") != \"%s\"\n", test->key, test->plain, test->cipher);
+ fail++;
+ }
+ if (memcmp(plain, deciphered, 16)) {
+ fprintf(stderr, "D(key=\"%s\", cipher=\"%s\") != \"%s\"\n", test->key, test->cipher, test->plain);
+ fail++;
+ }
+ }
+ if (fail == 0) {
+ fprintf(stderr, "All tests successful\n");
+ } else {
+ fprintf(stderr, "%i tests failed\n", fail);
+ }
+ return (fail != 0);
+}
diff --git a/src/crypto/equihash.cpp b/src/crypto/equihash.cpp
index 9a16fc085..07f82bcbe 100644
--- a/src/crypto/equihash.cpp
+++ b/src/crypto/equihash.cpp
@@ -1,7 +1,7 @@
// Copyright (c) 2016 Jack Grigg
// Copyright (c) 2016 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
// Implementation of the Equihash Proof-of-Work algorithm.
//
diff --git a/src/crypto/equihash.h b/src/crypto/equihash.h
index 57c434dae..3b837a67a 100644
--- a/src/crypto/equihash.h
+++ b/src/crypto/equihash.h
@@ -1,7 +1,7 @@
// Copyright (c) 2016 Jack Grigg
// Copyright (c) 2016 The Zcash developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_EQUIHASH_H
#define BITCOIN_EQUIHASH_H
@@ -15,6 +15,7 @@
#include
#include
#include
+#include
#include
#include
#include
diff --git a/src/crypto/equihash.tcc b/src/crypto/equihash.tcc
index 625749e47..a5fcbc4cc 100644
--- a/src/crypto/equihash.tcc
+++ b/src/crypto/equihash.tcc
@@ -1,7 +1,7 @@
// Copyright (c) 2016 Jack Grigg
// Copyright (c) 2016 The Zcash developers
// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// file COPYING or https://www.opensource.org/licenses/mit-license.php
#include
#include
diff --git a/src/crypto/hmac_sha256.cpp b/src/crypto/hmac_sha256.cpp
index 3c791625d..9e7863239 100644
--- a/src/crypto/hmac_sha256.cpp
+++ b/src/crypto/hmac_sha256.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include "crypto/hmac_sha256.h"
diff --git a/src/crypto/hmac_sha256.h b/src/crypto/hmac_sha256.h
index 1519c1457..e04cd50d8 100644
--- a/src/crypto/hmac_sha256.h
+++ b/src/crypto/hmac_sha256.h
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_CRYPTO_HMAC_SHA256_H
#define BITCOIN_CRYPTO_HMAC_SHA256_H
diff --git a/src/crypto/hmac_sha512.cpp b/src/crypto/hmac_sha512.cpp
index 5939c6ec4..cc1b33be1 100644
--- a/src/crypto/hmac_sha512.cpp
+++ b/src/crypto/hmac_sha512.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include "crypto/hmac_sha512.h"
diff --git a/src/crypto/hmac_sha512.h b/src/crypto/hmac_sha512.h
index 17dee61ea..42addab56 100644
--- a/src/crypto/hmac_sha512.h
+++ b/src/crypto/hmac_sha512.h
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_CRYPTO_HMAC_SHA512_H
#define BITCOIN_CRYPTO_HMAC_SHA512_H
diff --git a/src/crypto/ripemd160.cpp b/src/crypto/ripemd160.cpp
index 77c9acfc2..05d0c8237 100644
--- a/src/crypto/ripemd160.cpp
+++ b/src/crypto/ripemd160.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include "crypto/ripemd160.h"
diff --git a/src/crypto/ripemd160.h b/src/crypto/ripemd160.h
index 687204fda..0d78371c9 100644
--- a/src/crypto/ripemd160.h
+++ b/src/crypto/ripemd160.h
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_CRYPTO_RIPEMD160_H
#define BITCOIN_CRYPTO_RIPEMD160_H
diff --git a/src/crypto/sha1.cpp b/src/crypto/sha1.cpp
index 0b895b33a..e9570c8f7 100644
--- a/src/crypto/sha1.cpp
+++ b/src/crypto/sha1.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include "crypto/sha1.h"
diff --git a/src/crypto/sha1.h b/src/crypto/sha1.h
index 7b2a21bc6..3ed2e13d4 100644
--- a/src/crypto/sha1.h
+++ b/src/crypto/sha1.h
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_CRYPTO_SHA1_H
#define BITCOIN_CRYPTO_SHA1_H
diff --git a/src/crypto/sha256.cpp b/src/crypto/sha256.cpp
index 0718d2d25..90c682b75 100644
--- a/src/crypto/sha256.cpp
+++ b/src/crypto/sha256.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include "crypto/sha256.h"
#include "crypto/common.h"
diff --git a/src/crypto/sha256.h b/src/crypto/sha256.h
index 24c9c666d..fda7a427e 100644
--- a/src/crypto/sha256.h
+++ b/src/crypto/sha256.h
@@ -1,6 +1,6 @@
// Copyright (c) 2014-2016 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_CRYPTO_SHA256_H
#define BITCOIN_CRYPTO_SHA256_H
diff --git a/src/crypto/sha256_sse4.cpp b/src/crypto/sha256_sse4.cpp
index 89f529a3a..75f82b525 100644
--- a/src/crypto/sha256_sse4.cpp
+++ b/src/crypto/sha256_sse4.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2017 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
//
// This is a translation to GCC extended asm syntax from YASM code by Intel
// (available at the bottom of this file).
diff --git a/src/crypto/sha512.cpp b/src/crypto/sha512.cpp
index 564127cc3..3ccf1e222 100644
--- a/src/crypto/sha512.cpp
+++ b/src/crypto/sha512.cpp
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include "crypto/sha512.h"
diff --git a/src/crypto/sha512.h b/src/crypto/sha512.h
index f1f17caf9..f7e2a23e2 100644
--- a/src/crypto/sha512.h
+++ b/src/crypto/sha512.h
@@ -1,6 +1,6 @@
// Copyright (c) 2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_CRYPTO_SHA512_H
#define BITCOIN_CRYPTO_SHA512_H
diff --git a/src/cryptoconditions/Makefile.am b/src/cryptoconditions/Makefile.am
index 787b11ac6..615ac5783 100644
--- a/src/cryptoconditions/Makefile.am
+++ b/src/cryptoconditions/Makefile.am
@@ -15,7 +15,7 @@ AM_CFLAGS = -I$(top_srcdir)/src/asn -I$(top_srcdir)/include -I$(top_srcdir)/src/
LIBSECP256K1=src/include/secp256k1/libsecp256k1.la
$(LIBSECP256K1): $(wildcard src/secp256k1/*)
- $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) -march:x86-64 -g
+ $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) -g
CRYPTOCONDITIONS_CORE=libcryptoconditions_core.la
diff --git a/src/cryptoconditions/src/anon.c b/src/cryptoconditions/src/anon.c
index 55d7a3b7f..a1bd6b4a3 100644
--- a/src/cryptoconditions/src/anon.c
+++ b/src/cryptoconditions/src/anon.c
@@ -1,3 +1,4 @@
+// Copyright (c) 2019-2020 The Hush developers
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -53,11 +54,8 @@ static void anonToJSON(const CC *cond, cJSON *params) {
}
-static unsigned char *anonFingerprint(const CC *cond) {
- unsigned char *out = calloc(1, 32);
- //fprintf(stderr,"anon fingerprint %p %p\n",out,cond->fingerprint);
+static void anonFingerprint(const CC *cond, uint8_t *out) {
memcpy(out, cond->fingerprint, 32);
- return out;
}
diff --git a/src/cryptoconditions/src/asn/OCTET_STRING.c b/src/cryptoconditions/src/asn/OCTET_STRING.c
index 5420dedec..a886ff8fa 100644
--- a/src/cryptoconditions/src/asn/OCTET_STRING.c
+++ b/src/cryptoconditions/src/asn/OCTET_STRING.c
@@ -1714,7 +1714,9 @@ OCTET_STRING_free(asn_TYPE_descriptor_t *td, void *sptr, int contents_only) {
OCTET_STRING_t *st = (OCTET_STRING_t *)sptr;
asn_OCTET_STRING_specifics_t *specs;
asn_struct_ctx_t *ctx;
+#if !defined(__aarch64__)
struct _stack *stck;
+#endif
if(!td || !st)
return;
@@ -1731,6 +1733,15 @@ OCTET_STRING_free(asn_TYPE_descriptor_t *td, void *sptr, int contents_only) {
st->buf = 0;
}
+/* Attention !!!
+ * this is quick & dirty workaround for memory corruption bug on aarch64-linux-gnu
+ * - downside: allows memory leakage
+ * - issue description: On Raspberry Pi 4 @ 64bit linux, daemon crashes with "free(): invalid pointer" error
+ * - probable cause: misaligned memory access to nested structs containing pointers
+ * - TODO: use the latest asn1c compiler on CryptoConditions.asn, maybe generate cpp instead of c code... investigation in progress
+ */
+
+#if !defined(__aarch64__)
/*
* Remove decode-time stack.
*/
@@ -1747,6 +1758,7 @@ OCTET_STRING_free(asn_TYPE_descriptor_t *td, void *sptr, int contents_only) {
if(!contents_only) {
FREEMEM(st);
}
+#endif
}
/*
diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c
index 74949affc..6642b0345 100644
--- a/src/cryptoconditions/src/cryptoconditions.c
+++ b/src/cryptoconditions/src/cryptoconditions.c
@@ -1,3 +1,4 @@
+// Copyright (c) 2019-2020 The Hush developers
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -65,8 +66,8 @@ void appendUriSubtypes(uint32_t mask, unsigned char *buf) {
char *cc_conditionUri(const CC *cond) {
- unsigned char *fp = cond->type->fingerprint(cond);
- if (!fp) return NULL;
+ unsigned char *fp = calloc(1, 32);
+ cond->type->fingerprint(cond, fp);
unsigned char *encoded = base64_encode(fp, 32);
@@ -118,13 +119,13 @@ uint32_t fromAsnSubtypes(const ConditionTypes_t types) {
size_t cc_conditionBinary(const CC *cond, unsigned char *buf) {
Condition_t *asn = calloc(1, sizeof(Condition_t));
asnCondition(cond, asn);
+ size_t out = 0;
asn_enc_rval_t rc = der_encode_to_buffer(&asn_DEF_Condition, asn, buf, 1000);
- if (rc.encoded == -1) {
- fprintf(stderr, "CONDITION NOT ENCODED\n");
- return 0;
- }
+ if (rc.encoded == -1) goto end;
+ out = rc.encoded;
+end:
ASN_STRUCT_FREE(asn_DEF_Condition, asn);
- return rc.encoded;
+ return out;
}
@@ -146,10 +147,12 @@ void asnCondition(const CC *cond, Condition_t *asn) {
// This may look a little weird - we dont have a reference here to the correct
// union choice for the condition type, so we just assign everything to the threshold
// type. This works out nicely since the union choices have the same binary interface.
+
CompoundSha256Condition_t *choice = &asn->choice.thresholdSha256;
choice->cost = cc_getCost(cond);
- choice->fingerprint.buf = cond->type->fingerprint(cond);
choice->fingerprint.size = 32;
+ choice->fingerprint.buf = calloc(1, 32);
+ cond->type->fingerprint(cond, choice->fingerprint.buf);
choice->subtypes = asnSubtypes(cond->type->getSubtypes(cond));
}
diff --git a/src/cryptoconditions/src/ed25519.c b/src/cryptoconditions/src/ed25519.c
index 8d73d3cf1..33b332071 100644
--- a/src/cryptoconditions/src/ed25519.c
+++ b/src/cryptoconditions/src/ed25519.c
@@ -1,3 +1,4 @@
+// Copyright (c) 2019-2020 The Hush developers
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -25,11 +26,10 @@
struct CCType CC_Ed25519Type;
-static unsigned char *ed25519Fingerprint(const CC *cond) {
+static void ed25519Fingerprint(const CC *cond, uint8_t *out) {
Ed25519FingerprintContents_t *fp = calloc(1, sizeof(Ed25519FingerprintContents_t));
- //fprintf(stderr,"ed25519 fingerprint %p %p\n",fp,cond->publicKey);
OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, 32);
- return hashFingerprintContents(&asn_DEF_Ed25519FingerprintContents, fp);
+ hashFingerprintContents(&asn_DEF_Ed25519FingerprintContents, fp, out);
}
diff --git a/src/cryptoconditions/src/eval.c b/src/cryptoconditions/src/eval.c
index 99ff1ebf5..a017d181d 100644
--- a/src/cryptoconditions/src/eval.c
+++ b/src/cryptoconditions/src/eval.c
@@ -1,3 +1,4 @@
+// Copyright (c) 2019-2020 The Hush developers
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -25,11 +26,8 @@
struct CCType CC_EvalType;
-static unsigned char *evalFingerprint(const CC *cond) {
- unsigned char *hash = calloc(1, 32);
- //fprintf(stderr,"evalfingerprint %p %p\n",hash,cond->code);
- sha256(cond->code, cond->codeLength, hash);
- return hash;
+static void evalFingerprint(const CC *cond, uint8_t *out) {
+ sha256(cond->code, cond->codeLength, out);
}
@@ -105,7 +103,7 @@ static uint32_t evalSubtypes(const CC *cond) {
*/
int jsonVerifyEval(CC *cond, void *context) {
if (cond->codeLength == 5 && 0 == memcmp(cond->code, "TEST", 4)) {
- return cond->code[5];
+ return cond->code[4];
}
fprintf(stderr, "Cannot verify eval; user function unknown\n");
return 0;
diff --git a/src/cryptoconditions/src/include/secp256k1/Makefile.am b/src/cryptoconditions/src/include/secp256k1/Makefile.am
index 52303e4e4..13c83fe18 100644
--- a/src/cryptoconditions/src/include/secp256k1/Makefile.am
+++ b/src/cryptoconditions/src/include/secp256k1/Makefile.am
@@ -71,7 +71,7 @@ endif
endif
libsecp256k1_la_SOURCES = src/secp256k1.c
-libsecp256k1_la_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES) -march=x86-64 -g
+libsecp256k1_la_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES) -g
libsecp256k1_la_LIBADD = $(JNI_LIB) $(SECP_LIBS) $(COMMON_LIB)
libsecp256k1_jni_la_SOURCES = src/java/org_bitcoin_NativeSecp256k1.c src/java/org_bitcoin_Secp256k1Context.c
diff --git a/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_parsing.c b/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_parsing.c
index 5b141a994..74acf8c4f 100644
--- a/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_parsing.c
+++ b/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_parsing.c
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2015 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#include
diff --git a/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_parsing.h b/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_parsing.h
index 7eaf63bf6..9c5a51fbb 100644
--- a/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_parsing.h
+++ b/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_parsing.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2015 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
/****
diff --git a/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_privatekey_parsing.c b/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_privatekey_parsing.c
index c2e63b4b8..3fadba3f4 100644
--- a/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_privatekey_parsing.c
+++ b/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_privatekey_parsing.c
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014, 2015 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#include
diff --git a/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_privatekey_parsing.h b/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_privatekey_parsing.h
index fece261fb..d5c2e7487 100644
--- a/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_privatekey_parsing.h
+++ b/src/cryptoconditions/src/include/secp256k1/contrib/lax_der_privatekey_parsing.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014, 2015 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
/****
diff --git a/src/cryptoconditions/src/include/secp256k1/src/asm/field_10x26_arm.s b/src/cryptoconditions/src/include/secp256k1/src/asm/field_10x26_arm.s
index 5a9cc3ffc..e2029eb0c 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/asm/field_10x26_arm.s
+++ b/src/cryptoconditions/src/include/secp256k1/src/asm/field_10x26_arm.s
@@ -2,7 +2,7 @@
/**********************************************************************
* Copyright (c) 2014 Wladimir J. van der Laan *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
/*
ARM implementation of field_10x26 inner loops.
diff --git a/src/cryptoconditions/src/include/secp256k1/src/basic-config.h b/src/cryptoconditions/src/include/secp256k1/src/basic-config.h
index fc588061c..a9adbda17 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/basic-config.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/basic-config.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_BASIC_CONFIG_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/bench.h b/src/cryptoconditions/src/include/secp256k1/src/bench.h
index d5ebe0130..c8d038ff3 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/bench.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/bench.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_BENCH_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/bench_ecdh.c b/src/cryptoconditions/src/include/secp256k1/src/bench_ecdh.c
index 2de5126d6..95c44bb4a 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/bench_ecdh.c
+++ b/src/cryptoconditions/src/include/secp256k1/src/bench_ecdh.c
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2015 Pieter Wuille, Andrew Poelstra *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#include
diff --git a/src/cryptoconditions/src/include/secp256k1/src/bench_internal.c b/src/cryptoconditions/src/include/secp256k1/src/bench_internal.c
index 9b30c50d0..cae5f5d7e 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/bench_internal.c
+++ b/src/cryptoconditions/src/include/secp256k1/src/bench_internal.c
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014-2015 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#include
diff --git a/src/cryptoconditions/src/include/secp256k1/src/bench_recover.c b/src/cryptoconditions/src/include/secp256k1/src/bench_recover.c
index 506fc1880..0288c1c79 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/bench_recover.c
+++ b/src/cryptoconditions/src/include/secp256k1/src/bench_recover.c
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014-2015 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#include "include/secp256k1.h"
diff --git a/src/cryptoconditions/src/include/secp256k1/src/bench_sign.c b/src/cryptoconditions/src/include/secp256k1/src/bench_sign.c
index 544b43963..266df9c79 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/bench_sign.c
+++ b/src/cryptoconditions/src/include/secp256k1/src/bench_sign.c
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#include "include/secp256k1.h"
diff --git a/src/cryptoconditions/src/include/secp256k1/src/bench_verify.c b/src/cryptoconditions/src/include/secp256k1/src/bench_verify.c
index 418defa0a..3f154ea17 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/bench_verify.c
+++ b/src/cryptoconditions/src/include/secp256k1/src/bench_verify.c
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#include
diff --git a/src/cryptoconditions/src/include/secp256k1/src/ecdsa.h b/src/cryptoconditions/src/include/secp256k1/src/ecdsa.h
index 80590c7cc..fea457c20 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/ecdsa.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/ecdsa.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_ECDSA_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/ecdsa_impl.h b/src/cryptoconditions/src/include/secp256k1/src/ecdsa_impl.h
index c3400042d..a86fb9a44 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/ecdsa_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/ecdsa_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013-2015 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
diff --git a/src/cryptoconditions/src/include/secp256k1/src/eckey.h b/src/cryptoconditions/src/include/secp256k1/src/eckey.h
index b621f1e6c..913f1215c 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/eckey.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/eckey.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_ECKEY_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/eckey_impl.h b/src/cryptoconditions/src/include/secp256k1/src/eckey_impl.h
index 1ab9a68ec..0fccaffc6 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/eckey_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/eckey_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_ECKEY_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/ecmult.h b/src/cryptoconditions/src/include/secp256k1/src/ecmult.h
index 6d44aba60..28b1b14b7 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/ecmult.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/ecmult.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_ECMULT_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/ecmult_const.h b/src/cryptoconditions/src/include/secp256k1/src/ecmult_const.h
index bdb9ae43a..a3ab99007 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/ecmult_const.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/ecmult_const.h
@@ -3,7 +3,7 @@
/**********************************************************************
* Copyright (c) 2015 Andrew Poelstra *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_ECMULT_CONST_H
@@ -21,7 +21,7 @@ static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, cons
/**********************************************************************
* Copyright (c) 2015 Andrew Poelstra *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_ECMULT_CONST_H
@@ -36,4 +36,4 @@ static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, cons
#endif
-
+#endif
diff --git a/src/cryptoconditions/src/include/secp256k1/src/ecmult_const_impl.h b/src/cryptoconditions/src/include/secp256k1/src/ecmult_const_impl.h
index 7d7a172b7..395ed9f00 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/ecmult_const_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/ecmult_const_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2015 Pieter Wuille, Andrew Poelstra *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_ECMULT_CONST_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/ecmult_gen.h b/src/cryptoconditions/src/include/secp256k1/src/ecmult_gen.h
index 7564b7015..486feb13e 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/ecmult_gen.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/ecmult_gen.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_ECMULT_GEN_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/ecmult_gen_impl.h b/src/cryptoconditions/src/include/secp256k1/src/ecmult_gen_impl.h
index 714f02e94..a316e1c2a 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/ecmult_gen_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/ecmult_gen_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014, 2015 Pieter Wuille, Gregory Maxwell *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_ECMULT_GEN_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/ecmult_impl.h b/src/cryptoconditions/src/include/secp256k1/src/ecmult_impl.h
index 93d3794cb..17b8541db 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/ecmult_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/ecmult_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_ECMULT_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/field.h b/src/cryptoconditions/src/include/secp256k1/src/field.h
index bb6692ad5..30b6e50f0 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/field.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/field.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_FIELD_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/field_10x26.h b/src/cryptoconditions/src/include/secp256k1/src/field_10x26.h
index 727c5267f..c93cd4c86 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/field_10x26.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/field_10x26.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_FIELD_REPR_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/field_10x26_impl.h b/src/cryptoconditions/src/include/secp256k1/src/field_10x26_impl.h
index 94f8132fc..29799b418 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/field_10x26_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/field_10x26_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_FIELD_REPR_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/field_5x52.h b/src/cryptoconditions/src/include/secp256k1/src/field_5x52.h
index bccd8feb4..e9446b859 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/field_5x52.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/field_5x52.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_FIELD_REPR_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/field_5x52_asm_impl.h b/src/cryptoconditions/src/include/secp256k1/src/field_5x52_asm_impl.h
index 1fc3171f6..759101d0e 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/field_5x52_asm_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/field_5x52_asm_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013-2014 Diederik Huys, Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
/**
diff --git a/src/cryptoconditions/src/include/secp256k1/src/field_5x52_impl.h b/src/cryptoconditions/src/include/secp256k1/src/field_5x52_impl.h
index 957c61b01..f5dc9dc9d 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/field_5x52_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/field_5x52_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_FIELD_REPR_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/field_5x52_int128_impl.h b/src/cryptoconditions/src/include/secp256k1/src/field_5x52_int128_impl.h
index 95a0d1791..a26fb3c16 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/field_5x52_int128_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/field_5x52_int128_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_FIELD_INNER5X52_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/field_impl.h b/src/cryptoconditions/src/include/secp256k1/src/field_impl.h
index 20428648a..34827651c 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/field_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/field_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_FIELD_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/gen_context.c b/src/cryptoconditions/src/include/secp256k1/src/gen_context.c
index 1835fd491..5cd725509 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/gen_context.c
+++ b/src/cryptoconditions/src/include/secp256k1/src/gen_context.c
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014, 2015 Thomas Daede, Cory Fields *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#define USE_BASIC_CONFIG 1
diff --git a/src/cryptoconditions/src/include/secp256k1/src/group.h b/src/cryptoconditions/src/include/secp256k1/src/group.h
index ea1302deb..3b8a24883 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/group.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/group.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_GROUP_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/group_impl.h b/src/cryptoconditions/src/include/secp256k1/src/group_impl.h
index b31b6c12e..de6307c42 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/group_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/group_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_GROUP_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/hash.h b/src/cryptoconditions/src/include/secp256k1/src/hash.h
index de26e4b89..991b38699 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/hash.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/hash.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_HASH_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/hash_impl.h b/src/cryptoconditions/src/include/secp256k1/src/hash_impl.h
index c06db9e33..1f6dcc317 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/hash_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/hash_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_HASH_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/modules/ecdh/main_impl.h b/src/cryptoconditions/src/include/secp256k1/src/modules/ecdh/main_impl.h
index bd8739eeb..e80ed4af3 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/modules/ecdh/main_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/modules/ecdh/main_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2015 Andrew Poelstra *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_MODULE_ECDH_MAIN_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/modules/ecdh/tests_impl.h b/src/cryptoconditions/src/include/secp256k1/src/modules/ecdh/tests_impl.h
index 0c53f8ee0..99c400365 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/modules/ecdh/tests_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/modules/ecdh/tests_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2015 Andrew Poelstra *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_MODULE_ECDH_TESTS_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/modules/recovery/main_impl.h b/src/cryptoconditions/src/include/secp256k1/src/modules/recovery/main_impl.h
index 2f6691c5a..a63903ccb 100755
--- a/src/cryptoconditions/src/include/secp256k1/src/modules/recovery/main_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/modules/recovery/main_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013-2015 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_MODULE_RECOVERY_MAIN_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/modules/recovery/tests_impl.h b/src/cryptoconditions/src/include/secp256k1/src/modules/recovery/tests_impl.h
index 5c9bbe861..de2b0cab3 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/modules/recovery/tests_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/modules/recovery/tests_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013-2015 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_MODULE_RECOVERY_TESTS_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/num.h b/src/cryptoconditions/src/include/secp256k1/src/num.h
index 49f2dd791..48cc43488 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/num.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/num.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_NUM_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/num_gmp.h b/src/cryptoconditions/src/include/secp256k1/src/num_gmp.h
index 3619844bd..7c2f3387b 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/num_gmp.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/num_gmp.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_NUM_REPR_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/num_gmp_impl.h b/src/cryptoconditions/src/include/secp256k1/src/num_gmp_impl.h
index 0ae2a8ba0..a18ecb969 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/num_gmp_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/num_gmp_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_NUM_REPR_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/num_impl.h b/src/cryptoconditions/src/include/secp256k1/src/num_impl.h
index c45193b03..1ed66335b 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/num_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/num_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_NUM_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/scalar.h b/src/cryptoconditions/src/include/secp256k1/src/scalar.h
index 59304cb66..0b2393ff5 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/scalar.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/scalar.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_SCALAR_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/scalar_4x64.h b/src/cryptoconditions/src/include/secp256k1/src/scalar_4x64.h
index 19c7495d1..3fc3f8fae 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/scalar_4x64.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/scalar_4x64.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_SCALAR_REPR_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/scalar_4x64_impl.h b/src/cryptoconditions/src/include/secp256k1/src/scalar_4x64_impl.h
index db1ebf94b..2a2a21f45 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/scalar_4x64_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/scalar_4x64_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_SCALAR_REPR_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/scalar_8x32.h b/src/cryptoconditions/src/include/secp256k1/src/scalar_8x32.h
index 2c9a348e2..799c4806e 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/scalar_8x32.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/scalar_8x32.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_SCALAR_REPR_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/scalar_8x32_impl.h b/src/cryptoconditions/src/include/secp256k1/src/scalar_8x32_impl.h
index 4f9ed61fe..9e15725d2 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/scalar_8x32_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/scalar_8x32_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_SCALAR_REPR_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/scalar_impl.h b/src/cryptoconditions/src/include/secp256k1/src/scalar_impl.h
index fa790570f..2a98abf40 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/scalar_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/scalar_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_SCALAR_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/scalar_low.h b/src/cryptoconditions/src/include/secp256k1/src/scalar_low.h
index 5836febc5..016b4642b 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/scalar_low.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/scalar_low.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2015 Andrew Poelstra *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_SCALAR_REPR_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/scalar_low_impl.h b/src/cryptoconditions/src/include/secp256k1/src/scalar_low_impl.h
index c80e70c5a..7801a4a98 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/scalar_low_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/scalar_low_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2015 Andrew Poelstra *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_SCALAR_REPR_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/secp256k1.c b/src/cryptoconditions/src/include/secp256k1/src/secp256k1.c
index cecb1550b..d0a7c0c4f 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/secp256k1.c
+++ b/src/cryptoconditions/src/include/secp256k1/src/secp256k1.c
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013-2015 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#include "include/secp256k1.h"
diff --git a/src/cryptoconditions/src/include/secp256k1/src/testrand.h b/src/cryptoconditions/src/include/secp256k1/src/testrand.h
index f1f9be077..7b1acd16a 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/testrand.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/testrand.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_TESTRAND_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/testrand_impl.h b/src/cryptoconditions/src/include/secp256k1/src/testrand_impl.h
index 30a91e529..bcdbd149c 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/testrand_impl.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/testrand_impl.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013-2015 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_TESTRAND_IMPL_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/tests.c b/src/cryptoconditions/src/include/secp256k1/src/tests.c
index f307b99d5..890e6c977 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/tests.c
+++ b/src/cryptoconditions/src/include/secp256k1/src/tests.c
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014, 2015 Pieter Wuille, Gregory Maxwell *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#if defined HAVE_CONFIG_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/tests_exhaustive.c b/src/cryptoconditions/src/include/secp256k1/src/tests_exhaustive.c
index b040bb073..4e439bac4 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/tests_exhaustive.c
+++ b/src/cryptoconditions/src/include/secp256k1/src/tests_exhaustive.c
@@ -1,7 +1,7 @@
/***********************************************************************
* Copyright (c) 2016 Andrew Poelstra *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#if defined HAVE_CONFIG_H
diff --git a/src/cryptoconditions/src/include/secp256k1/src/util.h b/src/cryptoconditions/src/include/secp256k1/src/util.h
index b0441d8e3..617d5701d 100644
--- a/src/cryptoconditions/src/include/secp256k1/src/util.h
+++ b/src/cryptoconditions/src/include/secp256k1/src/util.h
@@ -1,7 +1,7 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Distributed under the MIT software license, see the accompanying *
- * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php*
**********************************************************************/
#ifndef SECP256K1_UTIL_H
diff --git a/src/cryptoconditions/src/internal.h b/src/cryptoconditions/src/internal.h
index 790e28962..3d24214ce 100644
--- a/src/cryptoconditions/src/internal.h
+++ b/src/cryptoconditions/src/internal.h
@@ -1,3 +1,4 @@
+// Copyright (c) 2019-2020 The Hush developers
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -41,7 +42,7 @@ typedef struct CCType {
char name[100];
Condition_PR asnType;
int (*visitChildren)(CC *cond, CCVisitor visitor);
- unsigned char *(*fingerprint)(const CC *cond);
+ void (*fingerprint)(const CC *cond, uint8_t *fp);
unsigned long (*getCost)(const CC *cond);
uint32_t (*getSubtypes)(const CC *cond);
CC *(*fromJSON)(const cJSON *params, char *err);
@@ -77,7 +78,7 @@ struct CCType *getTypeByAsnEnum(Condition_PR present);
*/
unsigned char *base64_encode(const unsigned char *data, size_t input_length);
unsigned char *base64_decode(const unsigned char *data_, size_t *output_length);
-unsigned char *hashFingerprintContents(asn_TYPE_descriptor_t *asnType, void *fp);
+void hashFingerprintContents(asn_TYPE_descriptor_t *asnType, void *fp, uint8_t* out);
void dumpStr(unsigned char *str, size_t len);
int checkString(const cJSON *value, char *key, char *err);
int checkDecodeBase64(const cJSON *value, char *key, char *err, unsigned char **data, size_t *size);
diff --git a/src/cryptoconditions/src/json_rpc.c b/src/cryptoconditions/src/json_rpc.c
index 150bcb12b..c4fde8080 100644
--- a/src/cryptoconditions/src/json_rpc.c
+++ b/src/cryptoconditions/src/json_rpc.c
@@ -1,3 +1,4 @@
+// Copyright (c) 2019-2020 The Hush developers
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
diff --git a/src/cryptoconditions/src/prefix.c b/src/cryptoconditions/src/prefix.c
index 45c6d8033..ea339df35 100644
--- a/src/cryptoconditions/src/prefix.c
+++ b/src/cryptoconditions/src/prefix.c
@@ -1,3 +1,4 @@
+// Copyright (c) 2019-2020 The Hush developers
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -37,13 +38,12 @@ static int prefixVisitChildren(CC *cond, CCVisitor visitor) {
}
-static unsigned char *prefixFingerprint(const CC *cond) {
+static void prefixFingerprint(const CC *cond, uint8_t *out) {
PrefixFingerprintContents_t *fp = calloc(1, sizeof(PrefixFingerprintContents_t));
- //fprintf(stderr,"prefixfinger %p %p\n",fp,cond->prefix);
- asnCondition(cond->subcondition, &fp->subcondition); // TODO: check asnCondition for safety
+ asnCondition(cond->subcondition, &fp->subcondition);
fp->maxMessageLength = cond->maxMessageLength;
OCTET_STRING_fromBuf(&fp->prefix, cond->prefix, cond->prefixLength);
- return hashFingerprintContents(&asn_DEF_PrefixFingerprintContents, fp);
+ hashFingerprintContents(&asn_DEF_PrefixFingerprintContents, fp, out);
}
diff --git a/src/cryptoconditions/src/preimage.c b/src/cryptoconditions/src/preimage.c
index 9e7fe12f4..2fee86b88 100644
--- a/src/cryptoconditions/src/preimage.c
+++ b/src/cryptoconditions/src/preimage.c
@@ -1,3 +1,4 @@
+// Copyright (c) 2019-2020 The Hush developers
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -44,11 +45,8 @@ static unsigned long preimageCost(const CC *cond) {
}
-static unsigned char *preimageFingerprint(const CC *cond) {
- unsigned char *hash = calloc(1, 32);
- //fprintf(stderr,"preimage %p %p\n",hash,cond->preimage);
- sha256(cond->preimage, cond->preimageLength, hash);
- return hash;
+static void preimageFingerprint(const CC *cond, uint8_t *out) {
+ sha256(cond->preimage, cond->preimageLength, out);
}
diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c
index a16115bb8..d5319d32b 100644
--- a/src/cryptoconditions/src/secp256k1.c
+++ b/src/cryptoconditions/src/secp256k1.c
@@ -1,3 +1,4 @@
+// Copyright (c) 2019-2020 The Hush developers
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -88,11 +89,10 @@ void initVerify() {
}
-static unsigned char *secp256k1Fingerprint(const CC *cond) {
+static void secp256k1Fingerprint(const CC *cond, uint8_t *out) {
Secp256k1FingerprintContents_t *fp = calloc(1, sizeof(Secp256k1FingerprintContents_t));
- //fprintf(stderr,"secpfinger %p %p size %d vs %d\n",fp,cond->publicKey,(int32_t)sizeof(Secp256k1FingerprintContents_t),(int32_t)SECP256K1_PK_SIZE);
OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, SECP256K1_PK_SIZE);
- return hashFingerprintContents(&asn_DEF_Secp256k1FingerprintContents, fp);
+ hashFingerprintContents(&asn_DEF_Secp256k1FingerprintContents, fp, out);
}
diff --git a/src/cryptoconditions/src/threshold.c b/src/cryptoconditions/src/threshold.c
index 9547f4f8c..e8e12435e 100644
--- a/src/cryptoconditions/src/threshold.c
+++ b/src/cryptoconditions/src/threshold.c
@@ -1,3 +1,4 @@
+// Copyright (c) 2019-2020 The Hush developers
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -94,17 +95,15 @@ static int cmpConditionBin(const void *a, const void *b) {
}
-static unsigned char *thresholdFingerprint(const CC *cond) {
- /* Create fingerprint */
+static void thresholdFingerprint(const CC *cond, uint8_t *out) {
ThresholdFingerprintContents_t *fp = calloc(1, sizeof(ThresholdFingerprintContents_t));
- //fprintf(stderr,"thresholdfinger %p\n",fp);
fp->threshold = cond->threshold;
for (int i=0; isize; i++) {
Condition_t *asnCond = asnConditionNew(cond->subconditions[i]);
asn_set_add(&fp->subconditions2, asnCond);
}
qsort(fp->subconditions2.list.array, cond->size, sizeof(Condition_t*), cmpConditionBin);
- return hashFingerprintContents(&asn_DEF_ThresholdFingerprintContents, fp);
+ hashFingerprintContents(&asn_DEF_ThresholdFingerprintContents, fp, out);
}
diff --git a/src/cryptoconditions/src/utils.c b/src/cryptoconditions/src/utils.c
index 6a2167119..ac2256f18 100644
--- a/src/cryptoconditions/src/utils.c
+++ b/src/cryptoconditions/src/utils.c
@@ -1,3 +1,4 @@
+// Copyright (c) 2019-2020 The Hush developers
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
@@ -210,17 +211,15 @@ void jsonAddBase64(cJSON *params, char *key, unsigned char *bin, size_t size) {
}
-unsigned char *hashFingerprintContents(asn_TYPE_descriptor_t *asnType, void *fp) {
+void hashFingerprintContents(asn_TYPE_descriptor_t *asnType, void *fp, uint8_t *out) {
unsigned char buf[BUF_SIZE];
asn_enc_rval_t rc = der_encode_to_buffer(asnType, fp, buf, BUF_SIZE);
ASN_STRUCT_FREE(*asnType, fp);
if (rc.encoded < 1) {
fprintf(stderr, "Encoding fingerprint failed\n");
- return 0;
+ return;
}
- unsigned char *hash = calloc(1,32);
- sha256(buf, rc.encoded, hash);
- return hash;
+ sha256(buf, rc.encoded, out);
}
@@ -301,5 +300,3 @@ int jsonGetHexOptional(const cJSON *params, char *key, char *err, unsigned char
}
return checkDecodeHex(item, key, err, data, size);
}
-
-
diff --git a/src/cryptoconditions/tests/test_failure_modes.py b/src/cryptoconditions/tests/test_failure_modes.py
index 59b0b3f24..435e20c88 100644
--- a/src/cryptoconditions/tests/test_failure_modes.py
+++ b/src/cryptoconditions/tests/test_failure_modes.py
@@ -82,4 +82,25 @@ def test_malleability_checked():
assert not cc_rfb(b'\xa2\x13\xa0\x0f\xa0\x06\x80\x04abcd\xa0\x05\x80\x03abc\xa1\x00')
+def test_large_threshold():
+ conds = [{
+ 'type': "secp256k1-sha-256",
+ "publicKey": "02D5D969305535AC29A77079C11D4F0DD40661CF96E04E974A5E8D7E374EE225AA"
+ }]
+
+ for i in range(250):
+ conds.append({
+ "type": "eval-sha-256",
+ "code": "VEVTVAE"
+ })
+
+ r = jsonRPC("encodeCondition", {
+ "type": "threshold-sha-256",
+ "subfulfillments": conds,
+ "threshold": 251
+ })
+ assert 'error' not in r, r
+
+
+
so.cc_conditionUri.restype = ctypes.c_char_p
diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp
index 47bbb0f05..8109307fb 100644
--- a/src/dbwrapper.cpp
+++ b/src/dbwrapper.cpp
@@ -1,6 +1,7 @@
// Copyright (c) 2012-2014 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include "dbwrapper.h"
diff --git a/src/dbwrapper.h b/src/dbwrapper.h
index a43383a0a..dedd4fbe1 100644
--- a/src/dbwrapper.h
+++ b/src/dbwrapper.h
@@ -1,7 +1,7 @@
// Copyright (c) 2012-2014 The Bitcoin Core developers
// Copyright (c) 2019 The Hush developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#ifndef BITCOIN_DBWRAPPER_H
#define BITCOIN_DBWRAPPER_H
diff --git a/src/deprecation.cpp b/src/deprecation.cpp
index b32f24880..c5b2cf02f 100644
--- a/src/deprecation.cpp
+++ b/src/deprecation.cpp
@@ -1,7 +1,7 @@
// Copyright (c) 2017 The Zcash developers
// Copyright (c) 2019-2020 The Hush developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/deprecation.h b/src/deprecation.h
index eae3c92b9..d98c1bf78 100644
--- a/src/deprecation.h
+++ b/src/deprecation.h
@@ -1,7 +1,7 @@
// Copyright (c) 2017 The Zcash developers
// Copyright (c) 2019-2020 The Hush developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
diff --git a/src/fs.cpp b/src/fs.cpp
new file mode 100644
index 000000000..a5e12f1cf
--- /dev/null
+++ b/src/fs.cpp
@@ -0,0 +1,15 @@
+#include "fs.h"
+
+namespace fsbridge {
+
+FILE *fopen(const fs::path& p, const char *mode)
+{
+ return ::fopen(p.string().c_str(), mode);
+}
+
+FILE *freopen(const fs::path& p, const char *mode, FILE *stream)
+{
+ return ::freopen(p.string().c_str(), mode, stream);
+}
+
+} // fsbridge
diff --git a/src/fs.h b/src/fs.h
new file mode 100644
index 000000000..74c3c5a0b
--- /dev/null
+++ b/src/fs.h
@@ -0,0 +1,25 @@
+// Copyright (c) 2017 The Bitcoin Core developers
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
+
+#ifndef KOMODO_FS_H
+#define KOMODO_FS_H
+
+#include
+#include
+
+#include
+#include
+#include
+
+/** Filesystem operations and types */
+namespace fs = boost::filesystem;
+
+/** Bridge operations to C stdio */
+namespace fsbridge {
+ FILE *fopen(const fs::path& p, const char *mode);
+ FILE *freopen(const fs::path& p, const char *mode, FILE *stream);
+};
+
+#endif // KOMODO_FS_H
diff --git a/src/gtest/json_test_vectors.cpp b/src/gtest/json_test_vectors.cpp
index 94ba5b4c5..685300e1a 100644
--- a/src/gtest/json_test_vectors.cpp
+++ b/src/gtest/json_test_vectors.cpp
@@ -1,3 +1,6 @@
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include "json_test_vectors.h"
UniValue
diff --git a/src/gtest/json_test_vectors.h b/src/gtest/json_test_vectors.h
index 907d4834a..a178a84e6 100644
--- a/src/gtest/json_test_vectors.h
+++ b/src/gtest/json_test_vectors.h
@@ -1,3 +1,6 @@
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include
#include "utilstrencodings.h"
diff --git a/src/gtest/main.cpp b/src/gtest/main.cpp
index 28114834c..afd7843cb 100644
--- a/src/gtest/main.cpp
+++ b/src/gtest/main.cpp
@@ -1,3 +1,6 @@
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include "gmock/gmock.h"
#include "crypto/common.h"
#include "key.h"
diff --git a/src/gtest/test_block.cpp b/src/gtest/test_block.cpp
index a0cdc1162..03a98375c 100644
--- a/src/gtest/test_block.cpp
+++ b/src/gtest/test_block.cpp
@@ -1,3 +1,6 @@
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include
#include "primitives/block.h"
diff --git a/src/gtest/test_checkblock.cpp b/src/gtest/test_checkblock.cpp
index 807191b5d..cba4f5d87 100644
--- a/src/gtest/test_checkblock.cpp
+++ b/src/gtest/test_checkblock.cpp
@@ -1,3 +1,6 @@
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include
#include
diff --git a/src/gtest/test_checktransaction.cpp b/src/gtest/test_checktransaction.cpp
index 0efac93db..fe0815a31 100644
--- a/src/gtest/test_checktransaction.cpp
+++ b/src/gtest/test_checktransaction.cpp
@@ -1,3 +1,6 @@
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include
#include
#include
diff --git a/src/gtest/test_deprecation.cpp b/src/gtest/test_deprecation.cpp
index f8b93d6b6..fda5447ed 100644
--- a/src/gtest/test_deprecation.cpp
+++ b/src/gtest/test_deprecation.cpp
@@ -1,4 +1,5 @@
// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
// Released under the GPLv3
#include
diff --git a/src/gtest/test_equihash.cpp b/src/gtest/test_equihash.cpp
index 6134e43c9..20dd296a5 100644
--- a/src/gtest/test_equihash.cpp
+++ b/src/gtest/test_equihash.cpp
@@ -1,3 +1,6 @@
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
#endif
diff --git a/src/gtest/test_foundersreward.cpp b/src/gtest/test_foundersreward.cpp
deleted file mode 100644
index 7e5a3cf05..000000000
--- a/src/gtest/test_foundersreward.cpp
+++ /dev/null
@@ -1,194 +0,0 @@
-#include
-
-#include "main.h"
-#include "utilmoneystr.h"
-#include "chainparams.h"
-#include "utilstrencodings.h"
-#include "zcash/Address.hpp"
-#include "wallet/wallet.h"
-#include "amount.h"
-#include
-#include
-#include
-#include
-#include
-#include "util.h"
-
-#ifndef disable_founders
-// To run tests:
-// ./zcash-gtest --gtest_filter="founders_reward_test.*"
-
-//
-// Enable this test to generate and print 48 testnet 2-of-3 multisig addresses.
-// The output can be copied into chainparams.cpp.
-// The temporary wallet file can be renamed as wallet.dat and used for testing with zcashd.
-//
-#if 0
-TEST(founders_reward_test, create_testnet_2of3multisig) {
- SelectParams(CBaseChainParams::TESTNET);
- boost::filesystem::path pathTemp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
- boost::filesystem::create_directories(pathTemp);
- mapArgs["-datadir"] = pathTemp.string();
- bool fFirstRun;
- auto pWallet = std::make_shared("wallet.dat");
- ASSERT_EQ(DB_LOAD_OK, pWallet->LoadWallet(fFirstRun));
- pWallet->TopUpKeyPool();
- std::cout << "Test wallet and logs saved in folder: " << pathTemp.native() << std::endl;
-
- int numKeys = 48;
- std::vector pubkeys;
- pubkeys.resize(3);
- CPubKey newKey;
- std::vector addresses;
- for (int i = 0; i < numKeys; i++) {
- ASSERT_TRUE(pWallet->GetKeyFromPool(newKey));
- pubkeys[0] = newKey;
- pWallet->SetAddressBook(newKey.GetID(), "", "receive");
-
- ASSERT_TRUE(pWallet->GetKeyFromPool(newKey));
- pubkeys[1] = newKey;
- pWallet->SetAddressBook(newKey.GetID(), "", "receive");
-
- ASSERT_TRUE(pWallet->GetKeyFromPool(newKey));
- pubkeys[2] = newKey;
- pWallet->SetAddressBook(newKey.GetID(), "", "receive");
-
- CScript result = GetScriptForMultisig(2, pubkeys);
- ASSERT_FALSE(result.size() > MAX_SCRIPT_ELEMENT_SIZE);
- CScriptID innerID(result);
- pWallet->AddCScript(result);
- pWallet->SetAddressBook(innerID, "", "receive");
-
- std::string address = EncodeDestination(innerID);
- addresses.push_back(address);
- }
-
- // Print out the addresses, 4 on each line.
- std::string s = "vFoundersRewardAddress = {\n";
- int i=0;
- int colsPerRow = 4;
- ASSERT_TRUE(numKeys % colsPerRow == 0);
- int numRows = numKeys/colsPerRow;
- for (int row=0; rowFlush(true);
-}
-#endif
-
-
-// Utility method to check the number of unique addresses from height 1 to maxHeight
-void checkNumberOfUniqueAddresses(int nUnique) {
- int maxHeight = Params().GetConsensus().GetLastFoundersRewardBlockHeight();
- std::set addresses;
- for (int i = 1; i <= maxHeight; i++) {
- addresses.insert(Params().GetFoundersRewardAddressAtHeight(i));
- }
- ASSERT_TRUE(addresses.size() == nUnique);
-}
-
-
-TEST(founders_reward_test, general) {
- SelectParams(CBaseChainParams::TESTNET);
-
- CChainParams params = Params();
-
- // Fourth testnet reward:
- // address = t2ENg7hHVqqs9JwU5cgjvSbxnT2a9USNfhy
- // script.ToString() = OP_HASH160 55d64928e69829d9376c776550b6cc710d427153 OP_EQUAL
- // HexStr(script) = a91455d64928e69829d9376c776550b6cc710d42715387
- EXPECT_EQ(HexStr(params.GetFoundersRewardScriptAtHeight(1)), "a914ef775f1f997f122a062fff1a2d7443abd1f9c64287");
- EXPECT_EQ(params.GetFoundersRewardAddressAtHeight(1), "t2UNzUUx8mWBCRYPRezvA363EYXyEpHokyi");
- EXPECT_EQ(HexStr(params.GetFoundersRewardScriptAtHeight(53126)), "a914ac67f4c072668138d88a86ff21b27207b283212f87");
- EXPECT_EQ(params.GetFoundersRewardAddressAtHeight(53126), "t2NGQjYMQhFndDHguvUw4wZdNdsssA6K7x2");
- EXPECT_EQ(HexStr(params.GetFoundersRewardScriptAtHeight(53127)), "a91455d64928e69829d9376c776550b6cc710d42715387");
- EXPECT_EQ(params.GetFoundersRewardAddressAtHeight(53127), "t2ENg7hHVqqs9JwU5cgjvSbxnT2a9USNfhy");
-
- int maxHeight = params.GetConsensus().GetLastFoundersRewardBlockHeight();
-
- // If the block height parameter is out of bounds, there is an assert.
- EXPECT_DEATH(params.GetFoundersRewardScriptAtHeight(0), "nHeight");
- EXPECT_DEATH(params.GetFoundersRewardScriptAtHeight(maxHeight+1), "nHeight");
- EXPECT_DEATH(params.GetFoundersRewardAddressAtHeight(0), "nHeight");
- EXPECT_DEATH(params.GetFoundersRewardAddressAtHeight(maxHeight+1), "nHeight");
-}
-
-
-#define NUM_MAINNET_FOUNDER_ADDRESSES 48
-
-TEST(founders_reward_test, mainnet) {
- SelectParams(CBaseChainParams::MAIN);
- checkNumberOfUniqueAddresses(NUM_MAINNET_FOUNDER_ADDRESSES);
-}
-
-
-#define NUM_TESTNET_FOUNDER_ADDRESSES 48
-
-TEST(founders_reward_test, testnet) {
- SelectParams(CBaseChainParams::TESTNET);
- checkNumberOfUniqueAddresses(NUM_TESTNET_FOUNDER_ADDRESSES);
-}
-
-
-#define NUM_REGTEST_FOUNDER_ADDRESSES 1
-
-TEST(founders_reward_test, regtest) {
- SelectParams(CBaseChainParams::REGTEST);
- checkNumberOfUniqueAddresses(NUM_REGTEST_FOUNDER_ADDRESSES);
-}
-
-
-
-// Test that 10% founders reward is fully rewarded after the first halving and slow start shift.
-// On Mainnet, this would be 2,100,000 ZEC after 850,000 blocks (840,000 + 10,000).
-TEST(founders_reward_test, slow_start_subsidy) {
- SelectParams(CBaseChainParams::MAIN);
- CChainParams params = Params();
-
- int maxHeight = params.GetConsensus().GetLastFoundersRewardBlockHeight();
- CAmount totalSubsidy = 0;
- for (int nHeight = 1; nHeight <= maxHeight; nHeight++) {
- CAmount nSubsidy = GetBlockSubsidy(nHeight, params.GetConsensus()) / 5;
- totalSubsidy += nSubsidy;
- }
-
- ASSERT_TRUE(totalSubsidy == MAX_MONEY/10.0);
-}
-
-
-// For use with mainnet and testnet which each have 48 addresses.
-// Verify the number of rewards each individual address receives.
-void verifyNumberOfRewards() {
- CChainParams params = Params();
- int maxHeight = params.GetConsensus().GetLastFoundersRewardBlockHeight();
- std::multiset ms;
- for (int nHeight = 1; nHeight <= maxHeight; nHeight++) {
- ms.insert(params.GetFoundersRewardAddressAtHeight(nHeight));
- }
-
- ASSERT_TRUE(ms.count(params.GetFoundersRewardAddressAtIndex(0)) == 17708);
- for (int i = 1; i <= 46; i++) {
- ASSERT_TRUE(ms.count(params.GetFoundersRewardAddressAtIndex(i)) == 17709);
- }
- ASSERT_TRUE(ms.count(params.GetFoundersRewardAddressAtIndex(47)) == 17677);
-}
-
-// Verify the number of rewards going to each mainnet address
-TEST(founders_reward_test, per_address_reward_mainnet) {
- SelectParams(CBaseChainParams::MAIN);
- verifyNumberOfRewards();
-}
-
-// Verify the number of rewards going to each testnet address
-TEST(founders_reward_test, per_address_reward_testnet) {
- SelectParams(CBaseChainParams::TESTNET);
- verifyNumberOfRewards();
-}
-#endif
diff --git a/src/gtest/test_httprpc.cpp b/src/gtest/test_httprpc.cpp
index c630973fb..0a6e90748 100644
--- a/src/gtest/test_httprpc.cpp
+++ b/src/gtest/test_httprpc.cpp
@@ -1,3 +1,6 @@
+// Copyright (c) 2019-2020 The Hush developers
+// Distributed under the GPLv3 software license, see the accompanying
+// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include
#include
diff --git a/src/gtest/test_joinsplit.cpp b/src/gtest/test_joinsplit.cpp
deleted file mode 100644
index 8032fc972..000000000
--- a/src/gtest/test_joinsplit.cpp
+++ /dev/null
@@ -1,585 +0,0 @@
-#include
-
-#include "utilstrencodings.h"
-
-#include
-#include
-
-#include "zcash/prf.h"
-#include "util.h"
-#include "streams.h"
-#include "version.h"
-#include "serialize.h"
-#include "primitives/transaction.h"
-#include "zcash/JoinSplit.hpp"
-#include "zcash/Note.hpp"
-#include "zcash/NoteEncryption.hpp"
-#include "zcash/IncrementalMerkleTree.hpp"
-
-#include
-
-using namespace libzcash;
-
-extern ZCJoinSplit* params;
-
-// Make the Groth proof for a Sprout statement,
-// and store the result in a JSDescription object.
-JSDescription makeSproutProof(
- ZCJoinSplit& js,
- const std::array& inputs,
- const std::array