summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2023-07-04 17:14:27 +0200
committerGravatar Nikias Bassen2023-07-04 17:14:27 +0200
commit474fd9284b76d8ddd3a3aec41cbca3cc48271cc1 (patch)
tree58fcb909dff8cee2d2121d17bf0643fad6a8e766
parent52ab7b76f76ee0464fd150ec881ce50fbf2dc001 (diff)
downloadlibimobiledevice-474fd9284b76d8ddd3a3aec41cbca3cc48271cc1.tar.gz
libimobiledevice-474fd9284b76d8ddd3a3aec41cbca3cc48271cc1.tar.bz2
3rd_party/libsrp6a-sha512: Updated to work with OpenSSL 3.0+ API
-rw-r--r--3rd_party/libsrp6a-sha512/Makefile.am9
-rw-r--r--3rd_party/libsrp6a-sha512/t_math.c8
-rw-r--r--3rd_party/libsrp6a-sha512/t_sha.c40
-rw-r--r--3rd_party/libsrp6a-sha512/t_sha.h24
4 files changed, 74 insertions, 7 deletions
diff --git a/3rd_party/libsrp6a-sha512/Makefile.am b/3rd_party/libsrp6a-sha512/Makefile.am
index c349d8c..2acd582 100644
--- a/3rd_party/libsrp6a-sha512/Makefile.am
+++ b/3rd_party/libsrp6a-sha512/Makefile.am
@@ -24,7 +24,8 @@ libsrp6a_sha512_la_SOURCES = \
t_conv.c t_math.c t_misc.c \
t_truerand.c cstr.c \
srp.c srp6a_sha512_client.c \
- srp.h srp_aux.h cstr.h
-if !HAVE_OPENSSL
-libsrp6a_sha512_la_SOURCES += t_sha.c
-endif
+ srp.h srp_aux.h cstr.h \
+ t_sha.c
+#if !HAVE_OPENSSL
+#libsrp6a_sha512_la_SOURCES += t_sha.c
+#endif
diff --git a/3rd_party/libsrp6a-sha512/t_math.c b/3rd_party/libsrp6a-sha512/t_math.c
index 166ee4c..037650e 100644
--- a/3rd_party/libsrp6a-sha512/t_math.c
+++ b/3rd_party/libsrp6a-sha512/t_math.c
@@ -39,11 +39,13 @@ typedef BIGNUM * BigInteger;
typedef BN_CTX * BigIntegerCtx;
typedef BN_MONT_CTX * BigIntegerModAccel;
#include <limits.h>
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
# ifndef OPENSSL_NO_ENGINE
# define OPENSSL_ENGINE
# include "openssl/engine.h"
static ENGINE * default_engine = NULL;
# endif /* OPENSSL_ENGINE */
+#endif
typedef int (*modexp_meth)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *mctx);
static modexp_meth default_modexp = NULL;
@@ -758,7 +760,11 @@ BigIntegerCheckPrime(BigInteger n, BigIntegerCtx c)
if(c == NULL)
c = ctx = BN_CTX_new();
#if OPENSSL_VERSION_NUMBER >= 0x00908000
- rv = BN_is_prime_ex(n, 25, c, NULL);
+ #if OPENSSL_VERSION_NUMBER >= 0x30000000L
+ rv = BN_check_prime(n, c, NULL);
+ #else
+ rv = BN_is_prime_ex(n, 25, c, NULL);
+ #endif
#else
rv = BN_is_prime(n, 25, NULL, c, NULL);
#endif
diff --git a/3rd_party/libsrp6a-sha512/t_sha.c b/3rd_party/libsrp6a-sha512/t_sha.c
index 4029de8..8e54cb6 100644
--- a/3rd_party/libsrp6a-sha512/t_sha.c
+++ b/3rd_party/libsrp6a-sha512/t_sha.c
@@ -107,6 +107,44 @@ SHA512Final_mbed(unsigned char digest[64], SHA512_CTX * ctx)
mbedtls_md_free(ctx);
}
+#elif defined(OPENSSL_SHA)
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+void
+SHA1Init_openssl(SHA1_CTX *ctx)
+{
+ *ctx = EVP_MD_CTX_new();
+ EVP_DigestInit(*ctx, EVP_sha1());
+}
+
+void SHA1Update_openssl(SHA1_CTX *ctx, const void *data, unsigned int len)
+{
+ EVP_DigestUpdate(*ctx, data, (size_t)len);
+}
+
+void SHA1Final_openssl(unsigned char digest[20], SHA1_CTX *ctx)
+{
+ EVP_DigestFinal(*ctx, digest, NULL);
+ EVP_MD_CTX_destroy(*ctx);
+}
+
+void
+SHA512Init_openssl(SHA512_CTX *ctx)
+{
+ *ctx = EVP_MD_CTX_new();
+ EVP_DigestInit(*ctx, EVP_sha512());
+}
+
+void SHA512Update_openssl(SHA512_CTX *ctx, const void *data, unsigned int len)
+{
+ EVP_DigestUpdate(*ctx, data, (size_t)len);
+}
+
+void SHA512Final_openssl(unsigned char digest[64], SHA512_CTX *ctx)
+{
+ EVP_DigestFinal(*ctx, digest, NULL);
+ EVP_MD_CTX_destroy(*ctx);
+}
+#endif
#elif !defined(OPENSSL_SHA) && !defined(TOMCRYPT_SHA)
/* Use the free SHA1 if the library doesn't have it */
@@ -273,4 +311,4 @@ unsigned char finalcount[8];
SHA1Transform(context->state, context->buffer);
#endif
}
-#endif /* OPENSSL */
+#endif
diff --git a/3rd_party/libsrp6a-sha512/t_sha.h b/3rd_party/libsrp6a-sha512/t_sha.h
index 18deec5..2e38067 100644
--- a/3rd_party/libsrp6a-sha512/t_sha.h
+++ b/3rd_party/libsrp6a-sha512/t_sha.h
@@ -38,6 +38,28 @@
#endif
#ifdef OPENSSL_SHA
+#include <openssl/err.h>
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#include <openssl/evp.h>
+
+typedef EVP_MD_CTX* SHA1_CTX;
+#define SHA1Init SHA1Init_openssl
+#define SHA1Update SHA1Update_openssl
+#define SHA1Final SHA1Final_openssl
+
+typedef EVP_MD_CTX* SHA512_CTX;
+#define SHA512Init SHA512Init_openssl
+#define SHA512Update SHA512Update_openssl
+#define SHA512Final SHA512Final_openssl
+
+void SHA1Init_openssl(SHA1_CTX *ctx);
+void SHA1Update_openssl(SHA1_CTX *ctx, const void *data, unsigned int len);
+void SHA1Final_openssl(unsigned char digest[20], SHA1_CTX *ctx);
+
+void SHA512Init_openssl(SHA512_CTX *ctx);
+void SHA512Update_openssl(SHA512_CTX *ctx, const void *data, unsigned int len);
+void SHA512Final_openssl(unsigned char digest[64], SHA1_CTX *ctx);
+#else /* for OpenSSL < 3.0 */
#include <openssl/sha.h>
typedef SHA_CTX SHA1_CTX;
@@ -48,7 +70,7 @@ typedef SHA_CTX SHA1_CTX;
#define SHA512Init SHA512_Init
#define SHA512Update SHA512_Update
#define SHA512Final SHA512_Final
-
+#endif /* for OpenSSL < 3.0 */
#elif defined(TOMCRYPT_SHA)
/* mycrypt.h already included above */