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_dh_nonce_finish.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_dh_nonce_finish_t private_tcg_pts_attr_dh_nonce_finish_t
;
27 * see section 3.8.3 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
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * | Reserved | Nonce Len | Selected Hash Algorithm |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * | D-H Initiator Public Value ... |
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 * | D-H Initiator Nonce ... |
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 #define PTS_DH_NONCE_FINISH_SIZE 12
42 #define PTS_DH_NONCE_FINISH_RESERVED 0x00
45 * Private data of an tcg_pts_attr_dh_nonce_finish_t object.
47 struct private_tcg_pts_attr_dh_nonce_finish_t
{
50 * Public members of tcg_pts_attr_dh_nonce_finish_t
52 tcg_pts_attr_dh_nonce_finish_t
public;
80 * Selected Hashing Algorithm
82 pts_meas_algorithms_t hash_algo
;
85 * DH Initiator Public Value
87 chunk_t initiator_pub_val
;
92 chunk_t initiator_nonce
;
95 METHOD(pa_tnc_attr_t
, get_vendor_id
, pen_t
,
96 private_tcg_pts_attr_dh_nonce_finish_t
*this)
98 return this->vendor_id
;
101 METHOD(pa_tnc_attr_t
, get_type
, u_int32_t
,
102 private_tcg_pts_attr_dh_nonce_finish_t
*this)
107 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
108 private_tcg_pts_attr_dh_nonce_finish_t
*this)
113 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
114 private_tcg_pts_attr_dh_nonce_finish_t
*this)
116 return this->noskip_flag
;
119 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
120 private_tcg_pts_attr_dh_nonce_finish_t
*this, bool noskip
)
122 this->noskip_flag
= noskip
;
125 METHOD(pa_tnc_attr_t
, build
, void,
126 private_tcg_pts_attr_dh_nonce_finish_t
*this)
128 bio_writer_t
*writer
;
130 writer
= bio_writer_create(PTS_DH_NONCE_FINISH_SIZE
);
131 writer
->write_uint8 (writer
, PTS_DH_NONCE_FINISH_RESERVED
);
132 writer
->write_uint8 (writer
, this->nonce_len
);
133 writer
->write_uint16(writer
, this->hash_algo
);
134 writer
->write_data (writer
, this->initiator_pub_val
);
135 writer
->write_data (writer
, this->initiator_nonce
);
137 this->value
= chunk_clone(writer
->get_buf(writer
));
138 writer
->destroy(writer
);
141 METHOD(pa_tnc_attr_t
, process
, status_t
,
142 private_tcg_pts_attr_dh_nonce_finish_t
*this, u_int32_t
*offset
)
144 bio_reader_t
*reader
;
148 if (this->value
.len
< PTS_DH_NONCE_FINISH_SIZE
)
150 DBG1(DBG_TNC
, "insufficient data for PTS DH Nonce Finish");
154 reader
= bio_reader_create(this->value
);
155 reader
->read_uint8 (reader
, &reserved
);
156 reader
->read_uint8 (reader
, &this->nonce_len
);
157 reader
->read_uint16(reader
, &hash_algo
);
158 this->hash_algo
= hash_algo
;
159 reader
->read_data(reader
, reader
->remaining(reader
) - this->nonce_len
,
160 &this->initiator_pub_val
);
161 reader
->read_data(reader
, this->nonce_len
, &this->initiator_nonce
);
163 reader
->destroy(reader
);
168 METHOD(pa_tnc_attr_t
, destroy
, void,
169 private_tcg_pts_attr_dh_nonce_finish_t
*this)
171 free(this->value
.ptr
);
172 free(this->initiator_pub_val
.ptr
);
173 free(this->initiator_nonce
.ptr
);
177 METHOD(tcg_pts_attr_dh_nonce_finish_t
, get_nonce_len
, u_int8_t
,
178 private_tcg_pts_attr_dh_nonce_finish_t
*this)
180 return this->nonce_len
;
183 METHOD(tcg_pts_attr_dh_nonce_finish_t
, get_hash_algo
, pts_meas_algorithms_t
,
184 private_tcg_pts_attr_dh_nonce_finish_t
*this)
186 return this->hash_algo
;
189 METHOD(tcg_pts_attr_dh_nonce_finish_t
, get_initiator_pub_val
, chunk_t
,
190 private_tcg_pts_attr_dh_nonce_finish_t
*this)
192 return this->initiator_pub_val
;
195 METHOD(tcg_pts_attr_dh_nonce_finish_t
, get_initiator_nonce
, chunk_t
,
196 private_tcg_pts_attr_dh_nonce_finish_t
*this)
198 return this->initiator_nonce
;
202 * Described in header.
204 pa_tnc_attr_t
*tcg_pts_attr_dh_nonce_finish_create(u_int8_t nonce_len
,
205 pts_meas_algorithms_t hash_algo
,
206 chunk_t initiator_nonce
,
207 chunk_t initiator_pub_val
)
209 private_tcg_pts_attr_dh_nonce_finish_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_nonce_len
= _get_nonce_len
,
224 .get_hash_algo
= _get_hash_algo
,
225 .get_initiator_nonce
= _get_initiator_nonce
,
226 .get_initiator_pub_val
= _get_initiator_pub_val
,
228 .vendor_id
= PEN_TCG
,
229 .type
= TCG_PTS_DH_NONCE_FINISH
,
230 .nonce_len
= nonce_len
,
231 .hash_algo
= hash_algo
,
232 .initiator_nonce
= initiator_nonce
,
233 .initiator_pub_val
= initiator_pub_val
,
236 return &this->public.pa_tnc_attribute
;
240 * Described in header.
242 pa_tnc_attr_t
*tcg_pts_attr_dh_nonce_finish_create_from_data(chunk_t value
)
244 private_tcg_pts_attr_dh_nonce_finish_t
*this;
248 .pa_tnc_attribute
= {
249 .get_vendor_id
= _get_vendor_id
,
250 .get_type
= _get_type
,
251 .get_value
= _get_value
,
252 .get_noskip_flag
= _get_noskip_flag
,
253 .set_noskip_flag
= _set_noskip_flag
,
258 .get_nonce_len
= _get_nonce_len
,
259 .get_hash_algo
= _get_hash_algo
,
260 .get_initiator_nonce
= _get_initiator_nonce
,
261 .get_initiator_pub_val
= _get_initiator_pub_val
,
263 .vendor_id
= PEN_TCG
,
264 .type
= TCG_PTS_DH_NONCE_FINISH
,
265 .value
= chunk_clone(value
),
268 return &this->public.pa_tnc_attribute
;