diff --git a/sgx-jvm/linux-sgx/.gitignore b/sgx-jvm/linux-sgx/.gitignore new file mode 100644 index 0000000000..89a3585dc9 --- /dev/null +++ b/sgx-jvm/linux-sgx/.gitignore @@ -0,0 +1,19 @@ +#object file +*.o + +#library +*.a + +#share object +*.so +*.so.* + +#generated proxy +*_u.c +*_u.h +*_t.c +*_t.h + +#output files +/build/ +/linux/installer/bin/*.bin diff --git a/sgx-jvm/linux-sgx/CONTRIBUTING.md b/sgx-jvm/linux-sgx/CONTRIBUTING.md new file mode 100644 index 0000000000..660066e7e9 --- /dev/null +++ b/sgx-jvm/linux-sgx/CONTRIBUTING.md @@ -0,0 +1,79 @@ +# Contributing + +## Issues + +GitHub Issues tracks SGX SDK and PSW design and development issues, bugs, and feature requests. +For usage, installation, or other requests for help, please use the [01.org](https://01.org/intel-software-guard-extensions/forum/forum) forum instead. + +When reporting a bug, please provide the following information, where applicable: + +* What are the steps to reproduce the bug? +* Can you reproduce the bug using the latest [master](https://github.com/01org/linux-sgx/tree/master)? +* What CPU, platform, operating system/distribution, and SGX driver are you running? The more specific, the better. +* For crashes, please provide the backtrace (use gdb). + + +### Contribution Guide + +We accept contributions as pull requests on GitHub. More detailed guidelines will be added later. Please follow these simple rules for now: + +* A PR should have a clear purpose, and do one thing only, and nothing more. This will enable us review your PR more quickly. +* Each commit in PR should be a small, atomic change representing one step in development. +* Please squash intermediate steps within PR for bugfixes, style cleanups, reversions, etc., so they would not appear in merged PR history. +* Please explain anything non-obvious from the code in comments, commit messages, or the PR description, as appropriate. + +### License + +linux-sgx is licensed under the terms in [LICENSE](https://github.com/01org/linux-sgx/blob/master/License.txt). By contributing to the project, you agree to the license and copyright terms therein and release your contribution under these terms. + +### Sign your work + +Please use the sign-off line at the end of the patch. Your signature certifies that you wrote the patch or otherwise have the right to pass it on as an open-source patch. The rules are pretty simple: if you can certify +the below (from [developercertificate.org](http://developercertificate.org/)): + +``` +Developer Certificate of Origin +Version 1.1 + +Copyright (C) 2004, 2006 The Linux Foundation and its contributors. +660 York Street, Suite 102, +San Francisco, CA 94110 USA + +Everyone is permitted to copy and distribute verbatim copies of this +license document, but changing it is not allowed. + +Developer's Certificate of Origin 1.1 + +By making a contribution to this project, I certify that: + +(a) The contribution was created in whole or in part by me and I + have the right to submit it under the open source license + indicated in the file; or + +(b) The contribution is based upon previous work that, to the best + of my knowledge, is covered under an appropriate open source + license and I have the right under that license to submit that + work with modifications, whether created in whole or in part + by me, under the same open source license (unless I am + permitted to submit under a different license), as indicated + in the file; or + +(c) The contribution was provided directly to me by some other + person who certified (a), (b) or (c) and I have not modified + it. + +(d) I understand and agree that this project and the contribution + are public and that a record of the contribution (including all + personal information I submit with it, including my sign-off) is + maintained indefinitely and may be redistributed consistent with + this project or the open source license(s) involved. +``` + +Then you just add a line to every git commit message: + + Signed-off-by: Joe Smith + +Use your real name (sorry, no pseudonyms or anonymous contributions.) + +If you set your `user.name` and `user.email` git configs, you can sign your +commit automatically with `git commit -s`. diff --git a/sgx-jvm/linux-sgx/License.txt b/sgx-jvm/linux-sgx/License.txt new file mode 100644 index 0000000000..ea9d767559 --- /dev/null +++ b/sgx-jvm/linux-sgx/License.txt @@ -0,0 +1,1396 @@ +BSD License + +Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of Intel Corporation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +================================================================= + +SGX Eclipse plug-in is licensed under Eclipse Public License-v1.0 +http://www.eclipse.org/legal/epl-v10.html + + + +============================================================== + +libsgx_le.signed.so, libsgx_pce.signed.so, libsgx_pve.signed.so and libsgx_qe.signed.so are licensed as Intel redistributable binary firmware and other blobs. + + +Copyright (c) Intel Corporation. + +Redistribution. Redistribution and use in binary form, without +modification, are permitted provided that the following conditions are +met: + +* Redistributions must reproduce the above copyright notice and the + following disclaimer in the documentation and/or other materials + provided with the distribution. +* Neither the name of Intel Corporation nor the names of its suppliers + may be used to endorse or promote products derived from this software + without specific prior written permission. +* No reverse engineering, decompilation, or disassembly of this software + is permitted. + +Limited patent license. Intel Corporation grants a world-wide, +royalty-free, non-exclusive license under patents it now or hereafter +owns or controls to make, have made, use, import, offer to sell and +sell ("Utilize") this software, but solely to the extent that any +such patent is necessary to Utilize the software alone, or in +combination with an operating system licensed under an approved Open +Source license as listed by the Open Source Initiative at +http://opensource.org/licenses. The patent license shall not apply to +any other combinations which include this software. No hardware per +se is licensed hereunder. + +DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH +DAMAGE. + + + +=========================================================================================================================================================== + +SGX software for Linux also uses third-party projects that may be distributed under different licenses. Please see below for details. + + +1. Android Open Source Project + +Copyright (C) 2012 The Android Open Source Project +All rights reserved. +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +2. compiler_rt + +The compiler_rt library is dual licensed under both the University of Illinois +"BSD-Like" license and the MIT license. As a user of this code you may choose +to use it under either license. As a contributor, you agree to allow your code +to be used under both. + +Full text of the relevant licenses is included below. + +============================================================================= + +University of Illinois/NCSA +Open Source License + +Copyright (c) 2009-2013 by the contributors listed in CREDITS.TXT + +All rights reserved. + +Developed by: + + LLVM Team + + University of Illinois at Urbana-Champaign + + http://llvm.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal with the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +- Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimers. + +- Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimers in the documentation and/or +other materials provided with the distribution. + +- Neither the names of the LLVM Team, University of Illinois at Urbana-Champaign, +nor the names of its contributors may be used to endorse or romote products derived +from this Software without specific prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT +OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS WITH THE SOFTWARE. + +============================================================================= + +Copyright (c) 2009-2013 by the contributors listed in CREDITS.TXT + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +============================================================================= +Copyrights and Licenses for Third Party Software Distributed with LLVM: +============================================================================= +The LLVM software contains code written by third parties. Such software will have its +own individual LICENSE.TXT file in the directory in which it appears. +This file will describe the copyrights, license, and restrictions which apply to that code. + +The disclaimer of warranty in the University of Illinois Open Source License applies to all +code in the LLVM Distribution, and nothing in any of the other licenses gives permission to +use the names of the LLVM Team or the University of Illinois to endorse or promote products +derived from this Software. + +The following pieces of software have additional or alternate copyrights, licenses, and/or +restrictions: + +Program Directory +------- --------- +mach_override lib/interception/mach_override + + + +3. DLmalloc + + +Public domain +http://g.oswego.edu/dl/html/malloc.html + +CC0 1.0 Universal + +CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. +DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. +CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS +MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS +PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF +THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER. + +Statement of Purpose +The laws of most jurisdictions throughout the world automatically confer exclusive +Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) +(each and all, an "owner") of an original work of authorship and/or a database (each, +a "Work"). +Certain owners wish to permanently relinquish those rights to a Work for the purpose +of contributing to a commons of creative, cultural and scientific works ("Commons") +that the public can reliably and without fear of later claims of infringement build +upon, modify, incorporate in other works, reuse and redistribute as freely as possible +in any form whatsoever and for any purposes, including without limitation commercial +purposes. These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific works, or to +gain reputation or greater distribution for their Work in part through the use and +efforts of others. +For these and/or other purposes and motivations, and without any expectation of +additional consideration or compensation, the person associating CC0 with a Work +(the "Affirmer"), to the extent that he or she is an owner of Copyright and Related +Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute +the Work under its terms, with knowledge of his or her Copyright and Related Rights +in the Work and the meaning and intended legal effect of CC0 on those rights. +1. Copyright and Related Rights. A Work made available under CC0 may be protected by +copyright and related or neighboring rights ("Copyright and Related Rights"). +Copyright and Related Rights include, but are not limited to, the following: +i. the right to reproduce, adapt, distribute, perform, display, communicate, + and translate a Work; +ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or likeness +depicted in a Work; +iv. rights protecting against unfair competition in regards to a Work, subject +to the limitations in paragraph 4(a), below; +v. rights protecting the extraction, dissemination, use and reuse of data in a Work; +vi. database rights (such as those arising under Directive 96/9/EC of the European +Parliament and of the Council of 11 March 1996 on the legal protection of databases, +and under any national implementation thereof, including any amended or successor +version of such directive); and +vii. other similar, equivalent or corresponding rights throughout the world based on +applicable law or treaty, and any national implementations thereof. +2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable +law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, +abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated +claims and causes of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for +the maximum duration provided by applicable law or treaty (including future time extensions), + (iii) in any current or future medium and for any number of copies, and (iv) for any purpose + whatsoever, including without limitation commercial, advertising or promotional purposes +(the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at +large and to the detriment of Affirmer's heirs and successors, fully intending that such +Waiver shall not be subject to revocation, rescission, cancellation, termination, or any +other legal or equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. +3. Public License Fallback. Should any part of the Waiver for any reason be judged legally +invalid or ineffective under applicable law, then the Waiver shall be preserved to the +maximum extent permitted taking into account Affirmer's express Statement of Purpose. In +addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable +and unconditional license to exercise Affirmer's Copyright and Related Rights in the +Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable +law or treaty (including future time extensions), (iii) in any current or future medium and +for any number of copies, and (iv) for any purpose whatsoever, including without limitation +commercial, advertising or promotional purposes (the "License"). The License shall be deemed +effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the +License for any reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder of the License, +and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his +or her remaining Copyright and Related Rights in the Work or (ii) assert any associated +claims and causes of action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. +4. Limitations and Disclaimers. +a. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, +licensed or otherwise affected by this document. +b. Affirmer offers the Work as-is and makes no representations or warranties of any +kind concerning the Work, express, implied, statutory or otherwise, including without limitation +warranties of title, merchantability, fitness for a particular purpose, non infringement, or +the absence of latent or other defects, accuracy, or the present or absence of errors, whether +or not discoverable, all to the greatest extent permissible under applicable law. +c. Affirmer disclaims responsibility for clearing rights of other persons that may apply + +to the Work or any use thereof, including without limitation any person's Copyright and Related +Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary +consents, permissions or other rights required for any use of the Work. +d. Affirmer understands and acknowledges that Creative Commons is not a party to this +document and has no duty or obligation with respect to this CC0 or use of the Work. + + + + +4. FreeBSD + +http://www.freebsd.org/ + +The FreeBSD* Copyright +Copyright 1992-2013 The FreeBSD Project. All rights reserved. +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. +THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. + + + + +5. libcxxrt + +The BSD License + +Copyright 2010-2011 PathScale, Inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list + of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or other + materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH +DAMAGE. + +The views and conclusions contained in the software and documentation are those of +the authors and should not be interpreted as representing official policies, either +expressed or implied, of PathScale, Inc. + + + + + +6. NetBSD + +=============================================================================================== + +/*- + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +________________________________________ +For complete copyright and licensing terms, see: http://www.netbsd.org/about/redistribution.html + + + + +7. OpenBSD + +http://openbsd.org/ + +OpenBSD* Copyright Policy +________________________________________ +- Goal +Copyright law is complex, OpenBSD* policy is simple - OpenBSD strives to maintain the spirit +of the original Berkeley Unix copyrights. +OpenBSD can exist as it does today because of the example set by the Computer Systems Research +Group at Berkeley and the battles which they and others fought to create a relatively +un-encumbered Unix source distribution. +The ability of a freely redistributable "Berkeley" Unix to move forward on a competitive +basis with other operating systems depends on the willingness of the various development +groups to exchange code amongst themselves and with other projects. Understanding the legal +issues surrounding copyright is fundamental to the ability to exchange and re-distribute code, +while honoring the spirit of the copyright and concept of attribution is fundamental to +promoting the cooperation of the people involved. +- The Berkeley* Copyright +The Berkeley* copyright poses no restrictions on private or commercial use of the software +and imposes only simple and uniform requirements for maintaining copyright notices in +redistributed versions and crediting the originator of the material only in advertising. +For instance: + * Copyright (c) 1982, 1986, 1990, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * +Berkeley rescinded the 3rd term (the advertising term) on 22 July 1999. Verbatim copies +of the Berkeley license in the OpenBSD tree have that term removed. In addition, many +3rd-party BSD-style licenses consist solely of the first two terms. +Because the OpenBSD copyright imposes no conditions beyond those imposed by the Berkeley +copyright, OpenBSD can hope to share the same wide distribution and applicability as the +Berkeley distributions. It follows however, that OpenBSD cannot include material which +includes copyrights which are more restrictive than the Berkeley copyright, or must +relegate this material to a secondary status, i.e. OpenBSD as a whole is freely +redistributable, but some optional components may not be. +- Copyright Law +While the overall subject of copyright law is far beyond the scope of this document, some +basics are in order. Under the current copyright law, copyrights are implicit in the +creation of a new work and reside with the creator, unless otherwise assigned. In general +the copyright applies only to the new work, not the material the work was derived from, +nor those portions of the derivative material included in the new work. +Copyright law admits to three general categories of works: +Original Work +A new work that is not derived from an existing work. +Derivative Work +Work that is derived from, includes or amends existing works. +Compilations +A work that is a compilation of existing new and derivative works. +The fundamental concept is that there is primacy of the copyright, that is a copyright of a +derivative work does not affect the rights held by the owner of the copyright of the original +work, rather only the part added. Likewise the copyright of a compilation does not affect the +rights of the owner of the included works, only the compilation as an entity. +It is vitally important to understand that copyrights are broad protections as defined by +national and international copyright law. The "copyright notices" usually included in source +files are not copyrights, but rather notices that a party asserts that they hold copyright +to the material or to part of the material. Typically these notices are associated with +license terms which grant permissions subject to copyright law and with disclaimers that +state the position of the copyright holder/distributor with respect to liability surrounding +use of the material. +- Permissions - the flip side +Because copyrights arise from the creation of a work, rather than through a registration process, +there needs to be a practical way to extend permission to use a work beyond what might be allowed +by "fair use" provisions of the copyright laws. +This permission typically takes the form of a "release" or "license" included in the work, which +grants the additional uses beyond those granted by copyright law, usually subject to a variety of +conditions. At one extreme sits "public domain" where the originator asserts that he imposes no +restrictions on use of the material, at the other restrictive clauses that actually grant no +additional rights or impose restrictive, discriminatory or impractical conditions on use of the +work. +Again, an important point to note is that the release and conditions can only apply to the +portion of the work that was originated by the copyright holder - the holder of a copyright +on a derivative work can neither grant additional permissions for use of the original work, +nor impose more restrictive conditions for use of that work. +Because copyright arises from the creation of a work and not the text or a registration process, +removing or altering a copyright notice or associated release terms has no bearing on the +existence of the copyright, rather all that is accomplished is to cast doubt upon whatever rights +the person making the modifications had to use the material in the first place. Likewise, adding +terms and conditions in conflict with the original terms and conditions does not supersede them, +rather it casts doubts on the rights of the person making the amendments to use the material and +creates confusion as to whether anyone can use the amended version or derivatives thereof. +Finally, releases are generally binding on the material that they are distributed with. This means +that if the originator of a work distributes that work with a release granting certain permissions, +those permissions apply as stated, without discrimination, to all persons legitimately possessing +a copy of the work. That means that having granted a permission, the copyright holder can not +retroactively say that an individual or class of individuals are no longer granted those permissions. +Likewise should the copyright holder decide to "go commercial" he can not revoke permissions already +granted for the use of the work as distributed, though he may impose more restrictive permissions in +his future distributions of that work. +- Specific Cases +This section attempts to summarize the position of OpenBSD relative to some commonly encountered +copyrights. +Berkeley* +The Berkeley copyright is the model for the OpenBSD copyright. It retains the rights of the +copyright holder, while imposing minimal conditions on the use of the copyrighted material. +Material with Berkeley copyrights, or copyrights closely adhering to the Berkeley model can +generally be included in OpenBSD. +AT&T* +As part of its settlement with AT&T*, Berkeley included an AT&T copyright notice on some of the +files in 4.4BSD lite and lite2. The terms of this license are identical to the standard Berkeley +license. +Additionally, OpenBSD includes some other AT&T code with non-restrictive copyrights, such as the +reference implementation of awk. +Caldera* +Caldera* (now known as the SCO group) is the current owner of the Unix code copyrights. On 23 +January 2002, the original Unix code (versions 1 through seven, including 32V) was freed by Caldera. +This code is now available under a 4-term BSD-style license. As a result, it is now possible to +incorporate real Unix code into OpenBSD (though this code is quite old and generally requires significant +changes to bring it up to date). +DEC*, Sun*, other manufacturers/software houses. +In general OpenBSD does not include material copyrighted by manufacturers or software houses. +Material may be included where the copyright owner has granted general permission for reuse +without conditions, with terms similar to the Berkeley copyright, or where the material is the +product of an employee and the employer's copyright notice effectively releases any rights they +might have to the work. +Carnegie-Mellon* (CMU, Mach) +The Carnegie-Mellon copyright is similar to the Berkeley copyright, except that it requests that +derivative works be made available to Carnegie-Mellon. Because this is only a request and not a +condition, such material can still be included in OpenBSD. It should be noted that existing +versions of Mach are still subject to AT&T copyrights, which prevents the general distribution +of Mach sources. +Apache* +The original Apache* copyright is similar to the Berkeley copyright, except that it stipulates +that products derived from the code may not have "Apache" in their name. The purpose of this +clause is to avoid a situation in which another party releases a modified version of the code +named in such a way to make users think that it is the "official" version. This is not an issue +with OpenBSD because OpenBSD is a Compilation, and not a Derived Work. Source code published under +version 2 of the Apache license cannot be included into OpenBSD. As a consequence, OpenBSD now +maintains its own version of Apache based on version 1.3.29. The OpenBSD version includes many +enhancements and bugfixes. +ISC* +The ISC* copyright is functionally equivalent to a two-term BSD copyright with language removed +that is made unnecessary by the Berne convention. This is the preferred license for new code +incorporated into OpenBSD. A sample license is included in the source tree as +/usr/src/share/misc/license.template. +GNU* General Public License, GPL, LGPL, copyleft, etc. +The GNU* Public License and licenses modeled on it impose the restriction that source code must +be distributed or made available for all works that are derivatives of the GNU copyrighted code. +While this may be a noble strategy in terms of software sharing, it is a condition that is +typically unacceptable for commercial use of software. As a consequence, software bound by the +GPL terms can not be included in the kernel or "runtime" of OpenBSD, though software subject to + GPL terms may be included as development tools or as part of the system that are "optional" as +long as such use does not result in OpenBSD as a whole becoming subject to the GPL terms. +As an example, GCC and other GNU tools are included in the OpenBSD tool chain. However, it is +quite possible to distribute a system for many applications without a tool chain, or the +distributor can choose to include a tool chain as an optional bundle which conforms to the +GPL terms. +NetBSD* +Much of OpenBSD is originally based on and evolved from NetBSD*, since some of the OpenBSD +developers were involved in the NetBSD project. The general NetBSD license terms are compatible +with the Berkeley license and permit such use. Material subject only to the general NetBSD license +can generally be included in OpenBSD. +In the past, NetBSD has included material copyrighted by individuals who have imposed license +conditions beyond that of the general NetBSD license, but granted the NetBSD Foundation license +to distribute the material. Such material can not be included in OpenBSD as long as the conditions +imposed are at odds with the OpenBSD license terms or releases from those terms are offered on a +discriminatory basis. +FreeBSD* +Most of FreeBSD* is also based on Berkeley licensed material or includes copyright notices based +on the Berkeley model. Such material can be included in OpenBSD, while those parts that are subject +to GPL or various individual copyright terms that are at odds with the OpenBSD license can not be +included in OpenBSD. +Linux* +Most of Linux* is subject to GPL style licensing terms and therefore can not be included in +OpenBSD. Individual components may be eligible, subject to the terms of the originator's copyright +notices. Note that Linux "distributions" may also be subject to additional copyright claims of the +distributing organization, either as a compilation or on material included that is not part of the +Linux core. +X*, XFree86*, X.Org* +X*, X.Org* or XFree86* are not parts of OpenBSD, rather X.Org and parts of XFree86 3.3.6 are +distributed with many OpenBSD ports as a convenience to the user, subject to applicable license +terms. +Shareware, Charityware, Freeware, etc. +Most "shareware" copyright notices impose conditions for redistribution, use or visibility that +are at conflict with the OpenBSD project goals. Review on a case-by-case basis is required as to +whether the wording of the conditions is acceptable in terms of conditions being requested vs. +demanded and whether the spirit of the conditions is compatible with goals of the OpenBSD project. +Public Domain +While material that is truly entered into the "Public Domain" can be included in OpenBSD, review +is required on a case by case basis. Frequently the "public domain" assertion is made by someone +who does not really hold all rights under Copyright law to grant that status or there are a variety +of conditions imposed on use. For a work to be truly in the "Public Domain" all rights are abandoned +and the material is offered without restrictions. + + + + +8. Openssl + + +http://www.openssl.org/ + + LICENSE ISSUES + ============== + + The OpenSSL* toolkit stays under a dual license, i.e. both the conditions of + the OpenSSL License and the original SSLeay license apply to the toolkit. + See below for the actual license texts. Actually both licenses are BSD-style + Open Source licenses. In case of any license issues related to OpenSSL + please contact openssl-core@openssl.org. + + OpenSSL License + --------------- + +/* ==================================================================== + * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + + Original SSLeay* License + ----------------------- + +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + + + + +9. Protocol Buffers + +Protocol Buffers - Google's data interchange format +Copyright 2008 Google Inc. All rights reserved. +http://code.google.com/p/protobuf/ +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or other + materials provided with the distribution. +3. Neither the name of the Google Inc. nor the names of its contributors may be used + to endorse or promote products derived from this software without specific prior + written permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + + + + +10. rdrand + +Intel Sample Source Code license. + +This license governs use of the accompanying software. By installing or +copying all or any part of the software components in this package, you +("you" or "Licensee") agree to the terms of this agreement. Do +not install or copy the software until you have carefully read and +agreed to the following terms and conditions. If you do not agree to the +terms of this agreement, promptly return the software to Intel +Corporation ("Intel"). + +1. Definitions: + +A. "Materials" are defined as the software (including the +Redistributables and Sample Source as defined herein), documentation, +and other materials, including any updates and upgrade thereto, that are +provided to you under this Agreement. + +B. "Redistributables" are the files listed in the "redist.txt" file that +is included in the Materials or are otherwise clearly identified as +redistributable files by Intel. + +C. "Sample Source" is the source code file(s) that: (i) +demonstrate(s) certain functions for particular purposes; (ii) are +identified as sample source code; and (iii) are provided hereunder in +source code form. + +D. "Intel's Licensed Patent Claims" means those claims of +Intel's patents that (a) are infringed by the Sample Source or +Redistributables, alone and not in combination, in their unmodified +form, as furnished by Intel to Licensee and (b) Intel has the right to +license. + +2. License Grant: Subject to all of the terms and conditions of this +Agreement: + +A. Intel grants to you a non-exclusive, non-assignable, copyright +license to use the Material for your internal development purposes only. + +B. Intel grants to you a non-exclusive, non-assignable copyright license +to reproduce the Sample Source, prepare derivative works of the Sample +Source and distribute the Sample Source or any derivative works thereof +that you create, as part of the product or application you develop using +the Materials. + +C. Intel grants to you a non-exclusive, non-assignable copyright license +to distribute the Redistributables, or any portions thereof, as part of +the product or application you develop using the Materials. + +D. Intel grants Licensee a non-transferable, non-exclusive, worldwide, +non-sublicenseable license under Intel's Licensed Patent Claims to +make, use, sell, and import the Sample Source and the Redistributables. + +3. Conditions and Limitations: + +A. This license does not grant you any rights to use Intel's name, +logo or trademarks. + +B. Title to the Materials and all copies thereof remain with Intel. The +Materials are copyrighted and are protected by United States copyright +laws. You will not remove any copyright notice from the Materials. You +agree to prevent any unauthorized copying of the Materials. Except as +expressly provided herein, Intel does not grant any express or implied +right to you under Intel patents, copyrights, trademarks, or trade +secret information. + +C. You may NOT: (i) use or copy the Materials except as provided in this +Agreement; (ii) rent or lease the Materials to any third party; (iii) +assign this Agreement or transfer the Materials without the express +written consent of Intel; (iv) modify, adapt, or translate the Materials +in whole or in part except as provided in this Agreement; (v) reverse +engineer, decompile, or disassemble the Materials not provided to you in +source code form; or (vii) distribute, sublicense or transfer the source +code form of any components of the Materials and derivatives thereof to +any third party except as provided in this Agreement. + +D. Platform Limitation - The licenses granted in section 2 extend only +to the software or derivative works that you create that run directly on +a Microsoft Windows operating system product, Microsoft run-time +technology (such as the .NET Framework or Silverlight), or Microsoft +application platform (such as Microsoft Office or Microsoft Dynamics). + +4. No Warranty: + +THE MATERIALS ARE PROVIDED "AS IS". INTEL DISCLAIMS ALL EXPRESS OR +IMPLIED WARRANTIES WITH RESPECT TO THEM, INCLUDING ANY IMPLIED +WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, AND FITNESS FOR ANY +PARTICULAR PURPOSE. + +5. LIMITATION OF LIABILITY: NEITHER INTEL NOR ITS SUPPLIERS SHALL BE +LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, +DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF +BUSINESS INFORMATION, OR OTHER LOSS) ARISING OUT OF THE USE OF OR +INABILITY TO USE THE SOFTWARE, EVEN IF INTEL HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE +EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL +DAMAGES, THE ABOVE LIMITATION MAY NOT APPLY TO YOU. + +6. USER SUBMISSIONS: You agree that any material, information or other +communication, including all data, images, sounds, text, and other +things embodied therein, you transmit or post to an Intel website or +provide to Intel under this Agreement will be considered +non-confidential ("Communications"). Intel will have no confidentiality +obligations with respect to the Communications. You agree that Intel and +its designees will be free to copy, modify, create derivative works, +publicly display, disclose, distribute, license and sublicense through +multiple tiers of distribution and licensees, incorporate and otherwise +use the Communications, including derivative works thereto, for any and +all commercial or non-commercial purposes + +7. TERMINATION OF THIS LICENSE: This Agreement becomes effective on the +date you accept this Agreement and will continue until terminated as +provided for in this Agreement. Intel may terminate this license at any +time if you are in breach of any of its terms and conditions. Upon +termination, you will immediately return to Intel or destroy the +Materials and all copies thereof. + +8. U.S. GOVERNMENT RESTRICTED RIGHTS: The Materials are provided with +"RESTRICTED RIGHTS". Use, duplication or disclosure by the Government is +subject to restrictions set forth in FAR52.227-14 and DFAR252.227-7013 +et seq. or its successor. Use of the Materials by the Government +constitutes acknowledgment of Intel's rights in them. + +9. APPLICABLE LAWS: Any claim arising under or relating to this +Agreement shall be governed by the internal substantive laws of the +State of Delaware, without regard to principles of conflict of laws. You +may not export the Materials in violation of applicable export laws. + + + + + + + + +11. SQLite + +http://sqlite.org/ + +SQLite* Copyright + +All of the code and documentation in SQLite has been dedicated to the public +domain by the authors. All code authors, and representatives of the companies +they work for, have signed affidavits dedicating their contributions to the +public domain and originals of those signed affidavits are stored in a firesafe +at the main offices of Hwaci. Anyone is free to copy, modify, publish, use, +compile, sell, or distribute the original SQLite code, either in source code +form or as a compiled binary, for any purpose, commercial or non-commercial, +and by any means. +The previous paragraph applies to the deliverable code and documentation in +SQLite - those parts of the SQLite library that you actually bundle and ship +with a larger application. Some scripts used as part of the build process +(for example the "configure" scripts generated by autoconf) might fall under +other open-source licenses. Nothing from these build scripts ever reaches the +final deliverable SQLite library, however, and so the licenses associated with +those scripts should not be a factor in assessing your rights to copy and use +the SQLite library. +All of the deliverable code in SQLite has been written from scratch. No code +has been taken from other projects or from the open internet. Every line of +code can be traced back to its original author, and all of those authors have +public domain dedications on file. So the SQLite code base is clean and is +uncontaminated with licensed code from other projects. + + + + + + + +12. STLPort + +License Agreement + +Boris Fomitchev grants Licensee a non-exclusive, non-transferable, + +royalty-free license to use STLport* and its documentation without +fee. + +By downloading, using, +or copying STLport or any portion thereof, +Licensee agrees to abide by the intellectual +property laws and all +other applicable laws of the United States of America, and to all of + +the terms and conditions of this Agreement. + +Licensee shall maintain the following copyright +and permission notices +on STLport sources and its documentation unchanged: + +Copyright 1999,2000 +Boris Fomitchev + +This material is provided "as is", with absolutely no warranty +expressed or +implied. Any use is at your own risk. + +Permission to use or copy this software for any purpose +is hereby +granted without fee, provided the above notices are retained on all +copies. Permission +to modify the code and to distribute modified code +is granted, provided the above notices are +retained, and a notice that +the code was modified is included with the above copyright notice. + + +The Licensee may distribute binaries compiled with STLport whether +original or modified) without +any royalties or restrictions. + +The Licensee may distribute original or modified STLport sources, + +provided that: + + - The conditions indicated in the above permission notice are met; + - The +following copyright notices are retained when present, and + conditions provided in +accompanying permission notices are met : + +Copyright 1994 Hewlett-Packard Company +Copyright +1996,97 Silicon Graphics Computer Systems, Inc. +Copyright 1997 Moscow Center for SPARC +Technology. + + Permission to use, copy, modify, distribute and sell this software + and its +documentation for any purpose is hereby granted without fee, + provided that the above +copyright notice appear in all copies and + that both that copyright notice and this permission +notice appear in + supporting documentation. Hewlett-Packard Company makes no + representations +about the suitability of this software for any + purpose. It is provided "as is" without +express or implied warranty. + + Permission to use, copy, modify, distribute and sell this +software + and its documentation for any purpose is hereby granted without fee, + provided that +the above copyright notice appear in all copies and + that both that copyright notice and this +permission notice appear in + supporting documentation. Silicon Graphics makes no representations + +about the suitability of this software for any purpose. It is + provided "as is" without express +or implied warranty. + + Permission to use, copy, modify, distribute and sell this software + and +its documentation for any purpose is hereby granted without fee, + provided that the above +copyright notice appear in all copies and + that both that copyright notice and this permission +notice appear in + supporting documentation. Moscow Center for SPARC Technology?makes + no +representations about the suitability of this software for any + purpose. It is provided "as is" +without express or implied warranty. + + + +http://www.stlport.org/doc/license.html + + + + + + +13. TinyXML + +http://www.grinninglizard.com/tinyxml/ + + +The zlib/libpng License +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the +use of this software. +Permission is granted to anyone to use this software for any purpose, including +commercial applications, and to alter it and redistribute it freely, subject to +the following restrictions: +1. The origin of this software must not be misrepresented; you must not claim + that you wrote the original software. If you use this software in a product, + an acknowledgment in the product documentation would be appreciated but is + not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. + + + + + +14. libunwind + +Copyright (C) 1996 X Consortium +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Except as contained in this notice, the name of the X Consortium shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the X Consortium. +X Window System is a trademark of X Consortium, Inc. + + + +15. ittnotify library + +BSD/GPLv2 dual license + +Copyright (c) 2011, Intel Corporation +All rights reserved. +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + Neither the name of the Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +The GNU General Public License (GPL) +Version 2, June 1991 +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. +Preamble +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. +To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. +For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. +We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. +Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. +Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. +The precise terms and conditions for copying, distribution and modification follow. +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + + + +16. EPID SDK + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + + +17. Eclipse Plug-in + +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: +i) changes to the Program, and +ii) additions to the Program; +where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. + +"Program" means the Contributions distributed in accordance with this Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. +b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. +c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. +d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: + +a) it complies with the terms and conditions of this Agreement; and +b) its license agreement: +i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; +ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; +iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and +iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. +When the Program is made available in source code form: + +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of the Program. +Contributors may not remove or alter any copyright notices contained within the Program. + +Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build.sh b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build.sh new file mode 100755 index 0000000000..e4bd19a937 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build.sh @@ -0,0 +1,251 @@ +#!/bin/bash +export PATH=/home/jenkins/jdk/bin/:$PATH + + +# Get the Eclipse launcher and build script to use +set -x +set -e + +TRUNK_HOME=$(cd $(pwd)/../../ ; pwd) +#gives you the posibility to overwrite eclipse, if you do not use URL +[ -n "${ECLIPSE_HOME}" ] || { echo "using default ECLIPSE_HOME=${TRUNK_HOME}/eclipse"; ECLIPSE_HOME=${TRUNK_HOME}/eclipse; } + + +BUILD_RELEASE_ID_PREFIX=Linux_SGX_1.5 + +if [ "$RELEASE_ID" != "${RELEASE_ID%$BUILD_RELEASE_ID_PREFIX*}" ]; then + echo "$BUILD_RELEASE_ID_PREFIX IS in $RELEASE_ID, so it is an triggered build. Change the RELEASE_ID to an accepted form." + temp=${RELEASE_ID#$BUILD_RELEASE_ID_PREFIX} + RELEASE_ID=v`echo ${temp} | tr -d _ | tr -d -` +else + echo "$BUILD_RELEASE_ID_PREFIX is NOT in $RELEASE_ID. Keeping the user specified RELEASE_ID." +fi + +function main() { + validate-jenkins-parameters + cleanupPreBuild + checkEnvironment + buildPlugin + archivePlugin +} + +function validate-jenkins-parameters { + validate-parameter "DELETE_CURRENT_ECLIPSE" "$DELETE_CURRENT_ECLIPSE" + [[ "ECLIPSE_DOWNLOAD_URL" != "" ]] && + echo "[WARNING] ECLIPSE_DOWNLOAD_URL is not set; assume eclipse archive is already downloaded" +} + +function validate-parameter { + local NAME="$1" + local VALUE="$2" + [[ ! -z "$VALUE" ]] || { + echo "Mandatory Jenkins parameter '\$$NAME' not set !" + exit 1 + } +} + +function cleanupPreBuild() { + ./clean.sh + + [[ "false" == "${DELETE_CURRENT_ECLIPSE}" ]] || { + forceRemoveEclipse + } +} + +function forceRemoveEclipse() { + pushd ${TRUNK_HOME} + rm -fr eclipse + popd +} + +function checkEnvironment() { + if [ ! -d "${ECLIPSE_HOME}" ]; then + echo "Eclipse does not exist" + echo "Downloading eclipse" + + getEclipse + fi + + if [ -z "$RELEASE_ID" ]; then + echo "Mandatory variable RELEASE_ID not defined; exiting" + exit + fi +} + +function getEclipse() { + local eclipseArchiveURL="${ECLIPSE_DOWNLOAD_URL}" + + pushd $TRUNK_HOME + cleanupEclipseArchive + downloadEclipse "${eclipseArchiveURL}" + unzipEclipse + installPDE + cleanupEclipseArchive + popd +} + +function cleanupEclipseArchive() { + find . -maxdepth 1 -mindepth 1 -name "*eclipse*.zip*" | xargs rm -f +} + +function downloadEclipse() { + local URL="$1" + if [[ "$1" != "" ]] ; then + echo " wget --no-proxy "$1"" + wget --no-proxy "$1" + else + echo "skip downloaded empty url" + fi + +} + +function unzipEclipse() { + pwd + rm -fr eclipse + local eclipseArchiveName="$(find . -maxdepth 1 -mindepth 1 -name "*eclipse*.zip*")" + unzip "${eclipseArchiveName}" + + [[ -d eclipse ]] || { + echo "Eclipse directory does not exist!" + exit + } + +# local eclipseFolderName=${eclipseArchiveName%.zip} +# local eclipseArchiveName="eclipse" +# mv "${eclipseFolderName}" eclipse +} + +function installPDE() { +echo "~~~~>" +pwd +${ECLIPSE_HOME}/eclipse -nosplash \ + -application org.eclipse.equinox.p2.director \ + -repository http://download.eclipse.org/eclipse/updates/4.4 \ + -destination ${ECLIPSE_HOME} \ + -installIU org.eclipse.pde.source.feature.group \ + -installIU org.eclipse.pde.feature.group +} + +function preBuild() { + local BUILDDIR="$1" + local BUILDDIRWORK="$2" + + local SITEFILE="$BUILDDIRWORK/sites/site.xml" + local FEATUREDIR="$BUILDDIRWORK/features" + local FEATUREFILE="feature.xml" + local PLUGINDIR="$BUILDDIRWORK/plugins" + local PLUGINFILE="META-INF/MANIFEST.MF" + + local ROOTDIR=$(dirname "$0")"/.." + local VERSION=$(awk '/STRFILEVER/ {print $3}' ${ROOTDIR}/common/inc/internal/se_version.h|sed 's/^\"\(.*\)\"$/\1/') + VERSION=$(echo "$VERSION" | awk -F'.' '{for(i=1; i<=NF&&i<=3; i++) if(i==1){version=$i} else{version=version"."$i}}; END{print version}') + + if [[ "$VERSION" =~ ^[0-9]{1,}(.[0-9]{1,}){2}$ ]]; then + rm -fr "$BUILDDIRWORK" + cp -fr "$BUILDDIR" "$BUILDDIRWORK" + + #site.xml + sed -i "s#[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{0,2\}\.qualifier#$VERSION\.qualifier#g" "$SITEFILE" + + #feature + for DIR in $(ls "$FEATUREDIR"); do + sed -i "s#[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{0,2\}\.qualifier#$VERSION\.qualifier#g" "$FEATUREDIR/$DIR/$FEATUREFILE" + done + + #plugin + for DIR in $(ls "$PLUGINDIR"); do + sed -i "s#[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{0,2\}\.qualifier#$VERSION\.qualifier#g" "$PLUGINDIR/$DIR/$PLUGINFILE" + done + fi +} + +function postBuild() { + local BUILDDIR="$1" + local BUILDDIRWORK="$2" + local UPDATESITEDIR="updatesite" + + if [[ -d "$BUILDDIRWORK" ]] && [[ -d "$BUILDDIRWORK/$UPDATESITEDIR" ]]; then + rm -fr "$BUILDDIR/$UPDATESITEDIR" + cp -fr "$BUILDDIRWORK/$UPDATESITEDIR" "$BUILDDIR/$UPDATESITEDIR" + rm -fr "$BUILDDIRWORK" + fi +} + +function buildPlugin() { + pwd + + echo "PWD=`pwd`" + echo "ECLIPSE_HOME=$ECLIPSE_HOME" + + #BASELOCATION="$PWD/target_platform" + BASELOCATION="$ECLIPSE_HOME" + BUILDVERSION="$RELEASE_ID" + BUILDDIR="$PWD/build_directory" + BUILDDIRWORK="$PWD/.build_directory" + BUILDCONFIG="$PWD/build_config" + LAUNCHER=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.equinox.launcher_*.jar` + BUILDFILE=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.pde.build_*/scripts/build.xml` + + # make sure we found valid files + if [ ! -f "$LAUNCHER" ]; then + echo "Installation Error: Eclipse plugin org.eclipse.equinox.launcher...jar not detected. " \ + "Found '$LAUNCHER'. Aborting." + exit 1 + fi + if [ ! -f "$BUILDFILE" ]; then + echo "Installation Error: Eclipse build file org.eclipse.pde.build_.../scripts/build.xml " \ + "not detected. Found '$BUILDFILE'. Aborting." + exit 1 + fi + + preBuild "$BUILDDIR" "$BUILDDIRWORK" + + # + # -- Print configuration used and actually execute the build -- + # + echo "Eclipse configuration found:" + echo " Eclipse Home: $ECLIPSE_HOME" + echo " Launcher: $LAUNCHER" + echo " Build File: $BUILDFILE" + echo " Build Config: $BUILDCONFIG" + echo " Base Location: $BASELOCATION" + echo " Build Directory: $BUILDDIRWORK" + echo " Build Version: $BUILDVERSION" + echo " Java: " $(which java) + java -version + +# CURRENT_DIR=$(pwd) +# ${ECLIPSE_HOME}/eclipse -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher -metadataRepository file:/${CURRENT_DIR}/build_directory/updatesite/sgx-eclipse-plugin -artifactRepository file:/${CURRENT_DIR}/build_directory/updatesite/featuresAndBundles -source ${CURRENT_DIR}/build_directory/ -config gtk.linux.x86 -compress -publishArtifacts +# cp ./build_directory/updatesite/featuresAndBundles/artifacts.jar ./build_directory/updatesite/sgx-eclipse-plugin/ + + java \ + -jar $LAUNCHER \ + -application org.eclipse.ant.core.antRunner \ + -buildfile $BUILDFILE \ + -DbuildDirectory=$BUILDDIRWORK \ + -DbaseLocation=$BASELOCATION \ + -Dbuilder=$BUILDCONFIG \ + -DforceContextQualifier=$BUILDVERSION \ + -v -v -v -v + + postBuild "$BUILDDIR" "$BUILDDIRWORK" +} + +function findFirst() { + echo "enter Find First, $@" 1>&2 + for i in "$@"; do + if [ -f "$i" ]; then + echo "found $i" 1>&2 + echo "$i" + return + fi + done +} + +function archivePlugin() { + pushd build_directory/updatesite/sgx-eclipse-plugin + zip -r Intel-sgx-eclipse-plugin.zip * + popd +} + +main diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/allElements.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/allElements.xml new file mode 100644 index 0000000000..0bb5016556 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/allElements.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/build.properties b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/build.properties new file mode 100644 index 0000000000..beda7eaf99 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/build.properties @@ -0,0 +1,307 @@ + +############################################################################### +# Copyright (c) 2003, 2011 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +# Compuware Corporation - Sebastien Angers +# - Enabled additional mirror slicingOptions in Headless PDE Build +# - Enabled 'raw' attribute for mirror step in Headless PDE Build +# - https://bugs.eclipse.org/338878 +############################################################################### +##################### +# Parameters describing how and where to execute the build. +# Typical users need only update the following properties: +# baseLocation - where things you are building against are installed +# bootclasspath - The base jars to compile against (typicaly rt.jar) +# configs - the list of {os, ws, arch} configurations to build. +# +# Of course any of the settings here can be overridden by spec'ing +# them on the command line (e.g., -DbaseLocation=d:/eclipse + +#The type of the top level element we are building, generally "feature" +topLevelElementType = feature +#The id of the top level element we are building +# the following feature will not be include in the final archive +topLevelElementId = com.intel.sgx.build.driver + +############# PRODUCT/PACKAGING CONTROL ############# +#product=/plugin or feature id/path/to/.product +#product=com.intel.sgx.feature +runPackager=false + +#Set the name of the archive that will result from the product build. +#archiveNamePrefix= + +# The prefix that will be used in the generated archive. +archivePrefix=sgx-eclipse-plugin + +# The location underwhich all of the build output will be collected. +collectingFolder=${archivePrefix} + +# The list of {os, ws, arch} configurations to build. This +# value is a '&' separated list of ',' separate triples. For example, +# configs=win32,win32,x86 & linux,motif,x86 +# By default the value is *,*,* +configs = *, *, * +#configs=win32, win32, x86 & \ +# win32,win32,x86_64 & \ +# win32,win32,wpf & \ +# linux, gtk, ppc & \ +# linux, gtk, x86 & \ +# linux, gtk, x86_64 & \ +# linux, motif, x86 & \ +# solaris, motif, sparc & \ +# solaris, gtk, sparc & \ +# aix, motif, ppc & \ +# hpux, motif, ia64_32 & \ +# macosx, carbon, ppc & \ +# macosx, carbon, x86 & \ +# macosx, cocoa, ppc & \ +# macosx, cocoa, x86 & \ +# macosx, cocoa, x86_64 + +# By default PDE creates one archive (result) per entry listed in the configs property. +# Setting this value to true will cause PDE to only create one output containing all +# artifacts for all the platforms listed in the configs property. +# To control the output format for the group, add a "group, group, group - " entry to the +# archivesFormat. +#groupConfigurations=true + +#The format of the archive. By default a zip is created using antZip. +#The list can only contain the configuration for which the desired format is different than zip. +#archivesFormat=win32, win32, x86 - antZip& \ +# linux, gtk, ppc - antZip &\ +# linux, gtk, x86 - antZip& \ +# linux, gtk, x86_64 - antZip& \ +# linux, motif, x86 - antZip& \ +# solaris, motif, sparc - antZip& \ +# solaris, gtk, sparc - antZip& \ +# aix, motif, ppc - antZip& \ +# hpux, motif, PA_RISC - antZip& \ +# macosx, carbon, ppc - antZip + +#Allow cycles involving at most one bundle that needs to be compiled with the rest being binary bundles. +allowBinaryCycles = true + +#Sort bundles depenedencies across all features instead of just within a given feature. +#flattenDependencies = true + +#Parallel compilation, requires flattenedDependencies=true +#parallelCompilation=true +#parallelThreadCount= +#parallelThreadsPerProcessor= + +#Set to true if you want the output to be ready for an update jar (no site.xml generated) +outputUpdateJars = true + +#Set to true for Jnlp generation +#codebase should be a URL that will be used as the root of all relative URLs in the output. +#generateJnlp=false +#jnlp.codebase= +#jnlp.j2se= +#jnlp.locale= +#jnlp.generateOfflineAllowed=true or false generate attribute in the generated features +#jnlp.configs=${configs} #uncomment to filter the content of the generated jnlp files based on the configuration being built + +#Set to true if you want to sign jars +#signJars=false +#sign.alias= +#sign.keystore= +#sign.storepass= +#sign.keypass= + +#Arguments to send to the zip executable +zipargs= + +#Arguments to send to the tar executable +tarargs= + +#individualSourceBundles=true + +#Control the creation of a file containing the version included in each configuration - on by default +#generateVersionsLists=false + +############ REPO MIRROR OPTIONS CONTROL ############ +# Default values for the slicingOptions and raw attribute of the p2.mirror Ant target used to generate the p2 repo (buildRepo) +# Note that the default values used by PDE/Build are different from the default values for p2.mirror's slicingOptions and raw attribute +# See http://help.eclipse.org/topic//org.eclipse.platform.doc.isv/guide/p2_repositorytasks.htm for the details +# of each setting. +#p2.mirror.slicing.filter= +#p2.mirror.slicing.followOnlyFilteredRequirements=false +#p2.mirror.slicing.followStrict=false +#p2.mirror.slicing.includeFeatures=true +#p2.mirror.slicing.includeNonGreedy=false +#p2.mirror.slicing.includeOptional=true +#p2.mirror.slicing.platformFilter= +#p2.mirror.slicing.latestVersionOnly=false + +#p2.mirror.raw=false + +############## SOURCE BUNDLE CONTROL ################ +# Set this property to have source bundles created and output into build repository. +# This does NOT put them in the build output (e.g., product) itself. +# Valid values are: not set, built, all. +# built = only source for bundles that are actually built/compiled in this run are output +# all = all available source is collected and output +#sourceBundleMode=all + +# When outputting autogenerated source bundles a feature is created to contain all the automatic +# source bundles. Typically this feature is not needed and can be ignored. As such, it is given a default +# name and version. These properties can be used to override the defaults. +# sourceBundleTemplateFeature - can specify an existing feature which will be augmented to form the generated source feature +# sourceBundleFeatureId - will be the id of generated source feature which contains all the generated source bundles, default value +# is sourceBundleTemplateFeature + ".source" if sourceBundleTemplateFeature is specified +#sourceBundleTemplateFeature= +#sourceBundleFeatureId= +#sourceBundleFeatureVersion= + +############## BUILD NAMING CONTROL ################ +# The directory into which the build elements are fetched and where +# the build takes place. +#buildDirectory= + +# Type of build. Used in naming the build output. Typically this value is +# one of I, N, M, S, ... +buildType=build + +# ID of the build. Used in naming the build output. +buildId=${forceContextQualifier} + +# Label for the build. Used in naming the build output +buildLabel=${buildId} + +# Timestamp for the build. Used in naming the build output +timestamp=007 + +#The value to be used for the qualifier of a plugin or feature when you want to override the value computed by pde. +#The value will only be applied to plugin or features indicating build.properties, qualifier = context +#forceContextQualifier= + +#Enable / disable the generation of a suffix for the features that use .qualifier. +#The generated suffix is computed according to the content of the feature +#generateFeatureVersionSuffix=true + +############# BASE CONTROL ############# +# Settings for the base Eclipse components and Java class libraries +# against which you are building. +# Base location for anything the build needs to compile against. For example, +# in most RCP app or a plug-in, the baseLocation should be the location of a previously +# installed Eclipse against which the application or plug-in code will be compiled and the RCP delta pack. + +base= +#baseLocation= + +#Folder containing repositories whose content is needed to compile against +#repoBaseLocation=${base}/repos +#Folder where the content of the repositories from ${repoBaseLocation} will be made available as a form suitable to be compiled against +#transformedRepoLocation=${base}/transformedRepos + +#Os/Ws/Arch/nl of the eclipse specified by baseLocation +baseos=win32 +basews=win32 +basearch=x86 + +#this property indicates whether you want the set of plug-ins and features to be considered during the build to be limited to the ones reachable from the features / plugins being built +filteredDependencyCheck=false + +#this property indicates whether the resolution should be done in development mode (i.e. ignore multiple bundles with singletons) +resolution.devMode=false + +#pluginPath is a list of locations in which to find plugins and features. This list is separated by the platform file separator (; or :) +#a location is one of: +#- the location of the jar or folder that is the plugin or feature : /path/to/foo.jar or /path/to/foo +#- a directory that contains a /plugins or /features subdirectory +#- the location of a feature.xml, or for 2.1 style plugins, the plugin.xml or fragment.xml +#pluginPath= + +skipBase=true +eclipseURL= +eclipseBuildId= +eclipseBaseURL=${eclipseURL}/eclipse-platform-${eclipseBuildId}-win32.zip + + +############# MAP FILE CONTROL ################ +# This section defines CVS tags to use when fetching the map files from the repository. +# If you want to fetch the map file from repository / location, change the getMapFiles target in the customTargets.xml + +skipMaps=true +mapsRepo=:pserver:anonymous@example.com/path/to/repo +mapsRoot=path/to/maps +mapsCheckoutTag=HEAD + +#tagMaps=true +mapsTagTag=v${buildId} + + +############ REPOSITORY CONTROL ############### +# This section defines properties parameterizing the repositories where plugins, fragments +# bundles and features are being obtained from. + +# The tags to use when fetching elements to build. +# By default thebuilder will use whatever is in the maps. +# This value takes the form of a comma separated list of repository identifier (like used in the map files) and the +# overriding value +# For example fetchTag=CVS=HEAD, SVN=v20050101 +# fetchTag=HEAD +skipFetch=true + + +############# JAVA COMPILER OPTIONS ############## +# The location of the Java jars to compile against. Typically the rt.jar for your JDK/JRE +#bootclasspath=${java.home}/lib/rt.jar + +# specific JRE locations to compile against. These values are used to compile bundles specifying a +# Bundle-RequiredExecutionEnvironment. Uncomment and set values for environments that you support +#CDC-1.0/Foundation-1.0= /path/to/rt.jar +#CDC-1.1/Foundation-1.1= +#OSGi/Minimum-1.0= +#OSGi/Minimum-1.1= +#JRE-1.1= +#J2SE-1.2= +#J2SE-1.3= +#J2SE-1.4= +#J2SE-1.5= +#JavaSE-1.6= +#PersonalJava-1.1= +#PersonalJava-1.2= +#CDC-1.0/PersonalBasis-1.0= +#CDC-1.0/PersonalJava-1.0= +#CDC-1.1/PersonalBasis-1.1= +#CDC-1.1/PersonalJava-1.1= + +# Specify the output format of the compiler log when eclipse jdt is used +logExtension=.log + +# Whether or not to include debug info in the output jars +javacDebugInfo=false + +# Whether or not to fail the build if there are compiler errors +javacFailOnError=true + +# Enable or disable verbose mode of the compiler +javacVerbose=true + +# Extra arguments for the compiler. These are specific to the java compiler being used. +#compilerArg= + +# Default value for the version of the source code. This value is used when compiling plug-ins that do not set the Bundle-RequiredExecutionEnvironment or set javacSource in build.properties +javacSource=1.6 + +# Default value for the version of the byte code targeted. This value is used when compiling plug-ins that do not set the Bundle-RequiredExecutionEnvironment or set javacTarget in build.properties. +javacTarget=1.6 + +################### CUSTOM PROPERTIES ####################################### +# repository location for update site +# comment out - this is passed in from command line +updateSiteSource=${buildDirectory}/sites +# where to place update site build +#updateSiteRoot=${user.home}/www/no_crawl/ +updateSiteRoot=${buildDirectory}/updatesite +updateSiteFolder=${archivePrefix} +updateSiteDestination=${updateSiteRoot}/${updateSiteFolder} + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/buildUpdateSite.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/buildUpdateSite.xml new file mode 100644 index 0000000000..a01006f811 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/buildUpdateSite.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/customAssembly.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/customAssembly.xml new file mode 100644 index 0000000000..ebe2861da3 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/customAssembly.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/customTargets.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/customTargets.xml new file mode 100644 index 0000000000..0a7316b142 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_config/customTargets.xml @@ -0,0 +1,208 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/features/com.intel.sgx.feature/.project b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/features/com.intel.sgx.feature/.project new file mode 100644 index 0000000000..2320c4af2d --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/features/com.intel.sgx.feature/.project @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + com.intel.sgx.feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/features/com.intel.sgx.feature/build.properties b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/features/com.intel.sgx.feature/build.properties new file mode 100644 index 0000000000..6fe048450c --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/features/com.intel.sgx.feature/build.properties @@ -0,0 +1,15 @@ +######################################################################### +# Copyright (c) 2016 Intel Corporation. # +# # +# All rights reserved. This program and the accompanying materials # +# are made available under the terms of the Eclipse Public License v1.0 # +# which accompanies this distribution, and is available at # +# http://www.eclipse.org/legal/epl-v10.html # +# # +# Contributors: # +# Intel Corporation - initial implementation and documentation # +######################################################################### + +bin.includes = feature.xml,\ + build.properties +generate.plugin@com.intel.sgx.source = com.intel.sgx.feature diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/features/com.intel.sgx.feature/feature.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/features/com.intel.sgx.feature/feature.xml new file mode 100644 index 0000000000..f9047a713e --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/features/com.intel.sgx.feature/feature.xml @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + The Software Guard Extensions Plug-in enables Independent Service +Vendors in developing Linux applications +with Software Guard Extensions. The Plug-in extends the C/C++ Development +tools Plug-in to allow ISVs develop secure extensions in C or +C++. The Plug-in also allows conversion of an Linux Application +project into an Linux Application project with Software Guard +Extensions. +Using the Plug-in features and SGX Plug-in Menu options, a developer +can modify the Signing keys and Enclave Configuration for an +Enclave project and can add enclaves inside a project with SGX Nature. +Once development is complete, the developer can build the Enclave +and the Linux project using the SGX SDK for Linux with Release/Debug Configurations in Simulation/Hardware +mode and Hardware Prerelease mode. + + + + All rights reserved with Intel Corporation and its Licensors. + + + + Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: +i) changes to the Program, and +ii) additions to the Program; +where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. + +"Program" means the Contributions distributed in accordance with this Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. +b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. +c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. +d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: + +a) it complies with the terms and conditions of this Agreement; and +b) its license agreement: +i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; +ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; +iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and +iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. +When the Program is made available in source code form: + +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of the Program. +Contributors may not remove or alter any copyright notices contained within the Program. + +Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/.classpath b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/.classpath new file mode 100644 index 0000000000..791c66decf --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/.classpath @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/.project b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/.project new file mode 100644 index 0000000000..76c2e17b70 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/.project @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + com.intel.sgx.userguide + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/META-INF/MANIFEST.MF b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..5db6ad6bff --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +License: Eclipse Public License Version 1.0 ("EPL") +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: SGX Eclipse Plugin Userguide +Bundle-SymbolicName: com.intel.sgx.userguide;singleton:=true +Bundle-Version: 1.0.1.qualifier +Bundle-Activator: com.intel.sgx.userguide.Activator +Bundle-Vendor: INTEL +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime +Bundle-ActivationPolicy: lazy diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/build.properties b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/build.properties new file mode 100644 index 0000000000..b148cda4b4 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/build.properties @@ -0,0 +1,19 @@ +######################################################################### +# Copyright (c) 2016 Intel Corporation. # +# # +# All rights reserved. This program and the accompanying materials # +# are made available under the terms of the Eclipse Public License v1.0 # +# which accompanies this distribution, and is available at # +# http://www.eclipse.org/legal/epl-v10.html # +# # +# Contributors: # +# Intel Corporation - initial implementation and documentation # +######################################################################### + +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + html/,\ + *.xml diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/A_Generated_Trusted_Library.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/A_Generated_Trusted_Library.png new file mode 100644 index 0000000000..d6cb5308c4 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/A_Generated_Trusted_Library.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_New_Intel_SGX_Enclave_Dialog.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_New_Intel_SGX_Enclave_Dialog.png new file mode 100644 index 0000000000..c857d80377 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_New_Intel_SGX_Enclave_Dialog.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_New_SGX_Static_Trusted_Library_Dialog.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_New_SGX_Static_Trusted_Library_Dialog.png new file mode 100644 index 0000000000..8fd22a4260 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_New_SGX_Static_Trusted_Library_Dialog.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_Repository_Dialog.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_Repository_Dialog.png new file mode 100644 index 0000000000..3d5dd178e5 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_Repository_Dialog.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_SGX_Nature.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_SGX_Nature.png new file mode 100644 index 0000000000..d6dbf14a6d Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_SGX_Nature.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_SGX_Untrusted_Module.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_SGX_Untrusted_Module.png new file mode 100644 index 0000000000..deec5090e3 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Add_SGX_Untrusted_Module.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Configurations_Specific_to_Intel_SGX_Technology.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Configurations_Specific_to_Intel_SGX_Technology.png new file mode 100644 index 0000000000..f36ca69c05 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Configurations_Specific_to_Intel_SGX_Technology.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Configure_SGX_Hardware_Release_Mode.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Configure_SGX_Hardware_Release_Mode.png new file mode 100644 index 0000000000..f7151654d0 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Configure_SGX_Hardware_Release_Mode.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Copying_the_Untrusted_Module_to_a_Project.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Copying_the_Untrusted_Module_to_a_Project.png new file mode 100644 index 0000000000..fb363ea78d Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Copying_the_Untrusted_Module_to_a_Project.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Customization_of_SGX_build_command.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Customization_of_SGX_build_command.png new file mode 100644 index 0000000000..a9c509501b Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Customization_of_SGX_build_command.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Down_Arrow_Button.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Down_Arrow_Button.png new file mode 100644 index 0000000000..fccabba54e Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Down_Arrow_Button.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Enclave_Configuration_Settings.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Enclave_Configuration_Settings.png new file mode 100644 index 0000000000..42217bd097 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Enclave_Configuration_Settings.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generate_Signed_Enclave_Dialog.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generate_Signed_Enclave_Dialog.png new file mode 100644 index 0000000000..9eebe98c66 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generate_Signed_Enclave_Dialog.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generate_Signed_Enclave_Dialog_with_Pre_configurations.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generate_Signed_Enclave_Dialog_with_Pre_configurations.png new file mode 100644 index 0000000000..538d68743a Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generate_Signed_Enclave_Dialog_with_Pre_configurations.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generated_Sample_Untrusted_Application.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generated_Sample_Untrusted_Application.png new file mode 100644 index 0000000000..7e7c609d61 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generated_Sample_Untrusted_Application.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generated_Skeleton_for_an_Enclave.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generated_Skeleton_for_an_Enclave.png new file mode 100644 index 0000000000..55e27af3ab Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generated_Skeleton_for_an_Enclave.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generating_Hash_Completion_Dialog.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generating_Hash_Completion_Dialog.png new file mode 100644 index 0000000000..032c17a2ea Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Generating_Hash_Completion_Dialog.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Import_or_Re_Generate_Enclave_Signing_Key.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Import_or_Re_Generate_Enclave_Signing_Key.png new file mode 100644 index 0000000000..d954544841 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Import_or_Re_Generate_Enclave_Signing_Key.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Intel_SGX_Configurations.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Intel_SGX_Configurations.png new file mode 100644 index 0000000000..f7151654d0 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Intel_SGX_Configurations.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Intel_SGX_Tools.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Intel_SGX_Tools.png new file mode 100644 index 0000000000..fb9ec29775 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Intel_SGX_Tools.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Makefile_for_Intel_SGX.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Makefile_for_Intel_SGX.png new file mode 100644 index 0000000000..466558cb4c Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Makefile_for_Intel_SGX.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/New_Project.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/New_Project.png new file mode 100644 index 0000000000..f7f391f6d6 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/New_Project.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Project_Explorer.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Project_Explorer.png new file mode 100644 index 0000000000..94913f3980 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Project_Explorer.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Project_Menu.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Project_Menu.png new file mode 100644 index 0000000000..659f0d92f3 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Project_Menu.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/SGX_Preference_Page.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/SGX_Preference_Page.png new file mode 100644 index 0000000000..90170646b4 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/SGX_Preference_Page.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Sample_Application.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Sample_Application.png new file mode 100644 index 0000000000..9c25b62823 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Sample_Application.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Select_Configuration_File.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Select_Configuration_File.png new file mode 100644 index 0000000000..a5fb4f811b Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Select_Configuration_File.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/The_Location_of_the_Plugin_zip_Archive.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/The_Location_of_the_Plugin_zip_Archive.png new file mode 100644 index 0000000000..afa17c33eb Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/The_Location_of_the_Plugin_zip_Archive.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/The_Result_of_Running_Samples_Generated_for_Enclaves.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/The_Result_of_Running_Samples_Generated_for_Enclaves.png new file mode 100644 index 0000000000..2f3a03acc5 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/The_Result_of_Running_Samples_Generated_for_Enclaves.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Two_StepSigne_Enclave_Generate_Hash.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Two_StepSigne_Enclave_Generate_Hash.png new file mode 100644 index 0000000000..7b9b49b640 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Two_StepSigne_Enclave_Generate_Hash.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Two_Step_Sign_Enclave_Menu.png b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Two_Step_Sign_Enclave_Menu.png new file mode 100644 index 0000000000..374fd094fd Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Images/Two_Step_Sign_Enclave_Menu.png differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Stylesheets/intel_css_styles.css b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Stylesheets/intel_css_styles.css new file mode 100644 index 0000000000..859063f2e1 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/Stylesheets/intel_css_styles.css @@ -0,0 +1,470 @@ +/*************************************************************************/ +/* Copyright (c) 2016 Intel Corporation. */ +/* */ +/* All rights reserved. This program and the accompanying materials */ +/* are made available under the terms of the Eclipse Public License v1.0 */ +/* which accompanies this distribution, and is available at */ +/* http://www.eclipse.org/legal/epl-v10.html */ +/* */ +/* Contributors: */ +/* Intel Corporation - initial implementation and documentation */ +/*************************************************************************/ +/**/ + +/*begin-old-version{{*/ + +body +{ + color: #333333; + background-color: #ffffff; + font-family: "Intel Clear", Verdana, Arial, sans-serif; + margin-left: 30px; + margin-right: 30px; + margin-bottom: 7%; + color: #333333; + background-color: #ffffff; + font-family: "Intel Clear", Verdana, Arial, sans-serif; + margin-left: 30px; + margin-right: 30px; + margin-bottom: 7%; + font-size: 12pt; +} + +.RevUpdate +{ + background-color: #FFFF99; + font-weight: normal; + line-height: 100%; + background-color: #FFFF99; + font-weight: normal; + line-height: 100%; +} + +.NonStdFortran +{ + color: #007F00; + color: #007F00; +} + +body.OH_VSIP_body +{ + margin-left: 30px; + margin-left: 30px; +} + +DIV.OH_outerContent +{ + border: 0px none #FFFFFF; + border: 0px none #ffffff; +} + +h1 +{ + color: #0071c5; + font-size: 15pt; + font-weight: normal; + padding-bottom: 1px; + margin-left: 0pt; + margin-bottom: 0px; + color: #0071c5; + font-size: 15pt; + font-weight: normal; + padding-bottom: 1px; + margin-left: 0pt; + margin-bottom: 0px; +} + +h1.firsttitle +{ + font-weight: normal; + border-bottom: 0 none; + margin-left: 0; + font-size: 18pt; + border-bottom: 1px solid #0071c5; + line-height: 100%; + padding-bottom: 10px; + margin-bottom: 20px; + margin-top: 20px; + font-weight: normal; + border-bottom: 0 none; + margin-left: 0; + font-size: 18pt; + border-bottom: 1px solid #0071c5; + line-height: 100%; + padding-bottom: 10px; + margin-bottom: 20px; + margin-top: 20px; +} + +h2 +{ + color: #0071c5; + margin-top: 15pt; + margin-bottom: 5pt; + font-size: 12pt; + color: #0071c5; + margin-top: 15pt; + margin-bottom: 5pt; + font-size: 12pt; +} + +h3 +{ + color: #333333; + font-weight: bold; + margin-top: 15pt; + margin-bottom: 5pt; + font-size: 11pt; + color: #333333; + font-weight: bold; + margin-top: 15pt; + margin-bottom: 5pt; + font-size: 11pt; +} + +h4 +{ + color: #0071c5; + margin-top: 10pt; + margin-bottom: 5pt; + padding-left: 0px; + font-size: 10pt; + color: #0071c5; + margin-top: 10pt; + margin-bottom: 5pt; + padding-left: 0px; + font-size: 10pt; +} + +h5 +{ + color: #0071c5; + margin-top: 10pt; + margin-bottom: 5pt; + padding-left: 0px; + font-size: 10pt; + color: #0071c5; + margin-top: 10pt; + margin-bottom: 5pt; + padding-left: 0px; + font-size: 10pt; +} + +h6 +{ + color: #0071c5; + margin-top: 10pt; + margin-bottom: 5pt; + padding-left: 0px; + font-size: 10pt; + color: #0071c5; + margin-top: 10pt; + margin-bottom: 5pt; + padding-left: 0px; + font-size: 10pt; +} + +.relinfo +{ + padding-left: 30px; + padding-left: 30px; +} + +.tablecap +{ + color: #0071c5; +} + +caption +{ + font-weight: bold; + text-align: left; + font-weight: bold; + text-align: left; + font-size: 12pt; +} + +.figcap +{ + margin-left: 24px; + font-size: 10pt; + font-weight: bold; + text-align: center; + margin-left: 24px; + font-size: 10pt; + font-weight: bold; + text-align: center; +} + +.sectiontitle +{ + padding-left: 0px; + padding-left: 0px; +} + +.linklist +{ + padding-left: 0px; + padding-left: 0px; +} + +h1.topictitle1 +{ + color: #0071c5; + font-size: 18pt; + margin-left: 0pt; + margin-bottom: 15px; + color: #0071c5; + font-size: 18pt; + margin-left: 0pt; + margin-bottom: 15px; +} + +#header_text +{ + color: #0071C5; + text-align: right; + color: #0071C5; + text-align: right; +} + +.titlepage +{ + margin-right: 15%; + margin-right: 15%; +} + +.familylinks +{ + margin-top: 1em; + margin-top: 1em; +} + +a.start +{ + font-size: 18pt; + text-decoration: underline; + font-size: 18pt; + text-decoration: underline; +} + +a.underlined +{ + text-decoration: underline; + text-decoration: underline; +} + +.shortdesc +{ + font-size: inherit; + padding-left: inherit; + line-height: 16pt; + margin-top: 0px; + margin-bottom: 0.5em; + font-size: inherit; + padding-left: inherit; + line-height: 16pt; + margin-top: 0px; + margin-bottom: 0.5em; +} + +.shortdesc-it +{ + font-style: italic; + font-style: italic; +} + +p +{ + margin-left: 0px; + line-height: 120%; + margin-top: 0; + margin-bottom: 10px; + margin-left: 0px; + line-height: 120%; + margin-top: 0; + margin-bottom: 10px; + font-size: 12pt; +} + +.p +{ + font-size: inherit; + margin-left: 0px; + line-height: 170%; + margin-top: 0; + margin-bottom: 5pt; + padding-left: 0pt; + font-size: inherit; + margin-left: 0px; + line-height: 170%; + margin-top: 0; + margin-bottom: 5pt; + padding-left: 0pt; +} + +table +{ + margin-bottom: 5pt; + border-collapse: collapse; + margin-left: 0px; + margin-top: 0.3em; + font-size: 10pt; + margin-bottom: 5pt; + border-collapse: collapse; + margin-left: 0px; + margin-top: 0.3em; + font-size: 10pt; +} + +tr +{ + vertical-align: top; + vertical-align: top; +} + +DIV.Note +{ + margin-top: 20pt; + margin-bottom: 20pt; + margin-right: 0.46cm; + padding-left: 5px; + border-top-style: solid; + border-top-width: 1px; + border-bottom-style: solid; + border-bottom-width: 1px; + font-size: 10pt; +} + +p.NoteTipHead +{ + font-weight: bold; + font-style: italic; + margin-top: 9pt; + margin-bottom: 3pt; + line-height: 15pt; + margin-left: 0.202cm; + font-family: "Verdana", "sans-serif"; + text-transform: uppercase; + text-align: justify; + font-size: 12pt; +} + +MadCap|xref +{ + color: #0860a8; + mc-format: '{paratext}'; + text-decoration: none; + font-size: 12pt; +} + +div.NoteCont +{ + border-bottom-style: solid; + border-bottom-width: 1px; + border-top-style: solid; + border-top-width: 1px; + font-size: 10pt; +} + +p.figcap +{ + text-align: left; + font-size: 12pt; +} + +th +{ + text-align: left; + font-size: 12pt; +} + +ul +{ + font-size: 12pt; +} + +ol +{ + font-size: 12pt; +} + +li +{ + font-size: 12pt; +} + +b +{ + font-size: 12pt; +} + +code +{ + font-size: 12pt; +} + +a:link +{ + color: #0071c5; + text-decoration: none; + color: #0071c5; + text-decoration: none; +} + +a:visited +{ + color: #0071c5; + text-decoration: none; + color: #0071c5; + text-decoration: none; +} + +a:hover +{ + color: #00aeef; + text-decoration: underline; + color: #00aeef; + text-decoration: underline; +} + +a:active +{ + color: #0071c5; + text-decoration: underline; + color: #0071c5; + text-decoration: underline; +} + +a.start:visited +{ + color: #0071c5; + text-decoration: underline; + color: #0071c5; + text-decoration: underline; +} + +a.start:active +{ + color: #0071c5; + text-decoration: underline; + color: #0071c5; + text-decoration: underline; +} + +a.underlined:visited +{ + color: #0071c5; + text-decoration: underline; + color: #0071c5; + text-decoration: underline; +} + +a.underlined:active +{ + color: #0071c5; + text-decoration: underline; + color: #0071c5; + text-decoration: underline; +} + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/content.html b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/content.html new file mode 100644 index 0000000000..c934419af6 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/content.html @@ -0,0 +1,557 @@ + + + + + + + + + +
+

Introduction

+

This Developer Guide is intended for use by Independent Service Vendors who wish to harden their Linux* applications using Intel(R) SGX Technology, code named Intel(R) Software Guard Extensions. The guide describes the procedure for installation of Intel(R) SGX Plugin for Eclipse* IDE and development of Intel(R) SGX components using the plugin. The Intel(R) SGX Plugin for Eclipse leverages on the Intel(R) Software Guard Extensions SDK, which is a collection of APIs, libraries and tools that enable you to develop, build and debug Intel(R) SGX applications in C/C++.

+

To learn more about the Intel(R) Software Guard Extensions SDK, see the Intel(R) Software Guard Extensions SDK for Linux* OS Developer Reference.

 
+
+

Introducing Intel(R) Software Guard Extensions

+

Intel(R) Software Guard Extensions is a new Intel technology, whose objective is to enable a high level of protection of secrets. It operates by allocating hardware-protected memory where code and data reside. The protected memory area within an application process is called an enclave. Data within the enclave memory can only be accessed by code that resides within that enclave. Enclave code can be invoked by special instructions.

+

An enclave can be built and loaded as a shared object.

+

Throughout this document, Intel(R) SGX refers to Intel(R) Software Guard Extensions.

+

An Intel(R) SGX application design is different from the design of non- Intel(R) SGX application as it specifies dividing the application into two logical parts:

+
    +
  • Trusted part. The code that accesses the secret resides here and it is called an enclave. More than one enclave can exist in an application.
  • +
  • Untrusted part. This includes the rest of the modules in the application, that is outside in an enclave.
  • +
+

The trusted components and untrusted components are developed as separate modules.

+

The trusted part or the enclave is implemented in C or C++. It is supplied as a collection of functions and data packaged in the form of a dynamically loaded library, a DLL in Windows* OS and a shared object in Linux* OS. It may be supplied either as a pre-built signed library or as a signed shared library built during compilation of the untrusted component.

+

Enclave functions within an enclave library are wrapped by auto-generated proxy and bridge functions that simplify the mechanism of using the Intel(R) SGX technology by developers.

+

The role of these functions is to handle the following tasks:

+
    +
  • Call an enclave function from untrusted code, also called an ECALL (enclave call).
  • +
  • Call an untrusted function from within an enclave, also called an OCALL (outside call).
  • +
  • Handle interrupts.
  • +
  • Handle exceptions.
  • +
+

The proxy and bridge functions are generated by the sgx_edger8r tool provided by Intel(R) SGX SDK. It reads an edl file (Enclave Descriptor Language) which describes the functions that form the trusted and untrusted component boundaries within the application.

+

After the enclave is built, a signed version of it is created using the tool sgx_sign also provided by Intel(R) SGX SDK. It is this signed version may be loaded and executed in the encrypted memory.

+

Enclaves may have some specific properties which are added as meta-information during the signing process. The meta-information is stored in one configuration xml file per enclave. See more details about meta-information in Intel(R) Software Guard Extensions SDK for Linux* OS Developer Reference.

+
+
+

Introducing Intel(R) Software Guard Extensions Eclipse* Plug-in

+

The Intel(R) Software Guard Extensions Eclipse* Plug-in helps the enclave developer to maintain enclaves and untrusted related code inside Eclipse* C/C++ projects. To use this support, add SGX nature to the C/C++ project. See Adding SGX Nature to a Project for details.

+

Once the SGX nature is added to a project, you will have access to the SGX commands. SGX nature adds also a folder called sgx to the root of the project, and a Makefile inside it. All resources of the project managed by Intel(R) Software Guard Extensions Eclipse Plug-inare located inside this directory. You can build and run enclaves related code using GNU* Make tool through the Makefile.

+

The plugin is generating minimal but ready-to-work code skeletons, complete with their own Makefile having all the required make targets as to call sgx_edger8r tool to generate the proxies and bridges, compile these source, generate a shared object and finally, to sign the enclave with the sgx_sign tool. This provide a starting point you may build upon.

+
+
+

Getting Started with Intel(R) Software Guard Extensions Eclipse* Plug-in

+

This section contains steps to set up your Intel(R) Software Guard Extensions Eclipse* Plug-in on a Linux* system, including necessary softwares, steps to install the product, and steps to configure your preferred product directory.

+

• Pre-requisites

+

• Installing Intel(R) Software Guard Extensions Eclipse* Plug-in

+

• Configuring Intel(R) Software Guard Extensions Eclipse* Plug-in

 
+
+

Pre-requisites

+

To use Intel(R) Software Guard Extensions Eclipse Plug-in, install the following softwares:

+
    +
  • Eclipse* Mars 1 with CDT IDE for C/C++ Developpers (version 4.5.1). To use this version, install Java* Development Kit (JDK) or Java* Runtime Environment (JRE) version 1.8 or above.
  • +
  • gcc/g++ tools
  • +
  • Openssl*
  • +
  • Intel(R) SGX SDK for Linux* OS
  • +
+
+
+

Installing Intel(R) Software Guard Extensions Eclipse* Plug-in

+

Install Intel(R) Software Guard Extensions Eclipse* Plug-in as a regular Eclipse Plugin:

+
    +
  1. Download the zip archive of Intel(R) Software Guard Extensions Eclipse Plug-in from Intel Site
  2. +
  3. +

    Go to Help menu -> Install New Software. Click the Add button for the Work with field to open the Add Repository dialog as shown in the following graphic:

    +

    + +

    +

    Add Repository Dialog

    +
  4. +
  5. +

    Enter SGX Archive in the Name field . Click the Archive... button and select the location of the downloaded archive as shown in the following graphic:

    +

    + +

    +

    The Location of the Plugin zip Archive

    +
  6. +
  7. Press OK to add the archive as a repository.
  8. +
  9. In the Install dialog, select the Software Guard Extensions Plugin check-box and proceed with the usual steps.
  10. +
+
+
+

Configuring Intel(R) Software Guard Extensions Eclipse* Plug-in

+

If you do not install Intel(R) SGX SDK for Linux* OS in the default location, you need to specify the path for Intel SGX SDK using the following steps:

+
    +
  1. +

    Go to Window menu ->Preferences. Enter SGX in the filter text field to quickly locate the SGX Preferences page.

    +

    + +

    +

    SGX Preference Page

    +
  2. +
  3. Enter the path for Intel SGX SDK for Linux OS in the SGX SDK Directory field.
  4. +
+
+
+

Command Reference

+

This topic provides the command reference for the following scenarios of using Intel(R) Software Guard Extensions Eclipse* Plug-in:

+
    +
  • Adding SGX nature to a project
  • +
  • Adding an SGX enclave
  • +
  • Adding an SGX trusted library
  • +
  • Adding an SGX untrusted module
  • +
  • Updating SGX enclave signing key
  • +
  • Updating enclave configuration files
  • +
  • Two steps sign enclave
  • +
+

All commands brought by Intel(R) Software Guard Extensions Eclipse Plug-in are available by right-clicking on the Project root in Project explorer view in menu Software Guard Extension Tools:

 

Project Explorer

 
+
+

Adding SGX Nature to a Project

+

The nature of an Eclipse project is a concept defined by an Eclipse Platform which allows a plug-in to tag a project as a specific kind of project. Intel(R) Software Guard Extensions uses an SGX nature to add SGX-specific behavior to projects. Project natures are defined by plug-ins, and are typically added or removed per-project when the user performs some action defined by the plug-in.

+

To use Intel(R) Software Guard Extensions Eclipse Plug-in in your project, you need to add SGX nature to it. You may either add SGX nature to a pre-existing C/C++ project or create a project with SGX nature from start. See Adding SGX Nature to a non-SGX project and Creating a New C/C++ Project with SGX Nature for how to complete these tasks.

+
+
+

Adding SGX Nature to a non-SGX project

+

When you have a C/C++ project created without Intel SGX, you cannot use Intel SGX support. In this case, you need to add SGX nature to this project to use Intel SGX support:

+
    +
  1. Right-click on the project root
  2. +
  3. +

    Select Software Guard Extension Tools → Add SGX Nature

    +

    + +

    +

    Add SGX Nature

    +
  4. +
+

After you add the SGX nature to your project, you should see:

+
    +
  • +

    A subdirectory sgx in the project which contains a Makefile file.

    +

    + +

    +

    Makefile for Intel(R) SGX

    +
  • +
  • +

    The Intel SGX tools as shown in the following graphic:

    +

    + +

    +

    Intel(R) SGX Tools

    +
  • +
  • +

    New configurations specific to SGX technology. You may see the configurations for the project by clicking to the down arrow of button usually found at the top of the Eclipse window:

    +

    + +

    +

    Configurations Specific to Intel(R) SGX Technology

    +
  • +
+
+
+

Creating a New C/C++ Project with SGX Nature

+

You can create a new project with SGX nature. To create such a project, follow these steps:

+
    +
  1. +

    Open a standard Eclipse new project: File menu → Project... . If you have installed Intel® Software Guard Extensions Eclipse Plug-in, you can see the category C/C++ with SGX Enabled in the New Project dialog.

    +

    + +

    +

    New Project

    +

    This category has 2 sub-categories, SGX C project and SGX C++ project. These sub-categories are similar to the sub-categories C Project and C++ Project of standard C/C++ category.

    +
  2. +
  3. Select one of the 2 sub-categories, SGX C project or SGX C++ project, and click Next.
  4. +
  5. Complete creating the project using the regular process of creating a standard C or C++ project.
  6. +
+
+

NOTE:

+

Projects created following the subcategories under C/C++ with SGX Enabled are identical with their standard counterparts, except that they have SGX Nature added. There is no difference between creating a C or C++ project with SGX enabled, or creating a standard C/C++ project and launch Add SGX nature from it, as described in precedent paragraph.

+
+
+
+

Adding an SGX Enclave

+

After you add the SGX nature to a project, you can start creating a minimal but complete skeleton for a new enclave:

+
    +
  1. Right-click on the project root in Project Explorer.
  2. +
  3. +

    Open the dialog Add New SGX Enclave by selecting Software Guard Extensions Tools → Add SGX Enclave from the contextual menu.

    +

    + +

    +

    Add New Intel® SGX Enclave Dialog

    +
  4. +
  5. +

    Choose a name for the enclave in Enclave name field. This name is used in the process of generation of the skeleton to give unicity to the source files and the name of the resulting executable, so you can add more than one enclave to the same project.

    +
      +
    • +

      If you do not select the Generate sample untrusted application checkbox, the plugin generates only a trusted file and a Makefile fragment to build and compile the trusted part. See the following graphic. All the code for the enclave, including build Makefile, is put in a directory <root>/sgx/enclave_<name> . C/C++ code for the enclave proper are in <root>/sgx/enclave_<name>/trusted.

      +

      + +

      +

      Generated Skeleton for an Enclave. The option to Generate Sample was not Used

      +
    • +
    • +

      If you select Generate sample untrusted application checkbox, a simple ready to work sample application is generated, including untrusted stubs and implementation for a sample OCALL and ECALL.

      +

      + +

      +

      Generated Sample Untrusted Application

      +
    • +
    +
  6. +
+
+

NOTE:

+

If you select the Generate sample untrusted application checkbox, ecalls from the untrusted part are not be resolved by Eclipse C/C++ indexer. These functions are marked with a red line. The declaration of these ecalls resides in the unstrusted stub header which is generated during the build proces and is not indexed by Eclipse. To resolve this problem, right-click on project root and select Index → Freshen All Files.

+
+
+
+

Adding an SGX Trusted Library

+

Trusted Static Libraries helps enclave author have libraries of shared code to be reused by enclaves, in exactly the same manner as usual static libxxx.a libraries are used to share code between regular non-SGX applications. The plugin adds a command to generate the skeleton of a trusted shared library.

+

To add a new SGX Trusted Library:

+
    +
  1. +

    Open Add New SGX Static Trusted Library dialog by right-click on the root of the project and select the appropriate command from Software Guard Extensions Tools menu:

    +

    + +

    +

    Add New SGX Static Trusted Library Dialog

    +
  2. +
  3. +

    Choose a name for the library and click OK. A skeleton for a trusted library is generated in directory <root>/sgx/trustedlib_<name>:

    +

    + +

    +

    A Generated Trusted Library

    +
  4. +
+
+
+

Adding an SGX Untrusted Module

+

Add an untrusted module to generate the untrusted stubs so you use an enclave, provided you have access to its .edl file. The enclave might have been built in the current project or in a different project.

+

To use trusted functionality of an enclave for which its *.edl is known, use the command Add SGX Untrusted Module:

+
    +
  1. +

    Open dialog Add Sgx Untrusted Module by right-click-ing the project root in Package Explorer and chose the command from Software Guard Extension Tools.

    +

    + +

    +

    Add SGX Untrusted Module

    +
  2. +
  3. +

    Use the Browse button to navigate the file system using a file dialog, and click OK. The untrusted module is copied to <root>/sgx/untrusted_<edl file name>. The selected *.edl is copied to the project.

    +

    + +

    +

    Copying the Untrusted Module to a Project

    +
  4. +
+
+
+

Updating SGX Enclave Signing Key

+

All skeletons enclave samples produced by the plugin contain a sample signing key. You might want to import another sign key that you already have, or generate a new one. Use the command Update SGX Enclave Signing Key to complete this task.

+
    +
  1. Choose Update SGX Enclave Signing Key by right-click on the project in Project Explorer -> Software Guard Extension Tools menu. The Import or (Re)Generate Enclave Signing Key dialog appears.
  2. +
  3. In the Import or (Re)Generate Enclave Signing Key dialog, click Select to open a file dialog to select the output key.
  4. +
  5. +

    Click Improt Key to update a selected signing key by copying another existing key or click Generate Key to update the selected signing key by generating a new key. In both cases, the new signature key is put into the file in text field Enclave Signing Key.

    +

    + +

    +

    Import or (Re)Generate Enclave Signing Key

    +
  6. +
  7. Click OK to update the enclave signing key.
  8. +
+

Under the hood, a new key is generated using openssl*, which needs to be installed on the machine:

+

openssl genrsa -out ../../../encl1_private.pem.key.pem -3 3072 +

+

+
+
+

Updating Enclave Configuration Files

+

A configuration file is an important part in the definition of an enclave. Intel(R) SGX SDK signer tool requires such *.xml configuration file as necessary input.

+

To update this configuration file, use the Update Config command:

+
    +
  1. +

    Right-click on the root project, Software Extension Guards Tools->Select Config File.

    +

    + +

    +

    Select Configuration File

    +
  2. +
  3. +

    Click OK or double-click the selected configuration file to open the Enclave Configuration Settings dialog.

    +

    + +

    +

    Enclave Configuration Settings

    +

    For details on the meaning of the fields, see Intel(R) Software Guard Extensions Developer Guide.

    +
  4. +
+
+
+

Two Steps Sign Enclave

+

To help you develop enclaves, Intel(R) Software Guard Extensions Eclipse Plug-in generates all required structure including:

+
    +
  • c/c++ files and header files
  • +
  • .edl file
  • +
  • *.config.xml file
  • +
  • a sample Makefile
  • +
  • a sample signing key
  • +
+

While these structure might be appropriate for development and debugging, you need a 2-step process to integrate your own signing schema for generating production enclaves.

+
    +
  1. Generate hash: the signer tool generates signing material from the unsigned compiled enclave and from the configuration file for the enclave. The signed material comes as an opaque sequence of bytes which are put in a file with extension .hex. This file is used with the external signing facility. You come back with a signature for the .hex file plus the public key of your signing facility, and proceed to Step 2.
  2. +
  3. Generate signed enclaves : the signer tool generates the final signed enclave.
  4. +
+

To complete this task, provide the following input parameters:

+
    +
  • The unsigned enclave
  • +
  • The configuration file
  • +
  • The output file produced when you generate hash (the .hex file)
  • +
  • The files produced by the external signing facility: the signature of the .hex file and public key for it
  • +
  • The plugin checks if the input parameters are consistent:
  • +
  • The .hex file matches the unsigned enclave and the configuration file,
  • +
  • The signed material is verified with the public key
  • +
+

If the parameters are consistenet, the production signed enclave is produced.

+
+

NOTE:

+

If you generate signed enclave right after generating hash, you can only enter the parameters specific for generating signed enclave.

+
+

To use the two-step signing function, activate the configuration SGX Hardware Release mode. When this configuration is active, the compilation does not produce a signed enclave, as in the other SGX configurations; the process only produces unsigned enclaves.

+

+ +

+

Configure SGX Hardware Release Mode

+

When you configure the plugin in the SGX Hardware Release Mode, you can see the Generate Hash and Generate Signed Enclave options through Software Guard Extension Tools->Two Step Sign Enclave.

+

+ +

+

Two Step Sign Enclave Menu

+
+
+

Generate Hash

+

Generating hash is the first step in the 2-Steps signing process.To generate hash, use the following steps:

+
    +
  1. +

    Right-click on project root, go to Software Guard Extensions Tools menu → Two StepSigne Enclave → Generate Hash

    +

    + +

    +

    Two StepSigne Enclave - Generate Hash

    +
  2. +
  3. In the Generate Hash dialog, enter the required inputs to the corresponding fields:
    • Enter the path to the compiled enclave to be signed in the Enclave Path field. Click Select Enclave to open a file dialog to select the enclave.
    • In the Hash File Location field , enter the path of the output file that will contain signing materials. By default this file has the same file name as the unsigned enclave, with .hex extension added. To change the path, click Select File Path to open a file dialog to select the file path.
    • In the Configuration File path field, enter the path of the configuration filefor the generated hash. Click Select Config to open a dialog to select from all enclave configuration files in the project (similar with the one of the command Update Config).
  4. +
  5. +

    Click OK after you fill in all the fields. The Intel(R) SGX SDK is launched under the hood with the provided parameters and the hash file is generated. A dialog box appears to confirm the completion:

    +

    + +

    +

    Generating Hash Completion Dialog

    +
  6. +
+

You complete the first step, generating hash, in the two step signing enclave. The *.hex file may be signed with the external facility, which generates a signature for it and a public verification key.

+

If you click OK, the Generate Signed Enclave dialog appears. The required fileds in this dialog have been pre-configured with the paths of the unsigned enclave, the configuration file and of the *.hex file. To generated the final signed enclave ready for production immediately, click OK.

+

+ +

+

Generate Signed Enclave Dialog with Pre-configurations

+

If you click Cancel in the Generate Signed Enclave dialog, you can continue the signing process later using the Generate Signed Enclave command.

+
+
+

Generate Signed Enclaves

+

Generating signed enclave is the second step in the 2-Steps signing process. You should have the following files to complete this step:

+
    +
  • The .hex file generated with Generate Hash command
  • +
  • The files produced from the external signing facility
  • +
  • The signature of the .hex file
  • +
  • The public verification key
  • +
+

To generate signed encalves, use the following steps:

+
    +
  1. +

    Right-click on the project root, and go to Software Guard Extensions Tools menu → Two Step Sign Enclave → Generate Signed Enclave.

    +

    + +

    +

    Generate Signed Enclave Dialog

    +
  2. +
  3. Enter the inputs to all the fields and click OK.
  4. +
+
+
+

Building and Running SGX Code

+

This section describes the following topics about building and running SGX code:

+
    +
  • SGX build configurations
  • +
  • Running samples generated for enclaves
  • +
 
+
+

SGX Build Configurations

+

There are usually two types of builds that a regular non-SGX project defines:

+
    +
  • Debug
  • +
  • Release
  • +
+

SGX-enabled projects add to this picture support to build and test SGX-enabled application on non-SGX platforms (or emulator) using simulation libraries. This approach doubles the set of build types, creating four possible combinations. For these combinations, you need to use different sets of compilation and linking flags and link different libraries.

+

The non-debug hardware build is meant to give production code, so it requires the maximum attention when signed. The Two Steps Sign schema is required for production enclaves, which involves an external signing facility, not part of Intel SGX SDK. The other configurations are not meant for production but they have to be signed too. The simplest and more convenient Single Step schema is used for them.

+

Again for testing purpose, you might want to experiment with a non-production enclave built with release compilation and linking flags, on a real hardware SGX-enabled platform. That would be an enclave built exactly as a production enclave, except for the sign process which would be Single Step. To support the construction of such enclave, there is a hardware non-debug build configuration dubbed Prerelease.

+

So there are five SGX related configurations when SGX Nature is added to a project:

+

+ +

+

Intel(R) SGX Configurations

+

The following table resumes the existing SGX configurations and relate them with compilation/linking flags (debug/non-debug) and signing scheme (single vs. two steps):

+

Intel(R) SGX Configurations

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Configuration NameSimulation?Debug?Signing Schema
SGX Hardware DebugHardwareDebugSingle Step
SGX Hardware Pre-releaseHardwareNon-debugSingle Step
SGX Hardware ReleaseHardwareNon-debugTwo Step
SGX SimulationSimulationNon-debugSingle Step
SGX SimulationDebug SimulationDebugSingle step
+

Intel® Software Guard Extensions Eclipse Plug-in uses standard GNU* make tool to build the trusted and the untrusted code, using the generated file sgx/Makefile.

+

This fact does not impose any restriction on the build tool chosen for the hosting project. Intel® Software Guard Extensions Eclipse* Plug-in uses its own build configurations which do not interfere with the configurations that you might have in your project.

+

When SGX configurations are selected, by default only code under <root>/sgx directory get built.

+

You can customize SGX configurations as any other Eclipse build configurations from the project properties dialog. For example:

+
    +
  1. Right-click in Project Explorer Properties → C/C++ Build
  2. +
  3. Uncheck the Use default build command checkbox.
  4. +
+

Then you can customize and integrate SGX build process. You can use Makefile instead of sgx/Makefile in the example shown in the following figure:

+

+ +

+

Customization of SGX Build Command

+

The build process is done using standard Eclipse interface for build, by example from the main Project menu:

+

+ +

+

Project Menu

+
+
+

Running Samples Generated for Enclaves

+

Intel(R) Software Guard Extensions Eclipse* Plugin provides an option to generate a sample application together with the enclave code when the enclave is created. After the project is build, the sample application is built also and ready to run. You can see the sample application named sample in the enclave directory in Project Explorer. You can run this sample as a local C/C++ application as shown in the following figure:

+

+ +

+

Sample Application

+

See the result of the execution in Eclipse console window as shown below:

+

+ +

+

The Result of Running Samples Generated for Enclaves

+
+ + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/plugin.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/plugin.xml new file mode 100644 index 0000000000..533d28bf13 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/plugin.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/src/com/intel/sgx/userguide/Activator.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/src/com/intel/sgx/userguide/Activator.java new file mode 100644 index 0000000000..f10dec9896 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/src/com/intel/sgx/userguide/Activator.java @@ -0,0 +1,73 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + +package com.intel.sgx.userguide; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "com.intel.sgx.userguide"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/toc.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/toc.xml new file mode 100644 index 0000000000..9a31c4b5b2 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/toc.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.classpath b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.classpath new file mode 100644 index 0000000000..6c009435ce --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.classpath @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.project b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.project new file mode 100644 index 0000000000..aec7e39589 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.project @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + com.intel.sgx + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.settings/org.eclipse.jdt.core.prefs b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..a698e59674 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/META-INF/MANIFEST.MF b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..f06f84d713 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/META-INF/MANIFEST.MF @@ -0,0 +1,26 @@ +License: Eclipse Public License Version 1.0 ("EPL") +bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: com.intel.sgx;singleton:=true +Bundle-Version: 1.0.1.qualifier +Bundle-Activator: com.intel.sgx.Activator +Bundle-Vendor: %Bundle-Vendor +Require-Bundle: org.eclipse.cdt.core;bundle-version="5.11.0", + org.eclipse.core.runtime;bundle-version="3.11.1", + org.eclipse.ui;bundle-version="3.107.0", + org.eclipse.cdt.managedbuilder.ui;bundle-version="8.2.2", + org.eclipse.cdt.managedbuilder.core;bundle-version="8.3.0", + org.eclipse.core.resources;bundle-version="3.10.1", + org.eclipse.cdt.ui;bundle-version="5.11.0", + org.eclipse.core.expressions;bundle-version="3.5.0", + org.eclipse.ui.ide;bundle-version="3.11.0" +Bundle-ActivationPolicy: lazy +Export-Package: com.intel.sgx, + com.intel.sgx.build, + com.intel.sgx.dialogs, + com.intel.sgx.discovery, + com.intel.sgx.handlers, + com.intel.sgx.natures, + com.intel.sgx.preferences, + com.intel.sgx.templates +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/OSGI-INF/l10n/bundle.properties b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000000..171c78c844 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,15 @@ +######################################################################### +# Copyright (c) 2016 Intel Corporation. # +# # +# All rights reserved. This program and the accompanying materials # +# are made available under the terms of the Eclipse Public License v1.0 # +# which accompanies this distribution, and is available at # +# http://www.eclipse.org/legal/epl-v10.html # +# # +# Contributors: # +# Intel Corporation - initial implementation and documentation # +######################################################################### + + +Bundle-Vendor = Intel Corporation +Bundle-Name = SGX(R) Linux Eclipse Plugin \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/build.properties b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/build.properties new file mode 100644 index 0000000000..d055ac2fdc --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/build.properties @@ -0,0 +1,24 @@ +######################################################################### +# Copyright (c) 2016 Intel Corporation. # +# # +# All rights reserved. This program and the accompanying materials # +# are made available under the terms of the Eclipse Public License v1.0 # +# which accompanies this distribution, and is available at # +# http://www.eclipse.org/legal/epl-v10.html # +# # +# Contributors: # +# Intel Corporation - initial implementation and documentation # +######################################################################### + + +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + templates/,\ + discovery/,\ + build.properties,\ + OSGI-INF/,\ + OSGI-INF/l10n/bundle.properties +jre.compilation.profile = JavaSE-1.8 diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/discovery/test.c b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/discovery/test.c new file mode 100644 index 0000000000..139597f9cb --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/discovery/test.c @@ -0,0 +1,2 @@ + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/discovery/test.cpp b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/discovery/test.cpp new file mode 100644 index 0000000000..139597f9cb --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/discovery/test.cpp @@ -0,0 +1,2 @@ + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/plugin.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/plugin.xml new file mode 100644 index 0000000000..86a2ba5d05 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/plugin.xml @@ -0,0 +1,786 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + An C project, with SGX Commands and Configurations + + + + + + An C++ project, with SGX Commands and Configurations + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/Activator.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/Activator.java new file mode 100644 index 0000000000..580330b423 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/Activator.java @@ -0,0 +1,75 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + +package com.intel.sgx; + +import java.net.URL; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + public static final String PLUGIN_ID = "com.intel.sgx";//$NON-NLS-1$ + + private static Activator plugin; + + public Activator() { + } + + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + public static Activator getDefault() { + return plugin; + } + + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } + + public static void log(Exception e) { + plugin.getLog().log(newStatus(e)); + } + + public static IStatus newStatus(Exception e) { + return new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e); + } + + public static URL findFile(Path path) { + return FileLocator.find(plugin.getBundle(), path, null); + } + + public static Bundle getBundle(String id){ + for(Bundle bundle : plugin.getBundle().getBundleContext().getBundles()){ + if(bundle.getSymbolicName().equals(id)) + return bundle; + } + return null; + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/CConfigurationDataProvider2.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/CConfigurationDataProvider2.java new file mode 100644 index 0000000000..59cdc66e33 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/CConfigurationDataProvider2.java @@ -0,0 +1,46 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx; + +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; +import org.eclipse.cdt.core.settings.model.extension.CConfigurationDataProvider; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +public class CConfigurationDataProvider2 extends CConfigurationDataProvider { + + public CConfigurationDataProvider2() { + } + + @Override + public CConfigurationData loadConfiguration(ICConfigurationDescription des, + IProgressMonitor monitor) throws CoreException { + return null; + } + + @Override + public CConfigurationData createConfiguration( + ICConfigurationDescription des, + ICConfigurationDescription baseDescription, + CConfigurationData baseData, boolean clone, IProgressMonitor monitor) + throws CoreException { + return null; + } + + @Override + public void removeConfiguration(ICConfigurationDescription des, + CConfigurationData data, IProgressMonitor monitor) { + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/Messages.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/Messages.java new file mode 100644 index 0000000000..d4133b2962 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/Messages.java @@ -0,0 +1,37 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + + private static final String BUNDLE_NAME = "com.intel.sgx.messages";//$NON-NLS-1$ + + /* + * TODO - These Strings can be used all through the package to control what messages are displayed. + * Todo here is to identify any message that needs to be made configurable. + */ + public static String CreateNativeFolders_No_folders; + public static String CreateNativeFolders_Missing_project_name; + public static String CreateNativeFolders_Project_does_not_exist; + + static{ + //Bundle initialization. + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages(){ + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/SdkPathVariableProvider.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/SdkPathVariableProvider.java new file mode 100644 index 0000000000..43f13da5f9 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/SdkPathVariableProvider.java @@ -0,0 +1,70 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx; +import java.io.File; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.variableresolvers.PathVariableResolver; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.preference.IPreferenceStore; + +import com.intel.sgx.preferences.PreferenceConstants; +import com.intel.sgx.preferences.SGXPreferencePage; + +public class SdkPathVariableProvider extends PathVariableResolver { + + public SdkPathVariableProvider() { + super(); + } + + @Override + public String[] getVariableNames(String variable, IResource resource) { + String variableNames[] = {"SGX_SDK_DIR_PATH"}; + return (variableNames); + } + + @Override + public String getValue(String variable, IResource resource) { + if(variable.equals("SGX_SDK_DIR_PATH")) { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + String SDKPath = store.getString(PreferenceConstants.SDK_PATH); + IPath SDKCanonicalPath= new Path(SDKPath); + return(SDKCanonicalPath.append("Include").toOSString()); + } + return null; + } + + public static String getSGXSdkLocation() { + return Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.SDK_PATH); + } + + public static boolean isSGXSdkLocationValid() { + String location = getSGXSdkLocation(); + if (location.length() == 0) + return false; + + return isValidSGXSdkLocation(location); + } + + public static boolean isValidSGXSdkLocation(String location) { + File dir = new File(location); + if (!dir.isDirectory()) + return false; + + return new PreferenceConstants.SGXSDK64Descriptor(dir).getSignerPath().canExecute() + || new PreferenceConstants.SGXSDK32Descriptor(dir).getSignerPath().canExecute(); + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/build/SGXSDKCommandLauncher.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/build/SGXSDKCommandLauncher.java new file mode 100644 index 0000000000..c0eb394532 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/build/SGXSDKCommandLauncher.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +/** + * This class follows the same solution provided in the NDK_PLUGIN for NDKCommandLauncher. + */ +package com.intel.sgx.build; + +import org.eclipse.cdt.core.CommandLauncher; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; + +import com.intel.sgx.SdkPathVariableProvider; +/** + * This launches the sgx-ndk-build. + */ +public class SGXSDKCommandLauncher extends CommandLauncher { + + @Override + public Process execute(IPath commandPath, String[] args, String[] env, IPath changeToDirectory, + IProgressMonitor monitor) + throws CoreException { + + return super.execute(commandPath, args, env, changeToDirectory, monitor); + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddEnclaveFileDialog.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddEnclaveFileDialog.java new file mode 100644 index 0000000000..e663a1c390 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddEnclaveFileDialog.java @@ -0,0 +1,126 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.dialogs; + +import javax.swing.JOptionPane; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import com.intel.sgx.handlers.AddEnclave; + +public class AddEnclaveFileDialog extends SGXDialogBase { + + private Text fileNameField; + private AddEnclave addHandler; + private boolean generateApp = true; + + public AddEnclaveFileDialog(Shell shell, AddEnclave addHandler) { + super(shell); + this.addHandler = addHandler; + this.shell = shell; + // setShellStyle(SWT.RESIZE | SWT.TITLE); + } + + public boolean generateApp() + { + return generateApp; + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = new GridLayout(1,false); + composite.setLayout(gridLayout); + + final Group container = new Group(composite, SWT.NONE); + container.setLayout(new GridLayout(3,false)); + GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL); + innergrid1.horizontalSpan = 3; + container.setLayoutData(innergrid1); + + addLabel(container, "Enter the name of the Enclave. Make sure the name is unique within the hosting application."); + + final Label fileNameLabel = new Label(container, SWT.NONE); + fileNameLabel.setText("Enclave name:"); + fileNameLabel.setLayoutData(new GridData(GridData.BEGINNING,GridData.CENTER, false, false)); + + fileNameField = new Text(container,SWT.SINGLE | SWT.BORDER); + GridData textGridData1 = new GridData(GridData.FILL_HORIZONTAL); + textGridData1.minimumWidth = 400; + textGridData1.grabExcessHorizontalSpace = true; + fileNameField.setLayoutData(textGridData1); + + Button generateUntrustedApp = new Button(container, SWT.CHECK); + generateUntrustedApp.setText("Generate sample untrusted application?"); + generateUntrustedApp.setLayoutData(new GridData(GridData.BEGINNING, GridData.END, false, false, 3, 1)); + generateUntrustedApp.setSelection(true); + + generateUntrustedApp.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent event) { + Button btn = (Button) event.getSource(); + generateApp = btn.getSelection(); + } + }); + + container.layout(); + composite.layout(); + return composite; + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Add New SGX Enclave Dialog"); + newShell.layout(); + } + + @Override + protected + void okPressed() { + addHandler.edlFilename = fileNameField.getText(); + if(!fileNameField.getText().isEmpty() + ){ + if(Character.isDigit(fileNameField.getText().charAt(0))) + { + JOptionPane.showMessageDialog(null, "Enclave names starting with digits are not allowed.", "Error", + JOptionPane.ERROR_MESSAGE); + } + else + super.okPressed(); + } + } + + @Override + protected Point getInitialSize(){ + return new Point(675,200); + } + + public String getFileName() { + return fileNameField.getText(); + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddTrustedStaticLibFileDialog.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddTrustedStaticLibFileDialog.java new file mode 100644 index 0000000000..b353c716c8 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddTrustedStaticLibFileDialog.java @@ -0,0 +1,109 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.dialogs; + +import javax.swing.JOptionPane; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import com.intel.sgx.handlers.AddTrustedStaticLib; + +public class AddTrustedStaticLibFileDialog extends SGXDialogBase { + + private Text fileNameField; + private AddTrustedStaticLib addHandler; + private boolean generateApp = false; + + public AddTrustedStaticLibFileDialog(Shell shell, AddTrustedStaticLib addHandler) { + super(shell); + this.addHandler = addHandler; + this.shell = shell; + // setShellStyle(SWT.RESIZE | SWT.TITLE); + } + + public boolean generateApp() + { + return generateApp; + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = new GridLayout(1,false); + composite.setLayout(gridLayout); + + final Group container = new Group(composite, SWT.NONE); + container.setLayout(new GridLayout(3,false)); + GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL); + innergrid1.horizontalSpan = 3; + container.setLayoutData(innergrid1); + + addLabel(container, "Enter the name of the Static Trusted Library."); + addLabel(container, "Make sure the name is unique within the hosting application."); + + final Label fileNameLabel = new Label(container, SWT.NONE); + fileNameLabel.setText("Static Trusted Library Name:"); + fileNameLabel.setLayoutData(new GridData(GridData.BEGINNING,GridData.CENTER, false, false)); + + fileNameField = new Text(container,SWT.SINGLE | SWT.BORDER); + GridData textGridData1 = new GridData(GridData.FILL_HORIZONTAL); + textGridData1.minimumWidth = 400; + textGridData1.grabExcessHorizontalSpace = true; + fileNameField.setLayoutData(textGridData1); + + composite.layout(); + + return composite; + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Add New SGX Static Trusted Library Dialog"); + } + + @Override + protected + void okPressed(){ + addHandler.edlFilename = fileNameField.getText(); + if(!fileNameField.getText().isEmpty() + ){ + if(Character.isDigit(fileNameField.getText().charAt(0))) + { + JOptionPane.showMessageDialog(null, "Enclave names starting with digits are not allowed.", "Error", + JOptionPane.ERROR_MESSAGE); + } + else + super.okPressed(); + } + } + + @Override + protected Point getInitialSize(){ + return new Point(675,200); + } + + public String getFileName() { + return fileNameField.getText(); + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddUntrustedModuleDialog.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddUntrustedModuleDialog.java new file mode 100644 index 0000000000..15779d4651 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/AddUntrustedModuleDialog.java @@ -0,0 +1,138 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.dialogs; + +import java.io.File; + +import javax.swing.JOptionPane; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import com.intel.sgx.handlers.AddUntrustedModule; + +public class AddUntrustedModuleDialog extends Dialog { + + private Text fileNameField,makeFilePathField; + private Shell shell; + private AddUntrustedModule addHandler; + private boolean generateApp = false; + + public AddUntrustedModuleDialog(Shell shell, AddUntrustedModule addHandler) { + super(shell); + this.addHandler = addHandler; + this.shell = shell; + //setShellStyle(SWT.RESIZE | SWT.TITLE); + } + + public boolean generateApp() + { + return generateApp; + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = new GridLayout(1,false); + composite.setLayout(gridLayout); + + final Group container = new Group(composite, SWT.NONE); + container.setLayout(new GridLayout(3,false)); + GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL); + innergrid1.horizontalSpan = 3; + container.setLayoutData(innergrid1); + + final Label messageLabel = new Label(container, SWT.NONE); + messageLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1)); + messageLabel.setText("Enter the path to the Enclave Descriptor file (*.edl) of the enclave to host."); + + + final Label fileNameLabel = new Label(container, SWT.NONE); + fileNameLabel.setText("Filename:"); + fileNameLabel.setLayoutData(new GridData(GridData.BEGINNING,GridData.CENTER, false, false)); + + + fileNameField = new Text(container,SWT.SINGLE | SWT.BORDER); + GridData textGridData1 = new GridData(GridData.FILL_HORIZONTAL); + textGridData1.minimumWidth = 400; + textGridData1.grabExcessHorizontalSpace = true; + fileNameField.setLayoutData(textGridData1); + + final Button browseButton = new Button(container, SWT.PUSH); + browseButton.setText("Browse"); + GridData buttonGridData1 = new GridData(GridData.END); + buttonGridData1.horizontalAlignment = SWT.RIGHT; + buttonGridData1.horizontalSpan = 1; + buttonGridData1.minimumWidth = 120; + browseButton.setLayoutData(buttonGridData1); + browseButton.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { + String result = null; + shell = new Shell(); + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + dialog.setFilterExtensions(new String [] {"*.edl"}); + dialog.setFilterPath(""); + result = dialog.open(); + fileNameField.setText(result); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + return composite; + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Add SGX Untrusted Module."); + } + + @Override + protected + void okPressed(){ + addHandler.edlFilename = fileNameField.getText(); + if(!fileNameField.getText().isEmpty()) + if((new File(fileNameField.getText())).isFile()) + super.okPressed(); + else + JOptionPane.showMessageDialog(null, "EDL file does not exist.", "Error", + JOptionPane.ERROR_MESSAGE); + } + + @Override + protected Point getInitialSize(){ + return new Point(675,200); + } + + public String getFileName() { + return fileNameField.getText(); + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/EnclaveConfigDialog.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/EnclaveConfigDialog.java new file mode 100644 index 0000000000..20595f8095 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/EnclaveConfigDialog.java @@ -0,0 +1,257 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.dialogs; + +import org.eclipse.jface.preference.JFacePreferences; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import com.intel.sgx.handlers.EnclaveConfigHandler; + +public class EnclaveConfigDialog extends SGXDialogBase { + + @SuppressWarnings("unused") + private Shell shell; + private EnclaveConfigHandler enclaveConfig; + private Label statusLabel; + private Text prodID; + private Text isvSvn; + private Text threadStackSize; + private Text globalHeapSize; + private Text tcsNum; + private Combo tcsPolicy; + private Button disableDebug; + + public EnclaveConfigDialog(Shell parentshell,EnclaveConfigHandler enclaveConfigHandler) { + super(parentshell); + this.shell = parentshell; + this.enclaveConfig = enclaveConfigHandler; + setShellStyle(SWT.RESIZE | SWT.TITLE); + } + + @Override + protected Control createDialogArea(Composite parent) { + + Composite container = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = new GridLayout(3,false); + container.setLayout(gridLayout); + + final Group groupLabel1 = new Group(container, SWT.None); + groupLabel1.setLayout(new GridLayout(3,false)); + GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL); + innergrid1.horizontalSpan = 3; + groupLabel1.setLayoutData(innergrid1); + + Label warningLabel = new Label(groupLabel1,SWT.BEGINNING | SWT.WRAP); + warningLabel.setText("Note: Use this Menu to change the Enclave settings."); + + statusLabel = new Label(container,SWT.BEGINNING | SWT.WRAP); + GridData statusGrid = new GridData(GridData.FILL_HORIZONTAL); + statusGrid.horizontalSpan = 3; + statusLabel.setLayoutData(statusGrid); + statusLabel.setText(""); + statusLabel.setForeground(JFaceResources.getColorRegistry().get(JFacePreferences.ERROR_COLOR)); + + final Group groupLabel2 = new Group(container, SWT.None); + groupLabel2.setLayout(new GridLayout(3,false)); + groupLabel2.setText("Modify the Enclave Settings here..."); + GridData innergrid = new GridData(GridData.FILL_HORIZONTAL); + innergrid.horizontalSpan = 3; + groupLabel2.setLayoutData(innergrid); + + final Label messageLabel0 = new Label(groupLabel2, SWT.NONE); + messageLabel0.setText("Product ID:"); + messageLabel0.setLayoutData(new GridData(GridData.BEGINNING)); + + prodID = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER); + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalSpan = 2; + gridData.widthHint = 400; + prodID.setLayoutData(gridData); + prodID.setText(enclaveConfig.prodId); + prodID.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent modifyEvent) { + statusLabel.setText(""); + enclaveConfig.prodId = prodID.getText(); + } + }); + + final Label messageLabel1 = new Label(groupLabel2, SWT.NONE); + messageLabel1.setText("ISV SVN:"); + messageLabel1.setLayoutData(new GridData(GridData.BEGINNING)); + + isvSvn = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER); + isvSvn.setLayoutData(gridData); + isvSvn.setText(enclaveConfig.isvSvn); + isvSvn.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent modifyEvent) { + statusLabel.setText(""); + enclaveConfig.isvSvn = isvSvn.getText(); + } + }); + + final Label messageLabel2 = new Label(groupLabel2, SWT.NONE); + messageLabel2.setText("Thread Stack Size:"); + messageLabel2.setLayoutData(new GridData(GridData.BEGINNING)); + + threadStackSize = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER); + threadStackSize.setLayoutData(gridData); + threadStackSize.setText(enclaveConfig.threadStackSize); + threadStackSize.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent modifyEvent) { + enclaveConfig.threadStackSize = threadStackSize.getText(); + if(!(threadStackSize.getText().matches("0x[0-9a-fA-F]{1,}000"))) + { + statusLabel.setText("Error: The Thread Stack Size value must be Page Aligned."); + } + else + { + if(!(enclaveConfig.globalHeapSize.matches("0x[0-9a-fA-F]{1,}000"))) + statusLabel.setText("Error: The Global Heap Size value must be Page Aligned."); + else + statusLabel.setText(""); + } + } + }); + + final Label messageLabel3 = new Label(groupLabel2, SWT.NONE); + messageLabel3.setText("Global Heap Size:"); + messageLabel3.setLayoutData(new GridData(GridData.BEGINNING)); + + globalHeapSize = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER); + globalHeapSize.setLayoutData(gridData); + globalHeapSize.setText(enclaveConfig.globalHeapSize); + globalHeapSize.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent modifyEvent) { + enclaveConfig.globalHeapSize = globalHeapSize.getText(); + if(!(globalHeapSize.getText().matches("0x[0-9a-fA-F]{1,}000"))) + { + statusLabel.setText("Error: The Global Heap Size value must be Page Aligned."); + } + else + { + if(!(enclaveConfig.threadStackSize.matches("0x[0-9a-fA-F]{1,}000"))) + statusLabel.setText("Error: The Thread Stack Size value must be Page Aligned."); + else + statusLabel.setText(""); + + } + } + }); + + final Label messageLabel4 = new Label(groupLabel2, SWT.NONE); + messageLabel4.setText("TCS Number:"); + messageLabel4.setLayoutData(new GridData(GridData.BEGINNING)); + + tcsNum = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER); + tcsNum.setLayoutData(gridData); + tcsNum.setText(enclaveConfig.tcsNum); + tcsNum.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent modifyEvent) { + statusLabel.setText(""); + enclaveConfig.tcsNum = tcsNum.getText(); + } + }); + + final Label messageLabel5 = new Label(groupLabel2, SWT.NONE); + messageLabel5.setText("TCS Policy:"); + messageLabel5.setLayoutData(new GridData(GridData.BEGINNING)); + + final String[] items = {"Unbound","Bound"}; + tcsPolicy = new Combo(groupLabel2, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER); + tcsPolicy.setItems(items); + String item = items[Integer.parseInt(enclaveConfig.tcsPolicy)]; + int index = tcsPolicy.indexOf(item); + tcsPolicy.select(index < 0 ? 0 : index); + tcsPolicy.setLayoutData(gridData); + tcsPolicy.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e){ + statusLabel.setText(""); + enclaveConfig.tcsPolicy = (tcsPolicy.getSelectionIndex() == 0 ? "0" : "1"); + } + }); + + + final Label messageLabel6 = new Label(groupLabel2, SWT.NONE); + messageLabel6.setText("Disable Debug:"); + messageLabel6.setLayoutData(new GridData(GridData.BEGINNING)); + + disableDebug = new Button(groupLabel2,SWT.CHECK); + GridData gridData1 = new GridData(GridData.FILL_HORIZONTAL); + disableDebug.setLayoutData(gridData1); + disableDebug.setSelection(enclaveConfig.disableDebug.equals("1")?true:false); + disableDebug.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e){ + statusLabel.setText(""); + enclaveConfig.disableDebug = disableDebug.getSelection()?"1":"0"; + } + }); + + if(statusLabel.getText() != null){ + statusLabel.setVisible(true); + } + else{ + statusLabel.setVisible(false); + } + + return container; + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Enclave Configuration Settings:"); + } + + @Override + protected Point getInitialSize(){ + return new Point(450,400); + } + + @Override + protected + void okPressed(){ + enclaveConfig.prodId = this.prodID.getText(); + enclaveConfig.isvSvn = this.isvSvn.getText(); + enclaveConfig.threadStackSize = this.threadStackSize.getText(); + enclaveConfig.globalHeapSize = this.globalHeapSize.getText(); + enclaveConfig.tcsNum = this.tcsNum.getText(); + enclaveConfig.tcsPolicy = this.tcsPolicy.getSelectionIndex() == 0 ? "0" : "1"; + enclaveConfig.disableDebug = disableDebug.getSelection()?"1":"0"; + + + if((statusLabel.getText() == "") && (enclaveConfig.globalHeapSize.matches("0x[0-9a-fA-F]{1,}000")) && (enclaveConfig.threadStackSize.matches("0x[0-9a-fA-F]{1,}000"))) + super.okPressed(); + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/RemoveEnclaveFileDialog.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/RemoveEnclaveFileDialog.java new file mode 100644 index 0000000000..6db3d2e1c4 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/RemoveEnclaveFileDialog.java @@ -0,0 +1,122 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.dialogs; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; +//import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import com.intel.sgx.handlers.RemoveEnclave; + +public class RemoveEnclaveFileDialog extends Dialog{ + + private Text fileNameField; + private Shell shell; + private RemoveEnclave removeHandler; + + public RemoveEnclaveFileDialog(Shell shell, RemoveEnclave removeHandler) { + super(shell); + this.removeHandler = removeHandler; + this.shell = shell; + setShellStyle(SWT.RESIZE | SWT.TITLE); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = new GridLayout(1,false); + composite.setLayout(gridLayout); + + final Group container = new Group(composite, SWT.None); + container.setLayout(new GridLayout(3,false)); + GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL); + innergrid1.horizontalSpan = 3; + container.setLayoutData(innergrid1); + container.setText("Path to Enclave directory:"); + + final Label messageLabel = new Label(container, SWT.NONE); + messageLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1)); + messageLabel.setText("Enter the name of the Enclave Or Navigate to the Enclave folder to be removed from the host."); + + final Label fileNameLabel = new Label(container, SWT.NONE); + fileNameLabel.setLayoutData(new GridData(GridData.BEGINNING,GridData.CENTER, false, false)); + fileNameLabel.setText("Enclave Name:"); + + fileNameField = new Text(container, SWT.SINGLE | SWT.BORDER); + GridData textGridData1 = new GridData(GridData.FILL_HORIZONTAL); + textGridData1.minimumWidth = 400; + textGridData1.grabExcessHorizontalSpace = true; + fileNameField.setLayoutData(textGridData1); + + final Button browseButton = new Button(container, SWT.PUSH); + browseButton.setText("Browse"); + GridData buttonGridData1 = new GridData(GridData.END); + buttonGridData1.horizontalAlignment = SWT.RIGHT; + buttonGridData1.horizontalSpan = 1; + buttonGridData1.minimumWidth = 120; + browseButton.setLayoutData(buttonGridData1); + browseButton.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { + String result = fileNameField.getText(); + + DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN); + dialog.setMessage("Select the Enclave Directory to remove."); + dialog.setFilterPath(""); + result = dialog.open(); + fileNameField.setText(result); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + return container; + } + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Remove an Imported Enclave"); + } + + @Override + protected void okPressed(){ + removeHandler.edlFilename = fileNameField.getText(); + if(!fileNameField.getText().isEmpty()) + super.okPressed(); + } + + @Override + protected Point getInitialSize(){ + return new Point(675,205); + } + + public String getFileName() { + return fileNameField.getText(); + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/SGXDialogBase.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/SGXDialogBase.java new file mode 100644 index 0000000000..4b49a8bb31 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/SGXDialogBase.java @@ -0,0 +1,222 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.dialogs; + +import java.io.InputStream; +import java.util.Scanner; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.window.IShellProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog; + +import com.intel.sgx.Activator; + +public abstract class SGXDialogBase extends Dialog { + + protected Shell shell; + public Text configFileField; + public static FilteredResourcesSelectionDialog dialogForConfig(Shell shell) { + // final IContainer container = ResourcesPlugin.getWorkspace().getRoot(); + + final IContainer container = SGXDialogBase.getCurrentProject(); + + FilteredResourcesSelectionDialog d = new FilteredResourcesSelectionDialog( + shell, false, container, IResource.FILE) { + { + setInitialPattern("**"); + } + + @Override + protected IStatus validateItem(Object item) { + // return Status.OK_STATUS; + IFile f = (IFile) item; + if (f.getParent() instanceof IProject) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, + "The selected resource has to be part of the source folder"); + } + + + return super.validateItem(item); + } + + protected ItemsFilter createFilter() { + return new ResourceFilter(container, true, IResource.FILE) { + + @Override + public boolean matchItem(Object item) { + return isConfigFile(item); + } + + private boolean isConfigFile(Object item) { + if (!(item.toString().endsWith(".xml") && super + .matchItem(item))) { + return false; + } + try { + IFile iFile = (IFile) item; + return streamContainsString(iFile.getContents(), + ""); + } catch (Throwable e) { + return false; + } + } + + }; + + } + + public boolean streamContainsString(InputStream is, + String searchString) { + Scanner streamScanner = new Scanner(is); + if (streamScanner.findWithinHorizon(searchString, 0) != null) { + return true; + } else { + return false; + } + } + + }; + return d; + } + + + + protected SelectionListener configFileSelectionListener = new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { + + FilteredResourcesSelectionDialog d = dialogForConfig(shell); + d.setTitle("Select Config File"); + if (d.open() == Dialog.OK) { + IFile target = (IFile) d.getResult()[0]; + configFileField.setText(target.getLocation().toOSString()); + } + ; + } + + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + // TODO Auto-generated method stub + + } + + }; + + public SGXDialogBase(Shell parentShell) { + super(parentShell); + } + + public SGXDialogBase(IShellProvider parentShell) { + super(parentShell); + } + + protected Text addGroup(Composite composite, String title, String subtitle, + String label, String selectButtonLabel, SelectionListener selectionListener) { + final Group container = new Group(composite, SWT.None); + container.setLayout(new GridLayout(3, false)); + GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL); + innergrid1.horizontalSpan = 3; + container.setLayoutData(innergrid1); + container.setText(title); + + final Label messageLabel = new Label(container, SWT.NONE); + messageLabel.setLayoutData(new GridData(GridData.BEGINNING, + GridData.CENTER, false, false, 3, 1)); + messageLabel.setText(subtitle); + + final Label messageLabel1 = new Label(container, SWT.NONE); + messageLabel1.setText(label); + messageLabel1.setLayoutData(new GridData(GridData.BEGINNING)); + + Text directoryNameField = new Text(container, SWT.SINGLE | SWT.BORDER); + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalSpan = 1; + gridData.widthHint = 400; + directoryNameField.setLayoutData(gridData); + + final Button selectButton = new Button(container, SWT.PUSH); + selectButton.setText(selectButtonLabel); + GridData buttonGridData = new GridData(GridData.END); + buttonGridData.horizontalAlignment = SWT.RIGHT; + buttonGridData.horizontalSpan = 1; + buttonGridData.minimumWidth = 120; + selectButton.setLayoutData(buttonGridData); + selectButton.addSelectionListener(selectionListener); + return directoryNameField; + } + + + public IPath getCurrentProjectPath() { + IProject project = getCurrentProject(); + + IPath path = null; + if (project != null) { + path = project.getLocation(); + } + return path; + } + + static public IProject getCurrentProject() { + IProject project = null; + + + IWorkbenchWindow window = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow(); + if (window != null) { + IStructuredSelection selection = (IStructuredSelection) window + .getSelectionService().getSelection(); + Object firstElement = selection.getFirstElement(); + if (firstElement instanceof IAdaptable) { + project = (IProject) ((IAdaptable) firstElement) + .getAdapter(IProject.class); + } + } + return project; + } + + @Override + protected void configureShell(Shell newShell){ + super.configureShell(newShell); + } + + protected void addLabel(final Group container, String labelText) { + final Label messageLabel = new Label(container, SWT.NONE); + messageLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1)); + messageLabel.setText(labelText); + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignDialogBase.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignDialogBase.java new file mode 100644 index 0000000000..07d25c7321 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignDialogBase.java @@ -0,0 +1,174 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.dialogs; + +import java.io.File; +import java.util.Scanner; + +import javax.swing.JOptionPane; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +public abstract class TwoStepSignDialogBase extends SGXDialogBase { + + public Text enclaveFileField; + public Text hashFileField; + public Text externalSignPublicKeyFileField; + public Text externalSignedHashFileField; + public Text outputSignedEnclaveFileField; + + public TwoStepSignDialogBase(Shell parentShell) { + super(parentShell); + setShellStyle(SWT.RESIZE | SWT.TITLE); + this.shell = TwoStepSignDialogBase.this.getParentShell(); + + } + + // for each field, a corresponding listener + protected SelectionListener enclaveFileSelectionListener = new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { + String result = enclaveFileField.getText(); + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + + + + dialog.setFilterExtensions(new String[]{"*.so"} ); + dialog.setFilterPath(getCurrentProjectPath().toOSString()); + + if (result != null && !result.isEmpty()) { + dialog.setFilterPath(new File(result).getParent()); + } else { + dialog.setFilterPath(getCurrentProjectPath().toOSString()); + } + + result = dialog.open(); + + enclaveFileField.setText(result); + + hashFileField.setText(result + ".hex"); + + if (outputSignedEnclaveFileField != null){ + String outputSignedEnclavePath = result; + if(outputSignedEnclavePath.endsWith(".so")) + { + outputSignedEnclavePath = + outputSignedEnclavePath.substring(0,outputSignedEnclavePath.length() - ".so".length()); + outputSignedEnclaveFileField.setText(outputSignedEnclavePath+".signed.so"); + } + + } + + + + } + + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + } + }; + + protected SelectionListener hashFileSelectionListener = new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { + String result = hashFileField.getText(); + + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + + if (result != null && !result.isEmpty()) { + dialog.setFilterPath(new File(result).getParent()); + } else { + dialog.setFilterPath(getCurrentProjectPath().toOSString()); + } + + result = dialog.open(); + + hashFileField.setText(result); + } + + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + } + + }; + + protected SelectionListener publicKeyLocationSelectionListener = new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { + String result = externalSignPublicKeyFileField.getText(); + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + dialog.setFilterExtensions(new String [] {"*.pem", "*"}); + dialog.setFilterPath(getCurrentProjectPath().toOSString()); + result = dialog.open(); + externalSignPublicKeyFileField.setText(result); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }; + + protected SelectionListener externalSignedHashFileSelectionListener = new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { + String result = externalSignedHashFileField.getText(); + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + dialog.setFilterPath(getCurrentProjectPath().toOSString()); + result = dialog.open(); + externalSignedHashFileField.setText(result); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }; + + protected SelectionListener outputSignedEnclaveListener = new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { + String result = outputSignedEnclaveFileField.getText(); + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + + + dialog.setFilterExtensions(new String[]{"*.so", } ); + dialog.setFilterPath(getCurrentProjectPath().toOSString()); + + if (result != null && !result.isEmpty()) { + dialog.setFilterPath(new File(result).getParent()); + } else { + dialog.setFilterPath(getCurrentProjectPath().toOSString()); + } + + result = dialog.open(); + + outputSignedEnclaveFileField.setText(result); + + } + + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + } + }; + + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + } + + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog1.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog1.java new file mode 100644 index 0000000000..fdba448164 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog1.java @@ -0,0 +1,72 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.dialogs; + +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +import com.intel.sgx.handlers.TwoStepSignHandlerBase; + +public class TwoStepSignStep1Dialog1 extends TwoStepSignDialogBase { + + final private TwoStepSignHandlerBase handler; + + public TwoStepSignStep1Dialog1(Shell parentShell, TwoStepSignHandlerBase handler) { + super(parentShell); + this.handler = handler; + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = new GridLayout(1, false); + composite.setLayout(gridLayout); + + enclaveFileField = addGroup(composite, "Unsigned Enclave Path:", + "Select Enclave for which to generate the Hash.", + "Enclave Path:", "Select Enclave", enclaveFileSelectionListener); + + hashFileField = addGroup(composite, "Generate Hash:", + "Select Location to Output Hash File.", "Hash File Location:", + "Select File Path", hashFileSelectionListener); + + configFileField = addGroup(composite, "Configuration File:", + "Select Input Configuration XML File. ", + "Configuration File:", "Select Config", + configFileSelectionListener); + + composite.pack(true); + return composite; + } + + @Override + protected void okPressed() { + handler.enclaveFile = enclaveFileField.getText(); + handler.hashFile = hashFileField.getText(); + handler.configFile = configFileField.getText(); + + super.okPressed(); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Two Step Enclave Sign - Generate Hash"); + } + + + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog2.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog2.java new file mode 100644 index 0000000000..4c2852f9f4 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog2.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.dialogs; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +public class TwoStepSignStep1Dialog2 extends TwoStepSignDialogBase { + + final private String hashFile; + + public TwoStepSignStep1Dialog2(Shell parentShell, String hashFile) { + super(parentShell); + this.hashFile = hashFile; + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = new GridLayout(1,false); + composite.setLayout(gridLayout); + + addGroup1(composite); + addGroup3(composite); + + + return composite; + } + + private void addGroup1(Composite composite) { + final Group container = new Group(composite, SWT.None); + container.setLayout(new GridLayout(3,false)); + GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL); + innergrid1.horizontalSpan = 3; + container.setLayoutData(innergrid1); + container.setText("Hash File:"); + + final Label messageLabel = new Label(container, SWT.NONE); + messageLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1)); + messageLabel.setText("Hash File Generated at Location:"); + + final Label messageLabel1 = new Label(container, SWT.NONE); + messageLabel1.setText(hashFile); + + messageLabel1.setLayoutData(new GridData(GridData.BEGINNING)); + } + + private void addGroup3(Composite composite) { + final Group container3 = new Group(composite, SWT.None); + container3.setLayout(new GridLayout(3,false)); + GridData innergrid3 = new GridData(GridData.FILL_HORIZONTAL); + innergrid3.horizontalSpan = 3; + container3.setLayoutData(innergrid3); + container3.setText("Generate Signed Enclave (Step-2):"); + + final Label messageLabel4 = new Label(container3, SWT.NONE); + messageLabel4.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1)); + messageLabel4.setText("To Generate Signed Enclave Now: Click OK"); + + final Label messageLabel5 = new Label(container3, SWT.NONE); + messageLabel5.setLayoutData(new GridData(GridData.CENTER, GridData.END, false, false, 3, 1)); + messageLabel5.setText("To Generate Signed Enclave Later: Click Cancel"); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Two Step Enclave Sign - Generate Hash"); + } + + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog3.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog3.java new file mode 100644 index 0000000000..976f1c21b3 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep1Dialog3.java @@ -0,0 +1,105 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.dialogs; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +import com.intel.sgx.handlers.TwoStepSignHandlerBase; + +public class TwoStepSignStep1Dialog3 extends TwoStepSignDialogBase { + + final private TwoStepSignHandlerBase handler; + + public TwoStepSignStep1Dialog3(Shell parentShell, TwoStepSignHandlerBase handler) { + super(parentShell); + this.handler = handler; + } + + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = new GridLayout(1, false); + composite.setLayout(gridLayout); + + addInfoGroup(composite); + + externalSignPublicKeyFileField = addGroup(composite, "Public Key:", + "Select the Public Key file obtained from signing facility", + "Public Key:", "Select", publicKeyLocationSelectionListener); + + externalSignedHashFileField = addGroup(composite, "Signature:", + "Select the Signature file obtained from signing facility.", + "Signature:", + "Select", externalSignedHashFileSelectionListener); + + + outputSignedEnclaveFileField = addGroup(composite, "Signed Enclave:", + "Select where to save the output Signed Enclave.", + "Signed Enclave:", + "Select", outputSignedEnclaveListener); + + return composite; + } + + protected void addInfoGroup(Composite composite) { + final Group container = new Group(composite, SWT.None); + container.setLayout(new GridLayout(3,false)); + GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL); + innergrid1.horizontalSpan = 3; + container.setLayoutData(innergrid1); + container.setText("Hash and Enclave:"); + + + addInfoKeyValue(container, "Enclave File:", handler.enclaveFile); + addInfoKeyValue(container, "Config File:", handler.configFile); + addInfoKeyValue(container, "Hash File:", handler.hashFile); + } + + private void addInfoKeyValue(final Group container, String key, + String value) { + final Label messageLabel2 = new Label(container, SWT.NONE); + messageLabel2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1)); + messageLabel2.setText(key); + + final Label messageLabel3 = new Label(container, SWT.NONE); + messageLabel3.setText(value); + messageLabel3.setLayoutData(new GridData(GridData.BEGINNING)); + } + + @Override + protected void okPressed() { + handler.externalSignPublicKeyFile = externalSignPublicKeyFileField.getText(); + handler.externallySignedHashFile = externalSignedHashFileField.getText(); + handler.outputSignedEnclaveFile = outputSignedEnclaveFileField.getText(); + super.okPressed(); + } + + + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Two Step Enclave Sign - Generate Signed Enclave"); + } + + + + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep2Dialog.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep2Dialog.java new file mode 100644 index 0000000000..acd9e99627 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/TwoStepSignStep2Dialog.java @@ -0,0 +1,92 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.dialogs; + +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +import com.intel.sgx.handlers.TwoStepSignHandlerBase; +import com.intel.sgx.handlers.TwoStepSignStep2; + +public class TwoStepSignStep2Dialog extends TwoStepSignDialogBase{ + + final private TwoStepSignHandlerBase handler; + + + public TwoStepSignStep2Dialog(Shell parentShell, TwoStepSignHandlerBase handler) { + super(parentShell); + this.handler = handler; + } + + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = new GridLayout(1,false); + composite.setLayout(gridLayout); + + + + enclaveFileField= addGroup(composite, "Enclave:", + "Select the unsigned enclave file", + "Unsigned Enclave File:", "Select", enclaveFileSelectionListener); + + configFileField = addGroup(composite, "Configuration File:", + "Select Input Configuration XML File. ", + "Configuration File:", "Select Config", + configFileSelectionListener); + + hashFileField= addGroup(composite, "Hash:", + "Select the Hash file obtained from previous step", + "Hash File:", "Select", hashFileSelectionListener); + + externalSignPublicKeyFileField= addGroup(composite, "Public Key:", + "Select the Public Key file obtained from external signing facility", + "Public Key:", "Select", publicKeyLocationSelectionListener); + + externalSignedHashFileField = addGroup(composite, "Signature:", + "Select the Signature file obtained from signing facility.", + "Signature:", + "Select", externalSignedHashFileSelectionListener); + + outputSignedEnclaveFileField = addGroup(composite, "Signed Enclave:", + "Select where to save the output Signed Enclave.", + "Signed Enclave:", + "Select", outputSignedEnclaveListener); + + return composite; + } + + + @Override + protected void okPressed() { + handler.enclaveFile = enclaveFileField.getText(); + handler.hashFile = hashFileField.getText(); + handler.configFile = configFileField.getText(); + handler.externalSignPublicKeyFile = externalSignPublicKeyFileField.getText(); + handler.externallySignedHashFile = externalSignedHashFileField.getText(); + handler.outputSignedEnclaveFile = outputSignedEnclaveFileField.getText(); + + super.okPressed(); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Two Step Enclave Sign - Generate Signed Enclave"); + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/UpdateSignKeyDialog.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/UpdateSignKeyDialog.java new file mode 100644 index 0000000000..502fb2dcfa --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/dialogs/UpdateSignKeyDialog.java @@ -0,0 +1,191 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.dialogs; + +import java.io.File; + +import javax.swing.JOptionPane; + +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import com.intel.sgx.handlers.UpdateSigningKey; + +public class UpdateSignKeyDialog extends SGXDialogBase { + + private Shell shell; + public Text sourceKeyFileField; + public Text destinationKeyFileField; + public static boolean regenerate = false; + + private final SelectionListener destinationKeyFileSelectionListener = new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { + String result = destinationKeyFileField.getText(); + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + dialog.setFilterPath(getCurrentProjectPath().toOSString()); + dialog.setFilterExtensions(new String [] {"*.pem", "*"}); + result = dialog.open(); + destinationKeyFileField.setText(result); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }; + + private final SelectionListener sourceKeyFileSelectionListener = new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { + String result = sourceKeyFileField.getText(); + FileDialog dialog = new FileDialog(shell, SWT.OPEN); + dialog.setFilterExtensions(new String [] {"*.pem", "*"}); + dialog.setFilterPath(getCurrentProjectPath().toOSString()); + result = dialog.open(); + sourceKeyFileField.setText(result); + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }; + final private UpdateSigningKey handler; + + public UpdateSignKeyDialog(Shell parentShell, UpdateSigningKey handler) { + super(parentShell); + this.shell = parentShell; + this.handler = handler; + setShellStyle(SWT.RESIZE | SWT.TITLE); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + final GridLayout gridLayout = new GridLayout(1,false); + composite.setLayout(gridLayout); + + destinationKeyFileField = addGroup(composite, "Enclave Signing Key:", + "Select the Signing Key to be Updated or Generated.", + "Enclave Signing Key:", "Select", destinationKeyFileSelectionListener); + + sourceKeyFileField = addGroup(composite, "Import:", + "To import your own Signing Key use the Import Signing Key option.", + "Import Signing Key:", "Import Key", sourceKeyFileSelectionListener); + + addGroup2(composite); + + return composite; + } + + protected void addGroup2(Composite composite) { + final Group container2 = new Group(composite, SWT.None); + container2.setLayout(new GridLayout(3,false)); + GridData innergrid2 = new GridData(GridData.FILL_HORIZONTAL); + innergrid2.horizontalSpan = 3; + container2.setLayoutData(innergrid2); + container2.setText("Generate:"); + + final Label messageLabel3 = new Label(container2, SWT.NONE); + messageLabel3.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1)); + messageLabel3.setText("To Generate a new Signing Key use the Generate Signing Key option."); + + Label warningLabel2 = new Label(container2,SWT.FILL | SWT.WRAP); + warningLabel2.setText("Generate a new Signing Key:"); + warningLabel2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label dummy2 = new Label(container2,0); + dummy2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + final Button updateSigningKey = new Button(container2, SWT.PUSH); + updateSigningKey.setText("Generate Key"); + GridData buttonGridData2 = new GridData(GridData.END); + buttonGridData2.horizontalAlignment = SWT.RIGHT; + buttonGridData2.horizontalSpan = 1; + buttonGridData2.minimumWidth = 120; + updateSigningKey.setLayoutData(buttonGridData2); + updateSigningKey.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { + if( !destinationKeyFileField.getText().isEmpty()) + { + regenerate = true; + UpdateSignKeyDialog.this.setReturnCode(InputDialog.OK); + okPressed(); + UpdateSignKeyDialog.this.close(); + } + else + JOptionPane.showMessageDialog(null, "Enclave Signing Key field is not provided.", "Error", + JOptionPane.ERROR_MESSAGE); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + } + + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Import or (Re)Generate Enclave Signing Key"); + } + + @Override + protected void okPressed() { + + handler.sourceKeyFile = sourceKeyFileField.getText(); + handler.destinationKeyFile = destinationKeyFileField.getText(); + if((!sourceKeyFileField.getText().isEmpty() && !destinationKeyFileField.getText().isEmpty() && + (new File(sourceKeyFileField.getText())).isFile()) + || regenerate == true ) + { + System.out.println("regenerate = " + regenerate); + super.okPressed(); + } + else + { + if(sourceKeyFileField.getText().isEmpty() && destinationKeyFileField.getText().isEmpty()) + JOptionPane.showMessageDialog(null, "Enclave Signing Key and Import Singing Key are not provided.", "Error", + JOptionPane.ERROR_MESSAGE); + else + { + if(sourceKeyFileField.getText().isEmpty()) + JOptionPane.showMessageDialog(null, "Import Singing Key is not provided.", "Error", + JOptionPane.ERROR_MESSAGE); + else + if(!(new File(sourceKeyFileField.getText())).isFile()) + JOptionPane.showMessageDialog(null, "Invalid Import Singing Key.", "Error", + JOptionPane.ERROR_MESSAGE); + + if(destinationKeyFileField.getText().isEmpty()) + JOptionPane.showMessageDialog(null, "Enclave Signing Key is not provided.", "Error", + JOptionPane.ERROR_MESSAGE); + } + } + + } + + + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKDiscoveredPathInfo.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKDiscoveredPathInfo.java new file mode 100644 index 0000000000..2c48b2fb39 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKDiscoveredPathInfo.java @@ -0,0 +1,202 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.discovery; + +import java.util.List; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo; +import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredScannerInfoSerializable; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; + +import com.intel.sgx.Activator; +/* + * This code has been taken from the NDK plugin for Linux. If there is an update to this code there, then refactor this code. + */ +public class SGXSDKDiscoveredPathInfo implements IDiscoveredPathInfo { + + private final IProject mProject; + private long mLastUpdate = IFile.NULL_STAMP; + private IPath[] mIncludePaths; + private Map mSymbols; + private boolean mNeedReindexing = false; + private static final IPath LINUX_MK = new Path("sgx/Makefile"); + + //Keys for preferences + // public static final String LAST_UPDATE = "lastUpdate"; //$NON-NLS-1$ + + + public SGXSDKDiscoveredPathInfo(IProject project) { + this.mProject = project; + load(); + } + + @Override + public IProject getProject() { + return mProject; + } + + @Override + public IPath[] getIncludePaths() { + if (mNeedReindexing) { + CCorePlugin.getIndexManager().reindex(CoreModel.getDefault().create(mProject)); + mNeedReindexing = false; + } + return mIncludePaths; + } + + void setIncludePaths(List pathStrings) { + mIncludePaths = new IPath[pathStrings.size()]; + int i = 0; + for (String path : pathStrings) + mIncludePaths[i++] = new Path(path); + mNeedReindexing = true; + } + + @Override + public Map getSymbols() { + if (mSymbols == null) + mSymbols = new HashMap(); + return mSymbols; + } + + void setSymbols(Map symbols) { + this.mSymbols = symbols; + } + + @Override + public IDiscoveredScannerInfoSerializable getSerializable() { + return null; + } + + public void update(IProgressMonitor monitor) throws CoreException { + if (!needUpdating()) + return; + + new SGXSDKDiscoveryUpdater(this).runUpdate(monitor); + + if (mIncludePaths != null && mSymbols != null) { + recordUpdate(); + save(); + } + } + + private boolean needUpdating() { + + + if (mLastUpdate == IFile.NULL_STAMP) { + return true; + } + + return mProject.getFile(LINUX_MK).getLocalTimeStamp() > mLastUpdate; + } + + private void recordUpdate() { + mLastUpdate = mProject.getFile(LINUX_MK).getLocalTimeStamp(); + } + + public void delete() { + mLastUpdate = IFile.NULL_STAMP; + } + + private File getInfoFile() { + File stateLoc = Activator.getDefault().getStateLocation().toFile(); + return new File(stateLoc, mProject.getName() + ".pathInfo"); //$NON-NLS-1$ + } + + private void save() { + try { + File infoFile = getInfoFile(); + infoFile.getParentFile().mkdirs(); + PrintStream out = new PrintStream(infoFile); + + out.print("t,"); //$NON-NLS-1$ + out.print(mLastUpdate); + out.println(); + + for (IPath include : mIncludePaths) { + out.print("i,"); //$NON-NLS-1$ + out.print(include.toPortableString()); + out.println(); + } + + for (Entry symbol : mSymbols.entrySet()) { + out.print("d,"); //$NON-NLS-1$ + out.print(symbol.getKey()); + out.print(","); //$NON-NLS-1$ + out.print(symbol.getValue()); + out.println(); + } + + out.close(); + } catch (IOException e) { + Activator.log(e); + } + + } + + private void load() { + try { + File infoFile = getInfoFile(); + if (!infoFile.exists()) + return; + + long timestamp = IFile.NULL_STAMP; + List includes = new ArrayList(); + Map defines = new HashMap(); + + BufferedReader reader = new BufferedReader(new FileReader(infoFile)); + for (String line = reader.readLine(); line != null; line = reader.readLine()) { + switch (line.charAt(0)) { + case 't': + timestamp = Long.valueOf(line.substring(2)); + break; + case 'i': + includes.add(Path.fromPortableString(line.substring(2))); + break; + case 'd': + int n = line.indexOf(',', 2); + if (n == -1) + defines.put(line.substring(2), ""); //$NON-NLS-1$ + else + defines.put(line.substring(2, n), line.substring(n + 1)); + break; + } + } + reader.close(); + + mLastUpdate = timestamp; + mIncludePaths = includes.toArray(new IPath[includes.size()]); + mSymbols = defines; + } catch (IOException e) { + Activator.log(e); + } + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKDiscoveryUpdater.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKDiscoveryUpdater.java new file mode 100644 index 0000000000..4c10fccdcc --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKDiscoveryUpdater.java @@ -0,0 +1,310 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.discovery; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.envvar.IEnvironmentVariable; +import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.managedbuilder.core.IBuilder; +import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; + +import com.intel.sgx.Activator; +import com.intel.sgx.build.SGXSDKCommandLauncher; + +/* + * This code has been taken from the NDK plugin for Linux. If there is an update to this code there, then refactor this code. + */ +public class SGXSDKDiscoveryUpdater { + private final SGXSDKDiscoveredPathInfo mPathInfo; + private final IProject mProject; + + private boolean mCPlusPlus = false; + private String mCommand; + private List mArguments = new ArrayList(); + + public SGXSDKDiscoveryUpdater(SGXSDKDiscoveredPathInfo pathInfo) { + mPathInfo = pathInfo; + mProject = pathInfo.getProject(); + } + + public void runUpdate(IProgressMonitor monitor) throws CoreException { + try { + // Run make -nB to get the list of commands + IPath commandPath = new Path("make"); //$NON-NLS-1$ + String[] args = {"-f", "sgx/Makefile", "-n", "-B" }; //$NON-NLS-1$ + String[] env = calcEnvironment(); + File projectDir = new File(mProject.getLocationURI()); + IPath changeToDirectory = new Path(projectDir.getAbsolutePath()); + Process proc = new SGXSDKCommandLauncher().execute(commandPath, args, env,changeToDirectory, monitor); + if (proc == null) { + return; + } + + BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream())); + String line = reader.readLine(); + while (line != null) { + checkBuildLine(line); + line = reader.readLine(); + } + + if (mCommand == null) { + return; + } + + // Run the unique commands with special gcc options to extract the + // symbols and paths + // -E -P -v -dD + mArguments.add("-E"); //$NON-NLS-1$ + mArguments.add("-P"); //$NON-NLS-1$ + mArguments.add("-v"); //$NON-NLS-1$ + mArguments.add("-dD"); //$NON-NLS-1$ + + URL url = Activator.findFile(new Path("discovery/" + (mCPlusPlus ? "test.cpp" : "test.c"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + File testFile = new File(FileLocator.toFileURL(url).toURI()); + String testFileName = testFile.getAbsolutePath().replace('\\', '/'); + mArguments.add(testFileName); + + args = mArguments.toArray(new String[mArguments.size()]); + proc = new SGXSDKCommandLauncher().execute(new Path(mCommand), args, env,changeToDirectory, monitor); + + final InputStream errStream = proc.getErrorStream(); + new Thread() { + @Override + public void run() { + checkIncludes(errStream); + }; + }.start(); + + checkDefines(proc.getInputStream()); + } catch (IOException e) { + throw new CoreException(Activator.newStatus(e)); + } catch (URISyntaxException e) { + throw new CoreException(Activator.newStatus(e)); + } + } + + private String[] calcEnvironment() throws CoreException { + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(mProject); + IBuilder builder = info.getDefaultConfiguration().getBuilder(); + HashMap envMap = new HashMap(); + if (builder.appendEnvironment()) { + ICConfigurationDescription cfgDes = ManagedBuildManager.getDescriptionForConfiguration(builder.getParent().getParent()); + IEnvironmentVariableManager mngr = CCorePlugin.getDefault().getBuildEnvironmentManager(); + IEnvironmentVariable[] vars = mngr.getVariables(cfgDes, true); + for (IEnvironmentVariable var : vars) { + envMap.put(var.getName(), var.getValue()); + } + } + // Add variables from build info + Map builderEnv = builder.getExpandedEnvironment(); + if (builderEnv != null) + envMap.putAll(builderEnv); + List strings = new ArrayList(envMap.size()); + for (Entry entry : envMap.entrySet()) { + StringBuffer buffer = new StringBuffer(entry.getKey()); + buffer.append('=').append(entry.getValue()); + strings.add(buffer.toString()); + } + return strings.toArray(new String[strings.size()]); + } + + private static class Line { + private final String line; + private int pos; + + public Line(String line) { + this.line = line; + } + + public Line(String line, int pos) { + this(line); + this.pos = pos; + } + + public String getToken() { + skipWhiteSpace(); + if (pos == line.length()) + return null; + + int start = pos; + boolean inQuote = false; + + while (true) { + char c = line.charAt(pos); + if (c == ' ') { + if (!inQuote) + return line.substring(start, pos); + } else if (c == '"') { + inQuote = !inQuote; + } + + if (++pos == line.length()) + return null; + } + + } + + private String getRemaining() { + if (pos == line.length()) + return null; + + skipWhiteSpace(); + String rc = line.substring(pos); + pos = line.length(); + return rc; + } + + private void skipWhiteSpace() { + while (true) { + if (pos == line.length()) + return; + char c = line.charAt(pos); + if (c == ' ') + pos++; + else + return; + } + } + } + + private void checkBuildLine(String text) { + Line line = new Line(text); + String cmd = line.getToken(); + if (cmd == null) { + return; + } else if (cmd.endsWith("g++")) { //$NON-NLS-1$ + if (mCommand == null || !mCPlusPlus) { + mCommand = cmd; + mCPlusPlus = true; + } + gatherOptions(line); + } else if (cmd.endsWith("gcc")) { //$NON-NLS-1$ + if (mCommand == null){ + mCommand = cmd; + } + gatherOptions(line); + } + + } + + private void gatherOptions(Line line) { + for (String option = line.getToken(); option != null; option = line.getToken()) { + if (option.startsWith("-")) { //$NON-NLS-1$ + // only look at options + if (option.equals("-I")) { //$NON-NLS-1$ + String dir = line.getToken(); + if (dir != null) + addArg(option + dir); + } else if (option.startsWith("-I")) { //$NON-NLS-1$ + addArg(option); + } else if (option.equals("-D")) { //$NON-NLS-1$ + String def = line.getToken(); + if (def != null) + addArg(option + def); + } else if (option.startsWith("-D")) { //$NON-NLS-1$ + addArg(option); + } else if (option.startsWith("-f")) { //$NON-NLS-1$ + addArg(option); + } else if (option.startsWith("-m")) { //$NON-NLS-1$ + addArg(option); + } else if (option.startsWith("--sysroot")) { //$NON-NLS-1$ + addArg(option); + } + } + } + } + + private void addArg(String arg) { + if (!mArguments.contains(arg)) + mArguments.add(arg); + } + + private void checkIncludes(InputStream in) { + try { + List includes = new ArrayList(); + boolean inIncludes1 = false; + boolean inIncludes2 = false; + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + String line = reader.readLine(); + while (line != null) { + if (!inIncludes1) { + if (line.equals("#include \"...\" search starts here:")) //$NON-NLS-1$ + inIncludes1 = true; + } else { + if (!inIncludes2) { + if (line.equals("#include <...> search starts here:")) //$NON-NLS-1$ + inIncludes2 = true; + else + includes.add(line.trim()); + } else { + if (line.equals("End of search list.")) { //$NON-NLS-1$ + mPathInfo.setIncludePaths(includes); + } else { + includes.add(line.trim()); + } + } + } + line = reader.readLine(); + } + } catch (IOException e) { + Activator.log(e); + } + } + + private void checkDefines(InputStream in) { + try { + Map defines = new HashMap(); + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + String line = reader.readLine(); + while (line != null) { + if (line.startsWith("#define")) { //$NON-NLS-1$ + Line l = new Line(line, 7); + String var = l.getToken(); + if (var == null) + continue; + String value = l.getRemaining(); + if (value == null) + value = ""; //$NON-NLS-1$ + defines.put(var, value); + } + line = reader.readLine(); + } + mPathInfo.setSymbols(defines); + } catch (IOException e) { + Activator.log(e); + } + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKScannerInfoCollector.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKScannerInfoCollector.java new file mode 100644 index 0000000000..fb21bff5cf --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/discovery/SGXSDKScannerInfoCollector.java @@ -0,0 +1,103 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.discovery; + +import java.util.List; +import java.util.Map; + +import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo; +import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector3; +import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollectorCleaner; +import org.eclipse.cdt.make.core.scannerconfig.InfoContext; +import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes; +import org.eclipse.cdt.managedbuilder.scannerconfig.IManagedScannerInfoCollector; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +/* + * This code has been taken from the NDK plugin for Linux. If there is an update to this code there, then refactor this code. + */ +public class SGXSDKScannerInfoCollector implements IScannerInfoCollector3,IScannerInfoCollectorCleaner,IManagedScannerInfoCollector{ + + private SGXSDKDiscoveredPathInfo sgxPathInfo; + + @Override + public void setProject(IProject project) { + throw new Error("Not implemented"); + } + + @Override + public void updateScannerConfiguration(IProgressMonitor monitor) + throws CoreException { + sgxPathInfo.update(monitor); + } + + @Override + public IDiscoveredPathInfo createPathInfoObject() { + return sgxPathInfo; + } + + @Override + public void contributeToScannerConfig(Object resource, @SuppressWarnings("rawtypes") Map scannerInfo) { + throw new Error("Not implemented"); + } + + @SuppressWarnings("rawtypes") + @Override + public List getCollectedScannerInfo(Object resource, ScannerInfoTypes type) { + throw new Error("Not implemented"); + } + + @Override + public Map getDefinedSymbols() { + throw new Error("Not implemented"); + } + + @Override + public List getIncludePaths() { + throw new Error("Not implemented"); + } + + @Override + public void deleteAllPaths(IResource resource) { + throw new Error("Not implemented"); + } + + @Override + public void deleteAllSymbols(IResource resource) { + throw new Error("Not implemented"); + } + + @Override + public void deletePath(IResource resource, String path) { + throw new Error("Not implemented"); + } + + @Override + public void deleteSymbol(IResource resource, String symbol) { + throw new Error("Not implemented"); + } + + @Override + public void deleteAll(IResource resource) { + sgxPathInfo.delete(); + } + + @Override + public void setInfoContext(InfoContext context) { + sgxPathInfo = new SGXSDKDiscoveredPathInfo(context.getProject()); + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddEnclave.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddEnclave.java new file mode 100644 index 0000000000..e998de690b --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddEnclave.java @@ -0,0 +1,213 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.handlers; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Map; + +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.templateengine.TemplateEngine; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +import com.intel.sgx.Activator; +import com.intel.sgx.dialogs.AddEnclaveFileDialog; +import com.intel.sgx.preferences.PreferenceConstants; + +public class AddEnclave extends ModuleCreationBaseHandler implements IHandler { + + public String edlFilename = ""; + public String linuxMakePath = ""; + @Override + public void addHandlerListener(IHandlerListener handlerListener) { + } + + @Override + public void dispose() { + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + String edlBasename,linuxPath,enclaveBasename; + IProject project = null; + + // Display display = Display.getCurrent(); + // Shell shell = new Shell(display); + Shell shell = null; + AddEnclaveFileDialog dialog = new AddEnclaveFileDialog(shell, this); + if (dialog.open() != InputDialog.OK) { + return null; + } + + if((edlFilename.isEmpty())){ + System.err.println("No Enclave selected to Import."); + return null; + } + + edlBasename = edlFilename; + ISelection selection = HandlerUtil.getCurrentSelection(event); + Object element = null; + if (selection instanceof IStructuredSelection) { + element = ((IStructuredSelection) selection).getFirstElement(); + if (element instanceof IResource) { + project = ((IResource) element).getProject(); + } + } + if (!project.exists()) { + System.err.println("Error: Project not found"); + return null; + } + + for (IConfigurationElement i : Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.core.resources.projectNature")){ + } + + + + + IPath linuxMkRelPath = (Path.fromOSString(linuxMakePath)).makeRelativeTo(project.getLocation().append("sgx").append("enclave_"+edlBasename)); + + + if(linuxMkRelPath.removeLastSegments(1).lastSegment().toString().equalsIgnoreCase("sgx")){ + linuxPath = linuxMkRelPath.removeLastSegments(3).toOSString(); + enclaveBasename = linuxMkRelPath.removeLastSegments(2).lastSegment().toString(); + } + + else{ + linuxPath = linuxMkRelPath.removeLastSegments(2).toOSString(); + enclaveBasename = linuxMkRelPath.removeLastSegments(1).lastSegment().toString(); + } + + IProgressMonitor monitor = new NullProgressMonitor(); + TemplateCore template = null; + if(isCPProject(project)) + if(dialog.generateApp()) + { + template = TemplateEngine.getDefault().getTemplateById("SGXEnclaveC++WithSample"); + } + else + { + template = TemplateEngine.getDefault().getTemplateById("SGXEnclaveC++Minimal"); + } + else + if(dialog.generateApp()) + { + template = TemplateEngine.getDefault().getTemplateById("SGXEnclaveCWithSample"); + } + else + { + template = TemplateEngine.getDefault().getTemplateById("SGXEnclaveCMinimal"); + } + + Map valueStore = template.getValueStore(); + valueStore.put("projectName", project.getName()); + valueStore.put("workspacePath", linuxPath); + valueStore.put("baseName", enclaveBasename); + valueStore.put("enclaveName",edlFilename); + valueStore.put("EnclaveName",capitalize(edlFilename)); + valueStore.put("ENCLAVENAME",edlFilename.toUpperCase()); + valueStore.put("SdkPathFromPlugin", Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.SDK_PATH)); + + IStatus[] statuses = template.executeTemplateProcesses(monitor, false); + for(IStatus e: statuses) + { + } + + ManagedBuildManager.saveBuildInfo(project, true); + try { + project.refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e) { + Activator.log(e); + e.printStackTrace(); + } + + + return null; + } + + private String capitalize(final String line) { + return Character.toUpperCase(line.charAt(0)) + line.substring(1); + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public boolean isHandled() { + return true; + } + + @Override + public void removeHandlerListener(IHandlerListener handlerListener) { + } + + public void setFilename(String filename) { + edlFilename = filename; + } + + + + + public static void copyFile(File source, File dest) throws IOException { + byte[] bytes = new byte[4092]; + if (source != null && dest != null) { + if (source.isFile()) { + FileInputStream in = null; + FileOutputStream out = null; + try { + in = new FileInputStream(source); + out = new FileOutputStream(dest); + int len; + while ((len = in.read(bytes)) != -1) { + out.write(bytes, 0, len); + } + } catch (Exception e) { + Activator.log(e); + System.err.println("Error: " + e.toString()); + } finally { + try { + if (in != null) + in.close(); + } finally { + if (out != null) + out.close(); + } + } + } + } + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddSGXNature.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddSGXNature.java new file mode 100644 index 0000000000..569b608adb --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddSGXNature.java @@ -0,0 +1,163 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.handlers; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.Map; + +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.templateengine.TemplateEngine; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +//import org.eclipse.core.resources.IWorkspaceRunnable; +//import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +//import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.handlers.HandlerUtil; + +import com.intel.sgx.Activator; +import com.intel.sgx.natures.SGXNature; + +public class AddSGXNature implements IHandler { + + private IProject project; + + public AddSGXNature() { + project = null; + } + + @Override + public void addHandlerListener(IHandlerListener arg0) { + } + + @Override + public void dispose() { + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection selection = HandlerUtil.getCurrentSelection(event); + Object element = null; + if (selection instanceof IStructuredSelection) { + element = ((IStructuredSelection) selection).getFirstElement(); + if (element instanceof IResource) { + project = ((IResource) element).getProject(); + } + } + if (!project.exists()) { + System.err.println("Error: Project not found"); + return null; + } else { + try { + TemplateCore template = TemplateEngine.getDefault().getTemplateById("AddSGXNature"); + + Map valueStore = template.getValueStore(); + valueStore.put("projectName",project.getName()); + valueStore.put("baseName",project.getName()); + + IProgressMonitor monitor = new NullProgressMonitor(); + template.executeTemplateProcesses(monitor, false); + + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + try{ + IProjectDescription description = project.getDescription(); + String[] natures = description.getNatureIds(); + + String[] newNatures = new String[natures.length + 1]; + System.arraycopy(natures, 0, newNatures, 0, natures.length); + newNatures[natures.length] = SGXNature.NATURE_ID; + IStatus status = workspace.validateNatureSet(newNatures); + + if (status.getCode() == IStatus.OK) { + description.setNatureIds(newNatures); + project.setDescription(description, null); + } + + project.refreshLocal(IResource.DEPTH_ONE,null); + } catch(CoreException e){ + Activator.log(e); + throw new InvocationTargetException(e); + } + } catch(InvocationTargetException e){ + Activator.log(e); + e.printStackTrace(); + } + + try { + project.refreshLocal(IResource.DEPTH_INFINITE,null); + } catch (CoreException e) { + e.printStackTrace(); + } + } + return null; + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public boolean isHandled() { + return true; + } + + @Override + public void removeHandlerListener(IHandlerListener arg0) { + } + + public static void copyFile(File source, File dest) throws IOException { + byte[] bytes = new byte[4092]; + if (source != null && dest != null) { + if (source.isFile()) { + FileInputStream in = null; + FileOutputStream out = null; + try { + in = new FileInputStream(source); + out = new FileOutputStream(dest); + int len; + while ((len = in.read(bytes)) != -1) { + out.write(bytes, 0, len); + } + } catch (Exception e) { + System.err.println("Error: " + e.toString()); + + } finally { + try { + if (in != null) + in.close(); + } finally { + if (out != null) + out.close(); + } + } + } + } + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddTrustedStaticLib.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddTrustedStaticLib.java new file mode 100644 index 0000000000..efeeeedd3a --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddTrustedStaticLib.java @@ -0,0 +1,193 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.handlers; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Map; + +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.templateengine.TemplateEngine; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +import com.intel.sgx.Activator; +import com.intel.sgx.dialogs.AddTrustedStaticLibFileDialog; +import com.intel.sgx.preferences.PreferenceConstants; + +public class AddTrustedStaticLib extends ModuleCreationBaseHandler implements IHandler { + + public String edlFilename = ""; + public String linuxMakePath = ""; + + @Override + public void addHandlerListener(IHandlerListener handlerListener) { + } + + @Override + public void dispose() { + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + String edlBasename,linuxPath,enclaveBasename; + IProject project = null; + + // Display display = Display.getCurrent(); + // Shell shell = new Shell(display); + Shell shell = null; + AddTrustedStaticLibFileDialog dialog = new AddTrustedStaticLibFileDialog(shell, this); + if (dialog.open() != InputDialog.OK) { + return null; + } + + if((edlFilename.isEmpty() )){ + System.err.println("No Enclave selected to Import."); + return null; + } + + edlBasename = edlFilename; + ISelection selection = HandlerUtil.getCurrentSelection(event); + Object element = null; + if (selection instanceof IStructuredSelection) { + element = ((IStructuredSelection) selection).getFirstElement(); + if (element instanceof IResource) { + project = ((IResource) element).getProject(); + } + } + if (!project.exists()) { + System.err.println("Error: Project not found"); + return null; + } + + for (IConfigurationElement i : Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.core.resources.projectNature")){ + } + + + + + IPath linuxMkRelPath = (Path.fromOSString(linuxMakePath)).makeRelativeTo(project.getLocation().append("sgx").append("enclave_"+edlBasename)); + + + if(linuxMkRelPath.removeLastSegments(1).lastSegment().toString().equalsIgnoreCase("sgx")){ + linuxPath = linuxMkRelPath.removeLastSegments(3).toOSString(); + enclaveBasename = linuxMkRelPath.removeLastSegments(2).lastSegment().toString(); + } + + else{ + linuxPath = linuxMkRelPath.removeLastSegments(2).toOSString(); + enclaveBasename = linuxMkRelPath.removeLastSegments(1).lastSegment().toString(); + } + + IProgressMonitor monitor = new NullProgressMonitor(); + TemplateCore template = null; + if(isCPProject(project)) + template = TemplateEngine.getDefault().getTemplateById("SGXTrustedStaticLibraryC++Minimal"); + else + template = TemplateEngine.getDefault().getTemplateById("SGXTrustedStaticLibraryCMinimal"); + + Map valueStore = template.getValueStore(); + valueStore.put("projectName", project.getName()); + valueStore.put("workspacePath", linuxPath); + valueStore.put("baseName", enclaveBasename); + valueStore.put("enclaveName",edlFilename); + valueStore.put("EnclaveName",capitalize(edlFilename)); + valueStore.put("ENCLAVENAME",edlFilename.toUpperCase()); + valueStore.put("SdkPathFromPlugin", Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.SDK_PATH)); + + IStatus[] statuses = template.executeTemplateProcesses(monitor, false); + + + ManagedBuildManager.saveBuildInfo(project, true); + try { + project.refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e) { + Activator.log(e); + e.printStackTrace(); + } + return null; + } + + private String capitalize(final String line) { + return Character.toUpperCase(line.charAt(0)) + line.substring(1); + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public boolean isHandled() { + return true; + } + + @Override + public void removeHandlerListener(IHandlerListener handlerListener) { + } + + public void setFilename(String filename) { + edlFilename = filename; + } + + public static void copyFile(File source, File dest) throws IOException { + byte[] bytes = new byte[4092]; + if (source != null && dest != null) { + if (source.isFile()) { + FileInputStream in = null; + FileOutputStream out = null; + try { + in = new FileInputStream(source); + out = new FileOutputStream(dest); + int len; + while ((len = in.read(bytes)) != -1) { + out.write(bytes, 0, len); + } + } catch (Exception e) { + Activator.log(e); + System.err.println("Error: " + e.toString()); + } finally { + try { + if (in != null) + in.close(); + } finally { + if (out != null) + out.close(); + } + } + } + } + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddUntrustedModule.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddUntrustedModule.java new file mode 100644 index 0000000000..4ebf8da34c --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/AddUntrustedModule.java @@ -0,0 +1,231 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.handlers; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Map; + + + +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.templateengine.TemplateEngine; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; + +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +import com.intel.sgx.Activator; +import com.intel.sgx.dialogs.AddUntrustedModuleDialog; +import com.intel.sgx.preferences.PreferenceConstants; + +public class AddUntrustedModule extends ModuleCreationBaseHandler implements IHandler { + + public String edlFilename = ""; + public String libPath = ""; + private IPath edlCanonicalFilename; + private IPath libCanonicalPathname; + + @Override + public void addHandlerListener(IHandlerListener handlerListener) { + } + + @Override + public void dispose() { + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + String edlBasename,edlPath,linuxLibPath,modulePath,enclaveBasename; + IProject project = null; + + //Display display = Display.getCurrent(); + Shell shell = null; + + AddUntrustedModuleDialog dialog = new AddUntrustedModuleDialog(shell, this); + if (dialog.open() != InputDialog.OK) { + return null; + } + + if((edlFilename.isEmpty() && libPath.isEmpty())){ + System.err.println("No Enclave selected to Import."); + return null; + } + if( edlFilename.isEmpty() ){ + System.err.println("Edl File not selected."); + return null; + } + edlCanonicalFilename = Path.fromOSString(edlFilename); + if (!edlCanonicalFilename.getFileExtension().toLowerCase().equals("edl")) { + System.err.println("Error: EDL file extension = "+ edlCanonicalFilename.getFileExtension()); + return null; + } + edlBasename = edlCanonicalFilename.removeFileExtension().lastSegment(); + + + ISelection selection = HandlerUtil.getCurrentSelection(event); + Object element = null; + if (selection instanceof IStructuredSelection) { + element = ((IStructuredSelection) selection).getFirstElement(); + if (element instanceof IResource) { + project = ((IResource) element).getProject(); + } + } + if (!project.exists()) { + System.err.println("Error: Project not found"); + return null; + } + + IPath targetRelPath = project.getProjectRelativePath().append("sgx").append("untrusted_" + edlBasename); + + try { + for (int i = 1; i <= targetRelPath.segmentCount(); i++) { + IFolder subfolder = project.getFolder(targetRelPath.uptoSegment(i)); + + if (!subfolder.exists()) { + subfolder.create(true, true, null); + } + } + } catch (CoreException e) { + System.err.println("Error: Error creating enclave directory."); + Activator.log(e); + e.printStackTrace(); + } + + IPath edlRelPath = (Path.fromOSString(edlFilename)).makeRelativeTo(project.getLocation().append("sgx")); + edlPath = edlRelPath.toOSString(); + IPath linuxLibRelPath = (Path.fromOSString(libPath)).makeRelativeTo(project.getLocation().append("sgx")); + + if(linuxLibRelPath.removeLastSegments(1).lastSegment().toString().equalsIgnoreCase("sgx")){ + linuxLibPath = linuxLibRelPath.removeLastSegments(3).toOSString(); + modulePath = linuxLibRelPath.removeFirstSegments(linuxLibRelPath.segmentCount()-3).removeLastSegments(1).toOSString(); + } + else if(linuxLibRelPath.removeLastSegments(1).lastSegment().toString().equalsIgnoreCase("src")){ + linuxLibPath = linuxLibRelPath.removeLastSegments(3).toOSString(); + modulePath = linuxLibRelPath.removeFirstSegments(linuxLibRelPath.segmentCount()-3).removeLastSegments(1).toOSString(); + } + else{ + linuxLibPath = linuxLibRelPath.removeLastSegments(2).toOSString(); + modulePath = linuxLibRelPath.removeFirstSegments(linuxLibRelPath.segmentCount()-2).removeLastSegments(1).toOSString(); + } + + IProgressMonitor monitor = new NullProgressMonitor(); + TemplateCore template = null; + if(isCPProject(project)) + template = TemplateEngine.getDefault().getTemplateById("SGXUntrustedModuleC++Minimal"); + else + template = TemplateEngine.getDefault().getTemplateById("SGXUntrustedModuleCMinimal"); + + + + Map valueStore = template.getValueStore(); + + + valueStore.put("projectName", project.getName()); + valueStore.put("sourcepath",linuxLibPath); + valueStore.put("edlPath", edlPath); + valueStore.put("baseName", edlBasename); + valueStore.put("workspacePath", linuxLibPath);//deprecate + valueStore.put("modPath", modulePath); + valueStore.put("ENCLAVENAME",edlBasename.toUpperCase()); + valueStore.put("libPath",libPath); + valueStore.put("SdkPathFromPlugin", Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.SDK_PATH)); + + IStatus[] statuses = template.executeTemplateProcesses(monitor, false); + + try { + copyFile(new File(edlFilename), project.getLocation().append("sgx").append("untrusted_"+edlBasename).append(edlBasename+".edl").toFile()); + } catch (IOException e1) { + e1.printStackTrace(); + } + + + ManagedBuildManager.saveBuildInfo(project, true); + try { + project.refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e) { + Activator.log(e); + e.printStackTrace(); + } + return null; + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public boolean isHandled() { + return true; + } + + @Override + public void removeHandlerListener(IHandlerListener handlerListener) { + } + + public void setFilename(String filename) { + edlFilename = filename; + } + + public static void copyFile(File source, File dest) throws IOException { + byte[] bytes = new byte[4092]; + if (source != null && dest != null) { + if (source.isFile()) { + FileInputStream in = null; + FileOutputStream out = null; + try { + in = new FileInputStream(source); + out = new FileOutputStream(dest); + int len; + while ((len = in.read(bytes)) != -1) { + out.write(bytes, 0, len); + } + } catch (Exception e) { + Activator.log(e); + System.err.println("Error: " + e.toString()); + } finally { + try { + if (in != null) + in.close(); + } finally { + if (out != null) + out.close(); + } + } + } + } + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/EnclaveConfigHandler.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/EnclaveConfigHandler.java new file mode 100644 index 0000000000..fffa912c4f --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/EnclaveConfigHandler.java @@ -0,0 +1,156 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.handlers; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.templateengine.TemplateEngine; +import org.eclipse.core.commands.IHandlerListener; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import com.intel.sgx.Activator; +import com.intel.sgx.dialogs.EnclaveConfigDialog; +import com.intel.sgx.dialogs.SGXDialogBase; + +public class EnclaveConfigHandler extends SGXHandler { + + public String prodId; + public String isvSvn; + public String threadStackSize; + public String globalHeapSize; + public String tcsNum; + public String tcsPolicy; + public String disableDebug; + private IFile configPath; + + @Override + public void addHandlerListener(IHandlerListener arg0) { + } + + @Override + public void dispose() { + } + + @Override + public Object executeSGXStuff() throws CancelException, ErrorException { + + FilteredResourcesSelectionDialog d = SGXDialogBase + .dialogForConfig(shell); + d.setTitle("Select Config File"); + if (d.open() != Dialog.OK) { + cancel(); + } + + configPath = ((IFile) d.getResult()[0]); + + readConfig(configPath.getLocation()); + EnclaveConfigDialog dialog = new EnclaveConfigDialog(shell, this); + if (dialog.open() != InputDialog.OK) { + return null; + } + writeConfig(); + refreshProject(); + + return null; + } + + protected void writeConfig() { + IProgressMonitor monitor = new NullProgressMonitor(); + TemplateCore template = TemplateEngine.getDefault().getTemplateById("SGXEnclaveConfig"); + + Map valueStore = template.getValueStore(); + valueStore.put("projectName", project.getName()); + valueStore.put("configFile", configPath.getProjectRelativePath().toOSString()); + valueStore.put("ProdID", this.prodId); + valueStore.put("IsvSvn", this.isvSvn); + valueStore.put("ThreadStackSize", this.threadStackSize); + valueStore.put("GlobalHeapSize", this.globalHeapSize); + valueStore.put("TcsNumber", this.tcsNum); + valueStore.put("TcsPolicy", this.tcsPolicy); + valueStore.put("DisableDebug", this.disableDebug); + IStatus[] result = template.executeTemplateProcesses(monitor, true); + + for (IStatus status: result) { + } + } + + + + protected void readConfig(IPath configPath) throws ErrorException { + + try { + String xmlFile = configPath.toString(); + File configFile = new File(xmlFile); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder; + dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(configFile); + doc.getDocumentElement().normalize(); + + NodeList nList = doc.getElementsByTagName("EnclaveConfiguration"); + Node nNode = nList.item(0); + + if (nNode.getNodeType() == Node.ELEMENT_NODE) { + Element e = (Element) nNode; + this.prodId = e.getElementsByTagName("ProdID").item(0) + .getTextContent(); + this.isvSvn = e.getElementsByTagName("ISVSVN").item(0) + .getTextContent(); + this.threadStackSize = e.getElementsByTagName("StackMaxSize") + .item(0).getTextContent(); + this.globalHeapSize = e.getElementsByTagName("HeapMaxSize") + .item(0).getTextContent(); + this.tcsNum = e.getElementsByTagName("TCSNum").item(0) + .getTextContent(); + this.tcsPolicy = e.getElementsByTagName("TCSPolicy").item(0) + .getTextContent(); + this.disableDebug = e.getElementsByTagName("DisableDebug") + .item(0).getTextContent(); + } + + } catch (ParserConfigurationException e) { + Activator.log(e); + e.printStackTrace(); + quitWithError("Could not parse '"+configPath.toOSString()+"'"); + } catch (SAXException e) { + Activator.log(e); + e.printStackTrace(); + quitWithError("Could not parse '"+configPath.toOSString()+"'"); + } catch (IOException e) { + Activator.log(e); + e.printStackTrace(); + quitWithError("Could not read'"+configPath.toOSString()+"'"); + } + + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/ModuleCreationBaseHandler.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/ModuleCreationBaseHandler.java new file mode 100644 index 0000000000..708208c6cb --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/ModuleCreationBaseHandler.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.handlers; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.runtime.CoreException; + +public class ModuleCreationBaseHandler { + public boolean isCPProject(IProject project) + { + boolean isCPProject = false; + IProjectDescription description; + try { + description = project.getDescription(); + String[] natures = description.getNatureIds(); + for(String nature: natures){ + if(nature.equals("org.eclipse.cdt.core.ccnature")) + isCPProject = true; + } + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return isCPProject; + + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/RemoveEnclave.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/RemoveEnclave.java new file mode 100644 index 0000000000..058e622996 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/RemoveEnclave.java @@ -0,0 +1,169 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.handlers; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +import com.intel.sgx.Activator; +import com.intel.sgx.dialogs.RemoveEnclaveFileDialog; + +public class RemoveEnclave implements IHandler { + + public String edlFilename = ""; + private IPath edlCanonicalFilename; + + @Override + public void addHandlerListener(IHandlerListener handlerListener) { + } + + @Override + public void dispose() { + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + String edlBasename; + IProject project = null; + + // Display display = Display.getCurrent(); + // Shell shell = new Shell(display); + + RemoveEnclaveFileDialog dialog = new RemoveEnclaveFileDialog(null, this); + + if (dialog.open() != InputDialog.OK) { + return null; + } + + edlCanonicalFilename = Path.fromOSString(edlFilename); + edlBasename = edlCanonicalFilename.lastSegment(); + + if(edlBasename.isEmpty()){ + return null; + } + + ISelection selection = HandlerUtil.getCurrentSelection(event); + Object element = null; + if(selection instanceof IStructuredSelection) { + element = ((IStructuredSelection)selection).getFirstElement(); + if (element instanceof IResource) { + project= ((IResource)element).getProject(); + } + } + if (!project.exists()) { + System.err.println("Error: Project not found"); + return null; + } + + IPath targetRelPath = project.getProjectRelativePath().append("sgx").append("enclave_" + edlBasename); + + try { + for (int i=1;i<=targetRelPath.segmentCount();i++) { + IFolder subfolder = project.getFolder(targetRelPath.uptoSegment(i)); + + if (subfolder.exists()){ + if(subfolder.getProjectRelativePath().toOSString().contains("enclave_"+edlBasename)){ + subfolder.delete(true, true, null); + break; + } + } + } + targetRelPath = project.getProjectRelativePath().append("sgx").append(edlBasename); + for (int i=1;i<=targetRelPath.segmentCount();i++) { + IFolder subfolder = project.getFolder(targetRelPath.uptoSegment(i)); + + if (subfolder.exists()){ + if(subfolder.getProjectRelativePath().toOSString().contains(edlBasename)){ + subfolder.delete(true, true, null); + break; + } + } + } + } catch (Exception e) { + Activator.log(e); + } + + try { + project.refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e) { + Activator.log(e); + } catch (IllegalArgumentException e){ + Activator.log(e); + } + + return null; + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public boolean isHandled() { + return true; + } + + @Override + public void removeHandlerListener(IHandlerListener handlerListener) { + } + + public static void copyFile(File source, File dest) throws IOException { + byte[] bytes = new byte[4092]; + if (source != null && dest != null) { + if (source.isFile()) { + FileInputStream in = null; + FileOutputStream out = null; + try { + in = new FileInputStream(source); + out = new FileOutputStream(dest); + int len; + while ((len = in.read(bytes)) != -1) { + out.write(bytes, 0, len); + } + } catch (Exception e) { + System.err.println("Error: " + e.toString()); + Activator.log(e); + } finally { + try { + if (in != null) + in.close(); + } finally { + if (out != null) + out.close(); + } + } + } + } + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/SGXHandler.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/SGXHandler.java new file mode 100644 index 0000000000..bfd5bcb551 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/SGXHandler.java @@ -0,0 +1,206 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.handlers; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +import javax.swing.JOptionPane; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Utility base class for all Handlers The derived classes must implement + * executeSgxStuff() instead of execute(). The user may call methods cancel(), + * quitWithError() & info() + * + * @author mlutescu + * + */ +public abstract class SGXHandler implements IHandler { + + public String projectPath = null; + protected IProject project; + protected Shell shell; + + /** + * Throwing this IS an error. Means that the process can't continue + * + * @author mlutescu + * + */ + static protected class ErrorException extends Exception { + + public ErrorException(String message) { + super(message); + } + + } + + /** + * Throwing this is not an error; just signals stop of execution because the + * user cancels + * + * @author mlutescu + * + */ + static protected class CancelException extends Exception { + + public CancelException() { + super(); + } + + } + + @Override + public final Object execute(ExecutionEvent event) throws ExecutionException { + try { + initializeShell(); + initializeProject(event); + return executeSGXStuff(); + } catch (ErrorException e) { + e.printStackTrace(); + } catch (CancelException e) { + // do nothing by design ; it's Ok to not handle this exception. + } + return null; + } + + protected abstract Object executeSGXStuff() throws ErrorException, + CancelException; + + public SGXHandler() { + super(); + } + + public static void copyFile(File source, File dest) throws ErrorException { + byte[] bytes = new byte[4092]; + if (source != null && dest != null) { + if (source.isFile()) { + FileInputStream in = null; + FileOutputStream out = null; + try { + in = new FileInputStream(source); + out = new FileOutputStream(dest); + int len; + while ((len = in.read(bytes)) != -1) { + out.write(bytes, 0, len); + } + } catch (IOException e) { + System.err.println("Error: " + e.toString()); + quitWithError("Could not copy from\n" + "'" + + source.getAbsolutePath() + "'\n" + "to\n" + "'" + + dest.getAbsolutePath()); + } finally { + try { + if (in != null) { + in.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + } + } + } + + protected static void quitWithError(String message) throws ErrorException { + JOptionPane.showMessageDialog(null, message, "Two Step Enclave Sign", + JOptionPane.ERROR_MESSAGE); + throw new ErrorException(message); + } + + static protected void cancel() throws CancelException { + throw new CancelException(); + } + + protected void initializeProject(ExecutionEvent event) + throws ErrorException { + project = null; + ISelection selection = HandlerUtil.getCurrentSelection(event); + Object element = null; + if (selection instanceof IStructuredSelection) { + element = ((IStructuredSelection) selection).getFirstElement(); + if (element instanceof IResource) { + project = ((IResource) element).getProject(); + } + } + + if (!project.exists()) { + quitWithError("Project not found"); + } + + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public boolean isHandled() { + return true; + } + + @Override + public void removeHandlerListener(IHandlerListener arg0) { + } + + @Override + public void addHandlerListener(IHandlerListener arg0) { + } + + @Override + public void dispose() { + } + + protected void initializeShell() { + shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + } + + protected void refreshProject() throws ErrorException { + try { + project.refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e1) { + quitWithError(e1.getLocalizedMessage()); + } + } + + protected void info(String windowName, String message) { + JOptionPane.showMessageDialog(null, message,windowName, + JOptionPane.INFORMATION_MESSAGE); + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/SGXSDKWizardHandler.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/SGXSDKWizardHandler.java new file mode 100644 index 0000000000..b445c5ea8a --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/SGXSDKWizardHandler.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.handlers; + +import org.eclipse.cdt.managedbuilder.core.IToolChain; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.ui.wizards.STDWizardHandler; + +public class SGXSDKWizardHandler extends STDWizardHandler { + + public SGXSDKWizardHandler() { + super(null, null); + } + + + @Override + public IToolChain[] getSelectedToolChains() { + IToolChain[] tcs = ManagedBuildManager.getRealToolChains(); + for (IToolChain tc : tcs) { + if (tc.getId().equals("com.intel.sgx.SGXtoolChain")) + return new IToolChain[] { + tc + }; + } + return super.getSelectedToolChains(); + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignHandlerBase.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignHandlerBase.java new file mode 100644 index 0000000000..59ae2eb7a4 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignHandlerBase.java @@ -0,0 +1,196 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.handlers; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; + +import com.intel.sgx.preferences.PreferenceConstants; + +public abstract class TwoStepSignHandlerBase extends SGXHandler { + + public String hashFile = null; + public String configFile = null; + public String enclaveFile = null; + public String externalSignPublicKeyFile = null; + public String externallySignedHashFile = null; + public String outputSignedEnclaveFile = null; + + protected File signtool; + + public TwoStepSignHandlerBase() { + super(); + } + + protected void executeGenData() throws ErrorException { + validateConfigFile(); + validateEnclaveFile(); + + refreshProject(); + executeSignTool(new String[] { "gendata", + "-enclave", enclaveFile, + "-config", configFile, + "-out", hashFile }); + refreshProject(); + + validateHashFile(); + + } + + protected void executeCatSig() throws ErrorException { + validateEnclaveFile(); + validateConfigFile(); + validateHashFile(); + + validateExternalSignPublicKeyFile(); + validateExternallySignedHashFile(); + + executeSignTool("catsig", + // enclave data: + "-enclave", enclaveFile, + "-config", configFile, + // previously generated: + "-unsigned", hashFile, + // externally generated + "-key", externalSignPublicKeyFile, + "-sig", externallySignedHashFile, + // output + "-out", outputSignedEnclaveFile + + ); + + refreshProject(); + + validateOutputSignedEnclaveFile(); + + info("Two Step Enclave Sign","Enclave signed successfully !"); + } + + void initializeSigntool() throws ErrorException { + signtool = PreferenceConstants.getSDKDescriptor().getSignerPath(); + if (!signtool.exists() || signtool.isDirectory()) { + quitWithError("Error generating hash! Sign Tool Not Found !\n Please make sure to have written in the box the value for SGX SDK Directory in Window->Preferences->SGX Preferences. \n Usually the path is in /opt/intel/sgxsdk/" ); + } + + } + + protected void validateEnclaveFile() throws ErrorException { + File enclave = new File(enclaveFile); + if (!enclave.exists() || enclave.isDirectory()) { + quitWithError("Error generating hash! Unsigned Enclave File Not Found! Try building the enclave first"); + } + } + + protected void validateConfigFile() throws ErrorException { + if (configFile == null || configFile.isEmpty()) { + quitWithError("Error Enclave Configuration File Not Found !"); + } + File config = new File(configFile); + if (!config.exists() || config.isDirectory()) { + quitWithError("Enclave Config File Not Found !"); + } + } + + protected void validateExternallySignedHashFile() throws ErrorException { + if (externallySignedHashFile == null || externallySignedHashFile.isEmpty()) { + quitWithError("Error signing enclave! Signature File Not Found !"); + } + + File signature = new File(externallySignedHashFile); + if (!signature.exists() || signature.isDirectory()) { + quitWithError("Error signing enclave! Signature File Not Found !"); + } + } + + protected void validateExternalSignPublicKeyFile() throws ErrorException { + if (externalSignPublicKeyFile == null || externalSignPublicKeyFile.isEmpty()) { + quitWithError("Public Key File Not Found !"); + } + + File publickkey = new File(externalSignPublicKeyFile); + if (!publickkey.exists() || publickkey.isDirectory()) { + quitWithError("Error signing enclave! Public Key File Not Found !"); + } + } + + private void validateOutputSignedEnclaveFile() throws ErrorException { + if(outputSignedEnclaveFile == null || outputSignedEnclaveFile.isEmpty()) + { + quitWithError("Output Signed File Not Found !"); + } + File outputSignedEnclave = new File(outputSignedEnclaveFile); + if(!outputSignedEnclave.exists() || outputSignedEnclave.isDirectory()) + { + quitWithError("Output Signed File Not Found !"); + } + + // TODO Auto-generated method stub + + } + + protected void validateHashFile() throws ErrorException { + if(hashFile == null || hashFile.isEmpty()) + { + quitWithError("Hash File Not Found !"); + } + File hash = new File(hashFile); + if(!hash.exists() || hash.isDirectory()) + { + quitWithError("Hash File Not Found !"); + } + } + + + protected void executeSignTool(String... args) throws ErrorException { + + Process q; + try { + + String[] allArgs = new String[args.length+1]; + allArgs[0] = signtool.getAbsolutePath(); + System.arraycopy(args, 0, allArgs, 1, args.length); + + for (String arg : args){ + } + String fullOutput = ""; + q = Runtime.getRuntime().exec(allArgs); + + BufferedReader stdInput = new BufferedReader(new InputStreamReader( + q.getInputStream())); + BufferedReader stdErr = new BufferedReader(new InputStreamReader( + q.getErrorStream())); + String s = null; + while ((s = stdInput.readLine()) != null) { + } + String[] out = new String[20]; + int i = 0; + while ((out[i] = stdErr.readLine()) != null) { + fullOutput += out[i]+"\n"; + i++; + } + String result = out[i - 1]; + + if (!result.equals("Succeed.")) { + // quitWithError("Error generating hash! " + out[i - 2]); + quitWithError("Error generating hash! " + fullOutput); + } + } catch (IOException e) { + quitWithError(e.getLocalizedMessage()); + } + + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignStep1.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignStep1.java new file mode 100644 index 0000000000..cb2f3649bd --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignStep1.java @@ -0,0 +1,74 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.handlers; + +import org.eclipse.jface.dialogs.InputDialog; + +import com.intel.sgx.dialogs.SGXDialogBase; +import com.intel.sgx.dialogs.TwoStepSignStep1Dialog1; +import com.intel.sgx.dialogs.TwoStepSignStep1Dialog2; +import com.intel.sgx.dialogs.TwoStepSignStep1Dialog3; + +// Generate Hash +public class TwoStepSignStep1 extends TwoStepSignHandlerBase { + + public TwoStepSignStep1() { + } + + @Override + protected Object executeSGXStuff() throws ErrorException, CancelException { + + initializeSigntool(); + + showDialog1(); + showDialog2(); + showDialog3(); + return null; + } + + private void showDialog1() throws CancelException, ErrorException { + + TwoStepSignStep1Dialog1 dialog1 = new TwoStepSignStep1Dialog1(shell, this); + if (dialog1.open() != InputDialog.OK) { + cancel(); + } + + executeGenData(); + + } + + private void showDialog2() throws CancelException { + TwoStepSignStep1Dialog2 dialog2 = new TwoStepSignStep1Dialog2(shell, + hashFile); + + if (dialog2.open() != InputDialog.OK) { + cancel(); + } + } + + protected void showDialog3() throws CancelException, ErrorException { + SGXDialogBase dialog3 = new TwoStepSignStep1Dialog3(shell, this); + if (dialog3.open() != InputDialog.OK) { + cancel(); + } + + validateExternalSignPublicKeyFile(); + + validateExternallySignedHashFile(); + + executeCatSig(); + + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignStep2.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignStep2.java new file mode 100644 index 0000000000..f19738036c --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/TwoStepSignStep2.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.handlers; + +import org.eclipse.jface.dialogs.InputDialog; + +import com.intel.sgx.dialogs.TwoStepSignStep2Dialog; + +// Sign +public class TwoStepSignStep2 extends TwoStepSignHandlerBase { + + public TwoStepSignStep2() { + } + + @Override + protected Object executeSGXStuff() throws ErrorException, CancelException { + initializeSigntool(); + + TwoStepSignStep2Dialog dialog = new TwoStepSignStep2Dialog(shell, this); + if(dialog.open() != InputDialog.OK) { + cancel(); + } + + executeCatSig(); + return null; + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/UpdateSigningKey.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/UpdateSigningKey.java new file mode 100644 index 0000000000..68870ea3cf --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/UpdateSigningKey.java @@ -0,0 +1,101 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.handlers; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +//import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +//import java.security.KeyPair; +//import java.security.KeyPairGenerator; +//import java.security.NoSuchAlgorithmException; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; + +//import org.bouncycastle.openssl.PEMWriter; +import com.intel.sgx.Activator; +import com.intel.sgx.dialogs.UpdateSignKeyDialog; + +public class UpdateSigningKey extends SGXHandler { + + public String sourceKeyFile = null; + public String destinationKeyFile = null; + public String projectPath = null; + + @Override + protected Object executeSGXStuff() throws ErrorException, CancelException { + + UpdateSignKeyDialog dialog = new UpdateSignKeyDialog(shell, this); + int result = dialog.open(); + if (result != InputDialog.OK) { + cancel(); + } + + if(UpdateSignKeyDialog.regenerate == false) + { + IPath sourceFile = Path.fromOSString(sourceKeyFile); + IPath destFile = Path.fromOSString(destinationKeyFile); + copyFile(sourceFile.toFile(), destFile.toFile()); + refreshProject(); + info("Update SGX Enclave Signing Key","copied \n'" + sourceKeyFile + "' into \n'" + destFile + "'"); + } else { + UpdateSignKeyDialog.regenerate = false; + try { + Process q; + String opensslCmd = "openssl genrsa -out " + destinationKeyFile + + " -3 3072"; + q = Runtime.getRuntime().exec(opensslCmd); + BufferedReader stdInput = new BufferedReader( + new InputStreamReader(q.getInputStream())); + BufferedReader stdErr = new BufferedReader( + new InputStreamReader(q.getErrorStream())); + String s = null; + while ((s = stdInput.readLine()) != null) { + } + while ((s = stdErr.readLine()) != null) { + } + project.refreshLocal(IResource.DEPTH_INFINITE, null); + if (q.exitValue() == 0){ + info("Update SGX Enclave Signing Key","'"+destinationKeyFile+"'"+" was generated!"); + } else { + quitWithError("Could not generate '"+destinationKeyFile+"'!!!"); + } + } catch (IOException e) { + Activator.log(e); + e.printStackTrace(); + } catch (CoreException e) { + Activator.log(e); + e.printStackTrace(); + } + } + return null; + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/about.html b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/about.html new file mode 100644 index 0000000000..a3b9ace448 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/handlers/about.html @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + +About + + +

About This Content

+ +

June 22, 2007

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/messages.properties b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/messages.properties new file mode 100644 index 0000000000..c0011fadda --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/messages.properties @@ -0,0 +1,16 @@ +######################################################################### +# Copyright (c) 2016 Intel Corporation. # +# # +# All rights reserved. This program and the accompanying materials # +# are made available under the terms of the Eclipse Public License v1.0 # +# which accompanies this distribution, and is available at # +# http://www.eclipse.org/legal/epl-v10.html # +# # +# Contributors: # +# Intel Corporation - initial implementation and documentation # +######################################################################### + + +CreateNativeFolders_No_folders=No folders. +CreateNativeFolders_Missing_project_name=Missing project Name. +CreateNativeFolders_Project_does_not_exist=Project does not exist. diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXCCNature.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXCCNature.java new file mode 100644 index 0000000000..fde7f7d29c --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXCCNature.java @@ -0,0 +1,45 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.natures; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectNature; +import org.eclipse.core.runtime.CoreException; + +public class SGXCCNature implements IProjectNature { + + private IProject project; + public static final String NATURE_ID = "com.intel.sgx.sgxccnature"; + + public SGXCCNature() { + } + + @Override + public void configure() throws CoreException { + } + + @Override + public void deconfigure() throws CoreException { + } + + @Override + public IProject getProject() { + return project; + } + + @Override + public void setProject(IProject project) { + this.project = project; + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXNature.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXNature.java new file mode 100644 index 0000000000..8db687e029 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXNature.java @@ -0,0 +1,45 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.natures; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectNature; +import org.eclipse.core.runtime.CoreException; + +public class SGXNature implements IProjectNature { + + private IProject project; + public static final String NATURE_ID = "com.intel.sgx.sgxnature"; + + public SGXNature() { + } + + @Override + public void configure() throws CoreException { + } + + @Override + public void deconfigure() throws CoreException { + } + + @Override + public IProject getProject() { + return project; + } + + @Override + public void setProject(IProject project) { + this.project = project; + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXStaticCCNature.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXStaticCCNature.java new file mode 100644 index 0000000000..0d642ee5c8 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/natures/SGXStaticCCNature.java @@ -0,0 +1,45 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.natures; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectNature; +import org.eclipse.core.runtime.CoreException; + +public class SGXStaticCCNature implements IProjectNature { + + private IProject project; + public static final String NATURE_ID = "com.intel.sgx.sgxstaticccnature"; + + public SGXStaticCCNature() { + } + + @Override + public void configure() throws CoreException { + } + + @Override + public void deconfigure() throws CoreException { + } + + @Override + public IProject getProject() { + return project; + } + + @Override + public void setProject(IProject project) { + this.project = project; + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/ISDKDescriptor.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/ISDKDescriptor.java new file mode 100644 index 0000000000..ec8b274912 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/ISDKDescriptor.java @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.preferences; + +import java.io.File; + + +public interface ISDKDescriptor { + + public abstract File getSdkDir(); + + public abstract File getToolsDir(); + + public abstract File getSignerPath(); + + public abstract File getEdger8rPath(); + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/PreferenceConstants.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/PreferenceConstants.java new file mode 100644 index 0000000000..5ce1abc9cc --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/PreferenceConstants.java @@ -0,0 +1,112 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.preferences; + +import java.io.File; + +import org.eclipse.jface.preference.IPreferenceStore; + +import com.intel.sgx.Activator; + +/** + * Constant definitions for plug-in preferences + */ +public class PreferenceConstants { + + public static final String SDK_PATH = "SDKPathPreference"; + + public static ISDKDescriptor getSDKDescriptor() { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + File sdkDir = new File(store.getString(PreferenceConstants.SDK_PATH)); + + if (System.getProperty("os.arch").contains("64")) { + return new SGXSDK64Descriptor(sdkDir); + } else { + return new SGXSDK32Descriptor(sdkDir); + } + } + + + static public class SGXSDK32Descriptor implements ISDKDescriptor { + private final File sdkDir; + private final File toolDir; + private final File signerPath; + private final File edger8rPath; + + public SGXSDK32Descriptor(File location){ + this.sdkDir = location; + this.toolDir = new File(location, "bin/x86"); + this.signerPath = new File(toolDir, "sgx_sign"); + this.edger8rPath = new File(toolDir, "sgx_edger8r"); + } + + @Override + public File getSdkDir() { + return sdkDir; + } + + @Override + public File getToolsDir() { + return toolDir; + } + + @Override + public File getSignerPath() { + return signerPath; + } + + @Override + public File getEdger8rPath() { + return edger8rPath; + } + + } + + + static public class SGXSDK64Descriptor implements ISDKDescriptor { + private final File sdkDir; + private final File toolDir; + private final File signerPath; + private final File edger8rPath; + + public SGXSDK64Descriptor(File sdkDir){ + this.sdkDir = sdkDir; + this.toolDir = new File(sdkDir, "bin/x64"); + this.signerPath = new File(toolDir, "sgx_sign"); + this.edger8rPath = new File(toolDir, "sgx_edger8r"); + } + + @Override + public File getSdkDir() { + return sdkDir; + } + + @Override + public File getToolsDir() { + return toolDir; + } + + @Override + public File getSignerPath() { + return signerPath; + } + + @Override + public File getEdger8rPath() { + return edger8rPath; + } + + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/PreferenceInitializer.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/PreferenceInitializer.java new file mode 100644 index 0000000000..b85d5e5299 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/PreferenceInitializer.java @@ -0,0 +1,32 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.preferences; + +import com.intel.sgx.Activator; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.jface.preference.IPreferenceStore; + +/** + * Class used to initialize default preference values. + */ +public class PreferenceInitializer extends AbstractPreferenceInitializer { + + public void initializeDefaultPreferences() { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + store.setDefault(PreferenceConstants.SDK_PATH, ""); + Activator.getDefault().getPreferenceStore().setValue(PreferenceConstants.SDK_PATH, "/opt/intel/sgxsdk"); + Activator.getDefault().getPreferenceStore().setDefault(PreferenceConstants.SDK_PATH, "/opt/intel/sgxsdk"); + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/SGXPreferencePage.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/SGXPreferencePage.java new file mode 100644 index 0000000000..bbf6608a71 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/preferences/SGXPreferencePage.java @@ -0,0 +1,110 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.preferences; + +import org.eclipse.jface.preference.DirectoryFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +import com.intel.sgx.Activator; +import com.intel.sgx.SdkPathVariableProvider; + +/** + * This class represents a preference page that + * is contributed to the Preferences dialog. By + * subclassing FieldEditorPreferencePage, we + * can use the field support built into JFace that allows + * us to create a page that is small and knows how to + * save, restore and apply itself. + *

+ * This page is used to modify preferences only. They + * are stored in the preference store that belongs to + * the main plug-in class. That way, preferences can + * be accessed directly via the preference store. + */ + +public class SGXPreferencePage + extends FieldEditorPreferencePage + implements IWorkbenchPreferencePage { + + private SGXSdkDirectoryFieldEditor sgxSdkDirectoryEditor; + + public SGXPreferencePage() { + super(GRID); + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + setDescription("SGX Preferences"); + } + + /** + * Creates the field editors. Field editors are abstractions of + * the common GUI blocks needed to manipulate various types + * of preferences. Each field editor knows how to save and + * restore itself. + */ + + @Override + protected void createFieldEditors() { + sgxSdkDirectoryEditor = new SGXSdkDirectoryFieldEditor(PreferenceConstants.SDK_PATH, + "&SGX SDK Directory:", getFieldEditorParent()); + addField(sgxSdkDirectoryEditor); + } + + /* + * Validates whether the path entered in the SGX SDK Preferences points to the SGX SDK or not. + */ + private static class SGXSdkDirectoryFieldEditor extends DirectoryFieldEditor { + public SGXSdkDirectoryFieldEditor(String name, String labelText, Composite parent) { + super(name, labelText, parent); + setEmptyStringAllowed(true); + } + + @Override + protected boolean doCheckState() { + if (!super.doCheckState()) { + setErrorMessage("SGX Preferences: Not a Valid directory"); + return false; + } + + String dirname = getTextControl().getText().trim(); + if (!dirname.isEmpty() && !SdkPathVariableProvider.isValidSGXSdkLocation(dirname)) { + setErrorMessage("SGX SDK: Not a Valid SGX SDK directory"); + return false; + } + return true; + } + + @Override + public Text getTextControl(Composite parent) { + setValidateStrategy(VALIDATE_ON_KEY_STROKE); + return super.getTextControl(parent); + } + } + + @Override + public void init(IWorkbench workbench) { + } + + @Override + public void dispose() { + super.dispose(); + + if (sgxSdkDirectoryEditor != null) { + sgxSdkDirectoryEditor.dispose(); + sgxSdkDirectoryEditor = null; + } + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/templates/CreateNativeFolders.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/templates/CreateNativeFolders.java new file mode 100644 index 0000000000..d493e146fe --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/templates/CreateNativeFolders.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.templates; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.core.settings.model.CIncludePathEntry; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICFolderDescription; +import org.eclipse.cdt.core.settings.model.ICLanguageSetting; +import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.templateengine.process.ProcessArgument; +import org.eclipse.cdt.core.templateengine.process.ProcessFailureException; +import org.eclipse.cdt.core.templateengine.process.ProcessRunner; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.internal.core.Configuration; +import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; + +import com.intel.sgx.Activator; +import com.intel.sgx.Messages; +import com.intel.sgx.preferences.PreferenceConstants; + +@SuppressWarnings("restriction") +public class CreateNativeFolders extends ProcessRunner { + + @Override + public void process(TemplateCore template, ProcessArgument[] args, + String processId, IProgressMonitor monitor) + throws ProcessFailureException { + String projectName = null; + String[] sourceFolders = null; + String[] outputFolders = null; + + for (ProcessArgument arg : args) { + String argName = arg.getName(); + if (argName.equals("projectName")) { + projectName = arg.getSimpleValue(); + } else if (argName.equals("sourceFolders")) { + sourceFolders = arg.getSimpleArrayValue(); + } else if (argName.equals("outputFolders")) { + outputFolders = arg.getSimpleArrayValue(); + } + } + + if (projectName == null) + throw new ProcessFailureException( + Messages.CreateNativeFolders_Missing_project_name); + + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + if (!project.exists()) + throw new ProcessFailureException( + Messages.CreateNativeFolders_Project_does_not_exist); + + if (sourceFolders == null && outputFolders == null) + throw new ProcessFailureException( + Messages.CreateNativeFolders_No_folders); + + try { + ICProject cproject = CCorePlugin.getDefault().getCoreModel() + .create(project); + IPathEntry[] pathEntries = cproject.getRawPathEntries(); + List newEntries = new ArrayList( + pathEntries.length); + for (IPathEntry pathEntry : pathEntries) { + if (pathEntry.getEntryKind() != IPathEntry.CDT_SOURCE + && pathEntry.getEntryKind() != IPathEntry.CDT_OUTPUT) { + newEntries.add(pathEntry); + } + } + if (sourceFolders != null) + for (String sourceFolder : sourceFolders) { + IFolder folder = project.getFolder(new Path(sourceFolder)); + if (!folder.exists()) + folder.create(true, true, monitor); + newEntries.add(CoreModel.newSourceEntry(folder + .getFullPath())); + } + if (outputFolders != null) + for (String outputFolder : outputFolders) { + IFolder folder = project.getFolder(new Path(outputFolder)); + if (!folder.exists()) + folder.create(true, true, monitor); + newEntries.add(CoreModel.newOutputEntry(folder + .getFullPath())); + } + cproject.setRawPathEntries( + newEntries.toArray(new IPathEntry[newEntries.size()]), + monitor); + + // IConfiguration[] configs = managedProject.getConfigurations(); + // for(IConfiguration conf:configs){ + // managedProject.removeConfiguration(conf.getId()); + + // } + + IConfiguration conSimDebug = ManagedBuildManager + .getExtensionConfiguration("com.intel.sgx.configuration.Sim.Debug"); + IConfiguration conSimRelease = ManagedBuildManager + .getExtensionConfiguration("com.intel.sgx.configuration.Sim.Release"); + IConfiguration conHwDebug = ManagedBuildManager + .getExtensionConfiguration("com.intel.sgx.configuration.HW.Debug"); + IConfiguration conHwPrerelease = ManagedBuildManager + .getExtensionConfiguration("com.intel.sgx.configuration.HW.Prerelease"); + IConfiguration conHwRelease = ManagedBuildManager + .getExtensionConfiguration("com.intel.sgx.configuration.HW.Release"); + + addConfigurationToProject(project, conSimDebug); + addConfigurationToProject(project, conSimRelease); + addConfigurationToProject(project, conHwDebug); + addConfigurationToProject(project, conHwPrerelease); + addConfigurationToProject(project, conHwRelease); + + + changeProjectConfiguration(project, conSimDebug); + + project.refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e) { + throw new ProcessFailureException(e); + } + } + + void addConfigurationToProject(IProject project, IConfiguration config) { + createConfiguration(project, config); + addSGXIncludePathsToConfiguration(project, config); + } + + private void addSGXIncludePathsToConfiguration(IProject project, + IConfiguration config) { + ICProjectDescription projectDescription = CoreModel.getDefault() + .getProjectDescription(project, true); + ICConfigurationDescription configDecriptions[] = projectDescription + .getConfigurations(); + for (ICConfigurationDescription configDescription : configDecriptions) { + ICFolderDescription projectRoot = configDescription + .getRootFolderDescription(); + + ICLanguageSetting[] settings = projectRoot.getLanguageSettings(); + for (ICLanguageSetting setting : settings) { + + if (!"org.eclipse.cdt.core.gcc".equals(setting.getLanguageId()) && !"org.eclipse.cdt.core.g++".equals(setting.getLanguageId()) ) { + continue; + } + List includes = new ArrayList(); + + includes.add(new CIncludePathEntry( Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.SDK_PATH) + + "/include/", + ICSettingEntry.LOCAL)); + + setting.setSettingEntries(ICSettingEntry.INCLUDE_PATH, includes); + } + } + try { + CoreModel.getDefault().setProjectDescription(project, + projectDescription); + } catch (CoreException e) { + e.printStackTrace(); + } + + } + + private void createConfiguration(IProject project, + IConfiguration config) { + ManagedProject managedProject = (ManagedProject) ManagedBuildManager.getBuildInfo(project) + .getManagedProject();; + + + Configuration cloneConfig1 = (Configuration) config; + Configuration cfg1 = new Configuration(managedProject, cloneConfig1, + cloneConfig1.getId(), false, false); + String target = cfg1.getArtifactName(); + if (target == null || target.length() == 0) + cfg1.setArtifactName(managedProject.getDefaultArtifactName()); + + cfg1.exportArtifactInfo(); + + ManagedBuildManager.saveBuildInfo(project, true); + } + + private void changeProjectConfiguration(IProject project, + IConfiguration conSimDebug) { + ICProjectDescription prjd = CCorePlugin.getDefault() + .getProjectDescriptionManager().getProjectDescription(project); + ICConfigurationDescription[] configs = prjd.getConfigurations(); + if (configs != null && configs.length > 0) { + for (ICConfigurationDescription config : configs) { + if (config.getConfiguration().getId() + .equals(conSimDebug.getId())) { + config.setActive(); + try { + CoreModel.getDefault().setProjectDescription(project, + prjd); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + } + } + } + + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/templates/SetCCNature.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/templates/SetCCNature.java new file mode 100644 index 0000000000..e85476b288 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/templates/SetCCNature.java @@ -0,0 +1,77 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.templates; + +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.templateengine.process.ProcessArgument; +import org.eclipse.cdt.core.templateengine.process.ProcessFailureException; +import org.eclipse.cdt.core.templateengine.process.ProcessRunner; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; + +import com.intel.sgx.Activator; +import com.intel.sgx.natures.SGXNature; + +public class SetCCNature extends ProcessRunner { + + public SetCCNature() { + } + + @Override + public void process(TemplateCore template, ProcessArgument[] args, + String processId, IProgressMonitor monitor) + throws ProcessFailureException { + String projectName = null; + IProject project = null; + + for(ProcessArgument arg: args){ + String argName = arg.getName(); + if(argName.equals("projectName")){ + projectName = arg.getSimpleValue(); + } + } + + + project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + IWorkspace workspace = project.getWorkspace(); + IProjectDescription description; + try { + description = project.getDescription(); + + String[] natures = description.getNatureIds(); + String[] newNatures = new String[natures.length+1]; + System.arraycopy(natures,0,newNatures,0,natures.length); + newNatures[natures.length] = SGXNature.NATURE_ID; + IStatus status = workspace.validateNatureSet(newNatures); + + if(status.getCode() == IStatus.OK) + { + + description.setNatureIds(newNatures); + project.setDescription(description, null); + } + else { + System.err.println("Incorrect Project Nature. Please check Project Settings."); + } + } catch (CoreException e) { + Activator.log(e); + e.printStackTrace(); + } + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/templates/SetStaticCCNature.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/templates/SetStaticCCNature.java new file mode 100644 index 0000000000..449a575262 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/templates/SetStaticCCNature.java @@ -0,0 +1,75 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.templates; + +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.templateengine.process.ProcessArgument; +import org.eclipse.cdt.core.templateengine.process.ProcessFailureException; +import org.eclipse.cdt.core.templateengine.process.ProcessRunner; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; + +import com.intel.sgx.Activator; +import com.intel.sgx.natures.SGXStaticCCNature; + +public class SetStaticCCNature extends ProcessRunner { + + public SetStaticCCNature() { + } + + @Override + public void process(TemplateCore template, ProcessArgument[] args, + String processId, IProgressMonitor monitor) + throws ProcessFailureException { + + String projectName = null; + IProject project = null; + + for(ProcessArgument arg: args){ + String argName = arg.getName(); + if(argName.equals("projectName")){ + projectName = arg.getSimpleValue(); + } + } + + project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + IWorkspace workspace = project.getWorkspace(); + IProjectDescription description; + try { + description = project.getDescription(); + + String[] natures = description.getNatureIds(); + String[] newNatures = new String[natures.length+1]; + System.arraycopy(natures,0,newNatures,0,natures.length); + newNatures[natures.length] = SGXStaticCCNature.NATURE_ID; + IStatus status = workspace.validateNatureSet(newNatures); + + if(status.getCode() == IStatus.OK) + { + description.setNatureIds(newNatures); + project.setDescription(description, null); + } + else + System.err.println("Incorrect Project Nature. Please check Project Settings."); + } catch (CoreException e) { + Activator.log(e); + e.printStackTrace(); + } + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/testers/SGXPropertyTester.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/testers/SGXPropertyTester.java new file mode 100644 index 0000000000..1b876c79c6 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/testers/SGXPropertyTester.java @@ -0,0 +1,79 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.testers; + +import java.util.regex.Pattern; + +import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.jface.viewers.StructuredSelection; + +public class SGXPropertyTester extends PropertyTester { + + private static final Pattern isRelease = Pattern.compile(".*Release.*"); + private static final Pattern isHW = Pattern.compile(".*Hardware.*"); + private static final Pattern isPreRelease = Pattern.compile(".*Prerelease.*");; + + public SGXPropertyTester() { + super(); + + // TODO Auto-generated constructor stub + } + + @Override + public boolean test(Object receiver, String property, Object[] args, + Object expectedValue) { + + + + + + if (property.equals("twoStepsActive")) { + IProject project = getProjectOfSelectedItem(receiver); + IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(project); + return isHW(buildInfo) && isRelease(buildInfo) && !isPreRelease(buildInfo); + + } else if (property.equals("sgxNatureAdded")) { + IProject project = getProjectOfSelectedItem(receiver); + return true; + } else { + return false; + } + } + + private IProject getProjectOfSelectedItem(Object receiver) { + StructuredSelection selection = (StructuredSelection) receiver; + IResource resource = (IResource) selection.getFirstElement(); + IProject project = resource.getProject(); + return project; + } + + boolean isHW(IManagedBuildInfo buildInfo){ + return isHW.matcher(buildInfo.getConfigurationName()).matches(); + } + + + + boolean isRelease(IManagedBuildInfo buildInfo){ + return isRelease.matcher(buildInfo.getConfigurationName()).matches(); + } + + boolean isPreRelease(IManagedBuildInfo buildInfo){ + return isPreRelease.matcher(buildInfo.getConfigurationName()).matches(); + } + +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/wizards/SGXCCProjectWizard.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/wizards/SGXCCProjectWizard.java new file mode 100644 index 0000000000..be6ec1e51b --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/wizards/SGXCCProjectWizard.java @@ -0,0 +1,145 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.wizards; + +import java.net.URI; +import java.util.Map; + +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.templateengine.TemplateEngine; +import org.eclipse.cdt.ui.wizards.CCProjectWizard; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; + +import com.intel.sgx.natures.SGXNature; + +public class SGXCCProjectWizard extends CCProjectWizard { + + private IProject project; + + @Override + protected boolean setCreated() throws CoreException { + boolean result = super.setCreated(); + doIt(project, new NullProgressMonitor()); + return result; + } + + @Override + public boolean performFinish() { + + return super.performFinish(); + } + + @Override + public void setInitializationData(IConfigurationElement config, + String propertyName, Object data) throws CoreException { + // TODO Auto-generated method stub + super.setInitializationData(config, propertyName, data); + } + + @Override + public IProject createIProject(String name, URI location) + throws CoreException { + // TODO Auto-generated method stub + return super.createIProject(name, location); + + } + + @Override + public IProject createIProject(String name, URI location, + IProgressMonitor monitor) throws CoreException { + project = super.createIProject(name, location, monitor); + return project; + } + + @Override + public String[] getExtensions() { + // TODO Auto-generated method stub + return super.getExtensions(); + } + + public SGXCCProjectWizard() { + // TODO Auto-generated constructor stub + } + + @Override + public String[] getNatures() { + // TODO Auto-generated method stub + return super.getNatures(); + } + + @Override + protected IProject continueCreation(IProject prj) { + // TODO Auto-generated method stub + return super.continueCreation(prj); + } + + @Override + public String[] getContentTypeIDs() { + // TODO Auto-generated method stub + return super.getContentTypeIDs(); + } + + @Override + public IProject getProject(boolean defaults) { + // TODO Auto-generated method stub + return super.getProject(defaults); + } + + @Override + public String[] getLanguageIDs() { + // TODO Auto-generated method stub + return super.getLanguageIDs(); + } + + void doIt(IProject project, IProgressMonitor monitor) throws CoreException { + TemplateCore template = TemplateEngine.getDefault().getTemplateById( + "AddSGXNature"); + Map valueStore = template.getValueStore(); + valueStore.put("projectName", project.getName()); + valueStore.put("baseName", project.getName()); + template.executeTemplateProcesses(monitor, false); + + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IProjectDescription description = project.getDescription(); + String[] natures = description.getNatureIds(); + + String[] newNatures = new String[natures.length + 1]; + System.arraycopy(natures, 0, newNatures, 0, natures.length); + newNatures[natures.length] = SGXNature.NATURE_ID; + IStatus status = workspace.validateNatureSet(newNatures); + + if (status.getCode() == IStatus.OK) { + description.setNatureIds(newNatures); + project.setDescription(description, null); + } else { + System.err + .println("Incorrect Project Nature. Please check Project Settings.");// TODO + // throw + // an + // exception + // here. + System.err.println("Status is: " + status.getCode()); + } + + // project.refreshLocal(IResource.DEPTH_ONE,null); + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/wizards/SGXCProjectWizard.java b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/wizards/SGXCProjectWizard.java new file mode 100644 index 0000000000..14ec8f8284 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/src/com/intel/sgx/wizards/SGXCProjectWizard.java @@ -0,0 +1,146 @@ +/////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2016 Intel Corporation. // +// // +// All rights reserved. This program and the accompanying materials // +// are made available under the terms of the Eclipse Public License v1.0 // +// which accompanies this distribution, and is available at // +// http://www.eclipse.org/legal/epl-v10.html // +// // +// Contributors: // +// Intel Corporation - initial implementation and documentation // +/////////////////////////////////////////////////////////////////////////// + + +package com.intel.sgx.wizards; + +import java.net.URI; +import java.util.Map; + +import org.eclipse.cdt.core.templateengine.TemplateCore; +import org.eclipse.cdt.core.templateengine.TemplateEngine; +import org.eclipse.cdt.ui.wizards.CProjectWizard; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; + +import com.intel.sgx.natures.SGXNature; + +public class SGXCProjectWizard extends CProjectWizard { + + private IProject project; + + @Override + protected boolean setCreated() throws CoreException { + boolean result = super.setCreated(); + doIt(project, new NullProgressMonitor()); + return result; + } + + @Override + public boolean performFinish() { + + return super.performFinish(); + } + + @Override + public void setInitializationData(IConfigurationElement config, + String propertyName, Object data) throws CoreException { + // TODO Auto-generated method stub + super.setInitializationData(config, propertyName, data); + } + + @Override + public IProject createIProject(String name, URI location) + throws CoreException { + // TODO Auto-generated method stub + return super.createIProject(name, location); + + } + + @Override + public IProject createIProject(String name, URI location, + IProgressMonitor monitor) throws CoreException { + project = super.createIProject(name, location, monitor); + return project; + } + + @Override + public String[] getExtensions() { + // TODO Auto-generated method stub + return super.getExtensions(); + } + + public SGXCProjectWizard() { + // TODO Auto-generated constructor stub + } + + @Override + public String[] getNatures() { + // TODO Auto-generated method stub + return super.getNatures(); + } + + @Override + protected IProject continueCreation(IProject prj) { + // TODO Auto-generated method stub + return super.continueCreation(prj); + } + + @Override + public String[] getContentTypeIDs() { + // TODO Auto-generated method stub + return super.getContentTypeIDs(); + } + + @Override + public IProject getProject(boolean defaults) { + // TODO Auto-generated method stub + return super.getProject(defaults); + } + + @Override + public String[] getLanguageIDs() { + // TODO Auto-generated method stub + return super.getLanguageIDs(); + } + + void doIt(IProject project, IProgressMonitor monitor) throws CoreException { + TemplateCore template = TemplateEngine.getDefault().getTemplateById( + "AddSGXNature"); + Map valueStore = template.getValueStore(); + valueStore.put("projectName", project.getName()); + valueStore.put("baseName", project.getName()); + template.executeTemplateProcesses(monitor, false); + + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IProjectDescription description = project.getDescription(); + String[] natures = description.getNatureIds(); + for (String nature : natures) { + } + + String[] newNatures = new String[natures.length + 1]; + System.arraycopy(natures, 0, newNatures, 0, natures.length); + newNatures[natures.length] = SGXNature.NATURE_ID; + IStatus status = workspace.validateNatureSet(newNatures); + + if (status.getCode() == IStatus.OK) { + description.setNatureIds(newNatures); + project.setDescription(description, null); + } else { + System.err + .println("Incorrect Project Nature. Please check Project Settings.");// TODO + // throw + // an + // exception + // here. + System.err.println("Status is: " + status.getCode()); + } + + } +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGX.gif b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGX.gif new file mode 100644 index 0000000000..21156bbf96 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGX.gif differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c++/minimal/enclavetemplate.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c++/minimal/enclavetemplate.xml new file mode 100644 index 0000000000..40d4b6b13a --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c++/minimal/enclavetemplate.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c++/minimal/trustedstatictemplate.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c++/minimal/trustedstatictemplate.xml new file mode 100644 index 0000000000..7b8649b17c --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c++/minimal/trustedstatictemplate.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c++/minimal/untrusted_module_template.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c++/minimal/untrusted_module_template.xml new file mode 100644 index 0000000000..537100987e --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c++/minimal/untrusted_module_template.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c++/with_sample/enclavetemplate.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c++/with_sample/enclavetemplate.xml new file mode 100644 index 0000000000..7d9527dafb --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c++/with_sample/enclavetemplate.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c/minimal/enclavetemplate.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c/minimal/enclavetemplate.xml new file mode 100644 index 0000000000..c32e20347a --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c/minimal/enclavetemplate.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c/minimal/trustedstatictemplate.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c/minimal/trustedstatictemplate.xml new file mode 100644 index 0000000000..6fc320cbba --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c/minimal/trustedstatictemplate.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c/minimal/untrusted_module_template.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c/minimal/untrusted_module_template.xml new file mode 100644 index 0000000000..b8aec6e666 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c/minimal/untrusted_module_template.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c/with_sample/enclavetemplate.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c/with_sample/enclavetemplate.xml new file mode 100644 index 0000000000..66344d6636 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/c/with_sample/enclavetemplate.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/common/addnaturetemplate.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/common/addnaturetemplate.xml new file mode 100644 index 0000000000..9cf5663e3c --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/common/addnaturetemplate.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/configtemplate.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/configtemplate.xml new file mode 100644 index 0000000000..7ce22c45e3 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/configtemplate.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/ctemplate.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/ctemplate.xml new file mode 100644 index 0000000000..ed5cbba697 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/ctemplate.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/cxxstaticlibtemplate.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/cxxstaticlibtemplate.xml new file mode 100644 index 0000000000..8ad900de61 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/cxxstaticlibtemplate.xml @@ -0,0 +1,109 @@ + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/cxxtemplate.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/cxxtemplate.xml new file mode 100644 index 0000000000..a07ed1479c --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/cxxtemplate.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/template.properties b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/template.properties new file mode 100644 index 0000000000..9ef4fcdf31 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/SGXtemplates/template.properties @@ -0,0 +1,63 @@ +######################################################################### +# Copyright (c) 2016 Intel Corporation. # +# # +# All rights reserved. This program and the accompanying materials # +# are made available under the terms of the Eclipse Public License v1.0 # +# which accompanies this distribution, and is available at # +# http://www.eclipse.org/legal/epl-v10.html # +# # +# Contributors: # +# Intel Corporation - initial implementation and documentation # +######################################################################### + SGX.author=Intel + + #Add Nature template Values + SGX.naturetemplate.title.description=A Software Guard Extensions Project template. + SGX.naturetemplate.title.label=SGX Project + SGX.naturetemplate.title.id=AddSGXNature + + #Enclave Config template Values + SGX.enclaveconfig.template.title.description=A Software Guard Extensions Configuration template. + SGX.enclaveconfig.template.title.label=SGX Enclave Configuration + SGX.enclaveconfig.template.title.id=SGXEnclaveConfig + + #Untrusted Module template values + SGX.untrustedModule.template.title.description= A Software Guard Extensions Untrusted Module template. + SGX.untrustedModule.template.title.label=SGX Untrusted Module + + #Enclave template values + SGX.enclave.template.title.description= A Software Guard Extensions Project template. + SGX.enclave.template.title.label=SGX Project + SGX.enclave.template.title.id=SGXProject + + #C template Values + SGX.Ctemplate.title.description=A Software Guard Extensions C Enclave Project template. + SGX.Ctemplate.title.label=SGX C Enclave Project + SGX.Ctemplate.title.id=SGXCProject + SGX.Ctemplate.enclaveSettings.label=Enclave Settings + SGX.Ctemplate.enclaveSettings.description=Initial settings required for a new enclave. + + #C Static lib template Values + SGX.CStatictemplate.title.description=A Software Guard Extensions C Enclave Project template. + SGX.CStatictemplate.title.label=SGX C Enclave Library Project + SGX.CStatictemplate.title.id=SGXCEnclaveLibProject + SGX.CStatictemplate.enclaveSettings.label=Enclave Settings + SGX.CStatictemplate.enclaveSettings.description=Initial settings required for a new enclave Library. + SGX.CStatictemplate.requiresEdl.label=Requires EDL + SGX.CStatictemplate.requiresEdl.description=De-select this option to create an Non-SGX trusted static library without an Edl file. By default, the project creates an Enclave library with an Edl file. + + #CXX template Values + SGX.CXXtemplate.title.description=A Software Guard Extensions C++ Enclave Project template. + SGX.CXXtemplate.title.label=C/C++ Project with SGX Nature + SGX.CXXtemplate.title.id=SGXCPPProject + SGX.CXXtemplate.enclaveSettings.label=Enclave Settings + SGX.CXXtemplate.enclaveSettings.description=Initial settings required for a new enclave. + + #CXX Static lib template Values + SGX.CXXStatictemplate.title.description=A Software Guard Extensions C++ Enclave Library Project template. + SGX.CXXStatictemplate.title.label=SGX C++ Enclave Library Project + SGX.CXXStatictemplate.title.id=SGXCPPEnclaveLibProject + SGX.CXXStatictemplate.enclaveSettings.label=Enclave Settings + SGX.CXXStatictemplate.enclaveSettings.description=Initial settings required for a new enclave Library. + SGX.CXXStatictemplate.requiresEdl.label=Requires EDL + SGX.CXXStatictemplate.requiresEdl.description=De-select this option to create an Non-SGX trusted static library without an Edl file. By default, the project creates an Enclave library with an Edl file. diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/newmngc_app.gif b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/newmngc_app.gif new file mode 100644 index 0000000000..23b0284f84 Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/newmngc_app.gif differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/newmngcc_app.gif b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/newmngcc_app.gif new file mode 100644 index 0000000000..4b39411daf Binary files /dev/null and b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/newmngcc_app.gif differ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/resources/Basename.config.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/resources/Basename.config.xml new file mode 100644 index 0000000000..6210afff28 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/resources/Basename.config.xml @@ -0,0 +1,9 @@ + + $(ProdID) + $(IsvSvn) + $(ThreadStackSize) + $(GlobalHeapSize) + $(TcsNumber) + $(TcsPolicy) + $(DisableDebug) + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/resources/Basename_private.pem b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/resources/Basename_private.pem new file mode 100644 index 0000000000..790839d391 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/resources/Basename_private.pem @@ -0,0 +1,39 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIG4wIBAAKCAYEA8DLzZJpN7sN5J1PtKZAqWFeW+0/pPJVWRKEB8lfqXGJ0YIjG +1o0g0/+60ktlm0vVdWSqepmpRpTB2ZZjxxc+JHfZGQnvmlGx6qQxSFS9u+S8mSzD +MknsquLVsi7rojq34dTwSckMg0KQ/sGmsV6EgsUnldhdcPOJ8+NaaqtmAmjHYIpK +jLo3pJz0e7NqKvzE2YhmZZjrIZBNFHxX/lrQ36lW6Obp8xj9CqUMZp+2+/ntdFSl +7u9BK5y3ZHh8hUx6PkHfV8f1h9iG1jroINrrQwhftKmcsg/DPG7NOnjK/EvFaBku +6p0pnmeJM6VUihaLWYNAAjylVmMysenAjl4jsSzQeIe5idoPzYonCuAcASj8utgz +4OxxMHFYAXzgc2An6jp700NOgmYdhtoTMCUjohyd+RHJoSNJpE+ocKPVM72xucJB +o8dK55kI2/E19EVm59UyhXs2YGIjswziMK94H9KSl+TRthny7wYKju09lbdQAGid +rZcYTv2LVYP1Q5IDAgEDAoIBgQCgIfeYZt6fLPtvjUjGYBw65Q9SNUYoY47Ya1ah +j/GS7E2VsISPCMCNVSc23O5nh+OjmHGnERuEYyvmZEKEuiltpTtmBp+8NnacbXYw +OH59QyhmHdd22/MclzkhdJ0W0c/r40rb212s1wtUgRnLlFhXLhpj5ZOgolv37Obx +x5lW8ITrBtxd0XptvfhSd5wcqIM7sERDu0drtYi4UuVUPIs/xjnwmfFMu1NcbghE +ann9UUj4OG6fSityaHpC+v2uMvrexpJP3csYY/VbrYdzlp9GLHkm9mM3Y1tSYoU4 +GhsLstDSHIOZ5f2trh+Re6759SktXi+E9B4xQvJwwVAufmfU0aVESHtJDllt+UOK +LfINb3SmXX8uINqAlees+xJDm/ZcA8vvWWioD8Hv6c47qzrYH1JwvTJtk3G3orFs +syZe7KYwUUBxTREmTCdWoeHC9Hou4MxgiyViPl5SbIUz4yqJgcr3gPtoSRhwvY3v +r1GyeyRuB0CsAun5TQCcx31XwssCgcEA/hK8i1nKvEaTJ5GX9bGZo7BtjWftuGfa +qk0b4aZLWBeoJpGgivolaloTYE+aBAhPMFNKo9HT357o9SW48yk0kyReywJj6HBf +b82TSjt9wXmeo+6cE7EO7k1sINoJnlRiDkWqdpZLzty24dWMN27oXjO2ELUmAgnT +M8rzcshlhRsp/OSD+kIyEfVstx3H3hzPDMyHsNnlPv0Jycdp+1YfANLOaog+JHUZ +Kwb90RF2ePXnLbt2ts0N03kuJKgqS6xbAoHBAPIFR1Sheib8A6UlBP3HYrYVPGzQ +GiaS35aN6YSrVxKn5AZcyPjKB6+IRnkcNA8efmUirhb8pCzf3hOiD1V3U17N+ccY +nLPUKjjGrnFfsyuILx1dWQgKGoFDEF0qO2+h1FHvH3Wm5bdxw70l0Z81Yv+57D9A +1/q8S90QqtrOtiA/jnRj3P+RfxwxYSLgm3G54JS3eEPQmQ4HjG2isGeEmVC9E7ob +GnU3NRrit9ZUzJEIsi2iRfTFq4WQ3EWwjvRBeQKBwQCpYdMHkTHS2bdvtmVOdmZt +IEkI7/PQRTxxiL1BGYeQD8VvC8BcpsOcPAzq37wCsDTK4jHCi+KVFJtOGSX3cM23 +bZSHVu1FoD+f3mIxfP6A+78X9GgNILSe3kgV5rEUOEFe2RxPDt00kySWjl16SfA+ +zSQLI26sBozNMfeh2u5YvMaomFf8LCFhTkh6E9qUEzSzMwUgkUN/U1vb2kanjr9V +4d7xsClto2Ycr1Pgtk77TpoefPnPM16M+3QYcBwycucCgcEAoVjaOGumxKgCbhit +/oTseWN9neARbwyVDwlGWHI6DG/tWZMwpdwFH7Au+2gitL7+7hceuf3CyJU+t8Ff +jk+M6d6mhLsTIo1xey8e9j/Mx7AfaOjmBVwRq4IK6MbSSmvi4UoU+RnuekvX026L +v3jsqnvy1NXlUdLdPgsckd8kFX+0TZfoqmD/aCDrbJW89nvrDc+lgosQtAUISRcg +RQMQ4H4NJry8TiTOEex6juMzC1shc8GD+IPHrmCS2SBfTYD7AoHAOYqsSbLvkhWP +JCx3wicFIY4y+eJW2hNK19ho+PEcrmu7+HKZHMU7oslsoSnme5mMomK9pZnY8KSy +px0D13XyUmEmZluxKcdUDC6mRWH4qkPt/9DGbzHwNLfla+KbxoNLi7F6U5XU5J/6 +NzZeO9HrLzHy1ck/0xUDU7Y+WWniMbUdlOpXSd+SsZtKomRhnc+QljYqSJplJL7f +mfnQ4stcY3RcPHGwfDOQT9sVk0hoIGXKCzEl217Iw1P8UwKvBbNe +-----END RSA PRIVATE KEY----- diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c++/sgx_t.mk b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c++/sgx_t.mk new file mode 100644 index 0000000000..41aaf26fa4 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c++/sgx_t.mk @@ -0,0 +1,127 @@ +######## SGX SDK Settings ######## +SGX_SDK ?= $(SdkPathFromPlugin) +SGX_MODE ?= SIM +SGX_ARCH ?= x64 + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +ifneq ($(SGX_MODE), HW) + Trts_Library_Name := sgx_trts_sim + Service_Library_Name := sgx_tservice_sim +else + Trts_Library_Name := sgx_trts + Service_Library_Name := sgx_tservice +endif + +Crypto_Library_Name := sgx_tcrypto + +$(EnclaveName)_Cpp_Files := trusted/$(enclaveName).cpp +$(EnclaveName)_C_Files := +$(EnclaveName)_Include_Paths := -IInclude -Itrusted -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport + + +Flags_Just_For_C := -Wno-implicit-function-declaration -std=c11 +Common_C_Cpp_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $($(EnclaveName)_Include_Paths) -fno-builtin-printf -I. +$(EnclaveName)_C_Flags := $(Flags_Just_For_C) $(Common_C_Cpp_Flags) +$(EnclaveName)_Cpp_Flags := $(Common_C_Cpp_Flags) -std=c++11 -nostdinc++ -fno-builtin-printf -I. + +$(EnclaveName)_Cpp_Flags := $($(EnclaveName)_Cpp_Flags) -fno-builtin-printf + +$(EnclaveName)_Link_Flags := $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \ + -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive \ + -Wl,--start-group -lsgx_tstdc -lsgx_tstdcxx -l$(Crypto_Library_Name) -l$(Service_Library_Name) -Wl,--end-group \ + -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \ + -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \ + -Wl,--defsym,__ImageBase=0 \ + -Wl,--version-script=trusted/$(enclaveName).lds + +$(EnclaveName)_Cpp_Objects := $($(EnclaveName)_Cpp_Files:.cpp=.o) +$(EnclaveName)_C_Objects := $($(EnclaveName)_C_Files:.c=.o) + +ifeq ($(SGX_MODE), HW) +ifneq ($(SGX_DEBUG), 1) +ifneq ($(SGX_PRERELEASE), 1) +Build_Mode = HW_RELEASE +endif +endif +endif + + +.PHONY: all run + +ifeq ($(Build_Mode), HW_RELEASE) +all: $(enclaveName).so + @echo "Build enclave $(enclaveName).so [$(Build_Mode)|$(SGX_ARCH)] success!" + @echo + @echo "*********************************************************************************************************************************************************" + @echo "PLEASE NOTE: In this mode, please sign the $(enclaveName).so first using Two Step Sign mechanism before you run the app to launch and access the enclave." + @echo "*********************************************************************************************************************************************************" + @echo + + +else +all: $(enclaveName).signed.so +endif + +run: all +ifneq ($(Build_Mode), HW_RELEASE) + @$(CURDIR)/app + @echo "RUN => app [$(SGX_MODE)|$(SGX_ARCH), OK]" +endif + + +######## $(enclaveName) Objects ######## + +trusted/$(enclaveName)_t.c: $(SGX_EDGER8R) ./trusted/$(enclaveName).edl + @cd ./trusted && $(SGX_EDGER8R) --trusted ../trusted/$(enclaveName).edl --search-path ../trusted --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +trusted/$(enclaveName)_t.o: ./trusted/$(enclaveName)_t.c + @$(CC) $($(EnclaveName)_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +trusted/%.o: trusted/%.cpp + @$(CXX) $($(EnclaveName)_Cpp_Flags) -c $< -o $@ + @echo "CXX <= $<" + +trusted/%.o: trusted/%.c + @$(CC) $($(EnclaveName)_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +$(enclaveName).so: trusted/$(enclaveName)_t.o $($(EnclaveName)_Cpp_Objects) $($(EnclaveName)_C_Objects) + @$(CXX) $^ -o $@ $($(EnclaveName)_Link_Flags) + @echo "LINK => $@" + +$(enclaveName).signed.so: $(enclaveName).so + @$(SGX_ENCLAVE_SIGNER) sign -key trusted/$(enclaveName)_private.pem -enclave $(enclaveName).so -out $@ -config trusted/$(enclaveName).config.xml + @echo "SIGN => $@" +clean: + @rm -f $(enclaveName).* trusted/$(enclaveName)_t.* $($(EnclaveName)_Cpp_Objects) $($(EnclaveName)_C_Objects) diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c++/sgx_u.mk b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c++/sgx_u.mk new file mode 100644 index 0000000000..201963cb07 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c++/sgx_u.mk @@ -0,0 +1,129 @@ +######## SGX SDK Settings ######## +SGX_SDK ?= $(SdkPathFromPlugin) +SGX_MODE ?= SIM +SGX_ARCH ?= x64 +UNTRUSTED_DIR=untrusted + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +######## App Settings ######## + +ifneq ($(SGX_MODE), HW) + Urts_Library_Name := sgx_urts_sim +else + Urts_Library_Name := sgx_urts +endif + +# App_Cpp_Files := App/App.cpp $(wildcard App/Edger8rSyntax/*.cpp) $(wildcard App/TrustedLibrary/*.cpp) +App_Cpp_Files := $(UNTRUSTED_DIR)/sample.cpp # $(wildcard App/TrustedLibrary/*.cpp) +App_Include_Paths := -IInclude -I$(UNTRUSTED_DIR) -I$(SGX_SDK)/include + +App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) + +# Three configuration modes - Debug, prerelease, release +# Debug - Macro DEBUG enabled. +# Prerelease - Macro NDEBUG and EDEBUG enabled. +# Release - Macro NDEBUG enabled. +ifeq ($(SGX_DEBUG), 1) + App_C_Flags += -DDEBUG -UNDEBUG -UEDEBUG +else ifeq ($(SGX_PRERELEASE), 1) + App_C_Flags += -DNDEBUG -DEDEBUG -UDEBUG +else + App_C_Flags += -DNDEBUG -UEDEBUG -UDEBUG +endif + +App_Cpp_Flags := $(App_C_Flags) -std=c++11 +App_Link_Flags := $(SGX_COMMON_CFLAGS) -L$(SGX_LIBRARY_PATH) -l$(Urts_Library_Name) -lpthread + +ifneq ($(SGX_MODE), HW) + App_Link_Flags += -lsgx_uae_service_sim +else + App_Link_Flags += -lsgx_uae_service +endif + +App_Cpp_Objects := $(App_Cpp_Files:.cpp=.o) + + + +ifeq ($(SGX_MODE), HW) +ifneq ($(SGX_DEBUG), 1) +ifneq ($(SGX_PRERELEASE), 1) +Build_Mode = HW_RELEASE +endif +endif +endif + + +.PHONY: all run + +ifeq ($(Build_Mode), HW_RELEASE) +all: sample + @echo "Build sample [$(Build_Mode)|$(SGX_ARCH)] success!" + @echo + @echo "*********************************************************************************************************************************************************" + @echo "PLEASE NOTE: In this mode, please sign the $(enclaveName).so first using Two Step Sign mechanism before you run the app to launch and access the enclave." + @echo "*********************************************************************************************************************************************************" + @echo + + +else +all: sample +endif + +run: all +ifneq ($(Build_Mode), HW_RELEASE) + @$(CURDIR)/sample + @echo "RUN => sample [$(SGX_MODE)|$(SGX_ARCH), OK]" +endif + +######## App Objects ######## + +$(UNTRUSTED_DIR)/$(enclaveName)_u.c: $(SGX_EDGER8R) trusted/$(enclaveName).edl + @cd $(UNTRUSTED_DIR) && $(SGX_EDGER8R) --untrusted ../trusted/$(enclaveName).edl --search-path ../trusted --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +$(UNTRUSTED_DIR)/$(enclaveName)_u.o: $(UNTRUSTED_DIR)/$(enclaveName)_u.c + @$(CC) $(App_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +$(UNTRUSTED_DIR)/%.o: $(UNTRUSTED_DIR)/%.cpp + @$(CXX) $(App_Cpp_Flags) -c $< -o $@ + @echo "CXX <= $<" + +sample: $(UNTRUSTED_DIR)/$(enclaveName)_u.o $(App_Cpp_Objects) + @$(CXX) $^ -o $@ $(App_Link_Flags) + @echo "LINK => $@" + + +.PHONY: clean + +clean: + @rm -f sample $(App_Cpp_Objects) $(UNTRUSTED_DIR)/$(enclaveName)_u.* diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c++/sgx_u.without_app.mk b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c++/sgx_u.without_app.mk new file mode 100644 index 0000000000..00aed4b876 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c++/sgx_u.without_app.mk @@ -0,0 +1,71 @@ +######## SGX SDK Settings ######## +SGX_SDK ?= $(SdkPathFromPlugin) +SGX_MODE ?= SIM +SGX_ARCH ?= x64 +UNTRUSTED_DIR=untrusted + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +######## App Settings ######## + +App_Include_Paths := -IInclude -I$(UNTRUSTED_DIR) -I$(SGX_SDK)/include + +App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) + +# Three configuration modes - Debug, prerelease, release +# Debug - Macro DEBUG enabled. +# Prerelease - Macro NDEBUG and EDEBUG enabled. +# Release - Macro NDEBUG enabled. +ifeq ($(SGX_DEBUG), 1) + App_C_Flags += -DDEBUG -UNDEBUG -UEDEBUG +else ifeq ($(SGX_PRERELEASE), 1) + App_C_Flags += -DNDEBUG -DEDEBUG -UDEBUG +else + App_C_Flags += -DNDEBUG -UEDEBUG -UDEBUG +endif + +App_Cpp_Flags := $(App_C_Flags) -std=c++11 + +.PHONY: all run + +all: $(UNTRUSTED_DIR)/$(enclaveName)_u.o + +######## App Objects ######## + +$(UNTRUSTED_DIR)/$(enclaveName)_u.c: $(SGX_EDGER8R) trusted/$(enclaveName).edl + @mkdir -p $(UNTRUSTED_DIR) + @cd $(UNTRUSTED_DIR) && $(SGX_EDGER8R) --untrusted ../trusted/$(enclaveName).edl --search-path ../trusted --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +$(UNTRUSTED_DIR)/$(enclaveName)_u.o: $(UNTRUSTED_DIR)/$(enclaveName)_u.c + @$(CC) $(App_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +.PHONY: clean + +clean: + @rm -f $(UNTRUSTED_DIR)/$(enclaveName)_u.* diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c/sgx_t.mk b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c/sgx_t.mk new file mode 100644 index 0000000000..3851c1de3b --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c/sgx_t.mk @@ -0,0 +1,115 @@ +######## SGX SDK Settings ######## +SGX_SDK ?= $(SdkPathFromPlugin) +SGX_MODE ?= SIM +SGX_ARCH ?= x64 + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +ifneq ($(SGX_MODE), HW) + Trts_Library_Name := sgx_trts_sim + Service_Library_Name := sgx_tservice_sim +else + Trts_Library_Name := sgx_trts + Service_Library_Name := sgx_tservice +endif + +Crypto_Library_Name := sgx_tcrypto + +$(EnclaveName)_C_Files := trusted/$(enclaveName).c +$(EnclaveName)_Include_Paths := -IInclude -Itrusted -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport + +Flags_Just_For_C := -Wno-implicit-function-declaration -std=c11 +Common_C_Cpp_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $($(EnclaveName)_Include_Paths) -fno-builtin-printf -I. +$(EnclaveName)_C_Flags := $(Flags_Just_For_C) $(Common_C_Cpp_Flags) + +$(EnclaveName)_Link_Flags := $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \ + -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive \ + -Wl,--start-group -lsgx_tstdc -lsgx_tstdcxx -l$(Crypto_Library_Name) -l$(Service_Library_Name) -Wl,--end-group \ + -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \ + -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \ + -Wl,--defsym,__ImageBase=0 \ + -Wl,--version-script=trusted/$(enclaveName).lds + +$(EnclaveName)_C_Objects := $($(EnclaveName)_C_Files:.c=.o) + +ifeq ($(SGX_MODE), HW) +ifneq ($(SGX_DEBUG), 1) +ifneq ($(SGX_PRERELEASE), 1) +Build_Mode = HW_RELEASE +endif +endif +endif + + +.PHONY: all run + +ifeq ($(Build_Mode), HW_RELEASE) +all: $(enclaveName).so + @echo "Build enclave $(enclaveName).so [$(Build_Mode)|$(SGX_ARCH)] success!" + @echo + @echo "*********************************************************************************************************************************************************" + @echo "PLEASE NOTE: In this mode, please sign the $(enclaveName).so first using Two Step Sign mechanism before you run the app to launch and access the enclave." + @echo "*********************************************************************************************************************************************************" + @echo +else +all: $(enclaveName).signed.so +endif + +run: all +ifneq ($(Build_Mode), HW_RELEASE) + @$(CURDIR)/app + @echo "RUN => app [$(SGX_MODE)|$(SGX_ARCH), OK]" +endif + + +######## $(enclaveName) Objects ######## + +trusted/$(enclaveName)_t.c: $(SGX_EDGER8R) ./trusted/$(enclaveName).edl + @cd ./trusted && $(SGX_EDGER8R) --trusted ../trusted/$(enclaveName).edl --search-path ../trusted --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +trusted/$(enclaveName)_t.o: ./trusted/$(enclaveName)_t.c + @$(CC) $($(EnclaveName)_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +trusted/%.o: trusted/%.c + @$(CC) $($(EnclaveName)_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +$(enclaveName).so: trusted/$(enclaveName)_t.o $($(EnclaveName)_C_Objects) + @$(CXX) $^ -o $@ $($(EnclaveName)_Link_Flags) + @echo "LINK => $@" + +$(enclaveName).signed.so: $(enclaveName).so + @$(SGX_ENCLAVE_SIGNER) sign -key trusted/$(enclaveName)_private.pem -enclave $(enclaveName).so -out $@ -config trusted/$(enclaveName).config.xml + @echo "SIGN => $@" +clean: + @rm -f $(enclaveName).* trusted/$(enclaveName)_t.* $($(EnclaveName)_C_Objects) diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c/sgx_u.mk b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c/sgx_u.mk new file mode 100644 index 0000000000..70d293e363 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c/sgx_u.mk @@ -0,0 +1,126 @@ +######## SGX SDK Settings ######## +SGX_SDK ?= $(SdkPathFromPlugin) +SGX_MODE ?= SIM +SGX_ARCH ?= x64 +UNTRUSTED_DIR=untrusted + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +######## App Settings ######## + +ifneq ($(SGX_MODE), HW) + Urts_Library_Name := sgx_urts_sim +else + Urts_Library_Name := sgx_urts +endif + +App_C_Files := $(UNTRUSTED_DIR)/sample.c +App_Include_Paths := -IInclude -I$(UNTRUSTED_DIR) -I$(SGX_SDK)/include + +App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) + +# Three configuration modes - Debug, prerelease, release +# Debug - Macro DEBUG enabled. +# Prerelease - Macro NDEBUG and EDEBUG enabled. +# Release - Macro NDEBUG enabled. +ifeq ($(SGX_DEBUG), 1) + App_C_Flags += -DDEBUG -UNDEBUG -UEDEBUG +else ifeq ($(SGX_PRERELEASE), 1) + App_C_Flags += -DNDEBUG -DEDEBUG -UDEBUG +else + App_C_Flags += -DNDEBUG -UEDEBUG -UDEBUG +endif + +App_Link_Flags := $(SGX_COMMON_CFLAGS) -L$(SGX_LIBRARY_PATH) -l$(Urts_Library_Name) -lpthread + +ifneq ($(SGX_MODE), HW) + App_Link_Flags += -lsgx_uae_service_sim +else + App_Link_Flags += -lsgx_uae_service +endif + +App_C_Objects := $(App_C_Files:.c=.o) + + + +ifeq ($(SGX_MODE), HW) +ifneq ($(SGX_DEBUG), 1) +ifneq ($(SGX_PRERELEASE), 1) +Build_Mode = HW_RELEASE +endif +endif +endif + + +.PHONY: all run + +ifeq ($(Build_Mode), HW_RELEASE) +all: sample + @echo "Build sample [$(Build_Mode)|$(SGX_ARCH)] success!" + @echo + @echo "*********************************************************************************************************************************************************" + @echo "PLEASE NOTE: In this mode, please sign the $(enclaveName).so first using Two Step Sign mechanism before you run the app to launch and access the enclave." + @echo "*********************************************************************************************************************************************************" + @echo + +else +all: sample +endif + +run: all +ifneq ($(Build_Mode), HW_RELEASE) + @$(CURDIR)/sample + @echo "RUN => sample [$(SGX_MODE)|$(SGX_ARCH), OK]" +endif + +######## App Objects ######## + +$(UNTRUSTED_DIR)/$(enclaveName)_u.c: $(SGX_EDGER8R) trusted/$(enclaveName).edl + @cd $(UNTRUSTED_DIR) && $(SGX_EDGER8R) --untrusted ../trusted/$(enclaveName).edl --search-path ../trusted --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +$(UNTRUSTED_DIR)/$(enclaveName)_u.o: $(UNTRUSTED_DIR)/$(enclaveName)_u.c + @$(CC) $(App_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +$(UNTRUSTED_DIR)/%.o: $(UNTRUSTED_DIR)/%.c + @$(CXX) $(App_C_Flags) -c $< -o $@ + @echo "CXX <= $<" + +sample: $(UNTRUSTED_DIR)/$(enclaveName)_u.o $(App_C_Objects) + @$(CXX) $^ -o $@ $(App_Link_Flags) + @echo "LINK => $@" + + +.PHONY: clean + +clean: + @rm -f sample $(App_C_Objects) $(UNTRUSTED_DIR)/$(enclaveName)_u.* diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c/sgx_u.without_app.mk b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c/sgx_u.without_app.mk new file mode 100644 index 0000000000..f9eee94c69 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/c/sgx_u.without_app.mk @@ -0,0 +1,70 @@ +######## SGX SDK Settings ######## +SGX_SDK ?= $(SdkPathFromPlugin) +SGX_MODE ?= SIM +SGX_ARCH ?= x64 +UNTRUSTED_DIR=untrusted + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +######## App Settings ######## + +App_Include_Paths := -IInclude -I$(UNTRUSTED_DIR) -I$(SGX_SDK)/include + +App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) + +# Three configuration modes - Debug, prerelease, release +# Debug - Macro DEBUG enabled. +# Prerelease - Macro NDEBUG and EDEBUG enabled. +# Release - Macro NDEBUG enabled. +ifeq ($(SGX_DEBUG), 1) + App_C_Flags += -DDEBUG -UNDEBUG -UEDEBUG +else ifeq ($(SGX_PRERELEASE), 1) + App_C_Flags += -DNDEBUG -DEDEBUG -UDEBUG +else + App_C_Flags += -DNDEBUG -UEDEBUG -UDEBUG +endif + + +.PHONY: all run + +all: $(UNTRUSTED_DIR)/$(enclaveName)_u.o + +######## App Objects ######## + +$(UNTRUSTED_DIR)/$(enclaveName)_u.c: $(SGX_EDGER8R) trusted/$(enclaveName).edl + @mkdir -p $(UNTRUSTED_DIR) + @cd $(UNTRUSTED_DIR) && $(SGX_EDGER8R) --untrusted ../trusted/$(enclaveName).edl --search-path ../trusted --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +$(UNTRUSTED_DIR)/$(enclaveName)_u.o: $(UNTRUSTED_DIR)/$(enclaveName)_u.c + @$(CC) $(App_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +.PHONY: clean + +clean: + @rm -f $(UNTRUSTED_DIR)/$(enclaveName)_u.* diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/common/Makefile b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/common/Makefile new file mode 100644 index 0000000000..3defedc4c8 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/makefiles/common/Makefile @@ -0,0 +1,8 @@ +all: + $(MAKE) -f sgx_u.mk all + $(MAKE) -f sgx_t.mk all + +clean: + $(MAKE) -f sgx_u.mk clean + $(MAKE) -f sgx_t.mk clean + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.config.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.config.xml new file mode 100644 index 0000000000..1b2f224567 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.config.xml @@ -0,0 +1,9 @@ + + 0 + 0 + 0x40000 + 0x100000 + 10 + 1 + 0 + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.cpp b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.cpp new file mode 100644 index 0000000000..78f55c1553 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.cpp @@ -0,0 +1,26 @@ +#include +#include /* vsnprintf */ + +#include "$(enclaveName).h" +#include "$(enclaveName)_t.h" /* print_string */ + +/* + * printf: + * Invokes OCALL to display the enclave buffer to the terminal. + */ +void printf(const char *fmt, ...) +{ + char buf[BUFSIZ] = {'\0'}; + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, BUFSIZ, fmt, ap); + va_end(ap); + ocall_$(enclaveName)_sample(buf); +} + +int ecall_$(enclaveName)_sample() +{ + printf("IN $(ENCLAVENAME)\n"); + return 0; +} + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.edl b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.edl new file mode 100644 index 0000000000..e97f447eb3 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.edl @@ -0,0 +1,18 @@ +/* $(enclaveName).edl - Top EDL file. */ + +enclave { + + /* + * ocall_$(enclaveName)_sample - invokes OCALL to display string buffer inside the enclave. + * [in]: copy the string buffer to App outside. + * [string]: specifies 'str' is a NULL terminated buffer. + */ + untrusted { + void ocall_$(enclaveName)_sample([in, string] const char *str); + }; + + + trusted { + public int ecall_$(enclaveName)_sample(); + }; +}; diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.h b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.h new file mode 100644 index 0000000000..2d29332f3f --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.h @@ -0,0 +1,17 @@ +#ifndef _$(ENCLAVENAME)_H_ +#define _$(ENCLAVENAME)_H_ + +#include +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +void printf(const char *fmt, ...); + +#if defined(__cplusplus) +} +#endif + +#endif /* !_$(ENCLAVENAME)_H_ */ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.lds b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.lds new file mode 100644 index 0000000000..9019f79f5d --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1.lds @@ -0,0 +1,9 @@ +$(enclaveName).so +{ + global: + g_global_data_sim; + g_global_data; + $(enclaveName)_entry; + local: + *; +}; diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1_minimal.cpp b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1_minimal.cpp new file mode 100644 index 0000000000..79700c42b7 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1_minimal.cpp @@ -0,0 +1,7 @@ +#include "$(enclaveName)_t.h" /* print_string */ + +int ecall_$(enclaveName)_sample() +{ + return 0; +} + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1_minimal.edl b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1_minimal.edl new file mode 100644 index 0000000000..f332f81910 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1_minimal.edl @@ -0,0 +1,10 @@ +/* $(enclaveName).edl - Top EDL file. */ + +enclave { + untrusted { + }; + + trusted { + public int ecall_$(enclaveName)_sample(); + }; +}; diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1_private.pem b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1_private.pem new file mode 100644 index 0000000000..529d07be35 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/trusted/Enclave1_private.pem @@ -0,0 +1,39 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIG4gIBAAKCAYEAroOogvsj/fZDZY8XFdkl6dJmky0lRvnWMmpeH41Bla6U1qLZ +AmZuyIF+mQC/cgojIsrBMzBxb1kKqzATF4+XwPwgKz7fmiddmHyYz2WDJfAjIveJ +ZjdMjM4+EytGlkkJ52T8V8ds0/L2qKexJ+NBLxkeQLfV8n1mIk7zX7jguwbCG1Pr +nEMdJ3Sew20vnje+RsngAzdPChoJpVsWi/K7cettX/tbnre1DL02GXc5qJoQYk7b +3zkmhz31TgFrd9VVtmUGyFXAysuSAb3EN+5VnHGr0xKkeg8utErea2FNtNIgua8H +ONfm9Eiyaav1SVKzPHlyqLtcdxH3I8Wg7yqMsaprZ1n5A1v/levxnL8+It02KseD +5HqV4rf/cImSlCt3lpRg8U5E1pyFQ2IVEC/XTDMiI3c+AR+w2jSRB3Bwn9zJtFlW +KHG3m1xGI4ck+Lci1JvWWLXQagQSPtZTsubxTQNx1gsgZhgv1JHVZMdbVlAbbRMC +1nSuJNl7KPAS/VfzAgEDAoIBgHRXxaynbVP5gkO0ug6Qw/E27wzIw4SmjsxG6Wpe +K7kfDeRskKxESdsA/xCrKkwGwhcx1iIgS5+Qscd1Yg+1D9X9asd/P7waPmWoZd+Z +AhlKwhdPsO7PiF3e1AzHhGQwsUTt/Y/aSI1MpHBvy2/s1h9mFCslOUxTmWw0oj/Q +ldIEgWeNR72CE2+jFIJIyml6ftnb6qzPiga8Bm48ubKh0kvySOqnkmnPzgh+JBD6 +JnBmtZbfPT97bwTT+N6rnPqOOApvfHPf15kWI8yDbprG1l4OCUaIUH1AszxLd826 +5IPM+8gINLRDP1MA6azECPjTyHXhtnSIBZCyWSVkc05vYmNXYUNiXWMajcxW9M02 +wKzFELO8NCEAkaTPxwo4SCyIjUxiK1LbQ9h8PSy4c1+gGP4LAMR8xqP4QKg6zdu9 +osUGG/xRe/uufgTBFkcjqBHtK5L5VI0jeNIUAgW/6iNbYXjBMJ0GfauLs+g1VsOm +WfdgXzsb9DYdMa0OXXHypmV4GwKBwQDUwQj8RKJ6c8cT4vcWCoJvJF00+RFL+P3i +Gx2DLERxRrDa8AVGfqaCjsR+3vLgG8V/py+z+dxZYSqeB80Qeo6PDITcRKoeAYh9 +xlT3LJOS+k1cJcEmlbbO2IjLkTmzSwa80fWexKu8/Xv6vv15gpqYl1ngYoqJM3pd +vzmTIOi7MKSZ0WmEQavrZj8zK4endE3v0eAEeQ55j1GImbypSf7Idh7wOXtjZ7WD +Dg6yWDrri+AP/L3gClMj8wsAxMV4ZR8CgcEA0fzDHkFa6raVOxWnObmRoDhAtE0a +cjUj976NM5yyfdf2MrKy4/RhdTiPZ6b08/lBC/+xRfV3xKVGzacm6QjqjZrUpgHC +0LKiZaMtccCJjLtPwQd0jGQEnKfMFaPsnhOc5y8qVkCzVOSthY5qhz0XNotHHFmJ +gffVgB0iqrMTvSL7IA2yqqpOqNRlhaYhNl8TiFP3gIeMtVa9rZy31JPgT2uJ+kfo +gV7sdTPEjPWZd7OshGxWpT6QfVDj/T9T7L6tAoHBAI3WBf2DFvxNL2KXT2QHAZ9t +k3imC4f7U+wSE6zILaDZyzygA4RUbwG0gv8/TJVn2P/Eynf76DuWHGlaiLWnCbSz +Az2DHBQBBaku409zDQym3j1ugMRjzzSQWzJg0SIyBH3hTmnYcn3+Uqcp/lEBvGW6 +O+rsXFt3pukqJmIV8HzLGGaLm62BHUeZf3dyWm+i3p/hQAL7Xvu04QW70xuGqdr5 +afV7p5eaeQIJXyGQJ0eylV/90+qxjMKiB1XYg6WYvwKBwQCL/ddpgOdHJGN8uRom +e7Zq0Csi3hGheMKlKbN3vcxT5U7MdyHtTZZOJbTvxKNNUNYH/8uD+PqDGNneb29G +BfGzvI3EASyLIcGZF3OhKwZd0jUrWk2y7Vhob91jwp2+t73vdMbkKyI4mHOuXvGv +fg95si9oO7EBT+Oqvhccd2J+F1IVXncccYnF4u5ZGWt5lLewN/pVr7MjjykeaHqN +t+rfnQam2psA6fL4zS2zTmZPzR2tnY8Y1GBTi0Ko1OKd1HMCgcAb5cB/7/AQlhP9 +yQa04PLH9ygQkKKptZp7dy5WcWRx0K/hAHRoi2aw1wZqfm7VBNu2SLcs90kCCCxp +6C5sfJi6b8NpNbIPC+sc9wsFr7pGo9SFzQ78UlcWYK2Gu2FxlMjonhka5hvo4zvg +WxlpXKEkaFt3gLd92m/dMqBrHfafH7VwOJY2zT3WIpjwuk0ZzmRg5p0pG/svVQEH +NZmwRwlopysbR69B/n1nefJ84UO50fLh5s5Zr3gBRwbWNZyzhXk= +-----END RSA PRIVATE KEY----- diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/untrusted/sample.cpp b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/untrusted/sample.cpp new file mode 100644 index 0000000000..58b28a8509 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/untrusted/sample.cpp @@ -0,0 +1,247 @@ +#include +#include + +#include +#include +#include +#include + +# define MAX_PATH FILENAME_MAX + + +#include +#include "sample.h" + +#include "$(enclaveName)_u.h" + + + +/* Global EID shared by multiple threads */ +sgx_enclave_id_t global_eid = 0; + +typedef struct _sgx_errlist_t { + sgx_status_t err; + const char *msg; + const char *sug; /* Suggestion */ +} sgx_errlist_t; + +/* Error code returned by sgx_create_enclave */ +static sgx_errlist_t sgx_errlist[] = { + { + SGX_ERROR_UNEXPECTED, + "Unexpected error occurred.", + NULL + }, + { + SGX_ERROR_INVALID_PARAMETER, + "Invalid parameter.", + NULL + }, + { + SGX_ERROR_OUT_OF_MEMORY, + "Out of memory.", + NULL + }, + { + SGX_ERROR_ENCLAVE_LOST, + "Power transition occurred.", + "Please refer to the sample \"PowerTransition\" for details." + }, + { + SGX_ERROR_INVALID_ENCLAVE, + "Invalid enclave image.", + NULL + }, + { + SGX_ERROR_INVALID_ENCLAVE_ID, + "Invalid enclave identification.", + NULL + }, + { + SGX_ERROR_INVALID_SIGNATURE, + "Invalid enclave signature.", + NULL + }, + { + SGX_ERROR_OUT_OF_EPC, + "Out of EPC memory.", + NULL + }, + { + SGX_ERROR_NO_DEVICE, + "Invalid SGX device.", + "Please make sure SGX module is enabled in the BIOS, and install SGX driver afterwards." + }, + { + SGX_ERROR_MEMORY_MAP_CONFLICT, + "Memory map conflicted.", + NULL + }, + { + SGX_ERROR_INVALID_METADATA, + "Invalid enclave metadata.", + NULL + }, + { + SGX_ERROR_DEVICE_BUSY, + "SGX device was busy.", + NULL + }, + { + SGX_ERROR_INVALID_VERSION, + "Enclave version was invalid.", + NULL + }, + { + SGX_ERROR_INVALID_ATTRIBUTE, + "Enclave was not authorized.", + NULL + }, + { + SGX_ERROR_ENCLAVE_FILE_ACCESS, + "Can't open enclave file.", + NULL + }, +}; + +/* Check error conditions for loading enclave */ +void print_error_message(sgx_status_t ret) +{ + size_t idx = 0; + size_t ttl = sizeof sgx_errlist/sizeof sgx_errlist[0]; + + for (idx = 0; idx < ttl; idx++) { + if(ret == sgx_errlist[idx].err) { + if(NULL != sgx_errlist[idx].sug) + printf("Info: %s\n", sgx_errlist[idx].sug); + printf("Error: %s\n", sgx_errlist[idx].msg); + break; + } + } + + if (idx == ttl) + printf("Error: Unexpected error occurred.\n"); +} + +/* Initialize the enclave: + * Step 1: retrive the launch token saved by last transaction + * Step 2: call sgx_create_enclave to initialize an enclave instance + * Step 3: save the launch token if it is updated + */ +int initialize_enclave(void) +{ + char token_path[MAX_PATH] = {'\0'}; + sgx_launch_token_t token = {0}; + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + int updated = 0; + /* Step 1: retrive the launch token saved by last transaction */ + + /* try to get the token saved in $HOME */ + const char *home_dir = getpwuid(getuid())->pw_dir; + if (home_dir != NULL && + (strlen(home_dir)+strlen("/")+sizeof(TOKEN_FILENAME)+1) <= MAX_PATH) { + /* compose the token path */ + strncpy(token_path, home_dir, strlen(home_dir)); + strncat(token_path, "/", strlen("/")); + strncat(token_path, TOKEN_FILENAME, sizeof(TOKEN_FILENAME)+1); + } else { + /* if token path is too long or $HOME is NULL */ + strncpy(token_path, TOKEN_FILENAME, sizeof(TOKEN_FILENAME)); + } + + FILE *fp = fopen(token_path, "rb"); + if (fp == NULL && (fp = fopen(token_path, "wb")) == NULL) { + printf("Warning: Failed to create/open the launch token file \"%s\".\n", token_path); + } + printf("token_path: %s\n", token_path); + if (fp != NULL) { + /* read the token from saved file */ + size_t read_num = fread(token, 1, sizeof(sgx_launch_token_t), fp); + if (read_num != 0 && read_num != sizeof(sgx_launch_token_t)) { + /* if token is invalid, clear the buffer */ + memset(&token, 0x0, sizeof(sgx_launch_token_t)); + printf("Warning: Invalid launch token read from \"%s\".\n", token_path); + } + } + + /* Step 2: call sgx_create_enclave to initialize an enclave instance */ + /* Debug Support: set 2nd parameter to 1 */ + + ret = sgx_create_enclave($(ENCLAVENAME)_FILENAME, SGX_DEBUG_FLAG, &token, &updated, &global_eid, NULL); + + if (ret != SGX_SUCCESS) { + print_error_message(ret); + if (fp != NULL) fclose(fp); + + return -1; + } + + /* Step 3: save the launch token if it is updated */ + + if (updated == FALSE || fp == NULL) { + /* if the token is not updated, or file handler is invalid, do not perform saving */ + if (fp != NULL) fclose(fp); + return 0; + } + + /* reopen the file with write capablity */ + fp = freopen(token_path, "wb", fp); + if (fp == NULL) return 0; + size_t write_num = fwrite(token, 1, sizeof(sgx_launch_token_t), fp); + if (write_num != sizeof(sgx_launch_token_t)) + printf("Warning: Failed to save launch token to \"%s\".\n", token_path); + fclose(fp); + + return 0; +} + +/* OCall functions */ +void ocall_$(enclaveName)_sample(const char *str) +{ + /* Proxy/Bridge will check the length and null-terminate + * the input string to prevent buffer overflow. + */ + printf("%s", str); +} + + +/* Application entry */ +int SGX_CDECL main(int argc, char *argv[]) +{ + (void)(argc); + (void)(argv); + + /* Changing dir to where the executable is.*/ + char absolutePath [MAX_PATH]; + char *ptr = NULL; + + ptr = realpath(dirname(argv[0]),absolutePath); + + if( chdir(absolutePath) != 0) + abort(); + + /* Initialize the enclave */ + if(initialize_enclave() < 0){ + + return -1; + } + + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + int ecall_return = 0; + + ret = ecall_$(enclaveName)_sample(global_eid, &ecall_return); + if (ret != SGX_SUCCESS) + abort(); + + if (ecall_return == 0) { + printf("Application ran with success\n"); + } + else + { + printf("Application failed %d \n", ecall_return); + } + + sgx_destroy_enclave(global_eid); + + return ecall_return; +} diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/untrusted/sample.h b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/untrusted/sample.h new file mode 100644 index 0000000000..a0fb5e780e --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXEnclave/untrusted/sample.h @@ -0,0 +1,34 @@ +#ifndef _APP_H_ +#define _APP_H_ + +#include +#include +#include +#include + +#include "sgx_error.h" /* sgx_status_t */ +#include "sgx_eid.h" /* sgx_enclave_id_t */ + +#ifndef TRUE +# define TRUE 1 +#endif + +#ifndef FALSE +# define FALSE 0 +#endif + + +# define TOKEN_FILENAME "enclave.token" +# define $(ENCLAVENAME)_FILENAME "$(enclaveName).signed.so" + +extern sgx_enclave_id_t global_eid; /* global enclave id */ + +#if defined(__cplusplus) +extern "C" { +#endif + +#if defined(__cplusplus) +} +#endif + +#endif /* !_APP_H_ */ diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXNature/Makefile b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXNature/Makefile new file mode 100644 index 0000000000..5a67151653 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXNature/Makefile @@ -0,0 +1,17 @@ +ALL_UNTRUSTED_MK=$(shell find . -name '*sgx_u.mk') +ALL_TRUSTED_MK=$(shell find . -name '*sgx_t.mk') +ALL_STATIC_MK=$(shell find . -name '*sgx_t_static.mk') + + + +.PHONY: all clean run + + +all clean: + $(foreach U_MK, $(ALL_UNTRUSTED_MK), $(MAKE) -C $(shell dirname $(U_MK)) -f $(shell basename $(U_MK)) $@;) + $(foreach T_MK, $(ALL_TRUSTED_MK), $(MAKE) -C $(shell dirname $(T_MK)) -f $(shell basename $(T_MK)) $@;) + $(foreach U_MK, $(ALL_STATIC_MK), $(MAKE) -C $(shell dirname $(U_MK)) -f $(shell basename $(U_MK)) $@;) + +run: + $(foreach U_MK, $(ALL_UNTRUSTED_MK), $(MAKE) -C $(shell dirname $(U_MK)) -f $(shell basename $(U_MK)) $@;) + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c++/sgx_t_static.mk b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c++/sgx_t_static.mk new file mode 100644 index 0000000000..62ff91ff93 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c++/sgx_t_static.mk @@ -0,0 +1,105 @@ +######## SGX SDK Settings ######## +SGX_SDK ?= $(SdkPathFromPlugin) +SGX_MODE ?= SIM +SGX_ARCH ?= x64 + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +ifneq ($(SGX_MODE), HW) + Trts_Library_Name := sgx_trts_sim + Service_Library_Name := sgx_tservice_sim +else + Trts_Library_Name := sgx_trts + Service_Library_Name := sgx_tservice +endif + +Crypto_Library_Name := sgx_tcrypto + +$(EnclaveName)_Cpp_Files := static_trusted/$(enclaveName).cpp +$(EnclaveName)_C_Files := +$(EnclaveName)_Include_Paths := -IInclude -I$(EnclaveName) -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport + +Flags_Just_For_C := -Wno-implicit-function-declaration -std=c11 +Common_C_Cpp_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $($(EnclaveName)_Include_Paths) -fno-builtin-printf -I. +$(EnclaveName)_C_Flags := $(Flags_Just_For_C) $(Common_C_Cpp_Flags) +$(EnclaveName)_Cpp_Flags := $(Common_C_Cpp_Flags) -std=c++11 -nostdinc++ -fno-builtin-printf -I. + +$(EnclaveName)_Cpp_Flags := $($(EnclaveName)_Cpp_Flags) -fno-builtin-printf + +$(EnclaveName)_Link_Flags := $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \ + -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive \ + -Wl,--start-group -lsgx_tstdc -lsgx_tstdcxx -l$(Crypto_Library_Name) -l$(Service_Library_Name) -Wl,--end-group \ + -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \ + -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \ + -Wl,--defsym,__ImageBase=0 \ + -Wl,--version-script=trusted/$(enclaveName).lds + + +$(EnclaveName)_Cpp_Objects := $($(EnclaveName)_Cpp_Files:.cpp=.o) +$(EnclaveName)_C_Objects := $($(EnclaveName)_C_Files:.c=.o) + +ifeq ($(SGX_MODE), HW) +ifneq ($(SGX_DEBUG), 1) +ifneq ($(SGX_PRERELEASE), 1) +Build_Mode = HW_RELEASE +endif +endif +endif + + +.PHONY: all run + +all: lib$(enclaveName).sgx.static.lib.a + +######## $(enclaveName) Objects ######## + +static_trusted/$(enclaveName)_t.h: $(SGX_EDGER8R) ./static_trusted/$(enclaveName).edl + @cd ./static_trusted && $(SGX_EDGER8R) --header-only --trusted ../static_trusted/$(enclaveName).edl --search-path ../static_trusted --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +static_trusted/$(enclaveName)_t.o: ./trusted/$(enclaveName)_t.c + @$(CC) $($(EnclaveName)_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +static_trusted/%.o: static_trusted/%.cpp + @$(CXX) $($(EnclaveName)_Include_Paths) $($(EnclaveName)_Cpp_Flags) -c $< -o $@ + @echo "CXX <= $<" + +static_trusted/%.o: static_trusted/%.c + @$(CC) $($(EnclaveName)_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +lib$(enclaveName).sgx.static.lib.a: static_trusted/$(enclaveName)_t.h $($(EnclaveName)_Cpp_Objects) $($(EnclaveName)_C_Objects) + ar rcs lib$(enclaveName).sgx.static.lib.a $($(EnclaveName)_Cpp_Objects) $($(EnclaveName)_C_Objects) + @echo "LINK => $@" + +clean: + @rm -f $(enclaveName).* static_trusted/$(enclaveName)_t.* $($(EnclaveName)_Cpp_Objects) $($(EnclaveName)_C_Objects) diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c++/sgx_u.without_app.mk b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c++/sgx_u.without_app.mk new file mode 100644 index 0000000000..c0d0c6778a --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c++/sgx_u.without_app.mk @@ -0,0 +1,71 @@ +######## SGX SDK Settings ######## +SGX_SDK ?= $(SdkPathFromPlugin) +SGX_MODE ?= SIM +SGX_ARCH ?= x64 +UNTRUSTED_DIR=untrusted + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +######## App Settings ######## + +App_Include_Paths := -IInclude -I$(UNTRUSTED_DIR) -I$(SGX_SDK)/include + +App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) + +# Three configuration modes - Debug, prerelease, release +# Debug - Macro DEBUG enabled. +# Prerelease - Macro NDEBUG and EDEBUG enabled. +# Release - Macro NDEBUG enabled. +ifeq ($(SGX_DEBUG), 1) + App_C_Flags += -DDEBUG -UNDEBUG -UEDEBUG +else ifeq ($(SGX_PRERELEASE), 1) + App_C_Flags += -DNDEBUG -DEDEBUG -UDEBUG +else + App_C_Flags += -DNDEBUG -UEDEBUG -UDEBUG +endif + +App_Cpp_Flags := $(App_C_Flags) -std=c++11 + +.PHONY: all run + +all: $(UNTRUSTED_DIR)/$(enclaveName)_u.o + +######## App Objects ######## + +$(UNTRUSTED_DIR)/$(enclaveName)_u.c: $(SGX_EDGER8R) static_trusted/$(enclaveName).edl + @mkdir -p $(UNTRUSTED_DIR) + @cd $(UNTRUSTED_DIR) && $(SGX_EDGER8R) --untrusted ../static_trusted/$(enclaveName).edl --search-path ../static_trusted --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +$(UNTRUSTED_DIR)/$(enclaveName)_u.o: $(UNTRUSTED_DIR)/$(enclaveName)_u.c + @$(CC) $(App_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +.PHONY: clean + +clean: + @rm -f $(UNTRUSTED_DIR)/$(enclaveName)_u.* diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c/sgx_t_static.mk b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c/sgx_t_static.mk new file mode 100644 index 0000000000..e3dbd8f7f5 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c/sgx_t_static.mk @@ -0,0 +1,95 @@ +######## SGX SDK Settings ######## +SGX_SDK ?= $(SdkPathFromPlugin) +SGX_MODE ?= SIM +SGX_ARCH ?= x64 + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +ifneq ($(SGX_MODE), HW) + Trts_Library_Name := sgx_trts_sim + Service_Library_Name := sgx_tservice_sim +else + Trts_Library_Name := sgx_trts + Service_Library_Name := sgx_tservice +endif + +Crypto_Library_Name := sgx_tcrypto + +$(EnclaveName)_C_Files := static_trusted/$(enclaveName).c +$(EnclaveName)_Include_Paths := -IInclude -I$(EnclaveName) -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport + +Flags_Just_For_C := -Wno-implicit-function-declaration -std=c11 +Common_C_Cpp_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $($(EnclaveName)_Include_Paths) -fno-builtin-printf -I. +$(EnclaveName)_C_Flags := $(Flags_Just_For_C) $(Common_C_Cpp_Flags) + +$(EnclaveName)_Link_Flags := $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \ + -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive \ + -Wl,--start-group -lsgx_tstdc -lsgx_tstdcxx -l$(Crypto_Library_Name) -l$(Service_Library_Name) -Wl,--end-group \ + -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \ + -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \ + -Wl,--defsym,__ImageBase=0 \ + -Wl,--version-script=trusted/$(enclaveName).lds + +$(EnclaveName)_C_Objects := $($(EnclaveName)_C_Files:.c=.o) + +ifeq ($(SGX_MODE), HW) +ifneq ($(SGX_DEBUG), 1) +ifneq ($(SGX_PRERELEASE), 1) +Build_Mode = HW_RELEASE +endif +endif +endif + + +.PHONY: all run + +all: lib$(enclaveName).sgx.static.lib.a + +######## $(enclaveName) Objects ######## + +static_trusted/$(enclaveName)_t.h: $(SGX_EDGER8R) ./static_trusted/$(enclaveName).edl + @cd ./static_trusted && $(SGX_EDGER8R) --header-only --trusted ../static_trusted/$(enclaveName).edl --search-path ../static_trusted --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +static_trusted/$(enclaveName)_t.o: ./trusted/$(enclaveName)_t.c + @$(CC) $($(EnclaveName)_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +static_trusted/%.o: static_trusted/%.c + @$(CC) $($(EnclaveName)_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +lib$(enclaveName).sgx.static.lib.a: static_trusted/$(enclaveName)_t.h $($(EnclaveName)_C_Objects) + ar rcs lib$(enclaveName).sgx.static.lib.a $($(EnclaveName)_Cpp_Objects) $($(EnclaveName)_C_Objects) + @echo "LINK => $@" + +clean: + @rm -f $(enclaveName).* static_trusted/$(enclaveName)_t.* $($(EnclaveName)_C_Objects) diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c/sgx_u.without_app.mk b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c/sgx_u.without_app.mk new file mode 100644 index 0000000000..e8a5508339 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c/sgx_u.without_app.mk @@ -0,0 +1,70 @@ +######## SGX SDK Settings ######## +SGX_SDK ?= $(SdkPathFromPlugin) +SGX_MODE ?= SIM +SGX_ARCH ?= x64 +UNTRUSTED_DIR=untrusted + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +######## App Settings ######## + +App_Include_Paths := -IInclude -I$(UNTRUSTED_DIR) -I$(SGX_SDK)/include + +App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) + +# Three configuration modes - Debug, prerelease, release +# Debug - Macro DEBUG enabled. +# Prerelease - Macro NDEBUG and EDEBUG enabled. +# Release - Macro NDEBUG enabled. +ifeq ($(SGX_DEBUG), 1) + App_C_Flags += -DDEBUG -UNDEBUG -UEDEBUG +else ifeq ($(SGX_PRERELEASE), 1) + App_C_Flags += -DNDEBUG -DEDEBUG -UDEBUG +else + App_C_Flags += -DNDEBUG -UEDEBUG -UDEBUG +endif + + +.PHONY: all run + +all: $(UNTRUSTED_DIR)/$(enclaveName)_u.o + +######## App Objects ######## + +$(UNTRUSTED_DIR)/$(enclaveName)_u.c: $(SGX_EDGER8R) static_trusted/$(enclaveName).edl + @mkdir -p $(UNTRUSTED_DIR) + @cd $(UNTRUSTED_DIR) && $(SGX_EDGER8R) --untrusted ../static_trusted/$(enclaveName).edl --search-path ../static_trusted --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +$(UNTRUSTED_DIR)/$(enclaveName)_u.o: $(UNTRUSTED_DIR)/$(enclaveName)_u.c + @$(CC) $(App_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +.PHONY: clean + +clean: + @rm -f $(UNTRUSTED_DIR)/$(enclaveName)_u.* diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/common/Makefile b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/common/Makefile new file mode 100644 index 0000000000..3defedc4c8 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/common/Makefile @@ -0,0 +1,8 @@ +all: + $(MAKE) -f sgx_u.mk all + $(MAKE) -f sgx_t.mk all + +clean: + $(MAKE) -f sgx_u.mk clean + $(MAKE) -f sgx_t.mk clean + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/common/Makefile.without_app b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/common/Makefile.without_app new file mode 100644 index 0000000000..28aa5c8f1e --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/common/Makefile.without_app @@ -0,0 +1,8 @@ +all: + $(MAKE) -f sgx_u.mk all + $(MAKE) -f sgx_t_static.mk all + +clean: + $(MAKE) -f sgx_u.mk clean + $(MAKE) -f sgx_t.mk clean + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/static_trusted/Enclave2_minimal.cpp b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/static_trusted/Enclave2_minimal.cpp new file mode 100644 index 0000000000..79700c42b7 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/static_trusted/Enclave2_minimal.cpp @@ -0,0 +1,7 @@ +#include "$(enclaveName)_t.h" /* print_string */ + +int ecall_$(enclaveName)_sample() +{ + return 0; +} + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/static_trusted/Enclave2_minimal.edl b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/static_trusted/Enclave2_minimal.edl new file mode 100644 index 0000000000..7af749e545 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/static_trusted/Enclave2_minimal.edl @@ -0,0 +1,11 @@ +/* $(enclaveName).edl - Top EDL file. */ + +enclave { + + untrusted { + }; + + trusted { + public int ecall_$(enclaveName)_sample(); + }; +}; diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXUntrustedModule/makefiles/c++/sgx_u.without_app.mk b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXUntrustedModule/makefiles/c++/sgx_u.without_app.mk new file mode 100644 index 0000000000..0db9ce0ab5 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXUntrustedModule/makefiles/c++/sgx_u.without_app.mk @@ -0,0 +1,75 @@ +######## SGX SDK Settings ######## +SGX_SDK ?= $(SdkPathFromPlugin) +SGX_MODE ?= SIM +SGX_ARCH ?= x64 +UNTRUSTED_DIR=untrusted +SGX_EDL_FILE := $(baseName).edl + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +######## App Settings ######## + +App_Include_Paths := -IInclude -I$(UNTRUSTED_DIR) -I$(SGX_SDK)/include + +App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) + +# Three configuration modes - Debug, prerelease, release +# Debug - Macro DEBUG enabled. +# Prerelease - Macro NDEBUG and EDEBUG enabled. +# Release - Macro NDEBUG enabled. +ifeq ($(SGX_DEBUG), 1) + App_C_Flags += -DDEBUG -UNDEBUG -UEDEBUG +else ifeq ($(SGX_PRERELEASE), 1) + App_C_Flags += -DNDEBUG -DEDEBUG -UDEBUG +else + App_C_Flags += -DNDEBUG -UEDEBUG -UDEBUG +endif + +App_Cpp_Flags := $(App_C_Flags) -std=c++11 + +.PHONY: all run + +all: $(UNTRUSTED_DIR)/$(baseName)_u.o $(UNTRUSTED_DIR)/$(baseName).o + +######## App Objects ######## + +$(UNTRUSTED_DIR)/$(baseName)_u.c: $(SGX_EDGER8R) $(SGX_EDL_FILE) + @mkdir -p $(UNTRUSTED_DIR) && cd $(UNTRUSTED_DIR) && $(SGX_EDGER8R) --untrusted $(SGX_EDL_FILE) --search-path .. --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +$(UNTRUSTED_DIR)/$(baseName)_u.o: $(UNTRUSTED_DIR)/$(baseName)_u.c + @$(CC) $(App_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +$(UNTRUSTED_DIR)/$(baseName).o: $(UNTRUSTED_DIR)/$(baseName).cpp + @$(CC) $(App_Cpp_Flags) -c $< -o $@ + @echo "CC <= $<" + +.PHONY: clean + +clean: + @rm -f $(UNTRUSTED_DIR)/$(baseName)_u.* $(UNTRUSTED_DIR)/$(baseName).o diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXUntrustedModule/makefiles/c/sgx_u.without_app.mk b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXUntrustedModule/makefiles/c/sgx_u.without_app.mk new file mode 100644 index 0000000000..cce0dfec11 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXUntrustedModule/makefiles/c/sgx_u.without_app.mk @@ -0,0 +1,75 @@ +######## SGX SDK Settings ######## +SGX_SDK ?= $(SdkPathFromPlugin) +SGX_MODE ?= SIM +SGX_ARCH ?= x64 +UNTRUSTED_DIR=untrusted +SGX_EDL_FILE := $(baseName).edl + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +######## App Settings ######## + +App_Include_Paths := -IInclude -I$(UNTRUSTED_DIR) -I$(SGX_SDK)/include + +App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) + +# Three configuration modes - Debug, prerelease, release +# Debug - Macro DEBUG enabled. +# Prerelease - Macro NDEBUG and EDEBUG enabled. +# Release - Macro NDEBUG enabled. +ifeq ($(SGX_DEBUG), 1) + App_C_Flags += -DDEBUG -UNDEBUG -UEDEBUG +else ifeq ($(SGX_PRERELEASE), 1) + App_C_Flags += -DNDEBUG -DEDEBUG -UDEBUG +else + App_C_Flags += -DNDEBUG -UEDEBUG -UDEBUG +endif + +App_Cpp_Flags := $(App_C_Flags) -std=c++11 + +.PHONY: all run + +all: $(UNTRUSTED_DIR)/$(baseName)_u.o $(UNTRUSTED_DIR)/$(baseName).o + +######## App Objects ######## + +$(UNTRUSTED_DIR)/$(baseName)_u.c: $(SGX_EDGER8R) $(SGX_EDL_FILE) + @mkdir -p $(UNTRUSTED_DIR) && cd $(UNTRUSTED_DIR) && $(SGX_EDGER8R) --untrusted $(SGX_EDL_FILE) --search-path .. --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +$(UNTRUSTED_DIR)/$(baseName)_u.o: $(UNTRUSTED_DIR)/$(baseName)_u.c + @$(CC) $(App_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +$(UNTRUSTED_DIR)/$(baseName).o: $(UNTRUSTED_DIR)/$(baseName).c + @$(CC) $(App_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +.PHONY: clean + +clean: + @rm -f $(UNTRUSTED_DIR)/$(baseName)_u.* $(UNTRUSTED_DIR)/$(baseName).o diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXUntrustedModule/makefiles/common/Makefile b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXUntrustedModule/makefiles/common/Makefile new file mode 100644 index 0000000000..af0747ec6d --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXUntrustedModule/makefiles/common/Makefile @@ -0,0 +1,6 @@ +all: + $(MAKE) -f sgx_u.mk all + +clean: + $(MAKE) -f sgx_u.mk clean + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXUntrustedModule/untrusted/untrusted_module.cpp b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXUntrustedModule/untrusted/untrusted_module.cpp new file mode 100644 index 0000000000..f4d2acdc38 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXUntrustedModule/untrusted/untrusted_module.cpp @@ -0,0 +1 @@ +#include "$(baseName)_u.h" diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/sites/site.xml b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/sites/site.xml new file mode 100644 index 0000000000..3c3d422d7b --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/build_directory/sites/site.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + This website hosts an evaluation version of the Eclipse Plug-in developed for Secure Guard Extensions Application development for Linux platforms. + + + + + + SGX Eclipse Plugin 1.0.1.qualifier + + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/clean.sh b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/clean.sh new file mode 100755 index 0000000000..ba0f7bc78a --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/clean.sh @@ -0,0 +1,20 @@ +# clean input directories to make sure there's nothing left from previous run + +rm -rfv ./build_directory/features/com.intel.sgx.build.driver +rm -fv build_directory/*.properties +rm -fv build_directory/*.xml +rm -fv build_directory/plugins/com.intel.sgx/build.xml +rm -fv build_directory/plugins/com.intel.sgx.userguide/build.xml +rm -rfv build_directory/plugins/com.intel.sgx/bin +rm -rfv build_directory/plugins/com.intel.sgx.userguide/bin +rm -rfv build_directory/plugins/com.intel.sgx.source_1.0.0.* +rm -rfv build_directory/features/com.intel.sgx.source +rm -fv build_directory/features/com.intel.sgx.feature/build.xml +rm -fv build_directory/features/com.intel.sgx.feature/*.zip +rm -rfv build_directory/nestedJars +rm -rfv build_directory/updatesite/sgx-eclipse-plugin +find . -name "*.zip" ! -name "eclipse_mars.v4.5.1_x64.zip" | xargs rm -rfv +find . -name "javaCompiler*" | xargs rm -rfv +find . -name "@*" | xargs rm -rfv +find build_directory -maxdepth 1 -mindepth 1 | grep -v "features" | grep -v "plugins" | grep -v "sites" | grep -v "updatesite" | xargs rm -frv + diff --git a/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/readme.txt b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/readme.txt new file mode 100644 index 0000000000..1430d35772 --- /dev/null +++ b/sgx-jvm/linux-sgx/Linux_SGXEclipsePlugin/readme.txt @@ -0,0 +1,22 @@ +The eclipse plugin build from command line requires the following variables to be set. + +$ECLIPSE_HOME - Path to eclipse home. In order to build the plugin eclipse needs to be installed. +$RELEASE_ID - The release id for the plugin. The release id should be changed for each source codes updates. +$DELETE_CURRENT_ECLIPSE - Delete current eclipse or not. Generally this variable is set to false. + +The following plugins are pre-requisites to be installed in Eclipse before trying to build the plugin. + +1. Eclipse IDE for C/C++ Developers 4.5.1.20150917-1200 (tested_version) +2. Eclipse PDE Plug-in Developer Resources 3.11.1.v20150904-0345 (tested_version) + +run ./build.sh from command line under current directory. +Once the build script is run, the folder build_directory/updatesite/sgx-eclipse-plugin contains the update site. This is the path that needs to be provided to the eclipse while doing installation. + +If the sgx eclipse plugin is already installed to eclipse and to build and install a newer version, uninstall the old version and start eclipse with the -clean option. +Then try to build the new version of the plugin and install it in eclipse. + +http://wiki.eclipse.org/FAQ_How_do_I_remove_a_plug-in%3F + +The plugin has been tested with the following Eclipse ADT version + +Build: v22.3.0-887826 diff --git a/sgx-jvm/linux-sgx/Makefile b/sgx-jvm/linux-sgx/Makefile new file mode 100644 index 0000000000..9cd3ab3a08 --- /dev/null +++ b/sgx-jvm/linux-sgx/Makefile @@ -0,0 +1,58 @@ +# +# Copyright (C) 2011-2016 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# + +include buildenv.mk +.PHONY: all psw sdk clean rebuild sdk_install_pkg psw_install_pkg + +all: sdk psw + +psw: sdk + $(MAKE) -C psw/ USE_OPT_LIBS=$(USE_OPT_LIBS) + +sdk: + $(MAKE) -C sdk/ USE_OPT_LIBS=$(USE_OPT_LIBS) + +# Generate SE SDK Install package +sdk_install_pkg: sdk + ./linux/installer/bin/build-installpkg.sh sdk + +psw_install_pkg: psw + ./linux/installer/bin/build-installpkg.sh psw + +clean: + @$(MAKE) -C sdk/ clean + @$(MAKE) -C psw/ clean + @$(RM) -r $(ROOT_DIR)/build + @$(RM) -r linux/installer/bin/sgx_linux*.bin + +rebuild: + $(MAKE) clean + $(MAKE) all diff --git a/sgx-jvm/linux-sgx/README.md b/sgx-jvm/linux-sgx/README.md new file mode 100644 index 0000000000..efacc00610 --- /dev/null +++ b/sgx-jvm/linux-sgx/README.md @@ -0,0 +1,179 @@ +Intel(R) Software Guard Extensions for Linux\* OS +================================================ + +# linux-sgx + +Introduction +------------ +Intel(R) Software Guard Extensions (Intel(R) SGX) is an Intel technology for application developers seeking to protect select code and data from disclosure or modification. + +The Linux SGX software stack is comprised of the SGX driver, the SGX SDK, and the SGX Platform Software. The SGX SDK and SGX PSW are hosted in the [linux-sgx](https://github.com/01org/linux-sgx) project. + +The [linux-sgx-driver](https://github.com/01org/linux-sgx-driver) project hosts the out-of-tree driver for the Linux SGX software stack, which will be used until the driver upstreaming process is complete. + +License +------- +See License.txt for details. + +Contributing +------- +See CONTRIBUTING.md for details. + +Documentation +------------- +- [Intel(R) SGX for Linux\* OS][1] project home page on [01.org](https://01.org) +- [Intel(R) SGX Programming Reference][2] +[1]: https://01.org/intel-softwareguard-extensions +[2]: https://software.intel.com/sites/default/files/managed/48/88/329298-002.pdf + +Build and Install the Intel(R) SGX Driver +----------------------------------------- +Follow the instructions in the [linux-sgx-driver](https://github.com/01org/linux-sgx-driver) project to build and install the SGX driver. + +Build the Intel(R) SGX SDK and Intel(R) SGX PSW Package +------------------------------------------------------- +###Prerequisites: +- Ensure that you have the following required operating systems: + Ubuntu\* Desktop-14.04-LTS 64bits +- Use the following command to install the required tools to build Intel(R) SGX SDK: +``` + $ sudo apt-get install build-essential ocaml automake autoconf libtool +``` +- Use the following command to install additional required tools to build Intel(R) SGX PSW: +``` + $ sudo apt-get install libcurl4-openssl-dev protobuf-compiler protobuf-c-compiler libprotobuf-dev libprotobuf-c0-dev +``` +- Use the script ``download_prebuilt.sh`` inside source code package to download prebuilt binaries to prebuilt folder + You may need set https proxy for wget tool used by the script (such as ``export https_proxy=http://test-proxy:test-port``) +``` + $ ./download_prebuilt.sh +``` + +###Build the Intel(R) SGX SDK and Intel(R) SGX PSW +The following steps describe how to build the Intel SGX SDK and PSW. You can build the project according to your requirement. +- To build both Intel SGX SDK and PSW with default configuration, enter the following command: + You can find the tools and libraries generated in the `build/linux` directory. + **Note**: You can also go to the sdk folder and use the `make` command to build the Intel SGX SDK component only. However, the building of PSW component is dependent on the building result of Intel SGX SDK. +``` + $ make +``` + +- The default build uses precompiled optimized libraries which have been downloaded by the script ``./download_prebuilt.sh``. + You can also use the non-optimized source code version implementation instead by entering the following command: +``` + $ make USE_OPT_LIBS=0 +``` +- To build Intel SGX SDK and PSW with debug information, enter the following command: +``` + $ make DEBUG=1 +``` +- To clean the files generated by previous `make` command, enter the following command: +``` + $ make clean +``` + +- The build above uses prebuilt Intel(R) Architecture Enclaves(LE/PvE/QE/PCE) - the files ``psw/ae/data/prebuilt/libsgx_*.signed.so``, which have been signed by Intel in advance. + To build those binaries by yourself (without a signature), first you need to build both Intel SGX SDK and PSW with the default configuration. After that, you can build each Architecture Enclave by using the `make` command from the corresponding folder: +``` + $ cd psw/ae/le + $ make +``` + +###Build Intel(R) SGX SDK Installer +To build Intel(R) SGX SDK installer, enter the following command: +``` +$ make sdk_install_pkg +``` +You can find the generated Intel SGX SDK installer ``sgx_linux_x64_sdk_${version}.bin`` located under `linux/installer/bin/`, where `${version}` refers to the version number. +You could also make an SGX SDK installer with non-optimized source code for crypto library by +``` +$ make sdk_install_pkg USE_OPT_LIBS=0 +``` + +###Build Intel(R) SGX PSW Installer +To build Intel(R) SGX PSW installer, enter the following command: +``` +$ make psw_install_pkg +``` +You can find the generated Intel SGX PSW installer ``sgx_linux_x64_psw_${version}.bin`` located under `linux/installer/bin/`, where `${version}` refers to the version number. +You could also make an SGX PSW intaller with non-optimized source code for crypto library by +``` +$ make psw_install_pkg USE_OPT_LIBS=0 +``` +Install Intel(R) SGX SDK +------------------------ +###Prerequisites +- Ensure that you have the following required operating systems: + Ubuntu\* Desktop-14.04-LTS 64bits +- Use the following command to install the required tool to use Intel(R) SGX SDK: +``` + $ sudo apt-get install build-essential +``` + +###Install Intel(R) SGX SDK +To install Intel(R) SGX SDK, execute the installer with root privilege: +``` +$ cd linux/installer/bin +$ sudo ./sgx_linux_x64_sdk_${version}.bin +``` +###Test Intel(R) SGX SDK Package with the Sample Codes +- Copy the sample codes installed by Intel(R) SGX SDK package into your work folder, such as +``` + $ cp -r /opt/intel/sgxsdk/SampleCode ~ +``` +- Compile and run each sample codes in the simulation mode to make sure the package works well. +``` + $ cd SampleCode/LocalAttestation + $ make + $ ./app +``` + Use similar commands for other sample codes. + +###Compile and Run the Sample Codes in the Hardware Mode +If you use an SGX hardware enabled machine, you need to run the sample codes in the hardware mode. +Ensure that you install SGX driver and Intel(R) SGX PSW installer on the machine. +See the topic, Install Intel(R) SGX PSW, on how to install the PSW package. +- Copy the sample codes installed by the Intel(R) SGX SDK package into your work folder, such as +``` + $ cp -r /opt/intel/sgxsdk/SampleCode ~ +``` +- Compile and run each sample codes in the debug mode. +``` + $ cd SampleCode/LocalAttestation + $ make SGX_MODE=HW SGX_DEBUG=1 + $ ./app +``` + Use similar commands for other sample codes. + +Install Intel(R) SGX PSW +------------------------ +###Prerequisites +- Ensure that you have the following required operating systems: + Ubuntu\* Desktop-14.04-LTS 64bits +- Ensure that you have the following required hardware: + 6th Generation Intel(R) Core(TM) Processor (code named Skylake) +- Configure the system with the **SGX hardware enabled** option and install SGX driver in advance. + See the topic, Build and Install the Intel(R) SGX Driver, on how to install the SGX driver. +- Install the library using the following command: +``` + $ sudo apt-get install libcurl4-openssl-dev libprotobuf-dev libprotobuf-c0-dev +``` + +###Install Intel(R) SGX PSW +To install Intel(R) SGX PSW, execute the installer with root privilege: +``` +$ cd linux/installer/bin +$ sudo ./sgx_linux_x64_psw_${version}.bin +``` + +###Start or Stop aesmd Service +The Intel(R) SGX PSW installer installs an aesmd service in your machine which is running in a special linux account aesmd. +To stop the service: `$ sudo service aesmd stop` +To start the service: `$ sudo service aesmd start` +To restart the service: `$ sudo service aesmd restart` + +###Configure the Proxy for aesmd Service +The aesmd service uses HTTP protocol to initialize some services. +If proxy is required for HTTP protocol, you may need manually setup the proxy for aesmd service. +You should manually edit file `/etc/aesmd.conf` (refer the comment in the file) to set the proxy for aesmd service. +After you configure the proxy, you need to restart the service to enable the proxy. diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/.cproject b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/.cproject new file mode 100644 index 0000000000..be4d65295c --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/.cproject @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/.project b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/.project new file mode 100644 index 0000000000..df8b1a4d24 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/.project @@ -0,0 +1,28 @@ + + + LocalAttestation + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.eclipse.cdt.core.ccnature + com.intel.sgx.sgxnature + + diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/App/App.cpp b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/App/App.cpp new file mode 100644 index 0000000000..92b5ec0b6c --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/App/App.cpp @@ -0,0 +1,450 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +// App.cpp : Defines the entry point for the console application. +#include +#include +#include "../Enclave1/Enclave1_u.h" +#include "../Enclave2/Enclave2_u.h" +#include "../Enclave3/Enclave3_u.h" +#include "sgx_eid.h" +#include "sgx_urts.h" +#define __STDC_FORMAT_MACROS +#include + + +#define UNUSED(val) (void)(val) +#define TCHAR char +#define _TCHAR char +#define _T(str) str +#define scanf_s scanf +#define _tmain main + +extern std::mapg_enclave_id_map; + + +sgx_enclave_id_t e1_enclave_id = 0; +sgx_enclave_id_t e2_enclave_id = 0; +sgx_enclave_id_t e3_enclave_id = 0; + +#define ENCLAVE1_PATH "libenclave1.so" +#define ENCLAVE2_PATH "libenclave2.so" +#define ENCLAVE3_PATH "libenclave3.so" + +void waitForKeyPress() +{ + char ch; + int temp; + printf("\n\nHit a key....\n"); + temp = scanf_s("%c", &ch); +} + +uint32_t load_enclaves() +{ + uint32_t enclave_temp_no; + int ret, launch_token_updated; + sgx_launch_token_t launch_token; + + enclave_temp_no = 0; + + ret = sgx_create_enclave(ENCLAVE1_PATH, SGX_DEBUG_FLAG, &launch_token, &launch_token_updated, &e1_enclave_id, NULL); + if (ret != SGX_SUCCESS) { + return ret; + } + + enclave_temp_no++; + g_enclave_id_map.insert(std::pair(e1_enclave_id, enclave_temp_no)); + + ret = sgx_create_enclave(ENCLAVE2_PATH, SGX_DEBUG_FLAG, &launch_token, &launch_token_updated, &e2_enclave_id, NULL); + if (ret != SGX_SUCCESS) { + return ret; + } + + enclave_temp_no++; + g_enclave_id_map.insert(std::pair(e2_enclave_id, enclave_temp_no)); + + ret = sgx_create_enclave(ENCLAVE3_PATH, SGX_DEBUG_FLAG, &launch_token, &launch_token_updated, &e3_enclave_id, NULL); + if (ret != SGX_SUCCESS) { + return ret; + } + + enclave_temp_no++; + g_enclave_id_map.insert(std::pair(e3_enclave_id, enclave_temp_no)); + + + + return SGX_SUCCESS; +} + +int _tmain(int argc, _TCHAR* argv[]) +{ + uint32_t ret_status; + sgx_status_t status; + + UNUSED(argc); + UNUSED(argv); + + if(load_enclaves() != SGX_SUCCESS) + { + printf("\nLoad Enclave Failure"); + } + + printf("\nAvaliable Enclaves"); + printf("\nEnclave1 - EnclaveID %" PRIx64, e1_enclave_id); + printf("\nEnclave2 - EnclaveID %" PRIx64, e2_enclave_id); + printf("\nEnclave3 - EnclaveID %" PRIx64, e3_enclave_id); + + do + { + //Test Create session between Enclave1(Source) and Enclave2(Destination) + status = Enclave1_test_create_session(e1_enclave_id, &ret_status, e1_enclave_id, e2_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave1_test_create_session Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nSecure Channel Establishment between Source (E1) and Destination (E2) Enclaves successful !!!"); + } + else + { + printf("\nSession establishment and key exchange failure between Source (E1) and Destination (E2): Error code is %x", ret_status); + break; + } + } + + //Test Enclave to Enclave call between Enclave1(Source) and Enclave2(Destination) + status = Enclave1_test_enclave_to_enclave_call(e1_enclave_id, &ret_status, e1_enclave_id, e2_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave1_test_enclave_to_enclave_call Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nEnclave to Enclave Call between Source (E1) and Destination (E2) Enclaves successful !!!"); + } + else + { + printf("\n\nEnclave to Enclave Call failure between Source (E1) and Destination (E2): Error code is %x", ret_status); + break; + } + } + //Test message exchange between Enclave1(Source) and Enclave2(Destination) + status = Enclave1_test_message_exchange(e1_enclave_id, &ret_status, e1_enclave_id, e2_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave1_test_message_exchange Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nMessage Exchange between Source (E1) and Destination (E2) Enclaves successful !!!"); + } + else + { + printf("\n\nMessage Exchange failure between Source (E1) and Destination (E2): Error code is %x", ret_status); + break; + } + } + //Test Create session between Enclave1(Source) and Enclave3(Destination) + status = Enclave1_test_create_session(e1_enclave_id, &ret_status, e1_enclave_id, e3_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave1_test_create_session Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nSecure Channel Establishment between Source (E1) and Destination (E3) Enclaves successful !!!"); + } + else + { + printf("\n\nSession establishment and key exchange failure between Source (E1) and Destination (E3): Error code is %x", ret_status); + break; + } + } + //Test Enclave to Enclave call between Enclave1(Source) and Enclave3(Destination) + status = Enclave1_test_enclave_to_enclave_call(e1_enclave_id, &ret_status, e1_enclave_id, e3_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave1_test_enclave_to_enclave_call Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nEnclave to Enclave Call between Source (E1) and Destination (E3) Enclaves successful !!!"); + } + else + { + printf("\n\nEnclave to Enclave Call failure between Source (E1) and Destination (E3): Error code is %x", ret_status); + break; + } + } + //Test message exchange between Enclave1(Source) and Enclave3(Destination) + status = Enclave1_test_message_exchange(e1_enclave_id, &ret_status, e1_enclave_id, e3_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave1_test_message_exchange Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nMessage Exchange between Source (E1) and Destination (E3) Enclaves successful !!!"); + } + else + { + printf("\n\nMessage Exchange failure between Source (E1) and Destination (E3): Error code is %x", ret_status); + break; + } + } + + //Test Create session between Enclave2(Source) and Enclave3(Destination) + status = Enclave2_test_create_session(e2_enclave_id, &ret_status, e2_enclave_id, e3_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave2_test_create_session Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nSecure Channel Establishment between Source (E2) and Destination (E3) Enclaves successful !!!"); + } + else + { + printf("\n\nSession establishment and key exchange failure between Source (E2) and Destination (E3): Error code is %x", ret_status); + break; + } + } + //Test Enclave to Enclave call between Enclave2(Source) and Enclave3(Destination) + status = Enclave2_test_enclave_to_enclave_call(e2_enclave_id, &ret_status, e2_enclave_id, e3_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave2_test_enclave_to_enclave_call Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nEnclave to Enclave Call between Source (E2) and Destination (E3) Enclaves successful !!!"); + } + else + { + printf("\n\nEnclave to Enclave Call failure between Source (E2) and Destination (E3): Error code is %x", ret_status); + break; + } + } + //Test message exchange between Enclave2(Source) and Enclave3(Destination) + status = Enclave2_test_message_exchange(e2_enclave_id, &ret_status, e2_enclave_id, e3_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave2_test_message_exchange Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nMessage Exchange between Source (E2) and Destination (E3) Enclaves successful !!!"); + } + else + { + printf("\n\nMessage Exchange failure between Source (E2) and Destination (E3): Error code is %x", ret_status); + break; + } + } + + //Test Create session between Enclave3(Source) and Enclave1(Destination) + status = Enclave3_test_create_session(e3_enclave_id, &ret_status, e3_enclave_id, e1_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave3_test_create_session Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nSecure Channel Establishment between Source (E3) and Destination (E1) Enclaves successful !!!"); + } + else + { + printf("\n\nSession establishment and key exchange failure between Source (E3) and Destination (E1): Error code is %x", ret_status); + break; + } + } + //Test Enclave to Enclave call between Enclave3(Source) and Enclave1(Destination) + status = Enclave3_test_enclave_to_enclave_call(e3_enclave_id, &ret_status, e3_enclave_id, e1_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave3_test_enclave_to_enclave_call Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nEnclave to Enclave Call between Source (E3) and Destination (E1) Enclaves successful !!!"); + } + else + { + printf("\n\nEnclave to Enclave Call failure between Source (E3) and Destination (E1): Error code is %x", ret_status); + break; + } + } + //Test message exchange between Enclave3(Source) and Enclave1(Destination) + status = Enclave3_test_message_exchange(e3_enclave_id, &ret_status, e3_enclave_id, e1_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave3_test_message_exchange Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nMessage Exchange between Source (E3) and Destination (E1) Enclaves successful !!!"); + } + else + { + printf("\n\nMessage Exchange failure between Source (E3) and Destination (E1): Error code is %x", ret_status); + break; + } + } + + + //Test Closing Session between Enclave1(Source) and Enclave2(Destination) + status = Enclave1_test_close_session(e1_enclave_id, &ret_status, e1_enclave_id, e2_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave1_test_close_session Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nClose Session between Source (E1) and Destination (E2) Enclaves successful !!!"); + } + else + { + printf("\n\nClose session failure between Source (E1) and Destination (E2): Error code is %x", ret_status); + break; + } + } + //Test Closing Session between Enclave1(Source) and Enclave3(Destination) + status = Enclave1_test_close_session(e1_enclave_id, &ret_status, e1_enclave_id, e3_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave1_test_close_session Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nClose Session between Source (E1) and Destination (E3) Enclaves successful !!!"); + } + else + { + printf("\n\nClose session failure between Source (E1) and Destination (E3): Error code is %x", ret_status); + break; + } + } + //Test Closing Session between Enclave2(Source) and Enclave3(Destination) + status = Enclave2_test_close_session(e2_enclave_id, &ret_status, e2_enclave_id, e3_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave2_test_close_session Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nClose Session between Source (E2) and Destination (E3) Enclaves successful !!!"); + } + else + { + printf("\n\nClose session failure between Source (E2) and Destination (E3): Error code is %x", ret_status); + break; + } + } + //Test Closing Session between Enclave3(Source) and Enclave1(Destination) + status = Enclave3_test_close_session(e3_enclave_id, &ret_status, e3_enclave_id, e1_enclave_id); + if (status!=SGX_SUCCESS) + { + printf("Enclave3_test_close_session Ecall failed: Error code is %x", status); + break; + } + else + { + if(ret_status==0) + { + printf("\n\nClose Session between Source (E3) and Destination (E1) Enclaves successful !!!"); + } + else + { + printf("\n\nClose session failure between Source (E3) and Destination (E1): Error code is %x", ret_status); + break; + } + } + +#pragma warning (push) +#pragma warning (disable : 4127) + }while(0); +#pragma warning (pop) + + sgx_destroy_enclave(e1_enclave_id); + sgx_destroy_enclave(e2_enclave_id); + sgx_destroy_enclave(e3_enclave_id); + + waitForKeyPress(); + + return 0; +} diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Enclave1.config.xml b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Enclave1.config.xml new file mode 100644 index 0000000000..436860dd50 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Enclave1.config.xml @@ -0,0 +1,11 @@ + + 0 + 0 + 0x40000 + 0x100000 + 1 + 1 + 0 + 0 + 0xFFFFFFFF + diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Enclave1.cpp b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Enclave1.cpp new file mode 100644 index 0000000000..c662516d1d --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Enclave1.cpp @@ -0,0 +1,373 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +// Enclave1.cpp : Defines the exported functions for the .so application +#include "sgx_eid.h" +#include "Enclave1_t.h" +#include "EnclaveMessageExchange.h" +#include "error_codes.h" +#include "Utility_E1.h" +#include "sgx_thread.h" +#include "sgx_dh.h" +#include + +#define UNUSED(val) (void)(val) + +std::mapg_src_session_info_map; + +static uint32_t e1_foo1_wrapper(ms_in_msg_exchange_t *ms, size_t param_lenth, char** resp_buffer, size_t* resp_length); + +//Function pointer table containing the list of functions that the enclave exposes +const struct { + size_t num_funcs; + const void* table[1]; +} func_table = { + 1, + { + (const void*)e1_foo1_wrapper, + } +}; + +//Makes use of the sample code function to establish a secure channel with the destination enclave (Test Vector) +uint32_t test_create_session(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id) +{ + ATTESTATION_STATUS ke_status = SUCCESS; + dh_session_t dest_session_info; + + //Core reference code function for creating a session + ke_status = create_session(src_enclave_id, dest_enclave_id, &dest_session_info); + + //Insert the session information into the map under the corresponding destination enclave id + if(ke_status == SUCCESS) + { + g_src_session_info_map.insert(std::pair(dest_enclave_id, dest_session_info)); + } + memset(&dest_session_info, 0, sizeof(dh_session_t)); + return ke_status; +} + +//Makes use of the sample code function to do an enclave to enclave call (Test Vector) +uint32_t test_enclave_to_enclave_call(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id) +{ + ATTESTATION_STATUS ke_status = SUCCESS; + uint32_t var1,var2; + uint32_t target_fn_id, msg_type; + char* marshalled_inp_buff; + size_t marshalled_inp_buff_len; + char* out_buff; + size_t out_buff_len; + dh_session_t *dest_session_info; + size_t max_out_buff_size; + char* retval; + + var1 = 0x4; + var2 = 0x5; + target_fn_id = 0; + msg_type = ENCLAVE_TO_ENCLAVE_CALL; + max_out_buff_size = 50; + + //Marshals the input parameters for calling function foo1 in Enclave2 into a input buffer + ke_status = marshal_input_parameters_e2_foo1(target_fn_id, msg_type, var1, var2, &marshalled_inp_buff, &marshalled_inp_buff_len); + if(ke_status != SUCCESS) + { + return ke_status; + } + + //Search the map for the session information associated with the destination enclave id of Enclave2 passed in + std::map::iterator it = g_src_session_info_map.find(dest_enclave_id); + if(it != g_src_session_info_map.end()) + { + dest_session_info = &it->second; + } + else + { + SAFE_FREE(marshalled_inp_buff); + return INVALID_SESSION; + } + + //Core Reference Code function + ke_status = send_request_receive_response(src_enclave_id, dest_enclave_id, dest_session_info, marshalled_inp_buff, + marshalled_inp_buff_len, max_out_buff_size, &out_buff, &out_buff_len); + + + if(ke_status != SUCCESS) + { + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + return ke_status; + } + + //Un-marshal the return value and output parameters from foo1 of Enclave 2 + ke_status = unmarshal_retval_and_output_parameters_e2_foo1(out_buff, &retval); + if(ke_status != SUCCESS) + { + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + return ke_status; + } + + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + SAFE_FREE(retval); + return SUCCESS; +} + +//Makes use of the sample code function to do a generic secret message exchange (Test Vector) +uint32_t test_message_exchange(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id) +{ + ATTESTATION_STATUS ke_status = SUCCESS; + uint32_t target_fn_id, msg_type; + char* marshalled_inp_buff; + size_t marshalled_inp_buff_len; + char* out_buff; + size_t out_buff_len; + dh_session_t *dest_session_info; + size_t max_out_buff_size; + char* secret_response; + uint32_t secret_data; + + target_fn_id = 0; + msg_type = MESSAGE_EXCHANGE; + max_out_buff_size = 50; + secret_data = 0x12345678; //Secret Data here is shown only for purpose of demonstration. + + //Marshals the secret data into a buffer + ke_status = marshal_message_exchange_request(target_fn_id, msg_type, secret_data, &marshalled_inp_buff, &marshalled_inp_buff_len); + if(ke_status != SUCCESS) + { + return ke_status; + } + //Search the map for the session information associated with the destination enclave id passed in + std::map::iterator it = g_src_session_info_map.find(dest_enclave_id); + if(it != g_src_session_info_map.end()) + { + dest_session_info = &it->second; + } + else + { + SAFE_FREE(marshalled_inp_buff); + return INVALID_SESSION; + } + + //Core Reference Code function + ke_status = send_request_receive_response(src_enclave_id, dest_enclave_id, dest_session_info, marshalled_inp_buff, + marshalled_inp_buff_len, max_out_buff_size, &out_buff, &out_buff_len); + if(ke_status != SUCCESS) + { + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + return ke_status; + } + + //Un-marshal the secret response data + ke_status = umarshal_message_exchange_response(out_buff, &secret_response); + if(ke_status != SUCCESS) + { + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + return ke_status; + } + + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + SAFE_FREE(secret_response); + return SUCCESS; +} + + +//Makes use of the sample code function to close a current session +uint32_t test_close_session(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id) +{ + dh_session_t dest_session_info; + ATTESTATION_STATUS ke_status = SUCCESS; + //Search the map for the session information associated with the destination enclave id passed in + std::map::iterator it = g_src_session_info_map.find(dest_enclave_id); + if(it != g_src_session_info_map.end()) + { + dest_session_info = it->second; + } + else + { + return NULL; + } + + //Core reference code function for closing a session + ke_status = close_session(src_enclave_id, dest_enclave_id); + + //Erase the session information associated with the destination enclave id + g_src_session_info_map.erase(dest_enclave_id); + return ke_status; +} + +//Function that is used to verify the trust of the other enclave +//Each enclave can have its own way verifying the peer enclave identity +extern "C" uint32_t verify_peer_enclave_trust(sgx_dh_session_enclave_identity_t* peer_enclave_identity) +{ + if(!peer_enclave_identity) + { + return INVALID_PARAMETER_ERROR; + } + if(peer_enclave_identity->isv_prod_id != 0 || !(peer_enclave_identity->attributes.flags & SGX_FLAGS_INITTED)) + // || peer_enclave_identity->attributes.xfrm !=3)// || peer_enclave_identity->mr_signer != xx //TODO: To be hardcoded with values to check + { + return ENCLAVE_TRUST_ERROR; + } + else + { + return SUCCESS; + } +} + + +//Dispatcher function that calls the approriate enclave function based on the function id +//Each enclave can have its own way of dispatching the calls from other enclave +extern "C" uint32_t enclave_to_enclave_call_dispatcher(char* decrypted_data, + size_t decrypted_data_length, + char** resp_buffer, + size_t* resp_length) +{ + ms_in_msg_exchange_t *ms; + uint32_t (*fn1)(ms_in_msg_exchange_t *ms, size_t, char**, size_t*); + if(!decrypted_data || !resp_length) + { + return INVALID_PARAMETER_ERROR; + } + ms = (ms_in_msg_exchange_t *)decrypted_data; + if(ms->target_fn_id >= func_table.num_funcs) + { + return INVALID_PARAMETER_ERROR; + } + fn1 = (uint32_t (*)(ms_in_msg_exchange_t*, size_t, char**, size_t*))func_table.table[ms->target_fn_id]; + return fn1(ms, decrypted_data_length, resp_buffer, resp_length); +} + +//Operates on the input secret and generates the output secret +uint32_t get_message_exchange_response(uint32_t inp_secret_data) +{ + uint32_t secret_response; + + //User should use more complex encryption method to protect their secret, below is just a simple example + secret_response = inp_secret_data & 0x11111111; + + return secret_response; + +} + +//Generates the response from the request message +extern "C" uint32_t message_exchange_response_generator(char* decrypted_data, + char** resp_buffer, + size_t* resp_length) +{ + ms_in_msg_exchange_t *ms; + uint32_t inp_secret_data; + uint32_t out_secret_data; + if(!decrypted_data || !resp_length) + { + return INVALID_PARAMETER_ERROR; + } + ms = (ms_in_msg_exchange_t *)decrypted_data; + + if(umarshal_message_exchange_request(&inp_secret_data,ms) != SUCCESS) + return ATTESTATION_ERROR; + + out_secret_data = get_message_exchange_response(inp_secret_data); + + if(marshal_message_exchange_response(resp_buffer, resp_length, out_secret_data) != SUCCESS) + return MALLOC_ERROR; + + return SUCCESS; + +} + + +static uint32_t e1_foo1(external_param_struct_t *p_struct_var) +{ + if(!p_struct_var) + { + return INVALID_PARAMETER_ERROR; + } + (p_struct_var->var1)++; + (p_struct_var->var2)++; + (p_struct_var->p_internal_struct->ivar1)++; + (p_struct_var->p_internal_struct->ivar2)++; + + return (p_struct_var->var1 + p_struct_var->var2 + p_struct_var->p_internal_struct->ivar1 + p_struct_var->p_internal_struct->ivar2); +} + +//Function which is executed on request from the source enclave +static uint32_t e1_foo1_wrapper(ms_in_msg_exchange_t *ms, + size_t param_lenth, + char** resp_buffer, + size_t* resp_length) +{ + UNUSED(param_lenth); + + uint32_t ret; + size_t len_data, len_ptr_data; + external_param_struct_t *p_struct_var; + internal_param_struct_t internal_struct_var; + + if(!ms || !resp_length) + { + return INVALID_PARAMETER_ERROR; + } + + p_struct_var = (external_param_struct_t*)malloc(sizeof(external_param_struct_t)); + if(!p_struct_var) + return MALLOC_ERROR; + + p_struct_var->p_internal_struct = &internal_struct_var; + + if(unmarshal_input_parameters_e1_foo1(p_struct_var, ms) != SUCCESS)//can use the stack + { + SAFE_FREE(p_struct_var); + return ATTESTATION_ERROR; + } + + ret = e1_foo1(p_struct_var); + + len_data = sizeof(external_param_struct_t) - sizeof(p_struct_var->p_internal_struct); + len_ptr_data = sizeof(internal_struct_var); + + if(marshal_retval_and_output_parameters_e1_foo1(resp_buffer, resp_length, ret, p_struct_var, len_data, len_ptr_data) != SUCCESS) + { + SAFE_FREE(p_struct_var); + return MALLOC_ERROR; + } + SAFE_FREE(p_struct_var); + return SUCCESS; +} + diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Enclave1.edl b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Enclave1.edl new file mode 100644 index 0000000000..378965cd11 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Enclave1.edl @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +enclave { + include "sgx_eid.h" + from "../LocalAttestationCode/LocalAttestationCode.edl" import *; + from "sgx_tstdc.edl" import *; + trusted{ + public uint32_t test_create_session(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + public uint32_t test_enclave_to_enclave_call(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + public uint32_t test_message_exchange(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + public uint32_t test_close_session(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + }; + +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Enclave1_private.pem b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Enclave1_private.pem new file mode 100644 index 0000000000..75d7f88cb9 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Enclave1_private.pem @@ -0,0 +1,39 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIG4wIBAAKCAYEAuJh4w/KzndQhzEqwH6Ut/3BmOom5CN117KT1/cemEbDLPhn0 +c5yjAfe4NL1qtGqz0RTK9X9BBSi89b6BrsM9S6c2cUJaeYAPrAtJ+IuzN/5BAmmf +RXbPccETd7rHvDdQ9KBRjCipTx+H0D5nOB76S5PZPVrduwrCmSqVFmLNVWWfPYQx +YewbJ2QfEfioICZFYR0Jou38mJqDTl+CH0gLAuQ4n1kdpQ3VGymzt3oUiPzf5ImJ +oZh5HjarRRiWV+cyNyXYJTnx0dOtFQDgd8HhniagbRB0ZOIt6599JjMkWGkVP0Ni +U/NIlXG5musU35GfLB8MbTcxblMNm9sMYz1R8y/eAreoPTXUhtK8NG2TEywRh3UP +RF9/jM9WczjQXxJ3RznKOwNVwg4cRY2AOqD2vb1iGSqyc/WMzVULgfclkcScp75/ +Auz9Y6473CQvaxyrseSWHGwCG7KG1GxYE8Bg8T6OlYD4mzKggoMdwVLAzUepRaPZ +5hqRDZzbTGUxJ+GLAgEDAoIBgHsQUIKhzRPiwTLcdWpuHqpK7tGxJgXo+Uht+VPa +brZ13NQRTaJobKv6es3TnHhHIotjMfj/gK4bKKPUVnSCKN0aJEuBkaZVX8gHhqWy +d3qpgKxGai5PNPaAt6UnL9LPi03ANl1wcN9qWorURNAUpt0NO348k9IHLGYcY2RB +3jjuaikCy5adZ2+YFLalxWrELkC+BmyeqGW8V4mVAWowB1dC0Go7aRiz42dxInpR +YwX96phbsRZlphQkci4QZDqaIFg3ndzTO5bo704zaMcbWtEjmFrYRyb519tRoDkN +Y0rGwOxFANeRV5dSfGGLm7K5JztiuHN0nMu3PhY4LOV0SeZ4+5sYn0LzB2nyKqgy +/c3AA2OG34DEdGxxh94kD66iKFVPyJG38/gnu9CsGmrLl3n4fgutPEVIbPdSSjex +4Y9EQfcnqImPxTrpP9CqD208VPcQHD/uy8s9q3961Ew3RPdHMZ8amIJdXkOmPEme +KZ7SG+VENBaj8r038iq1mPzcWwKBwQDcvJg75LfVuKX+cWMrTO2+MFVcEFiZ/NB/ +gh7mgL6lCleROVa9P6iR2Wn6vHq8nP5BkChehm/rXEG78fgXEMoArimF7FrrICfI +4yB0opDJz/tWrE/62impN7OR8Ce+RQThFj4RTnibQEEVt++JMUXFiMKLdWDSpC2i +tNWnlTOb7d89bk0yk62IoLElCZK/MIMxkCHBKW6YgrmvlPJKQwpA6Z3wQbUpE6Rb +9f8xJfxZGEJPH0s3Ds9A0CVuEt8OOXcCgcEA1hXTHhhgmb2gIUJgIcvrpkDmiLux +EG6ZoyLt6h5QwzScS6KKU1mcoJyVDd0wlt7mEXrPYYHWUWPuvpTQ8/4ZGMw7FCZe +bakhnwRbw36FlLwRG35wCF6nQO1XFBKRGto15ivfTyDvMpJBdtNpET5NwT/ifDF3 +OWS7t6TGhtcfnvBad5S1AgGoAq+q/huFiBGpDbxJ+1xh0lNL5Z8nVypvPWomNpde +rpLuwRPEIb+GBfQ9Hp5AjRXVsPjKnkHsnl2NAoHBAJMoZX1DJTklw/72Qhzd89Qg +OOgK5bv94FUBae8Afxixj7YmOdN/xbaQ8VHS/H29/tZgGumu9UeS1n1L+roLMVXJ +cQPy50dqxTCXavhsYIaKp48diqc8G8YlImFKxSmDWJYO1AuJpbzVgLklSlt2LoOw +gbJOQIxtc8HN48UOImfz6ij0M3cNHlsVy24GYdTLAiEKwStw9GWse8pjTDGCBtXx +E/WBI3C3wuf5VMtuqDtlgYoU3M9fNNXgGPQMlLQmTwKBwQCOuTdpZZW708AWLEAW +h/Ju1e8F0nYK9GZswfPxaYsszb2HwbGM5mhrEw4JPiBklJlg/IpBATmLl/R/DeCi +qWYQiCdixD7zxhZqAufXqa5jKAtnqaAFlG+AnjoNYbYR5s6ZcpTfa0ohttZPN5tg +1DPWKpb9dk97mH0lGIRZ5L+/Sub6YyNWq8VXH8dUElkFYRtefYankuvhjN1Dv2+P +cZ9+RsQkZOnJt0nWDS1r1QQD+Ci/FCsIuTkgpdxpgUhpk7MCgcEAkfkmaBDb7DG2 +Kc39R6ZZuPnV10w+WOpph7ugwcguG/E0wGq+jFWv6HFckCPeHT4BNtOk8Dem/kPp +teF51eAuFWEefj2tScvlSBBPcnla+WzMWXrlxVnajTt73w+oT2Ql//WhgREpsNfx +SvU80YPVu4GJfl+hhxBifLx+0FM20OESW93qFRc3p040bNrDY9JIZuly/y5zaiBa +mRZF9H8P+x3Lu5AJpdXQEOMZ/XJ/xkoWWjbTojkmgOmmZSMLd5Te +-----END RSA PRIVATE KEY----- diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Utility_E1.cpp b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Utility_E1.cpp new file mode 100644 index 0000000000..9c2247b716 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Utility_E1.cpp @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "sgx_eid.h" +#include "EnclaveMessageExchange.h" +#include "error_codes.h" +#include "Utility_E1.h" +#include "stdlib.h" +#include "string.h" + +uint32_t marshal_input_parameters_e2_foo1(uint32_t target_fn_id, uint32_t msg_type, uint32_t var1, uint32_t var2, char** marshalled_buff, size_t* marshalled_buff_len) +{ + ms_in_msg_exchange_t *ms; + size_t param_len, ms_len; + char *temp_buff; + + param_len = sizeof(var1)+sizeof(var2); + temp_buff = (char*)malloc(param_len); + if(!temp_buff) + return MALLOC_ERROR; + + memcpy(temp_buff,&var1,sizeof(var1)); + memcpy(temp_buff+sizeof(var1),&var2,sizeof(var2)); + ms_len = sizeof(ms_in_msg_exchange_t) + param_len; + ms = (ms_in_msg_exchange_t *)malloc(ms_len); + if(!ms) + { + SAFE_FREE(temp_buff); + return MALLOC_ERROR; + } + ms->msg_type = msg_type; + ms->target_fn_id = target_fn_id; + ms->inparam_buff_len = (uint32_t)param_len; + memcpy(&ms->inparam_buff, temp_buff, param_len); + *marshalled_buff = (char*)ms; + *marshalled_buff_len = ms_len; + SAFE_FREE(temp_buff); + return SUCCESS; +} + +uint32_t unmarshal_retval_and_output_parameters_e2_foo1(char* out_buff, char** retval) +{ + size_t retval_len; + ms_out_msg_exchange_t *ms; + if(!out_buff) + return INVALID_PARAMETER_ERROR; + ms = (ms_out_msg_exchange_t *)out_buff; + retval_len = ms->retval_len; + *retval = (char*)malloc(retval_len); + if(!*retval) + return MALLOC_ERROR; + + memcpy(*retval, ms->ret_outparam_buff, retval_len); + return SUCCESS; +} + +uint32_t unmarshal_input_parameters_e1_foo1(external_param_struct_t *pstruct, ms_in_msg_exchange_t* ms) +{ + char* buff; + size_t len; + if(!pstruct || !ms) + return INVALID_PARAMETER_ERROR; + + buff = ms->inparam_buff; + len = ms->inparam_buff_len; + if(len != (sizeof(pstruct->var1)+sizeof(pstruct->var2)+sizeof(pstruct->p_internal_struct->ivar1)+sizeof(pstruct->p_internal_struct->ivar2))) + return ATTESTATION_ERROR; + + memcpy(&pstruct->var1, buff, sizeof(pstruct->var1)); + memcpy(&pstruct->var2, buff + sizeof(pstruct->var1), sizeof(pstruct->var2)); + memcpy(&pstruct->p_internal_struct->ivar1, buff+(sizeof(pstruct->var1)+sizeof(pstruct->var2)), sizeof(pstruct->p_internal_struct->ivar1)); + memcpy(&pstruct->p_internal_struct->ivar2, buff+(sizeof(pstruct->var1)+sizeof(pstruct->var2)+sizeof(pstruct->p_internal_struct->ivar1)), sizeof(pstruct->p_internal_struct->ivar2)); + + return SUCCESS; +} + +uint32_t marshal_retval_and_output_parameters_e1_foo1(char** resp_buffer, size_t* resp_length, uint32_t retval, external_param_struct_t *p_struct_var, size_t len_data, size_t len_ptr_data) +{ + ms_out_msg_exchange_t *ms; + size_t param_len, ms_len, ret_param_len;; + char *temp_buff; + int* addr; + char* struct_data; + size_t retval_len; + + if(!resp_length || !p_struct_var) + return INVALID_PARAMETER_ERROR; + + retval_len = sizeof(retval); + struct_data = (char*)p_struct_var; + param_len = len_data + len_ptr_data; + ret_param_len = param_len + retval_len; + addr = *(int **)(struct_data + len_data); + temp_buff = (char*)malloc(ret_param_len); + if(!temp_buff) + return MALLOC_ERROR; + + memcpy(temp_buff, &retval, sizeof(retval)); + memcpy(temp_buff + sizeof(retval), struct_data, len_data); + memcpy(temp_buff + sizeof(retval) + len_data, addr, len_ptr_data); + ms_len = sizeof(ms_out_msg_exchange_t) + ret_param_len; + ms = (ms_out_msg_exchange_t *)malloc(ms_len); + if(!ms) + { + SAFE_FREE(temp_buff); + return MALLOC_ERROR; + } + ms->retval_len = (uint32_t)retval_len; + ms->ret_outparam_buff_len = (uint32_t)ret_param_len; + memcpy(&ms->ret_outparam_buff, temp_buff, ret_param_len); + *resp_buffer = (char*)ms; + *resp_length = ms_len; + + SAFE_FREE(temp_buff); + return SUCCESS; +} + +uint32_t marshal_message_exchange_request(uint32_t target_fn_id, uint32_t msg_type, uint32_t secret_data, char** marshalled_buff, size_t* marshalled_buff_len) +{ + ms_in_msg_exchange_t *ms; + size_t secret_data_len, ms_len; + if(!marshalled_buff_len) + return INVALID_PARAMETER_ERROR; + secret_data_len = sizeof(secret_data); + ms_len = sizeof(ms_in_msg_exchange_t) + secret_data_len; + ms = (ms_in_msg_exchange_t *)malloc(ms_len); + if(!ms) + return MALLOC_ERROR; + + ms->msg_type = msg_type; + ms->target_fn_id = target_fn_id; + ms->inparam_buff_len = (uint32_t)secret_data_len; + memcpy(&ms->inparam_buff, &secret_data, secret_data_len); + *marshalled_buff = (char*)ms; + *marshalled_buff_len = ms_len; + return SUCCESS; +} + +uint32_t umarshal_message_exchange_request(uint32_t* inp_secret_data, ms_in_msg_exchange_t* ms) +{ + char* buff; + size_t len; + if(!inp_secret_data || !ms) + return INVALID_PARAMETER_ERROR; + buff = ms->inparam_buff; + len = ms->inparam_buff_len; + if(len != sizeof(uint32_t)) + return ATTESTATION_ERROR; + + memcpy(inp_secret_data, buff, sizeof(uint32_t)); + + return SUCCESS; +} + +uint32_t marshal_message_exchange_response(char** resp_buffer, size_t* resp_length, uint32_t secret_response) +{ + ms_out_msg_exchange_t *ms; + size_t secret_response_len, ms_len; + size_t retval_len, ret_param_len; + if(!resp_length) + return INVALID_PARAMETER_ERROR; + secret_response_len = sizeof(secret_response); + retval_len = secret_response_len; + ret_param_len = secret_response_len; + ms_len = sizeof(ms_out_msg_exchange_t) + ret_param_len; + ms = (ms_out_msg_exchange_t *)malloc(ms_len); + if(!ms) + return MALLOC_ERROR; + + ms->retval_len = (uint32_t)retval_len; + ms->ret_outparam_buff_len = (uint32_t)ret_param_len; + memcpy(&ms->ret_outparam_buff, &secret_response, secret_response_len); + *resp_buffer = (char*)ms; + *resp_length = ms_len; + return SUCCESS; +} + +uint32_t umarshal_message_exchange_response(char* out_buff, char** secret_response) +{ + size_t retval_len; + ms_out_msg_exchange_t *ms; + if(!out_buff) + return INVALID_PARAMETER_ERROR; + ms = (ms_out_msg_exchange_t *)out_buff; + retval_len = ms->retval_len; + *secret_response = (char*)malloc(retval_len); + if(!*secret_response) + { + return MALLOC_ERROR; + } + memcpy(*secret_response, ms->ret_outparam_buff, retval_len); + return SUCCESS; +} + diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Utility_E1.h b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Utility_E1.h new file mode 100644 index 0000000000..7af49b6814 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave1/Utility_E1.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef UTILITY_E1_H__ +#define UTILITY_E1_H__ + +#include "stdint.h" + +typedef struct _internal_param_struct_t +{ + uint32_t ivar1; + uint32_t ivar2; +}internal_param_struct_t; + +typedef struct _external_param_struct_t +{ + uint32_t var1; + uint32_t var2; + internal_param_struct_t *p_internal_struct; +}external_param_struct_t; + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t marshal_input_parameters_e2_foo1(uint32_t target_fn_id, uint32_t msg_type, uint32_t var1, uint32_t var2, char** marshalled_buff, size_t* marshalled_buff_len); +uint32_t unmarshal_retval_and_output_parameters_e2_foo1(char* out_buff, char** retval); +uint32_t unmarshal_input_parameters_e1_foo1(external_param_struct_t *pstruct, ms_in_msg_exchange_t* ms); +uint32_t marshal_retval_and_output_parameters_e1_foo1(char** resp_buffer, size_t* resp_length, uint32_t retval, external_param_struct_t *p_struct_var, size_t len_data, size_t len_ptr_data); +uint32_t marshal_message_exchange_request(uint32_t target_fn_id, uint32_t msg_type, uint32_t secret_data, char** marshalled_buff, size_t* marshalled_buff_len); +uint32_t umarshal_message_exchange_request(uint32_t* inp_secret_data, ms_in_msg_exchange_t* ms); +uint32_t marshal_message_exchange_response(char** resp_buffer, size_t* resp_length, uint32_t secret_response); +uint32_t umarshal_message_exchange_response(char* out_buff, char** secret_response); +#ifdef __cplusplus + } +#endif +#endif diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Enclave2.config.xml b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Enclave2.config.xml new file mode 100644 index 0000000000..3317e37a37 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Enclave2.config.xml @@ -0,0 +1,11 @@ + + 0 + 0 + 0x40000 + 0x100000 + 1 + 1 + 0 + 0 + 0xFFFFFFFF + diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Enclave2.cpp b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Enclave2.cpp new file mode 100644 index 0000000000..537957f68c --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Enclave2.cpp @@ -0,0 +1,339 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +// Enclave2.cpp : Defines the exported functions for the DLL application +#include "sgx_eid.h" +#include "Enclave2_t.h" +#include "EnclaveMessageExchange.h" +#include "error_codes.h" +#include "Utility_E2.h" +#include "sgx_thread.h" +#include "sgx_dh.h" +#include + +#define UNUSED(val) (void)(val) + +std::mapg_src_session_info_map; + +static uint32_t e2_foo1_wrapper(ms_in_msg_exchange_t *ms, size_t param_lenth, char** resp_buffer, size_t* resp_length); + +//Function pointer table containing the list of functions that the enclave exposes +const struct { + size_t num_funcs; + const void* table[1]; +} func_table = { + 1, + { + (const void*)e2_foo1_wrapper, + } +}; + +//Makes use of the sample code function to establish a secure channel with the destination enclave +uint32_t test_create_session(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id) +{ + ATTESTATION_STATUS ke_status = SUCCESS; + dh_session_t dest_session_info; + //Core reference code function for creating a session + ke_status = create_session(src_enclave_id, dest_enclave_id,&dest_session_info); + if(ke_status == SUCCESS) + { + //Insert the session information into the map under the corresponding destination enclave id + g_src_session_info_map.insert(std::pair(dest_enclave_id, dest_session_info)); + } + memset(&dest_session_info, 0, sizeof(dh_session_t)); + return ke_status; +} + +//Makes use of the sample code function to do an enclave to enclave call (Test Vector) +uint32_t test_enclave_to_enclave_call(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id) +{ + ATTESTATION_STATUS ke_status = SUCCESS; + param_struct_t *p_struct_var, struct_var; + uint32_t target_fn_id, msg_type; + char* marshalled_inp_buff; + size_t marshalled_inp_buff_len; + char* out_buff; + size_t out_buff_len; + dh_session_t *dest_session_info; + size_t max_out_buff_size; + char* retval; + + max_out_buff_size = 50; + target_fn_id = 0; + msg_type = ENCLAVE_TO_ENCLAVE_CALL; + + struct_var.var1 = 0x3; + struct_var.var2 = 0x4; + p_struct_var = &struct_var; + + //Marshals the input parameters for calling function foo1 in Enclave3 into a input buffer + ke_status = marshal_input_parameters_e3_foo1(target_fn_id, msg_type, p_struct_var, &marshalled_inp_buff, &marshalled_inp_buff_len); + if(ke_status != SUCCESS) + { + return ke_status; + } + + //Search the map for the session information associated with the destination enclave id passed in + std::map::iterator it = g_src_session_info_map.find(dest_enclave_id); + if(it != g_src_session_info_map.end()) + { + dest_session_info = &it->second; + } + else + { + SAFE_FREE(marshalled_inp_buff); + return INVALID_SESSION; + } + + //Core Reference Code function + ke_status = send_request_receive_response(src_enclave_id, dest_enclave_id, dest_session_info, marshalled_inp_buff, + marshalled_inp_buff_len, max_out_buff_size, &out_buff, &out_buff_len); + + if(ke_status != SUCCESS) + { + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + return ke_status; + } + + //Un-marshal the return value and output parameters from foo1 of Enclave3 + ke_status = unmarshal_retval_and_output_parameters_e3_foo1(out_buff, p_struct_var, &retval); + if(ke_status != SUCCESS) + { + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + return ke_status; + } + + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + SAFE_FREE(retval); + return SUCCESS; +} + +//Makes use of the sample code function to do a generic secret message exchange (Test Vector) +uint32_t test_message_exchange(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id) +{ + ATTESTATION_STATUS ke_status = SUCCESS; + uint32_t target_fn_id, msg_type; + char* marshalled_inp_buff; + size_t marshalled_inp_buff_len; + char* out_buff; + size_t out_buff_len; + dh_session_t *dest_session_info; + size_t max_out_buff_size; + char* secret_response; + uint32_t secret_data; + + target_fn_id = 0; + msg_type = MESSAGE_EXCHANGE; + max_out_buff_size = 50; + secret_data = 0x12345678; //Secret Data here is shown only for purpose of demonstration. + + //Marshals the secret data into a buffer + ke_status = marshal_message_exchange_request(target_fn_id, msg_type, secret_data, &marshalled_inp_buff, &marshalled_inp_buff_len); + if(ke_status != SUCCESS) + { + return ke_status; + } + //Search the map for the session information associated with the destination enclave id passed in + std::map::iterator it = g_src_session_info_map.find(dest_enclave_id); + if(it != g_src_session_info_map.end()) + { + dest_session_info = &it->second; + } + else + { + SAFE_FREE(marshalled_inp_buff); + return INVALID_SESSION; + } + + //Core Reference Code function + ke_status = send_request_receive_response(src_enclave_id, dest_enclave_id, dest_session_info, marshalled_inp_buff, + marshalled_inp_buff_len, max_out_buff_size, &out_buff, &out_buff_len); + if(ke_status != SUCCESS) + { + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + return ke_status; + } + + //Un-marshal the secret response data + ke_status = umarshal_message_exchange_response(out_buff, &secret_response); + if(ke_status != SUCCESS) + { + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + return ke_status; + } + + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + SAFE_FREE(secret_response); + return SUCCESS; +} + + +//Makes use of the sample code function to close a current session +uint32_t test_close_session(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id) +{ + dh_session_t dest_session_info; + ATTESTATION_STATUS ke_status = SUCCESS; + //Search the map for the session information associated with the destination enclave id passed in + std::map::iterator it = g_src_session_info_map.find(dest_enclave_id); + if(it != g_src_session_info_map.end()) + { + dest_session_info = it->second; + } + else + { + return NULL; + } + //Core reference code function for closing a session + ke_status = close_session(src_enclave_id, dest_enclave_id); + + //Erase the session information associated with the destination enclave id + g_src_session_info_map.erase(dest_enclave_id); + return ke_status; +} + +//Function that is used to verify the trust of the other enclave +//Each enclave can have its own way verifying the peer enclave identity +extern "C" uint32_t verify_peer_enclave_trust(sgx_dh_session_enclave_identity_t* peer_enclave_identity) +{ + if(!peer_enclave_identity) + { + return INVALID_PARAMETER_ERROR; + } + if(peer_enclave_identity->isv_prod_id != 0 || !(peer_enclave_identity->attributes.flags & SGX_FLAGS_INITTED)) + // || peer_enclave_identity->attributes.xfrm !=3)// || peer_enclave_identity->mr_signer != xx //TODO: To be hardcoded with values to check + { + return ENCLAVE_TRUST_ERROR; + } + else + { + return SUCCESS; + } +} + +//Dispatch function that calls the approriate enclave function based on the function id +//Each enclave can have its own way of dispatching the calls from other enclave +extern "C" uint32_t enclave_to_enclave_call_dispatcher(char* decrypted_data, + size_t decrypted_data_length, + char** resp_buffer, + size_t* resp_length) +{ + ms_in_msg_exchange_t *ms; + uint32_t (*fn1)(ms_in_msg_exchange_t *ms, size_t, char**, size_t*); + if(!decrypted_data || !resp_length) + { + return INVALID_PARAMETER_ERROR; + } + ms = (ms_in_msg_exchange_t *)decrypted_data; + if(ms->target_fn_id >= func_table.num_funcs) + { + return INVALID_PARAMETER_ERROR; + } + fn1 = (uint32_t (*)(ms_in_msg_exchange_t*, size_t, char**, size_t*))func_table.table[ms->target_fn_id]; + return fn1(ms, decrypted_data_length, resp_buffer, resp_length); +} + +//Operates on the input secret and generates the output secret +uint32_t get_message_exchange_response(uint32_t inp_secret_data) +{ + uint32_t secret_response; + + //User should use more complex encryption method to protect their secret, below is just a simple example + secret_response = inp_secret_data & 0x11111111; + + return secret_response; + +} + +//Generates the response from the request message +extern "C" uint32_t message_exchange_response_generator(char* decrypted_data, + char** resp_buffer, + size_t* resp_length) +{ + ms_in_msg_exchange_t *ms; + uint32_t inp_secret_data; + uint32_t out_secret_data; + if(!decrypted_data || !resp_length) + { + return INVALID_PARAMETER_ERROR; + } + ms = (ms_in_msg_exchange_t *)decrypted_data; + + if(umarshal_message_exchange_request(&inp_secret_data,ms) != SUCCESS) + return ATTESTATION_ERROR; + + out_secret_data = get_message_exchange_response(inp_secret_data); + + if(marshal_message_exchange_response(resp_buffer, resp_length, out_secret_data) != SUCCESS) + return MALLOC_ERROR; + + return SUCCESS; + +} + +static uint32_t e2_foo1(uint32_t var1, uint32_t var2) +{ + return(var1 + var2); +} + +//Function which is executed on request from the source enclave +static uint32_t e2_foo1_wrapper(ms_in_msg_exchange_t *ms, + size_t param_lenth, + char** resp_buffer, + size_t* resp_length) +{ + UNUSED(param_lenth); + + uint32_t var1,var2,ret; + if(!ms || !resp_length) + { + return INVALID_PARAMETER_ERROR; + } + if(unmarshal_input_parameters_e2_foo1(&var1, &var2, ms) != SUCCESS) + return ATTESTATION_ERROR; + + ret = e2_foo1(var1, var2); + + if(marshal_retval_and_output_parameters_e2_foo1(resp_buffer, resp_length, ret) != SUCCESS ) + return MALLOC_ERROR; //can set resp buffer to null here + + return SUCCESS; +} diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Enclave2.edl b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Enclave2.edl new file mode 100644 index 0000000000..9ef5c33e4c --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Enclave2.edl @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +enclave { + include "sgx_eid.h" + from "../LocalAttestationCode/LocalAttestationCode.edl" import *; + from "sgx_tstdc.edl" import *; + trusted{ + public uint32_t test_create_session(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + public uint32_t test_enclave_to_enclave_call(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + public uint32_t test_message_exchange(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + public uint32_t test_close_session(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + }; +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Enclave2_private.pem b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Enclave2_private.pem new file mode 100644 index 0000000000..529d07be35 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Enclave2_private.pem @@ -0,0 +1,39 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIG4gIBAAKCAYEAroOogvsj/fZDZY8XFdkl6dJmky0lRvnWMmpeH41Bla6U1qLZ +AmZuyIF+mQC/cgojIsrBMzBxb1kKqzATF4+XwPwgKz7fmiddmHyYz2WDJfAjIveJ +ZjdMjM4+EytGlkkJ52T8V8ds0/L2qKexJ+NBLxkeQLfV8n1mIk7zX7jguwbCG1Pr +nEMdJ3Sew20vnje+RsngAzdPChoJpVsWi/K7cettX/tbnre1DL02GXc5qJoQYk7b +3zkmhz31TgFrd9VVtmUGyFXAysuSAb3EN+5VnHGr0xKkeg8utErea2FNtNIgua8H +ONfm9Eiyaav1SVKzPHlyqLtcdxH3I8Wg7yqMsaprZ1n5A1v/levxnL8+It02KseD +5HqV4rf/cImSlCt3lpRg8U5E1pyFQ2IVEC/XTDMiI3c+AR+w2jSRB3Bwn9zJtFlW +KHG3m1xGI4ck+Lci1JvWWLXQagQSPtZTsubxTQNx1gsgZhgv1JHVZMdbVlAbbRMC +1nSuJNl7KPAS/VfzAgEDAoIBgHRXxaynbVP5gkO0ug6Qw/E27wzIw4SmjsxG6Wpe +K7kfDeRskKxESdsA/xCrKkwGwhcx1iIgS5+Qscd1Yg+1D9X9asd/P7waPmWoZd+Z +AhlKwhdPsO7PiF3e1AzHhGQwsUTt/Y/aSI1MpHBvy2/s1h9mFCslOUxTmWw0oj/Q +ldIEgWeNR72CE2+jFIJIyml6ftnb6qzPiga8Bm48ubKh0kvySOqnkmnPzgh+JBD6 +JnBmtZbfPT97bwTT+N6rnPqOOApvfHPf15kWI8yDbprG1l4OCUaIUH1AszxLd826 +5IPM+8gINLRDP1MA6azECPjTyHXhtnSIBZCyWSVkc05vYmNXYUNiXWMajcxW9M02 +wKzFELO8NCEAkaTPxwo4SCyIjUxiK1LbQ9h8PSy4c1+gGP4LAMR8xqP4QKg6zdu9 +osUGG/xRe/uufgTBFkcjqBHtK5L5VI0jeNIUAgW/6iNbYXjBMJ0GfauLs+g1VsOm +WfdgXzsb9DYdMa0OXXHypmV4GwKBwQDUwQj8RKJ6c8cT4vcWCoJvJF00+RFL+P3i +Gx2DLERxRrDa8AVGfqaCjsR+3vLgG8V/py+z+dxZYSqeB80Qeo6PDITcRKoeAYh9 +xlT3LJOS+k1cJcEmlbbO2IjLkTmzSwa80fWexKu8/Xv6vv15gpqYl1ngYoqJM3pd +vzmTIOi7MKSZ0WmEQavrZj8zK4endE3v0eAEeQ55j1GImbypSf7Idh7wOXtjZ7WD +Dg6yWDrri+AP/L3gClMj8wsAxMV4ZR8CgcEA0fzDHkFa6raVOxWnObmRoDhAtE0a +cjUj976NM5yyfdf2MrKy4/RhdTiPZ6b08/lBC/+xRfV3xKVGzacm6QjqjZrUpgHC +0LKiZaMtccCJjLtPwQd0jGQEnKfMFaPsnhOc5y8qVkCzVOSthY5qhz0XNotHHFmJ +gffVgB0iqrMTvSL7IA2yqqpOqNRlhaYhNl8TiFP3gIeMtVa9rZy31JPgT2uJ+kfo +gV7sdTPEjPWZd7OshGxWpT6QfVDj/T9T7L6tAoHBAI3WBf2DFvxNL2KXT2QHAZ9t +k3imC4f7U+wSE6zILaDZyzygA4RUbwG0gv8/TJVn2P/Eynf76DuWHGlaiLWnCbSz +Az2DHBQBBaku409zDQym3j1ugMRjzzSQWzJg0SIyBH3hTmnYcn3+Uqcp/lEBvGW6 +O+rsXFt3pukqJmIV8HzLGGaLm62BHUeZf3dyWm+i3p/hQAL7Xvu04QW70xuGqdr5 +afV7p5eaeQIJXyGQJ0eylV/90+qxjMKiB1XYg6WYvwKBwQCL/ddpgOdHJGN8uRom +e7Zq0Csi3hGheMKlKbN3vcxT5U7MdyHtTZZOJbTvxKNNUNYH/8uD+PqDGNneb29G +BfGzvI3EASyLIcGZF3OhKwZd0jUrWk2y7Vhob91jwp2+t73vdMbkKyI4mHOuXvGv +fg95si9oO7EBT+Oqvhccd2J+F1IVXncccYnF4u5ZGWt5lLewN/pVr7MjjykeaHqN +t+rfnQam2psA6fL4zS2zTmZPzR2tnY8Y1GBTi0Ko1OKd1HMCgcAb5cB/7/AQlhP9 +yQa04PLH9ygQkKKptZp7dy5WcWRx0K/hAHRoi2aw1wZqfm7VBNu2SLcs90kCCCxp +6C5sfJi6b8NpNbIPC+sc9wsFr7pGo9SFzQ78UlcWYK2Gu2FxlMjonhka5hvo4zvg +WxlpXKEkaFt3gLd92m/dMqBrHfafH7VwOJY2zT3WIpjwuk0ZzmRg5p0pG/svVQEH +NZmwRwlopysbR69B/n1nefJ84UO50fLh5s5Zr3gBRwbWNZyzhXk= +-----END RSA PRIVATE KEY----- diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Utility_E2.cpp b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Utility_E2.cpp new file mode 100644 index 0000000000..962c68f922 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Utility_E2.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "sgx_eid.h" +#include "EnclaveMessageExchange.h" +#include "error_codes.h" +#include "Utility_E2.h" +#include "stdlib.h" +#include "string.h" + +uint32_t marshal_input_parameters_e3_foo1(uint32_t target_fn_id, uint32_t msg_type, param_struct_t *p_struct_var, char** marshalled_buff, size_t* marshalled_buff_len) +{ + ms_in_msg_exchange_t *ms; + size_t param_len, ms_len; + char *temp_buff; + if(!p_struct_var || !marshalled_buff_len) + return INVALID_PARAMETER_ERROR; + param_len = sizeof(param_struct_t); + temp_buff = (char*)malloc(param_len); + if(!temp_buff) + return MALLOC_ERROR; + memcpy(temp_buff, p_struct_var, sizeof(param_struct_t)); //can be optimized + ms_len = sizeof(ms_in_msg_exchange_t) + param_len; + ms = (ms_in_msg_exchange_t *)malloc(ms_len); + if(!ms) + { + SAFE_FREE(temp_buff); + return MALLOC_ERROR; + } + ms->msg_type = msg_type; + ms->target_fn_id = target_fn_id; + ms->inparam_buff_len = (uint32_t)param_len; + memcpy(&ms->inparam_buff, temp_buff, param_len); + *marshalled_buff = (char*)ms; + *marshalled_buff_len = ms_len; + SAFE_FREE(temp_buff); + return SUCCESS; +} + +uint32_t unmarshal_retval_and_output_parameters_e3_foo1(char* out_buff, param_struct_t *p_struct_var, char** retval) +{ + size_t retval_len; + ms_out_msg_exchange_t *ms; + if(!out_buff) + return INVALID_PARAMETER_ERROR; + ms = (ms_out_msg_exchange_t *)out_buff; + retval_len = ms->retval_len; + *retval = (char*)malloc(retval_len); + if(!*retval) + { + return MALLOC_ERROR; + } + memcpy(*retval, ms->ret_outparam_buff, retval_len); + memcpy(&p_struct_var->var1, (ms->ret_outparam_buff) + retval_len, sizeof(p_struct_var->var1)); + memcpy(&p_struct_var->var2, (ms->ret_outparam_buff) + retval_len + sizeof(p_struct_var->var1), sizeof(p_struct_var->var2)); + return SUCCESS; +} + + +uint32_t unmarshal_input_parameters_e2_foo1(uint32_t* var1, uint32_t* var2, ms_in_msg_exchange_t* ms) +{ + char* buff; + size_t len; + if(!var1 || !var2 || !ms) + return INVALID_PARAMETER_ERROR; + + buff = ms->inparam_buff; + len = ms->inparam_buff_len; + + if(len != (sizeof(*var1) + sizeof(*var2))) + return ATTESTATION_ERROR; + + memcpy(var1, buff, sizeof(*var1)); + memcpy(var2, buff + sizeof(*var1), sizeof(*var2)); + + return SUCCESS; +} + +uint32_t marshal_retval_and_output_parameters_e2_foo1(char** resp_buffer, size_t* resp_length, uint32_t retval) +{ + ms_out_msg_exchange_t *ms; + size_t ret_param_len, ms_len; + char *temp_buff; + size_t retval_len; + if(!resp_length) + return INVALID_PARAMETER_ERROR; + retval_len = sizeof(retval); + ret_param_len = retval_len; //no out parameters + temp_buff = (char*)malloc(ret_param_len); + if(!temp_buff) + return MALLOC_ERROR; + + memcpy(temp_buff, &retval, sizeof(retval)); + ms_len = sizeof(ms_out_msg_exchange_t) + ret_param_len; + ms = (ms_out_msg_exchange_t *)malloc(ms_len); + if(!ms) + { + SAFE_FREE(temp_buff); + return MALLOC_ERROR; + } + ms->retval_len = (uint32_t)retval_len; + ms->ret_outparam_buff_len = (uint32_t)ret_param_len; + memcpy(&ms->ret_outparam_buff, temp_buff, ret_param_len); + *resp_buffer = (char*)ms; + *resp_length = ms_len; + SAFE_FREE(temp_buff); + return SUCCESS; +} + +uint32_t marshal_message_exchange_request(uint32_t target_fn_id, uint32_t msg_type, uint32_t secret_data, char** marshalled_buff, size_t* marshalled_buff_len) +{ + ms_in_msg_exchange_t *ms; + size_t secret_data_len, ms_len; + if(!marshalled_buff_len) + return INVALID_PARAMETER_ERROR; + secret_data_len = sizeof(secret_data); + ms_len = sizeof(ms_in_msg_exchange_t) + secret_data_len; + ms = (ms_in_msg_exchange_t *)malloc(ms_len); + if(!ms) + return MALLOC_ERROR; + + ms->msg_type = msg_type; + ms->target_fn_id = target_fn_id; + ms->inparam_buff_len = (uint32_t)secret_data_len; + memcpy(&ms->inparam_buff, &secret_data, secret_data_len); + *marshalled_buff = (char*)ms; + *marshalled_buff_len = ms_len; + return SUCCESS; +} + +uint32_t umarshal_message_exchange_request(uint32_t* inp_secret_data, ms_in_msg_exchange_t* ms) +{ + char* buff; + size_t len; + if(!inp_secret_data || !ms) + return INVALID_PARAMETER_ERROR; + buff = ms->inparam_buff; + len = ms->inparam_buff_len; + if(len != sizeof(uint32_t)) + return ATTESTATION_ERROR; + + memcpy(inp_secret_data, buff, sizeof(uint32_t)); + + return SUCCESS; +} + + +uint32_t marshal_message_exchange_response(char** resp_buffer, size_t* resp_length, uint32_t secret_response) +{ + ms_out_msg_exchange_t *ms; + size_t secret_response_len, ms_len; + size_t retval_len, ret_param_len; + if(!resp_length) + return INVALID_PARAMETER_ERROR; + secret_response_len = sizeof(secret_response); + retval_len = secret_response_len; + ret_param_len = secret_response_len; + ms_len = sizeof(ms_out_msg_exchange_t) + ret_param_len; + ms = (ms_out_msg_exchange_t *)malloc(ms_len); + if(!ms) + return MALLOC_ERROR; + ms->retval_len = (uint32_t)retval_len; + ms->ret_outparam_buff_len = (uint32_t)ret_param_len; + memcpy(&ms->ret_outparam_buff, &secret_response, secret_response_len); + *resp_buffer = (char*)ms; + *resp_length = ms_len; + return SUCCESS; +} + +uint32_t umarshal_message_exchange_response(char* out_buff, char** secret_response) +{ + size_t retval_len; + ms_out_msg_exchange_t *ms; + if(!out_buff) + return INVALID_PARAMETER_ERROR; + ms = (ms_out_msg_exchange_t *)out_buff; + retval_len = ms->retval_len; + *secret_response = (char*)malloc(retval_len); + if(!*secret_response) + { + return MALLOC_ERROR; + } + memcpy(*secret_response, ms->ret_outparam_buff, retval_len); + return SUCCESS; +} diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Utility_E2.h b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Utility_E2.h new file mode 100644 index 0000000000..17b88cdea2 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave2/Utility_E2.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef UTILITY_E2_H__ +#define UTILITY_E2_H__ +#include "stdint.h" + +typedef struct _param_struct_t +{ + uint32_t var1; + uint32_t var2; +}param_struct_t; + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t marshal_input_parameters_e3_foo1(uint32_t target_fn_id, uint32_t msg_type, param_struct_t *p_struct_var, char** marshalled_buff, size_t* marshalled_buff_len); +uint32_t unmarshal_retval_and_output_parameters_e3_foo1(char* out_buff, param_struct_t *p_struct_var, char** retval); +uint32_t unmarshal_input_parameters_e2_foo1(uint32_t* var1, uint32_t* var2, ms_in_msg_exchange_t* ms); +uint32_t marshal_retval_and_output_parameters_e2_foo1(char** resp_buffer, size_t* resp_length, uint32_t retval); +uint32_t marshal_message_exchange_request(uint32_t target_fn_id, uint32_t msg_type, uint32_t secret_data, char** marshalled_buff, size_t* marshalled_buff_len); +uint32_t umarshal_message_exchange_request(uint32_t* inp_secret_data, ms_in_msg_exchange_t* ms); +uint32_t marshal_message_exchange_response(char** resp_buffer, size_t* resp_length, uint32_t secret_response); +uint32_t umarshal_message_exchange_response(char* out_buff, char** secret_response); + +#ifdef __cplusplus + } +#endif +#endif + diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Enclave3.config.xml b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Enclave3.config.xml new file mode 100644 index 0000000000..436860dd50 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Enclave3.config.xml @@ -0,0 +1,11 @@ + + 0 + 0 + 0x40000 + 0x100000 + 1 + 1 + 0 + 0 + 0xFFFFFFFF + diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Enclave3.cpp b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Enclave3.cpp new file mode 100644 index 0000000000..cc15bc4aa7 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Enclave3.cpp @@ -0,0 +1,366 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +// Enclave3.cpp : Defines the exported functions for the DLL application +#include "sgx_eid.h" +#include "Enclave3_t.h" +#include "EnclaveMessageExchange.h" +#include "error_codes.h" +#include "Utility_E3.h" +#include "sgx_thread.h" +#include "sgx_dh.h" +#include + +#define UNUSED(val) (void)(val) + +std::mapg_src_session_info_map; + +static uint32_t e3_foo1_wrapper(ms_in_msg_exchange_t *ms, size_t param_lenth, char** resp_buffer, size_t* resp_length); + +//Function pointer table containing the list of functions that the enclave exposes +const struct { + size_t num_funcs; + const void* table[1]; +} func_table = { + 1, + { + (const void*)e3_foo1_wrapper, + } +}; + +//Makes use of the sample code function to establish a secure channel with the destination enclave +uint32_t test_create_session(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id) +{ + ATTESTATION_STATUS ke_status = SUCCESS; + dh_session_t dest_session_info; + //Core reference code function for creating a session + ke_status = create_session(src_enclave_id, dest_enclave_id,&dest_session_info); + if(ke_status == SUCCESS) + { + //Insert the session information into the map under the corresponding destination enclave id + g_src_session_info_map.insert(std::pair(dest_enclave_id, dest_session_info)); + } + memset(&dest_session_info, 0, sizeof(dh_session_t)); + return ke_status; +} + +//Makes use of the sample code function to do an enclave to enclave call (Test Vector) +uint32_t test_enclave_to_enclave_call(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id) +{ + ATTESTATION_STATUS ke_status = SUCCESS; + external_param_struct_t *p_struct_var, struct_var; + internal_param_struct_t internal_struct_var; + uint32_t target_fn_id, msg_type; + char* marshalled_inp_buff; + size_t marshalled_inp_buff_len; + char* out_buff; + size_t out_buff_len; + dh_session_t *dest_session_info; + size_t max_out_buff_size; + char* retval; + + max_out_buff_size = 50; + msg_type = ENCLAVE_TO_ENCLAVE_CALL; + target_fn_id = 0; + internal_struct_var.ivar1 = 0x5; + internal_struct_var.ivar2 = 0x6; + struct_var.var1 = 0x3; + struct_var.var2 = 0x4; + struct_var.p_internal_struct = &internal_struct_var; + p_struct_var = &struct_var; + + size_t len_data = sizeof(struct_var) - sizeof(struct_var.p_internal_struct); + size_t len_ptr_data = sizeof(internal_struct_var); + + //Marshals the input parameters for calling function foo1 in Enclave1 into a input buffer + ke_status = marshal_input_parameters_e1_foo1(target_fn_id, msg_type, p_struct_var, len_data, + len_ptr_data, &marshalled_inp_buff, &marshalled_inp_buff_len); + + if(ke_status != SUCCESS) + { + return ke_status; + } + + //Search the map for the session information associated with the destination enclave id passed in + std::map::iterator it = g_src_session_info_map.find(dest_enclave_id); + if(it != g_src_session_info_map.end()) + { + dest_session_info = &it->second; + } + else + { + SAFE_FREE(marshalled_inp_buff); + return INVALID_SESSION; + } + + //Core Reference Code function + ke_status = send_request_receive_response(src_enclave_id, dest_enclave_id, dest_session_info, + marshalled_inp_buff, marshalled_inp_buff_len, max_out_buff_size, &out_buff, &out_buff_len); + + if(ke_status != SUCCESS) + { + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + return ke_status; + } + + ////Un-marshal the return value and output parameters from foo1 of Enclave1 + ke_status = unmarshal_retval_and_output_parameters_e1_foo1(out_buff, p_struct_var, &retval); + if(ke_status != SUCCESS) + { + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + return ke_status; + } + + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + SAFE_FREE(retval); + return SUCCESS; +} + +//Makes use of the sample code function to do a generic secret message exchange (Test Vector) +uint32_t test_message_exchange(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id) +{ + ATTESTATION_STATUS ke_status = SUCCESS; + uint32_t target_fn_id, msg_type; + char* marshalled_inp_buff; + size_t marshalled_inp_buff_len; + char* out_buff; + size_t out_buff_len; + dh_session_t *dest_session_info; + size_t max_out_buff_size; + char* secret_response; + uint32_t secret_data; + + target_fn_id = 0; + msg_type = MESSAGE_EXCHANGE; + max_out_buff_size = 50; + secret_data = 0x12345678; //Secret Data here is shown only for purpose of demonstration. + + //Marshals the parameters into a buffer + ke_status = marshal_message_exchange_request(target_fn_id, msg_type, secret_data, &marshalled_inp_buff, &marshalled_inp_buff_len); + if(ke_status != SUCCESS) + { + return ke_status; + } + //Search the map for the session information associated with the destination enclave id passed in + std::map::iterator it = g_src_session_info_map.find(dest_enclave_id); + if(it != g_src_session_info_map.end()) + { + dest_session_info = &it->second; + } + else + { + SAFE_FREE(marshalled_inp_buff); + return INVALID_SESSION; + } + + //Core Reference Code function + ke_status = send_request_receive_response(src_enclave_id, dest_enclave_id, dest_session_info, marshalled_inp_buff, + marshalled_inp_buff_len, max_out_buff_size, &out_buff, &out_buff_len); + + if(ke_status != SUCCESS) + { + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + return ke_status; + } + //Un-marshal the secret response data + ke_status = umarshal_message_exchange_response(out_buff, &secret_response); + if(ke_status != SUCCESS) + { + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + return ke_status; + } + + SAFE_FREE(marshalled_inp_buff); + SAFE_FREE(out_buff); + SAFE_FREE(secret_response); + return SUCCESS; +} + + +//Makes use of the sample code function to close a current session +uint32_t test_close_session(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id) +{ + dh_session_t dest_session_info; + ATTESTATION_STATUS ke_status = SUCCESS; + //Search the map for the session information associated with the destination enclave id passed in + std::map::iterator it = g_src_session_info_map.find(dest_enclave_id); + if(it != g_src_session_info_map.end()) + { + dest_session_info = it->second; + } + else + { + return NULL; + } + //Core reference code function for closing a session + ke_status = close_session(src_enclave_id, dest_enclave_id); + + //Erase the session information associated with the destination enclave id + g_src_session_info_map.erase(dest_enclave_id); + return ke_status; +} + +//Function that is used to verify the trust of the other enclave +//Each enclave can have its own way verifying the peer enclave identity +extern "C" uint32_t verify_peer_enclave_trust(sgx_dh_session_enclave_identity_t* peer_enclave_identity) +{ + if(!peer_enclave_identity) + { + return INVALID_PARAMETER_ERROR; + } + if(peer_enclave_identity->isv_prod_id != 0 || !(peer_enclave_identity->attributes.flags & SGX_FLAGS_INITTED)) + // || peer_enclave_identity->attributes.xfrm !=3)// || peer_enclave_identity->mr_signer != xx //TODO: To be hardcoded with values to check + { + return ENCLAVE_TRUST_ERROR; + } + else + { + return SUCCESS; + } +} + + +//Dispatch function that calls the approriate enclave function based on the function id +//Each enclave can have its own way of dispatching the calls from other enclave +extern "C" uint32_t enclave_to_enclave_call_dispatcher(char* decrypted_data, + size_t decrypted_data_length, + char** resp_buffer, + size_t* resp_length) +{ + ms_in_msg_exchange_t *ms; + uint32_t (*fn1)(ms_in_msg_exchange_t *ms, size_t, char**, size_t*); + if(!decrypted_data || !resp_length) + { + return INVALID_PARAMETER_ERROR; + } + ms = (ms_in_msg_exchange_t *)decrypted_data; + if(ms->target_fn_id >= func_table.num_funcs) + { + return INVALID_PARAMETER_ERROR; + } + fn1 = (uint32_t (*)(ms_in_msg_exchange_t*, size_t, char**, size_t*))func_table.table[ms->target_fn_id]; + return fn1(ms, decrypted_data_length, resp_buffer, resp_length); +} + +//Operates on the input secret and generates the output secret +uint32_t get_message_exchange_response(uint32_t inp_secret_data) +{ + uint32_t secret_response; + + //User should use more complex encryption method to protect their secret, below is just a simple example + secret_response = inp_secret_data & 0x11111111; + + return secret_response; + +} +//Generates the response from the request message +extern "C" uint32_t message_exchange_response_generator(char* decrypted_data, + char** resp_buffer, + size_t* resp_length) +{ + ms_in_msg_exchange_t *ms; + uint32_t inp_secret_data; + uint32_t out_secret_data; + if(!decrypted_data || !resp_length) + { + return INVALID_PARAMETER_ERROR; + } + ms = (ms_in_msg_exchange_t *)decrypted_data; + + if(umarshal_message_exchange_request(&inp_secret_data,ms) != SUCCESS) + return ATTESTATION_ERROR; + + out_secret_data = get_message_exchange_response(inp_secret_data); + + if(marshal_message_exchange_response(resp_buffer, resp_length, out_secret_data) != SUCCESS) + return MALLOC_ERROR; + + return SUCCESS; + +} + + +static uint32_t e3_foo1(param_struct_t *p_struct_var) +{ + if(!p_struct_var) + { + return INVALID_PARAMETER_ERROR; + } + p_struct_var->var1++; + p_struct_var->var2++; + + return(p_struct_var->var1 * p_struct_var->var2); +} + +//Function which is executed on request from the source enclave +static uint32_t e3_foo1_wrapper(ms_in_msg_exchange_t *ms, + size_t param_lenth, + char** resp_buffer, + size_t* resp_length) +{ + UNUSED(param_lenth); + + uint32_t ret; + param_struct_t *p_struct_var; + if(!ms || !resp_length) + { + return INVALID_PARAMETER_ERROR; + } + p_struct_var = (param_struct_t*)malloc(sizeof(param_struct_t)); + if(!p_struct_var) + return MALLOC_ERROR; + + if(unmarshal_input_parameters_e3_foo1(p_struct_var, ms) != SUCCESS) + { + SAFE_FREE(p_struct_var); + return ATTESTATION_ERROR; + } + + ret = e3_foo1(p_struct_var); + + if(marshal_retval_and_output_parameters_e3_foo1(resp_buffer, resp_length, ret, p_struct_var) != SUCCESS) + { + SAFE_FREE(p_struct_var); + return MALLOC_ERROR; + } + SAFE_FREE(p_struct_var); + return SUCCESS; +} diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Enclave3.edl b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Enclave3.edl new file mode 100644 index 0000000000..7584ee7945 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Enclave3.edl @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +enclave { + include "sgx_eid.h" + from "../LocalAttestationCode/LocalAttestationCode.edl" import *; + from "sgx_tstdc.edl" import *; + trusted{ + public uint32_t test_create_session(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + public uint32_t test_enclave_to_enclave_call(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + public uint32_t test_message_exchange(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + public uint32_t test_close_session(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + }; +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Enclave3_private.pem b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Enclave3_private.pem new file mode 100644 index 0000000000..b8ace89eb3 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Enclave3_private.pem @@ -0,0 +1,39 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIG4wIBAAKCAYEA0MvI9NpdP4GEqCvtlJQv00OybzTXzxBhPu/257VYt9cYw/ph +BN1WRyxBBcrZs15xmcvlb3xNmFGWs4w5oUgrFBNgi6g+CUOCsj0cM8xw7P/y3K0H +XaZUf+T3CXCp8NvlkZHzfdWAFA5lGGR9g6kmuk7SojE3h87Zm1KjPU/PvAe+BaMU +trlRr4gPNVnu19Vho60xwuswPxfl/pBFUIk7qWEUR3l2hiqWMeLgf3Ays/WSnkXA +uijwPt5g0hxsgIlyDrI3jKbf0zkFB56jvPwSykfU8aw4Gkbo5qSZxUAKnwH2L8Uf +yM6inBaaYtM79icRwsu45Yt6X0GAt7CSb/1TKBrnm5exmK1sug3YSQ/YuK1FYawU +vIaDD0YfzOndTNVBewA+Hr5xNPvqGJoRKHuGbyu2lI9jrKYpVxQWsmx38wnxF6kE +zX6N4m7KZiLeLpDdBVQtLuOzIdIE4wT3t/ckeqElxO/1Ut9bj765GcTTrYwMKHRw +ukWIH7ZtHtAjj0KzAgEDAoIBgQCLMoX4kZN/q63Fcp5jDXU3gnb0zeU0tZYp9U9F +I5B6j2XX/ECt6OQvctYD3JEiPvZmh+5KUt5li7nNCCZrhXINYkBdGtQGLQHMKL13 +3aCd//c9yK+TxDhVQ09boHFLPUO2YUz+jlVitENlmFOtG28m3zcWy3paieZnjGzT +iop9Wn6ubLh50OEfsAojkUnlOOvCc3aB8iAqD+6ptYOLBifGQLgvpk8EHGQhQer/ +oCHNTmG+2SsmxfV/Pus2vZ2rBkrUbZU0hwrnvKOIPhnt3Qwtmx9xsC67jF+MpWko +UisJXC27FAGz2gpIGMhBp35HEppwG9hhCuMQdK2g62bvweyr1tC4qOVdQrKvhksN +r6CMjS9eSXvmWdF7lU4oxStN0V56/LICSIsLbggUaxTPKhAVEgfTSqwEJoQuFA3Q +4GmgTydPhcRH1L/lhbWJqZQm7V1Gt+5i5J6iATD32uNQQ2iZi5GsUhr+jZC+WlE5 +6lS813cRNiaK52HIk62bG7IXOksCgcEA+6RxZhQ5GaCPYZNsk7TqxqsKopXKoYAr +2R4KWuexJTd+1kcNMk0ETX8OSgpY2cYL2uPFWmdutxPpLfpr8S2u92Da/Wxs70Ti +QSb0426ybTmnS5L7nOnGOHiddXILhW175liAszTeoR7nQ6vpr9YjfcnrXiB8bKIm +akft2DQoxrBPzEe9tA8gfkyDTsSG2j7kncSbvYRtkKcJOmmypotVU6uhRPSrSXCc +J59uBQkg6Bk4CKA1mz8ctG07MluFY0/ZAoHBANRpZlfIFl39gFmuEER7lb80GySO +J190LbqOca3dGOvAMsDgEAi6juJyX7ZNpbHFHj++LvmTtw9+kxhVDBcswS7304kt +7J2EfnGdctEZtXif1wiq30YWAp1tjRpQENKtt9wssmgcwgK39rZNiEHmStHGv3l+ +5TnKPKeuFCDnsLvi5lQYoK2wTYvZtsjf+Rnt7H17q90IV54pMjTS8BkGskCkKf2A +IYuaZkqX0T3cM6ovoYYDAU6rWL5rrYPLEwkbawKBwQCnwvZEDXtmawpBDPMNI0cv +HLHBuTHBAB07aVw8mnYYz6nkL14hiK2I/17cBuXmhAfnQoORmknPYptz/Ef2HnSk +6zyo8vNKLewrb03s9Hbze8TdDKe98S7QUGj49rJY86fu5asiIz8WFJotHUZ1OWz+ +hpzpav2dwW7xhUk6zXCEdYqIL9PNX2r+3azfLa88Ke2+gxJ+WEkLGgYm8SHEXOON +HRYt+HIw9b1vv56uBhXwENAFwCO81L3Nnid2565CNTsCgcEAjZuZj9q5k/5VkR61 +gv0Of3gSGF7E6k1z0bRLyT4QnSrMgJVgBdG0lvbqeYkZIS4UKn7J+7fPX6m3ZY4I +D3MrdKU3sMlIaQL+9mj3NhEjpb/ksHHqLrlXE55eEYq14cklPXMhmr3WrHqkeYkF +gUQx4S8qUP9De9wob8liwJp10pdEOBBrHnWJB+Z52z/7Zp6dqP0dPgWPvsYheIyg +EK8hgG1xU6rBB7xEMbqLfpLNHB/BBAIA3xzl1EfJAodiBhJHAoHAeTS2znDHYayI +TvK86tBAPVORiBVTSdRUONdGF3dipo24hyeyrI5MtiOoMc3sKWXnSTkDQWa3WiPx +qStBmmO/SbGTuz7T6+oOwGeMiYzYBe87Ayn8Y0KYYshFikieJbGusHjUlIGmCVPy +UHrDMYGwFGUGBwW47gBsnZa+YPHtxWCPDe/U80et2Trx0RXJJQPmupAVMSiJWObI +9k5gRU+xDqkHanyD1gkGGwhFTUNX94EJEOdQEWw3hxLnVtePoke/ +-----END RSA PRIVATE KEY----- diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Utility_E3.cpp b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Utility_E3.cpp new file mode 100644 index 0000000000..97cf9b0ce6 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Utility_E3.cpp @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "sgx_eid.h" +#include "EnclaveMessageExchange.h" +#include "error_codes.h" +#include "Utility_E3.h" +#include "stdlib.h" +#include "string.h" + +uint32_t marshal_input_parameters_e1_foo1(uint32_t target_fn_id, uint32_t msg_type, external_param_struct_t *p_struct_var, size_t len_data, size_t len_ptr_data, char** marshalled_buff, size_t* marshalled_buff_len) +{ + ms_in_msg_exchange_t *ms; + size_t param_len, ms_len; + char *temp_buff; + int* addr; + char* struct_data; + if(!p_struct_var || !marshalled_buff_len) + return INVALID_PARAMETER_ERROR; + struct_data = (char*)p_struct_var; + temp_buff = (char*)malloc(len_data + len_ptr_data); + if(!temp_buff) + return MALLOC_ERROR; + memcpy(temp_buff, struct_data, len_data); + addr = *(int **)(struct_data + len_data); + memcpy(temp_buff + len_data, addr, len_ptr_data); //can be optimized + param_len = len_data + len_ptr_data; + ms_len = sizeof(ms_in_msg_exchange_t) + param_len; + ms = (ms_in_msg_exchange_t *)malloc(ms_len); + if(!ms) + { + SAFE_FREE(temp_buff); + return MALLOC_ERROR; + } + ms->msg_type = msg_type; + ms->target_fn_id = target_fn_id; + ms->inparam_buff_len = (uint32_t)param_len; + memcpy(&ms->inparam_buff, temp_buff, param_len); + *marshalled_buff = (char*)ms; + *marshalled_buff_len = ms_len; + + SAFE_FREE(temp_buff); + return SUCCESS; +} + +uint32_t marshal_retval_and_output_parameters_e3_foo1(char** resp_buffer, size_t* resp_length, uint32_t retval, param_struct_t *p_struct_var) +{ + ms_out_msg_exchange_t *ms; + size_t ret_param_len, ms_len; + char *temp_buff; + size_t retval_len; + if(!resp_length || !p_struct_var) + return INVALID_PARAMETER_ERROR; + retval_len = sizeof(retval); + ret_param_len = sizeof(retval) + sizeof(param_struct_t); + temp_buff = (char*)malloc(ret_param_len); + if(!temp_buff) + return MALLOC_ERROR; + memcpy(temp_buff, &retval, sizeof(retval)); + memcpy(temp_buff + sizeof(retval), p_struct_var, sizeof(param_struct_t)); + ms_len = sizeof(ms_out_msg_exchange_t) + ret_param_len; + ms = (ms_out_msg_exchange_t *)malloc(ms_len); + if(!ms) + { + SAFE_FREE(temp_buff); + return MALLOC_ERROR; + } + ms->retval_len = (uint32_t)retval_len; + ms->ret_outparam_buff_len = (uint32_t)ret_param_len; + memcpy(&ms->ret_outparam_buff, temp_buff, ret_param_len); + *resp_buffer = (char*)ms; + *resp_length = ms_len; + SAFE_FREE(temp_buff); + return SUCCESS; +} + +uint32_t unmarshal_input_parameters_e3_foo1(param_struct_t *pstruct, ms_in_msg_exchange_t* ms) +{ + char* buff; + size_t len; + if(!pstruct || !ms) + return INVALID_PARAMETER_ERROR; + buff = ms->inparam_buff; + len = ms->inparam_buff_len; + + if(len != (sizeof(pstruct->var1) + sizeof(pstruct->var2))) + return ATTESTATION_ERROR; + + memcpy(&pstruct->var1, buff, sizeof(pstruct->var1)); + memcpy(&pstruct->var2, buff + sizeof(pstruct->var1), sizeof(pstruct->var2)); + + return SUCCESS; +} + + +uint32_t unmarshal_retval_and_output_parameters_e1_foo1(char* out_buff, external_param_struct_t *p_struct_var, char** retval) +{ + size_t retval_len; + ms_out_msg_exchange_t *ms; + if(!out_buff || !p_struct_var) + return INVALID_PARAMETER_ERROR; + ms = (ms_out_msg_exchange_t *)out_buff; + retval_len = ms->retval_len; + *retval = (char*)malloc(retval_len); + if(!*retval) + { + return MALLOC_ERROR; + } + memcpy(*retval, ms->ret_outparam_buff, retval_len); + memcpy(&p_struct_var->var1, (ms->ret_outparam_buff) + retval_len, sizeof(p_struct_var->var1)); + memcpy(&p_struct_var->var2, (ms->ret_outparam_buff) + retval_len + sizeof(p_struct_var->var1), sizeof(p_struct_var->var2)); + memcpy(&p_struct_var->p_internal_struct->ivar1, (ms->ret_outparam_buff) + retval_len + sizeof(p_struct_var->var1)+ sizeof(p_struct_var->var2), sizeof(p_struct_var->p_internal_struct->ivar1)); + memcpy(&p_struct_var->p_internal_struct->ivar2, (ms->ret_outparam_buff) + retval_len + sizeof(p_struct_var->var1)+ sizeof(p_struct_var->var2) + sizeof(p_struct_var->p_internal_struct->ivar1), sizeof(p_struct_var->p_internal_struct->ivar2)); + return SUCCESS; +} + + +uint32_t marshal_message_exchange_request(uint32_t target_fn_id, uint32_t msg_type, uint32_t secret_data, char** marshalled_buff, size_t* marshalled_buff_len) +{ + ms_in_msg_exchange_t *ms; + size_t secret_data_len, ms_len; + if(!marshalled_buff_len) + return INVALID_PARAMETER_ERROR; + secret_data_len = sizeof(secret_data); + ms_len = sizeof(ms_in_msg_exchange_t) + secret_data_len; + ms = (ms_in_msg_exchange_t *)malloc(ms_len); + if(!ms) + return MALLOC_ERROR; + + ms->msg_type = msg_type; + ms->target_fn_id = target_fn_id; + ms->inparam_buff_len = (uint32_t)secret_data_len; + memcpy(&ms->inparam_buff, &secret_data, secret_data_len); + + *marshalled_buff = (char*)ms; + *marshalled_buff_len = ms_len; + return SUCCESS; +} + +uint32_t umarshal_message_exchange_request(uint32_t* inp_secret_data, ms_in_msg_exchange_t* ms) +{ + char* buff; + size_t len; + if(!inp_secret_data || !ms) + return INVALID_PARAMETER_ERROR; + buff = ms->inparam_buff; + len = ms->inparam_buff_len; + + if(len != sizeof(uint32_t)) + return ATTESTATION_ERROR; + + memcpy(inp_secret_data, buff, sizeof(uint32_t)); + + return SUCCESS; +} + +uint32_t marshal_message_exchange_response(char** resp_buffer, size_t* resp_length, uint32_t secret_response) +{ + ms_out_msg_exchange_t *ms; + size_t secret_response_len, ms_len; + size_t retval_len, ret_param_len; + if(!resp_length) + return INVALID_PARAMETER_ERROR; + secret_response_len = sizeof(secret_response); + retval_len = secret_response_len; + ret_param_len = secret_response_len; + ms_len = sizeof(ms_out_msg_exchange_t) + ret_param_len; + ms = (ms_out_msg_exchange_t *)malloc(ms_len); + if(!ms) + return MALLOC_ERROR; + ms->retval_len = (uint32_t)retval_len; + ms->ret_outparam_buff_len = (uint32_t)ret_param_len; + memcpy(&ms->ret_outparam_buff, &secret_response, secret_response_len); + *resp_buffer = (char*)ms; + *resp_length = ms_len; + return SUCCESS; +} + +uint32_t umarshal_message_exchange_response(char* out_buff, char** secret_response) +{ + size_t retval_len; + ms_out_msg_exchange_t *ms; + if(!out_buff) + return INVALID_PARAMETER_ERROR; + ms = (ms_out_msg_exchange_t *)out_buff; + retval_len = ms->retval_len; + *secret_response = (char*)malloc(retval_len); + if(!*secret_response) + { + return MALLOC_ERROR; + } + memcpy(*secret_response, ms->ret_outparam_buff, retval_len); + return SUCCESS; +} + diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Utility_E3.h b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Utility_E3.h new file mode 100644 index 0000000000..83ba2d6f65 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Enclave3/Utility_E3.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef UTILITY_E3_H__ +#define UTILITY_E3_H__ + +#include "stdint.h" + + +typedef struct _internal_param_struct_t +{ + uint32_t ivar1; + uint32_t ivar2; +}internal_param_struct_t; + +typedef struct _external_param_struct_t +{ + uint32_t var1; + uint32_t var2; + internal_param_struct_t *p_internal_struct; +}external_param_struct_t; + +typedef struct _param_struct_t +{ + uint32_t var1; + uint32_t var2; +}param_struct_t; + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t marshal_input_parameters_e1_foo1(uint32_t target_fn_id, uint32_t msg_type, external_param_struct_t *p_struct_var, size_t len_data, size_t len_ptr_data, char** marshalled_buff, size_t* marshalled_buff_len); +uint32_t unmarshal_retval_and_output_parameters_e1_foo1(char* out_buff, external_param_struct_t *p_struct_var, char** retval); +uint32_t unmarshal_input_parameters_e3_foo1(param_struct_t *pstruct, ms_in_msg_exchange_t* ms); +uint32_t marshal_retval_and_output_parameters_e3_foo1(char** resp_buffer, size_t* resp_length, uint32_t retval, param_struct_t *p_struct_var); +uint32_t marshal_message_exchange_request(uint32_t target_fn_id, uint32_t msg_type, uint32_t secret_data, char** marshalled_buff, size_t* marshalled_buff_len); +uint32_t umarshal_message_exchange_request(uint32_t* inp_secret_data, ms_in_msg_exchange_t* ms); +uint32_t marshal_message_exchange_response(char** resp_buffer, size_t* resp_length, uint32_t secret_response); +uint32_t umarshal_message_exchange_response(char* out_buff, char** secret_response); + +#ifdef __cplusplus + } +#endif +#endif diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Include/dh_session_protocol.h b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Include/dh_session_protocol.h new file mode 100644 index 0000000000..bc92ee4d6c --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Include/dh_session_protocol.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _DH_SESSION_PROROCOL_H +#define _DH_SESSION_PROROCOL_H + +#include "sgx_ecp_types.h" +#include "sgx_key.h" +#include "sgx_report.h" +#include "sgx_attributes.h" + +#define NONCE_SIZE 16 +#define MAC_SIZE 16 + +#define MSG_BUF_LEN sizeof(ec_pub_t)*2 +#define MSG_HASH_SZ 32 + + +//Session information structure +typedef struct _la_dh_session_t +{ + uint32_t session_id; //Identifies the current session + uint32_t status; //Indicates session is in progress, active or closed + union + { + struct + { + sgx_dh_session_t dh_session; + }in_progress; + + struct + { + sgx_key_128bit_t AEK; //Session Key + uint32_t counter; //Used to store Message Sequence Number + }active; + }; +} dh_session_t; + + +#endif diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/EnclaveMessageExchange.cpp b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/EnclaveMessageExchange.cpp new file mode 100644 index 0000000000..a32e3e2197 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/EnclaveMessageExchange.cpp @@ -0,0 +1,721 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "sgx_trts.h" +#include "sgx_utils.h" +#include "EnclaveMessageExchange.h" +#include "sgx_eid.h" +#include "error_codes.h" +#include "sgx_ecp_types.h" +#include "sgx_thread.h" +#include +#include "dh_session_protocol.h" +#include "sgx_dh.h" +#include "sgx_tcrypto.h" +#include "LocalAttestationCode_t.h" + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t enclave_to_enclave_call_dispatcher(char* decrypted_data, size_t decrypted_data_length, char** resp_buffer, size_t* resp_length); +uint32_t message_exchange_response_generator(char* decrypted_data, char** resp_buffer, size_t* resp_length); +uint32_t verify_peer_enclave_trust(sgx_dh_session_enclave_identity_t* peer_enclave_identity); + +#ifdef __cplusplus +} +#endif + +#define MAX_SESSION_COUNT 16 + +//number of open sessions +uint32_t g_session_count = 0; + +ATTESTATION_STATUS generate_session_id(uint32_t *session_id); +ATTESTATION_STATUS end_session(sgx_enclave_id_t src_enclave_id); + +//Array of open session ids +session_id_tracker_t *g_session_id_tracker[MAX_SESSION_COUNT]; + +//Map between the source enclave id and the session information associated with that particular session +std::mapg_dest_session_info_map; + +//Create a session with the destination enclave +ATTESTATION_STATUS create_session(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id, + dh_session_t *session_info) +{ + sgx_dh_msg1_t dh_msg1; //Diffie-Hellman Message 1 + sgx_key_128bit_t dh_aek; // Session Key + sgx_dh_msg2_t dh_msg2; //Diffie-Hellman Message 2 + sgx_dh_msg3_t dh_msg3; //Diffie-Hellman Message 3 + uint32_t session_id; + uint32_t retstatus; + sgx_status_t status = SGX_SUCCESS; + sgx_dh_session_t sgx_dh_session; + sgx_dh_session_enclave_identity_t responder_identity; + + if(!session_info) + { + return INVALID_PARAMETER_ERROR; + } + + memset(&dh_aek,0, sizeof(sgx_key_128bit_t)); + memset(&dh_msg1, 0, sizeof(sgx_dh_msg1_t)); + memset(&dh_msg2, 0, sizeof(sgx_dh_msg2_t)); + memset(&dh_msg3, 0, sizeof(sgx_dh_msg3_t)); + memset(session_info, 0, sizeof(dh_session_t)); + + //Intialize the session as a session initiator + status = sgx_dh_init_session(SGX_DH_SESSION_INITIATOR, &sgx_dh_session); + if(SGX_SUCCESS != status) + { + return status; + } + + //Ocall to request for a session with the destination enclave and obtain session id and Message 1 if successful + status = session_request_ocall(&retstatus, src_enclave_id, dest_enclave_id, &dh_msg1, &session_id); + if (status == SGX_SUCCESS) + { + if ((ATTESTATION_STATUS)retstatus != SUCCESS) + return ((ATTESTATION_STATUS)retstatus); + } + else + { + return ATTESTATION_SE_ERROR; + } + //Process the message 1 obtained from desination enclave and generate message 2 + status = sgx_dh_initiator_proc_msg1(&dh_msg1, &dh_msg2, &sgx_dh_session); + if(SGX_SUCCESS != status) + { + return status; + } + + //Send Message 2 to Destination Enclave and get Message 3 in return + status = exchange_report_ocall(&retstatus, src_enclave_id, dest_enclave_id, &dh_msg2, &dh_msg3, session_id); + if (status == SGX_SUCCESS) + { + if ((ATTESTATION_STATUS)retstatus != SUCCESS) + return ((ATTESTATION_STATUS)retstatus); + } + else + { + return ATTESTATION_SE_ERROR; + } + + //Process Message 3 obtained from the destination enclave + status = sgx_dh_initiator_proc_msg3(&dh_msg3, &sgx_dh_session, &dh_aek, &responder_identity); + if(SGX_SUCCESS != status) + { + return status; + } + + // Verify the identity of the destination enclave + if(verify_peer_enclave_trust(&responder_identity) != SUCCESS) + { + return INVALID_SESSION; + } + + memcpy(session_info->active.AEK, &dh_aek, sizeof(sgx_key_128bit_t)); + session_info->session_id = session_id; + session_info->active.counter = 0; + session_info->status = ACTIVE; + memset(&dh_aek,0, sizeof(sgx_key_128bit_t)); + return status; +} + +//Handle the request from Source Enclave for a session +ATTESTATION_STATUS session_request(sgx_enclave_id_t src_enclave_id, + sgx_dh_msg1_t *dh_msg1, + uint32_t *session_id ) +{ + dh_session_t session_info; + sgx_dh_session_t sgx_dh_session; + sgx_status_t status = SGX_SUCCESS; + + if(!session_id || !dh_msg1) + { + return INVALID_PARAMETER_ERROR; + } + //Intialize the session as a session responder + status = sgx_dh_init_session(SGX_DH_SESSION_RESPONDER, &sgx_dh_session); + if(SGX_SUCCESS != status) + { + return status; + } + + //get a new SessionID + if ((status = (sgx_status_t)generate_session_id(session_id)) != SUCCESS) + return status; //no more sessions available + + //Allocate memory for the session id tracker + g_session_id_tracker[*session_id] = (session_id_tracker_t *)malloc(sizeof(session_id_tracker_t)); + if(!g_session_id_tracker[*session_id]) + { + return MALLOC_ERROR; + } + + memset(g_session_id_tracker[*session_id], 0, sizeof(session_id_tracker_t)); + g_session_id_tracker[*session_id]->session_id = *session_id; + session_info.status = IN_PROGRESS; + + //Generate Message1 that will be returned to Source Enclave + status = sgx_dh_responder_gen_msg1((sgx_dh_msg1_t*)dh_msg1, &sgx_dh_session); + if(SGX_SUCCESS != status) + { + SAFE_FREE(g_session_id_tracker[*session_id]); + return status; + } + memcpy(&session_info.in_progress.dh_session, &sgx_dh_session, sizeof(sgx_dh_session_t)); + //Store the session information under the correspoding source enlave id key + g_dest_session_info_map.insert(std::pair(src_enclave_id, session_info)); + + return status; +} + +//Verify Message 2, generate Message3 and exchange Message 3 with Source Enclave +ATTESTATION_STATUS exchange_report(sgx_enclave_id_t src_enclave_id, + sgx_dh_msg2_t *dh_msg2, + sgx_dh_msg3_t *dh_msg3, + uint32_t session_id) +{ + + sgx_key_128bit_t dh_aek; // Session key + dh_session_t *session_info; + ATTESTATION_STATUS status = SUCCESS; + sgx_dh_session_t sgx_dh_session; + sgx_dh_session_enclave_identity_t initiator_identity; + + if(!dh_msg2 || !dh_msg3) + { + return INVALID_PARAMETER_ERROR; + } + + memset(&dh_aek,0, sizeof(sgx_key_128bit_t)); + do + { + //Retreive the session information for the corresponding source enclave id + std::map::iterator it = g_dest_session_info_map.find(src_enclave_id); + if(it != g_dest_session_info_map.end()) + { + session_info = &it->second; + } + else + { + status = INVALID_SESSION; + break; + } + + if(session_info->status != IN_PROGRESS) + { + status = INVALID_SESSION; + break; + } + + memcpy(&sgx_dh_session, &session_info->in_progress.dh_session, sizeof(sgx_dh_session_t)); + + dh_msg3->msg3_body.additional_prop_length = 0; + //Process message 2 from source enclave and obtain message 3 + sgx_status_t se_ret = sgx_dh_responder_proc_msg2(dh_msg2, + dh_msg3, + &sgx_dh_session, + &dh_aek, + &initiator_identity); + if(SGX_SUCCESS != se_ret) + { + status = se_ret; + break; + } + + //Verify source enclave's trust + if(verify_peer_enclave_trust(&initiator_identity) != SUCCESS) + { + return INVALID_SESSION; + } + + //save the session ID, status and initialize the session nonce + session_info->session_id = session_id; + session_info->status = ACTIVE; + session_info->active.counter = 0; + memcpy(session_info->active.AEK, &dh_aek, sizeof(sgx_key_128bit_t)); + memset(&dh_aek,0, sizeof(sgx_key_128bit_t)); + g_session_count++; + }while(0); + + if(status != SUCCESS) + { + end_session(src_enclave_id); + } + + return status; +} + +//Request for the response size, send the request message to the destination enclave and receive the response message back +ATTESTATION_STATUS send_request_receive_response(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id, + dh_session_t *session_info, + char *inp_buff, + size_t inp_buff_len, + size_t max_out_buff_size, + char **out_buff, + size_t* out_buff_len) +{ + const uint8_t* plaintext; + uint32_t plaintext_length; + sgx_status_t status; + uint32_t retstatus; + secure_message_t* req_message; + secure_message_t* resp_message; + uint8_t *decrypted_data; + uint32_t decrypted_data_length; + uint32_t plain_text_offset; + uint8_t l_tag[TAG_SIZE]; + size_t max_resp_message_length; + plaintext = (const uint8_t*)(" "); + plaintext_length = 0; + + if(!session_info || !inp_buff) + { + return INVALID_PARAMETER_ERROR; + } + //Check if the nonce for the session has not exceeded 2^32-2 if so end session and start a new session + if(session_info->active.counter == ((uint32_t) - 2)) + { + close_session(src_enclave_id, dest_enclave_id); + create_session(src_enclave_id, dest_enclave_id, session_info); + } + + //Allocate memory for the AES-GCM request message + req_message = (secure_message_t*)malloc(sizeof(secure_message_t)+ inp_buff_len); + if(!req_message) + { + return MALLOC_ERROR; + } + + memset(req_message,0,sizeof(secure_message_t)+ inp_buff_len); + const uint32_t data2encrypt_length = (uint32_t)inp_buff_len; + //Set the payload size to data to encrypt length + req_message->message_aes_gcm_data.payload_size = data2encrypt_length; + + //Use the session nonce as the payload IV + memcpy(req_message->message_aes_gcm_data.reserved,&session_info->active.counter,sizeof(session_info->active.counter)); + + //Set the session ID of the message to the current session id + req_message->session_id = session_info->session_id; + + //Prepare the request message with the encrypted payload + status = sgx_rijndael128GCM_encrypt(&session_info->active.AEK, (uint8_t*)inp_buff, data2encrypt_length, + reinterpret_cast(&(req_message->message_aes_gcm_data.payload)), + reinterpret_cast(&(req_message->message_aes_gcm_data.reserved)), + sizeof(req_message->message_aes_gcm_data.reserved), plaintext, plaintext_length, + &(req_message->message_aes_gcm_data.payload_tag)); + + if(SGX_SUCCESS != status) + { + SAFE_FREE(req_message); + return status; + } + + //Allocate memory for the response payload to be copied + *out_buff = (char*)malloc(max_out_buff_size); + if(!*out_buff) + { + SAFE_FREE(req_message); + return MALLOC_ERROR; + } + + memset(*out_buff, 0, max_out_buff_size); + + //Allocate memory for the response message + resp_message = (secure_message_t*)malloc(sizeof(secure_message_t)+ max_out_buff_size); + if(!resp_message) + { + SAFE_FREE(req_message); + return MALLOC_ERROR; + } + + memset(resp_message, 0, sizeof(secure_message_t)+ max_out_buff_size); + + //Ocall to send the request to the Destination Enclave and get the response message back + status = send_request_ocall(&retstatus, src_enclave_id, dest_enclave_id, req_message, + (sizeof(secure_message_t)+ inp_buff_len), max_out_buff_size, + resp_message, (sizeof(secure_message_t)+ max_out_buff_size)); + if (status == SGX_SUCCESS) + { + if ((ATTESTATION_STATUS)retstatus != SUCCESS) + { + SAFE_FREE(req_message); + SAFE_FREE(resp_message); + return ((ATTESTATION_STATUS)retstatus); + } + } + else + { + SAFE_FREE(req_message); + SAFE_FREE(resp_message); + return ATTESTATION_SE_ERROR; + } + + max_resp_message_length = sizeof(secure_message_t)+ max_out_buff_size; + + if(sizeof(resp_message) > max_resp_message_length) + { + SAFE_FREE(req_message); + SAFE_FREE(resp_message); + return INVALID_PARAMETER_ERROR; + } + + //Code to process the response message from the Destination Enclave + + decrypted_data_length = resp_message->message_aes_gcm_data.payload_size; + plain_text_offset = decrypted_data_length; + decrypted_data = (uint8_t*)malloc(decrypted_data_length); + if(!decrypted_data) + { + SAFE_FREE(req_message); + SAFE_FREE(resp_message); + return MALLOC_ERROR; + } + memset(&l_tag, 0, 16); + + memset(decrypted_data, 0, decrypted_data_length); + + //Decrypt the response message payload + status = sgx_rijndael128GCM_decrypt(&session_info->active.AEK, resp_message->message_aes_gcm_data.payload, + decrypted_data_length, decrypted_data, + reinterpret_cast(&(resp_message->message_aes_gcm_data.reserved)), + sizeof(resp_message->message_aes_gcm_data.reserved), &(resp_message->message_aes_gcm_data.payload[plain_text_offset]), plaintext_length, + &resp_message->message_aes_gcm_data.payload_tag); + + if(SGX_SUCCESS != status) + { + SAFE_FREE(req_message); + SAFE_FREE(decrypted_data); + SAFE_FREE(resp_message); + return status; + } + + // Verify if the nonce obtained in the response is equal to the session nonce + 1 (Prevents replay attacks) + if(*(resp_message->message_aes_gcm_data.reserved) != (session_info->active.counter + 1 )) + { + SAFE_FREE(req_message); + SAFE_FREE(resp_message); + SAFE_FREE(decrypted_data); + return INVALID_PARAMETER_ERROR; + } + + //Update the value of the session nonce in the source enclave + session_info->active.counter = session_info->active.counter + 1; + + memcpy(out_buff_len, &decrypted_data_length, sizeof(decrypted_data_length)); + memcpy(*out_buff, decrypted_data, decrypted_data_length); + + SAFE_FREE(decrypted_data); + SAFE_FREE(req_message); + SAFE_FREE(resp_message); + return SUCCESS; + + +} + +//Process the request from the Source enclave and send the response message back to the Source enclave +ATTESTATION_STATUS generate_response(sgx_enclave_id_t src_enclave_id, + secure_message_t* req_message, + size_t req_message_size, + size_t max_payload_size, + secure_message_t* resp_message, + size_t resp_message_size) +{ + const uint8_t* plaintext; + uint32_t plaintext_length; + uint8_t *decrypted_data; + uint32_t decrypted_data_length; + uint32_t plain_text_offset; + ms_in_msg_exchange_t * ms; + size_t resp_data_length; + size_t resp_message_calc_size; + char* resp_data; + uint8_t l_tag[TAG_SIZE]; + size_t header_size, expected_payload_size; + dh_session_t *session_info; + secure_message_t* temp_resp_message; + uint32_t ret; + sgx_status_t status; + + plaintext = (const uint8_t*)(" "); + plaintext_length = 0; + + if(!req_message || !resp_message) + { + return INVALID_PARAMETER_ERROR; + } + + //Get the session information from the map corresponding to the source enclave id + std::map::iterator it = g_dest_session_info_map.find(src_enclave_id); + if(it != g_dest_session_info_map.end()) + { + session_info = &it->second; + } + else + { + return INVALID_SESSION; + } + + if(session_info->status != ACTIVE) + { + return INVALID_SESSION; + } + + //Set the decrypted data length to the payload size obtained from the message + decrypted_data_length = req_message->message_aes_gcm_data.payload_size; + + header_size = sizeof(secure_message_t); + expected_payload_size = req_message_size - header_size; + + //Verify the size of the payload + if(expected_payload_size != decrypted_data_length) + return INVALID_PARAMETER_ERROR; + + memset(&l_tag, 0, 16); + plain_text_offset = decrypted_data_length; + decrypted_data = (uint8_t*)malloc(decrypted_data_length); + if(!decrypted_data) + { + return MALLOC_ERROR; + } + + memset(decrypted_data, 0, decrypted_data_length); + + //Decrypt the request message payload from source enclave + status = sgx_rijndael128GCM_decrypt(&session_info->active.AEK, req_message->message_aes_gcm_data.payload, + decrypted_data_length, decrypted_data, + reinterpret_cast(&(req_message->message_aes_gcm_data.reserved)), + sizeof(req_message->message_aes_gcm_data.reserved), &(req_message->message_aes_gcm_data.payload[plain_text_offset]), plaintext_length, + &req_message->message_aes_gcm_data.payload_tag); + + if(SGX_SUCCESS != status) + { + SAFE_FREE(decrypted_data); + return status; + } + + //Casting the decrypted data to the marshaling structure type to obtain type of request (generic message exchange/enclave to enclave call) + ms = (ms_in_msg_exchange_t *)decrypted_data; + + + // Verify if the nonce obtained in the request is equal to the session nonce + if((uint32_t)*(req_message->message_aes_gcm_data.reserved) != session_info->active.counter || *(req_message->message_aes_gcm_data.reserved) > ((2^32)-2)) + { + SAFE_FREE(decrypted_data); + return INVALID_PARAMETER_ERROR; + } + + if(ms->msg_type == MESSAGE_EXCHANGE) + { + //Call the generic secret response generator for message exchange + ret = message_exchange_response_generator((char*)decrypted_data, &resp_data, &resp_data_length); + if(ret !=0) + { + SAFE_FREE(decrypted_data); + SAFE_FREE(resp_data); + return INVALID_SESSION; + } + } + else if(ms->msg_type == ENCLAVE_TO_ENCLAVE_CALL) + { + //Call the destination enclave's dispatcher to call the appropriate function in the destination enclave + ret = enclave_to_enclave_call_dispatcher((char*)decrypted_data, decrypted_data_length, &resp_data, &resp_data_length); + if(ret !=0) + { + SAFE_FREE(decrypted_data); + SAFE_FREE(resp_data); + return INVALID_SESSION; + } + } + else + { + SAFE_FREE(decrypted_data); + return INVALID_REQUEST_TYPE_ERROR; + } + + + if(resp_data_length > max_payload_size) + { + SAFE_FREE(resp_data); + SAFE_FREE(decrypted_data); + return OUT_BUFFER_LENGTH_ERROR; + } + + resp_message_calc_size = sizeof(secure_message_t)+ resp_data_length; + + if(resp_message_calc_size > resp_message_size) + { + SAFE_FREE(resp_data); + SAFE_FREE(decrypted_data); + return OUT_BUFFER_LENGTH_ERROR; + } + + //Code to build the response back to the Source Enclave + temp_resp_message = (secure_message_t*)malloc(resp_message_calc_size); + if(!temp_resp_message) + { + SAFE_FREE(resp_data); + SAFE_FREE(decrypted_data); + return MALLOC_ERROR; + } + + memset(temp_resp_message,0,sizeof(secure_message_t)+ resp_data_length); + const uint32_t data2encrypt_length = (uint32_t)resp_data_length; + temp_resp_message->session_id = session_info->session_id; + temp_resp_message->message_aes_gcm_data.payload_size = data2encrypt_length; + + //Increment the Session Nonce (Replay Protection) + session_info->active.counter = session_info->active.counter + 1; + + //Set the response nonce as the session nonce + memcpy(&temp_resp_message->message_aes_gcm_data.reserved,&session_info->active.counter,sizeof(session_info->active.counter)); + + //Prepare the response message with the encrypted payload + status = sgx_rijndael128GCM_encrypt(&session_info->active.AEK, (uint8_t*)resp_data, data2encrypt_length, + reinterpret_cast(&(temp_resp_message->message_aes_gcm_data.payload)), + reinterpret_cast(&(temp_resp_message->message_aes_gcm_data.reserved)), + sizeof(temp_resp_message->message_aes_gcm_data.reserved), plaintext, plaintext_length, + &(temp_resp_message->message_aes_gcm_data.payload_tag)); + + if(SGX_SUCCESS != status) + { + SAFE_FREE(resp_data); + SAFE_FREE(decrypted_data); + SAFE_FREE(temp_resp_message); + return status; + } + + memset(resp_message, 0, sizeof(secure_message_t)+ resp_data_length); + memcpy(resp_message, temp_resp_message, sizeof(secure_message_t)+ resp_data_length); + + SAFE_FREE(decrypted_data); + SAFE_FREE(resp_data); + SAFE_FREE(temp_resp_message); + + return SUCCESS; +} + +//Close a current session +ATTESTATION_STATUS close_session(sgx_enclave_id_t src_enclave_id, + sgx_enclave_id_t dest_enclave_id) +{ + sgx_status_t status; + + uint32_t retstatus; + + //Ocall to ask the destination enclave to end the session + status = end_session_ocall(&retstatus, src_enclave_id, dest_enclave_id); + if (status == SGX_SUCCESS) + { + if ((ATTESTATION_STATUS)retstatus != SUCCESS) + return ((ATTESTATION_STATUS)retstatus); + } + else + { + return ATTESTATION_SE_ERROR; + } + return SUCCESS; +} + +//Respond to the request from the Source Enclave to close the session +ATTESTATION_STATUS end_session(sgx_enclave_id_t src_enclave_id) +{ + ATTESTATION_STATUS status = SUCCESS; + int i; + dh_session_t session_info; + uint32_t session_id; + + //Get the session information from the map corresponding to the source enclave id + std::map::iterator it = g_dest_session_info_map.find(src_enclave_id); + if(it != g_dest_session_info_map.end()) + { + session_info = it->second; + } + else + { + return INVALID_SESSION; + } + + session_id = session_info.session_id; + //Erase the session information for the current session + g_dest_session_info_map.erase(src_enclave_id); + + //Update the session id tracker + if (g_session_count > 0) + { + //check if session exists + for (i=1; i <= MAX_SESSION_COUNT; i++) + { + if(g_session_id_tracker[i-1] != NULL && g_session_id_tracker[i-1]->session_id == session_id) + { + memset(g_session_id_tracker[i-1], 0, sizeof(session_id_tracker_t)); + SAFE_FREE(g_session_id_tracker[i-1]); + g_session_count--; + break; + } + } + } + + return status; + +} + + +//Returns a new sessionID for the source destination session +ATTESTATION_STATUS generate_session_id(uint32_t *session_id) +{ + ATTESTATION_STATUS status = SUCCESS; + + if(!session_id) + { + return INVALID_PARAMETER_ERROR; + } + //if the session structure is untintialized, set that as the next session ID + for (int i = 0; i < MAX_SESSION_COUNT; i++) + { + if (g_session_id_tracker[i] == NULL) + { + *session_id = i; + return status; + } + } + + status = NO_AVAILABLE_SESSION_ERROR; + + return status; + +} diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/EnclaveMessageExchange.h b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/EnclaveMessageExchange.h new file mode 100644 index 0000000000..c16a24656e --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/EnclaveMessageExchange.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "datatypes.h" +#include "sgx_eid.h" +#include "sgx_trts.h" +#include +#include "dh_session_protocol.h" + +#ifndef LOCALATTESTATION_H_ +#define LOCALATTESTATION_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t SGXAPI create_session(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id, dh_session_t *p_session_info); +uint32_t SGXAPI send_request_receive_response(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id, dh_session_t *p_session_info, char *inp_buff, size_t inp_buff_len, size_t max_out_buff_size, char **out_buff, size_t* out_buff_len); +uint32_t SGXAPI close_session(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/LocalAttestationCode.edl b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/LocalAttestationCode.edl new file mode 100644 index 0000000000..8e401ee843 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/LocalAttestationCode.edl @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +enclave { + include "sgx_eid.h" + include "datatypes.h" + include "../Include/dh_session_protocol.h" + trusted{ + public uint32_t session_request(sgx_enclave_id_t src_enclave_id, [out] sgx_dh_msg1_t *dh_msg1, [out] uint32_t *session_id); + public uint32_t exchange_report(sgx_enclave_id_t src_enclave_id, [in] sgx_dh_msg2_t *dh_msg2, [out] sgx_dh_msg3_t *dh_msg3, uint32_t session_id); + public uint32_t generate_response(sgx_enclave_id_t src_enclave_id, [in, size = req_message_size] secure_message_t* req_message, size_t req_message_size, size_t max_payload_size, [out, size=resp_message_size] secure_message_t* resp_message, size_t resp_message_size ); + public uint32_t end_session(sgx_enclave_id_t src_enclave_id); + }; + + untrusted{ + uint32_t session_request_ocall(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id, [out] sgx_dh_msg1_t *dh_msg1,[out] uint32_t *session_id); + uint32_t exchange_report_ocall(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id, [in] sgx_dh_msg2_t *dh_msg2, [out] sgx_dh_msg3_t *dh_msg3, uint32_t session_id); + uint32_t send_request_ocall(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id, [in, size = req_message_size] secure_message_t* req_message, size_t req_message_size, size_t max_payload_size, [out, size=resp_message_size] secure_message_t* resp_message, size_t resp_message_size); + uint32_t end_session_ocall(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + }; +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/datatypes.h b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/datatypes.h new file mode 100644 index 0000000000..1c198aa141 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/datatypes.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "sgx_report.h" +#include "sgx_eid.h" +#include "sgx_ecp_types.h" +#include "sgx_dh.h" +#include "sgx_tseal.h" + +#ifndef DATATYPES_H_ +#define DATATYPES_H_ + +#define DH_KEY_SIZE 20 +#define NONCE_SIZE 16 +#define MAC_SIZE 16 +#define MAC_KEY_SIZE 16 +#define PADDING_SIZE 16 + +#define TAG_SIZE 16 +#define IV_SIZE 12 + +#define DERIVE_MAC_KEY 0x0 +#define DERIVE_SESSION_KEY 0x1 +#define DERIVE_VK1_KEY 0x3 +#define DERIVE_VK2_KEY 0x4 + +#define CLOSED 0x0 +#define IN_PROGRESS 0x1 +#define ACTIVE 0x2 + +#define MESSAGE_EXCHANGE 0x0 +#define ENCLAVE_TO_ENCLAVE_CALL 0x1 + +#define INVALID_ARGUMENT -2 ///< Invalid function argument +#define LOGIC_ERROR -3 ///< Functional logic error +#define FILE_NOT_FOUND -4 ///< File not found + +#define SAFE_FREE(ptr) {if (NULL != (ptr)) {free(ptr); (ptr)=NULL;}} + +#define VMC_ATTRIBUTE_MASK 0xFFFFFFFFFFFFFFCB + +typedef uint8_t dh_nonce[NONCE_SIZE]; +typedef uint8_t cmac_128[MAC_SIZE]; + +#pragma pack(push, 1) + +//Format of the AES-GCM message being exchanged between the source and the destination enclaves +typedef struct _secure_message_t +{ + uint32_t session_id; //Session ID identifyting the session to which the message belongs + sgx_aes_gcm_data_t message_aes_gcm_data; +}secure_message_t; + +//Format of the input function parameter structure +typedef struct _ms_in_msg_exchange_t { + uint32_t msg_type; //Type of Call E2E or general message exchange + uint32_t target_fn_id; //Function Id to be called in Destination. Is valid only when msg_type=ENCLAVE_TO_ENCLAVE_CALL + uint32_t inparam_buff_len; //Length of the serialized input parameters + char inparam_buff[]; //Serialized input parameters +} ms_in_msg_exchange_t; + +//Format of the return value and output function parameter structure +typedef struct _ms_out_msg_exchange_t { + uint32_t retval_len; //Length of the return value + uint32_t ret_outparam_buff_len; //Length of the serialized return value and output parameters + char ret_outparam_buff[]; //Serialized return value and output parameters +} ms_out_msg_exchange_t; + +//Session Tracker to generate session ids +typedef struct _session_id_tracker_t +{ + uint32_t session_id; +}session_id_tracker_t; + +#pragma pack(pop) + +#endif diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/error_codes.h b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/error_codes.h new file mode 100644 index 0000000000..0bb2a25cf4 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/LocalAttestationCode/error_codes.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef ERROR_CODES_H_ +#define ERROR_CODES_H_ + +typedef uint32_t ATTESTATION_STATUS; + +#define SUCCESS 0x00 +#define INVALID_PARAMETER 0xE1 +#define VALID_SESSION 0xE2 +#define INVALID_SESSION 0xE3 +#define ATTESTATION_ERROR 0xE4 +#define ATTESTATION_SE_ERROR 0xE5 +#define IPP_ERROR 0xE6 +#define NO_AVAILABLE_SESSION_ERROR 0xE7 +#define MALLOC_ERROR 0xE8 +#define ERROR_TAG_MISMATCH 0xE9 +#define OUT_BUFFER_LENGTH_ERROR 0xEA +#define INVALID_REQUEST_TYPE_ERROR 0xEB +#define INVALID_PARAMETER_ERROR 0xEC +#define ENCLAVE_TRUST_ERROR 0xED +#define ENCRYPT_DECRYPT_ERROR 0xEE +#define DUPLICATE_SESSION 0xEF +#endif diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Makefile b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Makefile new file mode 100644 index 0000000000..4fb31a0b3c --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Makefile @@ -0,0 +1,328 @@ +# +# Copyright (C) 2011-2016 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# + +######## SGX SDK Settings ######## + +SGX_SDK ?= /opt/intel/sgxsdk +SGX_MODE ?= HW +SGX_ARCH ?= x64 +SGX_DEBUG ?= 1 + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +######## Library Settings ######## + +Trust_Lib_Name := libLocalAttestation_Trusted.a +TrustLib_Cpp_Files := $(wildcard LocalAttestationCode/*.cpp) +TrustLib_Cpp_Objects := $(TrustLib_Cpp_Files:.cpp=.o) +TrustLib_Include_Paths := -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport -I$(SGX_SDK)/include/epid -I./Include +TrustLib_Compile_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $(TrustLib_Include_Paths) +TrustLib_Compile_Cxx_Flags := -std=c++03 -nostdinc++ + +UnTrustLib_Name := libLocalAttestation_unTrusted.a +UnTrustLib_Cpp_Files := $(wildcard Untrusted_LocalAttestation/*.cpp) +UnTrustLib_Cpp_Objects := $(UnTrustLib_Cpp_Files:.cpp=.o) +UnTrustLib_Include_Paths := -I$(SGX_SDK)/include -I$(SGX_SDK)/include/ippcp -I./Include -I./LocalAttestationCode +UnTrustLib_Compile_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes -std=c++11 $(UnTrustLib_Include_Paths) + +######## App Settings ######## + +ifneq ($(SGX_MODE), HW) + Urts_Library_Name := sgx_urts_sim +else + Urts_Library_Name := sgx_urts +endif + +App_Cpp_Files := $(wildcard App/*.cpp) +App_Include_Paths := -I$(SGX_SDK)/include -I$(SGX_SDK)/include/ippcp -I./Include -I./LocalAttestationCode + +App_Compile_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) +# Three configuration modes - Debug, prerelease, release +# Debug - Macro DEBUG enabled. +# Prerelease - Macro NDEBUG and EDEBUG enabled. +# Release - Macro NDEBUG enabled. +ifeq ($(SGX_DEBUG), 1) + App_Compile_Flags += -DDEBUG -UNDEBUG -UEDEBUG +else ifeq ($(SGX_PRERELEASE), 1) + App_Compile_Flags += -DNDEBUG -DEDEBUG -UDEBUG +else + App_Compile_Flags += -DNDEBUG -UEDEBUG -UDEBUG +endif + +App_Link_Flags := $(SGX_COMMON_CFLAGS) -L$(SGX_LIBRARY_PATH) -l$(Urts_Library_Name) -L. -lpthread -lLocalAttestation_unTrusted + +ifneq ($(SGX_MODE), HW) + App_Link_Flags += -lsgx_uae_service_sim +else + App_Link_Flags += -lsgx_uae_service +endif + +App_Cpp_Objects := $(App_Cpp_Files:.cpp=.o) +App_Name := app + +######## Enclave Settings ######## + +ifneq ($(SGX_MODE), HW) + Trts_Library_Name := sgx_trts_sim + Service_Library_Name := sgx_tservice_sim +else + Trts_Library_Name := sgx_trts + Service_Library_Name := sgx_tservice +endif +Crypto_Library_Name := sgx_tcrypto + +Enclave_Cpp_Files_1 := $(wildcard Enclave1/*.cpp) +Enclave_Cpp_Files_2 := $(wildcard Enclave2/*.cpp) +Enclave_Cpp_Files_3 := $(wildcard Enclave3/*.cpp) +Enclave_Include_Paths := -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport -I./LocalAttestationCode -I./Include + +Enclave_Compile_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $(Enclave_Include_Paths) + +# To generate a proper enclave, it is recommended to follow below guideline to link the trusted libraries: +# 1. Link sgx_trts with the `--whole-archive' and `--no-whole-archive' options, +# so that the whole content of trts is included in the enclave. +# 2. For other libraries, you just need to pull the required symbols. +# Use `--start-group' and `--end-group' to link these libraries. +# Do NOT move the libraries linked with `--start-group' and `--end-group' within `--whole-archive' and `--no-whole-archive' options. +# Otherwise, you may get some undesirable errors. +Enclave_Link_Flags := $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \ + -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive \ + -Wl,--start-group -lsgx_tstdc -lsgx_tstdcxx -l$(Crypto_Library_Name) -L. -lLocalAttestation_Trusted -l$(Service_Library_Name) -Wl,--end-group \ + -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \ + -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \ + -Wl,--defsym,__ImageBase=0 + +Enclave_Cpp_Objects_1 := $(Enclave_Cpp_Files_1:.cpp=.o) +Enclave_Cpp_Objects_2 := $(Enclave_Cpp_Files_2:.cpp=.o) +Enclave_Cpp_Objects_3 := $(Enclave_Cpp_Files_3:.cpp=.o) + +Enclave_Name_1 := libenclave1.so +Enclave_Name_2 := libenclave2.so +Enclave_Name_3 := libenclave3.so + +ifeq ($(SGX_MODE), HW) +ifeq ($(SGX_DEBUG), 1) + Build_Mode = HW_DEBUG +else ifeq ($(SGX_PRERELEASE), 1) + Build_Mode = HW_PRERELEASE +else + Build_Mode = HW_RELEASE +endif +else +ifeq ($(SGX_DEBUG), 1) + Build_Mode = SIM_DEBUG +else ifeq ($(SGX_PRERELEASE), 1) + Build_Mode = SIM_PRERELEASE +else + Build_Mode = SIM_RELEASE +endif +endif + +ifeq ($(Build_Mode), HW_RELEASE) +all: $(Trust_Lib_Name) $(UnTrustLib_Name) Enclave1.so Enclave2.so Enclave3.so $(App_Name) + @echo "The project has been built in release hardware mode." + @echo "Please sign the enclaves (Enclave1.so, Enclave2.so, Enclave3.so) first with your signing keys before you run the $(App_Name) to launch and access the enclave." + @echo "To sign the enclaves use the following commands:" + @echo " $(SGX_ENCLAVE_SIGNER) sign -key -enclave Enclave1.so -out <$(Enclave_Name_1)> -config Enclave1/Enclave1.config.xml" + @echo " $(SGX_ENCLAVE_SIGNER) sign -key -enclave Enclave2.so -out <$(Enclave_Name_2)> -config Enclave2/Enclave2.config.xml" + @echo " $(SGX_ENCLAVE_SIGNER) sign -key -enclave Enclave3.so -out <$(Enclave_Name_3)> -config Enclave3/Enclave3.config.xml" + @echo "You can also sign the enclaves using an external signing tool." + @echo "To build the project in simulation mode set SGX_MODE=SIM. To build the project in prerelease mode set SGX_PRERELEASE=1 and SGX_MODE=HW." +else +all: $(Trust_Lib_Name) $(UnTrustLib_Name) $(Enclave_Name_1) $(Enclave_Name_2) $(Enclave_Name_3) $(App_Name) +ifeq ($(Build_Mode), HW_DEBUG) + @echo "The project has been built in debug hardware mode." +else ifeq ($(Build_Mode), SIM_DEBUG) + @echo "The project has been built in debug simulation mode." +else ifeq ($(Build_Mode), HW_PRERELEASE) + @echo "The project has been built in pre-release hardware mode." +else ifeq ($(Build_Mode), SIM_PRERELEASE) + @echo "The project has been built in pre-release simulation mode." +else + @echo "The project has been built in release simulation mode." +endif +endif + +######## Library Objects ######## + +LocalAttestationCode/LocalAttestationCode_t.c LocalAttestationCode/LocalAttestationCode_t.h : $(SGX_EDGER8R) LocalAttestationCode/LocalAttestationCode.edl + @cd LocalAttestationCode && $(SGX_EDGER8R) --trusted ../LocalAttestationCode/LocalAttestationCode.edl --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +LocalAttestationCode/LocalAttestationCode_t.o: LocalAttestationCode/LocalAttestationCode_t.c + @$(CC) $(TrustLib_Compile_Flags) -c $< -o $@ + @echo "CC <= $<" + +LocalAttestationCode/%.o: LocalAttestationCode/%.cpp LocalAttestationCode/LocalAttestationCode_t.h + @$(CXX) $(TrustLib_Compile_Flags) $(TrustLib_Compile_Cxx_Flags) -c $< -o $@ + @echo "CC <= $<" + +$(Trust_Lib_Name): LocalAttestationCode/LocalAttestationCode_t.o $(TrustLib_Cpp_Objects) + @$(AR) rcs $@ $^ + @echo "GEN => $@" + +Untrusted_LocalAttestation/%.o: Untrusted_LocalAttestation/%.cpp + @$(CXX) $(UnTrustLib_Compile_Flags) -c $< -o $@ + @echo "CC <= $<" + +$(UnTrustLib_Name): $(UnTrustLib_Cpp_Objects) + @$(AR) rcs $@ $^ + @echo "GEN => $@" + +######## App Objects ######## +Enclave1/Enclave1_u.c Enclave1/Enclave1_u.h: $(SGX_EDGER8R) Enclave1/Enclave1.edl + @cd Enclave1 && $(SGX_EDGER8R) --use-prefix --untrusted ../Enclave1/Enclave1.edl --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +App/Enclave1_u.o: Enclave1/Enclave1_u.c + @$(CC) $(App_Compile_Flags) -c $< -o $@ + @echo "CC <= $<" + +Enclave2/Enclave2_u.c Enclave2/Enclave2_u.h: $(SGX_EDGER8R) Enclave2/Enclave2.edl + @cd Enclave2 && $(SGX_EDGER8R) --use-prefix --untrusted ../Enclave2/Enclave2.edl --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +App/Enclave2_u.o: Enclave2/Enclave2_u.c + @$(CC) $(App_Compile_Flags) -c $< -o $@ + @echo "CC <= $<" + +Enclave3/Enclave3_u.c Enclave3/Enclave3_u.h: $(SGX_EDGER8R) Enclave3/Enclave3.edl + @cd Enclave3 && $(SGX_EDGER8R) --use-prefix --untrusted ../Enclave3/Enclave3.edl --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +App/Enclave3_u.o: Enclave3/Enclave3_u.c + @$(CC) $(App_Compile_Flags) -c $< -o $@ + @echo "CC <= $<" + +App/%.o: App/%.cpp Enclave1/Enclave1_u.h Enclave2/Enclave2_u.h Enclave3/Enclave3_u.h + @$(CXX) $(App_Compile_Flags) -c $< -o $@ + @echo "CXX <= $<" + +$(App_Name): App/Enclave1_u.o App/Enclave2_u.o App/Enclave3_u.o $(App_Cpp_Objects) $(UnTrustLib_Name) + @$(CXX) $^ -o $@ $(App_Link_Flags) + @echo "LINK => $@" + + +######## Enclave Objects ######## + +Enclave1/Enclave1_t.c Enclave1/Enclave1_t.h: $(SGX_EDGER8R) Enclave1/Enclave1.edl + @cd Enclave1 && $(SGX_EDGER8R) --use-prefix --trusted ../Enclave1/Enclave1.edl --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +Enclave1/Enclave1_t.o: Enclave1/Enclave1_t.c + @$(CC) $(Enclave_Compile_Flags) -c $< -o $@ + @echo "CC <= $<" + +Enclave1/%.o: Enclave1/%.cpp Enclave1/Enclave1_t.h + @$(CXX) -std=c++03 -nostdinc++ $(Enclave_Compile_Flags) -c $< -o $@ + @echo "CXX <= $<" + +Enclave1.so: Enclave1/Enclave1_t.o $(Enclave_Cpp_Objects_1) $(Trust_Lib_Name) + @$(CXX) Enclave1/Enclave1_t.o $(Enclave_Cpp_Objects_1) -o $@ $(Enclave_Link_Flags) + @echo "LINK => $@" + +$(Enclave_Name_1): Enclave1.so + @$(SGX_ENCLAVE_SIGNER) sign -key Enclave1/Enclave1_private.pem -enclave Enclave1.so -out $@ -config Enclave1/Enclave1.config.xml + @echo "SIGN => $@" + +Enclave2/Enclave2_t.c: $(SGX_EDGER8R) Enclave2/Enclave2.edl + @cd Enclave2 && $(SGX_EDGER8R) --use-prefix --trusted ../Enclave2/Enclave2.edl --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +Enclave2/Enclave2_t.o: Enclave2/Enclave2_t.c + @$(CC) $(Enclave_Compile_Flags) -c $< -o $@ + @echo "CC <= $<" + +Enclave2/%.o: Enclave2/%.cpp + @$(CXX) -std=c++03 -nostdinc++ $(Enclave_Compile_Flags) -c $< -o $@ + @echo "CXX <= $<" + +Enclave2.so: Enclave2/Enclave2_t.o $(Enclave_Cpp_Objects_2) $(Trust_Lib_Name) + @$(CXX) Enclave2/Enclave2_t.o $(Enclave_Cpp_Objects_2) -o $@ $(Enclave_Link_Flags) + @echo "LINK => $@" + +$(Enclave_Name_2): Enclave2.so + @$(SGX_ENCLAVE_SIGNER) sign -key Enclave2/Enclave2_private.pem -enclave Enclave2.so -out $@ -config Enclave2/Enclave2.config.xml + @echo "SIGN => $@" + +Enclave3/Enclave3_t.c: $(SGX_EDGER8R) Enclave3/Enclave3.edl + @cd Enclave3 && $(SGX_EDGER8R) --use-prefix --trusted ../Enclave3/Enclave3.edl --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +Enclave3/Enclave3_t.o: Enclave3/Enclave3_t.c + @$(CC) $(Enclave_Compile_Flags) -c $< -o $@ + @echo "CC <= $<" + +Enclave3/%.o: Enclave3/%.cpp + @$(CXX) -std=c++03 -nostdinc++ $(Enclave_Compile_Flags) -c $< -o $@ + @echo "CXX <= $<" + +Enclave3.so: Enclave3/Enclave3_t.o $(Enclave_Cpp_Objects_3) $(Trust_Lib_Name) + @$(CXX) Enclave3/Enclave3_t.o $(Enclave_Cpp_Objects_3) -o $@ $(Enclave_Link_Flags) + @echo "LINK => $@" + +$(Enclave_Name_3): Enclave3.so + @$(SGX_ENCLAVE_SIGNER) sign -key Enclave3/Enclave3_private.pem -enclave Enclave3.so -out $@ -config Enclave3/Enclave3.config.xml + @echo "SIGN => $@" + +######## Clean ######## +.PHONY: clean + +clean: + @rm -rf $(App_Name) *.so *.a App/*.o Enclave1/*.o Enclave1/*_t.* Enclave1/*_u.* Enclave2/*.o Enclave2/*_t.* Enclave2/*_u.* Enclave3/*.o Enclave3/*_t.* Enclave3/*_u.* LocalAttestationCode/*.o Untrusted_LocalAttestation/*.o LocalAttestationCode/*_t.* diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/README.txt b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/README.txt new file mode 100644 index 0000000000..882143468d --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/README.txt @@ -0,0 +1,27 @@ +--------------------------- +Purpose of LocalAttestation +--------------------------- +The project demonstrates: +- How to establish a protected channel +- Secret message exchange using enclave to enclave function calls + +------------------------------------ +How to Build/Execute the Sample Code +------------------------------------ +1. Install Intel(R) SGX SDK for Linux* OS +2. Build the project with the prepared Makefile: + a. Hardware Mode, Debug build: + $ make + b. Hardware Mode, Pre-release build: + $ make SGX_PRERELEASE=1 SGX_DEBUG=0 + c. Hardware Mode, Release build: + $ make SGX_DEBUG=0 + d. Simulation Mode, Debug build: + $ make SGX_MODE=SIM + e. Simulation Mode, Pre-release build: + $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0 + f. Simulation Mode, Release build: + $ make SGX_MODE=SIM SGX_DEBUG=0 +3. Execute the binary directly: + $ ./app +4. Remember to "make clean" before switching build mode diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Untrusted_LocalAttestation/UntrustedEnclaveMessageExchange.cpp b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Untrusted_LocalAttestation/UntrustedEnclaveMessageExchange.cpp new file mode 100644 index 0000000000..805c14abad --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Untrusted_LocalAttestation/UntrustedEnclaveMessageExchange.cpp @@ -0,0 +1,184 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "sgx_eid.h" +#include "error_codes.h" +#include "datatypes.h" +#include "sgx_urts.h" +#include "UntrustedEnclaveMessageExchange.h" +#include "sgx_dh.h" +#include + +std::mapg_enclave_id_map; + +//Makes an sgx_ecall to the destination enclave to get session id and message1 +ATTESTATION_STATUS session_request_ocall(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id, sgx_dh_msg1_t* dh_msg1, uint32_t* session_id) +{ + uint32_t status = 0; + sgx_status_t ret = SGX_SUCCESS; + uint32_t temp_enclave_no; + + std::map::iterator it = g_enclave_id_map.find(dest_enclave_id); + if(it != g_enclave_id_map.end()) + { + temp_enclave_no = it->second; + } + else + { + return INVALID_SESSION; + } + + switch(temp_enclave_no) + { + case 1: + ret = Enclave1_session_request(dest_enclave_id, &status, src_enclave_id, dh_msg1, session_id); + break; + case 2: + ret = Enclave2_session_request(dest_enclave_id, &status, src_enclave_id, dh_msg1, session_id); + break; + case 3: + ret = Enclave3_session_request(dest_enclave_id, &status, src_enclave_id, dh_msg1, session_id); + break; + } + if (ret == SGX_SUCCESS) + return (ATTESTATION_STATUS)status; + else + return INVALID_SESSION; + +} +//Makes an sgx_ecall to the destination enclave sends message2 from the source enclave and gets message 3 from the destination enclave +ATTESTATION_STATUS exchange_report_ocall(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id, sgx_dh_msg2_t *dh_msg2, sgx_dh_msg3_t *dh_msg3, uint32_t session_id) +{ + uint32_t status = 0; + sgx_status_t ret = SGX_SUCCESS; + uint32_t temp_enclave_no; + + std::map::iterator it = g_enclave_id_map.find(dest_enclave_id); + if(it != g_enclave_id_map.end()) + { + temp_enclave_no = it->second; + } + else + { + return INVALID_SESSION; + } + + switch(temp_enclave_no) + { + case 1: + ret = Enclave1_exchange_report(dest_enclave_id, &status, src_enclave_id, dh_msg2, dh_msg3, session_id); + break; + case 2: + ret = Enclave2_exchange_report(dest_enclave_id, &status, src_enclave_id, dh_msg2, dh_msg3, session_id); + break; + case 3: + ret = Enclave3_exchange_report(dest_enclave_id, &status, src_enclave_id, dh_msg2, dh_msg3, session_id); + break; + } + if (ret == SGX_SUCCESS) + return (ATTESTATION_STATUS)status; + else + return INVALID_SESSION; + +} + +//Make an sgx_ecall to the destination enclave function that generates the actual response +ATTESTATION_STATUS send_request_ocall(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id,secure_message_t* req_message, size_t req_message_size, size_t max_payload_size, secure_message_t* resp_message, size_t resp_message_size) +{ + uint32_t status = 0; + sgx_status_t ret = SGX_SUCCESS; + uint32_t temp_enclave_no; + + std::map::iterator it = g_enclave_id_map.find(dest_enclave_id); + if(it != g_enclave_id_map.end()) + { + temp_enclave_no = it->second; + } + else + { + return INVALID_SESSION; + } + + switch(temp_enclave_no) + { + case 1: + ret = Enclave1_generate_response(dest_enclave_id, &status, src_enclave_id, req_message, req_message_size, max_payload_size, resp_message, resp_message_size); + break; + case 2: + ret = Enclave2_generate_response(dest_enclave_id, &status, src_enclave_id, req_message, req_message_size, max_payload_size, resp_message, resp_message_size); + break; + case 3: + ret = Enclave3_generate_response(dest_enclave_id, &status, src_enclave_id, req_message, req_message_size, max_payload_size, resp_message, resp_message_size); + break; + } + if (ret == SGX_SUCCESS) + return (ATTESTATION_STATUS)status; + else + return INVALID_SESSION; + +} + +//Make an sgx_ecall to the destination enclave to close the session +ATTESTATION_STATUS end_session_ocall(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id) +{ + uint32_t status = 0; + sgx_status_t ret = SGX_SUCCESS; + uint32_t temp_enclave_no; + + std::map::iterator it = g_enclave_id_map.find(dest_enclave_id); + if(it != g_enclave_id_map.end()) + { + temp_enclave_no = it->second; + } + else + { + return INVALID_SESSION; + } + + switch(temp_enclave_no) + { + case 1: + ret = Enclave1_end_session(dest_enclave_id, &status, src_enclave_id); + break; + case 2: + ret = Enclave2_end_session(dest_enclave_id, &status, src_enclave_id); + break; + case 3: + ret = Enclave3_end_session(dest_enclave_id, &status, src_enclave_id); + break; + } + if (ret == SGX_SUCCESS) + return (ATTESTATION_STATUS)status; + else + return INVALID_SESSION; + +} diff --git a/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Untrusted_LocalAttestation/UntrustedEnclaveMessageExchange.h b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Untrusted_LocalAttestation/UntrustedEnclaveMessageExchange.h new file mode 100644 index 0000000000..684b33cb3b --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/LocalAttestation/Untrusted_LocalAttestation/UntrustedEnclaveMessageExchange.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "sgx_eid.h" +#include "error_codes.h" +#include "datatypes.h" +#include "sgx_urts.h" +#include "dh_session_protocol.h" +#include "sgx_dh.h" +#include + + +#ifndef ULOCALATTESTATION_H_ +#define ULOCALATTESTATION_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +sgx_status_t Enclave1_session_request(sgx_enclave_id_t eid, uint32_t* retval, sgx_enclave_id_t src_enclave_id, sgx_dh_msg1_t* dh_msg1, uint32_t* session_id); +sgx_status_t Enclave1_exchange_report(sgx_enclave_id_t eid, uint32_t* retval, sgx_enclave_id_t src_enclave_id, sgx_dh_msg2_t* dh_msg2, sgx_dh_msg3_t* dh_msg3, uint32_t session_id); +sgx_status_t Enclave1_generate_response(sgx_enclave_id_t eid, uint32_t* retval, sgx_enclave_id_t src_enclave_id, secure_message_t* req_message, size_t req_message_size, size_t max_payload_size, secure_message_t* resp_message, size_t resp_message_size); +sgx_status_t Enclave1_end_session(sgx_enclave_id_t eid, uint32_t* retval, sgx_enclave_id_t src_enclave_id); + +sgx_status_t Enclave2_session_request(sgx_enclave_id_t eid, uint32_t* retval, sgx_enclave_id_t src_enclave_id, sgx_dh_msg1_t* dh_msg1, uint32_t* session_id); +sgx_status_t Enclave2_exchange_report(sgx_enclave_id_t eid, uint32_t* retval, sgx_enclave_id_t src_enclave_id, sgx_dh_msg2_t* dh_msg2, sgx_dh_msg3_t* dh_msg3, uint32_t session_id); +sgx_status_t Enclave2_generate_response(sgx_enclave_id_t eid, uint32_t* retval, sgx_enclave_id_t src_enclave_id, secure_message_t* req_message, size_t req_message_size, size_t max_payload_size, secure_message_t* resp_message, size_t resp_message_size); +sgx_status_t Enclave2_end_session(sgx_enclave_id_t eid, uint32_t* retval, sgx_enclave_id_t src_enclave_id); + +sgx_status_t Enclave3_session_request(sgx_enclave_id_t eid, uint32_t* retval, sgx_enclave_id_t src_enclave_id, sgx_dh_msg1_t* dh_msg1, uint32_t* session_id); +sgx_status_t Enclave3_exchange_report(sgx_enclave_id_t eid, uint32_t* retval, sgx_enclave_id_t src_enclave_id, sgx_dh_msg2_t* dh_msg2, sgx_dh_msg3_t* dh_msg3, uint32_t session_id); +sgx_status_t Enclave3_generate_response(sgx_enclave_id_t eid, uint32_t* retval, sgx_enclave_id_t src_enclave_id, secure_message_t* req_message, size_t req_message_size, size_t max_payload_size, secure_message_t* resp_message, size_t resp_message_size); +sgx_status_t Enclave3_end_session(sgx_enclave_id_t eid, uint32_t* retval, sgx_enclave_id_t src_enclave_id); + +uint32_t session_request_ocall(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id, sgx_dh_msg1_t* dh_msg1, uint32_t* session_id); +uint32_t exchange_report_ocall(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id, sgx_dh_msg2_t* dh_msg2, sgx_dh_msg3_t* dh_msg3, uint32_t session_id); +uint32_t send_request_ocall(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id, secure_message_t* req_message, size_t req_message_size, size_t max_payload_size, secure_message_t* resp_message, size_t resp_message_size); +uint32_t end_session_ocall(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/SampleCode/PowerTransition/.cproject b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/.cproject new file mode 100644 index 0000000000..77c05bf4f1 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/.cproject @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/SampleCode/PowerTransition/.project b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/.project new file mode 100644 index 0000000000..7f1ef0688c --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/.project @@ -0,0 +1,28 @@ + + + PowerTransition + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.eclipse.cdt.core.ccnature + com.intel.sgx.sgxnature + + diff --git a/sgx-jvm/linux-sgx/SampleCode/PowerTransition/App/App.cpp b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/App/App.cpp new file mode 100644 index 0000000000..6384116722 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/App/App.cpp @@ -0,0 +1,319 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +// App.cpp : Define the entry point for the console application. +// + +#include +#include +#include +#include +#include + +#include "Enclave_u.h" +#include "sgx_urts.h" +#include "sgx_tseal.h" + +#include "rwlock.h" +#include "ErrorSupport.h" + +#define ENCLAVE_NAME "libenclave.signed.so" +#define TOKEN_NAME "Enclave.token" + +#define THREAD_NUM 3 + +// Global data +sgx_enclave_id_t global_eid = 0; +sgx_launch_token_t token = {0}; +rwlock_t lock_eid; +struct sealed_buf_t sealed_buf; + +using namespace std; + +// Ocall function +void print(const char *str) +{ + cout<()(std::this_thread::get_id()); + sgx_status_t ret = SGX_SUCCESS; + int retval = 0; + sgx_enclave_id_t current_eid = 0; + + // Enter the enclave to increase and seal the secret data for 100 times. + for(unsigned int i = 0; i< 50000; i++) + { + for( ; ; ) + { + // If power transition occurs, all the data inside the enclave will be lost when the system resumes. + // Therefore, if there are some secret data which need to be backed up for recover, + // users can choose to seal the secret data inside the enclave and back up the sealed data. + + // Enter the enclave to increase the secret data and back up the sealed data + rdlock(&lock_eid); + current_eid = global_eid; + rdunlock(&lock_eid); + ret = increase_and_seal_data(current_eid, &retval, thread_id, &sealed_buf); + + if(ret == SGX_ERROR_ENCLAVE_LOST) + { + // SGX_ERROR_ENCLAVE_LOST indicates the power transition occurs before the system resumes. + // Lock here is to make sure there is only one thread to load and initialize the enclave at the same time + wtlock(&lock_eid); + // The loading and initialization operations happen in current thread only if there is no other thread reloads and initializes the enclave before + if(current_eid == global_eid) + { + cout <<"power transition occured in increase_and_seal_data()." << endl; + // Use the backup sealed data to reload and initialize the enclave. + if((ret = load_and_initialize_enclave(¤t_eid, &sealed_buf)) != SGX_SUCCESS) + { + ret_error_support(ret); + wtunlock(&lock_eid); + return false; + } + else + { + // Update the global_eid after initializing the enclave successfully + global_eid = current_eid; + } + } + else + { + // The enclave has been reloaded by another thread. + // Update the current EID and do increase_and_seal_data() again. + current_eid = global_eid; + } + wtunlock(&lock_eid); + } + else + { + // No power transition occurs + break; + } + } + if(ret != SGX_SUCCESS) + { + ret_error_support(ret); + return false; + } + else if(retval != 0) + { + return false; + } + } + return true; +} + + +void thread_func() +{ + if(increase_and_seal_data_in_enclave() != true) + { + abort(); + } +} + +bool set_global_data() +{ + // Initialize the read/write lock. + init_rwlock(&lock_eid); + + // Get the saved launch token. + // If error occures, zero the token. + ifstream ifs(TOKEN_NAME, std::ios::binary | std::ios::in); + if(!ifs.good()) + { + memset(token, 0, sizeof(sgx_launch_token_t)); + } + else + { + ifs.read(reinterpret_cast(&token), sizeof(sgx_launch_token_t)); + if(ifs.fail()) + { + memset(&token, 0, sizeof(sgx_launch_token_t)); + } + } + + // Allocate memory to save the sealed data. + uint32_t sealed_len = sizeof(sgx_sealed_data_t) + sizeof(uint32_t); + for(int i = 0; i < BUF_NUM; i++) + { + sealed_buf.sealed_buf_ptr[i] = (uint8_t *)malloc(sealed_len); + if(sealed_buf.sealed_buf_ptr[i] == NULL) + { + cout << "Out of memory" << endl; + return false; + } + memset(sealed_buf.sealed_buf_ptr[i], 0, sealed_len); + } + sealed_buf.index = 0; // index indicates which buffer contains current sealed data and which contains the backup sealed data + + return true; +} + +void release_source() +{ + for(int i = 0; i < BUF_NUM; i++) + { + if(sealed_buf.sealed_buf_ptr[i] != NULL) + { + free(sealed_buf.sealed_buf_ptr[i]); + sealed_buf.sealed_buf_ptr[i] = NULL; + } + } + fini_rwlock(&lock_eid); + return; +} + +int main(int argc, char* argv[]) +{ + (void)argc, (void)argv; + + + // Initialize the global data + if(!set_global_data()) + { + release_source(); + cout << "Enter a character before exit ..." << endl; + getchar(); + return -1; + } + + // Load and initialize the signed enclave + // sealed_buf == NULL indicates it is the first time to initialize the enclave. + sgx_status_t ret = load_and_initialize_enclave(&global_eid , NULL); + if(ret != SGX_SUCCESS) + { + ret_error_support(ret); + release_source(); + cout << "Enter a character before exit ..." << endl; + getchar(); + return -1; + } + + cout << "****************************************************************" << endl; + cout << "Demonstrating Power transition needs your cooperation." << endl + << "Please take the following actions:" << endl + << " 1. Enter a character;" << endl + << " 2. Manually put the OS into a sleep or hibernate state;" << endl + << " 3. Resume the OS from that state;" << endl + << "Then you will see the application continues." << endl; + cout << "****************************************************************" << endl; + cout << "Now enter a character ..."; + getchar(); + + // Create multiple threads to calculate the sum + thread trd[THREAD_NUM]; + for (int i = 0; i< THREAD_NUM; i++) + { + trd[i] = thread(thread_func); + } + for (int i = 0; i < THREAD_NUM; i++) + { + trd[i].join(); + } + + // Release resources + release_source(); + + // Destroy the enclave + sgx_destroy_enclave(global_eid); + + cout << "Enter a character before exit ..." << endl; + getchar(); + return 0; +} + diff --git a/sgx-jvm/linux-sgx/SampleCode/PowerTransition/App/ErrorSupport.cpp b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/App/ErrorSupport.cpp new file mode 100644 index 0000000000..9665fb6b31 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/App/ErrorSupport.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#include +#include "ErrorSupport.h" + + +typedef struct _sgx_errlist_t { + sgx_status_t err; + const char * msg; +} sgx_errlist_t; + +static sgx_errlist_t sgx_errlist[] = { + {SGX_ERROR_UNEXPECTED, "Unexpected error occurred."}, + {SGX_ERROR_INVALID_PARAMETER, "Invalid parameter."}, + {SGX_ERROR_OUT_OF_MEMORY, "Out of memory."}, + {SGX_ERROR_ENCLAVE_LOST, "Power transition occurred."}, + {SGX_ERROR_INVALID_ENCLAVE, "Invalid enclave image."}, + {SGX_ERROR_INVALID_ENCLAVE_ID, "Invalid enclave identification."}, + {SGX_ERROR_INVALID_SIGNATURE, "Invalid enclave signature."}, + {SGX_ERROR_OUT_OF_EPC, "Out of EPC memory."}, + {SGX_ERROR_NO_DEVICE, "Invalid SGX device."}, + {SGX_ERROR_MEMORY_MAP_CONFLICT, "Memory map conflicted."}, + {SGX_ERROR_INVALID_METADATA, "Invalid encalve metadata."}, + {SGX_ERROR_DEVICE_BUSY, "SGX device is busy."}, + {SGX_ERROR_INVALID_VERSION, "Enclave metadata version is invalid."}, + {SGX_ERROR_ENCLAVE_FILE_ACCESS, "Can't open enclave file."}, + + {SGX_ERROR_INVALID_FUNCTION, "Invalid function name."}, + {SGX_ERROR_OUT_OF_TCS, "Out of TCS."}, + {SGX_ERROR_ENCLAVE_CRASHED, "The enclave is crashed."}, + + {SGX_ERROR_MAC_MISMATCH, "Report varification error occurred."}, + {SGX_ERROR_INVALID_ATTRIBUTE, "The enclave is not authorized."}, + {SGX_ERROR_INVALID_CPUSVN, "Invalid CPUSVN."}, + {SGX_ERROR_INVALID_ISVSVN, "Invalid ISVSVN."}, + {SGX_ERROR_INVALID_KEYNAME, "The requested key name is invalid."}, + + {SGX_ERROR_SERVICE_UNAVAILABLE, "AESM service is not responsive."}, + {SGX_ERROR_SERVICE_TIMEOUT, "Request to AESM is time out."}, + {SGX_ERROR_SERVICE_INVALID_PRIVILEGE, "Error occurred while getting launch token."}, +}; + + +void ret_error_support(sgx_status_t ret) +{ + size_t idx = 0; + size_t ttl = sizeof sgx_errlist/sizeof sgx_errlist[0]; + + for (idx = 0; idx < ttl; idx++) { + if(ret == sgx_errlist[idx].err) { + std::cout << "Error: "<< sgx_errlist[idx].msg << std::endl; + break; + } + } + if (idx == ttl) + std::cout << "Error: Unexpected error occurred." < +void wtlock(prwlock_t lock) +{ + int ret = pthread_rwlock_wrlock(lock); + if(0 != ret) + abort(); +} + +void wtunlock(prwlock_t lock) +{ + int ret = pthread_rwlock_unlock(lock); + if(0 != ret) + abort(); +} + + +void rdlock(prwlock_t lock) +{ + int ret = pthread_rwlock_rdlock(lock); + if(0 != ret) + abort(); +} + +void rdunlock(prwlock_t lock) +{ + int ret = pthread_rwlock_unlock(lock); + if(0 != ret) + abort(); +} + +void init_rwlock(prwlock_t lock) +{ + //use the default attribute. + int ret = pthread_rwlock_init(lock, NULL); + if(0 != ret) + abort(); +} + +void fini_rwlock(prwlock_t lock) +{ + int ret = pthread_rwlock_destroy(lock); + if(0 != ret) + abort(); +} + + diff --git a/sgx-jvm/linux-sgx/SampleCode/PowerTransition/App/rwlock.h b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/App/rwlock.h new file mode 100644 index 0000000000..19161f2845 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/App/rwlock.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + + +#ifndef _RWLOCK_H +#define _RWLOCK_H + +#include +typedef pthread_rwlock_t rwlock_t; +typedef pthread_rwlock_t* prwlock_t; + +#ifdef __cplusplus +extern "C" { +#endif + + void wtlock(prwlock_t lock); + void rdlock(prwlock_t lock); + void rdunlock(prwlock_t lock); + void wtunlock(prwlock_t lock); + void init_rwlock(prwlock_t lock); + void fini_rwlock(prwlock_t lock); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Common/types.h b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Common/types.h new file mode 100644 index 0000000000..a4dc4eaa94 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Common/types.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#ifndef _TYPES_H_ +#define _TYPES_H_ + +#define BUF_NUM 2 + +#define MOD2(x) ((x) % BUF_NUM) + +struct sealed_buf_t +{ + unsigned int index; + void * sealed_buf_ptr[BUF_NUM]; +}; + + +#endif diff --git a/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave.config.xml b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave.config.xml new file mode 100644 index 0000000000..23f5748464 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave.config.xml @@ -0,0 +1,11 @@ + + 0 + 0 + 0x40000 + 0x100000 + 3 + 1 + 0 + 0 + 0xFFFFFFFF + diff --git a/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave.cpp b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave.cpp new file mode 100644 index 0000000000..3918abf4ab --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave.cpp @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#include "string.h" +#include "stdlib.h" +#include "stdio.h" +#include "sgx_trts.h" +#include "sgx_thread.h" +#include "sgx_tseal.h" + +#include "Enclave_t.h" + +uint32_t g_secret; +sgx_thread_mutex_t g_mutex = SGX_THREAD_MUTEX_INITIALIZER; + +static inline void free_allocated_memory(void *pointer) +{ + if(pointer != NULL) + { + free(pointer); + pointer = NULL; + } +} + + +int initialize_enclave(struct sealed_buf_t *sealed_buf) +{ + // sealed_buf == NULL indicates it is the first time to initialize the enclave + if(sealed_buf == NULL) + { + sgx_thread_mutex_lock(&g_mutex); + g_secret = 0; + sgx_thread_mutex_unlock(&g_mutex); + return 0; + } + + // It is not the first time to initialize the enclave + // Reinitialize the enclave to recover the secret data from the input backup sealed data. + + uint32_t len = sizeof(sgx_sealed_data_t) + sizeof(uint32_t); + //Check the sealed_buf length and check the outside pointers deeply + if(sealed_buf->sealed_buf_ptr[MOD2(sealed_buf->index)] == NULL || + sealed_buf->sealed_buf_ptr[MOD2(sealed_buf->index + 1)] == NULL || + !sgx_is_outside_enclave(sealed_buf->sealed_buf_ptr[MOD2(sealed_buf->index)], len) || + !sgx_is_outside_enclave(sealed_buf->sealed_buf_ptr[MOD2(sealed_buf->index + 1)], len)) + { + print("Incorrect input parameter(s).\n"); + return -1; + } + + // Retrieve the secret from current backup sealed data + uint32_t unsealed_data = 0; + uint32_t unsealed_data_length = sizeof(g_secret); + uint8_t *plain_text = NULL; + uint32_t plain_text_length = 0; + uint8_t *temp_sealed_buf = (uint8_t *)malloc(len); + if(temp_sealed_buf == NULL) + { + print("Out of memory.\n"); + return -1; + } + + sgx_thread_mutex_lock(&g_mutex); + memcpy(temp_sealed_buf, sealed_buf->sealed_buf_ptr[MOD2(sealed_buf->index)], len); + + // Unseal current sealed buf + sgx_status_t ret = sgx_unseal_data((sgx_sealed_data_t *)temp_sealed_buf, plain_text, &plain_text_length, (uint8_t *)&unsealed_data, &unsealed_data_length); + if(ret == SGX_SUCCESS) + { + g_secret = unsealed_data; + sgx_thread_mutex_unlock(&g_mutex); + free_allocated_memory(temp_sealed_buf); + return 0; + } + else + { + sgx_thread_mutex_unlock(&g_mutex); + print("Failed to reinitialize the enclave.\n"); + free_allocated_memory(temp_sealed_buf); + return -1; + } +} + +int increase_and_seal_data(size_t tid, struct sealed_buf_t* sealed_buf) +{ + uint32_t sealed_len = sizeof(sgx_sealed_data_t) + sizeof(g_secret); + // Check the sealed_buf length and check the outside pointers deeply + if(sealed_buf->sealed_buf_ptr[MOD2(sealed_buf->index)] == NULL || + sealed_buf->sealed_buf_ptr[MOD2(sealed_buf->index + 1)] == NULL || + !sgx_is_outside_enclave(sealed_buf->sealed_buf_ptr[MOD2(sealed_buf->index)], sealed_len) || + !sgx_is_outside_enclave(sealed_buf->sealed_buf_ptr[MOD2(sealed_buf->index + 1)], sealed_len)) + { + print("Incorrect input parameter(s).\n"); + return -1; + } + + char string_buf[BUFSIZ] = {'\0'}; + uint32_t temp_secret = 0; + uint8_t *plain_text = NULL; + uint32_t plain_text_length = 0; + uint8_t *temp_sealed_buf = (uint8_t *)malloc(sealed_len); + if(temp_sealed_buf == NULL) + { + print("Out of memory.\n"); + return -1; + } + memset(temp_sealed_buf, 0, sealed_len); + + sgx_thread_mutex_lock(&g_mutex); + + // Increase and seal the secret data + temp_secret = ++g_secret; + sgx_status_t ret = sgx_seal_data(plain_text_length, plain_text, sizeof(g_secret), (uint8_t *)&g_secret, sealed_len, (sgx_sealed_data_t *)temp_sealed_buf); + if(ret != SGX_SUCCESS) + { + sgx_thread_mutex_unlock(&g_mutex); + print("Failed to seal data\n"); + free_allocated_memory(temp_sealed_buf); + return -1; + } + // Backup the sealed data to outside buffer + memcpy(sealed_buf->sealed_buf_ptr[MOD2(sealed_buf->index + 1)], temp_sealed_buf, sealed_len); + sealed_buf->index++; + + sgx_thread_mutex_unlock(&g_mutex); + free_allocated_memory(temp_sealed_buf); + + // Ocall to print the unsealed secret data outside. + // In theory, the secret data(s) SHOULD NOT be transferred outside the enclave as clear text(s). + // So please DO NOT print any secret outside. Here printing the secret data to outside is only for demo. + snprintf(string_buf, BUFSIZ, "Thread %#x>: %u\n", (unsigned int)tid, (unsigned int)temp_secret); + print(string_buf); + return 0; +} diff --git a/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave.edl b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave.edl new file mode 100644 index 0000000000..54aa25a740 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave.edl @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +enclave { + + // Import the Ocalls for trusted mutex + from "sgx_tstdc.edl" import *; + include "types.h" + + trusted { + public int initialize_enclave([in]struct sealed_buf_t* sealed_buf); + public int increase_and_seal_data(size_t tid, [in, out]struct sealed_buf_t* sealed_buf); + }; + + untrusted { + void print([in, string] const char *string); + }; +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave.lds b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave.lds new file mode 100644 index 0000000000..b1c6b6fd7e --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave.lds @@ -0,0 +1,9 @@ +libenclave.so +{ + global: + g_global_data_sim; + g_global_data; + enclave_entry; + local: + *; +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave_private.pem b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave_private.pem new file mode 100644 index 0000000000..529d07be35 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Enclave/Enclave_private.pem @@ -0,0 +1,39 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIG4gIBAAKCAYEAroOogvsj/fZDZY8XFdkl6dJmky0lRvnWMmpeH41Bla6U1qLZ +AmZuyIF+mQC/cgojIsrBMzBxb1kKqzATF4+XwPwgKz7fmiddmHyYz2WDJfAjIveJ +ZjdMjM4+EytGlkkJ52T8V8ds0/L2qKexJ+NBLxkeQLfV8n1mIk7zX7jguwbCG1Pr +nEMdJ3Sew20vnje+RsngAzdPChoJpVsWi/K7cettX/tbnre1DL02GXc5qJoQYk7b +3zkmhz31TgFrd9VVtmUGyFXAysuSAb3EN+5VnHGr0xKkeg8utErea2FNtNIgua8H +ONfm9Eiyaav1SVKzPHlyqLtcdxH3I8Wg7yqMsaprZ1n5A1v/levxnL8+It02KseD +5HqV4rf/cImSlCt3lpRg8U5E1pyFQ2IVEC/XTDMiI3c+AR+w2jSRB3Bwn9zJtFlW +KHG3m1xGI4ck+Lci1JvWWLXQagQSPtZTsubxTQNx1gsgZhgv1JHVZMdbVlAbbRMC +1nSuJNl7KPAS/VfzAgEDAoIBgHRXxaynbVP5gkO0ug6Qw/E27wzIw4SmjsxG6Wpe +K7kfDeRskKxESdsA/xCrKkwGwhcx1iIgS5+Qscd1Yg+1D9X9asd/P7waPmWoZd+Z +AhlKwhdPsO7PiF3e1AzHhGQwsUTt/Y/aSI1MpHBvy2/s1h9mFCslOUxTmWw0oj/Q +ldIEgWeNR72CE2+jFIJIyml6ftnb6qzPiga8Bm48ubKh0kvySOqnkmnPzgh+JBD6 +JnBmtZbfPT97bwTT+N6rnPqOOApvfHPf15kWI8yDbprG1l4OCUaIUH1AszxLd826 +5IPM+8gINLRDP1MA6azECPjTyHXhtnSIBZCyWSVkc05vYmNXYUNiXWMajcxW9M02 +wKzFELO8NCEAkaTPxwo4SCyIjUxiK1LbQ9h8PSy4c1+gGP4LAMR8xqP4QKg6zdu9 +osUGG/xRe/uufgTBFkcjqBHtK5L5VI0jeNIUAgW/6iNbYXjBMJ0GfauLs+g1VsOm +WfdgXzsb9DYdMa0OXXHypmV4GwKBwQDUwQj8RKJ6c8cT4vcWCoJvJF00+RFL+P3i +Gx2DLERxRrDa8AVGfqaCjsR+3vLgG8V/py+z+dxZYSqeB80Qeo6PDITcRKoeAYh9 +xlT3LJOS+k1cJcEmlbbO2IjLkTmzSwa80fWexKu8/Xv6vv15gpqYl1ngYoqJM3pd +vzmTIOi7MKSZ0WmEQavrZj8zK4endE3v0eAEeQ55j1GImbypSf7Idh7wOXtjZ7WD +Dg6yWDrri+AP/L3gClMj8wsAxMV4ZR8CgcEA0fzDHkFa6raVOxWnObmRoDhAtE0a +cjUj976NM5yyfdf2MrKy4/RhdTiPZ6b08/lBC/+xRfV3xKVGzacm6QjqjZrUpgHC +0LKiZaMtccCJjLtPwQd0jGQEnKfMFaPsnhOc5y8qVkCzVOSthY5qhz0XNotHHFmJ +gffVgB0iqrMTvSL7IA2yqqpOqNRlhaYhNl8TiFP3gIeMtVa9rZy31JPgT2uJ+kfo +gV7sdTPEjPWZd7OshGxWpT6QfVDj/T9T7L6tAoHBAI3WBf2DFvxNL2KXT2QHAZ9t +k3imC4f7U+wSE6zILaDZyzygA4RUbwG0gv8/TJVn2P/Eynf76DuWHGlaiLWnCbSz +Az2DHBQBBaku409zDQym3j1ugMRjzzSQWzJg0SIyBH3hTmnYcn3+Uqcp/lEBvGW6 +O+rsXFt3pukqJmIV8HzLGGaLm62BHUeZf3dyWm+i3p/hQAL7Xvu04QW70xuGqdr5 +afV7p5eaeQIJXyGQJ0eylV/90+qxjMKiB1XYg6WYvwKBwQCL/ddpgOdHJGN8uRom +e7Zq0Csi3hGheMKlKbN3vcxT5U7MdyHtTZZOJbTvxKNNUNYH/8uD+PqDGNneb29G +BfGzvI3EASyLIcGZF3OhKwZd0jUrWk2y7Vhob91jwp2+t73vdMbkKyI4mHOuXvGv +fg95si9oO7EBT+Oqvhccd2J+F1IVXncccYnF4u5ZGWt5lLewN/pVr7MjjykeaHqN +t+rfnQam2psA6fL4zS2zTmZPzR2tnY8Y1GBTi0Ko1OKd1HMCgcAb5cB/7/AQlhP9 +yQa04PLH9ygQkKKptZp7dy5WcWRx0K/hAHRoi2aw1wZqfm7VBNu2SLcs90kCCCxp +6C5sfJi6b8NpNbIPC+sc9wsFr7pGo9SFzQ78UlcWYK2Gu2FxlMjonhka5hvo4zvg +WxlpXKEkaFt3gLd92m/dMqBrHfafH7VwOJY2zT3WIpjwuk0ZzmRg5p0pG/svVQEH +NZmwRwlopysbR69B/n1nefJ84UO50fLh5s5Zr3gBRwbWNZyzhXk= +-----END RSA PRIVATE KEY----- diff --git a/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Makefile b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Makefile new file mode 100644 index 0000000000..6bccdb7673 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/Makefile @@ -0,0 +1,239 @@ +# +# Copyright (C) 2011-2016 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# + +####### SGX SDK Settings ######## + +SGX_SDK ?= /opt/intel/sgxsdk +SGX_MODE ?= HW +SGX_ARCH ?= x64 +SGX_DEBUG ?= 1 + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +######## App Settings ######## + +ifneq ($(SGX_MODE), HW) + Urts_Library_Name := sgx_urts_sim +else + Urts_Library_Name := sgx_urts +endif + +App_Cpp_Files := $(wildcard App/*.cpp) +App_Include_Paths := -I$(SGX_SDK)/include -I./Common + +App_Compile_CFlags := -fPIC -Wno-attributes $(App_Include_Paths) +# Three configuration modes - Debug, prerelease, release +# Debug - Macro DEBUG enabled. +# Prerelease - Macro NDEBUG and EDEBUG enabled. +# Release - Macro NDEBUG enabled. +ifeq ($(SGX_DEBUG), 1) + App_Compile_CFlags += -DDEBUG -UNDEBUG -UEDEBUG +else ifeq ($(SGX_PRERELEASE), 1) + App_Compile_CFlags += -DNDEBUG -DEDEBUG -UDEBUG +else + App_Compile_CFlags += -DNDEBUG -UEDEBUG -UDEBUG +endif + +App_Compile_CXXFlags := -std=c++0x $(App_Compile_CFlags) +App_Link_Flags := -L$(SGX_LIBRARY_PATH) -l$(Urts_Library_Name) -lpthread + +ifneq ($(SGX_MODE), HW) + App_Link_Flags += -lsgx_uae_service_sim +else + App_Link_Flags += -lsgx_uae_service +endif + +Gen_Untrusted_Source := App/Enclave_u.c +Gen_Untrusted_Object := App/Enclave_u.o + +App_Objects := $(Gen_Untrusted_Object) $(App_Cpp_Files:.cpp=.o) + +App_Name := app + + +######## Enclave Settings ######## + +ifneq ($(SGX_MODE), HW) + Trts_Library_Name := sgx_trts_sim + Service_Library_Name := sgx_tservice_sim +else + Trts_Library_Name := sgx_trts + Service_Library_Name := sgx_tservice +endif +Crypto_Library_Name := sgx_tcrypto + +Enclave_Cpp_Files := $(wildcard Enclave/*.cpp) + +Enclave_Include_Paths := -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport -I./Common + +Enclave_Compile_CFlags := -nostdinc -ffreestanding -fvisibility=hidden -fpie \ + $(Enclave_Include_Paths) +Enclave_Compile_CXXFlags := -nostdinc++ -std=c++03 $(Enclave_Compile_CFlags) + +# To generate a proper enclave, it is recommended to follow below guideline to link the trusted libraries: +# 1. Link sgx_trts with the `--whole-archive' and `--no-whole-archive' options, +# so that the whole content of trts is included in the enclave. +# 2. For other libraries, you just need to pull the required symbols. +# Use `--start-group' and `--end-group' to link these libraries. +# Do NOT move the libraries linked with `--start-group' and `--end-group' within `--whole-archive' and `--no-whole-archive' options. +# Otherwise, you may get some undesirable errors. +Enclave_Link_Flags := -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \ + -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive \ + -Wl,--start-group -lsgx_tstdc -lsgx_tstdcxx -l$(Crypto_Library_Name) -l$(Service_Library_Name) -Wl,--end-group \ + -Wl,--version-script=Enclave/Enclave.lds -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \ + -Wl,-pie,-eenclave_entry -Wl,--export-dynamic -Wl,--defsym,__ImageBase=0 + +Enclave_Cpp_Objects := $(Enclave_Cpp_Files:.cpp=.o) +Gen_Trusted_Source := Enclave/Enclave_t.c +Gen_Trusted_Object := Enclave/Enclave_t.o + +Enclave_Objects := $(Gen_Trusted_Object) $(Enclave_Cpp_Files:.cpp=.o) + +Enclave_Name := libenclave.so +Signed_Enclave_Name := libenclave.signed.so +Enclave_Config_File := Enclave/Enclave.config.xml + +ifeq ($(SGX_MODE), HW) +ifeq ($(SGX_DEBUG), 1) + Build_Mode = HW_DEBUG +else ifeq ($(SGX_PRERELEASE), 1) + Build_Mode = HW_PRERELEASE +else + Build_Mode = HW_RELEASE +endif +else +ifeq ($(SGX_DEBUG), 1) + Build_Mode = SIM_DEBUG +else ifeq ($(SGX_PRERELEASE), 1) + Build_Mode = SIM_PRERELEASE +else + Build_Mode = SIM_RELEASE +endif +endif + +ifeq ($(Build_Mode), HW_RELEASE) +all: $(App_Name) $(Enclave_Name) + @echo "The project has been built in release hardware mode." + @echo "Please sign the $(Enclave_Name) first with your signing key before you run the $(App_Name) to launch and access the enclave." + @echo "To sign the enclave use the command:" + @echo " $(SGX_ENCLAVE_SIGNER) sign -key -enclave $(Enclave_Name) -out <$(Signed_Enclave_Name)> -config $(Enclave_Config_File)" + @echo "You can also sign the enclave using an external signing tool." + @echo "To build the project in simulation mode set SGX_MODE=SIM. To build the project in prerelease mode set SGX_PRERELEASE=1 and SGX_MODE=HW." +else +all: $(App_Name) $(Signed_Enclave_Name) +ifeq ($(Build_Mode), HW_DEBUG) + @echo "The project has been built in debug hardware mode." +else ifeq ($(Build_Mode), SIM_DEBUG) + @echo "The project has been built in debug simulation mode." +else ifeq ($(Build_Mode), HW_PRERELEASE) + @echo "The project has been built in pre-release hardware mode." +else ifeq ($(Build_Mode), SIM_PRERELEASE) + @echo "The project has been built in pre-release simulation mode." +else + @echo "The project has been built in release simulation mode." +endif +endif + +######## App Objects ######## + +$(Gen_Untrusted_Source): $(SGX_EDGER8R) Enclave/Enclave.edl + @cd App && $(SGX_EDGER8R) --untrusted ../Enclave/Enclave.edl --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +$(Gen_Untrusted_Object): $(Gen_Untrusted_Source) + @$(CC) $(SGX_COMMON_CFLAGS) $(App_Compile_CFlags) -c $< -o $@ + @echo "CC <= $<" + +App/%.o: App/%.cpp + @$(CXX) $(SGX_COMMON_CFLAGS) $(App_Compile_CXXFlags) -c $< -o $@ + @echo "CXX <= $<" + +$(App_Name): $(App_Objects) + @$(CXX) $(SGX_COMMON_CFLAGS) $^ -o $@ $(App_Link_Flags) + @echo "LINK => $@" + + +######## Enclave Objects ######## + +$(Gen_Trusted_Source): $(SGX_EDGER8R) Enclave/Enclave.edl + @cd Enclave && $(SGX_EDGER8R) --trusted Enclave.edl --search-path $(SGX_SDK)/include + @echo "GEN => $@" +$(Gen_Trusted_Object): $(Gen_Trusted_Source) + @$(CC) $(SGX_COMMON_CFLAGS) $(Enclave_Compile_CFlags) -c $< -o $@ + @echo "CC <= $<" + +Enclave/%.o: Enclave/%.cpp + @$(CXX) $(SGX_COMMON_CFLAGS) $(Enclave_Compile_CXXFlags) -c $< -o $@ + @echo "CXX <= $<" + +$(Enclave_Name): $(Enclave_Objects) + @$(CXX) $(SGX_COMMON_CFLAGS) $(Enclave_Objects) -o $@ $(Enclave_Link_Flags) + @echo "LINK => $@" + +$(Signed_Enclave_Name): $(Enclave_Name) + @$(SGX_ENCLAVE_SIGNER) sign -key Enclave/Enclave_private.pem -enclave $(Enclave_Name) -out $@ -config $(Enclave_Config_File) + @echo "SIGN => $@" + + +######### clean up ######## +.PHONY: clean + + +clean: + @rm -f $(App_Name) $(App_Objects) $(Enclave_Name) $(Enclave_Objects) App/Enclave_u.* Enclave/Enclave_t.* $(Signed_Enclave_Name) diff --git a/sgx-jvm/linux-sgx/SampleCode/PowerTransition/README.txt b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/README.txt new file mode 100644 index 0000000000..23c298b021 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/PowerTransition/README.txt @@ -0,0 +1,26 @@ +-------------------------- +Purpose of PowerTransition +-------------------------- +The project demonstrates one method about power transition handling for Intel(R) +Software Guard Extensions projects development. + +------------------------------------ +How to Build/Execute the Sample Code +------------------------------------ +1. Install Intel(R) SGX SDK for Linux* OS +2. Build the project with the prepared Makefile: + a. Hardware Mode, Debug build: + $ make + b. Hardware Mode, Pre-release build: + $ make SGX_PRERELEASE=1 SGX_DEBUG=0 + c. Hardware Mode, Release build: + $ make SGX_DEBUG=0 + d. Simulation Mode, Debug build: + $ make SGX_MODE=SIM + e. Simulation Mode, Pre-release build: + $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0 + f. Simulation Mode, Release build: + $ make SGX_MODE=SIM SGX_DEBUG=0 +3. Execute the binary directly: + $ ./app +4. Remember to "make clean" before switching build mode diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/.cproject b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/.cproject new file mode 100644 index 0000000000..efe1117e34 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/.cproject @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/.project b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/.project new file mode 100644 index 0000000000..3cc71f6a6a --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/.project @@ -0,0 +1,28 @@ + + + RemoteAttestation + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.eclipse.cdt.core.ccnature + com.intel.sgx.sgxnature + + diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/Makefile b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/Makefile new file mode 100644 index 0000000000..1f6e5af6f7 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/Makefile @@ -0,0 +1,263 @@ +# +# Copyright (C) 2011-2016 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# + +######## SGX SDK Settings ######## + +SGX_SDK ?= /opt/intel/sgxsdk +SGX_MODE ?= HW +SGX_ARCH ?= x64 +SGX_DEBUG ?= 1 + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +ifeq ($(SUPPLIED_KEY_DERIVATION), 1) + SGX_COMMON_CFLAGS += -DSUPPLIED_KEY_DERIVATION +endif +######## App Settings ######## + +ifneq ($(SGX_MODE), HW) + Urts_Library_Name := sgx_urts_sim +else + Urts_Library_Name := sgx_urts +endif + +App_Cpp_Files := isv_app/isv_app.cpp +App_Include_Paths := -Iservice_provider -I$(SGX_SDK)/include + +App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) + +# Three configuration modes - Debug, prerelease, release +# Debug - Macro DEBUG enabled. +# Prerelease - Macro NDEBUG and EDEBUG enabled. +# Release - Macro NDEBUG enabled. +ifeq ($(SGX_DEBUG), 1) + App_C_Flags += -DDEBUG -UNDEBUG -UEDEBUG +else ifeq ($(SGX_PRERELEASE), 1) + App_C_Flags += -DNDEBUG -DEDEBUG -UDEBUG +else + App_C_Flags += -DNDEBUG -UEDEBUG -UDEBUG +endif + +App_Cpp_Flags := $(App_C_Flags) -std=c++11 +App_Link_Flags := $(SGX_COMMON_CFLAGS) -L$(SGX_LIBRARY_PATH) -l$(Urts_Library_Name) -L. -lsgx_ukey_exchange -lpthread -lservice_provider -Wl,-rpath=$(CURDIR)/sample_libcrypto -Wl,-rpath=$(CURDIR) + +ifneq ($(SGX_MODE), HW) + App_Link_Flags += -lsgx_uae_service_sim +else + App_Link_Flags += -lsgx_uae_service +endif + +App_Cpp_Objects := $(App_Cpp_Files:.cpp=.o) + +App_Name := app + +######## Service Provider Settings ######## + +ServiceProvider_Cpp_Files := service_provider/ecp.cpp service_provider/network_ra.cpp service_provider/service_provider.cpp service_provider/ias_ra.cpp +ServiceProvider_Include_Paths := -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport -Isample_libcrypto + +ServiceProvider_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes -I$(SGX_SDK)/include -Isample_libcrypto +ServiceProvider_Cpp_Flags := $(ServiceProvider_C_Flags) -std=c++11 +ServiceProvider_Link_Flags := -shared $(SGX_COMMON_CFLAGS) -L$(SGX_LIBRARY_PATH) -lsample_libcrypto -Lsample_libcrypto + +ServiceProvider_Cpp_Objects := $(ServiceProvider_Cpp_Files:.cpp=.o) + +######## Enclave Settings ######## + +ifneq ($(SGX_MODE), HW) + Trts_Library_Name := sgx_trts_sim + Service_Library_Name := sgx_tservice_sim +else + Trts_Library_Name := sgx_trts + Service_Library_Name := sgx_tservice +endif +Crypto_Library_Name := sgx_tcrypto + +Enclave_Cpp_Files := isv_enclave/isv_enclave.cpp +Enclave_Include_Paths := -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport + +Enclave_C_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $(Enclave_Include_Paths) +Enclave_Cpp_Flags := $(Enclave_C_Flags) -std=c++03 -nostdinc++ + +# To generate a proper enclave, it is recommended to follow below guideline to link the trusted libraries: +# 1. Link sgx_trts with the `--whole-archive' and `--no-whole-archive' options, +# so that the whole content of trts is included in the enclave. +# 2. For other libraries, you just need to pull the required symbols. +# Use `--start-group' and `--end-group' to link these libraries. +# Do NOT move the libraries linked with `--start-group' and `--end-group' within `--whole-archive' and `--no-whole-archive' options. +# Otherwise, you may get some undesirable errors. +Enclave_Link_Flags := $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \ + -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive \ + -Wl,--start-group -lsgx_tstdc -lsgx_tstdcxx -lsgx_tkey_exchange -l$(Crypto_Library_Name) -l$(Service_Library_Name) -Wl,--end-group \ + -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \ + -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \ + -Wl,--defsym,__ImageBase=0 \ + -Wl,--version-script=isv_enclave/isv_enclave.lds + +Enclave_Cpp_Objects := $(Enclave_Cpp_Files:.cpp=.o) + +Enclave_Name := isv_enclave.so +Signed_Enclave_Name := isv_enclave.signed.so +Enclave_Config_File := isv_enclave/isv_enclave.config.xml + +ifeq ($(SGX_MODE), HW) +ifeq ($(SGX_DEBUG), 1) + Build_Mode = HW_DEBUG +else ifeq ($(SGX_PRERELEASE), 1) + Build_Mode = HW_PRERELEASE +else + Build_Mode = HW_RELEASE +endif +else +ifeq ($(SGX_DEBUG), 1) + Build_Mode = SIM_DEBUG +else ifeq ($(SGX_PRERELEASE), 1) + Build_Mode = SIM_PRERELEASE +else + Build_Mode = SIM_RELEASE +endif +endif + + +.PHONY: all run + +ifeq ($(Build_Mode), HW_RELEASE) +all: libservice_provider.so $(App_Name) $(Enclave_Name) + @echo "The project has been built in release hardware mode." + @echo "Please sign the $(Enclave_Name) first with your signing key before you run the $(App_Name) to launch and access the enclave." + @echo "To sign the enclave use the command:" + @echo " $(SGX_ENCLAVE_SIGNER) sign -key -enclave $(Enclave_Name) -out <$(Signed_Enclave_Name)> -config $(Enclave_Config_File)" + @echo "You can also sign the enclave using an external signing tool." + @echo "To build the project in simulation mode set SGX_MODE=SIM. To build the project in prerelease mode set SGX_PRERELEASE=1 and SGX_MODE=HW." +else +all: libservice_provider.so $(App_Name) $(Signed_Enclave_Name) +ifeq ($(Build_Mode), HW_DEBUG) + @echo "The project has been built in debug hardware mode." +else ifeq ($(Build_Mode), SIM_DEBUG) + @echo "The project has been built in debug simulation mode." +else ifeq ($(Build_Mode), HW_PRERELEASE) + @echo "The project has been built in pre-release hardware mode." +else ifeq ($(Build_Mode), SIM_PRERELEASE) + @echo "The project has been built in pre-release simulation mode." +else + @echo "The project has been built in release simulation mode." +endif +endif + +run: all +ifneq ($(Build_Mode), HW_RELEASE) + @$(CURDIR)/$(App_Name) + @echo "RUN => $(App_Name) [$(SGX_MODE)|$(SGX_ARCH), OK]" +endif + +######## App Objects ######## + +isv_app/isv_enclave_u.c: $(SGX_EDGER8R) isv_enclave/isv_enclave.edl + @cd isv_app && $(SGX_EDGER8R) --untrusted ../isv_enclave/isv_enclave.edl --search-path ../isv_enclave --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +isv_app/isv_enclave_u.o: isv_app/isv_enclave_u.c + @$(CC) $(App_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +isv_app/%.o: isv_app/%.cpp + @$(CXX) $(App_Cpp_Flags) -c $< -o $@ + @echo "CXX <= $<" + +$(App_Name): isv_app/isv_enclave_u.o $(App_Cpp_Objects) + @$(CXX) $^ -o $@ $(App_Link_Flags) + @echo "LINK => $@" + +######## Service Provider Objects ######## + + +service_provider/%.o: service_provider/%.cpp + @$(CXX) $(ServiceProvider_Cpp_Flags) -c $< -o $@ + @echo "CXX <= $<" + +libservice_provider.so: $(ServiceProvider_Cpp_Objects) + @$(CXX) $^ -o $@ $(ServiceProvider_Link_Flags) + @echo "LINK => $@" + +######## Enclave Objects ######## + +isv_enclave/isv_enclave_t.c: $(SGX_EDGER8R) isv_enclave/isv_enclave.edl + @cd isv_enclave && $(SGX_EDGER8R) --trusted ../isv_enclave/isv_enclave.edl --search-path ../isv_enclave --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +isv_enclave/isv_enclave_t.o: isv_enclave/isv_enclave_t.c + @$(CC) $(Enclave_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +isv_enclave/%.o: isv_enclave/%.cpp + @$(CXX) $(Enclave_Cpp_Flags) -c $< -o $@ + @echo "CXX <= $<" + +$(Enclave_Name): isv_enclave/isv_enclave_t.o $(Enclave_Cpp_Objects) + @$(CXX) $^ -o $@ $(Enclave_Link_Flags) + @echo "LINK => $@" + +$(Signed_Enclave_Name): $(Enclave_Name) + @$(SGX_ENCLAVE_SIGNER) sign -key isv_enclave/isv_enclave_private.pem -enclave $(Enclave_Name) -out $@ -config $(Enclave_Config_File) + @echo "SIGN => $@" + +.PHONY: clean + +clean: + @rm -f $(App_Name) $(Enclave_Name) $(Signed_Enclave_Name) $(App_Cpp_Objects) isv_app/isv_enclave_u.* $(Enclave_Cpp_Objects) isv_enclave/isv_enclave_t.* libservice_provider.* $(ServiceProvider_Cpp_Objects) diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/README.txt b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/README.txt new file mode 100644 index 0000000000..2b78193368 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/README.txt @@ -0,0 +1,27 @@ +---------------------------- +Purpose of RemoteAttestation +---------------------------- +The project demonstrates: +- How an application enclave can attest to a remote party +- How an application enclave and the remote party can establish a secure session + +------------------------------------ +How to Build/Execute the Sample Code +------------------------------------ +1. Install Intel(R) SGX SDK for Linux* OS +2. Build the project with the prepared Makefile: + a. Hardware Mode, Debug build: + $ make + b. Hardware Mode, Pre-release build: + $ make SGX_PRERELEASE=1 SGX_DEBUG=0 + c. Hardware Mode, Release build: + $ make SGX_DEBUG=0 + d. Simulation Mode, Debug build: + $ make SGX_MODE=SIM + e. Simulation Mode, Pre-release build: + $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0 + f. Simulation Mode, Release build: + $ make SGX_MODE=SIM SGX_DEBUG=0 +3. Execute the binary directly: + $ ./app +4. Remember to "make clean" before switching build mode diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/isv_app/isv_app.cpp b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/isv_app/isv_app.cpp new file mode 100644 index 0000000000..0fb3590acb --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/isv_app/isv_app.cpp @@ -0,0 +1,716 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// This sample is confined to the communication between a SGX client platform +// and an ISV Application Server. + + + +#include +#include +#include +// Needed for definition of remote attestation messages. +#include "remote_attestation_result.h" + +#include "isv_enclave_u.h" + +// Needed to call untrusted key exchange library APIs, i.e. sgx_ra_proc_msg2. +#include "sgx_ukey_exchange.h" + +// Needed to get service provider's information, in your real project, you will +// need to talk to real server. +#include "network_ra.h" + +// Needed to create enclave and do ecall. +#include "sgx_urts.h" + +// Needed to query extended epid group id. +#include "sgx_uae_service.h" + +#include "service_provider.h" + +#ifndef SAFE_FREE +#define SAFE_FREE(ptr) {if (NULL != (ptr)) {free(ptr); (ptr) = NULL;}} +#endif + +// In addition to generating and sending messages, this application +// can use pre-generated messages to verify the generation of +// messages and the information flow. +#include "sample_messages.h" + + +#define ENCLAVE_PATH "isv_enclave.signed.so" + +uint8_t* msg1_samples[] = { msg1_sample1, msg1_sample2 }; +uint8_t* msg2_samples[] = { msg2_sample1, msg2_sample2 }; +uint8_t* msg3_samples[MSG3_BODY_SIZE] = { msg3_sample1, msg3_sample2 }; +uint8_t* attestation_msg_samples[] = + { attestation_msg_sample1, attestation_msg_sample2}; + +// Some utility functions to output some of the data structures passed between +// the ISV app and the remote attestation service provider. +void PRINT_BYTE_ARRAY( + FILE *file, void *mem, uint32_t len) +{ + if(!mem || !len) + { + fprintf(file, "\n( null )\n"); + return; + } + uint8_t *array = (uint8_t *)mem; + fprintf(file, "%u bytes:\n{\n", len); + uint32_t i = 0; + for(i = 0; i < len - 1; i++) + { + fprintf(file, "0x%x, ", array[i]); + if(i % 8 == 7) fprintf(file, "\n"); + } + fprintf(file, "0x%x ", array[i]); + fprintf(file, "\n}\n"); +} + + +void PRINT_ATTESTATION_SERVICE_RESPONSE( + FILE *file, + ra_samp_response_header_t *response) +{ + if(!response) + { + fprintf(file, "\t\n( null )\n"); + return; + } + + fprintf(file, "RESPONSE TYPE: 0x%x\n", response->type); + fprintf(file, "RESPONSE STATUS: 0x%x 0x%x\n", response->status[0], + response->status[1]); + fprintf(file, "RESPONSE BODY SIZE: %u\n", response->size); + + if(response->type == TYPE_RA_MSG2) + { + sgx_ra_msg2_t* p_msg2_body = (sgx_ra_msg2_t*)(response->body); + + fprintf(file, "MSG2 gb - "); + PRINT_BYTE_ARRAY(file, &(p_msg2_body->g_b), sizeof(p_msg2_body->g_b)); + + fprintf(file, "MSG2 spid - "); + PRINT_BYTE_ARRAY(file, &(p_msg2_body->spid), sizeof(p_msg2_body->spid)); + + fprintf(file, "MSG2 quote_type : %hx\n", p_msg2_body->quote_type); + + fprintf(file, "MSG2 kdf_id : %hx\n", p_msg2_body->kdf_id); + + fprintf(file, "MSG2 sign_gb_ga - "); + PRINT_BYTE_ARRAY(file, &(p_msg2_body->sign_gb_ga), + sizeof(p_msg2_body->sign_gb_ga)); + + fprintf(file, "MSG2 mac - "); + PRINT_BYTE_ARRAY(file, &(p_msg2_body->mac), sizeof(p_msg2_body->mac)); + + fprintf(file, "MSG2 sig_rl - "); + PRINT_BYTE_ARRAY(file, &(p_msg2_body->sig_rl), + p_msg2_body->sig_rl_size); + } + else if(response->type == TYPE_RA_ATT_RESULT) + { + sample_ra_att_result_msg_t *p_att_result = + (sample_ra_att_result_msg_t *)(response->body); + fprintf(file, "ATTESTATION RESULT MSG platform_info_blob - "); + PRINT_BYTE_ARRAY(file, &(p_att_result->platform_info_blob), + sizeof(p_att_result->platform_info_blob)); + + fprintf(file, "ATTESTATION RESULT MSG mac - "); + PRINT_BYTE_ARRAY(file, &(p_att_result->mac), sizeof(p_att_result->mac)); + + fprintf(file, "ATTESTATION RESULT MSG secret.payload_tag - %u bytes\n", + p_att_result->secret.payload_size); + + fprintf(file, "ATTESTATION RESULT MSG secret.payload - "); + PRINT_BYTE_ARRAY(file, p_att_result->secret.payload, + p_att_result->secret.payload_size); + } + else + { + fprintf(file, "\nERROR in printing out the response. " + "Response of type not supported %d\n", response->type); + } +} + +// This sample code doesn't have any recovery/retry mechanisms for the remote +// attestation. Since the enclave can be lost due S3 transitions, apps +// susceptible to S3 transitions should have logic to restart attestation in +// these scenarios. +#define _T(x) x +int main(int argc, char* argv[]) +{ + int ret = 0; + ra_samp_request_header_t *p_msg0_full = NULL; + ra_samp_response_header_t *p_msg0_resp_full = NULL; + ra_samp_request_header_t *p_msg1_full = NULL; + ra_samp_response_header_t *p_msg2_full = NULL; + sgx_ra_msg3_t *p_msg3 = NULL; + ra_samp_response_header_t* p_att_result_msg_full = NULL; + sgx_enclave_id_t enclave_id = 0; + int enclave_lost_retry_time = 1; + int busy_retry_time = 4; + sgx_ra_context_t context = INT_MAX; + sgx_status_t status = SGX_SUCCESS; + ra_samp_request_header_t* p_msg3_full = NULL; + + int32_t verify_index = -1; + int32_t verification_samples = sizeof(msg1_samples)/sizeof(msg1_samples[0]); + + FILE* OUTPUT = stdout; + +#define VERIFICATION_INDEX_IS_VALID() (verify_index > 0 && \ + verify_index <= verification_samples) +#define GET_VERIFICATION_ARRAY_INDEX() (verify_index-1) + + if(argc > 1) + { + + verify_index = atoi(argv[1]); + + if( VERIFICATION_INDEX_IS_VALID()) + { + fprintf(OUTPUT, "\nVerifying precomputed attestation messages " + "using precomputed values# %d\n", verify_index); + } + else + { + fprintf(OUTPUT, "\nValid invocations are:\n"); + fprintf(OUTPUT, "\n\tisv_app\n"); + fprintf(OUTPUT, "\n\tisv_app \n"); + fprintf(OUTPUT, "\nValid indices are [1 - %d]\n", + verification_samples); + fprintf(OUTPUT, "\nUsing a verification index uses precomputed " + "messages to assist debugging the remote attestation " + "service provider.\n"); + return -1; + } + } + + // Preparation for remote attestation by configuring extended epid group id. + { + uint32_t extended_epid_group_id = 0; + ret = sgx_get_extended_epid_group_id(&extended_epid_group_id); + if (SGX_SUCCESS != ret) + { + ret = -1; + fprintf(OUTPUT, "\nError, call sgx_get_extended_epid_group_id fail [%s].", + __FUNCTION__); + return ret; + } + fprintf(OUTPUT, "\nCall sgx_get_extended_epid_group_id success."); + + p_msg0_full = (ra_samp_request_header_t*) + malloc(sizeof(ra_samp_request_header_t) + +sizeof(uint32_t)); + if (NULL == p_msg0_full) + { + ret = -1; + goto CLEANUP; + } + p_msg0_full->type = TYPE_RA_MSG0; + p_msg0_full->size = sizeof(uint32_t); + + *(uint32_t*)((uint8_t*)p_msg0_full + sizeof(ra_samp_request_header_t)) = extended_epid_group_id; + { + + fprintf(OUTPUT, "\nMSG0 body generated -\n"); + + PRINT_BYTE_ARRAY(OUTPUT, p_msg0_full->body, p_msg0_full->size); + + } + // The ISV application sends msg0 to the SP. + // The ISV decides whether to support this extended epid group id. + fprintf(OUTPUT, "\nSending msg0 to remote attestation service provider.\n"); + + ret = ra_network_send_receive("http://SampleServiceProvider.intel.com/", + p_msg0_full, + &p_msg0_resp_full); + if (ret != 0) + { + fprintf(OUTPUT, "\nError, ra_network_send_receive for msg0 failed " + "[%s].", __FUNCTION__); + goto CLEANUP; + } + fprintf(OUTPUT, "\nSent MSG0 to remote attestation service.\n"); + } + // Remote attestation will be initiated the ISV server challenges the ISV + // app or if the ISV app detects it doesn't have the credentials + // (shared secret) from a previous attestation required for secure + // communication with the server. + { + // ISV application creates the ISV enclave. + int launch_token_update = 0; + sgx_launch_token_t launch_token = {0}; + memset(&launch_token, 0, sizeof(sgx_launch_token_t)); + do + { + ret = sgx_create_enclave(_T(ENCLAVE_PATH), + SGX_DEBUG_FLAG, + &launch_token, + &launch_token_update, + &enclave_id, NULL); + if(SGX_SUCCESS != ret) + { + ret = -1; + fprintf(OUTPUT, "\nError, call sgx_create_enclave fail [%s].", + __FUNCTION__); + goto CLEANUP; + } + fprintf(OUTPUT, "\nCall sgx_create_enclave success."); + + ret = enclave_init_ra(enclave_id, + &status, + false, + &context); + //Ideally, this check would be around the full attestation flow. + } while (SGX_ERROR_ENCLAVE_LOST == ret && enclave_lost_retry_time--); + + if(SGX_SUCCESS != ret || status) + { + ret = -1; + fprintf(OUTPUT, "\nError, call enclave_init_ra fail [%s].", + __FUNCTION__); + goto CLEANUP; + } + fprintf(OUTPUT, "\nCall enclave_init_ra success."); + + // isv application call uke sgx_ra_get_msg1 + p_msg1_full = (ra_samp_request_header_t*) + malloc(sizeof(ra_samp_request_header_t) + + sizeof(sgx_ra_msg1_t)); + if(NULL == p_msg1_full) + { + ret = -1; + goto CLEANUP; + } + p_msg1_full->type = TYPE_RA_MSG1; + p_msg1_full->size = sizeof(sgx_ra_msg1_t); + do + { + ret = sgx_ra_get_msg1(context, enclave_id, sgx_ra_get_ga, + (sgx_ra_msg1_t*)((uint8_t*)p_msg1_full + + sizeof(ra_samp_request_header_t))); + sleep(3); // Wait 3s between retries + } while (SGX_ERROR_BUSY == ret && busy_retry_time--); + if(SGX_SUCCESS != ret) + { + ret = -1; + fprintf(OUTPUT, "\nError, call sgx_ra_get_msg1 fail [%s].", + __FUNCTION__); + goto CLEANUP; + } + else + { + fprintf(OUTPUT, "\nCall sgx_ra_get_msg1 success.\n"); + + fprintf(OUTPUT, "\nMSG1 body generated -\n"); + + PRINT_BYTE_ARRAY(OUTPUT, p_msg1_full->body, p_msg1_full->size); + + } + + if(VERIFICATION_INDEX_IS_VALID()) + { + + memcpy_s(p_msg1_full->body, p_msg1_full->size, + msg1_samples[GET_VERIFICATION_ARRAY_INDEX()], + p_msg1_full->size); + + fprintf(OUTPUT, "\nInstead of using the recently generated MSG1, " + "we will use the following precomputed MSG1 -\n"); + + PRINT_BYTE_ARRAY(OUTPUT, p_msg1_full->body, p_msg1_full->size); + } + + + // The ISV application sends msg1 to the SP to get msg2, + // msg2 needs to be freed when no longer needed. + // The ISV decides whether to use linkable or unlinkable signatures. + fprintf(OUTPUT, "\nSending msg1 to remote attestation service provider." + "Expecting msg2 back.\n"); + + + ret = ra_network_send_receive("http://SampleServiceProvider.intel.com/", + p_msg1_full, + &p_msg2_full); + + if(ret != 0 || !p_msg2_full) + { + fprintf(OUTPUT, "\nError, ra_network_send_receive for msg1 failed " + "[%s].", __FUNCTION__); + if(VERIFICATION_INDEX_IS_VALID()) + { + fprintf(OUTPUT, "\nBecause we are in verification mode we will " + "ignore this error.\n"); + fprintf(OUTPUT, "\nInstead, we will pretend we received the " + "following MSG2 - \n"); + + SAFE_FREE(p_msg2_full); + ra_samp_response_header_t* precomputed_msg2 = + (ra_samp_response_header_t*)msg2_samples[ + GET_VERIFICATION_ARRAY_INDEX()]; + const size_t msg2_full_size = sizeof(ra_samp_response_header_t) + + precomputed_msg2->size; + p_msg2_full = + (ra_samp_response_header_t*)malloc(msg2_full_size); + if(NULL == p_msg2_full) + { + ret = -1; + goto CLEANUP; + } + memcpy_s(p_msg2_full, msg2_full_size, precomputed_msg2, + msg2_full_size); + + PRINT_BYTE_ARRAY(OUTPUT, p_msg2_full, + sizeof(ra_samp_response_header_t) + + p_msg2_full->size); + } + else + { + goto CLEANUP; + } + } + else + { + // Successfully sent msg1 and received a msg2 back. + // Time now to check msg2. + if(TYPE_RA_MSG2 != p_msg2_full->type) + { + + fprintf(OUTPUT, "\nError, didn't get MSG2 in response to MSG1. " + "[%s].", __FUNCTION__); + + if(VERIFICATION_INDEX_IS_VALID()) + { + fprintf(OUTPUT, "\nBecause we are in verification mode we " + "will ignore this error."); + } + else + { + goto CLEANUP; + } + } + + fprintf(OUTPUT, "\nSent MSG1 to remote attestation service " + "provider. Received the following MSG2:\n"); + PRINT_BYTE_ARRAY(OUTPUT, p_msg2_full, + sizeof(ra_samp_response_header_t) + + p_msg2_full->size); + + fprintf(OUTPUT, "\nA more descriptive representation of MSG2:\n"); + PRINT_ATTESTATION_SERVICE_RESPONSE(OUTPUT, p_msg2_full); + + if( VERIFICATION_INDEX_IS_VALID() ) + { + // The response should match the precomputed MSG2: + ra_samp_response_header_t* precomputed_msg2 = + (ra_samp_response_header_t *) + msg2_samples[GET_VERIFICATION_ARRAY_INDEX()]; + if(memcmp( precomputed_msg2, p_msg2_full, + sizeof(ra_samp_response_header_t) + p_msg2_full->size)) + { + fprintf(OUTPUT, "\nVerification ERROR. Our precomputed " + "value for MSG2 does NOT match.\n"); + fprintf(OUTPUT, "\nPrecomputed value for MSG2:\n"); + PRINT_BYTE_ARRAY(OUTPUT, precomputed_msg2, + sizeof(ra_samp_response_header_t) + + precomputed_msg2->size); + fprintf(OUTPUT, "\nA more descriptive representation " + "of precomputed value for MSG2:\n"); + PRINT_ATTESTATION_SERVICE_RESPONSE(OUTPUT, + precomputed_msg2); + } + else + { + fprintf(OUTPUT, "\nVerification COMPLETE. Remote " + "attestation service provider generated a " + "matching MSG2.\n"); + } + } + + } + + sgx_ra_msg2_t* p_msg2_body = (sgx_ra_msg2_t*)((uint8_t*)p_msg2_full + + sizeof(ra_samp_response_header_t)); + + + uint32_t msg3_size = 0; + if( VERIFICATION_INDEX_IS_VALID()) + { + // We cannot generate a valid MSG3 using the precomputed messages + // we have been using. We will use the precomputed msg3 instead. + msg3_size = MSG3_BODY_SIZE; + p_msg3 = (sgx_ra_msg3_t*)malloc(msg3_size); + if(NULL == p_msg3) + { + ret = -1; + goto CLEANUP; + } + memcpy_s(p_msg3, msg3_size, + msg3_samples[GET_VERIFICATION_ARRAY_INDEX()], msg3_size); + fprintf(OUTPUT, "\nBecause MSG1 was a precomputed value, the MSG3 " + "we use will also be. PRECOMPUTED MSG3 - \n"); + } + else + { + busy_retry_time = 2; + // The ISV app now calls uKE sgx_ra_proc_msg2, + // The ISV app is responsible for freeing the returned p_msg3!! + do + { + ret = sgx_ra_proc_msg2(context, + enclave_id, + sgx_ra_proc_msg2_trusted, + sgx_ra_get_msg3_trusted, + p_msg2_body, + p_msg2_full->size, + &p_msg3, + &msg3_size); + } while (SGX_ERROR_BUSY == ret && busy_retry_time--); + if(!p_msg3) + { + fprintf(OUTPUT, "\nError, call sgx_ra_proc_msg2 fail. " + "p_msg3 = 0x%p [%s].", p_msg3, __FUNCTION__); + ret = -1; + goto CLEANUP; + } + if(SGX_SUCCESS != (sgx_status_t)ret) + { + fprintf(OUTPUT, "\nError, call sgx_ra_proc_msg2 fail. " + "ret = 0x%08x [%s].", ret, __FUNCTION__); + ret = -1; + goto CLEANUP; + } + else + { + fprintf(OUTPUT, "\nCall sgx_ra_proc_msg2 success.\n"); + fprintf(OUTPUT, "\nMSG3 - \n"); + } + } + + PRINT_BYTE_ARRAY(OUTPUT, p_msg3, msg3_size); + + p_msg3_full = (ra_samp_request_header_t*)malloc( + sizeof(ra_samp_request_header_t) + msg3_size); + if(NULL == p_msg3_full) + { + ret = -1; + goto CLEANUP; + } + p_msg3_full->type = TYPE_RA_MSG3; + p_msg3_full->size = msg3_size; + if(memcpy_s(p_msg3_full->body, msg3_size, p_msg3, msg3_size)) + { + fprintf(OUTPUT,"\nError: INTERNAL ERROR - memcpy failed in [%s].", + __FUNCTION__); + ret = -1; + goto CLEANUP; + } + + // The ISV application sends msg3 to the SP to get the attestation + // result message, attestation result message needs to be freed when + // no longer needed. The ISV service provider decides whether to use + // linkable or unlinkable signatures. The format of the attestation + // result is up to the service provider. This format is used for + // demonstration. Note that the attestation result message makes use + // of both the MK for the MAC and the SK for the secret. These keys are + // established from the SIGMA secure channel binding. + ret = ra_network_send_receive("http://SampleServiceProvider.intel.com/", + p_msg3_full, + &p_att_result_msg_full); + if(ret || !p_att_result_msg_full) + { + ret = -1; + fprintf(OUTPUT, "\nError, sending msg3 failed [%s].", __FUNCTION__); + goto CLEANUP; + } + + + sample_ra_att_result_msg_t * p_att_result_msg_body = + (sample_ra_att_result_msg_t *)((uint8_t*)p_att_result_msg_full + + sizeof(ra_samp_response_header_t)); + if(TYPE_RA_ATT_RESULT != p_att_result_msg_full->type) + { + ret = -1; + fprintf(OUTPUT, "\nError. Sent MSG3 successfully, but the message " + "received was NOT of type att_msg_result. Type = " + "%d. [%s].", p_att_result_msg_full->type, + __FUNCTION__); + goto CLEANUP; + } + else + { + fprintf(OUTPUT, "\nSent MSG3 successfully. Received an attestation " + "result message back\n."); + if( VERIFICATION_INDEX_IS_VALID() ) + { + if(memcmp(p_att_result_msg_full->body, + attestation_msg_samples[GET_VERIFICATION_ARRAY_INDEX()], + p_att_result_msg_full->size) ) + { + fprintf(OUTPUT, "\nSent MSG3 successfully. Received an " + "attestation result message back that did " + "NOT match the expected value.\n"); + fprintf(OUTPUT, "\nEXPECTED ATTESTATION RESULT -"); + PRINT_BYTE_ARRAY(OUTPUT, + attestation_msg_samples[GET_VERIFICATION_ARRAY_INDEX()], + p_att_result_msg_full->size); + } + } + } + + fprintf(OUTPUT, "\nATTESTATION RESULT RECEIVED - "); + PRINT_BYTE_ARRAY(OUTPUT, p_att_result_msg_full->body, + p_att_result_msg_full->size); + + + if( VERIFICATION_INDEX_IS_VALID() ) + { + fprintf(OUTPUT, "\nBecause we used precomputed values for the " + "messages, the attestation result message will " + "not pass further verification tests, so we will " + "skip them.\n"); + goto CLEANUP; + } + + // Check the MAC using MK on the attestation result message. + // The format of the attestation result message is ISV specific. + // This is a simple form for demonstration. In a real product, + // the ISV may want to communicate more information. + ret = verify_att_result_mac(enclave_id, + &status, + context, + (uint8_t*)&p_att_result_msg_body->platform_info_blob, + sizeof(ias_platform_info_blob_t), + (uint8_t*)&p_att_result_msg_body->mac, + sizeof(sgx_mac_t)); + if((SGX_SUCCESS != ret) || + (SGX_SUCCESS != status)) + { + ret = -1; + fprintf(OUTPUT, "\nError: INTEGRITY FAILED - attestation result " + "message MK based cmac failed in [%s].", + __FUNCTION__); + goto CLEANUP; + } + + bool attestation_passed = true; + // Check the attestation result for pass or fail. + // Whether attestation passes or fails is a decision made by the ISV Server. + // When the ISV server decides to trust the enclave, then it will return success. + // When the ISV server decided to not trust the enclave, then it will return failure. + if(0 != p_att_result_msg_full->status[0] + || 0 != p_att_result_msg_full->status[1]) + { + fprintf(OUTPUT, "\nError, attestation result message MK based cmac " + "failed in [%s].", __FUNCTION__); + attestation_passed = false; + } + + // The attestation result message should contain a field for the Platform + // Info Blob (PIB). The PIB is returned by attestation server in the attestation report. + // It is not returned in all cases, but when it is, the ISV app + // should pass it to the blob analysis API called sgx_report_attestation_status() + // along with the trust decision from the ISV server. + // The ISV application will take action based on the update_info. + // returned in update_info by the API. + // This call is stubbed out for the sample. + // + // sgx_update_info_bit_t update_info; + // ret = sgx_report_attestation_status( + // &p_att_result_msg_body->platform_info_blob, + // attestation_passed ? 0 : 1, &update_info); + + // Get the shared secret sent by the server using SK (if attestation + // passed) + if(attestation_passed) + { + ret = put_secret_data(enclave_id, + &status, + context, + p_att_result_msg_body->secret.payload, + p_att_result_msg_body->secret.payload_size, + p_att_result_msg_body->secret.payload_tag); + if((SGX_SUCCESS != ret) || (SGX_SUCCESS != status)) + { + fprintf(OUTPUT, "\nError, attestation result message secret " + "using SK based AESGCM failed in [%s]. ret = " + "0x%0x. status = 0x%0x", __FUNCTION__, ret, + status); + goto CLEANUP; + } + } + fprintf(OUTPUT, "\nSecret successfully received from server."); + fprintf(OUTPUT, "\nRemote attestation success!"); + } + +CLEANUP: + // Clean-up + // Need to close the RA key state. + if(INT_MAX != context) + { + int ret_save = ret; + ret = enclave_ra_close(enclave_id, &status, context); + if(SGX_SUCCESS != ret || status) + { + ret = -1; + fprintf(OUTPUT, "\nError, call enclave_ra_close fail [%s].", + __FUNCTION__); + } + else + { + // enclave_ra_close was successful, let's restore the value that + // led us to this point in the code. + ret = ret_save; + } + fprintf(OUTPUT, "\nCall enclave_ra_close success."); + } + + sgx_destroy_enclave(enclave_id); + + + ra_free_network_response_buffer(p_msg0_resp_full); + ra_free_network_response_buffer(p_msg2_full); + ra_free_network_response_buffer(p_att_result_msg_full); + + // p_msg3 is malloc'd by the untrusted KE library. App needs to free. + SAFE_FREE(p_msg3); + SAFE_FREE(p_msg3_full); + SAFE_FREE(p_msg1_full); + SAFE_FREE(p_msg0_full); + printf("\nEnter a character before exit ...\n"); + getchar(); + return ret; +} + diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/isv_app/sample_messages.h b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/isv_app/sample_messages.h new file mode 100644 index 0000000000..92281777fa --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/isv_app/sample_messages.h @@ -0,0 +1,537 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +//This file contains samples of messages sent between the sample ISV application +//and the sample service provider. It is intended to be used so that authors +//of other service providers can verify that the messages generated by their +//remote attestation service matches. + +#include + +uint8_t msg1_sample1[] = +{ + 0xe8, 0xcf, 0xf, 0x97, 0x8a, 0xf4, 0x24, 0x8a, + 0xf5, 0x5b, 0x56, 0xf0, 0xac, 0x7f, 0x78, 0x39, + 0x71, 0x10, 0xb8, 0xdc, 0x88, 0xd, 0x50, 0xf0, + 0x39, 0x85, 0x37, 0xfe, 0xad, 0x1f, 0xc7, 0x59, + 0xc7, 0x23, 0x81, 0xfd, 0x4a, 0x2, 0x48, 0xdf, + 0xd3, 0x74, 0xda, 0x45, 0x48, 0x62, 0xc8, 0xb6, + 0x73, 0x43, 0x26, 0x42, 0x8f, 0x1f, 0x89, 0x17, + 0xe7, 0xa9, 0x2a, 0xf5, 0x27, 0xb3, 0xcc, 0x4d, + 0x3, 0x1, 0x0, 0x0 +}; + +uint8_t msg1_sample2[] = +{ + 0xa8, 0x56, 0x72, 0xc1, 0x14, 0x41, 0xa, 0x2f, + 0xdc, 0xb0, 0xa8, 0xa1, 0x3a, 0x51, 0x40, 0xf9, + 0x12, 0x9f, 0x11, 0x86, 0xe9, 0x1a, 0xf1, 0x16, + 0xbc, 0xd4, 0x6, 0x2f, 0x47, 0x2c, 0xc3, 0x37, + 0x8e, 0x65, 0x7, 0x29, 0x85, 0xb0, 0x8, 0x61, + 0x6b, 0x6d, 0xc7, 0x22, 0x7d, 0x22, 0x61, 0x7f, + 0x40, 0x43, 0x40, 0x5a, 0x7a, 0xf4, 0x94, 0x0, + 0x60, 0x36, 0xf6, 0xa4, 0x22, 0x22, 0x41, 0x82, + 0x3, 0x1, 0x0, 0x0 +}; + +uint8_t msg2_sample1[] = +{ + 0x2, 0x0, 0x0, 0xa8, 0x0, 0x0, 0x0, 0x0, + 0x6a, 0x83, 0xdc, 0x84, 0xd4, 0x4c, 0x8a, 0xbb, + 0x5e, 0x42, 0xaf, 0xee, 0x8d, 0xe9, 0xf4, 0x57, + 0x71, 0xfd, 0x73, 0x66, 0xd7, 0xfa, 0xad, 0xfa, + 0xf2, 0x17, 0x14, 0xdd, 0x5a, 0xb9, 0x9e, 0x97, + 0x79, 0xa7, 0x38, 0x72, 0xf2, 0xb8, 0xd6, 0xbe, + 0x18, 0x91, 0x7f, 0xf7, 0xb5, 0xd3, 0xe5, 0x64, + 0x9b, 0x12, 0x18, 0xaf, 0x39, 0x29, 0x6c, 0x24, + 0x19, 0x38, 0x29, 0xb, 0xc6, 0xac, 0xc, 0x62, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20, + 0x58, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x1, 0x0, 0x1, 0x0, 0x6a, 0x83, 0xdc, 0x84, + 0xd4, 0x4c, 0x8a, 0xbb, 0x5e, 0x42, 0xaf, 0xee, + 0x8d, 0xe9, 0xf4, 0x57, 0x71, 0xfd, 0x73, 0x66, + 0xd7, 0xfa, 0xad, 0xfa, 0xf2, 0x17, 0x14, 0xdd, + 0x5a, 0xb9, 0x9e, 0x97, 0x6, 0x10, 0x58, 0x61, + 0xa5, 0xbf, 0x7d, 0x2e, 0xab, 0xcc, 0x1a, 0x3e, + 0x4f, 0x44, 0x15, 0xe7, 0x91, 0xca, 0x64, 0x2b, + 0x42, 0xb7, 0x53, 0xd9, 0x71, 0x37, 0xf1, 0x9b, + 0x31, 0xb5, 0xa5, 0x6b, 0xf8, 0xfa, 0x64, 0xfe, + 0x7a, 0x9e, 0xdc, 0xf4, 0xf0, 0x59, 0xbd, 0x78, + 0x27, 0xc2, 0x55, 0xb9, 0x0, 0x0, 0x0, 0x0 +}; + +uint8_t msg2_sample2[] = +{ + 0x2, 0x0, 0x0, 0xa8, 0x0, 0x0, 0x0, 0x0, + 0x6a, 0x83, 0xdc, 0x84, 0xd4, 0x4c, 0x8a, 0xbb, + 0x5e, 0x42, 0xaf, 0xee, 0x8d, 0xe9, 0xf4, 0x57, + 0x71, 0xfd, 0x73, 0x66, 0xd7, 0xfa, 0xad, 0xfa, + 0xf2, 0x17, 0x14, 0xdd, 0x5a, 0xb9, 0x9e, 0x97, + 0x79, 0xa7, 0x38, 0x72, 0xf2, 0xb8, 0xd6, 0xbe, + 0x18, 0x91, 0x7f, 0xf7, 0xb5, 0xd3, 0xe5, 0x64, + 0x9b, 0x12, 0x18, 0xaf, 0x39, 0x29, 0x6c, 0x24, + 0x19, 0x38, 0x29, 0xb, 0xc6, 0xac, 0xc, 0x62, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20, + 0x58, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x1, 0x0, 0x1, 0x0, 0x6a, 0x83, 0xdc, 0x84, + 0xd4, 0x4c, 0x8a, 0xbb, 0x5e, 0x42, 0xaf, 0xee, + 0x8d, 0xe9, 0xf4, 0x57, 0x71, 0xfd, 0x73, 0x66, + 0xd7, 0xfa, 0xad, 0xfa, 0xf2, 0x17, 0x14, 0xdd, + 0x5a, 0xb9, 0x9e, 0x97, 0x75, 0x39, 0x23, 0x1b, + 0xc2, 0x5a, 0xd4, 0xfa, 0x41, 0xe9, 0xd4, 0x42, + 0x72, 0x8a, 0x75, 0x4b, 0x48, 0x5a, 0xfb, 0xc0, + 0x90, 0x42, 0xef, 0x9c, 0xed, 0xcb, 0xc1, 0x45, + 0x2d, 0xfe, 0x86, 0xbc, 0xee, 0x3, 0xa8, 0x97, + 0x68, 0xf0, 0xb4, 0xf, 0xa, 0x5b, 0x5f, 0xc1, + 0xe4, 0xf9, 0xa9, 0xa6, 0x0, 0x0, 0x0, 0x0 +}; + +#define MSG3_BODY_SIZE 1452 + +uint8_t msg3_sample1[MSG3_BODY_SIZE] = +{ + 0x57, 0x19, 0x8, 0xa1, 0x3b, 0xd0, 0x37, 0xa8, + 0x4a, 0x32, 0xf1, 0x31, 0xc1, 0x14, 0xff, 0xdf, + 0xe8, 0xcf, 0xf, 0x97, 0x8a, 0xf4, 0x24, 0x8a, + 0xf5, 0x5b, 0x56, 0xf0, 0xac, 0x7f, 0x78, 0x39, + 0x71, 0x10, 0xb8, 0xdc, 0x88, 0xd, 0x50, 0xf0, + 0x39, 0x85, 0x37, 0xfe, 0xad, 0x1f, 0xc7, 0x59, + 0xc7, 0x23, 0x81, 0xfd, 0x4a, 0x2, 0x48, 0xdf, + 0xd3, 0x74, 0xda, 0x45, 0x48, 0x62, 0xc8, 0xb6, + 0x73, 0x43, 0x26, 0x42, 0x8f, 0x1f, 0x89, 0x17, + 0xe7, 0xa9, 0x2a, 0xf5, 0x27, 0xb3, 0xcc, 0x4d, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x2, 0x0, 0x1, 0x0, 0x3, 0x1, 0x0, 0x0, + 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20, + 0x58, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x2, 0x2, 0xff, 0xff, 0xff, 0x1, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0xe2, 0x55, 0x5d, 0xc6, 0xe6, 0x69, 0x53, 0xc0, + 0x8d, 0x52, 0x5b, 0xc0, 0x2a, 0x2c, 0x5c, 0x2f, + 0xc, 0x8c, 0xfe, 0x5b, 0x1, 0xae, 0x89, 0xff, + 0x2, 0x2f, 0x97, 0xea, 0x9b, 0x45, 0xb6, 0x2e, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x60, 0x27, 0x7a, 0xd2, 0xfd, 0xfc, 0x57, 0xe9, + 0x80, 0xe8, 0x76, 0xe7, 0xf8, 0x78, 0xac, 0x19, + 0x9, 0x88, 0xe, 0xa5, 0x38, 0x7, 0x95, 0xa7, + 0xe8, 0xea, 0x98, 0xb1, 0x57, 0x84, 0x1f, 0x85, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x2a, 0xe, 0x9, 0x4c, 0xe2, 0xd9, 0x44, 0x73, + 0x36, 0x42, 0xfa, 0xe0, 0x44, 0x5b, 0x7b, 0x1f, + 0xc2, 0x85, 0x16, 0xca, 0xf1, 0xc5, 0xcd, 0xd2, + 0xf, 0xe4, 0xdf, 0xf, 0x31, 0xca, 0x36, 0x28, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0xa8, 0x2, 0x0, 0x0, 0x68, 0xe3, 0x1d, 0x2, + 0xd1, 0x6, 0x2a, 0x16, 0xab, 0x1c, 0xfd, 0x43, + 0x5c, 0x1f, 0x34, 0x5, 0x15, 0xc4, 0x84, 0xdd, + 0xee, 0x73, 0x79, 0xe7, 0x2e, 0xc8, 0x95, 0x77, + 0x6b, 0xca, 0xff, 0xb9, 0xf4, 0xf8, 0x5a, 0x42, + 0x9d, 0x32, 0x73, 0x62, 0xab, 0x49, 0x8, 0xa4, + 0xc3, 0x5c, 0x5a, 0x66, 0x38, 0x76, 0xcd, 0x58, + 0x5b, 0x85, 0xbf, 0xf0, 0x52, 0x12, 0xd2, 0xc8, + 0xd, 0xf8, 0x6d, 0x91, 0xb8, 0xcf, 0x3f, 0x1d, + 0xe0, 0x1d, 0x63, 0xb2, 0x58, 0xa7, 0xbc, 0x8, + 0x97, 0xbb, 0xcc, 0x19, 0x31, 0xdb, 0x47, 0xf3, + 0x8e, 0x54, 0x7d, 0x36, 0x6e, 0x6, 0xd3, 0x20, + 0xca, 0x5e, 0x8a, 0x5, 0x30, 0x50, 0x56, 0xe9, + 0x91, 0x9, 0x35, 0x13, 0x69, 0xd, 0x24, 0x71, + 0x55, 0xca, 0xe8, 0xef, 0x4d, 0x1c, 0xe6, 0x1f, + 0x51, 0xeb, 0x12, 0x32, 0x97, 0xa2, 0xbb, 0x1e, + 0xf2, 0x26, 0xc5, 0xe9, 0x3f, 0xda, 0x79, 0xc3, + 0x89, 0x28, 0x9, 0x6c, 0x59, 0x9e, 0x2d, 0x60, + 0x5f, 0x35, 0x33, 0x76, 0xfe, 0xf5, 0xba, 0x73, + 0xc5, 0xb6, 0x44, 0x9d, 0xb9, 0x3a, 0x90, 0x8, + 0x5e, 0xba, 0x33, 0x3d, 0xe5, 0xff, 0xc0, 0x5b, + 0xbb, 0x7b, 0xbc, 0x39, 0x52, 0x6f, 0x54, 0x8b, + 0xb5, 0x44, 0xf7, 0x75, 0xc5, 0x28, 0xa7, 0x51, + 0xd, 0x69, 0x2b, 0x3a, 0xfd, 0xc0, 0x7c, 0x6f, + 0xf, 0xcf, 0x76, 0x32, 0xea, 0x38, 0xd2, 0x8d, + 0xbe, 0x9c, 0xef, 0x3b, 0x56, 0xdc, 0x8e, 0x29, + 0x40, 0x87, 0x4, 0xe6, 0x15, 0xa1, 0x12, 0x9f, + 0x21, 0x12, 0xe8, 0xd8, 0x5, 0x26, 0x22, 0x23, + 0x12, 0x57, 0xd1, 0xb6, 0x3, 0x59, 0xfa, 0xa6, + 0xfe, 0x24, 0xe1, 0x84, 0xfb, 0x63, 0xf3, 0x3d, + 0xf1, 0xe2, 0x70, 0x2c, 0x94, 0xf1, 0xa4, 0xdc, + 0x70, 0x31, 0xda, 0x9e, 0xb9, 0xf7, 0xc6, 0xba, + 0xd3, 0x4e, 0x5c, 0x63, 0xf1, 0x78, 0xcc, 0x38, + 0xc2, 0x1a, 0xd6, 0x2, 0x34, 0x23, 0x1a, 0x4b, + 0x1, 0x4e, 0xf4, 0xe6, 0xe, 0x6b, 0xfa, 0x27, + 0x8d, 0xe3, 0x67, 0x5d, 0xec, 0x79, 0x13, 0x66, + 0x46, 0xbb, 0xd0, 0x8e, 0xc8, 0x21, 0x6f, 0x37, + 0x5c, 0x5e, 0x5d, 0xed, 0x8e, 0x2d, 0x8d, 0x94, + 0x68, 0x1, 0x0, 0x0, 0x84, 0xd5, 0x35, 0x93, + 0x3a, 0xb1, 0x19, 0x8e, 0xb6, 0xb0, 0x5f, 0x4f, + 0x66, 0x8a, 0xb3, 0xe0, 0x12, 0xbb, 0x7, 0xe0, + 0xa3, 0x6b, 0x54, 0xd5, 0xf6, 0xc8, 0x2, 0xdd, + 0x33, 0x78, 0x3c, 0x4f, 0xdc, 0xa3, 0x3e, 0x5c, + 0x99, 0xb8, 0x2f, 0x3f, 0xdf, 0xf0, 0xf0, 0x63, + 0x24, 0x6f, 0xc2, 0x17, 0xeb, 0x45, 0xd5, 0x79, + 0xaa, 0xb5, 0x46, 0x4b, 0x77, 0x6d, 0x3d, 0xbf, + 0xe8, 0xca, 0xaf, 0x4d, 0xb5, 0x5d, 0xee, 0x9e, + 0xf5, 0x73, 0x8d, 0x1, 0xff, 0x84, 0x1e, 0xc9, + 0x78, 0x2e, 0xde, 0x3, 0x97, 0x36, 0x1c, 0x47, + 0xc, 0x46, 0x5, 0xfc, 0x8b, 0xf5, 0xd5, 0x13, + 0xa3, 0x8, 0xd4, 0x29, 0x83, 0xfb, 0x4b, 0x3e, + 0xf1, 0x3d, 0xe8, 0x54, 0x28, 0x2f, 0x3d, 0x9c, + 0x8b, 0x91, 0xcc, 0xf0, 0x45, 0x40, 0x3, 0xb, + 0xaa, 0x41, 0x38, 0x2f, 0xad, 0xc3, 0x1d, 0x61, + 0x15, 0x20, 0x9, 0xea, 0xfd, 0xdb, 0xf9, 0x17, + 0x84, 0x19, 0xae, 0xf3, 0x4b, 0x4d, 0x8e, 0xa2, + 0x3e, 0x9c, 0xb3, 0x70, 0x4d, 0x38, 0x1, 0x5, + 0xb7, 0xc, 0xb2, 0xf6, 0x84, 0xbe, 0xbc, 0xd5, + 0xd1, 0x8a, 0x22, 0xfc, 0x82, 0xb4, 0x3b, 0x96, + 0x8f, 0xc0, 0x49, 0xaa, 0xf0, 0x52, 0x25, 0xda, + 0x39, 0xc2, 0x4c, 0xbc, 0xe2, 0x47, 0xe3, 0xc, + 0x59, 0xad, 0x40, 0x42, 0x17, 0x30, 0x4d, 0x1c, + 0x34, 0xd3, 0xdb, 0xa7, 0xc5, 0x9c, 0xef, 0x83, + 0xd, 0xb8, 0x9a, 0xa9, 0x29, 0x1b, 0x11, 0x32, + 0x74, 0x53, 0x17, 0x34, 0xd6, 0xa2, 0x14, 0x6, + 0x8b, 0xae, 0x8c, 0xb4, 0xcb, 0x20, 0xec, 0xb3, + 0x2f, 0xe, 0xf3, 0x8f, 0xc3, 0x84, 0xe3, 0xb8, + 0x46, 0x51, 0xea, 0xa6, 0x1c, 0x27, 0x31, 0x1e, + 0x69, 0xb, 0xc7, 0x47, 0xad, 0x7d, 0xde, 0x3f, + 0x13, 0x2b, 0x5e, 0x2a, 0x24, 0x37, 0x85, 0xa4, + 0x8d, 0x45, 0x39, 0xeb, 0x95, 0x47, 0xb8, 0x57, + 0x5d, 0x88, 0xeb, 0x56, 0xb0, 0xa8, 0x58, 0xd, + 0x9e, 0x1b, 0x80, 0x3a, 0x74, 0x86, 0x3a, 0x58, + 0xfc, 0xa6, 0xa, 0xc5, 0x66, 0x5f, 0xc7, 0xa9, + 0xd5, 0xc, 0x37, 0xd1, 0x23, 0xff, 0xfd, 0x1d, + 0x38, 0x1c, 0x98, 0xd1, 0xa9, 0x24, 0x3b, 0x23, + 0xa2, 0x1a, 0xee, 0x8, 0x31, 0x4f, 0xd5, 0xaa, + 0x1d, 0x67, 0xe7, 0x77, 0x5c, 0x46, 0xcc, 0xb, + 0x18, 0xf6, 0xdd, 0x86, 0xf4, 0xcc, 0xb4, 0xd5, + 0xcd, 0xe6, 0xae, 0xb3, 0xf0, 0x24, 0x15, 0x71, + 0xb3, 0x65, 0xff, 0xfa, 0xe5, 0x1a, 0x6d, 0xc3, + 0x6f, 0x43, 0x73, 0xe0, 0xe8, 0xa9, 0x6f, 0x68, + 0xf8, 0x4, 0xf2, 0x73, 0x1, 0x36, 0xeb, 0x83, + 0xa5, 0xf2, 0x6e, 0x4e, 0x36, 0xa5, 0x63, 0xab, + 0x7d, 0xa1, 0xd2, 0x24, 0x17, 0xb7, 0x3b, 0x96, + 0x4b, 0xbe, 0x4c, 0xcb +}; + + +uint8_t msg3_sample2[MSG3_BODY_SIZE] = +{ + 0x4f, 0x85, 0xd3, 0x93, 0xc, 0x44, 0x9c, 0xdd, + 0x3e, 0x81, 0xbd, 0xb6, 0xa2, 0x44, 0x16, 0x5f, + 0xa8, 0x56, 0x72, 0xc1, 0x14, 0x41, 0xa, 0x2f, + 0xdc, 0xb0, 0xa8, 0xa1, 0x3a, 0x51, 0x40, 0xf9, + 0x12, 0x9f, 0x11, 0x86, 0xe9, 0x1a, 0xf1, 0x16, + 0xbc, 0xd4, 0x6, 0x2f, 0x47, 0x2c, 0xc3, 0x37, + 0x8e, 0x65, 0x7, 0x29, 0x85, 0xb0, 0x8, 0x61, + 0x6b, 0x6d, 0xc7, 0x22, 0x7d, 0x22, 0x61, 0x7f, + 0x40, 0x43, 0x40, 0x5a, 0x7a, 0xf4, 0x94, 0x0, + 0x60, 0x36, 0xf6, 0xa4, 0x22, 0x22, 0x41, 0x82, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x2, 0x0, 0x1, 0x0, 0x3, 0x1, 0x0, 0x0, + 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20, + 0x58, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x2, 0x2, 0xff, 0xff, 0xff, 0x1, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0xe2, 0x55, 0x5d, 0xc6, 0xe6, 0x69, 0x53, 0xc0, + 0x8d, 0x52, 0x5b, 0xc0, 0x2a, 0x2c, 0x5c, 0x2f, + 0xc, 0x8c, 0xfe, 0x5b, 0x1, 0xae, 0x89, 0xff, + 0x2, 0x2f, 0x97, 0xea, 0x9b, 0x45, 0xb6, 0x2e, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x60, 0x27, 0x7a, 0xd2, 0xfd, 0xfc, 0x57, 0xe9, + 0x80, 0xe8, 0x76, 0xe7, 0xf8, 0x78, 0xac, 0x19, + 0x9, 0x88, 0xe, 0xa5, 0x38, 0x7, 0x95, 0xa7, + 0xe8, 0xea, 0x98, 0xb1, 0x57, 0x84, 0x1f, 0x85, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0xdd, 0xda, 0x3e, 0x6b, 0x72, 0xa2, 0xd7, 0x31, + 0x31, 0x32, 0xbd, 0xf3, 0xf4, 0xc0, 0xe3, 0xaa, + 0x16, 0x19, 0x72, 0x47, 0x92, 0xe7, 0x8f, 0xf8, + 0x40, 0x2b, 0xa7, 0xc0, 0xb9, 0x77, 0xb1, 0x1c, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0xa8, 0x2, 0x0, 0x0, 0x2e, 0x23, 0x7d, 0xe8, + 0x5d, 0xcd, 0x6d, 0x88, 0x6f, 0xad, 0xd3, 0x4c, + 0x7e, 0xed, 0xff, 0xa2, 0xea, 0x1c, 0xd5, 0xc8, + 0x54, 0xbb, 0x93, 0xc8, 0x1b, 0xbe, 0xbe, 0x51, + 0x6b, 0x8d, 0xb7, 0x90, 0x7f, 0x87, 0x9f, 0x9b, + 0x66, 0x4f, 0xeb, 0xf4, 0x34, 0xbb, 0x90, 0x5d, + 0xc5, 0x20, 0x7b, 0xd2, 0x5a, 0x92, 0x42, 0x80, + 0x2f, 0x3f, 0xc2, 0x64, 0x7e, 0x77, 0xa, 0x49, + 0xdb, 0xde, 0x77, 0x88, 0xd7, 0xce, 0xdb, 0x2e, + 0x44, 0x50, 0x26, 0xd8, 0x7a, 0xe, 0x1c, 0x7f, + 0x63, 0x36, 0x62, 0xa8, 0xa7, 0x2e, 0x60, 0x56, + 0xf4, 0xbc, 0xb5, 0xca, 0xc3, 0x81, 0x9e, 0x84, + 0xb8, 0xc, 0xef, 0x7a, 0x18, 0x4a, 0x5b, 0x3, + 0x0, 0xe3, 0x8c, 0x3f, 0x2e, 0xf9, 0x9a, 0xf7, + 0x72, 0xe1, 0xa0, 0x5e, 0x6a, 0x4c, 0x68, 0xea, + 0x67, 0xfc, 0xe8, 0x21, 0x27, 0x90, 0xae, 0xbf, + 0x51, 0xa4, 0xc9, 0xae, 0x3d, 0x3b, 0x5c, 0x53, + 0x7e, 0x25, 0xa4, 0x6f, 0x78, 0x99, 0x35, 0x2e, + 0x48, 0x50, 0xf9, 0xf0, 0x63, 0x90, 0x19, 0x6a, + 0xc, 0x3d, 0x48, 0x2a, 0x5f, 0x6f, 0xb, 0xd7, + 0x26, 0x64, 0xb5, 0xe0, 0x60, 0x36, 0x69, 0x40, + 0x9c, 0x21, 0x29, 0xe0, 0xca, 0xae, 0xd1, 0x7a, + 0x4, 0xb8, 0x8d, 0x96, 0x74, 0xa3, 0x7, 0xa4, + 0x41, 0x9e, 0xf7, 0x9, 0xbe, 0x8f, 0xe8, 0x65, + 0xd9, 0x26, 0x16, 0xa1, 0xef, 0x1b, 0xf4, 0xb7, + 0xd5, 0xfe, 0xd6, 0x7d, 0xa6, 0x6c, 0x50, 0x8c, + 0x90, 0x34, 0x1f, 0x17, 0x8c, 0x14, 0x38, 0x6d, + 0xd7, 0x83, 0x1a, 0x1e, 0xcf, 0xf5, 0xb, 0xdb, + 0x26, 0x8f, 0x23, 0xf9, 0x4f, 0x41, 0x73, 0xac, + 0x9d, 0xfa, 0x77, 0x3, 0x6a, 0x32, 0xbb, 0x37, + 0x93, 0x47, 0x38, 0x93, 0x39, 0xd2, 0x51, 0x46, + 0xaf, 0xfd, 0x71, 0xda, 0x89, 0xc7, 0x44, 0xb0, + 0xf3, 0x95, 0x74, 0x3b, 0xbc, 0x7d, 0x86, 0xc1, + 0x6e, 0x49, 0xd8, 0x52, 0xc, 0xc1, 0x88, 0x72, + 0x5, 0x5c, 0x92, 0x12, 0x22, 0x95, 0xc5, 0x12, + 0xf5, 0xfa, 0x11, 0x8d, 0x50, 0x42, 0x33, 0x4, + 0x41, 0x17, 0x90, 0xc8, 0xb3, 0x1d, 0x2e, 0xe5, + 0x13, 0xf5, 0xd6, 0xb1, 0xc5, 0xd4, 0x6d, 0xe1, + 0x68, 0x1, 0x0, 0x0, 0xc4, 0x15, 0xbf, 0x91, + 0xf1, 0xad, 0xb1, 0x9f, 0x9b, 0x6b, 0x8d, 0xa2, + 0xdf, 0x7d, 0x6, 0xf8, 0xba, 0x73, 0xb7, 0xb, + 0x72, 0xcc, 0x34, 0x4d, 0x52, 0x3b, 0x76, 0xfd, + 0x8e, 0x3a, 0x67, 0xcc, 0x36, 0xb, 0xa9, 0xc2, + 0x90, 0x37, 0x77, 0x75, 0x90, 0xb8, 0x97, 0x44, + 0xed, 0xb4, 0x61, 0xe8, 0x11, 0xe9, 0x2, 0x50, + 0xde, 0x98, 0x99, 0x3e, 0xf6, 0x5c, 0x71, 0x92, + 0x49, 0xcb, 0x0, 0x72, 0xe0, 0x55, 0xa9, 0x6e, + 0xc7, 0x2, 0xf4, 0x2b, 0x3c, 0xe3, 0x42, 0x7e, + 0x8b, 0xf, 0x26, 0xd9, 0x42, 0x21, 0xd5, 0x74, + 0xe3, 0x35, 0xb3, 0xb8, 0xfe, 0x25, 0x1d, 0x47, + 0x5b, 0x35, 0x8d, 0xfd, 0x18, 0x77, 0x29, 0xd9, + 0x69, 0x2b, 0x67, 0x54, 0x8c, 0xf5, 0xd7, 0x84, + 0x36, 0xf3, 0x96, 0xca, 0xb9, 0x42, 0xad, 0xd6, + 0xba, 0x8d, 0x2f, 0xfc, 0x21, 0xfe, 0xa7, 0xea, + 0x59, 0x94, 0xfe, 0x95, 0x1f, 0x1e, 0xb9, 0xca, + 0x5e, 0x4d, 0xf1, 0x2, 0x68, 0x91, 0xf7, 0xa1, + 0xea, 0x11, 0x90, 0x95, 0x1c, 0xf7, 0x85, 0xd4, + 0x70, 0xf9, 0x49, 0xae, 0x5e, 0xa5, 0x62, 0x3d, + 0x35, 0xc5, 0xdf, 0xc1, 0x7f, 0xc7, 0x39, 0x5a, + 0x3b, 0x89, 0x8c, 0x80, 0x71, 0xe7, 0xbc, 0xbf, + 0x4e, 0x72, 0x6d, 0xd7, 0xe0, 0xa2, 0xb0, 0x7d, + 0xca, 0x89, 0x22, 0x6, 0xb2, 0xb4, 0x3c, 0xa2, + 0xed, 0x51, 0xf, 0xa2, 0xf7, 0xc9, 0x89, 0xf0, + 0x27, 0x2f, 0xf6, 0x41, 0x4e, 0xa, 0x2b, 0x67, + 0x49, 0x44, 0x8e, 0x40, 0xc6, 0xb8, 0xad, 0xb8, + 0x40, 0xb, 0xba, 0x73, 0x2e, 0x1d, 0x4, 0xc9, + 0x28, 0x62, 0x6b, 0x3d, 0xe6, 0x5f, 0x1c, 0xdd, + 0xae, 0x27, 0x6d, 0x3c, 0x2d, 0xf6, 0x42, 0x3b, + 0x91, 0x1, 0x37, 0x47, 0x76, 0x5, 0xbc, 0x7, + 0x8c, 0x6, 0x81, 0x77, 0x70, 0x9d, 0x8a, 0x75, + 0x34, 0x1, 0x68, 0x1a, 0x38, 0x13, 0x11, 0x74, + 0xf2, 0x70, 0x4f, 0x9b, 0x86, 0x15, 0xc6, 0xbc, + 0x6b, 0x1a, 0x56, 0x3f, 0x4f, 0xfa, 0xd4, 0x17, + 0x97, 0xbb, 0x4b, 0x91, 0x3b, 0x54, 0xf7, 0x8e, + 0x53, 0xf5, 0x2, 0x21, 0x3b, 0x66, 0xf9, 0xe5, + 0x79, 0xff, 0xeb, 0x5c, 0x66, 0x1b, 0x34, 0xf4, + 0x41, 0xd1, 0x9a, 0xdb, 0x1f, 0x3e, 0xe3, 0x8a, + 0x90, 0x98, 0x9e, 0x73, 0xb9, 0xa8, 0x20, 0xfe, + 0xe7, 0xe3, 0x9f, 0x83, 0xd3, 0x95, 0x5f, 0xa, + 0x40, 0x53, 0x6a, 0xd3, 0x72, 0x32, 0xde, 0xf1, + 0xf, 0x98, 0x2b, 0x7d, 0x6e, 0x76, 0xbd, 0x31, + 0x84, 0x99, 0x1c, 0xdc, 0xac, 0x78, 0x44, 0xbf, + 0x29, 0xdd, 0x2e, 0xe3, 0x39, 0x9d, 0x38, 0x83, + 0xa, 0x3e, 0x83, 0xb6, 0x74, 0x44, 0x4d, 0x78, + 0x55, 0xb2, 0xe0, 0x74, 0x25, 0x61, 0x67, 0xc0, + 0xe8, 0x1e, 0x5e, 0xd8 +}; + +uint8_t attestation_msg_sample1[] = +{ + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x97, 0x9e, 0xb9, 0x5a, 0xdd, 0x14, 0x17, + 0xf2, 0xfa, 0xad, 0xfa, 0xd7, 0x66, 0x73, 0xfd, + 0x71, 0x57, 0xf4, 0xe9, 0x8d, 0xee, 0xaf, 0x42, + 0x5e, 0xbb, 0x8a, 0x4c, 0xd4, 0x84, 0xdc, 0x83, + 0x6a, 0x8, 0x70, 0xd, 0xf2, 0x42, 0x8b, 0x2b, + 0xee, 0x42, 0xb0, 0x85, 0xe5, 0xbf, 0x99, 0xc5, + 0x22, 0xf8, 0x37, 0xf7, 0xee, 0xb6, 0x2c, 0xd5, + 0x8c, 0x37, 0xa2, 0xd2, 0x51, 0xed, 0x45, 0xf9, + 0x65, 0xf2, 0x25, 0x8a, 0xf9, 0x9, 0x2d, 0xdb, + 0xdc, 0x4a, 0x73, 0xbd, 0x15, 0x49, 0x2, 0x10, + 0xd, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x54, 0x1c, 0xdd, 0x52, 0x93, 0xd8, 0xd4, + 0x28, 0x9d, 0x24, 0x7d, 0x4b, 0xe5, 0xcc, 0xe8, + 0xc0 +}; + +uint8_t attestation_msg_sample2[] = +{ + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x97, 0x9e, 0xb9, 0x5a, 0xdd, 0x14, 0x17, + 0xf2, 0xfa, 0xad, 0xfa, 0xd7, 0x66, 0x73, 0xfd, + 0x71, 0x57, 0xf4, 0xe9, 0x8d, 0xee, 0xaf, 0x42, + 0x5e, 0xbb, 0x8a, 0x4c, 0xd4, 0x84, 0xdc, 0x83, + 0x6a, 0x8, 0x70, 0xd, 0xf2, 0x42, 0x8b, 0x2b, + 0xee, 0x42, 0xb0, 0x85, 0xe5, 0xbf, 0x99, 0xc5, + 0x22, 0xf8, 0x37, 0xf7, 0xee, 0xb6, 0x2c, 0xd5, + 0x8c, 0x37, 0xa2, 0xd2, 0x51, 0xed, 0x45, 0xf9, + 0x65, 0x82, 0x12, 0xa8, 0x53, 0x84, 0x65, 0x62, + 0x33, 0xc0, 0x6, 0x86, 0x9f, 0x82, 0xbb, 0x6d, + 0xd6, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0xb1, 0x60, 0x31, 0x45, 0xd1, 0xa9, 0x23, + 0x7b, 0x85, 0x3f, 0x8, 0x3f, 0x48, 0x6d, 0x2d, + 0xad +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/isv_enclave/isv_enclave.config.xml b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/isv_enclave/isv_enclave.config.xml new file mode 100644 index 0000000000..0b95a3edb1 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/isv_enclave/isv_enclave.config.xml @@ -0,0 +1,11 @@ + + 0 + 0 + 0x40000 + 0x100000 + 1 + 1 + 0 + 0 + 0xFFFFFFFF + \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/isv_enclave/isv_enclave.cpp b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/isv_enclave/isv_enclave.cpp new file mode 100644 index 0000000000..980de0c8db --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/isv_enclave/isv_enclave.cpp @@ -0,0 +1,397 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include +#include "isv_enclave_t.h" +#include "sgx_tkey_exchange.h" +#include "sgx_tcrypto.h" +#include "string.h" + +// This is the public EC key of the SP. The corresponding private EC key is +// used by the SP to sign data used in the remote attestation SIGMA protocol +// to sign channel binding data in MSG2. A successful verification of the +// signature confirms the identity of the SP to the ISV app in remote +// attestation secure channel binding. The public EC key should be hardcoded in +// the enclave or delivered in a trustworthy manner. The use of a spoofed public +// EC key in the remote attestation with secure channel binding session may lead +// to a security compromise. Every different SP the enlcave communicates to +// must have a unique SP public key. Delivery of the SP public key is +// determined by the ISV. The TKE SIGMA protocl expects an Elliptical Curve key +// based on NIST P-256 +static const sgx_ec256_public_t g_sp_pub_key = { + { + 0x72, 0x12, 0x8a, 0x7a, 0x17, 0x52, 0x6e, 0xbf, + 0x85, 0xd0, 0x3a, 0x62, 0x37, 0x30, 0xae, 0xad, + 0x3e, 0x3d, 0xaa, 0xee, 0x9c, 0x60, 0x73, 0x1d, + 0xb0, 0x5b, 0xe8, 0x62, 0x1c, 0x4b, 0xeb, 0x38 + }, + { + 0xd4, 0x81, 0x40, 0xd9, 0x50, 0xe2, 0x57, 0x7b, + 0x26, 0xee, 0xb7, 0x41, 0xe7, 0xc6, 0x14, 0xe2, + 0x24, 0xb7, 0xbd, 0xc9, 0x03, 0xf2, 0x9a, 0x28, + 0xa8, 0x3c, 0xc8, 0x10, 0x11, 0x14, 0x5e, 0x06 + } + +}; + +// Used to store the secret passed by the SP in the sample code. The +// size is forced to be 8 bytes. Expected value is +// 0x01,0x02,0x03,0x04,0x0x5,0x0x6,0x0x7 +uint8_t g_secret[8] = {0}; + + +#ifdef SUPPLIED_KEY_DERIVATION + +#pragma message ("Supplied key derivation function is used.") + +typedef struct _hash_buffer_t +{ + uint8_t counter[4]; + sgx_ec256_dh_shared_t shared_secret; + uint8_t algorithm_id[4]; +} hash_buffer_t; + +const char ID_U[] = "SGXRAENCLAVE"; +const char ID_V[] = "SGXRASERVER"; + +// Derive two keys from shared key and key id. +bool derive_key( + const sgx_ec256_dh_shared_t *p_shared_key, + uint8_t key_id, + sgx_ec_key_128bit_t *first_derived_key, + sgx_ec_key_128bit_t *second_derived_key) +{ + sgx_status_t sgx_ret = SGX_SUCCESS; + hash_buffer_t hash_buffer; + sgx_sha_state_handle_t sha_context; + sgx_sha256_hash_t key_material; + + memset(&hash_buffer, 0, sizeof(hash_buffer_t)); + /* counter in big endian */ + hash_buffer.counter[3] = key_id; + + /*convert from little endian to big endian */ + for (size_t i = 0; i < sizeof(sgx_ec256_dh_shared_t); i++) + { + hash_buffer.shared_secret.s[i] = p_shared_key->s[sizeof(p_shared_key->s)-1 - i]; + } + + sgx_ret = sgx_sha256_init(&sha_context); + if (sgx_ret != SGX_SUCCESS) + { + return false; + } + sgx_ret = sgx_sha256_update((uint8_t*)&hash_buffer, sizeof(hash_buffer_t), sha_context); + if (sgx_ret != SGX_SUCCESS) + { + sgx_sha256_close(sha_context); + return false; + } + sgx_ret = sgx_sha256_update((uint8_t*)&ID_U, sizeof(ID_U), sha_context); + if (sgx_ret != SGX_SUCCESS) + { + sgx_sha256_close(sha_context); + return false; + } + sgx_ret = sgx_sha256_update((uint8_t*)&ID_V, sizeof(ID_V), sha_context); + if (sgx_ret != SGX_SUCCESS) + { + sgx_sha256_close(sha_context); + return false; + } + sgx_ret = sgx_sha256_get_hash(sha_context, &key_material); + if (sgx_ret != SGX_SUCCESS) + { + sgx_sha256_close(sha_context); + return false; + } + sgx_ret = sgx_sha256_close(sha_context); + + assert(sizeof(sgx_ec_key_128bit_t)* 2 == sizeof(sgx_sha256_hash_t)); + memcpy(first_derived_key, &key_material, sizeof(sgx_ec_key_128bit_t)); + memcpy(second_derived_key, (uint8_t*)&key_material + sizeof(sgx_ec_key_128bit_t), sizeof(sgx_ec_key_128bit_t)); + + // memset here can be optimized away by compiler, so please use memset_s on + // windows for production code and similar functions on other OSes. + memset(&key_material, 0, sizeof(sgx_sha256_hash_t)); + + return true; +} + +//isv defined key derivation function id +#define ISV_KDF_ID 2 + +typedef enum _derive_key_type_t +{ + DERIVE_KEY_SMK_SK = 0, + DERIVE_KEY_MK_VK, +} derive_key_type_t; + +sgx_status_t key_derivation(const sgx_ec256_dh_shared_t* shared_key, + uint16_t kdf_id, + sgx_ec_key_128bit_t* smk_key, + sgx_ec_key_128bit_t* sk_key, + sgx_ec_key_128bit_t* mk_key, + sgx_ec_key_128bit_t* vk_key) +{ + bool derive_ret = false; + + if (NULL == shared_key) + { + return SGX_ERROR_INVALID_PARAMETER; + } + + if (ISV_KDF_ID != kdf_id) + { + //fprintf(stderr, "\nError, key derivation id mismatch in [%s].", __FUNCTION__); + return SGX_ERROR_KDF_MISMATCH; + } + + derive_ret = derive_key(shared_key, DERIVE_KEY_SMK_SK, + smk_key, sk_key); + if (derive_ret != true) + { + //fprintf(stderr, "\nError, derive key fail in [%s].", __FUNCTION__); + return SGX_ERROR_UNEXPECTED; + } + + derive_ret = derive_key(shared_key, DERIVE_KEY_MK_VK, + mk_key, vk_key); + if (derive_ret != true) + { + //fprintf(stderr, "\nError, derive key fail in [%s].", __FUNCTION__); + return SGX_ERROR_UNEXPECTED; + } + return SGX_SUCCESS; +} +#else +#pragma message ("Default key derivation function is used.") +#endif + +// This ecall is a wrapper of sgx_ra_init to create the trusted +// KE exchange key context needed for the remote attestation +// SIGMA API's. Input pointers aren't checked since the trusted stubs +// copy them into EPC memory. +// +// @param b_pse Indicates whether the ISV app is using the +// platform services. +// @param p_context Pointer to the location where the returned +// key context is to be copied. +// +// @return Any error return from the create PSE session if b_pse +// is true. +// @return Any error returned from the trusted key exchange API +// for creating a key context. + +sgx_status_t enclave_init_ra( + int b_pse, + sgx_ra_context_t *p_context) +{ + // isv enclave call to trusted key exchange library. + sgx_status_t ret; + if(b_pse) + { + int busy_retry_times = 2; + do{ + ret = sgx_create_pse_session(); + }while (ret == SGX_ERROR_BUSY && busy_retry_times--); + if (ret != SGX_SUCCESS) + return ret; + } +#ifdef SUPPLIED_KEY_DERIVATION + ret = sgx_ra_init_ex(&g_sp_pub_key, b_pse, key_derivation, p_context); +#else + ret = sgx_ra_init(&g_sp_pub_key, b_pse, p_context); +#endif + if(b_pse) + { + sgx_close_pse_session(); + return ret; + } + return ret; +} + + +// Closes the tKE key context used during the SIGMA key +// exchange. +// +// @param context The trusted KE library key context. +// +// @return Return value from the key context close API + +sgx_status_t SGXAPI enclave_ra_close( + sgx_ra_context_t context) +{ + sgx_status_t ret; + ret = sgx_ra_close(context); + return ret; +} + + +// Verify the mac sent in att_result_msg from the SP using the +// MK key. Input pointers aren't checked since the trusted stubs +// copy them into EPC memory. +// +// +// @param context The trusted KE library key context. +// @param p_message Pointer to the message used to produce MAC +// @param message_size Size in bytes of the message. +// @param p_mac Pointer to the MAC to compare to. +// @param mac_size Size in bytes of the MAC +// +// @return SGX_ERROR_INVALID_PARAMETER - MAC size is incorrect. +// @return Any error produced by tKE API to get SK key. +// @return Any error produced by the AESCMAC function. +// @return SGX_ERROR_MAC_MISMATCH - MAC compare fails. + +sgx_status_t verify_att_result_mac(sgx_ra_context_t context, + uint8_t* p_message, + size_t message_size, + uint8_t* p_mac, + size_t mac_size) +{ + sgx_status_t ret; + sgx_ec_key_128bit_t mk_key; + + if(mac_size != sizeof(sgx_mac_t)) + { + ret = SGX_ERROR_INVALID_PARAMETER; + return ret; + } + if(message_size > UINT32_MAX) + { + ret = SGX_ERROR_INVALID_PARAMETER; + return ret; + } + + do { + uint8_t mac[SGX_CMAC_MAC_SIZE] = {0}; + + ret = sgx_ra_get_keys(context, SGX_RA_KEY_MK, &mk_key); + if(SGX_SUCCESS != ret) + { + break; + } + ret = sgx_rijndael128_cmac_msg(&mk_key, + p_message, + (uint32_t)message_size, + &mac); + if(SGX_SUCCESS != ret) + { + break; + } + if(0 == consttime_memequal(p_mac, mac, sizeof(mac))) + { + ret = SGX_ERROR_MAC_MISMATCH; + break; + } + + } + while(0); + + return ret; +} + + +// Generate a secret information for the SP encrypted with SK. +// Input pointers aren't checked since the trusted stubs copy +// them into EPC memory. +// +// @param context The trusted KE library key context. +// @param p_secret Message containing the secret. +// @param secret_size Size in bytes of the secret message. +// @param p_gcm_mac The pointer the the AESGCM MAC for the +// message. +// +// @return SGX_ERROR_INVALID_PARAMETER - secret size if +// incorrect. +// @return Any error produced by tKE API to get SK key. +// @return Any error produced by the AESGCM function. +// @return SGX_ERROR_UNEXPECTED - the secret doesn't match the +// expected value. + +sgx_status_t put_secret_data( + sgx_ra_context_t context, + uint8_t *p_secret, + uint32_t secret_size, + uint8_t *p_gcm_mac) +{ + sgx_status_t ret = SGX_SUCCESS; + sgx_ec_key_128bit_t sk_key; + + do { + if(secret_size != 8) + { + ret = SGX_ERROR_INVALID_PARAMETER; + break; + } + + ret = sgx_ra_get_keys(context, SGX_RA_KEY_SK, &sk_key); + if(SGX_SUCCESS != ret) + { + break; + } + + uint8_t aes_gcm_iv[12] = {0}; + ret = sgx_rijndael128GCM_decrypt(&sk_key, + p_secret, + secret_size, + &g_secret[0], + &aes_gcm_iv[0], + 12, + NULL, + 0, + (const sgx_aes_gcm_128bit_tag_t *) + (p_gcm_mac)); + + uint32_t i; + bool secret_match = true; + for(i=0;i +#include +#include "ecp.h" + +#include "sample_libcrypto.h" + + +#define MAC_KEY_SIZE 16 + +errno_t memcpy_s( + void *dest, + size_t numberOfElements, + const void *src, + size_t count) +{ + if(numberOfElementss[sizeof(p_shared_key->s) - 1 - i]; + } + + sample_ret = sample_sha256_init(&sha_context); + if (sample_ret != SAMPLE_SUCCESS) + { + return false; + } + sample_ret = sample_sha256_update((uint8_t*)&hash_buffer, sizeof(hash_buffer_t), sha_context); + if (sample_ret != SAMPLE_SUCCESS) + { + sample_sha256_close(sha_context); + return false; + } + sample_ret = sample_sha256_update((uint8_t*)ID_U, sizeof(ID_U), sha_context); + if (sample_ret != SAMPLE_SUCCESS) + { + sample_sha256_close(sha_context); + return false; + } + sample_ret = sample_sha256_update((uint8_t*)ID_V, sizeof(ID_V), sha_context); + if (sample_ret != SAMPLE_SUCCESS) + { + sample_sha256_close(sha_context); + return false; + } + sample_ret = sample_sha256_get_hash(sha_context, &key_material); + if (sample_ret != SAMPLE_SUCCESS) + { + sample_sha256_close(sha_context); + return false; + } + sample_ret = sample_sha256_close(sha_context); + + static_assert(sizeof(sample_ec_key_128bit_t)* 2 == sizeof(sample_sha256_hash_t), "structure size mismatch."); + memcpy(first_derived_key, &key_material, sizeof(sample_ec_key_128bit_t)); + memcpy(second_derived_key, (uint8_t*)&key_material + sizeof(sample_ec_key_128bit_t), sizeof(sample_ec_key_128bit_t)); + + // memset here can be optimized away by compiler, so please use memset_s on + // windows for production code and similar functions on other OSes. + memset(&key_material, 0, sizeof(sample_sha256_hash_t)); + + return true; +} + +#else + +#pragma message ("Default key derivation function is used.") + +#define EC_DERIVATION_BUFFER_SIZE(label_length) ((label_length) +4) + +const char str_SMK[] = "SMK"; +const char str_SK[] = "SK"; +const char str_MK[] = "MK"; +const char str_VK[] = "VK"; + +// Derive key from shared key and key id. +// key id should be sample_derive_key_type_t. +bool derive_key( + const sample_ec_dh_shared_t *p_shared_key, + uint8_t key_id, + sample_ec_key_128bit_t* derived_key) +{ + sample_status_t sample_ret = SAMPLE_SUCCESS; + uint8_t cmac_key[MAC_KEY_SIZE]; + sample_ec_key_128bit_t key_derive_key; + + memset(&cmac_key, 0, MAC_KEY_SIZE); + + sample_ret = sample_rijndael128_cmac_msg( + (sample_cmac_128bit_key_t *)&cmac_key, + (uint8_t*)p_shared_key, + sizeof(sample_ec_dh_shared_t), + (sample_cmac_128bit_tag_t *)&key_derive_key); + if (sample_ret != SAMPLE_SUCCESS) + { + // memset here can be optimized away by compiler, so please use memset_s on + // windows for production code and similar functions on other OSes. + memset(&key_derive_key, 0, sizeof(key_derive_key)); + return false; + } + + const char *label = NULL; + uint32_t label_length = 0; + switch (key_id) + { + case SAMPLE_DERIVE_KEY_SMK: + label = str_SMK; + label_length = sizeof(str_SMK) -1; + break; + case SAMPLE_DERIVE_KEY_SK: + label = str_SK; + label_length = sizeof(str_SK) -1; + break; + case SAMPLE_DERIVE_KEY_MK: + label = str_MK; + label_length = sizeof(str_MK) -1; + break; + case SAMPLE_DERIVE_KEY_VK: + label = str_VK; + label_length = sizeof(str_VK) -1; + break; + default: + // memset here can be optimized away by compiler, so please use memset_s on + // windows for production code and similar functions on other OSes. + memset(&key_derive_key, 0, sizeof(key_derive_key)); + return false; + break; + } + /* derivation_buffer = counter(0x01) || label || 0x00 || output_key_len(0x0080) */ + uint32_t derivation_buffer_length = EC_DERIVATION_BUFFER_SIZE(label_length); + uint8_t *p_derivation_buffer = (uint8_t *)malloc(derivation_buffer_length); + if (p_derivation_buffer == NULL) + { + // memset here can be optimized away by compiler, so please use memset_s on + // windows for production code and similar functions on other OSes. + memset(&key_derive_key, 0, sizeof(key_derive_key)); + return false; + } + memset(p_derivation_buffer, 0, derivation_buffer_length); + + /*counter = 0x01 */ + p_derivation_buffer[0] = 0x01; + /*label*/ + memcpy(&p_derivation_buffer[1], label, label_length); + /*output_key_len=0x0080*/ + uint16_t *key_len = (uint16_t *)(&(p_derivation_buffer[derivation_buffer_length - 2])); + *key_len = 0x0080; + + + sample_ret = sample_rijndael128_cmac_msg( + (sample_cmac_128bit_key_t *)&key_derive_key, + p_derivation_buffer, + derivation_buffer_length, + (sample_cmac_128bit_tag_t *)derived_key); + free(p_derivation_buffer); + // memset here can be optimized away by compiler, so please use memset_s on + // windows for production code and similar functions on other OSes. + memset(&key_derive_key, 0, sizeof(key_derive_key)); + if (sample_ret != SAMPLE_SUCCESS) + { + return false; + } + return true; +} +#endif \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/ecp.h b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/ecp.h new file mode 100644 index 0000000000..0a562b05f0 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/ecp.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _ECP_H +#define _ECP_H + +#include +#include + +#include "remote_attestation_result.h" + +#ifndef SAMPLE_FEBITSIZE + #define SAMPLE_FEBITSIZE 256 +#endif + +#define SAMPLE_ECP_KEY_SIZE (SAMPLE_FEBITSIZE/8) + +typedef struct sample_ec_priv_t +{ + uint8_t r[SAMPLE_ECP_KEY_SIZE]; +} sample_ec_priv_t; + +typedef struct sample_ec_dh_shared_t +{ + uint8_t s[SAMPLE_ECP_KEY_SIZE]; +}sample_ec_dh_shared_t; + +typedef uint8_t sample_ec_key_128bit_t[16]; + +#define SAMPLE_EC_MAC_SIZE 16 + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifndef _ERRNO_T_DEFINED +#define _ERRNO_T_DEFINED +typedef int errno_t; +#endif +errno_t memcpy_s(void *dest, size_t numberOfElements, const void *src, + size_t count); + + +#ifdef SUPPLIED_KEY_DERIVATION + +typedef enum _sample_derive_key_type_t +{ + SAMPLE_DERIVE_KEY_SMK_SK = 0, + SAMPLE_DERIVE_KEY_MK_VK, +} sample_derive_key_type_t; + +bool derive_key( + const sample_ec_dh_shared_t *p_shared_key, + uint8_t key_id, + sample_ec_key_128bit_t *first_derived_key, + sample_ec_key_128bit_t *second_derived_key); + +#else + +typedef enum _sample_derive_key_type_t +{ + SAMPLE_DERIVE_KEY_SMK = 0, + SAMPLE_DERIVE_KEY_SK, + SAMPLE_DERIVE_KEY_MK, + SAMPLE_DERIVE_KEY_VK, +} sample_derive_key_type_t; + +bool derive_key( + const sample_ec_dh_shared_t *p_shared_key, + uint8_t key_id, + sample_ec_key_128bit_t *derived_key); + +#endif + +bool verify_cmac128( + sample_ec_key_128bit_t mac_key, + const uint8_t *p_data_buf, + uint32_t buf_size, + const uint8_t *p_mac_buf); +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/ias_ra.cpp b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/ias_ra.cpp new file mode 100644 index 0000000000..ec6f52f769 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/ias_ra.cpp @@ -0,0 +1,254 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#include "service_provider.h" +#include "sample_libcrypto.h" +#include "ecp.h" +#include +#include +#include +#include +#include +#include "ias_ra.h" + +//This whole file is used as simulation of the interfaces to be +// delivered an attestation server. + + +#define UNUSED(expr) do { (void)(expr); } while (0) + +#if !defined(SWAP_ENDIAN_DW) + #define SWAP_ENDIAN_DW(dw) ((((dw) & 0x000000ff) << 24) \ + | (((dw) & 0x0000ff00) << 8) \ + | (((dw) & 0x00ff0000) >> 8) \ + | (((dw) & 0xff000000) >> 24)) +#endif +#if !defined(SWAP_ENDIAN_32B) + #define SWAP_ENDIAN_32B(ptr) \ +{\ + unsigned int temp = 0; \ + temp = SWAP_ENDIAN_DW(((unsigned int*)(ptr))[0]); \ + ((unsigned int*)(ptr))[0] = SWAP_ENDIAN_DW(((unsigned int*)(ptr))[7]); \ + ((unsigned int*)(ptr))[7] = temp; \ + temp = SWAP_ENDIAN_DW(((unsigned int*)(ptr))[1]); \ + ((unsigned int*)(ptr))[1] = SWAP_ENDIAN_DW(((unsigned int*)(ptr))[6]); \ + ((unsigned int*)(ptr))[6] = temp; \ + temp = SWAP_ENDIAN_DW(((unsigned int*)(ptr))[2]); \ + ((unsigned int*)(ptr))[2] = SWAP_ENDIAN_DW(((unsigned int*)(ptr))[5]); \ + ((unsigned int*)(ptr))[5] = temp; \ + temp = SWAP_ENDIAN_DW(((unsigned int*)(ptr))[3]); \ + ((unsigned int*)(ptr))[3] = SWAP_ENDIAN_DW(((unsigned int*)(ptr))[4]); \ + ((unsigned int*)(ptr))[4] = temp; \ +} +#endif + +// This is the ECDSA NIST P-256 private key used to sign platform_info_blob. +// This private +// key and the public key in SDK untrusted KElibrary should be a temporary key +// pair. For production parts an attestation server will sign the platform_info_blob with the +// production private key and the SDK untrusted KE library will have the public +// key for verifcation. + +static const sample_ec256_private_t g_rk_priv_key = +{{ + 0x63,0x2c,0xd4,0x02,0x7a,0xdc,0x56,0xa5, + 0x59,0x6c,0x44,0x3e,0x43,0xca,0x4e,0x0b, + 0x58,0xcd,0x78,0xcb,0x3c,0x7e,0xd5,0xb9, + 0xf2,0x91,0x5b,0x39,0x0d,0xb3,0xb5,0xfb +}}; + +static sample_spid_t g_sim_spid = {"Service X"}; + + +// Simulates the attestation server function for verifying the quote produce by +// the ISV enclave. It doesn't decrypt or verify the quote in +// the simulation. Just produces the attestaion verification +// report with the platform info blob. +// +// @param p_isv_quote Pointer to the quote generated by the ISV +// enclave. +// @param pse_manifest Pointer to the PSE manifest if used. +// @param p_attestation_verification_report Pointer the outputed +// verification report. +// +// @return int + +int ias_verify_attestation_evidence( + sample_quote_t *p_isv_quote, + uint8_t* pse_manifest, + ias_att_report_t* p_attestation_verification_report) +{ + int ret = 0; + sample_ecc_state_handle_t ecc_state = NULL; + + //unused parameters + UNUSED(pse_manifest); + + if((NULL == p_isv_quote) || + (NULL == p_attestation_verification_report)) + { + return -1; + } + //Decrypt the Quote signature and verify. + + p_attestation_verification_report->id = 0x12345678; + p_attestation_verification_report->status = IAS_QUOTE_OK; + p_attestation_verification_report->revocation_reason = + IAS_REVOC_REASON_NONE; + p_attestation_verification_report->info_blob.sample_epid_group_status = + 0 << IAS_EPID_GROUP_STATUS_REVOKED_BIT_POS + | 0 << IAS_EPID_GROUP_STATUS_REKEY_AVAILABLE_BIT_POS; + p_attestation_verification_report->info_blob.sample_tcb_evaluation_status = + 0 << IAS_TCB_EVAL_STATUS_CPUSVN_OUT_OF_DATE_BIT_POS + | 0 << IAS_TCB_EVAL_STATUS_ISVSVN_OUT_OF_DATE_BIT_POS; + p_attestation_verification_report->info_blob.pse_evaluation_status = + 0 << IAS_PSE_EVAL_STATUS_ISVSVN_OUT_OF_DATE_BIT_POS + | 0 << IAS_PSE_EVAL_STATUS_EPID_GROUP_REVOKED_BIT_POS + | 0 << IAS_PSE_EVAL_STATUS_PSDASVN_OUT_OF_DATE_BIT_POS + | 0 << IAS_PSE_EVAL_STATUS_SIGRL_OUT_OF_DATE_BIT_POS + | 0 << IAS_PSE_EVAL_STATUS_PRIVRL_OUT_OF_DATE_BIT_POS; + memset(p_attestation_verification_report-> + info_blob.latest_equivalent_tcb_psvn, 0, PSVN_SIZE); + memset(p_attestation_verification_report->info_blob.latest_pse_isvsvn, + 0, ISVSVN_SIZE); + memset(p_attestation_verification_report->info_blob.latest_psda_svn, + 0, PSDA_SVN_SIZE); + memset(p_attestation_verification_report->info_blob.performance_rekey_gid, + 0, GID_SIZE); + + // @TODO: Product signing algorithm still TBD. May be RSA2048 signing. + // Generate the Service providers ECCDH key pair. + do { + ret = sample_ecc256_open_context(&ecc_state); + if (SAMPLE_SUCCESS != ret) { + fprintf(stderr, "\nError, cannot get ECC cotext in [%s].", + __FUNCTION__); + ret = -1; + break; + } + // Sign + ret = sample_ecdsa_sign( + (uint8_t *)&p_attestation_verification_report-> + info_blob.sample_epid_group_status, + sizeof(ias_platform_info_blob_t) - sizeof(sample_ec_sign256_t), + (sample_ec256_private_t *)&g_rk_priv_key, + (sample_ec256_signature_t *)&p_attestation_verification_report-> + info_blob.signature, + ecc_state); + if (SAMPLE_SUCCESS != ret) { + fprintf(stderr, "\nError, sign ga_gb fail in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + SWAP_ENDIAN_32B(p_attestation_verification_report-> + info_blob.signature.x); + SWAP_ENDIAN_32B(p_attestation_verification_report-> + info_blob.signature.y); + + }while (0); + if (ecc_state) { + sample_ecc256_close_context(ecc_state); + } + p_attestation_verification_report->pse_status = IAS_PSE_OK; + + // For now, don't simulate the policy reports. + p_attestation_verification_report->policy_report_size = 0; + return(ret); +} + + +// Simulates retrieving the SIGRL for upon the SP request. +// +// @param gid Group ID for the EPID key. +// @param p_sig_rl_size Pointer to the output value of the full +// SIGRL size in bytes. (including the +// signature). +// @param p_sig_rl Pointer to the output of the SIGRL. +// +// @return int + +int ias_get_sigrl( + const sample_epid_group_id_t gid, + uint32_t *p_sig_rl_size, + uint8_t **p_sig_rl) +{ + int ret = 0; + + UNUSED(gid); + + do { + + if (NULL == p_sig_rl || NULL == p_sig_rl_size) { + ret = -1; + break; + } + *p_sig_rl_size = 0; + *p_sig_rl = NULL; + // we should try to get sig_rl from an attestation server + break; + }while (0); + + return(ret); +} + + +// Used to simulate the enrollment function of an attestation server. It only +// gives back the SPID right now. In production, the enrollment +// occurs out of context from an attestation attempt and only +// occurs once. +// +// +// @param sp_credentials +// @param p_spid +// @param p_authentication_token +// +// @return int + +int ias_enroll( + int sp_credentials, + sample_spid_t *p_spid, + int *p_authentication_token) +{ + UNUSED(sp_credentials); + UNUSED(p_authentication_token); + + if (NULL != p_spid) { + memcpy_s(p_spid, sizeof(sample_spid_t), &g_sim_spid, + sizeof(sample_spid_t)); + } else { + return(1); + } + return(0); +} + + diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/ias_ra.h b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/ias_ra.h new file mode 100644 index 0000000000..a984d0f06e --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/ias_ra.h @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#ifndef _IAS_RA_H +#define _IAS_RA_H + +#include "ecp.h" + +typedef enum { + IAS_QUOTE_OK, + IAS_QUOTE_SIGNATURE_INVALID, + IAS_QUOTE_GROUP_REVOKED, + IAS_QUOTE_SIGNATURE_REVOKED, + IAS_QUOTE_KEY_REVOKED, + IAS_QUOTE_SIGRL_VERSION_MISMATCH, + IAS_QUOTE_GROUP_OUT_OF_DATE, +} ias_quote_status_t; + +// These status should align with the definition in IAS API spec(rev 0.6) +typedef enum { + IAS_PSE_OK, + IAS_PSE_DESC_TYPE_NOT_SUPPORTED, + IAS_PSE_ISVSVN_OUT_OF_DATE, + IAS_PSE_MISCSELECT_INVALID, + IAS_PSE_ATTRIBUTES_INVALID, + IAS_PSE_MRSIGNER_INVALID, + IAS_PS_HW_GID_REVOKED, + IAS_PS_HW_PRIVKEY_RLVER_MISMATCH, + IAS_PS_HW_SIG_RLVER_MISMATCH, + IAS_PS_HW_CA_ID_INVALID, + IAS_PS_HW_SEC_INFO_INVALID, + IAS_PS_HW_PSDA_SVN_OUT_OF_DATE, +} ias_pse_status_t; + +// Revocation Reasons from RFC5280 +typedef enum { + IAS_REVOC_REASON_NONE, + IAS_REVOC_REASON_KEY_COMPROMISE, + IAS_REVOC_REASON_CA_COMPROMISED, + IAS_REVOC_REASON_SUPERCEDED, + IAS_REVOC_REASON_CESSATION_OF_OPERATION, + IAS_REVOC_REASON_CERTIFICATE_HOLD, + IAS_REVOC_REASON_PRIVILEGE_WITHDRAWN, + IAS_REVOC_REASON_AA_COMPROMISE, +} ias_revoc_reason_t; + +// These status should align with the definition in IAS API spec(rev 0.6) +#define IAS_EPID_GROUP_STATUS_REVOKED_BIT_POS 0x00 +#define IAS_EPID_GROUP_STATUS_REKEY_AVAILABLE_BIT_POS 0x01 + +#define IAS_TCB_EVAL_STATUS_CPUSVN_OUT_OF_DATE_BIT_POS 0x00 +#define IAS_TCB_EVAL_STATUS_ISVSVN_OUT_OF_DATE_BIT_POS 0x01 + +#define IAS_PSE_EVAL_STATUS_ISVSVN_OUT_OF_DATE_BIT_POS 0x00 +#define IAS_PSE_EVAL_STATUS_EPID_GROUP_REVOKED_BIT_POS 0x01 +#define IAS_PSE_EVAL_STATUS_PSDASVN_OUT_OF_DATE_BIT_POS 0x02 +#define IAS_PSE_EVAL_STATUS_SIGRL_OUT_OF_DATE_BIT_POS 0x03 +#define IAS_PSE_EVAL_STATUS_PRIVRL_OUT_OF_DATE_BIT_POS 0x04 + +// These status should align with the definition in IAS API spec(rev 0.6) +#define ISVSVN_SIZE 2 +#define PSDA_SVN_SIZE 4 +#define GID_SIZE 4 +#define PSVN_SIZE 18 + +#define SAMPLE_HASH_SIZE 32 // SHA256 +#define SAMPLE_MAC_SIZE 16 // Message Authentication Code + // - 16 bytes + +#define SAMPLE_REPORT_DATA_SIZE 64 + +typedef uint8_t sample_measurement_t[SAMPLE_HASH_SIZE]; +typedef uint8_t sample_mac_t[SAMPLE_MAC_SIZE]; +typedef uint8_t sample_report_data_t[SAMPLE_REPORT_DATA_SIZE]; +typedef uint16_t sample_prod_id_t; + +#define SAMPLE_CPUSVN_SIZE 16 + +typedef uint8_t sample_cpu_svn_t[SAMPLE_CPUSVN_SIZE]; +typedef uint16_t sample_isv_svn_t; + +typedef struct sample_attributes_t +{ + uint64_t flags; + uint64_t xfrm; +} sample_attributes_t; + +typedef struct sample_report_body_t { + sample_cpu_svn_t cpu_svn; // ( 0) Security Version of the CPU + uint8_t reserved1[32]; // ( 16) + sample_attributes_t attributes; // ( 48) Any special Capabilities + // the Enclave possess + sample_measurement_t mr_enclave; // ( 64) The value of the enclave's + // ENCLAVE measurement + uint8_t reserved2[32]; // ( 96) + sample_measurement_t mr_signer; // (128) The value of the enclave's + // SIGNER measurement + uint8_t reserved3[32]; // (160) + sample_measurement_t mr_reserved1; // (192) + sample_measurement_t mr_reserved2; // (224) + sample_prod_id_t isv_prod_id; // (256) Product ID of the Enclave + sample_isv_svn_t isv_svn; // (258) Security Version of the + // Enclave + uint8_t reserved4[60]; // (260) + sample_report_data_t report_data; // (320) Data provided by the user +} sample_report_body_t; + +#pragma pack(push, 1) + + +// This is a context data structure used in SP side +// @TODO: Modify at production to use the values specified by the Production +// IAS API +typedef struct _ias_att_report_t +{ + uint32_t id; + ias_quote_status_t status; + uint32_t revocation_reason; + ias_platform_info_blob_t info_blob; + ias_pse_status_t pse_status; + uint32_t policy_report_size; + + uint8_t policy_report[];// IAS_Q: Why does it specify a + // list of reports? + + +} ias_att_report_t; + +typedef uint8_t sample_epid_group_id_t[4]; + +typedef struct sample_spid_t +{ + uint8_t id[16]; +} sample_spid_t; + +typedef struct sample_basename_t +{ + uint8_t name[32]; +} sample_basename_t; + + +typedef struct sample_quote_nonce_t +{ + uint8_t rand[16]; +} sample_quote_nonce_t; + +#define SAMPLE_QUOTE_UNLINKABLE_SIGNATURE 0 +#define SAMPLE_QUOTE_LINKABLE_SIGNATURE 1 + +typedef struct sample_quote_t { + uint16_t version; // 0 + uint16_t sign_type; // 2 + sample_epid_group_id_t epid_group_id; // 4 + sample_isv_svn_t qe_svn; // 8 + uint8_t reserved[6]; // 10 + sample_basename_t basename; // 16 + sample_report_body_t report_body; // 48 + uint32_t signature_len; // 432 + uint8_t signature[]; // 436 +} sample_quote_t; + +#pragma pack(pop) + +#ifdef __cplusplus +extern "C" { +#endif + +int ias_enroll(int sp_credentials, sample_spid_t* spid, + int* authentication_token); +int ias_get_sigrl(const sample_epid_group_id_t gid, uint32_t* p_sig_rl_size, + uint8_t** p_sig_rl); +int ias_verify_attestation_evidence(sample_quote_t* p_isv_quote, + uint8_t* pse_manifest, + ias_att_report_t* attestation_verification_report); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/network_ra.cpp b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/network_ra.cpp new file mode 100644 index 0000000000..f8ab863720 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/network_ra.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#include +#include +#include +#include "network_ra.h" +#include "service_provider.h" + + +// Used to send requests to the service provider sample. It +// simulates network communication between the ISV app and the +// ISV service provider. This would be modified in a real +// product to use the proper IP communication. +// +// @param server_url String name of the server URL +// @param p_req Pointer to the message to be sent. +// @param p_resp Pointer to a pointer of the response message. + +// @return int + +int ra_network_send_receive(const char *server_url, + const ra_samp_request_header_t *p_req, + ra_samp_response_header_t **p_resp) +{ + int ret = 0; + ra_samp_response_header_t* p_resp_msg; + + if((NULL == server_url) || + (NULL == p_req) || + (NULL == p_resp)) + { + return -1; + } + + switch(p_req->type) + { + + case TYPE_RA_MSG0: + ret = sp_ra_proc_msg0_req((const sample_ra_msg0_t*)((uint8_t*)p_req + + sizeof(ra_samp_request_header_t)), + p_req->size); + if (0 != ret) + { + fprintf(stderr, "\nError, call sp_ra_proc_msg1_req fail [%s].", + __FUNCTION__); + } + break; + + case TYPE_RA_MSG1: + ret = sp_ra_proc_msg1_req((const sample_ra_msg1_t*)((uint8_t*)p_req + + sizeof(ra_samp_request_header_t)), + p_req->size, + &p_resp_msg); + if(0 != ret) + { + fprintf(stderr, "\nError, call sp_ra_proc_msg1_req fail [%s].", + __FUNCTION__); + } + else + { + *p_resp = p_resp_msg; + } + break; + + case TYPE_RA_MSG3: + ret =sp_ra_proc_msg3_req((const sample_ra_msg3_t*)((uint8_t*)p_req + + sizeof(ra_samp_request_header_t)), + p_req->size, + &p_resp_msg); + if(0 != ret) + { + fprintf(stderr, "\nError, call sp_ra_proc_msg3_req fail [%s].", + __FUNCTION__); + } + else + { + *p_resp = p_resp_msg; + } + break; + + default: + ret = -1; + fprintf(stderr, "\nError, unknown ra message type. Type = %d [%s].", + p_req->type, __FUNCTION__); + break; + } + + return ret; +} + +// Used to free the response messages. In the sample code, the +// response messages are allocated by the SP code. +// +// +// @param resp Pointer to the response buffer to be freed. + +void ra_free_network_response_buffer(ra_samp_response_header_t *resp) +{ + if(resp!=NULL) + { + free(resp); + } +} diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/network_ra.h b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/network_ra.h new file mode 100644 index 0000000000..9091bfb67c --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/network_ra.h @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#ifndef _NETWORK_RA_H +#define _NETWORK_RA_H + + +/* Enum for all possible message types between the ISV app and + * the ISV SP. Requests and responses in the remote attestation + * sample. + */ +typedef enum _ra_msg_type_t +{ + TYPE_RA_MSG0, + TYPE_RA_MSG1, + TYPE_RA_MSG2, + TYPE_RA_MSG3, + TYPE_RA_ATT_RESULT, +}ra_msg_type_t; + +/* Enum for all possible message types between the SP and IAS. + * Network communication is not simulated in the remote + * attestation sample. Currently these aren't used. + */ +typedef enum _ias_msg_type_t +{ + TYPE_IAS_ENROLL, + TYPE_IAS_GET_SIGRL, + TYPE_IAS_SIGRL, + TYPE_IAS_ATT_EVIDENCE, + TYPE_IAS_ATT_RESULT, +}ias_msg_type_t; + +#pragma pack(1) +typedef struct _ra_samp_request_header_t{ + uint8_t type; /* set to one of ra_msg_type_t*/ + uint32_t size; /*size of request body*/ + uint8_t align[3]; + uint8_t body[]; +}ra_samp_request_header_t; + +typedef struct _ra_samp_response_header_t{ + uint8_t type; /* set to one of ra_msg_type_t*/ + uint8_t status[2]; + uint32_t size; /*size of the response body*/ + uint8_t align[1]; + uint8_t body[]; +}ra_samp_response_header_t; + +#pragma pack() + +#ifdef __cplusplus +extern "C" { +#endif + +int ra_network_send_receive(const char *server_url, + const ra_samp_request_header_t *req, + ra_samp_response_header_t **p_resp); +void ra_free_network_response_buffer(ra_samp_response_header_t *resp); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/remote_attestation_result.h b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/remote_attestation_result.h new file mode 100644 index 0000000000..86d1532b6d --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/remote_attestation_result.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _REMOTE_ATTESTATION_RESULT_H_ +#define _REMOTE_ATTESTATION_RESULT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define SAMPLE_MAC_SIZE 16 /* Message Authentication Code*/ + /* - 16 bytes*/ +typedef uint8_t sample_mac_t[SAMPLE_MAC_SIZE]; + +#ifndef SAMPLE_FEBITSIZE + #define SAMPLE_FEBITSIZE 256 +#endif + +#define SAMPLE_NISTP256_KEY_SIZE (SAMPLE_FEBITSIZE/ 8 /sizeof(uint32_t)) + +typedef struct sample_ec_sign256_t +{ + uint32_t x[SAMPLE_NISTP256_KEY_SIZE]; + uint32_t y[SAMPLE_NISTP256_KEY_SIZE]; +} sample_ec_sign256_t; + +#pragma pack(push,1) + +#define SAMPLE_SP_TAG_SIZE 16 + +typedef struct sp_aes_gcm_data_t { + uint32_t payload_size; /* 0: Size of the payload which is*/ + /* encrypted*/ + uint8_t reserved[12]; /* 4: Reserved bits*/ + uint8_t payload_tag[SAMPLE_SP_TAG_SIZE]; + /* 16: AES-GMAC of the plain text,*/ + /* payload, and the sizes*/ + uint8_t payload[]; /* 32: Ciphertext of the payload*/ + /* followed by the plain text*/ +} sp_aes_gcm_data_t; + + +#define ISVSVN_SIZE 2 +#define PSDA_SVN_SIZE 4 +#define GID_SIZE 4 +#define PSVN_SIZE 18 + +/* @TODO: Modify at production to use the values specified by an Production*/ +/* attestation server API*/ +typedef struct ias_platform_info_blob_t +{ + uint8_t sample_epid_group_status; + uint16_t sample_tcb_evaluation_status; + uint16_t pse_evaluation_status; + uint8_t latest_equivalent_tcb_psvn[PSVN_SIZE]; + uint8_t latest_pse_isvsvn[ISVSVN_SIZE]; + uint8_t latest_psda_svn[PSDA_SVN_SIZE]; + uint8_t performance_rekey_gid[GID_SIZE]; + sample_ec_sign256_t signature; +} ias_platform_info_blob_t; + + +typedef struct sample_ra_att_result_msg_t { + ias_platform_info_blob_t platform_info_blob; + sample_mac_t mac; /* mac_smk(attestation_status)*/ + sp_aes_gcm_data_t secret; +} sample_ra_att_result_msg_t; + +#pragma pack(pop) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/service_provider.cpp b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/service_provider.cpp new file mode 100644 index 0000000000..1db44c0a96 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/service_provider.cpp @@ -0,0 +1,738 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#include "service_provider.h" + +#include "sample_libcrypto.h" + +#include "ecp.h" + +#include +#include +#include +#include +#include +#include "ias_ra.h" + +#ifndef SAFE_FREE +#define SAFE_FREE(ptr) {if (NULL != (ptr)) {free(ptr); (ptr) = NULL;}} +#endif + +// This is supported extended epid group of SP. SP can support more than one +// extended epid group with different extended epid group id and credentials. +static const sample_extended_epid_group g_extended_epid_groups[] = { + { + 0, + ias_enroll, + ias_get_sigrl, + ias_verify_attestation_evidence + } +}; + +// This is the private EC key of SP, the corresponding public EC key is +// hard coded in isv_enclave. It is based on NIST P-256 curve. +static const sample_ec256_private_t g_sp_priv_key = { + { + 0x90, 0xe7, 0x6c, 0xbb, 0x2d, 0x52, 0xa1, 0xce, + 0x3b, 0x66, 0xde, 0x11, 0x43, 0x9c, 0x87, 0xec, + 0x1f, 0x86, 0x6a, 0x3b, 0x65, 0xb6, 0xae, 0xea, + 0xad, 0x57, 0x34, 0x53, 0xd1, 0x03, 0x8c, 0x01 + } +}; + +// This is the public EC key of SP, this key is hard coded in isv_enclave. +// It is based on NIST P-256 curve. Not used in the SP code. +static const sample_ec_pub_t g_sp_pub_key = { + { + 0x72, 0x12, 0x8a, 0x7a, 0x17, 0x52, 0x6e, 0xbf, + 0x85, 0xd0, 0x3a, 0x62, 0x37, 0x30, 0xae, 0xad, + 0x3e, 0x3d, 0xaa, 0xee, 0x9c, 0x60, 0x73, 0x1d, + 0xb0, 0x5b, 0xe8, 0x62, 0x1c, 0x4b, 0xeb, 0x38 + }, + { + 0xd4, 0x81, 0x40, 0xd9, 0x50, 0xe2, 0x57, 0x7b, + 0x26, 0xee, 0xb7, 0x41, 0xe7, 0xc6, 0x14, 0xe2, + 0x24, 0xb7, 0xbd, 0xc9, 0x03, 0xf2, 0x9a, 0x28, + 0xa8, 0x3c, 0xc8, 0x10, 0x11, 0x14, 0x5e, 0x06 + } +}; + +// This is a context data structure used on SP side +typedef struct _sp_db_item_t +{ + sample_ec_pub_t g_a; + sample_ec_pub_t g_b; + sample_ec_key_128bit_t vk_key;// Shared secret key for the REPORT_DATA + sample_ec_key_128bit_t mk_key;// Shared secret key for generating MAC's + sample_ec_key_128bit_t sk_key;// Shared secret key for encryption + sample_ec_key_128bit_t smk_key;// Used only for SIGMA protocol + sample_ec_priv_t b; + sample_ps_sec_prop_desc_t ps_sec_prop; +}sp_db_item_t; +static sp_db_item_t g_sp_db; + +static const sample_extended_epid_group* g_sp_extended_epid_group_id= NULL; +static bool g_is_sp_registered = false; +static int g_sp_credentials = 0; +static int g_authentication_token = 0; + +uint8_t g_secret[8] = {0,1,2,3,4,5,6,7}; + +sample_spid_t g_spid; + + +// Verify message 0 then configure extended epid group. +int sp_ra_proc_msg0_req(const sample_ra_msg0_t *p_msg0, + uint32_t msg0_size) +{ + int ret = -1; + + if (!p_msg0 || + (msg0_size != sizeof(sample_ra_msg0_t))) + { + return -1; + } + uint32_t extended_epid_group_id = p_msg0->extended_epid_group_id; + + // Check to see if we have registered with the attestation server yet? + if (!g_is_sp_registered || + (g_sp_extended_epid_group_id != NULL && g_sp_extended_epid_group_id->extended_epid_group_id != extended_epid_group_id)) + { + // Check to see if the extended_epid_group_id is supported? + ret = SP_UNSUPPORTED_EXTENDED_EPID_GROUP; + for (size_t i = 0; i < sizeof(g_extended_epid_groups) / sizeof(sample_extended_epid_group); i++) + { + if (g_extended_epid_groups[i].extended_epid_group_id == extended_epid_group_id) + { + g_sp_extended_epid_group_id = &(g_extended_epid_groups[i]); + // In the product, the SP will establish a mutually + // authenticated SSL channel. During the enrollment process, the ISV + // registers it exchanges TLS certs with attestation server and obtains an SPID and + // Report Key from the attestation server. + // For a product attestation server, enrollment is an offline process. See the 'on-boarding' + // documentation to get the information required. The enrollment process is + // simulated by a call in this sample. + ret = g_sp_extended_epid_group_id->enroll(g_sp_credentials, &g_spid, + &g_authentication_token); + if (0 != ret) + { + ret = SP_IAS_FAILED; + break; + } + + g_is_sp_registered = true; + ret = SP_OK; + break; + } + } + } + else + { + ret = SP_OK; + } + + return ret; +} + +// Verify message 1 then generate and return message 2 to isv. +int sp_ra_proc_msg1_req(const sample_ra_msg1_t *p_msg1, + uint32_t msg1_size, + ra_samp_response_header_t **pp_msg2) +{ + int ret = 0; + ra_samp_response_header_t* p_msg2_full = NULL; + sample_ra_msg2_t *p_msg2 = NULL; + sample_ecc_state_handle_t ecc_state = NULL; + sample_status_t sample_ret = SAMPLE_SUCCESS; + bool derive_ret = false; + + if(!p_msg1 || + !pp_msg2 || + (msg1_size != sizeof(sample_ra_msg1_t))) + { + return -1; + } + + // Check to see if we have registered? + if (!g_is_sp_registered) + { + return SP_UNSUPPORTED_EXTENDED_EPID_GROUP; + } + + do + { + // Get the sig_rl from attestation server using GID. + // GID is Base-16 encoded of EPID GID in little-endian format. + // In the product, the SP and attesation server uses an established channel for + // communication. + uint8_t* sig_rl; + uint32_t sig_rl_size = 0; + + // The product interface uses a REST based message to get the SigRL. + + ret = g_sp_extended_epid_group_id->get_sigrl(p_msg1->gid, &sig_rl_size, &sig_rl); + if(0 != ret) + { + fprintf(stderr, "\nError, ias_get_sigrl [%s].", __FUNCTION__); + ret = SP_IAS_FAILED; + break; + } + + // Need to save the client's public ECCDH key to local storage + if (memcpy_s(&g_sp_db.g_a, sizeof(g_sp_db.g_a), &p_msg1->g_a, + sizeof(p_msg1->g_a))) + { + fprintf(stderr, "\nError, cannot do memcpy in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + + // Generate the Service providers ECCDH key pair. + sample_ret = sample_ecc256_open_context(&ecc_state); + if(SAMPLE_SUCCESS != sample_ret) + { + fprintf(stderr, "\nError, cannot get ECC context in [%s].", + __FUNCTION__); + ret = -1; + break; + } + sample_ec256_public_t pub_key = {{0},{0}}; + sample_ec256_private_t priv_key = {{0}}; + sample_ret = sample_ecc256_create_key_pair(&priv_key, &pub_key, + ecc_state); + if(SAMPLE_SUCCESS != sample_ret) + { + fprintf(stderr, "\nError, cannot generate key pair in [%s].", + __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + + // Need to save the SP ECCDH key pair to local storage. + if(memcpy_s(&g_sp_db.b, sizeof(g_sp_db.b), &priv_key,sizeof(priv_key)) + || memcpy_s(&g_sp_db.g_b, sizeof(g_sp_db.g_b), + &pub_key,sizeof(pub_key))) + { + fprintf(stderr, "\nError, cannot do memcpy in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + + // Generate the client/SP shared secret + sample_ec_dh_shared_t dh_key = {{0}}; + sample_ret = sample_ecc256_compute_shared_dhkey(&priv_key, + (sample_ec256_public_t *)&p_msg1->g_a, + (sample_ec256_dh_shared_t *)&dh_key, + ecc_state); + if(SAMPLE_SUCCESS != sample_ret) + { + fprintf(stderr, "\nError, compute share key fail in [%s].", + __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + +#ifdef SUPPLIED_KEY_DERIVATION + + // smk is only needed for msg2 generation. + derive_ret = derive_key(&dh_key, SAMPLE_DERIVE_KEY_SMK_SK, + &g_sp_db.smk_key, &g_sp_db.sk_key); + if(derive_ret != true) + { + fprintf(stderr, "\nError, derive key fail in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + + // The rest of the keys are the shared secrets for future communication. + derive_ret = derive_key(&dh_key, SAMPLE_DERIVE_KEY_MK_VK, + &g_sp_db.mk_key, &g_sp_db.vk_key); + if(derive_ret != true) + { + fprintf(stderr, "\nError, derive key fail in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } +#else + // smk is only needed for msg2 generation. + derive_ret = derive_key(&dh_key, SAMPLE_DERIVE_KEY_SMK, + &g_sp_db.smk_key); + if(derive_ret != true) + { + fprintf(stderr, "\nError, derive key fail in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + + // The rest of the keys are the shared secrets for future communication. + derive_ret = derive_key(&dh_key, SAMPLE_DERIVE_KEY_MK, + &g_sp_db.mk_key); + if(derive_ret != true) + { + fprintf(stderr, "\nError, derive key fail in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + + derive_ret = derive_key(&dh_key, SAMPLE_DERIVE_KEY_SK, + &g_sp_db.sk_key); + if(derive_ret != true) + { + fprintf(stderr, "\nError, derive key fail in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + + derive_ret = derive_key(&dh_key, SAMPLE_DERIVE_KEY_VK, + &g_sp_db.vk_key); + if(derive_ret != true) + { + fprintf(stderr, "\nError, derive key fail in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } +#endif + + uint32_t msg2_size = sizeof(sample_ra_msg2_t) + sig_rl_size; + p_msg2_full = (ra_samp_response_header_t*)malloc(msg2_size + + sizeof(ra_samp_response_header_t)); + if(!p_msg2_full) + { + fprintf(stderr, "\nError, out of memory in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + memset(p_msg2_full, 0, msg2_size + sizeof(ra_samp_response_header_t)); + p_msg2_full->type = TYPE_RA_MSG2; + p_msg2_full->size = msg2_size; + // The simulated message2 always passes. This would need to be set + // accordingly in a real service provider implementation. + p_msg2_full->status[0] = 0; + p_msg2_full->status[1] = 0; + p_msg2 = (sample_ra_msg2_t *)p_msg2_full->body; + + // Assemble MSG2 + if(memcpy_s(&p_msg2->g_b, sizeof(p_msg2->g_b), &g_sp_db.g_b, + sizeof(g_sp_db.g_b)) || + memcpy_s(&p_msg2->spid, sizeof(sample_spid_t), + &g_spid, sizeof(g_spid))) + { + fprintf(stderr,"\nError, memcpy failed in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + + // The service provider is responsible for selecting the proper EPID + // signature type and to understand the implications of the choice! + p_msg2->quote_type = SAMPLE_QUOTE_LINKABLE_SIGNATURE; + +#ifdef SUPPLIED_KEY_DERIVATION +//isv defined key derivation function id +#define ISV_KDF_ID 2 + p_msg2->kdf_id = ISV_KDF_ID; +#else + p_msg2->kdf_id = SAMPLE_AES_CMAC_KDF_ID; +#endif + // Create gb_ga + sample_ec_pub_t gb_ga[2]; + if(memcpy_s(&gb_ga[0], sizeof(gb_ga[0]), &g_sp_db.g_b, + sizeof(g_sp_db.g_b)) + || memcpy_s(&gb_ga[1], sizeof(gb_ga[1]), &g_sp_db.g_a, + sizeof(g_sp_db.g_a))) + { + fprintf(stderr,"\nError, memcpy failed in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + + // Sign gb_ga + sample_ret = sample_ecdsa_sign((uint8_t *)&gb_ga, sizeof(gb_ga), + (sample_ec256_private_t *)&g_sp_priv_key, + (sample_ec256_signature_t *)&p_msg2->sign_gb_ga, + ecc_state); + if(SAMPLE_SUCCESS != sample_ret) + { + fprintf(stderr, "\nError, sign ga_gb fail in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + + // Generate the CMACsmk for gb||SPID||TYPE||KDF_ID||Sigsp(gb,ga) + uint8_t mac[SAMPLE_EC_MAC_SIZE] = {0}; + uint32_t cmac_size = offsetof(sample_ra_msg2_t, mac); + sample_ret = sample_rijndael128_cmac_msg(&g_sp_db.smk_key, + (uint8_t *)&p_msg2->g_b, cmac_size, &mac); + if(SAMPLE_SUCCESS != sample_ret) + { + fprintf(stderr, "\nError, cmac fail in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + if(memcpy_s(&p_msg2->mac, sizeof(p_msg2->mac), mac, sizeof(mac))) + { + fprintf(stderr,"\nError, memcpy failed in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + + if(memcpy_s(&p_msg2->sig_rl[0], sig_rl_size, sig_rl, sig_rl_size)) + { + fprintf(stderr,"\nError, memcpy failed in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + p_msg2->sig_rl_size = sig_rl_size; + + }while(0); + + if(ret) + { + *pp_msg2 = NULL; + SAFE_FREE(p_msg2_full); + } + else + { + // Freed by the network simulator in ra_free_network_response_buffer + *pp_msg2 = p_msg2_full; + } + + if(ecc_state) + { + sample_ecc256_close_context(ecc_state); + } + + return ret; +} + +// Process remote attestation message 3 +int sp_ra_proc_msg3_req(const sample_ra_msg3_t *p_msg3, + uint32_t msg3_size, + ra_samp_response_header_t **pp_att_result_msg) +{ + int ret = 0; + sample_status_t sample_ret = SAMPLE_SUCCESS; + const uint8_t *p_msg3_cmaced = NULL; + sample_quote_t *p_quote = NULL; + sample_sha_state_handle_t sha_handle = NULL; + sample_report_data_t report_data = {0}; + sample_ra_att_result_msg_t *p_att_result_msg = NULL; + ra_samp_response_header_t* p_att_result_msg_full = NULL; + uint32_t i; + + if((!p_msg3) || + (msg3_size < sizeof(sample_ra_msg3_t)) || + (!pp_att_result_msg)) + { + return SP_INTERNAL_ERROR; + } + + // Check to see if we have registered? + if (!g_is_sp_registered) + { + return SP_UNSUPPORTED_EXTENDED_EPID_GROUP; + } + do + { + // Compare g_a in message 3 with local g_a. + ret = memcmp(&g_sp_db.g_a, &p_msg3->g_a, sizeof(sample_ec_pub_t)); + if(ret) + { + fprintf(stderr, "\nError, g_a is not same [%s].", __FUNCTION__); + ret = SP_PROTOCOL_ERROR; + break; + } + //Make sure that msg3_size is bigger than sample_mac_t. + uint32_t mac_size = msg3_size - sizeof(sample_mac_t); + p_msg3_cmaced = reinterpret_cast(p_msg3); + p_msg3_cmaced += sizeof(sample_mac_t); + + // Verify the message mac using SMK + sample_cmac_128bit_tag_t mac = {0}; + sample_ret = sample_rijndael128_cmac_msg(&g_sp_db.smk_key, + p_msg3_cmaced, + mac_size, + &mac); + if(SAMPLE_SUCCESS != sample_ret) + { + fprintf(stderr, "\nError, cmac fail in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + // In real implementation, should use a time safe version of memcmp here, + // in order to avoid side channel attack. + ret = memcmp(&p_msg3->mac, mac, sizeof(mac)); + if(ret) + { + fprintf(stderr, "\nError, verify cmac fail [%s].", __FUNCTION__); + ret = SP_INTEGRITY_FAILED; + break; + } + + if(memcpy_s(&g_sp_db.ps_sec_prop, sizeof(g_sp_db.ps_sec_prop), + &p_msg3->ps_sec_prop, sizeof(p_msg3->ps_sec_prop))) + { + fprintf(stderr,"\nError, memcpy failed in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + + p_quote = (sample_quote_t *)p_msg3->quote; + + // Check the quote version if needed. Only check the Quote.version field if the enclave + // identity fields have changed or the size of the quote has changed. The version may + // change without affecting the legacy fields or size of the quote structure. + //if(p_quote->version < ACCEPTED_QUOTE_VERSION) + //{ + // fprintf(stderr,"\nError, quote version is too old.", __FUNCTION__); + // ret = SP_QUOTE_VERSION_ERROR; + // break; + //} + + // Verify the report_data in the Quote matches the expected value. + // The first 32 bytes of report_data are SHA256 HASH of {ga|gb|vk}. + // The second 32 bytes of report_data are set to zero. + sample_ret = sample_sha256_init(&sha_handle); + if(sample_ret != SAMPLE_SUCCESS) + { + fprintf(stderr,"\nError, init hash failed in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + sample_ret = sample_sha256_update((uint8_t *)&(g_sp_db.g_a), + sizeof(g_sp_db.g_a), sha_handle); + if(sample_ret != SAMPLE_SUCCESS) + { + fprintf(stderr,"\nError, udpate hash failed in [%s].", + __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + sample_ret = sample_sha256_update((uint8_t *)&(g_sp_db.g_b), + sizeof(g_sp_db.g_b), sha_handle); + if(sample_ret != SAMPLE_SUCCESS) + { + fprintf(stderr,"\nError, udpate hash failed in [%s].", + __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + sample_ret = sample_sha256_update((uint8_t *)&(g_sp_db.vk_key), + sizeof(g_sp_db.vk_key), sha_handle); + if(sample_ret != SAMPLE_SUCCESS) + { + fprintf(stderr,"\nError, udpate hash failed in [%s].", + __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + sample_ret = sample_sha256_get_hash(sha_handle, + (sample_sha256_hash_t *)&report_data); + if(sample_ret != SAMPLE_SUCCESS) + { + fprintf(stderr,"\nError, Get hash failed in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + ret = memcmp((uint8_t *)&report_data, + (uint8_t *)&(p_quote->report_body.report_data), + sizeof(report_data)); + if(ret) + { + fprintf(stderr, "\nError, verify hash fail [%s].", __FUNCTION__); + ret = SP_INTEGRITY_FAILED; + break; + } + + // Verify Enclave policy (an attestation server may provide an API for this if we + // registered an Enclave policy) + + // Verify quote with attestation server. + // In the product, an attestation server could use a REST message and JSON formatting to request + // attestation Quote verification. The sample only simulates this interface. + ias_att_report_t attestation_report = {0}; + ret = g_sp_extended_epid_group_id->verify_attestation_evidence(p_quote, NULL, + &attestation_report); + if(0 != ret) + { + ret = SP_IAS_FAILED; + break; + } + FILE* OUTPUT = stdout; + fprintf(OUTPUT, "\n\n\tAtestation Report:"); + fprintf(OUTPUT, "\n\tid: 0x%0x.", attestation_report.id); + fprintf(OUTPUT, "\n\tstatus: %d.", attestation_report.status); + fprintf(OUTPUT, "\n\trevocation_reason: %u.", + attestation_report.revocation_reason); + // attestation_report.info_blob; + fprintf(OUTPUT, "\n\tpse_status: %d.", attestation_report.pse_status); + // Note: This sample always assumes the PIB is sent by attestation server. In the product + // implementation, the attestation server could only send the PIB for certain attestation + // report statuses. A product SP implementation needs to handle cases + // where the PIB is zero length. + + // Respond the client with the results of the attestation. + uint32_t att_result_msg_size = sizeof(sample_ra_att_result_msg_t); + p_att_result_msg_full = + (ra_samp_response_header_t*)malloc(att_result_msg_size + + sizeof(ra_samp_response_header_t) + sizeof(g_secret)); + if(!p_att_result_msg_full) + { + fprintf(stderr, "\nError, out of memory in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + memset(p_att_result_msg_full, 0, att_result_msg_size + + sizeof(ra_samp_response_header_t) + sizeof(g_secret)); + p_att_result_msg_full->type = TYPE_RA_ATT_RESULT; + p_att_result_msg_full->size = att_result_msg_size; + if(IAS_QUOTE_OK != attestation_report.status) + { + p_att_result_msg_full->status[0] = 0xFF; + } + if(IAS_PSE_OK != attestation_report.pse_status) + { + p_att_result_msg_full->status[1] = 0xFF; + } + + p_att_result_msg = + (sample_ra_att_result_msg_t *)p_att_result_msg_full->body; + + // In a product implementation of attestation server, the HTTP response header itself could have + // an RK based signature that the service provider needs to check here. + + // The platform_info_blob signature will be verified by the client + // when sent. No need to have the Service Provider to check it. The SP + // should pass it down to the application for further analysis. + + fprintf(OUTPUT, "\n\n\tEnclave Report:"); + fprintf(OUTPUT, "\n\tSignature Type: 0x%x", p_quote->sign_type); + fprintf(OUTPUT, "\n\tSignature Basename: "); + for(i=0; ibasename.name) && p_quote->basename.name[i]; + i++) + { + fprintf(OUTPUT, "%c", p_quote->basename.name[i]); + } +#ifdef __x86_64__ + fprintf(OUTPUT, "\n\tattributes.flags: 0x%0lx", + p_quote->report_body.attributes.flags); + fprintf(OUTPUT, "\n\tattributes.xfrm: 0x%0lx", + p_quote->report_body.attributes.xfrm); +#else + fprintf(OUTPUT, "\n\tattributes.flags: 0x%0llx", + p_quote->report_body.attributes.flags); + fprintf(OUTPUT, "\n\tattributes.xfrm: 0x%0llx", + p_quote->report_body.attributes.xfrm); +#endif + fprintf(OUTPUT, "\n\tmr_enclave: "); + for(i=0;ireport_body.mr_enclave[i]); + + //fprintf(stderr, "%02x",p_quote->report_body.mr_enclave.m[i]); + + } + fprintf(OUTPUT, "\n\tmr_signer: "); + for(i=0;ireport_body.mr_signer[i]); + + //fprintf(stderr, "%02x",p_quote->report_body.mr_signer.m[i]); + + } + fprintf(OUTPUT, "\n\tisv_prod_id: 0x%0x", + p_quote->report_body.isv_prod_id); + fprintf(OUTPUT, "\n\tisv_svn: 0x%0x",p_quote->report_body.isv_svn); + fprintf(OUTPUT, "\n"); + + // A product service provider needs to verify that its enclave properties + // match what is expected. The SP needs to check these values before + // trusting the enclave. For the sample, we always pass the policy check. + // Attestation server only verifies the quote structure and signature. It does not + // check the identity of the enclave. + bool isv_policy_passed = true; + + // Assemble Attestation Result Message + // Note, this is a structure copy. We don't copy the policy reports + // right now. + p_att_result_msg->platform_info_blob = attestation_report.info_blob; + + // Generate mac based on the mk key. + mac_size = sizeof(ias_platform_info_blob_t); + sample_ret = sample_rijndael128_cmac_msg(&g_sp_db.mk_key, + (const uint8_t*)&p_att_result_msg->platform_info_blob, + mac_size, + &p_att_result_msg->mac); + if(SAMPLE_SUCCESS != sample_ret) + { + fprintf(stderr, "\nError, cmac fail in [%s].", __FUNCTION__); + ret = SP_INTERNAL_ERROR; + break; + } + + // Generate shared secret and encrypt it with SK, if attestation passed. + uint8_t aes_gcm_iv[SAMPLE_SP_IV_SIZE] = {0}; + p_att_result_msg->secret.payload_size = 8; + if((IAS_QUOTE_OK == attestation_report.status) && + (IAS_PSE_OK == attestation_report.pse_status) && + (isv_policy_passed == true)) + { + ret = sample_rijndael128GCM_encrypt(&g_sp_db.sk_key, + &g_secret[0], + p_att_result_msg->secret.payload_size, + p_att_result_msg->secret.payload, + &aes_gcm_iv[0], + SAMPLE_SP_IV_SIZE, + NULL, + 0, + &p_att_result_msg->secret.payload_tag); + } + }while(0); + + if(ret) + { + *pp_att_result_msg = NULL; + SAFE_FREE(p_att_result_msg_full); + } + else + { + // Freed by the network simulator in ra_free_network_response_buffer + *pp_att_result_msg = p_att_result_msg_full; + } + return ret; +} + + + + diff --git a/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/service_provider.h b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/service_provider.h new file mode 100644 index 0000000000..83a7522e07 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/RemoteAttestation/service_provider/service_provider.h @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#ifndef _SERVICE_PROVIDER_H +#define _SERVICE_PROVIDER_H + +#include "remote_attestation_result.h" +#include "ias_ra.h" +#include "network_ra.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + SP_OK, + SP_UNSUPPORTED_EXTENDED_EPID_GROUP, + SP_INTEGRITY_FAILED, + SP_QUOTE_VERIFICATION_FAILED, + SP_IAS_FAILED, + SP_INTERNAL_ERROR, + SP_PROTOCOL_ERROR, + SP_QUOTE_VERSION_ERROR, +} sp_ra_msg_status_t; + +#pragma pack(push,1) + +#define SAMPLE_SP_TAG_SIZE 16 +#define SAMPLE_SP_IV_SIZE 12 + +typedef struct sample_ec_pub_t +{ + uint8_t gx[SAMPLE_ECP_KEY_SIZE]; + uint8_t gy[SAMPLE_ECP_KEY_SIZE]; +} sample_ec_pub_t; + +/*fixed length to align with internal structure*/ +typedef struct sample_ps_sec_prop_desc_t +{ + uint8_t sample_ps_sec_prop_desc[256]; +} sample_ps_sec_prop_desc_t; + +#pragma pack(pop) + +typedef uint32_t sample_ra_context_t; + +typedef uint8_t sample_key_128bit_t[16]; + +typedef sample_key_128bit_t sample_ra_key_128_t; + +typedef struct sample_ra_msg0_t +{ + uint32_t extended_epid_group_id; +} sample_ra_msg0_t; + + +typedef struct sample_ra_msg1_t +{ + sample_ec_pub_t g_a; /* the Endian-ness of Ga is + Little-Endian*/ + sample_epid_group_id_t gid; /* the Endian-ness of GID is + Little-Endian*/ +} sample_ra_msg1_t; + +/*Key Derivation Function ID : 0x0001 AES-CMAC Entropy Extraction and Key Expansion*/ +const uint16_t SAMPLE_AES_CMAC_KDF_ID = 0x0001; + +typedef struct sample_ra_msg2_t +{ + sample_ec_pub_t g_b; /* the Endian-ness of Gb is + Little-Endian*/ + sample_spid_t spid; /* In little endian*/ + uint16_t quote_type; /* unlinkable Quote(0) or linkable Quote(0) in little endian*/ + uint16_t kdf_id; /* key derivation function id in little endian. + 0x0001 for AES-CMAC Entropy Extraction and Key Derivation */ + sample_ec_sign256_t sign_gb_ga; /* In little endian*/ + sample_mac_t mac; /* mac_smk(g_b||spid||quote_type|| + sign_gb_ga)*/ + uint32_t sig_rl_size; + uint8_t sig_rl[]; +} sample_ra_msg2_t; + +typedef struct sample_ra_msg3_t +{ + sample_mac_t mac; /* mac_smk(g_a||ps_sec_prop||quote)*/ + sample_ec_pub_t g_a; /* the Endian-ness of Ga is*/ + /* Little-Endian*/ + sample_ps_sec_prop_desc_t ps_sec_prop; + uint8_t quote[]; +} sample_ra_msg3_t; + +int sp_ra_proc_msg0_req(const sample_ra_msg0_t *p_msg0, + uint32_t msg0_size); + +int sp_ra_proc_msg1_req(const sample_ra_msg1_t *p_msg1, + uint32_t msg1_size, + ra_samp_response_header_t **pp_msg2); + +int sp_ra_proc_msg3_req(const sample_ra_msg3_t *p_msg3, + uint32_t msg3_size, + ra_samp_response_header_t **pp_att_result_msg); + +int sp_ra_free_msg2( + sample_ra_msg2_t *p_msg2); + + + +typedef int (*sample_enroll)(int sp_credentials, sample_spid_t* spid, + int* authentication_token); + +typedef int(*sample_get_sigrl)(const sample_epid_group_id_t gid, uint32_t* p_sig_rl_size, + uint8_t** p_sig_rl); + +typedef int(*sample_verify_attestation_evidence)(sample_quote_t* p_isv_quote, + uint8_t* pse_manifest, + ias_att_report_t* attestation_verification_report); + + +typedef struct sample_extended_epid_group +{ + uint32_t extended_epid_group_id; + sample_enroll enroll; + sample_get_sigrl get_sigrl; + sample_verify_attestation_evidence verify_attestation_evidence; +} sample_extended_epid_group; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/.cproject b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/.cproject new file mode 100644 index 0000000000..e685836b4d --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/.cproject @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/.project b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/.project new file mode 100644 index 0000000000..102c105873 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/.project @@ -0,0 +1,28 @@ + + + SampleEnclave + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.eclipse.cdt.core.ccnature + com.intel.sgx.sgxnature + + diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/App.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/App.cpp new file mode 100644 index 0000000000..0538d2d8f3 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/App.cpp @@ -0,0 +1,265 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include +#include +#include + +# include +# include +# define MAX_PATH FILENAME_MAX + +#include "sgx_urts.h" +#include "App.h" +#include "Enclave_u.h" + +/* Global EID shared by multiple threads */ +sgx_enclave_id_t global_eid = 0; + +typedef struct _sgx_errlist_t { + sgx_status_t err; + const char *msg; + const char *sug; /* Suggestion */ +} sgx_errlist_t; + +/* Error code returned by sgx_create_enclave */ +static sgx_errlist_t sgx_errlist[] = { + { + SGX_ERROR_UNEXPECTED, + "Unexpected error occurred.", + NULL + }, + { + SGX_ERROR_INVALID_PARAMETER, + "Invalid parameter.", + NULL + }, + { + SGX_ERROR_OUT_OF_MEMORY, + "Out of memory.", + NULL + }, + { + SGX_ERROR_ENCLAVE_LOST, + "Power transition occurred.", + "Please refer to the sample \"PowerTransition\" for details." + }, + { + SGX_ERROR_INVALID_ENCLAVE, + "Invalid enclave image.", + NULL + }, + { + SGX_ERROR_INVALID_ENCLAVE_ID, + "Invalid enclave identification.", + NULL + }, + { + SGX_ERROR_INVALID_SIGNATURE, + "Invalid enclave signature.", + NULL + }, + { + SGX_ERROR_OUT_OF_EPC, + "Out of EPC memory.", + NULL + }, + { + SGX_ERROR_NO_DEVICE, + "Invalid SGX device.", + "Please make sure SGX module is enabled in the BIOS, and install SGX driver afterwards." + }, + { + SGX_ERROR_MEMORY_MAP_CONFLICT, + "Memory map conflicted.", + NULL + }, + { + SGX_ERROR_INVALID_METADATA, + "Invalid enclave metadata.", + NULL + }, + { + SGX_ERROR_DEVICE_BUSY, + "SGX device was busy.", + NULL + }, + { + SGX_ERROR_INVALID_VERSION, + "Enclave version was invalid.", + NULL + }, + { + SGX_ERROR_INVALID_ATTRIBUTE, + "Enclave was not authorized.", + NULL + }, + { + SGX_ERROR_ENCLAVE_FILE_ACCESS, + "Can't open enclave file.", + NULL + }, +}; + +/* Check error conditions for loading enclave */ +void print_error_message(sgx_status_t ret) +{ + size_t idx = 0; + size_t ttl = sizeof sgx_errlist/sizeof sgx_errlist[0]; + + for (idx = 0; idx < ttl; idx++) { + if(ret == sgx_errlist[idx].err) { + if(NULL != sgx_errlist[idx].sug) + printf("Info: %s\n", sgx_errlist[idx].sug); + printf("Error: %s\n", sgx_errlist[idx].msg); + break; + } + } + + if (idx == ttl) + printf("Error: Unexpected error occurred.\n"); +} + +/* Initialize the enclave: + * Step 1: try to retrieve the launch token saved by last transaction + * Step 2: call sgx_create_enclave to initialize an enclave instance + * Step 3: save the launch token if it is updated + */ +int initialize_enclave(void) +{ + char token_path[MAX_PATH] = {'\0'}; + sgx_launch_token_t token = {0}; + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + int updated = 0; + + /* Step 1: try to retrieve the launch token saved by last transaction + * if there is no token, then create a new one. + */ + /* try to get the token saved in $HOME */ + const char *home_dir = getpwuid(getuid())->pw_dir; + + if (home_dir != NULL && + (strlen(home_dir)+strlen("/")+sizeof(TOKEN_FILENAME)+1) <= MAX_PATH) { + /* compose the token path */ + strncpy(token_path, home_dir, strlen(home_dir)); + strncat(token_path, "/", strlen("/")); + strncat(token_path, TOKEN_FILENAME, sizeof(TOKEN_FILENAME)+1); + } else { + /* if token path is too long or $HOME is NULL */ + strncpy(token_path, TOKEN_FILENAME, sizeof(TOKEN_FILENAME)); + } + + FILE *fp = fopen(token_path, "rb"); + if (fp == NULL && (fp = fopen(token_path, "wb")) == NULL) { + printf("Warning: Failed to create/open the launch token file \"%s\".\n", token_path); + } + + if (fp != NULL) { + /* read the token from saved file */ + size_t read_num = fread(token, 1, sizeof(sgx_launch_token_t), fp); + if (read_num != 0 && read_num != sizeof(sgx_launch_token_t)) { + /* if token is invalid, clear the buffer */ + memset(&token, 0x0, sizeof(sgx_launch_token_t)); + printf("Warning: Invalid launch token read from \"%s\".\n", token_path); + } + } + /* Step 2: call sgx_create_enclave to initialize an enclave instance */ + /* Debug Support: set 2nd parameter to 1 */ + ret = sgx_create_enclave(ENCLAVE_FILENAME, SGX_DEBUG_FLAG, &token, &updated, &global_eid, NULL); + if (ret != SGX_SUCCESS) { + print_error_message(ret); + if (fp != NULL) fclose(fp); + return -1; + } + + /* Step 3: save the launch token if it is updated */ + if (updated == FALSE || fp == NULL) { + /* if the token is not updated, or file handler is invalid, do not perform saving */ + if (fp != NULL) fclose(fp); + return 0; + } + + /* reopen the file with write capablity */ + fp = freopen(token_path, "wb", fp); + if (fp == NULL) return 0; + size_t write_num = fwrite(token, 1, sizeof(sgx_launch_token_t), fp); + if (write_num != sizeof(sgx_launch_token_t)) + printf("Warning: Failed to save launch token to \"%s\".\n", token_path); + fclose(fp); + return 0; +} + +/* OCall functions */ +void ocall_print_string(const char *str) +{ + /* Proxy/Bridge will check the length and null-terminate + * the input string to prevent buffer overflow. + */ + printf("%s", str); +} + + +/* Application entry */ +int SGX_CDECL main(int argc, char *argv[]) +{ + (void)(argc); + (void)(argv); + + + /* Initialize the enclave */ + if(initialize_enclave() < 0){ + printf("Enter a character before exit ...\n"); + getchar(); + return -1; + } + + /* Utilize edger8r attributes */ + edger8r_array_attributes(); + edger8r_pointer_attributes(); + edger8r_type_attributes(); + edger8r_function_attributes(); + + /* Utilize trusted libraries */ + ecall_libc_functions(); + ecall_libcxx_functions(); + ecall_thread_functions(); + + /* Destroy the enclave */ + sgx_destroy_enclave(global_eid); + + printf("Info: SampleEnclave successfully returned.\n"); + + printf("Enter a character before exit ...\n"); + getchar(); + return 0; +} + diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/App.h b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/App.h new file mode 100644 index 0000000000..bc86ff850f --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/App.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifndef _APP_H_ +#define _APP_H_ + +#include +#include +#include +#include + +#include "sgx_error.h" /* sgx_status_t */ +#include "sgx_eid.h" /* sgx_enclave_id_t */ + +#ifndef TRUE +# define TRUE 1 +#endif + +#ifndef FALSE +# define FALSE 0 +#endif + +# define TOKEN_FILENAME "enclave.token" +# define ENCLAVE_FILENAME "enclave.signed.so" + +extern sgx_enclave_id_t global_eid; /* global enclave id */ + +#if defined(__cplusplus) +extern "C" { +#endif + +void edger8r_array_attributes(void); +void edger8r_type_attributes(void); +void edger8r_pointer_attributes(void); +void edger8r_function_attributes(void); + +void ecall_libc_functions(void); +void ecall_libcxx_functions(void); +void ecall_thread_functions(void); + +#if defined(__cplusplus) +} +#endif + +#endif /* !_APP_H_ */ diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/Edger8rSyntax/Arrays.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/Edger8rSyntax/Arrays.cpp new file mode 100644 index 0000000000..01552eeffb --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/Edger8rSyntax/Arrays.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "../App.h" +#include "Enclave_u.h" + +/* edger8r_array_attributes: + * Invokes ECALLs declared with array attributes. + */ +void edger8r_array_attributes(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + /* user_check */ + int arr1[4] = {0, 1, 2, 3}; + ret = ecall_array_user_check(global_eid, arr1); + if (ret != SGX_SUCCESS) + abort(); + + /* make sure arr1 is changed */ + for (int i = 0; i < 4; i++) + assert(arr1[i] == (3 - i)); + + /* in */ + int arr2[4] = {0, 1, 2, 3}; + ret = ecall_array_in(global_eid, arr2); + if (ret != SGX_SUCCESS) + abort(); + + /* arr2 is not changed */ + for (int i = 0; i < 4; i++) + assert(arr2[i] == i); + + /* out */ + int arr3[4] = {0, 1, 2, 3}; + ret = ecall_array_out(global_eid, arr3); + if (ret != SGX_SUCCESS) + abort(); + + /* arr3 is changed */ + for (int i = 0; i < 4; i++) + assert(arr3[i] == (3 - i)); + + /* in, out */ + int arr4[4] = {0, 1, 2, 3}; + ret = ecall_array_in_out(global_eid, arr4); + if (ret != SGX_SUCCESS) + abort(); + + /* arr4 is changed */ + for (int i = 0; i < 4; i++) + assert(arr4[i] == (3 - i)); + + /* isary */ + array_t arr5 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + ret = ecall_array_isary(global_eid, arr5); + if (ret != SGX_SUCCESS) + abort(); + + /* arr5 is changed */ + for (int i = 0; i < 10; i++) + assert(arr5[i] == (9 - i)); +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/Edger8rSyntax/Functions.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/Edger8rSyntax/Functions.cpp new file mode 100644 index 0000000000..acc2ad2737 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/Edger8rSyntax/Functions.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "../App.h" +#include "Enclave_u.h" + +/* No need to implement memccpy here! */ + +/* edger8r_function_attributes: + * Invokes ECALL declared with calling convention attributes. + * Invokes ECALL declared with [public]. + */ +void edger8r_function_attributes(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + ret = ecall_function_calling_convs(global_eid); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_function_public(global_eid); + if (ret != SGX_SUCCESS) + abort(); + + /* user shall not invoke private function here */ + int runned = 0; + ret = ecall_function_private(global_eid, &runned); + if (ret != SGX_ERROR_ECALL_NOT_ALLOWED || runned != 0) + abort(); +} + +/* ocall_function_allow: + * The OCALL invokes the [allow]ed ECALL 'edger8r_private'. + */ +void ocall_function_allow(void) +{ + int runned = 0; + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + ret = ecall_function_private(global_eid, &runned); + if (ret != SGX_SUCCESS || runned != 1) + abort(); +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/Edger8rSyntax/Pointers.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/Edger8rSyntax/Pointers.cpp new file mode 100644 index 0000000000..2187a40dde --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/Edger8rSyntax/Pointers.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "../App.h" +#include "Enclave_u.h" + +/* edger8r_pointer_attributes: + * Invokes the ECALLs declared with pointer attributes. + */ +void edger8r_pointer_attributes(void) +{ + int val = 0; + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + char c[128] = {0}; + size_t len = 0; + memset(c, 0xe, 128); + ret = ecall_pointer_user_check(global_eid, &len, &c, 128); + if (ret != SGX_SUCCESS) + abort(); + assert(strcmp(c, "SGX_SUCCESS") == 0); + + + val = 0; + ret = ecall_pointer_in(global_eid, &val); + if (ret != SGX_SUCCESS) + abort(); + assert(val == 0); + + val = 0; + ret = ecall_pointer_out(global_eid, &val); + if (ret != SGX_SUCCESS) + abort(); + assert(val == 1234); + + val = 0; + ret = ecall_pointer_in_out(global_eid, &val); + if (ret != SGX_SUCCESS) + abort(); + assert(val == 1234); + + ret = ocall_pointer_attr(global_eid); + if (ret != SGX_SUCCESS) + abort(); + + char str1[] = "1234567890"; + ret = ecall_pointer_string(global_eid, str1); + if (ret != SGX_SUCCESS) + abort(); + assert(memcmp(str1, "0987654321", strlen(str1)) == 0); + + const char str2[] = "1234567890"; + ret = ecall_pointer_string_const(global_eid, str2); + if (ret != SGX_SUCCESS) + abort(); + assert(memcmp(str2, "1234567890", strlen(str2)) == 0); + + char str3[] = "1234567890"; + ret = ecall_pointer_size(global_eid, (void*)str3, strlen(str3)); + if (ret != SGX_SUCCESS) + abort(); + assert(memcmp(str3, "0987654321", strlen(str3)) == 0); + + char str4[] = "1234567890"; + ret = ecall_pointer_isptr_readonly(global_eid, (buffer_t)str4, strlen(str4)); + if (ret != SGX_SUCCESS) + abort(); + assert(memcmp(str4, "1234567890", strlen(str4)) == 0); + + int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + ret = ecall_pointer_count(global_eid, arr, 10); + if (ret != SGX_SUCCESS) + abort(); + + for (int i = 0; i < 10; i++) + assert(arr[i] == (9 - i)); + + memset(arr, 0x0, sizeof(arr)); + ret = ecall_pointer_sizefunc(global_eid, (char *)arr); + if (ret != SGX_SUCCESS) + abort(); + + for (int i = 0; i < 10; i++) + assert(arr[i] == i); + + return; +} + +/* ocall_pointer_user_check: + * The OCALL declared with [user_check]. + */ +void ocall_pointer_user_check(int* val) +{ + (void)val; + assert(val != NULL); +} + +/* ocall_pointer_in: + * The OCALL declared with [in]. + */ +void ocall_pointer_in(int* val) +{ + *val = 1234; +} + +/* ocall_pointer_out: + * The OCALL declared with [out]. + */ +void ocall_pointer_out(int* val) +{ + *val = 1234; +} + +/* ocall_pointer_in_out: + * The OCALL declared with [in, out]. + */ +void ocall_pointer_in_out(int* val) +{ + *val = 1234; +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/Edger8rSyntax/Types.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/Edger8rSyntax/Types.cpp new file mode 100644 index 0000000000..19702263dd --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/Edger8rSyntax/Types.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "../App.h" +#include "Enclave_u.h" + +/* edger8r_type_attributes: + * Invokes ECALLs declared with basic types. + */ +void edger8r_type_attributes(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + ret = ecall_type_char(global_eid, (char)0x12); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_type_int(global_eid, (int)1234); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_type_float(global_eid, (float)1234.0); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_type_double(global_eid, (double)1234.5678); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_type_size_t(global_eid, (size_t)12345678); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_type_wchar_t(global_eid, (wchar_t)0x1234); + if (ret != SGX_SUCCESS) + abort(); + + struct struct_foo_t g = {1234, 5678}; + ret = ecall_type_struct(global_eid, g); + if (ret != SGX_SUCCESS) + abort(); + + union union_foo_t val = {0}; + ret = ecall_type_enum_union(global_eid, ENUM_FOO_0, &val); + if (ret != SGX_SUCCESS) + abort(); + assert(val.union_foo_0 == 2); +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/TrustedLibrary/Libc.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/TrustedLibrary/Libc.cpp new file mode 100644 index 0000000000..29f0074669 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/TrustedLibrary/Libc.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "../App.h" +#include "Enclave_u.h" + +/* ecall_libc_functions: + * Invokes standard C functions. + */ +void ecall_libc_functions(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + ret = ecall_malloc_free(global_eid); + if (ret != SGX_SUCCESS) + abort(); + + int cpuid[4] = {0x1, 0x0, 0x0, 0x0}; + ret = ecall_sgx_cpuid(global_eid, cpuid, 0x0); + if (ret != SGX_SUCCESS) + abort(); +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/TrustedLibrary/Libcxx.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/TrustedLibrary/Libcxx.cpp new file mode 100644 index 0000000000..f6d567b98f --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/TrustedLibrary/Libcxx.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include "../App.h" +#include "Enclave_u.h" + +/* ecall_libcxx_functions: + * Invokes standard C++ functions. + */ +void ecall_libcxx_functions(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + ret = ecall_exception(global_eid); + if (ret != SGX_SUCCESS) + abort(); + + ret = ecall_map(global_eid); + if (ret != SGX_SUCCESS) + abort(); +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/TrustedLibrary/Thread.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/TrustedLibrary/Thread.cpp new file mode 100644 index 0000000000..ca28fe5ed8 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/App/TrustedLibrary/Thread.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include +#include +using namespace std; + +#include "../App.h" +#include "Enclave_u.h" + +static size_t counter = 0; + +void increase_counter(void) +{ + size_t cnr = 0; + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + ret = ecall_increase_counter(global_eid, &cnr); + if (cnr != 0) counter = cnr; + if (ret != SGX_SUCCESS) + abort(); +} + +void data_producer(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + ret = ecall_producer(global_eid); + if (ret != SGX_SUCCESS) + abort(); +} + +void data_consumer(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + ret = ecall_consumer(global_eid); + if (ret != SGX_SUCCESS) + abort(); +} + +/* ecall_thread_functions: + * Invokes thread functions including mutex, condition variable, etc. + */ +void ecall_thread_functions(void) +{ + thread adder1(increase_counter); + thread adder2(increase_counter); + thread adder3(increase_counter); + thread adder4(increase_counter); + + adder1.join(); + adder2.join(); + adder3.join(); + adder4.join(); + + assert(counter == 4*LOOPS_PER_THREAD); + + printf("Info: executing thread synchronization, please wait... \n"); + /* condition variable */ + thread consumer1(data_consumer); + thread producer0(data_producer); + thread consumer2(data_consumer); + thread consumer3(data_consumer); + thread consumer4(data_consumer); + + consumer1.join(); + consumer2.join(); + consumer3.join(); + consumer4.join(); + producer0.join(); +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Arrays.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Arrays.cpp new file mode 100644 index 0000000000..cd0718b5c0 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Arrays.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Test Array Attributes */ + +#include "sgx_trts.h" +#include "../Enclave.h" +#include "Enclave_t.h" + +/* ecall_array_user_check: + * [user_check] parameter does not perfrom copy operations. + */ +void ecall_array_user_check(int arr[4]) +{ + if (sgx_is_outside_enclave(arr, 4 * sizeof(int)) != 1) + abort(); + + for (int i = 0; i < 4; i++) { + assert(arr[i] == i); + arr[i] = 3 - i; + } +} + +/* ecall_array_in: + * arr[] is copied to trusted domain, but modified + * results will not be reflected to the untrusted side. + */ +void ecall_array_in(int arr[4]) +{ + for (int i = 0; i < 4; i++) { + assert(arr[i] == i); + arr[i] = (3 - i); + } +} + +/* ecall_array_out: + * arr[] is allocated inside the enclave, and it will be copied + * to the untrusted side + */ +void ecall_array_out(int arr[4]) +{ + for (int i = 0; i < 4; i++) { + /* arr is not copied from App */ + assert(arr[i] == 0); + arr[i] = (3 - i); + } +} + +/* ecall_array_in_out: + * arr[] will be allocated inside the enclave, content of arr[] will be copied either. + * After ECALL returns, the results will be copied to the outside. + */ +void ecall_array_in_out(int arr[4]) +{ + for (int i = 0; i < 4; i++) { + assert(arr[i] == i); + arr[i] = (3 - i); + } +} + +/* ecall_array_isary: + * [isary] tells Edger8r that user defined 'array_t' is an array type. + */ +void ecall_array_isary(array_t arr) +{ + if (sgx_is_outside_enclave(arr, sizeof(array_t)) != 1) + abort(); + + int n = sizeof(array_t)/sizeof(arr[0]); + for (int i = 0; i < n; i++) { + assert(arr[i] == i); + arr[i] = (n - 1 - i); + } +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Arrays.edl b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Arrays.edl new file mode 100644 index 0000000000..4d481fa197 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Arrays.edl @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Arrays.edl - Samples for array attributes. */ + +enclave { + + /* + * Only for fixed-size array (size is explicitly specified). + */ + + trusted { + + /* + * []: can be used to declare an array. + * [user_check]: + * pointer of the array won't be valified, and the buffer pointed by 'arr' + * is not copied into the enclave either. But enclave can modify the memory outside. + */ + + public void ecall_array_user_check([user_check] int arr[4]); + + /* + * [in]: + * buffer for the array will be allocated inside the enclave, + * content of the array will be copied into the new allocated memory inside. + * Any changes performed inside the enclave will not affect the array outside. + */ + + public void ecall_array_in([in] int arr[4]); + + /* + * [out]: + * buffer for the array will be allocated inside the enclave, + * but the content of the array won't be copied. After ECALL returns, + * the buffer inside the enclave will copied into outside array. + */ + + public void ecall_array_out([out] int arr[4]); + + /* + * [in, out]: + * buffer for the array will be allocated inside the enclave, + * the content of the array will be copied either. After ECALL returns, + * the buffer inside the enclave will by copied into outside array again. + */ + + public void ecall_array_in_out([in, out] int arr[4]); + + /* + * [isary]: + * tells Edger8r the user defined 'array_t' is an array type, 'arr' will be + * treated as a pointer, no memory copied either due to [user_check]. + * For OCALLs, 'arr' shall point to the memory outside the enclave. + */ + + public void ecall_array_isary([user_check, isary] array_t arr); + + }; + + untrusted { + + /* + * [user_check|in|out|in,out|isary] can also be used in OCALLs, refer to the "User Guide" for details. + */ + + }; + +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Functions.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Functions.cpp new file mode 100644 index 0000000000..e29739a21e --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Functions.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Test Calling Conventions */ + +#include +#include + +#include "../Enclave.h" +#include "Enclave_t.h" + +/* ecall_function_calling_convs: + * memccpy is defined in system C library. + */ +void ecall_function_calling_convs(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + char s1[] = "1234567890"; + char s2[] = "0987654321"; + + char buf[BUFSIZ] = {'\0'}; + memcpy(buf, s1, strlen(s1)); + + ret = memccpy(NULL, s1, s2, '\0', strlen(s1)); + + if (ret != SGX_SUCCESS) + abort(); + assert(memcmp(s1, s2, strlen(s1)) == 0); + + return; +} + +/* ecall_function_public: + * The public ECALL that invokes the OCALL 'ocall_function_allow'. + */ +void ecall_function_public(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + ret = ocall_function_allow(); + if (ret != SGX_SUCCESS) + abort(); + + return; +} + +/* ecall_function_private: + * The private ECALL that only can be invoked in the OCALL 'ocall_function_allow'. + */ +int ecall_function_private(void) +{ + return 1; +} + diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Functions.edl b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Functions.edl new file mode 100644 index 0000000000..ad9e1d995f --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Functions.edl @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Functions.edl - Samples for function attributes. */ + +enclave { + + /* + * Following keywords/attributes are supported for untrusted functions: + * cdecl, stdcall, fastcall, dllimport (only for Windows). + * [public] is only supported for the trusted functions. + * Trusted function will be treated as [private] w/o the [public]. + */ + + trusted { + + public void ecall_function_calling_convs(void); + + /* + * [public]: + * public ECALL can be called directly in App. + */ + + public void ecall_function_public(void); + + /* + * [private]: + * private ECALL cannot be called directly in App. + */ + + int ecall_function_private(void); + + }; + + untrusted { + + /* + * [cdecl]: + * tells edger8r the calling convention of the OCALLs is 'cdecl'. + * [dllimport]: + * indicats the OCALL is provided in DLLs. + * + * Note: memccpy() is provided by MS system DLL, we don't need to implement it in App side. + */ + + [cdecl, dllimport] void *memccpy([in, out, size=len] void *dest, [in, size=len] const void *src, int val, size_t len); + + /* + * [allow]: + * OCALL 'ocall_function_allow' can invoke ECALL 'ecall_function_private' in App side. + * + * Note: No ECALL can be called in OCALL w/o [allow]. + */ + + void ocall_function_allow(void) allow(ecall_function_private); + + }; + +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Pointers.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Pointers.cpp new file mode 100644 index 0000000000..6e027e9cd3 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Pointers.cpp @@ -0,0 +1,217 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Test Pointer Auttributes */ + +#include +#include + +#include "sgx_trts.h" +#include "../Enclave.h" +#include "Enclave_t.h" + +/* checksum_internal: + * get simple checksum of input buffer and length + */ +int32_t checksum_internal(char *buf, size_t count) +{ + register int32_t sum = 0; + int16_t *ptr = (int16_t *)buf; + + /* Main summing loop */ + while(count > 1) { + sum = sum + *ptr++; + count = count - 2; + } + + /* Add left-over byte, if any */ + if (count > 0) + sum = sum + *((char *)ptr); + + return ~sum; +} + +/* ecall_pointer_user_check, ecall_pointer_in, ecall_pointer_out, ecall_pointer_in_out: + * The root ECALLs to test [in], [out], [user_check] attributes. + */ +size_t ecall_pointer_user_check(void *val, size_t sz) +{ + /* check if the buffer is allocated outside */ + if (sgx_is_outside_enclave(val, sz) != 1) + abort(); + + char tmp[100] = {0}; + size_t len = sz>100?100:sz; + + /* copy the memory into the enclave to make sure 'val' + * is not being changed in checksum_internal() */ + memcpy(tmp, val, len); + + int32_t sum = checksum_internal((char *)tmp, len); + printf("Checksum(0x%p, %zu) = 0x%x\n", + val, len, (unsigned int)sum); + + /* modify outside memory directly */ + memcpy(val, "SGX_SUCCESS", len>12?12:len); + + return len; +} + +/* ecall_pointer_in: + * the buffer of val is copied to the enclave. + */ + +void ecall_pointer_in(int *val) +{ + if (sgx_is_within_enclave(val, sizeof(int)) != 1) + abort(); + *val = 1234; +} + +/* ecall_pointer_out: + * the buffer of val is copied to the untrusted side. + */ +void ecall_pointer_out(int *val) +{ + if (sgx_is_within_enclave(val, sizeof(int)) != 1) + abort(); + assert(*val == 0); + *val = 1234; +} + +/* ecall_pointer_in_out: + * the buffer of val is double-copied. + */ +void ecall_pointer_in_out(int *val) +{ + if (sgx_is_within_enclave(val, sizeof(int)) != 1) + abort(); + *val = 1234; +} + +/* ocall_pointer_attr: + * The root ECALL that test OCALL [in], [out], [user_check]. + */ +void ocall_pointer_attr(void) +{ + sgx_status_t ret = SGX_ERROR_UNEXPECTED; + + int val = 0; + ret = ocall_pointer_user_check(&val); + if (ret != SGX_SUCCESS) + abort(); + + val = 0; + ret = ocall_pointer_in(&val); + if (ret != SGX_SUCCESS) + abort(); + assert(val == 0); + + val = 0; + ret = ocall_pointer_out(&val); + if (ret != SGX_SUCCESS) + abort(); + assert(val == 1234); + + val = 0; + ret = ocall_pointer_in_out(&val); + if (ret != SGX_SUCCESS) + abort(); + assert(val == 1234); + + return; +} + +/* ecall_pointer_string: + * [string] defines a string. + */ +void ecall_pointer_string(char *str) +{ + strncpy(str, "0987654321", strlen(str)); +} + +/* ecall_pointer_string_const: + * const [string] defines a string that cannot be modified. + */ +void ecall_pointer_string_const(const char *str) +{ + char* temp = new char[strlen(str)]; + strncpy(temp, str, strlen(str)); + delete []temp; +} + +/* ecall_pointer_size: + * 'len' needs to be specified to tell Edger8r the length of 'str'. + */ +void ecall_pointer_size(void *ptr, size_t len) +{ + strncpy((char*)ptr, "0987654321", len); +} + +/* ecall_pointer_count: + * 'cnt' needs to be specified to tell Edger8r the number of elements in 'arr'. + */ +void ecall_pointer_count(int *arr, int cnt) +{ + for (int i = (cnt - 1); i >= 0; i--) + arr[i] = (cnt - 1 - i); +} + +/* ecall_pointer_isptr_readonly: + * 'buf' is user defined type, shall be tagged with [isptr]. + * if it's not writable, [readonly] shall be specified. + */ +void ecall_pointer_isptr_readonly(buffer_t buf, size_t len) +{ + strncpy((char*)buf, "0987654321", len); +} + +/* get_buffer_len: + * get the length of input buffer 'buf'. + */ +size_t get_buffer_len(const char* buf) +{ + (void)buf; + return 10*sizeof(int); +} + +/* ecall_pointer_sizefunc: + * call get_buffer_len to determin the length of 'buf'. + */ +void ecall_pointer_sizefunc(char *buf) +{ + int *tmp = (int*)buf; + for (int i = 0; i < 10; i++) { + assert(tmp[i] == 0); + tmp[i] = i; + } +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Pointers.edl b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Pointers.edl new file mode 100644 index 0000000000..cbbc960f38 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Pointers.edl @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Pointers.edl - Samples for pointer attributes. */ + +enclave { + + /* + * Following keywords/attributes are supported for pointers in Edger8r: + * in, out, user_check, + * string, wstring, + * const, size, count, sizefunc, isptr, readonly + */ + + trusted { + + /* + * [user_check]: + * the pointer won't be validated, and the buffer pointed by + * 'val' is not copied into the enclave either. But Enclave + * can modify the memory pointed by 'val'. + */ + + public size_t ecall_pointer_user_check([user_check] void *val, size_t sz); + + /* + * [in]: + * buffer with the same size will be allocated inside the enclave, + * content pointed by 'val' will be copied into the new allocated + * memory inside. Any changes performed inside the enclave will not + * affect the buffer outside. + */ + + public void ecall_pointer_in([in] int *val); + + /* + * [out]: + * buffer with the same size will be allocated inside the enclave, + * but the content pointed by 'val' won't be copied. But after return, + * the buffer inside the enclave will copied into outside 'val'. + */ + + public void ecall_pointer_out([out] int *val); + + /* + * [in, out]: + * buffer with the same size will be allocated inside the enclave, + * the content pointed by 'val' will be copied either. After return, + * the buffer inside the enclave will by copied into outside 'val' again. + */ + + public void ecall_pointer_in_out([in, out] int *val); + + /* + * [string]: + * the attribute tells Edger8r 'str' is NULL terminated string, so strlen + * will be used to count the length of buffer pointed by 'str'. + */ + + public void ecall_pointer_string([in, out, string] char *str); + + /* + * [const]: + * the attribute tells Edger8r the buffer pointed by 'str' cannot be modified, + * so users cannot decorate 'str' with [out] attribute anymore. + */ + + public void ecall_pointer_string_const([in, string] const char *str); + + /* + * [size]: + * the attribute tells Edger8r the length of buffer in byte pointed by 'ptr' + * (shall be copied or not). + * Note: Users shall not specify [size] on [string] parameters. + */ + + public void ecall_pointer_size([in, out, size=len] void *ptr, size_t len); + + /* + * [count]: + * the attribute tells Edger8r the number of integers to be copied from 'arr'. + */ + + public void ecall_pointer_count([in, out, count=cnt] int *arr, int cnt); + + /* + * [isptr]: + * tells Edger8r the user defined type is a pointer; + * [readonly]: + * forbids the buffer allocated inside the enclave to be copied back to App + * (cannot use with [out]). + */ + + public void ecall_pointer_isptr_readonly([in, isptr, readonly, size=len] buffer_t buf, size_t len); + + /* + * [sizefunc]: + * call a function to decide the size/length of the parameter; + * Note: + * User need to define and implement `get_buf_len' as: + * size_t get_buf_len(const char* buf); + */ + + public void ecall_pointer_sizefunc([sizefunc = get_buffer_len, in, out] char *buf); + + }; + + /* + * Users can define multiple trusted/untrusted blocks, + * edger8r will merged them into one trusted/untrusted block. + */ + trusted { + /* + * Test pointer attributes in OCALLs + */ + + public void ocall_pointer_attr(void); + + }; + + untrusted { + + /* + * [user_check]: + * the pointer won't be valified, and the buffer pointed by 'val' is not + * copied to outside buffer either. Besides 'App' cannot modify the memory + * pointer by 'val'. + */ + + void ocall_pointer_user_check([user_check] int *val); + + /* + * [in]: + * buffer with the same size will be allocated in 'App' side, the content + * pointed by 'val' will be copied into the new allocated memory outside. + * Any changes performed by 'App' will not affect the buffer pointed by 'val'. + */ + + void ocall_pointer_in([in] int *val); + + /* + * [out]: + * buffer with the same size will be allocated in 'App' side, the content + * pointed by 'val' won't be copied. But after return, the buffer outside + * will be copied into the enclave. + */ + + void ocall_pointer_out([out] int *val); + + /* + * [in, out]: + * buffer with the same size will be allocated in 'App' side, the content + * pointed by 'val' will be copied either. After return, the buffer outside + * will copied into the enclave. + */ + + void ocall_pointer_in_out([in, out] int *val); + + }; + +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Types.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Types.cpp new file mode 100644 index 0000000000..aba016a6d8 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Types.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Test Basic Types */ + +#include "sgx_trts.h" +#include "../Enclave.h" +#include "Enclave_t.h" +#include +#include + +/* used to eliminate `unused variable' warning */ +#define UNUSED(val) (void)(val) + +#define ULP 2 + +/* used to compare double variables in order to avoid compile warnings */ +bool almost_equal(double x, double y) +{ + /* the machine epsilon has to be scaled to the magnitude of the larger value + and multiplied by the desired precision in ULPs (units in the last place) */ + return std::abs(x-y) <= std::numeric_limits::epsilon() * std::abs(x+y) * ULP; +} + +/* used to compare double variables in order to avoid compile warnings */ +bool almost_equal(float x, float y) +{ + /* the machine epsilon has to be scaled to the magnitude of the larger value + and multiplied by the desired precision in ULPs (units in the last place) */ + return std::abs(x-y) <= std::numeric_limits::epsilon() * std::abs(x+y) * ULP; +} + +/* ecall_type_char: + * [char] value passed by App. + */ +void ecall_type_char(char val) +{ + assert(val == 0x12); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* ecall_type_int: + * [int] value passed by App. + */ +void ecall_type_int(int val) +{ + assert(val == 1234); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* ecall_type_float: + * [float] value passed by App. + */ +void ecall_type_float(float val) +{ + assert(almost_equal(val, (float)1234.0)); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* ecall_type_double: + * [double] value passed by App. + */ +void ecall_type_double(double val) +{ + assert(almost_equal(val, (double)1234.5678)); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* ecall_type_size_t: + * [size_t] value passed by App. + */ +void ecall_type_size_t(size_t val) +{ + assert(val == (size_t)12345678); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* ecall_type_wchar_t: + * [wchar_t] value passed by App. + */ +void ecall_type_wchar_t(wchar_t val) +{ + assert(val == (wchar_t)0x1234); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* ecall_type_struct: + * struct_foo_t is defined in EDL and can be used in ECALL. + */ +void ecall_type_struct(struct struct_foo_t val) +{ + assert(val.struct_foo_0 == 1234); + assert(val.struct_foo_1 == 5678); +#ifndef DEBUG + UNUSED(val); +#endif +} + +/* + * ecall_type_enum_union: + * enum_foo_t/union_foo_t is defined in EDL + * and can be used in ECALL. + */ +void ecall_type_enum_union(enum enum_foo_t val1, union union_foo_t *val2) +{ + if (sgx_is_outside_enclave(val2, sizeof(union union_foo_t)) != 1) + abort(); + val2->union_foo_0 = 1; + val2->union_foo_1 = 2; /* overwrite union_foo_0 */ + assert(val1 == ENUM_FOO_0); +#ifndef DEBUG + UNUSED(val1); +#endif +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Types.edl b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Types.edl new file mode 100644 index 0000000000..a23aed85ca --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Types.edl @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Types.edl - Samples for basic types. */ + +enclave { + + /* + * Following types can be supported in Edger8r: + * char, short, int, float, double, void, + * int8_t, int16_t, int32_t, int64_t, + * size_t, wchar_t, + * uint8_t, uint16_t, uint32_t, uint64_t, + * unsigned, struct, enum, union. + */ + + /* + * We will demo few types in ECALL functions, data + * types in OCALL functions can be handled either. + */ + + /* structure definition */ + struct struct_foo_t { + /* Basic types can be used in structure. */ + uint32_t struct_foo_0; + uint64_t struct_foo_1; + }; + + /* enum definition */ + enum enum_foo_t { + ENUM_FOO_0 = 0, + ENUM_FOO_1 = 1 + }; + + /* union definition */ + union union_foo_t { + uint32_t union_foo_0; + uint32_t union_foo_1; + uint64_t union_foo_3; + }; + + trusted { + + public void ecall_type_char(char val); + public void ecall_type_int(int val); + + public void ecall_type_float(float val); + public void ecall_type_double(double val); + + public void ecall_type_size_t(size_t val); + public void ecall_type_wchar_t(wchar_t val); + + public void ecall_type_struct(struct struct_foo_t val); + public void ecall_type_enum_union(enum enum_foo_t val1, [user_check] union union_foo_t *val2); + + /* for using user defined types, please refer to Pointers.edl, Arrays.edl. */ + }; + +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.config.xml b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.config.xml new file mode 100644 index 0000000000..c9533851cf --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.config.xml @@ -0,0 +1,11 @@ + + 0 + 0 + 0x40000 + 0x100000 + 10 + 1 + 0 + 0 + 0xFFFFFFFF + diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.cpp new file mode 100644 index 0000000000..94a3108c46 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include +#include /* vsnprintf */ + +#include "Enclave.h" +#include "Enclave_t.h" /* print_string */ + +/* + * printf: + * Invokes OCALL to display the enclave buffer to the terminal. + */ +void printf(const char *fmt, ...) +{ + char buf[BUFSIZ] = {'\0'}; + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, BUFSIZ, fmt, ap); + va_end(ap); + ocall_print_string(buf); +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.edl b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.edl new file mode 100644 index 0000000000..9e31bd2ce8 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.edl @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Enclave.edl - Top EDL file. */ + +enclave { + + include "user_types.h" /* buffer_t */ + + /* Import ECALL/OCALL from sub-directory EDLs. + * [from]: specifies the location of EDL file. + * [import]: specifies the functions to import, + * [*]: implies to import all functions. + */ + + from "Edger8rSyntax/Types.edl" import *; + from "Edger8rSyntax/Pointers.edl" import *; + from "Edger8rSyntax/Arrays.edl" import *; + from "Edger8rSyntax/Functions.edl" import *; + + from "TrustedLibrary/Libc.edl" import *; + from "TrustedLibrary/Libcxx.edl" import ecall_exception, ecall_map; + from "TrustedLibrary/Thread.edl" import *; + + /* + * ocall_print_string - invokes OCALL to display string buffer inside the enclave. + * [in]: copy the string buffer to App outside. + * [string]: specifies 'str' is a NULL terminated buffer. + */ + untrusted { + void ocall_print_string([in, string] const char *str); + }; + +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.h b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.h new file mode 100644 index 0000000000..6e4c09ee2c --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifndef _ENCLAVE_H_ +#define _ENCLAVE_H_ + +#include +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +void printf(const char *fmt, ...); + +#if defined(__cplusplus) +} +#endif + +#endif /* !_ENCLAVE_H_ */ diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.lds b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.lds new file mode 100644 index 0000000000..e3d9d0ee0d --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave.lds @@ -0,0 +1,9 @@ +enclave.so +{ + global: + g_global_data_sim; + g_global_data; + enclave_entry; + local: + *; +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave_private.pem b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave_private.pem new file mode 100644 index 0000000000..529d07be35 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/Enclave_private.pem @@ -0,0 +1,39 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIG4gIBAAKCAYEAroOogvsj/fZDZY8XFdkl6dJmky0lRvnWMmpeH41Bla6U1qLZ +AmZuyIF+mQC/cgojIsrBMzBxb1kKqzATF4+XwPwgKz7fmiddmHyYz2WDJfAjIveJ +ZjdMjM4+EytGlkkJ52T8V8ds0/L2qKexJ+NBLxkeQLfV8n1mIk7zX7jguwbCG1Pr +nEMdJ3Sew20vnje+RsngAzdPChoJpVsWi/K7cettX/tbnre1DL02GXc5qJoQYk7b +3zkmhz31TgFrd9VVtmUGyFXAysuSAb3EN+5VnHGr0xKkeg8utErea2FNtNIgua8H +ONfm9Eiyaav1SVKzPHlyqLtcdxH3I8Wg7yqMsaprZ1n5A1v/levxnL8+It02KseD +5HqV4rf/cImSlCt3lpRg8U5E1pyFQ2IVEC/XTDMiI3c+AR+w2jSRB3Bwn9zJtFlW +KHG3m1xGI4ck+Lci1JvWWLXQagQSPtZTsubxTQNx1gsgZhgv1JHVZMdbVlAbbRMC +1nSuJNl7KPAS/VfzAgEDAoIBgHRXxaynbVP5gkO0ug6Qw/E27wzIw4SmjsxG6Wpe +K7kfDeRskKxESdsA/xCrKkwGwhcx1iIgS5+Qscd1Yg+1D9X9asd/P7waPmWoZd+Z +AhlKwhdPsO7PiF3e1AzHhGQwsUTt/Y/aSI1MpHBvy2/s1h9mFCslOUxTmWw0oj/Q +ldIEgWeNR72CE2+jFIJIyml6ftnb6qzPiga8Bm48ubKh0kvySOqnkmnPzgh+JBD6 +JnBmtZbfPT97bwTT+N6rnPqOOApvfHPf15kWI8yDbprG1l4OCUaIUH1AszxLd826 +5IPM+8gINLRDP1MA6azECPjTyHXhtnSIBZCyWSVkc05vYmNXYUNiXWMajcxW9M02 +wKzFELO8NCEAkaTPxwo4SCyIjUxiK1LbQ9h8PSy4c1+gGP4LAMR8xqP4QKg6zdu9 +osUGG/xRe/uufgTBFkcjqBHtK5L5VI0jeNIUAgW/6iNbYXjBMJ0GfauLs+g1VsOm +WfdgXzsb9DYdMa0OXXHypmV4GwKBwQDUwQj8RKJ6c8cT4vcWCoJvJF00+RFL+P3i +Gx2DLERxRrDa8AVGfqaCjsR+3vLgG8V/py+z+dxZYSqeB80Qeo6PDITcRKoeAYh9 +xlT3LJOS+k1cJcEmlbbO2IjLkTmzSwa80fWexKu8/Xv6vv15gpqYl1ngYoqJM3pd +vzmTIOi7MKSZ0WmEQavrZj8zK4endE3v0eAEeQ55j1GImbypSf7Idh7wOXtjZ7WD +Dg6yWDrri+AP/L3gClMj8wsAxMV4ZR8CgcEA0fzDHkFa6raVOxWnObmRoDhAtE0a +cjUj976NM5yyfdf2MrKy4/RhdTiPZ6b08/lBC/+xRfV3xKVGzacm6QjqjZrUpgHC +0LKiZaMtccCJjLtPwQd0jGQEnKfMFaPsnhOc5y8qVkCzVOSthY5qhz0XNotHHFmJ +gffVgB0iqrMTvSL7IA2yqqpOqNRlhaYhNl8TiFP3gIeMtVa9rZy31JPgT2uJ+kfo +gV7sdTPEjPWZd7OshGxWpT6QfVDj/T9T7L6tAoHBAI3WBf2DFvxNL2KXT2QHAZ9t +k3imC4f7U+wSE6zILaDZyzygA4RUbwG0gv8/TJVn2P/Eynf76DuWHGlaiLWnCbSz +Az2DHBQBBaku409zDQym3j1ugMRjzzSQWzJg0SIyBH3hTmnYcn3+Uqcp/lEBvGW6 +O+rsXFt3pukqJmIV8HzLGGaLm62BHUeZf3dyWm+i3p/hQAL7Xvu04QW70xuGqdr5 +afV7p5eaeQIJXyGQJ0eylV/90+qxjMKiB1XYg6WYvwKBwQCL/ddpgOdHJGN8uRom +e7Zq0Csi3hGheMKlKbN3vcxT5U7MdyHtTZZOJbTvxKNNUNYH/8uD+PqDGNneb29G +BfGzvI3EASyLIcGZF3OhKwZd0jUrWk2y7Vhob91jwp2+t73vdMbkKyI4mHOuXvGv +fg95si9oO7EBT+Oqvhccd2J+F1IVXncccYnF4u5ZGWt5lLewN/pVr7MjjykeaHqN +t+rfnQam2psA6fL4zS2zTmZPzR2tnY8Y1GBTi0Ko1OKd1HMCgcAb5cB/7/AQlhP9 +yQa04PLH9ygQkKKptZp7dy5WcWRx0K/hAHRoi2aw1wZqfm7VBNu2SLcs90kCCCxp +6C5sfJi6b8NpNbIPC+sc9wsFr7pGo9SFzQ78UlcWYK2Gu2FxlMjonhka5hvo4zvg +WxlpXKEkaFt3gLd92m/dMqBrHfafH7VwOJY2zT3WIpjwuk0ZzmRg5p0pG/svVQEH +NZmwRwlopysbR69B/n1nefJ84UO50fLh5s5Zr3gBRwbWNZyzhXk= +-----END RSA PRIVATE KEY----- diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Libc.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Libc.cpp new file mode 100644 index 0000000000..b0e566ced1 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Libc.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include +#include + +#include "sgx_trts.h" +#include "../Enclave.h" +#include "Enclave_t.h" + +/* ecall_malloc_free: + * Uses malloc/free to allocate/free trusted memory. + */ +void ecall_malloc_free(void) +{ + void *ptr = malloc(100); + assert(ptr != NULL); + memset(ptr, 0x0, 100); + free(ptr); +} + +/* ecall_sgx_cpuid: + * Uses sgx_cpuid to get CPU features and types. + */ +void ecall_sgx_cpuid(int cpuinfo[4], int leaf) +{ + sgx_status_t ret = sgx_cpuid(cpuinfo, leaf); + if (ret != SGX_SUCCESS) + abort(); +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Libc.edl b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Libc.edl new file mode 100644 index 0000000000..9efe3219d4 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Libc.edl @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Libc.edl - EDL sample for trusted C library. */ + +enclave { + + from "sgx_tstdc.edl" import sgx_oc_cpuidex; + + /* + * A subset of the C99 standard is supported as well as SGX customized functions: + * sgx_cpuid, etc. + */ + + trusted { + /* + * Utilize malloc/free in enclave. + */ + public void ecall_malloc_free(void); + + /* + * Utilize SGX version __cpuid() in enclave. + */ + public void ecall_sgx_cpuid([in, out] int cpuinfo[4], int leaf); + }; +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Libcxx.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Libcxx.cpp new file mode 100644 index 0000000000..6f76646466 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Libcxx.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include +#include + +#include "../Enclave.h" +#include "Enclave_t.h" + +/* + * ecall_exception: + * throw/catch C++ exception inside the enclave. + */ + +void ecall_exception(void) +{ + std::string foo = "foo"; + try { + throw std::runtime_error(foo); + } + catch (std::runtime_error const& e) { + assert( foo == e.what() ); + std::runtime_error clone(""); + clone = e; + assert(foo == clone.what() ); + } + catch (...) { + assert( false ); + } +} + +#include +#include + +using namespace std; + +/* + * ecall_map: + * Utilize STL in the enclave. + */ +void ecall_map(void) +{ + typedef map > map_t; + typedef map_t::value_type map_value; + map_t m; + + m.insert(map_value('a', 1)); + m.insert(map_value('b', 2)); + m.insert(map_value('c', 3)); + m.insert(map_value('d', 4)); + + assert(m['a'] == 1); + assert(m['b'] == 2); + assert(m['c'] == 3); + assert(m['d'] == 4); + + assert(m.find('e') == m.end()); + + return; +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Libcxx.edl b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Libcxx.edl new file mode 100644 index 0000000000..49a8b8d9d9 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Libcxx.edl @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Libcxx.edl - EDL sample for trusted C++ library. */ + +enclave { + + /* + * A subset of the C++03 standard is supported. + */ + + trusted { + /* + * Throw/catch exception inside the enclave. + */ + public void ecall_exception(void); + + /* + * Utilize inside the enclave. + */ + public void ecall_map(void); + }; +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Thread.cpp b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Thread.cpp new file mode 100644 index 0000000000..d360d716a6 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Thread.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "../Enclave.h" +#include "Enclave_t.h" + +#include + +static size_t global_counter = 0; +static sgx_thread_mutex_t global_mutex = SGX_THREAD_MUTEX_INITIALIZER; + +#define BUFFER_SIZE 50 + +typedef struct { + int buf[BUFFER_SIZE]; + int occupied; + int nextin; + int nextout; + sgx_thread_mutex_t mutex; + sgx_thread_cond_t more; + sgx_thread_cond_t less; +} cond_buffer_t; + +static cond_buffer_t buffer = {{0, 0, 0, 0, 0, 0}, 0, 0, 0, + SGX_THREAD_MUTEX_INITIALIZER, SGX_THREAD_COND_INITIALIZER, SGX_THREAD_COND_INITIALIZER}; + +/* + * ecall_increase_counter: + * Utilize thread APIs inside the enclave. + */ +size_t ecall_increase_counter(void) +{ + size_t ret = 0; + for (int i = 0; i < LOOPS_PER_THREAD; i++) { + sgx_thread_mutex_lock(&global_mutex); + /* mutually exclusive adding */ + size_t tmp = global_counter; + global_counter = ++tmp; + if (4*LOOPS_PER_THREAD == global_counter) + ret = global_counter; + sgx_thread_mutex_unlock(&global_mutex); + } + return ret; +} + +void ecall_producer(void) +{ + for (int i = 0; i < 4*LOOPS_PER_THREAD; i++) { + cond_buffer_t *b = &buffer; + sgx_thread_mutex_lock(&b->mutex); + while (b->occupied >= BUFFER_SIZE) + sgx_thread_cond_wait(&b->less, &b->mutex); + b->buf[b->nextin] = b->nextin; + b->nextin++; + b->nextin %= BUFFER_SIZE; + b->occupied++; + sgx_thread_cond_signal(&b->more); + sgx_thread_mutex_unlock(&b->mutex); + } +} + +void ecall_consumer(void) +{ + for (int i = 0; i < LOOPS_PER_THREAD; i++) { + cond_buffer_t *b = &buffer; + sgx_thread_mutex_lock(&b->mutex); + while(b->occupied <= 0) + sgx_thread_cond_wait(&b->more, &b->mutex); + b->buf[b->nextout++] = 0; + b->nextout %= BUFFER_SIZE; + b->occupied--; + sgx_thread_cond_signal(&b->less); + sgx_thread_mutex_unlock(&b->mutex); + } +} diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Thread.edl b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Thread.edl new file mode 100644 index 0000000000..77ce461de4 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Enclave/TrustedLibrary/Thread.edl @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Thread.edl - EDL sample for trusted thread library. */ + +enclave { + + from "sgx_tstdc.edl" import sgx_thread_wait_untrusted_event_ocall, sgx_thread_set_untrusted_event_ocall, sgx_thread_setwait_untrusted_events_ocall, sgx_thread_set_multiple_untrusted_events_ocall; + + trusted { + /* + * Use SGX mutex. + */ + public size_t ecall_increase_counter(); + + /* + * Use SGX condition variables. + */ + public void ecall_producer(); + public void ecall_consumer(); + + }; +}; diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Include/user_types.h b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Include/user_types.h new file mode 100644 index 0000000000..00a9bed83f --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Include/user_types.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* User defined types */ + + +#define LOOPS_PER_THREAD 500 + +typedef void *buffer_t; +typedef int array_t[10]; + diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Makefile b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Makefile new file mode 100644 index 0000000000..aaa22052e6 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/Makefile @@ -0,0 +1,239 @@ +# +# Copyright (C) 2011-2016 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# + +######## SGX SDK Settings ######## + +SGX_SDK ?= /opt/intel/sgxsdk +SGX_MODE ?= HW +SGX_ARCH ?= x64 +SGX_DEBUG ?= 1 + +ifeq ($(shell getconf LONG_BIT), 32) + SGX_ARCH := x86 +else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) + SGX_ARCH := x86 +endif + +ifeq ($(SGX_ARCH), x86) + SGX_COMMON_CFLAGS := -m32 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r +else + SGX_COMMON_CFLAGS := -m64 + SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 + SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign + SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r +endif + +ifeq ($(SGX_DEBUG), 1) +ifeq ($(SGX_PRERELEASE), 1) +$(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) +endif +endif + +ifeq ($(SGX_DEBUG), 1) + SGX_COMMON_CFLAGS += -O0 -g +else + SGX_COMMON_CFLAGS += -O2 +endif + +######## App Settings ######## + +ifneq ($(SGX_MODE), HW) + Urts_Library_Name := sgx_urts_sim +else + Urts_Library_Name := sgx_urts +endif + +App_Cpp_Files := App/App.cpp $(wildcard App/Edger8rSyntax/*.cpp) $(wildcard App/TrustedLibrary/*.cpp) +App_Include_Paths := -IInclude -IApp -I$(SGX_SDK)/include + +App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) + +# Three configuration modes - Debug, prerelease, release +# Debug - Macro DEBUG enabled. +# Prerelease - Macro NDEBUG and EDEBUG enabled. +# Release - Macro NDEBUG enabled. +ifeq ($(SGX_DEBUG), 1) + App_C_Flags += -DDEBUG -UNDEBUG -UEDEBUG +else ifeq ($(SGX_PRERELEASE), 1) + App_C_Flags += -DNDEBUG -DEDEBUG -UDEBUG +else + App_C_Flags += -DNDEBUG -UEDEBUG -UDEBUG +endif + +App_Cpp_Flags := $(App_C_Flags) -std=c++11 +App_Link_Flags := $(SGX_COMMON_CFLAGS) -L$(SGX_LIBRARY_PATH) -l$(Urts_Library_Name) -lpthread + +ifneq ($(SGX_MODE), HW) + App_Link_Flags += -lsgx_uae_service_sim +else + App_Link_Flags += -lsgx_uae_service +endif + +App_Cpp_Objects := $(App_Cpp_Files:.cpp=.o) + +App_Name := app + +######## Enclave Settings ######## + +ifneq ($(SGX_MODE), HW) + Trts_Library_Name := sgx_trts_sim + Service_Library_Name := sgx_tservice_sim +else + Trts_Library_Name := sgx_trts + Service_Library_Name := sgx_tservice +endif +Crypto_Library_Name := sgx_tcrypto + +Enclave_Cpp_Files := Enclave/Enclave.cpp $(wildcard Enclave/Edger8rSyntax/*.cpp) $(wildcard Enclave/TrustedLibrary/*.cpp) +Enclave_Include_Paths := -IInclude -IEnclave -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport + +Enclave_C_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $(Enclave_Include_Paths) +Enclave_Cpp_Flags := $(Enclave_C_Flags) -std=c++03 -nostdinc++ + +# To generate a proper enclave, it is recommended to follow below guideline to link the trusted libraries: +# 1. Link sgx_trts with the `--whole-archive' and `--no-whole-archive' options, +# so that the whole content of trts is included in the enclave. +# 2. For other libraries, you just need to pull the required symbols. +# Use `--start-group' and `--end-group' to link these libraries. +# Do NOT move the libraries linked with `--start-group' and `--end-group' within `--whole-archive' and `--no-whole-archive' options. +# Otherwise, you may get some undesirable errors. +Enclave_Link_Flags := $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \ + -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive \ + -Wl,--start-group -lsgx_tstdc -lsgx_tstdcxx -l$(Crypto_Library_Name) -l$(Service_Library_Name) -Wl,--end-group \ + -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \ + -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \ + -Wl,--defsym,__ImageBase=0 \ + -Wl,--version-script=Enclave/Enclave.lds + +Enclave_Cpp_Objects := $(Enclave_Cpp_Files:.cpp=.o) + +Enclave_Name := enclave.so +Signed_Enclave_Name := enclave.signed.so +Enclave_Config_File := Enclave/Enclave.config.xml + +ifeq ($(SGX_MODE), HW) +ifeq ($(SGX_DEBUG), 1) + Build_Mode = HW_DEBUG +else ifeq ($(SGX_PRERELEASE), 1) + Build_Mode = HW_PRERELEASE +else + Build_Mode = HW_RELEASE +endif +else +ifeq ($(SGX_DEBUG), 1) + Build_Mode = SIM_DEBUG +else ifeq ($(SGX_PRERELEASE), 1) + Build_Mode = SIM_PRERELEASE +else + Build_Mode = SIM_RELEASE +endif +endif + + +.PHONY: all run + +ifeq ($(Build_Mode), HW_RELEASE) +all: $(App_Name) $(Enclave_Name) + @echo "The project has been built in release hardware mode." + @echo "Please sign the $(Enclave_Name) first with your signing key before you run the $(App_Name) to launch and access the enclave." + @echo "To sign the enclave use the command:" + @echo " $(SGX_ENCLAVE_SIGNER) sign -key -enclave $(Enclave_Name) -out <$(Signed_Enclave_Name)> -config $(Enclave_Config_File)" + @echo "You can also sign the enclave using an external signing tool." + @echo "To build the project in simulation mode set SGX_MODE=SIM. To build the project in prerelease mode set SGX_PRERELEASE=1 and SGX_MODE=HW." +else +all: $(App_Name) $(Signed_Enclave_Name) +ifeq ($(Build_Mode), HW_DEBUG) + @echo "The project has been built in debug hardware mode." +else ifeq ($(Build_Mode), SIM_DEBUG) + @echo "The project has been built in debug simulation mode." +else ifeq ($(Build_Mode), HW_PRERELEASE) + @echo "The project has been built in pre-release hardware mode." +else ifeq ($(Build_Mode), SIM_PRERELEASE) + @echo "The project has been built in pre-release simulation mode." +else + @echo "The project has been built in release simulation mode." +endif +endif + +run: all +ifneq ($(Build_Mode), HW_RELEASE) + @$(CURDIR)/$(App_Name) + @echo "RUN => $(App_Name) [$(SGX_MODE)|$(SGX_ARCH), OK]" +endif + +######## App Objects ######## + +App/Enclave_u.c: $(SGX_EDGER8R) Enclave/Enclave.edl + @cd App && $(SGX_EDGER8R) --untrusted ../Enclave/Enclave.edl --search-path ../Enclave --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +App/Enclave_u.o: App/Enclave_u.c + @$(CC) $(App_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +App/%.o: App/%.cpp + @$(CXX) $(App_Cpp_Flags) -c $< -o $@ + @echo "CXX <= $<" + +$(App_Name): App/Enclave_u.o $(App_Cpp_Objects) + @$(CXX) $^ -o $@ $(App_Link_Flags) + @echo "LINK => $@" + + +######## Enclave Objects ######## + +Enclave/Enclave_t.c: $(SGX_EDGER8R) Enclave/Enclave.edl + @cd Enclave && $(SGX_EDGER8R) --trusted ../Enclave/Enclave.edl --search-path ../Enclave --search-path $(SGX_SDK)/include + @echo "GEN => $@" + +Enclave/Enclave_t.o: Enclave/Enclave_t.c + @$(CC) $(Enclave_C_Flags) -c $< -o $@ + @echo "CC <= $<" + +Enclave/%.o: Enclave/%.cpp + @$(CXX) $(Enclave_Cpp_Flags) -c $< -o $@ + @echo "CXX <= $<" + +$(Enclave_Name): Enclave/Enclave_t.o $(Enclave_Cpp_Objects) + @$(CXX) $^ -o $@ $(Enclave_Link_Flags) + @echo "LINK => $@" + +$(Signed_Enclave_Name): $(Enclave_Name) + @$(SGX_ENCLAVE_SIGNER) sign -key Enclave/Enclave_private.pem -enclave $(Enclave_Name) -out $@ -config $(Enclave_Config_File) + @echo "SIGN => $@" + +.PHONY: clean + +clean: + @rm -f $(App_Name) $(Enclave_Name) $(Signed_Enclave_Name) $(App_Cpp_Objects) App/Enclave_u.* $(Enclave_Cpp_Objects) Enclave/Enclave_t.* diff --git a/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/README.txt b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/README.txt new file mode 100644 index 0000000000..3ecd3c3ac3 --- /dev/null +++ b/sgx-jvm/linux-sgx/SampleCode/SampleEnclave/README.txt @@ -0,0 +1,30 @@ +------------------------ +Purpose of SampleEnclave +------------------------ +The project demonstrates several fundamental usages of Intel(R) Software Guard +Extensions (SGX) SDK: +- Initializing and destroying an enclave +- Creating ECALLs or OCALLs +- Calling trusted libraries inside the enclave + +------------------------------------ +How to Build/Execute the Sample Code +------------------------------------ +1. Install Intel(R) SGX SDK for Linux* OS +2. Build the project with the prepared Makefile: + a. Hardware Mode, Debug build: + $ make + b. Hardware Mode, Pre-release build: + $ make SGX_PRERELEASE=1 SGX_DEBUG=0 + c. Hardware Mode, Release build: + $ make SGX_DEBUG=0 + d. Simulation Mode, Debug build: + $ make SGX_MODE=SIM + e. Simulation Mode, Pre-release build: + $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0 + f. Simulation Mode, Release build: + $ make SGX_MODE=SIM SGX_DEBUG=0 +3. Execute the binary directly: + $ ./app +4. Remember to "make clean" before switching build mode + diff --git a/sgx-jvm/linux-sgx/build-scripts/enclave.lds b/sgx-jvm/linux-sgx/build-scripts/enclave.lds new file mode 100644 index 0000000000..975b185f3c --- /dev/null +++ b/sgx-jvm/linux-sgx/build-scripts/enclave.lds @@ -0,0 +1,9 @@ +{ +global: + enclave_entry; + g_global_data_sim; + g_peak_heap_used; + g_global_data; +local: + *; +}; diff --git a/sgx-jvm/linux-sgx/buildenv.mk b/sgx-jvm/linux-sgx/buildenv.mk new file mode 100644 index 0000000000..560e000ce0 --- /dev/null +++ b/sgx-jvm/linux-sgx/buildenv.mk @@ -0,0 +1,183 @@ +# +# Copyright (C) 2011-2016 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# + +# ----------------------------------------------------------------------------- +# Function : parent-dir +# Arguments: 1: path +# Returns : Parent dir or path of $1, with final separator removed. +# ----------------------------------------------------------------------------- +parent-dir = $(patsubst %/,%,$(dir $(1:%/=%))) + +# ----------------------------------------------------------------------------- +# Macro : my-dir +# Returns : the directory of the current Makefile +# Usage : $(my-dir) +# ----------------------------------------------------------------------------- +my-dir = $(realpath $(call parent-dir,$(lastword $(MAKEFILE_LIST)))) + + +ROOT_DIR := $(call my-dir) +COMMON_DIR := $(ROOT_DIR)/common +LINUX_EXTERNAL_DIR := $(ROOT_DIR)/external +LINUX_PSW_DIR := $(ROOT_DIR)/psw +LINUX_SDK_DIR := $(ROOT_DIR)/sdk +LINUX_UNITTESTS := $(ROOT_DIR)/unittests + + +CP := /bin/cp -f +MKDIR := mkdir -p +STRIP := strip +OBJCOPY := objcopy + +# clean the content of 'INCLUDE' - this variable will be set by vcvars32.bat +# thus it will cause build error when this variable is used by our Makefile, +# when compiling the code under Cygwin tainted by MSVC environment settings. +INCLUDE := + +# this will return the path to the file that included the buildenv.mk file +CUR_DIR := $(realpath $(call parent-dir,$(lastword $(wordlist 2,$(words $(MAKEFILE_LIST)),x $(MAKEFILE_LIST))))) + +# turn on stack protector for SDK +COMMON_FLAGS += -fstack-protector + +ifdef DEBUG + COMMON_FLAGS += -ggdb -DDEBUG -UNDEBUG + COMMON_FLAGS += -DSE_DEBUG_LEVEL=SE_TRACE_DEBUG +else + COMMON_FLAGS += -O2 -UDEBUG -DNDEBUG +endif + +ifdef SE_SIM + COMMON_FLAGS += -DSE_SIM +endif + +# turn on compiler warnings as much as possible +COMMON_FLAGS += -Wall -Wextra -Winit-self -Wpointer-arith -Wreturn-type \ + -Waddress -Wsequence-point -Wformat-security \ + -Wmissing-include-dirs -Wfloat-equal -Wundef -Wshadow \ + -Wcast-align -Wconversion -Wredundant-decls + +# additional warnings flags for C +CFLAGS += -Wjump-misses-init -Wstrict-prototypes -Wunsuffixed-float-constants + +# additional warnings flags for C++ +CXXFLAGS += -Wnon-virtual-dtor + +# for static_assert() +CXXFLAGS += -std=c++0x + +# Disable cxx11 abi +CXXFLAGS += -D_GLIBCXX_USE_CXX11_ABI=0 + +.DEFAULT_GOAL := all +# this turns off the RCS / SCCS implicit rules of GNU Make +% : RCS/%,v +% : RCS/% +% : %,v +% : s.% +% : SCCS/s.% + +# If a rule fails, delete $@. +.DELETE_ON_ERROR: + +HOST_FILE_PROGRAM := file + +UNAME := $(shell uname -m) +ifneq (,$(findstring 86,$(UNAME))) + HOST_ARCH := x86 + ifneq (,$(shell $(HOST_FILE_PROGRAM) -L $(SHELL) | grep 'x86[_-]64')) + HOST_ARCH := x86_64 + endif +else + $(info Unknown host CPU arhitecture $(UNAME)) + $(error Aborting) +endif + +BUILD_DIR := $(ROOT_DIR)/build/linux + +ifeq "$(findstring __INTEL_COMPILER, $(shell $(CC) -E -dM -xc /dev/null))" "__INTEL_COMPILER" + ifeq ($(shell test -f /usr/bin/dpkg; echo $$?), 0) + ADDED_INC := -I /usr/include/$(shell dpkg-architecture -qDEB_BUILD_MULTIARCH) + endif +endif + +ARCH := $(HOST_ARCH) +ifeq "$(findstring -m32, $(CXXFLAGS))" "-m32" + ARCH := x86 +endif + +ifeq ($(ARCH), x86) +COMMON_FLAGS += -DITT_ARCH_IA32 +else +COMMON_FLAGS += -DITT_ARCH_IA64 +endif + +CFLAGS += $(COMMON_FLAGS) +CXXFLAGS += $(COMMON_FLAGS) + +# Compiler and linker options for an Enclave +# +# We are using '--export-dynamic' so that `g_global_data_sim' etc. +# will be exported to dynamic symbol table. +# +# When `pie' is enabled, the linker (both BFD and Gold) under Ubuntu 14.04 +# will hide all symbols from dynamic symbol table even if they are marked +# as `global' in the LD version script. +ENCLAVE_CFLAGS = -ffreestanding -nostdinc -fvisibility=hidden -fpie +ENCLAVE_CXXFLAGS = $(ENCLAVE_CFLAGS) -nostdinc++ +ENCLAVE_LDFLAGS = -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \ + -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \ + -Wl,--defsym,__ImageBase=0 + + +# Choose to use the optimized libraries (IPP/String/Math) by default. +# Users could also use the non-optimized source code version by +# explicitly specifying 'USE_OPT_LIBS=0' +USE_OPT_LIBS ?= 1 + +ifeq ($(ARCH), x86_64) +IPP_SUBDIR = intel64 +else +IPP_SUBDIR = ia32 +endif + +ifneq ($(USE_OPT_LIBS), 0) + SGX_IPP_DIR := $(ROOT_DIR)/external/ippcp_internal + SGX_IPP_INC := $(SGX_IPP_DIR)/inc + IPP_LIBS_DIR := $(SGX_IPP_DIR)/lib/linux/$(IPP_SUBDIR) + LD_IPP := -lippcp -lippcore +else + SGX_IPP_DIR := $(ROOT_DIR)/external/crypto_px + SGX_IPP_INC := $(SGX_IPP_DIR)/include + IPP_LIBS_DIR := $(SGX_IPP_DIR) + LD_IPP := -lcrypto_px +endif + diff --git a/sgx-jvm/linux-sgx/common/inc/internal/ae_ipp.h b/sgx-jvm/linux-sgx/common/inc/internal/ae_ipp.h new file mode 100644 index 0000000000..3fad09cdff --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/ae_ipp.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifndef _AE_IPP_H +#define _AE_IPP_H + +#include "ippcore.h" +#include "ippcp.h" + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/arch.h b/sgx-jvm/linux-sgx/common/inc/internal/arch.h new file mode 100644 index 0000000000..624276e920 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/arch.h @@ -0,0 +1,298 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_ARCH_H_ +#define _SE_ARCH_H_ + +#include "inst.h" +#include "se_types.h" +#include "sgx_attributes.h" +#include "sgx_key.h" +#include "sgx_report.h" +#include "sgx_tcrypto.h" + +#define SE_PAGE_SIZE 0x1000 +#define TCS_SIZE SE_PAGE_SIZE + +#pragma pack(push, 1) + +#if !defined(__cplusplus) || defined(__INTEL_COMPILER) || (defined(SE_GNU) && !defined(__GXX_EXPERIMENTAL_CXX0X__)) +#define _ASSERT_CONCAT(a, b) a##b +#define ASSERT_CONCAT(a, b) _ASSERT_CONCAT(a, b) +#define se_static_assert(e) typedef char ASSERT_CONCAT(assert_line, __LINE__)[(e)?1:-1] +#else +#define se_static_assert(e) static_assert(e,#e) +#endif + +se_static_assert(sizeof(sgx_key_request_t) == 512); +se_static_assert(sizeof(sgx_target_info_t) == 512); + +/*SECS data structure*/ +typedef struct _secs_t +{ + uint64_t size; /* ( 0) Size of the enclave in bytes */ + PADDED_POINTER(void, base); /* ( 8) Base address of enclave */ + uint32_t ssa_frame_size; /* ( 16) size of 1 SSA frame in pages */ + sgx_misc_select_t misc_select; /* ( 20) Which fields defined in SSA.MISC */ +#define SECS_RESERVED1_LENGTH 24 + uint8_t reserved1[SECS_RESERVED1_LENGTH]; /* ( 24) reserved */ + sgx_attributes_t attributes; /* ( 48) ATTRIBUTES Flags Field */ + sgx_measurement_t mr_enclave; /* ( 64) Integrity Reg 0 - Enclave measurement */ +#define SECS_RESERVED2_LENGTH 32 + uint8_t reserved2[SECS_RESERVED2_LENGTH]; /* ( 96) reserved */ + sgx_measurement_t mr_signer; /* (128) Integrity Reg 1 - Enclave signing key */ +#define SECS_RESERVED3_LENGTH 96 + uint8_t reserved3[SECS_RESERVED3_LENGTH]; /* (160) reserved */ + sgx_prod_id_t isv_prod_id; /* (256) product ID of enclave */ + sgx_isv_svn_t isv_svn; /* (258) Security Version of the Enclave */ +#define SECS_RESERVED4_LENGTH 3836 + uint8_t reserved4[SECS_RESERVED4_LENGTH];/* (260) reserved */ +} secs_t; + +/* +TCS +flags definitions +*/ +#define DBGOPTIN 1 /* used by debugger */ + +typedef struct _tcs_t +{ + uint64_t reserved0; /* (0) */ + uint64_t flags; /* (8)bit 0: DBGOPTION */ + uint64_t ossa; /* (16)State Save Area */ + uint32_t cssa; /* (24)Current SSA slot */ + uint32_t nssa; /* (28)Number of SSA slots */ + uint64_t oentry; /* (32)Offset in enclave to which control is transferred on EENTER if enclave INACTIVE state */ + uint64_t reserved1; /* (40) */ + uint64_t ofs_base; /* (48)When added to the base address of the enclave, produces the base address FS segment inside the enclave */ + uint64_t ogs_base; /* (56)When added to the base address of the enclave, produces the base address GS segment inside the enclave */ + uint32_t ofs_limit; /* (64)Size to become the new FS limit in 32-bit mode */ + uint32_t ogs_limit; /* (68)Size to become the new GS limit in 32-bit mode */ +#define TCS_RESERVED_LENGTH 4024 + uint8_t reserved[TCS_RESERVED_LENGTH]; /* (72) */ +}tcs_t; + +se_static_assert(sizeof(tcs_t) == SE_PAGE_SIZE); + +/**************************************************************************** + * Definitions for SSA + ****************************************************************************/ +typedef struct _exit_info_t +{ + uint32_t vector:8; /* Exception number of exceptions reported inside enclave */ + uint32_t exit_type:3; /* 3: Hardware exceptions, 6: Software exceptions */ + uint32_t reserved:20; + uint32_t valid:1; /* 0: unsupported exceptions, 1: Supported exceptions */ +} exit_info_t; + +#define SE_VECTOR_DE 0 +#define SE_VECTOR_DB 1 +#define SE_VECTOR_BP 3 +#define SE_VECTOR_BR 5 +#define SE_VECTOR_UD 6 +#define SE_VECTOR_MF 16 +#define SE_VECTOR_AC 17 +#define SE_VECTOR_XM 19 + +typedef struct _ssa_gpr_t +{ + REGISTER( ax); /* (0) */ + REGISTER( cx); /* (8) */ + REGISTER( dx); /* (16) */ + REGISTER( bx); /* (24) */ + REGISTER( sp); /* (32) */ + REGISTER( bp); /* (40) */ + REGISTER( si); /* (48) */ + REGISTER( di); /* (56) */ + uint64_t r8; /* (64) */ + uint64_t r9; /* (72) */ + uint64_t r10; /* (80) */ + uint64_t r11; /* (88) */ + uint64_t r12; /* (96) */ + uint64_t r13; /* (104) */ + uint64_t r14; /* (112) */ + uint64_t r15; /* (120) */ + REGISTER(flags); /* (128) */ + REGISTER( ip); /* (136) */ + REGISTER( sp_u); /* (144) untrusted stack pointer. saved by EENTER */ + REGISTER( bp_u); /* (152) untrusted frame pointer. saved by EENTER */ + exit_info_t exit_info; /* (160) contain information for exits */ + uint32_t reserved; /* (164) padding to multiple of 8 bytes */ + uint64_t fs; /* (168) FS register */ + uint64_t gs; /* (176) GS register */ +} ssa_gpr_t; + +typedef uint64_t si_flags_t; + +#define SI_FLAG_NONE 0x0 +#define SI_FLAG_R 0x1 /* Read Access */ +#define SI_FLAG_W 0x2 /* Write Access */ +#define SI_FLAG_X 0x4 /* Execute Access */ +#define SI_FLAG_PT_LOW_BIT 0x8 /* PT low bit */ +#define SI_FLAG_PT_MASK (0xFF< +#include + +namespace { + template + void delete_ptrs_from_container(T& vec) + { + typename T::iterator iter = vec.begin(); + typename T::iterator end = vec.end(); + typename T::iterator this_iter; + + while (iter != end) + { + this_iter = iter; + ++iter; + delete *this_iter; + } + } + + /* Each pair is well-formed (p.first <= p.second) */ + template + bool is_overlap(const std::pair& p1, + const std::pair& p2) + { + assert(p1.first <= p1.second); + assert(p2.first <= p2.second); + + return ((p1.first <= p2.second) && (p2.first <= p1.second)); + } +} + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/cpuid.h b/sgx-jvm/linux-sgx/common/inc/internal/cpuid.h new file mode 100644 index 0000000000..b3ee8f5db9 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/cpuid.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _CPUID_H_ +#define _CPUID_H_ + +#include "linux/cpuid_gnu.h" + + +#endif /* _CPUID_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/internal/dh.h b/sgx-jvm/linux-sgx/common/inc/internal/dh.h new file mode 100644 index 0000000000..76c347f588 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/dh.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifndef _DH_H +#define _DH_H + +#include "utility.h" + +/*return true if encrypt message successfully */ +bool encrypt_msg(pse_message_t* pse_msg, uint8_t* data, sgx_key_128bit_t* authenticated_encryption_key); + +/*return true if decrypt message successfully */ +bool decrypt_msg(pse_message_t* pse_msg, uint8_t* data, sgx_key_128bit_t* authenticated_encryption_key); +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/driver_api.h b/sgx-jvm/linux-sgx/common/inc/internal/driver_api.h new file mode 100644 index 0000000000..c0e20232e7 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/driver_api.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _DRIVER_API_H_ +#define _DRIVER_API_H_ + +#include "arch.h" +#include "sgx_eid.h" + +/* +@enclave_id identify the unique enclave; +@start_addr is the linear address that driver allocate for app; +*/ +int create_enclave(secs_t *secs, sgx_enclave_id_t *enclave_id, void **start_addr); +/* +*@attr can be REMOVABLE +*/ +int add_enclave_page(sgx_enclave_id_t enclave_id, void *source, size_t offset, const sec_info_t &secinfo, uint32_t attr); +int init_enclave(sgx_enclave_id_t enclave_id, enclave_css_t *enclave_css, token_t *launch); +int destroy_enclave(sgx_enclave_id_t enclave_id); + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/ecp_interface.h b/sgx-jvm/linux-sgx/common/inc/internal/ecp_interface.h new file mode 100644 index 0000000000..d3b7515cd5 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/ecp_interface.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifndef _ECP_INTERFACE_H +#define _ECP_INTERFACE_H + +#include "sgx_ecp_types.h" +#include "sgx_tcrypto.h" + +//Key Derivation Function ID : 0x0001 AES-CMAC Entropy Extraction and Key Expansion +const uint16_t AES_CMAC_KDF_ID = 0x0001; + +sgx_status_t derive_key( + const sgx_ec256_dh_shared_t* shared_key, + const char* label, + uint32_t label_length, + sgx_ec_key_128bit_t* derived_key); + +#ifndef INTERNAL_SGX_ERROR_CODE_CONVERTOR +#define INTERNAL_SGX_ERROR_CODE_CONVERTOR(x) if(x != SGX_ERROR_OUT_OF_MEMORY){x = SGX_ERROR_UNEXPECTED;} +#endif + +#endif + diff --git a/sgx-jvm/linux-sgx/common/inc/internal/elf_util.h b/sgx-jvm/linux-sgx/common/inc/internal/elf_util.h new file mode 100644 index 0000000000..408c42f642 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/elf_util.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _ELF_UTIL_H_ +#define _ELF_UTIL_H_ + +#include "elfheader/elf_common.h" +#include "elfheader/elfstructs.h" + +#ifndef __ELF_NATIVE_CLASS +# if defined(_M_X64) || defined(__x86_64) || defined(__amd64) +# include /* for UINT_MAX */ +# define __ELF_NATIVE_CLASS 64 +# else +# define __ELF_NATIVE_CLASS 32 +# endif +#endif + +#if __ELF_NATIVE_CLASS == 64 +# define Rel Rela + +# define RTS_DT_REL DT_RELA +# define RTS_DT_RELSZ DT_RELASZ +# define RTS_DT_RELENT DT_RELAENT +# else +# define RTS_DT_REL DT_REL +# define RTS_DT_RELSZ DT_RELSZ +# define RTS_DT_RELENT DT_RELENT +#endif + +/* We use this macro to refer to ELF types independent of the native wordsize. + `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */ +#define ElfW(type) _ElfW (Elf, __ELF_NATIVE_CLASS, type) + +/* We use this macro to refer to ELF macro constants. For example, + `ELFW(R_SYM)' is used in place of `ELF32_R_SYM' or `ELF64_R_SYM'. */ +#define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type) + +#define _ElfW(e,w,t) _ElfW_1 (e, w, _##t) +#define _ElfW_1(e,w,t) e##w##t + +/* GNU header uses `JUMP_SLOT' while `JMP_SLOT' in FreeBSD. */ +#define R_X86_64_JUMP_SLOT R_X86_64_JMP_SLOT + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/elfheader/README.txt b/sgx-jvm/linux-sgx/common/inc/internal/elfheader/README.txt new file mode 100644 index 0000000000..654a5ecadd --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/elfheader/README.txt @@ -0,0 +1,59 @@ +Note, the files `elf_common.h' and `elfstructs.h' are from FreeBSD. + git://github.com/freebsd/freebsd.git + +But with slight modifications shown below: + +diff --git a/sys/sys/elf_common.h b/sys/sys/elf_common.h +index 8f02ef1..7601abb 100644 +--- a/sys/sys/elf_common.h ++++ b/sys/sys/elf_common.h +@@ -30,6 +30,9 @@ + #ifndef _SYS_ELF_COMMON_H_ + #define _SYS_ELF_COMMON_H_ 1 + ++typedef uint32_t u_int32_t; ++typedef uint32_t Elf_Symndx; ++ + /* + * ELF definitions that are independent of architecture or word size. + */ +@@ -117,9 +120,6 @@ typedef struct { + #define ELFOSABI_ARM 97 /* ARM */ + #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ + +-#define ELFOSABI_SYSV ELFOSABI_NONE /* symbol used in old spec */ +-#define ELFOSABI_MONTEREY ELFOSABI_AIX /* Monterey */ +- + /* e_ident */ + #define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ + (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ +@@ -242,7 +242,6 @@ typedef struct { + #define EM_486 6 /* Intel i486. */ + #define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ + #define EM_ALPHA_STD 41 /* Digital Alpha (standard value). */ +-#define EM_ALPHA 0x9026 /* Alpha (written in the absence of an ABI) */ + + /* Special section indexes. */ + #define SHN_UNDEF 0 /* Undefined, missing, irrelevant. */ +@@ -441,6 +440,8 @@ typedef struct { + #define DT_MOVETAB 0x6ffffefe /* move table */ + #define DT_SYMINFO 0x6ffffeff /* syminfo table */ + #define DT_ADDRRNGHI 0x6ffffeff ++#define DT_ADDRTAGIDX(tag) (DT_ADDRRNGHI - (tag)) /* Reverse order! */ ++#define DT_ADDRNUM 11 + + #define DT_VERSYM 0x6ffffff0 /* Address of versym section. */ + #define DT_RELACOUNT 0x6ffffff9 /* number of RELATIVE relocations */ +@@ -505,12 +506,9 @@ typedef struct { + #define STT_FILE 4 /* Source file. */ + #define STT_COMMON 5 /* Uninitialized common block. */ + #define STT_TLS 6 /* TLS object. */ +-#define STT_NUM 7 + #define STT_LOOS 10 /* Reserved range for operating system */ + #define STT_GNU_IFUNC 10 + #define STT_HIOS 12 /* specific semantics. */ +-#define STT_LOPROC 13 /* reserved range for processor */ +-#define STT_HIPROC 15 /* specific semantics. */ + + /* Symbol visibility - ELFNN_ST_VISIBILITY - st_other */ + #define STV_DEFAULT 0x0 /* Default visibility (see binding). */ diff --git a/sgx-jvm/linux-sgx/common/inc/internal/elfheader/elf_common.h b/sgx-jvm/linux-sgx/common/inc/internal/elfheader/elf_common.h new file mode 100644 index 0000000000..7601abb189 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/elfheader/elf_common.h @@ -0,0 +1,975 @@ +/*- + * Copyright (c) 2000, 2001, 2008, 2011, David E. O'Brien + * Copyright (c) 1998 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_ELF_COMMON_H_ +#define _SYS_ELF_COMMON_H_ 1 + +typedef uint32_t u_int32_t; +typedef uint32_t Elf_Symndx; + +/* + * ELF definitions that are independent of architecture or word size. + */ + +/* + * Note header. The ".note" section contains an array of notes. Each + * begins with this header, aligned to a word boundary. Immediately + * following the note header is n_namesz bytes of name, padded to the + * next word boundary. Then comes n_descsz bytes of descriptor, again + * padded to a word boundary. The values of n_namesz and n_descsz do + * not include the padding. + */ + +typedef struct { + u_int32_t n_namesz; /* Length of name. */ + u_int32_t n_descsz; /* Length of descriptor. */ + u_int32_t n_type; /* Type of this note. */ +} Elf_Note; + +/* + * The header for GNU-style hash sections. + */ + +typedef struct { + u_int32_t gh_nbuckets; /* Number of hash buckets. */ + u_int32_t gh_symndx; /* First visible symbol in .dynsym. */ + u_int32_t gh_maskwords; /* #maskwords used in bloom filter. */ + u_int32_t gh_shift2; /* Bloom filter shift count. */ +} Elf_GNU_Hash_Header; + +/* Indexes into the e_ident array. Keep synced with + http://www.sco.com/developers/gabi/latest/ch4.eheader.html */ +#define EI_MAG0 0 /* Magic number, byte 0. */ +#define EI_MAG1 1 /* Magic number, byte 1. */ +#define EI_MAG2 2 /* Magic number, byte 2. */ +#define EI_MAG3 3 /* Magic number, byte 3. */ +#define EI_CLASS 4 /* Class of machine. */ +#define EI_DATA 5 /* Data format. */ +#define EI_VERSION 6 /* ELF format version. */ +#define EI_OSABI 7 /* Operating system / ABI identification */ +#define EI_ABIVERSION 8 /* ABI version */ +#define OLD_EI_BRAND 8 /* Start of architecture identification. */ +#define EI_PAD 9 /* Start of padding (per SVR4 ABI). */ +#define EI_NIDENT 16 /* Size of e_ident array. */ + +/* Values for the magic number bytes. */ +#define ELFMAG0 0x7f +#define ELFMAG1 'E' +#define ELFMAG2 'L' +#define ELFMAG3 'F' +#define ELFMAG "\177ELF" /* magic string */ +#define SELFMAG 4 /* magic string size */ + +/* Values for e_ident[EI_VERSION] and e_version. */ +#define EV_NONE 0 +#define EV_CURRENT 1 + +/* Values for e_ident[EI_CLASS]. */ +#define ELFCLASSNONE 0 /* Unknown class. */ +#define ELFCLASS32 1 /* 32-bit architecture. */ +#define ELFCLASS64 2 /* 64-bit architecture. */ + +/* Values for e_ident[EI_DATA]. */ +#define ELFDATANONE 0 /* Unknown data format. */ +#define ELFDATA2LSB 1 /* 2's complement little-endian. */ +#define ELFDATA2MSB 2 /* 2's complement big-endian. */ + +/* Values for e_ident[EI_OSABI]. */ +#define ELFOSABI_NONE 0 /* UNIX System V ABI */ +#define ELFOSABI_HPUX 1 /* HP-UX operating system */ +#define ELFOSABI_NETBSD 2 /* NetBSD */ +#define ELFOSABI_LINUX 3 /* GNU/Linux */ +#define ELFOSABI_HURD 4 /* GNU/Hurd */ +#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */ +#define ELFOSABI_SOLARIS 6 /* Solaris */ +#define ELFOSABI_AIX 7 /* AIX */ +#define ELFOSABI_IRIX 8 /* IRIX */ +#define ELFOSABI_FREEBSD 9 /* FreeBSD */ +#define ELFOSABI_TRU64 10 /* TRU64 UNIX */ +#define ELFOSABI_MODESTO 11 /* Novell Modesto */ +#define ELFOSABI_OPENBSD 12 /* OpenBSD */ +#define ELFOSABI_OPENVMS 13 /* Open VMS */ +#define ELFOSABI_NSK 14 /* HP Non-Stop Kernel */ +#define ELFOSABI_AROS 15 /* Amiga Research OS */ +#define ELFOSABI_ARM 97 /* ARM */ +#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ + +/* e_ident */ +#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ + (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ + (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ + (ehdr).e_ident[EI_MAG3] == ELFMAG3) + +/* Values for e_type. */ +#define ET_NONE 0 /* Unknown type. */ +#define ET_REL 1 /* Relocatable. */ +#define ET_EXEC 2 /* Executable. */ +#define ET_DYN 3 /* Shared object. */ +#define ET_CORE 4 /* Core file. */ +#define ET_LOOS 0xfe00 /* First operating system specific. */ +#define ET_HIOS 0xfeff /* Last operating system-specific. */ +#define ET_LOPROC 0xff00 /* First processor-specific. */ +#define ET_HIPROC 0xffff /* Last processor-specific. */ + +/* Values for e_machine. */ +#define EM_NONE 0 /* Unknown machine. */ +#define EM_M32 1 /* AT&T WE32100. */ +#define EM_SPARC 2 /* Sun SPARC. */ +#define EM_386 3 /* Intel i386. */ +#define EM_68K 4 /* Motorola 68000. */ +#define EM_88K 5 /* Motorola 88000. */ +#define EM_860 7 /* Intel i860. */ +#define EM_MIPS 8 /* MIPS R3000 Big-Endian only. */ +#define EM_S370 9 /* IBM System/370. */ +#define EM_MIPS_RS3_LE 10 /* MIPS R3000 Little-Endian. */ +#define EM_PARISC 15 /* HP PA-RISC. */ +#define EM_VPP500 17 /* Fujitsu VPP500. */ +#define EM_SPARC32PLUS 18 /* SPARC v8plus. */ +#define EM_960 19 /* Intel 80960. */ +#define EM_PPC 20 /* PowerPC 32-bit. */ +#define EM_PPC64 21 /* PowerPC 64-bit. */ +#define EM_S390 22 /* IBM System/390. */ +#define EM_V800 36 /* NEC V800. */ +#define EM_FR20 37 /* Fujitsu FR20. */ +#define EM_RH32 38 /* TRW RH-32. */ +#define EM_RCE 39 /* Motorola RCE. */ +#define EM_ARM 40 /* ARM. */ +#define EM_SH 42 /* Hitachi SH. */ +#define EM_SPARCV9 43 /* SPARC v9 64-bit. */ +#define EM_TRICORE 44 /* Siemens TriCore embedded processor. */ +#define EM_ARC 45 /* Argonaut RISC Core. */ +#define EM_H8_300 46 /* Hitachi H8/300. */ +#define EM_H8_300H 47 /* Hitachi H8/300H. */ +#define EM_H8S 48 /* Hitachi H8S. */ +#define EM_H8_500 49 /* Hitachi H8/500. */ +#define EM_IA_64 50 /* Intel IA-64 Processor. */ +#define EM_MIPS_X 51 /* Stanford MIPS-X. */ +#define EM_COLDFIRE 52 /* Motorola ColdFire. */ +#define EM_68HC12 53 /* Motorola M68HC12. */ +#define EM_MMA 54 /* Fujitsu MMA. */ +#define EM_PCP 55 /* Siemens PCP. */ +#define EM_NCPU 56 /* Sony nCPU. */ +#define EM_NDR1 57 /* Denso NDR1 microprocessor. */ +#define EM_STARCORE 58 /* Motorola Star*Core processor. */ +#define EM_ME16 59 /* Toyota ME16 processor. */ +#define EM_ST100 60 /* STMicroelectronics ST100 processor. */ +#define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ processor. */ +#define EM_X86_64 62 /* Advanced Micro Devices x86-64 */ +#define EM_AMD64 EM_X86_64 /* Advanced Micro Devices x86-64 (compat) */ +#define EM_PDSP 63 /* Sony DSP Processor. */ +#define EM_FX66 66 /* Siemens FX66 microcontroller. */ +#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 + microcontroller. */ +#define EM_ST7 68 /* STmicroelectronics ST7 8-bit + microcontroller. */ +#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller. */ +#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller. */ +#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller. */ +#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller. */ +#define EM_SVX 73 /* Silicon Graphics SVx. */ +#define EM_ST19 74 /* STMicroelectronics ST19 8-bit mc. */ +#define EM_VAX 75 /* Digital VAX. */ +#define EM_CRIS 76 /* Axis Communications 32-bit embedded + processor. */ +#define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded + processor. */ +#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor. */ +#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor. */ +#define EM_MMIX 80 /* Donald Knuth's educational 64-bit proc. */ +#define EM_HUANY 81 /* Harvard University machine-independent + object files. */ +#define EM_PRISM 82 /* SiTera Prism. */ +#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller. */ +#define EM_FR30 84 /* Fujitsu FR30. */ +#define EM_D10V 85 /* Mitsubishi D10V. */ +#define EM_D30V 86 /* Mitsubishi D30V. */ +#define EM_V850 87 /* NEC v850. */ +#define EM_M32R 88 /* Mitsubishi M32R. */ +#define EM_MN10300 89 /* Matsushita MN10300. */ +#define EM_MN10200 90 /* Matsushita MN10200. */ +#define EM_PJ 91 /* picoJava. */ +#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor. */ +#define EM_ARC_A5 93 /* ARC Cores Tangent-A5. */ +#define EM_XTENSA 94 /* Tensilica Xtensa Architecture. */ +#define EM_VIDEOCORE 95 /* Alphamosaic VideoCore processor. */ +#define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose + Processor. */ +#define EM_NS32K 97 /* National Semiconductor 32000 series. */ +#define EM_TPC 98 /* Tenor Network TPC processor. */ +#define EM_SNP1K 99 /* Trebia SNP 1000 processor. */ +#define EM_ST200 100 /* STMicroelectronics ST200 microcontroller. */ +#define EM_IP2K 101 /* Ubicom IP2xxx microcontroller family. */ +#define EM_MAX 102 /* MAX Processor. */ +#define EM_CR 103 /* National Semiconductor CompactRISC + microprocessor. */ +#define EM_F2MC16 104 /* Fujitsu F2MC16. */ +#define EM_MSP430 105 /* Texas Instruments embedded microcontroller + msp430. */ +#define EM_BLACKFIN 106 /* Analog Devices Blackfin (DSP) processor. */ +#define EM_SE_C33 107 /* S1C33 Family of Seiko Epson processors. */ +#define EM_SEP 108 /* Sharp embedded microprocessor. */ +#define EM_ARCA 109 /* Arca RISC Microprocessor. */ +#define EM_UNICORE 110 /* Microprocessor series from PKU-Unity Ltd. + and MPRC of Peking University */ + +/* Non-standard or deprecated. */ +#define EM_486 6 /* Intel i486. */ +#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ +#define EM_ALPHA_STD 41 /* Digital Alpha (standard value). */ + +/* Special section indexes. */ +#define SHN_UNDEF 0 /* Undefined, missing, irrelevant. */ +#define SHN_LORESERVE 0xff00 /* First of reserved range. */ +#define SHN_LOPROC 0xff00 /* First processor-specific. */ +#define SHN_HIPROC 0xff1f /* Last processor-specific. */ +#define SHN_LOOS 0xff20 /* First operating system-specific. */ +#define SHN_HIOS 0xff3f /* Last operating system-specific. */ +#define SHN_ABS 0xfff1 /* Absolute values. */ +#define SHN_COMMON 0xfff2 /* Common data. */ +#define SHN_XINDEX 0xffff /* Escape -- index stored elsewhere. */ +#define SHN_HIRESERVE 0xffff /* Last of reserved range. */ + +/* sh_type */ +#define SHT_NULL 0 /* inactive */ +#define SHT_PROGBITS 1 /* program defined information */ +#define SHT_SYMTAB 2 /* symbol table section */ +#define SHT_STRTAB 3 /* string table section */ +#define SHT_RELA 4 /* relocation section with addends */ +#define SHT_HASH 5 /* symbol hash table section */ +#define SHT_DYNAMIC 6 /* dynamic section */ +#define SHT_NOTE 7 /* note section */ +#define SHT_NOBITS 8 /* no space section */ +#define SHT_REL 9 /* relocation section - no addends */ +#define SHT_SHLIB 10 /* reserved - purpose unknown */ +#define SHT_DYNSYM 11 /* dynamic symbol table section */ +#define SHT_INIT_ARRAY 14 /* Initialization function pointers. */ +#define SHT_FINI_ARRAY 15 /* Termination function pointers. */ +#define SHT_PREINIT_ARRAY 16 /* Pre-initialization function ptrs. */ +#define SHT_GROUP 17 /* Section group. */ +#define SHT_SYMTAB_SHNDX 18 /* Section indexes (see SHN_XINDEX). */ +#define SHT_LOOS 0x60000000 /* First of OS specific semantics */ +#define SHT_LOSUNW 0x6ffffff4 +#define SHT_SUNW_dof 0x6ffffff4 +#define SHT_SUNW_cap 0x6ffffff5 +#define SHT_SUNW_SIGNATURE 0x6ffffff6 +#define SHT_GNU_HASH 0x6ffffff6 +#define SHT_SUNW_ANNOTATE 0x6ffffff7 +#define SHT_SUNW_DEBUGSTR 0x6ffffff8 +#define SHT_SUNW_DEBUG 0x6ffffff9 +#define SHT_SUNW_move 0x6ffffffa +#define SHT_SUNW_COMDAT 0x6ffffffb +#define SHT_SUNW_syminfo 0x6ffffffc +#define SHT_SUNW_verdef 0x6ffffffd +#define SHT_GNU_verdef 0x6ffffffd /* Symbol versions provided */ +#define SHT_SUNW_verneed 0x6ffffffe +#define SHT_GNU_verneed 0x6ffffffe /* Symbol versions required */ +#define SHT_SUNW_versym 0x6fffffff +#define SHT_GNU_versym 0x6fffffff /* Symbol version table */ +#define SHT_HISUNW 0x6fffffff +#define SHT_HIOS 0x6fffffff /* Last of OS specific semantics */ +#define SHT_LOPROC 0x70000000 /* reserved range for processor */ +#define SHT_AMD64_UNWIND 0x70000001 /* unwind information */ +#define SHT_MIPS_REGINFO 0x70000006 +#define SHT_MIPS_OPTIONS 0x7000000d +#define SHT_MIPS_DWARF 0x7000001e /* MIPS gcc uses MIPS_DWARF */ +#define SHT_HIPROC 0x7fffffff /* specific section header types */ +#define SHT_LOUSER 0x80000000 /* reserved range for application */ +#define SHT_HIUSER 0xffffffff /* specific indexes */ + +/* Flags for sh_flags. */ +#define SHF_WRITE 0x1 /* Section contains writable data. */ +#define SHF_ALLOC 0x2 /* Section occupies memory. */ +#define SHF_EXECINSTR 0x4 /* Section contains instructions. */ +#define SHF_MERGE 0x10 /* Section may be merged. */ +#define SHF_STRINGS 0x20 /* Section contains strings. */ +#define SHF_INFO_LINK 0x40 /* sh_info holds section index. */ +#define SHF_LINK_ORDER 0x80 /* Special ordering requirements. */ +#define SHF_OS_NONCONFORMING 0x100 /* OS-specific processing required. */ +#define SHF_GROUP 0x200 /* Member of section group. */ +#define SHF_TLS 0x400 /* Section contains TLS data. */ +#define SHF_MASKOS 0x0ff00000 /* OS-specific semantics. */ +#define SHF_MASKPROC 0xf0000000 /* Processor-specific semantics. */ + +/* Values for p_type. */ +#define PT_NULL 0 /* Unused entry. */ +#define PT_LOAD 1 /* Loadable segment. */ +#define PT_DYNAMIC 2 /* Dynamic linking information segment. */ +#define PT_INTERP 3 /* Pathname of interpreter. */ +#define PT_NOTE 4 /* Auxiliary information. */ +#define PT_SHLIB 5 /* Reserved (not used). */ +#define PT_PHDR 6 /* Location of program header itself. */ +#define PT_TLS 7 /* Thread local storage segment */ +#define PT_LOOS 0x60000000 /* First OS-specific. */ +#define PT_SUNW_UNWIND 0x6464e550 /* amd64 UNWIND program header */ +#define PT_GNU_EH_FRAME 0x6474e550 +#define PT_GNU_STACK 0x6474e551 +#define PT_GNU_RELRO 0x6474e552 +#define PT_LOSUNW 0x6ffffffa +#define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */ +#define PT_SUNWSTACK 0x6ffffffb /* describes the stack segment */ +#define PT_SUNWDTRACE 0x6ffffffc /* private */ +#define PT_SUNWCAP 0x6ffffffd /* hard/soft capabilities segment */ +#define PT_HISUNW 0x6fffffff +#define PT_HIOS 0x6fffffff /* Last OS-specific. */ +#define PT_LOPROC 0x70000000 /* First processor-specific type. */ +#define PT_HIPROC 0x7fffffff /* Last processor-specific type. */ + +/* Values for p_flags. */ +#define PF_X 0x1 /* Executable. */ +#define PF_W 0x2 /* Writable. */ +#define PF_R 0x4 /* Readable. */ +#define PF_MASKOS 0x0ff00000 /* Operating system-specific. */ +#define PF_MASKPROC 0xf0000000 /* Processor-specific. */ + +/* Extended program header index. */ +#define PN_XNUM 0xffff + +/* Values for d_tag. */ +#define DT_NULL 0 /* Terminating entry. */ +#define DT_NEEDED 1 /* String table offset of a needed shared + library. */ +#define DT_PLTRELSZ 2 /* Total size in bytes of PLT relocations. */ +#define DT_PLTGOT 3 /* Processor-dependent address. */ +#define DT_HASH 4 /* Address of symbol hash table. */ +#define DT_STRTAB 5 /* Address of string table. */ +#define DT_SYMTAB 6 /* Address of symbol table. */ +#define DT_RELA 7 /* Address of ElfNN_Rela relocations. */ +#define DT_RELASZ 8 /* Total size of ElfNN_Rela relocations. */ +#define DT_RELAENT 9 /* Size of each ElfNN_Rela relocation entry. */ +#define DT_STRSZ 10 /* Size of string table. */ +#define DT_SYMENT 11 /* Size of each symbol table entry. */ +#define DT_INIT 12 /* Address of initialization function. */ +#define DT_FINI 13 /* Address of finalization function. */ +#define DT_SONAME 14 /* String table offset of shared object + name. */ +#define DT_RPATH 15 /* String table offset of library path. [sup] */ +#define DT_SYMBOLIC 16 /* Indicates "symbolic" linking. [sup] */ +#define DT_REL 17 /* Address of ElfNN_Rel relocations. */ +#define DT_RELSZ 18 /* Total size of ElfNN_Rel relocations. */ +#define DT_RELENT 19 /* Size of each ElfNN_Rel relocation. */ +#define DT_PLTREL 20 /* Type of relocation used for PLT. */ +#define DT_DEBUG 21 /* Reserved (not used). */ +#define DT_TEXTREL 22 /* Indicates there may be relocations in + non-writable segments. [sup] */ +#define DT_JMPREL 23 /* Address of PLT relocations. */ +#define DT_BIND_NOW 24 /* [sup] */ +#define DT_INIT_ARRAY 25 /* Address of the array of pointers to + initialization functions */ +#define DT_FINI_ARRAY 26 /* Address of the array of pointers to + termination functions */ +#define DT_INIT_ARRAYSZ 27 /* Size in bytes of the array of + initialization functions. */ +#define DT_FINI_ARRAYSZ 28 /* Size in bytes of the array of + termination functions. */ +#define DT_RUNPATH 29 /* String table offset of a null-terminated + library search path string. */ +#define DT_FLAGS 30 /* Object specific flag values. */ +#define DT_ENCODING 32 /* Values greater than or equal to DT_ENCODING + and less than DT_LOOS follow the rules for + the interpretation of the d_un union + as follows: even == 'd_ptr', odd == 'd_val' + or none */ +#define DT_PREINIT_ARRAY 32 /* Address of the array of pointers to + pre-initialization functions. */ +#define DT_PREINIT_ARRAYSZ 33 /* Size in bytes of the array of + pre-initialization functions. */ +#define DT_MAXPOSTAGS 34 /* number of positive tags */ +#define DT_LOOS 0x6000000d /* First OS-specific */ +#define DT_SUNW_AUXILIARY 0x6000000d /* symbol auxiliary name */ +#define DT_SUNW_RTLDINF 0x6000000e /* ld.so.1 info (private) */ +#define DT_SUNW_FILTER 0x6000000f /* symbol filter name */ +#define DT_SUNW_CAP 0x60000010 /* hardware/software */ +#define DT_HIOS 0x6ffff000 /* Last OS-specific */ + +/* + * DT_* entries which fall between DT_VALRNGHI & DT_VALRNGLO use the + * Dyn.d_un.d_val field of the Elf*_Dyn structure. + */ +#define DT_VALRNGLO 0x6ffffd00 +#define DT_CHECKSUM 0x6ffffdf8 /* elf checksum */ +#define DT_PLTPADSZ 0x6ffffdf9 /* pltpadding size */ +#define DT_MOVEENT 0x6ffffdfa /* move table entry size */ +#define DT_MOVESZ 0x6ffffdfb /* move table size */ +#define DT_FEATURE_1 0x6ffffdfc /* feature holder */ +#define DT_POSFLAG_1 0x6ffffdfd /* flags for DT_* entries, effecting */ + /* the following DT_* entry. */ + /* See DF_P1_* definitions */ +#define DT_SYMINSZ 0x6ffffdfe /* syminfo table size (in bytes) */ +#define DT_SYMINENT 0x6ffffdff /* syminfo entry size (in bytes) */ +#define DT_VALRNGHI 0x6ffffdff + +/* + * DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the + * Dyn.d_un.d_ptr field of the Elf*_Dyn structure. + * + * If any adjustment is made to the ELF object after it has been + * built, these entries will need to be adjusted. + */ +#define DT_ADDRRNGLO 0x6ffffe00 +#define DT_GNU_HASH 0x6ffffef5 /* GNU-style hash table */ +#define DT_CONFIG 0x6ffffefa /* configuration information */ +#define DT_DEPAUDIT 0x6ffffefb /* dependency auditing */ +#define DT_AUDIT 0x6ffffefc /* object auditing */ +#define DT_PLTPAD 0x6ffffefd /* pltpadding (sparcv9) */ +#define DT_MOVETAB 0x6ffffefe /* move table */ +#define DT_SYMINFO 0x6ffffeff /* syminfo table */ +#define DT_ADDRRNGHI 0x6ffffeff +#define DT_ADDRTAGIDX(tag) (DT_ADDRRNGHI - (tag)) /* Reverse order! */ +#define DT_ADDRNUM 11 + +#define DT_VERSYM 0x6ffffff0 /* Address of versym section. */ +#define DT_RELACOUNT 0x6ffffff9 /* number of RELATIVE relocations */ +#define DT_RELCOUNT 0x6ffffffa /* number of RELATIVE relocations */ +#define DT_FLAGS_1 0x6ffffffb /* state flags - see DF_1_* defs */ +#define DT_VERDEF 0x6ffffffc /* Address of verdef section. */ +#define DT_VERDEFNUM 0x6ffffffd /* Number of elems in verdef section */ +#define DT_VERNEED 0x6ffffffe /* Address of verneed section. */ +#define DT_VERNEEDNUM 0x6fffffff /* Number of elems in verneed section */ + +#define DT_LOPROC 0x70000000 /* First processor-specific type. */ +#define DT_DEPRECATED_SPARC_REGISTER 0x7000001 +#define DT_AUXILIARY 0x7ffffffd /* shared library auxiliary name */ +#define DT_USED 0x7ffffffe /* ignored - same as needed */ +#define DT_FILTER 0x7fffffff /* shared library filter name */ +#define DT_HIPROC 0x7fffffff /* Last processor-specific type. */ + +/* Values for DT_FLAGS */ +#define DF_ORIGIN 0x0001 /* Indicates that the object being loaded may + make reference to the $ORIGIN substitution + string */ +#define DF_SYMBOLIC 0x0002 /* Indicates "symbolic" linking. */ +#define DF_TEXTREL 0x0004 /* Indicates there may be relocations in + non-writable segments. */ +#define DF_BIND_NOW 0x0008 /* Indicates that the dynamic linker should + process all relocations for the object + containing this entry before transferring + control to the program. */ +#define DF_STATIC_TLS 0x0010 /* Indicates that the shared object or + executable contains code using a static + thread-local storage scheme. */ + +/* Values for DT_FLAGS_1 */ +#define DF_1_BIND_NOW 0x00000001 /* Same as DF_BIND_NOW */ +#define DF_1_GLOBAL 0x00000002 /* Set the RTLD_GLOBAL for object */ +#define DF_1_NODELETE 0x00000008 /* Set the RTLD_NODELETE for object */ +#define DF_1_LOADFLTR 0x00000010 /* Immediate loading of filtees */ +#define DF_1_NOOPEN 0x00000040 /* Do not allow loading on dlopen() */ +#define DF_1_ORIGIN 0x00000080 /* Process $ORIGIN */ +#define DF_1_NODEFLIB 0x00000800 /* Do not search default paths */ + +/* Values for n_type. Used in core files. */ +#define NT_PRSTATUS 1 /* Process status. */ +#define NT_FPREGSET 2 /* Floating point registers. */ +#define NT_PRPSINFO 3 /* Process state info. */ +#define NT_THRMISC 7 /* Thread miscellaneous info. */ + +/* Symbol Binding - ELFNN_ST_BIND - st_info */ +#define STB_LOCAL 0 /* Local symbol */ +#define STB_GLOBAL 1 /* Global symbol */ +#define STB_WEAK 2 /* like global - lower precedence */ +#define STB_LOOS 10 /* Reserved range for operating system */ +#define STB_HIOS 12 /* specific semantics. */ +#define STB_LOPROC 13 /* reserved range for processor */ +#define STB_HIPROC 15 /* specific semantics. */ + +/* Symbol type - ELFNN_ST_TYPE - st_info */ +#define STT_NOTYPE 0 /* Unspecified type. */ +#define STT_OBJECT 1 /* Data object. */ +#define STT_FUNC 2 /* Function. */ +#define STT_SECTION 3 /* Section. */ +#define STT_FILE 4 /* Source file. */ +#define STT_COMMON 5 /* Uninitialized common block. */ +#define STT_TLS 6 /* TLS object. */ +#define STT_LOOS 10 /* Reserved range for operating system */ +#define STT_GNU_IFUNC 10 +#define STT_HIOS 12 /* specific semantics. */ + +/* Symbol visibility - ELFNN_ST_VISIBILITY - st_other */ +#define STV_DEFAULT 0x0 /* Default visibility (see binding). */ +#define STV_INTERNAL 0x1 /* Special meaning in relocatable objects. */ +#define STV_HIDDEN 0x2 /* Not visible. */ +#define STV_PROTECTED 0x3 /* Visible but not preemptible. */ +#define STV_EXPORTED 0x4 +#define STV_SINGLETON 0x5 +#define STV_ELIMINATE 0x6 + +/* Special symbol table indexes. */ +#define STN_UNDEF 0 /* Undefined symbol index. */ + +/* Symbol versioning flags. */ +#define VER_DEF_CURRENT 1 +#define VER_DEF_IDX(x) VER_NDX(x) + +#define VER_FLG_BASE 0x01 +#define VER_FLG_WEAK 0x02 + +#define VER_NEED_CURRENT 1 +#define VER_NEED_WEAK (1u << 15) +#define VER_NEED_HIDDEN VER_NDX_HIDDEN +#define VER_NEED_IDX(x) VER_NDX(x) + +#define VER_NDX_LOCAL 0 +#define VER_NDX_GLOBAL 1 +#define VER_NDX_GIVEN 2 + +#define VER_NDX_HIDDEN (1u << 15) +#define VER_NDX(x) ((x) & ~(1u << 15)) + +#define CA_SUNW_NULL 0 +#define CA_SUNW_HW_1 1 /* first hardware capabilities entry */ +#define CA_SUNW_SF_1 2 /* first software capabilities entry */ + +/* + * Syminfo flag values + */ +#define SYMINFO_FLG_DIRECT 0x0001 /* symbol ref has direct association */ + /* to object containing defn. */ +#define SYMINFO_FLG_PASSTHRU 0x0002 /* ignored - see SYMINFO_FLG_FILTER */ +#define SYMINFO_FLG_COPY 0x0004 /* symbol is a copy-reloc */ +#define SYMINFO_FLG_LAZYLOAD 0x0008 /* object containing defn should be */ + /* lazily-loaded */ +#define SYMINFO_FLG_DIRECTBIND 0x0010 /* ref should be bound directly to */ + /* object containing defn. */ +#define SYMINFO_FLG_NOEXTDIRECT 0x0020 /* don't let an external reference */ + /* directly bind to this symbol */ +#define SYMINFO_FLG_FILTER 0x0002 /* symbol ref is associated to a */ +#define SYMINFO_FLG_AUXILIARY 0x0040 /* standard or auxiliary filter */ + +/* + * Syminfo.si_boundto values. + */ +#define SYMINFO_BT_SELF 0xffff /* symbol bound to self */ +#define SYMINFO_BT_PARENT 0xfffe /* symbol bound to parent */ +#define SYMINFO_BT_NONE 0xfffd /* no special symbol binding */ +#define SYMINFO_BT_EXTERN 0xfffc /* symbol defined as external */ +#define SYMINFO_BT_LOWRESERVE 0xff00 /* beginning of reserved entries */ + +/* + * Syminfo version values. + */ +#define SYMINFO_NONE 0 /* Syminfo version */ +#define SYMINFO_CURRENT 1 +#define SYMINFO_NUM 2 + +/* + * Relocation types. + * + * All machine architectures are defined here to allow tools on one to + * handle others. + */ + +#define R_386_NONE 0 /* No relocation. */ +#define R_386_32 1 /* Add symbol value. */ +#define R_386_PC32 2 /* Add PC-relative symbol value. */ +#define R_386_GOT32 3 /* Add PC-relative GOT offset. */ +#define R_386_PLT32 4 /* Add PC-relative PLT offset. */ +#define R_386_COPY 5 /* Copy data from shared object. */ +#define R_386_GLOB_DAT 6 /* Set GOT entry to data address. */ +#define R_386_JMP_SLOT 7 /* Set GOT entry to code address. */ +#define R_386_RELATIVE 8 /* Add load address of shared object. */ +#define R_386_GOTOFF 9 /* Add GOT-relative symbol address. */ +#define R_386_GOTPC 10 /* Add PC-relative GOT table address. */ +#define R_386_TLS_TPOFF 14 /* Negative offset in static TLS block */ +#define R_386_TLS_IE 15 /* Absolute address of GOT for -ve static TLS */ +#define R_386_TLS_GOTIE 16 /* GOT entry for negative static TLS block */ +#define R_386_TLS_LE 17 /* Negative offset relative to static TLS */ +#define R_386_TLS_GD 18 /* 32 bit offset to GOT (index,off) pair */ +#define R_386_TLS_LDM 19 /* 32 bit offset to GOT (index,zero) pair */ +#define R_386_TLS_GD_32 24 /* 32 bit offset to GOT (index,off) pair */ +#define R_386_TLS_GD_PUSH 25 /* pushl instruction for Sun ABI GD sequence */ +#define R_386_TLS_GD_CALL 26 /* call instruction for Sun ABI GD sequence */ +#define R_386_TLS_GD_POP 27 /* popl instruction for Sun ABI GD sequence */ +#define R_386_TLS_LDM_32 28 /* 32 bit offset to GOT (index,zero) pair */ +#define R_386_TLS_LDM_PUSH 29 /* pushl instruction for Sun ABI LD sequence */ +#define R_386_TLS_LDM_CALL 30 /* call instruction for Sun ABI LD sequence */ +#define R_386_TLS_LDM_POP 31 /* popl instruction for Sun ABI LD sequence */ +#define R_386_TLS_LDO_32 32 /* 32 bit offset from start of TLS block */ +#define R_386_TLS_IE_32 33 /* 32 bit offset to GOT static TLS offset entry */ +#define R_386_TLS_LE_32 34 /* 32 bit offset within static TLS block */ +#define R_386_TLS_DTPMOD32 35 /* GOT entry containing TLS index */ +#define R_386_TLS_DTPOFF32 36 /* GOT entry containing TLS offset */ +#define R_386_TLS_TPOFF32 37 /* GOT entry of -ve static TLS offset */ +#define R_386_IRELATIVE 42 /* PLT entry resolved indirectly at runtime */ + +#define R_ARM_NONE 0 /* No relocation. */ +#define R_ARM_PC24 1 +#define R_ARM_ABS32 2 +#define R_ARM_REL32 3 +#define R_ARM_PC13 4 +#define R_ARM_ABS16 5 +#define R_ARM_ABS12 6 +#define R_ARM_THM_ABS5 7 +#define R_ARM_ABS8 8 +#define R_ARM_SBREL32 9 +#define R_ARM_THM_PC22 10 +#define R_ARM_THM_PC8 11 +#define R_ARM_AMP_VCALL9 12 +#define R_ARM_SWI24 13 +#define R_ARM_THM_SWI8 14 +#define R_ARM_XPC25 15 +#define R_ARM_THM_XPC22 16 +/* TLS relocations */ +#define R_ARM_TLS_DTPMOD32 17 /* ID of module containing symbol */ +#define R_ARM_TLS_DTPOFF32 18 /* Offset in TLS block */ +#define R_ARM_TLS_TPOFF32 19 /* Offset in static TLS block */ +#define R_ARM_COPY 20 /* Copy data from shared object. */ +#define R_ARM_GLOB_DAT 21 /* Set GOT entry to data address. */ +#define R_ARM_JUMP_SLOT 22 /* Set GOT entry to code address. */ +#define R_ARM_RELATIVE 23 /* Add load address of shared object. */ +#define R_ARM_GOTOFF 24 /* Add GOT-relative symbol address. */ +#define R_ARM_GOTPC 25 /* Add PC-relative GOT table address. */ +#define R_ARM_GOT32 26 /* Add PC-relative GOT offset. */ +#define R_ARM_PLT32 27 /* Add PC-relative PLT offset. */ +#define R_ARM_GNU_VTENTRY 100 +#define R_ARM_GNU_VTINHERIT 101 +#define R_ARM_RSBREL32 250 +#define R_ARM_THM_RPC22 251 +#define R_ARM_RREL32 252 +#define R_ARM_RABS32 253 +#define R_ARM_RPC24 254 +#define R_ARM_RBASE 255 + +/* Name Value Field Calculation */ +#define R_IA_64_NONE 0 /* None */ +#define R_IA_64_IMM14 0x21 /* immediate14 S + A */ +#define R_IA_64_IMM22 0x22 /* immediate22 S + A */ +#define R_IA_64_IMM64 0x23 /* immediate64 S + A */ +#define R_IA_64_DIR32MSB 0x24 /* word32 MSB S + A */ +#define R_IA_64_DIR32LSB 0x25 /* word32 LSB S + A */ +#define R_IA_64_DIR64MSB 0x26 /* word64 MSB S + A */ +#define R_IA_64_DIR64LSB 0x27 /* word64 LSB S + A */ +#define R_IA_64_GPREL22 0x2a /* immediate22 @gprel(S + A) */ +#define R_IA_64_GPREL64I 0x2b /* immediate64 @gprel(S + A) */ +#define R_IA_64_GPREL32MSB 0x2c /* word32 MSB @gprel(S + A) */ +#define R_IA_64_GPREL32LSB 0x2d /* word32 LSB @gprel(S + A) */ +#define R_IA_64_GPREL64MSB 0x2e /* word64 MSB @gprel(S + A) */ +#define R_IA_64_GPREL64LSB 0x2f /* word64 LSB @gprel(S + A) */ +#define R_IA_64_LTOFF22 0x32 /* immediate22 @ltoff(S + A) */ +#define R_IA_64_LTOFF64I 0x33 /* immediate64 @ltoff(S + A) */ +#define R_IA_64_PLTOFF22 0x3a /* immediate22 @pltoff(S + A) */ +#define R_IA_64_PLTOFF64I 0x3b /* immediate64 @pltoff(S + A) */ +#define R_IA_64_PLTOFF64MSB 0x3e /* word64 MSB @pltoff(S + A) */ +#define R_IA_64_PLTOFF64LSB 0x3f /* word64 LSB @pltoff(S + A) */ +#define R_IA_64_FPTR64I 0x43 /* immediate64 @fptr(S + A) */ +#define R_IA_64_FPTR32MSB 0x44 /* word32 MSB @fptr(S + A) */ +#define R_IA_64_FPTR32LSB 0x45 /* word32 LSB @fptr(S + A) */ +#define R_IA_64_FPTR64MSB 0x46 /* word64 MSB @fptr(S + A) */ +#define R_IA_64_FPTR64LSB 0x47 /* word64 LSB @fptr(S + A) */ +#define R_IA_64_PCREL60B 0x48 /* immediate60 form1 S + A - P */ +#define R_IA_64_PCREL21B 0x49 /* immediate21 form1 S + A - P */ +#define R_IA_64_PCREL21M 0x4a /* immediate21 form2 S + A - P */ +#define R_IA_64_PCREL21F 0x4b /* immediate21 form3 S + A - P */ +#define R_IA_64_PCREL32MSB 0x4c /* word32 MSB S + A - P */ +#define R_IA_64_PCREL32LSB 0x4d /* word32 LSB S + A - P */ +#define R_IA_64_PCREL64MSB 0x4e /* word64 MSB S + A - P */ +#define R_IA_64_PCREL64LSB 0x4f /* word64 LSB S + A - P */ +#define R_IA_64_LTOFF_FPTR22 0x52 /* immediate22 @ltoff(@fptr(S + A)) */ +#define R_IA_64_LTOFF_FPTR64I 0x53 /* immediate64 @ltoff(@fptr(S + A)) */ +#define R_IA_64_LTOFF_FPTR32MSB 0x54 /* word32 MSB @ltoff(@fptr(S + A)) */ +#define R_IA_64_LTOFF_FPTR32LSB 0x55 /* word32 LSB @ltoff(@fptr(S + A)) */ +#define R_IA_64_LTOFF_FPTR64MSB 0x56 /* word64 MSB @ltoff(@fptr(S + A)) */ +#define R_IA_64_LTOFF_FPTR64LSB 0x57 /* word64 LSB @ltoff(@fptr(S + A)) */ +#define R_IA_64_SEGREL32MSB 0x5c /* word32 MSB @segrel(S + A) */ +#define R_IA_64_SEGREL32LSB 0x5d /* word32 LSB @segrel(S + A) */ +#define R_IA_64_SEGREL64MSB 0x5e /* word64 MSB @segrel(S + A) */ +#define R_IA_64_SEGREL64LSB 0x5f /* word64 LSB @segrel(S + A) */ +#define R_IA_64_SECREL32MSB 0x64 /* word32 MSB @secrel(S + A) */ +#define R_IA_64_SECREL32LSB 0x65 /* word32 LSB @secrel(S + A) */ +#define R_IA_64_SECREL64MSB 0x66 /* word64 MSB @secrel(S + A) */ +#define R_IA_64_SECREL64LSB 0x67 /* word64 LSB @secrel(S + A) */ +#define R_IA_64_REL32MSB 0x6c /* word32 MSB BD + A */ +#define R_IA_64_REL32LSB 0x6d /* word32 LSB BD + A */ +#define R_IA_64_REL64MSB 0x6e /* word64 MSB BD + A */ +#define R_IA_64_REL64LSB 0x6f /* word64 LSB BD + A */ +#define R_IA_64_LTV32MSB 0x74 /* word32 MSB S + A */ +#define R_IA_64_LTV32LSB 0x75 /* word32 LSB S + A */ +#define R_IA_64_LTV64MSB 0x76 /* word64 MSB S + A */ +#define R_IA_64_LTV64LSB 0x77 /* word64 LSB S + A */ +#define R_IA_64_PCREL21BI 0x79 /* immediate21 form1 S + A - P */ +#define R_IA_64_PCREL22 0x7a /* immediate22 S + A - P */ +#define R_IA_64_PCREL64I 0x7b /* immediate64 S + A - P */ +#define R_IA_64_IPLTMSB 0x80 /* function descriptor MSB special */ +#define R_IA_64_IPLTLSB 0x81 /* function descriptor LSB speciaal */ +#define R_IA_64_SUB 0x85 /* immediate64 A - S */ +#define R_IA_64_LTOFF22X 0x86 /* immediate22 special */ +#define R_IA_64_LDXMOV 0x87 /* immediate22 special */ +#define R_IA_64_TPREL14 0x91 /* imm14 @tprel(S + A) */ +#define R_IA_64_TPREL22 0x92 /* imm22 @tprel(S + A) */ +#define R_IA_64_TPREL64I 0x93 /* imm64 @tprel(S + A) */ +#define R_IA_64_TPREL64MSB 0x96 /* word64 MSB @tprel(S + A) */ +#define R_IA_64_TPREL64LSB 0x97 /* word64 LSB @tprel(S + A) */ +#define R_IA_64_LTOFF_TPREL22 0x9a /* imm22 @ltoff(@tprel(S+A)) */ +#define R_IA_64_DTPMOD64MSB 0xa6 /* word64 MSB @dtpmod(S + A) */ +#define R_IA_64_DTPMOD64LSB 0xa7 /* word64 LSB @dtpmod(S + A) */ +#define R_IA_64_LTOFF_DTPMOD22 0xaa /* imm22 @ltoff(@dtpmod(S+A)) */ +#define R_IA_64_DTPREL14 0xb1 /* imm14 @dtprel(S + A) */ +#define R_IA_64_DTPREL22 0xb2 /* imm22 @dtprel(S + A) */ +#define R_IA_64_DTPREL64I 0xb3 /* imm64 @dtprel(S + A) */ +#define R_IA_64_DTPREL32MSB 0xb4 /* word32 MSB @dtprel(S + A) */ +#define R_IA_64_DTPREL32LSB 0xb5 /* word32 LSB @dtprel(S + A) */ +#define R_IA_64_DTPREL64MSB 0xb6 /* word64 MSB @dtprel(S + A) */ +#define R_IA_64_DTPREL64LSB 0xb7 /* word64 LSB @dtprel(S + A) */ +#define R_IA_64_LTOFF_DTPREL22 0xba /* imm22 @ltoff(@dtprel(S+A)) */ + +#define R_MIPS_NONE 0 /* No reloc */ +#define R_MIPS_16 1 /* Direct 16 bit */ +#define R_MIPS_32 2 /* Direct 32 bit */ +#define R_MIPS_REL32 3 /* PC relative 32 bit */ +#define R_MIPS_26 4 /* Direct 26 bit shifted */ +#define R_MIPS_HI16 5 /* High 16 bit */ +#define R_MIPS_LO16 6 /* Low 16 bit */ +#define R_MIPS_GPREL16 7 /* GP relative 16 bit */ +#define R_MIPS_LITERAL 8 /* 16 bit literal entry */ +#define R_MIPS_GOT16 9 /* 16 bit GOT entry */ +#define R_MIPS_PC16 10 /* PC relative 16 bit */ +#define R_MIPS_CALL16 11 /* 16 bit GOT entry for function */ +#define R_MIPS_GPREL32 12 /* GP relative 32 bit */ +#define R_MIPS_GOTHI16 21 /* GOT HI 16 bit */ +#define R_MIPS_GOTLO16 22 /* GOT LO 16 bit */ +#define R_MIPS_CALLHI16 30 /* upper 16 bit GOT entry for function */ +#define R_MIPS_CALLLO16 31 /* lower 16 bit GOT entry for function */ + +#define R_PPC_NONE 0 /* No relocation. */ +#define R_PPC_ADDR32 1 +#define R_PPC_ADDR24 2 +#define R_PPC_ADDR16 3 +#define R_PPC_ADDR16_LO 4 +#define R_PPC_ADDR16_HI 5 +#define R_PPC_ADDR16_HA 6 +#define R_PPC_ADDR14 7 +#define R_PPC_ADDR14_BRTAKEN 8 +#define R_PPC_ADDR14_BRNTAKEN 9 +#define R_PPC_REL24 10 +#define R_PPC_REL14 11 +#define R_PPC_REL14_BRTAKEN 12 +#define R_PPC_REL14_BRNTAKEN 13 +#define R_PPC_GOT16 14 +#define R_PPC_GOT16_LO 15 +#define R_PPC_GOT16_HI 16 +#define R_PPC_GOT16_HA 17 +#define R_PPC_PLTREL24 18 +#define R_PPC_COPY 19 +#define R_PPC_GLOB_DAT 20 +#define R_PPC_JMP_SLOT 21 +#define R_PPC_RELATIVE 22 +#define R_PPC_LOCAL24PC 23 +#define R_PPC_UADDR32 24 +#define R_PPC_UADDR16 25 +#define R_PPC_REL32 26 +#define R_PPC_PLT32 27 +#define R_PPC_PLTREL32 28 +#define R_PPC_PLT16_LO 29 +#define R_PPC_PLT16_HI 30 +#define R_PPC_PLT16_HA 31 +#define R_PPC_SDAREL16 32 +#define R_PPC_SECTOFF 33 +#define R_PPC_SECTOFF_LO 34 +#define R_PPC_SECTOFF_HI 35 +#define R_PPC_SECTOFF_HA 36 + +/* + * 64-bit relocations + */ +#define R_PPC64_ADDR64 38 +#define R_PPC64_ADDR16_HIGHER 39 +#define R_PPC64_ADDR16_HIGHERA 40 +#define R_PPC64_ADDR16_HIGHEST 41 +#define R_PPC64_ADDR16_HIGHESTA 42 +#define R_PPC64_UADDR64 43 +#define R_PPC64_REL64 44 +#define R_PPC64_PLT64 45 +#define R_PPC64_PLTREL64 46 +#define R_PPC64_TOC16 47 +#define R_PPC64_TOC16_LO 48 +#define R_PPC64_TOC16_HI 49 +#define R_PPC64_TOC16_HA 50 +#define R_PPC64_TOC 51 +#define R_PPC64_DTPMOD64 68 +#define R_PPC64_TPREL64 73 +#define R_PPC64_DTPREL64 78 + +/* + * TLS relocations + */ +#define R_PPC_TLS 67 +#define R_PPC_DTPMOD32 68 +#define R_PPC_TPREL16 69 +#define R_PPC_TPREL16_LO 70 +#define R_PPC_TPREL16_HI 71 +#define R_PPC_TPREL16_HA 72 +#define R_PPC_TPREL32 73 +#define R_PPC_DTPREL16 74 +#define R_PPC_DTPREL16_LO 75 +#define R_PPC_DTPREL16_HI 76 +#define R_PPC_DTPREL16_HA 77 +#define R_PPC_DTPREL32 78 +#define R_PPC_GOT_TLSGD16 79 +#define R_PPC_GOT_TLSGD16_LO 80 +#define R_PPC_GOT_TLSGD16_HI 81 +#define R_PPC_GOT_TLSGD16_HA 82 +#define R_PPC_GOT_TLSLD16 83 +#define R_PPC_GOT_TLSLD16_LO 84 +#define R_PPC_GOT_TLSLD16_HI 85 +#define R_PPC_GOT_TLSLD16_HA 86 +#define R_PPC_GOT_TPREL16 87 +#define R_PPC_GOT_TPREL16_LO 88 +#define R_PPC_GOT_TPREL16_HI 89 +#define R_PPC_GOT_TPREL16_HA 90 + +/* + * The remaining relocs are from the Embedded ELF ABI, and are not in the + * SVR4 ELF ABI. + */ + +#define R_PPC_EMB_NADDR32 101 +#define R_PPC_EMB_NADDR16 102 +#define R_PPC_EMB_NADDR16_LO 103 +#define R_PPC_EMB_NADDR16_HI 104 +#define R_PPC_EMB_NADDR16_HA 105 +#define R_PPC_EMB_SDAI16 106 +#define R_PPC_EMB_SDA2I16 107 +#define R_PPC_EMB_SDA2REL 108 +#define R_PPC_EMB_SDA21 109 +#define R_PPC_EMB_MRKREF 110 +#define R_PPC_EMB_RELSEC16 111 +#define R_PPC_EMB_RELST_LO 112 +#define R_PPC_EMB_RELST_HI 113 +#define R_PPC_EMB_RELST_HA 114 +#define R_PPC_EMB_BIT_FLD 115 +#define R_PPC_EMB_RELSDA 116 + +#define R_SPARC_NONE 0 +#define R_SPARC_8 1 +#define R_SPARC_16 2 +#define R_SPARC_32 3 +#define R_SPARC_DISP8 4 +#define R_SPARC_DISP16 5 +#define R_SPARC_DISP32 6 +#define R_SPARC_WDISP30 7 +#define R_SPARC_WDISP22 8 +#define R_SPARC_HI22 9 +#define R_SPARC_22 10 +#define R_SPARC_13 11 +#define R_SPARC_LO10 12 +#define R_SPARC_GOT10 13 +#define R_SPARC_GOT13 14 +#define R_SPARC_GOT22 15 +#define R_SPARC_PC10 16 +#define R_SPARC_PC22 17 +#define R_SPARC_WPLT30 18 +#define R_SPARC_COPY 19 +#define R_SPARC_GLOB_DAT 20 +#define R_SPARC_JMP_SLOT 21 +#define R_SPARC_RELATIVE 22 +#define R_SPARC_UA32 23 +#define R_SPARC_PLT32 24 +#define R_SPARC_HIPLT22 25 +#define R_SPARC_LOPLT10 26 +#define R_SPARC_PCPLT32 27 +#define R_SPARC_PCPLT22 28 +#define R_SPARC_PCPLT10 29 +#define R_SPARC_10 30 +#define R_SPARC_11 31 +#define R_SPARC_64 32 +#define R_SPARC_OLO10 33 +#define R_SPARC_HH22 34 +#define R_SPARC_HM10 35 +#define R_SPARC_LM22 36 +#define R_SPARC_PC_HH22 37 +#define R_SPARC_PC_HM10 38 +#define R_SPARC_PC_LM22 39 +#define R_SPARC_WDISP16 40 +#define R_SPARC_WDISP19 41 +#define R_SPARC_GLOB_JMP 42 +#define R_SPARC_7 43 +#define R_SPARC_5 44 +#define R_SPARC_6 45 +#define R_SPARC_DISP64 46 +#define R_SPARC_PLT64 47 +#define R_SPARC_HIX22 48 +#define R_SPARC_LOX10 49 +#define R_SPARC_H44 50 +#define R_SPARC_M44 51 +#define R_SPARC_L44 52 +#define R_SPARC_REGISTER 53 +#define R_SPARC_UA64 54 +#define R_SPARC_UA16 55 +#define R_SPARC_TLS_GD_HI22 56 +#define R_SPARC_TLS_GD_LO10 57 +#define R_SPARC_TLS_GD_ADD 58 +#define R_SPARC_TLS_GD_CALL 59 +#define R_SPARC_TLS_LDM_HI22 60 +#define R_SPARC_TLS_LDM_LO10 61 +#define R_SPARC_TLS_LDM_ADD 62 +#define R_SPARC_TLS_LDM_CALL 63 +#define R_SPARC_TLS_LDO_HIX22 64 +#define R_SPARC_TLS_LDO_LOX10 65 +#define R_SPARC_TLS_LDO_ADD 66 +#define R_SPARC_TLS_IE_HI22 67 +#define R_SPARC_TLS_IE_LO10 68 +#define R_SPARC_TLS_IE_LD 69 +#define R_SPARC_TLS_IE_LDX 70 +#define R_SPARC_TLS_IE_ADD 71 +#define R_SPARC_TLS_LE_HIX22 72 +#define R_SPARC_TLS_LE_LOX10 73 +#define R_SPARC_TLS_DTPMOD32 74 +#define R_SPARC_TLS_DTPMOD64 75 +#define R_SPARC_TLS_DTPOFF32 76 +#define R_SPARC_TLS_DTPOFF64 77 +#define R_SPARC_TLS_TPOFF32 78 +#define R_SPARC_TLS_TPOFF64 79 + +#define R_X86_64_NONE 0 /* No relocation. */ +#define R_X86_64_64 1 /* Add 64 bit symbol value. */ +#define R_X86_64_PC32 2 /* PC-relative 32 bit signed sym value. */ +#define R_X86_64_GOT32 3 /* PC-relative 32 bit GOT offset. */ +#define R_X86_64_PLT32 4 /* PC-relative 32 bit PLT offset. */ +#define R_X86_64_COPY 5 /* Copy data from shared object. */ +#define R_X86_64_GLOB_DAT 6 /* Set GOT entry to data address. */ +#define R_X86_64_JMP_SLOT 7 /* Set GOT entry to code address. */ +#define R_X86_64_RELATIVE 8 /* Add load address of shared object. */ +#define R_X86_64_GOTPCREL 9 /* Add 32 bit signed pcrel offset to GOT. */ +#define R_X86_64_32 10 /* Add 32 bit zero extended symbol value */ +#define R_X86_64_32S 11 /* Add 32 bit sign extended symbol value */ +#define R_X86_64_16 12 /* Add 16 bit zero extended symbol value */ +#define R_X86_64_PC16 13 /* Add 16 bit signed extended pc relative symbol value */ +#define R_X86_64_8 14 /* Add 8 bit zero extended symbol value */ +#define R_X86_64_PC8 15 /* Add 8 bit signed extended pc relative symbol value */ +#define R_X86_64_DTPMOD64 16 /* ID of module containing symbol */ +#define R_X86_64_DTPOFF64 17 /* Offset in TLS block */ +#define R_X86_64_TPOFF64 18 /* Offset in static TLS block */ +#define R_X86_64_TLSGD 19 /* PC relative offset to GD GOT entry */ +#define R_X86_64_TLSLD 20 /* PC relative offset to LD GOT entry */ +#define R_X86_64_DTPOFF32 21 /* Offset in TLS block */ +#define R_X86_64_GOTTPOFF 22 /* PC relative offset to IE GOT entry */ +#define R_X86_64_TPOFF32 23 /* Offset in static TLS block */ +#define R_X86_64_IRELATIVE 37 + + +#endif /* !_SYS_ELF_COMMON_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/internal/elfheader/elfstructs.h b/sgx-jvm/linux-sgx/common/inc/internal/elfheader/elfstructs.h new file mode 100644 index 0000000000..77362f3b9e --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/elfheader/elfstructs.h @@ -0,0 +1,527 @@ +#ifndef __XEN_PUBLIC_ELFSTRUCTS_H__ +#define __XEN_PUBLIC_ELFSTRUCTS_H__ 1 +/* + * Copyright (c) 1995, 1996 Erik Theisen. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +typedef uint8_t Elf_Byte; + +typedef uint32_t Elf32_Addr; /* Unsigned program address */ +typedef uint32_t Elf32_Off; /* Unsigned file offset */ +typedef int32_t Elf32_Sword; /* Signed large integer */ +typedef uint32_t Elf32_Word; /* Unsigned large integer */ +typedef uint16_t Elf32_Half; /* Unsigned medium integer */ + +typedef uint64_t Elf64_Addr; +typedef uint64_t Elf64_Off; +typedef int32_t Elf64_Shalf; + +typedef int32_t Elf64_Sword; +typedef uint32_t Elf64_Word; + +typedef int64_t Elf64_Sxword; +typedef uint64_t Elf64_Xword; + +typedef uint32_t Elf64_Half; +typedef uint16_t Elf64_Quarter; + +/* + * e_ident[] identification indexes + * See http://www.caldera.com/developers/gabi/2000-07-17/ch4.eheader.html + */ +#define EI_MAG0 0 /* file ID */ +#define EI_MAG1 1 /* file ID */ +#define EI_MAG2 2 /* file ID */ +#define EI_MAG3 3 /* file ID */ +#define EI_CLASS 4 /* file class */ +#define EI_DATA 5 /* data encoding */ +#define EI_VERSION 6 /* ELF header version */ +#define EI_OSABI 7 /* OS/ABI ID */ +#define EI_ABIVERSION 8 /* ABI version */ +#define EI_PAD 9 /* start of pad bytes */ +#define EI_NIDENT 16 /* Size of e_ident[] */ + +/* e_ident[] magic number */ +#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */ +#define ELFMAG1 'E' /* e_ident[EI_MAG1] */ +#define ELFMAG2 'L' /* e_ident[EI_MAG2] */ +#define ELFMAG3 'F' /* e_ident[EI_MAG3] */ +#define ELFMAG "\177ELF" /* magic */ +#define SELFMAG 4 /* size of magic */ + +/* e_ident[] file class */ +#define ELFCLASSNONE 0 /* invalid */ +#define ELFCLASS32 1 /* 32-bit objs */ +#define ELFCLASS64 2 /* 64-bit objs */ +#define ELFCLASSNUM 3 /* number of classes */ + +/* e_ident[] data encoding */ +#define ELFDATANONE 0 /* invalid */ +#define ELFDATA2LSB 1 /* Little-Endian */ +#define ELFDATA2MSB 2 /* Big-Endian */ +#define ELFDATANUM 3 /* number of data encode defines */ + +/* e_ident[] Operating System/ABI */ +#define ELFOSABI_SYSV 0 /* UNIX System V ABI */ +#define ELFOSABI_HPUX 1 /* HP-UX operating system */ +#define ELFOSABI_NETBSD 2 /* NetBSD */ +#define ELFOSABI_LINUX 3 /* GNU/Linux */ +#define ELFOSABI_HURD 4 /* GNU/Hurd */ +#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */ +#define ELFOSABI_SOLARIS 6 /* Solaris */ +#define ELFOSABI_MONTEREY 7 /* Monterey */ +#define ELFOSABI_IRIX 8 /* IRIX */ +#define ELFOSABI_FREEBSD 9 /* FreeBSD */ +#define ELFOSABI_TRU64 10 /* TRU64 UNIX */ +#define ELFOSABI_MODESTO 11 /* Novell Modesto */ +#define ELFOSABI_OPENBSD 12 /* OpenBSD */ +#define ELFOSABI_ARM 97 /* ARM */ +#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ + +/* e_ident */ +#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ + (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ + (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ + (ehdr).e_ident[EI_MAG3] == ELFMAG3) + +/* ELF Header */ +typedef struct elfhdr { + unsigned char e_ident[EI_NIDENT]; /* ELF Identification */ + Elf32_Half e_type; /* object file type */ + Elf32_Half e_machine; /* machine */ + Elf32_Word e_version; /* object file version */ + Elf32_Addr e_entry; /* virtual entry point */ + Elf32_Off e_phoff; /* program header table offset */ + Elf32_Off e_shoff; /* section header table offset */ + Elf32_Word e_flags; /* processor-specific flags */ + Elf32_Half e_ehsize; /* ELF header size */ + Elf32_Half e_phentsize; /* program header entry size */ + Elf32_Half e_phnum; /* number of program header entries */ + Elf32_Half e_shentsize; /* section header entry size */ + Elf32_Half e_shnum; /* number of section header entries */ + Elf32_Half e_shstrndx; /* section header table's "section + header string table" entry offset */ +} Elf32_Ehdr; + +typedef struct { + unsigned char e_ident[EI_NIDENT]; /* Id bytes */ + Elf64_Quarter e_type; /* file type */ + Elf64_Quarter e_machine; /* machine type */ + Elf64_Half e_version; /* version number */ + Elf64_Addr e_entry; /* entry point */ + Elf64_Off e_phoff; /* Program hdr offset */ + Elf64_Off e_shoff; /* Section hdr offset */ + Elf64_Half e_flags; /* Processor flags */ + Elf64_Quarter e_ehsize; /* sizeof ehdr */ + Elf64_Quarter e_phentsize; /* Program header entry size */ + Elf64_Quarter e_phnum; /* Number of program headers */ + Elf64_Quarter e_shentsize; /* Section header entry size */ + Elf64_Quarter e_shnum; /* Number of section headers */ + Elf64_Quarter e_shstrndx; /* String table index */ +} Elf64_Ehdr; + +/* e_type */ +#define ET_NONE 0 /* No file type */ +#define ET_REL 1 /* relocatable file */ +#define ET_EXEC 2 /* executable file */ +#define ET_DYN 3 /* shared object file */ +#define ET_CORE 4 /* core file */ +#define ET_NUM 5 /* number of types */ +#define ET_LOPROC 0xff00 /* reserved range for processor */ +#define ET_HIPROC 0xffff /* specific e_type */ + +/* e_machine */ +#define EM_NONE 0 /* No Machine */ +#define EM_M32 1 /* AT&T WE 32100 */ +#define EM_SPARC 2 /* SPARC */ +#define EM_386 3 /* Intel 80386 */ +#define EM_68K 4 /* Motorola 68000 */ +#define EM_88K 5 /* Motorola 88000 */ +#define EM_486 6 /* Intel 80486 - unused? */ +#define EM_860 7 /* Intel 80860 */ +#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */ +/* + * Don't know if EM_MIPS_RS4_BE, + * EM_SPARC64, EM_PARISC, + * or EM_PPC are ABI compliant + */ +#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ +#define EM_SPARC64 11 /* SPARC v9 64-bit unoffical */ +#define EM_PARISC 15 /* HPPA */ +#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ +#define EM_PPC 20 /* PowerPC */ +#define EM_PPC64 21 /* PowerPC 64-bit */ +#define EM_ARM 40 /* Advanced RISC Machines ARM */ +#define EM_ALPHA 41 /* DEC ALPHA */ +#define EM_SPARCV9 43 /* SPARC version 9 */ +#define EM_ALPHA_EXP 0x9026 /* DEC ALPHA */ +#define EM_IA_64 50 /* Intel Merced */ +#define EM_X86_64 62 /* AMD x86-64 architecture */ +#define EM_VAX 75 /* DEC VAX */ + +/* Version */ +#define EV_NONE 0 /* Invalid */ +#define EV_CURRENT 1 /* Current */ +#define EV_NUM 2 /* number of versions */ + +/* Section Header */ +typedef struct { + Elf32_Word sh_name; /* name - index into section header + string table section */ + Elf32_Word sh_type; /* type */ + Elf32_Word sh_flags; /* flags */ + Elf32_Addr sh_addr; /* address */ + Elf32_Off sh_offset; /* file offset */ + Elf32_Word sh_size; /* section size */ + Elf32_Word sh_link; /* section header table index link */ + Elf32_Word sh_info; /* extra information */ + Elf32_Word sh_addralign; /* address alignment */ + Elf32_Word sh_entsize; /* section entry size */ +} Elf32_Shdr; + +typedef struct { + Elf64_Half sh_name; /* section name */ + Elf64_Half sh_type; /* section type */ + Elf64_Xword sh_flags; /* section flags */ + Elf64_Addr sh_addr; /* virtual address */ + Elf64_Off sh_offset; /* file offset */ + Elf64_Xword sh_size; /* section size */ + Elf64_Half sh_link; /* link to another */ + Elf64_Half sh_info; /* misc info */ + Elf64_Xword sh_addralign; /* memory alignment */ + Elf64_Xword sh_entsize; /* table entry size */ +} Elf64_Shdr; + +/* Special Section Indexes */ +#define SHN_UNDEF 0 /* undefined */ +#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */ +#define SHN_LOPROC 0xff00 /* reserved range for processor */ +#define SHN_HIPROC 0xff1f /* specific section indexes */ +#define SHN_ABS 0xfff1 /* absolute value */ +#define SHN_COMMON 0xfff2 /* common symbol */ +#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */ + +/* sh_type */ +#define SHT_NULL 0 /* inactive */ +#define SHT_PROGBITS 1 /* program defined information */ +#define SHT_SYMTAB 2 /* symbol table section */ +#define SHT_STRTAB 3 /* string table section */ +#define SHT_RELA 4 /* relocation section with addends*/ +#define SHT_HASH 5 /* symbol hash table section */ +#define SHT_DYNAMIC 6 /* dynamic section */ +#define SHT_NOTE 7 /* note section */ +#define SHT_NOBITS 8 /* no space section */ +#define SHT_REL 9 /* relation section without addends */ +#define SHT_SHLIB 10 /* reserved - purpose unknown */ +#define SHT_DYNSYM 11 /* dynamic symbol table section */ +#define SHT_NUM 12 /* number of section types */ +#define SHT_LOPROC 0x70000000 /* reserved range for processor */ +#define SHT_HIPROC 0x7fffffff /* specific section header types */ +#define SHT_LOUSER 0x80000000 /* reserved range for application */ +#define SHT_HIUSER 0xffffffff /* specific indexes */ + +/* Section names */ +#define ELF_BSS ".bss" /* uninitialized data */ +#define ELF_DATA ".data" /* initialized data */ +#define ELF_DEBUG ".debug" /* debug */ +#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */ +#define ELF_DYNSTR ".dynstr" /* dynamic string table */ +#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */ +#define ELF_FINI ".fini" /* termination code */ +#define ELF_GOT ".got" /* global offset table */ +#define ELF_HASH ".hash" /* symbol hash table */ +#define ELF_INIT ".init" /* initialization code */ +#define ELF_REL_DATA ".rel.data" /* relocation data */ +#define ELF_REL_FINI ".rel.fini" /* relocation termination code */ +#define ELF_REL_INIT ".rel.init" /* relocation initialization code */ +#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */ +#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */ +#define ELF_REL_TEXT ".rel.text" /* relocation code */ +#define ELF_RODATA ".rodata" /* read-only data */ +#define ELF_SHSTRTAB ".shstrtab" /* section header string table */ +#define ELF_STRTAB ".strtab" /* string table */ +#define ELF_SYMTAB ".symtab" /* symbol table */ +#define ELF_TEXT ".text" /* code */ + + +/* Section Attribute Flags - sh_flags */ +#define SHF_WRITE 0x1 /* Writable */ +#define SHF_ALLOC 0x2 /* occupies memory */ +#define SHF_EXECINSTR 0x4 /* executable */ +#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */ + /* specific section attributes */ + +/* Symbol Table Entry */ +typedef struct elf32_sym { + Elf32_Word st_name; /* name - index into string table */ + Elf32_Addr st_value; /* symbol value */ + Elf32_Word st_size; /* symbol size */ + unsigned char st_info; /* type and binding */ + unsigned char st_other; /* 0 - no defined meaning */ + Elf32_Half st_shndx; /* section header index */ +} Elf32_Sym; + +typedef struct { + Elf64_Half st_name; /* Symbol name index in str table */ + Elf_Byte st_info; /* type / binding attrs */ + Elf_Byte st_other; /* unused */ + Elf64_Quarter st_shndx; /* section index of symbol */ + Elf64_Xword st_value; /* value of symbol */ + Elf64_Xword st_size; /* size of symbol */ +} Elf64_Sym; + +/* Symbol table index */ +#define STN_UNDEF 0 /* undefined */ + +/* Extract symbol info - st_info */ +#define ELF32_ST_BIND(x) ((x) >> 4) +#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf) +#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf)) + +#define ELF64_ST_BIND(x) ((x) >> 4) +#define ELF64_ST_TYPE(x) (((unsigned int) x) & 0xf) +#define ELF64_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf)) + +/* Symbol Binding - ELF32_ST_BIND - st_info */ +#define STB_LOCAL 0 /* Local symbol */ +#define STB_GLOBAL 1 /* Global symbol */ +#define STB_WEAK 2 /* like global - lower precedence */ +#define STB_NUM 3 /* number of symbol bindings */ +#define STB_LOPROC 13 /* reserved range for processor */ +#define STB_HIPROC 15 /* specific symbol bindings */ + +/* Symbol type - ELF32_ST_TYPE - st_info */ +#define STT_NOTYPE 0 /* not specified */ +#define STT_OBJECT 1 /* data object */ +#define STT_FUNC 2 /* function */ +#define STT_SECTION 3 /* section */ +#define STT_FILE 4 /* file */ +#define STT_NUM 5 /* number of symbol types */ +#define STT_LOPROC 13 /* reserved range for processor */ +#define STT_HIPROC 15 /* specific symbol types */ + +/* Relocation entry with implicit addend */ +typedef struct { + Elf32_Addr r_offset; /* offset of relocation */ + Elf32_Word r_info; /* symbol table index and type */ +} Elf32_Rel; + +/* Relocation entry with explicit addend */ +typedef struct { + Elf32_Addr r_offset; /* offset of relocation */ + Elf32_Word r_info; /* symbol table index and type */ + Elf32_Sword r_addend; +} Elf32_Rela; + +/* Extract relocation info - r_info */ +#define ELF32_R_SYM(i) ((i) >> 8) +#define ELF32_R_TYPE(i) ((unsigned char) (i)) +#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t)) + +typedef struct { + Elf64_Xword r_offset; /* where to do it */ + Elf64_Xword r_info; /* index & type of relocation */ +} Elf64_Rel; + +typedef struct { + Elf64_Xword r_offset; /* where to do it */ + Elf64_Xword r_info; /* index & type of relocation */ + Elf64_Sxword r_addend; /* adjustment value */ +} Elf64_Rela; + +#define ELF64_R_SYM(info) ((info) >> 32) +#define ELF64_R_TYPE(info) ((info) & 0xFFFFFFFF) +#define ELF64_R_INFO(s,t) (((s) << 32) + (u_int32_t)(t)) + +/* Program Header */ +typedef struct { + Elf32_Word p_type; /* segment type */ + Elf32_Off p_offset; /* segment offset */ + Elf32_Addr p_vaddr; /* virtual address of segment */ + Elf32_Addr p_paddr; /* physical address - ignored? */ + Elf32_Word p_filesz; /* number of bytes in file for seg. */ + Elf32_Word p_memsz; /* number of bytes in mem. for seg. */ + Elf32_Word p_flags; /* flags */ + Elf32_Word p_align; /* memory alignment */ +} Elf32_Phdr; + +typedef struct { + Elf64_Half p_type; /* entry type */ + Elf64_Half p_flags; /* flags */ + Elf64_Off p_offset; /* offset */ + Elf64_Addr p_vaddr; /* virtual address */ + Elf64_Addr p_paddr; /* physical address */ + Elf64_Xword p_filesz; /* file size */ + Elf64_Xword p_memsz; /* memory size */ + Elf64_Xword p_align; /* memory & file alignment */ +} Elf64_Phdr; + +/* Segment types - p_type */ +#define PT_NULL 0 /* unused */ +#define PT_LOAD 1 /* loadable segment */ +#define PT_DYNAMIC 2 /* dynamic linking section */ +#define PT_INTERP 3 /* the RTLD */ +#define PT_NOTE 4 /* auxiliary information */ +#define PT_SHLIB 5 /* reserved - purpose undefined */ +#define PT_PHDR 6 /* program header */ +#define PT_NUM 7 /* Number of segment types */ +#define PT_LOPROC 0x70000000 /* reserved range for processor */ +#define PT_HIPROC 0x7fffffff /* specific segment types */ + +/* Segment flags - p_flags */ +#define PF_X 0x1 /* Executable */ +#define PF_W 0x2 /* Writable */ +#define PF_R 0x4 /* Readable */ +#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */ + /* specific segment flags */ + +/* Dynamic structure */ +typedef struct { + Elf32_Sword d_tag; /* controls meaning of d_val */ + union { + Elf32_Word d_val; /* Multiple meanings - see d_tag */ + Elf32_Addr d_ptr; /* program virtual address */ + } d_un; +} Elf32_Dyn; + +typedef struct { + Elf64_Xword d_tag; /* controls meaning of d_val */ + union { + Elf64_Addr d_ptr; + Elf64_Xword d_val; + } d_un; +} Elf64_Dyn; + +/* Dynamic Array Tags - d_tag */ +#define DT_NULL 0 /* marks end of _DYNAMIC array */ +#define DT_NEEDED 1 /* string table offset of needed lib */ +#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */ +#define DT_PLTGOT 3 /* address PLT/GOT */ +#define DT_HASH 4 /* address of symbol hash table */ +#define DT_STRTAB 5 /* address of string table */ +#define DT_SYMTAB 6 /* address of symbol table */ +#define DT_RELA 7 /* address of relocation table */ +#define DT_RELASZ 8 /* size of relocation table */ +#define DT_RELAENT 9 /* size of relocation entry */ +#define DT_STRSZ 10 /* size of string table */ +#define DT_SYMENT 11 /* size of symbol table entry */ +#define DT_INIT 12 /* address of initialization func. */ +#define DT_FINI 13 /* address of termination function */ +#define DT_SONAME 14 /* string table offset of shared obj */ +#define DT_RPATH 15 /* string table offset of library + search path */ +#define DT_SYMBOLIC 16 /* start sym search in shared obj. */ +#define DT_REL 17 /* address of rel. tbl. w addends */ +#define DT_RELSZ 18 /* size of DT_REL relocation table */ +#define DT_RELENT 19 /* size of DT_REL relocation entry */ +#define DT_PLTREL 20 /* PLT referenced relocation entry */ +#define DT_DEBUG 21 /* bugger */ +#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */ +#define DT_JMPREL 23 /* add. of PLT's relocation entries */ +#define DT_BIND_NOW 24 /* Bind now regardless of env setting */ +#define DT_NUM 25 /* Number used. */ +#define DT_LOPROC 0x70000000 /* reserved range for processor */ +#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */ + +/* Standard ELF hashing function */ +unsigned int elf_hash(const unsigned char *name); + +/* + * Note Definitions + */ +typedef struct { + Elf32_Word namesz; + Elf32_Word descsz; + Elf32_Word type; +} Elf32_Note; + +typedef struct { + Elf64_Half namesz; + Elf64_Half descsz; + Elf64_Half type; +} Elf64_Note; + + +#if defined(ELFSIZE) +#define CONCAT(x,y) __CONCAT(x,y) +#define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x))) +#define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y)))) +#define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE)) +#define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x))) +#endif + +#if defined(ELFSIZE) && (ELFSIZE == 32) +#define Elf_Ehdr Elf32_Ehdr +#define Elf_Phdr Elf32_Phdr +#define Elf_Shdr Elf32_Shdr +#define Elf_Sym Elf32_Sym +#define Elf_Rel Elf32_Rel +#define Elf_RelA Elf32_Rela +#define Elf_Dyn Elf32_Dyn +#define Elf_Word Elf32_Word +#define Elf_Sword Elf32_Sword +#define Elf_Addr Elf32_Addr +#define Elf_Off Elf32_Off +#define Elf_Nhdr Elf32_Nhdr +#define Elf_Note Elf32_Note + +#define ELF_R_SYM ELF32_R_SYM +#define ELF_R_TYPE ELF32_R_TYPE +#define ELF_R_INFO ELF32_R_INFO +#define ELFCLASS ELFCLASS32 + +#define ELF_ST_BIND ELF32_ST_BIND +#define ELF_ST_TYPE ELF32_ST_TYPE +#define ELF_ST_INFO ELF32_ST_INFO + +#define AuxInfo Aux32Info +#elif defined(ELFSIZE) && (ELFSIZE == 64) +#define Elf_Ehdr Elf64_Ehdr +#define Elf_Phdr Elf64_Phdr +#define Elf_Shdr Elf64_Shdr +#define Elf_Sym Elf64_Sym +#define Elf_Rel Elf64_Rel +#define Elf_RelA Elf64_Rela +#define Elf_Dyn Elf64_Dyn +#define Elf_Word Elf64_Word +#define Elf_Sword Elf64_Sword +#define Elf_Addr Elf64_Addr +#define Elf_Off Elf64_Off +#define Elf_Nhdr Elf64_Nhdr +#define Elf_Note Elf64_Note + +#define ELF_R_SYM ELF64_R_SYM +#define ELF_R_TYPE ELF64_R_TYPE +#define ELF_R_INFO ELF64_R_INFO +#define ELFCLASS ELFCLASS64 + +#define ELF_ST_BIND ELF64_ST_BIND +#define ELF_ST_TYPE ELF64_ST_TYPE +#define ELF_ST_INFO ELF64_ST_INFO + +#define AuxInfo Aux64Info +#endif + +#endif /* __XEN_PUBLIC_ELFSTRUCTS_H__ */ diff --git a/sgx-jvm/linux-sgx/common/inc/internal/enclave_creator.h b/sgx-jvm/linux-sgx/common/inc/internal/enclave_creator.h new file mode 100644 index 0000000000..c7f25088de --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/enclave_creator.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/** + * File: enclave_creator.h + * Description: this header file defines the interface used by Enclave loader to create the Enclave + * + * The hardware, simulation and signing mode shall inherit from this class and + * implement all the virtual functions + */ + +#ifndef _ENCLAVE_CREATOR_H +#define _ENCLAVE_CREATOR_H + +#include "arch.h" +#include "sgx_eid.h" +#include "metadata.h" +#include "sgx_error.h" +#include "util.h" +#include "launch_checker.h" +#include "uncopyable.h" +#include +#include "file.h" + +// this is the interface to both hardware, simulation and signing mode +class EnclaveCreator : private Uncopyable +{ +public: + /* + @quote the EPC reserved; + @enclave_id identify the unique enclave; + @start_addr is the linear address allocated for Enclave; + */ + virtual int create_enclave(secs_t *secs, sgx_enclave_id_t *enclave_id, void **start_addr, bool ae = false) = 0; + /* + *@attr can be REMOVABLE + */ + virtual int add_enclave_page(sgx_enclave_id_t enclave_id, void *source, uint64_t offset, const sec_info_t &sinfo, uint32_t attr) = 0; + virtual int init_enclave(sgx_enclave_id_t enclave_id, enclave_css_t *enclave_css, SGXLaunchToken *lc, le_prd_css_file_t *prd_css_file = NULL) = 0; + virtual int destroy_enclave(sgx_enclave_id_t enclave_id, uint64_t enclave_size = 0) = 0; + virtual int initialize(sgx_enclave_id_t enclave_id) = 0; + virtual bool use_se_hw() const = 0; + + virtual int get_misc_attr(sgx_misc_attribute_t *sgx_misc_attr, metadata_t *metadata, SGXLaunchToken * const lc, uint32_t flag) = 0; + virtual bool get_plat_cap(sgx_misc_attribute_t *se_attr) = 0; +#ifdef SE_1P5_VERTICAL + virtual uint32_t handle_page_fault(uint64_t pf_address) { UNUSED(pf_address); return (uint32_t)SGX_ERROR_UNEXPECTED; } +#endif + // destructor + virtual ~EnclaveCreator() {}; +}; + +EnclaveCreator* get_enclave_creator(void); + +extern EnclaveCreator* g_enclave_creator; + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/global_data.h b/sgx-jvm/linux-sgx/common/inc/internal/global_data.h new file mode 100644 index 0000000000..be1e97eec8 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/global_data.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/** + * File: global_data.h + * Description: + * The file defines the structure global_data_t. + */ + +#ifndef _TRTS_GLOBAL_DATA_H_ +#define _TRTS_GLOBAL_DATA_H_ + +#include "se_types.h" +#include "thread_data.h" + +typedef struct _global_data_t +{ + sys_word_t enclave_size; + sys_word_t heap_offset; + sys_word_t heap_size; + uint32_t thread_policy; + uint32_t reserved; + thread_data_t td_template; +} global_data_t; + +#define ENCLAVE_INIT_NOT_STARTED 0 +#define ENCLAVE_INIT_IN_PROGRESS 1 +#define ENCLAVE_INIT_DONE 2 +#define ENCLAVE_CRASHED 3 + +#ifdef __cplusplus +extern "C" { +#endif +extern SE_DECLSPEC_EXPORT global_data_t const volatile g_global_data; +extern uint32_t g_enclave_state; +extern uint8_t __ImageBase; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/global_init.h b/sgx-jvm/linux-sgx/common/inc/internal/global_init.h new file mode 100644 index 0000000000..d7a36530cb --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/global_init.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GLOBAL_INIT_H +#define GLOBAL_INIT_H + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +void init_global_object(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/inst.h b/sgx-jvm/linux-sgx/common/inc/internal/inst.h new file mode 100644 index 0000000000..cd09c5a939 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/inst.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_ARCH_H_ +# error "never include inst.h directly; use arch.h instead." +#endif + + +#ifndef _SE_INST_H_ +#define _SE_INST_H_ + +#define ENCLU 0xd7010f + +typedef enum { + SE_EREPORT = 0x0, + SE_EGETKEY, + SE_EENTER, + SE_ERESUME, + SE_EEXIT, + SE_LAST_RING3, + + SE_ECREATE = 0x0, + SE_EADD, + SE_EINIT, + SE_EREMOVE, + SE_EDBGRD, + SE_EDBGWR, + SE_EEXTEND, + SE_LAST_RING0 +} se_opcode_t; + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/ipp_wrapper.h b/sgx-jvm/linux-sgx/common/inc/internal/ipp_wrapper.h new file mode 100644 index 0000000000..242a041c3b --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/ipp_wrapper.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _IPP_WRAPPER_H +#define _IPP_WRAPPER_H + +#include "ippcp.h" + +#ifndef SAFE_FREE_MM +#define SAFE_FREE_MM(ptr) {\ + if(ptr != NULL) \ + { \ + free(ptr); \ + ptr = NULL; \ + }} +#endif + +#ifndef ERROR_BREAK +#define ERROR_BREAK(x) if(x != ippStsNoErr){break;} +#endif +#ifndef NULL_BREAK +#define NULL_BREAK(x) if(!x){break;} +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +IppStatus newBN(const Ipp32u *data, int size_in_bytes, IppsBigNumState **p_new_BN); + +IppStatus create_rsa_priv1_key(int n_byte_size, int d_byte_size, const Ipp32u *n, const Ipp32u *d, IppsRSAPrivateKeyState **new_pri_key1); + +IppStatus create_rsa_priv2_key(int p_byte_size, const Ipp32u *p, const Ipp32u *q, + const Ipp32u *dmp1, const Ipp32u *dmq1, const Ipp32u *iqmp, + IppsRSAPrivateKeyState **new_pri_key2); + +IppStatus create_rsa_pub_key(int n_byte_size, int e_byte_size, const Ipp32u *n, const Ipp32u *e, IppsRSAPublicKeyState **new_pub_key); + +IppStatus create_validate_rsa_key_pair(int n_byte_size, int e_byte_size, const Ipp32u *n, const Ipp32u *d, const Ipp32u *e, const Ipp32u *p, const Ipp32u *q, + const Ipp32u *dmp1, const Ipp32u *dmq1, const Ipp32u *iqmp, + IppsRSAPrivateKeyState **new_pri_key, IppsRSAPublicKeyState **new_pub_key, int *validate_result); + +IppStatus get_pub_key(const IppsRSAPublicKeyState *pub_key, int *e_byte_size, Ipp32u *e, int *n_byte_size, Ipp32u *n); + +void secure_free_BN(IppsBigNumState *pBN, int size_in_bytes); + +void secure_free_rsa_pri1_key(int n_byte_size, int d_byte_size, IppsRSAPrivateKeyState *pri_key1); + +void secure_free_rsa_pri2_key(int p_byte_size, IppsRSAPrivateKeyState *pri_key2); + +void secure_free_rsa_pub_key(int n_byte_size, int e_byte_size, IppsRSAPublicKeyState *pub_key); + + + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/sgx-jvm/linux-sgx/common/inc/internal/linux/cpuid_gnu.h b/sgx-jvm/linux-sgx/common/inc/internal/linux/cpuid_gnu.h new file mode 100644 index 0000000000..5fd907162f --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/linux/cpuid_gnu.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _CPUID_GNU_H_ +#define _CPUID_GNU_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* This is a PIC-compliant version of CPUID */ +static inline void cpuid(int *eax, int *ebx, int *ecx, int *edx) +{ +#if defined(__x86_64__) + asm("cpuid" + : "=a" (*eax), + "=b" (*ebx), + "=c" (*ecx), + "=d" (*edx) + : "0" (*eax), "2" (*ecx)); + +#else + /*on 32bit, ebx can NOT be used as PIC code*/ + asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" + : "=a" (*eax), "=r" (*ebx), "=c" (*ecx), "=d" (*edx) + : "0" (*eax), "2" (*ecx)); +#endif +} + +static inline void __cpuid(int a[4], int b) +{ + a[0] = b; + a[2] = 0; + cpuid(&a[0], &a[1], &a[2], &a[3]); +} + +static inline void __cpuidex(int a[4], int b, int c) +{ + a[0] = b; + a[2] = c; + cpuid(&a[0], &a[1], &a[2], &a[3]); +} + +#ifdef __cplusplus +} +#endif + +#endif /*_CPUID_GNU_H_*/ diff --git a/sgx-jvm/linux-sgx/common/inc/internal/linux/linux-regs.h b/sgx-jvm/linux-sgx/common/inc/internal/linux/linux-regs.h new file mode 100644 index 0000000000..1ebed38720 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/linux/linux-regs.h @@ -0,0 +1,272 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* + * This header wraps the register names for x86/x64. + */ + +#ifndef LINUX_REGS_H__ +#define LINUX_REGS_H__ + +#if defined(__i386) || defined(__i386__) +# define LINUX32 1 +# define SE_WORDSIZE 4 + +/* Generic argument picker for `naked' functions */ +# define naked_arg0 4(%esp) +# define naked_arg1 8(%esp) +# define naked_arg2 12(%esp) +# define naked_arg3 16(%esp) + +# define xax eax +# define xbx ebx +# define xcx ecx +# define xdx edx + +# define xsi esi +# define xdi edi +# define xbp ebp +# define xsp esp +#elif defined(__x86_64) || defined(__x86_64__) +# define LINUX64 1 +# define SE_WORDSIZE 8 + +/* For x86_64, the first six parameters are passed by + * rdi, rsi, rdx, rcx, r8, r9. + */ +# define naked_arg0 %rdi +# define naked_arg1 %rsi +# define naked_arg2 %rdx +# define naked_arg3 %rcx + +# define xax rax +# define xbx rbx +# define xcx rcx +# define xdx rdx + +# define xsi rsi +# define xdi rdi +# define xbp rbp +# define xsp rsp +#else +# error unknown platform! +#endif + +/* SE instructions - needs to be sync-up with inst70.h */ +#define SE_EREPORT 0 +#define SE_EGETKEY 1 +#define SE_EENTER 2 +#define SE_EEXIT 4 + +#define SE_ECREATE 0 +#define SE_EADD 1 +#define SE_EINIT 2 +#define SE_EREMOVE 3 + +/* + * Macros for GNU assembly + */ +.macro ENCLU +#ifdef SE_SIM + cmp $SE_EEXIT, %xax + jne 1f + + /* if leaf is EEXIT, xbp and xsp need to be passed by xdx and xcx */ + mov %xbp, %xdx + mov %xsp, %xcx +1: + push %xdi + push %xsi + push %xdx + push %xcx + push %xbx + push %xax + +# ifdef LINUX64 + pop %rdi + pop %rsi + pop %rdx + pop %rcx + pop %r8 + pop %r9 +# endif + +.type _SE3,@function +.protected _SE3 + call _SE3 + +# ifdef LINUX32 + add $(SE_WORDSIZE * 6), %esp +# endif + +#else /* SE_SIM */ +.byte 0x0f, 0x01, 0xd7 /* 0xf3 */ +#endif /* !SE_SIM */ +.endm + +/* declare a function with default visibility */ +.macro DECLARE_GLOBAL_FUNC name + .globl \name + .type \name, @function +\name: +.endm + +/* declare a function with visibility='hidden' */ +.macro DECLARE_LOCAL_FUNC name + .globl \name + .hidden \name + .type \name, @function +\name: +.endm + +.macro NAKED_PROLOG + push %xbp + mov %xsp, %xbp + sub $(7 * SE_WORDSIZE), %xsp +.endm + +.macro NAKED_EPILOG + mov %xbp, %xsp + pop %xbp +.endm + +/* `paramN' (N = 1,2,3,4) should be registers. */ +.macro SET_PARAMS param1:req, param2, param3, param4 +#if defined(LINUX32) + +.ifnb \param4 + mov \param4, 3*SE_WORDSIZE(%esp) +.endif + +.ifnb \param3 + mov \param3, 2*SE_WORDSIZE(%esp) +.endif + +.ifnb \param2 + mov \param2, 1*SE_WORDSIZE(%esp) +.endif + + mov \param1, 0*SE_WORDSIZE(%esp) + +#else /* LINUX32 */ + +.ifnb \param4 +.ifnc \param4, %rcx + mov \param4, %rcx +.endif +.endif + +.ifnb \param3 +.ifnc \param3, %rdx + mov \param3, %rdx +.endif +.endif + +.ifnb \param2 +.ifnc \param2, %rsi + mov \param2, %rsi +.endif +.endif + +.ifnc \param1, %rdi + mov \param1, %rdi +.endif + +#endif /* LINUX64 */ +.endm + +/*******************************************************************/ + +.macro SE_PROLOG + .cfi_startproc + +#ifdef LINUX32 + pushl %ebp + movl %esp, %ebp +#endif + + push %xbx + push %xcx + push %xdx + +#if defined LINUX64 + movq %rdi, %rbx + movq %rsi, %rcx + /* rdx remains the same, rdi/rsi is not used by _SE0 + */ +#elif defined LINUX32 + movl 2*SE_WORDSIZE(%ebp), %ebx + movl 3*SE_WORDSIZE(%ebp), %ecx + movl 4*SE_WORDSIZE(%ebp), %edx +#endif + +.endm + +/*******************************************************************/ + +.macro SE_EPILOG + pop %xdx + pop %xcx + pop %xbx + +#ifdef LINUX32 + movl %ebp, %esp + popl %ebp +#endif + + ret + .cfi_endproc +.endm + +/*******************************************************************/ + +/* load the address of `symbol' to the register `reg' in PIC way. */ +.macro lea_pic symbol, reg +#ifdef LINUX64 + lea \symbol(%rip), \reg +#else +/* The real code on x86 would look like this (get `bar' from `foo'): + * + * 00000198 : + * 198: c3 ret + * + * 00000199 : + * 199: e8 00 00 00 00 call 19e + * 19e: 58 pop %eax + * 19f: 8d 40 fa lea -0x6(%eax),%eax + */ + call . + 0x5 /* No label here to avoid interfering w/ calling code */ + pop \reg + lea (\symbol - . + 1)(\reg), \reg +#endif +.endm + +#endif /* LINUX_REGS_H__ */ diff --git a/sgx-jvm/linux-sgx/common/inc/internal/linux/xsave_gnu.h b/sgx-jvm/linux-sgx/common/inc/internal/linux/xsave_gnu.h new file mode 100644 index 0000000000..5466ba5de6 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/linux/xsave_gnu.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _XSAVE_GNU_H_ +#define _XSAVE_GNU_H_ + +#include "se_types.h" + +#ifdef __x86_64__ +# define ASM_FXSAVE "rex64/fxsave" +# define ASM_FXRSTR "rex64/fxrstor" +# define ASM_XSAVE ".byte 0x48,0x0f,0xae,0x21" +# define ASM_XRSTR ".byte 0x48,0x0f,0xae,0x2f" +#else +# define ASM_FXSAVE "fxsave" +# define ASM_FXRSTR "fxrstor" +# define ASM_XSAVE ".byte 0x0f,0xae,0x21" +# define ASM_XRSTR ".byte 0x0f,0xae,0x2f" +#endif + +static inline void do_fwait(void) +{ + asm volatile("fwait"); +} + +static inline void do_fxsave(void *buffer) +{ + asm volatile(ASM_FXSAVE" (%0)" : : "r"(buffer) : "memory"); +} + +static inline void do_fxrstor(const void *buffer) +{ + asm volatile(ASM_FXRSTR" (%0)" : : "r"(buffer)); +} + +static inline void do_xsave(void *buffer) +{ + asm volatile(ASM_XSAVE + : + : "D" (buffer), "a" (-1), "d" (-1) + : "memory"); +} + +static inline void _do_xrstor(const void *buffer, uint64_t mask) +{ + uint32_t lmask = (uint32_t)mask; + uint32_t hmask = (uint32_t)(mask >> 32); + + asm volatile(ASM_XRSTR + : + : "D" (buffer), "a" (lmask), "d" (hmask)); +} + +static inline void do_xrstor(const void *buffer) +{ + _do_xrstor(buffer, 0xffffffffffffffffULL); +} + +static inline void do_vzeroupper() +{ + asm volatile("vzeroupper"); +} + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/metadata.h b/sgx-jvm/linux-sgx/common/inc/internal/metadata.h new file mode 100644 index 0000000000..031af632e2 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/metadata.h @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _METADATA_H_ +#define _METADATA_H_ +#include "arch.h" +#include "se_macro.h" + +#pragma pack(1) + + /* version of metadata */ +#define MAJOR_VERSION 1 /* MAJOR_VERSION should not larger than 0ffffffff */ +#define MINOR_VERSION 3 /* MINOR_VERSION should not larger than 0ffffffff */ + +#define META_DATA_MAKE_VERSION(major, minor) (((uint64_t)major)<<32 | minor) + +#define METADATA_MAGIC 0x86A80294635D0E4CULL +#define METADATA_SIZE 0x1000 +/* TCS Policy bit masks */ +#define TCS_POLICY_BIND 0x00000000 /* If set, the TCS is bound to the application thread */ +#define TCS_POLICY_UNBIND 0x00000001 + +#define MAX_SAVE_BUF_SIZE 2632 + +#define TCS_NUM_MIN 1 +#define SSA_NUM_MIN 2 +#define SSA_FRAME_SIZE_MIN 1 +#define SSA_FRAME_SIZE_MAX 2 +#define STACK_SIZE_MIN 0x1000 +#define HEAP_SIZE_MIN 0 +#define DEFAULT_MISC_SELECT 0 +#define DEFAULT_MISC_MASK 0xFFFFFFFF + +typedef struct _data_directory_t +{ + uint32_t offset; + uint32_t size; +} data_directory_t; + +typedef enum +{ + DIR_PATCH, + DIR_LAYOUT, + DIR_NUM, +} dir_index_t; + +#define GROUP_FLAG (1<<12) +#define GROUP_ID(x) (GROUP_FLAG | x) +#define IS_GROUP_ID(x) !!((x) & GROUP_FLAG) +#define LAYOUT_ID_HEAP 1 +#define LAYOUT_ID_TCS 2 +#define LAYOUT_ID_TD 3 +#define LAYOUT_ID_SSA 4 +#define LAYOUT_ID_STACK 5 +#define LAYOUT_ID_THREAD_GROUP GROUP_ID(6) +#define LAYOUT_ID_GUARD 7 + +/* +** layout table example +** entry0 - entry1 - entry2 - group3 (entry_count=2, load_times=3) ... +** the load sequence should be: +** entry0 - entry1 - entry2 - entry1 - entry2 - entry1 - entry2 - entry1 - entry2 ... +** -------------- -------------- -------------- +** group3 1st time group3 2nd time group3 3rd time +*/ +typedef struct _layout_entry_t +{ + uint16_t id; /* unique ID to identify the purpose for this entry */ + uint16_t attributes; /* EADD/EEXTEND/EREMOVE... */ + uint32_t page_count; /* map size in page. Biggest chunk = 2^32 pages = 2^44 bytes. */ + uint64_t rva; /* map offset, relative to encalve base */ + uint32_t content_size; /* if content_offset = 0, content_size is the initial data to fill the whole page. */ + uint32_t content_offset; /* offset to the initial content, relative to metadata */ + si_flags_t si_flags; /* security info, R/W/X, SECS/TCS/REG/VA */ +} layout_entry_t; + +typedef struct _layout_group_t +{ + uint16_t id; /* unique ID to identify the purpose for this entry */ + uint16_t entry_count; /* reversely count entry_count entries for the group loading. */ + uint32_t load_times; /* the repeated times of loading */ + uint64_t load_step; /* the group size. the entry load rva should be adjusted with the load_step */ + /* rva = entry.rva + group.load_step * load_times */ + uint32_t reserved[4]; +} layout_group_t; + +typedef union _layout_t +{ + layout_entry_t entry; + layout_group_t group; +} layout_t; + +typedef struct _patch_entry_t +{ + uint64_t dst; /* relative to enclave file base */ + uint32_t src; /* relative to metadata base */ + uint32_t size; /* patched size */ + uint32_t reserved[4]; +} patch_entry_t; + +typedef struct _metadata_t +{ + uint64_t magic_num; /* The magic number identifying the file as a signed enclave image */ + uint64_t version; /* The metadata version */ + uint32_t size; /* The size of this structure */ + uint32_t tcs_policy; /* TCS management policy */ + uint32_t ssa_frame_size; /* The size of SSA frame in page */ + uint32_t max_save_buffer_size; /* Max buffer size is 2632 */ + uint32_t desired_misc_select; + uint32_t reserved; + uint64_t enclave_size; /* enclave virtual size */ + sgx_attributes_t attributes; /* XFeatureMask to be set in SECS. */ + enclave_css_t enclave_css; /* The enclave signature */ + data_directory_t dirs[DIR_NUM]; + uint8_t data[2208]; +}metadata_t; + +se_static_assert(sizeof(metadata_t) == METADATA_SIZE); + +#pragma pack() + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/oal/uae_oal_api.h b/sgx-jvm/linux-sgx/common/inc/internal/oal/uae_oal_api.h new file mode 100644 index 0000000000..42c917dddb --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/oal/uae_oal_api.h @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _UAE_OAL_H +#define _UAE_OAL_H + +#include "sgx_quote.h" +#include "sgx_error.h" +#include "sgx_urts.h" +#include +#include + +typedef enum{ + UAE_OAL_SUCCESS = 0, + UAE_OAL_ERROR_UNEXPECTED , + UAE_OAL_ERROR_AESM_UNAVAILABLE , + UAE_OAL_ERROR_TIMEOUT , +} uae_oal_status_t; + +/*OAL methods from here forward */ + +extern "C" +{ + +uae_oal_status_t SGXAPI oal_get_launch_token( + const enclave_css_t* signature, + const sgx_attributes_t* attribute, + sgx_launch_token_t* launch_token, + uint32_t timeout_usec, + aesm_error_t *result); + + +uae_oal_status_t SGXAPI oal_init_quote( + sgx_target_info_t *p_target_info, + sgx_epid_group_id_t *p_gid, + uint32_t timeout_usec, + aesm_error_t *result); + + +uae_oal_status_t SGXAPI oal_get_quote( + const sgx_report_t *p_report, + sgx_quote_sign_type_t quote_type, + const sgx_spid_t *p_spid, + const sgx_quote_nonce_t *p_nonce, + const uint8_t *p_sig_rl, + uint32_t sig_rl_size, + sgx_report_t *p_qe_report, + sgx_quote_t *p_quote, + uint32_t quote_size, + uint32_t timeout_usec, + aesm_error_t *result); + +uae_oal_status_t SGXAPI oal_get_ps_cap( + uint64_t* p_ps_cap, + uint32_t timeout_usec, + aesm_error_t *result); + +uae_oal_status_t SGXAPI oal_report_attestation_status( + const sgx_platform_info_t* p_platform_info, + int attestation_status, + sgx_update_info_bit_t* p_update_info, + uint32_t timeout_usec, + aesm_error_t *result); + +uae_oal_status_t oal_create_session( + uint32_t *session_id, + uint8_t *se_dh_msg1, + uint32_t dh_msg1_size, + uint32_t timeout_usec, + aesm_error_t *result); + +uae_oal_status_t oal_exchange_report( + uint32_t session_id, + const uint8_t *se_dh_msg2, + uint32_t dh_msg2_size, + uint8_t *se_dh_msg3, + uint32_t dh_msg3_size, + uint32_t timeout_usec, + aesm_error_t *result); + +uae_oal_status_t oal_close_session( + uint32_t session_id, + uint32_t timeout_usec, + aesm_error_t *result); + +uae_oal_status_t oal_invoke_service( + const uint8_t *pse_message_req, + uint32_t pse_message_req_size, + uint8_t *pse_message_resp, + uint32_t pse_message_resp_size, + uint32_t timeout_usec, + aesm_error_t *response); + +uae_oal_status_t oal_get_whitelist_size( + uint32_t* p_whitelist_size, + uint32_t timeout_usec, + aesm_error_t* result); + +uae_oal_status_t oal_get_whitelist( + uint8_t* p_whitelist, + uint32_t whitelist_size, + uint32_t timeout_usec, + aesm_error_t *result); + +uae_oal_status_t oal_get_extended_epid_group_id( + uint32_t* extended_group_id, + uint32_t timeout_usec, + aesm_error_t *result); + +uae_oal_status_t oal_switch_extended_epid_group( + uint32_t x_group_id, + uint32_t timeout_usec, + aesm_error_t *result); + +sgx_status_t oal_map_status(uae_oal_status_t status); +sgx_status_t oal_map_result(aesm_error_t result); + +} /* end of extern "C" */ +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/routine.h b/sgx-jvm/linux-sgx/common/inc/internal/routine.h new file mode 100644 index 0000000000..c753b2e2bf --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/routine.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifndef _ROUTINE_H_ +#define _ROUTINE_H_ +#include "sgx_eid.h" +#include "sgx_error.h" +#include "sgx_defs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _ocall_table_t +{ + uint32_t count; + void *ocall[]; +} sgx_ocall_table_t; + +sgx_status_t SGXAPI sgx_ecall(const sgx_enclave_id_t enclave_id, const int proc, const void *ocall_table, void *ms); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/common/inc/internal/rts.h b/sgx-jvm/linux-sgx/common/inc/internal/rts.h new file mode 100644 index 0000000000..61a7711501 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/rts.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _RTS_H_ +#define _RTS_H_ + +#include "se_types.h" +#include "rts_cmd.h" + +typedef struct _ocall_context_t +{ + uintptr_t shadow0; + uintptr_t shadow1; + uintptr_t shadow2; + uintptr_t shadow3; + uintptr_t ocall_flag; + uintptr_t ocall_index; + uintptr_t pre_last_sp; + uintptr_t r15; + uintptr_t r14; + uintptr_t r13; + uintptr_t r12; + uintptr_t xbp; + uintptr_t xdi; + uintptr_t xsi; + uintptr_t xbx; + uintptr_t reserved[3]; + uintptr_t ocall_depth; + uintptr_t ocall_ret; +} ocall_context_t; + +typedef enum +{ + SDK_VERSION_1_5, + SDK_VERSION_2_0 +} sdk_version_t; + +typedef struct _cpu_feature_sdk_version +{ + uint64_t cpu_features; + sdk_version_t version; +}cpu_sdk_info_t; + +#define OCALL_FLAG 0x4F434944 + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/rts_cmd.h b/sgx-jvm/linux-sgx/common/inc/internal/rts_cmd.h new file mode 100644 index 0000000000..671c2c90d1 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/rts_cmd.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* ECALL command */ +#define ECMD_ECALL 0 +#define ECMD_INIT_ENCLAVE -1 +#define ECMD_ORET -2 +#define ECMD_EXCEPT -3 + +/* OCALL command */ +#define OCMD_ERET -1 + diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_atomic.h b/sgx-jvm/linux-sgx/common/inc/internal/se_atomic.h new file mode 100644 index 0000000000..f4de235e8d --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_atomic.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_ATOMIC_H_ +#define _SE_ATOMIC_H_ + + +inline uint32_t se_atomic_inc(volatile uint32_t *mem) +{ + int ret; + + __asm__ __volatile__ ("lock; xaddl %0, %1" + : "=r" (ret), "=m" (*mem) + : "0" (1), "m" (*mem) + ); + + return ret + 1; +} + +inline uint32_t se_atomic_dec(uint32_t volatile *mem) +{ + int ret; + + __asm__ __volatile__ ("lock; xaddl %0, %1" + : "=r" (ret), "=m" (*mem) + : "0" (-1), "m" (*mem) + ); + + return ret - 1; +} + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_cdefs.h b/sgx-jvm/linux-sgx/common/inc/internal/se_cdefs.h new file mode 100644 index 0000000000..12be808120 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_cdefs.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifndef _SE_CDEFS_H_ +#define _SE_CDEFS_H_ + + +#define SGX_WEAK __attribute__((weak)) + +# if (__GNUC__ >= 3) +# define likely(x) __builtin_expect ((x), 1) +# define unlikely(x) __builtin_expect ((x), 0) +# else +# define likely(x) (x) +# define unlikely(x) (x) +# endif + +#ifndef SE_DECLSPEC_EXPORT +#define SE_DECLSPEC_EXPORT __attribute__((visibility("default"))) +#endif + +#ifndef SE_DECLSPEC_IMPORT +#define SE_DECLSPEC_IMPORT +#endif + +#ifndef SE_DECLSPEC_ALIGN +#define SE_DECLSPEC_ALIGN(x) __attribute__((aligned(x))) +#endif + +#ifndef SE_DECLSPEC_THREAD +#define SE_DECLSPEC_THREAD /*__thread*/ +#endif + +/* disable __try, __except on linux */ +#ifndef __try +#define __try try +#endif + +#ifndef __except +#define __except(x) catch(...) +#endif + + +#ifndef SE_DRIVER + +# define SE_GNU +# if defined(__x86_64__) +# define SE_64 +# define SE_GNU64 +# else +# define SE_32 +# define SE_GNU32 +# endif + +#endif + + #define INITIALIZER(f) \ + static void f(void) __attribute__((constructor)); + +#ifdef __cplusplus +#define MY_EXTERN extern "C" +#else +#define MY_EXTERN extern +#endif + +#define SGX_ACCESS_VERSION(libname, num) \ + MY_EXTERN const char *sgx_##libname##_version; \ + const char * __attribute__((destructor)) libname##_access_version_dummy##num() \ + { \ + return sgx_##libname##_version; \ + } + + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_cpu_feature.h b/sgx-jvm/linux-sgx/common/inc/internal/se_cpu_feature.h new file mode 100644 index 0000000000..8b3edbfa66 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_cpu_feature.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifndef _SE_CPU_FEATURE_H_ +#define _SE_CPU_FEATURE_H_ + +#include +#include "se_cpu_feature_defs.h" + + +#ifdef __cplusplus +extern "C" uint64_t g_cpu_feature_indicator; +#else +extern uint64_t g_cpu_feature_indicator; +#endif + +#define TEST_CPU_HAS_RDRAND (g_cpu_feature_indicator & CPU_FEATURE_RDRND) + + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_cpu_feature_defs.h b/sgx-jvm/linux-sgx/common/inc/internal/se_cpu_feature_defs.h new file mode 100644 index 0000000000..20983b96d7 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_cpu_feature_defs.h @@ -0,0 +1,294 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_CPU_FEATURE_DEFS_H_ +#define _SE_CPU_FEATURE_DEFS_H_ + +/* + * Different extended model + model values for Silverthorn. + */ +#define CPU_ATOM1 0x1c +#define CPU_ATOM2 0x26 +#define CPU_ATOM3 0x27 + +/* + * The processor family is an 8-bit value obtained by adding the + * Extended Family field of the processor signature returned by + * CPUID Function 1 with the Family field. + * F = (CPUID(1).EAX[27:20] >> 20) + (CPUID(1).EAX[11:8] >> 8) + */ +#define CPU_FAMILY(x) (((((x) >> 20) & 0xffU) | (((x) >> 8) & 0xfU)) & 0xffU) + +/* The processor model is an 8-bit value obtained by shifting left 4 + * the Extended Model field of the processor signature returned by + * CPUID Function 1 then adding the Model field. + * M = (CPUID(1).EAX[19:16] >> 12) + (CPUID(1).EAX[7:4] >> 4) + */ +#define CPU_MODEL(x) ((((x) >> 12) & 0xf0U) | (((x) >> 4) & 0xfU)) +#define CPU_STEPPING(x) (((x) >> 0) & 0xf) + +#define CPU_HAS_MMX(x) (((x) & (1 << 23)) != 0) +#define CPU_HAS_FXSAVE(x) (((x) & (1 << 24)) != 0) +#define CPU_HAS_SSE(x) (((x) & (1 << 25)) != 0) +#define CPU_HAS_SSE2(x) (((x) & (1 << 26)) != 0) +#define CPU_HAS_PNI(x) (((x) & (1 << 0)) != 0) +#define CPU_HAS_MNI(x) (((x) & (1 << 9)) != 0) +#define CPU_HAS_SNI(x) (((x) & (1 << 19)) != 0) +#define CPU_HAS_MOVBE(x) (((x) & (1 << 22)) != 0) +#define CPU_HAS_SSE4_2(x) (((x) & (1 << 20)) != 0) +#define CPU_HAS_POPCNT(x) (((x) & (1 << 23)) != 0) +#define CPU_HAS_PCLMULQDQ(x) (((x) & (1 << 1)) != 0) +#define CPU_HAS_AES(x) (((x) & (1 << 25)) != 0) +#define CPU_HAS_XSAVE(x) (((x) & (1 << 27)) != 0) +#define CPU_HAS_AVX(x) (((x) & (1 << 28)) != 0) +#define XFEATURE_ENABLED_AVX(x) \ + (((x) & 0x06) == 0x06) +#define CPU_HAS_F16C(x) (((x) & (1 << 29)) != 0) +#define CPU_HAS_RDRAND(x) (((x) & (1 << 30)) != 0) +#define CPU_HAS_IVB(x) (CPU_HAS_F16C(x) && CPU_HAS_RDRAND(x)) +#define CPU_HAS_IVB_NORDRAND(x) (CPU_HAS_F16C(x)) +#define CPU_HAS_AVX2(x) (((x) & (1 << 5)) != 0) +#define CPU_HAS_HLE(x) (((x) & (1 << 4)) != 0) +#define CPU_HAS_RTM(x) (((x) & (1 << 11)) != 0) +#define CPU_HAS_ADCOX(x) (((x) & (1 << 19)) != 0) +#define CPU_HAS_RDSEED(x) (((x) & (1 << 18)) != 0) +#define CPU_HAS_BMI(x) (((x) & (1 << 3)) != 0 && \ + ((x) & (1 << 8)) != 0) +#define CPU_HAS_LZCNT(x) (((x) & (1 << 5)) != 0) +#define CPU_HAS_PREFETCHW(x) (((x) & (1 << 8)) != 0) +#define CPU_HAS_FMA(x) (((x) & (1 << 12)) != 0) +#define CPU_HAS_HSW(cpuid7_ebx, ecpuid1_ecx, cpuid1_ecx) \ + (CPU_HAS_AVX2(cpuid7_ebx) && CPU_HAS_BMI(cpuid7_ebx) && \ + CPU_HAS_LZCNT(ecpuid1_ecx) && CPU_HAS_FMA(cpuid1_ecx) && \ + CPU_HAS_HLE(cpuid7_ebx) && CPU_HAS_RTM(cpuid7_ebx)) + +#define CPU_HAS_FPU(x) (((x) & (1 << 0)) != 0) +#define CPU_HAS_CMOV(x) (((x) & (1 << 15)) != 0) + +#define CPU_HAS_SSE3(x) (((x) & (1 << 0)) != 0) +#define CPU_HAS_SSSE3(x) (((x) & (1 << 9)) != 0) + +#define CPU_HAS_SSE4_1(x) (((x) & (1 << 19)) != 0) + +#define CPU_HAS_LRBNI(x) (((x) & (1 << 1)) != 0) +#define CPU_HAS_LRB2(x) (((x) & (1 << 4)) != 0) + + +#define CPU_GENU_VAL ('G' << 0 | 'e' << 8 | 'n' << 16 | 'u' << 24) +#define CPU_INEI_VAL ('i' << 0 | 'n' << 8 | 'e' << 16 | 'I' << 24) +#define CPU_NTEL_VAL ('n' << 0 | 't' << 8 | 'e' << 16 | 'l' << 24) + +/* + * These values must be in sync with dev/proton/globals/glob_cpu_info.c + * c_legacy_cpu_set_xxx constants. + */ +#define CPU_GENERIC 0x1 +#define CPU_PENTIUM 0x2 +#define CPU_PENTIUM_PRO 0x4 +#define CPU_PENTIUM_MMX 0x8 +#define CPU_PENTIUM_II 0x10 +#define CPU_PENTIUM_II_FXSV 0x20 +#define CPU_PENTIUM_III 0x40 +#define CPU_PENTIUM_III_SSE 0x80 +#define CPU_PENTIUM_4 0x100 +#define CPU_PENTIUM_4_SSE2 0x200 +#define CPU_BNI 0x400 +#define CPU_PENTIUM_4_PNI 0x800 +#define CPU_MNI 0x1000 +#define CPU_SNI 0x2000 +#define CPU_BNL 0x4000 +#define CPU_NHM 0x8000 +#define CPU_WSM 0x10000 +#define CPU_SNB 0x20000 +#define CPU_IVB 0x40000 +#define CPU_HSW 0x400000 + +#define CPU_PENTIUM_FAMILY 5 +#define CPU_PPRO_FAMILY 6 +#define CPU_WMT_FAMILY 15 + +/* + * The processor is a generic IA32 CPU + */ +#define CPU_FEATURE_GENERIC_IA32 0x00000001ULL + +/* + * Floating point unit is on-chip. + */ +#define CPU_FEATURE_FPU 0x00000002ULL + +/* + * Conditional mov instructions are supported. + */ +#define CPU_FEATURE_CMOV 0x00000004ULL + +/* + * The processor supports the MMX technology instruction set extensions + * to Intel Architecture. + */ +#define CPU_FEATURE_MMX 0x00000008ULL + +/* + * The FXSAVE and FXRSTOR instructions are supported for fast + * save and restore of the floating point context. + */ +#define CPU_FEATURE_FXSAVE 0x00000010ULL + +/* + * Indicates the processor supports the Streaming SIMD Extensions Instructions. + */ +#define CPU_FEATURE_SSE 0x00000020ULL + +/* + * Indicates the processor supports the Streaming SIMD + * Extensions 2 Instructions. + */ +#define CPU_FEATURE_SSE2 0x00000040ULL + +/* + * Indicates the processor supports the Streaming SIMD + * Extensions 3 Instructions. (PNI) + */ +#define CPU_FEATURE_SSE3 0x00000080ULL + +/* + * The processor supports the Supplemental Streaming SIMD Extensions 3 + * instructions. (MNI) + */ +#define CPU_FEATURE_SSSE3 0x00000100ULL + +/* + * The processor supports the Streaming SIMD Extensions 4.1 instructions.(SNI) + */ +#define CPU_FEATURE_SSE4_1 0x00000200ULL + +/* + * The processor supports the Streaming SIMD Extensions 4.1 instructions. + * (NNI + STTNI) + */ +#define CPU_FEATURE_SSE4_2 0x00000400ULL + + +/* + * The processor supports POPCNT instruction. + */ +#define CPU_FEATURE_POPCNT 0x00000800ULL + +/* + * The processor supports MOVBE instruction. + */ +#define CPU_FEATURE_MOVBE 0x00001000ULL + +/* + * The processor supports PCLMULQDQ instruction. + */ +#define CPU_FEATURE_PCLMULQDQ 0x00002000ULL + +/* + * The processor supports instruction extension for encryption. + */ +#define CPU_FEATURE_AES 0x00004000ULL + +/* + * The processor supports 16-bit floating-point conversions instructions. + */ +#define CPU_FEATURE_F16C 0x00008000ULL + +/* + * The processor supports AVX instruction extension. + */ +#define CPU_FEATURE_AVX 0x00010000ULL + +/* + * The processor supports RDRND (read random value) instruction. + */ +#define CPU_FEATURE_RDRND 0x00020000ULL + +/* + * The processor supports FMA instructions. + */ +#define CPU_FEATURE_FMA 0x00040000ULL + +/* + * The processor supports two groups of advanced bit manipulation extensions. - Haswell introduced, AVX2 related + */ +#define CPU_FEATURE_BMI 0x00080000ULL + +/* + * The processor supports LZCNT instruction (counts the number of leading zero + * bits). - Haswell introduced + */ +#define CPU_FEATURE_LZCNT 0x00100000ULL + +/* + * The processor supports HLE extension (hardware lock elision). - Haswell introduced + */ +#define CPU_FEATURE_HLE 0x00200000ULL + +/* + * The processor supports RTM extension (restricted transactional memory) - Haswell AVX2 related. + */ +#define CPU_FEATURE_RTM 0x00400000ULL + +/* + * The processor supports AVX2 instruction extension. + */ +#define CPU_FEATURE_AVX2 0x00800000ULL + +/* + * The processor supports AVX512 instruction extension. + */ +#define CPU_FEATURE_AVX512 0x01000000ULL + +/* + * The processor supports the PREFETCHW instruction. + */ +#define CPU_FEATURE_PREFETCHW 0x02000000ULL + +/* + * The processor supports RDSEED instruction. + */ +#define CPU_FEATURE_RDSEED 0x04000000ULL + +/* + * The processor supports ADCX and ADOX instructions. + */ +#define CPU_FEATURE_ADCOX 0x08000000ULL + +/* + * The processor is a full inorder (Silverthorne) processor + */ +#define CPU_FEATURE_FULL_INORDER 0x10000000ULL + +/* Reserved feature bits which includes the unset bit CPU_FEATURE_AVX512 */ +#define RESERVED_CPU_FEATURE_BIT ((~(0x20000000ULL - 1)) | 0x01000000ULL) + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_debugger_lib.h b/sgx-jvm/linux-sgx/common/inc/internal/se_debugger_lib.h new file mode 100644 index 0000000000..97e4e36546 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_debugger_lib.h @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SEDEBUGGERLIB_H_ +#define _SEDEBUGGERLIB_H_ + +#include "arch.h" +#include "se_types.h" +#include "se_macro.h" +#include + +#define URTS_EXCEPTION_PRECREATEENCLAVE 0xa1a01ec0 +#define URTS_EXCEPTION_POSTINITENCLAVE 0xa1a01ec1 +#define URTS_EXCEPTION_PREREMOVEENCLAVE 0xa1a01ec3 +#define URTS_EXCEPTION_PREEENTER 0xa1a01ec7 + +#define FIRST_CHANCE_EXCEPTION 1 +#define SECOND_CHANCE_EXCEPTION 0 + +#define DBWIN_BUFFER 0xa1a01ec5 +#define CXX_EXCEPTION 0xe06d7363 + +#define SE_UNICODE 1 +#define SE_ANSI 0 +#define DEBUGGER_ENABLED 1 + +#define DEBUG_INFO_STRUCT_VERSION 0x83d0ce23 + +const size_t BUF_SIZE = sizeof(void*); + +typedef struct _debug_tcs_info_t +{ + struct _debug_tcs_info_t* next_tcs_info; + void* TCS_address; + uintptr_t ocall_frame; /* ocall_frame_t** */ + unsigned long thread_id; +}debug_tcs_info_t; + + +#define DEBUG_INFO_MAX_PARAMETERS 10 +typedef struct _debug_info_t +{ + uintptr_t param_array[DEBUG_INFO_MAX_PARAMETERS]; +}debug_info_t; + +//enclave_type bit map +#define ET_SIM_SHIFT 0 /*bits[0]=0 hw, bits[0]=1 sim*/ +#define ET_DEBUG_SHIFT 1 /*bits[1]=0 product enclave, bits[1]=1 debug enclave*/ +#define ET_SIM (1 << ET_SIM_SHIFT) +#define ET_DEBUG (1 << ET_DEBUG_SHIFT) + +typedef struct _debug_enclave_info_t +{ + PADDED_POINTER(struct _debug_enclave_info_t, next_enclave_info); + PADDED_POINTER(void, start_addr); + PADDED_POINTER(debug_tcs_info_t, tcs_list); + uint32_t enclave_type; + uint32_t file_name_size; + PADDED_POINTER(void, lpFileName); + PADDED_POINTER(void, g_peak_heap_used_addr); + PADDED_POINTER(void, dyn_sec); + sgx_misc_select_t misc_select; + /* The following members are optional or unused */ + uint32_t struct_version; + uint32_t unicode; +}debug_enclave_info_t; +typedef struct _ocall_frame_t +{ + uintptr_t pre_last_frame; + uintptr_t index; + uintptr_t xbp; + uintptr_t ret; +}ocall_frame_t; + +static inline void destory_debug_info(debug_enclave_info_t *debug_info) +{ + if(debug_info->lpFileName) + { + free(debug_info->lpFileName); + debug_info->lpFileName = NULL; + } + + /*tcs_list is just a pointer, the instance is maintained in CTrustThread, so don't free it.*/ + debug_info->tcs_list = NULL; +} +#endif /*_SEDEBUGGERLIB_H_*/ + diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_enclave_type.h b/sgx-jvm/linux-sgx/common/inc/internal/se_enclave_type.h new file mode 100644 index 0000000000..bd450e3918 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_enclave_type.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_ENCLAVE_TYPE_H_ +#define _SE_ENCLAVE_TYPE_H_ + +typedef enum +{ + enclave_type_general = 0, + enclave_type_architecture, +} enclave_type_t; + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_error_internal.h b/sgx-jvm/linux-sgx/common/inc/internal/se_error_internal.h new file mode 100644 index 0000000000..b98aed81d7 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_error_internal.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_ERROR_INTERNAL_H_ +#define _SE_ERROR_INTERNAL_H_ + +#include "sgx_error.h" + +/* +bit[31:30] - main module id + 00 - external error + 11---internal error +bit[29:16] - reserved +bit[15:12] - sub-module id +bit[11:0] - specific error +*/ + +#define MAIN_MOD_SHIFT 30 +#define SUB_MOD_SHIFT 12 + +#define INTERNAL_ERROR 3 +#define EXTERNAL_ERROR 0 + +#define SE_INTERNAL_ERROR(x) (0xC0000000|(x)) + +typedef enum _se_status_internal_t +{ + SE_ERROR_SUCCESS = 0, /*same value as SGX_SUCCESS*/ + /*error code for driver return to uRTS*/ + SE_ERROR_DRIVER_UNEXPECTED = SE_INTERNAL_ERROR(0X2001), + SE_ERROR_DRIVER_INVALID_ID = SE_INTERNAL_ERROR(0X2002), + SE_ERROR_DRIVER_INVALID_PARAMETER = SE_INTERNAL_ERROR(0X2003), + SE_ERROR_DRIVER_INVALID_REQUEST = SE_INTERNAL_ERROR(0X2004), + SE_ERROR_DRIVER_OUTOF_MEMORY_R0 = SE_INTERNAL_ERROR(0X2005), + SE_ERROR_DRIVER_OUTOF_MEMORY_R3 = SE_INTERNAL_ERROR(0X2006), + SE_ERROR_DRIVER_OUTOF_EPC = SE_INTERNAL_ERROR(0X2007), + SE_ERROR_DRIVER_HW_CAPABILITY = SE_INTERNAL_ERROR(0X2008), + SE_ERROR_DRIVER_MEMORY_MAP_CONFLICT = SE_INTERNAL_ERROR(0X2009), + SE_ERROR_DRIVER_POWER = SE_INTERNAL_ERROR(0X200a), + SE_ERROR_DRIVER_INVALID_PRIVILEGE = SE_INTERNAL_ERROR(0X200b), + SE_ERROR_DRIVER_INVALID_ISVSVNLE = SE_INTERNAL_ERROR(0X200c), + + SE_ERROR_DRIVER_INVALID_SIG_STRUCT = SE_INTERNAL_ERROR(0X2100), + SE_ERROR_DRIVER_INVALID_ATTRIBUTE = SE_INTERNAL_ERROR(0X2101), + SE_ERROR_DRIVER_INVALID_MEASUREMENT = SE_INTERNAL_ERROR(0X2102), + SE_ERROR_DRIVER_INVALID_SIGNATURE = SE_INTERNAL_ERROR(0X2103), + SE_ERROR_DRIVER_INVALID_LAUNCH_TOKEN= SE_INTERNAL_ERROR(0X2104), + SE_ERROR_DRIVER_INVALID_CPUSVN = SE_INTERNAL_ERROR(0X2105), + SE_ERROR_DRIVER_UNMASKED_EVENT = SE_INTERNAL_ERROR(0X2106), + + SE_ERROR_INVALID_LAUNCH_TOKEN = SE_INTERNAL_ERROR(0x2200), /* the license is invalid*/ + SE_ERROR_INVALID_MEASUREMENT = SE_INTERNAL_ERROR(0x2201), /* The measurement of the enclave is invalid. May caused by signature or launch token*/ + SE_ERROR_READ_LOCK_FAIL = SE_INTERNAL_ERROR(0x2202), + SE_ERROR_INVALID_ISVSVNLE = SE_INTERNAL_ERROR(0X2203), + + /*error code for untrusted event of SE mutex*/ + SE_ERROR_MUTEX_GET_EVENT = SE_INTERNAL_ERROR(0x3001), + SE_ERROR_MUTEX_WAIT_EVENT = SE_INTERNAL_ERROR(0x3002), + SE_ERROR_MUTEX_WAKE_EVENT = SE_INTERNAL_ERROR(0x3003), +} se_status_internal_t; + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_event.h b/sgx-jvm/linux-sgx/common/inc/internal/se_event.h new file mode 100644 index 0000000000..3672fd3246 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_event.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_EVENT_H_ +#define _SE_EVENT_H_ + +# include +# include +# include +typedef void * se_handle_t; + +#include "sgx_defs.h" + +#define SE_MUTEX_SUCCESS 0x0 +#define SE_MUTEX_INVALID 0x1 +#define SE_MUTEX_ERROR_WAKE 0x2 +#define SE_MUTEX_ERROR_WAIT 0x3 + +#ifdef __cplusplus +extern "C" { +#endif + +se_handle_t SGXAPI se_event_init(void); +void SGXAPI se_event_destroy(se_handle_t); + +int SGXAPI se_event_wait(se_handle_t); +int SGXAPI se_event_wake(se_handle_t); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_lock.hpp b/sgx-jvm/linux-sgx/common/inc/internal/se_lock.hpp new file mode 100644 index 0000000000..68aedf2cf5 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_lock.hpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* This file implement lock guard */ + +#ifndef SE_LOCK_HPP +#define SE_LOCK_HPP + +#include "util.h" +#include "se_thread.h" +#include "uncopyable.h" + +class Mutex: private Uncopyable +{ +public: + Mutex(){se_mutex_init(&m_mutex);} + ~Mutex(){se_mutex_destroy(&m_mutex);} + void lock(){se_mutex_lock(&m_mutex);} + void unlock(){se_mutex_unlock(&m_mutex);} +private: + se_mutex_t m_mutex; +}; + +class LockGuard: private Uncopyable +{ +public: + LockGuard(Mutex* mutex):m_mutex(mutex){m_mutex->lock();} + ~LockGuard(){m_mutex->unlock();} +private: + Mutex* m_mutex; +}; + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_macro.h b/sgx-jvm/linux-sgx/common/inc/internal/se_macro.h new file mode 100644 index 0000000000..4b465ac71b --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_macro.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + #ifndef SE_MACRO_H_ + #define SE_MACRO_H_ + +#ifndef SGX_HYPERV_ECO +#define SGX_HYPERV_ECO +#endif + + #endif \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_map.h b/sgx-jvm/linux-sgx/common/inc/internal/se_map.h new file mode 100644 index 0000000000..2b1889a838 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_map.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_MAP_H_ +#define _SE_MAP_H_ + +#include +#include +#include +#include + +#include "se_types.h" + +#include +#include +#include +#include +typedef int se_file_handle_t; + +typedef struct { + uint8_t* base_addr; /* pointer to the mapped area */ + size_t length; /* the length of the mapping */ +} map_handle_t; + +#ifdef __cplusplus +extern "C" { +#endif + +/* Map a file to memory and get its size. */ +map_handle_t* map_file(se_file_handle_t fd, uint32_t *size); + +/* Unmap a mapped file. */ +void unmap_file(map_handle_t* mh); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_memcpy.h b/sgx-jvm/linux-sgx/common/inc/internal/se_memcpy.h new file mode 100644 index 0000000000..f7cd259993 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_memcpy.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_MEMCPY_H_ +#define _SE_MEMCPY_H_ + +#include + + +/* memcpy_s always return 0 under Linux */ + +#ifndef _ERRNO_T_DEFINED +#define _ERRNO_T_DEFINED +typedef int errno_t; +#endif + +static inline errno_t memcpy_s(void *dest, size_t numberOfElements, const void *src, size_t count) +{ + if(numberOfElements +#include +#include +#include + +#ifndef MEM_COMMIT +#define MEM_COMMIT 0x1000 +#endif + +#ifndef MEM_RESERVE +#define MEM_RESERVE 0x2000 +#endif + +#ifdef MEM_RELEASE +#warning "MEM_RELEASE define conflict" +#else +#define MEM_RELEASE 0x8000 +#endif + +#ifdef MEM_DECOMMIT +#warning "MEM_DECOMMIT define conflict" +#else +#define MEM_DECOMMIT 0x4000 +#endif + +#include "se_types.h" +#include "arch.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* +Reserves or commits a region of pages in the virtual address space of the calling process. +Memory allocated by this function is automatically initialized to zero, unless MEM_RESET is specified. +@address: the starting address of the region to allocate. +@size: size of region in bytes. +@type: Only MEM_COMMIT accepted. + MEM_COMMIT - Allocates memory charges for the specified reserved memory pages. + Actual physical pages are not allocated until the virtual addresses are actually accessed. + The function initializes the memory to zero. +@return value: If the function succeeds, the return value is the base address of the allocated region of pages. + If the function fails, the return value is NULL. +*/ +void* se_virtual_alloc(void* address, size_t size, uint32_t type); +/* +Releases, decommits, or releases and decommits a region of pages within the virtual address space of the calling process. +@address:A pointer to the base address of the region of pages to be freed. If the dwFreeType parameter is MEM_RELEASE, + this parameter must be the base address returned by the se_virtual_alloc function when the region of pages is reserved. +@size: The size of the region of memory to be freed, in bytes. +@type: Only MEM_RELEASE accepted + MEM_RELEASE - releases the specified region of pages. After this operation, the pages are in the free state. +@return value:If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. +*/ +int se_virtual_free(void* address, size_t size, uint32_t type); +/* +Locks the specified region of the process's virtual address space into physical memory, ensuring that subsequent access to the region will not incur a page fault. +@address: A pointer to the base address of the region of pages to be locked. + The region of affected pages includes all pages that contain one or more bytes in the range from the address parameter to (address+size). +@size: The size of the region to be locked, in bytes. +@return value: If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. +*/ +int se_virtual_lock(void* address, size_t size); +/* +Changes the protection on a region of committed pages in the virtual address space of the calling process. +@address: A pointer an address that describes the starting page of the region of pages whose access protection attributes are to be changed. +@size: The size of the region whose access protection attributes are to be changed, in bytes. +@prot: The memory protection option. The option can be SI_FLAG_R, SI_FLAG_W, SI_FLAG_X. +@return value: If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. +*/ + +#define SGX_PROT_NONE PROT_NONE + +int se_virtual_protect(void* address, size_t size, uint32_t prot); + + +#include +#include +#include +#include +typedef pid_t se_proc_t; + +/* +@return value: on success, return TRUE else return FALSE +*/ +se_proc_t get_self_proc(void); +/* +** If the function succeeds, the return value is nonzero. +** If the function fails, the return value is zero. +*/ +int put_self_proc(se_proc_t proc); +int se_read_process_mem(se_proc_t proc, void* base_addr, void* buffer, size_t size, size_t* read_nr); +int se_write_process_mem(se_proc_t proc, void* base_addr, void* buffer, size_t size, size_t* write_ndr); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_page_attr.h b/sgx-jvm/linux-sgx/common/inc/internal/se_page_attr.h new file mode 100644 index 0000000000..9bafac8af5 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_page_attr.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_PAGE_ATTR_H_ +#define _SE_PAGE_ATTR_H_ + +typedef enum +{ + DoEADD = 0, + DoEEXTEND, +} ATTRIBUTE_BITS_t; + +typedef enum +{ + ADD_PAGE_ONLY = 1< + +typedef pthread_rwlock_t se_rwlock_t; +typedef pthread_rwlock_t* se_prwlock_t; + +#ifdef __cplusplus +extern "C" { +#endif + +void se_wtlock(se_prwlock_t); +void se_wtunlock(se_prwlock_t); +int se_try_rdlock(se_prwlock_t); +void se_rdlock(se_prwlock_t lock); +void se_rdunlock(se_prwlock_t); +void se_init_rwlock(se_prwlock_t lock); +void se_fini_rwlock(se_prwlock_t lock); + +#ifdef __cplusplus +} +#endif + +#endif /* _RWLOCK_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_stdio.h b/sgx-jvm/linux-sgx/common/inc/internal/se_stdio.h new file mode 100644 index 0000000000..9f5dc3adab --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_stdio.h @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#ifndef SE_STDIO_H +#define SE_STDIO_H + +#include +#include +#include "se_memcpy.h" +#include +#include +#include +#include +#include + +#ifndef MAX_PATH +#define MAX_PATH 260 +#endif + +static inline int se_delete_file(const char *path_name) +{ + return unlink(path_name); +} + +#define se_delete_tfile se_delete_file + +static inline int sprintf_s(char *dst_buf, size_t size_in_bytes, const char *format, ...) +{ + va_list argptr; + int cnt; + va_start(argptr, format); + cnt = vsnprintf(dst_buf, size_in_bytes, format, argptr); + va_end(argptr); + return cnt; +} + +static inline int _snprintf_s(char *dst_buf, size_t size_in_bytes, size_t max_count, const char *format, ...) +{ + (void) size_in_bytes; + va_list argptr; + int cnt; + va_start(argptr, format); + cnt = vsnprintf(dst_buf, max_count, format, argptr); + va_end(argptr); + return cnt; +} + +static inline errno_t fopen_s(FILE **f, const char *filename, const char *mode) +{ + errno_t err = 0; + *f = fopen(filename, mode); + if(*f==NULL){ + err = -1; + } + return err; +} + +static inline int se_copy_file(const char *dst_name, const char *src_name) +{ + int dest = -1; + int source = -1; + ssize_t nr_read; + struct stat stat_buf; + +#ifndef BUF_SIZE +#define BUF_SIZE 4096 +#endif + char buf[BUF_SIZE]; + + /* open the input file */ + source = open(src_name, O_RDONLY); + if(source < 0) + goto error; + + /* get size and permissions of the prebuild DB file */ + if (fstat(source, &stat_buf) != 0) + goto error; + + dest = open(dst_name, O_WRONLY|O_CREAT|O_TRUNC, stat_buf.st_mode); + if(dest < 0) + goto error; + + while ((nr_read = read(source, buf, BUF_SIZE)) > 0) + { + if (write(dest, buf, nr_read) != nr_read) + goto error; + } +#undef BUF_SIZE + + close(dest); + close(source); + return 0; + +error: + if(dest>=0)close(dest); + if(source>=0)close(source); + return -1; +} + +#ifdef __cplusplus +template +int sprintf_s(char (&dst)[_Size], const char *format, ...) +{ + va_list argptr; + int cnt; + va_start(argptr, format); + cnt = vsprintf(dst, format, argptr); + va_end(argptr); + return cnt; +} + +template +int _snprintf_s(char (&dst)[_Size], size_t max_count, const char *format, ...) +{ + va_list argptr; + int cnt; + va_start(argptr, format); + cnt = vsnprintf(dst, max_count, format, argptr); + va_end(argptr); + return cnt; +} + +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_string.h b/sgx-jvm/linux-sgx/common/inc/internal/se_string.h new file mode 100644 index 0000000000..e5185617df --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_string.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_STRING_H_ +#define _SE_STRING_H_ + +#include "se_memcpy.h" +#include + + +#ifndef _ERRNO_T_DEFINED +#define _ERRNO_T_DEFINED +typedef int errno_t; +#endif + +static inline errno_t strcat_s(char *dst, size_t max_size, const char *src) +{ + if(strlen(dst)+strlen(src)+1>max_size)return -1; + strcat(dst, src); + return 0; +} + +static inline errno_t strcpy_s(char *dst, size_t max_size, const char *src) +{ + if(strnlen(src, max_size)+1>max_size)return -1; + strcpy(dst, src); + return 0; +} + +#define _strnicmp strncasecmp +static inline errno_t strncat_s(char *dst, size_t max_size, const char *src, size_t max_count) +{ + size_t len = strnlen(src,max_count); + len+=strnlen(dst, max_size)+1; + if(len>max_size)return -1; + strncat(dst, src, max_count); + return 0; +} + +#define _strdup strdup +#define strnlen_s strnlen + + + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_thread.h b/sgx-jvm/linux-sgx/common/inc/internal/se_thread.h new file mode 100644 index 0000000000..d6432b80b1 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_thread.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#ifndef _SE_THREAD_H_ +#define _SE_THREAD_H_ + + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE /* for PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP */ +#endif +#include +#include +#include +#include +typedef pthread_mutex_t se_mutex_t; +typedef pid_t se_thread_id_t; +typedef pthread_key_t se_tls_index_t; + +#ifdef __cplusplus +extern "C" { +#endif +/* +@mutex: A pointer to the critical section object. +@return value: If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. +*/ +void se_mutex_init(se_mutex_t* mutex); +int se_mutex_lock(se_mutex_t* mutex); +int se_mutex_unlock(se_mutex_t* mutex); +int se_mutex_destroy(se_mutex_t* mutex); + +unsigned int se_get_threadid(void); + +/* tls functions */ +int se_tls_alloc(se_tls_index_t *tls_index); +int se_tls_free(se_tls_index_t tls_index); +void * se_tls_get_value(se_tls_index_t tls_index); +int se_tls_set_value(se_tls_index_t tls_index, void *tls_value); + +/* se_thread_handle_t se_create_thread(size_t stack_size, thread_start_routine_t start_routine, void *param, se_thread_t* thread); */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_time.h b/sgx-jvm/linux-sgx/common/inc/internal/se_time.h new file mode 100644 index 0000000000..d1492021ea --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_time.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_TIME_H_ +#define _SE_TIME_H_ + +#include "se_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* +*@milli_seconds: the time range for sleep. It is milliseconds. +*/ +void se_sleep(uint32_t milli_seconds); +uint64_t se_get_tick_count_freq(void); +uint64_t se_get_tick_count(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_trace.h b/sgx-jvm/linux-sgx/common/inc/internal/se_trace.h new file mode 100644 index 0000000000..68967939d7 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_trace.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* + *This file wrapper some trace output. +*/ + +#ifndef _SE_DEBUG_H_ +#define _SE_DEBUG_H_ + +#include +#include + +typedef enum +{ + SE_TRACE_ERROR, + SE_TRACE_WARNING, + SE_TRACE_NOTICE, + SE_TRACE_DEBUG +} se_trace_t; + +#ifndef SE_DEBUG_LEVEL +/* Each module need define their own SE_DEBUG_LEVEL */ +#define SE_DEBUG_LEVEL SE_TRACE_ERROR +#endif + +#ifdef __cplusplus +extern "C" { +#endif +int se_trace_internal(int debug_level, const char *fmt, ...); + +#ifdef __cplusplus +} +#endif + +/* For libraries, we usually define DISABLE_TRACE to disable any trace. */ +/* For apps, we usually enable trace. */ +#ifdef DISABLE_TRACE +#define SE_TRACE(...) +#define se_trace(...) +#else /* DISABLE_TRACE */ +#define se_trace(debug_level, fmt, ...) \ + do { \ + if(debug_level <= SE_DEBUG_LEVEL) \ + se_trace_internal(debug_level, fmt, ##__VA_ARGS__); \ + }while(0) + +/* For compatibility, SE_TRACE/se_trace is used in old code. */ +/* New code should use SE_TRACE_DEBUG, SE_TRACE_NOTICE, SE_TRACE_WARNING, SE_TRACE_ERROR */ +#define SE_TRACE(debug_level, fmt, ...) \ + se_trace(debug_level, "[%s %s:%d] " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__) +#endif/* DISABLE_TRACE */ + +/* SE_TRACE_DEBUG and SE_TRACE_NOTICE print the debug information plus message. */ +#define SE_TRACE_DEBUG(fmt, ...) se_trace(SE_TRACE_DEBUG, "[%s %s:%d] " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__) +#define SE_TRACE_NOTICE(fmt, ...) se_trace(SE_TRACE_NOTICE, "[%s %s:%d] " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__) +/* SE_TRACE_WARNING and SE_TRACE_ERROR only print message. */ +#define SE_TRACE_WARNING(fmt, ...) se_trace(SE_TRACE_WARNING, fmt, ##__VA_ARGS__) +#define SE_TRACE_ERROR(fmt, ...) se_trace(SE_TRACE_ERROR, fmt, ##__VA_ARGS__) + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_types.h b/sgx-jvm/linux-sgx/common/inc/internal/se_types.h new file mode 100644 index 0000000000..c3b29e047a --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_types.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* + * This file is to define some types that is platform independent. +*/ + +#ifndef _SE_TYPE_H_ +#define _SE_TYPE_H_ +#include "se_cdefs.h" + +#ifdef SE_DRIVER + +typedef INT8 int8_t; +typedef UINT8 uint8_t; +typedef INT16 int16_t; +typedef UINT16 uint16_t; +typedef INT32 int32_t; +typedef UINT32 uint32_t; +typedef INT64 int64_t; +typedef UINT64 uint64_t; + +#else + +#include +#include + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#endif + +#if defined(SE_64) + +#define PADDED_POINTER(t, p) t* p +#define PADDED_DWORD(d) uint64_t d +#define PADDED_LONG(l) int64_t l +#define REG(name) r##name +#ifdef SE_SIM_EXCEPTION +#define REG_ALIAS(name) R##name +#endif +#define REGISTER(name) uint64_t REG(name) + +#else /* !defined(SE_64) */ + +#define PADDED_POINTER(t, p) t* p; void* ___##p##_pad_to64_bit +#define PADDED_DWORD(d) uint32_t d; uint32_t ___##d##_pad_to64_bit +#define PADDED_LONG(l) int32_t l; int32_t ___##l##_pad_to64_bit + +#define REG(name) e##name + +#ifdef SE_SIM_EXCEPTION +#define REG_ALIAS(name) E##name +#endif + +#define REGISTER(name) uint32_t REG(name); uint32_t ___##e##name##_pad_to64_bit + +#endif /* !defined(SE_64) */ + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_vendor.h b/sgx-jvm/linux-sgx/common/inc/internal/se_vendor.h new file mode 100644 index 0000000000..ce2f1674bc --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_vendor.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_VENDOR_H_ +#define _SE_VENDOR_H_ + +#define INTEL_VENDOR_ID 0x8086 +#define AE_PRODUCT_ID 0x1 + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_version.h b/sgx-jvm/linux-sgx/common/inc/internal/se_version.h new file mode 100644 index 0000000000..84814cfc28 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_version.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define STRFILEVER "1.7.100.36470" + diff --git a/sgx-jvm/linux-sgx/common/inc/internal/se_wrapper.h b/sgx-jvm/linux-sgx/common/inc/internal/se_wrapper.h new file mode 100644 index 0000000000..0edf25d8be --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/se_wrapper.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* + *This file wrapper all the head file that is platform dependent. +*/ +#ifndef _SE_WRAPPER_H_ +#define _SE_WRAPPER_H_ + +#include "se_cdefs.h" +#include "se_types.h" +#include "se_thread.h" +#include "se_trace.h" +#include "se_time.h" +#include "se_event.h" +#include "se_rwlock.h" +#include "se_atomic.h" +#include "se_memcpy.h" +#include "se_string.h" +#include "se_stdio.h" + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/sgx_memset_s.h b/sgx-jvm/linux-sgx/common/inc/internal/sgx_memset_s.h new file mode 100644 index 0000000000..64956b384a --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/sgx_memset_s.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SE_MEMSET_S_H +#define _SE_MEMSET_S_H +#include +#ifdef __cplusplus +extern "C" +#endif +int memset_s(void *s, size_t smax, int c, size_t n); + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/sgx_profile.h b/sgx-jvm/linux-sgx/common/inc/internal/sgx_profile.h new file mode 100644 index 0000000000..3c83d1a396 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/sgx_profile.h @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* +Some notes for using the profiling macros + +1. Define _PROFILE_ before including "sgx_profile.h" will enable the profiling, + also need to include sgx_profile.cpp in the compiling process +2. When use it in multi-threaded application, please don't trigger profiling in multiple threads at the same time. + The implementation is not thread-safe now, to avoid additional latency introduced by locks +3. PROFILE_OUTPUT macro should only be used once before application exits +4. PROFILE_START and PROFILE_END should be paired, otherwise PROFILE_OUTPUT will abort the program when detects the mismatch + +A simple example to use PROFILE macro + +#define _PROFILE_ +#include "sgx_profile.h" + +... +PROFILE_INIT(); +... + +PROFILE_START("func1"); +func1(); +PROFILE_END("func1"); + +... + +PROFILE_START("func2"); +func2(); +PROFILE_END("func2"); + +... + +PROFILE_OUTPUT("C:\\work\\output.csv"); +... +*/ + + +#ifndef _SGX_PROFILE_H_ +#define _SGX_PROFILE_H_ + + +#if defined(_PROFILE_) +#define PRO_START 0 +#define PRO_END 1 + +#if defined(__cplusplus) +extern "C" +{ +#endif + +void profile_init(); +void profile_start(const char* str); /* 'str' must be global string. Do not use string in stack. */ +void profile_end(const char * str); +void profile_output(const char* filename); + +#if defined(__cplusplus) +} +#endif + +#define PROFILE_INIT() profile_init() +#define PROFILE_START(x) profile_start(x) +#define PROFILE_END(x) profile_end(x) +#define PROFILE_OUTPUT(x) profile_output(x) + +#else +#define PROFILE_INIT() +#define PROFILE_START(x) +#define PROFILE_END(x) +#define PROFILE_OUTPUT(x) +#endif + + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/sgx_read_rand.h b/sgx-jvm/linux-sgx/common/inc/internal/sgx_read_rand.h new file mode 100644 index 0000000000..05d79861f3 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/sgx_read_rand.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __SGX_READ_RAND_H__ +#define __SGX_READ_RAND_H__ +#include "sgx.h" +#include "sgx_defs.h" +#ifdef __cplusplus +extern "C" +#endif +sgx_status_t SGXAPI sgx_read_rand(unsigned char *buf, size_t size); +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/sgx_sha256_128.h b/sgx-jvm/linux-sgx/common/inc/internal/sgx_sha256_128.h new file mode 100644 index 0000000000..52602d0ec2 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/sgx_sha256_128.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifndef _SHA256_128_H +#define _SHA256_128_H + +#include "stdlib.h" +#include "sgx_utils.h" +#include "sgx_tcrypto.h" +#include "math.h" +#include "string.h" + +#define SGX_SHA256_128_HASH_SIZE 16 +typedef uint8_t sgx_sha256_128_hash_t[SGX_SHA256_128_HASH_SIZE]; + +sgx_status_t SGXAPI sgx_sha256_128_msg(const uint8_t *p_src, uint32_t src_len, sgx_sha256_128_hash_t *p_hash); + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/sgx_tcrypto_internal.h b/sgx-jvm/linux-sgx/common/inc/internal/sgx_tcrypto_internal.h new file mode 100644 index 0000000000..666b36125a --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/sgx_tcrypto_internal.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SGX_TCRYPTO_INTERNAL_H_ +#define _SGX_TCRYPTO_INTERNAL_H_ + +#include "sgx_tcrypto.h" + +typedef struct _sgx_ec256_dh_shared512_t +{ + uint8_t x[SGX_ECP256_KEY_SIZE]; + uint8_t y[SGX_ECP256_KEY_SIZE]; +} sgx_ec256_dh_shared512_t; + +#ifdef __cplusplus +extern "C" { +#endif + + /* Computes 512-bit DH shared key based on private B key (local) and remote public Ga Key + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Inputs: sgx_ecc_state_handle_t ecc_handle - Handle to the ECC crypto system + * sgx_ec256_private_t *p_private_b - Pointer to the local private key + * sgx_ec256_public_t *p_public_ga - Pointer to the remote public key + * Output: sgx_ec256_dh_shared512_t *p_shared_key - Pointer to the 512-bit shared DH key + */ + sgx_status_t SGXAPI sgx_ecc256_compute_shared_dhkey512(sgx_ec256_private_t *p_private_b, + sgx_ec256_public_t *p_public_ga, + sgx_ec256_dh_shared512_t *p_shared_key, + sgx_ecc_state_handle_t ecc_handle); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/tae_service_internal.h b/sgx-jvm/linux-sgx/common/inc/internal/tae_service_internal.h new file mode 100644 index 0000000000..948402c2bd --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/tae_service_internal.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _TAE_SERVICE_INTERNAL_H_ +#define _TAE_SERVICE_INTERNAL_H_ + +#include +#include "sgx.h" +#include "arch.h" +#include "sgx_tae_service.h" +#include "pse_types.h" + +#pragma pack(push, 1) + +typedef struct _se_ps_sec_prop_desc_internal +{ + uint32_t desc_type; /* Type of this descriptor. Must be 0 */ + sgx_prod_id_t pse_prod_id; /* REPORT(PSE).ProdID */ + sgx_isv_svn_t pse_isvsvn; /* REPORT(PSE).ISVSVN */ + uint32_t pse_miscselect; /* REPORT(PSE).MISC_SELECT */ + uint32_t reserved1; /* For DESC_TYPE=0, MBZ */ + sgx_attributes_t pse_attributes; /* REPORT(PSE).ATTRIBUTES */ + sgx_measurement_t pse_mr_signer; /* REPORT(PSE).MRSIGNER */ + uint32_t reserved2[16]; + /*the following will be provided by PSE from CSE_SEC_PROP */ + cse_sec_prop_t cse_sec_prop; +} se_ps_sec_prop_desc_internal_t; + +se_static_assert(sizeof(se_ps_sec_prop_desc_internal_t) == sizeof(sgx_ps_sec_prop_desc_t)); + +#pragma pack(pop) + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/thread_data.h b/sgx-jvm/linux-sgx/common/inc/internal/thread_data.h new file mode 100644 index 0000000000..da2bfe7abc --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/thread_data.h @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _THREAD_DATA_H_ +#define _THREAD_DATA_H_ + +#include "se_types.h" +#include "se_cdefs.h" + +#ifdef TD_SUPPORT_MULTI_PLATFORM +/* To enable the SignTool to sign both 32/64-bit Enclave for ELF, + * we need to make the struct `thread_data_t' have a consistent + * definition for 32/64-bit compiler. + * + * We achieve it by forcing the compiler to check pre-defined macros + * `RTS_SYSTEM_WORDSIZE' + * + * |--------------------------+-------| + * | RTS_SYSTEM_WORDSIZE = 32 | ELF32 | + * |--------------------------+-------| + * | RTS_SYSTEM_WORDSIZE = 64 | ELF64 | + * + */ +# ifndef RTS_SYSTEM_WORDSIZE +# error RTS_SYSTEM_WORDSIZE should be pre-defined. +# endif + +/* Avoid to use `uintptr_t' in the struct `thread_data_t' and its members. */ +# if RTS_SYSTEM_WORDSIZE == 32 +typedef uint32_t sys_word_t; +# elif RTS_SYSTEM_WORDSIZE == 64 +typedef uint64_t sys_word_t; +# else +# error Invalid value for 'RTS_SYSTEM_WORDSIZE'. +# endif + +#else + +/* For uRTS, there is no need to define the macro 'TD_SUPPORT_MULTI_PLATFORM' */ +typedef size_t sys_word_t; + +/* SE_32 and SE_64 are defined in "se_cdefs.h" */ +# ifdef SE_32 +# define RTS_SYSTEM_WORDSIZE 32 +# elif defined(SE_64) +# define RTS_SYSTEM_WORDSIZE 64 +# else +# error Unknown system word size. +# endif + +#endif /* ! TD_SUPPORT_MULTI_PLATFORM */ + +/* The data structure currently is naturally aligned regardless of the value of + * RTS_SYSTEM_WORDSIZE. + * + * However, we need to take care when modifying the data structure in future. + */ + +typedef struct _thread_data_t +{ + sys_word_t self_addr; + sys_word_t last_sp; /* set by urts, relative to TCS */ + sys_word_t stack_base_addr; /* set by urts, relative to TCS */ + sys_word_t stack_limit_addr; /* set by urts, relative to TCS */ + sys_word_t first_ssa_gpr; /* set by urts, relative to TCS */ + sys_word_t stack_guard; /* GCC expects start_guard at 0x14 on x86 and 0x28 on x64 */ + + sys_word_t reserved; + sys_word_t ssa_frame_size; /* set by urts, in pages (se_ptrace.c needs to know its offset). */ + sys_word_t last_error; /* init to be 0. Used by trts. */ + +#ifdef TD_SUPPORT_MULTI_PLATFORM + sys_word_t m_next; /* next TD used by trusted thread library (of type "struct _thread_data *") */ +#else + struct _thread_data_t *m_next; +#endif + sys_word_t tls_addr; /* points to TLS pages */ + sys_word_t tls_array; /* points to TD.tls_addr relative to TCS */ +#ifdef TD_SUPPORT_MULTI_PLATFORM + sys_word_t exception_flag; /* mark how many exceptions are being handled */ +#else + intptr_t exception_flag; +#endif + sys_word_t cxx_thread_info[6]; +} thread_data_t; + +#ifdef __cplusplus +extern "C" { +#endif + +thread_data_t *get_thread_data(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/trts_inst.h b/sgx-jvm/linux-sgx/common/inc/internal/trts_inst.h new file mode 100644 index 0000000000..09ed8ae9f5 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/trts_inst.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _TRTS_INST_H_ +#define _TRTS_INST_H_ + +#include "sgx.h" + +/* Attention: + * if the following alignment requirement changes, go to selib to + * review the memory allocation of sgx_create_report and sgx_get_key. + */ +#define TARGET_INFO_ALIGN_SIZE 512 +#define REPORT_DATA_ALIGN_SIZE 128 +#define REPORT_ALIGN_SIZE 512 +#define KEY_REQUEST_ALIGN_SIZE 512 +#define KEY_ALIGN_SIZE 16 + +#define BIT_ERROR(x) (1 << (x)) + +typedef enum _egetkey_status_t +{ + EGETKEY_SUCCESS = 0, + EGETKEY_INVALID_ATTRIBUTE = BIT_ERROR(1), + EGETKEY_INVALID_CPUSVN = BIT_ERROR(5), + EGETKEY_INVALID_ISVSVN = BIT_ERROR(6), + EGETKEY_INVALID_KEYNAME = BIT_ERROR(8), +} egetkey_status_t; + +#ifdef __cplusplus +extern "C" { +#endif + +void do_ereport(const sgx_target_info_t *target_info, const sgx_report_data_t *report_data, sgx_report_t *report); +int do_egetkey(const sgx_key_request_t *key_request, sgx_key_128bit_t *key); +uint32_t do_rdrand(uint32_t *rand); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/uae_service_internal.h b/sgx-jvm/linux-sgx/common/inc/internal/uae_service_internal.h new file mode 100644 index 0000000000..75428cadef --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/uae_service_internal.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _UAE_SERVICE_INTERNAL_H_ +#define _UAE_SERVICE_INTERNAL_H_ + +#include +#include "arch.h" +#include "sgx_urts.h" + +#ifdef __cplusplus +extern "C" { +#endif +/** + * Function to get launch token of a enclave + * + * @param signature[in] Signature of enclave to be launched. + * @param attribute[in] Attribute of enclave to be launched. + * @param launch_token[out] Vontains launch token. + * @return if a launch token is generated,return SGX_SCCUESS, otherwise return general error code SGX_ERROR_SERVICE_UNAVAILABLE + * SGX_ERROR_SERVICE_TIMEOUT, or SGX_ERROR_SERVICE_INVALID_PRIVILEGE, SGX_ERROR_INVALID_PARAMETER + * to indicate special error condition. + */ +sgx_status_t SGXAPI get_launch_token(const enclave_css_t* signature, const sgx_attributes_t* attribute, sgx_launch_token_t* launch_token); + +/* Return SGX_SUCCESS on success */ +sgx_status_t create_session_ocall(uint32_t* sid, uint8_t* dh_msg1, uint32_t dh_msg1_size, uint32_t timeout); + +/* Return SGX_SUCCESS on success */ +sgx_status_t exchange_report_ocall(uint32_t sid, const uint8_t* dh_msg2, uint32_t dh_msg2_size, uint8_t* dh_msg3, uint32_t dh_msg3_size, uint32_t timeout); + +/* Return SGX_SUCCESS on success */ +sgx_status_t close_session_ocall(uint32_t sid, uint32_t timeout); + +/* Return SGX_SUCCESS on success */ +sgx_status_t invoke_service_ocall( + const uint8_t* pse_message_req, uint32_t pse_message_req_size, + uint8_t* pse_message_resp, uint32_t pse_message_resp_size, + uint32_t timeout + ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/uncopyable.h b/sgx-jvm/linux-sgx/common/inc/internal/uncopyable.h new file mode 100644 index 0000000000..b271953f79 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/uncopyable.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _UNCOPYABLE_H_ +#define _UNCOPYABLE_H_ + +/* Similiar to boost::noncopyable */ +class Uncopyable { +protected: + Uncopyable() {} + ~Uncopyable() {} + +private: + /* Disable copying */ + Uncopyable(const Uncopyable&); + Uncopyable& operator=(const Uncopyable&); +}; + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/util.h b/sgx-jvm/linux-sgx/common/inc/internal/util.h new file mode 100644 index 0000000000..ce066ec32a --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/util.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _UTIL_H_ +#define _UTIL_H_ + +#include "arch.h" +#include + +#ifdef __cplusplus +#define GET_PTR(t, p, offset) reinterpret_cast( reinterpret_cast(p) + static_cast(offset) ) +#define PTR_DIFF(p1, p2) ((reinterpret_cast(p1) - reinterpret_cast(p2))) +#else +#define GET_PTR(t, p, offset) (t*)( (size_t)(p) + (size_t)(offset) ) +#define PTR_DIFF(p1, p2) ((size_t)(p1) - (size_t)(p2)) +#endif + +#define DIFF(p1, p2) (assert((size_t)(p1) >= (size_t)(p2)), ((size_t)(p1) - (size_t)(p2))) +#define DIFF64(p1, p2) (assert((uint64_t)(p1) >= (uint64_t)(p2)), ((uint64_t)(p1) - (uint64_t)(p2))) + +#define SE_PAGE_SHIFT 12 +#define SE_BULK_PAGE_FRAME_SHIFT 4 +#define SE_BULK_PAGE_FRAME_SIZE (1 << SE_BULK_PAGE_FRAME_SHIFT) +#define SE_BULK_PAGE_FRAME_MASK (SE_BULK_PAGE_FRAME_SIZE-1) +#define SE_BULK_PAGE_SHIFT (SE_PAGE_SHIFT + SE_BULK_PAGE_FRAME_SHIFT) +#define SE_BULK_PAGE_SIZE (1 << SE_BULK_PAGE_SHIFT) +#define SE_GUARD_PAGE_SHIFT SE_PAGE_SHIFT +#define SE_GUARD_PAGE_SIZE SE_PAGE_SIZE + +#define ROUND_TO(x, align) (((x) + ((align)-1)) & ~((align)-1)) +#define ROUND_TO_PAGE(x) ROUND_TO(x, SE_PAGE_SIZE) +#define TRIM_TO_PAGE(x) ((x) & ~(SE_PAGE_SIZE-1)) +#define PAGE_OFFSET(x) ((x) & (SE_PAGE_SIZE -1)) +#ifdef __cplusplus +#define PAGE_ALIGN(t, x) reinterpret_cast((reinterpret_cast(x)+(SE_PAGE_SIZE-1)) & (~(SE_PAGE_SIZE-1))) +#else +#define PAGE_ALIGN(t, x) (t*)( ((size_t)(x)+(SE_PAGE_SIZE-1)) & (~(SE_PAGE_SIZE-1)) ) +#endif + +#define IS_PAGE_ALIGNED(x) (!((size_t)(x)&(SE_PAGE_SIZE-1))) + +#define MIN(x, y) (((x)>(y))?(y):(x)) +#define MAX(x, y) (((x)>(y))?(x):(y)) +#define ARRAY_LENGTH(x) (sizeof(x)/sizeof(x[0])) + +/* used to eliminate `unused variable' warning */ +#define UNUSED(val) (void)(val) + +#include +#define container_of(ptr, type, member) (type *)( (char *)(ptr) - offsetof(type,member) ) + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/internal/xsave.h b/sgx-jvm/linux-sgx/common/inc/internal/xsave.h new file mode 100644 index 0000000000..431d453542 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/internal/xsave.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _XSAVE_H_ +#define _XSAVE_H_ + +#include "se_types.h" + + +#define XSAVE_ALIGN_SIZE 64 +#define FXSAVE_ALIGN_SIZE 16 +#define FXSAVE_SIZE 528 +/* 512 + 16, the alignment is handled in internal functions */ + +#define CLEAN_XFEATURE_REGS save_and_clean_xfeature_regs(NULL); + +#ifdef __cplusplus +extern "C" { +#endif + +#include "linux/xsave_gnu.h" + +/* implemented in urts_xsave.cpp/trts_xsave.cpp */ +void save_and_clean_xfeature_regs(uint8_t *buffer); +void restore_xfeature_regs(const uint8_t *buffer); + +/* trts_xsave.cpp */ +uint64_t get_xfeature_state(); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx.h b/sgx-jvm/linux-sgx/common/inc/sgx.h new file mode 100644 index 0000000000..7695c65d04 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SGX_H_ +#define _SGX_H_ + +#include "sgx_error.h" +#include "sgx_attributes.h" +#include "sgx_key.h" +#include "sgx_report.h" + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_attributes.h b/sgx-jvm/linux-sgx/common/inc/sgx_attributes.h new file mode 100644 index 0000000000..665ce88547 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_attributes.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SGX_ATTRIBUTES_H_ +#define _SGX_ATTRIBUTES_H_ + +#include + +/* Enclave Flags Bit Masks */ +#define SGX_FLAGS_INITTED 0x0000000000000001ULL /* If set, then the enclave is initialized */ +#define SGX_FLAGS_DEBUG 0x0000000000000002ULL /* If set, then the enclave is debug */ +#define SGX_FLAGS_MODE64BIT 0x0000000000000004ULL /* If set, then the enclave is 64 bit */ +#define SGX_FLAGS_PROVISION_KEY 0x0000000000000010ULL /* If set, then the enclave has access to provision key */ +#define SGX_FLAGS_EINITOKEN_KEY 0x0000000000000020ULL /* If set, then the enclave has access to EINITOKEN key */ +#define SGX_FLAGS_RESERVED (~(SGX_FLAGS_INITTED | SGX_FLAGS_DEBUG | SGX_FLAGS_MODE64BIT | SGX_FLAGS_PROVISION_KEY | SGX_FLAGS_EINITOKEN_KEY)) + +/* XSAVE Feature Request Mask */ +#define SGX_XFRM_LEGACY 0x0000000000000003ULL /* Legacy XFRM */ +#define SGX_XFRM_AVX 0x0000000000000006ULL /* AVX */ +#define SGX_XFRM_AVX512 0x00000000000000E6ULL /* AVX-512 - not supported */ +#define SGX_XFRM_MPX 0x0000000000000018ULL /* MPX - not supported */ + +#define SGX_XFRM_RESERVED (~(SGX_XFRM_LEGACY | SGX_XFRM_AVX)) + +typedef struct _attributes_t +{ + uint64_t flags; + uint64_t xfrm; +} sgx_attributes_t; + +/* define MISCSELECT - all bits are currently reserved */ +typedef uint32_t sgx_misc_select_t; + +typedef struct _sgx_misc_attribute_t { + sgx_attributes_t secs_attr; + sgx_misc_select_t misc_select; +} sgx_misc_attribute_t; + +#endif/* _SGX_ATTRIBUTES_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_cpuid.h b/sgx-jvm/linux-sgx/common/inc/sgx_cpuid.h new file mode 100644 index 0000000000..2d4221280b --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_cpuid.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +/** + * File: sgx_cpuid.h + * Description: + * Enquire CPU capabilities via OCALLs. + */ + +#ifndef _SGX_CPUID_H_ +#define _SGX_CPUID_H_ + +#include "sgx_defs.h" +#include "sgx_error.h" + +#ifdef __cplusplus +extern "C" { +#endif + +sgx_status_t SGXAPI sgx_cpuid(int cpuinfo[4], int leaf); +sgx_status_t SGXAPI sgx_cpuidex(int cpuinfo[4], int leaf, int subleaf); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_defs.h b/sgx-jvm/linux-sgx/common/inc/sgx_defs.h new file mode 100644 index 0000000000..4b0a658283 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_defs.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SGX_DEFS_H_ +#define _SGX_DEFS_H_ + +/* The following macros are for GCC only */ + +# define SGXAPI + +# ifdef linux +# undef linux +# endif +# define SGX_CXX_NATIVE_HEADER(header) + +# define SGX_CDECL +# define SGX_STDCALL +# define SGX_FASTCALL + +# define SGX_DLLIMPORT +# define SGX_UBRIDGE(attr, fname, args...) attr fname args + + +#define SGX_NOCONVENTION /* Empty. No calling convention specified. */ + +#endif /* !_SGX_DEFS_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_dh.h b/sgx-jvm/linux-sgx/common/inc/sgx_dh.h new file mode 100644 index 0000000000..9860271a0b --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_dh.h @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#ifndef _SGX_DH_H_ +#define _SGX_DH_H_ + +#include "sgx.h" +#include "sgx_defs.h" +#include "sgx_ecp_types.h" + +#pragma pack(push, 1) + +#define SGX_DH_MAC_SIZE 16 + +#define SGX_DH_SESSION_DATA_SIZE 200 + +typedef struct _sgx_dh_msg1_t +{ + sgx_ec256_public_t g_a; /* the Endian-ness of Ga is Little-Endian */ + sgx_target_info_t target; +} sgx_dh_msg1_t; + +typedef struct _sgx_dh_msg2_t +{ + sgx_ec256_public_t g_b; /* the Endian-ness of Gb is Little-Endian */ + sgx_report_t report; + uint8_t cmac[SGX_DH_MAC_SIZE]; +} sgx_dh_msg2_t; + +typedef struct _sgx_dh_msg3_body_t +{ + sgx_report_t report; + uint32_t additional_prop_length; + uint8_t additional_prop[0]; +} sgx_dh_msg3_body_t; + + +typedef struct _sgx_dh_msg3_t +{ + uint8_t cmac[SGX_DH_MAC_SIZE]; + sgx_dh_msg3_body_t msg3_body; +} sgx_dh_msg3_t; + +typedef struct _sgx_dh_session_enclave_identity_t +{ + sgx_cpu_svn_t cpu_svn; + sgx_misc_select_t misc_select; + uint8_t reserved_1[28]; + sgx_attributes_t attributes; + sgx_measurement_t mr_enclave; + uint8_t reserved_2[32]; + sgx_measurement_t mr_signer; + uint8_t reserved_3[96]; + sgx_prod_id_t isv_prod_id; + sgx_isv_svn_t isv_svn; +} sgx_dh_session_enclave_identity_t; + +typedef enum _sgx_dh_session_role_t +{ + SGX_DH_SESSION_INITIATOR, + SGX_DH_SESSION_RESPONDER +} sgx_dh_session_role_t; + +typedef struct _sgx_dh_session_t +{ + uint8_t sgx_dh_session[SGX_DH_SESSION_DATA_SIZE]; +} sgx_dh_session_t; +#pragma pack(pop) +#ifdef __cplusplus +extern "C" { +#endif + +/* The order of calling SGX DH Library APIs is restricted as below */ +/* As session initiator : Step.1 sgx_dh_init_session --> Step.2 sgx_dh_initiator_proc_msg1 --> Step.3 sgx_dh_initiator_proc_msg3 */ +/* As session responder : Step.1 sgx_dh_init_session --> Step.2 sgx_dh_responder_gen_msg1 --> Step.3 sgx_dh_responder_proc_msg2*/ +/* Any out of order calling will cause session establishment failure. */ + +/*Function name: sgx_dh_init_session +** parameter description +**@ [input] role: caller's role in dh session establishment +**@ [output] session: point to dh session structure that is used during establishment, the buffer must be in enclave address space +*/ +sgx_status_t SGXAPI sgx_dh_init_session(sgx_dh_session_role_t role, + sgx_dh_session_t* session); +/*Function name: sgx_dh_responder_gen_msg1 +** parameter description +**@ [output] msg1: point to dh message 1 buffer, and the buffer must be in enclave address space +**@ [input/output] dh_session: point to dh session structure that is used during establishment, and the buffer must be in enclave address space +*/ +sgx_status_t SGXAPI sgx_dh_responder_gen_msg1(sgx_dh_msg1_t* msg1, + sgx_dh_session_t* dh_session); +/*Function name: sgx_dh_initiator_proc_msg1 +** parameter description +**@ [input] msg1: point to dh message 1 buffer generated by session responder, and the buffer must be in enclave address space +**@ [output] msg2: point to dh message 2 buffer, and the buffer must be in enclave address space +**@ [input/output] dh_session: point to dh session structure that is used during establishment, and the buffer must be in enclave address space +*/ +sgx_status_t SGXAPI sgx_dh_initiator_proc_msg1(const sgx_dh_msg1_t* msg1, + sgx_dh_msg2_t* msg2, + sgx_dh_session_t* dh_session); +/*Function name: sgx_dh_responder_proc_msg2 +** parameter description +**@ [input] msg2: point to dh message 2 buffer generated by session initiator, and the buffer must be in enclave address space +**@ [output] msg3: point to dh message 3 buffer generated by session responder in this function, and the buffer must be in enclave address space +**@ [input/output] dh_session: point to dh session structure that is used during establishment, and the buffer must be in enclave address space +**@ [output] aek: AEK derived from shared key. the buffer must be in enclave address space. +**@ [output] initiator_identity: identity information of initiator including isv svn, isv product id, sgx attributes, mr signer, and mr enclave. the buffer must be in enclave address space. +*/ +sgx_status_t SGXAPI sgx_dh_responder_proc_msg2(const sgx_dh_msg2_t* msg2, + sgx_dh_msg3_t* msg3, + sgx_dh_session_t* dh_session, + sgx_key_128bit_t* aek, + sgx_dh_session_enclave_identity_t* initiator_identity); +/*Function name: sgx_dh_initiator_proc_msg3 +** parameter description +**@ [input] msg3: point to dh message 3 buffer generated by session responder, and the buffer must be in enclave address space +**@ [input/output] dh_session: point to dh session structure that is used during establishment, and the buffer must be in enclave address space +**@ [output] aek: AEK derived from shared key. the buffer must be in enclave address space. +**@ [output] responder_identity: identity information of responder including isv svn, isv product id, sgx attributes, mr signer, and mr enclave. the buffer must be in enclave address space. +*/ +sgx_status_t SGXAPI sgx_dh_initiator_proc_msg3(const sgx_dh_msg3_t* msg3, + sgx_dh_session_t* dh_session, + sgx_key_128bit_t* aek, + sgx_dh_session_enclave_identity_t* responder_identity); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_ecp_types.h b/sgx-jvm/linux-sgx/common/inc/sgx_ecp_types.h new file mode 100644 index 0000000000..ef935d103b --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_ecp_types.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#ifndef _SGX_ECP_TYPES_H_ +#define _SGX_ECP_TYPES_H_ + +#include + +#pragma pack(push, 1) + +#include "sgx_tcrypto.h" + +#ifndef SGX_FEBITSIZE +#define SGX_FEBITSIZE 256 +#endif + +typedef struct _ecc_param_t +{ + uint32_t eccP[SGX_NISTP_ECP256_KEY_SIZE]; /* EC prime field */ + uint32_t eccA[SGX_NISTP_ECP256_KEY_SIZE]; /* EC curve coefficient A */ + uint32_t eccB[SGX_NISTP_ECP256_KEY_SIZE]; /* EC curve coefficient B */ + uint32_t eccG[2][SGX_NISTP_ECP256_KEY_SIZE]; /* ECC base point */ + uint32_t eccR[SGX_NISTP_ECP256_KEY_SIZE]; /* ECC base point order */ +} sgx_ecc_param_t; + +typedef uint8_t sgx_ec_key_128bit_t[SGX_CMAC_KEY_SIZE]; + +#pragma pack(pop) + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_edger8r.h b/sgx-jvm/linux-sgx/common/inc/sgx_edger8r.h new file mode 100644 index 0000000000..f3da7873df --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_edger8r.h @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +/* + * Here contains functions intended to be used by `sgx_edger8r' only. + * + * ------------------------------------- + * Be warned: use them at your own risk. + * ------------------------------------- + * + */ + +#ifndef _SGX_EDGER8R_H_ +#define _SGX_EDGER8R_H_ + +#include "sgx_defs.h" +#include "sgx_error.h" +#include "sgx_eid.h" +#include /* for size_t */ + +/* The `sgx_edger8r' tool will generate C interfaces. */ +#ifdef __cplusplus +# define SGX_EXTERNC extern "C" +#else +# define SGX_EXTERNC +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* sgx_ocalloc() + * Parameters: + * size - bytes to allocate on the outside stack + * Return Value: + * the pointer to the allocated space on the outside stack + * NULL - fail to allocate +*/ +void* SGXAPI sgx_ocalloc(size_t size); + +/* sgx_ocfree() + * Parameters: + * N/A + * Return Value: + * N/A +*/ +void SGXAPI sgx_ocfree(void); + +/* sgx_ecall() + * Parameters: + * eid - the enclave id + * index - the index of the trusted function + * ocall_table - the address of the OCALL table + * ms - the pointer to the marshaling struct + * Return Value: + * SGX_SUCCESS on success +*/ +sgx_status_t SGXAPI sgx_ecall(const sgx_enclave_id_t eid, + const int index, + const void* ocall_table, + void* ms); + +/* sgx_ocall() + * Parameters: + * index - the index of the untrusted function + * ms - the pointer to the marshaling struct + * Return Value: + * SGX_SUCCESS on success +*/ +sgx_status_t SGXAPI sgx_ocall(const unsigned int index, + void* ms); + +#ifdef __cplusplus +} +#endif + +#endif /* !_SGX_EDGER8R_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_eid.h b/sgx-jvm/linux-sgx/common/inc/sgx_eid.h new file mode 100644 index 0000000000..ea2dfc6e28 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_eid.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SGX_EID_H_ +#define _SGX_EID_H_ + +#include + +typedef uint64_t sgx_enclave_id_t; + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_error.h b/sgx-jvm/linux-sgx/common/inc/sgx_error.h new file mode 100644 index 0000000000..d093fd8a1e --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_error.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SGX_ERROR_H_ +#define _SGX_ERROR_H_ + +#define SGX_MK_ERROR(x) (0x00000000|(x)) + +typedef enum _status_t +{ + SGX_SUCCESS = SGX_MK_ERROR(0x0000), + + SGX_ERROR_UNEXPECTED = SGX_MK_ERROR(0x0001), /* Unexpected error */ + SGX_ERROR_INVALID_PARAMETER = SGX_MK_ERROR(0x0002), /* The parameter is incorrect */ + SGX_ERROR_OUT_OF_MEMORY = SGX_MK_ERROR(0x0003), /* Not enough memory is available to complete this operation */ + SGX_ERROR_ENCLAVE_LOST = SGX_MK_ERROR(0x0004), /* Enclave lost after power transition or used in child process created by linux:fork() */ + SGX_ERROR_INVALID_STATE = SGX_MK_ERROR(0x0005), /* SGX API is invoked in incorrect order or state */ + + SGX_ERROR_INVALID_FUNCTION = SGX_MK_ERROR(0x1001), /* The ecall/ocall index is invalid */ + SGX_ERROR_OUT_OF_TCS = SGX_MK_ERROR(0x1003), /* The enclave is out of TCS */ + SGX_ERROR_ENCLAVE_CRASHED = SGX_MK_ERROR(0x1006), /* The enclave is crashed */ + SGX_ERROR_ECALL_NOT_ALLOWED = SGX_MK_ERROR(0x1007), /* The ECALL is not allowed at this time, e.g. ecall is blocked by the dynamic entry table, or nested ecall is not allowed during initialization */ + SGX_ERROR_OCALL_NOT_ALLOWED = SGX_MK_ERROR(0x1008), /* The OCALL is not allowed at this time, e.g. ocall is not allowed during exception handling */ + SGX_ERROR_STACK_OVERRUN = SGX_MK_ERROR(0x1009), /* The enclave is running out of stack */ + + SGX_ERROR_UNDEFINED_SYMBOL = SGX_MK_ERROR(0x2000), /* The enclave image has undefined symbol. */ + SGX_ERROR_INVALID_ENCLAVE = SGX_MK_ERROR(0x2001), /* The enclave image is not correct. */ + SGX_ERROR_INVALID_ENCLAVE_ID = SGX_MK_ERROR(0x2002), /* The enclave id is invalid */ + SGX_ERROR_INVALID_SIGNATURE = SGX_MK_ERROR(0x2003), /* The signature is invalid */ + SGX_ERROR_NDEBUG_ENCLAVE = SGX_MK_ERROR(0x2004), /* The enclave is signed as product enclave, and can not be created as debuggable enclave. */ + SGX_ERROR_OUT_OF_EPC = SGX_MK_ERROR(0x2005), /* Not enough EPC is available to load the enclave */ + SGX_ERROR_NO_DEVICE = SGX_MK_ERROR(0x2006), /* Can't open SGX device */ + SGX_ERROR_MEMORY_MAP_CONFLICT= SGX_MK_ERROR(0x2007), /* Page mapping failed in driver */ + SGX_ERROR_INVALID_METADATA = SGX_MK_ERROR(0x2009), /* The metadata is incorrect. */ + SGX_ERROR_DEVICE_BUSY = SGX_MK_ERROR(0x200c), /* Device is busy, mostly EINIT failed. */ + SGX_ERROR_INVALID_VERSION = SGX_MK_ERROR(0x200d), /* Metadata version is inconsistent between uRTS and sgx_sign or uRTS is incompatible with current platform. */ + SGX_ERROR_MODE_INCOMPATIBLE = SGX_MK_ERROR(0x200e), /* The target enclave 32/64 bit mode or sim/hw mode is incompatible with the mode of current uRTS. */ + SGX_ERROR_ENCLAVE_FILE_ACCESS = SGX_MK_ERROR(0x200f), /* Can't open enclave file. */ + SGX_ERROR_INVALID_MISC = SGX_MK_ERROR(0x2010), /* The MiscSelct/MiscMask settings are not correct.*/ + + SGX_ERROR_MAC_MISMATCH = SGX_MK_ERROR(0x3001), /* Indicates verification error for reports, sealed datas, etc */ + SGX_ERROR_INVALID_ATTRIBUTE = SGX_MK_ERROR(0x3002), /* The enclave is not authorized */ + SGX_ERROR_INVALID_CPUSVN = SGX_MK_ERROR(0x3003), /* The cpu svn is beyond platform's cpu svn value */ + SGX_ERROR_INVALID_ISVSVN = SGX_MK_ERROR(0x3004), /* The isv svn is greater than the enclave's isv svn */ + SGX_ERROR_INVALID_KEYNAME = SGX_MK_ERROR(0x3005), /* The key name is an unsupported value */ + + SGX_ERROR_SERVICE_UNAVAILABLE = SGX_MK_ERROR(0x4001), /* Indicates aesm didn't response or the requested service is not supported */ + SGX_ERROR_SERVICE_TIMEOUT = SGX_MK_ERROR(0x4002), /* The request to aesm time out */ + SGX_ERROR_AE_INVALID_EPIDBLOB = SGX_MK_ERROR(0x4003), /* Indicates epid blob verification error */ + SGX_ERROR_SERVICE_INVALID_PRIVILEGE = SGX_MK_ERROR(0x4004), /* Enclave has no privilege to get launch token */ + SGX_ERROR_EPID_MEMBER_REVOKED = SGX_MK_ERROR(0x4005), /* The EPID group membership is revoked. */ + SGX_ERROR_UPDATE_NEEDED = SGX_MK_ERROR(0x4006), /* SGX needs to be updated */ + SGX_ERROR_NETWORK_FAILURE = SGX_MK_ERROR(0x4007), /* Network connecting or proxy setting issue is encountered */ + SGX_ERROR_AE_SESSION_INVALID = SGX_MK_ERROR(0x4008), /* Session is invalid or ended by server */ + SGX_ERROR_BUSY = SGX_MK_ERROR(0x400a), /* The requested service is temporarily not availabe */ + SGX_ERROR_MC_NOT_FOUND = SGX_MK_ERROR(0x400c), /* The Monotonic Counter doesn't exist or has been invalided */ + SGX_ERROR_MC_NO_ACCESS_RIGHT = SGX_MK_ERROR(0x400d), /* Caller doesn't have the access right to specified VMC */ + SGX_ERROR_MC_USED_UP = SGX_MK_ERROR(0x400e), /* Monotonic counters are used out */ + SGX_ERROR_MC_OVER_QUOTA = SGX_MK_ERROR(0x400f), /* Monotonic counters exceeds quota limitation */ + SGX_ERROR_KDF_MISMATCH = SGX_MK_ERROR(0x4011), /* Key derivation function doesn't match during key exchange */ + +} sgx_status_t; + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_intrin.h b/sgx-jvm/linux-sgx/common/inc/sgx_intrin.h new file mode 100644 index 0000000000..237a1cd6f1 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_intrin.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#ifndef _SGX_INTRIN_H_ +#define _SGX_INTRIN_H_ + +#if defined(__STDC__) || defined(__cplusplus) +# define __STRING(x) #x +#else +# define __STRING(x) "x" +#endif + +#define _DEPR_MESSAGE(func) __STRING(func)" is deprecated in enclave." + +/* Deprecated GCC Built-ins */ + +# include + +/*#pragma GCC diagnostic error "-Wdeprecated-declarations" */ +#define _SGX_DEPRECATED(__ret_type, __func_name, ...) \ + __attribute__((deprecated(_DEPR_MESSAGE(__func_name)))) \ + __ret_type __func_name(__VA_ARGS__) + +_SGX_DEPRECATED(void, _writefsbase_u32, unsigned int); +_SGX_DEPRECATED(void, _writefsbase_u64, unsigned long long); +_SGX_DEPRECATED(void, _writegsbase_u32, unsigned int); +_SGX_DEPRECATED(void, _writegsbase_u64, unsigned long long); + +_SGX_DEPRECATED(unsigned long long, __rdpmc, int); +_SGX_DEPRECATED(unsigned long long, __rdtsc, void); +_SGX_DEPRECATED(unsigned long long, __rdtscp, unsigned int *); + + +#endif /* _SGX_INTRIN_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_key.h b/sgx-jvm/linux-sgx/common/inc/sgx_key.h new file mode 100644 index 0000000000..b607747843 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_key.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + + +/* + * This file is to define Enclave's keys +*/ + +#ifndef _SGX_KEY_H_ +#define _SGX_KEY_H_ + +#include +#include "sgx_attributes.h" + +/* Key Name */ +#define SGX_KEYSELECT_EINITOKEN 0x0000 +#define SGX_KEYSELECT_PROVISION 0x0001 +#define SGX_KEYSELECT_PROVISION_SEAL 0x0002 +#define SGX_KEYSELECT_REPORT 0x0003 +#define SGX_KEYSELECT_SEAL 0x0004 + +/* Key Policy */ +#define SGX_KEYPOLICY_MRENCLAVE 0x0001 /* Derive key using the enclave's ENCLAVE measurement register */ +#define SGX_KEYPOLICY_MRSIGNER 0x0002 /* Derive key using the enclave's SINGER measurement register */ + +#define SGX_KEYID_SIZE 32 +#define SGX_CPUSVN_SIZE 16 + +typedef uint8_t sgx_key_128bit_t[16]; +typedef uint16_t sgx_isv_svn_t; + +typedef struct _sgx_cpu_svn_t +{ + uint8_t svn[SGX_CPUSVN_SIZE]; +} sgx_cpu_svn_t; + +typedef struct _sgx_key_id_t +{ + uint8_t id[SGX_KEYID_SIZE]; +} sgx_key_id_t; + +#define SGX_KEY_REQUEST_RESERVED2_BYTES 436 + +typedef struct _key_request_t +{ + uint16_t key_name; /* Identifies the key required */ + uint16_t key_policy; /* Identifies which inputs should be used in the key derivation */ + sgx_isv_svn_t isv_svn; /* Security Version of the Enclave */ + uint16_t reserved1; /* Must be 0 */ + sgx_cpu_svn_t cpu_svn; /* Security Version of the CPU */ + sgx_attributes_t attribute_mask; /* Mask which ATTRIBUTES Seal keys should be bound to */ + sgx_key_id_t key_id; /* Value for key wear-out protection */ + sgx_misc_select_t misc_mask; /* Mask what MISCSELECT Seal keys bound to */ + uint8_t reserved2[SGX_KEY_REQUEST_RESERVED2_BYTES]; /* Struct size is 512 bytes */ +} sgx_key_request_t; + + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_key_exchange.h b/sgx-jvm/linux-sgx/common/inc/sgx_key_exchange.h new file mode 100644 index 0000000000..570945f013 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_key_exchange.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SGX_KEY_EXCHANGE_H_ +#define _SGX_KEY_EXCHANGE_H_ + +#include +#include "sgx_quote.h" +#include "sgx_ecp_types.h" +#include "sgx_tae_service.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef uint32_t sgx_ra_context_t; + +typedef sgx_key_128bit_t sgx_ra_key_128_t; + +typedef enum _ra_key_type_t +{ + SGX_RA_KEY_SK = 1, + SGX_RA_KEY_MK, + SGX_RA_KEY_VK, +} sgx_ra_key_type_t; + +typedef struct _ra_msg1_t +{ + sgx_ec256_public_t g_a; /* the Endian-ness of Ga is Little-Endian */ + sgx_epid_group_id_t gid; /* the Endian-ness of GID is Little-Endian */ +} sgx_ra_msg1_t; + + +typedef struct _ra_msg2_t +{ + sgx_ec256_public_t g_b; /* the Endian-ness of Gb is Little-Endian */ + sgx_spid_t spid; + uint16_t quote_type; /* unlinkable Quote(0) or linkable Quote(1) in little endian*/ + uint16_t kdf_id; /* key derivation function id in little endian. */ + sgx_ec256_signature_t sign_gb_ga; /* In little endian */ + sgx_mac_t mac; /* mac_smk(g_b||spid||quote_type||kdf_id||sign_gb_ga) */ + uint32_t sig_rl_size; + uint8_t sig_rl[]; +} sgx_ra_msg2_t; + +typedef struct _ra_msg3_t +{ + sgx_mac_t mac; /* mac_smk(g_a||ps_sec_prop||quote) */ + sgx_ec256_public_t g_a; /* the Endian-ness of Ga is Little-Endian */ + sgx_ps_sec_prop_desc_t ps_sec_prop; + uint8_t quote[]; +} sgx_ra_msg3_t; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_quote.h b/sgx-jvm/linux-sgx/common/inc/sgx_quote.h new file mode 100644 index 0000000000..aec125e893 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_quote.h @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + + /** + * File: sgx_quote.h + * Description: Definition for quote structure. + * + * Quote structure and all relative structure will be defined in this file. + */ + +#ifndef _SGX_QUOTE_H_ +#define _SGX_QUOTE_H_ + +#include "sgx_report.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#pragma pack(push, 1) +typedef uint8_t sgx_epid_group_id_t[4]; + +typedef struct _spid_t +{ + uint8_t id[16]; +} sgx_spid_t; + +typedef struct _basename_t +{ + uint8_t name[32]; +} sgx_basename_t; + + +typedef struct _quote_nonce +{ + uint8_t rand[16]; +} sgx_quote_nonce_t; + +typedef enum +{ + SGX_UNLINKABLE_SIGNATURE, + SGX_LINKABLE_SIGNATURE +} sgx_quote_sign_type_t; + +typedef struct _quote_t +{ + uint16_t version; /* 0 */ + uint16_t sign_type; /* 2 */ + sgx_epid_group_id_t epid_group_id; /* 4 */ + sgx_isv_svn_t qe_svn; /* 8 */ + sgx_isv_svn_t pce_svn; /* 10 */ + uint32_t xeid; /* 12 */ + sgx_basename_t basename; /* 16 */ + sgx_report_body_t report_body; /* 48 */ + uint32_t signature_len; /* 432 */ + uint8_t signature[]; /* 436 */ +} sgx_quote_t; + +#define SGX_PLATFORM_INFO_SIZE 101 +typedef struct _platform_info +{ + uint8_t platform_info[SGX_PLATFORM_INFO_SIZE]; +} sgx_platform_info_t; + +typedef struct _update_info_bit +{ + int ucodeUpdate; + int csmeFwUpdate; + int pswUpdate; +} sgx_update_info_bit_t; + +#pragma pack(pop) + + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_report.h b/sgx-jvm/linux-sgx/common/inc/sgx_report.h new file mode 100644 index 0000000000..8d26087397 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_report.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +/* + * This file is to define Enclave's Report +*/ + +#ifndef _SGX_REPORT_H_ +#define _SGX_REPORT_H_ + +#include "sgx_attributes.h" +#include "sgx_key.h" + +#define SGX_HASH_SIZE 32 /* SHA256 */ +#define SGX_MAC_SIZE 16 /* Message Authentication Code - 16 bytes */ + +#define SGX_REPORT_DATA_SIZE 64 + +typedef struct _sgx_measurement_t +{ + uint8_t m[SGX_HASH_SIZE]; +} sgx_measurement_t; + +typedef uint8_t sgx_mac_t[SGX_MAC_SIZE]; + +typedef struct _sgx_report_data_t +{ + uint8_t d[SGX_REPORT_DATA_SIZE]; +} sgx_report_data_t; + +typedef uint16_t sgx_prod_id_t; + +#define SGX_TARGET_INFO_RESERVED1_BYTES 4 +#define SGX_TARGET_INFO_RESERVED2_BYTES 456 + +typedef struct _targe_info_t +{ + sgx_measurement_t mr_enclave; /* ( 0) The MRENCLAVE of the target enclave */ + sgx_attributes_t attributes; /* ( 32) The ATTRIBUTES field of the target enclave */ + uint8_t reserved1[SGX_TARGET_INFO_RESERVED1_BYTES]; /* ( 48) Reserved */ + sgx_misc_select_t misc_select; /* ( 52) The MISCSELECT of the target enclave */ + uint8_t reserved2[SGX_TARGET_INFO_RESERVED2_BYTES]; /* ( 56) Struct size is 512 bytes */ +} sgx_target_info_t; + +typedef struct _report_body_t +{ + sgx_cpu_svn_t cpu_svn; /* ( 0) Security Version of the CPU */ + sgx_misc_select_t misc_select; /* ( 16) Which fields defined in SSA.MISC */ + uint8_t reserved1[28]; /* ( 20) */ + sgx_attributes_t attributes; /* ( 48) Any special Capabilities the Enclave possess */ + sgx_measurement_t mr_enclave; /* ( 64) The value of the enclave's ENCLAVE measurement */ + uint8_t reserved2[32]; /* ( 96) */ + sgx_measurement_t mr_signer; /* (128) The value of the enclave's SIGNER measurement */ + uint8_t reserved3[96]; /* (160) */ + sgx_prod_id_t isv_prod_id; /* (256) Product ID of the Enclave */ + sgx_isv_svn_t isv_svn; /* (258) Security Version of the Enclave */ + uint8_t reserved4[60]; /* (260) */ + sgx_report_data_t report_data; /* (320) Data provided by the user */ +} sgx_report_body_t; + +typedef struct _report_t /* 432 bytes */ +{ + sgx_report_body_t body; + sgx_key_id_t key_id; /* (384) KeyID used for diversifying the key tree */ + sgx_mac_t mac; /* (416) The Message Authentication Code over this structure. */ +} sgx_report_t; + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_spinlock.h b/sgx-jvm/linux-sgx/common/inc/sgx_spinlock.h new file mode 100644 index 0000000000..77d8084856 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_spinlock.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + + + +#ifndef _SGX_SPINLOCK_H_ +#define _SGX_SPINLOCK_H_ + +#include "sgx_defs.h" +#include + +typedef volatile uint32_t sgx_spinlock_t; + +#define SGX_SPINLOCK_INITIALIZER 0 + +#if defined(__cplusplus) +extern "C" { +#endif + +uint32_t SGXAPI sgx_spin_lock(sgx_spinlock_t *lock); +uint32_t SGXAPI sgx_spin_unlock(sgx_spinlock_t *lock); + +#if defined(__cplusplus) +} +#endif + +#endif /* !_SGX_SPINLOCK_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_tae_service.edl b/sgx-jvm/linux-sgx/common/inc/sgx_tae_service.edl new file mode 100644 index 0000000000..9b19a8026b --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_tae_service.edl @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +enclave{ + from "sgx_tstdc.edl" import *; + untrusted { + sgx_status_t create_session_ocall([out] uint32_t* sid, + [size = dh_msg1_size, out] uint8_t* dh_msg1, + uint32_t dh_msg1_size, + uint32_t timeout); + + sgx_status_t exchange_report_ocall(uint32_t sid, + [size = dh_msg2_size, in] uint8_t* dh_msg2, uint32_t dh_msg2_size, + [size = dh_msg3_size, out] uint8_t* dh_msg3, uint32_t dh_msg3_size, + uint32_t timeout); + + sgx_status_t close_session_ocall(uint32_t sid, uint32_t timeout); + + sgx_status_t invoke_service_ocall([size = pse_message_req_size, in] uint8_t* pse_message_req, + uint32_t pse_message_req_size, + [size = pse_message_resp_size, out] uint8_t* pse_message_resp, uint32_t pse_message_resp_size, + uint32_t timeout); + }; +}; diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_tae_service.h b/sgx-jvm/linux-sgx/common/inc/sgx_tae_service.h new file mode 100644 index 0000000000..687f230607 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_tae_service.h @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SGX_TAE_SERVICE_H_ +#define _SGX_TAE_SERVICE_H_ + +/** +* File: +* sgx_tae_service.h +*Description: +* header for trusted AE support library. +* ADD from path/sgx_tae_service.edl import *; to your edl file +* to use sgx_tae_service.lib +*/ + +#include "sgx.h" +#include "sgx_defs.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +#pragma pack(push, 1) + +typedef uint64_t sgx_time_t; + +typedef uint8_t sgx_time_source_nonce_t[32]; + +#define SGX_MC_UUID_COUNTER_ID_SIZE 3 +#define SGX_MC_UUID_NONCE_SIZE 13 +typedef struct _mc_uuid { + uint8_t counter_id[SGX_MC_UUID_COUNTER_ID_SIZE]; + uint8_t nonce[SGX_MC_UUID_NONCE_SIZE]; +} sgx_mc_uuid_t; + +/* fixed length to align with internal structure */ +typedef struct _ps_sec_prop_desc +{ + uint8_t sgx_ps_sec_prop_desc[256]; +} sgx_ps_sec_prop_desc_t; + +#pragma pack(pop) + +/* create a session, call it before using Platform Service */ +sgx_status_t SGXAPI sgx_create_pse_session(void); + +/* close a created session, call it after finishing using Platform Service */ +sgx_status_t SGXAPI sgx_close_pse_session(void); + +/* get a data structure describing the Security Property of the Platform Service */ +sgx_status_t SGXAPI sgx_get_ps_sec_prop(sgx_ps_sec_prop_desc_t* security_property); + +/* provides the trusted platform current time */ +sgx_status_t SGXAPI sgx_get_trusted_time( + sgx_time_t* current_time, + sgx_time_source_nonce_t* time_source_nonce + ); + +/* monotonic counter policy */ +#define SGX_MC_POLICY_SIGNER 0x1 +#define SGX_MC_POLICY_ENCLAVE 0x2 +/* create a monotonic counter using given policy(SIGNER 0x1 or ENCLAVE 0x2) and attribute_mask */ +sgx_status_t SGXAPI sgx_create_monotonic_counter_ex( + uint16_t owner_policy, + const sgx_attributes_t* owner_attribute_mask, + sgx_mc_uuid_t* counter_uuid, + uint32_t* counter_value + ); + +/* create a monotonic counter using default policy SIGNER and default attribute_mask */ +sgx_status_t SGXAPI sgx_create_monotonic_counter( + sgx_mc_uuid_t* counter_uuid, + uint32_t* counter_value + ); + +/* destroy a specified monotonic counter */ +sgx_status_t SGXAPI sgx_destroy_monotonic_counter(const sgx_mc_uuid_t* counter_uuid); + +/* increment a specified monotonic counter by 1 */ +sgx_status_t SGXAPI sgx_increment_monotonic_counter( + const sgx_mc_uuid_t* counter_uuid, + uint32_t* counter_value + ); + +/* read a specified monotonic counter */ +sgx_status_t SGXAPI sgx_read_monotonic_counter( + const sgx_mc_uuid_t* counter_uuid, + uint32_t* counter_value + ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_tcrypto.h b/sgx-jvm/linux-sgx/common/inc/sgx_tcrypto.h new file mode 100644 index 0000000000..8ecf0b32d0 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_tcrypto.h @@ -0,0 +1,588 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +/** +* File: sgx_tcrypto.h +* Description: +* Interface for generic crypto library APIs required in SDK implementation. +*/ + +#ifndef _SGX_TCRYPTO_H_ +#define _SGX_TCRYPTO_H_ + +#include "sgx.h" +#include "sgx_defs.h" + +#define SGX_SHA256_HASH_SIZE 32 +#define SGX_ECP256_KEY_SIZE 32 +#define SGX_NISTP_ECP256_KEY_SIZE (SGX_ECP256_KEY_SIZE/sizeof(uint32_t)) +#define SGX_AESGCM_IV_SIZE 12 +#define SGX_AESGCM_KEY_SIZE 16 +#define SGX_AESGCM_MAC_SIZE 16 +#define SGX_CMAC_KEY_SIZE 16 +#define SGX_CMAC_MAC_SIZE 16 +#define SGX_AESCTR_KEY_SIZE 16 + +typedef struct _sgx_ec256_dh_shared_t +{ + uint8_t s[SGX_ECP256_KEY_SIZE]; +} sgx_ec256_dh_shared_t; + +typedef struct _sgx_ec256_private_t +{ + uint8_t r[SGX_ECP256_KEY_SIZE]; +} sgx_ec256_private_t; + +typedef struct _sgx_ec256_public_t +{ + uint8_t gx[SGX_ECP256_KEY_SIZE]; + uint8_t gy[SGX_ECP256_KEY_SIZE]; +} sgx_ec256_public_t; + +typedef struct _sgx_ec256_signature_t +{ + uint32_t x[SGX_NISTP_ECP256_KEY_SIZE]; + uint32_t y[SGX_NISTP_ECP256_KEY_SIZE]; +} sgx_ec256_signature_t; + +typedef void* sgx_sha_state_handle_t; +typedef void* sgx_cmac_state_handle_t; +typedef void* sgx_ecc_state_handle_t; + +typedef uint8_t sgx_sha256_hash_t[SGX_SHA256_HASH_SIZE]; + +typedef uint8_t sgx_aes_gcm_128bit_key_t[SGX_AESGCM_KEY_SIZE]; +typedef uint8_t sgx_aes_gcm_128bit_tag_t[SGX_AESGCM_MAC_SIZE]; +typedef uint8_t sgx_cmac_128bit_key_t[SGX_CMAC_KEY_SIZE]; +typedef uint8_t sgx_cmac_128bit_tag_t[SGX_CMAC_MAC_SIZE]; +typedef uint8_t sgx_aes_ctr_128bit_key_t[SGX_AESCTR_KEY_SIZE]; + +typedef enum { + SGX_EC_VALID, /* validation pass successfully */ + + SGX_EC_COMPOSITE_BASE, /* field based on composite */ + SGX_EC_COMPLICATED_BASE, /* number of non-zero terms in the polynomial (> PRIME_ARR_MAX) */ + SGX_EC_IS_ZERO_DISCRIMINANT,/* zero discriminant */ + SGX_EC_COMPOSITE_ORDER, /* composite order of base point */ + SGX_EC_INVALID_ORDER, /* invalid base point order */ + SGX_EC_IS_WEAK_MOV, /* weak Meneze-Okamoto-Vanstone reduction attack */ + SGX_EC_IS_WEAK_SSA, /* weak Semaev-Smart,Satoh-Araki reduction attack */ + SGX_EC_IS_SUPER_SINGULAR, /* supersingular curve */ + + SGX_EC_INVALID_PRIVATE_KEY, /* !(0 < Private < order) */ + SGX_EC_INVALID_PUBLIC_KEY, /* (order*PublicKey != Infinity) */ + SGX_EC_INVALID_KEY_PAIR, /* (Private*BasePoint != PublicKey) */ + + SGX_EC_POINT_OUT_OF_GROUP, /* out of group (order*P != Infinity) */ + SGX_EC_POINT_IS_AT_INFINITY,/* point (P=(Px,Py)) at Infinity */ + SGX_EC_POINT_IS_NOT_VALID, /* point (P=(Px,Py)) out-of EC */ + + SGX_EC_POINT_IS_EQUAL, /* compared points are equal */ + SGX_EC_POINT_IS_NOT_EQUAL, /* compared points are different */ + + SGX_EC_INVALID_SIGNATURE /* invalid signature */ +} sgx_generic_ecresult_t; + + +#ifdef __cplusplus +extern "C" { +#endif + + /** SHA Hashing functions - NOTE: ONLY 256-bit is supported. + * + * NOTE: Use sgx_sha256_msg if the src pointer contains the complete msg to perform hash (Option 1) + * Else use the Init, Update, Update, ..., Final procedure (Option 2) + * Option 1: If the complete dataset is available for hashing, sgx_sha256_msg + * is a single API call for generating the 256bit hash for the given dataset. + * Return: If source pointer or hash pointer are NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * If hash function fails then SGX_ERROR_UNEXPECTED is returned. + * Option 2: If the hash is to be performed over multiple data sets, then use: + * A. sgx_sha256_init - to create the context - context memory is allocated by this function. + * Return: If out of enclave memory, SGX_ERROR_OUT_OF_MEMORY is returned. + * If context creation fails then SGX_ERROR_UNEXPECTED is returned. + * B. sgx_sha256_update - updates hash based on input source data + * This function should be called for each chunk of data to be + * included in the hash including the 1st and final chunks. + * Return: If source pointer or context pointer are NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * If hash function fails then SGX_ERROR_UNEXPECTED is returned. + * C. sgx_sha256_get_hash - function obtains the hash value + * Return: If hash pointer or context pointer are NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * If the function fails then SGX_ERROR_UNEXPECTED is returned. + * D. sgx_sha256_close - SHOULD BE CALLED to FREE context memory + * Upon completing the process of computing a hash over a set of data + * or sets of data, this function is used to free the context. + * Return: If context pointer is NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Inputs: uint8_t *p_src - Pointer to the input stream to be hashed + * uint32_t src_len - Length of the input stream to be hashed + * Output: sgx_sha256_hash_t *p_hash - Resultant hash from operation + */ + sgx_status_t SGXAPI sgx_sha256_msg(const uint8_t *p_src, uint32_t src_len, sgx_sha256_hash_t *p_hash); + + /** Allocates and initializes sha256 state + * + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Output: sgx_sha_state_handle_t *p_sha_handle - Pointer to the handle of the SHA256 state + */ + sgx_status_t SGXAPI sgx_sha256_init(sgx_sha_state_handle_t* p_sha_handle); + + /** Updates sha256 has calculation based on the input message + * + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Input: sgx_sha_state_handle_t sha_handle - Handle to the SHA256 state + * uint8_t *p_src - Pointer to the input stream to be hashed + * uint32_t src_len - Length of the input stream to be hashed + */ + sgx_status_t SGXAPI sgx_sha256_update(const uint8_t *p_src, uint32_t src_len, sgx_sha_state_handle_t sha_handle); + + /** Returns Hash calculation + * + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Input: sgx_sha_state_handle_t sha_handle - Handle to the SHA256 state + * Output: sgx_sha256_hash_t *p_hash - Resultant hash from operation + */ + sgx_status_t SGXAPI sgx_sha256_get_hash(sgx_sha_state_handle_t sha_handle, sgx_sha256_hash_t *p_hash); + + /** Cleans up SHA state + * + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Input: sgx_sha_state_handle_t sha_handle - Handle to the SHA256 state + */ + sgx_status_t SGXAPI sgx_sha256_close(sgx_sha_state_handle_t sha_handle); + + /**Rijndael AES-GCM - Only 128-bit key AES-GCM Encryption/Decryption is supported + * + * The Galois/Counter Mode (GCM) is a mode of operation of the AES algorithm. + * GCM [NIST SP 800-38D] uses a variation of the Counter mode of operation for encryption. + * GCM assures authenticity of the confidential data (of up to about 64 GB per invocation) + * using a universal hash function defined over a binary finite field (the Galois field). + * + * GCM can also provide authentication assurance for additional data + * (of practically unlimited length per invocation) that is not encrypted. + * GCM provides stronger authentication assurance than a (non-cryptographic) checksum or + * error detecting code. In particular, GCM can detect both accidental modifications of + * the data and intentional, unauthorized modifications. + * + * sgx_rijndael128GCM_encrypt: + * Return: If key, source, destination, MAC, or IV pointer is NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * If AAD size is > 0 and the AAD pointer is NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * If the Source Length is < 1, SGX_ERROR_INVALID_PARAMETER is returned. + * IV Length must = 12 (bytes) or SGX_ERROR_INVALID_PARAMETER is returned. + * If out of enclave memory then SGX_ERROR_OUT_OF_MEMORY is returned. + * If the encryption process fails then SGX_ERROR_UNEXPECTED is returned. + * + * sgx_rijndael128GCM_decrypt: + * Return: If key, source, destination, MAC, or IV pointer is NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * If AAD size is > 0 and the AAD pointer is NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * If the Source Length is < 1, SGX_ERROR_INVALID_PARAMETER is returned. + * IV Length must = 12 (bytes) or SGX_ERROR_INVALID_PARAMETER is returned. + * If the decryption process fails then SGX_ERROR_UNEXPECTED is returned. + * If the input MAC does not match the calculated MAC, SGX_ERROR_MAC_MISMATCH is returned. + * + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Inputs: sgx_aes_gcm_128bit_key_t *p_key - Pointer to the key used in encryption/decryption operation + * Size MUST BE 128-bits + * uint8_t *p_src - Pointer to the input stream to be encrypted/decrypted + * uint32_t src_len - Length of the input stream to be encrypted/decrypted + * uint8_t *p_iv - Pointer to the initialization vector + * uint32_t iv_len - Length of the initialization vector - MUST BE 12 (bytes) + * NIST AES-GCM recommended IV size = 96 bits + * uint8_t *p_aad - Pointer to the input stream of additional authentication data + * uint32_t aad_len - Length of the additional authentication data stream + * sgx_aes_gcm_128bit_tag_t *p_in_mac - Pointer to the expected MAC in decryption process + * Output: uint8_t *p_dst - Pointer to the cipher text for encryption or clear text for decryption. Size of buffer should be >= src_len. + * sgx_aes_gcm_128bit_tag_t *p_out_mac - Pointer to the MAC generated from encryption process + * NOTE: Wrapper is responsible for confirming decryption tag matches encryption tag + */ + sgx_status_t SGXAPI sgx_rijndael128GCM_encrypt(const sgx_aes_gcm_128bit_key_t *p_key, + const uint8_t *p_src, + uint32_t src_len, + uint8_t *p_dst, + const uint8_t *p_iv, + uint32_t iv_len, + const uint8_t *p_aad, + uint32_t aad_len, + sgx_aes_gcm_128bit_tag_t *p_out_mac); + sgx_status_t SGXAPI sgx_rijndael128GCM_decrypt(const sgx_aes_gcm_128bit_key_t *p_key, + const uint8_t *p_src, + uint32_t src_len, + uint8_t *p_dst, + const uint8_t *p_iv, + uint32_t iv_len, + const uint8_t *p_aad, + uint32_t aad_len, + const sgx_aes_gcm_128bit_tag_t *p_in_mac); + + /** Message Authentication Rijndael 128 CMAC - Only 128-bit key size is supported. + * NOTE: Use sgx_rijndael128_cmac_msg if the src ptr contains the complete msg to perform hash (Option 1) + * Else use the Init, Update, Update, ..., Final, Close procedure (Option 2) + * Option 1: If the complete dataset is available for hashing, sgx_rijndael128_cmac_msg + * is a single API call for generating the 128-bit hash for the given dataset. + * Return: If source, key, or MAC pointer is NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * If out of enclave memory, SGX_ERROR_OUT_OF_MEMORY is returned. + * If hash function fails then SGX_ERROR_UNEXPECTED is returned. + * Option 2: If the hash is to be performed over multiple data sets, then use: + * A. sgx_cmac128_init - to create the context - context memory is allocated by this function. + * Return: If key pointer is NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * If out of enclave memory, SGX_ERROR_OUT_OF_MEMORY is returned. + * If context creation fails then SGX_ERROR_UNEXPECTED is returned. + * B. sgx_cmac128_update - updates hash based on input source data + * This function should be called for each chunk of data to be + * included in the hash including the 1st and final chunks. + * Return: If source pointer or context pointer are NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * If hash function fails then SGX_ERROR_UNEXPECTED is returned. + * C. sgx_cmac128_final - function obtains the hash value + * Upon completing the process of computing a hash over a set of data or sets of data, + * this function populates the hash value. + * Return: If hash pointer or context pointer are NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * If the function fails then SGX_ERROR_UNEXPECTED is returned. + * D. sgx_cmac128_close - SHOULD BE CALLED to clean up the CMAC state + * Upon populating the hash value over a set of data or sets of data, + * this function is used to free the CMAC state. + * Return: If CMAC state pointer is NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Inputs: sgx_cmac_128bit_key_t *p_key - Pointer to the key used in encryption/decryption operation + * uint8_t *p_src - Pointer to the input stream to be MAC’d + * uint32_t src_len - Length of the input stream to be MAC’d + * Output: sgx_cmac_gcm_128bit_tag_t *p_mac - Pointer to the resultant MAC + */ + sgx_status_t SGXAPI sgx_rijndael128_cmac_msg(const sgx_cmac_128bit_key_t *p_key, + const uint8_t *p_src, + uint32_t src_len, + sgx_cmac_128bit_tag_t *p_mac); + /** Allocates and initializes CMAC state. + * + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Inputs: sgx_cmac_128bit_key_t *p_key - Pointer to the key used in encryption/decryption operation + * Output: sgx_cmac_state_handle_t *p_cmac_handle - Pointer to the handle of the CMAC state + */ + sgx_status_t SGXAPI sgx_cmac128_init(const sgx_cmac_128bit_key_t *p_key, sgx_cmac_state_handle_t* p_cmac_handle); + + /** Updates CMAC has calculation based on the input message. + * + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Input: sgx_cmac_state_handle_t cmac_handle - Handle to the CMAC state + * uint8_t *p_src - Pointer to the input stream to be hashed + * uint32_t src_len - Length of the input stream to be hashed + */ + sgx_status_t SGXAPI sgx_cmac128_update(const uint8_t *p_src, uint32_t src_len, sgx_cmac_state_handle_t cmac_handle); + + /** Returns Hash calculation and clean up CMAC state. + * + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Input: sgx_cmac_state_handle_t cmac_handle - Handle to the CMAC state + * Output: sgx_cmac_128bit_tag_t *p_hash - Resultant hash from operation + */ + sgx_status_t SGXAPI sgx_cmac128_final(sgx_cmac_state_handle_t cmac_handle, sgx_cmac_128bit_tag_t *p_hash); + + /** Clean up the CMAC state + * + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Input: sgx_cmac_state_handle_t cmac_handle - Handle to the CMAC state + */ + sgx_status_t SGXAPI sgx_cmac128_close(sgx_cmac_state_handle_t cmac_handle); + + + /** AES-CTR 128-bit - Only 128-bit key size is supported. + * + * These functions encrypt/decrypt the input data stream of a variable length according + * to the CTR mode as specified in [NIST SP 800-38A]. The counter can be thought of as + * an IV which increments on successive encryption or decrytion calls. For a given + * dataset or data stream the incremented counter block should be used on successive + * calls of the encryption/decryption process for that given stream. However for + * new or different datasets/streams, the same counter should not be reused, instead + * intialize the counter for the new data set. + * + * sgx_aes_ctr_encrypt + * Return: If source, key, counter, or destination pointer is NULL, + * SGX_ERROR_INVALID_PARAMETER is returned. + * If out of enclave memory, SGX_ERROR_OUT_OF_MEMORY is returned. + * If the encryption process fails then SGX_ERROR_UNEXPECTED is returned. + * sgx_aes_ctr_decrypt + * Return: If source, key, counter, or destination pointer is NULL, + * SGX_ERROR_INVALID_PARAMETER is returned. + * If out of enclave memory, SGX_ERROR_OUT_OF_MEMORY is returned. + * If the decryption process fails then SGX_ERROR_UNEXPECTED is returned. + * + * Parameters: + * Return: + * sgx_status_t - SGX_SUCCESS or failure as defined + * in sgx_error.h + * Inputs: + * sgx_aes_128bit_key_t *p_key - Pointer to the key used in + * encryption/decryption operation + * uint8_t *p_src - Pointer to the input stream to be + * encrypted/decrypted + * uint32_t src_len - Length of the input stream to be + * encrypted/decrypted + * uint8_t *p_ctr - Pointer to the counter block + * uint32_t ctr_inc_bits - Number of bits in counter to be + * incremented + * Output: + * uint8_t *p_dst - Pointer to the cipher text. + * Size of buffer should be >= src_len. + */ + sgx_status_t SGXAPI sgx_aes_ctr_encrypt( + const sgx_aes_ctr_128bit_key_t *p_key, + const uint8_t *p_src, + const uint32_t src_len, + uint8_t *p_ctr, + const uint32_t ctr_inc_bits, + uint8_t *p_dst); + sgx_status_t SGXAPI sgx_aes_ctr_decrypt( + const sgx_aes_ctr_128bit_key_t *p_key, + const uint8_t *p_src, + const uint32_t src_len, + uint8_t *p_ctr, + const uint32_t ctr_inc_bits, + uint8_t *p_dst); + + + /** + * Elliptic Curve Cryptography based on GF(p), 256 bit. + * + * Elliptic curve cryptosystems (ECCs) implement a different way of creating public keys. + * Because elliptic curve calculation is based on the addition of the rational points in + * the (x,y) plane and it is difficult to solve a discrete logarithm from these points, + * a higher level of security is achieved through the cryptographic schemes that use the + * elliptic curves. The cryptographic systems that encrypt messages by using the properties + * of elliptic curves are hard to attack due to the extreme complexity of deciphering the + * private key. + * + * Use of elliptic curves allows for shorter public key length and encourage cryptographers + * to create cryptosystems with the same or higher encryption strength as the RSA or DSA + * cryptosystems. Because of the relatively short key length, ECCs do encryption and decryption + * faster on the hardware that requires less computation processing volumes. For example, with + * a key length of 150-350 bits, ECCs provide the same encryption strength as the cryptosystems + * who have to use 600 -1400 bits. + * + * ECCP stands for Elliptic Curve Cryptography Prime and these functions include operations + * over a prime finite field GF(p). + * + */ + /** Allocates and initializes ecc context. + * The function initializes the context of the elliptic curve cryptosystem over the + * prime finite field GF(p). This function allocates and initializes the ecc context. + * Return: If out of enclave memory, SGX_ERROR_OUT_OF_MEMORY is returned. + * If context creation fails then SGX_ERROR_UNEXPECTED is returned. + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Output: sgx_ecc_state_handle_t *p_ecc_handle - Pointer to the handle of the ECC crypto system + */ + sgx_status_t SGXAPI sgx_ecc256_open_context(sgx_ecc_state_handle_t* p_ecc_handle); + + /** Cleans up ecc context. + * Return: If context pointer is NULL, SGX_ERROR_INVALID_PARAMETER is returned. + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Output: sgx_ecc_state_handle_t ecc_handle - Handle to the ECC crypto system + */ + sgx_status_t SGXAPI sgx_ecc256_close_context(sgx_ecc_state_handle_t ecc_handle); + + /** Populates private/public key pair. + * NOTE: Caller code allocates memory for Private & Public key pointers to be populated + * + * The function generates a private key p_private and computes a public key p_public of the + * elliptic cryptosystem over a finite field GF(p). + * + * The private key p_private is a number that lies in the range of [1, n-1] where n is + * the order of the elliptic curve base point. + * + * The public key p_public is an elliptic curve point such that p_public = p_private ?G, + * where G is the base point of the elliptic curve. + * + * The context of the point p_public as an elliptic curve point must be created by using + * the function sgx_ecc256_open_context. + * + * Return: If context, public key, or private key pointer is NULL, + * SGX_ERROR_INVALID_PARAMETER is returned. + * If the key creation process fails then SGX_ERROR_UNEXPECTED is returned. + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Inputs: sgx_ecc_state_handle_t ecc_handle - Handle to the ECC crypto system + * Outputs: sgx_ec256_private_t *p_private - Pointer to the private key - LITTLE ENDIAN + * sgx_ec256_public_t *p_public - Pointer to the public key - LITTLE ENDIAN + */ + sgx_status_t SGXAPI sgx_ecc256_create_key_pair(sgx_ec256_private_t *p_private, + sgx_ec256_public_t *p_public, + sgx_ecc_state_handle_t ecc_handle); + + /** Checks whether the input point is a valid point on the given elliptic curve. + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined sgx_error.h + * Inputs: sgx_ecc_state_handle_t ecc_handle - Handle to ECC crypto system + * sgx_ec256_public_t *p_point - Pointer to perform validity check on - LITTLE ENDIAN + * Output: int *p_valid - Return 0 if the point is an invalid point on ECC curve + */ + sgx_status_t SGXAPI sgx_ecc256_check_point(const sgx_ec256_public_t *p_point, + const sgx_ecc_state_handle_t ecc_handle, + int *p_valid); + + /** Computes DH shared key based on own (local) private key and remote public Ga Key. + * NOTE: Caller code allocates memory for Shared key pointer to be populated + * + * The function computes a secret number bnShare, which is a secret key shared between + * two participants of the cryptosystem. + * + * In cryptography, metasyntactic names such as Alice as Bob are normally used as examples + * and in discussions and stand for participant A and participant B. + * + * Both participants (Alice and Bob) use the cryptosystem for receiving a common secret point + * on the elliptic curve called a secret key. To receive a secret key, participants apply the + * Diffie-Hellman key-agreement scheme involving public key exchange. The value of the secret + * key entirely depends on participants. + * + * According to the scheme, Alice and Bob perform the following operations: + * 1. Alice calculates her own public key pubKeyA by using her private key + * privKeyA: pubKeyA = privKeyA ?G, where G is the base point of the elliptic curve. + * 2. Alice passes the public key to Bob. + * 3. Bob calculates his own public key pubKeyB by using his private key + * privKeyB: pubKeyB = privKeyB ?G, where G is a base point of the elliptic curve. + * 4. Bob passes the public key to Alice. + * 5. Alice gets Bob's public key and calculates the secret point shareA. When calculating, + * she uses her own private key and Bob's public key and applies the following formula: + * shareA = privKeyA ?pubKeyB = privKeyA ?privKeyB ?G. + * 6. Bob gets Alice's public key and calculates the secret point shareB. When calculating, + * he uses his own private key and Alice's public key and applies the following formula: + * shareB = privKeyB ?pubKeyA = privKeyB ?privKeyA ?G. + * + * Because the following equation is true privKeyA ?privKeyB ?G = privKeyB ?privKeyA ?G, + * the result of both calculations is the same, that is, the equation shareA = shareB is true. + * The secret point serves as a secret key. + * + * Shared secret bnShare is an x-coordinate of the secret point on the elliptic curve. The elliptic + * curve domain parameters must be hitherto defined by the function: sgx_ecc256_open_context. + * + * Return: If context, public key, private key, or shared key pointer is NULL, + * SGX_ERROR_INVALID_PARAMETER is returned. + * If the remote public key is not a valid point on the elliptic curve, + * SGX_ERROR_INVALID_PARAMETER is returned. + * If the key creation process fails then SGX_ERROR_UNEXPECTED is returned. + * + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Inputs: sgx_ecc_state_handle_t ecc_handle - Handle to the ECC crypto system + * sgx_ec256_private_t *p_private_b - Pointer to the local private key - LITTLE ENDIAN + * sgx_ec256_public_t *p_public_ga - Pointer to the remote public key - LITTLE ENDIAN + * Output: sgx_ec256_dh_shared_t *p_shared_key - Pointer to the shared DH key - LITTLE ENDIAN + */ + sgx_status_t SGXAPI sgx_ecc256_compute_shared_dhkey(sgx_ec256_private_t *p_private_b, + sgx_ec256_public_t *p_public_ga, + sgx_ec256_dh_shared_t *p_shared_key, + sgx_ecc_state_handle_t ecc_handle); + + /** Computes signature for data based on private key. + * + * A message digest is a fixed size number derived from the original message with + * an applied hash function over the binary code of the message. (SHA256 in this case) + * The signer's private key and the message digest are used to create a signature. + * + * A digital signature over a message consists of a pair of large numbers, 256-bits each, + * which the given function computes. + * + * The scheme used for computing a digital signature is of the ECDSA scheme, + * an elliptic curve of the DSA scheme. + * + * The keys can be generated and set up by the function: sgx_ecc256_create_key_pair. + * + * The elliptic curve domain parameters must be created by function: + * sgx_ecc256_open_context + * + * Return: If context, private key, signature or data pointer is NULL, + * SGX_ERROR_INVALID_PARAMETER is returned. + * If the signature creation process fails then SGX_ERROR_UNEXPECTED is returned. + * + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Inputs: sgx_ecc_state_handle_t ecc_handle - Handle to the ECC crypto system + * sgx_ec256_private_t *p_private - Pointer to the private key - LITTLE ENDIAN + * uint8_t *p_data - Pointer to the data to be signed + * uint32_t data_size - Size of the data to be signed + * Output: ec256_signature_t *p_signature - Pointer to the signature - LITTLE ENDIAN + */ + sgx_status_t SGXAPI sgx_ecdsa_sign(const uint8_t *p_data, + uint32_t data_size, + sgx_ec256_private_t *p_private, + sgx_ec256_signature_t *p_signature, + sgx_ecc_state_handle_t ecc_handle); + + /** Verifies the signature for the given data based on the public key. + * + * A digital signature over a message consists of a pair of large numbers, 256-bits each, + * which could be created by function: sgx_ecdsa_sign. The scheme used for computing a + * digital signature is of the ECDSA scheme, an elliptic curve of the DSA scheme. + * + * The typical result of the digital signature verification is one of the two values: + * SGX_Generic_ECValid - Digital signature is valid + * SGX_Generic_ECInvalidSignature - Digital signature is not valid + * + * The elliptic curve domain parameters must be created by function: + * sgx_ecc256_open_context + * + * Return: If context, public key, signature, result or data pointer is NULL, + * SGX_ERROR_INVALID_PARAMETER is returned. + * If the verification process fails then SGX_ERROR_UNEXPECTED is returned. + * Parameters: + * Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h + * Inputs: sgx_ecc_state_handle_t ecc_handle - Handle to the ECC crypto system + * sgx_ec256_public_t *p_public - Pointer to the public key + * uint8_t *p_data - Pointer to the data to be signed + * uint32_t data_size - Size of the data to be signed + * sgx_ec256_signature_t *p_signature - Pointer to the signature + * Output: uint8_t *p_result - Pointer to the result of verification check + */ + sgx_status_t SGXAPI sgx_ecdsa_verify(const uint8_t *p_data, + uint32_t data_size, + const sgx_ec256_public_t *p_public, + sgx_ec256_signature_t *p_signature, + uint8_t *p_result, + sgx_ecc_state_handle_t ecc_handle); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_thread.h b/sgx-jvm/linux-sgx/common/inc/sgx_thread.h new file mode 100644 index 0000000000..ee0274c9e3 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_thread.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SGX_THREAD_H_ +#define _SGX_THREAD_H_ + +#include +#include +#include "sgx_defs.h" + +typedef uintptr_t sgx_thread_t; + +typedef struct sgx_thread_queue +{ + sgx_thread_t m_first; /* first element */ + sgx_thread_t m_last; /* last element */ +} sgx_thread_queue_t; + +/* Mutex */ +typedef struct sgx_thread_mutex +{ + size_t m_refcount; + uint32_t m_control; + volatile uint32_t m_lock; /* use sgx_spinlock_t */ + sgx_thread_t m_owner; + sgx_thread_queue_t m_queue; +} sgx_thread_mutex_t; + +#define SGX_THREAD_T_NULL ((sgx_thread_t)(NULL)) + +#define SGX_THREAD_MUTEX_NONRECURSIVE 0x01 +#define SGX_THREAD_MUTEX_RECURSIVE 0x02 +#define SGX_THREAD_NONRECURSIVE_MUTEX_INITIALIZER \ + {0, SGX_THREAD_MUTEX_NONRECURSIVE, 0, SGX_THREAD_T_NULL, {SGX_THREAD_T_NULL, SGX_THREAD_T_NULL}} +#define SGX_THREAD_RECURSIVE_MUTEX_INITIALIZER \ + {0, SGX_THREAD_MUTEX_RECURSIVE, 0, SGX_THREAD_T_NULL, {SGX_THREAD_T_NULL, SGX_THREAD_T_NULL}} +#define SGX_THREAD_MUTEX_INITIALIZER \ + SGX_THREAD_NONRECURSIVE_MUTEX_INITIALIZER + +typedef struct sgx_thread_mutex_attr +{ + unsigned char m_dummy; /* for C syntax check */ +} sgx_thread_mutexattr_t; + +/* Condition Variable */ +typedef struct sgx_thread_cond +{ + volatile uint32_t m_lock; /* use sgx_spinlock_t */ + sgx_thread_queue_t m_queue; +} sgx_thread_cond_t; + +#define SGX_THREAD_COND_INITIALIZER {0, {SGX_THREAD_T_NULL, SGX_THREAD_T_NULL}} + +typedef struct sgx_thread_cond_attr +{ + unsigned char m_dummy; /* for C syntax check */ +} sgx_thread_condattr_t; + +#ifdef __cplusplus +extern "C" { +#endif + +/* Mutex */ +int SGXAPI sgx_thread_mutex_init(sgx_thread_mutex_t *mutex, const sgx_thread_mutexattr_t *unused); +int SGXAPI sgx_thread_mutex_destroy(sgx_thread_mutex_t *mutex); + +int SGXAPI sgx_thread_mutex_lock(sgx_thread_mutex_t *mutex); +int SGXAPI sgx_thread_mutex_trylock(sgx_thread_mutex_t *mutex); +int SGXAPI sgx_thread_mutex_unlock(sgx_thread_mutex_t *mutex); + +/* Condition Variable */ +int SGXAPI sgx_thread_cond_init(sgx_thread_cond_t *cond, const sgx_thread_condattr_t *unused); +int SGXAPI sgx_thread_cond_destroy(sgx_thread_cond_t *cond); + +int SGXAPI sgx_thread_cond_wait(sgx_thread_cond_t *cond, sgx_thread_mutex_t *mutex); +int SGXAPI sgx_thread_cond_signal(sgx_thread_cond_t *cond); +int SGXAPI sgx_thread_cond_broadcast(sgx_thread_cond_t *cond); + +sgx_thread_t SGXAPI sgx_thread_self(void); +int sgx_thread_equal(sgx_thread_t a, sgx_thread_t b); + +#ifdef __cplusplus +} +#endif + +#endif /* _SGX_THREAD_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_tkey_exchange.edl b/sgx-jvm/linux-sgx/common/inc/sgx_tkey_exchange.edl new file mode 100644 index 0000000000..179418d0ce --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_tkey_exchange.edl @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +enclave { + from "sgx_tae_service.edl" import *; + trusted { + public sgx_status_t sgx_ra_get_ga(sgx_ra_context_t context, + [out] sgx_ec256_public_t *g_a); + + public sgx_status_t sgx_ra_proc_msg2_trusted(sgx_ra_context_t context, + [in]const sgx_ra_msg2_t *p_msg2, /*copy msg2 except quote into enclave */ + [in] const sgx_target_info_t *p_qe_target, + [out] sgx_report_t *p_report, + [out] sgx_quote_nonce_t *p_nonce); + + public sgx_status_t sgx_ra_get_msg3_trusted(sgx_ra_context_t context, + uint32_t quote_size, + [in]sgx_report_t* qe_report, + [user_check]sgx_ra_msg3_t *p_msg3, + uint32_t msg3_size); + }; +}; diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_tkey_exchange.h b/sgx-jvm/linux-sgx/common/inc/sgx_tkey_exchange.h new file mode 100644 index 0000000000..eb8e27f6e3 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_tkey_exchange.h @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SGX_TKEY_EXCHANGE_H_ +#define _SGX_TKEY_EXCHANGE_H_ + +#include "sgx.h" +#include "sgx_defs.h" +#include "sgx_key_exchange.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The sgx_ra_init function creates a context for the remote attestation and + * key exchange process. + * + * @param p_pub_key The EC public key of the service provider based on the NIST + * P-256 elliptic curve. + * @param b_pse If true, platform service information is needed in message + * 3. The caller should make sure a PSE session has been + * established using sgx_create_pse_session before attempting + * to establish a remote attestation and key exchange session + * involving platform service information. + * @param p_context The output context for the subsequent remote attestation + * and key exchange process, to be used in sgx_ra_get_msg1 and + * sgx_ra_proc_msg2. + * @return sgx_status_t SGX_SUCCESS Indicates success. + * SGX_ERROR_INVALID_PARAMETER Indicates an error that + * the input parameters are + * invalid. + * SGX_ERROR_OUT_OF_MEMORY There is not enough + * memory available to + * complete this operation. + * SGX_ERROR_AE_SESSION_INVALID Session is invalid or + * ended by server. + * SGX_ERROR_UNEXPECTED Indicates an unexpected + * error occurs. + */ +sgx_status_t SGXAPI sgx_ra_init( + const sgx_ec256_public_t *p_pub_key, + int b_pse, + sgx_ra_context_t *p_context); + +/* + * The sgx_ra_derive_secret_keys_t function should takes the Diffie-Hellman + * shared secret as input to allow the ISV enclave to generate their own derived + * shared keys (SMK, SK, MK and VK). + * + * @param p_shared_key The the Diffie-Hellman shared secret. + * @param kdf_id, Key Derivation Function ID + * @param p_smk_key The output SMK. + * @param p_sk_key The output SK. + * @param p_mk_key The output MK. + * @param p_vk_key The output VK. + * @return sgx_status_t SGX_SUCCESS Indicates success. + * SGX_ERROR_INVALID_PARAMETER Indicates an error that + * the input parameters are + * invalid. + * SGX_ERROR_KDF_MISMATCH Indicates key derivation + * function doesn't match. + * SGX_ERROR_OUT_OF_MEMORY There is not enough + * memory available to + * complete this operation. + * SGX_ERROR_UNEXPECTED Indicates an unexpected + * error occurs. + */ + +typedef sgx_status_t(*sgx_ra_derive_secret_keys_t)( + const sgx_ec256_dh_shared_t* p_shared_key, + uint16_t kdf_id, + sgx_ec_key_128bit_t* p_smk_key, + sgx_ec_key_128bit_t* p_sk_key, + sgx_ec_key_128bit_t* p_mk_key, + sgx_ec_key_128bit_t* p_vk_key); + +/* + * The sgx_ra_init_ex function creates a context for the remote attestation and + * key exchange process asociated with a key derive function. + * + * @param p_pub_key The EC public key of the service provider based on the NIST + * P-256 elliptic curve. + * @param b_pse If true, platform service information is needed in message + * 3. The caller should make sure a PSE session has been + * established using sgx_create_pse_session before attempting + * to establish a remote attestation and key exchange session + * involving platform service information. + * @param derive_key_cb A pointer to a call back routine matching the + * function prototype of sgx_ra_derive_secret_keys_t. This + * function takes the Diffie-Hellman shared secret as input + * to allow the ISV enclave to generate their own derived + * shared keys (SMK, SK, MK and VK). + * @param p_context The output context for the subsequent remote attestation + * and key exchange process, to be used in sgx_ra_get_msg1 and + * sgx_ra_get_msg2. + * @return sgx_status_t SGX_SUCCESS Indicates success. + * SGX_ERROR_INVALID_PARAMETER Indicates an error that + * the input parameters are + * invalid. + * SGX_ERROR_OUT_OF_MEMORY There is not enough + * memory available to + * complete this operation. + * SGX_ERROR_AE_SESSION_INVALID Session is invalid or + * ended by server. + * SGX_ERROR_UNEXPECTED Indicates an unexpected + * error occurs. + */ + +sgx_status_t SGXAPI sgx_ra_init_ex( + const sgx_ec256_public_t *p_pub_key, + int b_pse, + sgx_ra_derive_secret_keys_t derive_key_cb, + sgx_ra_context_t *p_context); +/* + * The sgx_ra_get_keys function is used to get the negotiated keys of a remote + * attestation and key exchange session. This function should only be called + * after the service provider accepts the remote attestation and key exchange + * protocol message 3 produced by sgx_ra_proc_msg2. + * + * @param context Context returned by sgx_ra_init. + * @param type The specifier of keys, can be SGX_RA_KEY_MK, SGX_RA_KEY_SK + * and SGX_RA_VK. + * @param p_key The key returned. + * @return sgx_status_t SGX_SUCCESS Indicates success. + * SGX_ERROR_INVALID_PARAMETER Indicates an error that + * the input parameters are + * invalid. + * SGX_ERROR_INVALID_STATE Indicates this function + * is called out of order. + */ +sgx_status_t SGXAPI sgx_ra_get_keys( + sgx_ra_context_t context, + sgx_ra_key_type_t type, + sgx_ra_key_128_t *p_key); + +/* + * Call the sgx_ra_close function to release the remote attestation and key + * exchange context after the process is done and the context isn't needed + * anymore. + * + * @param context Context returned by sgx_ra_init. + * @return sgx_status_t SGX_SUCCESS Indicates success. + * SGX_ERROR_INVALID_PARAMETER Indicates an error that + * the input parameters are + * invalid. + */ +sgx_status_t SGXAPI sgx_ra_close( + sgx_ra_context_t context); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_trts.h b/sgx-jvm/linux-sgx/common/inc/sgx_trts.h new file mode 100644 index 0000000000..1a669f78d2 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_trts.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SGX_TRTS_H_ +#define _SGX_TRTS_H_ + +#include "sgx_error.h" +#include "stddef.h" +#include "sgx_defs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* sgx_is_within_enclave() + * Parameters: + * addr - the start address of the buffer + * size - the size of the buffer + * Return Value: + * 1 - the buffer is strictly within the enclave + * 0 - the whole buffer or part of the buffer is not within the enclave, + * or the buffer is wrap around +*/ +int SGXAPI sgx_is_within_enclave(const void *addr, size_t size); + +/* sgx_is_outside_enclave() + * Parameters: + * addr - the start address of the buffer + * size - the size of the buffer + * Return Value: + * 1 - the buffer is strictly outside the enclave + * 0 - the whole buffer or part of the buffer is not outside the enclave, + * or the buffer is wrap around +*/ +int SGXAPI sgx_is_outside_enclave(const void *addr, size_t size); + + +/* sgx_read_rand() + * Parameters: + * rand - the buffer to receive the random number + * length_in_bytes - the number of bytes to read the random number + * Return Value: + * SGX_SUCCESS - success + * SGX_ERROR_INVALID_PARAMETER - the parameter is invalid + * SGX_ERROR_UNEXPECTED - HW failure of RDRAND instruction +*/ +sgx_status_t SGXAPI sgx_read_rand(unsigned char *rand, size_t length_in_bytes); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_trts_exception.h b/sgx-jvm/linux-sgx/common/inc/sgx_trts_exception.h new file mode 100644 index 0000000000..41280aff4d --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_trts_exception.h @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +/** + * File: sgx_trts_exception.h + * Description: + * Header file for custom exception handling support. + */ + +#ifndef _SGX_TRTS_EXCEPTION_H_ +#define _SGX_TRTS_EXCEPTION_H_ + +#include +#include +#include "sgx_defs.h" + +#define EXCEPTION_CONTINUE_SEARCH 0 +#define EXCEPTION_CONTINUE_EXECUTION -1 + +typedef enum _sgx_exception_vector_t +{ + SGX_EXCEPTION_VECTOR_DE = 0, /* DIV and DIV instructions */ + SGX_EXCEPTION_VECTOR_DB = 1, /* For Intel use only */ + SGX_EXCEPTION_VECTOR_BP = 3, /* INT 3 instruction */ + SGX_EXCEPTION_VECTOR_BR = 5, /* BOUND instruction */ + SGX_EXCEPTION_VECTOR_UD = 6, /* UD2 instruction or reserved opcode */ + SGX_EXCEPTION_VECTOR_MF = 16, /* x87 FPU floating-point or WAIT/FWAIT instruction */ + SGX_EXCEPTION_VECTOR_AC = 17, /* Any data reference in memory */ + SGX_EXCEPTION_VECTOR_XM = 19, /* SSE/SSE2/SSE3 floating-point instruction */ +} sgx_exception_vector_t; + +typedef enum _sgx_exception_type_t +{ + SGX_EXCEPTION_HARDWARE = 3, + SGX_EXCEPTION_SOFTWARE = 6, +} sgx_exception_type_t; + +#if defined (_M_X64) || defined (__x86_64__) +typedef struct _cpu_context_t +{ + uint64_t rax; + uint64_t rcx; + uint64_t rdx; + uint64_t rbx; + uint64_t rsp; + uint64_t rbp; + uint64_t rsi; + uint64_t rdi; + uint64_t r8; + uint64_t r9; + uint64_t r10; + uint64_t r11; + uint64_t r12; + uint64_t r13; + uint64_t r14; + uint64_t r15; + uint64_t rflags; + uint64_t rip; +} sgx_cpu_context_t; +#else +typedef struct _cpu_context_t +{ + uint32_t eax; + uint32_t ecx; + uint32_t edx; + uint32_t ebx; + uint32_t esp; + uint32_t ebp; + uint32_t esi; + uint32_t edi; + uint32_t eflags; + uint32_t eip; +} sgx_cpu_context_t; +#endif + +typedef struct _exception_info_t +{ + sgx_cpu_context_t cpu_context; + sgx_exception_vector_t exception_vector; + sgx_exception_type_t exception_type; +} sgx_exception_info_t; + +typedef int (*sgx_exception_handler_t)(sgx_exception_info_t *info); + +#ifdef __cplusplus +extern "C" { +#endif + +/* sgx_register_exception_handler() + * register a custom exception handler + * Parameter + * is_first_handler - the order in which the handler should be called. + * If the parameter is nonzero, the handler is the first handler to be called. + * If the parameter is zero, the handler is the last handler to be called. + * exception_handler - a pointer to the handler to be called. + * Return Value + * handler - success + * NULL - fail +*/ +void * SGXAPI sgx_register_exception_handler(int is_first_handler, sgx_exception_handler_t exception_handler); + +/* sgx_unregister_exception_handler() + * unregister a custom exception handler. + * Parameter + * handler - a handler to the custom excepetion handler previously + * registered using the sgx_register_exception_handler function. + * Return Value + * none zero - success + * 0 - fail +*/ +int SGXAPI sgx_unregister_exception_handler(void *handler); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_tseal.h b/sgx-jvm/linux-sgx/common/inc/sgx_tseal.h new file mode 100644 index 0000000000..fa93227800 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_tseal.h @@ -0,0 +1,257 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#ifndef _SGX_TSEAL_H_ +#define _SGX_TSEAL_H_ + +#include +#include +#include "sgx_key.h" +#include "sgx_error.h" +#include "sgx_defs.h" +#include "sgx_attributes.h" +#include "sgx_tcrypto.h" + +#define SGX_SEAL_TAG_SIZE SGX_AESGCM_MAC_SIZE +#define SGX_SEAL_IV_SIZE 12 + +typedef struct _aes_gcm_data_t +{ + uint32_t payload_size; /* 0: Size of the payload which includes both the encrypted data and the optional additional MAC text */ + uint8_t reserved[12]; /* 4: Reserved bits */ + uint8_t payload_tag[SGX_SEAL_TAG_SIZE]; /* 16: AES-GMAC of the plain text, payload, and the sizes */ + uint8_t payload[]; /* 32: The payload data which includes the encrypted data followed by the optional additional MAC text */ +} sgx_aes_gcm_data_t; + +typedef struct _sealed_data_t +{ + sgx_key_request_t key_request; /* 00: The key request used to obtain the sealing key */ + uint32_t plain_text_offset; /* 64: Offset within aes_data.playload to the start of the optional additional MAC text */ + uint8_t reserved[12]; /* 68: Reserved bits */ + sgx_aes_gcm_data_t aes_data; /* 80: Data structure holding the AES/GCM related data */ +} sgx_sealed_data_t; + +#ifdef __cplusplus +extern "C" { +#endif + /* sgx_calc_sealed_data_size + * Purpose: This function is used to determine how much memory to allocate for sgx_sealed_data_t structure. + * + * Paramters: + * add_mac_txt_size - [IN] Length of the optional additional data stream in bytes + * txt_encrypt_size - [IN] Length of the data stream to be encrypted in bytes + * + * Return Value: + * uint32_t - The minimum number of bytes that need to be allocated for the sgx_sealed_data_t structure + * If the function fails, the return value is UINT32_MAX + */ + uint32_t sgx_calc_sealed_data_size(const uint32_t add_mac_txt_size, const uint32_t txt_encrypt_size); + + /* sgx_get_add_mac_txt_len + * Purpose: This function is used to determine how much memory to allocate for the additional_MAC_text buffer + * + * Parameter: + * p_sealed_data - [IN] Pointer to the sgx_sealed_data_t structure which was populated by the sgx_seal_data function + * + * Return Value: + * uint32_t - The number of bytes in the optional additional MAC buffer + */ + uint32_t sgx_get_add_mac_txt_len(const sgx_sealed_data_t* p_sealed_data); + + /* sgx_get_encrypt_txt_len + * + * Parameter: + * p_sealed_data - [IN] Pointer to the sgx_sealed_data_t structure which was populated by the sgx_seal_data function + * + * Return Value: + * uint32_t - The number of bytes in the encrypted data buffer + * If the function fails, the return value is UINT32_MAX + */ + uint32_t sgx_get_encrypt_txt_len(const sgx_sealed_data_t* p_sealed_data); + + + /* sgx_seal_data + * Purpose: This algorithm is used to AES-GCM encrypt the input data. Specifically, + * two input data sets can be provided, one is the text to encrypt (p_text2encrypt) + * the second being optional additional text that should not be encrypted but will + * be part of the GCM MAC calculation. + * The sgx_sealed_data_t structure should be allocated prior to the API call and + * should include buffer storage for the MAC text and encrypted text. + * The sgx_sealed_data_t structure contains the data required to unseal the data on + * the same system it was sealed. + * + * Parameters: + * additional_MACtext_length - [IN] length of the plaintext data stream in bytes + * The additional data is optional and thus the length + * can be zero if no data is provided + * p_additional_MACtext - [IN] pointer to the plaintext data stream to be GCM protected + * The additional data is optional. You may pass a NULL pointer + * but additional_MACtext_length must be zero in that case + * text2encrypt_length - [IN] length of the data stream to encrypt in bytes + * p_text2encrypt - [IN] pointer to data stream to encrypt + * sealed_data_size - [IN] Size of the sealed data buffer passed in + * p_sealed_data - [OUT] pointer to the sealed data structure containing protected data + * + * Return Value: + * sgx_status_t - SGX Error code + */ + sgx_status_t SGXAPI sgx_seal_data(const uint32_t additional_MACtext_length, + const uint8_t *p_additional_MACtext, + const uint32_t text2encrypt_length, + const uint8_t *p_text2encrypt, + const uint32_t sealed_data_size, + sgx_sealed_data_t *p_sealed_data); + + /* sgx_seal_data_ex + * Purpose: Expert version of sgx_seal_data which is used if the key_policy/attribute_mask/misc_mask + * need to be modified from the default values. + * + * Parameters: + * key_policy - [IN] Specifies the measurement to use in key derivation + * attribute_mask - [IN] Identifies which platform/enclave attributes to use in key derivation + * misc_mask - [IN] The mask for MISC_SELECT + * additional_MACtext_length - [IN] length of the plaintext data stream in bytes + * The additional data is optional and thus the length + * can be zero if no data is provided + * p_additional_MACtext - [IN] pointer to the plaintext data stream to be GCM protected + * The additional data is optional. You may pass a NULL pointer + * but additional_MACtext_length must be zero in that case + * text2encrypt_length - [IN] length of the data stream to encrypt in bytes + * p_text2encrypt - [IN] pointer to data stream to encrypt + * sealed_data_size - [IN] Size of the sealed data buffer passed in + * p_sealed_data - [OUT] pointer to the sealed data structure containing protected data + * + * Return Value: + * sgx_status_t - SGX Error code + */ + sgx_status_t SGXAPI sgx_seal_data_ex(const uint16_t key_policy, + const sgx_attributes_t attribute_mask, + const sgx_misc_select_t misc_mask, + const uint32_t additional_MACtext_length, + const uint8_t *p_additional_MACtext, + const uint32_t text2encrypt_length, + const uint8_t *p_text2encrypt, + const uint32_t sealed_data_size, + sgx_sealed_data_t *p_sealed_data); + + /* sgx_unseal_data + * Purpose: Unseal the sealed data structure passed in and populate the MAC text and decrypted text + * buffers with the appropriate data from the sealed data structure. + * + * Parameters: + * p_sealed_data - [IN] pointer to the sealed data structure containing protected data + * p_additional_MACtext - [OUT] pointer to the plaintext data stream which was GCM protected + * The additiona data is optional. You may pass a NULL pointer but + * p_additional_MACtext_length must be zero in that case + * p_additional_MACtext_length - [IN/OUT] pointer to length of the plaintext data stream in bytes + * If there is not additional data, this parameter should be zero. + * p_decrypted_text - [OUT] pointer to decrypted data stream + * p_decrypted_text_length - [IN/OUT] pointer to length of the decrypted data stream to encrypt in bytes + * + * Return Value: + * sgx_status_t - SGX Error code + */ + sgx_status_t SGXAPI sgx_unseal_data(const sgx_sealed_data_t *p_sealed_data, + uint8_t *p_additional_MACtext, + uint32_t *p_additional_MACtext_length, + uint8_t *p_decrypted_text, + uint32_t *p_decrypted_text_length); + + /* sgx_mac_aadata + * Purpose: Use AES-GCM algorithm to generate a sealed data structure with integrity protection. + * Specifically, the input data set is ONLY the plaintext data stream, or + * additional authenticated data(AAD), no encrypt data. + * The sgx_sealed_data_t structure should be allocated prior to the API call and + * should include buffer storage for the plaintext data. + * The sgx_sealed_data_t structure contains the data required to unseal the data on + * the same system it was sealed. + * + * Parameters: + * additional_MACtext_length - [IN] length of the plaintext data stream in bytes + * p_additional_MACtext - [IN] pointer to the plaintext data stream to be GCM protected + * sealed_data_size - [IN] Size of the sealed data buffer passed in + * p_sealed_data - [OUT] pointer to the sealed data structure containing protected data + * + * Return Value: + * sgx_status_t - SGX Error code + */ + sgx_status_t sgx_mac_aadata(const uint32_t additional_MACtext_length, + const uint8_t *p_additional_MACtext, + const uint32_t sealed_data_size, + sgx_sealed_data_t *p_sealed_data); + + /* sgx_mac_aadata_ex + * Purpose: Expert version of sgx_mac_aadata which is used if the key_policy/attribute_mask/misc_mask + * need to be modified from the default values. + * + * Parameters: + * key_policy - [IN] Specifies the measurement to use in key derivation + * attribute_mask - [IN] Identifies which platform/enclave attributes to use in key derivation + * misc_mask - [IN] The mask for MISC_SELECT + * additional_MACtext_length - [IN] length of the plaintext data stream in bytes + * p_additional_MACtext - [IN] pointer to the plaintext data stream to be GCM protected + * sealed_data_size - [IN] Size of the sealed data buffer passed in + * p_sealed_data - [OUT] pointer to the sealed data structure containing protected data + * + * Return Value: + * sgx_status_t - SGX Error code + */ + sgx_status_t sgx_mac_aadata_ex(const uint16_t key_policy, + const sgx_attributes_t attribute_mask, + const sgx_misc_select_t misc_mask, + const uint32_t additional_MACtext_length, + const uint8_t *p_additional_MACtext, + const uint32_t sealed_data_size, + sgx_sealed_data_t *p_sealed_data); + + /* sgx_unmac_aadata + * Purpose: Unseal the sealed data structure passed in and populate the plaintext data stream + * with the appropriate data from the sealed data structure. + * + * Parameters: + * p_sealed_data - [IN] pointer to the sealed data structure containing protected data + * p_additional_MACtext - [OUT] pointer to the plaintext data stream which was GCM protected + * p_additional_MACtext_length - [IN/OUT] pointer to length of the plaintext data stream in bytes + * + * Return Value: + * sgx_status_t - SGX Error code + */ + sgx_status_t sgx_unmac_aadata(const sgx_sealed_data_t *p_sealed_data, + uint8_t *p_additional_MACtext, + uint32_t *p_additional_MACtext_length); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_tstdc.edl b/sgx-jvm/linux-sgx/common/inc/sgx_tstdc.edl new file mode 100644 index 0000000000..e92e2218c3 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_tstdc.edl @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +enclave { + untrusted { + [cdecl] void sgx_oc_cpuidex([in, out] int cpuinfo[4], int leaf, int subleaf); + + /* Go outside and wait on my untrusted event */ + [cdecl] int sgx_thread_wait_untrusted_event_ocall([user_check] const void *self); + + /* Wake a thread waiting on its untrusted event */ + [cdecl] int sgx_thread_set_untrusted_event_ocall([user_check] const void *waiter); + + /* Wake a thread waiting on its untrusted event, and wait on my untrusted event */ + [cdecl] int sgx_thread_setwait_untrusted_events_ocall([user_check] const void *waiter, [user_check] const void *self); + + /* Wake multiple threads waiting on their untrusted events */ + [cdecl] int sgx_thread_set_multiple_untrusted_events_ocall([in, count = total] const void **waiters, size_t total); + }; +}; diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_uae_service.h b/sgx-jvm/linux-sgx/common/inc/sgx_uae_service.h new file mode 100644 index 0000000000..ff668b131b --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_uae_service.h @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SGX_UAE_SERVICE_H_ +#define _SGX_UAE_SERVICE_H_ + +#include + +#include "sgx_quote.h" +#include "sgx_error.h" +#include "sgx_urts.h" + +#define PS_CAP_TRUSTED_TIME 0x1 +#define PS_CAP_MONOTONIC_COUNTER 0x2 + +/** + * Platform service capabilities + * ps_cap0 + * Bit 0 : Trusted Time + * Bit 1 : Monotonic Counter + * Bit 2-31 : Reserved + * ps_cap1 + * Bit 0-31 : Reserved + */ +typedef struct _sgx_ps_cap_t +{ + uint32_t ps_cap0; + uint32_t ps_cap1; +} sgx_ps_cap_t; + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Function used to initialize the process of quoting. + * + * @param p_target_info[out] Target info of quoting enclave. + * @param p_gid[out] ID of platform's current EPID group. + * @return If outputs are generated, return SGX_SCCUESS, otherwise return general error code + * or SGX_ERROR_AE_INVALID_EPIDBLOB to indicate special error condition. + */ +sgx_status_t SGXAPI sgx_init_quote( + sgx_target_info_t *p_target_info, + sgx_epid_group_id_t *p_gid); + + +/* + * Function used to get quote size. + * + * @param p_sig_rl[in] OPTIONAL Signature Revocation List. + * @param p_quote_size[out] Quote size, in bytes. + * @return If quote size is calculated,return SGX_SCCUESS, otherwise return + * SGX_ERROR_INVALID_PARAMETER to indicate special error condition. + */ +sgx_status_t SGXAPI sgx_get_quote_size( + const uint8_t *p_sig_rl, + uint32_t* p_quote_size); + +/* + * Function used to get quote. + * + * @param p_report[in] Report of enclave for which quote is being calculated. + * @param quote_type[in] Linkable or unlinkable quote. + * @param p_spid[in] Pointer of SPID. + * @param p_nonce[in] OPTIONAL nonce. + * @param p_sig_rl[in] OPTIONAL list of signature made fore EPID. + * @param sig_rl_size[in] The size of p_sig_rl, in bytes. + * @param p_qe_report[out] OPTIONAL The QE report. + * @param p_quote[out] The quote buffer, can not be NULL. + * @param quote_size[in] Quote buffer size, in bytes. + * @return If quote is generated,return SGX_SCCUESS, + * error code or SGX_ERROR_AE_INVALID_EPIDBLOB, + * SGX_ERROR_INVALID_PARAMETER to indicate special error condition. + * SGX_ERROR_EPID_MEMBER_REVOKED to indicate the EPID group membership has been revoked. + */ +sgx_status_t SGXAPI sgx_get_quote( + const sgx_report_t *p_report, + sgx_quote_sign_type_t quote_type, + const sgx_spid_t *p_spid, + const sgx_quote_nonce_t *p_nonce, + const uint8_t *p_sig_rl, + uint32_t sig_rl_size, + sgx_report_t *p_qe_report, + sgx_quote_t *p_quote, + uint32_t quote_size); + +/** + * Get the platform service capabilities + * + * @param sgx_ps_cap Platform capabilities reported by AESM. + * @return if OK, return SGX_SUCCESS + */ +sgx_status_t SGXAPI sgx_get_ps_cap(sgx_ps_cap_t* p_sgx_ps_cap); + +/** + * Get the white list's size + * + * @param p_whitelist_size Save the size of the white list. + * @return if OK, return SGX_SUCCESS + */ +sgx_status_t SGXAPI sgx_get_whitelist_size(uint32_t* p_whitelist_size); + +/** + * Get the white list value + * + * @param p_whitelist Save the white list value + * @param whitelist_size The size of the white list and the read data size is whitelist_size + * @return if OK, return SGX_SUCCESS + */ +sgx_status_t SGXAPI sgx_get_whitelist(uint8_t* p_whitelist, uint32_t whitelist_size); + +/** + * Get the extended epid group id + * + * @param p_extended_epid_group_id Save the extended epid group id. + * @return if OK, return SGX_SUCCESS + */ +sgx_status_t SGXAPI sgx_get_extended_epid_group_id(uint32_t* p_extended_epid_group_id); + +#define SGX_IS_TRUSTED_TIME_AVAILABLE(cap) ((((uint32_t)PS_CAP_TRUSTED_TIME)&((cap).ps_cap0))!=0) +#define SGX_IS_MONOTONIC_COUNTER_AVAILABLE(cap) ((((uint32_t)PS_CAP_MONOTONIC_COUNTER)&((cap).ps_cap0))!=0) + +/* + * Function used to report the status of the attestation. + * + * @param p_platform_info[in] platform information received from Intel Attestation Server. + * @param attestation_status[in] Value representing status during attestation. 0 if attestation succeeds. + * @param p_update_info[out] update information of the SGX platform. + * @return If OK, return SGX_SUCCESS. If update is needed, return SGX_ERROR_UPDATE_NEEDED and update_info contains update information. + */ + +sgx_status_t SGXAPI sgx_report_attestation_status( + const sgx_platform_info_t* p_platform_info, + int attestation_status, + sgx_update_info_bit_t* p_update_info); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_ukey_exchange.h b/sgx-jvm/linux-sgx/common/inc/sgx_ukey_exchange.h new file mode 100644 index 0000000000..0f1e79f506 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_ukey_exchange.h @@ -0,0 +1,199 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _SGX_UKEY_EXCHANGE_H_ +#define _SGX_UKEY_EXCHANGE_H_ + +#include "sgx_eid.h" +#include "sgx_defs.h" +#include "sgx_key_exchange.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef sgx_status_t (* sgx_ecall_get_ga_trusted_t)( + sgx_enclave_id_t eid, + sgx_status_t* retval, + sgx_ra_context_t context, + sgx_ec256_public_t *g_a); + +typedef sgx_status_t (* sgx_ecall_proc_msg2_trusted_t)( + sgx_enclave_id_t eid, + sgx_status_t* retval, + sgx_ra_context_t context, + const sgx_ra_msg2_t *p_msg2, + const sgx_target_info_t *p_qe_target, + sgx_report_t *p_report, + sgx_quote_nonce_t* nonce); + +typedef sgx_status_t (* sgx_ecall_get_msg3_trusted_t)( + sgx_enclave_id_t eid, + sgx_status_t* retval, + sgx_ra_context_t context, + uint32_t quote_size, + sgx_report_t* qe_report, + sgx_ra_msg3_t *p_msg3, + uint32_t msg3_size); + +/* + * sgx_ra_get_msg1 is used to get the remote attestation and key exchange + * protocol message 1 to send to a service provider. The application enclave + * should use sgx_ra_init function to create the remote attestation and key + * exchange process context and return to the untrusted code, before the + * untrusted code can invoke this function. + * + * @param context Context returned by the sgx_ra_init function inside the + * application enclave. + * @param eid ID of the application enclave which is going to be + * attested. + * @param p_get_ga Function pointer of the ECALL proxy sgx_ra_get_ga + * generated by sgx_edger8r. The application enclave should + * link with sgx_tkey_exchange library and import + * sgx_tkey_exchange.edl in the enclave's EDL file to + * expose the ECALL proxy for sgx_ra_get_ga. + * @param p_msg1 Message 1 used by the remote attestation and key + * exchange protocol. + * @return sgx_status_t SGX_SUCCESS Indicates success. + * SGX_ERROR_INVALID_PARAMETER Invalid input parameters + * detected. + * SGX_ERROR_AE_INVALID_EPIDBLOB The EPID blob is + * corrupted. + * SGX_ERROR_INVALID_STATE SGX API is invoked in + * incorrect order or + * state. + * SGX_ERROR_EPID_MEMBER_REVOKED The EPID group + * membership revoked. + * SGX_ERROR_BUSY The requested service is + * temporarily not + * available. + * SGX_ERROR_UPDATE_NEEDED SGX needs to be updated. + * SGX_ERROR_SERVICE_UNAVAILABLE The AE service did not + * respond. + * SGX_ERROR_SERVICE_TIMEOUT A request to the AE + * service timed out. + * SGX_ERROR_NETWORK_FAILURE Network connecting or + * proxy setting issue was + * encountered. + * SGX_ERROR_OUT_OF_MEMORY There is not enough + * memory available to + * complete this operation. + * SGX_ERROR_UNEXPECTED Indicates an unexpected + * error occurs. + * And other possible return code from sgx_ecall. + */ +sgx_status_t SGXAPI sgx_ra_get_msg1( + sgx_ra_context_t context, + sgx_enclave_id_t eid, + sgx_ecall_get_ga_trusted_t p_get_ga, + sgx_ra_msg1_t *p_msg1); + +/* + * sgx_ra_get_msg2 is used to process the remote attestation and key exchange + * protocol message 2 from the service provider and generate message 3 to send + * to the service provider. If the service provider accepts message 3, + * negotiated session keys between the application enclave and the service + * provider are ready for use. The application enclave can use sgx_ra_get_keys + * function to retrieve the negotiated keys and use sgx_ra_close function to + * release the context of the remote attestation and key exchange process. + * + * @param context Context returned by the sgx_ra_init function inside the + * application enclave. + * @param eid ID of the application enclave which is going to be + * attested. + * @param p_proc_msg2 Function pointer of the ECALL proxy sgx_ra_proc_msg2_trusted + * generated by sgx_edger8r. The application enclave should + * link with sgx_tkey_exchange library and import the + * sgx_tkey_exchange.edl in the application enclave's EDL + * file to expose the ECALL proxy for sgx_ra_get_msg2. + * @param p_get_msg3 Function pointer of the ECALL proxy sgx_ra_get_msg3_trusted + * generated by sgx_edger8r. The application enclave should + * link with sgx_tkey_exchange library and import the + * sgx_tkey_exchange.edl in the application enclave's EDL + * file to expose the ECALL proxy for sgx_ra_get_msg3. + * @param p_msg2 sgx_ra_msg2_t message 2 from the service provider + * received by application. + * @param msg2_size The length of msg2 (in bytes). + * @param pp_msg3 sgx_ra_msg3_t message 3 to be sent to the service + * provider. The message buffer is allocated by the + * sgx_ukey_exchange library. The caller should free the + * buffer after use. + * @param p_msg3_size The length of msg3 (in bytes). + * @return sgx_status_t SGX_SUCCESS Indicates success. + * SGX_ERROR_INVALID_PARAMETER Invalid input parameters + * detected. + * SGX_ERROR_AE_INVALID_EPIDBLOB The EPID blob is + * corrupted. + * SGX_ERROR_INVALID_STATE SGX API is invoked in + * incorrect order or + * state. + * SGX_ERROR_EPID_MEMBER_REVOKED The EPID group + * membership revoked. + * SGX_ERROR_INVALID_SIGNATURE The signature is invalid. + * SGX_ERROR_MAC_MISMATCH Indicates verification + * error for reports, sealed + * data, etc. + * SGX_ERROR_KDF_MISMATCH Indicates key derivation + * function doesn't match. + * SGX_ERROR_BUSY The requested service is + * temporarily not + * available. + * SGX_ERROR_UPDATE_NEEDED SGX needs to be updated. + * SGX_ERROR_SERVICE_UNAVAILABLE The AE service did not + * respond. + * SGX_ERROR_SERVICE_TIMEOUT A request to the AE + * service timed out. + * SGX_ERROR_NETWORK_FAILURE Network connecting or + * proxy setting issue was + * encountered. + * SGX_ERROR_OUT_OF_MEMORY There is not enough + * memory available to + * complete this operation. + * SGX_ERROR_UNEXPECTED Indicates an unexpected + * error occurs. + * And other possible return code from sgx_ecall. + */ +sgx_status_t SGXAPI sgx_ra_proc_msg2( + sgx_ra_context_t context, + sgx_enclave_id_t eid, + sgx_ecall_proc_msg2_trusted_t p_proc_msg2, + sgx_ecall_get_msg3_trusted_t p_get_msg3, + const sgx_ra_msg2_t *p_msg2, + uint32_t msg2_size, + sgx_ra_msg3_t **pp_msg3, + uint32_t *p_msg3_size); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_urts.h b/sgx-jvm/linux-sgx/common/inc/sgx_urts.h new file mode 100644 index 0000000000..c1bfa65183 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_urts.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#ifndef _SGX_URTS_H_ +#define _SGX_URTS_H_ + +#include "sgx_attributes.h" +#include "sgx_error.h" +#include "sgx_eid.h" +#include "sgx_defs.h" +#include "sgx_key.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef uint8_t sgx_launch_token_t[1024]; + +/* Convenient macro to be passed to sgx_create_enclave(). */ +#if !defined(NDEBUG) || defined(EDEBUG) +#define SGX_DEBUG_FLAG ((int)1) +#else +#define SGX_DEBUG_FLAG ((int)0) +#endif + +sgx_status_t SGXAPI sgx_create_enclave(const char *file_name, const int debug, sgx_launch_token_t *launch_token, int *launch_token_updated, sgx_enclave_id_t *enclave_id, sgx_misc_attribute_t *misc_attr); + +sgx_status_t SGXAPI sgx_destroy_enclave(const sgx_enclave_id_t enclave_id); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/sgx_utils.h b/sgx-jvm/linux-sgx/common/inc/sgx_utils.h new file mode 100644 index 0000000000..0d8420b753 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/sgx_utils.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +/** + * File: sgx_utils.h + * Description: + * Trusted library for SGX instructions + */ + +#ifndef _SGX_UTILS_H_ +#define _SGX_UTILS_H_ + +#include "sgx.h" +#include "sgx_defs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*sgx_create_report + * Purpose: Create a cryptographic report of the enclave using the input information if any. + * + * Parameters: + * target_info - [IN] pointer to the information of the target enclave. + * report_data - [IN] pointer to a set of data used for communication between the enclaves. + * report - [OUT] pointer to the cryptographic report of the enclave + * + * Return value: + * sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h. +*/ +sgx_status_t SGXAPI sgx_create_report(const sgx_target_info_t *target_info, const sgx_report_data_t *report_data, sgx_report_t *report); + +/* sgx_verify_report + * Purpose: Software verification for the input report + * + * Paramters: + * report - [IN] ponter to the cryptographic report to be verified. + * + * Return value: + * sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h. +*/ +sgx_status_t SGXAPI sgx_verify_report(const sgx_report_t *report); + +/*sgx_get_key + * Purpose: Generate a 128-bit secret key with the input information. + * + * Parameters: + * key_request - [IN] pointer to the sgx_key_request_t object used for selecting the appropriate key. + * key - [OUT] Pointer to the buffer that receives the cryptographic key output. + * + * Return value: + * sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h. +*/ +sgx_status_t SGXAPI sgx_get_key(const sgx_key_request_t *key_request, sgx_key_128bit_t *key); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx-jvm/linux-sgx/common/inc/stdc++/exception b/sgx-jvm/linux-sgx/common/inc/stdc++/exception new file mode 100644 index 0000000000..0389bfd199 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/stdc++/exception @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _EXCEPTION_ +#define _EXCEPTION_ + +#include +#include SGX_CXX_NATIVE_HEADER(exception) + +#endif /* _EXCEPTION_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/stdc++/linux/exception b/sgx-jvm/linux-sgx/common/inc/stdc++/linux/exception new file mode 100644 index 0000000000..afcb0feac1 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/stdc++/linux/exception @@ -0,0 +1,77 @@ +/* + * Copyright 2010-2011 PathScale, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS + * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LINUX_EXCEPTION_ +#define _LINUX_EXCEPTION_ + + +namespace std +{ + class exception + { + public: + exception() throw(); + exception(const exception&) throw(); + exception& operator=(const exception&) throw(); + virtual ~exception(); + virtual const char* what() const throw(); + }; + + /** + * Bad allocation exception. Thrown by ::operator new() if it fails. + */ + class bad_alloc: public exception + { + public: + bad_alloc() throw(); + bad_alloc(const bad_alloc&) throw(); + bad_alloc& operator=(const bad_alloc&) throw(); + ~bad_alloc(); + virtual const char* what() const throw(); + }; + + class bad_exception : public exception + { + public: + bad_exception() throw(); + virtual ~bad_exception() throw(); + virtual const char* what() const throw(); + }; + + bool uncaught_exception() throw(); + + typedef void (*unexpected_handler)(); + unexpected_handler set_unexpected(unexpected_handler) throw(); + void unexpected(); + + typedef void (*terminate_handler)(); + terminate_handler set_terminate(terminate_handler) throw(); + void terminate(); + +} // namespace std + + +#endif /* _LINUX_EXCEPTION_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/stdc++/linux/typeinfo b/sgx-jvm/linux-sgx/common/inc/stdc++/linux/typeinfo new file mode 100644 index 0000000000..a32df180f6 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/stdc++/linux/typeinfo @@ -0,0 +1,138 @@ +/* + * Copyright 2010-2011 PathScale, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS + * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LINUX_TYPEINFO_ +#define _LINUX_TYPEINFO_ + +#include +#include "exception" + +namespace __cxxabiv1 +{ + struct __class_type_info; +} +namespace std +{ + /** + * Standard type info class. The layout of this class is specified by the + * ABI. The layout of the vtable is not, but is intended to be + * compatible with the GNU ABI. + * + * Unlike the GNU version, the vtable layout is considered semi-private. + */ + class type_info + { + public: + /** + * Virtual destructor. This class must have one virtual function to + * ensure that it has a vtable. + */ + virtual ~type_info(); + bool operator==(const type_info &) const; + bool operator!=(const type_info &) const; + bool before(const type_info &) const; + const char* name() const; + type_info(); + private: + type_info(const type_info& rhs); + type_info& operator= (const type_info& rhs); + const char *__type_name; + /* + * The following functions are in this order to match the + * vtable layout of libsupc++. This allows libcxxrt to be used + * with libraries that depend on this. + * + * These functions are in the public headers for libstdc++, so + * we have to assume that someone will probably call them and + * expect them to work. Their names must also match the names used in + * libsupc++, so that code linking against this library can subclass + * type_info and correctly fill in the values in the vtables. + */ + public: + /** + * Returns true if this is some pointer type, false otherwise. + */ + virtual bool __is_pointer_p() const { return false; } + /** + * Returns true if this is some function type, false otherwise. + */ + virtual bool __is_function_p() const { return false; } + /** + * Catch function. Allows external libraries to implement + * their own basic types. This is used, for example, in the + * GNUstep Objective-C runtime to allow Objective-C types to be + * caught in G++ catch blocks. + * + * The outer parameter indicates the number of outer pointers + * in the high bits. The low bit indicates whether the + * pointers are const qualified. + */ + virtual bool __do_catch(const type_info *thrown_type, + void **thrown_object, + unsigned outer) const; + /** + * Performs an upcast. This is used in exception handling to + * cast from subclasses to superclasses. If the upcast is + * possible, it returns true and adjusts the pointer. If the + * upcast is not possible, it returns false and does not adjust + * the pointer. + */ + virtual bool __do_upcast( + const __cxxabiv1::__class_type_info *target, + void **thrown_object) const + { + (void)target, (void)thrown_object; + return false; + } + }; + + /** + * Bad cast exception. Thrown by the __cxa_bad_cast() helper function. + */ + class bad_cast: public exception { + public: + bad_cast() throw(); + bad_cast(const bad_cast&) throw(); + bad_cast& operator=(const bad_cast&) throw(); + virtual ~bad_cast(); + virtual const char* what() const throw(); + }; + + /** + * Bad typeidexception. Thrown by the __cxa_bad_typeid() helper function. + */ + class bad_typeid: public exception + { + public: + bad_typeid() throw(); + bad_typeid(const bad_typeid &__rhs) throw(); + virtual ~bad_typeid(); + bad_typeid& operator=(const bad_typeid &__rhs) throw(); + virtual const char* what() const throw(); + }; +} + +#endif /* _LINUX_TYPEINFO_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/stdc++/new b/sgx-jvm/linux-sgx/common/inc/stdc++/new new file mode 100644 index 0000000000..fbf11fb67d --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/stdc++/new @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _NEW_ +#define _NEW_ + +#include +#include +#include + + +namespace std +{ + typedef void (*new_handler)(); // The type of the function called when allocation fails. + + struct nothrow_t {}; // placement new tag type to suppress exceptions + const nothrow_t nothrow = {}; // constant for placement new tag + + /* + * The function to call when allocation fails. By default, there is no + * handler and a bad allocation exception is thrown if an allocation fails. + */ + new_handler set_new_handler(new_handler handler) throw(); +}; + +void* SGXAPI operator new (size_t) throw (std::bad_alloc); +void* SGXAPI operator new[] (size_t) throw (std::bad_alloc); + +void* SGXAPI operator new (size_t, const std::nothrow_t&) throw(); +void* SGXAPI operator new (size_t, void*) throw(); +void* SGXAPI operator new[] (size_t, const std::nothrow_t&) throw(); +void* SGXAPI operator new[] (size_t, void*) throw(); + +void SGXAPI operator delete (void*) throw (); +void SGXAPI operator delete (void*, const std::nothrow_t&) throw(); +void SGXAPI operator delete (void*, void*) throw(); +void SGXAPI operator delete[] (void*) throw (); +void SGXAPI operator delete[] (void*, const std::nothrow_t&) throw(); +void SGXAPI operator delete[] (void*, void*) throw(); + +#endif /* _NEW_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/stdc++/typeinfo b/sgx-jvm/linux-sgx/common/inc/stdc++/typeinfo new file mode 100644 index 0000000000..fa9c05e737 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/stdc++/typeinfo @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _TYPEINFO_ +#define _TYPEINFO_ + +#include +#include SGX_CXX_NATIVE_HEADER(typeinfo) + +#endif /* _TYPEINFO_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/assert.h b/sgx-jvm/linux-sgx/common/inc/tlibc/assert.h new file mode 100644 index 0000000000..82489e80c0 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/assert.h @@ -0,0 +1,63 @@ +/* $OpenBSD: assert.h,v 1.12 2006/01/31 10:53:51 hshoexer Exp $ */ +/* $NetBSD: assert.h,v 1.6 1994/10/26 00:55:44 cgd Exp $ */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)assert.h 8.2 (Berkeley) 1/21/94 + */ + +/* + * Unlike other ANSI header files, may usefully be included + * multiple times, with and without NDEBUG defined. + */ + +#include + +#undef assert + +#ifdef NDEBUG +# define assert(e) ((void)0) +#else +# define assert(e) ((e) ? (void)0 : __assert(__FILE__, __LINE__, __func__, #e)) +#endif + +#ifndef _ASSERT_H_DECLS +#define _ASSERT_H_DECLS +__BEGIN_DECLS + +void _TLIBC_CDECL_ __assert(const char *, int, const char *, const char *); + +__END_DECLS +#endif /* Not _ASSERT_H_DECLS */ + diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/complex.h b/sgx-jvm/linux-sgx/common/inc/tlibc/complex.h new file mode 100644 index 0000000000..7d92d63e87 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/complex.h @@ -0,0 +1,134 @@ +/* $OpenBSD: complex.h,v 1.3 2010/07/24 22:17:03 guenther Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _COMPLEX_H_ +#define _COMPLEX_H_ + +#include + +/* + * C99 + */ +#ifdef __GNUC__ +#if __STDC_VERSION__ < 199901 +#define _Complex __complex__ +#endif +#define _Complex_I 1.0fi +#elif defined(lint) +#define _Complex_I 1.0fi +#endif + +#define complex _Complex + +/* XXX switch to _Imaginary_I */ +#undef I +#define I _Complex_I + +__BEGIN_DECLS +/* + * Double versions of C99 functions + */ +double complex cacos(double complex); +double complex casin(double complex); +double complex catan(double complex); +double complex ccos(double complex); +double complex csin(double complex); +double complex ctan(double complex); +double complex cacosh(double complex); +double complex casinh(double complex); +double complex catanh(double complex); +double complex ccosh(double complex); +double complex csinh(double complex); +double complex ctanh(double complex); +double complex cexp(double complex); +double complex clog(double complex); +double cabs(double complex); +double complex cpow(double complex, double complex); +double complex csqrt(double complex); +double carg(double complex); +double cimag(double complex); +double complex conj(double complex); +double complex cproj(double complex); +double creal(double complex); +/* + * C99 reserved + */ +double complex clog10(double complex); + +/* + * Float versions of C99 functions + */ +float complex cacosf(float complex); +float complex casinf(float complex); +float complex catanf(float complex); +float complex ccosf(float complex); +float complex csinf(float complex); +float complex ctanf(float complex); +float complex cacoshf(float complex); +float complex casinhf(float complex); +float complex catanhf(float complex); +float complex ccoshf(float complex); +float complex csinhf(float complex); +float complex ctanhf(float complex); +float complex cexpf(float complex); +float complex clogf(float complex); +float cabsf(float complex); +float complex cpowf(float complex, float complex); +float complex csqrtf(float complex); +float cargf(float complex); +float cimagf(float complex); +float complex conjf(float complex); +float complex cprojf(float complex); +float crealf(float complex); +/* + * C99 reserved + */ +float complex clog10f(float complex); + +/* + * Long double versions of C99 functions + */ +long double complex cacosl(long double complex); +long double complex casinl(long double complex); +long double complex catanl(long double complex); +long double complex ccosl(long double complex); +long double complex csinl(long double complex); +long double complex ctanl(long double complex); +long double complex cacoshl(long double complex); +long double complex casinhl(long double complex); +long double complex catanhl(long double complex); +long double complex ccoshl(long double complex); +long double complex csinhl(long double complex); +long double complex ctanhl(long double complex); +long double complex cexpl(long double complex); +long double complex clogl(long double complex); +long double cabsl(long double complex); +long double complex cpowl(long double complex, long double complex); +long double complex csqrtl(long double complex); +long double cargl(long double complex); +long double cimagl(long double complex); +long double complex conjl(long double complex); +long double complex cprojl(long double complex); +long double creall(long double complex); +/* + * C99 reserved + */ +long double complex clog10l(long double complex); + +__END_DECLS + +#endif /* !_COMPLEX_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/ctype.h b/sgx-jvm/linux-sgx/common/inc/tlibc/ctype.h new file mode 100644 index 0000000000..1408447059 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/ctype.h @@ -0,0 +1,64 @@ +/* $OpenBSD: ctype.h,v 1.22 2010/10/01 20:10:24 guenther Exp $ */ +/* $NetBSD: ctype.h,v 1.14 1994/10/26 00:55:47 cgd Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ctype.h 5.3 (Berkeley) 4/3/91 + */ + +#ifndef _CTYPE_H_ +#define _CTYPE_H_ + +#include + +__BEGIN_DECLS + +int _TLIBC_CDECL_ isalnum(int); +int _TLIBC_CDECL_ isalpha(int); +int _TLIBC_CDECL_ iscntrl(int); +int _TLIBC_CDECL_ isdigit(int); +int _TLIBC_CDECL_ isgraph(int); +int _TLIBC_CDECL_ islower(int); +int _TLIBC_CDECL_ isprint(int); +int _TLIBC_CDECL_ ispunct(int); +int _TLIBC_CDECL_ isspace(int); +int _TLIBC_CDECL_ isupper(int); +int _TLIBC_CDECL_ isxdigit(int); +int _TLIBC_CDECL_ tolower(int); +int _TLIBC_CDECL_ toupper(int); +int _TLIBC_CDECL_ isblank(int); + +__END_DECLS + +#endif /* _CTYPE_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/endian.h b/sgx-jvm/linux-sgx/common/inc/tlibc/endian.h new file mode 100644 index 0000000000..fcd74c9a14 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/endian.h @@ -0,0 +1,33 @@ +/* $OpenBSD: endian.h,v 1.18 2006/03/27 07:09:24 otto Exp $ */ + +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ENDIAN_H_ +#define _ENDIAN_H_ + +#include + +#endif /* _ENDIAN_H_ */ + diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/errno.h b/sgx-jvm/linux-sgx/common/inc/tlibc/errno.h new file mode 100644 index 0000000000..0924d5ac4b --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/errno.h @@ -0,0 +1,187 @@ +/* $OpenBSD: errno.h,v 1.1 2005/12/28 16:33:56 millert Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)errno.h 8.5 (Berkeley) 1/21/94 + */ + +#ifndef _ERRNO_H_ +#define _ERRNO_H_ + +#include + +#define EPERM 1 +#define ENOENT 2 +#define ESRCH 3 +#define EINTR 4 +#define EIO 5 +#define ENXIO 6 +#define E2BIG 7 +#define ENOEXEC 8 +#define EBADF 9 +#define ECHILD 10 +#define EAGAIN 11 +#define ENOMEM 12 +#define EACCES 13 +#define EFAULT 14 +#define ENOTBLK 15 +#define EBUSY 16 +#define EEXIST 17 +#define EXDEV 18 +#define ENODEV 19 +#define ENOTDIR 20 +#define EISDIR 21 +#define EINVAL 22 +#define ENFILE 23 +#define EMFILE 24 +#define ENOTTY 25 +#define ETXTBSY 26 +#define EFBIG 27 +#define ENOSPC 28 +#define ESPIPE 29 +#define EROFS 30 +#define EMLINK 31 +#define EPIPE 32 +#define EDOM 33 +#define ERANGE 34 +#define EDEADLK 35 +#define ENAMETOOLONG 36 +#define ENOLCK 37 +#define ENOSYS 38 +#define ENOTEMPTY 39 +#define ELOOP 40 +#define EWOULDBLOCK EAGAIN +#define ENOMSG 42 +#define EIDRM 43 +#define ECHRNG 44 +#define EL2NSYNC 45 +#define EL3HLT 46 +#define EL3RST 47 +#define ELNRNG 48 +#define EUNATCH 49 +#define ENOCSI 50 +#define EL2HLT 51 +#define EBADE 52 +#define EBADR 53 +#define EXFULL 54 +#define ENOANO 55 +#define EBADRQC 56 +#define EBADSLT 57 +#define EDEADLOCK EDEADLK +#define EBFONT 59 +#define ENOSTR 60 +#define ENODATA 61 +#define ETIME 62 +#define ENOSR 63 +#define ENONET 64 +#define ENOPKG 65 +#define EREMOTE 66 +#define ENOLINK 67 +#define EADV 68 +#define ESRMNT 69 +#define ECOMM 70 +#define EPROTO 71 +#define EMULTIHOP 72 +#define EDOTDOT 73 +#define EBADMSG 74 +#define EOVERFLOW 75 +#define ENOTUNIQ 76 +#define EBADFD 77 +#define EREMCHG 78 +#define ELIBACC 79 +#define ELIBBAD 80 +#define ELIBSCN 81 +#define ELIBMAX 82 +#define ELIBEXEC 83 +#define EILSEQ 84 +#define ERESTART 85 +#define ESTRPIPE 86 +#define EUSERS 87 +#define ENOTSOCK 88 +#define EDESTADDRREQ 89 +#define EMSGSIZE 90 +#define EPROTOTYPE 91 +#define ENOPROTOOPT 92 +#define EPROTONOSUPPORT 93 +#define ESOCKTNOSUPPORT 94 +#define EOPNOTSUPP 95 +#define EPFNOSUPPORT 96 +#define EAFNOSUPPORT 97 +#define EADDRINUSE 98 +#define EADDRNOTAVAIL 99 +#define ENETDOWN 100 +#define ENETUNREACH 101 +#define ENETRESET 102 +#define ECONNABORTED 103 +#define ECONNRESET 104 +#define ENOBUFS 105 +#define EISCONN 106 +#define ENOTCONN 107 +#define ESHUTDOWN 108 +#define ETOOMANYREFS 109 +#define ETIMEDOUT 110 +#define ECONNREFUSED 111 +#define EHOSTDOWN 112 +#define EHOSTUNREACH 113 +#define EALREADY 114 +#define EINPROGRESS 115 +#define ESTALE 116 +#define EUCLEAN 117 +#define ENOTNAM 118 +#define ENAVAIL 119 +#define EISNAM 120 +#define EREMOTEIO 121 +#define EDQUOT 122 +#define ENOMEDIUM 123 +#define EMEDIUMTYPE 124 +#define ECANCELED 125 +#define ENOKEY 126 +#define EKEYEXPIRED 127 +#define EKEYREVOKED 128 +#define EKEYREJECTED 129 +#define EOWNERDEAD 130 +#define ENOTRECOVERABLE 131 +#define ERFKILL 132 +#define EHWPOISON 133 +#define ENOTSUP EOPNOTSUPP + +__BEGIN_DECLS + +#ifndef errno +int * _TLIBC_CDECL_ __errno(void); +#define errno (*__errno()) +#endif /* errno */ +__END_DECLS + +#endif /* _ERRNO_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/float.h b/sgx-jvm/linux-sgx/common/inc/tlibc/float.h new file mode 100644 index 0000000000..99ae58de83 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/float.h @@ -0,0 +1,84 @@ +/* $OpenBSD: float.h,v 1.3 2008/07/21 20:50:54 martynas Exp $ */ +/* $NetBSD: float.h,v 1.8 1995/06/20 20:45:37 jtc Exp $ */ + +/* + * Copyright (c) 1989 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)float.h 7.1 (Berkeley) 5/8/90 + */ + +#ifndef _FLOAT_H_ +#define _FLOAT_H_ + +#include + +#define FLT_RADIX 2 /* b */ + +// The rounding direction can be specified by fesetround() in +#define FLT_ROUNDS 1 /* addition rounding: near */ +#define DECIMAL_DIG 21 /* max precision in decimal digits */ + +// NOTE: FLT_EVAL_METHOD is -1 under FREEBSD x86. +#ifdef __i386__ +#define FLT_EVAL_METHOD 2 /* long double */ +#else +#define FLT_EVAL_METHOD 0 /* no promotions */ +#endif + +#define DBL_MANT_DIG 53 +#define DBL_EPSILON 2.2204460492503131E-16 +#define DBL_DIG 15 +#define DBL_MIN_EXP (-1021) +#define DBL_MIN 2.2250738585072014E-308 +#define DBL_MIN_10_EXP (-307) +#define DBL_MAX_EXP 1024 +#define DBL_MAX_10_EXP 308 + +#define FLT_MANT_DIG 24 /* p */ +#define FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define FLT_MIN_EXP (-125) /* emin */ +#define FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define FLT_MAX_EXP 128 /* emax */ +#define FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define DBL_MAX 1.7976931348623157E+308 +#define FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ +#define FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ + +#define LDBL_MANT_DIG 64 +#define LDBL_EPSILON 1.08420217248550443401e-19L +#define LDBL_DIG 18 +#define LDBL_MIN_EXP (-16381) +#define LDBL_MIN 3.36210314311209350626e-4932L +#define LDBL_MIN_10_EXP (-4931) +#define LDBL_MAX_EXP 16384 +#define LDBL_MAX 1.18973149535723176502e+4932L +#define LDBL_MAX_10_EXP 4932 + +#endif /* _FLOAT_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/inttypes.h b/sgx-jvm/linux-sgx/common/inc/tlibc/inttypes.h new file mode 100644 index 0000000000..c4fbcafc32 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/inttypes.h @@ -0,0 +1,330 @@ +/* $OpenBSD: inttypes.h,v 1.10 2009/01/13 18:13:51 kettenis Exp $ */ + +/* + * Copyright (c) 1997, 2005 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _INTTYPES_H_ +#define _INTTYPES_H_ + +#include + +/* + * 7.8.1 Macros for format specifiers + * + * Each of the following object-like macros expands to a string + * literal containing a conversion specifier, possibly modified by + * a prefix such as hh, h, l, or ll, suitable for use within the + * format argument of a formatted input/output function when + * converting the corresponding integer type. These macro names + * have the general form of PRI (character string literals for the + * fprintf family) or SCN (character string literals for the fscanf + * family), followed by the conversion specifier, followed by a + * name corresponding to a similar typedef name. For example, + * PRIdFAST32 can be used in a format string to print the value of + * an integer of type int_fast32_t. + */ + +/* fprintf macros for signed integers */ +#define PRId8 "d" /* int8_t */ +#define PRId16 "d" /* int16_t */ +#define PRId32 "d" /* int32_t */ +#ifdef __x86_64__ +#define PRId64 "ld" /* int64_t */ +#else +#define PRId64 "lld" /* int64_t */ +#endif + +#define PRIdLEAST8 "d" /* int_least8_t */ +#define PRIdLEAST16 "d" /* int_least16_t */ +#define PRIdLEAST32 "d" /* int_least32_t */ +#ifdef __x86_64__ +#define PRIdLEAST64 "ld" /* int_least64_t */ +#else +#define PRIdLEAST64 "lld" /* int_least64_t */ +#endif + +#define PRIdFAST8 "d" /* int_fast8_t */ +#ifdef __x86_64__ +#define PRIdFAST16 "ld" /* int_fast16_t */ +#define PRIdFAST32 "ld" /* int_fast32_t */ +#define PRIdFAST64 "ld" /* int_fast64_t */ +#else +#define PRIdFAST16 "d" /* int_fast16_t */ +#define PRIdFAST32 "d" /* int_fast32_t */ +#define PRIdFAST64 "lld" /* int_fast64_t */ +#endif + +#ifdef __x86_64__ +#define PRIdMAX "ld" /* intmax_t */ +#else +#if defined(__i386__) +#define PRIdMAX "lld" /* intmax_t */ +#else +#define PRIdMAX "jd" /* intmax_t */ +#endif +#endif + +#ifdef __i386__ +#define PRIdPTR "d" /* intptr_t */ +#else +#define PRIdPTR "ld" /* intptr_t */ +#endif + +#define PRIi8 "i" /* int8_t */ +#define PRIi16 "i" /* int16_t */ +#define PRIi32 "i" /* int32_t */ +#ifdef __x86_64__ +#define PRIi64 "li" /* int64_t */ +#else +#define PRIi64 "lli" /* int64_t */ +#endif + +#define PRIiLEAST8 "i" /* int_least8_t */ +#define PRIiLEAST16 "i" /* int_least16_t */ +#define PRIiLEAST32 "i" /* int_least32_t */ +#ifdef __x86_64__ +#define PRIiLEAST64 "li" /* int_least64_t */ +#else +#define PRIiLEAST64 "lli" /* int_least64_t */ +#endif + +#define PRIiFAST8 "i" /* int_fast8_t */ +#ifdef __x86_64__ +#define PRIiFAST16 "li" /* int_fast16_t */ +#define PRIiFAST32 "li" /* int_fast32_t */ +#define PRIiFAST64 "li" /* int_fast64_t */ +#else +#define PRIiFAST16 "i" /* int_fast16_t */ +#define PRIiFAST32 "i" /* int_fast32_t */ +#define PRIiFAST64 "lli" /* int_fast64_t */ +#endif + +#ifdef __x86_64__ +#define PRIiMAX "li" /* intmax_t */ +#else +#if defined(__i386__) +#define PRIiMAX "lli" /* intmax_t */ +#else +#define PRIiMAX "ji" /* intmax_t */ +#endif +#endif + +#ifdef __i386__ +#define PRIiPTR "i" /* intptr_t */ +#else +#define PRIiPTR "li" /* intptr_t */ +#endif + +/* fprintf macros for unsigned integers */ +#define PRIo8 "o" /* int8_t */ +#define PRIo16 "o" /* int16_t */ +#define PRIo32 "o" /* int32_t */ +#ifdef __x86_64__ +#define PRIo64 "lo" /* int64_t */ +#else +#define PRIo64 "llo" /* int64_t */ +#endif + +#define PRIoLEAST8 "o" /* int_least8_t */ +#define PRIoLEAST16 "o" /* int_least16_t */ +#define PRIoLEAST32 "o" /* int_least32_t */ +#ifdef __x86_64__ +#define PRIoLEAST64 "lo" /* int_least64_t */ +#else +#define PRIoLEAST64 "llo" /* int_least64_t */ +#endif + +#define PRIoFAST8 "o" /* int_fast8_t */ +#ifdef __x86_64__ +#define PRIoFAST16 "lo" /* int_fast16_t */ +#define PRIoFAST32 "lo" /* int_fast32_t */ +#define PRIoFAST64 "lo" /* int_fast64_t */ +#else +#define PRIoFAST16 "o" /* int_fast16_t */ +#define PRIoFAST32 "o" /* int_fast32_t */ +#define PRIoFAST64 "llo" /* int_fast64_t */ +#endif + +#ifdef __x86_64__ +#define PRIoMAX "lo" /* intmax_t */ +#else +#if defined(__i386__) +#define PRIoMAX "llo" /* intmax_t */ +#else +#define PRIoMAX "jo" /* intmax_t */ +#endif +#endif + +#ifdef __i386__ +#define PRIoPTR "o" /* intptr_t */ +#else +#define PRIoPTR "lo" /* intptr_t */ +#endif + +#define PRIu8 "u" /* uint8_t */ +#define PRIu16 "u" /* uint16_t */ +#define PRIu32 "u" /* uint32_t */ + +#ifdef __x86_64__ +#define PRIu64 "lu" /* uint64_t */ +#else +#define PRIu64 "llu" /* uint64_t */ +#endif + +#define PRIuLEAST8 "u" /* uint_least8_t */ +#define PRIuLEAST16 "u" /* uint_least16_t */ +#define PRIuLEAST32 "u" /* uint_least32_t */ + +#ifdef __x86_64__ +#define PRIuLEAST64 "lu" /* uint_least64_t */ +#else +#define PRIuLEAST64 "llu" /* uint_least64_t */ +#endif + +#define PRIuFAST8 "u" /* uint_fast8_t */ + +#ifdef __x86_64__ +#define PRIuFAST16 "lu" /* uint_fast16_t */ +#define PRIuFAST32 "lu" /* uint_fast32_t */ +#define PRIuFAST64 "lu" /* uint_fast64_t */ +#else +#define PRIuFAST16 "u" /* uint_fast16_t */ +#define PRIuFAST32 "u" /* uint_fast32_t */ +#define PRIuFAST64 "llu" /* uint_fast64_t */ +#endif + +#ifdef __x86_64__ +#define PRIuMAX "lu" /* uintmax_t */ +#else +#if defined(__i386__) +#define PRIuMAX "llu" /* uintmax_t */ +#else +#define PRIuMAX "ju" /* uintmax_t */ +#endif +#endif + +#ifdef __i386__ +#define PRIuPTR "u" /* uintptr_t */ +#else +#define PRIuPTR "lu" /* uintptr_t */ +#endif + +#define PRIx8 "x" /* uint8_t */ +#define PRIx16 "x" /* uint16_t */ +#define PRIx32 "x" /* uint32_t */ +#ifdef __x86_64__ +#define PRIx64 "lx" /* uint64_t */ +#else +#define PRIx64 "llx" /* uint64_t */ +#endif + +#define PRIxLEAST8 "x" /* uint_least8_t */ +#define PRIxLEAST16 "x" /* uint_least16_t */ +#define PRIxLEAST32 "x" /* uint_least32_t */ +#ifdef __x86_64__ +#define PRIxLEAST64 "lx" /* uint_least64_t */ +#else +#define PRIxLEAST64 "llx" /* uint_least64_t */ +#endif + +#define PRIxFAST8 "x" /* uint_fast8_t */ +#ifdef __x86_64__ +#define PRIxFAST16 "lx" /* uint_fast16_t */ +#define PRIxFAST32 "lx" /* uint_fast32_t */ +#define PRIxFAST64 "lx" /* uint_fast64_t */ +#else +#define PRIxFAST16 "x" /* uint_fast16_t */ +#define PRIxFAST32 "x" /* uint_fast32_t */ +#define PRIxFAST64 "llx" /* uint_fast64_t */ +#endif + +#ifdef __x86_64__ +#define PRIxMAX "lx" /* uintmax_t */ +#else +#if defined(__i386__) +#define PRIxMAX "llx" /* uintmax_t */ +#else +#define PRIxMAX "jx" /* uintmax_t */ +#endif +#endif + +#ifdef __i386__ +#define PRIxPTR "x" /* uintptr_t */ +#else +#define PRIxPTR "lx" /* uintptr_t */ +#endif + +#define PRIX8 "X" /* uint8_t */ +#define PRIX16 "X" /* uint16_t */ +#define PRIX32 "X" /* uint32_t */ + +#ifdef __x86_64__ +#define PRIX64 "lX" /* uint64_t */ +#else +#define PRIX64 "llX" /* uint64_t */ +#endif + +#define PRIXLEAST8 "X" /* uint_least8_t */ +#define PRIXLEAST16 "X" /* uint_least16_t */ +#define PRIXLEAST32 "X" /* uint_least32_t */ +#ifdef __x86_64__ +#define PRIXLEAST64 "lX" /* uint_least64_t */ +#else +#define PRIXLEAST64 "llX" /* uint_least64_t */ +#endif + +#define PRIXFAST8 "X" /* uint_fast8_t */ +#ifdef __x86_64__ +#define PRIXFAST16 "lX" /* uint_fast16_t */ +#define PRIXFAST32 "lX" /* uint_fast32_t */ +#define PRIXFAST64 "lX" /* uint_fast64_t */ +#else +#define PRIXFAST16 "X" /* uint_fast16_t */ +#define PRIXFAST32 "X" /* uint_fast32_t */ +#define PRIXFAST64 "llX" /* uint_fast64_t */ +#endif + +#ifdef __x86_64__ +#define PRIXMAX "lX" /* uintmax_t */ +#else +#if defined(__i386__) +#define PRIXMAX "llX" /* uintmax_t */ +#else +#define PRIXMAX "jX" /* uintmax_t */ +#endif +#endif + +#ifdef __i386__ +#define PRIXPTR "X" /* uintptr_t */ +#else +#define PRIXPTR "lX" /* uintptr_t */ +#endif + +typedef struct { + intmax_t quot; /* quotient */ + intmax_t rem; /* remainder */ +} imaxdiv_t; + +__BEGIN_DECLS + +intmax_t _TLIBC_CDECL_ imaxabs(intmax_t); +imaxdiv_t _TLIBC_CDECL_ imaxdiv(intmax_t, intmax_t); +intmax_t _TLIBC_CDECL_ strtoimax(const char *, char **, int); +uintmax_t _TLIBC_CDECL_ strtoumax(const char *, char **, int); + +__END_DECLS + +#endif /* _INTTYPES_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/iso646.h b/sgx-jvm/linux-sgx/common/inc/tlibc/iso646.h new file mode 100644 index 0000000000..d711cace6d --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/iso646.h @@ -0,0 +1,26 @@ +/* $OpenBSD: iso646.h,v 1.3 2001/10/11 00:05:21 espie Exp $ */ +/* $NetBSD: iso646.h,v 1.1 1995/02/17 09:08:10 jtc Exp $ */ + +/* + * Written by J.T. Conklin 02/16/95. + * Public domain. + */ + +#ifndef _ISO646_H_ +#define _ISO646_H_ + +#ifndef __cplusplus +#define and && +#define and_eq &= +#define bitand & +#define bitor | +#define compl ~ +#define not ! +#define not_eq != +#define or || +#define or_eq |= +#define xor ^ +#define xor_eq ^= +#endif + +#endif /* !_ISO646_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/limits.h b/sgx-jvm/linux-sgx/common/inc/tlibc/limits.h new file mode 100644 index 0000000000..fab59c9b8e --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/limits.h @@ -0,0 +1,41 @@ +/* $OpenBSD: limits.h,v 1.15 2008/02/10 09:59:54 kettenis Exp $ */ +/* $NetBSD: limits.h,v 1.7 1994/10/26 00:56:00 cgd Exp $ */ + +/* + * Copyright (c) 1988 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)limits.h 5.9 (Berkeley) 4/3/91 + */ + + +#ifndef _LIMITS_H_ +#define _LIMITS_H_ + +#include + +#endif /* !_LIMITS_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/math.h b/sgx-jvm/linux-sgx/common/inc/tlibc/math.h new file mode 100644 index 0000000000..104ac7f156 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/math.h @@ -0,0 +1,430 @@ +/* $OpenBSD: math.h,v 1.27 2010/12/14 11:16:15 martynas Exp $ */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * from: @(#)fdlibm.h 5.1 93/09/24 + */ + +#ifndef _MATH_H_ +#define _MATH_H_ + +#include +#include +#include + +#include + +typedef __float_t float_t; +typedef __double_t double_t; + +#define FP_NAN 0x00 +#define FP_INFINITE 0x01 +#define FP_ZERO 0x02 +#define FP_SUBNORMAL 0x03 +#define FP_NORMAL 0x04 + +#define FP_ILOGB0 (-INT_MAX - 1) +#define FP_ILOGBNAN (-INT_MAX - 1) + +#define fpclassify(x) \ + ((sizeof (x) == sizeof (float)) ? \ + __fpclassifyf(x) \ + : (sizeof (x) == sizeof (double)) ? \ + __fpclassify(x) \ + : __fpclassifyl(x)) +#define isfinite(x) \ + ((sizeof (x) == sizeof (float)) ? \ + __isfinitef(x) \ + : (sizeof (x) == sizeof (double)) ? \ + __isfinite(x) \ + : __isfinitel(x)) +#define isnormal(x) \ + ((sizeof (x) == sizeof (float)) ? \ + __isnormalf(x) \ + : (sizeof (x) == sizeof (double)) ? \ + __isnormal(x) \ + : __isnormall(x)) +#define signbit(x) \ + ((sizeof (x) == sizeof (float)) ? \ + __signbitf(x) \ + : (sizeof (x) == sizeof (double)) ? \ + __signbit(x) \ + : __signbitl(x)) +#define isinf(x) \ + ((sizeof (x) == sizeof (float)) ? \ + __isinff(x) \ + : (sizeof (x) == sizeof (double)) ? \ + __isinf(x) \ + : __isinfl(x)) +#define isnan(x) \ + ((sizeof (x) == sizeof (float)) ? \ + __isnanf(x) \ + : (sizeof (x) == sizeof (double)) ? \ + __isnan(x) \ + : __isnanl(x)) + +#define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) +#define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) +#define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) +#define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) +#define islessgreater(x, y) (!isunordered((x), (y)) && ((x) > (y) || (y) > (x))) +#define isunordered(x, y) (isnan(x) || isnan(y)) + +__BEGIN_DECLS + +extern char __infinity[]; +#define HUGE_VAL (*(double *)(void *)__infinity) +#define HUGE_VALF ((float)HUGE_VAL) +#define HUGE_VALL ((long double)HUGE_VAL) +#define INFINITY HUGE_VALF +extern char __nan[]; +#define NAN (*(float *)(void *)__nan) + +/* + * ANSI/POSIX + */ +double _TLIBC_CDECL_ acos(double); +double _TLIBC_CDECL_ asin(double); +double _TLIBC_CDECL_ atan(double); +double _TLIBC_CDECL_ atan2(double, double); +double _TLIBC_CDECL_ cos(double); +double _TLIBC_CDECL_ sin(double); +double _TLIBC_CDECL_ tan(double); + +double _TLIBC_CDECL_ cosh(double); +double _TLIBC_CDECL_ sinh(double); +double _TLIBC_CDECL_ tanh(double); + +double _TLIBC_CDECL_ exp(double); +double _TLIBC_CDECL_ frexp(double, int *); +double _TLIBC_CDECL_ ldexp(double, int); +double _TLIBC_CDECL_ log(double); +double _TLIBC_CDECL_ log10(double); +double _TLIBC_CDECL_ modf(double, double *); + +double _TLIBC_CDECL_ pow(double, double); +double _TLIBC_CDECL_ sqrt(double); + +double _TLIBC_CDECL_ ceil(double); +double _TLIBC_CDECL_ fabs(double); +double _TLIBC_CDECL_ floor(double); +double _TLIBC_CDECL_ fmod(double, double); + +/* + * C99 + */ +double _TLIBC_CDECL_ acosh(double); +double _TLIBC_CDECL_ asinh(double); +double _TLIBC_CDECL_ atanh(double); + +double _TLIBC_CDECL_ exp2(double); +double _TLIBC_CDECL_ expm1(double); +int _TLIBC_CDECL_ ilogb(double); +double _TLIBC_CDECL_ log1p(double); +double _TLIBC_CDECL_ log2(double); +double _TLIBC_CDECL_ logb(double); +double _TLIBC_CDECL_ scalbn(double, int); +double _TLIBC_CDECL_ scalbln(double, long int); + +double _TLIBC_CDECL_ cbrt(double); +double _TLIBC_CDECL_ hypot(double, double); + +double _TLIBC_CDECL_ erf(double); +double _TLIBC_CDECL_ erfc(double); +double _TLIBC_CDECL_ lgamma(double); +double _TLIBC_CDECL_ tgamma(double); + +double _TLIBC_CDECL_ nearbyint(double); +double _TLIBC_CDECL_ rint(double); +long int _TLIBC_CDECL_ lrint(double); +long long int _TLIBC_CDECL_ llrint(double); +double _TLIBC_CDECL_ round(double); +long int _TLIBC_CDECL_ lround(double); +long long int _TLIBC_CDECL_ llround(double); +double _TLIBC_CDECL_ trunc(double); + +double _TLIBC_CDECL_ remainder(double, double); +double _TLIBC_CDECL_ remquo(double, double, int *); + +double _TLIBC_CDECL_ copysign(double, double); +double _TLIBC_CDECL_ nan(const char *); +double _TLIBC_CDECL_ nextafter(double, double); + +double _TLIBC_CDECL_ fdim(double, double); +double _TLIBC_CDECL_ fmax(double, double); +double _TLIBC_CDECL_ fmin(double, double); + +double _TLIBC_CDECL_ fma(double, double, double); + +/* + * Float versions of C99 functions + */ + +float _TLIBC_CDECL_ acosf(float); +float _TLIBC_CDECL_ asinf(float); +float _TLIBC_CDECL_ atanf(float); +float _TLIBC_CDECL_ atan2f(float, float); +float _TLIBC_CDECL_ cosf(float); +float _TLIBC_CDECL_ sinf(float); +float _TLIBC_CDECL_ tanf(float); + +float _TLIBC_CDECL_ acoshf(float); +float _TLIBC_CDECL_ asinhf(float); +float _TLIBC_CDECL_ atanhf(float); +float _TLIBC_CDECL_ coshf(float); +float _TLIBC_CDECL_ sinhf(float); +float _TLIBC_CDECL_ tanhf(float); + +float _TLIBC_CDECL_ expf(float); +float _TLIBC_CDECL_ exp2f(float); +float _TLIBC_CDECL_ expm1f(float); +float _TLIBC_CDECL_ frexpf(float, int *); +int _TLIBC_CDECL_ ilogbf(float); +float _TLIBC_CDECL_ ldexpf(float, int); +float _TLIBC_CDECL_ logf(float); +float _TLIBC_CDECL_ log10f(float); +float _TLIBC_CDECL_ log1pf(float); +float _TLIBC_CDECL_ log2f(float); +float _TLIBC_CDECL_ logbf(float); +float _TLIBC_CDECL_ modff(float, float *); +float _TLIBC_CDECL_ scalbnf(float, int); +float _TLIBC_CDECL_ scalblnf(float, long int); + +float _TLIBC_CDECL_ cbrtf(float); +float _TLIBC_CDECL_ fabsf(float); +float _TLIBC_CDECL_ hypotf(float, float); +float _TLIBC_CDECL_ powf(float, float); +float _TLIBC_CDECL_ sqrtf(float); + +float _TLIBC_CDECL_ erff(float); +float _TLIBC_CDECL_ erfcf(float); +float _TLIBC_CDECL_ lgammaf(float); +float _TLIBC_CDECL_ tgammaf(float); + +float _TLIBC_CDECL_ ceilf(float); +float _TLIBC_CDECL_ floorf(float); +float _TLIBC_CDECL_ nearbyintf(float); + +float _TLIBC_CDECL_ rintf(float); +long int _TLIBC_CDECL_ lrintf(float); +long long int _TLIBC_CDECL_ llrintf(float); +float _TLIBC_CDECL_ roundf(float); +long int _TLIBC_CDECL_ lroundf(float); +long long int _TLIBC_CDECL_ llroundf(float); +float _TLIBC_CDECL_ truncf(float); + +float _TLIBC_CDECL_ fmodf(float, float); +float _TLIBC_CDECL_ remainderf(float, float); +float _TLIBC_CDECL_ remquof(float, float, int *); + +float _TLIBC_CDECL_ copysignf(float, float); +float _TLIBC_CDECL_ nanf(const char *); +float _TLIBC_CDECL_ nextafterf(float, float); + +float _TLIBC_CDECL_ fdimf(float, float); +float _TLIBC_CDECL_ fmaxf(float, float); +float _TLIBC_CDECL_ fminf(float, float); + +float _TLIBC_CDECL_ fmaf(float, float, float); + +/* + * Long double versions of C99 functions + */ + +/* Macros defining long double functions to be their double counterparts + * (long double is synonymous with double in this implementation). + */ + +long double _TLIBC_CDECL_ acosl(long double); +long double _TLIBC_CDECL_ asinl(long double); +long double _TLIBC_CDECL_ atanl(long double); +long double _TLIBC_CDECL_ atan2l(long double, long double); +long double _TLIBC_CDECL_ cosl(long double); +long double _TLIBC_CDECL_ sinl(long double); +long double _TLIBC_CDECL_ tanl(long double); + +long double _TLIBC_CDECL_ acoshl(long double); +long double _TLIBC_CDECL_ asinhl(long double); +long double _TLIBC_CDECL_ atanhl(long double); +long double _TLIBC_CDECL_ coshl(long double); +long double _TLIBC_CDECL_ sinhl(long double); +long double _TLIBC_CDECL_ tanhl(long double); + +long double _TLIBC_CDECL_ expl(long double); +long double _TLIBC_CDECL_ exp2l(long double); +long double _TLIBC_CDECL_ expm1l(long double); +long double _TLIBC_CDECL_ frexpl(long double, int *); +int _TLIBC_CDECL_ ilogbl(long double); +long double _TLIBC_CDECL_ ldexpl(long double, int); +long double _TLIBC_CDECL_ logl(long double); +long double _TLIBC_CDECL_ log10l(long double); +long double _TLIBC_CDECL_ log1pl(long double); +long double _TLIBC_CDECL_ log2l(long double); +long double _TLIBC_CDECL_ logbl(long double); +long double _TLIBC_CDECL_ modfl(long double, long double *); +long double _TLIBC_CDECL_ scalbnl(long double, int); +long double _TLIBC_CDECL_ scalblnl(long double, long int); + +long double _TLIBC_CDECL_ cbrtl(long double); +long double _TLIBC_CDECL_ fabsl(long double); +long double _TLIBC_CDECL_ hypotl(long double, long double); +long double _TLIBC_CDECL_ powl(long double, long double); +long double _TLIBC_CDECL_ sqrtl(long double); + +long double _TLIBC_CDECL_ erfl(long double); +long double _TLIBC_CDECL_ erfcl(long double); +long double _TLIBC_CDECL_ lgammal(long double); +long double _TLIBC_CDECL_ tgammal(long double); + +long double _TLIBC_CDECL_ ceill(long double); +long double _TLIBC_CDECL_ floorl(long double); +long double _TLIBC_CDECL_ nearbyintl(long double); +long double _TLIBC_CDECL_ rintl(long double); +long int _TLIBC_CDECL_ lrintl(long double); +long long int _TLIBC_CDECL_ llrintl(long double); +long double _TLIBC_CDECL_ roundl(long double); +long int _TLIBC_CDECL_ lroundl(long double); +long long int _TLIBC_CDECL_ llroundl(long double); +long double _TLIBC_CDECL_ truncl(long double); + +long double _TLIBC_CDECL_ fmodl(long double, long double); +long double _TLIBC_CDECL_ remainderl(long double, long double); +long double _TLIBC_CDECL_ remquol(long double, long double, int *); + +long double _TLIBC_CDECL_ copysignl(long double, long double); +long double _TLIBC_CDECL_ nanl(const char *); +long double _TLIBC_CDECL_ nextafterl(long double, long double); + +long double _TLIBC_CDECL_ fdiml(long double, long double); +long double _TLIBC_CDECL_ fmaxl(long double, long double); +long double _TLIBC_CDECL_ fminl(long double, long double); +long double _TLIBC_CDECL_ fmal(long double, long double, long double); + +/* nexttoward(): +* The implementation in Intel math library is incompatible with MSVC. +* Because sizeof(long double) is 8bytes with MSVC, +* but the expected long double size is 10bytes. +* And by default, MSVC doesn't provide nexttoward(). +* So we only provide Linux version here. +*/ +double _TLIBC_CDECL_ nexttoward(double, long double); +float _TLIBC_CDECL_ nexttowardf(float, long double); + +long double _TLIBC_CDECL_ nexttowardl(long double, long double); + +/* + * Library implementation + */ +int _TLIBC_CDECL_ __fpclassify(double); +int _TLIBC_CDECL_ __fpclassifyf(float); +int _TLIBC_CDECL_ __isfinite(double); +int _TLIBC_CDECL_ __isfinitef(float); +int _TLIBC_CDECL_ __isinf(double); +int _TLIBC_CDECL_ __isinff(float); +int _TLIBC_CDECL_ __isnan(double); +int _TLIBC_CDECL_ __isnanf(float); +int _TLIBC_CDECL_ __isnormal(double); +int _TLIBC_CDECL_ __isnormalf(float); +int _TLIBC_CDECL_ __signbit(double); +int _TLIBC_CDECL_ __signbitf(float); + +int _TLIBC_CDECL_ __fpclassifyl(long double); +int _TLIBC_CDECL_ __isfinitel(long double); +int _TLIBC_CDECL_ __isinfl(long double); +int _TLIBC_CDECL_ __isnanl(long double); +int _TLIBC_CDECL_ __isnormall(long double); +int _TLIBC_CDECL_ __signbitl(long double); + +/* + * Non-C99 functions. + */ +double _TLIBC_CDECL_ drem(double, double); +double _TLIBC_CDECL_ exp10(double); +double _TLIBC_CDECL_ gamma(double); +double _TLIBC_CDECL_ gamma_r(double, int *); +double _TLIBC_CDECL_ j0(double); +double _TLIBC_CDECL_ j1(double); +double _TLIBC_CDECL_ jn(int, double); +double _TLIBC_CDECL_ lgamma_r(double, int *); +double _TLIBC_CDECL_ pow10(double); +double _TLIBC_CDECL_ scalb(double, double); +/* C99 Macro signbit.*/ +double _TLIBC_CDECL_ significand(double); +void _TLIBC_CDECL_ sincos(double, double *, double *); +double _TLIBC_CDECL_ y0(double); +double _TLIBC_CDECL_ y1(double); +double _TLIBC_CDECL_ yn(int, double); +/* C99 Macro isinf.*/ +/* C99 Macro isnan.*/ +int _TLIBC_CDECL_ finite(double); + +float _TLIBC_CDECL_ dremf(float, float); +float _TLIBC_CDECL_ exp10f(float); +float _TLIBC_CDECL_ gammaf(float); +float _TLIBC_CDECL_ gammaf_r(float, int *); +float _TLIBC_CDECL_ j0f(float); +float _TLIBC_CDECL_ j1f(float); +float _TLIBC_CDECL_ jnf(int, float); +float _TLIBC_CDECL_ lgammaf_r(float, int *); +float _TLIBC_CDECL_ pow10f(float); +float _TLIBC_CDECL_ scalbf(float, float); +int _TLIBC_CDECL_ signbitf(float); +float _TLIBC_CDECL_ significandf(float); +void _TLIBC_CDECL_ sincosf(float, float *, float *); +float _TLIBC_CDECL_ y0f(float); +float _TLIBC_CDECL_ y1f(float); +float _TLIBC_CDECL_ ynf(int, float); +int _TLIBC_CDECL_ finitef(float); +int _TLIBC_CDECL_ isinff(float); +int _TLIBC_CDECL_ isnanf(float); + +long double _TLIBC_CDECL_ dreml(long double, long double); +long double _TLIBC_CDECL_ exp10l(long double); +long double _TLIBC_CDECL_ gammal(long double); +long double _TLIBC_CDECL_ gammal_r(long double, int *); +long double _TLIBC_CDECL_ j0l(long double); +long double _TLIBC_CDECL_ j1l(long double); +long double _TLIBC_CDECL_ jnl(int, long double); +long double _TLIBC_CDECL_ lgammal_r(long double, int *); +long double _TLIBC_CDECL_ pow10l(long double); +long double _TLIBC_CDECL_ scalbl(long double, long double); +int _TLIBC_CDECL_ signbitl(long double); +long double _TLIBC_CDECL_ significandl(long double); +void _TLIBC_CDECL_ sincosl(long double, long double *, long double *); +long double _TLIBC_CDECL_ y1l(long double); +long double _TLIBC_CDECL_ y0l(long double); +long double _TLIBC_CDECL_ ynl(int, long double); +int _TLIBC_CDECL_ finitel(long double); +int _TLIBC_CDECL_ isinfl(long double); +int _TLIBC_CDECL_ isnanl(long double); + +/* + * TODO: From Intel Decimal Floating-Point Math Library + * signbitd32/signbitd64/signbitd128, finited32/finited64/finited128 + * isinfd32/isinfd64/isinfd128, isnand32/isnand64/isnand128 + */ +#if defined(__cplusplus) +/* Clang does not support decimal floating point types. + * + * c.f.: + * http://clang.llvm.org/docs/UsersManual.html#gcc-extensions-not-implemented-yet + */ +#if !defined(__clang__) +typedef float _Decimal32 __attribute__((mode(SD))); +typedef float _Decimal64 __attribute__((mode(DD))); +typedef float _Decimal128 __attribute__((mode(TD))); +#endif +#endif + +__END_DECLS + +#endif /* !_MATH_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/setjmp.h b/sgx-jvm/linux-sgx/common/inc/tlibc/setjmp.h new file mode 100644 index 0000000000..ac5627f7ea --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/setjmp.h @@ -0,0 +1,64 @@ +/* $NetBSD: setjmp.h,v 1.26 2011/11/05 09:27:06 joerg Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)setjmp.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _SETJMP_H_ +#define _SETJMP_H_ + +#ifndef _JB_ATTRIBUTES +#define _JB_ATTRIBUTES /**/ +#else +#endif +#ifndef _BSD_JBSLOT_T_ +#define _BSD_JBSLOT_T_ long +#endif + +#define _JBLEN 8 + +typedef _BSD_JBSLOT_T_ jmp_buf[_JBLEN] _JB_ATTRIBUTES; + +#include +#define __returns_twice __attribute__((__returns_twice__)) +#define __dead + +__BEGIN_DECLS +int _setjmp(jmp_buf) __returns_twice; +void _longjmp(jmp_buf, int) __dead; +__END_DECLS + +#endif /* !_SETJMP_H_ */ + diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/stdarg.h b/sgx-jvm/linux-sgx/common/inc/tlibc/stdarg.h new file mode 100644 index 0000000000..ed73e246a6 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/stdarg.h @@ -0,0 +1,48 @@ +/* $OpenBSD: stdarg.h,v 1.14 2010/12/30 05:01:36 tedu Exp $ */ +/* $NetBSD: stdarg.h,v 1.12 1995/12/25 23:15:31 mycroft Exp $ */ + +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)stdarg.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _STDARG_H_ +#define _STDARG_H_ + +#include +#include + +typedef __va_list va_list; + +#define va_start(ap, last) __builtin_va_start((ap), last) +#define va_end __builtin_va_end +#define va_arg __builtin_va_arg +#define va_copy(dst, src) __builtin_va_copy((dst),(src)) + +#endif /* !_STDARG_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/stdbool.h b/sgx-jvm/linux-sgx/common/inc/tlibc/stdbool.h new file mode 100644 index 0000000000..bd1837ec46 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/stdbool.h @@ -0,0 +1,44 @@ +/* $OpenBSD: stdbool.h,v 1.5 2010/07/24 22:17:03 guenther Exp $ */ + +/* + * Written by Marc Espie, September 25, 1999 + * Public domain. + */ + +#ifndef _STDBOOL_H_ +#define _STDBOOL_H_ + +#ifndef __cplusplus + +#ifndef __GNUC__ +/* Support for _C99: type _Bool is already built-in. */ +/* `_Bool' type must promote to `int' or `unsigned int'. */ +typedef enum { + false = 0, + true = 1 +} _Bool; + +/* And those constants must also be available as macros. */ +# define false false +# define true true +#else /* __GNUC__ */ +# define false 0 +# define true 1 +#endif + +/* User visible type `bool' is provided as a macro which may be redefined */ +#define bool _Bool + +#else /* __cplusplus */ + +# define _Bool bool +# define bool bool +# define false false +# define true true + +#endif + +/* Inform that everything is fine */ +#define __bool_true_false_are_defined 1 + +#endif /* _STDBOOL_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/stddef.h b/sgx-jvm/linux-sgx/common/inc/tlibc/stddef.h new file mode 100644 index 0000000000..84509c5025 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/stddef.h @@ -0,0 +1,70 @@ +/* $OpenBSD: stddef.h,v 1.10 2009/09/22 21:40:02 jsg Exp $ */ +/* $NetBSD: stddef.h,v 1.4 1994/10/26 00:56:26 cgd Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)stddef.h 5.5 (Berkeley) 4/3/91 + */ + +#ifndef _STDDEF_H_ +#define _STDDEF_H_ + +#include +#include + +#ifndef _PTRDIFF_T_DEFINED_ +#define _PTRDIFF_T_DEFINED_ +typedef __ptrdiff_t ptrdiff_t; +#endif + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus) +#define _WCHAR_T_DEFINED_ +#ifndef __WCHAR_TYPE__ +#define __WCHAR_TYPE__ int +#endif +typedef __WCHAR_TYPE__ wchar_t; +#endif + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#define offsetof(type, member) ((size_t)(&((type *)0)->member)) + +#endif /* _STDDEF_H_ */ + diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/stdint.h b/sgx-jvm/linux-sgx/common/inc/tlibc/stdint.h new file mode 100644 index 0000000000..d283ae9214 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/stdint.h @@ -0,0 +1,24 @@ +/* $OpenBSD: stdint.h,v 1.4 2006/12/10 22:17:55 deraadt Exp $ */ + +/* + * Copyright (c) 1997, 2005 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _STDINT_H_ +#define _STDINT_H_ + +#include + +#endif /* _STDINT_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/stdio.h b/sgx-jvm/linux-sgx/common/inc/tlibc/stdio.h new file mode 100644 index 0000000000..0175a3ace3 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/stdio.h @@ -0,0 +1,95 @@ +/* $OpenBSD: stdio.h,v 1.38 2009/11/09 00:18:27 kurt Exp $ */ +/* $NetBSD: stdio.h,v 1.18 1996/04/25 18:29:21 jtc Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)stdio.h 5.17 (Berkeley) 6/3/91 + */ + +#ifndef _STDIO_H_ +#define _STDIO_H_ + +#include +#include + +#include + +#ifndef _SIZE_T_DEFINED_ +typedef __size_t size_t; +#define _SIZE_T_DEFINED_ +#endif + +#ifndef NULL +# ifdef __cplusplus +# define NULL 0 +# else +# define NULL ((void *)0) +# endif +#endif + +# define BUFSIZ 8192 + +#define EOF (-1) + +__BEGIN_DECLS + +int _TLIBC_CDECL_ snprintf(char *, size_t, const char *, ...) _GCC_PRINTF_FORMAT_(3, 4); +int _TLIBC_CDECL_ vsnprintf(char *, size_t, const char *, __va_list) _GCC_PRINTF_FORMAT_(3, 0); + +/* + * Deprecated definitions. + */ +#if 0 /* No FILE */ +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, fprintf, FILE *, const char *, ...); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, putc, int, FILE *); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, fputc, int, FILE *); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, fputs, const char *, FILE *); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, fscanf, FILE *, const char *, ...); +_TLIBC_DEPRECATED_FUNCTION_(size_t _TLIBC_CDECL_, fwrite, const void *, size_t, size_t, FILE *); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, printf, const char *, ...); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, putchar, int); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, puts, const char *); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, scanf, const char *, ...); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, sprintf, char *, const char *, ...); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, sscanf, const char *, const char *, ...); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, vfprintf, FILE *, const char *, __va_list); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, vfscanf, FILE *, const char *, __va_list); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, vprintf, const char *, __va_list); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, vscanf, const char *, __va_list); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, vsprintf, char *, const char *, __va_list); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, vsscanf, const char *, const char *, __va_list); +#endif + +__END_DECLS + + +#endif /* !_STDIO_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/stdlib.h b/sgx-jvm/linux-sgx/common/inc/tlibc/stdlib.h new file mode 100644 index 0000000000..936042ec26 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/stdlib.h @@ -0,0 +1,164 @@ +/* $OpenBSD: stdlib.h,v 1.47 2010/05/18 22:24:55 tedu Exp $ */ +/* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */ + +/*- +* Copyright (c) 1990 The Regents of the University of California. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* 3. Neither the name of the University nor the names of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +* SUCH DAMAGE. +* +* @(#)stdlib.h 5.13 (Berkeley) 6/4/91 +*/ + +#ifndef _STDLIB_H_ +#define _STDLIB_H_ + +#include +#include + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#ifdef _TLIBC_WIN_ +#if !defined(_WCHAR_T_DEFINED) && !defined (_NATIVE_WCHAR_T_DEFINED) +#define _WCHAR_T_DEFINED +typedef unsigned short wchar_t; +#endif +#else +#if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus) +#define _WCHAR_T_DEFINED_ +#ifndef __WCHAR_TYPE__ +#define __WCHAR_TYPE__ int +#endif +typedef __WCHAR_TYPE__ wchar_t; +#endif +#endif + +#ifndef _DIV_T_DEFINED +typedef struct { + int quot; /* quotient */ + int rem; /* remainder */ +} div_t; + +typedef struct { + long quot; /* quotient */ + long rem; /* remainder */ +} ldiv_t; + +typedef struct { + long long quot; /* quotient */ + long long rem; /* remainder */ +} lldiv_t; +#define _DIV_T_DEFINED +#endif + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 + +#define RAND_MAX 0x7fffffff +#define MB_CUR_MAX 1 + +__BEGIN_DECLS + +_TLIBC_NORETURN_ void _TLIBC_CDECL_ abort(void); +int _TLIBC_CDECL_ abs(int); +double _TLIBC_CDECL_ atof(const char *); +int _TLIBC_CDECL_ atoi(const char *); +long _TLIBC_CDECL_ atol(const char *); +void * _TLIBC_CDECL_ bsearch(const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); +div_t _TLIBC_CDECL_ div(int, int); +void * _TLIBC_CDECL_ calloc(size_t, size_t); +void _TLIBC_CDECL_ free(void *); +void * _TLIBC_CDECL_ malloc(size_t); +void * _TLIBC_CDECL_ memalign(size_t, size_t); +void * _TLIBC_CDECL_ realloc(void *, size_t); +void * _TLIBC_CDECL_ __tlibc_calloc(size_t, size_t); +void _TLIBC_CDECL_ __tlibc_free(void *); +void * _TLIBC_CDECL_ __tlibc_malloc(size_t); +void * _TLIBC_CDECL_ __tlibc_memalign(size_t, size_t); +void * _TLIBC_CDECL_ __tlibc_realloc(void *, size_t); +long _TLIBC_CDECL_ labs(long); +ldiv_t _TLIBC_CDECL_ ldiv(long, long); +void _TLIBC_CDECL_ qsort(void *, size_t, size_t, int (*)(const void *, const void *)); +double _TLIBC_CDECL_ strtod(const char *, char **); +long _TLIBC_CDECL_ strtol(const char *, char **, int); +float _TLIBC_CDECL_ strtof(const char *, char **); + +long long + _TLIBC_CDECL_ atoll(const char *); +long long + _TLIBC_CDECL_ llabs(long long); +lldiv_t + _TLIBC_CDECL_ lldiv(long long, long long); +long long + _TLIBC_CDECL_ strtoll(const char *, char **, int); +unsigned long + _TLIBC_CDECL_ strtoul(const char *, char **, int); +long double + _TLIBC_CDECL_ strtold(const char *, char **); +unsigned long long + _TLIBC_CDECL_ strtoull(const char *, char **, int); + +int _TLIBC_CDECL_ mblen(const char *, size_t); +size_t _TLIBC_CDECL_ mbstowcs(wchar_t *, const char *, size_t); +int _TLIBC_CDECL_ wctomb(char *, wchar_t); +int _TLIBC_CDECL_ mbtowc(wchar_t *, const char *, size_t); +size_t _TLIBC_CDECL_ wcstombs(char *, const wchar_t *, size_t); + + +/* + * Deprecated C99. + */ +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, atexit, void (_TLIBC_CDECL_ *)(void)); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, rand, void); +_TLIBC_DEPRECATED_FUNCTION_(void _TLIBC_CDECL_, srand, unsigned); +_TLIBC_DEPRECATED_FUNCTION_(void _TLIBC_CDECL_, exit, int); +_TLIBC_DEPRECATED_FUNCTION_(void _TLIBC_CDECL_, _Exit, int); +_TLIBC_DEPRECATED_FUNCTION_(char * _TLIBC_CDECL_, getenv, const char *); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, system, const char *); + +/* + * Non-C99 Functions. + */ +void * _TLIBC_CDECL_ alloca(size_t); + +/* + * Deprecated Non-C99. + */ +//_TLIBC_DEPRECATED_FUNCTION_(void _TLIBC_CDECL_, _exit, int); + +__END_DECLS + +#endif /* !_STDLIB_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/string.h b/sgx-jvm/linux-sgx/common/inc/tlibc/string.h new file mode 100644 index 0000000000..c8e458f477 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/string.h @@ -0,0 +1,125 @@ +/* $OpenBSD: string.h,v 1.20 2010/09/24 13:33:00 matthew Exp $ */ +/* $NetBSD: string.h,v 1.6 1994/10/26 00:56:30 cgd Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)string.h 5.10 (Berkeley) 3/9/91 + */ + +#ifndef _STRING_H_ +#define _STRING_H_ + +#include +#include + +#ifndef _SIZE_T_DEFINED_ +typedef __size_t size_t; +#define _SIZE_T_DEFINED_ +#endif + +#ifndef _ERRNO_T_DEFINED +#define _ERRNO_T_DEFINED +typedef int errno_t; +#endif + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +__BEGIN_DECLS + +void * _TLIBC_CDECL_ memchr(const void *, int, size_t); +int _TLIBC_CDECL_ memcmp(const void *, const void *, size_t); +void * _TLIBC_CDECL_ memcpy(void *, const void *, size_t); +void * _TLIBC_CDECL_ memmove(void *, const void *, size_t); +void * _TLIBC_CDECL_ memset(void *, int, size_t); +char * _TLIBC_CDECL_ strchr(const char *, int); +int _TLIBC_CDECL_ strcmp(const char *, const char *); +int _TLIBC_CDECL_ strcoll(const char *, const char *); +size_t _TLIBC_CDECL_ strcspn(const char *, const char *); +char * _TLIBC_CDECL_ strerror(int); +size_t _TLIBC_CDECL_ strlen(const char *); +char * _TLIBC_CDECL_ strncat(char *, const char *, size_t); +int _TLIBC_CDECL_ strncmp(const char *, const char *, size_t); +char * _TLIBC_CDECL_ strncpy(char *, const char *, size_t); +char * _TLIBC_CDECL_ strpbrk(const char *, const char *); +char * _TLIBC_CDECL_ strrchr(const char *, int); +size_t _TLIBC_CDECL_ strspn(const char *, const char *); +char * _TLIBC_CDECL_ strstr(const char *, const char *); +char * _TLIBC_CDECL_ strtok(char *, const char *); +size_t _TLIBC_CDECL_ strxfrm(char *, const char *, size_t); +size_t _TLIBC_CDECL_ strlcpy(char *, const char *, size_t); +errno_t _TLIBC_CDECL_ memset_s(void *s, size_t smax, int c, size_t n); + +/* + * Deprecated C99. + */ +_TLIBC_DEPRECATED_FUNCTION_(char * _TLIBC_CDECL_, strcat, char *, const char *); +_TLIBC_DEPRECATED_FUNCTION_(char * _TLIBC_CDECL_, strcpy, char *, const char *); + +/* + * Common used non-C99 functions. + */ +char * _TLIBC_CDECL_ strndup(const char *, size_t); +size_t _TLIBC_CDECL_ strnlen(const char *, size_t); +int _TLIBC_CDECL_ consttime_memequal(const void *b1, const void *b2, size_t len); + +/* + * Non-C99 + */ +int _TLIBC_CDECL_ bcmp(const void *, const void *, size_t); +void _TLIBC_CDECL_ bcopy(const void *, void *, size_t); +void _TLIBC_CDECL_ bzero(void *, size_t); +char * _TLIBC_CDECL_ index(const char *, int); +void * _TLIBC_CDECL_ mempcpy(void *, const void *, size_t); +char * _TLIBC_CDECL_ rindex(const char *, int); +char * _TLIBC_CDECL_ stpncpy(char *dest, const char *src, size_t n); +int _TLIBC_CDECL_ strcasecmp(const char *, const char *); +int _TLIBC_CDECL_ strncasecmp(const char *, const char *, size_t); + +int _TLIBC_CDECL_ ffs(int); +int _TLIBC_CDECL_ ffsl(long int); +int _TLIBC_CDECL_ ffsll(long long int); + +char * _TLIBC_CDECL_ strtok_r(char *, const char *, char **); +int _TLIBC_CDECL_ strerror_r(int, char *, size_t); + +/* + * Deprecated Non-C99. + */ +_TLIBC_DEPRECATED_FUNCTION_(char * _TLIBC_CDECL_, strdup, const char *); +_TLIBC_DEPRECATED_FUNCTION_(char * _TLIBC_CDECL_, stpcpy, char *dest, const char *src); + +__END_DECLS + +#endif /* _STRING_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/sys/_types.h b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/_types.h new file mode 100644 index 0000000000..b1b315c7ed --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/_types.h @@ -0,0 +1,133 @@ +/* $OpenBSD: _types.h,v 1.2 2008/03/16 19:42:57 otto Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)types.h 8.3 (Berkeley) 1/5/94 + */ + +#ifndef _SYS__TYPES_H_ +#define _SYS__TYPES_H_ + +#include +/* 7.18.1.1 Exact-width integer types */ +typedef signed char __int8_t; +typedef unsigned char __uint8_t; +typedef short __int16_t; +typedef unsigned short __uint16_t; +typedef int __int32_t; +typedef unsigned int __uint32_t; +typedef long long __int64_t; +typedef unsigned long long __uint64_t; + +/* 7.18.1.2 Minimum-width integer types */ +typedef __int8_t __int_least8_t; +typedef __uint8_t __uint_least8_t; +typedef __int16_t __int_least16_t; +typedef __uint16_t __uint_least16_t; +typedef __int32_t __int_least32_t; +typedef __uint32_t __uint_least32_t; +typedef __int64_t __int_least64_t; +typedef __uint64_t __uint_least64_t; + +/* 7.18.1.3 Fastest minimum-width integer types */ +typedef __int8_t __int_fast8_t; +typedef __uint8_t __uint_fast8_t; +#ifdef __x86_64__ +/* Linux x86_64, from stdint.h */ +typedef long int __int_fast16_t; +typedef unsigned long int __uint_fast16_t; +typedef long int __int_fast32_t; +typedef unsigned long int __uint_fast32_t; +typedef long int __int_fast64_t; +typedef unsigned long int __uint_fast64_t; +#else +/* Android x86, and Linux x86 */ +typedef __int32_t __int_fast16_t; +typedef __uint32_t __uint_fast16_t; +typedef __int32_t __int_fast32_t; +typedef __uint32_t __uint_fast32_t; +typedef __int64_t __int_fast64_t; +typedef __uint64_t __uint_fast64_t; +#endif + +typedef long __off_t; + +/* 7.18.1.4 Integer types capable of holding object pointers */ +#ifdef __i386__ +typedef __int32_t __intptr_t; +typedef __uint32_t __uintptr_t; +typedef __int32_t __ptrdiff_t; +/* Standard system types */ +typedef __uint32_t __size_t; +typedef __int32_t __ssize_t; +typedef long double __double_t; +typedef long double __float_t; +#else +typedef __int64_t __intptr_t; +typedef __uint64_t __uintptr_t; +typedef __int64_t __ptrdiff_t; + +/* Standard system types */ +typedef unsigned long __size_t; +typedef long __ssize_t; +typedef double __double_t; +typedef float __float_t; + +#endif /* !__i386__ */ + +typedef long __clock_t; + +typedef long __time_t; +typedef __builtin_va_list __va_list; +typedef int __wint_t; +/* wctype_t and wctrans_t are defined in wchar.h */ +typedef unsigned long int __wctype_t; +typedef int * __wctrans_t; + +/* + * mbstate_t is an opaque object to keep conversion state, during multibyte + * stream conversions. The content must not be referenced by user programs. + */ +/* For Linux, __mbstate_t is defined in wchar.h */ +typedef struct { + int __c; + union { + __wint_t __wc; + char __wcb[4]; + } __v; +} __mbstate_t; + +/* 7.18.1.5 Greatest-width integer types */ +typedef __int64_t __intmax_t; +typedef __uint64_t __uintmax_t; + +#endif /* !_SYS__TYPES_H_ */ + + + diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/sys/cdefs.h b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/cdefs.h new file mode 100644 index 0000000000..398a12bbc7 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/cdefs.h @@ -0,0 +1,132 @@ +/* $OpenBSD: cdefs.h,v 1.34 2012/08/14 20:11:37 matthew Exp $ */ +/* $NetBSD: cdefs.h,v 1.16 1996/04/03 20:46:39 christos Exp $ */ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Berkeley Software Design, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)cdefs.h 8.7 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_CDEFS_H_ +#define _SYS_CDEFS_H_ + +/* Declaration field in C/C++ headers */ +#if defined(__cplusplus) +# define __BEGIN_DECLS extern "C" { +# define __END_DECLS } +#else +# define __BEGIN_DECLS +# define __END_DECLS +#endif + +#if defined(__STDC__) || defined(__cplusplus) +# define __CONCAT(x,y) x ## y +# define __STRING(x) #x +#else +# define __CONCAT(x,y) x/**/y +# define __STRING(x) "x" +#endif +/* + * Macro to test if we're using a specific version of gcc or later. + */ +#if defined __GNUC__ && defined __GNUC_MINOR_ +# define __GNUC_PREREQ__(ma, mi) \ + ((__GNUC__ > (ma)) || (__GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))) +#else +# define __GNUC_PREREQ__(ma, mi) 0 +#endif + +/* Calling Convention: cdecl */ +#define _TLIBC_CDECL_ + +/* Thread Directive */ +#define _TLIBC_THREAD_ /* __thread */ + +/* Deprecated Warnings */ +#define _TLIBC_DEPRECATED_MSG(x) __STRING(x)" is deprecated in tlibc." +#define _TLIBC_DEPRECATED_(x) __attribute__((deprecated(_TLIBC_DEPRECATED_MSG(x)))) + +#ifndef _TLIBC_WARN_DEPRECATED_FUNCTIONS_ +# define _TLIBC_DEPRECATED_FUNCTION_(__ret, __func, ...) +#else +# define _TLIBC_DEPRECATED_FUNCTION_(__ret, __func, ...) \ + _TLIBC_DEPRECATED_(__func) \ + __ret __func(__VA_ARGS__) +#endif + +/* Static analysis for printf format strings. + * _MSC_PRINTF_FORMAT_: MSVC SAL annotation for specifying format strings. + * _GCC_PRINTF_FORMAT_(x, y): GCC declaring attribute for checking format strings. + * x - index of the format string. In C++ non-static method, index 1 is reseved for 'this'. + * y - index of first variadic agrument in '...'. + */ +#define _GCC_PRINTF_FORMAT_(x, y) __attribute__((__format__ (printf, x, y))) + +/* Attribute - noreturn */ +#define _TLIBC_NORETURN_ __attribute__ ((__noreturn__)) + +/* + * GNU C version 2.96 adds explicit branch prediction so that + * the CPU back-end can hint the processor and also so that + * code blocks can be reordered such that the predicted path + * sees a more linear flow, thus improving cache behavior, etc. + * + * The following two macros provide us with a way to utilize this + * compiler feature. Use __predict_true() if you expect the expression + * to evaluate to true, and __predict_false() if you expect the + * expression to evaluate to false. + * + * A few notes about usage: + * + * * Generally, __predict_false() error condition checks (unless + * you have some _strong_ reason to do otherwise, in which case + * document it), and/or __predict_true() `no-error' condition + * checks, assuming you want to optimize for the no-error case. + * + * * Other than that, if you don't know the likelihood of a test + * succeeding from empirical or other `hard' evidence, don't + * make predictions. + * + * * These are meant to be used in places that are run `a lot'. + * It is wasteful to make predictions in code that is run + * seldomly (e.g. at subsystem initialization time) as the + * basic block reordering that this affects can often generate + * larger code. + */ +#if defined(__GNUC__) && __GNUC_PREREQ__(2, 96) +#define __predict_true(exp) __builtin_expect(((exp) != 0), 1) +#define __predict_false(exp) __builtin_expect(((exp) != 0), 0) +#else +#define __predict_true(exp) ((exp) != 0) +#define __predict_false(exp) ((exp) != 0) +#endif + +#endif /* !_SYS_CDEFS_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/sys/endian.h b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/endian.h new file mode 100644 index 0000000000..29edd81c5c --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/endian.h @@ -0,0 +1,54 @@ +/* $OpenBSD: endian.h,v 1.18 2006/03/27 07:09:24 otto Exp $ */ + +/*- + * Copyright (c) 1997 Niklas Hallqvist. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Generic definitions for little- and big-endian systems. Other endianesses + * has to be dealt with in the specific machine/endian.h file for that port. + * + * This file is meant to be included from a little- or big-endian port's + * machine/endian.h after setting _BYTE_ORDER to either 1234 for little endian + * or 4321 for big.. + */ + +#ifndef _SYS_ENDIAN_H_ +#define _SYS_ENDIAN_H_ + +#define _LITTLE_ENDIAN 1234 +#define _BIG_ENDIAN 4321 +#define _PDP_ENDIAN 3412 +#define _BYTE_ORDER _LITTLE_ENDIAN + +#define LITTLE_ENDIAN _LITTLE_ENDIAN +#define BIG_ENDIAN _BIG_ENDIAN +#define PDP_ENDIAN _PDP_ENDIAN +#define BYTE_ORDER _BYTE_ORDER + +#define __BYTE_ORDER _BYTE_ORDER +#define __BIG_ENDIAN _BIG_ENDIAN +#define __LITTLE_ENDIAN _LITTLE_ENDIAN + +#endif /* _SYS_ENDIAN_H_ */ + diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/sys/ieee.h b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/ieee.h new file mode 100644 index 0000000000..8370cd8295 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/ieee.h @@ -0,0 +1,145 @@ +/* $OpenBSD: ieee.h,v 1.2 2008/09/07 20:36:06 martynas Exp $ */ +/* $NetBSD: ieee.h,v 1.1 1996/09/30 16:34:25 ws Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Lawrence Berkeley Laboratory. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ + +#include + +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS 64 + +#define EXT_TO_ARRAY32(p, a) do { \ + (a)[0] = (uint32_t)(p)->ext_fracl; \ + (a)[1] = (uint32_t)(p)->ext_frach; \ +} while(0) + +struct ieee_single { + u_int sng_frac:23; + u_int sng_exp:8; + u_int sng_sign:1; +}; + +struct ieee_double { + u_int dbl_fracl; + u_int dbl_frach:20; + u_int dbl_exp:11; + u_int dbl_sign:1; +}; + +struct ieee_ext { + u_int ext_fracl; + u_int ext_frach; + u_int ext_exp:15; + u_int ext_sign:1; + u_int ext_padl:16; + u_int ext_padh; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 +#define EXT_EXP_INFNAN 32767 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#define EXT_QUIETNAN (1 << 15) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 +#define EXT_EXP_BIAS 16383 diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/sys/limits.h b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/limits.h new file mode 100644 index 0000000000..3d1f9673ad --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/limits.h @@ -0,0 +1,77 @@ +/* $OpenBSD: limits.h,v 1.8 2009/11/27 19:54:35 guenther Exp $ */ +/* + * Copyright (c) 2002 Marc Espie. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD + * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _SYS_LIMITS_H_ +#define _SYS_LIMITS_H_ + +#include + +/* Common definitions for limits.h. */ + +#define CHAR_BIT 8 /* number of bits in a char */ + +#define SCHAR_MAX 0x7f /* max value for a signed char */ +#define SCHAR_MIN (-0x7f - 1) /* min value for a signed char */ + +#define UCHAR_MAX 0xff /* max value for an unsigned char */ +#ifdef __CHAR_UNSIGNED__ +# define CHAR_MIN 0 /* min value for a char */ +# define CHAR_MAX 0xff /* max value for a char */ +#else +# define CHAR_MAX 0x7f +# define CHAR_MIN (-0x7f-1) +#endif + +#define MB_LEN_MAX 1 /* Allow UTF-8 (RFC 3629) */ + +#define USHRT_MAX 0xffff /* max value for an unsigned short */ +#define SHRT_MAX 0x7fff /* max value for a short */ +#define SHRT_MIN (-0x7fff-1) /* min value for a short */ + +#define UINT_MAX 0xffffffffU /* max value for an unsigned int */ +#define INT_MAX 0x7fffffff /* max value for an int */ +#define INT_MIN (-0x7fffffff-1) /* min value for an int */ + +#ifdef __x86_64__ +# define ULONG_MAX 0xffffffffffffffffUL /* max value for unsigned long */ +# define LONG_MAX 0x7fffffffffffffffL /* max value for a signed long */ +# define LONG_MIN (-0x7fffffffffffffffL-1) /* min value for a signed long */ +#else +# define ULONG_MAX 0xffffffffUL /* max value for an unsigned long */ +# define LONG_MAX 0x7fffffffL /* max value for a long */ +# define LONG_MIN (-0x7fffffffL-1) /* min value for a long */ +#endif + +#define ULLONG_MAX 0xffffffffffffffffULL /* max value for unsigned long long */ +#define LLONG_MAX 0x7fffffffffffffffLL /* max value for a signed long long */ +#define LLONG_MIN (-0x7fffffffffffffffLL-1) /* min value for a signed long long */ + +#ifdef __x86_64__ +# define LONG_BIT 64 +#else +# define LONG_BIT 32 +#endif + +#endif /* !_SYS_LIMITS_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/sys/stdint.h b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/stdint.h new file mode 100644 index 0000000000..b76cc52ed8 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/stdint.h @@ -0,0 +1,253 @@ +/* $OpenBSD: stdint.h,v 1.4 2006/12/10 22:17:55 deraadt Exp $ */ + +/* + * Copyright (c) 1997, 2005 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _SYS_STDINT_H_ +#define _SYS_STDINT_H_ + +#include +#include + +/* 7.18.1.1 Exact-width integer types (also in sys/types.h) */ +#ifndef _INT8_T_DEFINED_ +#define _INT8_T_DEFINED_ +typedef __int8_t int8_t; +#endif + +#ifndef _UINT8_T_DEFINED_ +#define _UINT8_T_DEFINED_ +typedef __uint8_t uint8_t; +#endif + +#ifndef _INT16_T_DEFINED_ +#define _INT16_T_DEFINED_ +typedef __int16_t int16_t; +#endif + +#ifndef _UINT16_T_DEFINED_ +#define _UINT16_T_DEFINED_ +typedef __uint16_t uint16_t; +#endif + +#ifndef _INT32_T_DEFINED_ +#define _INT32_T_DEFINED_ +typedef __int32_t int32_t; +#endif + +#ifndef _UINT32_T_DEFINED_ +#define _UINT32_T_DEFINED_ +typedef __uint32_t uint32_t; +#endif + +#ifndef _INT64_T_DEFINED_ +#define _INT64_T_DEFINED_ +typedef __int64_t int64_t; +#endif + +#ifndef _UINT64_T_DEFINED_ +#define _UINT64_T_DEFINED_ +typedef __uint64_t uint64_t; +#endif + +/* 7.18.1.2 Minimum-width integer types */ +typedef __int_least8_t int_least8_t; +typedef __uint_least8_t uint_least8_t; +typedef __int_least16_t int_least16_t; +typedef __uint_least16_t uint_least16_t; +typedef __int_least32_t int_least32_t; +typedef __uint_least32_t uint_least32_t; +typedef __int_least64_t int_least64_t; +typedef __uint_least64_t uint_least64_t; + +/* 7.18.1.3 Fastest minimum-width integer types */ +typedef __int_fast8_t int_fast8_t; +typedef __uint_fast8_t uint_fast8_t; +typedef __int_fast16_t int_fast16_t; +typedef __uint_fast16_t uint_fast16_t; +typedef __int_fast32_t int_fast32_t; +typedef __uint_fast32_t uint_fast32_t; +typedef __int_fast64_t int_fast64_t; +typedef __uint_fast64_t uint_fast64_t; + +/* 7.18.1.4 Integer types capable of holding object pointers */ +#ifndef _INTPTR_T_DEFINED_ +#define _INTPTR_T_DEFINED_ +typedef __intptr_t intptr_t; +#endif + +#ifndef _UINTPTR_T_DEFINED_ +#define _UINTPTR_T_DEFINED_ +typedef __uintptr_t uintptr_t; +#endif + +/* 7.18.1.5 Greatest-width integer types */ +typedef __intmax_t intmax_t; +typedef __uintmax_t uintmax_t; + +//#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) +/* + * 7.18.2 Limits of specified-width integer types. + * + * The following object-like macros specify the minimum and maximum limits + * of integer types corresponding to the typedef names defined above. + */ + +/* 7.18.2.1 Limits of exact-width integer types */ +#define INT8_MIN (-0x7f - 1) +#define INT16_MIN (-0x7fff - 1) +#define INT32_MIN (-0x7fffffff - 1) +#define INT64_MIN (-0x7fffffffffffffffLL - 1) + +#define INT8_MAX 0x7f +#define INT16_MAX 0x7fff +#define INT32_MAX 0x7fffffff +#define INT64_MAX 0x7fffffffffffffffLL + +#define UINT8_MAX 0xff +#define UINT16_MAX 0xffff +#define UINT32_MAX 0xffffffffU +#define UINT64_MAX 0xffffffffffffffffULL + +/* 7.18.2.2 Limits of minimum-width integer types */ +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST64_MIN INT64_MIN + +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MAX INT64_MAX + +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +/* 7.18.2.3 Limits of fastest minimum-width integer types */ +#define INT_FAST8_MIN INT8_MIN +#define INT_FAST16_MIN INT16_MIN +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST64_MIN INT64_MIN + +#define INT_FAST8_MAX INT8_MAX +#ifdef __x86_64__ +#define INT_FAST16_MAX INT64_MAX +#define INT_FAST32_MAX INT64_MAX +#else +#define INT_FAST16_MAX INT32_MAX +#define INT_FAST32_MAX INT32_MAX +#endif +#define INT_FAST64_MAX INT64_MAX + +#define UINT_FAST8_MAX UINT8_MAX +#ifdef __x86_64__ +#define UINT_FAST16_MAX UINT64_MAX +#define UINT_FAST32_MAX UINT64_MAX +#else +#define UINT_FAST16_MAX UINT32_MAX +#define UINT_FAST32_MAX UINT32_MAX +#endif +#define UINT_FAST64_MAX UINT64_MAX + +/* 7.18.2.4 Limits of integer types capable of holding object pointers */ +#ifdef __x86_64__ +#define INTPTR_MIN INT64_MIN +#define INTPTR_MAX INT64_MAX +#define UINTPTR_MAX UINT64_MAX +#else +#define INTPTR_MIN INT32_MIN +#define INTPTR_MAX INT32_MAX +#define UINTPTR_MAX UINT32_MAX +#endif + +/* 7.18.2.5 Limits of greatest-width integer types */ +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +/* + * 7.18.3 Limits of other integer types. + * + * The following object-like macros specify the minimum and maximum limits + * of integer types corresponding to types specified in other standard + * header files. + */ + +/* Limits of ptrdiff_t */ +#define PTRDIFF_MIN INTPTR_MIN +#define PTRDIFF_MAX INTPTR_MAX + +/* Limits of size_t (also in limits.h) */ +#ifndef SIZE_MAX +#define SIZE_MAX UINTPTR_MAX +#endif + +/* Limits of wchar_t */ +#ifdef _TLIBC_WIN_ +# define WCHAR_MIN 0x0000 +# define WCHAR_MAX 0xffff +#else +# ifdef __WCHAR_MAX__ +# define WCHAR_MAX __WCHAR_MAX__ +# else +# define WCHAR_MAX (2147483647) +# endif +# ifdef __WCHAR_MIN__ +# define WCHAR_MIN __WCHAR_MIN__ +# elif L'\0' - 1 > 0 +# define WCHAR_MIN L'\0' +# else +# define WCHAR_MIN (-WCHAR_MAX - 1) +# endif +#endif + +/* Limits of wint_t */ +# define WINT_MIN (0u) +# define WINT_MAX (4294967295u) + +//#endif /* __cplusplus || __STDC_LIMIT_MACROS */ + +//#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) +/* + * 7.18.4 Macros for integer constants. + * + * The following function-like macros expand to integer constants + * suitable for initializing objects that have integer types corresponding + * to types defined in . The argument in any instance of + * these macros shall be a decimal, octal, or hexadecimal constant with + * a value that does not exceed the limits for the corresponding type. + */ + +/* 7.18.4.1 Macros for minimum-width integer constants. */ +#define INT8_C(_c) (_c) +#define INT16_C(_c) (_c) +#define INT32_C(_c) (_c) +#define INT64_C(_c) __CONCAT(_c, LL) + +#define UINT8_C(_c) (_c) +#define UINT16_C(_c) (_c) +#define UINT32_C(_c) __CONCAT(_c, U) +#define UINT64_C(_c) __CONCAT(_c, ULL) + +/* 7.18.4.2 Macros for greatest-width integer constants. */ +#define INTMAX_C(_c) __CONCAT(_c, LL) +#define UINTMAX_C(_c) __CONCAT(_c, ULL) + +//#endif /* __cplusplus || __STDC_CONSTANT_MACROS */ + +#endif /* _SYS_STDINT_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/sys/types.h b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/types.h new file mode 100644 index 0000000000..474f3e93d9 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/sys/types.h @@ -0,0 +1,128 @@ +/* $OpenBSD: types.h,v 1.31 2008/03/16 19:42:57 otto Exp $ */ +/* $NetBSD: types.h,v 1.29 1996/11/15 22:48:25 jtc Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)types.h 8.4 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_TYPES_H_ +#define _SYS_TYPES_H_ + +#include +#include + +typedef unsigned char u_char; +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; + +typedef unsigned char unchar; /* Sys V compatibility */ +typedef unsigned short ushort; /* Sys V compatibility */ +typedef unsigned int uint; /* Sys V compatibility */ +typedef unsigned long ulong; /* Sys V compatibility */ + +#ifndef _INT8_T_DEFINED_ +#define _INT8_T_DEFINED_ +typedef __int8_t int8_t; +#endif + +#ifndef _UINT8_T_DEFINED_ +#define _UINT8_T_DEFINED_ +typedef __uint8_t uint8_t; +#endif + +#ifndef _INT16_T_DEFINED_ +#define _INT16_T_DEFINED_ +typedef __int16_t int16_t; +#endif + +#ifndef _UINT16_T_DEFINED_ +#define _UINT16_T_DEFINED_ +typedef __uint16_t uint16_t; +#endif + +#ifndef _INT32_T_DEFINED_ +#define _INT32_T_DEFINED_ +typedef __int32_t int32_t; +#endif + +#ifndef _UINT32_T_DEFINED_ +#define _UINT32_T_DEFINED_ +typedef __uint32_t uint32_t; +#endif + +#ifndef _INT64_T_DEFINED_ +#define _INT64_T_DEFINED_ +typedef __int64_t int64_t; +#endif + +#ifndef _UINT64_T_DEFINED_ +#define _UINT64_T_DEFINED_ +typedef __uint64_t uint64_t; +#endif + +#ifndef _INTPTR_T_DEFINED_ +#define _INTPTR_T_DEFINED_ +typedef __intptr_t intptr_t; +#endif + +#ifndef _UINTPTR_T_DEFINED_ +#define _UINTPTR_T_DEFINED_ +typedef __uintptr_t uintptr_t; +#endif + +/* BSD-style unsigned bits types */ +typedef __uint8_t u_int8_t; +typedef __uint16_t u_int16_t; +typedef __uint32_t u_int32_t; +typedef __uint64_t u_int64_t; + + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#ifndef _SSIZE_T_DEFINED_ +#define _SSIZE_T_DEFINED_ +typedef __ssize_t ssize_t; +#endif + +#ifndef _OFF_T_DEFINED_ +#define _OFF_T_DEFINED_ +typedef __off_t off_t; +#endif + +#endif /* !_SYS_TYPES_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/time.h b/sgx-jvm/linux-sgx/common/inc/tlibc/time.h new file mode 100644 index 0000000000..3880d3e9ac --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/time.h @@ -0,0 +1,104 @@ +/* $OpenBSD: time.h,v 1.18 2006/01/06 18:53:04 millert Exp $ */ +/* $NetBSD: time.h,v 1.9 1994/10/26 00:56:35 cgd Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)time.h 5.12 (Berkeley) 3/9/91 + */ + +#ifndef _TIME_H_ +#define _TIME_H_ + +#include +#include + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if !defined (_CLOCK_T_DEFINED_) && !defined (_CLOCK_T_DEFINED) +#define _CLOCK_T_DEFINED_ +#define _CLOCK_T_DEFINED +typedef __clock_t clock_t; +#endif + +#if !defined (_TIME_T_DEFINED_) && !defined (_TIME_T_DEFINED) +#define _TIME_T_DEFINED_ +#define _TIME_T_DEFINED +typedef __time_t time_t; +#endif + +#if !defined (_SIZE_T_DEFINED_) && !defined (_SIZE_T_DEFINED) +#define _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED +typedef __size_t size_t; +#endif + +#if !defined (_TM_DEFINED) +#define _TM_DEFINED +struct tm { + int tm_sec; /* seconds after the minute [0-60] */ + int tm_min; /* minutes after the hour [0-59] */ + int tm_hour; /* hours since midnight [0-23] */ + int tm_mday; /* day of the month [1-31] */ + int tm_mon; /* months since January [0-11] */ + int tm_year; /* years since 1900 */ + int tm_wday; /* days since Sunday [0-6] */ + int tm_yday; /* days since January 1 [0-365] */ + int tm_isdst; /* Daylight Saving Time flag */ + /* FIXME: naming issue exists on Fedora/Ubuntu */ + long tm_gmtoff; /* offset from UTC in seconds */ + char *tm_zone; /* timezone abbreviation */ +}; +#endif + +__BEGIN_DECLS + +double _TLIBC_CDECL_ difftime(time_t, time_t); +char * _TLIBC_CDECL_ asctime(const struct tm *); +size_t _TLIBC_CDECL_ strftime(char *, size_t, const char *, const struct tm *); + +/* + * Non-C99 + */ +char * _TLIBC_CDECL_ asctime_r(const struct tm *, char *); + +__END_DECLS + +#endif /* !_TIME_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/unistd.h b/sgx-jvm/linux-sgx/common/inc/tlibc/unistd.h new file mode 100644 index 0000000000..2958a6ccc6 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/unistd.h @@ -0,0 +1,59 @@ +/* $OpenBSD: unistd.h,v 1.62 2008/06/25 14:58:54 millert Exp $ */ +/* $NetBSD: unistd.h,v 1.26.4.1 1996/05/28 02:31:51 mrg Exp $ */ + +/*- + * Copyright (c) 1991 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)unistd.h 5.13 (Berkeley) 6/17/91 + */ + +#ifndef _UNISTD_H_ +#define _UNISTD_H_ + +#include +#include + +__BEGIN_DECLS + +void * _TLIBC_CDECL_ sbrk(intptr_t); + +/* + * Deprecated Non-C99. + */ +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, execl, const char *, const char *, ...); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, execlp, const char *, const char *, ...); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, execle, const char *, const char *, ...); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, execv, const char *, char * const *); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, execve, const char *, char * const *, char * const *); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, execvp, const char *, char * const *); + +//_TLIBC_DEPRECATED_FUNCTION_(pid_t _TLIBC_CDECL_, fork, void); /* no pid_t */ + +__END_DECLS + +#endif /* !_UNISTD_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/wchar.h b/sgx-jvm/linux-sgx/common/inc/tlibc/wchar.h new file mode 100644 index 0000000000..4ca0b39f40 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/wchar.h @@ -0,0 +1,139 @@ +/* $OpenBSD: wchar.h,v 1.11 2010/07/24 09:58:39 guenther Exp $ */ +/* $NetBSD: wchar.h,v 1.16 2003/03/07 07:11:35 tshiozak Exp $ */ + +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_H_ +#define _WCHAR_H_ + +#include +#include +#include /* WCHAR_MAX/WCHAR_MIN */ + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus) +#define _WCHAR_T_DEFINED_ +#ifndef __WCHAR_TYPE__ +#define __WCHAR_TYPE__ int +#endif +typedef __WCHAR_TYPE__ wchar_t; +#endif + +#ifndef _MBSTATE_T_DEFINED_ +#define _MBSTATE_T_DEFINED_ +typedef __mbstate_t mbstate_t; +#endif + +#ifndef _WINT_T_DEFINED_ +#define _WINT_T_DEFINED_ +typedef __wint_t wint_t; +#endif + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#ifndef WEOF +#define WEOF ((wint_t)-1) +#endif + +__BEGIN_DECLS + +wint_t _TLIBC_CDECL_ btowc(int); +int _TLIBC_CDECL_ wctob(wint_t); +size_t _TLIBC_CDECL_ mbrlen(const char *, size_t, mbstate_t *); +size_t _TLIBC_CDECL_ mbrtowc(wchar_t *, const char *, size_t, mbstate_t *); +int _TLIBC_CDECL_ mbsinit(const mbstate_t *); +size_t _TLIBC_CDECL_ mbsrtowcs(wchar_t *, const char **, size_t, mbstate_t *); +size_t _TLIBC_CDECL_ wcrtomb(char *, wchar_t, mbstate_t *); +wchar_t * _TLIBC_CDECL_ wcschr(const wchar_t *, wchar_t); +int _TLIBC_CDECL_ wcscmp(const wchar_t *, const wchar_t *); +int _TLIBC_CDECL_ wcscoll(const wchar_t *, const wchar_t *); +size_t _TLIBC_CDECL_ wcscspn(const wchar_t *, const wchar_t *); +size_t _TLIBC_CDECL_ wcslen(const wchar_t *); +wchar_t * _TLIBC_CDECL_ wcsncat(wchar_t *, const wchar_t *, size_t); +int _TLIBC_CDECL_ wcsncmp(const wchar_t *, const wchar_t *, size_t); +wchar_t * _TLIBC_CDECL_ wcsncpy(wchar_t *, const wchar_t *, size_t); +wchar_t * _TLIBC_CDECL_ wcspbrk(const wchar_t *, const wchar_t *); +wchar_t * _TLIBC_CDECL_ wcsrchr(const wchar_t *, wchar_t); +size_t _TLIBC_CDECL_ wcsrtombs(char *, const wchar_t **, size_t, mbstate_t *); +size_t _TLIBC_CDECL_ wcsspn(const wchar_t *, const wchar_t *); +wchar_t * _TLIBC_CDECL_ wcsstr(const wchar_t *, const wchar_t *); +wchar_t * _TLIBC_CDECL_ wcstok(wchar_t *, const wchar_t *, wchar_t **); +size_t _TLIBC_CDECL_ wcsxfrm(wchar_t *, const wchar_t *, size_t); +wchar_t * _TLIBC_CDECL_ wmemchr(const wchar_t *, wchar_t, size_t); +int _TLIBC_CDECL_ wmemcmp(const wchar_t *, const wchar_t *, size_t); +wchar_t * _TLIBC_CDECL_ wmemcpy(wchar_t *, const wchar_t *, size_t); +wchar_t * _TLIBC_CDECL_ wmemmove(wchar_t *, const wchar_t *, size_t); +wchar_t * _TLIBC_CDECL_ wmemset(wchar_t *, wchar_t, size_t); + +int _TLIBC_CDECL_ swprintf(wchar_t *, size_t, const wchar_t *, ...); +int _TLIBC_CDECL_ vswprintf(wchar_t *, size_t, const wchar_t *, __va_list); + +/* leagcy version of wcsstr */ +wchar_t * _TLIBC_CDECL_ wcswcs(const wchar_t *, const wchar_t *); + +__END_DECLS + +#endif /* !_WCHAR_H_ */ diff --git a/sgx-jvm/linux-sgx/common/inc/tlibc/wctype.h b/sgx-jvm/linux-sgx/common/inc/tlibc/wctype.h new file mode 100644 index 0000000000..25466f15d1 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/inc/tlibc/wctype.h @@ -0,0 +1,83 @@ +/* $OpenBSD: wctype.h,v 1.5 2006/01/06 18:53:04 millert Exp $ */ +/* $NetBSD: wctype.h,v 1.5 2003/03/02 22:18:11 tshiozak Exp $ */ + +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * citrus Id: wctype.h,v 1.4 2000/12/21 01:50:21 itojun Exp + */ + +#ifndef _WCTYPE_H_ +#define _WCTYPE_H_ + +#include +#include + +#ifndef _WINT_T_DEFINED_ +#define _WINT_T_DEFINED_ +typedef __wint_t wint_t; +#endif + +#ifndef _WCTRANS_T_DEFINED_ +#define _WCTRANS_T_DEFINED_ +typedef __wctrans_t wctrans_t; +#endif + +#ifndef _WCTYPE_T_DEFINED_ +#define _WCTYPE_T_DEFINED_ +typedef __wctype_t wctype_t; +#endif + +#ifndef WEOF +#define WEOF ((wint_t)-1) +#endif + +__BEGIN_DECLS + +/* + * Deprecated definitions. + */ +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswalnum, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswalpha, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswblank, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswcntrl, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswdigit, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswgraph, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswlower, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswprint, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswpunct, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswspace, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswupper, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswxdigit, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(int _TLIBC_CDECL_, iswctype, wint_t, wctype_t); +_TLIBC_DEPRECATED_FUNCTION_(wint_t _TLIBC_CDECL_, towctrans, wint_t, wctrans_t); +_TLIBC_DEPRECATED_FUNCTION_(wint_t _TLIBC_CDECL_, towlower, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(wint_t _TLIBC_CDECL_, towupper, wint_t); +_TLIBC_DEPRECATED_FUNCTION_(wctrans_t _TLIBC_CDECL_, wctrans, const char *); +_TLIBC_DEPRECATED_FUNCTION_(wctype_t _TLIBC_CDECL_, wctype, const char *); + +__END_DECLS + +#endif /* _WCTYPE_H_ */ diff --git a/sgx-jvm/linux-sgx/common/se_wrapper/Makefile b/sgx-jvm/linux-sgx/common/se_wrapper/Makefile new file mode 100644 index 0000000000..0cf6f20ebd --- /dev/null +++ b/sgx-jvm/linux-sgx/common/se_wrapper/Makefile @@ -0,0 +1,61 @@ +# +# Copyright (C) 2011-2016 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# + +include ../../buildenv.mk + +CFLAGS += -Werror -D_GNU_SOURCE -fPIC +CFLAGS += $(ADDED_INC) + +CPPFLAGS := -I$(COMMON_DIR)/inc/ \ + -I$(COMMON_DIR)/inc/internal + +OBJS := se_memory.o \ + se_thread.o \ + se_trace.o \ + se_event.o \ + se_rwlock.o \ + se_time.o \ + se_map.o + +LIBWRAPPER := libwrapper.a + +.PHONY: clean all +all: $(LIBWRAPPER) + +$(LIBWRAPPER): $(OBJS) + $(AR) rcs $@ $^ + +$(OBJS): %.o: $(COMMON_DIR)/src/%.c + $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ + +.PHONY: clean +clean: + @$(RM) $(LIBWRAPPER) $(OBJS) diff --git a/sgx-jvm/linux-sgx/common/src/dh.cpp b/sgx-jvm/linux-sgx/common/src/dh.cpp new file mode 100644 index 0000000000..6b01601b9f --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/dh.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/** +* File: +* dh.cpp +*Description: +* Encrypt and decrypt messages over DH session +*/ +#include "dh.h" +#include "sgx_tcrypto.h" + +bool encrypt_msg(pse_message_t* pse_msg, uint8_t* data, sgx_key_128bit_t* authenticated_encryption_key) +{ + /* get random IV */ + if(sgx_read_rand(pse_msg->payload_iv, PAYLOAD_IV_SIZE) != SGX_SUCCESS) + { + return false; + } + + return (SGX_SUCCESS == sgx_rijndael128GCM_encrypt( + authenticated_encryption_key, + data, + pse_msg->payload_size, + reinterpret_cast(&(pse_msg->payload)), + reinterpret_cast(&(pse_msg->payload_iv)), + 12, + NULL, + 0, + &pse_msg->payload_tag + )); +} + +bool decrypt_msg(pse_message_t* pse_msg, uint8_t* data, sgx_key_128bit_t* authenticated_encryption_key) +{ + return(SGX_SUCCESS == sgx_rijndael128GCM_decrypt( + authenticated_encryption_key, + pse_msg->payload, + pse_msg->payload_size, + data, + reinterpret_cast(&(pse_msg->payload_iv)), + 12, + NULL, + 0, + &pse_msg->payload_tag + )); +} + diff --git a/sgx-jvm/linux-sgx/common/src/ecp.cpp b/sgx-jvm/linux-sgx/common/src/ecp.cpp new file mode 100644 index 0000000000..ea632f9443 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/ecp.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "sgx_ecp_types.h" +#include "ecp_interface.h" +#include "stdlib.h" +#include "string.h" + +#ifndef ERROR_BREAK +#define ERROR_BREAK(x) if(x != ippStsNoErr){break;} +#endif +#ifndef NULL_BREAK +#define NULL_BREAK(x) if(!x){break;} +#endif +#ifndef SAFE_FREE +#define SAFE_FREE(ptr) {if (NULL != (ptr)) {free(ptr); (ptr)=NULL;}} +#endif + +#define MAC_KEY_SIZE 16 + +#define EC_DERIVATION_BUFFER_SIZE(label_length) ((label_length) +4) + +sgx_status_t derive_key( + const sgx_ec256_dh_shared_t* shared_key, + const char* label, + uint32_t label_length, + sgx_ec_key_128bit_t* derived_key) +{ + sgx_status_t se_ret = SGX_SUCCESS; + uint8_t cmac_key[MAC_KEY_SIZE]; + sgx_ec_key_128bit_t key_derive_key; + if (!shared_key || !derived_key || !label) + { + return SGX_ERROR_INVALID_PARAMETER; + } + + /*check integer overflow */ + if (label_length > EC_DERIVATION_BUFFER_SIZE(label_length)) + { + return SGX_ERROR_INVALID_PARAMETER; + } + + memset(cmac_key, 0, MAC_KEY_SIZE); + se_ret = sgx_rijndael128_cmac_msg((sgx_cmac_128bit_key_t *)cmac_key, + (uint8_t*)shared_key, + sizeof(sgx_ec256_dh_shared_t), + (sgx_cmac_128bit_tag_t *)&key_derive_key); + if (SGX_SUCCESS != se_ret) + { + memset_s(&key_derive_key, sizeof(key_derive_key), 0, sizeof(key_derive_key)); + INTERNAL_SGX_ERROR_CODE_CONVERTOR(se_ret); + return se_ret; + } + /* derivation_buffer = counter(0x01) || label || 0x00 || output_key_len(0x0080) */ + uint32_t derivation_buffer_length = EC_DERIVATION_BUFFER_SIZE(label_length); + uint8_t *p_derivation_buffer = (uint8_t *)malloc(derivation_buffer_length); + if (p_derivation_buffer == NULL) + { + return SGX_ERROR_OUT_OF_MEMORY; + } + memset(p_derivation_buffer, 0, derivation_buffer_length); + + /*counter = 0x01 */ + p_derivation_buffer[0] = 0x01; + /*label*/ + memcpy(&p_derivation_buffer[1], label, label_length); + /*output_key_len=0x0080*/ + uint16_t *key_len = (uint16_t *)&p_derivation_buffer[derivation_buffer_length - 2]; + *key_len = 0x0080; + + se_ret = sgx_rijndael128_cmac_msg((sgx_cmac_128bit_key_t *)&key_derive_key, + p_derivation_buffer, + derivation_buffer_length, + (sgx_cmac_128bit_tag_t *)derived_key); + memset_s(&key_derive_key, sizeof(key_derive_key), 0, sizeof(key_derive_key)); + free(p_derivation_buffer); + if(SGX_SUCCESS != se_ret) + { + INTERNAL_SGX_ERROR_CODE_CONVERTOR(se_ret); + } + return se_ret; +} diff --git a/sgx-jvm/linux-sgx/common/src/ipp_bn.cpp b/sgx-jvm/linux-sgx/common/src/ipp_bn.cpp new file mode 100644 index 0000000000..03b7cb6826 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/ipp_bn.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/** +* File: +* ipp_bn.cpp +*Description: +* Wrappers for Big number generation and free functions +* +*/ + + + +#include "ipp_wrapper.h" + +#include +#include + +#ifndef _TLIBC_CDECL_ +extern "C" int memset_s(void *s, size_t smax, int c, size_t n); +#endif + +extern "C" IppStatus + newBN(const Ipp32u *data, int size_in_bytes, IppsBigNumState **p_new_BN) +{ + IppsBigNumState *pBN=0; + int bn_size = 0; + + if(p_new_BN == NULL || size_in_bytes <= 0 || size_in_bytes % sizeof(Ipp32u)) + return ippStsBadArgErr; + + /* Get the size of the IppsBigNumState context in bytes */ + IppStatus error_code = ippsBigNumGetSize(size_in_bytes/(int)sizeof(Ipp32u), &bn_size); + if(error_code != ippStsNoErr) + { + *p_new_BN = 0; + return error_code; + } + pBN = (IppsBigNumState *) malloc(bn_size); + if(!pBN) + { + error_code = ippStsMemAllocErr; + *p_new_BN = 0; + return error_code; + } + /* Initializes context and partitions allocated buffer */ + error_code = ippsBigNumInit(size_in_bytes/(int)sizeof(Ipp32u), pBN); + if(error_code != ippStsNoErr) + { + SAFE_FREE_MM(pBN); + *p_new_BN = 0; + return error_code; + } + if(data) + { + error_code = ippsSet_BN(IppsBigNumPOS, size_in_bytes/(int)sizeof(Ipp32u), data, pBN); + if(error_code != ippStsNoErr) + { + SAFE_FREE_MM(pBN); + *p_new_BN = 0; + return error_code; + } + } + *p_new_BN = pBN; + return error_code; + +} + + +extern "C" void secure_free_BN(IppsBigNumState *pBN, int size_in_bytes) +{ + if(pBN == NULL || size_in_bytes <= 0 || size_in_bytes % sizeof(Ipp32u)) + { + if(pBN) + { + free(pBN); + } + return; + } + + int bn_size = 0; + + /* Get the size of the IppsBigNumState context in bytes + * Since we have checked the size_in_bytes before and the &bn_size is not NULL, + * ippsBigNumGetSize never returns failure + */ + if(ippsBigNumGetSize(size_in_bytes/(int)sizeof(Ipp32u), &bn_size) != ippStsNoErr) + { + free(pBN); + return; + } + /* Clear the buffer before free. */ + memset_s(pBN, bn_size, 0, bn_size); + free(pBN); + return; +} diff --git a/sgx-jvm/linux-sgx/common/src/ipp_rsa_key.cpp b/sgx-jvm/linux-sgx/common/src/ipp_rsa_key.cpp new file mode 100644 index 0000000000..e1ccd5513e --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/ipp_rsa_key.cpp @@ -0,0 +1,351 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/** +* File: +* ipp_rsa_key.cpp +*Description: +* Wrapper for rsa key operation functions (public key generation and free excluded) +* +*/ + +#include "ipp_wrapper.h" +#include "util.h" + +#include +#include +#include +#include + +extern "C" int memset_s(void *s, size_t smax, int c, size_t n); + +static IppStatus newPRNG(IppsPRNGState **pRandGen) +{ + if(pRandGen == NULL) + return ippStsBadArgErr; + int ctxSize = 0; + IppStatus error_code = ippsPRNGGetSize(&ctxSize); + if(error_code != ippStsNoErr) + return error_code; + IppsPRNGState* pCtx = (IppsPRNGState *) malloc(ctxSize); + if(pCtx == NULL) + return ippStsMemAllocErr; + + error_code = ippsPRNGInit(160, pCtx); + if(error_code != ippStsNoErr) + { + free(pCtx); + return error_code; + } + + *pRandGen = pCtx; + return error_code; +} + +static IppStatus newPrimeGen(int nMaxBits, IppsPrimeState ** pPrimeG) +{ + if(pPrimeG == NULL || nMaxBits <= 0 ) + return ippStsBadArgErr; + int ctxSize = 0; + IppStatus error_code = ippsPrimeGetSize(nMaxBits, &ctxSize); + if(error_code != ippStsNoErr) + return error_code; + IppsPrimeState* pCtx = (IppsPrimeState *) malloc(ctxSize); + if(pCtx == NULL) + return ippStsMemAllocErr; + + error_code = ippsPrimeInit(nMaxBits, pCtx); + if(error_code != ippStsNoErr) + { + free(pCtx); + return error_code; + } + + *pPrimeG = pCtx; + return error_code; +} + + +extern "C" IppStatus create_rsa_priv2_key(int p_byte_size, const Ipp32u *p, const Ipp32u *q, + const Ipp32u *dmp1, const Ipp32u *dmq1, const Ipp32u *iqmp, + IppsRSAPrivateKeyState **new_pri_key2) +{ + IppsRSAPrivateKeyState *p_rsa2 = NULL; + IppsBigNumState *p_p = NULL, *p_q = NULL, *p_dmp1 = NULL, *p_dmq1 = NULL, *p_iqmp = NULL; + int rsa2_size = 0; + + if(p_byte_size <= 0 || p == NULL || q == NULL || dmp1 == NULL || dmq1 == NULL || iqmp == NULL || new_pri_key2 == NULL) + { + return ippStsBadArgErr; + } + + IppStatus error_code = ippStsNoErr; + do{ + error_code = newBN(p, p_byte_size, &p_p); + ERROR_BREAK(error_code); + error_code = newBN(q, p_byte_size, &p_q); + ERROR_BREAK(error_code); + error_code = newBN(dmp1, p_byte_size, &p_dmp1); + ERROR_BREAK(error_code); + error_code = newBN(dmq1, p_byte_size, &p_dmq1); + ERROR_BREAK(error_code); + error_code = newBN(iqmp, p_byte_size, &p_iqmp); + ERROR_BREAK(error_code); + error_code = ippsRSA_GetSizePrivateKeyType2(p_byte_size * 8, p_byte_size * 8, &rsa2_size); + ERROR_BREAK(error_code); + p_rsa2 = (IppsRSAPrivateKeyState *)malloc(rsa2_size); + NULL_BREAK(p_rsa2); + + error_code = ippsRSA_InitPrivateKeyType2(p_byte_size * 8, p_byte_size * 8, p_rsa2, rsa2_size); + ERROR_BREAK(error_code); + error_code = ippsRSA_SetPrivateKeyType2(p_p, p_q, p_dmp1, p_dmq1, p_iqmp, p_rsa2); + ERROR_BREAK(error_code); + }while(0); + + secure_free_BN(p_p, p_byte_size); + secure_free_BN(p_q, p_byte_size); + secure_free_BN(p_dmp1, p_byte_size); + secure_free_BN(p_dmq1, p_byte_size); + secure_free_BN(p_iqmp, p_byte_size); + + if(error_code != ippStsNoErr || p_rsa2 == NULL) + { + if(error_code == ippStsNoErr ) + error_code = ippStsMemAllocErr; + + /* Clear sensitive data before free */ + secure_free_rsa_pri2_key(p_byte_size, p_rsa2); + return error_code; + } + + *new_pri_key2 = p_rsa2; + return error_code; +} + +extern "C" IppStatus create_rsa_priv1_key(int n_byte_size, int d_byte_size, const Ipp32u *n, const Ipp32u *d, IppsRSAPrivateKeyState **new_pri_key1) +{ + IppsRSAPrivateKeyState *p_rsa1 = NULL; + IppsBigNumState *p_n = NULL, *p_d = NULL; + int rsa1_size = 0; + if(n_byte_size <= 0 || d_byte_size <= 0 || n == NULL || d == NULL || new_pri_key1 == NULL) + { + return ippStsBadArgErr; + } + IppStatus error_code = ippStsNoErr; + do{ + error_code = newBN(n, n_byte_size, &p_n); + ERROR_BREAK(error_code); + error_code = newBN(d, d_byte_size, &p_d); + ERROR_BREAK(error_code); + + error_code = ippsRSA_GetSizePrivateKeyType1(n_byte_size * 8, d_byte_size * 8, &rsa1_size); + ERROR_BREAK(error_code); + p_rsa1 = (IppsRSAPrivateKeyState *)malloc(rsa1_size); + NULL_BREAK(p_rsa1); + error_code = ippsRSA_InitPrivateKeyType1(n_byte_size * 8, d_byte_size * 8, p_rsa1, rsa1_size); + ERROR_BREAK(error_code); + error_code = ippsRSA_SetPrivateKeyType1(p_n, p_d, p_rsa1); + ERROR_BREAK(error_code); + }while(0); + secure_free_BN(p_n, n_byte_size); + secure_free_BN(p_d, d_byte_size); + if(error_code != ippStsNoErr || p_rsa1 == NULL) + { + if(error_code == ippStsNoErr ) + error_code = ippStsMemAllocErr; + + /* Clear sensitive data before free */ + secure_free_rsa_pri1_key(n_byte_size, d_byte_size, p_rsa1); + return error_code; + } + + *new_pri_key1 = p_rsa1; + return error_code; +} + + +extern "C" IppStatus create_validate_rsa_key_pair(int n_byte_size, int e_byte_size, const Ipp32u *n, const Ipp32u *d, const Ipp32u *e, const Ipp32u *p, const Ipp32u *q, + const Ipp32u *dmp1, const Ipp32u *dmq1, const Ipp32u *iqmp, + IppsRSAPrivateKeyState **new_pri_key, IppsRSAPublicKeyState **new_pub_key, int *validate_result) +{ + if(n_byte_size <= 0 || e_byte_size <= 0 || n == NULL || d == NULL || e == NULL || + p == NULL || q == NULL || dmp1 == NULL || dmq1 == NULL || iqmp == NULL || new_pri_key == NULL || + new_pub_key == NULL || validate_result == NULL) + { + return ippStsBadArgErr; + } + IppsRSAPrivateKeyState *p_pri_key1 = NULL, *p_pri_key2 = NULL; + IppsRSAPublicKeyState *p_pub_key = NULL; + IppStatus error_code = ippStsNoErr; + IppsPRNGState *p_rand = NULL; + IppsPrimeState *p_prime = NULL; + Ipp8u * scratch_buffer = NULL; + int result = IPP_IS_VALID; + int max_size = 0, pri1_size = 0, pri2_size = 0, pub_size = 0; + + do + { + /* Generate the pri_key1, pri_key2 and pub_key */ + error_code = create_rsa_priv1_key(n_byte_size, n_byte_size, n, d, &p_pri_key1); + ERROR_BREAK(error_code); + error_code = create_rsa_priv2_key(n_byte_size/2, p, q, dmp1, dmq1, iqmp, &p_pri_key2); + ERROR_BREAK(error_code); + error_code = create_rsa_pub_key(n_byte_size, e_byte_size, n, e, &p_pub_key); + ERROR_BREAK(error_code); + + /* Generate random state and prime state */ + error_code = newPRNG(&p_rand); + ERROR_BREAK(error_code); + error_code = newPrimeGen(n_byte_size * 8 / 2, &p_prime); + ERROR_BREAK(error_code); + + /* Allocate scratch buffer */ + error_code = ippsRSA_GetBufferSizePrivateKey(&pri1_size, p_pri_key1); + ERROR_BREAK(error_code); + error_code = ippsRSA_GetBufferSizePrivateKey(&pri2_size, p_pri_key2); + ERROR_BREAK(error_code); + max_size = MAX(pri1_size, pri2_size); + error_code = ippsRSA_GetBufferSizePublicKey(&pub_size, p_pub_key); + ERROR_BREAK(error_code); + max_size = MAX(max_size, pub_size); + scratch_buffer = (Ipp8u *)malloc(max_size); + NULL_BREAK(scratch_buffer); + memset(scratch_buffer, 0, max_size); + + /* Validate keys */ + error_code = ippsRSA_ValidateKeys(&result, p_pub_key, p_pri_key2, p_pri_key1, scratch_buffer, 10, p_prime, ippsPRNGen, p_rand); + ERROR_BREAK(error_code); + }while(0); + SAFE_FREE_MM(p_rand); + SAFE_FREE_MM(p_prime); + secure_free_rsa_pri2_key(n_byte_size/2, p_pri_key2); + + if(error_code != ippStsNoErr || scratch_buffer == NULL) + { + if(error_code == ippStsNoErr) + error_code = ippStsMemAllocErr; + + SAFE_FREE_MM(scratch_buffer); + secure_free_rsa_pri1_key(n_byte_size, n_byte_size, p_pri_key1); + secure_free_rsa_pub_key(n_byte_size, e_byte_size, p_pub_key); + return error_code; + } + SAFE_FREE_MM(scratch_buffer); + *new_pri_key = p_pri_key1; + *new_pub_key = p_pub_key; + *validate_result = result; + return error_code; +} + +extern "C" IppStatus get_pub_key(const IppsRSAPublicKeyState *pub_key, int *e_byte_size, Ipp32u *e, int *n_byte_size, Ipp32u *n) +{ + IppStatus error_code = ippStsNoErr; + IppsBigNumState *p_n=NULL, *p_e=NULL; + + if(!pub_key || !e_byte_size || !e || !n_byte_size || !n) + { + return ippStsBadArgErr; + } + do + { + error_code = newBN(NULL, SE_KEY_SIZE, &p_n); + ERROR_BREAK(error_code); + error_code = newBN(NULL, sizeof(Ipp32u), &p_e); + ERROR_BREAK(error_code); + + error_code = ippsRSA_GetPublicKey(p_n, p_e, pub_key); + ERROR_BREAK(error_code); + + IppsBigNumSGN sgn = IppsBigNumPOS; + Ipp32u *pdata = NULL; + int length_in_bit = 0; + + + error_code = ippsRef_BN(&sgn, &length_in_bit, &pdata, p_n); + ERROR_BREAK(error_code); + *n_byte_size = ROUND_TO(length_in_bit, 8)/8; + memset(n, 0, *n_byte_size); + memcpy(n, pdata, ROUND_TO(length_in_bit, 8)/8); + + error_code = ippsRef_BN(&sgn, &length_in_bit, &pdata, p_e); + ERROR_BREAK(error_code); + *e_byte_size = ROUND_TO(length_in_bit, 8)/8; + memset(e, 0, *e_byte_size); + memcpy(e, pdata, ROUND_TO(length_in_bit, 8)/8); + } while(0); + + secure_free_BN(p_n, SE_KEY_SIZE); + secure_free_BN(p_e, sizeof(Ipp32u)); + return error_code; +} + +extern "C" void secure_free_rsa_pri1_key(int n_byte_size, int d_byte_size, IppsRSAPrivateKeyState *pri_key1) +{ + if(n_byte_size <= 0 || d_byte_size <= 0 || pri_key1 == NULL) + { + if(pri_key1) + free(pri_key1); + return; + } + + int rsa1_size = 0; + if(ippsRSA_GetSizePrivateKeyType1(n_byte_size * 8, d_byte_size * 8, &rsa1_size) != ippStsNoErr) + { + free(pri_key1); + return; + } + /* Clear the buffer before free. */ + memset_s(pri_key1, rsa1_size, 0, rsa1_size); + free(pri_key1); + return; +} + +extern "C" void secure_free_rsa_pri2_key(int p_byte_size, IppsRSAPrivateKeyState *pri_key2) +{ + if(p_byte_size <= 0 || pri_key2 == NULL) + { + if(pri_key2) + free(pri_key2); + return; + } + + int rsa2_size = 0; + if(ippsRSA_GetSizePrivateKeyType2(p_byte_size * 8, p_byte_size * 8, &rsa2_size) != ippStsNoErr) + { + free(pri_key2); + return; + } + /* Clear the buffer before free. */ + memset_s(pri_key2, rsa2_size, 0, rsa2_size); + free(pri_key2); + return; +} diff --git a/sgx-jvm/linux-sgx/common/src/ipp_rsa_pub_key.cpp b/sgx-jvm/linux-sgx/common/src/ipp_rsa_pub_key.cpp new file mode 100644 index 0000000000..dfc3fc3488 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/ipp_rsa_pub_key.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/** +* File: +* ipp_rsa_pub_key.cpp +*Description: +* Wrapper for rsa public key generation and free +* +*/ + +#include "ipp_wrapper.h" + +#include +#include + +#ifndef _TLIBC_CDECL_ +extern "C" int memset_s(void *s, size_t smax, int c, size_t n); +#endif + +extern "C" IppStatus create_rsa_pub_key(int n_byte_size, int e_byte_size, const Ipp32u *n, const Ipp32u *e, IppsRSAPublicKeyState **new_pub_key) +{ + IppsRSAPublicKeyState *p_pub_key = NULL; + IppsBigNumState *p_n = NULL, *p_e = NULL; + int rsa_size = 0; + if(n_byte_size <= 0 || e_byte_size <= 0 || n == NULL || e == NULL || new_pub_key == NULL) + { + return ippStsBadArgErr; + } + + IppStatus error_code = ippStsNoErr; + do{ + error_code = newBN(n, n_byte_size, &p_n); + ERROR_BREAK(error_code); + error_code = newBN(e, e_byte_size, &p_e); + ERROR_BREAK(error_code); + + error_code = ippsRSA_GetSizePublicKey(n_byte_size * 8, e_byte_size * 8, &rsa_size); + ERROR_BREAK(error_code); + p_pub_key = (IppsRSAPublicKeyState *)malloc(rsa_size); + NULL_BREAK(p_pub_key); + error_code = ippsRSA_InitPublicKey(n_byte_size * 8, e_byte_size * 8, p_pub_key, rsa_size); + ERROR_BREAK(error_code); + error_code = ippsRSA_SetPublicKey(p_n, p_e, p_pub_key); + ERROR_BREAK(error_code); + }while(0); + secure_free_BN(p_n, n_byte_size); + secure_free_BN(p_e, e_byte_size); + if(error_code != ippStsNoErr || p_pub_key == NULL) + { + if(error_code == ippStsNoErr ) + error_code = ippStsMemAllocErr; + + secure_free_rsa_pub_key(n_byte_size, e_byte_size, p_pub_key); + return error_code; + } + + *new_pub_key = p_pub_key; + return error_code; + +} + +extern "C" void secure_free_rsa_pub_key(int n_byte_size, int e_byte_size, IppsRSAPublicKeyState *pub_key) +{ + if(n_byte_size <= 0 || e_byte_size <= 0 || pub_key == NULL) + { + if(pub_key) + free(pub_key); + return; + } + int rsa_size = 0; + if(ippsRSA_GetSizePublicKey(n_byte_size * 8, e_byte_size * 8, &rsa_size) != ippStsNoErr) + { + free(pub_key); + return; + } + /* Clear the buffer before free. */ + memset_s(pub_key, rsa_size, 0, rsa_size); + free(pub_key); + return; +} diff --git a/sgx-jvm/linux-sgx/common/src/se_event.c b/sgx-jvm/linux-sgx/common/src/se_event.c new file mode 100644 index 0000000000..132e48b204 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/se_event.c @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "se_event.h" + +#include + +se_handle_t se_event_init(void) +{ + return calloc(1, sizeof(int)); +} + +void se_event_destroy(se_handle_t se_event) +{ + if (se_event != NULL) + free(se_event); +} + +int se_event_wait(se_handle_t se_event) +{ + if (se_event == NULL) + return SE_MUTEX_INVALID; + + if (__sync_fetch_and_add((int*)se_event, -1) == 0) + syscall(__NR_futex, se_event, FUTEX_WAIT, -1, NULL, NULL, 0); + + return SE_MUTEX_SUCCESS; +} + +int se_event_wake(se_handle_t se_event) +{ + if (se_event == NULL) + return SE_MUTEX_INVALID; + + if (__sync_fetch_and_add((int*)se_event, 1) != 0) + syscall(__NR_futex, se_event, FUTEX_WAKE, 1, NULL, NULL, 0); + + return SE_MUTEX_SUCCESS; +} diff --git a/sgx-jvm/linux-sgx/common/src/se_map.c b/sgx-jvm/linux-sgx/common/src/se_map.c new file mode 100644 index 0000000000..687d035012 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/se_map.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#include "se_map.h" +#include "se_trace.h" +#include + +map_handle_t* map_file(se_file_handle_t fd, uint32_t *size) +{ + struct stat st; + memset(&st, 0, sizeof(st)); + if (-1 == fstat(fd, &st)) + return NULL; + + map_handle_t* mh = (map_handle_t *)calloc(1, sizeof(map_handle_t)); + if (mh == NULL) + return NULL; + + mh->base_addr = (uint8_t *)mmap(NULL, (size_t)st.st_size, + PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); + if(MAP_FAILED == mh->base_addr) + { + free(mh); + SE_TRACE(SE_TRACE_WARNING, "Couldn't map view of file, error code %x\n", errno); + return NULL; + } + + mh->length = (size_t)st.st_size; + if (size) *size = (uint32_t)st.st_size; + return mh; +} + +void unmap_file(map_handle_t* mh) +{ + munmap(mh->base_addr, mh->length); + free(mh); +} + + diff --git a/sgx-jvm/linux-sgx/common/src/se_memory.c b/sgx-jvm/linux-sgx/common/src/se_memory.c new file mode 100644 index 0000000000..d860b6bc34 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/se_memory.c @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#include "se_memory.h" +#include "se_trace.h" +#include "util.h" + +void* se_virtual_alloc(void* address, size_t size, uint32_t type) +{ + UNUSED(type); + void* pRet = mmap(address, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if(MAP_FAILED == pRet) + return NULL; + return pRet; +} + +int se_virtual_free(void* address, size_t size, uint32_t type) +{ + UNUSED(type); + + return !(munmap(address, size)); + +} + +int se_virtual_lock(void* address, size_t size) +{ + return !mlock(address, size); +} + +static unsigned int get_prot(uint64_t flags) +{ + if ((flags & SI_FLAG_PT_MASK) == SI_FLAG_TCS) + return PROT_READ|PROT_WRITE|PROT_EXEC; + + switch (flags & (SI_FLAG_R | SI_FLAG_W | SI_FLAG_X)) + { + case SI_FLAG_X: return PROT_EXEC; break; + case SI_FLAG_R | SI_FLAG_X: return PROT_READ|PROT_EXEC; break; + case SI_FLAG_R | SI_FLAG_W | SI_FLAG_X: return PROT_READ|PROT_WRITE|PROT_EXEC; break; + case SI_FLAG_R: return PROT_READ; break; + case SI_FLAG_R | SI_FLAG_W: return PROT_READ|PROT_WRITE; break; + /* This covers no access, W and WX */ + default: return PROT_NONE; break; + } + +} +int se_virtual_protect(void* address, size_t size, uint32_t prot) +{ + return !mprotect(address, size, (int)get_prot(prot)); +} + +se_proc_t get_self_proc() +{ + return getpid(); +} + +int put_self_proc(se_proc_t proc) +{ + UNUSED(proc); + return 1; +} + +int se_read_process_mem(se_proc_t proc, void* base_addr, void* buffer, size_t size, size_t* read_nr) +{ + char filename[64]; + int fd = -1; + int ret = FALSE; + ssize_t len = 0; + off64_t offset = (off64_t)(size_t) base_addr; + + snprintf (filename, 64, "/proc/%d/mem", (int)proc); + fd = open(filename, O_RDONLY | O_LARGEFILE); + if(fd == -1) + return FALSE; + + if(lseek64(fd, offset, SEEK_SET) == -1) + { + goto out; + } + if((len = read(fd, buffer, size)) < 0) + { + goto out; + } + else if(read_nr) + *read_nr = (size_t)len; /* len is a non-negative number */ + + ret = TRUE; + +out: + close (fd); + return ret; +} + +int se_write_process_mem(se_proc_t proc, void* base_addr, void* buffer, size_t size, size_t* write_nr) +{ + char filename[64]; + int fd = -1; + int ret = FALSE; + ssize_t len = 0; + off64_t offset = (off64_t)(size_t)base_addr; + + snprintf (filename, 64, "/proc/%d/mem", (int)proc); + fd = open(filename, O_RDWR | O_LARGEFILE); + if(fd == -1) + return FALSE; + + if(lseek64(fd, offset, SEEK_SET) == -1) + { + goto out; + } + if((len = write(fd, buffer, size)) < 0) + { + goto out; + } + else if(write_nr) + *write_nr = (size_t)len; /* len is a non-negative number */ + + ret = TRUE; +out: + close (fd); + return ret; +} + diff --git a/sgx-jvm/linux-sgx/common/src/se_rwlock.c b/sgx-jvm/linux-sgx/common/src/se_rwlock.c new file mode 100644 index 0000000000..9164a123f7 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/se_rwlock.c @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "se_rwlock.h" +#include "internal/util.h" + + +#include +void se_wtlock(se_prwlock_t lock) +{ + int ret = pthread_rwlock_wrlock(lock); + if(0 != ret) + abort(); +} + +void se_wtunlock(se_prwlock_t lock) +{ + int ret = pthread_rwlock_unlock(lock); + if(0 != ret) + abort(); +} + +int se_try_rdlock(se_prwlock_t lock) +{ + return (0 == pthread_rwlock_tryrdlock(lock)); +} + +void se_rdlock(se_prwlock_t lock) +{ + int ret = pthread_rwlock_rdlock(lock); + if(0 != ret) + abort(); +} + +void se_rdunlock(se_prwlock_t lock) +{ + int ret = pthread_rwlock_unlock(lock); + if(0 != ret) + abort(); +} + +void se_init_rwlock(se_prwlock_t lock) +{ + /* use the default attribute. */ + int ret = pthread_rwlock_init(lock, NULL); + if(0 != ret) + abort(); +} + +void se_fini_rwlock(se_prwlock_t lock) +{ + int ret = pthread_rwlock_destroy(lock); + if(0 != ret) + abort(); +} + diff --git a/sgx-jvm/linux-sgx/common/src/se_thread.c b/sgx-jvm/linux-sgx/common/src/se_thread.c new file mode 100644 index 0000000000..b188a049d1 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/se_thread.c @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include "se_thread.h" +#include "se_types.h" + +void se_mutex_init(se_mutex_t* mutex) +{ +#ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP + se_mutex_t tmp = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; +#elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER) + se_mutex_t tmp = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; +#else +#error no pre-defined RECURSIVE_MUTEX found. +#endif + + /* C doesn't allow `*mutex = PTHREAD_..._INITIALIZER'.*/ + memcpy(mutex, &tmp, sizeof(tmp)); +} + +int se_mutex_lock(se_mutex_t* mutex) { return (0 == pthread_mutex_lock(mutex)); } +int se_mutex_unlock(se_mutex_t* mutex) { return (0 == pthread_mutex_unlock(mutex)); } +int se_mutex_destroy(se_mutex_t* mutex) { return (0 == pthread_mutex_destroy(mutex));} + +unsigned int se_get_threadid(void) { return (unsigned)syscall(__NR_gettid);} +/* tls functions */ +int se_tls_alloc(se_tls_index_t *tls_index) { return !pthread_key_create(tls_index, NULL); } +int se_tls_free(se_tls_index_t tls_index) { return !pthread_key_delete(tls_index); } +void * se_tls_get_value(se_tls_index_t tls_index) { return pthread_getspecific(tls_index); } +int se_tls_set_value(se_tls_index_t tls_index, void *tls_value) { return !pthread_setspecific(tls_index, tls_value); } +/* +se_thread_handle_t se_create_thread(size_t stack_size, thread_start_routine_t start_routine, void *param, se_thread_t *thread) +{ + pthread_attr_t attr, *attr_ptr = NULL; + int ret; + + if(stack_size > 0) + { + ret = pthread_attr_init(&attr); + if(ret) + return NULL; + ret = pthread_attr_setstacksize(&attr, stack_size); + if(ret) + return NULL; + attr_ptr = &attr; + } + else + { + attr_ptr = NULL; + } + ret = pthread_create(thread, attr_ptr, start_routine, param); + if(ret) + return NULL; + if(attr_ptr) + pthread_attr_destroy(&attr); + + return thread; + +} +*/ diff --git a/sgx-jvm/linux-sgx/common/src/se_time.c b/sgx-jvm/linux-sgx/common/src/se_time.c new file mode 100644 index 0000000000..20bc84fc38 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/se_time.c @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "se_time.h" + + +#include +#include +void se_sleep(uint32_t milli_seconds) +{ + usleep(milli_seconds * 1000); +} + +uint64_t se_get_tick_count_freq(void) +{ + return 1000000000ULL; +} + +uint64_t se_get_tick_count(void) +{ + struct timespec tm; + if (clock_gettime(CLOCK_MONOTONIC, &tm) != 0) + return 0; + return ((uint64_t)tm.tv_sec * 1000000000ULL) + ((uint64_t)tm.tv_nsec ); +} diff --git a/sgx-jvm/linux-sgx/common/src/se_trace.c b/sgx-jvm/linux-sgx/common/src/se_trace.c new file mode 100644 index 0000000000..ff81de827d --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/se_trace.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "se_trace.h" +#include +int se_trace_internal(int debug_level, const char *fmt, ...) +{ + va_list args; + int ret = 0; + + va_start(args, fmt); + if(SE_TRACE_NOTICE == debug_level) + ret = vfprintf(stdout, fmt, args); + else + ret = vfprintf(stderr, fmt, args); + va_end(args); + + return ret; +} diff --git a/sgx-jvm/linux-sgx/common/src/sgx_memset_s.cpp b/sgx-jvm/linux-sgx/common/src/sgx_memset_s.cpp new file mode 100644 index 0000000000..816c1504e5 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/sgx_memset_s.cpp @@ -0,0 +1,78 @@ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Alan Barrett + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ISO/IEC 9899:2011 section K.3.7.4.1 The memset_s function + */ + +#include "sgx_memset_s.h" +#include +#include +#include +/* + * __memset_vp is a volatile pointer to a function. + * It is initialised to point to memset, and should never be changed. + */ +static void * (* const volatile __memset_vp)(void *, int, size_t) + = (memset); + +#ifdef memset_s +#undef memset_s /* in case it was defined as a macro */ +#endif + +#ifdef __cplusplus +extern "C" +#endif +int memset_s(void *s, size_t smax, int c, size_t n) +{ + int err = 0; + + if (s == NULL) { + err = EINVAL; + goto out; + } + + if (n > smax) { + err = EOVERFLOW; + n = smax; + } + + /* Calling through a volatile pointer should never be optimised away. */ + (*__memset_vp)(s, c, n); + + out: + if (err == 0) + return 0; + else { + errno = err; + /* XXX call runtime-constraint handler */ + return err; + } +} + diff --git a/sgx-jvm/linux-sgx/common/src/sgx_profile.cpp b/sgx-jvm/linux-sgx/common/src/sgx_profile.cpp new file mode 100644 index 0000000000..17244cd008 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/sgx_profile.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#ifdef _PROFILE_ + +#include +#include +#include +#include "sgx_profile.h" +#include "se_time.h" +#include +using namespace std; + +typedef struct _profile_item_t{ + const char *str; /* tag */ + int flag; /* 0: start, 1: end */ + long long time; /* current time */ +} profile_item_t; + +static vector profile_items; +static int alloc_size; +static int used_size; +const int MALLOC_SIZE = 1000; +static long long freq = {0}; + +#define MALLOC_TAG "PROFILE_MALLOC_CONSUMED_TIME" + +extern "C" void profile_init() +{ + freq = se_get_tick_count_freq(); + profile_items.resize(MALLOC_SIZE); + alloc_size = MALLOC_SIZE; + used_size = 0; +} + +static void profile_add_info(const char *str, int flag) +{ + long long cur_time = se_get_tick_count(); + if(used_size==alloc_size){ + alloc_size+=MALLOC_SIZE; + profile_items.resize(alloc_size); + profile_items[used_size].flag = PRO_START; + profile_items[used_size].str = MALLOC_TAG; + profile_items[used_size].time = cur_time; + cur_time = se_get_tick_count(); + used_size++; + profile_items[used_size].flag = PRO_END; + profile_items[used_size].str = MALLOC_TAG; + profile_items[used_size].time = cur_time; + used_size++; + } + profile_items[used_size].flag = flag; + profile_items[used_size].str = str; + profile_items[used_size].time = cur_time; + used_size++; +} + +extern "C" void profile_start(const char* str) +{ + profile_add_info(str, PRO_START); +} + +extern "C" void profile_end(const char * str) +{ + profile_add_info(str, PRO_END); +} + +#include +std::string get_prof_fun_name(const char *s) +{ + std::string input(s); + size_t end = input.find("("); + size_t begin = input.substr(0,end).rfind(" ")+1; + end = end - begin; + return input.substr(begin,end); +} + +extern "C" void profile_output(const char* filename) +{ + int i,j; + + ofstream fs; + fs.open(filename); /* do not overwritten previous value */ + + fs << "freq: " << freq <str << endl; */ + return; + } + } + } + + if(j == used_size) + { + /* cout << "Error: not find end for " << it->str << endl; */ + return; + } + + fs << get_prof_fun_name(profile_items[i].str) << "," << profile_items[i].time << "," << profile_items[j].time << endl; + } + profile_items.clear(); + used_size=0; + alloc_size=0; + fs.close(); + +} +#endif diff --git a/sgx-jvm/linux-sgx/common/src/sgx_read_rand.cpp b/sgx-jvm/linux-sgx/common/src/sgx_read_rand.cpp new file mode 100644 index 0000000000..410ea6979c --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/sgx_read_rand.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +/* Please add external/rdrand into INCLUDE path and correpondent library to project */ + +#include +#include +#include +#include "sgx.h" +#include "sgx_defs.h" +#include "se_wrapper.h" +#include "rdrand.h" +#include "cpuid.h" +#include +#ifndef UINT32_MAX +#define UINT32_MAX 0xFFFFFFFFU +#endif + +static int g_is_rdrand_supported=-1; + +#define RDRAND_MASK 0x40000000 + +static int rdrand_cpuid() +{ + int info[4] = {-1, -1, -1, -1}; + + /* Are we on an Intel processor? */ + + __cpuid(info, 0); + + if (memcmp(&info[1], "Genu", 4) != 0 || + memcmp(&info[3], "ineI", 4) != 0 || + memcmp(&info[2], "ntel", 4) != 0 ) { + return 0; + } + + /* Do we have RDRAND? */ + + __cpuid(info, /*feature bits*/1); + + int ecx = info[2]; + if ((ecx & RDRAND_MASK) == RDRAND_MASK) + return 1; + else + return 0; +} + + +extern "C" sgx_status_t SGXAPI sgx_read_rand(uint8_t *buf, size_t size) +{ + if(buf == NULL || size == 0 || size> UINT32_MAX ){ + return SGX_ERROR_INVALID_PARAMETER; + } + if(g_is_rdrand_supported==-1){ + g_is_rdrand_supported = rdrand_cpuid(); + } + if(!g_is_rdrand_supported){ + uint32_t i; + for(i=0;i<(uint32_t)size;++i){ + buf[i]=(uint8_t)rand(); + } + }else{ + int rd_ret =rdrand_get_bytes((uint32_t)size, buf); + if(rd_ret != RDRAND_SUCCESS){ + rd_ret = rdrand_get_bytes((uint32_t)size, buf); + if(rd_ret != RDRAND_SUCCESS){ + return SGX_ERROR_UNEXPECTED; + } + } + } + return SGX_SUCCESS; +} diff --git a/sgx-jvm/linux-sgx/common/src/sgx_sha256_128.cpp b/sgx-jvm/linux-sgx/common/src/sgx_sha256_128.cpp new file mode 100644 index 0000000000..a12618b7d1 --- /dev/null +++ b/sgx-jvm/linux-sgx/common/src/sgx_sha256_128.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2011-2016 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include "sgx_sha256_128.h" + +/* +** SHA256-128 implementation: +** out-length := x ¨C number of bits to output +** prefix := SHA-256(out-length) +** digest := SHA-256(prefix || m) +** output := truncate(digest, out-length) ? always return first out-length bits +*/ +sgx_status_t SGXAPI sgx_sha256_128_msg(const uint8_t *p_src, uint32_t src_len, sgx_sha256_128_hash_t *p_hash) +{ + uint32_t outlength = 128; /*number of bits to output */ + uint32_t sha256_128_digest_length; + sgx_status_t ret; + sgx_sha256_hash_t digest = {0}; + uint8_t* digest_buffer = NULL; + + /* check potential overflow and NULL pointer */ + if( (UINT32_MAX-src_len) < sizeof(sgx_sha256_hash_t) || !p_hash || !p_src) + return SGX_ERROR_INVALID_PARAMETER; + + sha256_128_digest_length = (uint32_t)sizeof(sgx_sha256_hash_t)+ src_len; + + digest_buffer = (uint8_t*)malloc(sha256_128_digest_length); + if(!digest_buffer) + return SGX_ERROR_OUT_OF_MEMORY; + memset(digest_buffer, 0, sha256_128_digest_length); + + /* get prefix := SHA-256(out-length) */ + ret = sgx_sha256_msg((const uint8_t*)&outlength, sizeof(uint32_t), (sgx_sha256_hash_t*)digest_buffer); + if(SGX_SUCCESS != ret) + goto clean_up; + + /* get digest := SHA-256(prefix || m) */ + memcpy(digest_buffer+sizeof(sgx_sha256_hash_t), p_src, src_len); /* copy m to digest_buffer */ + ret = sgx_sha256_msg((const uint8_t*)digest_buffer, sha256_128_digest_length, &digest); + if(SGX_SUCCESS != ret) + goto clean_up; + + /* output truncated hash + return the first 128 bits */ + memcpy(p_hash, &digest, sizeof(sgx_sha256_128_hash_t)); + +clean_up: + if(digest_buffer) + free(digest_buffer); + + return ret; +} diff --git a/sgx-jvm/linux-sgx/download_prebuilt.sh b/sgx-jvm/linux-sgx/download_prebuilt.sh new file mode 100755 index 0000000000..2d8214786e --- /dev/null +++ b/sgx-jvm/linux-sgx/download_prebuilt.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2011-2016 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# + + +top_dir=`dirname $0` +#out_dir=$top_dir/psw/ae/data/prebuilt +out_dir=$top_dir +optlib_name=optimized_libs-1.7.100.35958.tar +ae_file_name=prebuilt-ae-1.7.100.35958.tar +server_url_path=https://download.01.org/intel-sgx/linux-1.7/ +server_optlib_url=$server_url_path/$optlib_name +server_ae_url=$server_url_path/$ae_file_name +optlib_md5=d873e20155fceb870c2e14771cc2258a +ae_md5=ca7cf31f1e9fee06feea44732cfbc908 +rm -rf $out_dir/$optlib_name +wget $server_optlib_url -P $out_dir +if [ $? -ne 0 ]; then + echo "Fail to download file $server_optlib_url" + exit -1 +fi +md5sum $out_dir/$optlib_name > check_sum.txt +grep $optlib_md5 check_sum.txt +if [ $? -ne 0 ]; then + echo "File $server_optlib_url checksum failure" + exit -1 +fi +rm -rf $out_dir/$ae_file_name +wget $server_ae_url -P $out_dir +if [ $? -ne 0 ]; then + echo "Fail to download file $server_ae_url" + exit -1 +fi +md5sum $out_dir/$ae_file_name > check_sum.txt +grep $ae_md5 check_sum.txt +if [ $? -ne 0 ]; then + echo "File $server_optlib_url checksum failure" + exit -1 +fi + +pushd $out_dir;tar -xf $optlib_name;tar -xf $ae_file_name;rm -f $optlib_name;rm -f $ae_file_name;popd diff --git a/sgx-jvm/linux-sgx/external/crypto_px/Makefile b/sgx-jvm/linux-sgx/external/crypto_px/Makefile new file mode 100644 index 0000000000..6739cdaf32 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/Makefile @@ -0,0 +1,62 @@ +# +# Copyright (C) 2011-2016 Intel Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# + +include ../../buildenv.mk + +CFLAGS += -fPIC -D_PX +ifeq ($(ARCH), x86_64) + CFLAGS += -D_ARCH_EM64T +else + CFLAGS += -D_ARCH_IA32 +endif + +INC := -I./include \ + -I./sources/include \ + -I./sources/ippcp/src + +SRCS := $(wildcard ./sources/ippcp/src/*.c) +OBJS := $(SRCS:.c=.o) + +libcrypto_px.a: $(OBJS) + ar crv $@ $^ + +%.o :%.c + $(CC) -c $(INC) $(CFLAGS) $< -o $@ + +.PHONY: all +all: libcrypto_px.a + +.PHONY: clean +clean: + @$(RM) $(OBJS) libcrypto_px.a + +.PHONY: rebuild +rebuild: clean all diff --git a/sgx-jvm/linux-sgx/external/crypto_px/include/ippbase.h b/sgx-jvm/linux-sgx/external/crypto_px/include/ippbase.h new file mode 100755 index 0000000000..202cda8f26 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/include/ippbase.h @@ -0,0 +1,195 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#ifndef __IPPBASE_H__ +#define __IPPBASE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined( _WIN32 ) || defined ( _WIN64 ) + #define __STDCALL __stdcall + #define __CDECL __cdecl + #define __INT64 __int64 + #define __UINT64 unsigned __int64 +#else + #define __STDCALL + #define __CDECL + #define __INT64 long long + #define __UINT64 unsigned long long +#endif + +#define IPP_PI ( 3.14159265358979323846 ) /* ANSI C does not support M_PI */ +#define IPP_2PI ( 6.28318530717958647692 ) /* 2*pi */ +#define IPP_PI2 ( 1.57079632679489661923 ) /* pi/2 */ +#define IPP_PI4 ( 0.78539816339744830961 ) /* pi/4 */ +#define IPP_PI180 ( 0.01745329251994329577 ) /* pi/180 */ +#define IPP_RPI ( 0.31830988618379067154 ) /* 1/pi */ +#define IPP_SQRT2 ( 1.41421356237309504880 ) /* sqrt(2) */ +#define IPP_SQRT3 ( 1.73205080756887729353 ) /* sqrt(3) */ +#define IPP_LN2 ( 0.69314718055994530942 ) /* ln(2) */ +#define IPP_LN3 ( 1.09861228866810969139 ) /* ln(3) */ +#define IPP_E ( 2.71828182845904523536 ) /* e */ +#define IPP_RE ( 0.36787944117144232159 ) /* 1/e */ +#define IPP_EPS23 ( 1.19209289e-07f ) +#define IPP_EPS52 ( 2.2204460492503131e-016 ) + +#define IPP_MAX_8U ( 0xFF ) +#define IPP_MAX_16U ( 0xFFFF ) +#define IPP_MAX_32U ( 0xFFFFFFFF ) +#define IPP_MIN_8U ( 0 ) +#define IPP_MIN_16U ( 0 ) +#define IPP_MIN_32U ( 0 ) +#define IPP_MIN_8S (-128 ) +#define IPP_MAX_8S ( 127 ) +#define IPP_MIN_16S (-32768 ) +#define IPP_MAX_16S ( 32767 ) +#define IPP_MIN_32S (-2147483647 - 1 ) +#define IPP_MAX_32S ( 2147483647 ) +#define IPP_MIN_64U ( 0 ) + +#if defined( _WIN32 ) || defined ( _WIN64 ) + #define IPP_MAX_64S ( 9223372036854775807i64 ) + #define IPP_MIN_64S (-9223372036854775807i64 - 1 ) + #define IPP_MAX_64U ( 0xffffffffffffffffL ) /* 18446744073709551615 */ +#else + #define IPP_MAX_64S ( 9223372036854775807LL ) + #define IPP_MIN_64S (-9223372036854775807LL - 1 ) + #define IPP_MAX_64U ( 0xffffffffffffffffLL ) /* 18446744073709551615 */ +#endif + +#define IPP_MINABS_32F ( 1.175494351e-38f ) +#define IPP_MAXABS_32F ( 3.402823466e+38f ) +#define IPP_EPS_32F ( 1.192092890e-07f ) +#define IPP_MINABS_64F ( 2.2250738585072014e-308 ) +#define IPP_MAXABS_64F ( 1.7976931348623158e+308 ) +#define IPP_EPS_64F ( 2.2204460492503131e-016 ) + +#define IPP_MAX( a, b ) ( ((a) > (b)) ? (a) : (b) ) +#define IPP_MIN( a, b ) ( ((a) < (b)) ? (a) : (b) ) + +#define IPP_ABS( a ) ( ((a) < 0) ? (-(a)) : (a) ) + +typedef struct { + int major; /* e.g. 1 */ + int minor; /* e.g. 2 */ + int majorBuild; /* e.g. 3 */ + int build; /* e.g. 10, always >= majorBuild */ + char targetCpu[4]; /* corresponding to Intel(R) processor */ + const char* Name; /* e.g. "ippsw7" */ + const char* Version; /* e.g. "v1.2 Beta" */ + const char* BuildDate; /* e.g. "Jul 20 99" */ +} IppLibraryVersion; + +typedef unsigned char Ipp8u; +typedef unsigned short Ipp16u; +typedef unsigned int Ipp32u; +typedef signed char Ipp8s; +typedef signed short Ipp16s; +typedef signed int Ipp32s; +typedef float Ipp32f; +typedef __INT64 Ipp64s; +typedef __UINT64 Ipp64u; +typedef double Ipp64f; +typedef Ipp16s Ipp16f; + +typedef struct { + Ipp8s re; + Ipp8s im; +} Ipp8sc; + +typedef struct { + Ipp16s re; + Ipp16s im; +} Ipp16sc; + +typedef struct { + Ipp16u re; + Ipp16u im; +} Ipp16uc; + +typedef struct { + Ipp32s re; + Ipp32s im; +} Ipp32sc; + +typedef struct { + Ipp32f re; + Ipp32f im; +} Ipp32fc; + +typedef struct { + Ipp64s re; + Ipp64s im; +} Ipp64sc; + +typedef struct { + Ipp64f re; + Ipp64f im; +} Ipp64fc; + +typedef enum { + ippUndef = -1, + ipp1u = 0, + ipp8u = 1, + ipp8uc = 2, + ipp8s = 3, + ipp8sc = 4, + ipp16u = 5, + ipp16uc = 6, + ipp16s = 7, + ipp16sc = 8, + ipp32u = 9, + ipp32uc = 10, + ipp32s = 11, + ipp32sc = 12, + ipp32f = 13, + ipp32fc = 14, + ipp64u = 15, + ipp64uc = 16, + ipp64s = 17, + ipp64sc = 18, + ipp64f = 19, + ipp64fc = 20 +} IppDataType; + +typedef enum { + ippFalse = 0, + ippTrue = 1 +} IppBool; + +#ifdef __cplusplus +} +#endif + +#endif /* __IPPBASE_H__ */ + diff --git a/sgx-jvm/linux-sgx/external/crypto_px/include/ippcore.h b/sgx-jvm/linux-sgx/external/crypto_px/include/ippcore.h new file mode 100755 index 0000000000..ec5185923c --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/include/ippcore.h @@ -0,0 +1,395 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined( __IPPCORE_H__ ) || defined( _OWN_BLDPCS ) +#define __IPPCORE_H__ + +#if defined (_WIN32_WCE) && defined (_M_IX86) && defined (__stdcall) + #define _IPP_STDCALL_CDECL + #undef __stdcall +#endif + +#ifndef __IPPDEFS_H__ + #include "ippdefs.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + +#if !defined( _IPP_NO_DEFAULT_LIB ) + #if defined( _IPP_SEQUENTIAL_DYNAMIC ) + #pragma comment( lib, __FILE__ "/../../lib/" _INTEL_PLATFORM "ippcore" ) + #elif defined( _IPP_SEQUENTIAL_STATIC ) + #pragma comment( lib, __FILE__ "/../../lib/" _INTEL_PLATFORM "ippcoremt" ) + #elif defined( _IPP_PARALLEL_DYNAMIC ) + #pragma comment( lib, __FILE__ "/../../lib/" _INTEL_PLATFORM "threaded/ippcore" ) + #elif defined( _IPP_PARALLEL_STATIC ) + #pragma comment( lib, __FILE__ "/../../lib/" _INTEL_PLATFORM "threaded/ippcoremt" ) + #endif +#endif + +/* ///////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Functions declarations +//////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// */ + + +/* ///////////////////////////////////////////////////////////////////////////// +// Name: ippGetLibVersion +// Purpose: getting of the library version +// Returns: the structure of information about version +// of ippcore library +// Parameters: +// +// Notes: not necessary to release the returned structure +*/ +IPPAPI( const IppLibraryVersion*, ippGetLibVersion, (void) ) + + +/* ///////////////////////////////////////////////////////////////////////////// +// Name: ippGetStatusString +// Purpose: convert the library status code to a readable string +// Parameters: +// StsCode IPP status code +// Returns: pointer to string describing the library status code +// +// Notes: don't free the pointer +*/ +IPPAPI( const char*, ippGetStatusString, ( IppStatus StsCode ) ) + + + +/* ///////////////////////////////////////////////////////////////////////////// +// Name: ippGetCpuClocks +// Purpose: reading of time stamp counter (TSC) register value +// Returns: TSC value +// +// Note: An hardware exception is possible if TSC reading is not supported by +/ the current chipset +*/ + +IPPAPI( Ipp64u, ippGetCpuClocks, (void) ) + + +/* /////////////////////////////////////////////////////////////////////////// +// Names: ippSetFlushToZero, +// ippSetDenormAreZero. +// +// Purpose: ippSetFlushToZero enables or disables the flush-to-zero mode, +// ippSetDenormAreZero enables or disables the denormals-are-zeros +// mode. +// +// Arguments: +// value - !0 or 0 - set or clear the corresponding bit of MXCSR +// pUMask - pointer to user store current underflow exception mask +// ( may be NULL if don't want to store ) +// +// Return: +// ippStsNoErr - Ok +// ippStsCpuNotSupportedErr - the mode is not supported +*/ + +IPPAPI( IppStatus, ippSetFlushToZero, ( int value, unsigned int* pUMask )) +IPPAPI( IppStatus, ippSetDenormAreZeros, ( int value )) + + + +/* ///////////////////////////////////////////////////////////////////////////// +// Name: ippAlignPtr +// Purpose: pointer aligning +// Returns: aligned pointer +// +// Parameter: +// ptr - pointer +// alignBytes - number of bytes to align +// +*/ +IPPAPI( void*, ippAlignPtr, ( void * ptr, int alignBytes ) ) + +/* ///////////////////////////////////////////////////////////////////////////// +// Functions to allocate and free memory +///////////////////////////////////////////////////////////////////////////// */ +/* ///////////////////////////////////////////////////////////////////////////// +// Name: ippMalloc +// Purpose: 64-byte aligned memory allocation +// Parameter: +// len number of bytes +// Returns: pointer to allocated memory +// +// Notes: the memory allocated by ippMalloc has to be free by ippFree +// function only. +*/ + +IPPAPI( void*, ippMalloc, (int length) ) + + +/* ///////////////////////////////////////////////////////////////////////////// +// Name: ippFree +// Purpose: free memory allocated by the ippMalloc function +// Parameter: +// ptr pointer to the memory allocated by the ippMalloc function +// +// Notes: use the function to free memory allocated by ippMalloc +*/ +IPPAPI( void, ippFree, (void* ptr) ) + + + +/* ///////////////////////////////////////////////////////////////////////////// +// Name: ippInit +// Purpose: Automatic switching to best for current cpu library code using. +// Returns: +// ippStsNoErr +// +// Parameter: nothing +// +// Notes: At the moment of this function execution no any other IPP function +// has to be working +*/ +IPPAPI( IppStatus, ippInit, ( void )) + + +/* //////////////////////////////////////////////////////////////////////////// +// Name: ippGetCpuFreqMhz +// +// Purpose: the function estimates cpu frequency and returns +// its value in MHz as a integer +// +// Return: +// ippStsNoErr Ok +// ippStsNullPtrErr null pointer to the freq value +// ippStsSizeErr wrong num of tries, internal var +// Arguments: +// pMhz pointer to the integer to write +// cpu freq value estimated +// +// Notes: no exact value is guaranteed, the value could +// vary with cpu workloading +*/ + +IPPAPI(IppStatus, ippGetCpuFreqMhz, ( int* pMhz ) ) + +/* //////////////////////////////////////////////////////////////////////////// +// Name: ippSetNumThreads +// +// Purpose: +// +// Return: +// ippStsNoErr Ok +// ippStsNoOperation For static library internal threading is not supported +// ippStsSizeErr Desired number of threads less or equal zero +// +// Arguments: +// numThr Desired number of threads +*/ +IPPAPI( IppStatus, ippSetNumThreads, ( int numThr ) ) + +/* //////////////////////////////////////////////////////////////////////////// +// Name: ippGetNumThreads +// +// Purpose: +// +// Return: +// ippStsNoErr Ok +// ippStsNullPtrErr Pointer to numThr is Null +// ippStsNoOperation For static library internal threading is not supported +// and return value is always == 1 +// +// Arguments: +// pNumThr Pointer to memory location where to store current numThr +*/ +IPPAPI( IppStatus, ippGetNumThreads, (int* pNumThr) ) + +/* //////////////////////////////////////////////////////////////////////////// +// Name: ippGetMaxCacheSizeB +// +// Purpose: Detects maximal from the sizes of L2 or L3 in bytes +// +// Return: +// ippStsNullPtrErr The result's pointer is NULL. +// ippStsNotSupportedCpu The cpu is not supported. +// ippStsUnknownCacheSize The cpu is supported, but the size of the cache is unknown. +// ippStsNoErr Ok +// +// Arguments: +// pSizeByte Pointer to the result +// +// Note: +// 1). Intel(R) processors are supported only. +// 2). Intel(R) Itanium(R) processors and platforms with Intel XScale(R) technology are unsupported +// 3). For unsupported processors the result is "0", +// and the return status is "ippStsNotSupportedCpu". +// 4). For supported processors the result is "0", +// and the return status is "ippStsUnknownCacheSize". +// if sizes of the cache is unknown. +// +*/ +IPPAPI( IppStatus, ippGetMaxCacheSizeB, ( int* pSizeByte ) ) + +/* +// Name: ippGetCpuFeatures +// Purpose: Detects CPU features. +// Parameters: +// pFeaturesMask Pointer to the features mask. +// Nonzero value of bit means the corresponding feature is supported. +// Features mask values are defined in the ippdefs.h +// [ 0] - MMX ( ippCPUID_MMX ) +// [ 1] - SSE ( ippCPUID_SSE ) +// [ 2] - SSE2 ( ippCPUID_SSE2 ) +// [ 3] - SSE3 ( ippCPUID_SSE3 ) +// [ 4] - SSSE3 ( ippCPUID_SSSE3 ) +// [ 5] - MOVBE ( ippCPUID_MOVBE ) +// [ 6] - SSE41 ( ippCPUID_SSE41 ) +// [ 7] - SSE42 ( ippCPUID_SSE42 ) +// [ 8] - AVX ( ippCPUID_AVX ) +// [ 9] - ENABLEDBYOS( ippAVX_ENABLEDBYOS ) +// [10] - AES ( ippCPUID_AES ) +// [11] - PCLMULQDQ ( ippCPUID_CLMUL ) +// [12] - ABR ( ippCPUID_ABR ) +// [13] - RDRAND ( ippCPUID_RDRAND ) +// [14] - F16C ( ippCPUID_F16C ) +// [15] - AVX2 ( ippCPUID_AVX2 ) +// [16] - ADOX/ADCX ( ippCPUID_ADCOX ) ADCX and ADOX instructions +// [17] - RDSEED ( ippCPUID_RDSEED ) The RDSEED instruction +// [18] - PREFETCHW ( ippCPUID_PREFETCHW ) The PREFETCHW instruction +// [19] - SHA ( ippCPUID_SHA ) Intel (R) SHA Extensions +// [20:63] - Reserved +// +// pCpuidInfoRegs Pointer to the 4-element vector. +// Result of CPUID.1 are stored in this vector. +// [0] - register EAX +// [1] - register EBX +// [2] - register ECX +// [3] - register EDX +// If pointer pCpuidInfoRegs is set to NULL, registers are not stored. +// +// Returns: +// ippStsNullPtrErr The pointer to the features mask (pFeaturesMask) is NULL. +// ippStsNotSupportedCpu CPU is not supported. +// ippStsNoErr Ok +// +// Note: Only IA-32 and Intel(R) 64 are supported +*/ +IPPAPI( IppStatus, ippGetCpuFeatures, ( Ipp64u* pFeaturesMask, + Ipp32u pCpuidInfoRegs[4] ) ) + +/* +// Name: ippGetEnabledCpuFeatures +// Purpose: Detects enabled features for loaded libraries +// Returns: Features mask +// Features mask values are defined in the ippdefs.h +// [ 0] - ippCPUID_MMX +// [ 1] - ippCPUID_SSE +// [ 2] - ippCPUID_SSE2 +// [ 3] - ippCPUID_SSE3 +// [ 4] - ippCPUID_SSSE3 +// [ 5] - ippCPUID_MOVBE +// [ 6] - ippCPUID_SSE41 +// [ 7] - ippCPUID_SSE42 +// [ 8] - ippCPUID_AVX +// [ 9] - ippAVX_ENABLEDBYOS +// [10] - ippCPUID_AES +// [11] - ippCPUID_CLMUL +// [12] - ippCPUID_ABR +// [13] - ippCPUID_RDRAND +// [14] - ippCPUID_F16C +// [15] - ippCPUID_AVX2 +// [16] - ippCPUID_ADCOX +// [17] - ippCPUID_RDSEED +// [18] - ippCPUID_PREFETCHW +// [19] - ippCPUID_SHA +// [20:63] - Reserved +// +*/ +IPPAPI( Ipp64u, ippGetEnabledCpuFeatures, ( void ) ) + +/* //////////////////////////////////////////////////////////////////////////// +// Name: ippSetCpuFeatures +// +// Purpose: Changes the set of enabled/disabled CPU features. +// This function sets the processor-specific code of the Intel IPP +// library according to the processor features specified in cpuFeatures. +// +// Return: +// ippStsNoErr No errors. +// Warnings: +// ippStsFeatureNotSupported Current CPU doesn't support at least 1 of the +// desired features; +// ippStsUnknownFeature At least one of the desired features is unknown; +// ippStsFeaturesCombination Wrong combination of features; +// ippStsCpuMismatch Indicates that the specified processor features +// are not valid. Previously set code is used. +// +// Arguments: +// cpuFeatures Desired features to support by the library +// (see ippdefs.h for ippCPUID_XX definition) +// +// NOTE: this function can re-initializes dispatcher and after the +// call another library (letter) may work +// CAUTION: At the moment of this function excecution no any other IPP +// function has to be working +// +// The next pre-defined sets of features can be used: +// 32-bit code: +// #define PX_FM ( ippCPUID_MMX | ippCPUID_SSE ) +// #define W7_FM ( PX_FM | ippCPUID_SSE2 ) +// #define V8_FM ( W7_FM | ippCPUID_SSE3 | ippCPUID_SSSE3 ) +// #define S8_FM ( V8_FM | ippCPUID_MOVBE ) +// #define P8_FM ( V8_FM | ippCPUID_SSE41 | ippCPUID_SSE42 | ippCPUID_AES | ippCPUID_CLMUL | ippCPUID_SHA ) +// #define G9_FM ( P8_FM | ippCPUID_AVX | ippAVX_ENABLEDBYOS | ippCPUID_RDRAND | ippCPUID_F16C ) +// #define H9_FM ( G9_FM | ippCPUID_AVX2 | ippCPUID_MOVBE | ippCPUID_ADCOX | ippCPUID_RDSEED | ippCPUID_PREFETCHW ) +// +// 64-bit code: +// #define PX_FM ( ippCPUID_MMX | ippCPUID_SSE | ippCPUID_SSE2 ) +// #define M7_FM ( PX_FM | ippCPUID_SSE3 ) +// #define N8_FM ( S8_FM ) +// #define U8_FM ( V8_FM ) +// #define Y8_FM ( P8_FM ) +// #define E9_FM ( G9_FM ) +// #define L9_FM ( H9_FM ) +// +*/ + +IPPAPI( IppStatus, ippSetCpuFeatures,( Ipp64u cpuFeatures )) + +#if defined (_IPP_STDCALL_CDECL) + #undef _IPP_STDCALL_CDECL + #define __stdcall __cdecl +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __IPPCORE_H__ */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/include/ippcp.h b/sgx-jvm/linux-sgx/external/crypto_px/include/ippcp.h new file mode 100755 index 0000000000..48d1d81cce --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/include/ippcp.h @@ -0,0 +1,327 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined( __IPPCP_H__ ) || defined( _OWN_BLDPCS ) +#define __IPPCP_H__ + + +#if defined (_WIN32_WCE) && defined (_M_IX86) && defined (__stdcall) + #define _IPP_STDCALL_CDECL + #undef __stdcall +#endif + + +#ifndef __IPPDEFS_H__ + #include "ippdefs.h" +#endif + +#ifndef __IPPCPDEFS_H__ + #include "ippcpdefs.h" +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ///////////////////////////////////////////////////////////////////////////// +// Name: ippcpGetLibVersion +// Purpose: getting of the library version +// Returns: the structure of information about version of ippCP library +// Parameters: +// +// Notes: not necessary to release the returned structure +*/ +IPPAPI( const IppLibraryVersion*, ippcpGetLibVersion, (void) ) + + +/* +// AES +*/ +IPPAPI(IppStatus, ippsAESGetSize,(int *pSize)) +IPPAPI(IppStatus, ippsAESInit,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx, int ctxSize)) + +/* AES-CTR */ +IPPAPI(IppStatus, ippsAESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsAESSpec* pCtx, + Ipp8u* pCtrValue, int ctrNumBitSize)) +IPPAPI(IppStatus, ippsAESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, + const IppsAESSpec* pCtx, + Ipp8u* pCtrValue, int ctrNumBitSize)) + +/* AES-GCM */ +IPPAPI(IppStatus, ippsAES_GCMGetSize,(int * pSize)) +IPPAPI(IppStatus, ippsAES_GCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_GCMState* pState, int ctxSize)) + +IPPAPI(IppStatus, ippsAES_GCMReset,(IppsAES_GCMState* pState)) +IPPAPI(IppStatus, ippsAES_GCMProcessIV,(const Ipp8u* pIV, int ivLen, + IppsAES_GCMState* pState)) +IPPAPI(IppStatus, ippsAES_GCMProcessAAD,(const Ipp8u* pAAD, int ivAAD, + IppsAES_GCMState* pState)) +IPPAPI(IppStatus, ippsAES_GCMStart,(const Ipp8u* pIV, int ivLen, + const Ipp8u* pAAD, int aadLen, + IppsAES_GCMState* pState)) +IPPAPI(IppStatus, ippsAES_GCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, ippsAES_GCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, ippsAES_GCMGetTag,(Ipp8u* pDstTag, int tagLen, const IppsAES_GCMState* pState)) + +/* AES-CMAC */ +IPPAPI(IppStatus, ippsAES_CMACGetSize,(int* pSize)) +IPPAPI(IppStatus, ippsAES_CMACInit,(const Ipp8u* pKey, int keyLen, IppsAES_CMACState* pState, int ctxSize)) + +IPPAPI(IppStatus, ippsAES_CMACUpdate,(const Ipp8u* pSrc, int len, IppsAES_CMACState* pState)) +IPPAPI(IppStatus, ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pState)) +IPPAPI(IppStatus, ippsAES_CMACGetTag,(Ipp8u* pMD, int mdLen, const IppsAES_CMACState* pState)) + +/* +// hash +*/ +IPPAPI(IppStatus, ippsHashGetSize,(int* pSize)) +IPPAPI(IppStatus, ippsHashInit,(IppsHashState* pCtx, IppHashAlgId hashAlg)) + +IPPAPI(IppStatus, ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pCtx)) +IPPAPI(IppStatus, ippsHashGetTag,(Ipp8u* pMD, int tagLen, const IppsHashState* pCtx)) +IPPAPI(IppStatus, ippsHashFinal,(Ipp8u* pMD, IppsHashState* pCtx)) +IPPAPI(IppStatus, ippsHashMessage,(const Ipp8u* pMsg, int len, Ipp8u* pMD, IppHashAlgId hashAlg)) + +IPPAPI(IppStatus, ippsMGF,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, IppHashAlgId hashAlg)) + +IPPAPI(IppStatus, ippsHMAC_GetSize,(int* pSize)) +IPPAPI(IppStatus, ippsHMAC_Init,(const Ipp8u* pKey, int keyLen, IppsHMACState* pCtx, IppHashAlgId hashAlg)) + +IPPAPI(IppStatus, ippsHMAC_Update,(const Ipp8u* pSrc, int len, IppsHMACState* pCtx)) +IPPAPI(IppStatus, ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) +IPPAPI(IppStatus, ippsHMAC_GetTag,(Ipp8u* pMD, int mdLen, const IppsHMACState* pCtx)) +IPPAPI(IppStatus, ippsHMAC_Message,(const Ipp8u* pMsg, int msgLen, + const Ipp8u* pKey, int keyLen, + Ipp8u* pMD, int mdLen, + IppHashAlgId hashAlg)) + +/* +// Big Number Integer Arithmetic +*/ +IPPAPI(IppStatus, ippsBigNumGetSize,(int length, int* pSize)) +IPPAPI(IppStatus, ippsBigNumInit,(int length, IppsBigNumState* pBN)) + +IPPAPI(IppStatus, ippsSet_BN,(IppsBigNumSGN sgn, + int length, const Ipp32u* pData, + IppsBigNumState* pBN)) +IPPAPI(IppStatus, ippsRef_BN,(IppsBigNumSGN* pSgn, int* bitSize, Ipp32u** const ppData, + const IppsBigNumState* pBN)) + +IPPAPI(IppStatus, ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) +IPPAPI(IppStatus, ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) +IPPAPI(IppStatus, ippsDiv_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pQ, IppsBigNumState* pR)) +IPPAPI(IppStatus, ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) +IPPAPI(IppStatus, ippsCmp_BN,(const IppsBigNumState* pA, const IppsBigNumState* pB, Ipp32u* pResult)) +IPPAPI(IppStatus, ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) + +IPPAPI(IppStatus, ippsSetOctString_BN,(const Ipp8u* pStr, int strLen, IppsBigNumState* pBN)) +IPPAPI(IppStatus, ippsGetOctString_BN,(Ipp8u* pStr, int strLen, const IppsBigNumState* pBN)) + +/* +// Montgomery Operations +*/ +IPPAPI(IppStatus, ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) +IPPAPI(IppStatus, ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) +IPPAPI(IppStatus, ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) +IPPAPI(IppStatus, ippsMontMul, (const IppsBigNumState* pA, const IppsBigNumState* pB, IppsMontState* m, IppsBigNumState* pR)) + +/* +// PRNG +*/ +IPPAPI(IppStatus, ippsPRNGGetSize,(int* pSize)) +IPPAPI(IppStatus, ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) + +/* +// Prime Number Generation +*/ +IPPAPI(IppStatus, ippsPrimeGetSize,(int nMaxBits, int* pSize)) +IPPAPI(IppStatus, ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) + + +/* +// RSA +*/ +IPPAPI(IppStatus, ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) +IPPAPI(IppStatus, ippsRSA_InitPublicKey,(int rsaModulusBitSize, int publicExpBitSize, + IppsRSAPublicKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, ippsRSA_SetPublicKey,(const IppsBigNumState* pModulus, + const IppsBigNumState* pPublicExp, + IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, ippsRSA_GetPublicKey,(IppsBigNumState* pModulus, + IppsBigNumState* pPublicExp, + const IppsRSAPublicKeyState* pKey)) + +IPPAPI(IppStatus, ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) +IPPAPI(IppStatus, ippsRSA_InitPrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, + IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, ippsRSA_SetPrivateKeyType1,(const IppsBigNumState* pModulus, + const IppsBigNumState* pPrivateExp, + IppsRSAPrivateKeyState* pKey)) + +IPPAPI(IppStatus, ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) +IPPAPI(IppStatus, ippsRSA_InitPrivateKeyType2,(int factorPbitSize, int factorQbitSize, + IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, ippsRSA_SetPrivateKeyType2,(const IppsBigNumState* pFactorP, + const IppsBigNumState* pFactorQ, + const IppsBigNumState* pCrtExpP, + const IppsBigNumState* pCrtExpQ, + const IppsBigNumState* pInverseQ, + IppsRSAPrivateKeyState* pKey)) + +IPPAPI(IppStatus, ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) + +IPPAPI(IppStatus, ippsRSA_Encrypt,(const IppsBigNumState* pPtxt, + IppsBigNumState* pCtxt, + const IppsRSAPublicKeyState* pKey, + Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, ippsRSA_Decrypt,(const IppsBigNumState* pCtxt, + IppsBigNumState* pPtxt, + const IppsRSAPrivateKeyState* pKey, + Ipp8u* pScratchBuffer)) + +IPPAPI(IppStatus, ippsRSA_ValidateKeys,(int* pResult, + const IppsRSAPublicKeyState* pPublicKey, + const IppsRSAPrivateKeyState* pPrivateKeyType2, + const IppsRSAPrivateKeyState* pPrivateKeyType1, + Ipp8u* pScratchBuffer, + int nTrials, + IppsPrimeState* pPrimeGen, + IppBitSupplier rndFunc, void* pRndParam)) + +/* encryption scheme: RSAES-OAEP */ +IPPAPI(IppStatus, ippsRSAEncrypt_OAEP,(const Ipp8u* pSrc, int srcLen, + const Ipp8u* pLabel, int labLen, + const Ipp8u* pSeed, + Ipp8u* pDst, + const IppsRSAPublicKeyState* pKey, + IppHashAlgId hashAlg, + Ipp8u* pBuffer)) +IPPAPI(IppStatus, ippsRSA_OAEPEncrypt_SHA256,(const Ipp8u* pSrc, int srcLen, + const Ipp8u* pLabel, int labLen, + const Ipp8u* pSeed, + Ipp8u* pDst, + const IppsRSAPublicKeyState* pKey, + Ipp8u* pBuffer)) + +/* signature scheme : RSA-SSA-PKCS1-v1_5 */ +IPPAPI(IppStatus, ippsRSASign_PKCS1v15,(const Ipp8u* pMsg, int msgLen, + Ipp8u* pSign, + const IppsRSAPrivateKeyState* pPrvKey, + const IppsRSAPublicKeyState* pPubKey, + IppHashAlgId hashAlg, + Ipp8u* pBuffer)) + + +IPPAPI(IppStatus, ippsRSAVerify_PKCS1v15,(const Ipp8u* pMsg, int msgLen, + const Ipp8u* pSign, int* pIsValid, + const IppsRSAPublicKeyState* pKey, + IppHashAlgId hashAlg, + Ipp8u* pBuffer)) + + +/* +// EC Cryptography +*/ +IPPAPI(IppStatus, ippsECCPGetSize,(int feBitSize, int* pSize)) +IPPAPI(IppStatus, ippsECCPInit,(int feBitSize, IppsECCPState* pECC)) + +IPPAPI(IppStatus, ippsECCPSet,(const IppsBigNumState* pPrime, + const IppsBigNumState* pA, const IppsBigNumState* pB, + const IppsBigNumState* pGX,const IppsBigNumState* pGY,const IppsBigNumState* pOrder, + int cofactor, + IppsECCPState* pECC)) + +IPPAPI(IppStatus, ippsECCPSetStd,(IppECCType flag, IppsECCPState* pECC)) + + +IPPAPI(IppStatus, ippsECCPPointGetSize,(int feBitSize, int* pSize)) +IPPAPI(IppStatus, ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) + +IPPAPI(IppStatus, ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, + IppsECCPPointState* pPoint, IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pECC)) + +IPPAPI(IppStatus, ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, + const IppsECCPPointState* pPoint, IppsECCPState* pECC)) + +IPPAPI(IppStatus, ippsECCPCheckPoint,(const IppsECCPPointState* pP, + IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, + IppECResult* pResult, IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPNegativePoint,(const IppsECCPPointState* pP, + IppsECCPPointState* pR, IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, + IppsECCPPointState* pR, IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, + IppsECCPPointState* pR, IppsECCPState* pECC)) + +IPPAPI(IppStatus, ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, + IppsECCPState* pECC, + IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, ippsECCPPublicKey,(const IppsBigNumState* pPrivate, + IppsECCPPointState* pPublic, + IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, + IppBool regular, + IppsECCPState* pECC)) + +IPPAPI(IppStatus, ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, + const IppsECCPPointState* pPublicB, + IppsBigNumState* pShare, + IppsECCPState* pECC)) + +IPPAPI(IppStatus, ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, + const IppsBigNumState* pPrivate, + IppsBigNumState* pSignX, IppsBigNumState* pSignY, + IppsECCPState* pECC)) +IPPAPI(IppStatus, ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, + const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, + IppECResult* pResult, + IppsECCPState* pECC)) + +#ifdef __cplusplus +} +#endif + +#if defined (_IPP_STDCALL_CDECL) + #undef _IPP_STDCALL_CDECL + #define __stdcall __cdecl +#endif + +#endif /* __IPPCP_H__ */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/include/ippcpdefs.h b/sgx-jvm/linux-sgx/external/crypto_px/include/ippcpdefs.h new file mode 100755 index 0000000000..612ed50dec --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/include/ippcpdefs.h @@ -0,0 +1,211 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#ifndef __IPPCPDEFS_H__ +#define __IPPCPDEFS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +// AES +*/ +#define IPP_AES_BLOCK_BITSIZE (128) /* cipher blocksizes (bits) */ + +typedef enum { /* cipher keysizes (bits) */ + ippRijndaelKey128 = 128, IppsRijndaelKey128 = 128, /* 128-bit key */ + ippRijndaelKey192 = 192, IppsRijndaelKey192 = 192, /* 192-bit key */ + ippRijndaelKey256 = 256, IppsRijndaelKey256 = 256 /* 256-bit key */ +} IppsRijndaelKeyLength; + +typedef struct _cpRijndael128 IppsAESSpec; +typedef struct _cpAES_GCM IppsAES_GCMState; +typedef struct _cpAES_CMAC IppsAES_CMACState; + + +/* +// hash +*/ +typedef enum { + ippHashAlg_Unknown, + ippHashAlg_SHA1, + ippHashAlg_SHA256, + ippHashAlg_SHA224, + ippHashAlg_SHA512, + ippHashAlg_SHA384, + ippHashAlg_MD5, + ippHashAlg_SHA512_224, + ippHashAlg_SHA512_256, + ippHashAlg_MaxNo +} IppHashAlgId; + +#define IPP_ALG_HASH_UNKNOWN (ippHashAlg_Unknown) /* unknown */ +#define IPP_ALG_HASH_SHA1 (ippHashAlg_SHA1) /* SHA1 */ +#define IPP_ALG_HASH_SHA256 (ippHashAlg_SHA256) /* SHA256 */ +#define IPP_ALG_HASH_SHA224 (ippHashAlg_SHA224) /* SHA224 or SHA256/224 */ +#define IPP_ALG_HASH_SHA512 (ippHashAlg_SHA512) /* SHA512 */ +#define IPP_ALG_HASH_SHA384 (ippHashAlg_SHA384) /* SHA384 or SHA512/384 */ +#define IPP_ALG_HASH_MD5 (ippHashAlg_MD5) /* MD5 */ +#define IPP_ALG_HASH_SHA512_224 (ippHashAlg_SHA512_224) /* SHA512/224 */ +#define IPP_ALG_HASH_SHA512_256 (ippHashAlg_SHA512_256) /* SHA512/256 */ +#define IPP_ALG_HASH_LIMIT (ippHashAlg_MaxNo) /* hash alg limiter*/ + +#define IPP_SHA1_DIGEST_BITSIZE 160 /* digest size (bits) */ +#define IPP_SHA256_DIGEST_BITSIZE 256 +#define IPP_SHA224_DIGEST_BITSIZE 224 +#define IPP_SHA384_DIGEST_BITSIZE 384 +#define IPP_SHA512_DIGEST_BITSIZE 512 +#define IPP_MD5_DIGEST_BITSIZE 128 +#define IPP_SHA512_224_DIGEST_BITSIZE 224 +#define IPP_SHA512_256_DIGEST_BITSIZE 256 + +typedef struct _cpHashCtx IppsHashState; +typedef struct _cpHMAC IppsHMACState; + + +/* +// Big Number Integer Arithmetic +*/ +#define BN_MAXBITSIZE (16*1024) /* bn max size (bits) */ + +/* operation results */ +#define IPP_IS_EQ (0) +#define IPP_IS_GT (1) +#define IPP_IS_LT (2) +#define IPP_IS_NE (3) +#define IPP_IS_NA (4) + +#define IPP_IS_PRIME (5) +#define IPP_IS_COMPOSITE (6) + +#define IPP_IS_VALID (7) +#define IPP_IS_INVALID (8) +#define IPP_IS_INCOMPLETE (9) +#define IPP_IS_ATINFINITY (10) + +#define IS_ZERO IPP_IS_EQ +#define GREATER_THAN_ZERO IPP_IS_GT +#define LESS_THAN_ZERO IPP_IS_LT +#define IS_PRIME IPP_IS_PRIME +#define IS_COMPOSITE IPP_IS_COMPOSITE +#define IS_VALID_KEY IPP_IS_VALID +#define IS_INVALID_KEY IPP_IS_INVALID +#define IS_INCOMPLETED_KEY IPP_IS_INCOMPLETE + +typedef enum { + ippBigNumNEG = 0, IppsBigNumNEG = 0, + ippBigNumPOS = 1, IppsBigNumPOS = 1 +} IppsBigNumSGN; + +typedef enum { + ippBinaryMethod = 0, IppsBinaryMethod = 0, + ippSlidingWindows = 1, IppsSlidingWindows = 1 +} IppsExpMethod; + +typedef struct _cpBigNum IppsBigNumState; +typedef struct _cpMontgomery IppsMontState; +typedef struct _cpPRNG IppsPRNGState; +typedef struct _cpPrime IppsPrimeState; + +/* External Bit Supplier */ +typedef IppStatus (__STDCALL *IppBitSupplier)(Ipp32u* pRand, int nBits, void* pEbsParams); + + +/* +// RSA +*/ +#define MIN_RSA_SIZE (8) +#define MAX_RSA_SIZE (4096) + +typedef struct _cpRSA IppsRSAState; +typedef struct _cpRSA_public_key IppsRSAPublicKeyState; +typedef struct _cpRSA_private_key IppsRSAPrivateKeyState; + + +/* +// EC Cryptography +*/ +#define EC_GFP_MAXBITSIZE (1024) + +typedef struct _cpECCP IppsECCPState; +typedef struct _cpECCPPoint IppsECCPPointState; + +/* operation result */ +typedef enum { + ippECValid, /* validation pass successfully */ + + ippECCompositeBase, /* field based on composite */ + ippECComplicatedBase, /* number of non-zero terms in the polynomial (> PRIME_ARR_MAX) */ + ippECIsZeroDiscriminant,/* zero discriminant */ + ippECCompositeOrder, /* composite order of base point */ + ippECInvalidOrder, /* invalid base point order */ + ippECIsWeakMOV, /* weak Meneze-Okamoto-Vanstone reduction attack */ + ippECIsWeakSSSA, /* weak Semaev-Smart,Satoh-Araki reduction attack */ + ippECIsSupersingular, /* supersingular curve */ + + ippECInvalidPrivateKey, /* !(0 < Private < order) */ + ippECInvalidPublicKey, /* (order*PublicKey != Infinity) */ + ippECInvalidKeyPair, /* (Private*BasePoint != PublicKey) */ + + ippECPointOutOfGroup, /* out of group (order*P != Infinity) */ + ippECPointIsAtInfinite, /* point (P=(Px,Py)) at Infinity */ + ippECPointIsNotValid, /* point (P=(Px,Py)) out-of EC */ + + ippECPointIsEqual, /* compared points are equal */ + ippECPointIsNotEqual, /* compared points are different */ + + ippECInvalidSignature /* invalid signature */ +} IppECResult; + +typedef enum { + ippECarbitrary =0x00000, IppECCArbitrary = 0x00000, /* arbitrary ECC */ + + ippECPstd = 0x10000, IppECCPStd = 0x10000, /* random (recommended) EC over FG(p): */ + ippECPstd112r1 = ippECPstd, IppECCPStd112r1 = IppECCPStd, /* secp112r1 curve */ + ippECPstd112r2 = ippECPstd+1, IppECCPStd112r2 = IppECCPStd+1, /* secp112r2 curve */ + ippECPstd128r1 = ippECPstd+2, IppECCPStd128r1 = IppECCPStd+2, /* secp128r1 curve */ + ippECPstd128r2 = ippECPstd+3, IppECCPStd128r2 = IppECCPStd+3, /* secp128r2 curve */ + ippECPstd160r1 = ippECPstd+4, IppECCPStd160r1 = IppECCPStd+4, /* secp160r1 curve */ + ippECPstd160r2 = ippECPstd+5, IppECCPStd160r2 = IppECCPStd+5, /* secp160r2 curve */ + ippECPstd192r1 = ippECPstd+6, IppECCPStd192r1 = IppECCPStd+6, /* secp192r1 curve */ + ippECPstd224r1 = ippECPstd+7, IppECCPStd224r1 = IppECCPStd+7, /* secp224r1 curve */ + ippECPstd256r1 = ippECPstd+8, IppECCPStd256r1 = IppECCPStd+8, /* secp256r1 curve */ + ippECPstd384r1 = ippECPstd+9, IppECCPStd384r1 = IppECCPStd+9, /* secp384r1 curve */ + ippECPstd521r1 = ippECPstd+10, IppECCPStd521r1 = IppECCPStd+10, /* secp521r1 curve */ +} IppsECType, IppECCType; + + +#ifdef __cplusplus +} +#endif + +#endif /* __IPPCPDEFS_H__ */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/include/ippdefs.h b/sgx-jvm/linux-sgx/external/crypto_px/include/ippdefs.h new file mode 100755 index 0000000000..1e78d0c76f --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/include/ippdefs.h @@ -0,0 +1,129 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#ifndef __IPPDEFS_H__ +#define __IPPDEFS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +#if defined (_WIN64) +#define _INTEL_PLATFORM "intel64/" +#elif defined (_WIN32) +#define _INTEL_PLATFORM "ia32/" +#endif + +#if !defined( IPPAPI ) + + #if defined( IPP_W32DLL ) && (defined( _WIN32 ) || defined( _WIN64 )) + #if defined( _MSC_VER ) || defined( __ICL ) + #define IPPAPI( type,name,arg ) \ + __declspec(dllimport) type __STDCALL name arg; + #else + #define IPPAPI( type,name,arg ) type __STDCALL name arg; + #endif + #else + #define IPPAPI( type,name,arg ) type __STDCALL name arg; + #endif + +#endif + +#if (defined( __ICL ) || defined( __ECL ) || defined(_MSC_VER)) && !defined( _PCS ) && !defined( _PCS_GENSTUBS ) + #if( __INTEL_COMPILER >= 1100 ) /* icl 11.0 supports additional comment */ + #if( _MSC_VER >= 1400 ) + #define IPP_DEPRECATED( comment ) __declspec( deprecated ( comment )) + #else + #pragma message ("your icl version supports additional comment for deprecated functions but it can't be displayed") + #pragma message ("because internal _MSC_VER macro variable setting requires compatibility with MSVC7.1") + #pragma message ("use -Qvc8 switch for icl command line to see these additional comments") + #define IPP_DEPRECATED( comment ) __declspec( deprecated ) + #endif + #elif( _MSC_FULL_VER >= 140050727 )&&( !defined( __INTEL_COMPILER )) /* VS2005 supports additional comment */ + #define IPP_DEPRECATED( comment ) __declspec( deprecated ( comment )) + #elif( _MSC_VER <= 1200 )&&( !defined( __INTEL_COMPILER )) /* VS 6 doesn't support deprecation */ + #define IPP_DEPRECATED( comment ) + #else + #define IPP_DEPRECATED( comment ) __declspec( deprecated ) + #endif +#elif (defined(__ICC) || defined(__ECC) || defined( __GNUC__ )) && !defined( _PCS ) && !defined( _PCS_GENSTUBS ) + #if defined( __GNUC__ ) + #if __GNUC__ >= 4 && __GNUC_MINOR__ >= 5 + #define IPP_DEPRECATED( message ) __attribute__(( deprecated( message ))) + #else + #define IPP_DEPRECATED( message ) __attribute__(( deprecated )) + #endif + #else + #define IPP_DEPRECATED( comment ) __attribute__(( deprecated )) + #endif +#else + #define IPP_DEPRECATED( comment ) +#endif + +#if (defined( __ICL ) || defined( __ECL ) || defined(_MSC_VER)) + #if !defined( _IPP_NO_DEFAULT_LIB ) + #if (( defined( _IPP_PARALLEL_DYNAMIC ) && !defined( _IPP_PARALLEL_STATIC ) && !defined( _IPP_SEQUENTIAL_DYNAMIC ) && !defined( _IPP_SEQUENTIAL_STATIC )) || \ + (!defined( _IPP_PARALLEL_DYNAMIC ) && defined( _IPP_PARALLEL_STATIC ) && !defined( _IPP_SEQUENTIAL_DYNAMIC ) && !defined( _IPP_SEQUENTIAL_STATIC )) || \ + (!defined( _IPP_PARALLEL_DYNAMIC ) && !defined( _IPP_PARALLEL_STATIC ) && defined( _IPP_SEQUENTIAL_DYNAMIC ) && !defined( _IPP_SEQUENTIAL_STATIC )) || \ + (!defined( _IPP_PARALLEL_DYNAMIC ) && !defined( _IPP_PARALLEL_STATIC ) && !defined( _IPP_SEQUENTIAL_DYNAMIC ) && defined( _IPP_SEQUENTIAL_STATIC ))) + #elif (!defined( _IPP_PARALLEL_DYNAMIC ) && !defined( _IPP_PARALLEL_STATIC ) && !defined( _IPP_SEQUENTIAL_DYNAMIC ) && !defined( _IPP_SEQUENTIAL_STATIC )) + #define _IPP_NO_DEFAULT_LIB + #else + #error Illegal combination of _IPP_PARALLEL_DYNAMIC/_IPP_PARALLEL_STATIC/_IPP_SEQUENTIAL_DYNAMIC/_IPP_SEQUENTIAL_STATIC, only one definition can be defined + #endif + #endif +#else + #define _IPP_NO_DEFAULT_LIB + #if (defined( _IPP_PARALLEL_DYNAMIC ) || defined( _IPP_PARALLEL_STATIC ) || defined(_IPP_SEQUENTIAL_DYNAMIC) || defined(_IPP_SEQUENTIAL_STATIC)) + #pragma message ("defines _IPP_PARALLEL_DYNAMIC/_IPP_PARALLEL_STATIC/_IPP_SEQUENTIAL_DYNAMIC/_IPP_SEQUENTIAL_STATIC do not have any effect in current configuration") + #endif +#endif + +#if !defined( _IPP_NO_DEFAULT_LIB ) + #if defined( _IPP_PARALLEL_STATIC ) + #pragma comment( lib, "libircmt" ) + #pragma comment( lib, "libmmt" ) + #pragma comment( lib, "svml_dispmt" ) + #pragma comment( lib, "libiomp5md" ) + #endif +#endif + +#include "ippbase.h" +#include "ipptypes.h" + +extern const IppiRect ippRectInfinite; + +#ifdef __cplusplus +} +#endif + +#endif /* __IPPDEFS_H__ */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/include/ipptypes.h b/sgx-jvm/linux-sgx/external/crypto_px/include/ipptypes.h new file mode 100755 index 0000000000..dedb27991c --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/include/ipptypes.h @@ -0,0 +1,1104 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#ifndef __IPPTYPES_H__ +#define __IPPTYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/*****************************************************************************/ +/* Below are ippCore domain specific definitions */ +/*****************************************************************************/ +#if !defined( _OWN_BLDPCS ) + +#define ippCPUID_MMX 0x00000001 /* Intel Architecture MMX technology supported */ +#define ippCPUID_SSE 0x00000002 /* Streaming SIMD Extensions */ +#define ippCPUID_SSE2 0x00000004 /* Streaming SIMD Extensions 2 */ +#define ippCPUID_SSE3 0x00000008 /* Streaming SIMD Extensions 3 */ +#define ippCPUID_SSSE3 0x00000010 /* Supplemental Streaming SIMD Extensions 3 */ +#define ippCPUID_MOVBE 0x00000020 /* The processor supports MOVBE instruction */ +#define ippCPUID_SSE41 0x00000040 /* Streaming SIMD Extensions 4.1 */ +#define ippCPUID_SSE42 0x00000080 /* Streaming SIMD Extensions 4.2 */ +#define ippCPUID_AVX 0x00000100 /* Advanced Vector Extensions instruction set */ +#define ippAVX_ENABLEDBYOS 0x00000200 /* The operating system supports AVX */ +#define ippCPUID_AES 0x00000400 /* AES instruction */ +#define ippCPUID_CLMUL 0x00000800 /* PCLMULQDQ instruction */ +#define ippCPUID_ABR 0x00001000 /* Reserved */ +#define ippCPUID_RDRAND 0x00002000 /* Read Random Number instructions */ +#define ippCPUID_F16C 0x00004000 /* Float16 instructions */ +#define ippCPUID_AVX2 0x00008000 /* Advanced Vector Extensions 2 instruction set */ +#define ippCPUID_ADCOX 0x00010000 /* ADCX and ADOX instructions */ +#define ippCPUID_RDSEED 0x00020000 /* The RDSEED instruction */ +#define ippCPUID_PREFETCHW 0x00040000 /* The PREFETCHW instruction */ +#define ippCPUID_SHA 0x00080000 /* Intel (R) SHA Extensions */ +#define ippCPUID_AVX512F 0x00100000 /* AVX-512 Foundation instructions */ +#define ippCPUID_AVX512CD 0x00200000 /* AVX-512 Conflict Detection instructions */ +#define ippCPUID_AVX512ER 0x00400000 /* AVX-512 Exponential & Reciprocal instructions*/ +#define ippCPUID_AVX512PF 0x00800000 /* AVX-512 Prefetch instructions */ +#define ippCPUID_AVX512BW 0x01000000 /* AVX-512 Byte & Word instructions */ +#define ippCPUID_AVX512DQ 0x02000000 /* AVX-512 DWord & QWord instructions */ +#define ippCPUID_AVX512VL 0x04000000 /* AVX-512 Vector Length extensions */ +#define ippCPUID_KNC 0x80000000 /* Intel(R) Xeon Phi(TM) Coprocessor */ +#if defined( _WIN32 ) || defined ( _WIN64 ) + #define ippCPUID_NOCHECK 0x8000000000000000L /* Force ippSetCpuFeatures to set CPU features without check */ +#else + #define ippCPUID_NOCHECK 0x8000000000000000LL +#endif + +#if defined( _WIN32 ) || defined ( _WIN64 ) + #define ippCPUID_GETINFO_A 0x616f666e69746567L /* Force ipp_GetCpuFeatures to work as cpuid instruction */ +#else + #define ippCPUID_GETINFO_A 0x616f666e69746567LL +#endif + +#define IPP_COUNT_OF( obj ) (sizeof(obj)/sizeof(obj[0])) + +/*****************************************************************************/ +/* Below are ippSP domain specific definitions */ +/*****************************************************************************/ +typedef enum { + ippRndZero, + ippRndNear, + ippRndFinancial, + ippRndHintAccurate=0x10 +} IppRoundMode; + + +typedef enum { + ippAlgHintNone, + ippAlgHintFast, + ippAlgHintAccurate +} IppHintAlgorithm; + +typedef enum { + ippCmpLess, + ippCmpLessEq, + ippCmpEq, + ippCmpGreaterEq, + ippCmpGreater +} IppCmpOp; + +typedef enum { + ippAlgAuto = 0x00000000, + ippAlgDirect = 0x00000001, + ippAlgFFT = 0x00000002, + ippAlgMask = 0x000000FF +} IppAlgType; + +typedef enum { + ippsNormNone = 0x00000000, /* default */ + ippsNormA = 0x00000100, /* biased normalization */ + ippsNormB = 0x00000200, /* unbiased normalization */ + ippsNormMask = 0x0000FF00 +} IppsNormOp; + +typedef enum { + ippNormInf = 0x00000001, + ippNormL1 = 0x00000002, + ippNormL2 = 0x00000004 +} IppNormType; + +enum { + IPP_FFT_DIV_FWD_BY_N = 1, + IPP_FFT_DIV_INV_BY_N = 2, + IPP_FFT_DIV_BY_SQRTN = 4, + IPP_FFT_NODIV_BY_ANY = 8 +}; + +enum { + IPP_DIV_FWD_BY_N = 1, + IPP_DIV_INV_BY_N = 2, + IPP_DIV_BY_SQRTN = 4, + IPP_NODIV_BY_ANY = 8 +}; + +typedef struct { + Ipp32f rho; + Ipp32f theta; +} IppPointPolar; + +typedef enum {ippWinBartlett,ippWinBlackman,ippWinHamming,ippWinHann,ippWinRect} IppWinType; + +typedef enum { ippButterworth, ippChebyshev1 } IppsIIRFilterType; + +typedef enum { ippZCR=0, ippZCXor, ippZCC } IppsZCType; + +#if !defined( _OWN_BLDPCS ) + +typedef struct { + int left; + int right; +} IppsROI; + +typedef struct RandUniState_8u IppsRandUniState_8u; +typedef struct RandUniState_16s IppsRandUniState_16s; +typedef struct RandUniState_32f IppsRandUniState_32f; +typedef struct RandUniState_64f IppsRandUniState_64f; + +typedef struct RandGaussState_8u IppsRandGaussState_8u; +typedef struct RandGaussState_16s IppsRandGaussState_16s; +typedef struct RandGaussState_32f IppsRandGaussState_32f; +typedef struct RandGaussState_64f IppsRandGaussState_64f; + +typedef struct FFTSpec_C_32fc IppsFFTSpec_C_32fc; +typedef struct FFTSpec_C_32f IppsFFTSpec_C_32f; +typedef struct FFTSpec_R_32f IppsFFTSpec_R_32f; + +typedef struct FFTSpec_C_64fc IppsFFTSpec_C_64fc; +typedef struct FFTSpec_C_64f IppsFFTSpec_C_64f; +typedef struct FFTSpec_R_64f IppsFFTSpec_R_64f; + +typedef struct DFTSpec_C_32fc IppsDFTSpec_C_32fc; +typedef struct DFTSpec_C_32f IppsDFTSpec_C_32f; +typedef struct DFTSpec_R_32f IppsDFTSpec_R_32f; + +typedef struct DFTSpec_C_64fc IppsDFTSpec_C_64fc; +typedef struct DFTSpec_C_64f IppsDFTSpec_C_64f; +typedef struct DFTSpec_R_64f IppsDFTSpec_R_64f; + +typedef struct DCTFwdSpec_32f IppsDCTFwdSpec_32f; +typedef struct DCTInvSpec_32f IppsDCTInvSpec_32f; + +typedef struct DCTFwdSpec_64f IppsDCTFwdSpec_64f; +typedef struct DCTInvSpec_64f IppsDCTInvSpec_64f; + +typedef struct sWTFwdState_32f IppsWTFwdState_32f; +typedef struct sWTFwdState_8u32f IppsWTFwdState_8u32f; +typedef struct sWTFwdState_16s32f IppsWTFwdState_16s32f; +typedef struct sWTFwdState_16u32f IppsWTFwdState_16u32f; +typedef struct sWTInvState_32f IppsWTInvState_32f; +typedef struct sWTInvState_32f8u IppsWTInvState_32f8u; +typedef struct sWTInvState_32f16s IppsWTInvState_32f16s; +typedef struct sWTInvState_32f16u IppsWTInvState_32f16u; + +typedef struct IIRState_32f IppsIIRState_32f; +typedef struct IIRState_32fc IppsIIRState_32fc; +typedef struct IIRState32f_16s IppsIIRState32f_16s; +typedef struct IIRState32fc_16sc IppsIIRState32fc_16sc; +typedef struct IIRState_64f IppsIIRState_64f; +typedef struct IIRState_64fc IppsIIRState_64fc; +typedef struct IIRState64f_32f IppsIIRState64f_32f; +typedef struct IIRState64fc_32fc IppsIIRState64fc_32fc; +typedef struct IIRState64f_32s IppsIIRState64f_32s; +typedef struct IIRState64fc_32sc IppsIIRState64fc_32sc; +typedef struct IIRState64f_16s IppsIIRState64f_16s; +typedef struct IIRState64fc_16sc IppsIIRState64fc_16sc; + +typedef struct FIRSpec_32f IppsFIRSpec_32f; +typedef struct FIRSpec_64f IppsFIRSpec_64f; +typedef struct FIRSpec_32fc IppsFIRSpec_32fc; +typedef struct FIRSpec_64fc IppsFIRSpec_64fc; + +typedef struct FIRLMSState_32f IppsFIRLMSState_32f; +typedef struct FIRLMSState32f_16s IppsFIRLMSState32f_16s; + +typedef struct HilbertSpec IppsHilbertSpec; + +typedef struct FIRSparseState_32f IppsFIRSparseState_32f; +typedef struct IIRSparseState_32f IppsIIRSparseState_32f; + +typedef struct ResamplingPolyphase_16s IppsResamplingPolyphase_16s; +typedef struct ResamplingPolyphaseFixed_16s IppsResamplingPolyphaseFixed_16s; +typedef struct ResamplingPolyphase_32f IppsResamplingPolyphase_32f; +typedef struct ResamplingPolyphaseFixed_32f IppsResamplingPolyphaseFixed_32f; + +#endif /* _OWN_BLDPCS */ + +/*****************************************************************************/ +/* Below are ippIP domain specific definitions */ +/*****************************************************************************/ +#define IPP_TEMPORAL_COPY 0x0 +#define IPP_NONTEMPORAL_STORE 0x01 +#define IPP_NONTEMPORAL_LOAD 0x02 + +typedef int IppEnum; + +#define IPP_DEG_TO_RAD( deg ) ( (deg)/180.0 * IPP_PI ) + +typedef enum { + ippiNormNone = 0x00000000, /* default */ + ippiNorm = 0x00000100, /* normalized form */ + ippiNormCoefficient = 0x00000200, /* correlation coefficient in the range [-1.0 ... 1.0] */ + ippiNormMask = 0x0000FF00 +} IppiNormOp; + +typedef enum { + ippiROIFull = 0x00000000, + ippiROIValid = 0x00010000, + ippiROISame = 0x00020000, + ippiROIMask = 0x00FF0000 +} IppiROIShape; + +typedef enum { + ippC0 = 0, + ippC1 = 1, + ippC2 = 2, + ippC3 = 3, + ippC4 = 4, + ippP2 = 5, + ippP3 = 6, + ippP4 = 7, + ippAC1 = 8, + ippAC4 = 9, + ippA0C4 = 10, + ippAP4 = 11 +} IppChannels; + +typedef enum _IppiBorderType { + ippBorderConst = 0, + ippBorderRepl = 1, + ippBorderWrap = 2, + ippBorderMirror = 3, /* left border: 012... -> 21012... */ + ippBorderMirrorR = 4, /* left border: 012... -> 210012... */ + ippBorderInMem = 6, + ippBorderTransp = 7, + ippBorderInMemTop = 0x0010, + ippBorderInMemBottom = 0x0020, + ippBorderInMemLeft = 0x0040, + ippBorderInMemRight = 0x0080 +} IppiBorderType; + +typedef enum { + ippAxsHorizontal, + ippAxsVertical, + ippAxsBoth, + ippAxs45, + ippAxs135 +} IppiAxis; + +typedef struct { + int x; + int y; + int width; + int height; +} IppiRect; + +typedef struct { + int x; + int y; +} IppiPoint; + +typedef struct { + int width; + int height; +} IppiSize; + +typedef struct { + Ipp32f x; + Ipp32f y; +} IppiPoint_32f; + +typedef enum _IppiMaskSize { + ippMskSize1x3 = 13, + ippMskSize1x5 = 15, + ippMskSize3x1 = 31, + ippMskSize3x3 = 33, + ippMskSize5x1 = 51, + ippMskSize5x5 = 55 +} IppiMaskSize; + +enum { + IPPI_INTER_NN = 1, + IPPI_INTER_LINEAR = 2, + IPPI_INTER_CUBIC = 4, + IPPI_INTER_CUBIC2P_BSPLINE, /* two-parameter cubic filter (B=1, C=0) */ + IPPI_INTER_CUBIC2P_CATMULLROM, /* two-parameter cubic filter (B=0, C=1/2) */ + IPPI_INTER_CUBIC2P_B05C03, /* two-parameter cubic filter (B=1/2, C=3/10) */ + IPPI_INTER_SUPER = 8, + IPPI_INTER_LANCZOS = 16, + IPPI_ANTIALIASING = (1 << 29), + IPPI_SUBPIXEL_EDGE = (1 << 30), + IPPI_SMOOTH_EDGE = (1 << 31) +}; + +typedef enum { + ippNearest = IPPI_INTER_NN, + ippLinear = IPPI_INTER_LINEAR, + ippCubic = IPPI_INTER_CUBIC2P_CATMULLROM, + ippLanczos = IPPI_INTER_LANCZOS, + ippHahn = 0, + ippSuper = IPPI_INTER_SUPER +} IppiInterpolationType; + +typedef enum { + ippPolyphase_1_2, + ippPolyphase_3_5, + ippPolyphase_2_3, + ippPolyphase_7_10, + ippPolyphase_3_4 +} IppiFraction; + +enum { + IPP_FASTN_ORIENTATION = 0x0001, + IPP_FASTN_NMS = 0x0002, + IPP_FASTN_CIRCLE = 0X0004, + IPP_FASTN_SCORE_MODE0 = 0X0020 +}; + +#if !defined( _OWN_BLDPCS ) + +typedef enum { + ippAlphaOver, + ippAlphaIn, + ippAlphaOut, + ippAlphaATop, + ippAlphaXor, + ippAlphaPlus, + ippAlphaOverPremul, + ippAlphaInPremul, + ippAlphaOutPremul, + ippAlphaATopPremul, + ippAlphaXorPremul, + ippAlphaPlusPremul +} IppiAlphaType; + +typedef struct DeconvFFTState_32f_C1R IppiDeconvFFTState_32f_C1R; +typedef struct DeconvFFTState_32f_C3R IppiDeconvFFTState_32f_C3R; +typedef struct DeconvLR_32f_C1R IppiDeconvLR_32f_C1R; +typedef struct DeconvLR_32f_C3R IppiDeconvLR_32f_C3R; + +typedef enum { + ippiFilterBilateralGauss = 100, + ippiFilterBilateralGaussFast = 101 +} IppiFilterBilateralType; + +typedef struct FilterBilateralSpec IppiFilterBilateralSpec; + +typedef enum { + ippDistNormL1 = 0x00000002 +} IppiDistanceMethodType; + +typedef enum { + ippResizeFilterHann, + ippResizeFilterLanczos +} IppiResizeFilterType; + +typedef struct ResizeFilterState IppiResizeFilterState; + +typedef struct { + Ipp32u borderLeft; + Ipp32u borderTop; + Ipp32u borderRight; + Ipp32u borderBottom; +} IppiBorderSize; + +typedef enum { + ippWarpForward, + ippWarpBackward, +} IppiWarpDirection; + +typedef enum { + ippWarpAffine, + ippWarpPerspective, + ippWarpBilinear, +} IppiWarpTransformType; + + +typedef struct ResizeSpec_32f IppiResizeSpec_32f; +typedef struct ResizeYUV422Spec IppiResizeYUV422Spec; +typedef struct ResizeYUV420Spec IppiResizeYUV420Spec; + +typedef struct ResizeSpec_64f IppiResizeSpec_64f; + +typedef struct IppiWarpSpec IppiWarpSpec; + +typedef struct FilterBorderSpec IppiFilterBorderSpec; + +typedef struct ThresholdAdaptiveSpec IppiThresholdAdaptiveSpec; + +typedef struct HistogramSpec IppiHistogramSpec; + +typedef struct { + int cvCompatible; /* openCV compatible output format */ + int cellSize; /* squre cell size (pixels) */ + int blockSize; /* square block size (pixels) */ + int blockStride; /* block displacement (the same for x- and y- directions) */ + int nbins; /* required number of bins */ + Ipp32f sigma; /* gaussian factor of HOG block weights */ + Ipp32f l2thresh; /* normalization factor */ + IppiSize winSize; /* detection window size (pixels) */ +} IppiHOGConfig; + +typedef struct FFT2DSpec_C_32fc IppiFFTSpec_C_32fc; +typedef struct FFT2DSpec_R_32f IppiFFTSpec_R_32f; + +typedef struct DFT2DSpec_C_32fc IppiDFTSpec_C_32fc; +typedef struct DFT2DSpec_R_32f IppiDFTSpec_R_32f; + +typedef struct DCT2DFwdSpec_32f IppiDCTFwdSpec_32f; +typedef struct DCT2DInvSpec_32f IppiDCTInvSpec_32f; + +typedef struct iWTFwdSpec_32f_C1R IppiWTFwdSpec_32f_C1R; +typedef struct iWTInvSpec_32f_C1R IppiWTInvSpec_32f_C1R; +typedef struct iWTFwdSpec_32f_C3R IppiWTFwdSpec_32f_C3R; +typedef struct iWTInvSpec_32f_C3R IppiWTInvSpec_32f_C3R; + +typedef struct MomentState64f IppiMomentState_64f; +typedef Ipp64f IppiHuMoment_64f[7]; + +typedef struct LUT_Spec IppiLUT_Spec; + +#define IPP_HOG_MAX_CELL (16) /* max size of CELL */ +#define IPP_HOG_MAX_BLOCK (64) /* max size of BLOCK */ +#define IPP_HOG_MAX_BINS (16) /* max number of BINS */ + +typedef struct _ipHOG IppiHOGSpec; + +#endif /* _OWN_BLDPCS */ + + + /**** Below are 3D Image (Volume) Processing specific definitions ****/ + +typedef struct { + int width; + int height; + int depth; +} IpprVolume; + +typedef struct { + int x; + int y; + int z; + int width; + int height; + int depth; +} IpprCuboid; + +typedef struct { + int x; + int y; + int z; +} IpprPoint; + +/*****************************************************************************/ +/* Below are ippCV domain specific definitions */ +/*****************************************************************************/ + +typedef enum _IppiDifferentialKernel +{ + ippFilterSobelVert, + ippFilterSobelHoriz, + ippFilterSobel, + ippFilterScharrVert, + ippFilterScharrHoriz, + ippFilterScharr, + ippFilterCentralDiffVert, + ippFilterCentralDiffHoriz, + ippFilterCentralDiff, +}IppiDifferentialKernel; + +#if !defined( _OWN_BLDPCS ) + +typedef enum _IppiKernelType { + ippKernelSobel = 0, + ippKernelScharr = 1, + ippKernelSobelNeg = 2 +} IppiKernelType; + +typedef enum _IppiNorm { + ippiNormInf = 0, + ippiNormL1 = 1, + ippiNormL2 = 2, + ippiNormFM = 3 +} IppiNorm; + +typedef struct ipcvMorphState IppiMorphState; +typedef struct ipcvMorphAdvState IppiMorphAdvState; +typedef struct ipcvMorphGrayState_8u IppiMorphGrayState_8u; +typedef struct ipcvMorphGrayState_32f IppiMorphGrayState_32f; + +typedef struct ipcvConvState IppiConvState; + +typedef struct _IppiConnectedComp { + Ipp64f area; /* area of the segmented component */ + Ipp64f value[3];/* gray scale value of the segmented component */ + IppiRect rect; /* bounding rectangle of the segmented component */ +} IppiConnectedComp; + +typedef struct PyramidState IppiPyramidState; + +typedef IppiPyramidState IppiPyramidDownState_8u_C1R; +typedef IppiPyramidState IppiPyramidDownState_16u_C1R; +typedef IppiPyramidState IppiPyramidDownState_32f_C1R; +typedef IppiPyramidState IppiPyramidDownState_8u_C3R; +typedef IppiPyramidState IppiPyramidDownState_16u_C3R; +typedef IppiPyramidState IppiPyramidDownState_32f_C3R; +typedef IppiPyramidState IppiPyramidUpState_8u_C1R; +typedef IppiPyramidState IppiPyramidUpState_16u_C1R; +typedef IppiPyramidState IppiPyramidUpState_32f_C1R; +typedef IppiPyramidState IppiPyramidUpState_8u_C3R; +typedef IppiPyramidState IppiPyramidUpState_16u_C3R; +typedef IppiPyramidState IppiPyramidUpState_32f_C3R; + + +typedef struct _IppiPyramid { + Ipp8u **pImage; + IppiSize *pRoi; + Ipp64f *pRate; + int *pStep; + Ipp8u *pState; + int level; +} IppiPyramid; + +typedef struct OptFlowPyrLK IppiOptFlowPyrLK; + +typedef IppiOptFlowPyrLK IppiOptFlowPyrLK_8u_C1R; +typedef IppiOptFlowPyrLK IppiOptFlowPyrLK_16u_C1R; +typedef IppiOptFlowPyrLK IppiOptFlowPyrLK_32f_C1R; + +typedef struct ipcvHaarClassifier_32f IppiHaarClassifier_32f; +typedef struct ipcvHaarClassifier_32s IppiHaarClassifier_32s; + +typedef struct ipcvFGHistogramState_8u_C1R IppFGHistogramState_8u_C1R; +typedef struct ipcvFGHistogramState_8u_C3R IppFGHistogramState_8u_C3R; + +typedef struct ipcvFGGaussianState_8u_C1R IppFGGaussianState_8u_C1R; +typedef struct ipcvFGGaussianState_8u_C3R IppFGGaussianState_8u_C3R; + +typedef enum _IppiInpaintFlag { + IPP_INPAINT_TELEA = 0, + IPP_INPAINT_NS = 1 +} IppiInpaintFlag; + +typedef struct ippcvFilterGaussianSpec IppFilterGaussianSpec; + +typedef struct ipcvInpaintState_8u IppiInpaintState_8u_C1R; +typedef struct ipcvInpaintState_8u IppiInpaintState_8u_C3R; + +typedef struct HoughProbSpec IppiHoughProbSpec; + +typedef struct FastNSpec IppiFastNSpec; + +typedef struct _IppiCornerFastN { + int x; + int y; + int cornerType; + int orientation; + float angle; + float score; +} IppiCornerFastN; + +typedef struct FGMMState_8u_C3R IppFGMMState_8u_C3R; + +typedef struct +{ + unsigned int numFrames; + unsigned int maxNGauss; + Ipp32f varInit; + Ipp32f varMin; + Ipp32f varMax; + Ipp32f varWBRatio; + Ipp32f bckgThr; + Ipp32f varNGRatio; + Ipp32f reduction; + Ipp8u shadowValue; + char shadowFlag; + Ipp32f shadowRatio; +} IppFGMModel; + +#endif /* _OWN_BLDPCS */ + +#define IPP_SEGMENT_QUEUE 0x01 +#define IPP_SEGMENT_DISTANCE 0x02 +#define IPP_SEGMENT_BORDER_4 0x40 +#define IPP_SEGMENT_BORDER_8 0x80 + +#define IPP_TRUNC(a,b) ((a)&~((b)-1)) +#define IPP_APPEND(a,b) (((a)+(b)-1)&~((b)-1)) + +/*****************************************************************************/ +/* Below are ippCC domain specific definitions */ +/*****************************************************************************/ +enum { + IPP_UPPER = 1, + IPP_LEFT = 2, + IPP_CENTER = 4, + IPP_RIGHT = 8, + IPP_LOWER = 16, + IPP_UPPER_LEFT = 32, + IPP_UPPER_RIGHT = 64, + IPP_LOWER_LEFT = 128, + IPP_LOWER_RIGHT = 256 +}; + +#if !defined( _OWN_BLDPCS ) + +typedef enum { + ippDitherNone, + ippDitherFS, + ippDitherJJN, + ippDitherStucki, + ippDitherBayer +} IppiDitherType; + +#endif /* _OWN_BLDPCS */ + +/*****************************************************************************/ +/* Below are ippCH domain specific definitions */ +/*****************************************************************************/ + +#if !defined( _OWN_BLDPCS ) + +typedef struct { + void *pFind; + int lenFind; +} IppRegExpFind; + +typedef struct RegExpState IppRegExpState; + +typedef enum { + ippFmtASCII = 0, + ippFmtUTF8 +} IppRegExpFormat; + +typedef struct RegExpReplaceState IppRegExpReplaceState; + +#endif /* _OWN_BLDPCS */ + +/*****************************************************************************/ +/* Below are ippDC domain specific definitions */ +/*****************************************************************************/ + +#if !defined ( _OWN_BLDPCS ) + +typedef struct MTFState_8u IppMTFState_8u; + +typedef enum { + ippBWTItohTanakaLimSort, + ippBWTItohTanakaUnlimSort, + ippBWTSuffixSort, + ippBWTAutoSort +} IppBWTSortAlgorithmHint; + +typedef struct LZSSState_8u IppLZSSState_8u; + +typedef struct LZ77State_8u IppLZ77State_8u; +typedef enum{ + IppLZ77FastCompr, + IppLZ77AverageCompr, + IppLZ77BestCompr +} IppLZ77ComprLevel; +typedef enum{ + IppLZ77NoChcksm, + IppLZ77Adler32, + IppLZ77CRC32 +} IppLZ77Chcksm; +typedef enum { + IppLZ77NoFlush, + IppLZ77SyncFlush, + IppLZ77FullFlush, + IppLZ77FinishFlush +} IppLZ77Flush; +typedef struct IppLZ77Pairs_16u { + Ipp16u length; + Ipp16u offset; +} IppLZ77Pair; +typedef enum { + IppLZ77StatusInit, + IppLZ77StatusLZ77Process, + IppLZ77StatusHuffProcess, + IppLZ77StatusFinal +} IppLZ77DeflateStatus; +typedef enum { + IppLZ77UseFixed, + IppLZ77UseDynamic, + IppLZ77UseStored +} IppLZ77HuffMode; +typedef enum { + IppLZ77InflateStatusInit, + IppLZ77InflateStatusHuffProcess, + IppLZ77InflateStatusLZ77Process, + IppLZ77InflateStatusFinal +} IppLZ77InflateStatus; + +typedef struct IppInflateState { + const Ipp8u* pWindow; /* pointer to the sliding window + (the dictionary for the LZ77 algorithm) */ + unsigned int winSize; /* size of the sliding window */ + unsigned int tableType; /* type of Huffman code tables + (for example, 0 - tables for Fixed Huffman codes) */ + unsigned int tableBufferSize; /* (ENOUGH = 2048) * (sizeof(code) = 4) - + sizeof(IppInflateState) */ +} IppInflateState; + +typedef enum { /* this type is used as a translator of the inflate_mode type from zlib */ + ippTYPE, + ippLEN, + ippLENEXT +} IppInflateMode; + +typedef struct { + Ipp16u freq; + Ipp16u code; +} IppDeflateFreqTable; + +typedef struct { + Ipp16u code; + Ipp16u len; +} IppDeflateHuffCode; + +typedef struct RLEState_BZ2 IppRLEState_BZ2; + +typedef struct EncodeHuffState_BZ2 IppEncodeHuffState_BZ2; + +typedef struct DecodeHuffState_BZ2 IppDecodeHuffState_BZ2; + +typedef enum { + IppLZO1XST, /* Single-threaded, generic LZO-compatible*/ + IppLZO1XMT /* Multi-threaded */ +} IppLZOMethod ; + +typedef struct LZOState_8u IppLZOState_8u; + +#endif /* _OWN_BLDPCS */ + +/* ///////////////////////////////////////////////////////////////////////////// +// The following enumerator defines a status of IPP operations +// negative value means error +*/ +typedef enum { + /* errors */ + ippStsNotSupportedModeErr = -9999,/* The requested mode is currently not supported. */ + ippStsCpuNotSupportedErr = -9998,/* The target CPU is not supported. */ + ippStsInplaceModeNotSupportedErr = -9997,/* The inplace operation is currently not supported. */ + + ippStsIIRIIRLengthErr = -234, /* Vector length for IIRIIR function is less than 3*(IIR order) */ + ippStsWarpTransformTypeErr = -233, /* The warp transform type is illegal */ + ippStsExceededSizeErr = -232, /* Requested size exceeded the maximum supported ROI size */ + ippStsWarpDirectionErr = -231, /* The warp transform direction is illegal */ + + ippStsFilterTypeErr = -230, /* The filter type is incorrect or not supported */ + + ippStsNormErr = -229, /* The norm is incorrect or not supported */ + + ippStsAlgTypeErr = -228, /* Algorithm type is not supported. */ + ippStsMisalignedOffsetErr = -227, /* The offset is not aligned with an element. */ + + ippStsQuadraticNonResidueErr = -226, /* SQRT operation on quadratic non-residue value. */ + + ippStsBorderErr = -225, /* Illegal value for border type.*/ + + ippStsDitherTypeErr = -224, /* Dithering type is not supported. */ + ippStsH264BufferFullErr = -223, /* Buffer for the output bitstream is full. */ + ippStsWrongAffinitySettingErr= -222, /* An affinity setting does not correspond to the affinity setting that was set by f.ippSetAffinity(). */ + ippStsLoadDynErr = -221, /* Error when loading the dynamic library. */ + + ippStsPointAtInfinity = -220, /* Point at infinity is detected. */ + + ippStsUnknownStatusCodeErr = -216, /* Unknown status code. */ + + ippStsOFBSizeErr = -215, /* Incorrect value for crypto OFB block size. */ + ippStsLzoBrokenStreamErr = -214, /* LZO safe decompression function cannot decode LZO stream. */ + + ippStsRoundModeNotSupportedErr = -213, /* Rounding mode is not supported. */ + ippStsDecimateFractionErr = -212, /* Fraction in Decimate is not supported. */ + ippStsWeightErr = -211, /* Incorrect value for weight. */ + + ippStsQualityIndexErr = -210, /* Cannot calculate the quality index for an image filled with a constant. */ + ippStsIIRPassbandRippleErr = -209, /* Ripple in passband for Chebyshev1 design is less than zero, equal to zero, or greater than 29. */ + ippStsFilterFrequencyErr = -208, /* Cutoff frequency of filter is less than zero, equal to zero, or greater than 0.5. */ + ippStsFIRGenOrderErr = -207, /* Order of the FIR filter for design is less than 1. */ + ippStsIIRGenOrderErr = -206, /* Order of the IIR filter for design is less than 1, or greater than 12. */ + + ippStsConvergeErr = -205, /* The algorithm does not converge. */ + ippStsSizeMatchMatrixErr = -204, /* The sizes of the source matrices are unsuitable. */ + ippStsCountMatrixErr = -203, /* Count value is less than, or equal to zero. */ + ippStsRoiShiftMatrixErr = -202, /* RoiShift value is negative or not divisible by the size of the data type. */ + + ippStsResizeNoOperationErr = -201, /* One of the output image dimensions is less than 1 pixel. */ + ippStsSrcDataErr = -200, /* The source buffer contains unsupported data. */ + ippStsMaxLenHuffCodeErr = -199, /* Huff: Max length of Huffman code is more than the expected one. */ + ippStsCodeLenTableErr = -198, /* Huff: Invalid codeLenTable. */ + ippStsFreqTableErr = -197, /* Huff: Invalid freqTable. */ + + ippStsIncompleteContextErr = -196, /* Crypto: set up of context is not complete. */ + + ippStsSingularErr = -195, /* Matrix is singular. */ + ippStsSparseErr = -194, /* Positions of taps are not in ascending order, or are negative, or repetitive. */ + ippStsBitOffsetErr = -193, /* Incorrect bit offset value. */ + ippStsQPErr = -192, /* Incorrect quantization parameter value. */ + ippStsVLCErr = -191, /* Illegal VLC or FLC is detected during stream decoding. */ + ippStsRegExpOptionsErr = -190, /* RegExp: Options for the pattern are incorrect. */ + ippStsRegExpErr = -189, /* RegExp: The structure pRegExpState contains incorrect data. */ + ippStsRegExpMatchLimitErr = -188, /* RegExp: The match limit is exhausted. */ + ippStsRegExpQuantifierErr = -187, /* RegExp: Incorrect quantifier. */ + ippStsRegExpGroupingErr = -186, /* RegExp: Incorrect grouping. */ + ippStsRegExpBackRefErr = -185, /* RegExp: Incorrect back reference. */ + ippStsRegExpChClassErr = -184, /* RegExp: Incorrect character class. */ + ippStsRegExpMetaChErr = -183, /* RegExp: Incorrect metacharacter. */ + ippStsStrideMatrixErr = -182, /* Stride value is not positive or not divisible by the size of the data type. */ + ippStsCTRSizeErr = -181, /* Incorrect value for crypto CTR block size. */ + ippStsJPEG2KCodeBlockIsNotAttached =-180, /* Codeblock parameters are not attached to the state structure. */ + ippStsNotPosDefErr = -179, /* Matrix is not positive definite. */ + + ippStsEphemeralKeyErr = -178, /* ECC: Invalid ephemeral key. */ + ippStsMessageErr = -177, /* ECC: Invalid message digest. */ + ippStsShareKeyErr = -176, /* ECC: Invalid share key. */ + ippStsIvalidPublicKey = -175, /* ECC: Invalid public key. */ + ippStsIvalidPrivateKey = -174, /* ECC: Invalid private key. */ + ippStsOutOfECErr = -173, /* ECC: Point out of EC. */ + ippStsECCInvalidFlagErr = -172, /* ECC: Invalid Flag. */ + + ippStsMP3FrameHeaderErr = -171, /* Error in fields of the IppMP3FrameHeader structure. */ + ippStsMP3SideInfoErr = -170, /* Error in fields of the IppMP3SideInfo structure. */ + + ippStsBlockStepErr = -169, /* Step for Block is less than 8. */ + ippStsMBStepErr = -168, /* Step for MB is less than 16. */ + + ippStsAacPrgNumErr = -167, /* AAC: Invalid number of elements for one program. */ + ippStsAacSectCbErr = -166, /* AAC: Invalid section codebook. */ + ippStsAacSfValErr = -164, /* AAC: Invalid scalefactor value. */ + ippStsAacCoefValErr = -163, /* AAC: Invalid quantized coefficient value. */ + ippStsAacMaxSfbErr = -162, /* AAC: Invalid coefficient index. */ + ippStsAacPredSfbErr = -161, /* AAC: Invalid predicted coefficient index. */ + ippStsAacPlsDataErr = -160, /* AAC: Invalid pulse data attributes. */ + ippStsAacGainCtrErr = -159, /* AAC: Gain control is not supported. */ + ippStsAacSectErr = -158, /* AAC: Invalid number of sections. */ + ippStsAacTnsNumFiltErr = -157, /* AAC: Invalid number of TNS filters. */ + ippStsAacTnsLenErr = -156, /* AAC: Invalid length of TNS region. */ + ippStsAacTnsOrderErr = -155, /* AAC: Invalid order of TNS filter. */ + ippStsAacTnsCoefResErr = -154, /* AAC: Invalid bit-resolution for TNS filter coefficients. */ + ippStsAacTnsCoefErr = -153, /* AAC: Invalid coefficients of TNS filter. */ + ippStsAacTnsDirectErr = -152, /* AAC: Invalid direction TNS filter. */ + ippStsAacTnsProfileErr = -151, /* AAC: Invalid TNS profile. */ + ippStsAacErr = -150, /* AAC: Internal error. */ + ippStsAacBitOffsetErr = -149, /* AAC: Invalid current bit offset in bitstream. */ + ippStsAacAdtsSyncWordErr = -148, /* AAC: Invalid ADTS syncword. */ + ippStsAacSmplRateIdxErr = -147, /* AAC: Invalid sample rate index. */ + ippStsAacWinLenErr = -146, /* AAC: Invalid window length (not short or long). */ + ippStsAacWinGrpErr = -145, /* AAC: Invalid number of groups for current window length. */ + ippStsAacWinSeqErr = -144, /* AAC: Invalid window sequence range. */ + ippStsAacComWinErr = -143, /* AAC: Invalid common window flag. */ + ippStsAacStereoMaskErr = -142, /* AAC: Invalid stereo mask. */ + ippStsAacChanErr = -141, /* AAC: Invalid channel number. */ + ippStsAacMonoStereoErr = -140, /* AAC: Invalid mono-stereo flag. */ + ippStsAacStereoLayerErr = -139, /* AAC: Invalid this Stereo Layer flag. */ + ippStsAacMonoLayerErr = -138, /* AAC: Invalid this Mono Layer flag. */ + ippStsAacScalableErr = -137, /* AAC: Invalid scalable object flag. */ + ippStsAacObjTypeErr = -136, /* AAC: Invalid audio object type. */ + ippStsAacWinShapeErr = -135, /* AAC: Invalid window shape. */ + ippStsAacPcmModeErr = -134, /* AAC: Invalid PCM output interleaving indicator. */ + ippStsVLCUsrTblHeaderErr = -133, /* VLC: Invalid header inside table. */ + ippStsVLCUsrTblUnsupportedFmtErr = -132, /* VLC: Table format is not supported. */ + ippStsVLCUsrTblEscAlgTypeErr = -131, /* VLC: Ecs-algorithm is not supported. */ + ippStsVLCUsrTblEscCodeLengthErr = -130, /* VLC: Esc-code length inside table header is incorrect. */ + ippStsVLCUsrTblCodeLengthErr = -129, /* VLC: Code length inside table is incorrect. */ + ippStsVLCInternalTblErr = -128, /* VLC: Invalid internal table. */ + ippStsVLCInputDataErr = -127, /* VLC: Invalid input data. */ + ippStsVLCAACEscCodeLengthErr = -126, /* VLC: Invalid AAC-Esc code length. */ + ippStsNoiseRangeErr = -125, /* Noise value for Wiener Filter is out of range. */ + ippStsUnderRunErr = -124, /* Error in data under run. */ + ippStsPaddingErr = -123, /* Detected padding error indicates the possible data corruption. */ + ippStsCFBSizeErr = -122, /* Incorrect value for crypto CFB block size. */ + ippStsPaddingSchemeErr = -121, /* Invalid padding scheme. */ + ippStsInvalidCryptoKeyErr = -120, /* A compromised key causes suspansion of the requested cryptographic operation. */ + ippStsLengthErr = -119, /* Incorrect value for string length. */ + ippStsBadModulusErr = -118, /* Bad modulus caused a failure in module inversion. */ + ippStsLPCCalcErr = -117, /* Cannot evaluate linear prediction. */ + ippStsRCCalcErr = -116, /* Cannot compute reflection coefficients. */ + ippStsIncorrectLSPErr = -115, /* Incorrect values for Linear Spectral Pair. */ + ippStsNoRootFoundErr = -114, /* No roots are found for equation. */ + ippStsJPEG2KBadPassNumber = -113, /* Pass number exceeds allowed boundaries [0,nOfPasses-1]. */ + ippStsJPEG2KDamagedCodeBlock= -112, /* Codeblock for decoding contains damaged data. */ + ippStsH263CBPYCodeErr = -111, /* Illegal Huffman code is detected through CBPY stream processing. */ + ippStsH263MCBPCInterCodeErr = -110, /* Illegal Huffman code is detected through MCBPC Inter stream processing. */ + ippStsH263MCBPCIntraCodeErr = -109, /* Illegal Huffman code is detected through MCBPC Intra stream processing. */ + ippStsNotEvenStepErr = -108, /* Step value is not pixel multiple. */ + ippStsHistoNofLevelsErr = -107, /* Number of levels for histogram is less than 2. */ + ippStsLUTNofLevelsErr = -106, /* Number of levels for LUT is less than 2. */ + ippStsMP4BitOffsetErr = -105, /* Incorrect bit offset value. */ + ippStsMP4QPErr = -104, /* Incorrect quantization parameter. */ + ippStsMP4BlockIdxErr = -103, /* Incorrect block index. */ + ippStsMP4BlockTypeErr = -102, /* Incorrect block type. */ + ippStsMP4MVCodeErr = -101, /* Illegal Huffman code is detected during MV stream processing. */ + ippStsMP4VLCCodeErr = -100, /* Illegal Huffman code is detected during VLC stream processing. */ + ippStsMP4DCCodeErr = -99, /* Illegal code is detected during DC stream processing. */ + ippStsMP4FcodeErr = -98, /* Incorrect fcode value. */ + ippStsMP4AlignErr = -97, /* Incorrect buffer alignment . */ + ippStsMP4TempDiffErr = -96, /* Incorrect temporal difference. */ + ippStsMP4BlockSizeErr = -95, /* Incorrect size of a block or macroblock. */ + ippStsMP4ZeroBABErr = -94, /* All BAB values are equal to zero. */ + ippStsMP4PredDirErr = -93, /* Incorrect prediction direction. */ + ippStsMP4BitsPerPixelErr = -92, /* Incorrect number of bits per pixel. */ + ippStsMP4VideoCompModeErr = -91, /* Incorrect video component mode. */ + ippStsMP4LinearModeErr = -90, /* Incorrect DC linear mode. */ + ippStsH263PredModeErr = -83, /* Incorrect Prediction Mode value. */ + ippStsH263BlockStepErr = -82, /* The step value is less than 8. */ + ippStsH263MBStepErr = -81, /* The step value is less than 16. */ + ippStsH263FrameWidthErr = -80, /* The frame width is less than 8. */ + ippStsH263FrameHeightErr = -79, /* The frame height is less than, or equal to zero. */ + ippStsH263ExpandPelsErr = -78, /* Expand pixels number is less than 8. */ + ippStsH263PlaneStepErr = -77, /* Step value is less than the plane width. */ + ippStsH263QuantErr = -76, /* Quantizer value is less than, or equal to zero, or greater than 31. */ + ippStsH263MVCodeErr = -75, /* Illegal Huffman code is detected during MV stream processing. */ + ippStsH263VLCCodeErr = -74, /* Illegal Huffman code is detected during VLC stream processing. */ + ippStsH263DCCodeErr = -73, /* Illegal code is detected during DC stream processing. */ + ippStsH263ZigzagLenErr = -72, /* Zigzag compact length is more than 64. */ + ippStsFBankFreqErr = -71, /* Incorrect value for the filter bank frequency parameter. */ + ippStsFBankFlagErr = -70, /* Incorrect value for the filter bank parameter. */ + ippStsFBankErr = -69, /* Filter bank is not correctly initialized. */ + ippStsNegOccErr = -67, /* Occupation count is negative. */ + ippStsCdbkFlagErr = -66, /* Incorrect value for the codebook flag parameter. */ + ippStsSVDCnvgErr = -65, /* SVD algorithm does not converge. */ + ippStsJPEGHuffTableErr = -64, /* JPEG Huffman table is destroyed. */ + ippStsJPEGDCTRangeErr = -63, /* JPEG DCT coefficient is out of range. */ + ippStsJPEGOutOfBufErr = -62, /* Attempt to access out of the buffer limits. */ + ippStsDrawTextErr = -61, /* System error in the draw text operation. */ + ippStsChannelOrderErr = -60, /* Incorrect order of the destination channels. */ + ippStsZeroMaskValuesErr = -59, /* All values of the mask are equal to zero. */ + ippStsQuadErr = -58, /* The quadrangle is nonconvex or degenerates into triangle, line, or point */ + ippStsRectErr = -57, /* Size of the rectangle region is less than, or equal to 1. */ + ippStsCoeffErr = -56, /* Incorrect values for transformation coefficients. */ + ippStsNoiseValErr = -55, /* Incorrect value for noise amplitude for dithering. */ + ippStsDitherLevelsErr = -54, /* Number of dithering levels is out of range. */ + ippStsNumChannelsErr = -53, /* Number of channels is incorrect, or not supported. */ + ippStsCOIErr = -52, /* COI is out of range. */ + ippStsDivisorErr = -51, /* Divisor is equal to zero, function is aborted. */ + ippStsAlphaTypeErr = -50, /* Illegal type of image compositing operation. */ + ippStsGammaRangeErr = -49, /* Gamma range bounds is less than, or equal to zero. */ + ippStsGrayCoefSumErr = -48, /* Sum of the conversion coefficients must be less than, or equal to 1. */ + ippStsChannelErr = -47, /* Illegal channel number. */ + ippStsToneMagnErr = -46, /* Tone magnitude is less than, or equal to zero. */ + ippStsToneFreqErr = -45, /* Tone frequency is negative, or greater than, or equal to 0.5. */ + ippStsTonePhaseErr = -44, /* Tone phase is negative, or greater than, or equal to 2*PI. */ + ippStsTrnglMagnErr = -43, /* Triangle magnitude is less than, or equal to zero. */ + ippStsTrnglFreqErr = -42, /* Triangle frequency is negative, or greater than, or equal to 0.5. */ + ippStsTrnglPhaseErr = -41, /* Triangle phase is negative, or greater than, or equal to 2*PI. */ + ippStsTrnglAsymErr = -40, /* Triangle asymmetry is less than -PI, or greater than, or equal to PI. */ + ippStsHugeWinErr = -39, /* Kaiser window is too big. */ + ippStsJaehneErr = -38, /* Magnitude value is negative. */ + ippStsStrideErr = -37, /* Stride value is less than the length of the row. */ + ippStsEpsValErr = -36, /* Negative epsilon value. */ + ippStsWtOffsetErr = -35, /* Invalid offset value for wavelet filter. */ + ippStsAnchorErr = -34, /* Anchor point is outside the mask. */ + ippStsMaskSizeErr = -33, /* Invalid mask size. */ + ippStsShiftErr = -32, /* Shift value is less than zero. */ + ippStsSampleFactorErr = -31, /* Sampling factor is less than, or equal to zero. */ + ippStsSamplePhaseErr = -30, /* Phase value is out of range: 0 <= phase < factor. */ + ippStsFIRMRFactorErr = -29, /* MR FIR sampling factor is less than, or equal to zero. */ + ippStsFIRMRPhaseErr = -28, /* MR FIR sampling phase is negative, or greater than, or equal to the sampling factor. */ + ippStsRelFreqErr = -27, /* Relative frequency value is out of range. */ + ippStsFIRLenErr = -26, /* Length of a FIR filter is less than, or equal to zero. */ + ippStsIIROrderErr = -25, /* Order of an IIR filter is not valid. */ + ippStsDlyLineIndexErr = -24, /* Invalid value for the delay line sample index. */ + ippStsResizeFactorErr = -23, /* Resize factor(s) is less than, or equal to zero. */ + ippStsInterpolationErr = -22, /* Invalid interpolation mode. */ + ippStsMirrorFlipErr = -21, /* Invalid flip mode. */ + ippStsMoment00ZeroErr = -20, /* Moment value M(0,0) is too small to continue calculations. */ + ippStsThreshNegLevelErr = -19, /* Negative value of the level in the threshold operation. */ + ippStsThresholdErr = -18, /* Invalid threshold bounds. */ + ippStsContextMatchErr = -17, /* Context parameter does not match the operation. */ + ippStsFftFlagErr = -16, /* Invalid value for the FFT flag parameter. */ + ippStsFftOrderErr = -15, /* Invalid value for the FFT order parameter. */ + ippStsStepErr = -14, /* Step value is not valid. */ + ippStsScaleRangeErr = -13, /* Scale bounds are out of range. */ + ippStsDataTypeErr = -12, /* Data type is incorrect or not supported. */ + ippStsOutOfRangeErr = -11, /* Argument is out of range, or point is outside the image. */ + ippStsDivByZeroErr = -10, /* An attempt to divide by zero. */ + ippStsMemAllocErr = -9, /* Memory allocated for the operation is not enough.*/ + ippStsNullPtrErr = -8, /* Null pointer error. */ + ippStsRangeErr = -7, /* Incorrect values for bounds: the lower bound is greater than the upper bound. */ + ippStsSizeErr = -6, /* Incorrect value for data size. */ + ippStsBadArgErr = -5, /* Incorrect arg/param of the function. */ + ippStsNoMemErr = -4, /* Not enough memory for the operation. */ + ippStsSAReservedErr3 = -3, /* Unknown/unspecified error, -3. */ + ippStsErr = -2, /* Unknown/unspecified error, -2. */ + ippStsSAReservedErr1 = -1, /* Unknown/unspecified error, -1. */ + + /* no errors */ + ippStsNoErr = 0, /* No errors. */ + + /* warnings */ + ippStsNoOperation = 1, /* No operation has been executed. */ + ippStsMisalignedBuf = 2, /* Misaligned pointer in operation in which it must be aligned. */ + ippStsSqrtNegArg = 3, /* Negative value(s) for the argument in the Sqrt function. */ + ippStsInvZero = 4, /* INF result. Zero value was met by InvThresh with zero level. */ + ippStsEvenMedianMaskSize= 5, /* Even size of the Median Filter mask was replaced with the odd one. */ + ippStsDivByZero = 6, /* Zero value(s) for the divisor in the Div function. */ + ippStsLnZeroArg = 7, /* Zero value(s) for the argument in the Ln function. */ + ippStsLnNegArg = 8, /* Negative value(s) for the argument in the Ln function. */ + ippStsNanArg = 9, /* Argument value is not a number. */ + ippStsJPEGMarker = 10, /* JPEG marker in the bitstream. */ + ippStsResFloor = 11, /* All result values are floored. */ + ippStsOverflow = 12, /* Overflow in the operation. */ + ippStsLSFLow = 13, /* Quantized LP synthesis filter stability check is applied at the low boundary of [0,pi]. */ + ippStsLSFHigh = 14, /* Quantized LP synthesis filter stability check is applied at the high boundary of [0,pi]. */ + ippStsLSFLowAndHigh = 15, /* Quantized LP synthesis filter stability check is applied at both boundaries of [0,pi]. */ + ippStsZeroOcc = 16, /* Zero occupation count. */ + ippStsUnderflow = 17, /* Underflow in the operation. */ + ippStsSingularity = 18, /* Singularity in the operation. */ + ippStsDomain = 19, /* Argument is out of the function domain. */ + ippStsNonIntelCpu = 20, /* The target CPU is not Genuine Intel. */ + ippStsCpuMismatch = 21, /* Cannot set the library for the given CPU. */ + ippStsNoIppFunctionFound = 22, /* Application does not contain Intel IPP function calls. */ + ippStsDllNotFoundBestUsed = 23, /* Dispatcher cannot find the newest version of the Intel IPP dll. */ + ippStsNoOperationInDll = 24, /* The function does nothing in the dynamic version of the library. */ + ippStsInsufficientEntropy= 25, /* Generation of the prime/key failed due to insufficient entropy in the random seed and stimulus bit string. */ + ippStsOvermuchStrings = 26, /* Number of destination strings is more than expected. */ + ippStsOverlongString = 27, /* Length of one of the destination strings is more than expected. */ + ippStsAffineQuadChanged = 28, /* 4th vertex of destination quad is not equal to customer's one. */ + ippStsWrongIntersectROI = 29, /* ROI has no intersection with the source or destination ROI. No operation. */ + ippStsWrongIntersectQuad = 30, /* Quadrangle has no intersection with the source or destination ROI. No operation. */ + ippStsSmallerCodebook = 31, /* Size of created codebook is less than the cdbkSize argument. */ + ippStsSrcSizeLessExpected = 32, /* DC: Size of the source buffer is less than the expected one. */ + ippStsDstSizeLessExpected = 33, /* DC: Size of the destination buffer is less than the expected one. */ + ippStsStreamEnd = 34, /* DC: The end of stream processed. */ + ippStsDoubleSize = 35, /* Width or height of image is odd. */ + ippStsNotSupportedCpu = 36, /* The CPU is not supported. */ + ippStsUnknownCacheSize = 37, /* The CPU is supported, but the size of the cache is unknown. */ + ippStsSymKernelExpected = 38, /* The Kernel is not symmetric. */ + ippStsEvenMedianWeight = 39, /* Even weight of the Weighted Median Filter is replaced with the odd one. */ + ippStsWrongIntersectVOI = 40, /* VOI has no intersection with the source or destination volume. No operation. */ + ippStsI18nMsgCatalogInvalid=41, /* Message Catalog is invalid, English message returned. */ + ippStsI18nGetMessageFail = 42, /* Failed to fetch a localized message, English message returned. For more information use errno on Linux* OS and GetLastError on Windows* OS. */ + ippStsWaterfall = 43, /* Cannot load required library, waterfall is used. */ + ippStsPrevLibraryUsed = 44, /* Cannot load required library, previous dynamic library is used. */ + ippStsLLADisabled = 45, /* OpenMP* Low Level Affinity is disabled. */ + ippStsNoAntialiasing = 46, /* The mode does not support antialiasing. */ + ippStsRepetitiveSrcData = 47, /* DC: The source data is too repetitive. */ + ippStsSizeWrn = 48, /* The size does not allow to perform full operation. */ + ippStsFeatureNotSupported = 49, /* Current CPU doesn't support at least 1 of the desired features. */ + ippStsUnknownFeature = 50, /* At least one of the desired features is unknown. */ + ippStsFeaturesCombination = 51, /* Wrong combination of features. */ + ippStsAccurateModeNotSupported = 52 /* Accurate mode is not supported. */ +} IppStatus; + +#define ippStsOk ippStsNoErr + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __IPPTYPES_H__ */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/include/ippversion.h b/sgx-jvm/linux-sgx/external/crypto_px/include/ippversion.h new file mode 100755 index 0000000000..478ac0b0cf --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/include/ippversion.h @@ -0,0 +1,41 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined( __IPPVERSION_H__ ) +#define __IPPVERSION_H__ + +#define IPP_VERSION_MAJOR 9 +#define IPP_VERSION_MINOR 0 +#define IPP_VERSION_UPDATE 2 + +#define IPP_VERSION_STR "9.0.2" + +#endif /* __IPPVERSION_H__ */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/include/cpudef.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/include/cpudef.h new file mode 100644 index 0000000000..3d9cde6c64 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/include/cpudef.h @@ -0,0 +1,264 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#ifndef __CPUDEF_H__ +#define __CPUDEF_H__ + +#include "ippcore.h" + +#if defined( __cplusplus ) +extern "C" { +#endif + +#undef __CDECL +#if defined( _WIN32 ) || defined ( _WIN64 ) + #define __CDECL __cdecl +#else + #define __CDECL +#endif + + +/* Intel CPU informator */ + +typedef struct { + int family; + int stepping; + int model; + int type; + int feature; + int tlb; + int cache; + int mmx; + int freq; + int ssx; + int wni; + int htt; + int pni; + int em64t; + int mni; + int phcores; + int sse41; + int sse42; + int ext_family; + int ext_model; + int movbe_instr; + int avx; + int xsavexgetbv; +} ippIntelCpuId; + +int __CDECL ownGetMaskFeatures( Ipp64u* pFeaturesMask ); +int __CDECL ownGetFeature( Ipp64u MaskOfFeature ); +int __CDECL ipp_is_avx_extension( void ); + +__INT64 __CDECL ipp_get_pentium_counter (void); +int __CDECL ipp_is_mmx_extension (void); +int __CDECL ipp_is_ssx_extension (void); +int __CDECL ipp_is_wni_extension (void); +int __CDECL ipp_is_htt_extension( void ); +int __CDECL ipp_is_pni_extension( void ); +int __CDECL ipp_is_mni_extension( void ); +int __CDECL ipp_is_sse41_extension( void ); +int __CDECL ipp_is_sse42_extension( void ); +int __CDECL ipp_is_movbe( void ); +int __CDECL ipp_get_cores_on_die( void ); +int __CDECL ipp_is_em64t_extension( void ); +int __CDECL ipp_has_cpuid ( void ); +int __CDECL ipp_has_rdtsc( void ); + +void __CDECL ipp_get_pentium_ident ( ippIntelCpuId* cpuid ); +int __CDECL ipp_is_GenuineIntel ( void ); +int __CDECL ipp_max_cpuid_input( void ); +int __CDECL ipp_get_cpuid( int regs[4], int valEAX, int valECX ); +void __CDECL ipp_get_cache_line_size( int* szCacheLine ); + +int __CDECL ipp_isnan( double x ); +int __CDECL ipp_finite( double x ); +int __CDECL ipp_isnan_32f( float x ); +int __CDECL ipp_finite_32f( float x ); +#define ipp_isfinite ipp_finite + +unsigned int __CDECL ipp_control87 ( unsigned int newcw, unsigned int mask ); +unsigned int __CDECL ipp_status87 ( void ); +unsigned int __CDECL ipp_clear87 ( void ); + +unsigned int __CDECL ipp_clear_ssx (void); +/* topology/affinity */ + +/* here are definitions of the CW bits exactly as x87 and ssx have */ + +#define IPP_FPU_MASK_RC 0x0c00 +#define IPP_FPU_MASK_PC 0x0300 +#define IPP_FPU_MASK_RCPC 0x0f00 + +#define IPP_FPU_RC_NEAR 0x0000 +#define IPP_FPU_RC_DOWN 0x0400 +#define IPP_FPU_RC_UP 0x0800 +#define IPP_FPU_RC_ZERO 0x0c00 + +#define IPP_FPU_PC_24 0x0000 +#define IPP_FPU_PC_53 0x0200 +#define IPP_FPU_PC_64 0x0300 + + +unsigned int __CDECL ipp_set_rcpc_fpu( unsigned int newrcpc, unsigned int mask); +void __CDECL ipp_set_cw_fpu( unsigned int cw ); + +#define IPP_SSX_RC_NEAR 0x0000 +#define IPP_SSX_RC_DOWN 0x2000 +#define IPP_SSX_RC_UP 0x4000 +#define IPP_SSX_RC_ZERO 0x6000 +#define IPP_SSX_MASK_RC 0x6000 + + +unsigned int __CDECL ipp_set_rc_ssx( unsigned int newrc ); +void __CDECL ipp_set_cw_ssx( unsigned int cw ); + +/* ================= FPU section ===================== */ + +/* Control bits - disable exceptions */ +#define FPU_EXC_MSK 0x003f /* Exception Masks Mask */ +#define FPU_MSK_INVALID 0x0001 /* invalid operation */ +#define FPU_MSK_DENORMAL 0x0002 /* denormalized operand */ +#define FPU_MSK_ZERODIV 0x0004 /* zero divide */ +#define FPU_MSK_OVERFLOW 0x0008 /* overflow */ +#define FPU_MSK_UNDERFLOW 0x0010 /* underflow */ +#define FPU_MSK_INEXACT 0x0020 /* inexact (precision) */ + +/* Status bits - exceptions */ +#define FPU_EXC_FLG 0x003f /* Exception Flags Mask */ +#define FPU_FLG_INVALID 0x0001 /* invalid operation */ +#define FPU_FLG_DENORMAL 0x0002 /* denormalized operand */ +#define FPU_FLG_ZERODIV 0x0004 /* zero divide */ +#define FPU_FLG_OVERFLOW 0x0008 /* overflow */ +#define FPU_FLG_UNDERFLOW 0x0010 /* underflow */ +#define FPU_FLG_INEXACT 0x0020 /* inexact (precision) */ + +/* Control bits - rounding control */ +#define FPU_RND 0x0c00 /* Rounding Control Mask */ +#define FPU_RND_NEAR 0x0000 /* near */ +#define FPU_RND_DOWN 0x0400 /* down */ +#define FPU_RND_UP 0x0800 /* up */ +#define FPU_RND_CHOP 0x0c00 /* chop */ + +/* Control bits - precision control */ +#define FPU_PRC 0x0300 /* Precision Control Mask */ +#define FPU_PRC_64 0x0300 /* 64 bits */ +#define FPU_PRC_53 0x0200 /* 53 bits */ +#define FPU_PRC_24 0x0000 /* 24 bits */ + +/* Control bits - all masks */ +#define FPU_ALL 0x0f3f /* all masks */ + +/* ============= definition for control/status world ============== */ + +#define FPU_SET_EXC_MASK(mask) ps_set_cw_fpu(mask,FPU_EXC_MSK) +#define FPU_GET_EXC_MASK() (ps_set_cw_fpu(0,0) & FPU_EXC_MSK) + +#define FPU_GET_EXC_FLAG() (ps_get_sw_fpu() & FPU_EXC_FLG) + +#define FPU_SET_RND_MODE(mode) ps_set_cw_fpu(mode,FPU_RND) +#define FPU_GET_RND_MODE() (ps_set_cw_fpu(0,0) & FPU_RND) + +#define FPU_SET_PRC_MODE(mode) ps_set_cw_fpu(mode,FPU_PRC) +#define FPU_GET_PRC_MODE() (ps_set_cw_fpu(0,0) & FPU_PRC) + +unsigned int __CDECL ps_set_cw_fpu( unsigned int newcw, unsigned int msk); +unsigned int __CDECL ps_get_cw_fpu(void); +unsigned int __CDECL ps_get_sw_fpu(void); +unsigned int __CDECL ps_clear_fpu(void); + +/* ======================= SSX section ============================ */ + +/* Control bits - disable exceptions */ +#define SSX_EXC_MSK 0x1f80 /* Disabling exception mask */ +#define SSX_MSK_INEXACT 0x1000 /* precision (inexact) */ +#define SSX_MSK_UNDERFLOW 0x0800 /* underflow */ +#define SSX_MSK_OVERFLOW 0x0400 /* overflow */ +#define SSX_MSK_ZERODIV 0x0200 /* divide by zero */ +#define SSX_MSK_DENORMAL 0x0100 /* denormalized */ +#define SSX_MSK_INVALID 0x0080 /* invalid operation */ + +/* Status bits - exceptions */ +#define SSX_EXC_FLG 0x003f /* Exception flags mask */ +#define SSX_FLG_INEXACT 0x0020 /* precision (inexact) */ +#define SSX_FLG_UNDERFLOW 0x0010 /* underflow */ +#define SSX_FLG_OVERFLOW 0x0008 /* overflow */ +#define SSX_FLG_ZERODIV 0x0004 /* divide by zero */ +#define SSX_FLG_DENORMAL 0x0002 /* denormalized */ +#define SSX_FLG_INVALID 0x0001 /* invalid operation */ + +/* Control bits - rounding control */ +#define SSX_RND 0x6000 /* Rounding control mask */ +#define SSX_RND_NEAR 0x0000 /* near */ +#define SSX_RND_DOWN 0x2000 /* down */ +#define SSX_RND_UP 0x4000 /* up */ +#define SSX_RND_CHOP 0x6000 /* chop */ + +/* Control bits - flush to zero mode */ +#define SSX_FZ 0x8000 /* Flush to zero mask */ +#define SSX_FZ_ENABLE 0x8000 /* flush to zero */ +#define SSX_FZ_DISABLE 0x0000 /* not flush to zero */ + +/* Control bits - denormals are zero mode */ +#define SSX_DAZ 0x0040 /* denorm. are zero mask */ +#define SSX_DAZ_ENABLE 0x0040 /* denorm. are zero */ +#define SSX_DAZ_DISABLE 0x0000 /* denorm. are not zero */ + +#define SSX_ALL 0xffbf /* All masks */ + +/* ==================== definition for SSX register =============== */ + +#define SSX_SET_EXC_MASK(mask) ps_set_ssx(mask,SSX_EXC_MSK) +#define SSX_GET_EXC_MASK() (ps_get_ssx() & SSX_EXC_MSK) + +#define SSX_SET_EXC_FLAG(flag) ps_set_ssx(flag,SSX_EXC_FLG) +#define SSX_GET_EXC_FLAG() (ps_get_ssx() & SSX_EXC_FLG) + +#define SSX_SET_RND_MODE(mode) ps_set_ssx(mode,SSX_RND) +#define SSX_GET_RND_MODE() (ps_get_ssx() & SSX_RND) + +#define SSX_SET_FZ_MODE(mode) ps_set_ssx(mode,SSX_FZ) +#define SSX_GET_FZ_MODE() (ps_get_ssx() & SSX_FZ) + +#define SSX_SET_DAZ_MODE(mode) ps_set_ssx(mode,SSX_DAZ) +#define SSX_GET_DAZ_MODE() (ps_get_ssx() & SSX_DAZ) + +unsigned int __CDECL ps_set_ssx(unsigned int newssx, unsigned int msk); +unsigned int __CDECL ps_get_ssx(void); +unsigned int __CDECL ipp_tst_daz_ssx(void); + +#if defined( __cplusplus ) +} +#endif + +#endif /* __CPUDEF_H__ */ + +/* ////////////////////////// End of file "cpudef.h" //////////////////////// */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/include/ippver.gen b/sgx-jvm/linux-sgx/external/crypto_px/sources/include/ippver.gen new file mode 100644 index 0000000000..51c4a2d51d --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/include/ippver.gen @@ -0,0 +1,56 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_IPP_DYNAMIC) || defined(_CORE) +#include "owndefs.h" + +#ifndef _IPP_VERSION +#define _IPP_VERSION "" +#endif + +#define GET_LIB_NAME01(pref) pref ## GetLibVersion + +#define GET_LIB_NAME(pref) GET_LIB_NAME01(pref) + +#define LIBVERNAME s_libVer + +#define SLIBVERNAME LIBVERNAME +#include "ippverstr.gen" + +#include "cpudef.h" + +extern int ippJumpIndexForMergedDLL; + +IPPFUN( const IppLibraryVersion*, GET_LIB_NAME(LIB_PREFIX), (void) ) +{ + return &LIBVERNAME; +} +#endif diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/include/ippver.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/include/ippver.h new file mode 100644 index 0000000000..ef6868a967 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/include/ippver.h @@ -0,0 +1,46 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "ippversion.h" +#ifndef BASE_VERSION +#define BASE_VERSION() IPP_VERSION_MAJOR,IPP_VERSION_MINOR,IPP_VERSION_UPDATE +#endif + +#ifndef STR_VERSION + #ifdef IPP_REVISION + #define STR_VERSION() IPP_VERSION_STR " (r" STR( IPP_REVISION ) ")" + #else + #define STR_VERSION() IPP_VERSION_STR " (-)" + #endif +#endif + + +/* ////////////////////////////// End of file /////////////////////////////// */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/include/ippverstr.gen b/sgx-jvm/linux-sgx/external/crypto_px/sources/include/ippverstr.gen new file mode 100644 index 0000000000..edbcad3309 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/include/ippverstr.gen @@ -0,0 +1,120 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#ifdef _IPP_OMP_STATIC +#define LIB_THREADS " threaded" +#define CORE_THREADS " (threaded)" +#else +#define LIB_THREADS "" +#define CORE_THREADS "" +#endif + +#define GET_LIBRARY_NAME( cpu, is ) #cpu, IPP_LIB_SHORTNAME() " " is " (" #cpu LIB_THREADS ")" + +static const IppLibraryVersion SLIBVERNAME = { + +/* major, minor, update (ex-majorBuild) */ + BASE_VERSION(), + +#if defined IPP_REVISION + IPP_REVISION, +#else + -1, +#endif /* IPP_REVISION */ + +#if defined( _CORE ) + /*GET_LIBRARY_NAME( core )*/ + "core", + "ippCore" CORE_THREADS + +#elif ( _IPP_ARCH == _IPP_ARCH_IA32 ) || ( _IPP_ARCH == _IPP_ARCH_LP32 ) + #if ( _IPP == _IPP_M5 ) + GET_LIBRARY_NAME( m5, "586" ) + #elif ( _IPP == _IPP_H9 ) + GET_LIBRARY_NAME( h9, "AVX2" ) + #elif ( _IPP == _IPP_G9 ) + GET_LIBRARY_NAME( g9, "AVX" ) + #elif ( _IPP == _IPP_P8 ) + GET_LIBRARY_NAME( p8, "SSE4.2" ) + #elif ( _IPPLP32 == _IPPLP32_S8 ) + GET_LIBRARY_NAME( s8, "Atom" ) + #elif ( _IPP == _IPP_V8 ) + GET_LIBRARY_NAME( v8, "SSSE3" ) + #elif ( _IPP == _IPP_W7 ) + GET_LIBRARY_NAME( w7, "SSE2" ) + #else + GET_LIBRARY_NAME( px, "PX" ) + #endif + +#elif ( _IPP_ARCH == _IPP_ARCH_EM64T ) || ( _IPP_ARCH == _IPP_ARCH_LP64 ) + #if ( _IPP32E == _IPP32E_K0 ) + GET_LIBRARY_NAME( k0, "AVX-512F/CD/BW/DQ/VL" ) + #elif ( _IPP32E == _IPP32E_N0 ) + GET_LIBRARY_NAME( n0, "AVX-512F/CD/ER/PF" ) + #elif ( _IPP32E == _IPP32E_E9 ) + GET_LIBRARY_NAME( e9, "AVX" ) + #elif ( _IPP32E == _IPP32E_L9 ) + GET_LIBRARY_NAME( l9, "AVX2" ) + #elif ( _IPP32E == _IPP32E_Y8 ) + GET_LIBRARY_NAME( y8, "SSE4.2" ) + #elif ( _IPPLP64 == _IPPLP64_N8 ) + GET_LIBRARY_NAME( n8, "Atom" ) + #elif ( _IPP32E == _IPP32E_U8 ) + GET_LIBRARY_NAME( u8, "SSSE3" ) + #elif ( _IPP32E == _IPP32E_M7 ) + GET_LIBRARY_NAME( m7, "SSE3" ) + #else + GET_LIBRARY_NAME( mx, "PX" ) + #endif + +#elif ( _IPP_ARCH == _IPP_ARCH_LRB2 ) + #if ( _IPPLRB == _IPPLRB_BX ) + GET_LIBRARY_NAME( bx, "PX" ) + #elif ( _IPPLRB == _IPPLRB_B2 ) + GET_LIBRARY_NAME( b2, "KNC" ) + #endif + +#else + #error ARCH not supported + +#endif + +#if defined( TICKTOCK ) + "+" +#endif + +/* release Version (by Manager) */ + ,STR_VERSION() + +/* BuildDate (by QA person) */ + ,__DATE__ + +}; diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/include/owndefs.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/include/owndefs.h new file mode 100644 index 0000000000..6d9b386375 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/include/owndefs.h @@ -0,0 +1,944 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#ifndef __OWNDEFS_H__ +#define __OWNDEFS_H__ + +#if defined( _VXWORKS ) + #include + #undef NONE +#endif + +#include "ippdefs.h" + +#if defined(__INTEL_COMPILER) || defined(_MSC_VER) + #define __INLINE static __inline +#elif defined( __GNUC__ ) + #define __INLINE static __inline__ +#else + #define __INLINE static +#endif + +#if defined(__INTEL_COMPILER) + #define __RESTRICT restrict +#elif !defined( __RESTRICT ) + #define __RESTRICT +#endif + +#if defined( IPP_W32DLL ) + #if defined( _MSC_VER ) || defined( __INTEL_COMPILER ) + #define IPPFUN(type,name,arg) __declspec(dllexport) type __STDCALL name arg + #else + #define IPPFUN(type,name,arg) extern type __STDCALL name arg + #endif +#else + #define IPPFUN(type,name,arg) extern type __STDCALL name arg +#endif + + +/* structure represeting 128 bit unsigned integer type */ + +typedef struct{ + Ipp64u low; + Ipp64u high; +}Ipp128u; + +#define _IPP_PX 0 /* pure C-code ia32 */ +#define _IPP_M5 1 /* Quark (Pentium) - x86+x87 ia32 */ +#define _IPP_M6 2 /* Pentium MMX - MMX ia32 */ +#define _IPP_A6 4 /* Pentium III - SSE ia32 */ +#define _IPP_W7 8 /* Pentium 4 - SSE2 ia32 */ +#define _IPP_T7 16 /* Pentium with x64 support (Nocona) - SSE3 ia32 */ +#define _IPP_V8 32 /* Merom - SSSE3 ia32 */ +#define _IPP_P8 64 /* Penryn - SSE4.1 + tick for SSE4.2 ia32 */ +#define _IPP_G9 128 /* SandyBridge (GSSE) - AVX ia32 */ +#define _IPP_H9 256 /* Haswell (AVX2) ia32 */ +#define _IPP_I0 512 /* KNL (AVX-512) ia32 */ +#define _IPP_S0 1024 /* SkyLake Xeon (AVX-512) ia32 */ + +#define _IPPXSC_PX 0 +#define _IPPXSC_S1 1 +#define _IPPXSC_S2 2 +#define _IPPXSC_C2 4 + +#define _IPPLRB_PX 0 +#define _IPPLRB_B1 1 +#define _IPPLRB_B2 2 + +#define _IPP64_PX _IPP_PX +#define _IPP64_I7 64 + +#define _IPP32E_PX _IPP_PX /* pure C-code x64 */ +#define _IPP32E_M7 32 /* Pentium with x64 support (Nocona) - SSE3 x64 */ +#define _IPP32E_U8 64 /* Merom - SSSE3 x64 */ +#define _IPP32E_Y8 128 /* Penryn - SSE4.1 + tick for SSE4.2 x64 */ +#define _IPP32E_E9 256 /* SandyBridge (GSSE) - AVX x64 */ +#define _IPP32E_L9 512 /* Haswell (AVX2) x64 */ +#define _IPP32E_N0 1024 /* KNL (AVX-512) x64 */ +#define _IPP32E_K0 2048 /* SkyLake Xeon (AVX-512) x64 */ + +#define _IPPLP32_PX _IPP_PX +#define _IPPLP32_S8 1 /* old Atom (SSSE3+movbe) (Silverthorne) ia32 */ + +#define _IPPLP64_PX _IPP_PX +#define _IPPLP64_N8 1 /* old Atom (SSSE3+movbe) (Silverthorne) x64 */ + +#if defined(__INTEL_COMPILER) || (_MSC_VER >= 1300) + #define __ALIGN8 __declspec (align(8)) + #define __ALIGN16 __declspec (align(16)) +#if !defined( OSX32 ) + #define __ALIGN32 __declspec (align(32)) +#else + #define __ALIGN32 __declspec (align(16)) +#endif + #define __ALIGN64 __declspec (align(64)) +#elif defined (__GNUC__) + #define __ALIGN8 __attribute((aligned(8))) + #define __ALIGN16 __attribute((aligned(16))) + #define __ALIGN32 __attribute((aligned(32))) + #define __ALIGN64 __attribute((aligned(64))) +#else + #define __ALIGN8 + #define __ALIGN16 + #define __ALIGN32 + #define __ALIGN64 +#endif + +#if defined ( _M5 ) /* Quark (Pentium) - x86+x87 ia32 */ + #define _IPP _IPP_M5 + #define _IPP32E _IPP32E_PX + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined ( _M6 ) /* Pentium MMX - MMX ia32 */ + #define _IPP _IPP_M6 + #define _IPP32E _IPP32E_PX + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _A6 ) /* Pentium III - SSE ia32 */ + #define _IPP _IPP_A6 + #define _IPP32E _IPP32E_PX + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _W7 ) /* Pentium 4 - SSE2 ia32 */ + #define _IPP _IPP_W7 + #define _IPP32E _IPP32E_PX + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _T7 ) /* Pentium with x64 support (Nocona) - SSE3 ia32 */ + #define _IPP _IPP_T7 + #define _IPP32E _IPP32E_PX + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _V8 ) /* Merom - SSSE3 ia32 */ + #define _IPP _IPP_V8 + #define _IPP32E _IPP32E_PX + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _P8 ) /* Penryn - SSE4.1 + tick for SSE4.2 ia32 */ + #define _IPP _IPP_P8 + #define _IPP32E _IPP32E_PX + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _G9 ) /* SandyBridge (GSSE) - AVX ia32 */ + #define _IPP _IPP_G9 + #define _IPP32E _IPP32E_PX + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _H9 ) /* Haswell (AVX2) ia32 */ + #define _IPP _IPP_H9 + #define _IPP32E _IPP32E_PX + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _M7 ) /* Pentium with x64 support (Nocona) - SSE3 x64 */ + #define _IPP _IPP_PX + #define _IPP32E _IPP32E_M7 + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _U8 ) /* Merom - SSSE3 x64 */ + #define _IPP _IPP_PX + #define _IPP32E _IPP32E_U8 + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _Y8 ) /* Penryn - SSE4.1 + tick for SSE4.2 x64 */ + #define _IPP _IPP_PX + #define _IPP32E _IPP32E_Y8 + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _E9 ) /* SandyBridge (GSSE) - AVX x64 */ + #define _IPP _IPP_PX + #define _IPP32E _IPP32E_E9 + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _L9 ) /* Haswell (AVX2) x64 */ + #define _IPP _IPP_PX + #define _IPP32E _IPP32E_L9 + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _N0 ) /* KNL (AVX-512) x64 */ + #define _IPP _IPP_PX + #define _IPP32E _IPP32E_N0 + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _K0 ) /* SkyLake Xeon (AVX-512) x64 */ + #define _IPP _IPP_PX + #define _IPP32E _IPP32E_K0 + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _B2 ) /* KNC (MIC) */ + #define _IPP _IPP_PX + #define _IPP32E _IPP32E_PX + #define _IPPLRB _IPPLRB_B2 + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _S8 ) /* old Atom (SSSE3+movbe) (Silverthorne) ia32 */ + #define _IPP _IPP_V8 + #define _IPP32E _IPP32E_PX + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_S8 + #define _IPPLP64 _IPPLP64_PX + +#elif defined( _N8 ) /* old Atom (SSSE3+movbe) (Silverthorne) x64 */ + #define _IPP _IPP_PX + #define _IPP32E _IPP32E_U8 + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_N8 + +#else + #define _IPP _IPP_PX + #define _IPP32E _IPP32E_PX + #define _IPPLRB _IPPLRB_PX + #define _IPPLP32 _IPPLP32_PX + #define _IPPLP64 _IPPLP64_PX + +#endif + + +#define _IPP_ARCH_IA32 1 +#define _IPP_ARCH_IA64 2 +#define _IPP_ARCH_EM64T 4 +#define _IPP_ARCH_XSC 8 +#define _IPP_ARCH_LRB 16 +#define _IPP_ARCH_LP32 32 +#define _IPP_ARCH_LP64 64 +#define _IPP_ARCH_LRB2 128 + +#if defined ( _ARCH_IA32 ) + #define _IPP_ARCH _IPP_ARCH_IA32 + +#elif defined( _ARCH_EM64T ) + #define _IPP_ARCH _IPP_ARCH_EM64T + +#elif defined( _ARCH_LRB2 ) + #define _IPP_ARCH _IPP_ARCH_LRB2 + +#elif defined( _ARCH_LP32 ) + #define _IPP_ARCH _IPP_ARCH_LP32 + +#elif defined( _ARCH_LP64 ) + #define _IPP_ARCH _IPP_ARCH_LP64 + +#else + #if defined(_M_AMD64) || defined(__x86_64) || defined(__x86_64__) + #define _IPP_ARCH _IPP_ARCH_EM64T + + #else + #define _IPP_ARCH _IPP_ARCH_IA32 + + #endif +#endif + +#if ((_IPP_ARCH == _IPP_ARCH_IA32) || (_IPP_ARCH == _IPP_ARCH_LP32)) +__INLINE +Ipp32s IPP_INT_PTR( const void* ptr ) { + union { + void* Ptr; + Ipp32s Int; + } dd; + dd.Ptr = (void*)ptr; + return dd.Int; +} + +__INLINE +Ipp32u IPP_UINT_PTR( const void* ptr ) { + union { + void* Ptr; + Ipp32u Int; + } dd; + dd.Ptr = (void*)ptr; + return dd.Int; +} +#elif ((_IPP_ARCH == _IPP_ARCH_EM64T) || (_IPP_ARCH == _IPP_ARCH_LRB2) || (_IPP_ARCH == _IPP_ARCH_LP64)) +__INLINE +Ipp64s IPP_INT_PTR( const void* ptr ) { + union { + void* Ptr; + Ipp64s Int; + } dd; + dd.Ptr = (void*)ptr; + return dd.Int; +} + +__INLINE +Ipp64u IPP_UINT_PTR( const void* ptr ) { + union { + void* Ptr; + Ipp64u Int; + } dd; + dd.Ptr = (void*)ptr; + return dd.Int; +} +#else + #define IPP_INT_PTR( ptr ) ( (long)(ptr) ) + #define IPP_UINT_PTR( ptr ) ( (unsigned long)(ptr) ) +#endif + +#define IPP_ALIGN_TYPE(type, align) ((align)/sizeof(type)-1) +#define IPP_BYTES_TO_ALIGN(ptr, align) ((-(IPP_INT_PTR(ptr)&((align)-1)))&((align)-1)) +#define IPP_ALIGNED_PTR(ptr, align) (void*)( (unsigned char*)(ptr) + (IPP_BYTES_TO_ALIGN( ptr, align )) ) + +#define IPP_ALIGNED_SIZE(size, align) (((size)+(align)-1)&~((align)-1)) + +#define IPP_MALLOC_ALIGNED_BYTES 64 +#define IPP_MALLOC_ALIGNED_8BYTES 8 +#define IPP_MALLOC_ALIGNED_16BYTES 16 +#define IPP_MALLOC_ALIGNED_32BYTES 32 + +#define IPP_ALIGNED_ARRAY(align,arrtype,arrname,arrlength)\ + char arrname##AlignedArrBuff[sizeof(arrtype)*(arrlength)+IPP_ALIGN_TYPE(char, align)];\ + arrtype *arrname = (arrtype*)IPP_ALIGNED_PTR(arrname##AlignedArrBuff,align) + +#if defined( __cplusplus ) +extern "C" { +#endif + +/* ///////////////////////////////////////////////////////////////////////////// + + IPP Context Identification + + /////////////////////////////////////////////////////////////////////////// */ + +#define IPP_CONTEXT( a, b, c, d) \ + (int)(((unsigned)(a) << 24) | ((unsigned)(b) << 16) | \ + ((unsigned)(c) << 8) | (unsigned)(d)) + +typedef enum { + idCtxUnknown = 0, + idCtxFFT_C_16sc, + idCtxFFT_C_16s, + idCtxFFT_R_16s, + idCtxFFT_C_32fc, + idCtxFFT_C_32f, + idCtxFFT_R_32f, + idCtxFFT_C_64fc, + idCtxFFT_C_64f, + idCtxFFT_R_64f, + idCtxDFT_C_16sc, + idCtxDFT_C_16s, + idCtxDFT_R_16s, + idCtxDFT_C_32fc, + idCtxDFT_C_32f, + idCtxDFT_R_32f, + idCtxDFT_C_64fc, + idCtxDFT_C_64f, + idCtxDFT_R_64f, + idCtxDCTFwd_16s, + idCtxDCTInv_16s, + idCtxDCTFwd_32f, + idCtxDCTInv_32f, + idCtxDCTFwd_64f, + idCtxDCTInv_64f, + idCtxFFT2D_C_32fc, + idCtxFFT2D_R_32f, + idCtxDFT2D_C_32fc, + idCtxDFT2D_R_32f, + idCtxFFT2D_R_32s, + idCtxDFT2D_R_32s, + idCtxDCT2DFwd_32f, + idCtxDCT2DInv_32f, + idCtxMoment64f, + idCtxMoment64s, + idCtxRandUni_8u, + idCtxRandUni_16s, + idCtxRandUni_32f, + idCtxRandUni_64f, + idCtxRandGauss_8u, + idCtxRandGauss_16s, + idCtxRandGauss_32f, + idCtxRandGauss_64f, + idCtxWTFwd_32f, + idCtxWTFwd_8u32f, + idCtxWTFwd_8s32f, + idCtxWTFwd_16u32f, + idCtxWTFwd_16s32f, + idCtxWTFwd2D_32f_C1R, + idCtxWTInv2D_32f_C1R, + idCtxWTFwd2D_32f_C3R, + idCtxWTInv2D_32f_C3R, + idCtxWTInv_32f, + idCtxWTInv_32f8u, + idCtxWTInv_32f8s, + idCtxWTInv_32f16u, + idCtxWTInv_32f16s, + idCtxMDCTFwd_32f, + idCtxMDCTInv_32f, + idCtxMDCTFwd_16s, + idCtxFIRBlock_32f, + idCtxFDP_32f, + idCtxRLMS_32f = IPP_CONTEXT( 'L', 'M', 'S', '1'), + idCtxRLMS32f_16s = IPP_CONTEXT( 'L', 'M', 'S', 0 ), + idCtxIIRAR_32f = IPP_CONTEXT( 'I', 'I', '0', '1'), + idCtxIIRBQ_32f = IPP_CONTEXT( 'I', 'I', '0', '2'), + idCtxIIRAR_32fc = IPP_CONTEXT( 'I', 'I', '0', '3'), + idCtxIIRBQ_32fc = IPP_CONTEXT( 'I', 'I', '0', '4'), + idCtxIIRAR32f_16s = IPP_CONTEXT( 'I', 'I', '0', '5'), + idCtxIIRBQ32f_16s = IPP_CONTEXT( 'I', 'I', '0', '6'), + idCtxIIRAR32fc_16sc = IPP_CONTEXT( 'I', 'I', '0', '7'), + idCtxIIRBQ32fc_16sc = IPP_CONTEXT( 'I', 'I', '0', '8'), + idCtxIIRAR32s_16s = IPP_CONTEXT( 'I', 'I', '0', '9'), + idCtxIIRBQ32s_16s = IPP_CONTEXT( 'I', 'I', '1', '0'), + idCtxIIRAR32sc_16sc = IPP_CONTEXT( 'I', 'I', '1', '1'), + idCtxIIRBQ32sc_16sc = IPP_CONTEXT( 'I', 'I', '1', '2'), + idCtxIIRAR_64f = IPP_CONTEXT( 'I', 'I', '1', '3'), + idCtxIIRBQ_64f = IPP_CONTEXT( 'I', 'I', '1', '4'), + idCtxIIRAR_64fc = IPP_CONTEXT( 'I', 'I', '1', '5'), + idCtxIIRBQ_64fc = IPP_CONTEXT( 'I', 'I', '1', '6'), + idCtxIIRAR64f_32f = IPP_CONTEXT( 'I', 'I', '1', '7'), + idCtxIIRBQ64f_32f = IPP_CONTEXT( 'I', 'I', '1', '8'), + idCtxIIRAR64fc_32fc = IPP_CONTEXT( 'I', 'I', '1', '9'), + idCtxIIRBQ64fc_32fc = IPP_CONTEXT( 'I', 'I', '2', '0'), + idCtxIIRAR64f_32s = IPP_CONTEXT( 'I', 'I', '2', '1'), + idCtxIIRBQ64f_32s = IPP_CONTEXT( 'I', 'I', '2', '2'), + idCtxIIRAR64fc_32sc = IPP_CONTEXT( 'I', 'I', '2', '3'), + idCtxIIRBQ64fc_32sc = IPP_CONTEXT( 'I', 'I', '2', '4'), + idCtxIIRAR64f_16s = IPP_CONTEXT( 'I', 'I', '2', '5'), + idCtxIIRBQ64f_16s = IPP_CONTEXT( 'I', 'I', '2', '6'), + idCtxIIRAR64fc_16sc = IPP_CONTEXT( 'I', 'I', '2', '7'), + idCtxIIRBQ64fc_16sc = IPP_CONTEXT( 'I', 'I', '2', '8'), + idCtxIIRBQDF1_32f = IPP_CONTEXT( 'I', 'I', '2', '9'), + idCtxIIRBQDF164f_32s= IPP_CONTEXT( 'I', 'I', '3', '0'), + idCtxFIRSR_32f = IPP_CONTEXT( 'F', 'I', '0', '1'), + idCtxFIRSR_32fc = IPP_CONTEXT( 'F', 'I', '0', '2'), + idCtxFIRMR_32f = IPP_CONTEXT( 'F', 'I', '0', '3'), + idCtxFIRMR_32fc = IPP_CONTEXT( 'F', 'I', '0', '4'), + idCtxFIRSR32f_16s = IPP_CONTEXT( 'F', 'I', '0', '5'), + idCtxFIRSR32fc_16sc = IPP_CONTEXT( 'F', 'I', '0', '6'), + idCtxFIRMR32f_16s = IPP_CONTEXT( 'F', 'I', '0', '7'), + idCtxFIRMR32fc_16sc = IPP_CONTEXT( 'F', 'I', '0', '8'), + idCtxFIRSR32s_16s = IPP_CONTEXT( 'F', 'I', '0', '9'), + idCtxFIRSR32sc_16sc = IPP_CONTEXT( 'F', 'I', '1', '0'), + idCtxFIRMR32s_16s = IPP_CONTEXT( 'F', 'I', '1', '1'), + idCtxFIRMR32sc_16sc = IPP_CONTEXT( 'F', 'I', '1', '2'), + idCtxFIRSR_64f = IPP_CONTEXT( 'F', 'I', '1', '3'), + idCtxFIRSR_64fc = IPP_CONTEXT( 'F', 'I', '1', '4'), + idCtxFIRMR_64f = IPP_CONTEXT( 'F', 'I', '1', '5'), + idCtxFIRMR_64fc = IPP_CONTEXT( 'F', 'I', '1', '6'), + idCtxFIRSR64f_32f = IPP_CONTEXT( 'F', 'I', '1', '7'), + idCtxFIRSR64fc_32fc = IPP_CONTEXT( 'F', 'I', '1', '8'), + idCtxFIRMR64f_32f = IPP_CONTEXT( 'F', 'I', '1', '9'), + idCtxFIRMR64fc_32fc = IPP_CONTEXT( 'F', 'I', '2', '0'), + idCtxFIRSR64f_32s = IPP_CONTEXT( 'F', 'I', '2', '1'), + idCtxFIRSR64fc_32sc = IPP_CONTEXT( 'F', 'I', '2', '2'), + idCtxFIRMR64f_32s = IPP_CONTEXT( 'F', 'I', '2', '3'), + idCtxFIRMR64fc_32sc = IPP_CONTEXT( 'F', 'I', '2', '4'), + idCtxFIRSR64f_16s = IPP_CONTEXT( 'F', 'I', '2', '5'), + idCtxFIRSR64fc_16sc = IPP_CONTEXT( 'F', 'I', '2', '6'), + idCtxFIRMR64f_16s = IPP_CONTEXT( 'F', 'I', '2', '7'), + idCtxFIRMR64fc_16sc = IPP_CONTEXT( 'F', 'I', '2', '8'), + idCtxFIRSR_16s = IPP_CONTEXT( 'F', 'I', '2', '9'), + idCtxFIRMR_16s = IPP_CONTEXT( 'F', 'I', '3', '0'), + idCtxFIRSRStream_16s= IPP_CONTEXT( 'F', 'I', '3', '1'), + idCtxFIRMRStream_16s= IPP_CONTEXT( 'F', 'I', '3', '2'), + idCtxFIRSRStream_32f= IPP_CONTEXT( 'F', 'I', '3', '3'), + idCtxFIRMRStream_32f= IPP_CONTEXT( 'F', 'I', '3', '4'), + idCtxRLMS32s_16s = IPP_CONTEXT( 'L', 'M', 'S', 'R'), + idCtxCLMS32s_16s = IPP_CONTEXT( 'L', 'M', 'S', 'C'), + idCtxEncode_JPEG2K, + idCtxDES = IPP_CONTEXT( ' ', 'D', 'E', 'S'), + idCtxBlowfish = IPP_CONTEXT( ' ', ' ', 'B', 'F'), + idCtxRijndael = IPP_CONTEXT( ' ', 'R', 'I', 'J'), + idCtxSMS4 = IPP_CONTEXT( 'S', 'M', 'S', '4'), + idCtxTwofish = IPP_CONTEXT( ' ', ' ', 'T', 'F'), + idCtxARCFOUR = IPP_CONTEXT( ' ', 'R', 'C', '4'), + idCtxRC564 = IPP_CONTEXT( 'R', 'C', '5', '1'), + idCtxRC5128 = IPP_CONTEXT( 'R', 'C', '5', '2'), + idCtxSHA1 = IPP_CONTEXT( 'S', 'H', 'S', '1'), + idCtxSHA224 = IPP_CONTEXT( 'S', 'H', 'S', '3'), + idCtxSHA256 = IPP_CONTEXT( 'S', 'H', 'S', '2'), + idCtxSHA384 = IPP_CONTEXT( 'S', 'H', 'S', '4'), + idCtxSHA512 = IPP_CONTEXT( 'S', 'H', 'S', '5'), + idCtxMD5 = IPP_CONTEXT( ' ', 'M', 'D', '5'), + idCtxHMAC = IPP_CONTEXT( 'H', 'M', 'A', 'C'), + idCtxDAA = IPP_CONTEXT( ' ', 'D', 'A', 'A'), + idCtxBigNum = IPP_CONTEXT( 'B', 'I', 'G', 'N'), + idCtxMontgomery = IPP_CONTEXT( 'M', 'O', 'N', 'T'), + idCtxPrimeNumber = IPP_CONTEXT( 'P', 'R', 'I', 'M'), + idCtxPRNG = IPP_CONTEXT( 'P', 'R', 'N', 'G'), + idCtxRSA = IPP_CONTEXT( ' ', 'R', 'S', 'A'), + idCtxRSA_PubKey = IPP_CONTEXT( 'R', 'S', 'A', '0'), + idCtxRSA_PrvKey1 = IPP_CONTEXT( 'R', 'S', 'A', '1'), + idCtxRSA_PrvKey2 = IPP_CONTEXT( 'R', 'S', 'A', '2'), + idCtxDSA = IPP_CONTEXT( ' ', 'D', 'S', 'A'), + idCtxECCP = IPP_CONTEXT( ' ', 'E', 'C', 'P'), + idCtxECCB = IPP_CONTEXT( ' ', 'E', 'C', 'B'), + idCtxECCPPoint = IPP_CONTEXT( 'P', 'E', 'C', 'P'), + idCtxECCBPoint = IPP_CONTEXT( 'P', 'E', 'C', 'B'), + idCtxDH = IPP_CONTEXT( ' ', ' ', 'D', 'H'), + idCtxDLP = IPP_CONTEXT( ' ', 'D', 'L', 'P'), + idCtxCMAC = IPP_CONTEXT( 'C', 'M', 'A', 'C'), + idCtxRFFT2_8u, + idCtxHilbert_32f32fc, + idCtxHilbert_16s32fc, + idCtxHilbert_16s16sc, + idCtxTone_16s, + idCtxTriangle_16s, + idCtxDFTOutOrd_C_32fc, + idCtxDFTOutOrd_C_64fc, + idCtxFFT_C_32sc, + idCtxFFT_C_32s, + idCtxFFT_R_32s, + idCtxFFT_R_16s32s, + idCtxDecodeProgr_JPEG2K, + idCtxWarp_MPEG4, + idCtxQuantInvIntra_MPEG4, + idCtxQuantInvInter_MPEG4, + idCtxQuantIntra_MPEG4, + idCtxQuantInter_MPEG4, + idCtxAnalysisFilter_SBR_C_32f32fc, + idCtxAnalysisFilter_SBR_C_32f, + idCtxAnalysisFilter_SBR_R_32f, + idCtxSynthesisFilter_SBR_C_32fc32f, + idCtxSynthesisFilter_SBR_C_32f, + idCtxSynthesisFilter_SBR_R_32f, + idCtxSynthesisDownFilter_SBR_C_32fc32f, + idCtxSynthesisDownFilter_SBR_C_32f, + idCtxSynthesisDownFilter_SBR_R_32f, + idCtxVLCEncode, + idCtxVLCDecode, + idCtxAnalysisFilter_SBR_C_32s32sc, + idCtxAnalysisFilter_SBR_R_32s, + idCtxSynthesisFilter_SBR_C_32sc32s, + idCtxSynthesisFilter_SBR_R_32s, + idCtxSynthesisDownFilter_SBR_C_32sc32s, + idCtxSynthesisDownFilter_SBR_R_32s, + idCtxSynthesisFilter_PQMF_MP3_32f, + idCtxAnalysisFilter_PQMF_MP3_32f, + idCtxResampleRow, + idCtxAnalysisFilter_SBR_Enc_C_32f32fc, + idCtxSynthesisFilter_DTS_32f, + idCtxFilterBilateralGauss_8u, + idCtxFilterBilateralGaussFast_8u, + idCtxBGF, + idCtxPolyGF, + idCtxRSenc, + idCtxRSdec, + idCtxSnow3g = IPP_CONTEXT( 'S', 'n', 'o', 'w'), + idCtxSnow3gF8, + idCtxSnow3gF9, + idCtxKasumi = IPP_CONTEXT( 'K', 'a', 's', 'u'), + idCtxKasumiF8, + idCtxKasumiF9, + idCtxResizeHannFilter_8u, + idCtxResizeLanczosFilter_8u, + idCtxAESXCBC, + idCtxAESCCM, + idCtxAESGCM, + idCtxMsgCatalog, + idCtxGFP, + idCtxGFPE, + idCtxGFPX, + idCtxGFPXE, + idCtxGFPXQX, + idCtxGFPXQXE, + idCtxGFPEC, + idCtxGFPPoint, + idCtxGFPXEC, + idCtxGFPXECPoint, + idCtxPairing, + idCtxResize_32f, + idCtxResizeYUV420, + idCtxResizeYUV422, + idCtxResize_64f, + idCtxFilterBilateralBorder, + idCtxThresholdAdaptiveGauss, + idCtxHOG, + idCtxFastN, + idCtxHash, + idCtxSM3 +} IppCtxId; + + + + +/* ///////////////////////////////////////////////////////////////////////////// + Helpers + /////////////////////////////////////////////////////////////////////////// */ + +#define IPP_NOERROR_RET() return ippStsNoErr +#define IPP_ERROR_RET( ErrCode ) return (ErrCode) + +#ifdef _IPP_DEBUG + + #define IPP_BADARG_RET( expr, ErrCode )\ + {if (expr) { IPP_ERROR_RET( ErrCode ); }} + +#else + + #define IPP_BADARG_RET( expr, ErrCode ) + +#endif + + + #define IPP_BAD_SIZE_RET( n )\ + IPP_BADARG_RET( (n)<=0, ippStsSizeErr ) + + #define IPP_BAD_STEP_RET( n )\ + IPP_BADARG_RET( (n)<=0, ippStsStepErr ) + + #define IPP_BAD_PTR1_RET( ptr )\ + IPP_BADARG_RET( NULL==(ptr), ippStsNullPtrErr ) + + #define IPP_BAD_PTR2_RET( ptr1, ptr2 )\ + {IPP_BAD_PTR1_RET( ptr1 ); IPP_BAD_PTR1_RET( ptr2 )} + + #define IPP_BAD_PTR3_RET( ptr1, ptr2, ptr3 )\ + {IPP_BAD_PTR2_RET( ptr1, ptr2 ); IPP_BAD_PTR1_RET( ptr3 )} + + #define IPP_BAD_PTR4_RET( ptr1, ptr2, ptr3, ptr4 )\ + {IPP_BAD_PTR2_RET( ptr1, ptr2 ); IPP_BAD_PTR2_RET( ptr3, ptr4 )} + + #define IPP_BAD_ISIZE_RET(roi) \ + IPP_BADARG_RET( ((roi).width<=0 || (roi).height<=0), ippStsSizeErr) + +/* ////////////////////////////////////////////////////////////////////////// */ +/* internal messages */ + +#define MSG_LOAD_DLL_ERR (-9700) /* Error at loading of %s library */ +#define MSG_NO_DLL (-9701) /* No DLLs were found in the Waterfall procedure */ +#define MSG_NO_SHARED (-9702) /* No shared libraries were found in the Waterfall procedure */ + +/* ////////////////////////////////////////////////////////////////////////// */ + + +typedef union { /* double precision */ + Ipp64s hex; + Ipp64f fp; +} IppFP_64f; + +typedef union { /* single precision */ + Ipp32s hex; + Ipp32f fp; +} IppFP_32f; + + +extern const IppFP_32f ippConstantOfNAN_32f; +extern const IppFP_64f ippConstantOfNAN_64f; + +extern const IppFP_32f ippConstantOfINF_32f; +extern const IppFP_64f ippConstantOfINF_64f; +extern const IppFP_32f ippConstantOfINF_NEG_32f; +extern const IppFP_64f ippConstantOfINF_NEG_64f; + +#define NAN_32F (ippConstantOfNAN_32f.fp) +#define NAN_64F (ippConstantOfNAN_64f.fp) +#define INF_32F (ippConstantOfINF_32f.fp) +#define INF_64F (ippConstantOfINF_64f.fp) +#define INF_NEG_32F (ippConstantOfINF_NEG_32f.fp) +#define INF_NEG_64F (ippConstantOfINF_NEG_64f.fp) + +/* ////////////////////////////////////////////////////////////////////////// */ + +typedef enum { + ippunreg=-1, + ippac = 0, + ippcc = 1, + ippch = 2, + ippcp = 3, + ippcv = 4, + ippdc = 5, + ippdi = 6, + ippgen = 7, + ippi = 8, + ippj = 9, + ippm = 10, + ippr = 11, + ipps = 12, + ippsc = 13, + ippsr = 14, + ippvc = 15, + ippvm = 16, + ippmsdk = 17, + ippcpepid = 18, + ippe = 19, + ipprs = 20, + ippsq = 21, + ippnomore +} IppDomain; + +int __CDECL ownGetNumThreads( void ); +int __CDECL ownGetFeature( Ipp64u MaskOfFeature ); /* the main function of tick-tock dispatcher */ + +#ifdef _IPP_DYNAMIC +typedef IppStatus (__STDCALL *DYN_RELOAD)( int ); +void __CDECL ownRegisterLib( IppDomain, DYN_RELOAD ); +void __CDECL ownUnregisterLib( IppDomain ); +#endif + +/* the number of threads available for any ipp function that uses OMP; */ +/* at the ippxx.dll loading time is equal to the number of logical processors, */ +/* and can be changed ONLY externally by library user to any desired number */ +/* by means of ippSetNumThreads() function */ +#define IPP_GET_NUM_THREADS() ( ownGetNumThreads() ) +#define IPP_OMP_NUM_THREADS() num_threads( IPP_GET_NUM_THREADS() ) +#define IPP_OMP_LIMIT_MAX_NUM_THREADS(n) num_threads( IPP_MIN(IPP_GET_NUM_THREADS(),(n))) + + +/* ////////////////////////////////////////////////////////////////////////// */ + +/* Define NULL pointer value */ +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#define UNREFERENCED_PARAMETER(p) (p)=(p) + +#if defined( _IPP_MARK_LIBRARY ) +static char G[] = {73, 80, 80, 71, 101, 110, 117, 105, 110, 101, 243, 193, 210, 207, 215}; +#endif + + +#define STR2(x) #x +#define STR(x) STR2(x) +#define MESSAGE( desc )\ + message(__FILE__ "(" STR(__LINE__) "):" #desc) + +/* +// endian definition +*/ +#define IPP_LITTLE_ENDIAN (0) +#define IPP_BIG_ENDIAN (1) + +#if defined( _IPP_LE ) + #define IPP_ENDIAN IPP_LITTLE_ENDIAN + +#elif defined( _IPP_BE ) + #define IPP_ENDIAN IPP_BIG_ENDIAN + +#else + #if defined( __ARMEB__ ) + #define IPP_ENDIAN IPP_BIG_ENDIAN + + #else + #define IPP_ENDIAN IPP_LITTLE_ENDIAN + + #endif +#endif + + +/* ////////////////////////////////////////////////////////////////////////// */ + +/* intrinsics */ +#if (_IPP >= _IPP_A6) || (_IPP32E >= _IPP32E_M7) + #if defined(__INTEL_COMPILER) || (_MSC_VER >= 1300) + #if (_IPP == _IPP_A6) + #include "xmmintrin.h" + #elif (_IPP == _IPP_W7) + #if defined(__INTEL_COMPILER) + #include "emmintrin.h" + #else + #undef _W7 + #include "emmintrin.h" + #define _W7 + #endif + #define _mm_loadu _mm_loadu_si128 + #elif (_IPP == _IPP_T7) || (_IPP32E == _IPP32E_M7) + #if defined(__INTEL_COMPILER) + #include "pmmintrin.h" + #define _mm_loadu _mm_lddqu_si128 + #elif (_MSC_FULL_VER >= 140050110) + #include "intrin.h" + #define _mm_loadu _mm_lddqu_si128 + #elif (_MSC_FULL_VER < 140050110) + #include "emmintrin.h" + #define _mm_loadu _mm_loadu_si128 + #endif + #elif (_IPP == _IPP_V8) || (_IPP32E == _IPP32E_U8) + #if defined(__INTEL_COMPILER) + #include "tmmintrin.h" + #define _mm_loadu _mm_lddqu_si128 + #elif (_MSC_FULL_VER >= 140050110) + #include "intrin.h" + #define _mm_loadu _mm_lddqu_si128 + #elif (_MSC_FULL_VER < 140050110) + #include "emmintrin.h" + #define _mm_loadu _mm_loadu_si128 + #endif + #elif (_IPP == _IPP_P8) || (_IPP32E == _IPP32E_Y8) + #if defined(__INTEL_COMPILER) + #include "smmintrin.h" + #define _mm_loadu _mm_lddqu_si128 + #elif (_MSC_FULL_VER >= 140050110) + #include "intrin.h" + #define _mm_loadu _mm_lddqu_si128 + #elif (_MSC_FULL_VER < 140050110) + #include "emmintrin.h" + #define _mm_loadu _mm_loadu_si128 + #endif + #elif (_IPP >= _IPP_G9) || (_IPP32E >= _IPP32E_E9) + #if defined(__INTEL_COMPILER) + #include "immintrin.h" + #define _mm_loadu _mm_lddqu_si128 + #elif (_MSC_FULL_VER >= 160021003) + #include "immintrin.h" + #define _mm_loadu _mm_lddqu_si128 + #endif + #endif + #endif +#elif (_IPPLP32 >= _IPPLP32_S8) || (_IPPLP64 >= _IPPLP64_N8) + #if defined(__INTEL_COMPILER) + #include "tmmintrin.h" + #define _mm_loadu _mm_lddqu_si128 + #elif (_MSC_FULL_VER >= 140050110) + #include "intrin.h" + #define _mm_loadu _mm_lddqu_si128 + #elif (_MSC_FULL_VER < 140050110) + #include "emmintrin.h" + #define _mm_loadu _mm_loadu_si128 + #endif +#elif (_IPPLRB >= _IPPLRB_B2) + #if defined(__INTEL_COMPILER) || defined(_REF_LIB) + #include "immintrin.h" + #endif +#endif + +// **** intrinsics for bit casting **** +#if defined(__INTEL_COMPILER) +extern unsigned int __intel_castf32_u32(float val); +extern float __intel_castu32_f32(unsigned int val); +extern unsigned __int64 __intel_castf64_u64(double val); +extern double __intel_castu64_f64(unsigned __int64 val); + #define __CAST_32f32u(val) __intel_castf32_u32((Ipp32f)val) + #define __CAST_32u32f(val) __intel_castu32_f32((Ipp32u)val) + #define __CAST_64f64u(val) __intel_castf64_u64((Ipp64f)val) + #define __CAST_64u64f(val) __intel_castu64_f64((Ipp64u)val) +#else + #define __CAST_32f32u(val) ( *((Ipp32u*)&val) ) + #define __CAST_32u32f(val) ( *((Ipp32f*)&val) ) + #define __CAST_64f64u(val) ( *((Ipp64u*)&val) ) + #define __CAST_64u64f(val) ( *((Ipp64f*)&val) ) +#endif + + +// short names for vector registers casting +#define _pd2ps _mm_castpd_ps +#define _ps2pd _mm_castps_pd +#define _pd2pi _mm_castpd_si128 +#define _pi2pd _mm_castsi128_pd +#define _ps2pi _mm_castps_si128 +#define _pi2ps _mm_castsi128_ps + +#define _ypd2ypi _mm256_castpd_si256 +#define _ypi2ypd _mm256_castsi256_pd +#define _yps2ypi _mm256_castps_si256 +#define _ypi2yps _mm256_castsi256_ps +#define _ypd2yps _mm256_castpd_ps +#define _yps2ypd _mm256_castps_pd + +#define _yps2ps _mm256_castps256_ps128 +#define _ypi2pi _mm256_castsi256_si128 +#define _ypd2pd _mm256_castpd256_pd128 +#define _ps2yps _mm256_castps128_ps256 +#define _pi2ypi _mm256_castsi128_si256 +#define _pd2ypd _mm256_castpd128_pd256 + + +#if defined(__INTEL_COMPILER) +#define __IVDEP ivdep +#else +#define __IVDEP message("message :: 'ivdep' is not defined") +#endif +//usage: #pragma __IVDEP + +/* ////////////////////////////////////////////////////////////////////////// + _IPP_DATA shoul be defined only: + - if compile not merged library + - only for 1 CPU for merged library to avoid data duplication +*/ +#if defined( _MERGED_BLD ) && ( defined(_G9) || defined(_E9) ) /* compile data only for g9 and e9 CPU */ + #define _IPP_DATA 1 +#elif !defined( _MERGED_BLD ) /* compile data if it isn't merged library */ + #define _IPP_DATA 1 +#endif + + +#if defined( __cplusplus ) +} +#endif + +#endif /* __OWNDEFS_H__ */ + diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/owncp.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/owncp.h new file mode 100644 index 0000000000..5793989761 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/owncp.h @@ -0,0 +1,149 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#ifndef __OWNCP_H__ +#define __OWNCP_H__ + +#ifndef __OWNDEFS_H__ + #include "owndefs.h" +#endif + +#ifndef __IPPCP_H__ + #include "ippcp.h" +#endif + +#pragma warning( disable : 4324) + +/* ippCP length */ +typedef int cpSize; + +/* +// common macros & definitions +*/ + +/* size of cache line (bytes) */ +#define CACHE_LINE_SIZE (64) +#define LOG_CACHE_LINE_SIZE (6) + +/* swap data & pointers */ +#define SWAP_PTR(ATYPE, pX,pY) { ATYPE* aPtr=(pX); (pX)=(pY); (pY)=aPtr; } +#define SWAP(x,y) {(x)^=(y); (y)^=(x); (x)^=(y);} + +/* alignment value */ +#define ALIGN_VAL ((int)sizeof(void*)) + +/* bitsize */ +#define BYTESIZE (8) +#define BITSIZE(x) ((int)(sizeof(x)*BYTESIZE)) + +/* bit length -> byte/word length conversion */ +#define BITS2WORD8_SIZE(x) (((x)+ 7)>>3) +#define BITS2WORD16_SIZE(x) (((x)+15)>>4) +#define BITS2WORD32_SIZE(x) (((x)+31)>>5) +#define BITS2WORD64_SIZE(x) (((x)+63)>>6) + +/* WORD and DWORD manipulators */ +#define LODWORD(x) ((Ipp32u)(x)) +#define HIDWORD(x) ((Ipp32u)(((Ipp64u)(x) >>32) & 0xFFFFFFFF)) + +#define MAKEHWORD(bLo,bHi) ((Ipp16u)(((Ipp8u)(bLo)) | ((Ipp16u)((Ipp8u)(bHi))) << 8)) +#define MAKEWORD(hLo,hHi) ((Ipp32u)(((Ipp16u)(hLo)) | ((Ipp32u)((Ipp16u)(hHi))) << 16)) +#define MAKEDWORD(wLo,wHi) ((Ipp64u)(((Ipp32u)(wLo)) | ((Ipp64u)((Ipp32u)(wHi))) << 32)) + +/* extract byte */ +#define EBYTE(w,n) ((Ipp8u)((w) >> (8 * (n)))) + +/* hexString <-> Ipp32u conversion */ +#define HSTRING_TO_U32(ptrByte) \ + (((ptrByte)[0]) <<24) \ + +(((ptrByte)[1]) <<16) \ + +(((ptrByte)[2]) <<8) \ + +((ptrByte)[3]) +#define U32_TO_HSTRING(ptrByte, x) \ + (ptrByte)[0] = (Ipp8u)((x)>>24); \ + (ptrByte)[1] = (Ipp8u)((x)>>16); \ + (ptrByte)[2] = (Ipp8u)((x)>>8); \ + (ptrByte)[3] = (Ipp8u)(x) + +/* 32- and 64-bit masks for MSB of nbits-sequence */ +#define MAKEMASK32(nbits) (0xFFFFFFFF >>((32 - ((nbits)&0x1F)) &0x1F)) +#define MAKEMASK64(nbits) (0xFFFFFFFFFFFFFFFF >>((64 - ((nbits)&0x3F)) &0x3F)) + +/* Logical Shifts (right and left) of WORD */ +#define LSR32(x,nBits) ((x)>>(nBits)) +#define LSL32(x,nBits) ((x)<<(nBits)) + +/* Rorate (right and left) of WORD */ +#if defined(_MSC_VER) +# include +# define ROR32(x, nBits) _lrotr((x),(nBits)) +# define ROL32(x, nBits) _lrotl((x),(nBits)) +#else +# define ROR32(x, nBits) (LSR32((x),(nBits)) | LSL32((x),32-(nBits))) +# define ROL32(x, nBits) ROR32((x),(32-(nBits))) +#endif + +/* Logical Shifts (right and left) of DWORD */ +#define LSR64(x,nBits) ((x)>>(nBits)) +#define LSL64(x,nBits) ((x)<<(nBits)) + +/* Rorate (right and left) of DWORD */ +#define ROR64(x, nBits) (LSR64((x),(nBits)) | LSL64((x),64-(nBits))) +#define ROL64(x, nBits) ROR64((x),(64-(nBits))) + +/* change endian */ +#if defined(_MSC_VER) +# define ENDIANNESS(x) _byteswap_ulong((x)) +# define ENDIANNESS32(x) ENDIANNESS((x)) +# define ENDIANNESS64(x) _byteswap_uint64((x)) +#else +# define ENDIANNESS(x) ((ROR32((x), 24) & 0x00ff00ff) | (ROR32((x), 8) & 0xff00ff00)) +# define ENDIANNESS32(x) ENDIANNESS((x)) +# define ENDIANNESS64(x) MAKEDWORD(ENDIANNESS(HIDWORD((x))), ENDIANNESS(LODWORD((x)))) +#endif + +#define IPP_MAKE_MULTIPLE_OF_8(x) ((x) = ((x)+7)&(~7)) +#define IPP_MAKE_MULTIPLE_OF_16(x) ((x) = ((x)+15)&(~15)) + +/* 64-bit constant */ +#if !defined(__GNUC__) + #define CONST_64(x) (x) /*(x##i64)*/ +#else + #define CONST_64(x) (x##LL) +#endif + +/* copy under mask */ +#define MASKED_COPY_BNU(dst, mask, src1, src2, len) { \ + cpSize i; \ + for(i=0; i<(len); i++) (dst)[i] = ((mask) & (src1)[i]) | (~(mask) & (src2)[i]); \ +} + +#endif /* __OWNCP_H__ */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesauthcmacca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesauthcmacca.c new file mode 100644 index 0000000000..0443664763 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesauthcmacca.c @@ -0,0 +1,396 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpcmac.h" +#include "pcpaesm.h" +#include "pcptool.h" + +#include "pcprijtables.h" + +/*F* +// Name: ippsAES_CMACGetSize +// +// Purpose: Returns size of AES-CMAC context (in bytes). +// +// Returns: Reason: +// ippStsNullPtrErr pSzie == NULL +// ippStsNoErr no errors +// +// Parameters: +// pSize pointer to the AES-CMAC size of context +// +*F*/ +static int cpSizeofCtx_AESCMAC(void) +{ + return sizeof(IppsAES_CMACState) + AESCMAC_ALIGNMENT-1; +} + +IPPFUN(IppStatus, ippsAES_CMACGetSize,(int* pSize)) +{ + /* test size's pointer */ + IPP_BAD_PTR1_RET(pSize); + + *pSize = cpSizeofCtx_AESCMAC(); + + return ippStsNoErr; +} + + +/*F* +// Name: ippsAES_CMACInit +// +// Purpose: Init AES-CMAC context. +// +// Returns: Reason: +// ippStsNullPtrErr pCtx == NULL +// ippStsMemAllocErr size of buffer is not match fro operation +// ippStsLengthErr keyLen != 16 +// keyLen != 24 +// keyLen != 32 +// ippStsNoErr no errors +// +// Parameters: +// pKey pointer to the secret key +// keyLen length of secret key +// pCtx pointer to the CMAC context +// ctxSize available size (in bytes) of buffer above +// +*F*/ +static +void init(IppsAES_CMACState* pCtx) +{ + /* buffer is empty */ + CMAC_INDX(pCtx) = 0; + /* zeros MAC */ + PaddBlock(0, CMAC_MAC(pCtx), MBS_RIJ128); +} + +static +void LogicalLeftSift16(const Ipp8u* pSrc, Ipp8u* pDst) +{ + Ipp32u carry = 0; + int n; + for(n=0; n<16; n++) { + Ipp32u x = pSrc[16-1-n] + pSrc[16-1-n] + carry; + pDst[16-1-n] = (Ipp8u)x; + carry = (x>>8) & 0xFF; + } +} + +IPPFUN(IppStatus, ippsAES_CMACInit,(const Ipp8u* pKey, int keyLen, IppsAES_CMACState* pCtx, int ctxSize)) +{ + /* test pCtx pointer */ + IPP_BAD_PTR1_RET(pCtx); + + /* test available size of context buffer */ + IPP_BADARG_RET(ctxSize>7)) & 0x87); /* ^ Rb changed for constant time execution */ + + /* precompute k2 subkey */ + msb = (CMAC_K1(pCtx))[0]; + LogicalLeftSift16(CMAC_K1(pCtx),CMAC_K2(pCtx)); + (CMAC_K2(pCtx))[MBS_RIJ128-1] ^= (Ipp8u)((0-(msb>>7)) & 0x87); /* ^ Rb changed for constant time execution */ + } + + return sts; + } +} + + +/*F* +// Name: ippsAES_CMACUpdate +// +// Purpose: Updates intermadiate digest based on input stream. +// +// Returns: Reason: +// ippStsNullPtrErr pSrc == NULL +// pCtx == NULL +// ippStsContextMatchErr !VALID_AESCMAC_ID() +// ippStsLengthErr len <0 +// ippStsNoErr no errors +// +// Parameters: +// pSrc pointer to the input stream +// len input stream length +// pCtx pointer to the CMAC context +// +*F*/ +static +void AES_CMAC_processing(Ipp8u* pDigest, const Ipp8u* pSrc, int processedLen, const IppsAESSpec* pAES) +{ + /* setup encoder method */ + RijnCipher encoder = RIJ_ENCODER(pAES); + + while(processedLen) { + ((Ipp32u*)pDigest)[0] ^= ((Ipp32u*)pSrc)[0]; + ((Ipp32u*)pDigest)[1] ^= ((Ipp32u*)pSrc)[1]; + ((Ipp32u*)pDigest)[2] ^= ((Ipp32u*)pSrc)[2]; + ((Ipp32u*)pDigest)[3] ^= ((Ipp32u*)pSrc)[3]; + + encoder(pDigest, pDigest, RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox); + + pSrc += MBS_RIJ128; + processedLen -= MBS_RIJ128; + } +} + +IPPFUN(IppStatus, ippsAES_CMACUpdate,(const Ipp8u* pSrc, int len, IppsAES_CMACState* pCtx)) +{ + int processedLen; + + /* test context pointer */ + IPP_BAD_PTR1_RET(pCtx); + /* use aligned context */ + pCtx = (IppsAES_CMACState*)( IPP_ALIGNED_PTR(pCtx, AESCMAC_ALIGNMENT) ); + + /* test ID */ + IPP_BADARG_RET(!VALID_AESCMAC_ID(pCtx), ippStsContextMatchErr); + /* test input message and it's length */ + IPP_BADARG_RET((len<0 && pSrc), ippStsLengthErr); + /* test source pointer */ + IPP_BADARG_RET((len && !pSrc), ippStsNullPtrErr); + + if(!len) + return ippStsNoErr; + + { + /* + // test internal buffer filling + */ + if(CMAC_INDX(pCtx)) { + /* copy from input stream to the internal buffer as match as possible */ + processedLen = IPP_MIN(len, (MBS_RIJ128 - CMAC_INDX(pCtx))); + CopyBlock(pSrc, CMAC_BUFF(pCtx)+CMAC_INDX(pCtx), processedLen); + + /* internal buffer filling */ + CMAC_INDX(pCtx) += processedLen; + + /* update message pointer and length */ + pSrc += processedLen; + len -= processedLen; + + if(!len) + return ippStsNoErr; + + /* update CMAC if buffer full but not the last */ + if(MBS_RIJ128==CMAC_INDX(pCtx) ) { + const IppsAESSpec* pAES = &CMAC_CIPHER(pCtx); + /* setup encoder method */ + RijnCipher encoder = RIJ_ENCODER(pAES); + XorBlock16(CMAC_BUFF(pCtx), CMAC_MAC(pCtx), CMAC_MAC(pCtx)); + + encoder(CMAC_MAC(pCtx), CMAC_MAC(pCtx), RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox); + + CMAC_INDX(pCtx) = 0; + } + } + + /* + // main part + */ + processedLen = len & ~(MBS_RIJ128-1); + if(!(len & (MBS_RIJ128-1))) + processedLen -= MBS_RIJ128; + if(processedLen) { + const IppsAESSpec* pAES = &CMAC_CIPHER(pCtx); + + AES_CMAC_processing(CMAC_MAC(pCtx), pSrc, processedLen, pAES); + + /* update message pointer and length */ + pSrc += processedLen; + len -= processedLen; + } + + /* + // remaind + */ + if(len) { + CopyBlock(pSrc, (Ipp8u*)(&CMAC_BUFF(pCtx)), len); + /* update internal buffer filling */ + CMAC_INDX(pCtx) += len; + } + + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsAES_CMACFinal +// +// Purpose: Stop message digesting and return MD. +// +// Returns: Reason: +// ippStsNullPtrErr pMD == NULL +// pCtx == NULL +// ippStsContextMatchErr !VALID_AESCMAC_ID() +// ippStsLengthErr MBS_RIJ128 < mdLen <1 +// ippStsNoErr no errors +// +// Parameters: +// pMD pointer to the output message digest +// mdLen requested length of the message digest +// pCtx pointer to the CMAC context +// +*F*/ +IPPFUN(IppStatus, ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pCtx)) +{ + /* test context pointer and ID */ + IPP_BAD_PTR1_RET(pCtx); + /* use aligned context */ + pCtx = (IppsAES_CMACState*)( IPP_ALIGNED_PTR(pCtx, AESCMAC_ALIGNMENT) ); + + IPP_BADARG_RET(!VALID_AESCMAC_ID(pCtx), ippStsContextMatchErr); + /* test DAC pointer */ + IPP_BAD_PTR1_RET(pMD); + IPP_BADARG_RET((mdLen<1)||(MBS_RIJ128idCtx) +#define AESGCM_STATE(stt) ((stt)->state) + +#define AESGCM_IV_LEN(stt) ((stt)->ivLen) +#define AESGCM_AAD_LEN(stt) ((stt)->aadLen) +#define AESGCM_TXT_LEN(stt) ((stt)->txtLen) + +#define AESGCM_BUFLEN(stt) ((stt)->bufLen) +#define AESGCM_COUNTER(stt) ((stt)->counter) +#define AESGCM_ECOUNTER0(stt) ((stt)->ecounter0) +#define AESGCM_ECOUNTER(stt) ((stt)->ecounter) +#define AESGCM_GHASH(stt) ((stt)->ghash) + +#define AESGCM_HASH(stt) ((stt)->hashFun) +#define AESGCM_AUTH(stt) ((stt)->authFun) +#define AESGCM_ENC(stt) ((stt)->encFun) +#define AESGCM_DEC(stt) ((stt)->decFun) + +#define AESGCM_CIPHER(stt) (IppsAESSpec*)(&((stt)->cipher)) + +#define AESGCM_HKEY(stt) ((stt)->multiplier) +#define AESGCM_CPWR(stt) ((stt)->multiplier) +#define AES_GCM_MTBL(stt) ((stt)->multiplier) + +#define AESGCM_VALID_ID(stt) (AESGCM_ID((stt))==idCtxAESGCM) + + +__INLINE void IncrementCounter32(Ipp8u* pCtr) +{ + int i; + for(i=BLOCK_SIZE-1; i>=CTR_POS && 0==(Ipp8u)(++pCtr[i]); i--) ; +} + + +void AesGcmPrecompute_table2K(Ipp8u* pPrecomputeData, const Ipp8u* pHKey); +void AesGcmMulGcm_table2K(Ipp8u* pGhash, const Ipp8u* pHkey, const void* pParam); +void AesGcmAuth_table2K(Ipp8u* pGhash, const Ipp8u* pSrc, int len, const Ipp8u* pHkey, const void* pParam); +void wrpAesGcmEnc_table2K(Ipp8u* pDst, const Ipp8u* pSrc, int len, IppsAES_GCMState* pCtx); +void wrpAesGcmDec_table2K(Ipp8u* pDst, const Ipp8u* pSrc, int len, IppsAES_GCMState* pCtx); + +extern const Ipp16u AesGcmConst_table[256]; /* precomputed reduction table */ + +#endif /* _CP_AESAUTH_GCM_H*/ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesauthgcmca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesauthgcmca.c new file mode 100644 index 0000000000..bf8d8264b4 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesauthgcmca.c @@ -0,0 +1,731 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" + +#include "pcpaesauthgcm.h" +#include "pcptool.h" + +#include "pcprijtables.h" + +/*F* +// Name: ippsAES_GCMGetSize +// +// Purpose: Returns size of AES_GCM state (in bytes). +// +// Returns: Reason: +// ippStsNullPtrErr pSize == NULL +// ippStsNoErr no errors +// +// Parameters: +// pSize pointer to size of context +// +*F*/ +static int cpSizeofCtx_AESGCM(void) +{ + int precomp_size; + + precomp_size = PRECOMP_DATA_SIZE_FAST2K; + + /* decrease precomp_size as soon as BLOCK_SIZE bytes already reserved in context */ + precomp_size -= BLOCK_SIZE; + + return sizeof(IppsAES_GCMState) + +precomp_size + +AESGCM_ALIGNMENT-1; +} + +IPPFUN(IppStatus, ippsAES_GCMGetSize,(int* pSize)) +{ + /* test size's pointer */ + IPP_BAD_PTR1_RET(pSize); + + *pSize = cpSizeofCtx_AESGCM(); + + return ippStsNoErr; +} + + +/*F* +// Name: ippsAES_GCMReset +// +// Purpose: Resets AES_GCM context. +// +// Returns: Reason: +// ippStsNullPtrErr pState== NULL +// ippStsContextMatchErr pState points on invalid context +// ippStsNoErr no errors +// +// Parameters: +// pState pointer to the context +// +*F*/ +IPPFUN(IppStatus, ippsAES_GCMReset,(IppsAES_GCMState* pState)) +{ + /* test pState pointer */ + IPP_BAD_PTR1_RET(pState); + + /* use aligned context */ + pState = (IppsAES_GCMState*)( IPP_ALIGNED_PTR(pState, AESGCM_ALIGNMENT) ); + /* test context validity */ + IPP_BADARG_RET(!AESGCM_VALID_ID(pState), ippStsContextMatchErr); + + /* reset GCM */ + AESGCM_STATE(pState) = GcmInit; + AESGCM_IV_LEN(pState) = CONST_64(0); + AESGCM_AAD_LEN(pState) = CONST_64(0); + AESGCM_TXT_LEN(pState) = CONST_64(0); + + AESGCM_BUFLEN(pState) = 0; + PaddBlock(0, AESGCM_COUNTER(pState), BLOCK_SIZE); + PaddBlock(0, AESGCM_ECOUNTER(pState), BLOCK_SIZE); + PaddBlock(0, AESGCM_ECOUNTER0(pState), BLOCK_SIZE); + PaddBlock(0, AESGCM_GHASH(pState), BLOCK_SIZE); + + return ippStsNoErr; +} + + +/*F* +// Name: ippsAES_GCMInit +// +// Purpose: Init AES_GCM context for future usage. +// +// Returns: Reason: +// ippStsNullPtrErr pState == NULL +// ippStsMemAllocErr size of buffer is not match fro operation +// ippStsLengthErr keyLen != 16 && +// != 24 && +// != 32 +// ippStsNoErr no errors +// +// Parameters: +// pKey pointer to the secret key +// keyLen length of secret key +// pState pointer to the AES-GCM context +// ctxSize available size (in bytes) of buffer above +// +*F*/ +IPPFUN(IppStatus, ippsAES_GCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_GCMState* pState, int ctxSize)) +{ + /* test pCtx pointer */ + IPP_BAD_PTR1_RET(pState); + + /* test available size of context buffer */ + IPP_BADARG_RET(ctxSize0 +// ippStsContextMatchErr !AESGCM_VALID_ID() +// ippStsLengthErr ivLen <0 +// ippStsBadArgErr illegal sequence call +// ippStsNoErr no errors +// +// Parameters: +// pIV pointer to the IV +// ivLen length of IV (it could be 0) +// pState pointer to the context +// +*F*/ +IPPFUN(IppStatus, ippsAES_GCMProcessIV,(const Ipp8u* pIV, int ivLen, IppsAES_GCMState* pState)) +{ + /* test pState pointer */ + IPP_BAD_PTR1_RET(pState); + + /* test IV pointer and length */ + IPP_BADARG_RET(ivLen && !pIV, ippStsNullPtrErr); + IPP_BADARG_RET(ivLen<0, ippStsLengthErr); + + /* use aligned context */ + pState = (IppsAES_GCMState*)( IPP_ALIGNED_PTR(pState, AESGCM_ALIGNMENT) ); + /* test context validity */ + IPP_BADARG_RET(!AESGCM_VALID_ID(pState), ippStsContextMatchErr); + + IPP_BADARG_RET(!(GcmInit==AESGCM_STATE(pState) || GcmIVprocessing==AESGCM_STATE(pState)), ippStsBadArgErr); + + /* switch IVprocessing on */ + AESGCM_STATE(pState) = GcmIVprocessing; + + /* test if buffer is not empty */ + if(AESGCM_BUFLEN(pState)) { + int locLen = IPP_MIN(ivLen, BLOCK_SIZE-AESGCM_BUFLEN(pState)); + XorBlock(pIV, AESGCM_COUNTER(pState)+AESGCM_BUFLEN(pState), AESGCM_COUNTER(pState)+AESGCM_BUFLEN(pState), locLen); + AESGCM_BUFLEN(pState) += locLen; + + /* if buffer full */ + if(BLOCK_SIZE==AESGCM_BUFLEN(pState)) { + MulGcm_ ghashFunc = AESGCM_HASH(pState); + ghashFunc(AESGCM_COUNTER(pState), AESGCM_HKEY(pState), AesGcmConst_table); + AESGCM_BUFLEN(pState) = 0; + } + + AESGCM_IV_LEN(pState) += locLen; + pIV += locLen; + ivLen -= locLen; + } + + /* process main part of IV */ + { + int lenBlks = ivLen & (-BLOCK_SIZE); + if(lenBlks) { + Auth_ authFunc = AESGCM_AUTH(pState); + + authFunc(AESGCM_COUNTER(pState), pIV, lenBlks, AESGCM_HKEY(pState), AesGcmConst_table); + + AESGCM_IV_LEN(pState) += lenBlks; + pIV += lenBlks; + ivLen -= lenBlks; + } + } + + /* copy the rest of IV into the buffer */ + if(ivLen) { + XorBlock(pIV, AESGCM_COUNTER(pState), AESGCM_COUNTER(pState), ivLen); + AESGCM_IV_LEN(pState) += ivLen; + AESGCM_BUFLEN(pState) += ivLen; + } + + return ippStsNoErr; +} + + +/*F* +// Name: ippsAES_GCMProcessAAD +// +// Purpose: AAD processing. +// +// Returns: Reason: +// ippStsNullPtrErr pState == NULL +// pAAD == NULL, aadLen>0 +// ippStsContextMatchErr !AESGCM_VALID_ID() +// ippStsLengthErr aadLen <0 +// ippStsBadArgErr illegal sequence call +// ippStsNoErr no errors +// +// Parameters: +// pAAD pointer to the AAD +// aadlen length of AAD (it could be 0) +// pState pointer to the context +// +*F*/ +IPPFUN(IppStatus, ippsAES_GCMProcessAAD,(const Ipp8u* pAAD, int aadLen, IppsAES_GCMState* pState)) +{ + /* test pState pointer */ + IPP_BAD_PTR1_RET(pState); + /* use aligned context */ + pState = (IppsAES_GCMState*)( IPP_ALIGNED_PTR(pState, AESGCM_ALIGNMENT) ); + /* test if context is valid */ + IPP_BADARG_RET(!AESGCM_VALID_ID(pState), ippStsContextMatchErr); + + /* test AAD pointer and length */ + IPP_BADARG_RET(aadLen && !pAAD, ippStsNullPtrErr); + IPP_BADARG_RET(aadLen<0, ippStsLengthErr); + + IPP_BADARG_RET(!(GcmIVprocessing==AESGCM_STATE(pState) || GcmAADprocessing==AESGCM_STATE(pState)), ippStsBadArgErr); + + { + /* get method */ + MulGcm_ hashFunc = AESGCM_HASH(pState); + + if( GcmIVprocessing==AESGCM_STATE(pState) ) { + IPP_BADARG_RET(0==AESGCM_IV_LEN(pState), ippStsBadArgErr); + + /* complete IV processing */ + if(CTR_POS==AESGCM_IV_LEN(pState)) { + /* apply special format if IV length is 12 bytes */ + AESGCM_COUNTER(pState)[12] = 0; + AESGCM_COUNTER(pState)[13] = 0; + AESGCM_COUNTER(pState)[14] = 0; + AESGCM_COUNTER(pState)[15] = 1; + } + else { + /* process the rest of IV */ + if(AESGCM_BUFLEN(pState)) + hashFunc(AESGCM_COUNTER(pState), AESGCM_HKEY(pState), AesGcmConst_table); + + /* add IV bit length */ + { + Ipp64u ivBitLen = AESGCM_IV_LEN(pState)*BYTESIZE; + Ipp8u tmp[BLOCK_SIZE]; + PaddBlock(0, tmp, BLOCK_SIZE-8); + U32_TO_HSTRING(tmp+8, HIDWORD(ivBitLen)); + U32_TO_HSTRING(tmp+12, LODWORD(ivBitLen)); + XorBlock16(tmp, AESGCM_COUNTER(pState), AESGCM_COUNTER(pState)); + hashFunc(AESGCM_COUNTER(pState), AESGCM_HKEY(pState), AesGcmConst_table); + } + } + + /* prepare initial counter */ + { + IppsAESSpec* pAES = AESGCM_CIPHER(pState); + RijnCipher encoder = RIJ_ENCODER(pAES); + encoder(AESGCM_COUNTER(pState), AESGCM_ECOUNTER0(pState), RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox); + } + + /* switch mode and init counters */ + AESGCM_STATE(pState) = GcmAADprocessing; + AESGCM_AAD_LEN(pState) = CONST_64(0); + AESGCM_BUFLEN(pState) = 0; + } + + /* + // AAD processing + */ + + /* test if buffer is not empty */ + if(AESGCM_BUFLEN(pState)) { + int locLen = IPP_MIN(aadLen, BLOCK_SIZE-AESGCM_BUFLEN(pState)); + XorBlock(pAAD, AESGCM_GHASH(pState)+AESGCM_BUFLEN(pState), AESGCM_GHASH(pState)+AESGCM_BUFLEN(pState), locLen); + AESGCM_BUFLEN(pState) += locLen; + + /* if buffer full */ + if(BLOCK_SIZE==AESGCM_BUFLEN(pState)) { + hashFunc(AESGCM_GHASH(pState), AESGCM_HKEY(pState), AesGcmConst_table); + AESGCM_BUFLEN(pState) = 0; + } + + AESGCM_AAD_LEN(pState) += locLen; + pAAD += locLen; + aadLen -= locLen; + } + + /* process main part of AAD */ + { + int lenBlks = aadLen & (-BLOCK_SIZE); + if(lenBlks) { + Auth_ authFunc = AESGCM_AUTH(pState); + + authFunc(AESGCM_GHASH(pState), pAAD, lenBlks, AESGCM_HKEY(pState), AesGcmConst_table); + + AESGCM_AAD_LEN(pState) += lenBlks; + pAAD += lenBlks; + aadLen -= lenBlks; + } + } + + /* copy the rest of AAD into the buffer */ + if(aadLen) { + XorBlock(pAAD, AESGCM_GHASH(pState), AESGCM_GHASH(pState), aadLen); + AESGCM_AAD_LEN(pState) += aadLen; + AESGCM_BUFLEN(pState) = aadLen; + } + + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsAES_GCMStart +// +// Purpose: Start the process of encryption or decryption and authentication tag generation. +// +// Returns: Reason: +// ippStsNullPtrErr pState == NULL +// pIV == NULL, ivLen>0 +// pAAD == NULL, aadLen>0 +// ippStsContextMatchErr !AESGCM_VALID_ID() +// ippStsLengthErr ivLen < 0 +// aadLen < 0 +// ippStsNoErr no errors +// +// Parameters: +// pIV pointer to the IV (nonce) +// ivLen length of the IV in bytes +// pAAD pointer to the Addition Authenticated Data (header) +// aadLen length of the AAD in bytes +// pState pointer to the AES-GCM state +// +*F*/ +IPPFUN(IppStatus, ippsAES_GCMStart,(const Ipp8u* pIV, int ivLen, + const Ipp8u* pAAD, int aadLen, + IppsAES_GCMState* pState)) +{ + IppStatus sts = ippsAES_GCMReset(pState); + if(ippStsNoErr==sts) + sts = ippsAES_GCMProcessIV(pIV, ivLen, pState); + if(ippStsNoErr==sts) + sts = ippsAES_GCMProcessAAD(pAAD, aadLen, pState); + return sts; +} + + +/*F* +// Name: ippsAES_GCMEncrypt +// +// Purpose: Encrypts a data buffer in the GCM mode. +// +// Returns: Reason: +// ippStsNullPtrErr pSrc == NULL +// pDst == NULL +// pState == NULL +// ippStsContextMatchErr !AESGCM_VALID_ID() +// ippStsLengthErr txtLen<0 +// ippStsNoErr no errors +// +// Parameters: +// pSrc Pointer to plaintext. +// pDst Pointer to ciphertext. +// len Length of the plaintext and ciphertext in bytes +// pState pointer to the context +// +*F*/ +IPPFUN(IppStatus, ippsAES_GCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int txtLen, + IppsAES_GCMState* pState)) +{ + /* test pState pointer */ + IPP_BAD_PTR1_RET(pState); + /* use aligned context */ + pState = (IppsAES_GCMState*)( IPP_ALIGNED_PTR(pState, AESGCM_ALIGNMENT) ); + /* test state ID */ + IPP_BADARG_RET(!AESGCM_VALID_ID(pState), ippStsContextMatchErr); + /* test context validity */ + IPP_BADARG_RET(!(GcmAADprocessing==AESGCM_STATE(pState) || GcmTXTprocessing==AESGCM_STATE(pState)), ippStsBadArgErr); + + /* test text pointers and length */ + IPP_BAD_PTR2_RET(pSrc, pDst); + IPP_BADARG_RET(txtLen<0, ippStsLengthErr); + + + { + /* get method */ + IppsAESSpec* pAES = AESGCM_CIPHER(pState); + RijnCipher encoder = RIJ_ENCODER(pAES); + MulGcm_ hashFunc = AESGCM_HASH(pState); + + if( GcmAADprocessing==AESGCM_STATE(pState) ) { + /* complete AAD processing */ + if(AESGCM_BUFLEN(pState)) + hashFunc(AESGCM_GHASH(pState), AESGCM_HKEY(pState), AesGcmConst_table); + + /* increment counter block */ + IncrementCounter32(AESGCM_COUNTER(pState)); + /* and encrypt counter */ + encoder(AESGCM_COUNTER(pState), AESGCM_ECOUNTER(pState), RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox); + + /* switch mode and init counters */ + AESGCM_STATE(pState) = GcmTXTprocessing; + AESGCM_TXT_LEN(pState) = CONST_64(0); + AESGCM_BUFLEN(pState) = 0; + } + + /* + // process text (encrypt and authenticate) + */ + /* process partial block */ + if(AESGCM_BUFLEN(pState)) { + int locLen = IPP_MIN(txtLen, BLOCK_SIZE-AESGCM_BUFLEN(pState)); + /* ctr encryption */ + XorBlock(pSrc, AESGCM_ECOUNTER(pState)+AESGCM_BUFLEN(pState), pDst, locLen); + /* authentication */ + XorBlock(pDst, AESGCM_GHASH(pState)+AESGCM_BUFLEN(pState), AESGCM_GHASH(pState)+AESGCM_BUFLEN(pState), locLen); + + AESGCM_BUFLEN(pState) += locLen; + AESGCM_TXT_LEN(pState) += locLen; + pSrc += locLen; + pDst += locLen; + txtLen -= locLen; + + /* if buffer full */ + if(BLOCK_SIZE==AESGCM_BUFLEN(pState)) { + /* hash buffer */ + hashFunc(AESGCM_GHASH(pState), AESGCM_HKEY(pState), AesGcmConst_table); + AESGCM_BUFLEN(pState) = 0; + + /* increment counter block */ + IncrementCounter32(AESGCM_COUNTER(pState)); + /* and encrypt counter */ + encoder(AESGCM_COUNTER(pState), AESGCM_ECOUNTER(pState), RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox); + } + } + + /* process the main part of text */ + { + int lenBlks = txtLen & (-BLOCK_SIZE); + if(lenBlks) { + Encrypt_ encFunc = AESGCM_ENC(pState); + + encFunc(pDst, pSrc, lenBlks, pState); + + AESGCM_TXT_LEN(pState) += lenBlks; + pSrc += lenBlks; + pDst += lenBlks; + txtLen -= lenBlks; + } + } + + /* process the rest of text */ + if(txtLen) { + XorBlock(pSrc, AESGCM_ECOUNTER(pState)+AESGCM_BUFLEN(pState), pDst, txtLen); + XorBlock(pDst, AESGCM_GHASH(pState)+AESGCM_BUFLEN(pState), AESGCM_GHASH(pState)+AESGCM_BUFLEN(pState), txtLen); + + AESGCM_BUFLEN(pState) += txtLen; + AESGCM_TXT_LEN(pState) += txtLen; + } + + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsAES_GCMDecrypt +// +// Purpose: Decrypts a data buffer in the GCM mode. +// +// Returns: Reason: +// ippStsNullPtrErr pSrc == NULL +// pDst == NULL +// pState == NULL +// ippStsContextMatchErr !AESGCM_VALID_ID() +// ippStsLengthErr txtLen<0 +// ippStsNoErr no errors +// +// Parameters: +// pSrc Pointer to ciphertext. +// pDst Pointer to plaintext. +// len Length of the plaintext and ciphertext in bytes +// pState pointer to the context +// +*F*/ +IPPFUN(IppStatus, ippsAES_GCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int txtLen, IppsAES_GCMState* pState)) +{ + /* test pState pointer */ + IPP_BAD_PTR1_RET(pState); + /* use aligned context */ + pState = (IppsAES_GCMState*)( IPP_ALIGNED_PTR(pState, AESGCM_ALIGNMENT) ); + /* test state ID */ + IPP_BADARG_RET(!AESGCM_VALID_ID(pState), ippStsContextMatchErr); + /* test context validity */ + IPP_BADARG_RET(!(GcmAADprocessing==AESGCM_STATE(pState) || GcmTXTprocessing==AESGCM_STATE(pState)), ippStsBadArgErr); + + /* test text pointers and length */ + IPP_BAD_PTR2_RET(pSrc, pDst); + IPP_BADARG_RET(txtLen<0, ippStsLengthErr); + + + { + /* get method */ + IppsAESSpec* pAES = AESGCM_CIPHER(pState); + RijnCipher encoder = RIJ_ENCODER(pAES); + MulGcm_ hashFunc = AESGCM_HASH(pState); + + if( GcmAADprocessing==AESGCM_STATE(pState) ) { + /* complete AAD processing */ + if(AESGCM_BUFLEN(pState)) + hashFunc(AESGCM_GHASH(pState), AESGCM_HKEY(pState), AesGcmConst_table); + + /* increment counter block */ + IncrementCounter32(AESGCM_COUNTER(pState)); + /* and encrypt counter */ + encoder(AESGCM_COUNTER(pState), AESGCM_ECOUNTER(pState), RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox); + + /* switch mode and init counters */ + AESGCM_BUFLEN(pState) = 0; + AESGCM_TXT_LEN(pState) = CONST_64(0); + AESGCM_STATE(pState) = GcmTXTprocessing; + } + + /* + // process text (authenticate and decrypt ) + */ + /* process partial block */ + if(AESGCM_BUFLEN(pState)) { + int locLen = IPP_MIN(txtLen, BLOCK_SIZE-AESGCM_BUFLEN(pState)); + /* authentication */ + XorBlock(pSrc, AESGCM_GHASH(pState)+AESGCM_BUFLEN(pState), AESGCM_GHASH(pState)+AESGCM_BUFLEN(pState), locLen); + /* ctr decryption */ + XorBlock(pSrc, AESGCM_ECOUNTER(pState)+AESGCM_BUFLEN(pState), pDst, locLen); + + AESGCM_BUFLEN(pState) += locLen; + AESGCM_TXT_LEN(pState) += locLen; + pSrc += locLen; + pDst += locLen; + txtLen -= locLen; + + /* if buffer full */ + if(BLOCK_SIZE==AESGCM_BUFLEN(pState)) { + /* hash buffer */ + hashFunc(AESGCM_GHASH(pState), AESGCM_HKEY(pState), AesGcmConst_table); + AESGCM_BUFLEN(pState) = 0; + + /* increment counter block */ + IncrementCounter32(AESGCM_COUNTER(pState)); + /* and encrypt counter */ + encoder(AESGCM_COUNTER(pState), AESGCM_ECOUNTER(pState), RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox); + } + } + + /* process the main part of text */ + { + int lenBlks = txtLen & (-BLOCK_SIZE); + if(lenBlks) { + Decrypt_ decFunc = AESGCM_DEC(pState); + + decFunc(pDst, pSrc, lenBlks, pState); + + AESGCM_TXT_LEN(pState) += lenBlks; + pSrc += lenBlks; + pDst += lenBlks; + txtLen -= lenBlks; + } + } + + /* process the rest of text */ + if(txtLen) { + /* ctr encryption */ + XorBlock(pSrc, AESGCM_GHASH(pState)+AESGCM_BUFLEN(pState), AESGCM_GHASH(pState)+AESGCM_BUFLEN(pState), txtLen); + XorBlock(pSrc, AESGCM_ECOUNTER(pState)+AESGCM_BUFLEN(pState), pDst, txtLen); + + AESGCM_BUFLEN(pState) += txtLen; + AESGCM_TXT_LEN(pState) += txtLen; + } + + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsAES_GCMGetTag +// +// Purpose: Generates authentication tag in the GCM mode. +// +// Returns: Reason: +// ippStsNullPtrErr pDstTag == NULL +// pState == NULL +// ippStsLengthErr tagLen<=0 || tagLen>16 +// ippStsContextMatchErr !AESGCM_VALID_ID() +// ippStsNoErr no errors +// +// Parameters: +// pDstTag pointer to the authentication tag. +// tagLen length of the authentication tag *pDstTag in bytes +// pState pointer to the context +// +*F*/ +IPPFUN(IppStatus, ippsAES_GCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_GCMState* pState)) +{ + /* test State pointer */ + IPP_BAD_PTR1_RET(pState); + /* use aligned context */ + pState = (IppsAES_GCMState*)( IPP_ALIGNED_PTR(pState, AESGCM_ALIGNMENT) ); + /* test state ID */ + IPP_BADARG_RET(!AESGCM_VALID_ID(pState), ippStsContextMatchErr); + + /* test tag pointer and length */ + IPP_BAD_PTR1_RET(pTag); + IPP_BADARG_RET(tagLen<=0 || tagLen>BLOCK_SIZE, ippStsLengthErr); + + + { + /* get method */ + MulGcm_ hashFunc = AESGCM_HASH(pState); + + __ALIGN16 Ipp8u tmpHash[BLOCK_SIZE]; + Ipp8u tmpCntr[BLOCK_SIZE]; + + /* local copy of AAD and text counters (in bits) */ + Ipp64u aadBitLen = AESGCM_AAD_LEN(pState)*BYTESIZE; + Ipp64u txtBitLen = AESGCM_TXT_LEN(pState)*BYTESIZE; + + /* do local copy of ghash */ + CopyBlock16(AESGCM_GHASH(pState), tmpHash); + + /* complete text processing */ + if(AESGCM_BUFLEN(pState)) { + hashFunc(tmpHash, AESGCM_HKEY(pState), AesGcmConst_table); + } + + /* process lengths of AAD and text */ + U32_TO_HSTRING(tmpCntr, HIDWORD(aadBitLen)); + U32_TO_HSTRING(tmpCntr+4, LODWORD(aadBitLen)); + U32_TO_HSTRING(tmpCntr+8, HIDWORD(txtBitLen)); + U32_TO_HSTRING(tmpCntr+12,LODWORD(txtBitLen)); + + XorBlock16(tmpHash, tmpCntr, tmpHash); + hashFunc(tmpHash, AESGCM_HKEY(pState), AesGcmConst_table); + + /* add encrypted initial counter */ + XorBlock16(tmpHash, AESGCM_ECOUNTER0(pState), tmpHash); + + /* return tag of required lenth */ + CopyBlock(tmpHash, pTag, tagLen); + + return ippStsNoErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesgcmtableca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesgcmtableca.c new file mode 100644 index 0000000000..ca4f51afe1 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesgcmtableca.c @@ -0,0 +1,52 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" + +const Ipp16u AesGcmConst_table[256] = { +0x0000, 0xc201, 0x8403, 0x4602, 0x0807, 0xca06, 0x8c04, 0x4e05, 0x100e, 0xd20f, 0x940d, 0x560c, 0x1809, 0xda08, 0x9c0a, 0x5e0b, +0x201c, 0xe21d, 0xa41f, 0x661e, 0x281b, 0xea1a, 0xac18, 0x6e19, 0x3012, 0xf213, 0xb411, 0x7610, 0x3815, 0xfa14, 0xbc16, 0x7e17, +0x4038, 0x8239, 0xc43b, 0x063a, 0x483f, 0x8a3e, 0xcc3c, 0x0e3d, 0x5036, 0x9237, 0xd435, 0x1634, 0x5831, 0x9a30, 0xdc32, 0x1e33, +0x6024, 0xa225, 0xe427, 0x2626, 0x6823, 0xaa22, 0xec20, 0x2e21, 0x702a, 0xb22b, 0xf429, 0x3628, 0x782d, 0xba2c, 0xfc2e, 0x3e2f, +0x8070, 0x4271, 0x0473, 0xc672, 0x8877, 0x4a76, 0x0c74, 0xce75, 0x907e, 0x527f, 0x147d, 0xd67c, 0x9879, 0x5a78, 0x1c7a, 0xde7b, +0xa06c, 0x626d, 0x246f, 0xe66e, 0xa86b, 0x6a6a, 0x2c68, 0xee69, 0xb062, 0x7263, 0x3461, 0xf660, 0xb865, 0x7a64, 0x3c66, 0xfe67, +0xc048, 0x0249, 0x444b, 0x864a, 0xc84f, 0x0a4e, 0x4c4c, 0x8e4d, 0xd046, 0x1247, 0x5445, 0x9644, 0xd841, 0x1a40, 0x5c42, 0x9e43, +0xe054, 0x2255, 0x6457, 0xa656, 0xe853, 0x2a52, 0x6c50, 0xae51, 0xf05a, 0x325b, 0x7459, 0xb658, 0xf85d, 0x3a5c, 0x7c5e, 0xbe5f, +0x00e1, 0xc2e0, 0x84e2, 0x46e3, 0x08e6, 0xcae7, 0x8ce5, 0x4ee4, 0x10ef, 0xd2ee, 0x94ec, 0x56ed, 0x18e8, 0xdae9, 0x9ceb, 0x5eea, +0x20fd, 0xe2fc, 0xa4fe, 0x66ff, 0x28fa, 0xeafb, 0xacf9, 0x6ef8, 0x30f3, 0xf2f2, 0xb4f0, 0x76f1, 0x38f4, 0xfaf5, 0xbcf7, 0x7ef6, +0x40d9, 0x82d8, 0xc4da, 0x06db, 0x48de, 0x8adf, 0xccdd, 0x0edc, 0x50d7, 0x92d6, 0xd4d4, 0x16d5, 0x58d0, 0x9ad1, 0xdcd3, 0x1ed2, +0x60c5, 0xa2c4, 0xe4c6, 0x26c7, 0x68c2, 0xaac3, 0xecc1, 0x2ec0, 0x70cb, 0xb2ca, 0xf4c8, 0x36c9, 0x78cc, 0xbacd, 0xfccf, 0x3ece, +0x8091, 0x4290, 0x0492, 0xc693, 0x8896, 0x4a97, 0x0c95, 0xce94, 0x909f, 0x529e, 0x149c, 0xd69d, 0x9898, 0x5a99, 0x1c9b, 0xde9a, +0xa08d, 0x628c, 0x248e, 0xe68f, 0xa88a, 0x6a8b, 0x2c89, 0xee88, 0xb083, 0x7282, 0x3480, 0xf681, 0xb884, 0x7a85, 0x3c87, 0xfe86, +0xc0a9, 0x02a8, 0x44aa, 0x86ab, 0xc8ae, 0x0aaf, 0x4cad, 0x8eac, 0xd0a7, 0x12a6, 0x54a4, 0x96a5, 0xd8a0, 0x1aa1, 0x5ca3, 0x9ea2, +0xe0b5, 0x22b4, 0x64b6, 0xa6b7, 0xe8b2, 0x2ab3, 0x6cb1, 0xaeb0, 0xf0bb, 0x32ba, 0x74b8, 0xb6b9, 0xf8bc, 0x3abd, 0x7cbf, 0xbebe +}; diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesgcmtbl2kca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesgcmtbl2kca.c new file mode 100644 index 0000000000..edbdfd291a --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesgcmtbl2kca.c @@ -0,0 +1,229 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" + +#include "pcpaesauthgcm.h" +#include "pcptool.h" + +#include "pcprijtables.h" + + +/* +// AES-GCM precomputations. +*/ +static void RightShiftBlock16(Ipp8u* pBlock) +{ + Ipp8u v0 = 0; + int i; + for(i=0; i<16; i++) { + Ipp8u v1 = pBlock[i]; + Ipp8u tmp = (Ipp8u)( (v1>>1) | (v0<<7) ); + pBlock[i] = tmp; + v0 = v1; + } +} +void AesGcmPrecompute_table2K(Ipp8u* pPrecomputeData, const Ipp8u* pHKey) +{ + Ipp8u t[BLOCK_SIZE]; + int n; + + CopyBlock16(pHKey, t); + + for(n=0; n<128-24; n++) { + /* get msb */ + int hBit = t[15]&1; + + int k = n%32; + if(k<4) { + CopyBlock16(t, pPrecomputeData +1024 +(n/32)*256 +(Ipp32u)(1<<(7-k))); + } + else if(k<8) { + CopyBlock16(t, pPrecomputeData +(n/32)*256 +(Ipp32u)(1<<(11-k))); + } + + /* shift */ + RightShiftBlock16(t); + /* xor if msb=1 */ + if(hBit) + t[0] ^= 0xe1; + } + + for(n=0; n<4; n++) { + int m, k; + XorBlock16(pPrecomputeData +n*256, pPrecomputeData +n*256, pPrecomputeData +n*256); + XorBlock16(pPrecomputeData +1024 +n*256, pPrecomputeData +1024 +n*256, pPrecomputeData +1024 +n*256); + for(m=2; m<=8; m*=2) + for(k=1; k=BLOCK_SIZE) { + /* add src */ + XorBlock16(pSrc, pHash, pHash); + /* hash it */ + AesGcmMulGcm_table2K(pHash, pHKey, AesGcmConst_table); + + pSrc += BLOCK_SIZE; + len -= BLOCK_SIZE; + } +} + + +/* +// encrypts and authenticates n*BLOCK_SIZE bytes +*/ +void wrpAesGcmEnc_table2K(Ipp8u* pDst, const Ipp8u* pSrc, int len, IppsAES_GCMState* pState) +{ + Ipp8u* pHashedData = pDst; + int hashedDataLen = len; + + Ipp8u* pCounter = AESGCM_COUNTER(pState); + Ipp8u* pECounter = AESGCM_ECOUNTER(pState); + + IppsAESSpec* pAES = AESGCM_CIPHER(pState); + RijnCipher encoder = RIJ_ENCODER(pAES); + + while(len>=BLOCK_SIZE) { + /* encrypt whole AES block */ + XorBlock16(pSrc, pECounter, pDst); + + pSrc += BLOCK_SIZE; + pDst += BLOCK_SIZE; + len -= BLOCK_SIZE; + + /* increment counter block */ + IncrementCounter32(pCounter); + /* and encrypt counter */ + encoder(pCounter, pECounter, RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox); + } + + AesGcmAuth_table2K(AESGCM_GHASH(pState), pHashedData, hashedDataLen, AESGCM_HKEY(pState), AesGcmConst_table); +} + + +/* +// authenticates and decrypts n*BLOCK_SIZE bytes +*/ +void wrpAesGcmDec_table2K(Ipp8u* pDst, const Ipp8u* pSrc, int len, IppsAES_GCMState* pState) +{ + AesGcmAuth_table2K(AESGCM_GHASH(pState), pSrc, len, AESGCM_HKEY(pState), AesGcmConst_table); + + { + Ipp8u* pCounter = AESGCM_COUNTER(pState); + Ipp8u* pECounter = AESGCM_ECOUNTER(pState); + + IppsAESSpec* pAES = AESGCM_CIPHER(pState); + RijnCipher encoder = RIJ_ENCODER(pAES); + + while(len>=BLOCK_SIZE) { + /* encrypt whole AES block */ + XorBlock16(pSrc, pECounter, pDst); + + pSrc += BLOCK_SIZE; + pDst += BLOCK_SIZE; + len -= BLOCK_SIZE; + + /* increment counter block */ + IncrementCounter32(pCounter); + /* and encrypt counter */ + encoder(pCounter, pECounter, RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox); + } + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesm.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesm.h new file mode 100644 index 0000000000..924fcf238e --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesm.h @@ -0,0 +1,50 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_PCP_AES_H) +#define _PCP_AES_H + +#include "pcprij.h" + +/* alignment of AES context */ +#define AES_ALIGNMENT (RIJ_ALIGNMENT) + +/* valid AES context ID */ +#define VALID_AES_ID(ctx) (RIJ_ID((ctx))==idCtxRijndael) + +/* size of AES context */ +__INLINE int cpSizeofCtx_AES(void) +{ + return sizeof(IppsAESSpec) + +(AES_ALIGNMENT-1); +} + +#endif /* _PCP_AES_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesmctrca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesmctrca.c new file mode 100644 index 0000000000..6aac2fc218 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesmctrca.c @@ -0,0 +1,150 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" + +#include "owncp.h" +#include "pcpaesm.h" +#include "pcptool.h" + +#include "pcprijtables.h" + +/* +// AES-CRT processing. +// +// Returns: Reason: +// ippStsNullPtrErr pCtx == NULL +// pSrc == NULL +// pDst == NULL +// pCtrValue ==NULL +// ippStsContextMatchErr !VALID_AES_ID() +// ippStsLengthErr len <1 +// ippStsCTRSizeErr 128 < ctrNumBitSize < 1 +// ippStsNoErr no errors +// +// Parameters: +// pSrc pointer to the source data buffer +// pDst pointer to the target data buffer +// dataLen input/output buffer length (in bytes) +// pCtx pointer to rge AES context +// pCtrValue pointer to the counter block +// ctrNumBitSize counter block size (bits) +// +// Note: +// counter will updated on return +// +*/ +static +IppStatus cpProcessAES_ctr(const Ipp8u* pSrc, Ipp8u* pDst, int dataLen, + const IppsAESSpec* pCtx, + Ipp8u* pCtrValue, int ctrNumBitSize) +{ + /* test context */ + IPP_BAD_PTR1_RET(pCtx); + /* use aligned AES context */ + pCtx = (IppsAESSpec*)( IPP_ALIGNED_PTR(pCtx, AES_ALIGNMENT) ); + /* test the context ID */ + IPP_BADARG_RET(!VALID_AES_ID(pCtx), ippStsContextMatchErr); + + /* test source, target and counter block pointers */ + IPP_BAD_PTR3_RET(pSrc, pDst, pCtrValue); + /* test stream length */ + IPP_BADARG_RET((dataLen<1), ippStsLengthErr); + + /* test counter block size */ + IPP_BADARG_RET(((MBS_RIJ128*8)= MBS_RIJ128) { + /* encrypt counter block */ + encoder((Ipp8u*)counter, (Ipp8u*)output, RIJ_NR(pCtx), RIJ_EKEYS(pCtx), RijEncSbox); + + /* compute ciphertext block */ + if( !(IPP_UINT_PTR(pSrc) & 0x3) && !(IPP_UINT_PTR(pDst) & 0x3)) { + ((Ipp32u*)pDst)[0] = output[0]^((Ipp32u*)pSrc)[0]; + ((Ipp32u*)pDst)[1] = output[1]^((Ipp32u*)pSrc)[1]; + ((Ipp32u*)pDst)[2] = output[2]^((Ipp32u*)pSrc)[2]; + ((Ipp32u*)pDst)[3] = output[3]^((Ipp32u*)pSrc)[3]; + } + else + XorBlock16(pSrc, output, pDst); + /* encrement counter block */ + StdIncrement((Ipp8u*)counter,MBS_RIJ128*8, ctrNumBitSize); + + pSrc += MBS_RIJ128; + pDst += MBS_RIJ128; + dataLen -= MBS_RIJ128; + } + /* + // encrypt last data block + */ + if(dataLen) { + /* encrypt counter block */ + encoder((Ipp8u*)counter, (Ipp8u*)output, RIJ_NR(pCtx), RIJ_EKEYS(pCtx), RijEncSbox); + + /* compute ciphertext block */ + XorBlock(pSrc, output, pDst,dataLen); + /* encrement counter block */ + StdIncrement((Ipp8u*)counter,MBS_RIJ128*8, ctrNumBitSize); + } + + /* update counter */ + CopyBlock16(counter, pCtrValue); + + return ippStsNoErr; + } +} + +IPPFUN(IppStatus, ippsAESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int dataLen, + const IppsAESSpec* pCtx, + Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + return cpProcessAES_ctr(pSrc, pDst, dataLen, pCtx, pCtrValue, ctrNumBitSize); +} + +IPPFUN(IppStatus, ippsAESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int dataLen, + const IppsAESSpec* pCtx, + Ipp8u* pCtrValue, int ctrNumBitSize)) +{ + return cpProcessAES_ctr(pSrc, pDst, dataLen, pCtx, pCtrValue, ctrNumBitSize); +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesminitca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesminitca.c new file mode 100644 index 0000000000..262fa85e90 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpaesminitca.c @@ -0,0 +1,173 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpaesm.h" +#include "pcptool.h" + +#include "pcprijtables.h" + +/*F* +// Name: ippsAESGetSize +// +// Purpose: Returns size of AES context (in bytes). +// +// Returns: Reason: +// ippStsNullPtrErr pSzie == NULL +// ippStsNoErr no errors +// +// Parameters: +// pSize pointer to AES size of context(in bytes) +// +*F*/ +IPPFUN(IppStatus, ippsAESGetSize,(int* pSize)) +{ + /* test size's pointer */ + IPP_BAD_PTR1_RET(pSize); + + *pSize = cpSizeofCtx_AES(); + + return ippStsNoErr; +} + +/* number of rounds (use [NK] for access) */ +static int rij128nRounds[3] = {NR128_128, NR128_192, NR128_256}; + +/* +// number of keys (estimation only!) (use [NK] for access) +// +// accurate number of keys necassary for encrypt/decrypt are: +// nKeys = NB * (NR+1) +// where NB - data block size (32-bit words) +// NR - number of rounds (depend on NB and keyLen) +// +// but the estimation +// estnKeys = (NK*n) >= nKeys +// or +// estnKeys = ( (NB*(NR+1) + (NK-1)) / NK) * NK +// where NK - key length (words) +// NB - data block size (word) +// NR - number of rounds (depend on NB and keyLen) +// nKeys - accurate numner of keys +// is more convinient when calculates key extension +*/ +static int rij128nKeys[3] = {44, 54, 64 }; + +/* +// helper for nRounds[] and estnKeys[] access +// note: x is length in 32-bits words +*/ +__INLINE int rij_index(int x) +{ return (x-NB(128))>>1; } + +/*F* +// Name: ippsAESInit +// +// Purpose: Init AES context for future usage +// and setup secret key. +// +// Returns: Reason: +// ippStsNullPtrErr pCtx == NULL +// ippStsMemAllocErr size of buffer is not match fro operation +// ippStsLengthErr keyLen != 16 +// keyLen != 24 +// keyLen != 32 +// +// Parameters: +// pKey secret key +// keyLen length of the secret key (in bytes) +// pCtx pointer to buffer initialized as AES context +// ctxSize available size (in bytes) of buffer above +// +// Note: +// if pKey==NULL, then AES initialized by zero value key +// +*F*/ +IPPFUN(IppStatus, ippsAESInit,(const Ipp8u* pKey, int keyLen, + IppsAESSpec* pCtxRaw, int rawCtxSize)) +{ + /* test context pointer */ + IPP_BAD_PTR1_RET(pCtxRaw); + + /* make sure in legal keyLen */ + IPP_BADARG_RET(keyLen!=16 && keyLen!=24 && keyLen!=32, ippStsLengthErr); + + { + /* use aligned Rijndael context */ + IppsAESSpec* pCtx = (IppsAESSpec*)( IPP_ALIGNED_PTR(pCtxRaw, AES_ALIGNMENT) ); + + /* test available size of context buffer */ + if(((Ipp8u*)pCtx+sizeof(IppsAESSpec)) > ((Ipp8u*)pCtxRaw+rawCtxSize)) + IPP_ERROR_RET(ippStsMemAllocErr); + + else { + int keyWords = NK(keyLen*BITSIZE(Ipp8u)); + int nExpKeys = rij128nKeys [ rij_index(keyWords) ]; + int nRounds = rij128nRounds[ rij_index(keyWords) ]; + + Ipp8u zeroKey[32] = {0}; + const Ipp8u* pActualKey = pKey? pKey : zeroKey; + + /* clear context */ + PaddBlock(0, pCtx, sizeof(IppsAESSpec)); + + /* init spec */ + RIJ_ID(pCtx) = idCtxRijndael; + RIJ_NB(pCtx) = NB(128); + RIJ_NK(pCtx) = keyWords; + RIJ_NR(pCtx) = nRounds; + RIJ_SAFE_INIT(pCtx) = 1; + + /* set key expansion */ + ExpandRijndaelKey(pActualKey, keyWords, NB(128), nRounds, nExpKeys, + RIJ_EKEYS(pCtx), + RIJ_DKEYS(pCtx)); + { + int nr; + Ipp8u* pEnc_key = (Ipp8u*)(RIJ_EKEYS(pCtx)); + /* update key material: transpose inplace */ + for(nr=0; nr<(1+nRounds); nr++, pEnc_key+=16) { + SWAP(pEnc_key[ 1], pEnc_key[ 4]); + SWAP(pEnc_key[ 2], pEnc_key[ 8]); + SWAP(pEnc_key[ 3], pEnc_key[12]); + SWAP(pEnc_key[ 6], pEnc_key[ 9]); + SWAP(pEnc_key[ 7], pEnc_key[13]); + SWAP(pEnc_key[11], pEnc_key[14]); + } + } + RIJ_ENCODER(pCtx) = Safe2Encrypt_RIJ128; /* safe encoder (compact Sbox)) */ + RIJ_DECODER(pCtx) = Safe2Decrypt_RIJ128; /* safe decoder (compact Sbox)) */ + + return ippStsNoErr; + } + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbn.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbn.h new file mode 100644 index 0000000000..180f59c5fd --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbn.h @@ -0,0 +1,210 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_CP_BN_H) +#define _CP_BN_H + +#include "pcpbnuimpl.h" +#include "pcpbnuarith.h" +#include "pcpbnumisc.h" +#include "pcpbnu32arith.h" +#include "pcpbnu32misc.h" + +/* +// Big Number context +*/ +struct _cpBigNum +{ + IppCtxId idCtx; /* BigNum ctx id */ + IppsBigNumSGN sgn; /* sign */ + cpSize size; /* BigNum size (BNU_CHUNK_T) */ + cpSize room; /* BigNum max size (BNU_CHUNK_T) */ + BNU_CHUNK_T* number; /* BigNum value */ + BNU_CHUNK_T* buffer; /* temporary buffer */ +}; + +/* BN accessory macros */ +#define BN_ID(pBN) ((pBN)->idCtx) +#define BN_SIGN(pBN) ((pBN)->sgn) +#define BN_POSITIVE(pBN) (BN_SIGN(pBN)==ippBigNumPOS) +#define BN_NEGATIVE(pBN) (BN_SIGN(pBN)==ippBigNumNEG) +#define BN_NUMBER(pBN) ((pBN)->number) +#define BN_BUFFER(pBN) ((pBN)->buffer) +#define BN_ROOM(pBN) ((pBN)->room) +#define BN_SIZE(pBN) ((pBN)->size) +#define BN_SIZE32(pBN) ((pBN)->size*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u))) +//#define BN_SIZE32(pBN) (BITS2WORD32_SIZE( BITSIZE_BNU(BN_NUMBER((pBN)),BN_SIZE((pBN))))) + +#define BN_VALID_ID(pBN) (BN_ID((pBN))==idCtxBigNum) + +#define INVERSE_SIGN(s) (((s)==ippBigNumPOS)? ippBigNumNEG : ippBigNumPOS) + +#define BN_ALIGNMENT ((int)sizeof(void*)) + + +/* pack-unpack context */ +void cpPackBigNumCtx(const IppsBigNumState* pBN, Ipp8u* pBuffer); +void cpUnpackBigNumCtx(const Ipp8u* pBuffer, IppsBigNumState* pBN); + +/* copy BN */ +__INLINE IppsBigNumState* cpBN_copy(IppsBigNumState* pDst, const IppsBigNumState* pSrc) +{ + BN_SIGN(pDst) = BN_SIGN(pSrc); + BN_SIZE(pDst) = BN_SIZE(pSrc); + ZEXPAND_COPY_BNU(BN_NUMBER(pDst), BN_ROOM(pDst), BN_NUMBER(pSrc), BN_SIZE(pSrc)); + return pDst; +} +/* set BN to zero */ +__INLINE IppsBigNumState* cpBN_zero(IppsBigNumState* pBN) +{ + BN_SIGN(pBN) = ippBigNumPOS; + BN_SIZE(pBN) = 1; + ZEXPAND_BNU(BN_NUMBER(pBN),0, (int)BN_ROOM(pBN)); + return pBN; +} +/* fixup BN */ +__INLINE IppsBigNumState* cpBN_fix(IppsBigNumState* pBN) +{ + cpSize len = BN_SIZE(pBN); + FIX_BNU(BN_NUMBER(pBN), len); + BN_SIZE(pBN) = len; + return pBN; +} +/* set BN to chunk */ +__INLINE IppsBigNumState* cpBN_chunk(IppsBigNumState* pBN, BNU_CHUNK_T a) +{ + BN_SIGN(pBN) = ippBigNumPOS; + BN_SIZE(pBN) = 1; + ZEXPAND_BNU(BN_NUMBER(pBN),0, (int)BN_ROOM(pBN)); + BN_NUMBER(pBN)[0] = a; + return pBN; +} +/* set BN to 2^m */ +__INLINE IppsBigNumState* cpBN_power2(IppsBigNumState* pBN, int power) +{ + cpSize size = BITS_BNU_CHUNK(power+1); + if(BN_ROOM(pBN) >= size) { + BN_SIGN(pBN) = ippBigNumPOS; + BN_SIZE(pBN) = size; + ZEXPAND_BNU(BN_NUMBER(pBN),0, BN_ROOM(pBN)); + SET_BIT(BN_NUMBER(pBN), power); + return pBN; + } + else return NULL; +} + +/* bitsize of BN */ +__INLINE int cpBN_bitsize(const IppsBigNumState* pA) +{ + int bitsize = BITSIZE_BNU(BN_NUMBER(pA), BN_SIZE(pA)); + return bitsize; +} + +/* returns -1/0/+1 depemding on A~B comparison */ +__INLINE int cpBN_cmp(const IppsBigNumState* pA, const IppsBigNumState* pB) +{ + IppsBigNumSGN signA = BN_SIGN(pA); + IppsBigNumSGN signB = BN_SIGN(pB); + + if(signA==signB) { + int result = cpCmp_BNU(BN_NUMBER(pA), BN_SIZE(pA), BN_NUMBER(pB), BN_SIZE(pB)); + return (ippBigNumPOS==signA)? result : -result; + } + return (ippBigNumPOS==signA)? 1 : -1; +} + +/* returns -1/0/+1 depemding on A comparison 00 */ +__INLINE int cpBN_tst(const IppsBigNumState* pA) +{ + if(1==BN_SIZE(pA) && 0==BN_NUMBER(pA)[0]) + return 0; + else + return BN_POSITIVE(pA)? 1 : -1; +} + + +// some addtition functions +__INLINE int IsZero_BN(const IppsBigNumState* pA) +{ + return ( BN_SIZE(pA)==1 ) && ( BN_NUMBER(pA)[0]==0 ); +} +__INLINE int IsOdd_BN(const IppsBigNumState* pA) +{ + return BN_NUMBER(pA)[0] & 1; +} + +__INLINE IppsBigNumState* BN_Word(IppsBigNumState* pBN, BNU_CHUNK_T w) +{ + BN_SIGN(pBN) = ippBigNumPOS; + BN_SIZE(pBN) = 1; + ZEXPAND_BNU(BN_NUMBER(pBN),0, BN_ROOM(pBN)); + BN_NUMBER(pBN)[0] = w; + return pBN; +} +__INLINE IppsBigNumState* BN_Set(const BNU_CHUNK_T* pData, cpSize len, IppsBigNumState* pBN) +{ + BN_SIGN(pBN) = ippBigNumPOS; + BN_SIZE(pBN) = len; + ZEXPAND_COPY_BNU(BN_NUMBER(pBN), BN_ROOM(pBN), pData, len); + return pBN; +} +__INLINE IppsBigNumState* BN_Make(BNU_CHUNK_T* pData, BNU_CHUNK_T* pBuffer, cpSize len, IppsBigNumState* pBN) +{ + BN_ID(pBN) = idCtxBigNum; + BN_SIGN(pBN) = ippBigNumPOS; + BN_SIZE(pBN) = 1; + BN_ROOM(pBN) = len; + BN_NUMBER(pBN) = pData; + BN_BUFFER(pBN) = pBuffer; + return pBN; +} + + + +/* +// fixed single chunk BN +*/ +typedef struct _ippcpBigNumChunk { + IppsBigNumState bn; + BNU_CHUNK_T value; + BNU_CHUNK_T temporary; +} IppsBigNumStateChunk; + +/* reference to BN(1) and BN(2) */ +IppsBigNumState* cpBN_OneRef(void); +IppsBigNumState* cpBN_TwoRef(void); +IppsBigNumState* cpBN_ThreeRef(void); + +#define BN_ONE_REF() cpBN_OneRef() +#define BN_TWO_REF() cpBN_TwoRef() +#define BN_THREE_REF() cpBN_ThreeRef() + +#endif /* _CP_BN_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnca.c new file mode 100644 index 0000000000..5e1e2a3d38 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnca.c @@ -0,0 +1,1058 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpbn.h" +#include "pcptool.h" + +/* BN(1) and reference */ +static IppsBigNumStateChunk cpChunk_BN1 = { + { + idCtxBigNum, + ippBigNumPOS, + 1,1, + &cpChunk_BN1.value,&cpChunk_BN1.temporary + }, + 1,0 +}; +IppsBigNumState* cpBN_OneRef(void) +{ return &cpChunk_BN1.bn; }; + +/* BN(2) and reference */ +static IppsBigNumStateChunk cpChunk_BN2 = { + { + idCtxBigNum, + ippBigNumPOS, + 1,1, + &cpChunk_BN2.value,&cpChunk_BN2.temporary + }, + 2,0 +}; +IppsBigNumState* cpBN_TwoRef(void) +{ return &cpChunk_BN2.bn; }; + +/* BN(3) and reference */ +static IppsBigNumStateChunk cpChunk_BN3 = { + { + idCtxBigNum, + ippBigNumPOS, + 1,1, + &cpChunk_BN3.value,&cpChunk_BN3.temporary + }, + 3,0 +}; +IppsBigNumState* cpBN_ThreeRef(void) +{ return &cpChunk_BN3.bn; }; + + + +/*F* +// Name: ippsBigNumGetSize +// +// Purpose: Returns size of BigNum ctx (bytes). +// +// Returns: Reason: +// ippStsNullPtrErr pCtxSize == NULL +// ippStsLengthErr len32 < 1 +// len32 > BITS2WORD32_SIZE(BN_MAXBITSIZE) +// ippStsNoErr no errors +// +// Parameters: +// pCtxSize pointer BigNum ctx size +// +*F*/ +IPPFUN(IppStatus, ippsBigNumGetSize, (cpSize len32, cpSize *pCtxSize)) +{ + IPP_BAD_PTR1_RET(pCtxSize); + IPP_BADARG_RET(len32<1 || len32>BITS2WORD32_SIZE(BN_MAXBITSIZE), ippStsLengthErr); + + { + /* convert length to the number of BNU_CHUNK_T */ + cpSize len = INTERNAL_BNU_LENGTH(len32); + + /* reserve one BNU_CHUNK_T more for cpDiv_BNU, + mul, mont exp operations */ + len++; + + *pCtxSize = sizeof(IppsBigNumState) + + len*sizeof(BNU_CHUNK_T) + + len*sizeof(BNU_CHUNK_T) + + BN_ALIGNMENT-1; + + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsBigNumInit +// +// Purpose: Init BigNum spec for future usage. +// +// Returns: Reason: +// ippStsNullPtrErr pBN == NULL +// ippStsLengthErr len32<1 +// len32 > BITS2WORD32_SIZE(BN_MAXBITSIZE) +// ippStsNoErr no errors +// +// Parameters: +// len32 max BN length (32-bits segments) +// pBN BigNum ctx +// +*F*/ +IPPFUN(IppStatus, ippsBigNumInit, (cpSize len32, IppsBigNumState* pBN)) +{ + IPP_BADARG_RET(len32<1 || len32>BITS2WORD32_SIZE(BN_MAXBITSIZE), ippStsLengthErr); + IPP_BAD_PTR1_RET(pBN); + pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) ); + + { + Ipp8u* ptr = (Ipp8u*)pBN; + + /* convert length to the number of BNU_CHUNK_T */ + cpSize len = INTERNAL_BNU_LENGTH(len32); + + BN_ID(pBN) = idCtxUnknown; + BN_SIGN(pBN) = ippBigNumPOS; + BN_SIZE(pBN) = 1; /* initial valie is zero */ + BN_ROOM(pBN) = len; /* close to what has been passed by user */ + + /* reserve one BNU_CHUNK_T more for cpDiv_BNU, + mul, mont exp operations */ + len++; + + /* allocate buffers */ + BN_NUMBER(pBN) = (BNU_CHUNK_T*)(ptr += sizeof(IppsBigNumState)); + BN_BUFFER(pBN) = (BNU_CHUNK_T*)(ptr += len*sizeof(BNU_CHUNK_T)); /* use expanded length here */ + + /* set BN value and buffer to zero */ + ZEXPAND_BNU(BN_NUMBER(pBN), 0, len); + ZEXPAND_BNU(BN_BUFFER(pBN), 0, len); + + BN_ID(pBN) = idCtxBigNum; + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsCmpZero_BN +// +// Purpose: Test BigNum value. +// +// Returns: Reason: +// ippStsNullPtrErr pBN == NULL +// pResult == NULL +// ippStsContextMatchErr BN_VALID_ID() +// ippStsNoErr no errors +// +// Parameters: +// pBN BigNum ctx +// pResult result of comparison +// +*F*/ +IPPFUN(IppStatus, ippsCmpZero_BN, (const IppsBigNumState* pBN, Ipp32u* pResult)) +{ + IPP_BAD_PTR2_RET(pBN, pResult); + + pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pBN), ippStsContextMatchErr); + + if(BN_SIZE(pBN)==1 && BN_NUMBER(pBN)[0]==0) + *pResult = IS_ZERO; + else if (BN_SIGN(pBN)==ippBigNumPOS) + *pResult = GREATER_THAN_ZERO; + else if (BN_SIGN(pBN)==ippBigNumNEG) + *pResult = LESS_THAN_ZERO; + + return ippStsNoErr; +} + + +/*F* +// Name: ippsCmp_BN +// +// Purpose: Compare two BigNums. +// +// Returns: Reason: +// ippStsNullPtrErr pA == NULL +// pB == NULL +// pResult == NULL +// ippStsContextMatchErr BN_VALID_ID(pA) +// BN_VALID_ID(pB) +// ippStsNoErr no errors +// +// Parameters: +// pA BigNum ctx +// pB BigNum ctx +// pResult result of comparison +// +*F*/ +IPPFUN(IppStatus, ippsCmp_BN,(const IppsBigNumState* pA, const IppsBigNumState* pB, Ipp32u *pResult)) +{ + IPP_BAD_PTR3_RET(pA, pB, pResult); + + pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); + pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); + + { + int res; + if(BN_SIGN(pA)==BN_SIGN(pB)) { + res = cpCmp_BNU(BN_NUMBER(pA), BN_SIZE(pA), BN_NUMBER(pB), BN_SIZE(pB)); + if(ippBigNumNEG==BN_SIGN(pA)) + res = -res; + } + else + res = (ippBigNumPOS==BN_SIGN(pA))? 1 :-1; + + *pResult = (1==res)? IPP_IS_GT : (-1==res)? IPP_IS_LT : IPP_IS_EQ; + + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsSet_BN +// +// Purpose: Set BigNum. +// +// Returns: Reason: +// ippStsNullPtrErr pBN == NULL +// pData == NULL +// ippStsContextMatchErr BN_VALID_ID(pBN) +// ippStsLengthErr len32 < 1 +// ippStsOutOfRangeErr len32 > BN_ROOM() +// ippStsNoErr no errors +// +// Parameters: +// sgn sign +// len32 data size (in Ipp32u chunks) +// pData source data pointer +// pBn BigNum ctx +// +*F*/ +IPPFUN(IppStatus, ippsSet_BN, (IppsBigNumSGN sgn, cpSize len32, const Ipp32u* pData, + IppsBigNumState* pBN)) +{ + IPP_BAD_PTR2_RET(pData, pBN); + + pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pBN), ippStsContextMatchErr); + + IPP_BADARG_RET(len32<1, ippStsLengthErr); + + /* compute real size */ + FIX_BNU(pData, len32); + + { + cpSize len = INTERNAL_BNU_LENGTH(len32); + IPP_BADARG_RET(len > BN_ROOM(pBN), ippStsOutOfRangeErr); + + ZEXPAND_COPY_BNU((Ipp32u*)BN_NUMBER(pBN), BN_ROOM(pBN)*(int)(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)), pData, len32); + + BN_SIZE(pBN) = len; + + if(len32==1 && pData[0] == 0) + sgn = ippBigNumPOS; /* consider zero value as positive */ + BN_SIGN(pBN) = sgn; + + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsRef_BN +// +// Purpose: Get BigNum info. +// +// Returns: Reason: +// ippStsNullPtrErr pBN == NULL +// ippStsContextMatchErr BN_VALID_ID(pBN) +// ippStsNoErr no errors +// +// Parameters: +// pSgn pointer to the sign +// pBitSize pointer to the data size (in bits) +// ppData pointer to the data buffer +// pBN BigNum ctx +// +*F*/ +IPPFUN(IppStatus, ippsRef_BN, (IppsBigNumSGN* pSgn, cpSize* pBitSize, Ipp32u** const ppData, + const IppsBigNumState *pBN)) +{ + IPP_BAD_PTR1_RET(pBN); + + pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pBN), ippStsContextMatchErr); + + if(pSgn) + *pSgn = BN_SIGN(pBN); + if(pBitSize) { + cpSize bitLen = BITSIZE_BNU(BN_NUMBER(pBN), BN_SIZE(pBN)); + *pBitSize = bitLen? bitLen : 1; + } + + if(ppData) + *ppData = (Ipp32u*)BN_NUMBER(pBN); + + return ippStsNoErr; +} + + +/*F* +// Name: ippsAdd_BN +// +// Purpose: Add BigNum. +// +// Returns: Reason: +// ippStsNullPtrErr pA == NULL +// pB == NULL +// pR == NULL +// ippStsContextMatchErr BN_VALID_ID(pA) +// BN_VALID_ID(pB) +// BN_VALID_ID(pR) +// ippStsOutOfRangeErr pR can not hold result +// ippStsNoErr no errors +// +// Parameters: +// pA source BigNum +// pB source BigNum +// pR resultant BigNum +// +*F*/ +IPPFUN(IppStatus, ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +{ + IPP_BAD_PTR3_RET(pA, pB, pR); + + pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); + pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); + pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); + + { + cpSize nsA = BN_SIZE(pA); + cpSize nsB = BN_SIZE(pB); + cpSize nsR = BN_ROOM(pR); + IPP_BADARG_RET(nsR < IPP_MAX(nsA, nsB), ippStsOutOfRangeErr); + + { + BNU_CHUNK_T* pDataR = BN_NUMBER(pR); + + IppsBigNumSGN sgnA = BN_SIGN(pA); + IppsBigNumSGN sgnB = BN_SIGN(pB); + BNU_CHUNK_T* pDataA = BN_NUMBER(pA); + BNU_CHUNK_T* pDataB = BN_NUMBER(pB); + + BNU_CHUNK_T carry; + + if(sgnA==sgnB) { + if(nsA < nsB) { + SWAP(nsA, nsB); + SWAP_PTR(BNU_CHUNK_T, pDataA, pDataB); + } + + carry = cpAdd_BNU(pDataR, pDataA, pDataB, nsB); + if(nsA>nsB) + carry = cpInc_BNU(pDataR+nsB, pDataA+nsB, nsA-nsB, carry); + if(carry) { + if(nsR>nsA) + pDataR[nsA++] = carry; + else + IPP_ERROR_RET(ippStsOutOfRangeErr); + } + BN_SIGN(pR) = sgnA; + } + + else { + int cmpRes = cpCmp_BNU(pDataA, nsA, pDataB, nsB); + + if(0==cmpRes) { + pDataR[0] = 0; + BN_SIZE(pR) = 1; + BN_SIGN(pR) = ippBigNumPOS; + return ippStsNoErr; + } + + if(0>cmpRes) { + SWAP(nsA, nsB); + SWAP_PTR(BNU_CHUNK_T, pDataA, pDataB); + } + + carry = cpSub_BNU(pDataR, pDataA, pDataB, nsB); + if(nsA>nsB) + cpDec_BNU(pDataR+nsB, pDataA+nsB, nsA-nsB, carry); + + BN_SIGN(pR) = cmpRes>0? sgnA : INVERSE_SIGN(sgnA); + } + + FIX_BNU(pDataR, nsA); + BN_SIZE(pR) = nsA; + + return ippStsNoErr; + } + } +} + + +/*F* +// Name: ippsSub_BN +// +// Purpose: Subtcrac BigNum. +// +// Returns: Reason: +// ippStsNullPtrErr pA == NULL +// pB == NULL +// pR == NULL +// ippStsContextMatchErr BN_VALID_ID(pA) +// BN_VALID_ID(pB) +// BN_VALID_ID(pR) +// ippStsOutOfRangeErr pR can not hold result +// ippStsNoErr no errors +// +// Parameters: +// pA source BigNum +// pB source BigNum +// pR resultant BigNum +// +*F*/ +IPPFUN(IppStatus, ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +{ + IPP_BAD_PTR3_RET(pA, pB, pR); + + pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); + pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); + pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); + + { + cpSize nsA = BN_SIZE(pA); + cpSize nsB = BN_SIZE(pB); + cpSize nsR = BN_ROOM(pR); + IPP_BADARG_RET(nsR < IPP_MAX(nsA, nsB), ippStsOutOfRangeErr); + + { + BNU_CHUNK_T* pDataR = BN_NUMBER(pR); + + IppsBigNumSGN sgnA = BN_SIGN(pA); + IppsBigNumSGN sgnB = BN_SIGN(pB); + BNU_CHUNK_T* pDataA = BN_NUMBER(pA); + BNU_CHUNK_T* pDataB = BN_NUMBER(pB); + + BNU_CHUNK_T carry; + + if(sgnA!=sgnB) { + if(nsA < nsB) { + SWAP(nsA, nsB); + SWAP_PTR(BNU_CHUNK_T, pDataA, pDataB); + } + + carry = cpAdd_BNU(pDataR, pDataA, pDataB, nsB); + if(nsA>nsB) + carry = cpInc_BNU(pDataR+nsB, pDataA+nsB, nsA-nsB, carry); + if(carry) { + if(nsR > nsA) + pDataR[nsA++] = carry; + else + IPP_ERROR_RET(ippStsOutOfRangeErr); + } + BN_SIGN(pR) = sgnA; + } + + else { + int cmpRes= cpCmp_BNU(pDataA, nsA, pDataB, nsB); + + if(0==cmpRes) { + ZEXPAND_BNU(pDataR,0, nsR); + BN_SIZE(pR) = 1; + BN_SIGN(pR) = ippBigNumPOS; + return ippStsNoErr; + } + + if(0>cmpRes) { + SWAP(nsA, nsB); + SWAP_PTR(BNU_CHUNK_T, pDataA, pDataB); + } + + carry = cpSub_BNU(pDataR, pDataA, pDataB, nsB); + if(nsA>nsB) + cpDec_BNU(pDataR+nsB, pDataA+nsB, nsA-nsB, carry); + + BN_SIGN(pR) = cmpRes>0? sgnA : INVERSE_SIGN(sgnA); + } + + FIX_BNU(pDataR, nsA); + BN_SIZE(pR) = nsA; + + return ippStsNoErr; + } + } +} + + +/*F* +// Name: ippsMul_BN +// +// Purpose: Multiply BigNum. +// +// Returns: Reason: +// ippStsNullPtrErr pA == NULL +// pB == NULL +// pR == NULL +// ippStsContextMatchErr BN_VALID_ID(pA) +// BN_VALID_ID(pB) +// BN_VALID_ID(pR) +// ippStsOutOfRangeErr pR can not hold result +// ippStsNoErr no errors +// +// Parameters: +// pA source BigNum +// pB source BigNum +// pR resultant BigNum +// +*F*/ +IPPFUN(IppStatus, ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +{ + IPP_BAD_PTR3_RET(pA, pB, pR); + + pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); + pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); + pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); + + { + BNU_CHUNK_T* pDataA = BN_NUMBER(pA); + BNU_CHUNK_T* pDataB = BN_NUMBER(pB); + BNU_CHUNK_T* pDataR = BN_NUMBER(pR); + + cpSize nsA = BN_SIZE(pA); + cpSize nsB = BN_SIZE(pB); + cpSize nsR = BN_ROOM(pR); + + cpSize bitSizeA = BITSIZE_BNU(pDataA, nsA); + cpSize bitSizeB = BITSIZE_BNU(pDataB, nsB); + + /* test if multiplicant/multiplier is zero */ + if(!bitSizeA || !bitSizeB) { + BN_SIZE(pR) = 1; + BN_SIGN(pR) = IppsBigNumPOS; + pDataR[0] = 0; + return ippStsNoErr; + } + + /* test if even low estimation of product A*B exceeded */ + IPP_BADARG_RET(nsR*BNU_CHUNK_BITS < (bitSizeA+bitSizeB-1), ippStsOutOfRangeErr); + + { + BNU_CHUNK_T* aData = pDataA; + BNU_CHUNK_T* bData = pDataB; + + if(pA == pR) { + aData = BN_BUFFER(pR); + COPY_BNU(aData, pDataA, nsA); + } + if((pB == pR) && (pA != pB)) { + bData = BN_BUFFER(pR); + COPY_BNU(bData, pDataB, nsB); + } + + /* clear result */ + ZEXPAND_BNU(pDataR, 0, nsR+1); + + cpMul_BNU_school(pDataR, aData, nsA, bData, nsB); + + nsR = (bitSizeA + bitSizeB + BNU_CHUNK_BITS - 1) /BNU_CHUNK_BITS; + FIX_BNU(pDataR, nsR); + IPP_BADARG_RET(nsR>BN_ROOM(pR), ippStsOutOfRangeErr); + + BN_SIZE(pR) = nsR; + BN_SIGN(pR) = (BN_SIGN(pA)==BN_SIGN(pB)? ippBigNumPOS : ippBigNumNEG); + return ippStsNoErr; + } + } +} + + +/*F* +// Name: ippsDiv_BN +// +// Purpose: Divide BigNum. +// +// Returns: Reason: +// ippStsNullPtrErr pA == NULL +// pB == NULL +// pQ == NULL +// pR == NULL +// ippStsContextMatchErr BN_VALID_ID(pA) +// BN_VALID_ID(pB) +// BN_VALID_ID(pQ) +// BN_VALID_ID(pR) +// ippStsOutOfRangeErr pQ and/or pR can not hold result +// ippStsNoErr no errors +// +// Parameters: +// pA source BigNum +// pB source BigNum +// pQ quotient BigNum +// pR reminder BigNum +// +// A = Q*B + R, 0 <= val(R) < val(B), sgn(A)==sgn(R) +// +*F*/ +IPPFUN(IppStatus, ippsDiv_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pQ, IppsBigNumState* pR)) +{ + IPP_BAD_PTR4_RET(pA, pB, pQ, pR); + + pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); + pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); + pQ = (IppsBigNumState*)( IPP_ALIGNED_PTR(pQ, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pQ), ippStsContextMatchErr); + pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); + + IPP_BADARG_RET(BN_SIZE(pB)== 1 && BN_NUMBER(pB)[0]==0, ippStsDivByZeroErr); + + IPP_BADARG_RET(BN_ROOM(pR)cmpRes) + SWAP_PTR(IppsBigNumState, x, y); + if(0==cmpRes) { + COPY_BNU(BN_NUMBER(g), BN_NUMBER(x), BN_SIZE(x)); + BN_SIGN(g) = ippBigNumPOS; + BN_SIZE(g) = BN_SIZE(x); + return ippStsNoErr; + } + if(BN_SIZE(x)==1) { + BNU_CHUNK_T gcd = cpGcd_BNU(BN_NUMBER(x)[0], BN_NUMBER(y)[0]); + BN_NUMBER(g)[0] = gcd; + BN_SIZE(g) = 1; + return ippStsNoErr; + } + } + + { + Ipp32u* xBuffer = (Ipp32u*)BN_BUFFER(x); + Ipp32u* yBuffer = (Ipp32u*)BN_BUFFER(y); + Ipp32u* gBuffer = (Ipp32u*)BN_BUFFER(g); + Ipp32u* xData = (Ipp32u*)BN_NUMBER(x); + Ipp32u* yData = (Ipp32u*)BN_NUMBER(y); + Ipp32u* gData = (Ipp32u*)BN_NUMBER(g); + cpSize nsXmax = BN_ROOM(x)*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)); + cpSize nsYmax = BN_ROOM(y)*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)); + cpSize nsGmax = BN_ROOM(g)*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)); + cpSize nsX = BN_SIZE(x)*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)); + cpSize nsY = BN_SIZE(y)*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)); + + Ipp32u* T; + Ipp32u* u; + + FIX_BNU(xData, nsX); + FIX_BNU(yData, nsY); + + /* init buffers */ + ZEXPAND_COPY_BNU(xBuffer, nsX, xData, nsXmax); + ZEXPAND_COPY_BNU(yBuffer, nsY, yData, nsYmax); + + T = gBuffer; + u = gData; + ZEXPAND_BNU(T, 0, nsGmax); + ZEXPAND_BNU(u, 0, nsGmax); + + while(nsX > (cpSize)(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u))) { + /* xx and yy is the high-order digits of x and y (yy could be 0) */ + + Ipp64u xx = (Ipp64u)(xBuffer[nsX-1]); + Ipp64u yy = (nsY < nsX)? 0 : (Ipp64u)(yBuffer[nsY-1]); + + Ipp64s AA = 1; + Ipp64s BB = 0; + Ipp64s CC = 0; + Ipp64s DD = 1; + Ipp64s t; + + while((yy+CC)!=0 && (yy+DD)!=0) { + Ipp64u q = ( xx + AA ) / ( yy + CC ); + Ipp64u q1 = ( xx + BB ) / ( yy + DD ); + if(q!=q1) + break; + t = AA - q*CC; + AA = CC; + CC = t; + t = BB - q*DD; + BB = DD; + DD = t; + t = xx - q*yy; + xx = yy; + yy = t; + } + + if(BB == 0) { + /* T = x mod y */ + cpSize nsT = cpMod_BNU32(xBuffer, nsX, yBuffer, nsY); + ZEXPAND_BNU(T, 0, nsGmax); + COPY_BNU(T, xBuffer, nsT); + /* a = b; b = T; */ + ZEXPAND_BNU(xBuffer, 0, nsXmax); + COPY_BNU(xBuffer, yBuffer, nsY); + ZEXPAND_BNU(yBuffer, 0, nsYmax); + COPY_BNU(yBuffer, T, nsY); + } + + else { + Ipp32u carry; + /* + // T = AA*x + BB*y; + // u = CC*x + DD*y; + // b = u; a = T; + */ + if((AA <= 0)&&(BB>=0)) { + Ipp32u a1 = (Ipp32u)(-AA); + carry = cpMulDgt_BNU32(T, yBuffer, nsY, (Ipp32u)BB); + carry = cpMulDgt_BNU32(u, xBuffer, nsY, a1); + /* T = BB*y - AA*x; */ + carry = cpSub_BNU32(T, T, u, nsY); + } + else { + if((AA >= 0)&&(BB<=0)) { + Ipp32u b1 = (Ipp32u)(-BB); + carry = cpMulDgt_BNU32(T, xBuffer, nsY, (Ipp32u)AA); + carry = cpMulDgt_BNU32(u, yBuffer, nsY, b1); + /* T = AA*x - BB*y; */ + carry = cpSub_BNU32(T, T, u, nsY); + } + else { + /*AA*BB>=0 */ + carry = cpMulDgt_BNU32(T, xBuffer, nsY, (Ipp32u)AA); + carry = cpMulDgt_BNU32(u, yBuffer, nsY, (Ipp32u)BB); + /* T = AA*x + BB*y; */ + carry = cpAdd_BNU32(T, T, u, nsY); + } + } + + /* Now T is reserved. We use only u for intermediate results. */ + if((CC <= 0)&&(DD>=0)){ + Ipp32u c1 = (Ipp32u)(-CC); + /* u = x*CC; x = u; */ + carry = cpMulDgt_BNU32(u, xBuffer, nsY, c1); + COPY_BNU(xBuffer, u, nsY); + /* u = y*DD; */ + carry = cpMulDgt_BNU32(u, yBuffer, nsY, (Ipp32u)DD); + /* u = DD*y - CC*x; */ + carry = cpSub_BNU32(u, u, xBuffer, nsY); + } + else { + if((CC >= 0)&&(DD<=0)){ + Ipp32u d1 = (Ipp32u)(-DD); + /* u = y*DD; y = u */ + carry = cpMulDgt_BNU32(u, yBuffer, nsY, d1); + COPY_BNU(yBuffer, u, nsY); + /* u = CC*x; */ + carry = cpMulDgt_BNU32(u, xBuffer, nsY, (Ipp32u)CC); + /* u = CC*x - DD*y; */ + carry = cpSub_BNU32(u, u, yBuffer, nsY); + } + else { + /*CC*DD>=0 */ + /* y = y*DD */ + carry = cpMulDgt_BNU32(u, yBuffer, nsY, (Ipp32u)DD); + COPY_BNU(yBuffer, u, nsY); + /* u = x*CC */ + carry = cpMulDgt_BNU32(u, xBuffer, nsY, (Ipp32u)CC); + /* u = x*CC + y*DD */ + carry = cpAdd_BNU32(u, u, yBuffer, nsY); + } + } + + /* y = u; x = T; */ + COPY_BNU(yBuffer, u, nsY); + COPY_BNU(xBuffer, T, nsY); + } + + FIX_BNU(xBuffer, nsX); + FIX_BNU(yBuffer, nsY); + + if (nsY > nsX) { + SWAP_PTR(IppsBigNumState, x, y); + SWAP(nsX, nsY); + } + + if (nsY==1 && yBuffer[nsY-1]==0) { + /* End evaluation */ + ZEXPAND_BNU(gData, 0, nsGmax); + COPY_BNU(gData, xBuffer, nsX); + BN_SIZE(g) = INTERNAL_BNU_LENGTH(nsX); + BN_SIGN(g) = ippBigNumPOS; + return ippStsNoErr; + } + } + + BN_NUMBER(g)[0] = cpGcd_BNU(((BNU_CHUNK_T*)xBuffer)[0], ((BNU_CHUNK_T*)yBuffer)[0]); + BN_SIZE(g) = 1; + BN_SIGN(g) = ippBigNumPOS; + return ippStsNoErr; + } + } +} + + +/*F* +// Name: ippsModInv_BN +// +// Purpose: Multiplicative Inversion BigNum. +// +// Returns: Reason: +// ippStsNullPtrErr pA == NULL +// pM == NULL +// pR == NULL +// ippStsContextMatchErr BN_VALID_ID(pA) +// BN_VALID_ID(pM) +// BN_VALID_ID(pR) +// ippStsBadArgErr A<=0 +// ippStsBadModulusErr M<=0 +// ippStsScaleRangeErr A>=M +// ippStsOutOfRangeErr pR can not hold result +// ippStsNoErr no errors +// ippStsBadModulusErr inversion not found +// +// Parameters: +// pA source (value) BigNum +// pM source (modulus) BigNum +// pR reminder BigNum +// +*F*/ +IPPFUN(IppStatus, ippsModInv_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR) ) +{ + IPP_BAD_PTR3_RET(pA, pM, pR); + + pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); + pM = (IppsBigNumState*)( IPP_ALIGNED_PTR(pM, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pM), ippStsContextMatchErr); + pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); + + IPP_BADARG_RET(BN_ROOM(pR) < BN_SIZE(pM), ippStsOutOfRangeErr); + IPP_BADARG_RET(BN_NEGATIVE(pA) || (BN_SIZE(pA)==1 && BN_NUMBER(pA)[0]==0), ippStsBadArgErr); + IPP_BADARG_RET(BN_NEGATIVE(pM) || (BN_SIZE(pM)==1 && BN_NUMBER(pM)[0]==0), ippStsBadModulusErr); + IPP_BADARG_RET(cpCmp_BNU(BN_NUMBER(pA), BN_SIZE(pA), BN_NUMBER(pM), BN_SIZE(pM)) >= 0, ippStsScaleRangeErr); + + { + cpSize nsR = cpModInv_BNU(BN_NUMBER(pR), + BN_NUMBER(pA), BN_SIZE(pA), + BN_NUMBER(pM), BN_SIZE(pM), + BN_BUFFER(pR), BN_BUFFER(pA), BN_BUFFER(pM)); + if(nsR) { + BN_SIGN(pR) = ippBigNumPOS; + BN_SIZE(pR) = nsR; + return ippStsNoErr; + } + else + return ippStsBadModulusErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnresource.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnresource.h new file mode 100644 index 0000000000..0358aaed4e --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnresource.h @@ -0,0 +1,51 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_PCP_BNRESOURCE_H) +#define _PCP_BNRESOURCE_H + + +typedef struct { + void* pNext; + IppsBigNumState* pBN; +} BigNumNode; + + +/* size (byte) of BN resource */ +int cpBigNumListGetSize(int feBitSize, int nodes); + +/* init BN resource */ +void cpBigNumListInit(int feBitSize, int nodes, BigNumNode* pList); + +/* get BN from resource */ +IppsBigNumState* cpBigNumListGet(BigNumNode** pList); + +#endif /* _PCP_BNRESOURCE_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnresourceca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnresourceca.c new file mode 100644 index 0000000000..63bdd6737f --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnresourceca.c @@ -0,0 +1,93 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpbnresource.h" +#include "pcpbn.h" + +/* +// Size of BigNum List Buffer +*/ +int cpBigNumListGetSize(int feBitSize, int nodes) +{ + /* size of buffer per single big number */ + int bnSize; + ippsBigNumGetSize(BITS2WORD32_SIZE(feBitSize), &bnSize); + + /* size of buffer for whole list */ + return (ALIGN_VAL-1) + (sizeof(BigNumNode) + bnSize) * nodes; +} + +/* +// Init list +// +// Note: buffer for BN list must have appropriate alignment +*/ +void cpBigNumListInit(int feBitSize, int nodes, BigNumNode* pList) +{ + int itemSize; + /* length of Big Num */ + int bnLen = BITS2WORD32_SIZE(feBitSize); + /* size of buffer per single big number */ + ippsBigNumGetSize(bnLen, &itemSize); + /* size of list item */ + itemSize += sizeof(BigNumNode); + + { + int n; + /* init all nodes */ + BigNumNode* pNode = (BigNumNode*)( (Ipp8u*)pList + (nodes-1)*itemSize ); + BigNumNode* pNext = NULL; + for(n=0; npNext = pNext; + pNode->pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(tbnPtr, ALIGN_VAL) ); + ippsBigNumInit(bnLen, pNode->pBN); + pNext = pNode; + pNode = (BigNumNode*)( (Ipp8u*)pNode - itemSize); + } + } +} + +/* +// Get BigNum reference +*/ +IppsBigNumState* cpBigNumListGet(BigNumNode** ppList) +{ + if(*ppList) { + IppsBigNumState* ret = (*ppList)->pBN; + *ppList = (BigNumNode*)((*ppList)->pNext); + return ret; + } + else + return NULL; +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnsetca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnsetca.c new file mode 100644 index 0000000000..728ec45c8d --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnsetca.c @@ -0,0 +1,119 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpbn.h" + + +/*F* +// Name: ippsSetOctString_BN +// +// Purpose: Convert octet string into the BN value. +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pOctStr +// NULL == pBN +// +// ippStsLengthErr 0>strLen +// +// ippStsSizeErr BN_ROOM() is enough for keep actual strLen +// +// ippStsNoErr no errors +// +// Parameters: +// pOctStr pointer to the source octet string +// strLen octet string length +// pBN pointer to the target BN +// +*F*/ +IPPFUN(IppStatus, ippsSetOctString_BN,(const Ipp8u* pOctStr, cpSize strLen, + IppsBigNumState* pBN)) +{ + IPP_BAD_PTR2_RET(pOctStr, pBN); + + pBN = (IppsBigNumState*)( IPP_ALIGNED_PTR(pBN, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pBN), ippStsContextMatchErr); + + IPP_BADARG_RET((0>strLen), ippStsLengthErr); + + /* remove leading zeros */ + while(strLen && (0==pOctStr[0])) { + strLen--; + pOctStr++; + } + + /* test BN size */ + IPP_BADARG_RET((int)(sizeof(BNU_CHUNK_T)*BN_ROOM(pBN))strLen), ippStsLengthErr); + + return cpToOctStr_BNU(pOctStr,strLen, BN_NUMBER(pBN),BN_SIZE(pBN))? ippStsNoErr : ippStsLengthErr; +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnu32arith.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnu32arith.c new file mode 100644 index 0000000000..79779fd27c --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnu32arith.c @@ -0,0 +1,234 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owncp.h" +#include "pcpbnumisc.h" +#include "pcpbnu32misc.h" +#include "pcpbnu32arith.h" + + +/* +// BNU32 addition +*/ +Ipp32u cpAdd_BNU32(Ipp32u* pR, const Ipp32u* pA, const Ipp32u* pB, cpSize ns) +{ + Ipp32u carry = 0; + cpSize i; + for(i=0; i>(32-1); + } + return borrow; +} + +/* +// BNU32 mul_by_digit +*/ +Ipp32u cpMulDgt_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize nsA, Ipp32u val) +{ + Ipp32u carry = 0; + cpSize i; + for(i=0; i0; nsA--) { + Ipp64u r = (Ipp64u)*pR - (Ipp64u)(*pA++) * val - carry; + *pR++ = LODWORD(r); + carry = 0-HIDWORD(r); + } + return carry; +} + +/* +// BNU32 division +*/ +int cpDiv_BNU32(Ipp32u* pQ, cpSize* sizeQ, + Ipp32u* pX, cpSize sizeX, + Ipp32u* pY, cpSize sizeY) +{ + FIX_BNU(pY,sizeY); + FIX_BNU(pX,sizeX); + + /* special case */ + if(sizeX < sizeY) { + + if(pQ) { + pQ[0] = 0; + *sizeQ = 1; + } + + return sizeX; + } + + /* special case */ + if(1 == sizeY) { + int i; + Ipp32u r = 0; + for(i=(int)sizeX-1; i>=0; i--) { + Ipp64u tmp = MAKEDWORD(pX[i],r); + Ipp32u q = LODWORD(tmp / pY[0]); + r = LODWORD(tmp - q*pY[0]); + if(pQ) pQ[i] = q; + } + + pX[0] = r; + + if(pQ) { + FIX_BNU(pQ,sizeX); + *sizeQ = sizeX; + } + + return 1; + } + + + /* common case */ + { + cpSize qs = sizeX-sizeY+1; + + cpSize nlz = cpNLZ_BNU32(pY[sizeY-1]); + + /* normalization */ + pX[sizeX] = 0; + if(nlz) { + cpSize ni; + + pX[sizeX] = pX[sizeX-1] >> (32-nlz); + for(ni=sizeX-1; ni>0; ni--) + pX[ni] = (pX[ni]<>(32-nlz)); + pX[0] <<= nlz; + + for(ni=sizeY-1; ni>0; ni--) + pY[ni] = (pY[ni]<>(32-nlz)); + pY[0] <<= nlz; + } + + /* + // division + */ + { + Ipp32u yHi = pY[sizeY-1]; + + int i; + for(i=(int)qs-1; i>=0; i--) { + Ipp32u extend; + + /* estimate digit of quotient */ + Ipp64u tmp = MAKEDWORD(pX[i+sizeY-1], pX[i+sizeY]); + Ipp64u q = tmp / yHi; + Ipp64u r = tmp - q*yHi; + + /* tune estimation above */ + for(; HIDWORD(q) || (Ipp64u)q*pY[sizeY-2] > MAKEDWORD(pX[i+sizeY-2],r); ) { + q -= 1; + r += yHi; + if( HIDWORD(r) ) + break; + } + + /* multiply and subtract */ + extend = cpSubMulDgt_BNU32(pX+i, pY, sizeY, (Ipp32u)q); + extend = (pX[i+sizeY] -= extend); + + if(extend) { /* subtracted too much */ + q -= 1; + extend = cpAdd_BNU32(pX+i, pY, pX+i, sizeY); + pX[i+sizeY] += extend; + } + + /* store quotation digit */ + if(pQ) pQ[i] = LODWORD(q); + } + } + + /* de-normalization */ + if(nlz) { + cpSize ni; + for(ni=0; ni>nlz) | (pX[ni+1]<<(32-nlz)); + for(ni=0; ni>nlz) | (pY[ni+1]<<(32-nlz)); + pY[sizeY-1] >>= nlz; + } + + FIX_BNU(pX,sizeX); + + if(pQ) { + FIX_BNU(pQ,qs); + *sizeQ = qs; + } + + return sizeX; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnu32arith.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnu32arith.h new file mode 100644 index 0000000000..96cfe24231 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnu32arith.h @@ -0,0 +1,46 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_CP_BNU32_ARITH_H) +#define _CP_BNU32_ARITH_H + +Ipp32u cpAdd_BNU32(Ipp32u* pR, const Ipp32u* pA, const Ipp32u* pB, int ns); +Ipp32u cpSub_BNU32(Ipp32u* pR, const Ipp32u* pA, const Ipp32u* pB, int ns); +Ipp32u cpInc_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize ns, Ipp32u val); +Ipp32u cpDec_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize ns, Ipp32u val); + +Ipp32u cpMulDgt_BNU32(Ipp32u* pR, const Ipp32u* pA, int ns, Ipp32u val); +Ipp32u cpSubMulDgt_BNU32(Ipp32u* pR, const Ipp32u* pA, int nsA, Ipp32u val); + +int cpDiv_BNU32(Ipp32u* pQ, int* nsQ, Ipp32u* pX, int nsX, Ipp32u* pY, int nsY); +#define cpMod_BNU32(pX,sizeX, pM,sizeM) cpDiv_BNU32(NULL,NULL, (pX),(sizeX), (pM),(sizeM)) + +#endif /* _CP_BNU32_ARITH_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnu32misc.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnu32misc.c new file mode 100644 index 0000000000..6680a497d7 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnu32misc.c @@ -0,0 +1,53 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owncp.h" +#include "pcpbnuimpl.h" +#include "pcpbnumisc.h" +#include "pcpbnu32misc.h" + + +/* +// number of leading zeros +*/ +cpSize cpNLZ_BNU32(Ipp32u x) +{ + cpSize nlz = BITSIZE(Ipp32u); + if(x) { + nlz = 0; + if( 0==(x & 0xFFFF0000) ) { nlz +=16; x<<=16; } + if( 0==(x & 0xFF000000) ) { nlz += 8; x<<= 8; } + if( 0==(x & 0xF0000000) ) { nlz += 4; x<<= 4; } + if( 0==(x & 0xC0000000) ) { nlz += 2; x<<= 2; } + if( 0==(x & 0x80000000) ) { nlz++; } + } + return nlz; +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnu32misc.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnu32misc.h new file mode 100644 index 0000000000..cda2eca224 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnu32misc.h @@ -0,0 +1,49 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_CP_BNU32_MISC_H) +#define _CP_BNU32_MISC_H + + +/* bit operations */ +#define BITSIZE_BNU32(p,ns) ((ns)*BNU_CHUNK_32BIT-cpNLZ_BNU32((p)[(ns)-1])) + +/* number of leading/trailing zeros */ +cpSize cpNLZ_BNU32(Ipp32u x); + +/* most significant BNU bit */ +__INLINE int cpMSBit_BNU32(const Ipp32u* pA, cpSize nsA) +{ + FIX_BNU(pA, nsA); + return nsA*BITSIZE(Ipp32u) - cpNLZ_BNU32(pA[nsA-1]) -1; +} + +#endif /* _CP_BNU32_MISC_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnuarith.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnuarith.c new file mode 100644 index 0000000000..93822f3f67 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnuarith.c @@ -0,0 +1,301 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owncp.h" +#include "pcpbnuarith.h" +#include "pcpbnumisc.h" + + +/* Function cpAdd_BNU - addition of 2 BigNumbers */ +BNU_CHUNK_T cpAdd_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, cpSize ns) +{ + BNU_CHUNK_T carry = 0; + cpSize i; + for(i=0; i b){ + gcd = a; + t = b; + } else { + t = a; + gcd = b; + } + + while (t != 0) { + r = gcd % t; + gcd = t; + t = r; + } + return gcd; +} + + +/* +// cpMAC_BNU +// +// Multiply with ACcumulation +// Computes r <- r + a * b, returns real size of the r in the size_r variable +// Returns 0 if there are no enought buffer size to write to r[MAX(size_r + 1, size_a + size_b) - 1] +// Returns 1 if no error +// +// Note: +// DO NOT run in inplace mode +// The minimum buffer size for the r must be (size_a + size_b - 1) +// the maximum buffer size for the r is MAX(size_r + 1, size_a + size_b) +*/ +static int cpMac_BNU(BNU_CHUNK_T* pR, cpSize nsR, + const BNU_CHUNK_T* pA, cpSize nsA, + const BNU_CHUNK_T* pB, cpSize nsB) +{ + /* cleanup the rest of destination buffer */ + ZEXPAND_BNU(pR, nsR, nsA+nsB-1); + + { + BNU_CHUNK_T expansion = 0; + cpSize i; + for(i=0; i> (BNU_CHUNK_BITS/2)) + +/* (carry,R) = A+B */ +#define ADD_AB(CARRY,R, A,B) \ +do { \ + BNU_CHUNK_T __s = (A) + (B); \ + (CARRY) = __s < (A); \ + (R) = __s; \ +} while(0) + +/* (carry,R) = A+B+C */ +#define ADD_ABC(CARRY,R, A,B,C) \ +do { \ + BNU_CHUNK_T __s = (A) + (B); \ + BNU_CHUNK_T __t1= __s < (A); \ + BNU_CHUNK_T __r = __s + (C); \ + BNU_CHUNK_T __t2 = __r < __s; \ + (CARRY) = __t1 + __t2; \ + (R) = __r; \ +} while(0) + +/* (borrow,R) = A-B */ +#define SUB_AB(BORROW,R, A,B) \ +do { \ + (BORROW) = (A)<(B); \ + (R) = (A)-(B); \ +} while(0) + +/* (borrow,R) = A-B-C */ +#define SUB_ABC(BORROW,R, A,B,C) \ +do { \ + BNU_CHUNK_T __s = (A) -( B); \ + BNU_CHUNK_T __t1= __s > (A); \ + BNU_CHUNK_T __r = __s - (C); \ + BNU_CHUNK_T __t2 = __r > __s; \ + (BORROW) = __t1 + __t2; \ + (R) = __r; \ +} while(0) + +/* (RH,RL) = A*B */ +#define MUL_AB(RH, RL, A, B) \ + do { \ + BNU_CHUNK_T __aL = LO_CHUNK((A)); \ + BNU_CHUNK_T __aH = HI_CHUNK((A)); \ + BNU_CHUNK_T __bL = LO_CHUNK((B)); \ + BNU_CHUNK_T __bH = HI_CHUNK((B)); \ + \ + BNU_CHUNK_T __x0 = (BNU_CHUNK_T) __aL * __bL; \ + BNU_CHUNK_T __x1 = (BNU_CHUNK_T) __aL * __bH; \ + BNU_CHUNK_T __x2 = (BNU_CHUNK_T) __aH * __bL; \ + BNU_CHUNK_T __x3 = (BNU_CHUNK_T) __aH * __bH; \ + \ + __x1 += HI_CHUNK(__x0); \ + __x1 += __x2; \ + if(__x1 < __x2) \ + __x3 += BNU_CHUNK_2H; \ + \ + (RH) = __x3 + HI_CHUNK(__x1); \ + (RL) = (__x1 << BNU_CHUNK_BITS/2) + LO_CHUNK(__x0); \ + } while (0) + +#endif /* _CP_BNU_IMPL_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnumisc.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnumisc.c new file mode 100644 index 0000000000..3b0bb839fc --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnumisc.c @@ -0,0 +1,208 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owncp.h" +#include "pcpbnumisc.h" + + +/* +// number of leading zeros +*/ +cpSize cpNLZ_BNU(BNU_CHUNK_T x) +{ + cpSize nlz = BNU_CHUNK_BITS; + if(x) { + nlz = 0; + #if (BNU_CHUNK_BITS == BNU_CHUNK_64BIT) + if( 0==(x & 0xFFFFFFFF00000000) ) { nlz +=32; x<<=32; } + if( 0==(x & 0xFFFF000000000000) ) { nlz +=16; x<<=16; } + if( 0==(x & 0xFF00000000000000) ) { nlz += 8; x<<= 8; } + if( 0==(x & 0xF000000000000000) ) { nlz += 4; x<<= 4; } + if( 0==(x & 0xC000000000000000) ) { nlz += 2; x<<= 2; } + if( 0==(x & 0x8000000000000000) ) { nlz++; } + #else + if( 0==(x & 0xFFFF0000) ) { nlz +=16; x<<=16; } + if( 0==(x & 0xFF000000) ) { nlz += 8; x<<= 8; } + if( 0==(x & 0xF0000000) ) { nlz += 4; x<<= 4; } + if( 0==(x & 0xC0000000) ) { nlz += 2; x<<= 2; } + if( 0==(x & 0x80000000) ) { nlz++; } + #endif + } + return nlz; +} + +/* +// number of trailing zeros +*/ +cpSize cpNTZ_BNU(BNU_CHUNK_T x) +{ + cpSize ntz = BNU_CHUNK_BITS; + if(x) { + ntz = 0; + #if (BNU_CHUNK_BITS==BNU_CHUNK_64BIT) + if( 0==(x & 0x00000000FFFFFFFF) ) { ntz+=32; x>>=32; } + if( 0==(x & 0x000000000000FFFF) ) { ntz+=16; x>>=16; } + if( 0==(x & 0x00000000000000FF) ) { ntz+= 8; x>>= 8; } + if( 0==(x & 0x000000000000000F) ) { ntz+= 4; x>>= 4; } + if( 0==(x & 0x0000000000000003) ) { ntz+= 2; x>>= 2; } + if( 0==(x & 0x0000000000000001) ) { ntz++; } + #else + if( 0==(x & 0x0000FFFF) ) { ntz+=16; x>>=16; } + if( 0==(x & 0x000000FF) ) { ntz+= 8; x>>= 8; } + if( 0==(x & 0x0000000F) ) { ntz+= 4; x>>= 4; } + if( 0==(x & 0x00000003) ) { ntz+= 2; x>>= 2; } + if( 0==(x & 0x00000001) ) { ntz++; } + #endif + } + return ntz; +} + + +/* +// Logical shift right (including inplace) +// +// Returns new length +// +*/ +cpSize cpLSR_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize nsA, cpSize nBits) +{ + cpSize nw = nBits/BNU_CHUNK_BITS; + cpSize n; + + pA += nw; + nsA -= nw; + + nBits %= BNU_CHUNK_BITS; + if(nBits) { + BNU_CHUNK_T hi; + BNU_CHUNK_T lo = pA[0]; + + for(n=0; n<(nsA-1); n++) { + hi = pA[n+1]; + pR[n] = (lo>>nBits) | (hi<<(BNU_CHUNK_BITS-nBits)); + lo = hi; + } + pR[nsA-1] = (lo>>nBits); + } + else { + for(n=0; n=(int)sizeof(BNU_CHUNK_T); nsA++,strLen-=(int)(sizeof(BNU_CHUNK_T))) { + /* pack sizeof(BNU_CHUNK_T) bytes into single BNU_CHUNK_T value*/ + *pA++ = + #if (BNU_CHUNK_BITS==BNU_CHUNK_64BIT) + +( (BNU_CHUNK_T)pStr[strLen-8]<<(8*7) ) + +( (BNU_CHUNK_T)pStr[strLen-7]<<(8*6) ) + +( (BNU_CHUNK_T)pStr[strLen-6]<<(8*5) ) + +( (BNU_CHUNK_T)pStr[strLen-5]<<(8*4) ) + #endif + +( (BNU_CHUNK_T)pStr[strLen-4]<<(8*3) ) + +( (BNU_CHUNK_T)pStr[strLen-3]<<(8*2) ) + +( (BNU_CHUNK_T)pStr[strLen-2]<<(8*1) ) + + (BNU_CHUNK_T)pStr[strLen-1]; + } + + /* convert the beginning of the string */ + if(strLen) { + BNU_CHUNK_T x = 0; + for(x=0; strLen>0; strLen--) { + BNU_CHUNK_T d = *pStr++; + x = (x<<8) + d; + } + *pA++ = x; + nsA++; + } + + return nsA; +} + +/* +// Convert BNU into HexString representation +// +// Returns length of the string or 0 if no success +*/ +cpSize cpToOctStr_BNU(Ipp8u* pStr, cpSize strLen, const BNU_CHUNK_T* pA, cpSize nsA) +{ + FIX_BNU(pA, nsA); + { + cpSize bnuBitSize = BITSIZE_BNU(pA, nsA); + if(bnuBitSize <= strLen*BYTESIZE) { + int cnvLen = 0; + BNU_CHUNK_T x = pA[nsA-1]; + + ZEXPAND_BNU(pStr, 0, strLen); + pStr += strLen - BITS2WORD8_SIZE(bnuBitSize); + + if(x) { + //int nb; + cpSize nb; + for(nb=cpNLZ_BNU(x)/BYTESIZE; nb<(cpSize)(sizeof(BNU_CHUNK_T)); cnvLen++, nb++) + *pStr++ = EBYTE(x, sizeof(BNU_CHUNK_T)-1-nb); + + for(--nsA; nsA>0; cnvLen+=sizeof(BNU_CHUNK_T), nsA--) { + x = pA[nsA-1]; + #if (BNU_CHUNK_BITS==BNU_CHUNK_64BIT) + *pStr++ = EBYTE(x,7); + *pStr++ = EBYTE(x,6); + *pStr++ = EBYTE(x,5); + *pStr++ = EBYTE(x,4); + #endif + *pStr++ = EBYTE(x,3); + *pStr++ = EBYTE(x,2); + *pStr++ = EBYTE(x,1); + *pStr++ = EBYTE(x,0); + } + } + return strLen; + } + else + return 0; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnumisc.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnumisc.h new file mode 100644 index 0000000000..cbb8d60dbc --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpbnumisc.h @@ -0,0 +1,149 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_PCP_BNUMISC_H) +#define _PCP_BNUMISC_H + +#include "pcpbnuimpl.h" + + +/* bit operations */ +#define BITSIZE_BNU(p,ns) ((ns)*BNU_CHUNK_BITS-cpNLZ_BNU((p)[(ns)-1])) +#define BIT_BNU(bnu, ns,nbit) ((((nbit)>>BNU_CHUNK_LOG2) < (ns))? ((((bnu))[(nbit)>>BNU_CHUNK_LOG2] >>((nbit)&(BNU_CHUNK_BITS))) &1) : 0) +#define TST_BIT(bnu, nbit) ((((bnu))[(nbit)>>BNU_CHUNK_LOG2]) & ((BNU_CHUNK_T)1<<((nbit)&(BNU_CHUNK_BITS-1)))) +#define SET_BIT(bnu, nbit) ((((bnu))[(nbit)>>BNU_CHUNK_LOG2]) |= ((BNU_CHUNK_T)1<<((nbit)&(BNU_CHUNK_BITS-1)))) +#define CLR_BIT(bnu, nbit) ((((bnu))[(nbit)>>BNU_CHUNK_LOG2]) &=~((BNU_CHUNK_T)1<<((nbit)&(BNU_CHUNK_BITS-1)))) + +/* convert bitsize nbits into the number of BNU_CHUNK_T */ +#define BITS_BNU_CHUNK(nbits) (((nbits)+BNU_CHUNK_BITS-1)/BNU_CHUNK_BITS) + +/* mask for top BNU_CHUNK_T */ +#define MASK_BNU_CHUNK(nbits) ((BNU_CHUNK_T)(-1) >>((BNU_CHUNK_BITS- ((nbits)&(BNU_CHUNK_BITS-1))) &(BNU_CHUNK_BITS-1))) + +/* copy BNU content */ +#define COPY_BNU(dst, src, len) \ +{ \ + cpSize __idx; \ + for(__idx=0; __idx<(len); __idx++) (dst)[__idx] = (src)[__idx]; \ +} + +/* expand by zeros */ +#define ZEXPAND_BNU(srcdst,srcLen, dstLen) \ +{ \ + cpSize __idx; \ + for(__idx=(srcLen); __idx<(dstLen); __idx++) (srcdst)[__idx] = 0; \ +} + +/* copy and expand by zeros */ +#define ZEXPAND_COPY_BNU(dst,dstLen, src,srcLen) \ +{ \ + cpSize __idx; \ + for(__idx=0; __idx<(srcLen); __idx++) (dst)[__idx] = (src)[__idx]; \ + for(; __idx<(dstLen); __idx++) (dst)[__idx] = 0; \ +} + +/* fix actual length */ +#define FIX_BNU(src,srcLen) \ + for(; ((srcLen)>1) && (0==(src)[(srcLen)-1]); (srcLen)--) + + +/* copy and set */ +__INLINE void cpCpy_BNU(BNU_CHUNK_T* pDst, const BNU_CHUNK_T* pSrc, cpSize ns) +{ COPY_BNU(pDst, pSrc, ns); } + +__INLINE void cpSet_BNU(BNU_CHUNK_T* pDst, cpSize ns, BNU_CHUNK_T val) +{ + ZEXPAND_BNU(pDst, 0, ns); + pDst[0] = val; +} + +/* fix up */ +__INLINE int cpFix_BNU(const BNU_CHUNK_T* pA, int nsA) +{ + FIX_BNU(pA, nsA); + return nsA; +} + +/* comparison +// +// returns +// negative, if A < B +// 0, if A = B +// positive, if A > B +*/ +__INLINE int cpCmp_BNU(const BNU_CHUNK_T* pA, cpSize nsA, const BNU_CHUNK_T* pB, cpSize nsB) +{ + if(nsA!=nsB) + return nsA>nsB? 1 : -1; + else { + for(; nsA>0; nsA--) { + if(pA[nsA-1] > pB[nsA-1]) + return 1; + else if(pA[nsA-1] < pB[nsA-1]) + return -1; + } + return 0; + } +} +__INLINE int cpEqu_BNU_CHUNK(const BNU_CHUNK_T* pA, cpSize nsA, BNU_CHUNK_T b) +{ + return (pA[0]==b && 1==cpFix_BNU(pA, nsA)); +} + +/* +// test +// +// returns +// 0, if A = 0 +// >0, if A > 0 +// <0, looks like impossible (or error) case +*/ +__INLINE int cpTst_BNU(const BNU_CHUNK_T* pA, int nsA) +{ + for(; (nsA>0) && (0==pA[nsA-1]); nsA--) ; + return nsA; +} + +/* number of leading/trailing zeros */ +cpSize cpNLZ_BNU(BNU_CHUNK_T x); +cpSize cpNTZ_BNU(BNU_CHUNK_T x); + +/* logical shift left/right */ +int cpLSR_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize nsA, cpSize nBits); + +/* least and most significant BNU bit */ +int cpMSBit_BNU(const BNU_CHUNK_T* pA, cpSize nsA); + +/* BNU <-> hex-string conversion */ +int cpToOctStr_BNU(Ipp8u* pStr, cpSize strLen, const BNU_CHUNK_T* pA, cpSize nsA); +int cpFromOctStr_BNU(BNU_CHUNK_T* pA, const Ipp8u* pStr, cpSize strLen); + +#endif /* _PCP_BNUMISC_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpcmac.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpcmac.h new file mode 100644 index 0000000000..47eee76e9c --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpcmac.h @@ -0,0 +1,70 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_PCP_CMAC_H) +#define _PCP_CMAC_H + +#include "pcprij.h" + + +/* +// Rijndael128 based CMAC context +*/ +struct _cpAES_CMAC { + IppCtxId idCtx; /* CMAC identifier */ + int index; /* internal buffer entry (free) */ + int dummy[2]; /* align-16 */ + Ipp8u k1[MBS_RIJ128]; /* k1 subkey */ + Ipp8u k2[MBS_RIJ128]; /* k2 subkey */ + Ipp8u mBuffer[MBS_RIJ128];/* buffer */ + Ipp8u mMAC[MBS_RIJ128]; /* intermediate digest */ + __ALIGN16 /* aligned AES context */ + IppsAESSpec mCipherCtx; +}; + +/* alignment */ +#define AESCMAC_ALIGNMENT (RIJ_ALIGNMENT) + +/* +// Useful macros +*/ +#define CMAC_ID(stt) ((stt)->idCtx) +#define CMAC_INDX(stt) ((stt)->index) +#define CMAC_K1(stt) ((stt)->k1) +#define CMAC_K2(stt) ((stt)->k2) +#define CMAC_BUFF(stt) ((stt)->mBuffer) +#define CMAC_MAC(stt) ((stt)->mMAC) +#define CMAC_CIPHER(stt) ((stt)->mCipherCtx) + +/* valid context ID */ +#define VALID_AESCMAC_ID(ctx) (CMAC_ID((ctx))==idCtxCMAC) + +#endif /* _PCP_CMAC_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccp.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccp.h new file mode 100644 index 0000000000..34871a136f --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccp.h @@ -0,0 +1,230 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_PCP_ECCP_H) +#define _PCP_ECCP_H + +#include "pcpbnresource.h" +#include "pcppma.h" +#include "pcpeccppoint.h" +#include "pcpeccpsscm.h" + + +typedef struct eccp_method_st ECCP_METHOD; + +/* +// ECC over prime GF(p) Context +*/ +struct _cpECCP { + IppCtxId idCtx; /* prime EC identifier */ + + IppsBigNumState* pPrime; /* specify finite field GF(p) */ + IppsBigNumState* pA; /* scecify A & B of EC equation: */ + IppsBigNumState* pB; /* y^2 = x^3 + A*x + B (mod)p */ + + IppsBigNumState* pGX; /* Base Point (X coordinate) */ + IppsBigNumState* pGY; /* Base Point (Y coordinate) */ + IppsBigNumState* pR; /* order (r) of Base Point */ + /* fields above mainly for ippsECCPSet()/ippsECCPGet() */ + + Ipp32u eccStandard;/* generic/standard ecc */ + + ECCP_METHOD* pMethod; + + int gfeBitSize; /* size (bits) of field element */ + int ordBitSize; /* size (bits) of BP order */ + + int a_3; /* ==1 if A==-3 or A==P-3 */ + IppsBigNumState* pAenc; /* internal formatted pA value */ + IppsBigNumState* pBenc; /* internal formatted pB value */ + IppsMontState* pMontP; /* montromery engine (modulo p) */ + + IppsECCPPointState* pGenc; /* internal formatted Base Point */ + IppsBigNumState* pCofactor; /* cofactor = #E/base_point_order*/ + IppsMontState* pMontR; /* montromery engine (modulo r) */ + + IppsBigNumState* pPrivate; /* private key */ + IppsECCPPointState* pPublic; /* public key (affine) */ + IppsBigNumState* pPrivateE; /* ephemeral private key */ + IppsECCPPointState* pPublicE; /* ephemeral public key (affine) */ + + IppsPrimeState* pPrimary; /* prime engine */ + + Ipp8u* pSscmBuffer;/* pointer to sscm buffer */ + + BigNumNode* pBnList; /* list of big numbers */ +}; + +/* some useful constants */ +#define BNLISTSIZE (32) /* list size (probably less) */ + +/* +// Contetx Access Macros +*/ +#define ECP_ID(ctx) ((ctx)->idCtx) + +#define ECP_PRIME(ctx) ((ctx)->pPrime) +#define ECP_A(ctx) ((ctx)->pA) +#define ECP_B(ctx) ((ctx)->pB) + +#define ECP_GX(ctx) ((ctx)->pGX) +#define ECP_GY(ctx) ((ctx)->pGY) +#define ECP_ORDER(ctx) ((ctx)->pR) + +#define ECP_TYPE(ctx) ((ctx)->eccStandard) + +#define ECP_METHOD(ctx) ((ctx)->pMethod) + +#define ECP_GFEBITS(ctx) ((ctx)->gfeBitSize) +#define ECP_ORDBITS(ctx) ((ctx)->ordBitSize) + +#define ECP_AMI3(ctx) ((ctx)->a_3) +#define ECP_AENC(ctx) ((ctx)->pAenc) +#define ECP_BENC(ctx) ((ctx)->pBenc) +#define ECP_PMONT(ctx) ((ctx)->pMontP) + +#define ECP_GENC(ctx) ((ctx)->pGenc) +#define ECP_COFACTOR(ctx) ((ctx)->pCofactor) +#define ECP_RMONT(ctx) ((ctx)->pMontR) + +#define ECP_PRIVATE(ctx) ((ctx)->pPrivate) +#define ECP_PUBLIC(ctx) ((ctx)->pPublic) +#define ECP_PRIVATE_E(ctx) ((ctx)->pPrivateE) +#define ECP_PUBLIC_E(ctx) ((ctx)->pPublicE) + +#define ECP_PRIMARY(ctx) ((ctx)->pPrimary) +#define ECP_SCCMBUFF(ctx) ((ctx)->pSscmBuffer) +#define ECP_BNCTX(ctx) ((ctx)->pBnList) + +#define ECP_VALID_ID(ctx) (ECP_ID((ctx))==idCtxECCP) + +/* +// Recommended (Standard) Domain Parameters +*/ +extern const Ipp32u secp112r1_p[]; // (2^128 -3)/76439 +extern const Ipp32u secp112r1_a[]; +extern const Ipp32u secp112r1_b[]; +extern const Ipp32u secp112r1_gx[]; +extern const Ipp32u secp112r1_gy[]; +extern const Ipp32u secp112r1_r[]; +extern Ipp32u secp112r1_h; + +extern const Ipp32u secp112r2_p[]; // (2^128 -3)/76439 +extern const Ipp32u secp112r2_a[]; +extern const Ipp32u secp112r2_b[]; +extern const Ipp32u secp112r2_gx[]; +extern const Ipp32u secp112r2_gy[]; +extern const Ipp32u secp112r2_r[]; +extern Ipp32u secp112r2_h; + +extern const Ipp32u secp128r1_p[]; // 2^128 -2^97 -1 +extern const Ipp32u secp128r1_a[]; +extern const Ipp32u secp128r1_b[]; +extern const Ipp32u secp128r1_gx[]; +extern const Ipp32u secp128r1_gy[]; +extern const Ipp32u secp128r1_r[]; +extern Ipp32u secp128r1_h; + +extern const Ipp32u* secp128_mx[]; + +extern const Ipp32u secp128r2_p[]; // 2^128 -2^97 -1 +extern const Ipp32u secp128r2_a[]; +extern const Ipp32u secp128r2_b[]; +extern const Ipp32u secp128r2_gx[]; +extern const Ipp32u secp128r2_gy[]; +extern const Ipp32u secp128r2_r[]; +extern Ipp32u secp128r2_h; + +extern const Ipp32u secp160r1_p[]; // 2^160 -2^31 -1 +extern const Ipp32u secp160r1_a[]; +extern const Ipp32u secp160r1_b[]; +extern const Ipp32u secp160r1_gx[]; +extern const Ipp32u secp160r1_gy[]; +extern const Ipp32u secp160r1_r[]; +extern Ipp32u secp160r1_h; + +extern const Ipp32u secp160r2_p[]; // 2^160 -2^32 -2^14 -2^12 -2^9 -2^8 -2^7 -2^2 -1 +extern const Ipp32u secp160r2_a[]; +extern const Ipp32u secp160r2_b[]; +extern const Ipp32u secp160r2_gx[]; +extern const Ipp32u secp160r2_gy[]; +extern const Ipp32u secp160r2_r[]; +extern Ipp32u secp160r2_h; + +extern const Ipp32u secp192r1_p[]; // 2^192 -2^64 -1 +extern const Ipp32u secp192r1_a[]; +extern const Ipp32u secp192r1_b[]; +extern const Ipp32u secp192r1_gx[]; +extern const Ipp32u secp192r1_gy[]; +extern const Ipp32u secp192r1_r[]; +extern Ipp32u secp192r1_h; + +extern const Ipp32u secp224r1_p[]; // 2^224 -2^96 +1 +extern const Ipp32u secp224r1_a[]; +extern const Ipp32u secp224r1_b[]; +extern const Ipp32u secp224r1_gx[]; +extern const Ipp32u secp224r1_gy[]; +extern const Ipp32u secp224r1_r[]; +extern Ipp32u secp224r1_h; + +extern const Ipp32u secp256r1_p[]; // 2^256 -2^224 +2^192 +2^96 -1 +extern const Ipp32u secp256r1_a[]; +extern const Ipp32u secp256r1_b[]; +extern const Ipp32u secp256r1_gx[]; +extern const Ipp32u secp256r1_gy[]; +extern const Ipp32u secp256r1_r[]; +extern Ipp32u secp256r1_h; + +extern const Ipp32u secp384r1_p[]; // 2^384 -2^128 -2^96 +2^32 -1 +extern const Ipp32u secp384r1_a[]; +extern const Ipp32u secp384r1_b[]; +extern const Ipp32u secp384r1_gx[]; +extern const Ipp32u secp384r1_gy[]; +extern const Ipp32u secp384r1_r[]; +extern Ipp32u secp384r1_h; + +extern const Ipp32u secp521r1_p[]; // 2^521 -1 +extern const Ipp32u secp521r1_a[]; +extern const Ipp32u secp521r1_b[]; +extern const Ipp32u secp521r1_gx[]; +extern const Ipp32u secp521r1_gy[]; +extern const Ipp32u secp521r1_r[]; +extern Ipp32u secp521r1_h; + +/* half of some std modulus */ +extern const Ipp32u h_secp128r1_p[]; +extern const Ipp32u h_secp192r1_p[]; +extern const Ipp32u h_secp224r1_p[]; +extern const Ipp32u h_secp256r1_p[]; +extern const Ipp32u h_secp384r1_p[]; +extern const Ipp32u h_secp521r1_p[]; + +#endif /* _PCP_ECCP_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpdpca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpdpca.c new file mode 100644 index 0000000000..e4c88689d4 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpdpca.c @@ -0,0 +1,370 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpeccp.h" +#include "pcpeccppoint.h" +#include "pcpbnresource.h" +#include "pcpeccpmethod.h" +#include "pcpeccpmethodcom.h" +#include "pcppma.h" + + +/*F* +// Name: ippsECCPSet +// +// Purpose: Set EC Domain Parameters. +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pPrime +// NULL == pA +// NULL == pB +// NULL == pGX +// NULL == pGY +// NULL == pOrder +// NULL == pECC +// +// ippStsContextMatchErr illegal pPrime->idCtx +// illegal pA->idCtx +// illegal pB->idCtx +// illegal pGX->idCtx +// illegal pGY->idCtx +// illegal pOrder->idCtx +// illegal pECC->idCtx +// +// ippStsRangeErr not enough room for: +// pPrime +// pA, pB, +// pGX,pGY +// pOrder +// +// ippStsRangeErr 0>= cofactor +// +// ippStsNoErr no errors +// +// Parameters: +// pPrime pointer to the prime (specify FG(p)) +// pA pointer to the A coefficient of EC equation +// pB pointer to the B coefficient of EC equation +// pGX,pGY pointer to the Base Point (x and y coordinates) of EC +// pOrder pointer to the Base Point order +// cofactor cofactor value +// pECC pointer to the ECC context +// +*F*/ +static +void ECCPSetDP(IppECCType flag, + int primeSize, const Ipp32u* pPrime, + int aSize, const Ipp32u* pA, + int bSize, const Ipp32u* pB, + int gxSize, const Ipp32u* pGx, + int gySize, const Ipp32u* pGy, + int orderSize, const Ipp32u* pOrder, + Ipp32u cofactor, + IppsECCPState* pECC) +{ + ECP_TYPE(pECC) = flag; + + /* reset size (bits) of field element */ + ECP_GFEBITS(pECC) = cpMSBit_BNU32(pPrime, primeSize) +1; + /* reset size (bits) of Base Point order */ + ECP_ORDBITS(pECC) = cpMSBit_BNU32(pOrder, orderSize) +1; + + /* set up prime */ + ippsSet_BN(ippBigNumPOS, primeSize, pPrime, ECP_PRIME(pECC)); + /* set up A */ + ippsSet_BN(ippBigNumPOS, aSize, pA, ECP_A(pECC)); + /* test A */ + BN_Word(ECP_B(pECC), 3); + PMA_add(ECP_B(pECC), ECP_A(pECC), ECP_B(pECC), ECP_PRIME(pECC)); + ECP_AMI3(pECC) = IsZero_BN(ECP_B(pECC)); + /* set up B */ + ippsSet_BN(ippBigNumPOS, bSize, pB, ECP_B(pECC)); + + /* set up affine coordinates of Base Point and order */ + ippsSet_BN(ippBigNumPOS, gxSize, pGx, ECP_GX(pECC)); + ippsSet_BN(ippBigNumPOS, gySize, pGy, ECP_GY(pECC)); + ippsSet_BN(ippBigNumPOS, orderSize, pOrder, ECP_ORDER(pECC)); + + /* set up cofactor */ + //ippsSet_BN(ippBigNumPOS, 1, &((Ipp32u)cofactor), ECP_COFACTOR(pECC)); + ippsSet_BN(ippBigNumPOS, 1, &cofactor, ECP_COFACTOR(pECC)); + + /* montgomery engine (prime) */ + if( ippStsNoErr == ippsMontSet((Ipp32u*)BN_NUMBER(ECP_PRIME(pECC)), BN_SIZE32(ECP_PRIME(pECC)), ECP_PMONT(pECC)) ) { + /* modulo reduction and montgomery form of A and B */ + PMA_mod(ECP_AENC(pECC), ECP_A(pECC), ECP_PRIME(pECC)); + PMA_enc(ECP_AENC(pECC), ECP_AENC(pECC), ECP_PMONT(pECC)); + PMA_mod(ECP_BENC(pECC), ECP_B(pECC), ECP_PRIME(pECC)); + PMA_enc(ECP_BENC(pECC), ECP_BENC(pECC), ECP_PMONT(pECC)); + /* projective coordinates and montgomery form of of Base Point */ + if( ( IsZero_BN(ECP_BENC(pECC)) && ECCP_IsPointAtAffineInfinity1(ECP_GX(pECC), ECP_GY(pECC))) || + (!IsZero_BN(ECP_BENC(pECC)) && ECCP_IsPointAtAffineInfinity0(ECP_GX(pECC), ECP_GY(pECC))) ) + ECCP_SetPointToInfinity(ECP_GENC(pECC)); + else { + ECP_METHOD(pECC)->SetPointProjective(ECP_GX(pECC), ECP_GY(pECC), BN_ONE_REF(), ECP_GENC(pECC), pECC); + } + } + + /* montgomery engine (order) */ + if( ippStsNoErr == ippsMontSet((Ipp32u*)BN_NUMBER(ECP_ORDER(pECC)), BN_SIZE32(ECP_ORDER(pECC)), ECP_RMONT(pECC)) ) + PMA_enc(ECP_COFACTOR(pECC), ECP_COFACTOR(pECC), ECP_RMONT(pECC)); + + /* set zero private keys */ + BN_Word(ECP_PRIVATE(pECC), 0); + BN_Word(ECP_PRIVATE_E(pECC), 0); + + /* set infinity public keys */ + ECCP_SetPointToInfinity(ECP_PUBLIC(pECC)); + ECCP_SetPointToInfinity(ECP_PUBLIC_E(pECC)); +} + + +IPPFUN(IppStatus, ippsECCPSet, (const IppsBigNumState* pPrime, + const IppsBigNumState* pA, const IppsBigNumState* pB, + const IppsBigNumState* pGX,const IppsBigNumState* pGY,const IppsBigNumState* pOrder, + int cofactor, + IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test pPrime */ + IPP_BAD_PTR1_RET(pPrime); + pPrime = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrime, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pPrime), ippStsContextMatchErr); + IPP_BADARG_RET((cpBN_bitsize(pPrime)>ECP_GFEBITS(pECC)), ippStsRangeErr); + + /* test pA and pB */ + IPP_BAD_PTR2_RET(pA,pB); + pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, ALIGN_VAL) ); + pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); + IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); + IPP_BADARG_RET((cpBN_bitsize(pA)>ECP_GFEBITS(pECC)), ippStsRangeErr); + IPP_BADARG_RET((cpBN_bitsize(pB)>ECP_GFEBITS(pECC)), ippStsRangeErr); + + /* test pG and pGorder pointers */ + IPP_BAD_PTR3_RET(pGX,pGY, pOrder); + pGX = (IppsBigNumState*)( IPP_ALIGNED_PTR(pGX, ALIGN_VAL) ); + pGY = (IppsBigNumState*)( IPP_ALIGNED_PTR(pGY, ALIGN_VAL) ); + pOrder = (IppsBigNumState*)( IPP_ALIGNED_PTR(pOrder, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pGX), ippStsContextMatchErr); + IPP_BADARG_RET(!BN_VALID_ID(pGY), ippStsContextMatchErr); + IPP_BADARG_RET(!BN_VALID_ID(pOrder), ippStsContextMatchErr); + IPP_BADARG_RET((cpBN_bitsize(pGX)>ECP_GFEBITS(pECC)), ippStsRangeErr); + IPP_BADARG_RET((cpBN_bitsize(pGY)>ECP_GFEBITS(pECC)), ippStsRangeErr); + IPP_BADARG_RET((cpBN_bitsize(pOrder)>ECP_ORDBITS(pECC)), ippStsRangeErr); + + /* test cofactor */ + IPP_BADARG_RET(!(0idCtx +// +// ippStsECCInvalidFlagErr invalid flag +// +// ippStsNoErr no errors +// +// Parameters: +// flag specify standard ECC parameter(s) to be setup +// pECC pointer to the ECC context +// +*F*/ +IPPFUN(IppStatus, ippsECCPSetStd, (IppECCType flag, IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + *(ECP_METHOD(pECC)) = *(ECCPcom_Methods()); + + switch(flag) { + case IppECCPStd112r1: + ECCPSetDP(IppECCPStd112r1, + BITS2WORD32_SIZE(112), secp112r1_p, + BITS2WORD32_SIZE(112), secp112r1_a, + BITS2WORD32_SIZE(112), secp112r1_b, + BITS2WORD32_SIZE(112), secp112r1_gx, + BITS2WORD32_SIZE(112), secp112r1_gy, + BITS2WORD32_SIZE(112), secp112r1_r, + secp112r1_h, pECC); + break; + + case IppECCPStd112r2: + ECCPSetDP(IppECCPStd112r2, + BITS2WORD32_SIZE(112), secp112r2_p, + BITS2WORD32_SIZE(112), secp112r2_a, + BITS2WORD32_SIZE(112), secp112r2_b, + BITS2WORD32_SIZE(112), secp112r2_gx, + BITS2WORD32_SIZE(112), secp112r2_gy, + BITS2WORD32_SIZE(112), secp112r2_r, + secp112r2_h, pECC); + break; + + case IppECCPStd128r1: + ECCPSetDP(IppECCPStd128r1, + BITS2WORD32_SIZE(128), secp128r1_p, + BITS2WORD32_SIZE(128), secp128r1_a, + BITS2WORD32_SIZE(128), secp128r1_b, + BITS2WORD32_SIZE(128), secp128r1_gx, + BITS2WORD32_SIZE(128), secp128r1_gy, + BITS2WORD32_SIZE(128), secp128r1_r, + secp128r1_h, pECC); + break; + + case IppECCPStd128r2: + ECCPSetDP(IppECCPStd128r2, + BITS2WORD32_SIZE(128), secp128r2_p, + BITS2WORD32_SIZE(128), secp128r2_a, + BITS2WORD32_SIZE(128), secp128r2_b, + BITS2WORD32_SIZE(128), secp128r2_gx, + BITS2WORD32_SIZE(128), secp128r2_gy, + BITS2WORD32_SIZE(128), secp128r2_r, + secp128r2_h, pECC); + break; + + case IppECCPStd160r1: + ECCPSetDP(IppECCPStd160r1, + BITS2WORD32_SIZE(160), secp160r1_p, + BITS2WORD32_SIZE(160), secp160r1_a, + BITS2WORD32_SIZE(160), secp160r1_b, + BITS2WORD32_SIZE(160), secp160r1_gx, + BITS2WORD32_SIZE(160), secp160r1_gy, + BITS2WORD32_SIZE(161), secp160r1_r, + secp160r1_h, pECC); + break; + + case IppECCPStd160r2: + ECCPSetDP(IppECCPStd160r2, + BITS2WORD32_SIZE(160), secp160r2_p, + BITS2WORD32_SIZE(160), secp160r2_a, + BITS2WORD32_SIZE(160), secp160r2_b, + BITS2WORD32_SIZE(160), secp160r2_gx, + BITS2WORD32_SIZE(160), secp160r2_gy, + BITS2WORD32_SIZE(161), secp160r2_r, + secp160r2_h, pECC); + break; + + case IppECCPStd192r1: + ECCPSetDP(IppECCPStd192r1, + BITS2WORD32_SIZE(192), secp192r1_p, + BITS2WORD32_SIZE(192), secp192r1_a, + BITS2WORD32_SIZE(192), secp192r1_b, + BITS2WORD32_SIZE(192), secp192r1_gx, + BITS2WORD32_SIZE(192), secp192r1_gy, + BITS2WORD32_SIZE(192), secp192r1_r, + secp192r1_h, pECC); + break; + + case IppECCPStd224r1: + ECCPSetDP(IppECCPStd224r1, + BITS2WORD32_SIZE(224), secp224r1_p, + BITS2WORD32_SIZE(224), secp224r1_a, + BITS2WORD32_SIZE(224), secp224r1_b, + BITS2WORD32_SIZE(224), secp224r1_gx, + BITS2WORD32_SIZE(224), secp224r1_gy, + BITS2WORD32_SIZE(224), secp224r1_r, + secp224r1_h, pECC); + break; + + case IppECCPStd256r1: + ECCPSetDP(IppECCPStd256r1, + BITS2WORD32_SIZE(256), secp256r1_p, + BITS2WORD32_SIZE(256), secp256r1_a, + BITS2WORD32_SIZE(256), secp256r1_b, + BITS2WORD32_SIZE(256), secp256r1_gx, + BITS2WORD32_SIZE(256), secp256r1_gy, + BITS2WORD32_SIZE(256), secp256r1_r, + secp256r1_h, pECC); + break; + + case IppECCPStd384r1: + ECCPSetDP(IppECCPStd384r1, + BITS2WORD32_SIZE(384), secp384r1_p, + BITS2WORD32_SIZE(384), secp384r1_a, + BITS2WORD32_SIZE(384), secp384r1_b, + BITS2WORD32_SIZE(384), secp384r1_gx, + BITS2WORD32_SIZE(384), secp384r1_gy, + BITS2WORD32_SIZE(384), secp384r1_r, + secp384r1_h, pECC); + break; + + case IppECCPStd521r1: + ECCPSetDP(IppECCPStd521r1, + BITS2WORD32_SIZE(521), secp521r1_p, + BITS2WORD32_SIZE(521), secp521r1_a, + BITS2WORD32_SIZE(521), secp521r1_b, + BITS2WORD32_SIZE(521), secp521r1_gx, + BITS2WORD32_SIZE(521), secp521r1_gy, + BITS2WORD32_SIZE(521), secp521r1_r, + secp521r1_h, pECC); + break; + + default: + return ippStsECCInvalidFlagErr; + } + + return ippStsNoErr; +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpgenkeyca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpgenkeyca.c new file mode 100644 index 0000000000..b152a7b82c --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpgenkeyca.c @@ -0,0 +1,107 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpeccppoint.h" +#include "pcpeccpmethod.h" +#include "pcpeccpmethodcom.h" + + +/*F* +// Name: ippsECCPGenKeyPair +// +// Purpose: Generate (private,public) Key Pair +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pECC +// NULL == pPrivate +// NULL == pPublic +// +// ippStsContextMatchErr illegal pECC->idCtx +// illegal pPrivate->idCtx +// illegal pPublic->idCtx +// +// ippStsNoErr no errors +// +// Parameters: +// pPrivate pointer to the resultant private key +// pPublic pointer to the resultant public key +// pECC pointer to the ECCP context +// +*F*/ +IPPFUN(IppStatus, ippsECCPGenKeyPair, (IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, + IppsECCPState* pECC, + IppBitSupplier rndFunc, void* pRndParam)) +{ + IPP_BAD_PTR2_RET(pECC, rndFunc); + + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test private/public keys */ + IPP_BAD_PTR2_RET(pPrivate,pPublic); + pPrivate = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrivate, ALIGN_VAL) ); + pPublic = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPublic, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pPrivate), ippStsContextMatchErr); + IPP_BADARG_RET((BN_ROOM(pPrivate)*BITSIZE(BNU_CHUNK_T)MulBasePoint(pPrivate, pPublic, pECC, ECP_BNCTX(pECC)); + + return ippStsNoErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpinitca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpinitca.c new file mode 100644 index 0000000000..ee54bb844b --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpinitca.c @@ -0,0 +1,305 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpeccp.h" +#include "pcpeccppoint.h" +#include "pcpbnresource.h" +#include "pcpeccpmethod.h" +#include "pcpeccpsscm.h" +#include "pcptool.h" + + +/*F* +// Name: ippsECCPGetSize +// +// Purpose: Returns size of ECC context (bytes). +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pSize +// +// ippStsSizeErr 2>feBitSize +// +// ippStsNoErr no errors +// +// Parameters: +// feBitSize size of field element (bits) +// pSize pointer to the size of internal ECC context +// +*F*/ +IPPFUN(IppStatus, ippsECCPGetSize, (int feBitSize, int *pSize)) +{ + /* test size's pointer */ + IPP_BAD_PTR1_RET(pSize); + + /* test size of field element */ + IPP_BADARG_RET((2>feBitSize || feBitSize>EC_GFP_MAXBITSIZE), ippStsSizeErr); + + { + int bn1Size; + int bn2Size; + int pointSize; + int mont1Size; + int mont2Size; + int primeSize; + int listSize; + + /* size of field element */ + int gfeSize = BITS2WORD32_SIZE(feBitSize); + /* size of order */ + int ordSize = BITS2WORD32_SIZE(feBitSize+1); + + /* size of sscm buffer */ + int w = cpECCP_OptimalWinSize(feBitSize+1); + int nPrecomputed = 1<feBitSize +// +// ippStsNoErr no errors +// +// Parameters: +// feBitSize size of field element (bits) +// pECC pointer to the ECC context +// +*F*/ +IPPFUN(IppStatus, ippsECCPInit, (int feBitSize, IppsECCPState* pECC)) +{ + /* test pECC pointer */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + + /* test size of field element */ + IPP_BADARG_RET((2>feBitSize || feBitSize>EC_GFP_MAXBITSIZE), ippStsSizeErr); + + /* clear context */ + PaddBlock(0, pECC, sizeof(IppsECCPState)); + + /* context ID */ + ECP_ID(pECC) = idCtxECCP; + + /* generic EC */ + ECP_TYPE(pECC) = IppECCArbitrary; + + /* size of field element & BP order */ + ECP_GFEBITS(pECC) = feBitSize; + ECP_ORDBITS(pECC) = feBitSize+1; + + /* + // init other context fields + */ + { + int bn1Size; + int bn2Size; + int pointSize; + int mont1Size; + int mont2Size; + int primeSize; + + /* size of field element */ + int gfeSize = BITS2WORD32_SIZE(feBitSize); + /* size of order */ + int ordSize = BITS2WORD32_SIZE(feBitSize+1); + + /* size of sscm buffer */ + int w = cpECCP_OptimalWinSize(feBitSize+1); + int nPrecomputed = 1< pP==pQ (maybe both pP and pQ are at Infinity) +// returns 1 => pP!=pQ +// +// Note +// In general we check: +// P_X*Q_Z^2 ~ Q_X*P_Z^2 +// P_Y*Q_Z^3 ~ Q_Y*P_Z^3 +*/ +int ECCP_ComparePoint(const IppsECCPPointState* pP, + const IppsECCPPointState* pQ, + const IppsECCPState* pECC, + BigNumNode* pList) +{ + /* P or/and Q at Infinity */ + if( ECCP_IsPointAtInfinity(pP) ) + return ECCP_IsPointAtInfinity(pQ)? 0:1; + if( ECCP_IsPointAtInfinity(pQ) ) + return ECCP_IsPointAtInfinity(pP)? 0:1; + + /* (P_Z==1) && (Q_Z==1) */ + if( ECP_POINT_AFFINE(pP) && ECP_POINT_AFFINE(pQ) ) + return ((0==cpBN_cmp(ECP_POINT_X(pP),ECP_POINT_X(pQ))) && (0==cpBN_cmp(ECP_POINT_Y(pP),ECP_POINT_Y(pQ))))? 0:1; + + { + IppsMontState* pMont = ECP_PMONT(pECC); + + IppsBigNumState* pPtmp = cpBigNumListGet(&pList); + IppsBigNumState* pQtmp = cpBigNumListGet(&pList); + IppsBigNumState* pPZ = cpBigNumListGet(&pList); + IppsBigNumState* pQZ = cpBigNumListGet(&pList); + + /* P_X*Q_Z^2 ~ Q_X*P_Z^2 */ + if( !ECP_POINT_AFFINE(pQ) ) { + PMA_sqre(pQZ, ECP_POINT_Z(pQ), pMont); /* Ptmp = P_X*Q_Z^2 */ + PMA_mule(pPtmp, ECP_POINT_X(pP), pQZ, pMont); + } + else { + PMA_set(pPtmp, ECP_POINT_X(pP)); + } + if( !ECP_POINT_AFFINE(pP) ) { + PMA_sqre(pPZ, ECP_POINT_Z(pP), pMont); /* Qtmp = Q_X*P_Z^2 */ + PMA_mule(pQtmp, ECP_POINT_X(pQ), pPZ, pMont); + } + else { + PMA_set(pQtmp, ECP_POINT_X(pQ)); + } + if ( cpBN_cmp(pPtmp, pQtmp) ) + return 1; /* points are different: (P_X*Q_Z^2) != (Q_X*P_Z^2) */ + + /* P_Y*Q_Z^3 ~ Q_Y*P_Z^3 */ + if( !ECP_POINT_AFFINE(pQ) ) { + PMA_mule(pQZ, pQZ, ECP_POINT_Z(pQ), pMont); /* Ptmp = P_Y*Q_Z^3 */ + PMA_mule(pPtmp, ECP_POINT_Y(pP), pQZ, pMont); + } + else { + PMA_set(pPtmp, ECP_POINT_Y(pP)); + } + if( !ECP_POINT_AFFINE(pP) ) { + PMA_mule(pPZ, pPZ, ECP_POINT_Z(pP), pMont); /* Qtmp = Q_Y*P_Z^3 */ + PMA_mule(pQtmp, ECP_POINT_Y(pQ), pPZ, pMont); + } + else { + PMA_set(pQtmp, ECP_POINT_Y(pQ)); + } + return cpBN_cmp(pPtmp, pQtmp)? 1:0; + } +} + +/* +// ECCP_NegPoint +// +// Negative point +*/ +void ECCP_NegPoint(const IppsECCPPointState* pP, + IppsECCPPointState* pR, + const IppsECCPState* pECC) +{ + /* test point at Infinity */ + if( ECCP_IsPointAtInfinity(pP) ) + ECCP_SetPointToInfinity(pR); + + else { + IppsBigNumState* pModulo = ECP_PRIME(pECC); + + if( pP!=pR ) { + PMA_set(ECP_POINT_X(pR), ECP_POINT_X(pP)); + PMA_set(ECP_POINT_Z(pR), ECP_POINT_Z(pP)); + } + PMA_sub(ECP_POINT_Y(pR), pModulo, ECP_POINT_Y(pP), pModulo); + ECP_POINT_AFFINE(pR) = ECP_POINT_AFFINE(pP); + } +} + +/* +// ECCP_DblPoint +// +// Double point +*/ +void ECCP_DblPoint(const IppsECCPPointState* pP, + IppsECCPPointState* pR, + const IppsECCPState* pECC, + BigNumNode* pList) +{ + /* P at infinity */ + if( ECCP_IsPointAtInfinity(pP) ) + ECCP_SetPointToInfinity(pR); + + else { + IppsMontState* pMont = ECP_PMONT(pECC); + + IppsBigNumState* bnV = cpBigNumListGet(&pList); + IppsBigNumState* bnU = cpBigNumListGet(&pList); + IppsBigNumState* bnM = cpBigNumListGet(&pList); + IppsBigNumState* bnS = cpBigNumListGet(&pList); + IppsBigNumState* bnT = cpBigNumListGet(&pList); + IppsBigNumState* pModulo = ECP_PRIME(pECC); + + /* M = 3*X^2 + A*Z^4 */ + if( ECP_POINT_AFFINE(pP) ) { + PMA_sqre(bnU, ECP_POINT_X(pP), pMont); + PMA_add(bnM, bnU, bnU, pModulo); + PMA_add(bnM, bnM, bnU, pModulo); + PMA_add(bnM, bnM, ECP_AENC(pECC), pModulo); + } + else if( ECP_AMI3(pECC) ) { + PMA_sqre(bnU, ECP_POINT_Z(pP), pMont); + PMA_add(bnS, ECP_POINT_X(pP), bnU, pModulo); + PMA_sub(bnT, ECP_POINT_X(pP), bnU, pModulo); + PMA_mule(bnM, bnS, bnT, pMont); + PMA_add(bnU, bnM, bnM, pModulo); + PMA_add(bnM, bnU, bnM, pModulo); + } + else { + PMA_sqre(bnU, ECP_POINT_X(pP), pMont); + PMA_add(bnM, bnU, bnU, pModulo); + PMA_add(bnM, bnM, bnU, pModulo); + PMA_sqre(bnU, ECP_POINT_Z(pP), pMont); + PMA_sqre(bnU, bnU, pMont); + PMA_mule(bnU, bnU, ECP_AENC(pECC), pMont); + PMA_add(bnM, bnM, bnU, pModulo); + } + + PMA_add(bnV, ECP_POINT_Y(pP), ECP_POINT_Y(pP), pModulo); + + /* R_Z = 2*Y*Z */ + if( ECP_POINT_AFFINE(pP) ) { + PMA_set(ECP_POINT_Z(pR), bnV); + } + else { + PMA_mule(ECP_POINT_Z(pR), bnV, ECP_POINT_Z(pP), pMont); + } + + /* S = 4*X*Y^2 */ + PMA_sqre(bnT, bnV, pMont); + PMA_mule(bnS, bnT, ECP_POINT_X(pP), pMont); + + /* R_X = M^2 - 2*S */ + PMA_sqre(bnU, bnM, pMont); + PMA_sub(bnU, bnU, bnS, pModulo); + PMA_sub(ECP_POINT_X(pR), bnU, bnS, pModulo); + + /* T = 8*Y^4 */ + PMA_mule(bnV, bnV, ECP_POINT_Y(pP), pMont); + PMA_mule(bnT, bnT, bnV, pMont); + + /* R_Y = M*(S - R_X) - T */ + PMA_sub(bnS, bnS, ECP_POINT_X(pR), pModulo); + PMA_mule(bnS, bnS, bnM, pMont); + PMA_sub(ECP_POINT_Y(pR), bnS, bnT, pModulo); + + ECP_POINT_AFFINE(pR) = 0; + } +} + +/* +// ECCP_AddPoint +// +// Add points +*/ +void ECCP_AddPoint(const IppsECCPPointState* pP, + const IppsECCPPointState* pQ, + IppsECCPPointState* pR, + const IppsECCPState* pECC, + BigNumNode* pList) +{ + /* prevent operation with point at Infinity */ + if( ECCP_IsPointAtInfinity(pP) ) { + ECCP_CopyPoint(pQ, pR); + return; + } + if( ECCP_IsPointAtInfinity(pQ) ) { + ECCP_CopyPoint(pP, pR); + return; + } + + /* + // addition + */ + { + IppsMontState* pMont = ECP_PMONT(pECC); + + IppsBigNumState* bnU0 = cpBigNumListGet(&pList); + IppsBigNumState* bnS0 = cpBigNumListGet(&pList); + IppsBigNumState* bnU1 = cpBigNumListGet(&pList); + IppsBigNumState* bnS1 = cpBigNumListGet(&pList); + IppsBigNumState* bnW = cpBigNumListGet(&pList); + IppsBigNumState* bnR = cpBigNumListGet(&pList); + IppsBigNumState *bnT = bnU0; + IppsBigNumState *bnM = bnS0; + IppsBigNumState* pModulo = ECP_PRIME(pECC); + + /* U0 = P_X * Q_Z^2 */ + /* S0 = P_Y * Q_Z^3 */ + if( ECP_POINT_AFFINE(pQ) ) { + PMA_set(bnU0, ECP_POINT_X(pP)); + PMA_set(bnS0, ECP_POINT_Y(pP)); + } + else { + PMA_sqre(bnW, ECP_POINT_Z(pQ), pMont); + PMA_mule(bnU0,ECP_POINT_X(pP), bnW, pMont); + PMA_mule(bnW, ECP_POINT_Z(pQ), bnW, pMont); + PMA_mule(bnS0,ECP_POINT_Y(pP), bnW, pMont); + } + + /* U1 = Q_X * P_Z^2 */ + /* S1 = Q_Y * P_Z^3 */ + if( ECP_POINT_AFFINE(pP) ) { + PMA_set(bnU1, ECP_POINT_X(pQ)); + PMA_set(bnS1, ECP_POINT_Y(pQ)); + } + else { + PMA_sqre(bnW, ECP_POINT_Z(pP), pMont); + PMA_mule(bnU1,ECP_POINT_X(pQ), bnW, pMont); + PMA_mule(bnW, ECP_POINT_Z(pP), bnW, pMont); + PMA_mule(bnS1,ECP_POINT_Y(pQ), bnW, pMont); + } + + /* W = U0-U1 */ + /* R = S0-S1 */ + PMA_sub(bnW, bnU0, bnU1, pModulo); + PMA_sub(bnR, bnS0, bnS1, pModulo); + + if( IsZero_BN(bnW) ) { + if( IsZero_BN(bnR) ) { + ECCP_DblPoint(pP, pR, pECC, pList); + return; + } + else { + ECCP_SetPointToInfinity(pR); + return; + } + } + + /* T = U0+U1 */ + /* M = S0+S1 */ + PMA_add(bnT, bnU0, bnU1, pModulo); + PMA_add(bnM, bnS0, bnS1, pModulo); + + /* R_Z = P_Z * Q_Z * W */ + if( ECP_POINT_AFFINE(pQ) && ECP_POINT_AFFINE(pP) ) { + PMA_set(ECP_POINT_Z(pR), bnW); + } + else { + if( ECP_POINT_AFFINE(pQ) ) { + PMA_set(bnU1, ECP_POINT_Z(pP)); + } + else if( ECP_POINT_AFFINE(pP) ) { + PMA_set(bnU1, ECP_POINT_Z(pQ)); + } + else { + PMA_mule(bnU1, ECP_POINT_Z(pP), ECP_POINT_Z(pQ), pMont); + } + PMA_mule(ECP_POINT_Z(pR), bnU1, bnW, pMont); + } + + PMA_sqre(bnU1, bnW, pMont); /* U1 = W^2 */ + PMA_mule(bnS1, bnT, bnU1, pMont); /* S1 = T * W^2 */ + + /* R_X = R^2 - T * W^2 */ + PMA_sqre(ECP_POINT_X(pR), bnR, pMont); + PMA_sub(ECP_POINT_X(pR), ECP_POINT_X(pR), bnS1, pModulo); + + /* V = T * W^2 - 2 * R_X (S1) */ + PMA_sub(bnS1, bnS1, ECP_POINT_X(pR), pModulo); + PMA_sub(bnS1, bnS1, ECP_POINT_X(pR), pModulo); + + /* R_Y = (V * R - M * W^3) /2 */ + PMA_mule(ECP_POINT_Y(pR), bnS1, bnR, pMont); + PMA_mule(bnU1, bnU1, bnW, pMont); + PMA_mule(bnU1, bnU1, bnM, pMont); + PMA_sub(bnU1, ECP_POINT_Y(pR), bnU1, pModulo); + PMA_div2(ECP_POINT_Y(pR), bnU1, pModulo); + + ECP_POINT_AFFINE(pR) = 0; + } +} + +/* +// ECCP_MulPoint +// +// Multiply point by scalar +*/ +void ECCP_MulPoint(const IppsECCPPointState* pP, + const IppsBigNumState* bnN, + IppsECCPPointState* pR, + const IppsECCPState* pECC, + BigNumNode* pList) +{ + /* test zero scalar or input point at Infinity */ + if( IsZero_BN(bnN) || ECCP_IsPointAtInfinity(pP) ) { + ECCP_SetPointToInfinity(pR); + return; + } + + /* + // scalar multiplication + */ + else { + Ipp8u* pScratchAligned = ECP_SCCMBUFF(pECC); + + BNU_CHUNK_T* pN = BN_NUMBER(bnN); + cpSize nsN = BN_SIZE(bnN); + /* scalar bitsize */ + int scalarBitSize = BITSIZE_BNU(pN, nsN); + /* optimal size of window */ + int w = cpECCP_OptimalWinSize(scalarBitSize); + /* number of table entries */ + int nPrecomputed = 1<>shift) & dmask; + + /* initialize result (ECP_FINITE_POINT|ECP_PROJECTIVE) */ + cpECCP_ScrambleGet(pR, coordSize, pScratchAligned+windowVal, nPrecomputed); + ECP_POINT_AFFINE(pR) = 0; + + /* initialize temporary T (ECP_PROJECTIVE) */ + ECP_POINT_AFFINE(&T) = 0; + + for(wPosition-=w; wPosition>=0; wPosition-=w) { + /* w times doubling */ + int k; + for(k=0; k>shift) & dmask; + + /* extract value from the pre-computed table */ + cpECCP_ScrambleGet(&T, coordSize, pScratchAligned+windowVal, nPrecomputed); + + /* and add it */ + ECCP_AddPoint(pR, &T, pR, pECC, pList); + } + } + } +} + + +void ECCP_MulBasePoint(const IppsBigNumState* pK, + IppsECCPPointState* pR, + const IppsECCPState* pECC, + BigNumNode* pList) +{ + ECCP_MulPoint(ECP_GENC(pECC), pK, pR, pECC, pList); +} + +/* +// ECCP_ProdPoint +// +// Point product +*/ +void ECCP_ProdPoint(const IppsECCPPointState* pP, + const IppsBigNumState* bnPscalar, + const IppsECCPPointState* pQ, + const IppsBigNumState* bnQscalar, + IppsECCPPointState* pR, + const IppsECCPState* pECC, + BigNumNode* pList) +{ + IppsECCPPointState T; + IppsECCPPointState U; + + ECP_POINT_X(&T) = cpBigNumListGet(&pList); + ECP_POINT_Y(&T) = cpBigNumListGet(&pList); + ECP_POINT_Z(&T) = cpBigNumListGet(&pList); + + ECP_POINT_X(&U) = cpBigNumListGet(&pList); + ECP_POINT_Y(&U) = cpBigNumListGet(&pList); + ECP_POINT_Z(&U) = cpBigNumListGet(&pList); + + ECCP_MulPoint(pP, bnPscalar, &T, (IppsECCPState*)pECC, pList); + ECCP_MulPoint(pQ, bnQscalar, &U, (IppsECCPState*)pECC, pList); + ECCP_AddPoint(&T, &U, pR, pECC, pList); +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccppoint.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccppoint.h new file mode 100644 index 0000000000..a72b0ea1ef --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccppoint.h @@ -0,0 +1,60 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_PCP_ECCPPOINT_H) +#define _PCP_ECCPPOINT_H + +#include "pcpeccp.h" + + +/* +// EC Point context +*/ +struct _cpECCPPoint { + IppCtxId idCtx; /* EC Point identifier */ + + IppsBigNumState* pX; /* projective X */ + IppsBigNumState* pY; /* Y */ + IppsBigNumState* pZ; /* Z coordinates */ + int affine; /* impotrant case Z=1 */ +}; + +/* +// Contetx Access Macros +*/ +#define ECP_POINT_ID(ctx) ((ctx)->idCtx) +#define ECP_POINT_X(ctx) ((ctx)->pX) +#define ECP_POINT_Y(ctx) ((ctx)->pY) +#define ECP_POINT_Z(ctx) ((ctx)->pZ) +#define ECP_POINT_AFFINE(ctx) ((ctx)->affine) +#define ECP_POINT_VALID_ID(ctx) (ECP_POINT_ID((ctx))==idCtxECCPPoint) + +#endif /* _PCP_ECCPPOINT_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccppointca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccppointca.c new file mode 100644 index 0000000000..04dd7ca4a7 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccppointca.c @@ -0,0 +1,128 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpeccppoint.h" + + +/*F* +// Name: ippsECCPPointGetSize +// +// Purpose: Returns size of EC Point context (bytes). +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pSzie +// ippStsSizeErr 2>feBitSize +// ippStsNoErr no errors +// +// Parameters: +// feBitSize size of field element (bits) +// pSize pointer to the size of EC Point context +// +*F*/ +IPPFUN(IppStatus, ippsECCPPointGetSize, (int feBitSize, int* pSize)) +{ + /* test size's pointer */ + IPP_BAD_PTR1_RET(pSize); + + /* test size of field element */ + IPP_BADARG_RET((2>feBitSize), ippStsSizeErr); + + { + int bnSize; + ippsBigNumGetSize(BITS2WORD32_SIZE(feBitSize), &bnSize); + *pSize = sizeof(IppsECCPPointState) + + bnSize /* X coodinate */ + + bnSize /* Y coodinate */ + + bnSize /* Z coodinate */ + +(ALIGN_VAL-1); + } + return ippStsNoErr; +} + + +/*F* +// Name: ippsECCPPointInit +// +// Purpose: Init EC Point context. +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pPoint +// ippStsSizeErr 2>feBitSize +// ippStsNoErr no errors +// +// Parameters: +// feBitSize size of field element (bits) +// pECC pointer to ECC context +// +*F*/ +IPPFUN(IppStatus, ippsECCPPointInit, (int feBitSize, IppsECCPPointState* pPoint)) +{ + /* test pEC pointer */ + IPP_BAD_PTR1_RET(pPoint); + + /* use aligned context */ + pPoint = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPoint, ALIGN_VAL) ); + + /* test size of field element */ + IPP_BADARG_RET((2>feBitSize), ippStsSizeErr); + + /* context ID */ + ECP_POINT_ID(pPoint) = idCtxECCPPoint; + + /* meaning: point was not set */ + ECP_POINT_AFFINE(pPoint) =-1; + + /* + // init other context fields + */ + { + Ipp8u* ptr = (Ipp8u*)pPoint; + int bnLen = BITS2WORD32_SIZE(feBitSize); + int bnSize; + ippsBigNumGetSize(bnLen, &bnSize); + + /* allocate coordinate buffers */ + ptr += sizeof(IppsECCPPointState); + ECP_POINT_X(pPoint) = (IppsBigNumState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) ); + ptr += bnSize; + ECP_POINT_Y(pPoint) = (IppsBigNumState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) ); + ptr += bnSize; + ECP_POINT_Z(pPoint) = (IppsBigNumState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) ); + + /* init coordinate buffers */ + ippsBigNumInit(bnLen, ECP_POINT_X(pPoint)); + ippsBigNumInit(bnLen, ECP_POINT_Y(pPoint)); + ippsBigNumInit(bnLen, ECP_POINT_Z(pPoint)); + } + return ippStsNoErr; +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccppointopca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccppointopca.c new file mode 100644 index 0000000000..df81d08f93 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccppointopca.c @@ -0,0 +1,476 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpeccppoint.h" +#include "pcpeccpmethod.h" +#include "pcpeccpmethodcom.h" + + +/*F* +// Name: ippsECCPSetPoint +// +// Purpose: Converts regular affine coordinates EC point (pX,pY) +// into internal presentation - montgomery projective. +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pECC +// NULL == pPoint +// NULL == pX +// NULL == pY +// +// ippStsContextMatchErr illegal pECC->idCtx +// illegal pX->idCtx +// illegal pY->idCtx +// illegal pPoint->idCtx +// +// ippStsOutOfECErr point out-of EC +// +// ippStsNoErr no errors +// +// Parameters: +// pX pointer to the regular affine coordinate X +// pY pointer to the regular affine coordinate Y +// pPoint pointer to the EC Point context +// pECC pointer to the ECCP context +// +// Note: +// if B==0 and (x,y)=(0,y) then point at Infinity will be set up +// if B!=0 and (x,y)=(0,0) then point at Infinity will be set up +// else point with requested coordinates (x,y) wil be set up +// There are no check validation inside! +// +*F*/ +IPPFUN(IppStatus, ippsECCPSetPoint,(const IppsBigNumState* pX, + const IppsBigNumState* pY, + IppsECCPPointState* pPoint, + IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test pX and pY */ + IPP_BAD_PTR2_RET(pX,pY); + pX = (IppsBigNumState*)( IPP_ALIGNED_PTR(pX, ALIGN_VAL) ); + pY = (IppsBigNumState*)( IPP_ALIGNED_PTR(pY, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pX), ippStsContextMatchErr); + IPP_BADARG_RET(!BN_VALID_ID(pY), ippStsContextMatchErr); + + /* test pPoint */ + IPP_BAD_PTR1_RET(pPoint); + pPoint = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPoint, ALIGN_VAL) ); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPoint), ippStsContextMatchErr); + + /* set affine coordinates at Infinity */ + if( ( IsZero_BN(ECP_BENC(pECC)) && ECCP_IsPointAtAffineInfinity1(pX,pY)) || + (!IsZero_BN(ECP_BENC(pECC)) && ECCP_IsPointAtAffineInfinity0(pX,pY)) ) + ECCP_SetPointToInfinity(pPoint); + /* set point */ + else { + ECP_METHOD(pECC)->SetPointProjective(pX, pY, BN_ONE_REF(), pPoint, pECC); + } + + return ippStsNoErr; +} + + +/*F* +// Name: ippsECCPSetPointAtInfinity +// +// Purpose: Set point at Infinity +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pECC +// NULL == pPoint +// +// ippStsContextMatchErr illegal pECC->idCtx +// illegal pPoint->idCtx +// +// ippStsNoErr no errors +// +// Parameters: +// pPoint pointer to the EC Point context +// pECC pointer to the ECCP context +// +*F*/ +IPPFUN(IppStatus, ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, + IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test pPoint */ + IPP_BAD_PTR1_RET(pPoint); + pPoint = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPoint, ALIGN_VAL) ); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPoint), ippStsContextMatchErr); + + ECCP_SetPointToInfinity(pPoint); + return ippStsNoErr; +} + + +/*F* +// Name: ippsECCPGetPoint +// +// Purpose: Converts internal presentation EC point - montgomery projective +// into regular affine coordinates EC point (pX,pY) +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pECC +// NULL == pPoint +// +// ippStsContextMatchErr illegal pECC->idCtx +// illegal pPoint->idCtx +// NULL != pX, illegal pX->idCtx +// NULL != pY, illegal pY->idCtx +// +// ippStsNoErr no errors +// +// Parameters: +// pX pointer to the regular affine coordinate X +// pY pointer to the regular affine coordinate Y +// pLength pointer to the length of coordinates +// pPoint pointer to the EC Point context +// pECC pointer to the ECCP context +// +*F*/ +IPPFUN(IppStatus, ippsECCPGetPoint,(IppsBigNumState* pX, + IppsBigNumState* pY, + const IppsECCPPointState* pPoint, + IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test source point */ + IPP_BAD_PTR1_RET(pPoint); + pPoint = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPoint, ALIGN_VAL) ); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPoint), ippStsContextMatchErr); + + /* test pX and pY */ + if(pX) { + pX = (IppsBigNumState*)( IPP_ALIGNED_PTR(pX, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pX), ippStsContextMatchErr); + } + if(pY) { + pY = (IppsBigNumState*)( IPP_ALIGNED_PTR(pY, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pY), ippStsContextMatchErr); + } + + if( ECCP_IsPointAtInfinity(pPoint) ) { + if( IsZero_BN(ECP_BENC(pECC)) ) + ECCP_SetPointToAffineInfinity1(pX, pY); + else + ECCP_SetPointToAffineInfinity0(pX, pY); + } + else + ECP_METHOD(pECC)->GetPointAffine(pX, pY, pPoint, pECC, ECP_BNCTX(pECC)); + return ippStsNoErr; +} + + +/*F* +// Name: ippsECCPCheckPoint +// +// Purpose: Check EC point: +// - is point lie on EC +// - is point at infinity +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pECC +// NULL == pP +// NULL == pResult +// +// ippStsContextMatchErr illegal pECC->idCtx +// illegal pP->idCtx +// +// ippStsNoErr no errors +// +// Parameters: +// pPoint pointer to the EC Point context +// pECC pointer to the ECCP context +// pResult pointer to the result: +// ippECValid +// ippECPointIsNotValid +// ippECPointIsAtInfinite +// +*F*/ +IPPFUN(IppStatus, ippsECCPCheckPoint,(const IppsECCPPointState* pP, + IppECResult* pResult, + IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test point */ + IPP_BAD_PTR1_RET(pP); + pP = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pP, ALIGN_VAL) ); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pP), ippStsContextMatchErr); + + /* test pResult */ + IPP_BAD_PTR1_RET(pResult); + + if( ECCP_IsPointAtInfinity(pP) ) + *pResult = ippECPointIsAtInfinite; + else if( ECP_METHOD(pECC)->IsPointOnCurve(pP, pECC, ECP_BNCTX(pECC)) ) + *pResult = ippECValid; + else + *pResult = ippECPointIsNotValid; + + return ippStsNoErr; +} + + +/*F* +// Name: ippsECCPComparePoint +// +// Purpose: Compare two EC points +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pECC +// NULL == pP +// NULL == pQ +// NULL == pResult +// +// ippStsContextMatchErr illegal pECC->idCtx +// illegal pP->idCtx +// illegal pQ->idCtx +// +// ippStsNoErr no errors +// +// Parameters: +// pP pointer to the EC Point context +// pQ pointer to the EC Point context +// pECC pointer to the ECCP context +// pResult pointer to the result: +// ippECPointIsEqual +// ippECPointIsNotEqual +// +*F*/ +IPPFUN(IppStatus, ippsECCPComparePoint,(const IppsECCPPointState* pP, + const IppsECCPPointState* pQ, + IppECResult* pResult, + IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test points */ + IPP_BAD_PTR2_RET(pP,pQ); + pP = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pP, ALIGN_VAL) ); + pQ = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pQ, ALIGN_VAL) ); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pP), ippStsContextMatchErr); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pQ), ippStsContextMatchErr); + + /* test pResult */ + IPP_BAD_PTR1_RET(pResult); + + *pResult = ECP_METHOD(pECC)->ComparePoint(pP, pQ, pECC, ECP_BNCTX(pECC))? ippECPointIsNotEqual : ippECPointIsEqual; + + return ippStsNoErr; +} + + +/*F* +// Name: ippsECCPNegativePoint +// +// Purpose: Perforn EC point operation: R = -P +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pECC +// NULL == pP +// NULL == pR +// +// ippStsContextMatchErr illegal pECC->idCtx +// illegal pP->idCtx +// illegal pR->idCtx +// +// ippStsNoErr no errors +// +// Parameters: +// pP pointer to the source EC Point context +// pR pointer to the resultant EC Point context +// pECC pointer to the ECCP context +// +*F*/ +IPPFUN(IppStatus, ippsECCPNegativePoint, (const IppsECCPPointState* pP, + IppsECCPPointState* pR, + IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test points */ + IPP_BAD_PTR2_RET(pP,pR); + pP = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pP, ALIGN_VAL) ); + pR = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pR, ALIGN_VAL) ); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pP), ippStsContextMatchErr); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pR), ippStsContextMatchErr); + + ECP_METHOD(pECC)->NegPoint(pP, pR, pECC); + + return ippStsNoErr; +} + + +/*F* +// Name: ippsECCPAddPoint +// +// Purpose: Perforn EC point operation: R = P+Q +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pECC +// NULL == pP +// NULL == pQ +// NULL == pR +// +// ippStsContextMatchErr illegal pECC->idCtx +// illegal pP->idCtx +// illegal pQ->idCtx +// illegal pR->idCtx +// +// ippStsNoErr no errors +// +// Parameters: +// pP pointer to the source EC Point context +// pQ pointer to the source EC Point context +// pR pointer to the resultant EC Point context +// pECC pointer to the ECCP context +// +*F*/ +IPPFUN(IppStatus, ippsECCPAddPoint,(const IppsECCPPointState* pP, + const IppsECCPPointState* pQ, + IppsECCPPointState* pR, + IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test points */ + IPP_BAD_PTR3_RET(pP,pQ,pR); + pP = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pP, ALIGN_VAL) ); + pQ = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pQ, ALIGN_VAL) ); + pR = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pR, ALIGN_VAL) ); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pP), ippStsContextMatchErr); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pQ), ippStsContextMatchErr); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pR), ippStsContextMatchErr); + + if(pP==pQ) + ECP_METHOD(pECC)->DblPoint(pP, pR, pECC, ECP_BNCTX(pECC)); + else + ECP_METHOD(pECC)->AddPoint(pP, pQ, pR, pECC, ECP_BNCTX(pECC)); + + return ippStsNoErr; +} + + +/*F* +// Name: ippsECCPMulPointScalar +// +// Purpose: Perforn EC point operation: R = k*P +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pECC +// NULL == pP +// NULL == pK +// NULL == pR +// +// ippStsContextMatchErr illegal pECC->idCtx +// illegal pP->idCtx +// illegal pK->idCtx +// illegal pR->idCtx +// +// ippStsNoErr no errors +// +// Parameters: +// pP pointer to the source EC Point context +// pK pointer to the source BigNum multiplier context +// pR pointer to the resultant EC Point context +// pECC pointer to the ECCP context +// +*F*/ +IPPFUN(IppStatus, ippsECCPMulPointScalar,(const IppsECCPPointState* pP, + const IppsBigNumState* pK, + IppsECCPPointState* pR, + IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test points */ + IPP_BAD_PTR2_RET(pP,pR); + pP = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pP, ALIGN_VAL) ); + pR = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pR, ALIGN_VAL) ); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pP), ippStsContextMatchErr); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pR), ippStsContextMatchErr); + + /* test scalar */ + IPP_BAD_PTR1_RET(pK); + pK = (IppsBigNumState*)( IPP_ALIGNED_PTR(pK, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pK), ippStsContextMatchErr); + + ECP_METHOD(pECC)->MulPoint(pP, pK, pR, pECC, ECP_BNCTX(pECC)); + + return ippStsNoErr; +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccppublickeyca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccppublickeyca.c new file mode 100644 index 0000000000..42b2515cf4 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccppublickeyca.c @@ -0,0 +1,89 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpeccppoint.h" +#include "pcpeccpmethod.h" +#include "pcpeccpmethodcom.h" + + +/*F* +// Name: ippsECCPPublicKey +// +// Purpose: Calculate Public Key +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pECC +// NULL == pPrivate +// NULL == pPublic +// +// ippStsContextMatchErr illegal pECC->idCtx +// illegal pPrivate->idCtx +// illegal pPublic->idCtx +// +// ippStsIvalidPrivateKey !(0 < pPrivate < order) +// +// ippStsNoErr no errors +// +// Parameters: +// pPrivate pointer to the private key +// pPublic pointer to the resultant public key +// pECC pointer to the ECCP context +// +*F*/ +IPPFUN(IppStatus, ippsECCPPublicKey, (const IppsBigNumState* pPrivate, + IppsECCPPointState* pPublic, + IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test public key */ + IPP_BAD_PTR1_RET(pPublic); + pPublic = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPublic, ALIGN_VAL) ); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPublic), ippStsContextMatchErr); + + /* test private keys */ + IPP_BAD_PTR1_RET(pPrivate); + pPrivate = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrivate, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pPrivate), ippStsContextMatchErr); + IPP_BADARG_RET(!((0cpBN_cmp(pPrivate, ECP_ORDER(pECC))) ), ippStsIvalidPrivateKey); + + /* calculates public key */ + ECP_METHOD(pECC)->MulBasePoint(pPrivate, pPublic, pECC, ECP_BNCTX(pECC)); + + return ippStsNoErr; +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpsecretdhca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpsecretdhca.c new file mode 100644 index 0000000000..3fec05a086 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpsecretdhca.c @@ -0,0 +1,116 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpeccp.h" +#include "pcpeccppoint.h" +#include "pcpeccpmethod.h" +#include "pcpeccpmethodcom.h" + + +/*F* +// Name: ippsECCPSharedSecretDH +// +// Purpose: Shared Secret Value Derivation +// (Diffie-Hellman version). +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pECC +// NULL == pPrivateA +// NULL == pPublicB +// NULL == pShare +// +// ippStsContextMatchErr illegal pECC->idCtx +// illegal pPrivateA->idCtx +// illegal pPublicB->idCtx +// illegal pShare->idCtx +// +// ippStsRangeErr not enough room for share key +// +// ippStsShareKeyErr (infinity) => z +// +// ippStsNoErr no errors +// +// Parameters: +// pPrivateA pointer to own private key +// pPublicB pointer to alien public key +// pShare pointer to the shareds secret value +// pECC pointer to the ECCP context +// +*F*/ +IPPFUN(IppStatus, ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, + const IppsECCPPointState* pPublicB, + IppsBigNumState* pShare, + IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test private (own) key */ + IPP_BAD_PTR1_RET(pPrivateA); + pPrivateA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrivateA, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pPrivateA), ippStsContextMatchErr); + + /* test public (other party) key */ + IPP_BAD_PTR1_RET(pPublicB); + pPublicB = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPublicB, ALIGN_VAL) ); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPublicB), ippStsContextMatchErr); + + /* test share secret value */ + IPP_BAD_PTR1_RET(pShare); + pShare = (IppsBigNumState*)( IPP_ALIGNED_PTR(pShare, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pShare), ippStsContextMatchErr); + IPP_BADARG_RET((BN_ROOM(pShare)*BITSIZE(BNU_CHUNK_T)MulPoint(pPublicB, pPrivateA, &Tmp, pECC, pList); + + /* test: Tmp ~ point at Infinity */ + if( ECCP_IsPointAtInfinity(&Tmp) ) + return ippStsShareKeyErr; + else { + ECP_METHOD(pECC)->GetPointAffine(pShare, NULL, &Tmp, pECC, pList); + return ippStsNoErr; + } + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpsetkeyca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpsetkeyca.c new file mode 100644 index 0000000000..c1644c06ae --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpsetkeyca.c @@ -0,0 +1,105 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpeccp.h" +#include "pcpeccppoint.h" +#include "pcpeccpmethod.h" +#include "pcpeccpmethodcom.h" + + +/*F* +// Name: ippsECCPSetKeyPair +// +// Purpose: Generate (private,public) Key Pair +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pECC +// NULL == pPrivate +// NULL == pPublic +// +// ippStsContextMatchErr illegal pECC->idCtx +// illegal pPrivate->idCtx +// illegal pPublic->idCtx +// +// ippStsNoErr no errors +// +// Parameters: +// pPrivate pointer to the private key +// pPublic pointer to the public key +// regular flag regular/ephemeral keys +// pECC pointer to the ECCP context +// +*F*/ +IPPFUN(IppStatus, ippsECCPSetKeyPair, (const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, + IppBool regular, + IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + /* test ID */ + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + { + IppsBigNumState* targetPrivate; + IppsECCPPointState* targetPublic; + + if( regular ) { + targetPrivate = ECP_PRIVATE(pECC); + targetPublic = ECP_PUBLIC(pECC); + } + else { + targetPrivate = ECP_PRIVATE_E(pECC); + targetPublic = ECP_PUBLIC_E(pECC); + } + + /* set up private key request */ + if( pPrivate ) { + pPrivate = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrivate, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pPrivate), ippStsContextMatchErr); + ippsSet_BN(ippBigNumPOS, BN_SIZE32(pPrivate), (Ipp32u*)BN_NUMBER(pPrivate), targetPrivate); + } + + /* set up public key request */ + if( pPublic ) { + pPublic = (IppsECCPPointState*)( IPP_ALIGNED_PTR(pPublic, ALIGN_VAL) ); + IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPublic), ippStsContextMatchErr); + + ECP_METHOD(pECC)->GetPointAffine(ECP_POINT_X(targetPublic), ECP_POINT_Y(targetPublic), pPublic, pECC, ECP_BNCTX(pECC)); + ECP_METHOD(pECC)->SetPointAffine(ECP_POINT_X(targetPublic), ECP_POINT_Y(targetPublic), targetPublic, pECC); + } + + return ippStsNoErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpsigndsaca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpsigndsaca.c new file mode 100644 index 0000000000..bcda1d76ad --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpsigndsaca.c @@ -0,0 +1,149 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpeccp.h" +#include "pcpeccppoint.h" +#include "pcpeccpmethod.h" +#include "pcpeccpmethodcom.h" + + +/*F* +// Name: ippsECCPSignDSA +// +// Purpose: Signing of message representative. +// (DSA version). +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pECC +// NULL == pMsgDigest +// NULL == pPrivate +// NULL == pSignX +// NULL == pSignY +// +// ippStsContextMatchErr illegal pECC->idCtx +// illegal pMsgDigest->idCtx +// illegal pPrivate->idCtx +// illegal pSignX->idCtx +// illegal pSignY->idCtx +// +// ippStsMessageErr MsgDigest >= order +// +// ippStsRangeErr not enough room for: +// signX +// signY +// +// ippStsEphemeralKeyErr (0==signX) || (0==signY) +// +// ippStsNoErr no errors +// +// Parameters: +// pMsgDigest pointer to the message representative to be signed +// pPrivate pointer to the regular private key +// pSignX,pSignY pointer to the signature +// pECC pointer to the ECCP context +// +// Note: +// - ephemeral key pair extracted from pECC and +// must be generated and before ippsECCPDSASign() usage +// - ephemeral key pair destroy before exit +// +*F*/ +IPPFUN(IppStatus, ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, + const IppsBigNumState* pPrivate, + IppsBigNumState* pSignX, IppsBigNumState* pSignY, + IppsECCPState* pECC)) +{ + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test private key*/ + IPP_BAD_PTR1_RET(pPrivate); + pPrivate = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrivate, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pPrivate), ippStsContextMatchErr); + + /* test message representative */ + IPP_BAD_PTR1_RET(pMsgDigest); + pMsgDigest = (IppsBigNumState*)( IPP_ALIGNED_PTR(pMsgDigest, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pMsgDigest), ippStsContextMatchErr); + IPP_BADARG_RET((0<=cpBN_cmp(pMsgDigest, ECP_ORDER(pECC))), ippStsMessageErr); + + /* test signature */ + IPP_BAD_PTR2_RET(pSignX,pSignY); + pSignX = (IppsBigNumState*)( IPP_ALIGNED_PTR(pSignX, ALIGN_VAL) ); + pSignY = (IppsBigNumState*)( IPP_ALIGNED_PTR(pSignY, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pSignX), ippStsContextMatchErr); + IPP_BADARG_RET(!BN_VALID_ID(pSignY), ippStsContextMatchErr); + IPP_BADARG_RET((BN_ROOM(pSignX)*BITSIZE(BNU_CHUNK_T)GetPointAffine(pTmp, NULL, ECP_PUBLIC_E(pECC), pECC, pList); + + /* + // compute + // signX = eph_pub_x (mod order) + */ + PMA_mod(pSignX, pTmp, pOrder); + if( !IsZero_BN(pSignX) ) { + + IppsBigNumState* pEncMsg = cpBigNumListGet(&pList); + IppsBigNumState* pEncSignX = cpBigNumListGet(&pList); + PMA_enc(pEncMsg, (IppsBigNumState*)pMsgDigest, rMont); + PMA_enc(pEncSignX, pSignX, rMont); + + /* + // compute + // signY = (1/eph_private)*(pMsgDigest + private*signX) (mod order) + */ + PMA_inv(pSignY, ECP_PRIVATE_E(pECC), pOrder); + PMA_enc(ECP_PRIVATE_E(pECC), pPrivate, rMont); + PMA_mule(pTmp, ECP_PRIVATE_E(pECC), pEncSignX, rMont); + PMA_add(pTmp, pTmp, pEncMsg, pOrder); + PMA_mule(pSignY, pSignY, pTmp, rMont); + if( !IsZero_BN(pSignY) ) + return ippStsNoErr; + } + + return ippStsEphemeralKeyErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpsscm.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpsscm.c new file mode 100644 index 0000000000..32ab537cf1 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpeccpsscm.c @@ -0,0 +1,161 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpbn.h" +#include "pcpeccppoint.h" + + +#define LOG2_CACHE_LINE_SIZE (LOG_CACHE_LINE_SIZE) + +static int div_upper(int a, int d) +{ return (a+d-1)/d; } + +static int getNumOperations(int bitsize, int w) +{ + int n_overhead = (1<=n_opt) break; + w_opt = w_trial; + n_opt = n_trial; + } + return w_opt; +#undef LIMIT +} + +int cpECCP_ConvertRepresentation(BNU_CHUNK_T* pInput, int inpBits, int w) +{ + Ipp32u* pR = (Ipp32u*)pInput; + Ipp16u* pR16 = (Ipp16u*)pInput; + + int outBits = 0; + Ipp32u base = (BNU_CHUNK_T)1<>digitShift) &digitMask; + + Ipp32u delta = (base-digit) & ~digitMask; + delta <<= digitShift; + cpDec_BNU32((Ipp32u*)(pR16+chunkIdx), (Ipp32u*)(pR16+chunkIdx), (2*nsR-chunkIdx+1)/2, delta); + + inpBits = BITSIZE_BNU32(pR, nsR); + outBits += w; + } + + return outBits; +} + +/* +// cpsScramblePut/cpsScrambleGet +// stores to/retrieves from pScrambleEntry position +// pre-computed data if fixed window method is used +*/ +void cpECCP_ScramblePut(Ipp8u* pScrambleEntry, int proposity, + const IppsECCPPointState* pPoint, cpSize coordLen) +{ + int i; + Ipp8u* pCoord; + + BNU_CHUNK_T* pX = BN_NUMBER(ECP_POINT_X(pPoint)); + BNU_CHUNK_T* pY = BN_NUMBER(ECP_POINT_Y(pPoint)); + BNU_CHUNK_T* pZ = BN_NUMBER(ECP_POINT_Z(pPoint)); + int coordSize = coordLen*sizeof(BNU_CHUNK_T); + + ZEXPAND_BNU(pX, BN_SIZE(ECP_POINT_X(pPoint)), coordLen); + ZEXPAND_BNU(pY, BN_SIZE(ECP_POINT_Y(pPoint)), coordLen); + ZEXPAND_BNU(pZ, BN_SIZE(ECP_POINT_Z(pPoint)), coordLen); + + pCoord = (Ipp8u*)pX; + for(i=0; iidCtx +// illegal pMsgDigest->idCtx +// illegal pSignX->idCtx +// illegal pSignY->idCtx +// +// ippStsMessageErr MsgDigest >= order +// +// ippStsNoErr no errors +// +// Parameters: +// pMsgDigest pointer to the message representative to be signed +// pSignX,pSignY pointer to the signature +// pResult pointer to the result: ippECValid/ippECInvalidSignature +// pECC pointer to the ECCP context +// +// Note: +// - signer's key must be set up in ECCP context +// before ippsECCPVerifyDSA() usage +// +*F*/ +IPPFUN(IppStatus, ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, + const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, + IppECResult* pResult, + IppsECCPState* pECC)) +{ + IppsMontState* rMont; + + /* test pECC */ + IPP_BAD_PTR1_RET(pECC); + /* use aligned EC context */ + pECC = (IppsECCPState*)( IPP_ALIGNED_PTR(pECC, ALIGN_VAL) ); + IPP_BADARG_RET(!ECP_VALID_ID(pECC), ippStsContextMatchErr); + + /* test message representative */ + IPP_BAD_PTR1_RET(pMsgDigest); + pMsgDigest = (IppsBigNumState*)( IPP_ALIGNED_PTR(pMsgDigest, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pMsgDigest), ippStsContextMatchErr); + rMont = ECP_RMONT(pECC); + IPP_BADARG_RET((0<=cpBN_cmp(pMsgDigest, ECP_ORDER(pECC))), ippStsMessageErr); + + /* test result */ + IPP_BAD_PTR1_RET(pResult); + + /* test signature */ + IPP_BAD_PTR2_RET(pSignX,pSignY); + pSignX = (IppsBigNumState*)( IPP_ALIGNED_PTR(pSignX, ALIGN_VAL) ); + pSignY = (IppsBigNumState*)( IPP_ALIGNED_PTR(pSignY, ALIGN_VAL) ); + IPP_BADARG_RET(!BN_VALID_ID(pSignX), ippStsContextMatchErr); + IPP_BADARG_RET(!BN_VALID_ID(pSignY), ippStsContextMatchErr); + + /* test signature value */ + if( (0>cpBN_tst(pSignX)) || (0>cpBN_tst(pSignY)) || + (0<=cpBN_cmp(pSignX, ECP_ORDER(pECC))) || + (0<=cpBN_cmp(pSignY, ECP_ORDER(pECC))) ) { + *pResult = ippECInvalidSignature; + return ippStsNoErr; + } + + /* validate signature */ + else { + IppsECCPPointState P1; + + BigNumNode* pList = ECP_BNCTX(pECC); + IppsBigNumState* pH1 = cpBigNumListGet(&pList); + IppsBigNumState* pH2 = cpBigNumListGet(&pList); + IppsBigNumState* pOrder = cpBigNumListGet(&pList); + BN_Set(MNT_MODULUS(rMont), MNT_SIZE(rMont), pOrder); + + ECP_POINT_X(&P1) = cpBigNumListGet(&pList); + ECP_POINT_Y(&P1) = cpBigNumListGet(&pList); + ECP_POINT_Z(&P1) = cpBigNumListGet(&pList); + + PMA_inv(pH1, (IppsBigNumState*)pSignY, pOrder);/* h = 1/signY (mod order) */ + PMA_enc(pH1, pH1, rMont); + PMA_mule(pH2, (IppsBigNumState*)pSignX, pH1, rMont); /* h2 = pSignX * h (mod order) */ + PMA_mule(pH1, (IppsBigNumState*)pMsgDigest, pH1, rMont); /* h1 = pMsgDigest * h (mod order) */ + + /* compute h1*BasePoint + h2*publicKey */ + ECP_METHOD(pECC)->ProdPoint(ECP_GENC(pECC), pH1, + ECP_PUBLIC(pECC), pH2, + &P1, pECC, pList); + + if( ECCP_IsPointAtInfinity(&P1) ) { + *pResult = ippECInvalidSignature; + return ippStsNoErr; + } + /* extract X component */ + ECP_METHOD(pECC)->GetPointAffine(pH1, NULL, &P1, pECC, pList); + /* compare with signX */ + PMA_mod(pH1, pH1, pOrder); + *pResult = (0==cpBN_cmp(pH1, pSignX))? ippECValid : ippECInvalidSignature; + return ippStsNoErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphash.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphash.h new file mode 100644 index 0000000000..669f3e3467 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphash.h @@ -0,0 +1,159 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_PCP_HASH_H) +#define _PCP_HASH_H + + +/* messge block size */ +#define MBS_SHA1 (64) /* SHA1 message block size (bytes) */ +#define MBS_SHA256 (64) /* SHA256 and SHA224 */ +#define MBS_SHA224 (64) /* SHA224 */ +#define MBS_SHA512 (128) /* SHA512 and SHA384 */ +#define MBS_SHA384 (128) /* SHA384 */ +#define MBS_MD5 (64) /* MD5 */ +#define MBS_HASH_MAX (MBS_SHA512) /* max message block size (bytes) */ +#define MAX_HASH_SIZE (IPP_SHA512_DIGEST_BITSIZE/8) /* hash of the max len (bytes) */ + +/* +// Useful macros +*/ +#define SHS_ID(stt) ((stt)->idCtx) +#define SHS_INDX(stt) ((stt)->index) +#define SHS_LENL(stt) ((stt)->msgLenLo) +#define SHS_LENH(stt) ((stt)->msgLenHi) +#define SHS_BUFF(stt) ((stt)->msgBuffer) +#define SHS_HASH(stt) ((stt)->msgHash) + +/* initial hash values */ +extern const Ipp32u SHA1_IV[]; +extern const Ipp32u SHA256_IV[]; +extern const Ipp32u SHA224_IV[]; +extern const Ipp64u SHA512_IV[]; +extern const Ipp64u SHA384_IV[]; +extern const Ipp32u MD5_IV[]; +extern const Ipp64u SHA512_224_IV[]; +extern const Ipp64u SHA512_256_IV[]; + +/* hash alg additive constants */ +extern __ALIGN16 const Ipp32u SHA1_cnt[]; +extern __ALIGN16 const Ipp32u SHA256_cnt[]; +extern __ALIGN16 const Ipp64u SHA512_cnt[]; +extern __ALIGN16 const Ipp32u MD5_cnt[]; + + +/* hash alg attributes */ +typedef struct _cpHashAttr { + int ivSize; /* attr: length (bytes) of initial value cpHashIV */ + int hashSize; /* attr: length (bytes) of hash */ + int msgBlkSize; /* attr: length (bytes) of message block */ + int msgLenRepSize; /* attr: length (bytes) in representation of processed message length */ + Ipp64u msgLenMax[2]; /* attr: max message length (bytes) (low high) */ +} cpHashAttr; + + +/* hash value */ +typedef Ipp64u cpHash[IPP_SHA512_DIGEST_BITSIZE/BITSIZE(Ipp64u)]; /* hash value */ + +/* hash update function */ +typedef void (*cpHashProc)(void* pHash, const Ipp8u* pMsg, int msgLen, const void* pParam); + + + +/* hash context */ +struct _cpHashCtx { + IppCtxId idCtx; /* hash identifier */ + IppHashAlgId algID; /* hash algorithm ID */ + Ipp64u msgLenLo; /* length (bytes) of processed message: */ + Ipp64u msgLenHi; /* low and high parts */ + cpHashProc hashProc; /* hash update function */ + const void* pParam; /* optional hashProc's parameter */ + cpHash hashVal; /* intermadiate has value */ + int buffOffset; /* current buffer position */ + Ipp8u msgBuffer[MBS_HASH_MAX]; /* buffer */ +}; + +/* accessors */ +#define HASH_CTX_ID(stt) ((stt)->idCtx) +#define HASH_ALG_ID(stt) ((stt)->algID) +#define HASH_LENLO(stt) ((stt)->msgLenLo) +#define HASH_LENHI(stt) ((stt)->msgLenHi) +#define HASH_FUNC(stt) ((stt)->hashProc) +#define HASH_FUNC_PAR(stt) ((stt)->pParam) +#define HASH_VALUE(stt) ((stt)->hashVal) +#define HAHS_BUFFIDX(stt) ((stt)->buffOffset) +#define HASH_BUFF(stt) ((stt)->msgBuffer) +#define HASH_VALID_ID(pCtx) (HASH_CTX_ID((pCtx))==idCtxHash) + + +/* hash alg opt argument */ +extern const void* cpHashProcFuncOpt[]; + +/* enabled hash alg */ +extern const IppHashAlgId cpEnabledHashAlgID[]; + +/* hash alg IV (init value) */ +extern const Ipp8u* cpHashIV[]; + +/* hash alg attribute DB */ +extern const cpHashAttr cpHashAlgAttr[]; + +/* IV size helper */ +__INLINE int cpHashIvSize(IppHashAlgId algID) +{ return cpHashAlgAttr[algID].ivSize; } + +/* hash size helper */ +__INLINE int cpHashSize(IppHashAlgId algID) +{ return cpHashAlgAttr[algID].hashSize; } + +/* message block size helper */ +__INLINE int cpHashMBS(IppHashAlgId algID) +{ return cpHashAlgAttr[algID].msgBlkSize; } + +/* maps algID into enabled IppHashAlgId value */ +__INLINE IppHashAlgId cpValidHashAlg(IppHashAlgId algID) +{ + /* maps algID into the valid range */ + algID = (((int)ippHashAlg_Unknown < (int)algID) && ((int)algID < (int)ippHashAlg_MaxNo))? algID : ippHashAlg_Unknown; + return cpEnabledHashAlgID[algID]; +} + + +/* processing functions */ +void UpdateSHA1 (void* pHash, const Ipp8u* mblk, int mlen, const void* pParam); +void UpdateSHA256(void* pHash, const Ipp8u* mblk, int mlen, const void* pParam); +void UpdateSHA512(void* pHash, const Ipp8u* mblk, int mlen, const void* pParam); +void UpdateMD5 (void* pHash, const Ipp8u* mblk, int mlen, const void* pParam); + +/* general methods */ +int cpReInitHash(IppsHashState* pCtx, IppHashAlgId algID); + +#endif /* _PCP_HASH_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashca.c new file mode 100644 index 0000000000..47b2a8b670 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashca.c @@ -0,0 +1,513 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcphash.h" +#include "pcptool.h" + + +/*F* +// Name: ippsHashGetSize +// +// Purpose: Returns size (bytes) of IppsHashState state. +// +// Returns: Reason: +// ippStsNullPtrErr pSize == NULL +// ippStsNoErr no errors +// +// Parameters: +// pSize pointer to state size +// +*F*/ +IPPFUN(IppStatus, ippsHashGetSize,(int* pSize)) +{ + /* test pointers */ + IPP_BAD_PTR1_RET(pSize); + + *pSize = sizeof(IppsHashState); + return ippStsNoErr; +} + + +/*F* +// Name: ippsHashInit +// +// Purpose: Init Hash state. +// +// Returns: Reason: +// ippStsNullPtrErr pState == NULL +// ippStsNotSupportedModeErr if algID is not match to supported hash alg +// ippStsNoErr no errors +// +// Parameters: +// pCtx pointer to the Hash state +// algID hash alg ID +// +*F*/ +int cpReInitHash(IppsHashState* pCtx, IppHashAlgId algID) +{ + int hashIvSize = cpHashIvSize(algID); + const Ipp8u* iv = cpHashIV[algID]; + + HASH_LENLO(pCtx) = CONST_64(0); + HASH_LENHI(pCtx) = CONST_64(0); + HAHS_BUFFIDX(pCtx) = 0; + CopyBlock(iv, HASH_VALUE(pCtx), hashIvSize); + + return hashIvSize; +} + +/* +// hash alg default processing functions and opt argument +*/ +static cpHashProc cpHashProcFunc[] = { + (cpHashProc)NULL, + UpdateSHA1, + UpdateSHA256, + UpdateSHA256, + UpdateSHA512, + UpdateSHA512, + UpdateMD5, + UpdateSHA512, + UpdateSHA512, +}; + +int cpInitHash(IppsHashState* pCtx, IppHashAlgId algID) +{ + /* setup default processing function */ + HASH_FUNC(pCtx) = cpHashProcFunc[algID]; + + /* setup optional agr of processing function */ + HASH_FUNC_PAR(pCtx) = cpHashProcFuncOpt[algID]; + + return cpReInitHash(pCtx, algID); +} + +IPPFUN(IppStatus, ippsHashInit,(IppsHashState* pCtx, IppHashAlgId algID)) +{ + /* get algorithm id */ + algID = cpValidHashAlg(algID); + /* test hash alg */ + IPP_BADARG_RET(ippHashAlg_Unknown==algID, ippStsNotSupportedModeErr); + + /* test ctx pointer */ + IPP_BAD_PTR1_RET(pCtx); + /* test hash alg */ + + /* set ctx ID */ + HASH_CTX_ID(pCtx) = idCtxHash; + HASH_ALG_ID(pCtx) = algID; + + /* init context */ + cpInitHash(pCtx, algID); + return ippStsNoErr; +} + + +/*F* +// Name: ippsHashUpdate +// +// Purpose: Updates intermediate hash value based on input stream. +// +// Returns: Reason: +// ippStsNullPtrErr pCtx == NULL +// ippStsNullPtrErr pSrc==0 but len!=0 +// ippStsContextMatchErr pCtx->idCtx != idCtxHash +// ippStsLengthErr len <0 +// ippStsNoErr no errors +// +// Parameters: +// pSrc pointer to the input stream +// len input stream length +// pCtx pointer to the Hash context +// +*F*/ +__INLINE int IsExceedMsgLen(Ipp64u maxLo, Ipp64u maxHi, Ipp64u lenLo, Ipp64u lenHi) +{ + int isExceed = lenLo > maxLo; + isExceed = (lenHi+isExceed) > maxHi; + return isExceed; +} + +IPPFUN(IppStatus, ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pCtx)) +{ + /* test state pointer and ID */ + IPP_BAD_PTR1_RET(pCtx); + /* test the context */ + IPP_BADARG_RET(!HASH_VALID_ID(pCtx), ippStsContextMatchErr); + /* test input length */ + IPP_BADARG_RET((len<0 && pSrc), ippStsLengthErr); + /* test source pointer */ + IPP_BADARG_RET((len && !pSrc), ippStsNullPtrErr); + + /* handle non empty input */ + if(len) { + const cpHashAttr* pAttr = &cpHashAlgAttr[HASH_ALG_ID(pCtx)]; + + /* test if size of message is being processed not exceeded yet */ + Ipp64u lenLo = HASH_LENLO(pCtx); + Ipp64u lenHi = HASH_LENHI(pCtx); + lenLo += len; + if(lenLo < HASH_LENLO(pCtx)) lenHi++; + if(IsExceedMsgLen(pAttr->msgLenMax[0],pAttr->msgLenMax[1], lenLo,lenHi)) + IPP_ERROR_RET(ippStsLengthErr); + + else { + cpHashProc hashFunc = HASH_FUNC(pCtx); /* processing function */ + const void* pParam = HASH_FUNC_PAR(pCtx); /* and it's addition params */ + int mbs = pAttr->msgBlkSize; /* data block size */ + + /* + // processing + */ + { + int procLen; + + /* test if internal buffer is not empty */ + int n = HAHS_BUFFIDX(pCtx); + if(n) { + procLen = IPP_MIN(len, (mbs-n)); + CopyBlock(pSrc, HASH_BUFF(pCtx)+n, procLen); + HAHS_BUFFIDX(pCtx) = n += procLen; + + /* block processing */ + if(mbs==n) { + hashFunc(HASH_VALUE(pCtx), HASH_BUFF(pCtx), mbs, pParam); + HAHS_BUFFIDX(pCtx) = 0; + } + + /* update message pointer and length */ + pSrc += procLen; + len -= procLen; + } + + /* main processing part */ + procLen = len & ~(mbs-1); + if(procLen) { + hashFunc(HASH_VALUE(pCtx), pSrc, procLen, pParam); + pSrc += procLen; + len -= procLen; + } + + /* rest of input message */ + if(len) { + CopyBlock(pSrc, HASH_BUFF(pCtx), len); + HAHS_BUFFIDX(pCtx) += len; + } + } + + /* update length of processed message */ + HASH_LENLO(pCtx) = lenLo; + HASH_LENHI(pCtx) = lenHi; + + return ippStsNoErr; + } + } + + return ippStsNoErr; +} + + +static void cpComputeDigest(Ipp8u* pHashTag, int hashTagLen, const IppsHashState* pCtx) +{ + /* hash alg and parameters */ + cpHashProc hashFunc = HASH_FUNC(pCtx); /* processing function */ + const void* pParam = HASH_FUNC_PAR(pCtx); /* and it's addition params */ + + /* attributes */ + const cpHashAttr* pAttr = &cpHashAlgAttr[HASH_ALG_ID(pCtx)]; + int mbs = pAttr->msgBlkSize; /* data block size */ + int ivSize = pAttr->ivSize; /* size of hash's IV */ + int msgLenRepSize = pAttr->msgLenRepSize; /* length of the message representation */ + + /* number of bytes in context buffer */ + int n = HAHS_BUFFIDX(pCtx); + /* buffer and it actual length */ + Ipp8u buffer[MBS_HASH_MAX*2]; + int bufferLen = n < (mbs-msgLenRepSize)? mbs : mbs*2; + + /* copy current hash value */ + cpHash hash; + CopyBlock(HASH_VALUE(pCtx), hash, ivSize); + + /* copy of state's buffer */ + CopyBlock(HASH_BUFF(pCtx), buffer, bufferLen); + /* end of message bit */ + buffer[n++] = 0x80; + /* padd buffer */ + PaddBlock(0, buffer+n, bufferLen-n-msgLenRepSize); + + /* message length representation in bits (remember about big endian) */ + { + /* convert processed message length bytes ->bits */ + Ipp64u lo = HASH_LENLO(pCtx); + Ipp64u hi = HASH_LENHI(pCtx); + hi = LSL64(hi,3) | LSR64(lo,63-3); + lo = LSL64(lo,3); + + if(msgLenRepSize>(int)(sizeof(Ipp64u))) { + #if (IPP_ENDIAN == IPP_BIG_ENDIAN) + ((Ipp64u*)(buffer+bufferLen))[-2] = hi; + #else + ((Ipp64u*)(buffer+bufferLen))[-2] = ENDIANNESS64(hi); + #endif + } + + /* recall about MD5 specific */ + if(ippHashAlg_MD5!=HASH_ALG_ID(pCtx)) { + #if (IPP_ENDIAN == IPP_BIG_ENDIAN) + ((Ipp64u*)(buffer+bufferLen))[-1] = lo; + #else + ((Ipp64u*)(buffer+bufferLen))[-1] = ENDIANNESS64(lo); + #endif + } + else { + #if (IPP_ENDIAN == IPP_BIG_ENDIAN) + ((Ipp64u*)(buffer+bufferLen))[-1] = ENDIANNESS64(lo); + #else + ((Ipp64u*)(buffer+bufferLen))[-1] = lo; + #endif + } + } + + /* copmplete hash computation */ + hashFunc(hash, buffer, bufferLen, pParam); + + /* store digest into the user buffer (remember digest in big endian) */ + if(msgLenRepSize>(int)(sizeof(Ipp64u))) { + /* ippHashAlg_SHA384, ippHashAlg_SHA512, ippHashAlg_SHA512_224 and ippHashAlg_SHA512_256 */ + hash[0] = ENDIANNESS64(hash[0]); + hash[1] = ENDIANNESS64(hash[1]); + hash[2] = ENDIANNESS64(hash[2]); + hash[3] = ENDIANNESS64(hash[3]); + hash[4] = ENDIANNESS64(hash[4]); + hash[5] = ENDIANNESS64(hash[5]); + hash[6] = ENDIANNESS64(hash[6]); + hash[7] = ENDIANNESS64(hash[7]); + } + else if(ippHashAlg_MD5!=HASH_ALG_ID(pCtx)) { + ((Ipp32u*)hash)[0] = ENDIANNESS32(((Ipp32u*)hash)[0]); + ((Ipp32u*)hash)[1] = ENDIANNESS32(((Ipp32u*)hash)[1]); + ((Ipp32u*)hash)[2] = ENDIANNESS32(((Ipp32u*)hash)[2]); + ((Ipp32u*)hash)[3] = ENDIANNESS32(((Ipp32u*)hash)[3]); + ((Ipp32u*)hash)[4] = ENDIANNESS32(((Ipp32u*)hash)[4]); + if(ippHashAlg_SHA1!=HASH_ALG_ID(pCtx)) { + ((Ipp32u*)hash)[5] = ENDIANNESS32(((Ipp32u*)hash)[5]); + ((Ipp32u*)hash)[6] = ENDIANNESS32(((Ipp32u*)hash)[6]); + ((Ipp32u*)hash)[7] = ENDIANNESS32(((Ipp32u*)hash)[7]); + } + } + CopyBlock(hash, pHashTag, hashTagLen); +} + + +/*F* +// Name: ippsHashGetTag +// +// Purpose: Compute digest based on current state. +// Note, that futher digest update is possible +// +// Returns: Reason: +// ippStsNullPtrErr pTag == NULL +// pCtx == NULL +// ippStsContextMatchErr pCtx->idCtx != idCtxHash +// ippStsLengthErr hashSize < tagLen <1 +// ippStsNoErr no errors +// +// Parameters: +// pTag address of the output digest +// tagLen length of digest +// pCtx pointer to the SHS state +// +*F*/ +IPPFUN(IppStatus, ippsHashGetTag,(Ipp8u* pTag, int tagLen, const IppsHashState* pCtx)) +{ + /* test state pointer and ID */ + IPP_BAD_PTR2_RET(pTag, pCtx); + /* test the context */ + IPP_BADARG_RET(!HASH_VALID_ID(pCtx), ippStsContextMatchErr); + + { + /* size of hash */ + int hashSize = cpHashAlgAttr[HASH_ALG_ID(pCtx)].hashSize; + if(tagLen<1||hashSizeidCtx != idCtxHash +// ippStsNoErr no errors +// +// Parameters: +// pMD address of the output digest +// pCtx pointer to the SHS state +// +*F*/ +IPPFUN(IppStatus, ippsHashFinal,(Ipp8u* pMD, IppsHashState* pCtx)) +{ + /* test state pointer and ID */ + IPP_BAD_PTR2_RET(pMD, pCtx); + /* test the context */ + IPP_BADARG_RET(!HASH_VALID_ID(pCtx), ippStsContextMatchErr); + + { + IppHashAlgId algID = HASH_ALG_ID(pCtx); + int hashSize = cpHashAlgAttr[algID].hashSize; + + cpComputeDigest(pMD, hashSize, pCtx); + cpReInitHash(pCtx, algID); + + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsHashMessage +// +// Purpose: Hash of the whole message. +// +// Returns: Reason: +// ippStsNullPtrErr pMD == NULL +// pMsg == NULL but msgLen!=0 +// ippStsLengthErr msgLen <0 +// ippStsNotSupportedModeErr if algID is not match to supported hash alg +// ippStsNoErr no errors +// +// Parameters: +// pMsg pointer to the input message +// msgLen input message length +// pMD address of the output digest +// algID hash alg ID +// +*F*/ +IPPFUN(IppStatus, ippsHashMessage,(const Ipp8u* pMsg, int msgLen, Ipp8u* pMD, IppHashAlgId algID)) +{ + /* get algorithm id */ + algID = cpValidHashAlg(algID); + /* test hash alg */ + IPP_BADARG_RET(ippHashAlg_Unknown==algID, ippStsNotSupportedModeErr); + + /* test digest pointer */ + IPP_BAD_PTR1_RET(pMD); + /* test message length */ + IPP_BADARG_RET((msgLen<0), ippStsLengthErr); + /* test message pointer */ + IPP_BADARG_RET((msgLen && !pMsg), ippStsNullPtrErr); + + { + /* processing function and parameter */ + cpHashProc hashFunc = cpHashProcFunc[algID]; + const void* pParam = cpHashProcFuncOpt[algID]; + + /* attributes */ + const cpHashAttr* pAttr = &cpHashAlgAttr[algID]; + int mbs = pAttr->msgBlkSize; /* data block size */ + int ivSize = pAttr->ivSize; /* size of hash's IV */ + int hashSize = pAttr->hashSize; /* hash size */ + int msgLenRepSize = pAttr->msgLenRepSize; /* length of the message representation */ + + /* message bitlength representation */ + Ipp64u msgLenBits = (Ipp64u)msgLen*8; + /* length of main message part */ + int msgLenBlks = msgLen & (-mbs); + /* rest of message length */ + int msgLenRest = msgLen - msgLenBlks; + + /* end of message buffer */ + Ipp8u buffer[MBS_HASH_MAX*2]; + int bufferLen = (msgLenRest < (mbs-msgLenRepSize))? mbs : mbs*2; + + /* init hash */ + cpHash hash; + const Ipp8u* iv = cpHashIV[algID]; + CopyBlock(iv, hash, ivSize); + + /*construct last messge block(s) */ + #define MSG_LEN_REP (sizeof(Ipp64u)) + + /* copy end of message */ + CopyBlock(pMsg+msgLen-msgLenRest, buffer, msgLenRest); + /* end of message bit */ + buffer[msgLenRest++] = 0x80; + /* padd buffer */ + PaddBlock(0, buffer+msgLenRest, bufferLen-msgLenRest-MSG_LEN_REP); + /* copy message bitlength representation */ + if(ippHashAlg_MD5!=algID) + msgLenBits = ENDIANNESS64(msgLenBits); + ((Ipp64u*)(buffer+bufferLen))[-1] = msgLenBits; + + #undef MSG_LEN_REP + + /* message processing */ + if(msgLenBlks) + hashFunc(hash, pMsg, msgLenBlks, pParam); + hashFunc(hash, buffer, bufferLen, pParam); + + /* store digest into the user buffer (remember digest in big endian) */ + if(msgLenRepSize > (int)(sizeof(Ipp64u))) { + /* ippHashAlg_SHA384, ippHashAlg_SHA512, ippHashAlg_SHA512_224 and ippHashAlg_SHA512_256 */ + hash[0] = ENDIANNESS64(hash[0]); + hash[1] = ENDIANNESS64(hash[1]); + hash[2] = ENDIANNESS64(hash[2]); + hash[3] = ENDIANNESS64(hash[3]); + hash[4] = ENDIANNESS64(hash[4]); + hash[5] = ENDIANNESS64(hash[5]); + hash[6] = ENDIANNESS64(hash[6]); + hash[7] = ENDIANNESS64(hash[7]); + } + else if(ippHashAlg_MD5!=algID) { + /* ippHashAlg_SHA1, ippHashAlg_SHA224, ippHashAlg_SHA256 and ippHashAlg_SM3 */ + ((Ipp32u*)hash)[0] = ENDIANNESS32(((Ipp32u*)hash)[0]); + ((Ipp32u*)hash)[1] = ENDIANNESS32(((Ipp32u*)hash)[1]); + ((Ipp32u*)hash)[2] = ENDIANNESS32(((Ipp32u*)hash)[2]); + ((Ipp32u*)hash)[3] = ENDIANNESS32(((Ipp32u*)hash)[3]); + ((Ipp32u*)hash)[4] = ENDIANNESS32(((Ipp32u*)hash)[4]); + ((Ipp32u*)hash)[5] = ENDIANNESS32(((Ipp32u*)hash)[5]); + ((Ipp32u*)hash)[6] = ENDIANNESS32(((Ipp32u*)hash)[6]); + ((Ipp32u*)hash)[7] = ENDIANNESS32(((Ipp32u*)hash)[7]); + } + CopyBlock(hash, pMD, hashSize); + + return ippStsNoErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashcnt.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashcnt.c new file mode 100644 index 0000000000..37e0188172 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashcnt.c @@ -0,0 +1,216 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcphash.h" + +/* +// enabled hash alg IDs +*/ +const IppHashAlgId cpEnabledHashAlgID[] = { + IPP_ALG_HASH_UNKNOWN, + IPP_ALG_HASH_SHA1, + IPP_ALG_HASH_SHA256, + IPP_ALG_HASH_SHA224, + IPP_ALG_HASH_SHA512, + IPP_ALG_HASH_SHA384, + IPP_ALG_HASH_MD5, + IPP_ALG_HASH_SHA512_224, + IPP_ALG_HASH_SHA512_256 +}; +//////////////////////////////////////////////////////////// + +/* +// hash init values +*/ +const Ipp32u UnknownHash_IV[] = { + 0}; + +const Ipp32u SHA1_IV[] = { + 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0}; + +const Ipp32u SHA256_IV[] = { + 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, + 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19}; + +const Ipp32u SHA224_IV[] = { + 0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, + 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4}; + +const Ipp64u SHA512_IV[] = { + CONST_64(0x6A09E667F3BCC908), CONST_64(0xBB67AE8584CAA73B), + CONST_64(0x3C6EF372FE94F82B), CONST_64(0xA54FF53A5F1D36F1), + CONST_64(0x510E527FADE682D1), CONST_64(0x9B05688C2B3E6C1F), + CONST_64(0x1F83D9ABFB41BD6B), CONST_64(0x5BE0CD19137E2179)}; + +const Ipp64u SHA384_IV[] = { + CONST_64(0xCBBB9D5DC1059ED8), CONST_64(0x629A292A367CD507), + CONST_64(0x9159015A3070DD17), CONST_64(0x152FECD8F70E5939), + CONST_64(0x67332667FFC00B31), CONST_64(0x8EB44A8768581511), + CONST_64(0xDB0C2E0D64F98FA7), CONST_64(0x47B5481DBEFA4FA4)}; + +const Ipp32u MD5_IV[] = { + 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476}; + +const Ipp64u SHA512_224_IV[] = { + CONST_64(0x8C3D37C819544DA2), CONST_64(0x73E1996689DCD4D6), + CONST_64(0x1DFAB7AE32FF9C82), CONST_64(0x679DD514582F9FCF), + CONST_64(0x0F6D2B697BD44DA8), CONST_64(0x77E36F7304C48942), + CONST_64(0x3F9D85A86A1D36C8), CONST_64(0x1112E6AD91D692A1)}; + +const Ipp64u SHA512_256_IV[] = { + CONST_64(0x22312194FC2BF72C), CONST_64(0x9F555FA3C84C64C2), + CONST_64(0x2393B86B6F53B151), CONST_64(0x963877195940EABD), + CONST_64(0x96283EE2A88EFFE3), CONST_64(0xBE5E1E2553863992), + CONST_64(0x2B0199FC2C85B8AA), CONST_64(0x0EB72DDC81C52CA2)}; + +const Ipp8u* cpHashIV[] = { + (Ipp8u*)UnknownHash_IV, + (Ipp8u*)SHA1_IV, + (Ipp8u*)SHA256_IV, + (Ipp8u*)SHA224_IV, + (Ipp8u*)SHA512_IV, + (Ipp8u*)SHA384_IV, + (Ipp8u*)MD5_IV, + (Ipp8u*)SHA512_224_IV, + (Ipp8u*)SHA512_256_IV, +}; + +//////////////////////////////////////////////////////////// + +/* +// additive constatns +*/ +__ALIGN16 const Ipp32u SHA1_cnt[] = { + 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 +}; + +__ALIGN16 const Ipp32u SHA256_cnt[] = { + 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, + 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, + 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, + 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, + 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, + 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, + 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, + 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, + 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, + 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, + 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, + 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, + 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, + 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, + 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, + 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 +}; + +__ALIGN16 const Ipp64u SHA512_cnt[] = { + CONST_64(0x428A2F98D728AE22), CONST_64(0x7137449123EF65CD), CONST_64(0xB5C0FBCFEC4D3B2F), CONST_64(0xE9B5DBA58189DBBC), + CONST_64(0x3956C25BF348B538), CONST_64(0x59F111F1B605D019), CONST_64(0x923F82A4AF194F9B), CONST_64(0xAB1C5ED5DA6D8118), + CONST_64(0xD807AA98A3030242), CONST_64(0x12835B0145706FBE), CONST_64(0x243185BE4EE4B28C), CONST_64(0x550C7DC3D5FFB4E2), + CONST_64(0x72BE5D74F27B896F), CONST_64(0x80DEB1FE3B1696B1), CONST_64(0x9BDC06A725C71235), CONST_64(0xC19BF174CF692694), + CONST_64(0xE49B69C19EF14AD2), CONST_64(0xEFBE4786384F25E3), CONST_64(0x0FC19DC68B8CD5B5), CONST_64(0x240CA1CC77AC9C65), + CONST_64(0x2DE92C6F592B0275), CONST_64(0x4A7484AA6EA6E483), CONST_64(0x5CB0A9DCBD41FBD4), CONST_64(0x76F988DA831153B5), + CONST_64(0x983E5152EE66DFAB), CONST_64(0xA831C66D2DB43210), CONST_64(0xB00327C898FB213F), CONST_64(0xBF597FC7BEEF0EE4), + CONST_64(0xC6E00BF33DA88FC2), CONST_64(0xD5A79147930AA725), CONST_64(0x06CA6351E003826F), CONST_64(0x142929670A0E6E70), + CONST_64(0x27B70A8546D22FFC), CONST_64(0x2E1B21385C26C926), CONST_64(0x4D2C6DFC5AC42AED), CONST_64(0x53380D139D95B3DF), + CONST_64(0x650A73548BAF63DE), CONST_64(0x766A0ABB3C77B2A8), CONST_64(0x81C2C92E47EDAEE6), CONST_64(0x92722C851482353B), + CONST_64(0xA2BFE8A14CF10364), CONST_64(0xA81A664BBC423001), CONST_64(0xC24B8B70D0F89791), CONST_64(0xC76C51A30654BE30), + CONST_64(0xD192E819D6EF5218), CONST_64(0xD69906245565A910), CONST_64(0xF40E35855771202A), CONST_64(0x106AA07032BBD1B8), + CONST_64(0x19A4C116B8D2D0C8), CONST_64(0x1E376C085141AB53), CONST_64(0x2748774CDF8EEB99), CONST_64(0x34B0BCB5E19B48A8), + CONST_64(0x391C0CB3C5C95A63), CONST_64(0x4ED8AA4AE3418ACB), CONST_64(0x5B9CCA4F7763E373), CONST_64(0x682E6FF3D6B2B8A3), + CONST_64(0x748F82EE5DEFB2FC), CONST_64(0x78A5636F43172F60), CONST_64(0x84C87814A1F0AB72), CONST_64(0x8CC702081A6439EC), + CONST_64(0x90BEFFFA23631E28), CONST_64(0xA4506CEBDE82BDE9), CONST_64(0xBEF9A3F7B2C67915), CONST_64(0xC67178F2E372532B), + CONST_64(0xCA273ECEEA26619C), CONST_64(0xD186B8C721C0C207), CONST_64(0xEADA7DD6CDE0EB1E), CONST_64(0xF57D4F7FEE6ED178), + CONST_64(0x06F067AA72176FBA), CONST_64(0x0A637DC5A2C898A6), CONST_64(0x113F9804BEF90DAE), CONST_64(0x1B710B35131C471B), + CONST_64(0x28DB77F523047D84), CONST_64(0x32CAAB7B40C72493), CONST_64(0x3C9EBE0A15C9BEBC), CONST_64(0x431D67C49C100D4C), + CONST_64(0x4CC5D4BECB3E42B6), CONST_64(0x597F299CFC657E2A), CONST_64(0x5FCB6FAB3AD6FAEC), CONST_64(0x6C44198C4A475817) +}; + +__ALIGN16 const Ipp32u MD5_cnt[] = { + 0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE, + 0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501, + 0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE, + 0x6B901122, 0xFD987193, 0xA679438E, 0x49B40821, + + 0xF61E2562, 0xC040B340, 0x265E5A51, 0xE9B6C7AA, + 0xD62F105D, 0x02441453, 0xD8A1E681, 0xE7D3FBC8, + 0x21E1CDE6, 0xC33707D6, 0xF4D50D87, 0x455A14ED, + 0xA9E3E905, 0xFCEFA3F8, 0x676F02D9, 0x8D2A4C8A, + + 0xFFFA3942, 0x8771F681, 0x6D9D6122, 0xFDE5380C, + 0xA4BEEA44, 0x4BDECFA9, 0xF6BB4B60, 0xBEBFBC70, + 0x289B7EC6, 0xEAA127FA, 0xD4EF3085, 0x04881D05, + 0xD9D4D039, 0xE6DB99E5, 0x1FA27CF8, 0xC4AC5665, + + 0xF4292244, 0x432AFF97, 0xAB9423A7, 0xFC93A039, + 0x655B59C3, 0x8F0CCC92, 0xFFEFF47D, 0x85845DD1, + 0x6FA87E4F, 0xFE2CE6E0, 0xA3014314, 0x4E0811A1, + 0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391 +}; + +/* +// hash alg default processing opt argument +*/ +const void* cpHashProcFuncOpt[] = { + NULL, + SHA1_cnt, + SHA256_cnt, + SHA256_cnt, + SHA512_cnt, + SHA512_cnt, + MD5_cnt, + SHA512_cnt, + SHA512_cnt, +}; +//////////////////////////////////////////////////////////// + +/* hash alg attributes */ +const cpHashAttr cpHashAlgAttr[] = { + {0, 0, 0, 0, {CONST_64(0),CONST_64(0)}}, /* unknown */ + + {IPP_SHA1_DIGEST_BITSIZE/8, IPP_SHA1_DIGEST_BITSIZE/8, MBS_SHA1, sizeof(Ipp64u), {CONST_64(0x2000000000000000-1),CONST_64(0)}}, + + {IPP_SHA256_DIGEST_BITSIZE/8,IPP_SHA256_DIGEST_BITSIZE/8, MBS_SHA256, sizeof(Ipp64u), {CONST_64(0x2000000000000000-1),CONST_64(0)}}, + + {IPP_SHA256_DIGEST_BITSIZE/8,IPP_SHA224_DIGEST_BITSIZE/8, MBS_SHA224, sizeof(Ipp64u), {CONST_64(0x2000000000000000-1),CONST_64(0)}}, + + {IPP_SHA512_DIGEST_BITSIZE/8,IPP_SHA512_DIGEST_BITSIZE/8, MBS_SHA512, sizeof(Ipp64u)*2, {CONST_64(0xFFFFFFFFFFFFFFFF),CONST_64(0x2000000000000000-1)}}, + + {IPP_SHA512_DIGEST_BITSIZE/8,IPP_SHA384_DIGEST_BITSIZE/8, MBS_SHA384, sizeof(Ipp64u)*2, {CONST_64(0xFFFFFFFFFFFFFFFF),CONST_64(0x2000000000000000-1)}}, + + {IPP_MD5_DIGEST_BITSIZE/8,IPP_MD5_DIGEST_BITSIZE/8, MBS_MD5, sizeof(Ipp64u), {CONST_64(0x2000000000000000-1),CONST_64(0)}}, + + {IPP_SHA512_DIGEST_BITSIZE/8,IPP_SHA512_224_DIGEST_BITSIZE/8, MBS_SHA512, sizeof(Ipp64u)*2, {CONST_64(0xFFFFFFFFFFFFFFFF),CONST_64(0x2000000000000000-1)}}, + + {IPP_SHA512_DIGEST_BITSIZE/8,IPP_SHA512_256_DIGEST_BITSIZE/8, MBS_SHA512, sizeof(Ipp64u)*2, {CONST_64(0xFFFFFFFFFFFFFFFF),CONST_64(0x2000000000000000-1)}} +}; diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashmd5px.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashmd5px.c new file mode 100644 index 0000000000..d6a93dd22f --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashmd5px.c @@ -0,0 +1,197 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcphash.h" +#include "pcptool.h" + +#pragma message("IPP_ALG_HASH_MD5 enabled") + + +/* +// Magic functions defined in RFC 1321 +// +*/ +#define F(X,Y,Z) ((Z) ^ ((X) & ((Y) ^ (Z)))) /* sightly optimized form of (((X) & (Y)) | ((~(X) & (Z)))*/ +#define G(X,Y,Z) F((Z),(X),(Y)) /* replace the original (((X) & (Z)) | ((Y) & ~(Z))) */ +#define H(X,Y,Z) ((X) ^ (Y) ^ (Z)) +#define I(X,Y,Z) ((Y) ^ ((X) | ~(Z))) + +/* +// MD5 step +*/ +#define MD5_STEP(MAGIC, A,B,C,D, data, constant, nrot) \ + (A = B +ROL32((A +MAGIC(B,C,D) +data +constant), nrot)) + +/* +// MD5 left rotations (number of bits) +// depends on round type +*/ +#define F1 7 +#define F2 12 +#define F3 17 +#define F4 22 + +#define G1 5 +#define G2 9 +#define G3 14 +#define G4 20 + +#define H1 4 +#define H2 11 +#define H3 16 +#define H4 23 + +#define I1 6 +#define I2 10 +#define I3 15 +#define I4 21 + +/*F* +// Name: UpdateMD5 +// +// Purpose: Update internal hash according to input message stream. +// +// Parameters: +// uniHash pointer to in/out hash +// mblk pointer to message stream +// mlen message stream length (multiple by message block size) +// uniParam pointer to the optional parameter +// +*F*/ +void UpdateMD5(void* uinHash, const Ipp8u* mblk, int mlen, const void* uniParam) +{ + Ipp32u* digest = (Ipp32u*)uinHash; + Ipp32u* MD5_cnt_loc = (Ipp32u*)uniParam; + + for(; mlen>=MBS_MD5; mblk += MBS_MD5, mlen -= MBS_MD5) { + + /* allocate data */ + #if (IPP_ENDIAN == IPP_BIG_ENDIAN) + Ipp32u data[MBS_MD5/sizeof(Ipp32u)]; + #else + /* or just word alias */ + Ipp32u* data = (Ipp32u*)mblk; + #endif + + /* init variables */ + Ipp32u a = digest[0]; + Ipp32u b = digest[1]; + Ipp32u c = digest[2]; + Ipp32u d = digest[3]; + + #if (IPP_ENDIAN == IPP_BIG_ENDIAN) + int t; + for(t=0; t<16; t++) { + data[t] = ENDIANNESS(((Ipp32u*)mblk)[t]); + } + #endif + + /* rounds type F */ + MD5_STEP(F, a,b,c,d, data[ 0], MD5_cnt_loc[ 0], F1); + MD5_STEP(F, d,a,b,c, data[ 1], MD5_cnt_loc[ 1], F2); + MD5_STEP(F, c,d,a,b, data[ 2], MD5_cnt_loc[ 2], F3); + MD5_STEP(F, b,c,d,a, data[ 3], MD5_cnt_loc[ 3], F4); + MD5_STEP(F, a,b,c,d, data[ 4], MD5_cnt_loc[ 4], F1); + MD5_STEP(F, d,a,b,c, data[ 5], MD5_cnt_loc[ 5], F2); + MD5_STEP(F, c,d,a,b, data[ 6], MD5_cnt_loc[ 6], F3); + MD5_STEP(F, b,c,d,a, data[ 7], MD5_cnt_loc[ 7], F4); + MD5_STEP(F, a,b,c,d, data[ 8], MD5_cnt_loc[ 8], F1); + MD5_STEP(F, d,a,b,c, data[ 9], MD5_cnt_loc[ 9], F2); + MD5_STEP(F, c,d,a,b, data[10], MD5_cnt_loc[10], F3); + MD5_STEP(F, b,c,d,a, data[11], MD5_cnt_loc[11], F4); + MD5_STEP(F, a,b,c,d, data[12], MD5_cnt_loc[12], F1); + MD5_STEP(F, d,a,b,c, data[13], MD5_cnt_loc[13], F2); + MD5_STEP(F, c,d,a,b, data[14], MD5_cnt_loc[14], F3); + MD5_STEP(F, b,c,d,a, data[15], MD5_cnt_loc[15], F4); + + /* rounds type G */ + MD5_STEP(G, a,b,c,d, data[ 1], MD5_cnt_loc[16], G1); + MD5_STEP(G, d,a,b,c, data[ 6], MD5_cnt_loc[17], G2); + MD5_STEP(G, c,d,a,b, data[11], MD5_cnt_loc[18], G3); + MD5_STEP(G, b,c,d,a, data[ 0], MD5_cnt_loc[19], G4); + MD5_STEP(G, a,b,c,d, data[ 5], MD5_cnt_loc[20], G1); + MD5_STEP(G, d,a,b,c, data[10], MD5_cnt_loc[21], G2); + MD5_STEP(G, c,d,a,b, data[15], MD5_cnt_loc[22], G3); + MD5_STEP(G, b,c,d,a, data[ 4], MD5_cnt_loc[23], G4); + MD5_STEP(G, a,b,c,d, data[ 9], MD5_cnt_loc[24], G1); + MD5_STEP(G, d,a,b,c, data[14], MD5_cnt_loc[25], G2); + MD5_STEP(G, c,d,a,b, data[ 3], MD5_cnt_loc[26], G3); + MD5_STEP(G, b,c,d,a, data[ 8], MD5_cnt_loc[27], G4); + MD5_STEP(G, a,b,c,d, data[13], MD5_cnt_loc[28], G1); + MD5_STEP(G, d,a,b,c, data[ 2], MD5_cnt_loc[29], G2); + MD5_STEP(G, c,d,a,b, data[ 7], MD5_cnt_loc[30], G3); + MD5_STEP(G, b,c,d,a, data[12], MD5_cnt_loc[31], G4); + + /* rounds type H */ + MD5_STEP(H, a,b,c,d, data[ 5], MD5_cnt_loc[32], H1); + MD5_STEP(H, d,a,b,c, data[ 8], MD5_cnt_loc[33], H2); + MD5_STEP(H, c,d,a,b, data[11], MD5_cnt_loc[34], H3); + MD5_STEP(H, b,c,d,a, data[14], MD5_cnt_loc[35], H4); + MD5_STEP(H, a,b,c,d, data[ 1], MD5_cnt_loc[36], H1); + MD5_STEP(H, d,a,b,c, data[ 4], MD5_cnt_loc[37], H2); + MD5_STEP(H, c,d,a,b, data[ 7], MD5_cnt_loc[38], H3); + MD5_STEP(H, b,c,d,a, data[10], MD5_cnt_loc[39], H4); + MD5_STEP(H, a,b,c,d, data[13], MD5_cnt_loc[40], H1); + MD5_STEP(H, d,a,b,c, data[ 0], MD5_cnt_loc[41], H2); + MD5_STEP(H, c,d,a,b, data[ 3], MD5_cnt_loc[42], H3); + MD5_STEP(H, b,c,d,a, data[ 6], MD5_cnt_loc[43], H4); + MD5_STEP(H, a,b,c,d, data[ 9], MD5_cnt_loc[44], H1); + MD5_STEP(H, d,a,b,c, data[12], MD5_cnt_loc[45], H2); + MD5_STEP(H, c,d,a,b, data[15], MD5_cnt_loc[46], H3); + MD5_STEP(H, b,c,d,a, data[ 2], MD5_cnt_loc[47], H4); + + /* rounds type I */ + MD5_STEP(I, a,b,c,d, data[ 0], MD5_cnt_loc[48], I1); + MD5_STEP(I, d,a,b,c, data[ 7], MD5_cnt_loc[49], I2); + MD5_STEP(I, c,d,a,b, data[14], MD5_cnt_loc[50], I3); + MD5_STEP(I, b,c,d,a, data[ 5], MD5_cnt_loc[51], I4); + MD5_STEP(I, a,b,c,d, data[12], MD5_cnt_loc[52], I1); + MD5_STEP(I, d,a,b,c, data[ 3], MD5_cnt_loc[53], I2); + MD5_STEP(I, c,d,a,b, data[10], MD5_cnt_loc[54], I3); + MD5_STEP(I, b,c,d,a, data[ 1], MD5_cnt_loc[55], I4); + MD5_STEP(I, a,b,c,d, data[ 8], MD5_cnt_loc[56], I1); + MD5_STEP(I, d,a,b,c, data[15], MD5_cnt_loc[57], I2); + MD5_STEP(I, c,d,a,b, data[ 6], MD5_cnt_loc[58], I3); + MD5_STEP(I, b,c,d,a, data[13], MD5_cnt_loc[59], I4); + MD5_STEP(I, a,b,c,d, data[ 4], MD5_cnt_loc[60], I1); + MD5_STEP(I, d,a,b,c, data[11], MD5_cnt_loc[61], I2); + MD5_STEP(I, c,d,a,b, data[ 2], MD5_cnt_loc[62], I3); + MD5_STEP(I, b,c,d,a, data[ 9], MD5_cnt_loc[63], I4); + + /* update digest */ + digest[0] += a; + digest[1] += b; + digest[2] += c; + digest[3] += d; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashsha1px.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashsha1px.c new file mode 100644 index 0000000000..77b7c184e1 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashsha1px.c @@ -0,0 +1,174 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcphash.h" +#include "pcptool.h" + + +/* +// Magic functions defined in FIPS 180-1 +// +*/ +#define MAGIC_F0(B,C,D) (((B) & (C)) | ((~(B)) & (D))) +#define MAGIC_F1(B,C,D) ((B) ^ (C) ^ (D)) +#define MAGIC_F2(B,C,D) (((B) & (C)) | ((B) & (D)) | ((C) & (D))) +#define MAGIC_F3(B,C,D) ((B) ^ (C) ^ (D)) + +#define SHA1_STEP(A,B,C,D,E, MAGIC_FUN, W,K) \ + (E)+= ROL32((A),5) + MAGIC_FUN((B),(C),(D)) + (W) + (K); \ + (B) = ROL32((B),30) + +#define COMPACT_SHA1_STEP(A,B,C,D,E, MAGIC_FUN, W,K, t) { \ + Ipp32u _T = ROL32((A),5) + MAGIC_FUN((t)/20, (B),(C),(D)) + (E) + (W)[(t)] + (K)[(t)/20]; \ + (E) = (D); \ + (D) = (C); \ + (C) = ROL32((B),30); \ + (B) = (A); \ + (A) = _T; \ +} + +#if defined(_ALG_SHA1_COMPACT_) +__INLINE Ipp32u MagicFun(int s, Ipp32u b, Ipp32u c, Ipp32u d) +{ + switch(s) { + case 0: return MAGIC_F0(b,c,d); + case 2: return MAGIC_F2(b,c,d); + default:return MAGIC_F1(b,c,d); + } +} +#endif + + +/*F* +// Name: UpdateSHA1 +// +// Purpose: Update internal hash according to input message stream. +// +// Parameters: +// uniHash pointer to in/out hash +// mblk pointer to message stream +// mlen message stream length (multiple by message block size) +// uniParam pointer to the optional parameter +// +*F*/ +#if defined(_ALG_SHA1_COMPACT_) +#pragma message("SHA1 compact") +#endif + +void UpdateSHA1(void* uinHash, const Ipp8u* mblk, int mlen, const void *uniParam) +{ + Ipp32u* data = (Ipp32u*)mblk; + + Ipp32u* digest = (Ipp32u*)uinHash; + Ipp32u* SHA1_cnt_loc = (Ipp32u*)uniParam; + + for(; mlen>=MBS_SHA1; data += MBS_SHA1/sizeof(Ipp32u), mlen -= MBS_SHA1) { + int t; + + /* + // expand message block + */ + Ipp32u W[80]; + /* initialize the first 16 words in the array W (remember about endian) */ + for(t=0; t<16; t++) { + #if (IPP_ENDIAN == IPP_BIG_ENDIAN) + W[t] = data[t]; + #else + W[t] = ENDIANNESS(data[t]); + #endif + } + /* schedule another 80-16 words in the array W */ + for(; t<80; t++) { + W[t] = ROL32(W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1); + } + + /* + // update hash + */ + { + /* init A, B, C, D, E by the the input hash */ + Ipp32u A = digest[0]; + Ipp32u B = digest[1]; + Ipp32u C = digest[2]; + Ipp32u D = digest[3]; + Ipp32u E = digest[4]; + + #if defined(_ALG_SHA1_COMPACT_) + /* steps 0-79 */ + for(t=0; t<80; t++) + COMPACT_SHA1_STEP(A,B,C,D,E, MagicFun, W, SHA1_cnt_loc, t); + + #else + /* perform 0-19 steps */ + for(t=0; t<20; t+=5) { + SHA1_STEP(A,B,C,D,E, MAGIC_F0, W[t ],SHA1_cnt_loc[0]); + SHA1_STEP(E,A,B,C,D, MAGIC_F0, W[t+1],SHA1_cnt_loc[0]); + SHA1_STEP(D,E,A,B,C, MAGIC_F0, W[t+2],SHA1_cnt_loc[0]); + SHA1_STEP(C,D,E,A,B, MAGIC_F0, W[t+3],SHA1_cnt_loc[0]); + SHA1_STEP(B,C,D,E,A, MAGIC_F0, W[t+4],SHA1_cnt_loc[0]); + } + /* perform 20-39 steps */ + for(; t<40; t+=5) { + SHA1_STEP(A,B,C,D,E, MAGIC_F1, W[t ],SHA1_cnt_loc[1]); + SHA1_STEP(E,A,B,C,D, MAGIC_F1, W[t+1],SHA1_cnt_loc[1]); + SHA1_STEP(D,E,A,B,C, MAGIC_F1, W[t+2],SHA1_cnt_loc[1]); + SHA1_STEP(C,D,E,A,B, MAGIC_F1, W[t+3],SHA1_cnt_loc[1]); + SHA1_STEP(B,C,D,E,A, MAGIC_F1, W[t+4],SHA1_cnt_loc[1]); + } + /* perform 40-59 steps */ + for(; t<60; t+=5) { + SHA1_STEP(A,B,C,D,E, MAGIC_F2, W[t ],SHA1_cnt_loc[2]); + SHA1_STEP(E,A,B,C,D, MAGIC_F2, W[t+1],SHA1_cnt_loc[2]); + SHA1_STEP(D,E,A,B,C, MAGIC_F2, W[t+2],SHA1_cnt_loc[2]); + SHA1_STEP(C,D,E,A,B, MAGIC_F2, W[t+3],SHA1_cnt_loc[2]); + SHA1_STEP(B,C,D,E,A, MAGIC_F2, W[t+4],SHA1_cnt_loc[2]); + } + /* perform 60-79 steps */ + for(; t<80; t+=5) { + SHA1_STEP(A,B,C,D,E, MAGIC_F3, W[t ],SHA1_cnt_loc[3]); + SHA1_STEP(E,A,B,C,D, MAGIC_F3, W[t+1],SHA1_cnt_loc[3]); + SHA1_STEP(D,E,A,B,C, MAGIC_F3, W[t+2],SHA1_cnt_loc[3]); + SHA1_STEP(C,D,E,A,B, MAGIC_F3, W[t+3],SHA1_cnt_loc[3]); + SHA1_STEP(B,C,D,E,A, MAGIC_F3, W[t+4],SHA1_cnt_loc[3]); + } + #endif + + /* update digest */ + digest[0] += A; + digest[1] += B; + digest[2] += C; + digest[3] += D; + digest[4] += E; + } + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashsha256px.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashsha256px.c new file mode 100644 index 0000000000..932b9cb335 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashsha256px.c @@ -0,0 +1,199 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcphash.h" +#include "pcptool.h" + + +/* +// SHA256 Specific Macros (reference proposal 256-384-512) +*/ +#define CH(x,y,z) (((x) & (y)) ^ (~(x) & (z))) +#define MAJ(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) + +#define SUM0(x) (ROR32((x), 2) ^ ROR32((x),13) ^ ROR32((x),22)) +#define SUM1(x) (ROR32((x), 6) ^ ROR32((x),11) ^ ROR32((x),25)) + +#define SIG0(x) (ROR32((x), 7) ^ ROR32((x),18) ^ LSR32((x), 3)) +#define SIG1(x) (ROR32((x),17) ^ ROR32((x),19) ^ LSR32((x),10)) + +#define SHA256_UPDATE(i) \ + wdat[i & 15] += SIG1(wdat[(i+14)&15]) + wdat[(i+9)&15] + SIG0(wdat[(i+1)&15]) + +#define SHA256_STEP(i,j) \ + v[(7 - i) & 7] += (j ? SHA256_UPDATE(i) : wdat[i&15]) \ + + SHA256_cnt_loc[i + j] \ + + SUM1(v[(4-i)&7]) \ + + CH(v[(4-i)&7], v[(5-i)&7], v[(6-i)&7]); \ + v[(3-i)&7] += v[(7-i)&7]; \ + v[(7-i)&7] += SUM0(v[(0-i)&7]) + MAJ(v[(0-i)&7], v[(1-i)&7], v[(2-i)&7]) + +#define COMPACT_SHA256_STEP(A,B,C,D,E,F,G,H, W,K, r) { \ + Ipp32u _T1 = (H) + SUM1((E)) + CH((E),(F),(G)) + (W)[(r)] + (K)[(r)]; \ + Ipp32u _T2 = SUM0((A)) + MAJ((A),(B),(C)); \ + (H) = (G); \ + (G) = (F); \ + (F) = (E); \ + (E) = (D)+_T1; \ + (D) = (C); \ + (C) = (B); \ + (B) = (A); \ + (A) = _T1+_T2; \ +} + +/*F* +// Name: UpdateSHA256 +// +// Purpose: Update internal hash according to input message stream. +// +// Parameters: +// uniHash pointer to in/out hash +// mblk pointer to message stream +// mlen message stream length (multiple by message block size) +// uniParam pointer to the optional parameter +// +*F*/ +#if defined(_ALG_SHA256_COMPACT_) +#pragma message("SHA256 compact") + +void UpdateSHA256(void* uniHash, const Ipp8u* mblk, int mlen, const void* uniParam) +{ + Ipp32u* data = (Ipp32u*)mblk; + + Ipp32u* digest = (Ipp32u*)uniHash; + Ipp32u* SHA256_cnt_loc = (Ipp32u*)uniParam; + + for(; mlen>=MBS_SHA256; data += MBS_SHA256/sizeof(Ipp32u), mlen -= MBS_SHA256) { + int t; + + /* + // expand message block + */ + Ipp32u W[64]; + /* initialize the first 16 words in the array W (remember about endian) */ + for(t=0; t<16; t++) { + #if (IPP_ENDIAN == IPP_BIG_ENDIAN) + W[t] = data[t]; + #else + W[t] = ENDIANNESS( data[t] ); + #endif + } + for(; t<64; t++) + W[t] = SIG1(W[t-2]) + W[t-7] + SIG0(W[t-15]) + W[t-16]; + + /* + // update hash + */ + { + /* init A, B, C, D, E, F, G, H by the input hash */ + Ipp32u A = digest[0]; + Ipp32u B = digest[1]; + Ipp32u C = digest[2]; + Ipp32u D = digest[3]; + Ipp32u E = digest[4]; + Ipp32u F = digest[5]; + Ipp32u G = digest[6]; + Ipp32u H = digest[7]; + + for(t=0; t<64; t++) + COMPACT_SHA256_STEP(A,B,C,D,E,F,G,H, W,SHA256_cnt_loc, t); + + /* update hash*/ + digest[0] += A; + digest[1] += B; + digest[2] += C; + digest[3] += D; + digest[4] += E; + digest[5] += F; + digest[6] += G; + digest[7] += H; + } + } +} + +#else +void UpdateSHA256(void* uniHash, const Ipp8u* mblk, int mlen, const void* uniParam) +{ + Ipp32u* data = (Ipp32u*)mblk; + + Ipp32u* digest = (Ipp32u*)uniHash; + Ipp32u* SHA256_cnt_loc = (Ipp32u*)uniParam; + + for(; mlen>=MBS_SHA256; data += MBS_SHA256/sizeof(Ipp32u), mlen -= MBS_SHA256) { + Ipp32u wdat[16]; + int j; + + /* copy digest */ + Ipp32u v[8]; + CopyBlock(digest, v, IPP_SHA256_DIGEST_BITSIZE/BYTESIZE); + + /* initialize the first 16 words in the array W (remember about endian) */ + for(j=0; j<16; j++) { + #if (IPP_ENDIAN == IPP_BIG_ENDIAN) + wdat[j] = data[j]; + #else + wdat[j] = ENDIANNESS( data[j] ); + #endif + } + + for(j=0; j<64; j+=16) { + SHA256_STEP( 0, j); + SHA256_STEP( 1, j); + SHA256_STEP( 2, j); + SHA256_STEP( 3, j); + SHA256_STEP( 4, j); + SHA256_STEP( 5, j); + SHA256_STEP( 6, j); + SHA256_STEP( 7, j); + SHA256_STEP( 8, j); + SHA256_STEP( 9, j); + SHA256_STEP(10, j); + SHA256_STEP(11, j); + SHA256_STEP(12, j); + SHA256_STEP(13, j); + SHA256_STEP(14, j); + SHA256_STEP(15, j); + } + + /* update digest */ + digest[0] += v[0]; + digest[1] += v[1]; + digest[2] += v[2]; + digest[3] += v[3]; + digest[4] += v[4]; + digest[5] += v[5]; + digest[6] += v[6]; + digest[7] += v[7]; + } +} +#endif diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashsha512px.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashsha512px.c new file mode 100644 index 0000000000..6b8983d467 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphashsha512px.c @@ -0,0 +1,207 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcphash.h" +#include "pcptool.h" + + +/* +// SHA512 Specific Macros (reference proposal 256-384-512) +// +// Note: All operations act on DWORDs (64-bits) +*/ +#define CH(x,y,z) (((x) & (y)) ^ (~(x) & (z))) +#define MAJ(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) + +#define SUM0(x) (ROR64((x),28) ^ ROR64((x),34) ^ ROR64((x),39)) +#define SUM1(x) (ROR64((x),14) ^ ROR64((x),18) ^ ROR64((x),41)) + +#define SIG0(x) (ROR64((x), 1) ^ ROR64((x), 8) ^ LSR64((x), 7)) +#define SIG1(x) (ROR64((x),19) ^ ROR64((x),61) ^ LSR64((x), 6)) + +#define SHA512_UPDATE(i) \ + wdat[i&15] += SIG1(wdat[(i+14)&15]) + wdat[(i+9)&15] + SIG0(wdat[(i+1)&15]) + +#define SHA512_STEP(i,j) \ + v[(7-i)&7] += (j ? SHA512_UPDATE(i) : wdat[i&15]) \ + + SHA512_cnt_loc[i+j] \ + + SUM1(v[(4-i)&7]) \ + + CH(v[(4-i)&7], v[(5-i)&7], v[(6-i)&7]); \ + v[(3-i)&7] += v[(7-i)&7]; \ + v[(7-i)&7] += SUM0(v[(0-i)&7]) + MAJ(v[(0-i)&7], v[(1-i)&7], v[(2-i)&7]) + +#define COMPACT_SHA512_STEP(A,B,C,D,E,F,G,H, W,K, r) { \ + Ipp64u _T1 = (H) + SUM1((E)) + CH((E),(F),(G)) + (W)[(r)] + (K)[(r)]; \ + Ipp64u _T2 = SUM0((A)) + MAJ((A),(B),(C)); \ + (H) = (G); \ + (G) = (F); \ + (F) = (E); \ + (E) = (D)+_T1; \ + (D) = (C); \ + (C) = (B); \ + (B) = (A); \ + (A) = _T1+_T2; \ +} + +/*F* +// Name: UpdateSHA512 +// +// Purpose: Update internal hash according to input message stream. +// +// Parameters: +// uniHash pointer to in/out hash +// mblk pointer to message stream +// mlen message stream length (multiple by message block size) +// uniParam pointer to the optional parameter +// +*F*/ +#if defined(_ALG_SHA512_COMPACT_) +#pragma message("SHA512 compact") + +void UpdateSHA512(void* uniHash, const Ipp8u* mblk, int mlen, const void* uniPraram) +{ + Ipp32u* data = (Ipp32u*)mblk; + + Ipp64u* digest = (Ipp64u*)uniHash; + Ipp64u* SHA512_cnt_loc = (Ipp64u*)uniPraram; + + + for(; mlen>=MBS_SHA512; data += MBS_SHA512/sizeof(Ipp32u), mlen -= MBS_SHA512) { + int t; + Ipp64u W[80]; + + /* + // expand message block + */ + /* initialize the first 16 words in the array W (remember about endian) */ + for(t=0; t<16; t++) { + Ipp32u hiX = data[2*t]; + Ipp32u loX = data[2*t+1]; + #if (IPP_ENDIAN == IPP_BIG_ENDIAN) + W[t] = MAKEDWORD(loX, hiX); + #else + W[t] = MAKEDWORD( ENDIANNESS(loX), ENDIANNESS(hiX) ); + #endif + } + for(; t<80; t++) + W[t] = SIG1(W[t-2]) + W[t-7] + SIG0(W[t-15]) + W[t-16]; + + /* + // update hash + */ + { + /* init A, B, C, D, E, F, G, H by the input hash */ + Ipp64u A = digest[0]; + Ipp64u B = digest[1]; + Ipp64u C = digest[2]; + Ipp64u D = digest[3]; + Ipp64u E = digest[4]; + Ipp64u F = digest[5]; + Ipp64u G = digest[6]; + Ipp64u H = digest[7]; + + for(t=0; t<80; t++) + COMPACT_SHA512_STEP(A,B,C,D,E,F,G,H, W,SHA512_cnt_loc, t); + + /* update hash*/ + digest[0] += A; + digest[1] += B; + digest[2] += C; + digest[3] += D; + digest[4] += E; + digest[5] += F; + digest[6] += G; + digest[7] += H; + } + } +} + +#else +void UpdateSHA512(void* uniHash, const Ipp8u* mblk, int mlen, const void* uniPraram) +{ + Ipp32u* data = (Ipp32u*)mblk; + + Ipp64u* digest = (Ipp64u*)uniHash; + Ipp64u* SHA512_cnt_loc = (Ipp64u*)uniPraram; + + for(; mlen>=MBS_SHA512; data += MBS_SHA512/sizeof(Ipp32u), mlen -= MBS_SHA512) { + Ipp64u wdat[16]; + int j; + + Ipp64u v[8]; + + /* initialize the first 16 words in the array W (remember about endian) */ + for(j=0; j<16; j++) { + Ipp32u hiX = data[2*j]; + Ipp32u loX = data[2*j+1]; + #if (IPP_ENDIAN == IPP_BIG_ENDIAN) + wdat[j] = MAKEDWORD(loX, hiX); + #else + wdat[j] = MAKEDWORD( ENDIANNESS(loX), ENDIANNESS(hiX) ); + #endif + } + + /* copy digest */ + CopyBlock(digest, v, IPP_SHA512_DIGEST_BITSIZE/BYTESIZE); + + for(j=0; j<80; j+=16) { + SHA512_STEP( 0, j); + SHA512_STEP( 1, j); + SHA512_STEP( 2, j); + SHA512_STEP( 3, j); + SHA512_STEP( 4, j); + SHA512_STEP( 5, j); + SHA512_STEP( 6, j); + SHA512_STEP( 7, j); + SHA512_STEP( 8, j); + SHA512_STEP( 9, j); + SHA512_STEP(10, j); + SHA512_STEP(11, j); + SHA512_STEP(12, j); + SHA512_STEP(13, j); + SHA512_STEP(14, j); + SHA512_STEP(15, j); + } + + /* update digest */ + digest[0] += v[0]; + digest[1] += v[1]; + digest[2] += v[2]; + digest[3] += v[3]; + digest[4] += v[4]; + digest[5] += v[5]; + digest[6] += v[6]; + digest[7] += v[7]; + } +} +#endif diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphmac.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphmac.h new file mode 100644 index 0000000000..65374dbb87 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphmac.h @@ -0,0 +1,55 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_PCP_HMAC_H) +#define _PCP_HMAC_H + +#include "pcphash.h" + +/* +// HMAC context +*/ +struct _cpHMAC { + IppCtxId idCtx; /* HMAC identifier */ + Ipp8u ipadKey[MBS_HASH_MAX]; /* inner padding key */ + Ipp8u opadKey[MBS_HASH_MAX]; /* outer padding key */ + IppsHashState hashCtx; /* hash context */ +}; + +/* accessors */ +#define HMAC_CTX_ID(stt) ((stt)->idCtx) +#define HASH_CTX(stt) ((stt)->hashCtx) +#define HMAC_VALID_ID(stt) (HMAC_CTX_ID((stt))==idCtxHMAC) + +#define IPAD (0x36) /* inner padding value */ +#define OPAD (0x5C) /* outer padding value */ + +#endif /* _PCP_HMAC_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphmacca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphmacca.c new file mode 100644 index 0000000000..524d26f49b --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcphmacca.c @@ -0,0 +1,332 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcphmac.h" +#include "pcptool.h" + +/*F* +// Name: ippsHMAC_GetSize +// +// Purpose: Returns size of HMAC state (bytes). +// +// Returns: Reason: +// ippStsNullPtrErr pSzie == NULL +// ippStsNoErr no errors +// +// Parameters: +// pSize pointer to the HMAC state size +// +*F*/ +IPPFUN(IppStatus, ippsHMAC_GetSize,(int* pSize)) +{ + /* test size's pointer */ + IPP_BAD_PTR1_RET(pSize); + + *pSize = sizeof(IppsHMACState); + return ippStsNoErr; +} + +/*F* +// Name: ippsHMAC_Init +// +// Purpose: Init HMAC state. +// +// Returns: Reason: +// ippStsNullPtrErr pKey == NULL +// pState == NULL +// ippStsLengthErr keyLen <0 +// ippStsNotSupportedModeErr if algID is not match to supported hash alg +// ippStsNoErr no errors +// +// Parameters: +// pKey pointer to the secret key +// keyLen length (bytes) of the secret key +// pState pointer to the HMAC state +// hashAlg hash alg ID +// +*F*/ +IPPFUN(IppStatus, ippsHMAC_Init,(const Ipp8u* pKey, int keyLen, IppsHMACState* pCtx, IppHashAlgId hashAlg)) +{ + //int mbs; + + /* get algorithm id */ + hashAlg = cpValidHashAlg(hashAlg); + /* test hash alg */ + IPP_BADARG_RET(ippHashAlg_Unknown==hashAlg, ippStsNotSupportedModeErr); + //mbs = cpHashMBS(hashAlg); + + /* test pState pointer */ + IPP_BAD_PTR1_RET(pCtx); + + /* test key pointer and key length */ + IPP_BAD_PTR1_RET(pKey); + IPP_BADARG_RET(0>keyLen, ippStsLengthErr); + + /* set state ID */ + HMAC_CTX_ID(pCtx) = idCtxHMAC; + + /* init hash context */ + ippsHashInit(&HASH_CTX(pCtx), hashAlg); + + { + int n; + + /* hash specific */ + IppsHashState* pHashCtx = &HASH_CTX(pCtx); + int mbs = cpHashMBS(hashAlg); + int hashSize = cpHashSize(hashAlg); + + /* copyMask = keyLen>mbs? 0xFF : 0x00 */ + int copyMask = (mbs-keyLen) >>(BITSIZE(int)-1); + + /* actualKeyLen = keyLen>mbs? hashSize:keyLen */ + int actualKeyLen = (hashSize & copyMask) | (keyLen & ~copyMask); + + /* compute hash(key, keyLen) just in case */ + ippsHashUpdate(pKey, keyLen, pHashCtx); + ippsHashFinal(HASH_BUFF(pHashCtx), pHashCtx); + + /* copy either key or hash(key) into ipad- and opad- buffers */ + MASKED_COPY_BNU(pCtx->ipadKey, (Ipp8u)copyMask, HASH_BUFF(pHashCtx), pKey, actualKeyLen); + MASKED_COPY_BNU(pCtx->opadKey, (Ipp8u)copyMask, HASH_BUFF(pHashCtx), pKey, actualKeyLen); + + /* XOR-ing key */ + for(n=0; nipadKey[n] ^= (Ipp8u)IPAD; + pCtx->opadKey[n] ^= (Ipp8u)OPAD; + } + for(; nipadKey[n] = (Ipp8u)IPAD; + pCtx->opadKey[n] = (Ipp8u)OPAD; + } + + /* ipad key processing */ + ippsHashUpdate(pCtx->ipadKey, mbs, pHashCtx); + + return ippStsNoErr; + } +} + +/*F* +// Name: ippsHMAC_Update +// +// Purpose: Updates intermadiate MAC based on input stream. +// +// Returns: Reason: +// ippStsNullPtrErr pSrc == NULL +// pState == NULL +// ippStsContextMatchErr pState->idCtx != idCtxHMAC +// ippStsLengthErr len <0 +// ippStsNoErr no errors +// +// Parameters: +// pSrc pointer to the input stream +// len input stream length +// pState pointer to the HMAC state +// +*F*/ +IPPFUN(IppStatus, ippsHMAC_Update,(const Ipp8u* pSrc, int len, IppsHMACState* pCtx)) +{ + /* test state pointers */ + IPP_BAD_PTR1_RET(pCtx); + + /* test state ID */ + IPP_BADARG_RET(!HMAC_VALID_ID(pCtx), ippStsContextMatchErr); + /* test input length */ + IPP_BADARG_RET((len<0), ippStsLengthErr); + /* test source pointer */ + IPP_BADARG_RET((len && !pSrc), ippStsNullPtrErr); + + if(len) + return ippsHashUpdate(pSrc, len, &HASH_CTX(pCtx)); + else + return ippStsNoErr; +} + +/*F* +// Name: ippsHMAC_Final +// +// Purpose: Stop message digesting and return digest. +// +// Returns: Reason: +// ippStsNullPtrErr pMD == NULL +// pState == NULL +// ippStsContextMatchErr pState->idCtx != idCtxHMAC +// ippStsLengthErr sizeof(DigestMD5) < mdLen <1 +// ippStsNoErr no errors +// +// Parameters: +// pMD address of the output digest +// pState pointer to the HMAC state +// +*F*/ +IPPFUN(IppStatus, ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) +{ + /* test state pointer and ID */ + IPP_BAD_PTR1_RET(pCtx); + IPP_BADARG_RET(!HMAC_VALID_ID(pCtx), ippStsContextMatchErr); + + /* test MD pointer and length */ + IPP_BAD_PTR1_RET(pMD); + IPP_BADARG_RET(mdLen<=0, ippStsLengthErr); + + { + /* hash specific */ + IppsHashState* pHashCtx = &HASH_CTX(pCtx); + int mbs = cpHashMBS(HASH_ALG_ID(pHashCtx)); + int hashSize = cpHashSize(HASH_ALG_ID(pHashCtx)); + if(mdLen>hashSize) + IPP_ERROR_RET(ippStsLengthErr); + + /* + // finalize hmac + */ + { + /* finalize 1-st step */ + Ipp8u md[IPP_SHA512_DIGEST_BITSIZE/8]; + IppStatus sts = ippsHashFinal(md, pHashCtx); + + if(ippStsNoErr==sts) { + /* perform outer hash */ + ippsHashUpdate(pCtx->opadKey, mbs, pHashCtx); + ippsHashUpdate(md, hashSize, pHashCtx); + + /* complete HMAC */ + ippsHashFinal(md, pHashCtx); + CopyBlock(md, pMD, IPP_MIN(hashSize, mdLen)); + + /* ready to the next HMAC computation */ + ippsHashUpdate(pCtx->ipadKey, mbs, pHashCtx); + } + + return sts; + } + } +} + +/*F* +// Name: ippsHMAC_GetTag +// +// Purpose: Compute digest with further digesting ability. +// +// Returns: Reason: +// ippStsNullPtrErr pMD == NULL +// pState == NULL +// ippStsContextMatchErr pState->idCtx != idCtxHMAC +// ippStsLengthErr size_of_digest < mdLen <1 +// ippStsNoErr no errors +// +// Parameters: +// pMD address of the output digest +// mdLen length of the digest +// pState pointer to the HMAC state +// +*F*/ +IPPFUN(IppStatus, ippsHMAC_GetTag,(Ipp8u* pMD, int mdLen, const IppsHMACState* pCtx)) +{ + /* test state pointer and ID */ + IPP_BAD_PTR1_RET(pCtx); + IPP_BADARG_RET(!HMAC_VALID_ID(pCtx), ippStsContextMatchErr); + + /* test MD pointer */ + IPP_BAD_PTR1_RET(pMD); + + { + IppsHMACState tmpCtx; + CopyBlock(pCtx, &tmpCtx, sizeof(IppsHMACState)); + return ippsHMAC_Final(pMD, mdLen, &tmpCtx); + } +} + +/*F* +// Name: ippsHMAC_Message +// +// Purpose: MAC of the whole message. +// +// Returns: Reason: +// ippStsNullPtrErr pMsg == NULL +// pKey == NULL +// pMD == NULL +// ippStsLengthErr msgLen <0 +// keyLen <0 +// size_of_digest < mdLen <1 +// ippStsNotSupportedModeErr if algID is not match to supported hash alg +// ippStsNoErr no errors +// +// Parameters: +// pMsg pointer to the input message +// msgLen input message length +// pKey pointer to the secret key +// keyLen secret key length +// pMD pointer to message digest +// mdLen MD length +// hashAlg hash alg ID +// +*F*/ +IPPFUN(IppStatus, ippsHMAC_Message,(const Ipp8u* pMsg, int msgLen, + const Ipp8u* pKey, int keyLen, + Ipp8u* pMD, int mdLen, + IppHashAlgId hashAlg)) +{ + /* get algorithm id */ + hashAlg = cpValidHashAlg(hashAlg); + /* test hash alg */ + IPP_BADARG_RET(ippHashAlg_Unknown==hashAlg, ippStsNotSupportedModeErr); + + /* test secret key pointer and length */ + IPP_BAD_PTR1_RET(pKey); + IPP_BADARG_RET((keyLen<0), ippStsLengthErr); + + /* test input message pointer and length */ + IPP_BADARG_RET((msgLen<0), ippStsLengthErr); + IPP_BADARG_RET((msgLen && !pMsg), ippStsNullPtrErr); + + /* test MD pointer and length */ + IPP_BAD_PTR1_RET(pMD); + IPP_BADARG_RET(0>=mdLen || mdLen>cpHashSize(hashAlg), ippStsLengthErr); + + { + IppsHMACState ctx; + IppStatus sts = ippsHMAC_Init(pKey, keyLen, &ctx, hashAlg); + if(ippStsNoErr!=sts) goto exit; + + sts = ippsHashUpdate(pMsg,msgLen, &HASH_CTX(&ctx)); + if(ippStsNoErr!=sts) goto exit; + + sts = ippsHMAC_Final(pMD, mdLen, &ctx); + + exit: + PurgeBlock(&ctx, sizeof(IppsHMACState)); + return sts; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpmontexpbinca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpmontexpbinca.c new file mode 100644 index 0000000000..fdc43b5127 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpmontexpbinca.c @@ -0,0 +1,116 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpbn.h" +#include "pcpmontgomery.h" + + +/* +// Binary method of Exponentiation +*/ +cpSize cpMontExpBin_BNU(BNU_CHUNK_T* dataY, + const BNU_CHUNK_T* dataX, cpSize nsX, + const BNU_CHUNK_T* dataE, cpSize nsE, + IppsMontState* pMont) +{ + cpSize nsM = MNT_SIZE(pMont); + + /* + // test for special cases: + // x^0 = 1 + // 0^e = 0 + */ + if( cpEqu_BNU_CHUNK(dataE, nsE, 0) ) { + COPY_BNU(dataY, MNT_1(pMont), nsM); + } + else if( cpEqu_BNU_CHUNK(dataX, nsX, 0) ) { + ZEXPAND_BNU(dataY, 0, nsM); + } + + /* general case */ + else { + BNU_CHUNK_T* dataM = MNT_MODULUS(pMont); + BNU_CHUNK_T m0 = MNT_HELPER(pMont); + + /* Montgomery engine buffers */ + BNU_CHUNK_T* pKBuffer = MNT_KBUFFER(pMont); + BNU_CHUNK_T* pProduct = MNT_PRODUCT(pMont); + + BNU_CHUNK_T* dataT = MNT_TBUFFER(pMont); + + /* execute most significant part pE */ + BNU_CHUNK_T eValue = dataE[nsE-1]; + int n = cpNLZ_BNU(eValue)+1; + + /* expand base and init result */ + ZEXPAND_COPY_BNU(dataT, nsM, dataX, nsX); + COPY_BNU(dataY, dataT, nsM); + + eValue <<= n; + for(; n0; nsE--) { + eValue = dataE[nsE-1]; + + for(n=0; nidCtx) +#define MNT_ROOM(eng) ((eng)->maxLen) +#define MNT_SIZE(eng) ((eng)->modLen) +#define MNT_HELPER(eng) ((eng)->m0) +#define MNT_MODULUS(eng) ((eng)->pModulus) +#define MNT_1(eng) ((eng)->pIdentity) +#define MNT_IDENT_R(eng) (MNT_1((eng))) +#define MNT_SQUARE_R(eng) ((eng)->pSquare) +#define MNT_CUBE_R(eng) ((eng)->pCube) +#define MNT_TBUFFER(eng) ((eng)->pTBuffer) +#define MNT_SBUFFER(eng) ((eng)->pSBuffer) +#define MNT_PRODUCT(eng) ((eng)->pProduct) +#define MNT_KBUFFER(eng) ((eng)->pKBuffer) + +#define MNT_VALID_ID(eng) (MNT_ID((eng))==idCtxMontgomery) + +/* default methos */ +#define EXPONENT_METHOD (ippBinaryMethod) + +/* alignment */ +#define MONT_ALIGNMENT ((int)(sizeof(void*))) + + +/* +// Pacp/unpack Montgomery context +*/ +void cpPackMontCtx(const IppsMontState* pCtx, Ipp8u* pBuffer); +void cpUnpackMontCtx(const Ipp8u* pBuffer, IppsMontState* pCtx); + + +/* +// Montgomery reduction, multiplication and squaring +*/ +void cpMontRedAdc_BNU(BNU_CHUNK_T* pR, + BNU_CHUNK_T* pProduct, + const BNU_CHUNK_T* pModulus, cpSize nsM, BNU_CHUNK_T m0); + +__INLINE void cpMontRed_BNU(BNU_CHUNK_T* pR, + BNU_CHUNK_T* pProduct, + const BNU_CHUNK_T* pModulus, cpSize nsM, BNU_CHUNK_T m0) +{ + cpMontRedAdc_BNU(pR, pProduct, pModulus, nsM, m0); +} + +__INLINE void cpMontMul_BNU(BNU_CHUNK_T* pR, + const BNU_CHUNK_T* pX, cpSize nsX, + const BNU_CHUNK_T* pY, cpSize nsY, + const BNU_CHUNK_T* pModulus, cpSize nsM, BNU_CHUNK_T m0, + BNU_CHUNK_T* pProduct, BNU_CHUNK_T* pKBuffer) +{ + cpMul_BNU(pProduct, pX,nsX, pY,nsY, pKBuffer); + ZEXPAND_BNU(pProduct,nsX+nsY, 2*nsM); + cpMontRed_BNU(pR, pProduct, pModulus, nsM, m0); +} + +__INLINE void cpMontSqr_BNU(BNU_CHUNK_T* pR, + const BNU_CHUNK_T* pX, cpSize nsX, + const BNU_CHUNK_T* pModulus, cpSize nsM, BNU_CHUNK_T m0, + BNU_CHUNK_T* pProduct, BNU_CHUNK_T* pKBuffer) +{ + cpSqr_BNU(pProduct, pX,nsX, pKBuffer); + ZEXPAND_BNU(pProduct, 2*nsX, 2*nsM); + cpMontRed_BNU(pR, pProduct, pModulus, nsM, m0); +} + +/* +// Montgomery encoding/decoding +*/ +__INLINE cpSize cpMontEnc_BNU(BNU_CHUNK_T* pR, + const BNU_CHUNK_T* pXreg, cpSize nsX, + IppsMontState* pMont) +{ + cpSize nsM = MNT_SIZE(pMont); + cpMontMul_BNU(pR, + pXreg, nsX, MNT_SQUARE_R(pMont), nsM, + MNT_MODULUS(pMont), nsM, MNT_HELPER(pMont), + MNT_PRODUCT(pMont), MNT_KBUFFER(pMont)); + + FIX_BNU(pR, nsM); + return nsM; +} + +__INLINE cpSize cpMontDec_BNU(BNU_CHUNK_T* pR, + const BNU_CHUNK_T* pXmont, cpSize nsX, + IppsMontState* pMont) +{ + cpSize nsM = MNT_SIZE(pMont); + ZEXPAND_COPY_BNU(MNT_PRODUCT(pMont), 2*nsM, pXmont, nsX); + + cpMontRed_BNU(pR, MNT_PRODUCT(pMont), MNT_MODULUS(pMont), nsM, MNT_HELPER(pMont)); + + FIX_BNU(pR, nsM); + return nsM; +} + +__INLINE void cpMontEnc_BN(IppsBigNumState* pRbn, + const IppsBigNumState* pXbn, + IppsMontState* pMont) +{ + BNU_CHUNK_T* pR = BN_NUMBER(pRbn); + cpSize nsM = MNT_SIZE(pMont); + cpMontMul_BNU(pR, + BN_NUMBER(pXbn), BN_SIZE(pXbn), + MNT_SQUARE_R(pMont), nsM, + MNT_MODULUS(pMont), nsM, MNT_HELPER(pMont), + MNT_PRODUCT(pMont), MNT_KBUFFER(pMont)); + + FIX_BNU(pR, nsM); + BN_SIZE(pRbn) = nsM; + BN_SIGN(pRbn) = ippBigNumPOS; +} + +__INLINE void cpMontDec_BN(IppsBigNumState* pRbn, + const IppsBigNumState* pXbn, + IppsMontState* pMont) +{ + BNU_CHUNK_T* pR = BN_NUMBER(pRbn); + cpSize nsM = MNT_SIZE(pMont); + ZEXPAND_COPY_BNU(MNT_PRODUCT(pMont), 2*nsM, BN_NUMBER(pXbn), BN_SIZE(pXbn)); + + cpMontRed_BNU(pR, MNT_PRODUCT(pMont), MNT_MODULUS(pMont), nsM, MNT_HELPER(pMont)); + + FIX_BNU(pR, nsM); + BN_SIZE(pRbn) = nsM; + BN_SIGN(pRbn) = ippBigNumPOS; +} + +/* +// Montgomery exponentiation (binary) +*/ +cpSize cpMontExpBin_BNU(BNU_CHUNK_T* pY, + const BNU_CHUNK_T* pX, cpSize nsX, + const BNU_CHUNK_T* pE, cpSize nsE, + IppsMontState* pMont); + +#endif /* _CP_MONTGOMETRY_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpmontgomeryca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpmontgomeryca.c new file mode 100644 index 0000000000..8459fd0249 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpmontgomeryca.c @@ -0,0 +1,296 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpbn.h" +#include "pcpmontgomery.h" +#include "pcptool.h" + +/*F* +// Name: ippsMontGetSize +// +// Purpose: Specifies size of buffer in bytes. +// +// Returns: Reason: +// ippStsNullPtrErr pCtxSize==NULL +// ippStsLengthErr maxLen32 < 1 +// maxLen32 > BITS2WORD32_SIZE(BN_MAXBITSIZE) +// ippStsNoErr no errors +// +// Parameters: +// method selected exponential method (unused parameter) +// maxLen32 max modulus length (in Ipp32u chunks) +// pCtxSize size of context +// +// Notes: Function always use method=ippBinaryMethod, +// so this parameter is ignored +*F*/ +IPPFUN(IppStatus, ippsMontGetSize, (IppsExpMethod method, cpSize maxLen32, cpSize* pCtxSize)) +{ + IPP_BAD_PTR1_RET(pCtxSize); + IPP_BADARG_RET(maxLen32<1 || maxLen32>BITS2WORD32_SIZE(BN_MAXBITSIZE), ippStsLengthErr); + + UNREFERENCED_PARAMETER(method); + + { + /* convert modulus length to the number of BNU_CHUNK_T */ + cpSize modSize = INTERNAL_BNU_LENGTH(maxLen32); + + *pCtxSize= sizeof(IppsMontState) + + modSize*sizeof(BNU_CHUNK_T) /* modulus */ + + modSize*sizeof(BNU_CHUNK_T) /* identity */ + + modSize*sizeof(BNU_CHUNK_T) /* square R */ + + modSize*sizeof(BNU_CHUNK_T) /* cube R */ + + modSize*sizeof(BNU_CHUNK_T) /* internal buffer */ + + modSize*sizeof(BNU_CHUNK_T) /* internal sscm buffer */ + + modSize*sizeof(BNU_CHUNK_T)*2 /* internal product */ + + MONT_ALIGNMENT-1; + + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsMontInit +// +// Purpose: Initializes the symbolic data structure and partitions the +// specified buffer space. +// +// Returns: Reason: +// ippStsNullPtrErr pMont==NULL +// ippStsLengthErr maxLen32 < 1 +// maxLen32 > BITS2WORD32_SIZE(BN_MAXBITSIZE) +// ippStsNoErr no errors +// +// Parameters: +// method selected exponential method (unused parameter) +// maxLen32 max modulus length (in Ipp32u chunks) +// pMont pointer to Montgomery context +*F*/ +IPPFUN(IppStatus, ippsMontInit,(IppsExpMethod method, int maxLen32, IppsMontState* pMont)) +{ + IPP_BADARG_RET(maxLen32<1 || maxLen32>BITS2WORD32_SIZE(BN_MAXBITSIZE), ippStsLengthErr); + + IPP_BAD_PTR1_RET(pMont); + pMont = (IppsMontState*)( IPP_ALIGNED_PTR(pMont, MONT_ALIGNMENT) ); + + UNREFERENCED_PARAMETER(method); + + MNT_ID(pMont) = idCtxUnknown; + MNT_ROOM(pMont) = INTERNAL_BNU_LENGTH(maxLen32); + MNT_SIZE(pMont) = 0; + MNT_HELPER(pMont) = 0; + + { + Ipp8u* ptr = (Ipp8u*)pMont; + + /* convert modulus length to the number of BNU_CHUNK_T */ + cpSize modSize = MNT_ROOM(pMont); + + /* assign internal buffers */ + MNT_MODULUS(pMont) = (BNU_CHUNK_T*)( ptr += sizeof(IppsMontState) ); + + MNT_1(pMont) = (BNU_CHUNK_T*)( ptr += modSize*sizeof(BNU_CHUNK_T) ); + MNT_SQUARE_R(pMont)= (BNU_CHUNK_T*)( ptr += modSize*sizeof(BNU_CHUNK_T) ); + MNT_CUBE_R(pMont) = (BNU_CHUNK_T*)( ptr += modSize*sizeof(BNU_CHUNK_T) ); + + MNT_TBUFFER(pMont) = (BNU_CHUNK_T*)( ptr += modSize*sizeof(BNU_CHUNK_T) ); + MNT_SBUFFER(pMont) = (BNU_CHUNK_T*)( ptr += modSize*sizeof(BNU_CHUNK_T) ); + MNT_PRODUCT(pMont) = (BNU_CHUNK_T*)( ptr += modSize*sizeof(BNU_CHUNK_T) ); + MNT_KBUFFER(pMont) = (BNU_CHUNK_T*)NULL; + + /* init internal buffers */ + ZEXPAND_BNU(MNT_MODULUS(pMont), 0, modSize); + ZEXPAND_BNU(MNT_1(pMont), 0, modSize); + ZEXPAND_BNU(MNT_SQUARE_R(pMont), 0, modSize); + ZEXPAND_BNU(MNT_CUBE_R(pMont), 0, modSize); + + MNT_ID(pMont) = idCtxMontgomery; + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsMontSet +// +// Purpose: Setup modulus value +// +// Returns: Reason: +// ippStsNullPtrErr pMont==NULL +// pModulus==NULL +// ippStsContextMatchErr !MNT_VALID_ID() +// ippStsLengthErr len32<1 +// ippStsNoErr no errors +// +// Parameters: +// pModulus pointer to the modulus buffer +// len32 length of the modulus (in Ipp32u chunks). +// pMont pointer to the context +*F*/ +static BNU_CHUNK_T cpMontHelper(BNU_CHUNK_T m0) +{ + BNU_CHUNK_T y = 1; + BNU_CHUNK_T x = 2; + BNU_CHUNK_T mask = 2*x-1; + + int i; + for(i=2; i<=BNU_CHUNK_BITS; i++, x<<=1) { + BNU_CHUNK_T rH, rL; + MUL_AB(rH, rL, m0, y); + if( x < (rL & mask) ) /* x < ((m0*y) mod (2*x)) */ + y+=x; + mask += mask + 1; + } + return 0-y; +} + +IPPFUN(IppStatus, ippsMontSet,(const Ipp32u* pModulus, cpSize len32, IppsMontState* pMont)) +{ + IPP_BAD_PTR2_RET(pModulus, pMont); + pMont = (IppsMontState*)(IPP_ALIGNED_PTR((pMont), MONT_ALIGNMENT)); + IPP_BADARG_RET(!MNT_VALID_ID(pMont), ippStsContextMatchErr); + + IPP_BADARG_RET(len32<1, ippStsLengthErr); + + /* modulus is not an odd number */ + IPP_BADARG_RET((pModulus[0] & 1) == 0, ippStsBadModulusErr); + IPP_BADARG_RET(MNT_ROOM(pMont)<(int)(INTERNAL_BNU_LENGTH(len32)), ippStsOutOfRangeErr); + + { + BNU_CHUNK_T m0; + cpSize len; + + /* fix input modulus */ + FIX_BNU(pModulus, len32); + + /* store modulus */ + ZEXPAND_BNU(MNT_MODULUS(pMont), 0, MNT_ROOM(pMont)); + COPY_BNU((Ipp32u*)(MNT_MODULUS(pMont)), pModulus, len32); + /* store modulus length */ + len = INTERNAL_BNU_LENGTH(len32); + MNT_SIZE(pMont) = len; + + /* pre-compute helper m0, m0*m = -1 mod R */ + m0 = cpMontHelper(MNT_MODULUS(pMont)[0]); + MNT_HELPER(pMont) = m0; + + /* setup identity */ + ZEXPAND_BNU(MNT_1(pMont), 0, len); + MNT_1(pMont)[len] = 1; + cpMod_BNU(MNT_1(pMont), len+1, MNT_MODULUS(pMont), len); + + /* setup square */ + ZEXPAND_BNU(MNT_SQUARE_R(pMont), 0, len); + COPY_BNU(MNT_SQUARE_R(pMont)+len, MNT_1(pMont), len); + cpMod_BNU(MNT_SQUARE_R(pMont), 2*len, MNT_MODULUS(pMont), len); + + /* setup cube */ + ZEXPAND_BNU(MNT_CUBE_R(pMont), 0, len); + COPY_BNU(MNT_CUBE_R(pMont)+len, MNT_SQUARE_R(pMont), len); + cpMod_BNU(MNT_CUBE_R(pMont), 2*len, MNT_MODULUS(pMont), len); + + /* clear buffers */ + ZEXPAND_BNU(MNT_TBUFFER(pMont), 0, len); + ZEXPAND_BNU(MNT_SBUFFER(pMont), 0, len); + ZEXPAND_BNU(MNT_PRODUCT(pMont), 0, 2*len); + + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsMontMul +// +// Purpose: Computes Montgomery modular multiplication for positive big +// number integers of Montgomery form. The following pseudocode +// represents this function: +// r <- ( a * b * R^(-1) ) mod m +// +// Returns: Reason: +// ippStsNoErr Returns no error. +// ippStsNullPtrErr Returns an error when pointers are null. +// ippStsBadArgErr Returns an error when a or b is a negative integer. +// ippStsScaleRangeErr Returns an error when a or b is more than m. +// ippStsOutOfRangeErr Returns an error when IppsBigNumState *r is larger than +// IppsMontState *m. +// ippStsContextMatchErr Returns an error when the context parameter does +// not match the operation. +// +// Parameters: +// a Multiplicand within the range [0, m - 1]. +// b Multiplier within the range [0, m - 1]. +// m Modulus. +// r Montgomery multiplication result. +// +// Notes: The size of IppsBigNumState *r should not be less than the data +// length of the modulus m. +*F*/ +IPPFUN(IppStatus, ippsMontMul, (const IppsBigNumState* pA, const IppsBigNumState* pB, IppsMontState* pMont, IppsBigNumState* pR)) +{ + IPP_BAD_PTR4_RET(pA, pB, pMont, pR); + + pMont = (IppsMontState*)(IPP_ALIGNED_PTR((pMont), MONT_ALIGNMENT)); + pA = (IppsBigNumState*)( IPP_ALIGNED_PTR(pA, BN_ALIGNMENT) ); + pB = (IppsBigNumState*)( IPP_ALIGNED_PTR(pB, BN_ALIGNMENT) ); + pR = (IppsBigNumState*)( IPP_ALIGNED_PTR(pR, BN_ALIGNMENT) ); + + IPP_BADARG_RET(!MNT_VALID_ID(pMont), ippStsContextMatchErr); + IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr); + IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr); + IPP_BADARG_RET(!BN_VALID_ID(pR), ippStsContextMatchErr); + + IPP_BADARG_RET(BN_NEGATIVE(pA) || BN_NEGATIVE(pB), ippStsBadArgErr); + IPP_BADARG_RET(cpCmp_BNU(BN_NUMBER(pA), BN_SIZE(pA), MNT_MODULUS(pMont), MNT_SIZE(pMont)) >= 0, ippStsScaleRangeErr); + IPP_BADARG_RET(cpCmp_BNU(BN_NUMBER(pB), BN_SIZE(pB), MNT_MODULUS(pMont), MNT_SIZE(pMont)) >= 0, ippStsScaleRangeErr); + IPP_BADARG_RET(BN_ROOM(pR) < MNT_SIZE(pMont), ippStsOutOfRangeErr); + + { + BNU_CHUNK_T* pDataR = BN_NUMBER(pR); + cpSize nsM = MNT_SIZE(pMont); + + cpMontMul_BNU(pDataR, + BN_NUMBER(pA), BN_SIZE(pA), + BN_NUMBER(pB), BN_SIZE(pB), + MNT_MODULUS(pMont), nsM, + MNT_HELPER(pMont), + MNT_PRODUCT(pMont), MNT_KBUFFER(pMont)); + + FIX_BNU(pDataR, nsM); + BN_SIZE(pR) = nsM; + BN_SIGN(pR) = ippBigNumPOS; + + return ippStsNoErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpmontred.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpmontred.c new file mode 100644 index 0000000000..a7851d6ec8 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpmontred.c @@ -0,0 +1,64 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owncp.h" +#include "pcpbnuarith.h" + + +void cpMontRedAdc_BNU(BNU_CHUNK_T* pR, + BNU_CHUNK_T* pProduct, + const BNU_CHUNK_T* pModulus, cpSize nsM, BNU_CHUNK_T m0) +{ + BNU_CHUNK_T carry; + BNU_CHUNK_T extension; + + cpSize n; + for(n=0, carry = 0; n<(nsM-1); n++) { + BNU_CHUNK_T u = pProduct[n]*m0; + BNU_CHUNK_T t = pProduct[nsM +n +1] + carry; + + extension = cpAddMulDgt_BNU(pProduct+n, pModulus, nsM, u); + ADD_AB(carry, pProduct[nsM+n], pProduct[nsM+n], extension); + t += carry; + + carry = tmaxbitSizeN) +#define RSA_PUB_KEY_MAXSIZE_E(x) ((x)->maxbitSizeE) +#define RSA_PUB_KEY_ID(x) ((x)->id) +#define RSA_PUB_KEY_BITSIZE_N(x) ((x)->bitSizeN) +#define RSA_PUB_KEY_BITSIZE_E(x) ((x)->bitSizeE) +#define RSA_PUB_KEY_E(x) ((x)->pDataE) +#define RSA_PUB_KEY_NMONT(x) ((x)->pMontN) +#define RSA_PUB_KEY_VALID_ID(x) (RSA_PUB_KEY_ID((x))==idCtxRSA_PubKey) +#define RSA_PUB_KEY_IS_SET(x) (RSA_PUB_KEY_BITSIZE_N((x))>0) + +/* alignment */ +#define RSA_PUBLIC_KEY_ALIGNMENT ((int)(sizeof(void*))) + +struct _cpRSA_private_key { + IppCtxId id; /* key ID */ + int maxbitSizeN; + int maxbitSizeD; + int bitSizeN; /* RSA modulus bitsize */ + int bitSizeD; /* RSA private exp bitsize */ + int bitSizeP; /* RSA p-factor bitsize */ + int bitSizeQ; /* RSA q-factor bitsize */ + + BNU_CHUNK_T* pDataD; /* private exp */ + BNU_CHUNK_T* pDataDp; /* dp private exp */ + BNU_CHUNK_T* pDataDq; /* dq private exp */ + BNU_CHUNK_T* pDataQinv; /* qinv coeff */ + + IppsMontState* pMontP; /* montgomery engine (P) */ + IppsMontState* pMontQ; /* montgomery engine (Q) */ + IppsMontState* pMontN; /* montgomery engine (N) */ +}; + +/* access */ +#define RSA_PRV_KEY_MAXSIZE_N(x) ((x)->maxbitSizeN) +#define RSA_PRV_KEY_MAXSIZE_D(x) ((x)->maxbitSizeD) +#define RSA_PRV_KEY_ID(x) ((x)->id) +#define RSA_PRV_KEY_BITSIZE_N(x) ((x)->bitSizeN) +#define RSA_PRV_KEY_BITSIZE_D(x) ((x)->bitSizeD) +#define RSA_PRV_KEY_BITSIZE_P(x) ((x)->bitSizeP) +#define RSA_PRV_KEY_BITSIZE_Q(x) ((x)->bitSizeQ) +#define RSA_PRV_KEY_D(x) ((x)->pDataD) +#define RSA_PRV_KEY_DP(x) ((x)->pDataDp) +#define RSA_PRV_KEY_DQ(x) ((x)->pDataDq) +#define RSA_PRV_KEY_INVQ(x) ((x)->pDataQinv) +#define RSA_PRV_KEY_PMONT(x) ((x)->pMontP) +#define RSA_PRV_KEY_QMONT(x) ((x)->pMontQ) +#define RSA_PRV_KEY_NMONT(x) ((x)->pMontN) +#define RSA_PRV_KEY1_VALID_ID(x) (RSA_PRV_KEY_ID((x))==idCtxRSA_PrvKey1) +#define RSA_PRV_KEY2_VALID_ID(x) (RSA_PRV_KEY_ID((x))==idCtxRSA_PrvKey2) +#define RSA_PRV_KEY_VALID_ID(x) (RSA_PRV_KEY1_VALID_ID((x)) || RSA_PRV_KEY2_VALID_ID((x))) +#define RSA_PRV_KEY_IS_SET(x) (RSA_PRV_KEY_BITSIZE_N((x))>0) + +/* alignment */ +#define RSA_PRIVATE_KEY_ALIGNMENT ((int)(sizeof(void*))) + +/* pubic and private key operations */ +void gsRSApub_cipher(IppsBigNumState* pY, const IppsBigNumState* pX, const IppsRSAPublicKeyState* pKey, BNU_CHUNK_T* pScratchBuffer); +void gsRSAprv_cipher(IppsBigNumState* pY, const IppsBigNumState* pX, const IppsRSAPrivateKeyState* pKey, BNU_CHUNK_T* pScratchBuffer); +void gsRSAprv_cipher_crt(IppsBigNumState* pY, const IppsBigNumState* pX, const IppsRSAPrivateKeyState* pKey, BNU_CHUNK_T* pScratchBuffer); + +#endif /* _CP_NG_RSA_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsaencodec.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsaencodec.c new file mode 100644 index 0000000000..4d147ad395 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsaencodec.c @@ -0,0 +1,437 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpbn.h" +#include "pcpngrsa.h" +#include "pcpngrsamontstuff.h" + + +/*F* +// Name: ippsRSA_GetBufferSizePublicKey +// +// Purpose: Returns size of temporary buffer (in bytes) for public key operation +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pKey +// NULL == pBufferSize +// +// ippStsContextMatchErr !RSA_PUB_KEY_VALID_ID() +// +// ippStsIncompleteContextErr no ippsRSA_SetPublicKey() call +// +// ippStsNoErr no error +// +// Parameters: +// pBufferSize pointer to size of temporary buffer +// pKey pointer to the key context +*F*/ +IPPFUN(IppStatus, ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) +{ + IPP_BAD_PTR1_RET(pKey); + pKey = (IppsRSAPublicKeyState*)( IPP_ALIGNED_PTR(pKey, RSA_PUBLIC_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PUB_KEY_VALID_ID(pKey), ippStsContextMatchErr); + IPP_BADARG_RET(!RSA_PUB_KEY_IS_SET(pKey), ippStsIncompleteContextErr); + + IPP_BAD_PTR1_RET(pBufferSize); + + { + cpSize expBitSize = RSA_PUB_KEY_BITSIZE_E(pKey); + cpSize w = gsMontExp_WinSize(expBitSize); + cpSize precompLen = (1==w)? 0 : (1<1) + // temporary product (2) + */ + cpSize bufferLen = ((nsM+1)*2)*2 + +precompLen*nsM + +nsM + +nsM*2; + + *pBufferSize = bufferLen*sizeof(BNU_CHUNK_T) + + sizeof(BNU_CHUNK_T)-1 + + (CACHE_LINE_SIZE-1); + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsRSA_GetBufferSizePublicKey +// +// Purpose: Returns size of temporary buffer (in bytes) for public key operation +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pKey +// NULL == pBufferSize +// +// ippStsContextMatchErr !RSA_PRV_KEY_VALID_ID() +// +// ippStsIncompleteContextErr (type1) private key is not set up +// +// ippStsNoErr no error +// +// Parameters: +// pBufferSize pointer to size of temporary buffer +// pKey pointer to the key context +*F*/ +IPPFUN(IppStatus, ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) +{ + IPP_BAD_PTR1_RET(pKey); + pKey = (IppsRSAPrivateKeyState*)( IPP_ALIGNED_PTR(pKey, RSA_PUBLIC_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PRV_KEY_VALID_ID(pKey), ippStsContextMatchErr); + IPP_BADARG_RET(RSA_PRV_KEY1_VALID_ID(pKey) && !RSA_PRV_KEY_IS_SET(pKey), ippStsIncompleteContextErr); + + IPP_BAD_PTR1_RET(pBufferSize); + + { + cpSize bufferLen; + if(RSA_PRV_KEY1_VALID_ID(pKey)) { + cpSize expBitSize = RSA_PRV_KEY_BITSIZE_D(pKey); + cpSize w = gsMontExp_WinSize(expBitSize); + cpSize precompLen = (1==w)? 0 : (1<1) + // temporary product (2) + */ + bufferLen = ((nsN+1)*2)*2 + +gsPrecompResourcelen(precompLen,nsN) //+precompLen*nsN + +nsN + +nsN + +nsN*2; + } + else { + cpSize expBitSize = IPP_MAX(RSA_PRV_KEY_BITSIZE_P(pKey), RSA_PRV_KEY_BITSIZE_Q(pKey)); + cpSize w = gsMontExp_WinSize(expBitSize); + cpSize precompLen = (1==w)? 0 : (1<1) + // recoure to keep "masked" multipler (x|1) (1), (w=1) + // or resource to keep zero-extended power e (1), (w>1) + // temporary product (2) + */ + bufferLen = ((nsP*2+1)*2)*2 + +gsPrecompResourcelen(precompLen, nsP) //+precompLen*nsP + +nsP + +nsP + +nsP*2; + bufferLen = IPP_MAX( IPP_MAX(validationBufferLen,generationBufferLen), bufferLen ); + } + *pBufferSize = bufferLen*sizeof(BNU_CHUNK_T) + + sizeof(BNU_CHUNK_T)-1 + + (CACHE_LINE_SIZE-1); + return ippStsNoErr; + } +} + + + +void gsRSApub_cipher(IppsBigNumState* pY, + const IppsBigNumState* pX, + const IppsRSAPublicKeyState* pKey, + BNU_CHUNK_T* pScratchBuffer) +{ + IppsMontState* pMontN = RSA_PUB_KEY_NMONT(pKey); + gsMontEnc_BN(pY, pX, pMontN, pScratchBuffer); + + { + /* optimal size of window */ + BNU_CHUNK_T* pExp = RSA_PUB_KEY_E(pKey); + cpSize nsExp = BITS_BNU_CHUNK(RSA_PUB_KEY_BITSIZE_E(pKey)); + cpSize w = gsMontExp_WinSize(RSA_PUB_KEY_BITSIZE_E(pKey)); + + if(1==w) + gsMontExpBin_BN(pY, pY, pExp, nsExp, pMontN, pScratchBuffer); + else + gsMontExpWin_BN(pY, pY, pExp, nsExp, w, pMontN, pScratchBuffer); + } + + gsMontDec_BN(pY, pY, pMontN, pScratchBuffer); +} + + +/*F* +// Name: ippsRSA_Encrypt +// +// Purpose: Performs RSA Encryprion +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pKey +// NULL == pPtxt +// NULL == pCtxt +// NULL == pBuffer +// +// ippStsContextMatchErr !RSA_PUB_KEY_VALID_ID() +// !BN_VALID_ID(pPtxt) +// !BN_VALID_ID(pCtxt) +// +// ippStsIncompleteContextErr public key is not setup +// +// ippStsOutOfRangeErr pPtxt >= modulus +// pPtxt <0 +// +// ippStsSizeErr BN_ROOM(pCtxt) is not enough +// +// ippStsNoErr no error +// +// Parameters: +// pPtxt pointer to the plaintext +// pCtxt pointer to the ciphertext +// pKey pointer to the key context +// pScratchBuffer pointer to the temporary buffer +*F*/ +IPPFUN(IppStatus, ippsRSA_Encrypt,(const IppsBigNumState* pPtxt, + IppsBigNumState* pCtxt, + const IppsRSAPublicKeyState* pKey, + Ipp8u* pScratchBuffer)) +{ + IPP_BAD_PTR2_RET(pKey, pScratchBuffer); + pKey = (IppsRSAPublicKeyState*)( IPP_ALIGNED_PTR(pKey, RSA_PUBLIC_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PUB_KEY_VALID_ID(pKey), ippStsContextMatchErr); + IPP_BADARG_RET(!RSA_PUB_KEY_IS_SET(pKey), ippStsIncompleteContextErr); + + IPP_BAD_PTR1_RET(pPtxt); + pPtxt = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPtxt, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pPtxt), ippStsContextMatchErr); + IPP_BADARG_RET(BN_NEGATIVE(pPtxt), ippStsOutOfRangeErr); + IPP_BADARG_RET(0 <= cpCmp_BNU(BN_NUMBER(pPtxt), BN_SIZE(pPtxt), + MNT_MODULUS(RSA_PUB_KEY_NMONT(pKey)), MNT_SIZE(RSA_PUB_KEY_NMONT(pKey))), ippStsOutOfRangeErr); + + IPP_BAD_PTR1_RET(pCtxt); + pCtxt = (IppsBigNumState*)( IPP_ALIGNED_PTR(pCtxt, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pCtxt), ippStsContextMatchErr); + IPP_BADARG_RET(BN_ROOM(pCtxt) < BITS_BNU_CHUNK(RSA_PUB_KEY_BITSIZE_N(pKey)), ippStsSizeErr); + + gsRSApub_cipher(pCtxt, + pPtxt, + pKey, + (BNU_CHUNK_T*)(IPP_ALIGNED_PTR((pScratchBuffer), (int)sizeof(BNU_CHUNK_T))) ); + return ippStsNoErr; +} + + + +void gsRSAprv_cipher(IppsBigNumState* pY, + const IppsBigNumState* pX, + const IppsRSAPrivateKeyState* pKey, + BNU_CHUNK_T* pScratchBuffer) +{ + IppsMontState* pMontN = RSA_PRV_KEY_NMONT(pKey); + gsMontEnc_BN(pY, pX, pMontN, pScratchBuffer); + + { + /* optimal size of window */ + BNU_CHUNK_T* pExp = RSA_PRV_KEY_D(pKey); + cpSize nsExp = BITS_BNU_CHUNK(RSA_PRV_KEY_BITSIZE_D(pKey)); + cpSize w = gsMontExp_WinSize(RSA_PRV_KEY_BITSIZE_D(pKey)); + + if(1==w) + gsMontExpBin_BN_sscm(pY, pY, pExp, nsExp, pMontN, pScratchBuffer); + else + gsMontExpWin_BN_sscm(pY, pY, pExp, nsExp, w, pMontN, pScratchBuffer); + } + + gsMontDec_BN(pY, pY, pMontN, pScratchBuffer); +} + +void gsRSAprv_cipher_crt(IppsBigNumState* pY, + const IppsBigNumState* pX, + const IppsRSAPrivateKeyState* pKey, + BNU_CHUNK_T* pScratchBuffer) +{ + /* P- and Q- montgometry engines */ + IppsMontState* pMontP = RSA_PRV_KEY_PMONT(pKey); + IppsMontState* pMontQ = RSA_PRV_KEY_QMONT(pKey); + cpSize nsP = MNT_SIZE(pMontP); + cpSize nsQ = MNT_SIZE(pMontQ); + + const BNU_CHUNK_T* dataX = BN_NUMBER(pX); + cpSize nsX = BN_SIZE(pX); + BNU_CHUNK_T* dataXp = BN_NUMBER(pY); + BNU_CHUNK_T* dataXq = BN_BUFFER(pY); + + cpSize bitSizeDP = BITSIZE_BNU(RSA_PRV_KEY_DP(pKey), nsP); + cpSize bitSizeDQ = BITSIZE_BNU(RSA_PRV_KEY_DQ(pKey), nsQ); + cpSize w; + BNU_CHUNK_T cf; + + /* compute xq = x^dQ mod Q */ + COPY_BNU(dataXq, dataX, nsX); + cpMod_BNU(dataXq, nsX, MNT_MODULUS(pMontQ), nsQ); + gsMontEnc_BNU(dataXq, dataXq, nsQ, pMontQ, pScratchBuffer); + w = gsMontExp_WinSize(bitSizeDQ); + + if(1==w) + gsMontExpBin_BNU_sscm(dataXq, + dataXq, nsQ, + RSA_PRV_KEY_DQ(pKey), BITS_BNU_CHUNK(bitSizeDQ), + pMontQ, pScratchBuffer); + else + gsMontExpWin_BNU_sscm(dataXq, + dataXq, nsQ, + RSA_PRV_KEY_DQ(pKey), BITS_BNU_CHUNK(bitSizeDQ), w, + pMontQ, pScratchBuffer); + + gsMontDec_BNU(dataXq, dataXq, nsQ, pMontQ, pScratchBuffer); + + /* compute xp = x^dP mod P */ + COPY_BNU(dataXp, dataX, nsX); + cpMod_BNU(dataXp, nsX, MNT_MODULUS(pMontP), nsP); + gsMontEnc_BNU(dataXp, dataXp, nsP, pMontP, pScratchBuffer); + w = gsMontExp_WinSize(bitSizeDP); + + if(1==w) + gsMontExpBin_BNU_sscm(dataXp, + dataXp, nsP, + RSA_PRV_KEY_DP(pKey), BITS_BNU_CHUNK(bitSizeDP), + pMontP, pScratchBuffer); + else + gsMontExpWin_BNU_sscm(dataXp, + dataXp, nsP, + RSA_PRV_KEY_DP(pKey), BITS_BNU_CHUNK(bitSizeDP), w, + pMontP, pScratchBuffer); + + gsMontDec_BNU(dataXp, dataXp, nsP, pMontP, pScratchBuffer); + + /* xp -= xq */ + cf = cpSub_BNU(dataXp, dataXp, dataXq, nsQ); + if(nsP-nsQ) + cf = cpDec_BNU(dataXp+nsQ, dataXp+nsQ, (nsP-nsQ), cf); + if(cf) + cpAdd_BNU(dataXp, dataXp, MNT_MODULUS(pMontP), nsP); + + /* xp = xp*qInv mod P */ + cpMontMul_BNU(dataXp, + dataXp, nsP, + RSA_PRV_KEY_INVQ(pKey), nsP, + MNT_MODULUS(pMontP), nsP, MNT_HELPER(pMontP), + pScratchBuffer, NULL); + + /* Y = xq + xp*Q */ + cpMul_BNU_school(pScratchBuffer, + dataXp, nsP, + MNT_MODULUS(pMontQ), nsQ); + cf = cpAdd_BNU(BN_NUMBER(pY), pScratchBuffer, dataXq, nsQ); + cpInc_BNU(BN_NUMBER(pY)+nsQ, pScratchBuffer+nsQ, nsP, cf); + + nsX = nsP+nsQ; + FIX_BNU(BN_NUMBER(pY), nsX); + BN_SIZE(pY) = nsX; + BN_SIGN(pY) = ippBigNumPOS; +} + +/*F* +// Name: ippsRSA_Decrypt +// +// Purpose: Performs RSA Decryprion +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pKey +// NULL == pCtxt +// NULL == pPtxt +// NULL == pBuffer +// +// ippStsContextMatchErr !RSA_PUB_KEY_VALID_ID() +// !BN_VALID_ID(pCtxt) +// !BN_VALID_ID(pPtxt) +// +// ippStsIncompleteContextErr private key is not set up +// +// ippStsOutOfRangeErr pCtxt >= modulus +// pCtxt <0 +// +// ippStsSizeErr BN_ROOM(pPtxt) is not enough +// +// ippStsNoErr no error +// +// Parameters: +// pCtxt pointer to the ciphertext +// pPtxt pointer to the plaintext +// pKey pointer to the key context +// pScratchBuffer pointer to the temporary buffer +*F*/ +IPPFUN(IppStatus, ippsRSA_Decrypt,(const IppsBigNumState* pCtxt, + IppsBigNumState* pPtxt, + const IppsRSAPrivateKeyState* pKey, + Ipp8u* pScratchBuffer)) +{ + IPP_BAD_PTR2_RET(pKey, pScratchBuffer); + pKey = (IppsRSAPrivateKeyState*)( IPP_ALIGNED_PTR(pKey, RSA_PRIVATE_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PRV_KEY_VALID_ID(pKey), ippStsContextMatchErr); + IPP_BADARG_RET(!RSA_PRV_KEY_IS_SET(pKey), ippStsIncompleteContextErr); + + IPP_BAD_PTR1_RET(pCtxt); + pCtxt = (IppsBigNumState*)( IPP_ALIGNED_PTR(pCtxt, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pCtxt), ippStsContextMatchErr); + IPP_BADARG_RET(BN_NEGATIVE(pCtxt), ippStsOutOfRangeErr); + IPP_BADARG_RET(0 <= cpCmp_BNU(BN_NUMBER(pCtxt), BN_SIZE(pCtxt), + MNT_MODULUS(RSA_PRV_KEY_NMONT(pKey)), MNT_SIZE(RSA_PRV_KEY_NMONT(pKey))), ippStsOutOfRangeErr); + + IPP_BAD_PTR1_RET(pPtxt); + pPtxt = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPtxt, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pPtxt), ippStsContextMatchErr); + IPP_BADARG_RET(BN_ROOM(pPtxt) < BITS_BNU_CHUNK(RSA_PRV_KEY_BITSIZE_N(pKey)), ippStsSizeErr); + + if(RSA_PRV_KEY1_VALID_ID(pKey)) + gsRSAprv_cipher(pPtxt, + pCtxt, + pKey, + (BNU_CHUNK_T*)(IPP_ALIGNED_PTR((pScratchBuffer), (int)sizeof(BNU_CHUNK_T))) ); + else + gsRSAprv_cipher_crt(pPtxt, + pCtxt, + pKey, + (BNU_CHUNK_T*)(IPP_ALIGNED_PTR((pScratchBuffer), (int)sizeof(BNU_CHUNK_T))) ); + return ippStsNoErr; +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsaesoaepca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsaesoaepca.c new file mode 100644 index 0000000000..ac9ce14f14 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsaesoaepca.c @@ -0,0 +1,176 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcptool.h" +#include "pcpngrsa.h" +#include "pcphash.h" + + +/*F* +// Name: ippsRSAEncrypt_OAEP +// +// Purpose: Performs RSAES-OAEP encryprion scheme +// +// Returns: Reason: +// ippStsNotSupportedModeErr unknown hashAlg +// +// ippStsNullPtrErr NULL == pKey +// NULL == pSrc +// NULL == pDst +// NULL == pLabel +// NULL == pSeed +// NULL == pBuffer +// +// ippStsLengthErr srcLen <0 +// labLen <0 +// srcLen > RSAsize -2*hashLen -2 +// RSAsize < 2*hashLen +2 +// +// ippStsContextMatchErr !RSA_PUB_KEY_VALID_ID() +// +// ippStsIncompleteContextErr public key is not set up +// +// ippStsNoErr no error +// +// Parameters: +// pSrc pointer to the plaintext +// srcLen plaintext length (bytes) +// pLabel (optional) pointer to the label associated with plaintext +// labLen label length (bytes) +// pSeed seed string of hashLen size +// pDst pointer to the ciphertext (length of pdst is not less then size of RSA modulus) +// pKey pointer to the RSA public key context +// hashAlg hash alg ID +// pBuffer pointer to scratch buffer +*F*/ +IPPFUN(IppStatus, ippsRSAEncrypt_OAEP,(const Ipp8u* pSrc, int srcLen, + const Ipp8u* pLabel, int labLen, + const Ipp8u* pSeed, + Ipp8u* pDst, + const IppsRSAPublicKeyState* pKey, + IppHashAlgId hashAlg, + Ipp8u* pBuffer)) +{ + int hashLen; + + /* test hash algorith ID */ + hashAlg = cpValidHashAlg(hashAlg); + IPP_BADARG_RET(ippHashAlg_Unknown==hashAlg, ippStsNotSupportedModeErr); + + /* test data pointer */ + IPP_BAD_PTR3_RET(pSrc,pDst, pSeed); + + IPP_BADARG_RET(!pLabel && labLen, ippStsNullPtrErr); + + /* test public key context */ + IPP_BAD_PTR2_RET(pKey, pBuffer); + pKey = (IppsRSAPublicKeyState*)( IPP_ALIGNED_PTR(pKey, RSA_PUBLIC_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PUB_KEY_VALID_ID(pKey), ippStsContextMatchErr); + IPP_BADARG_RET(!RSA_PUB_KEY_IS_SET(pKey), ippStsIncompleteContextErr); + + /* test length */ + IPP_BADARG_RET(srcLen<0||labLen<0, ippStsLengthErr); + + hashLen = cpHashSize(hashAlg); + /* test compatibility of RSA and hash length */ + IPP_BADARG_RET(BITS2WORD8_SIZE(RSA_PRV_KEY_BITSIZE_N(pKey)) < (2*hashLen +2), ippStsLengthErr); + /* test compatibility of msg length and other (RSA and hash) lengths */ + IPP_BADARG_RET(BITS2WORD8_SIZE(RSA_PRV_KEY_BITSIZE_N(pKey))-(2*hashLen +2) < srcLen, ippStsLengthErr); + + { + /* size of RSA modulus in bytes and chunks */ + int k = BITS2WORD8_SIZE(RSA_PUB_KEY_BITSIZE_N(pKey)); + cpSize nsN = BITS_BNU_CHUNK(RSA_PUB_KEY_BITSIZE_N(pKey)); + + /* + // EME-OAEP encoding + */ + { + Ipp8u seedMask[BITS2WORD8_SIZE(IPP_SHA512_DIGEST_BITSIZE)]; + + Ipp8u* pMaskedSeed = pDst+1; + Ipp8u* pMaskedDB = pDst +hashLen +1; + + pDst[0] = 0; + + /* maskedDB = MGF(seed, k-1-hashLen)*/ + ippsMGF(pSeed, hashLen, pMaskedDB, k-1-hashLen, hashAlg); + + /* seedMask = HASH(pLab) */ + ippsHashMessage(pLabel, labLen, seedMask, hashAlg); + + /* maskedDB ^= concat(HASH(pLab),PS,0x01,pSc) */ + XorBlock(pMaskedDB, seedMask, pMaskedDB, hashLen); + pMaskedDB[k-srcLen-hashLen-2] ^= 0x01; + XorBlock(pMaskedDB+k-srcLen-hashLen-2+1, pSrc, pMaskedDB+k-srcLen-hashLen-2+1, srcLen); + + /* seedMask = MGF(maskedDB, hashLen) */ + ippsMGF(pMaskedDB, k-1-hashLen, seedMask, hashLen, hashAlg); + /* maskedSeed = seed ^ seedMask */ + XorBlock(pSeed, seedMask, pMaskedSeed, hashLen); + } + + /* RSA encryption */ + { + /* align buffer */ + BNU_CHUNK_T* pScratchBuffer = (BNU_CHUNK_T*)(IPP_ALIGNED_PTR(pBuffer, (int)sizeof(BNU_CHUNK_T)) ); + + /* temporary BN */ + __ALIGN8 IppsBigNumState tmpBN; + BN_Make(pScratchBuffer, pScratchBuffer+nsN+1, nsN, &tmpBN); + + /* updtae buffer pointer */ + pScratchBuffer += (nsN+1)*2; + + ippsSetOctString_BN(pDst, k, &tmpBN); + + gsRSApub_cipher(&tmpBN, &tmpBN, pKey, pScratchBuffer); + + ippsGetOctString_BN(pDst, k, &tmpBN); + } + + return ippStsNoErr; + } +} + + +IPPFUN(IppStatus, ippsRSA_OAEPEncrypt_SHA256,(const Ipp8u* pSrc, int srcLen, + const Ipp8u* pLabel, int labLen, + const Ipp8u* pSeed, + Ipp8u* pDst, + const IppsRSAPublicKeyState* pKey, + Ipp8u* pBuffer)) +{ return ippsRSAEncrypt_OAEP(pSrc,srcLen, pLabel,labLen, pSeed, + pDst, pKey, + IPP_ALG_HASH_SHA256, + pBuffer); } diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsagenerate.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsagenerate.c new file mode 100644 index 0000000000..2896ffdc89 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsagenerate.c @@ -0,0 +1,323 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpbn.h" +#include "pcpprimeg.h" +#include "pcpngrsa.h" +#include "pcpngrsamontstuff.h" + +/*F* +// Name: ippsRSA_ValidateKeys +// +// Purpose: Validate RSA keys +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pPublicKey +// NULL == pPrivateKeyType2 +// NULL == pPrivateKeyType1 +// NULL == pBuffer +// NULL == pPrimeGen +// NULL == rndFunc +// NULL == pResult +// +// ippStsContextMatchErr !RSA_PUB_KEY_VALID_ID(pPublicKey) +// !RSA_PRV_KEY2_VALID_ID(pPrivateKeyType2) +// !RSA_PRV_KEY1_VALID_ID(pPrivateKeyType1) +// !PRIME_VALID_ID(pPrimeGen) +// +// ippStsIncompleteContextErr public and.or private key is not set up +// +// ippStsSizeErr PRIME_MAXBITSIZE(pPrimeGen) < factorPbitSize +// +// ippStsBadArgErr nTrials < 1 +// +// ippStsNoErr no error +// +// Parameters: +// pResult pointer to the validation result +// pPublicKey pointer to the public key context +// pPrivateKeyType2 pointer to the private key type2 context +// pPrivateKeyType1 (optional) pointer to the private key type1 context +// pBuffer pointer to the temporary buffer +// nTrials parameter of Miller-Rabin Test +// pPrimeGen pointer to the Prime generator context +// rndFunc external PRNG +// pRndParam pointer to the external PRNG parameters +*F*/ +/* +// make sure D*E = 1 mod(phi(P,Q)) +// where phi(P,Q) = (P-1)*(Q-1) +*/ +static +int isValidPriv1_classic(const BNU_CHUNK_T* pN, int nsN, + const BNU_CHUNK_T* pE, int nsE, + const BNU_CHUNK_T* pD, int nsD, + const BNU_CHUNK_T* pFactorP, int nsP, + const BNU_CHUNK_T* pFactorQ, int nsQ, + BNU_CHUNK_T* pBuffer) +{ + BNU_CHUNK_T* pPhi = pBuffer; + BNU_CHUNK_T* pProduct = pPhi + nsN; + BNU_CHUNK_T c = cpSub_BNU(pPhi, pN, pFactorP, nsP); + int prodLen; + if(nsN>1) cpDec_BNU(pPhi+nsP, pN+nsP, nsQ, c); + c = cpSub_BNU(pPhi,pPhi, pFactorQ, nsQ); + if(nsN>1) cpDec_BNU(pPhi+nsQ, pPhi+nsQ, nsP, c); + cpInc_BNU(pPhi, pPhi, nsP+nsQ, 1); + + cpMul_BNU_school(pProduct, pE, nsE, pD, nsD); + prodLen = cpMod_BNU(pProduct, nsE+nsD, pPhi, nsN); + + return 1==cpEqu_BNU_CHUNK(pProduct, prodLen, 1)? IPP_IS_VALID : IPP_IS_INVALID; +} + +/* +// make sure D*E = 1 mod(lcm(P-1,Q-1)) +// where lcm(P-1,Q-1) = (P-1)*(Q-1)/gcd(P-1,Q-1) +*/ +static +int isValidPriv1_rsa(const BNU_CHUNK_T* pN, int nsN, + const BNU_CHUNK_T* pE, int nsE, + const BNU_CHUNK_T* pD, int nsD, + BNU_CHUNK_T* pFactorP, int nsP, + BNU_CHUNK_T* pFactorQ, int nsQ, + BNU_CHUNK_T* pBuffer) +{ + __ALIGN8 IppsBigNumState tmpBN1; + __ALIGN8 IppsBigNumState tmpBN2; + __ALIGN8 IppsBigNumState tmpBN3; + + BNU_CHUNK_T* pProduct = pBuffer; + BNU_CHUNK_T* pGcd = pProduct+(nsN+1); + BNU_CHUNK_T* pLcm; + int nsLcm; + int prodLen; + pBuffer = pGcd + (nsP+1)*2; + + /* P = P-1 and Q = Q-1 */ + pFactorP[0]--; + pFactorQ[0]--; + + /* compute product (P-1)*(Q-1) = P*Q -P -Q +1 = N -(P-1) -(Q-1) -1 */ + { + BNU_CHUNK_T c = cpSub_BNU(pProduct, pN, pFactorP, nsP); + if(nsN>1) cpDec_BNU(pProduct+nsP, pN+nsP, nsQ, c); + c = cpSub_BNU(pProduct, pProduct, pFactorQ, nsQ); + if(nsN>1) cpDec_BNU(pProduct+nsQ, pProduct+nsQ, nsP, c); + cpDec_BNU(pProduct, pProduct, nsN, 1); + } + + /* compute gcd(p-1, q-1) */ + BN_Make(pGcd, pGcd+nsP+1, nsP, &tmpBN1); /* BN(gcd) */ + BN_SIZE(&tmpBN1) = nsP; + BN_Make(pFactorP, pBuffer, nsP, &tmpBN2); /* BN(P-1) */ + BN_SIZE(&tmpBN2) = nsP; + BN_Make(pFactorQ, pBuffer+nsP+1, nsQ, &tmpBN3); /* BN(Q-1) */ + BN_SIZE(&tmpBN3) = nsQ; + ippsGcd_BN(&tmpBN2, &tmpBN3, &tmpBN1); + + /* compute lcm(p-1, q-1) = (p-1)(q-1)/gcd(p-1, q-1) */ + pLcm = pBuffer; + cpDiv_BNU(pLcm, &nsLcm, pProduct, nsN, pGcd, BN_SIZE(&tmpBN1)); + + /* test E*D = 1 mod lcm */ + cpMul_BNU_school(pProduct, pE, nsE, pD, nsD); + prodLen = cpMod_BNU(pProduct, nsE+nsD, pLcm, nsLcm); + + /* restore P and Q */ + pFactorP[0]++; + pFactorQ[0]++; + + return 1==cpEqu_BNU_CHUNK(pProduct, prodLen, 1)? IPP_IS_VALID : IPP_IS_INVALID; +} + +IPPFUN(IppStatus, ippsRSA_ValidateKeys,(int* pResult, + const IppsRSAPublicKeyState* pPublicKey, + const IppsRSAPrivateKeyState* pPrivateKeyType2, + const IppsRSAPrivateKeyState* pPrivateKeyType1, /*optional */ + Ipp8u* pBuffer, + int nTrials, + IppsPrimeState* pPrimeGen, + IppBitSupplier rndFunc, void* pRndParam)) +{ + IPP_BAD_PTR1_RET(pPublicKey); + pPublicKey = (IppsRSAPublicKeyState*)( IPP_ALIGNED_PTR(pPublicKey, RSA_PUBLIC_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PUB_KEY_VALID_ID(pPublicKey), ippStsContextMatchErr); + IPP_BADARG_RET(!RSA_PUB_KEY_IS_SET(pPublicKey), ippStsIncompleteContextErr); + + IPP_BAD_PTR1_RET(pPrivateKeyType2); + pPrivateKeyType2 = (IppsRSAPrivateKeyState*)( IPP_ALIGNED_PTR(pPrivateKeyType2, RSA_PRIVATE_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PRV_KEY2_VALID_ID(pPrivateKeyType2), ippStsContextMatchErr); + IPP_BADARG_RET(!RSA_PRV_KEY_IS_SET(pPrivateKeyType2), ippStsIncompleteContextErr); + + if(pPrivateKeyType1) { /* pPrivateKeyType1 is optional */ + pPrivateKeyType1 = (IppsRSAPrivateKeyState*)( IPP_ALIGNED_PTR(pPrivateKeyType1, RSA_PRIVATE_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PRV_KEY1_VALID_ID(pPrivateKeyType1), ippStsContextMatchErr); + IPP_BADARG_RET(!RSA_PRV_KEY_IS_SET(pPrivateKeyType1), ippStsIncompleteContextErr); + } + + IPP_BAD_PTR1_RET(pPrimeGen); + pPrimeGen = (IppsPrimeState*)( IPP_ALIGNED_PTR(pPrimeGen, PRIME_ALIGNMENT) ); + IPP_BADARG_RET(!PRIME_VALID_ID(pPrimeGen), ippStsContextMatchErr); + IPP_BADARG_RET(PRIME_MAXBITSIZE(pPrimeGen) < RSA_PRV_KEY_BITSIZE_P(pPrivateKeyType2), ippStsSizeErr); + + IPP_BAD_PTR3_RET(pResult, pBuffer, rndFunc); + + /* test security parameter parameter */ + IPP_BADARG_RET((1>nTrials), ippStsBadArgErr); + + { + BNU_CHUNK_T* pScratchBuffer = (BNU_CHUNK_T*)(IPP_ALIGNED_PTR(pBuffer, (int)sizeof(BNU_CHUNK_T))); + + /* E key component */ + BNU_CHUNK_T* pExpE = RSA_PUB_KEY_E(pPublicKey); + cpSize nsE = BITS_BNU_CHUNK(RSA_PUB_KEY_BITSIZE_E(pPublicKey)); + /* P, dP, invQ key components */ + BNU_CHUNK_T* pFactorP= MNT_MODULUS(RSA_PRV_KEY_PMONT(pPrivateKeyType2)); + BNU_CHUNK_T* pExpDp = RSA_PRV_KEY_DP(pPrivateKeyType2); + BNU_CHUNK_T* pInvQ = RSA_PRV_KEY_INVQ(pPrivateKeyType2); + cpSize nsP = MNT_SIZE(RSA_PRV_KEY_PMONT(pPrivateKeyType2)); + /* Q, dQ key components */ + BNU_CHUNK_T* pFactorQ= MNT_MODULUS(RSA_PRV_KEY_QMONT(pPrivateKeyType2)); + BNU_CHUNK_T* pExpDq = RSA_PRV_KEY_DQ(pPrivateKeyType2); + cpSize nsQ = MNT_SIZE(RSA_PRV_KEY_QMONT(pPrivateKeyType2)); + + /*const*/ BNU_CHUNK_T* pN0 = MNT_MODULUS(RSA_PUB_KEY_NMONT(pPublicKey)); + cpSize nsN = MNT_SIZE(RSA_PUB_KEY_NMONT(pPublicKey)); + + *pResult = IPP_IS_VALID; + + /* make sure P is prime */ + if(!cpPrimeTest(pFactorP, nsP, nTrials, pPrimeGen, rndFunc, pRndParam)) { + *pResult = IPP_IS_COMPOSITE; + return ippStsNoErr; + } + + /* make sure Q is prime */ + if(!cpPrimeTest(pFactorQ, nsQ, nTrials, pPrimeGen, rndFunc, pRndParam)) { + *pResult = IPP_IS_COMPOSITE; + return ippStsNoErr; + } + + /* make sure PubKey(N)==PrivKeytype2(N) and PubKey(N)==PrivKeytype1(N) */ + if(cpCmp_BNU(pN0, nsN, + MNT_MODULUS(RSA_PRV_KEY_NMONT(pPrivateKeyType2)), MNT_SIZE(RSA_PRV_KEY_NMONT(pPrivateKeyType2)))) { + *pResult = IPP_IS_INVALID; + return ippStsNoErr; + } + if(pPrivateKeyType1) { + if(cpCmp_BNU(pN0, nsN, + MNT_MODULUS(RSA_PRV_KEY_NMONT(pPrivateKeyType1)), MNT_SIZE(RSA_PRV_KEY_NMONT(pPrivateKeyType1)))) { + *pResult = IPP_IS_INVALID; + return ippStsNoErr; + } + } + + /* make sure 3 <= E < N */ + if(1==nsE && pExpE[0]<3) { + *pResult = IPP_IS_INVALID; + return ippStsNoErr; + } + if(0 <= cpCmp_BNU(pExpE, nsE, pN0, nsN)) { + *pResult = IPP_IS_INVALID; + return ippStsNoErr; + } + + { + BNU_CHUNK_T* pFactor1 = pScratchBuffer; + BNU_CHUNK_T* pInv = pFactor1 +nsP+1; + BNU_CHUNK_T* pBufInv = pInv +nsP+1; + BNU_CHUNK_T* pBufE = pBufInv +nsP+1; + BNU_CHUNK_T* pBufFact = pBufE +nsP+1; + BNU_CHUNK_T* pProduct = pBufInv; + + /* make sure E*dP = 1 mod (P-1) */ + cpDec_BNU(pFactor1, pFactorP, nsP, 1); + cpMul_BNU_school(pProduct, pExpDp, nsP, pExpE, nsE); + cpMod_BNU(pProduct, nsP+nsE, pFactor1, nsP); + if(!cpEqu_BNU_CHUNK(pProduct, nsP, 1)) { + *pResult = IPP_IS_INVALID; + return ippStsNoErr; + } + /* make sure 1==GCD(E,P-1) => exist Inv(E,P-1) */ + if(!cpModInv_BNU(pInv, pExpE, nsE, pFactor1, nsP, pBufInv, pBufE, pBufFact)) { + *pResult = IPP_IS_INVALID; + return ippStsNoErr; + } + + /* make sure E*dQ = 1 mod (Q-1) */ + cpDec_BNU(pFactor1, pFactorQ, nsQ, 1); + cpMul_BNU_school(pProduct, pExpDq, nsQ, pExpE, nsE); + cpMod_BNU(pProduct, nsQ+nsE, pFactor1, nsQ); + if(!cpEqu_BNU_CHUNK(pProduct, nsQ, 1)) { + *pResult = IPP_IS_INVALID; + return ippStsNoErr; + } + /* make sure 1==GCD(E,Q-1) => exist Inv(E,Q-1) */ + if(!cpModInv_BNU(pInv, pExpE, nsE, pFactor1, nsQ, pBufInv, pBufE, pBufFact)) { + *pResult = IPP_IS_INVALID; + return ippStsNoErr; + } + } + + /* make sure Q*Qinv = 1 mod P */ + cpMontMul_BNU(pScratchBuffer, + pFactorQ, nsQ, + pInvQ, nsP, + pFactorP, nsP, MNT_HELPER(RSA_PRV_KEY_PMONT(pPrivateKeyType2)), + pScratchBuffer+nsP, NULL); + if(!cpEqu_BNU_CHUNK(pScratchBuffer, nsP, 1)) { + *pResult = IPP_IS_INVALID; + return ippStsNoErr; + } + + /* test priva exponent (optiobal) */ + if(pPrivateKeyType1) { + const BNU_CHUNK_T* pExpD = RSA_PRV_KEY_D(pPrivateKeyType1); + cpSize nsD = nsN; + + int resilt1 = isValidPriv1_classic(pN0,nsN, pExpE,nsE, pExpD,nsD, + pFactorP,nsP, pFactorQ,nsQ, + (BNU_CHUNK_T*)pScratchBuffer); + int resilt2 = isValidPriv1_rsa(pN0,nsN, pExpE,nsE, pExpD,nsD, + pFactorP,nsP, pFactorQ,nsQ, + (BNU_CHUNK_T*)pScratchBuffer); + if(IPP_IS_VALID!=resilt1 && IPP_IS_VALID!=resilt2) { + *pResult = IPP_IS_INVALID; + return ippStsNoErr; + } + } + + return ippStsNoErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsakeyprivate.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsakeyprivate.c new file mode 100644 index 0000000000..5c4c13e845 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsakeyprivate.c @@ -0,0 +1,496 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpbn.h" +#include "pcpngrsa.h" +#include "pcpngrsamontstuff.h" + +/*F* +// Name: ippsRSA_GetSizePrivateKeyType1 +// +// Purpose: Returns context size (bytes) of RSA private key (type1) context +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pSize +// +// ippStsNotSupportedModeErr MIN_RSA_SIZE > rsaModulusBitSize +// MAX_RSA_SIZE < rsaModulusBitSize +// +// ippStsBadArgErr 0 >= privateExpBitSize +// privateExpBitSize > rsaModulusBitSize +// +// ippStsNoErr no error +// +// Parameters: +// rsaModulusBitSize bitsize of RSA modulus (bitsize of N) +// privateExpBitSize bitsize of private exponent (bitsize of D) +// pSize pointer to the size of RSA key context (bytes) +*F*/ +static int cpSizeof_RSA_privateKey1(int rsaModulusBitSize, int privateExpBitSize) +{ + int prvExpLen = BITS_BNU_CHUNK(privateExpBitSize); + int modulusLen32 = BITS2WORD32_SIZE(rsaModulusBitSize); + int montNsize; + gsMontGetSize(ippBinaryMethod, modulusLen32, &montNsize); + + return sizeof(IppsRSAPrivateKeyState) + + prvExpLen*sizeof(BNU_CHUNK_T) + + sizeof(BNU_CHUNK_T)-1 + + montNsize + + (RSA_PRIVATE_KEY_ALIGNMENT-1); +} + +IPPFUN(IppStatus, ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) +{ + IPP_BAD_PTR1_RET(pKeySize); + IPP_BADARG_RET((MIN_RSA_SIZE>rsaModulusBitSize) || (rsaModulusBitSize>MAX_RSA_SIZE), ippStsNotSupportedModeErr); + IPP_BADARG_RET(!((0 rsaModulusBitSize +// MAX_RSA_SIZE < rsaModulusBitSize +// +// ippStsBadArgErr 0 >= privateExpBitSize +// privateExpBitSize > rsaModulusBitSize +// +// ippStsMemAllocErr keyCtxSize is not enough for operation +// +// ippStsNoErr no error +// +// Parameters: +// rsaModulusBitSize bitsize of RSA modulus (bitsize of N) +// privateExpBitSize bitsize of private exponent (bitsize of D) +// pKey pointer to the key context +// keyCtxSize size of memmory accosizted with key comtext +*F*/ +IPPFUN(IppStatus, ippsRSA_InitPrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, + IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +{ + IPP_BAD_PTR1_RET(pKey); + pKey = (IppsRSAPrivateKeyState*)( IPP_ALIGNED_PTR(pKey, RSA_PRIVATE_KEY_ALIGNMENT) ); + + IPP_BADARG_RET((MIN_RSA_SIZE>rsaModulusBitSize) || (rsaModulusBitSize>MAX_RSA_SIZE), ippStsNotSupportedModeErr); + IPP_BADARG_RET(!((0= pModulus +// 0 >= pPrivateExp +// +// ippStsSizeErr bitsize(pModulus) exceeds requested value +// bitsize(pPrivateExp) exceeds requested value +// +// ippStsNoErr no error +// +// Parameters: +// pModulus pointer to modulus (N) +// pPrivateExp pointer to public exponent (D) +// pKey pointer to the key context +*F*/ +IPPFUN(IppStatus, ippsRSA_SetPrivateKeyType1,(const IppsBigNumState* pModulus, + const IppsBigNumState* pPrivateExp, + IppsRSAPrivateKeyState* pKey)) +{ + IPP_BAD_PTR1_RET(pKey); + pKey = (IppsRSAPrivateKeyState*)( IPP_ALIGNED_PTR(pKey, RSA_PRIVATE_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PRV_KEY1_VALID_ID(pKey), ippStsContextMatchErr); + + IPP_BAD_PTR1_RET(pModulus); + pModulus = (IppsBigNumState*)( IPP_ALIGNED_PTR(pModulus, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pModulus), ippStsContextMatchErr); + IPP_BADARG_RET(!(0 < cpBN_tst(pModulus)), ippStsOutOfRangeErr); + IPP_BADARG_RET(BITSIZE_BNU(BN_NUMBER(pModulus), BN_SIZE(pModulus)) > RSA_PRV_KEY_MAXSIZE_N(pKey), ippStsSizeErr); + + IPP_BAD_PTR1_RET(pPrivateExp); + pPrivateExp = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPrivateExp, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pPrivateExp), ippStsContextMatchErr); + IPP_BADARG_RET(!(0 < cpBN_tst(pPrivateExp)), ippStsOutOfRangeErr); + IPP_BADARG_RET(BITSIZE_BNU(BN_NUMBER(pPrivateExp), BN_SIZE(pPrivateExp)) > RSA_PRV_KEY_MAXSIZE_D(pKey), ippStsSizeErr); + + { + /* store D */ + ZEXPAND_COPY_BNU(RSA_PRV_KEY_D(pKey), BITS_BNU_CHUNK(RSA_PRV_KEY_MAXSIZE_D(pKey)), BN_NUMBER(pPrivateExp), BN_SIZE(pPrivateExp)); + + /* setup montgomery engine */ + gsMontSet((Ipp32u*)BN_NUMBER(pModulus), BN_SIZE32(pModulus), RSA_PRV_KEY_NMONT(pKey)); + + RSA_PRV_KEY_BITSIZE_N(pKey) = cpBN_bitsize(pModulus); + RSA_PRV_KEY_BITSIZE_D(pKey) = cpBN_bitsize(pPrivateExp); + + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsRSA_GetSizePrivateKeyType2 +// +// Purpose: Returns context size (bytes) of RSA private key (type2) context +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pSize +// +// ippStsNotSupportedModeErr MIN_RSA_SIZE > (factorPbitSize+factorQbitSize) +// MAX_RSA_SIZE < (factorPbitSize+factorQbitSize) +// +// ippStsBadArgErr 0 >= factorPbitSize +// 0 >= factorQbitSize +// factorQbitSize > factorPbitSize +// +// ippStsNoErr no error +// +// Parameters: +// factorPbitSize bitsize of RSA modulus (bitsize of P) +// factorPbitSize bitsize of private exponent (bitsize of Q) +// pSize pointer to the size of RSA key context (bytes) +*F*/ +static int cpSizeof_RSA_privateKey2(int factorPbitSize, int factorQbitSize) +{ + int factorPlen = BITS_BNU_CHUNK(factorPbitSize); + int factorQlen = BITS_BNU_CHUNK(factorQbitSize); + int factorPlen32 = BITS2WORD32_SIZE(factorPbitSize); + int factorQlen32 = BITS2WORD32_SIZE(factorQbitSize); + int rsaModulusLen32 = BITS2WORD32_SIZE(factorPbitSize+factorQbitSize); + int montPsize; + int montQsize; + int montNsize; + gsMontGetSize(ippBinaryMethod, factorPlen32, &montPsize); + gsMontGetSize(ippBinaryMethod, factorQlen32, &montQsize); + gsMontGetSize(ippBinaryMethod, rsaModulusLen32, &montNsize); + + return sizeof(IppsRSAPrivateKeyState) + + factorPlen*sizeof(BNU_CHUNK_T) /* dp slot */ + + factorQlen*sizeof(BNU_CHUNK_T) /* dq slot */ + + factorPlen*sizeof(BNU_CHUNK_T) /* qinv slot */ + + sizeof(BNU_CHUNK_T)-1 + + montPsize + + montQsize + + montNsize + + (RSA_PRIVATE_KEY_ALIGNMENT-1); +} + +IPPFUN(IppStatus, ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) +{ + IPP_BAD_PTR1_RET(pKeySize); + IPP_BADARG_RET((factorPbitSize<=0) || (factorQbitSize<=0), ippStsBadArgErr); + IPP_BADARG_RET((factorPbitSize < factorQbitSize), ippStsBadArgErr); + IPP_BADARG_RET((MIN_RSA_SIZE>(factorPbitSize+factorQbitSize) || (factorPbitSize+factorQbitSize)>MAX_RSA_SIZE), ippStsNotSupportedModeErr); + + *pKeySize = cpSizeof_RSA_privateKey2(factorPbitSize, factorQbitSize); + return ippStsNoErr; +} + + +/*F* +// Name: ippsRSA_InitPrivateKeyType2 +// +// Purpose: Init RSA private key context +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pKey +// +// ippStsNotSupportedModeErr MIN_RSA_SIZE > (factorPbitSize+factorQbitSize) +// MAX_RSA_SIZE < (factorPbitSize+factorQbitSize) +// +// ippStsBadArgErr 0 >= factorPbitSize +// 0 >= factorQbitSize +// factorQbitSize > factorPbitSize +// +// ippStsMemAllocErr keyCtxSize is not enough for operation +// +// ippStsNoErr no error +// +// Parameters: +// factorPbitSize bitsize of RSA modulus (bitsize of P) +// factorQbitSize bitsize of private exponent (bitsize of Q) +// pKey pointer to the key context +// keyCtxSize size of memmory accosizted with key comtext +*F*/ +IPPFUN(IppStatus, ippsRSA_InitPrivateKeyType2,(int factorPbitSize, int factorQbitSize, + IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +{ + IPP_BAD_PTR1_RET(pKey); + IPP_BADARG_RET((factorPbitSize<=0) || (factorQbitSize<=0), ippStsBadArgErr); + IPP_BADARG_RET((factorPbitSize < factorQbitSize), ippStsBadArgErr); + IPP_BADARG_RET((MIN_RSA_SIZE>(factorPbitSize+factorQbitSize) || (factorPbitSize+factorQbitSize)>MAX_RSA_SIZE), ippStsNotSupportedModeErr); + + /* test available size of context buffer */ + IPP_BADARG_RET(keyCtxSize= pFactorP, 0 >= pFactorQ +// 0 >= pCrtExpP, 0 >= pCrtExpQ +// 0 >= pInverseQ +// +// ippStsSizeErr bitsize(pFactorP) exceeds requested value +// bitsize(pFactorQ) exceeds requested value +// bitsize(pCrtExpP) > bitsize(pFactorP) +// bitsize(pCrtExpQ) > bitsize(pFactorQ) +// bitsize(pInverseQ) > bitsize(pFactorP) +// +// ippStsNoErr no error +// +// Parameters: +// pFactorP, pFactorQ pointer to the RSA modulus (N) prime factors +// pCrtExpP, pCrtExpQ pointer to CTR's exponent +// pInverseQ 1/Q mod P +// pKey pointer to the key context +*F*/ +IPPFUN(IppStatus, ippsRSA_SetPrivateKeyType2,(const IppsBigNumState* pFactorP, + const IppsBigNumState* pFactorQ, + const IppsBigNumState* pCrtExpP, + const IppsBigNumState* pCrtExpQ, + const IppsBigNumState* pInverseQ, + IppsRSAPrivateKeyState* pKey)) +{ + IPP_BAD_PTR1_RET(pKey); + pKey = (IppsRSAPrivateKeyState*)( IPP_ALIGNED_PTR(pKey, RSA_PRIVATE_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PRV_KEY2_VALID_ID(pKey), ippStsContextMatchErr); + + IPP_BAD_PTR1_RET(pFactorP); + pFactorP = (IppsBigNumState*)( IPP_ALIGNED_PTR(pFactorP, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pFactorP), ippStsContextMatchErr); + IPP_BADARG_RET(!(0 < cpBN_tst(pFactorP)), ippStsOutOfRangeErr); + IPP_BADARG_RET(BITSIZE_BNU(BN_NUMBER(pFactorP), BN_SIZE(pFactorP)) > RSA_PRV_KEY_BITSIZE_P(pKey), ippStsSizeErr); + + IPP_BAD_PTR1_RET(pFactorQ); + pFactorQ = (IppsBigNumState*)( IPP_ALIGNED_PTR(pFactorQ, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pFactorQ), ippStsContextMatchErr); + IPP_BADARG_RET(!(0 < cpBN_tst(pFactorQ)), ippStsOutOfRangeErr); + IPP_BADARG_RET(BITSIZE_BNU(BN_NUMBER(pFactorQ), BN_SIZE(pFactorQ)) > RSA_PRV_KEY_BITSIZE_Q(pKey), ippStsSizeErr); + + /* let P>Q */ + IPP_BADARG_RET(0>=cpBN_cmp(pFactorP,pFactorQ), ippStsBadArgErr); + + IPP_BAD_PTR1_RET(pCrtExpP); + pCrtExpP = (IppsBigNumState*)( IPP_ALIGNED_PTR(pCrtExpP, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pCrtExpP), ippStsContextMatchErr); + IPP_BADARG_RET(!(0 < cpBN_tst(pCrtExpP)), ippStsOutOfRangeErr); + IPP_BADARG_RET(BITSIZE_BNU(BN_NUMBER(pCrtExpP), BN_SIZE(pCrtExpP)) > RSA_PRV_KEY_BITSIZE_P(pKey), ippStsSizeErr); + + IPP_BAD_PTR1_RET(pCrtExpQ); + pCrtExpQ = (IppsBigNumState*)( IPP_ALIGNED_PTR(pCrtExpQ, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pCrtExpQ), ippStsContextMatchErr); + IPP_BADARG_RET(!(0 < cpBN_tst(pCrtExpQ)), ippStsOutOfRangeErr); + IPP_BADARG_RET(BITSIZE_BNU(BN_NUMBER(pCrtExpQ), BN_SIZE(pCrtExpQ)) > RSA_PRV_KEY_BITSIZE_Q(pKey), ippStsSizeErr); + + IPP_BAD_PTR1_RET(pInverseQ); + pInverseQ = (IppsBigNumState*)( IPP_ALIGNED_PTR(pInverseQ, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pInverseQ), ippStsContextMatchErr); + IPP_BADARG_RET(!(0 < cpBN_tst(pInverseQ)), ippStsOutOfRangeErr); + IPP_BADARG_RET(BITSIZE_BNU(BN_NUMBER(pInverseQ), BN_SIZE(pInverseQ)) > RSA_PRV_KEY_BITSIZE_P(pKey), ippStsSizeErr); + + /* set bitsize(N) = 0, so the key contex is not ready */ + RSA_PRV_KEY_BITSIZE_N(pKey) = 0; + RSA_PRV_KEY_BITSIZE_D(pKey) = 0; + + /* setup montgomery engine P */ + gsMontSet((Ipp32u*)BN_NUMBER(pFactorP), BN_SIZE32(pFactorP), RSA_PRV_KEY_PMONT(pKey)); + /* setup montgomery engine Q */ + gsMontSet((Ipp32u*)BN_NUMBER(pFactorQ), BN_SIZE32(pFactorQ), RSA_PRV_KEY_QMONT(pKey)); + + /* actual size of key components */ + RSA_PRV_KEY_BITSIZE_P(pKey) = cpBN_bitsize(pFactorP); + RSA_PRV_KEY_BITSIZE_Q(pKey) = cpBN_bitsize(pFactorQ); + + /* store CTR's exp dp */ + ZEXPAND_COPY_BNU(RSA_PRV_KEY_DP(pKey), BITS_BNU_CHUNK(RSA_PRV_KEY_BITSIZE_P(pKey)), BN_NUMBER(pCrtExpP), BN_SIZE(pCrtExpP)); + /* store CTR's exp dq */ + ZEXPAND_COPY_BNU(RSA_PRV_KEY_DQ(pKey), BITS_BNU_CHUNK(RSA_PRV_KEY_BITSIZE_Q(pKey)), BN_NUMBER(pCrtExpQ), BN_SIZE(pCrtExpQ)); + /* store mont encoded CTR's coeff qinv */ + { + IppsMontState* pMontP = RSA_PRV_KEY_PMONT(pKey); + BNU_CHUNK_T* pTmpProduct = MNT_MODULUS(RSA_PRV_KEY_NMONT(pKey)); + cpMontMul_BNU(RSA_PRV_KEY_INVQ(pKey), + BN_NUMBER(pInverseQ), BN_SIZE(pInverseQ), + MNT_SQUARE_R(pMontP), MNT_SIZE(pMontP), + MNT_MODULUS(pMontP), MNT_SIZE(pMontP), MNT_HELPER(pMontP), + pTmpProduct, NULL); + } + + /* setup montgomery engine N = P*Q */ + { + BNU_CHUNK_T* pN = MNT_MODULUS(RSA_PRV_KEY_NMONT(pKey)); + cpSize nsN = BITS_BNU_CHUNK(RSA_PRV_KEY_BITSIZE_P(pKey) + RSA_PRV_KEY_BITSIZE_Q(pKey)); + + cpMul_BNU_school(pN, + BN_NUMBER(pFactorP), BN_SIZE(pFactorP), + BN_NUMBER(pFactorQ), BN_SIZE(pFactorQ)); + + gsMontSet((Ipp32u*)MNT_MODULUS(RSA_PRV_KEY_NMONT(pKey)), BITS2WORD32_SIZE(RSA_PRV_KEY_BITSIZE_P(pKey)+RSA_PRV_KEY_BITSIZE_Q(pKey)), RSA_PRV_KEY_NMONT(pKey)); + + FIX_BNU(pN, nsN); + RSA_PRV_KEY_BITSIZE_N(pKey) = BITSIZE_BNU(pN, nsN); + } + + return ippStsNoErr; +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsakeypublic.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsakeypublic.c new file mode 100644 index 0000000000..a76c955d2a --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsakeypublic.c @@ -0,0 +1,272 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcpbn.h" +#include "pcpngrsa.h" +#include "pcpngrsamontstuff.h" + + +/*F* +// Name: ippsRSA_GetSizePublicKey +// +// Purpose: Returns context size (bytes) of RSA public key context +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pSize +// +// ippStsNotSupportedModeErr MIN_RSA_SIZE > rsaModulusBitSize +// MAX_RSA_SIZE < rsaModulusBitSize +// +// ippStsBadArgErr 0 >= publicExpBitSize +// publicExpBitSize > rsaModulusBitSize +// +// ippStsNoErr no error +// +// Parameters: +// rsaModulusBitSize bitsize of RSA modulus (bitsize of N) +// publicExpBitSize bitsize of public exponent (bitsize of E) +// pSize pointer to the size of RSA key context (bytes) +*F*/ +static int cpSizeof_RSA_publicKey(int rsaModulusBitSize, int publicExpBitSize) +{ + int pubExpLen = BITS_BNU_CHUNK(publicExpBitSize); + int modulusLen32 = BITS2WORD32_SIZE(rsaModulusBitSize); + int montNsize; + gsMontGetSize(ippBinaryMethod, modulusLen32, &montNsize); + + return sizeof(IppsRSAPublicKeyState) + + pubExpLen*sizeof(BNU_CHUNK_T) + + sizeof(BNU_CHUNK_T)-1 + + montNsize + + (RSA_PUBLIC_KEY_ALIGNMENT-1); +} + +IPPFUN(IppStatus, ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int publicExpBitSize, int* pKeySize)) +{ + IPP_BAD_PTR1_RET(pKeySize); + IPP_BADARG_RET((MIN_RSA_SIZE>rsaModulusBitSize) || (rsaModulusBitSize>MAX_RSA_SIZE), ippStsNotSupportedModeErr); + IPP_BADARG_RET(!((0 rsaModulusBitSize +// MAX_RSA_SIZE < rsaModulusBitSize +// +// ippStsBadArgErr 0 >= publicExpBitSize +// publicExpBitSize > rsaModulusBitSize +// +// ippStsMemAllocErr keyCtxSize is not enough for operation +// +// ippStsNoErr no error +// +// Parameters: +// rsaModulusBitSize bitsize of RSA modulus (bitsize of N) +// publicExpBitSize bitsize of public exponent (bitsize of E) +// pKey pointer to the key context +// keyCtxSize size of memmory accosizted with key comtext +*F*/ +IPPFUN(IppStatus, ippsRSA_InitPublicKey,(int rsaModulusBitSize, int publicExpBitSize, + IppsRSAPublicKeyState* pKey, int keyCtxSize)) +{ + IPP_BAD_PTR1_RET(pKey); + pKey = (IppsRSAPublicKeyState*)( IPP_ALIGNED_PTR(pKey, RSA_PUBLIC_KEY_ALIGNMENT) ); + + IPP_BADARG_RET((MIN_RSA_SIZE>rsaModulusBitSize) || (rsaModulusBitSize>MAX_RSA_SIZE), ippStsNotSupportedModeErr); + IPP_BADARG_RET(!((0= pModulus +// 0 >= pPublicExp +// +// ippStsSizeErr bitsize(pModulus) exceeds requested value +// bitsize(pPublicExp) exceeds requested value +// +// ippStsNoErr no error +// +// Parameters: +// pModulus pointer to modulus (N) +// pPublicExp pointer to public exponent (E) +// pKey pointer to the key context +*F*/ +IPPFUN(IppStatus, ippsRSA_SetPublicKey,(const IppsBigNumState* pModulus, + const IppsBigNumState* pPublicExp, + IppsRSAPublicKeyState* pKey)) +{ + IPP_BAD_PTR1_RET(pKey); + pKey = (IppsRSAPublicKeyState*)( IPP_ALIGNED_PTR(pKey, RSA_PUBLIC_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PUB_KEY_VALID_ID(pKey), ippStsContextMatchErr); + + IPP_BAD_PTR1_RET(pModulus); + pModulus = (IppsBigNumState*)( IPP_ALIGNED_PTR(pModulus, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pModulus), ippStsContextMatchErr); + IPP_BADARG_RET(!(0 < cpBN_tst(pModulus)), ippStsOutOfRangeErr); + IPP_BADARG_RET(BITSIZE_BNU(BN_NUMBER(pModulus), BN_SIZE(pModulus)) > RSA_PUB_KEY_MAXSIZE_N(pKey), ippStsSizeErr); + + IPP_BAD_PTR1_RET(pPublicExp); + pPublicExp = (IppsBigNumState*)( IPP_ALIGNED_PTR(pPublicExp, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pPublicExp), ippStsContextMatchErr); + IPP_BADARG_RET(!(0 < cpBN_tst(pPublicExp)), ippStsOutOfRangeErr); + IPP_BADARG_RET(BITSIZE_BNU(BN_NUMBER(pPublicExp), BN_SIZE(pPublicExp)) > RSA_PUB_KEY_MAXSIZE_E(pKey), ippStsSizeErr); + + { + RSA_PUB_KEY_BITSIZE_N(pKey) = 0; + RSA_PUB_KEY_BITSIZE_E(pKey) = 0; + + /* store E */ + ZEXPAND_COPY_BNU(RSA_PUB_KEY_E(pKey), BITS_BNU_CHUNK(RSA_PUB_KEY_MAXSIZE_E(pKey)), BN_NUMBER(pPublicExp), BN_SIZE(pPublicExp)); + + /* setup montgomery engine */ + gsMontSet((Ipp32u*)BN_NUMBER(pModulus), BN_SIZE32(pModulus), RSA_PUB_KEY_NMONT(pKey)); + + RSA_PUB_KEY_BITSIZE_N(pKey) = cpBN_bitsize(pModulus); + RSA_PUB_KEY_BITSIZE_E(pKey) = cpBN_bitsize(pPublicExp); + + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsRSA_GetPublicKey +// +// Purpose: Extract key component from the key context +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pKey +// +// ippStsContextMatchErr !RSA_PUB_KEY_VALID_ID() +// !BN_VALID_ID(pModulus) +// !BN_VALID_ID(pExp) +// +// ippStsIncompleteContextErr public key is not set up +// +// ippStsSizeErr BN_ROOM(pModulus), BN_ROOM(pExp) is not enough +// +// ippStsNoErr no error +// +// Parameters: +// pModulus (optional) pointer to the modulus (N) +// pExp (optional) pointer to the public exponent (E) +// pKey pointer to the key context +*F*/ +IPPFUN(IppStatus, ippsRSA_GetPublicKey,(IppsBigNumState* pModulus, + IppsBigNumState* pExp, + const IppsRSAPublicKeyState* pKey)) +{ + IPP_BAD_PTR1_RET(pKey); + pKey = (IppsRSAPublicKeyState*)( IPP_ALIGNED_PTR(pKey, RSA_PUBLIC_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PUB_KEY_VALID_ID(pKey), ippStsContextMatchErr); + + if(pModulus) { + pModulus = (IppsBigNumState*)( IPP_ALIGNED_PTR(pModulus, BN_ALIGNMENT) ); + IPP_BADARG_RET(!BN_VALID_ID(pModulus), ippStsContextMatchErr); + IPP_BADARG_RET(!RSA_PUB_KEY_IS_SET(pKey), ippStsIncompleteContextErr); + IPP_BADARG_RET(BN_ROOM(pModulus)0; nsE--) { + eValue = dataE[nsE-1]; + + for(n=0; n=0; j--) { + mask_pattern = (BNU_CHUNK_T)(back_step-1); + + /* safeBuffer = (Y[] and mask_pattern) or (X[] and ~mask_pattern) */ + for(i=0; i>j) & 0x1) & (back_step^1); + j += back_step; + } + + /* execute rest bits of E */ + for(--nsE; nsE>0; nsE--) { + eValue = dataE[nsE-1]; + + for(j=BNU_CHUNK_BITS-1; j>=0; j--) { + mask_pattern = (BNU_CHUNK_T)(back_step-1); + + /* safeBuffer = (Y[] and mask_pattern) or (X[] and ~mask_pattern) */ + for(i=0; i>j) & 0x1) & (back_step^1); + j += back_step; + } + } + } + + return nsM; +} + + +/* +// "fast" fixed-size window montgomery exponentiation +// +// scratch buffer structure: +// precomutation resource[(1<>shift) &mask; + + /* initialize result */ + COPY_BNU(dataY, pResource+windowVal*nsM, nsM); + + for(eBit-=wBitSize; eBit>=0; eBit-=wBitSize) { + /* do square window times */ + for(n=0,windowVal=0; n>shift) &mask; + + if(windowVal) { + /* extract precomputed value and muptiply */ + cpMul_BNU(pProduct, dataY, nsM, pResource+windowVal*nsM, nsM, pBufferMulK); + cpMontRed_BNU(dataY, pProduct, dataM, nsM, m0); + } + } + } + } + + return nsM; +} + + +/* +// "safe" fixed-size window montgomery exponentiation +// +// scratch buffer structure: +// precomutation resource[(1<>shift) &mask; + + /* initialize result */ + cpScrambleGet((Ipp32u*)dataY, nsM*sizeof(BNU_CHUNK_T)/sizeof(Ipp32u), ((Ipp8u*)pResource)+windowVal*chunkSize, chunkSize); + + for(eBit-=bitsizeEwin; eBit>=0; eBit-=bitsizeEwin) { + /* do square window times */ + for(n=0,windowVal=0; n>shift) &mask; + + /* exptact precomputed value and muptiply */ + cpScrambleGet((Ipp32u*)dataT, nsM*sizeof(BNU_CHUNK_T)/sizeof(Ipp32u), ((Ipp8u*)pResource)+windowVal*chunkSize, chunkSize); + + cpMul_BNU(pProduct, dataY, nsM, dataT, nsM, pBufferMulK); + cpMontRed_BNU(dataY, pProduct, dataM, nsM, m0); + } + } + } + + return nsM; +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsamontstuff.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsamontstuff.h new file mode 100644 index 0000000000..2c69c8f0b3 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsamontstuff.h @@ -0,0 +1,229 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_CP_NG_RSA_MONT_STUFF_H) +#define _CP_NG_RSA_MONT_STUFF_H + +#include "pcpbn.h" +#include "pcpmontgomery.h" + +/* +// Montgomery engine preparation (GetSize/init/Set) +*/ +void gsMontGetSize(IppsExpMethod method, int length, int* pSize); +void gsMontInit(IppsExpMethod method, int length, IppsMontState* pCtx); +void gsMontSet(const Ipp32u* pModulo, int size, IppsMontState* pCtx); + + +/* +// optimal size of fixed window exponentiation +*/ +__INLINE cpSize gsMontExp_WinSize(cpSize bitsize) +{ + return + bitsize> 4096? 6 : /* 4096- .. . */ + bitsize> 2666? 5 : /* 2666 - 4095 */ + bitsize> 717? 4 : /* 717 - 2665 */ + bitsize> 178? 3 : /* 178 - 716 */ + bitsize> 41? 2 : 1; /* 41 - 177 */ +} + +/* +// Montgomery encoding/decoding +*/ +__INLINE cpSize gsMontEnc_BNU(BNU_CHUNK_T* pR, + const BNU_CHUNK_T* pXreg, cpSize nsX, + const IppsMontState* pMont, + BNU_CHUNK_T* pBuffer) +{ + cpSize nsM = MNT_SIZE(pMont); + BNU_CHUNK_T* pProduct = pBuffer; + BNU_CHUNK_T* pBufferKmul = NULL; + + cpMontMul_BNU(pR, + pXreg, nsX, MNT_SQUARE_R(pMont), nsM, + MNT_MODULUS(pMont), nsM, MNT_HELPER(pMont), + pProduct, pBufferKmul); + return nsM; +} + +__INLINE cpSize gsMontDec_BNU(BNU_CHUNK_T* pR, + const BNU_CHUNK_T* pXmont, cpSize nsX, + const IppsMontState* pMont, + BNU_CHUNK_T* pBuffer) +{ + cpSize nsM = MNT_SIZE(pMont); + ZEXPAND_COPY_BNU(pBuffer, 2*nsM, pXmont, nsX); + + cpMontRed_BNU(pR, pBuffer, MNT_MODULUS(pMont), nsM, MNT_HELPER(pMont)); + return nsM; +} + +__INLINE void gsMontEnc_BN(IppsBigNumState* pRbn, + const IppsBigNumState* pXbn, + const IppsMontState* pMont, + BNU_CHUNK_T* pBuffer) +{ + BNU_CHUNK_T* pR = BN_NUMBER(pRbn); + cpSize nsM = MNT_SIZE(pMont); + + gsMontEnc_BNU(pR, BN_NUMBER(pXbn), BN_SIZE(pXbn), pMont, pBuffer); + + FIX_BNU(pR, nsM); + BN_SIZE(pRbn) = nsM; + BN_SIGN(pRbn) = ippBigNumPOS; +} + +__INLINE void gsMontDec_BN(IppsBigNumState* pRbn, + const IppsBigNumState* pXbn, + const IppsMontState* pMont, + BNU_CHUNK_T* pBuffer) +{ + BNU_CHUNK_T* pR = BN_NUMBER(pRbn); + cpSize nsM = MNT_SIZE(pMont); + + gsMontDec_BNU(pR, BN_NUMBER(pXbn), BN_SIZE(pXbn), pMont, pBuffer); + + FIX_BNU(pR, nsM); + BN_SIZE(pRbn) = nsM; + BN_SIGN(pRbn) = ippBigNumPOS; +} + + +/* +// binary montgomery exponentiation ("fast" version) +*/ +cpSize gsMontExpBin_BNU(BNU_CHUNK_T* dataY, + const BNU_CHUNK_T* dataX, cpSize nsX, + const BNU_CHUNK_T* dataE, cpSize nsE, + const IppsMontState* pMont, + BNU_CHUNK_T* pBuffer); + +__INLINE void gsMontExpBin_BN(IppsBigNumState* pY, + const IppsBigNumState* pX, + const BNU_CHUNK_T* dataE, cpSize nsE, + const IppsMontState* pMont, + BNU_CHUNK_T* pBuffer) +{ + BNU_CHUNK_T* dataY = BN_NUMBER(pY); + cpSize nsY = gsMontExpBin_BNU(dataY, + BN_NUMBER(pX), BN_SIZE(pX), + dataE, nsE, + pMont, pBuffer); + FIX_BNU(dataY, nsY); + BN_SIZE(pY) = nsY; + BN_SIGN(pY) = ippBigNumPOS; +} + +/* +// fixed-size window montgomery exponentiation ("fast" version) +*/ +cpSize gsMontExpWin_BNU(BNU_CHUNK_T* pY, + const BNU_CHUNK_T* pX, cpSize nsX, + const BNU_CHUNK_T* dataE, cpSize nsE, cpSize bitsieW, + const IppsMontState* pMont, + BNU_CHUNK_T* pBuffer); + +__INLINE void gsMontExpWin_BN(IppsBigNumState* pY, + const IppsBigNumState* pX, + const BNU_CHUNK_T* dataE, cpSize nsE, cpSize bitsieW, + const IppsMontState* pMont, + BNU_CHUNK_T* pBuffer) +{ + BNU_CHUNK_T* dataY = BN_NUMBER(pY); + cpSize nsY = gsMontExpWin_BNU(dataY, + BN_NUMBER(pX), BN_SIZE(pX), + dataE, nsE, bitsieW, + pMont, pBuffer); + FIX_BNU(dataY, nsY); + BN_SIZE(pY) = nsY; + BN_SIGN(pY) = ippBigNumPOS; +} + +/* +// binary montgomery exponentiation ("safe" version) +*/ +__INLINE cpSize gsPrecompResourcelen(int n, cpSize nsM) +{ + cpSize nsR = sizeof(BNU_CHUNK_T)*nsM*n + (CACHE_LINE_SIZE-1); + nsR /=CACHE_LINE_SIZE; /* num of cashe lines */ + nsR *= (CACHE_LINE_SIZE/sizeof(BNU_CHUNK_T)); + return nsR; +} + +cpSize gsMontExpBin_BNU_sscm(BNU_CHUNK_T* pY, + const BNU_CHUNK_T* pX, cpSize nsX, + const BNU_CHUNK_T* pE, cpSize nsE, + const IppsMontState* pMont, + BNU_CHUNK_T* pBuffer); + +__INLINE void gsMontExpBin_BN_sscm(IppsBigNumState* pY, + const IppsBigNumState* pX, + const BNU_CHUNK_T* dataE, cpSize nsE, + const IppsMontState* pMont, + BNU_CHUNK_T* pBuffer) +{ + BNU_CHUNK_T* dataY = BN_NUMBER(pY); + cpSize nsY = gsMontExpBin_BNU_sscm(dataY, + BN_NUMBER(pX), BN_SIZE(pX), + dataE, nsE, + pMont, pBuffer); + FIX_BNU(dataY, nsY); + BN_SIZE(pY) = nsY; + BN_SIGN(pY) = ippBigNumPOS; +} + +/* +// fixed-size window montgomery exponentiation ("safe" version) +*/ +cpSize gsMontExpWin_BNU_sscm(BNU_CHUNK_T* dataY, + const BNU_CHUNK_T* dataX, cpSize nsX, + const BNU_CHUNK_T* dataE, cpSize nsE, cpSize bitsieEwin, + const IppsMontState* pMont, + BNU_CHUNK_T* pBuffer); + +__INLINE void gsMontExpWin_BN_sscm(IppsBigNumState* pY, + const IppsBigNumState* pX, + const BNU_CHUNK_T* dataE, cpSize nsE, cpSize bitsieEwin, + const IppsMontState* pMont, + BNU_CHUNK_T* pBuffer) +{ + BNU_CHUNK_T* dataY = BN_NUMBER(pY); + cpSize nsY = gsMontExpWin_BNU_sscm(dataY, + BN_NUMBER(pX), BN_SIZE(pX), + dataE, nsE, bitsieEwin, + pMont, pBuffer); + FIX_BNU(dataY, nsY); + BN_SIZE(pY) = nsY; + BN_SIGN(pY) = ippBigNumPOS; +} + +#endif /* _CP_NG_RSA_MONT_STUFF_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsassapkcsv15ca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsassapkcsv15ca.c new file mode 100644 index 0000000000..c16699fc14 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpngrsassapkcsv15ca.c @@ -0,0 +1,278 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" + +#include "pcpngrsa.h" +#include "pcphash.h" +#include "pcptool.h" + +static int EMSA_PKCSv15(const Ipp8u* msgDg, int lenMsgDg, + const Ipp8u* fixPS, int lenFixPS, + Ipp8u* pEM, int lenEM) +{ + /* + // encoded message format: + // EM = 00 || 01 || PS=(FF..FF) || 00 || T + // T = fixPS || msgDg + // len(PS) >= 8 + */ + int tLen = lenFixPS + lenMsgDg; + + if(lenEM >= tLen+11) { + int psLen = lenEM - 3 - tLen; + + PaddBlock(0xFF, pEM, lenEM); + pEM[0] = 0x00; + pEM[1] = 0x01; + pEM[2+psLen] = 0x00; + CopyBlock(fixPS, pEM+3+psLen, lenFixPS); + CopyBlock(msgDg, pEM+3+psLen+lenFixPS, lenMsgDg); + return 1; + } + else + return 0; /* encoded message length too long */ +} + +/* +// The DER encoding T of the DigestInfo value is equal to the following (see PKCS-1v2-2): +*/ +static const Ipp8u SHA1_fixPS[] = "\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14"; +static const Ipp8u SHA224_fixPS[] = "\x30\x2d\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x04\x05\x00\x04\x1c"; +static const Ipp8u SHA256_fixPS[] = "\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01\x05\x00\x04\x20"; +static const Ipp8u SHA384_fixPS[] = "\x30\x41\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x02\x05\x00\x04\x30"; +static const Ipp8u SHA512_fixPS[] = "\x30\x51\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x03\x05\x00\x04\x40"; +static const Ipp8u MD5_fixPS[] = "\x30\x20\x30\x0c\x06\x08\x2a\x86\x48\x86\xf7\x0d\x02\x05\x05\x00\x04\x10"; +static const Ipp8u SHA512_224_fixPS[] = "\x30\x2d\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x05\x05\x00\x04\x1c"; +static const Ipp8u SHA512_256_fixPS[] = "\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x06\x05\x00\x04\x20"; + +typedef struct { + const Ipp8u* pSalt; + int saltLen; +} SaltInfo; + +static SaltInfo pksc15_salt[] = { + {NULL, 0}, + {SHA1_fixPS, sizeof(SHA1_fixPS)-1}, + {SHA256_fixPS, sizeof(SHA256_fixPS)-1}, + {SHA224_fixPS, sizeof(SHA224_fixPS)-1}, + {SHA512_fixPS, sizeof(SHA512_fixPS)-1}, + {SHA384_fixPS, sizeof(SHA384_fixPS)-1}, + { MD5_fixPS, sizeof(MD5_fixPS)-1}, + {NULL, 0}, + {SHA512_224_fixPS, sizeof(SHA512_224_fixPS)-1}, + {SHA512_256_fixPS, sizeof(SHA512_256_fixPS)-1}, +}; +/* //////////////////////////////////////////////////////////////////////////////////////////////// */ + +static int GenerateSing(const Ipp8u* pMsg, int msgLen, /* message representation */ + const Ipp8u* pSalt, int saltLen, /* fied string */ + Ipp8u* pSign, + const IppsRSAPrivateKeyState* pPrvKey, + const IppsRSAPublicKeyState* pPubKey, + Ipp8u* pBuffer) +{ + /* size of RSA modulus in bytes and chunks */ + cpSize rsaBits = RSA_PRV_KEY_BITSIZE_N(pPrvKey); + cpSize k = BITS2WORD8_SIZE(rsaBits); + cpSize nsN = BITS_BNU_CHUNK(rsaBits); + + /* EMSA-PKCS-v1_5 encoding */ + int result = EMSA_PKCSv15(pMsg,msgLen, pSalt,saltLen, pSign, k); + + if(result) { + /* align buffer */ + BNU_CHUNK_T* pScratchBuffer = (BNU_CHUNK_T*)(IPP_ALIGNED_PTR(pBuffer, (int)sizeof(BNU_CHUNK_T)) ); + + /* temporary BNs */ + __ALIGN8 IppsBigNumState bnC; + __ALIGN8 IppsBigNumState bnP; + + /* make BNs */ + BN_Make(pScratchBuffer, pScratchBuffer+nsN+1, nsN, &bnC); + pScratchBuffer += (nsN+1)*2; + BN_Make(pScratchBuffer, pScratchBuffer+nsN+1, nsN, &bnP); + pScratchBuffer += (nsN+1)*2; + + /* + // private-key operation + */ + ippsSetOctString_BN(pSign, k, &bnC); + + if(RSA_PRV_KEY1_VALID_ID(pPrvKey)) + gsRSAprv_cipher(&bnP, &bnC, pPrvKey, pScratchBuffer); + else + gsRSAprv_cipher_crt(&bnP, &bnC, pPrvKey, pScratchBuffer); + + ippsGetOctString_BN(pSign, k, &bnP); + + /* check the result before send it out (fault attack mitigatioin) */ + if(pPubKey) { + gsRSApub_cipher(&bnP, &bnP, pPubKey, pScratchBuffer); + + /* check signature before send it out (fault attack mitigatioin) */ + if(0!=cpBN_cmp(&bnP, &bnC)) { + PaddBlock(0, pSign, k); + result = 0; + } + } + } + + return result; +} + +IPPFUN(IppStatus, ippsRSASign_PKCS1v15,(const Ipp8u* pMsg, int msgLen, + Ipp8u* pSign, + const IppsRSAPrivateKeyState* pPrvKey, + const IppsRSAPublicKeyState* pPubKey, + IppHashAlgId hashAlg, + Ipp8u* pBuffer)) +{ + /* test private key context */ + IPP_BAD_PTR2_RET(pPrvKey, pBuffer); + pPrvKey = (IppsRSAPrivateKeyState*)( IPP_ALIGNED_PTR(pPrvKey, RSA_PRIVATE_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PRV_KEY_VALID_ID(pPrvKey), ippStsContextMatchErr); + IPP_BADARG_RET(!RSA_PRV_KEY_IS_SET(pPrvKey), ippStsIncompleteContextErr); + + /* test hash algorith ID */ + hashAlg = cpValidHashAlg(hashAlg); + IPP_BADARG_RET(ippHashAlg_Unknown==hashAlg, ippStsNotSupportedModeErr); + + /* use aligned public key context if defined */ + if(pPubKey) { + pPubKey = (IppsRSAPublicKeyState*)( IPP_ALIGNED_PTR(pPubKey, RSA_PUBLIC_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PUB_KEY_VALID_ID(pPubKey), ippStsContextMatchErr); + IPP_BADARG_RET(!RSA_PUB_KEY_IS_SET(pPubKey), ippStsIncompleteContextErr); + } + + /* test data pointer */ + IPP_BAD_PTR2_RET(pMsg, pSign); + /* test length */ + IPP_BADARG_RET(msgLen<0, ippStsLengthErr); + + { + Ipp8u md[IPP_SHA512_DIGEST_BITSIZE/BYTESIZE]; + int mdLen = cpHashSize(hashAlg); + ippsHashMessage(pMsg, msgLen, md, hashAlg); + + { + const Ipp8u* pSalt = pksc15_salt[hashAlg].pSalt; + int saltLen = pksc15_salt[hashAlg].saltLen; + + int sts = GenerateSing(md, mdLen, + pSalt, saltLen, + pSign, + pPrvKey, pPubKey, pBuffer); + + return (1==sts)? ippStsNoErr : ippStsSizeErr; + } + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +static int VerifySing(const Ipp8u* pMsg, int msgLen, /* message representation */ + const Ipp8u* pSalt, int saltLen, /* fied string */ + const Ipp8u* pSign, + int* pIsValid, + const IppsRSAPublicKeyState* pKey, + Ipp8u* pBuffer) +{ + /* size of RSA modulus in bytes and chunks */ + cpSize rsaBits = RSA_PUB_KEY_BITSIZE_N(pKey); + cpSize k = BITS2WORD8_SIZE(rsaBits); + cpSize nsN = BITS_BNU_CHUNK(rsaBits); + + /* align buffer */ + BNU_CHUNK_T* pScratchBuffer = (BNU_CHUNK_T*)(IPP_ALIGNED_PTR(pBuffer, (int)sizeof(BNU_CHUNK_T)) ); + + /* temporary BNs */ + __ALIGN8 IppsBigNumState bnC; + __ALIGN8 IppsBigNumState bnP; + + /* make BNs */ + BN_Make(pScratchBuffer, pScratchBuffer+nsN+1, nsN, &bnC); + pScratchBuffer += (nsN+1)*2; + BN_Make(pScratchBuffer, pScratchBuffer+nsN+1, nsN, &bnP); + pScratchBuffer += (nsN+1)*2; + + /* + // public-key operation + */ + ippsSetOctString_BN(pSign, k, &bnP); + gsRSApub_cipher(&bnC, &bnP, pKey, pScratchBuffer); + + /* convert EM into the string */ + ippsGetOctString_BN((Ipp8u*)(BN_BUFFER(&bnC)), k, &bnC); + + /* EMSA-PKCS-v1_5 encoding */ + if( EMSA_PKCSv15(pMsg,msgLen, pSalt,saltLen, (Ipp8u*)(BN_NUMBER(&bnC)), k) ) { + *pIsValid = 1==EquBlock((Ipp8u*)(BN_BUFFER(&bnC)), (Ipp8u*)(BN_NUMBER(&bnC)), k); + return 1; + } + else + return 0; +} + +IPPFUN(IppStatus, ippsRSAVerify_PKCS1v15,(const Ipp8u* pMsg, int msgLen, + const Ipp8u* pSign, int* pIsValid, + const IppsRSAPublicKeyState* pKey, + IppHashAlgId hashAlg, + Ipp8u* pBuffer)) +{ + /* test public key context */ + IPP_BAD_PTR2_RET(pKey, pBuffer); + pKey = (IppsRSAPublicKeyState*)( IPP_ALIGNED_PTR(pKey, RSA_PUBLIC_KEY_ALIGNMENT) ); + IPP_BADARG_RET(!RSA_PUB_KEY_VALID_ID(pKey), ippStsContextMatchErr); + IPP_BADARG_RET(!RSA_PUB_KEY_IS_SET(pKey), ippStsIncompleteContextErr); + + /* test hash algorith ID */ + hashAlg = cpValidHashAlg(hashAlg); + IPP_BADARG_RET(ippHashAlg_Unknown==hashAlg, ippStsNotSupportedModeErr); + + /* test data pointer */ + IPP_BAD_PTR3_RET(pMsg, pSign, pIsValid); + /* test length */ + IPP_BADARG_RET(msgLen<0, ippStsLengthErr); + + *pIsValid = 0; + { + Ipp8u md[IPP_SHA512_DIGEST_BITSIZE/BYTESIZE]; + int mdLen = cpHashSize(hashAlg); + ippsHashMessage(pMsg, msgLen, md, hashAlg); + + return VerifySing(md, mdLen, + pksc15_salt[hashAlg].pSalt, pksc15_salt[hashAlg].saltLen, + pSign, pIsValid, + pKey, pBuffer)? ippStsNoErr : ippStsSizeErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcppma.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcppma.h new file mode 100644 index 0000000000..66f5da33fe --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcppma.h @@ -0,0 +1,83 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_PCP_PMA_H) +#define _PCP_PMA_H + +#include "pcpbn.h" +#include "pcpmontgomery.h" + + +/* +// Prime Modulo Arithmetic +*/ +#define PMA_set(r,a) \ + BN_SIGN((r)) = BN_SIGN((a)); \ + BN_SIZE((r)) = BN_SIZE((a)); \ + ZEXPAND_COPY_BNU(BN_NUMBER((r)),BN_ROOM((r)), BN_NUMBER((a)),BN_SIZE((a))) \ + +#define PMA_mod(r,a,modulo) \ + ippsMod_BN((a),(modulo),(r)) + +#define PMA_inv(r,a,modulo) \ + ippsModInv_BN((a),(modulo),(r)) + +#define PMA_div2(r,a,modulo) { \ + if( IsOdd_BN((a)) ) { \ + ippsAdd_BN((a), (modulo), (a)); \ + } \ + BN_SIZE((r)) = cpLSR_BNU(BN_NUMBER((r)), BN_NUMBER((a)), (int)BN_SIZE((a)), 1); \ + cpBN_fix((r)); \ +} + +#define PMA_add(r,a,b,modulo) \ + ippsAdd_BN((a),(b),(r)); \ + if( cpCmp_BNU(BN_NUMBER((r)),BN_SIZE((r)),BN_NUMBER((modulo)),BN_SIZE(modulo)) >= 0 ) \ + ippsSub_BN((r),(modulo),(r)) + +#define PMA_sub(r,a,b,modulo) \ + ippsSub_BN((a),(b),(r)); \ + if( BN_NEGATIVE((r)) ) \ + ippsAdd_BN((r),(modulo),(r)) + +#define PMA_enc(r,a,mont) \ + cpMontEnc_BN((r), (a), (mont)) + +#define PMA_dec(r,a,mont) \ + cpMontDec_BN((r), (a), (mont)) + +#define PMA_sqre(r,a,mont) \ + ippsMontMul((a),(a), (mont),(r)) + +#define PMA_mule(r,a,b,mont) \ + ippsMontMul((a),(b), (mont),(r)) + +#endif /* _PCP_PMA_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprimeg.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprimeg.h new file mode 100644 index 0000000000..7e54efbe61 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprimeg.h @@ -0,0 +1,78 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_CP_PRIME_H) +#define _CP_PRIME_H + +#include "pcpbn.h" +#include "pcpmontgomery.h" + + +/* +// Prime context +*/ +struct _cpPrime { + IppCtxId idCtx; /* Prime context identifier */ + cpSize maxBitSize; /* max bit length */ + BNU_CHUNK_T* pPrime; /* prime value */ + BNU_CHUNK_T* pT1; /* temporary BNU */ + BNU_CHUNK_T* pT2; /* temporary BNU */ + BNU_CHUNK_T* pT3; /* temporary BNU */ + IppsMontState* pMont; /* montgomery engine */ +}; + +/* alignment */ +#define PRIME_ALIGNMENT ((int)sizeof(void*)) + +/* Prime accessory macros */ +#define PRIME_ID(ctx) ((ctx)->idCtx) +#define PRIME_MAXBITSIZE(ctx) ((ctx)->maxBitSize) +#define PRIME_NUMBER(ctx) ((ctx)->pPrime) +#define PRIME_TEMP1(ctx) ((ctx)->pT1) +#define PRIME_TEMP2(ctx) ((ctx)->pT2) +#define PRIME_TEMP3(ctx) ((ctx)->pT3) +#define PRIME_MONT(ctx) ((ctx)->pMont) + +#define PRIME_VALID_ID(ctx) (PRIME_ID((ctx))==idCtxPrimeNumber) + +/* easy prime test */ +int cpMimimalPrimeTest(const Ipp32u* pPrime, cpSize ns); + +/* prime test */ +int cpPrimeTest(const BNU_CHUNK_T* pPrime, cpSize primeLen, + cpSize nTrials, + IppsPrimeState* pCtx, + IppBitSupplier rndFunc, void* pRndParam); + +void cpPackPrimeCtx(const IppsPrimeState* pCtx, Ipp8u* pBuffer); +void cpUnpackPrimeCtx(const Ipp8u* pBuffer, IppsPrimeState* pCtx); + +#endif /* _CP_PRIME_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprimegenca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprimegenca.c new file mode 100644 index 0000000000..6b105e8c16 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprimegenca.c @@ -0,0 +1,472 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owncp.h" +#include "pcpprimeg.h" +#include "pcptool.h" + + +/*F* +// Name: ippsPrimeTest +// +// Purpose: Tests the set BN for being a probable prime. +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pCtx +// NULL == pResult +// NULL == rndFunc +// ippStsContextMatchErr illegal pCtx->idCtx +// ippStsOutOfRangeErr zero value under the test +// ippStsBadArgErr 1 > nTrials +// ippStsNoErr no error +// +// Parameters: +// nTrials parameter for the Miller-Rabin probable primality test +// pResult pointer to the test result (IS_COMPOSITE / IS_PRIME) +// pCtx pointer to the context +// rndFunc external PRNG +// pRndParam pointer to the external PRNG parameters +*F*/ + +/* minimal prime test */ +static Ipp32u PrimeList[] = { + 2, 3, 5, 7, 11, 13, 17, 19, + 23, 29, 31, 37, 41, 43, 47, 53, + 59, 61, 67, 71, 73, 79, 83, 89, + 97, 101, 103, 107, 109, 113, 127, 131, + 137, 139, 149, 151, 157, 163, 167, 173, + 179, 181, 191, 193, 197, 199, 211, 223, + 227, 229, 233, 239, 241, 251, 257, 263, + 269, 271, 277, 281, 283, 293, 307, 311, + 313, 317, 331, 337, 347, 349, 353, 359, + 367, 373, 379, 383, 389, 397, 401, 409, + 419, 421, 431, 433, 439, 443, 449, 457, + 461, 463, 467, 479, 487, 491, 499, 503, + 509, 521, 523, 541, 547, 557, 563, 569, + 571, 577, 587, 593, 599, 601, 607, 613, + 617, 619, 631, 641, 643, 647, 653, 659, + 661, 673, 677, 683, 691, 701, 709, 719, + 727, 733, 739, 743, 751, 757, 761, 769, + 773, 787, 797, 809, 811, 821, 823, 827, + 829, 839, 853, 857, 859, 863, 877, 881, + 883, 887, 907, 911, 919, 929, 937, 941, + 947, 953, 967, 971, 977, 983, 991, 997, + 1009,1013,1019,1021,1031,1033,1039,1049, + 1051,1061,1063,1069,1087,1091,1093,1097, + 1103,1109,1117,1123,1129,1151,1153,1163, + 1171,1181,1187,1193,1201,1213,1217,1223, + 1229,1231,1237,1249,1259,1277,1279,1283, + 1289,1291,1297,1301,1303,1307,1319,1321, + 1327,1361,1367,1373,1381,1399,1409,1423, + 1427,1429,1433,1439,1447,1451,1453,1459, + 1471,1481,1483,1487,1489,1493,1499,1511, + 1523,1531,1543,1549,1553,1559,1567,1571, + 1579,1583,1597,1601,1607,1609,1613,1619, + 1621,1627,1637,1657,1663,1667,1669,1693, + 1697,1699,1709,1721,1723,1733,1741,1747, + 1753,1759,1777,1783,1787,1789,1801,1811, + 1823,1831,1847,1861,1867,1871,1873,1877, + 1879,1889,1901,1907,1913,1931,1933,1949, + 1951,1973,1979,1987,1993,1997,1999,2003, + 2011,2017,2027,2029,2039,2053,2063,2069, + 2081,2083,2087,2089,2099,2111,2113,2129, + 2131,2137,2141,2143,2153,2161,2179,2203, + 2207,2213,2221,2237,2239,2243,2251,2267, + 2269,2273,2281,2287,2293,2297,2309,2311, + 2333,2339,2341,2347,2351,2357,2371,2377, + 2381,2383,2389,2393,2399,2411,2417,2423, + 2437,2441,2447,2459,2467,2473,2477,2503, + 2521,2531,2539,2543,2549,2551,2557,2579, + 2591,2593,2609,2617,2621,2633,2647,2657, + 2659,2663,2671,2677,2683,2687,2689,2693, + 2699,2707,2711,2713,2719,2729,2731,2741, + 2749,2753,2767,2777,2789,2791,2797,2801, + 2803,2819,2833,2837,2843,2851,2857,2861, + 2879,2887,2897,2903,2909,2917,2927,2939, + 2953,2957,2963,2969,2971,2999,3001,3011, + 3019,3023,3037,3041,3049,3061,3067,3079, + 3083,3089,3109,3119,3121,3137,3163,3167, + 3169,3181,3187,3191,3203,3209,3217,3221, + 3229,3251,3253,3257,3259,3271,3299,3301, + 3307,3313,3319,3323,3329,3331,3343,3347, + 3359,3361,3371,3373,3389,3391,3407,3413, + 3433,3449,3457,3461,3463,3467,3469,3491, + 3499,3511,3517,3527,3529,3533,3539,3541, + 3547,3557,3559,3571,3581,3583,3593,3607, + 3613,3617,3623,3631,3637,3643,3659,3671, + 3673,3677,3691,3697,3701,3709,3719,3727, + 3733,3739,3761,3767,3769,3779,3793,3797, + 3803,3821,3823,3833,3847,3851,3853,3863, + 3877,3881,3889,3907,3911,3917,3919,3923, + 3929,3931,3943,3947,3967,3989,4001,4003, + 4007,4013,4019,4021,4027,4049,4051,4057, + 4073,4079,4091,4093,4099,4111,4127,4129, + 4133,4139,4153,4157,4159,4177,4201,4211, + 4217,4219,4229,4231,4241,4243,4253,4259, + 4261,4271,4273,4283,4289,4297,4327,4337, + 4339,4349,4357,4363,4373,4391,4397,4409, + 4421,4423,4441,4447,4451,4457,4463,4481, + 4483,4493,4507,4513,4517,4519,4523,4547, + 4549,4561,4567,4583,4591,4597,4603,4621, + 4637,4639,4643,4649,4651,4657,4663,4673, + 4679,4691,4703,4721,4723,4729,4733,4751, + 4759,4783,4787,4789,4793,4799,4801,4813, + 4817,4831,4861,4871,4877,4889,4903,4909, + 4919,4931,4933,4937,4943,4951,4957,4967, + 4969,4973,4987,4993,4999,5003,5009,5011, + 5021,5023,5039,5051,5059,5077,5081,5087, + 5099,5101,5107,5113,5119,5147,5153,5167, + 5171,5179,5189,5197,5209,5227,5231,5233, + 5237,5261,5273,5279,5281,5297,5303,5309, + 5323,5333,5347,5351,5381,5387,5393,5399, + 5407,5413,5417,5419,5431,5437,5441,5443, + 5449,5471,5477,5479,5483,5501,5503,5507, + 5519,5521,5527,5531,5557,5563,5569,5573, + 5581,5591,5623,5639,5641,5647,5651,5653, + 5657,5659,5669,5683,5689,5693,5701,5711, + 5717,5737,5741,5743,5749,5779,5783,5791, + 5801,5807,5813,5821,5827,5839,5843,5849, + 5851,5857,5861,5867,5869,5879,5881,5897, + 5903,5923,5927,5939,5953,5981,5987,6007, + 6011,6029,6037,6043,6047,6053,6067,6073, + 6079,6089,6091,6101,6113,6121,6131,6133, + 6143,6151,6163,6173,6197,6199,6203,6211, + 6217,6221,6229,6247,6257,6263,6269,6271, + 6277,6287,6299,6301,6311,6317,6323,6329, + 6337,6343,6353,6359,6361,6367,6373,6379, + 6389,6397,6421,6427,6449,6451,6469,6473, + 6481,6491,6521,6529,6547,6551,6553,6563, + 6569,6571,6577,6581,6599,6607,6619,6637, + 6653,6659,6661,6673,6679,6689,6691,6701, + 6703,6709,6719,6733,6737,6761,6763,6779, + 6781,6791,6793,6803,6823,6827,6829,6833, + 6841,6857,6863,6869,6871,6883,6899,6907, + 6911,6917,6947,6949,6959,6961,6967,6971, + 6977,6983,6991,6997,7001,7013,7019,7027, + 7039,7043,7057,7069,7079,7103,7109,7121, + 7127,7129,7151,7159,7177,7187,7193,7207, + 7211,7213,7219,7229,7237,7243,7247,7253, + 7283,7297,7307,7309,7321,7331,7333,7349, + 7351,7369,7393,7411,7417,7433,7451,7457, + 7459,7477,7481,7487,7489,7499,7507,7517, + 7523,7529,7537,7541,7547,7549,7559,7561, + 7573,7577,7583,7589,7591,7603,7607,7621, + 7639,7643,7649,7669,7673,7681,7687,7691, + 7699,7703,7717,7723,7727,7741,7753,7757, + 7759,7789,7793,7817,7823,7829,7841,7853, + 7867,7873,7877,7879,7883,7901,7907,7919, + 7927,7933,7937,7949,7951,7963,7993,8009, + 8011,8017,8039,8053,8059,8069,8081,8087, + 8089,8093,8101,8111,8117,8123,8147,8161, + 8167,8171,8179,8191,8209,8219,8221,8231, + 8233,8237,8243,8263,8269,8273,8287,8291, + 8293,8297,8311,8317,8329,8353,8363,8369, + 8377,8387,8389,8419,8423,8429,8431,8443, + 8447,8461,8467,8501,8513,8521,8527,8537, + 8539,8543,8563,8573,8581,8597,8599,8609, + 8623,8627,8629,8641,8647,8663,8669,8677, + 8681,8689,8693,8699,8707,8713,8719,8731, + 8737,8741,8747,8753,8761,8779,8783,8803, + 8807,8819,8821,8831,8837,8839,8849,8861, + 8863,8867,8887,8893,8923,8929,8933,8941, + 8951,8963,8969,8971,8999,9001,9007,9011, + 9013,9029,9041,9043,9049,9059,9067,9091, + 9103,9109,9127,9133,9137,9151,9157,9161, + 9173,9181,9187,9199,9203,9209,9221,9227, + 9239,9241,9257,9277,9281,9283,9293,9311, + 9319,9323,9337,9341,9343,9349,9371,9377, + 9391,9397,9403,9413,9419,9421,9431,9433, + 9437,9439,9461,9463,9467,9473,9479,9491, + 9497,9511,9521,9533,9539,9547,9551,9587, + 9601,9613,9619,9623,9629,9631,9643,9649, + 9661,9677,9679,9689,9697,9719,9721,9733, + 9739,9743,9749,9767,9769,9781,9787,9791, + 9803,9811,9817,9829,9833,9839,9851,9857, + 9859,9871,9883,9887,9901,9907,9923,9929, + 9931,9941,9949,9967,9973,10007,10009,10037, + 10039,10061,10067,10069,10079,10091,10093,10099, + 10103,10111,10133,10139,10141,10151,10159,10163, + 10169,10177,10181,10193,10211,10223,10243,10247, + 10253,10259,10267,10271,10273,10289,10301,10303, + 10313,10321,10331,10333,10337,10343,10357,10369, + 10391,10399,10427,10429,10433,10453,10457,10459, + 10463,10477,10487,10499,10501,10513,10529,10531, + 10559,10567,10589,10597,10601,10607,10613,10627, + 10631,10639,10651,10657,10663,10667,10687,10691, + 10709,10711,10723,10729,10733,10739,10753,10771, + 10781,10789,10799,10831,10837,10847,10853,10859, + 10861,10867,10883,10889,10891,10903,10909,10937, + 10939,10949,10957,10973,10979,10987,10993,11003, + 11027,11047,11057,11059,11069,11071,11083,11087, + 11093,11113,11117,11119,11131,11149,11159,11161, + 11171,11173,11177,11197,11213,11239,11243,11251, + 11257,11261,11273,11279,11287,11299,11311,11317, + 11321,11329,11351,11353,11369,11383,11393,11399, + 11411,11423,11437,11443,11447,11467,11471,11483, + 11489,11491,11497,11503,11519,11527,11549,11551, + 11579,11587,11593,11597,11617,11621,11633,11657, + 11677,11681,11689,11699,11701,11717,11719,11731, + 11743,11777,11779,11783,11789,11801,11807,11813, + 11821,11827,11831,11833,11839,11863,11867,11887, + 11897,11903,11909,11923,11927,11933,11939,11941, + 11953,11959,11969,11971,11981,11987,12007,12011, + 12037,12041,12043,12049,12071,12073,12097,12101, + 12107,12109,12113,12119,12143,12149,12157,12161, + 12163,12197,12203,12211,12227,12239,12241,12251, + 12253,12263,12269,12277,12281,12289,12301,12323, + 12329,12343,12347,12373,12377,12379,12391,12401, + 12409,12413,12421,12433,12437,12451,12457,12473, + 12479,12487,12491,12497,12503,12511,12517,12527, + 12539,12541,12547,12553,12569,12577,12583,12589, + 12601,12611,12613,12619,12637,12641,12647,12653, + 12659,12671,12689,12697,12703,12713,12721,12739, + 12743,12757,12763,12781,12791,12799,12809,12821, + 12823,12829,12841,12853,12889,12893,12899,12907, + 12911,12917,12919,12923,12941,12953,12959,12967, + 12973,12979,12983,13001,13003,13007,13009,13033, + 13037,13043,13049,13063,13093,13099,13103,13109, + 13121,13127,13147,13151,13159,13163,13171,13177, + 13183,13187,13217,13219,13229,13241,13249,13259, + 13267,13291,13297,13309,13313,13327,13331,13337, + 13339,13367,13381,13397,13399,13411,13417,13421, + 13441,13451,13457,13463,13469,13477,13487,13499, + 13513,13523,13537,13553,13567,13577,13591,13597, + 13613,13619,13627,13633,13649,13669,13679,13681, + 13687,13691,13693,13697,13709,13711,13721,13723, + 13729,13751,13757,13759,13763,13781,13789,13799, + 13807,13829,13831,13841,13859,13873,13877,13879, + 13883,13901,13903,13907,13913,13921,13931,13933, + 13963,13967,13997,13999,14009,14011,14029,14033, + 14051,14057,14071,14081,14083,14087,14107,14143, + 14149,14153,14159,14173,14177,14197,14207,14221, + 14243,14249,14251,14281,14293,14303,14321,14323, + 14327,14341,14347,14369,14387,14389,14401,14407, + 14411,14419,14423,14431,14437,14447,14449,14461, + 14479,14489,14503,14519,14533,14537,14543,14549, + 14551,14557,14561,14563,14591,14593,14621,14627, + 14629,14633,14639,14653,14657,14669,14683,14699, + 14713,14717,14723,14731,14737,14741,14747,14753, + 14759,14767,14771,14779,14783,14797,14813,14821, + 14827,14831,14843,14851,14867,14869,14879,14887, + 14891,14897,14923,14929,14939,14947,14951,14957, + 14969,14983,15013,15017,15031,15053,15061,15073, + 15077,15083,15091,15101,15107,15121,15131,15137, + 15139,15149,15161,15173,15187,15193,15199,15217, + 15227,15233,15241,15259,15263,15269,15271,15277, + 15287,15289,15299,15307,15313,15319,15329,15331, + 15349,15359,15361,15373,15377,15383,15391,15401, + 15413,15427,15439,15443,15451,15461,15467,15473, + 15493,15497,15511,15527,15541,15551,15559,15569, + 15581,15583,15601,15607,15619,15629,15641,15643, + 15647,15649,15661,15667,15671,15679,15683,15727, + 15731,15733,15737,15739,15749,15761,15767,15773, + 15787,15791,15797,15803,15809,15817,15823,15859, + 15877,15881,15887,15889,15901,15907,15913,15919, + 15923,15937,15959,15971,15973,15991,16001,16007, + 16033,16057,16061,16063,16067,16069,16073,16087, + 16091,16097,16103,16111,16127,16139,16141,16183, + 16187,16189,16193,16217,16223,16229,16231,16249, + 16253,16267,16273,16301,16319,16333,16339,16349, + 16361,16363,16369,16381,16411,16417,16421,16427, + 16433,16447,16451,16453,16477,16481,16487,16493, + 16519,16529,16547,16553,16561,16567,16573,16603, + 16607,16619,16631,16633,16649,16651,16657,16661, + 16673,16691,16693,16699,16703,16729,16741,16747, + 16759,16763,16787,16811,16823,16829,16831,16843, + 16871,16879,16883,16889,16901,16903,16921,16927, + 16931,16937,16943,16963,16979,16981,16987,16993, + 17011,17021,17027,17029,17033,17041,17047,17053, + 17077,17093,17099,17107,17117,17123,17137,17159, + 17167,17183,17189,17191,17203,17207,17209,17231, + 17239,17257,17291,17293,17299,17317,17321,17327, + 17333,17341,17351,17359,17377,17383,17387,17389, + 17393,17401,17417,17419,17431,17443,17449,17467, + 17471,17477,17483,17489,17491,17497,17509,17519, + 17539,17551,17569,17573,17579,17581,17597,17599, + 17609,17623,17627,17657,17659,17669,17681,17683, + 17707,17713,17729,17737,17747,17749,17761,17783, + 17789,17791,17807,17827,17837,17839,17851,17863 +}; + +static +Ipp32u cpMod32(const Ipp32u* pX, cpSize sizeX, Ipp32u divider) +{ + cpSize n; + Ipp32u r; + for(n=sizeX, r=0; n>0; n--) { + Ipp64u tmp = MAKEDWORD(pX[n-1],r); + r = (Ipp32u)(tmp%divider); + } + return r; +} + +int cpMimimalPrimeTest(const Ipp32u* pPrime, cpSize len32) +{ + cpSize i; + + FIX_BNU(pPrime, len32); + + /* take a look in the list */ + if(1==len32) { + for(i=0; i<(cpSize)(sizeof(PrimeList)/sizeof(Ipp32u)); i++) { + if(pPrime[0]==PrimeList[i]) + return 1; + } + } + + /* test if value under the test is divisible by first prime numbers 2,3,5, ... */ + for(i=0; i<(cpSize)(sizeof(PrimeList)/sizeof(Ipp32u)); i++) { + if(0 == cpMod32(pPrime, len32, PrimeList[i])) + return 0; + } + + return 1; +} + +/* Rabin-Miller test */ +static +int RabinMiller(int a, + BNU_CHUNK_T* pZ, + BNU_CHUNK_T* pR, cpSize nsR, + BNU_CHUNK_T* pM, cpSize nsM, + IppsMontState* pMont) +{ + /* modulus and it length and other parameters */ + const BNU_CHUNK_T* pModulus = MNT_MODULUS(pMont); + cpSize modLen = MNT_SIZE(pMont); + BNU_CHUNK_T m0 = MNT_HELPER(pMont); + BNU_CHUNK_T* pProduct = MNT_PRODUCT(pMont); + BNU_CHUNK_T* pKBuffer = MNT_KBUFFER(pMont); + + /* compute z = r^m mod prime */ + nsR = cpMontEnc_BNU(pR, pR, nsR, pMont); + cpMontExpBin_BNU(pZ, pR, nsR, pM, nsM, pMont); + + /* if z==1 => probably prime */ + if(0==cpCmp_BNU(pZ, modLen, MNT_1(pMont), modLen)) + return 1; + + /* if z==prime-1 => probably prime */ + cpSub_BNU(MNT_PRODUCT(pMont), pModulus, MNT_1(pMont), modLen); + if(0==cpCmp_BNU(pZ, modLen, MNT_PRODUCT(pMont), modLen)) + return 1; + + while(--a) { + + /* z = z^2 mod w */ + cpMontSqr_BNU(pZ, pZ, modLen, pModulus, modLen, m0, pProduct, pKBuffer); + + /* if z==1 => definitely composite */ + if(0==cpCmp_BNU(pZ, modLen, MNT_1(pMont), modLen)) + return 1; + + /* if z==w-1 => probably prime */ + cpSub_BNU(MNT_PRODUCT(pMont), pModulus, MNT_1(pMont), modLen); + if(0==cpCmp_BNU(pZ, modLen, MNT_PRODUCT(pMont), modLen)) + return 1; + } + + /* if we are here, then we deal with composize */ + return 0; +} + +int cpPrimeTest(const BNU_CHUNK_T* pPrime, cpSize primeLen, + cpSize nTrials, + IppsPrimeState* pCtx, + IppBitSupplier rndFunc, void* pRndParam) +{ + FIX_BNU(pPrime, primeLen); + + /* 0 is composite number */ + if( primeLen==1 && pPrime[0]==0) + return 0; + + /* 2 is prime number */ + else if( primeLen==1 && pPrime[0]==2) + return 1; + + /* + // test number + */ + else { + cpSize primeBitsize = BITSIZE_BNU(pPrime, primeLen); + cpSize primeLen32 = BITS2WORD32_SIZE(primeBitsize); + + /* apply easy prime test */ + if( 0==cpMimimalPrimeTest((Ipp32u*)pPrime, primeLen32) ) + return 0; + + /* continue test */ + else { + cpSize n, a; + + IppsMontState* pMont = PRIME_MONT(pCtx); + BNU_CHUNK_T* pMdata = PRIME_TEMP1(pCtx); + BNU_CHUNK_T* pRdata = PRIME_TEMP2(pCtx); + BNU_CHUNK_T* pZdata = PRIME_TEMP3(pCtx); + cpSize lenM, lenR; + + /* set up Montgomery engine (and save value being under the test) */ + ippsMontSet((Ipp32u*)pPrime, primeLen32, pMont); + + /* express w = m*2^a + 1 */ + cpDec_BNU(pMdata, pPrime, primeLen, 1); + for(n=0,a=0; n=1 */ + if(!cpTst_BNU(pRdata, lenR)) + pRdata[0] |= 1; + FIX_BNU(pRdata, lenR); + + /* Rabin-Miller test */ + if(0==RabinMiller(a, pZdata, pRdata,lenR, pMdata,lenM, pMont)) + return 0; + } + + return 1; + } + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprimeginitca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprimeginitca.c new file mode 100644 index 0000000000..2a8af24616 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprimeginitca.c @@ -0,0 +1,124 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owncp.h" +#include "pcpprimeg.h" +#include "pcptool.h" + + +/*F* +// Name: ippsPrimeGetSize +// +// Purpose: Returns size of Prime Number Generator context (bytes). +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pSize +// ippStsLengthErr 1 > maxBits +// ippStsNoErr no error +// +// Parameters: +// maxBits max length of a prime number +// pSize pointer to the size of internal context +*F*/ +IPPFUN(IppStatus, ippsPrimeGetSize, (cpSize maxBits, cpSize* pSize)) +{ + IPP_BAD_PTR1_RET(pSize); + IPP_BADARG_RET(maxBits<1, ippStsLengthErr); + + { + cpSize len = BITS_BNU_CHUNK(maxBits); + cpSize len32 = BITS2WORD32_SIZE(maxBits); + cpSize montSize; + ippsMontGetSize(ippBinaryMethod, len32, &montSize); + + *pSize = sizeof(IppsPrimeState) + +len*sizeof(BNU_CHUNK_T) + +len*sizeof(BNU_CHUNK_T) + +len*sizeof(BNU_CHUNK_T) + +len*sizeof(BNU_CHUNK_T) + +montSize + +PRIME_ALIGNMENT-1; + + return ippStsNoErr; + } +} + + +/*F* +// Name: ippsPrimeInit +// +// Purpose: Initializes Prime Number Generator context +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pCtx +// ippStsLengthErr 1 > maxBits +// ippStsNoErr no error +// +// Parameters: +// maxBits max length of a prime number +// pCtx pointer to the context to be initialized +*F*/ +IPPFUN(IppStatus, ippsPrimeInit, (cpSize maxBits, IppsPrimeState* pCtx)) +{ + IPP_BAD_PTR1_RET(pCtx); + IPP_BADARG_RET(maxBits<1, ippStsLengthErr); + + /* use aligned PRNG context */ + pCtx = (IppsPrimeState*)( IPP_ALIGNED_PTR(pCtx, PRIME_ALIGNMENT) ); + + { + Ipp8u* ptr = (Ipp8u*)pCtx; + + cpSize len = BITS_BNU_CHUNK(maxBits); + cpSize len32 = BITS2WORD32_SIZE(maxBits); + + PRIME_ID(pCtx) = idCtxPrimeNumber; + PRIME_MAXBITSIZE(pCtx) = maxBits; + + ptr += sizeof(IppsPrimeState); + PRIME_NUMBER(pCtx) = (BNU_CHUNK_T*)ptr; + + ptr += len*sizeof(BNU_CHUNK_T); + PRIME_TEMP1(pCtx) = (BNU_CHUNK_T*)ptr; + + ptr += len*sizeof(BNU_CHUNK_T); + PRIME_TEMP2(pCtx) = (BNU_CHUNK_T*)ptr; + + ptr += len*sizeof(BNU_CHUNK_T); + PRIME_TEMP3(pCtx) = (BNU_CHUNK_T*)ptr; + + ptr += len*sizeof(BNU_CHUNK_T); + PRIME_MONT(pCtx) = (IppsMontState*)( IPP_ALIGNED_PTR((ptr), MONT_ALIGNMENT) ); + ippsMontInit(ippBinaryMethod, len32, PRIME_MONT(pCtx)); + + return ippStsNoErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprng.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprng.h new file mode 100644 index 0000000000..2c0201df48 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprng.h @@ -0,0 +1,65 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_CP_PRNG_H) +#define _CP_PRNG_H + +/* +// Pseudo-random generation context +*/ + +#define MAX_XKEY_SIZE 512 +#define DEFAULT_XKEY_SIZE 512 /* must be >=160 || <=512 */ + +struct _cpPRNG { + IppCtxId idCtx; /* PRNG identifier */ + cpSize seedBits; /* secret seed-key bitsize */ + BNU_CHUNK_T Q[BITS_BNU_CHUNK(160)]; /* modulus */ + BNU_CHUNK_T T[BITS_BNU_CHUNK(160)]; /* parameter of SHA_G() funct */ + BNU_CHUNK_T xAug[BITS_BNU_CHUNK(MAX_XKEY_SIZE)]; /* optional entropy augment */ + BNU_CHUNK_T xKey[BITS_BNU_CHUNK(MAX_XKEY_SIZE)]; /* secret seed-key */ +}; + +/* alignment */ +#define PRNG_ALIGNMENT ((int)(sizeof(void*))) + +#define RAND_ID(ctx) ((ctx)->idCtx) +#define RAND_SEEDBITS(ctx) ((ctx)->seedBits) +#define RAND_Q(ctx) ((ctx)->Q) +#define RAND_T(ctx) ((ctx)->T) +#define RAND_XAUGMENT(ctx) ((ctx)->xAug) +#define RAND_XKEY(ctx) ((ctx)->xKey) + +#define RAND_VALID_ID(ctx) (RAND_ID((ctx))==idCtxPRNG) + +int cpPRNGen(Ipp32u* pBuffer, cpSize bitLen, IppsPRNGState* pCtx); + +#endif /* _CP_PRNG_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprngenca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprngenca.c new file mode 100644 index 0000000000..066c3caa54 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprngenca.c @@ -0,0 +1,178 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" + +#include "owncp.h" +#include "pcpbn.h" +#include "pcphash.h" +#include "pcpprng.h" +#include "pcptool.h" + +/* +// G() function based on SHA1 +// +// Parameters: +// T 160 bit parameter +// pHexStr input hex string +// hexStrLen size of hex string (Ipp8u segnments) +// xBNU 160 bit BNU result +// +// Note 1: +// must to be hexStrLen <= 64 (512 bits) +*/ +static +void SHA1_G(Ipp32u* xBNU, const Ipp32u* T, Ipp8u* pHexStr, int hexStrLen) +{ + /* select processing function */ + cpHashProc updateFunc = UpdateSHA1; + + /* pad HexString zeros */ + PaddBlock(0, pHexStr+hexStrLen, BITS2WORD8_SIZE(MAX_XKEY_SIZE)-hexStrLen); + + /* reset initial HASH value */ + xBNU[0] = T[0]; + xBNU[1] = T[1]; + xBNU[2] = T[2]; + xBNU[3] = T[3]; + xBNU[4] = T[4]; + + /* SHA1 */ + //UpdateSHA1(xBNU, pHexStr, BITS2WORD8_SIZE(MAX_XKEY_SIZE), SHA1_cnt); + updateFunc(xBNU, pHexStr, BITS2WORD8_SIZE(MAX_XKEY_SIZE), SHA1_cnt); + + /* swap back */ + SWAP(xBNU[0],xBNU[4]); + SWAP(xBNU[1],xBNU[3]); +} + +/* +// Returns bitsize of the bitstring has beed added +*/ +int cpPRNGen(Ipp32u* pRand, cpSize nBits, IppsPRNGState* pRnd) +{ + BNU_CHUNK_T Xj [BITS_BNU_CHUNK(MAX_XKEY_SIZE)]; + BNU_CHUNK_T XVAL[BITS_BNU_CHUNK(MAX_XKEY_SIZE)]; + + Ipp8u TXVAL[BITS2WORD8_SIZE(MAX_XKEY_SIZE)]; + + /* XKEY length in BNU_CHUNK_T */ + cpSize xKeyLen = BITS_BNU_CHUNK(RAND_SEEDBITS(pRnd)); + /* XKEY length in bytes */ + cpSize xKeySize= BITS2WORD8_SIZE(RAND_SEEDBITS(pRnd)); + /* XKEY word's mask */ + BNU_CHUNK_T xKeyMsk = MASK_BNU_CHUNK(RAND_SEEDBITS(pRnd)); + + /* number of Ipp32u chunks to be generated */ + cpSize genlen = BITS2WORD32_SIZE(nBits); + + ZEXPAND_BNU(Xj, 0, BITS_BNU_CHUNK(MAX_XKEY_SIZE)); + ZEXPAND_BNU(XVAL, 0, BITS_BNU_CHUNK(MAX_XKEY_SIZE)); + + while(genlen) { + cpSize len; + + /* Step 1: XVAL=(Xkey+Xseed) mod 2^b */ + BNU_CHUNK_T carry = cpAdd_BNU(XVAL, RAND_XKEY(pRnd), RAND_XAUGMENT(pRnd), xKeyLen); + XVAL[xKeyLen-1] &= xKeyMsk; + + /* Step 2: xj=G(t, XVAL) mod Q */ + cpToOctStr_BNU(TXVAL, xKeySize, XVAL, xKeyLen); + SHA1_G((Ipp32u*)Xj, (Ipp32u*)RAND_T(pRnd), TXVAL, xKeySize); + + { + cpSize sizeXj = BITS_BNU_CHUNK(160); + if(0 <= cpCmp_BNU(Xj, BITS_BNU_CHUNK(IPP_SHA1_DIGEST_BITSIZE), RAND_Q(pRnd),BITS_BNU_CHUNK(IPP_SHA1_DIGEST_BITSIZE)) ) + sizeXj = cpMod_BNU(Xj, BITS_BNU_CHUNK(IPP_SHA1_DIGEST_BITSIZE), RAND_Q(pRnd), BITS_BNU_CHUNK(IPP_SHA1_DIGEST_BITSIZE)); + FIX_BNU(Xj, sizeXj); + ZEXPAND_BNU(Xj, sizeXj, BITS_BNU_CHUNK(MAX_XKEY_SIZE)); + } + + /* Step 3: Xkey=(1+Xkey+Xj) mod 2^b */ + cpInc_BNU(RAND_XKEY(pRnd), RAND_XKEY(pRnd), xKeyLen, 1); + carry = cpAdd_BNU(RAND_XKEY(pRnd), RAND_XKEY(pRnd), Xj, xKeyLen); + RAND_XKEY(pRnd)[xKeyLen-1] &= xKeyMsk; + + /* fill out result */ + len = genlenidCtx +// +// ippStsLengthErr 1 > nBits +// +// ippStsNoErr no error +// +// Parameters: +// pBuffer pointer to the buffer +// nBits number of bits be requested +// pRndCtx pointer to the context +*F*/ +IPPFUN(IppStatus, ippsPRNGen,(Ipp32u* pBuffer, cpSize nBits, void* pRnd)) +{ + IppsPRNGState* pRndCtx = (IppsPRNGState*)pRnd; + + /* test PRNG context */ + IPP_BAD_PTR2_RET(pBuffer, pRnd); + + pRndCtx = (IppsPRNGState*)( IPP_ALIGNED_PTR(pRndCtx, PRNG_ALIGNMENT) ); + IPP_BADARG_RET(!RAND_VALID_ID(pRndCtx), ippStsContextMatchErr); + + /* test sizes */ + IPP_BADARG_RET(nBits< 1, ippStsLengthErr); + + { + cpSize rndSize = BITS2WORD32_SIZE(nBits); + Ipp32u rndMask = MAKEMASK32(nBits); + + cpPRNGen(pBuffer, nBits, pRndCtx); + pBuffer[rndSize-1] &= rndMask; + + return ippStsNoErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprnginitca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprnginitca.c new file mode 100644 index 0000000000..9f42b23ff8 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpprnginitca.c @@ -0,0 +1,113 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" + +#include "owncp.h" +#include "pcpbn.h" +#include "pcpprng.h" +#include "pcphash.h" +#include "pcptool.h" + + +/*F* +// Name: ippsPRNGGetSize +// +// Purpose: Returns size of PRNG context (bytes). +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pSize +// +// ippStsNoErr no error +// +// Parameters: +// pSize pointer to the size of internal context +*F*/ +IPPFUN(IppStatus, ippsPRNGGetSize, (int* pSize)) +{ + IPP_BAD_PTR1_RET(pSize); + + *pSize = sizeof(IppsPRNGState) + +PRNG_ALIGNMENT-1; + return ippStsNoErr; +} + + +/*F* +// Name: ippsPRNGInit +// +// Purpose: Initializes PRNG context +// +// Returns: Reason: +// ippStsNullPtrErr NULL == pRnd +// +// ippStsLengthErr seedBits < 1 +// seedBits < MAX_XKEY_SIZE +// seedBits%8 !=0 +// +// ippStsNoErr no error +// +// Parameters: +// seedBits seed bitsize +// pRnd pointer to the context to be initialized +*F*/ +IPPFUN(IppStatus, ippsPRNGInit, (int seedBits, IppsPRNGState* pRnd)) +{ + /* test PRNG context */ + IPP_BAD_PTR1_RET(pRnd); + pRnd = (IppsPRNGState*)( IPP_ALIGNED_PTR(pRnd, PRNG_ALIGNMENT) ); + + /* test sizes */ + IPP_BADARG_RET((1>seedBits) || (seedBits>MAX_XKEY_SIZE) ||(seedBits&7), ippStsLengthErr); + + { + int hashIvSize = cpHashIvSize(ippHashAlg_SHA1); + const Ipp8u* iv = cpHashIV[ippHashAlg_SHA1]; + + /* cleanup context */ + ZEXPAND_BNU((Ipp8u*)pRnd, 0, (cpSize)(sizeof(IppsPRNGState))); + + RAND_ID(pRnd) = idCtxPRNG; + RAND_SEEDBITS(pRnd) = seedBits; + + /* default Q parameter */ + ((Ipp32u*)RAND_Q(pRnd))[0] = 0xFFFFFFFF; + ((Ipp32u*)RAND_Q(pRnd))[1] = 0xFFFFFFFF; + ((Ipp32u*)RAND_Q(pRnd))[2] = 0xFFFFFFFF; + ((Ipp32u*)RAND_Q(pRnd))[3] = 0xFFFFFFFF; + ((Ipp32u*)RAND_Q(pRnd))[4] = 0xFFFFFFFF; + + /* default T parameter */ + CopyBlock(iv, RAND_T(pRnd), hashIvSize); + + return ippStsNoErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcprij.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcprij.h new file mode 100644 index 0000000000..f2e59a558d --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcprij.h @@ -0,0 +1,141 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_PCP_RIJ_H) +#define _PCP_RIJ_H + + +/* +// The GF(256) modular polynomial and elements +*/ +#define WPOLY 0x011B +#define BPOLY 0x1B + +/* +// Make WORD using 4 arbitrary bytes +*/ +#define BYTES_TO_WORD(b0,b1,b2,b3) ( ( ((Ipp32u)((Ipp8u)(b3))) <<24 ) \ + |( ((Ipp32u)((Ipp8u)(b2))) <<16 ) \ + |( ((Ipp32u)((Ipp8u)(b1))) << 8 ) \ + |( ((Ipp32u)((Ipp8u)(b0))) ) ) +/* +// Make WORD setting byte in specified position +*/ +#define BYTE0_TO_WORD(b) BYTES_TO_WORD((b), 0, 0, 0) +#define BYTE1_TO_WORD(b) BYTES_TO_WORD( 0, (b), 0, 0) +#define BYTE2_TO_WORD(b) BYTES_TO_WORD( 0, 0, (b), 0) +#define BYTE3_TO_WORD(b) BYTES_TO_WORD( 0, 0, 0, (b)) + +/* +// Extract byte from specified position n. +// Sure, n=0,1,2 or 3 only +*/ +#define EBYTE(w,n) ((Ipp8u)((w) >> (8 * (n)))) + + +/* +// Rijndael's spec +*/ +typedef void (*RijnCipher)(const Ipp8u* pInpBlk, Ipp8u* pOutBlk, int nr, const Ipp8u* pKeys, const void* pTbl); + +struct _cpRijndael128 { + IppCtxId idCtx; /* Rijndael spec identifier */ + int nk; /* security key length (words) */ + int nb; /* data block size (words) */ + int nr; /* number of rounds */ + RijnCipher encoder; /* encoder/decoder */ + RijnCipher decoder; /* entry point */ + Ipp32u* pEncTbl; /* expanded S-boxes for */ + Ipp32u* pDecTbl; /* encryption and decryption */ + Ipp32u enc_keys[64]; /* array of keys for encryprion */ + Ipp32u dec_keys[64]; /* array of keys for decryprion */ + Ipp32u aesNI; /* AES instruction available */ + Ipp32u safeInit; /* SafeInit performed */ +}; + +/* alignment */ +#define RIJ_ALIGNMENT (16) + +#define MBS_RIJ128 (128/8) /* message block size (bytes) */ +#define MBS_RIJ192 (192/8) +#define MBS_RIJ256 (256/8) + +#define SR (4) /* number of rows in STATE data */ + +#define NB(msgBlks) ((msgBlks)/32) /* message block size (words) */ + /* 4-word for 128-bits data block */ + /* 6-word for 192-bits data block */ + /* 8-word for 256-bits data block */ + +#define NK(keybits) ((keybits)/32) /* key length (words): */ +#define NK128 NK(ippRijndaelKey128)/* 4-word for 128-bits security key */ +#define NK192 NK(ippRijndaelKey192)/* 6-word for 192-bits security key */ +#define NK256 NK(ippRijndaelKey256)/* 8-word for 256-bits security key */ + +#define NR128_128 (10) /* number of rounds data: 128 bits key: 128 bits are used */ +#define NR128_192 (12) /* number of rounds data: 128 bits key: 192 bits are used */ +#define NR128_256 (14) /* number of rounds data: 128 bits key: 256 bits are used */ +#define NR192_128 (12) /* number of rounds data: 192 bits key: 128 bits are used */ +#define NR192_192 (12) /* number of rounds data: 192 bits key: 192 bits are used */ +#define NR192_256 (14) /* number of rounds data: 192 bits key: 256 bits are used */ +#define NR256_128 (14) /* number of rounds data: 256 bits key: 128 bits are used */ +#define NR256_192 (14) /* number of rounds data: 256 bits key: 192 bits are used */ +#define NR256_256 (14) /* number of rounds data: 256 bits key: 256 bits are used */ + +/* +// Useful macros +*/ +#define RIJ_ID(ctx) ((ctx)->idCtx) +#define RIJ_NB(ctx) ((ctx)->nb) +#define RIJ_NK(ctx) ((ctx)->nk) +#define RIJ_NR(ctx) ((ctx)->nr) +#define RIJ_ENCODER(ctx) ((ctx)->encoder) +#define RIJ_DECODER(ctx) ((ctx)->decoder) +#define RIJ_ENC_SBOX(ctx) ((ctx)->pEncTbl) +#define RIJ_DEC_SBOX(ctx) ((ctx)->pDecTbl) +#define RIJ_EKEYS(ctx) (Ipp8u*)((ctx)->enc_keys) +#define RIJ_DKEYS(ctx) (Ipp8u*)((ctx)->dec_keys) +#define RIJ_AESNI(ctx) ((ctx)->aesNI) +#define RIJ_SAFE_INIT(ctx) ((ctx)->safeInit) + +#define RIJ_ID_TEST(ctx) (RIJ_ID((ctx))==idCtxRijndael) + +/* +// Internal functions +*/ + +void Safe2Encrypt_RIJ128(const Ipp8u* pInpBlk, Ipp8u* pOutBlk, int nr, const Ipp8u* pKeys, const void* pTbl); +void Safe2Decrypt_RIJ128(const Ipp8u* pInpBlk, Ipp8u* pOutBlk, int nr, const Ipp8u* pKeys, const void* pTbl); + +void ExpandRijndaelKey(const Ipp8u* pKey, int NK, int NB, int NR, int nKeys, + Ipp8u* pEncKeys, Ipp8u* pDecKeys); + +#endif /* _PCP_RIJ_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcprij128safe2.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcprij128safe2.h new file mode 100644 index 0000000000..c407edd470 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcprij128safe2.h @@ -0,0 +1,79 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_PCP_RIJ_SAFE2_H) +#define _PCP_RIJ_SAFE2_H + +// transpose 4x4 Ipp8u matrix +#define TRANSPOSE(out, inp) \ + (out)[ 0] = (inp)[ 0]; \ + (out)[ 4] = (inp)[ 1]; \ + (out)[ 8] = (inp)[ 2]; \ + (out)[12] = (inp)[ 3]; \ + \ + (out)[ 1] = (inp)[ 4]; \ + (out)[ 5] = (inp)[ 5]; \ + (out)[ 9] = (inp)[ 6]; \ + (out)[13] = (inp)[ 7]; \ + \ + (out)[ 2] = (inp)[ 8]; \ + (out)[ 6] = (inp)[ 9]; \ + (out)[10] = (inp)[10]; \ + (out)[14] = (inp)[11]; \ + \ + (out)[ 3] = (inp)[12]; \ + (out)[ 7] = (inp)[13]; \ + (out)[11] = (inp)[14]; \ + (out)[15] = (inp)[15] + +__INLINE void XorRoundKey(Ipp32u* state, const Ipp32u* RoundKey) +{ + state[0] ^= RoundKey[0]; + state[1] ^= RoundKey[1]; + state[2] ^= RoundKey[2]; + state[3] ^= RoundKey[3]; +} + +// xtime is a macro that finds the product of {02} and the argument to xtime modulo {1b} +__INLINE Ipp32u mask4(Ipp32u x) +{ + x &= 0x80808080; + return (Ipp32u)((x<<1) - (x>>7)); +} + +__INLINE Ipp32u xtime4(Ipp32u x) +{ + Ipp32u t = (x+x) &0xFEFEFEFE; + t ^= mask4(x) & 0x1B1B1B1B; + return t; +} + +#endif /* _PCP_RIJ_SAFE2_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcprij128safedec2pxca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcprij128safedec2pxca.c new file mode 100644 index 0000000000..8dbbb21ae4 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcprij128safedec2pxca.c @@ -0,0 +1,133 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" + +#include "pcprij128safe2.h" +#include "pcprijtables.h" + + +__INLINE Ipp8u getInvSboxValue(Ipp32u x) +{ + Ipp32u t[sizeof(RijDecSbox)/CACHE_LINE_SIZE]; + const Ipp8u* SboxEntry = RijDecSbox +x%CACHE_LINE_SIZE; + Ipp32u i; + for(i=0; i0;round--) { + invShiftRows(state); + invSubBytes((Ipp8u*)state); + XorRoundKey(state,(Ipp32u*)(RoundKey+round*16)); + invMixColumns(state); + } + + // last round + invShiftRows(state); + invSubBytes((Ipp8u*)state); + XorRoundKey(state,(Ipp32u*)(RoundKey+0*16)); + + // copy from the state to output + TRANSPOSE(out, (Ipp8u*)state); +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcprij128safeenc2pxca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcprij128safeenc2pxca.c new file mode 100644 index 0000000000..c59006df7b --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcprij128safeenc2pxca.c @@ -0,0 +1,125 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" + +#include "pcprij128safe2.h" +#include "pcprijtables.h" + + +__INLINE Ipp8u getSboxValue(Ipp32u x) +{ + Ipp32u t[sizeof(RijEncSbox)/CACHE_LINE_SIZE]; + const Ipp8u* SboxEntry = RijEncSbox +x%CACHE_LINE_SIZE; + Ipp32u i; + for(i=0; i>7) & 1) * WPOLY)) +#define gf_m4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY)) +#define gf_m8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) \ + ^ (((x>>5) & 4) * WPOLY)) +#define gf_m1(x) ((x)) +#define gf_m3(x) (gf_m2(x) ^ x) +#define gf_m9(x) (gf_m8(x) ^ x) +#define gf_mB(x) (gf_m8(x) ^ gf_m2(x) ^ x) +#define gf_mD(x) (gf_m8(x) ^ gf_m4(x) ^ x) +#define gf_mE(x) (gf_m8(x) ^ gf_m4(x) ^ gf_m2(x)) + +/* +// The following particular transformations +// are used for create Encryption Tables +*/ +#define fwd_t0(x) BYTES_TO_WORD(gf_m2(x), gf_m1(x), gf_m1(x), gf_m3(x)) +#define fwd_t1(x) BYTES_TO_WORD(gf_m3(x), gf_m2(x), gf_m1(x), gf_m1(x)) +#define fwd_t2(x) BYTES_TO_WORD(gf_m1(x), gf_m3(x), gf_m2(x), gf_m1(x)) +#define fwd_t3(x) BYTES_TO_WORD(gf_m1(x), gf_m1(x), gf_m3(x), gf_m2(x)) + +/* +// The following particular transformations +// are used for create Decryption Tables +*/ +#define inv_t0(x) BYTES_TO_WORD(gf_mE(x), gf_m9(x), gf_mD(x), gf_mB(x)) +#define inv_t1(x) BYTES_TO_WORD(gf_mB(x), gf_mE(x), gf_m9(x), gf_mD(x)) +#define inv_t2(x) BYTES_TO_WORD(gf_mD(x), gf_mB(x), gf_mE(x), gf_m9(x)) +#define inv_t3(x) BYTES_TO_WORD(gf_m9(x), gf_mD(x), gf_mB(x), gf_mE(x)) + +#define exp_b3(x) BYTES_TO_WORD(0, 0, 0, (x)) +#define exp_b2(x) BYTES_TO_WORD(0, 0, (x),0) +#define exp_b1(x) BYTES_TO_WORD(0, (x),0, 0) +#define exp_b0(x) BYTES_TO_WORD((x),0, 0, 0) + +/* +// The following particular transformations +// are used for create pure Encryption/Decryption Sboxes +*/ +#define none_t(x) (x) + + +/* +// Just sequence of byte, beginning 0x00 upto 0xff +// (be parametrized by any transformation 't') +*/ +#define LINE(t) \ + t(0x00), t(0x01), t(0x02), t(0x03), t(0x04), t(0x05), t(0x06), t(0x07),\ + t(0x08), t(0x09), t(0x0a), t(0x0b), t(0x0c), t(0x0d), t(0x0e), t(0x0f),\ + t(0x10), t(0x11), t(0x12), t(0x13), t(0x14), t(0x15), t(0x16), t(0x17),\ + t(0x18), t(0x19), t(0x1a), t(0x1b), t(0x1c), t(0x1d), t(0x1e), t(0x1f),\ + t(0x20), t(0x21), t(0x22), t(0x23), t(0x24), t(0x25), t(0x26), t(0x27),\ + t(0x28), t(0x29), t(0x2a), t(0x2b), t(0x2c), t(0x2d), t(0x2e), t(0x2f),\ + t(0x30), t(0x31), t(0x32), t(0x33), t(0x34), t(0x35), t(0x36), t(0x37),\ + t(0x38), t(0x39), t(0x3a), t(0x3b), t(0x3c), t(0x3d), t(0x3e), t(0x3f),\ + t(0x40), t(0x41), t(0x42), t(0x43), t(0x44), t(0x45), t(0x46), t(0x47),\ + t(0x48), t(0x49), t(0x4a), t(0x4b), t(0x4c), t(0x4d), t(0x4e), t(0x4f),\ + t(0x50), t(0x51), t(0x52), t(0x53), t(0x54), t(0x55), t(0x56), t(0x57),\ + t(0x58), t(0x59), t(0x5a), t(0x5b), t(0x5c), t(0x5d), t(0x5e), t(0x5f),\ + t(0x60), t(0x61), t(0x62), t(0x63), t(0x64), t(0x65), t(0x66), t(0x67),\ + t(0x68), t(0x69), t(0x6a), t(0x6b), t(0x6c), t(0x6d), t(0x6e), t(0x6f),\ + t(0x70), t(0x71), t(0x72), t(0x73), t(0x74), t(0x75), t(0x76), t(0x77),\ + t(0x78), t(0x79), t(0x7a), t(0x7b), t(0x7c), t(0x7d), t(0x7e), t(0x7f),\ + t(0x80), t(0x81), t(0x82), t(0x83), t(0x84), t(0x85), t(0x86), t(0x87),\ + t(0x88), t(0x89), t(0x8a), t(0x8b), t(0x8c), t(0x8d), t(0x8e), t(0x8f),\ + t(0x90), t(0x91), t(0x92), t(0x93), t(0x94), t(0x95), t(0x96), t(0x97),\ + t(0x98), t(0x99), t(0x9a), t(0x9b), t(0x9c), t(0x9d), t(0x9e), t(0x9f),\ + t(0xa0), t(0xa1), t(0xa2), t(0xa3), t(0xa4), t(0xa5), t(0xa6), t(0xa7),\ + t(0xa8), t(0xa9), t(0xaa), t(0xab), t(0xac), t(0xad), t(0xae), t(0xaf),\ + t(0xb0), t(0xb1), t(0xb2), t(0xb3), t(0xb4), t(0xb5), t(0xb6), t(0xb7),\ + t(0xb8), t(0xb9), t(0xba), t(0xbb), t(0xbc), t(0xbd), t(0xbe), t(0xbf),\ + t(0xc0), t(0xc1), t(0xc2), t(0xc3), t(0xc4), t(0xc5), t(0xc6), t(0xc7),\ + t(0xc8), t(0xc9), t(0xca), t(0xcb), t(0xcc), t(0xcd), t(0xce), t(0xcf),\ + t(0xd0), t(0xd1), t(0xd2), t(0xd3), t(0xd4), t(0xd5), t(0xd6), t(0xd7),\ + t(0xd8), t(0xd9), t(0xda), t(0xdb), t(0xdc), t(0xdd), t(0xde), t(0xdf),\ + t(0xe0), t(0xe1), t(0xe2), t(0xe3), t(0xe4), t(0xe5), t(0xe6), t(0xe7),\ + t(0xe8), t(0xe9), t(0xea), t(0xeb), t(0xec), t(0xed), t(0xee), t(0xef),\ + t(0xf0), t(0xf1), t(0xf2), t(0xf3), t(0xf4), t(0xf5), t(0xf6), t(0xf7),\ + t(0xf8), t(0xf9), t(0xfa), t(0xfb), t(0xfc), t(0xfd), t(0xfe), t(0xff) + +/* +// Encrypt/Decrypt S-box data +// (be parametrized by any transformation 't') +*/ +#define ENC_SBOX(t) \ + t(0x63), t(0x7c), t(0x77), t(0x7b), t(0xf2), t(0x6b), t(0x6f), t(0xc5),\ + t(0x30), t(0x01), t(0x67), t(0x2b), t(0xfe), t(0xd7), t(0xab), t(0x76),\ + t(0xca), t(0x82), t(0xc9), t(0x7d), t(0xfa), t(0x59), t(0x47), t(0xf0),\ + t(0xad), t(0xd4), t(0xa2), t(0xaf), t(0x9c), t(0xa4), t(0x72), t(0xc0),\ + t(0xb7), t(0xfd), t(0x93), t(0x26), t(0x36), t(0x3f), t(0xf7), t(0xcc),\ + t(0x34), t(0xa5), t(0xe5), t(0xf1), t(0x71), t(0xd8), t(0x31), t(0x15),\ + t(0x04), t(0xc7), t(0x23), t(0xc3), t(0x18), t(0x96), t(0x05), t(0x9a),\ + t(0x07), t(0x12), t(0x80), t(0xe2), t(0xeb), t(0x27), t(0xb2), t(0x75),\ + t(0x09), t(0x83), t(0x2c), t(0x1a), t(0x1b), t(0x6e), t(0x5a), t(0xa0),\ + t(0x52), t(0x3b), t(0xd6), t(0xb3), t(0x29), t(0xe3), t(0x2f), t(0x84),\ + t(0x53), t(0xd1), t(0x00), t(0xed), t(0x20), t(0xfc), t(0xb1), t(0x5b),\ + t(0x6a), t(0xcb), t(0xbe), t(0x39), t(0x4a), t(0x4c), t(0x58), t(0xcf),\ + t(0xd0), t(0xef), t(0xaa), t(0xfb), t(0x43), t(0x4d), t(0x33), t(0x85),\ + t(0x45), t(0xf9), t(0x02), t(0x7f), t(0x50), t(0x3c), t(0x9f), t(0xa8),\ + t(0x51), t(0xa3), t(0x40), t(0x8f), t(0x92), t(0x9d), t(0x38), t(0xf5),\ + t(0xbc), t(0xb6), t(0xda), t(0x21), t(0x10), t(0xff), t(0xf3), t(0xd2),\ + t(0xcd), t(0x0c), t(0x13), t(0xec), t(0x5f), t(0x97), t(0x44), t(0x17),\ + t(0xc4), t(0xa7), t(0x7e), t(0x3d), t(0x64), t(0x5d), t(0x19), t(0x73),\ + t(0x60), t(0x81), t(0x4f), t(0xdc), t(0x22), t(0x2a), t(0x90), t(0x88),\ + t(0x46), t(0xee), t(0xb8), t(0x14), t(0xde), t(0x5e), t(0x0b), t(0xdb),\ + t(0xe0), t(0x32), t(0x3a), t(0x0a), t(0x49), t(0x06), t(0x24), t(0x5c),\ + t(0xc2), t(0xd3), t(0xac), t(0x62), t(0x91), t(0x95), t(0xe4), t(0x79),\ + t(0xe7), t(0xc8), t(0x37), t(0x6d), t(0x8d), t(0xd5), t(0x4e), t(0xa9),\ + t(0x6c), t(0x56), t(0xf4), t(0xea), t(0x65), t(0x7a), t(0xae), t(0x08),\ + t(0xba), t(0x78), t(0x25), t(0x2e), t(0x1c), t(0xa6), t(0xb4), t(0xc6),\ + t(0xe8), t(0xdd), t(0x74), t(0x1f), t(0x4b), t(0xbd), t(0x8b), t(0x8a),\ + t(0x70), t(0x3e), t(0xb5), t(0x66), t(0x48), t(0x03), t(0xf6), t(0x0e),\ + t(0x61), t(0x35), t(0x57), t(0xb9), t(0x86), t(0xc1), t(0x1d), t(0x9e),\ + t(0xe1), t(0xf8), t(0x98), t(0x11), t(0x69), t(0xd9), t(0x8e), t(0x94),\ + t(0x9b), t(0x1e), t(0x87), t(0xe9), t(0xce), t(0x55), t(0x28), t(0xdf),\ + t(0x8c), t(0xa1), t(0x89), t(0x0d), t(0xbf), t(0xe6), t(0x42), t(0x68),\ + t(0x41), t(0x99), t(0x2d), t(0x0f), t(0xb0), t(0x54), t(0xbb), t(0x16) + +#define DEC_SBOX(t) \ + t(0x52), t(0x09), t(0x6a), t(0xd5), t(0x30), t(0x36), t(0xa5), t(0x38),\ + t(0xbf), t(0x40), t(0xa3), t(0x9e), t(0x81), t(0xf3), t(0xd7), t(0xfb),\ + t(0x7c), t(0xe3), t(0x39), t(0x82), t(0x9b), t(0x2f), t(0xff), t(0x87),\ + t(0x34), t(0x8e), t(0x43), t(0x44), t(0xc4), t(0xde), t(0xe9), t(0xcb),\ + t(0x54), t(0x7b), t(0x94), t(0x32), t(0xa6), t(0xc2), t(0x23), t(0x3d),\ + t(0xee), t(0x4c), t(0x95), t(0x0b), t(0x42), t(0xfa), t(0xc3), t(0x4e),\ + t(0x08), t(0x2e), t(0xa1), t(0x66), t(0x28), t(0xd9), t(0x24), t(0xb2),\ + t(0x76), t(0x5b), t(0xa2), t(0x49), t(0x6d), t(0x8b), t(0xd1), t(0x25),\ + t(0x72), t(0xf8), t(0xf6), t(0x64), t(0x86), t(0x68), t(0x98), t(0x16),\ + t(0xd4), t(0xa4), t(0x5c), t(0xcc), t(0x5d), t(0x65), t(0xb6), t(0x92),\ + t(0x6c), t(0x70), t(0x48), t(0x50), t(0xfd), t(0xed), t(0xb9), t(0xda),\ + t(0x5e), t(0x15), t(0x46), t(0x57), t(0xa7), t(0x8d), t(0x9d), t(0x84),\ + t(0x90), t(0xd8), t(0xab), t(0x00), t(0x8c), t(0xbc), t(0xd3), t(0x0a),\ + t(0xf7), t(0xe4), t(0x58), t(0x05), t(0xb8), t(0xb3), t(0x45), t(0x06),\ + t(0xd0), t(0x2c), t(0x1e), t(0x8f), t(0xca), t(0x3f), t(0x0f), t(0x02),\ + t(0xc1), t(0xaf), t(0xbd), t(0x03), t(0x01), t(0x13), t(0x8a), t(0x6b),\ + t(0x3a), t(0x91), t(0x11), t(0x41), t(0x4f), t(0x67), t(0xdc), t(0xea),\ + t(0x97), t(0xf2), t(0xcf), t(0xce), t(0xf0), t(0xb4), t(0xe6), t(0x73),\ + t(0x96), t(0xac), t(0x74), t(0x22), t(0xe7), t(0xad), t(0x35), t(0x85),\ + t(0xe2), t(0xf9), t(0x37), t(0xe8), t(0x1c), t(0x75), t(0xdf), t(0x6e),\ + t(0x47), t(0xf1), t(0x1a), t(0x71), t(0x1d), t(0x29), t(0xc5), t(0x89),\ + t(0x6f), t(0xb7), t(0x62), t(0x0e), t(0xaa), t(0x18), t(0xbe), t(0x1b),\ + t(0xfc), t(0x56), t(0x3e), t(0x4b), t(0xc6), t(0xd2), t(0x79), t(0x20),\ + t(0x9a), t(0xdb), t(0xc0), t(0xfe), t(0x78), t(0xcd), t(0x5a), t(0xf4),\ + t(0x1f), t(0xdd), t(0xa8), t(0x33), t(0x88), t(0x07), t(0xc7), t(0x31),\ + t(0xb1), t(0x12), t(0x10), t(0x59), t(0x27), t(0x80), t(0xec), t(0x5f),\ + t(0x60), t(0x51), t(0x7f), t(0xa9), t(0x19), t(0xb5), t(0x4a), t(0x0d),\ + t(0x2d), t(0xe5), t(0x7a), t(0x9f), t(0x93), t(0xc9), t(0x9c), t(0xef),\ + t(0xa0), t(0xe0), t(0x3b), t(0x4d), t(0xae), t(0x2a), t(0xf5), t(0xb0),\ + t(0xc8), t(0xeb), t(0xbb), t(0x3c), t(0x83), t(0x53), t(0x99), t(0x61),\ + t(0x17), t(0x2b), t(0x04), t(0x7e), t(0xba), t(0x77), t(0xd6), t(0x26),\ + t(0xe1), t(0x69), t(0x14), t(0x63), t(0x55), t(0x21), t(0x0c), t(0x7d), + +/* +// Internal cipher tables +*/ +extern const __ALIGN64 Ipp8u RijEncSbox[256]; /* pure encryption S-box */ +extern const __ALIGN64 Ipp8u RijDecSbox[256]; /* pure decryption S-box */ + +#endif /* _PCP_RIJTBLES_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpscramble.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpscramble.h new file mode 100644 index 0000000000..9518ef6ada --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpscramble.h @@ -0,0 +1,170 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_PC_SCRAMBLE_H) +#define _PC_SCRAMBLE_H + +/* +// cpsScramblePut/cpsScrambleGet +// stores to/retrieves from pScrambleEntry position +// pre-computed data if fixed window method is used +*/ +__INLINE void cpScramblePut(Ipp8u* pArray, cpSize colummSize, + const Ipp32u* pData, cpSize dataSize) +{ + int i; + switch(colummSize) { + case 1: + dataSize *= sizeof(Ipp32u); + for(i=0; i=2; dataSize-=2, pArray+=CACHE_LINE_SIZE, pData+=2) { + ((Ipp32u*)pArray)[0] = pData[0]; + ((Ipp32u*)pArray)[1] = pData[1]; + } + if(dataSize) + ((Ipp32u*)pArray)[0] = pData[0]; + break; + case 16: + for(; dataSize>=4; dataSize-=4, pArray+=CACHE_LINE_SIZE, pData+=4) { + ((Ipp32u*)pArray)[0] = pData[0]; + ((Ipp32u*)pArray)[1] = pData[1]; + ((Ipp32u*)pArray)[2] = pData[2]; + ((Ipp32u*)pArray)[3] = pData[3]; + } + for(; dataSize>0; dataSize--, pArray+=sizeof(Ipp32u), pData++) + ((Ipp32u*)pArray)[0] = pData[0]; + break; + case 32: + for(; dataSize>=8; dataSize-=8, pArray+=CACHE_LINE_SIZE, pData+=8) { + ((Ipp32u*)pArray)[0] = pData[0]; + ((Ipp32u*)pArray)[1] = pData[1]; + ((Ipp32u*)pArray)[2] = pData[2]; + ((Ipp32u*)pArray)[3] = pData[3]; + ((Ipp32u*)pArray)[4] = pData[4]; + ((Ipp32u*)pArray)[5] = pData[5]; + ((Ipp32u*)pArray)[6] = pData[6]; + ((Ipp32u*)pArray)[7] = pData[7]; + } + for(; dataSize>0; dataSize--, pArray+=sizeof(Ipp32u), pData++) + ((Ipp32u*)pArray)[0] = pData[0]; + break; + default: + break; + } +} + + +/* +// Retrieve data from pArray +*/ +#define u8_to_u32(b0,b1,b2,b3, x) \ + ((x) = (b0), \ + (x)|=((b1)<<8), \ + (x)|=((b2)<<16), \ + (x)|=((b3)<<24)) +#define u16_to_u32(w0,w1, x) \ + ((x) = (w0), \ + (x)|=((w1)<<16)) +#define u32_to_u64(dw0,dw1, x) \ + ((x) = (Ipp64u)(dw0), \ + (x)|= (((Ipp64u)(dw1))<<32)) + +__INLINE void cpScrambleGet(Ipp32u* pData, cpSize dataSize, + const Ipp8u* pArray, cpSize colummSize) +{ + int i; + switch(colummSize) { + case 1: + for(i=0; i=2; dataSize-=2, pArray+=CACHE_LINE_SIZE, pData+=2) { + pData[0] = ((Ipp32u*)pArray)[0]; + pData[1] = ((Ipp32u*)pArray)[1]; + } + if(dataSize) + pData[0] = ((Ipp32u*)pArray)[0]; + break; + case 16: + for(; dataSize>=4; dataSize-=4, pArray+=CACHE_LINE_SIZE, pData+=4) { + pData[0] = ((Ipp32u*)pArray)[0]; + pData[1] = ((Ipp32u*)pArray)[1]; + pData[2] = ((Ipp32u*)pArray)[2]; + pData[3] = ((Ipp32u*)pArray)[3]; + + } + for(; dataSize>0; dataSize--, pArray+=sizeof(Ipp32u), pData++) + pData[0] = ((Ipp32u*)pArray)[0]; + break; + case 32: + for(; dataSize>=8; dataSize-=8, pArray+=CACHE_LINE_SIZE, pData+=8) { + pData[0] = ((Ipp32u*)pArray)[0]; + pData[1] = ((Ipp32u*)pArray)[1]; + pData[2] = ((Ipp32u*)pArray)[2]; + pData[3] = ((Ipp32u*)pArray)[3]; + pData[4] = ((Ipp32u*)pArray)[4]; + pData[5] = ((Ipp32u*)pArray)[5]; + pData[6] = ((Ipp32u*)pArray)[6]; + pData[7] = ((Ipp32u*)pArray)[7]; + } + for(; dataSize>0; dataSize--, pArray+=sizeof(Ipp32u), pData++) + pData[0] = ((Ipp32u*)pArray)[0]; + break; + default: + break; + } +} + +#endif /* _PC_SCRAMBLE_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpshsmgfca.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpshsmgfca.c new file mode 100644 index 0000000000..544d30eb89 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpshsmgfca.c @@ -0,0 +1,109 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" +#include "owncp.h" +#include "pcphash.h" +#include "pcptool.h" + + +/*F* +// Name: ippsMGF_SHA1 +// ippsMGF_SHA224 +// ippsMGF_SHA256 +// ippsMGF_SHA384 +// ippsMGF_SHA512 +// ippsMGF_MD5 +// +// Purpose: Mask Generation Functios. +// +// Returns: Reason: +// ippStsNullPtrErr pMask == NULL +// ippStsLengthErr seedLen <0 +// maskLen <0 +// ippStsNotSupportedModeErr if algID is not match to supported hash alg +// ippStsNoErr no errors +// +// Parameters: +// pSeed pointer to the input stream +// seedLen input stream length (bytes) +// pMaske pointer to the ouput mask +// maskLen desired length of mask (bytes) +// +*F*/ +IPPFUN(IppStatus, ippsMGF,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, IppHashAlgId hashAlg)) +{ + /* get algorithm id */ + hashAlg = cpValidHashAlg(hashAlg); + /* test hash alg */ + IPP_BADARG_RET(ippHashAlg_Unknown==hashAlg, ippStsNotSupportedModeErr); + + IPP_BAD_PTR1_RET(pMask); + IPP_BADARG_RET((seedLen<0)||(maskLen<0), ippStsLengthErr); + + { + /* hash specific */ + int hashSize = cpHashSize(hashAlg); + + int i, outLen; + + IppsHashState hashCtx; + ippsHashInit(&hashCtx, hashAlg); + + if(!pSeed) + seedLen = 0; + + for(i=0,outLen=0; outLen>24) & 0xFF); + cnt[1] = (Ipp8u)((i>>16) & 0xFF); + cnt[2] = (Ipp8u)((i>>8) & 0xFF); + cnt[3] = (Ipp8u)(i & 0xFF); + + cpReInitHash(&hashCtx, hashAlg); + ippsHashUpdate(pSeed, seedLen, &hashCtx); + ippsHashUpdate(cnt, 4, &hashCtx); + + if((outLen + hashSize) <= maskLen) { + ippsHashFinal(pMask+outLen, &hashCtx); + outLen += hashSize; + } + else { + Ipp8u md[BITS2WORD8_SIZE(IPP_SHA512_DIGEST_BITSIZE)]; + ippsHashFinal(md, &hashCtx); + CopyBlock(md, pMask+outLen, maskLen-outLen); + outLen = maskLen; + } + } + + return ippStsNoErr; + } +} diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcptool.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcptool.h new file mode 100644 index 0000000000..9d6b63e913 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcptool.h @@ -0,0 +1,177 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#if !defined(_PC_TOOL_H) +#define _CP_TOOL_H + +/* copy data block */ +__INLINE void CopyBlock(const void* pSrc, void* pDst, cpSize numBytes) +{ + const Ipp8u* s = (Ipp8u*)pSrc; + Ipp8u* d = (Ipp8u*)pDst; + cpSize k; + for(k=0; k> (blkSize-numSize)%8 ); + + /* save crytical byte */ + Ipp8u save = (Ipp8u)( pCounter[maskPosition] & ~mask ); + + int len = BITS2WORD8_SIZE(blkSize); + Ipp32u carry = 1; + for(; (len>maskPosition) && carry; len--) { + Ipp32u x = pCounter[len-1] + carry; + pCounter[len-1] = (Ipp8u)x; + carry = (x>>8) & 0xFF; + } + + /* update crytical byte */ + pCounter[maskPosition] &= mask; + pCounter[maskPosition] |= save; +} + +#endif /* _CP_TOOL_H */ diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpver.c b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpver.c new file mode 100644 index 0000000000..18c70aa883 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpver.c @@ -0,0 +1,41 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "owndefs.h" + +#ifndef __OWNCP_H__ + #include "owncp.h" +#endif + +#include "pcpname.h" +#include "pcpver.h" + +#include "ippver.gen" diff --git a/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpver.h b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpver.h new file mode 100644 index 0000000000..30e6dc3a02 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/crypto_px/sources/ippcp/src/pcpver.h @@ -0,0 +1,36 @@ +/* +* Copyright (C) 2016 Intel Corporation. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ + +#include "ippver.h" +#define BUILD() 1043 +#define VERSION() BASE_VERSION(),BUILD() + +/* ////////////////////////// End of file "pcpver.h" ///////////////////////// */ diff --git a/sgx-jvm/linux-sgx/external/epid/LICENSE.txt b/sgx-jvm/linux-sgx/external/epid/LICENSE.txt new file mode 100644 index 0000000000..38f89e4ace --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/LICENSE.txt @@ -0,0 +1,249 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +======================================================================= + +EPID SDK Subcomponents: + +The EPID SDK contains subcomponents with separate copyright notices +and license terms. Your use of the source code for these subcomponents +is subject to the terms and conditions of the following licenses. + + +----------------------------------------------------------------------- +The BSD 3-Clause License +----------------------------------------------------------------------- + +The EPID SDK bundles portions of the following under the BSD 3-Clause +License: + + - Google Test (https://github.com/google/googletest) + Copyright 2008, Google Inc. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/sgx-jvm/linux-sgx/external/epid/Makefile b/sgx-jvm/linux-sgx/external/epid/Makefile new file mode 100644 index 0000000000..a542d977a3 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/Makefile @@ -0,0 +1,52 @@ +include ../../buildenv.mk + +EPIDLIB := libepid.a +TOP_DIR := $(LINUX_EXTERNAL_DIR)/epid + +CFLAGS += -fPIC +DEFINES := -DIPPEPID_USE_MERGEDLIB -DASSUME_GETOCTSTRING_POINT_VALID + +ifdef DEBUG + CFLAGS += -O0 + DEFINES += -DDEBUG +else + DEFINES += -DNDEBUG +endif + +ifeq ($(ARCH), x86_64) + DEFINES += -DUSE_Y8_HEADER +else + DEFINES += -DUSE_P8_HEADER +endif + +vpath %.c epid/common epid/common/math epid/member epid/verifier ext/ipp/sources/ippcpepid/src + +INCLUDE += -I$(TOP_DIR)/ext/ipp/include \ + -I$(TOP_DIR)/ext/ipp/sources/include \ + -I$(TOP_DIR)/ext/ipp/sources/ippcp/src \ + -I$(TOP_DIR)/ext/ipp/sources/ippcpepid/src \ + -I$(TOP_DIR) + +SRC := commitment.c epid2params.c errors.c grouppubkey.c memory.c printutils.c sigrlvalid.c stack.c \ + bignum.c ecgroup.c finitefield.c pairing.c \ + context.c nr_prove.c privkey.c signbasic.c get_sigsize.c presig.c request_join.c sign.c \ + check_privrl_entry.c nrverify.c verifybasic.c context.c sigs_linked.c verify.c \ + pcpgfp.c pcpgfpec.c pcpgfpecpoint.c pcpgfpecpointstuff.c pcpgfpstuff.c pcpgfpx.c pcpgfpxstuff.c + +OBJ := $(SRC:.c=.o) + +.PHONY: all +all: $(EPIDLIB) + +$(EPIDLIB): $(OBJ) + $(AR) rcs $@ $^ + +%.o: %.c + $(CC) $(INCLUDE) $(filter-out -Werror, $(CFLAGS)) $(DEFINES) -c $< -o $@ + +.PHONY: clean +clean: + @$(RM) $(OBJ) $(EPIDLIB) + +.PHONY: rebuild +rebuild: clean all diff --git a/sgx-jvm/linux-sgx/external/epid/NOTICE.txt b/sgx-jvm/linux-sgx/external/epid/NOTICE.txt new file mode 100644 index 0000000000..fc0c4208bb --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/NOTICE.txt @@ -0,0 +1,22 @@ +Intel(R) EPID SDK +Copyright 2016 Intel Corporation + +========== + +The Intel(R) EPID SDK contains subcomponents with separate copyright notices +and license terms. + +Your use of the source code for the these subcomponents is subject to +the terms and conditions of their respective licenses. + +See the LICENSE.txt file for a list of subcomponents and dependencies and +their respective licenses. + +---------- + +The source code used for math primitives in the Intel(R) EPID SDK is a +subset of the Intel(R) IPP Cryptography library (v9.0.3) written in +C. For higher performance, you can use the commercial version of the +IPP Cryptography libraries, which are available at +https://software.intel.com/articles/download-ipp-cryptography-libraries. + diff --git a/sgx-jvm/linux-sgx/external/epid/README.md b/sgx-jvm/linux-sgx/external/epid/README.md new file mode 100644 index 0000000000..332f72233e --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/README.md @@ -0,0 +1,57 @@ +# Intel(R) EPID SDK + +The Intel(R) Enhanced Privacy ID Software Development Kit + +Intel(R) EPID SDK enables adding Intel(R) EPID support to applications +and platforms. + +Intel(R) EPID is a cryptographic protocol which enables the remote +authentication of a trusted platform whilst preserving the user's +privacy. + +* For a given public key there are many (e.g., millions) of private + keys. The key holders form a group. + +* Any key holder may sign against the one public key. + +* No one can tell which private key signed the data. This is the + privacy property. + +You can use Intel(R) EPID as a foundational building block for a +multitude of security solutions. + + +## Prerequisites + +* [Python](http://www.python.org) + +* [SCons](http://www.scons.org/) + +* [Parts](https://bitbucket.org/sconsparts/parts) + +* A C/C++ compiler supported by Parts + + +## Release Notes + +See [RELEASE_NOTES.md](RELEASE_NOTES.md). + + +## Documentation + +See [doc/index.html](doc/index.html) to browse the html +documentation. + + +## License + +See [LICENSE.txt](LICENSE.txt). + + +## Math Primitives + +The source code used for math primitives in the Intel(R) EPID SDK is a +subset of the Intel(R) IPP Cryptography library (v9.0.3) written in +C. For higher performance, you can use the commercial version of the +IPP Cryptography libraries, which are available at +https://software.intel.com/articles/download-ipp-cryptography-libraries. diff --git a/sgx-jvm/linux-sgx/external/epid/RELEASE_NOTES.md b/sgx-jvm/linux-sgx/external/epid/RELEASE_NOTES.md new file mode 100644 index 0000000000..3eb9ab3fc5 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/RELEASE_NOTES.md @@ -0,0 +1,41 @@ +# Intel(R) EPID SDK Release Notes {#ChangeLog} + +# 2.0.0 + +## New in This Release + +* Signed binary issuer material support. + + - Binary issuer material validation APIs. + + - Updated sample issuer material. + + - Updated samples that parse signed binary issuer material. + +* Compressed member private key support. + +* Validated on additional IoT platforms. + + - Windows 10 IoT Core + + - WindRiver IDP + + +## Changes + +* The default hash algorithm has changed. It is now SHA-512. + +* Functions that returned `EpidNullPtrErr` now return `EpidBadArgErr` + instead. + + +## Fixes + +* Updated build flags to work around GCC 4.8.5 defect. + + +## Known Issues + +* SHA-512/256 hash algorithm is not supported. + +* Compressed key sample material is not included in the package. diff --git a/sgx-jvm/linux-sgx/external/epid/ReadMe.txt b/sgx-jvm/linux-sgx/external/epid/ReadMe.txt new file mode 100644 index 0000000000..9520110999 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/ReadMe.txt @@ -0,0 +1,29 @@ +======================================================================== + STATIC LIBRARY : epid Project Overview +======================================================================== + +AppWizard has created this epid library project for you. + +No source files were created as part of your project. + + +epid.vcxproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +epid.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" comments to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/sgx-jvm/linux-sgx/external/epid/SConstruct b/sgx-jvm/linux-sgx/external/epid/SConstruct new file mode 100644 index 0000000000..296adced51 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/SConstruct @@ -0,0 +1,210 @@ +############################################################################ +# Copyright 2016 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################ + +"""use scons -k to invoke all builds regardless of unit test failures +""" +import string +import sys +import SCons.Script +import os.path +from parts import * + +print "**************** TOOLS ****************" +print '* Python Version:', string.split(sys.version, " ", 1)[0] +print '* SCons Version:', SCons.__version__ +print '* Parts Version:', PartsExtensionVersion() +print "***************************************" + +def PrintCompilerVersion(env): + """ + Function to print version of compilers used for build + Args: + env: Environment to get compilers version + """ + res = '' + if 'INTELC_VERSION' in env: + res += 'ICC ' + env['INTELC_VERSION'] + ';' + if 'MSVC_VERSION' in env: + res += 'MS ' + env['MSVC_VERSION'] + ';' + if 'GXX_VERSION' in env: + res += 'GXX ' + env['GXX_VERSION'] + ';' + if 'GCC_VERSION' in env: + res += 'GCC ' + env['GCC_VERSION'] + ';' + print 'Compiler Version: ', res + +def include_parts(part_list, **kwargs): + for parts_file in part_list: + if os.path.isfile(DefaultEnvironment().subst(parts_file)): + Part(parts_file=parts_file, **kwargs) + +######## Part groups #################################################### +ipp_parts = ['ext/ipp/ippcp.parts', + 'ext/ipp/ippcpepid.parts', + 'ext/ipp/ippcommon.parts'] +utest_parts = ['ext/gtest/gtest.parts', + 'epid/common-testhelper/common-testhelper.parts'] +common_parts = ['epid/common/common.parts'] +member_parts = ['epid/member/member.parts'] +verifier_parts = ['epid/verifier/verifier.parts'] +util_parts = ['example/util/util.parts'] +example_parts = ['example/verifysig/verifysig.parts', + 'example/signmsg/signmsg.parts', + 'example/data/data.parts'] +example_test_parts = ['test/testbot/testbot.parts', + 'test/testbot/signmsg/signmsg_testbot.parts', + 'test/testbot/verifysig/verifysig_testbot.parts', + 'test/testbot/integration/integration_testbot.parts'] +package_parts = ['ext/gtest/gtest.parts', + 'ext/ipp/ippcommon.parts', + 'ext/ipp/ippcp.parts', + 'ext/ipp/ippcpepid.parts', + 'package.parts'] +internal_tools_parts = ['tools/ikgfwrapper/ikgfwrapper.parts', + 'tools/revokegrp/revokegrp.parts', + 'tools/revokekey/revokekey.parts', + 'tools/revokesig/revokesig.parts', + 'tools/extractkeys/extractkeys.parts', + 'tools/extractgrps/extractgrps.parts'] +######## End Part groups ############################################### +######## Commandline option setup ####################################### +product_variants = [ + 'production', + 'internal-test', + 'package-epid-sdk', + 'internal-tools' +] + +default_variant = 'production' + +def is_production(): + return GetOption("product-variant") == 'production' + +def is_internal_test(): + return GetOption("product-variant") == 'internal-test' + +def is_internal_tools(): + return GetOption("product-variant") == 'internal-tools' + +def is_package(): + return GetOption("product-variant") == 'package-epid-sdk' + +def variant_dirname(): + s = GetOption("product-variant") + if s == 'production': + return 'epid-sdk' + elif s == 'package-epid-sdk': + return 'epid-sdk' + else: + return s + +AddOption("--product-variant", "--prod-var", nargs=1, + help=("Select product variant to build. Possible " + "options are: {0}. The default is {1} if no option " + "is specified").format(", ".join(product_variants), + default_variant), + action='store', dest='product-variant', type='choice', + choices=product_variants, default=default_variant) + +SetOptionDefault("PRODUCT_VARIANT", variant_dirname()) + +######## End Commandline option setup ################################### + + +# fix for parts 0.10.8 until we get better logic to extract ${CC} +SetOptionDefault('PARTS_USE_SHORT_TOOL_NAMES', 1) + +def set_default_production_options(): + SetOptionDefault('TARGET_PLATFORM', 'x86_64') + SetOptionDefault('CONFIG', 'release') + + SetOptionDefault('TARGET_VARIANT', '${TARGET_OS}-${TARGET_ARCH}') + + SetOptionDefault('INSTALL_ROOT', + '#_install/${PRODUCT_VARIANT}') + + SetOptionDefault('INSTALL_TOOLS_BIN', + '$INSTALL_ROOT/tools') + + SetOptionDefault('INSTALL_SAMPLE_BIN', + '$INSTALL_ROOT/example') + + SetOptionDefault('INSTALL_EPID_INCLUDE', + '$INSTALL_ROOT/include/epid') + + SetOptionDefault('INSTALL_IPP_INCLUDE', + '$INSTALL_ROOT/include/ext/ipp/include') + + SetOptionDefault('INSTALL_TEST_BIN', + '$INSTALL_ROOT/test') + + SetOptionDefault('INSTALL_LIB', + '$INSTALL_ROOT/lib/${TARGET_VARIANT}') + + SetOptionDefault('INSTALL_SAMPLE_DATA', + '$INSTALL_ROOT/example') + + SetOptionDefault('PACKAGE_DIR', + '#_package') + + SetOptionDefault('PACKAGE_ROOT', + '#_package/${PRODUCT_VARIANT}') + + SetOptionDefault('ROOT', + '#') + + SetOptionDefault('PACKAGE_NAME', + '{PRODUCT_VARIANT}') + +if is_production(): + set_default_production_options() + include_parts(ipp_parts, mode=['install_lib'], + INSTALL_INCLUDE='${INSTALL_IPP_INCLUDE}') + include_parts(utest_parts + common_parts + + member_parts + verifier_parts, + mode=['install_lib'], + INSTALL_INCLUDE='${INSTALL_EPID_INCLUDE}') + include_parts(util_parts + example_parts, + INSTALL_INCLUDE='${INSTALL_EPID_INCLUDE}', + INSTALL_BIN='${INSTALL_SAMPLE_BIN}', + INSTALL_DATA='${INSTALL_SAMPLE_DATA}') + PrintCompilerVersion(DefaultEnvironment()) + Default('all') + Default('run_utest::') + +if is_internal_test(): + set_default_production_options() + include_parts(ipp_parts) + include_parts(utest_parts + common_parts + + member_parts + verifier_parts) + include_parts(util_parts + example_parts, + INSTALL_BIN='${INSTALL_SAMPLE_BIN}', + INSTALL_DATA='${INSTALL_SAMPLE_DATA}') + include_parts(example_test_parts) + Default('all') + +if is_internal_tools(): + set_default_production_options() + include_parts(ipp_parts + utest_parts + common_parts + util_parts) + include_parts(internal_tools_parts, INSTALL_BIN='${INSTALL_TOOLS_BIN}') + Default('ikgfwrapper', 'revokegrp', 'revokekey', 'revokesig', + 'extractkeys', 'extractgrps') + +if is_package(): + set_default_production_options() + include_parts(package_parts, + mode=['install_package'], + INSTALL_TOP_LEVEL='${PACKAGE_ROOT}') + Default('package') diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/BuildingSdk.html b/sgx-jvm/linux-sgx/external/epid/doc/html/BuildingSdk.html new file mode 100644 index 0000000000..715303c04d --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/BuildingSdk.html @@ -0,0 +1,150 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Building From Source + + + + + + + + + + + + +

+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
Building From Source
+
+
+ +

To use the SDK in a project, the code from the SDK must be included in that project. The easiest way to do this is to link to static libraries. The SDK comes with build scripts to build static libraries for common environments.

+

+Prerequisites

+

Building SDK code out of the box requires a number of tools. This section lists the tools used to build the SDK.

+ + + + + + + + + + + +
Prerequisite Notes
A C/C++ compiler Core code in C. Unit tests need C++11 support.
Python Validated with v2.7.10
SCons Validated with v2.4.1
Parts 0.10.9.2 or later
+

+Building

+

To use the SDK, you need to build it to generate libraries compatible with your build environment.

+

To build based on the default SConstruct file in the root directory of the SDK, invoke scons with no arguments.

cd <path/to/sdk-root>
+scons
+

By default, this performs a 64 bit release build.

+

Potentially useful command line options:

+ + + + + + + + + + + + + + + + + + + + + + + + + +
Option Action
--cfg=debug Build in debug mode
--cfg=release Build in release mode
--target=x86 Target x86
--target=x86_64 Target x86_64
--tc=cl Use msvc to compile
--tc=gcc Use gcc to compile
--tc=icl,mstools Use intelc to compile
build:: Build the SDK (does not build unit tests)
utest:: Build unit tests
run_utest:: Run unit tests (builds tests if needed)
-c Clean the build
+

Built components appear in the _install directory of the SDK root.

+

+Example Programs

+

The SDK includes several examples that show you different aspects of how the Intel® EPID scheme works. In the SDK build, these examples are located in _install/epid-sdk/example.

+ + + + + + + +
Name Description
signmsg Create Intel® EPID signature of message
verifysig Verify signature is from a group member in good standing
+

+Building with Other Build Systems

+

It is relatively straightforward to port the SDK to your build system of choice. The following dependency diagram shows the relationship between components and the sources used to build them.

+
+basicdoc.png +
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/ChangeLog.html b/sgx-jvm/linux-sgx/external/epid/doc/html/ChangeLog.html new file mode 100644 index 0000000000..ed8fc9fb33 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/ChangeLog.html @@ -0,0 +1,106 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: What's New + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
What's New
+
+
+

2.0.0

+

New in This Release

+
    +
  • Signed binary issuer material support.
      +
    • Binary issuer material validation APIs.
    • +
    • Updated sample issuer material.
    • +
    • Updated samples that parse signed binary issuer material.
    • +
    +
  • +
  • Compressed member private key support.
  • +
  • Validated on additional IoT platforms.
      +
    • Windows 10 IoT Core
    • +
    • WindRiver IDP
    • +
    +
  • +
+

Changes

+
    +
  • The default hash algorithm has changed. It is now SHA-512.
  • +
  • Functions that returned EpidNullPtrErr now return EpidBadArgErr instead.
  • +
+

Fixes

+
    +
  • Updated build flags to work around GCC 4.8.5 defect.
  • +
+

Known Issues

+
    +
  • SHA-512/256 hash algorithm is not supported.
  • +
  • Compressed key sample material is not included in the package.
  • +
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/EpidOverview.html b/sgx-jvm/linux-sgx/external/epid/doc/html/EpidOverview.html new file mode 100644 index 0000000000..ae20c68102 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/EpidOverview.html @@ -0,0 +1,172 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Introduction to the Intel® EPID Scheme + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
Introduction to the Intel® EPID Scheme
+
+
+ +

Intel® EPID is a cryptographic protocol which enables the remote authentication of a trusted platform whilst preserving the user's privacy.

+

+Roles

+

In the Intel® EPID scheme, there are three roles: issuers, members, and verifiers.

+

The entities in these roles interact with each other in such a way that a member can prove to a verifier that it is a trusted member of a group without disclosing the identity of the member. Groups are created and managed by the issuer.

+
+epid_diagram_high_level_use_case.png +
+

+Issuers

+

The issuer is responsible for managing group membership.

+

The issuer manages groups by doing the following:

+
    +
  • Creates groups by generating one issuing private key and one group certificate for each group. The group certificate contains the group public key.
  • +
  • Creates group members by generating unique Intel® EPID member private keys through bulk provisioning. Member private keys are created from the issuing private key for the group.
  • +
  • Manages requests from prospective members to join existing groups by using the join protocol.
  • +
  • Creates and maintains signature based revocation lists and private key based revocation lists. These lists of members no longer in good standing allow members to be dropped from a group.
  • +
  • Creates and maintains group revocation lists.
  • +
  • Makes group public keys and revocation lists available to verifiers.
  • +
+
+epid_diagram_issuer_high_level.png +
+

+Members

+

The member is the entity that attempts to anonymously prove its group membership to the verifier.

+
    +
  • Members are authorized by the issuer as part of a group.
  • +
  • Each group member has a unique Intel® EPID private key, which corresponds to the group.
  • +
  • The member uses its member private key to sign a message to prove group membership to the verifier without revealing the identity of the member.
  • +
+
+epid_diagram_member_high_level.png +
+

+Verifiers

+

The verifier checks an Intel(R) EPID signature to establish whether it was signed by an entity or device that is a member in good standing.

+

The verifier acts on behalf of a party that needs to know it is communicating with a trusted device. Verifiers obtain group certificates and revocation lists from issuers and negotiate details of signature protocol with members.

+

A verifier can do the following:

+
    +
  • Confirm a member is in fact a member of a given group in good standing.
  • +
  • Obtain group certificates and revocation lists from issuers.
  • +
  • Negotiate details of signature protocol with members.
  • +
+
+epid_diagram_verifier_high_level.png +
+

+Groups

+

An Intel® EPID group represents a set of trusted entities called members. Issuers create groups and manage group membership. For each group, the issuer creates a group public key simultaneously with the corresponding issuing private key. The issuer uses the issuing private key to create unique member private keys for each group member, and makes the group public key available to verifiers.

+

All groups have the following:

+
    +
  • Group public key, which corresponds to the issuing private key kept by the issuer
  • +
  • Signature based revocation list
  • +
  • Private key based revocation list
  • +
  • Member private keys, generated from the issuing private key
  • +
+

If a signature based revocation list or private key based revocation list does not exist, it is assumed to be empty.

+

+Keys

+

The Intel® EPID scheme works with three types of keys: the group public key, the issuing private key, and the member private key. A group public key corresponds to the unique member private keys that are part of the group. Member private keys are generated from the issuing private key.

+

Additionally, in the Intel® EPID scheme, a private key can be revoked given a signature created by that key, even if the key itself is still unknown. Group membership can be revoked and entire groups can be revoked. For more information on revocation, refer to Revocation.

+

+Group Public Key

+

The group public key is the key used by the verifier to confirm that a member belongs to a group in good standing. Each member private key in a group is associated with the group's public key.

+

When a group is created, the group public key and the issuing private key are simultaneously generated by the issuer. The verifier obtains the group public key from the issuer.

+

+Issuing Private Key

+

The issuing private key is the key used by the issuer to generate unique private keys for each member of a given group. For every group public key, there is a corresponding issuing private key. The issuing private key remains with the issuer and is kept private.

+

+Member Private Key

+

The member private key is the key used by the member to digitally sign a message when attempting to prove to the verifier that the member belongs to the group and is in good standing.

+

Unique member private keys are generated by the issuer for each member of a given group. The same group public key corresponds to each member private key in the group.

+

+Member and Verifier Interaction

+

Each Intel® EPID member uses its Intel® EPID private key to digitally sign a message. The resulting signature is called an Intel® EPID signature.

+

The Intel® EPID verifier uses the group public key to verify the correctness of an Intel® EPID signature, i.e., to verify that the signature was indeed created by a member with a valid Intel® EPID private key.

+

However, the Intel® EPID signature does not convey any information about which unique private key was used to create the signature.

+
+epid_diagram_high_level_interaction.png +
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/Glossary.html b/sgx-jvm/linux-sgx/external/epid/doc/html/Glossary.html new file mode 100644 index 0000000000..09a29e6fcb --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/Glossary.html @@ -0,0 +1,170 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Glossary + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
Glossary
+
+
+ +

+DAA

+

Direct Anonymous Attestation (DAA) is a digital signature algorithm that supports anonymity by providing a group public verification key associated with many unique private signing keys. Intel® EPID enhances DAA by enabling a private key to be revoked given a signature created by that key, even if the key itself is still unknown.

+

+Elliptic curve

+

In elliptic curve cryptography, an elliptic curve is an algebraic structure used to create a function whose output is easy to compute, but whose input is difficult to compute given the output. Elliptic curve cryptography requires smaller keys compared to non-elliptic curve cryptography (based on Galois fields) to provide equivalent security.

+

+Elliptic curve point

+

An elliptic curve point is a point along an elliptic curve. The security of elliptic curve cryptography depends on the ability to compute a point multiplication and the inability to compute the multiplicand given the original and product points.

+

+Group

+

An Intel® EPID group represents a set of trusted entities called members.

+

Issuers create groups and manage group membership. For each group, the issuer creates a group public key simultaneously with the corresponding issuing private key. The issuer uses the issuing private key to create unique member private keys for each group member, and makes the group public key available to verifiers.

+

All groups have the following:

+
    +
  • Group public key, which corresponds to the issuing private key kept by the issuer
  • +
  • Signature based revocation list
  • +
  • Private key based revocation list
  • +
  • Member private keys, generated from the issuing private key
  • +
+

If a signature based revocation list or private key based revocation list does not exist, it is assumed to be empty.

+

+Group certificate

+

The group certificate contains the group public key. The group certificate is created by the issuer and obtained by the verifier. When the issuer creates groups, it generates one issuing private key and one group certificate for each group.

+

+Group public key

+

The group public key is the key used by the verifier to confirm that a member belongs to a group in good standing. Each member private key in a group is associated with the group's public key.

+

When a group is created, the group public key and the issuing private key are simultaneously generated by the issuer. The verifier obtains the group public key from the issuer.

+

+Intel® EPID

+

Enhanced Privacy ID (Intel® EPID) is a cryptographic protocol for attestation of a trusted platform while preserving the user's privacy. Intel® EPID can be used as a foundational building block for a multitude of security solutions.

+

+Intel® EPID signature

+

An Intel® EPID signature is a type of digital signature that preserves anonymity of the signer, while still proving the signer is a member of a trusted group.

+

+Issuer

+

The issuer is the entity in the Intel® EPID scheme that is responsible for managing group membership. An example of an issuer is the Intel Key Generation Facility.

+

The issuer manages groups by doing the following:

+
    +
  • Creates groups by generating one issuing private key and one group certificate for each group. The group certificate contains the group public key.
  • +
  • Creates group members by generating unique Intel® EPID member private keys through bulk provisioning. Member private keys are created from the issuing private key for the group.
  • +
  • Manages requests from prospective members to join existing groups by using the join protocol.
  • +
  • Creates and maintains signature based revocation lists and private key based revocation lists. These lists of members no longer in good standing allow members to be dropped from a group.
  • +
  • Creates and maintains group revocation lists.
  • +
  • Makes group public keys and revocation lists available to verifiers.
  • +
+

+Issuing private key

+

The issuing private key is the key used by the issuer to generate unique private keys for each member of a given group. For every group public key, there is a corresponding issuing private key. The issuing private key remains with the issuer and is kept private.

+

+Member

+

The member is the entity that attempts to prove its group membership to the verifier. Members are authorized by the issuer as part of a group and each group member has a unique Intel® EPID private key. The member uses its member private key to sign a message to prove group membership without revealing its identity. An example of a member is a PC with an embedded Intel® EPID member private key.

+

+Name-based signature

+

A name-based signature is a type of signature that gives the verifier the ability to link Intel® EPID signatures from the same member, reducing the member's privacy.

+

A name-based signature is created using the additional parameter of a basename. If a basename is not specified, a random number is chosen as the basename. If the member uses the same basename, the verifier can mathematically link signatures generated by the member, showing that the signatures are from the same member.

+

+Member private key

+

The member private key is the key used by the member to digitally sign a message when attempting to prove to the verifier that the member belongs to the group and is in good standing.

+

Unique member private keys are generated by the issuer for each member of a given group. The same group public key corresponds to each member private key in the group.

+

+Non-revoked proof

+

A non-revoked proof is part of an Intel® EPID signature that proves that the member is not a specific revoked entity in the signature based revocation list. The member provides the signature with a number of non-revoked proofs, one per revocation list entry, to prove to the verifier that the member does not correspond to any entry in the revocation list.

+

+Pairing

+

Pairing is a mathematical operation that maps two elliptic curve groups to a third multiplicative group.

+

+Revocation, revocation lists

+

Revocation lists are data structures used by the verifier to identify members that are no longer approved members of the group.

+

The verifier obtains the member private key based revocation list (PrivRL), signature based revocation list (SigRL), and group based revocation list (GroupRL) from the issuer. The verifier can also maintain its own verifier blacklist (VerifierRL).

+

+Verifier

+

The verifier is the entity that checks an Intel® EPID signature to establish whether it was signed by an entity or device that is a member in good standing.

+

The verifier acts on behalf of a party that needs to know it is communicating with a trusted device. Verifiers obtain group certificates and revocation lists from issuers and negotiate details of signature protocol with members.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/ImplementationNotes.html b/sgx-jvm/linux-sgx/external/epid/doc/html/ImplementationNotes.html new file mode 100644 index 0000000000..c8a9555422 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/ImplementationNotes.html @@ -0,0 +1,110 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Implementation Notes + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
Implementation Notes
+
+
+ +

+Random Number Generation

+

Some SDK APIs require a random number data source. A BitSupplier provides a source of random data. This function should be a cryptographically secure random number generator.

+
Warning
The pseudo-random number generator provided with the examples is for sample use only and is not suitable for cryptographically secure applications.
+

+Protecting Secrets

+

Member code works with private keys, so member code must be run in a trusted environment.

+
Warning
If member memory is available to an untrusted source, the member private key could be exposed.
+

The EpidZeroMemory function is used by the memory allocation routines EpidAlloc, EpidRealloc and EpidFree to wipe the memory as memory is freed.

+
Warning
The EpidZeroMemory function may be optimized away by some compilers. If it is, you should consider using a compiler or operating system specific memory sanitization function (e.g. memcpy_s or SecureZeroMemory).
+

+Replacing Math Primitives

+

SDK math primitives are designed to be replaced with your own implementation if you need to rely on custom hardware for performance. The SDK is designed to simplify this process by isolating implementation details behind a clearly defined interface, defined by the non-internal headers the epid/common/math directory. Math functionality has detailed tests to ease validation.

+

+Octstring/Buffer Types

+

Serialized information in the SDK is passed in fixed size buffer types whenever possible. Collectively these fixed size buffer types are called Octstrings.

+

In epid/common/types.h, there are a large number of packed structs that contain other packed structs, which eventually contain OctStr* types. Normally these are named *Str and are refered to as Str types.

+

OctStr* types are buffers that hold N bits, where N is the number at the end of the type name. These types usually represent numbers in a Big Endian format (buffer[0] is the most significant value).

+

Str types generally represent fixed size groups of numbers such as a point or vector.

+

OctStr* and Str types are usually populated by reading a buffer from a file or other storage, or by calling a serialize function. OctStr* and Str types must be packed so that the compiler does not insert padding. In the current code, this is done using pragmas.

+
#pragma pack(1)
// OctStr* type holding 256 bits
typedef struct OctStr256 {
unsigned char data[256 / CHAR_BIT];
// Str type consisting of a single 256 bit number
typedef struct FqElemStr {
// Str type consisting of a two other Str types
typedef struct G1ElemStr {

Many APIs use void* parameters where OctStr* types are expected. If more than one size is allowed, a size parameter is usually also required.

+

+Flexible Arrays

+

A common idiom in the SDK is the use of flexible array types. These types are structs with the last element being an array of size 1 of some type. Flexible array types always have a size value embedded in the struct. The name of the count and array fields differs between flexible array types.

+
typedef struct Sample {
OctStr32 data;
OctStr32 count;
G1ElemStr array[1];
} Sample;

Flexible array types are expected to be in a buffer of size sizeof(FA) + ((N-1) * sizeof(E)) where FA is the flexible array type, N is the number of elements in the array and E is the type of each element. Note that this may be smaller than sizeof(FA) if N is 0, in which case referencing any element is an error.

+
Sample* AllocSample(size_t count) {
return (Sample*)malloc(sizeof(Sample)
+ (count * sizeof(G1ElemStr))
- sizeof(G1ElemStr));
}

In many cases, functions that accept flexible array types will also expect a buffer size that is compared against the computed size of the array as a sanity check.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/IssuerMaterial.html b/sgx-jvm/linux-sgx/external/epid/doc/html/IssuerMaterial.html new file mode 100644 index 0000000000..67d8ab03d0 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/IssuerMaterial.html @@ -0,0 +1,136 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Sample Issuer Material + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
Sample Issuer Material
+
+
+ +

Because the SDK does not include issuer APIs, pre-generated sample data is included for validation purposes.

+
Note
Sample compressed key material is not included in the package.
+

+Sample Groups

+

Issuers create groups and manage group membership. For each group, the issuer creates a group public key simultaneously with the corresponding issuing private key. The issuer uses the issuing private key to create unique member private keys for each group member, and makes the group public key available to verifiers.

+

All groups have the following:

+
    +
  • Group public key, which corresponds to the issuing private key kept by the issuer
  • +
  • Signature based revocation list
  • +
  • Private key based revocation list
  • +
  • Member private keys, generated from the issuing private key
  • +
+

If a signature based revocation list or private key based revocation list does not exist, it is assumed to be empty.

+

+groupa

+

There are eight members in groupa:

+
    +
  • groupa/member0 - A non-revoked member.
  • +
  • groupa/member1 - Another non-revoked member.
  • +
  • groupa/privrevokedmember0 - A revoked member. Revoked by Private-Key based revocation list (groupa/privrl.bin)
  • +
  • groupa/privrevokedmember1 - A revoked member. Revoked by Private-Key based revocation list (groupa/privrl.bin)
  • +
  • groupa/privrevokedmember2 - A revoked member. Revoked by Private-Key based revocation list (groupa/privrl.bin)
  • +
  • groupa/sigrevokedmember0 - A revoked member. Revoked by Signature based revocation list (groupa/sigrl.bin)
  • +
  • groupa/sigrevokedmember1 - A revoked member. Revoked by Signature based revocation list (groupa/sigrl.bin)
  • +
  • groupa/sigrevokedmember2 - A revoked member. Revoked by Signature based revocation list (groupa/sigrl.bin)
  • +
+

The following are groupa revocation lists:

+
    +
  • groupa/privrl.bin - Private-Key based revocation list. privrevokedmember0, privrevokedmember1 and privrevokedmember2** revoked.
  • +
  • groupa/sigrl.bin - Signature based revocation list. sigrevokedmember0, sigrevokedmember0 and sigrevokedmember0** revoked.
  • +
+

+groupb

+

There are four members in groupb:

+
    +
  • groupb/member0 - A non-revoked member.
  • +
  • groupb/member1 - Another non-revoked member.
  • +
  • groupb/privrevokedmember0 - A revoked member. Revoked by Private-Key based revocation list (groupb/privrl.bin)
  • +
  • groupb/sigrevokedmember0 - A revoked member. Revoked by Signature based revocation list (groupb/sigrl.bin)
  • +
+

The following are groupb revocation lists:

+
    +
  • groupb/privrl.bin - Private-Key based revocation list. privrevokedmember0 revoked.
  • +
  • groupb/sigrl.bin - Signature based revocation list. sigrevokedmember0 revoked.
  • +
+

+Group Based Revocation Lists

+

If an entire group is no longer valid, the issuer can revoke it using the group based revocation list. Two sample group based revocation lists are provided with the SDK.

+
    +
  • grprl_empty.bin - No entries
  • +
  • grprl.bin - One entry in which groupb is revoked.
  • +
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/LegalInformation.html b/sgx-jvm/linux-sgx/external/epid/doc/html/LegalInformation.html new file mode 100644 index 0000000000..959bf33c6c --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/LegalInformation.html @@ -0,0 +1,84 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Legal Information + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
Legal Information
+
+
+

INFORMATION IN THIS DOCUMENT IS PROVIDED IN CONNECTION WITH INTEL® PRODUCTS. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. EXCEPT AS PROVIDED IN INTEL'S TERMS AND CONDITIONS OF SALE FOR SUCH PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER, AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO SALE AND/OR USE OF INTEL PRODUCTS INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.

+

UNLESS OTHERWISE AGREED IN WRITING BY INTEL, THE INTEL PRODUCTS ARE NOT DESIGNED NOR INTENDED FOR ANY APPLICATION IN WHICH THE FAILURE OF THE INTEL PRODUCT COULD CREATE A SITUATION WHERE PERSONAL INJURY OR DEATH MAY OCCUR.

+

Intel may make changes to specifications and product descriptions at any time, without notice. Designers must not rely on the absence or characteristics of any features or instructions marked "reserved" or "undefined." Intel reserves these for future definition and shall have no responsibility whatsoever for conflicts or incompatibilities arising from future changes to them. The information here is subject to change without notice. Do not finalize a design with this information.

+

The products described in this document may contain design defects or errors known as errata which may cause the product to deviate from published specifications. Current characterized errata are available on request.

+

Contact your local Intel sales office or your distributor to obtain the latest specifications and before placing your product order.

+

Copies of documents which have an order number and are referenced in this document, or other Intel literature, may be obtained by calling 1-800-548-4725, or by visiting Intel's web site http://www.intel.com.

+

Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and other countries.

+

*Other names and brands may be claimed as the property of others.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/SdkOverview.html b/sgx-jvm/linux-sgx/external/epid/doc/html/SdkOverview.html new file mode 100644 index 0000000000..b9432dfdda --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/SdkOverview.html @@ -0,0 +1,163 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: What's Included in the SDK + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
What's Included in the SDK
+
+
+ +

+SDK Components

+

The SDK is divided into logical components to separate responsibilities and create interfaces that you can re-implement using custom tools such as hardware accelerators.

+
+sdk_block_diagram.png +
+


+ The Intel® EPID SDK is divided into the following components:

+ + + + + + + + + + + + + + + + + + + + + + + + + +
Component Description
member Library containing APIs needed to implement a member
verifier Library containing APIs needed to implement a verifier
common Library containing common types and functions
math Math primitives used by member and verifier
IPP A C-only non-optimized subset of Intel® IPP
signmsg A sample program showing how to sign messages
verfifysig A sample program showing how to verify signatures
util Common utilities used by samples
gtest gtest unit test framework
Build Scripts Scripts to configure and build the SDK
Sample Issuer Material Sample keys and revocation lists
+

Math primitives are implemented in the math sub-component of common. The reference math primitive implementation is based on a non-optimized Vanilla C subset of the Intel® Performance Primitives. Math is designed so that you can replace its implementation to call custom hardware IP blocks or optimized libraries.

+

+Filesystem Layout

+

The Intel® EPID SDK has two filesystem layouts: the Source Layout and the Install Layout.

+

The Source Layout is what you find when you download the SDK and extract it to disk. This layout contains all of the files that you need to build the libraries, samples, tests, and data generated by the SDK.

+

The Install Layout is the layout of files under the _install folder after you build the SDK.

+

+Source Layout

+

The Source Layout is used by the build scripts in the Intel® EPID SDK to find components and files needed to create libraries and executables.

epid-sdk/
+|__ LICENSE.txt             Distribution license
+|__ NOTICE.txt              Legal notices
+|__ README.md               Readme
+|__ RELEASE_NOTES.md        Release notes
+|__ SConstruct              Main build configuration
+|
+|__ doc/
+|   |__ html/               HTML format documentation
+|   |__ index.html          Entry point for HTML format documentation
+|
+|__ epid/
+|   |__ common/             Source for Common
+|   |__ common-testhelper/  Source for unit test helper common helpers
+|   |__ member/             Source for Member
+|   |__ verifier/           Source for Verifier
+|
+|__ example/
+|   |__ data/               Binary data used for testing and tutorials
+|   |__ signmsg/            Source for message signing example
+|   |__ util/               Common utilities for examples
+|   |__ verifysig/          Source for signature validation signing example
+|
+|__ ext/
+|   |__ gtest/             Third party gtest library
+|   |__ ipp/               IPP library
+|
+|__ parts-site/            Parts platform config scripts
+

+Install Layout

+

The Install Layout contains the data developers need to develop and build their applications using the Intel® EPID SDK. Once built, the Install Layout has no dependency on the Source Layout, allowing developers to build the SDK once and reuse the built files in other locations or on other computers.

_install/
+|__ epid-sdk/
+    |__ include/            C include header files for the SDK
+    |__ lib/
+    |   |__ <platform>      Target specific static libraries for the SDK
+    |
+    |__example/             Sample applications and data
+    |__test/                Unit test executables (if unit tests built)
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/SignVerifyTutorial.html b/sgx-jvm/linux-sgx/external/epid/doc/html/SignVerifyTutorial.html new file mode 100644 index 0000000000..3aca35d6f5 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/SignVerifyTutorial.html @@ -0,0 +1,192 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Signing and Verification Tutorial + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
Signing and Verification Tutorial
+
+
+ +

The Intel® EPID SDK provides example tools to show you how to use the Intel® EPID SDK APIs. These examples are called signmsg and verifysig.

+

You can build these examples using the instructions in Building From Source. The tutorial assumes _install/epid-sdk/example is the current directory.

+

All command lines in this tutorial use posix command line conventions; for other systems, adjust accordingly.

+

For the code used in this tutorial, refer to Examples.

+
Note
The data for running this tutorial is pre-generated. Once the samples are built, the data is in the _install/epid-sdk/example/data directory. See Sample Issuer Material.
+

+Creating an Intel® EPID Signature of a Given Message

+

The example application signmsg shows you how to create an Intel® EPID Signature of a given message.

$ ./signmsg -h
+Usage: signmsg [OPTION]...
+Create Intel(R) EPID signature of message
+
+Options:
+
+--sig=FILE            write signature to FILE (default: sig.dat)
+--msg=MESSAGE         MESSAGE to sign
+--bsn=BASENAME        BASENAME to sign with (default: random)
+--sigrl=FILE          load signature based revocation list from FILE
+--gpubkey=FILE        load group public key from FILE
+                        (default: pubkey.bin)
+--mprivkey=FILE       load member private key from FILE
+                        (default: mprivkey.dat)
+--mprecmpi=FILE       load pre-computed member data from FILE
+--mprecmpo=FILE       write pre-computed member data to FILE
+--hashalg=NAME        SHA-256 | SHA-384 | SHA-512 (default: SHA-512)
+--capubkey=FILE       load IoT Issuing CA public key from FILE
+                        (default: cacert.bin)
+-h,--help             display this help and exit
+-v,--verbose          print status messages to stdout
+

To sign a message, a group member in good standing uses the following command:

$ ./signmsg --msg="test0"
+

The above command signs a message "test0". signmsg uses default options for the group public key, member private key, and hash algorithm (SHA-512). All other parameters that are not given are ignored. The command produces a signature file: sig.dat

+

+Verifying an Intel® EPID Signature

+

The example application verifysig shows you how to verify that a given Intel® EPID Signature is produced by a member in good standing.

$ ./verifysig -h
+Usage: verifysig [OPTION]...
+Verify signature was created by group member in good standing
+
+Options:
+
+--sig=FILE            load signature from FILE (default: sig.dat)
+--msg=MESSAGE         MESSAGE that was signed (default: empty)
+--bsn=BASENAME        BASENAME used in signature (default: random)
+--privrl=FILE         load private key based revocation list from FILE
+--sigrl=FILE          load signature based revocation list from FILE
+--grprl=FILE          load group revocation list from FILE
+                        (default: grprl.bin)
+--verifierrl=FILE     load verifier revocation list from FILE
+--gpubkey=FILE        load group public key from FILE (default: pubkey.bin)
+--vprecmpi=FILE       load pre-computed verifier data from FILE
+--vprecmpo=FILE       write pre-computed verifier data to FILE
+--hashalg=NAME        SHA-256 | SHA-384 | SHA-512 (default: SHA-512)
+--capubkey=FILE       load IoT Issuing CA public key from FILE
+                        (default: cacert.bin)
+-h,--help             display this help and exit
+-v,--verbose          print status messages to stdout
+

To verify that a signature is from a member in good standing, the verifier uses the following command:

$ ./verifysig --msg="test0"
+signature verified successfully
+

This verifies that the default signature file sig.dat is generated for the message "test0" by a member in good standing. verifysig uses default inputs for group public key and hash algorithm (SHA-512). All other parameters are ignored. The output verifysig: signature verified successfully denotes that the verification is successful.

+

+Linking Intel® EPID Signatures from the Same Member

+

A name-based signature is a type of signature that gives the verifier the ability to link Intel® EPID signatures from the same member, reducing the member's privacy.

+

The verifier can ask the member to sign a message with a basename that the verifier chooses. If the member uses the name-based signature option (i.e., in cases where a basename is specified), then all the signatures created by the member using the same basename are linkable by the verifier.

+
Warning
The use of a name-based signature creates a platform unique pseudonymous identifier. Because it reduces the member's privacy, the user should be notified when it is used and should have control over its use.
+

A name-based signature is created using the additional parameter of a basename. If the member uses the same basename, the verifier can mathematically link signatures generated by the member, showing that the signatures are from the same member.

+

If basename is not provided, then the member uses a random basename and the signature generated by the member is anonymous.

+

To Sign message "test0" with a basename "base0":

$ ./signmsg --msg="test0" --bsn="base0"
+

To verify the signature:

$ ./verifysig --msg="test0" --bsn="base0"
+verifysig: signature verified successfully
+

+Expected Failures

+

The signature verification process fails if there is a parameter mismatch between sign and verify operations. Here are some examples.

+

Verification fails if there is a mismatch in the message:

$ ./signmsg --msg="test0"
+$ ./verifysig --msg="test1"
+verifysig: signature verification failed: invalid signature
+

Verification fails if there is a mismatch in the basename:

$ ./signmsg --msg="test0" --bsn="base0"
+$ ./verifysig --msg="test0" --bsn="base1"
+verifysig: signature verification failed: invalid signature
+

The Intel® EPID SDK supports the following hash algorithms: SHA-256, SHA-384, SHA-512. The selected hash algorithm must be the same for both sign and verify. Mismatch in hash algorithm results in verification failure:

$ ./signmsg --msg="test0" --hashalg=SHA-256
+$ ./verifysig --msg="test0" --hashalg=SHA-384
+verifysig: signature verification failed: invalid signature
+

+Revocation

+

Revocation lists are data structures used by the verifier to identify members that are no longer approved members of the group.

+

The verifier obtains the member private key based revocation list (PrivRL), signature based revocation list (SigRL), and group based revocation list (GroupRL) from the issuer. The verifier can also maintain its own verifier blacklist (VerifierRL).

+

+Detecting Revoked Group from Group Revocation List

+

Verification of a signature fails if it is generated by a member of a group that is revoked in the group revocation list.

+

For example,

$ ./signmsg --msg="test0" --gpubkey=data/groupb/pubkey.bin --mprivkey=data/groupb/member0/mprivkey.dat
+$ ./verifysig --msg="test0" --grprl=data/grprl.bin --gpubkey=data/groupb/pubkey.bin
+verifysig: signature verification failed: signature revoked in GroupRl
+

The verification fails because groupb is revoked and is an entry in the group revocation list (grprl.bin).

+

+Detecting Revoked Member from Private Key Based Revocation List

+

Verification of a signature fails if it is generated by a member whose private key is revoked in a private-key based revocation list.

+

For example,

$ ./signmsg --msg=test0 --gpubkey=data/groupa/pubkey.bin --mprivkey=data/groupa/privrevokedmember0/mprivkey.dat
+$ ./verifysig --msg=test0 --privrl=data/groupa/privrl.bin --gpubkey=data/groupa/pubkey.bin
+verifysig: signature verification failed: signature revoked in PrivRl
+

The verification fails because the private key of privrevokedmember0 is revoked and is an entry in the private key based revocation list of groupa (privrl.bin).

+

+Detecting Revoked Member from Signature Based Revocation List

+

Verification of a signature fails if it is generated by a member whose signature is revoked in a signature based revocation list.

$ ./signmsg --msg="test1" --sigrl=data/groupa/sigrl.bin --gpubkey=data/groupa/pubkey.bin --mprivkey=data/groupa/sigrevokedmember0/mprivkey.dat
+signmsg: signature revoked in SigRL
+$ ./verifysig --msg="test1" --sigrl=data/groupa/sigrl.bin --gpubkey=data/groupa/pubkey.bin
+verifysig: signature verification failed: signature revoked in SigRl
+

The message "test1" is signed by signmsg with a warning signmsg: signature revoked in SigRL. This means that the signature of sigrevokedmember0 is revoked in the signature based revocation list. The verification fails because the signature was generated by sigrevokedmember0, which is revoked and is an entry in the signature based revocation list of groupa (sigrl.bin).

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/annotated.html b/sgx-jvm/linux-sgx/external/epid/doc/html/annotated.html new file mode 100644 index 0000000000..3fbd0796d1 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/annotated.html @@ -0,0 +1,136 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Structures + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
Data Structures
+
+
+
Here are the data structures with brief descriptions:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 CAllowedBasenameInternal implementation of base name
 CBasicSignatureIntel(R) EPID 2.0 basic signature
 CBigNumStrSerialized BigNum
 CCommitValuesStorage for values to create commitment in Sign and Verify algorithms
 CCompressedPrivKeyCompressed private key
 CEcdsaPrivateKeyECDSA Private Key
 CEcdsaPublicKeyECDSA Public Key
 CEcdsaSignatureECDSA Signature using NIST 256-bit curve secp256r1
 CEpid2ParamsIntel(R) EPID 2.0 Parameters
 CEpid2Params_Internal representation of Epid2Params
 CEpidCaCertificateIoT CA Certificate binary format
 CEpidFileHeaderIntel(R) EPID binary file header
 CEpidGroupPubKeyCertificateIntel(R) EPID 2.0 Group Public Key binary format
 CEpidSignatureIntel(R) EPID 2.0 Signature
 CErrorTextEntryRecord mapping status code to string
 CFpElemStrNumber in [0, p-1]
 CFq12ElemDatData for element in Fq2^3^2
 CFq12ElemStrSerialized Fq2^3^2 element
 CFq2ElemDatData for element in Fq2
 CFq2ElemStrSerialized Fq2 element
 CFq6ElemDatData for element in Fq2^3
 CFq6ElemStrSerialized Fq2^3 element
 CFqElemDatData for element in Fq
 CFqElemStrNumber in [0, q-1]
 CG1ElemStrSerialized G1 element
 CG2ElemStrSerialized G2 element
 CGroupPubKeyIntel(R) EPID 2.0 group public key
 CGroupPubKey_Internal representation of GroupPubKey
 CGroupRlGroup revocation list
 CGtElemStrSerialized GT element
 CIPrivKeyIntel(R) EPID 2.0 issuing private key
 CJoinPCommitValuesStorage for values to create commitment in Sign and Verify algorithms
 CJoinRequestJoin request
 CMemberCtxMember context definition
 CMemberPrecompPre-computed member settings
 CMembershipCredentialMembership credential
 CNrProofNon-revoked Proof
 CNrVerifyCommitValuesStorage for values to create commitment in NrProve algorithm
 COctStr128128 bit octet string
 COctStr1616 bit octet string
 COctStr256256 bit octet string
 COctStr3232 bit octet string
 COctStr512512 bit octet string
 COctStr6464 bit octet string
 COctStr88 bit octet string
 CPreComputedSignaturePre-computed signature
 CPrivKeyIntel(R) EPID 2.0 private key
 CPrivKey_Internal implementation of PrivKey
 CPrivRlPrivate-key based revocation list
 CSha256DigestSHA256 digest
 CSigRlSignature based revocation list
 CSigRlEntryEntry in SigRL (B,K)
 CStackInternal representation of a Stack
 CVerifierCtxVerifier context definition
 CVerifierPrecompPre-computed member settings
 CVerifierRl
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/arrowdown.png b/sgx-jvm/linux-sgx/external/epid/doc/html/arrowdown.png new file mode 100644 index 0000000000..0b63f6d38c Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/arrowdown.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/arrowright.png b/sgx-jvm/linux-sgx/external/epid/doc/html/arrowright.png new file mode 100644 index 0000000000..c6ee22f937 Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/arrowright.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/basicdoc.png b/sgx-jvm/linux-sgx/external/epid/doc/html/basicdoc.png new file mode 100644 index 0000000000..e092eb64db Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/basicdoc.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/bc_s.png b/sgx-jvm/linux-sgx/external/epid/doc/html/bc_s.png new file mode 100644 index 0000000000..224b29aa98 Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/bc_s.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/bdwn.png b/sgx-jvm/linux-sgx/external/epid/doc/html/bdwn.png new file mode 100644 index 0000000000..940a0b9504 Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/bdwn.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/bignum_8c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/bignum_8c.html new file mode 100644 index 0000000000..4ad4279bec --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/bignum_8c.html @@ -0,0 +1,120 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/math/bignum.c File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
bignum.c File Reference
+
+
+ +

Big number implementation. +More...

+
#include "epid/common/math/bignum.h"
+#include "epid/common/math/bignum-internal.h"
+#include "epid/common/memory.h"
+#include "ext/ipp/include/ippcp.h"
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

EpidStatus NewBigNum (size_t data_size_bytes, BigNum **bignum)
 Constructs a new BigNum. More...
 
void DeleteBigNum (BigNum **bignum)
 Deletes a previously allocated BigNum. More...
 
EpidStatus ReadBigNum (void const *bn_str, size_t strlen, BigNum *bn)
 Deserializes a BigNum from a string. More...
 
EpidStatus WriteBigNum (BigNum const *bn, size_t strlen, void const *bn_str)
 Serializes a BigNum to a string. More...
 
+int OctStr2Bnu (uint32_t *bnu_ptr, void const *octstr_ptr, int octstr_len)
 convert octet string into "big number unsigned" representation
 
EpidStatus BigNumAdd (BigNum const *a, BigNum const *b, BigNum *r)
 Adds two BigNum values. More...
 
EpidStatus BigNumSub (BigNum const *a, BigNum const *b, BigNum *r)
 Subtracts two BigNum values. More...
 
EpidStatus BigNumMul (BigNum const *a, BigNum const *b, BigNum *r)
 Multiplies two BigNum values. More...
 
EpidStatus BigNumMod (BigNum const *a, BigNum const *b, BigNum *r)
 Computes modular reduction for BigNum value by specified modulus. More...
 
+

Detailed Description

+

Big number implementation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/bignum_8h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/bignum_8h.html new file mode 100644 index 0000000000..ac66718f6c --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/bignum_8h.html @@ -0,0 +1,124 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/math/bignum.h File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
bignum.h File Reference
+
+
+ +

Big number interface. +More...

+
#include <stddef.h>
+#include <stdint.h>
+#include "epid/common/errors.h"
+#include "epid/common/types.h"
+
+ + + + +

+Typedefs

+typedef struct BigNum BigNum
 Internal representation of large numbers.
 
+ + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

EpidStatus NewBigNum (size_t data_size_bytes, BigNum **bignum)
 Constructs a new BigNum. More...
 
void DeleteBigNum (BigNum **bignum)
 Deletes a previously allocated BigNum. More...
 
EpidStatus ReadBigNum (void const *bn_str, size_t strlen, BigNum *bn)
 Deserializes a BigNum from a string. More...
 
EpidStatus WriteBigNum (BigNum const *bn, size_t strlen, void const *bn_str)
 Serializes a BigNum to a string. More...
 
EpidStatus BigNumAdd (BigNum const *a, BigNum const *b, BigNum *r)
 Adds two BigNum values. More...
 
EpidStatus BigNumSub (BigNum const *a, BigNum const *b, BigNum *r)
 Subtracts two BigNum values. More...
 
EpidStatus BigNumMul (BigNum const *a, BigNum const *b, BigNum *r)
 Multiplies two BigNum values. More...
 
EpidStatus BigNumMod (BigNum const *a, BigNum const *b, BigNum *r)
 Computes modular reduction for BigNum value by specified modulus. More...
 
+

Detailed Description

+

Big number interface.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/bitsupplier_8h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/bitsupplier_8h.html new file mode 100644 index 0000000000..c89b3b2043 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/bitsupplier_8h.html @@ -0,0 +1,92 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/bitsupplier.h File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
bitsupplier.h File Reference
+
+
+ +

Random data supplier interface. +More...

+ + + + + +

+Typedefs

typedef int(__STDCALL * BitSupplier) (unsigned int *rand_data, int num_bits, void *user_data)
 Generates random data. More...
 
+

Detailed Description

+

Random data supplier interface.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/building__sdk_8dox.html b/sgx-jvm/linux-sgx/external/epid/doc/html/building__sdk_8dox.html new file mode 100644 index 0000000000..6e2f6fe4bb --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/building__sdk_8dox.html @@ -0,0 +1,82 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: doc/docsrc/building_sdk.dox File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
doc/docsrc/building_sdk.dox File Reference
+
+
+ +

This file is used by Doxygen to generate documentation. +More...

+

Detailed Description

+

This file is used by Doxygen to generate documentation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/check__privrl__entry_8c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/check__privrl__entry_8c.html new file mode 100644 index 0000000000..77506853ea --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/check__privrl__entry_8c.html @@ -0,0 +1,93 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/verifier/check_privrl_entry.c File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
check_privrl_entry.c File Reference
+
+
+ +

EpidCheckPrivRlEntry implementation. +More...

+ + + + + +

+Functions

EpidStatus EpidCheckPrivRlEntry (VerifierCtx const *ctx, BasicSignature const *sig, FpElemStr const *f)
 Verifies a signature has not been revoked in the private key based revocation list. More...
 
+

Detailed Description

+

EpidCheckPrivRlEntry implementation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/classes.html b/sgx-jvm/linux-sgx/external/epid/doc/html/classes.html new file mode 100644 index 0000000000..1a92e1c897 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/classes.html @@ -0,0 +1,113 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Structure Index + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
Data Structure Index
+
+
+
A | B | C | E | F | G | I | J | M | N | O | P | S | V
+ + + + + + + + + + + + + + + + + + + + +
  A  
+
Epid2Params_   
  G  
+
MemberPrecomp   PrivKey   
EpidCaCertificate   MembershipCredential   PrivKey_   
AllowedBasename   EpidFileHeader   G1ElemStr   
  N  
+
PrivRl   
  B  
+
EpidGroupPubKeyCertificate   G2ElemStr   
  S  
+
EpidSignature   GroupPubKey   NrProof   
BasicSignature   ErrorTextEntry   GroupPubKey_   NrVerifyCommitValues   Sha256Digest   
BigNumStr   
  F  
+
GroupRl   
  O  
+
SigRl   
  C  
+
GtElemStr   SigRlEntry   
FpElemStr   
  I  
+
OctStr128   Stack   
CommitValues   Fq12ElemDat   OctStr16   
  V  
+
CompressedPrivKey   Fq12ElemStr   IPrivKey   OctStr256   
  E  
+
Fq2ElemDat   
  J  
+
OctStr32   VerifierCtx   
Fq2ElemStr   OctStr512   VerifierPrecomp   
EcdsaPrivateKey   Fq6ElemDat   JoinPCommitValues   OctStr64   VerifierRl   
EcdsaPublicKey   Fq6ElemStr   JoinRequest   OctStr8   
EcdsaSignature   FqElemDat   
  M  
+
  P  
+
Epid2Params   FqElemStr   
MemberCtx   PreComputedSignature   
+
A | B | C | E | F | G | I | J | M | N | O | P | S | V
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/closed.png b/sgx-jvm/linux-sgx/external/epid/doc/html/closed.png new file mode 100644 index 0000000000..98cc2c909d Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/closed.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/commitment_8c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/commitment_8c.html new file mode 100644 index 0000000000..13a543a28d --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/commitment_8c.html @@ -0,0 +1,98 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/commitment.c File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
commitment.c File Reference
+
+
+ +

Commitment hash implementation. +More...

+
#include <limits.h>
+#include "epid/common/commitment.h"
+#include "epid/common/memory.h"
+#include "epid/common/epid2params_ate.inc"
+
+ + + + + + + +

+Functions

EpidStatus SetCalculatedCommitValues (G1ElemStr const *B, G1ElemStr const *K, G1ElemStr const *T, EcPoint const *R1, EcGroup *G1, FfElement const *R2, FiniteField *GT, CommitValues *values)
 Set CommitValues structure fields calculated in algorithm. More...
 
EpidStatus CalculateCommitmentHash (CommitValues const *values, FiniteField *Fp, HashAlg hash_alg, void const *msg, size_t msg_len, FfElement *c)
 Calculate Fp.hash(t3 || m) for Sign and Verfiy algorithms. More...
 
+

Detailed Description

+

Commitment hash implementation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/commitment_8h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/commitment_8h.html new file mode 100644 index 0000000000..fc9e54f8c4 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/commitment_8h.html @@ -0,0 +1,108 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/commitment.h File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
commitment.h File Reference
+
+
+ +

Commitment hash interface. +More...

+ + + + + +

+Data Structures

struct  CommitValues
 Storage for values to create commitment in Sign and Verify algorithms. More...
 
+ + + + + + + + + + +

+Functions

EpidStatus SetKeySpecificCommitValues (GroupPubKey const *pub_key, CommitValues *values)
 Set group public key related fields from CommitValues structure. More...
 
EpidStatus SetCalculatedCommitValues (G1ElemStr const *B, G1ElemStr const *K, G1ElemStr const *T, EcPoint const *R1, EcGroup *G1, FfElement const *R2, FiniteField *GT, CommitValues *values)
 Set CommitValues structure fields calculated in algorithm. More...
 
EpidStatus CalculateCommitmentHash (CommitValues const *values, FiniteField *Fp, HashAlg hash_alg, void const *msg, size_t msg_len, FfElement *c)
 Calculate Fp.hash(t3 || m) for Sign and Verfiy algorithms. More...
 
+

Detailed Description

+

Commitment hash interface.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/decompress__privkey_8c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/decompress__privkey_8c.html new file mode 100644 index 0000000000..b34aa82ea7 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/decompress__privkey_8c.html @@ -0,0 +1,124 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/member/decompress_privkey.c File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
decompress_privkey.c File Reference
+
+
+ +

EpidDecompressPrivKey implementation. +More...

+
#include "epid/member/api.h"
+#include "epid/common/memory.h"
+#include "epid/common/epid2params.h"
+#include "epid/common/math/bignum-internal.h"
+#include "epid/common/math/hash.h"
+#include "epid/member/privkey.h"
+
+ + + + +

+Macros

#define BREAK_ON_EPID_ERROR(ret)
 Handle Intel(R) EPID Error with Break. More...
 
+ + + + +

+Functions

EpidStatus EpidDecompressPrivKey (GroupPubKey const *pub_key, CompressedPrivKey const *compressed_privkey, PrivKey *priv_key)
 Decompresses compressed member private key. More...
 
+

Detailed Description

+

EpidDecompressPrivKey implementation.

+

Macro Definition Documentation

+ +
+
+ + + + + + + + +
#define BREAK_ON_EPID_ERROR( ret)
+
+Value:
if (kEpidNoErr != (ret)) { \
break; \
}
no error
Definition: errors.h:41
+
+

Handle Intel(R) EPID Error with Break.

+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/dir_02c945662023679b89476bd7126bc985.html b/sgx-jvm/linux-sgx/external/epid/doc/html/dir_02c945662023679b89476bd7126bc985.html new file mode 100644 index 0000000000..34c3526226 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/dir_02c945662023679b89476bd7126bc985.html @@ -0,0 +1,111 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/verifier Directory Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
verifier Directory Reference
+
+
+ +

Verifier functionality.

+ +More...

+ + + + + + + + + + + + + + + + + + + + + + + + + + +

+Files

file  api.h
 Intel(R) EPID SDK verifier API.
 
file  check_privrl_entry.c
 EpidCheckPrivRlEntry implementation.
 
file  context.c
 Verifier context implementation.
 
file  context.h
 Verifier context interface.
 
file  nrverify.c
 NrVerfy implementation.
 
file  sigs_linked.c
 AreSigsLinked implementation.
 
file  verify.c
 Verify implementation.
 
file  verifybasic.c
 VerifyBasicSig implementation.
 
+

Detailed Description

+

Verifier functionality.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/dir_12b90d9c027aaf878a834df729679a56.html b/sgx-jvm/linux-sgx/external/epid/doc/html/dir_12b90d9c027aaf878a834df729679a56.html new file mode 100644 index 0000000000..9031b5cc6b --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/dir_12b90d9c027aaf878a834df729679a56.html @@ -0,0 +1,96 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid Directory Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
epid Directory Reference
+
+
+ +

Core Intel® EPID functionality.

+ +More...

+ + + + + + + + + + + +

+Directories

directory  common
 Common code shared between core sub-components.
 
directory  member
 Member functionality.
 
directory  verifier
 Verifier functionality.
 
+

Detailed Description

+

Core Intel® EPID functionality.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/dir_512d3e62841a8535b716ec4cf8b9e950.html b/sgx-jvm/linux-sgx/external/epid/doc/html/dir_512d3e62841a8535b716ec4cf8b9e950.html new file mode 100644 index 0000000000..dd82485b94 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/dir_512d3e62841a8535b716ec4cf8b9e950.html @@ -0,0 +1,123 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/member Directory Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
member Directory Reference
+
+
+ +

Member functionality.

+ +More...

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Files

file  api.h
 Intel(R) EPID SDK member API.
 
file  context.c
 Member context implementation.
 
file  context.h
 Member context interface.
 
file  decompress_privkey.c
 EpidDecompressPrivKey implementation.
 
file  get_sigsize.c
 EpidGetSigSize implementation.
 
file  nr_prove.c
 EpidNrProve implementation.
 
file  presig.c
 EpidComputePreSig implementation.
 
file  privkey.c
 Private key implementation.
 
file  privkey.h
 Private key private interface.
 
file  request_join.c
 EpidRequestJoin implementation.
 
file  sign.c
 EpidSign implementation.
 
file  signbasic.c
 EpidSignBasic implementation.
 
+

Detailed Description

+

Member functionality.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/dir_f169ebf8da29290a918fa4b3f7151050.html b/sgx-jvm/linux-sgx/external/epid/doc/html/dir_f169ebf8da29290a918fa4b3f7151050.html new file mode 100644 index 0000000000..7a85522717 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/dir_f169ebf8da29290a918fa4b3f7151050.html @@ -0,0 +1,132 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/math Directory Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
math Directory Reference
+
+
+ +

Math primitives.

+ +More...

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Files

file  bignum.c
 Big number implementation.
 
file  bignum.h
 Big number interface.
 
file  ecdsa.h
 Ecdsa interface.
 
file  ecdsa_sign.c
 EcdsaSignBuffer implementation.
 
file  ecdsa_verify.c
 EcdsaVerifyBuffer implementation.
 
file  ecgroup.c
 Elliptic curve group implementation.
 
file  ecgroup.h
 Elliptic curve group interface.
 
file  finitefield.c
 Finite field implementation.
 
file  finitefield.h
 Finite field interface.
 
file  hash.h
 Hash primitives.
 
file  pairing.c
 Pairing implementation.
 
file  pairing.h
 Pairing interface.
 
file  printutils.c
 Print helper implementation.
 
file  printutils.h
 Print helper interface.
 
file  sha256.c
 SHA256 implementation.
 
+

Detailed Description

+

Math primitives.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/dir_f6bef457d5f671b6e774bfccc16651f6.html b/sgx-jvm/linux-sgx/external/epid/doc/html/dir_f6bef457d5f671b6e774bfccc16651f6.html new file mode 100644 index 0000000000..9ce1d0c21e --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/dir_f6bef457d5f671b6e774bfccc16651f6.html @@ -0,0 +1,156 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common Directory Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
common Directory Reference
+
+
+ +

Common code shared between core sub-components.

+ +More...

+ + + + + +

+Directories

directory  math
 Math primitives.
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Files

file  bitsupplier.h
 Random data supplier interface.
 
file  commitment.c
 Commitment hash implementation.
 
file  commitment.h
 Commitment hash interface.
 
file  endian_convert.h
 Endianness conversion interface.
 
file  epid2params.c
 Intel(R) EPID 2.0 constant parameters implementation.
 
file  epid2params.h
 Intel(R) EPID 2.0 constant parameters interface.
 
file  epid2params_ate.inc
 Intel(R) EPID 2.0 constant parameters data.
 
file  errors.c
 Error reporting implementation.
 
file  errors.h
 Error reporting.
 
file  file_parser.c
 Implementation of issuer material file parsing utilities.
 
file  file_parser.h
 Epid issuer material parsing utilities.
 
file  grouppubkey.c
 Group public key implementation.
 
file  grouppubkey.h
 Group public key interface.
 
file  memory.c
 Memory access implementation.
 
file  memory.h
 Memory access interface.
 
file  sigrlvalid.c
 SigRl validity checking implementation.
 
file  sigrlvalid.h
 SigRl validity checking interface.
 
file  stack.c
 Stack container implementation.
 
file  stack.h
 Stack container interface.
 
file  stdtypes.h
 C99 standard data types.
 
file  types.h
 SDK data types.
 
+

Detailed Description

+

Common code shared between core sub-components.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/doc.png b/sgx-jvm/linux-sgx/external/epid/doc/html/doc.png new file mode 100644 index 0000000000..17edabff95 Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/doc.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/doxygen.css b/sgx-jvm/linux-sgx/external/epid/doc/html/doxygen.css new file mode 100644 index 0000000000..1425ec530d --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/doxygen.css @@ -0,0 +1,1475 @@ +/* The standard CSS for doxygen 1.8.11 */ + +body, table, div, p, dl { + font: 400 14px/22px Roboto,sans-serif; +} + +/* @group Heading Levels */ + +h1.groupheader { + font-size: 150%; +} + +.title { + font: 400 14px/28px Roboto,sans-serif; + font-size: 150%; + font-weight: bold; + margin: 10px 2px; +} + +h2.groupheader { + border-bottom: 1px solid #879ECB; + color: #354C7B; + font-size: 150%; + font-weight: normal; + margin-top: 1.75em; + padding-top: 8px; + padding-bottom: 4px; + width: 100%; +} + +h3.groupheader { + font-size: 100%; +} + +h1, h2, h3, h4, h5, h6 { + -webkit-transition: text-shadow 0.5s linear; + -moz-transition: text-shadow 0.5s linear; + -ms-transition: text-shadow 0.5s linear; + -o-transition: text-shadow 0.5s linear; + transition: text-shadow 0.5s linear; + margin-right: 15px; +} + +h1.glow, h2.glow, h3.glow, h4.glow, h5.glow, h6.glow { + text-shadow: 0 0 15px cyan; +} + +dt { + font-weight: bold; +} + +div.multicol { + -moz-column-gap: 1em; + -webkit-column-gap: 1em; + -moz-column-count: 3; + -webkit-column-count: 3; +} + +p.startli, p.startdd { + margin-top: 2px; +} + +p.starttd { + margin-top: 0px; +} + +p.endli { + margin-bottom: 0px; +} + +p.enddd { + margin-bottom: 4px; +} + +p.endtd { + margin-bottom: 2px; +} + +/* @end */ + +caption { + font-weight: bold; +} + +span.legend { + font-size: 70%; + text-align: center; +} + +h3.version { + font-size: 90%; + text-align: center; +} + +div.qindex, div.navtab{ + background-color: #EBEFF6; + border: 1px solid #A3B4D7; + text-align: center; +} + +div.qindex, div.navpath { + width: 100%; + line-height: 140%; +} + +div.navtab { + margin-right: 15px; +} + +/* @group Link Styling */ + +a { + color: #3D578C; + font-weight: normal; + text-decoration: none; +} + +.contents a:visited { + color: #4665A2; +} + +a:hover { + text-decoration: underline; +} + +a.qindex { + font-weight: bold; +} + +a.qindexHL { + font-weight: bold; + background-color: #9CAFD4; + color: #ffffff; + border: 1px double #869DCA; +} + +.contents a.qindexHL:visited { + color: #ffffff; +} + +a.el { + font-weight: bold; +} + +a.elRef { +} + +a.code, a.code:visited, a.line, a.line:visited { + color: #4665A2; +} + +a.codeRef, a.codeRef:visited, a.lineRef, a.lineRef:visited { + color: #4665A2; +} + +/* @end */ + +dl.el { + margin-left: -1cm; +} + +pre.fragment { + border: 1px solid #C4CFE5; + background-color: #FBFCFD; + padding: 4px 6px; + margin: 4px 8px 4px 2px; + overflow: auto; + word-wrap: break-word; + font-size: 9pt; + line-height: 125%; + font-family: monospace, fixed; + font-size: 105%; +} + +div.fragment { + padding: 4px 6px; + margin: 4px 8px 4px 2px; + background-color: #FBFCFD; + border: 1px solid #C4CFE5; +} + +div.line { + font-family: monospace, fixed; + font-size: 13px; + min-height: 13px; + line-height: 1.0; + text-wrap: unrestricted; + white-space: -moz-pre-wrap; /* Moz */ + white-space: -pre-wrap; /* Opera 4-6 */ + white-space: -o-pre-wrap; /* Opera 7 */ + white-space: pre-wrap; /* CSS3 */ + word-wrap: break-word; /* IE 5.5+ */ + text-indent: -53px; + padding-left: 53px; + padding-bottom: 0px; + margin: 0px; + -webkit-transition-property: background-color, box-shadow; + -webkit-transition-duration: 0.5s; + -moz-transition-property: background-color, box-shadow; + -moz-transition-duration: 0.5s; + -ms-transition-property: background-color, box-shadow; + -ms-transition-duration: 0.5s; + -o-transition-property: background-color, box-shadow; + -o-transition-duration: 0.5s; + transition-property: background-color, box-shadow; + transition-duration: 0.5s; +} + +div.line:after { + content:"\000A"; + white-space: pre; +} + +div.line.glow { + background-color: cyan; + box-shadow: 0 0 10px cyan; +} + + +span.lineno { + padding-right: 4px; + text-align: right; + border-right: 2px solid #0F0; + background-color: #E8E8E8; + white-space: pre; +} +span.lineno a { + background-color: #D8D8D8; +} + +span.lineno a:hover { + background-color: #C8C8C8; +} + +div.ah, span.ah { + background-color: black; + font-weight: bold; + color: #ffffff; + margin-bottom: 3px; + margin-top: 3px; + padding: 0.2em; + border: solid thin #333; + border-radius: 0.5em; + -webkit-border-radius: .5em; + -moz-border-radius: .5em; + box-shadow: 2px 2px 3px #999; + -webkit-box-shadow: 2px 2px 3px #999; + -moz-box-shadow: rgba(0, 0, 0, 0.15) 2px 2px 2px; + background-image: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#000),color-stop(0.3, #444)); + background-image: -moz-linear-gradient(center top, #eee 0%, #444 40%, #000 110%); +} + +div.classindex ul { + list-style: none; + padding-left: 0; +} + +div.classindex span.ai { + display: inline-block; +} + +div.groupHeader { + margin-left: 16px; + margin-top: 12px; + font-weight: bold; +} + +div.groupText { + margin-left: 16px; + font-style: italic; +} + +body { + background-color: white; + color: black; + margin: 0; +} + +div.contents { + margin-top: 10px; + margin-left: 12px; + margin-right: 8px; +} + +td.indexkey { + background-color: #EBEFF6; + font-weight: bold; + border: 1px solid #C4CFE5; + margin: 2px 0px 2px 0; + padding: 2px 10px; + white-space: nowrap; + vertical-align: top; +} + +td.indexvalue { + background-color: #EBEFF6; + border: 1px solid #C4CFE5; + padding: 2px 10px; + margin: 2px 0px; +} + +tr.memlist { + background-color: #EEF1F7; +} + +p.formulaDsp { + text-align: center; +} + +img.formulaDsp { + +} + +img.formulaInl { + vertical-align: middle; +} + +div.center { + text-align: center; + margin-top: 0px; + margin-bottom: 0px; + padding: 0px; +} + +div.center img { + border: 0px; +} + +address.footer { + text-align: right; + padding-right: 12px; +} + +img.footer { + border: 0px; + vertical-align: middle; +} + +/* @group Code Colorization */ + +span.keyword { + color: #008000 +} + +span.keywordtype { + color: #604020 +} + +span.keywordflow { + color: #e08000 +} + +span.comment { + color: #800000 +} + +span.preprocessor { + color: #806020 +} + +span.stringliteral { + color: #002080 +} + +span.charliteral { + color: #008080 +} + +span.vhdldigit { + color: #ff00ff +} + +span.vhdlchar { + color: #000000 +} + +span.vhdlkeyword { + color: #700070 +} + +span.vhdllogic { + color: #ff0000 +} + +blockquote { + background-color: #F7F8FB; + border-left: 2px solid #9CAFD4; + margin: 0 24px 0 4px; + padding: 0 12px 0 16px; +} + +/* @end */ + +/* +.search { + color: #003399; + font-weight: bold; +} + +form.search { + margin-bottom: 0px; + margin-top: 0px; +} + +input.search { + font-size: 75%; + color: #000080; + font-weight: normal; + background-color: #e8eef2; +} +*/ + +td.tiny { + font-size: 75%; +} + +.dirtab { + padding: 4px; + border-collapse: collapse; + border: 1px solid #A3B4D7; +} + +th.dirtab { + background: #EBEFF6; + font-weight: bold; +} + +hr { + height: 0px; + border: none; + border-top: 1px solid #4A6AAA; +} + +hr.footer { + height: 1px; +} + +/* @group Member Descriptions */ + +table.memberdecls { + border-spacing: 0px; + padding: 0px; +} + +.memberdecls td, .fieldtable tr { + -webkit-transition-property: background-color, box-shadow; + -webkit-transition-duration: 0.5s; + -moz-transition-property: background-color, box-shadow; + -moz-transition-duration: 0.5s; + -ms-transition-property: background-color, box-shadow; + -ms-transition-duration: 0.5s; + -o-transition-property: background-color, box-shadow; + -o-transition-duration: 0.5s; + transition-property: background-color, box-shadow; + transition-duration: 0.5s; +} + +.memberdecls td.glow, .fieldtable tr.glow { + background-color: cyan; + box-shadow: 0 0 15px cyan; +} + +.mdescLeft, .mdescRight, +.memItemLeft, .memItemRight, +.memTemplItemLeft, .memTemplItemRight, .memTemplParams { + background-color: #F9FAFC; + border: none; + margin: 4px; + padding: 1px 0 0 8px; +} + +.mdescLeft, .mdescRight { + padding: 0px 8px 4px 8px; + color: #555; +} + +.memSeparator { + border-bottom: 1px solid #DEE4F0; + line-height: 1px; + margin: 0px; + padding: 0px; +} + +.memItemLeft, .memTemplItemLeft { + white-space: nowrap; +} + +.memItemRight { + width: 100%; +} + +.memTemplParams { + color: #4665A2; + white-space: nowrap; + font-size: 80%; +} + +/* @end */ + +/* @group Member Details */ + +/* Styles for detailed member documentation */ + +.memtemplate { + font-size: 80%; + color: #4665A2; + font-weight: normal; + margin-left: 9px; +} + +.memnav { + background-color: #EBEFF6; + border: 1px solid #A3B4D7; + text-align: center; + margin: 2px; + margin-right: 15px; + padding: 2px; +} + +.mempage { + width: 100%; +} + +.memitem { + padding: 0; + margin-bottom: 10px; + margin-right: 5px; + -webkit-transition: box-shadow 0.5s linear; + -moz-transition: box-shadow 0.5s linear; + -ms-transition: box-shadow 0.5s linear; + -o-transition: box-shadow 0.5s linear; + transition: box-shadow 0.5s linear; + display: table !important; + width: 100%; +} + +.memitem.glow { + box-shadow: 0 0 15px cyan; +} + +.memname { + font-weight: bold; + margin-left: 6px; +} + +.memname td { + vertical-align: bottom; +} + +.memproto, dl.reflist dt { + border-top: 1px solid #A8B8D9; + border-left: 1px solid #A8B8D9; + border-right: 1px solid #A8B8D9; + padding: 6px 0px 6px 0px; + color: #253555; + font-weight: bold; + text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9); + background-image:url('nav_f.png'); + background-repeat:repeat-x; + background-color: #E2E8F2; + /* opera specific markup */ + box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); + border-top-right-radius: 4px; + border-top-left-radius: 4px; + /* firefox specific markup */ + -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px; + -moz-border-radius-topright: 4px; + -moz-border-radius-topleft: 4px; + /* webkit specific markup */ + -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); + -webkit-border-top-right-radius: 4px; + -webkit-border-top-left-radius: 4px; + +} + +.memdoc, dl.reflist dd { + border-bottom: 1px solid #A8B8D9; + border-left: 1px solid #A8B8D9; + border-right: 1px solid #A8B8D9; + padding: 6px 10px 2px 10px; + background-color: #FBFCFD; + border-top-width: 0; + background-image:url('nav_g.png'); + background-repeat:repeat-x; + background-color: #FFFFFF; + /* opera specific markup */ + border-bottom-left-radius: 4px; + border-bottom-right-radius: 4px; + box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); + /* firefox specific markup */ + -moz-border-radius-bottomleft: 4px; + -moz-border-radius-bottomright: 4px; + -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px; + /* webkit specific markup */ + -webkit-border-bottom-left-radius: 4px; + -webkit-border-bottom-right-radius: 4px; + -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); +} + +dl.reflist dt { + padding: 5px; +} + +dl.reflist dd { + margin: 0px 0px 10px 0px; + padding: 5px; +} + +.paramkey { + text-align: right; +} + +.paramtype { + white-space: nowrap; +} + +.paramname { + color: #602020; + white-space: nowrap; +} +.paramname em { + font-style: normal; +} +.paramname code { + line-height: 14px; +} + +.params, .retval, .exception, .tparams { + margin-left: 0px; + padding-left: 0px; +} + +.params .paramname, .retval .paramname { + font-weight: bold; + vertical-align: top; +} + +.params .paramtype { + font-style: italic; + vertical-align: top; +} + +.params .paramdir { + font-family: "courier new",courier,monospace; + vertical-align: top; +} + +table.mlabels { + border-spacing: 0px; +} + +td.mlabels-left { + width: 100%; + padding: 0px; +} + +td.mlabels-right { + vertical-align: bottom; + padding: 0px; + white-space: nowrap; +} + +span.mlabels { + margin-left: 8px; +} + +span.mlabel { + background-color: #728DC1; + border-top:1px solid #5373B4; + border-left:1px solid #5373B4; + border-right:1px solid #C4CFE5; + border-bottom:1px solid #C4CFE5; + text-shadow: none; + color: white; + margin-right: 4px; + padding: 2px 3px; + border-radius: 3px; + font-size: 7pt; + white-space: nowrap; + vertical-align: middle; +} + + + +/* @end */ + +/* these are for tree view inside a (index) page */ + +div.directory { + margin: 10px 0px; + border-top: 1px solid #9CAFD4; + border-bottom: 1px solid #9CAFD4; + width: 100%; +} + +.directory table { + border-collapse:collapse; +} + +.directory td { + margin: 0px; + padding: 0px; + vertical-align: top; +} + +.directory td.entry { + white-space: nowrap; + padding-right: 6px; + padding-top: 3px; +} + +.directory td.entry a { + outline:none; +} + +.directory td.entry a img { + border: none; +} + +.directory td.desc { + width: 100%; + padding-left: 6px; + padding-right: 6px; + padding-top: 3px; + border-left: 1px solid rgba(0,0,0,0.05); +} + +.directory tr.even { + padding-left: 6px; + background-color: #F7F8FB; +} + +.directory img { + vertical-align: -30%; +} + +.directory .levels { + white-space: nowrap; + width: 100%; + text-align: right; + font-size: 9pt; +} + +.directory .levels span { + cursor: pointer; + padding-left: 2px; + padding-right: 2px; + color: #3D578C; +} + +.arrow { + color: #9CAFD4; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + cursor: pointer; + font-size: 80%; + display: inline-block; + width: 16px; + height: 22px; +} + +.icon { + font-family: Arial, Helvetica; + font-weight: bold; + font-size: 12px; + height: 14px; + width: 16px; + display: inline-block; + background-color: #728DC1; + color: white; + text-align: center; + border-radius: 4px; + margin-left: 2px; + margin-right: 2px; +} + +.icona { + width: 24px; + height: 22px; + display: inline-block; +} + +.iconfopen { + width: 24px; + height: 18px; + margin-bottom: 4px; + background-image:url('folderopen.png'); + background-position: 0px -4px; + background-repeat: repeat-y; + vertical-align:top; + display: inline-block; +} + +.iconfclosed { + width: 24px; + height: 18px; + margin-bottom: 4px; + background-image:url('folderclosed.png'); + background-position: 0px -4px; + background-repeat: repeat-y; + vertical-align:top; + display: inline-block; +} + +.icondoc { + width: 24px; + height: 18px; + margin-bottom: 4px; + background-image:url('doc.png'); + background-position: 0px -4px; + background-repeat: repeat-y; + vertical-align:top; + display: inline-block; +} + +table.directory { + font: 400 14px Roboto,sans-serif; +} + +/* @end */ + +div.dynheader { + margin-top: 8px; + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +address { + font-style: normal; + color: #2A3D61; +} + +table.doxtable caption { + caption-side: top; +} + +table.doxtable { + border-collapse:collapse; + margin-top: 4px; + margin-bottom: 4px; +} + +table.doxtable td, table.doxtable th { + border: 1px solid #2D4068; + padding: 3px 7px 2px; +} + +table.doxtable th { + background-color: #374F7F; + color: #FFFFFF; + font-size: 110%; + padding-bottom: 4px; + padding-top: 5px; +} + +table.fieldtable { + /*width: 100%;*/ + margin-bottom: 10px; + border: 1px solid #A8B8D9; + border-spacing: 0px; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; + border-radius: 4px; + -moz-box-shadow: rgba(0, 0, 0, 0.15) 2px 2px 2px; + -webkit-box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.15); + box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.15); +} + +.fieldtable td, .fieldtable th { + padding: 3px 7px 2px; +} + +.fieldtable td.fieldtype, .fieldtable td.fieldname { + white-space: nowrap; + border-right: 1px solid #A8B8D9; + border-bottom: 1px solid #A8B8D9; + vertical-align: top; +} + +.fieldtable td.fieldname { + padding-top: 3px; +} + +.fieldtable td.fielddoc { + border-bottom: 1px solid #A8B8D9; + /*width: 100%;*/ +} + +.fieldtable td.fielddoc p:first-child { + margin-top: 0px; +} + +.fieldtable td.fielddoc p:last-child { + margin-bottom: 2px; +} + +.fieldtable tr:last-child td { + border-bottom: none; +} + +.fieldtable th { + background-image:url('nav_f.png'); + background-repeat:repeat-x; + background-color: #E2E8F2; + font-size: 90%; + color: #253555; + padding-bottom: 4px; + padding-top: 5px; + text-align:left; + -moz-border-radius-topleft: 4px; + -moz-border-radius-topright: 4px; + -webkit-border-top-left-radius: 4px; + -webkit-border-top-right-radius: 4px; + border-top-left-radius: 4px; + border-top-right-radius: 4px; + border-bottom: 1px solid #A8B8D9; +} + + +.tabsearch { + top: 0px; + left: 10px; + height: 36px; + background-image: url('tab_b.png'); + z-index: 101; + overflow: hidden; + font-size: 13px; +} + +.navpath ul +{ + font-size: 11px; + background-image:url('tab_b.png'); + background-repeat:repeat-x; + background-position: 0 -5px; + height:30px; + line-height:30px; + color:#8AA0CC; + border:solid 1px #C2CDE4; + overflow:hidden; + margin:0px; + padding:0px; +} + +.navpath li +{ + list-style-type:none; + float:left; + padding-left:10px; + padding-right:15px; + background-image:url('bc_s.png'); + background-repeat:no-repeat; + background-position:right; + color:#364D7C; +} + +.navpath li.navelem a +{ + height:32px; + display:block; + text-decoration: none; + outline: none; + color: #283A5D; + font-family: 'Lucida Grande',Geneva,Helvetica,Arial,sans-serif; + text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9); + text-decoration: none; +} + +.navpath li.navelem a:hover +{ + color:#6884BD; +} + +.navpath li.footer +{ + list-style-type:none; + float:right; + padding-left:10px; + padding-right:15px; + background-image:none; + background-repeat:no-repeat; + background-position:right; + color:#364D7C; + font-size: 8pt; +} + + +div.summary +{ + float: right; + font-size: 8pt; + padding-right: 5px; + width: 50%; + text-align: right; +} + +div.summary a +{ + white-space: nowrap; +} + +table.classindex +{ + margin: 10px; + white-space: nowrap; + margin-left: 3%; + margin-right: 3%; + width: 94%; + border: 0; + border-spacing: 0; + padding: 0; +} + +div.ingroups +{ + font-size: 8pt; + width: 50%; + text-align: left; +} + +div.ingroups a +{ + white-space: nowrap; +} + +div.header +{ + background-image:url('nav_h.png'); + background-repeat:repeat-x; + background-color: #F9FAFC; + margin: 0px; + border-bottom: 1px solid #C4CFE5; +} + +div.headertitle +{ + padding: 5px 5px 5px 10px; +} + +dl +{ + padding: 0 0 0 10px; +} + +/* dl.note, dl.warning, dl.attention, dl.pre, dl.post, dl.invariant, dl.deprecated, dl.todo, dl.test, dl.bug */ +dl.section +{ + margin-left: 0px; + padding-left: 0px; +} + +dl.note +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #D0C000; +} + +dl.warning, dl.attention +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #FF0000; +} + +dl.pre, dl.post, dl.invariant +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #00D000; +} + +dl.deprecated +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #505050; +} + +dl.todo +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #00C0E0; +} + +dl.test +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #3030E0; +} + +dl.bug +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #C08050; +} + +dl.section dd { + margin-bottom: 6px; +} + + +#projectlogo +{ + text-align: center; + vertical-align: bottom; + border-collapse: separate; +} + +#projectlogo img +{ + border: 0px none; +} + +#projectalign +{ + vertical-align: middle; +} + +#projectname +{ + font: 300% Tahoma, Arial,sans-serif; + margin: 0px; + padding: 2px 0px; +} + +#projectbrief +{ + font: 120% Tahoma, Arial,sans-serif; + margin: 0px; + padding: 0px; +} + +#projectnumber +{ + font: 50% Tahoma, Arial,sans-serif; + margin: 0px; + padding: 0px; +} + +#titlearea +{ + padding: 0px; + margin: 0px; + width: 100%; + border-bottom: 1px solid #5373B4; +} + +.image +{ + text-align: center; +} + +.dotgraph +{ + text-align: center; +} + +.mscgraph +{ + text-align: center; +} + +.diagraph +{ + text-align: center; +} + +.caption +{ + font-weight: bold; +} + +div.zoom +{ + border: 1px solid #90A5CE; +} + +dl.citelist { + margin-bottom:50px; +} + +dl.citelist dt { + color:#334975; + float:left; + font-weight:bold; + margin-right:10px; + padding:5px; +} + +dl.citelist dd { + margin:2px 0; + padding:5px 0; +} + +div.toc { + padding: 14px 25px; + background-color: #F4F6FA; + border: 1px solid #D8DFEE; + border-radius: 7px 7px 7px 7px; + float: right; + height: auto; + margin: 0 8px 10px 10px; + width: 200px; +} + +div.toc li { + background: url("bdwn.png") no-repeat scroll 0 5px transparent; + font: 10px/1.2 Verdana,DejaVu Sans,Geneva,sans-serif; + margin-top: 5px; + padding-left: 10px; + padding-top: 2px; +} + +div.toc h3 { + font: bold 12px/1.2 Arial,FreeSans,sans-serif; + color: #4665A2; + border-bottom: 0 none; + margin: 0; +} + +div.toc ul { + list-style: none outside none; + border: medium none; + padding: 0px; +} + +div.toc li.level1 { + margin-left: 0px; +} + +div.toc li.level2 { + margin-left: 15px; +} + +div.toc li.level3 { + margin-left: 30px; +} + +div.toc li.level4 { + margin-left: 45px; +} + +.inherit_header { + font-weight: bold; + color: gray; + cursor: pointer; + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.inherit_header td { + padding: 6px 0px 2px 5px; +} + +.inherit { + display: none; +} + +tr.heading h2 { + margin-top: 12px; + margin-bottom: 4px; +} + +/* tooltip related style info */ + +.ttc { + position: absolute; + display: none; +} + +#powerTip { + cursor: default; + white-space: nowrap; + background-color: white; + border: 1px solid gray; + border-radius: 4px 4px 4px 4px; + box-shadow: 1px 1px 7px gray; + display: none; + font-size: smaller; + max-width: 80%; + opacity: 0.9; + padding: 1ex 1em 1em; + position: absolute; + z-index: 2147483647; +} + +#powerTip div.ttdoc { + color: grey; + font-style: italic; +} + +#powerTip div.ttname a { + font-weight: bold; +} + +#powerTip div.ttname { + font-weight: bold; +} + +#powerTip div.ttdeci { + color: #006318; +} + +#powerTip div { + margin: 0px; + padding: 0px; + font: 12px/16px Roboto,sans-serif; +} + +#powerTip:before, #powerTip:after { + content: ""; + position: absolute; + margin: 0px; +} + +#powerTip.n:after, #powerTip.n:before, +#powerTip.s:after, #powerTip.s:before, +#powerTip.w:after, #powerTip.w:before, +#powerTip.e:after, #powerTip.e:before, +#powerTip.ne:after, #powerTip.ne:before, +#powerTip.se:after, #powerTip.se:before, +#powerTip.nw:after, #powerTip.nw:before, +#powerTip.sw:after, #powerTip.sw:before { + border: solid transparent; + content: " "; + height: 0; + width: 0; + position: absolute; +} + +#powerTip.n:after, #powerTip.s:after, +#powerTip.w:after, #powerTip.e:after, +#powerTip.nw:after, #powerTip.ne:after, +#powerTip.sw:after, #powerTip.se:after { + border-color: rgba(255, 255, 255, 0); +} + +#powerTip.n:before, #powerTip.s:before, +#powerTip.w:before, #powerTip.e:before, +#powerTip.nw:before, #powerTip.ne:before, +#powerTip.sw:before, #powerTip.se:before { + border-color: rgba(128, 128, 128, 0); +} + +#powerTip.n:after, #powerTip.n:before, +#powerTip.ne:after, #powerTip.ne:before, +#powerTip.nw:after, #powerTip.nw:before { + top: 100%; +} + +#powerTip.n:after, #powerTip.ne:after, #powerTip.nw:after { + border-top-color: #ffffff; + border-width: 10px; + margin: 0px -10px; +} +#powerTip.n:before { + border-top-color: #808080; + border-width: 11px; + margin: 0px -11px; +} +#powerTip.n:after, #powerTip.n:before { + left: 50%; +} + +#powerTip.nw:after, #powerTip.nw:before { + right: 14px; +} + +#powerTip.ne:after, #powerTip.ne:before { + left: 14px; +} + +#powerTip.s:after, #powerTip.s:before, +#powerTip.se:after, #powerTip.se:before, +#powerTip.sw:after, #powerTip.sw:before { + bottom: 100%; +} + +#powerTip.s:after, #powerTip.se:after, #powerTip.sw:after { + border-bottom-color: #ffffff; + border-width: 10px; + margin: 0px -10px; +} + +#powerTip.s:before, #powerTip.se:before, #powerTip.sw:before { + border-bottom-color: #808080; + border-width: 11px; + margin: 0px -11px; +} + +#powerTip.s:after, #powerTip.s:before { + left: 50%; +} + +#powerTip.sw:after, #powerTip.sw:before { + right: 14px; +} + +#powerTip.se:after, #powerTip.se:before { + left: 14px; +} + +#powerTip.e:after, #powerTip.e:before { + left: 100%; +} +#powerTip.e:after { + border-left-color: #ffffff; + border-width: 10px; + top: 50%; + margin-top: -10px; +} +#powerTip.e:before { + border-left-color: #808080; + border-width: 11px; + top: 50%; + margin-top: -11px; +} + +#powerTip.w:after, #powerTip.w:before { + right: 100%; +} +#powerTip.w:after { + border-right-color: #ffffff; + border-width: 10px; + top: 50%; + margin-top: -10px; +} +#powerTip.w:before { + border-right-color: #808080; + border-width: 11px; + top: 50%; + margin-top: -11px; +} + +@media print +{ + #top { display: none; } + #side-nav { display: none; } + #nav-path { display: none; } + body { overflow:visible; } + h1, h2, h3, h4, h5, h6 { page-break-after: avoid; } + .summary { display: none; } + .memitem { page-break-inside: avoid; } + #doc-content + { + margin-left:0 !important; + height:auto !important; + width:auto !important; + overflow:inherit; + display:inline; + } +} + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/doxygen.png b/sgx-jvm/linux-sgx/external/epid/doc/html/doxygen.png new file mode 100644 index 0000000000..3ff17d807f Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/doxygen.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/dynsections.js b/sgx-jvm/linux-sgx/external/epid/doc/html/dynsections.js new file mode 100644 index 0000000000..85e1836909 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/dynsections.js @@ -0,0 +1,97 @@ +function toggleVisibility(linkObj) +{ + var base = $(linkObj).attr('id'); + var summary = $('#'+base+'-summary'); + var content = $('#'+base+'-content'); + var trigger = $('#'+base+'-trigger'); + var src=$(trigger).attr('src'); + if (content.is(':visible')===true) { + content.hide(); + summary.show(); + $(linkObj).addClass('closed').removeClass('opened'); + $(trigger).attr('src',src.substring(0,src.length-8)+'closed.png'); + } else { + content.show(); + summary.hide(); + $(linkObj).removeClass('closed').addClass('opened'); + $(trigger).attr('src',src.substring(0,src.length-10)+'open.png'); + } + return false; +} + +function updateStripes() +{ + $('table.directory tr'). + removeClass('even').filter(':visible:even').addClass('even'); +} + +function toggleLevel(level) +{ + $('table.directory tr').each(function() { + var l = this.id.split('_').length-1; + var i = $('#img'+this.id.substring(3)); + var a = $('#arr'+this.id.substring(3)); + if (l + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/math/ecdsa.h File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
ecdsa.h File Reference
+
+
+ +

Ecdsa interface. +More...

+
#include <stddef.h>
+#include "epid/common/errors.h"
+#include "epid/common/types.h"
+#include "epid/common/bitsupplier.h"
+
+ + + + + + + +

+Functions

EpidStatus EcdsaVerifyBuffer (void const *buf, size_t buf_len, EcdsaPublicKey const *pubkey, EcdsaSignature const *sig)
 Verifies authenticity of a digital signature over a buffer. More...
 
EpidStatus EcdsaSignBuffer (void const *buf, size_t buf_len, EcdsaPrivateKey const *privkey, BitSupplier rnd_func, void *rnd_param, EcdsaSignature *sig)
 Creates ECDSA signature of buffer. More...
 
+

Detailed Description

+

Ecdsa interface.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/ecdsa__sign_8c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/ecdsa__sign_8c.html new file mode 100644 index 0000000000..a94a4c26c3 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/ecdsa__sign_8c.html @@ -0,0 +1,105 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/math/ecdsa_sign.c File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
ecdsa_sign.c File Reference
+
+
+ +

EcdsaSignBuffer implementation. +More...

+
#include "epid/common/math/ecdsa.h"
+#include "epid/common/math/bignum.h"
+#include "epid/common/math/bignum-internal.h"
+#include "epid/common/math/ecgroup.h"
+#include "epid/common/memory.h"
+#include "ext/ipp/include/ippcp.h"
+
+ + + + +

+Macros

+#define EPHKEYGEN_WATCHDOG   (10)
 The number of attempts to generate ephemeral key pair.
 
+ + + + +

+Functions

EpidStatus EcdsaSignBuffer (void const *buf, size_t buf_len, EcdsaPrivateKey const *privkey, BitSupplier rnd_func, void *rnd_param, EcdsaSignature *sig)
 Creates ECDSA signature of buffer. More...
 
+

Detailed Description

+

EcdsaSignBuffer implementation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/ecdsa__verify_8c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/ecdsa__verify_8c.html new file mode 100644 index 0000000000..bb97f4f4c2 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/ecdsa__verify_8c.html @@ -0,0 +1,133 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/math/ecdsa_verify.c File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
ecdsa_verify.c File Reference
+
+
+ +

EcdsaVerifyBuffer implementation. +More...

+
#include "epid/common/math/ecdsa.h"
+#include "epid/common/math/bignum.h"
+#include "epid/common/math/bignum-internal.h"
+#include "epid/common/memory.h"
+#include "ext/ipp/include/ippcp.h"
+
+ + + + +

+Macros

#define BREAK_ON_IPP_ERROR(sts, ret)
 Handle Ipp Errors with Break. More...
 
+ + + + +

+Functions

EpidStatus EcdsaVerifyBuffer (void const *buf, size_t buf_len, EcdsaPublicKey const *pubkey, EcdsaSignature const *sig)
 Verifies authenticity of a digital signature over a buffer. More...
 
+

Detailed Description

+

EcdsaVerifyBuffer implementation.

+

Macro Definition Documentation

+ +
+
+ + + + + + + + + + + + + + + + + + +
#define BREAK_ON_IPP_ERROR( sts,
 ret 
)
+
+Value:
{ \
IppStatus temp_sts = (sts); \
if (ippStsNoErr != temp_sts) { \
(ret) = kEpidMathErr; \
break; \
} \
}
internal math error
Definition: errors.h:53
+
+

Handle Ipp Errors with Break.

+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/ecgroup_8c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/ecgroup_8c.html new file mode 100644 index 0000000000..a59852ba8f --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/ecgroup_8c.html @@ -0,0 +1,222 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/math/ecgroup.c File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
ecgroup.c File Reference
+
+
+ +

Elliptic curve group implementation. +More...

+
#include <string.h>
+#include "epid/common/math/bignum-internal.h"
+#include "epid/common/math/ecgroup-internal.h"
+#include "epid/common/math/ecgroup.h"
+#include "epid/common/math/finitefield-internal.h"
+#include "epid/common/memory.h"
+#include "ext/ipp/include/ippcp.h"
+#include "ext/ipp/include/ippcpepid.h"
+
+ + + + +

+Macros

+#define EPID_ECHASH_WATCHDOG   (50)
 The number of attempts to hash a message to an element.
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

EpidStatus NewEcGroup (FiniteField const *ff, FfElement const *a, FfElement const *b, FfElement const *x, FfElement const *y, BigNum const *order, BigNum const *cofactor, EcGroup **g)
 Constructs a new EcGroup. More...
 
void DeleteEcGroup (EcGroup **g)
 Deletes a previously allocated EcGroup. More...
 
EpidStatus NewEcPoint (EcGroup const *g, EcPoint **p)
 Creates a new EcPoint. More...
 
void DeleteEcPoint (EcPoint **p)
 Deletes a previously allocated EcPoint. More...
 
EpidStatus eccontains (EcGroup *g, void const *p_str, size_t strlen, EcPoint *p, bool *in_group)
 Check and initialize element if it is in elliptic curve group. More...
 
EpidStatus ReadEcPoint (EcGroup *g, void const *p_str, size_t strlen, EcPoint *p)
 Deserializes an EcPoint from a string. More...
 
EpidStatus WriteEcPoint (EcGroup *g, EcPoint const *p, void *p_str, size_t strlen)
 Serializes an EcPoint to a string. More...
 
EpidStatus EcMul (EcGroup *g, EcPoint const *a, EcPoint const *b, EcPoint *r)
 Multiplies two elements in an elliptic curve group. More...
 
EpidStatus EcExp (EcGroup *g, EcPoint const *a, BigNumStr const *b, EcPoint *r)
 Raises a point in an elliptic curve group to a power. More...
 
EpidStatus EcSscmExp (EcGroup *g, EcPoint const *a, BigNumStr const *b, EcPoint *r)
 Software side-channel mitigated implementation of EcExp. More...
 
EpidStatus EcMultiExp (EcGroup *g, EcPoint const **a, BigNumStr const **b, size_t m, EcPoint *r)
 Multi-exponentiates elements in elliptic curve group. More...
 
EpidStatus EcSscmMultiExp (EcGroup *g, EcPoint const **a, BigNumStr const **b, size_t m, EcPoint *r)
 Software side-channel mitigated implementation of EcMultiExp. More...
 
EpidStatus EcGetRandom (EcGroup *g, BitSupplier rnd_func, void *rnd_func_param, EcPoint *r)
 Generates a random element from an elliptic curve group. More...
 
EpidStatus EcInGroup (EcGroup *g, void const *p_str, size_t strlen, bool *in_group)
 Checks if a point is in an elliptic curve group. More...
 
EpidStatus EcHash (EcGroup *g, void const *msg, size_t msg_len, HashAlg hash_alg, EcPoint *r)
 Hashes an arbitrary message to an element in an elliptic curve group. More...
 
EpidStatus EcMakePoint (EcGroup *g, FfElement const *x, EcPoint *r)
 Sets an EcPoint variable to a point on a curve. More...
 
EpidStatus EcInverse (EcGroup *g, EcPoint const *p, EcPoint *r)
 Computes the additive inverse of an EcPoint. More...
 
EpidStatus EcIsEqual (EcGroup *g, EcPoint const *a, EcPoint const *b, bool *is_equal)
 Checks if two EcPoints are equal. More...
 
EpidStatus EcIsIdentity (EcGroup *g, EcPoint const *p, bool *is_identity)
 Checks if an EcPoint is the identity element. More...
 
+

Detailed Description

+

Elliptic curve group implementation.

+

Function Documentation

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus eccontains (EcGroupg,
void const * p_str,
size_t strlen,
EcPointp,
boolin_group 
)
+
+ +

Check and initialize element if it is in elliptic curve group.

+

This is internal function. Takes a value p as input. If p is indeed an element of g, it outputs true, otherwise, it outputs false.

+

This is only used to check if input buffer are actually valid elements in group. If p is in g, this fills p and initializes it to internal FfElement format.

+
Parameters
+ + + + + + +
[in]gThe eliptic curve group in which to perform the check
[in]p_strSerialized eliptic curve group element to check
[in]strlenThe size of p_str in bytes.
[out]pDeserialized value of p_str
[out]in_groupResult of the check
+
+
+
Returns
EpidStatus
+
See also
NewEcPoint
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/ecgroup_8h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/ecgroup_8h.html new file mode 100644 index 0000000000..ebb7d5d214 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/ecgroup_8h.html @@ -0,0 +1,159 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/math/ecgroup.h File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
ecgroup.h File Reference
+
+
+ +

Elliptic curve group interface. +More...

+ + + + + + + + +

+Typedefs

+typedef struct EcGroup EcGroup
 Elliptic curve group over finite field.
 
+typedef struct EcPoint EcPoint
 Point on elliptic curve over finite field.
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

EpidStatus NewEcGroup (FiniteField const *ff, FfElement const *a, FfElement const *b, FfElement const *x, FfElement const *y, BigNum const *order, BigNum const *cofactor, EcGroup **g)
 Constructs a new EcGroup. More...
 
void DeleteEcGroup (EcGroup **g)
 Deletes a previously allocated EcGroup. More...
 
EpidStatus NewEcPoint (EcGroup const *g, EcPoint **p)
 Creates a new EcPoint. More...
 
void DeleteEcPoint (EcPoint **p)
 Deletes a previously allocated EcPoint. More...
 
EpidStatus ReadEcPoint (EcGroup *g, void const *p_str, size_t strlen, EcPoint *p)
 Deserializes an EcPoint from a string. More...
 
EpidStatus WriteEcPoint (EcGroup *g, EcPoint const *p, void *p_str, size_t strlen)
 Serializes an EcPoint to a string. More...
 
EpidStatus EcMul (EcGroup *g, EcPoint const *a, EcPoint const *b, EcPoint *r)
 Multiplies two elements in an elliptic curve group. More...
 
EpidStatus EcExp (EcGroup *g, EcPoint const *a, BigNumStr const *b, EcPoint *r)
 Raises a point in an elliptic curve group to a power. More...
 
EpidStatus EcSscmExp (EcGroup *g, EcPoint const *a, BigNumStr const *b, EcPoint *r)
 Software side-channel mitigated implementation of EcExp. More...
 
EpidStatus EcMultiExp (EcGroup *g, EcPoint const **a, BigNumStr const **b, size_t m, EcPoint *r)
 Multi-exponentiates elements in elliptic curve group. More...
 
EpidStatus EcSscmMultiExp (EcGroup *g, EcPoint const **a, BigNumStr const **b, size_t m, EcPoint *r)
 Software side-channel mitigated implementation of EcMultiExp. More...
 
EpidStatus EcGetRandom (EcGroup *g, BitSupplier rnd_func, void *rnd_func_param, EcPoint *r)
 Generates a random element from an elliptic curve group. More...
 
EpidStatus EcInGroup (EcGroup *g, void const *p_str, size_t strlen, bool *in_group)
 Checks if a point is in an elliptic curve group. More...
 
EpidStatus EcHash (EcGroup *g, void const *msg, size_t msg_len, HashAlg hash_alg, EcPoint *r)
 Hashes an arbitrary message to an element in an elliptic curve group. More...
 
EpidStatus EcMakePoint (EcGroup *g, FfElement const *x, EcPoint *r)
 Sets an EcPoint variable to a point on a curve. More...
 
EpidStatus EcInverse (EcGroup *g, EcPoint const *p, EcPoint *r)
 Computes the additive inverse of an EcPoint. More...
 
EpidStatus EcIsEqual (EcGroup *g, EcPoint const *a, EcPoint const *b, bool *is_equal)
 Checks if two EcPoints are equal. More...
 
EpidStatus EcIsIdentity (EcGroup *g, EcPoint const *p, bool *is_identity)
 Checks if an EcPoint is the identity element. More...
 
+

Detailed Description

+

Elliptic curve group interface.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/endian__convert_8h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/endian__convert_8h.html new file mode 100644 index 0000000000..5f089eb45b --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/endian__convert_8h.html @@ -0,0 +1,92 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/endian_convert.h File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
endian_convert.h File Reference
+
+
+ +

Endianness conversion interface. +More...

+
#include <stdint.h>
+
+ + + + +

+Macros

#define ntohl(u32)
 Macros to transform oct str 32 into uint_32. More...
 
+

Detailed Description

+

Endianness conversion interface.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/epid2params_8c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/epid2params_8c.html new file mode 100644 index 0000000000..8d24884ccc --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/epid2params_8c.html @@ -0,0 +1,98 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/epid2params.c File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
epid2params.c File Reference
+
+
+ +

Intel(R) EPID 2.0 constant parameters implementation. +More...

+ + + + + + + + +

+Functions

+EpidStatus NewFq6 (Epid2Params const *param, FiniteField *Fq2, FfElement *xi, FiniteField **Fq6)
 create a new Finite Field Fq6
 
void DeleteEpid2Params (Epid2Params_ **epid_params)
 Deallocates storage for internal representation of Epid2Params. More...
 
+

Detailed Description

+

Intel(R) EPID 2.0 constant parameters implementation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/epid2params_8h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/epid2params_8h.html new file mode 100644 index 0000000000..58c8eb3451 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/epid2params_8h.html @@ -0,0 +1,105 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/epid2params.h File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
epid2params.h File Reference
+
+
+ +

Intel(R) EPID 2.0 constant parameters interface. +More...

+ + + + + +

+Data Structures

struct  Epid2Params_
 Internal representation of Epid2Params. More...
 
+ + + + + + + +

+Functions

EpidStatus CreateEpid2Params (Epid2Params_ **params)
 Constructs the internal representation of Epid2Params. More...
 
void DeleteEpid2Params (Epid2Params_ **epid_params)
 Deallocates storage for internal representation of Epid2Params. More...
 
+

Detailed Description

+

Intel(R) EPID 2.0 constant parameters interface.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/epid2params__ate_8inc.html b/sgx-jvm/linux-sgx/external/epid/doc/html/epid2params__ate_8inc.html new file mode 100644 index 0000000000..b7168eae1f --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/epid2params__ate_8inc.html @@ -0,0 +1,82 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/epid2params_ate.inc File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
epid2params_ate.inc File Reference
+
+
+ +

Intel(R) EPID 2.0 constant parameters data. +More...

+

Detailed Description

+

Intel(R) EPID 2.0 constant parameters data.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/epid__overview_8dox.html b/sgx-jvm/linux-sgx/external/epid/doc/html/epid__overview_8dox.html new file mode 100644 index 0000000000..eefba2234f --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/epid__overview_8dox.html @@ -0,0 +1,82 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: doc/docsrc/epid_overview.dox File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
doc/docsrc/epid_overview.dox File Reference
+
+
+ +

This file is used by Doxygen to generate documentation. +More...

+

Detailed Description

+

This file is used by Doxygen to generate documentation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_high_level_interaction.png b/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_high_level_interaction.png new file mode 100644 index 0000000000..1013eb05f2 Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_high_level_interaction.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_high_level_use_case.png b/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_high_level_use_case.png new file mode 100644 index 0000000000..acc6374728 Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_high_level_use_case.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_issuer_high_level.png b/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_issuer_high_level.png new file mode 100644 index 0000000000..d03d6b9fdb Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_issuer_high_level.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_member_high_level.png b/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_member_high_level.png new file mode 100644 index 0000000000..58d784f413 Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_member_high_level.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_verifier_high_level.png b/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_verifier_high_level.png new file mode 100644 index 0000000000..bb92560c91 Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/epid_diagram_verifier_high_level.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/epidstyle.css b/sgx-jvm/linux-sgx/external/epid/doc/html/epidstyle.css new file mode 100644 index 0000000000..0ad7ff8689 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/epidstyle.css @@ -0,0 +1,325 @@ +.image { + text-align: left; +} +body { + color: #333333; + background-color: #ffffff; + font-family: Verdana, Arial, sans-serif; + font-size: 10pt; + margin-left: 0px; +} +h1 { + color: #0860a8; + font-size: 15pt; + padding-bottom: 1px; + margin-left: 0pt; + margin-bottom: 0px; + border-bottom: 1px solid #0860A8; + font-weight: normal; +} +h1.title { + border-bottom: 0 none; + margin-left: 0; + font-weight: normal; +} +h2 { + color: #0860a8; + font-weight: lighter; + margin-top: 5pt; + margin-bottom: 0; + font-size: 13pt; +} +h3 { + color: #333333; + font-weight: bold; + margin-top: 5pt; + margin-bottom: 0; + font-size: 11pt; +} +a:link { + color: #0860a8; + text-decoration: none; +} +a:visited { + color: #0860a8; + text-decoration: none; +} +a:active { + color: #0860a8; + text-decoration: underline; +} +a:hover { + color: #0860a8; + text-decoration: underline; +} +p { + font-size: inherit; + line-height: 120%; + margin-top: 0; + margin-bottom: 5pt; + font-family: Verdana, Arial, sans-serif; + font-size: 10pt; +} +blockquote { + margin-top: 0; + margin-bottom: 0; +} +HR { + color: #555555; + border: 0; + background: #555555; + height: 1px; + margin-left: 0; +} +p.Note { + margin-top: 0; + margin-left: 25px; + margin-bottom: 10pt; +} +h3.NoteTipHead { + color: #006699; + margin-top: 11pt; + padding-bottom: 0; + line-height: 18px; + text-transform: uppercase; +} +LI.h3-NoteTipHead { + color: #006699; + line-height: 18px; + text-transform: uppercase; +} +h3.NoteTipHead img { + vertical-align: middle; +} +/* +table { + margin-bottom: 5pt; + border-collapse: collapse; + margin-top: 0.3em; + font-size: 10pt; +} +tr { + vertical-align: top; +} +th { + padding: 4px; + text-align: left; + background-color: #555555; + font-weight: bold; + margin-top: 0; + margin-bottom: 0; + color: #ffffff; + font-size: 11pt; + border: 1px #bababa solid; +} +td { + border: 1px #bababa solid; + vertical-align: top; + font-size: 9pt; + margin-bottom: 0px; + margin-top: 0; + margin-left: 0; + padding: 0px; + text-align: left; +} +P.TableCell { + margin-top: 0; + margin-left: 4px; + padding: 0px; + margin-bottom: 0; + font-size: 9pt; + line-height: 120%; +} +td p { + margin-top: 0; + margin-left: 4; + padding: 0; + margin-bottom: 0; + text-align: left; + font-size: 9pt; + line-height: 120%; +} +td h3 { + margin-top: 0; + margin-left: 0; + padding: 0; + text-align: left; + font-size: inherit; + line-height: 120%; +} +td ul { + font-size: inherit; +} +td ol { + font-size: inherit; +} +td.noBorder { + border: 0px none; +} +h3.TableHead { + padding: 4px; + text-align: left; + background-color: #555555; + font-weight: bold; + margin-top: 0; + margin-bottom: 0; + color: #ffffff; + font-size: 11pt; +} +td table { + margin-left: 0; +} +*/ +ol { + margin-bottom: 1em; + font-size: inherit; + margin-top: 0px; + line-height: 100%; + list-style-type: decimal; +} +ol ol { + list-style: lower-alpha; + margin-bottom: 0em; + font-size: inherit; +} +ol ul { + margin-bottom: 0px; + font-size: inherit; +} +ol p { + margin-bottom: 0.2em; + margin-top: 0.2em; + margin-left: 0; + padding-left: 0; + font-size: inherit; +} +ol.Note { + margin-left: 25px; +} +ul { + margin-bottom: 1em; + font-size: inherit; + margin-top: 0px; + line-height: 100%; +} +ul p { + margin-bottom: 0.2em; + margin-top: 0.2em; + margin-left: 0; + padding-left: 0; + font-size: inherit; +} +ul ol { + margin-bottom: 0em; + font-size: inherit; + list-style-type: decimal; +} +ul ul { + margin-bottom: 0px; + font-size: inherit; +} +ul.Note { + margin-left: 25px; +} +li { + font-size: inherit; + margin-top: 0px; + line-height: 130%; +} +li p { + margin-bottom: 0.2em; + margin-top: 0.2em; + margin-left: 0; + padding-left: 0; + font-size: inherit; +} +p.twoColumnListHead { + color: #000000; + margin-top: 0; + margin-bottom: 0; + font-weight: bold; +} +dl { + margin-bottom: 1em; + font-size: inherit; + margin-top: 0px; +} +dt { + font-weight: bold; + margin-top: 1em; +} +dd { + font-size: inherit; + margin-top: 0; +} +dd p { + margin-bottom: 0.2em; + margin-top: 0.2em; + font-size: inherit; +} +p.pRelatedLink { + margin-top: 0px; + margin-bottom: 0px; +} +SPAN.Code { + font-family: "Courier New", Courier, monospace; +} +span.Variable { + font-family: Courier, monospace; + font-style: italic; +} +SPAN.Superscript { + vertical-align: top; + font-size: 80%; +} +SPAN.Color { + color: #6C9A65; +} +SPAN.Color2 { + color: #0860a8; +} +SPAN.Color3 { + color: #fd0b01; +} +SPAN.Color4 { + color: #f8aa06; +} +.Code { + font-family: "Courier New", Courier, monospace; + background-color: #eeeeee; +} +.link_buttons { + background-color: #EEEEEE; + border-color: #EEEEEE; + border-width: 1px; + padding: 4px; +} +.Color { + color: #6C9A65; +} +.Preformatted { + x-text-tab-stops: repeat 1in; + margin-top: 0; + margin-bottom: 0; + font-size: 10pt; + font-family: "Courier New", Courier, monospace; + background-color: #eeeeee; +} + +/* Hide top level nav-tree node */ +#nav-tree-contents > ul > li > div { + display: none; +} + +/* Shift remaining nav-tree nodes left */ +#nav-tree-contents > ul { + margin: 0; + padding: 0; + margin-left: -16px; + margin-top: -2em; /* nav-tree hack*/ +} + +#projectlink { + color:inherit; + text-decoration:none; +} \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/errors_8c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/errors_8c.html new file mode 100644 index 0000000000..ce82948c36 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/errors_8c.html @@ -0,0 +1,101 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/errors.c File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
errors.c File Reference
+
+
+ +

Error reporting implementation. +More...

+
#include <stddef.h>
+#include "epid/common/stdtypes.h"
+#include "epid/common/errors.h"
+
+ + + + +

+Data Structures

struct  ErrorTextEntry
 Record mapping status code to string. More...
 
+ + + + +

+Functions

char const * EpidStatusToString (EpidStatus e)
 Returns string representation of error code. More...
 
+

Detailed Description

+

Error reporting implementation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/errors_8h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/errors_8h.html new file mode 100644 index 0000000000..7b8a7f8697 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/errors_8h.html @@ -0,0 +1,122 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/errors.h File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
errors.h File Reference
+
+
+ +

Error reporting. +More...

+ + + + + +

+Enumerations

enum  EpidStatus {
+  kEpidNoErr = 0, +kEpidSigValid = 0, +kEpidSigInvalid = 1, +kEpidSigRevokedinGroupRl = 2, +
+  kEpidSigRevokedinPrivRl = 3, +kEpidSigRevokedinSigRl = 4, +kEpidSigRevokedinVerifierRl = 5, +kEpidErr = -999, +
+  kEpidNotImpl, +kEpidBadArgErr, +kEpidNoMemErr, +kEpidMemAllocErr, +
+  kEpidMathErr, +kEpidDivByZeroErr, +kEpidUnderflowErr, +kEpidHashAlgorithmNotSupported, +
+  kEpidRandMaxIterErr, +kEpidDuplicateErr +
+ }
 Return status for SDK functions. More...
 
+ + + + +

+Functions

char const * EpidStatusToString (EpidStatus e)
 Returns string representation of error code. More...
 
+

Detailed Description

+

Error reporting.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/examples.html b/sgx-jvm/linux-sgx/external/epid/doc/html/examples.html new file mode 100644 index 0000000000..f2de4e678e --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/examples.html @@ -0,0 +1,82 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Examples + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
Examples
+
+
+
Here is a list of all examples:
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/examples.js b/sgx-jvm/linux-sgx/external/epid/doc/html/examples.js new file mode 100644 index 0000000000..cdfa35393e --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/examples.js @@ -0,0 +1,5 @@ +var examples = +[ + [ "signmsg.c", "signmsg_8c-example.html", null ], + [ "verifysig.c", "verifysig_8c-example.html", null ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/examples_8dox.html b/sgx-jvm/linux-sgx/external/epid/doc/html/examples_8dox.html new file mode 100644 index 0000000000..7f8829a3bb --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/examples_8dox.html @@ -0,0 +1,82 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: doc/docsrc/examples.dox File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
doc/docsrc/examples.dox File Reference
+
+
+ +

This file is used by Doxygen to generate documentation. +More...

+

Detailed Description

+

This file is used by Doxygen to generate documentation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/file__parser_8c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/file__parser_8c.html new file mode 100644 index 0000000000..befa225f71 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/file__parser_8c.html @@ -0,0 +1,118 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/file_parser.c File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
file_parser.c File Reference
+
+
+ +

Implementation of issuer material file parsing utilities. +More...

+
#include "epid/common/file_parser.h"
+#include <string.h>
+#include "epid/common/math/ecdsa.h"
+#include "epid/common/memory.h"
+
+ + + + +

+Data Structures

struct  EpidGroupPubKeyCertificate
 Intel(R) EPID 2.0 Group Public Key binary format. More...
 
+ + + + + + + + + + + + + +

+Functions

EpidStatus EpidParseGroupPubKeyFile (void const *buf, size_t len, EpidCaCertificate const *cert, GroupPubKey *pubkey)
 Extracts group public key from buffer in issuer binary format. More...
 
EpidStatus EpidParsePrivRlFile (void const *buf, size_t len, EpidCaCertificate const *cert, PrivRl *rl, size_t *rl_len)
 Extracts private key revocation list from buffer in issuer binary format. More...
 
EpidStatus EpidParseSigRlFile (void const *buf, size_t len, EpidCaCertificate const *cert, SigRl *rl, size_t *rl_len)
 Extracts signature revocation list from buffer in issuer binary format. More...
 
EpidStatus EpidParseGroupRlFile (void const *buf, size_t len, EpidCaCertificate const *cert, GroupRl *rl, size_t *rl_len)
 Extracts group revocation list from buffer in issuer binary format. More...
 
+ + + + +

+Variables

const OctStr16 kEpidFileTypeCode [kNumFileTypes]
 Encoding of issuer material file types. More...
 
+

Detailed Description

+

Implementation of issuer material file parsing utilities.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/file__parser_8h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/file__parser_8h.html new file mode 100644 index 0000000000..b87ad4cac5 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/file__parser_8h.html @@ -0,0 +1,141 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/file_parser.h File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
file_parser.h File Reference
+
+
+ +

Epid issuer material parsing utilities. +More...

+
#include <stddef.h>
+#include "epid/common/types.h"
+#include "epid/common/errors.h"
+
+ + + + + + + +

+Data Structures

struct  EpidFileHeader
 Intel(R) EPID binary file header. More...
 
struct  EpidCaCertificate
 IoT CA Certificate binary format. More...
 
+ + + + +

+Enumerations

enum  EpidFileType {
+  kIssuingCaPubKeyFile, +kGroupPubKeyFile, +kPrivRlFile, +kSigRlFile, +
+  kGroupRlFile, +kPrivRlRequestFile, +kSigRlRequestFile, +kGroupRlRequestFile, +
+  kNumFileTypes +
+ }
 Recognized Intel(R) EPID file types. More...
 
+ + + + + + + + + + + + + +

+Functions

EpidStatus EpidParseGroupPubKeyFile (void const *buf, size_t len, EpidCaCertificate const *cert, GroupPubKey *pubkey)
 Extracts group public key from buffer in issuer binary format. More...
 
EpidStatus EpidParsePrivRlFile (void const *buf, size_t len, EpidCaCertificate const *cert, PrivRl *rl, size_t *rl_len)
 Extracts private key revocation list from buffer in issuer binary format. More...
 
EpidStatus EpidParseSigRlFile (void const *buf, size_t len, EpidCaCertificate const *cert, SigRl *rl, size_t *rl_len)
 Extracts signature revocation list from buffer in issuer binary format. More...
 
EpidStatus EpidParseGroupRlFile (void const *buf, size_t len, EpidCaCertificate const *cert, GroupRl *rl, size_t *rl_len)
 Extracts group revocation list from buffer in issuer binary format. More...
 
+ + + + +

+Variables

+const OctStr16 kEpidFileTypeCode [kNumFileTypes]
 Encoding of issuer material file types.
 
+

Detailed Description

+

Epid issuer material parsing utilities.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/files.html b/sgx-jvm/linux-sgx/external/epid/doc/html/files.html new file mode 100644 index 0000000000..9da5d546e4 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/files.html @@ -0,0 +1,141 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: File List + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
File List
+
+
+
Here is a list of all documented files with brief descriptions:
+
[detail level 1234]
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  epidCore Intel® EPID functionality
  commonCommon code shared between core sub-components
  mathMath primitives
 bignum.cBig number implementation
 bignum.hBig number interface
 ecdsa.hEcdsa interface
 ecdsa_sign.cEcdsaSignBuffer implementation
 ecdsa_verify.cEcdsaVerifyBuffer implementation
 ecgroup.cElliptic curve group implementation
 ecgroup.hElliptic curve group interface
 finitefield.cFinite field implementation
 finitefield.hFinite field interface
 hash.hHash primitives
 pairing.cPairing implementation
 pairing.hPairing interface
 printutils.cPrint helper implementation
 printutils.hPrint helper interface
 sha256.cSHA256 implementation
 bitsupplier.hRandom data supplier interface
 commitment.cCommitment hash implementation
 commitment.hCommitment hash interface
 endian_convert.hEndianness conversion interface
 epid2params.cIntel(R) EPID 2.0 constant parameters implementation
 epid2params.hIntel(R) EPID 2.0 constant parameters interface
 epid2params_ate.incIntel(R) EPID 2.0 constant parameters data
 errors.cError reporting implementation
 errors.hError reporting
 file_parser.cImplementation of issuer material file parsing utilities
 file_parser.hEpid issuer material parsing utilities
 grouppubkey.cGroup public key implementation
 grouppubkey.hGroup public key interface
 memory.cMemory access implementation
 memory.hMemory access interface
 sigrlvalid.cSigRl validity checking implementation
 sigrlvalid.hSigRl validity checking interface
 stack.cStack container implementation
 stack.hStack container interface
 stdtypes.hC99 standard data types
 types.hSDK data types
  memberMember functionality
 api.hIntel(R) EPID SDK member API
 context.cMember context implementation
 context.hMember context interface
 decompress_privkey.cEpidDecompressPrivKey implementation
 get_sigsize.cEpidGetSigSize implementation
 nr_prove.cEpidNrProve implementation
 presig.cEpidComputePreSig implementation
 privkey.cPrivate key implementation
 privkey.hPrivate key private interface
 request_join.cEpidRequestJoin implementation
 sign.cEpidSign implementation
 signbasic.cEpidSignBasic implementation
  verifierVerifier functionality
 api.hIntel(R) EPID SDK verifier API
 check_privrl_entry.cEpidCheckPrivRlEntry implementation
 context.cVerifier context implementation
 context.hVerifier context interface
 nrverify.cNrVerfy implementation
 sigs_linked.cAreSigsLinked implementation
 verify.cVerify implementation
 verifybasic.cVerifyBasicSig implementation
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/finitefield_8c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/finitefield_8c.html new file mode 100644 index 0000000000..da6975291f --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/finitefield_8c.html @@ -0,0 +1,162 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/math/finitefield.c File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
finitefield.c File Reference
+
+
+ +

Finite field implementation. +More...

+
#include <limits.h>
+#include <string.h>
+#include "epid/common/math/finitefield.h"
+#include "epid/common/math/bignum-internal.h"
+#include "epid/common/math/finitefield-internal.h"
+#include "epid/common/memory.h"
+#include "ext/ipp/include/ippcp.h"
+#include "ext/ipp/include/ippcpepid.h"
+
+ + + + +

+Macros

+#define RNG_WATCHDOG   (10)
 Number of tries for RNG.
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

+EpidStatus InitFiniteFieldFromIpp (IppsGFpState *ipp_ff, FiniteField *ff)
 Initializes a FiniteField structure.
 
EpidStatus NewFiniteField (BigNumStr const *prime, FiniteField **ff)
 Creates new finite field. More...
 
EpidStatus NewFiniteFieldViaBinomalExtension (FiniteField const *ground_field, FfElement const *ground_element, int degree, FiniteField **ff)
 Creates a new finite field using binomial extension. More...
 
void DeleteFiniteField (FiniteField **ff)
 Frees a previously allocated FiniteField. More...
 
EpidStatus NewFfElement (FiniteField const *ff, FfElement **new_ff_elem)
 Creates a new finite field element. More...
 
void DeleteFfElement (FfElement **ff_elem)
 Frees a previously allocated FfElement. More...
 
EpidStatus ReadFfElement (FiniteField *ff, void const *ff_elem_str, size_t strlen, FfElement *ff_elem)
 Deserializes a FfElement from a string. More...
 
EpidStatus WriteFfElement (FiniteField *ff, FfElement const *ff_elem, void *ff_elem_str, size_t strlen)
 Serializes a finite field element to a string. More...
 
EpidStatus FfNeg (FiniteField *ff, FfElement const *a, FfElement *r)
 Calculates the additive inverse of a finite field element. More...
 
EpidStatus FfInv (FiniteField *ff, FfElement const *a, FfElement *r)
 Calculates the multiplicative inverse of a finite field element. More...
 
EpidStatus FfAdd (FiniteField *ff, FfElement const *a, FfElement const *b, FfElement *r)
 Adds two finite field elements. More...
 
EpidStatus FfMul (FiniteField *ff, FfElement const *a, FfElement const *b, FfElement *r)
 Multiplies two finite field elements. More...
 
EpidStatus FfIsZero (FiniteField *ff, FfElement const *a, bool *is_zero)
 Checks if given finite field element is the additive identity (zero). More...
 
EpidStatus FfExp (FiniteField *ff, FfElement const *a, BigNum const *b, FfElement *r)
 Raises an element of a finite field to a power. More...
 
EpidStatus FfMultiExp (FiniteField *ff, FfElement const **p, BigNumStr const **b, size_t m, FfElement *r)
 Multi-exponentiates finite field elements. More...
 
EpidStatus FfSscmMultiExp (FiniteField *ff, FfElement const **p, BigNumStr const **b, size_t m, FfElement *r)
 Software side-channel mitigated implementation of FfMultiExp. More...
 
EpidStatus FfIsEqual (FiniteField *ff, FfElement const *a, FfElement const *b, bool *is_equal)
 Checks if two finite field elements are equal. More...
 
EpidStatus FfHash (FiniteField *ff, void const *msg, size_t msg_len, HashAlg hash_alg, FfElement *r)
 Hashes an arbitrary message to an element in a finite field. More...
 
EpidStatus FfGetRandom (FiniteField *ff, BigNumStr const *low_bound, BitSupplier rnd_func, void *rnd_param, FfElement *r)
 Generate random finite field element. More...
 
+

Detailed Description

+

Finite field implementation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/finitefield_8h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/finitefield_8h.html new file mode 100644 index 0000000000..b966a52228 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/finitefield_8h.html @@ -0,0 +1,159 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/math/finitefield.h File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
finitefield.h File Reference
+
+
+ +

Finite field interface. +More...

+ + + + + + + + +

+Typedefs

+typedef struct FiniteField FiniteField
 A finite field.
 
+typedef struct FfElement FfElement
 An element in a finite field.
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

EpidStatus NewFiniteField (BigNumStr const *prime, FiniteField **ff)
 Creates new finite field. More...
 
EpidStatus NewFiniteFieldViaBinomalExtension (FiniteField const *ground_field, FfElement const *ground_element, int degree, FiniteField **ff)
 Creates a new finite field using binomial extension. More...
 
void DeleteFiniteField (FiniteField **ff)
 Frees a previously allocated FiniteField. More...
 
EpidStatus NewFfElement (FiniteField const *ff, FfElement **new_ff_elem)
 Creates a new finite field element. More...
 
void DeleteFfElement (FfElement **ff_elem)
 Frees a previously allocated FfElement. More...
 
EpidStatus ReadFfElement (FiniteField *ff, void const *ff_elem_str, size_t strlen, FfElement *ff_elem)
 Deserializes a FfElement from a string. More...
 
EpidStatus WriteFfElement (FiniteField *ff, FfElement const *ff_elem, void *ff_elem_str, size_t strlen)
 Serializes a finite field element to a string. More...
 
EpidStatus FfNeg (FiniteField *ff, FfElement const *a, FfElement *r)
 Calculates the additive inverse of a finite field element. More...
 
EpidStatus FfInv (FiniteField *ff, FfElement const *a, FfElement *r)
 Calculates the multiplicative inverse of a finite field element. More...
 
EpidStatus FfAdd (FiniteField *ff, FfElement const *a, FfElement const *b, FfElement *r)
 Adds two finite field elements. More...
 
EpidStatus FfMul (FiniteField *ff, FfElement const *a, FfElement const *b, FfElement *r)
 Multiplies two finite field elements. More...
 
EpidStatus FfIsZero (FiniteField *ff, FfElement const *a, bool *is_zero)
 Checks if given finite field element is the additive identity (zero). More...
 
EpidStatus FfExp (FiniteField *ff, FfElement const *a, BigNum const *b, FfElement *r)
 Raises an element of a finite field to a power. More...
 
EpidStatus FfMultiExp (FiniteField *ff, FfElement const **a, BigNumStr const **b, size_t m, FfElement *r)
 Multi-exponentiates finite field elements. More...
 
EpidStatus FfSscmMultiExp (FiniteField *ff, FfElement const **a, BigNumStr const **b, size_t m, FfElement *r)
 Software side-channel mitigated implementation of FfMultiExp. More...
 
EpidStatus FfIsEqual (FiniteField *ff, FfElement const *a, FfElement const *b, bool *is_equal)
 Checks if two finite field elements are equal. More...
 
EpidStatus FfHash (FiniteField *ff, void const *msg, size_t msg_len, HashAlg hash_alg, FfElement *r)
 Hashes an arbitrary message to an element in a finite field. More...
 
EpidStatus FfGetRandom (FiniteField *ff, BigNumStr const *low_bound, BitSupplier rnd_func, void *rnd_param, FfElement *r)
 Generate random finite field element. More...
 
+

Detailed Description

+

Finite field interface.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/folderclosed.png b/sgx-jvm/linux-sgx/external/epid/doc/html/folderclosed.png new file mode 100644 index 0000000000..bb8ab35edc Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/folderclosed.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/folderopen.png b/sgx-jvm/linux-sgx/external/epid/doc/html/folderopen.png new file mode 100644 index 0000000000..d6c7f676a3 Binary files /dev/null and b/sgx-jvm/linux-sgx/external/epid/doc/html/folderopen.png differ diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions.html new file mode 100644 index 0000000000..e284cced9a --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions.html @@ -0,0 +1,98 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- a -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_b.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_b.html new file mode 100644 index 0000000000..a2e57488e9 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_b.html @@ -0,0 +1,107 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- b -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_c.html new file mode 100644 index 0000000000..e373d8a1e1 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_c.html @@ -0,0 +1,85 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- c -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_d.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_d.html new file mode 100644 index 0000000000..48a9295861 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_d.html @@ -0,0 +1,90 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- d -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_e.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_e.html new file mode 100644 index 0000000000..89b95e91a6 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_e.html @@ -0,0 +1,112 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- e -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_f.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_f.html new file mode 100644 index 0000000000..72d55950ca --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_f.html @@ -0,0 +1,100 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- f -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_g.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_g.html new file mode 100644 index 0000000000..edb3cd466b --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_g.html @@ -0,0 +1,122 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- g -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_h.html new file mode 100644 index 0000000000..dcb325c8ae --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_h.html @@ -0,0 +1,98 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- h -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_k.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_k.html new file mode 100644 index 0000000000..fdf2abced7 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_k.html @@ -0,0 +1,95 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- k -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_l.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_l.html new file mode 100644 index 0000000000..9c72e634d0 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_l.html @@ -0,0 +1,79 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- l -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_m.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_m.html new file mode 100644 index 0000000000..8d86dd4814 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_m.html @@ -0,0 +1,82 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- m -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_n.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_n.html new file mode 100644 index 0000000000..23782aac09 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_n.html @@ -0,0 +1,102 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- n -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_p.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_p.html new file mode 100644 index 0000000000..8355af16e5 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_p.html @@ -0,0 +1,105 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- p -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_q.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_q.html new file mode 100644 index 0000000000..ea64bc38f2 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_q.html @@ -0,0 +1,80 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- q -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_r.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_r.html new file mode 100644 index 0000000000..313ae27a04 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_r.html @@ -0,0 +1,121 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- r -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_s.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_s.html new file mode 100644 index 0000000000..671de83346 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_s.html @@ -0,0 +1,113 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- s -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_t.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_t.html new file mode 100644 index 0000000000..d845079562 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_t.html @@ -0,0 +1,99 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- t -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_v.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_v.html new file mode 100644 index 0000000000..590391966a --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_v.html @@ -0,0 +1,88 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- v -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars.html new file mode 100644 index 0000000000..445df8d494 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars.html @@ -0,0 +1,98 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- a -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_b.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_b.html new file mode 100644 index 0000000000..d19d2371e7 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_b.html @@ -0,0 +1,107 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- b -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_c.html new file mode 100644 index 0000000000..0225552d3a --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_c.html @@ -0,0 +1,85 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- c -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_d.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_d.html new file mode 100644 index 0000000000..5887dbfcd7 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_d.html @@ -0,0 +1,90 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+ +
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_e.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_e.html new file mode 100644 index 0000000000..81b785fd71 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_e.html @@ -0,0 +1,112 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- e -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_f.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_f.html new file mode 100644 index 0000000000..a9cdb55eb9 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_f.html @@ -0,0 +1,100 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- f -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_g.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_g.html new file mode 100644 index 0000000000..fc37948c73 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_g.html @@ -0,0 +1,122 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ + + + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_h.html new file mode 100644 index 0000000000..53e982ccb1 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_h.html @@ -0,0 +1,98 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ + + + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_k.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_k.html new file mode 100644 index 0000000000..84e55cd6b7 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_k.html @@ -0,0 +1,95 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- k -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_l.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_l.html new file mode 100644 index 0000000000..b5eef3e5df --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_l.html @@ -0,0 +1,79 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- l -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_m.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_m.html new file mode 100644 index 0000000000..58b6aa8a09 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_m.html @@ -0,0 +1,82 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- m -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_n.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_n.html new file mode 100644 index 0000000000..b154f6685e --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_n.html @@ -0,0 +1,102 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- n -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_p.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_p.html new file mode 100644 index 0000000000..03f386e990 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_p.html @@ -0,0 +1,105 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- p -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_q.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_q.html new file mode 100644 index 0000000000..ae5b02c099 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_q.html @@ -0,0 +1,80 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- q -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_r.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_r.html new file mode 100644 index 0000000000..a9c20fb040 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_r.html @@ -0,0 +1,121 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- r -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_s.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_s.html new file mode 100644 index 0000000000..e6a4e85a9d --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_s.html @@ -0,0 +1,113 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- s -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_t.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_t.html new file mode 100644 index 0000000000..6a1d6689e8 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_t.html @@ -0,0 +1,99 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- t -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_v.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_v.html new file mode 100644 index 0000000000..63566534eb --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_v.html @@ -0,0 +1,88 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- v -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_w.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_w.html new file mode 100644 index 0000000000..4034b01b6a --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_w.html @@ -0,0 +1,83 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ + + + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_x.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_x.html new file mode 100644 index 0000000000..17d2cc60bc --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_x.html @@ -0,0 +1,95 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ + + + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_y.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_y.html new file mode 100644 index 0000000000..96f739bfab --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_vars_y.html @@ -0,0 +1,83 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields - Variables + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- y -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_w.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_w.html new file mode 100644 index 0000000000..8c463abed0 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_w.html @@ -0,0 +1,83 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- w -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_x.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_x.html new file mode 100644 index 0000000000..e54c6ebf5f --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_x.html @@ -0,0 +1,95 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- x -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/functions_y.html b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_y.html new file mode 100644 index 0000000000..47cbd2d3d1 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/functions_y.html @@ -0,0 +1,83 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Data Fields + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
+ +

- y -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/get__sigsize_8c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/get__sigsize_8c.html new file mode 100644 index 0000000000..e1196acb68 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/get__sigsize_8c.html @@ -0,0 +1,93 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/member/get_sigsize.c File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
get_sigsize.c File Reference
+
+
+ +

EpidGetSigSize implementation. +More...

+ + + + + +

+Functions

size_t EpidGetSigSize (SigRl const *sig_rl)
 Computes the size in bytes required for a Intel(R) EPID signature. More...
 
+

Detailed Description

+

EpidGetSigSize implementation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals.html new file mode 100644 index 0000000000..85cb8704c3 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals.html @@ -0,0 +1,80 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- a -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_b.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_b.html new file mode 100644 index 0000000000..82c9bd3dc3 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_b.html @@ -0,0 +1,119 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- b -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_c.html new file mode 100644 index 0000000000..a3ef228d2e --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_c.html @@ -0,0 +1,104 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- c -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_d.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_d.html new file mode 100644 index 0000000000..48bbd7ba26 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_d.html @@ -0,0 +1,120 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- d -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_defs.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_defs.html new file mode 100644 index 0000000000..63b1b750d1 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_defs.html @@ -0,0 +1,197 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- b -

+ + +

- c -

+ + +

- e -

+ + +

- f -

+ + +

- i -

+ + +

- m -

+ + +

- n -

+ + +

- p -

+ + +

- r -

+ + +

- s -

+ + +

- t -

+ + +

- w -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_e.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_e.html new file mode 100644 index 0000000000..a2efb894bf --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_e.html @@ -0,0 +1,308 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- e -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_enum.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_enum.html new file mode 100644 index 0000000000..9054ce7352 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_enum.html @@ -0,0 +1,86 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_eval.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_eval.html new file mode 100644 index 0000000000..4e265cb3f6 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_eval.html @@ -0,0 +1,184 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- k -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_f.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_f.html new file mode 100644 index 0000000000..7b7f7bfb4d --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_f.html @@ -0,0 +1,129 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- f -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func.html new file mode 100644 index 0000000000..786416a46d --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func.html @@ -0,0 +1,80 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- a -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_b.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_b.html new file mode 100644 index 0000000000..452e4ac509 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_b.html @@ -0,0 +1,92 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- b -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_c.html new file mode 100644 index 0000000000..032b6eeed2 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_c.html @@ -0,0 +1,99 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- c -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_d.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_d.html new file mode 100644 index 0000000000..b6f814ed21 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_d.html @@ -0,0 +1,120 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- d -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_e.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_e.html new file mode 100644 index 0000000000..e0bd93d98c --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_e.html @@ -0,0 +1,287 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- e -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_f.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_f.html new file mode 100644 index 0000000000..b3b0673c4a --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_f.html @@ -0,0 +1,120 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- f -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_i.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_i.html new file mode 100644 index 0000000000..26cdb45ccb --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_i.html @@ -0,0 +1,83 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- i -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_m.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_m.html new file mode 100644 index 0000000000..58fbba2e30 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_m.html @@ -0,0 +1,80 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- m -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_n.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_n.html new file mode 100644 index 0000000000..e940ff24a1 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_n.html @@ -0,0 +1,107 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- n -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_o.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_o.html new file mode 100644 index 0000000000..ec740c2fd9 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_o.html @@ -0,0 +1,79 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- o -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_p.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_p.html new file mode 100644 index 0000000000..61f42fdb0d --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_p.html @@ -0,0 +1,128 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- p -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_r.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_r.html new file mode 100644 index 0000000000..f4db740eae --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_r.html @@ -0,0 +1,88 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- r -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_s.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_s.html new file mode 100644 index 0000000000..8dad2c468e --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_s.html @@ -0,0 +1,99 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- s -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_w.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_w.html new file mode 100644 index 0000000000..378005ea04 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_func_w.html @@ -0,0 +1,88 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+  + +

- w -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_g.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_g.html new file mode 100644 index 0000000000..363836c265 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_g.html @@ -0,0 +1,79 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- g -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_h.html new file mode 100644 index 0000000000..e45607a9d3 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_h.html @@ -0,0 +1,79 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- h -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_i.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_i.html new file mode 100644 index 0000000000..6d046c6a48 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_i.html @@ -0,0 +1,89 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- i -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_k.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_k.html new file mode 100644 index 0000000000..09524383ae --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_k.html @@ -0,0 +1,188 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- k -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_m.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_m.html new file mode 100644 index 0000000000..b6884640b0 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_m.html @@ -0,0 +1,86 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- m -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_n.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_n.html new file mode 100644 index 0000000000..1b72d4169b --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_n.html @@ -0,0 +1,110 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- n -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_o.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_o.html new file mode 100644 index 0000000000..8b0da4a790 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_o.html @@ -0,0 +1,79 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- o -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_p.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_p.html new file mode 100644 index 0000000000..196ac75dac --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_p.html @@ -0,0 +1,137 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- p -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_r.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_r.html new file mode 100644 index 0000000000..a3f9836ed2 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_r.html @@ -0,0 +1,100 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- r -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_s.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_s.html new file mode 100644 index 0000000000..91f6e87aa2 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_s.html @@ -0,0 +1,114 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- s -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_t.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_t.html new file mode 100644 index 0000000000..a6e1ee10d6 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_t.html @@ -0,0 +1,79 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- t -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_type.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_type.html new file mode 100644 index 0000000000..8975797ee7 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_type.html @@ -0,0 +1,110 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_vars.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_vars.html new file mode 100644 index 0000000000..80dfdade97 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_vars.html @@ -0,0 +1,78 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/globals_w.html b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_w.html new file mode 100644 index 0000000000..6a291796f8 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/globals_w.html @@ -0,0 +1,91 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Globals + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:
+ +

- w -

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/glossary_8dox.html b/sgx-jvm/linux-sgx/external/epid/doc/html/glossary_8dox.html new file mode 100644 index 0000000000..268f395b34 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/glossary_8dox.html @@ -0,0 +1,82 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: doc/docsrc/glossary.dox File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
doc/docsrc/glossary.dox File Reference
+
+
+ +

This file is used by Doxygen to generate documentation. +More...

+

Detailed Description

+

This file is used by Doxygen to generate documentation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___big_num_primitives.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___big_num_primitives.html new file mode 100644 index 0000000000..c54ac40cb6 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___big_num_primitives.html @@ -0,0 +1,445 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: bignum + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
bignum
+
+
+ +

Big number operations. +More...

+ + + + + +

+Typedefs

+typedef struct BigNum BigNum
 Internal representation of large numbers.
 
+ + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

EpidStatus NewBigNum (size_t data_size_bytes, BigNum **bignum)
 Constructs a new BigNum. More...
 
void DeleteBigNum (BigNum **bignum)
 Deletes a previously allocated BigNum. More...
 
EpidStatus ReadBigNum (void const *bn_str, size_t strlen, BigNum *bn)
 Deserializes a BigNum from a string. More...
 
EpidStatus WriteBigNum (BigNum const *bn, size_t strlen, void const *bn_str)
 Serializes a BigNum to a string. More...
 
EpidStatus BigNumAdd (BigNum const *a, BigNum const *b, BigNum *r)
 Adds two BigNum values. More...
 
EpidStatus BigNumSub (BigNum const *a, BigNum const *b, BigNum *r)
 Subtracts two BigNum values. More...
 
EpidStatus BigNumMul (BigNum const *a, BigNum const *b, BigNum *r)
 Multiplies two BigNum values. More...
 
EpidStatus BigNumMod (BigNum const *a, BigNum const *b, BigNum *r)
 Computes modular reduction for BigNum value by specified modulus. More...
 
+

Detailed Description

+

Big number operations.

+

This module provides an API for working with large numbers. BigNums represent non-negative integers.

+

Each BigNum variable represents a number of a byte-size set when the variable was created. BigNum variables cannot be re-sized after they are created.

+

Function Documentation

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus BigNumAdd (BigNum const * a,
BigNum const * b,
BigNumr 
)
+
+ +

Adds two BigNum values.

+
Parameters
+ + + + +
[in]aThe left hand parameter.
[in]bThe right hand parameter.
[out]rThe result of adding a and b.
+
+
+
Returns
EpidStatus
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus BigNumMod (BigNum const * a,
BigNum const * b,
BigNumr 
)
+
+ +

Computes modular reduction for BigNum value by specified modulus.

+
Parameters
+ + + + +
[in]aThe BigNum value.
[in]bThe modulus.
[out]rModular reduction result.
+
+
+
Returns
EpidStatus
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus BigNumMul (BigNum const * a,
BigNum const * b,
BigNumr 
)
+
+ +

Multiplies two BigNum values.

+
Parameters
+ + + + +
[in]aThe left hand parameter.
[in]bThe right hand parameter.
[out]rThe result of multiplying a and b.
+
+
+
Returns
EpidStatus
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus BigNumSub (BigNum const * a,
BigNum const * b,
BigNumr 
)
+
+ +

Subtracts two BigNum values.

+
Parameters
+ + + + +
[in]aThe left hand parameter.
[in]bThe right hand parameter.
[out]rThe result of subtracting a and b.
+
+
+
Returns
EpidStatus
+ +
+
+ +
+
+ + + + + + + + +
void DeleteBigNum (BigNum ** bignum)
+
+ +

Deletes a previously allocated BigNum.

+

Frees memory pointed to by bignum. Nulls the pointer.

+
Parameters
+ + +
[in]bignumThe BigNum. Can be NULL.
+
+
+
See also
NewBigNum
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
EpidStatus NewBigNum (size_t data_size_bytes,
BigNum ** bignum 
)
+
+ +

Constructs a new BigNum.

+

Allocates memory and creates a new BigNum.

+

Use DeleteBigNum() to free memory.

+
Parameters
+ + + +
[in]data_size_bytesThe size in bytes of the new number.
[out]bignumThe BigNum.
+
+
+
Returns
EpidStatus
+
See also
DeleteBigNum
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus ReadBigNum (void const * bn_str,
size_t strlen,
BigNumbn 
)
+
+ +

Deserializes a BigNum from a string.

+
Parameters
+ + + + +
[in]bn_strThe serialized value.
[in]strlenThe size of bn_str in bytes.
[out]bnThe target BigNum.
+
+
+
Returns
EpidStatus
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus WriteBigNum (BigNum const * bn,
size_t strlen,
void const * bn_str 
)
+
+ +

Serializes a BigNum to a string.

+
Parameters
+ + + + +
[in]bnThe BigNum to be serialized.
[in]strlenThe size of bn_str in bytes.
[out]bn_strThe target string.
+
+
+
Returns
EpidStatus
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___big_num_primitives.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___big_num_primitives.js new file mode 100644 index 0000000000..d4354d5148 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___big_num_primitives.js @@ -0,0 +1,12 @@ +var group___big_num_primitives = +[ + [ "BigNum", "group___big_num_primitives.html#ga2bf153e27be2683f0fb26f0f7ff1f718", null ], + [ "BigNumAdd", "group___big_num_primitives.html#gae70fd9b3026f0ab3c7e9601d0a3186b8", null ], + [ "BigNumMod", "group___big_num_primitives.html#ga7dd6038987210d10bf843602fef0c929", null ], + [ "BigNumMul", "group___big_num_primitives.html#ga03c89b8b8dd87de2c0f4b5822145d317", null ], + [ "BigNumSub", "group___big_num_primitives.html#gacbec9669ab0fe768e2be74dcaca397ea", null ], + [ "DeleteBigNum", "group___big_num_primitives.html#ga2d17600068b1d94000635c6644258a03", null ], + [ "NewBigNum", "group___big_num_primitives.html#gad5f6f262bfd780fed3678bcee16f0aed", null ], + [ "ReadBigNum", "group___big_num_primitives.html#ga808cf477b70ed06358b11756bfe36024", null ], + [ "WriteBigNum", "group___big_num_primitives.html#ga47f356d816bcb5742ba6d78000861328", null ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___ec_group_primitives.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___ec_group_primitives.html new file mode 100644 index 0000000000..de489f9e26 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___ec_group_primitives.html @@ -0,0 +1,1078 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: ecgroup + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
ecgroup
+
+
+ +

Elliptic curve group operations. +More...

+ + + + + + + + +

+Typedefs

+typedef struct EcGroup EcGroup
 Elliptic curve group over finite field.
 
+typedef struct EcPoint EcPoint
 Point on elliptic curve over finite field.
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

EpidStatus NewEcGroup (FiniteField const *ff, FfElement const *a, FfElement const *b, FfElement const *x, FfElement const *y, BigNum const *order, BigNum const *cofactor, EcGroup **g)
 Constructs a new EcGroup. More...
 
void DeleteEcGroup (EcGroup **g)
 Deletes a previously allocated EcGroup. More...
 
EpidStatus NewEcPoint (EcGroup const *g, EcPoint **p)
 Creates a new EcPoint. More...
 
void DeleteEcPoint (EcPoint **p)
 Deletes a previously allocated EcPoint. More...
 
EpidStatus ReadEcPoint (EcGroup *g, void const *p_str, size_t strlen, EcPoint *p)
 Deserializes an EcPoint from a string. More...
 
EpidStatus WriteEcPoint (EcGroup *g, EcPoint const *p, void *p_str, size_t strlen)
 Serializes an EcPoint to a string. More...
 
EpidStatus EcMul (EcGroup *g, EcPoint const *a, EcPoint const *b, EcPoint *r)
 Multiplies two elements in an elliptic curve group. More...
 
EpidStatus EcExp (EcGroup *g, EcPoint const *a, BigNumStr const *b, EcPoint *r)
 Raises a point in an elliptic curve group to a power. More...
 
EpidStatus EcSscmExp (EcGroup *g, EcPoint const *a, BigNumStr const *b, EcPoint *r)
 Software side-channel mitigated implementation of EcExp. More...
 
EpidStatus EcMultiExp (EcGroup *g, EcPoint const **a, BigNumStr const **b, size_t m, EcPoint *r)
 Multi-exponentiates elements in elliptic curve group. More...
 
EpidStatus EcSscmMultiExp (EcGroup *g, EcPoint const **a, BigNumStr const **b, size_t m, EcPoint *r)
 Software side-channel mitigated implementation of EcMultiExp. More...
 
EpidStatus EcGetRandom (EcGroup *g, BitSupplier rnd_func, void *rnd_func_param, EcPoint *r)
 Generates a random element from an elliptic curve group. More...
 
EpidStatus EcInGroup (EcGroup *g, void const *p_str, size_t strlen, bool *in_group)
 Checks if a point is in an elliptic curve group. More...
 
EpidStatus EcHash (EcGroup *g, void const *msg, size_t msg_len, HashAlg hash_alg, EcPoint *r)
 Hashes an arbitrary message to an element in an elliptic curve group. More...
 
EpidStatus EcMakePoint (EcGroup *g, FfElement const *x, EcPoint *r)
 Sets an EcPoint variable to a point on a curve. More...
 
EpidStatus EcInverse (EcGroup *g, EcPoint const *p, EcPoint *r)
 Computes the additive inverse of an EcPoint. More...
 
EpidStatus EcIsEqual (EcGroup *g, EcPoint const *a, EcPoint const *b, bool *is_equal)
 Checks if two EcPoints are equal. More...
 
EpidStatus EcIsIdentity (EcGroup *g, EcPoint const *p, bool *is_identity)
 Checks if an EcPoint is the identity element. More...
 
+

Detailed Description

+

Elliptic curve group operations.

+

Provides APIs for working with Elliptic curve groups. Elliptic curve groups allow simple mathematical operations based on points that lie on a defined elliptic curve. The results of these operations also lie on the same curve.

+

Curves themselves are defined based on elements (FfElement) of a finite field (FiniteField).

+

Function Documentation

+ +
+
+ + + + + + + + +
void DeleteEcGroup (EcGroup ** g)
+
+ +

Deletes a previously allocated EcGroup.

+

Frees memory pointed to by elliptic curve group. Nulls the pointer.

+
Parameters
+ + +
[in]gThe elliptic curve group. Can be NULL.
+
+
+
See also
NewEcGroup
+ +
+
+ +
+
+ + + + + + + + +
void DeleteEcPoint (EcPoint ** p)
+
+ +

Deletes a previously allocated EcPoint.

+

Frees memory used by a point on elliptic curve group. Nulls the pointer.

+
Parameters
+ + +
[in]pThe EcPoint. Can be NULL.
+
+
+
See also
NewEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcExp (EcGroupg,
EcPoint const * a,
BigNumStr const * b,
EcPointr 
)
+
+ +

Raises a point in an elliptic curve group to a power.

+

This exponentiation operation is also known as element multiplication for elliptic curve groups.

Parameters
+ + + + + +
[in]gThe elliptic curve group.
[in]aThe base.
[in]bThe power. Power must be less than the order of the elliptic curve group.
[out]rThe result of raising a to the power b.
+
+
+
Returns
EpidStatus
+
See also
NewEcGroup
+
+NewEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcGetRandom (EcGroupg,
BitSupplier rnd_func,
void * rnd_func_param,
EcPointr 
)
+
+ +

Generates a random element from an elliptic curve group.

+

This function is only available for G1 and GT.

+
Parameters
+ + + + + +
[in]gThe elliptic curve group.
[in]rnd_funcRandom number generator.
[in]rnd_func_paramPass through context data for rnd_func.
[in,out]rOutput random elliptic curve element.
+
+
+
Returns
EpidStatus
+
See also
NewEcPoint
+
+BitSupplier
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcHash (EcGroupg,
void const * msg,
size_t msg_len,
HashAlg hash_alg,
EcPointr 
)
+
+ +

Hashes an arbitrary message to an element in an elliptic curve group.

+
Parameters
+ + + + + + +
[in]gThe elliptic curve group.
[in]msgThe message.
[in]msg_lenThe size of msg in bytes.
[in]hash_algThe hash algorithm.
[out]rThe hashed value.
+
+
+
Returns
EpidStatus
+
See also
NewEcGroup
+
+NewEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcInGroup (EcGroupg,
void const * p_str,
size_t strlen,
boolin_group 
)
+
+ +

Checks if a point is in an elliptic curve group.

+
Parameters
+ + + + + +
[in]gThe elliptic curve group.
[in]p_strA serialized point. Must be a G1ElemStr or G2ElemStr.
[in]strlenThe size of p_str in bytes.
[out]in_groupThe result of the check.
+
+
+
Returns
EpidStatus
+
See also
NewEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcInverse (EcGroupg,
EcPoint const * p,
EcPointr 
)
+
+ +

Computes the additive inverse of an EcPoint.

+

This inverse operation is also known as element negation for elliptic curve groups.

+
Parameters
+ + + + +
[in]gThe elliptic curve group.
[in]pThe point.
[out]rThe inverted point.
+
+
+
Returns
EpidStatus
+
See also
NewEcGroup
+
+NewEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcIsEqual (EcGroupg,
EcPoint const * a,
EcPoint const * b,
boolis_equal 
)
+
+ +

Checks if two EcPoints are equal.

+
Parameters
+ + + + + +
[in]gThe elliptic curve group.
[in]aA point to check.
[in]bAnother point to check.
[out]is_equalThe result of the check.
+
+
+
Returns
EpidStatus
+
See also
NewEcGroup
+
+NewEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcIsIdentity (EcGroupg,
EcPoint const * p,
boolis_identity 
)
+
+ +

Checks if an EcPoint is the identity element.

+

Takes a group element P as input. It outputs true if P is the identity element of G. Otherwise, it outputs false.

+
Parameters
+ + + + +
[in]gThe elliptic curve group.
[in]pThe point to check.
[out]is_identityThe result of the check.
+
+
+
Returns
EpidStatus
+
See also
NewEcGroup
+
+NewEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcMakePoint (EcGroupg,
FfElement const * x,
EcPointr 
)
+
+ +

Sets an EcPoint variable to a point on a curve.

+

This function is only available for G1.

+
Parameters
+ + + + +
[in]gThe elliptic curve group.
[in]xThe x coordinate.
[out]rThe point.
+
+
+
Returns
EpidStatus
+
See also
NewEcGroup
+
+NewEcPoint
+
+NewFfElement
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcMul (EcGroupg,
EcPoint const * a,
EcPoint const * b,
EcPointr 
)
+
+ +

Multiplies two elements in an elliptic curve group.

+

This multiplication operation is also known as element addition for elliptic curve groups.

+
Parameters
+ + + + + +
[in]gThe elliptic curve group.
[in]aThe left hand parameter.
[in]bThe right hand parameter.
[out]rThe result of multiplying a and b.
+
+
+
Returns
EpidStatus
+
See also
NewEcGroup
+
+NewEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcMultiExp (EcGroupg,
EcPoint const ** a,
BigNumStr const ** b,
size_t m,
EcPointr 
)
+
+ +

Multi-exponentiates elements in elliptic curve group.

+

Takes a group elements a[0], ... , a[m-1] in G and positive integers b[0], ..., b[m-1], where m is a small positive integer. Outputs r (in G) = EcExp(a[0],b[0]) * ... * EcExp(a[m-1],b[m-1]).

+
Parameters
+ + + + + + +
[in]gThe elliptic curve group.
[in]aThe bases.
[in]bThe powers. Power must be less than the order of the elliptic curve group.
[in]mNumber of entries in a and b.
[out]rThe result of raising each a to the corresponding power b and multiplying the results.
+
+
+
Returns
EpidStatus
+
See also
NewEcGroup
+
+NewEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcSscmExp (EcGroupg,
EcPoint const * a,
BigNumStr const * b,
EcPointr 
)
+
+ +

Software side-channel mitigated implementation of EcExp.

+

This exponentiation operation is also known as element multiplication for elliptic curve groups.

+
Attention
The reference implementation of EcSscmExp calls EcExp directly because the implementation of EcExp is already side channel mitigated. Implementers providing their own versions of this function are responsible for ensuring that EcSscmExp is side channel mitigated per section 8 of the Intel(R) EPID 2.0 spec.
+
Parameters
+ + + + + +
[in]gThe elliptic curve group.
[in]aThe base.
[in]bThe power. Power must be less than the order of the elliptic curve group.
[out]rThe result of raising a to the power b.
+
+
+
Returns
EpidStatus
+
See also
NewEcGroup
+
+NewEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcSscmMultiExp (EcGroupg,
EcPoint const ** a,
BigNumStr const ** b,
size_t m,
EcPointr 
)
+
+ +

Software side-channel mitigated implementation of EcMultiExp.

+

Takes a group elements a[0], ... , a[m-1] in G and positive integers b[0], ..., b[m-1], where m is a small positive integer. Outputs r (in G) = EcExp(a[0],b[0]) * ... * EcExp(a[m-1],b[m-1]).

+
Attention
The reference implementation of EcSscmMultiExp calls EcMultiExp directly because the implementation of EcMultiExp is already side channel mitigated. Implementers providing their own versions of this function are responsible for ensuring that EcSscmMultiExp is side channel mitigated per section 8 of the Intel(R) EPID 2.0 spec.
+
Parameters
+ + + + + + +
[in]gThe elliptic curve group.
[in]aThe bases.
[in]bThe powers. Power must be less than the order of the elliptic curve group.
[in]mNumber of entries in a and b.
[out]rThe result of raising each a to the corresponding power b and multiplying the results.
+
+
+
Returns
EpidStatus
+
See also
NewEcGroup
+
+NewEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus NewEcGroup (FiniteField const * ff,
FfElement const * a,
FfElement const * b,
FfElement const * x,
FfElement const * y,
BigNum const * order,
BigNum const * cofactor,
EcGroup ** g 
)
+
+ +

Constructs a new EcGroup.

+

Allocates memory and creates a new elliptic curve group.

+

Use DeleteFiniteField() to free memory.

+
Parameters
+ + + + + + + + + +
[in]ffThe finite field on which the curve is based.
[in]aThe A value of the elliptic curve.
[in]bThe B value of the elliptic curve.
[in]xThe X co-ordinate of the base point of the elliptic curve.
[in]yThe Y co-ordinate of the base point of the elliptic curve.
[in]orderThe order of the elliptic curve group.
[in]cofactorThe co-factor of the elliptic curve.
[out]gThe newly constructed elliptic curve group.
+
+
+
Returns
EpidStatus
+
See also
DeleteEcGroup
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
EpidStatus NewEcPoint (EcGroup const * g,
EcPoint ** p 
)
+
+ +

Creates a new EcPoint.

+

Allocates memory and creates a new point on elliptic curve group.

+

Use DeleteEcPoint() to free memory.

+
Parameters
+ + + +
[in]gElliptic curve group.
[out]pNewly constructed point on the elliptic curve group g.
+
+
+
Returns
EpidStatus
+
See also
NewEcGroup
+
+DeleteEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus ReadEcPoint (EcGroupg,
void const * p_str,
size_t strlen,
EcPointp 
)
+
+ +

Deserializes an EcPoint from a string.

+
Parameters
+ + + + + +
[in]gThe elliptic curve group.
[in]p_strThe serialized value.
[in]strlenThe size of p_str in bytes.
[out]pThe target EcPoint.
+
+
+
Returns
EpidStatus
+
See also
NewEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus WriteEcPoint (EcGroupg,
EcPoint const * p,
void * p_str,
size_t strlen 
)
+
+ +

Serializes an EcPoint to a string.

+
Parameters
+ + + + + +
[in]gThe elliptic curve group.
[in]pThe EcPoint to be serialized.
[out]p_strThe target string.
[in]strlenthe size of p_str in bytes.
+
+
+
Returns
EpidStatus
+
See also
NewEcPoint
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___ec_group_primitives.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___ec_group_primitives.js new file mode 100644 index 0000000000..bf32859b49 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___ec_group_primitives.js @@ -0,0 +1,23 @@ +var group___ec_group_primitives = +[ + [ "EcGroup", "group___ec_group_primitives.html#gac91c5a7623c17a868dd15b2e9aaf7159", null ], + [ "EcPoint", "group___ec_group_primitives.html#ga85c1d5e106031b385a6e23e598ac98fa", null ], + [ "DeleteEcGroup", "group___ec_group_primitives.html#gab7af276256c27610eda85ff432b846ea", null ], + [ "DeleteEcPoint", "group___ec_group_primitives.html#ga8cb086d792bffb79b3ca07e6ca4ce0e7", null ], + [ "EcExp", "group___ec_group_primitives.html#ga01bf8d6fa60a2e445490966b3a06c270", null ], + [ "EcGetRandom", "group___ec_group_primitives.html#ga3f96c43d14d24de0f7a5e214aef64196", null ], + [ "EcHash", "group___ec_group_primitives.html#gadc22ee07864a7ee681a881029b69d76a", null ], + [ "EcInGroup", "group___ec_group_primitives.html#ga4d0f32aede3066eae500241b387bd970", null ], + [ "EcInverse", "group___ec_group_primitives.html#ga0b6d7a3398251e9352fb29ef4abef466", null ], + [ "EcIsEqual", "group___ec_group_primitives.html#gad3b3c63c48fa24e8dea07837b05bc061", null ], + [ "EcIsIdentity", "group___ec_group_primitives.html#ga9cf15b34bc4ff12e58b169dd989d8210", null ], + [ "EcMakePoint", "group___ec_group_primitives.html#ga8a6114a48214a327d4ec04fd25e5940e", null ], + [ "EcMul", "group___ec_group_primitives.html#ga25c9013cc76907d73765eb7a96aa8c96", null ], + [ "EcMultiExp", "group___ec_group_primitives.html#gae96c38e004ccd2211290ad6e66415ec4", null ], + [ "EcSscmExp", "group___ec_group_primitives.html#gaf3b6a548aa6f0d4f028a14feca251f57", null ], + [ "EcSscmMultiExp", "group___ec_group_primitives.html#ga40e3431d3dbe8cf7a65ada7b7811cba4", null ], + [ "NewEcGroup", "group___ec_group_primitives.html#gaf4e23677dd378ef2e0cf55df79cbdb62", null ], + [ "NewEcPoint", "group___ec_group_primitives.html#ga6417b0ce72ba96de00c329e322fec7fb", null ], + [ "ReadEcPoint", "group___ec_group_primitives.html#ga2d433f567fa2419465a49604f4da21ad", null ], + [ "WriteEcPoint", "group___ec_group_primitives.html#ga4bb7d6691ffbb6e947c1068453e27fbd", null ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___ecdsa_primitives.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___ecdsa_primitives.html new file mode 100644 index 0000000000..e1c37b9239 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___ecdsa_primitives.html @@ -0,0 +1,229 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: ecdsa + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
ecdsa
+
+
+ +

Elliptic Curve Digital Signature Algorithm Primitives. +More...

+ + + + + + + + +

+Functions

EpidStatus EcdsaVerifyBuffer (void const *buf, size_t buf_len, EcdsaPublicKey const *pubkey, EcdsaSignature const *sig)
 Verifies authenticity of a digital signature over a buffer. More...
 
EpidStatus EcdsaSignBuffer (void const *buf, size_t buf_len, EcdsaPrivateKey const *privkey, BitSupplier rnd_func, void *rnd_param, EcdsaSignature *sig)
 Creates ECDSA signature of buffer. More...
 
+

Detailed Description

+

Elliptic Curve Digital Signature Algorithm Primitives.

+

Provides APIs for computing and checking buffer signatures using the Elliptic Curve Digital Signature Algorithm.

+

Function Documentation

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcdsaSignBuffer (void const * buf,
size_t buf_len,
EcdsaPrivateKey const * privkey,
BitSupplier rnd_func,
void * rnd_param,
EcdsaSignaturesig 
)
+
+ +

Creates ECDSA signature of buffer.

+

Uses Elliptic Curve Digital Signature Algorithm (ECDSA) to generate a signature of the SHA256 hash of the input buffer with the provided private key.

+

The operation is over the standard secp256r1 curve.

+
Parameters
+ + + + + + + +
[in]bufPointer to buffer containing message to sign.
[in]buf_lenThe size of buf in bytes.
[in]privkeyThe ECDSA private key on secp256r1 curve.
[in]rnd_funcRandom number generator.
[in]rnd_paramPass through context data for rnd_func.
[out]sigThe resulting ECDSA signature.
+
+
+
Returns
EpidStatus
+
Return values
+ + +
kEpidRandMaxIterErrFailed to sign after maximum number of iterations due to bad luck in random number generation.
+
+
+
See also
EcdsaSignBuffer
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EcdsaVerifyBuffer (void const * buf,
size_t buf_len,
EcdsaPublicKey const * pubkey,
EcdsaSignature const * sig 
)
+
+ +

Verifies authenticity of a digital signature over a buffer.

+

Uses Elliptic Curve Digital Signature Algorithm (ECDSA) to verify that the SHA256 hash of the input buffer was signed with the private key corresponding to the provided public key.

+

The operation is over the standard secp256r1 curve.

+
Warning
It is the responsibility of the caller to verify the identity of the public key.
+
Parameters
+ + + + + +
[in]bufPointer to buffer containing message to verify.
[in]buf_lenThe size of buf in bytes.
[in]pubkeyThe ECDSA public key on secp256r1 curve.
[in]sigThe ECDSA signature to be verified.
+
+
+
Returns
EpidStatus
+
Return values
+ + + +
kEpidSigValidEcdsaSignature is valid for the given buffer.
kEpidSigInvalidEcdsaSignature is invalid for the given buffer.
+
+
+
See also
EcdsaSignBuffer
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___ecdsa_primitives.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___ecdsa_primitives.js new file mode 100644 index 0000000000..37f85bf007 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___ecdsa_primitives.js @@ -0,0 +1,5 @@ +var group___ecdsa_primitives = +[ + [ "EcdsaSignBuffer", "group___ecdsa_primitives.html#ga67091ecae643c1b8a0b0a4946eda7afe", null ], + [ "EcdsaVerifyBuffer", "group___ecdsa_primitives.html#gaab68de7291db6e42a01e99c2fa40057f", null ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_common.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_common.html new file mode 100644 index 0000000000..e0940043c1 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_common.html @@ -0,0 +1,1066 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: common + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+ +
+ +

Common code shared between core sub-components. +More...

+ + + + + + + + + + + + + + + + + +

+Modules

 math
 Math Primitives and Group Operations.
 
 errors
 Error reporting interface.
 
 fileparser
 Parser for issuer material.
 
 print_utils
 Debug print routines.
 
 types
 SDK data types.
 
+ + + + + + + + + + + + + +

+Data Structures

struct  CommitValues
 Storage for values to create commitment in Sign and Verify algorithms. More...
 
struct  Epid2Params_
 Internal representation of Epid2Params. More...
 
struct  GroupPubKey_
 Internal representation of GroupPubKey. More...
 
struct  PrivKey_
 Internal implementation of PrivKey. More...
 
+ + + + + + + + + + + + + + + + +

+Macros

#define ntohl(u32)
 Macros to transform oct str 32 into uint_32. More...
 
+#define EPID_ENABLE_EPID_ZERO_MEMORY_ON_FREE
 When enabled secrets are wiped out from the memory by EpidFree.
 
+#define SAFE_ALLOC(size)   EpidAlloc(size);
 Allocates zero initalized block of memory.
 
#define SAFE_FREE(ptr)
 Deallocates space allocated by SAFE_ALLOC() and nulls pointer. More...
 
+#define SAFE_REALLOC(ptr, size)   EpidRealloc((ptr), (size))
 Changes the size of the memory block pointed to by ptr.
 
+ + + + +

+Typedefs

typedef int(__STDCALL * BitSupplier) (unsigned int *rand_data, int num_bits, void *user_data)
 Generates random data. More...
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

EpidStatus SetKeySpecificCommitValues (GroupPubKey const *pub_key, CommitValues *values)
 Set group public key related fields from CommitValues structure. More...
 
EpidStatus SetCalculatedCommitValues (G1ElemStr const *B, G1ElemStr const *K, G1ElemStr const *T, EcPoint const *R1, EcGroup *G1, FfElement const *R2, FiniteField *GT, CommitValues *values)
 Set CommitValues structure fields calculated in algorithm. More...
 
EpidStatus CalculateCommitmentHash (CommitValues const *values, FiniteField *Fp, HashAlg hash_alg, void const *msg, size_t msg_len, FfElement *c)
 Calculate Fp.hash(t3 || m) for Sign and Verfiy algorithms. More...
 
EpidStatus CreateEpid2Params (Epid2Params_ **params)
 Constructs the internal representation of Epid2Params. More...
 
void DeleteEpid2Params (Epid2Params_ **epid_params)
 Deallocates storage for internal representation of Epid2Params. More...
 
EpidStatus CreateGroupPubKey (GroupPubKey const *pub_key_str, EcGroup *G1, EcGroup *G2, GroupPubKey_ **pub_key)
 Constructs internal representation of GroupPubKey. More...
 
void DeleteGroupPubKey (GroupPubKey_ **pub_key)
 Deallocates storage for internal representation of GroupPubKey. More...
 
void EpidZeroMemory (void *ptr, size_t size)
 Clear information stored in block of memory pointer to by ptr. More...
 
void * EpidAlloc (size_t size)
 Allocates memory of size bytes. More...
 
void * EpidRealloc (void *ptr, size_t new_size)
 Reallocates memory allocated by EpidAlloc. More...
 
void EpidFree (void *ptr)
 Frees memory allocated by EpidAlloc. More...
 
int memcpy_S (void *dest, size_t destsz, void const *src, size_t count)
 Copies bytes between buffers with security ehancements. More...
 
bool IsSigRlValid (GroupId const *gid, SigRl const *sig_rl, size_t sig_rl_size)
 Function to verify if signature based revocation list is valid. More...
 
bool CreateStack (size_t element_size, Stack **stack)
 Create stack. More...
 
void * StackPushN (Stack *stack, size_t n, void *elements)
 Push multiple elements to the stack. More...
 
bool StackPopN (Stack *stack, size_t n, void *elements)
 Pop multiple elements from the stack. More...
 
size_t StackGetSize (Stack const *stack)
 Get number of elements in the stack. More...
 
void DeleteStack (Stack **stack)
 Deallocates memory used for the stack. More...
 
EpidStatus CreatePrivKey (PrivKey const *priv_key_str, EcGroup *G1, FiniteField *Fp, PrivKey_ **priv_key)
 Constructs internal representation of PrivKey. More...
 
void DeletePrivKey (PrivKey_ **priv_key)
 Deallocate storage for internal representation of PrivKey. More...
 
+

Detailed Description

+

Common code shared between core sub-components.

+

Constants, utility functions, and libraries that are used widely in the implementation or definition of APIs and samples.

+

Macro Definition Documentation

+ +
+
+ + + + + + + + +
#define ntohl( u32)
+
+Value:
((uint32_t)(((((unsigned char*)&(u32))[0]) << 24) + \
((((unsigned char*)&(u32))[1]) << 16) + \
((((unsigned char*)&(u32))[2]) << 8) + \
(((unsigned char*)&(u32))[3])))
+

Macros to transform oct str 32 into uint_32.

+ +
+
+ +
+
+ + + + + + + + +
#define SAFE_FREE( ptr)
+
+Value:
{ \
if (NULL != (ptr)) { \
EpidFree(ptr); \
(ptr) = NULL; \
} \
}
+

Deallocates space allocated by SAFE_ALLOC() and nulls pointer.

+ +
+
+

Typedef Documentation

+ +
+
+ + + + +
typedef int(__STDCALL* BitSupplier) (unsigned int *rand_data, int num_bits, void *user_data)
+
+ +

Generates random data.

+

It is the responsibility of the caller of the SDK interfaces to implement a function of this prototype and to then pass a pointer to this function into methods that require it.

+
Parameters
+ + + + +
[out]rand_datadestination buffer
[in]num_bitssize of rand_data in bits
[in]user_datauser data passed through from api call.
+
+
+
Returns
zero on success and non-zero value on error.
+ +
+
+

Function Documentation

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus CalculateCommitmentHash (CommitValues const * values,
FiniteFieldFp,
HashAlg hash_alg,
void const * msg,
size_t msg_len,
FfElementc 
)
+
+ +

Calculate Fp.hash(t3 || m) for Sign and Verfiy algorithms.

+

Calculate c = Fp.hash(t3 || m) where t3 is Fp.hash(p || g1 || g2 || h1 || h2 || w || B || K || T || R1 || R2).

+
Parameters
+ + + + + + + +
[in]valuesCommit values to hash
[in]FpFinite field to perfom hash operation in
[in]hash_algHash algorithm to use
[in]msgMessage to hash
[in]msg_lenSize of msg buffer in bytes
[out]cResult of calculation
+
+
+
Returns
EpidStatus
+
See also
SetKeySpecificCommitValues
+
+SetCalculatedCommitValues
+ +
+
+ +
+
+ + + + + + + + +
EpidStatus CreateEpid2Params (Epid2Params_ ** params)
+
+ +

Constructs the internal representation of Epid2Params.

+

Allocates memory for the internal representation of Epid2Params. Initialize the Epid2Params. Use DeleteEpid2Params() to deallocate memory.

+
Parameters
+ + +
[in,out]paramsInternal Epid2Params
+
+
+
Returns
EpidStatus
+
See also
DeleteEpid2Params
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus CreateGroupPubKey (GroupPubKey const * pub_key_str,
EcGroupG1,
EcGroupG2,
GroupPubKey_ ** pub_key 
)
+
+ +

Constructs internal representation of GroupPubKey.

+

Allocates memory and initializes gid, h1, h2, w parameters. Use DeleteGroupPubKey() to deallocate memory

+
Parameters
+ + + + + +
[in]pub_key_strOct string representation of group public key
[in]G1EcGroup containing elements h1 and h2
[in]G2EcGroup containing element w
[out]pub_keyGroup public key: (gid, h1, h2, w)
+
+
+
Returns
EpidStatus
+
See also
DeleteGroupPubKey
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus CreatePrivKey (PrivKey const * priv_key_str,
EcGroupG1,
FiniteFieldFp,
PrivKey_ ** priv_key 
)
+
+ +

Constructs internal representation of PrivKey.

+

This function allocates memory and initializes gid, A, x, f parameters.

+
Parameters
+ + + + + +
[in]priv_key_strSerialized representation of private key
[in]G1EcGroup containing element A
[in]FpFiniteField containing elements x and f
[out]priv_keyNewly created private key: (gid, A, x, f)
+
+
+
Returns
EpidStatus
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
bool CreateStack (size_t element_size,
Stack ** stack 
)
+
+ +

Create stack.

+
Parameters
+ + + +
[in]element_sizeSize of stack element
[out]stackStack context to be created
+
+
+
Returns
true is operation succeed, false if stack were failed to allocate
+
See also
DeleteStack
+ +
+
+ +
+
+ + + + + + + + +
void DeleteEpid2Params (Epid2Params_ ** epid_params)
+
+ +

Deallocates storage for internal representation of Epid2Params.

+

Frees the memory and nulls the pointer.

+
Parameters
+ + +
[in,out]epid_paramsparams to be deallocated
+
+
+
See also
CreateEpid2Params
+ +
+
+ +
+
+ + + + + + + + +
void DeleteGroupPubKey (GroupPubKey_ ** pub_key)
+
+ +

Deallocates storage for internal representation of GroupPubKey.

+

Frees memory pointed to by Group public key. Nulls the pointer.

+
Parameters
+ + +
[in]pub_keyGroup public key to be freed
+
+
+
See also
CreateGroupPubKey
+ +
+
+ +
+
+ + + + + + + + +
void DeletePrivKey (PrivKey_ ** priv_key)
+
+ +

Deallocate storage for internal representation of PrivKey.

+

Frees memory pointed to by Member private key. Nulls the pointer.

+
Parameters
+ + +
[in]priv_keyMember private key to be freed
+
+
+ +
+
+ +
+
+ + + + + + + + +
void DeleteStack (Stack ** stack)
+
+ +

Deallocates memory used for the stack.

+
Parameters
+ + +
[in,out]stackStack context
+
+
+
See also
CreateStack
+ +
+
+ +
+
+ + + + + + + + +
void* EpidAlloc (size_t size)
+
+ +

Allocates memory of size bytes.

+

The content of memory is initialized with zeros. Memory must be freed with EpidFree function.

+
Parameters
+ + +
[in]sizenumber of bytes to allocate
+
+
+
Returns
pointer to allocated memory.
+ +
+
+ +
+
+ + + + + + + + +
void EpidFree (void * ptr)
+
+ +

Frees memory allocated by EpidAlloc.

+

Clears information stored in the block of memory.

+
Parameters
+ + +
[in]ptrpointer to allocated memory block
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
void* EpidRealloc (void * ptr,
size_t new_size 
)
+
+ +

Reallocates memory allocated by EpidAlloc.

+

In case of error NULL pointer is returned and input memory block is not changed. Memory must be freed with EpidFree function.

+
Parameters
+ + + +
[in]ptrpointer to memory block to reallocate
[in]new_sizenumber of bytes to reallocate for
+
+
+
Returns
pointer to allocated memory.
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
void EpidZeroMemory (void * ptr,
size_t size 
)
+
+ +

Clear information stored in block of memory pointer to by ptr.

+
Warning
This function may be optimized away by some compilers. If it is, you should consider using a compiler or operating system specific memory sanitization function (e.g. memcpy_s or SecureZeroMemory).
+
Parameters
+ + + +
[in]ptrpointer to memory block
[in]sizenumber of bytes to clear
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
bool IsSigRlValid (GroupId const * gid,
SigRl const * sig_rl,
size_t sig_rl_size 
)
+
+ +

Function to verify if signature based revocation list is valid.

+
Parameters
+ + + + +
[in]gidGroup id
[in]sig_rlSignature based revocation list
[in]sig_rl_sizeSize of signature based revocation list
+
+
+
Returns
true if revocation list is valid
+
+false if revocation list is invalid
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int memcpy_S (void * dest,
size_t destsz,
void const * src,
size_t count 
)
+
+ +

Copies bytes between buffers with security ehancements.

+

Copies count bytes from src to dest. If the source and destination overlap, the behavior is undefined.

+
Parameters
+ + + + + +
[out]destpointer to the object to copy to
[in]destszmax number of bytes to modify in the destination (typically the size of the destination object)
[in]srcpointer to the object to copy from
[in]countnumber of bytes to copy
+
+
+
Returns
zero on success and non-zero value on error.
+

Copies bytes between buffers with security ehancements.

+
Note
Implementation follows C11 memcpy_s but with checks always enabled
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus SetCalculatedCommitValues (G1ElemStr const * B,
G1ElemStr const * K,
G1ElemStr const * T,
EcPoint const * R1,
EcGroupG1,
FfElement const * R2,
FiniteFieldGT,
CommitValuesvalues 
)
+
+ +

Set CommitValues structure fields calculated in algorithm.

+

Set B, K, T, R1 and R2 fields of values argument.

+
Parameters
+ + + + + + + + + +
[in]BValue of B to set
[in]KValue of K to set
[in]TValue of T to set
[in]R1Value of R1 to set
[in]G1EcGroup containing element R1
[in]R2Value of R2 to set
[in]GTFiniteField containing element R2
[out]valuesPointer to CommitValues structure to fill.
+
+
+
Returns
EpidStatus
+
See also
CalculateCommitmentHash
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
EpidStatus SetKeySpecificCommitValues (GroupPubKey const * pub_key,
CommitValuesvalues 
)
+
+ +

Set group public key related fields from CommitValues structure.

+

Set p, g1, g2, h1, h2 and w fields of values argument.

+
Parameters
+ + + +
[in]pub_keyGroup public key
[out]valuesPointer to CommitValues structure to fill.
+
+
+
Returns
EpidStatus
+
See also
CalculateCommitmentHash
+ +
+
+ +
+
+ + + + + + + + +
size_t StackGetSize (Stack const * stack)
+
+ +

Get number of elements in the stack.

+
Parameters
+ + +
[in]stackStack context
+
+
+
Returns
Number of elements in the stack or 0 if stack is NULL
+
See also
CreateStack
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
bool StackPopN (Stackstack,
size_t n,
void * elements 
)
+
+ +

Pop multiple elements from the stack.

+
Parameters
+ + + + +
[in,out]stackStack context
[in]nNumber of elements to pop from the stack
[out]elementsPointer to a buffer to store elements removed from the stack
+
+
+
Returns
true is operation succeed, false otherwise
+
See also
CreateStack
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
void* StackPushN (Stackstack,
size_t n,
void * elements 
)
+
+ +

Push multiple elements to the stack.

+
Parameters
+ + + + +
[in,out]stackStack context
[in]nNumber of elements to push to the stack
[in]elementsArray of elements to push to the stack. Can be NULL
+
+
+
Returns
A pointer to an array of new elements in the stack or NULL if stack is empty or push operation were failed.
+
See also
CreateStack
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_common.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_common.js new file mode 100644 index 0000000000..78783bcfb6 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_common.js @@ -0,0 +1,76 @@ +var group___epid_common = +[ + [ "math", "group___epid_math.html", "group___epid_math" ], + [ "errors", "group___error_codes.html", "group___error_codes" ], + [ "fileparser", "group___file_parser.html", "group___file_parser" ], + [ "print_utils", "group___epid_print.html", "group___epid_print" ], + [ "types", "group___epid_types.html", "group___epid_types" ], + [ "CommitValues", "struct_commit_values.html", [ + [ "B", "struct_commit_values.html#abc97167d51a8d0669da9a8d97353db4d", null ], + [ "g1", "struct_commit_values.html#a22512a6efa7b7b0277b211be64f71c30", null ], + [ "g2", "struct_commit_values.html#af7022c18732bbee8c12328923a4a12a1", null ], + [ "h1", "struct_commit_values.html#a42297d157420f0b554bce8a8cbe95c46", null ], + [ "h2", "struct_commit_values.html#a4a93cb984bac3de47bb60511b382a074", null ], + [ "K", "struct_commit_values.html#a49f073d0132a51020c0bfc819ec0d619", null ], + [ "p", "struct_commit_values.html#af5bf0f288e76f28ce54fe2df813881ef", null ], + [ "R1", "struct_commit_values.html#a00f7731d75085be08f171771c8f43d30", null ], + [ "R2", "struct_commit_values.html#acb0d12e761fadb149924cdf21290b9bf", null ], + [ "T", "struct_commit_values.html#ab2da47fe5c28b4202658c5ad3523ea1a", null ], + [ "w", "struct_commit_values.html#ac00af9d3eeb74543808a9e52e692f614", null ] + ] ], + [ "Epid2Params_", "struct_epid2_params__.html", [ + [ "Fp", "struct_epid2_params__.html#a45d742532485af7f34d43606a3f96b5d", null ], + [ "Fq", "struct_epid2_params__.html#a9cd99a40a7427666ff4b940ed69f69a0", null ], + [ "Fq2", "struct_epid2_params__.html#aebda3f9b5ed6f015adc992216bacf29f", null ], + [ "Fq6", "struct_epid2_params__.html#af3e9afc48ec8274f15d10f5f991c0937", null ], + [ "g1", "struct_epid2_params__.html#a337490f043e867b6c8d92180a9120541", null ], + [ "G1", "struct_epid2_params__.html#ade20ba985bc9219832df78ee9d255ee5", null ], + [ "g2", "struct_epid2_params__.html#a20dcfa40dba6679f45f1b90a91791a5c", null ], + [ "G2", "struct_epid2_params__.html#ae15ab066b26bbf1be8772743d604c766", null ], + [ "GT", "struct_epid2_params__.html#ac085cbd970d89fb382b621fb2884e420", null ], + [ "neg", "struct_epid2_params__.html#a1e50604a1739e48e8588d666d33d03ef", null ], + [ "p", "struct_epid2_params__.html#ad90e9f295e28d3f93852e87e97640e76", null ], + [ "pairing_state", "struct_epid2_params__.html#a74aa52f336a194b20627f8a540196dd5", null ], + [ "q", "struct_epid2_params__.html#a6d56c3f4dff7e92a0738e7866208bf4d", null ], + [ "t", "struct_epid2_params__.html#a4bca3d05a46b1325ac2490ebeb460543", null ], + [ "xi", "struct_epid2_params__.html#a51a678f0f26804e0c6f3a4c55fcf6731", null ] + ] ], + [ "GroupPubKey_", "struct_group_pub_key__.html", [ + [ "gid", "struct_group_pub_key__.html#afd2192bfd1e24c09951d9c0200a74f95", null ], + [ "h1", "struct_group_pub_key__.html#a2322bc1b42f85e0d01b50b15d064f840", null ], + [ "h2", "struct_group_pub_key__.html#a4d95b831d9a66071092678547df921ae", null ], + [ "w", "struct_group_pub_key__.html#a4d1537e5bd834b6fc92eb2fd7c826329", null ] + ] ], + [ "PrivKey_", "struct_priv_key__.html", [ + [ "A", "struct_priv_key__.html#aaf02af1379a0801f49a3f8845e7a1b1f", null ], + [ "f", "struct_priv_key__.html#a183eb6658baec9825313ab534608fa10", null ], + [ "gid", "struct_priv_key__.html#a0892f451bb967dd7c99fe1d926d5056f", null ], + [ "x", "struct_priv_key__.html#a327d7192cbb6b5638e3f6f1c3d9d2d5b", null ] + ] ], + [ "EPID_ENABLE_EPID_ZERO_MEMORY_ON_FREE", "group___epid_common.html#gab1587898f15de1b51cd5e799a43465ff", null ], + [ "ntohl", "group___epid_common.html#ga29a7e07cd5181e738f98fc026979efca", null ], + [ "SAFE_ALLOC", "group___epid_common.html#ga38fad13430eba25f9f9b05e35ecd22f8", null ], + [ "SAFE_FREE", "group___epid_common.html#ga2ca3c202ee727774d55890e568621842", null ], + [ "SAFE_REALLOC", "group___epid_common.html#ga41c113e15b695291199c27fac4bd53fa", null ], + [ "BitSupplier", "group___epid_common.html#ga6119a2c0323a3fca9e502b24bc378c2c", null ], + [ "CalculateCommitmentHash", "group___epid_common.html#ga23f8ea0f7529e8e7a81bd88e607dda01", null ], + [ "CreateEpid2Params", "group___epid_common.html#ga5c396a5ac8a0e5ec1e02330c53420dce", null ], + [ "CreateGroupPubKey", "group___epid_common.html#ga20a575d3d538b0bac654fd57f20e2b30", null ], + [ "CreatePrivKey", "group___epid_common.html#gae51985a0e811f4bbb2d70b62e35b881e", null ], + [ "CreateStack", "group___epid_common.html#ga00cb25d52726cef61a9a5266176c2a58", null ], + [ "DeleteEpid2Params", "group___epid_common.html#gac22664b5f7df5cd4da1bd7b1b1e7912f", null ], + [ "DeleteGroupPubKey", "group___epid_common.html#ga07c9b47d326ee784aecb78195adffb8b", null ], + [ "DeletePrivKey", "group___epid_common.html#ga53db100214e65e362fa426508a240d12", null ], + [ "DeleteStack", "group___epid_common.html#ga3335a4754825c54840263aa4b2a9bf67", null ], + [ "EpidAlloc", "group___epid_common.html#gada170fd890504b013139f4a33033ae4b", null ], + [ "EpidFree", "group___epid_common.html#gaeae76709e6bfc80c9d79ec4943ccc1ac", null ], + [ "EpidRealloc", "group___epid_common.html#ga6911838728d546e4a51d7bcb8404525c", null ], + [ "EpidZeroMemory", "group___epid_common.html#gad471f600f6032f432b99432fda97a070", null ], + [ "IsSigRlValid", "group___epid_common.html#ga23ec3f6c8b89eb63e04d2b1ec6fd2696", null ], + [ "memcpy_S", "group___epid_common.html#ga4856121ac4bce4161a015a8a2b4f5b1c", null ], + [ "SetCalculatedCommitValues", "group___epid_common.html#ga3f3c3b965dd714179cbc2f8d96678ee0", null ], + [ "SetKeySpecificCommitValues", "group___epid_common.html#ga2d54f4f222e965222024113c0420602d", null ], + [ "StackGetSize", "group___epid_common.html#gab34066dc882ad63362c43c0790973fdc", null ], + [ "StackPopN", "group___epid_common.html#ga8cdde2b366f4473f0a6965bcfea5b6a6", null ], + [ "StackPushN", "group___epid_common.html#ga0b4dedb867504e0148aa0e1fdf642b2b", null ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_math.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_math.html new file mode 100644 index 0000000000..574d7260c3 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_math.html @@ -0,0 +1,106 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: math + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
math
+
+
+ +

Math Primitives and Group Operations. +More...

+ + + + + + + + + + + + + + + + + + + + +

+Modules

 bignum
 Big number operations.
 
 ecdsa
 Elliptic Curve Digital Signature Algorithm Primitives.
 
 ecgroup
 Elliptic curve group operations.
 
 finitefield
 Finite field operations.
 
 hash
 Hash primitives.
 
 pairing
 Pairing operations.
 
+

Detailed Description

+

Math Primitives and Group Operations.

+

Provides abstracted math primitives that are designed to be overridden by implementers porting to environments with specialized hardware. This module is defined and tested to hide implementation details from users of the API

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_math.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_math.js new file mode 100644 index 0000000000..c416f54486 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_math.js @@ -0,0 +1,9 @@ +var group___epid_math = +[ + [ "bignum", "group___big_num_primitives.html", "group___big_num_primitives" ], + [ "ecdsa", "group___ecdsa_primitives.html", "group___ecdsa_primitives" ], + [ "ecgroup", "group___ec_group_primitives.html", "group___ec_group_primitives" ], + [ "finitefield", "group___finite_field_primitives.html", "group___finite_field_primitives" ], + [ "hash", "group___hash_primitives.html", "group___hash_primitives" ], + [ "pairing", "group___pairing_primitives.html", "group___pairing_primitives" ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_member_module.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_member_module.html new file mode 100644 index 0000000000..898d1c9185 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_member_module.html @@ -0,0 +1,933 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: member + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
member
+
+
+ +

Member functionality. +More...

+ + + + + + + + +

+Data Structures

struct  MemberPrecomp
 Pre-computed member settings. More...
 
struct  PreComputedSignature
 Pre-computed signature. More...
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

EpidStatus EpidMemberCreate (GroupPubKey const *pub_key, PrivKey const *priv_key, MemberPrecomp const *precomp, BitSupplier rnd_func, void *rnd_param, MemberCtx **ctx)
 Creates a new member context. More...
 
void EpidMemberDelete (MemberCtx **ctx)
 Deletes an existing member context. More...
 
EpidStatus EpidMemberWritePrecomp (MemberCtx const *ctx, MemberPrecomp *precomp)
 Serializes the pre-computed member settings. More...
 
EpidStatus EpidMemberSetHashAlg (MemberCtx *ctx, HashAlg hash_alg)
 Sets the hash algorithm to be used by a member. More...
 
size_t EpidGetSigSize (SigRl const *sig_rl)
 Computes the size in bytes required for a Intel(R) EPID signature. More...
 
EpidStatus EpidSign (MemberCtx const *ctx, void const *msg, size_t msg_len, void const *basename, size_t basename_len, SigRl const *sig_rl, size_t sig_rl_size, EpidSignature *sig, size_t sig_len)
 Writes a Intel(R) EPID signature. More...
 
EpidStatus EpidRegisterBaseName (MemberCtx *ctx, void const *basename, size_t basename_len)
 Registers a basename with a member. More...
 
EpidStatus EpidAddPreSigs (MemberCtx *ctx, size_t number_presigs, PreComputedSignature *presigs)
 Extends the member's pool of pre-computed signatures. More...
 
size_t EpidGetNumPreSigs (MemberCtx const *ctx)
 Gets the number of pre-computed signatures in the member's pool. More...
 
EpidStatus EpidWritePreSigs (MemberCtx *ctx, PreComputedSignature *presigs, size_t number_presigs)
 Serializes pre-computed signatures from the member's pool. More...
 
EpidStatus EpidRequestJoin (GroupPubKey const *pub_key, IssuerNonce const *ni, FpElemStr const *f, BitSupplier rnd_func, void *rnd_param, HashAlg hash_alg, JoinRequest *join_request)
 Creates a request to join a group. More...
 
EpidStatus EpidSignBasic (MemberCtx const *ctx, void const *msg, size_t msg_len, void const *basename, size_t basename_len, BasicSignature *sig)
 Creates a basic signature for use in constrained environment. More...
 
EpidStatus EpidNrProve (MemberCtx const *ctx, void const *msg, size_t msg_len, BasicSignature const *sig, SigRlEntry const *sigrl_entry, NrProof *proof)
 Calculates a non-revoked proof for a single signature based revocation list entry. More...
 
bool EpidIsPrivKeyInGroup (GroupPubKey const *pub_key, PrivKey const *priv_key)
 Tests if a member private key is valid without checking revocation. More...
 
EpidStatus EpidDecompressPrivKey (GroupPubKey const *pub_key, CompressedPrivKey const *compressed_privkey, PrivKey *priv_key)
 Decompresses compressed member private key. More...
 
+

Detailed Description

+

Member functionality.

+

Defines the APIs needed by Intel(R) EPID members. Each member context (MemberCtx) represents membership in a single group.

+

Function Documentation

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidAddPreSigs (MemberCtxctx,
size_t number_presigs,
PreComputedSignaturepresigs 
)
+
+ +

Extends the member's pool of pre-computed signatures.

+

Can either generate new pre-computed signatures or import existing ones. EpidWritePreSigs can be used to export pre-computed signatures.

+
Parameters
+ + + + +
[in]ctxThe member context.
[in]number_presigsThe number of pre-computed signatures to add to the internal pool.
[in,out]presigsOptional array of valid pre-computed signatures to import. If presigs is not NULL it most contain at least number_presigs pre-computed signatures.
+
+
+
Returns
EpidStatus
+
Note
presigs buffer is zeroed out before return to prevent pre-computed signatures from being reused.
+
+If the result is not kEpidNoErr the state of the pre-computed signature pool, and of presigs, is undefined.
+
See also
EpidMemberCreate
+
+EpidWritePreSigs
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidDecompressPrivKey (GroupPubKey const * pub_key,
CompressedPrivKey const * compressed_privkey,
PrivKeypriv_key 
)
+
+ +

Decompresses compressed member private key.

+

Converts a compressed member private key into a member private key for use by other member APIs.

+
Parameters
+ + + + +
[in]pub_keyThe public key of the group.
[in]compressed_privkeyThe compressed member private key to be decompressed.
[out]priv_keyThe member private key.
+
+
+
Returns
EpidStatus
+
Examples:
signmsg.c.
+
+
+
+ +
+
+ + + + + + + + +
size_t EpidGetNumPreSigs (MemberCtx const * ctx)
+
+ +

Gets the number of pre-computed signatures in the member's pool.

+
Parameters
+ + +
[in]ctxThe member context.
+
+
+
Returns
Number of remaining pre-computed signatures. Returns 0 if ctx is NULL.
+
See also
EpidMemberCreate
+
+EpidWritePreSigs
+ +
+
+ +
+
+ + + + + + + + +
size_t EpidGetSigSize (SigRl const * sig_rl)
+
+ +

Computes the size in bytes required for a Intel(R) EPID signature.

+
Parameters
+ + +
[in]sig_rlThe signature based revocation list that is used. NULL is treated as a zero length list.
+
+
+
Returns
Size in bytes of an Intel(R) EPID signature including proofs for each entry in the signature based revocation list.
+
See also
SigRl
+
Examples:
signmsg.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
bool EpidIsPrivKeyInGroup (GroupPubKey const * pub_key,
PrivKey const * priv_key 
)
+
+ +

Tests if a member private key is valid without checking revocation.

+

Used to check that a member private key is a valid key for a group. This is useful as a cross check when creating a new member private key as part of the join process

+
Parameters
+ + + +
[in]pub_keyThe public key of the group.
[in]priv_keyThe private key to check.
+
+
+
Returns
bool
+
Return values
+ + + +
trueif the private key is valid for the group of the public key
falseif the private key is not valid for the group of the public key
+
+
+
See also
EpidRequestJoin
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidMemberCreate (GroupPubKey const * pub_key,
PrivKey const * priv_key,
MemberPrecomp const * precomp,
BitSupplier rnd_func,
void * rnd_param,
MemberCtx ** ctx 
)
+
+ +

Creates a new member context.

+

Must be called to create the member context that is used by other "Member" APIs.

+

Allocates memory for the context, then initializes it.

+

EpidMemberDelete() must be called to safely release the member context.

+
Parameters
+ + + + + + + +
[in]pub_keyThe group certificate.
[in]priv_keyThe member private key.
[in]precompOptional pre-computed data. If NULL the value is computed internally and is readable using EpidMemberWritePrecomp().
[in]rnd_funcRandom number generator.
[in]rnd_paramPass through context data for rnd_func.
[out]ctxNewly constructed member context.
+
+
+
Returns
EpidStatus
+
Warning
For security rnd_func should be a cryptographically secure random number generator.
+
Note
If the result is not kEpidNoErr the content of ctx is undefined.
+
See also
EpidMemberDelete
+
+EpidMemberWritePrecomp
+
Examples:
signmsg.c.
+
+
+
+ +
+
+ + + + + + + + +
void EpidMemberDelete (MemberCtx ** ctx)
+
+ +

Deletes an existing member context.

+

Must be called to safely release a member context created using EpidMemberCreate().

+

De-initializes the context, frees memory used by the context, and sets the context pointer to NULL.

+
Parameters
+ + +
[in,out]ctxThe member context. Can be NULL.
+
+
+
See also
EpidMemberCreate
+
Examples:
signmsg.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
EpidStatus EpidMemberSetHashAlg (MemberCtxctx,
HashAlg hash_alg 
)
+
+ +

Sets the hash algorithm to be used by a member.

+
Parameters
+ + + +
[in]ctxThe member context.
[in]hash_algThe hash algorithm to use.
+
+
+
Returns
EpidStatus
+
Note
If the result is not kEpidNoErr, the hash algorithm used by the member is undefined.
+
See also
EpidMemberCreate
+
+HashAlg
+
Examples:
signmsg.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
EpidStatus EpidMemberWritePrecomp (MemberCtx const * ctx,
MemberPrecompprecomp 
)
+
+ +

Serializes the pre-computed member settings.

+
Parameters
+ + + +
[in]ctxThe member context.
[out]precompThe Serialized pre-computed member settings.
+
+
+
Returns
EpidStatus
+
Note
If the result is not kEpidNoErr, the content of precomp is undefined.
+
Examples:
signmsg.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidNrProve (MemberCtx const * ctx,
void const * msg,
size_t msg_len,
BasicSignature const * sig,
SigRlEntry const * sigrl_entry,
NrProofproof 
)
+
+ +

Calculates a non-revoked proof for a single signature based revocation list entry.

+

Used in constrained environments where, due to limited memory, it may not be possible to process through a large and potentially unbounded revocation list.

+
Parameters
+ + + + + + + +
[in]ctxThe member context.
[in]msgThe message.
[in]msg_lenThe length of message in bytes.
[in]sigThe basic signature.
[in]sigrl_entryThe signature based revocation list entry.
[out]proofThe generated non-revoked proof.
+
+
+
Returns
EpidStatus
+
Note
This function should be used in conjunction with EpidSignBasic().
+
+If the result is not kEpidNoErr, the content of proof is undefined.
+
See also
EpidMemberCreate
+
+EpidSignBasic
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidRegisterBaseName (MemberCtxctx,
void const * basename,
size_t basename_len 
)
+
+ +

Registers a basename with a member.

+

To prevent loss of privacy, the member keeps a list of basenames (corresponding to authorized verifiers). The member signs a message with a basename only if the basename is in the member's basename list.

+
Warning
The use of a name-based signature creates a platform unique pseudonymous identifier. Because it reduces the member's privacy, the user should be notified when it is used and should have control over its use.
+
Parameters
+ + + + +
[in]ctxThe member context.
[in]basenameThe basename.
[in]basename_lenLength of the basename.
+
+
+
Returns
EpidStatus
+
Return values
+ + +
kEpidDuplicateErrThe basename was already registered.
+
+
+
Note
If the result is not kEpidNoErr or kEpidDuplicateErr it is undefined if the basename is registered.
+
Examples:
signmsg.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidRequestJoin (GroupPubKey const * pub_key,
IssuerNonce const * ni,
FpElemStr const * f,
BitSupplier rnd_func,
void * rnd_param,
HashAlg hash_alg,
JoinRequestjoin_request 
)
+
+ +

Creates a request to join a group.

+

The created request is part of the interaction with an issuer needed to join a group. This interaction with the issuer is outside the scope of this API.

+
Parameters
+ + + + + + + + +
[in]pub_keyThe group certificate of group to join.
[in]niThe nonce chosen by issuer as part of join protocol.
[in]fA randomly selected integer in [1, p-1].
[in]rnd_funcRandom number generator.
[in]rnd_paramPass through context data for rnd_func.
[in]hash_algThe hash algorithm to be used.
[out]join_requestThe join request.
+
+
+
Returns
EpidStatus
+
Warning
For security rnd_func should be a cryptographically secure random number generator.
+
Note
The default hash algorithm in Member is SHA-512. This is the recommended option if you do not override the hash algorithm elsewhere.
+
+If the result is not kEpidNoErr, the content of join_request is undefined.
+
See also
HashAlg
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidSign (MemberCtx const * ctx,
void const * msg,
size_t msg_len,
void const * basename,
size_t basename_len,
SigRl const * sig_rl,
size_t sig_rl_size,
EpidSignaturesig,
size_t sig_len 
)
+
+ +

Writes a Intel(R) EPID signature.

+
Parameters
+ + + + + + + + + + +
[in]ctxThe member context.
[in]msgThe message to sign.
[in]msg_lenThe length in bytes of message.
[in]basenameOptional basename. If basename is NULL a random basename is used. Signatures generated using random basenames are anonymous. Signatures generated using the same basename are linkable by the verifier. If a basename is provided, it must already be registered, or kEpidBadArgErr is returned.
[in]basename_lenThe size of basename in bytes. Must be 0 basename is NULL.
[in]sig_rlThe signature based revocation list.
[in]sig_rl_sizeThe size in bytes of the signature based revocation list.
[out]sigThe generated signature
[in]sig_lenThe size of signature in bytes. Must be equal to value returned by EpidGetSigSize().
+
+
+
Returns
EpidStatus
+
Note
If the result is not kEpidNoErr the content of sig is undefined.
+
See also
EpidMemberCreate
+
+EpidMemberSetHashAlg
+
+EpidGetSigSize
+
Examples:
signmsg.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidSignBasic (MemberCtx const * ctx,
void const * msg,
size_t msg_len,
void const * basename,
size_t basename_len,
BasicSignaturesig 
)
+
+ +

Creates a basic signature for use in constrained environment.

+

Used in constrained environments where, due to limited memory, it may not be possible to process through a large and potentially unbounded revocation list.

+
Parameters
+ + + + + + + +
[in]ctxThe member context.
[in]msgThe message.
[in]msg_lenThe length of message in bytes.
[in]basenameOptional basename. If basename is NULL a random basename is used. Signatures generated using random basenames are anonymous. Signatures generated using the same basename are linkable by the verifier. If a basename is provided it must already be registered or kEpidBadArgErr is returned.
[in]basename_lenThe size of basename in bytes. Must be 0 basename is NULL.
[out]sigThe generated basic signature
+
+
+
Returns
EpidStatus
+
Note
This function should be used in conjunction with EpidNrProve()
+
+If the result is not kEpidNoErr the content of sig, is undefined.
+
See also
EpidMemberCreate
+
+EpidNrProve
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidWritePreSigs (MemberCtxctx,
PreComputedSignaturepresigs,
size_t number_presigs 
)
+
+ +

Serializes pre-computed signatures from the member's pool.

+

Removes requested number of pre-computed signatures from member's pool and stores them in presigs array. Use EpidAddPreSigs to add pre-computed signatures to the pool.

+
Parameters
+ + + + +
[in]ctxThe member context.
[out]presigsAn existing buffer of pre-computed signatures.
[in]number_presigsNumber of pre-computed signatures to read. Number_presigs must not be greater than the value returned by EpidGetNumPreSigs.
+
+
+
Returns
EpidStatus
+
Note
If the result is not kEpidNoErr the state of the pre-computed signature pool, and of presigs, is undefined.
+
See also
EpidMemberCreate
+
+EpidGetNumPreSigs
+
+EpidAddPreSigs
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_member_module.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_member_module.js new file mode 100644 index 0000000000..1a6c7f47ae --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_member_module.js @@ -0,0 +1,37 @@ +var group___epid_member_module = +[ + [ "MemberPrecomp", "struct_member_precomp.html", [ + [ "e12", "struct_member_precomp.html#a55e5c4b25c8f0f426969a8d745260fe5", null ], + [ "e22", "struct_member_precomp.html#a4e7412969bed3964f813b093b948e7b4", null ], + [ "e2w", "struct_member_precomp.html#a879d5a7b0c30088b23f6e5c5fc62f834", null ], + [ "ea2", "struct_member_precomp.html#a573551f6494e372f44fd3bdf5b02aeda", null ] + ] ], + [ "PreComputedSignature", "struct_pre_computed_signature.html", [ + [ "a", "struct_pre_computed_signature.html#af23f3f9693857a33fe8564644612ea37", null ], + [ "B", "struct_pre_computed_signature.html#a9cc2eb61572a1aca9e6bc3d5e6f4c1fe", null ], + [ "b", "struct_pre_computed_signature.html#a666710432d9d54ca896647a976892c4f", null ], + [ "K", "struct_pre_computed_signature.html#a2a4eaffe2717bd9c8c360599612adbe6", null ], + [ "R1", "struct_pre_computed_signature.html#a72be597624957e3d668c95ff6f445f94", null ], + [ "R2", "struct_pre_computed_signature.html#a79f06fb57842597372e00dd34c1a804a", null ], + [ "ra", "struct_pre_computed_signature.html#a54462643b8a2b4f2741bf8d2e6909d11", null ], + [ "rb", "struct_pre_computed_signature.html#a6a1db672c609943fe7af84320dc68ba3", null ], + [ "rf", "struct_pre_computed_signature.html#ac244bd559a96812bcee7671abc299b66", null ], + [ "rx", "struct_pre_computed_signature.html#acd0674d5b5e96244645e9abef7bdbddc", null ], + [ "T", "struct_pre_computed_signature.html#a73471643dc757115701833ca2e831a72", null ] + ] ], + [ "EpidAddPreSigs", "group___epid_member_module.html#gad2e3de5c6ce641a318f8a46b61e75236", null ], + [ "EpidDecompressPrivKey", "group___epid_member_module.html#gaf8cd05388f017486f14da2ee48d067ef", null ], + [ "EpidGetNumPreSigs", "group___epid_member_module.html#gad78ca056dfea2565bbacd5734d9dc075", null ], + [ "EpidGetSigSize", "group___epid_member_module.html#ga76e535722467af7c16809b5b521e0000", null ], + [ "EpidIsPrivKeyInGroup", "group___epid_member_module.html#ga8e3f201d1e9dc668659e08a3bdf543b6", null ], + [ "EpidMemberCreate", "group___epid_member_module.html#ga561c4d544a78ee1bf59c3f4f919aa7bb", null ], + [ "EpidMemberDelete", "group___epid_member_module.html#ga3824589c683c5e0e59d483462fce65d6", null ], + [ "EpidMemberSetHashAlg", "group___epid_member_module.html#ga9998eb454838ff5d232ff22ecbab31bf", null ], + [ "EpidMemberWritePrecomp", "group___epid_member_module.html#ga5c35798d62cf81c4ca62b22c38809721", null ], + [ "EpidNrProve", "group___epid_member_module.html#gac8e2c6c1fead8030785a40427905a2cc", null ], + [ "EpidRegisterBaseName", "group___epid_member_module.html#gad92d3c3266ae1833ffb1dba9ad76035d", null ], + [ "EpidRequestJoin", "group___epid_member_module.html#ga13dd0d72be9babf8194d472d7712a361", null ], + [ "EpidSign", "group___epid_member_module.html#ga759155a719254f734157722716dac640", null ], + [ "EpidSignBasic", "group___epid_member_module.html#gae04a250d5981fcf9bd6f9f57e0468faa", null ], + [ "EpidWritePreSigs", "group___epid_member_module.html#ga9e12c7cec8d0c4e07b12c0e26a278c9d", null ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_module.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_module.html new file mode 100644 index 0000000000..3b36d18879 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_module.html @@ -0,0 +1,97 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
epid
+
+
+ +

Core Intel® EPID functionality. +More...

+ + + + + + + + + + + +

+Modules

 common
 Common code shared between core sub-components.
 
 member
 Member functionality.
 
 verifier
 Verifier functionality.
 
+

Detailed Description

+

Core Intel® EPID functionality.

+

Contains core functionality used to provide or implement APIs in the Intel(R) EPID SDK.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_module.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_module.js new file mode 100644 index 0000000000..892eddf409 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_module.js @@ -0,0 +1,6 @@ +var group___epid_module = +[ + [ "common", "group___epid_common.html", "group___epid_common" ], + [ "member", "group___epid_member_module.html", "group___epid_member_module" ], + [ "verifier", "group___epid_verifier_module.html", "group___epid_verifier_module" ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_print.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_print.html new file mode 100644 index 0000000000..f4b0a4d894 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_print.html @@ -0,0 +1,660 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: print_utils + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
print_utils
+
+
+ +

Debug print routines. +More...

+ + + + + +

+Enumerations

enum  PrintUtilFormat { kPrintUtilUnannotated = 0, +kPrintUtilAnnotated = 1 + }
 Print format. More...
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

void PrintBigNum (BigNum const *big_num, char const *var_name)
 Prints BigNum. More...
 
void PrintFfElement (FiniteField const *ff, FfElement const *ff_element, char const *var_name, PrintUtilFormat format)
 Prints finite field element. More...
 
void PrintEcPoint (EcGroup const *g, EcPoint const *ec_point, char const *var_name, PrintUtilFormat format)
 Prints elliptic curve group element. More...
 
void PrintBigNumStr (BigNumStr const *big_num_str, char const *var_name)
 Prints serialized BigNum. More...
 
void PrintFpElemStr (FpElemStr const *fp_elem_str, char const *var_name)
 Prints serialized Fp element. More...
 
void PrintFqElemStr (FqElemStr const *fq_elem_str, char const *var_name)
 Prints serialized Fq element. More...
 
void PrintFq2ElemStr (Fq2ElemStr const *fq2_elem_str, char const *var_name, PrintUtilFormat format)
 Prints serialized Fq2 element. More...
 
void PrintFq6ElemStr (Fq6ElemStr const *fq6_elem_str, char const *var_name, PrintUtilFormat format)
 Prints serialized Fq6 element. More...
 
void PrintFq12ElemStr (Fq12ElemStr const *fq12_elem_str, char const *var_name, PrintUtilFormat format)
 Prints serialized Fq12 element. More...
 
void PrintG1ElemStr (G1ElemStr const *g1_elem_str, char const *var_name, PrintUtilFormat format)
 Prints serialized G1 element. More...
 
void PrintG2ElemStr (G2ElemStr const *g2_elem_str, char const *var_name, PrintUtilFormat format)
 Prints serialized G2 element. More...
 
void PrintGtElemStr (GtElemStr const *gt_elem_str, char const *var_name, PrintUtilFormat format)
 Prints serialized Gt element. More...
 
+

Detailed Description

+

Debug print routines.

+

Defines an API to print formatted versions of the types used for mathematical operations.

+

If the symbol EPID_ENABLE_DEBUG_PRINT is not defined, all calls to the functions in this module are ignored.

+

Enumeration Type Documentation

+ +
+
+ + + + +
enum PrintUtilFormat
+
+ +

Print format.

+ + + +
Enumerator
kPrintUtilUnannotated  +

Unannotated output format.

+
kPrintUtilAnnotated  +

Annotated output format.

+
+ +
+
+

Function Documentation

+ +
+
+ + + + + + + + + + + + + + + + + + +
void PrintBigNum (BigNum const * big_num,
char const * var_name 
)
+
+ +

Prints BigNum.

+

Macro EPID_ENABLE_DEBUG_PRINT needs to be defined in order to activate this routine; otherwise, it prints nothing.

+
Parameters
+ + + +
[in]big_numBigNum to be printed
[in]var_nameResult variable name
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
void PrintBigNumStr (BigNumStr const * big_num_str,
char const * var_name 
)
+
+ +

Prints serialized BigNum.

+

Macro EPID_ENABLE_DEBUG_PRINT needs to be defined in order to activate this routine; otherwise, it prints nothing.

+
Parameters
+ + + +
[in]big_num_strSerialized BigNum to be printed
[in]var_nameResult variable name
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void PrintEcPoint (EcGroup const * g,
EcPoint const * ec_point,
char const * var_name,
PrintUtilFormat format 
)
+
+ +

Prints elliptic curve group element.

+

Macro EPID_ENABLE_DEBUG_PRINT needs to be defined in order to activate this routine; otherwise, it prints nothing.

+
Parameters
+ + + + + +
[in]gElliptic curve group that element to be printed belongs to
[in]ec_pointElliptic curve group element to be printed
[in]var_nameResult variable name
[in]formatOutput format
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void PrintFfElement (FiniteField const * ff,
FfElement const * ff_element,
char const * var_name,
PrintUtilFormat format 
)
+
+ +

Prints finite field element.

+

Macro EPID_ENABLE_DEBUG_PRINT needs to be defined in order to activate this routine; otherwise, it prints nothing.

+
Parameters
+ + + + + +
[in]ffFinite field that element to be printed belongs to
[in]ff_elementFinite field element to be printed
[in]var_nameResult variable name
[in]formatOutput format
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
void PrintFpElemStr (FpElemStr const * fp_elem_str,
char const * var_name 
)
+
+ +

Prints serialized Fp element.

+

Macro EPID_ENABLE_DEBUG_PRINT needs to be defined in order to activate this routine; otherwise, it prints nothing.

+
Parameters
+ + + +
[in]fp_elem_strSerialized Fp element to be printed
[in]var_nameResult variable name
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
void PrintFq12ElemStr (Fq12ElemStr const * fq12_elem_str,
char const * var_name,
PrintUtilFormat format 
)
+
+ +

Prints serialized Fq12 element.

+

Macro EPID_ENABLE_DEBUG_PRINT needs to be defined in order to activate this routine; otherwise, it prints nothing.

+
Parameters
+ + + + +
[in]fq12_elem_strSerialized Intel(R) EPID Fq12 element to be printed
[in]var_nameResult variable name
[in]formatOutput format
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
void PrintFq2ElemStr (Fq2ElemStr const * fq2_elem_str,
char const * var_name,
PrintUtilFormat format 
)
+
+ +

Prints serialized Fq2 element.

+

Macro EPID_ENABLE_DEBUG_PRINT needs to be defined in order to activate this routine; otherwise, it prints nothing.

+
Parameters
+ + + + +
[in]fq2_elem_strSerialized Fq2 element to be printed
[in]var_nameResult variable name
[in]formatOutput format
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
void PrintFq6ElemStr (Fq6ElemStr const * fq6_elem_str,
char const * var_name,
PrintUtilFormat format 
)
+
+ +

Prints serialized Fq6 element.

+

Macro EPID_ENABLE_DEBUG_PRINT needs to be defined in order to activate this routine; otherwise, it prints nothing.

+
Parameters
+ + + + +
[in]fq6_elem_strSerialized Fq6 element to be printed
[in]var_nameResult variable name
[in]formatOutput format
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
void PrintFqElemStr (FqElemStr const * fq_elem_str,
char const * var_name 
)
+
+ +

Prints serialized Fq element.

+

Macro EPID_ENABLE_DEBUG_PRINT needs to be defined in order to activate this routine; otherwise, it prints nothing.

+
Parameters
+ + + +
[in]fq_elem_strSerialized Fq element to be printed
[in]var_nameResult variable name
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
void PrintG1ElemStr (G1ElemStr const * g1_elem_str,
char const * var_name,
PrintUtilFormat format 
)
+
+ +

Prints serialized G1 element.

+

Macro EPID_ENABLE_DEBUG_PRINT needs to be defined in order to activate this routine; otherwise, it prints nothing.

+
Parameters
+ + + + +
[in]g1_elem_strSerialized G1 element to be printed
[in]var_nameResult variable name
[in]formatOutput format
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
void PrintG2ElemStr (G2ElemStr const * g2_elem_str,
char const * var_name,
PrintUtilFormat format 
)
+
+ +

Prints serialized G2 element.

+

Macro EPID_ENABLE_DEBUG_PRINT needs to be defined in order to activate this routine; otherwise, it prints nothing.

+
Parameters
+ + + + +
[in]g2_elem_strSerialized G2 element to be printed
[in]var_nameResult variable name
[in]formatOutput format
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
void PrintGtElemStr (GtElemStr const * gt_elem_str,
char const * var_name,
PrintUtilFormat format 
)
+
+ +

Prints serialized Gt element.

+

Macro EPID_ENABLE_DEBUG_PRINT needs to be defined in order to activate this routine; otherwise, it prints nothing.

+
Parameters
+ + + + +
[in]gt_elem_strSerialized G2 element to be printed
[in]var_nameResult variable name
[in]formatOutput format
+
+
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_print.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_print.js new file mode 100644 index 0000000000..00d8c84e1f --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_print.js @@ -0,0 +1,19 @@ +var group___epid_print = +[ + [ "PrintUtilFormat", "group___epid_print.html#ga3e215d157eb205ad596bb84bce694a83", [ + [ "kPrintUtilUnannotated", "group___epid_print.html#gga3e215d157eb205ad596bb84bce694a83aeb475b793d8d357087d7fcc74702ffae", null ], + [ "kPrintUtilAnnotated", "group___epid_print.html#gga3e215d157eb205ad596bb84bce694a83ae2d5345c14f57fc992a613003c3c443d", null ] + ] ], + [ "PrintBigNum", "group___epid_print.html#ga45a933b44fc1dfe926e3af89c198070a", null ], + [ "PrintBigNumStr", "group___epid_print.html#ga5f249c594ed12e4a9b11b7bc101da85d", null ], + [ "PrintEcPoint", "group___epid_print.html#ga0d6377d9c1651d0101ec6b61feaa78ca", null ], + [ "PrintFfElement", "group___epid_print.html#gaa3b1cbbfc6f78562658953113e5798cf", null ], + [ "PrintFpElemStr", "group___epid_print.html#gae553c3a156a0e4968b89635ab0757580", null ], + [ "PrintFq12ElemStr", "group___epid_print.html#gaf185fe3df270cd8b4a2969bf3cfc5d5f", null ], + [ "PrintFq2ElemStr", "group___epid_print.html#ga883a834ab1703365bb0bca4abd3104de", null ], + [ "PrintFq6ElemStr", "group___epid_print.html#ga3f2961ef6b4c44a6205d422d8a293476", null ], + [ "PrintFqElemStr", "group___epid_print.html#ga6c9fea48fa0477f4a98abb50f891a5e4", null ], + [ "PrintG1ElemStr", "group___epid_print.html#ga87168a3ce5306f9839b8e8d6c9a5f84f", null ], + [ "PrintG2ElemStr", "group___epid_print.html#gab76a4cf0385dc4a76bb56ee9f0e3e87a", null ], + [ "PrintGtElemStr", "group___epid_print.html#ga138cd388247a58680d4701d59d6976d2", null ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_types.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_types.html new file mode 100644 index 0000000000..efdfd1d41b --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_types.html @@ -0,0 +1,266 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: types + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+ +
+ +

SDK data types. +More...

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Data Structures

struct  OctStr8
 8 bit octet string More...
 
struct  OctStr16
 16 bit octet string More...
 
struct  OctStr32
 32 bit octet string More...
 
struct  OctStr64
 64 bit octet string More...
 
struct  OctStr128
 128 bit octet string More...
 
struct  OctStr256
 256 bit octet string More...
 
struct  OctStr512
 512 bit octet string More...
 
struct  BigNumStr
 Serialized BigNum. More...
 
struct  FpElemStr
 a number in [0, p-1] More...
 
struct  FqElemStr
 a number in [0, q-1] More...
 
struct  G1ElemStr
 Serialized G1 element. More...
 
struct  G2ElemStr
 Serialized G2 element. More...
 
struct  GtElemStr
 Serialized GT element. More...
 
struct  Epid2Params
 Intel(R) EPID 2.0 Parameters. More...
 
struct  GroupPubKey
 Intel(R) EPID 2.0 group public key. More...
 
struct  IPrivKey
 Intel(R) EPID 2.0 issuing private key. More...
 
struct  PrivKey
 Intel(R) EPID 2.0 private key. More...
 
struct  CompressedPrivKey
 Compressed private key. More...
 
struct  MembershipCredential
 Membership credential. More...
 
struct  JoinRequest
 Join request. More...
 
struct  BasicSignature
 Intel(R) EPID 2.0 basic signature. More...
 
struct  NrProof
 non-revoked Proof. More...
 
struct  EpidSignature
 Intel(R) EPID 2.0 Signature. More...
 
struct  PrivRl
 private-key based revocation list. More...
 
struct  SigRlEntry
 entry in SigRL (B,K) More...
 
struct  SigRl
 signature based revocation list More...
 
struct  GroupRl
 group revocation list More...
 
struct  VerifierRl
 
struct  Fq2ElemStr
 Serialized Fq2 element. More...
 
struct  Fq6ElemStr
 Serialized Fq2^3 element. More...
 
struct  Fq12ElemStr
 Serialized Fq2^3^2 element. More...
 
struct  EcdsaSignature
 ECDSA Signature using NIST 256-bit curve secp256r1. More...
 
struct  EcdsaPublicKey
 ECDSA Public Key. More...
 
struct  EcdsaPrivateKey
 ECDSA Private Key. More...
 
+ + + + + + + + + + + + + +

+Typedefs

+typedef OctStr128 GroupId
 group ID
 
+typedef OctStr256 Seed
 256 bit seed derived from fuse key
 
+typedef OctStr256 IssuerNonce
 256 bit nonce chosen by issuer
 
+typedef G1ElemStr ReKeySeed
 element to store seed values for later rekey
 
+ + + + +

+Enumerations

enum  HashAlg {
+  kSha256 = 0, +kSha384 = 1, +kSha512 = 2, +kSha512_256 = 3, +
+  kSha3_256 = 4, +kSha3_384 = 5, +kSha3_512 = 6 +
+ }
 Recognized hash algorithms. More...
 
+

Detailed Description

+

SDK data types.

+

Defines serialized data types used by the SDK.

+

Most of the types defined here are fixed size binary buffers of various sizes that are semantically mapped to the types of various inputs to the EPID APIs.

+

For example GtElemStr is a 384 byte buffer that represents a serialized value that is compatible with a FfElement belonging to the FiniteField GT.

+

Enumeration Type Documentation

+ +
+
+ + + + +
enum HashAlg
+
+ +

Recognized hash algorithms.

+ + + + + + + + +
Enumerator
kSha256  +

SHA-256.

+
kSha384  +

SHA-384.

+
kSha512  +

SHA-512.

+
kSha512_256  +

SHA-512/256.

+
kSha3_256  +

Reserved for SHA3/256.

+
kSha3_384  +

Reserved for SHA3/384.

+
kSha3_512  +

Reserved for SHA3/512.

+
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_types.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_types.js new file mode 100644 index 0000000000..f473312478 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_types.js @@ -0,0 +1,169 @@ +var group___epid_types = +[ + [ "OctStr8", "struct_oct_str8.html", [ + [ "data", "struct_oct_str8.html#a5e6c56fda48c88b419e621b464b03bef", null ] + ] ], + [ "OctStr16", "struct_oct_str16.html", [ + [ "data", "struct_oct_str16.html#a86ed6671693a3f60ec4ff7de2c1206c3", null ] + ] ], + [ "OctStr32", "struct_oct_str32.html", [ + [ "data", "struct_oct_str32.html#a5588a7e70f3d73f6ce58b567a9f5c5c8", null ] + ] ], + [ "OctStr64", "struct_oct_str64.html", [ + [ "data", "struct_oct_str64.html#a0e107d78192a5ae0b48ed9e5c4eab0fc", null ] + ] ], + [ "OctStr128", "struct_oct_str128.html", [ + [ "data", "struct_oct_str128.html#a7482aa9b0b580fdd50bd65419d52d4b9", null ] + ] ], + [ "OctStr256", "struct_oct_str256.html", [ + [ "data", "struct_oct_str256.html#a359781bb84f5717a16094583a00ef14e", null ] + ] ], + [ "OctStr512", "struct_oct_str512.html", [ + [ "data", "struct_oct_str512.html#abd4d1b97fe49321571da86de1aeac653", null ] + ] ], + [ "BigNumStr", "struct_big_num_str.html", [ + [ "data", "struct_big_num_str.html#a442dcf33889b4f85c5b1228d2c8e6838", null ] + ] ], + [ "FpElemStr", "struct_fp_elem_str.html", [ + [ "data", "struct_fp_elem_str.html#a5ddb96a5567750f2834335851c906c45", null ] + ] ], + [ "FqElemStr", "struct_fq_elem_str.html", [ + [ "data", "struct_fq_elem_str.html#aac1a876b51a8d2c6d1510e4df2fd3f14", null ] + ] ], + [ "G1ElemStr", "struct_g1_elem_str.html", [ + [ "x", "struct_g1_elem_str.html#a3b0e658d6e5697763ad9c633c11d4ec4", null ], + [ "y", "struct_g1_elem_str.html#a8f2455ca314e885ea180dadf84bf27c3", null ] + ] ], + [ "G2ElemStr", "struct_g2_elem_str.html", [ + [ "x", "struct_g2_elem_str.html#a145ec5b20a6f4f00b080e11c8680afc3", null ], + [ "y", "struct_g2_elem_str.html#a43141b2458aecceed8ee2748270f7908", null ] + ] ], + [ "GtElemStr", "struct_gt_elem_str.html", [ + [ "x", "struct_gt_elem_str.html#aeaeb0e9e1c6efd378a475eb9a6c42132", null ] + ] ], + [ "Epid2Params", "struct_epid2_params.html", [ + [ "b", "struct_epid2_params.html#a2f868edb49be49f645101ef5ebbbc551", null ], + [ "beta", "struct_epid2_params.html#ac2d7507c6f58c3451beacacb91b52695", null ], + [ "g1", "struct_epid2_params.html#a4c5195b4fa9393a07a121336202531ad", null ], + [ "g2", "struct_epid2_params.html#a609b0aac17fca34fe39bee29676a9618", null ], + [ "neg", "struct_epid2_params.html#af23f07fb0e1745c0ad14aceeaa946928", null ], + [ "p", "struct_epid2_params.html#ac0e0dad45b10927860cd5fa4f8101f08", null ], + [ "q", "struct_epid2_params.html#a023603228fed2854ddae2e228938940f", null ], + [ "t", "struct_epid2_params.html#a200a0cba1c9e4ad512bece23f2461a5f", null ], + [ "xi", "struct_epid2_params.html#ae1d8f5d6036a82064e91bc137b278e74", null ] + ] ], + [ "GroupPubKey", "struct_group_pub_key.html", [ + [ "gid", "struct_group_pub_key.html#ae8e77ab4d5eb3c8e566c24a64cce56ee", null ], + [ "h1", "struct_group_pub_key.html#a8c22c758ea186f95e3bf4b2ef8451da5", null ], + [ "h2", "struct_group_pub_key.html#a2a4320ec99fd1a15df412fbf2a8d49f1", null ], + [ "w", "struct_group_pub_key.html#a86be439104fb60b324784baf24a943f9", null ] + ] ], + [ "IPrivKey", "struct_i_priv_key.html", [ + [ "gamma", "struct_i_priv_key.html#a6d484175317aef09fb959c3ca55fc70a", null ], + [ "gid", "struct_i_priv_key.html#ad400a4237b6d50855538fd40580eb1bb", null ] + ] ], + [ "PrivKey", "struct_priv_key.html", [ + [ "A", "struct_priv_key.html#a266c7e369b8b868ef5755e9cd3c0c849", null ], + [ "f", "struct_priv_key.html#ad7ee0392a583edd2e287cf8c1f9066ba", null ], + [ "gid", "struct_priv_key.html#ab416dcb4366427c24b44c2a02e4ae7c8", null ], + [ "x", "struct_priv_key.html#aa805f9e124f05bdb733c85cb93614cbd", null ] + ] ], + [ "CompressedPrivKey", "struct_compressed_priv_key.html", [ + [ "ax", "struct_compressed_priv_key.html#a0b0535f0567eb0e48f799d27991d0f66", null ], + [ "gid", "struct_compressed_priv_key.html#ac6689899f1d9a6a8c5e4915563679840", null ], + [ "seed", "struct_compressed_priv_key.html#a54b9af7699f517bbaef3d52d03e3fed8", null ] + ] ], + [ "MembershipCredential", "struct_membership_credential.html", [ + [ "A", "struct_membership_credential.html#a6d38ac3a9c5417833b8adb9b22bc9dc8", null ], + [ "gid", "struct_membership_credential.html#afbff64ec55888c7e2a658eabb5e16671", null ], + [ "x", "struct_membership_credential.html#a2c5c0d22999d6917fea5ad6618883bcf", null ] + ] ], + [ "JoinRequest", "struct_join_request.html", [ + [ "c", "struct_join_request.html#a55e30a274e83b808db6fbab5ae6c6cb8", null ], + [ "F", "struct_join_request.html#a005651506fd4511e8a3537f6c3634532", null ], + [ "s", "struct_join_request.html#a73bf8989df5f90eb3d06e7a42ad74d1d", null ] + ] ], + [ "BasicSignature", "struct_basic_signature.html", [ + [ "B", "struct_basic_signature.html#ae90cb6af66b010ae39913f033c1e65ac", null ], + [ "c", "struct_basic_signature.html#a4daa94db5068db3f10960f3dd178d603", null ], + [ "K", "struct_basic_signature.html#a0078cc83ecf6c7e31f96b7d44aa60e21", null ], + [ "sa", "struct_basic_signature.html#a69115a4776d15b48411dd6c3a76d0f3d", null ], + [ "sb", "struct_basic_signature.html#a91daebc5b577688afeed2a7ee7913245", null ], + [ "sf", "struct_basic_signature.html#a79d8dec8c5da176e497abf22e4c43adb", null ], + [ "sx", "struct_basic_signature.html#a0e8ea6a2cd3af10e9b59d96d7d06bc69", null ], + [ "T", "struct_basic_signature.html#a730f74d85cfb4fa4089d43c87b97a624", null ] + ] ], + [ "NrProof", "struct_nr_proof.html", [ + [ "c", "struct_nr_proof.html#a0de1aa69acf3d93da34cf4a613b359a1", null ], + [ "smu", "struct_nr_proof.html#a717ec36a6c91acd01d9b642bb20fc178", null ], + [ "snu", "struct_nr_proof.html#ae2e9f22089793a4d44a0f7f5cdb78a0c", null ], + [ "T", "struct_nr_proof.html#ace535065bbf96502b893ac677dc8dcd3", null ] + ] ], + [ "EpidSignature", "struct_epid_signature.html", [ + [ "n2", "struct_epid_signature.html#a62a6b0ffcd5f68dd3d2786a58fe43017", null ], + [ "rl_ver", "struct_epid_signature.html#a4155f3f4f1223fc4ae50c94f5305def1", null ], + [ "sigma", "struct_epid_signature.html#a89d2e38223944310b6eeeadf6061a2dd", null ], + [ "sigma0", "struct_epid_signature.html#ab0fe5f98bff737fcfbfe0b4d658e83f2", null ] + ] ], + [ "PrivRl", "struct_priv_rl.html", [ + [ "f", "struct_priv_rl.html#a60d73f9ef5fc81f117b3abadf8c18466", null ], + [ "gid", "struct_priv_rl.html#af7317529b8e55476bd06b66ed8131d64", null ], + [ "n1", "struct_priv_rl.html#a6da9639ec4061689d1c30a58e0befd14", null ], + [ "version", "struct_priv_rl.html#a4c6b51cec760f7e81ca8635422ac6a50", null ] + ] ], + [ "SigRlEntry", "struct_sig_rl_entry.html", [ + [ "b", "struct_sig_rl_entry.html#ac6a47ff0d1b8ea1512e0ff14983ac5ce", null ], + [ "k", "struct_sig_rl_entry.html#a0dfeb058614e81878bfbf86ae3edac3c", null ] + ] ], + [ "SigRl", "struct_sig_rl.html", [ + [ "bk", "struct_sig_rl.html#ac23a919993d99d24a5150302f1778102", null ], + [ "gid", "struct_sig_rl.html#a12757d30fcccd310716433948e0b603e", null ], + [ "n2", "struct_sig_rl.html#a9dfb6b508db9051f4dc480a51d702af2", null ], + [ "version", "struct_sig_rl.html#ac9d4c343c539dba799e1f42eb38b351f", null ] + ] ], + [ "GroupRl", "struct_group_rl.html", [ + [ "gid", "struct_group_rl.html#a51022e172ab8b945efc69f1e63170107", null ], + [ "n3", "struct_group_rl.html#a9067f01c63cdefbc8e23c3cf67a10172", null ], + [ "version", "struct_group_rl.html#a69c41d99cdfc5b6ece7442f466f7ec3f", null ] + ] ], + [ "VerifierRl", "struct_verifier_rl.html", [ + [ "B", "struct_verifier_rl.html#a5d9a9265fffa96fd5f9260543eb08c68", null ], + [ "gid", "struct_verifier_rl.html#ab85c4666d16145ff16443e84468d2d7d", null ], + [ "K", "struct_verifier_rl.html#ac7d3dceab4772096bbbeb3fa735d18a9", null ], + [ "n4", "struct_verifier_rl.html#a1e3f84b873bccc0c882aa6432c42d2f7", null ], + [ "version", "struct_verifier_rl.html#afa44ab69ffff5a3508366aeb2131fdaa", null ] + ] ], + [ "Fq2ElemStr", "struct_fq2_elem_str.html", [ + [ "a", "struct_fq2_elem_str.html#ab1d253eb24ba30eaf516ac429daab915", null ] + ] ], + [ "Fq6ElemStr", "struct_fq6_elem_str.html", [ + [ "a", "struct_fq6_elem_str.html#a89d656e5c815b4a2382d11ef6932a7d2", null ] + ] ], + [ "Fq12ElemStr", "struct_fq12_elem_str.html", [ + [ "a", "struct_fq12_elem_str.html#a0520947335aaf52de90af1dec5bdd112", null ] + ] ], + [ "EcdsaSignature", "struct_ecdsa_signature.html", [ + [ "x", "struct_ecdsa_signature.html#a64b623605a55a267a36df18f29142d0d", null ], + [ "y", "struct_ecdsa_signature.html#a2efd6bf37b12f35135bf325fa491b029", null ] + ] ], + [ "EcdsaPublicKey", "struct_ecdsa_public_key.html", [ + [ "x", "struct_ecdsa_public_key.html#a37c51614faf022eec491b4de8f3a13e1", null ], + [ "y", "struct_ecdsa_public_key.html#a4503c4613386cbc78add1dc245c99284", null ] + ] ], + [ "EcdsaPrivateKey", "struct_ecdsa_private_key.html", [ + [ "data", "struct_ecdsa_private_key.html#a97efee9b4079f95d94a104f9a6d8c96d", null ] + ] ], + [ "GroupId", "group___epid_types.html#gada666b48d0cbc301985405fde896f1de", null ], + [ "IssuerNonce", "group___epid_types.html#ga55eb2193045bde31af3f551565126042", null ], + [ "ReKeySeed", "group___epid_types.html#ga54bd22670f2e348593db7ab631131d10", null ], + [ "Seed", "group___epid_types.html#ga888541b8148df69c634a92c64ed51317", null ], + [ "HashAlg", "group___epid_types.html#ga5e450438f6f9a5eacd0cf5ce354ec890", [ + [ "kSha256", "group___epid_types.html#gga5e450438f6f9a5eacd0cf5ce354ec890aefb89989305b5c34120b0f18ee8e2c5d", null ], + [ "kSha384", "group___epid_types.html#gga5e450438f6f9a5eacd0cf5ce354ec890a0f4dde6e82b84f5769873f6704fcd290", null ], + [ "kSha512", "group___epid_types.html#gga5e450438f6f9a5eacd0cf5ce354ec890afb78d98f37fecc53dd1637d94c5c0055", null ], + [ "kSha512_256", "group___epid_types.html#gga5e450438f6f9a5eacd0cf5ce354ec890a9746b5049a62bca2f7b844925e6136ba", null ], + [ "kSha3_256", "group___epid_types.html#gga5e450438f6f9a5eacd0cf5ce354ec890a4fa16d3867498f5e2f8ae5c94b0fab85", null ], + [ "kSha3_384", "group___epid_types.html#gga5e450438f6f9a5eacd0cf5ce354ec890a90d21c8885ab138f7cf91f253dd6ef86", null ], + [ "kSha3_512", "group___epid_types.html#gga5e450438f6f9a5eacd0cf5ce354ec890ade8e74cf7910b3a71fe902a40abf7eee", null ] + ] ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_verifier_module.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_verifier_module.html new file mode 100644 index 0000000000..1e2f5d1f79 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_verifier_module.html @@ -0,0 +1,834 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: verifier + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
verifier
+
+
+ +

Verifier functionality. +More...

+ + + + + +

+Data Structures

struct  VerifierPrecomp
 Pre-computed member settings. More...
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

EpidStatus EpidVerifierCreate (GroupPubKey const *pub_key, VerifierPrecomp const *precomp, VerifierCtx **ctx)
 Creates a new verifier context. More...
 
void EpidVerifierDelete (VerifierCtx **ctx)
 Deletes an existing verifier context. More...
 
EpidStatus EpidVerifierWritePrecomp (VerifierCtx const *ctx, VerifierPrecomp *precomp)
 Serializes the pre-computed verifier settings. More...
 
EpidStatus EpidVerifierSetPrivRl (VerifierCtx *ctx, PrivRl const *priv_rl, size_t priv_rl_size)
 Sets the private key based revocation list. More...
 
EpidStatus EpidVerifierSetSigRl (VerifierCtx *ctx, SigRl const *sig_rl, size_t sig_rl_size)
 Sets the signature based revocation list. More...
 
EpidStatus EpidVerifierSetGroupRl (VerifierCtx *ctx, GroupRl const *grp_rl, size_t grp_rl_size)
 Sets the group based revocation list. More...
 
EpidStatus EpidVerifierSetVerifierRl (VerifierCtx *ctx, VerifierRl const *ver_rl, size_t ver_rl_size)
 Sets the verifier revocation list. More...
 
EpidStatus EpidVerifierSetHashAlg (VerifierCtx *ctx, HashAlg hash_alg)
 Sets the hash algorithm to be used by a verifier. More...
 
EpidStatus EpidVerify (VerifierCtx const *ctx, EpidSignature const *sig, size_t sig_len, void const *msg, size_t msg_len, void const *basename, size_t basename_len)
 Verifies a signature and checks revocation status. More...
 
bool EpidAreSigsLinked (BasicSignature const *sig1, BasicSignature const *sig2)
 Determines if two signatures are linked. More...
 
EpidStatus EpidVerifyBasicSig (VerifierCtx const *ctx, BasicSignature const *sig, void const *msg, size_t msg_len, void const *basename, size_t basename_len)
 Verifies a member signature without revocation checks. More...
 
EpidStatus EpidNrVerify (VerifierCtx const *ctx, BasicSignature const *sig, void const *msg, size_t msg_len, SigRlEntry const *sigrl_entry, NrProof const *proof)
 Verifies the non-revoked proof for a single signature based revocation list entry. More...
 
EpidStatus EpidCheckPrivRlEntry (VerifierCtx const *ctx, BasicSignature const *sig, FpElemStr const *f)
 Verifies a signature has not been revoked in the private key based revocation list. More...
 
+

Detailed Description

+

Verifier functionality.

+

Defines the APIs needed by Intel(R) EPID verifiers. Each verifier context (VerifierCtx) represents a verifier for a single group.

+

Function Documentation

+ +
+
+ + + + + + + + + + + + + + + + + + +
bool EpidAreSigsLinked (BasicSignature const * sig1,
BasicSignature const * sig2 
)
+
+ +

Determines if two signatures are linked.

+

The Intel(R) EPID scheme allows signatures to be linked. If basename option is specified when signing, signatures with the same basename are linkable. This linking capability allows the verifier, or anyone, to know whether two Intel(R) EPID signatures are generated by the same member.

+
Parameters
+ + + +
[in]sig1A basic signature.
[in]sig2A basic signature.
+
+
+
Returns
bool
+
Return values
+ + + +
trueif the signatures were generated by the same member
falseif it couldn't be determined if the signatures were generated by the same member
+
+
+
Note
The input signatures should be verified using EpidVerifyBasicSig() before invocation. Behavior is undefined if either of the signatures cannot be verified.
+
See also
EpidVerifyBasicSig
+
+EpidSignBasic
+
+EpidSign
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidCheckPrivRlEntry (VerifierCtx const * ctx,
BasicSignature const * sig,
FpElemStr const * f 
)
+
+ +

Verifies a signature has not been revoked in the private key based revocation list.

+

Used in constrained environments where, due to limited memory, it may not be possible to process through a large and potentially unbounded revocation list.

+
Parameters
+ + + + +
[in]ctxThe verifier context.
[in]sigThe basic signature.
[in]fThe private key based revocation list entry.
+
+
+
Note
Sig should be verified using EpidVerifyBasicSig() before invocation. Behavior is undefined if sig cannot be verified.
+
+This function should be used in conjunction with EpidNrVerify() and EpidVerifyBasicSig().
+
+If the result is not kEpidNoErr the verify should be considered to have failed.
+
Returns
EpidStatus
+
See also
EpidVerifierCreate
+
+EpidNrVerify
+
+EpidVerifyBasicSig
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidNrVerify (VerifierCtx const * ctx,
BasicSignature const * sig,
void const * msg,
size_t msg_len,
SigRlEntry const * sigrl_entry,
NrProof const * proof 
)
+
+ +

Verifies the non-revoked proof for a single signature based revocation list entry.

+

Used in constrained environments where, due to limited memory, it may not be possible to process through a large and potentially unbounded revocation list.

+
Parameters
+ + + + + + + +
[in]ctxThe verifier context.
[in]sigThe basic signature.
[in]msgThe message that was signed.
[in]msg_lenThe size of msg in bytes.
[in]sigrl_entryThe signature based revocation list entry.
[in]proofThe non-revoked proof.
+
+
+
Returns
EpidStatus
+
Note
Sig should be verified using EpidVerifyBasicSig() before invocation. Behavior is undefined if sig cannot be verified.
+
+This function should be used in conjunction with EpidVerifyBasicSig() and EpidCheckPrivRlEntry().
+
+If the result is not kEpidNoErr, the verification should be considered to have failed.
+
See also
EpidVerifierCreate
+
+EpidVerifyBasicSig
+
+EpidCheckPrivRlEntry
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidVerifierCreate (GroupPubKey const * pub_key,
VerifierPrecomp const * precomp,
VerifierCtx ** ctx 
)
+
+ +

Creates a new verifier context.

+

Must be called to create the verifier context that is used by other "Verifier" APIs.

+

Allocates memory for the context, then initializes it.

+

EpidVerifierDelete() must be called to safely release the member context.

+
Parameters
+ + + + +
[in]pub_keyThe group certificate.
[in]precompOptional pre-computed data. If NULL the value is computed internally and is readable using EpidVerifierWritePrecomp().
[out]ctxNewly constructed verifier context.
+
+
+
Returns
EpidStatus
+
Note
If the result is not kEpidNoErr the content of ctx is undefined.
+
See also
EpidVerifierDelete
+
+EpidVerifierWritePrecomp
+
Examples:
verifysig.c.
+
+
+
+ +
+
+ + + + + + + + +
void EpidVerifierDelete (VerifierCtx ** ctx)
+
+ +

Deletes an existing verifier context.

+

Must be called to safely release a verifier context created using EpidVerifierCreate().

+

De-initializes the context, frees memory used by the context, and sets the context pointer to NULL.

+
Parameters
+ + +
[in,out]ctxThe verifier context. Can be NULL.
+
+
+
See also
EpidVerifierCreate
+
Examples:
verifysig.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidVerifierSetGroupRl (VerifierCtxctx,
GroupRl const * grp_rl,
size_t grp_rl_size 
)
+
+ +

Sets the group based revocation list.

+

The caller is responsible for insuring the revocation list is authorized, e.g signed by the issuer. The caller is also responsible checking the version of the revocation list. The call fails if trying to set an older version of the revocation list than was last set.

+
Attention
The memory pointed to by grp_rl is accessed directly by the verifier until a new list is set or the verifier is destroyed. Do not modify the contents of this memory. The behavior of subsequent operations that rely on the revocation list is undefined if the memory is modified.
+
+It is the responsibility of the caller to free the memory pointed to by grp_rl after the verifier is no longer using it.
+
Parameters
+ + + + +
[in,out]ctxThe verifier context.
[in]grp_rlThe group based revocation list.
[in]grp_rl_sizeThe size of the group based revocation list in bytes.
+
+
+
Returns
EpidStatus
+
Note
If the result is not kEpidNoErr the group based revocation list pointed to by the verifier is undefined.
+
See also
EpidVerifierCreate
+
Examples:
verifysig.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
EpidStatus EpidVerifierSetHashAlg (VerifierCtxctx,
HashAlg hash_alg 
)
+
+ +

Sets the hash algorithm to be used by a verifier.

+
Parameters
+ + + +
[in]ctxThe verifier context.
[in]hash_algThe hash algorithm to use.
+
+
+
Returns
EpidStatus
+
Note
If the result is not kEpidNoErr, the hash algorithm used by the verifier is undefined.
+
See also
EpidVerifierCreate
+
+HashAlg
+
Examples:
verifysig.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidVerifierSetPrivRl (VerifierCtxctx,
PrivRl const * priv_rl,
size_t priv_rl_size 
)
+
+ +

Sets the private key based revocation list.

+

The caller is responsible for insuring the revocation list is authorized, e.g signed by the issuer. The caller is also responsible checking the version of the revocation list. The call fails if trying to set an older version of the revocation list than was last set.

+
Attention
The memory pointed to by priv_rl is accessed directly by the verifier until a new list is set or the verifier is destroyed. Do not modify the contents of this memory. The behavior of subsequent operations that rely on the revocation list is undefined if the memory is modified.
+
+It is the responsibility of the caller to free the memory pointed to by priv_rl after the verifier is no longer using it.
+
Parameters
+ + + + +
[in,out]ctxThe verifier context.
[in]priv_rlThe private key based revocation list.
[in]priv_rl_sizeThe size of the private key based revocation list in bytes.
+
+
+
Returns
EpidStatus
+
Note
If the result is not kEpidNoErr the private key based revocation list pointed to by the verifier is undefined.
+
See also
EpidVerifierCreate
+
Examples:
verifysig.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidVerifierSetSigRl (VerifierCtxctx,
SigRl const * sig_rl,
size_t sig_rl_size 
)
+
+ +

Sets the signature based revocation list.

+

The caller is responsible for insuring the revocation list is authorized, e.g signed by the issuer. The caller is also responsible checking the version of the revocation list. The call fails if trying to set an older version of the revocation list than was last set.

+
Attention
The memory pointed to by sig_rl is accessed directly by the verifier until a new list is set or the verifier is destroyed. Do not modify the contents of this memory. The behavior of subsequent operations that rely on the revocation list is undefined if the memory is modified.
+
+It is the responsibility of the caller to free the memory pointed to by sig_rl after the verifier is no longer using it.
+
Parameters
+ + + + +
[in,out]ctxThe verifier context.
[in]sig_rlThe signature based revocation list.
[in]sig_rl_sizeThe size of the signature based revocation list in bytes.
+
+
+
Returns
EpidStatus
+
Note
If the result is not kEpidNoErr the signature based revocation list pointed to by the verifier is undefined.
+
See also
EpidVerifierCreate
+
Examples:
verifysig.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidVerifierSetVerifierRl (VerifierCtxctx,
VerifierRl const * ver_rl,
size_t ver_rl_size 
)
+
+ +

Sets the verifier revocation list.

+

The caller is responsible for insuring the revocation list is authorized, e.g signed by the issuer. The caller is also responsible checking the version of the revocation list. The call fails if trying to set an older version of the revocation list than was last set.

+
Attention
The memory pointed to by ver_rl is accessed directly by the verifier until a new list is set or the verifier is destroyed. Do not modify the contents of this memory. The behavior of subsequent operations that rely on the revocation list is undefined if the memory is modified.
+
+It is the responsibility of the caller to free the memory pointed to by ver_rl after the verifier is no longer using it.
+
Parameters
+ + + + +
[in,out]ctxThe verifier context.
[in]ver_rlThe verifier revocation list.
[in]ver_rl_sizeThe size of the verifier revocation list in bytes.
+
+
+
Returns
EpidStatus
+
Note
If the result is not kEpidNoErr the verifier revocation list pointed to by the verifier is undefined.
+
See also
EpidVerifierCreate
+
Examples:
verifysig.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
EpidStatus EpidVerifierWritePrecomp (VerifierCtx const * ctx,
VerifierPrecompprecomp 
)
+
+ +

Serializes the pre-computed verifier settings.

+
Parameters
+ + + +
[in]ctxThe verifier context.
[out]precompThe Serialized pre-computed verifier settings.
+
+
+
Returns
EpidStatus
+
Note
If the result is not kEpidNoErr the content of precomp is undefined.
+
Examples:
verifysig.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidVerify (VerifierCtx const * ctx,
EpidSignature const * sig,
size_t sig_len,
void const * msg,
size_t msg_len,
void const * basename,
size_t basename_len 
)
+
+ +

Verifies a signature and checks revocation status.

+
Parameters
+ + + + + + + + +
[in]ctxThe verifier context.
[in]sigThe signature.
[in]sig_lenThe size of sig in bytes.
[in]msgThe message that was signed.
[in]msg_lenThe size of msg in bytes.
[in]basenameThe basename. Pass NULL if not specified
[in]basename_lenNumber of bytes in basename buffer. Must be 0 if basename is NULL.
+
+
+
Returns
EpidStatus
+
Return values
+ + + + + + + +
kEpidSigValidSignature validated successfully
kEpidSigInvalidSignature is invalid
kEpidSigRevokedinGroupRlSignature revoked in GroupRl
kEpidSigRevokedinPrivRlSignature revoked in PrivRl
kEpidSigRevokedinSigRlSignature revoked in SigRl
kEpidSigRevokedinVerifierRlSignature revoked in VerifierRl
+
+
+
Note
If the result is not kEpidNoErr or one of the values listed above the verify should be considered to have failed.
+
See also
EpidVerifierCreate
+
+EpidSignBasic
+
+EpidSign
+
Examples:
verifysig.c.
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidVerifyBasicSig (VerifierCtx const * ctx,
BasicSignature const * sig,
void const * msg,
size_t msg_len,
void const * basename,
size_t basename_len 
)
+
+ +

Verifies a member signature without revocation checks.

+

Used in constrained environments where, due to limited memory, it may not be possible to process through a large and potentially unbounded revocation list.

+
Parameters
+ + + + + + + +
[in]ctxThe verifier context.
[in]sigThe basic signature.
[in]msgThe message that was signed.
[in]msg_lenThe size of msg in bytes.
[in]basenameThe basename. Pass NULL if not specified
[in]basename_lenNumber of bytes in basename buffer. Must be 0 if basename is NULL.
+
+
+
Returns
EpidStatus
+
Note
This function should be used in conjunction with EpidNrVerify() and EpidCheckPrivRlEntry().
+
+If the result is not kEpidNoErr the verify should be considered to have failed.
+
See also
EpidVerifierCreate
+
+EpidSignBasic
+
+EpidSign
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_verifier_module.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_verifier_module.js new file mode 100644 index 0000000000..cabf2b5c64 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___epid_verifier_module.js @@ -0,0 +1,22 @@ +var group___epid_verifier_module = +[ + [ "VerifierPrecomp", "struct_verifier_precomp.html", [ + [ "e12", "struct_verifier_precomp.html#ad1106376f12772942af0331eb74de6e5", null ], + [ "e22", "struct_verifier_precomp.html#af8fd90f3a5a2be932a97dcd86099d5b2", null ], + [ "e2w", "struct_verifier_precomp.html#a8caf79578e3c0baf91921460391103ca", null ], + [ "eg12", "struct_verifier_precomp.html#ab061d6cc07d1467eeb5bf25f3ea7e306", null ] + ] ], + [ "EpidAreSigsLinked", "group___epid_verifier_module.html#gae44bd8acbc1e7205aeedff0c7e2632a8", null ], + [ "EpidCheckPrivRlEntry", "group___epid_verifier_module.html#gaeb05e6faea6f09c0665b13adc6e7ddea", null ], + [ "EpidNrVerify", "group___epid_verifier_module.html#gac6e2fab59e3af8a33a74a5b201642700", null ], + [ "EpidVerifierCreate", "group___epid_verifier_module.html#ga1d116daaee5466a1485d26ebc4e3ab70", null ], + [ "EpidVerifierDelete", "group___epid_verifier_module.html#ga6707e691f4b3916f9c684d5bbd463d12", null ], + [ "EpidVerifierSetGroupRl", "group___epid_verifier_module.html#ga1d41d6ef4dabbc30ec28452edd6baffb", null ], + [ "EpidVerifierSetHashAlg", "group___epid_verifier_module.html#ga97b58b2382f24756b66a357f1e825c92", null ], + [ "EpidVerifierSetPrivRl", "group___epid_verifier_module.html#gafab08180a43b58ce2e1d56c4b070bb0e", null ], + [ "EpidVerifierSetSigRl", "group___epid_verifier_module.html#ga4c7c9820409ee06f30bb8dc75fdd5dcf", null ], + [ "EpidVerifierSetVerifierRl", "group___epid_verifier_module.html#ga0909703a0a4dfe080374d0d99077465a", null ], + [ "EpidVerifierWritePrecomp", "group___epid_verifier_module.html#ga92df4d00ea4ee59d7bfd35b23da03392", null ], + [ "EpidVerify", "group___epid_verifier_module.html#ga39b240a17f310894e9f5946c9a731798", null ], + [ "EpidVerifyBasicSig", "group___epid_verifier_module.html#ga974b92a62e8b65ea75cf802e8cc6bb6a", null ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___error_codes.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___error_codes.html new file mode 100644 index 0000000000..557e3e73fc --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___error_codes.html @@ -0,0 +1,225 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: errors + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
errors
+
+
+ +

Error reporting interface. +More...

+ + + + + +

+Enumerations

enum  EpidStatus {
+  kEpidNoErr = 0, +kEpidSigValid = 0, +kEpidSigInvalid = 1, +kEpidSigRevokedinGroupRl = 2, +
+  kEpidSigRevokedinPrivRl = 3, +kEpidSigRevokedinSigRl = 4, +kEpidSigRevokedinVerifierRl = 5, +kEpidErr = -999, +
+  kEpidNotImpl, +kEpidBadArgErr, +kEpidNoMemErr, +kEpidMemAllocErr, +
+  kEpidMathErr, +kEpidDivByZeroErr, +kEpidUnderflowErr, +kEpidHashAlgorithmNotSupported, +
+  kEpidRandMaxIterErr, +kEpidDuplicateErr +
+ }
 Return status for SDK functions. More...
 
+ + + + +

+Functions

char const * EpidStatusToString (EpidStatus e)
 Returns string representation of error code. More...
 
+

Detailed Description

+

Error reporting interface.

+

This module defines the return status type. It also provides tools for interactions with status values, such as converting them to a string.

+

Enumeration Type Documentation

+ +
+
+ + + + +
enum EpidStatus
+
+ +

Return status for SDK functions.

+

Convention for status values is as follows:

    +
  • Zero indicates "success"
  • +
  • Any positive number indicates "success with status"
  • +
  • Any negative number indicates "failure"
  • +
+ + + + + + + + + + + + + + + + + + + +
Enumerator
kEpidNoErr  +

no error

+
kEpidSigValid  +

Signature is valid.

+
kEpidSigInvalid  +

Signature is invalid.

+
kEpidSigRevokedinGroupRl  +

Signature revoked in GroupRl.

+
kEpidSigRevokedinPrivRl  +

Signature revoked in PrivRl.

+
kEpidSigRevokedinSigRl  +

Signature revoked in SigRl.

+
kEpidSigRevokedinVerifierRl  +

Signature revoked in VerifierRl.

+
kEpidErr  +

unspecified error

+
kEpidNotImpl  +

not implemented error

+
kEpidBadArgErr  +

incorrect arg to function

+
kEpidNoMemErr  +

not enough memory for the operation

+
kEpidMemAllocErr  +

insufficient memory allocated for operation

+
kEpidMathErr  +

internal math error

+
kEpidDivByZeroErr  +

an attempt to divide by zero

+
kEpidUnderflowErr  +

a value became less than minimum supported level

+
kEpidHashAlgorithmNotSupported  +

unsupported hash algorithm type

+
kEpidRandMaxIterErr  +

reached max iteration for random number generation

+
kEpidDuplicateErr  +

argument would add duplicate entry

+
+
Examples:
verifysig.c.
+
+
+
+

Function Documentation

+ +
+
+ + + + + + + + +
char const* EpidStatusToString (EpidStatus e)
+
+ +

Returns string representation of error code.

+
Parameters
+ + +
eThe status value.
+
+
+
Returns
The string describing the status.
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___error_codes.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___error_codes.js new file mode 100644 index 0000000000..6121a1ddb8 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___error_codes.js @@ -0,0 +1,24 @@ +var group___error_codes = +[ + [ "EpidStatus", "group___error_codes.html#gafdb27c77c2c4b32c807e326a8a0da360", [ + [ "kEpidNoErr", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a8a6861e14322ca9193498ffc955537f9", null ], + [ "kEpidSigValid", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360ab45ad60085d03c03ea30b40a0519897e", null ], + [ "kEpidSigInvalid", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360aeedd19b8a1cbdecf963f90b4860e02b8", null ], + [ "kEpidSigRevokedinGroupRl", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a2b38f44424cecd7b432194a2012dc9c7", null ], + [ "kEpidSigRevokedinPrivRl", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a780a20821863553b88ca617a6fc0f718", null ], + [ "kEpidSigRevokedinSigRl", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360aff83186b61d48f9fee5f691c5b219bc1", null ], + [ "kEpidSigRevokedinVerifierRl", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360addbba767bb884b4459a567056b4d3f86", null ], + [ "kEpidErr", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360aa08f0d2e394b37694117a6a32bc71e6e", null ], + [ "kEpidNotImpl", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a5252da1ff519a098446723e9edd30cc7", null ], + [ "kEpidBadArgErr", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360ad134d6cc95a9dcb1b1a9f9c358047cbf", null ], + [ "kEpidNoMemErr", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360ab7dfec784192a827a91a4b8a6054d01c", null ], + [ "kEpidMemAllocErr", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a11a4d2f1c37064eb663de08dc57bcda8", null ], + [ "kEpidMathErr", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a1739ecb620f4bede2e1b84e52a96cee6", null ], + [ "kEpidDivByZeroErr", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a893cd0d417b139bb376d09c93695c3f3", null ], + [ "kEpidUnderflowErr", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a83a867b4f71ee13edbfca2f1b72abbec", null ], + [ "kEpidHashAlgorithmNotSupported", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360ad4d4ff24a7ef2cd7a50b8082265e9ff4", null ], + [ "kEpidRandMaxIterErr", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a61234ad9610406da6bf7977afd72a357", null ], + [ "kEpidDuplicateErr", "group___error_codes.html#ggafdb27c77c2c4b32c807e326a8a0da360a3706f895a660260033b5b91890516c0f", null ] + ] ], + [ "EpidStatusToString", "group___error_codes.html#ga59e8680ce52509302fd58a987e45004d", null ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___file_parser.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___file_parser.html new file mode 100644 index 0000000000..70cd3af34e --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___file_parser.html @@ -0,0 +1,439 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: fileparser + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+ +
+ +

Parser for issuer material. +More...

+ + + + + + + + +

+Data Structures

struct  EpidFileHeader
 Intel(R) EPID binary file header. More...
 
struct  EpidCaCertificate
 IoT CA Certificate binary format. More...
 
+ + + + +

+Enumerations

enum  EpidFileType {
+  kIssuingCaPubKeyFile, +kGroupPubKeyFile, +kPrivRlFile, +kSigRlFile, +
+  kGroupRlFile, +kPrivRlRequestFile, +kSigRlRequestFile, +kGroupRlRequestFile, +
+  kNumFileTypes +
+ }
 Recognized Intel(R) EPID file types. More...
 
+ + + + + + + + + + + + + +

+Functions

EpidStatus EpidParseGroupPubKeyFile (void const *buf, size_t len, EpidCaCertificate const *cert, GroupPubKey *pubkey)
 Extracts group public key from buffer in issuer binary format. More...
 
EpidStatus EpidParsePrivRlFile (void const *buf, size_t len, EpidCaCertificate const *cert, PrivRl *rl, size_t *rl_len)
 Extracts private key revocation list from buffer in issuer binary format. More...
 
EpidStatus EpidParseSigRlFile (void const *buf, size_t len, EpidCaCertificate const *cert, SigRl *rl, size_t *rl_len)
 Extracts signature revocation list from buffer in issuer binary format. More...
 
EpidStatus EpidParseGroupRlFile (void const *buf, size_t len, EpidCaCertificate const *cert, GroupRl *rl, size_t *rl_len)
 Extracts group revocation list from buffer in issuer binary format. More...
 
+ + + + +

+Variables

+const OctStr16 kEpidFileTypeCode [kNumFileTypes]
 Encoding of issuer material file types.
 
+

Detailed Description

+

Parser for issuer material.

+

Provides an API for parsing buffers formatted according to the various IoT Intel(R) EPID binary file formats.

+

Enumeration Type Documentation

+ +
+
+ + + + +
enum EpidFileType
+
+ +

Recognized Intel(R) EPID file types.

+ + + + + + + + + + +
Enumerator
kIssuingCaPubKeyFile  +

IoT Issuing CA public key file.

+
kGroupPubKeyFile  +

Group Public Key Output File Format.

+
kPrivRlFile  +

Binary Private Key Revocation List.

+
kSigRlFile  +

Binary Signature Revocation List.

+
kGroupRlFile  +

Binary Group Revocation List.

+
kPrivRlRequestFile  +

Binary Private Key Revocation Request.

+
kSigRlRequestFile  +

Binary Signature Revocation Request.

+
kGroupRlRequestFile  +

Binary Group Revocation Request.

+
kNumFileTypes  +

Maximum number of file types.

+
+ +
+
+

Function Documentation

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidParseGroupPubKeyFile (void const * buf,
size_t len,
EpidCaCertificate const * cert,
GroupPubKeypubkey 
)
+
+ +

Extracts group public key from buffer in issuer binary format.

+

Extracts the first group public key from a buffer with format of Intel(R) EPID 2.0 Group Public Key Certificate Binary File. The function validates that the first public key was signed by the private key corresponding to the provided CA certificate and the size of the input buffer is correct.

+
Warning
It is the responsibility of the caller to authenticate the EpidCaCertificate.
+
Parameters
+ + + + + +
[in]bufPointer to buffer containing public key to extract.
[in]lenThe size of buf in bytes.
[in]certThe issuing CA public key certificate.
[out]pubkeyThe extracted group public key.
+
+
+
Returns
EpidStatus
+
Return values
+ + +
kEpidSigInvalidParsing failed due to data authentication failure.
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidParseGroupRlFile (void const * buf,
size_t len,
EpidCaCertificate const * cert,
GroupRlrl,
size_t * rl_len 
)
+
+ +

Extracts group revocation list from buffer in issuer binary format.

+

Extracts the group revocation list from a buffer with format of Binary Group Certificate Revocation List File. The function validates that the revocation list was signed by the private key corresponding to the provided CA certificate and the size of the input buffer is correct.

+

To determine the required size of the revocation list output buffer, provide a null pointer for the output buffer.

+
Warning
It is the responsibility of the caller to authenticate the EpidCaCertificate.
+
Parameters
+ + + + + + +
[in]bufPointer to buffer containing the revocation list to extract.
[in]lenThe size of buf in bytes.
[in]certThe issuing CA public key certificate.
[out]rlThe extracted revocation list. If Null, rl_len is filled with the required output buffer size.
[in,out]rl_lenThe size of rl in bytes.
+
+
+
Returns
EpidStatus
+
Return values
+ + +
kEpidSigInvalidParsing failed due to data authentication failure.
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidParsePrivRlFile (void const * buf,
size_t len,
EpidCaCertificate const * cert,
PrivRlrl,
size_t * rl_len 
)
+
+ +

Extracts private key revocation list from buffer in issuer binary format.

+

Extracts the private key revocation list from a buffer with format of Binary Private Key Revocation List File. The function validates that the revocation list was signed by the private key corresponding to the provided CA certificate and the size of the input buffer is correct.

+

To determine the required size of the revocation list output buffer, provide a null pointer for the output buffer.

+
Warning
It is the responsibility of the caller to authenticate the EpidCaCertificate.
+
Parameters
+ + + + + + +
[in]bufPointer to buffer containing the revocation list to extract.
[in]lenThe size of buf in bytes.
[in]certThe issuing CA public key certificate.
[out]rlThe extracted revocation list. If Null, rl_len is filled with the required output buffer size.
[in,out]rl_lenThe size of rl in bytes.
+
+
+
Returns
EpidStatus
+
Return values
+ + +
kEpidSigInvalidParsing failed due to data authentication failure.
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus EpidParseSigRlFile (void const * buf,
size_t len,
EpidCaCertificate const * cert,
SigRlrl,
size_t * rl_len 
)
+
+ +

Extracts signature revocation list from buffer in issuer binary format.

+

Extracts the signature based revocation list from a buffer with format of Binary Signature Revocation List File. The function validates that the revocation list was signed by the private key corresponding to the provided CA certificate and the size of the input buffer is correct.

+

To determine the required size of the revocation list output buffer, provide a null pointer for the output buffer.

+
Warning
It is the responsibility of the caller to authenticate the EpidCaCertificate.
+
Parameters
+ + + + + + +
[in]bufPointer to buffer containing the revocation list to extract.
[in]lenThe size of buf in bytes.
[in]certThe issuing CA public key certificate.
[out]rlThe extracted revocation list. If Null, rl_len is filled with the required output buffer size.
[in,out]rl_lenThe size of rl in bytes.
+
+
+
Returns
EpidStatus
+
Return values
+ + +
kEpidSigInvalidParsing failed due to data authentication failure.
+
+
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___file_parser.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___file_parser.js new file mode 100644 index 0000000000..0d7346c603 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___file_parser.js @@ -0,0 +1,34 @@ +var group___file_parser = +[ + [ "EpidFileHeader", "struct_epid_file_header.html", [ + [ "epid_version", "struct_epid_file_header.html#a35d43c51c1739940381e4898ca87b824", null ], + [ "file_type", "struct_epid_file_header.html#af5d48c739cc6c00c6e1ce35abf4f1473", null ] + ] ], + [ "EpidCaCertificate", "struct_epid_ca_certificate.html", [ + [ "a", "struct_epid_ca_certificate.html#a2811c1914ffae913820f13da914c8f01", null ], + [ "b", "struct_epid_ca_certificate.html#a280e0b0238cf45834c21849ab8a7e124", null ], + [ "header", "struct_epid_ca_certificate.html#ac03cf7257c52ad14e3dd3201b930dd50", null ], + [ "prime", "struct_epid_ca_certificate.html#a3a44e8050ca2f5085652b2b4e15b779c", null ], + [ "pubkey", "struct_epid_ca_certificate.html#a9d2fc21f46cf9fc96e2ea557b70e5356", null ], + [ "r", "struct_epid_ca_certificate.html#ab9d4c318b1fc8d38d3ce53b29f2dfee2", null ], + [ "signature", "struct_epid_ca_certificate.html#a2f8f09ae02919c379c38386668b47418", null ], + [ "x", "struct_epid_ca_certificate.html#a4f77996f90ed7da1d0503c4236b2c9d1", null ], + [ "y", "struct_epid_ca_certificate.html#abd69cce8d5e3940787ee0d17f72184ab", null ] + ] ], + [ "EpidFileType", "group___file_parser.html#ga9a33be7edc6b4c7a867fb07bd2bddecb", [ + [ "kIssuingCaPubKeyFile", "group___file_parser.html#gga9a33be7edc6b4c7a867fb07bd2bddecbac24554caafe2db01e2daed413188cd92", null ], + [ "kGroupPubKeyFile", "group___file_parser.html#gga9a33be7edc6b4c7a867fb07bd2bddecba1f8d8c4b253403a35c51e05d34a7ca1e", null ], + [ "kPrivRlFile", "group___file_parser.html#gga9a33be7edc6b4c7a867fb07bd2bddecba692b4141bff8225bee6000750b0da322", null ], + [ "kSigRlFile", "group___file_parser.html#gga9a33be7edc6b4c7a867fb07bd2bddecba8aead4b6aab87a1efb2d7e8c77a9b710", null ], + [ "kGroupRlFile", "group___file_parser.html#gga9a33be7edc6b4c7a867fb07bd2bddecba8e5247daee3999540e6cb24d4c2b3770", null ], + [ "kPrivRlRequestFile", "group___file_parser.html#gga9a33be7edc6b4c7a867fb07bd2bddecbac708ba9e56eaeac0f1256457cbd45911", null ], + [ "kSigRlRequestFile", "group___file_parser.html#gga9a33be7edc6b4c7a867fb07bd2bddecbac52e5fe24a12424316f655b9b7c62600", null ], + [ "kGroupRlRequestFile", "group___file_parser.html#gga9a33be7edc6b4c7a867fb07bd2bddecbab772fa1e3f221af125ffb34b86b3f24c", null ], + [ "kNumFileTypes", "group___file_parser.html#gga9a33be7edc6b4c7a867fb07bd2bddecbac6d742ea3dd3b17f6d763970ac84b811", null ] + ] ], + [ "EpidParseGroupPubKeyFile", "group___file_parser.html#ga43fdbc1bf2edd3695d21cb457365afbb", null ], + [ "EpidParseGroupRlFile", "group___file_parser.html#gad767f72dc55307b872a8b5600da3fd6f", null ], + [ "EpidParsePrivRlFile", "group___file_parser.html#gadc033fb23e3cbda56aa7e3d412060b7e", null ], + [ "EpidParseSigRlFile", "group___file_parser.html#ga237ef5a43076aa6fc6eb18829a93da3f", null ], + [ "kEpidFileTypeCode", "group___file_parser.html#ga3770c39a0546c79447c9d4159d794c33", null ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___finite_field_primitives.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___finite_field_primitives.html new file mode 100644 index 0000000000..1c40c12d63 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___finite_field_primitives.html @@ -0,0 +1,1048 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: finitefield + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
finitefield
+
+
+ +

Finite field operations. +More...

+ + + + + + + + +

+Typedefs

+typedef struct FiniteField FiniteField
 A finite field.
 
+typedef struct FfElement FfElement
 An element in a finite field.
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

EpidStatus NewFiniteField (BigNumStr const *prime, FiniteField **ff)
 Creates new finite field. More...
 
EpidStatus NewFiniteFieldViaBinomalExtension (FiniteField const *ground_field, FfElement const *ground_element, int degree, FiniteField **ff)
 Creates a new finite field using binomial extension. More...
 
void DeleteFiniteField (FiniteField **ff)
 Frees a previously allocated FiniteField. More...
 
EpidStatus NewFfElement (FiniteField const *ff, FfElement **new_ff_elem)
 Creates a new finite field element. More...
 
void DeleteFfElement (FfElement **ff_elem)
 Frees a previously allocated FfElement. More...
 
EpidStatus ReadFfElement (FiniteField *ff, void const *ff_elem_str, size_t strlen, FfElement *ff_elem)
 Deserializes a FfElement from a string. More...
 
EpidStatus WriteFfElement (FiniteField *ff, FfElement const *ff_elem, void *ff_elem_str, size_t strlen)
 Serializes a finite field element to a string. More...
 
EpidStatus FfNeg (FiniteField *ff, FfElement const *a, FfElement *r)
 Calculates the additive inverse of a finite field element. More...
 
EpidStatus FfInv (FiniteField *ff, FfElement const *a, FfElement *r)
 Calculates the multiplicative inverse of a finite field element. More...
 
EpidStatus FfAdd (FiniteField *ff, FfElement const *a, FfElement const *b, FfElement *r)
 Adds two finite field elements. More...
 
EpidStatus FfMul (FiniteField *ff, FfElement const *a, FfElement const *b, FfElement *r)
 Multiplies two finite field elements. More...
 
EpidStatus FfIsZero (FiniteField *ff, FfElement const *a, bool *is_zero)
 Checks if given finite field element is the additive identity (zero). More...
 
EpidStatus FfExp (FiniteField *ff, FfElement const *a, BigNum const *b, FfElement *r)
 Raises an element of a finite field to a power. More...
 
EpidStatus FfMultiExp (FiniteField *ff, FfElement const **a, BigNumStr const **b, size_t m, FfElement *r)
 Multi-exponentiates finite field elements. More...
 
EpidStatus FfSscmMultiExp (FiniteField *ff, FfElement const **a, BigNumStr const **b, size_t m, FfElement *r)
 Software side-channel mitigated implementation of FfMultiExp. More...
 
EpidStatus FfIsEqual (FiniteField *ff, FfElement const *a, FfElement const *b, bool *is_equal)
 Checks if two finite field elements are equal. More...
 
EpidStatus FfHash (FiniteField *ff, void const *msg, size_t msg_len, HashAlg hash_alg, FfElement *r)
 Hashes an arbitrary message to an element in a finite field. More...
 
EpidStatus FfGetRandom (FiniteField *ff, BigNumStr const *low_bound, BitSupplier rnd_func, void *rnd_param, FfElement *r)
 Generate random finite field element. More...
 
+

Detailed Description

+

Finite field operations.

+

provides APIs for working with finite fields. Finite fields allow simple mathematical operations based on a finite set of discrete values. the results of these operations are also contained in the same set.

+

A simple example of a finite field is all integers from zero that are less than a given value.

+

The elements (FfElement) of a finite field can be used in a variety of simple mathematical operations that result in elements of the same field.

+

Function Documentation

+ +
+
+ + + + + + + + +
void DeleteFfElement (FfElement ** ff_elem)
+
+ +

Frees a previously allocated FfElement.

+

Frees memory pointed to by ff_elem. Nulls the pointer.

+
Parameters
+ + +
[in]ff_elemThe finite field element. Can be NULL.
+
+
+
See also
NewFfElement
+ +
+
+ +
+
+ + + + + + + + +
void DeleteFiniteField (FiniteField ** ff)
+
+ +

Frees a previously allocated FiniteField.

+

Frees memory pointed to by finite field. Nulls the pointer.

+
Parameters
+ + +
[in]ffThe Finite field. Can be NULL.
+
+
+
See also
NewFiniteField
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus FfAdd (FiniteFieldff,
FfElement const * a,
FfElement const * b,
FfElementr 
)
+
+ +

Adds two finite field elements.

+
Parameters
+ + + + + +
[in]ffThe finite field.
[out]aThe left hand parameter.
[out]bThe right hand parameter.
[out]rThe result of adding a and b.
+
+
+
Returns
EpidStatus
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus FfExp (FiniteFieldff,
FfElement const * a,
BigNum const * b,
FfElementr 
)
+
+ +

Raises an element of a finite field to a power.

+
Parameters
+ + + + + +
[in]ffThe finite field in which to perform the operation
[in]aThe base.
[in]bThe power.
[out]rThe result of raising a to the power b.
+
+
+
Returns
EpidStatus
+
See also
NewFiniteField
+
+NewFfElement
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus FfGetRandom (FiniteFieldff,
BigNumStr const * low_bound,
BitSupplier rnd_func,
void * rnd_param,
FfElementr 
)
+
+ +

Generate random finite field element.

+
Parameters
+ + + + + + +
[in]ffThe finite field associated with the random finite field element.
[in]low_boundLower bound of the random finite field to be generated.
[in]rnd_funcRandom number generator.
[in]rnd_paramPass through context data for rnd_func.
[in,out]rThe random finite field element.
+
+
+
Returns
EpidStatus
+
Return values
+ + +
kEpidRandMaxIterErrthe function should be called again with different random data.
+
+
+
See also
NewFfElement
+
+BitSupplier
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus FfHash (FiniteFieldff,
void const * msg,
size_t msg_len,
HashAlg hash_alg,
FfElementr 
)
+
+ +

Hashes an arbitrary message to an element in a finite field.

+
Parameters
+ + + + + + +
[in]ffThe finite field.
[in]msgThe message.
[in]msg_lenThe size of msg in bytes.
[in]hash_algThe hash algorithm.
[out]rThe hashed value.
+
+
+
Returns
EpidStatus
+
See also
NewFiniteField
+
+NewFfElement
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus FfInv (FiniteFieldff,
FfElement const * a,
FfElementr 
)
+
+ +

Calculates the multiplicative inverse of a finite field element.

+
Parameters
+ + + + +
[in]ffThe finite field.
[in]aThe element.
[out]rThe inverted element.
+
+
+
Returns
EpidStatus
+
See also
NewFiniteField
+
+NewFfElement
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus FfIsEqual (FiniteFieldff,
FfElement const * a,
FfElement const * b,
boolis_equal 
)
+
+ +

Checks if two finite field elements are equal.

+
Parameters
+ + + + + +
[in]ffThe finite field.
[in]aAn element to check.
[in]bAnother element to check.
[out]is_equalThe result of the check.
+
+
+
Returns
EpidStatus
+
See also
NewEcGroup
+
+NewEcPoint
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus FfIsZero (FiniteFieldff,
FfElement const * a,
boolis_zero 
)
+
+ +

Checks if given finite field element is the additive identity (zero).

+
Parameters
+ + + + +
[in]ffThe finite field.
[out]aThe element.
[out]is_zeroThe result of the check.
+
+
+
Returns
EpidStatus
+
See also
NewFiniteField
+
+NewFfElement
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus FfMul (FiniteFieldff,
FfElement const * a,
FfElement const * b,
FfElementr 
)
+
+ +

Multiplies two finite field elements.

+
Parameters
+ + + + + +
[in]ffThe finite field.
[out]aThe left hand parameter.
[out]bThe right hand parameter. If ff is an extension field of a field F then this parameter may be an element of either ff or F.
[out]rThe result of multiplying a and b.
+
+
+
Returns
EpidStatus
+
See also
NewFiniteField
+
+NewFfElement
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus FfMultiExp (FiniteFieldff,
FfElement const ** a,
BigNumStr const ** b,
size_t m,
FfElementr 
)
+
+ +

Multi-exponentiates finite field elements.

+

Calculates FfExp(p[0],b[0]) * ... * FfExp(p[m-1],b[m-1]) for m > 1

+
Parameters
+ + + + + + +
[in]ffThe finite field in which to perform the operation
[in]aThe bases.
[in]bThe powers.
[in]mNumber of entries in a and b.
[out]rThe result of raising each a to the corresponding power b and multiplying the results.
+
+
+
Returns
EpidStatus
+
See also
NewFiniteField
+
+NewFfElement
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus FfNeg (FiniteFieldff,
FfElement const * a,
FfElementr 
)
+
+ +

Calculates the additive inverse of a finite field element.

+
Parameters
+ + + + +
[in]ffThe finite field.
[in]aThe element.
[out]rThe inverted element.
+
+
+
Returns
EpidStatus
+
See also
NewFiniteField
+
+NewFfElement
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus FfSscmMultiExp (FiniteFieldff,
FfElement const ** a,
BigNumStr const ** b,
size_t m,
FfElementr 
)
+
+ +

Software side-channel mitigated implementation of FfMultiExp.

+

Calculates FfExp(p[0],b[0]) * ... * FfExp(p[m-1],b[m-1]) for m > 1

+
Attention
The reference implementation of FfSscmMultiExp calls FfMultiExp directly because the implementation of FfMultiExp is already side channel mitigated. Implementers providing their own versions of this function are responsible for ensuring that FfSscmMultiExp is side channel mitigated per section 8 of the Intel(R) EPID 2.0 spec.
+
Parameters
+ + + + + + +
[in]ffThe finite field in which to perform the operation.
[in]aThe bases.
[in]bThe powers.
[in]mNumber of entries in a and b.
[out]rThe result of raising each a to the corresponding power b and multiplying the results.
+
+
+
Returns
EpidStatus
+
See also
NewFiniteField
+
+NewFfElement
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
EpidStatus NewFfElement (FiniteField const * ff,
FfElement ** new_ff_elem 
)
+
+ +

Creates a new finite field element.

+

Allocates memory and creates a new finite field element.

+

Use DeleteFfElement() to free memory.

+
Parameters
+ + + +
[in]ffThe finite field.
[out]new_ff_elemThe Newly constructed finite field element.
+
+
+
Returns
EpidStatus
+
See also
NewFiniteField
+
+DeleteFfElement
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
EpidStatus NewFiniteField (BigNumStr const * prime,
FiniteField ** ff 
)
+
+ +

Creates new finite field.

+

Allocates memory and creates a new finite field GF(prime).

+

Use DeleteFiniteField() to free memory.

+
Parameters
+ + + +
[in]primeThe order of finite field.
[out]ffThe Newly constructed finite field.
+
+
+
Returns
EpidStatus
+
See also
DeleteFiniteField
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus NewFiniteFieldViaBinomalExtension (FiniteField const * ground_field,
FfElement const * ground_element,
int degree,
FiniteField ** ff 
)
+
+ +

Creates a new finite field using binomial extension.

+

Allocates memory and creates a finite field using binomial extension.

+

Use DeleteFiniteField() to free memory.

+
Parameters
+ + + + + +
[in]ground_fieldThe ground field.
[in]ground_elementThe low-order term of the extension.
[in]degreeThe degree of the extension.
[out]ffThe Newly constructed finite field.
+
+
+
Returns
EpidStatus
+
See also
DeleteFiniteField
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus ReadFfElement (FiniteFieldff,
void const * ff_elem_str,
size_t strlen,
FfElementff_elem 
)
+
+ +

Deserializes a FfElement from a string.

+
Parameters
+ + + + + +
[in]ffThe the finite field.
[in]ff_elem_strThe serialized value.
[in]strlenThe size of ff_elem_str in bytes.
[out]ff_elemthe target FfElement.
+
+
+
Returns
EpidStatus
+
See also
NewFfElement
+
+WriteFfElement
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus WriteFfElement (FiniteFieldff,
FfElement const * ff_elem,
void * ff_elem_str,
size_t strlen 
)
+
+ +

Serializes a finite field element to a string.

+
Parameters
+ + + + + +
[in]ffThe finite field.
[in]ff_elemThe FfElement to be serialized.
[out]ff_elem_strThe target string.
[in]strlenThe size of ff_elem_str in bytes.
+
+
+
Returns
EpidStatus
+
See also
NewFfElement
+
+FpElemStr
+
+FqElemStr
+
+GtElemStr
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___finite_field_primitives.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___finite_field_primitives.js new file mode 100644 index 0000000000..462a90c1c5 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___finite_field_primitives.js @@ -0,0 +1,23 @@ +var group___finite_field_primitives = +[ + [ "FfElement", "group___finite_field_primitives.html#ga6cff5c7c06b07a87442b810ccc0a86fa", null ], + [ "FiniteField", "group___finite_field_primitives.html#gab281b24e336a8b3d7d90079d862d969e", null ], + [ "DeleteFfElement", "group___finite_field_primitives.html#ga1bad3c6945d1d709fceb07a1dd03000e", null ], + [ "DeleteFiniteField", "group___finite_field_primitives.html#gacbdd2871ecf93dadaac9d2c5b16e1e5f", null ], + [ "FfAdd", "group___finite_field_primitives.html#ga1a6e6d3c2319bb24eae8670b021e223b", null ], + [ "FfExp", "group___finite_field_primitives.html#gaf0ddbc1bad048d67771cba119eb44a6c", null ], + [ "FfGetRandom", "group___finite_field_primitives.html#ga6622db072782fd9e53b4d59dd3dbd8e8", null ], + [ "FfHash", "group___finite_field_primitives.html#ga18a952cebb4a1274c73e6cb0c19e8aea", null ], + [ "FfInv", "group___finite_field_primitives.html#ga26069d035d0f6ade33af2b5d5c14949a", null ], + [ "FfIsEqual", "group___finite_field_primitives.html#gaed2acb8583e9c9f6b49fdb660c672625", null ], + [ "FfIsZero", "group___finite_field_primitives.html#ga20d9140e5670d679ef8183d9b5115f53", null ], + [ "FfMul", "group___finite_field_primitives.html#ga4613a75bd001a974b3e3e494c3a112a5", null ], + [ "FfMultiExp", "group___finite_field_primitives.html#ga84d21decc1c957bcf6e98e1492eb2ac3", null ], + [ "FfNeg", "group___finite_field_primitives.html#gae7a8c7503b6fc7a41bcaab4d45ca37b2", null ], + [ "FfSscmMultiExp", "group___finite_field_primitives.html#ga0d0c31a22bbfb665a16b2d25b0cd2634", null ], + [ "NewFfElement", "group___finite_field_primitives.html#gacc54f315ede2dbeb8c5990c024a0de6c", null ], + [ "NewFiniteField", "group___finite_field_primitives.html#ga7d99fdc5e4573668a5744e49df7ab67c", null ], + [ "NewFiniteFieldViaBinomalExtension", "group___finite_field_primitives.html#ga83041e3be9984a4bd8f1021934bfa3a2", null ], + [ "ReadFfElement", "group___finite_field_primitives.html#ga884d9e1baadf29a410244a735853e3c7", null ], + [ "WriteFfElement", "group___finite_field_primitives.html#ga678694636708463b078d842d5c58a900", null ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___hash_primitives.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___hash_primitives.html new file mode 100644 index 0000000000..3125c01dc9 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___hash_primitives.html @@ -0,0 +1,142 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: hash + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
hash
+
+
+ +

Hash primitives. +More...

+ + + + + +

+Data Structures

struct  Sha256Digest
 SHA256 digest. More...
 
+ + + + +

+Functions

EpidStatus Sha256MessageDigest (void const *msg, size_t len, Sha256Digest *digest)
 Computes SHA256 digest of a message. More...
 
+

Detailed Description

+

Hash primitives.

+

Provides APIs for computing digests of messages.

+

Function Documentation

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus Sha256MessageDigest (void const * msg,
size_t len,
Sha256Digestdigest 
)
+
+ +

Computes SHA256 digest of a message.

+
Parameters
+ + + + +
[in]msgMessage to compute digest for.
[in]lenThe size of msg in bytes.
[out]digestThe resulting message digest.
+
+
+
Returns
EpidStatus
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___hash_primitives.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___hash_primitives.js new file mode 100644 index 0000000000..14b92829cf --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___hash_primitives.js @@ -0,0 +1,7 @@ +var group___hash_primitives = +[ + [ "Sha256Digest", "struct_sha256_digest.html", [ + [ "data", "struct_sha256_digest.html#a4b6462ddd3f89e4c40220ceb6b1c7f28", null ] + ] ], + [ "Sha256MessageDigest", "group___hash_primitives.html#ga86d62aac9efd7445acee311b41846c6c", null ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___pairing_primitives.html b/sgx-jvm/linux-sgx/external/epid/doc/html/group___pairing_primitives.html new file mode 100644 index 0000000000..6b31f6182c --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___pairing_primitives.html @@ -0,0 +1,249 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: pairing + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
pairing
+
+
+ +

Pairing operations. +More...

+ + + + + +

+Typedefs

+typedef struct PairingState PairingState
 A pairing.
 
+ + + + + + + + + + +

+Functions

EpidStatus NewPairingState (EcGroup const *ga, EcGroup const *gb, FiniteField *ff, BigNumStr const *t, bool neg, PairingState **ps)
 Constructs a new Pairing State. More...
 
void DeletePairingState (PairingState **ps)
 Frees a previously allocated by PairingState. More...
 
EpidStatus Pairing (PairingState *ps, FfElement *d, EcPoint const *a, EcPoint const *b)
 Computes an Optimal Ate Pairing for two parameters. More...
 
+

Detailed Description

+

Pairing operations.

+

Provides APIs for defining and using a pairing relationship between two Elliptic Curve Groups.

+

Function Documentation

+ +
+
+ + + + + + + + +
void DeletePairingState (PairingState ** ps)
+
+ +

Frees a previously allocated by PairingState.

+

Frees memory pointed to by pairing state. Nulls the pointer.

+
Parameters
+ + +
[in]psThe Pairing state. Can be NULL.
+
+
+
See also
NewPairingState
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus NewPairingState (EcGroup const * ga,
EcGroup const * gb,
FiniteFieldff,
BigNumStr const * t,
bool neg,
PairingState ** ps 
)
+
+ +

Constructs a new Pairing State.

+

Allocates memory and creates a new Pairing State for Optimal Ate Pairing.

+

Use DeletePairingState() to free memory.

+
Parameters
+ + + + + + + +
[in]gaThe EcGroup from which the first parameter of the pairing is taken.
[in]gbThe EcGroup from which the second parameter of the pairing is taken.
[in]ffThe result finite field. Must be a Fq12 field.
[in]tA positive integer such that 6(t^2) == q - p, where p and q are parameters of G1.
[in]negSelect the alternate "negate" processing path for Optimal Ate Pairing.
[out]psNewly constructed Pairing State.
+
+
+
Returns
EpidStatus
+
See also
DeletePairingState
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EpidStatus Pairing (PairingStateps,
FfElementd,
EcPoint const * a,
EcPoint const * b 
)
+
+ +

Computes an Optimal Ate Pairing for two parameters.

+
Parameters
+ + + + + +
[in]psThe pairing state.
[out]dThe result of the pairing. Will be in ff used to create the pairing state.
[in]aThe first value to pair. Must be in ga used to create ps.
[in]bThe second value to pair. Must be in gb used to create ps
+
+
+
Returns
EpidStatus
+ +
+
+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/group___pairing_primitives.js b/sgx-jvm/linux-sgx/external/epid/doc/html/group___pairing_primitives.js new file mode 100644 index 0000000000..4f7612011c --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/group___pairing_primitives.js @@ -0,0 +1,7 @@ +var group___pairing_primitives = +[ + [ "PairingState", "group___pairing_primitives.html#ga3f1fa61d25487f96dfb0ffef4ad35607", null ], + [ "DeletePairingState", "group___pairing_primitives.html#gad54aebdc331d39b73000fdca9e04f94d", null ], + [ "NewPairingState", "group___pairing_primitives.html#ga29f79a645871830754d396b9b4a2a0cc", null ], + [ "Pairing", "group___pairing_primitives.html#ga5dd07d13536e27c37eaeee285297066c", null ] +]; \ No newline at end of file diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/grouppubkey_8c.html b/sgx-jvm/linux-sgx/external/epid/doc/html/grouppubkey_8c.html new file mode 100644 index 0000000000..009cf4253e --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/grouppubkey_8c.html @@ -0,0 +1,96 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/grouppubkey.c File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
grouppubkey.c File Reference
+
+
+ +

Group public key implementation. +More...

+ + + + + + + + +

+Functions

EpidStatus CreateGroupPubKey (GroupPubKey const *pub_key_str, EcGroup *G1, EcGroup *G2, GroupPubKey_ **pub_key)
 Constructs internal representation of GroupPubKey. More...
 
void DeleteGroupPubKey (GroupPubKey_ **pub_key)
 Deallocates storage for internal representation of GroupPubKey. More...
 
+

Detailed Description

+

Group public key implementation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/grouppubkey_8h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/grouppubkey_8h.html new file mode 100644 index 0000000000..a179e826a0 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/grouppubkey_8h.html @@ -0,0 +1,104 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/grouppubkey.h File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
grouppubkey.h File Reference
+
+
+ +

Group public key interface. +More...

+ + + + + +

+Data Structures

struct  GroupPubKey_
 Internal representation of GroupPubKey. More...
 
+ + + + + + + +

+Functions

EpidStatus CreateGroupPubKey (GroupPubKey const *pub_key_str, EcGroup *G1, EcGroup *G2, GroupPubKey_ **pub_key)
 Constructs internal representation of GroupPubKey. More...
 
void DeleteGroupPubKey (GroupPubKey_ **pub_key)
 Deallocates storage for internal representation of GroupPubKey. More...
 
+

Detailed Description

+

Group public key interface.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/hash_8h.html b/sgx-jvm/linux-sgx/external/epid/doc/html/hash_8h.html new file mode 100644 index 0000000000..fb3b6f669a --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/hash_8h.html @@ -0,0 +1,102 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: epid/common/math/hash.h File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
hash.h File Reference
+
+
+ +

Hash primitives. +More...

+
#include <stddef.h>
+#include <stdint.h>
+#include <limits.h>
+#include "epid/common/errors.h"
+
+ + + + +

+Data Structures

struct  Sha256Digest
 SHA256 digest. More...
 
+ + + + +

+Functions

EpidStatus Sha256MessageDigest (void const *msg, size_t len, Sha256Digest *digest)
 Computes SHA256 digest of a message. More...
 
+

Detailed Description

+

Hash primitives.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/implementation__notes_8dox.html b/sgx-jvm/linux-sgx/external/epid/doc/html/implementation__notes_8dox.html new file mode 100644 index 0000000000..be407ab5bb --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/implementation__notes_8dox.html @@ -0,0 +1,82 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: doc/docsrc/implementation_notes.dox File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
doc/docsrc/implementation_notes.dox File Reference
+
+
+ +

This file is used by Doxygen to generate documentation. +More...

+

Detailed Description

+

This file is used by Doxygen to generate documentation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/index.html b/sgx-jvm/linux-sgx/external/epid/doc/html/index.html new file mode 100644 index 0000000000..3a81885cd2 --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/index.html @@ -0,0 +1,78 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: Introducing the Intel® EPID SDK + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
Introducing the Intel® EPID SDK
+
+
+

Intel® EPID is a cryptographic protocol which enables the remote authentication of a trusted platform whilst preserving the user's privacy.

+

The Intel® EPID Software Development Kit provides an implementation of the Intel® EPID specification that developers can use when developing their own applications using Intel® EPID technology.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/issuer__material_8dox.html b/sgx-jvm/linux-sgx/external/epid/doc/html/issuer__material_8dox.html new file mode 100644 index 0000000000..b8c991864e --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/issuer__material_8dox.html @@ -0,0 +1,82 @@ + + + + + + + +Intel® Enhanced Privacy ID SDK: doc/docsrc/issuer_material.dox File Reference + + + + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + +
+
+ +
+
+
+ +
+
+
+
doc/docsrc/issuer_material.dox File Reference
+
+
+ +

This file is used by Doxygen to generate documentation. +More...

+

Detailed Description

+

This file is used by Doxygen to generate documentation.

+
+
+ + + + + diff --git a/sgx-jvm/linux-sgx/external/epid/doc/html/jquery.js b/sgx-jvm/linux-sgx/external/epid/doc/html/jquery.js new file mode 100644 index 0000000000..1f4d0b47ce --- /dev/null +++ b/sgx-jvm/linux-sgx/external/epid/doc/html/jquery.js @@ -0,0 +1,68 @@ +/*! + * jQuery JavaScript Library v1.7.1 + * http://jquery.com/ + * + * Copyright 2011, John Resig + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * Includes Sizzle.js + * http://sizzlejs.com/ + * Copyright 2011, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * + * Date: Mon Nov 21 21:11:03 2011 -0500 + */ +(function(bb,L){var av=bb.document,bu=bb.navigator,bl=bb.location;var b=(function(){var bF=function(b0,b1){return new bF.fn.init(b0,b1,bD)},bU=bb.jQuery,bH=bb.$,bD,bY=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,bM=/\S/,bI=/^\s+/,bE=/\s+$/,bA=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,bN=/^[\],:{}\s]*$/,bW=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,bP=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,bJ=/(?:^|:|,)(?:\s*\[)+/g,by=/(webkit)[ \/]([\w.]+)/,bR=/(opera)(?:.*version)?[ \/]([\w.]+)/,bQ=/(msie) ([\w.]+)/,bS=/(mozilla)(?:.*? rv:([\w.]+))?/,bB=/-([a-z]|[0-9])/ig,bZ=/^-ms-/,bT=function(b0,b1){return(b1+"").toUpperCase()},bX=bu.userAgent,bV,bC,e,bL=Object.prototype.toString,bG=Object.prototype.hasOwnProperty,bz=Array.prototype.push,bK=Array.prototype.slice,bO=String.prototype.trim,bv=Array.prototype.indexOf,bx={};bF.fn=bF.prototype={constructor:bF,init:function(b0,b4,b3){var b2,b5,b1,b6;if(!b0){return this}if(b0.nodeType){this.context=this[0]=b0;this.length=1;return this}if(b0==="body"&&!b4&&av.body){this.context=av;this[0]=av.body;this.selector=b0;this.length=1;return this}if(typeof b0==="string"){if(b0.charAt(0)==="<"&&b0.charAt(b0.length-1)===">"&&b0.length>=3){b2=[null,b0,null]}else{b2=bY.exec(b0)}if(b2&&(b2[1]||!b4)){if(b2[1]){b4=b4 instanceof bF?b4[0]:b4;b6=(b4?b4.ownerDocument||b4:av);b1=bA.exec(b0);if(b1){if(bF.isPlainObject(b4)){b0=[av.createElement(b1[1])];bF.fn.attr.call(b0,b4,true)}else{b0=[b6.createElement(b1[1])]}}else{b1=bF.buildFragment([b2[1]],[b6]);b0=(b1.cacheable?bF.clone(b1.fragment):b1.fragment).childNodes}return bF.merge(this,b0)}else{b5=av.getElementById(b2[2]);if(b5&&b5.parentNode){if(b5.id!==b2[2]){return b3.find(b0)}this.length=1;this[0]=b5}this.context=av;this.selector=b0;return this}}else{if(!b4||b4.jquery){return(b4||b3).find(b0)}else{return this.constructor(b4).find(b0)}}}else{if(bF.isFunction(b0)){return b3.ready(b0)}}if(b0.selector!==L){this.selector=b0.selector;this.context=b0.context}return bF.makeArray(b0,this)},selector:"",jquery:"1.7.1",length:0,size:function(){return this.length},toArray:function(){return bK.call(this,0)},get:function(b0){return b0==null?this.toArray():(b0<0?this[this.length+b0]:this[b0])},pushStack:function(b1,b3,b0){var b2=this.constructor();if(bF.isArray(b1)){bz.apply(b2,b1)}else{bF.merge(b2,b1)}b2.prevObject=this;b2.context=this.context;if(b3==="find"){b2.selector=this.selector+(this.selector?" ":"")+b0}else{if(b3){b2.selector=this.selector+"."+b3+"("+b0+")"}}return b2},each:function(b1,b0){return bF.each(this,b1,b0)},ready:function(b0){bF.bindReady();bC.add(b0);return this},eq:function(b0){b0=+b0;return b0===-1?this.slice(b0):this.slice(b0,b0+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(bK.apply(this,arguments),"slice",bK.call(arguments).join(","))},map:function(b0){return this.pushStack(bF.map(this,function(b2,b1){return b0.call(b2,b1,b2)}))},end:function(){return this.prevObject||this.constructor(null)},push:bz,sort:[].sort,splice:[].splice};bF.fn.init.prototype=bF.fn;bF.extend=bF.fn.extend=function(){var b9,b2,b0,b1,b6,b7,b5=arguments[0]||{},b4=1,b3=arguments.length,b8=false;if(typeof b5==="boolean"){b8=b5;b5=arguments[1]||{};b4=2}if(typeof b5!=="object"&&!bF.isFunction(b5)){b5={}}if(b3===b4){b5=this;--b4}for(;b40){return}bC.fireWith(av,[bF]);if(bF.fn.trigger){bF(av).trigger("ready").off("ready")}}},bindReady:function(){if(bC){return}bC=bF.Callbacks("once memory");if(av.readyState==="complete"){return setTimeout(bF.ready,1)}if(av.addEventListener){av.addEventListener("DOMContentLoaded",e,false);bb.addEventListener("load",bF.ready,false)}else{if(av.attachEvent){av.attachEvent("onreadystatechange",e);bb.attachEvent("onload",bF.ready);var b0=false;try{b0=bb.frameElement==null}catch(b1){}if(av.documentElement.doScroll&&b0){bw()}}}},isFunction:function(b0){return bF.type(b0)==="function"},isArray:Array.isArray||function(b0){return bF.type(b0)==="array"},isWindow:function(b0){return b0&&typeof b0==="object"&&"setInterval" in b0},isNumeric:function(b0){return !isNaN(parseFloat(b0))&&isFinite(b0)},type:function(b0){return b0==null?String(b0):bx[bL.call(b0)]||"object"},isPlainObject:function(b2){if(!b2||bF.type(b2)!=="object"||b2.nodeType||bF.isWindow(b2)){return false}try{if(b2.constructor&&!bG.call(b2,"constructor")&&!bG.call(b2.constructor.prototype,"isPrototypeOf")){return false}}catch(b1){return false}var b0;for(b0 in b2){}return b0===L||bG.call(b2,b0)},isEmptyObject:function(b1){for(var b0 in b1){return false}return true},error:function(b0){throw new Error(b0)},parseJSON:function(b0){if(typeof b0!=="string"||!b0){return null}b0=bF.trim(b0);if(bb.JSON&&bb.JSON.parse){return bb.JSON.parse(b0)}if(bN.test(b0.replace(bW,"@").replace(bP,"]").replace(bJ,""))){return(new Function("return "+b0))()}bF.error("Invalid JSON: "+b0)},parseXML:function(b2){var b0,b1;try{if(bb.DOMParser){b1=new DOMParser();b0=b1.parseFromString(b2,"text/xml")}else{b0=new ActiveXObject("Microsoft.XMLDOM");b0.async="false";b0.loadXML(b2)}}catch(b3){b0=L}if(!b0||!b0.documentElement||b0.getElementsByTagName("parsererror").length){bF.error("Invalid XML: "+b2)}return b0},noop:function(){},globalEval:function(b0){if(b0&&bM.test(b0)){(bb.execScript||function(b1){bb["eval"].call(bb,b1)})(b0)}},camelCase:function(b0){return b0.replace(bZ,"ms-").replace(bB,bT)},nodeName:function(b1,b0){return b1.nodeName&&b1.nodeName.toUpperCase()===b0.toUpperCase()},each:function(b3,b6,b2){var b1,b4=0,b5=b3.length,b0=b5===L||bF.isFunction(b3);if(b2){if(b0){for(b1 in b3){if(b6.apply(b3[b1],b2)===false){break}}}else{for(;b40&&b0[0]&&b0[b1-1])||b1===0||bF.isArray(b0));if(b3){for(;b21?aJ.call(arguments,0):bG;if(!(--bw)){bC.resolveWith(bC,bx)}}}function bz(bF){return function(bG){bB[bF]=arguments.length>1?aJ.call(arguments,0):bG;bC.notifyWith(bE,bB)}}if(e>1){for(;bv
a";bI=bv.getElementsByTagName("*");bF=bv.getElementsByTagName("a")[0];if(!bI||!bI.length||!bF){return{}}bG=av.createElement("select");bx=bG.appendChild(av.createElement("option"));bE=bv.getElementsByTagName("input")[0];bJ={leadingWhitespace:(bv.firstChild.nodeType===3),tbody:!bv.getElementsByTagName("tbody").length,htmlSerialize:!!bv.getElementsByTagName("link").length,style:/top/.test(bF.getAttribute("style")),hrefNormalized:(bF.getAttribute("href")==="/a"),opacity:/^0.55/.test(bF.style.opacity),cssFloat:!!bF.style.cssFloat,checkOn:(bE.value==="on"),optSelected:bx.selected,getSetAttribute:bv.className!=="t",enctype:!!av.createElement("form").enctype,html5Clone:av.createElement("nav").cloneNode(true).outerHTML!=="<:nav>",submitBubbles:true,changeBubbles:true,focusinBubbles:false,deleteExpando:true,noCloneEvent:true,inlineBlockNeedsLayout:false,shrinkWrapBlocks:false,reliableMarginRight:true};bE.checked=true;bJ.noCloneChecked=bE.cloneNode(true).checked;bG.disabled=true;bJ.optDisabled=!bx.disabled;try{delete bv.test}catch(bC){bJ.deleteExpando=false}if(!bv.addEventListener&&bv.attachEvent&&bv.fireEvent){bv.attachEvent("onclick",function(){bJ.noCloneEvent=false});bv.cloneNode(true).fireEvent("onclick")}bE=av.createElement("input");bE.value="t";bE.setAttribute("type","radio");bJ.radioValue=bE.value==="t";bE.setAttribute("checked","checked");bv.appendChild(bE);bD=av.createDocumentFragment();bD.appendChild(bv.lastChild);bJ.checkClone=bD.cloneNode(true).cloneNode(true).lastChild.checked;bJ.appendChecked=bE.checked;bD.removeChild(bE);bD.appendChild(bv);bv.innerHTML="";if(bb.getComputedStyle){bA=av.createElement("div");bA.style.width="0";bA.style.marginRight="0";bv.style.width="2px";bv.appendChild(bA);bJ.reliableMarginRight=(parseInt((bb.getComputedStyle(bA,null)||{marginRight:0}).marginRight,10)||0)===0}if(bv.attachEvent){for(by in {submit:1,change:1,focusin:1}){bB="on"+by;bw=(bB in bv);if(!bw){bv.setAttribute(bB,"return;");bw=(typeof bv[bB]==="function")}bJ[by+"Bubbles"]=bw}}bD.removeChild(bv);bD=bG=bx=bA=bv=bE=null;b(function(){var bM,bU,bV,bT,bN,bO,bL,bS,bR,e,bP,bQ=av.getElementsByTagName("body")[0];if(!bQ){return}bL=1;bS="position:absolute;top:0;left:0;width:1px;height:1px;margin:0;";bR="visibility:hidden;border:0;";e="style='"+bS+"border:5px solid #000;padding:0;'";bP="
";bM=av.createElement("div");bM.style.cssText=bR+"width:0;height:0;position:static;top:0;margin-top:"+bL+"px";bQ.insertBefore(bM,bQ.firstChild);bv=av.createElement("div");bM.appendChild(bv);bv.innerHTML="
t
";bz=bv.getElementsByTagName("td");bw=(bz[0].offsetHeight===0);bz[0].style.display="";bz[1].style.display="none";bJ.reliableHiddenOffsets=bw&&(bz[0].offsetHeight===0);bv.innerHTML="";bv.style.width=bv.style.paddingLeft="1px";b.boxModel=bJ.boxModel=bv.offsetWidth===2;if(typeof bv.style.zoom!=="undefined"){bv.style.display="inline";bv.style.zoom=1;bJ.inlineBlockNeedsLayout=(bv.offsetWidth===2);bv.style.display="";bv.innerHTML="
";bJ.shrinkWrapBlocks=(bv.offsetWidth!==2)}bv.style.cssText=bS+bR;bv.innerHTML=bP;bU=bv.firstChild;bV=bU.firstChild;bN=bU.nextSibling.firstChild.firstChild;bO={doesNotAddBorder:(bV.offsetTop!==5),doesAddBorderForTableAndCells:(bN.offsetTop===5)};bV.style.position="fixed";bV.style.top="20px";bO.fixedPosition=(bV.offsetTop===20||bV.offsetTop===15);bV.style.position=bV.style.top="";bU.style.overflow="hidden";bU.style.position="relative";bO.subtractsBorderForOverflowNotVisible=(bV.offsetTop===-5);bO.doesNotIncludeMarginInBodyOffset=(bQ.offsetTop!==bL);bQ.removeChild(bM);bv=bM=null;b.extend(bJ,bO)});return bJ})();var aS=/^(?:\{.*\}|\[.*\])$/,aA=/([A-Z])/g;b.extend({cache:{},uuid:0,expando:"jQuery"+(b.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:true,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:true},hasData:function(e){e=e.nodeType?b.cache[e[b.expando]]:e[b.expando];return !!e&&!S(e)},data:function(bx,bv,bz,by){if(!b.acceptData(bx)){return}var bG,bA,bD,bE=b.expando,bC=typeof bv==="string",bF=bx.nodeType,e=bF?b.cache:bx,bw=bF?bx[bE]:bx[bE]&&bE,bB=bv==="events";if((!bw||!e[bw]||(!bB&&!by&&!e[bw].data))&&bC&&bz===L){return}if(!bw){if(bF){bx[bE]=bw=++b.uuid}else{bw=bE}}if(!e[bw]){e[bw]={};if(!bF){e[bw].toJSON=b.noop}}if(typeof bv==="object"||typeof bv==="function"){if(by){e[bw]=b.extend(e[bw],bv)}else{e[bw].data=b.extend(e[bw].data,bv)}}bG=bA=e[bw];if(!by){if(!bA.data){bA.data={}}bA=bA.data}if(bz!==L){bA[b.camelCase(bv)]=bz}if(bB&&!bA[bv]){return bG.events}if(bC){bD=bA[bv];if(bD==null){bD=bA[b.camelCase(bv)]}}else{bD=bA}return bD},removeData:function(bx,bv,by){if(!b.acceptData(bx)){return}var bB,bA,bz,bC=b.expando,bD=bx.nodeType,e=bD?b.cache:bx,bw=bD?bx[bC]:bC;if(!e[bw]){return}if(bv){bB=by?e[bw]:e[bw].data;if(bB){if(!b.isArray(bv)){if(bv in bB){bv=[bv]}else{bv=b.camelCase(bv);if(bv in bB){bv=[bv]}else{bv=bv.split(" ")}}}for(bA=0,bz=bv.length;bA-1){return true}}return false},val:function(bx){var e,bv,by,bw=this[0];if(!arguments.length){if(bw){e=b.valHooks[bw.nodeName.toLowerCase()]||b.valHooks[bw.type];if(e&&"get" in e&&(bv=e.get(bw,"value"))!==L){return bv}bv=bw.value;return typeof bv==="string"?bv.replace(aU,""):bv==null?"":bv}return}by=b.isFunction(bx);return this.each(function(bA){var bz=b(this),bB;if(this.nodeType!==1){return}if(by){bB=bx.call(this,bA,bz.val())}else{bB=bx}if(bB==null){bB=""}else{if(typeof bB==="number"){bB+=""}else{if(b.isArray(bB)){bB=b.map(bB,function(bC){return bC==null?"":bC+""})}}}e=b.valHooks[this.nodeName.toLowerCase()]||b.valHooks[this.type];if(!e||!("set" in e)||e.set(this,bB,"value")===L){this.value=bB}})}});b.extend({valHooks:{option:{get:function(e){var bv=e.attributes.value;return !bv||bv.specified?e.value:e.text}},select:{get:function(e){var bA,bv,bz,bx,by=e.selectedIndex,bB=[],bC=e.options,bw=e.type==="select-one";if(by<0){return null}bv=bw?by:0;bz=bw?by+1:bC.length;for(;bv=0});if(!e.length){bv.selectedIndex=-1}return e}}},attrFn:{val:true,css:true,html:true,text:true,data:true,width:true,height:true,offset:true},attr:function(bA,bx,bB,bz){var bw,e,by,bv=bA.nodeType;if(!bA||bv===3||bv===8||bv===2){return}if(bz&&bx in b.attrFn){return b(bA)[bx](bB)}if(typeof bA.getAttribute==="undefined"){return b.prop(bA,bx,bB)}by=bv!==1||!b.isXMLDoc(bA);if(by){bx=bx.toLowerCase();e=b.attrHooks[bx]||(ao.test(bx)?aY:be)}if(bB!==L){if(bB===null){b.removeAttr(bA,bx);return}else{if(e&&"set" in e&&by&&(bw=e.set(bA,bB,bx))!==L){return bw}else{bA.setAttribute(bx,""+bB);return bB}}}else{if(e&&"get" in e&&by&&(bw=e.get(bA,bx))!==null){return bw}else{bw=bA.getAttribute(bx);return bw===null?L:bw}}},removeAttr:function(bx,bz){var by,bA,bv,e,bw=0;if(bz&&bx.nodeType===1){bA=bz.toLowerCase().split(af);e=bA.length;for(;bw=0)}}})});var bd=/^(?:textarea|input|select)$/i,n=/^([^\.]*)?(?:\.(.+))?$/,J=/\bhover(\.\S+)?\b/,aO=/^key/,bf=/^(?:mouse|contextmenu)|click/,T=/^(?:focusinfocus|focusoutblur)$/,U=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,Y=function(e){var bv=U.exec(e);if(bv){bv[1]=(bv[1]||"").toLowerCase();bv[3]=bv[3]&&new RegExp("(?:^|\\s)"+bv[3]+"(?:\\s|$)")}return bv},j=function(bw,e){var bv=bw.attributes||{};return((!e[1]||bw.nodeName.toLowerCase()===e[1])&&(!e[2]||(bv.id||{}).value===e[2])&&(!e[3]||e[3].test((bv["class"]||{}).value)))},bt=function(e){return b.event.special.hover?e:e.replace(J,"mouseenter$1 mouseleave$1")};b.event={add:function(bx,bC,bJ,bA,by){var bD,bB,bK,bI,bH,bF,e,bG,bv,bz,bw,bE;if(bx.nodeType===3||bx.nodeType===8||!bC||!bJ||!(bD=b._data(bx))){return}if(bJ.handler){bv=bJ;bJ=bv.handler}if(!bJ.guid){bJ.guid=b.guid++}bK=bD.events;if(!bK){bD.events=bK={}}bB=bD.handle;if(!bB){bD.handle=bB=function(bL){return typeof b!=="undefined"&&(!bL||b.event.triggered!==bL.type)?b.event.dispatch.apply(bB.elem,arguments):L};bB.elem=bx}bC=b.trim(bt(bC)).split(" ");for(bI=0;bI=0){bG=bG.slice(0,-1);bw=true}if(bG.indexOf(".")>=0){bx=bG.split(".");bG=bx.shift();bx.sort()}if((!bA||b.event.customEvent[bG])&&!b.event.global[bG]){return}bv=typeof bv==="object"?bv[b.expando]?bv:new b.Event(bG,bv):new b.Event(bG);bv.type=bG;bv.isTrigger=true;bv.exclusive=bw;bv.namespace=bx.join(".");bv.namespace_re=bv.namespace?new RegExp("(^|\\.)"+bx.join("\\.(?:.*\\.)?")+"(\\.|$)"):null;by=bG.indexOf(":")<0?"on"+bG:"";if(!bA){e=b.cache;for(bC in e){if(e[bC].events&&e[bC].events[bG]){b.event.trigger(bv,bD,e[bC].handle.elem,true)}}return}bv.result=L;if(!bv.target){bv.target=bA}bD=bD!=null?b.makeArray(bD):[];bD.unshift(bv);bF=b.event.special[bG]||{};if(bF.trigger&&bF.trigger.apply(bA,bD)===false){return}bB=[[bA,bF.bindType||bG]];if(!bJ&&!bF.noBubble&&!b.isWindow(bA)){bI=bF.delegateType||bG;bH=T.test(bI+bG)?bA:bA.parentNode;bz=null;for(;bH;bH=bH.parentNode){bB.push([bH,bI]);bz=bH}if(bz&&bz===bA.ownerDocument){bB.push([bz.defaultView||bz.parentWindow||bb,bI])}}for(bC=0;bCbA){bH.push({elem:this,matches:bz.slice(bA)})}for(bC=0;bC0?this.on(e,null,bx,bw):this.trigger(e)};if(b.attrFn){b.attrFn[e]=true}if(aO.test(e)){b.event.fixHooks[e]=b.event.keyHooks}if(bf.test(e)){b.event.fixHooks[e]=b.event.mouseHooks}}); +/*! + * Sizzle CSS Selector Engine + * Copyright 2011, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * More information: http://sizzlejs.com/ + */ +(function(){var bH=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,bC="sizcache"+(Math.random()+"").replace(".",""),bI=0,bL=Object.prototype.toString,bB=false,bA=true,bK=/\\/g,bO=/\r\n/g,bQ=/\W/;[0,0].sort(function(){bA=false;return 0});var by=function(bV,e,bY,bZ){bY=bY||[];e=e||av;var b1=e;if(e.nodeType!==1&&e.nodeType!==9){return[]}if(!bV||typeof bV!=="string"){return bY}var bS,b3,b6,bR,b2,b5,b4,bX,bU=true,bT=by.isXML(e),bW=[],b0=bV;do{bH.exec("");bS=bH.exec(b0);if(bS){b0=bS[3];bW.push(bS[1]);if(bS[2]){bR=bS[3];break}}}while(bS);if(bW.length>1&&bD.exec(bV)){if(bW.length===2&&bE.relative[bW[0]]){b3=bM(bW[0]+bW[1],e,bZ)}else{b3=bE.relative[bW[0]]?[e]:by(bW.shift(),e);while(bW.length){bV=bW.shift();if(bE.relative[bV]){bV+=bW.shift()}b3=bM(bV,b3,bZ)}}}else{if(!bZ&&bW.length>1&&e.nodeType===9&&!bT&&bE.match.ID.test(bW[0])&&!bE.match.ID.test(bW[bW.length-1])){b2=by.find(bW.shift(),e,bT);e=b2.expr?by.filter(b2.expr,b2.set)[0]:b2.set[0]}if(e){b2=bZ?{expr:bW.pop(),set:bF(bZ)}:by.find(bW.pop(),bW.length===1&&(bW[0]==="~"||bW[0]==="+")&&e.parentNode?e.parentNode:e,bT);b3=b2.expr?by.filter(b2.expr,b2.set):b2.set;if(bW.length>0){b6=bF(b3)}else{bU=false}while(bW.length){b5=bW.pop();b4=b5;if(!bE.relative[b5]){b5=""}else{b4=bW.pop()}if(b4==null){b4=e}bE.relative[b5](b6,b4,bT)}}else{b6=bW=[]}}if(!b6){b6=b3}if(!b6){by.error(b5||bV)}if(bL.call(b6)==="[object Array]"){if(!bU){bY.push.apply(bY,b6)}else{if(e&&e.nodeType===1){for(bX=0;b6[bX]!=null;bX++){if(b6[bX]&&(b6[bX]===true||b6[bX].nodeType===1&&by.contains(e,b6[bX]))){bY.push(b3[bX])}}}else{for(bX=0;b6[bX]!=null;bX++){if(b6[bX]&&b6[bX].nodeType===1){bY.push(b3[bX])}}}}}else{bF(b6,bY)}if(bR){by(bR,b1,bY,bZ);by.uniqueSort(bY)}return bY};by.uniqueSort=function(bR){if(bJ){bB=bA;bR.sort(bJ);if(bB){for(var e=1;e0};by.find=function(bX,e,bY){var bW,bS,bU,bT,bV,bR;if(!bX){return[]}for(bS=0,bU=bE.order.length;bS":function(bW,bR){var bV,bU=typeof bR==="string",bS=0,e=bW.length;if(bU&&!bQ.test(bR)){bR=bR.toLowerCase();for(;bS=0)){if(!bS){e.push(bV)}}else{if(bS){bR[bU]=false}}}}return false},ID:function(e){return e[1].replace(bK,"")},TAG:function(bR,e){return bR[1].replace(bK,"").toLowerCase()},CHILD:function(e){if(e[1]==="nth"){if(!e[2]){by.error(e[0])}e[2]=e[2].replace(/^\+|\s*/g,"");var bR=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(e[2]==="even"&&"2n"||e[2]==="odd"&&"2n+1"||!/\D/.test(e[2])&&"0n+"+e[2]||e[2]);e[2]=(bR[1]+(bR[2]||1))-0;e[3]=bR[3]-0}else{if(e[2]){by.error(e[0])}}e[0]=bI++;return e},ATTR:function(bU,bR,bS,e,bV,bW){var bT=bU[1]=bU[1].replace(bK,"");if(!bW&&bE.attrMap[bT]){bU[1]=bE.attrMap[bT]}bU[4]=(bU[4]||bU[5]||"").replace(bK,"");if(bU[2]==="~="){bU[4]=" "+bU[4]+" "}return bU},PSEUDO:function(bU,bR,bS,e,bV){if(bU[1]==="not"){if((bH.exec(bU[3])||"").length>1||/^\w/.test(bU[3])){bU[3]=by(bU[3],null,null,bR)}else{var bT=by.filter(bU[3],bR,bS,true^bV);if(!bS){e.push.apply(e,bT)}return false}}else{if(bE.match.POS.test(bU[0])||bE.match.CHILD.test(bU[0])){return true}}return bU},POS:function(e){e.unshift(true);return e}},filters:{enabled:function(e){return e.disabled===false&&e.type!=="hidden"},disabled:function(e){return e.disabled===true},checked:function(e){return e.checked===true},selected:function(e){if(e.parentNode){e.parentNode.selectedIndex}return e.selected===true},parent:function(e){return !!e.firstChild},empty:function(e){return !e.firstChild},has:function(bS,bR,e){return !!by(e[3],bS).length},header:function(e){return(/h\d/i).test(e.nodeName)},text:function(bS){var e=bS.getAttribute("type"),bR=bS.type;return bS.nodeName.toLowerCase()==="input"&&"text"===bR&&(e===bR||e===null)},radio:function(e){return e.nodeName.toLowerCase()==="input"&&"radio"===e.type},checkbox:function(e){return e.nodeName.toLowerCase()==="input"&&"checkbox"===e.type},file:function(e){return e.nodeName.toLowerCase()==="input"&&"file"===e.type},password:function(e){return e.nodeName.toLowerCase()==="input"&&"password"===e.type},submit:function(bR){var e=bR.nodeName.toLowerCase();return(e==="input"||e==="button")&&"submit"===bR.type},image:function(e){return e.nodeName.toLowerCase()==="input"&&"image"===e.type},reset:function(bR){var e=bR.nodeName.toLowerCase();return(e==="input"||e==="button")&&"reset"===bR.type},button:function(bR){var e=bR.nodeName.toLowerCase();return e==="input"&&"button"===bR.type||e==="button"},input:function(e){return(/input|select|textarea|button/i).test(e.nodeName)},focus:function(e){return e===e.ownerDocument.activeElement}},setFilters:{first:function(bR,e){return e===0},last:function(bS,bR,e,bT){return bR===bT.length-1},even:function(bR,e){return e%2===0},odd:function(bR,e){return e%2===1},lt:function(bS,bR,e){return bRe[3]-0},nth:function(bS,bR,e){return e[3]-0===bR},eq:function(bS,bR,e){return e[3]-0===bR}},filter:{PSEUDO:function(bS,bX,bW,bY){var e=bX[1],bR=bE.filters[e];if(bR){return bR(bS,bW,bX,bY)}else{if(e==="contains"){return(bS.textContent||bS.innerText||bw([bS])||"").indexOf(bX[3])>=0}else{if(e==="not"){var bT=bX[3];for(var bV=0,bU=bT.length;bV=0)}}},ID:function(bR,e){return bR.nodeType===1&&bR.getAttribute("id")===e},TAG:function(bR,e){return(e==="*"&&bR.nodeType===1)||!!bR.nodeName&&bR.nodeName.toLowerCase()===e},CLASS:function(bR,e){return(" "+(bR.className||bR.getAttribute("class"))+" ").indexOf(e)>-1},ATTR:function(bV,bT){var bS=bT[1],e=by.attr?by.attr(bV,bS):bE.attrHandle[bS]?bE.attrHandle[bS](bV):bV[bS]!=null?bV[bS]:bV.getAttribute(bS),bW=e+"",bU=bT[2],bR=bT[4];return e==null?bU==="!=":!bU&&by.attr?e!=null:bU==="="?bW===bR:bU==="*="?bW.indexOf(bR)>=0:bU==="~="?(" "+bW+" ").indexOf(bR)>=0:!bR?bW&&e!==false:bU==="!="?bW!==bR:bU==="^="?bW.indexOf(bR)===0:bU==="$="?bW.substr(bW.length-bR.length)===bR:bU==="|="?bW===bR||bW.substr(0,bR.length+1)===bR+"-":false},POS:function(bU,bR,bS,bV){var e=bR[2],bT=bE.setFilters[e];if(bT){return bT(bU,bS,bR,bV)}}}};var bD=bE.match.POS,bx=function(bR,e){return"\\"+(e-0+1)};for(var bz in bE.match){bE.match[bz]=new RegExp(bE.match[bz].source+(/(?![^\[]*\])(?![^\(]*\))/.source));bE.leftMatch[bz]=new RegExp(/(^(?:.|\r|\n)*?)/.source+bE.match[bz].source.replace(/\\(\d+)/g,bx))}var bF=function(bR,e){bR=Array.prototype.slice.call(bR,0);if(e){e.push.apply(e,bR);return e}return bR};try{Array.prototype.slice.call(av.documentElement.childNodes,0)[0].nodeType}catch(bP){bF=function(bU,bT){var bS=0,bR=bT||[];if(bL.call(bU)==="[object Array]"){Array.prototype.push.apply(bR,bU)}else{if(typeof bU.length==="number"){for(var e=bU.length;bS";e.insertBefore(bR,e.firstChild);if(av.getElementById(bS)){bE.find.ID=function(bU,bV,bW){if(typeof bV.getElementById!=="undefined"&&!bW){var bT=bV.getElementById(bU[1]);return bT?bT.id===bU[1]||typeof bT.getAttributeNode!=="undefined"&&bT.getAttributeNode("id").nodeValue===bU[1]?[bT]:L:[]}};bE.filter.ID=function(bV,bT){var bU=typeof bV.getAttributeNode!=="undefined"&&bV.getAttributeNode("id");return bV.nodeType===1&&bU&&bU.nodeValue===bT}}e.removeChild(bR);e=bR=null})();(function(){var e=av.createElement("div");e.appendChild(av.createComment(""));if(e.getElementsByTagName("*").length>0){bE.find.TAG=function(bR,bV){var bU=bV.getElementsByTagName(bR[1]);if(bR[1]==="*"){var bT=[];for(var bS=0;bU[bS];bS++){if(bU[bS].nodeType===1){bT.push(bU[bS])}}bU=bT}return bU}}e.innerHTML="";if(e.firstChild&&typeof e.firstChild.getAttribute!=="undefined"&&e.firstChild.getAttribute("href")!=="#"){bE.attrHandle.href=function(bR){return bR.getAttribute("href",2)}}e=null})();if(av.querySelectorAll){(function(){var e=by,bT=av.createElement("div"),bS="__sizzle__";bT.innerHTML="

";if(bT.querySelectorAll&&bT.querySelectorAll(".TEST").length===0){return}by=function(b4,bV,bZ,b3){bV=bV||av;if(!b3&&!by.isXML(bV)){var b2=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b4);if(b2&&(bV.nodeType===1||bV.nodeType===9)){if(b2[1]){return bF(bV.getElementsByTagName(b4),bZ)}else{if(b2[2]&&bE.find.CLASS&&bV.getElementsByClassName){return bF(bV.getElementsByClassName(b2[2]),bZ)}}}if(bV.nodeType===9){if(b4==="body"&&bV.body){return bF([bV.body],bZ)}else{if(b2&&b2[3]){var bY=bV.getElementById(b2[3]);if(bY&&bY.parentNode){if(bY.id===b2[3]){return bF([bY],bZ)}}else{return bF([],bZ)}}}try{return bF(bV.querySelectorAll(b4),bZ)}catch(b0){}}else{if(bV.nodeType===1&&bV.nodeName.toLowerCase()!=="object"){var bW=bV,bX=bV.getAttribute("id"),bU=bX||bS,b6=bV.parentNode,b5=/^\s*[+~]/.test(b4);if(!bX){bV.setAttribute("id",bU)}else{bU=bU.replace(/'/g,"\\$&")}if(b5&&b6){bV=bV.parentNode}try{if(!b5||b6){return bF(bV.querySelectorAll("[id='"+bU+"'] "+b4),bZ)}}catch(b1){}finally{if(!bX){bW.removeAttribute("id")}}}}}return e(b4,bV,bZ,b3)};for(var bR in e){by[bR]=e[bR]}bT=null})()}(function(){var e=av.documentElement,bS=e.matchesSelector||e.mozMatchesSelector||e.webkitMatchesSelector||e.msMatchesSelector;if(bS){var bU=!bS.call(av.createElement("div"),"div"),bR=false;try{bS.call(av.documentElement,"[test!='']:sizzle")}catch(bT){bR=true}by.matchesSelector=function(bW,bY){bY=bY.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!by.isXML(bW)){try{if(bR||!bE.match.PSEUDO.test(bY)&&!/!=/.test(bY)){var bV=bS.call(bW,bY);if(bV||!bU||bW.document&&bW.document.nodeType!==11){return bV}}}catch(bX){}}return by(bY,null,null,[bW]).length>0}}})();(function(){var e=av.createElement("div");e.innerHTML="
";if(!e.getElementsByClassName||e.getElementsByClassName("e").length===0){return}e.lastChild.className="e";if(e.getElementsByClassName("e").length===1){return}bE.order.splice(1,0,"CLASS");bE.find.CLASS=function(bR,bS,bT){if(typeof bS.getElementsByClassName!=="undefined"&&!bT){return bS.getElementsByClassName(bR[1])}};e=null})();function bv(bR,bW,bV,bZ,bX,bY){for(var bT=0,bS=bZ.length;bT0){bU=e;break}}}e=e[bR]}bZ[bT]=bU}}}if(av.documentElement.contains){by.contains=function(bR,e){return bR!==e&&(bR.contains?bR.contains(e):true)}}else{if(av.documentElement.compareDocumentPosition){by.contains=function(bR,e){return !!(bR.compareDocumentPosition(e)&16)}}else{by.contains=function(){return false}}}by.isXML=function(e){var bR=(e?e.ownerDocument||e:0).documentElement;return bR?bR.nodeName!=="HTML":false};var bM=function(bS,e,bW){var bV,bX=[],bU="",bY=e.nodeType?[e]:e;while((bV=bE.match.PSEUDO.exec(bS))){bU+=bV[0];bS=bS.replace(bE.match.PSEUDO,"")}bS=bE.relative[bS]?bS+"*":bS;for(var bT=0,bR=bY.length;bT0){for(bB=bA;bB=0:b.filter(e,this).length>0:this.filter(e).length>0)},closest:function(by,bx){var bv=[],bw,e,bz=this[0];if(b.isArray(by)){var bB=1;while(bz&&bz.ownerDocument&&bz!==bx){for(bw=0;bw-1:b.find.matchesSelector(bz,by)){bv.push(bz);break}else{bz=bz.parentNode;if(!bz||!bz.ownerDocument||bz===bx||bz.nodeType===11){break}}}}bv=bv.length>1?b.unique(bv):bv;return this.pushStack(bv,"closest",by)},index:function(e){if(!e){return(this[0]&&this[0].parentNode)?this.prevAll().length:-1}if(typeof e==="string"){return b.inArray(this[0],b(e))}return b.inArray(e.jquery?e[0]:e,this)},add:function(e,bv){var bx=typeof e==="string"?b(e,bv):b.makeArray(e&&e.nodeType?[e]:e),bw=b.merge(this.get(),bx);return this.pushStack(C(bx[0])||C(bw[0])?bw:b.unique(bw))},andSelf:function(){return this.add(this.prevObject)}});function C(e){return !e||!e.parentNode||e.parentNode.nodeType===11}b.each({parent:function(bv){var e=bv.parentNode;return e&&e.nodeType!==11?e:null},parents:function(e){return b.dir(e,"parentNode")},parentsUntil:function(bv,e,bw){return b.dir(bv,"parentNode",bw)},next:function(e){return b.nth(e,2,"nextSibling")},prev:function(e){return b.nth(e,2,"previousSibling")},nextAll:function(e){return b.dir(e,"nextSibling")},prevAll:function(e){return b.dir(e,"previousSibling")},nextUntil:function(bv,e,bw){return b.dir(bv,"nextSibling",bw)},prevUntil:function(bv,e,bw){return b.dir(bv,"previousSibling",bw)},siblings:function(e){return b.sibling(e.parentNode.firstChild,e)},children:function(e){return b.sibling(e.firstChild)},contents:function(e){return b.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:b.makeArray(e.childNodes)}},function(e,bv){b.fn[e]=function(by,bw){var bx=b.map(this,bv,by);if(!ab.test(e)){bw=by}if(bw&&typeof bw==="string"){bx=b.filter(bw,bx)}bx=this.length>1&&!ay[e]?b.unique(bx):bx;if((this.length>1||a9.test(bw))&&aq.test(e)){bx=bx.reverse()}return this.pushStack(bx,e,P.call(arguments).join(","))}});b.extend({filter:function(bw,e,bv){if(bv){bw=":not("+bw+")"}return e.length===1?b.find.matchesSelector(e[0],bw)?[e[0]]:[]:b.find.matches(bw,e)},dir:function(bw,bv,by){var e=[],bx=bw[bv];while(bx&&bx.nodeType!==9&&(by===L||bx.nodeType!==1||!b(bx).is(by))){if(bx.nodeType===1){e.push(bx)}bx=bx[bv]}return e},nth:function(by,e,bw,bx){e=e||1;var bv=0;for(;by;by=by[bw]){if(by.nodeType===1&&++bv===e){break}}return by},sibling:function(bw,bv){var e=[];for(;bw;bw=bw.nextSibling){if(bw.nodeType===1&&bw!==bv){e.push(bw)}}return e}});function aG(bx,bw,e){bw=bw||0;if(b.isFunction(bw)){return b.grep(bx,function(bz,by){var bA=!!bw.call(bz,by,bz);return bA===e})}else{if(bw.nodeType){return b.grep(bx,function(bz,by){return(bz===bw)===e})}else{if(typeof bw==="string"){var bv=b.grep(bx,function(by){return by.nodeType===1});if(bp.test(bw)){return b.filter(bw,bv,!e)}else{bw=b.filter(bw,bv)}}}}return b.grep(bx,function(bz,by){return(b.inArray(bz,bw)>=0)===e})}function a(e){var bw=aR.split("|"),bv=e.createDocumentFragment();if(bv.createElement){while(bw.length){bv.createElement(bw.pop())}}return bv}var aR="abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",ag=/ jQuery\d+="(?:\d+|null)"/g,ar=/^\s+/,R=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,d=/<([\w:]+)/,w=/",""],legend:[1,"
","
"],thead:[1,"","
"],tr:[2,"","
"],td:[3,"","
"],col:[2,"","
"],area:[1,"",""],_default:[0,"",""]},ac=a(av);ax.optgroup=ax.option;ax.tbody=ax.tfoot=ax.colgroup=ax.caption=ax.thead;ax.th=ax.td;if(!b.support.htmlSerialize){ax._default=[1,"div
","
"]}b.fn.extend({text:function(e){if(b.isFunction(e)){return this.each(function(bw){var bv=b(this);bv.text(e.call(this,bw,bv.text()))})}if(typeof e!=="object"&&e!==L){return this.empty().append((this[0]&&this[0].ownerDocument||av).createTextNode(e))}return b.text(this)},wrapAll:function(e){if(b.isFunction(e)){return this.each(function(bw){b(this).wrapAll(e.call(this,bw))})}if(this[0]){var bv=b(e,this[0].ownerDocument).eq(0).clone(true);if(this[0].parentNode){bv.insertBefore(this[0])}bv.map(function(){var bw=this;while(bw.firstChild&&bw.firstChild.nodeType===1){bw=bw.firstChild}return bw}).append(this)}return this},wrapInner:function(e){if(b.isFunction(e)){return this.each(function(bv){b(this).wrapInner(e.call(this,bv))})}return this.each(function(){var bv=b(this),bw=bv.contents();if(bw.length){bw.wrapAll(e)}else{bv.append(e)}})},wrap:function(e){var bv=b.isFunction(e);return this.each(function(bw){b(this).wrapAll(bv?e.call(this,bw):e)})},unwrap:function(){return this.parent().each(function(){if(!b.nodeName(this,"body")){b(this).replaceWith(this.childNodes)}}).end()},append:function(){return this.domManip(arguments,true,function(e){if(this.nodeType===1){this.appendChild(e)}})},prepend:function(){return this.domManip(arguments,true,function(e){if(this.nodeType===1){this.insertBefore(e,this.firstChild)}})},before:function(){if(this[0]&&this[0].parentNode){return this.domManip(arguments,false,function(bv){this.parentNode.insertBefore(bv,this)})}else{if(arguments.length){var e=b.clean(arguments);e.push.apply(e,this.toArray());return this.pushStack(e,"before",arguments)}}},after:function(){if(this[0]&&this[0].parentNode){return this.domManip(arguments,false,function(bv){this.parentNode.insertBefore(bv,this.nextSibling)})}else{if(arguments.length){var e=this.pushStack(this,"after",arguments);e.push.apply(e,b.clean(arguments));return e}}},remove:function(e,bx){for(var bv=0,bw;(bw=this[bv])!=null;bv++){if(!e||b.filter(e,[bw]).length){if(!bx&&bw.nodeType===1){b.cleanData(bw.getElementsByTagName("*"));b.cleanData([bw])}if(bw.parentNode){bw.parentNode.removeChild(bw)}}}return this},empty:function(){for(var e=0,bv;(bv=this[e])!=null;e++){if(bv.nodeType===1){b.cleanData(bv.getElementsByTagName("*"))}while(bv.firstChild){bv.removeChild(bv.firstChild)}}return this},clone:function(bv,e){bv=bv==null?false:bv;e=e==null?bv:e;return this.map(function(){return b.clone(this,bv,e)})},html:function(bx){if(bx===L){return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(ag,""):null}else{if(typeof bx==="string"&&!ae.test(bx)&&(b.support.leadingWhitespace||!ar.test(bx))&&!ax[(d.exec(bx)||["",""])[1].toLowerCase()]){bx=bx.replace(R,"<$1>");try{for(var bw=0,bv=this.length;bw1&&bw0?this.clone(true):this).get();b(bC[bA])[bv](by);bz=bz.concat(by)}return this.pushStack(bz,e,bC.selector)}}});function bg(e){if(typeof e.getElementsByTagName!=="undefined"){return e.getElementsByTagName("*")}else{if(typeof e.querySelectorAll!=="undefined"){return e.querySelectorAll("*")}else{return[]}}}function az(e){if(e.type==="checkbox"||e.type==="radio"){e.defaultChecked=e.checked}}function E(e){var bv=(e.nodeName||"").toLowerCase();if(bv==="input"){az(e)}else{if(bv!=="script"&&typeof e.getElementsByTagName!=="undefined"){b.grep(e.getElementsByTagName("input"),az)}}}function al(e){var bv=av.createElement("div");ac.appendChild(bv);bv.innerHTML=e.outerHTML;return bv.firstChild}b.extend({clone:function(by,bA,bw){var e,bv,bx,bz=b.support.html5Clone||!ah.test("<"+by.nodeName)?by.cloneNode(true):al(by);if((!b.support.noCloneEvent||!b.support.noCloneChecked)&&(by.nodeType===1||by.nodeType===11)&&!b.isXMLDoc(by)){ai(by,bz);e=bg(by);bv=bg(bz);for(bx=0;e[bx];++bx){if(bv[bx]){ai(e[bx],bv[bx])}}}if(bA){t(by,bz);if(bw){e=bg(by);bv=bg(bz);for(bx=0;e[bx];++bx){t(e[bx],bv[bx])}}}e=bv=null;return bz},clean:function(bw,by,bH,bA){var bF;by=by||av;if(typeof by.createElement==="undefined"){by=by.ownerDocument||by[0]&&by[0].ownerDocument||av}var bI=[],bB;for(var bE=0,bz;(bz=bw[bE])!=null;bE++){if(typeof bz==="number"){bz+=""}if(!bz){continue}if(typeof bz==="string"){if(!W.test(bz)){bz=by.createTextNode(bz)}else{bz=bz.replace(R,"<$1>");var bK=(d.exec(bz)||["",""])[1].toLowerCase(),bx=ax[bK]||ax._default,bD=bx[0],bv=by.createElement("div");if(by===av){ac.appendChild(bv)}else{a(by).appendChild(bv)}bv.innerHTML=bx[1]+bz+bx[2];while(bD--){bv=bv.lastChild}if(!b.support.tbody){var e=w.test(bz),bC=bK==="table"&&!e?bv.firstChild&&bv.firstChild.childNodes:bx[1]===""&&!e?bv.childNodes:[];for(bB=bC.length-1;bB>=0;--bB){if(b.nodeName(bC[bB],"tbody")&&!bC[bB].childNodes.length){bC[bB].parentNode.removeChild(bC[bB])}}}if(!b.support.leadingWhitespace&&ar.test(bz)){bv.insertBefore(by.createTextNode(ar.exec(bz)[0]),bv.firstChild)}bz=bv.childNodes}}var bG;if(!b.support.appendChecked){if(bz[0]&&typeof(bG=bz.length)==="number"){for(bB=0;bB=0){return bx+"px"}}else{return bx}}}});if(!b.support.opacity){b.cssHooks.opacity={get:function(bv,e){return au.test((e&&bv.currentStyle?bv.currentStyle.filter:bv.style.filter)||"")?(parseFloat(RegExp.$1)/100)+"":e?"1":""},set:function(by,bz){var bx=by.style,bv=by.currentStyle,e=b.isNumeric(bz)?"alpha(opacity="+bz*100+")":"",bw=bv&&bv.filter||bx.filter||"";bx.zoom=1;if(bz>=1&&b.trim(bw.replace(ak,""))===""){bx.removeAttribute("filter");if(bv&&!bv.filter){return}}bx.filter=ak.test(bw)?bw.replace(ak,e):bw+" "+e}}}b(function(){if(!b.support.reliableMarginRight){b.cssHooks.marginRight={get:function(bw,bv){var e;b.swap(bw,{display:"inline-block"},function(){if(bv){e=Z(bw,"margin-right","marginRight")}else{e=bw.style.marginRight}});return e}}}});if(av.defaultView&&av.defaultView.getComputedStyle){aI=function(by,bw){var bv,bx,e;bw=bw.replace(z,"-$1").toLowerCase();if((bx=by.ownerDocument.defaultView)&&(e=bx.getComputedStyle(by,null))){bv=e.getPropertyValue(bw);if(bv===""&&!b.contains(by.ownerDocument.documentElement,by)){bv=b.style(by,bw)}}return bv}}if(av.documentElement.currentStyle){aX=function(bz,bw){var bA,e,by,bv=bz.currentStyle&&bz.currentStyle[bw],bx=bz.style;if(bv===null&&bx&&(by=bx[bw])){bv=by}if(!bc.test(bv)&&bn.test(bv)){bA=bx.left;e=bz.runtimeStyle&&bz.runtimeStyle.left;if(e){bz.runtimeStyle.left=bz.currentStyle.left}bx.left=bw==="fontSize"?"1em":(bv||0);bv=bx.pixelLeft+"px";bx.left=bA;if(e){bz.runtimeStyle.left=e}}return bv===""?"auto":bv}}Z=aI||aX;function p(by,bw,bv){var bA=bw==="width"?by.offsetWidth:by.offsetHeight,bz=bw==="width"?an:a1,bx=0,e=bz.length;if(bA>0){if(bv!=="border"){for(;bx)<[^<]*)*<\/script>/gi,q=/^(?:select|textarea)/i,h=/\s+/,br=/([?&])_=[^&]*/,K=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,A=b.fn.load,aa={},r={},aE,s,aV=["*/"]+["*"];try{aE=bl.href}catch(aw){aE=av.createElement("a");aE.href="";aE=aE.href}s=K.exec(aE.toLowerCase())||[];function f(e){return function(by,bA){if(typeof by!=="string"){bA=by;by="*"}if(b.isFunction(bA)){var bx=by.toLowerCase().split(h),bw=0,bz=bx.length,bv,bB,bC;for(;bw=0){var e=bw.slice(by,bw.length);bw=bw.slice(0,by)}var bx="GET";if(bz){if(b.isFunction(bz)){bA=bz;bz=L}else{if(typeof bz==="object"){bz=b.param(bz,b.ajaxSettings.traditional);bx="POST"}}}var bv=this;b.ajax({url:bw,type:bx,dataType:"html",data:bz,complete:function(bC,bB,bD){bD=bC.responseText;if(bC.isResolved()){bC.done(function(bE){bD=bE});bv.html(e?b("
").append(bD.replace(a6,"")).find(e):bD)}if(bA){bv.each(bA,[bD,bB,bC])}}});return this},serialize:function(){return b.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?b.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||q.test(this.nodeName)||aZ.test(this.type))}).map(function(e,bv){var bw=b(this).val();return bw==null?null:b.isArray(bw)?b.map(bw,function(by,bx){return{name:bv.name,value:by.replace(bs,"\r\n")}}):{name:bv.name,value:bw.replace(bs,"\r\n")}}).get()}});b.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(e,bv){b.fn[bv]=function(bw){return this.on(bv,bw)}});b.each(["get","post"],function(e,bv){b[bv]=function(bw,by,bz,bx){if(b.isFunction(by)){bx=bx||bz;bz=by;by=L}return b.ajax({type:bv,url:bw,data:by,success:bz,dataType:bx})}});b.extend({getScript:function(e,bv){return b.get(e,L,bv,"script")},getJSON:function(e,bv,bw){return b.get(e,bv,bw,"json")},ajaxSetup:function(bv,e){if(e){am(bv,b.ajaxSettings)}else{e=bv;bv=b.ajaxSettings}am(bv,e);return bv},ajaxSettings:{url:aE,isLocal:aM.test(s[1]),global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":aV},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":bb.String,"text html":true,"text json":b.parseJSON,"text xml":b.parseXML},flatOptions:{context:true,url:true}},ajaxPrefilter:f(aa),ajaxTransport:f(r),ajax:function(bz,bx){if(typeof bz==="object"){bx=bz;bz=L}bx=bx||{};var bD=b.ajaxSetup({},bx),bS=bD.context||bD,bG=bS!==bD&&(bS.nodeType||bS instanceof b)?b(bS):b.event,bR=b.Deferred(),bN=b.Callbacks("once memory"),bB=bD.statusCode||{},bC,bH={},bO={},bQ,by,bL,bE,bI,bA=0,bw,bK,bJ={readyState:0,setRequestHeader:function(bT,bU){if(!bA){var e=bT.toLowerCase();bT=bO[e]=bO[e]||bT;bH[bT]=bU}return this},getAllResponseHeaders:function(){return bA===2?bQ:null},getResponseHeader:function(bT){var e;if(bA===2){if(!by){by={};while((e=aD.exec(bQ))){by[e[1].toLowerCase()]=e[2]}}e=by[bT.toLowerCase()]}return e===L?null:e},overrideMimeType:function(e){if(!bA){bD.mimeType=e}return this},abort:function(e){e=e||"abort";if(bL){bL.abort(e)}bF(0,e);return this}};function bF(bZ,bU,b0,bW){if(bA===2){return}bA=2;if(bE){clearTimeout(bE)}bL=L;bQ=bW||"";bJ.readyState=bZ>0?4:0;var bT,b4,b3,bX=bU,bY=b0?bj(bD,bJ,b0):L,bV,b2;if(bZ>=200&&bZ<300||bZ===304){if(bD.ifModified){if((bV=bJ.getResponseHeader("Last-Modified"))){b.lastModified[bC]=bV}if((b2=bJ.getResponseHeader("Etag"))){b.etag[bC]=b2}}if(bZ===304){bX="notmodified";bT=true}else{try{b4=G(bD,bY);bX="success";bT=true}catch(b1){bX="parsererror";b3=b1}}}else{b3=bX;if(!bX||bZ){bX="error";if(bZ<0){bZ=0}}}bJ.status=bZ;bJ.statusText=""+(bU||bX);if(bT){bR.resolveWith(bS,[b4,bX,bJ])}else{bR.rejectWith(bS,[bJ,bX,b3])}bJ.statusCode(bB);bB=L;if(bw){bG.trigger("ajax"+(bT?"Success":"Error"),[bJ,bD,bT?b4:b3])}bN.fireWith(bS,[bJ,bX]);if(bw){bG.trigger("ajaxComplete",[bJ,bD]);if(!(--b.active)){b.event.trigger("ajaxStop")}}}bR.promise(bJ);bJ.success=bJ.done;bJ.error=bJ.fail;bJ.complete=bN.add;bJ.statusCode=function(bT){if(bT){var e;if(bA<2){for(e in bT){bB[e]=[bB[e],bT[e]]}}else{e=bT[bJ.status];bJ.then(e,e)}}return this};bD.url=((bz||bD.url)+"").replace(bq,"").replace(c,s[1]+"//");bD.dataTypes=b.trim(bD.dataType||"*").toLowerCase().split(h);if(bD.crossDomain==null){bI=K.exec(bD.url.toLowerCase());bD.crossDomain=!!(bI&&(bI[1]!=s[1]||bI[2]!=s[2]||(bI[3]||(bI[1]==="http:"?80:443))!=(s[3]||(s[1]==="http:"?80:443))))}if(bD.data&&bD.processData&&typeof bD.data!=="string"){bD.data=b.param(bD.data,bD.traditional)}aW(aa,bD,bx,bJ);if(bA===2){return false}bw=bD.global;bD.type=bD.type.toUpperCase();bD.hasContent=!aQ.test(bD.type);if(bw&&b.active++===0){b.event.trigger("ajaxStart")}if(!bD.hasContent){if(bD.data){bD.url+=(M.test(bD.url)?"&":"?")+bD.data;delete bD.data}bC=bD.url;if(bD.cache===false){var bv=b.now(),bP=bD.url.replace(br,"$1_="+bv);bD.url=bP+((bP===bD.url)?(M.test(bD.url)?"&":"?")+"_="+bv:"")}}if(bD.data&&bD.hasContent&&bD.contentType!==false||bx.contentType){bJ.setRequestHeader("Content-Type",bD.contentType)}if(bD.ifModified){bC=bC||bD.url;if(b.lastModified[bC]){bJ.setRequestHeader("If-Modified-Since",b.lastModified[bC])}if(b.etag[bC]){bJ.setRequestHeader("If-None-Match",b.etag[bC])}}bJ.setRequestHeader("Accept",bD.dataTypes[0]&&bD.accepts[bD.dataTypes[0]]?bD.accepts[bD.dataTypes[0]]+(bD.dataTypes[0]!=="*"?", "+aV+"; q=0.01":""):bD.accepts["*"]);for(bK in bD.headers){bJ.setRequestHeader(bK,bD.headers[bK])}if(bD.beforeSend&&(bD.beforeSend.call(bS,bJ,bD)===false||bA===2)){bJ.abort();return false}for(bK in {success:1,error:1,complete:1}){bJ[bK](bD[bK])}bL=aW(r,bD,bx,bJ);if(!bL){bF(-1,"No Transport")}else{bJ.readyState=1;if(bw){bG.trigger("ajaxSend",[bJ,bD])}if(bD.async&&bD.timeout>0){bE=setTimeout(function(){bJ.abort("timeout")},bD.timeout)}try{bA=1;bL.send(bH,bF)}catch(bM){if(bA<2){bF(-1,bM)}else{throw bM}}}return bJ},param:function(e,bw){var bv=[],by=function(bz,bA){bA=b.isFunction(bA)?bA():bA;bv[bv.length]=encodeURIComponent(bz)+"="+encodeURIComponent(bA)};if(bw===L){bw=b.ajaxSettings.traditional}if(b.isArray(e)||(e.jquery&&!b.isPlainObject(e))){b.each(e,function(){by(this.name,this.value)})}else{for(var bx in e){v(bx,e[bx],bw,by)}}return bv.join("&").replace(k,"+")}});function v(bw,by,bv,bx){if(b.isArray(by)){b.each(by,function(bA,bz){if(bv||ap.test(bw)){bx(bw,bz)}else{v(bw+"["+(typeof bz==="object"||b.isArray(bz)?bA:"")+"]",bz,bv,bx)}})}else{if(!bv&&by!=null&&typeof by==="object"){for(var e in by){v(bw+"["+e+"]",by[e],bv,bx)}}else{bx(bw,by)}}}b.extend({active:0,lastModified:{},etag:{}});function bj(bD,bC,bz){var bv=bD.contents,bB=bD.dataTypes,bw=bD.responseFields,by,bA,bx,e;for(bA in bw){if(bA in bz){bC[bw[bA]]=bz[bA]}}while(bB[0]==="*"){bB.shift();if(by===L){by=bD.mimeType||bC.getResponseHeader("content-type")}}if(by){for(bA in bv){if(bv[bA]&&bv[bA].test(by)){bB.unshift(bA);break}}}if(bB[0] in bz){bx=bB[0]}else{for(bA in bz){if(!bB[0]||bD.converters[bA+" "+bB[0]]){bx=bA;break}if(!e){e=bA}}bx=bx||e}if(bx){if(bx!==bB[0]){bB.unshift(bx)}return bz[bx]}}function G(bH,bz){if(bH.dataFilter){bz=bH.dataFilter(bz,bH.dataType)}var bD=bH.dataTypes,bG={},bA,bE,bw=bD.length,bB,bC=bD[0],bx,by,bF,bv,e;for(bA=1;bA=bw.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();bw.animatedProperties[this.prop]=true;for(bA in bw.animatedProperties){if(bw.animatedProperties[bA]!==true){e=false}}if(e){if(bw.overflow!=null&&!b.support.shrinkWrapBlocks){b.each(["","X","Y"],function(bC,bD){bz.style["overflow"+bD]=bw.overflow[bC]})}if(bw.hide){b(bz).hide()}if(bw.hide||bw.show){for(bA in bw.animatedProperties){b.style(bz,bA,bw.orig[bA]);b.removeData(bz,"fxshow"+bA,true);b.removeData(bz,"toggle"+bA,true)}}bv=bw.complete;if(bv){bw.complete=false;bv.call(bz)}}return false}else{if(bw.duration==Infinity){this.now=bx}else{bB=bx-this.startTime;this.state=bB/bw.duration;this.pos=b.easing[bw.animatedProperties[this.prop]](this.state,bB,0,1,bw.duration);this.now=this.start+((this.end-this.start)*this.pos)}this.update()}return true}};b.extend(b.fx,{tick:function(){var bw,bv=b.timers,e=0;for(;e").appendTo(e),bw=bv.css("display");bv.remove();if(bw==="none"||bw===""){if(!a8){a8=av.createElement("iframe");a8.frameBorder=a8.width=a8.height=0}e.appendChild(a8);if(!m||!a8.createElement){m=(a8.contentWindow||a8.contentDocument).document;m.write((av.compatMode==="CSS1Compat"?"":"")+"");m.close()}bv=m.createElement(bx);m.body.appendChild(bv);bw=b.css(bv,"display");e.removeChild(a8)}Q[bx]=bw}return Q[bx]}var V=/^t(?:able|d|h)$/i,ad=/^(?:body|html)$/i;if("getBoundingClientRect" in av.documentElement){b.fn.offset=function(bI){var by=this[0],bB;if(bI){return this.each(function(e){b.offset.setOffset(this,bI,e)})}if(!by||!by.ownerDocument){return null}if(by===by.ownerDocument.body){return b.offset.bodyOffset(by)}try{bB=by.getBoundingClientRect()}catch(bF){}var bH=by.ownerDocument,bw=bH.documentElement;if(!bB||!b.contains(bw,by)){return bB?{top:bB.top,left:bB.left}:{top:0,left:0}}var bC=bH.body,bD=aK(bH),bA=bw.clientTop||bC.clientTop||0,bE=bw.clientLeft||bC.clientLeft||0,bv=bD.pageYOffset||b.support.boxModel&&bw.scrollTop||bC.scrollTop,bz=bD.pageXOffset||b.support.boxModel&&bw.scrollLeft||bC.scrollLeft,bG=bB.top+bv-bA,bx=bB.left+bz-bE;return{top:bG,left:bx}}}else{b.fn.offset=function(bF){var bz=this[0];if(bF){return this.each(function(bG){b.offset.setOffset(this,bF,bG)})}if(!bz||!bz.ownerDocument){return null}if(bz===bz.ownerDocument.body){return b.offset.bodyOffset(bz)}var bC,bw=bz.offsetParent,bv=bz,bE=bz.ownerDocument,bx=bE.documentElement,bA=bE.body,bB=bE.defaultView,e=bB?bB.getComputedStyle(bz,null):bz.currentStyle,bD=bz.offsetTop,by=bz.offsetLeft;while((bz=bz.parentNode)&&bz!==bA&&bz!==bx){if(b.support.fixedPosition&&e.position==="fixed"){break}bC=bB?bB.getComputedStyle(bz,null):bz.currentStyle;bD-=bz.scrollTop;by-=bz.scrollLeft;if(bz===bw){bD+=bz.offsetTop;by+=bz.offsetLeft;if(b.support.doesNotAddBorder&&!(b.support.doesAddBorderForTableAndCells&&V.test(bz.nodeName))){bD+=parseFloat(bC.borderTopWidth)||0;by+=parseFloat(bC.borderLeftWidth)||0}bv=bw;bw=bz.offsetParent}if(b.support.subtractsBorderForOverflowNotVisible&&bC.overflow!=="visible"){bD+=parseFloat(bC.borderTopWidth)||0;by+=parseFloat(bC.borderLeftWidth)||0}e=bC}if(e.position==="relative"||e.position==="static"){bD+=bA.offsetTop;by+=bA.offsetLeft}if(b.support.fixedPosition&&e.position==="fixed"){bD+=Math.max(bx.scrollTop,bA.scrollTop);by+=Math.max(bx.scrollLeft,bA.scrollLeft)}return{top:bD,left:by}}}b.offset={bodyOffset:function(e){var bw=e.offsetTop,bv=e.offsetLeft;if(b.support.doesNotIncludeMarginInBodyOffset){bw+=parseFloat(b.css(e,"marginTop"))||0;bv+=parseFloat(b.css(e,"marginLeft"))||0}return{top:bw,left:bv}},setOffset:function(bx,bG,bA){var bB=b.css(bx,"position");if(bB==="static"){bx.style.position="relative"}var bz=b(bx),bv=bz.offset(),e=b.css(bx,"top"),bE=b.css(bx,"left"),bF=(bB==="absolute"||bB==="fixed")&&b.inArray("auto",[e,bE])>-1,bD={},bC={},bw,by;if(bF){bC=bz.position();bw=bC.top;by=bC.left}else{bw=parseFloat(e)||0;by=parseFloat(bE)||0}if(b.isFunction(bG)){bG=bG.call(bx,bA,bv)}if(bG.top!=null){bD.top=(bG.top-bv.top)+bw}if(bG.left!=null){bD.left=(bG.left-bv.left)+by}if("using" in bG){bG.using.call(bx,bD)}else{bz.css(bD)}}};b.fn.extend({position:function(){if(!this[0]){return null}var bw=this[0],bv=this.offsetParent(),bx=this.offset(),e=ad.test(bv[0].nodeName)?{top:0,left:0}:bv.offset();bx.top-=parseFloat(b.css(bw,"marginTop"))||0;bx.left-=parseFloat(b.css(bw,"marginLeft"))||0;e.top+=parseFloat(b.css(bv[0],"borderTopWidth"))||0;e.left+=parseFloat(b.css(bv[0],"borderLeftWidth"))||0;return{top:bx.top-e.top,left:bx.left-e.left}},offsetParent:function(){return this.map(function(){var e=this.offsetParent||av.body;while(e&&(!ad.test(e.nodeName)&&b.css(e,"position")==="static")){e=e.offsetParent}return e})}});b.each(["Left","Top"],function(bv,e){var bw="scroll"+e;b.fn[bw]=function(bz){var bx,by;if(bz===L){bx=this[0];if(!bx){return null}by=aK(bx);return by?("pageXOffset" in by)?by[bv?"pageYOffset":"pageXOffset"]:b.support.boxModel&&by.document.documentElement[bw]||by.document.body[bw]:bx[bw]}return this.each(function(){by=aK(this);if(by){by.scrollTo(!bv?bz:b(by).scrollLeft(),bv?bz:b(by).scrollTop())}else{this[bw]=bz}})}});function aK(e){return b.isWindow(e)?e:e.nodeType===9?e.defaultView||e.parentWindow:false}b.each(["Height","Width"],function(bv,e){var bw=e.toLowerCase();b.fn["inner"+e]=function(){var bx=this[0];return bx?bx.style?parseFloat(b.css(bx,bw,"padding")):this[bw]():null};b.fn["outer"+e]=function(by){var bx=this[0];return bx?bx.style?parseFloat(b.css(bx,bw,by?"margin":"border")):this[bw]():null};b.fn[bw]=function(bz){var bA=this[0];if(!bA){return bz==null?null:this}if(b.isFunction(bz)){return this.each(function(bE){var bD=b(this);bD[bw](bz.call(this,bE,bD[bw]()))})}if(b.isWindow(bA)){var bB=bA.document.documentElement["client"+e],bx=bA.document.body;return bA.document.compatMode==="CSS1Compat"&&bB||bx&&bx["client"+e]||bB}else{if(bA.nodeType===9){return Math.max(bA.documentElement["client"+e],bA.body["scroll"+e],bA.documentElement["scroll"+e],bA.body["offset"+e],bA.documentElement["offset"+e])}else{if(bz===L){var bC=b.css(bA,bw),by=parseFloat(bC);return b.isNumeric(by)?by:bC}else{return this.css(bw,typeof bz==="string"?bz:bz+"px")}}}}});bb.jQuery=bb.$=b;if(typeof define==="function"&&define.amd&&define.amd.jQuery){define("jquery",[],function(){return b})}})(window);/*! + * jQuery UI 1.8.18 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI + */ +(function(a,d){a.ui=a.ui||{};if(a.ui.version){return}a.extend(a.ui,{version:"1.8.18",keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91}});a.fn.extend({propAttr:a.fn.prop||a.fn.attr,_focus:a.fn.focus,focus:function(e,f){return typeof e==="number"?this.each(function(){var g=this;setTimeout(function(){a(g).focus();if(f){f.call(g)}},e)}):this._focus.apply(this,arguments)},scrollParent:function(){var e;if((a.browser.msie&&(/(static|relative)/).test(this.css("position")))||(/absolute/).test(this.css("position"))){e=this.parents().filter(function(){return(/(relative|absolute|fixed)/).test(a.curCSS(this,"position",1))&&(/(auto|scroll)/).test(a.curCSS(this,"overflow",1)+a.curCSS(this,"overflow-y",1)+a.curCSS(this,"overflow-x",1))}).eq(0)}else{e=this.parents().filter(function(){return(/(auto|scroll)/).test(a.curCSS(this,"overflow",1)+a.curCSS(this,"overflow-y",1)+a.curCSS(this,"overflow-x",1))}).eq(0)}return(/fixed/).test(this.css("position"))||!e.length?a(document):e},zIndex:function(h){if(h!==d){return this.css("zIndex",h)}if(this.length){var f=a(this[0]),e,g;while(f.length&&f[0]!==document){e=f.css("position");if(e==="absolute"||e==="relative"||e==="fixed"){g=parseInt(f.css("zIndex"),10);if(!isNaN(g)&&g!==0){return g}}f=f.parent()}}return 0},disableSelection:function(){return this.bind((a.support.selectstart?"selectstart":"mousedown")+".ui-disableSelection",function(e){e.preventDefault()})},enableSelection:function(){return this.unbind(".ui-disableSelection")}});a.each(["Width","Height"],function(g,e){var f=e==="Width"?["Left","Right"]:["Top","Bottom"],h=e.toLowerCase(),k={innerWidth:a.fn.innerWidth,innerHeight:a.fn.innerHeight,outerWidth:a.fn.outerWidth,outerHeight:a.fn.outerHeight};function j(m,l,i,n){a.each(f,function(){l-=parseFloat(a.curCSS(m,"padding"+this,true))||0;if(i){l-=parseFloat(a.curCSS(m,"border"+this+"Width",true))||0}if(n){l-=parseFloat(a.curCSS(m,"margin"+this,true))||0}});return l}a.fn["inner"+e]=function(i){if(i===d){return k["inner"+e].call(this)}return this.each(function(){a(this).css(h,j(this,i)+"px")})};a.fn["outer"+e]=function(i,l){if(typeof i!=="number"){return k["outer"+e].call(this,i)}return this.each(function(){a(this).css(h,j(this,i,true,l)+"px")})}});function c(g,e){var j=g.nodeName.toLowerCase();if("area"===j){var i=g.parentNode,h=i.name,f;if(!g.href||!h||i.nodeName.toLowerCase()!=="map"){return false}f=a("img[usemap=#"+h+"]")[0];return !!f&&b(f)}return(/input|select|textarea|button|object/.test(j)?!g.disabled:"a"==j?g.href||e:e)&&b(g)}function b(e){return !a(e).parents().andSelf().filter(function(){return a.curCSS(this,"visibility")==="hidden"||a.expr.filters.hidden(this)}).length}a.extend(a.expr[":"],{data:function(g,f,e){return !!a.data(g,e[3])},focusable:function(e){return c(e,!isNaN(a.attr(e,"tabindex")))},tabbable:function(g){var e=a.attr(g,"tabindex"),f=isNaN(e);return(f||e>=0)&&c(g,!f)}});a(function(){var e=document.body,f=e.appendChild(f=document.createElement("div"));f.offsetHeight;a.extend(f.style,{minHeight:"100px",height:"auto",padding:0,borderWidth:0});a.support.minHeight=f.offsetHeight===100;a.support.selectstart="onselectstart" in f;e.removeChild(f).style.display="none"});a.extend(a.ui,{plugin:{add:function(f,g,j){var h=a.ui[f].prototype;for(var e in j){h.plugins[e]=h.plugins[e]||[];h.plugins[e].push([g,j[e]])}},call:function(e,g,f){var j=e.plugins[g];if(!j||!e.element[0].parentNode){return}for(var h=0;h0){return true}h[e]=1;g=(h[e]>0);h[e]=0;return g},isOverAxis:function(f,e,g){return(f>e)&&(f<(e+g))},isOver:function(j,f,i,h,e,g){return a.ui.isOverAxis(j,i,e)&&a.ui.isOverAxis(f,h,g)}})})(jQuery);/*! + * jQuery UI Widget 1.8.18 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Widget + */ +(function(b,d){if(b.cleanData){var c=b.cleanData;b.cleanData=function(f){for(var g=0,h;(h=f[g])!=null;g++){try{b(h).triggerHandler("remove")}catch(j){}}c(f)}}else{var a=b.fn.remove;b.fn.remove=function(e,f){return this.each(function(){if(!f){if(!e||b.filter(e,[this]).length){b("*",this).add([this]).each(function(){try{b(this).triggerHandler("remove")}catch(g){}})}}return a.call(b(this),e,f)})}}b.widget=function(f,h,e){var g=f.split(".")[0],j;f=f.split(".")[1];j=g+"-"+f;if(!e){e=h;h=b.Widget}b.expr[":"][j]=function(k){return !!b.data(k,f)};b[g]=b[g]||{};b[g][f]=function(k,l){if(arguments.length){this._createWidget(k,l)}};var i=new h();i.options=b.extend(true,{},i.options);b[g][f].prototype=b.extend(true,i,{namespace:g,widgetName:f,widgetEventPrefix:b[g][f].prototype.widgetEventPrefix||f,widgetBaseClass:j},e);b.widget.bridge(f,b[g][f])};b.widget.bridge=function(f,e){b.fn[f]=function(i){var g=typeof i==="string",h=Array.prototype.slice.call(arguments,1),j=this;i=!g&&h.length?b.extend.apply(null,[true,i].concat(h)):i;if(g&&i.charAt(0)==="_"){return j}if(g){this.each(function(){var k=b.data(this,f),l=k&&b.isFunction(k[i])?k[i].apply(k,h):k;if(l!==k&&l!==d){j=l;return false}})}else{this.each(function(){var k=b.data(this,f);if(k){k.option(i||{})._init()}else{b.data(this,f,new e(i,this))}})}return j}};b.Widget=function(e,f){if(arguments.length){this._createWidget(e,f)}};b.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",options:{disabled:false},_createWidget:function(f,g){b.data(g,this.widgetName,this);this.element=b(g);this.options=b.extend(true,{},this.options,this._getCreateOptions(),f);var e=this;this.element.bind("remove."+this.widgetName,function(){e.destroy()});this._create();this._trigger("create");this._init()},_getCreateOptions:function(){return b.metadata&&b.metadata.get(this.element[0])[this.widgetName]},_create:function(){},_init:function(){},destroy:function(){this.element.unbind("."+this.widgetName).removeData(this.widgetName);this.widget().unbind("."+this.widgetName).removeAttr("aria-disabled").removeClass(this.widgetBaseClass+"-disabled ui-state-disabled")},widget:function(){return this.element},option:function(f,g){var e=f;if(arguments.length===0){return b.extend({},this.options)}if(typeof f==="string"){if(g===d){return this.options[f]}e={};e[f]=g}this._setOptions(e);return this},_setOptions:function(f){var e=this;b.each(f,function(g,h){e._setOption(g,h)});return this},_setOption:function(e,f){this.options[e]=f;if(e==="disabled"){this.widget()[f?"addClass":"removeClass"](this.widgetBaseClass+"-disabled ui-state-disabled").attr("aria-disabled",f)}return this},enable:function(){return this._setOption("disabled",false)},disable:function(){return this._setOption("disabled",true)},_trigger:function(e,f,g){var j,i,h=this.options[e];g=g||{};f=b.Event(f);f.type=(e===this.widgetEventPrefix?e:this.widgetEventPrefix+e).toLowerCase();f.target=this.element[0];i=f.originalEvent;if(i){for(j in i){if(!(j in f)){f[j]=i[j]}}}this.element.trigger(f,g);return !(b.isFunction(h)&&h.call(this.element[0],f,g)===false||f.isDefaultPrevented())}}})(jQuery);/*! + * jQuery UI Mouse 1.8.18 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Mouse + * + * Depends: + * jquery.ui.widget.js + */ +(function(b,c){var a=false;b(document).mouseup(function(d){a=false});b.widget("ui.mouse",{options:{cancel:":input,option",distance:1,delay:0},_mouseInit:function(){var d=this;this.element.bind("mousedown."+this.widgetName,function(e){return d._mouseDown(e)}).bind("click."+this.widgetName,function(e){if(true===b.data(e.target,d.widgetName+".preventClickEvent")){b.removeData(e.target,d.widgetName+".preventClickEvent");e.stopImmediatePropagation();return false}});this.started=false},_mouseDestroy:function(){this.element.unbind("."+this.widgetName)},_mouseDown:function(f){if(a){return}(this._mouseStarted&&this._mouseUp(f));this._mouseDownEvent=f;var e=this,g=(f.which==1),d=(typeof this.options.cancel=="string"&&f.target.nodeName?b(f.target).closest(this.options.cancel).length:false);if(!g||d||!this._mouseCapture(f)){return true}this.mouseDelayMet=!this.options.delay;if(!this.mouseDelayMet){this._mouseDelayTimer=setTimeout(function(){e.mouseDelayMet=true},this.options.delay)}if(this._mouseDistanceMet(f)&&this._mouseDelayMet(f)){this._mouseStarted=(this._mouseStart(f)!==false);if(!this._mouseStarted){f.preventDefault();return true}}if(true===b.data(f.target,this.widgetName+".preventClickEvent")){b.removeData(f.target,this.widgetName+".preventClickEvent")}this._mouseMoveDelegate=function(h){return e._mouseMove(h)};this._mouseUpDelegate=function(h){return e._mouseUp(h)};b(document).bind("mousemove."+this.widgetName,this._mouseMoveDelegate).bind("mouseup."+this.widgetName,this._mouseUpDelegate);f.preventDefault();a=true;return true},_mouseMove:function(d){if(b.browser.msie&&!(document.documentMode>=9)&&!d.button){return this._mouseUp(d)}if(this._mouseStarted){this._mouseDrag(d);return d.preventDefault()}if(this._mouseDistanceMet(d)&&this._mouseDelayMet(d)){this._mouseStarted=(this._mouseStart(this._mouseDownEvent,d)!==false);(this._mouseStarted?this._mouseDrag(d):this._mouseUp(d))}return !this._mouseStarted},_mouseUp:function(d){b(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate);if(this._mouseStarted){this._mouseStarted=false;if(d.target==this._mouseDownEvent.target){b.data(d.target,this.widgetName+".preventClickEvent",true)}this._mouseStop(d)}return false},_mouseDistanceMet:function(d){return(Math.max(Math.abs(this._mouseDownEvent.pageX-d.pageX),Math.abs(this._mouseDownEvent.pageY-d.pageY))>=this.options.distance)},_mouseDelayMet:function(d){return this.mouseDelayMet},_mouseStart:function(d){},_mouseDrag:function(d){},_mouseStop:function(d){},_mouseCapture:function(d){return true}})})(jQuery);(function(c,d){c.widget("ui.resizable",c.ui.mouse,{widgetEventPrefix:"resize",options:{alsoResize:false,animate:false,animateDuration:"slow",animateEasing:"swing",aspectRatio:false,autoHide:false,containment:false,ghost:false,grid:false,handles:"e,s,se",helper:false,maxHeight:null,maxWidth:null,minHeight:10,minWidth:10,zIndex:1000},_create:function(){var f=this,k=this.options;this.element.addClass("ui-resizable");c.extend(this,{_aspectRatio:!!(k.aspectRatio),aspectRatio:k.aspectRatio,originalElement:this.element,_proportionallyResizeElements:[],_helper:k.helper||k.ghost||k.animate?k.helper||"ui-resizable-helper":null});if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)){this.element.wrap(c('
').css({position:this.element.css("position"),width:this.element.outerWidth(),height:this.element.outerHeight(),top:this.element.css("top"),left:this.element.css("left")}));this.element=this.element.parent().data("resizable",this.element.data("resizable"));this.elementIsWrapper=true;this.element.css({marginLeft:this.originalElement.css("marginLeft"),marginTop:this.originalElement.css("marginTop"),marginRight:this.originalElement.css("marginRight"),marginBottom:this.originalElement.css("marginBottom")});this.originalElement.css({marginLeft:0,marginTop:0,marginRight:0,marginBottom:0});this.originalResizeStyle=this.originalElement.css("resize");this.originalElement.css("resize","none");this._proportionallyResizeElements.push(this.originalElement.css({position:"static",zoom:1,display:"block"}));this.originalElement.css({margin:this.originalElement.css("margin")});this._proportionallyResize()}this.handles=k.handles||(!c(".ui-resizable-handle",this.element).length?"e,s,se":{n:".ui-resizable-n",e:".ui-resizable-e",s:".ui-resizable-s",w:".ui-resizable-w",se:".ui-resizable-se",sw:".ui-resizable-sw",ne:".ui-resizable-ne",nw:".ui-resizable-nw"});if(this.handles.constructor==String){if(this.handles=="all"){this.handles="n,e,s,w,se,sw,ne,nw"}var l=this.handles.split(",");this.handles={};for(var g=0;g
');if(/sw|se|ne|nw/.test(j)){h.css({zIndex:++k.zIndex})}if("se"==j){h.addClass("ui-icon ui-icon-gripsmall-diagonal-se")}this.handles[j]=".ui-resizable-"+j;this.element.append(h)}}this._renderAxis=function(q){q=q||this.element;for(var n in this.handles){if(this.handles[n].constructor==String){this.handles[n]=c(this.handles[n],this.element).show()}if(this.elementIsWrapper&&this.originalElement[0].nodeName.match(/textarea|input|select|button/i)){var o=c(this.handles[n],this.element),p=0;p=/sw|ne|nw|se|n|s/.test(n)?o.outerHeight():o.outerWidth();var m=["padding",/ne|nw|n/.test(n)?"Top":/se|sw|s/.test(n)?"Bottom":/^e$/.test(n)?"Right":"Left"].join("");q.css(m,p);this._proportionallyResize()}if(!c(this.handles[n]).length){continue}}};this._renderAxis(this.element);this._handles=c(".ui-resizable-handle",this.element).disableSelection();this._handles.mouseover(function(){if(!f.resizing){if(this.className){var i=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i)}f.axis=i&&i[1]?i[1]:"se"}});if(k.autoHide){this._handles.hide();c(this.element).addClass("ui-resizable-autohide").hover(function(){if(k.disabled){return}c(this).removeClass("ui-resizable-autohide");f._handles.show()},function(){if(k.disabled){return}if(!f.resizing){c(this).addClass("ui-resizable-autohide");f._handles.hide()}})}this._mouseInit()},destroy:function(){this._mouseDestroy();var e=function(g){c(g).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing").removeData("resizable").unbind(".resizable").find(".ui-resizable-handle").remove()};if(this.elementIsWrapper){e(this.element);var f=this.element;f.after(this.originalElement.css({position:f.css("position"),width:f.outerWidth(),height:f.outerHeight(),top:f.css("top"),left:f.css("left")})).remove()}this.originalElement.css("resize",this.originalResizeStyle);e(this.originalElement);return this},_mouseCapture:function(f){var g=false;for(var e in this.handles){if(c(this.handles[e])[0]==f.target){g=true}}return !this.options.disabled&&g},_mouseStart:function(g){var j=this.options,f=this.element.position(),e=this.element;this.resizing=true;this.documentScroll={top:c(document).scrollTop(),left:c(document).scrollLeft()};if(e.is(".ui-draggable")||(/absolute/).test(e.css("position"))){e.css({position:"absolute",top:f.top,left:f.left})}this._renderProxy();var k=b(this.helper.css("left")),h=b(this.helper.css("top"));if(j.containment){k+=c(j.containment).scrollLeft()||0;h+=c(j.containment).scrollTop()||0}this.offset=this.helper.offset();this.position={left:k,top:h};this.size=this._helper?{width:e.outerWidth(),height:e.outerHeight()}:{width:e.width(),height:e.height()};this.originalSize=this._helper?{width:e.outerWidth(),height:e.outerHeight()}:{width:e.width(),height:e.height()};this.originalPosition={left:k,top:h};this.sizeDiff={width:e.outerWidth()-e.width(),height:e.outerHeight()-e.height()};this.originalMousePosition={left:g.pageX,top:g.pageY};this.aspectRatio=(typeof j.aspectRatio=="number")?j.aspectRatio:((this.originalSize.width/this.originalSize.height)||1);var i=c(".ui-resizable-"+this.axis).css("cursor");c("body").css("cursor",i=="auto"?this.axis+"-resize":i);e.addClass("ui-resizable-resizing");this._propagate("start",g);return true},_mouseDrag:function(e){var h=this.helper,g=this.options,m={},q=this,j=this.originalMousePosition,n=this.axis;var r=(e.pageX-j.left)||0,p=(e.pageY-j.top)||0;var i=this._change[n];if(!i){return false}var l=i.apply(this,[e,r,p]),k=c.browser.msie&&c.browser.version<7,f=this.sizeDiff;this._updateVirtualBoundaries(e.shiftKey);if(this._aspectRatio||e.shiftKey){l=this._updateRatio(l,e)}l=this._respectSize(l,e);this._propagate("resize",e);h.css({top:this.position.top+"px",left:this.position.left+"px",width:this.size.width+"px",height:this.size.height+"px"});if(!this._helper&&this._proportionallyResizeElements.length){this._proportionallyResize()}this._updateCache(l);this._trigger("resize",e,this.ui());return false},_mouseStop:function(h){this.resizing=false;var i=this.options,m=this;if(this._helper){var g=this._proportionallyResizeElements,e=g.length&&(/textarea/i).test(g[0].nodeName),f=e&&c.ui.hasScroll(g[0],"left")?0:m.sizeDiff.height,k=e?0:m.sizeDiff.width;var n={width:(m.helper.width()-k),height:(m.helper.height()-f)},j=(parseInt(m.element.css("left"),10)+(m.position.left-m.originalPosition.left))||null,l=(parseInt(m.element.css("top"),10)+(m.position.top-m.originalPosition.top))||null;if(!i.animate){this.element.css(c.extend(n,{top:l,left:j}))}m.helper.height(m.size.height);m.helper.width(m.size.width);if(this._helper&&!i.animate){this._proportionallyResize()}}c("body").css("cursor","auto");this.element.removeClass("ui-resizable-resizing");this._propagate("stop",h);if(this._helper){this.helper.remove()}return false},_updateVirtualBoundaries:function(g){var j=this.options,i,h,f,k,e;e={minWidth:a(j.minWidth)?j.minWidth:0,maxWidth:a(j.maxWidth)?j.maxWidth:Infinity,minHeight:a(j.minHeight)?j.minHeight:0,maxHeight:a(j.maxHeight)?j.maxHeight:Infinity};if(this._aspectRatio||g){i=e.minHeight*this.aspectRatio;f=e.minWidth/this.aspectRatio;h=e.maxHeight*this.aspectRatio;k=e.maxWidth/this.aspectRatio;if(i>e.minWidth){e.minWidth=i}if(f>e.minHeight){e.minHeight=f}if(hl.width),s=a(l.height)&&i.minHeight&&(i.minHeight>l.height);if(h){l.width=i.minWidth}if(s){l.height=i.minHeight}if(t){l.width=i.maxWidth}if(m){l.height=i.maxHeight}var f=this.originalPosition.left+this.originalSize.width,p=this.position.top+this.size.height;var k=/sw|nw|w/.test(q),e=/nw|ne|n/.test(q);if(h&&k){l.left=f-i.minWidth}if(t&&k){l.left=f-i.maxWidth}if(s&&e){l.top=p-i.minHeight}if(m&&e){l.top=p-i.maxHeight}var n=!l.width&&!l.height;if(n&&!l.left&&l.top){l.top=null}else{if(n&&!l.top&&l.left){l.left=null}}return l},_proportionallyResize:function(){var k=this.options;if(!this._proportionallyResizeElements.length){return}var g=this.helper||this.element;for(var f=0;f');var e=c.browser.msie&&c.browser.version<7,g=(e?1:0),h=(e?2:-1);this.helper.addClass(this._helper).css({width:this.element.outerWidth()+h,height:this.element.outerHeight()+h,position:"absolute",left:this.elementOffset.left-g+"px",top:this.elementOffset.top-g+"px",zIndex:++i.zIndex});this.helper.appendTo("body").disableSelection()}else{this.helper=this.element}},_change:{e:function(g,f,e){return{width:this.originalSize.width+f}},w:function(h,f,e){var j=this.options,g=this.originalSize,i=this.originalPosition;return{left:i.left+f,width:g.width-f}},n:function(h,f,e){var j=this.options,g=this.originalSize,i=this.originalPosition;return{top:i.top+e,height:g.height-e}},s:function(g,f,e){return{height:this.originalSize.height+e}},se:function(g,f,e){return c.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,[g,f,e]))},sw:function(g,f,e){return c.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[g,f,e]))},ne:function(g,f,e){return c.extend(this._change.n.apply(this,arguments),this._change.e.apply(this,[g,f,e]))},nw:function(g,f,e){return c.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[g,f,e]))}},_propagate:function(f,e){c.ui.plugin.call(this,f,[e,this.ui()]);(f!="resize"&&this._trigger(f,e,this.ui()))},plugins:{},ui:function(){return{originalElement:this.originalElement,element:this.element,helper:this.helper,position:this.position,size:this.size,originalSize:this.originalSize,originalPosition:this.originalPosition}}});c.extend(c.ui.resizable,{version:"1.8.18"});c.ui.plugin.add("resizable","alsoResize",{start:function(f,g){var e=c(this).data("resizable"),i=e.options;var h=function(j){c(j).each(function(){var k=c(this);k.data("resizable-alsoresize",{width:parseInt(k.width(),10),height:parseInt(k.height(),10),left:parseInt(k.css("left"),10),top:parseInt(k.css("top"),10)})})};if(typeof(i.alsoResize)=="object"&&!i.alsoResize.parentNode){if(i.alsoResize.length){i.alsoResize=i.alsoResize[0];h(i.alsoResize)}else{c.each(i.alsoResize,function(j){h(j)})}}else{h(i.alsoResize)}},resize:function(g,i){var f=c(this).data("resizable"),j=f.options,h=f.originalSize,l=f.originalPosition;var k={height:(f.size.height-h.height)||0,width:(f.size.width-h.width)||0,top:(f.position.top-l.top)||0,left:(f.position.left-l.left)||0},e=function(m,n){c(m).each(function(){var q=c(this),r=c(this).data("resizable-alsoresize"),p={},o=n&&n.length?n:q.parents(i.originalElement[0]).length?["width","height"]:["width","height","top","left"];c.each(o,function(s,u){var t=(r[u]||0)+(k[u]||0);if(t&&t>=0){p[u]=t||null}});q.css(p)})};if(typeof(j.alsoResize)=="object"&&!j.alsoResize.nodeType){c.each(j.alsoResize,function(m,n){e(m,n)})}else{e(j.alsoResize)}},stop:function(e,f){c(this).removeData("resizable-alsoresize")}});c.ui.plugin.add("resizable","animate",{stop:function(i,n){var p=c(this).data("resizable"),j=p.options;var h=p._proportionallyResizeElements,e=h.length&&(/textarea/i).test(h[0].nodeName),f=e&&c.ui.hasScroll(h[0],"left")?0:p.sizeDiff.height,l=e?0:p.sizeDiff.width;var g={width:(p.size.width-l),height:(p.size.height-f)},k=(parseInt(p.element.css("left"),10)+(p.position.left-p.originalPosition.left))||null,m=(parseInt(p.element.css("top"),10)+(p.position.top-p.originalPosition.top))||null;p.element.animate(c.extend(g,m&&k?{top:m,left:k}:{}),{duration:j.animateDuration,easing:j.animateEasing,step:function(){var o={width:parseInt(p.element.css("width"),10),height:parseInt(p.element.css("height"),10),top:parseInt(p.element.css("top"),10),left:parseInt(p.element.css("left"),10)};if(h&&h.length){c(h[0]).css({width:o.width,height:o.height})}p._updateCache(o);p._propagate("resize",i)}})}});c.ui.plugin.add("resizable","containment",{start:function(f,r){var t=c(this).data("resizable"),j=t.options,l=t.element;var g=j.containment,k=(g instanceof c)?g.get(0):(/parent/.test(g))?l.parent().get(0):g;if(!k){return}t.containerElement=c(k);if(/document/.test(g)||g==document){t.containerOffset={left:0,top:0};t.containerPosition={left:0,top:0};t.parentData={element:c(document),left:0,top:0,width:c(document).width(),height:c(document).height()||document.body.parentNode.scrollHeight}}else{var n=c(k),i=[];c(["Top","Right","Left","Bottom"]).each(function(p,o){i[p]=b(n.css("padding"+o))});t.containerOffset=n.offset();t.containerPosition=n.position();t.containerSize={height:(n.innerHeight()-i[3]),width:(n.innerWidth()-i[1])};var q=t.containerOffset,e=t.containerSize.height,m=t.containerSize.width,h=(c.ui.hasScroll(k,"left")?k.scrollWidth:m),s=(c.ui.hasScroll(k)?k.scrollHeight:e);t.parentData={element:k,left:q.left,top:q.top,width:h,height:s}}},resize:function(g,q){var t=c(this).data("resizable"),i=t.options,f=t.containerSize,p=t.containerOffset,m=t.size,n=t.position,r=t._aspectRatio||g.shiftKey,e={top:0,left:0},h=t.containerElement;if(h[0]!=document&&(/static/).test(h.css("position"))){e=p}if(n.left<(t._helper?p.left:0)){t.size.width=t.size.width+(t._helper?(t.position.left-p.left):(t.position.left-e.left));if(r){t.size.height=t.size.width/i.aspectRatio}t.position.left=i.helper?p.left:0}if(n.top<(t._helper?p.top:0)){t.size.height=t.size.height+(t._helper?(t.position.top-p.top):t.position.top);if(r){t.size.width=t.size.height*i.aspectRatio}t.position.top=t._helper?p.top:0}t.offset.left=t.parentData.left+t.position.left;t.offset.top=t.parentData.top+t.position.top;var l=Math.abs((t._helper?t.offset.left-e.left:(t.offset.left-e.left))+t.sizeDiff.width),s=Math.abs((t._helper?t.offset.top-e.top:(t.offset.top-p.top))+t.sizeDiff.height);var k=t.containerElement.get(0)==t.element.parent().get(0),j=/relative|absolute/.test(t.containerElement.css("position"));if(k&&j){l-=t.parentData.left}if(l+t.size.width>=t.parentData.width){t.size.width=t.parentData.width-l;if(r){t.size.height=t.size.width/t.aspectRatio}}if(s+t.size.height>=t.parentData.height){t.size.height=t.parentData.height-s;if(r){t.size.width=t.size.height*t.aspectRatio}}},stop:function(f,n){var q=c(this).data("resizable"),g=q.options,l=q.position,m=q.containerOffset,e=q.containerPosition,i=q.containerElement;var j=c(q.helper),r=j.offset(),p=j.outerWidth()-q.sizeDiff.width,k=j.outerHeight()-q.sizeDiff.height;if(q._helper&&!g.animate&&(/relative/).test(i.css("position"))){c(this).css({left:r.left-e.left-m.left,width:p,height:k})}if(q._helper&&!g.animate&&(/static/).test(i.css("position"))){c(this).css({left:r.left-e.left-m.left,width:p,height:k})}}});c.ui.plugin.add("resizable","ghost",{start:function(g,h){var e=c(this).data("resizable"),i=e.options,f=e.size;e.ghost=e.originalElement.clone();e.ghost.css({opacity:0.25,display:"block",position:"relative",height:f.height,width:f.width,margin:0,left:0,top:0}).addClass("ui-resizable-ghost").addClass(typeof i.ghost=="string"?i.ghost:"");e.ghost.appendTo(e.helper)},resize:function(f,g){var e=c(this).data("resizable"),h=e.options;if(e.ghost){e.ghost.css({position:"relative",height:e.size.height,width:e.size.width})}},stop:function(f,g){var e=c(this).data("resizable"),h=e.options;if(e.ghost&&e.helper){e.helper.get(0).removeChild(e.ghost.get(0))}}});c.ui.plugin.add("resizable","grid",{resize:function(e,m){var p=c(this).data("resizable"),h=p.options,k=p.size,i=p.originalSize,j=p.originalPosition,n=p.axis,l=h._aspectRatio||e.shiftKey;h.grid=typeof h.grid=="number"?[h.grid,h.grid]:h.grid;var g=Math.round((k.width-i.width)/(h.grid[0]||1))*(h.grid[0]||1),f=Math.round((k.height-i.height)/(h.grid[1]||1))*(h.grid[1]||1);if(/^(se|s|e)$/.test(n)){p.size.width=i.width+g;p.size.height=i.height+f}else{if(/^(ne)$/.test(n)){p.size.width=i.width+g;p.size.height=i.height+f;p.position.top=j.top-f}else{if(/^(sw)$/.test(n)){p.size.width=i.width+g;p.size.height=i.height+f;p.position.left=j.left-g}else{p.size.width=i.width+g;p.size.height=i.height+f;p.position.top=j.top-f;p.position.left=j.left-g}}}}});var b=function(e){return parseInt(e,10)||0};var a=function(e){return !isNaN(parseInt(e,10))}})(jQuery);/*! + * jQuery hashchange event - v1.3 - 7/21/2010 + * http://benalman.com/projects/jquery-hashchange-plugin/ + * + * Copyright (c) 2010 "Cowboy" Ben Alman + * Dual licensed under the MIT and GPL licenses. + * http://benalman.com/about/license/ + */ +(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('