Build correctly for me on FreeBSD 10.
[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
112 #ifdef TEST_ENG_OPENSSL_RC4
113 static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
114                            const int **nids, int nid);
115 #endif
116 #ifdef TEST_ENG_OPENSSL_SHA
117 static int openssl_digests(ENGINE *e, const EVP_MD **digest,
118                            const int **nids, int nid);
119 #endif
120
121 #ifdef TEST_ENG_OPENSSL_PKEY
122 static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
123                                       UI_METHOD *ui_method,
124                                       void *callback_data);
125 #endif
126
127 #ifdef TEST_ENG_OPENSSL_HMAC
128 static int ossl_register_hmac_meth(void);
129 static int ossl_pkey_meths(ENGINE *e, EVP_PKEY_METHOD **pmeth,
130                            const int **nids, int nid);
131 #endif
132
133 /* The constants used when creating the ENGINE */
134 static const char *engine_openssl_id = "openssl";
135 static const char *engine_openssl_name = "Software engine support";
136
137 /*
138  * This internal function is used by ENGINE_openssl() and possibly by the
139  * "dynamic" ENGINE support too
140  */
141 static int bind_helper(ENGINE *e)
142 {
143     if (!ENGINE_set_id(e, engine_openssl_id)
144         || !ENGINE_set_name(e, engine_openssl_name)
145 #ifndef TEST_ENG_OPENSSL_NO_ALGORITHMS
146 # ifndef OPENSSL_NO_RSA
147         || !ENGINE_set_RSA(e, RSA_get_default_method())
148 # endif
149 # ifndef OPENSSL_NO_DSA
150         || !ENGINE_set_DSA(e, DSA_get_default_method())
151 # endif
152 # ifndef OPENSSL_NO_ECDH
153         || !ENGINE_set_ECDH(e, ECDH_OpenSSL())
154 # endif
155 # ifndef OPENSSL_NO_ECDSA
156         || !ENGINE_set_ECDSA(e, ECDSA_OpenSSL())
157 # endif
158 # ifndef OPENSSL_NO_DH
159         || !ENGINE_set_DH(e, DH_get_default_method())
160 # endif
161         || !ENGINE_set_RAND(e, RAND_SSLeay())
162 # ifdef TEST_ENG_OPENSSL_RC4
163         || !ENGINE_set_ciphers(e, openssl_ciphers)
164 # endif
165 # ifdef TEST_ENG_OPENSSL_SHA
166         || !ENGINE_set_digests(e, openssl_digests)
167 # endif
168 #endif
169 #ifdef TEST_ENG_OPENSSL_PKEY
170         || !ENGINE_set_load_privkey_function(e, openssl_load_privkey)
171 #endif
172 #ifdef TEST_ENG_OPENSSL_HMAC
173         || !ossl_register_hmac_meth()
174         || !ENGINE_set_pkey_meths(e, ossl_pkey_meths)
175 #endif
176         )
177         return 0;
178     /*
179      * If we add errors to this ENGINE, ensure the error handling is setup
180      * here
181      */
182     /* openssl_load_error_strings(); */
183     return 1;
184 }
185
186 static ENGINE *engine_openssl(void)
187 {
188     ENGINE *ret = ENGINE_new();
189     if (!ret)
190         return NULL;
191     if (!bind_helper(ret)) {
192         ENGINE_free(ret);
193         return NULL;
194     }
195     return ret;
196 }
197
198 void ENGINE_load_openssl(void)
199 {
200     ENGINE *toadd = engine_openssl();
201     if (!toadd)
202         return;
203     ENGINE_add(toadd);
204     /*
205      * If the "add" worked, it gets a structural reference. So either way, we
206      * release our just-created reference.
207      */
208     ENGINE_free(toadd);
209     ERR_clear_error();
210 }
211
212 /*
213  * This stuff is needed if this ENGINE is being compiled into a
214  * self-contained shared-library.
215  */
216 #ifdef ENGINE_DYNAMIC_SUPPORT
217 static int bind_fn(ENGINE *e, const char *id)
218 {
219     if (id && (strcmp(id, engine_openssl_id) != 0))
220         return 0;
221     if (!bind_helper(e))
222         return 0;
223     return 1;
224 }
225
226 IMPLEMENT_DYNAMIC_CHECK_FN()
227     IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
228 #endif                          /* ENGINE_DYNAMIC_SUPPORT */
229 #ifdef TEST_ENG_OPENSSL_RC4
230 /*-
231  * This section of code compiles an "alternative implementation" of two modes of
232  * RC4 into this ENGINE. The result is that EVP_CIPHER operation for "rc4"
233  * should under normal circumstances go via this support rather than the default
234  * EVP support. There are other symbols to tweak the testing;
235  *    TEST_ENC_OPENSSL_RC4_OTHERS - print a one line message to stderr each time
236  *        we're asked for a cipher we don't support (should not happen).
237  *    TEST_ENG_OPENSSL_RC4_P_INIT - print a one line message to stderr each time
238  *        the "init_key" handler is called.
239  *    TEST_ENG_OPENSSL_RC4_P_CIPHER - ditto for the "cipher" handler.
240  */
241 # include <openssl/rc4.h>
242 # define TEST_RC4_KEY_SIZE               16
243 static const int test_cipher_nids[] = { NID_rc4, NID_rc4_40 };
244
245 static const int test_cipher_nids_number = 2;
246 typedef struct {
247     unsigned char key[TEST_RC4_KEY_SIZE];
248     RC4_KEY ks;
249 } TEST_RC4_KEY;
250 # define test(ctx) ((TEST_RC4_KEY *)(ctx)->cipher_data)
251 static int test_rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
252                              const unsigned char *iv, int enc)
253 {
254 # ifdef TEST_ENG_OPENSSL_RC4_P_INIT
255     fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_init_key() called\n");
256 # endif
257     memcpy(&test(ctx)->key[0], key, EVP_CIPHER_CTX_key_length(ctx));
258     RC4_set_key(&test(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx),
259                 test(ctx)->key);
260     return 1;
261 }
262
263 static int test_rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
264                            const unsigned char *in, size_t inl)
265 {
266 # ifdef TEST_ENG_OPENSSL_RC4_P_CIPHER
267     fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_cipher() called\n");
268 # endif
269     RC4(&test(ctx)->ks, inl, in, out);
270     return 1;
271 }
272
273 static const EVP_CIPHER test_r4_cipher = {
274     NID_rc4,
275     1, TEST_RC4_KEY_SIZE, 0,
276     EVP_CIPH_VARIABLE_LENGTH,
277     test_rc4_init_key,
278     test_rc4_cipher,
279     NULL,
280     sizeof(TEST_RC4_KEY),
281     NULL,
282     NULL,
283     NULL,
284     NULL
285 };
286
287 static const EVP_CIPHER test_r4_40_cipher = {
288     NID_rc4_40,
289     1, 5 /* 40 bit */ , 0,
290     EVP_CIPH_VARIABLE_LENGTH,
291     test_rc4_init_key,
292     test_rc4_cipher,
293     NULL,
294     sizeof(TEST_RC4_KEY),
295     NULL,
296     NULL,
297     NULL,
298     NULL
299 };
300
301 static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
302                            const int **nids, int nid)
303 {
304     if (!cipher) {
305         /* We are returning a list of supported nids */
306         *nids = test_cipher_nids;
307         return test_cipher_nids_number;
308     }
309     /* We are being asked for a specific cipher */
310     if (nid == NID_rc4)
311         *cipher = &test_r4_cipher;
312     else if (nid == NID_rc4_40)
313         *cipher = &test_r4_40_cipher;
314     else {
315 # ifdef TEST_ENG_OPENSSL_RC4_OTHERS
316         fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) returning NULL for "
317                 "nid %d\n", nid);
318 # endif
319         *cipher = NULL;
320         return 0;
321     }
322     return 1;
323 }
324 #endif
325
326 #ifdef TEST_ENG_OPENSSL_SHA
327 /* Much the same sort of comment as for TEST_ENG_OPENSSL_RC4 */
328 # include <openssl/sha.h>
329 static const int test_digest_nids[] = { NID_sha1 };
330
331 static const int test_digest_nids_number = 1;
332 static int test_sha1_init(EVP_MD_CTX *ctx)
333 {
334 # ifdef TEST_ENG_OPENSSL_SHA_P_INIT
335     fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_init() called\n");
336 # endif
337     return SHA1_Init(ctx->md_data);
338 }
339
340 static int test_sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count)
341 {
342 # ifdef TEST_ENG_OPENSSL_SHA_P_UPDATE
343     fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_update() called\n");
344 # endif
345     return SHA1_Update(ctx->md_data, data, count);
346 }
347
348 static int test_sha1_final(EVP_MD_CTX *ctx, unsigned char *md)
349 {
350 # ifdef TEST_ENG_OPENSSL_SHA_P_FINAL
351     fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_final() called\n");
352 # endif
353     return SHA1_Final(md, ctx->md_data);
354 }
355
356 static const EVP_MD test_sha_md = {
357     NID_sha1,
358     NID_sha1WithRSAEncryption,
359     SHA_DIGEST_LENGTH,
360     0,
361     test_sha1_init,
362     test_sha1_update,
363     test_sha1_final,
364     NULL,
365     NULL,
366     EVP_PKEY_RSA_method,
367     SHA_CBLOCK,
368     sizeof(EVP_MD *) + sizeof(SHA_CTX),
369 };
370
371 static int openssl_digests(ENGINE *e, const EVP_MD **digest,
372                            const int **nids, int nid)
373 {
374     if (!digest) {
375         /* We are returning a list of supported nids */
376         *nids = test_digest_nids;
377         return test_digest_nids_number;
378     }
379     /* We are being asked for a specific digest */
380     if (nid == NID_sha1)
381         *digest = &test_sha_md;
382     else {
383 # ifdef TEST_ENG_OPENSSL_SHA_OTHERS
384         fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) returning NULL for "
385                 "nid %d\n", nid);
386 # endif
387         *digest = NULL;
388         return 0;
389     }
390     return 1;
391 }
392 #endif
393
394 #ifdef TEST_ENG_OPENSSL_PKEY
395 static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
396                                       UI_METHOD *ui_method,
397                                       void *callback_data)
398 {
399     BIO *in;
400     EVP_PKEY *key;
401     fprintf(stderr, "(TEST_ENG_OPENSSL_PKEY)Loading Private key %s\n",
402             key_id);
403     in = BIO_new_file(key_id, "r");
404     if (!in)
405         return NULL;
406     key = PEM_read_bio_PrivateKey(in, NULL, 0, NULL);
407     BIO_free(in);
408     return key;
409 }
410 #endif
411
412 #ifdef TEST_ENG_OPENSSL_HMAC
413
414 /*
415  * Experimental HMAC redirection implementation: mainly copied from
416  * hm_pmeth.c
417  */
418
419 /* HMAC pkey context structure */
420
421 typedef struct {
422     const EVP_MD *md;           /* MD for HMAC use */
423     ASN1_OCTET_STRING ktmp;     /* Temp storage for key */
424     HMAC_CTX ctx;
425 } OSSL_HMAC_PKEY_CTX;
426
427 static int ossl_hmac_init(EVP_PKEY_CTX *ctx)
428 {
429     OSSL_HMAC_PKEY_CTX *hctx;
430     hctx = OPENSSL_malloc(sizeof(OSSL_HMAC_PKEY_CTX));
431     if (!hctx)
432         return 0;
433     hctx->md = NULL;
434     hctx->ktmp.data = NULL;
435     hctx->ktmp.length = 0;
436     hctx->ktmp.flags = 0;
437     hctx->ktmp.type = V_ASN1_OCTET_STRING;
438     HMAC_CTX_init(&hctx->ctx);
439     EVP_PKEY_CTX_set_data(ctx, hctx);
440     EVP_PKEY_CTX_set0_keygen_info(ctx, NULL, 0);
441 # ifdef TEST_ENG_OPENSSL_HMAC_INIT
442     fprintf(stderr, "(TEST_ENG_OPENSSL_HMAC) ossl_hmac_init() called\n");
443 # endif
444     return 1;
445 }
446
447 static int ossl_hmac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
448 {
449     OSSL_HMAC_PKEY_CTX *sctx, *dctx;
450     if (!ossl_hmac_init(dst))
451         return 0;
452     sctx = EVP_PKEY_CTX_get_data(src);
453     dctx = EVP_PKEY_CTX_get_data(dst);
454     dctx->md = sctx->md;
455     HMAC_CTX_init(&dctx->ctx);
456     if (!HMAC_CTX_copy(&dctx->ctx, &sctx->ctx))
457         return 0;
458     if (sctx->ktmp.data) {
459         if (!ASN1_OCTET_STRING_set(&dctx->ktmp,
460                                    sctx->ktmp.data, sctx->ktmp.length))
461             return 0;
462     }
463     return 1;
464 }
465
466 static void ossl_hmac_cleanup(EVP_PKEY_CTX *ctx)
467 {
468     OSSL_HMAC_PKEY_CTX *hctx;
469     hctx = EVP_PKEY_CTX_get_data(ctx);
470     HMAC_CTX_cleanup(&hctx->ctx);
471     if (hctx->ktmp.data) {
472         if (hctx->ktmp.length)
473             OPENSSL_cleanse(hctx->ktmp.data, hctx->ktmp.length);
474         OPENSSL_free(hctx->ktmp.data);
475         hctx->ktmp.data = NULL;
476     }
477     OPENSSL_free(hctx);
478 }
479
480 static int ossl_hmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
481 {
482     ASN1_OCTET_STRING *hkey = NULL;
483     OSSL_HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx);
484     if (!hctx->ktmp.data)
485         return 0;
486     hkey = ASN1_OCTET_STRING_dup(&hctx->ktmp);
487     if (!hkey)
488         return 0;
489     EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, hkey);
490
491     return 1;
492 }
493
494 static int ossl_int_update(EVP_MD_CTX *ctx, const void *data, size_t count)
495 {
496     OSSL_HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx->pctx);
497     if (!HMAC_Update(&hctx->ctx, data, count))
498         return 0;
499     return 1;
500 }
501
502 static int ossl_hmac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
503 {
504     EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_NO_INIT);
505     mctx->update = ossl_int_update;
506     return 1;
507 }
508
509 static int ossl_hmac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig,
510                              size_t *siglen, EVP_MD_CTX *mctx)
511 {
512     unsigned int hlen;
513     OSSL_HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx);
514     int l = EVP_MD_CTX_size(mctx);
515
516     if (l < 0)
517         return 0;
518     *siglen = l;
519     if (!sig)
520         return 1;
521
522     if (!HMAC_Final(&hctx->ctx, sig, &hlen))
523         return 0;
524     *siglen = (size_t)hlen;
525     return 1;
526 }
527
528 static int ossl_hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
529 {
530     OSSL_HMAC_PKEY_CTX *hctx = EVP_PKEY_CTX_get_data(ctx);
531     EVP_PKEY *pk;
532     ASN1_OCTET_STRING *key;
533     switch (type) {
534
535     case EVP_PKEY_CTRL_SET_MAC_KEY:
536         if ((!p2 && p1 > 0) || (p1 < -1))
537             return 0;
538         if (!ASN1_OCTET_STRING_set(&hctx->ktmp, p2, p1))
539             return 0;
540         break;
541
542     case EVP_PKEY_CTRL_MD:
543         hctx->md = p2;
544         break;
545
546     case EVP_PKEY_CTRL_DIGESTINIT:
547         pk = EVP_PKEY_CTX_get0_pkey(ctx);
548         key = EVP_PKEY_get0(pk);
549         if (!HMAC_Init_ex(&hctx->ctx, key->data, key->length, hctx->md, NULL))
550             return 0;
551         break;
552
553     default:
554         return -2;
555
556     }
557     return 1;
558 }
559
560 static int ossl_hmac_ctrl_str(EVP_PKEY_CTX *ctx,
561                               const char *type, const char *value)
562 {
563     if (!value) {
564         return 0;
565     }
566     if (!strcmp(type, "key")) {
567         void *p = (void *)value;
568         return ossl_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, -1, p);
569     }
570     if (!strcmp(type, "hexkey")) {
571         unsigned char *key;
572         int r;
573         long keylen;
574         key = string_to_hex(value, &keylen);
575         if (!key)
576             return 0;
577         r = ossl_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key);
578         OPENSSL_free(key);
579         return r;
580     }
581     return -2;
582 }
583
584 static EVP_PKEY_METHOD *ossl_hmac_meth;
585
586 static int ossl_register_hmac_meth(void)
587 {
588     EVP_PKEY_METHOD *meth;
589     meth = EVP_PKEY_meth_new(EVP_PKEY_HMAC, 0);
590     if (!meth)
591         return 0;
592     EVP_PKEY_meth_set_init(meth, ossl_hmac_init);
593     EVP_PKEY_meth_set_copy(meth, ossl_hmac_copy);
594     EVP_PKEY_meth_set_cleanup(meth, ossl_hmac_cleanup);
595
596     EVP_PKEY_meth_set_keygen(meth, 0, ossl_hmac_keygen);
597
598     EVP_PKEY_meth_set_signctx(meth, ossl_hmac_signctx_init,
599                               ossl_hmac_signctx);
600
601     EVP_PKEY_meth_set_ctrl(meth, ossl_hmac_ctrl, ossl_hmac_ctrl_str);
602     ossl_hmac_meth = meth;
603     return 1;
604 }
605
606 static int ossl_pkey_meths(ENGINE *e, EVP_PKEY_METHOD **pmeth,
607                            const int **nids, int nid)
608 {
609     static int ossl_pkey_nids[] = {
610         EVP_PKEY_HMAC,
611         0
612     };
613     if (!pmeth) {
614         *nids = ossl_pkey_nids;
615         return 1;
616     }
617
618     if (nid == EVP_PKEY_HMAC) {
619         *pmeth = ossl_hmac_meth;
620         return 1;
621     }
622
623     *pmeth = NULL;
624     return 0;
625 }
626
627 #endif