tor-browser

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

lowpbe.h (3391B)


      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 _SECPKCS5_H_
      6 #define _SECPKCS5_H_
      7 
      8 #include "plarena.h"
      9 #include "secitem.h"
     10 #include "seccomon.h"
     11 #include "secoidt.h"
     12 #include "hasht.h"
     13 
     14 typedef SECItem *(*SEC_PKCS5GetPBEPassword)(void *arg);
     15 
     16 /* used for V2 PKCS 12 Draft Spec */
     17 typedef enum {
     18    pbeBitGenIDNull = 0,
     19    pbeBitGenCipherKey = 0x01,
     20    pbeBitGenCipherIV = 0x02,
     21    pbeBitGenIntegrityKey = 0x03
     22 } PBEBitGenID;
     23 
     24 typedef enum {
     25    NSSPKCS5_PBKDF1 = 0,
     26    NSSPKCS5_PBKDF2 = 1,
     27    NSSPKCS5_PKCS12_V2 = 2
     28 } NSSPKCS5PBEType;
     29 
     30 typedef struct NSSPKCS5PBEParameterStr NSSPKCS5PBEParameter;
     31 
     32 struct NSSPKCS5PBEParameterStr {
     33    PLArenaPool *poolp;
     34    SECItem salt;      /* octet string */
     35    SECItem iteration; /* integer */
     36    SECItem keyLength; /* integer */
     37 
     38    /* used locally */
     39    int iter;
     40    int keyLen;
     41    int ivLen;
     42    unsigned char *ivData;
     43    HASH_HashType hashType;
     44    NSSPKCS5PBEType pbeType;
     45    SECAlgorithmID prfAlg;
     46    PBEBitGenID keyID;
     47    SECOidTag encAlg;
     48    PRBool is2KeyDES;
     49 };
     50 
     51 SEC_BEGIN_PROTOS
     52 /* Create a PKCS5 Algorithm ID
     53 * The algorithm ID is set up using the PKCS #5 parameter structure
     54 *  algorithm is the PBE algorithm ID for the desired algorithm
     55 *  pbe is a pbe param block with all the info needed to create the
     56 *   algorithm id.
     57 * If an error occurs or the algorithm specified is not supported
     58 * or is not a password based encryption algorithm, NULL is returned.
     59 * Otherwise, a pointer to the algorithm id is returned.
     60 */
     61 extern SECAlgorithmID *
     62 nsspkcs5_CreateAlgorithmID(PLArenaPool *arena, SECOidTag algorithm,
     63                           NSSPKCS5PBEParameter *pbe);
     64 
     65 /*
     66 * Convert an Algorithm ID to a PBE Param.
     67 * NOTE: this does not suppport PKCS 5 v2 because it's only used for the
     68 * keyDB which only support PKCS 5 v1, PFX, and PKCS 12.
     69 */
     70 NSSPKCS5PBEParameter *
     71 nsspkcs5_AlgidToParam(SECAlgorithmID *algid);
     72 
     73 /*
     74 * Convert an Algorithm ID to a PBE Param.
     75 * NOTE: this does not suppport PKCS 5 v2 because it's only used for the
     76 * keyDB which only support PKCS 5 v1, PFX, and PKCS 12.
     77 */
     78 NSSPKCS5PBEParameter *
     79 nsspkcs5_NewParam(SECOidTag alg, HASH_HashType hashType, SECItem *salt,
     80                  int iterationCount);
     81 
     82 /* Encrypt/Decrypt data using password based encryption.
     83 *  algid is the PBE algorithm identifier,
     84 *  pwitem is the password,
     85 *  src is the source for encryption/decryption,
     86 *  encrypt is PR_TRUE for encryption, PR_FALSE for decryption.
     87 * The key and iv are generated based upon PKCS #5 then the src
     88 * is either encrypted or decrypted.  If an error occurs, NULL
     89 * is returned, otherwise the ciphered contents is returned.
     90 */
     91 extern SECItem *
     92 nsspkcs5_CipherData(NSSPKCS5PBEParameter *, SECItem *pwitem,
     93                    SECItem *src, PRBool encrypt, PRBool *update);
     94 
     95 extern SECItem *
     96 nsspkcs5_ComputeKeyAndIV(NSSPKCS5PBEParameter *, SECItem *pwitem,
     97                         SECItem *iv, PRBool faulty3DES);
     98 
     99 /* Destroys PBE parameter */
    100 extern void
    101 nsspkcs5_DestroyPBEParameter(NSSPKCS5PBEParameter *param);
    102 
    103 HASH_HashType HASH_FromHMACOid(SECOidTag oid);
    104 SECOidTag HASH_HMACOidFromHash(HASH_HashType);
    105 
    106 /* fips selftest */
    107 extern SECStatus
    108 sftk_fips_pbkdf_PowerUpSelfTests(void);
    109 
    110 SEC_END_PROTOS
    111 
    112 #endif