1 | // =================================================================== |
---|
2 | // |
---|
3 | // Copyright (c) 2005, Intel Corp. |
---|
4 | // All rights reserved. |
---|
5 | // |
---|
6 | // Redistribution and use in source and binary forms, with or without |
---|
7 | // modification, are permitted provided that the following conditions |
---|
8 | // are met: |
---|
9 | // |
---|
10 | // * Redistributions of source code must retain the above copyright |
---|
11 | // notice, this list of conditions and the following disclaimer. |
---|
12 | // * Redistributions in binary form must reproduce the above |
---|
13 | // copyright notice, this list of conditions and the following |
---|
14 | // disclaimer in the documentation and/or other materials provided |
---|
15 | // with the distribution. |
---|
16 | // * Neither the name of Intel Corporation nor the names of its |
---|
17 | // contributors may be used to endorse or promote products derived |
---|
18 | // from this software without specific prior written permission. |
---|
19 | // |
---|
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
---|
23 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
---|
24 | // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
---|
25 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
26 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
---|
27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
28 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
---|
29 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
---|
31 | // OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | // =================================================================== |
---|
33 | |
---|
34 | #ifndef __VTPM_BUFFER_H__ |
---|
35 | #define __VTPM_BUFFER_H__ |
---|
36 | |
---|
37 | #include <stddef.h> // for pointer NULL |
---|
38 | #include "tcg.h" |
---|
39 | |
---|
40 | typedef UINT32 tpm_size_t; |
---|
41 | |
---|
42 | // first version, probably will be expanded... |
---|
43 | |
---|
44 | #define NULL_BUF {0,0,0,0} |
---|
45 | |
---|
46 | typedef struct { |
---|
47 | // private!! |
---|
48 | tpm_size_t size, alloc_size; |
---|
49 | BYTE * bytes; |
---|
50 | |
---|
51 | BOOL is_owner; // do we own this buffer, and need to free it? |
---|
52 | } buffer_t; |
---|
53 | |
---|
54 | // allocate the buffer if initsize > 0, copying over initval if provided |
---|
55 | TPM_RESULT buffer_init (buffer_t * buf, |
---|
56 | tpm_size_t initsize, |
---|
57 | const BYTE* initval); |
---|
58 | |
---|
59 | // Create a new buffer from a BYTE *. Use buffer_free to destroy original BYTE * |
---|
60 | TPM_RESULT buffer_init_convert (buffer_t * buf, |
---|
61 | tpm_size_t initsize, |
---|
62 | BYTE* initval); |
---|
63 | |
---|
64 | // make an alias to a constant array, no copying |
---|
65 | TPM_RESULT buffer_init_const (buffer_t * buf, tpm_size_t size, const BYTE* val); |
---|
66 | |
---|
67 | // make an alias into buf, with given offset and length |
---|
68 | // if len = 0, make the alias go to the end of buf |
---|
69 | TPM_RESULT buffer_init_alias (buffer_t * buf, const buffer_t * b, |
---|
70 | tpm_size_t offset, tpm_size_t); |
---|
71 | |
---|
72 | // make an alias buffer into a bytestream |
---|
73 | TPM_RESULT buffer_init_alias_convert (buffer_t * buf, |
---|
74 | tpm_size_t size, BYTE* val); |
---|
75 | |
---|
76 | // "copy constructor" |
---|
77 | TPM_RESULT buffer_init_copy (buffer_t * buf, const buffer_t * src); |
---|
78 | |
---|
79 | |
---|
80 | // copy into the start of a |
---|
81 | TPM_RESULT buffer_copy (buffer_t * dest, const buffer_t* src); |
---|
82 | |
---|
83 | // are they equal? |
---|
84 | BOOL buffer_eq (const buffer_t * a, const buffer_t * b); |
---|
85 | |
---|
86 | // set the buffer to a constant byte |
---|
87 | void buffer_memset (buffer_t * buf, BYTE b); |
---|
88 | |
---|
89 | tpm_size_t buffer_len (const buffer_t* buf); |
---|
90 | |
---|
91 | TPM_RESULT buffer_free (buffer_t * buf); |
---|
92 | |
---|
93 | TPM_RESULT buffer_append_raw (buffer_t * buf, tpm_size_t len, const BYTE* bytes); |
---|
94 | |
---|
95 | #endif // _TOOLS_H_ |
---|