-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextra.c
164 lines (142 loc) · 4.19 KB
/
extra.c
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// SPDX-FileCopyrightText: 2022-2024 "extra" provider collective
//
// SPDX-License-Identifier: LGPL-3.0-or-later
/* CC-BY license applied, see LICENCE.md */
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <openssl/core.h>
#include <openssl/core_dispatch.h>
#include "prov/err.h"
#include "prov/num.h"
#include "export.h"
#include "e_params.h"
#include "local.h"
#include "crypt_data.h"
#include "md6_data.h"
/*********************************************************************
*
* Errors
*
*****/
static const OSSL_ITEM reason_strings[] = {
GLOBAL_EXTRA_REASONS,
CRYPT_REASONS,
MD6_REASONS,
{ 0, NULL }
};
/*********************************************************************
*
* Provider context
*
*****/
static void provider_ctx_free(struct provider_ctx_st *ctx)
{
if (ctx != NULL)
proverr_free_handle(ctx->proverr_handle);
free(ctx);
}
static struct provider_ctx_st *provider_ctx_new(const OSSL_CORE_HANDLE *core,
const OSSL_DISPATCH *in)
{
struct provider_ctx_st *ctx;
if ((ctx = malloc(sizeof(*ctx))) != NULL
&& (ctx->proverr_handle = proverr_new_handle(core, in)) != NULL) {
ctx->core_handle = core;
} else {
provider_ctx_free(ctx);
ctx = NULL;
}
return ctx;
}
/*********************************************************************
*
* Setup
*
*****/
/* The table of digests this provider offers */
static const OSSL_ALGORITHM digests[] = {
MD6_ALGORITHMS("provider=extra"),
{ NULL , NULL, NULL }
};
/* The table of kdfs this provider offers */
static const OSSL_ALGORITHM kdfs[] = {
CRYPT_ALGORITHMS("provider=extra"),
{ NULL , NULL, NULL }
};
/*
* Forward declarations to ensure we get signatures right. All the
* OSSL_FUNC_* types come from <openssl/core_dispatch.h>
*/
static OSSL_FUNC_provider_query_operation_fn extra_prov_operation;
static OSSL_FUNC_provider_get_params_fn extra_prov_get_params;
static OSSL_FUNC_provider_get_reason_strings_fn extra_prov_get_reason_strings;
/* The function that returns the appropriate algorithm table per operation */
static const OSSL_ALGORITHM *extra_prov_operation(void *vprovctx,
int operation_id,
int *no_cache)
{
*no_cache = 0;
switch (operation_id) {
case OSSL_OP_KDF:
return kdfs;
case OSSL_OP_DIGEST:
return digests;
}
return NULL;
}
static const OSSL_ITEM *extra_prov_get_reason_strings(void *provctx)
{
return reason_strings;
}
static int extra_prov_get_params(void *provctx, OSSL_PARAM *params)
{
OSSL_PARAM *p;
int ok = 1;
for(p = params; p->key != NULL; p++)
switch (extra_params_parse(p->key)) {
case V_PARAM_version:
*(const void **)p->data = VERSION;
p->return_size = strlen(VERSION);
break;
case V_PARAM_buildinfo:
if (BUILDTYPE[0] != '\0') {
*(const void **)p->data = BUILDTYPE;
p->return_size = strlen(BUILDTYPE);
}
break;
case V_PARAM_author:
if (AUTHOR[0] != '\0') {
*(const void **)p->data = AUTHOR;
p->return_size = strlen(AUTHOR);
}
break;
}
return ok;
}
/* The function that tears down this provider */
static void extra_prov_teardown(void *vprovctx)
{
provider_ctx_free(vprovctx);
}
/* The base dispatch table */
static const OSSL_DISPATCH provider_functions[] = {
{ OSSL_FUNC_PROVIDER_TEARDOWN, (funcptr_t)extra_prov_teardown },
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (funcptr_t)extra_prov_operation },
{ OSSL_FUNC_PROVIDER_GET_REASON_STRINGS,
(funcptr_t)extra_prov_get_reason_strings },
{ OSSL_FUNC_PROVIDER_GET_PARAMS,
(funcptr_t)extra_prov_get_params },
{ 0, NULL }
};
EXTRA_EXPORT int
OSSL_provider_init(const OSSL_CORE_HANDLE *core,
const OSSL_DISPATCH *in,
const OSSL_DISPATCH **out,
void **vprovctx)
{
if ((*vprovctx = provider_ctx_new(core, in)) == NULL)
return 0;
*out = provider_functions;
return 1;
}