yading@11: /* yading@11: * RTMP Diffie-Hellmann utilities yading@11: * Copyright (c) 2012 Samuel Pitoiset yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVFORMAT_RTMPDH_H yading@11: #define AVFORMAT_RTMPDH_H yading@11: yading@11: #include "avformat.h" yading@11: #include "config.h" yading@11: yading@11: #if CONFIG_NETTLE || CONFIG_GCRYPT yading@11: #if CONFIG_NETTLE yading@11: #include yading@11: #include yading@11: yading@11: typedef mpz_ptr FFBigNum; yading@11: #elif CONFIG_GCRYPT yading@11: #include yading@11: yading@11: typedef gcry_mpi_t FFBigNum; yading@11: #endif yading@11: yading@11: typedef struct FF_DH { yading@11: FFBigNum p; yading@11: FFBigNum g; yading@11: FFBigNum pub_key; yading@11: FFBigNum priv_key; yading@11: long length; yading@11: } FF_DH; yading@11: yading@11: #elif CONFIG_OPENSSL yading@11: #include yading@11: #include yading@11: yading@11: typedef BIGNUM *FFBigNum; yading@11: typedef DH FF_DH; yading@11: #endif yading@11: yading@11: /** yading@11: * Initialize a Diffie-Hellmann context. yading@11: * yading@11: * @param key_len length of the key yading@11: * @return a new Diffie-Hellmann context on success, NULL otherwise yading@11: */ yading@11: FF_DH *ff_dh_init(int key_len); yading@11: yading@11: /** yading@11: * Free a Diffie-Hellmann context. yading@11: * yading@11: * @param dh a Diffie-Hellmann context to free yading@11: */ yading@11: void ff_dh_free(FF_DH *dh); yading@11: yading@11: /** yading@11: * Generate a public key. yading@11: * yading@11: * @param dh a Diffie-Hellmann context yading@11: * @return zero on success, negative value otherwise yading@11: */ yading@11: int ff_dh_generate_public_key(FF_DH *dh); yading@11: yading@11: /** yading@11: * Write the public key into the given buffer. yading@11: * yading@11: * @param dh a Diffie-Hellmann context, containing the public key to write yading@11: * @param pub_key the buffer where the public key is written yading@11: * @param pub_key_len the length of the buffer yading@11: * @return zero on success, negative value otherwise yading@11: */ yading@11: int ff_dh_write_public_key(FF_DH *dh, uint8_t *pub_key, int pub_key_len); yading@11: yading@11: /** yading@11: * Compute the shared secret key from the private FF_DH value and the yading@11: * other party's public value. yading@11: * yading@11: * @param dh a Diffie-Hellmann context, containing the private key yading@11: * @param pub_key the buffer containing the public key yading@11: * @param pub_key_len the length of the buffer yading@11: * @param secret_key the buffer where the secret key is written yading@11: * @return length of the shared secret key on success, negative value otherwise yading@11: */ yading@11: int ff_dh_compute_shared_secret_key(FF_DH *dh, const uint8_t *pub_key, yading@11: int pub_key_len, uint8_t *secret_key); yading@11: yading@11: #endif /* AVFORMAT_RTMPDH_H */