Browse Source

Linux 1.7 Open Source Gold release
Signed-off-by: Li, Xun <xun.li@email.com>

llly 7 years ago
parent
commit
6662022bf8
100 changed files with 15424 additions and 15271 deletions
  1. 1 1
      Linux_SGXEclipsePlugin/build.sh
  2. 0 22
      Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/PageLayouts/Default.flpgl
  3. 6 5
      Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/content.html
  4. 12 11
      Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/toc.xml
  5. 3 3
      Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c++/sgx_t_static.mk
  6. 3 3
      Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c/sgx_t_static.mk
  7. 5 3
      Makefile
  8. 34 7
      README.md
  9. 6 6
      SampleCode/LocalAttestation/.cproject
  10. 1 1
      SampleCode/LocalAttestation/.project
  11. 9 5
      SampleCode/LocalAttestation/App/App.cpp
  12. 29 6
      SampleCode/LocalAttestation/Makefile
  13. 7 7
      SampleCode/LocalAttestation/README.txt
  14. 6 6
      SampleCode/PowerTransition/.cproject
  15. 1 1
      SampleCode/PowerTransition/.project
  16. 1 1
      SampleCode/PowerTransition/Enclave/Enclave.cpp
  17. 26 7
      SampleCode/PowerTransition/Makefile
  18. 7 7
      SampleCode/PowerTransition/README.txt
  19. 6 6
      SampleCode/RemoteAttestation/.cproject
  20. 1 1
      SampleCode/RemoteAttestation/.project
  21. 26 4
      SampleCode/RemoteAttestation/Makefile
  22. 7 7
      SampleCode/RemoteAttestation/README.txt
  23. 6 6
      SampleCode/SampleEnclave/.cproject
  24. 1 1
      SampleCode/SampleEnclave/.project
  25. 1 1
      SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Pointers.cpp
  26. 26 4
      SampleCode/SampleEnclave/Makefile
  27. 7 6
      SampleCode/SampleEnclave/README.txt
  28. 27 0
      buildenv.mk
  29. 1 1
      common/inc/internal/se_quote_internal.h
  30. 1 1
      common/inc/internal/se_version.h
  31. 0 0
      common/inc/internal/sgx_sha256_128.h
  32. 2 2
      common/inc/sgx_attributes.h
  33. 10 10
      common/inc/sgx_key.h
  34. 32 6
      download_prebuilt.sh
  35. 1 1
      external/crypto_px/Makefile
  36. 195 195
      external/crypto_px/include/ippbase.h
  37. 395 395
      external/crypto_px/include/ippcore.h
  38. 327 327
      external/crypto_px/include/ippcp.h
  39. 211 211
      external/crypto_px/include/ippcpdefs.h
  40. 129 129
      external/crypto_px/include/ippdefs.h
  41. 1104 1104
      external/crypto_px/include/ipptypes.h
  42. 41 41
      external/crypto_px/include/ippversion.h
  43. 264 264
      external/crypto_px/sources/include/cpudef.h
  44. 46 46
      external/crypto_px/sources/include/ippver.h
  45. 944 944
      external/crypto_px/sources/include/owndefs.h
  46. 149 149
      external/crypto_px/sources/ippcp/src/owncp.h
  47. 396 396
      external/crypto_px/sources/ippcp/src/pcpaesauthcmacca.c
  48. 141 141
      external/crypto_px/sources/ippcp/src/pcpaesauthgcm.h
  49. 731 731
      external/crypto_px/sources/ippcp/src/pcpaesauthgcmca.c
  50. 52 52
      external/crypto_px/sources/ippcp/src/pcpaesgcmtableca.c
  51. 229 229
      external/crypto_px/sources/ippcp/src/pcpaesgcmtbl2kca.c
  52. 50 50
      external/crypto_px/sources/ippcp/src/pcpaesm.h
  53. 150 150
      external/crypto_px/sources/ippcp/src/pcpaesmctrca.c
  54. 173 173
      external/crypto_px/sources/ippcp/src/pcpaesminitca.c
  55. 210 210
      external/crypto_px/sources/ippcp/src/pcpbn.h
  56. 1058 1058
      external/crypto_px/sources/ippcp/src/pcpbnca.c
  57. 51 51
      external/crypto_px/sources/ippcp/src/pcpbnresource.h
  58. 93 93
      external/crypto_px/sources/ippcp/src/pcpbnresourceca.c
  59. 119 119
      external/crypto_px/sources/ippcp/src/pcpbnsetca.c
  60. 234 234
      external/crypto_px/sources/ippcp/src/pcpbnu32arith.c
  61. 46 46
      external/crypto_px/sources/ippcp/src/pcpbnu32arith.h
  62. 53 53
      external/crypto_px/sources/ippcp/src/pcpbnu32misc.c
  63. 49 49
      external/crypto_px/sources/ippcp/src/pcpbnu32misc.h
  64. 301 301
      external/crypto_px/sources/ippcp/src/pcpbnuarith.c
  65. 114 114
      external/crypto_px/sources/ippcp/src/pcpbnuarith.h
  66. 141 141
      external/crypto_px/sources/ippcp/src/pcpbnuimpl.h
  67. 208 208
      external/crypto_px/sources/ippcp/src/pcpbnumisc.c
  68. 149 149
      external/crypto_px/sources/ippcp/src/pcpbnumisc.h
  69. 70 70
      external/crypto_px/sources/ippcp/src/pcpcmac.h
  70. 230 230
      external/crypto_px/sources/ippcp/src/pcpeccp.h
  71. 370 370
      external/crypto_px/sources/ippcp/src/pcpeccpdpca.c
  72. 107 107
      external/crypto_px/sources/ippcp/src/pcpeccpgenkeyca.c
  73. 305 305
      external/crypto_px/sources/ippcp/src/pcpeccpinitca.c
  74. 93 93
      external/crypto_px/sources/ippcp/src/pcpeccpmethod.h
  75. 133 133
      external/crypto_px/sources/ippcp/src/pcpeccpmethodcom.h
  76. 731 731
      external/crypto_px/sources/ippcp/src/pcpeccpmethodcomca.c
  77. 60 60
      external/crypto_px/sources/ippcp/src/pcpeccppoint.h
  78. 128 128
      external/crypto_px/sources/ippcp/src/pcpeccppointca.c
  79. 476 476
      external/crypto_px/sources/ippcp/src/pcpeccppointopca.c
  80. 89 89
      external/crypto_px/sources/ippcp/src/pcpeccppublickeyca.c
  81. 116 116
      external/crypto_px/sources/ippcp/src/pcpeccpsecretdhca.c
  82. 105 105
      external/crypto_px/sources/ippcp/src/pcpeccpsetkeyca.c
  83. 149 149
      external/crypto_px/sources/ippcp/src/pcpeccpsigndsaca.c
  84. 161 161
      external/crypto_px/sources/ippcp/src/pcpeccpsscm.c
  85. 49 49
      external/crypto_px/sources/ippcp/src/pcpeccpsscm.h
  86. 324 324
      external/crypto_px/sources/ippcp/src/pcpeccpstdca.c
  87. 145 145
      external/crypto_px/sources/ippcp/src/pcpeccpverifydsaca.c
  88. 159 159
      external/crypto_px/sources/ippcp/src/pcphash.h
  89. 513 513
      external/crypto_px/sources/ippcp/src/pcphashca.c
  90. 216 216
      external/crypto_px/sources/ippcp/src/pcphashcnt.c
  91. 197 197
      external/crypto_px/sources/ippcp/src/pcphashmd5px.c
  92. 174 174
      external/crypto_px/sources/ippcp/src/pcphashsha1px.c
  93. 199 199
      external/crypto_px/sources/ippcp/src/pcphashsha256px.c
  94. 207 207
      external/crypto_px/sources/ippcp/src/pcphashsha512px.c
  95. 55 55
      external/crypto_px/sources/ippcp/src/pcphmac.h
  96. 332 332
      external/crypto_px/sources/ippcp/src/pcphmacca.c
  97. 116 116
      external/crypto_px/sources/ippcp/src/pcpmontexpbinca.c
  98. 190 190
      external/crypto_px/sources/ippcp/src/pcpmontgomery.h
  99. 296 296
      external/crypto_px/sources/ippcp/src/pcpmontgomeryca.c
  100. 64 64
      external/crypto_px/sources/ippcp/src/pcpmontred.c

+ 1 - 1
Linux_SGXEclipsePlugin/build.sh

@@ -11,7 +11,7 @@ TRUNK_HOME=$(cd $(pwd)/../../ ; pwd)
 [ -n "${ECLIPSE_HOME}" ] || { echo "using default ECLIPSE_HOME=${TRUNK_HOME}/eclipse"; ECLIPSE_HOME=${TRUNK_HOME}/eclipse; }
 
 
-BUILD_RELEASE_ID_PREFIX=Linux_SGX_1.6
+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."

+ 0 - 22
Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/Resources/PageLayouts/Default.flpgl

@@ -1,22 +0,0 @@
-<!--------------------------------------------------------------------------->
-<!-- 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	   -->
-<!--------------------------------------------------------------------------->
-<?xml version="1.0" encoding="utf-8"?>
-<PageStyles>
-    <Page Name="Normal" Width="800" Height="800" Padding="1in" PageSize="Letter" PaddingLeft="1.50cm" PaddingRight="1cm" PaddingTop="1in" PaddingBottom="1in">
-        <Frame Flow="header" Height="0.5in" Right="0" X="0" Y="-0.75in" ColumnCount="1" Width="6.5in">
-        </Frame>
-        <Frame Flow="footer" Height="0.5in" Right="0" Bottom="0" X="0" Y="9.25in" Width="6.5in">
-        </Frame>
-        <Frame Flow="body" ColumnCount="1" ColumnGap="0.25in" ColumnDivider="Solid 1pt Black" Width="6.5in" Height="9in">
-        </Frame>
-    </Page>
-</PageStyles>

+ 6 - 5
Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/html/content.html

@@ -9,8 +9,9 @@
 
  Contributors:
      Intel Corporation - initial implementation and documentation
- -->
 
+
+ -->
 <html xmlns:MadCap='http://www.madcapsoftware.com/Schemas/MadCap.xsd' MadCap:lastBlockDepth='4' MadCap:lastHeight='1043' MadCap:lastWidth='652'>
   <head>
     <link href='Resources/Stylesheets/intel_css_styles.css' rel='stylesheet' type='text/css' />
@@ -24,7 +25,7 @@ modification. Intel(R) SGX makes such protections possible through the use of
 enclaves. Enclaves are protected areas of execution. Application code can be put 
 into an enclave through special instructions and software made available to 
 developers by the Intel(R) SGX SDK.</p>
-        <p><a href="Legal_Information.htm">Legal Information</a>
+        <p><a href="#Legal_Information">Legal Information</a>
         </p>
     </div>
     <div id='Legal_Information'>
@@ -104,11 +105,11 @@ developers by the Intel(R) SGX SDK.</p>
         </ul>
         <p>The proxy and bridge functions are generated by the <code>sgx_edger8r</code> tool provided by Intel(R) SGX SDK. It reads an <i>edl</i> file (Enclave Descriptor Language) which describes the functions that form the <i>trusted</i> and <i>untrusted</i> component boundaries within the application.</p>
         <p>After the enclave is built, a signed version of it is created using the tool <code>sgx_sign</code> also provided by Intel(R) SGX SDK.  It is this signed version may be loaded and executed in the encrypted memory.</p>
-        <p>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, whose details may be seen in <i>Intel(R) Software Guard Extensions SDK for Linux* OS</i>.</p>
+        <p>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 <i>Intel(R) Software Guard Extensions SDK for Linux* OS Developer Reference</i>.</p>
     </div>
     <div id='Introducing_Intel_Software_Guard_Extensions'>
         <h2>Introducing Intel(R) Software Guard Extensions Eclipse* Plug-in</h2>
-        <p>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 <a href="Adding_SGX_Nature_to_a_Project.htm">Adding SGX Nature to a Project</a> for details.</p>
+        <p>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 <a href="#Adding_SGX_Nature_to_a_Project">Adding SGX Nature to a Project</a> for details.</p>
         <p>Once the SGX nature is added to a project, you will have access to the SGX commands.  SGX nature adds also a folder called <code>sgx</code> 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.</p>
         <p>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 <code>sgx_edger8r</code> tool to generate the proxies and bridges, compile these source, generate a shared object and finally, to sign the enclave with the <code>sgx_sign</code> tool.  This provide a starting point you may build upon.</p>
     </div>
@@ -181,7 +182,7 @@ developers by the Intel(R) SGX SDK.</p>
     <div id='Adding_SGX_Nature_to_a_Project'>
         <h2>Adding SGX Nature to a Project</h2>
         <p>The <i>nature</i> 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 <i>SGX nature</i> 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.</p>
-        <p>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 <a href="Adding_SGX_Nature_to_a_non_SGX_project.htm">Adding SGX Nature to a non-SGX project</a> and <a href="Creating_a_New_C_C_Project_with_SGX_Nature.htm">Creating a New C/C++ Project with SGX Nature</a> for how to complete these tasks.</p>
+        <p>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 <a href="#Adding_SGX_Nature_to_a_non_SGX_project">Adding SGX Nature to a non-SGX project</a> and <a href="#Creating_a_New_C_C_Project_with_SGX_Nature">Creating a New C/C++ Project with SGX Nature</a> for how to complete these tasks.</p>
     </div>
     <div id='Adding_SGX_Nature_to_a_non_SGX_project'>
         <h3>Adding SGX Nature to a non-SGX project</h3>

+ 12 - 11
Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx.userguide/toc.xml

@@ -1,16 +1,17 @@
 <?xml version='1.0' encoding='utf-8'?>
 <!-- 
- 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	   
- -->
+ 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
 
+
+ -->
 <toc href='html/content.html#SGX_title' label='Intel(R) SGX Plugin Developer Guide'>
   <topic label='Legal Information' href='html/content.html#Legal_Information' />
   <topic label='Introduction' href='html/content.html#Introduction'>
@@ -41,4 +42,4 @@
     <topic label='SGX Build Configurations' href='html/content.html#SGX_Build_Configurations' />
     <topic label='Running Samples Generated for Enclaves' href='html/content.html#Running_Samples_Generated_for_Enclaves' />
   </topic>
-</toc>
+</toc>

+ 3 - 3
Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c++/sgx_t_static.mk

@@ -77,7 +77,7 @@ endif
 
 .PHONY: all run
 
-all: $(enclaveName).sgx.static.lib.a
+all: lib$(enclaveName).sgx.static.lib.a
 
 ######## $(enclaveName) Objects ########
 
@@ -97,8 +97,8 @@ static_trusted/%.o: static_trusted/%.c
 	@$(CC) $($(EnclaveName)_C_Flags) -c $< -o $@
 	@echo "CC  <=  $<"
 
-$(enclaveName).sgx.static.lib.a: static_trusted/$(enclaveName)_t.h $($(EnclaveName)_Cpp_Objects) $($(EnclaveName)_C_Objects)
-	ar rcs $(enclaveName).sgx.static.lib.a $($(EnclaveName)_Cpp_Objects) $($(EnclaveName)_C_Objects)  
+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:

+ 3 - 3
Linux_SGXEclipsePlugin/build_directory/plugins/com.intel.sgx/templates/sgx/SGXTrustedStaticLibrary/makefiles/c/sgx_t_static.mk

@@ -71,7 +71,7 @@ endif
 
 .PHONY: all run
 
-all: $(enclaveName).sgx.static.lib.a
+all: lib$(enclaveName).sgx.static.lib.a
 
 ######## $(enclaveName) Objects ########
 
@@ -87,8 +87,8 @@ static_trusted/%.o: static_trusted/%.c
 	@$(CC) $($(EnclaveName)_C_Flags) -c $< -o $@
 	@echo "CC  <=  $<"
 
-$(enclaveName).sgx.static.lib.a: static_trusted/$(enclaveName)_t.h $($(EnclaveName)_C_Objects)
-	ar rcs $(enclaveName).sgx.static.lib.a $($(EnclaveName)_Cpp_Objects) $($(EnclaveName)_C_Objects)  
+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:

+ 5 - 3
Makefile

@@ -35,10 +35,10 @@ include buildenv.mk
 all: sdk psw
 
 psw: sdk
-	$(MAKE) -C psw/
+	$(MAKE) -C psw/ USE_OPT_LIBS=$(USE_OPT_LIBS)
 
 sdk:
-	$(MAKE) -C sdk/
+	$(MAKE) -C sdk/ USE_OPT_LIBS=$(USE_OPT_LIBS)
 
 # Generate SE SDK Install package
 sdk_install_pkg: sdk
@@ -53,4 +53,6 @@ clean:
 	@$(RM)   -r $(ROOT_DIR)/build
 	@$(RM)   -r linux/installer/bin/sgx_linux*.bin
 
-rebuild: clean all
+rebuild:
+	$(MAKE) clean
+	$(MAKE) all

+ 34 - 7
README.md

@@ -43,8 +43,8 @@ Build the Intel(R) SGX SDK and Intel(R) SGX PSW Package
 ```
   $ 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`)  
+- 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
 ```
@@ -58,6 +58,11 @@ The following steps describe how to build the Intel SGX SDK and PSW. You can bui
   $ 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
@@ -67,20 +72,34 @@ The following steps describe how to build the Intel SGX SDK and PSW. You can bui
   $ 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 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 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
@@ -92,12 +111,16 @@ Install Intel(R) SGX SDK
 ```
 
 ###Install Intel(R) SGX SDK
-To install Intel(R) SGX SDK, enter the following commands:
+To install Intel(R) SGX SDK, execute the installer with root privilege:
 ```
 $ cd linux/installer/bin
-$ ./sgx_linux_x64_sdk_${version}.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
@@ -110,6 +133,10 @@ $ ./sgx_linux_x64_sdk_${version}.bin
 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

+ 6 - 6
SampleCode/LocalAttestation/.cproject

@@ -168,24 +168,24 @@
 		</cconfiguration>
 	</storageModule>
 	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
-		<project id="SimpleEnclave.null.1312290154" name="SimpleEnclave"/>
+		<project id="LocalAttestation.null.1312290154" name="LocalAttestation"/>
 	</storageModule>
 	<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
 	<storageModule moduleId="refreshScope" versionNumber="2">
 		<configuration configurationName="SGX Debug HW Mode">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/LocalAttestation"/>
 		</configuration>
 		<configuration configurationName="SGX Debug Sim Mode">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/LocalAttestation"/>
 		</configuration>
 		<configuration configurationName="Debug">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/LocalAttestation"/>
 		</configuration>
 		<configuration configurationName="Release">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/LocalAttestation"/>
 		</configuration>
 		<configuration configurationName="SGX Release HW Mode">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/LocalAttestation"/>
 		</configuration>
 	</storageModule>
 	<storageModule moduleId="scannerConfiguration">

+ 1 - 1
SampleCode/LocalAttestation/.project

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-	<name>SimpleEnclave</name>
+	<name>LocalAttestation</name>
 	<comment></comment>
 	<projects>
 	</projects>

+ 9 - 5
SampleCode/LocalAttestation/App/App.cpp

@@ -38,6 +38,9 @@
 #include "../Enclave3/Enclave3_u.h"
 #include "sgx_eid.h"
 #include "sgx_urts.h"
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+
 
 #define UNUSED(val) (void)(val)
 #define TCHAR   char
@@ -59,9 +62,10 @@ sgx_enclave_id_t e3_enclave_id = 0;
 
 void waitForKeyPress()
 {
-    uint8_t    ch;
+    char ch;
+    int temp;
     printf("\n\nHit a key....\n");
-    scanf_s("%c", &ch);
+    temp = scanf_s("%c", &ch);
 }
 
 uint32_t load_enclaves()
@@ -115,9 +119,9 @@ int _tmain(int argc, _TCHAR* argv[])
     }
 
     printf("\nAvaliable Enclaves");
-    printf("\nEnclave1 - EnclaveID %llx",e1_enclave_id);
-    printf("\nEnclave2 - EnclaveID %llx",e2_enclave_id);
-    printf("\nEnclave3 - EnclaveID %llx",e3_enclave_id);
+    printf("\nEnclave1 - EnclaveID %" PRIx64, e1_enclave_id);
+    printf("\nEnclave2 - EnclaveID %" PRIx64, e2_enclave_id);
+    printf("\nEnclave3 - EnclaveID %" PRIx64, e3_enclave_id);
     
     do
     {

+ 29 - 6
SampleCode/LocalAttestation/Makefile

@@ -32,8 +32,9 @@
 ######## SGX SDK Settings ########
 
 SGX_SDK ?= /opt/intel/sgxsdk
-SGX_MODE ?= SIM
+SGX_MODE ?= HW
 SGX_ARCH ?= x64
+SGX_DEBUG ?= 1
 
 ifeq ($(shell getconf LONG_BIT), 32)
 	SGX_ARCH := x86
@@ -71,7 +72,8 @@ 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 -std=c++03 -nostdinc++ $(TrustLib_Include_Paths)
+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)
@@ -155,10 +157,20 @@ Enclave_Name_2 := libenclave2.so
 Enclave_Name_3 := libenclave3.so
 
 ifeq ($(SGX_MODE), HW)
-ifneq ($(SGX_DEBUG), 1)
-ifneq ($(SGX_PRERELEASE), 1)
-Build_Mode = HW_RELEASE
+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
 
@@ -174,6 +186,17 @@ all: $(Trust_Lib_Name) $(UnTrustLib_Name) Enclave1.so Enclave2.so Enclave3.so $(
 	@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 ########
@@ -187,7 +210,7 @@ LocalAttestationCode/LocalAttestationCode_t.o: LocalAttestationCode/LocalAttesta
 	@echo "CC   <=  $<"
 
 LocalAttestationCode/%.o: LocalAttestationCode/%.cpp LocalAttestationCode/LocalAttestationCode_t.h
-	@$(CXX) $(TrustLib_Compile_Flags) -c $< -o $@
+	@$(CXX) $(TrustLib_Compile_Flags) $(TrustLib_Compile_Cxx_Flags) -c $< -o $@
 	@echo "CC   <= $<"
 
 $(Trust_Lib_Name): LocalAttestationCode/LocalAttestationCode_t.o $(TrustLib_Cpp_Objects)

+ 7 - 7
SampleCode/LocalAttestation/README.txt

@@ -11,17 +11,17 @@ 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 SGX_MODE=HW SGX_DEBUG=1
+        $ make
     b. Hardware Mode, Pre-release build:
-        $ make SGX_MODE=HW SGX_PRERELEASE=1
+        $ make SGX_PRERELEASE=1 SGX_DEBUG=0
     c. Hardware Mode, Release build:
-        $ make SGX_MODE=HW
+        $ make SGX_DEBUG=0
     d. Simulation Mode, Debug build:
-        $ make SGX_DEBUG=1
+        $ make SGX_MODE=SIM
     e. Simulation Mode, Pre-release build:
-        $ make SGX_PRERELEASE=1
+        $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0
     f. Simulation Mode, Release build:
-        $ make
+        $ make SGX_MODE=SIM SGX_DEBUG=0
 3. Execute the binary directly:
     $ ./app
-
+4. Remember to "make clean" before switching build mode

+ 6 - 6
SampleCode/PowerTransition/.cproject

@@ -168,24 +168,24 @@
 		</cconfiguration>
 	</storageModule>
 	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
-		<project id="SimpleEnclave.null.1312290154" name="SimpleEnclave"/>
+		<project id="PowerTransition.null.1312290154" name="PowerTransition"/>
 	</storageModule>
 	<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
 	<storageModule moduleId="refreshScope" versionNumber="2">
 		<configuration configurationName="SGX Debug HW Mode">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/PowerTransition"/>
 		</configuration>
 		<configuration configurationName="SGX Debug Sim Mode">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/PowerTransition"/>
 		</configuration>
 		<configuration configurationName="Debug">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/PowerTransition"/>
 		</configuration>
 		<configuration configurationName="Release">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/PowerTransition"/>
 		</configuration>
 		<configuration configurationName="SGX Release HW Mode">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/PowerTransition"/>
 		</configuration>
 	</storageModule>
 	<storageModule moduleId="scannerConfiguration">

+ 1 - 1
SampleCode/PowerTransition/.project

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-	<name>SimpleEnclave</name>
+	<name>PowerTransition</name>
 	<comment></comment>
 	<projects>
 	</projects>

+ 1 - 1
SampleCode/PowerTransition/Enclave/Enclave.cpp

@@ -158,7 +158,7 @@ int increase_and_seal_data(size_t tid, struct sealed_buf_t* 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>: %d\n", (unsigned int)tid, temp_secret);
+    snprintf(string_buf, BUFSIZ, "Thread %#x>: %u\n", (unsigned int)tid, (unsigned int)temp_secret);
     print(string_buf);
     return 0;
 }

+ 26 - 7
SampleCode/PowerTransition/Makefile

@@ -32,8 +32,9 @@
 ####### SGX SDK Settings ########
 
 SGX_SDK ?= /opt/intel/sgxsdk
-SGX_MODE ?= SIM
+SGX_MODE ?= HW
 SGX_ARCH ?= x64
+SGX_DEBUG ?= 1
 
 ifeq ($(shell getconf LONG_BIT), 32)
 	SGX_ARCH := x86
@@ -149,10 +150,20 @@ Signed_Enclave_Name := libenclave.signed.so
 Enclave_Config_File := Enclave/Enclave.config.xml
 
 ifeq ($(SGX_MODE), HW)
-ifneq ($(SGX_DEBUG), 1)
-ifneq ($(SGX_PRERELEASE), 1)
-Build_Mode = HW_RELEASE
+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
 
@@ -166,9 +177,17 @@ all: $(App_Name) $(Enclave_Name)
 	@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)
-	@echo "Build $(App_Name) [$(SGX_MODE)|$(SGX_ARCH)] Success!"
-	@echo "Please RUN the project with command:"
-	@echo "    $(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
 
 ######## App Objects ########

+ 7 - 7
SampleCode/PowerTransition/README.txt

@@ -10,17 +10,17 @@ 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 SGX_MODE=HW SGX_DEBUG=1
+        $ make
     b. Hardware Mode, Pre-release build:
-        $ make SGX_MODE=HW SGX_PRERELEASE=1
+        $ make SGX_PRERELEASE=1 SGX_DEBUG=0
     c. Hardware Mode, Release build:
-        $ make SGX_MODE=HW
+        $ make SGX_DEBUG=0
     d. Simulation Mode, Debug build:
-        $ make SGX_DEBUG=1
+        $ make SGX_MODE=SIM
     e. Simulation Mode, Pre-release build:
-        $ make SGX_PRERELEASE=1
+        $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0
     f. Simulation Mode, Release build:
-        $ make
+        $ make SGX_MODE=SIM SGX_DEBUG=0
 3. Execute the binary directly:
     $ ./app
-
+4. Remember to "make clean" before switching build mode

+ 6 - 6
SampleCode/RemoteAttestation/.cproject

@@ -168,24 +168,24 @@
 		</cconfiguration>
 	</storageModule>
 	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
-		<project id="SimpleEnclave.null.1312290154" name="SimpleEnclave"/>
+		<project id="RemoteAttestation.null.1312290154" name="RemoteAttestation"/>
 	</storageModule>
 	<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
 	<storageModule moduleId="refreshScope" versionNumber="2">
 		<configuration configurationName="SGX Debug HW Mode">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/RemoteAttestation"/>
 		</configuration>
 		<configuration configurationName="SGX Debug Sim Mode">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/RemoteAttestation"/>
 		</configuration>
 		<configuration configurationName="Debug">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/RemoteAttestation"/>
 		</configuration>
 		<configuration configurationName="Release">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/RemoteAttestation"/>
 		</configuration>
 		<configuration configurationName="SGX Release HW Mode">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/RemoteAttestation"/>
 		</configuration>
 	</storageModule>
 	<storageModule moduleId="scannerConfiguration">

+ 1 - 1
SampleCode/RemoteAttestation/.project

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-	<name>SimpleEnclave</name>
+	<name>RemoteAttestation</name>
 	<comment></comment>
 	<projects>
 	</projects>

+ 26 - 4
SampleCode/RemoteAttestation/Makefile

@@ -32,8 +32,9 @@
 ######## SGX SDK Settings ########
 
 SGX_SDK ?= /opt/intel/sgxsdk
-SGX_MODE ?= SIM
+SGX_MODE ?= HW
 SGX_ARCH ?= x64
+SGX_DEBUG ?= 1
 
 ifeq ($(shell getconf LONG_BIT), 32)
 	SGX_ARCH := x86
@@ -156,10 +157,20 @@ Signed_Enclave_Name := isv_enclave.signed.so
 Enclave_Config_File := isv_enclave/isv_enclave.config.xml
 
 ifeq ($(SGX_MODE), HW)
-ifneq ($(SGX_DEBUG), 1)
-ifneq ($(SGX_PRERELEASE), 1)
-Build_Mode = HW_RELEASE
+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
 
@@ -176,6 +187,17 @@ all: libservice_provider.so $(App_Name) $(Enclave_Name)
 	@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

+ 7 - 7
SampleCode/RemoteAttestation/README.txt

@@ -11,17 +11,17 @@ 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 SGX_MODE=HW SGX_DEBUG=1
+        $ make
     b. Hardware Mode, Pre-release build:
-        $ make SGX_MODE=HW SGX_PRERELEASE=1
+        $ make SGX_PRERELEASE=1 SGX_DEBUG=0
     c. Hardware Mode, Release build:
-        $ make SGX_MODE=HW
+        $ make SGX_DEBUG=0
     d. Simulation Mode, Debug build:
-        $ make SGX_DEBUG=1
+        $ make SGX_MODE=SIM
     e. Simulation Mode, Pre-release build:
-        $ make SGX_PRERELEASE=1
+        $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0
     f. Simulation Mode, Release build:
-        $ make
+        $ make SGX_MODE=SIM SGX_DEBUG=0
 3. Execute the binary directly:
     $ ./app
-
+4. Remember to "make clean" before switching build mode

+ 6 - 6
SampleCode/SampleEnclave/.cproject

@@ -168,24 +168,24 @@
 		</cconfiguration>
 	</storageModule>
 	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
-		<project id="SimpleEnclave.null.1312290154" name="SimpleEnclave"/>
+		<project id="SampleEnclave.null.1312290154" name="SampleEnclave"/>
 	</storageModule>
 	<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
 	<storageModule moduleId="refreshScope" versionNumber="2">
 		<configuration configurationName="SGX Debug HW Mode">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/SampleEnclave"/>
 		</configuration>
 		<configuration configurationName="SGX Debug Sim Mode">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/SampleEnclave"/>
 		</configuration>
 		<configuration configurationName="Debug">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/SampleEnclave"/>
 		</configuration>
 		<configuration configurationName="Release">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/SampleEnclave"/>
 		</configuration>
 		<configuration configurationName="SGX Release HW Mode">
-			<resource resourceType="PROJECT" workspacePath="/SimpleEnclave"/>
+			<resource resourceType="PROJECT" workspacePath="/SampleEnclave"/>
 		</configuration>
 	</storageModule>
 	<storageModule moduleId="scannerConfiguration">

+ 1 - 1
SampleCode/SampleEnclave/.project

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-	<name>SimpleEnclave</name>
+	<name>SampleEnclave</name>
 	<comment></comment>
 	<projects>
 	</projects>

+ 1 - 1
SampleCode/SampleEnclave/Enclave/Edger8rSyntax/Pointers.cpp

@@ -78,7 +78,7 @@ size_t ecall_pointer_user_check(void *val, size_t sz)
     
     int32_t sum = checksum_internal((char *)tmp, len);
     printf("Checksum(0x%p, %zu) = 0x%x\n", 
-            val, len, sum);
+            val, len, (unsigned int)sum);
     
     /* modify outside memory directly */
     memcpy(val, "SGX_SUCCESS", len>12?12:len);

+ 26 - 4
SampleCode/SampleEnclave/Makefile

@@ -32,8 +32,9 @@
 ######## SGX SDK Settings ########
 
 SGX_SDK ?= /opt/intel/sgxsdk
-SGX_MODE ?= SIM
+SGX_MODE ?= HW
 SGX_ARCH ?= x64
+SGX_DEBUG ?= 1
 
 ifeq ($(shell getconf LONG_BIT), 32)
 	SGX_ARCH := x86
@@ -142,10 +143,20 @@ Signed_Enclave_Name := enclave.signed.so
 Enclave_Config_File := Enclave/Enclave.config.xml
 
 ifeq ($(SGX_MODE), HW)
-ifneq ($(SGX_DEBUG), 1)
-ifneq ($(SGX_PRERELEASE), 1)
-Build_Mode = HW_RELEASE
+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
 
@@ -162,6 +173,17 @@ all: $(App_Name) $(Enclave_Name)
 	@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

+ 7 - 6
SampleCode/SampleEnclave/README.txt

@@ -13,17 +13,18 @@ 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 SGX_MODE=HW SGX_DEBUG=1
+        $ make
     b. Hardware Mode, Pre-release build:
-        $ make SGX_MODE=HW SGX_PRERELEASE=1
+        $ make SGX_PRERELEASE=1 SGX_DEBUG=0
     c. Hardware Mode, Release build:
-        $ make SGX_MODE=HW
+        $ make SGX_DEBUG=0
     d. Simulation Mode, Debug build:
-        $ make SGX_DEBUG=1
+        $ make SGX_MODE=SIM
     e. Simulation Mode, Pre-release build:
-        $ make SGX_PRERELEASE=1
+        $ make SGX_MODE=SIM SGX_PRERELEASE=1 SGX_DEBUG=0
     f. Simulation Mode, Release build:
-        $ make
+        $ make SGX_MODE=SIM SGX_DEBUG=0
 3. Execute the binary directly:
     $ ./app
+4. Remember to "make clean" before switching build mode
 

+ 27 - 0
buildenv.mk

@@ -54,6 +54,8 @@ 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,
@@ -151,3 +153,28 @@ 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
+

+ 1 - 1
common/inc/internal/se_quote_internal.h

@@ -33,7 +33,7 @@
 #define _SE_QUOTE_INTERNAL_H_
 
 #include "se_types.h"
-#include "epid_types.h"
+#include "epid/common/types.h"
 
 #ifdef  __cplusplus
 extern "C" {

+ 1 - 1
common/inc/internal/se_version.h

@@ -28,5 +28,5 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
-#define STRFILEVER    "1.6.100.34922"
+#define STRFILEVER    "1.7.100.36470"
 

+ 0 - 0
common/inc/sgx_sha256_128.h → common/inc/internal/sgx_sha256_128.h


+ 2 - 2
common/inc/sgx_attributes.h

@@ -39,8 +39,8 @@
 #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_LICENSE_KEY    0x0000000000000020ULL     /* If set, then the enclave has access to License key */
-#define SGX_FLAGS_RESERVED       (~(SGX_FLAGS_INITTED | SGX_FLAGS_DEBUG | SGX_FLAGS_MODE64BIT | SGX_FLAGS_PROVISION_KEY | SGX_FLAGS_LICENSE_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 */

+ 10 - 10
common/inc/sgx_key.h

@@ -43,7 +43,7 @@
 #include "sgx_attributes.h"
 
 /* Key Name */
-#define SGX_KEYSELECT_LICENSE          0x0000
+#define SGX_KEYSELECT_EINITOKEN        0x0000
 #define SGX_KEYSELECT_PROVISION        0x0001
 #define SGX_KEYSELECT_PROVISION_SEAL   0x0002
 #define SGX_KEYSELECT_REPORT           0x0003
@@ -73,15 +73,15 @@ typedef struct _sgx_key_id_t
 
 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 */
+    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;
 
 

+ 32 - 6
download_prebuilt.sh

@@ -32,12 +32,38 @@
 
 
 top_dir=`dirname $0`
-out_dir=$top_dir/psw/ae/data/prebuilt
-file_name=sgxprebuilt-1.6.100.34040.tar
-server_url=https://download.01.org/intel-sgx/linux-1.6/$file_name
-wget $server_url -P $out_dir
+#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_url"
+    echo "Fail to download file $server_optlib_url"
     exit -1
 fi
-pushd $out_dir;tar -xf $file_name;rm -rf $file_name;popd
+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

+ 1 - 1
external/crypto_px/Makefile

@@ -31,7 +31,7 @@
 
 include ../../buildenv.mk
 
-CFLAGS += $(ENCLAVE_CFLAGS)  -D_PX
+CFLAGS += -fPIC  -D_PX
 ifeq ($(ARCH), x86_64)
 	CFLAGS += -D_ARCH_EM64T
 else

+ 195 - 195
external/crypto_px/include/ippbase.h

@@ -1,195 +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__ */
-
+/*
+* 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__ */
+

+ 395 - 395
external/crypto_px/include/ippcore.h

@@ -1,395 +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__ */
+/*
+* 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__ */

+ 327 - 327
external/crypto_px/include/ippcp.h

@@ -1,327 +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__ */
+/*
+* 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__ */

+ 211 - 211
external/crypto_px/include/ippcpdefs.h

@@ -1,211 +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__ */
+/*
+* 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__ */

+ 129 - 129
external/crypto_px/include/ippdefs.h

@@ -1,129 +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__ */
+/*
+* 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__ */

+ 1104 - 1104
external/crypto_px/include/ipptypes.h

@@ -1,1104 +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__ */
+/*
+* 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__ */

+ 41 - 41
external/crypto_px/include/ippversion.h

@@ -1,41 +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__ */
+/*
+* 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__ */

+ 264 - 264
external/crypto_px/sources/include/cpudef.h

@@ -1,264 +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" //////////////////////// */
+/*
+* 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" //////////////////////// */

+ 46 - 46
external/crypto_px/sources/include/ippver.h

@@ -1,46 +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 /////////////////////////////// */
+/*
+* 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 /////////////////////////////// */

+ 944 - 944
external/crypto_px/sources/include/owndefs.h

@@ -1,944 +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 <vxWorks.h>
-  #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__ */
-
+/*
+* 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 <vxWorks.h>
+  #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__ */
+

+ 149 - 149
external/crypto_px/sources/ippcp/src/owncp.h

@@ -1,149 +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 <stdlib.h>
-#  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__ */
+/*
+* 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 <stdlib.h>
+#  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__ */

+ 396 - 396
external/crypto_px/sources/ippcp/src/pcpaesauthcmacca.c

@@ -1,396 +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<cpSizeofCtx_AESCMAC(), ippStsMemAllocErr);
-
-   /* use aligned context */
-   pCtx = (IppsAES_CMACState*)( IPP_ALIGNED_PTR(pCtx, AESCMAC_ALIGNMENT) );
-
-   {
-      IppStatus sts;
-
-      /* set context ID */
-      CMAC_ID(pCtx) = idCtxCMAC;
-      /* init internal buffer and DAC */
-      init(pCtx);
-
-      /* init AES cipher */
-      sts = ippsAESInit(pKey, keyLen, &CMAC_CIPHER(pCtx), cpSizeofCtx_AES());
-
-      if(ippStsNoErr==sts) {
-         const IppsAESSpec* pAES = &CMAC_CIPHER(pCtx);
-
-         /* setup encoder method */
-         RijnCipher encoder = RIJ_ENCODER(pAES);
-
-         int msb;
-         encoder(CMAC_MAC(pCtx), CMAC_K1(pCtx), RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox);
-
-         /* precompute k1 subkey */
-         msb = (CMAC_K1(pCtx))[0];
-         LogicalLeftSift16(CMAC_K1(pCtx),CMAC_K1(pCtx));
-         (CMAC_K1(pCtx))[MBS_RIJ128-1] ^= (Ipp8u)((0-(msb>>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_RIJ128<mdLen), ippStsLengthErr);
-
-   {
-      const IppsAESSpec* pAES = &CMAC_CIPHER(pCtx);
-      /* setup encoder method */
-      RijnCipher encoder = RIJ_ENCODER(pAES);
-
-      /* message length is divided by MBS_RIJ128 */
-      if(MBS_RIJ128==CMAC_INDX(pCtx)) {
-         XorBlock16(CMAC_BUFF(pCtx), CMAC_K1(pCtx), CMAC_BUFF(pCtx));
-      }
-      /* message length isn't divided by MBS_RIJ128 */
-      else {
-         PaddBlock(0, CMAC_BUFF(pCtx)+CMAC_INDX(pCtx), MBS_RIJ128-CMAC_INDX(pCtx));
-         CMAC_BUFF(pCtx)[CMAC_INDX(pCtx)] = 0x80;
-         XorBlock16(CMAC_BUFF(pCtx), CMAC_K2(pCtx), CMAC_BUFF(pCtx));
-      }
-
-      XorBlock16(CMAC_BUFF(pCtx), CMAC_MAC(pCtx), CMAC_MAC(pCtx));
-
-      encoder(CMAC_MAC(pCtx), CMAC_MAC(pCtx), RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox);
-
-      /* return truncated DAC */
-      CopyBlock(CMAC_MAC(pCtx), pMD, mdLen);
-
-      /* re-init context */
-      init(pCtx);
-
-      return ippStsNoErr;
-   }
-}
-
-
-/*F*
-//    Name: ippsAES_CMACGetTag
-//
-// Purpose: computes MD value and could contunue process.
-//
-// 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_CMACGetTag,(Ipp8u* pMD, int mdLen, const 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_RIJ128<mdLen), ippStsLengthErr);
-
-   {
-      const IppsAESSpec* pAES = &CMAC_CIPHER(pCtx);
-      /* setup encoder method */
-      RijnCipher encoder = RIJ_ENCODER(pAES);
-
-      Ipp8u locBuffer[MBS_RIJ128];
-      Ipp8u locMac[MBS_RIJ128];
-      CopyBlock16(CMAC_BUFF(pCtx), locBuffer);
-      CopyBlock16(CMAC_MAC(pCtx), locMac);
-
-      /* message length is divided by MBS_RIJ128 */
-      if(MBS_RIJ128==CMAC_INDX(pCtx)) {
-         XorBlock16(locBuffer, CMAC_K1(pCtx), locBuffer);
-      }
-      /* message length isn't divided by MBS_RIJ128 */
-      else {
-         PaddBlock(0, locBuffer+CMAC_INDX(pCtx), MBS_RIJ128-CMAC_INDX(pCtx));
-         locBuffer[CMAC_INDX(pCtx)] = 0x80;
-         XorBlock16(locBuffer, CMAC_K2(pCtx), locBuffer);
-      }
-
-      XorBlock16(locBuffer, locMac, locMac);
-
-      encoder(locMac, locMac, RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox);
-
-      /* return truncated DAC */
-      CopyBlock(locMac, pMD, mdLen);
-
-      return ippStsNoErr;
-   }
-}
+/*
+* 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<cpSizeofCtx_AESCMAC(), ippStsMemAllocErr);
+
+   /* use aligned context */
+   pCtx = (IppsAES_CMACState*)( IPP_ALIGNED_PTR(pCtx, AESCMAC_ALIGNMENT) );
+
+   {
+      IppStatus sts;
+
+      /* set context ID */
+      CMAC_ID(pCtx) = idCtxCMAC;
+      /* init internal buffer and DAC */
+      init(pCtx);
+
+      /* init AES cipher */
+      sts = ippsAESInit(pKey, keyLen, &CMAC_CIPHER(pCtx), cpSizeofCtx_AES());
+
+      if(ippStsNoErr==sts) {
+         const IppsAESSpec* pAES = &CMAC_CIPHER(pCtx);
+
+         /* setup encoder method */
+         RijnCipher encoder = RIJ_ENCODER(pAES);
+
+         int msb;
+         encoder(CMAC_MAC(pCtx), CMAC_K1(pCtx), RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox);
+
+         /* precompute k1 subkey */
+         msb = (CMAC_K1(pCtx))[0];
+         LogicalLeftSift16(CMAC_K1(pCtx),CMAC_K1(pCtx));
+         (CMAC_K1(pCtx))[MBS_RIJ128-1] ^= (Ipp8u)((0-(msb>>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_RIJ128<mdLen), ippStsLengthErr);
+
+   {
+      const IppsAESSpec* pAES = &CMAC_CIPHER(pCtx);
+      /* setup encoder method */
+      RijnCipher encoder = RIJ_ENCODER(pAES);
+
+      /* message length is divided by MBS_RIJ128 */
+      if(MBS_RIJ128==CMAC_INDX(pCtx)) {
+         XorBlock16(CMAC_BUFF(pCtx), CMAC_K1(pCtx), CMAC_BUFF(pCtx));
+      }
+      /* message length isn't divided by MBS_RIJ128 */
+      else {
+         PaddBlock(0, CMAC_BUFF(pCtx)+CMAC_INDX(pCtx), MBS_RIJ128-CMAC_INDX(pCtx));
+         CMAC_BUFF(pCtx)[CMAC_INDX(pCtx)] = 0x80;
+         XorBlock16(CMAC_BUFF(pCtx), CMAC_K2(pCtx), CMAC_BUFF(pCtx));
+      }
+
+      XorBlock16(CMAC_BUFF(pCtx), CMAC_MAC(pCtx), CMAC_MAC(pCtx));
+
+      encoder(CMAC_MAC(pCtx), CMAC_MAC(pCtx), RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox);
+
+      /* return truncated DAC */
+      CopyBlock(CMAC_MAC(pCtx), pMD, mdLen);
+
+      /* re-init context */
+      init(pCtx);
+
+      return ippStsNoErr;
+   }
+}
+
+
+/*F*
+//    Name: ippsAES_CMACGetTag
+//
+// Purpose: computes MD value and could contunue process.
+//
+// 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_CMACGetTag,(Ipp8u* pMD, int mdLen, const 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_RIJ128<mdLen), ippStsLengthErr);
+
+   {
+      const IppsAESSpec* pAES = &CMAC_CIPHER(pCtx);
+      /* setup encoder method */
+      RijnCipher encoder = RIJ_ENCODER(pAES);
+
+      Ipp8u locBuffer[MBS_RIJ128];
+      Ipp8u locMac[MBS_RIJ128];
+      CopyBlock16(CMAC_BUFF(pCtx), locBuffer);
+      CopyBlock16(CMAC_MAC(pCtx), locMac);
+
+      /* message length is divided by MBS_RIJ128 */
+      if(MBS_RIJ128==CMAC_INDX(pCtx)) {
+         XorBlock16(locBuffer, CMAC_K1(pCtx), locBuffer);
+      }
+      /* message length isn't divided by MBS_RIJ128 */
+      else {
+         PaddBlock(0, locBuffer+CMAC_INDX(pCtx), MBS_RIJ128-CMAC_INDX(pCtx));
+         locBuffer[CMAC_INDX(pCtx)] = 0x80;
+         XorBlock16(locBuffer, CMAC_K2(pCtx), locBuffer);
+      }
+
+      XorBlock16(locBuffer, locMac, locMac);
+
+      encoder(locMac, locMac, RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox);
+
+      /* return truncated DAC */
+      CopyBlock(locMac, pMD, mdLen);
+
+      return ippStsNoErr;
+   }
+}

+ 141 - 141
external/crypto_px/sources/ippcp/src/pcpaesauthgcm.h

@@ -1,141 +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(_CP_AESAUTH_GCM_H)
-#define _CP_AESAUTH_GCM_H
-
-#include "owndefs.h"
-#include "owncp.h"
-#include "pcpaesm.h"
-
-#define BLOCK_SIZE (MBS_RIJ128)
-
-/* GCM Hash prototype: GHash = GHash*HKey mod G() */
-typedef void (*MulGcm_)(Ipp8u* pGHash, const Ipp8u* pHKey, const void* pParam);
-
-/* GCM Authentication prototype: GHash = (GHash^src[])*HKey mod G() */
-typedef void (*Auth_)(Ipp8u* pHash, const Ipp8u* pSrc, int len, const Ipp8u* pHKey, const void* pParam);
-
-/* GCM Encrypt_Authentication prototype */
-typedef void (*Encrypt_)(Ipp8u* pDst, const Ipp8u* pSrc, int len, IppsAES_GCMState* pCtx);
-
-/* GCM Authentication_Decrypt prototype */
-typedef void (*Decrypt_)(Ipp8u* pDst, const Ipp8u* pSrc, int len, IppsAES_GCMState* pCtx);
-
-typedef enum {
-   GcmInit,
-   GcmIVprocessing,
-   GcmAADprocessing,
-   GcmTXTprocessing
-} GcmState;
-
-struct _cpAES_GCM {
-   IppCtxId idCtx;                  /* AES-GCM id                    */
-   GcmState state;                  /* GCM state: Init, IV|AAD|TXT proccessing */
-   Ipp64u   ivLen;                  /* IV length (bytes)             */
-   Ipp64u   aadLen;                 /* header length (bytes)         */
-   Ipp64u   txtLen;                 /* text length (bytes)           */
-
-   int      bufLen;                 /* staff buffer length           */
-   __ALIGN16                        /* aligned buffers               */
-   Ipp8u    counter[BLOCK_SIZE];    /* counter                       */
-   Ipp8u    ecounter0[BLOCK_SIZE];  /* encrypted initial counter     */
-   Ipp8u    ecounter[BLOCK_SIZE];   /* encrypted counter             */
-   Ipp8u    ghash[BLOCK_SIZE];      /* ghash accumulator             */
-
-   MulGcm_  hashFun;                /* AES-GCM mul function          */
-   Auth_    authFun;                /* authentication function       */
-   Encrypt_ encFun;                 /* encryption & authentication   */
-   Decrypt_ decFun;                 /* authentication & decryption   */
-
-   __ALIGN16                        /* aligned AES context           */
-   IppsAESSpec cipher;
-
-   __ALIGN16                        /* aligned pre-computed data:    */
-   Ipp8u multiplier[BLOCK_SIZE];    /* - (default) hKey                             */
-                                    /* - (ase_ni)  hKey*t, (hKey*t)^2, (hKey*t)^4   */
-                                    /* - (safe) hKey*(t^i), i=0,...,127             */
-};
-
-#define CTR_POS         12
-
-/* alignment */
-#define AESGCM_ALIGNMENT   (16)
-
-#define PRECOMP_DATA_SIZE_AES_NI_AESGCM   (BLOCK_SIZE*4)
-#define PRECOMP_DATA_SIZE_FAST2K          (BLOCK_SIZE*128)
-
-/*
-// Useful macros
-*/
-#define AESGCM_ID(stt)           ((stt)->idCtx)
-#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*/
+/*
+* 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_AESAUTH_GCM_H)
+#define _CP_AESAUTH_GCM_H
+
+#include "owndefs.h"
+#include "owncp.h"
+#include "pcpaesm.h"
+
+#define BLOCK_SIZE (MBS_RIJ128)
+
+/* GCM Hash prototype: GHash = GHash*HKey mod G() */
+typedef void (*MulGcm_)(Ipp8u* pGHash, const Ipp8u* pHKey, const void* pParam);
+
+/* GCM Authentication prototype: GHash = (GHash^src[])*HKey mod G() */
+typedef void (*Auth_)(Ipp8u* pHash, const Ipp8u* pSrc, int len, const Ipp8u* pHKey, const void* pParam);
+
+/* GCM Encrypt_Authentication prototype */
+typedef void (*Encrypt_)(Ipp8u* pDst, const Ipp8u* pSrc, int len, IppsAES_GCMState* pCtx);
+
+/* GCM Authentication_Decrypt prototype */
+typedef void (*Decrypt_)(Ipp8u* pDst, const Ipp8u* pSrc, int len, IppsAES_GCMState* pCtx);
+
+typedef enum {
+   GcmInit,
+   GcmIVprocessing,
+   GcmAADprocessing,
+   GcmTXTprocessing
+} GcmState;
+
+struct _cpAES_GCM {
+   IppCtxId idCtx;                  /* AES-GCM id                    */
+   GcmState state;                  /* GCM state: Init, IV|AAD|TXT proccessing */
+   Ipp64u   ivLen;                  /* IV length (bytes)             */
+   Ipp64u   aadLen;                 /* header length (bytes)         */
+   Ipp64u   txtLen;                 /* text length (bytes)           */
+
+   int      bufLen;                 /* staff buffer length           */
+   __ALIGN16                        /* aligned buffers               */
+   Ipp8u    counter[BLOCK_SIZE];    /* counter                       */
+   Ipp8u    ecounter0[BLOCK_SIZE];  /* encrypted initial counter     */
+   Ipp8u    ecounter[BLOCK_SIZE];   /* encrypted counter             */
+   Ipp8u    ghash[BLOCK_SIZE];      /* ghash accumulator             */
+
+   MulGcm_  hashFun;                /* AES-GCM mul function          */
+   Auth_    authFun;                /* authentication function       */
+   Encrypt_ encFun;                 /* encryption & authentication   */
+   Decrypt_ decFun;                 /* authentication & decryption   */
+
+   __ALIGN16                        /* aligned AES context           */
+   IppsAESSpec cipher;
+
+   __ALIGN16                        /* aligned pre-computed data:    */
+   Ipp8u multiplier[BLOCK_SIZE];    /* - (default) hKey                             */
+                                    /* - (ase_ni)  hKey*t, (hKey*t)^2, (hKey*t)^4   */
+                                    /* - (safe) hKey*(t^i), i=0,...,127             */
+};
+
+#define CTR_POS         12
+
+/* alignment */
+#define AESGCM_ALIGNMENT   (16)
+
+#define PRECOMP_DATA_SIZE_AES_NI_AESGCM   (BLOCK_SIZE*4)
+#define PRECOMP_DATA_SIZE_FAST2K          (BLOCK_SIZE*128)
+
+/*
+// Useful macros
+*/
+#define AESGCM_ID(stt)           ((stt)->idCtx)
+#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*/

+ 731 - 731
external/crypto_px/sources/ippcp/src/pcpaesauthgcmca.c

@@ -1,731 +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(ctxSize<cpSizeofCtx_AESGCM(), ippStsMemAllocErr);
-
-   /* use aligned context */
-   pState = (IppsAES_GCMState*)( IPP_ALIGNED_PTR(pState, AESGCM_ALIGNMENT) );
-
-   /* set and clear GCM context */
-   AESGCM_ID(pState) = idCtxAESGCM;
-   ippsAES_GCMReset(pState);
-
-   /* init cipher */
-   {
-      IppStatus sts = ippsAESInit(pKey, keyLen, AESGCM_CIPHER(pState), cpSizeofCtx_AES());
-      if(ippStsNoErr!=sts)
-         return sts;
-   }
-
-   /* set up:
-   // - ghash function
-   // - authentication function
-   */
-   AESGCM_HASH(pState) = AesGcmMulGcm_table2K;
-   AESGCM_AUTH(pState) = AesGcmAuth_table2K;
-   AESGCM_ENC(pState)  = wrpAesGcmEnc_table2K;
-   AESGCM_DEC(pState)  = wrpAesGcmDec_table2K;
-
-   /* precomputations (for constant multiplier(s)) */
-   {
-      IppsAESSpec* pAES = AESGCM_CIPHER(pState);
-      RijnCipher encoder = RIJ_ENCODER(pAES);
-
-      /* multiplier c = Enc({0}) */
-      PaddBlock(0, AESGCM_HKEY(pState), BLOCK_SIZE);
-      encoder(AESGCM_HKEY(pState), AESGCM_HKEY(pState), RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox);
-   }
-
-   AesGcmPrecompute_table2K(AES_GCM_MTBL(pState), AESGCM_HKEY(pState));
-
-   return ippStsNoErr;
-}
-
-
-/*F*
-//    Name: ippsAES_GCMProcessIV
-//
-// Purpose: IV processing.
-//
-// Returns:                Reason:
-//    ippStsNullPtrErr        pState == NULL
-//                            pIV ==NULL && ivLen>0
-//    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;
-   }
-}
+/*
+* 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(ctxSize<cpSizeofCtx_AESGCM(), ippStsMemAllocErr);
+
+   /* use aligned context */
+   pState = (IppsAES_GCMState*)( IPP_ALIGNED_PTR(pState, AESGCM_ALIGNMENT) );
+
+   /* set and clear GCM context */
+   AESGCM_ID(pState) = idCtxAESGCM;
+   ippsAES_GCMReset(pState);
+
+   /* init cipher */
+   {
+      IppStatus sts = ippsAESInit(pKey, keyLen, AESGCM_CIPHER(pState), cpSizeofCtx_AES());
+      if(ippStsNoErr!=sts)
+         return sts;
+   }
+
+   /* set up:
+   // - ghash function
+   // - authentication function
+   */
+   AESGCM_HASH(pState) = AesGcmMulGcm_table2K;
+   AESGCM_AUTH(pState) = AesGcmAuth_table2K;
+   AESGCM_ENC(pState)  = wrpAesGcmEnc_table2K;
+   AESGCM_DEC(pState)  = wrpAesGcmDec_table2K;
+
+   /* precomputations (for constant multiplier(s)) */
+   {
+      IppsAESSpec* pAES = AESGCM_CIPHER(pState);
+      RijnCipher encoder = RIJ_ENCODER(pAES);
+
+      /* multiplier c = Enc({0}) */
+      PaddBlock(0, AESGCM_HKEY(pState), BLOCK_SIZE);
+      encoder(AESGCM_HKEY(pState), AESGCM_HKEY(pState), RIJ_NR(pAES), RIJ_EKEYS(pAES), RijEncSbox);
+   }
+
+   AesGcmPrecompute_table2K(AES_GCM_MTBL(pState), AESGCM_HKEY(pState));
+
+   return ippStsNoErr;
+}
+
+
+/*F*
+//    Name: ippsAES_GCMProcessIV
+//
+// Purpose: IV processing.
+//
+// Returns:                Reason:
+//    ippStsNullPtrErr        pState == NULL
+//                            pIV ==NULL && ivLen>0
+//    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;
+   }
+}

+ 52 - 52
external/crypto_px/sources/ippcp/src/pcpaesgcmtableca.c

@@ -1,52 +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
-};
+/*
+* 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
+};

+ 229 - 229
external/crypto_px/sources/ippcp/src/pcpaesgcmtbl2kca.c

@@ -1,229 +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<m; k++) {
-            XorBlock16(pPrecomputeData +n*256+m*16, pPrecomputeData +n*256+k*16, pPrecomputeData +n*256 +(m+k)*16);
-            XorBlock16(pPrecomputeData +1024 +n*256+m*16, pPrecomputeData +1024 +n*256+k*16, pPrecomputeData +1024 +n*256 +(m+k)*16);
-         }
-   }
-}
-
-
-/*
-// AesGcmMulGcm_def|safe(Ipp8u* pGhash, const Ipp8u* pHKey)
-//
-// Ghash = Ghash * HKey mod G()
-*/
-void AesGcmMulGcm_table2K(Ipp8u* pGhash, const Ipp8u* pPrecomputeData, const void* pParam)
-{
-   __ALIGN16 Ipp8u t5[BLOCK_SIZE];
-   __ALIGN16 Ipp8u t4[BLOCK_SIZE];
-   __ALIGN16 Ipp8u t3[BLOCK_SIZE];
-   __ALIGN16 Ipp8u t2[BLOCK_SIZE];
-
-   int nw;
-   Ipp32u a;
-
-   UNREFERENCED_PARAMETER(pParam);
-
-   XorBlock16(t5, t5, t5);
-   XorBlock16(t4, t4, t4);
-   XorBlock16(t3, t3, t3);
-   XorBlock16(t2, t2, t2);
-
-   for(nw=0; nw<4; nw++) {
-      Ipp32u hashdw = ((Ipp32u*)pGhash)[nw];
-
-      a = hashdw & 0xf0f0f0f0;
-      XorBlock16(t5, pPrecomputeData+1024+EBYTE(a,1)+256*nw, t5);
-      XorBlock16(t4, pPrecomputeData+1024+EBYTE(a,0)+256*nw, t4);
-      XorBlock16(t3, pPrecomputeData+1024+EBYTE(a,3)+256*nw, t3);
-      XorBlock16(t2, pPrecomputeData+1024+EBYTE(a,2)+256*nw, t2);
-
-      a = (hashdw<<4) & 0xf0f0f0f0;
-      XorBlock16(t5, pPrecomputeData+EBYTE(a,1)+256*nw, t5);
-      XorBlock16(t4, pPrecomputeData+EBYTE(a,0)+256*nw, t4);
-      XorBlock16(t3, pPrecomputeData+EBYTE(a,3)+256*nw, t3);
-      XorBlock16(t2, pPrecomputeData+EBYTE(a,2)+256*nw, t2);
-   }
-
-   XorBlock(t2+1, t3, t2+1, BLOCK_SIZE-1);
-   XorBlock(t5+1, t2, t5+1, BLOCK_SIZE-1);
-   XorBlock(t4+1, t5, t4+1, BLOCK_SIZE-1);
-
-   nw = t3[BLOCK_SIZE-1];
-   a = (Ipp32u)AesGcmConst_table[nw];
-   a <<= 8;
-   nw = t2[BLOCK_SIZE-1];
-   a ^= (Ipp32u)AesGcmConst_table[nw];
-   a <<= 8;
-   nw = t5[BLOCK_SIZE-1];
-   a ^= (Ipp32u)AesGcmConst_table[nw];
-
-   XorBlock(t4, &a, t4, sizeof(Ipp32u));
-   CopyBlock16(t4, pGhash);
-}
-
-
-/*
-// authenticates n*BLOCK_SIZE bytes
-*/
-void AesGcmAuth_table2K(Ipp8u* pHash, const Ipp8u* pSrc, int len, const Ipp8u* pHKey, const void* pParam)
-{
-   UNREFERENCED_PARAMETER(pParam);
-
-   while(len>=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);
-      }
-   }
-}
+/*
+* 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<m; k++) {
+            XorBlock16(pPrecomputeData +n*256+m*16, pPrecomputeData +n*256+k*16, pPrecomputeData +n*256 +(m+k)*16);
+            XorBlock16(pPrecomputeData +1024 +n*256+m*16, pPrecomputeData +1024 +n*256+k*16, pPrecomputeData +1024 +n*256 +(m+k)*16);
+         }
+   }
+}
+
+
+/*
+// AesGcmMulGcm_def|safe(Ipp8u* pGhash, const Ipp8u* pHKey)
+//
+// Ghash = Ghash * HKey mod G()
+*/
+void AesGcmMulGcm_table2K(Ipp8u* pGhash, const Ipp8u* pPrecomputeData, const void* pParam)
+{
+   __ALIGN16 Ipp8u t5[BLOCK_SIZE];
+   __ALIGN16 Ipp8u t4[BLOCK_SIZE];
+   __ALIGN16 Ipp8u t3[BLOCK_SIZE];
+   __ALIGN16 Ipp8u t2[BLOCK_SIZE];
+
+   int nw;
+   Ipp32u a;
+
+   UNREFERENCED_PARAMETER(pParam);
+
+   XorBlock16(t5, t5, t5);
+   XorBlock16(t4, t4, t4);
+   XorBlock16(t3, t3, t3);
+   XorBlock16(t2, t2, t2);
+
+   for(nw=0; nw<4; nw++) {
+      Ipp32u hashdw = ((Ipp32u*)pGhash)[nw];
+
+      a = hashdw & 0xf0f0f0f0;
+      XorBlock16(t5, pPrecomputeData+1024+EBYTE(a,1)+256*nw, t5);
+      XorBlock16(t4, pPrecomputeData+1024+EBYTE(a,0)+256*nw, t4);
+      XorBlock16(t3, pPrecomputeData+1024+EBYTE(a,3)+256*nw, t3);
+      XorBlock16(t2, pPrecomputeData+1024+EBYTE(a,2)+256*nw, t2);
+
+      a = (hashdw<<4) & 0xf0f0f0f0;
+      XorBlock16(t5, pPrecomputeData+EBYTE(a,1)+256*nw, t5);
+      XorBlock16(t4, pPrecomputeData+EBYTE(a,0)+256*nw, t4);
+      XorBlock16(t3, pPrecomputeData+EBYTE(a,3)+256*nw, t3);
+      XorBlock16(t2, pPrecomputeData+EBYTE(a,2)+256*nw, t2);
+   }
+
+   XorBlock(t2+1, t3, t2+1, BLOCK_SIZE-1);
+   XorBlock(t5+1, t2, t5+1, BLOCK_SIZE-1);
+   XorBlock(t4+1, t5, t4+1, BLOCK_SIZE-1);
+
+   nw = t3[BLOCK_SIZE-1];
+   a = (Ipp32u)AesGcmConst_table[nw];
+   a <<= 8;
+   nw = t2[BLOCK_SIZE-1];
+   a ^= (Ipp32u)AesGcmConst_table[nw];
+   a <<= 8;
+   nw = t5[BLOCK_SIZE-1];
+   a ^= (Ipp32u)AesGcmConst_table[nw];
+
+   XorBlock(t4, &a, t4, sizeof(Ipp32u));
+   CopyBlock16(t4, pGhash);
+}
+
+
+/*
+// authenticates n*BLOCK_SIZE bytes
+*/
+void AesGcmAuth_table2K(Ipp8u* pHash, const Ipp8u* pSrc, int len, const Ipp8u* pHKey, const void* pParam)
+{
+   UNREFERENCED_PARAMETER(pParam);
+
+   while(len>=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);
+      }
+   }
+}

+ 50 - 50
external/crypto_px/sources/ippcp/src/pcpaesm.h

@@ -1,50 +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 */
+/*
+* 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 */

+ 150 - 150
external/crypto_px/sources/ippcp/src/pcpaesmctrca.c

@@ -1,150 +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)<ctrNumBitSize)||(ctrNumBitSize<1), ippStsCTRSizeErr);
-
-   {
-      Ipp32u counter[NB(128)];
-      Ipp32u  output[NB(128)];
-
-      /* setup encoder method */
-      RijnCipher encoder = RIJ_ENCODER(pCtx);
-
-      /* copy counter */
-      CopyBlock16(pCtrValue, counter);
-
-      /*
-      // encrypt block-by-block aligned streams
-      */
-      while(dataLen>= 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);
-}
+/*
+* 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)<ctrNumBitSize)||(ctrNumBitSize<1), ippStsCTRSizeErr);
+
+   {
+      Ipp32u counter[NB(128)];
+      Ipp32u  output[NB(128)];
+
+      /* setup encoder method */
+      RijnCipher encoder = RIJ_ENCODER(pCtx);
+
+      /* copy counter */
+      CopyBlock16(pCtrValue, counter);
+
+      /*
+      // encrypt block-by-block aligned streams
+      */
+      while(dataLen>= 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);
+}

+ 173 - 173
external/crypto_px/sources/ippcp/src/pcpaesminitca.c

@@ -1,173 +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;
-      }
-   }
-}
+/*
+* 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;
+      }
+   }
+}

+ 210 - 210
external/crypto_px/sources/ippcp/src/pcpbn.h

@@ -1,210 +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  0</==0/>0 */
-__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 */
+/*
+* 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  0</==0/>0 */
+__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 */

+ 1058 - 1058
external/crypto_px/sources/ippcp/src/pcpbnca.c

@@ -1,1058 +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)<BN_SIZE(pB), ippStsOutOfRangeErr);
-   IPP_BADARG_RET((int)BN_ROOM(pQ)<(int)(BN_SIZE(pA)-BN_SIZE(pB)), ippStsOutOfRangeErr);
-
-   {
-      BNU_CHUNK_T* pDataA = BN_BUFFER(pA);
-      cpSize nsA = BN_SIZE(pA);
-      BNU_CHUNK_T* pDataB = BN_NUMBER(pB);
-      cpSize nsB = BN_SIZE(pB);
-      BNU_CHUNK_T* pDataQ = BN_NUMBER(pQ);
-      cpSize nsQ;
-      BNU_CHUNK_T* pDataR = BN_NUMBER(pR);
-      cpSize nsR;
-
-      COPY_BNU(pDataA, BN_NUMBER(pA), nsA);
-      nsR = cpDiv_BNU(pDataQ, &nsQ, pDataA, nsA, pDataB, nsB);
-      COPY_BNU(pDataR, pDataA, nsR);
-
-      BN_SIGN(pQ) = BN_SIGN(pA)==BN_SIGN(pB)? ippBigNumPOS : ippBigNumNEG;
-      FIX_BNU(pDataQ, nsQ);
-      BN_SIZE(pQ) = nsQ;
-      if(nsQ==1 && pDataQ[0]==0) BN_SIGN(pQ) = ippBigNumPOS;
-
-      BN_SIGN(pR) = BN_SIGN(pA);
-      FIX_BNU(pDataR, nsR);
-      BN_SIZE(pR) = nsR;
-      if(nsR==1 && pDataR[0]==0) BN_SIGN(pR) = ippBigNumPOS;
-
-      return ippStsNoErr;
-   }
-}
-
-
-/*F*
-//    Name: ippsMod_BN
-//
-// Purpose: reduction BigNum.
-//
-// Returns:                Reason:
-//    ippStsNullPtrErr        pA  == NULL
-//                            pM  == NULL
-//                            pR  == NULL
-//    ippStsContextMatchErr   BN_VALID_ID(pA)
-//                            BN_VALID_ID(pM)
-//                            BN_VALID_ID(pR)
-//    ippStsOutOfRangeErr     pR can not hold result
-//    ippStsNoErr             no errors
-//
-// Parameters:
-//    pA    source BigNum
-//    pB    source BigNum
-//    pR    reminder BigNum
-//
-//    A = Q*M + R, 0 <= R < B
-//
-*F*/
-IPPFUN(IppStatus, ippsMod_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_NEGATIVE(pM), ippStsBadModulusErr);
-   IPP_BADARG_RET(BN_SIZE(pM)== 1 && BN_NUMBER(pM)[0]==0, ippStsBadModulusErr);
-
-   IPP_BADARG_RET(BN_ROOM(pR)<BN_SIZE(pM), ippStsOutOfRangeErr);
-
-   if(cpEqu_BNU_CHUNK(BN_NUMBER(pA), BN_SIZE(pA), 0)) {
-      BN_SIGN(pR) = ippBigNumPOS;
-      BN_SIZE(pR) = 1;
-      BN_NUMBER(pR)[0] = 0;
-   }
-
-   else {
-      BNU_CHUNK_T* pDataM = BN_NUMBER(pM);
-      cpSize nsM = BN_SIZE(pM);
-      BNU_CHUNK_T* pBuffA = BN_BUFFER(pA);
-      cpSize nsA = BN_SIZE(pA);
-      BNU_CHUNK_T* pDataR = BN_NUMBER(pR);
-      cpSize nsR;
-
-      COPY_BNU(pBuffA, BN_NUMBER(pA), nsA);
-      nsR = cpMod_BNU(pBuffA, nsA, pDataM, nsM);
-
-      COPY_BNU(pDataR, pBuffA, nsR);
-      BN_SIZE(pR) = nsR;
-      BN_SIGN(pR) = ippBigNumPOS;
-
-      if(BN_NEGATIVE(pA) && !(nsR==1 && pDataR[0]==0)) {
-         ZEXPAND_BNU(pDataR, nsR, nsM);
-         cpSub_BNU(pDataR, pDataM, pDataR, nsM);
-         FIX_BNU(pDataR, nsM);
-         BN_SIZE(pR) = nsM;
-      }
-   }
-
-   return ippStsNoErr;
-}
-
-
-/*F*
-//    Name: ippsGcd_BN
-//
-// Purpose: compute GCD value.
-//
-// Returns:                Reason:
-//    ippStsNullPtrErr        pA  == NULL
-//                            pB  == NULL
-//                            pG  == NULL
-//    ippStsContextMatchErr   BN_VALID_ID(pA)
-//                            BN_VALID_ID(pB)
-//                            BN_VALID_ID(pG)
-//    ippStsBadArgErr         A==B==0
-//    ippStsOutOfRangeErr     pG can not hold result
-//    ippStsNoErr             no errors
-//
-// Parameters:
-//    pA    source BigNum
-//    pB    source BigNum
-//    pG    GCD value
-//
-*F*/
-IPPFUN(IppStatus, ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pG))
-{
-   IPP_BAD_PTR3_RET(pA, pB, pG);
-
-   pA = (IppsBigNumState*)(IPP_ALIGNED_PTR(pA, BN_ALIGNMENT));
-   pB = (IppsBigNumState*)(IPP_ALIGNED_PTR(pB, BN_ALIGNMENT));
-   pG = (IppsBigNumState*)(IPP_ALIGNED_PTR(pG, BN_ALIGNMENT));
-   IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr);
-   IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr);
-   IPP_BADARG_RET(!BN_VALID_ID(pG), ippStsContextMatchErr);
-
-   IPP_BADARG_RET(BN_ROOM(pG) < IPP_MIN(BN_SIZE(pA), BN_SIZE(pB)), ippStsOutOfRangeErr);
-
-   {
-      IppsBigNumState* x = pA;
-      IppsBigNumState* y = pB;
-      IppsBigNumState* g = pG;
-
-      int aIsZero = BN_SIZE(pA)==1 && BN_NUMBER(pA)[0]==0;
-      int bIsZero = BN_SIZE(pB)==1 && BN_NUMBER(pB)[0]==0;
-
-      if(aIsZero && bIsZero)
-         return ippStsBadArgErr;
-      if(aIsZero && !bIsZero) {
-         COPY_BNU(BN_NUMBER(g), BN_NUMBER(pB), BN_SIZE(pB));
-         BN_SIZE(g) = BN_SIZE(pB);
-         BN_SIGN(g) = ippBigNumPOS;
-         return ippStsNoErr;
-      }
-      if(bIsZero && !aIsZero) {
-         COPY_BNU(BN_NUMBER(g), BN_NUMBER(pA), BN_SIZE(pB));
-         BN_SIZE(g) = BN_SIZE(pA);
-         BN_SIGN(g) = ippBigNumPOS;
-         return ippStsNoErr;
-      }
-
-      /*
-      // Lehmer's algorithm requres that first number must be greater than second
-      // x is the first, y is the second
-      */
-      {
-         int cmpRes = cpCmp_BNU(BN_NUMBER(x), BN_SIZE(x), BN_NUMBER(y), BN_SIZE(y));
-         if(0>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;
-    }
-}
+/*
+* 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)<BN_SIZE(pB), ippStsOutOfRangeErr);
+   IPP_BADARG_RET((int)BN_ROOM(pQ)<(int)(BN_SIZE(pA)-BN_SIZE(pB)), ippStsOutOfRangeErr);
+
+   {
+      BNU_CHUNK_T* pDataA = BN_BUFFER(pA);
+      cpSize nsA = BN_SIZE(pA);
+      BNU_CHUNK_T* pDataB = BN_NUMBER(pB);
+      cpSize nsB = BN_SIZE(pB);
+      BNU_CHUNK_T* pDataQ = BN_NUMBER(pQ);
+      cpSize nsQ;
+      BNU_CHUNK_T* pDataR = BN_NUMBER(pR);
+      cpSize nsR;
+
+      COPY_BNU(pDataA, BN_NUMBER(pA), nsA);
+      nsR = cpDiv_BNU(pDataQ, &nsQ, pDataA, nsA, pDataB, nsB);
+      COPY_BNU(pDataR, pDataA, nsR);
+
+      BN_SIGN(pQ) = BN_SIGN(pA)==BN_SIGN(pB)? ippBigNumPOS : ippBigNumNEG;
+      FIX_BNU(pDataQ, nsQ);
+      BN_SIZE(pQ) = nsQ;
+      if(nsQ==1 && pDataQ[0]==0) BN_SIGN(pQ) = ippBigNumPOS;
+
+      BN_SIGN(pR) = BN_SIGN(pA);
+      FIX_BNU(pDataR, nsR);
+      BN_SIZE(pR) = nsR;
+      if(nsR==1 && pDataR[0]==0) BN_SIGN(pR) = ippBigNumPOS;
+
+      return ippStsNoErr;
+   }
+}
+
+
+/*F*
+//    Name: ippsMod_BN
+//
+// Purpose: reduction BigNum.
+//
+// Returns:                Reason:
+//    ippStsNullPtrErr        pA  == NULL
+//                            pM  == NULL
+//                            pR  == NULL
+//    ippStsContextMatchErr   BN_VALID_ID(pA)
+//                            BN_VALID_ID(pM)
+//                            BN_VALID_ID(pR)
+//    ippStsOutOfRangeErr     pR can not hold result
+//    ippStsNoErr             no errors
+//
+// Parameters:
+//    pA    source BigNum
+//    pB    source BigNum
+//    pR    reminder BigNum
+//
+//    A = Q*M + R, 0 <= R < B
+//
+*F*/
+IPPFUN(IppStatus, ippsMod_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_NEGATIVE(pM), ippStsBadModulusErr);
+   IPP_BADARG_RET(BN_SIZE(pM)== 1 && BN_NUMBER(pM)[0]==0, ippStsBadModulusErr);
+
+   IPP_BADARG_RET(BN_ROOM(pR)<BN_SIZE(pM), ippStsOutOfRangeErr);
+
+   if(cpEqu_BNU_CHUNK(BN_NUMBER(pA), BN_SIZE(pA), 0)) {
+      BN_SIGN(pR) = ippBigNumPOS;
+      BN_SIZE(pR) = 1;
+      BN_NUMBER(pR)[0] = 0;
+   }
+
+   else {
+      BNU_CHUNK_T* pDataM = BN_NUMBER(pM);
+      cpSize nsM = BN_SIZE(pM);
+      BNU_CHUNK_T* pBuffA = BN_BUFFER(pA);
+      cpSize nsA = BN_SIZE(pA);
+      BNU_CHUNK_T* pDataR = BN_NUMBER(pR);
+      cpSize nsR;
+
+      COPY_BNU(pBuffA, BN_NUMBER(pA), nsA);
+      nsR = cpMod_BNU(pBuffA, nsA, pDataM, nsM);
+
+      COPY_BNU(pDataR, pBuffA, nsR);
+      BN_SIZE(pR) = nsR;
+      BN_SIGN(pR) = ippBigNumPOS;
+
+      if(BN_NEGATIVE(pA) && !(nsR==1 && pDataR[0]==0)) {
+         ZEXPAND_BNU(pDataR, nsR, nsM);
+         cpSub_BNU(pDataR, pDataM, pDataR, nsM);
+         FIX_BNU(pDataR, nsM);
+         BN_SIZE(pR) = nsM;
+      }
+   }
+
+   return ippStsNoErr;
+}
+
+
+/*F*
+//    Name: ippsGcd_BN
+//
+// Purpose: compute GCD value.
+//
+// Returns:                Reason:
+//    ippStsNullPtrErr        pA  == NULL
+//                            pB  == NULL
+//                            pG  == NULL
+//    ippStsContextMatchErr   BN_VALID_ID(pA)
+//                            BN_VALID_ID(pB)
+//                            BN_VALID_ID(pG)
+//    ippStsBadArgErr         A==B==0
+//    ippStsOutOfRangeErr     pG can not hold result
+//    ippStsNoErr             no errors
+//
+// Parameters:
+//    pA    source BigNum
+//    pB    source BigNum
+//    pG    GCD value
+//
+*F*/
+IPPFUN(IppStatus, ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pG))
+{
+   IPP_BAD_PTR3_RET(pA, pB, pG);
+
+   pA = (IppsBigNumState*)(IPP_ALIGNED_PTR(pA, BN_ALIGNMENT));
+   pB = (IppsBigNumState*)(IPP_ALIGNED_PTR(pB, BN_ALIGNMENT));
+   pG = (IppsBigNumState*)(IPP_ALIGNED_PTR(pG, BN_ALIGNMENT));
+   IPP_BADARG_RET(!BN_VALID_ID(pA), ippStsContextMatchErr);
+   IPP_BADARG_RET(!BN_VALID_ID(pB), ippStsContextMatchErr);
+   IPP_BADARG_RET(!BN_VALID_ID(pG), ippStsContextMatchErr);
+
+   IPP_BADARG_RET(BN_ROOM(pG) < IPP_MIN(BN_SIZE(pA), BN_SIZE(pB)), ippStsOutOfRangeErr);
+
+   {
+      IppsBigNumState* x = pA;
+      IppsBigNumState* y = pB;
+      IppsBigNumState* g = pG;
+
+      int aIsZero = BN_SIZE(pA)==1 && BN_NUMBER(pA)[0]==0;
+      int bIsZero = BN_SIZE(pB)==1 && BN_NUMBER(pB)[0]==0;
+
+      if(aIsZero && bIsZero)
+         return ippStsBadArgErr;
+      if(aIsZero && !bIsZero) {
+         COPY_BNU(BN_NUMBER(g), BN_NUMBER(pB), BN_SIZE(pB));
+         BN_SIZE(g) = BN_SIZE(pB);
+         BN_SIGN(g) = ippBigNumPOS;
+         return ippStsNoErr;
+      }
+      if(bIsZero && !aIsZero) {
+         COPY_BNU(BN_NUMBER(g), BN_NUMBER(pA), BN_SIZE(pB));
+         BN_SIZE(g) = BN_SIZE(pA);
+         BN_SIGN(g) = ippBigNumPOS;
+         return ippStsNoErr;
+      }
+
+      /*
+      // Lehmer's algorithm requres that first number must be greater than second
+      // x is the first, y is the second
+      */
+      {
+         int cmpRes = cpCmp_BNU(BN_NUMBER(x), BN_SIZE(x), BN_NUMBER(y), BN_SIZE(y));
+         if(0>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;
+    }
+}

+ 51 - 51
external/crypto_px/sources/ippcp/src/pcpbnresource.h

@@ -1,51 +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 */
+/*
+* 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 */

+ 93 - 93
external/crypto_px/sources/ippcp/src/pcpbnresourceca.c

@@ -1,93 +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; n<nodes; n++) {
-         Ipp8u* tbnPtr = (Ipp8u*)pNode + sizeof(BigNumNode);
-         pNode->pNext = 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;
-}
+/*
+* 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; n<nodes; n++) {
+         Ipp8u* tbnPtr = (Ipp8u*)pNode + sizeof(BigNumNode);
+         pNode->pNext = 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;
+}

+ 119 - 119
external/crypto_px/sources/ippcp/src/pcpbnsetca.c

@@ -1,119 +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, ippStsSizeErr);
-   if(strLen)
-      BN_SIZE(pBN) = cpFromOctStr_BNU(BN_NUMBER(pBN), pOctStr, strLen);
-   else {
-      BN_NUMBER(pBN)[0] = (BNU_CHUNK_T)0;
-      BN_SIZE(pBN) = 1;
-   }
-   BN_SIGN(pBN) = ippBigNumPOS;
-
-   return ippStsNoErr;
-}
-
-
-/*F*
-//    Name: ippsGetOctString_BN
-//
-// Purpose: Convert BN value into the octet string.
-//
-// Returns:                   Reason:
-//    ippStsNullPtrErr           NULL == pOctStr
-//                               NULL == pBN
-//
-//    ippStsRangeErr             BN <0
-//
-//    ippStsLengthErr            strLen is enough for keep BN value
-//
-//    ippStsNoErr                no errors
-//
-// Parameters:
-//    pBN         pointer to the source BN
-//    pOctStr     pointer to the target octet string
-//    strLen      octet string length
-*F*/
-IPPFUN(IppStatus, ippsGetOctString_BN,(Ipp8u* pOctStr, cpSize strLen,
-                                       const 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(BN_NEGATIVE(pBN), ippStsRangeErr);
-   IPP_BADARG_RET((0>strLen), ippStsLengthErr);
-
-   return cpToOctStr_BNU(pOctStr,strLen, BN_NUMBER(pBN),BN_SIZE(pBN))? ippStsNoErr : ippStsLengthErr;
-}
+/*
+* 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, ippStsSizeErr);
+   if(strLen)
+      BN_SIZE(pBN) = cpFromOctStr_BNU(BN_NUMBER(pBN), pOctStr, strLen);
+   else {
+      BN_NUMBER(pBN)[0] = (BNU_CHUNK_T)0;
+      BN_SIZE(pBN) = 1;
+   }
+   BN_SIGN(pBN) = ippBigNumPOS;
+
+   return ippStsNoErr;
+}
+
+
+/*F*
+//    Name: ippsGetOctString_BN
+//
+// Purpose: Convert BN value into the octet string.
+//
+// Returns:                   Reason:
+//    ippStsNullPtrErr           NULL == pOctStr
+//                               NULL == pBN
+//
+//    ippStsRangeErr             BN <0
+//
+//    ippStsLengthErr            strLen is enough for keep BN value
+//
+//    ippStsNoErr                no errors
+//
+// Parameters:
+//    pBN         pointer to the source BN
+//    pOctStr     pointer to the target octet string
+//    strLen      octet string length
+*F*/
+IPPFUN(IppStatus, ippsGetOctString_BN,(Ipp8u* pOctStr, cpSize strLen,
+                                       const 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(BN_NEGATIVE(pBN), ippStsRangeErr);
+   IPP_BADARG_RET((0>strLen), ippStsLengthErr);
+
+   return cpToOctStr_BNU(pOctStr,strLen, BN_NUMBER(pBN),BN_SIZE(pBN))? ippStsNoErr : ippStsLengthErr;
+}

+ 234 - 234
external/crypto_px/sources/ippcp/src/pcpbnu32arith.c

@@ -1,234 +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<ns; i++) {
-      Ipp64u t = (Ipp64u)carry +pA[i] + pB[i];
-      pR[i] = LODWORD(t);
-      carry = HIDWORD(t);
-   }
-   return carry;
-}
-
-/*
-// BNU32 subtraction
-*/
-Ipp32u cpSub_BNU32(Ipp32u* pR, const Ipp32u* pA, const Ipp32u* pB, cpSize ns)
-{
-   Ipp32u borrow = 0;
-   cpSize i;
-   for(i=0; i<ns; i++) {
-      Ipp64u t = (Ipp64u)(pA[i]) - pB[i] - borrow;
-      pR[i] = LODWORD(t);
-      borrow = 0-HIDWORD(t);
-   }
-   return borrow;
-}
-
-/*
-// BNU32 decrement
-*/
-Ipp32u cpDec_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize ns, Ipp32u v)
-{
-   Ipp32u borrow = v;
-   int n;
-   for(n=0; n<ns; n++) {
-      Ipp64u t = (Ipp64u)(pA[n]) - (Ipp64u)borrow;
-      pR[n] = LODWORD(t);
-      borrow = HIDWORD(t)>>(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; i<nsA; i++) {
-      Ipp64u t = (Ipp64u)val * (Ipp64u)pA[i] + carry;
-      pR[i] = LODWORD(t);
-      carry = HIDWORD(t);
-    }
-    return carry;
-}
-
-
-/*
-// BNU32 mul_by_digit_subtract
-*/
-Ipp32u cpSubMulDgt_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize nsA, Ipp32u val)
-{
-   Ipp32u carry = 0;
-   for(; nsA>0; 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]<<nlz) | (pX[ni-1]>>(32-nlz));
-         pX[0] <<= nlz;
-
-         for(ni=sizeY-1; ni>0; ni--)
-            pY[ni] = (pY[ni]<<nlz) | (pY[ni-1]>>(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<sizeX; ni++)
-            pX[ni] = (pX[ni]>>nlz) | (pX[ni+1]<<(32-nlz));
-         for(ni=0; ni<sizeY-1; ni++)
-            pY[ni] = (pY[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;
-   }
-}
+/*
+* 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<ns; i++) {
+      Ipp64u t = (Ipp64u)carry +pA[i] + pB[i];
+      pR[i] = LODWORD(t);
+      carry = HIDWORD(t);
+   }
+   return carry;
+}
+
+/*
+// BNU32 subtraction
+*/
+Ipp32u cpSub_BNU32(Ipp32u* pR, const Ipp32u* pA, const Ipp32u* pB, cpSize ns)
+{
+   Ipp32u borrow = 0;
+   cpSize i;
+   for(i=0; i<ns; i++) {
+      Ipp64u t = (Ipp64u)(pA[i]) - pB[i] - borrow;
+      pR[i] = LODWORD(t);
+      borrow = 0-HIDWORD(t);
+   }
+   return borrow;
+}
+
+/*
+// BNU32 decrement
+*/
+Ipp32u cpDec_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize ns, Ipp32u v)
+{
+   Ipp32u borrow = v;
+   int n;
+   for(n=0; n<ns; n++) {
+      Ipp64u t = (Ipp64u)(pA[n]) - (Ipp64u)borrow;
+      pR[n] = LODWORD(t);
+      borrow = HIDWORD(t)>>(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; i<nsA; i++) {
+      Ipp64u t = (Ipp64u)val * (Ipp64u)pA[i] + carry;
+      pR[i] = LODWORD(t);
+      carry = HIDWORD(t);
+    }
+    return carry;
+}
+
+
+/*
+// BNU32 mul_by_digit_subtract
+*/
+Ipp32u cpSubMulDgt_BNU32(Ipp32u* pR, const Ipp32u* pA, cpSize nsA, Ipp32u val)
+{
+   Ipp32u carry = 0;
+   for(; nsA>0; 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]<<nlz) | (pX[ni-1]>>(32-nlz));
+         pX[0] <<= nlz;
+
+         for(ni=sizeY-1; ni>0; ni--)
+            pY[ni] = (pY[ni]<<nlz) | (pY[ni-1]>>(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<sizeX; ni++)
+            pX[ni] = (pX[ni]>>nlz) | (pX[ni+1]<<(32-nlz));
+         for(ni=0; ni<sizeY-1; ni++)
+            pY[ni] = (pY[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;
+   }
+}

+ 46 - 46
external/crypto_px/sources/ippcp/src/pcpbnu32arith.h

@@ -1,46 +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 */
+/*
+* 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 */

+ 53 - 53
external/crypto_px/sources/ippcp/src/pcpbnu32misc.c

@@ -1,53 +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;
-}
+/*
+* 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;
+}

+ 49 - 49
external/crypto_px/sources/ippcp/src/pcpbnu32misc.h

@@ -1,49 +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 */
+/*
+* 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 */

+ 301 - 301
external/crypto_px/sources/ippcp/src/pcpbnuarith.c

@@ -1,301 +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<ns; i++) {
-      ADD_ABC(carry, pR[i], pA[i],pB[i], carry);
-   }
-   return carry;
-}
-
-/* Function cpSub_BNU - subtraction of 2 BigNumbers  */
-BNU_CHUNK_T cpSub_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, cpSize ns)
-{
-   BNU_CHUNK_T borrow = 0;
-   cpSize i;
-   for(i=0; i<ns; i++) {
-      SUB_ABC(borrow, pR[i], pA[i], pB[i], borrow);
-   }
-   return borrow;
-}
-
-/* Function cpInc_BNU - increment BigNumber  */
-BNU_CHUNK_T cpInc_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val)
-{
-   cpSize i;
-   for(i=0; i<ns && val; i++) {
-      BNU_CHUNK_T carry;
-      ADD_AB(carry, pR[i], pA[i], val);
-      val = carry;
-   }
-   if(pR!=pA)
-      for(; i<ns; i++)
-         pR[i] = pA[i];
-   return val;
-}
-
-BNU_CHUNK_T cpDec_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val)
-{
-   cpSize i;
-   for(i=0; i<ns && val; i++) {
-      BNU_CHUNK_T borrow;
-      SUB_AB(borrow, pR[i], pA[i], val);
-      val = borrow;
-   }
-   if(pR!=pA)
-      for(; i<ns; i++)
-         pR[i] = pA[i];
-   return val;
-}
-
-BNU_CHUNK_T cpAddMulDgt_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val)
-{
-   BNU_CHUNK_T extension = 0;
-   cpSize i;
-   for(i=0; i<ns; i++) {
-      BNU_CHUNK_T rH, rL;
-
-      MUL_AB(rH, rL, pA[i], val);
-      ADD_ABC(extension, pR[i], pR[i], rL, extension);
-      extension += rH;
-   }
-   return extension;
-}
-
-BNU_CHUNK_T cpMulAdc_BNU_school(BNU_CHUNK_T* pR,
-                          const BNU_CHUNK_T* pA, cpSize nsA,
-                          const BNU_CHUNK_T* pB, cpSize nsB)
-{
-   const BNU_CHUNK_T* pa = (BNU_CHUNK_T*)pA;
-   const BNU_CHUNK_T* pb = (BNU_CHUNK_T*)pB;
-   BNU_CHUNK_T* pr = (BNU_CHUNK_T*)pR;
-
-   BNU_CHUNK_T extension = 0;
-   cpSize i, j;
-
-   ZEXPAND_BNU(pr, 0, nsA+nsB);
-
-   for(i=0; i<nsB; i++ ) {
-      BNU_CHUNK_T b = pb[i];
-
-      for(j=0, extension=0; j<nsA; j++ ) {
-         BNU_CHUNK_T rH, rL;
-
-         MUL_AB(rH, rL, pa[j], b);
-         ADD_ABC(extension, pr[i+j], pr[i+j], rL, extension);
-         extension += rH;
-      }
-      pr[i+j] = extension;
-   }
-   return extension;
-}
-
-
-BNU_CHUNK_T cpSqrAdc_BNU_school(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize nsA)
-{
-   cpSize i;
-
-   BNU_CHUNK_T extension;
-   BNU_CHUNK_T rH, rL;
-
-   /* init result */
-   pR[0] = 0;
-   for(i=1, extension=0; i<nsA; i++) {
-      MUL_AB(rH, rL, pA[i], pA[0]);
-      ADD_AB(extension, pR[i], rL, extension);
-      extension += rH;
-   }
-   pR[i] = extension;
-
-   /* add other a[i]*a[j] */
-   for(i=1; i<nsA-1; i++) {
-      BNU_CHUNK_T a = pA[i];
-      cpSize j;
-      for(j=i+1, extension=0; j<nsA; j++) {
-         MUL_AB(rH, rL, pA[j], a);
-         ADD_ABC(extension, pR[i+j], rL, pR[i+j], extension);
-         extension += rH;
-      }
-      pR[i+j] = extension;
-   }
-
-   /* double a[i]*a[j] */
-   for(i=1, extension=0; i<(2*nsA-1); i++) {
-      ADD_ABC(extension, pR[i], pR[i], pR[i], extension);
-   }
-   pR[i] = extension;
-
-   /* add a[i]^2 */
-   for(i=0, extension=0; i<nsA; i++) {
-      MUL_AB(rH, rL, pA[i], pA[i]);
-      ADD_ABC(extension, pR[2*i], pR[2*i], rL, extension);
-      ADD_ABC(extension, pR[2*i+1], pR[2*i+1], rH, extension);
-   }
-   return pR[2*nsA-1];
-}
-
-
-BNU_CHUNK_T cpGcd_BNU(BNU_CHUNK_T a, BNU_CHUNK_T b)
-{
-    BNU_CHUNK_T gcd, t, r;
-
-    if(a > 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<nsB && !expansion; i++) {
-         expansion = cpAddMulDgt_BNU(pR+i, pA, nsA, pB[i]);
-         if(expansion)
-            expansion = cpInc_BNU(pR+i+nsA, pR+i+nsA, nsR-i-nsA, expansion);
-      }
-
-      if(expansion)
-         return 0;
-      else {   /* compute real size */
-         FIX_BNU(pR, nsR);
-         return nsR;
-      }
-   }
-}
-
-
-int cpModInv_BNU(BNU_CHUNK_T* pInv,
-            const BNU_CHUNK_T* pA, cpSize nsA,
-            const BNU_CHUNK_T* pM, cpSize nsM,
-                  BNU_CHUNK_T* bufInv, BNU_CHUNK_T* bufA, BNU_CHUNK_T* bufM)
-{
-    FIX_BNU(pA, nsA);
-    FIX_BNU(pM, nsM);
-
-   /* inv(1) = 1 */
-   if(nsA==1 && pA[0]==1) {
-      pInv[0] = 1;
-      return 1;
-   }
-
-   {
-      cpSize moduloSize = nsM;
-
-      BNU_CHUNK_T* X1 = pInv;
-      BNU_CHUNK_T* X2 = bufM;
-      BNU_CHUNK_T* Q = bufInv;
-      cpSize nsX1 = 1;
-      cpSize nsX2 = 1;
-      cpSize nsQ;
-
-      COPY_BNU(bufA, pA, nsA);
-
-      ZEXPAND_BNU(X1, 0, moduloSize);
-      ZEXPAND_BNU(X2, 0, moduloSize);
-      X2[0] = 1;
-
-      for(;;) {
-         nsM = cpDiv_BNU(Q, &nsQ, (BNU_CHUNK_T*)pM, nsM, bufA, nsA);
-         nsX1 = cpMac_BNU(X1,moduloSize, Q,nsQ, X2,nsX2);
-
-         if (nsM==1 && pM[0]==1) {
-            ////ZEXPAND_BNU(X2, nsX2, moduloSize);
-            nsX2 = cpMac_BNU(X2,moduloSize, X1,nsX1, bufA, nsA);
-            COPY_BNU((BNU_CHUNK_T*)pM, X2, moduloSize);
-            cpSub_BNU(pInv, pM, X1, moduloSize);
-            FIX_BNU(pInv, moduloSize);
-            return moduloSize;
-         }
-         else if (nsM==1 && pM[0]==0) {
-            cpMul_BNU_school((BNU_CHUNK_T*)pM, X1,nsX1, bufA, nsA);
-            /* gcd = buf_a */
-            return 0;
-         }
-
-         nsA = cpDiv_BNU(Q, &nsQ, bufA, nsA, (BNU_CHUNK_T*)pM, nsM);
-         nsX2 = cpMac_BNU(X2,moduloSize, Q,nsQ, X1,nsX1);
-
-         if(nsA==1 && bufA[0]==1) {
-            ////ZEXPAND_BNU(X1, nsX1, moduloSize);
-            nsX1 = cpMac_BNU(X1, moduloSize, X2, nsX2, pM, nsM);
-            COPY_BNU((BNU_CHUNK_T*)pM, X1, moduloSize);
-            COPY_BNU(pInv, X2, nsX2);
-            return nsX2;
-         }
-         else if (nsA==1 && bufA[0]==0) {
-            /* gcd = m */
-            COPY_BNU(X1, pM, nsM);
-            cpMul_BNU_school((BNU_CHUNK_T*)pM, X2, nsX2, X1, nsM);
-            return 0;
-         }
-      }
-   }
-}
+/*
+* 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<ns; i++) {
+      ADD_ABC(carry, pR[i], pA[i],pB[i], carry);
+   }
+   return carry;
+}
+
+/* Function cpSub_BNU - subtraction of 2 BigNumbers  */
+BNU_CHUNK_T cpSub_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, cpSize ns)
+{
+   BNU_CHUNK_T borrow = 0;
+   cpSize i;
+   for(i=0; i<ns; i++) {
+      SUB_ABC(borrow, pR[i], pA[i], pB[i], borrow);
+   }
+   return borrow;
+}
+
+/* Function cpInc_BNU - increment BigNumber  */
+BNU_CHUNK_T cpInc_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val)
+{
+   cpSize i;
+   for(i=0; i<ns && val; i++) {
+      BNU_CHUNK_T carry;
+      ADD_AB(carry, pR[i], pA[i], val);
+      val = carry;
+   }
+   if(pR!=pA)
+      for(; i<ns; i++)
+         pR[i] = pA[i];
+   return val;
+}
+
+BNU_CHUNK_T cpDec_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val)
+{
+   cpSize i;
+   for(i=0; i<ns && val; i++) {
+      BNU_CHUNK_T borrow;
+      SUB_AB(borrow, pR[i], pA[i], val);
+      val = borrow;
+   }
+   if(pR!=pA)
+      for(; i<ns; i++)
+         pR[i] = pA[i];
+   return val;
+}
+
+BNU_CHUNK_T cpAddMulDgt_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val)
+{
+   BNU_CHUNK_T extension = 0;
+   cpSize i;
+   for(i=0; i<ns; i++) {
+      BNU_CHUNK_T rH, rL;
+
+      MUL_AB(rH, rL, pA[i], val);
+      ADD_ABC(extension, pR[i], pR[i], rL, extension);
+      extension += rH;
+   }
+   return extension;
+}
+
+BNU_CHUNK_T cpMulAdc_BNU_school(BNU_CHUNK_T* pR,
+                          const BNU_CHUNK_T* pA, cpSize nsA,
+                          const BNU_CHUNK_T* pB, cpSize nsB)
+{
+   const BNU_CHUNK_T* pa = (BNU_CHUNK_T*)pA;
+   const BNU_CHUNK_T* pb = (BNU_CHUNK_T*)pB;
+   BNU_CHUNK_T* pr = (BNU_CHUNK_T*)pR;
+
+   BNU_CHUNK_T extension = 0;
+   cpSize i, j;
+
+   ZEXPAND_BNU(pr, 0, nsA+nsB);
+
+   for(i=0; i<nsB; i++ ) {
+      BNU_CHUNK_T b = pb[i];
+
+      for(j=0, extension=0; j<nsA; j++ ) {
+         BNU_CHUNK_T rH, rL;
+
+         MUL_AB(rH, rL, pa[j], b);
+         ADD_ABC(extension, pr[i+j], pr[i+j], rL, extension);
+         extension += rH;
+      }
+      pr[i+j] = extension;
+   }
+   return extension;
+}
+
+
+BNU_CHUNK_T cpSqrAdc_BNU_school(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize nsA)
+{
+   cpSize i;
+
+   BNU_CHUNK_T extension;
+   BNU_CHUNK_T rH, rL;
+
+   /* init result */
+   pR[0] = 0;
+   for(i=1, extension=0; i<nsA; i++) {
+      MUL_AB(rH, rL, pA[i], pA[0]);
+      ADD_AB(extension, pR[i], rL, extension);
+      extension += rH;
+   }
+   pR[i] = extension;
+
+   /* add other a[i]*a[j] */
+   for(i=1; i<nsA-1; i++) {
+      BNU_CHUNK_T a = pA[i];
+      cpSize j;
+      for(j=i+1, extension=0; j<nsA; j++) {
+         MUL_AB(rH, rL, pA[j], a);
+         ADD_ABC(extension, pR[i+j], rL, pR[i+j], extension);
+         extension += rH;
+      }
+      pR[i+j] = extension;
+   }
+
+   /* double a[i]*a[j] */
+   for(i=1, extension=0; i<(2*nsA-1); i++) {
+      ADD_ABC(extension, pR[i], pR[i], pR[i], extension);
+   }
+   pR[i] = extension;
+
+   /* add a[i]^2 */
+   for(i=0, extension=0; i<nsA; i++) {
+      MUL_AB(rH, rL, pA[i], pA[i]);
+      ADD_ABC(extension, pR[2*i], pR[2*i], rL, extension);
+      ADD_ABC(extension, pR[2*i+1], pR[2*i+1], rH, extension);
+   }
+   return pR[2*nsA-1];
+}
+
+
+BNU_CHUNK_T cpGcd_BNU(BNU_CHUNK_T a, BNU_CHUNK_T b)
+{
+    BNU_CHUNK_T gcd, t, r;
+
+    if(a > 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<nsB && !expansion; i++) {
+         expansion = cpAddMulDgt_BNU(pR+i, pA, nsA, pB[i]);
+         if(expansion)
+            expansion = cpInc_BNU(pR+i+nsA, pR+i+nsA, nsR-i-nsA, expansion);
+      }
+
+      if(expansion)
+         return 0;
+      else {   /* compute real size */
+         FIX_BNU(pR, nsR);
+         return nsR;
+      }
+   }
+}
+
+
+int cpModInv_BNU(BNU_CHUNK_T* pInv,
+            const BNU_CHUNK_T* pA, cpSize nsA,
+            const BNU_CHUNK_T* pM, cpSize nsM,
+                  BNU_CHUNK_T* bufInv, BNU_CHUNK_T* bufA, BNU_CHUNK_T* bufM)
+{
+    FIX_BNU(pA, nsA);
+    FIX_BNU(pM, nsM);
+
+   /* inv(1) = 1 */
+   if(nsA==1 && pA[0]==1) {
+      pInv[0] = 1;
+      return 1;
+   }
+
+   {
+      cpSize moduloSize = nsM;
+
+      BNU_CHUNK_T* X1 = pInv;
+      BNU_CHUNK_T* X2 = bufM;
+      BNU_CHUNK_T* Q = bufInv;
+      cpSize nsX1 = 1;
+      cpSize nsX2 = 1;
+      cpSize nsQ;
+
+      COPY_BNU(bufA, pA, nsA);
+
+      ZEXPAND_BNU(X1, 0, moduloSize);
+      ZEXPAND_BNU(X2, 0, moduloSize);
+      X2[0] = 1;
+
+      for(;;) {
+         nsM = cpDiv_BNU(Q, &nsQ, (BNU_CHUNK_T*)pM, nsM, bufA, nsA);
+         nsX1 = cpMac_BNU(X1,moduloSize, Q,nsQ, X2,nsX2);
+
+         if (nsM==1 && pM[0]==1) {
+            ////ZEXPAND_BNU(X2, nsX2, moduloSize);
+            nsX2 = cpMac_BNU(X2,moduloSize, X1,nsX1, bufA, nsA);
+            COPY_BNU((BNU_CHUNK_T*)pM, X2, moduloSize);
+            cpSub_BNU(pInv, pM, X1, moduloSize);
+            FIX_BNU(pInv, moduloSize);
+            return moduloSize;
+         }
+         else if (nsM==1 && pM[0]==0) {
+            cpMul_BNU_school((BNU_CHUNK_T*)pM, X1,nsX1, bufA, nsA);
+            /* gcd = buf_a */
+            return 0;
+         }
+
+         nsA = cpDiv_BNU(Q, &nsQ, bufA, nsA, (BNU_CHUNK_T*)pM, nsM);
+         nsX2 = cpMac_BNU(X2,moduloSize, Q,nsQ, X1,nsX1);
+
+         if(nsA==1 && bufA[0]==1) {
+            ////ZEXPAND_BNU(X1, nsX1, moduloSize);
+            nsX1 = cpMac_BNU(X1, moduloSize, X2, nsX2, pM, nsM);
+            COPY_BNU((BNU_CHUNK_T*)pM, X1, moduloSize);
+            COPY_BNU(pInv, X2, nsX2);
+            return nsX2;
+         }
+         else if (nsA==1 && bufA[0]==0) {
+            /* gcd = m */
+            COPY_BNU(X1, pM, nsM);
+            cpMul_BNU_school((BNU_CHUNK_T*)pM, X2, nsX2, X1, nsM);
+            return 0;
+         }
+      }
+   }
+}

+ 114 - 114
external/crypto_px/sources/ippcp/src/pcpbnuarith.h

@@ -1,114 +1,114 @@
-/*
-* 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_BNU_ARITH_H)
-#define _CP_BNU_ARITH_H
-
-#include "pcpbnuimpl.h"
-#include "pcpbnu32arith.h"
-
-BNU_CHUNK_T cpAdd_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, cpSize ns);
-BNU_CHUNK_T cpSub_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, cpSize ns);
-BNU_CHUNK_T cpInc_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val);
-BNU_CHUNK_T cpDec_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val);
-
-BNU_CHUNK_T cpAddMulDgt_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val);
-
-BNU_CHUNK_T cpMulAdc_BNU_school(BNU_CHUNK_T* pR,
-                         const BNU_CHUNK_T* pA, cpSize nsA,
-                         const BNU_CHUNK_T* pB, cpSize nsB);
-
-__INLINE BNU_CHUNK_T cpMul_BNU_school(BNU_CHUNK_T* pR,
-                                const BNU_CHUNK_T* pA, cpSize nsA,
-                                const BNU_CHUNK_T* pB, cpSize nsB)
-{
-   return cpMulAdc_BNU_school(pR, pA,nsA, pB,nsB);
-}
-
-BNU_CHUNK_T cpSqrAdc_BNU_school(BNU_CHUNK_T * pR, const BNU_CHUNK_T * pA, cpSize nsA);
-
-__INLINE BNU_CHUNK_T cpSqr_BNU_school(BNU_CHUNK_T * pR, const BNU_CHUNK_T * pA, cpSize nsA)
-{
-   return cpSqrAdc_BNU_school(pR, pA,nsA);
-}
-
-BNU_CHUNK_T cpGcd_BNU(BNU_CHUNK_T a, BNU_CHUNK_T b);
-
-int cpModInv_BNU(BNU_CHUNK_T* pInv,
-           const BNU_CHUNK_T* pA, cpSize nsA,
-           const BNU_CHUNK_T* pM, cpSize nsM,
-                 BNU_CHUNK_T* bufInv, BNU_CHUNK_T* bufA, BNU_CHUNK_T* bufM);
-
-
-/*
-// multiplication/squaring wrappers
-*/
-__INLINE BNU_CHUNK_T cpMul_BNU(BNU_CHUNK_T* pR,
-                         const BNU_CHUNK_T* pA, cpSize nsA,
-                         const BNU_CHUNK_T* pB, cpSize nsB,
-                               BNU_CHUNK_T* pBuffer)
-{
-   UNREFERENCED_PARAMETER(pBuffer);
-   return cpMul_BNU_school(pR, pA,nsA, pB,nsB);
-}
-__INLINE BNU_CHUNK_T cpSqr_BNU(BNU_CHUNK_T * pR,
-                         const BNU_CHUNK_T * pA, cpSize nsA,
-                               BNU_CHUNK_T* pBuffer)
-{
-   UNREFERENCED_PARAMETER(pBuffer);
-   return cpSqr_BNU_school(pR, pA,nsA);
-}
-
-/*
-// division/reduction wrappers
-*/
-__INLINE cpSize cpDiv_BNU(BNU_CHUNK_T* pQ, cpSize* pnsQ, BNU_CHUNK_T* pA, cpSize nsA, BNU_CHUNK_T* pB, cpSize nsB)
-{
-   int nsR = cpDiv_BNU32((Ipp32u*)pQ, pnsQ,
-                         (Ipp32u*)pA, nsA*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)),
-                         (Ipp32u*)pB, nsB*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)));
-   #if (BNU_CHUNK_BITS == BNU_CHUNK_64BIT)
-   if(nsR&1) ((Ipp32u*)pA)[nsR] = 0;
-   nsR = INTERNAL_BNU_LENGTH(nsR);
-   if(pQ) {
-      if(*pnsQ&1) ((Ipp32u*)pQ)[*pnsQ] = 0;
-      *pnsQ = INTERNAL_BNU_LENGTH(*pnsQ);
-   }
-   #endif
-   return nsR;
-}
-
-__INLINE cpSize cpMod_BNU(BNU_CHUNK_T* pX, cpSize nsX, BNU_CHUNK_T* pModulus, cpSize nsM)
-{
-   return cpDiv_BNU(NULL,NULL, pX,nsX, pModulus, nsM);
-}
-
-#endif /* _CP_BNU_ARITH_H */
+/*
+* 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_BNU_ARITH_H)
+#define _CP_BNU_ARITH_H
+
+#include "pcpbnuimpl.h"
+#include "pcpbnu32arith.h"
+
+BNU_CHUNK_T cpAdd_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, cpSize ns);
+BNU_CHUNK_T cpSub_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, const BNU_CHUNK_T* pB, cpSize ns);
+BNU_CHUNK_T cpInc_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val);
+BNU_CHUNK_T cpDec_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val);
+
+BNU_CHUNK_T cpAddMulDgt_BNU(BNU_CHUNK_T* pR, const BNU_CHUNK_T* pA, cpSize ns, BNU_CHUNK_T val);
+
+BNU_CHUNK_T cpMulAdc_BNU_school(BNU_CHUNK_T* pR,
+                         const BNU_CHUNK_T* pA, cpSize nsA,
+                         const BNU_CHUNK_T* pB, cpSize nsB);
+
+__INLINE BNU_CHUNK_T cpMul_BNU_school(BNU_CHUNK_T* pR,
+                                const BNU_CHUNK_T* pA, cpSize nsA,
+                                const BNU_CHUNK_T* pB, cpSize nsB)
+{
+   return cpMulAdc_BNU_school(pR, pA,nsA, pB,nsB);
+}
+
+BNU_CHUNK_T cpSqrAdc_BNU_school(BNU_CHUNK_T * pR, const BNU_CHUNK_T * pA, cpSize nsA);
+
+__INLINE BNU_CHUNK_T cpSqr_BNU_school(BNU_CHUNK_T * pR, const BNU_CHUNK_T * pA, cpSize nsA)
+{
+   return cpSqrAdc_BNU_school(pR, pA,nsA);
+}
+
+BNU_CHUNK_T cpGcd_BNU(BNU_CHUNK_T a, BNU_CHUNK_T b);
+
+int cpModInv_BNU(BNU_CHUNK_T* pInv,
+           const BNU_CHUNK_T* pA, cpSize nsA,
+           const BNU_CHUNK_T* pM, cpSize nsM,
+                 BNU_CHUNK_T* bufInv, BNU_CHUNK_T* bufA, BNU_CHUNK_T* bufM);
+
+
+/*
+// multiplication/squaring wrappers
+*/
+__INLINE BNU_CHUNK_T cpMul_BNU(BNU_CHUNK_T* pR,
+                         const BNU_CHUNK_T* pA, cpSize nsA,
+                         const BNU_CHUNK_T* pB, cpSize nsB,
+                               BNU_CHUNK_T* pBuffer)
+{
+   UNREFERENCED_PARAMETER(pBuffer);
+   return cpMul_BNU_school(pR, pA,nsA, pB,nsB);
+}
+__INLINE BNU_CHUNK_T cpSqr_BNU(BNU_CHUNK_T * pR,
+                         const BNU_CHUNK_T * pA, cpSize nsA,
+                               BNU_CHUNK_T* pBuffer)
+{
+   UNREFERENCED_PARAMETER(pBuffer);
+   return cpSqr_BNU_school(pR, pA,nsA);
+}
+
+/*
+// division/reduction wrappers
+*/
+__INLINE cpSize cpDiv_BNU(BNU_CHUNK_T* pQ, cpSize* pnsQ, BNU_CHUNK_T* pA, cpSize nsA, BNU_CHUNK_T* pB, cpSize nsB)
+{
+   int nsR = cpDiv_BNU32((Ipp32u*)pQ, pnsQ,
+                         (Ipp32u*)pA, nsA*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)),
+                         (Ipp32u*)pB, nsB*(sizeof(BNU_CHUNK_T)/sizeof(Ipp32u)));
+   #if (BNU_CHUNK_BITS == BNU_CHUNK_64BIT)
+   if(nsR&1) ((Ipp32u*)pA)[nsR] = 0;
+   nsR = INTERNAL_BNU_LENGTH(nsR);
+   if(pQ) {
+      if(*pnsQ&1) ((Ipp32u*)pQ)[*pnsQ] = 0;
+      *pnsQ = INTERNAL_BNU_LENGTH(*pnsQ);
+   }
+   #endif
+   return nsR;
+}
+
+__INLINE cpSize cpMod_BNU(BNU_CHUNK_T* pX, cpSize nsX, BNU_CHUNK_T* pModulus, cpSize nsM)
+{
+   return cpDiv_BNU(NULL,NULL, pX,nsX, pModulus, nsM);
+}
+
+#endif /* _CP_BNU_ARITH_H */

+ 141 - 141
external/crypto_px/sources/ippcp/src/pcpbnuimpl.h

@@ -1,141 +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(_CP_BNU_IMPL_H)
-#define _CP_BNU_IMPL_H
-
-#define BNU_CHUNK_64BIT        (64)
-#define BNU_CHUNK_32BIT        (32)
-
-
-/*
-// define BNU chunk data type
-*/
-#if ((_IPP_ARCH == _IPP_ARCH_EM64T) || (_IPP_ARCH == _IPP_ARCH_LP64) || (_IPP_ARCH == _IPP_ARCH_LRB) || (_IPP_ARCH == _IPP_ARCH_LRB2))
-   typedef Ipp64u BNU_CHUNK_T;
-   typedef Ipp64s BNS_CHUNK_T;
-   #define BNU_CHUNK_LOG2  (6)
-   #define BNU_CHUNK_BITS  BNU_CHUNK_64BIT
-
-#else
-   typedef Ipp32u BNU_CHUNK_T;
-   typedef Ipp32s BNS_CHUNK_T;
-   #define BNU_CHUNK_LOG2  (5)
-   #define BNU_CHUNK_BITS  BNU_CHUNK_32BIT
-#endif
-
-#define BNU_CHUNK_MASK        (~(BNU_CHUNK_T)(0))
-
-#if (BNU_CHUNK_BITS == BNU_CHUNK_64BIT)
-   #pragma message ("BNU_CHUNK_BITS = 64 bit")
-#elif (BNU_CHUNK_BITS == BNU_CHUNK_32BIT)
-   #pragma message ("BNU_CHUNK_BITS = 32 bit")
-#else
-   #error BNU_CHUNK_BITS should be either 64 or 32 bit!
-#endif
-
-
-#ifdef _MSC_VER
-#  pragma warning( disable : 4127)
-#endif
-
-/* user's API BNU chunk data type */
-typedef Ipp32u API_BNU_CHUNK_T;
-
-/* convert API_BNU_CHUNK_T (usual Ipp32u) length into the BNU_CHUNK_T length */
-#define INTERNAL_BNU_LENGTH(apiLen) \
-   ((apiLen) + sizeof(BNU_CHUNK_T)/sizeof(API_BNU_CHUNK_T) -1)/(sizeof(BNU_CHUNK_T)/sizeof(API_BNU_CHUNK_T))
-
-/* Low and High parts of BNU_CHUNK_T value */
-#define BNU_CHUNK_2H ((BNU_CHUNK_T)1 << (BNU_CHUNK_BITS/2))
-#define LO_CHUNK(c)  ((BNU_CHUNK_T)(c) & (BNU_CHUNK_2H - 1))
-#define HI_CHUNK(c)  ((BNU_CHUNK_T)(c) >> (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 */
+/*
+* 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_BNU_IMPL_H)
+#define _CP_BNU_IMPL_H
+
+#define BNU_CHUNK_64BIT        (64)
+#define BNU_CHUNK_32BIT        (32)
+
+
+/*
+// define BNU chunk data type
+*/
+#if ((_IPP_ARCH == _IPP_ARCH_EM64T) || (_IPP_ARCH == _IPP_ARCH_LP64) || (_IPP_ARCH == _IPP_ARCH_LRB) || (_IPP_ARCH == _IPP_ARCH_LRB2))
+   typedef Ipp64u BNU_CHUNK_T;
+   typedef Ipp64s BNS_CHUNK_T;
+   #define BNU_CHUNK_LOG2  (6)
+   #define BNU_CHUNK_BITS  BNU_CHUNK_64BIT
+
+#else
+   typedef Ipp32u BNU_CHUNK_T;
+   typedef Ipp32s BNS_CHUNK_T;
+   #define BNU_CHUNK_LOG2  (5)
+   #define BNU_CHUNK_BITS  BNU_CHUNK_32BIT
+#endif
+
+#define BNU_CHUNK_MASK        (~(BNU_CHUNK_T)(0))
+
+#if (BNU_CHUNK_BITS == BNU_CHUNK_64BIT)
+   #pragma message ("BNU_CHUNK_BITS = 64 bit")
+#elif (BNU_CHUNK_BITS == BNU_CHUNK_32BIT)
+   #pragma message ("BNU_CHUNK_BITS = 32 bit")
+#else
+   #error BNU_CHUNK_BITS should be either 64 or 32 bit!
+#endif
+
+
+#ifdef _MSC_VER
+#  pragma warning( disable : 4127)
+#endif
+
+/* user's API BNU chunk data type */
+typedef Ipp32u API_BNU_CHUNK_T;
+
+/* convert API_BNU_CHUNK_T (usual Ipp32u) length into the BNU_CHUNK_T length */
+#define INTERNAL_BNU_LENGTH(apiLen) \
+   ((apiLen) + sizeof(BNU_CHUNK_T)/sizeof(API_BNU_CHUNK_T) -1)/(sizeof(BNU_CHUNK_T)/sizeof(API_BNU_CHUNK_T))
+
+/* Low and High parts of BNU_CHUNK_T value */
+#define BNU_CHUNK_2H ((BNU_CHUNK_T)1 << (BNU_CHUNK_BITS/2))
+#define LO_CHUNK(c)  ((BNU_CHUNK_T)(c) & (BNU_CHUNK_2H - 1))
+#define HI_CHUNK(c)  ((BNU_CHUNK_T)(c) >> (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 */

+ 208 - 208
external/crypto_px/sources/ippcp/src/pcpbnumisc.c

@@ -1,208 +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<nsA; n++)
-         pR[n] = pA[n];
-   }
-
-   for(n=0; n<nw; n++)
-      pR[nsA+n] = 0;
-
-   return nsA+nw;
-}
-
-
-/*
-// Convert Oct String into BNU representation
-//
-// Returns size of BNU in BNU_CHUNK_T chunks
-*/
-cpSize cpFromOctStr_BNU(BNU_CHUNK_T* pA, const Ipp8u* pStr, cpSize strLen)
-{
-   int nsA =0;
-
-   /* start from the end of string */
-   for(; strLen>=(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;
-   }
-}
+/*
+* 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<nsA; n++)
+         pR[n] = pA[n];
+   }
+
+   for(n=0; n<nw; n++)
+      pR[nsA+n] = 0;
+
+   return nsA+nw;
+}
+
+
+/*
+// Convert Oct String into BNU representation
+//
+// Returns size of BNU in BNU_CHUNK_T chunks
+*/
+cpSize cpFromOctStr_BNU(BNU_CHUNK_T* pA, const Ipp8u* pStr, cpSize strLen)
+{
+   int nsA =0;
+
+   /* start from the end of string */
+   for(; strLen>=(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;
+   }
+}

+ 149 - 149
external/crypto_px/sources/ippcp/src/pcpbnumisc.h

@@ -1,149 +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 */
+/*
+* 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 */

+ 70 - 70
external/crypto_px/sources/ippcp/src/pcpcmac.h

@@ -1,70 +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 */
+/*
+* 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 */

+ 230 - 230
external/crypto_px/sources/ippcp/src/pcpeccp.h

@@ -1,230 +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 */
+/*
+* 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 */

+ 370 - 370
external/crypto_px/sources/ippcp/src/pcpeccpdpca.c

@@ -1,370 +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(!(0<cofactor), ippStsRangeErr);
-
-   /* set general methods */
-   *(ECP_METHOD(pECC)) = *(ECCPcom_Methods());
-
-   /* set domain parameters */
-   ECCPSetDP(IppECCArbitrary,
-             BN_SIZE32(pPrime), (Ipp32u*)BN_NUMBER(pPrime),
-             BN_SIZE32(pA),     (Ipp32u*)BN_NUMBER(pA),
-             BN_SIZE32(pB),     (Ipp32u*)BN_NUMBER(pB),
-             BN_SIZE32(pGX),    (Ipp32u*)BN_NUMBER(pGX),
-             BN_SIZE32(pGY),    (Ipp32u*)BN_NUMBER(pGY),
-             BN_SIZE32(pOrder), (Ipp32u*)BN_NUMBER(pOrder),
-             cofactor,
-             pECC);
-
-   return ippStsNoErr;
-}
-
-
-/*F*
-//    Name: ippsECCPSetStd
-//
-// Purpose: Set Standard ECC Domain Parameter.
-//
-// Returns:                Reason:
-//    ippStsNullPtrErr        NULL == pECC
-//
-//    ippStsContextMatchErr   illegal pECC->idCtx
-//
-//    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;
-}
+/*
+* 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(!(0<cofactor), ippStsRangeErr);
+
+   /* set general methods */
+   *(ECP_METHOD(pECC)) = *(ECCPcom_Methods());
+
+   /* set domain parameters */
+   ECCPSetDP(IppECCArbitrary,
+             BN_SIZE32(pPrime), (Ipp32u*)BN_NUMBER(pPrime),
+             BN_SIZE32(pA),     (Ipp32u*)BN_NUMBER(pA),
+             BN_SIZE32(pB),     (Ipp32u*)BN_NUMBER(pB),
+             BN_SIZE32(pGX),    (Ipp32u*)BN_NUMBER(pGX),
+             BN_SIZE32(pGY),    (Ipp32u*)BN_NUMBER(pGY),
+             BN_SIZE32(pOrder), (Ipp32u*)BN_NUMBER(pOrder),
+             cofactor,
+             pECC);
+
+   return ippStsNoErr;
+}
+
+
+/*F*
+//    Name: ippsECCPSetStd
+//
+// Purpose: Set Standard ECC Domain Parameter.
+//
+// Returns:                Reason:
+//    ippStsNullPtrErr        NULL == pECC
+//
+//    ippStsContextMatchErr   illegal pECC->idCtx
+//
+//    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;
+}

+ 107 - 107
external/crypto_px/sources/ippcp/src/pcpeccpgenkeyca.c

@@ -1,107 +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)<ECP_ORDBITS(pECC)), ippStsSizeErr);
-   IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPublic), ippStsContextMatchErr);
-
-   {
-      /*
-      // generate random private key X:  0 < X < R
-      */
-      int reqBitLen = ECP_ORDBITS(pECC);
-
-      IppsBigNumState* pOrder = ECP_ORDER(pECC);
-
-      int xSize;
-      Ipp32u* pX = (Ipp32u*)BN_NUMBER(pPrivate);
-      Ipp32u xMask = MAKEMASK32(reqBitLen);
-
-      BN_SIGN(pPrivate) = ippBigNumPOS;
-      do {
-         xSize = BITS2WORD32_SIZE(reqBitLen);
-         rndFunc(pX, reqBitLen, pRndParam);
-         pX[xSize-1] &= xMask;
-         FIX_BNU(pX, xSize);
-         BN_SIZE(pPrivate) = INTERNAL_BNU_LENGTH(xSize);
-      } while( (0 == cpBN_tst(pPrivate)) ||
-               (0 <= cpBN_cmp(pPrivate, pOrder)) );
-
-      /* calculate public key */
-      ECP_METHOD(pECC)->MulBasePoint(pPrivate, pPublic, pECC, ECP_BNCTX(pECC));
-
-      return ippStsNoErr;
-   }
-}
+/*
+* 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)<ECP_ORDBITS(pECC)), ippStsSizeErr);
+   IPP_BADARG_RET(!ECP_POINT_VALID_ID(pPublic), ippStsContextMatchErr);
+
+   {
+      /*
+      // generate random private key X:  0 < X < R
+      */
+      int reqBitLen = ECP_ORDBITS(pECC);
+
+      IppsBigNumState* pOrder = ECP_ORDER(pECC);
+
+      int xSize;
+      Ipp32u* pX = (Ipp32u*)BN_NUMBER(pPrivate);
+      Ipp32u xMask = MAKEMASK32(reqBitLen);
+
+      BN_SIGN(pPrivate) = ippBigNumPOS;
+      do {
+         xSize = BITS2WORD32_SIZE(reqBitLen);
+         rndFunc(pX, reqBitLen, pRndParam);
+         pX[xSize-1] &= xMask;
+         FIX_BNU(pX, xSize);
+         BN_SIZE(pPrivate) = INTERNAL_BNU_LENGTH(xSize);
+      } while( (0 == cpBN_tst(pPrivate)) ||
+               (0 <= cpBN_cmp(pPrivate, pOrder)) );
+
+      /* calculate public key */
+      ECP_METHOD(pECC)->MulBasePoint(pPrivate, pPublic, pECC, ECP_BNCTX(pECC));
+
+      return ippStsNoErr;
+   }
+}

+ 305 - 305
external/crypto_px/sources/ippcp/src/pcpeccpinitca.c

@@ -1,305 +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<<w;
-      int sscmBuffSize = nPrecomputed*(BITS_BNU_CHUNK(feBitSize)*3*sizeof(BNU_CHUNK_T)) +(CACHE_LINE_SIZE-1);
-
-      /* size of BigNum over GF(p) */
-      ippsBigNumGetSize(gfeSize, &bn1Size);
-
-      /* size of BigNum over GF(r) */
-      ippsBigNumGetSize(ordSize, &bn2Size);
-
-      /* size of EC point over GF(p) */
-      ippsECCPPointGetSize(feBitSize, &pointSize);
-
-      /* size of montgomery engine over GF(p) */
-      ippsMontGetSize(ippBinaryMethod, BITS2WORD32_SIZE(feBitSize), &mont1Size);
-
-      /* size of montgomery engine over GF(r) */
-      ippsMontGetSize(ippBinaryMethod, BITS2WORD32_SIZE(feBitSize+1), &mont2Size);
-
-      /* size of prime engine */
-      ippsPrimeGetSize(feBitSize+1, &primeSize);
-
-      /* size of big num list (big num in the list preserve 32 bit word) */
-      listSize = cpBigNumListGetSize(feBitSize+1, BNLISTSIZE);
-
-      *pSize = sizeof(IppsECCPState)
-              +sizeof(ECCP_METHOD)  /* methods       */
-
-              +bn1Size              /* prime         */
-              +bn1Size              /* A             */
-              +bn1Size              /* B             */
-
-              +bn1Size              /* GX            */
-              +bn1Size              /* GY            */
-              +bn2Size              /* order         */
-
-              +bn1Size              /* Aenc          */
-              +bn1Size              /* Benc          */
-              +mont1Size            /* montgomery(p) */
-
-              +pointSize            /* Genc          */
-              +bn2Size              /* cofactor      */
-              +mont2Size            /* montgomery(r) */
-
-              +bn2Size              /* private       */
-              +pointSize            /* public        */
-
-              +bn2Size              /* eph private   */
-              +pointSize            /* eph public    */
-
-              +primeSize            /* prime engine  */
-              +sscmBuffSize         /* sscm buffer   */
-              +listSize             /* temp big num  */
-              +(ALIGN_VAL-1);
-   }
-
-   return ippStsNoErr;
-}
-
-
-/*F*
-//    Name: ippsECCPInit
-//
-// Purpose: Init ECC context.
-//
-// Returns:                   Reason:
-//    ippStsNullPtrErr           NULL == pECC
-//
-//    ippStsSizeErr              2>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<<w;
-      int sscmBuffSize = nPrecomputed*(BITS_BNU_CHUNK(feBitSize)*3*sizeof(BNU_CHUNK_T)) +(CACHE_LINE_SIZE-1);
-
-      Ipp8u* ptr = (Ipp8u*)pECC;
-
-      /* size of BigNum over GF(p) */
-      ippsBigNumGetSize(gfeSize, &bn1Size);
-
-      /* size of BigNum over GF(r) */
-      ippsBigNumGetSize(ordSize, &bn2Size);
-
-      /* size of EC point over GF(p) */
-      ippsECCPPointGetSize(feBitSize, &pointSize);
-
-      /* size of montgomery engine over GF(p) */
-      ippsMontGetSize(ippBinaryMethod, BITS2WORD32_SIZE(feBitSize), &mont1Size);
-
-      /* size of montgomery engine over GF(r) */
-      ippsMontGetSize(ippBinaryMethod, BITS2WORD32_SIZE(feBitSize+1), &mont2Size);
-
-      /* size of prime engine */
-      ippsPrimeGetSize(feBitSize+1, &primeSize);
-
-      /* size of big num list */
-      /* listSize = cpBigNumListGetSize(feBitSize+1+32, BNLISTSIZE); */
-
-      /* allocate buffers */
-      ptr += sizeof(IppsECCPState);
-
-      ECP_METHOD(pECC)  = (ECCP_METHOD*)  (ptr);
-      ptr += sizeof(ECCP_METHOD);
-
-      ECP_PRIME(pECC)   = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-      ptr += bn1Size;
-      ECP_A(pECC)       = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-      ptr += bn1Size;
-      ECP_B(pECC)       = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-
-      ptr += bn1Size;
-      ECP_GX(pECC)      = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-      ptr += bn1Size;
-      ECP_GY(pECC)      = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-      ptr += bn1Size;
-      ECP_ORDER(pECC)   = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-
-      ptr += bn2Size;
-      ECP_AENC(pECC)    = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-      ptr += bn1Size;
-      ECP_BENC(pECC)    = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-      ptr += bn1Size;
-      ECP_PMONT(pECC)   = (IppsMontState*)     ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-
-      ptr += mont1Size;
-      ECP_GENC(pECC)    = (IppsECCPPointState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-      ptr += pointSize;
-      ECP_COFACTOR(pECC)= (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-      ptr += bn2Size;
-      ECP_RMONT(pECC)   = (IppsMontState*)     ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-
-      ptr += mont2Size;
-      ECP_PRIVATE(pECC) = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-      ptr += bn2Size;
-      ECP_PUBLIC(pECC)  = (IppsECCPPointState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-
-      ptr += pointSize;
-      ECP_PRIVATE_E(pECC) = (IppsBigNumState*) ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-      ptr += bn2Size;
-      ECP_PUBLIC_E(pECC) =(IppsECCPPointState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-
-      ptr += pointSize;
-      ECP_PRIMARY(pECC) = (IppsPrimeState*)    ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-      ptr += primeSize;
-
-      ECP_SCCMBUFF(pECC) = (Ipp8u*)            ( IPP_ALIGNED_PTR(ptr,CACHE_LINE_SIZE) );
-      ptr += sscmBuffSize;
-
-      ECP_BNCTX(pECC)   = (BigNumNode*)        ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
-
-      /* init buffers */
-      ippsBigNumInit(gfeSize,  ECP_PRIME(pECC));
-      ippsBigNumInit(gfeSize,  ECP_A(pECC));
-      ippsBigNumInit(gfeSize,  ECP_B(pECC));
-
-      ippsBigNumInit(gfeSize,  ECP_GX(pECC));
-      ippsBigNumInit(gfeSize,  ECP_GY(pECC));
-      ippsBigNumInit(ordSize,  ECP_ORDER(pECC));
-
-      ippsBigNumInit(gfeSize,  ECP_AENC(pECC));
-      ippsBigNumInit(gfeSize,  ECP_BENC(pECC));
-      ippsMontInit(ippBinaryMethod, BITS2WORD32_SIZE(feBitSize), ECP_PMONT(pECC));
-
-      ippsECCPPointInit(feBitSize, ECP_GENC(pECC));
-      ippsBigNumInit(ordSize,    ECP_COFACTOR(pECC));
-      ippsMontInit(ippBinaryMethod, BITS2WORD32_SIZE(feBitSize+1), ECP_RMONT(pECC));
-
-      ippsBigNumInit(ordSize,   ECP_PRIVATE(pECC));
-      ippsECCPPointInit(feBitSize,ECP_PUBLIC(pECC));
-
-      ippsBigNumInit(ordSize,   ECP_PRIVATE_E(pECC));
-      ippsECCPPointInit(feBitSize,ECP_PUBLIC_E(pECC));
-
-      cpBigNumListInit(feBitSize+1, BNLISTSIZE, ECP_BNCTX(pECC));
-   }
-
-   return ippStsNoErr;
-}
+/*
+* 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<<w;
+      int sscmBuffSize = nPrecomputed*(BITS_BNU_CHUNK(feBitSize)*3*sizeof(BNU_CHUNK_T)) +(CACHE_LINE_SIZE-1);
+
+      /* size of BigNum over GF(p) */
+      ippsBigNumGetSize(gfeSize, &bn1Size);
+
+      /* size of BigNum over GF(r) */
+      ippsBigNumGetSize(ordSize, &bn2Size);
+
+      /* size of EC point over GF(p) */
+      ippsECCPPointGetSize(feBitSize, &pointSize);
+
+      /* size of montgomery engine over GF(p) */
+      ippsMontGetSize(ippBinaryMethod, BITS2WORD32_SIZE(feBitSize), &mont1Size);
+
+      /* size of montgomery engine over GF(r) */
+      ippsMontGetSize(ippBinaryMethod, BITS2WORD32_SIZE(feBitSize+1), &mont2Size);
+
+      /* size of prime engine */
+      ippsPrimeGetSize(feBitSize+1, &primeSize);
+
+      /* size of big num list (big num in the list preserve 32 bit word) */
+      listSize = cpBigNumListGetSize(feBitSize+1, BNLISTSIZE);
+
+      *pSize = sizeof(IppsECCPState)
+              +sizeof(ECCP_METHOD)  /* methods       */
+
+              +bn1Size              /* prime         */
+              +bn1Size              /* A             */
+              +bn1Size              /* B             */
+
+              +bn1Size              /* GX            */
+              +bn1Size              /* GY            */
+              +bn2Size              /* order         */
+
+              +bn1Size              /* Aenc          */
+              +bn1Size              /* Benc          */
+              +mont1Size            /* montgomery(p) */
+
+              +pointSize            /* Genc          */
+              +bn2Size              /* cofactor      */
+              +mont2Size            /* montgomery(r) */
+
+              +bn2Size              /* private       */
+              +pointSize            /* public        */
+
+              +bn2Size              /* eph private   */
+              +pointSize            /* eph public    */
+
+              +primeSize            /* prime engine  */
+              +sscmBuffSize         /* sscm buffer   */
+              +listSize             /* temp big num  */
+              +(ALIGN_VAL-1);
+   }
+
+   return ippStsNoErr;
+}
+
+
+/*F*
+//    Name: ippsECCPInit
+//
+// Purpose: Init ECC context.
+//
+// Returns:                   Reason:
+//    ippStsNullPtrErr           NULL == pECC
+//
+//    ippStsSizeErr              2>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<<w;
+      int sscmBuffSize = nPrecomputed*(BITS_BNU_CHUNK(feBitSize)*3*sizeof(BNU_CHUNK_T)) +(CACHE_LINE_SIZE-1);
+
+      Ipp8u* ptr = (Ipp8u*)pECC;
+
+      /* size of BigNum over GF(p) */
+      ippsBigNumGetSize(gfeSize, &bn1Size);
+
+      /* size of BigNum over GF(r) */
+      ippsBigNumGetSize(ordSize, &bn2Size);
+
+      /* size of EC point over GF(p) */
+      ippsECCPPointGetSize(feBitSize, &pointSize);
+
+      /* size of montgomery engine over GF(p) */
+      ippsMontGetSize(ippBinaryMethod, BITS2WORD32_SIZE(feBitSize), &mont1Size);
+
+      /* size of montgomery engine over GF(r) */
+      ippsMontGetSize(ippBinaryMethod, BITS2WORD32_SIZE(feBitSize+1), &mont2Size);
+
+      /* size of prime engine */
+      ippsPrimeGetSize(feBitSize+1, &primeSize);
+
+      /* size of big num list */
+      /* listSize = cpBigNumListGetSize(feBitSize+1+32, BNLISTSIZE); */
+
+      /* allocate buffers */
+      ptr += sizeof(IppsECCPState);
+
+      ECP_METHOD(pECC)  = (ECCP_METHOD*)  (ptr);
+      ptr += sizeof(ECCP_METHOD);
+
+      ECP_PRIME(pECC)   = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+      ptr += bn1Size;
+      ECP_A(pECC)       = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+      ptr += bn1Size;
+      ECP_B(pECC)       = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+
+      ptr += bn1Size;
+      ECP_GX(pECC)      = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+      ptr += bn1Size;
+      ECP_GY(pECC)      = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+      ptr += bn1Size;
+      ECP_ORDER(pECC)   = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+
+      ptr += bn2Size;
+      ECP_AENC(pECC)    = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+      ptr += bn1Size;
+      ECP_BENC(pECC)    = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+      ptr += bn1Size;
+      ECP_PMONT(pECC)   = (IppsMontState*)     ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+
+      ptr += mont1Size;
+      ECP_GENC(pECC)    = (IppsECCPPointState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+      ptr += pointSize;
+      ECP_COFACTOR(pECC)= (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+      ptr += bn2Size;
+      ECP_RMONT(pECC)   = (IppsMontState*)     ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+
+      ptr += mont2Size;
+      ECP_PRIVATE(pECC) = (IppsBigNumState*)   ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+      ptr += bn2Size;
+      ECP_PUBLIC(pECC)  = (IppsECCPPointState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+
+      ptr += pointSize;
+      ECP_PRIVATE_E(pECC) = (IppsBigNumState*) ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+      ptr += bn2Size;
+      ECP_PUBLIC_E(pECC) =(IppsECCPPointState*)( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+
+      ptr += pointSize;
+      ECP_PRIMARY(pECC) = (IppsPrimeState*)    ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+      ptr += primeSize;
+
+      ECP_SCCMBUFF(pECC) = (Ipp8u*)            ( IPP_ALIGNED_PTR(ptr,CACHE_LINE_SIZE) );
+      ptr += sscmBuffSize;
+
+      ECP_BNCTX(pECC)   = (BigNumNode*)        ( IPP_ALIGNED_PTR(ptr,ALIGN_VAL) );
+
+      /* init buffers */
+      ippsBigNumInit(gfeSize,  ECP_PRIME(pECC));
+      ippsBigNumInit(gfeSize,  ECP_A(pECC));
+      ippsBigNumInit(gfeSize,  ECP_B(pECC));
+
+      ippsBigNumInit(gfeSize,  ECP_GX(pECC));
+      ippsBigNumInit(gfeSize,  ECP_GY(pECC));
+      ippsBigNumInit(ordSize,  ECP_ORDER(pECC));
+
+      ippsBigNumInit(gfeSize,  ECP_AENC(pECC));
+      ippsBigNumInit(gfeSize,  ECP_BENC(pECC));
+      ippsMontInit(ippBinaryMethod, BITS2WORD32_SIZE(feBitSize), ECP_PMONT(pECC));
+
+      ippsECCPPointInit(feBitSize, ECP_GENC(pECC));
+      ippsBigNumInit(ordSize,    ECP_COFACTOR(pECC));
+      ippsMontInit(ippBinaryMethod, BITS2WORD32_SIZE(feBitSize+1), ECP_RMONT(pECC));
+
+      ippsBigNumInit(ordSize,   ECP_PRIVATE(pECC));
+      ippsECCPPointInit(feBitSize,ECP_PUBLIC(pECC));
+
+      ippsBigNumInit(ordSize,   ECP_PRIVATE_E(pECC));
+      ippsECCPPointInit(feBitSize,ECP_PUBLIC_E(pECC));
+
+      cpBigNumListInit(feBitSize+1, BNLISTSIZE, ECP_BNCTX(pECC));
+   }
+
+   return ippStsNoErr;
+}

+ 93 - 93
external/crypto_px/sources/ippcp/src/pcpeccpmethod.h

@@ -1,93 +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.
-*
-*/
-
-#if !defined(_PCP_ECCP_METHOD_H)
-#define _PCP_ECCP_METHOD_H
-
-/*
-// Point Operation Prototypes
-*/
-struct eccp_method_st {
-    void (*SetPointProjective)(const IppsBigNumState* pX,
-                              const IppsBigNumState* pY,
-                              const IppsBigNumState* pZ,
-                              IppsECCPPointState* pPoint,
-                              const IppsECCPState* pECC);
-   void (*SetPointAffine)(const IppsBigNumState* pX,
-                          const IppsBigNumState* pY,
-                          IppsECCPPointState* pPoint,
-                          const IppsECCPState* pECC);
-
-   void (*GetPointAffine)(IppsBigNumState* pX,
-                          IppsBigNumState* pY,
-                          const IppsECCPPointState* pPoint,
-                          const IppsECCPState* pECC,
-                          BigNumNode* pList);
-
-   int (*IsPointOnCurve)(const IppsECCPPointState* pPoint,
-                         const IppsECCPState* pECC,
-                         BigNumNode* pList);
-
-   int (*ComparePoint)(const IppsECCPPointState* pP,
-                       const IppsECCPPointState* pQ,
-                       const IppsECCPState* pECC,
-                       BigNumNode* pList);
-   void (*NegPoint)(const IppsECCPPointState* pP,
-                    IppsECCPPointState* pR,
-                    const IppsECCPState* pECC);
-   void (*DblPoint)(const IppsECCPPointState* pP,
-                    IppsECCPPointState* pR,
-                    const IppsECCPState* pECC,
-                    BigNumNode* pList);
-   void (*AddPoint)(const IppsECCPPointState* pP,
-                    const IppsECCPPointState* pQ,
-                    IppsECCPPointState* pR,
-                    const IppsECCPState* pECC,
-                    BigNumNode* pList);
-   void (*MulPoint)(const IppsECCPPointState* pP,
-                    const IppsBigNumState* pK,
-                    IppsECCPPointState* pR,
-                    const IppsECCPState* pECC,
-                    BigNumNode* pList);
-   void (*MulBasePoint)(const IppsBigNumState* pK,
-                    IppsECCPPointState* pR,
-                    const IppsECCPState* pECC,
-                    BigNumNode* pList);
-   void (*ProdPoint)(const IppsECCPPointState* pP,
-                     const IppsBigNumState*    bnPscalar,
-                     const IppsECCPPointState* pQ,
-                     const IppsBigNumState*    bnQscalar,
-                     IppsECCPPointState* pR,
-                     const IppsECCPState* pECC,
-                     BigNumNode* pList);
-};
-
-#endif /* _PCP_ECCP_METHOD_H */
+/*
+* 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_METHOD_H)
+#define _PCP_ECCP_METHOD_H
+
+/*
+// Point Operation Prototypes
+*/
+struct eccp_method_st {
+    void (*SetPointProjective)(const IppsBigNumState* pX,
+                              const IppsBigNumState* pY,
+                              const IppsBigNumState* pZ,
+                              IppsECCPPointState* pPoint,
+                              const IppsECCPState* pECC);
+   void (*SetPointAffine)(const IppsBigNumState* pX,
+                          const IppsBigNumState* pY,
+                          IppsECCPPointState* pPoint,
+                          const IppsECCPState* pECC);
+
+   void (*GetPointAffine)(IppsBigNumState* pX,
+                          IppsBigNumState* pY,
+                          const IppsECCPPointState* pPoint,
+                          const IppsECCPState* pECC,
+                          BigNumNode* pList);
+
+   int (*IsPointOnCurve)(const IppsECCPPointState* pPoint,
+                         const IppsECCPState* pECC,
+                         BigNumNode* pList);
+
+   int (*ComparePoint)(const IppsECCPPointState* pP,
+                       const IppsECCPPointState* pQ,
+                       const IppsECCPState* pECC,
+                       BigNumNode* pList);
+   void (*NegPoint)(const IppsECCPPointState* pP,
+                    IppsECCPPointState* pR,
+                    const IppsECCPState* pECC);
+   void (*DblPoint)(const IppsECCPPointState* pP,
+                    IppsECCPPointState* pR,
+                    const IppsECCPState* pECC,
+                    BigNumNode* pList);
+   void (*AddPoint)(const IppsECCPPointState* pP,
+                    const IppsECCPPointState* pQ,
+                    IppsECCPPointState* pR,
+                    const IppsECCPState* pECC,
+                    BigNumNode* pList);
+   void (*MulPoint)(const IppsECCPPointState* pP,
+                    const IppsBigNumState* pK,
+                    IppsECCPPointState* pR,
+                    const IppsECCPState* pECC,
+                    BigNumNode* pList);
+   void (*MulBasePoint)(const IppsBigNumState* pK,
+                    IppsECCPPointState* pR,
+                    const IppsECCPState* pECC,
+                    BigNumNode* pList);
+   void (*ProdPoint)(const IppsECCPPointState* pP,
+                     const IppsBigNumState*    bnPscalar,
+                     const IppsECCPPointState* pQ,
+                     const IppsBigNumState*    bnQscalar,
+                     IppsECCPPointState* pR,
+                     const IppsECCPState* pECC,
+                     BigNumNode* pList);
+};
+
+#endif /* _PCP_ECCP_METHOD_H */

+ 133 - 133
external/crypto_px/sources/ippcp/src/pcpeccpmethodcom.h

@@ -1,133 +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.
-*
-*/
-
-#if !defined(_PCP_ECCPMETHODCOM_H)
-#define _PCP_ECCPMETHODCOM_H
-
-#include "pcpeccp.h"
-
-
-/*
-// Returns reference
-*/
-ECCP_METHOD* ECCPcom_Methods(void);
-
-/*
-// Copy
-*/
-void ECCP_CopyPoint(const IppsECCPPointState* pSrc, IppsECCPPointState* pDst);
-
-/*
-// Point Set. These operations implies
-// transformation of regular coordinates into internal format
-*/
-void ECCP_SetPointProjective(const IppsBigNumState* pX,
-                             const IppsBigNumState* pY,
-                             const IppsBigNumState* pZ,
-                             IppsECCPPointState* pPoint,
-                             const IppsECCPState* pECC);
-
-void ECCP_SetPointAffine(const IppsBigNumState* pX,
-                         const IppsBigNumState* pY,
-                         IppsECCPPointState* pPoint,
-                         const IppsECCPState* pECC);
-
-/*
-// Get Point. These operations implies
-// transformation of internal format coordinates into regular
-*/
-void ECCP_GetPointAffine(IppsBigNumState* pX,
-                         IppsBigNumState* pY,
-                         const IppsECCPPointState* pPoint,
-                         const IppsECCPState* pECC,
-                         BigNumNode* pList);
-
-/*
-// Set To Infinity
-*/
-void ECCP_SetPointToInfinity(IppsECCPPointState* pPoint);
-void ECCP_SetPointToAffineInfinity0(IppsBigNumState* pX, IppsBigNumState* pY);
-void ECCP_SetPointToAffineInfinity1(IppsBigNumState* pX, IppsBigNumState* pY);
-
-/*
-// Test Is At Infinity
-// Test is On EC
-*/
-int ECCP_IsPointAtInfinity(const IppsECCPPointState* pPoint);
-int ECCP_IsPointAtAffineInfinity0(const IppsBigNumState* pX, const IppsBigNumState* pY);
-int ECCP_IsPointAtAffineInfinity1(const IppsBigNumState* pX, const IppsBigNumState* pY);
-int ECCP_IsPointOnCurve(const IppsECCPPointState* pPoint,
-                        const IppsECCPState* pECC,
-                        BigNumNode* pList);
-
-/*
-// Operations
-*/
-int ECCP_ComparePoint(const IppsECCPPointState* pP,
-                      const IppsECCPPointState* pQ,
-                      const IppsECCPState* pECC,
-                      BigNumNode* pList);
-
-void ECCP_NegPoint(const IppsECCPPointState* pP,
-                   IppsECCPPointState* pR,
-                   const IppsECCPState* pECC);
-
-void ECCP_DblPoint(const IppsECCPPointState* pP,
-                   IppsECCPPointState* pR,
-                   const IppsECCPState* pECC,
-                   BigNumNode* pList);
-
-void ECCP_AddPoint(const IppsECCPPointState* pP,
-                   const IppsECCPPointState* pQ,
-                   IppsECCPPointState* pR,
-                   const IppsECCPState* pECC,
-                   BigNumNode* pList);
-
-void ECCP_MulPoint(const IppsECCPPointState* pP,
-                   const IppsBigNumState* pK,
-                   IppsECCPPointState* pR,
-                   const IppsECCPState* pECC,
-                   BigNumNode* pList);
-
-void ECCP_MulBasePoint(const IppsBigNumState* pK,
-                    IppsECCPPointState* pR,
-                    const IppsECCPState* pECC,
-                    BigNumNode* pList);
-
-void ECCP_ProdPoint(const IppsECCPPointState* pP,
-                    const IppsBigNumState*    bnPscalar,
-                    const IppsECCPPointState* pQ,
-                    const IppsBigNumState*    bnQscalar,
-                    IppsECCPPointState* pR,
-                    const IppsECCPState* pECC,
-                    BigNumNode* pList);
-
-#endif /* _PCP_ECCPMETHODCOM_H */
+/*
+* 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_ECCPMETHODCOM_H)
+#define _PCP_ECCPMETHODCOM_H
+
+#include "pcpeccp.h"
+
+
+/*
+// Returns reference
+*/
+ECCP_METHOD* ECCPcom_Methods(void);
+
+/*
+// Copy
+*/
+void ECCP_CopyPoint(const IppsECCPPointState* pSrc, IppsECCPPointState* pDst);
+
+/*
+// Point Set. These operations implies
+// transformation of regular coordinates into internal format
+*/
+void ECCP_SetPointProjective(const IppsBigNumState* pX,
+                             const IppsBigNumState* pY,
+                             const IppsBigNumState* pZ,
+                             IppsECCPPointState* pPoint,
+                             const IppsECCPState* pECC);
+
+void ECCP_SetPointAffine(const IppsBigNumState* pX,
+                         const IppsBigNumState* pY,
+                         IppsECCPPointState* pPoint,
+                         const IppsECCPState* pECC);
+
+/*
+// Get Point. These operations implies
+// transformation of internal format coordinates into regular
+*/
+void ECCP_GetPointAffine(IppsBigNumState* pX,
+                         IppsBigNumState* pY,
+                         const IppsECCPPointState* pPoint,
+                         const IppsECCPState* pECC,
+                         BigNumNode* pList);
+
+/*
+// Set To Infinity
+*/
+void ECCP_SetPointToInfinity(IppsECCPPointState* pPoint);
+void ECCP_SetPointToAffineInfinity0(IppsBigNumState* pX, IppsBigNumState* pY);
+void ECCP_SetPointToAffineInfinity1(IppsBigNumState* pX, IppsBigNumState* pY);
+
+/*
+// Test Is At Infinity
+// Test is On EC
+*/
+int ECCP_IsPointAtInfinity(const IppsECCPPointState* pPoint);
+int ECCP_IsPointAtAffineInfinity0(const IppsBigNumState* pX, const IppsBigNumState* pY);
+int ECCP_IsPointAtAffineInfinity1(const IppsBigNumState* pX, const IppsBigNumState* pY);
+int ECCP_IsPointOnCurve(const IppsECCPPointState* pPoint,
+                        const IppsECCPState* pECC,
+                        BigNumNode* pList);
+
+/*
+// Operations
+*/
+int ECCP_ComparePoint(const IppsECCPPointState* pP,
+                      const IppsECCPPointState* pQ,
+                      const IppsECCPState* pECC,
+                      BigNumNode* pList);
+
+void ECCP_NegPoint(const IppsECCPPointState* pP,
+                   IppsECCPPointState* pR,
+                   const IppsECCPState* pECC);
+
+void ECCP_DblPoint(const IppsECCPPointState* pP,
+                   IppsECCPPointState* pR,
+                   const IppsECCPState* pECC,
+                   BigNumNode* pList);
+
+void ECCP_AddPoint(const IppsECCPPointState* pP,
+                   const IppsECCPPointState* pQ,
+                   IppsECCPPointState* pR,
+                   const IppsECCPState* pECC,
+                   BigNumNode* pList);
+
+void ECCP_MulPoint(const IppsECCPPointState* pP,
+                   const IppsBigNumState* pK,
+                   IppsECCPPointState* pR,
+                   const IppsECCPState* pECC,
+                   BigNumNode* pList);
+
+void ECCP_MulBasePoint(const IppsBigNumState* pK,
+                    IppsECCPPointState* pR,
+                    const IppsECCPState* pECC,
+                    BigNumNode* pList);
+
+void ECCP_ProdPoint(const IppsECCPPointState* pP,
+                    const IppsBigNumState*    bnPscalar,
+                    const IppsECCPPointState* pQ,
+                    const IppsBigNumState*    bnQscalar,
+                    IppsECCPPointState* pR,
+                    const IppsECCPState* pECC,
+                    BigNumNode* pList);
+
+#endif /* _PCP_ECCPMETHODCOM_H */

+ 731 - 731
external/crypto_px/sources/ippcp/src/pcpeccpmethodcomca.c

@@ -1,731 +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 "pcpeccppoint.h"
-#include "pcpeccpmethod.h"
-#include "pcpeccpmethodcom.h"
-#include "pcppma.h"
-#include "pcpeccpsscm.h"
-
-
-static
-ECCP_METHOD ECCPcom = {
-   ECCP_SetPointProjective,
-   ECCP_SetPointAffine,
-   ECCP_GetPointAffine,
-
-   ECCP_IsPointOnCurve,
-
-   ECCP_ComparePoint,
-   ECCP_NegPoint,
-   ECCP_DblPoint,
-   ECCP_AddPoint,
-   ECCP_MulPoint,
-   ECCP_MulBasePoint,
-   ECCP_ProdPoint
-};
-
-
-/*
-// Returns reference
-*/
-ECCP_METHOD* ECCPcom_Methods(void)
-{
-   return &ECCPcom;
-}
-
-
-/*
-// Copy Point
-*/
-void ECCP_CopyPoint(const IppsECCPPointState* pSrc, IppsECCPPointState* pDst)
-{
-   cpBN_copy(ECP_POINT_X(pDst), ECP_POINT_X(pSrc));
-   cpBN_copy(ECP_POINT_Y(pDst), ECP_POINT_Y(pSrc));
-   cpBN_copy(ECP_POINT_Z(pDst), ECP_POINT_Z(pSrc));
-   ECP_POINT_AFFINE(pDst) = ECP_POINT_AFFINE(pSrc);
-}
-
-/*
-// ECCP_PoinSettProjective
-// Converts regular projective triplet (pX,pY,pZ) into pPoint
-// (see note above)
-*/
-void ECCP_SetPointProjective(const IppsBigNumState* pX,
-                             const IppsBigNumState* pY,
-                             const IppsBigNumState* pZ,
-                             IppsECCPPointState* pPoint,
-                             const IppsECCPState* pECC)
-{
-   IppsMontState* pMont = ECP_PMONT(pECC);
-
-   PMA_enc(ECP_POINT_X(pPoint), (IppsBigNumState*)pX, pMont);
-   PMA_enc(ECP_POINT_Y(pPoint), (IppsBigNumState*)pY, pMont);
-   PMA_enc(ECP_POINT_Z(pPoint), (IppsBigNumState*)pZ, pMont);
-   ECP_POINT_AFFINE(pPoint) = cpBN_cmp(pZ, BN_ONE_REF())==0;
-}
-
-/*
-// ECCP_PointAffineSet
-// Converts regular affine pair (pX,pY) into pPoint
-*/
-void ECCP_SetPointAffine(const IppsBigNumState* pX,
-                         const IppsBigNumState* pY,
-                         IppsECCPPointState* pPoint,
-                         const IppsECCPState* pECC)
-{
-   IppsMontState* pMont = ECP_PMONT(pECC);
-   PMA_enc(ECP_POINT_X(pPoint), (IppsBigNumState*)pX, pMont);
-   PMA_enc(ECP_POINT_Y(pPoint), (IppsBigNumState*)pY, pMont);
-   PMA_enc(ECP_POINT_Z(pPoint), (IppsBigNumState*)cpBN_OneRef(), pMont);
-   ECP_POINT_AFFINE(pPoint) = 1;
-}
-
-/*
-// ECCP_GetPointAffine
-//
-// Converts pPoint into regular affine pair (pX,pY)
-//
-// Note:
-// pPoint is not point at Infinity
-// transform  (X, Y, Z)  into  (x, y) = (X/Z^2, Y/Z^3)
-*/
-void ECCP_GetPointAffine(IppsBigNumState* pX, IppsBigNumState* pY,
-                         const IppsECCPPointState* pPoint,
-                         const IppsECCPState* pECC,
-                         BigNumNode* pList)
-{
-   IppsMontState* pMont = ECP_PMONT(pECC);
-
-   /* case Z == 1 */
-   if( ECP_POINT_AFFINE(pPoint) ) {
-      if(pX) {
-         PMA_dec(pX, ECP_POINT_X(pPoint), pMont);
-      }
-      if(pY) {
-         PMA_dec(pY, ECP_POINT_Y(pPoint), pMont);
-      }
-   }
-
-   /* case Z != 1 */
-   else {
-      IppsBigNumState* pT = cpBigNumListGet(&pList);
-      IppsBigNumState* pU = cpBigNumListGet(&pList);
-      IppsBigNumState* pModulo = ECP_PRIME(pECC);
-
-      /* decode Z */
-      PMA_dec(pU, ECP_POINT_Z(pPoint), pMont);
-      /* regular T = Z^-1 */
-      PMA_inv(pT, pU, pModulo);
-      /* montgomery U = Z^-1 */
-      PMA_enc(pU, pT, pMont);
-      /* regular T = Z^-2 */
-      PMA_mule(pT, pU, pT, pMont);
-
-      if(pX) {
-         PMA_mule(pX,pT, ECP_POINT_X(pPoint), pMont);
-      }
-      if(pY) {
-         /* regular U = Z^-3 */
-         PMA_mule(pU, pU, pT, pMont);
-         PMA_mule(pY,pU, ECP_POINT_Y(pPoint), pMont);
-      }
-   }
-}
-
-/*
-// ECCP_SetPointToInfinity
-// ECCP_SetPointToAffineInfinity0
-// ECCP_SetPointToAffineInfinity1
-//
-// Set point to Infinity
-*/
-void ECCP_SetPointToInfinity(IppsECCPPointState* pPoint)
-{
-   cpBN_zero(ECP_POINT_X(pPoint));
-   cpBN_zero(ECP_POINT_Y(pPoint));
-   cpBN_zero(ECP_POINT_Z(pPoint));
-   ECP_POINT_AFFINE(pPoint) = 0;
-}
-
-void ECCP_SetPointToAffineInfinity0(IppsBigNumState* pX, IppsBigNumState* pY)
-{
-   if(pX) cpBN_zero(pX);
-   if(pY) cpBN_zero(pY);
-}
-
-void ECCP_SetPointToAffineInfinity1(IppsBigNumState* pX, IppsBigNumState* pY)
-{
-   if(pX) cpBN_zero(pX);
-   if(pY) BN_Word(pY,1);
-}
-
-/*
-// ECCP_IsPointAtInfinity
-// ECCP_IsPointAtAffineInfinity0
-// ECCP_IsPointAtAffineInfinity1
-//
-// Test point is at Infinity
-*/
-int ECCP_IsPointAtInfinity(const IppsECCPPointState* pPoint)
-{
-   return IsZero_BN( ECP_POINT_Z(pPoint) );
-}
-
-int ECCP_IsPointAtAffineInfinity0(const IppsBigNumState* pX, const IppsBigNumState* pY)
-{
-   return IsZero_BN(pX) && IsZero_BN(pY);
-}
-
-int ECCP_IsPointAtAffineInfinity1(const IppsBigNumState* pX, const IppsBigNumState* pY)
-{
-   return IsZero_BN(pX) && !IsZero_BN(pY);
-}
-
-/*
-// ECCP_IsPointOnCurve
-//
-// Test point is lie on curve
-//
-// Note
-// We deal with equation: y^2 = x^3 + A*x + B.
-// Or in projective coordinates: Y^2 = X^3 + a*X*Z^4 + b*Z^6.
-// The point under test is given by projective triplet (X,Y,Z),
-// which represents actually (x,y) = (X/Z^2,Y/Z^3).
-*/
-int ECCP_IsPointOnCurve(const IppsECCPPointState* pPoint,
-                        const IppsECCPState* pECC,
-                        BigNumNode* pList)
-{
-   /* let think Infinity point is on the curve */
-   if( ECCP_IsPointAtInfinity(pPoint) )
-      return 1;
-
-   else {
-      IppsMontState*   pMont = ECP_PMONT(pECC);
-      IppsBigNumState* pR = cpBigNumListGet(&pList);
-      IppsBigNumState* pT = cpBigNumListGet(&pList);
-      IppsBigNumState* pModulo = ECP_PRIME(pECC);
-
-      PMA_sqre(pR, ECP_POINT_X(pPoint), pMont);      // R = X^3
-      PMA_mule(pR, pR, ECP_POINT_X(pPoint), pMont);
-
-      /* case Z != 1 */
-      if( !ECP_POINT_AFFINE(pPoint) ) {
-         IppsBigNumState* pZ4 = cpBigNumListGet(&pList);
-         IppsBigNumState* pZ6 = cpBigNumListGet(&pList);
-         PMA_sqre(pT,  ECP_POINT_Z(pPoint), pMont);  // Z^2
-         PMA_sqre(pZ4, pT,                pMont);  // Z^4
-         PMA_mule(pZ6, pZ4, pT,           pMont);  // Z^6
-
-         PMA_mule(pT, pZ4, ECP_POINT_X(pPoint), pMont); // T = X*Z^4
-         if( ECP_AMI3(pECC) ) {
-            IppsBigNumState* pU = cpBigNumListGet(&pList);
-               PMA_add(pU, pT, pT, pModulo);             // R = X^3 +a*X*Z^4
-               PMA_add(pU, pU, pT, pModulo);
-               PMA_sub(pR, pR, pU, pModulo);
-         }
-         else {
-            PMA_mule(pT, pT, ECP_AENC(pECC), pMont);  // R = X^3 +a*X*Z^4
-            PMA_add(pR, pR, pT, pModulo);
-         }
-           PMA_mule(pT, pZ6, ECP_BENC(pECC), pMont);    // R = X^3 +a*X*Z^4 + b*Z^6
-           PMA_add(pR, pR, pT, pModulo);
-
-      }
-      /* case Z == 1 */
-      else {
-         if( ECP_AMI3(pECC) ) {
-               PMA_add(pT, ECP_POINT_X(pPoint), ECP_POINT_X(pPoint), pModulo); // R = X^3 +a*X
-               PMA_add(pT, pT, ECP_POINT_X(pPoint), pModulo);
-               PMA_sub(pR, pR, pT, pModulo);
-         }
-         else {
-               PMA_mule(pT, ECP_POINT_X(pPoint), ECP_AENC(pECC), pMont);  // R = X^3 +a*X
-               PMA_add(pR, pR, pT, pModulo);
-         }
-         PMA_add(pR, pR, ECP_BENC(pECC), pModulo);                   // R = X^3 +a*X + b
-      }
-      PMA_sqre(pT, ECP_POINT_Y(pPoint), pMont);  // T = Y^2
-      return 0==cpBN_cmp(pR, pT);
-   }
-}
-
-/*
-// ECCP_ComparePoint
-//
-// Compare two points:
-//    returns 0 => 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<<w;
-
-      /* allocate temporary scalar */
-      IppsBigNumState* bnTN = cpBigNumListGet(&pList);
-      BNU_CHUNK_T* pTN = BN_NUMBER(bnTN);
-
-      int coordSize = BITS_BNU_CHUNK(ECP_GFEBITS(pECC));
-      IppsECCPPointState T;
-      ECP_POINT_X(&T) = cpBigNumListGet(&pList);
-      ECP_POINT_Y(&T) = cpBigNumListGet(&pList);
-      ECP_POINT_Z(&T) = cpBigNumListGet(&pList);
-      ECCP_SetPointToInfinity(&T);
-
-      /* init result */
-      ECCP_CopyPoint(pP, pR);
-      if( ippBigNumNEG == BN_SIGN(bnN) )
-         ECCP_NegPoint(pR, pR, pECC);
-
-      /* pre-compute auxiliary table t[] = {(2^w)*P, 1*P, 2*P, ..., (2^(w-1))*P} */
-      {
-         int n;
-         for(n=1; n<nPrecomputed; n++) {
-            ECCP_AddPoint(pR, &T, &T, pECC, pList);
-            cpECCP_ScramblePut(pScratchAligned+n, nPrecomputed, &T, coordSize);
-         }
-         ECCP_AddPoint(pR, &T, &T, pECC, pList);
-         cpECCP_ScramblePut(pScratchAligned, nPrecomputed, &T, coordSize);
-      }
-
-      /* copy scalar */
-      cpCpy_BNU(pTN, pN, nsN);
-      /* and convert it presentaion to avoid usage of O point */
-      scalarBitSize = cpECCP_ConvertRepresentation(pTN, scalarBitSize, w);
-
-      /* prepare temporary scalar for processing */
-      pTN[BITS_BNU_CHUNK(scalarBitSize)] = 0;
-      scalarBitSize = ((scalarBitSize+w-1)/w)*w;
-
-      /*
-      // scalar multiplication
-      */
-      {
-         Ipp32u dmask = nPrecomputed-1;
-
-         /* position (bit number) of the leftmost window */
-         int wPosition = scalarBitSize-w;
-
-         /* extract leftmost window value */
-         Ipp32u eChunk = *((Ipp32u*)((Ipp16u*)pTN + wPosition/BITSIZE(Ipp16u)));
-         int shift = wPosition & 0xF;
-         Ipp32u windowVal = (eChunk>>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<w; k++)
-               ECCP_DblPoint(pR, pR, pECC, pList);
-
-            /* extract next window value */
-            eChunk = *((Ipp32u*)((Ipp16u*)pTN + wPosition/BITSIZE(Ipp16u)));
-            shift = wPosition & 0xF;
-            windowVal = (eChunk>>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);
-}
+/*
+* 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"
+#include "pcppma.h"
+#include "pcpeccpsscm.h"
+
+
+static
+ECCP_METHOD ECCPcom = {
+   ECCP_SetPointProjective,
+   ECCP_SetPointAffine,
+   ECCP_GetPointAffine,
+
+   ECCP_IsPointOnCurve,
+
+   ECCP_ComparePoint,
+   ECCP_NegPoint,
+   ECCP_DblPoint,
+   ECCP_AddPoint,
+   ECCP_MulPoint,
+   ECCP_MulBasePoint,
+   ECCP_ProdPoint
+};
+
+
+/*
+// Returns reference
+*/
+ECCP_METHOD* ECCPcom_Methods(void)
+{
+   return &ECCPcom;
+}
+
+
+/*
+// Copy Point
+*/
+void ECCP_CopyPoint(const IppsECCPPointState* pSrc, IppsECCPPointState* pDst)
+{
+   cpBN_copy(ECP_POINT_X(pDst), ECP_POINT_X(pSrc));
+   cpBN_copy(ECP_POINT_Y(pDst), ECP_POINT_Y(pSrc));
+   cpBN_copy(ECP_POINT_Z(pDst), ECP_POINT_Z(pSrc));
+   ECP_POINT_AFFINE(pDst) = ECP_POINT_AFFINE(pSrc);
+}
+
+/*
+// ECCP_PoinSettProjective
+// Converts regular projective triplet (pX,pY,pZ) into pPoint
+// (see note above)
+*/
+void ECCP_SetPointProjective(const IppsBigNumState* pX,
+                             const IppsBigNumState* pY,
+                             const IppsBigNumState* pZ,
+                             IppsECCPPointState* pPoint,
+                             const IppsECCPState* pECC)
+{
+   IppsMontState* pMont = ECP_PMONT(pECC);
+
+   PMA_enc(ECP_POINT_X(pPoint), (IppsBigNumState*)pX, pMont);
+   PMA_enc(ECP_POINT_Y(pPoint), (IppsBigNumState*)pY, pMont);
+   PMA_enc(ECP_POINT_Z(pPoint), (IppsBigNumState*)pZ, pMont);
+   ECP_POINT_AFFINE(pPoint) = cpBN_cmp(pZ, BN_ONE_REF())==0;
+}
+
+/*
+// ECCP_PointAffineSet
+// Converts regular affine pair (pX,pY) into pPoint
+*/
+void ECCP_SetPointAffine(const IppsBigNumState* pX,
+                         const IppsBigNumState* pY,
+                         IppsECCPPointState* pPoint,
+                         const IppsECCPState* pECC)
+{
+   IppsMontState* pMont = ECP_PMONT(pECC);
+   PMA_enc(ECP_POINT_X(pPoint), (IppsBigNumState*)pX, pMont);
+   PMA_enc(ECP_POINT_Y(pPoint), (IppsBigNumState*)pY, pMont);
+   PMA_enc(ECP_POINT_Z(pPoint), (IppsBigNumState*)cpBN_OneRef(), pMont);
+   ECP_POINT_AFFINE(pPoint) = 1;
+}
+
+/*
+// ECCP_GetPointAffine
+//
+// Converts pPoint into regular affine pair (pX,pY)
+//
+// Note:
+// pPoint is not point at Infinity
+// transform  (X, Y, Z)  into  (x, y) = (X/Z^2, Y/Z^3)
+*/
+void ECCP_GetPointAffine(IppsBigNumState* pX, IppsBigNumState* pY,
+                         const IppsECCPPointState* pPoint,
+                         const IppsECCPState* pECC,
+                         BigNumNode* pList)
+{
+   IppsMontState* pMont = ECP_PMONT(pECC);
+
+   /* case Z == 1 */
+   if( ECP_POINT_AFFINE(pPoint) ) {
+      if(pX) {
+         PMA_dec(pX, ECP_POINT_X(pPoint), pMont);
+      }
+      if(pY) {
+         PMA_dec(pY, ECP_POINT_Y(pPoint), pMont);
+      }
+   }
+
+   /* case Z != 1 */
+   else {
+      IppsBigNumState* pT = cpBigNumListGet(&pList);
+      IppsBigNumState* pU = cpBigNumListGet(&pList);
+      IppsBigNumState* pModulo = ECP_PRIME(pECC);
+
+      /* decode Z */
+      PMA_dec(pU, ECP_POINT_Z(pPoint), pMont);
+      /* regular T = Z^-1 */
+      PMA_inv(pT, pU, pModulo);
+      /* montgomery U = Z^-1 */
+      PMA_enc(pU, pT, pMont);
+      /* regular T = Z^-2 */
+      PMA_mule(pT, pU, pT, pMont);
+
+      if(pX) {
+         PMA_mule(pX,pT, ECP_POINT_X(pPoint), pMont);
+      }
+      if(pY) {
+         /* regular U = Z^-3 */
+         PMA_mule(pU, pU, pT, pMont);
+         PMA_mule(pY,pU, ECP_POINT_Y(pPoint), pMont);
+      }
+   }
+}
+
+/*
+// ECCP_SetPointToInfinity
+// ECCP_SetPointToAffineInfinity0
+// ECCP_SetPointToAffineInfinity1
+//
+// Set point to Infinity
+*/
+void ECCP_SetPointToInfinity(IppsECCPPointState* pPoint)
+{
+   cpBN_zero(ECP_POINT_X(pPoint));
+   cpBN_zero(ECP_POINT_Y(pPoint));
+   cpBN_zero(ECP_POINT_Z(pPoint));
+   ECP_POINT_AFFINE(pPoint) = 0;
+}
+
+void ECCP_SetPointToAffineInfinity0(IppsBigNumState* pX, IppsBigNumState* pY)
+{
+   if(pX) cpBN_zero(pX);
+   if(pY) cpBN_zero(pY);
+}
+
+void ECCP_SetPointToAffineInfinity1(IppsBigNumState* pX, IppsBigNumState* pY)
+{
+   if(pX) cpBN_zero(pX);
+   if(pY) BN_Word(pY,1);
+}
+
+/*
+// ECCP_IsPointAtInfinity
+// ECCP_IsPointAtAffineInfinity0
+// ECCP_IsPointAtAffineInfinity1
+//
+// Test point is at Infinity
+*/
+int ECCP_IsPointAtInfinity(const IppsECCPPointState* pPoint)
+{
+   return IsZero_BN( ECP_POINT_Z(pPoint) );
+}
+
+int ECCP_IsPointAtAffineInfinity0(const IppsBigNumState* pX, const IppsBigNumState* pY)
+{
+   return IsZero_BN(pX) && IsZero_BN(pY);
+}
+
+int ECCP_IsPointAtAffineInfinity1(const IppsBigNumState* pX, const IppsBigNumState* pY)
+{
+   return IsZero_BN(pX) && !IsZero_BN(pY);
+}
+
+/*
+// ECCP_IsPointOnCurve
+//
+// Test point is lie on curve
+//
+// Note
+// We deal with equation: y^2 = x^3 + A*x + B.
+// Or in projective coordinates: Y^2 = X^3 + a*X*Z^4 + b*Z^6.
+// The point under test is given by projective triplet (X,Y,Z),
+// which represents actually (x,y) = (X/Z^2,Y/Z^3).
+*/
+int ECCP_IsPointOnCurve(const IppsECCPPointState* pPoint,
+                        const IppsECCPState* pECC,
+                        BigNumNode* pList)
+{
+   /* let think Infinity point is on the curve */
+   if( ECCP_IsPointAtInfinity(pPoint) )
+      return 1;
+
+   else {
+      IppsMontState*   pMont = ECP_PMONT(pECC);
+      IppsBigNumState* pR = cpBigNumListGet(&pList);
+      IppsBigNumState* pT = cpBigNumListGet(&pList);
+      IppsBigNumState* pModulo = ECP_PRIME(pECC);
+
+      PMA_sqre(pR, ECP_POINT_X(pPoint), pMont);      // R = X^3
+      PMA_mule(pR, pR, ECP_POINT_X(pPoint), pMont);
+
+      /* case Z != 1 */
+      if( !ECP_POINT_AFFINE(pPoint) ) {
+         IppsBigNumState* pZ4 = cpBigNumListGet(&pList);
+         IppsBigNumState* pZ6 = cpBigNumListGet(&pList);
+         PMA_sqre(pT,  ECP_POINT_Z(pPoint), pMont);  // Z^2
+         PMA_sqre(pZ4, pT,                pMont);  // Z^4
+         PMA_mule(pZ6, pZ4, pT,           pMont);  // Z^6
+
+         PMA_mule(pT, pZ4, ECP_POINT_X(pPoint), pMont); // T = X*Z^4
+         if( ECP_AMI3(pECC) ) {
+            IppsBigNumState* pU = cpBigNumListGet(&pList);
+               PMA_add(pU, pT, pT, pModulo);             // R = X^3 +a*X*Z^4
+               PMA_add(pU, pU, pT, pModulo);
+               PMA_sub(pR, pR, pU, pModulo);
+         }
+         else {
+            PMA_mule(pT, pT, ECP_AENC(pECC), pMont);  // R = X^3 +a*X*Z^4
+            PMA_add(pR, pR, pT, pModulo);
+         }
+           PMA_mule(pT, pZ6, ECP_BENC(pECC), pMont);    // R = X^3 +a*X*Z^4 + b*Z^6
+           PMA_add(pR, pR, pT, pModulo);
+
+      }
+      /* case Z == 1 */
+      else {
+         if( ECP_AMI3(pECC) ) {
+               PMA_add(pT, ECP_POINT_X(pPoint), ECP_POINT_X(pPoint), pModulo); // R = X^3 +a*X
+               PMA_add(pT, pT, ECP_POINT_X(pPoint), pModulo);
+               PMA_sub(pR, pR, pT, pModulo);
+         }
+         else {
+               PMA_mule(pT, ECP_POINT_X(pPoint), ECP_AENC(pECC), pMont);  // R = X^3 +a*X
+               PMA_add(pR, pR, pT, pModulo);
+         }
+         PMA_add(pR, pR, ECP_BENC(pECC), pModulo);                   // R = X^3 +a*X + b
+      }
+      PMA_sqre(pT, ECP_POINT_Y(pPoint), pMont);  // T = Y^2
+      return 0==cpBN_cmp(pR, pT);
+   }
+}
+
+/*
+// ECCP_ComparePoint
+//
+// Compare two points:
+//    returns 0 => 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<<w;
+
+      /* allocate temporary scalar */
+      IppsBigNumState* bnTN = cpBigNumListGet(&pList);
+      BNU_CHUNK_T* pTN = BN_NUMBER(bnTN);
+
+      int coordSize = BITS_BNU_CHUNK(ECP_GFEBITS(pECC));
+      IppsECCPPointState T;
+      ECP_POINT_X(&T) = cpBigNumListGet(&pList);
+      ECP_POINT_Y(&T) = cpBigNumListGet(&pList);
+      ECP_POINT_Z(&T) = cpBigNumListGet(&pList);
+      ECCP_SetPointToInfinity(&T);
+
+      /* init result */
+      ECCP_CopyPoint(pP, pR);
+      if( ippBigNumNEG == BN_SIGN(bnN) )
+         ECCP_NegPoint(pR, pR, pECC);
+
+      /* pre-compute auxiliary table t[] = {(2^w)*P, 1*P, 2*P, ..., (2^(w-1))*P} */
+      {
+         int n;
+         for(n=1; n<nPrecomputed; n++) {
+            ECCP_AddPoint(pR, &T, &T, pECC, pList);
+            cpECCP_ScramblePut(pScratchAligned+n, nPrecomputed, &T, coordSize);
+         }
+         ECCP_AddPoint(pR, &T, &T, pECC, pList);
+         cpECCP_ScramblePut(pScratchAligned, nPrecomputed, &T, coordSize);
+      }
+
+      /* copy scalar */
+      cpCpy_BNU(pTN, pN, nsN);
+      /* and convert it presentaion to avoid usage of O point */
+      scalarBitSize = cpECCP_ConvertRepresentation(pTN, scalarBitSize, w);
+
+      /* prepare temporary scalar for processing */
+      pTN[BITS_BNU_CHUNK(scalarBitSize)] = 0;
+      scalarBitSize = ((scalarBitSize+w-1)/w)*w;
+
+      /*
+      // scalar multiplication
+      */
+      {
+         Ipp32u dmask = nPrecomputed-1;
+
+         /* position (bit number) of the leftmost window */
+         int wPosition = scalarBitSize-w;
+
+         /* extract leftmost window value */
+         Ipp32u eChunk = *((Ipp32u*)((Ipp16u*)pTN + wPosition/BITSIZE(Ipp16u)));
+         int shift = wPosition & 0xF;
+         Ipp32u windowVal = (eChunk>>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<w; k++)
+               ECCP_DblPoint(pR, pR, pECC, pList);
+
+            /* extract next window value */
+            eChunk = *((Ipp32u*)((Ipp16u*)pTN + wPosition/BITSIZE(Ipp16u)));
+            shift = wPosition & 0xF;
+            windowVal = (eChunk>>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);
+}

+ 60 - 60
external/crypto_px/sources/ippcp/src/pcpeccppoint.h

@@ -1,60 +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 */
+/*
+* 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 */

+ 128 - 128
external/crypto_px/sources/ippcp/src/pcpeccppointca.c

@@ -1,128 +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;
-}
+/*
+* 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;
+}

+ 476 - 476
external/crypto_px/sources/ippcp/src/pcpeccppointopca.c

@@ -1,476 +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;
-}
+/*
+* 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;
+}

+ 89 - 89
external/crypto_px/sources/ippcp/src/pcpeccppublickeyca.c

@@ -1,89 +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(!((0<cpBN_tst(pPrivate)) && (0>cpBN_cmp(pPrivate, ECP_ORDER(pECC))) ), ippStsIvalidPrivateKey);
-
-   /* calculates public key */
-   ECP_METHOD(pECC)->MulBasePoint(pPrivate, pPublic, pECC, ECP_BNCTX(pECC));
-
-   return ippStsNoErr;
-}
+/*
+* 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(!((0<cpBN_tst(pPrivate)) && (0>cpBN_cmp(pPrivate, ECP_ORDER(pECC))) ), ippStsIvalidPrivateKey);
+
+   /* calculates public key */
+   ECP_METHOD(pECC)->MulBasePoint(pPrivate, pPublic, pECC, ECP_BNCTX(pECC));
+
+   return ippStsNoErr;
+}

+ 116 - 116
external/crypto_px/sources/ippcp/src/pcpeccpsecretdhca.c

@@ -1,116 +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)<ECP_GFEBITS(pECC)), ippStsRangeErr);
-
-   {
-      BigNumNode* pList = ECP_BNCTX(pECC);
-      IppsECCPPointState Tmp;
-      ECP_POINT_X(&Tmp) = cpBigNumListGet(&pList);
-      ECP_POINT_Y(&Tmp) = cpBigNumListGet(&pList);
-      ECP_POINT_Z(&Tmp) = cpBigNumListGet(&pList);
-
-      /* Tmp = (own)_private * (alien)_public */
-      ECP_METHOD(pECC)->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;
-      }
-   }
-}
+/*
+* 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)<ECP_GFEBITS(pECC)), ippStsRangeErr);
+
+   {
+      BigNumNode* pList = ECP_BNCTX(pECC);
+      IppsECCPPointState Tmp;
+      ECP_POINT_X(&Tmp) = cpBigNumListGet(&pList);
+      ECP_POINT_Y(&Tmp) = cpBigNumListGet(&pList);
+      ECP_POINT_Z(&Tmp) = cpBigNumListGet(&pList);
+
+      /* Tmp = (own)_private * (alien)_public */
+      ECP_METHOD(pECC)->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;
+      }
+   }
+}

+ 105 - 105
external/crypto_px/sources/ippcp/src/pcpeccpsetkeyca.c

@@ -1,105 +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;
-   }
-}
+/*
+* 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;
+   }
+}

+ 149 - 149
external/crypto_px/sources/ippcp/src/pcpeccpsigndsaca.c

@@ -1,149 +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)<ECP_ORDBITS(pECC)), ippStsRangeErr);
-   IPP_BADARG_RET((BN_ROOM(pSignY)*BITSIZE(BNU_CHUNK_T)<ECP_ORDBITS(pECC)), ippStsRangeErr);
-
-   {
-      IppsMontState* rMont = ECP_RMONT(pECC);
-      IppsBigNumState* pOrder = ECP_ORDER(pECC);
-
-      BigNumNode* pList = ECP_BNCTX(pECC);
-      IppsBigNumState* pTmp = cpBigNumListGet(&pList);
-
-      /* extract ephemeral public key (X component only) */
-      ECP_METHOD(pECC)->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;
-   }
-}
+/*
+* 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)<ECP_ORDBITS(pECC)), ippStsRangeErr);
+   IPP_BADARG_RET((BN_ROOM(pSignY)*BITSIZE(BNU_CHUNK_T)<ECP_ORDBITS(pECC)), ippStsRangeErr);
+
+   {
+      IppsMontState* rMont = ECP_RMONT(pECC);
+      IppsBigNumState* pOrder = ECP_ORDER(pECC);
+
+      BigNumNode* pList = ECP_BNCTX(pECC);
+      IppsBigNumState* pTmp = cpBigNumListGet(&pList);
+
+      /* extract ephemeral public key (X component only) */
+      ECP_METHOD(pECC)->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;
+   }
+}

+ 161 - 161
external/crypto_px/sources/ippcp/src/pcpeccpsscm.c

@@ -1,161 +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<<w) -1;
-   int n_ops = div_upper(bitsize, w) + n_overhead;
-   return n_ops;
-}
-
-int cpECCP_OptimalWinSize(int bitsize)
-{
-#define LIMIT (LOG2_CACHE_LINE_SIZE)
-   int w_opt = 1;
-   int n_opt = getNumOperations(bitsize, w_opt);
-   int w_trial;
-   for(w_trial=w_opt+1; w_trial<=LIMIT; w_trial++) {
-      int n_trial = getNumOperations(bitsize, w_trial);
-      if(n_trial>=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<<w;
-   Ipp32u digitMask = base-1;
-   int i;
-
-   cpSize nsR = BITS2WORD32_SIZE(inpBits);
-   pR[nsR] = 0;               // expand 32-bit representation of input
-   for(i=0; i<inpBits; i+=w) {
-      cpSize chunkIdx = i/BITSIZE(Ipp16u);
-      Ipp32u chunk = ((Ipp32u*)(pR16+chunkIdx))[0];
-      int  digitShift = i % BITSIZE(Ipp16u);
-      Ipp32u digit = (chunk>>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; i<coordSize; i++, pScrambleEntry+=proposity)
-      *pScrambleEntry = pCoord[i];
-
-   pCoord = (Ipp8u*)pY;
-   for(i=0; i<coordSize; i++, pScrambleEntry+=proposity)
-      *pScrambleEntry = pCoord[i];
-
-   pCoord = (Ipp8u*)pZ;
-   for(i=0; i<coordSize; i++, pScrambleEntry+=proposity)
-      *pScrambleEntry = pCoord[i];
-}
-
-void cpECCP_ScrambleGet(IppsECCPPointState* pPoint, cpSize coordLen,
-                      const Ipp8u* pScrambleEntry, int proposity)
-{
-   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);
-   int i;
-
-   Ipp8u* pCoord = (Ipp8u*)pX;
-   for(i=0; i<coordSize; i++, pScrambleEntry+=proposity)
-      pCoord[i] = *pScrambleEntry;
-
-   pCoord = (Ipp8u*)pY;
-   for(i=0; i<coordSize; i++, pScrambleEntry+=proposity)
-      pCoord[i] = *pScrambleEntry;
-
-   pCoord = (Ipp8u*)pZ;
-   for(i=0; i<coordSize; i++, pScrambleEntry+=proposity)
-      pCoord[i] = *pScrambleEntry;
-
-   i = coordLen;
-   FIX_BNU(pX, i);
-   BN_SIZE(ECP_POINT_X(pPoint)) = i;
-
-   i = coordLen;
-   FIX_BNU(pY, i);
-   BN_SIZE(ECP_POINT_Y(pPoint)) = i;
-
-   i = coordLen;
-   FIX_BNU(pZ, i);
-   BN_SIZE(ECP_POINT_Z(pPoint)) = i;
-}
+/*
+* 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<<w) -1;
+   int n_ops = div_upper(bitsize, w) + n_overhead;
+   return n_ops;
+}
+
+int cpECCP_OptimalWinSize(int bitsize)
+{
+#define LIMIT (LOG2_CACHE_LINE_SIZE)
+   int w_opt = 1;
+   int n_opt = getNumOperations(bitsize, w_opt);
+   int w_trial;
+   for(w_trial=w_opt+1; w_trial<=LIMIT; w_trial++) {
+      int n_trial = getNumOperations(bitsize, w_trial);
+      if(n_trial>=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<<w;
+   Ipp32u digitMask = base-1;
+   int i;
+
+   cpSize nsR = BITS2WORD32_SIZE(inpBits);
+   pR[nsR] = 0;               // expand 32-bit representation of input
+   for(i=0; i<inpBits; i+=w) {
+      cpSize chunkIdx = i/BITSIZE(Ipp16u);
+      Ipp32u chunk = ((Ipp32u*)(pR16+chunkIdx))[0];
+      int  digitShift = i % BITSIZE(Ipp16u);
+      Ipp32u digit = (chunk>>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; i<coordSize; i++, pScrambleEntry+=proposity)
+      *pScrambleEntry = pCoord[i];
+
+   pCoord = (Ipp8u*)pY;
+   for(i=0; i<coordSize; i++, pScrambleEntry+=proposity)
+      *pScrambleEntry = pCoord[i];
+
+   pCoord = (Ipp8u*)pZ;
+   for(i=0; i<coordSize; i++, pScrambleEntry+=proposity)
+      *pScrambleEntry = pCoord[i];
+}
+
+void cpECCP_ScrambleGet(IppsECCPPointState* pPoint, cpSize coordLen,
+                      const Ipp8u* pScrambleEntry, int proposity)
+{
+   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);
+   int i;
+
+   Ipp8u* pCoord = (Ipp8u*)pX;
+   for(i=0; i<coordSize; i++, pScrambleEntry+=proposity)
+      pCoord[i] = *pScrambleEntry;
+
+   pCoord = (Ipp8u*)pY;
+   for(i=0; i<coordSize; i++, pScrambleEntry+=proposity)
+      pCoord[i] = *pScrambleEntry;
+
+   pCoord = (Ipp8u*)pZ;
+   for(i=0; i<coordSize; i++, pScrambleEntry+=proposity)
+      pCoord[i] = *pScrambleEntry;
+
+   i = coordLen;
+   FIX_BNU(pX, i);
+   BN_SIZE(ECP_POINT_X(pPoint)) = i;
+
+   i = coordLen;
+   FIX_BNU(pY, i);
+   BN_SIZE(ECP_POINT_Y(pPoint)) = i;
+
+   i = coordLen;
+   FIX_BNU(pZ, i);
+   BN_SIZE(ECP_POINT_Z(pPoint)) = i;
+}

+ 49 - 49
external/crypto_px/sources/ippcp/src/pcpeccpsscm.h

@@ -1,49 +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(_PCP_ECCP_SSCM_H)
-#define _PCP_ECCP_SSCM_H
-
-#include "pcpeccppoint.h"
-
-int cpECCP_OptimalWinSize(int bitSize);
-
-int cpECCP_ConvertRepresentation(BNU_CHUNK_T* pR, int inpBits, int w);
-
-/*
-// 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, int coordLen);
-void cpECCP_ScrambleGet(IppsECCPPointState* pPoint, int coordLen, const Ipp8u* pScrambleEntry, int proposity);
-
-#endif /* _PCP_ECCP_SSCM_H */
+/*
+* 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_SSCM_H)
+#define _PCP_ECCP_SSCM_H
+
+#include "pcpeccppoint.h"
+
+int cpECCP_OptimalWinSize(int bitSize);
+
+int cpECCP_ConvertRepresentation(BNU_CHUNK_T* pR, int inpBits, int w);
+
+/*
+// 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, int coordLen);
+void cpECCP_ScrambleGet(IppsECCPPointState* pPoint, int coordLen, const Ipp8u* pScrambleEntry, int proposity);
+
+#endif /* _PCP_ECCP_SSCM_H */

+ 324 - 324
external/crypto_px/sources/ippcp/src/pcpeccpstdca.c

@@ -1,324 +1,324 @@
-/*
-* 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"
-
-
-/* Recommended Parameters secp112r1 */
-const Ipp32u secp112r1_p[] = { /* (2^128 -3)/76439 */
-   0xBEAD208B, 0x5E668076, 0x2ABF62E3, 0xDB7C};
-const Ipp32u secp112r1_a[] = {
-   0xBEAD2088, 0x5E668076, 0x2ABF62E3, 0xDB7C};
-const Ipp32u secp112r1_b[] = {
-   0x11702B22, 0x16EEDE89, 0xF8BA0439, 0x659E};
-const Ipp32u secp112r1_gx[] = {
-   0xF9C2F098, 0x5EE76B55, 0x7239995A, 0x0948};
-const Ipp32u secp112r1_gy[] = {
-   0x0FF77500, 0xC0A23E0E, 0xE5AF8724, 0xA89C};
-const Ipp32u secp112r1_r[] = {
-   0xAC6561C5, 0x5E7628DF, 0x2ABF62E3, 0xDB7C};
-Ipp32u secp112r1_h = 1;
-
-/* Recommended Parameters secp112r2 */
-const Ipp32u secp112r2_p[] = { /* (2^128 -3)/76439 */
-   0xBEAD208B, 0x5E668076, 0x2ABF62E3, 0xDB7C};
-const Ipp32u secp112r2_a[] = {
-   0x5C0EF02C, 0x8A0AAAF6, 0xC24C05F3, 0x6127};
-const Ipp32u secp112r2_b[] = {
-   0x4C85D709, 0xED74FCC3, 0xF1815DB5, 0x51DE};
-const Ipp32u secp112r2_gx[] = {
-   0xD0928643, 0xB4E1649D, 0x0AB5E892, 0x4BA3};
-const Ipp32u secp112r2_gy[] = {
-   0x6E956E97, 0x3747DEF3, 0x46F5882E, 0xADCD};
-const Ipp32u secp112r2_r[] = {
-   0x0520D04B, 0xD7597CA1, 0x0AAFD8B8, 0x36DF};
-Ipp32u secp112r2_h = 4;
-
-/* Recommended Parameters secp128r1 */
-const Ipp32u h_secp128r1_p[] = { /* halpf of secp128r1_p */
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x7FFFFFFE};
-
-const Ipp32u secp128r1_p[] = { // 2^128 -2^97 -1
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFD, 0x0, 0x0};
-const Ipp32u secp128r1_a[] = {
-   0xFFFFFFFC, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFD};
-const Ipp32u secp128r1_b[] = {
-   0x2CEE5ED3, 0xD824993C, 0x1079F43D, 0xE87579C1};
-const Ipp32u secp128r1_gx[] = {
-   0xA52C5B86, 0x0C28607C, 0x8B899B2D, 0x161FF752};
-const Ipp32u secp128r1_gy[] = {
-   0xDDED7A83, 0xC02DA292, 0x5BAFEB13, 0xCF5AC839};
-const Ipp32u secp128r1_r[] = {
-   0x9038A115, 0x75A30D1B, 0x00000000, 0xFFFFFFFE};
-Ipp32u secp128r1_h = 1;
-
-/* Recommended Parameters secp128r2 */
-const Ipp32u secp128r2_p[] = { /* 2^128 -2^97 -1 */
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFD, 0x0, 0x0};
-const Ipp32u secp128r2_a[] = {
-   0xBFF9AEE1, 0xBF59CC9B, 0xD1B3BBFE, 0xD6031998};
-const Ipp32u secp128r2_b[] = {
-   0xBB6D8A5D, 0xDC2C6558, 0x80D02919, 0x5EEEFCA3};
-const Ipp32u secp128r2_gx[] = {
-   0xCDEBC140, 0xE6FB32A7, 0x5E572983, 0x7B6AA5D8};
-const Ipp32u secp128r2_gy[] = {
-   0x5FC34B44, 0x7106FE80, 0x894D3AEE, 0x27B6916A};
-const Ipp32u secp128r2_r[] = {
-   0x0613B5A3, 0xBE002472, 0x7FFFFFFF, 0x3FFFFFFF};
-Ipp32u secp128r2_h = 4;
-
-/* Recommended Parameters secp160r1 */
-const Ipp32u secp160r1_p[] = { /* 2^160 -2^31 -1 */
-   0x7FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
-const Ipp32u secp160r1_a[] = {
-   0x7FFFFFFC, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
-const Ipp32u secp160r1_b[] = {
-   0xC565FA45, 0x81D4D4AD, 0x65ACF89F, 0x54BD7A8B, 0x1C97BEFC};
-const Ipp32u secp160r1_gx[] = {
-   0x13CBFC82, 0x68C38BB9, 0x46646989, 0x8EF57328, 0x4A96B568};
-const Ipp32u secp160r1_gy[] = {
-   0x7AC5FB32, 0x04235137, 0x59DCC912, 0x3168947D, 0x23A62855};
-const Ipp32u secp160r1_r[] = {
-   0xCA752257, 0xF927AED3, 0x0001F4C8, 0x00000000, 0x00000000, 0x1};
-Ipp32u secp160r1_h = 1;
-
-/* Recommended Parameters secp160r2 */
-const Ipp32u secp160r2_p[] = { /* 2^160 -2^32 -2^14 -2^12 -2^9 -2^8 -2^7 -2^2 -1 */
-   0xFFFFAC73, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
-const Ipp32u secp160r2_a[] = {
-   0xFFFFAC70, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
-const Ipp32u secp160r2_b[] = {
-   0xF50388BA, 0x04664D5A, 0xAB572749, 0xFB59EB8B, 0xB4E134D3};
-const Ipp32u secp160r2_gx[] = {
-   0x3144CE6D, 0x30F7199D, 0x1F4FF11B, 0x293A117E, 0x52DCB034};
-const Ipp32u secp160r2_gy[] = {
-   0xA7D43F2E, 0xF9982CFE, 0xE071FA0D, 0xE331F296, 0xFEAFFEF2};
-const Ipp32u secp160r2_r[] = {
-   0xF3A1A16B, 0xE786A818, 0x0000351E, 0x00000000, 0x00000000, 0x1};
-Ipp32u secp160r2_h = 1;
-
-/* Recommended Parameters secp192r1 */
-const Ipp32u h_secp192r1_p[] = { /* half of secp192r1_p */
-   0xFFFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x7FFFFFFF};
-
-const Ipp32u secp192r1_p[] = { /* 2^192 -2^64 -1 */
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0, 0x0};
-const Ipp32u secp192r1_a[] = {
-   0xFFFFFFFC, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
-const Ipp32u secp192r1_b[] = {
-   0xC146B9B1, 0xFEB8DEEC, 0x72243049, 0x0FA7E9AB, 0xE59C80E7, 0x64210519};
-const Ipp32u secp192r1_gx[] = {
-   0x82FF1012, 0xF4FF0AFD, 0x43A18800, 0x7CBF20EB, 0xB03090F6, 0x188DA80E};
-const Ipp32u secp192r1_gy[] = {
-   0x1E794811, 0x73F977A1, 0x6B24CDD5, 0x631011ED, 0xFFC8DA78, 0x07192B95};
-const Ipp32u secp192r1_r[] = {
-   0xB4D22831, 0x146BC9B1, 0x99DEF836, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
-Ipp32u secp192r1_h = 1;
-
-/* Recommended Parameters secp224r1 */
-const Ipp32u h_secp224r1_p[] = { /* half of secp224r1_p */
-   0x00000000, 0x00000000, 0x80000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
-   0x7FFFFFFF, 0x0};
-
-const Ipp32u secp224r1_p[] = { /* 2^224 -2^96 +1 */
-   0x00000001, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
-   0xFFFFFFFF, 0x0};
-const Ipp32u secp224r1_a[] = {
-   0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF,
-   0xFFFFFFFF};
-const Ipp32u secp224r1_b[] = {
-   0x2355FFB4, 0x270B3943, 0xD7BFD8BA, 0x5044B0B7, 0xF5413256, 0x0C04B3AB,
-   0xB4050A85};
-const Ipp32u secp224r1_gx[] = {
-   0x115C1D21, 0x343280D6, 0x56C21122, 0x4A03C1D3, 0x321390B9, 0x6BB4BF7F,
-   0xB70E0CBD};
-const Ipp32u secp224r1_gy[] = {
-   0x85007E34, 0x44D58199, 0x5A074764, 0xCD4375A0, 0x4C22DFE6, 0xB5F723FB,
-   0xBD376388};
-const Ipp32u secp224r1_r[] = {
-   0x5C5C2A3D, 0x13DD2945, 0xE0B8F03E, 0xFFFF16A2, 0xFFFFFFFF, 0xFFFFFFFF,
-   0xFFFFFFFF};
-Ipp32u secp224r1_h = 1;
-
-/* Recommended Parameters secp256r1 */
-const Ipp32u h_secp256r1_p[] = { /* half of secp256r1_p */
-   0xFFFFFFFF, 0xFFFFFFFF, 0x7FFFFFFF, 0x00000000, 0x00000000, 0x80000000,
-   0x80000000, 0x7FFFFFFF};
-
-const Ipp32u secp256r1_p[] = { /* 2^256 -2^224 +2^192 +2^96 -1 */
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000,
-   0x00000001, 0xFFFFFFFF, 0x0, 0x0};
-const Ipp32u secp256r1_a[] = {
-   0xFFFFFFFC, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000,
-   0x00000001, 0xFFFFFFFF};
-const Ipp32u secp256r1_b[] = {
-   0x27D2604B, 0x3BCE3C3E, 0xCC53B0F6, 0x651D06B0, 0x769886BC, 0xB3EBBD55,
-   0xAA3A93E7, 0x5AC635D8};
-const Ipp32u secp256r1_gx[] = {
-   0xD898C296, 0xF4A13945, 0x2DEB33A0, 0x77037D81, 0x63A440F2, 0xF8BCE6E5,
-   0xE12C4247, 0x6B17D1F2};
-const Ipp32u secp256r1_gy[] = {
-   0x37BF51F5, 0xCBB64068, 0x6B315ECE, 0x2BCE3357, 0x7C0F9E16, 0x8EE7EB4A,
-   0xFE1A7F9B, 0x4FE342E2};
-const Ipp32u secp256r1_r[] = {
-   0xFC632551, 0xF3B9CAC2, 0xA7179E84, 0xBCE6FAAD, 0xFFFFFFFF, 0xFFFFFFFF,
-   0x00000000, 0xFFFFFFFF};
-Ipp32u secp256r1_h = 1;
-
-/* Recommended Parameters secp384r1 */
-const Ipp32u h_secp384r1_p[] = { /* half of secp384r1_p */
-   0x7FFFFFFF, 0x00000000, 0x80000000, 0x7FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x7FFFFFFF};
-
-const Ipp32u secp384r1_p[] = { /* 2^384 -2^128 -2^96 +2^32 -1 */
-   0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
-   0x0, 0x0};
-const Ipp32u secp384r1_a[] = {
-   0xFFFFFFFC, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
-const Ipp32u secp384r1_b[] = {
-   0xD3EC2AEF, 0x2A85C8ED, 0x8A2ED19D, 0xC656398D, 0x5013875A, 0x0314088F,
-   0xFE814112, 0x181D9C6E, 0xE3F82D19, 0x988E056B, 0xE23EE7E4, 0xB3312FA7};
-const Ipp32u secp384r1_gx[] = {
-   0x72760AB7, 0x3A545E38, 0xBF55296C, 0x5502F25D, 0x82542A38, 0x59F741E0,
-   0x8BA79B98, 0x6E1D3B62, 0xF320AD74, 0x8EB1C71E, 0xBE8B0537, 0xAA87CA22};
-const Ipp32u secp384r1_gy[] = {
-   0x90EA0E5F, 0x7A431D7C, 0x1D7E819D, 0x0A60B1CE, 0xB5F0B8C0, 0xE9DA3113,
-   0x289A147C, 0xF8F41DBD, 0x9292DC29, 0x5D9E98BF, 0x96262C6F, 0x3617DE4A};
-const Ipp32u secp384r1_r[] = {
-   0xCCC52973, 0xECEC196A, 0x48B0A77A, 0x581A0DB2, 0xF4372DDF, 0xC7634D81,
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
-Ipp32u secp384r1_h = 1;
-
-/* Recommended Parameters secp521r1 */
-const Ipp32u h_secp521r1_p[] = { /* half of secp521r1_p */
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x000000FF, 0x0};
-
-const Ipp32u secp521r1_p[] = { /* 2^521 -1 */
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x000001FF, 0x0};
-const Ipp32u secp521r1_a[] = {
-   0xFFFFFFFC, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x000001FF};
-const Ipp32u secp521r1_b[] = {
-   0x6B503F00, 0xEF451FD4, 0x3D2C34F1, 0x3573DF88, 0x3BB1BF07, 0x1652C0BD,
-   0xEC7E937B, 0x56193951, 0x8EF109E1, 0xB8B48991, 0x99B315F3, 0xA2DA725B,
-   0xB68540EE, 0x929A21A0, 0x8E1C9A1F, 0x953EB961, 0x00000051};
-const Ipp32u secp521r1_gx[] = {
-   0xC2E5BD66, 0xF97E7E31, 0x856A429B, 0x3348B3C1, 0xA2FFA8DE, 0xFE1DC127,
-   0xEFE75928, 0xA14B5E77, 0x6B4D3DBA, 0xF828AF60, 0x053FB521, 0x9C648139,
-   0x2395B442, 0x9E3ECB66, 0x0404E9CD, 0x858E06B7, 0x000000C6};
-const Ipp32u secp521r1_gy[] = {
-   0x9FD16650, 0x88BE9476, 0xA272C240, 0x353C7086, 0x3FAD0761, 0xC550B901,
-   0x5EF42640, 0x97EE7299, 0x273E662C, 0x17AFBD17, 0x579B4468, 0x98F54449,
-   0x2C7D1BD9, 0x5C8A5FB4, 0x9A3BC004, 0x39296A78, 0x00000118};
-const Ipp32u secp521r1_r[] = {
-   0x91386409, 0xBB6FB71E, 0x899C47AE, 0x3BB5C9B8, 0xF709A5D0, 0x7FCC0148,
-   0xBF2F966B, 0x51868783, 0xFFFFFFFA, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
-   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x000001FF};
-Ipp32u secp521r1_h = 1;
-
-
-/* premultiplied secp128r{1|2}_p (for spesial implementation) */
-static const Ipp32u secp128_x2[] = {0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFB, 0x01, 0x0};
-static const Ipp32u secp128_x3[] = {0xFFFFFFFD, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF9, 0x02, 0x0};
-static const Ipp32u secp128_x4[] = {0xFFFFFFFC, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF7, 0x03, 0x0};
-static const Ipp32u secp128_x5[] = {0xFFFFFFFB, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF5, 0x04, 0x0};
-static const Ipp32u secp128_x6[] = {0xFFFFFFFA, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF3, 0x05, 0x0};
-static const Ipp32u secp128_x7[] = {0xFFFFFFF9, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF1, 0x06, 0x0};
-static const Ipp32u secp128_x8[] = {0xFFFFFFF8, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFEF, 0x07, 0x0};
-static const Ipp32u secp128_x9[] = {0xFFFFFFF7, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFED, 0x08, 0x0};
-static const Ipp32u secp128_xA[] = {0xFFFFFFF6, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFEB, 0x09, 0x0};
-static const Ipp32u secp128_xB[] = {0xFFFFFFF5, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE9, 0x0A, 0x0};
-static const Ipp32u secp128_xC[] = {0xFFFFFFF4, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE7, 0x0B, 0x0};
-static const Ipp32u secp128_xD[] = {0xFFFFFFF3, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE5, 0x0C, 0x0};
-static const Ipp32u secp128_xE[] = {0xFFFFFFF2, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE3, 0x0D, 0x0};
-static const Ipp32u secp128_xF[] = {0xFFFFFFF1, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE1, 0x0E, 0x0};
-static const Ipp32u secp128_x10[]= {0xFFFFFFF0, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFDF, 0x0F, 0x0};
-static const Ipp32u secp128_x11[]= {0xFFFFFFEF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFDD, 0x10, 0x0};
-static const Ipp32u secp128_x12[]= {0xFFFFFFEE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFDB, 0x11, 0x0};
-static const Ipp32u secp128_x13[]= {0xFFFFFFED, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFD9, 0x12, 0x0};
-static const Ipp32u secp128_x14[]= {0xFFFFFFEC, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFD7, 0x13, 0x0};
-static const Ipp32u secp128_x15[]= {0xFFFFFFEB, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFD5, 0x14, 0x0};
-static const Ipp32u secp128_x16[]= {0xFFFFFFEA, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFD3, 0x15, 0x0};
-static const Ipp32u secp128_x17[]= {0xFFFFFFE9, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFD1, 0x16, 0x0};
-static const Ipp32u secp128_x18[]= {0xFFFFFFE8, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFCF, 0x17, 0x0};
-static const Ipp32u secp128_x19[]= {0xFFFFFFE7, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFCD, 0x18, 0x0};
-static const Ipp32u secp128_x1A[]= {0xFFFFFFE6, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFCB, 0x19, 0x0};
-static const Ipp32u secp128_x1B[]= {0xFFFFFFE5, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC9, 0x1A, 0x0};
-static const Ipp32u secp128_x1C[]= {0xFFFFFFE4, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC7, 0x1B, 0x0};
-static const Ipp32u secp128_x1D[]= {0xFFFFFFE3, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC5, 0x1C, 0x0};
-static const Ipp32u secp128_x1E[]= {0xFFFFFFE2, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC3, 0x1D, 0x0};
-static const Ipp32u secp128_x1F[]= {0xFFFFFFE1, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC1, 0x1E, 0x0};
-static const Ipp32u secp128_x20[]= {0xFFFFFFE0, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFBF, 0x1F, 0x0};
-
-#define MAX_MUL (32)
-const Ipp32u* secp128_mx[MAX_MUL] = {
-   secp128r1_p,   /*  1*secp128r1_p */
-   secp128_x2,    /*  2*secp128r1_p */
-   secp128_x3,    /*  3*secp128r1_p */
-   secp128_x4,    /*  4*secp128r1_p */
-   secp128_x5,    /*  5*secp128r1_p */
-   secp128_x6,    /*  6*secp128r1_p */
-   secp128_x7,    /*  7*secp128r1_p */
-   secp128_x8,    /*  8*secp128r1_p */
-   secp128_x9,    /*  9*secp128r1_p */
-   secp128_xA,    /* 10*secp128r1_p */
-   secp128_xB,    /* 11*secp128r1_p */
-   secp128_xC,    /* 12*secp128r1_p */
-   secp128_xD,    /* 13*secp128r1_p */
-   secp128_xE,    /* 14*secp128r1_p */
-   secp128_xF,    /* 15*secp128r1_p */
-   secp128_x10,   /* 16*secp128r1_p */
-   secp128_x11,   /* 17*secp128r1_p */
-   secp128_x12,   /* 18*secp128r1_p */
-   secp128_x13,   /* 19*secp128r1_p */
-   secp128_x14,   /* 20*secp128r1_p */
-   secp128_x15,   /* 21*secp128r1_p */
-   secp128_x16,   /* 22*secp128r1_p */
-   secp128_x17,   /* 23*secp128r1_p */
-   secp128_x18,   /* 24*secp128r1_p */
-   secp128_x19,   /* 25*secp128r1_p */
-   secp128_x1A,   /* 26*secp128r1_p */
-   secp128_x1B,   /* 27*secp128r1_p */
-   secp128_x1C,   /* 28*secp128r1_p */
-   secp128_x1D,   /* 29*secp128r1_p */
-   secp128_x1E,   /* 30*secp128r1_p */
-   secp128_x1F,   /* 31*secp128r1_p */
-   secp128_x20    /* 32*secp128r1_p */
-};
+/*
+* 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"
+
+
+/* Recommended Parameters secp112r1 */
+const Ipp32u secp112r1_p[] = { /* (2^128 -3)/76439 */
+   0xBEAD208B, 0x5E668076, 0x2ABF62E3, 0xDB7C};
+const Ipp32u secp112r1_a[] = {
+   0xBEAD2088, 0x5E668076, 0x2ABF62E3, 0xDB7C};
+const Ipp32u secp112r1_b[] = {
+   0x11702B22, 0x16EEDE89, 0xF8BA0439, 0x659E};
+const Ipp32u secp112r1_gx[] = {
+   0xF9C2F098, 0x5EE76B55, 0x7239995A, 0x0948};
+const Ipp32u secp112r1_gy[] = {
+   0x0FF77500, 0xC0A23E0E, 0xE5AF8724, 0xA89C};
+const Ipp32u secp112r1_r[] = {
+   0xAC6561C5, 0x5E7628DF, 0x2ABF62E3, 0xDB7C};
+Ipp32u secp112r1_h = 1;
+
+/* Recommended Parameters secp112r2 */
+const Ipp32u secp112r2_p[] = { /* (2^128 -3)/76439 */
+   0xBEAD208B, 0x5E668076, 0x2ABF62E3, 0xDB7C};
+const Ipp32u secp112r2_a[] = {
+   0x5C0EF02C, 0x8A0AAAF6, 0xC24C05F3, 0x6127};
+const Ipp32u secp112r2_b[] = {
+   0x4C85D709, 0xED74FCC3, 0xF1815DB5, 0x51DE};
+const Ipp32u secp112r2_gx[] = {
+   0xD0928643, 0xB4E1649D, 0x0AB5E892, 0x4BA3};
+const Ipp32u secp112r2_gy[] = {
+   0x6E956E97, 0x3747DEF3, 0x46F5882E, 0xADCD};
+const Ipp32u secp112r2_r[] = {
+   0x0520D04B, 0xD7597CA1, 0x0AAFD8B8, 0x36DF};
+Ipp32u secp112r2_h = 4;
+
+/* Recommended Parameters secp128r1 */
+const Ipp32u h_secp128r1_p[] = { /* halpf of secp128r1_p */
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x7FFFFFFE};
+
+const Ipp32u secp128r1_p[] = { // 2^128 -2^97 -1
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFD, 0x0, 0x0};
+const Ipp32u secp128r1_a[] = {
+   0xFFFFFFFC, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFD};
+const Ipp32u secp128r1_b[] = {
+   0x2CEE5ED3, 0xD824993C, 0x1079F43D, 0xE87579C1};
+const Ipp32u secp128r1_gx[] = {
+   0xA52C5B86, 0x0C28607C, 0x8B899B2D, 0x161FF752};
+const Ipp32u secp128r1_gy[] = {
+   0xDDED7A83, 0xC02DA292, 0x5BAFEB13, 0xCF5AC839};
+const Ipp32u secp128r1_r[] = {
+   0x9038A115, 0x75A30D1B, 0x00000000, 0xFFFFFFFE};
+Ipp32u secp128r1_h = 1;
+
+/* Recommended Parameters secp128r2 */
+const Ipp32u secp128r2_p[] = { /* 2^128 -2^97 -1 */
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFD, 0x0, 0x0};
+const Ipp32u secp128r2_a[] = {
+   0xBFF9AEE1, 0xBF59CC9B, 0xD1B3BBFE, 0xD6031998};
+const Ipp32u secp128r2_b[] = {
+   0xBB6D8A5D, 0xDC2C6558, 0x80D02919, 0x5EEEFCA3};
+const Ipp32u secp128r2_gx[] = {
+   0xCDEBC140, 0xE6FB32A7, 0x5E572983, 0x7B6AA5D8};
+const Ipp32u secp128r2_gy[] = {
+   0x5FC34B44, 0x7106FE80, 0x894D3AEE, 0x27B6916A};
+const Ipp32u secp128r2_r[] = {
+   0x0613B5A3, 0xBE002472, 0x7FFFFFFF, 0x3FFFFFFF};
+Ipp32u secp128r2_h = 4;
+
+/* Recommended Parameters secp160r1 */
+const Ipp32u secp160r1_p[] = { /* 2^160 -2^31 -1 */
+   0x7FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
+const Ipp32u secp160r1_a[] = {
+   0x7FFFFFFC, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
+const Ipp32u secp160r1_b[] = {
+   0xC565FA45, 0x81D4D4AD, 0x65ACF89F, 0x54BD7A8B, 0x1C97BEFC};
+const Ipp32u secp160r1_gx[] = {
+   0x13CBFC82, 0x68C38BB9, 0x46646989, 0x8EF57328, 0x4A96B568};
+const Ipp32u secp160r1_gy[] = {
+   0x7AC5FB32, 0x04235137, 0x59DCC912, 0x3168947D, 0x23A62855};
+const Ipp32u secp160r1_r[] = {
+   0xCA752257, 0xF927AED3, 0x0001F4C8, 0x00000000, 0x00000000, 0x1};
+Ipp32u secp160r1_h = 1;
+
+/* Recommended Parameters secp160r2 */
+const Ipp32u secp160r2_p[] = { /* 2^160 -2^32 -2^14 -2^12 -2^9 -2^8 -2^7 -2^2 -1 */
+   0xFFFFAC73, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
+const Ipp32u secp160r2_a[] = {
+   0xFFFFAC70, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
+const Ipp32u secp160r2_b[] = {
+   0xF50388BA, 0x04664D5A, 0xAB572749, 0xFB59EB8B, 0xB4E134D3};
+const Ipp32u secp160r2_gx[] = {
+   0x3144CE6D, 0x30F7199D, 0x1F4FF11B, 0x293A117E, 0x52DCB034};
+const Ipp32u secp160r2_gy[] = {
+   0xA7D43F2E, 0xF9982CFE, 0xE071FA0D, 0xE331F296, 0xFEAFFEF2};
+const Ipp32u secp160r2_r[] = {
+   0xF3A1A16B, 0xE786A818, 0x0000351E, 0x00000000, 0x00000000, 0x1};
+Ipp32u secp160r2_h = 1;
+
+/* Recommended Parameters secp192r1 */
+const Ipp32u h_secp192r1_p[] = { /* half of secp192r1_p */
+   0xFFFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x7FFFFFFF};
+
+const Ipp32u secp192r1_p[] = { /* 2^192 -2^64 -1 */
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0, 0x0};
+const Ipp32u secp192r1_a[] = {
+   0xFFFFFFFC, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
+const Ipp32u secp192r1_b[] = {
+   0xC146B9B1, 0xFEB8DEEC, 0x72243049, 0x0FA7E9AB, 0xE59C80E7, 0x64210519};
+const Ipp32u secp192r1_gx[] = {
+   0x82FF1012, 0xF4FF0AFD, 0x43A18800, 0x7CBF20EB, 0xB03090F6, 0x188DA80E};
+const Ipp32u secp192r1_gy[] = {
+   0x1E794811, 0x73F977A1, 0x6B24CDD5, 0x631011ED, 0xFFC8DA78, 0x07192B95};
+const Ipp32u secp192r1_r[] = {
+   0xB4D22831, 0x146BC9B1, 0x99DEF836, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
+Ipp32u secp192r1_h = 1;
+
+/* Recommended Parameters secp224r1 */
+const Ipp32u h_secp224r1_p[] = { /* half of secp224r1_p */
+   0x00000000, 0x00000000, 0x80000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+   0x7FFFFFFF, 0x0};
+
+const Ipp32u secp224r1_p[] = { /* 2^224 -2^96 +1 */
+   0x00000001, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+   0xFFFFFFFF, 0x0};
+const Ipp32u secp224r1_a[] = {
+   0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF,
+   0xFFFFFFFF};
+const Ipp32u secp224r1_b[] = {
+   0x2355FFB4, 0x270B3943, 0xD7BFD8BA, 0x5044B0B7, 0xF5413256, 0x0C04B3AB,
+   0xB4050A85};
+const Ipp32u secp224r1_gx[] = {
+   0x115C1D21, 0x343280D6, 0x56C21122, 0x4A03C1D3, 0x321390B9, 0x6BB4BF7F,
+   0xB70E0CBD};
+const Ipp32u secp224r1_gy[] = {
+   0x85007E34, 0x44D58199, 0x5A074764, 0xCD4375A0, 0x4C22DFE6, 0xB5F723FB,
+   0xBD376388};
+const Ipp32u secp224r1_r[] = {
+   0x5C5C2A3D, 0x13DD2945, 0xE0B8F03E, 0xFFFF16A2, 0xFFFFFFFF, 0xFFFFFFFF,
+   0xFFFFFFFF};
+Ipp32u secp224r1_h = 1;
+
+/* Recommended Parameters secp256r1 */
+const Ipp32u h_secp256r1_p[] = { /* half of secp256r1_p */
+   0xFFFFFFFF, 0xFFFFFFFF, 0x7FFFFFFF, 0x00000000, 0x00000000, 0x80000000,
+   0x80000000, 0x7FFFFFFF};
+
+const Ipp32u secp256r1_p[] = { /* 2^256 -2^224 +2^192 +2^96 -1 */
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000,
+   0x00000001, 0xFFFFFFFF, 0x0, 0x0};
+const Ipp32u secp256r1_a[] = {
+   0xFFFFFFFC, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000,
+   0x00000001, 0xFFFFFFFF};
+const Ipp32u secp256r1_b[] = {
+   0x27D2604B, 0x3BCE3C3E, 0xCC53B0F6, 0x651D06B0, 0x769886BC, 0xB3EBBD55,
+   0xAA3A93E7, 0x5AC635D8};
+const Ipp32u secp256r1_gx[] = {
+   0xD898C296, 0xF4A13945, 0x2DEB33A0, 0x77037D81, 0x63A440F2, 0xF8BCE6E5,
+   0xE12C4247, 0x6B17D1F2};
+const Ipp32u secp256r1_gy[] = {
+   0x37BF51F5, 0xCBB64068, 0x6B315ECE, 0x2BCE3357, 0x7C0F9E16, 0x8EE7EB4A,
+   0xFE1A7F9B, 0x4FE342E2};
+const Ipp32u secp256r1_r[] = {
+   0xFC632551, 0xF3B9CAC2, 0xA7179E84, 0xBCE6FAAD, 0xFFFFFFFF, 0xFFFFFFFF,
+   0x00000000, 0xFFFFFFFF};
+Ipp32u secp256r1_h = 1;
+
+/* Recommended Parameters secp384r1 */
+const Ipp32u h_secp384r1_p[] = { /* half of secp384r1_p */
+   0x7FFFFFFF, 0x00000000, 0x80000000, 0x7FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x7FFFFFFF};
+
+const Ipp32u secp384r1_p[] = { /* 2^384 -2^128 -2^96 +2^32 -1 */
+   0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+   0x0, 0x0};
+const Ipp32u secp384r1_a[] = {
+   0xFFFFFFFC, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
+const Ipp32u secp384r1_b[] = {
+   0xD3EC2AEF, 0x2A85C8ED, 0x8A2ED19D, 0xC656398D, 0x5013875A, 0x0314088F,
+   0xFE814112, 0x181D9C6E, 0xE3F82D19, 0x988E056B, 0xE23EE7E4, 0xB3312FA7};
+const Ipp32u secp384r1_gx[] = {
+   0x72760AB7, 0x3A545E38, 0xBF55296C, 0x5502F25D, 0x82542A38, 0x59F741E0,
+   0x8BA79B98, 0x6E1D3B62, 0xF320AD74, 0x8EB1C71E, 0xBE8B0537, 0xAA87CA22};
+const Ipp32u secp384r1_gy[] = {
+   0x90EA0E5F, 0x7A431D7C, 0x1D7E819D, 0x0A60B1CE, 0xB5F0B8C0, 0xE9DA3113,
+   0x289A147C, 0xF8F41DBD, 0x9292DC29, 0x5D9E98BF, 0x96262C6F, 0x3617DE4A};
+const Ipp32u secp384r1_r[] = {
+   0xCCC52973, 0xECEC196A, 0x48B0A77A, 0x581A0DB2, 0xF4372DDF, 0xC7634D81,
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
+Ipp32u secp384r1_h = 1;
+
+/* Recommended Parameters secp521r1 */
+const Ipp32u h_secp521r1_p[] = { /* half of secp521r1_p */
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x000000FF, 0x0};
+
+const Ipp32u secp521r1_p[] = { /* 2^521 -1 */
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x000001FF, 0x0};
+const Ipp32u secp521r1_a[] = {
+   0xFFFFFFFC, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x000001FF};
+const Ipp32u secp521r1_b[] = {
+   0x6B503F00, 0xEF451FD4, 0x3D2C34F1, 0x3573DF88, 0x3BB1BF07, 0x1652C0BD,
+   0xEC7E937B, 0x56193951, 0x8EF109E1, 0xB8B48991, 0x99B315F3, 0xA2DA725B,
+   0xB68540EE, 0x929A21A0, 0x8E1C9A1F, 0x953EB961, 0x00000051};
+const Ipp32u secp521r1_gx[] = {
+   0xC2E5BD66, 0xF97E7E31, 0x856A429B, 0x3348B3C1, 0xA2FFA8DE, 0xFE1DC127,
+   0xEFE75928, 0xA14B5E77, 0x6B4D3DBA, 0xF828AF60, 0x053FB521, 0x9C648139,
+   0x2395B442, 0x9E3ECB66, 0x0404E9CD, 0x858E06B7, 0x000000C6};
+const Ipp32u secp521r1_gy[] = {
+   0x9FD16650, 0x88BE9476, 0xA272C240, 0x353C7086, 0x3FAD0761, 0xC550B901,
+   0x5EF42640, 0x97EE7299, 0x273E662C, 0x17AFBD17, 0x579B4468, 0x98F54449,
+   0x2C7D1BD9, 0x5C8A5FB4, 0x9A3BC004, 0x39296A78, 0x00000118};
+const Ipp32u secp521r1_r[] = {
+   0x91386409, 0xBB6FB71E, 0x899C47AE, 0x3BB5C9B8, 0xF709A5D0, 0x7FCC0148,
+   0xBF2F966B, 0x51868783, 0xFFFFFFFA, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x000001FF};
+Ipp32u secp521r1_h = 1;
+
+
+/* premultiplied secp128r{1|2}_p (for spesial implementation) */
+static const Ipp32u secp128_x2[] = {0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFB, 0x01, 0x0};
+static const Ipp32u secp128_x3[] = {0xFFFFFFFD, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF9, 0x02, 0x0};
+static const Ipp32u secp128_x4[] = {0xFFFFFFFC, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF7, 0x03, 0x0};
+static const Ipp32u secp128_x5[] = {0xFFFFFFFB, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF5, 0x04, 0x0};
+static const Ipp32u secp128_x6[] = {0xFFFFFFFA, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF3, 0x05, 0x0};
+static const Ipp32u secp128_x7[] = {0xFFFFFFF9, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFF1, 0x06, 0x0};
+static const Ipp32u secp128_x8[] = {0xFFFFFFF8, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFEF, 0x07, 0x0};
+static const Ipp32u secp128_x9[] = {0xFFFFFFF7, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFED, 0x08, 0x0};
+static const Ipp32u secp128_xA[] = {0xFFFFFFF6, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFEB, 0x09, 0x0};
+static const Ipp32u secp128_xB[] = {0xFFFFFFF5, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE9, 0x0A, 0x0};
+static const Ipp32u secp128_xC[] = {0xFFFFFFF4, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE7, 0x0B, 0x0};
+static const Ipp32u secp128_xD[] = {0xFFFFFFF3, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE5, 0x0C, 0x0};
+static const Ipp32u secp128_xE[] = {0xFFFFFFF2, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE3, 0x0D, 0x0};
+static const Ipp32u secp128_xF[] = {0xFFFFFFF1, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFE1, 0x0E, 0x0};
+static const Ipp32u secp128_x10[]= {0xFFFFFFF0, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFDF, 0x0F, 0x0};
+static const Ipp32u secp128_x11[]= {0xFFFFFFEF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFDD, 0x10, 0x0};
+static const Ipp32u secp128_x12[]= {0xFFFFFFEE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFDB, 0x11, 0x0};
+static const Ipp32u secp128_x13[]= {0xFFFFFFED, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFD9, 0x12, 0x0};
+static const Ipp32u secp128_x14[]= {0xFFFFFFEC, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFD7, 0x13, 0x0};
+static const Ipp32u secp128_x15[]= {0xFFFFFFEB, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFD5, 0x14, 0x0};
+static const Ipp32u secp128_x16[]= {0xFFFFFFEA, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFD3, 0x15, 0x0};
+static const Ipp32u secp128_x17[]= {0xFFFFFFE9, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFD1, 0x16, 0x0};
+static const Ipp32u secp128_x18[]= {0xFFFFFFE8, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFCF, 0x17, 0x0};
+static const Ipp32u secp128_x19[]= {0xFFFFFFE7, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFCD, 0x18, 0x0};
+static const Ipp32u secp128_x1A[]= {0xFFFFFFE6, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFCB, 0x19, 0x0};
+static const Ipp32u secp128_x1B[]= {0xFFFFFFE5, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC9, 0x1A, 0x0};
+static const Ipp32u secp128_x1C[]= {0xFFFFFFE4, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC7, 0x1B, 0x0};
+static const Ipp32u secp128_x1D[]= {0xFFFFFFE3, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC5, 0x1C, 0x0};
+static const Ipp32u secp128_x1E[]= {0xFFFFFFE2, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC3, 0x1D, 0x0};
+static const Ipp32u secp128_x1F[]= {0xFFFFFFE1, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFC1, 0x1E, 0x0};
+static const Ipp32u secp128_x20[]= {0xFFFFFFE0, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFBF, 0x1F, 0x0};
+
+#define MAX_MUL (32)
+const Ipp32u* secp128_mx[MAX_MUL] = {
+   secp128r1_p,   /*  1*secp128r1_p */
+   secp128_x2,    /*  2*secp128r1_p */
+   secp128_x3,    /*  3*secp128r1_p */
+   secp128_x4,    /*  4*secp128r1_p */
+   secp128_x5,    /*  5*secp128r1_p */
+   secp128_x6,    /*  6*secp128r1_p */
+   secp128_x7,    /*  7*secp128r1_p */
+   secp128_x8,    /*  8*secp128r1_p */
+   secp128_x9,    /*  9*secp128r1_p */
+   secp128_xA,    /* 10*secp128r1_p */
+   secp128_xB,    /* 11*secp128r1_p */
+   secp128_xC,    /* 12*secp128r1_p */
+   secp128_xD,    /* 13*secp128r1_p */
+   secp128_xE,    /* 14*secp128r1_p */
+   secp128_xF,    /* 15*secp128r1_p */
+   secp128_x10,   /* 16*secp128r1_p */
+   secp128_x11,   /* 17*secp128r1_p */
+   secp128_x12,   /* 18*secp128r1_p */
+   secp128_x13,   /* 19*secp128r1_p */
+   secp128_x14,   /* 20*secp128r1_p */
+   secp128_x15,   /* 21*secp128r1_p */
+   secp128_x16,   /* 22*secp128r1_p */
+   secp128_x17,   /* 23*secp128r1_p */
+   secp128_x18,   /* 24*secp128r1_p */
+   secp128_x19,   /* 25*secp128r1_p */
+   secp128_x1A,   /* 26*secp128r1_p */
+   secp128_x1B,   /* 27*secp128r1_p */
+   secp128_x1C,   /* 28*secp128r1_p */
+   secp128_x1D,   /* 29*secp128r1_p */
+   secp128_x1E,   /* 30*secp128r1_p */
+   secp128_x1F,   /* 31*secp128r1_p */
+   secp128_x20    /* 32*secp128r1_p */
+};

+ 145 - 145
external/crypto_px/sources/ippcp/src/pcpeccpverifydsaca.c

@@ -1,145 +1,145 @@
-/*
-* 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: ippsECCPVerifyDSA
-//
-// Purpose: Verify Signature (DSA version).
-//
-// Returns:                   Reason:
-//    ippStsNullPtrErr           NULL == pECC
-//                               NULL == pMsgDigest
-//                               NULL == pSignX
-//                               NULL == pSignY
-//                               NULL == pResult
-//
-//    ippStsContextMatchErr      illegal pECC->idCtx
-//                               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;
-   }
-}
+/*
+* 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: ippsECCPVerifyDSA
+//
+// Purpose: Verify Signature (DSA version).
+//
+// Returns:                   Reason:
+//    ippStsNullPtrErr           NULL == pECC
+//                               NULL == pMsgDigest
+//                               NULL == pSignX
+//                               NULL == pSignY
+//                               NULL == pResult
+//
+//    ippStsContextMatchErr      illegal pECC->idCtx
+//                               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;
+   }
+}

+ 159 - 159
external/crypto_px/sources/ippcp/src/pcphash.h

@@ -1,159 +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 */
+/*
+* 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 */

+ 513 - 513
external/crypto_px/sources/ippcp/src/pcphashca.c

@@ -1,513 +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||hashSize<tagLen) IPP_ERROR_RET(ippStsLengthErr);
-
-      cpComputeDigest(pTag, tagLen, pCtx);
-      return ippStsNoErr;
-   }
-}
-
-/*F*
-//    Name: ippsHashFinal
-//
-// Purpose: Complete message digesting and return digest.
-//
-// Returns:                   Reason:
-//    ippStsNullPtrErr           pMD == NULL
-//                               pCtx == NULL
-//    ippStsContextMatchErr      pCtx->idCtx != 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;
-   }
-}
+/*
+* 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||hashSize<tagLen) IPP_ERROR_RET(ippStsLengthErr);
+
+      cpComputeDigest(pTag, tagLen, pCtx);
+      return ippStsNoErr;
+   }
+}
+
+/*F*
+//    Name: ippsHashFinal
+//
+// Purpose: Complete message digesting and return digest.
+//
+// Returns:                   Reason:
+//    ippStsNullPtrErr           pMD == NULL
+//                               pCtx == NULL
+//    ippStsContextMatchErr      pCtx->idCtx != 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;
+   }
+}

+ 216 - 216
external/crypto_px/sources/ippcp/src/pcphashcnt.c

@@ -1,216 +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)}}
-};
+/*
+* 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)}}
+};

+ 197 - 197
external/crypto_px/sources/ippcp/src/pcphashmd5px.c

@@ -1,197 +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;
-   }
-}
+/*
+* 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;
+   }
+}

+ 174 - 174
external/crypto_px/sources/ippcp/src/pcphashsha1px.c

@@ -1,174 +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;
-      }
-   }
-}
+/*
+* 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;
+      }
+   }
+}

+ 199 - 199
external/crypto_px/sources/ippcp/src/pcphashsha256px.c

@@ -1,199 +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
+/*
+* 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

+ 207 - 207
external/crypto_px/sources/ippcp/src/pcphashsha512px.c

@@ -1,207 +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
+/*
+* 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

+ 55 - 55
external/crypto_px/sources/ippcp/src/pcphmac.h

@@ -1,55 +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 */
+/*
+* 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 */

+ 332 - 332
external/crypto_px/sources/ippcp/src/pcphmacca.c

@@ -1,332 +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; n<actualKeyLen; n++) {
-         pCtx->ipadKey[n] ^= (Ipp8u)IPAD;
-         pCtx->opadKey[n] ^= (Ipp8u)OPAD;
-      }
-      for(; n<mbs; n++) {
-         pCtx->ipadKey[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;
-   }
-}
+/*
+* 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; n<actualKeyLen; n++) {
+         pCtx->ipadKey[n] ^= (Ipp8u)IPAD;
+         pCtx->opadKey[n] ^= (Ipp8u)OPAD;
+      }
+      for(; n<mbs; n++) {
+         pCtx->ipadKey[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;
+   }
+}

+ 116 - 116
external/crypto_px/sources/ippcp/src/pcpmontexpbinca.c

@@ -1,116 +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(; n<BNU_CHUNK_BITS; n++, eValue<<=1) {
-         /* squaring R = R*R mod Modulus */
-         cpMontSqr_BNU(dataY,
-                       dataY, nsM,
-                       dataM, nsM, m0,
-                       pProduct, pKBuffer);
-         /* and multiply R = R*X mod Modulus */
-         if(eValue & ((BNU_CHUNK_T)1<<(BNU_CHUNK_BITS-1)))
-            cpMontMul_BNU(dataY,
-                          dataY, nsM,
-                          dataT, nsM,
-                          dataM, nsM, m0,
-                          pProduct, pKBuffer);
-      }
-
-      /* execute rest bits of E */
-      for(--nsE; nsE>0; nsE--) {
-         eValue = dataE[nsE-1];
-
-         for(n=0; n<BNU_CHUNK_BITS; n++, eValue<<=1) {
-            /* squaring: R = R*R mod Modulus */
-            cpMontSqr_BNU(dataY,
-                          dataY, nsM,
-                          dataM, nsM, m0,
-                          pProduct, pKBuffer);
-            if(eValue & ((BNU_CHUNK_T)1<<(BNU_CHUNK_BITS-1)))
-               cpMontMul_BNU(dataY,
-                             dataY, nsM,
-                             dataT, nsM,
-                             dataM, nsM, m0,
-                             pProduct, pKBuffer);
-         }
-      }
-   }
-
-   return nsM;
-}
+/*
+* 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(; n<BNU_CHUNK_BITS; n++, eValue<<=1) {
+         /* squaring R = R*R mod Modulus */
+         cpMontSqr_BNU(dataY,
+                       dataY, nsM,
+                       dataM, nsM, m0,
+                       pProduct, pKBuffer);
+         /* and multiply R = R*X mod Modulus */
+         if(eValue & ((BNU_CHUNK_T)1<<(BNU_CHUNK_BITS-1)))
+            cpMontMul_BNU(dataY,
+                          dataY, nsM,
+                          dataT, nsM,
+                          dataM, nsM, m0,
+                          pProduct, pKBuffer);
+      }
+
+      /* execute rest bits of E */
+      for(--nsE; nsE>0; nsE--) {
+         eValue = dataE[nsE-1];
+
+         for(n=0; n<BNU_CHUNK_BITS; n++, eValue<<=1) {
+            /* squaring: R = R*R mod Modulus */
+            cpMontSqr_BNU(dataY,
+                          dataY, nsM,
+                          dataM, nsM, m0,
+                          pProduct, pKBuffer);
+            if(eValue & ((BNU_CHUNK_T)1<<(BNU_CHUNK_BITS-1)))
+               cpMontMul_BNU(dataY,
+                             dataY, nsM,
+                             dataT, nsM,
+                             dataM, nsM, m0,
+                             pProduct, pKBuffer);
+         }
+      }
+   }
+
+   return nsM;
+}

+ 190 - 190
external/crypto_px/sources/ippcp/src/pcpmontgomery.h

@@ -1,190 +1,190 @@
-/*
-* 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_MONTGOMETRY_H)
-#define _CP_MONTGOMETRY_H
-
-/*
-// Montgomery spec structure
-*/
-struct _cpMontgomery
-{
-   IppCtxId       idCtx;      /* Montgomery spec identifier             */
-   cpSize         maxLen;     /* maximum length of modulus being stored */
-   cpSize         modLen;     /* length of modulus (and R = b^modLen)   */
-   BNU_CHUNK_T    m0;         /* low word of (1/modulus) mod R          */
-   BNU_CHUNK_T*   pModulus;   /* modulus (of modLen BNU_CHUNK_T size)   */
-   BNU_CHUNK_T*   pIdentity;  /* mont_enc(1)                            */
-   BNU_CHUNK_T*   pSquare;    /* mont_enc(R^2)                          */
-   BNU_CHUNK_T*   pCube;      /* mont_enc(R^3)                          */
-   BNU_CHUNK_T*   pTBuffer;   /* internal buffer  modLen BNU_CHUNK_T    */
-   BNU_CHUNK_T*   pSBuffer;   /* internal buffer  modLen BNU_CHUNK_T    */
-   BNU_CHUNK_T*   pProduct;   /* internal product (2*modLen BNU_CHUNK_T)*/
-   BNU_CHUNK_T*   pKBuffer;   /* mul/sqr buffer (Karatsuba method used) */
-};
-
-/* accessory macros */
-#define MNT_ID(eng)       ((eng)->idCtx)
-#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 */
+/*
+* 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_MONTGOMETRY_H)
+#define _CP_MONTGOMETRY_H
+
+/*
+// Montgomery spec structure
+*/
+struct _cpMontgomery
+{
+   IppCtxId       idCtx;      /* Montgomery spec identifier             */
+   cpSize         maxLen;     /* maximum length of modulus being stored */
+   cpSize         modLen;     /* length of modulus (and R = b^modLen)   */
+   BNU_CHUNK_T    m0;         /* low word of (1/modulus) mod R          */
+   BNU_CHUNK_T*   pModulus;   /* modulus (of modLen BNU_CHUNK_T size)   */
+   BNU_CHUNK_T*   pIdentity;  /* mont_enc(1)                            */
+   BNU_CHUNK_T*   pSquare;    /* mont_enc(R^2)                          */
+   BNU_CHUNK_T*   pCube;      /* mont_enc(R^3)                          */
+   BNU_CHUNK_T*   pTBuffer;   /* internal buffer  modLen BNU_CHUNK_T    */
+   BNU_CHUNK_T*   pSBuffer;   /* internal buffer  modLen BNU_CHUNK_T    */
+   BNU_CHUNK_T*   pProduct;   /* internal product (2*modLen BNU_CHUNK_T)*/
+   BNU_CHUNK_T*   pKBuffer;   /* mul/sqr buffer (Karatsuba method used) */
+};
+
+/* accessory macros */
+#define MNT_ID(eng)       ((eng)->idCtx)
+#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 */

+ 296 - 296
external/crypto_px/sources/ippcp/src/pcpmontgomeryca.c

@@ -1,296 +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;
-   }
-}
+/*
+* 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;
+   }
+}

+ 64 - 64
external/crypto_px/sources/ippcp/src/pcpmontred.c

@@ -1,64 +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 = t<pProduct[nsM+n+1];
-      pProduct[nsM+n+1] = t;
-   }
-
-   m0 *= pProduct[nsM-1];
-   extension = cpAddMulDgt_BNU(pProduct+nsM-1, pModulus, nsM, m0);
-   ADD_AB(extension, pProduct[2*nsM-1], pProduct[2*nsM-1], extension);
-
-   carry |= extension;
-   carry -= cpSub_BNU(pR, pProduct+nsM, pModulus, nsM);
-   /* condition copy: R = carry? Product+mSize : R */
-   MASKED_COPY_BNU(pR, carry, pProduct+nsM, pR, nsM);
-}
+/*
+* 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 = t<pProduct[nsM+n+1];
+      pProduct[nsM+n+1] = t;
+   }
+
+   m0 *= pProduct[nsM-1];
+   extension = cpAddMulDgt_BNU(pProduct+nsM-1, pModulus, nsM, m0);
+   ADD_AB(extension, pProduct[2*nsM-1], pProduct[2*nsM-1], extension);
+
+   carry |= extension;
+   carry -= cpSub_BNU(pR, pProduct+nsM, pModulus, nsM);
+   /* condition copy: R = carry? Product+mSize : R */
+   MASKED_COPY_BNU(pR, carry, pProduct+nsM, pR, nsM);
+}

Some files were not shown because too many files changed in this diff