1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/softoken/legacydb/lowkeyi.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,152 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef _LOWKEYI_H_ 1.9 +#define _LOWKEYI_H_ 1.10 + 1.11 +#include "prtypes.h" 1.12 +#include "seccomon.h" 1.13 +#include "secoidt.h" 1.14 +#include "pcertt.h" 1.15 +#include "lowkeyti.h" 1.16 +#include "sdb.h" 1.17 + 1.18 +SEC_BEGIN_PROTOS 1.19 + 1.20 +/* 1.21 + * See bugzilla bug 125359 1.22 + * Since NSS (via PKCS#11) wants to handle big integers as unsigned ints, 1.23 + * all of the templates above that en/decode into integers must be converted 1.24 + * from ASN.1's signed integer type. This is done by marking either the 1.25 + * source or destination (encoding or decoding, respectively) type as 1.26 + * siUnsignedInteger. 1.27 + */ 1.28 +extern void lg_prepare_low_rsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key); 1.29 +extern void lg_prepare_low_pqg_params_for_asn1(PQGParams *params); 1.30 +extern void lg_prepare_low_dsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key); 1.31 +extern void lg_prepare_low_dh_priv_key_for_asn1(NSSLOWKEYPrivateKey *key); 1.32 +#ifndef NSS_DISABLE_ECC 1.33 +extern void lg_prepare_low_ec_priv_key_for_asn1(NSSLOWKEYPrivateKey *key); 1.34 +extern void lg_prepare_low_ecparams_for_asn1(ECParams *params); 1.35 +#endif /* NSS_DISABLE_ECC */ 1.36 + 1.37 +typedef char * (* NSSLOWKEYDBNameFunc)(void *arg, int dbVersion); 1.38 + 1.39 +/* 1.40 +** Open a key database. 1.41 +*/ 1.42 +extern NSSLOWKEYDBHandle *nsslowkey_OpenKeyDB(PRBool readOnly, 1.43 + const char *domain, 1.44 + const char *prefix, 1.45 + NSSLOWKEYDBNameFunc namecb, 1.46 + void *cbarg); 1.47 + 1.48 +/* 1.49 +** Close the specified key database. 1.50 +*/ 1.51 +extern void nsslowkey_CloseKeyDB(NSSLOWKEYDBHandle *handle); 1.52 + 1.53 +/* 1.54 + * Get the version number of the database 1.55 + */ 1.56 +extern int nsslowkey_GetKeyDBVersion(NSSLOWKEYDBHandle *handle); 1.57 + 1.58 +/* 1.59 +** Delete a key from the database 1.60 +*/ 1.61 +extern SECStatus nsslowkey_DeleteKey(NSSLOWKEYDBHandle *handle, 1.62 + const SECItem *pubkey); 1.63 + 1.64 +/* 1.65 +** Store a key in the database, indexed by its public key modulus. 1.66 +** "pk" is the private key to store 1.67 +** "f" is the callback function for getting the password 1.68 +** "arg" is the argument for the callback 1.69 +*/ 1.70 +extern SECStatus nsslowkey_StoreKeyByPublicKey(NSSLOWKEYDBHandle *handle, 1.71 + NSSLOWKEYPrivateKey *pk, 1.72 + SECItem *pubKeyData, 1.73 + char *nickname, 1.74 + SDB *sdb); 1.75 + 1.76 +/* does the key for this cert exist in the database filed by modulus */ 1.77 +extern PRBool nsslowkey_KeyForCertExists(NSSLOWKEYDBHandle *handle, 1.78 + NSSLOWCERTCertificate *cert); 1.79 +/* does a key with this ID already exist? */ 1.80 +extern PRBool nsslowkey_KeyForIDExists(NSSLOWKEYDBHandle *handle, SECItem *id); 1.81 + 1.82 +/* 1.83 +** Destroy a private key object. 1.84 +** "key" the object 1.85 +** "freeit" if PR_TRUE then free the object as well as its sub-objects 1.86 +*/ 1.87 +extern void lg_nsslowkey_DestroyPrivateKey(NSSLOWKEYPrivateKey *key); 1.88 + 1.89 +/* 1.90 +** Destroy a public key object. 1.91 +** "key" the object 1.92 +** "freeit" if PR_TRUE then free the object as well as its sub-objects 1.93 +*/ 1.94 +extern void lg_nsslowkey_DestroyPublicKey(NSSLOWKEYPublicKey *key); 1.95 + 1.96 + 1.97 +/* 1.98 +** Convert a low private key "privateKey" into a public low key 1.99 +*/ 1.100 +extern NSSLOWKEYPublicKey 1.101 + *lg_nsslowkey_ConvertToPublicKey(NSSLOWKEYPrivateKey *privateKey); 1.102 + 1.103 + 1.104 +SECStatus 1.105 +nsslowkey_UpdateNickname(NSSLOWKEYDBHandle *handle, 1.106 + NSSLOWKEYPrivateKey *privkey, 1.107 + SECItem *pubKeyData, 1.108 + char *nickname, 1.109 + SDB *sdb); 1.110 + 1.111 +/* Store key by modulus and specify an encryption algorithm to use. 1.112 + * handle is the pointer to the key database, 1.113 + * privkey is the private key to be stored, 1.114 + * f and arg are the function and arguments to the callback 1.115 + * to get a password, 1.116 + * algorithm is the algorithm which the privKey is to be stored. 1.117 + * A return of anything but SECSuccess indicates failure. 1.118 + */ 1.119 +extern SECStatus 1.120 +nsslowkey_StoreKeyByPublicKeyAlg(NSSLOWKEYDBHandle *handle, 1.121 + NSSLOWKEYPrivateKey *privkey, 1.122 + SECItem *pubKeyData, 1.123 + char *nickname, 1.124 + SDB *sdb, 1.125 + PRBool update); 1.126 + 1.127 +/* Find key by modulus. This function is the inverse of store key 1.128 + * by modulus. An attempt to locate the key with "modulus" is 1.129 + * performed. If the key is found, the private key is returned, 1.130 + * else NULL is returned. 1.131 + * modulus is the modulus to locate 1.132 + */ 1.133 +extern NSSLOWKEYPrivateKey * 1.134 +nsslowkey_FindKeyByPublicKey(NSSLOWKEYDBHandle *handle, SECItem *modulus, 1.135 + SDB *sdb); 1.136 + 1.137 +extern char * 1.138 +nsslowkey_FindKeyNicknameByPublicKey(NSSLOWKEYDBHandle *handle, 1.139 + SECItem *modulus, SDB *sdb); 1.140 + 1.141 +#ifndef NSS_DISABLE_ECC 1.142 +/* 1.143 + * smaller version of EC_FillParams. In this code, we only need 1.144 + * oid and DER data. 1.145 + */ 1.146 +SECStatus LGEC_FillParams(PLArenaPool *arena, const SECItem *encodedParams, 1.147 + ECParams *params); 1.148 + 1.149 +/* Copy all of the fields from srcParams into dstParams */ 1.150 +SECStatus LGEC_CopyParams(PLArenaPool *arena, ECParams *dstParams, 1.151 + const ECParams *srcParams); 1.152 +#endif 1.153 +SEC_END_PROTOS 1.154 + 1.155 +#endif /* _LOWKEYI_H_ */