summaryrefslogtreecommitdiff
path: root/src/libstrongswan/plugins/bliss/bliss_huffman_code.h
blob: df8511b2e1ad932687710d686901f9443486316b (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
/*
 * Copyright (C) 2014 Andreas Steffen
 * 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 bliss_huffman_code bliss_huffman_code
 * @{ @ingroup bliss_p
 */

#ifndef BLISS_HUFFMAN_CODE_H_
#define BLISS_HUFFMAN_CODE_H_

#include "bliss_param_set.h"

#include <library.h>

typedef struct bliss_huffman_code_t bliss_huffman_code_t;
typedef struct bliss_huffman_code_tuple_t bliss_huffman_code_tuple_t;
typedef struct bliss_huffman_code_node_t bliss_huffman_code_node_t;

struct bliss_huffman_code_tuple_t {
	uint32_t code;
	uint16_t bits;
};

#define BLISS_HUFFMAN_CODE_NO_TUPLE		-1
#define BLISS_HUFFMAN_CODE_NO_NODE		-1

struct bliss_huffman_code_node_t {
	int16_t node_0;
	int16_t node_1;
	int16_t tuple;
};

/**
 * Defines the Huffman code for the optimum encoding of a BLISS signature
 */
struct bliss_huffman_code_t {

	/**
	 * Range of z1:  0..n_z1-1
	 */
	uint16_t n_z1;

	/**
	 * Range of z2:  -n_z2..n_z2
	 */
	uint16_t n_z2;

	/**
	 * Table of tuple codewords
	 */
	bliss_huffman_code_tuple_t *tuples;

	/**
	 * Table of binary decision nodes
	 */
	bliss_huffman_code_node_t *nodes;
};

/**
 * Get Optimum Huffman code for BLISS signature given by BLISS parameter set ID
 *
 * @param id	BLISS parameter set ID
 * @return		Optimum Huffman code for BLISS signature
*/
bliss_huffman_code_t* bliss_huffman_code_get_by_id(bliss_param_set_id_t id);

#endif /** BLISS_HUFFMAN_CODE_H_ @}*/