security/nss/lib/pkcs7/p7local.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial