On Thu, 19 Jul 2012, Samuel Pitoiset wrote:
diff --git a/libavformat/rtmpdh.c b/libavformat/rtmpdh.c
new file mode 100644
index 0000000..8ddc5fc
--- /dev/null
+++ b/libavformat/rtmpdh.c
@@ -0,0 +1,329 @@
+/*
+ * RTMP Diffie-Hellmann utilities
+ * Copyright (c) 2012 Samuel Pitoiset
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * RTMP Diffie-Hellmann utilities
+ */
+
+#include "config.h"
+#include "rtmpdh.h"
+
+#define P1024 \
+ "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
+ "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
+ "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
+ "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
+ "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381" \
+ "FFFFFFFFFFFFFFFF"
+
+#define Q1024 \
+ "7FFFFFFFFFFFFFFFE487ED5110B4611A62633145C06E0E68" \
+ "948127044533E63A0105DF531D89CD9128A5043CC71A026E" \
+ "F7CA8CD9E69D218D98158536F92F8A1BA7F09AB6B6A8E122" \
+ "F242DABB312F3F637A262174D31BF6B585FFAE5B7A035BF6" \
+ "F71C35FDAD44CFD2D74F9208BE258FF324943328F67329C0" \
+ "FFFFFFFFFFFFFFFF"
+
+#if CONFIG_NETTLE || CONFIG_GCRYPT
+#if CONFIG_NETTLE
+#define bn_new(bn) \
+ do { \
+ bn = av_malloc(sizeof(*bn)); \
+ if (bn) \
+ mpz_init2(bn, 1); \
+ } while (0)
+#define bn_free(bn) \
+ do { \
+ mpz_clear(bn); \
+ av_free(bn); \
+ } while (0)
+#define bn_set_word(bn, w) mpz_set_ui(bn, w)
+#define bn_cmp(a, b) mpz_cmp(a, b)
+#define bn_copy(to, from) mpz_set(to, from)
+#define bn_sub_word(bn, w) mpz_sub_ui(bn, bn, w)
+#define bn_cmp_1(bn) mpz_cmp_ui(bn, 1)
+#define bn_num_bytes(bn) (mpz_sizeinbase(bn, 2) + 7) / 8
+#define bn_bn2bin(bn, buf, len) nettle_mpz_get_str_256(len, buf, bn)
+#define bn_bin2bn(bn, buf, len) \
+ do { \
+ bn_new(bn); \
+ if (bn) \
+ nettle_mpz_set_str_256_u(bn, len, buf); \
+ } while (0)
+#define bn_hex2bn(bn, buf, ret) \
+ do { \
+ bn_new(bn); \
+ if (bn) \
+ ret = (mpz_set_str(bn, buf, 16) == 0); \
+ } while (0)
+#define bn_modexp(bn, y, q, p) mpz_powm(bn, y, q, p)
+#define bn_random(bn, num_bytes) mpz_random(bn, num_bytes);
If you look up this function, it says "Generate a random integer of at
most max_size limbs. The generated random number doesn't satisfy any
particular requirements of randomness.". If you look further in the source
of gmp, you'll notice that it always uses the same random seed, so it will
always generate the same "secret" key. Not exactly ideal.
So for this case you might want to use e.g. av_get_random_seed instead to
seed an AVLFG to generate as much random data as you need.
I'm not sure if this is the case for the gcrypt or openssl version of the
same stuff though. Please investigate that and see which ones need to use
better random functions.
// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel