"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libavformat/rtmpdh.c" between
libav-12.1.tar.gz and libav-12.2.tar.gz

About: libav provides cross-platform tools ("avconv") and libraries to convert, manipulate and stream a wide range of multimedia (audio and video) formats and protocols.

rtmpdh.c  (libav-12.1):rtmpdh.c  (libav-12.2)
skipping to change at line 57 skipping to change at line 57
"FFFFFFFFFFFFFFFF" "FFFFFFFFFFFFFFFF"
#define Q1024 \ #define Q1024 \
"7FFFFFFFFFFFFFFFE487ED5110B4611A62633145C06E0E68" \ "7FFFFFFFFFFFFFFFE487ED5110B4611A62633145C06E0E68" \
"948127044533E63A0105DF531D89CD9128A5043CC71A026E" \ "948127044533E63A0105DF531D89CD9128A5043CC71A026E" \
"F7CA8CD9E69D218D98158536F92F8A1BA7F09AB6B6A8E122" \ "F7CA8CD9E69D218D98158536F92F8A1BA7F09AB6B6A8E122" \
"F242DABB312F3F637A262174D31BF6B585FFAE5B7A035BF6" \ "F242DABB312F3F637A262174D31BF6B585FFAE5B7A035BF6" \
"F71C35FDAD44CFD2D74F9208BE258FF324943328F67329C0" \ "F71C35FDAD44CFD2D74F9208BE258FF324943328F67329C0" \
"FFFFFFFFFFFFFFFF" "FFFFFFFFFFFFFFFF"
#if CONFIG_GMP || CONFIG_GCRYPT
#if CONFIG_GMP #if CONFIG_GMP
#define bn_new(bn) \ #define bn_new(bn) \
do { \ do { \
bn = av_malloc(sizeof(*bn)); \ bn = av_malloc(sizeof(*bn)); \
if (bn) \ if (bn) \
mpz_init2(bn, 1); \ mpz_init2(bn, 1); \
} while (0) } while (0)
#define bn_free(bn) \ #define bn_free(bn) \
do { \ do { \
mpz_clear(bn); \ mpz_clear(bn); \
skipping to change at line 96 skipping to change at line 95
mpz_import(bn, len, 1, 1, 0, 0, buf); \ mpz_import(bn, len, 1, 1, 0, 0, buf); \
} while (0) } while (0)
#define bn_hex2bn(bn, buf, ret) \ #define bn_hex2bn(bn, buf, ret) \
do { \ do { \
bn_new(bn); \ bn_new(bn); \
if (bn) \ if (bn) \
ret = (mpz_set_str(bn, buf, 16) == 0); \ ret = (mpz_set_str(bn, buf, 16) == 0); \
else \ else \
ret = 1; \ ret = 1; \
} while (0) } while (0)
#define bn_modexp(bn, y, q, p) mpz_powm(bn, y, q, p)
#define bn_random(bn, num_bits) \ #define bn_random(bn, num_bits) \
do { \ do { \
int bits = num_bits; \ int bits = num_bits; \
mpz_set_ui(bn, 0); \ mpz_set_ui(bn, 0); \
for (bits = num_bits; bits > 0; bits -= 32) { \ for (bits = num_bits; bits > 0; bits -= 32) { \
mpz_mul_2exp(bn, bn, 32); \ mpz_mul_2exp(bn, bn, 32); \
mpz_add_ui(bn, bn, av_get_random_seed()); \ mpz_add_ui(bn, bn, av_get_random_seed()); \
} \ } \
mpz_fdiv_r_2exp(bn, bn, num_bits); \ mpz_fdiv_r_2exp(bn, bn, num_bits); \
} while (0) } while (0)
static int bn_modexp(FFBigNum bn, FFBigNum y, FFBigNum q, FFBigNum p)
{
mpz_powm(bn, y, q, p);
return 0;
}
#elif CONFIG_GCRYPT #elif CONFIG_GCRYPT
#define bn_new(bn) bn = gcry_mpi_new(1) #define bn_new(bn) bn = gcry_mpi_new(1)
#define bn_free(bn) gcry_mpi_release(bn) #define bn_free(bn) gcry_mpi_release(bn)
#define bn_set_word(bn, w) gcry_mpi_set_ui(bn, w) #define bn_set_word(bn, w) gcry_mpi_set_ui(bn, w)
#define bn_cmp(a, b) gcry_mpi_cmp(a, b) #define bn_cmp(a, b) gcry_mpi_cmp(a, b)
#define bn_copy(to, from) gcry_mpi_set(to, from) #define bn_copy(to, from) gcry_mpi_set(to, from)
#define bn_sub_word(bn, w) gcry_mpi_sub_ui(bn, bn, w) #define bn_sub_word(bn, w) gcry_mpi_sub_ui(bn, bn, w)
#define bn_cmp_1(bn) gcry_mpi_cmp_ui(bn, 1) #define bn_cmp_1(bn) gcry_mpi_cmp_ui(bn, 1)
#define bn_num_bytes(bn) (gcry_mpi_get_nbits(bn) + 7) / 8 #define bn_num_bytes(bn) (gcry_mpi_get_nbits(bn) + 7) / 8
#define bn_bn2bin(bn, buf, len) gcry_mpi_print(GCRYMPI_FMT_USG, buf, len, NU LL, bn) #define bn_bn2bin(bn, buf, len) gcry_mpi_print(GCRYMPI_FMT_USG, buf, len, NU LL, bn)
#define bn_bin2bn(bn, buf, len) gcry_mpi_scan(&bn, GCRYMPI_FMT_USG, buf, len , NULL) #define bn_bin2bn(bn, buf, len) gcry_mpi_scan(&bn, GCRYMPI_FMT_USG, buf, len , NULL)
#define bn_hex2bn(bn, buf, ret) ret = (gcry_mpi_scan(&bn, GCRYMPI_FMT_HEX, b uf, 0, 0) == 0) #define bn_hex2bn(bn, buf, ret) ret = (gcry_mpi_scan(&bn, GCRYMPI_FMT_HEX, b uf, 0, 0) == 0)
#define bn_modexp(bn, y, q, p) gcry_mpi_powm(bn, y, q, p)
#define bn_random(bn, num_bits) gcry_mpi_randomize(bn, num_bits, GCRY_WEAK_R ANDOM) #define bn_random(bn, num_bits) gcry_mpi_randomize(bn, num_bits, GCRY_WEAK_R ANDOM)
static int bn_modexp(FFBigNum bn, FFBigNum y, FFBigNum q, FFBigNum p)
{
gcry_mpi_powm(bn, y, q, p);
return 0;
}
#elif CONFIG_OPENSSL
#define bn_new(bn) bn = BN_new()
#define bn_free(bn) BN_free(bn)
#define bn_set_word(bn, w) BN_set_word(bn, w)
#define bn_cmp(a, b) BN_cmp(a, b)
#define bn_copy(to, from) BN_copy(to, from)
#define bn_sub_word(bn, w) BN_sub_word(bn, w)
#define bn_cmp_1(bn) BN_cmp(bn, BN_value_one())
#define bn_num_bytes(bn) BN_num_bytes(bn)
#define bn_bn2bin(bn, buf, len) BN_bn2bin(bn, buf)
#define bn_bin2bn(bn, buf, len) bn = BN_bin2bn(buf, len, 0)
#define bn_hex2bn(bn, buf, ret) ret = BN_hex2bn(&bn, buf)
#define bn_random(bn, num_bits) BN_rand(bn, num_bits, 0, 0)
static int bn_modexp(FFBigNum bn, FFBigNum y, FFBigNum q, FFBigNum p)
{
BN_CTX *ctx = BN_CTX_new();
if (!ctx)
return AVERROR(ENOMEM);
if (!BN_mod_exp(bn, y, q, p, ctx)) {
BN_CTX_free(ctx);
return AVERROR(EINVAL);
}
BN_CTX_free(ctx);
return 0;
}
#endif #endif
#define MAX_BYTES 18000 #define MAX_BYTES 18000
#define dh_new() av_malloc(sizeof(FF_DH)) #define dh_new() av_mallocz(sizeof(FF_DH))
static FFBigNum dh_generate_key(FF_DH *dh) static FFBigNum dh_generate_key(FF_DH *dh)
{ {
int num_bytes; int num_bytes;
num_bytes = bn_num_bytes(dh->p) - 1; num_bytes = bn_num_bytes(dh->p) - 1;
if (num_bytes <= 0 || num_bytes > MAX_BYTES) if (num_bytes <= 0 || num_bytes > MAX_BYTES)
return NULL; return NULL;
bn_new(dh->priv_key); bn_new(dh->priv_key);
if (!dh->priv_key) if (!dh->priv_key)
return NULL; return NULL;
bn_random(dh->priv_key, 8 * num_bytes); bn_random(dh->priv_key, 8 * num_bytes);
bn_new(dh->pub_key); bn_new(dh->pub_key);
if (!dh->pub_key) { if (!dh->pub_key) {
bn_free(dh->priv_key); bn_free(dh->priv_key);
return NULL; return NULL;
} }
bn_modexp(dh->pub_key, dh->g, dh->priv_key, dh->p); if (bn_modexp(dh->pub_key, dh->g, dh->priv_key, dh->p) < 0)
return NULL;
return dh->pub_key; return dh->pub_key;
} }
static int dh_compute_key(FF_DH *dh, FFBigNum pub_key_bn, static int dh_compute_key(FF_DH *dh, FFBigNum pub_key_bn,
uint32_t secret_key_len, uint8_t *secret_key) uint32_t secret_key_len, uint8_t *secret_key)
{ {
FFBigNum k; FFBigNum k;
int ret;
bn_new(k); bn_new(k);
if (!k) if (!k)
return -1; return -1;
bn_modexp(k, pub_key_bn, dh->priv_key, dh->p); if ((ret = bn_modexp(k, pub_key_bn, dh->priv_key, dh->p)) < 0) {
bn_free(k);
return ret;
}
bn_bn2bin(k, secret_key, secret_key_len); bn_bn2bin(k, secret_key, secret_key_len);
bn_free(k); bn_free(k);
/* return the length of the shared secret key like DH_compute_key */ /* return the length of the shared secret key like DH_compute_key */
return secret_key_len; return secret_key_len;
} }
void ff_dh_free(FF_DH *dh) void ff_dh_free(FF_DH *dh)
{ {
if (!dh) if (!dh)
return; return;
bn_free(dh->p); bn_free(dh->p);
bn_free(dh->g); bn_free(dh->g);
bn_free(dh->pub_key); bn_free(dh->pub_key);
bn_free(dh->priv_key); bn_free(dh->priv_key);
av_free(dh); av_free(dh);
} }
#elif CONFIG_OPENSSL
#define bn_new(bn) bn = BN_new()
#define bn_free(bn) BN_free(bn)
#define bn_set_word(bn, w) BN_set_word(bn, w)
#define bn_cmp(a, b) BN_cmp(a, b)
#define bn_copy(to, from) BN_copy(to, from)
#define bn_sub_word(bn, w) BN_sub_word(bn, w)
#define bn_cmp_1(bn) BN_cmp(bn, BN_value_one())
#define bn_num_bytes(bn) BN_num_bytes(bn)
#define bn_bn2bin(bn, buf, len) BN_bn2bin(bn, buf)
#define bn_bin2bn(bn, buf, len) bn = BN_bin2bn(buf, len, 0)
#define bn_hex2bn(bn, buf, ret) ret = BN_hex2bn(&bn, buf)
#define bn_modexp(bn, y, q, p) \
do { \
BN_CTX *ctx = BN_CTX_new(); \
if (!ctx) \
return AVERROR(ENOMEM); \
if (!BN_mod_exp(bn, y, q, p, ctx)) { \
BN_CTX_free(ctx); \
return AVERROR(EINVAL); \
} \
BN_CTX_free(ctx); \
} while (0)
#define dh_new() DH_new()
#define dh_generate_key(dh) DH_generate_key(dh)
static int dh_compute_key(FF_DH *dh, FFBigNum pub_key_bn,
uint32_t secret_key_len, uint8_t *secret_key)
{
if (secret_key_len < DH_size(dh))
return AVERROR(EINVAL);
return DH_compute_key(secret_key, pub_key_bn, dh);
}
void ff_dh_free(FF_DH *dh)
{
if (!dh)
return;
DH_free(dh);
}
#endif
static int dh_is_valid_public_key(FFBigNum y, FFBigNum p, FFBigNum q) static int dh_is_valid_public_key(FFBigNum y, FFBigNum p, FFBigNum q)
{ {
FFBigNum bn = NULL; FFBigNum bn = NULL;
int ret = AVERROR(EINVAL); int ret = AVERROR(EINVAL);
bn_new(bn); bn_new(bn);
if (!bn) if (!bn)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
skipping to change at line 248 skipping to change at line 243
if (!bn_cmp(y, bn)) if (!bn_cmp(y, bn))
goto fail; goto fail;
/* Verify with Sophie-Germain prime /* Verify with Sophie-Germain prime
* *
* This is a nice test to make sure the public key position is calculated * This is a nice test to make sure the public key position is calculated
* correctly. This test will fail in about 50% of the cases if applied to * correctly. This test will fail in about 50% of the cases if applied to
* random data. * random data.
*/ */
/* y must fulfill y^q mod p = 1 */ /* y must fulfill y^q mod p = 1 */
bn_modexp(bn, y, q, p); if ((ret = bn_modexp(bn, y, q, p)) < 0)
goto fail;
ret = AVERROR(EINVAL);
if (bn_cmp_1(bn)) if (bn_cmp_1(bn))
goto fail; goto fail;
ret = 0; ret = 0;
fail: fail:
bn_free(bn); bn_free(bn);
return ret; return ret;
} }
 End of changes. 12 change blocks. 
49 lines changed or deleted 46 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)