diff --git a/CMakeLists.txt b/CMakeLists.txt
index b9e259b3..4d89700a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.13)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
include(ABYCacheVariables)
+set(CMAKE_CXX_STANDARD 14)
project(ABY LANGUAGES C CXX)
# Write built executables and libraries to bin/ and lib/, respectively.
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
@@ -12,8 +13,10 @@ endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
endif()
+if(ANDROID)
+ add_definitions(-DANDROID)
+endif()
-include(AddENCRYPTO_utils)
add_subdirectory(src/abycore)
if(ABY_BUILD_EXE)
diff --git a/LICENSE b/LICENSE
index dbbe3558..0a041280 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,661 +1,165 @@
- GNU AFFERO GENERAL PUBLIC LICENSE
- Version 3, 19 November 2007
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
- Copyright (C) 2007 Free Software Foundation, Inc.
+ 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 GNU Affero General Public License is a free, copyleft license for
-software and other kinds of works, specifically designed to ensure
-cooperation with the community in the case of network server software.
-
- The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works. By contrast,
-our General Public Licenses are 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.
-
- 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.
-
- Developers that use our General Public Licenses protect your rights
-with two steps: (1) assert copyright on the software, and (2) offer
-you this License which gives you legal permission to copy, distribute
-and/or modify the software.
-
- A secondary benefit of defending all users' freedom is that
-improvements made in alternate versions of the program, if they
-receive widespread use, become available for other developers to
-incorporate. Many developers of free software are heartened and
-encouraged by the resulting cooperation. However, in the case of
-software used on network servers, this result may fail to come about.
-The GNU General Public License permits making a modified version and
-letting the public access it on a server without ever releasing its
-source code to the public.
-
- The GNU Affero General Public License is designed specifically to
-ensure that, in such cases, the modified source code becomes available
-to the community. It requires the operator of a network server to
-provide the source code of the modified version running there to the
-users of that server. Therefore, public use of a modified version, on
-a publicly accessible server, gives the public access to the source
-code of the modified version.
-
- An older license, called the Affero General Public License and
-published by Affero, was designed to accomplish similar goals. This is
-a different license, not a version of the Affero GPL, but Affero has
-released a new version of the Affero GPL which permits relicensing under
-this license.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- TERMS AND CONDITIONS
-
- 0. Definitions.
-
- "This License" refers to version 3 of the GNU Affero 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. Remote Network Interaction; Use with the GNU General Public License.
-
- Notwithstanding any other provision of this License, if you modify the
-Program, your modified version must prominently offer all users
-interacting with it remotely through a computer network (if your version
-supports such interaction) an opportunity to receive the Corresponding
-Source of your version by providing access to the Corresponding Source
-from a network server at no charge, through some standard or customary
-means of facilitating copying of software. This Corresponding Source
-shall include the Corresponding Source for any work covered by version 3
-of the GNU General Public License that is incorporated pursuant to the
-following paragraph.
-
- 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 GNU 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 work with which it is combined will remain governed by version
-3 of the GNU General Public License.
-
- 14. Revised Versions of this License.
-
- The Free Software Foundation may publish revised and/or new versions of
-the GNU Affero 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 GNU Affero 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
-GNU Affero 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 GNU Affero 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.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-
- Copyright (C)
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- 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. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
-
-Also add information on how to contact you by electronic and paper mail.
-
- If your software can interact with users remotely through a computer
-network, you should also make sure that it provides a way for users to
-get its source. For example, if your program is a web application, its
-interface could display a "Source" link that leads users to an archive
-of the code. There are many ways you could offer source, and different
-solutions will be better for different programs; see section 13 for the
-specific requirements.
-
- You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU AGPL, see
-.
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser 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
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/README.md b/README.md
index 15be7c8b..87f9cd6c 100644
--- a/README.md
+++ b/README.md
@@ -20,13 +20,13 @@ By *Daniel Demmler, Thomas Schneider and Michael Zohner* ([ENCRYPTO](http://www.
- [Build Options](#build-options)
- [Cleaning the Build Directory](#cleaning-the-build-directory)
- [Installation](#installation)
- - [Developer Guide and Documentation](#developer-guide-and-documentation)
+ - [Building for Android](#building-for-android)
+ - [Developer Guide and Documentation](#developer-guide-and-documentation)
- [ABY Applications](#aby-applications)
- [Included Example Applications](#included-example-applications)
- [Running Applications](#running-applications)
- [Creating and Building your own ABY Application](#creating-and-building-your-own-aby-application)
-
### Features
---
ABY efficiently combines secure computation schemes based on **Arithmetic sharing**, **Boolean sharing**, and **Yao’s garbled circuits** and makes available best-practice solutions in secure two-party computation.
@@ -182,12 +182,36 @@ make
make install
```
-
#### Developer Guide and Documentation
We provide an extensive [developer guide](https://www.informatik.tu-darmstadt.de/media/encrypto/encrypto_code/abydevguide.pdf) with many examples and explanations of how to use ABY.
Also, see the [online doxygen documentation of ABY](http://encryptogroup.github.io/ABY/docs/index.html) for further information and comments on the code.
+## Building for Android
+
+1. Clone the ABY git repository by running:
+ ```
+ git clone https://github.com/encryptogroup/ABY.git
+ ```
+
+2. Enter the Framework directory: `cd ABY/`
+
+3. Create and enter the build directory: `mkdir build && cd build`
+
+4. Use CMake to configure the build and setting android variables:
+ ```
+ cmake -DANDROID_NDK= -DANDROID_NATIVE_API_LEVEL= -DANDROID_ABI= ..
+ ```
+ where is a number between 16 and the latest Android API and is the target platform (one of armeabi-v7a, arm64-v8a, x86 and x86_64 respectively).
+
+ Please note that when using ABY with Android Studio that needs to be the path to the NDK used by Android Studio (often located at $HOME/Android/Sdk/ndk-bundle on Linux).
+
+
+5. Call `make` in the build directory.
+ You can find the build executables and libraries in the directories `bin/`
+ and `lib/`, respectively.
+
+6. Call 'make install' after the build has finished. This will install the libraries into the provided NDK.
### ABY Applications
---
@@ -234,6 +258,8 @@ Also, see the [online doxygen documentation of ABY](http://encryptogroup.github.
add_executable(my_application my_application.cpp)
target_link_libraries(my_application ABY::aby)
```
+* If you are using ABY for Android in Android Studio and you encounter the "library libc++_shared.so not found" error, make sure to pass '-DANDROID_STL=c++_shared' as an argument to cmake within the gradle script. Setting ANDROID_STL within the cmake script won't work.
+
* Otherwise, setup the include path such that the headers of ABY and its
dependencies can be found and link your application to the `libaby.a`
library and the other dependencies (see above).
diff --git a/cmake/ABYConfig.cmake.in b/cmake/ABYConfig.cmake.in
index 11e6b490..44181f59 100644
--- a/cmake/ABYConfig.cmake.in
+++ b/cmake/ABYConfig.cmake.in
@@ -4,10 +4,18 @@ include(CMakeFindDependencyMacro)
find_dependency(OTExtension)
find_dependency(ENCRYPTO_utils)
-find_dependency(MIRACL)
find_dependency(GMP)
find_dependency(Threads)
if(NOT TARGET ABY::aby)
include("${ABY_CMAKE_DIR}/ABYTargets.cmake")
endif()
+
+if(NOT "${ABY_LIBRARY_TYPE}" STREQUAL "STATIC" AND NOT "${ABY_LIBRARY_TYPE}" STREQUAL "SHARED")
+ set(ABY_LIBRARY_TYPE "@ABY_LIBRARY_TYPE@")
+endif()
+set(LIB_PREFIX "${CMAKE_${ABY_LIBRARY_TYPE}_LIBRARY_PREFIX}")
+set(LIB_SUFFIX "${CMAKE_${ABY_LIBRARY_TYPE}_LIBRARY_SUFFIX}")
+
+set(LIBRARIES_FULL_PATH "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}aby${LIB_SUFFIX}")
+set(LIB_NAME "ABY")
diff --git a/cmake/GMPConfig.cmake.in b/cmake/GMPConfig.cmake.in
new file mode 100644
index 00000000..d1ecc1ff
--- /dev/null
+++ b/cmake/GMPConfig.cmake.in
@@ -0,0 +1,31 @@
+if(NOT "${GMP_LIBRARY_TYPE}" STREQUAL "STATIC" AND NOT "${GMP_LIBRARY_TYPE}" STREQUAL "SHARED")
+ set(GMP_LIBRARY_TYPE "@GMP_LIBRARY_TYPE@")
+endif()
+set(LIB_PREFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_PREFIX}")
+set(LIB_SUFFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_SUFFIX}")
+
+find_path(GMP_INCLUDE_DIR gmp.h PATHS "@ANDROID_NDK@/@ABY_INSTALL_INCLUDE@")
+
+set(GMP_LIBRARY "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}gmp${LIB_SUFFIX}")
+if(EXISTS "${GMP_INCLUDE_DIR}" AND EXISTS "${GMP_LIBRARY}")
+ set(GMP_FOUND TRUE)
+else()
+ set(GMP_LIBRARY )
+ set(GMP_FOUND FALSE)
+endif()
+
+if(GMP_FOUND AND NOT TARGET GMP::GMP)
+ add_library(GMP::GMP UNKNOWN IMPORTED)
+ set_target_properties(GMP::GMP PROPERTIES
+ IMPORTED_LOCATION "${GMP_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${GMP_INCLUDE_DIR}"
+ )
+endif()
+
+mark_as_advanced(
+ GMP_INCLUDE_DIR
+ GMP_LIBRARY
+)
+
+set(LIBRARIES_FULL_PATH "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}gmp${LIB_SUFFIX}")
+set(LIB_NAME "GMP")
diff --git a/cmake/GMPXXConfig.cmake.in b/cmake/GMPXXConfig.cmake.in
new file mode 100644
index 00000000..a84a703c
--- /dev/null
+++ b/cmake/GMPXXConfig.cmake.in
@@ -0,0 +1,31 @@
+if(NOT "${GMP_LIBRARY_TYPE}" STREQUAL "STATIC" AND NOT "${GMP_LIBRARY_TYPE}" STREQUAL "SHARED")
+ set(GMP_LIBRARY_TYPE "@GMP_LIBRARY_TYPE@")
+endif()
+set(LIB_PREFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_PREFIX}")
+set(LIB_SUFFIX "${CMAKE_${GMP_LIBRARY_TYPE}_LIBRARY_SUFFIX}")
+
+find_path(GMPXX_INCLUDE_DIR gmpxx.h PATHS "@ANDROID_NDK@/@ABY_INSTALL_INCLUDE@")
+
+set(GMPXX_LIBRARY "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}gmpxx${LIB_SUFFIX}")
+if(EXISTS "${GMPXX_INCLUDE_DIR}" AND EXISTS "${GMPXX_LIBRARY}")
+ set(GMPXX_FOUND TRUE)
+else()
+ set(GMPXX_LIBRARY )
+ set(GMPXX_FOUND FALSE)
+endif()
+
+if(GMPXX_FOUND AND NOT TARGET GMP::GMPXX)
+ add_library(GMP::GMPXX UNKNOWN IMPORTED)
+ set_target_properties(GMP::GMPXX PROPERTIES
+ IMPORTED_LOCATION "${GMPXX_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${GMPXX_INCLUDE_DIR}"
+ )
+endif()
+
+mark_as_advanced(
+ GMPXX_INCLUDE_DIR
+ GMPXX_LIBRARY
+)
+
+set(LIBRARIES_FULL_PATH "@ANDROID_NDK@/@ABY_INSTALL_LIB@/${LIB_PREFIX}gmpxx${LIB_SUFFIX}")
+set(LIB_NAME "GMP")
diff --git a/cmake/ImportIntoAndroidStudio.cmake b/cmake/ImportIntoAndroidStudio.cmake
new file mode 100644
index 00000000..db7baaa4
--- /dev/null
+++ b/cmake/ImportIntoAndroidStudio.cmake
@@ -0,0 +1,15 @@
+
+function(import_into_android_studio IMPORT_LOCATION)
+ if(ANDROID AND "${${LIB_NAME}_LIBRARY_TYPE}" STREQUAL "SHARED" AND EXISTS "${IMPORT_LOCATION}")
+ foreach(lib IN LISTS LIBRARIES_FULL_PATH)
+ get_filename_component(lib_name "${lib}" NAME)
+ file(COPY "${lib}" DESTINATION "${IMPORT_LOCATION}")
+ endforeach()
+ endif()
+endfunction()
+
+if(NOT IMPORT_LOCATION)
+ import_into_android_studio("${PROJECT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}")
+else()
+ import_into_android_studio("${IMPORT_LOCATION}")
+endif()
diff --git a/cmake/Modules/ABYCacheVariables.cmake b/cmake/Modules/ABYCacheVariables.cmake
index e18833ce..85ae27af 100644
--- a/cmake/Modules/ABYCacheVariables.cmake
+++ b/cmake/Modules/ABYCacheVariables.cmake
@@ -1,6 +1,6 @@
option(ABY_BUILD_EXE "Build executables" OFF)
set(ABY_LIBRARY_TYPE "${ABY_LIBRARY_TYPE}" CACHE STRING
- "[STATIC | SHARED | MODULE] The type of library in which ABY will be built. Default: SHARED"
+ "[STATIC | SHARED | MODULE] The type of library in which ABY will be built. Default: STATIC"
)
set_property(CACHE ABY_LIBRARY_TYPE PROPERTY STRINGS "STATIC" "SHARED" "MODULE")
string(TOUPPER "${ABY_LIBRARY_TYPE}" ABY_LIBRARY_TYPE)
@@ -16,11 +16,12 @@ elseif(NOT "${ABY_LIBRARY_TYPE}" STREQUAL "STATIC" AND
set(ABY_LIBRARY_TYPE "SHARED")
endif()
-set(DEPENDENCY_DIR "${DEPENDENCY_DIR}" CACHE PATH
- "Path to directory, where dependencies will be downloaded."
-)
-if("${DEPENDENCY_DIR}" STREQUAL "" AND EXISTS "${PROJECT_SOURCE_DIR}/dependencies")
- set(DEPENDENCY_DIR "${PROJECT_SOURCE_DIR}/dependencies")
+set(DEPENDENCY_DIR "${DEPENDENCY_DIR}" CACHE PATH "Path to directory, where dependencies will be downloaded.")
+if(DEPENDENCY_DIR STREQUAL "")
+ if(NOT EXISTS "${CMAKE_SOURCE_DIR}/extern/dependencies")
+ file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/extern/dependencies")
+ endif()
+ set(DEPENDENCY_DIR "${CMAKE_SOURCE_DIR}/extern/dependencies")
endif()
# Set build type to `Release` if none was specified:
diff --git a/cmake/Modules/AndroidCacheVariables.cmake b/cmake/Modules/AndroidCacheVariables.cmake
index 74e36ed7..a584558f 100644
--- a/cmake/Modules/AndroidCacheVariables.cmake
+++ b/cmake/Modules/AndroidCacheVariables.cmake
@@ -38,7 +38,7 @@ endif()
if(ANDROID)
set(CMAKE_TOOLCHAIN_FILE ${ANDROID_TOOLCHAIN_FILE})
endif(ANDROID)
-if(ANDROID AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+if(ANDROID AND NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${ANDROID_NDK}"
CACHE PATH
"Default install directory for android builds."
diff --git a/cmake/Modules/ImportSharedLibs.cmake b/cmake/Modules/ImportSharedLibs.cmake
new file mode 100644
index 00000000..d5bf8c67
--- /dev/null
+++ b/cmake/Modules/ImportSharedLibs.cmake
@@ -0,0 +1,16 @@
+
+
+function(import_shared_libs)
+ set(DEFAULT_IMPORT_LOCATION "${PROJECT_SOURCE_DIR}/../jniLibs")
+ if(${ARGC} LESS 1)
+ set(IMPORT_LOCATION "${DEFAULT_IMPORT_LOCATION}")
+ else()
+ set(IMPORT_LOCATION "${ARGV0}")
+ endif()
+ if(NOT EXISTS "${IMPORT_LOCATION}")
+ file(MAKE_DIRECTORY "${IMPORT_LOCATION}")
+ endif()
+ foreach(lib IN LISTS SHARED_LIBS)
+ file(COPY "${lib}" DESTINATION "${IMPORT_LOCATION}")
+ endforeach()
+endfunction()
diff --git a/extern/boost-cmake b/extern/boost-cmake
deleted file mode 160000
index f0f64add..00000000
--- a/extern/boost-cmake
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit f0f64adda5ac1312549056dab502da55b9c45b7b
diff --git a/src/abycore/ABY_utils/ABYconstants.h b/src/abycore/ABY_utils/ABYconstants.h
index 202823a9..306ed2e2 100644
--- a/src/abycore/ABY_utils/ABYconstants.h
+++ b/src/abycore/ABY_utils/ABYconstants.h
@@ -2,17 +2,17 @@
\file ABYconstants.h
\author michael.zohner@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2017 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief File containing all ABY constants used throughout the source
*/
@@ -64,6 +64,10 @@
#define USE_MULTI_MUX_GATES
+// default directory containing ABY circuit files.
+// can also be passed to ABYParty constructor at runtime
+#define ABY_CIRCUIT_DIR "../../bin/circ/"
+
/**
\enum e_role
\brief Defines the role of the party or the source / target for certain operations (e.g., input/output)
@@ -208,7 +212,7 @@ typedef struct {
std::string opname;
} aby_ops_t;
-static std::string get_circuit_type_name(e_circuit c) {
+inline std::string get_circuit_type_name(e_circuit c) {
switch(c) {
case C_BOOLEAN:
return "BOOLEAN";
@@ -219,7 +223,7 @@ static std::string get_circuit_type_name(e_circuit c) {
}
}
-static std::string get_role_name(e_role r) {
+inline std::string get_role_name(e_role r) {
switch(r) {
case SERVER:
return "SERVER";
@@ -232,7 +236,7 @@ static std::string get_role_name(e_role r) {
}
}
-static std::string get_sharing_name(e_sharing s) {
+inline std::string get_sharing_name(e_sharing s) {
switch (s) {
case S_BOOL:
return "Bool";
@@ -249,7 +253,7 @@ static std::string get_sharing_name(e_sharing s) {
}
}
-static std::string get_gate_type_name(e_gatetype g) {
+inline std::string get_gate_type_name(e_gatetype g) {
switch (g) {
case G_LIN: return "Linear";
case G_NON_LIN: return "Non-Linear";
@@ -279,13 +283,13 @@ typedef enum op_t{
ADD, MUL, SUB, DIV, SIN, SQRT, EXP, EXP2, CMP, LN, LOG2, COS, SQR
}op_t;
-// Floating point operation cinfiguration.
+// Floating point operation cinfiguration.
typedef enum fp_op_setting{
ieee, no_status
}fp_op_setting;
-static std::string get_op_name(e_operation op) {
+inline std::string get_op_name(e_operation op) {
switch (op) {
case OP_XOR:
return "XOR";
diff --git a/src/abycore/ABY_utils/yaokey.h b/src/abycore/ABY_utils/yaokey.h
index 2b0e9da5..8535795c 100644
--- a/src/abycore/ABY_utils/yaokey.h
+++ b/src/abycore/ABY_utils/yaokey.h
@@ -2,17 +2,17 @@
\file yaokey.h
\author michael.zohner@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief YaoKey Implementation
*/
@@ -22,8 +22,8 @@
#include
/* an interface to operations on yaos garbled circuits keys for pre-defined symmetric security sizes */
-#define _MSB_UINT64_T 0x80000000000000L
-#define _TWO_MSB_UINT64_T 0xC0000000000000L
+#define _MSB_uint64_t 0x80000000000000L
+#define _TWO_MSB_uint64_t 0xC0000000000000L
#define _TWO_MSB_DOWNSHIFT 62
class YaoKey {
@@ -45,18 +45,18 @@ class YaoKeyST: public YaoKey {
}
;
void XOR(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]);
- (((UINT16_T*) (out))[4] = ((UINT16_T*) (ina))[4] ^ ((UINT16_T*) (inb))[4]);
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]);
+ (((uint16_t*) (out))[4] = ((uint16_t*) (ina))[4] ^ ((uint16_t*) (inb))[4]);
};
void XOR_DOUBLE_B(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<1);
- ((UINT16_T*) (out))[4] = ((UINT16_T*) (ina))[4] ^ ((((UINT16_T*) (inb))[4]<<1) ^ (!!(((UINT64_T*) (inb))[0] & _MSB_UINT64_T)));
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]<<1);
+ ((uint16_t*) (out))[4] = ((uint16_t*) (ina))[4] ^ ((((uint16_t*) (inb))[4]<<1) ^ (!!(((uint64_t*) (inb))[0] & _MSB_uint64_t)));
};
void XOR_QUAD_B(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<2);
- ((UINT16_T*) (out))[4] = ((UINT16_T*) (ina))[4] ^ ((((UINT16_T*) (inb))[4]<<2) ^ ((((UINT64_T*) (inb))[0] & _TWO_MSB_UINT64_T))>>_TWO_MSB_DOWNSHIFT);
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]<<2);
+ ((uint16_t*) (out))[4] = ((uint16_t*) (ina))[4] ^ ((((uint16_t*) (inb))[4]<<2) ^ ((((uint64_t*) (inb))[0] & _TWO_MSB_uint64_t))>>_TWO_MSB_DOWNSHIFT);
};
};
@@ -70,18 +70,18 @@ class YaoKeyMT: public YaoKey {
}
;
void XOR(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]);
- (((UINT32_T*) (out))[3] = ((UINT32_T*) (ina))[3] ^ ((UINT32_T*) (inb))[3]);
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]);
+ (((uint32_t*) (out))[3] = ((uint32_t*) (ina))[3] ^ ((uint32_t*) (inb))[3]);
};
void XOR_DOUBLE_B(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<1);
- (((UINT32_T*) (out))[3] = ((UINT32_T*) (ina))[3] ^ ((UINT32_T*) (inb))[3]<<1);
- (((UINT32_T*) (out))[3] = ((UINT32_T*) (ina))[3] ^ (((UINT32_T*) (inb))[3]<<1) ^ (!!(((UINT64_T*) (inb))[0] & _MSB_UINT64_T)));
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]<<1);
+ (((uint32_t*) (out))[3] = ((uint32_t*) (ina))[3] ^ ((uint32_t*) (inb))[3]<<1);
+ (((uint32_t*) (out))[3] = ((uint32_t*) (ina))[3] ^ (((uint32_t*) (inb))[3]<<1) ^ (!!(((uint64_t*) (inb))[0] & _MSB_uint64_t)));
};
void XOR_QUAD_B(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<2);
- //(((UINT32_T*) (out))[3] = ((UINT32_T*) (ina))[3] ^ ((UINT32_T*) (inb))[3]<<2);
- (((UINT32_T*) (out))[3] = ((UINT32_T*) (ina))[3] ^ (((UINT32_T*) (inb))[3]<<2) ^ ((((UINT64_T*) (inb))[0] & _TWO_MSB_UINT64_T))>>_TWO_MSB_DOWNSHIFT);
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]<<2);
+ //(((uint32_t*) (out))[3] = ((uint32_t*) (ina))[3] ^ ((uint32_t*) (inb))[3]<<2);
+ (((uint32_t*) (out))[3] = ((uint32_t*) (ina))[3] ^ (((uint32_t*) (inb))[3]<<2) ^ ((((uint64_t*) (inb))[0] & _TWO_MSB_uint64_t))>>_TWO_MSB_DOWNSHIFT);
};
};
class YaoKeyLT: public YaoKey {
@@ -91,16 +91,16 @@ class YaoKeyLT: public YaoKey {
}
;
void XOR(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]);
- (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ ((UINT64_T*) (inb))[1]);
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]);
+ (((uint64_t*) (out))[1] = ((uint64_t*) (ina))[1] ^ ((uint64_t*) (inb))[1]);
};
void XOR_DOUBLE_B(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<1);
- (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ (((UINT64_T*) (inb))[1]<<1) ^ (!!(((UINT64_T*) (inb))[0] & _MSB_UINT64_T)));
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]<<1);
+ (((uint64_t*) (out))[1] = ((uint64_t*) (ina))[1] ^ (((uint64_t*) (inb))[1]<<1) ^ (!!(((uint64_t*) (inb))[0] & _MSB_uint64_t)));
};
void XOR_QUAD_B(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<2);
- (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ (((UINT64_T*) (inb))[1]<<2) ^ ((((UINT64_T*) (inb))[0] & _TWO_MSB_UINT64_T))>>_TWO_MSB_DOWNSHIFT);
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]<<2);
+ (((uint64_t*) (out))[1] = ((uint64_t*) (ina))[1] ^ (((uint64_t*) (inb))[1]<<2) ^ ((((uint64_t*) (inb))[0] & _TWO_MSB_uint64_t))>>_TWO_MSB_DOWNSHIFT);
};
};
@@ -111,21 +111,21 @@ class YaoKeyXLT: public YaoKey {
}
;
void XOR(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]);
- (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ ((UINT64_T*) (inb))[1]);
- (((UINT64_T*) (out))[2] = ((UINT64_T*) (ina))[2] ^ ((UINT64_T*) (inb))[2]);
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]);
+ (((uint64_t*) (out))[1] = ((uint64_t*) (ina))[1] ^ ((uint64_t*) (inb))[1]);
+ (((uint64_t*) (out))[2] = ((uint64_t*) (ina))[2] ^ ((uint64_t*) (inb))[2]);
};
void XOR_DOUBLE_B(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<1);
- (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ (((UINT64_T*) (inb))[1]<<1) ^ (!!(((UINT64_T*) (inb))[0] & _MSB_UINT64_T)));
- (((UINT64_T*) (out))[2] = ((UINT64_T*) (ina))[2] ^ (((UINT64_T*) (inb))[2]<<1) ^ (!!(((UINT64_T*) (inb))[1] & _MSB_UINT64_T)));
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]<<1);
+ (((uint64_t*) (out))[1] = ((uint64_t*) (ina))[1] ^ (((uint64_t*) (inb))[1]<<1) ^ (!!(((uint64_t*) (inb))[0] & _MSB_uint64_t)));
+ (((uint64_t*) (out))[2] = ((uint64_t*) (ina))[2] ^ (((uint64_t*) (inb))[2]<<1) ^ (!!(((uint64_t*) (inb))[1] & _MSB_uint64_t)));
};
void XOR_QUAD_B(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<2);
- (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ (((UINT64_T*) (inb))[1]<<2) ^ ((((UINT64_T*) (inb))[0] & _TWO_MSB_UINT64_T))>>_TWO_MSB_DOWNSHIFT);
- (((UINT64_T*) (out))[2] = ((UINT64_T*) (ina))[2] ^ (((UINT64_T*) (inb))[2]<<2) ^ ((((UINT64_T*) (inb))[1] & _TWO_MSB_UINT64_T))>>_TWO_MSB_DOWNSHIFT);
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]<<2);
+ (((uint64_t*) (out))[1] = ((uint64_t*) (ina))[1] ^ (((uint64_t*) (inb))[1]<<2) ^ ((((uint64_t*) (inb))[0] & _TWO_MSB_uint64_t))>>_TWO_MSB_DOWNSHIFT);
+ (((uint64_t*) (out))[2] = ((uint64_t*) (ina))[2] ^ (((uint64_t*) (inb))[2]<<2) ^ ((((uint64_t*) (inb))[1] & _TWO_MSB_uint64_t))>>_TWO_MSB_DOWNSHIFT);
};
};
@@ -136,26 +136,26 @@ class YaoKeyXXLT: public YaoKey {
}
;
void XOR(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]);
- (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ ((UINT64_T*) (inb))[1]);
- (((UINT64_T*) (out))[2] = ((UINT64_T*) (ina))[2] ^ ((UINT64_T*) (inb))[2]);
- (((UINT64_T*) (out))[3] = ((UINT64_T*) (ina))[3] ^ ((UINT64_T*) (inb))[3]);
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]);
+ (((uint64_t*) (out))[1] = ((uint64_t*) (ina))[1] ^ ((uint64_t*) (inb))[1]);
+ (((uint64_t*) (out))[2] = ((uint64_t*) (ina))[2] ^ ((uint64_t*) (inb))[2]);
+ (((uint64_t*) (out))[3] = ((uint64_t*) (ina))[3] ^ ((uint64_t*) (inb))[3]);
};
void XOR_DOUBLE_B(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<1);
- (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ (((UINT64_T*) (inb))[1]<<1) ^ (!!(((UINT64_T*) (inb))[0] & _MSB_UINT64_T)));
- (((UINT64_T*) (out))[2] = ((UINT64_T*) (ina))[2] ^ (((UINT64_T*) (inb))[2]<<1) ^ (!!(((UINT64_T*) (inb))[1] & _MSB_UINT64_T)));
- (((UINT64_T*) (out))[3] = ((UINT64_T*) (ina))[3] ^ (((UINT64_T*) (inb))[3]<<1) ^ (!!(((UINT64_T*) (inb))[2] & _MSB_UINT64_T)));
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]<<1);
+ (((uint64_t*) (out))[1] = ((uint64_t*) (ina))[1] ^ (((uint64_t*) (inb))[1]<<1) ^ (!!(((uint64_t*) (inb))[0] & _MSB_uint64_t)));
+ (((uint64_t*) (out))[2] = ((uint64_t*) (ina))[2] ^ (((uint64_t*) (inb))[2]<<1) ^ (!!(((uint64_t*) (inb))[1] & _MSB_uint64_t)));
+ (((uint64_t*) (out))[3] = ((uint64_t*) (ina))[3] ^ (((uint64_t*) (inb))[3]<<1) ^ (!!(((uint64_t*) (inb))[2] & _MSB_uint64_t)));
};
void XOR_QUAD_B(BYTE* out, BYTE* ina, BYTE* inb) {
- (((UINT64_T*) (out))[0] = ((UINT64_T*) (ina))[0] ^ ((UINT64_T*) (inb))[0]<<2);
- (((UINT64_T*) (out))[1] = ((UINT64_T*) (ina))[1] ^ (((UINT64_T*) (inb))[1]<<2) ^ ((((UINT64_T*) (inb))[0] & _TWO_MSB_UINT64_T))>>_TWO_MSB_DOWNSHIFT);
- (((UINT64_T*) (out))[2] = ((UINT64_T*) (ina))[2] ^ (((UINT64_T*) (inb))[2]<<2) ^ ((((UINT64_T*) (inb))[1] & _TWO_MSB_UINT64_T))>>_TWO_MSB_DOWNSHIFT);
- (((UINT64_T*) (out))[3] = ((UINT64_T*) (ina))[3] ^ (((UINT64_T*) (inb))[3]<<2) ^ ((((UINT64_T*) (inb))[2] & _TWO_MSB_UINT64_T))>>_TWO_MSB_DOWNSHIFT);
+ (((uint64_t*) (out))[0] = ((uint64_t*) (ina))[0] ^ ((uint64_t*) (inb))[0]<<2);
+ (((uint64_t*) (out))[1] = ((uint64_t*) (ina))[1] ^ (((uint64_t*) (inb))[1]<<2) ^ ((((uint64_t*) (inb))[0] & _TWO_MSB_uint64_t))>>_TWO_MSB_DOWNSHIFT);
+ (((uint64_t*) (out))[2] = ((uint64_t*) (ina))[2] ^ (((uint64_t*) (inb))[2]<<2) ^ ((((uint64_t*) (inb))[1] & _TWO_MSB_uint64_t))>>_TWO_MSB_DOWNSHIFT);
+ (((uint64_t*) (out))[3] = ((uint64_t*) (ina))[3] ^ (((uint64_t*) (inb))[3]<<2) ^ ((((uint64_t*) (inb))[2] & _TWO_MSB_uint64_t))>>_TWO_MSB_DOWNSHIFT);
};
};
-static void InitYaoKey(YaoKey** key, int symbits) {
+inline void InitYaoKey(YaoKey** key, uint32_t symbits) {
if (symbits == ST.symbits)
*key = new YaoKeyST();
else if (symbits == MT.symbits)
diff --git a/src/abycore/CMakeLists.txt b/src/abycore/CMakeLists.txt
index aa709d5c..f157f8ff 100644
--- a/src/abycore/CMakeLists.txt
+++ b/src/abycore/CMakeLists.txt
@@ -2,11 +2,6 @@ cmake_minimum_required(VERSION 3.13)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
-include(AddGMP)
-include(AddBoost)
-include(AddOTExtension)
-find_package(Threads REQUIRED)
-
set(INSTALL_NAME ${PROJECT_NAME})
if(ANDROID)
@@ -19,16 +14,23 @@ if(ANDROID)
set(ABY_INSTALL_INCLUDE "${ABY_INSTALL_PREFIX}/include")
set(ABY_INSTALL_LIB "${ABY_INSTALL_PREFIX}/lib")
set(ABY_INSTALL_ARCHIVE "${ABY_INSTALL_PREFIX}/lib")
- set(ABY_INSTALL_CONFIG "sysroot/share/cmake")
+ set(ABY_INSTALL_CONFIG "usr/local")
else(ANDROID)
set(INSTALL_BOOST_DEPENDENCIES FALSE)
set(ABY_INSTALL_PREFIX "")
set(ABY_INSTALL_INCLUDE "include")
set(ABY_INSTALL_LIB "lib")
set(ABY_INSTALL_ARCHIVE "lib")
- set(ABY_INSTALL_CONFIG "share/cmake")
+ set(ABY_INSTALL_CONFIG "usr/local")
endif(ANDROID)
+
+include(AddGMP)
+include(AddBoost)
+include(AddENCRYPTO_utils)
+include(AddOTExtension)
+find_package(Threads REQUIRED)
+
add_library(aby ${ABY_LIBRARY_TYPE}
aby/abyparty.cpp
aby/abysetup.cpp
@@ -49,7 +51,6 @@ add_library(aby ${ABY_LIBRARY_TYPE}
)
add_library(ABY::aby ALIAS aby)
-target_compile_features(aby PUBLIC cxx_std_14)
#target_compile_options(aby PRIVATE "-Wall" "-Wextra" "-Weffc++")
target_compile_options(aby PRIVATE "-Wall" "-Wextra")
@@ -64,22 +65,21 @@ target_link_libraries(aby
PUBLIC ENCRYPTO_utils::encrypto_utils
PUBLIC GMP::GMP
PUBLIC Threads::Threads
- PRIVATE Boost::boost Boost::filesystem
+ PRIVATE Boost::filesystem
)
if(INSTALL_BOOST_DEPENDENCIES)
set_target_properties(Boost_filesystem PROPERTIES EXCLUDE_FROM_ALL 0)
- set(ABY_TARGETS aby Boost_filesystem)
+ set(ABY_TARGETS aby)
+ set(ABY_DEPENDENCIES Boost_filesystem Boost::boost)
else()
set(ABY_TARGETS aby)
endif()
-
-
include(InstallConfig)
install_config(ABY_INSTALL_LOCATION "${PROJECT_NAME}" "${ABY_INSTALL_CONFIG}")
-install(TARGETS ${ABY_TARGETS}
+install(TARGETS ${ABY_TARGETS} ${ABY_DEPENDENCIES}
EXPORT "${INSTALL_NAME}Targets"
ARCHIVE DESTINATION "${ABY_INSTALL_LIB}"
LIBRARY DESTINATION "${ABY_INSTALL_LIB}"
@@ -93,6 +93,9 @@ export(TARGETS ${ABY_TARGETS}
NAMESPACE "${INSTALL_NAME}::"
FILE "${INSTALL_NAME}Targets.cmake"
)
+export(TARGETS ${ABY_DEPENDENCIES}
+ APPEND FILE "${INSTALL_NAME}Targets.cmake"
+)
install(EXPORT "${INSTALL_NAME}Targets"
NAMESPACE "${INSTALL_NAME}::"
DESTINATION "${ABY_INSTALL_LOCATION}"
diff --git a/src/abycore/DGK/dgkparty.cpp b/src/abycore/DGK/dgkparty.cpp
index d14269f1..4c6e2477 100644
--- a/src/abycore/DGK/dgkparty.cpp
+++ b/src/abycore/DGK/dgkparty.cpp
@@ -2,41 +2,34 @@
\file dgkparty.cpp
\author daniel.demmler@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief DGKParty implementation
*/
#include "dgkparty.h"
-#include
-#include
-
-#define CHECKMT 0
-#define DGK_DEBUG 0
-#define NETDEBUG 0
-#define WINDOWSIZE 65536 //maximum size of a network packet in Byte
/**
* initializes a DGK_Party with the asymmetric security parameter and the sharelength and exchanges public keys.
* @param mode - 0 = generate new key; 1 = read key
*/
-DGKParty::DGKParty(UINT DGKbits, UINT sharelen, channel* chan, UINT readkey) {
+DGKParty::DGKParty(uint32_t DGKModulusBits, uint32_t shareBitLength, channel* chan, uint32_t readkey) {
- m_nShareLength = sharelen;
- m_nDGKbits = DGKbits;
- m_nBuflen = DGKbits / 8 + 1; //size of one ciphertext to send via network. DGK uses n bits == n/8 bytes
+ m_nShareBitLength = shareBitLength;
+ m_nDGKModulusBits = DGKModulusBits;
+ m_nBuflen = DGKModulusBits / 8 + 1; //size of one ciphertext to send via network. DGK uses n bits == n/8 bytes
-#if DEBUG
- cout << "Created party with " << DGKbits << " key bits and" << sharelen << " bit shares" << endl;
+#if DGK_DEBUG
+ std::cout << "Created party with " << DGKModulusBits << " key bits and " << shareBitLength << " bit shares" << std::endl;
#endif
if (readkey) {
@@ -53,14 +46,14 @@ DGKParty::DGKParty(UINT DGKbits, UINT sharelen, channel* chan, UINT readkey) {
* @param mode - 0 = generate new key; 1 = read key
* Public keys must be exchanged manually when using this constructor!
*/
-DGKParty::DGKParty(UINT DGKbits, UINT sharelen, UINT readkey) {
+DGKParty::DGKParty(uint32_t DGKModulusBits, uint32_t shareBitLength, uint32_t readkey) {
- m_nShareLength = sharelen;
- m_nDGKbits = DGKbits;
- m_nBuflen = DGKbits / 8 + 1; //size of one ciphertext to send via network. DGK uses n bits == n/8 bytes
+ m_nShareBitLength = shareBitLength;
+ m_nDGKModulusBits = DGKModulusBits;
+ m_nBuflen = DGKModulusBits / 8 + 1; //size of one ciphertext to send via network. DGK uses n bits == n/8 bytes
#if DGK_DEBUG
- cout << "Created party with " << DGKbits << " key bits and" << sharelen << " bit shares" << endl;
+ std::cout << "Created party with " << DGKModulusBits << " key bits and " << shareBitLength << " bit shares" << std::endl;
#endif
if (readkey) {
@@ -72,21 +65,21 @@ DGKParty::DGKParty(UINT DGKbits, UINT sharelen, UINT readkey) {
void DGKParty::readKey() {
#if DGK_DEBUG
- cout << "KeyGen" << endl;
+ std::cout << "Reading DGK key…" << std::endl;
#endif
- dgk_readkey(m_nDGKbits, m_nShareLength, &m_localpub, &m_prv);
+ dgk_readkey(m_nDGKModulusBits, m_nShareBitLength, &m_localpub, &m_prv);
#if DGK_DEBUG
- cout << "key read." << endl;
+ std::cout << "key read." << std::endl;
#endif
}
void DGKParty::generateKey() {
-#if DEBUG
- cout << "KeyGen" << endl;
+#if DGK_DEBUG
+ std::cout << "Generating DKG key…" << std::endl;
#endif
- dgk_keygen(m_nDGKbits, m_nShareLength, &m_localpub, &m_prv);
-#if DEBUG
- cout << "key generated." << endl;
+ dgk_keygen(m_nDGKModulusBits, m_nShareBitLength, &m_localpub, &m_prv);
+#if DGK_DEBUG
+ std::cout << "key generated." << std::endl;
#endif
}
@@ -95,28 +88,27 @@ void DGKParty::generateKey() {
*/
DGKParty::~DGKParty() {
#if DGK_DEBUG
- cout << "Deleting DGKParty..." << endl;
+ std::cout << "Deleting DGKParty…" << std::endl;
#endif
dgk_freeprvkey(m_prv);
dgk_freepubkey(m_localpub);
dgk_freepubkey(m_remotepub);
-
}
/**
- * inputs pre-allocates byte buffers for aMT calculation.
- * numMTs must be the total number of MTs and divisible by 2
+ * inputs: pre-allocates byte buffers for aMT calculation.
+ * numMTs is the total number of MTs
*/
-void DGKParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE * bB1, BYTE * bC1, UINT numMTs, channel* chan) {
+void DGKParty::computeArithmeticMTs(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE * bB1, BYTE * bC1, uint32_t numMTs, channel* chan) {
struct timespec start, end;
- numMTs = numMTs / 2; // We can be both sender and receiver at the same time.
+ numMTs = ceil_divide(numMTs, 2); // We can be both sender and receiver at the same time.
- UINT shareBytes = m_nShareLength / 8;
- UINT offset = 0;
+ uint32_t shareBytes = m_nShareBitLength / 8;
+ uint32_t offset = 0;
#if DGK_DEBUG
- cout << "dgkbits: " << m_nDGKbits << " sharelen: " << m_nShareLength << endl;
+ std::cout << "DGKModulusBits: " << m_nDGKModulusBits << " shareBitLength: " << m_nShareBitLength << std::endl;
#endif
mpz_t r, x, y, z;
@@ -132,7 +124,7 @@ void DGKParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
mpz_t b1[numMTs];
mpz_t c1[numMTs];
- for (UINT i = 0; i < numMTs; i++) {
+ for (uint32_t i = 0; i < numMTs; i++) {
mpz_inits(a[i], b[i], c[i], a1[i], b1[i], c1[i], NULL);
}
@@ -144,7 +136,7 @@ void DGKParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
clock_gettime(CLOCK_MONOTONIC, &start);
// read server a,b shares and encrypt them into buffer
- for (UINT i = 0; i < numMTs; i++) {
+ for (uint32_t i = 0; i < numMTs; i++) {
mpz_import(x, 1, 1, shareBytes, 0, 0, bA + i * shareBytes);
mpz_import(y, 1, 1, shareBytes, 0, 0, bB + i * shareBytes);
@@ -156,7 +148,7 @@ void DGKParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
}
// send & receive encrypted values
- int window = WINDOWSIZE;
+ int window = DGK_WINDOWSIZE;
int tosend = m_nBuflen * numMTs;
offset = 0;
@@ -180,7 +172,7 @@ void DGKParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
offset = 0;
//read shares from client byte arrays
- for (UINT j = 0; j < numMTs; j++) {
+ for (uint32_t j = 0; j < numMTs; j++) {
mpz_import(a1[j], 1, 1, shareBytes, 0, 0, bA1 + offset);
mpz_import(b1[j], 1, 1, shareBytes, 0, 0, bB1 + offset);
@@ -190,7 +182,7 @@ void DGKParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
dbpowmod(c1[j], x, b1[j], y, a1[j], m_remotepub->n);
// pick random r for masking
- aby_prng(x, 2 * m_nShareLength + 1);
+ aby_prng(x, 2 * m_nShareBitLength + 1);
dgk_encrypt_fb(y, m_remotepub, x);
@@ -201,7 +193,7 @@ void DGKParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
mpz_mul(c1[j], a1[j], b1[j]); //c = a * b
mpz_sub(c1[j], c1[j], x); // c = c - x
- mpz_mod_2exp(c1[j], c1[j], m_nShareLength); // c = c mod 2^shareLength
+ mpz_mod_2exp(c1[j], c1[j], m_nShareBitLength); // c = c mod 2^shareLength
mpz_export(bC1 + offset, NULL, 1, shareBytes, 0, 0, c1[j]);
@@ -211,7 +203,7 @@ void DGKParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
// ----------------############# ###############-----------------------
// all packets packed. exchange these packets
- window = WINDOWSIZE;
+ window = DGK_WINDOWSIZE;
tosend = m_nBuflen * numMTs;
offset = 0;
@@ -229,7 +221,7 @@ void DGKParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
offset = 0;
- for (UINT i = 0; i < numMTs; i++) {
+ for (uint32_t i = 0; i < numMTs; i++) {
mpz_import(r, m_nBuflen, -1, 1, 1, 0, zbuf + i * m_nBuflen);
dgk_decrypt(r, m_localpub, m_prv, r);
@@ -237,16 +229,17 @@ void DGKParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
mpz_import(a[i], 1, 1, shareBytes, 0, 0, bA + offset);
mpz_import(b[i], 1, 1, shareBytes, 0, 0, bB + offset);
- mpz_mod_2exp(c[i], r, m_nShareLength); // c = x mod 2^shareLength == read the share from least significant bits
+ mpz_mod_2exp(c[i], r, m_nShareBitLength); // c = x mod 2^shareLength == read the share from least significant bits
mpz_addmul(c[i], a[i], b[i]); //c = a*b + c
- mpz_mod_2exp(c[i], c[i], m_nShareLength); // c = c mod 2^shareLength
+ mpz_mod_2exp(c[i], c[i], m_nShareBitLength); // c = c mod 2^shareLength
mpz_export(bC + offset, NULL, 1, shareBytes, 0, 0, c[i]);
offset += shareBytes;
}
-#if CHECKMT
- cout << "Checking MT validity with values from other party:" << endl;
+#if DGK_CHECKMT
+ //TODO: This overwrites generated MTs and should be put in a separate function.
+ std::cout << "Checking MT validity with values from other party:" << std::endl;
mpz_t ai, bi, ci, ai1, bi1, ci1, ta, tb;
mpz_inits(ai, bi, ci, ai1, bi1, ci1, ta, tb, NULL);
@@ -258,7 +251,7 @@ void DGKParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
chan->send(bC, numMTs * shareBytes);
chan->blocking_receive(bC, numMTs * shareBytes);
- for (UINT i = 0; i < numMTs; i++) {
+ for (uint32_t i = 0; i < numMTs; i++) {
mpz_import(ai, 1, 1, shareBytes, 0, 0, bA + i * shareBytes);
mpz_import(bi, 1, 1, shareBytes, 0, 0, bB + i * shareBytes);
@@ -272,25 +265,27 @@ void DGKParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
mpz_add(tb, bi, bi1);
mpz_mul(ta, ta, tb);
mpz_add(tb, ci, ci1);
- mpz_mod_2exp(ta, ta, m_nShareLength);
- mpz_mod_2exp(tb, tb, m_nShareLength);
+ mpz_mod_2exp(ta, ta, m_nShareBitLength);
+ mpz_mod_2exp(tb, tb, m_nShareBitLength);
if (mpz_cmp(ta, tb) == 0) {
- cout << "MT is fine - i:" << i << "| " << ai << " " << bi << " " << ci << " . " << ai1 << " " << bi1 << " " << ci1 << endl;
+ std::cout << "MT is fine - i:" << i << "| " << ai << " " << bi << " " << ci << " . " << ai1 << " " << bi1 << " " << ci1 << std::endl;
} else {
- cout << "Error in MT - i:" << i << "| " << ai << " " << bi << " " << ci << " . " << ai1 << " " << bi1 << " " << ci1 << endl;
+ std::cout << "Error in MT - i:" << i << "| " << ai << " " << bi << " " << ci << " . " << ai1 << " " << bi1 << " " << ci1 << std::endl;
}
-
- //cout << (mpz_cmp(c1[i], a1[i]) == 0 ? "MT is fine." : "Error in MT!") << endl;
+ //cout << (mpz_cmp(c1[i], a1[i]) == 0 ? "MT is fine." : "Error in MT!") << std::endl;
}
mpz_clears(ai, bi, ci, ai1, bi1, ci1, ta, tb, NULL);
#endif
clock_gettime(CLOCK_MONOTONIC, &end);
+
+#if DGK_BENCH
printf("generating 2x %u MTs took %f\n", numMTs, getMillies(start, end));
+#endif
//clean up after ourselves
- for (UINT i = 0; i < numMTs; i++) {
+ for (uint32_t i = 0; i < numMTs; i++) {
mpz_clears(a[i], b[i], c[i], a1[i], b1[i], c1[i], NULL);
}
@@ -318,17 +313,17 @@ void DGKParty::keyExchange(channel* chan) {
receivempz_t(g, chan); //g
receivempz_t(h, chan); //h
- dgk_complete_pubkey(m_nDGKbits, m_nShareLength, &m_remotepub, n, g, h);
+ dgk_complete_pubkey(m_nDGKModulusBits, m_nShareBitLength, &m_remotepub, n, g, h);
// pre calculate table for fixed-base exponentiation for client
- fbpowmod_init_g(m_remotepub->g, m_remotepub->n, 2 * m_nShareLength + 2);
+ fbpowmod_init_g(m_remotepub->g, m_remotepub->n, 2 * m_nShareBitLength + 2);
fbpowmod_init_h(m_remotepub->h, m_remotepub->n, 400); // 2.5 * t = 2.5 * 160 = 400 bit
//free a and b
mpz_clears(n, g, h, NULL);
-#if DEBUG
- cout << "KX done. This pubkey: " << m_localpub->n << " remotekey: " << m_remotepub->n << endl;
+#if DGK_DEBUG
+ std::cout << "KX done. Local pubkey: " << m_localpub->n << " remote pubkey: " << m_remotepub->n << std::endl;
#endif
}
@@ -338,12 +333,12 @@ void DGKParty::keyExchange(channel* chan) {
void DGKParty::sendmpz_t(mpz_t t, channel* chan, BYTE * buf) {
//clear upper bytes of the buffer, so tailing bytes are zero
- for (int i = mpz_sizeinbase(t, 256); i < m_nBuflen; i++) {
+ for (uint32_t i = mpz_sizeinbase(t, 256); i < m_nBuflen; i++) {
*(buf + i) = 0;
}
-#if NETDEBUG
- cout << mpz_sizeinbase(t, 256) << " vs. " << m_nBuflen << endl;
+#if DGK_NETDEBUG
+ std::cout << mpz_sizeinbase(t, 256) << " vs. " << m_nBuflen << std::endl;
#endif
mpz_export(buf, NULL, -1, 1, 1, 0, t);
@@ -351,13 +346,13 @@ void DGKParty::sendmpz_t(mpz_t t, channel* chan, BYTE * buf) {
//send bytes of t
chan->send(buf, (uint64_t) m_nBuflen);
-#if NETDEBUG
- cout << endl << "SEND" << endl;
- for (int i = 0; i < m_nBuflen; i++) {
+#if DGK_NETDEBUG
+ std::cout << std::endl << "SEND" << std::endl;
+ for (uint32_t i = 0; i < m_nBuflen; i++) {
printf("%02x.", *(buf + i));
}
- cout << endl << "sent: " << t << " with len: " << m_nBuflen << " should have been " << mpz_sizeinbase(t, 256) << endl;
+ std::cout << std::endl << "sent: " << t << " with len: " << m_nBuflen << " should have been " << mpz_sizeinbase(t, 256) << std::endl;
#endif
}
@@ -368,13 +363,13 @@ void DGKParty::receivempz_t(mpz_t t, channel* chan, BYTE * buf) {
chan->blocking_receive(buf, (uint64_t) m_nBuflen);
mpz_import(t, m_nBuflen, -1, 1, 1, 0, buf);
-#if NETDEBUG
- cout << endl << "RECEIVE" << endl;
- for (int i = 0; i < m_nBuflen; i++) {
+#if DGK_NETDEBUG
+ std::cout << std::endl << "RECEIVE" << std::endl;
+ for (uint32_t i = 0; i < m_nBuflen; i++) {
printf("%02x.", *(buf + i));
}
- cout << "received: " << t << " with len: " << m_nBuflen << endl;
+ std::cout << "received: " << t << " with len: " << m_nBuflen << std::endl;
#endif
}
@@ -393,8 +388,8 @@ void DGKParty::sendmpz_t(mpz_t t, channel* chan) {
chan->send(arr, (uint64_t) bytelen);
free(arr);
-#if NETDEBUG
- cout << "sent: " << t << " with len: " << bytelen << endl;
+#if DGK_NETDEBUG
+ std::cout << "sent: " << t << " with len: " << bytelen << std::endl;
#endif
}
@@ -413,25 +408,25 @@ void DGKParty::receivempz_t(mpz_t t, channel* chan) {
mpz_import(t, bytelen, 1, 1, 1, 0, arr);
free(arr);
-#if NETDEBUG
- cout << "received: " << t << " with len: " << bytelen << endl;
+#if DGK_NETDEBUG
+ std::cout << "received: " << t << " with len: " << bytelen << std::endl;
#endif
}
#if DEBUG
-void DGKParty::printBuf(BYTE* b, UINT len) {
- for (UINT i = 0; i < len; i++) {
+void DGKParty::printBuf(BYTE* b, uint32_t len) {
+ for (uint32_t i = 0; i < len; i++) {
printf("%02x.", *(b + i));
}
- cout << endl;
+ std::cout << std::endl;
}
#endif
/**
* reads a new key from disk (to be used when parameters change)
*/
-void DGKParty::loadNewKey(UINT DGKbits, UINT sharelen) {
- m_nDGKbits = DGKbits;
- m_nShareLength = sharelen;
- dgk_readkey(m_nDGKbits, m_nShareLength, &m_localpub, &m_prv);
+void DGKParty::loadNewKey(uint32_t DGKModulusBits, uint32_t shareBitLength) {
+ m_nDGKModulusBits = DGKModulusBits;
+ m_nShareBitLength = shareBitLength;
+ dgk_readkey(m_nDGKModulusBits, m_nShareBitLength, &m_localpub, &m_prv);
}
diff --git a/src/abycore/DGK/dgkparty.h b/src/abycore/DGK/dgkparty.h
index 9634af12..a749a391 100644
--- a/src/abycore/DGK/dgkparty.h
+++ b/src/abycore/DGK/dgkparty.h
@@ -2,23 +2,29 @@
\file dgkparty.h
\author daniel.demmler@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief DGKParty
*/
#ifndef __DGKPARTY_H__
#define __DGKPARTY_H__
+#define DGK_CHECKMT 0
+#define DGK_DEBUG 0
+#define DGK_BENCH 0
+#define DGK_NETDEBUG 0
+#define DGK_WINDOWSIZE 65536 //maximum size of a network packet in Byte
+
#include
#include
#include
@@ -26,34 +32,39 @@
#include
#include
#include
+#include
+#include
+#if DGK_DEBUG || DGK_BENCH
+#include
+#endif
class DGKParty {
public:
- DGKParty(UINT DGKbits, UINT sharelen, UINT readkey);
- DGKParty(UINT DGKbits, UINT sharelen, channel* chan, UINT readkey);
+ DGKParty(uint32_t DGKModulusBits, uint32_t shareBitLength, uint32_t readkey);
+ DGKParty(uint32_t DGKModulusBits, uint32_t shareBitLength, channel* chan, uint32_t readkey);
~DGKParty();
void keyExchange(channel* chan);
- void preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE * bB1, BYTE * bC1, UINT numMTs, channel* chan);
+ void computeArithmeticMTs(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE * bB1, BYTE * bC1, uint32_t numMTs, channel* chan);
void readKey();
void generateKey();
- void loadNewKey(UINT DGKbits, UINT sharelen);
+ void loadNewKey(uint32_t DGKModulusBits, uint32_t shareBitLength);
private:
- USHORT m_nNumMTThreads;
- USHORT m_nShareLength;
- UINT m_nDGKbits;
- UINT m_nBuflen;
+ uint16_t m_nNumMTThreads;
+ uint16_t m_nShareBitLength;
+ uint32_t m_nDGKModulusBits;
+ uint32_t m_nBuflen;
// Crypto and GMP PRNG
dgk_pubkey_t *m_localpub, *m_remotepub;
dgk_prvkey_t *m_prv;
- void benchPreCompPacking1(channel* chan, BYTE * buf, UINT packlen, UINT numshares, mpz_t * a, mpz_t * b, mpz_t * c, mpz_t * a1, mpz_t * b1, mpz_t * c1, mpz_t r, mpz_t x,
+ void benchPreCompPacking1(channel* chan, BYTE * buf, uint32_t packlen, uint32_t numshares, mpz_t * a, mpz_t * b, mpz_t * c, mpz_t * a1, mpz_t * b1, mpz_t * c1, mpz_t r, mpz_t x,
mpz_t y, mpz_t z);
void sendmpz_t(mpz_t t, channel* chan, BYTE * buf);
@@ -62,8 +73,7 @@ class DGKParty {
void sendmpz_t(mpz_t t, channel* chan);
void receivempz_t(mpz_t t, channel* chan);
- void printBuf(BYTE* b, UINT l);
-
+ void printBuf(BYTE* b, uint32_t l);
};
#endif //__DGK_PARTY_H__
diff --git a/src/abycore/DJN/djnparty.cpp b/src/abycore/DJN/djnparty.cpp
index bf852901..aa66dedf 100644
--- a/src/abycore/DJN/djnparty.cpp
+++ b/src/abycore/DJN/djnparty.cpp
@@ -2,57 +2,49 @@
\file djnparty.cpp
\author daniel.demmler@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief Implementation of DJNParty class
*/
#include "djnparty.h"
-#include
-#include
-
-#define CHECKMT 0
-#define DJN_DEBUG 0
-#define NETDEBUG 0
-#define NETDEBUG2 0
-#define WINDOWSIZE 65536//maximum size of a network packet in Byte
/**
- * initializes a DJN_Party with the asymmetric security parameter and the sharelength.
+ * initializes a DJN_Party with the asymmetric security parameter and the shareBitLength.
* Generates DJN key.
* Key Exchange must be done manually after calling this constructor!
*/
-DJNParty::DJNParty(UINT DJNbits, UINT sharelen, channel* chan) {
+DJNParty::DJNParty(uint32_t DJNModulusBits, uint32_t shareBitLength, channel* chan) {
- m_nShareLength = sharelen;
- m_nDJNbits = DJNbits;
- m_nBuflen = DJNbits / 4 + 1;
+ m_nShareBitLength = shareBitLength;
+ m_nDJNModulusBits = DJNModulusBits;
+ m_nBuflen = DJNModulusBits / 4 + 1;
#if DJN_DEBUG
- std::cout << "(sock) Created party with " << DJNbits << " bits and" << m_nBuflen << std::endl;
+ std::cout << "(sock) Created party with " << DJNModulusBits << " bits and" << m_nBuflen << std::endl;
#endif
keyGen();
keyExchange(chan);
}
-DJNParty::DJNParty(UINT DJNbits, UINT sharelen) {
+DJNParty::DJNParty(uint32_t DJNModulusBits, uint32_t shareBitLength) {
- m_nShareLength = sharelen;
- m_nDJNbits = DJNbits;
- m_nBuflen = DJNbits / 4 + 1;
+ m_nShareBitLength = shareBitLength;
+ m_nDJNModulusBits = DJNModulusBits;
+ m_nBuflen = DJNModulusBits / 4 + 1;
#if DJN_DEBUG
- std::cout << "(nosock) Created party with " << DJNbits << " bits and" << m_nBuflen << std::endl;
+ std::cout << "(nosock) Created party with " << DJNModulusBits << " bits and" << m_nBuflen << std::endl;
#endif
keyGen();
@@ -62,11 +54,11 @@ void DJNParty::keyGen() {
#if DJN_DEBUG
std::cout << "KG" << std::endl;
#endif
- djn_keygen(m_nDJNbits, &m_localpub, &m_prv);
+ djn_keygen(m_nDJNModulusBits, &m_localpub, &m_prv);
}
-void DJNParty::setSharelLength(UINT sharelen) {
- m_nShareLength = sharelen;
+void DJNParty::setShareBitLength(uint32_t shareBitLength) {
+ m_nShareBitLength = shareBitLength;
}
/**
@@ -79,28 +71,26 @@ DJNParty::~DJNParty() {
djn_freeprvkey(m_prv);
djn_freepubkey(m_localpub);
djn_freepubkey(m_remotepub);
-
}
/**
- * inputs pre-allocates byte buffers for aMT calculation.
- * numMTs must be the total number of MTs and divisible by 2
+ * inputs: pre-allocates byte buffers for aMT calculation.
+ * numMTs is total number of MTs
*/
-void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE * bB1, BYTE * bC1, UINT numMTs, channel* chan) {
+void DJNParty::computeArithmeticMTs(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE * bB1, BYTE * bC1, uint32_t numMTs, channel* chan) {
struct timespec start, end;
+ numMTs = ceil_divide(numMTs, 2); // We can be both sender and receiver at the same time.
- numMTs = numMTs / 2; // We can be both sender and receiver at the same time.
-
- UINT maxShareLen = 2 * m_nShareLength + 41; // length of one share in the packet, sigma = 40
- UINT packshares = m_nDJNbits / maxShareLen; // number of shares in one packet
- UINT numpacks = (numMTs + packshares - 1) / packshares; // total number of packets to send in order to generate numMTs = CEIL(numMTs/2*numshares)
+ uint32_t maxShareBitLength = 2 * m_nShareBitLength + 41; // length of one share in the packet, sigma = 40
+ uint32_t packshares = m_nDJNModulusBits / maxShareBitLength; // number of shares in one packet
+ uint32_t numpacks = ceil_divide(numMTs, packshares); // total number of packets to send in order to generate numMTs
- UINT shareBytes = m_nShareLength / 8;
- UINT offset = 0;
- UINT limit = packshares; // upper bound for a package shares, used to handle non-full last packages / alignment
+ uint32_t shareBytes = m_nShareBitLength / 8;
+ uint32_t offset = 0;
+ uint32_t limit = packshares; // upper bound for a package shares, used to handle non-full last packages / alignment
#if DJN_DEBUG
- std::cout << "djnbits: " << m_nDJNbits << " sharelen: " << m_nShareLength << " packlen: " << maxShareLen << " numshares: " << packshares << " numpacks: " << numpacks << std::endl;
+ std::cout << "DJNModulusBits: " << m_nDJNModulusBits << " ShareBitLength: " << m_nShareBitLength << " packlen: " << maxShareBitLength << " numshares: " << packshares << " numpacks: " << numpacks << std::endl;
#endif
mpz_t r, x, y, z;
@@ -116,7 +106,7 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
mpz_t b1[packshares];
mpz_t c1[packshares];
- for (UINT i = 0; i < packshares; i++) {
+ for (uint32_t i = 0; i < packshares; i++) {
mpz_inits(a[i], b[i], c[i], a1[i], b1[i], c1[i], NULL);
}
@@ -128,7 +118,7 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
clock_gettime(CLOCK_MONOTONIC, &start);
// read server a,b shares and encrypt them into buffer
- for (UINT i = 0; i < numMTs; i++) {
+ for (uint32_t i = 0; i < numMTs; i++) {
mpz_import(x, 1, 1, shareBytes, 0, 0, bA + i * shareBytes);
mpz_import(y, 1, 1, shareBytes, 0, 0, bB + i * shareBytes);
@@ -140,7 +130,7 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
}
// send & receive encrypted values
- int window = WINDOWSIZE;
+ int window = DJN_WINDOWSIZE;
int tosend = m_nBuflen * numMTs;
offset = 0;
@@ -162,14 +152,14 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
// pack ALL the packets
offset = 0;
- for (UINT i = 0; i < numpacks; i++) {
+ for (uint32_t i = 0; i < numpacks; i++) {
if (i == numpacks - 1) {
limit = numMTs % packshares; // if last package, only fill buffers to requested size and discard remaining shares
}
//read shares from client byte arrays
- for (UINT j = 0; j < limit; j++) {
+ for (uint32_t j = 0; j < limit; j++) {
mpz_import(a1[j], 1, 1, shareBytes, 0, 0, bA1 + offset);
mpz_import(b1[j], 1, 1, shareBytes, 0, 0, bB1 + offset);
@@ -183,7 +173,7 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
// horner packing of shares into 1 ciphertext
mpz_set(z, c1[limit - 1]);
mpz_set_ui(y, 0);
- mpz_setbit(y, maxShareLen); // y = 2^shareLength, for shifting ciphertext
+ mpz_setbit(y, maxShareBitLength); // y = 2^ShareBitLength, for shifting ciphertext
for (int j = limit - 2; j >= 0; j--) {
mpz_powm(z, z, y, m_remotepub->n_squared);
@@ -206,14 +196,14 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
offset -= shareBytes * limit;
// calculate c shares for client part
- for (UINT j = 0; j < limit; j++) {
- mpz_mod_2exp(y, x, m_nShareLength); // y = r mod 2^shareLength == read the share from least significant bits
- mpz_div_2exp(x, x, maxShareLen); // r = r >> maxShareLen
+ for (uint32_t j = 0; j < limit; j++) {
+ mpz_mod_2exp(y, x, m_nShareBitLength); // y = r mod 2^ShareBitLength == read the share from least significant bits
+ mpz_div_2exp(x, x, maxShareBitLength); // r = r >> maxShareBitLength
mpz_mul(c1[j], a1[j], b1[j]); //c = a * b
mpz_sub(c1[j], c1[j], y); // c = c - y
- mpz_mod_2exp(c1[j], c1[j], m_nShareLength); // c = c mod 2^shareLength
+ mpz_mod_2exp(c1[j], c1[j], m_nShareBitLength); // c = c mod 2^ShareBitLength
mpz_export(bC1 + offset, NULL, 1, shareBytes, 0, 0, c1[j]);
offset += shareBytes;
@@ -223,7 +213,7 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
// ----------------############# ###############-----------------------
// all packets packed. exchange these packets
- window = WINDOWSIZE;
+ window = DJN_WINDOWSIZE;
tosend = m_nBuflen * numpacks;
offset = 0;
@@ -241,7 +231,7 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
limit = packshares;
offset = 0;
- for (UINT i = 0; i < numpacks; i++) {
+ for (uint32_t i = 0; i < numpacks; i++) {
if (i == numpacks - 1) {
limit = numMTs % packshares; // if last package, only fill buffers to requested size and discard remaining shares
@@ -251,20 +241,20 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
djn_decrypt(r, m_localpub, m_prv, r);
- for (UINT j = 0; j < limit; j++) {
+ for (uint32_t j = 0; j < limit; j++) {
mpz_import(a[j], 1, 1, shareBytes, 0, 0, bA + offset);
mpz_import(b[j], 1, 1, shareBytes, 0, 0, bB + offset);
- mpz_mod_2exp(c[j], r, m_nShareLength); // c = x mod 2^shareLength == read the share from least significant bits
- mpz_div_2exp(r, r, maxShareLen); // x = x >> maxShareLen
+ mpz_mod_2exp(c[j], r, m_nShareBitLength); // c = x mod 2^ShareBitLength == read the share from least significant bits
+ mpz_div_2exp(r, r, maxShareBitLength); // x = x >> maxShareBitLength
mpz_addmul(c[j], a[j], b[j]); //c = a*b + c
- mpz_mod_2exp(c[j], c[j], m_nShareLength); // c = c mod 2^shareLength
+ mpz_mod_2exp(c[j], c[j], m_nShareBitLength); // c = c mod 2^ShareBitLength
mpz_export(bC + offset, NULL, 1, shareBytes, 0, 0, c[j]);
offset += shareBytes;
}
}
-#if CHECKMT
+#if DJN_CHECKMT
std::cout << "Checking MT validity with values from other party:" << std::endl;
mpz_t ai, bi, ci, ai1, bi1, ci1, ta, tb;
@@ -277,7 +267,7 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
chan->send(bC, numMTs * shareBytes);
chan->blocking_receive(bC, numMTs * shareBytes);
- for (UINT i = 0; i < numMTs; i++) {
+ for (uint32_t i = 0; i < numMTs; i++) {
mpz_import(ai, 1, 1, shareBytes, 0, 0, bA + i * shareBytes);
mpz_import(bi, 1, 1, shareBytes, 0, 0, bB + i * shareBytes);
@@ -291,8 +281,8 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
mpz_add(tb, bi, bi1);
mpz_mul(ta, ta, tb);
mpz_add(tb, ci, ci1);
- mpz_mod_2exp(ta, ta, m_nShareLength);
- mpz_mod_2exp(tb, tb, m_nShareLength);
+ mpz_mod_2exp(ta, ta, m_nShareBitLength);
+ mpz_mod_2exp(tb, tb, m_nShareBitLength);
if (mpz_cmp(ta, tb) == 0) {
std::cout << "MT is fine - i:" << i << "| " << ai << " " << bi << " " << ci << " . " << ai1 << " " << bi1 << " " << ci1 << std::endl;
@@ -306,10 +296,13 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
#endif
clock_gettime(CLOCK_MONOTONIC, &end);
+
+#if DJN_BENCH
printf("generating 2x %u MTs took %f\n", numMTs, getMillies(start, end));
+#endif
//clean up after ourselves
- for (UINT i = 0; i < packshares; i++) {
+ for (uint32_t i = 0; i < packshares; i++) {
mpz_clears(a[i], b[i], c[i], a1[i], b1[i], c1[i], NULL);
}
@@ -325,13 +318,13 @@ void DJNParty::preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE *
* a,b,c are server shares. a1,b1,c1 are client shares.
* All mpz_t values must be pre-initialized.
*/
-void DJNParty::benchPreCompPacking1(channel* chan, BYTE * buf, UINT packlen, UINT numshares, mpz_t * a, mpz_t * b, mpz_t * c, mpz_t * a1, mpz_t * b1, mpz_t * c1, mpz_t r, mpz_t x,
+void DJNParty::benchPreCompPacking1(channel* chan, BYTE * buf, uint32_t packlen, uint32_t numshares, mpz_t * a, mpz_t * b, mpz_t * a1, mpz_t * b1, mpz_t * c1, mpz_t r, mpz_t x,
mpz_t y, mpz_t z) {
#if DJN_DEBUG
std::cout << "packlen: " << packlen << " numshares: " << numshares << std::endl;
#endif
- for (UINT i = 0; i < numshares; i++) {
+ for (uint32_t i = 0; i < numshares; i++) {
djn_encrypt_crt(r, m_localpub, m_prv, a[i]);
mpz_export(buf + 2 * i * m_nBuflen, NULL, -1, 1, 1, 0, r);
djn_encrypt_crt(r, m_localpub, m_prv, b[i]);
@@ -340,23 +333,23 @@ void DJNParty::benchPreCompPacking1(channel* chan, BYTE * buf, UINT packlen, UIN
chan->send(buf, (uint64_t) m_nBuflen * numshares * 2);
-#if NETDEBUG
+#if DJN_NETDEBUG
std::cout << " SEND " << std::endl;
- for (UINT xx=0; xx < m_nBuflen * numshares * 2; xx++) {
+ for (uint32_t xx=0; xx < m_nBuflen * numshares * 2; xx++) {
printf("%02x.", *(buf + xx));
}
#endif
chan->blocking_receive(buf, (uint64_t) m_nBuflen * numshares * 2);
-#if NETDEBUG
+#if DJN_NETDEBUG
std::cout << " RECV " << std::endl;
- for (UINT xx=0; xx < m_nBuflen * numshares * 2; xx++) {
+ for (uint32_t xx=0; xx < m_nBuflen * numshares * 2; xx++) {
printf("%02x.", *(buf + xx));
}
#endif
- for (UINT i = 0; i < numshares; i++) {
+ for (uint32_t i = 0; i < numshares; i++) {
mpz_import(x, m_nBuflen, -1, 1, 1, 0, buf + 2 * i * m_nBuflen);
mpz_import(y, m_nBuflen, -1, 1, 1, 0, buf + (2 * i + 1) * m_nBuflen);
@@ -366,7 +359,7 @@ void DJNParty::benchPreCompPacking1(channel* chan, BYTE * buf, UINT packlen, UIN
// horner packing of shares into 1 ciphertext
mpz_set(z, c1[numshares - 1]);
mpz_set_ui(y, 0);
- mpz_setbit(y, packlen); // y = 2^shareLength, for shifting ciphertext
+ mpz_setbit(y, packlen); // y = 2^ShareBitLength, for shifting ciphertext
for (int i = numshares - 2; i >= 0; i--) {
mpz_powm(z, z, y, m_remotepub->n_squared);
@@ -384,14 +377,14 @@ void DJNParty::benchPreCompPacking1(channel* chan, BYTE * buf, UINT packlen, UIN
mpz_mod(z, z, m_remotepub->n_squared);
// calculate c shares for client part
- for (UINT i = 0; i < numshares; i++) {
- mpz_mod_2exp(y, x, m_nShareLength); // y = r mod 2^shareLength == read the share from least significant bits
+ for (uint32_t i = 0; i < numshares; i++) {
+ mpz_mod_2exp(y, x, m_nShareBitLength); // y = r mod 2^ShareBitLength == read the share from least significant bits
mpz_div_2exp(x, x, packlen); // r = r >> packlen
mpz_mul(c1[i], a1[i], b1[i]); //c = a * b
mpz_sub(c1[i], c1[i], y); // c = c - y
- mpz_mod_2exp(c1[i], c1[i], m_nShareLength); // c = c mod 2^shareLength
+ mpz_mod_2exp(c1[i], c1[i], m_nShareBitLength); // c = c mod 2^ShareBitLength
}
}
@@ -409,10 +402,10 @@ void DJNParty::keyExchange(channel* chan) {
mpz_inits(a, b, NULL);
receivempz_t(a, chan); //n
receivempz_t(b, chan); //h
- djn_complete_pubkey(m_nDJNbits, &m_remotepub, a, b);
+ djn_complete_pubkey(m_nDJNModulusBits, &m_remotepub, a, b);
// pre calculate table for fixed-base exponentiation for client
- fbpowmod_init_g(m_remotepub->h_s, m_remotepub->n_squared, 2 * m_nDJNbits);
+ fbpowmod_init_g(m_remotepub->h_s, m_remotepub->n_squared, 2 * m_nDJNModulusBits);
//free a and b
mpz_clears(a, b, NULL);
@@ -428,11 +421,11 @@ void DJNParty::keyExchange(channel* chan) {
void DJNParty::sendmpz_t(mpz_t t, channel* chan, BYTE * buf) {
//clear upper bytes of the buffer, so tailing bytes are zero
- for (int i = mpz_sizeinbase(t, 256); i < m_nBuflen; i++) {
+ for (uint32_t i = mpz_sizeinbase(t, 256); i < m_nBuflen; i++) {
*(buf + i) = 0;
}
-#if NETDEBUG2
+#if DJN_NETDEBUG2
std::cout << mpz_sizeinbase(t, 256) << " vs. " << m_nBuflen << std::endl;
#endif
@@ -441,9 +434,9 @@ void DJNParty::sendmpz_t(mpz_t t, channel* chan, BYTE * buf) {
//send Bytes of t
chan->send(buf, (uint64_t) m_nBuflen);
-#if NETDEBUG
+#if DJN_NETDEBUG
std::cout << std::endl << "SEND" << std::endl;
- for (int i = 0; i < m_nBuflen; i++) {
+ for (uint32_t i = 0; i < m_nBuflen; i++) {
printf("%02x.", *(m_sendbuf + i));
}
@@ -458,9 +451,9 @@ void DJNParty::receivempz_t(mpz_t t, channel* chan, BYTE * buf) {
chan->blocking_receive(buf, (uint64_t) m_nBuflen);
mpz_import(t, m_nBuflen, -1, 1, 1, 0, buf);
-#if NETDEBUG
+#if DJN_NETDEBUG
std::cout << std::endl << "RECEIVE" << std::endl;
- for (int i = 0; i < m_nBuflen; i++) {
+ for (uint32_t i = 0; i < m_nBuflen; i++) {
printf("%02x.", *(m_recbuf + i));
}
@@ -483,7 +476,7 @@ void DJNParty::sendmpz_t(mpz_t t, channel* chan) {
chan->send(arr, (uint64_t) bytelen);
free(arr);
-#if NETDEBUG
+#if DJN_NETDEBUG
std::cout << "sent: " << t << " with len: " << bytelen << std::endl;
#endif
}
@@ -503,14 +496,14 @@ void DJNParty::receivempz_t(mpz_t t, channel* chan) {
mpz_import(t, bytelen, 1, 1, 1, 0, arr);
free(arr);
-#if NETDEBUG
+#if DJN_NETDEBUG
std::cout << "received: " << t << " with len: " << bytelen << std::endl;
#endif
}
#if DJN_DEBUG
-void DJNParty::printBuf(BYTE* b, UINT len) {
- for (UINT i = 0; i < len; i++) {
+void DJNParty::printBuf(BYTE* b, uint32_t len) {
+ for (uint32_t i = 0; i < len; i++) {
printf("%02x.", *(b + i));
}
std::cout << std::endl;
diff --git a/src/abycore/DJN/djnparty.h b/src/abycore/DJN/djnparty.h
index 9e3f8b8e..03b0af76 100644
--- a/src/abycore/DJN/djnparty.h
+++ b/src/abycore/DJN/djnparty.h
@@ -2,23 +2,30 @@
\file djnparty.h
\author daniel.demmler@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief Implementation of DJNParty class
*/
#ifndef __DJNPARTY_H__
#define __DJNPARTY_H__
+#define DJN_CHECKMT 0
+#define DJN_DEBUG 0
+#define DJN_BENCH 0
+#define DJN_NETDEBUG 0
+#define DJN_NETDEBUG2 0
+#define DJN_WINDOWSIZE 65536//maximum size of a network packet in Byte
+
#include
#include
#include
@@ -26,32 +33,37 @@
#include
#include
#include
+#include
+#include
+#if DJN_DEBUG || DJN_BENCH
+#include
+#endif
class DJNParty {
public:
- DJNParty(UINT DJNbits, UINT sharelen);
- DJNParty(UINT DJNbits, UINT sharelen, channel* chan);
+ DJNParty(uint32_t DJNModulusBits, uint32_t shareBitLength);
+ DJNParty(uint32_t DJNModulusBits, uint32_t shareBitLength, channel* chan);
~DJNParty();
void keyExchange(channel* chan);
- void preCompBench(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE * bB1, BYTE * bC1, UINT numMTs, channel* chan);
+ void computeArithmeticMTs(BYTE * bA, BYTE * bB, BYTE * bC, BYTE * bA1, BYTE * bB1, BYTE * bC1, uint32_t numMTs, channel* chan);
- void setSharelLength(UINT sharelen);
+ void setShareBitLength(uint32_t shareBitLength);
void keyGen();
private:
- USHORT m_nNumMTThreads;
- USHORT m_nShareLength;
- UINT m_nDJNbits;
- UINT m_nBuflen;
+ uint16_t m_nNumMTThreads;
+ uint16_t m_nShareBitLength;
+ uint32_t m_nDJNModulusBits;
+ uint32_t m_nBuflen;
// Crypto and GMP PRNG
djn_pubkey_t *m_localpub, *m_remotepub;
djn_prvkey_t *m_prv;
- void benchPreCompPacking1(channel* chan, BYTE * buf, UINT packlen, UINT numshares, mpz_t * a, mpz_t * b, mpz_t * c, mpz_t * a1, mpz_t * b1, mpz_t * c1, mpz_t r, mpz_t x,
- mpz_t y, mpz_t z);
+ void benchPreCompPacking1(channel* chan, BYTE * buf, uint32_t packlen, uint32_t numshares,
+ mpz_t * a, mpz_t * b, mpz_t * a1, mpz_t * b1, mpz_t * c1, mpz_t r, mpz_t x, mpz_t y, mpz_t z);
void sendmpz_t(mpz_t t, channel* chan, BYTE * buf);
void receivempz_t(mpz_t t, channel* chan, BYTE * buf);
@@ -59,7 +71,7 @@ class DJNParty {
void sendmpz_t(mpz_t t, channel* chan);
void receivempz_t(mpz_t t, channel* chan);
- void printBuf(BYTE* b, UINT l);
+ void printBuf(BYTE* b, uint32_t l);
};
diff --git a/src/abycore/aby/abyparty.cpp b/src/abycore/aby/abyparty.cpp
index 7a26cba8..02a452c2 100644
--- a/src/abycore/aby/abyparty.cpp
+++ b/src/abycore/aby/abyparty.cpp
@@ -2,17 +2,17 @@
\file abyparty.cpp
\author michael.zohner@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief ABYParty class implementation.
*/
@@ -51,6 +51,9 @@ class ABYParty::CPartyWorkerThread: public CThread {
m_evt.Set();
}
+ CEvent* GetEvent() {
+ return &m_evt;
+ }
private:
void ThreadMain();
uint32_t threadid;
@@ -62,7 +65,7 @@ class ABYParty::CPartyWorkerThread: public CThread {
ABYParty::ABYParty(e_role pid, const std::string& addr, uint16_t port, seclvl seclvl,
uint32_t bitlen, uint32_t nthreads, e_mt_gen_alg mg_algo,
- uint32_t maxgates)
+ uint32_t reservegates, const std::string& abycircdir)
: m_cCrypt(std::make_unique(seclvl.symbits)), glock(std::make_unique()),
m_eMTGenAlg(mg_algo), m_eRole(pid), m_nNumOTThreads(nthreads),
m_tComm(std::make_unique()),
@@ -94,35 +97,36 @@ ABYParty::ABYParty(e_role pid, const std::string& addr, uint16_t port, seclvl se
std::cout << "Generating circuit" << std::endl;
#endif
StartWatch("Generating circuit", P_CIRCUIT);
- if (!InitCircuit(bitlen, maxgates)) {
+ if (!InitCircuit(bitlen, reservegates, abycircdir)) {
std::cout << "There was an while initializing the circuit, ending! " << std::endl;
std::exit(EXIT_FAILURE);
}
StopWatch("Time for circuit generation: ", P_CIRCUIT);
}
-
void ABYParty::ConnectAndBaseOTs() {
+ if (!is_online) {
#ifndef BATCH
- std::cout << "Establishing network connection" << std::endl;
+ std::cout << "Establishing network connection" << std::endl;
#endif
- //Establish network connection
- StartWatch("Establishing network connection: ", P_NETWORK);
- if (!EstablishConnection()) {
- std::cout << "There was an error during establish connection, ending! " << std::endl;
- std::exit(EXIT_FAILURE);
- }
- StopWatch("Time for network connect: ", P_NETWORK);
+ //Establish network connection
+ StartWatch("Establishing network connection: ", P_NETWORK);
+ if (!EstablishConnection()) {
+ std::cout << "There was an error during establish connection, ending! " << std::endl;
+ std::exit(EXIT_FAILURE);
+ }
+ StopWatch("Time for network connect: ", P_NETWORK);
#ifndef BATCH
- std::cout << "Performing base OTs" << std::endl;
+ std::cout << "Performing base OTs" << std::endl;
#endif
- /* Pre-Compute Naor-Pinkas base OTs by starting two threads */
- StartRecording("Starting NP OT", P_BASE_OT, m_vSockets);
- m_pSetup->PrepareSetupPhase(m_tComm.get());
- StopRecording("Time for NP OT: ", P_BASE_OT, m_vSockets);
+ /* Pre-Compute Naor-Pinkas base OTs by starting two threads */
+ StartRecording("Starting NP OT", P_BASE_OT, m_vSockets);
+ m_pSetup->PrepareSetupPhase(m_tComm.get());
+ StopRecording("Time for NP OT: ", P_BASE_OT, m_vSockets);
- is_online = true;
+ is_online = true;
+ }
}
ABYParty::~ABYParty() {
@@ -155,8 +159,8 @@ BOOL ABYParty::Init() {
void ABYParty::Cleanup() {
// free any gates that are still instantiated
for(size_t i = 0; i < m_pCircuit->GetGateHead(); i++) {
- if(m_pGates[i].instantiated) {
- m_vSharings[0]->FreeGate(&m_pGates[i]);
+ if((*m_vGates)[i].instantiated) {
+ m_vSharings[0]->FreeGate(&(*m_vGates)[i]);
}
}
for(uint32_t i = 0; i < S_LAST; i++) {
@@ -184,9 +188,7 @@ void ABYParty::ExecCircuit() {
std::cout << "Finishing circuit generation" << std::endl;
#endif
- if (!is_online) {
- ConnectAndBaseOTs();
- }
+ ConnectAndBaseOTs();
StartRecording("Starting execution", P_TOTAL, m_vSockets);
@@ -211,7 +213,7 @@ void ABYParty::ExecCircuit() {
std::cout << "Performing setup phase for " << m_vSharings[i]->sharing_type() << " sharing" << std::endl;
#endif
if(i == S_YAO) {
- StartWatch("Starting Circuit Garbling", P_GARBLE);
+ StartRecording("Starting Circuit Garbling", P_GARBLE, m_vSockets);
if(m_eRole == SERVER) {
m_vSharings[S_YAO]->PerformSetupPhase(m_pSetup.get());
m_vSharings[S_YAO_REV]->PerformSetupPhase(m_pSetup.get());
@@ -223,7 +225,7 @@ void ABYParty::ExecCircuit() {
m_vSharings[S_YAO_REV]->PerformSetupPhase(m_pSetup.get());*/
m_vSharings[S_YAO]->FinishSetupPhase(m_pSetup.get());
m_vSharings[S_YAO_REV]->FinishSetupPhase(m_pSetup.get());
- StopWatch("Time for Circuit garbling: ", P_GARBLE);
+ StopRecording("Time for Circuit garbling: ", P_GARBLE, m_vSockets);
} else if (i == S_YAO_REV) {
//Do nothing, was done in parallel to Yao
} else {
@@ -265,40 +267,40 @@ void ABYParty::ExecCircuit() {
}
-BOOL ABYParty::InitCircuit(uint32_t bitlen, uint32_t maxgates) {
- // Specification of maximum amount of gates in constructor in abyparty.h
- m_pCircuit = new ABYCircuit(maxgates);
+BOOL ABYParty::InitCircuit(uint32_t bitlen, uint32_t reservegates, const std::string& abycircdir) {
+ // Default reserved gates in abyparty.h constructur
+ m_pCircuit = new ABYCircuit(reservegates);
m_vSharings.resize(S_LAST);
- m_vSharings[S_BOOL] = new BoolSharing(S_BOOL, m_eRole, 1, m_pCircuit, m_cCrypt.get());
+ m_vSharings[S_BOOL] = new BoolSharing(S_BOOL, m_eRole, 1, m_pCircuit, m_cCrypt.get(), abycircdir);
if (m_eRole == SERVER) {
- m_vSharings[S_YAO] = new YaoServerSharing(S_YAO, SERVER, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get());
- m_vSharings[S_YAO_REV] = new YaoClientSharing(S_YAO_REV, CLIENT, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get());
+ m_vSharings[S_YAO] = new YaoServerSharing(S_YAO, SERVER, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get(), abycircdir);
+ m_vSharings[S_YAO_REV] = new YaoClientSharing(S_YAO_REV, CLIENT, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get(), abycircdir);
}
else {
- m_vSharings[S_YAO] = new YaoClientSharing(S_YAO, CLIENT, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get());
- m_vSharings[S_YAO_REV] = new YaoServerSharing(S_YAO_REV, SERVER, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get());
+ m_vSharings[S_YAO] = new YaoClientSharing(S_YAO, CLIENT, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get(), abycircdir);
+ m_vSharings[S_YAO_REV] = new YaoServerSharing(S_YAO_REV, SERVER, m_sSecLvl.symbits, m_pCircuit, m_cCrypt.get(), abycircdir);
}
switch (bitlen) {
case 8:
- m_vSharings[S_ARITH] = new ArithSharing(S_ARITH, m_eRole, 1, m_pCircuit, m_cCrypt.get(), m_eMTGenAlg);
+ m_vSharings[S_ARITH] = new ArithSharing(S_ARITH, m_eRole, 1, m_pCircuit, m_cCrypt.get(), m_eMTGenAlg);
break;
case 16:
- m_vSharings[S_ARITH] = new ArithSharing(S_ARITH, m_eRole, 1, m_pCircuit, m_cCrypt.get(), m_eMTGenAlg);
+ m_vSharings[S_ARITH] = new ArithSharing(S_ARITH, m_eRole, 1, m_pCircuit, m_cCrypt.get(), m_eMTGenAlg);
break;
case 32:
- m_vSharings[S_ARITH] = new ArithSharing(S_ARITH, m_eRole, 1, m_pCircuit, m_cCrypt.get(), m_eMTGenAlg);
+ m_vSharings[S_ARITH] = new ArithSharing(S_ARITH, m_eRole, 1, m_pCircuit, m_cCrypt.get(), m_eMTGenAlg);
break;
case 64:
- m_vSharings[S_ARITH] = new ArithSharing(S_ARITH, m_eRole, 1, m_pCircuit, m_cCrypt.get(), m_eMTGenAlg);
+ m_vSharings[S_ARITH] = new ArithSharing(S_ARITH, m_eRole, 1, m_pCircuit, m_cCrypt.get(), m_eMTGenAlg);
break;
default:
- m_vSharings[S_ARITH] = new ArithSharing(S_ARITH, m_eRole, 1, m_pCircuit, m_cCrypt.get(), m_eMTGenAlg);
+ m_vSharings[S_ARITH] = new ArithSharing(S_ARITH, m_eRole, 1, m_pCircuit, m_cCrypt.get(), m_eMTGenAlg);
break;
}
- m_vSharings[S_SPLUT] = new SetupLUT(S_SPLUT, m_eRole, 1, m_pCircuit, m_cCrypt.get());
+ m_vSharings[S_SPLUT] = new SetupLUT(S_SPLUT, m_eRole, 1, m_pCircuit, m_cCrypt.get(), abycircdir);
- m_pGates = m_pCircuit->Gates();
+ m_vGates = &(m_pCircuit->GatesVec());
#ifndef BATCH
std::cout << " circuit initialized..." << std::endl;
@@ -378,7 +380,7 @@ BOOL ABYParty::EvaluateCircuit() {
clock_gettime(CLOCK_MONOTONIC, &tstart);
#endif
//std::cout << "Finishing circuit layer for sharing "<< i << std::endl;
- m_vSharings[i]->FinishCircuitLayer(depth);
+ m_vSharings[i]->FinishCircuitLayer();
#if BENCHONLINEPHASE
clock_gettime(CLOCK_MONOTONIC, &tend);
fincirclayer[i] += getMillies(tstart, tend);
@@ -409,7 +411,7 @@ BOOL ABYParty::PerformInteraction() {
return success;
}
-BOOL ABYParty::ThreadSendValues() {
+BOOL ABYParty::ThreadSendValues(uint32_t id) {
std::vector >sendbuf(m_vSharings.size());
std::vector >sndbytes(m_vSharings.size());
@@ -440,7 +442,7 @@ BOOL ABYParty::ThreadSendValues() {
//gettimeofday(&tstart, NULL);
if(snd_buf_size_total > 0) {
//m_vSockets[2]->Send(snd_buf_total, snd_buf_size_total);
- m_tPartyChan->send(snd_buf_total, snd_buf_size_total);
+ m_tPartyChan->blocking_send(m_vThreads[id]->GetEvent(), snd_buf_total, snd_buf_size_total);
}
free(snd_buf_total);
@@ -586,15 +588,15 @@ BOOL ABYParty::ABYPartyListen() {
// TODO: are InstantiateGate and UsedGate needed in ABYParty? They don't
// seem to get used anywhere
void ABYParty::InstantiateGate(uint32_t gateid) {
- m_pGates[gateid].gs.val = (UGATE_T*) malloc(sizeof(UGATE_T) * (ceil_divide(m_pGates[gateid].nvals, GATE_T_BITS)));
+ (*m_vGates)[gateid].gs.val = (UGATE_T*) malloc(sizeof(UGATE_T) * (ceil_divide((*m_vGates)[gateid].nvals, GATE_T_BITS)));
}
void ABYParty::UsedGate(uint32_t gateid) {
//Decrease the number of further uses of the gate
- m_pGates[gateid].nused--;
+ (*m_vGates)[gateid].nused--;
//If the gate is needed in another subsequent gate, delete it
- if (!m_pGates[gateid].nused) {
- free(m_pGates[gateid].gs.val);
+ if (!(*m_vGates)[gateid].nused) {
+ free((*m_vGates)[gateid].gs.val);
}
}
@@ -606,8 +608,8 @@ void ABYParty::Reset() {
// free any gates that are still instantiated
for(size_t i = 0; i < m_pCircuit->GetGateHead(); i++) {
- if(m_pGates[i].instantiated) {
- m_vSharings[0]->FreeGate(&m_pGates[i]);
+ if((*m_vGates)[i].instantiated) {
+ m_vSharings[0]->FreeGate(&(*m_vGates)[i]);
}
}
for (uint32_t i = 0; i < m_vSharings.size(); i++) {
@@ -629,6 +631,14 @@ uint64_t ABYParty::GetReceivedData(ABYPHASE phase) {
return GetReceivedDataForPhase(phase);
}
+uint32_t ABYParty::GetTotalGates() {
+ return m_pCircuit->GetGateHead();
+}
+
+uint32_t ABYParty::GetTotalDepth() {
+ return m_pCircuit->GetTotalDepth();
+}
+
//===========================================================================
// Thread Management
BOOL ABYParty::WakeupWorkerThreads(EPartyJobType e) {
@@ -689,7 +699,7 @@ void ABYParty::CPartyWorkerThread::ThreadMain() {
return;
case e_Party_Comm:
if (threadid == 0){
- bSuccess = m_pCallback->ThreadSendValues();
+ bSuccess = m_pCallback->ThreadSendValues(threadid);
}
else{
bSuccess = m_pCallback->ThreadReceiveValues();
diff --git a/src/abycore/aby/abyparty.h b/src/abycore/aby/abyparty.h
index 99afd2c3..406de880 100644
--- a/src/abycore/aby/abyparty.h
+++ b/src/abycore/aby/abyparty.h
@@ -2,17 +2,17 @@
\file abyparty.h
\author michael.zohner@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief ABYParty class.
*/
@@ -41,7 +41,7 @@ class CLock;
class ABYParty {
public:
ABYParty(e_role pid, const std::string& addr = "127.0.0.1", uint16_t port = 7766, seclvl seclvl = LT, uint32_t bitlen = 32,
- uint32_t nthreads = 2, e_mt_gen_alg mg_algo = MT_OT, uint32_t maxgates = 4000000);
+ uint32_t nthreads = 2, e_mt_gen_alg mg_algo = MT_OT, uint32_t reservegates = 65536, const std::string& abycircdir = ABY_CIRCUIT_DIR);
~ABYParty();
/**
@@ -59,13 +59,14 @@ class ABYParty {
double GetTiming(ABYPHASE phase);
uint64_t GetSentData(ABYPHASE phase);
uint64_t GetReceivedData(ABYPHASE phase);
-
+ uint32_t GetTotalGates();
+ uint32_t GetTotalDepth();
private:
BOOL Init();
void Cleanup();
- BOOL InitCircuit(uint32_t bitlen, uint32_t maxgates);
+ BOOL InitCircuit(uint32_t bitlen, uint32_t reservegates, const std::string& circdir = ABY_CIRCUIT_DIR);
BOOL EstablishConnection();
@@ -82,7 +83,7 @@ class ABYParty {
void UsedGate(uint32_t gateid);
BOOL PerformInteraction();
- BOOL ThreadSendValues();
+ BOOL ThreadSendValues(uint32_t id);
BOOL ThreadReceiveValues();
void PrintPerformanceStatistics();
@@ -120,7 +121,7 @@ class ABYParty {
uint32_t m_nMyNumInBits;
// Ciruit
ABYCircuit* m_pCircuit;
- GATE* m_pGates;
+ std::vector* m_vGates;
uint32_t m_nSizeOfVal;
diff --git a/src/abycore/aby/abysetup.cpp b/src/abycore/aby/abysetup.cpp
index 39fef178..fdca9d4f 100644
--- a/src/abycore/aby/abysetup.cpp
+++ b/src/abycore/aby/abysetup.cpp
@@ -2,24 +2,23 @@
\file abysetup.cpp
\author michael.zohner@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief ABYSetup class implementation.
*/
#include "abysetup.h"
#include
#include
-#include
ABYSetup::ABYSetup(crypto* crypt, uint32_t numThreads, e_role role, e_mt_gen_alg mtalgo) {
m_nNumOTThreads = numThreads;
@@ -51,22 +50,26 @@ BOOL ABYSetup::Init() {
m_vThreads[i]->Start();
}
- //the bit length of the DJN and DGK party is irrelevant here, since it is set for each MT Gen task independently
+ //the bit length of the DJN party is irrelevant here, since it is set for each MT Gen task independently
if (m_eMTGenAlg == MT_PAILLIER) {
#ifndef BATCH
std::cout << "Creating new DJNPart with key bitlen = " << m_cCrypt->get_seclvl().ifcbits << std::endl;
#endif
- m_cPaillierMTGen = new DJNParty(m_cCrypt->get_seclvl().ifcbits, sizeof(UINT16_T) * 8);
- } else if (m_eMTGenAlg == MT_DGK) {
-#ifndef BATCH
- std::cout << "Creating new DGKPart with key bitlen = " << m_cCrypt->get_seclvl().ifcbits << std::endl;
-#endif
-#ifdef BENCH_PRECOMP
- m_cDGKMTGen = (DGKParty**) malloc(sizeof(DGKParty*));
- m_cDGKMTGen[0] = new DGKParty(m_sSecLvl.ifcbits, sizeof(UINT64_T) * 8, 0);
-#endif
- //m_cDGKMTGen = new DGKParty(m_cCrypt->get_seclvl().ifcbits, sizeof(UINT16_T) * 8);
+ m_cPaillierMTGen = new DJNParty(m_cCrypt->get_seclvl().ifcbits, sizeof(uint16_t) * 8);
}
+// we cannot create a DGKParty here, since we do not know the share bit length yet.
+// for DGK this will be done in PerformSetupPhase()
+
+// else if (m_eMTGenAlg == MT_DGK) {
+// #ifndef BATCH
+// std::cout << "Creating new DGKPart with key bitlen = " << m_cCrypt->get_seclvl().ifcbits << std::endl;
+// #endif
+// #ifdef BENCH_PRECOMP
+// m_cDGKMTGen = (DGKParty**) malloc(sizeof(DGKParty*));
+// m_cDGKMTGen[0] = new DGKParty(m_sSecLvl.ifcbits, sizeof(uint64_t) * 8, 0);
+// #endif
+// //m_cDGKMTGen = new DGKParty(m_cCrypt->get_seclvl().ifcbits, sizeof(uint16_t) * 8);
+// }
return true;
}
@@ -87,6 +90,10 @@ void ABYSetup::Cleanup() {
if(iknp_ot_receiver) {
delete iknp_ot_receiver;
}
+ if(m_cPaillierMTGen){
+ delete m_cPaillierMTGen;
+ }
+
#ifdef USE_KK_OT
//FIXME: deleting kk_ot_receiver or sender causes a SegFault in AES with Yao
@@ -205,7 +212,10 @@ BOOL ABYSetup::PerformSetupPhase() {
//Start Paillier MT generation
WakeupWorkerThreads(e_MTPaillier);
success &= WaitWorkerThreads();
- } else if (m_eMTGenAlg == MT_DGK) {
+ }
+ else if (m_eMTGenAlg == MT_DGK) {
+ // we cannot create the DGK parties earlier
+ // since share length in m_vPKMTGenTasks[i]->sharebitlen is required and only known from here on
#ifndef BENCH_PRECOMP
m_cDGKMTGen = (DGKParty**) malloc(sizeof(DGKParty*) * m_vPKMTGenTasks.size());
#endif
@@ -232,7 +242,7 @@ BOOL ABYSetup::FinishSetupPhase() {
return true;
}
-BOOL ABYSetup::ThreadRunNPSnd(uint32_t exec) {
+BOOL ABYSetup::ThreadRunNPSnd() {
BOOL success = true;
iknp_ot_sender->ComputeBaseOTs(P_FIELD);
#ifdef USE_KK_OT
@@ -241,7 +251,7 @@ BOOL ABYSetup::ThreadRunNPSnd(uint32_t exec) {
return success;
}
-BOOL ABYSetup::ThreadRunNPRcv(uint32_t exec) {
+BOOL ABYSetup::ThreadRunNPRcv() {
BOOL success = true;
iknp_ot_receiver->ComputeBaseOTs(P_FIELD);
#ifdef USE_KK_OT
@@ -251,10 +261,10 @@ BOOL ABYSetup::ThreadRunNPRcv(uint32_t exec) {
}
//Receiver and Sender switch roles in the beginning of the OT extension protocol to obliviously transfer a matrix T
-BOOL ABYSetup::ThreadRunIKNPSnd(uint32_t exec) {
+BOOL ABYSetup::ThreadRunIKNPSnd(uint32_t threadid) {
bool success = true;
- uint32_t inverse = exec ^ m_eRole;
+ uint32_t inverse = threadid ^ m_eRole;
uint32_t nsndvals = 2;
CBitVector** X = (CBitVector**) malloc(sizeof(CBitVector*) * nsndvals);
@@ -285,10 +295,10 @@ BOOL ABYSetup::ThreadRunIKNPSnd(uint32_t exec) {
return success;
}
-BOOL ABYSetup::ThreadRunIKNPRcv(uint32_t exec) {
+BOOL ABYSetup::ThreadRunIKNPRcv(uint32_t threadid) {
bool success = true;
- uint32_t inverse = exec ^ m_eRole;
+ uint32_t inverse = threadid ^ m_eRole;
// uint32_t symbits = m_cCrypt->get_seclvl().symbits;
uint32_t nsndvals = 2;
@@ -319,10 +329,10 @@ BOOL ABYSetup::ThreadRunIKNPRcv(uint32_t exec) {
//KK13 OT extension sender and receiver routine outsourced in separate threads
-BOOL ABYSetup::ThreadRunKKSnd(uint32_t exec) {
+BOOL ABYSetup::ThreadRunKKSnd(uint32_t threadid) {
bool success = true;
- uint32_t inverse = exec ^ m_eRole;
+ uint32_t inverse = threadid ^ m_eRole;
for (uint32_t i = 0; i < m_vKKOTTasks[inverse].size(); i++) {
KK_OTTask* task = m_vKKOTTasks[inverse][i];
@@ -356,10 +366,10 @@ BOOL ABYSetup::ThreadRunKKSnd(uint32_t exec) {
return success;
}
-BOOL ABYSetup::ThreadRunKKRcv(uint32_t exec) {
+BOOL ABYSetup::ThreadRunKKRcv(uint32_t threadid) {
bool success = true;
- uint32_t inverse = exec ^ m_eRole;
+ uint32_t inverse = threadid ^ m_eRole;
// uint32_t symbits = m_cCrypt->get_seclvl().symbits;
// uint32_t nsndvals = 2;
@@ -388,36 +398,46 @@ BOOL ABYSetup::ThreadRunKKRcv(uint32_t exec) {
return success;
}
-
BOOL ABYSetup::ThreadRunPaillierMTGen(uint32_t threadid) {
-
uint32_t nthreads = 2 * m_nNumOTThreads;
- channel* djnchan = new channel(DJN_CHANNEL+threadid, m_tComm->rcv_std.get(), m_tComm->snd_std.get());
- for (uint32_t i = 0; i < m_vPKMTGenTasks.size(); i++) {
+ channel* djnchan = new channel(DJN_CHANNEL + threadid, m_tComm->rcv_std.get(), m_tComm->snd_std.get());
+ for (uint32_t i = 0; i < m_vPKMTGenTasks.size(); i++) {
PKMTGenVals* ptask = m_vPKMTGenTasks[i];
- uint32_t nummtsperthread = ceil_divide(ptask->numMTs, nthreads);
+ // equally distribute MTs to threads. Number of MTs per thread must be multiple of 2.
+ uint32_t nummtsperthread = ptask->numMTs / (nthreads * 2);
+ uint32_t threadmod = ptask->numMTs % (nthreads * 2);
+ uint32_t mynummts = (nummtsperthread + ((threadid * 2) < threadmod)) * 2;
- uint32_t mynummts = nummtsperthread; //times two since we need the number of MTs to be a multiple of 2 internally
uint32_t sharebytelen = ceil_divide(ptask->sharebitlen, 8);
- if (threadid == nthreads - 1) {
- mynummts = ptask->numMTs - (nthreads-1 ) * nummtsperthread;
- }
-
- uint32_t mystartpos = nummtsperthread * threadid * sharebytelen;
- m_cPaillierMTGen->setSharelLength(ptask->sharebitlen);
-
- UINT32_T roleoffset = mystartpos + sharebytelen * (mynummts / 2);
- if (m_eRole == SERVER) {
- m_cPaillierMTGen->preCompBench(ptask->A->GetArr() + mystartpos, ptask->B->GetArr() + mystartpos, ptask->C->GetArr() + mystartpos, ptask->A->GetArr() + roleoffset,
- ptask->B->GetArr() + roleoffset, ptask->C->GetArr() + roleoffset, mynummts, djnchan);
- } else {
- m_cPaillierMTGen->preCompBench(ptask->A->GetArr() + roleoffset, ptask->B->GetArr() + roleoffset, ptask->C->GetArr() + roleoffset, ptask->A->GetArr() + mystartpos,
- ptask->B->GetArr() + mystartpos, ptask->C->GetArr() + mystartpos, mynummts, djnchan);
+ if (mynummts > 0) {
+ uint32_t mystartpos = 0;
+
+ // add up previous threads numMTs to find start index for this thread
+ for (uint32_t t = 0; t < threadid; ++t) {
+ mystartpos += (nummtsperthread + ((t * 2) < threadmod)) * 2;
+ }
+ mystartpos *= sharebytelen;
+
+ //add an offset depending on the role of the party
+ uint32_t roleoffset = mystartpos + sharebytelen * (mynummts / 2);
+
+ m_cPaillierMTGen->setShareBitLength(ptask->sharebitlen);
+
+ if (m_eRole == SERVER) {
+ m_cPaillierMTGen->computeArithmeticMTs(
+ ptask->A->GetArr() + mystartpos, ptask->B->GetArr() + mystartpos, ptask->C->GetArr() + mystartpos,
+ ptask->A->GetArr() + roleoffset, ptask->B->GetArr() + roleoffset, ptask->C->GetArr() + roleoffset,
+ mynummts, djnchan);
+ } else {
+ m_cPaillierMTGen->computeArithmeticMTs(
+ ptask->A->GetArr() + roleoffset, ptask->B->GetArr() + roleoffset, ptask->C->GetArr() + roleoffset,
+ ptask->A->GetArr() + mystartpos, ptask->B->GetArr() + mystartpos, ptask->C->GetArr() + mystartpos,
+ mynummts, djnchan);
+ }
}
- free(ptask);
}
djnchan->synchronize_end();
delete djnchan;
@@ -426,37 +446,44 @@ BOOL ABYSetup::ThreadRunPaillierMTGen(uint32_t threadid) {
}
BOOL ABYSetup::ThreadRunDGKMTGen(uint32_t threadid) {
-
uint32_t nthreads = 2 * m_nNumOTThreads;
- channel* dgkchan = new channel(DGK_CHANNEL+threadid, m_tComm->rcv_std.get(), m_tComm->snd_std.get());
+ channel* dgkchan = new channel(DGK_CHANNEL + threadid, m_tComm->rcv_std.get(), m_tComm->snd_std.get());
for (uint32_t i = 0; i < m_vPKMTGenTasks.size(); i++) {
PKMTGenVals* ptask = m_vPKMTGenTasks[i];
- //times two since we need the number of MTs to be a multiple of 2 internally
- uint32_t nummtsperthread = ceil_divide(ptask->numMTs, nthreads);
- uint32_t mynummts = nummtsperthread;
- uint32_t sharebytelen = ceil_divide(ptask->sharebitlen, 8);
-
- //if the number of MTs is not evenly divisible among all threads
- if (threadid == nthreads - 1) {
- mynummts = ptask->numMTs - (nthreads-1 ) * nummtsperthread;
- }
+ // equally distribute MTs to threads. Number of MTs per thread must be multiple of 2.
+ uint32_t nummtsperthread = ptask->numMTs / (nthreads * 2);
+ uint32_t threadmod = ptask->numMTs % (nthreads * 2);
+ uint32_t mynummts = (nummtsperthread + ((threadid * 2) < threadmod)) * 2;
- uint32_t mystartpos = nummtsperthread * threadid * sharebytelen;
-
- //add an offset depending on the role of the party
- UINT32_T roleoffset = mystartpos + sharebytelen * (mynummts / 2);
+ uint32_t sharebytelen = ceil_divide(ptask->sharebitlen, 8);
- if (m_eRole == SERVER) {
- m_cDGKMTGen[i]->preCompBench(ptask->A->GetArr() + mystartpos, ptask->B->GetArr() + mystartpos, ptask->C->GetArr() + mystartpos, ptask->A->GetArr() + roleoffset,
- ptask->B->GetArr() + roleoffset, ptask->C->GetArr() + roleoffset, mynummts, dgkchan);
- } else {
- m_cDGKMTGen[i]->preCompBench(ptask->A->GetArr() + roleoffset, ptask->B->GetArr() + roleoffset, ptask->C->GetArr() + roleoffset, ptask->A->GetArr() + mystartpos,
- ptask->B->GetArr() + mystartpos, ptask->C->GetArr() + mystartpos, mynummts, dgkchan);
+ if (mynummts > 0) {
+ uint32_t mystartpos = 0;
+
+ // add up previous threads numMTs to find start index for this thread
+ for (uint32_t t = 0; t < threadid; ++t) {
+ mystartpos += (nummtsperthread + ((t * 2) < threadmod)) * 2;
+ }
+ mystartpos *= sharebytelen;
+
+ //add an offset depending on the role of the party
+ uint32_t roleoffset = mystartpos + sharebytelen * (mynummts / 2);
+
+ if (m_eRole == SERVER) {
+ m_cDGKMTGen[i]->computeArithmeticMTs(
+ ptask->A->GetArr() + mystartpos, ptask->B->GetArr() + mystartpos, ptask->C->GetArr() + mystartpos,
+ ptask->A->GetArr() + roleoffset, ptask->B->GetArr() + roleoffset, ptask->C->GetArr() + roleoffset,
+ mynummts, dgkchan);
+ } else {
+ m_cDGKMTGen[i]->computeArithmeticMTs(
+ ptask->A->GetArr() + roleoffset, ptask->B->GetArr() + roleoffset, ptask->C->GetArr() + roleoffset,
+ ptask->A->GetArr() + mystartpos, ptask->B->GetArr() + mystartpos, ptask->C->GetArr() + mystartpos,
+ mynummts, dgkchan);
+ }
}
- free(ptask);
}
dgkchan->synchronize_end();
delete dgkchan;
@@ -484,12 +511,14 @@ void ABYSetup::AddReceiveTask(BYTE* rcvbuf, uint64_t rcvbytes) {
WakeupWorkerThreads(e_Receive);
}
+
BOOL ABYSetup::ThreadSendData(uint32_t threadid) {
- m_tSetupChan->send(m_tsndtask.sndbuf, m_tsndtask.sndbytes);
+ m_tSetupChan->blocking_send(m_vThreads[threadid]->GetEvent(), m_tsndtask.sndbuf, m_tsndtask.sndbytes);
return true;
}
-BOOL ABYSetup::ThreadReceiveData(uint32_t threadid) {
+
+BOOL ABYSetup::ThreadReceiveData() {
m_tSetupChan->blocking_receive(m_trcvtask.rcvbuf, m_trcvtask.rcvbytes);
return true;
}
@@ -501,15 +530,17 @@ BOOL ABYSetup::WakeupWorkerThreads(EJobType e) {
m_nWorkingThreads = 2;
- if (e == e_MTPaillier || e == e_MTDGK)
+ if (e == e_MTPaillier || e == e_MTDGK) {
m_nWorkingThreads = 2 * m_nNumOTThreads;
- else if (e == e_Send || e == e_Receive)
+ } else if (e == e_Send || e == e_Receive) {
m_nWorkingThreads = 1;
+ }
uint32_t n = m_nWorkingThreads;
- for (uint32_t i = 0; i < n; i++)
+ for (uint32_t i = 0; i < n; i++){
m_vThreads[i]->PutJob(e);
+ }
return TRUE;
}
@@ -573,9 +604,9 @@ void ABYSetup::CWorkerThread::ThreadMain() {
break;
case e_NP:
if (threadid == SERVER)
- bSuccess = m_pCallback->ThreadRunNPSnd(threadid);
+ bSuccess = m_pCallback->ThreadRunNPSnd();
else
- bSuccess = m_pCallback->ThreadRunNPRcv(threadid);
+ bSuccess = m_pCallback->ThreadRunNPRcv();
break;
case e_MTPaillier:
bSuccess = m_pCallback->ThreadRunPaillierMTGen(threadid);
@@ -587,7 +618,7 @@ void ABYSetup::CWorkerThread::ThreadMain() {
bSuccess = m_pCallback->ThreadSendData(threadid);
break;
case e_Receive:
- bSuccess = m_pCallback->ThreadReceiveData(threadid);
+ bSuccess = m_pCallback->ThreadReceiveData();
break;
case e_Transmit:
case e_Undefined:
@@ -599,12 +630,18 @@ void ABYSetup::CWorkerThread::ThreadMain() {
}
void ABYSetup::Reset() {
- /* Clear any remaining OT tasks */
+ /* Clear any remaining IKNP OT tasks */
for (uint32_t i = 0; i < m_vIKNPOTTasks.size(); i++) {
m_vIKNPOTTasks[i].clear();
}
- /* Clear any remaining OT tasks */
+ /* Clear any remaining KK OT tasks */
for (uint32_t i = 0; i < m_vKKOTTasks.size(); i++) {
m_vKKOTTasks[i].clear();
}
+
+ /* Clear any remaining MTGen tasks */
+ for (uint32_t i = 0; i < m_vPKMTGenTasks.size(); i++) {
+ free(m_vPKMTGenTasks[i]);
+ }
+ m_vPKMTGenTasks.clear();
}
diff --git a/src/abycore/aby/abysetup.h b/src/abycore/aby/abysetup.h
index bfd13544..f0d3d693 100644
--- a/src/abycore/aby/abysetup.h
+++ b/src/abycore/aby/abysetup.h
@@ -2,17 +2,17 @@
\file abysetup.h
\author michael.zohner@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief Contains all methods that are processed during the setup phase of ABY
*/
@@ -152,19 +152,19 @@ class ABYSetup {
BOOL Init();
void Cleanup();
- BOOL ThreadRunNPSnd(uint32_t exec);
- BOOL ThreadRunNPRcv(uint32_t exec);
+ BOOL ThreadRunNPSnd();
+ BOOL ThreadRunNPRcv();
- BOOL ThreadRunIKNPSnd(uint32_t exec);
- BOOL ThreadRunIKNPRcv(uint32_t exec);
+ BOOL ThreadRunIKNPSnd(uint32_t threadid);
+ BOOL ThreadRunIKNPRcv(uint32_t threadid);
- BOOL ThreadRunKKSnd(uint32_t exec);
- BOOL ThreadRunKKRcv(uint32_t exec);
+ BOOL ThreadRunKKSnd(uint32_t threadid);
+ BOOL ThreadRunKKRcv(uint32_t threadid);
- BOOL ThreadSendData(uint32_t exec);
- BOOL ThreadReceiveData(uint32_t exec);
+ BOOL ThreadSendData(uint32_t threadid);
+ BOOL ThreadReceiveData();
- BOOL ThreadRunPaillierMTGen(uint32_t exec);
+ BOOL ThreadRunPaillierMTGen(uint32_t threadid);
BOOL ThreadRunDGKMTGen(uint32_t threadid);
// IKNP OTTask values
@@ -220,6 +220,9 @@ class ABYSetup {
m_eJob = e;
m_evt.Set();
}
+ CEvent* GetEvent() {
+ return &m_evt;
+ }
private:
void ThreadMain();
uint32_t threadid;
diff --git a/src/abycore/circuit/abycircuit.cpp b/src/abycore/circuit/abycircuit.cpp
index cd8c44bf..04e2f99c 100644
--- a/src/abycore/circuit/abycircuit.cpp
+++ b/src/abycore/circuit/abycircuit.cpp
@@ -2,17 +2,17 @@
\file abycircuit.cpp
\author michael.zohner@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief Implementation of ABY Circuit Class.
*/
@@ -29,142 +29,144 @@
void ABYCircuit::Cleanup() {
Reset();
- free(m_pGates);
}
-ABYCircuit::ABYCircuit(uint32_t maxgates) {
- m_nMaxGates = maxgates;
- m_pGates = (GATE*) calloc(maxgates, sizeof(GATE));
- m_nNextFreeGate = 0;
- m_nMaxVectorSize = 1;
- m_nMaxDepth = 0;
+ABYCircuit::ABYCircuit(uint32_t reservegates) :
+ m_nMaxVectorSize{1},
+ m_nMaxDepth{0}
+{
+ m_vGates.reserve(reservegates);
+}
+
+/**
+ * Gate ID of the just inserted gate
+ */
+inline uint32_t ABYCircuit::currentGateId() {
+ return m_vGates.size() - 1;
}
-inline void ABYCircuit::InitGate(GATE* gate, e_gatetype type) {
+inline GATE* ABYCircuit::InitGate(e_gatetype type) {
#ifdef DEBUG_CIRCUIT_CONSTRUCTION
std::cout << "Putting new gate with type " << type << std::endl;
#endif
- if(m_nNextFreeGate >= m_nMaxGates) {
- std::cerr << "I have more gates than available: " << m_nNextFreeGate << std::endl;
- }
- assert(m_nNextFreeGate < m_nMaxGates);
-
- gate->type = type;
- gate->nused = 0;
- gate->nrounds = 0;
+ // We abuse resize() to insert a new zero-initialized GATE struct at the end
+ // of the gate vector
+ m_vGates.resize(m_vGates.size() + 1);
+ m_vGates.back().type = type;
+ return &(m_vGates.back());
}
-inline void ABYCircuit::InitGate(GATE* gate, e_gatetype type, uint32_t ina) {
- InitGate(gate, type);
+inline GATE* ABYCircuit::InitGate(e_gatetype type, uint32_t ina) {
+ GATE* gate = InitGate(type);
- assert(ina < m_nNextFreeGate);
- gate->depth = ComputeDepth(m_pGates[ina]);
+ assert(ina < GetGateHead());
+ gate->depth = ComputeDepth(m_vGates[ina]);
m_nMaxDepth = std::max(m_nMaxDepth, gate->depth);
gate->ingates.ningates = 1;
gate->ingates.inputs.parent = ina;
- gate->context = m_pGates[ina].context;
- gate->sharebitlen = m_pGates[ina].sharebitlen;
+ gate->context = m_vGates[ina].context;
+ gate->sharebitlen = m_vGates[ina].sharebitlen;
MarkGateAsUsed(ina);
+ return gate;
}
-inline void ABYCircuit::InitGate(GATE* gate, e_gatetype type, uint32_t ina, uint32_t inb) {
- InitGate(gate, type);
+inline GATE* ABYCircuit::InitGate(e_gatetype type, uint32_t ina, uint32_t inb) {
+ GATE* gate = InitGate(type);
- if(ina >= m_nNextFreeGate || inb >= m_nNextFreeGate) {
- std::cout << "ina = " << ina << ", inb = " << inb << ", nfg = " << m_nNextFreeGate << std::endl;
- assert(ina < m_nNextFreeGate && inb < m_nNextFreeGate);
+ if(ina >= GetGateHead() || inb >= GetGateHead()) {
+ std::cout << "ina = " << ina << ", inb = " << inb << ", nfg = " << GetGateHead() << std::endl;
+ assert(ina < GetGateHead() && inb < GetGateHead());
}
- gate->depth = std::max(ComputeDepth(m_pGates[ina]), ComputeDepth(m_pGates[inb]));
+ gate->depth = std::max(ComputeDepth(m_vGates[ina]), ComputeDepth(m_vGates[inb]));
m_nMaxDepth = std::max(m_nMaxDepth, gate->depth);
gate->ingates.ningates = 2;
gate->ingates.inputs.twin.left = ina;
gate->ingates.inputs.twin.right = inb;
- assert(m_pGates[ina].context == m_pGates[inb].context);
- assert(m_pGates[ina].sharebitlen == m_pGates[inb].sharebitlen);
+ assert(m_vGates[ina].context == m_vGates[inb].context);
+ assert(m_vGates[ina].sharebitlen == m_vGates[inb].sharebitlen);
- gate->context = m_pGates[ina].context;
- gate->sharebitlen = m_pGates[ina].sharebitlen;
+ gate->context = m_vGates[ina].context;
+ gate->sharebitlen = m_vGates[ina].sharebitlen;
MarkGateAsUsed(ina);
MarkGateAsUsed(inb);
+ return gate;
}
-inline void ABYCircuit::InitGate(GATE* gate, e_gatetype type, std::vector& inputs) {
- InitGate(gate, type);
+inline GATE* ABYCircuit::InitGate(e_gatetype type, std::vector& inputs) {
+ GATE* gate = InitGate(type);
gate->ingates.ningates = inputs.size();
gate->depth = 0;
if (inputs.size() == 0)
- return;
+ return gate;
uint32_t ina = inputs[0];
- assert(ina < m_nNextFreeGate);
+ assert(ina < GetGateHead());
- gate->depth = ComputeDepth(m_pGates[ina]);
+ gate->depth = ComputeDepth(m_vGates[ina]);
gate->ingates.inputs.parents = (uint32_t*) malloc(sizeof(uint32_t) * inputs.size());
memcpy(gate->ingates.inputs.parents, inputs.data(), inputs.size() * sizeof(uint32_t));
- gate->context = m_pGates[ina].context;
- gate->sharebitlen = m_pGates[ina].sharebitlen;
+ gate->context = m_vGates[ina].context;
+ gate->sharebitlen = m_vGates[ina].sharebitlen;
MarkGateAsUsed(ina);
for (uint32_t i = 1; i < inputs.size(); i++) {
- assert(inputs[i] < m_nNextFreeGate);
- gate->depth = std::max(gate->depth, ComputeDepth(m_pGates[inputs[i]]));
- assert(gate->context == m_pGates[inputs[i]].context);
- assert(gate->sharebitlen == m_pGates[inputs[i]].sharebitlen);
+ assert(inputs[i] < GetGateHead());
+ gate->depth = std::max(gate->depth, ComputeDepth(m_vGates[inputs[i]]));
+ assert(gate->context == m_vGates[inputs[i]].context);
+ assert(gate->sharebitlen == m_vGates[inputs[i]].sharebitlen);
MarkGateAsUsed(inputs[i]);
}
m_nMaxDepth = std::max(m_nMaxDepth, gate->depth);
+ return gate;
}
-//Add a gate to m_pGates, increase the gateptr, used for G_LIN or G_NON_LIN
+//Add a gate to m_vGates, increase the gateptr, used for G_LIN or G_NON_LIN
uint32_t ABYCircuit::PutPrimitiveGate(e_gatetype type, uint32_t inleft, uint32_t inright, uint32_t rounds) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, type, inleft, inright);
+ GATE* gate = InitGate(type, inleft, inright);
- gate->nvals = std::min(m_pGates[inleft].nvals, m_pGates[inright].nvals);
+ gate->nvals = std::min(m_vGates[inleft].nvals, m_vGates[inright].nvals);
gate->nrounds = rounds;
#ifdef DEBUG_CIRCUIT_CONSTRUCTION
- std::cout << "New primitive gate with id: " << m_nNextFreeGate << ", left in = " << inleft << ", right in = " << inright << ", nvals = " << gate->nvals <<
+ std::cout << "New primitive gate with id: " << currentGateId() << ", left in = " << inleft << ", right in = " << inright << ", nvals = " << gate->nvals <<
", depth = " << gate->depth << ", sharingsize = " << gate->sharebitlen << ", nrounds = " << gate->nrounds << std::endl;
#endif
- return m_nNextFreeGate++;
+ return currentGateId();
}
//add a vector-MT gate, mostly the same as a standard primitive gate but with explicit choiceinput / vectorinput
uint32_t ABYCircuit::PutNonLinearVectorGate(e_gatetype type, uint32_t choiceinput, uint32_t vectorinput, uint32_t rounds) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, type, choiceinput, vectorinput);
+ GATE* gate = InitGate(type, choiceinput, vectorinput);
- assert((m_pGates[vectorinput].nvals % m_pGates[choiceinput].nvals) == 0);
+ assert((m_vGates[vectorinput].nvals % m_vGates[choiceinput].nvals) == 0);
- gate->nvals = m_pGates[vectorinput].nvals;
+ gate->nvals = m_vGates[vectorinput].nvals;
gate->nrounds = rounds;
- gate->gs.avs.bitlen = m_pGates[vectorinput].nvals / m_pGates[choiceinput].nvals;
+ gate->gs.avs.bitlen = m_vGates[vectorinput].nvals / m_vGates[choiceinput].nvals;
- return m_nNextFreeGate++;
+ return currentGateId();
}
uint32_t ABYCircuit::PutCombinerGate(std::vector input) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_COMBINE, input);
+ GATE* gate = InitGate(G_COMBINE, input);
gate->nvals = 0;
for(uint32_t i = 0; i < input.size(); i++) {
- //std::cout << "size at i = " << i << ": " << m_pGates[input[i]].nvals << std::endl;;
- gate->nvals += m_pGates[input[i]].nvals;
+ //std::cout << "size at i = " << i << ": " << m_vGates[input[i]].nvals << std::endl;;
+ gate->nvals += m_vGates[input[i]].nvals;
}
//std::cout << "Putting combiner gate with nvals = " << gate->nvals << std::endl;
@@ -172,25 +174,24 @@ uint32_t ABYCircuit::PutCombinerGate(std::vector input) {
if (gate->nvals > m_nMaxVectorSize)
m_nMaxVectorSize = gate->nvals;
- return m_nNextFreeGate++;
+ return currentGateId();
}
//gatelenghts is defaulted to NULL
uint32_t ABYCircuit::PutSplitterGate(uint32_t input, uint32_t pos, uint32_t bitlen) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_SPLIT, input);
+ GATE* gate = InitGate(G_SPLIT, input);
gate->gs.sinput.pos = pos;
gate->nvals = bitlen;
- return m_nNextFreeGate++;
+ return currentGateId();
}
//gatelenghts is defaulted to NULL
std::vector ABYCircuit::PutSplitterGate(uint32_t input, std::vector bitlen) {
- uint32_t nvals = m_pGates[input].nvals;
+ uint32_t nvals = m_vGates[input].nvals;
if(bitlen.size() == 0) {
bitlen.resize(nvals, 1);
}
@@ -198,16 +199,6 @@ std::vector ABYCircuit::PutSplitterGate(uint32_t input, std::vectorgs.sinput.pos = ctr;
-
- gate->nvals = 1;
-
- ctr += gate->nvals;
- m_nNextFreeGate++;*/
outids[i] = PutSplitterGate(input, ctr, bitlen[i]);
ctr += bitlen[i];
//std::cout << "bitlen[" << i << "] = " << bitlen[i] << std::endl;
@@ -220,32 +211,30 @@ std::vector ABYCircuit::PutSplitterGate(uint32_t input, std::vector input, uint32_t pos) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_COMBINEPOS, input);
+ GATE* gate = InitGate(G_COMBINEPOS, input);
gate->nvals = input.size();
gate->gs.combinepos.pos = pos;
for (uint32_t i = 0; i < input.size(); i++) {
- assert(pos < m_pGates[input[i]].nvals);
+ assert(pos < m_vGates[input[i]].nvals);
}
if (gate->nvals > m_nMaxVectorSize)
m_nMaxVectorSize = gate->nvals;
- return m_nNextFreeGate++;
+ return currentGateId();
}
uint32_t ABYCircuit::PutSubsetGate(uint32_t input, uint32_t* posids, uint32_t nvals_out, bool copy_posids) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_SUBSET, input);
+ GATE* gate = InitGate(G_SUBSET, input);
gate->nvals = nvals_out;
- //std::cout << "Putting subset gate with nvals = " << nvals << " on pos " << m_nNextFreeGate << std::endl;
- //assert(gate->nvals <= m_pGates[input].nvals);
+ //std::cout << "Putting subset gate with nvals = " << nvals << " on pos " << currentGateId() << std::endl;
+ //assert(gate->nvals <= m_vGates[input].nvals);
gate->gs.sub_pos.copy_posids = copy_posids;
@@ -261,7 +250,7 @@ uint32_t ABYCircuit::PutSubsetGate(uint32_t input, uint32_t* posids, uint32_t nv
//std::cout << "copied" << std::endl;
//This check can be left out for performance reasons
- uint32_t inputnvals = m_pGates[input].nvals;
+ uint32_t inputnvals = m_vGates[input].nvals;
for (uint32_t i = 0; i < gate->nvals; i++) {
assert(posids[i] < inputnvals);
}
@@ -269,12 +258,11 @@ uint32_t ABYCircuit::PutSubsetGate(uint32_t input, uint32_t* posids, uint32_t nv
if (gate->nvals > m_nMaxVectorSize)
m_nMaxVectorSize = gate->nvals;
- return m_nNextFreeGate++;
+ return currentGateId();
}
uint32_t ABYCircuit::PutStructurizedCombinerGate(std::vector input, uint32_t pos_start, uint32_t pos_incr, uint32_t nvals) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_STRUCT_COMBINE, input);
+ GATE* gate = InitGate(G_STRUCT_COMBINE, input);
gate->nvals = nvals;
@@ -284,28 +272,27 @@ uint32_t ABYCircuit::PutStructurizedCombinerGate(std::vector input, ui
/*std::cout << "From " << pos_start << " incr: " << pos_incr << " for " << nvals << " vals with max = ";
for (uint32_t i = 0; i < input.size(); i++) {
- std::cout << m_pGates[input[i]].nvals << "; ";
- //assert(pos_start + ((nvals-1) * pos_incr) <= m_pGates[input[i]].nvals);
+ std::cout << m_vGates[input[i]].nvals << "; ";
+ //assert(pos_start + ((nvals-1) * pos_incr) <= m_vGates[input[i]].nvals);
}
std::cout << std::endl;*/
if (gate->nvals > m_nMaxVectorSize)
m_nMaxVectorSize = gate->nvals;
- return m_nNextFreeGate++;
+ return currentGateId();
}
uint32_t ABYCircuit::PutRepeaterGate(uint32_t input, uint32_t nvals) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_REPEAT, input);
+ GATE* gate = InitGate(G_REPEAT, input);
gate->nvals = nvals;
if (gate->nvals > m_nMaxVectorSize)
m_nMaxVectorSize = gate->nvals;
- return m_nNextFreeGate++;
+ return currentGateId();
}
std::vector ABYCircuit::PutRepeaterGate(std::vector input, uint32_t nvals) {
@@ -317,68 +304,63 @@ std::vector ABYCircuit::PutRepeaterGate(std::vector input, u
}
uint32_t ABYCircuit::PutPermutationGate(std::vector input, uint32_t* positions) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_PERM, input);
+ GATE* gate = InitGate(G_PERM, input);
gate->nvals = input.size();
gate->gs.perm.posids = (uint32_t*) malloc(sizeof(uint32_t) * gate->nvals);
for (uint32_t i = 0; i < input.size(); i++) {
- assert(positions[i] < m_pGates[input[i]].nvals);
+ assert(positions[i] < m_vGates[input[i]].nvals);
gate->gs.perm.posids[i] = positions[i];
}
if (gate->nvals > m_nMaxVectorSize)
m_nMaxVectorSize = gate->nvals;
- return m_nNextFreeGate++;
+ return currentGateId();
}
uint32_t ABYCircuit::PutUniversalGate(uint32_t inleft, uint32_t inright, uint32_t op_id, uint32_t nrounds) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_UNIV, inleft, inright);
+ GATE* gate = InitGate(G_UNIV, inleft, inright);
- gate->nvals = std::min(m_pGates[inleft].nvals, m_pGates[inright].nvals);
+ gate->nvals = std::min(m_vGates[inleft].nvals, m_vGates[inright].nvals);
gate->nrounds = nrounds;
gate->gs.ttable = op_id;
#ifdef DEBUG_CIRCUIT_CONSTRUCTION
- cout << "New Universal Gate with id: " << m_nNextFreeGate << ", left in = " << inleft << ", right in = " << inright << ", nvals = " << gate->nvals <<
+ cout << "New Universal Gate with id: " << currentGateId() << ", left in = " << inleft << ", right in = " << inright << ", nvals = " << gate->nvals <<
", depth = " << gate->depth << ", sharingsize = " << gate->sharebitlen << ", nrounds = " << gate->nrounds << ", and operation_id = " << op_id << endl;
#endif
- return m_nNextFreeGate++;
+ return currentGateId();
}
uint32_t ABYCircuit::PutOUTGate(uint32_t in, e_role dst, uint32_t rounds) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_OUT, in);
+ GATE* gate = InitGate(G_OUT, in);
- gate->nvals = m_pGates[in].nvals;
+ gate->nvals = m_vGates[in].nvals;
gate->gs.oshare.dst = dst;
gate->nrounds = rounds;
- return m_nNextFreeGate++;
+ return currentGateId();
}
uint32_t ABYCircuit::PutSharedOUTGate(uint32_t in) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_SHARED_OUT, in);
+ GATE* gate = InitGate(G_SHARED_OUT, in);
- gate->nvals = m_pGates[in].nvals;
+ gate->nvals = m_vGates[in].nvals;
gate->nrounds = 0;
- return m_nNextFreeGate++;
+ return currentGateId();
}
uint32_t ABYCircuit::PutINGate(e_sharing context, uint32_t nvals, uint32_t sharebitlen, e_role src, uint32_t rounds) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_IN);
+ GATE* gate = InitGate(G_IN);
gate->nvals = nvals;
gate->depth = 0;
@@ -391,12 +373,11 @@ uint32_t ABYCircuit::PutINGate(e_sharing context, uint32_t nvals, uint32_t share
if (gate->nvals > m_nMaxVectorSize)
m_nMaxVectorSize = gate->nvals;
- return m_nNextFreeGate++;
+ return currentGateId();
}
uint32_t ABYCircuit::PutSharedINGate(e_sharing context, uint32_t nvals, uint32_t sharebitlen) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_SHARED_IN);
+ GATE* gate = InitGate(G_SHARED_IN);
gate->nvals = nvals;
gate->depth = 0;
@@ -408,13 +389,12 @@ uint32_t ABYCircuit::PutSharedINGate(e_sharing context, uint32_t nvals, uint32_t
if (gate->nvals > m_nMaxVectorSize)
m_nMaxVectorSize = gate->nvals;
- return m_nNextFreeGate++;
+ return currentGateId();
}
uint32_t ABYCircuit::PutConstantGate(e_sharing context, UGATE_T val, uint32_t nvals, uint32_t sharebitlen) {
assert(nvals > 0 && sharebitlen > 0);
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_CONSTANT);
+ GATE* gate = InitGate(G_CONSTANT);
gate->gs.constval = val;
gate->depth = 0;
gate->nvals = nvals;
@@ -422,34 +402,32 @@ uint32_t ABYCircuit::PutConstantGate(e_sharing context, UGATE_T val, uint32_t nv
gate->sharebitlen = sharebitlen;
gate->nrounds = 0;
- if (gate->nvals > m_nMaxVectorSize)
+ if(gate->nvals > m_nMaxVectorSize) {
m_nMaxVectorSize = gate->nvals;
-
- return m_nNextFreeGate++;
+ }
+ return currentGateId();
}
uint32_t ABYCircuit::PutINVGate(uint32_t in) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_INV, in);
+ GATE* gate = InitGate(G_INV, in);
- gate->nvals = m_pGates[in].nvals;
+ gate->nvals = m_vGates[in].nvals;
- return m_nNextFreeGate++;
+ return currentGateId();
}
uint32_t ABYCircuit::PutCONVGate(std::vector in, uint32_t nrounds, e_sharing dst, uint32_t sharebitlen) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_CONV, in);
+ GATE* gate = InitGate(G_CONV, in);
gate->sharebitlen = sharebitlen;
gate->context = dst;
gate->nrounds = nrounds;
- gate->nvals = m_pGates[in[0]].nvals;
+ gate->nvals = m_vGates[in[0]].nvals;
for (uint32_t i = 0; i < in.size(); i++) {
- assert(gate->nvals == m_pGates[in[i]].nvals);
+ assert(gate->nvals == m_vGates[in[i]].nvals);
}
- return m_nNextFreeGate++;
+ return currentGateId();
}
std::vector ABYCircuit::PutOUTGate(std::vector in, e_role dst, uint32_t rounds) {
@@ -470,8 +448,7 @@ std::vector ABYCircuit::PutSharedOUTGate(std::vector in) {
uint32_t ABYCircuit::PutCallbackGate(std::vector in, uint32_t rounds, void (*callback)(GATE*, void*), void* infos,
uint32_t nvals) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_CALLBACK, in);
+ GATE* gate = InitGate(G_CALLBACK, in);
gate->gs.cbgate.callback = callback;
gate->gs.cbgate.infos = infos;
@@ -480,13 +457,12 @@ uint32_t ABYCircuit::PutCallbackGate(std::vector in, uint32_t rounds,
gate->nvals = nvals;
- return m_nNextFreeGate++;
+ return currentGateId();
}
uint32_t ABYCircuit::PutTruthTableGate(std::vector in, uint32_t rounds, uint32_t out_bits,
uint64_t* truth_table) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_TT, in);
+ GATE* gate = InitGate(G_TT, in);
assert(in.size() < 32);
assert(in.size() > 0);
@@ -498,31 +474,30 @@ uint32_t ABYCircuit::PutTruthTableGate(std::vector in, uint32_t rounds
gate->nrounds = rounds;
- gate->nvals = m_pGates[in[0]].nvals*out_bits;
+ gate->nvals = m_vGates[in[0]].nvals*out_bits;
for(uint32_t i = 1; i < in.size(); i++) {
- assert(gate->nvals/out_bits == m_pGates[in[i]].nvals);
+ assert(gate->nvals/out_bits == m_vGates[in[i]].nvals);
}
#ifdef DEBUGBOOL_NO_MT
std::cout << "Putting TT gate at depth " << gate->depth << ", predec. ";
for(uint32_t i = 0; i < in.size(); i++) {
- std::cout << i << ": " << get_gate_type_name(m_pGates[in[0]].type) << " has depth "
- << m_pGates[in[0]].depth << " and rounds " << m_pGates[in[0]].nrounds << ", ";
+ std::cout << i << ": " << get_gate_type_name(m_vGates[in[0]].type) << " has depth "
+ << m_vGates[in[0]].depth << " and rounds " << m_vGates[in[0]].nrounds << ", ";
}
std::cout << "my nvals = " << gate->nvals << " and " << out_bits << " output bits "<< std::endl;
#endif
- return m_nNextFreeGate++;
+ return currentGateId();
}
//TODO change gs.infostr to string
uint32_t ABYCircuit::PutPrintValGate(std::vector in, std::string infostr) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_PRINT_VAL, in);
+ GATE* gate = InitGate(G_PRINT_VAL, in);
- gate->nvals = m_pGates[in[0]].nvals;
+ gate->nvals = m_vGates[in[0]].nvals;
for(uint32_t i = 1; i < in.size(); i++) {
- assert(gate->nvals == m_pGates[in[i]].nvals);
+ assert(gate->nvals == m_vGates[in[i]].nvals);
}
// buffer is freed in Sharing::EvaluatePrintValGate
@@ -531,17 +506,16 @@ uint32_t ABYCircuit::PutPrintValGate(std::vector in, std::string infos
buffer[infostr.size()] = '\0';
gate->gs.infostr = buffer;
- return m_nNextFreeGate++;
+ return currentGateId();
}
uint32_t ABYCircuit::PutAssertGate(std::vector in, uint32_t bitlen, UGATE_T* assert_val) {
- GATE* gate = m_pGates + m_nNextFreeGate;
- InitGate(gate, G_ASSERT, in);
+ GATE* gate = InitGate(G_ASSERT, in);
- gate->nvals = m_pGates[in[0]].nvals;
+ gate->nvals = m_vGates[in[0]].nvals;
for(uint32_t i = 1; i < in.size(); i++) {
- assert(gate->nvals == m_pGates[in[i]].nvals);
+ assert(gate->nvals == m_vGates[in[i]].nvals);
}
//initialize a new block of memory and copy the assert_val into this block
@@ -549,7 +523,7 @@ uint32_t ABYCircuit::PutAssertGate(std::vector in, uint32_t bitlen, UG
gate->gs.assertval = (UGATE_T*) calloc(ugatelen, sizeof(UGATE_T));
memcpy(gate->gs.assertval, assert_val, ugatelen * sizeof(UGATE_T));
- return m_nNextFreeGate++;
+ return currentGateId();
}
@@ -570,8 +544,8 @@ uint32_t ABYCircuit::PutAssertGate(std::vector in, uint32_t bitlen, UG
#ifdef DEBUGBOOL_NO_MT
std::cout << "Putting mutli output TT gate at depth " << gate->depth << ", predec. ";
for(uint32_t i = 0; i < in.size(); i++) {
- std::cout << i << ": " << get_gate_type_name(m_pGates[in[0]].type) << " has depth "
- << m_pGates[in[0]].depth << " and rounds " << m_pGates[in[0]].nrounds << ", ";
+ std::cout << i << ": " << get_gate_type_name(m_vGates[in[0]].type) << " has depth "
+ << m_vGates[in[0]].depth << " and rounds " << m_vGates[in[0]].nrounds << ", ";
}
std::cout << "my nvals = " << gate->nvals << std::endl;
#endif
@@ -583,11 +557,11 @@ uint32_t ABYCircuit::PutAssertGate(std::vector in, uint32_t bitlen, UG
void ABYCircuit::ExportCircuitInBristolFormat(std::vector ingates_client, std::vector ingates_server,
std::vector outgates, const char* filename) {
//Maps an ABY gate-id into a Bristol gate-id
- std::vector gate_id_map(m_nNextFreeGate, -1);
+ std::vector gate_id_map(m_vGates.size(), -1);
//The ABY output gates are not requried and the circuit has to make sure that the output gates appear last
std::vector outgate_map(outgates.size());
//There are no constants in the Bristol circuit and hence they need to be propagated using this vector. Init with -1 to show that input is not a constant.
- std::vector constant_map(m_nNextFreeGate, -1);
+ std::vector constant_map(m_vGates.size(), -1);
//keeps track of the next free gate id in the Bristol circuit
uint32_t bristol_gate_ctr = 0;
//a temporary value for assigning the correct id to output gates
@@ -624,7 +598,7 @@ void ABYCircuit::ExportCircuitInBristolFormat(std::vector ingates_clie
//Remove the ABY output gates
for(uint32_t i = 0; i < outgates.size(); i++) {
- outgate_map[i] = m_pGates[outgates[i]].ingates.inputs.parent;
+ outgate_map[i] = m_vGates[outgates[i]].ingates.inputs.parent;
}
//Check whether any input gates are also output gates. If so, create an extra XOR gate that evaluates to zero and give the output gates again
@@ -650,8 +624,8 @@ void ABYCircuit::ExportCircuitInBristolFormat(std::vector ingates_clie
total_bristol_gates = bristol_gate_ctr + n_in_out_gates;
//count the total number of gates in the Bristol circuit prior to printing the circuit
- for(uint32_t i = 0; i < m_nNextFreeGate; i++) {
- if(m_pGates[i].type == G_LIN || m_pGates[i].type == G_NON_LIN || m_pGates[i].type == G_INV) {
+ for(uint32_t i = 0; i < m_vGates.size(); i++) {
+ if(m_vGates[i].type == G_LIN || m_vGates[i].type == G_NON_LIN || m_vGates[i].type == G_INV) {
total_bristol_gates++;
}
}
@@ -683,7 +657,7 @@ void ABYCircuit::ExportCircuitInBristolFormat(std::vector ingates_clie
}
//Now go through all gates in the ABY circuit
- for(uint32_t i = 0; i < m_nNextFreeGate; i++) {
+ for(uint32_t i = 0; i < m_vGates.size(); i++) {
out_gate_present = false;
//skip the output gates since they need to be in order for the Bristol file format
for(uint32_t j = 0; j < outgate_map.size(); j++) {
@@ -707,41 +681,41 @@ void ABYCircuit::ExportCircuitInBristolFormat(std::vector ingates_clie
void ABYCircuit::ExportGateInBristolFormat(uint32_t gateid, uint32_t& next_gate_id, std::vector& gate_id_map,
std::vector& constant_map, std::ofstream& outfile) {
- if(m_pGates[gateid].type == G_IN) {
+ if(m_vGates[gateid].type == G_IN) {
//Ignore input gates
- } else if(m_pGates[gateid].type == G_LIN) {
+ } else if(m_vGates[gateid].type == G_LIN) {
//enter gate into map
- if(constant_map[m_pGates[gateid].ingates.inputs.twin.left] + constant_map[m_pGates[gateid].ingates.inputs.twin.right] != -2) {
+ if(constant_map[m_vGates[gateid].ingates.inputs.twin.left] + constant_map[m_vGates[gateid].ingates.inputs.twin.right] != -2) {
CheckAndPropagateConstant(gateid, next_gate_id, gate_id_map, constant_map, outfile);
} else {
- outfile << "2 1 " << gate_id_map[m_pGates[gateid].ingates.inputs.twin.left] << " " << gate_id_map[m_pGates[gateid].ingates.inputs.twin.right] << " " << next_gate_id << " XOR"<< std::endl;
+ outfile << "2 1 " << gate_id_map[m_vGates[gateid].ingates.inputs.twin.left] << " " << gate_id_map[m_vGates[gateid].ingates.inputs.twin.right] << " " << next_gate_id << " XOR"<< std::endl;
gate_id_map[gateid] = next_gate_id++;
}
- } else if(m_pGates[gateid].type == G_NON_LIN) {
- if(constant_map[m_pGates[gateid].ingates.inputs.twin.left] + constant_map[m_pGates[gateid].ingates.inputs.twin.right] != -2) {
+ } else if(m_vGates[gateid].type == G_NON_LIN) {
+ if(constant_map[m_vGates[gateid].ingates.inputs.twin.left] + constant_map[m_vGates[gateid].ingates.inputs.twin.right] != -2) {
CheckAndPropagateConstant(gateid, next_gate_id, gate_id_map, constant_map, outfile);
} else {
- outfile << "2 1 " << gate_id_map[m_pGates[gateid].ingates.inputs.twin.left] << " " << gate_id_map[m_pGates[gateid].ingates.inputs.twin.right] << " " << next_gate_id << " AND"<< std::endl;
+ outfile << "2 1 " << gate_id_map[m_vGates[gateid].ingates.inputs.twin.left] << " " << gate_id_map[m_vGates[gateid].ingates.inputs.twin.right] << " " << next_gate_id << " AND"<< std::endl;
gate_id_map[gateid] = next_gate_id++;
}
- } else if(m_pGates[gateid].type == G_INV) {
- if(constant_map[m_pGates[gateid].ingates.inputs.parent] != -1) {
- if(constant_map[m_pGates[gateid].ingates.inputs.parent] == 0) {
- constant_map[gateid] = constant_map[m_pGates[gateid].ingates.inputs.parent];
+ } else if(m_vGates[gateid].type == G_INV) {
+ if(constant_map[m_vGates[gateid].ingates.inputs.parent] != -1) {
+ if(constant_map[m_vGates[gateid].ingates.inputs.parent] == 0) {
+ constant_map[gateid] = constant_map[m_vGates[gateid].ingates.inputs.parent];
} else {
- constant_map[gateid] = constant_map[m_pGates[gateid].ingates.inputs.parent] ^ 1;
+ constant_map[gateid] = constant_map[m_vGates[gateid].ingates.inputs.parent] ^ 1;
}
} else {
- outfile << "1 1 " << gate_id_map[m_pGates[gateid].ingates.inputs.parent] << " " << next_gate_id << " INV"<< std::endl;
+ outfile << "1 1 " << gate_id_map[m_vGates[gateid].ingates.inputs.parent] << " " << next_gate_id << " INV"<< std::endl;
gate_id_map[gateid] = next_gate_id++;
}
- } else if(m_pGates[gateid].type == G_CONSTANT) {
- assert(m_pGates[gateid].gs.constval == 0 || m_pGates[gateid].gs.constval == 1);
- constant_map[gateid] = m_pGates[gateid].gs.constval;
- } else if(m_pGates[gateid].type == G_OUT) {
+ } else if(m_vGates[gateid].type == G_CONSTANT) {
+ assert(m_vGates[gateid].gs.constval == 0 || m_vGates[gateid].gs.constval == 1);
+ constant_map[gateid] = m_vGates[gateid].gs.constval;
+ } else if(m_vGates[gateid].type == G_OUT) {
//Ignore input gates
} else {
- std::cerr << "Gate type not available in Bristol format: " << get_gate_type_name(m_pGates[gateid].type) << ". Program exits. " << std::endl;
+ std::cerr << "Gate type not available in Bristol format: " << get_gate_type_name(m_vGates[gateid].type) << ". Program exits. " << std::endl;
outfile.close();
std::exit(EXIT_FAILURE);
}
@@ -751,71 +725,71 @@ void ABYCircuit::CheckAndPropagateConstant(uint32_t gateid, uint32_t& next_gate_
std::vector& constant_map, std::ofstream& outfile) {
//both gates are constant zero
- if(constant_map[m_pGates[gateid].ingates.inputs.twin.left] == 0 && constant_map[m_pGates[gateid].ingates.inputs.twin.right] == 0) {
+ if(constant_map[m_vGates[gateid].ingates.inputs.twin.left] == 0 && constant_map[m_vGates[gateid].ingates.inputs.twin.right] == 0) {
constant_map[gateid] = 0;
return;
}
//both gates are constant one
- if(constant_map[m_pGates[gateid].ingates.inputs.twin.left] + constant_map[m_pGates[gateid].ingates.inputs.twin.right] == 2) {
- if(m_pGates[gateid].type == G_LIN) {
+ if(constant_map[m_vGates[gateid].ingates.inputs.twin.left] + constant_map[m_vGates[gateid].ingates.inputs.twin.right] == 2) {
+ if(m_vGates[gateid].type == G_LIN) {
constant_map[gateid] = 0;
- } else if( m_pGates[gateid].type == G_NON_LIN) {
+ } else if( m_vGates[gateid].type == G_NON_LIN) {
constant_map[gateid] = 1;
}
return;
}
//one gate is constant one, the second constant zero
- if(constant_map[m_pGates[gateid].ingates.inputs.twin.left] + constant_map[m_pGates[gateid].ingates.inputs.twin.right] == 1) {
- if(m_pGates[gateid].type == G_LIN) {
+ if(constant_map[m_vGates[gateid].ingates.inputs.twin.left] + constant_map[m_vGates[gateid].ingates.inputs.twin.right] == 1) {
+ if(m_vGates[gateid].type == G_LIN) {
constant_map[gateid] = 1;
- } else if( m_pGates[gateid].type == G_NON_LIN) {
+ } else if( m_vGates[gateid].type == G_NON_LIN) {
constant_map[gateid] = 0;
}
return;
}
//one gate is has a constant zero, the other gate is not a constant
- if(constant_map[m_pGates[gateid].ingates.inputs.twin.left] + constant_map[m_pGates[gateid].ingates.inputs.twin.right] == -1) {
- if(m_pGates[gateid].type == G_LIN) {
- if(constant_map[m_pGates[gateid].ingates.inputs.twin.left] == -1) {
- gate_id_map[gateid] = gate_id_map[m_pGates[gateid].ingates.inputs.twin.left];
+ if(constant_map[m_vGates[gateid].ingates.inputs.twin.left] + constant_map[m_vGates[gateid].ingates.inputs.twin.right] == -1) {
+ if(m_vGates[gateid].type == G_LIN) {
+ if(constant_map[m_vGates[gateid].ingates.inputs.twin.left] == -1) {
+ gate_id_map[gateid] = gate_id_map[m_vGates[gateid].ingates.inputs.twin.left];
} else {
- gate_id_map[gateid] = gate_id_map[m_pGates[gateid].ingates.inputs.twin.right];
+ gate_id_map[gateid] = gate_id_map[m_vGates[gateid].ingates.inputs.twin.right];
}
- } else if( m_pGates[gateid].type == G_NON_LIN) {
+ } else if( m_vGates[gateid].type == G_NON_LIN) {
constant_map[gateid] = 0;
}
return;
}
//one gate is has a constant one, the other gate is not a constant
- if(constant_map[m_pGates[gateid].ingates.inputs.twin.left] + constant_map[m_pGates[gateid].ingates.inputs.twin.right] == 0) {
- if(m_pGates[gateid].type == G_LIN) {
- if(constant_map[m_pGates[gateid].ingates.inputs.twin.left] == -1) {
- outfile << "1 1 " << gate_id_map[m_pGates[gateid].ingates.inputs.twin.left] << " " << next_gate_id << " INV"<< std::endl;
+ if(constant_map[m_vGates[gateid].ingates.inputs.twin.left] + constant_map[m_vGates[gateid].ingates.inputs.twin.right] == 0) {
+ if(m_vGates[gateid].type == G_LIN) {
+ if(constant_map[m_vGates[gateid].ingates.inputs.twin.left] == -1) {
+ outfile << "1 1 " << gate_id_map[m_vGates[gateid].ingates.inputs.twin.left] << " " << next_gate_id << " INV"<< std::endl;
gate_id_map[gateid] = next_gate_id++;
} else {
- outfile << "1 1 " << gate_id_map[m_pGates[gateid].ingates.inputs.twin.right] << " " << next_gate_id << " INV"<< std::endl;
+ outfile << "1 1 " << gate_id_map[m_vGates[gateid].ingates.inputs.twin.right] << " " << next_gate_id << " INV"<< std::endl;
gate_id_map[gateid] = next_gate_id++;
}
- } else if( m_pGates[gateid].type == G_NON_LIN) {
- if(constant_map[m_pGates[gateid].ingates.inputs.twin.left] == -1) {
- gate_id_map[gateid] = gate_id_map[m_pGates[gateid].ingates.inputs.twin.left];
+ } else if( m_vGates[gateid].type == G_NON_LIN) {
+ if(constant_map[m_vGates[gateid].ingates.inputs.twin.left] == -1) {
+ gate_id_map[gateid] = gate_id_map[m_vGates[gateid].ingates.inputs.twin.left];
} else {
- gate_id_map[gateid] = gate_id_map[m_pGates[gateid].ingates.inputs.twin.right];
+ gate_id_map[gateid] = gate_id_map[m_vGates[gateid].ingates.inputs.twin.right];
}
}
return;
}
//The code must have stopped before from one of the conditions
assert(false);
- //std::cout << "Ran through code and missed something for " << constant_map[m_pGates[gateid].ingates.inputs.twin.left] << ", " << constant_map[m_pGates[gateid].ingates.inputs.twin.right] << std::endl;
+ //std::cout << "Ran through code and missed something for " << constant_map[m_vGates[gateid].ingates.inputs.twin.left] << ", " << constant_map[m_vGates[gateid].ingates.inputs.twin.right] << std::endl;
}
inline void ABYCircuit::MarkGateAsUsed(uint32_t gateid, uint32_t uses) {
- m_pGates[gateid].nused += uses;
+ m_vGates[gateid].nused += uses;
}
@@ -831,8 +805,7 @@ uint32_t FindBitLenPositionInVec(uint32_t bitlen, non_lin_vec_ctx* list, uint32_
}
void ABYCircuit::Reset() {
- memset(m_pGates, 0, sizeof(GATE) * m_nMaxGates);
- m_nNextFreeGate = 0;
+ m_vGates.clear();
m_nMaxVectorSize = 1;
m_nMaxDepth = 0;
}
diff --git a/src/abycore/circuit/abycircuit.h b/src/abycore/circuit/abycircuit.h
index d0f6367a..30c7571f 100644
--- a/src/abycore/circuit/abycircuit.h
+++ b/src/abycore/circuit/abycircuit.h
@@ -2,17 +2,17 @@
\file abycircuit.h
\author michael.zohner@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief ABYCircuit class.
*/
#ifndef __ABYCIRCUIT_H_
@@ -186,15 +186,15 @@ uint32_t FindBitLenPositionInVec(uint32_t bitlen, non_lin_vec_ctx* list, uint32_
class ABYCircuit {
public:
- ABYCircuit(uint32_t maxgates);
+ ABYCircuit(uint32_t reservegates);
virtual ~ABYCircuit() {
Cleanup();
}
void Cleanup();
void Reset();
- GATE* Gates() {
- return m_pGates;
+ inline std::vector& GatesVec() {
+ return m_vGates;
}
uint32_t PutPrimitiveGate(e_gatetype type, uint32_t inleft, uint32_t inright, uint32_t rounds);
@@ -232,7 +232,7 @@ class ABYCircuit {
uint32_t PutAssertGate(std::vector in, uint32_t bitlen, UGATE_T* assert_val);
uint32_t GetGateHead() {
- return m_nNextFreeGate;
+ return m_vGates.size();
}
uint32_t GetTotalDepth() {
@@ -248,11 +248,11 @@ class ABYCircuit {
std::vector outgates, const char* filename);
private:
-
- inline void InitGate(GATE* gate, e_gatetype type);
- inline void InitGate(GATE* gate, e_gatetype type, uint32_t ina);
- inline void InitGate(GATE* gate, e_gatetype type, uint32_t ina, uint32_t inb);
- inline void InitGate(GATE* gate, e_gatetype type, std::vector& inputs);
+ inline uint32_t currentGateId();
+ inline GATE* InitGate(e_gatetype type);
+ inline GATE* InitGate(e_gatetype type, uint32_t ina);
+ inline GATE* InitGate(e_gatetype type, uint32_t ina, uint32_t inb);
+ inline GATE* InitGate(e_gatetype type, std::vector& inputs);
inline uint32_t GetNumRounds(e_gatetype type, e_sharing context);
inline void MarkGateAsUsed(uint32_t gateid, uint32_t uses = 1);
@@ -262,10 +262,8 @@ class ABYCircuit {
void CheckAndPropagateConstant(uint32_t gateid, uint32_t& next_gate_id, std::vector& gate_id_map,
std::vector& constant_map, std::ofstream& outfile);
- GATE* m_pGates;
- uint32_t m_nNextFreeGate; // points to the current first unused gate
+ std::vector m_vGates;
uint32_t m_nMaxVectorSize; // The maximum vector size in bits, required for correctly instantiating the 0 and 1 gates
- uint32_t m_nMaxGates; // Maximal number of gates that is allowed
uint32_t m_nMaxDepth; // maximum depth encountered in the circuit
};
diff --git a/src/abycore/circuit/arithmeticcircuits.cpp b/src/abycore/circuit/arithmeticcircuits.cpp
index f9fd2d79..7fcc4373 100644
--- a/src/abycore/circuit/arithmeticcircuits.cpp
+++ b/src/abycore/circuit/arithmeticcircuits.cpp
@@ -2,17 +2,17 @@
\file arithmeticcircuits.cpp
\author michael.zohner@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief Arithmetic Circuit class.
*/
@@ -50,7 +50,7 @@ share* ArithmeticCircuit::PutMULGate(share* ina, share* inb) {
uint32_t ArithmeticCircuit::PutMULGate(uint32_t inleft, uint32_t inright) {
// check if one of the inputs is a const gate and then use a MULCONST gate
// instead.
- if (m_pGates[inleft].type == G_CONSTANT || m_pGates[inright].type == G_CONSTANT) {
+ if (m_vGates[inleft].type == G_CONSTANT || m_vGates[inright].type == G_CONSTANT) {
#ifdef DEBUGARITH
std::cout << "MUL(" << inleft << ", " << inright <<
"): Constant factor present, putting a MULCONST gate instead." << std::endl;
@@ -61,9 +61,9 @@ uint32_t ArithmeticCircuit::PutMULGate(uint32_t inleft, uint32_t inright) {
uint32_t gateid = m_cCircuit->PutPrimitiveGate(G_NON_LIN, inleft, inright, m_nRoundsAND);
UpdateInteractiveQueue(gateid);
- if (m_pGates[gateid].nvals != INT_MAX) {
+ if (m_vGates[gateid].nvals != INT_MAX) {
//TODO implement for NON_LIN_VEC
- m_nMULs += m_pGates[gateid].nvals;
+ m_nMULs += m_vGates[gateid].nvals;
}
return gateid;
}
@@ -76,8 +76,8 @@ share* ArithmeticCircuit::PutMULCONSTGate(share* ina, share* inb) {
uint32_t ArithmeticCircuit::PutMULCONSTGate(uint32_t inleft, uint32_t inright) {
// One of the gates needs to be a constant gate
- assert (m_pGates[inleft].type == G_CONSTANT || m_pGates[inright].type == G_CONSTANT);
- if (m_pGates[inleft].type == G_CONSTANT && m_pGates[inright].type == G_CONSTANT) {
+ assert (m_vGates[inleft].type == G_CONSTANT || m_vGates[inright].type == G_CONSTANT);
+ if (m_vGates[inleft].type == G_CONSTANT && m_vGates[inright].type == G_CONSTANT) {
std::cerr << "MULCONST(" << inleft << "," << inright <<
"): Both sides are constants, consider just multiplying their values before adding them as CONST gates.\n";
}
@@ -119,17 +119,17 @@ uint32_t ArithmeticCircuit::PutINGate(e_role src) {
switch (src) {
case SERVER:
m_vInputGates[0].push_back(gateid);
- m_vInputBits[0] += (m_pGates[gateid].nvals * m_nShareBitLen);
+ m_vInputBits[0] += (m_vGates[gateid].nvals * m_nShareBitLen);
break;
case CLIENT:
m_vInputGates[1].push_back(gateid);
- m_vInputBits[1] += (m_pGates[gateid].nvals * m_nShareBitLen);
+ m_vInputBits[1] += (m_vGates[gateid].nvals * m_nShareBitLen);
break;
case ALL:
m_vInputGates[0].push_back(gateid);
m_vInputGates[1].push_back(gateid);
- m_vInputBits[0] += (m_pGates[gateid].nvals * m_nShareBitLen);
- m_vInputBits[1] += (m_pGates[gateid].nvals * m_nShareBitLen);
+ m_vInputBits[0] += (m_vGates[gateid].nvals * m_nShareBitLen);
+ m_vInputBits[1] += (m_vGates[gateid].nvals * m_nShareBitLen);
break;
default:
std::cerr << "Role not recognized" << std::endl;
@@ -151,17 +151,17 @@ uint32_t ArithmeticCircuit::PutSIMDINGate(uint32_t ninvals, e_role src) {
switch (src) {
case SERVER:
m_vInputGates[0].push_back(gateid);
- m_vInputBits[0] += (m_pGates[gateid].nvals * m_nShareBitLen);
+ m_vInputBits[0] += (m_vGates[gateid].nvals * m_nShareBitLen);
break;
case CLIENT:
m_vInputGates[1].push_back(gateid);
- m_vInputBits[1] += (m_pGates[gateid].nvals * m_nShareBitLen);
+ m_vInputBits[1] += (m_vGates[gateid].nvals * m_nShareBitLen);
break;
case ALL:
m_vInputGates[0].push_back(gateid);
m_vInputGates[1].push_back(gateid);
- m_vInputBits[0] += (m_pGates[gateid].nvals * m_nShareBitLen);
- m_vInputBits[1] += (m_pGates[gateid].nvals * m_nShareBitLen);
+ m_vInputBits[0] += (m_vGates[gateid].nvals * m_nShareBitLen);
+ m_vInputBits[1] += (m_vGates[gateid].nvals * m_nShareBitLen);
break;
default:
std::cerr << "Role not recognized" << std::endl;
@@ -179,12 +179,12 @@ uint32_t ArithmeticCircuit::PutSharedSIMDINGate(uint32_t ninvals) {
}
-share* ArithmeticCircuit::PutDummyINGate(uint32_t bitlen) {
+share* ArithmeticCircuit::PutDummyINGate([[maybe_unused]] uint32_t bitlen) {
std::vector wires(1);
wires[0] = PutINGate((e_role) !m_eMyRole);
return new arithshare(wires, this);
}
-share* ArithmeticCircuit::PutDummySIMDINGate(uint32_t nvals, uint32_t bitlen) {
+share* ArithmeticCircuit::PutDummySIMDINGate(uint32_t nvals, [[maybe_unused]] uint32_t bitlen) {
std::vector wires(1);
wires[0] = PutSIMDINGate(nvals, (e_role) !m_eMyRole);
return new arithshare(wires, this);
@@ -199,17 +199,17 @@ uint32_t ArithmeticCircuit::PutOUTGate(uint32_t parentid, e_role dst) {
switch (dst) {
case SERVER:
m_vOutputGates[0].push_back(gateid);
- m_vOutputBits[0] += (m_pGates[gateid].nvals * m_nShareBitLen);
+ m_vOutputBits[0] += (m_vGates[gateid].nvals * m_nShareBitLen);
break;
case CLIENT:
m_vOutputGates[1].push_back(gateid);
- m_vOutputBits[1] += (m_pGates[gateid].nvals * m_nShareBitLen);
+ m_vOutputBits[1] += (m_vGates[gateid].nvals * m_nShareBitLen);
break;
case ALL:
m_vOutputGates[0].push_back(gateid);
m_vOutputGates[1].push_back(gateid);
- m_vOutputBits[0] += (m_pGates[gateid].nvals * m_nShareBitLen);
- m_vOutputBits[1] += (m_pGates[gateid].nvals * m_nShareBitLen);
+ m_vOutputBits[0] += (m_vGates[gateid].nvals * m_nShareBitLen);
+ m_vOutputBits[1] += (m_vGates[gateid].nvals * m_nShareBitLen);
break;
default:
std::cerr << "Role not recognized" << std::endl;
@@ -251,7 +251,7 @@ uint32_t ArithmeticCircuit::PutINVGate(uint32_t parentid) {
uint32_t ArithmeticCircuit::PutCONVGate(std::vector parentids) {
uint32_t gateid = m_cCircuit->PutCONVGate(parentids, 2, S_ARITH, m_nShareBitLen);
UpdateInteractiveQueue(gateid);
- m_nCONVGates += m_pGates[gateid].nvals * parentids.size();
+ m_nCONVGates += m_vGates[gateid].nvals * parentids.size();
return gateid;
}
@@ -281,40 +281,79 @@ share* ArithmeticCircuit::PutCallbackGate(share* in, uint32_t rounds, void (*cal
return new arithshare(gateid, this);
}
-share* ArithmeticCircuit::PutTruthTableGate(share* in, uint64_t* ttable) {
- std::cerr << "PutTruthTableGate not implemented in ArithmeticCircuit!!" << std::endl;
- return NULL;
-}
-
-share* ArithmeticCircuit::PutTruthTableMultiOutputGate(share* in, uint32_t out_bits, uint64_t* ttable) {
- std::cerr << "PutTruthTableMultiOutputGate not implemented in ArithmeticCircuit!!" << std::endl;
- return NULL;
-}
-
share* ArithmeticCircuit::PutCONSGate(uint8_t* val, uint32_t bitlen) {
- //TODO
- std::cerr << "Not implemented yet!" << std::endl;
- return NULL; //new arithshare(0, this);
+ return PutSIMDCONSGate(1, val, bitlen);
}
+//TODO Test the gates properly
share* ArithmeticCircuit::PutSIMDCONSGate(uint32_t nvals, uint8_t* val, uint32_t bitlen) {
- //TODO
- std::cerr << "Not implemented yet!" << std::endl;
- return NULL; //new arithshare(0, this);
+ uint8_t sharebytes = m_nShareBitLen / 8;
+ uint32_t valamount = bitlen / m_nShareBitLen;
+ std::vector gateids(valamount);
+ for(uint32_t i = 0; i < valamount; ++i) {
+ UGATE_T one_val = 0;
+ for(uint8_t j = 0; j < sharebytes; ++j) {
+ one_val |= val[i * sharebytes + j] << (j * 8);
+ }
+ gateids[i] = PutConstantGate(one_val, nvals);
+ }
+ return new arithshare(gateids, this);
}
share* ArithmeticCircuit::PutCONSGate(uint32_t* val, uint32_t bitlen) {
- //TODO
- std::cerr << "Not implemented yet!" << std::endl;
- return NULL; //new arithshare(0, this);
+ return PutSIMDCONSGate(1, val, bitlen);
}
+//TODO Test the gates properly
share* ArithmeticCircuit::PutSIMDCONSGate(uint32_t nvals, uint32_t* val, uint32_t bitlen) {
- //TODO
- std::cerr << "Not implemented yet!" << std::endl;
- return NULL; //new arithshare(0, this);
+ uint32_t valamount = bitlen / m_nShareBitLen;
+ std::vector gateids(valamount);
+ if(m_nShareBitLen == 64) {
+ for(uint32_t i = 0; i < valamount; ++i) {
+ gateids[i] = PutConstantGate(((UGATE_T) val[i * 2]) + (((UGATE_T) val[i * 2 + 1]) << 32), nvals);
+ }
+ } else if(m_nShareBitLen == 32){
+ for(uint32_t i = 0; i < valamount; ++i) {
+ gateids[i] = PutConstantGate((UGATE_T) val[i], nvals);
+ }
+ } else if(m_nShareBitLen == 16) {
+ uint32_t loopamount = valamount / 2;
+ for(uint32_t i = 0; i < loopamount; ++i) {
+ gateids[i * 2] = PutConstantGate((UGATE_T) (val[i] & 0x0000FFFF), nvals);
+ gateids[i * 2 + 1] = PutConstantGate((UGATE_T) (val[i] & 0xFFFF0000) >> 16, nvals);
+ }
+ if(valamount % 2 == 1) {
+ uint32_t lastamount = valamount - 1;
+ gateids[lastamount] = PutConstantGate((UGATE_T) (val[loopamount] & 0x0000FFFF), nvals);
+ }
+ } else { //m_nShareBitLen == 8
+ uint32_t loopamount = valamount / 4;
+ for(uint32_t i = 0; i < loopamount; ++i) {
+ gateids[i * 4] = PutConstantGate((UGATE_T) (val[i] & 0x000000FF), nvals);
+ gateids[i * 4 + 1] = PutConstantGate((UGATE_T) (val[i] & 0x0000FF00) >> 8, nvals);
+ gateids[i * 4 + 2] = PutConstantGate((UGATE_T) (val[i] & 0x00FF0000) >> 16, nvals);
+ gateids[i * 4 + 3] = PutConstantGate((UGATE_T) (val[i] & 0xFF000000) >> 24, nvals);
+ }
+ if(valamount % 4 == 1) {
+ uint32_t lastamount = valamount - 1;
+ gateids[lastamount] = PutConstantGate((UGATE_T) (val[loopamount] & 0x000000FF), nvals);
+ } else if(valamount % 4 == 2) {
+ uint32_t lastamount = valamount - 1;
+ uint32_t secondlastamount = valamount - 2;
+ gateids[secondlastamount] = PutConstantGate((UGATE_T) (val[loopamount] & 0x000000FF), nvals);
+ gateids[lastamount] = PutConstantGate((UGATE_T) (val[loopamount] & 0x0000FF00) >> 8, nvals);
+ } else if(valamount % 4 == 3) {
+ uint32_t lastamount = valamount - 1;
+ uint32_t secondlastamount = valamount - 2;
+ uint32_t thirdlastamount = valamount - 3;
+ gateids[thirdlastamount] = PutConstantGate((UGATE_T) (val[loopamount] & 0x000000FF), nvals);
+ gateids[secondlastamount] = PutConstantGate((UGATE_T) (val[loopamount] & 0x0000FF00) >> 8, nvals);
+ gateids[lastamount] = PutConstantGate((UGATE_T) (val[loopamount] & 0x00FF0000) >> 16, nvals);
+ }
+ }
+ return new arithshare(gateids, this);
}
@@ -336,24 +375,24 @@ share* ArithmeticCircuit::PutB2AGate(share* ina) {
//enqueue interactive gate queue
void ArithmeticCircuit::UpdateInteractiveQueue(uint32_t gateid) {
- if (m_pGates[gateid].depth + 1 > m_vInteractiveQueueOnLvl.size()) {
- m_vInteractiveQueueOnLvl.resize(m_pGates[gateid].depth + 1);
- if (m_pGates[gateid].depth + 1 > m_nMaxDepth) {
- m_nMaxDepth = m_pGates[gateid].depth + 1;
+ if (m_vGates[gateid].depth + 1 > m_vInteractiveQueueOnLvl.size()) {
+ m_vInteractiveQueueOnLvl.resize(m_vGates[gateid].depth + 1);
+ if (m_vGates[gateid].depth + 1 > m_nMaxDepth) {
+ m_nMaxDepth = m_vGates[gateid].depth + 1;
}
}
- m_vInteractiveQueueOnLvl[m_pGates[gateid].depth].push_back(gateid);
+ m_vInteractiveQueueOnLvl[m_vGates[gateid].depth].push_back(gateid);
}
//enqueue locally evaluated gate queue
void ArithmeticCircuit::UpdateLocalQueue(uint32_t gateid) {
- if (m_pGates[gateid].depth + 1 > m_vLocalQueueOnLvl.size()) {
- m_vLocalQueueOnLvl.resize(m_pGates[gateid].depth + 1);
- if (m_pGates[gateid].depth + 1 > m_nMaxDepth) {
- m_nMaxDepth = m_pGates[gateid].depth + 1;
+ if (m_vGates[gateid].depth + 1 > m_vLocalQueueOnLvl.size()) {
+ m_vLocalQueueOnLvl.resize(m_vGates[gateid].depth + 1);
+ if (m_vGates[gateid].depth + 1 > m_nMaxDepth) {
+ m_nMaxDepth = m_vGates[gateid].depth + 1;
}
}
- m_vLocalQueueOnLvl[m_pGates[gateid].depth].push_back(gateid);
+ m_vLocalQueueOnLvl[m_vGates[gateid].depth].push_back(gateid);
}
void ArithmeticCircuit::Reset() {
diff --git a/src/abycore/circuit/arithmeticcircuits.h b/src/abycore/circuit/arithmeticcircuits.h
index cf50fe41..f78b72a4 100644
--- a/src/abycore/circuit/arithmeticcircuits.h
+++ b/src/abycore/circuit/arithmeticcircuits.h
@@ -2,17 +2,17 @@
\file arithmeticcircuits.h
\author michael.zohner@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief A collection of boolean circuits for boolean and yao sharing in the ABY framework
*/
@@ -51,7 +51,7 @@ class ArithmeticCircuit: public Circuit {
template uint32_t PutINGate(T val, e_role role){
uint32_t gateid = PutINGate(role);
if (role == m_eMyRole) {
- GATE* gate = m_pGates + gateid;
+ GATE* gate = &(m_vGates[gateid]);
gate->gs.ishare.inval = (UGATE_T*) calloc(ceil_divide(1 * m_nShareBitLen, sizeof(UGATE_T) * 8), sizeof(UGATE_T));
*gate->gs.ishare.inval = (UGATE_T) val;
@@ -65,7 +65,7 @@ class ArithmeticCircuit: public Circuit {
template uint32_t PutSIMDINGate(uint32_t nvals, T val, e_role role) {
uint32_t gateid = PutSIMDINGate(nvals, role);
if (role == m_eMyRole) {
- GATE* gate = m_pGates + gateid;
+ GATE* gate = &(m_vGates[gateid]);
gate->gs.ishare.inval = (UGATE_T*) calloc(ceil_divide(nvals * m_nShareBitLen, GATE_T_BITS), sizeof(UGATE_T));
*gate->gs.ishare.inval = (UGATE_T) val;
@@ -80,7 +80,7 @@ class ArithmeticCircuit: public Circuit {
template uint32_t PutSharedINGate(T val) {
uint32_t gateid = PutSharedINGate();
- GATE* gate = m_pGates + gateid;
+ GATE* gate = &(m_vGates[gateid]);
gate->gs.val = (UGATE_T*) calloc(ceil_divide(1 * m_nShareBitLen, GATE_T_BITS), sizeof(UGATE_T));
*gate->gs.val = (UGATE_T) val;
@@ -92,7 +92,7 @@ class ArithmeticCircuit: public Circuit {
template uint32_t PutSharedSIMDINGate(uint32_t nvals, T val) {
uint32_t gateid = PutSharedSIMDINGate(nvals);
- GATE* gate = m_pGates + gateid;
+ GATE* gate = &(m_vGates[gateid]);
gate->gs.val = (UGATE_T*) calloc(ceil_divide(nvals * m_nShareBitLen, GATE_T_BITS), sizeof(UGATE_T));
*gate->gs.val = (UGATE_T) val;
@@ -221,8 +221,16 @@ class ArithmeticCircuit: public Circuit {
share* PutCallbackGate(share* in, uint32_t rounds, void (*callback)(GATE*, void*), void* infos, uint32_t nvals);
- share* PutTruthTableGate(share* in, uint64_t* ttable);
- share* PutTruthTableMultiOutputGate(share* in, uint32_t out_bits, uint64_t* ttable);
+
+ share* PutTruthTableGate(share*, uint64_t*) {
+ std::cerr << "PutTruthTableGate not implemented in ArithmeticCircuit!!" << std::endl;
+ return NULL;
+ }
+
+ share* PutTruthTableMultiOutputGate(share*, uint32_t, uint64_t*) {
+ std::cerr << "PutTruthTableMultiOutputGate not implemented in ArithmeticCircuit!!" << std::endl;
+ return NULL;
+ }
@@ -328,11 +336,10 @@ class ArithmeticCircuit: public Circuit {
assert(bitlen <= m_nShareBitLen);
share* shr = new arithshare(this);
uint32_t gateid = PutSharedSIMDINGate(nvals);
- uint32_t iters = sizeof(UGATE_T) / sizeof(T);
- assert(iters > 0);
+ assert((sizeof(UGATE_T) / sizeof(T)) > 0);
shr->set_wire_id(0, gateid);
- GATE* gate = m_pGates + gateid;
+ GATE* gate = &(m_vGates[gateid]);
uint32_t sharebytelen = ceil_divide(m_nShareBitLen, 8);
uint32_t inbytelen = ceil_divide(bitlen, 8);
gate->gs.val = (UGATE_T*) calloc(nvals, PadToMultiple(sharebytelen, sizeof(UGATE_T)));
@@ -343,7 +350,7 @@ class ArithmeticCircuit: public Circuit {
return shr;
}
- template share* InternalPutSharedINGate(uint32_t nvals, T val, uint32_t bitlen) {
+ template share* InternalPutSharedINGate(uint32_t nvals, T val, [[maybe_unused]] uint32_t bitlen) {
share* shr = new arithshare(this);
shr->set_wire_id(0, PutSharedSIMDINGate(nvals, val));
return shr;
@@ -353,12 +360,11 @@ class ArithmeticCircuit: public Circuit {
assert(bitlen <= m_nShareBitLen);
share* shr = new arithshare(this);
uint32_t gateid = PutSIMDINGate(nvals, role);
- uint32_t iters = sizeof(UGATE_T) / sizeof(T);
- assert(iters > 0);
+ assert((sizeof(UGATE_T) / sizeof(T)) > 0);
shr->set_wire_id(0, gateid);
if (role == m_eMyRole) {
- GATE* gate = m_pGates + gateid;
+ GATE* gate = &(m_vGates[gateid]);
uint32_t sharebytelen = ceil_divide(m_nShareBitLen, 8);
uint32_t inbytelen = ceil_divide(bitlen, 8);
gate->gs.ishare.inval = (UGATE_T*) calloc(nvals, PadToMultiple(sharebytelen, sizeof(UGATE_T)));
@@ -372,7 +378,7 @@ class ArithmeticCircuit: public Circuit {
return shr;
}
- template share* InternalPutINGate(uint32_t nvals, T val, uint32_t bitlen, e_role role) {
+ template share* InternalPutINGate(uint32_t nvals, T val, [[maybe_unused]] uint32_t bitlen, e_role role) {
share* shr = new arithshare(this);
shr->set_wire_id(0, PutSIMDINGate(nvals, val, role));
return shr;
diff --git a/src/abycore/circuit/booleancircuits.cpp b/src/abycore/circuit/booleancircuits.cpp
index 9a24ff39..9f5ab5b9 100644
--- a/src/abycore/circuit/booleancircuits.cpp
+++ b/src/abycore/circuit/booleancircuits.cpp
@@ -2,17 +2,17 @@
\file booleancircuits.cpp
\author michael.zohner@ec-spride.de
\copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
- Copyright (C) 2015 Engineering Cryptographic Protocols Group, TU Darmstadt
+ Copyright (C) 2019 Engineering Cryptographic Protocols Group, TU Darmstadt
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ ABY 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. See the
+ GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
\brief A collection of boolean circuits for boolean and yao sharing in the ABY framework
*/
@@ -110,8 +110,8 @@ uint32_t BooleanCircuit::PutANDGate(uint32_t inleft, uint32_t inright) {
std::cerr << "Context not recognized" << std::endl;
}
- if (m_pGates[gateid].nvals != INT_MAX) {
- m_vANDs[0].numgates += m_pGates[gateid].nvals;
+ if (m_vGates[gateid].nvals != INT_MAX) {
+ m_vANDs[0].numgates += m_vGates[gateid].nvals;
} else {
std::cerr << "INT_MAX not allowed as nvals" << std::endl;
}
@@ -127,10 +127,11 @@ uint32_t BooleanCircuit::PutANDGate(uint32_t inleft, uint32_t inright) {
std::vector BooleanCircuit::PutANDGate(std::vector inleft, std::vector inright) {
PadWithLeadingZeros(inleft, inright);
- uint32_t lim = inleft.size();
- std::vector out(lim);
- for (uint32_t i = 0; i < lim; i++)
+ uint32_t resultbitlen = inleft.size();
+ std::vector out(resultbitlen);
+ for (uint32_t i = 0; i < resultbitlen; i++){
out[i] = PutANDGate(inleft[i], inright[i]);
+ }
return out;
}
@@ -149,15 +150,15 @@ uint32_t BooleanCircuit::PutVectorANDGate(uint32_t choiceinput, uint32_t vectori
uint32_t gateid = m_cCircuit->PutNonLinearVectorGate(G_NON_LIN_VEC, choiceinput, vectorinput, m_nRoundsAND);
UpdateInteractiveQueue(gateid);
- //std::cout << "Putting a vector and gate between a gate with " << m_pGates[choiceinput].nvals << " and " <<
- // m_pGates[vectorinput].nvals << ", res gate has nvals = " << m_pGates[gateid].nvals << std::endl;
+ //std::cout << "Putting a vector and gate between a gate with " << m_vGates[choiceinput].nvals << " and " <<
+ // m_vGates[vectorinput].nvals << ", res gate has nvals = " << m_vGates[gateid].nvals << std::endl;
- if (m_pGates[gateid].nvals != INT_MAX) {
+ if (m_vGates[gateid].nvals != INT_MAX) {
//Update vector AND sizes
//find location of vector AND bitlength
- //int pos = FindBitLenPositionInVec(m_pGates[gateid].nvals, m_vANDs, m_nNumANDSizes);
- int pos = FindBitLenPositionInVec(m_pGates[gateid].gs.avs.bitlen, m_vANDs, m_nNumANDSizes);
+ //int pos = FindBitLenPositionInVec(m_vGates[gateid].nvals, m_vANDs, m_nNumANDSizes);
+ int pos = FindBitLenPositionInVec(m_vGates[gateid].gs.avs.bitlen, m_vANDs, m_nNumANDSizes);
if (pos == -1) {
//Create new entry for the bit-length
m_nNumANDSizes++;
@@ -165,12 +166,12 @@ uint32_t BooleanCircuit::PutVectorANDGate(uint32_t choiceinput, uint32_t vectori
memcpy(temp, m_vANDs, (m_nNumANDSizes - 1) * sizeof(non_lin_vec_ctx));
free(m_vANDs);
m_vANDs = temp;
- //m_vANDs[m_nNumANDSizes - 1].bitlen = m_pGates[gateid].nvals;
- m_vANDs[m_nNumANDSizes - 1].bitlen = m_pGates[gateid].gs.avs.bitlen;
- m_vANDs[m_nNumANDSizes - 1].numgates = m_pGates[choiceinput].nvals; //1
+ //m_vANDs[m_nNumANDSizes - 1].bitlen = m_vGates[gateid].nvals;
+ m_vANDs[m_nNumANDSizes - 1].bitlen = m_vGates[gateid].gs.avs.bitlen;
+ m_vANDs[m_nNumANDSizes - 1].numgates = m_vGates[choiceinput].nvals; //1
} else {
//increase number of vector ANDs for this bitlength by one
- m_vANDs[pos].numgates+=m_pGates[choiceinput].nvals;
+ m_vANDs[pos].numgates+=m_vGates[choiceinput].nvals;
}
}
return gateid;
@@ -184,17 +185,18 @@ uint32_t BooleanCircuit::PutXORGate(uint32_t inleft, uint32_t inright) {
//std::cout << "inleft = " << inleft << ", inright = " << inright << std::endl;
uint32_t gateid = m_cCircuit->PutPrimitiveGate(G_LIN, inleft, inright, m_nRoundsXOR);
UpdateLocalQueue(gateid);
- m_nNumXORVals += m_pGates[gateid].nvals;
+ m_nNumXORVals += m_vGates[gateid].nvals;
m_nNumXORGates += 1;
return gateid;
}
std::vector BooleanCircuit::PutXORGate(std::vector inleft, std::vector inright) {
PadWithLeadingZeros(inleft, inright);
- uint32_t lim = inleft.size();
- std::vector out(lim);
- for (uint32_t i = 0; i < lim; i++)
+ uint32_t resultbitlen = inleft.size();
+ std::vector out(resultbitlen);
+ for (uint32_t i = 0; i < resultbitlen; i++){
out[i] = PutXORGate(inleft[i], inright[i]);
+ }
return out;
}
@@ -204,17 +206,17 @@ uint32_t BooleanCircuit::PutINGate(e_role src) {
switch (src) {
case SERVER:
m_vInputGates[0].push_back(gateid);
- m_vInputBits[0] += m_pGates[gateid].nvals;
+ m_vInputBits[0] += m_vGates[gateid].nvals;
break;
case CLIENT:
m_vInputGates[1].push_back(gateid);
- m_vInputBits[1] += m_pGates[gateid].nvals;
+ m_vInputBits[1] += m_vGates[gateid].nvals;
break;
case ALL:
m_vInputGates[0].push_back(gateid);
m_vInputGates[1].push_back(gateid);
- m_vInputBits[0] += m_pGates[gateid].nvals;
- m_vInputBits[1] += m_pGates[gateid].nvals;
+ m_vInputBits[0] += m_vGates[gateid].nvals;
+ m_vInputBits[1] += m_vGates[gateid].nvals;
break;
default:
std::cerr << "Role not recognized" << std::endl;
@@ -230,17 +232,17 @@ uint32_t BooleanCircuit::PutSIMDINGate(uint32_t ninvals, e_role src) {
switch (src) {
case SERVER:
m_vInputGates[0].push_back(gateid);
- m_vInputBits[0] += m_pGates[gateid].nvals;
+ m_vInputBits[0] += m_vGates[gateid].nvals;
break;
case CLIENT:
m_vInputGates[1].push_back(gateid);
- m_vInputBits[1] += m_pGates[gateid].nvals;
+ m_vInputBits[1] += m_vGates[gateid].nvals;
break;
case ALL:
m_vInputGates[0].push_back(gateid);
m_vInputGates[1].push_back(gateid);
- m_vInputBits[0] += m_pGates[gateid].nvals;
- m_vInputBits[1] += m_pGates[gateid].nvals;
+ m_vInputBits[0] += m_vGates[gateid].nvals;
+ m_vInputBits[1] += m_vGates[gateid].nvals;
break;
default:
std::cerr << "Role not recognized" << std::endl;
@@ -285,7 +287,7 @@ uint32_t BooleanCircuit::PutINGate(uint64_t val, e_role role) {
uint32_t gateid = PutINGate(role);
if (role == m_eMyRole) {
//assign value
- GATE* gate = m_pGates + gateid;
+ GATE* gate = &(m_vGates[gateid]);
gate->gs.ishare.inval = (UGATE_T*) calloc(ceil_divide(1 * m_nShareBitLen, sizeof(UGATE_T) * 8), sizeof(UGATE_T));
memcpy(gate->gs.ishare.inval, &val, ceil_divide(1 * m_nShareBitLen, 8));
@@ -299,7 +301,7 @@ uint32_t BooleanCircuit::PutINGate(uint64_t val, e_role role) {
uint32_t BooleanCircuit::PutSharedINGate(uint64_t val) {
uint32_t gateid = PutSharedINGate();
//assign value
- GATE* gate = m_pGates + gateid;
+ GATE* gate = &(m_vGates[gateid]);
gate->gs.val = (UGATE_T*) calloc(ceil_divide(1 * m_nShareBitLen, sizeof(UGATE_T) * 8), sizeof(UGATE_T));
memcpy(gate->gs.val, &val, ceil_divide(1 * m_nShareBitLen, 8));
@@ -312,7 +314,7 @@ uint32_t BooleanCircuit::PutSIMDINGate(uint32_t nvals, uint64_t val, e_role role
uint32_t gateid = PutSIMDINGate(nvals, role);
if (role == m_eMyRole) {
//assign value
- GATE* gate = m_pGates + gateid;
+ GATE* gate = &(m_vGates[gateid]);
gate->gs.ishare.inval = (UGATE_T*) calloc(ceil_divide(nvals * m_nShareBitLen, sizeof(UGATE_T) * 8), sizeof(UGATE_T));
memcpy(gate->gs.ishare.inval, &val, ceil_divide(nvals * m_nShareBitLen, 8));
@@ -327,7 +329,7 @@ uint32_t BooleanCircuit::PutSharedSIMDINGate(uint32_t nvals, uint64_t val) {
uint32_t gateid = PutSharedSIMDINGate(nvals);
//assign value
- GATE* gate = m_pGates + gateid;
+ GATE* gate = &(m_vGates[gateid]);
gate->gs.val = (UGATE_T*) calloc(ceil_divide(nvals * m_nShareBitLen, sizeof(UGATE_T) * 8), sizeof(UGATE_T));
memcpy(gate->gs.val, &val, ceil_divide(nvals * m_nShareBitLen, 8));
@@ -339,7 +341,7 @@ uint32_t BooleanCircuit::PutSharedSIMDINGate(uint32_t nvals, uint64_t val) {
uint32_t BooleanCircuit::PutYaoSharedSIMDINGate(uint32_t nvals, yao_fields keys) {
uint32_t gateid = PutSharedSIMDINGate(nvals);
//assign value
- GATE* gate = m_pGates + gateid;
+ GATE* gate = &(m_vGates[gateid]);
//TODO: fixed to 128-bit security atm. CHANGE
uint8_t keybytelen = ceil_divide(128, 8);
if(m_eMyRole == SERVER) {
@@ -374,17 +376,17 @@ uint32_t BooleanCircuit::PutOUTGate(uint32_t parentid, e_role dst) {
switch (dst) {
case SERVER:
m_vOutputGates[0].push_back(gateid);
- m_vOutputBits[0] += m_pGates[gateid].nvals;
+ m_vOutputBits[0] += m_vGates[gateid].nvals;
break;
case CLIENT:
m_vOutputGates[1].push_back(gateid);
- m_vOutputBits[1] += m_pGates[gateid].nvals;
+ m_vOutputBits[1] += m_vGates[gateid].nvals;
break;
case ALL:
m_vOutputGates[0].push_back(gateid);
m_vOutputGates[1].push_back(gateid);
- m_vOutputBits[0] += m_pGates[gateid].nvals;
- m_vOutputBits[1] += m_pGates[gateid].nvals;
+ m_vOutputBits[0] += m_vGates[gateid].nvals;
+ m_vOutputBits[1] += m_vGates[gateid].nvals;
break;
default:
std::cerr << "Role not recognized" << std::endl;
@@ -407,17 +409,17 @@ std::vector BooleanCircuit::PutOUTGate(std::vector parentids
switch (dst) {
case SERVER:
m_vOutputGates[0].push_back(gateid[i]);
- m_vOutputBits[0] += m_pGates[gateid[i]].nvals;
+ m_vOutputBits[0] += m_vGates[gateid[i]].nvals;
break;
case CLIENT:
m_vOutputGates[1].push_back(gateid[i]);
- m_vOutputBits[1] += m_pGates[gateid[i]].nvals;
+ m_vOutputBits[1] += m_vGates[gateid[i]].nvals;
break;
case ALL:
m_vOutputGates[0].push_back(gateid[i]);
m_vOutputGates[1].push_back(gateid[i]);
- m_vOutputBits[0] += m_pGates[gateid[i]].nvals;
- m_vOutputBits[1] += m_pGates[gateid[i]].nvals;
+ m_vOutputBits[0] += m_vGates[gateid[i]].nvals;
+ m_vOutputBits[1] += m_vGates[gateid[i]].nvals;
break;
default:
std::cerr << "Role not recognized" << std::endl;
@@ -442,58 +444,39 @@ share* BooleanCircuit::PutSharedOUTGate(share* parent) {
}
share* BooleanCircuit::PutCONSGate(UGATE_T val, uint32_t bitlen) {
- share* shr = new boolshare(bitlen, this);
- for (uint32_t i = 0; i < bitlen; i++) {
- if ((val >> i) & 0x01) {
- shr->set_wire_id(i, PutConstantGate(1, 1));
- } else {
- shr->set_wire_id(i, PutConstantGate(0, 1));
- }
- }
- return shr;
+ return PutSIMDCONSGate(1, val, bitlen);
}
share* BooleanCircuit::PutCONSGate(uint8_t* val, uint32_t bitlen) {
- share* shr = new boolshare(bitlen, this);
- for (uint32_t i = 0; i < bitlen; i++) {
- shr->set_wire_id(i, PutConstantGate(val[i] & 0x01, 1));
- }
- return shr;
+ return PutSIMDCONSGate(1, val, bitlen);
}
share* BooleanCircuit::PutCONSGate(uint32_t* val, uint32_t bitlen) {
- share* shr = new boolshare(bitlen, this);
- for (uint32_t i = 0; i < bitlen; i++) {
- shr->set_wire_id(i, PutConstantGate((val[i >> 5] >> i) & 0x01, 1));
- }
- return shr;
+ return PutSIMDCONSGate(1, val, bitlen);
}
share* BooleanCircuit::PutSIMDCONSGate(uint32_t nvals, UGATE_T val, uint32_t bitlen) {
share* shr = new boolshare(bitlen, this);
- for (uint32_t i = 0; i < bitlen; i++) {
- if ((val >> i) & 0x01) {
- shr->set_wire_id(i, PutConstantGate(~0L, nvals));
- }
- else {
- shr->set_wire_id(i, PutConstantGate(0L, nvals));
- }
+ for(uint32_t i = 0; i < bitlen; ++i) {
+ shr->set_wire_id(i, PutConstantGate((val >> i) & 1, nvals));
}
return shr;
}
share* BooleanCircuit::PutSIMDCONSGate(uint32_t nvals, uint8_t* val, uint32_t bitlen) {
share* shr = new boolshare(bitlen, this);
- for (uint32_t i = 0; i < bitlen; i++) {
- shr->set_wire_id(i, PutConstantGate(val[i] & 0x01, nvals));
+ for(uint32_t i = 0; i < bitlen; ++i) {
+ uint32_t shift = i % 8;
+ shr->set_wire_id(i, PutConstantGate((val[(i / 8)] & (1 << shift)) >> shift, nvals));
}
return shr;
}
share* BooleanCircuit::PutSIMDCONSGate(uint32_t nvals, uint32_t* val, uint32_t bitlen) {
share* shr = new boolshare(bitlen, this);
- for (uint32_t i = 0; i < bitlen; i++) {
- shr->set_wire_id(i, PutConstantGate((val[i >> 5] >> i) & 0x01, nvals));
+ for(uint32_t i = 0; i < bitlen; ++i) {
+ uint32_t shift = i % 32;
+ shr->set_wire_id(i, PutConstantGate((val[(i / 32)] & (1 << shift)) >> shift, nvals));
}
return shr;
}
@@ -525,10 +508,10 @@ share* BooleanCircuit::PutINVGate(share* parent) {
uint32_t BooleanCircuit::PutY2BCONVGate(uint32_t parentid) {
std::vector in(1, parentid);
uint32_t gateid = m_cCircuit->PutCONVGate(in, 1, S_BOOL, m_nShareBitLen);
- m_pGates[gateid].depth++;
+ m_vGates[gateid].depth++;
UpdateLocalQueue(gateid);
//a Y input gate cannot be parent to a Y2B gate. Alternatively, put a Boolean input gate
- assert(m_pGates[parentid].type != G_IN);
+ assert(m_vGates[parentid].type != G_IN);
return gateid;
}
@@ -539,7 +522,7 @@ uint32_t BooleanCircuit::PutB2YCONVGate(uint32_t parentid) {
UpdateInteractiveQueue(gateid);
//treat similar to input gate of client and server
- m_nB2YGates += m_pGates[gateid].nvals;
+ m_nB2YGates += m_vGates[gateid].nvals;
return gateid;
}
@@ -547,12 +530,12 @@ uint32_t BooleanCircuit::PutB2YCONVGate(uint32_t parentid) {
uint32_t BooleanCircuit::PutYSwitchRolesGate(uint32_t parentid) {
std::vector in(1, parentid);
assert(m_eContext == S_YAO || m_eContext == S_YAO_REV);
- assert(m_pGates[in[0]].context != m_eContext);
+ assert(m_vGates[in[0]].context != m_eContext);
uint32_t gateid = m_cCircuit->PutCONVGate(in, 2, m_eContext, m_nShareBitLen);
UpdateInteractiveQueue(gateid);
//treat similar to input gate of client and server
- m_nYSwitchGates += m_pGates[gateid].nvals;
+ m_nYSwitchGates += m_vGates[gateid].nvals;
return gateid;
}
@@ -597,22 +580,22 @@ share* BooleanCircuit::PutYSwitchRolesGate(share* ina) {
}
std::vector BooleanCircuit::PutA2YCONVGate(std::vector parentid) {
- std::vector srvshares(m_pGates[parentid[0]].sharebitlen);
- std::vector clishares(m_pGates[parentid[0]].sharebitlen);
+ std::vector srvshares(m_vGates[parentid[0]].sharebitlen);
+ std::vector clishares(m_vGates[parentid[0]].sharebitlen);
- for (uint32_t i = 0; i < m_pGates[parentid[0]].sharebitlen; i++) {
+ for (uint32_t i = 0; i < m_vGates[parentid[0]].sharebitlen; i++) {
srvshares[i] = m_cCircuit->PutCONVGate(parentid, 1, S_YAO, m_nShareBitLen);
- m_pGates[srvshares[i]].gs.pos = 2 * i;
- m_pGates[srvshares[i]].depth++; //increase depth by 1 since yao is evaluated before arith
+ m_vGates[srvshares[i]].gs.pos = 2 * i;
+ m_vGates[srvshares[i]].depth++; //increase depth by 1 since yao is evaluated before arith
UpdateInteractiveQueue(srvshares[i]);
clishares[i] = m_cCircuit->PutCONVGate(parentid, 2, S_YAO, m_nShareBitLen);
- m_pGates[clishares[i]].gs.pos = 2 * i + 1;
- m_pGates[clishares[i]].depth++; //increase depth by 1 since yao is evaluated before arith
+ m_vGates[clishares[i]].gs.pos = 2 * i + 1;
+ m_vGates[clishares[i]].depth++; //increase depth by 1 since yao is evaluated before arith
UpdateInteractiveQueue(clishares[i]);
}
- m_nA2YGates += m_pGates[parentid[0]].nvals * m_pGates[parentid[0]].sharebitlen;
+ m_nA2YGates += m_vGates[parentid[0]].nvals * m_vGates[parentid[0]].sharebitlen;
return PutAddGate(srvshares, clishares);
@@ -643,7 +626,7 @@ uint32_t BooleanCircuit::PutUniversalGate(uint32_t a, uint32_t b, uint32_t op_id
if(m_eContext == S_YAO) { //In case of Yao, put universal gate
gateid = m_cCircuit->PutUniversalGate(a, b, op_id, m_nRoundsAND);
UpdateLocalQueue(gateid);
- m_nUNIVGates+=m_pGates[gateid].nvals;
+ m_nUNIVGates+=m_vGates[gateid].nvals;
} else if (m_eContext == S_BOOL) { //In case of GMW, replace universal gate by sub-circuit
gateid = PutUniversalGateCircuit(a, b, op_id);
} else {
@@ -724,7 +707,7 @@ std::vector BooleanCircuit::PutTruthTableMultiOutputGate(std::vector bitlens(out_bits, m_pGates[in[0]].nvals);
+ std::vector bitlens(out_bits, m_vGates[in[0]].nvals);
//assert(out_bits <= 8);
std::vector output = m_cCircuit->PutSplitterGate(tmpgate, bitlens);
@@ -760,8 +743,8 @@ share* BooleanCircuit::PutTruthTableGate(share* in, uint64_t* ttable) {
//check if the len exists, otherwise allocate new and update
void BooleanCircuit::UpdateTruthTableSizes(uint32_t len, uint32_t gateid, uint32_t out_bits) {
//check depth and resize if required
- uint32_t depth = m_pGates[gateid].depth;
- uint32_t nvals = m_pGates[gateid].nvals/out_bits;
+ uint32_t depth = m_vGates[gateid].depth;
+ uint32_t nvals = m_vGates[gateid].nvals/out_bits;
if(depth >= m_vTTlens.size()) {
uint32_t old_depth = m_vTTlens.size();
uint32_t nlens = m_vTTlens[0].size();
@@ -797,7 +780,7 @@ void BooleanCircuit::UpdateTruthTableSizes(uint32_t len, uint32_t gateid, uint32
//In case of OP-LUT, also save the truth table which is needed in the setup phase
if(m_eContext == S_BOOL) {
for(uint32_t n = 0; n < nvals; n++) {
- m_vTTlens[depth][i][j].ttable_values.push_back(m_pGates[gateid].gs.tt.table);
+ m_vTTlens[depth][i][j].ttable_values.push_back(m_vGates[gateid].gs.tt.table);
}
}
}
@@ -819,7 +802,7 @@ void BooleanCircuit::UpdateTruthTableSizes(uint32_t len, uint32_t gateid, uint32
//In case of OP-LUT, also save the truth table which is needed in the setup phase
if(m_eContext == S_BOOL) {
for(uint32_t n = 0; n < nvals; n++) {
- m_vTTlens[depth][old_in_lens][0].ttable_values.push_back(m_pGates[gateid].gs.tt.table);
+ m_vTTlens[depth][old_in_lens][0].ttable_values.push_back(m_vGates[gateid].gs.tt.table);
}
}
outs_exist = true;
@@ -839,7 +822,7 @@ void BooleanCircuit::UpdateTruthTableSizes(uint32_t len, uint32_t gateid, uint32
//In case of OP-LUT, also save the truth table which is needed in the setup phase
if(m_eContext == S_BOOL) {
for(uint32_t n = 0; n < nvals; n++) {
- m_vTTlens[depth][id][old_out_lens].ttable_values.push_back(m_pGates[gateid].gs.tt.table);
+ m_vTTlens[depth][id][old_out_lens].ttable_values.push_back(m_vGates[gateid].gs.tt.table);
}
}
outs_exist = true;
@@ -849,26 +832,26 @@ void BooleanCircuit::UpdateTruthTableSizes(uint32_t len, uint32_t gateid, uint32
//enqueue interactive gate queue
void BooleanCircuit::UpdateInteractiveQueue(uint32_t gateid) {
- if (m_pGates[gateid].depth + 1 > m_vInteractiveQueueOnLvl.size()) {
- m_vInteractiveQueueOnLvl.resize(m_pGates[gateid].depth + 1);
- if (m_pGates[gateid].depth + 1 > m_nMaxDepth) {
- m_nMaxDepth = m_pGates[gateid].depth + 1;
+ if (m_vGates[gateid].depth + 1 > m_vInteractiveQueueOnLvl.size()) {
+ m_vInteractiveQueueOnLvl.resize(m_vGates[gateid].depth + 1);
+ if (m_vGates[gateid].depth + 1 > m_nMaxDepth) {
+ m_nMaxDepth = m_vGates[gateid].depth + 1;
}
}
- m_vInteractiveQueueOnLvl[m_pGates[gateid].depth].push_back(gateid);
+ m_vInteractiveQueueOnLvl[m_vGates[gateid].depth].push_back(gateid);
m_nGates++;
}
//enqueue locally evaluated gate queue
void BooleanCircuit::UpdateLocalQueue(uint32_t gateid) {
- if (m_pGates[gateid].depth + 1 > m_vLocalQueueOnLvl.size()) {
+ if (m_vGates[gateid].depth + 1 > m_vLocalQueueOnLvl.size()) {
//std::cout << "increasing size of local queue" << std::endl;
- m_vLocalQueueOnLvl.resize(m_pGates[gateid].depth + 1);
- if (m_pGates[gateid].depth + 1 > m_nMaxDepth) {
- m_nMaxDepth = m_pGates[gateid].depth + 1;
+ m_vLocalQueueOnLvl.resize(m_vGates[gateid].depth + 1);
+ if (m_vGates[gateid].depth + 1 > m_nMaxDepth) {
+ m_nMaxDepth = m_vGates[gateid].depth + 1;
}
}
- m_vLocalQueueOnLvl[m_pGates[gateid].depth].push_back(gateid);
+ m_vLocalQueueOnLvl[m_vGates[gateid].depth].push_back(gateid);
m_nGates++;
}
@@ -890,17 +873,13 @@ std::vector BooleanCircuit::PutLeftShifterGate(std::vector v
}
// Builds a universal gate that output op_id depending on the circuit
-// Only works for nvals <= 32 due to the constant gate implementation in Bool
-// sharing.
uint32_t BooleanCircuit::PutUniversalGateCircuit(uint32_t a, uint32_t b, uint32_t op_id) {
- uint32_t nvals = std::max(m_pGates[a].nvals, m_pGates[b].nvals);
- assert(nvals <= 32);
+ uint32_t nvals = std::max(m_vGates[a].nvals, m_vGates[b].nvals);
- uint32_t mask = 0xFFFFFFFF;
- uint32_t c0 = PutConstantGate((op_id & 0x01) * mask, nvals);
- uint32_t c1 = PutConstantGate(((op_id>>1) & 0x01) * mask, nvals);
- uint32_t c2 = PutConstantGate(((op_id>>2) & 0x01) * mask, nvals);
- uint32_t c3 = PutConstantGate(((op_id>>3) & 0x01) * mask, nvals);
+ uint32_t c0 = PutConstantGate(op_id & 0x01, nvals);
+ uint32_t c1 = PutConstantGate((op_id>>1) & 0x01, nvals);
+ uint32_t c2 = PutConstantGate((op_id>>2) & 0x01, nvals);
+ uint32_t c3 = PutConstantGate((op_id>>3) & 0x01, nvals);
uint32_t c0c1 = PutXORGate(c0, c1);
uint32_t c2c3 = PutXORGate(c2, c3);
@@ -942,14 +921,14 @@ std::vector BooleanCircuit::PutSizeOptimizedAddGate(std::vector C(rep);
+ uint32_t inputbitlen = a.size();// + (!!bCarry);
+ std::vector C(inputbitlen);
uint32_t axc, bxc, acNbc;
- C[0] = PutXORGate(a[0], a[0]);//PutConstantGate(0, m_pGates[a[0]].nvals); //the second parameter stands for the number of vals
+ C[0] = PutXORGate(a[0], a[0]);//PutConstantGate(0, m_vGates[a[0]].nvals); //the second parameter stands for the number of vals
uint32_t i = 0;
- for (; i < rep - 1; i++) {
+ for (; i < inputbitlen - 1; i++) {
//===================
// New Gates
// a[i] xor c[i]
@@ -984,8 +963,8 @@ std::vector BooleanCircuit::PutSizeOptimizedAddGate(std::vector AxB(rep);
- for (uint32_t i = 0; i < rep; i++) {
+ std::vector AxB(inputbitlen);
+ for (uint32_t i = 0; i < inputbitlen; i++) {
// a[i] xor b[i]
AxB[i] = PutXORGate(a[i], b[i]);
}
@@ -995,8 +974,8 @@ std::vector BooleanCircuit::PutSizeOptimizedAddGate(std::vector out(rep + (!!bCarry));
- for (uint32_t i = 0; i < rep; i++) {
+ std::vector out(inputbitlen + (!!bCarry));
+ for (uint32_t i = 0; i < inputbitlen; i++) {
out[i] = PutXORGate(C[i], AxB[i]);
}
@@ -1005,7 +984,7 @@ std::vector BooleanCircuit::PutSizeOptimizedAddGate(std::vector BooleanCircuit::PutSizeOptimizedAddGate(std::vector BooleanCircuit::PutDepthOptimizedAddGate(std::vector a, std::vector b, BOOL bCARRY, bool vector_and) {
PadWithLeadingZeros(a, b);
- uint32_t id, rep = std::min(a.size(), b.size());
+ uint32_t id, inputbitlen = std::min(a.size(), b.size());
std::vector out(a.size() + bCARRY);
- std::vector parity(a.size()), carry(rep), parity_zero(rep);
- uint32_t zerogate = PutConstantGate(0, m_pGates[a[0]].nvals);
- uint32_t startid = zerogate;
+ std::vector parity(a.size()), carry(inputbitlen), parity_zero(inputbitlen);
+ uint32_t zerogate = PutConstantGate(0, m_vGates[a[0]].nvals);
share* zero_share = new boolshare(2, this);
share* ina = new boolshare(2, this);
share* sel = new boolshare(1, this);
@@ -1031,14 +1009,14 @@ std::vector BooleanCircuit::PutDepthOptimizedAddGate(std::vectorset_wire_id(0, zerogate);
zero_share->set_wire_id(1, zerogate);
- for (uint32_t i = 0; i < rep; i++) { //0-th layer
+ for (uint32_t i = 0; i < inputbitlen; i++) { //0-th layer
parity[i] = PutXORGate(a[i], b[i]);
parity_zero[i] = parity[i];
carry[i] = PutANDGate(a[i], b[i]);
}
- for (uint32_t i = 1; i <= (uint32_t) ceil(log(rep) / log(2)); i++) {
- for (uint32_t j = 0; j < rep; j++) {
+ for (uint32_t i = 1; i <= (uint32_t) ceil(log(inputbitlen) / log(2)); i++) {
+ for (uint32_t j = 0; j < inputbitlen; j++) {
if (j % (uint32_t) pow(2, i) >= pow(2, (i - 1))) {
id = pow(2, (i - 1)) + pow(2, i) * ((uint32_t) floor(j / (pow(2, i)))) - 1;
if(m_eContext == S_BOOL && vector_and) {
@@ -1058,11 +1036,11 @@ std::vector BooleanCircuit::PutDepthOptimizedAddGate(std::vector > BooleanCircuit::PutCarrySaveGate(std::vector
* 1) for the inputs, 2) for intermediate carry-forwarding, 3) for critical path on inputs, 4) for the critical path, 5) for the inverse carry tree.
*/
std::vector BooleanCircuit::PutLUTAddGate(std::vector a, std::vector b, BOOL bCARRY) {
- uint32_t id, rep = std::max(a.size(), b.size());
+ uint32_t inputbitlen = std::max(a.size(), b.size());
PadWithLeadingZeros(a, b);
std::vector out(a.size() + bCARRY);
- std::vector parity(rep), carry(rep), parity_zero(rep), tmp;
- std::vector lut_in(2*rep);
+ std::vector parity(inputbitlen), carry(inputbitlen), parity_zero(inputbitlen), tmp;
+ std::vector lut_in(2*inputbitlen);
uint32_t max_ins = 4, processed_ins;
- uint32_t max_invs = 7;
- uint32_t n_crit_ins = std::min(rep, (uint32_t) max_ins);
+ uint32_t n_crit_ins = std::min(inputbitlen, (uint32_t) max_ins);
std::vector tmpout;
- //std::cout << "Building a LUT add gate for " << rep << " input bits" << std::endl;
+ //std::cout << "Building a LUT add gate for " << inputbitlen << " input bits" << std::endl;
//step 1: process the input values and generate carry / parity signals
//compute the parity bits for the zero-th layer. Are needed for the result
- for (uint32_t i = 0; i < rep; i++) { //0-th layer
+ for (uint32_t i = 0; i < inputbitlen; i++) { //0-th layer
parity_zero[i] = PutXORGate(a[i], b[i]);
parity[i] = parity_zero[i];
}
@@ -1153,8 +1130,8 @@ std::vector BooleanCircuit::PutLUTAddGate(std::vector a, std
}
//process the remaining input bits to have all carry / parity signals
- for(uint32_t i = n_crit_ins; i < rep; ) {
- processed_ins = std::min(rep - i, max_ins);
+ for(uint32_t i = n_crit_ins; i < inputbitlen; ) {
+ processed_ins = std::min(inputbitlen - i, max_ins);
//assign values to the LUT
lut_in.clear();
lut_in.resize(2*processed_ins);
@@ -1190,12 +1167,12 @@ std::vector BooleanCircuit::PutLUTAddGate(std::vector a, std
}
//step 2: process the carry / parity signals and forward them in the tree
- for(uint32_t d = 1; d < ceil_log2(rep+1)/2; d++) {
+ for(uint32_t d = 1; d < ceil_log2(inputbitlen+1)/2; d++) {
//step 2.1: process the carry signals on the critical path
uint32_t base = 8 * (1<<(2*(d-1)));
uint32_t dist = base/2;
- processed_ins = 1+ std::min((rep - base)/dist, max_ins-2);
+ processed_ins = 1+ std::min((inputbitlen - base)/dist, max_ins-2);
//std::cout << "critical intermediate base = " << base << ", dist = " << dist << ", processed_ins = " << processed_ins << std::endl;
lut_in.clear();
@@ -1216,8 +1193,8 @@ std::vector BooleanCircuit::PutLUTAddGate(std::vector a, std
}
//step 2.2: forward carry and parity signals down the tree
- for(uint32_t i = (base+3*dist)-1; i+dist < rep; i+=(4*dist)) {
- processed_ins = std::min(ceil_divide((rep - (i+dist)),2*dist), max_ins-2);
+ for(uint32_t i = (base+3*dist)-1; i+dist < inputbitlen; i+=(4*dist)) {
+ processed_ins = std::min(ceil_divide((inputbitlen - (i+dist)),2*dist), max_ins-2);
//std::cout << "intermediate base = " << i << ", dist = " << dist << ", processed_ins = " << processed_ins << std::endl;
lut_in.clear();
@@ -1241,19 +1218,19 @@ std::vector BooleanCircuit::PutLUTAddGate(std::vector a, std
}
- //std::cout << "Doing " << (floor_log2(rep/5)/2)+1 << " iterations on the inverse carry tree, " << floor_log2(rep/5) << ", " << rep/5 << std::endl;
+ //std::cout << "Doing " << (floor_log2(inputbitlen/5)/2)+1 << " iterations on the inverse carry tree, " << floor_log2(inputbitlen/5) << ", " << inputbitlen/5 << std::endl;
//step 3: build the inverse carry tree
//d increases with d = 0: 5, d = 1: 20, d = 2: 80; d = 3: 320, ...
- for(int32_t d = (floor_log2(rep/5)/2); d >= 0; d--) {
+ for(int32_t d = (floor_log2(inputbitlen/5)/2); d >= 0; d--) {
//for d = 0: 4, for d = 1: 16, for d = 2: 64
uint32_t start = 4 * (1<<(2*d));
//for start = 4: 1, start = 16: 4, start = 64: 16
uint32_t dist = start/4;
//std::cout << "d = " << d << ", start = " << start << ", dist = " << dist << std::endl;
- for(uint32_t i = start; i < rep; i+=start) {
+ for(uint32_t i = start; i < inputbitlen; i+=start) {
//processed_ins here needs to be between 1 and 3
- //processed_ins = std::min(rep - i, max_ins-1);
- processed_ins = std::min((rep - i)/dist, max_ins-1);
+ //processed_ins = std::min(inputbitlen - i, max_ins-1);
+ processed_ins = std::min((inputbitlen - i)/dist, max_ins-1);
if(processed_ins > 0) {
//assign values to the LUT
lut_in.clear();
@@ -1286,58 +1263,57 @@ std::vector BooleanCircuit::PutLUTAddGate(std::vector a, std
//step 4: compute the outputs from the carry signals and the parity bits at the zero-th level
out[0] = parity_zero[0];
- for (uint32_t i = 1; i < rep; i++) {
+ for (uint32_t i = 1; i < inputbitlen; i++) {
out[i] = PutXORGate(parity_zero[i], carry[i - 1]);
}
if (bCARRY) //Do I expect a carry in the most significant bit position?
- out[rep] = carry[rep - 1];
+ out[inputbitlen] = carry[inputbitlen - 1];
return out;
}
-std::vector BooleanCircuit::PutMulGate(std::vector a, std::vector b, uint32_t resbitlen, bool depth_optimized, bool vector_ands) {
+std::vector BooleanCircuit::PutMulGate(std::vector a, std::vector b, uint32_t resultbitlen, bool depth_optimized, bool vector_ands) {
PadWithLeadingZeros(a, b);
- //std::cout << "a.size() = " << a.size() << ", b.size() = " << b.size() << std::endl;
- uint32_t rep = a.size();
+ // std::cout << "a.size() = " << a.size() << ", b.size() = " << b.size() << std::endl;
+ uint32_t inputbitlen = a.size();
- if(rep == 1) {
+ if(inputbitlen == 1) {
return PutANDGate(a, b);
}
- std::vector > vAdds(rep);
- uint32_t zerogate = PutConstantGate(0, m_pGates[a[0]].nvals);
-
- uint32_t lim = std::min(resbitlen, 2 * rep);
+ std::vector > vAdds(inputbitlen);
+ uint32_t zerogate = PutConstantGate(0, m_vGates[a[0]].nvals);
+ resultbitlen = std::min(resultbitlen, 2 * inputbitlen);
- if(m_eContext== S_BOOL && vector_ands) {
+ if(m_eContext == S_BOOL && vector_ands) {
share *ina, *inb, **mulout, *zero_share;
- ina = new boolshare(a, this); //ina = (share**) malloc(sizeof(share*) * 1);
- inb = new boolshare(b, this);//inb = (share**) malloc(sizeof(share*) * 1);
- zero_share = new boolshare(rep, this);
+ ina = new boolshare(a, this);
+ inb = new boolshare(b, this);
+ zero_share = new boolshare(inputbitlen, this);
- mulout = (share**) malloc(sizeof(share*) * rep);
+ mulout = (share**) malloc(sizeof(share*) * inputbitlen);
- for(uint32_t i = 0; i < rep; i++) {
- mulout[i] = new boolshare(rep, this);
+ for(uint32_t i = 0; i < inputbitlen; i++) {
+ mulout[i] = new boolshare(inputbitlen, this);
zero_share->set_wire_id(i, zerogate);
}
- for(uint32_t i = 0; i < rep; i++) {
+ for(uint32_t i = 0; i < inputbitlen; i++) {
PutMultiMUXGate(&ina, &zero_share, inb->get_wire_ids_as_share(i), 1, &(mulout[i]));
}
- for (uint32_t i = 0, ctr; i < rep; i++) {
+ for (uint32_t i = 0, ctr; i < inputbitlen; i++) {
ctr = 0;
- vAdds[i].resize(lim);
+ vAdds[i].resize(resultbitlen);
- for (uint32_t j = 0; j < i && ctr < lim; j++, ctr++) {
+ for (uint32_t j = 0; j < i && ctr < resultbitlen; j++, ctr++) {
vAdds[i][ctr] = zerogate;
}
- for (uint32_t j = 0; j < rep && ctr < lim; j++, ctr++) {
+ for (uint32_t j = 0; j < inputbitlen && ctr < resultbitlen; j++, ctr++) {
vAdds[i][ctr] = mulout[j]->get_wire_id(i);//(a[j], b[i]);
}
- for (uint32_t j = i; j < rep && ctr < lim; j++, ctr++) {
+ for (uint32_t j = i; j < inputbitlen && ctr < resultbitlen; j++, ctr++) {
vAdds[i][ctr] = zerogate;
}
}
@@ -1346,22 +1322,22 @@ std::vector BooleanCircuit::PutMulGate(std::vector a, std::v
} else {
// Compute AND between all bits
#ifdef ZDEBUG
- std::cout << "Starting to construct multiplication gate for " << rep << " bits" << std::endl;
+ std::cout << "Starting to construct multiplication gate for " << inputbitlen << " bits" << std::endl;
#endif
- for (uint32_t i = 0, ctr; i < rep; i++) {
+ for (uint32_t i = 0, ctr; i < inputbitlen; i++) {
ctr = 0;
- vAdds[i].resize(lim);
+ vAdds[i].resize(resultbitlen);
#ifdef ZDEBUG
- std::cout << "New Iteration with ctr = " << ctr << ", and lim = " << lim << std::endl;
+ std::cout << "New Iteration with ctr = " << ctr << ", and resultbitlen = " << resultbitlen << std::endl;
#endif
- for (uint32_t j = 0; j < i && ctr < lim; j++, ctr++) {
+ for (uint32_t j = 0; j < i && ctr < resultbitlen; j++, ctr++) {
vAdds[i][ctr] = zerogate;
}
- for (uint32_t j = 0; j < rep && ctr < lim; j++, ctr++) {
+ for (uint32_t j = 0; j < inputbitlen && ctr < resultbitlen; j++, ctr++) {
vAdds[i][ctr] = PutANDGate(a[j], b[i]);
}
- for (uint32_t j = i; j < rep && ctr < lim; j++, ctr++) {
+ for (uint32_t j = i; j < inputbitlen && ctr < resultbitlen; j++, ctr++) {
vAdds[i][ctr] = zerogate;
}
}
@@ -1373,17 +1349,15 @@ std::vector BooleanCircuit::PutMulGate(std::vector a, std::v
return PutDepthOptimizedAddGate(out[0], out[1]);
} else {
return PutWideAddGate(vAdds);
-
}
-
}
share* BooleanCircuit::PutMULGate(share* ina, share* inb) {
//set the resulting bit length to be the smallest of: 1) bit length of the products or 2) the highest maximum bit length between ina and inb
- uint32_t resbitlen = std::min(ina->get_bitlength() + inb->get_bitlength(), std::max(ina->get_max_bitlength(), inb->get_max_bitlength()));
- return new boolshare(PutMulGate(ina->get_wires(), inb->get_wires(), resbitlen), this);
+ uint32_t resultbitlen = std::min(ina->get_bitlength() + inb->get_bitlength(), std::max(ina->get_max_bitlength(), inb->get_max_bitlength()));
+ return new boolshare(PutMulGate(ina->get_wires(), inb->get_wires(), resultbitlen), this);
}
share* BooleanCircuit::PutGTGate(share* ina, share* inb) {
@@ -1422,14 +1396,14 @@ std::vector BooleanCircuit::PutWideAddGate(std::vector > BooleanCircuit::PutCSNNetwork(std::vector > ins) {
// build a balanced carry-save network
- uint32_t rep = ins[0].size();
+ uint32_t inputbitlen = ins[0].size();
uint32_t wires = ins.size();
std::vector > survivors(wires * 2);// = ins;
std::vector > carry_lines(wires-2);
std::vector > rem(8);
std::vector > out(2);
- int p_head=wires, p_tail = 0, c_head = 0, c_tail = 0, temp_gates;
- std::vector dummy(rep);
+ int p_head=wires, p_tail = 0, c_head = 0, c_tail = 0;//, temp_gates;
+ std::vector dummy(inputbitlen);
for(uint32_t i = 0; i < ins.size(); i++) {
survivors[i] = ins[i];
@@ -1444,9 +1418,9 @@ std::vector > BooleanCircuit::PutCSNNetwork(std::vector > BooleanCircuit::PutCSNNetwork(std::vector > BooleanCircuit::PutCSNNetwork(std::vector > BooleanCircuit::PutCSNNetwork(std::vector BooleanCircuit::PutSUBGate(std::vector a, std::vector b, uint32_t max_bitlength) {
//pad with leading zeros
if(a.size() < max_bitlength) {
- uint32_t zerogate = PutConstantGate(0, m_pGates[a[0]].nvals);
+ uint32_t zerogate = PutConstantGate(0, m_vGates[a[0]].nvals);
a.resize(max_bitlength, zerogate);
}
if(b.size() < max_bitlength) {
- uint32_t zerogate = PutConstantGate(0, m_pGates[a[0]].nvals);
+ uint32_t zerogate = PutConstantGate(0, m_vGates[a[0]].nvals);
b.resize(max_bitlength, zerogate);
}
@@ -1520,7 +1494,7 @@ std::vector BooleanCircuit::PutSUBGate(std::vector a, std::v
ainv[i] = PutINVGate(a[i]);
}
- C[0] = PutConstantGate(0, m_pGates[a[0]].nvals);
+ C[0] = PutConstantGate(0, m_vGates[a[0]].nvals);
for (i = 0; i < bitlen - 1; i++) {
//===================
@@ -1571,7 +1545,7 @@ uint32_t BooleanCircuit::PutGTGate(std::vector a, std::vector a, std::vector b) {
PadWithLeadingZeros(a, b);
uint32_t ci = 0, ci1, ac, bc, acNbc;
- ci = PutConstantGate((UGATE_T) 0, m_pGates[a[0]].nvals);
+ ci = PutConstantGate((UGATE_T) 0, m_vGates[a[0]].nvals);
for (uint32_t i = 0; i < a.size(); i++, ci = ci1) {
ac = PutXORGate(a[i], ci);
bc = PutXORGate(b[i], ci);
@@ -1586,21 +1560,21 @@ uint32_t BooleanCircuit::PutSizeOptimizedGTGate(std::vector a, std::ve
uint32_t BooleanCircuit::PutDepthOptimizedGTGate(std::vector a, std::vector b) {
PadWithLeadingZeros(a, b);
uint32_t i, rem;
- uint32_t rep = std::min(a.size(), b.size());
- std::vector agtb(rep);
- std::vector eq(rep);
+ uint32_t inputbitlen = std::min(a.size(), b.size());
+ std::vector agtb(inputbitlen);
+ std::vector eq(inputbitlen);
//Put the leaf comparison nodes from which the tree is built
- for (i = 0; i < rep; i++) {
+ for (i = 0; i < inputbitlen; i++) {
agtb[i] = PutANDGate(a[i], PutINVGate(b[i])); //PutBitGreaterThanGate(a[i], b[i]);
}
- //compute the pairwise bit equality from bits 1 to bit rep
- for (i = 1; i < rep; i++) {
+ //compute the pairwise bit equality from bits 1 to bit inputbitlen
+ for (i = 1; i < inputbitlen; i++) {
eq[i] = PutINVGate(PutXORGate(a[i], b[i]));
}
- rem = rep;
+ rem = inputbitlen;
while (rem > 1) {
uint32_t j = 0;
@@ -1699,9 +1673,9 @@ uint32_t BooleanCircuit::PutLUTGTGate(std::vector a, std::vector a, std::vector b) {
PadWithLeadingZeros(a, b);
- uint32_t rep = a.size(), temp;
- std::vector xors(rep);
- for (uint32_t i = 0; i < rep; i++) {
+ uint32_t inputbitlen = a.size(), temp;
+ std::vector xors(inputbitlen);
+ for (uint32_t i = 0; i < inputbitlen; i++) {
temp = PutXORGate(a[i], b[i]);
xors[i] = PutINVGate(temp);
}
@@ -1736,17 +1710,17 @@ share* BooleanCircuit::PutORGate(share* a, share* b) {
/* if c [0] = s & a[0], c[1] = s & a[1], ...*/
share* BooleanCircuit::PutANDVecGate(share* ina, share* inb) {
- uint32_t rep = ina->get_bitlength();
- share* out = new boolshare(rep, this);
+ uint32_t inputbitlen = ina->get_bitlength();
+ share* out = new boolshare(inputbitlen, this);
if (m_eContext == S_BOOL) {
- for (uint32_t i = 0; i < rep; i++) {
+ for (uint32_t i = 0; i < inputbitlen; i++) {
out->set_wire_id(i, PutVectorANDGate(inb->get_wire_id(i), ina->get_wire_id(i)));
}
} else {
//std::cout << "Putting usual AND gate" << std::endl;
- for (uint32_t i = 0; i < rep; i++) {
- uint32_t bvec = PutRepeaterGate(inb->get_wire_id(i), m_pGates[ina->get_wire_id(i)].nvals);
+ for (uint32_t i = 0; i < inputbitlen; i++) {
+ uint32_t bvec = PutRepeaterGate(inb->get_wire_id(i), m_vGates[ina->get_wire_id(i)].nvals);
out->set_wire_id(i, PutANDGate(ina->get_wire_id(i), bvec));
}
}
@@ -1756,21 +1730,21 @@ share* BooleanCircuit::PutANDVecGate(share* ina, share* inb) {
/* if s == 0 ? b : a*/
std::vector BooleanCircuit::PutMUXGate(std::vector a, std::vector b, uint32_t s, BOOL vecand) {
std::vector out;
- uint32_t rep = std::max(a.size(), b.size());
+ uint32_t inputbitlen = std::max(a.size(), b.size());
uint32_t sab, ab;
PadWithLeadingZeros(a, b);
- out.resize(rep);
+ out.resize(inputbitlen);
uint32_t nvals=1;
for(uint32_t i = 0; i < a.size(); i++) {
- if(m_pGates[a[i]].nvals > nvals)
- nvals = m_pGates[a[i]].nvals;
+ if(m_vGates[a[i]].nvals > nvals)
+ nvals = m_vGates[a[i]].nvals;
}
for(uint32_t i = 0; i < b.size(); i++)
- if(m_pGates[b[i]].nvals > nvals)
- nvals = m_pGates[b[i]].nvals;
+ if(m_vGates[b[i]].nvals > nvals)
+ nvals = m_vGates[b[i]].nvals;
if (m_eContext == S_BOOL && vecand && nvals == 1) {
uint32_t avec = PutCombinerGate(a);
@@ -1779,7 +1753,7 @@ std::vector BooleanCircuit::PutMUXGate(std::vector a, std::v
out = PutSplitterGate(PutVecANDMUXGate(avec, bvec, s));
} else {
- for (uint32_t i = 0; i < rep; i++) {
+ for (uint32_t i = 0; i < inputbitlen; i++) {
ab = PutXORGate(a[i], b[i]);
sab = PutANDGate(s, ab);
out[i] = PutXORGate(b[i], sab);
@@ -1799,14 +1773,11 @@ std::vector BooleanCircuit::PutVecANDMUXGate(std::vector a,
PadWithLeadingZeros(a, b);
std::vector out(nmuxes);
- uint32_t sab, ab;
//std::cout << "Putting Vector AND gate" << std::endl;
for (uint32_t i = 0; i < nmuxes; i++) {
- ab = PutXORGate(a[i], b[i]);
- sab = PutVectorANDGate(s[i], ab);
- out[i] = PutXORGate(b[i], sab);
+ out[i] = PutVecANDMUXGate(a[i], b[i], s[i]);
}
return out;
@@ -1819,8 +1790,7 @@ uint32_t BooleanCircuit::PutVecANDMUXGate(uint32_t a, uint32_t b, uint32_t s) {
if (m_eContext == S_BOOL) {
sab = PutVectorANDGate(s, ab);
} else {
- uint32_t svec = PutRepeaterGate(s, m_pGates[ab].nvals);
- sab = PutANDGate(svec, ab);
+ sab = PutANDGate(s, ab);
}
return PutXORGate(b, sab);
}
@@ -1918,11 +1888,11 @@ share** BooleanCircuit::PutCondSwapGate(share* a, share* b, share* s, BOOL vecto
//if s == 0: a stays a, else a becomes b
std::vector > BooleanCircuit::PutCondSwapGate(std::vector a, std::vector b, uint32_t s, BOOL vectorized) {
std::vector > out(2);
- uint32_t rep = std::max(a.size(), b.size());
+ uint32_t inputbitlen = std::max(a.size(), b.size());
PadWithLeadingZeros(a, b);
- out[0].resize(rep);
- out[1].resize(rep);
+ out[0].resize(inputbitlen);
+ out[1].resize(inputbitlen);
uint32_t ab, snab, svec;
@@ -1936,12 +1906,12 @@ std::vector > BooleanCircuit::PutCondSwapGate(std::vector<
out[0] = PutSplitterGate(PutXORGate(snab, avec));
out[1] = PutSplitterGate(PutXORGate(snab, bvec));
} else {
- if (m_pGates[s].nvals < m_pGates[a[0]].nvals)
- svec = PutRepeaterGate(s, m_pGates[a[0]].nvals);
+ if (m_vGates[s].nvals < m_vGates[a[0]].nvals)
+ svec = PutRepeaterGate(s, m_vGates[a[0]].nvals);
else
svec = s;
- for (uint32_t i = 0; i < rep; i++) {
+ for (uint32_t i = 0; i < inputbitlen; i++) {
ab = PutXORGate(a[i], b[i]);
snab = PutANDGate(svec, ab);
@@ -2174,7 +2144,6 @@ void BooleanCircuit::PutMaxIdxGate(std::vector > vals, std
std::vector& maxval, std::vector& maxid) {
// build a balanced binary tree
uint32_t cmp;
- uint32_t avec, bvec;
std::vector > m_vELMs = vals;
#ifdef USE_MULTI_MUX_GATES
uint32_t nvariables = 2;
@@ -2319,8 +2288,8 @@ std::vector BooleanCircuit::PutGateFromFile(const std::string filename
wires[tokens[0]] = PutConstantGate(0, nvals);
break;
- case '1': // Constant Zero Gate
- wires[tokens[0]] = PutConstantGate((1 << nvals) - 1, nvals);
+ case '1': // Constant One Gate
+ wires[tokens[0]] = PutConstantGate(1, nvals);
break;
case 'A': // AND Gate
@@ -2360,6 +2329,7 @@ std::vector BooleanCircuit::PutGateFromFile(const std::string filename
else {
std::cerr << "Error: Unable to open circuit file " << filename << std::endl;
+ std::exit(EXIT_FAILURE);
}
wires.clear();
@@ -2386,6 +2356,7 @@ std::vector BooleanCircuit::PutUniversalCircuitFromFile(const std::str
if(!p1file.is_open()) {
std::cerr << "Error: Unable to open programming file " << p1filename << std::endl;
+ std::exit(EXIT_FAILURE);
}
#ifdef DEBUG_UC
std::cout << "Server Input Control Bits " ;
@@ -2427,6 +2398,7 @@ std::vector BooleanCircuit::PutUniversalCircuitFromFile(const std::str
if (!myfile.is_open()) {
std::cerr << "Error: Unable to open circuit file " << filename << std::endl;
+ std::exit(EXIT_FAILURE);
}
while (getline(myfile, line)) {
@@ -2528,6 +2500,7 @@ void BooleanCircuit::GetInputLengthFromFile(const std::string filename, uint32_t
if (!myfile.is_open()) {
std::cerr << "Error: Unable to open circuit file " << filename << std::endl;
+ std::exit(EXIT_FAILURE);
}
while (getline(myfile, line)) {
@@ -2675,6 +2648,7 @@ std::vector BooleanCircuit::PutLUTGateFromFile(const std::string filen
else {
std::cerr << "Error: Unable to open circuit file " << filename << std::endl;
+ std::exit(EXIT_FAILURE);
}
wires.clear();
@@ -2718,6 +2692,7 @@ uint32_t BooleanCircuit::GetInputLengthFromFile(const std::string filename){
else {
std::cerr << "Error: Unable to open circuit file " << filename << std::endl;
+ std::exit(EXIT_FAILURE);
}
tokens.clear();
@@ -2748,9 +2723,8 @@ uint32_t BooleanCircuit::PutIdxGate(uint32_t r, uint32_t maxidx) {
void BooleanCircuit::PutMultiMUXGate(share** Sa, share** Sb, share* sel, uint32_t nshares, share** Sout) {
std::vector inputsa, inputsb;
- uint32_t *posids;
uint32_t bitlen = 0;
- uint32_t nvals = m_pGates[sel->get_wire_id(0)].nvals;
+ uint32_t nvals = m_vGates[sel->get_wire_id(0)].nvals;
//Yao not allowed, if so just put standard muxes
assert(m_eContext == S_BOOL);
@@ -2821,389 +2795,390 @@ void BooleanCircuit::Reset() {
void BooleanCircuit::PadWithLeadingZeros(std::vector