1295367Sdes/* $Id: openssl-compat.c,v 1.19 2014/07/02 05:28:07 djm Exp $ */ 2149749Sdes 3149749Sdes/* 4149749Sdes * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> 5149749Sdes * 6149749Sdes * Permission to use, copy, modify, and distribute this software for any 7149749Sdes * purpose with or without fee is hereby granted, provided that the above 8149749Sdes * copyright notice and this permission notice appear in all copies. 9149749Sdes * 10149749Sdes * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11149749Sdes * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12149749Sdes * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13149749Sdes * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14149749Sdes * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15149749Sdes * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16149749Sdes * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17149749Sdes */ 18149749Sdes 19295367Sdes#define SSH_DONT_OVERLOAD_OPENSSL_FUNCS 20149749Sdes#include "includes.h" 21149749Sdes 22295367Sdes#ifdef WITH_OPENSSL 23295367Sdes 24221420Sdes#include <stdarg.h> 25221420Sdes#include <string.h> 26221420Sdes 27162852Sdes#ifdef USE_OPENSSL_ENGINE 28162852Sdes# include <openssl/engine.h> 29221420Sdes# include <openssl/conf.h> 30162852Sdes#endif 31162852Sdes 32221420Sdes#include "log.h" 33221420Sdes 34149749Sdes#include "openssl-compat.h" 35149749Sdes 36295367Sdes/* 37295367Sdes * OpenSSL version numbers: MNNFFPPS: major minor fix patch status 38295367Sdes * We match major, minor, fix and status (not patch) for <1.0.0. 39295367Sdes * After that, we acceptable compatible fix versions (so we 40295367Sdes * allow 1.0.1 to work with 1.0.0). Going backwards is only allowed 41295367Sdes * within a patch series. 42295367Sdes */ 43149749Sdes 44149749Sdesint 45295367Sdesssh_compatible_openssl(long headerver, long libver) 46149749Sdes{ 47295367Sdes long mask, hfix, lfix; 48149749Sdes 49295367Sdes /* exact match is always OK */ 50295367Sdes if (headerver == libver) 51295367Sdes return 1; 52162852Sdes 53295367Sdes /* for versions < 1.0.0, major,minor,fix,status must match */ 54295367Sdes if (headerver < 0x1000000f) { 55295367Sdes mask = 0xfffff00fL; /* major,minor,fix,status */ 56295367Sdes return (headerver & mask) == (libver & mask); 57295367Sdes } 58295367Sdes 59295367Sdes /* 60295367Sdes * For versions >= 1.0.0, major,minor,status must match and library 61295367Sdes * fix version must be equal to or newer than the header. 62295367Sdes */ 63295367Sdes mask = 0xfff0000fL; /* major,minor,status */ 64295367Sdes hfix = (headerver & 0x000ff000) >> 12; 65295367Sdes lfix = (libver & 0x000ff000) >> 12; 66295367Sdes if ( (headerver & mask) == (libver & mask) && lfix >= hfix) 67295367Sdes return 1; 68295367Sdes return 0; 69262566Sdes} 70262566Sdes 71162852Sdes#ifdef USE_OPENSSL_ENGINE 72162852Sdesvoid 73226046Sdesssh_OpenSSL_add_all_algorithms(void) 74162852Sdes{ 75226046Sdes OpenSSL_add_all_algorithms(); 76162852Sdes 77162852Sdes /* Enable use of crypto hardware */ 78162852Sdes ENGINE_load_builtin_engines(); 79162852Sdes ENGINE_register_all_complete(); 80204917Sdes OPENSSL_config(NULL); 81162852Sdes} 82162852Sdes#endif 83295367Sdes 84295367Sdes#endif /* WITH_OPENSSL */ 85