| OLD | NEW |
| (Empty) |
| 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 /* | |
| 6 * Support routines for PKCS7 implementation, none of which are exported. | |
| 7 * This file should only contain things that are needed by both the | |
| 8 * encoding/creation side *and* the decoding/decryption side. Anything | |
| 9 * else should just be static routines in the appropriate file. | |
| 10 * | |
| 11 * Do not export this file! If something in here is really needed outside | |
| 12 * of pkcs7 code, first try to add a PKCS7 interface which will do it for | |
| 13 * you. If that has a problem, then just move out what you need, changing | |
| 14 * its name as appropriate! | |
| 15 * | |
| 16 * $Id: p7local.h,v 1.4 2012/04/25 14:50:06 gerv%gerv.net Exp $ | |
| 17 */ | |
| 18 | |
| 19 #ifndef _P7LOCAL_H_ | |
| 20 #define _P7LOCAL_H_ | |
| 21 | |
| 22 #include "secpkcs7.h" | |
| 23 #include "secasn1t.h" | |
| 24 | |
| 25 extern const SEC_ASN1Template sec_PKCS7ContentInfoTemplate[]; | |
| 26 | |
| 27 /* opaque objects */ | |
| 28 typedef struct sec_pkcs7_cipher_object sec_PKCS7CipherObject; | |
| 29 | |
| 30 | |
| 31 /************************************************************************/ | |
| 32 SEC_BEGIN_PROTOS | |
| 33 | |
| 34 /* | |
| 35 * Look through a set of attributes and find one that matches the | |
| 36 * specified object ID. If "only" is true, then make sure that | |
| 37 * there is not more than one attribute of the same type. Otherwise, | |
| 38 * just return the first one found. (XXX Does anybody really want | |
| 39 * that first-found behavior? It was like that when I found it...) | |
| 40 */ | |
| 41 extern SEC_PKCS7Attribute *sec_PKCS7FindAttribute (SEC_PKCS7Attribute **attrs, | |
| 42 SECOidTag oidtag, | |
| 43 PRBool only); | |
| 44 /* | |
| 45 * Return the single attribute value, doing some sanity checking first: | |
| 46 * - Multiple values are *not* expected. | |
| 47 * - Empty values are *not* expected. | |
| 48 */ | |
| 49 extern SECItem *sec_PKCS7AttributeValue (SEC_PKCS7Attribute *attr); | |
| 50 | |
| 51 /* | |
| 52 * Encode a set of attributes (found in "src"). | |
| 53 */ | |
| 54 extern SECItem *sec_PKCS7EncodeAttributes (PRArenaPool *poolp, | |
| 55 SECItem *dest, void *src); | |
| 56 | |
| 57 /* | |
| 58 * Make sure that the order of the attributes guarantees valid DER | |
| 59 * (which must be in lexigraphically ascending order for a SET OF); | |
| 60 * if reordering is necessary it will be done in place (in attrs). | |
| 61 */ | |
| 62 extern SECStatus sec_PKCS7ReorderAttributes (SEC_PKCS7Attribute **attrs); | |
| 63 | |
| 64 | |
| 65 /* | |
| 66 * Create a context for decrypting, based on the given key and algorithm. | |
| 67 */ | |
| 68 extern sec_PKCS7CipherObject * | |
| 69 sec_PKCS7CreateDecryptObject (PK11SymKey *key, SECAlgorithmID *algid); | |
| 70 | |
| 71 /* | |
| 72 * Create a context for encrypting, based on the given key and algorithm, | |
| 73 * and fill in the algorithm id. | |
| 74 */ | |
| 75 extern sec_PKCS7CipherObject * | |
| 76 sec_PKCS7CreateEncryptObject (PRArenaPool *poolp, PK11SymKey *key, | |
| 77 SECOidTag algtag, SECAlgorithmID *algid); | |
| 78 | |
| 79 /* | |
| 80 * Destroy the given decryption or encryption object. | |
| 81 */ | |
| 82 extern void sec_PKCS7DestroyDecryptObject (sec_PKCS7CipherObject *obj); | |
| 83 extern void sec_PKCS7DestroyEncryptObject (sec_PKCS7CipherObject *obj); | |
| 84 | |
| 85 /* | |
| 86 * What will be the output length of the next call to encrypt/decrypt? | |
| 87 * Result can be used to perform memory allocations. Note that the amount | |
| 88 * is exactly accurate only when not doing a block cipher or when final | |
| 89 * is false, otherwise it is an upper bound on the amount because until | |
| 90 * we see the data we do not know how many padding bytes there are | |
| 91 * (always between 1 and the cipher block size). | |
| 92 * | |
| 93 * Note that this can return zero, which does not mean that the cipher | |
| 94 * operation can be skipped! (It simply means that there are not enough | |
| 95 * bytes to make up an entire block; the bytes will be reserved until | |
| 96 * there are enough to encrypt/decrypt at least one block.) However, | |
| 97 * if zero is returned it *does* mean that no output buffer need be | |
| 98 * passed in to the subsequent cipher operation, as no output bytes | |
| 99 * will be stored. | |
| 100 */ | |
| 101 extern unsigned int sec_PKCS7DecryptLength (sec_PKCS7CipherObject *obj, | |
| 102 unsigned int input_len, | |
| 103 PRBool final); | |
| 104 extern unsigned int sec_PKCS7EncryptLength (sec_PKCS7CipherObject *obj, | |
| 105 unsigned int input_len, | |
| 106 PRBool final); | |
| 107 | |
| 108 /* | |
| 109 * Decrypt a given length of input buffer (starting at "input" and | |
| 110 * containing "input_len" bytes), placing the decrypted bytes in | |
| 111 * "output" and storing the output length in "*output_len_p". | |
| 112 * "obj" is the return value from sec_PKCS7CreateDecryptObject. | |
| 113 * When "final" is true, this is the last of the data to be decrypted. | |
| 114 */ | |
| 115 extern SECStatus sec_PKCS7Decrypt (sec_PKCS7CipherObject *obj, | |
| 116 unsigned char *output, | |
| 117 unsigned int *output_len_p, | |
| 118 unsigned int max_output_len, | |
| 119 const unsigned char *input, | |
| 120 unsigned int input_len, | |
| 121 PRBool final); | |
| 122 | |
| 123 /* | |
| 124 * Encrypt a given length of input buffer (starting at "input" and | |
| 125 * containing "input_len" bytes), placing the encrypted bytes in | |
| 126 * "output" and storing the output length in "*output_len_p". | |
| 127 * "obj" is the return value from sec_PKCS7CreateEncryptObject. | |
| 128 * When "final" is true, this is the last of the data to be encrypted. | |
| 129 */ | |
| 130 extern SECStatus sec_PKCS7Encrypt (sec_PKCS7CipherObject *obj, | |
| 131 unsigned char *output, | |
| 132 unsigned int *output_len_p, | |
| 133 unsigned int max_output_len, | |
| 134 const unsigned char *input, | |
| 135 unsigned int input_len, | |
| 136 PRBool final); | |
| 137 | |
| 138 /************************************************************************/ | |
| 139 SEC_END_PROTOS | |
| 140 | |
| 141 #endif /* _P7LOCAL_H_ */ | |
| OLD | NEW |