andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: #ifndef _SECPKCS5_H_ andre@0: #define _SECPKCS5_H_ andre@0: andre@0: #include "plarena.h" andre@0: #include "secitem.h" andre@0: #include "seccomon.h" andre@0: #include "secoidt.h" andre@0: #include "hasht.h" andre@0: andre@0: typedef SECItem * (* SEC_PKCS5GetPBEPassword)(void *arg); andre@0: andre@0: /* used for V2 PKCS 12 Draft Spec */ andre@0: typedef enum { andre@0: pbeBitGenIDNull = 0, andre@0: pbeBitGenCipherKey = 0x01, andre@0: pbeBitGenCipherIV = 0x02, andre@0: pbeBitGenIntegrityKey = 0x03 andre@0: } PBEBitGenID; andre@0: andre@0: typedef enum { andre@0: NSSPKCS5_PBKDF1 = 0, andre@0: NSSPKCS5_PBKDF2 = 1, andre@0: NSSPKCS5_PKCS12_V2 = 2 andre@0: } NSSPKCS5PBEType; andre@0: andre@0: typedef struct NSSPKCS5PBEParameterStr NSSPKCS5PBEParameter; andre@0: andre@0: struct NSSPKCS5PBEParameterStr { andre@0: PLArenaPool *poolp; andre@0: SECItem salt; /* octet string */ andre@0: SECItem iteration; /* integer */ andre@0: SECItem keyLength; /* integer */ andre@0: andre@0: /* used locally */ andre@0: int iter; andre@0: int keyLen; andre@0: int ivLen; andre@0: unsigned char *ivData; andre@0: HASH_HashType hashType; andre@0: NSSPKCS5PBEType pbeType; andre@0: SECAlgorithmID prfAlg; andre@0: PBEBitGenID keyID; andre@0: SECOidTag encAlg; andre@0: PRBool is2KeyDES; andre@0: }; andre@0: andre@0: andre@0: SEC_BEGIN_PROTOS andre@0: /* Create a PKCS5 Algorithm ID andre@0: * The algorithm ID is set up using the PKCS #5 parameter structure andre@0: * algorithm is the PBE algorithm ID for the desired algorithm andre@0: * pbe is a pbe param block with all the info needed to create the andre@0: * algorithm id. andre@0: * If an error occurs or the algorithm specified is not supported andre@0: * or is not a password based encryption algorithm, NULL is returned. andre@0: * Otherwise, a pointer to the algorithm id is returned. andre@0: */ andre@0: extern SECAlgorithmID * andre@0: nsspkcs5_CreateAlgorithmID(PLArenaPool *arena, SECOidTag algorithm, andre@0: NSSPKCS5PBEParameter *pbe); andre@0: andre@0: /* andre@0: * Convert an Algorithm ID to a PBE Param. andre@0: * NOTE: this does not suppport PKCS 5 v2 because it's only used for the andre@0: * keyDB which only support PKCS 5 v1, PFX, and PKCS 12. andre@0: */ andre@0: NSSPKCS5PBEParameter * andre@0: nsspkcs5_AlgidToParam(SECAlgorithmID *algid); andre@0: andre@0: /* andre@0: * Convert an Algorithm ID to a PBE Param. andre@0: * NOTE: this does not suppport PKCS 5 v2 because it's only used for the andre@0: * keyDB which only support PKCS 5 v1, PFX, and PKCS 12. andre@0: */ andre@0: NSSPKCS5PBEParameter * andre@0: nsspkcs5_NewParam(SECOidTag alg, SECItem *salt, int iterator); andre@0: andre@0: andre@0: /* Encrypt/Decrypt data using password based encryption. andre@0: * algid is the PBE algorithm identifier, andre@0: * pwitem is the password, andre@0: * src is the source for encryption/decryption, andre@0: * encrypt is PR_TRUE for encryption, PR_FALSE for decryption. andre@0: * The key and iv are generated based upon PKCS #5 then the src andre@0: * is either encrypted or decrypted. If an error occurs, NULL andre@0: * is returned, otherwise the ciphered contents is returned. andre@0: */ andre@0: extern SECItem * andre@0: nsspkcs5_CipherData(NSSPKCS5PBEParameter *, SECItem *pwitem, andre@0: SECItem *src, PRBool encrypt, PRBool *update); andre@0: andre@0: extern SECItem * andre@0: nsspkcs5_ComputeKeyAndIV(NSSPKCS5PBEParameter *, SECItem *pwitem, andre@0: SECItem *iv, PRBool faulty3DES); andre@0: andre@0: /* Destroys PBE parameter */ andre@0: extern void andre@0: nsspkcs5_DestroyPBEParameter(NSSPKCS5PBEParameter *param); andre@0: andre@0: HASH_HashType HASH_FromHMACOid(SECOidTag oid); andre@0: andre@0: SEC_END_PROTOS andre@0: andre@0: #endif