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