2000-03-31 20:13:40 +00:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Netscape security libraries.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
2003-02-27 01:31:38 +00:00
|
|
|
* Portions created by Sun Microsystems, Inc. are Copyright (C) 2003
|
|
|
|
* Sun Microsystems, Inc. All Rights Reserved.
|
|
|
|
*
|
2001-04-11 00:29:18 +00:00
|
|
|
* Contributor(s):
|
|
|
|
* Dr Stephen Henson <stephen.henson@gemplus.com>
|
2003-02-27 01:31:38 +00:00
|
|
|
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
|
2000-03-31 20:13:40 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the
|
|
|
|
* terms of the GNU General Public License Version 2 or later (the
|
|
|
|
* "GPL"), in which case the provisions of the GPL are applicable
|
|
|
|
* instead of those above. If you wish to allow use of your
|
|
|
|
* version of this file only under the terms of the GPL and not to
|
|
|
|
* allow others to use your version of this file under the MPL,
|
|
|
|
* indicate your decision by deleting the provisions above and
|
|
|
|
* replace them with the notice and other provisions required by
|
|
|
|
* the GPL. If you do not delete the provisions above, a recipient
|
|
|
|
* may use your version of this file under either the MPL or the
|
|
|
|
* GPL.
|
|
|
|
*
|
|
|
|
* key.h - public data structures and prototypes for the private key library
|
|
|
|
*
|
2004-01-22 02:19:42 +00:00
|
|
|
* $Id: keyhi.h,v 1.9 2004/01/22 02:19:42 nelsonb%netscape.com Exp $
|
2000-03-31 20:13:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _KEYHI_H_
|
|
|
|
#define _KEYHI_H_
|
|
|
|
|
|
|
|
#include "plarena.h"
|
|
|
|
|
|
|
|
#include "seccomon.h"
|
|
|
|
#include "secoidt.h"
|
|
|
|
#include "secdert.h"
|
|
|
|
#include "keythi.h"
|
|
|
|
#include "certt.h"
|
2001-09-20 21:30:48 +00:00
|
|
|
/*#include "secpkcs5.h" */
|
2000-03-31 20:13:40 +00:00
|
|
|
|
|
|
|
SEC_BEGIN_PROTOS
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Destroy a subject-public-key-info object.
|
|
|
|
*/
|
|
|
|
extern void SECKEY_DestroySubjectPublicKeyInfo(CERTSubjectPublicKeyInfo *spki);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Copy subject-public-key-info "src" to "dst". "dst" is filled in
|
|
|
|
** appropriately (memory is allocated for each of the sub objects).
|
|
|
|
*/
|
|
|
|
extern SECStatus SECKEY_CopySubjectPublicKeyInfo(PRArenaPool *arena,
|
|
|
|
CERTSubjectPublicKeyInfo *dst,
|
|
|
|
CERTSubjectPublicKeyInfo *src);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Update the PQG parameters for a cert's public key.
|
|
|
|
** Only done for DSA and Fortezza certs
|
|
|
|
*/
|
|
|
|
extern SECStatus
|
|
|
|
SECKEY_UpdateCertPQG(CERTCertificate * subjectCert);
|
|
|
|
|
|
|
|
|
|
|
|
/* Compare the KEA parameters of two public keys.
|
|
|
|
* Only used by fortezza. */
|
|
|
|
|
|
|
|
extern SECStatus
|
|
|
|
SECKEY_KEAParamCompare(CERTCertificate *cert1,CERTCertificate *cert2);
|
|
|
|
|
|
|
|
/*
|
2003-02-27 01:31:38 +00:00
|
|
|
** Return the strength of the public key in bytes
|
2000-03-31 20:13:40 +00:00
|
|
|
*/
|
|
|
|
extern unsigned SECKEY_PublicKeyStrength(SECKEYPublicKey *pubk);
|
|
|
|
|
2003-02-27 01:31:38 +00:00
|
|
|
/*
|
|
|
|
** Return the strength of the public key in bits
|
|
|
|
*/
|
|
|
|
extern unsigned SECKEY_PublicKeyStrengthInBits(SECKEYPublicKey *pubk);
|
2000-03-31 20:13:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Make a copy of the private key "privKey"
|
|
|
|
*/
|
|
|
|
extern SECKEYPrivateKey *SECKEY_CopyPrivateKey(SECKEYPrivateKey *privKey);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Make a copy of the public key "pubKey"
|
|
|
|
*/
|
|
|
|
extern SECKEYPublicKey *SECKEY_CopyPublicKey(SECKEYPublicKey *pubKey);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Convert a private key "privateKey" into a public key
|
|
|
|
*/
|
|
|
|
extern SECKEYPublicKey *SECKEY_ConvertToPublicKey(SECKEYPrivateKey *privateKey);
|
|
|
|
|
|
|
|
/*
|
2001-04-11 00:29:18 +00:00
|
|
|
* create a new RSA key pair. The private Key is returned...
|
2000-03-31 20:13:40 +00:00
|
|
|
*/
|
|
|
|
SECKEYPrivateKey *SECKEY_CreateRSAPrivateKey(int keySizeInBits,
|
|
|
|
SECKEYPublicKey **pubk, void *cx);
|
2001-04-11 00:29:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* create a new DH key pair. The private Key is returned...
|
|
|
|
*/
|
2001-09-20 21:30:48 +00:00
|
|
|
SECKEYPrivateKey *SECKEY_CreateDHPrivateKey(SECKEYDHParams *param,
|
2001-04-11 00:29:18 +00:00
|
|
|
SECKEYPublicKey **pubk, void *cx);
|
2003-02-27 01:31:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* create a new EC key pair. The private Key is returned...
|
|
|
|
*/
|
|
|
|
SECKEYPrivateKey *SECKEY_CreateECPrivateKey(SECKEYECParams *param,
|
|
|
|
SECKEYPublicKey **pubk, void *cx);
|
|
|
|
|
2000-03-31 20:13:40 +00:00
|
|
|
/*
|
|
|
|
** Create a subject-public-key-info based on a public key.
|
|
|
|
*/
|
|
|
|
extern CERTSubjectPublicKeyInfo *
|
|
|
|
SECKEY_CreateSubjectPublicKeyInfo(SECKEYPublicKey *k);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Decode a DER encoded public key into an SECKEYPublicKey structure.
|
|
|
|
*/
|
|
|
|
extern SECKEYPublicKey *SECKEY_DecodeDERPublicKey(SECItem *pubkder);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Convert a base64 ascii encoded DER public key to our internal format.
|
|
|
|
*/
|
|
|
|
extern SECKEYPublicKey *SECKEY_ConvertAndDecodePublicKey(char *pubkstr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Convert a base64 ascii encoded DER public key and challenge to spki,
|
|
|
|
** and verify the signature and challenge data are correct
|
|
|
|
*/
|
|
|
|
extern CERTSubjectPublicKeyInfo *
|
|
|
|
SECKEY_ConvertAndDecodePublicKeyAndChallenge(char *pkacstr, char *challenge,
|
|
|
|
void *cx);
|
|
|
|
|
2001-06-07 21:47:29 +00:00
|
|
|
/*
|
|
|
|
** Encode a CERTSubjectPublicKeyInfo structure. into a
|
|
|
|
** DER encoded subject public key info.
|
|
|
|
*/
|
|
|
|
SECItem *
|
|
|
|
SECKEY_EncodeDERSubjectPublicKeyInfo(SECKEYPublicKey *pubk);
|
|
|
|
|
2000-03-31 20:13:40 +00:00
|
|
|
/*
|
|
|
|
** Decode a DER encoded subject public key info into a
|
|
|
|
** CERTSubjectPublicKeyInfo structure.
|
|
|
|
*/
|
|
|
|
extern CERTSubjectPublicKeyInfo *
|
|
|
|
SECKEY_DecodeDERSubjectPublicKeyInfo(SECItem *spkider);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Convert a base64 ascii encoded DER subject public key info to our
|
|
|
|
** internal format.
|
|
|
|
*/
|
|
|
|
extern CERTSubjectPublicKeyInfo *
|
|
|
|
SECKEY_ConvertAndDecodeSubjectPublicKeyInfo(char *spkistr);
|
|
|
|
|
2001-04-24 20:04:14 +00:00
|
|
|
/*
|
|
|
|
* extract the public key from a subject Public Key info structure.
|
|
|
|
* (used by JSS).
|
|
|
|
*/
|
|
|
|
extern SECKEYPublicKey *
|
|
|
|
SECKEY_ExtractPublicKey(CERTSubjectPublicKeyInfo *);
|
|
|
|
|
2000-03-31 20:13:40 +00:00
|
|
|
/*
|
|
|
|
** Destroy a private key object.
|
|
|
|
** "key" the object
|
|
|
|
*/
|
|
|
|
extern void SECKEY_DestroyPrivateKey(SECKEYPrivateKey *key);
|
|
|
|
|
2001-04-24 20:04:14 +00:00
|
|
|
|
2000-03-31 20:13:40 +00:00
|
|
|
/*
|
|
|
|
** Destroy a public key object.
|
|
|
|
** "key" the object
|
|
|
|
*/
|
|
|
|
extern void SECKEY_DestroyPublicKey(SECKEYPublicKey *key);
|
|
|
|
|
|
|
|
/* Destroy and zero out a private key info structure. for now this
|
|
|
|
* function zero's out memory allocated in an arena for the key
|
|
|
|
* since PORT_FreeArena does not currently do this.
|
|
|
|
*
|
|
|
|
* NOTE -- If a private key info is allocated in an arena, one should
|
|
|
|
* not call this function with freeit = PR_FALSE. The function should
|
|
|
|
* destroy the arena.
|
|
|
|
*/
|
|
|
|
extern void
|
|
|
|
SECKEY_DestroyPrivateKeyInfo(SECKEYPrivateKeyInfo *pvk, PRBool freeit);
|
|
|
|
|
|
|
|
/* Destroy and zero out an encrypted private key info.
|
|
|
|
*
|
|
|
|
* NOTE -- If a encrypted private key info is allocated in an arena, one should
|
|
|
|
* not call this function with freeit = PR_FALSE. The function should
|
|
|
|
* destroy the arena.
|
|
|
|
*/
|
|
|
|
extern void
|
|
|
|
SECKEY_DestroyEncryptedPrivateKeyInfo(SECKEYEncryptedPrivateKeyInfo *epki,
|
|
|
|
PRBool freeit);
|
|
|
|
|
|
|
|
/* Copy private key info structure.
|
|
|
|
* poolp is the arena into which the contents of from is to be copied.
|
|
|
|
* NULL is a valid entry.
|
|
|
|
* to is the destination private key info
|
|
|
|
* from is the source private key info
|
|
|
|
* if either from or to is NULL or an error occurs, SECFailure is
|
|
|
|
* returned. otherwise, SECSuccess is returned.
|
|
|
|
*/
|
|
|
|
extern SECStatus
|
|
|
|
SECKEY_CopyPrivateKeyInfo(PRArenaPool *poolp,
|
|
|
|
SECKEYPrivateKeyInfo *to,
|
|
|
|
SECKEYPrivateKeyInfo *from);
|
|
|
|
|
|
|
|
/* Copy encrypted private key info structure.
|
|
|
|
* poolp is the arena into which the contents of from is to be copied.
|
|
|
|
* NULL is a valid entry.
|
|
|
|
* to is the destination encrypted private key info
|
|
|
|
* from is the source encrypted private key info
|
|
|
|
* if either from or to is NULL or an error occurs, SECFailure is
|
|
|
|
* returned. otherwise, SECSuccess is returned.
|
|
|
|
*/
|
|
|
|
extern SECStatus
|
|
|
|
SECKEY_CopyEncryptedPrivateKeyInfo(PRArenaPool *poolp,
|
|
|
|
SECKEYEncryptedPrivateKeyInfo *to,
|
|
|
|
SECKEYEncryptedPrivateKeyInfo *from);
|
|
|
|
/*
|
|
|
|
* Accessor functions for key type of public and private keys.
|
|
|
|
*/
|
|
|
|
KeyType SECKEY_GetPrivateKeyType(SECKEYPrivateKey *privKey);
|
|
|
|
KeyType SECKEY_GetPublicKeyType(SECKEYPublicKey *pubKey);
|
|
|
|
|
2001-06-25 19:31:17 +00:00
|
|
|
/*
|
|
|
|
* Creates a PublicKey from its DER encoding.
|
|
|
|
* Currently only supports RSA and DSA keys.
|
|
|
|
*/
|
|
|
|
SECKEYPublicKey*
|
|
|
|
SECKEY_ImportDERPublicKey(SECItem *derKey, CK_KEY_TYPE type);
|
|
|
|
|
|
|
|
SECKEYPrivateKeyList*
|
|
|
|
SECKEY_NewPrivateKeyList(void);
|
|
|
|
|
|
|
|
void
|
|
|
|
SECKEY_DestroyPrivateKeyList(SECKEYPrivateKeyList *keys);
|
|
|
|
|
|
|
|
void
|
|
|
|
SECKEY_RemovePrivateKeyListNode(SECKEYPrivateKeyListNode *node);
|
|
|
|
|
|
|
|
SECStatus
|
|
|
|
SECKEY_AddPrivateKeyToListTail( SECKEYPrivateKeyList *list,
|
|
|
|
SECKEYPrivateKey *key);
|
|
|
|
|
|
|
|
#define PRIVKEY_LIST_HEAD(l) ((SECKEYPrivateKeyListNode*)PR_LIST_HEAD(&l->list))
|
|
|
|
#define PRIVKEY_LIST_NEXT(n) ((SECKEYPrivateKeyListNode *)n->links.next)
|
|
|
|
#define PRIVKEY_LIST_END(n,l) (((void *)n) == ((void *)&l->list))
|
2000-03-31 20:13:40 +00:00
|
|
|
|
2002-02-03 03:37:26 +00:00
|
|
|
SECKEYPublicKeyList*
|
|
|
|
SECKEY_NewPublicKeyList(void);
|
|
|
|
|
|
|
|
void
|
|
|
|
SECKEY_DestroyPublicKeyList(SECKEYPublicKeyList *keys);
|
|
|
|
|
|
|
|
void
|
|
|
|
SECKEY_RemovePublicKeyListNode(SECKEYPublicKeyListNode *node);
|
|
|
|
|
|
|
|
SECStatus
|
|
|
|
SECKEY_AddPublicKeyToListTail( SECKEYPublicKeyList *list,
|
|
|
|
SECKEYPublicKey *key);
|
|
|
|
|
|
|
|
#define PUBKEY_LIST_HEAD(l) ((SECKEYPublicKeyListNode*)PR_LIST_HEAD(&l->list))
|
|
|
|
#define PUBKEY_LIST_NEXT(n) ((SECKEYPublicKeyListNode *)n->links.next)
|
|
|
|
#define PUBKEY_LIST_END(n,l) (((void *)n) == ((void *)&l->list))
|
|
|
|
|
2004-01-22 02:19:42 +00:00
|
|
|
#ifdef NSS_ENABLE_ECC
|
|
|
|
extern int SECKEY_ECParamsToKeySize(const SECItem *params);
|
|
|
|
#endif /* NSS_ENABLE_ECC */
|
|
|
|
|
2000-03-31 20:13:40 +00:00
|
|
|
SEC_END_PROTOS
|
|
|
|
|
|
|
|
#endif /* _KEYHI_H_ */
|