RsaTool: Fix openssl compatibility

This commit is contained in:
vit9696 2019-04-06 12:16:59 +03:00
parent 147f88d1f2
commit 67ccc0330c
3 changed files with 11 additions and 76 deletions

Binary file not shown.

View File

@ -6,7 +6,6 @@
* support for additional RSA key sizes. (platform/system/core,git/libmincrypt
* /tools/DumpPublicKey.java). Uses the OpenSSL X509 and BIGNUM library.
*/
#include <openssl/pem.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
@ -15,7 +14,7 @@
* and output a pre-processed version of keys for use by RSA verification
* routines.
*/
int check(RSA* key) {
static int check(RSA* key) {
const BIGNUM *n, *e;
int public_exponent, modulus;
RSA_get0_key(key, &n, &e, NULL);
@ -33,7 +32,7 @@ int check(RSA* key) {
}
return 1;
}
void native_to_big(unsigned char *data, size_t size) {
static void native_to_big(unsigned char *data, size_t size) {
size_t i, tmp = 1;
if (*(unsigned char *)&tmp == 1) {
fprintf(stderr, "WARNING: Assuming little endian encoding.\n");
@ -46,7 +45,7 @@ void native_to_big(unsigned char *data, size_t size) {
fprintf(stderr, "WARNING: Assuming big endian encoding.\n");
}
}
void print_data(void *data, size_t size) {
static void print_data(void *data, size_t size) {
size_t i;
static size_t block = 0;
if (data == NULL) {
@ -64,7 +63,7 @@ void print_data(void *data, size_t size) {
}
/* Pre-processes and outputs RSA public key to standard out.
*/
void output(RSA* key) {
static void output(RSA* key) {
int i, nwords;
const BIGNUM *key_n;
BIGNUM *N = NULL;

View File

@ -14,81 +14,14 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef _OPENSSL_COMPAT_H
#define _OPENSSL_COMPAT_H
#ifndef OPENSSL_COMPAT_H
#define OPENSSL_COMPAT_H
#include <openssl/opensslv.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
#include <openssl/dsa.h>
int ssh_compatible_openssl(long, long);
#if OPENSSL_VERSION_NUMBER < 0x10000001L
# define LIBCRYPTO_EVP_INL_TYPE unsigned int
#else
# define LIBCRYPTO_EVP_INL_TYPE size_t
#endif
#ifndef OPENSSL_RSA_MAX_MODULUS_BITS
# define OPENSSL_RSA_MAX_MODULUS_BITS 16384
#endif
#ifndef OPENSSL_DSA_MAX_MODULUS_BITS
# define OPENSSL_DSA_MAX_MODULUS_BITS 10000
#endif
#ifndef OPENSSL_HAVE_EVPCTR
# define EVP_aes_128_ctr evp_aes_128_ctr
# define EVP_aes_192_ctr evp_aes_128_ctr
# define EVP_aes_256_ctr evp_aes_128_ctr
const EVP_CIPHER *evp_aes_128_ctr(void);
void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, size_t);
#endif
/* Avoid some #ifdef. Code that uses these is unreachable without GCM */
#if !defined(OPENSSL_HAVE_EVPGCM) && !defined(EVP_CTRL_GCM_SET_IV_FIXED)
# define EVP_CTRL_GCM_SET_IV_FIXED -1
# define EVP_CTRL_GCM_IV_GEN -1
# define EVP_CTRL_GCM_SET_TAG -1
# define EVP_CTRL_GCM_GET_TAG -1
#endif
/* Replace missing EVP_CIPHER_CTX_ctrl() with something that returns failure */
#ifndef HAVE_EVP_CIPHER_CTX_CTRL
# ifdef OPENSSL_HAVE_EVPGCM
# error AES-GCM enabled without EVP_CIPHER_CTX_ctrl /* shouldn't happen */
# else
# define EVP_CIPHER_CTX_ctrl(a,b,c,d) (0)
# endif
#endif
#if defined(HAVE_EVP_RIPEMD160)
# if defined(OPENSSL_NO_RIPEMD) || defined(OPENSSL_NO_RMD160)
# undef HAVE_EVP_RIPEMD160
# endif
#endif
/*
* We overload some of the OpenSSL crypto functions with ssh_* equivalents
* to automatically handle OpenSSL engine initialisation.
*
* In order for the compat library to call the real functions, it must
* define SSH_DONT_OVERLOAD_OPENSSL_FUNCS before including this file and
* implement the ssh_* equivalents.
*/
#ifndef SSH_DONT_OVERLOAD_OPENSSL_FUNCS
# ifdef USE_OPENSSL_ENGINE
# ifdef OpenSSL_add_all_algorithms
# undef OpenSSL_add_all_algorithms
# endif
# define OpenSSL_add_all_algorithms() ssh_OpenSSL_add_all_algorithms()
# endif
void ssh_OpenSSL_add_all_algorithms(void);
#endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */
#ifndef HAVE_RSA_GET0_KEY
/**
* Get the RSA parameters
*
@ -114,7 +47,9 @@ RSA_get0_key(const RSA *rsa, const BIGNUM **n,
*d = rsa ? rsa->d : NULL;
}
}
#endif
#ifndef HAVE_RSA_SET0_KEY
/**
* Set the RSA parameters
*
@ -151,6 +86,7 @@ RSA_set0_key(RSA *rsa, BIGNUM *n, BIGNUM *e, BIGNUM *d)
return 1;
}
#endif
#endif /* _OPENSSL_COMPAT_H */