Created framework for BLISS post-quantum signature algorithm
[strongswan.git] / src / libstrongswan / plugins / bliss / bliss_public_key.c
1 /*
2 * Copyright (C) 2014 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "bliss_public_key.h"
17
18 typedef struct private_bliss_public_key_t private_bliss_public_key_t;
19
20 /**
21 * Private data structure with signing context.
22 */
23 struct private_bliss_public_key_t {
24 /**
25 * Public interface for this signer.
26 */
27 bliss_public_key_t public;
28
29 /**
30 * BLISS type
31 */
32 u_int key_size;
33
34 /**
35 * reference counter
36 */
37 refcount_t ref;
38 };
39
40 METHOD(public_key_t, get_type, key_type_t,
41 private_bliss_public_key_t *this)
42 {
43 return KEY_BLISS;
44 }
45
46 METHOD(public_key_t, verify, bool,
47 private_bliss_public_key_t *this, signature_scheme_t scheme,
48 chunk_t data, chunk_t signature)
49 {
50 switch (scheme)
51 {
52 case SIGN_BLISS_I_SHA256:
53 return FALSE;
54 case SIGN_BLISS_IV_SHA384:
55 return FALSE;
56 default:
57 DBG1(DBG_LIB, "signature scheme %N not supported by BLISS",
58 signature_scheme_names, scheme);
59 return FALSE;
60 }
61 }
62
63 METHOD(public_key_t, encrypt_, bool,
64 private_bliss_public_key_t *this, encryption_scheme_t scheme,
65 chunk_t plain, chunk_t *crypto)
66 {
67 DBG1(DBG_LIB, "encryption scheme %N not supported",
68 encryption_scheme_names, scheme);
69 return FALSE;
70 }
71
72 METHOD(public_key_t, get_keysize, int,
73 private_bliss_public_key_t *this)
74 {
75 return this->key_size;
76 }
77
78 METHOD(public_key_t, get_encoding, bool,
79 private_bliss_public_key_t *this, cred_encoding_type_t type,
80 chunk_t *encoding)
81 {
82 bool success = TRUE;
83
84 *encoding = chunk_empty;
85
86 return success;
87 }
88
89 METHOD(public_key_t, get_fingerprint, bool,
90 private_bliss_public_key_t *this, cred_encoding_type_t type, chunk_t *fp)
91 {
92 bool success = FALSE;
93
94 return success;
95 }
96
97 METHOD(public_key_t, get_ref, public_key_t*,
98 private_bliss_public_key_t *this)
99 {
100 ref_get(&this->ref);
101 return &this->public.key;
102 }
103
104 METHOD(public_key_t, destroy, void,
105 private_bliss_public_key_t *this)
106 {
107 if (ref_put(&this->ref))
108 {
109 free(this);
110 }
111 }
112
113 /**
114 * See header.
115 */
116 bliss_public_key_t *bliss_public_key_load(key_type_t type, va_list args)
117 {
118 private_bliss_public_key_t *this;
119
120 while (TRUE)
121 {
122 switch (va_arg(args, builder_part_t))
123 {
124 case BUILD_END:
125 break;
126 default:
127 return NULL;
128 }
129 break;
130 }
131
132 INIT(this,
133 .public = {
134 .key = {
135 .get_type = _get_type,
136 .verify = _verify,
137 .encrypt = _encrypt_,
138 .equals = public_key_equals,
139 .get_keysize = _get_keysize,
140 .get_fingerprint = _get_fingerprint,
141 .has_fingerprint = public_key_has_fingerprint,
142 .get_encoding = _get_encoding,
143 .get_ref = _get_ref,
144 .destroy = _destroy,
145 },
146 },
147 .ref = 1,
148 );
149
150 return &this->public;
151 }