[rtmpdump] branch master updated. 52746d7 Portability tweaks for prev commit

rtmpdump at mplayerhq.hu rtmpdump at mplayerhq.hu
Fri Mar 1 17:25:49 EET 2024


The branch, master has been updated
       via  52746d7c5246c4d07d98921e6415de7b4c34c927 (commit)
      from  ee5456b5374c12f66e47f56b4e83e9557c62ebfe (commit)


- Log -----------------------------------------------------------------
commit 52746d7c5246c4d07d98921e6415de7b4c34c927
Author:     Howard Chu <hyc at highlandsun.com>
AuthorDate: Fri Mar 1 15:23:58 2024 +0000
Commit:     Howard Chu <hyc at highlandsun.com>
CommitDate: Fri Mar 1 15:23:58 2024 +0000

    Portability tweaks for prev commit
    
    Note that using anything newer than OpenSSL 3.0 probably won't work,
    since support for RC4 is going away and the Diffie-Hellman APIs are
    also deprecated.

diff --git a/librtmp/dh.h b/librtmp/dh.h
index 59ab6a8..fa2c74f 100644
--- a/librtmp/dh.h
+++ b/librtmp/dh.h
@@ -42,6 +42,10 @@ typedef mpi * MP_t;
 #define MP_bytes(u)	mpi_size(u)
 #define MP_setbin(u,buf,len)	mpi_write_binary(u,buf,len)
 #define MP_getbin(u,buf,len)	MP_new(u); mpi_read_binary(u,buf,len)
+#define MP_setpg(dh, p, g)	dh->p = p; dh->g = g
+#define MP_setlength(dh, l)	dh->length = l
+#define MP_getp(dh)	dh->p
+#define MP_getpubkey(dh)	dh->pub_key
 
 typedef struct MDH {
   MP_t p;
@@ -93,6 +97,10 @@ typedef mpz_ptr MP_t;
 #define MP_bytes(u)	(mpz_sizeinbase(u, 2) + 7) / 8
 #define MP_setbin(u,buf,len)	nettle_mpz_get_str_256(len,buf,u)
 #define MP_getbin(u,buf,len)	u = malloc(sizeof(*u)); mpz_init2(u, 1); nettle_mpz_set_str_256_u(u,len,buf)
+#define MP_setpg(dh, p, g)	dh->p = p; dh->g = g
+#define MP_setlength(dh, l)	dh->length = l
+#define MP_getp(dh)	dh->p
+#define MP_getpubkey(dh)	dh->pub_key
 
 typedef struct MDH {
   MP_t p;
@@ -187,6 +195,17 @@ typedef BIGNUM * MP_t;
 #define MDH_generate_key(dh)	DH_generate_key(dh)
 #define MDH_compute_key(secret, seclen, pub, dh)	DH_compute_key(secret, pub, dh)
 
+#if OPENSSL_VERSION_NUMBER >= 0x10100000
+#define MP_setpg(dh, p, g)	DH_set0_pqg(dh, p, NULL, g)
+#define MP_setlength(dh, l)	DH_set_length(dh, l)
+#define MP_getp(dh)	DH_get0_p(dh)
+#define MP_getpubkey(dh)	DH_get0_pub_key(dh)
+#else
+#define MP_setpg(dh, p, g)	dh->p = p; dh->g = g
+#define MP_setlength(dh, l)	dh->length = l
+#define MP_getp(dh)	dh->p
+#define MP_getpubkey(dh)	dh->pub_key
+#endif
 #endif
 
 #include "log.h"
@@ -266,9 +285,9 @@ DHInit(int nKeyBits)
     }
 
   MP_set_w(g, 2);	/* base 2 */
-  DH_set0_pqg(dh, p, NULL, g);
+  MP_setpg(dh, p, g);
 
-  DH_set_length(dh, nKeyBits);
+  MP_setlength(dh, nKeyBits);
   return dh;
 
 failed:
@@ -293,12 +312,17 @@ DHGenerateKey(MDH *dh)
     {
       if (MDH_generate_key(dh))
         {
-	  MP_t key = (MP_t)DH_get0_pub_key(dh);
-	  MP_t p = (MP_t)DH_get0_p(dh);
+	  MP_t key = (MP_t)MP_getpubkey(dh);
+	  MP_t p = (MP_t)MP_getp(dh);
 	  res = isValidPublicKey(key, p, q1);
         }
       else
 	{
+#if !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000
+	  MP_free(dh->pub_key);
+	  MP_free(dh->priv_key);
+	  dh->pub_key = dh->priv_key = 0;
+#endif
 	  res = 0;
 	  break;
 	}
@@ -316,7 +340,7 @@ DHGetPublicKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen)
 {
   int len;
   MP_t pub_key;
-  if (!dh || !(pub_key = (MP_t)DH_get0_pub_key(dh)))
+  if (!dh || !(pub_key = (MP_t)MP_getpubkey(dh)))
     return 0;
 
   len = MP_bytes(pub_key);
@@ -366,7 +390,7 @@ DHComputeSharedSecretKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen,
   MP_gethex(q1, Q1024, len);
   assert(len);
 
-  if (isValidPublicKey(pubkeyBn, (MP_t)DH_get0_p(dh), q1))
+  if (isValidPublicKey(pubkeyBn, (MP_t)MP_getp(dh), q1))
     res = MDH_compute_key(secret, nPubkeyLen, pubkeyBn, dh);
   else
     res = -1;

-----------------------------------------------------------------------

Summary of changes:
 librtmp/dh.h | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)


hooks/post-receive
-- 



More information about the rtmpdump mailing list