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