• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2 * Copyright 2010-2018 Intel Corporation
3 * All Rights Reserved.
4 *
5 * If this  software was obtained  under the  Intel Simplified  Software License,
6 * the following terms apply:
7 *
8 * The source code,  information  and material  ("Material") contained  herein is
9 * owned by Intel Corporation or its  suppliers or licensors,  and  title to such
10 * Material remains with Intel  Corporation or its  suppliers or  licensors.  The
11 * Material  contains  proprietary  information  of  Intel or  its suppliers  and
12 * licensors.  The Material is protected by  worldwide copyright  laws and treaty
13 * provisions.  No part  of  the  Material   may  be  used,  copied,  reproduced,
14 * modified, published,  uploaded, posted, transmitted,  distributed or disclosed
15 * in any way without Intel's prior express written permission.  No license under
16 * any patent,  copyright or other  intellectual property rights  in the Material
17 * is granted to  or  conferred  upon  you,  either   expressly,  by implication,
18 * inducement,  estoppel  or  otherwise.  Any  license   under such  intellectual
19 * property rights must be express and approved by Intel in writing.
20 *
21 * Unless otherwise agreed by Intel in writing,  you may not remove or alter this
22 * notice or  any  other  notice   embedded  in  Materials  by  Intel  or Intel's
23 * suppliers or licensors in any way.
24 *
25 *
26 * If this  software  was obtained  under the  Apache License,  Version  2.0 (the
27 * "License"), the following terms apply:
28 *
29 * You may  not use this  file except  in compliance  with  the License.  You may
30 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
31 *
32 *
33 * Unless  required  by   applicable  law  or  agreed  to  in  writing,  software
34 * distributed under the License  is distributed  on an  "AS IS"  BASIS,  WITHOUT
35 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 *
37 * See the   License  for the   specific  language   governing   permissions  and
38 * limitations under the License.
39 *******************************************************************************/
40 
41 /*
42 //     Intel(R) Integrated Performance Primitives. Cryptography Primitives.
43 //     EC over GF(p^m) definitinons
44 //
45 //     Context:
46 //        ippsGFpECGetSubgroup()
47 //
48 */
49 
50 #include "owndefs.h"
51 #include "owncp.h"
52 #include "pcpgfpecstuff.h"
53 #include "pcpeccp.h"
54 
55 /*F*
56 // Name: ippsGFpECGet
57 //
58 // Purpose: Extracts the parameters (base point and its order) of an elliptic curve
59 //
60 // Returns:                   Reason:
61 //    ippStsNullPtrErr              NULL == pEC
62 //
63 //    ippStsContextMatchErr         invalid pEC->idCtx
64 //                                  NULL == pEC->subgroup
65 //                                  invalid pX->idCtx
66 //                                  invalid pY->idCtx
67 //
68 //    ippStsOutOfRangeErr           GFPE_ROOM(pX)!=GFP_FELEN(pGFE)
69 //                                  GFPE_ROOM(pY)!=GFP_FELEN(pGFE)
70 //
71 //    ippStsLengthErr               BN_ROOM(pOrder) < orderLen
72 //                                  BN_ROOM(pCofactor) < cofactorLen
73 //
74 //    ippStsNoErr                   no error
75 //
76 // Parameters:
77 //    ppGFp          Pointer to the pointer to the context of underlying finite field
78 //    pX, pY         Pointers to the X and Y coordinates of the base point of the elliptic curve
79 //    pOrder         Pointer to the big number context storing the order of the base point.
80 //    pCofactor      Pointer to the big number context storing the cofactor.
81 //    pEC            Pointer to the context of the elliptic curve.
82 //
83 *F*/
84 
85 IPPFUN(IppStatus, ippsGFpECGetSubgroup,(IppsGFpState** const ppGFp,
86                                      IppsGFpElement* pX, IppsGFpElement* pY,
87                                      IppsBigNumState* pOrder,
88                                      IppsBigNumState* pCofactor,
89                                      const IppsGFpECState* pEC))
90 {
91    IPP_BAD_PTR1_RET(pEC);
92    pEC = (IppsGFpECState*)( IPP_ALIGNED_PTR(pEC, ECGFP_ALIGNMENT) );
93    IPP_BADARG_RET( !ECP_TEST_ID(pEC), ippStsContextMatchErr );
94    IPP_BADARG_RET(!ECP_SUBGROUP(pEC), ippStsContextMatchErr);
95 
96    {
97       const IppsGFpState* pGF = ECP_GFP(pEC);
98       gsModEngine* pGFE = GFP_PMA(pGF);
99       Ipp32u elementSize = GFP_FELEN(pGFE);
100 
101       if(ppGFp) {
102          *ppGFp = (IppsGFpState*)pGF;
103       }
104 
105       if(pX) {
106          IPP_BADARG_RET( !GFPE_TEST_ID(pX), ippStsContextMatchErr );
107          IPP_BADARG_RET( GFPE_ROOM(pX)!=GFP_FELEN(pGFE), ippStsOutOfRangeErr);
108          cpGFpElementCopy(GFPE_DATA(pX), ECP_G(pEC), elementSize);
109       }
110       if(pY) {
111          IPP_BADARG_RET( !GFPE_TEST_ID(pY), ippStsContextMatchErr );
112          IPP_BADARG_RET( GFPE_ROOM(pY)!=GFP_FELEN(pGFE), ippStsOutOfRangeErr);
113          cpGFpElementCopy(GFPE_DATA(pY), ECP_G(pEC)+elementSize, elementSize);
114       }
115 
116       if(pOrder) {
117          BNU_CHUNK_T* pOrderData = MOD_MODULUS(ECP_MONT_R(pEC));
118          int orderBitSize = ECP_ORDBITSIZE(pEC);
119          int orderLen = BITS_BNU_CHUNK(orderBitSize);
120          FIX_BNU(pOrderData, orderLen);
121 
122          pOrder = (IppsBigNumState*)( IPP_ALIGNED_PTR(pOrder, BN_ALIGNMENT) );
123          IPP_BADARG_RET(!BN_VALID_ID(pOrder), ippStsContextMatchErr);
124          IPP_BADARG_RET(BN_ROOM(pOrder) < orderLen, ippStsLengthErr);
125 
126          ZEXPAND_COPY_BNU(BN_NUMBER(pOrder), BN_ROOM(pOrder), pOrderData, orderLen);
127          BN_SIZE(pOrder) = orderLen;
128          BN_SIGN(pOrder) = ippBigNumPOS;
129       }
130 
131       if(pCofactor) {
132          BNU_CHUNK_T* pCofactorData = ECP_COFACTOR(pEC);
133          int cofactorLen = elementSize;
134          FIX_BNU(pCofactorData, cofactorLen);
135 
136          pCofactor = (IppsBigNumState*)( IPP_ALIGNED_PTR(pCofactor, BN_ALIGNMENT) );
137          IPP_BADARG_RET(!BN_VALID_ID(pCofactor), ippStsContextMatchErr);
138          IPP_BADARG_RET(BN_ROOM(pCofactor) < cofactorLen, ippStsLengthErr);
139 
140          ZEXPAND_COPY_BNU(BN_NUMBER(pCofactor), BN_ROOM(pCofactor), pCofactorData, cofactorLen);
141          BN_SIZE(pCofactor) = cofactorLen;
142          BN_SIGN(pCofactor) = ippBigNumPOS;
143       }
144 
145       return ippStsNoErr;
146    }
147 }
148