mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +00:00
add __openssl_compute_key to calc the shared key
This commit is contained in:
parent
7adbe7f456
commit
d4c2aa1e8e
2 changed files with 33 additions and 0 deletions
|
@ -129,6 +129,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#define ERROR_OpenSslSha256Final 2035
|
||||
#define ERROR_OpenSslSha256EvpDigest 2036
|
||||
#define ERROR_OpenSslSha256DigestSize 2037
|
||||
#define ERROR_OpenSslGetPeerPublicKey 2038
|
||||
#define ERROR_OpenSslComputeSharedKey 2039
|
||||
//
|
||||
// system control message,
|
||||
// not an error, but special control logic.
|
||||
|
|
|
@ -202,6 +202,37 @@ namespace _srs_internal
|
|||
|
||||
return ret;
|
||||
}
|
||||
int __openssl_compute_key(DH* pdh, const char* peer_pub_key, int ppk_size, char* secret)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
int32_t bits_count = 1024;
|
||||
|
||||
// 2. generate the g, p, private/public key.
|
||||
if ((ret = __openssl_initialize_dh(pdh, bits_count)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// copy public key to bytes.
|
||||
srs_assert(BN_num_bytes(pdh->pub_key) == ppk_size);
|
||||
|
||||
BIGNUM* ppk = NULL;
|
||||
if ((ppk = BN_bin2bn((const unsigned char*)peer_pub_key, ppk_size, 0)) == NULL) {
|
||||
ret = ERROR_OpenSslGetPeerPublicKey;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// if failed, donot return, do cleanup.
|
||||
if (DH_compute_key((unsigned char*)secret, ppk, pdh) < 0) {
|
||||
ret = ERROR_OpenSslComputeSharedKey;
|
||||
}
|
||||
|
||||
if (ppk) {
|
||||
BN_free(ppk);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
void __openssl_free(DH* pdh)
|
||||
{
|
||||
if (pdh != NULL) {
|
||||
|
|
Loading…
Reference in a new issue