2 * Copyright (C) 2011 Sansar Choinyambuu
3 * HSR Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "tcg_pts_attr_meas_algo.h"
18 #include <pa_tnc/pa_tnc_msg.h>
19 #include <bio/bio_writer.h>
20 #include <bio/bio_reader.h>
23 typedef struct private_tcg_pts_attr_meas_algo_t private_tcg_pts_attr_meas_algo_t
;
26 * PTS Measurement Algorithm
27 * see section 3.9.1 of PTS Protocol: Binding to TNC IF-M Specification
30 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 * | Reserved | Hash Algorithm Set |
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * Diffie-Hellman Hash Algorithm Values
40 * see section 3.8.5 of PTS Protocol: Binding to TNC IF-M Specification
43 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * |1|2|3|R|R|R|R|R|R|R|R|R|R|R|R|R|
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 #define PTS_MEAS_ALGO_SIZE 4
52 #define PTS_MEAS_ALGO_RESERVED 0x00
55 * Private data of an tcg_pts_attr_meas_algo_t object.
57 struct private_tcg_pts_attr_meas_algo_t
{
60 * Public members of tcg_pts_attr_meas_algo_t
62 tcg_pts_attr_meas_algo_t
public;
87 pts_meas_algorithms_t algorithms
;
91 METHOD(pa_tnc_attr_t
, get_vendor_id
, pen_t
,
92 private_tcg_pts_attr_meas_algo_t
*this)
94 return this->vendor_id
;
97 METHOD(pa_tnc_attr_t
, get_type
, u_int32_t
,
98 private_tcg_pts_attr_meas_algo_t
*this)
103 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
104 private_tcg_pts_attr_meas_algo_t
*this)
109 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
110 private_tcg_pts_attr_meas_algo_t
*this)
112 return this->noskip_flag
;
115 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
116 private_tcg_pts_attr_meas_algo_t
*this, bool noskip
)
118 this->noskip_flag
= noskip
;
121 METHOD(pa_tnc_attr_t
, build
, void,
122 private_tcg_pts_attr_meas_algo_t
*this)
124 bio_writer_t
*writer
;
125 u_int16_t algorithms
= 0;
127 writer
= bio_writer_create(PTS_MEAS_ALGO_SIZE
);
128 writer
->write_uint16 (writer
, PTS_MEAS_ALGO_RESERVED
);
130 /* Determine the hash algorithms to set*/
131 if (this->algorithms
& PTS_MEAS_ALGO_SHA384
)
135 if (this->algorithms
& PTS_MEAS_ALGO_SHA256
)
139 if (this->algorithms
& PTS_MEAS_ALGO_SHA1
)
143 writer
->write_uint16(writer
, algorithms
);
145 this->value
= chunk_clone(writer
->get_buf(writer
));
146 writer
->destroy(writer
);
149 METHOD(pa_tnc_attr_t
, process
, status_t
,
150 private_tcg_pts_attr_meas_algo_t
*this, u_int32_t
*offset
)
152 bio_reader_t
*reader
;
154 u_int16_t algorithms
;
156 if (this->value
.len
< PTS_MEAS_ALGO_SIZE
)
158 DBG1(DBG_TNC
, "insufficient data for PTS Measurement Algorithm");
162 reader
= bio_reader_create(this->value
);
163 reader
->read_uint16 (reader
, &reserved
);
164 reader
->read_uint16(reader
, &algorithms
);
166 if ((algorithms
>> 13) & 1)
168 this->algorithms
|= PTS_MEAS_ALGO_SHA384
;
170 if ((algorithms
>> 14) & 1)
172 this->algorithms
|= PTS_MEAS_ALGO_SHA256
;
174 if ((algorithms
>> 15) & 1)
176 this->algorithms
|= PTS_MEAS_ALGO_SHA1
;
179 reader
->destroy(reader
);
184 METHOD(pa_tnc_attr_t
, destroy
, void,
185 private_tcg_pts_attr_meas_algo_t
*this)
187 free(this->value
.ptr
);
191 METHOD(tcg_pts_attr_meas_algo_t
, get_algorithms
, pts_meas_algorithms_t
,
192 private_tcg_pts_attr_meas_algo_t
*this)
194 return this->algorithms
;
197 METHOD(tcg_pts_attr_meas_algo_t
, set_algorithms
, void,
198 private_tcg_pts_attr_meas_algo_t
*this,
199 pts_meas_algorithms_t algorithms
)
201 this->algorithms
= algorithms
;
205 * Described in header.
207 pa_tnc_attr_t
*tcg_pts_attr_meas_algo_create(pts_meas_algorithms_t algorithms
)
209 private_tcg_pts_attr_meas_algo_t
*this;
213 .pa_tnc_attribute
= {
214 .get_vendor_id
= _get_vendor_id
,
215 .get_type
= _get_type
,
216 .get_value
= _get_value
,
217 .get_noskip_flag
= _get_noskip_flag
,
218 .set_noskip_flag
= _set_noskip_flag
,
223 .get_algorithms
= _get_algorithms
,
224 .set_algorithms
= _set_algorithms
,
226 .vendor_id
= PEN_TCG
,
227 .type
= TCG_PTS_MEAS_ALGO
,
228 .algorithms
= algorithms
,
231 return &this->public.pa_tnc_attribute
;
236 * Described in header.
238 pa_tnc_attr_t
*tcg_pts_attr_meas_algo_create_from_data(chunk_t data
)
240 private_tcg_pts_attr_meas_algo_t
*this;
244 .pa_tnc_attribute
= {
245 .get_vendor_id
= _get_vendor_id
,
246 .get_type
= _get_type
,
247 .get_value
= _get_value
,
248 .get_noskip_flag
= _get_noskip_flag
,
249 .set_noskip_flag
= _set_noskip_flag
,
254 .get_algorithms
= _get_algorithms
,
255 .set_algorithms
= _set_algorithms
,
257 .vendor_id
= PEN_TCG
,
258 .type
= TCG_PTS_MEAS_ALGO
,
259 .value
= chunk_clone(data
),
262 return &this->public.pa_tnc_attribute
;