• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2 * Copyright 2013-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 //     Internal Definitions and
46 //     Internal ng RSA Function Prototypes
47 //
48 //
49 */
50 
51 #if !defined(_CP_NG_RSA_H)
52 #define _CP_NG_RSA_H
53 
54 #include "pcpbn.h"
55 #include "pcpmontgomery.h"
56 #include "pcpngmontexpstuff.h"
57 
58 struct _cpRSA_public_key {
59    IppCtxId       id;            /* key ID */
60    int         maxbitSizeN;
61    int         maxbitSizeE;
62    int            bitSizeN;      /* RSA modulus bitsize */
63    int            bitSizeE;      /* RSA public exp bitsize */
64 
65    BNU_CHUNK_T*   pDataE;        /* public exp */
66    gsModEngine*   pMontN;        /* montgomery engine (N) */
67 };
68 
69 /* access */
70 #define RSA_PUB_KEY_MAXSIZE_N(x) ((x)->maxbitSizeN)
71 #define RSA_PUB_KEY_MAXSIZE_E(x) ((x)->maxbitSizeE)
72 #define RSA_PUB_KEY_ID(x)        ((x)->id)
73 #define RSA_PUB_KEY_BITSIZE_N(x) ((x)->bitSizeN)
74 #define RSA_PUB_KEY_BITSIZE_E(x) ((x)->bitSizeE)
75 #define RSA_PUB_KEY_E(x)         ((x)->pDataE)
76 #define RSA_PUB_KEY_NMONT(x)     ((x)->pMontN)
77 #define RSA_PUB_KEY_VALID_ID(x)  (RSA_PUB_KEY_ID((x))==idCtxRSA_PubKey)
78 #define RSA_PUB_KEY_IS_SET(x)    (RSA_PUB_KEY_BITSIZE_N((x))>0)
79 
80 /* alignment */
81 #define RSA_PUBLIC_KEY_ALIGNMENT ((int)(sizeof(void*)))
82 
83 struct _cpRSA_private_key {
84    IppCtxId       id;            /* key ID */
85    int         maxbitSizeN;
86    int         maxbitSizeD;
87    int            bitSizeN;      /* RSA modulus bitsize */
88    int            bitSizeD;      /* RSA private exp bitsize */
89    int            bitSizeP;      /* RSA p-factor bitsize */
90    int            bitSizeQ;      /* RSA q-factor bitsize */
91 
92    BNU_CHUNK_T*   pDataD;        /* private exp */
93    BNU_CHUNK_T*   pDataDp;       /* dp private exp */
94    BNU_CHUNK_T*   pDataDq;       /* dq private exp */
95    BNU_CHUNK_T*   pDataQinv;     /* qinv coeff */
96 
97    gsModEngine* pMontP;          /* montgomery engine (P) */
98    gsModEngine* pMontQ;          /* montgomery engine (Q) */
99    gsModEngine* pMontN;          /* montgomery engine (N) */
100 };
101 
102 /* access */
103 #define RSA_PRV_KEY_MAXSIZE_N(x) ((x)->maxbitSizeN)
104 #define RSA_PRV_KEY_MAXSIZE_D(x) ((x)->maxbitSizeD)
105 #define RSA_PRV_KEY_ID(x)        ((x)->id)
106 #define RSA_PRV_KEY_BITSIZE_N(x) ((x)->bitSizeN)
107 #define RSA_PRV_KEY_BITSIZE_D(x) ((x)->bitSizeD)
108 #define RSA_PRV_KEY_BITSIZE_P(x) ((x)->bitSizeP)
109 #define RSA_PRV_KEY_BITSIZE_Q(x) ((x)->bitSizeQ)
110 #define RSA_PRV_KEY_D(x)         ((x)->pDataD)
111 #define RSA_PRV_KEY_DP(x)        ((x)->pDataDp)
112 #define RSA_PRV_KEY_DQ(x)        ((x)->pDataDq)
113 #define RSA_PRV_KEY_INVQ(x)      ((x)->pDataQinv)
114 #define RSA_PRV_KEY_PMONT(x)     ((x)->pMontP)
115 #define RSA_PRV_KEY_QMONT(x)     ((x)->pMontQ)
116 #define RSA_PRV_KEY_NMONT(x)     ((x)->pMontN)
117 #define RSA_PRV_KEY1_VALID_ID(x) (RSA_PRV_KEY_ID((x))==idCtxRSA_PrvKey1)
118 #define RSA_PRV_KEY2_VALID_ID(x) (RSA_PRV_KEY_ID((x))==idCtxRSA_PrvKey2)
119 #define RSA_PRV_KEY_VALID_ID(x)  (RSA_PRV_KEY1_VALID_ID((x)) || RSA_PRV_KEY2_VALID_ID((x)))
120 #define RSA_PRV_KEY_IS_SET(x)    (RSA_PRV_KEY_BITSIZE_N((x))>0)
121 
122 /* alignment */
123 #define RSA_PRIVATE_KEY_ALIGNMENT ((int)(sizeof(void*)))
124 
125 #define MOD_ENGINE_RSA_POOL_SIZE    (2)
126 
127 /*
128 // Montgomery engine preparation (GetSize/init/Set)
129 */
130 #define rsaMontExpGetSize OWNAPI(rsaMontExpGetSize)
131 void rsaMontExpGetSize(int length, int* pSize);
132 
133 /*
134 // pubic and private key operations
135 */
136 #define gsRSApub_cipher OWNAPI(gsRSApub_cipher)
137 void    gsRSApub_cipher(IppsBigNumState* pY, const IppsBigNumState* pX, const IppsRSAPublicKeyState* pKey, BNU_CHUNK_T* pScratchBuffer);
138 
139 #define gsRSAprv_cipher OWNAPI(gsRSAprv_cipher)
140 void    gsRSAprv_cipher(IppsBigNumState* pY, const IppsBigNumState* pX, const IppsRSAPrivateKeyState* pKey, BNU_CHUNK_T* pScratchBuffer);
141 
142 #define gsRSAprv_cipher_crt OWNAPI(gsRSAprv_cipher_crt)
143 void    gsRSAprv_cipher_crt(IppsBigNumState* pY, const IppsBigNumState* pX, const IppsRSAPrivateKeyState* pKey, BNU_CHUNK_T* pScratchBuffer);
144 
145 #endif /* _CP_NG_RSA_H */
146