Back to index

lightning-sunbird  0.9+nobinonly
keythi.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef _KEYTHI_H_
00038 #define _KEYTHI_H_ 1
00039 
00040 #include "plarena.h"
00041 #include "pkcs11t.h"
00042 #include "secmodt.h"
00043 #include "prclist.h"
00044 
00045 typedef enum { 
00046     nullKey = 0, 
00047     rsaKey = 1, 
00048     dsaKey = 2, 
00049     fortezzaKey = 3,
00050     dhKey = 4, 
00051     keaKey = 5,
00052     ecKey = 6
00053 } KeyType;
00054 
00055 /*
00056 ** Template Definitions
00057 **/
00058 
00059 SEC_BEGIN_PROTOS
00060 extern const SEC_ASN1Template SECKEY_RSAPublicKeyTemplate[];
00061 extern const SEC_ASN1Template SECKEY_DSAPublicKeyTemplate[];
00062 extern const SEC_ASN1Template SECKEY_DHPublicKeyTemplate[];
00063 extern const SEC_ASN1Template SECKEY_DHParamKeyTemplate[];
00064 extern const SEC_ASN1Template SECKEY_PQGParamsTemplate[];
00065 extern const SEC_ASN1Template SECKEY_DSAPrivateKeyExportTemplate[];
00066 
00067 /* Windows DLL accessor functions */
00068 extern SEC_ASN1TemplateChooser NSS_Get_SECKEY_DSAPublicKeyTemplate;
00069 extern SEC_ASN1TemplateChooser NSS_Get_SECKEY_RSAPublicKeyTemplate;
00070 SEC_END_PROTOS
00071 
00072 
00073 /*
00074 ** RSA Public Key structures
00075 ** member names from PKCS#1, section 7.1 
00076 */
00077 
00078 struct SECKEYRSAPublicKeyStr {
00079     PRArenaPool * arena;
00080     SECItem modulus;
00081     SECItem publicExponent;
00082 };
00083 typedef struct SECKEYRSAPublicKeyStr SECKEYRSAPublicKey;
00084 
00085 
00086 /*
00087 ** DSA Public Key and related structures
00088 */
00089 
00090 struct SECKEYPQGParamsStr {
00091     PRArenaPool *arena;
00092     SECItem prime;    /* p */
00093     SECItem subPrime; /* q */
00094     SECItem base;     /* g */
00095     /* XXX chrisk: this needs to be expanded to hold j and validationParms (RFC2459 7.3.2) */
00096 };
00097 typedef struct SECKEYPQGParamsStr SECKEYPQGParams;
00098 
00099 struct SECKEYDSAPublicKeyStr {
00100     SECKEYPQGParams params;
00101     SECItem publicValue;
00102 };
00103 typedef struct SECKEYDSAPublicKeyStr SECKEYDSAPublicKey;
00104 
00105 
00106 /*
00107 ** Diffie-Hellman Public Key structure
00108 ** Structure member names suggested by PKCS#3.
00109 */
00110 struct SECKEYDHParamsStr {
00111     PRArenaPool * arena;
00112     SECItem prime; /* p */
00113     SECItem base; /* g */
00114 };
00115 typedef struct SECKEYDHParamsStr SECKEYDHParams;
00116 
00117 struct SECKEYDHPublicKeyStr {
00118     PRArenaPool * arena;
00119     SECItem prime;
00120     SECItem base;
00121     SECItem publicValue;
00122 };
00123 typedef struct SECKEYDHPublicKeyStr SECKEYDHPublicKey;
00124 
00125 /*
00126 ** Elliptic curve Public Key structure
00127 ** The PKCS#11 layer needs DER encoding of ANSI X9.62
00128 ** parameters value
00129 */
00130 typedef SECItem SECKEYECParams;
00131 
00132 struct SECKEYECPublicKeyStr {
00133     SECKEYECParams DEREncodedParams;
00134     int     size;             /* size in bits */
00135     SECItem publicValue;      /* encoded point */
00136     /* XXX Even though the PKCS#11 interface takes encoded parameters,
00137      * we may still wish to decode them above PKCS#11 for things like
00138      * printing key information. For named curves, which is what
00139      * we initially support, we ought to have the curve name at the
00140      * very least.
00141      */
00142 };
00143 typedef struct SECKEYECPublicKeyStr SECKEYECPublicKey;
00144 
00145 /*
00146 ** FORTEZZA Public Key structures
00147 */
00148 struct SECKEYFortezzaPublicKeyStr {
00149     int      KEAversion;
00150     int      DSSversion;
00151     unsigned char    KMID[8];
00152     SECItem clearance;
00153     SECItem KEApriviledge;
00154     SECItem DSSpriviledge;
00155     SECItem KEAKey;
00156     SECItem DSSKey;
00157     SECKEYPQGParams params;
00158     SECKEYPQGParams keaParams;
00159 };
00160 typedef struct SECKEYFortezzaPublicKeyStr SECKEYFortezzaPublicKey;
00161 
00162 struct SECKEYDiffPQGParamsStr {
00163     SECKEYPQGParams DiffKEAParams;
00164     SECKEYPQGParams DiffDSAParams;
00165 };
00166 typedef struct SECKEYDiffPQGParamsStr SECKEYDiffPQGParams;
00167 
00168 struct SECKEYPQGDualParamsStr {
00169     SECKEYPQGParams CommParams;
00170     SECKEYDiffPQGParams DiffParams;
00171 };
00172 typedef struct SECKEYPQGDualParamsStr SECKEYPQGDualParams;
00173 
00174 struct SECKEYKEAParamsStr {
00175     PLArenaPool *arena;
00176     SECItem hash;
00177 };
00178 typedef struct SECKEYKEAParamsStr SECKEYKEAParams;
00179  
00180 struct SECKEYKEAPublicKeyStr {
00181     SECKEYKEAParams params;
00182     SECItem publicValue;
00183 };
00184 typedef struct SECKEYKEAPublicKeyStr SECKEYKEAPublicKey;
00185 
00186 /*
00187 ** A Generic  public key object.
00188 */
00189 struct SECKEYPublicKeyStr {
00190     PLArenaPool *arena;
00191     KeyType keyType;
00192     PK11SlotInfo *pkcs11Slot;
00193     CK_OBJECT_HANDLE pkcs11ID;
00194     union {
00195         SECKEYRSAPublicKey rsa;
00196        SECKEYDSAPublicKey dsa;
00197        SECKEYDHPublicKey  dh;
00198         SECKEYKEAPublicKey kea;
00199         SECKEYFortezzaPublicKey fortezza;
00200        SECKEYECPublicKey  ec;
00201     } u;
00202 };
00203 typedef struct SECKEYPublicKeyStr SECKEYPublicKey;
00204 
00205 #define CachedAttribute(attribute,setbit) \
00206 static const PRUint32 SECKEY_##attribute = 1 << setbit;
00207 
00208 /* bit flag definitions for staticflags */
00209 #define SECKEY_Attributes_Cached 0x1    /* bit 0 states
00210                                            whether attributes are cached */
00211 CachedAttribute(CKA_PRIVATE,1) /* bit 1 is the value of CKA_PRIVATE */
00212 
00213 #define SECKEY_ATTRIBUTES_CACHED(key) \
00214      (0 != (key->staticflags & SECKEY_Attributes_Cached))
00215 
00216 #define SECKEY_ATTRIBUTE_VALUE(key,attribute) \
00217      (0 != (key->staticflags & SECKEY_##attribute))
00218 
00219 #define SECKEY_HAS_ATTRIBUTE_SET(key,attribute) \
00220     (0 != (key->staticflags & SECKEY_Attributes_Cached)) ? \
00221     (0 != (key->staticflags & SECKEY_##attribute)) : \
00222     PK11_HasAttributeSet(key->pkcs11Slot,key->pkcs11ID,attribute)
00223 
00224 /*
00225 ** A generic key structure
00226 */ 
00227 struct SECKEYPrivateKeyStr {
00228     PLArenaPool *arena;
00229     KeyType keyType;
00230     PK11SlotInfo *pkcs11Slot;      /* pkcs11 slot this key lives in */
00231     CK_OBJECT_HANDLE pkcs11ID;  /* ID of pkcs11 object */
00232     PRBool pkcs11IsTemp;    /* temp pkcs11 object, delete it when done */
00233     void *wincx;            /* context for errors and pw prompts */
00234     PRUint32 staticflags;       /* bit flag of cached PKCS#11 attributes */
00235 };
00236 typedef struct SECKEYPrivateKeyStr SECKEYPrivateKey;
00237 
00238 /* Despite the name, this struct isn't used by any pkcs5 code.
00239 ** It's used by pkcs7 and pkcs12 code.
00240 */
00241 typedef struct {
00242     SECItem *pwitem;
00243     PK11SymKey *key;
00244     PK11SlotInfo *slot;
00245     void *wincx;
00246 } SEC_PKCS5KeyAndPassword;
00247 
00248 typedef struct {
00249     PRCList links;
00250     SECKEYPrivateKey *key;
00251 } SECKEYPrivateKeyListNode;
00252 
00253 typedef struct {
00254     PRCList list;
00255     PRArenaPool *arena;
00256 } SECKEYPrivateKeyList;
00257 
00258 typedef struct {
00259     PRCList links;
00260     SECKEYPublicKey *key;
00261 } SECKEYPublicKeyListNode;
00262 
00263 typedef struct {
00264     PRCList list;
00265     PRArenaPool *arena;
00266 } SECKEYPublicKeyList;
00267 #endif /* _KEYTHI_H_ */
00268