tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

lowkeyi.h (5390B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef _LOWKEYI_H_
      6 #define _LOWKEYI_H_
      7 
      8 #include "prtypes.h"
      9 #include "seccomon.h"
     10 #include "secoidt.h"
     11 #include "pcertt.h"
     12 #include "lowkeyti.h"
     13 #include "sdb.h"
     14 
     15 SEC_BEGIN_PROTOS
     16 
     17 /*
     18 * See bugzilla bug 125359
     19 * Since NSS (via PKCS#11) wants to handle big integers as unsigned ints,
     20 * all of the templates above that en/decode into integers must be converted
     21 * from ASN.1's signed integer type.  This is done by marking either the
     22 * source or destination (encoding or decoding, respectively) type as
     23 * siUnsignedInteger.
     24 */
     25 extern void lg_prepare_low_rsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
     26 extern void lg_prepare_low_pqg_params_for_asn1(PQGParams *params);
     27 extern void lg_prepare_low_dsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
     28 extern void lg_prepare_low_dh_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
     29 extern void lg_prepare_low_ec_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
     30 extern void lg_prepare_low_ecparams_for_asn1(ECParams *params);
     31 
     32 typedef char *(*NSSLOWKEYDBNameFunc)(void *arg, int dbVersion);
     33 
     34 /*
     35 ** Open a key database.
     36 */
     37 extern NSSLOWKEYDBHandle *nsslowkey_OpenKeyDB(PRBool readOnly,
     38                                              const char *domain,
     39                                              const char *prefix,
     40                                              NSSLOWKEYDBNameFunc namecb,
     41                                              void *cbarg);
     42 
     43 /*
     44 ** Close the specified key database.
     45 */
     46 extern void nsslowkey_CloseKeyDB(NSSLOWKEYDBHandle *handle);
     47 
     48 /*
     49 * Get the version number of the database
     50 */
     51 extern int nsslowkey_GetKeyDBVersion(NSSLOWKEYDBHandle *handle);
     52 
     53 /*
     54 ** Delete a key from the database
     55 */
     56 extern SECStatus nsslowkey_DeleteKey(NSSLOWKEYDBHandle *handle,
     57                                     const SECItem *pubkey);
     58 
     59 /*
     60 ** Store a key in the database, indexed by its public key modulus.
     61 **  "pk" is the private key to store
     62 **  "f" is the callback function for getting the password
     63 **  "arg" is the argument for the callback
     64 */
     65 extern SECStatus nsslowkey_StoreKeyByPublicKey(NSSLOWKEYDBHandle *handle,
     66                                               NSSLOWKEYPrivateKey *pk,
     67                                               SECItem *pubKeyData,
     68                                               char *nickname,
     69                                               SDB *sdb);
     70 
     71 /* does the key for this cert exist in the database filed by modulus */
     72 extern PRBool nsslowkey_KeyForCertExists(NSSLOWKEYDBHandle *handle,
     73                                         NSSLOWCERTCertificate *cert);
     74 /* does a key with this ID already exist? */
     75 extern PRBool nsslowkey_KeyForIDExists(NSSLOWKEYDBHandle *handle, SECItem *id);
     76 
     77 /*
     78 ** Destroy a private key object.
     79 **  "key" the object
     80 **  "freeit" if PR_TRUE then free the object as well as its sub-objects
     81 */
     82 extern void lg_nsslowkey_DestroyPrivateKey(NSSLOWKEYPrivateKey *key);
     83 
     84 /*
     85 ** Destroy a public key object.
     86 **  "key" the object
     87 **  "freeit" if PR_TRUE then free the object as well as its sub-objects
     88 */
     89 extern void lg_nsslowkey_DestroyPublicKey(NSSLOWKEYPublicKey *key);
     90 
     91 /*
     92 ** Convert a low private key "privateKey" into a public low key
     93 */
     94 extern NSSLOWKEYPublicKey
     95    *
     96    lg_nsslowkey_ConvertToPublicKey(NSSLOWKEYPrivateKey *privateKey);
     97 
     98 SECStatus
     99 nsslowkey_UpdateNickname(NSSLOWKEYDBHandle *handle,
    100                         NSSLOWKEYPrivateKey *privkey,
    101                         SECItem *pubKeyData,
    102                         char *nickname,
    103                         SDB *sdb);
    104 
    105 /* Store key by modulus and specify an encryption algorithm to use.
    106 *   handle is the pointer to the key database,
    107 *   privkey is the private key to be stored,
    108 *   f and arg are the function and arguments to the callback
    109 *       to get a password,
    110 *   algorithm is the algorithm which the privKey is to be stored.
    111 * A return of anything but SECSuccess indicates failure.
    112 */
    113 extern SECStatus
    114 nsslowkey_StoreKeyByPublicKeyAlg(NSSLOWKEYDBHandle *handle,
    115                                 NSSLOWKEYPrivateKey *privkey,
    116                                 SECItem *pubKeyData,
    117                                 char *nickname,
    118                                 SDB *sdb,
    119                                 PRBool update);
    120 
    121 /* Find key by modulus.  This function is the inverse of store key
    122 * by modulus.  An attempt to locate the key with "modulus" is
    123 * performed.  If the key is found, the private key is returned,
    124 * else NULL is returned.
    125 *   modulus is the modulus to locate
    126 */
    127 extern NSSLOWKEYPrivateKey *
    128 nsslowkey_FindKeyByPublicKey(NSSLOWKEYDBHandle *handle, SECItem *modulus,
    129                             SDB *sdb);
    130 
    131 extern char *
    132 nsslowkey_FindKeyNicknameByPublicKey(NSSLOWKEYDBHandle *handle,
    133                                     SECItem *modulus, SDB *sdb);
    134 
    135 /*
    136 * smaller version of EC_FillParams. In this code, we only need
    137 * oid and DER data.
    138 */
    139 SECStatus LGEC_FillParams(PLArenaPool *arena, const SECItem *encodedParams,
    140                          ECParams *params);
    141 
    142 /* Copy all of the fields from srcParams into dstParams */
    143 SECStatus LGEC_CopyParams(PLArenaPool *arena, ECParams *dstParams,
    144                          const ECParams *srcParams);
    145 
    146 SEC_END_PROTOS
    147 
    148 #endif /* _LOWKEYI_H_ */