2 * RTMP Diffie-Hellmann utilities
3 * Copyright (c) 2012 Samuel Pitoiset
5 * This file is part of FFmpeg.
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.
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.
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
22 #ifndef AVFORMAT_RTMPDH_H
23 #define AVFORMAT_RTMPDH_H
28 #if CONFIG_NETTLE || CONFIG_GCRYPT
31 #include <nettle/bignum.h>
33 typedef mpz_ptr FFBigNum;
37 typedef gcry_mpi_t FFBigNum;
40 typedef struct FF_DH {
49 #include <openssl/bn.h>
50 #include <openssl/dh.h>
52 typedef BIGNUM *FFBigNum;
57 * Initialize a Diffie-Hellmann context.
59 * @param key_len length of the key
60 * @return a new Diffie-Hellmann context on success, NULL otherwise
62 FF_DH *ff_dh_init(int key_len);
65 * Free a Diffie-Hellmann context.
67 * @param dh a Diffie-Hellmann context to free
69 void ff_dh_free(FF_DH *dh);
72 * Generate a public key.
74 * @param dh a Diffie-Hellmann context
75 * @return zero on success, negative value otherwise
77 int ff_dh_generate_public_key(FF_DH *dh);
80 * Write the public key into the given buffer.
82 * @param dh a Diffie-Hellmann context, containing the public key to write
83 * @param pub_key the buffer where the public key is written
84 * @param pub_key_len the length of the buffer
85 * @return zero on success, negative value otherwise
87 int ff_dh_write_public_key(FF_DH *dh, uint8_t *pub_key, int pub_key_len);
90 * Compute the shared secret key from the private FF_DH value and the
91 * other party's public value.
93 * @param dh a Diffie-Hellmann context, containing the private key
94 * @param pub_key the buffer containing the public key
95 * @param pub_key_len the length of the buffer
96 * @param secret_key the buffer where the secret key is written
97 * @return length of the shared secret key on success, negative value otherwise
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);
102 #endif /* AVFORMAT_RTMPDH_H */