Libav
rtmpdh.h
Go to the documentation of this file.
1 /*
2  * RTMP Diffie-Hellmann utilities
3  * Copyright (c) 2012 Samuel Pitoiset
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef AVFORMAT_RTMPDH_H
23 #define AVFORMAT_RTMPDH_H
24 
25 #include "avformat.h"
26 #include "config.h"
27 
28 #if CONFIG_NETTLE || CONFIG_GCRYPT
29 #if CONFIG_NETTLE
30 #include <gmp.h>
31 #include <nettle/bignum.h>
32 
33 typedef mpz_ptr FFBigNum;
34 #elif CONFIG_GCRYPT
35 #include <gcrypt.h>
36 
37 typedef gcry_mpi_t FFBigNum;
38 #endif
39 
40 typedef struct FF_DH {
41  FFBigNum p;
42  FFBigNum g;
43  FFBigNum pub_key;
44  FFBigNum priv_key;
45  long length;
46 } FF_DH;
47 
48 #elif CONFIG_OPENSSL
49 #include <openssl/bn.h>
50 #include <openssl/dh.h>
51 
52 typedef BIGNUM *FFBigNum;
53 typedef DH FF_DH;
54 #endif
55 
62 FF_DH *ff_dh_init(int key_len);
63 
69 void ff_dh_free(FF_DH *dh);
70 
77 int ff_dh_generate_public_key(FF_DH *dh);
78 
87 int ff_dh_write_public_key(FF_DH *dh, uint8_t *pub_key, int pub_key_len);
88 
99 int ff_dh_compute_shared_secret_key(FF_DH *dh, const uint8_t *pub_key,
100  int pub_key_len, uint8_t *secret_key);
101 
102 #endif /* AVFORMAT_RTMPDH_H */