Imported Upstream version 3.13.6
[platform/upstream/nss.git] / mozilla / security / nss / lib / pk11wrap / pk11pqg.h
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is the Netscape security libraries.
15  *
16  * The Initial Developer of the Original Code is
17  * Netscape Communications Corporation.
18  * Portions created by the Initial Developer are Copyright (C) 1994-2001
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPL"), or
25  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26  * in which case the provisions of the GPL or the LGPL are applicable instead
27  * of those above. If you wish to allow use of your version of this file only
28  * under the terms of either the GPL or the LGPL, and not to allow others to
29  * use your version of this file under the terms of the MPL, indicate your
30  * decision by deleting the provisions above and replace them with the notice
31  * and other provisions required by the GPL or the LGPL. If you do not delete
32  * the provisions above, a recipient may use your version of this file under
33  * the terms of any one of the MPL, the GPL or the LGPL.
34  *
35  * ***** END LICENSE BLOCK ***** */
36 /* Thse functions are stub functions which will get replaced with calls through
37  * PKCS #11.
38  */
39
40 #ifndef _PK11PQG_H_
41 #define  _PK11PQG_H_ 1
42
43 #include "blapit.h"
44
45 SEC_BEGIN_PROTOS
46
47 /* Generate PQGParams and PQGVerify structs.
48  * Length of seed and length of h both equal length of P. 
49  * All lengths are specified by "j", according to the table above.
50  */
51 extern SECStatus PK11_PQG_ParamGen(unsigned int j, PQGParams **pParams, 
52                                                         PQGVerify **pVfy);
53
54 /* Generate PQGParams and PQGVerify structs.
55  * Length of P specified by j.  Length of h will match length of P.
56  * Length of SEED in bytes specified in seedBytes.
57  * seedBbytes must be in the range [20..255] or an error will result.
58  */
59 extern SECStatus PK11_PQG_ParamGenSeedLen( unsigned int j, 
60         unsigned int seedBytes, PQGParams **pParams, PQGVerify **pVfy);
61
62 /*  Test PQGParams for validity as DSS PQG values.
63  *  If vfy is non-NULL, test PQGParams to make sure they were generated
64  *       using the specified seed, counter, and h values.
65  *
66  *  Return value indicates whether Verification operation ran successfully
67  *  to completion, but does not indicate if PQGParams are valid or not.
68  *  If return value is SECSuccess, then *pResult has these meanings:
69  *       SECSuccess: PQGParams are valid.
70  *       SECFailure: PQGParams are invalid.
71  *
72  * Verify the following 12 facts about PQG counter SEED g and h
73  * 1.  Q is 160 bits long.
74  * 2.  P is one of the 9 valid lengths.
75  * 3.  G < P
76  * 4.  P % Q == 1
77  * 5.  Q is prime
78  * 6.  P is prime
79  * Steps 7-12 are done only if the optional PQGVerify is supplied.
80  * 7.  counter < 4096
81  * 8.  g >= 160 and g < 2048   (g is length of seed in bits)
82  * 9.  Q generated from SEED matches Q in PQGParams.
83  * 10. P generated from (L, counter, g, SEED, Q) matches P in PQGParams.
84  * 11. 1 < h < P-1
85  * 12. G generated from h matches G in PQGParams.
86  */
87
88 extern SECStatus PK11_PQG_VerifyParams(const PQGParams *params, 
89                                     const PQGVerify *vfy, SECStatus *result);
90 extern void PK11_PQG_DestroyParams(PQGParams *params);
91 extern void PK11_PQG_DestroyVerify(PQGVerify *vfy);
92
93 /**************************************************************************
94  *  Return a pointer to a new PQGParams struct that is constructed from   *
95  *  copies of the arguments passed in.                                    *
96  *  Return NULL on failure.                                               *
97  **************************************************************************/
98 extern PQGParams * PK11_PQG_NewParams(const SECItem * prime, const 
99                                 SECItem * subPrime, const SECItem * base);
100
101
102 /**************************************************************************
103  * Fills in caller's "prime" SECItem with the prime value in params.
104  * Contents can be freed by calling SECITEM_FreeItem(prime, PR_FALSE);  
105  **************************************************************************/
106 extern SECStatus PK11_PQG_GetPrimeFromParams(const PQGParams *params, 
107                                                         SECItem * prime);
108
109
110 /**************************************************************************
111  * Fills in caller's "subPrime" SECItem with the prime value in params.
112  * Contents can be freed by calling SECITEM_FreeItem(subPrime, PR_FALSE);       
113  **************************************************************************/
114 extern SECStatus PK11_PQG_GetSubPrimeFromParams(const PQGParams *params, 
115                                                         SECItem * subPrime);
116
117
118 /**************************************************************************
119  * Fills in caller's "base" SECItem with the base value in params.
120  * Contents can be freed by calling SECITEM_FreeItem(base, PR_FALSE);   
121  **************************************************************************/
122 extern SECStatus PK11_PQG_GetBaseFromParams(const PQGParams *params, 
123                                                         SECItem *base);
124
125
126 /**************************************************************************
127  *  Return a pointer to a new PQGVerify struct that is constructed from   *
128  *  copies of the arguments passed in.                                    *
129  *  Return NULL on failure.                                               *
130  **************************************************************************/
131 extern PQGVerify * PK11_PQG_NewVerify(unsigned int counter, 
132                                 const SECItem * seed, const SECItem * h);
133
134
135 /**************************************************************************
136  * Returns "counter" value from the PQGVerify.
137  **************************************************************************/
138 extern unsigned int PK11_PQG_GetCounterFromVerify(const PQGVerify *verify);
139
140 /**************************************************************************
141  * Fills in caller's "seed" SECItem with the seed value in verify.
142  * Contents can be freed by calling SECITEM_FreeItem(seed, PR_FALSE);   
143  **************************************************************************/
144 extern SECStatus PK11_PQG_GetSeedFromVerify(const PQGVerify *verify, 
145                                                         SECItem *seed);
146
147 /**************************************************************************
148  * Fills in caller's "h" SECItem with the h value in verify.
149  * Contents can be freed by calling SECITEM_FreeItem(h, PR_FALSE);      
150  **************************************************************************/
151 extern SECStatus PK11_PQG_GetHFromVerify(const PQGVerify *verify, SECItem * h);
152
153 SEC_END_PROTOS
154
155 #endif