OpenFFmpeg
rtmpdh.h
1 /*
2  * RTMP Diffie-Hellmann utilities
3  * Copyright (c) 2012 Samuel Pitoiset
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 <stdint.h>
26 
27 #include "config.h"
28 
29 #if CONFIG_GMP
30 #include <gmp.h>
31 
32 typedef mpz_ptr FFBigNum;
33 #elif CONFIG_GCRYPT
34 #include <gcrypt.h>
35 
36 typedef gcry_mpi_t FFBigNum;
37 
38 #elif CONFIG_OPENSSL
39 #include <openssl/bn.h>
40 #include <openssl/dh.h>
41 
42 typedef BIGNUM *FFBigNum;
43 #elif CONFIG_MBEDTLS
44 #include <mbedtls/bignum.h>
45 
46 typedef mbedtls_mpi *FFBigNum;
47 
48 #endif
49 
50 typedef struct FF_DH {
51  FFBigNum p;
52  FFBigNum g;
53  FFBigNum pub_key;
54  FFBigNum priv_key;
55  long length;
56 } FF_DH;
57 
58 
65 FF_DH *ff_dh_init(int key_len);
66 
72 void ff_dh_free(FF_DH *dh);
73 
81 
90 int ff_dh_write_public_key(FF_DH *dh, uint8_t *pub_key, int pub_key_len);
91 
103 int ff_dh_compute_shared_secret_key(FF_DH *dh, const uint8_t *pub_key,
104  int pub_key_len, uint8_t *secret_key,
105  int secret_key_len);
106 
107 #endif /* AVFORMAT_RTMPDH_H */
int ff_dh_write_public_key(FF_DH *dh, uint8_t *pub_key, int pub_key_len)
Write the public key into the given buffer.
Definition: rtmpdh.c:374
Definition: rtmpdh.h:50
int ff_dh_compute_shared_secret_key(FF_DH *dh, const uint8_t *pub_key, int pub_key_len, uint8_t *secret_key, int secret_key_len)
Compute the shared secret key from the private FF_DH value and the other party&#39;s public value...
Definition: rtmpdh.c:390
void ff_dh_free(FF_DH *dh)
Free a Diffie-Hellmann context.
Definition: rtmpdh.c:269
int ff_dh_generate_public_key(FF_DH *dh)
Generate a public key.
Definition: rtmpdh.c:348
av_cold FF_DH * ff_dh_init(int key_len)
Initialize a Diffie-Hellmann context.
Definition: rtmpdh.c:321