summaryrefslogtreecommitdiff
path: root/src/libstrongswan/plugins/bliss/bliss_utils.h
blob: 063fd91c8f2fe4368905357261b6acb6da48abb5 (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
/*
 * 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_utils bliss_utils
 * @{ @ingroup bliss_p
 */

#ifndef BLISS_UTILS_H_
#define BLISS_UTILS_H_

#include "bliss_param_set.h"

#include <library.h>

/**
 * Compute the scalar product of two vectors of size n
 *
 * @param x			input vector of size n
 * @param y			input vector of size n
 * @param n			size of input vectors x and y
 * @result			scalar product of x and y
 */
int32_t bliss_utils_scalar_product(int32_t *x, int32_t *y, int n);

/**
 * Drop d bits but round first
 *
 * @param set		BLISS parameter set
 * @param x			input vector x of size n
 * @param xd		rounded vector x with d bits dropped
 */
void bliss_utils_round_and_drop(bliss_param_set_t *set,	int32_t *x, int16_t *xd);

/**
 * Generate the binary challenge vector c as an array of kappa indices
 *
 * @param hasher	hasher used as an oracle
 * @param data_hash	hash of the data to be signed
 * @param ud		input vector ud of size n
 * @param n			size of input vector ud
 * @param kappa		parameter kappa
 * @param c_indices	indexes of non-zero challenge coefficients
 */
bool bliss_utils_generate_c(hasher_t *hasher, chunk_t data_hash, uint16_t *ud,
							int n, uint16_t kappa, uint16_t *c_indices);

/**
 * Check the infinity and l2 norms of the vectors z1 and z2d << d
 *
 * @param set	BLISS parameter set
 * @param z1	input vector
 * @param z2d	input vector
 * @result		TRUE if infinite and l2 norms do not exceed boundaries
 */
bool bliss_utils_check_norms(bliss_param_set_t *set, int32_t *z1, int16_t *z2d);

#endif /** BLISS_UTILS_H_ @}*/