]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - contrib/bind9/lib/dns/opensslrsa_link.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / contrib / bind9 / lib / dns / opensslrsa_link.c
1 /*
2  * Copyright (C) 2004-2010  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2000-2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /*
19  * Principal Author: Brian Wellington
20  * $Id: opensslrsa_link.c,v 1.20.50.8 2010/01/22 02:36:49 marka Exp $
21  */
22 #ifdef OPENSSL
23 #include <config.h>
24
25 #ifndef USE_EVP
26 #if !defined(HAVE_EVP_SHA256) || !defined(HAVE_EVP_SHA512)
27 #define USE_EVP 0
28 #else
29 #define USE_EVP 1
30 #endif
31 #endif
32
33 #include <isc/entropy.h>
34 #include <isc/md5.h>
35 #include <isc/sha1.h>
36 #include <isc/sha2.h>
37 #include <isc/mem.h>
38 #include <isc/string.h>
39 #include <isc/util.h>
40
41 #include <dst/result.h>
42
43 #include "dst_internal.h"
44 #include "dst_openssl.h"
45 #include "dst_parse.h"
46
47 #include <openssl/err.h>
48 #include <openssl/objects.h>
49 #include <openssl/rsa.h>
50 #if OPENSSL_VERSION_NUMBER > 0x00908000L
51 #include <openssl/bn.h>
52 #endif
53 #include <openssl/engine.h>
54
55 /*
56  * We don't use configure for windows so enforce the OpenSSL version
57  * here.  Unlike with configure we don't support overriding this test.
58  */
59 #ifdef WIN32
60 #if !((OPENSSL_VERSION_NUMBER >= 0x009070cfL && \
61        OPENSSL_VERSION_NUMBER < 0x00908000L) || \
62       OPENSSL_VERSION_NUMBER >= 0x0090804fL)
63 #error Please upgrade OpenSSL to 0.9.8d/0.9.7l or greater.
64 #endif
65 #endif
66
67
68         /*
69          * XXXMPA  Temporarily disable RSA_BLINDING as it requires
70          * good quality random data that cannot currently be guaranteed.
71          * XXXMPA  Find which versions of openssl use pseudo random data
72          * and set RSA_FLAG_BLINDING for those.
73          */
74
75 #if 0
76 #if OPENSSL_VERSION_NUMBER < 0x0090601fL
77 #define SET_FLAGS(rsa) \
78         do { \
79         (rsa)->flags &= ~(RSA_FLAG_CACHE_PUBLIC | RSA_FLAG_CACHE_PRIVATE); \
80         (rsa)->flags |= RSA_FLAG_BLINDING; \
81         } while (0)
82 #else
83 #define SET_FLAGS(rsa) \
84         do { \
85                 (rsa)->flags |= RSA_FLAG_BLINDING; \
86         } while (0)
87 #endif
88 #endif
89
90 #if OPENSSL_VERSION_NUMBER < 0x0090601fL
91 #define SET_FLAGS(rsa) \
92         do { \
93         (rsa)->flags &= ~(RSA_FLAG_CACHE_PUBLIC | RSA_FLAG_CACHE_PRIVATE); \
94         (rsa)->flags &= ~RSA_FLAG_BLINDING; \
95         } while (0)
96 #elif defined(RSA_FLAG_NO_BLINDING)
97 #define SET_FLAGS(rsa) \
98         do { \
99                 (rsa)->flags &= ~RSA_FLAG_BLINDING; \
100                 (rsa)->flags |= RSA_FLAG_NO_BLINDING; \
101         } while (0)
102 #else
103 #define SET_FLAGS(rsa) \
104         do { \
105                 (rsa)->flags &= ~RSA_FLAG_BLINDING; \
106         } while (0)
107 #endif
108
109 #define DST_RET(a) {ret = a; goto err;}
110
111 static isc_result_t opensslrsa_todns(const dst_key_t *key, isc_buffer_t *data);
112
113 static isc_result_t
114 opensslrsa_createctx(dst_key_t *key, dst_context_t *dctx) {
115 #if USE_EVP
116         EVP_MD_CTX *evp_md_ctx;
117         const EVP_MD *type = NULL;
118 #endif
119
120         UNUSED(key);
121         REQUIRE(dctx->key->key_alg == DST_ALG_RSAMD5 ||
122                 dctx->key->key_alg == DST_ALG_RSASHA1 ||
123                 dctx->key->key_alg == DST_ALG_NSEC3RSASHA1 ||
124                 dctx->key->key_alg == DST_ALG_RSASHA256 ||
125                 dctx->key->key_alg == DST_ALG_RSASHA512);
126
127 #if USE_EVP
128         evp_md_ctx = EVP_MD_CTX_create();
129         if (evp_md_ctx == NULL)
130                 return (ISC_R_NOMEMORY);
131
132         switch (dctx->key->key_alg) {
133         case DST_ALG_RSAMD5:
134                 type = EVP_md5();       /* MD5 + RSA */
135                 break;
136         case DST_ALG_RSASHA1:
137         case DST_ALG_NSEC3RSASHA1:
138                 type = EVP_sha1();      /* SHA1 + RSA */
139                 break;
140 #ifdef HAVE_EVP_SHA256
141         case DST_ALG_RSASHA256:
142                 type = EVP_sha256();    /* SHA256 + RSA */
143                 break;
144 #endif
145 #ifdef HAVE_EVP_SHA512
146         case DST_ALG_RSASHA512:
147                 type = EVP_sha512();
148                 break;
149 #endif
150         default:
151                 INSIST(0);
152         }
153
154         if (!EVP_DigestInit_ex(evp_md_ctx, type, NULL)) {
155                 EVP_MD_CTX_destroy(evp_md_ctx);
156                 return (ISC_R_FAILURE);
157         }
158         dctx->ctxdata.evp_md_ctx = evp_md_ctx;
159 #else
160         switch (dctx->key->key_alg) {
161         case DST_ALG_RSAMD5:
162                 {
163                         isc_md5_t *md5ctx;
164
165                         md5ctx = isc_mem_get(dctx->mctx, sizeof(isc_md5_t));
166                         if (md5ctx == NULL)
167                                 return (ISC_R_NOMEMORY);
168                         isc_md5_init(md5ctx);
169                         dctx->ctxdata.md5ctx = md5ctx;
170                 }
171                 break;
172         case DST_ALG_RSASHA1:
173         case DST_ALG_NSEC3RSASHA1:
174                 {
175                         isc_sha1_t *sha1ctx;
176
177                         sha1ctx = isc_mem_get(dctx->mctx, sizeof(isc_sha1_t));
178                         if (sha1ctx == NULL)
179                                 return (ISC_R_NOMEMORY);
180                         isc_sha1_init(sha1ctx);
181                         dctx->ctxdata.sha1ctx = sha1ctx;
182                 }
183                 break;
184         case DST_ALG_RSASHA256:
185                 {
186                         isc_sha256_t *sha256ctx;
187
188                         sha256ctx = isc_mem_get(dctx->mctx,
189                                                 sizeof(isc_sha256_t));
190                         if (sha256ctx == NULL)
191                                 return (ISC_R_NOMEMORY);
192                         isc_sha256_init(sha256ctx);
193                         dctx->ctxdata.sha256ctx = sha256ctx;
194                 }
195                 break;
196         case DST_ALG_RSASHA512:
197                 {
198                         isc_sha512_t *sha512ctx;
199
200                         sha512ctx = isc_mem_get(dctx->mctx,
201                                                 sizeof(isc_sha512_t));
202                         if (sha512ctx == NULL)
203                                 return (ISC_R_NOMEMORY);
204                         isc_sha512_init(sha512ctx);
205                         dctx->ctxdata.sha512ctx = sha512ctx;
206                 }
207                 break;
208         default:
209                 INSIST(0);
210         }
211 #endif
212
213         return (ISC_R_SUCCESS);
214 }
215
216 static void
217 opensslrsa_destroyctx(dst_context_t *dctx) {
218 #if USE_EVP
219         EVP_MD_CTX *evp_md_ctx = dctx->ctxdata.evp_md_ctx;
220 #endif
221
222         REQUIRE(dctx->key->key_alg == DST_ALG_RSAMD5 ||
223                 dctx->key->key_alg == DST_ALG_RSASHA1 ||
224                 dctx->key->key_alg == DST_ALG_NSEC3RSASHA1 ||
225                 dctx->key->key_alg == DST_ALG_RSASHA256 ||
226                 dctx->key->key_alg == DST_ALG_RSASHA512);
227
228 #if USE_EVP
229         if (evp_md_ctx != NULL) {
230                 EVP_MD_CTX_destroy(evp_md_ctx);
231                 dctx->ctxdata.evp_md_ctx = NULL;
232         }
233 #else
234         switch (dctx->key->key_alg) {
235         case DST_ALG_RSAMD5:
236                 {
237                         isc_md5_t *md5ctx = dctx->ctxdata.md5ctx;
238
239                         if (md5ctx != NULL) {
240                                 isc_md5_invalidate(md5ctx);
241                                 isc_mem_put(dctx->mctx, md5ctx,
242                                             sizeof(isc_md5_t));
243                                 dctx->ctxdata.md5ctx = NULL;
244                         }
245                 }
246                 break;
247         case DST_ALG_RSASHA1:
248         case DST_ALG_NSEC3RSASHA1:
249                 {
250                         isc_sha1_t *sha1ctx = dctx->ctxdata.sha1ctx;
251
252                         if (sha1ctx != NULL) {
253                                 isc_sha1_invalidate(sha1ctx);
254                                 isc_mem_put(dctx->mctx, sha1ctx,
255                                             sizeof(isc_sha1_t));
256                                 dctx->ctxdata.sha1ctx = NULL;
257                         }
258                 }
259                 break;
260         case DST_ALG_RSASHA256:
261                 {
262                         isc_sha256_t *sha256ctx = dctx->ctxdata.sha256ctx;
263
264                         if (sha256ctx != NULL) {
265                                 isc_sha256_invalidate(sha256ctx);
266                                 isc_mem_put(dctx->mctx, sha256ctx,
267                                             sizeof(isc_sha256_t));
268                                 dctx->ctxdata.sha256ctx = NULL;
269                         }
270                 }
271                 break;
272         case DST_ALG_RSASHA512:
273                 {
274                         isc_sha512_t *sha512ctx = dctx->ctxdata.sha512ctx;
275
276                         if (sha512ctx != NULL) {
277                                 isc_sha512_invalidate(sha512ctx);
278                                 isc_mem_put(dctx->mctx, sha512ctx,
279                                             sizeof(isc_sha512_t));
280                                 dctx->ctxdata.sha512ctx = NULL;
281                         }
282                 }
283                 break;
284         default:
285                 INSIST(0);
286         }
287 #endif
288 }
289
290 static isc_result_t
291 opensslrsa_adddata(dst_context_t *dctx, const isc_region_t *data) {
292 #if USE_EVP
293         EVP_MD_CTX *evp_md_ctx = dctx->ctxdata.evp_md_ctx;
294 #endif
295
296         REQUIRE(dctx->key->key_alg == DST_ALG_RSAMD5 ||
297                 dctx->key->key_alg == DST_ALG_RSASHA1 ||
298                 dctx->key->key_alg == DST_ALG_NSEC3RSASHA1 ||
299                 dctx->key->key_alg == DST_ALG_RSASHA256 ||
300                 dctx->key->key_alg == DST_ALG_RSASHA512);
301
302 #if USE_EVP
303         if (!EVP_DigestUpdate(evp_md_ctx, data->base, data->length)) {
304                 return (ISC_R_FAILURE);
305         }
306 #else
307         switch (dctx->key->key_alg) {
308         case DST_ALG_RSAMD5:
309                 {
310                         isc_md5_t *md5ctx = dctx->ctxdata.md5ctx;
311
312                         isc_md5_update(md5ctx, data->base, data->length);
313                 }
314                 break;
315         case DST_ALG_RSASHA1:
316         case DST_ALG_NSEC3RSASHA1:
317                 {
318                         isc_sha1_t *sha1ctx = dctx->ctxdata.sha1ctx;
319
320                         isc_sha1_update(sha1ctx, data->base, data->length);
321                 }
322                 break;
323         case DST_ALG_RSASHA256:
324                 {
325                         isc_sha256_t *sha256ctx = dctx->ctxdata.sha256ctx;
326
327                         isc_sha256_update(sha256ctx, data->base, data->length);
328                 }
329                 break;
330         case DST_ALG_RSASHA512:
331                 {
332                         isc_sha512_t *sha512ctx = dctx->ctxdata.sha512ctx;
333
334                         isc_sha512_update(sha512ctx, data->base, data->length);
335                 }
336                 break;
337         default:
338                 INSIST(0);
339         }
340 #endif
341         return (ISC_R_SUCCESS);
342 }
343
344 #if ! USE_EVP && OPENSSL_VERSION_NUMBER < 0x00908000L
345 /*
346  * Digest prefixes from RFC 5702.
347  */
348 static unsigned char sha256_prefix[] =
349          { 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48,
350            0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20};
351 static unsigned char sha512_prefix[] =
352          { 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48,
353            0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40};
354 #define PREFIXLEN sizeof(sha512_prefix)
355 #else
356 #define PREFIXLEN 0
357 #endif
358
359 static isc_result_t
360 opensslrsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
361         dst_key_t *key = dctx->key;
362         isc_region_t r;
363         unsigned int siglen = 0;
364 #if USE_EVP
365         EVP_MD_CTX *evp_md_ctx = dctx->ctxdata.evp_md_ctx;
366         EVP_PKEY *pkey = key->keydata.pkey;
367 #else
368         RSA *rsa = key->keydata.rsa;
369         /* note: ISC_SHA512_DIGESTLENGTH >= ISC_*_DIGESTLENGTH */
370         unsigned char digest[PREFIXLEN + ISC_SHA512_DIGESTLENGTH];
371         int status = 0;
372         int type = 0;
373         unsigned int digestlen = 0;
374         char *message;
375         unsigned long err;
376         const char* file;
377         int line;
378 #if OPENSSL_VERSION_NUMBER < 0x00908000L
379         unsigned int prefixlen = 0;
380         const unsigned char *prefix = NULL;
381 #endif
382 #endif
383
384         REQUIRE(dctx->key->key_alg == DST_ALG_RSAMD5 ||
385                 dctx->key->key_alg == DST_ALG_RSASHA1 ||
386                 dctx->key->key_alg == DST_ALG_NSEC3RSASHA1 ||
387                 dctx->key->key_alg == DST_ALG_RSASHA256 ||
388                 dctx->key->key_alg == DST_ALG_RSASHA512);
389
390         isc_buffer_availableregion(sig, &r);
391
392 #if USE_EVP
393         if (r.length < (unsigned int) EVP_PKEY_size(pkey))
394                 return (ISC_R_NOSPACE);
395
396         if (!EVP_SignFinal(evp_md_ctx, r.base, &siglen, pkey)) {
397                 return (ISC_R_FAILURE);
398         }
399 #else
400         if (r.length < (unsigned int) RSA_size(rsa))
401                 return (ISC_R_NOSPACE);
402
403         switch (dctx->key->key_alg) {
404         case DST_ALG_RSAMD5:
405                 {
406                         isc_md5_t *md5ctx = dctx->ctxdata.md5ctx;
407
408                         isc_md5_final(md5ctx, digest);
409                         type = NID_md5;
410                         digestlen = ISC_MD5_DIGESTLENGTH;
411                 }
412                 break;
413         case DST_ALG_RSASHA1:
414         case DST_ALG_NSEC3RSASHA1:
415                 {
416                         isc_sha1_t *sha1ctx = dctx->ctxdata.sha1ctx;
417
418                         isc_sha1_final(sha1ctx, digest);
419                         type = NID_sha1;
420                         digestlen = ISC_SHA1_DIGESTLENGTH;
421                 }
422                 break;
423         case DST_ALG_RSASHA256:
424                 {
425                         isc_sha256_t *sha256ctx = dctx->ctxdata.sha256ctx;
426
427                         isc_sha256_final(digest, sha256ctx);
428                         digestlen = ISC_SHA256_DIGESTLENGTH;
429 #if OPENSSL_VERSION_NUMBER < 0x00908000L
430                         prefix = sha256_prefix;
431                         prefixlen = sizeof(sha256_prefix);
432 #else
433                         type = NID_sha256;
434 #endif
435                 }
436                 break;
437         case DST_ALG_RSASHA512:
438                 {
439                         isc_sha512_t *sha512ctx = dctx->ctxdata.sha512ctx;
440
441                         isc_sha512_final(digest, sha512ctx);
442                         digestlen = ISC_SHA512_DIGESTLENGTH;
443 #if OPENSSL_VERSION_NUMBER < 0x00908000L
444                         prefix = sha512_prefix;
445                         prefixlen = sizeof(sha512_prefix);
446 #else
447                         type = NID_sha512;
448 #endif
449                 }
450                 break;
451         default:
452                 INSIST(0);
453         }
454
455 #if OPENSSL_VERSION_NUMBER < 0x00908000L
456         switch (dctx->key->key_alg) {
457         case DST_ALG_RSAMD5:
458         case DST_ALG_RSASHA1:
459         case DST_ALG_NSEC3RSASHA1:
460                 INSIST(type != 0);
461                 status = RSA_sign(type, digest, digestlen, r.base,
462                                   &siglen, rsa);
463                 break;
464
465         case DST_ALG_RSASHA256:
466         case DST_ALG_RSASHA512:
467                 INSIST(prefix != NULL);
468                 INSIST(prefixlen != 0);
469                 INSIST(prefixlen + digestlen <= sizeof(digest));
470
471                 memmove(digest + prefixlen, digest, digestlen);
472                 memcpy(digest, prefix, prefixlen);
473                 status = RSA_private_encrypt(digestlen + prefixlen,
474                                              digest, r.base, rsa,
475                                              RSA_PKCS1_PADDING);
476                 if (status < 0)
477                         status = 0;
478                 else
479                         siglen = status;
480                 break;
481
482         default:
483                 INSIST(0);
484         }
485 #else
486         INSIST(type != 0);
487         status = RSA_sign(type, digest, digestlen, r.base, &siglen, rsa);
488 #endif
489         if (status == 0) {
490                 err = ERR_peek_error_line(&file, &line);
491                 if (err != 0U) {
492                         message = ERR_error_string(err, NULL);
493                 }
494                 return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
495         }
496 #endif
497
498         isc_buffer_add(sig, siglen);
499
500         return (ISC_R_SUCCESS);
501 }
502
503 static isc_result_t
504 opensslrsa_verify(dst_context_t *dctx, const isc_region_t *sig) {
505         dst_key_t *key = dctx->key;
506         int status = 0;
507 #if USE_EVP
508         EVP_MD_CTX *evp_md_ctx = dctx->ctxdata.evp_md_ctx;
509         EVP_PKEY *pkey = key->keydata.pkey;
510 #else
511         /* note: ISC_SHA512_DIGESTLENGTH >= ISC_*_DIGESTLENGTH */
512         unsigned char digest[ISC_SHA512_DIGESTLENGTH];
513         int type = 0;
514         unsigned int digestlen = 0;
515         RSA *rsa = key->keydata.rsa;
516 #if OPENSSL_VERSION_NUMBER < 0x00908000L
517         unsigned int prefixlen = 0;
518         const unsigned char *prefix = NULL;
519 #endif
520 #endif
521
522         REQUIRE(dctx->key->key_alg == DST_ALG_RSAMD5 ||
523                 dctx->key->key_alg == DST_ALG_RSASHA1 ||
524                 dctx->key->key_alg == DST_ALG_NSEC3RSASHA1 ||
525                 dctx->key->key_alg == DST_ALG_RSASHA256 ||
526                 dctx->key->key_alg == DST_ALG_RSASHA512);
527
528 #if USE_EVP
529         status = EVP_VerifyFinal(evp_md_ctx, sig->base, sig->length, pkey);
530 #else
531         switch (dctx->key->key_alg) {
532         case DST_ALG_RSAMD5:
533                 {
534                         isc_md5_t *md5ctx = dctx->ctxdata.md5ctx;
535
536                         isc_md5_final(md5ctx, digest);
537                         type = NID_md5;
538                         digestlen = ISC_MD5_DIGESTLENGTH;
539                 }
540                 break;
541         case DST_ALG_RSASHA1:
542         case DST_ALG_NSEC3RSASHA1:
543                 {
544                         isc_sha1_t *sha1ctx = dctx->ctxdata.sha1ctx;
545
546                         isc_sha1_final(sha1ctx, digest);
547                         type = NID_sha1;
548                         digestlen = ISC_SHA1_DIGESTLENGTH;
549                 }
550                 break;
551         case DST_ALG_RSASHA256:
552                 {
553                         isc_sha256_t *sha256ctx = dctx->ctxdata.sha256ctx;
554
555                         isc_sha256_final(digest, sha256ctx);
556                         digestlen = ISC_SHA256_DIGESTLENGTH;
557 #if OPENSSL_VERSION_NUMBER < 0x00908000L
558                         prefix = sha256_prefix;
559                         prefixlen = sizeof(sha256_prefix);
560 #else
561                         type = NID_sha256;
562 #endif
563                 }
564                 break;
565         case DST_ALG_RSASHA512:
566                 {
567                         isc_sha512_t *sha512ctx = dctx->ctxdata.sha512ctx;
568
569                         isc_sha512_final(digest, sha512ctx);
570                         digestlen = ISC_SHA512_DIGESTLENGTH;
571 #if OPENSSL_VERSION_NUMBER < 0x00908000L
572                         prefix = sha512_prefix;
573                         prefixlen = sizeof(sha512_prefix);
574 #else
575                         type = NID_sha512;
576 #endif
577                 }
578                 break;
579         default:
580                 INSIST(0);
581         }
582
583         if (sig->length != (unsigned int) RSA_size(rsa))
584                 return (DST_R_VERIFYFAILURE);
585
586 #if OPENSSL_VERSION_NUMBER < 0x00908000L
587         switch (dctx->key->key_alg) {
588         case DST_ALG_RSAMD5:
589         case DST_ALG_RSASHA1:
590         case DST_ALG_NSEC3RSASHA1:
591                 INSIST(type != 0);
592                 status = RSA_verify(type, digest, digestlen, sig->base,
593                                     RSA_size(rsa), rsa);
594                 break;
595
596         case DST_ALG_RSASHA256:
597         case DST_ALG_RSASHA512:
598                 {
599                         /*
600                          * 1024 is big enough for all valid RSA bit sizes
601                          * for use with DNSSEC.
602                          */
603                         unsigned char original[PREFIXLEN + 1024];
604
605                         INSIST(prefix != NULL);
606                         INSIST(prefixlen != 0U);
607
608                         if (RSA_size(rsa) > (int)sizeof(original))
609                                 return (DST_R_VERIFYFAILURE);
610
611                         status = RSA_public_decrypt(sig->length, sig->base,
612                                                     original, rsa,
613                                                     RSA_PKCS1_PADDING);
614                         if (status <= 0)
615                                 return (DST_R_VERIFYFAILURE);
616                         if (status != (int)(prefixlen + digestlen))
617                                 return (DST_R_VERIFYFAILURE);
618                         if (memcmp(original, prefix, prefixlen))
619                                 return (DST_R_VERIFYFAILURE);
620                         if (memcmp(original + prefixlen, digest, digestlen))
621                                 return (DST_R_VERIFYFAILURE);
622                         status = 1;
623                 }
624                 break;
625
626         default:
627                 INSIST(0);
628         }
629 #else
630         INSIST(type != 0);
631         status = RSA_verify(type, digest, digestlen, sig->base,
632                              RSA_size(rsa), rsa);
633 #endif
634 #endif
635         if (status != 1)
636                 return (dst__openssl_toresult(DST_R_VERIFYFAILURE));
637
638         return (ISC_R_SUCCESS);
639 }
640
641 static isc_boolean_t
642 opensslrsa_compare(const dst_key_t *key1, const dst_key_t *key2) {
643         int status;
644         RSA *rsa1 = NULL, *rsa2 = NULL;
645 #if USE_EVP
646         EVP_PKEY *pkey1, *pkey2;
647 #endif
648
649 #if USE_EVP
650         pkey1 = key1->keydata.pkey;
651         pkey2 = key2->keydata.pkey;
652         /*
653          * The pkey reference will keep these around after
654          * the RSA_free() call.
655          */
656         if (pkey1 != NULL) {
657                 rsa1 = EVP_PKEY_get1_RSA(pkey1);
658                 RSA_free(rsa1);
659         }
660         if (pkey2 != NULL) {
661                 rsa2 = EVP_PKEY_get1_RSA(pkey2);
662                 RSA_free(rsa2);
663         }
664 #else
665         rsa1 = key1->keydata.rsa;
666         rsa2 = key2->keydata.rsa;
667 #endif
668
669         if (rsa1 == NULL && rsa2 == NULL)
670                 return (ISC_TRUE);
671         else if (rsa1 == NULL || rsa2 == NULL)
672                 return (ISC_FALSE);
673
674         status = BN_cmp(rsa1->n, rsa2->n) ||
675                  BN_cmp(rsa1->e, rsa2->e);
676
677         if (status != 0)
678                 return (ISC_FALSE);
679
680 #if USE_EVP
681         if ((rsa1->flags & RSA_FLAG_EXT_PKEY) != 0 ||
682             (rsa2->flags & RSA_FLAG_EXT_PKEY) != 0) {
683                 if ((rsa1->flags & RSA_FLAG_EXT_PKEY) == 0 ||
684                     (rsa2->flags & RSA_FLAG_EXT_PKEY) == 0)
685                         return (ISC_FALSE);
686                 /*
687                  * Can't compare private parameters, BTW does it make sense?
688                  */
689                 return (ISC_TRUE);
690         }
691 #endif
692
693         if (rsa1->d != NULL || rsa2->d != NULL) {
694                 if (rsa1->d == NULL || rsa2->d == NULL)
695                         return (ISC_FALSE);
696                 status = BN_cmp(rsa1->d, rsa2->d) ||
697                          BN_cmp(rsa1->p, rsa2->p) ||
698                          BN_cmp(rsa1->q, rsa2->q);
699
700                 if (status != 0)
701                         return (ISC_FALSE);
702         }
703         return (ISC_TRUE);
704 }
705
706 static isc_result_t
707 opensslrsa_generate(dst_key_t *key, int exp) {
708 #if OPENSSL_VERSION_NUMBER > 0x00908000L
709         BN_GENCB cb;
710         RSA *rsa = RSA_new();
711         BIGNUM *e = BN_new();
712 #if USE_EVP
713         EVP_PKEY *pkey = EVP_PKEY_new();
714 #endif
715
716         if (rsa == NULL || e == NULL)
717                 goto err;
718 #if USE_EVP
719         if (pkey == NULL)
720                 goto err;
721         if (!EVP_PKEY_set1_RSA(pkey, rsa))
722                 goto err;
723 #endif
724
725         if (exp == 0) {
726                 /* RSA_F4 0x10001 */
727                 BN_set_bit(e, 0);
728                 BN_set_bit(e, 16);
729         } else {
730                 /* F5 0x100000001 */
731                 BN_set_bit(e, 0);
732                 BN_set_bit(e, 32);
733         }
734
735         BN_GENCB_set_old(&cb, NULL, NULL);
736
737         if (RSA_generate_key_ex(rsa, key->key_size, e, &cb)) {
738                 BN_free(e);
739                 SET_FLAGS(rsa);
740 #if USE_EVP
741                 key->keydata.pkey = pkey;
742
743                 RSA_free(rsa);
744 #else
745                 key->keydata.rsa = rsa;
746 #endif
747                 return (ISC_R_SUCCESS);
748         }
749
750 err:
751 #if USE_EVP
752         if (pkey != NULL)
753                 EVP_PKEY_free(pkey);
754 #endif
755         if (e != NULL)
756                 BN_free(e);
757         if (rsa != NULL)
758                 RSA_free(rsa);
759         return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
760 #else
761         RSA *rsa;
762         unsigned long e;
763 #if USE_EVP
764         EVP_PKEY *pkey = EVP_PKEY_new();
765
766         if (pkey == NULL)
767                 return (ISC_R_NOMEMORY);
768 #endif
769
770         if (exp == 0)
771                e = RSA_F4;
772         else
773                e = 0x40000003;
774         rsa = RSA_generate_key(key->key_size, e, NULL, NULL);
775         if (rsa == NULL) {
776 #if USE_EVP
777                 EVP_PKEY_free(pkey);
778 #endif
779                 return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
780         }
781         SET_FLAGS(rsa);
782 #if USE_EVP
783         if (!EVP_PKEY_set1_RSA(pkey, rsa)) {
784                 EVP_PKEY_free(pkey);
785                 RSA_free(rsa);
786                 return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
787         }
788         key->keydata.pkey = pkey;
789         RSA_free(rsa);
790 #else
791         key->keydata.rsa = rsa;
792 #endif
793
794         return (ISC_R_SUCCESS);
795 #endif
796 }
797
798 static isc_boolean_t
799 opensslrsa_isprivate(const dst_key_t *key) {
800 #if USE_EVP
801         RSA *rsa = EVP_PKEY_get1_RSA(key->keydata.pkey);
802         INSIST(rsa != NULL);
803         RSA_free(rsa);
804         /* key->keydata.pkey still has a reference so rsa is still valid. */
805 #else
806         RSA *rsa = key->keydata.rsa;
807 #endif
808         if (rsa != NULL && (rsa->flags & RSA_FLAG_EXT_PKEY) != 0)
809                 return (ISC_TRUE);
810         return (ISC_TF(rsa != NULL && rsa->d != NULL));
811 }
812
813 static void
814 opensslrsa_destroy(dst_key_t *key) {
815 #if USE_EVP
816         EVP_PKEY *pkey = key->keydata.pkey;
817         EVP_PKEY_free(pkey);
818         key->keydata.pkey = NULL;
819 #else
820         RSA *rsa = key->keydata.rsa;
821         RSA_free(rsa);
822         key->keydata.rsa = NULL;
823 #endif
824 }
825
826
827 static isc_result_t
828 opensslrsa_todns(const dst_key_t *key, isc_buffer_t *data) {
829         isc_region_t r;
830         unsigned int e_bytes;
831         unsigned int mod_bytes;
832         isc_result_t ret;
833         RSA *rsa;
834 #if USE_EVP
835         EVP_PKEY *pkey;
836 #endif
837
838 #if USE_EVP
839         REQUIRE(key->keydata.pkey != NULL);
840 #else
841         REQUIRE(key->keydata.rsa != NULL);
842 #endif
843
844 #if USE_EVP
845         pkey = key->keydata.pkey;
846         rsa = EVP_PKEY_get1_RSA(pkey);
847         if (rsa == NULL)
848                 return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
849 #else
850         rsa = key->keydata.rsa;
851 #endif
852
853         isc_buffer_availableregion(data, &r);
854
855         e_bytes = BN_num_bytes(rsa->e);
856         mod_bytes = BN_num_bytes(rsa->n);
857
858         if (e_bytes < 256) {    /*%< key exponent is <= 2040 bits */
859                 if (r.length < 1)
860                         DST_RET(ISC_R_NOSPACE);
861                 isc_buffer_putuint8(data, (isc_uint8_t) e_bytes);
862                 isc_region_consume(&r, 1);
863         } else {
864                 if (r.length < 3)
865                         DST_RET(ISC_R_NOSPACE);
866                 isc_buffer_putuint8(data, 0);
867                 isc_buffer_putuint16(data, (isc_uint16_t) e_bytes);
868                 isc_region_consume(&r, 3);
869         }
870
871         if (r.length < e_bytes + mod_bytes)
872                 DST_RET(ISC_R_NOSPACE);
873
874         BN_bn2bin(rsa->e, r.base);
875         isc_region_consume(&r, e_bytes);
876         BN_bn2bin(rsa->n, r.base);
877
878         isc_buffer_add(data, e_bytes + mod_bytes);
879
880         ret = ISC_R_SUCCESS;
881  err:
882 #if USE_EVP
883         if (rsa != NULL)
884                 RSA_free(rsa);
885 #endif
886         return (ret);
887 }
888
889 static isc_result_t
890 opensslrsa_fromdns(dst_key_t *key, isc_buffer_t *data) {
891         RSA *rsa;
892         isc_region_t r;
893         unsigned int e_bytes;
894 #if USE_EVP
895         EVP_PKEY *pkey;
896 #endif
897
898         isc_buffer_remainingregion(data, &r);
899         if (r.length == 0)
900                 return (ISC_R_SUCCESS);
901
902         rsa = RSA_new();
903         if (rsa == NULL)
904                 return (dst__openssl_toresult(ISC_R_NOMEMORY));
905         SET_FLAGS(rsa);
906
907         if (r.length < 1) {
908                 RSA_free(rsa);
909                 return (DST_R_INVALIDPUBLICKEY);
910         }
911         e_bytes = *r.base++;
912         r.length--;
913
914         if (e_bytes == 0) {
915                 if (r.length < 2) {
916                         RSA_free(rsa);
917                         return (DST_R_INVALIDPUBLICKEY);
918                 }
919                 e_bytes = ((*r.base++) << 8);
920                 e_bytes += *r.base++;
921                 r.length -= 2;
922         }
923
924         if (r.length < e_bytes) {
925                 RSA_free(rsa);
926                 return (DST_R_INVALIDPUBLICKEY);
927         }
928         rsa->e = BN_bin2bn(r.base, e_bytes, NULL);
929         r.base += e_bytes;
930         r.length -= e_bytes;
931
932         rsa->n = BN_bin2bn(r.base, r.length, NULL);
933
934         key->key_size = BN_num_bits(rsa->n);
935
936         isc_buffer_forward(data, r.length);
937
938 #if USE_EVP
939         pkey = EVP_PKEY_new();
940         if (pkey == NULL) {
941                 RSA_free(rsa);
942                 return (ISC_R_NOMEMORY);
943         }
944         if (!EVP_PKEY_set1_RSA(pkey, rsa)) {
945                 EVP_PKEY_free(pkey);
946                 RSA_free(rsa);
947                 return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
948         }
949         key->keydata.pkey = pkey;
950         RSA_free(rsa);
951 #else
952         key->keydata.rsa = rsa;
953 #endif
954
955         return (ISC_R_SUCCESS);
956 }
957
958 static isc_result_t
959 opensslrsa_tofile(const dst_key_t *key, const char *directory) {
960         int i;
961         RSA *rsa;
962         dst_private_t priv;
963         unsigned char *bufs[8];
964         isc_result_t result;
965
966 #if USE_EVP
967         if (key->keydata.pkey == NULL)
968                 return (DST_R_NULLKEY);
969         rsa = EVP_PKEY_get1_RSA(key->keydata.pkey);
970         if (rsa == NULL)
971                 return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
972 #else
973         if (key->keydata.rsa == NULL)
974                 return (DST_R_NULLKEY);
975         rsa = key->keydata.rsa;
976 #endif
977
978         for (i = 0; i < 8; i++) {
979                 bufs[i] = isc_mem_get(key->mctx, BN_num_bytes(rsa->n));
980                 if (bufs[i] == NULL) {
981                         result = ISC_R_NOMEMORY;
982                         goto fail;
983                 }
984         }
985
986         i = 0;
987
988         priv.elements[i].tag = TAG_RSA_MODULUS;
989         priv.elements[i].length = BN_num_bytes(rsa->n);
990         BN_bn2bin(rsa->n, bufs[i]);
991         priv.elements[i].data = bufs[i];
992         i++;
993
994         priv.elements[i].tag = TAG_RSA_PUBLICEXPONENT;
995         priv.elements[i].length = BN_num_bytes(rsa->e);
996         BN_bn2bin(rsa->e, bufs[i]);
997         priv.elements[i].data = bufs[i];
998         i++;
999
1000         if (rsa->d != NULL) {
1001                 priv.elements[i].tag = TAG_RSA_PRIVATEEXPONENT;
1002                 priv.elements[i].length = BN_num_bytes(rsa->d);
1003                 BN_bn2bin(rsa->d, bufs[i]);
1004                 priv.elements[i].data = bufs[i];
1005                 i++;
1006         }
1007
1008         if (rsa->p != NULL) {
1009                 priv.elements[i].tag = TAG_RSA_PRIME1;
1010                 priv.elements[i].length = BN_num_bytes(rsa->p);
1011                 BN_bn2bin(rsa->p, bufs[i]);
1012                 priv.elements[i].data = bufs[i];
1013                 i++;
1014         }
1015
1016         if (rsa->q != NULL) {
1017                 priv.elements[i].tag = TAG_RSA_PRIME2;
1018                 priv.elements[i].length = BN_num_bytes(rsa->q);
1019                 BN_bn2bin(rsa->q, bufs[i]);
1020                 priv.elements[i].data = bufs[i];
1021                 i++;
1022         }
1023
1024         if (rsa->dmp1 != NULL) {
1025                 priv.elements[i].tag = TAG_RSA_EXPONENT1;
1026                 priv.elements[i].length = BN_num_bytes(rsa->dmp1);
1027                 BN_bn2bin(rsa->dmp1, bufs[i]);
1028                 priv.elements[i].data = bufs[i];
1029                 i++;
1030         }
1031
1032         if (rsa->dmq1 != NULL) {
1033                 priv.elements[i].tag = TAG_RSA_EXPONENT2;
1034                 priv.elements[i].length = BN_num_bytes(rsa->dmq1);
1035                 BN_bn2bin(rsa->dmq1, bufs[i]);
1036                 priv.elements[i].data = bufs[i];
1037                 i++;
1038         }
1039
1040         if (rsa->iqmp != NULL) {
1041                 priv.elements[i].tag = TAG_RSA_COEFFICIENT;
1042                 priv.elements[i].length = BN_num_bytes(rsa->iqmp);
1043                 BN_bn2bin(rsa->iqmp, bufs[i]);
1044                 priv.elements[i].data = bufs[i];
1045                 i++;
1046         }
1047
1048         if (key->engine != NULL) {
1049                 priv.elements[i].tag = TAG_RSA_ENGINE;
1050                 priv.elements[i].length = strlen(key->engine) + 1;
1051                 priv.elements[i].data = (unsigned char *)key->engine;
1052                 i++;
1053         }
1054
1055         if (key->label != NULL) {
1056                 priv.elements[i].tag = TAG_RSA_LABEL;
1057                 priv.elements[i].length = strlen(key->label) + 1;
1058                 priv.elements[i].data = (unsigned char *)key->label;
1059                 i++;
1060         }
1061
1062         priv.nelements = i;
1063         result =  dst__privstruct_writefile(key, &priv, directory);
1064  fail:
1065 #if USE_EVP
1066         RSA_free(rsa);
1067 #endif
1068         for (i = 0; i < 8; i++) {
1069                 if (bufs[i] == NULL)
1070                         break;
1071                 isc_mem_put(key->mctx, bufs[i], BN_num_bytes(rsa->n));
1072         }
1073         return (result);
1074 }
1075
1076 static isc_result_t
1077 opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer) {
1078         dst_private_t priv;
1079         isc_result_t ret;
1080         int i;
1081         RSA *rsa = NULL;
1082         ENGINE *e = NULL;
1083         isc_mem_t *mctx = key->mctx;
1084         const char *name = NULL, *label = NULL;
1085         EVP_PKEY *pkey = NULL;
1086
1087         /* read private key file */
1088         ret = dst__privstruct_parse(key, DST_ALG_RSA, lexer, mctx, &priv);
1089         if (ret != ISC_R_SUCCESS)
1090                 return (ret);
1091
1092         for (i = 0; i < priv.nelements; i++) {
1093                 switch (priv.elements[i].tag) {
1094                 case TAG_RSA_ENGINE:
1095                         name = (char *)priv.elements[i].data;
1096                         break;
1097                 case TAG_RSA_LABEL:
1098                         label = (char *)priv.elements[i].data;
1099                         break;
1100                 default:
1101                         break;
1102                 }
1103         }
1104         /*
1105          * Is this key is stored in a HSM?
1106          * See if we can fetch it.
1107          */
1108         if (name != NULL || label != NULL) {
1109                 INSIST(name != NULL);
1110                 INSIST(label != NULL);
1111                 e = dst__openssl_getengine(name);
1112                 if (e == NULL)
1113                         DST_RET(DST_R_NOENGINE);
1114                 pkey = ENGINE_load_private_key(e, label, NULL, NULL);
1115                 if (pkey == NULL) {
1116                         /* ERR_print_errors_fp(stderr); */
1117                         DST_RET(ISC_R_NOTFOUND);
1118                 }
1119                 key->engine = isc_mem_strdup(key->mctx, name);
1120                 if (key->engine == NULL)
1121                         DST_RET(ISC_R_NOMEMORY);
1122                 key->label = isc_mem_strdup(key->mctx, label);
1123                 if (key->label == NULL)
1124                         DST_RET(ISC_R_NOMEMORY);
1125                 key->key_size = EVP_PKEY_bits(pkey);
1126 #if USE_EVP
1127                 key->keydata.pkey = pkey;
1128 #else
1129                 key->keydata.rsa = EVP_PKEY_get1_RSA(pkey);
1130                 if (rsa == NULL)
1131                         DST_RET(dst__openssl_toresult(DST_R_OPENSSLFAILURE));
1132                 EVP_PKEY_free(pkey);
1133 #endif
1134                 dst__privstruct_free(&priv, mctx);
1135                 return (ISC_R_SUCCESS);
1136         }
1137
1138         rsa = RSA_new();
1139         if (rsa == NULL)
1140                 DST_RET(ISC_R_NOMEMORY);
1141         SET_FLAGS(rsa);
1142
1143 #if USE_EVP
1144         pkey = EVP_PKEY_new();
1145         if (pkey == NULL)
1146                 DST_RET(ISC_R_NOMEMORY);
1147         if (!EVP_PKEY_set1_RSA(pkey, rsa)) {
1148                 DST_RET(ISC_R_FAILURE);
1149         }
1150         key->keydata.pkey = pkey;
1151 #else
1152         key->keydata.rsa = rsa;
1153 #endif
1154
1155         for (i = 0; i < priv.nelements; i++) {
1156                 BIGNUM *bn;
1157                 switch (priv.elements[i].tag) {
1158                 case TAG_RSA_ENGINE:
1159                         continue;
1160                 case TAG_RSA_LABEL:
1161                         continue;
1162                 case TAG_RSA_PIN:
1163                         continue;
1164                 default:
1165                         bn = BN_bin2bn(priv.elements[i].data,
1166                                        priv.elements[i].length, NULL);
1167                         if (bn == NULL)
1168                                 DST_RET(ISC_R_NOMEMORY);
1169                 }
1170
1171                 switch (priv.elements[i].tag) {
1172                         case TAG_RSA_MODULUS:
1173                                 rsa->n = bn;
1174                                 break;
1175                         case TAG_RSA_PUBLICEXPONENT:
1176                                 rsa->e = bn;
1177                                 break;
1178                         case TAG_RSA_PRIVATEEXPONENT:
1179                                 rsa->d = bn;
1180                                 break;
1181                         case TAG_RSA_PRIME1:
1182                                 rsa->p = bn;
1183                                 break;
1184                         case TAG_RSA_PRIME2:
1185                                 rsa->q = bn;
1186                                 break;
1187                         case TAG_RSA_EXPONENT1:
1188                                 rsa->dmp1 = bn;
1189                                 break;
1190                         case TAG_RSA_EXPONENT2:
1191                                 rsa->dmq1 = bn;
1192                                 break;
1193                         case TAG_RSA_COEFFICIENT:
1194                                 rsa->iqmp = bn;
1195                                 break;
1196                 }
1197         }
1198         dst__privstruct_free(&priv, mctx);
1199
1200         key->key_size = BN_num_bits(rsa->n);
1201 #if USE_EVP
1202         RSA_free(rsa);
1203 #endif
1204
1205         return (ISC_R_SUCCESS);
1206
1207  err:
1208 #if USE_EVP
1209         if (pkey != NULL)
1210                 EVP_PKEY_free(pkey);
1211 #endif
1212         if (rsa != NULL)
1213                 RSA_free(rsa);
1214         opensslrsa_destroy(key);
1215         dst__privstruct_free(&priv, mctx);
1216         memset(&priv, 0, sizeof(priv));
1217         return (ret);
1218 }
1219
1220 static isc_result_t
1221 opensslrsa_fromlabel(dst_key_t *key, const char *engine, const char *label,
1222                      const char *pin)
1223 {
1224         ENGINE *e = NULL;
1225         isc_result_t ret;
1226         EVP_PKEY *pkey = NULL;
1227
1228         UNUSED(pin);
1229
1230         e = dst__openssl_getengine(engine);
1231         if (e == NULL)
1232                 DST_RET(DST_R_NOENGINE);
1233         pkey = ENGINE_load_private_key(e, label, NULL, NULL);
1234         if (pkey == NULL)
1235                 DST_RET(ISC_R_NOTFOUND);
1236         key->engine = isc_mem_strdup(key->mctx, label);
1237         if (key->engine == NULL)
1238                 DST_RET(ISC_R_NOMEMORY);
1239         key->label = isc_mem_strdup(key->mctx, label);
1240         if (key->label == NULL)
1241                 DST_RET(ISC_R_NOMEMORY);
1242         key->key_size = EVP_PKEY_bits(pkey);
1243 #if USE_EVP
1244         key->keydata.pkey = pkey;
1245 #else
1246         key->keydata.rsa = EVP_PKEY_get1_RSA(pkey);
1247         EVP_PKEY_free(pkey);
1248         if (key->keydata.rsa == NULL)
1249                 return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
1250 #endif
1251         return (ISC_R_SUCCESS);
1252
1253  err:
1254         if (pkey != NULL)
1255                 EVP_PKEY_free(pkey);
1256         return (ret);
1257 }
1258
1259 static dst_func_t opensslrsa_functions = {
1260         opensslrsa_createctx,
1261         opensslrsa_destroyctx,
1262         opensslrsa_adddata,
1263         opensslrsa_sign,
1264         opensslrsa_verify,
1265         NULL, /*%< computesecret */
1266         opensslrsa_compare,
1267         NULL, /*%< paramcompare */
1268         opensslrsa_generate,
1269         opensslrsa_isprivate,
1270         opensslrsa_destroy,
1271         opensslrsa_todns,
1272         opensslrsa_fromdns,
1273         opensslrsa_tofile,
1274         opensslrsa_parse,
1275         NULL, /*%< cleanup */
1276         opensslrsa_fromlabel,
1277 };
1278
1279 isc_result_t
1280 dst__opensslrsa_init(dst_func_t **funcp, unsigned char algorithm) {
1281         REQUIRE(funcp != NULL);
1282
1283         if (*funcp == NULL) {
1284                 switch (algorithm) {
1285                 case DST_ALG_RSASHA256:
1286 #if defined(HAVE_EVP_SHA256) || !USE_EVP
1287                         *funcp = &opensslrsa_functions;
1288 #endif
1289                         break;
1290                 case DST_ALG_RSASHA512:
1291 #if defined(HAVE_EVP_SHA512) || !USE_EVP
1292                         *funcp = &opensslrsa_functions;
1293 #endif
1294                         break;
1295                 default:
1296                         *funcp = &opensslrsa_functions;
1297                         break;
1298                 }
1299         }
1300         return (ISC_R_SUCCESS);
1301 }
1302
1303 #else /* OPENSSL */
1304
1305 #include <isc/util.h>
1306
1307 EMPTY_TRANSLATION_UNIT
1308
1309 #endif /* OPENSSL */
1310 /*! \file */