summaryrefslogtreecommitdiff
path: root/src/libstrongswan/plugins/ntru/ntru_public_key.h
blob: 4f098f28cf5e1b09b5c35eac05ba9aaa1950628c (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
/*
 * 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 ntru_public_key ntru_public_key
 * @{ @ingroup ntru_p
 */

#ifndef NTRU_PUBLIC_KEY_H_
#define NTRU_PUBLIC_KEY_H_

typedef struct ntru_public_key_t ntru_public_key_t;

#include "ntru_param_set.h"
#include "ntru_drbg.h"

#include <library.h>

/**
 * Implements an NTRU encryption public key
 */
struct ntru_public_key_t {

	/**
	 * Returns NTRU parameter set ID of the public key
	 *
	 * @return			NTRU parameter set ID
	 */
	ntru_param_set_id_t (*get_id)(ntru_public_key_t *this);

	/**
	 * Returns the packed encoding of the NTRU encryption public key
	 *
	 * @return			Packed encoding of NTRU encryption public key
	 */
	chunk_t (*get_encoding)(ntru_public_key_t *this);

	/**
	 * Encrypts a plaintext with the NTRU public key
	 *
	 * @param ciphertext	Plaintext
	 * @param plaintext		Ciphertext
	 * @return				TRUE if encryption was successful
	 */
	bool (*encrypt)(ntru_public_key_t *this, chunk_t plaintext,
					chunk_t *ciphertext);

	/**
	 * Destroy ntru_public_key_t object
	 */
	void (*destroy)(ntru_public_key_t *this);
};

/**
 * Creates an NTRU encryption public key from coefficients
 *
 * @param drbg			Deterministic random bit generator
 * @param params		NTRU encryption parameter set to be used
 * @param pubkey		Coefficients of public key polynomial h
 */
ntru_public_key_t *ntru_public_key_create(ntru_drbg_t *drbg,
										  const ntru_param_set_t *params,
										  uint16_t *pubkey);

/**
 * Creates an NTRU encryption public key from encoding
 *
 * @param drbg			Deterministic random bit generator
 * @param data			Encoded NTRU public key
 */
ntru_public_key_t *ntru_public_key_create_from_data(ntru_drbg_t *drbg,
													chunk_t data);


#endif /** NTRU_PUBLIC_KEY_H_ @}*/