summaryrefslogtreecommitdiff
path: root/src/libpts/pts/pts_meas_algo.h
blob: 1d96a49467df93aafd6eaafc93ad1437b6d81003 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * Copyright (C) 2011 Sansar Choinyambuu
 * HSR Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

/**
 * @defgroup pts_meas_algo pts_meas_algo
 * @{ @ingroup pts
 */

#ifndef PTS_MEAS_ALGO_H_
#define PTS_MEAS_ALGO_H_

#include <library.h>
#include <crypto/hashers/hasher.h>

typedef enum pts_meas_algorithms_t pts_meas_algorithms_t;

/**
 * PTS Measurement Algorithms
 */
enum pts_meas_algorithms_t {
	PTS_MEAS_ALGO_NONE   =	   0,
	PTS_MEAS_ALGO_SHA1   =	(1<<15),
	PTS_MEAS_ALGO_SHA256 =	(1<<14),
	PTS_MEAS_ALGO_SHA384 =	(1<<13),
};

/**
 * enum name for pts_meas_algorithms_t.
 */
extern enum_name_t *pts_meas_algorithm_names;

/**
 * Diffie-Hellman Hash Algorithm Values
 * see section 3.8.5 of PTS Protocol: Binding to TNC IF-M Specification
 *
 *					   1
 *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 
 *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  |1|2|3|R|R|R|R|R|R|R|R|R|R|R|R|R|
 *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  
 */

/**
 * Probe available PTS measurement algorithms
 *
 * @param algorithms	set of available algorithms
 * @return				TRUE if mandatory algorithms are available
 */
bool pts_meas_algo_probe(pts_meas_algorithms_t *algorithms);

/**
 * Update supported PTS measurement algorithms according to configuration
 *
 * sha1 :  PTS_MEAS_ALGO_SHA1
 * sha256: PTS_MEAS_ALGO_SHA1 | PTS_MEAS_ALGO_SHA256
 * sha384: PTS_MEAS_ALGO_SHA1 | PTS_MEAS_ALGO_SHA256 | PTS_MEAS_ALGO_SHA384
 *
 * The PTS-IMC is expected to select the strongest supported algorithm
 *
 * @param hash_alg		configured hash algorithm
 * @param algorithms	returns set of available PTS measurement algorithms
 */
bool pts_meas_algo_update(char *hash_alg, pts_meas_algorithms_t *algorithms);

/**
 * Select the strongest PTS measurement algorithm
 * among a set of offered PTS measurement algorithms
 *
 * @param supported_algos	set of supported PTS measurement algorithms
 * @param offered_algos		set of offered PTS measurements algorithms
 * @return					selected algorithm
 */
pts_meas_algorithms_t pts_meas_algo_select(pts_meas_algorithms_t supported_algos,
										   pts_meas_algorithms_t offered_algos);

/**
 * Convert pts_meas_algorithms_t to hash_algorithm_t
 *
 * @param algorithm		PTS measurement algorithm type
 * @return				libstrongswan hash algorithm type
 */
hash_algorithm_t pts_meas_algo_to_hash(pts_meas_algorithms_t algorithm);

/**
 * Return the hash size of a pts_meas_algorithm
 *
 * @param algorithm		PTS measurement algorithm type
 * @return				hash size in bytes
 */
size_t pts_meas_algo_hash_size(pts_meas_algorithms_t algorithm);

#endif /** PTS_MEAS_ALGO_H_ @}*/