blob: 63a660c7a42a7bb65ec18bafb2bbad394d04ea9a [file] [log] [blame]
Damien Miller86687062014-07-02 15:28:02 +10001/* $Id: openssl-compat.c,v 1.19 2014/07/02 05:28:07 djm Exp $ */
Darren Tuckera55ec772005-06-09 21:45:10 +10002
3/*
4 * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
Damien Miller86687062014-07-02 15:28:02 +100019#define SSH_DONT_OVERLOAD_OPENSSL_FUNCS
Darren Tuckera55ec772005-06-09 21:45:10 +100020#include "includes.h"
21
Damien Miller72ef7c12015-01-15 02:21:31 +110022#ifdef WITH_OPENSSL
23
Darren Tuckerebdef762010-12-04 23:20:50 +110024#include <stdarg.h>
25#include <string.h>
26
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110027#ifdef USE_OPENSSL_ENGINE
28# include <openssl/engine.h>
Darren Tucker9e0ff7a2010-11-22 17:59:00 +110029# include <openssl/conf.h>
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110030#endif
31
Darren Tuckerebdef762010-12-04 23:20:50 +110032#include "log.h"
33
Darren Tuckerbfaaf962008-02-28 19:13:52 +110034#include "openssl-compat.h"
35
Darren Tucker316fac62014-06-17 23:06:07 +100036/*
37 * OpenSSL version numbers: MNNFFPPS: major minor fix patch status
38 * We match major, minor, fix and status (not patch) for <1.0.0.
39 * After that, we acceptable compatible fix versions (so we
40 * allow 1.0.1 to work with 1.0.0). Going backwards is only allowed
41 * within a patch series.
42 */
43
44int
45ssh_compatible_openssl(long headerver, long libver)
46{
47 long mask, hfix, lfix;
48
49 /* exact match is always OK */
50 if (headerver == libver)
51 return 1;
52
53 /* for versions < 1.0.0, major,minor,fix,status must match */
54 if (headerver < 0x1000000f) {
55 mask = 0xfffff00fL; /* major,minor,fix,status */
56 return (headerver & mask) == (libver & mask);
57 }
58
59 /*
60 * For versions >= 1.0.0, major,minor,status must match and library
61 * fix version must be equal to or newer than the header.
62 */
63 mask = 0xfff0000fL; /* major,minor,status */
64 hfix = (headerver & 0x000ff000) >> 12;
65 lfix = (libver & 0x000ff000) >> 12;
66 if ( (headerver & mask) == (libver & mask) && lfix >= hfix)
67 return 1;
68 return 0;
69}
70
Darren Tucker94413cf2006-02-22 22:24:47 +110071#ifdef USE_OPENSSL_ENGINE
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110072void
Darren Tuckerd6548fe2011-05-10 11:13:36 +100073ssh_OpenSSL_add_all_algorithms(void)
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110074{
Darren Tuckerd6548fe2011-05-10 11:13:36 +100075 OpenSSL_add_all_algorithms();
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110076
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110077 /* Enable use of crypto hardware */
78 ENGINE_load_builtin_engines();
79 ENGINE_register_all_complete();
Darren Tucker19d32cb2010-01-29 10:54:11 +110080 OPENSSL_config(NULL);
Darren Tuckerfabdb6c2006-02-20 20:17:35 +110081}
Darren Tucker94413cf2006-02-22 22:24:47 +110082#endif
Damien Miller72ef7c12015-01-15 02:21:31 +110083
84#endif /* WITH_OPENSSL */