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