~ubuntu-branches/ubuntu/trusty/xulrunner/trusty

« back to all changes in this revision

Viewing changes to security/nss-fips/lib/softoken/lowkeyi.h

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2008-08-25 13:04:18 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20080825130418-ck1i2ms384tzb9m0
Tags: 1.8.1.16+nobinonly-0ubuntu1
* New upstream release (taken from upstream CVS), LP: #254618.
* Fix MFSA 2008-35, MFSA 2008-34, MFSA 2008-33, MFSA 2008-32, MFSA 2008-31,
  MFSA 2008-30, MFSA 2008-29, MFSA 2008-28, MFSA 2008-27, MFSA 2008-25,
  MFSA 2008-24, MFSA 2008-23, MFSA 2008-22, MFSA 2008-21, MFSA 2008-26 also
  known as CVE-2008-2933, CVE-2008-2785, CVE-2008-2811, CVE-2008-2810,
  CVE-2008-2809, CVE-2008-2808, CVE-2008-2807, CVE-2008-2806, CVE-2008-2805,
  CVE-2008-2803, CVE-2008-2802, CVE-2008-2801, CVE-2008-2800, CVE-2008-2798.
* Drop 89_bz419350_attachment_306066 patch, merged upstream.
* Bump Standards-Version to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2000
 
19
 * the Initial Developer. All Rights Reserved.
 
20
 *
 
21
 * Contributor(s):
 
22
 *   Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
 
23
 *
 
24
 * Alternatively, the contents of this file may be used under the terms of
 
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
28
 * of those above. If you wish to allow use of your version of this file only
 
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
30
 * use your version of this file under the terms of the MPL, indicate your
 
31
 * decision by deleting the provisions above and replace them with the notice
 
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
33
 * the provisions above, a recipient may use your version of this file under
 
34
 * the terms of any one of the MPL, the GPL or the LGPL.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
/* $Id: lowkeyi.h,v 1.10 2004/04/27 23:04:38 gerv%gerv.net Exp $ */
 
38
 
 
39
#ifndef _LOWKEYI_H_
 
40
#define _LOWKEYI_H_
 
41
 
 
42
#include "prtypes.h"
 
43
#include "seccomon.h"
 
44
#include "secoidt.h"
 
45
#include "pcertt.h"
 
46
#include "lowkeyti.h"
 
47
 
 
48
SEC_BEGIN_PROTOS
 
49
 
 
50
/*
 
51
 * See bugzilla bug 125359
 
52
 * Since NSS (via PKCS#11) wants to handle big integers as unsigned ints,
 
53
 * all of the templates above that en/decode into integers must be converted
 
54
 * from ASN.1's signed integer type.  This is done by marking either the
 
55
 * source or destination (encoding or decoding, respectively) type as
 
56
 * siUnsignedInteger.
 
57
 */
 
58
extern void prepare_low_rsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
 
59
extern void prepare_low_pqg_params_for_asn1(PQGParams *params);
 
60
extern void prepare_low_dsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
 
61
extern void prepare_low_dsa_priv_key_export_for_asn1(NSSLOWKEYPrivateKey *key);
 
62
extern void prepare_low_dh_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
 
63
#ifdef NSS_ENABLE_ECC
 
64
extern void prepare_low_ec_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
 
65
extern void prepare_low_ecparams_for_asn1(ECParams *params);
 
66
#endif /* NSS_ENABLE_ECC */
 
67
 
 
68
typedef char * (* NSSLOWKEYDBNameFunc)(void *arg, int dbVersion);
 
69
    
 
70
/*
 
71
** Open a key database.
 
72
*/
 
73
extern NSSLOWKEYDBHandle *nsslowkey_OpenKeyDB(PRBool readOnly,
 
74
                                           const char *domain,
 
75
                                           const char *prefix,
 
76
                                           NSSLOWKEYDBNameFunc namecb,
 
77
                                           void *cbarg);
 
78
 
 
79
 
 
80
/*
 
81
 * Clear out all the keys in the existing database
 
82
 */
 
83
extern SECStatus nsslowkey_ResetKeyDB(NSSLOWKEYDBHandle *handle);
 
84
 
 
85
/*
 
86
** Close the specified key database.
 
87
*/
 
88
extern void nsslowkey_CloseKeyDB(NSSLOWKEYDBHandle *handle);
 
89
 
 
90
/*
 
91
 * Get the version number of the database
 
92
 */
 
93
extern int nsslowkey_GetKeyDBVersion(NSSLOWKEYDBHandle *handle);
 
94
 
 
95
/*
 
96
** Support a default key database.
 
97
*/
 
98
extern void nsslowkey_SetDefaultKeyDB(NSSLOWKEYDBHandle *handle);
 
99
extern NSSLOWKEYDBHandle *nsslowkey_GetDefaultKeyDB(void);
 
100
 
 
101
/* set the alg id of the key encryption algorithm */
 
102
extern void nsslowkey_SetDefaultKeyDBAlg(SECOidTag alg);
 
103
 
 
104
/*
 
105
 * given a password and salt, produce a hash of the password
 
106
 */
 
107
extern SECItem *nsslowkey_HashPassword(char *pw, SECItem *salt);
 
108
 
 
109
/*
 
110
 * Derive the actual password value for a key database from the
 
111
 * password string value.  The derivation uses global salt value
 
112
 * stored in the key database.
 
113
 */
 
114
extern SECItem *
 
115
nsslowkey_DeriveKeyDBPassword(NSSLOWKEYDBHandle *handle, char *pw);
 
116
 
 
117
/*
 
118
** Delete a key from the database
 
119
*/
 
120
extern SECStatus nsslowkey_DeleteKey(NSSLOWKEYDBHandle *handle, 
 
121
                                  SECItem *pubkey);
 
122
 
 
123
/*
 
124
** Store a key in the database, indexed by its public key modulus.
 
125
**      "pk" is the private key to store
 
126
**      "f" is a the callback function for getting the password
 
127
**      "arg" is the argument for the callback
 
128
*/
 
129
extern SECStatus nsslowkey_StoreKeyByPublicKey(NSSLOWKEYDBHandle *handle, 
 
130
                                            NSSLOWKEYPrivateKey *pk,
 
131
                                            SECItem *pubKeyData,
 
132
                                            char *nickname,
 
133
                                            SECItem *arg);
 
134
 
 
135
/* does the key for this cert exist in the database filed by modulus */
 
136
extern PRBool nsslowkey_KeyForCertExists(NSSLOWKEYDBHandle *handle,
 
137
                                         NSSLOWCERTCertificate *cert);
 
138
/* does a key with this ID already exist? */
 
139
extern PRBool nsslowkey_KeyForIDExists(NSSLOWKEYDBHandle *handle, SECItem *id);
 
140
 
 
141
 
 
142
extern SECStatus nsslowkey_HasKeyDBPassword(NSSLOWKEYDBHandle *handle);
 
143
extern SECStatus nsslowkey_SetKeyDBPassword(NSSLOWKEYDBHandle *handle,
 
144
                                     SECItem *pwitem);
 
145
extern SECStatus nsslowkey_CheckKeyDBPassword(NSSLOWKEYDBHandle *handle,
 
146
                                           SECItem *pwitem);
 
147
extern SECStatus nsslowkey_ChangeKeyDBPassword(NSSLOWKEYDBHandle *handle,
 
148
                                            SECItem *oldpwitem,
 
149
                                            SECItem *newpwitem);
 
150
 
 
151
/*
 
152
** Destroy a private key object.
 
153
**      "key" the object
 
154
**      "freeit" if PR_TRUE then free the object as well as its sub-objects
 
155
*/
 
156
extern void nsslowkey_DestroyPrivateKey(NSSLOWKEYPrivateKey *key);
 
157
 
 
158
/*
 
159
** Destroy a public key object.
 
160
**      "key" the object
 
161
**      "freeit" if PR_TRUE then free the object as well as its sub-objects
 
162
*/
 
163
extern void nsslowkey_DestroyPublicKey(NSSLOWKEYPublicKey *key);
 
164
 
 
165
/*
 
166
** Return the modulus length of "pubKey".
 
167
*/
 
168
extern unsigned int nsslowkey_PublicModulusLen(NSSLOWKEYPublicKey *pubKey);
 
169
 
 
170
 
 
171
/*
 
172
** Return the modulus length of "privKey".
 
173
*/
 
174
extern unsigned int nsslowkey_PrivateModulusLen(NSSLOWKEYPrivateKey *privKey);
 
175
 
 
176
 
 
177
/*
 
178
** Convert a low private key "privateKey" into a public low key
 
179
*/
 
180
extern NSSLOWKEYPublicKey 
 
181
                *nsslowkey_ConvertToPublicKey(NSSLOWKEYPrivateKey *privateKey);
 
182
 
 
183
/*
 
184
 * Set the Key Database password.
 
185
 *   handle is a handle to the key database
 
186
 *   pwitem is the new password
 
187
 *   algorithm is the algorithm by which the key database 
 
188
 *      password is to be encrypted.
 
189
 * On failure, SECFailure is returned, otherwise SECSuccess is 
 
190
 * returned.
 
191
 */
 
192
extern SECStatus 
 
193
nsslowkey_SetKeyDBPasswordAlg(NSSLOWKEYDBHandle *handle,
 
194
                        SECItem *pwitem, 
 
195
                        SECOidTag algorithm);
 
196
 
 
197
/* Check the key database password.
 
198
 *   handle is a handle to the key database
 
199
 *   pwitem is the suspect password
 
200
 *   algorithm is the algorithm by which the key database 
 
201
 *      password is to be encrypted.
 
202
 * The password is checked against plaintext to see if it is the
 
203
 * actual password.  If it is not, SECFailure is returned.
 
204
 */
 
205
extern SECStatus 
 
206
nsslowkey_CheckKeyDBPasswordAlg(NSSLOWKEYDBHandle *handle,
 
207
                                SECItem *pwitem, 
 
208
                                SECOidTag algorithm);
 
209
 
 
210
/* Change the key database password and/or algorithm by which
 
211
 * the password is stored with.  
 
212
 *   handle is a handle to the key database
 
213
 *   old_pwitem is the current password
 
214
 *   new_pwitem is the new password
 
215
 *   old_algorithm is the algorithm by which the key database 
 
216
 *      password is currently encrypted.
 
217
 *   new_algorithm is the algorithm with which the new password
 
218
 *      is to be encrypted.
 
219
 * A return of anything but SECSuccess indicates failure.
 
220
 */
 
221
extern SECStatus 
 
222
nsslowkey_ChangeKeyDBPasswordAlg(NSSLOWKEYDBHandle *handle,
 
223
                              SECItem *oldpwitem, SECItem *newpwitem,
 
224
                              SECOidTag old_algorithm);
 
225
 
 
226
SECStatus
 
227
nsslowkey_UpdateNickname(NSSLOWKEYDBHandle *handle,
 
228
                           NSSLOWKEYPrivateKey *privkey,
 
229
                           SECItem *pubKeyData,
 
230
                           char *nickname,
 
231
                           SECItem *arg);
 
232
 
 
233
/* Store key by modulus and specify an encryption algorithm to use.
 
234
 *   handle is the pointer to the key database,
 
235
 *   privkey is the private key to be stored,
 
236
 *   f and arg are the function and arguments to the callback
 
237
 *       to get a password,
 
238
 *   algorithm is the algorithm which the privKey is to be stored.
 
239
 * A return of anything but SECSuccess indicates failure.
 
240
 */
 
241
extern SECStatus 
 
242
nsslowkey_StoreKeyByPublicKeyAlg(NSSLOWKEYDBHandle *handle, 
 
243
                              NSSLOWKEYPrivateKey *privkey, 
 
244
                              SECItem *pubKeyData,
 
245
                              char *nickname,
 
246
                              SECItem *arg,
 
247
                              SECOidTag algorithm,
 
248
                              PRBool update); 
 
249
 
 
250
/* Find key by modulus.  This function is the inverse of store key
 
251
 * by modulus.  An attempt to locate the key with "modulus" is 
 
252
 * performed.  If the key is found, the private key is returned,
 
253
 * else NULL is returned.
 
254
 *   modulus is the modulus to locate
 
255
 */
 
256
extern NSSLOWKEYPrivateKey *
 
257
nsslowkey_FindKeyByPublicKey(NSSLOWKEYDBHandle *handle, SECItem *modulus, 
 
258
                          SECItem *arg);
 
259
 
 
260
extern char *
 
261
nsslowkey_FindKeyNicknameByPublicKey(NSSLOWKEYDBHandle *handle,
 
262
                                        SECItem *modulus, SECItem *pwitem);
 
263
 
 
264
 
 
265
/* Make a copy of a low private key in it's own arena.
 
266
 * a return of NULL indicates an error.
 
267
 */
 
268
extern NSSLOWKEYPrivateKey *
 
269
nsslowkey_CopyPrivateKey(NSSLOWKEYPrivateKey *privKey);
 
270
 
 
271
 
 
272
SEC_END_PROTOS
 
273
 
 
274
#endif /* _LOWKEYI_H_ */