aboutsummaryrefslogtreecommitdiff
path: root/ext/ipp/sources/ippcp/pcpgfpec_dblpoint.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/ipp/sources/ippcp/pcpgfpec_dblpoint.c')
-rw-r--r--ext/ipp/sources/ippcp/pcpgfpec_dblpoint.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/ext/ipp/sources/ippcp/pcpgfpec_dblpoint.c b/ext/ipp/sources/ippcp/pcpgfpec_dblpoint.c
new file mode 100644
index 0000000..7cf8611
--- /dev/null
+++ b/ext/ipp/sources/ippcp/pcpgfpec_dblpoint.c
@@ -0,0 +1,134 @@
+/*******************************************************************************
+* Copyright 2010-2018 Intel Corporation
+* All Rights Reserved.
+*
+* If this software was obtained under the Intel Simplified Software License,
+* the following terms apply:
+*
+* The source code, information and material ("Material") contained herein is
+* owned by Intel Corporation or its suppliers or licensors, and title to such
+* Material remains with Intel Corporation or its suppliers or licensors. The
+* Material contains proprietary information of Intel or its suppliers and
+* licensors. The Material is protected by worldwide copyright laws and treaty
+* provisions. No part of the Material may be used, copied, reproduced,
+* modified, published, uploaded, posted, transmitted, distributed or disclosed
+* in any way without Intel's prior express written permission. No license under
+* any patent, copyright or other intellectual property rights in the Material
+* is granted to or conferred upon you, either expressly, by implication,
+* inducement, estoppel or otherwise. Any license under such intellectual
+* property rights must be express and approved by Intel in writing.
+*
+* Unless otherwise agreed by Intel in writing, you may not remove or alter this
+* notice or any other notice embedded in Materials by Intel or Intel's
+* suppliers or licensors in any way.
+*
+*
+* If this software was obtained under the Apache License, Version 2.0 (the
+* "License"), the following terms apply:
+*
+* You may not use this file except in compliance with the License. You may
+* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+*
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*******************************************************************************/
+
+/*
+//
+// Purpose:
+// Intel(R) Integrated Performance Primitives. Cryptography Primitives.
+// Internal EC over GF(p^m) basic Definitions & Function Prototypes
+//
+// Context:
+// gfec_point_double()
+//
+*/
+
+#include "owndefs.h"
+#include "owncp.h"
+#include "pcpgfpecstuff.h"
+#include "gsscramble.h"
+
+
+
+#if ( ECP_PROJECTIVE_COORD == JACOBIAN )
+/*
+// A = 4*x*y^2
+// B = 3*x^2 + a*z^4
+//
+// x3 = -2*A + B^2
+// y3 = -8y^4 +B*(A-x3)
+// z3 = 2*y*z
+//
+// complexity: = 4s+4m (NIST's, SM2 curves)
+// = (EPID2 curve)
+// = 6s+4m (arbitrary curves)
+*/
+void gfec_point_double(BNU_CHUNK_T* pRdata, const BNU_CHUNK_T* pPdata, IppsGFpECState* pEC)
+{
+ IppsGFpState* pGF = ECP_GFP(pEC);
+ gsModEngine* pGFE = GFP_PMA(pGF);
+ int elemLen = GFP_FELEN(pGFE);
+
+ mod_add add = GFP_METHOD(pGFE)->add; /* gf add */
+ mod_sub sub = GFP_METHOD(pGFE)->sub; /* gf sub */
+ mod_div2 div2= GFP_METHOD(pGFE)->div2; /* gf div2 */
+ mod_mul2 mul2= GFP_METHOD(pGFE)->mul2; /* gf mul2 */
+ mod_mul3 mul3= GFP_METHOD(pGFE)->mul3; /* gf mul3 */
+ mod_mul mul = GFP_METHOD(pGFE)->mul; /* gf mul */
+ mod_sqr sqr = GFP_METHOD(pGFE)->sqr; /* gf sqr */
+
+ const BNU_CHUNK_T* pX = pPdata;
+ const BNU_CHUNK_T* pY = pPdata+elemLen;
+ const BNU_CHUNK_T* pZ = pPdata+2*+elemLen;
+
+ BNU_CHUNK_T* rX = pRdata;
+ BNU_CHUNK_T* rY = pRdata+elemLen;
+ BNU_CHUNK_T* rZ = pRdata+2*elemLen;
+
+ /* get temporary from top of EC point pool */
+ BNU_CHUNK_T* U = pEC->pPool;
+ BNU_CHUNK_T* M = U+elemLen;
+ BNU_CHUNK_T* S = M+elemLen;
+
+ mul2(S, pY, pGFE); /* S = 2*Y */
+ sqr(U, pZ, pGFE); /* U = Z^2 */
+
+ sqr(M, S, pGFE); /* M = 4*Y^2 */
+ mul(rZ, S, pZ, pGFE); /* Zres = 2*Y*Z */
+
+ sqr(rY, M, pGFE); /* Yres = 16*Y^4 */
+
+ mul(S, M, pX, pGFE); /* S = 4*X*Y^2 */
+ div2(rY, rY, pGFE); /* Yres = 8*Y^4 */
+
+ if(ECP_STD==ECP_SPECIFIC(pEC)) {
+ add(M, pX, U, pGFE); /* M = 3*(X^2-Z^4) */
+ sub(U, pX, U, pGFE);
+ mul(M, M, U, pGFE);
+ mul3(M, M, pGFE);
+ }
+ else {
+ sqr(M, pX, pGFE); /* M = 3*X^2 */
+ mul3(M, M, pGFE);
+ if(ECP_EPID2!=ECP_SPECIFIC(pEC)) {
+ sqr(U, U, pGFE); /* M = 3*X^2+a*Z4 */
+ mul(U, U, ECP_A(pEC), pGFE);
+ add(M, M, U, pGFE);
+ }
+ }
+
+ mul2(U, S, pGFE); /* U = 8*X*Y^2 */
+ sqr(rX, M, pGFE); /* Xres = M^2 */
+ sub(rX, rX, U, pGFE); /* Xres = M^2-U */
+
+ sub(S, S, rX, pGFE); /* S = 4*X*Y^2-Xres */
+ mul(S, S, M, pGFE); /* S = M*(4*X*Y^2-Xres) */
+ sub(rY, S, rY, pGFE); /* Yres = M*(4*X*Y^2-Xres) -8*Y^4 */
+}
+#endif