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: /* andre@0: * Support routines for PKCS7 implementation, none of which are exported. andre@0: * This file should only contain things that are needed by both the andre@0: * encoding/creation side *and* the decoding/decryption side. Anything andre@0: * else should just be static routines in the appropriate file. andre@0: * andre@0: * Do not export this file! If something in here is really needed outside andre@0: * of pkcs7 code, first try to add a PKCS7 interface which will do it for andre@0: * you. If that has a problem, then just move out what you need, changing andre@0: * its name as appropriate! andre@0: */ andre@0: andre@0: #ifndef _P7LOCAL_H_ andre@0: #define _P7LOCAL_H_ andre@0: andre@0: #include "secpkcs7.h" andre@0: #include "secasn1t.h" andre@0: andre@0: extern const SEC_ASN1Template sec_PKCS7ContentInfoTemplate[]; andre@0: andre@0: /* opaque objects */ andre@0: typedef struct sec_pkcs7_cipher_object sec_PKCS7CipherObject; andre@0: andre@0: andre@0: /************************************************************************/ andre@0: SEC_BEGIN_PROTOS andre@0: andre@0: /* andre@0: * Look through a set of attributes and find one that matches the andre@0: * specified object ID. If "only" is true, then make sure that andre@0: * there is not more than one attribute of the same type. Otherwise, andre@0: * just return the first one found. (XXX Does anybody really want andre@0: * that first-found behavior? It was like that when I found it...) andre@0: */ andre@0: extern SEC_PKCS7Attribute *sec_PKCS7FindAttribute (SEC_PKCS7Attribute **attrs, andre@0: SECOidTag oidtag, andre@0: PRBool only); andre@0: /* andre@0: * Return the single attribute value, doing some sanity checking first: andre@0: * - Multiple values are *not* expected. andre@0: * - Empty values are *not* expected. andre@0: */ andre@0: extern SECItem *sec_PKCS7AttributeValue (SEC_PKCS7Attribute *attr); andre@0: andre@0: /* andre@0: * Encode a set of attributes (found in "src"). andre@0: */ andre@0: extern SECItem *sec_PKCS7EncodeAttributes (PLArenaPool *poolp, andre@0: SECItem *dest, void *src); andre@0: andre@0: /* andre@0: * Make sure that the order of the attributes guarantees valid DER andre@0: * (which must be in lexigraphically ascending order for a SET OF); andre@0: * if reordering is necessary it will be done in place (in attrs). andre@0: */ andre@0: extern SECStatus sec_PKCS7ReorderAttributes (SEC_PKCS7Attribute **attrs); andre@0: andre@0: andre@0: /* andre@0: * Create a context for decrypting, based on the given key and algorithm. andre@0: */ andre@0: extern sec_PKCS7CipherObject * andre@0: sec_PKCS7CreateDecryptObject (PK11SymKey *key, SECAlgorithmID *algid); andre@0: andre@0: /* andre@0: * Create a context for encrypting, based on the given key and algorithm, andre@0: * and fill in the algorithm id. andre@0: */ andre@0: extern sec_PKCS7CipherObject * andre@0: sec_PKCS7CreateEncryptObject (PLArenaPool *poolp, PK11SymKey *key, andre@0: SECOidTag algtag, SECAlgorithmID *algid); andre@0: andre@0: /* andre@0: * Destroy the given decryption or encryption object. andre@0: */ andre@0: extern void sec_PKCS7DestroyDecryptObject (sec_PKCS7CipherObject *obj); andre@0: extern void sec_PKCS7DestroyEncryptObject (sec_PKCS7CipherObject *obj); andre@0: andre@0: /* andre@0: * What will be the output length of the next call to encrypt/decrypt? andre@0: * Result can be used to perform memory allocations. Note that the amount andre@0: * is exactly accurate only when not doing a block cipher or when final andre@0: * is false, otherwise it is an upper bound on the amount because until andre@0: * we see the data we do not know how many padding bytes there are andre@0: * (always between 1 and the cipher block size). andre@0: * andre@0: * Note that this can return zero, which does not mean that the cipher andre@0: * operation can be skipped! (It simply means that there are not enough andre@0: * bytes to make up an entire block; the bytes will be reserved until andre@0: * there are enough to encrypt/decrypt at least one block.) However, andre@0: * if zero is returned it *does* mean that no output buffer need be andre@0: * passed in to the subsequent cipher operation, as no output bytes andre@0: * will be stored. andre@0: */ andre@0: extern unsigned int sec_PKCS7DecryptLength (sec_PKCS7CipherObject *obj, andre@0: unsigned int input_len, andre@0: PRBool final); andre@0: extern unsigned int sec_PKCS7EncryptLength (sec_PKCS7CipherObject *obj, andre@0: unsigned int input_len, andre@0: PRBool final); andre@0: andre@0: /* andre@0: * Decrypt a given length of input buffer (starting at "input" and andre@0: * containing "input_len" bytes), placing the decrypted bytes in andre@0: * "output" and storing the output length in "*output_len_p". andre@0: * "obj" is the return value from sec_PKCS7CreateDecryptObject. andre@0: * When "final" is true, this is the last of the data to be decrypted. andre@0: */ andre@0: extern SECStatus sec_PKCS7Decrypt (sec_PKCS7CipherObject *obj, andre@0: unsigned char *output, andre@0: unsigned int *output_len_p, andre@0: unsigned int max_output_len, andre@0: const unsigned char *input, andre@0: unsigned int input_len, andre@0: PRBool final); andre@0: andre@0: /* andre@0: * Encrypt a given length of input buffer (starting at "input" and andre@0: * containing "input_len" bytes), placing the encrypted bytes in andre@0: * "output" and storing the output length in "*output_len_p". andre@0: * "obj" is the return value from sec_PKCS7CreateEncryptObject. andre@0: * When "final" is true, this is the last of the data to be encrypted. andre@0: */ andre@0: extern SECStatus sec_PKCS7Encrypt (sec_PKCS7CipherObject *obj, andre@0: unsigned char *output, andre@0: unsigned int *output_len_p, andre@0: unsigned int max_output_len, andre@0: const unsigned char *input, andre@0: unsigned int input_len, andre@0: PRBool final); andre@0: andre@0: /************************************************************************/ andre@0: SEC_END_PROTOS andre@0: andre@0: #endif /* _P7LOCAL_H_ */