Implemented ntru_private_key class
[strongswan.git] / src / libstrongswan / plugins / ntru / ntru_param_set.h
1 /*
2 * Copyright (C) 2014 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * Copyright (C) 2009-2013 Security Innovation
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /**
19 * @defgroup ntru_param_set ntru_param_set
20 * @{ @ingroup ntru_p
21 */
22
23 #ifndef NTRU_PARAM_SET_H_
24 #define NTRU_PARAM_SET_H_
25
26 typedef enum ntru_param_set_id_t ntru_param_set_id_t;
27 typedef struct ntru_param_set_t ntru_param_set_t;
28
29 #include <library.h>
30
31 /**
32 * Encoding types for NTRU encryption public/private key blobs
33 */
34 #define NTRU_PUBKEY_TAG 0x01
35 #define NTRU_PRIVKEY_DEFAULT_TAG 0x02
36 #define NTRU_PRIVKEY_TRITS_TAG 0xfe
37 #define NTRU_PRIVKEY_INDICES_TAG 0xff
38
39 /**
40 * Size in octets of the OID designating the NTRU encryption parameter set
41 */
42 #define NTRU_OID_LEN 3
43
44 /**
45 * Packing types for NTRU encryption public/private keys
46 */
47 #define NTRU_KEY_PACKED_COEFFICIENTS 0x01
48 #define NTRU_KEY_PACKED_INDICES 0x02
49 #define NTRU_KEY_PACKED_TRITS 0x03
50
51 /**
52 * NTRU encryption parameter set ID list
53 */
54 enum ntru_param_set_id_t {
55 /* X9.98/IEEE 1363.1 parameter sets for best bandwidth (smallest size) */
56 NTRU_EES401EP1,
57 NTRU_EES449EP1,
58 NTRU_EES677EP1,
59 NTRU_EES1087EP2,
60 /* X9.98/IEEE 1363.1 parameter sets balancing speed and bandwidth */
61 NTRU_EES541EP1,
62 NTRU_EES613EP1,
63 NTRU_EES887EP1,
64 NTRU_EES1171EP1,
65 /* X9.98/IEEE 1363.1 parameter sets for best speed */
66 NTRU_EES659EP1,
67 NTRU_EES761EP1,
68 NTRU_EES1087EP1,
69 NTRU_EES1499EP1,
70 /* Best bandwidth and speed, no X9.98 compatibility */
71 NTRU_EES401EP2,
72 NTRU_EES439EP1,
73 NTRU_EES593EP1,
74 NTRU_EES743EP1,
75 };
76
77 extern enum_name_t *ntru_param_set_id_names;
78
79 /**
80 * NTRU encryption parameter set definitions
81 */
82 struct ntru_param_set_t {
83 ntru_param_set_id_t id; /* NTRU parameter set ID */
84 uint8_t oid[NTRU_OID_LEN]; /* pointer to OID */
85 uint8_t der_id; /* parameter-set DER id */
86 uint8_t N_bits; /* no. of bits in N (i.e. in an index */
87 uint16_t N; /* ring dimension */
88 uint16_t sec_strength_len; /* no. of octets of security strength */
89 uint16_t q; /* big modulus */
90 uint8_t q_bits; /* no. of bits in q (i.e. in a coefficient */
91 bool is_product_form; /* if product form used */
92 uint32_t dF_r; /* no. of +1 or -1 coefficients in ring elements
93 F, r */
94 uint16_t dg; /* no. - 1 of +1 coefficients or
95 no. of -1 coefficients in ring element g */
96 uint16_t m_len_max; /* max no. of plaintext octets */
97 uint16_t min_msg_rep_wt; /* min. message representative weight */
98 uint8_t c_bits; /* no. bits in candidate for deriving an index */
99 uint8_t m_len_len; /* no. of octets to hold mLenOctets */
100 };
101
102 /**
103 * Get NTRU encryption parameter set by NTRU parameter set ID
104 *
105 * @param id NTRU parameter set ID
106 * @return NTRU parameter set
107 */
108 ntru_param_set_t* ntru_param_set_get_by_id(ntru_param_set_id_t id);
109
110 /**
111 * Get NTRU encryption parameter set by NTRU parameter set OID
112 *
113 * @param oid NTRU parameter set OID
114 * @return NTRU parameter set
115 */
116 ntru_param_set_t* ntru_param_set_get_by_oid(uint8_t const *oid);
117
118 #endif /** NTRU_PARAM_SET_H_ @}*/
119