|
@@ -96,6 +96,67 @@ struct pubkey_algorithm {
|
96
|
96
|
const char *name;
|
97
|
97
|
/** Context size */
|
98
|
98
|
size_t ctxsize;
|
|
99
|
+ /** Initialise algorithm
|
|
100
|
+ *
|
|
101
|
+ * @v ctx Context
|
|
102
|
+ * @v key Key
|
|
103
|
+ * @v key_len Length of key
|
|
104
|
+ * @ret rc Return status code
|
|
105
|
+ */
|
|
106
|
+ int ( * init ) ( void *ctx, const void *key, size_t key_len );
|
|
107
|
+ /** Calculate maximum output length
|
|
108
|
+ *
|
|
109
|
+ * @v ctx Context
|
|
110
|
+ * @ret max_len Maximum output length
|
|
111
|
+ */
|
|
112
|
+ size_t ( * max_len ) ( void *ctx );
|
|
113
|
+ /** Encrypt
|
|
114
|
+ *
|
|
115
|
+ * @v ctx Context
|
|
116
|
+ * @v plaintext Plaintext
|
|
117
|
+ * @v plaintext_len Length of plaintext
|
|
118
|
+ * @v ciphertext Ciphertext
|
|
119
|
+ * @ret ciphertext_len Length of ciphertext, or negative error
|
|
120
|
+ */
|
|
121
|
+ int ( * encrypt ) ( void *ctx, const void *data, size_t len,
|
|
122
|
+ void *out );
|
|
123
|
+ /** Decrypt
|
|
124
|
+ *
|
|
125
|
+ * @v ctx Context
|
|
126
|
+ * @v ciphertext Ciphertext
|
|
127
|
+ * @v ciphertext_len Ciphertext length
|
|
128
|
+ * @v plaintext Plaintext
|
|
129
|
+ * @ret plaintext_len Plaintext length, or negative error
|
|
130
|
+ */
|
|
131
|
+ int ( * decrypt ) ( void *ctx, const void *data, size_t len,
|
|
132
|
+ void *out );
|
|
133
|
+ /** Sign digest value
|
|
134
|
+ *
|
|
135
|
+ * @v ctx Context
|
|
136
|
+ * @v digest Digest algorithm
|
|
137
|
+ * @v value Digest value
|
|
138
|
+ * @v signature Signature
|
|
139
|
+ * @ret signature_len Signature length, or negative error
|
|
140
|
+ */
|
|
141
|
+ int ( * sign ) ( void *ctx, struct digest_algorithm *digest,
|
|
142
|
+ const void *value, void *signature );
|
|
143
|
+ /** Verify signed digest value
|
|
144
|
+ *
|
|
145
|
+ * @v ctx Context
|
|
146
|
+ * @v digest Digest algorithm
|
|
147
|
+ * @v value Digest value
|
|
148
|
+ * @v signature Signature
|
|
149
|
+ * @v signature_len Signature length
|
|
150
|
+ * @ret rc Return status code
|
|
151
|
+ */
|
|
152
|
+ int ( * verify ) ( void *ctx, struct digest_algorithm *digest,
|
|
153
|
+ const void *value, const void *signature,
|
|
154
|
+ size_t signature_len );
|
|
155
|
+ /** Finalise algorithm
|
|
156
|
+ *
|
|
157
|
+ * @v ctx Context
|
|
158
|
+ */
|
|
159
|
+ void ( * final ) ( void *ctx );
|
99
|
160
|
};
|
100
|
161
|
|
101
|
162
|
static inline void digest_init ( struct digest_algorithm *digest,
|
|
@@ -147,6 +208,43 @@ static inline int is_stream_cipher ( struct cipher_algorithm *cipher ) {
|
147
|
208
|
return ( cipher->blocksize == 1 );
|
148
|
209
|
}
|
149
|
210
|
|
|
211
|
+static inline int pubkey_init ( struct pubkey_algorithm *pubkey, void *ctx,
|
|
212
|
+ const void *key, size_t key_len ) {
|
|
213
|
+ return pubkey->init ( ctx, key, key_len );
|
|
214
|
+}
|
|
215
|
+
|
|
216
|
+static inline size_t pubkey_max_len ( struct pubkey_algorithm *pubkey,
|
|
217
|
+ void *ctx ) {
|
|
218
|
+ return pubkey->max_len ( ctx );
|
|
219
|
+}
|
|
220
|
+
|
|
221
|
+static inline int pubkey_encrypt ( struct pubkey_algorithm *pubkey, void *ctx,
|
|
222
|
+ const void *data, size_t len, void *out ) {
|
|
223
|
+ return pubkey->encrypt ( ctx, data, len, out );
|
|
224
|
+}
|
|
225
|
+
|
|
226
|
+static inline int pubkey_decrypt ( struct pubkey_algorithm *pubkey, void *ctx,
|
|
227
|
+ const void *data, size_t len, void *out ) {
|
|
228
|
+ return pubkey->decrypt ( ctx, data, len, out );
|
|
229
|
+}
|
|
230
|
+
|
|
231
|
+static inline int pubkey_sign ( struct pubkey_algorithm *pubkey, void *ctx,
|
|
232
|
+ struct digest_algorithm *digest,
|
|
233
|
+ const void *value, void *signature ) {
|
|
234
|
+ return pubkey->sign ( ctx, digest, value, signature );
|
|
235
|
+}
|
|
236
|
+
|
|
237
|
+static inline int pubkey_verify ( struct pubkey_algorithm *pubkey, void *ctx,
|
|
238
|
+ struct digest_algorithm *digest,
|
|
239
|
+ const void *value, const void *signature,
|
|
240
|
+ size_t signature_len ) {
|
|
241
|
+ return pubkey->verify ( ctx, digest, value, signature, signature_len );
|
|
242
|
+}
|
|
243
|
+
|
|
244
|
+static inline void pubkey_final ( struct pubkey_algorithm *pubkey, void *ctx ) {
|
|
245
|
+ pubkey->final ( ctx );
|
|
246
|
+}
|
|
247
|
+
|
150
|
248
|
extern struct digest_algorithm digest_null;
|
151
|
249
|
extern struct cipher_algorithm cipher_null;
|
152
|
250
|
extern struct pubkey_algorithm pubkey_null;
|