annotate ffmpeg/libavformat/rtmpdh.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * RTMP Diffie-Hellmann utilities
yading@11 3 * Copyright (c) 2012 Samuel Pitoiset
yading@11 4 *
yading@11 5 * This file is part of FFmpeg.
yading@11 6 *
yading@11 7 * FFmpeg is free software; you can redistribute it and/or
yading@11 8 * modify it under the terms of the GNU Lesser General Public
yading@11 9 * License as published by the Free Software Foundation; either
yading@11 10 * version 2.1 of the License, or (at your option) any later version.
yading@11 11 *
yading@11 12 * FFmpeg is distributed in the hope that it will be useful,
yading@11 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 15 * Lesser General Public License for more details.
yading@11 16 *
yading@11 17 * You should have received a copy of the GNU Lesser General Public
yading@11 18 * License along with FFmpeg; if not, write to the Free Software
yading@11 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 20 */
yading@11 21
yading@11 22 #ifndef AVFORMAT_RTMPDH_H
yading@11 23 #define AVFORMAT_RTMPDH_H
yading@11 24
yading@11 25 #include "avformat.h"
yading@11 26 #include "config.h"
yading@11 27
yading@11 28 #if CONFIG_NETTLE || CONFIG_GCRYPT
yading@11 29 #if CONFIG_NETTLE
yading@11 30 #include <gmp.h>
yading@11 31 #include <nettle/bignum.h>
yading@11 32
yading@11 33 typedef mpz_ptr FFBigNum;
yading@11 34 #elif CONFIG_GCRYPT
yading@11 35 #include <gcrypt.h>
yading@11 36
yading@11 37 typedef gcry_mpi_t FFBigNum;
yading@11 38 #endif
yading@11 39
yading@11 40 typedef struct FF_DH {
yading@11 41 FFBigNum p;
yading@11 42 FFBigNum g;
yading@11 43 FFBigNum pub_key;
yading@11 44 FFBigNum priv_key;
yading@11 45 long length;
yading@11 46 } FF_DH;
yading@11 47
yading@11 48 #elif CONFIG_OPENSSL
yading@11 49 #include <openssl/bn.h>
yading@11 50 #include <openssl/dh.h>
yading@11 51
yading@11 52 typedef BIGNUM *FFBigNum;
yading@11 53 typedef DH FF_DH;
yading@11 54 #endif
yading@11 55
yading@11 56 /**
yading@11 57 * Initialize a Diffie-Hellmann context.
yading@11 58 *
yading@11 59 * @param key_len length of the key
yading@11 60 * @return a new Diffie-Hellmann context on success, NULL otherwise
yading@11 61 */
yading@11 62 FF_DH *ff_dh_init(int key_len);
yading@11 63
yading@11 64 /**
yading@11 65 * Free a Diffie-Hellmann context.
yading@11 66 *
yading@11 67 * @param dh a Diffie-Hellmann context to free
yading@11 68 */
yading@11 69 void ff_dh_free(FF_DH *dh);
yading@11 70
yading@11 71 /**
yading@11 72 * Generate a public key.
yading@11 73 *
yading@11 74 * @param dh a Diffie-Hellmann context
yading@11 75 * @return zero on success, negative value otherwise
yading@11 76 */
yading@11 77 int ff_dh_generate_public_key(FF_DH *dh);
yading@11 78
yading@11 79 /**
yading@11 80 * Write the public key into the given buffer.
yading@11 81 *
yading@11 82 * @param dh a Diffie-Hellmann context, containing the public key to write
yading@11 83 * @param pub_key the buffer where the public key is written
yading@11 84 * @param pub_key_len the length of the buffer
yading@11 85 * @return zero on success, negative value otherwise
yading@11 86 */
yading@11 87 int ff_dh_write_public_key(FF_DH *dh, uint8_t *pub_key, int pub_key_len);
yading@11 88
yading@11 89 /**
yading@11 90 * Compute the shared secret key from the private FF_DH value and the
yading@11 91 * other party's public value.
yading@11 92 *
yading@11 93 * @param dh a Diffie-Hellmann context, containing the private key
yading@11 94 * @param pub_key the buffer containing the public key
yading@11 95 * @param pub_key_len the length of the buffer
yading@11 96 * @param secret_key the buffer where the secret key is written
yading@11 97 * @return length of the shared secret key on success, negative value otherwise
yading@11 98 */
yading@11 99 int ff_dh_compute_shared_secret_key(FF_DH *dh, const uint8_t *pub_key,
yading@11 100 int pub_key_len, uint8_t *secret_key);
yading@11 101
yading@11 102 #endif /* AVFORMAT_RTMPDH_H */