1 /******************************************************************************* 2 * Copyright 2003-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 // 43 // Purpose: 44 // Cryptography Primitive. 45 // EC over Prime Finite Field (setup/retrieve domain parameters) 46 // 47 // Contents: 48 // ECCPSetDP() 49 // 50 */ 51 52 #include "owndefs.h" 53 #include "owncp.h" 54 #include "pcpeccp.h" 55 56 /*F* 57 // Name: ippsECCPSet 58 // 59 // Purpose: Set EC Domain Parameters. 60 // 61 // Returns: Reason: 62 // ippStsNullPtrErr NULL == pPrime 63 // NULL == pA 64 // NULL == pB 65 // NULL == pGX 66 // NULL == pGY 67 // NULL == pOrder 68 // NULL == pECC 69 // 70 // ippStsContextMatchErr illegal pPrime->idCtx 71 // illegal pA->idCtx 72 // illegal pB->idCtx 73 // illegal pGX->idCtx 74 // illegal pGY->idCtx 75 // illegal pOrder->idCtx 76 // illegal pECC->idCtx 77 // 78 // ippStsRangeErr not enough room for: 79 // pPrime 80 // pA, pB, 81 // pGX,pGY 82 // pOrder 83 // 84 // ippStsRangeErr 0>= cofactor 85 // 86 // ippStsNoErr no errors 87 // 88 // Parameters: 89 // pPrime pointer to the prime (specify FG(p)) 90 // pA pointer to the A coefficient of EC equation 91 // pB pointer to the B coefficient of EC equation 92 // pGX,pGY pointer to the Base Point (x and y coordinates) of EC 93 // pOrder pointer to the Base Point order 94 // cofactor cofactor value 95 // pECC pointer to the ECC context 96 // 97 *F*/ 98 IppStatus ECCPSetDP(const IppsGFpMethod* method, 99 int pLen, const BNU_CHUNK_T* pP, 100 int aLen, const BNU_CHUNK_T* pA, 101 int bLen, const BNU_CHUNK_T* pB, 102 int xLen, const BNU_CHUNK_T* pX, 103 int yLen, const BNU_CHUNK_T* pY, 104 int rLen, const BNU_CHUNK_T* pR, 105 BNU_CHUNK_T h, 106 IppsGFpECState* pEC) 107 { 108 IPP_BADARG_RET(!ECP_TEST_ID(pEC), ippStsContextMatchErr); 109 110 { 111 IppsGFpState * pGF = ECP_GFP(pEC); 112 113 IppStatus sts = ippStsNoErr; 114 IppsBigNumState P, H; 115 int primeBitSize = BITSIZE_BNU(pP, pLen); 116 //cpConstructBN(&P, pLen, (BNU_CHUNK_T*)pP, NULL); 117 //sts = cpGFpSetGFp(&P, primeBitSize, method, pGF); 118 cpGFpSetGFp(pP, primeBitSize, method, pGF); 119 120 if(ippStsNoErr==sts) { 121 gsModEngine* pGFE = GFP_PMA(pGF); 122 123 do { 124 int elemLen = GFP_FELEN(pGFE); 125 IppsGFpElement elmA, elmB; 126 127 /* convert A ans B coeffs into GF elements */ 128 cpGFpElementConstruct(&elmA, cpGFpGetPool(1, pGFE), elemLen); 129 cpGFpElementConstruct(&elmB, cpGFpGetPool(1, pGFE), elemLen); 130 sts = ippsGFpSetElement((Ipp32u*)pA, BITS2WORD32_SIZE(BITSIZE_BNU(pA,aLen)), &elmA, pGF); 131 if(ippStsNoErr!=sts) break; 132 sts = ippsGFpSetElement((Ipp32u*)pB, BITS2WORD32_SIZE(BITSIZE_BNU(pB,bLen)), &elmB, pGF); 133 if(ippStsNoErr!=sts) break; 134 /* and set EC */ 135 sts = ippsGFpECSet(&elmA, &elmB, pEC); 136 if(ippStsNoErr!=sts) break; 137 138 /* convert GX ans GY coeffs into GF elements */ 139 cpConstructBN(&P, rLen, (BNU_CHUNK_T*)pR, NULL); 140 cpConstructBN(&H, 1, &h, NULL); 141 sts = ippsGFpSetElement((Ipp32u*)pX, BITS2WORD32_SIZE(BITSIZE_BNU(pX,xLen)), &elmA, pGF); 142 if(ippStsNoErr!=sts) break; 143 sts = ippsGFpSetElement((Ipp32u*)pY, BITS2WORD32_SIZE(BITSIZE_BNU(pY,yLen)), &elmB, pGF); 144 if(ippStsNoErr!=sts) break; 145 /* and init EC subgroup */ 146 sts = ippsGFpECSetSubgroup(&elmA, &elmB, &P, &H, pEC); 147 } while(0); 148 149 cpGFpReleasePool(2, pGFE); 150 } 151 152 return sts; 153 } 154 } 155