~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/security/nss/lib/cryptohi/cryptohi.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * crypto.h - public data structures and prototypes for the crypto library
 
3
 *
 
4
 * The contents of this file are subject to the Mozilla Public
 
5
 * License Version 1.1 (the "License"); you may not use this file
 
6
 * except in compliance with the License. You may obtain a copy of
 
7
 * the License at http://www.mozilla.org/MPL/
 
8
 * 
 
9
 * Software distributed under the License is distributed on an "AS
 
10
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
11
 * implied. See the License for the specific language governing
 
12
 * rights and limitations under the License.
 
13
 * 
 
14
 * The Original Code is the Netscape security libraries.
 
15
 * 
 
16
 * The Initial Developer of the Original Code is Netscape
 
17
 * Communications Corporation.  Portions created by Netscape are 
 
18
 * Copyright (C) 1994-2000 Netscape Communications Corporation.  All
 
19
 * Rights Reserved.
 
20
 * 
 
21
 * Portions created by Sun Microsystems, Inc. are Copyright (C) 2003
 
22
 * Sun Microsystems, Inc. All Rights Reserved. 
 
23
 * 
 
24
 * Contributor(s):
 
25
 *      Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
 
26
 * 
 
27
 * Alternatively, the contents of this file may be used under the
 
28
 * terms of the GNU General Public License Version 2 or later (the
 
29
 * "GPL"), in which case the provisions of the GPL are applicable 
 
30
 * instead of those above.  If you wish to allow use of your 
 
31
 * version of this file only under the terms of the GPL and not to
 
32
 * allow others to use your version of this file under the MPL,
 
33
 * indicate your decision by deleting the provisions above and
 
34
 * replace them with the notice and other provisions required by
 
35
 * the GPL.  If you do not delete the provisions above, a recipient
 
36
 * may use your version of this file under either the MPL or the
 
37
 * GPL.
 
38
 *
 
39
 * $Id: cryptohi.h,v 1.6 2003/10/17 13:45:32 ian.mcgreer%sun.com Exp $
 
40
 */
 
41
 
 
42
#ifndef _CRYPTOHI_H_
 
43
#define _CRYPTOHI_H_
 
44
 
 
45
#include "blapit.h"
 
46
 
 
47
#include "seccomon.h"
 
48
#include "secoidt.h"
 
49
#include "secdert.h"
 
50
#include "cryptoht.h"
 
51
#include "keyt.h"
 
52
#include "certt.h"
 
53
 
 
54
 
 
55
SEC_BEGIN_PROTOS
 
56
 
 
57
 
 
58
/****************************************/
 
59
/*
 
60
** DER encode/decode (EC)DSA signatures
 
61
*/
 
62
 
 
63
/* ANSI X9.57 defines DSA signatures as DER encoded data.  Our DSA code (and
 
64
 * most of the rest of the world) just generates 40 bytes of raw data.  These
 
65
 * functions convert between formats.
 
66
 */
 
67
extern SECStatus DSAU_EncodeDerSig(SECItem *dest, SECItem *src);
 
68
extern SECItem *DSAU_DecodeDerSig(SECItem *item);
 
69
 
 
70
/*
 
71
 * Unlike DSA, raw ECDSA signatures do not have a fixed length.
 
72
 * Rather they contain two integers r and s whose length depends
 
73
 * on the size of the EC key used for signing.
 
74
 *
 
75
 * We can reuse the DSAU_EncodeDerSig interface to DER encode
 
76
 * raw ECDSA signature keeping in mind that the length of r 
 
77
 * is the same as that of s and exactly half of src->len.
 
78
 *
 
79
 * For decoding, we need to pass the length of the desired
 
80
 * raw signature (twice the key size) explicitly.
 
81
 */
 
82
extern SECStatus DSAU_EncodeDerSigWithLen(SECItem *dest, SECItem *src, 
 
83
                                          unsigned int len);
 
84
extern SECItem *DSAU_DecodeDerSigToLen(SECItem *item, unsigned int len);
 
85
 
 
86
/****************************************/
 
87
/*
 
88
** Signature creation operations
 
89
*/
 
90
 
 
91
/*
 
92
** Create a new signature context used for signing a data stream.
 
93
**      "alg" the signature algorithm to use (e.g. SEC_OID_RSA_WITH_MD5)
 
94
**      "privKey" the private key to use
 
95
*/
 
96
extern SGNContext *SGN_NewContext(SECOidTag alg, SECKEYPrivateKey *privKey);
 
97
 
 
98
/*
 
99
** Destroy a signature-context object
 
100
**      "key" the object
 
101
**      "freeit" if PR_TRUE then free the object as well as its sub-objects
 
102
*/
 
103
extern void SGN_DestroyContext(SGNContext *cx, PRBool freeit);
 
104
 
 
105
/*
 
106
** Reset the signing context "cx" to its initial state, preparing it for
 
107
** another stream of data.
 
108
*/
 
109
extern SECStatus SGN_Begin(SGNContext *cx);
 
110
 
 
111
/*
 
112
** Update the signing context with more data to sign.
 
113
**      "cx" the context
 
114
**      "input" the input data to sign
 
115
**      "inputLen" the length of the input data
 
116
*/
 
117
extern SECStatus SGN_Update(SGNContext *cx, unsigned char *input,
 
118
                           unsigned int inputLen);
 
119
 
 
120
/*
 
121
** Finish the signature process. Use either k0 or k1 to sign the data
 
122
** stream that was input using SGN_Update. The resulting signature is
 
123
** formatted using PKCS#1 and then encrypted using RSA private or public
 
124
** encryption.
 
125
**      "cx" the context
 
126
**      "result" the final signature data (memory is allocated)
 
127
*/
 
128
extern SECStatus SGN_End(SGNContext *cx, SECItem *result);
 
129
 
 
130
/*
 
131
** Sign a single block of data using private key encryption and given
 
132
** signature/hash algorithm.
 
133
**      "result" the final signature data (memory is allocated)
 
134
**      "buf" the input data to sign
 
135
**      "len" the amount of data to sign
 
136
**      "pk" the private key to encrypt with
 
137
**      "algid" the signature/hash algorithm to sign with 
 
138
**              (must be compatible with the key type).
 
139
*/
 
140
extern SECStatus SEC_SignData(SECItem *result, unsigned char *buf, int len,
 
141
                             SECKEYPrivateKey *pk, SECOidTag algid);
 
142
 
 
143
/*
 
144
** Sign a pre-digested block of data using private key encryption, encoding
 
145
**  The given signature/hash algorithm.
 
146
**      "result" the final signature data (memory is allocated)
 
147
**      "digest" the digest to sign
 
148
**      "pk" the private key to encrypt with
 
149
**      "algtag" The algorithm tag to encode (need for RSA only)
 
150
*/
 
151
extern SECStatus SGN_Digest(SECKEYPrivateKey *privKey,
 
152
                SECOidTag algtag, SECItem *result, SECItem *digest);
 
153
 
 
154
/*
 
155
** DER sign a single block of data using private key encryption and the
 
156
** MD5 hashing algorithm. This routine first computes a digital signature
 
157
** using SEC_SignData, then wraps it with an CERTSignedData and then der
 
158
** encodes the result.
 
159
**      "arena" is the memory arena to use to allocate data from
 
160
**      "result" the final der encoded data (memory is allocated)
 
161
**      "buf" the input data to sign
 
162
**      "len" the amount of data to sign
 
163
**      "pk" the private key to encrypt with
 
164
*/
 
165
extern SECStatus SEC_DerSignData(PRArenaPool *arena, SECItem *result,
 
166
                                unsigned char *buf, int len,
 
167
                                SECKEYPrivateKey *pk, SECOidTag algid);
 
168
 
 
169
/*
 
170
** Destroy a signed-data object.
 
171
**      "sd" the object
 
172
**      "freeit" if PR_TRUE then free the object as well as its sub-objects
 
173
*/
 
174
extern void SEC_DestroySignedData(CERTSignedData *sd, PRBool freeit);
 
175
 
 
176
/****************************************/
 
177
/*
 
178
** Signature verification operations
 
179
*/
 
180
 
 
181
/*
 
182
** Create a signature verification context.
 
183
**      "key" the public key to verify with
 
184
**      "sig" the encrypted signature data if sig is NULL then
 
185
**         VFY_EndWithSignature must be called with the correct signature at
 
186
**         the end of the processing.
 
187
**      "algid" specifies the signing algorithm to use.  This must match
 
188
**          the key type.
 
189
**      "wincx" void pointer to the window context
 
190
*/
 
191
extern VFYContext *VFY_CreateContext(SECKEYPublicKey *key, SECItem *sig,
 
192
                                     SECOidTag algid, void *wincx);
 
193
 
 
194
/*
 
195
** Destroy a verification-context object.
 
196
**      "cx" the context to destroy
 
197
**      "freeit" if PR_TRUE then free the object as well as its sub-objects
 
198
*/
 
199
extern void VFY_DestroyContext(VFYContext *cx, PRBool freeit);
 
200
 
 
201
extern SECStatus VFY_Begin(VFYContext *cx);
 
202
 
 
203
/*
 
204
** Update a verification context with more input data. The input data
 
205
** is fed to a secure hash function (depending on what was in the
 
206
** encrypted signature data).
 
207
**      "cx" the context
 
208
**      "input" the input data
 
209
**      "inputLen" the amount of input data
 
210
*/
 
211
extern SECStatus VFY_Update(VFYContext *cx, unsigned char *input,
 
212
                            unsigned int inputLen);
 
213
 
 
214
/*
 
215
** Finish the verification process. The return value is a status which
 
216
** indicates success or failure. On success, the SECSuccess value is
 
217
** returned. Otherwise, SECFailure is returned and the error code found
 
218
** using PORT_GetError() indicates what failure occurred.
 
219
**      "cx" the context
 
220
*/
 
221
extern SECStatus VFY_End(VFYContext *cx);
 
222
 
 
223
/*
 
224
** Finish the verification process. The return value is a status which
 
225
** indicates success or failure. On success, the SECSuccess value is
 
226
** returned. Otherwise, SECFailure is returned and the error code found
 
227
** using PORT_GetError() indicates what failure occurred. If signature is
 
228
** supplied the verification uses this signature to verify, otherwise the
 
229
** signature passed in VFY_CreateContext() is used. 
 
230
** VFY_EndWithSignature(cx,NULL); is identical to VFY_End(cx);.
 
231
**      "cx" the context
 
232
**      "sig" the encrypted signature data
 
233
*/
 
234
extern SECStatus VFY_EndWithSignature(VFYContext *cx, SECItem *sig);
 
235
 
 
236
 
 
237
/*
 
238
** Verify the signature on a block of data for which we already have
 
239
** the digest. The signature data is an RSA private key encrypted
 
240
** block of data formatted according to PKCS#1.
 
241
**      "dig" the digest
 
242
**      "key" the public key to check the signature with
 
243
**      "sig" the encrypted signature data
 
244
**      "algid" specifies the signing algorithm to use.  This must match
 
245
**          the key type.
 
246
**/
 
247
extern SECStatus VFY_VerifyDigest(SECItem *dig, SECKEYPublicKey *key,
 
248
                                  SECItem *sig, SECOidTag algid, void *wincx);
 
249
 
 
250
/*
 
251
** Verify the signature on a block of data. The signature data is an RSA
 
252
** private key encrypted block of data formatted according to PKCS#1.
 
253
**      "buf" the input data
 
254
**      "len" the length of the input data
 
255
**      "key" the public key to check the signature with
 
256
**      "sig" the encrypted signature data
 
257
**      "algid" specifies the signing algorithm to use.  This must match
 
258
**          the key type.
 
259
*/
 
260
extern SECStatus VFY_VerifyData(unsigned char *buf, int len,
 
261
                                SECKEYPublicKey *key, SECItem *sig,
 
262
                                SECOidTag algid, void *wincx);
 
263
 
 
264
 
 
265
SEC_END_PROTOS
 
266
 
 
267
#endif /* _CRYPTOHI_H_ */