Update multimedia/librtmp to version 2.4.20151223_4
[dports.git] / multimedia / librtmp / files / patch-librtmp-dh.h
1 --- librtmp/dh.h.orig   2016-02-29 01:15:13 UTC
2 +++ librtmp/dh.h
3 @@ -194,7 +194,7 @@ typedef BIGNUM * MP_t;
4  
5  /* RFC 2631, Section 2.1.5, http://www.ietf.org/rfc/rfc2631.txt */
6  static int
7 -isValidPublicKey(MP_t y, MP_t p, MP_t q)
8 +isValidPublicKey(const MP_t y, const MP_t p, const MP_t q)
9  {
10    int ret = TRUE;
11    MP_t bn;
12 @@ -253,20 +253,43 @@ DHInit(int nKeyBits)
13    if (!dh)
14      goto failed;
15  
16 +#if !defined(USE_OPENSSL) || defined(LIBRESSL_VERSION_NUMBER) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
17    MP_new(dh->g);
18  
19    if (!dh->g)
20      goto failed;
21 +#else
22 +  BIGNUM *g;
23  
24 +  MP_new(g);
25 +  if (g == NULL)
26 +    goto failed;
27 +#endif
28 +
29 +#if !defined(USE_OPENSSL) || defined(LIBRESSL_VERSION_NUMBER) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
30    MP_gethex(dh->p, P1024, res);        /* prime P1024, see dhgroups.h */
31 +#else
32 +  const BIGNUM *p = DH_get0_p(dh);
33 +
34 +  MP_gethex(p, P1024, res);    /* prime P1024, see dhgroups.h */
35 +#endif
36    if (!res)
37      {
38        goto failed;
39      }
40  
41 +#if !defined(USE_OPENSSL) || defined(LIBRESSL_VERSION_NUMBER) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
42    MP_set_w(dh->g, 2);  /* base 2 */
43 +#else
44 +  MP_set_w(g, 2);      /* base 2 */
45 +  DH_set0_pqg(dh, p, NULL, g);
46 +#endif
47  
48 +#if !defined(USE_OPENSSL) || defined(LIBRESSL_VERSION_NUMBER) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
49    dh->length = nKeyBits;
50 +#else
51 +  DH_set_length(dh, nKeyBits);
52 +#endif
53    return dh;
54  
55  failed:
56 @@ -293,12 +316,20 @@ DHGenerateKey(MDH *dh)
57        MP_gethex(q1, Q1024, res);
58        assert(res);
59  
60 +#if !defined(USE_OPENSSL) || defined(LIBRESSL_VERSION_NUMBER) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
61        res = isValidPublicKey(dh->pub_key, dh->p, q1);
62 +#else
63 +      res = isValidPublicKey(DH_get0_pub_key(dh), DH_get0_p(dh), q1);
64 +#endif
65        if (!res)
66         {
67 +#if !defined(USE_OPENSSL) || defined(LIBRESSL_VERSION_NUMBER) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
68           MP_free(dh->pub_key);
69           MP_free(dh->priv_key);
70           dh->pub_key = dh->priv_key = 0;
71 +#else
72 +          DH_set0_key(dh, NULL, NULL);
73 +#endif
74         }
75  
76        MP_free(q1);
77 @@ -314,15 +345,27 @@ static int
78  DHGetPublicKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen)
79  {
80    int len;
81 +#if !defined(USE_OPENSSL) || defined(LIBRESSL_VERSION_NUMBER) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
82    if (!dh || !dh->pub_key)
83 +#else
84 +  if (!dh || !DH_get0_pub_key(dh))
85 +#endif
86      return 0;
87  
88 +#if !defined(USE_OPENSSL) || defined(LIBRESSL_VERSION_NUMBER) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
89    len = MP_bytes(dh->pub_key);
90 +#else
91 +  len = MP_bytes(DH_get0_pub_key(dh));
92 +#endif
93    if (len <= 0 || len > (int) nPubkeyLen)
94      return 0;
95  
96    memset(pubkey, 0, nPubkeyLen);
97 +#if !defined(USE_OPENSSL) || defined(LIBRESSL_VERSION_NUMBER) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
98    MP_setbin(dh->pub_key, pubkey + (nPubkeyLen - len), len);
99 +#else
100 +  MP_setbin(DH_get0_pub_key(dh), pubkey + (nPubkeyLen - len), len);
101 +#endif
102    return 1;
103  }
104  
105 @@ -364,7 +407,11 @@ DHComputeSharedSecretKey(MDH *dh, uint8_
106    MP_gethex(q1, Q1024, len);
107    assert(len);
108  
109 +#if !defined(USE_OPENSSL) || defined(LIBRESSL_VERSION_NUMBER) || !defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100000L
110    if (isValidPublicKey(pubkeyBn, dh->p, q1))
111 +#else
112 +  if (isValidPublicKey(pubkeyBn, DH_get0_p(dh), q1))
113 +#endif
114      res = MDH_compute_key(secret, nPubkeyLen, pubkeyBn, dh);
115    else
116      res = -1;