]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/engine/eng_openssl.c
Run util/openssl-format-source -v -c .
[thirdparty/openssl.git] / crypto / engine / eng_openssl.c
1 /* crypto/engine/eng_openssl.c */
2 /*
3 * Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL project
4 * 2000.
5 */
6 /* ====================================================================
7 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * licensing@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59 /* ====================================================================
60 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
61 * ECDH support in OpenSSL originally developed by
62 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
63 */
64
65 #include <stdio.h>
66 #include <openssl/crypto.h>
67 #include "cryptlib.h"
68 #include <openssl/engine.h>
69 #include <openssl/dso.h>
70 #include <openssl/pem.h>
71 #include <openssl/evp.h>
72 #include <openssl/rand.h>
73 #ifndef OPENSSL_NO_RSA
74 # include <openssl/rsa.h>
75 #endif
76 #ifndef OPENSSL_NO_DSA
77 # include <openssl/dsa.h>
78 #endif
79 #ifndef OPENSSL_NO_DH
80 # include <openssl/dh.h>
81 #endif
82
83 #include <openssl/hmac.h>
84 #include <openssl/x509v3.h>
85
86 /*
87 * This testing gunk is implemented (and explained) lower down. It also
88 * assumes the application explicitly calls "ENGINE_load_openssl()" because
89 * this is no longer automatic in ENGINE_load_builtin_engines().
90 */
91 #define TEST_ENG_OPENSSL_RC4
92 #define TEST_ENG_OPENSSL_PKEY
93 /* #define TEST_ENG_OPENSSL_HMAC */
94 /* #define TEST_ENG_OPENSSL_HMAC_INIT */
95 /* #define TEST_ENG_OPENSSL_RC4_OTHERS */
96 #define TEST_ENG_OPENSSL_RC4_P_INIT
97 /* #define TEST_ENG_OPENSSL_RC4_P_CIPHER */
98 #define TEST_ENG_OPENSSL_SHA
99 /* #define TEST_ENG_OPENSSL_SHA_OTHERS */
100 /* #define TEST_ENG_OPENSSL_SHA_P_INIT */
101 /* #define TEST_ENG_OPENSSL_SHA_P_UPDATE */
102 /* #define TEST_ENG_OPENSSL_SHA_P_FINAL */
103
104 /* Now check what of those algorithms are actually enabled */
105 #ifdef OPENSSL_NO_RC4
106 # undef TEST_ENG_OPENSSL_RC4
107 # undef TEST_ENG_OPENSSL_RC4_OTHERS
108 # undef TEST_ENG_OPENSSL_RC4_P_INIT
109 # undef TEST_ENG_OPENSSL_RC4_P_CIPHER
110 #endif
111 #if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA0) || defined(OPENSSL_NO_SHA1)
112 # undef TEST_ENG_OPENSSL_SHA
113 # undef TEST_ENG_OPENSSL_SHA_OTHERS
114 # undef TEST_ENG_OPENSSL_SHA_P_INIT
115 # undef TEST_ENG_OPENSSL_SHA_P_UPDATE
116 # undef TEST_ENG_OPENSSL_SHA_P_FINAL
117 #endif
118
119 #ifdef TEST_ENG_OPENSSL_RC4
120 static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
121 const int **nids, int nid);
122 #endif
123 #ifdef TEST_ENG_OPENSSL_SHA
124 static int openssl_digests(ENGINE *e, const EVP_MD **digest,
125 const int **nids, int nid);
126 #endif
127
128 #ifdef TEST_ENG_OPENSSL_PKEY
129 static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
130 UI_METHOD *ui_method,
131 void *callback_data);
132 #endif
133
134 #ifdef TEST_ENG_OPENSSL_HMAC
135 static int ossl_register_hmac_meth(void);
136 static int ossl_pkey_meths(ENGINE *e, EVP_PKEY_METHOD **pmeth,
137 const int **nids, int nid);
138 #endif
139
140 /* The constants used when creating the ENGINE */
141 static const char *engine_openssl_id = "openssl";
142 static const char *engine_openssl_name = "Software engine support";
143
144 /*
145 * This internal function is used by ENGINE_openssl() and possibly by the
146 * "dynamic" ENGINE support too
147 */
148 static int bind_helper(ENGINE *e)
149 {
150 if (!ENGINE_set_id(e, engine_openssl_id)
151 || !ENGINE_set_name(e, engine_openssl_name)
152 #ifndef TEST_ENG_OPENSSL_NO_ALGORITHMS
153 # ifndef OPENSSL_NO_RSA
154 || !ENGINE_set_RSA(e, RSA_get_default_method())
155 # endif
156 # ifndef OPENSSL_NO_DSA
157 || !ENGINE_set_DSA(e, DSA_get_default_method())
158 # endif
159 # ifndef OPENSSL_NO_ECDH
160 || !ENGINE_set_ECDH(e, ECDH_OpenSSL())
161 # endif
162 # ifndef OPENSSL_NO_ECDSA
163 || !ENGINE_set_ECDSA(e, ECDSA_OpenSSL())
164 # endif
165 # ifndef OPENSSL_NO_DH
166 || !ENGINE_set_DH(e, DH_get_default_method())
167 # endif
168 || !ENGINE_set_RAND(e, RAND_SSLeay())
169 # ifdef TEST_ENG_OPENSSL_RC4
170 || !ENGINE_set_ciphers(e, openssl_ciphers)
171 # endif
172 # ifdef TEST_ENG_OPENSSL_SHA
173 || !ENGINE_set_digests(e, openssl_digests)
174 # endif
175 #endif
176 #ifdef TEST_ENG_OPENSSL_PKEY
177 || !ENGINE_set_load_privkey_function(e, openssl_load_privkey)
178 #endif
179 #ifdef TEST_ENG_OPENSSL_HMAC
180 || !ossl_register_hmac_meth()
181 || !ENGINE_set_pkey_meths(e, ossl_pkey_meths)
182 #endif
183 )
184 return 0;
185 /*
186 * If we add errors to this ENGINE, ensure the error handling is setup
187 * here
188 */
189 /* openssl_load_error_strings(); */
190 return 1;
191 }
192
193 static ENGINE *engine_openssl(void)
194 {
195 ENGINE *ret = ENGINE_new();
196 if (!ret)
197 return NULL;
198 if (!bind_helper(ret)) {
199 ENGINE_free(ret);
200 return NULL;
201 }
202 return ret;
203 }
204
205 void ENGINE_load_openssl(void)
206 {
207 ENGINE *toadd = engine_openssl();
208 if (!toadd)
209 return;
210 ENGINE_add(toadd);
211 /*
212 * If the "add" worked, it gets a structural reference. So either way, we
213 * release our just-created reference.
214 */
215 ENGINE_free(toadd);
216 ERR_clear_error();
217 }
218
219 /*
220 * This stuff is needed if this ENGINE is being compiled into a
221 * self-contained shared-library.
222 */
223 #ifdef ENGINE_DYNAMIC_SUPPORT
224 static int bind_fn(ENGINE *e, const char *id)
225 {
226 if (id && (strcmp(id, engine_openssl_id) != 0))
227 return 0;
228 if (!bind_helper(e))
229 return 0;
230 return 1;
231 }
232
233 IMPLEMENT_DYNAMIC_CHECK_FN()
234 IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
235 #endif /* ENGINE_DYNAMIC_SUPPORT */
236 #ifdef TEST_ENG_OPENSSL_RC4
237 /*-
238 * This section of code compiles an "alternative implementation" of two modes of
239 * RC4 into this ENGINE. The result is that EVP_CIPHER operation for "rc4"
240 * should under normal circumstances go via this support rather than the default
241 * EVP support. There are other symbols to tweak the testing;
242 * TEST_ENC_OPENSSL_RC4_OTHERS - print a one line message to stderr each time
243 * we're asked for a cipher we don't support (should not happen).
244 * TEST_ENG_OPENSSL_RC4_P_INIT - print a one line message to stderr each time
245 * the "init_key" handler is called.
246 * TEST_ENG_OPENSSL_RC4_P_CIPHER - ditto for the "cipher" handler.
247 */
248 # include <openssl/rc4.h>
249 # define TEST_RC4_KEY_SIZE 16
250 static const int test_cipher_nids[] = { NID_rc4, NID_rc4_40 };
251
252 static const int test_cipher_nids_number = 2;
253 typedef struct {
254 unsigned char key[TEST_RC4_KEY_SIZE];
255 RC4_KEY ks;
256 } TEST_RC4_KEY;
257 # define test(ctx) ((TEST_RC4_KEY *)(ctx)->cipher_data)
258 static int test_rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
259 const unsigned char *iv, int enc)
260 {
261 # ifdef TEST_ENG_OPENSSL_RC4_P_INIT
262 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_init_key() called\n");
263 # endif
264 memcpy(&test(ctx)->key[0], key, EVP_CIPHER_CTX_key_length(ctx));
265 RC4_set_key(&test(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx),
266 test(ctx)->key);
267 return 1;
268 }
269
270 static int test_rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
271 const unsigned char *in, size_t inl)
272 {
273 # ifdef TEST_ENG_OPENSSL_RC4_P_CIPHER
274 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_cipher() called\n");
275 # endif
276 RC4(&test(ctx)->ks, inl, in, out);
277 return 1;
278 }
279
280 static const EVP_CIPHER test_r4_cipher = {
281 NID_rc4,
282 1, TEST_RC4_KEY_SIZE, 0,
283 EVP_CIPH_VARIABLE_LENGTH,
284 test_rc4_init_key,
285 test_rc4_cipher,
286 NULL,
287 sizeof(TEST_RC4_KEY),
288 NULL,
289 NULL,
290 NULL,
291 NULL
292 };
293
294 static const EVP_CIPHER test_r4_40_cipher = {
295 NID_rc4_40,
296 1, 5 /* 40 bit */ , 0,
297 EVP_CIPH_VARIABLE_LENGTH,
298 test_rc4_init_key,
299 test_rc4_cipher,
300 NULL,
301 sizeof(TEST_RC4_KEY),
302 NULL,
303 NULL,
304 NULL,
305 NULL
306 };
307
308 static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
309 const int **nids, int nid)
310 {
311 if (!cipher) {
312 /* We are returning a list of supported nids */
313 *nids = test_cipher_nids;
314 return test_cipher_nids_number;
315 }
316 /* We are being asked for a specific cipher */
317 if (nid == NID_rc4)
318 *cipher = &test_r4_cipher;
319 else if (nid == NID_rc4_40)
320 *cipher = &test_r4_40_cipher;
321 else {
322 # ifdef TEST_ENG_OPENSSL_RC4_OTHERS
323 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) returning NULL for "
324 "nid %d\n", nid);
325 # endif
326 *cipher = NULL;
327 return 0;
328 }
329 return 1;
330 }
331 #endif
332
333 #ifdef TEST_ENG_OPENSSL_SHA
334 /* Much the same sort of comment as for TEST_ENG_OPENSSL_RC4 */
335 # include <openssl/sha.h>
336 static const int test_digest_nids[] = { NID_sha1 };
337
338 static const int test_digest_nids_number = 1;
339 static int test_sha1_init(EVP_MD_CTX *ctx)
340 {
341 # ifdef TEST_ENG_OPENSSL_SHA_P_INIT
342 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_init() called\n");
343 # endif
344 return SHA1_Init(ctx->md_data);
345 }
346
347 static int test_sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count)
348 {
349 # ifdef TEST_ENG_OPENSSL_SHA_P_UPDATE
350 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_update() called\n");
351 # endif
352 return SHA1_Update(ctx->md_data, data, count);
353 }
354
355 static int test_sha1_final(EVP_MD_CTX *ctx, unsigned char *md)
356 {
357 # ifdef TEST_ENG_OPENSSL_SHA_P_FINAL
358 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_final() called\n");
359 # endif
360 return SHA1_Final(md, ctx->md_data);
361 }
362
363 static const EVP_MD test_sha_md = {
364 NID_sha1,
365 NID_sha1WithRSAEncryption,
366 SHA_DIGEST_LENGTH,
367 0,
368 test_sha1_init,
369 test_sha1_update,
370 test_sha1_final,
371 NULL,
372 NULL,
373 EVP_PKEY_RSA_method,
374 SHA_CBLOCK,
375 sizeof(EVP_MD *) + sizeof(SHA_CTX),
376 };
377
378 static int openssl_digests(ENGINE *e, const EVP_MD **digest,
379 const int **nids, int nid)
380 {
381 if (!digest) {
382 /* We are returning a list of supported nids */
383 *nids = test_digest_nids;
384 return test_digest_nids_number;
385 }
386 /* We are being asked for a specific digest */
387 if (nid == NID_sha1)
388 *digest = &test_sha_md;
389 else {
390 # ifdef TEST_ENG_OPENSSL_SHA_OTHERS
391 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) returning NULL for "
392 "nid %d\n", nid);
393 # endif
394 *digest = NULL;
395 return 0;
396 }
397 return 1;
398 }
399 #endif
400
401 #ifdef TEST_ENG_OPENSSL_PKEY
402 static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
403 UI_METHOD *ui_method,
404 void *callback_data)
405 {
406 BIO *in;
407 EVP_PKEY *key;
408 fprintf(stderr, "(TEST_ENG_OPENSSL_PKEY)Loading Private key %s\n",
409 key_id);
410 in = BIO_new_file(key_id, "r");
411 if (!in)
412 return NULL;
413 key = PEM_read_bio_PrivateKey(in, NULL, 0, NULL);
414 BIO_free(in);
415 return key;
416 }
417 #endif
418
419 #ifdef TEST_ENG_OPENSSL_HMAC
420
421 /*
422 * Experimental HMAC redirection implementation: mainly copied from
423 * hm_pmeth.c
424 */
425
426 /* HMAC pkey context structure */
427
428 typedef struct {
429 const EVP_MD *md; /* MD for HMAC use */
430 ASN1_OCTET_STRING ktmp; /* Temp storage for key */
431 HMAC_CTX ctx;
432 } OSSL_HMAC_PKEY_CTX;
433
434 static int ossl_hmac_init(EVP_PKEY_CTX *ctx)
435 {
436 OSSL_HMAC_PKEY_CTX *hctx;
437 hctx = OPENSSL_malloc(sizeof(OSSL_HMAC_PKEY_CTX));
438 if (!hctx)
439 return 0;
440 hctx->md = NULL;
441 hctx->ktmp.data = NULL;
442 hctx->ktmp.length = 0;
443 hctx->ktmp.flags = 0;
444 hctx->ktmp.type = V_ASN1_OCTET_STRING;
445 HMAC_CTX_init(&hctx->ctx);
446 EVP_PKEY_CTX_set_data(ctx, hctx);
447 EVP_PKEY_CTX_set0_keygen_info(ctx, NULL, 0);
448 # ifdef TEST_ENG_OPENSSL_HMAC_INIT
449 fprintf(stderr, "(TEST_ENG_OPENSSL_HMAC) ossl_hmac_init() called\n");
450 # endif
451 return 1;
452 }
453
454 static int ossl_hmac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
455 {
456 OSSL_HMAC_PKEY_CTX *sctx, *dctx;
457 if (!ossl_hmac_init(dst))
458 return 0;
459 sctx = EVP_PKEY_CTX_get_data(src);
460 dctx = EVP_PKEY_CTX_get_data(dst);
461 dctx->md = sctx->md;
462 HMAC_CTX_init(&dctx->ctx);
463 if (!HMAC_CTX_copy(&dctx->ctx, &sctx->ctx))
464 return 0;
465 if (sctx->ktmp.data) {
466 if (!ASN1_OCTET_STRING_set(&dctx->ktmp,
467 sctx->ktmp.data, sctx->ktmp.length))
468 return 0;
469 }
470 return 1;
471 }
472
473 static void ossl_hmac_cleanup(EVP_PKEY_CTX *ctx)
474 {
475 OSSL_HMAC_PKEY_CTX *hctx;
476 hctx = EVP_PKEY_CTX_get_data(ctx);
477 HMAC_CTX_cleanup(&hctx->ctx);
478 if (hctx->ktmp.data) {
479 if (hctx->ktmp.length)
480 OPENSSL_cleanse(hctx->ktmp.data, hctx->ktmp.length);
481 OPENSSL_free(hctx->ktmp.data);
482 hctx->ktmp.data = NULL;
483 }
484 OPENSSL_free(hctx);
485 }
486
487 static int ossl_hmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
488 {
489 ASN1_OCTET_STRING *hkey = NULL;
490 OSSL_HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx);
491 if (!hctx->ktmp.data)
492 return 0;
493 hkey = ASN1_OCTET_STRING_dup(&hctx->ktmp);
494 if (!hkey)
495 return 0;
496 EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, hkey);
497
498 return 1;
499 }
500
501 static int ossl_int_update(EVP_MD_CTX *ctx, const void *data, size_t count)
502 {
503 OSSL_HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx->pctx);
504 if (!HMAC_Update(&hctx->ctx, data, count))
505 return 0;
506 return 1;
507 }
508
509 static int ossl_hmac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
510 {
511 EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_NO_INIT);
512 mctx->update = ossl_int_update;
513 return 1;
514 }
515
516 static int ossl_hmac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig,
517 size_t *siglen, EVP_MD_CTX *mctx)
518 {
519 unsigned int hlen;
520 OSSL_HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx);
521 int l = EVP_MD_CTX_size(mctx);
522
523 if (l < 0)
524 return 0;
525 *siglen = l;
526 if (!sig)
527 return 1;
528
529 if (!HMAC_Final(&hctx->ctx, sig, &hlen))
530 return 0;
531 *siglen = (size_t)hlen;
532 return 1;
533 }
534
535 static int ossl_hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
536 {
537 OSSL_HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx);
538 EVP_PKEY *pk;
539 ASN1_OCTET_STRING *key;
540 switch (type) {
541
542 case EVP_PKEY_CTRL_SET_MAC_KEY:
543 if ((!p2 && p1 > 0) || (p1 < -1))
544 return 0;
545 if (!ASN1_OCTET_STRING_set(&hctx->ktmp, p2, p1))
546 return 0;
547 break;
548
549 case EVP_PKEY_CTRL_MD:
550 hctx->md = p2;
551 break;
552
553 case EVP_PKEY_CTRL_DIGESTINIT:
554 pk = EVP_PKEY_CTX_get0_pkey(ctx);
555 key = EVP_PKEY_get0(pk);
556 if (!HMAC_Init_ex(&hctx->ctx, key->data, key->length, hctx->md, NULL))
557 return 0;
558 break;
559
560 default:
561 return -2;
562
563 }
564 return 1;
565 }
566
567 static int ossl_hmac_ctrl_str(EVP_PKEY_CTX *ctx,
568 const char *type, const char *value)
569 {
570 if (!value) {
571 return 0;
572 }
573 if (!strcmp(type, "key")) {
574 void *p = (void *)value;
575 return ossl_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, -1, p);
576 }
577 if (!strcmp(type, "hexkey")) {
578 unsigned char *key;
579 int r;
580 long keylen;
581 key = string_to_hex(value, &keylen);
582 if (!key)
583 return 0;
584 r = ossl_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key);
585 OPENSSL_free(key);
586 return r;
587 }
588 return -2;
589 }
590
591 static EVP_PKEY_METHOD *ossl_hmac_meth;
592
593 static int ossl_register_hmac_meth(void)
594 {
595 EVP_PKEY_METHOD *meth;
596 meth = EVP_PKEY_meth_new(EVP_PKEY_HMAC, 0);
597 if (!meth)
598 return 0;
599 EVP_PKEY_meth_set_init(meth, ossl_hmac_init);
600 EVP_PKEY_meth_set_copy(meth, ossl_hmac_copy);
601 EVP_PKEY_meth_set_cleanup(meth, ossl_hmac_cleanup);
602
603 EVP_PKEY_meth_set_keygen(meth, 0, ossl_hmac_keygen);
604
605 EVP_PKEY_meth_set_signctx(meth, ossl_hmac_signctx_init,
606 ossl_hmac_signctx);
607
608 EVP_PKEY_meth_set_ctrl(meth, ossl_hmac_ctrl, ossl_hmac_ctrl_str);
609 ossl_hmac_meth = meth;
610 return 1;
611 }
612
613 static int ossl_pkey_meths(ENGINE *e, EVP_PKEY_METHOD **pmeth,
614 const int **nids, int nid)
615 {
616 static int ossl_pkey_nids[] = {
617 EVP_PKEY_HMAC,
618 0
619 };
620 if (!pmeth) {
621 *nids = ossl_pkey_nids;
622 return 1;
623 }
624
625 if (nid == EVP_PKEY_HMAC) {
626 *pmeth = ossl_hmac_meth;
627 return 1;
628 }
629
630 *pmeth = NULL;
631 return 0;
632 }
633
634 #endif