andre@3: /* This Source Code Form is subject to the terms of the Mozilla Public andre@3: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@3: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@3: andre@3: #ifndef _LOWKEYI_H_ andre@3: #define _LOWKEYI_H_ andre@3: andre@3: #include "prtypes.h" andre@3: #include "seccomon.h" andre@3: #include "secoidt.h" andre@3: #include "pcertt.h" andre@3: #include "lowkeyti.h" andre@3: #include "sdb.h" andre@3: andre@3: SEC_BEGIN_PROTOS andre@3: andre@3: /* andre@3: * See bugzilla bug 125359 andre@3: * Since NSS (via PKCS#11) wants to handle big integers as unsigned ints, andre@3: * all of the templates above that en/decode into integers must be converted andre@3: * from ASN.1's signed integer type. This is done by marking either the andre@3: * source or destination (encoding or decoding, respectively) type as andre@3: * siUnsignedInteger. andre@3: */ andre@3: extern void lg_prepare_low_rsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key); andre@3: extern void lg_prepare_low_pqg_params_for_asn1(PQGParams *params); andre@3: extern void lg_prepare_low_dsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key); andre@3: extern void lg_prepare_low_dh_priv_key_for_asn1(NSSLOWKEYPrivateKey *key); andre@3: #ifndef NSS_DISABLE_ECC andre@3: extern void lg_prepare_low_ec_priv_key_for_asn1(NSSLOWKEYPrivateKey *key); andre@3: extern void lg_prepare_low_ecparams_for_asn1(ECParams *params); andre@3: #endif /* NSS_DISABLE_ECC */ andre@3: andre@3: typedef char * (* NSSLOWKEYDBNameFunc)(void *arg, int dbVersion); andre@3: andre@3: /* andre@3: ** Open a key database. andre@3: */ andre@3: extern NSSLOWKEYDBHandle *nsslowkey_OpenKeyDB(PRBool readOnly, andre@3: const char *domain, andre@3: const char *prefix, andre@3: NSSLOWKEYDBNameFunc namecb, andre@3: void *cbarg); andre@3: andre@3: /* andre@3: ** Close the specified key database. andre@3: */ andre@3: extern void nsslowkey_CloseKeyDB(NSSLOWKEYDBHandle *handle); andre@3: andre@3: /* andre@3: * Get the version number of the database andre@3: */ andre@3: extern int nsslowkey_GetKeyDBVersion(NSSLOWKEYDBHandle *handle); andre@3: andre@3: /* andre@3: ** Delete a key from the database andre@3: */ andre@3: extern SECStatus nsslowkey_DeleteKey(NSSLOWKEYDBHandle *handle, andre@3: const SECItem *pubkey); andre@3: andre@3: /* andre@3: ** Store a key in the database, indexed by its public key modulus. andre@3: ** "pk" is the private key to store andre@3: ** "f" is the callback function for getting the password andre@3: ** "arg" is the argument for the callback andre@3: */ andre@3: extern SECStatus nsslowkey_StoreKeyByPublicKey(NSSLOWKEYDBHandle *handle, andre@3: NSSLOWKEYPrivateKey *pk, andre@3: SECItem *pubKeyData, andre@3: char *nickname, andre@3: SDB *sdb); andre@3: andre@3: /* does the key for this cert exist in the database filed by modulus */ andre@3: extern PRBool nsslowkey_KeyForCertExists(NSSLOWKEYDBHandle *handle, andre@3: NSSLOWCERTCertificate *cert); andre@3: /* does a key with this ID already exist? */ andre@3: extern PRBool nsslowkey_KeyForIDExists(NSSLOWKEYDBHandle *handle, SECItem *id); andre@3: andre@3: /* andre@3: ** Destroy a private key object. andre@3: ** "key" the object andre@3: ** "freeit" if PR_TRUE then free the object as well as its sub-objects andre@3: */ andre@3: extern void lg_nsslowkey_DestroyPrivateKey(NSSLOWKEYPrivateKey *key); andre@3: andre@3: /* andre@3: ** Destroy a public key object. andre@3: ** "key" the object andre@3: ** "freeit" if PR_TRUE then free the object as well as its sub-objects andre@3: */ andre@3: extern void lg_nsslowkey_DestroyPublicKey(NSSLOWKEYPublicKey *key); andre@3: andre@3: andre@3: /* andre@3: ** Convert a low private key "privateKey" into a public low key andre@3: */ andre@3: extern NSSLOWKEYPublicKey andre@3: *lg_nsslowkey_ConvertToPublicKey(NSSLOWKEYPrivateKey *privateKey); andre@3: andre@3: andre@3: SECStatus andre@3: nsslowkey_UpdateNickname(NSSLOWKEYDBHandle *handle, andre@3: NSSLOWKEYPrivateKey *privkey, andre@3: SECItem *pubKeyData, andre@3: char *nickname, andre@3: SDB *sdb); andre@3: andre@3: /* Store key by modulus and specify an encryption algorithm to use. andre@3: * handle is the pointer to the key database, andre@3: * privkey is the private key to be stored, andre@3: * f and arg are the function and arguments to the callback andre@3: * to get a password, andre@3: * algorithm is the algorithm which the privKey is to be stored. andre@3: * A return of anything but SECSuccess indicates failure. andre@3: */ andre@3: extern SECStatus andre@3: nsslowkey_StoreKeyByPublicKeyAlg(NSSLOWKEYDBHandle *handle, andre@3: NSSLOWKEYPrivateKey *privkey, andre@3: SECItem *pubKeyData, andre@3: char *nickname, andre@3: SDB *sdb, andre@3: PRBool update); andre@3: andre@3: /* Find key by modulus. This function is the inverse of store key andre@3: * by modulus. An attempt to locate the key with "modulus" is andre@3: * performed. If the key is found, the private key is returned, andre@3: * else NULL is returned. andre@3: * modulus is the modulus to locate andre@3: */ andre@3: extern NSSLOWKEYPrivateKey * andre@3: nsslowkey_FindKeyByPublicKey(NSSLOWKEYDBHandle *handle, SECItem *modulus, andre@3: SDB *sdb); andre@3: andre@3: extern char * andre@3: nsslowkey_FindKeyNicknameByPublicKey(NSSLOWKEYDBHandle *handle, andre@3: SECItem *modulus, SDB *sdb); andre@3: andre@3: #ifndef NSS_DISABLE_ECC andre@3: /* andre@3: * smaller version of EC_FillParams. In this code, we only need andre@3: * oid and DER data. andre@3: */ andre@3: SECStatus LGEC_FillParams(PLArenaPool *arena, const SECItem *encodedParams, andre@3: ECParams *params); andre@3: andre@3: /* Copy all of the fields from srcParams into dstParams */ andre@3: SECStatus LGEC_CopyParams(PLArenaPool *arena, ECParams *dstParams, andre@3: const ECParams *srcParams); andre@3: #endif andre@3: SEC_END_PROTOS andre@3: andre@3: #endif /* _LOWKEYI_H_ */