From: hyc Date: Sat, 26 Dec 2009 23:36:35 +0000 (+0000) Subject: Minor cleanup X-Git-Tag: v2.4~385 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cfe110af69c206160cce7f66ea871e20bd217af6;p=rtmpdump Minor cleanup git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@114 400ebc74-4327-4243-bc38-086b20814532 --- diff --git a/dh.h b/dh.h index 6b9bd74..0765eee 100644 --- a/dh.h +++ b/dh.h @@ -43,7 +43,7 @@ void dh_pg_init() { if(dh_shared_p || dh_shared_g) return; - + dh_shared_p = BN_new(); dh_shared_g = BN_new(); assert(dh_shared_p && dh_shared_g); @@ -88,7 +88,7 @@ isValidPublicKey(BIGNUM * y, BIGNUM * p, BIGNUM * q) // Verify with Sophie-Germain prime // // This is a nice test to make sure the public key position is calculated - // correctly. This test will fail in about 50% of the cases if applied to + // correctly. This test will fail in about 50% of the cases if applied to // random data. // if (q) @@ -192,6 +192,7 @@ DHGetPublicKey(DH * dh, uint8_t * pubkey, size_t nPubkeyLen) return 1; } +#if 0 /* unused */ static int DHGetPrivateKey(DH * dh, uint8_t * privkey, size_t nPrivkeyLen) { @@ -206,6 +207,7 @@ DHGetPrivateKey(DH * dh, uint8_t * privkey, size_t nPrivkeyLen) BN_bn2bin(dh->priv_key, privkey + (nPrivkeyLen - len)); return 1; } +#endif // computes the shared secret key from the private DH value and the othe parties public key (pubkey) static int diff --git a/handshake.h b/handshake.h index faeb116..5cac855 100644 --- a/handshake.h +++ b/handshake.h @@ -257,15 +257,18 @@ HandShake(RTMP * r, bool FP9HandShake) int i; int dhposClient = 0; int digestPosClient = 0; - RC4_KEY *keyIn = 0; - RC4_KEY *keyOut = 0; bool encrypted = r->Link.protocol == RTMP_PROTOCOL_RTMPE || r->Link.protocol == RTMP_PROTOCOL_RTMPTE; - char clientbuf[RTMP_SIG_SIZE + 1], *clientsig=clientbuf+1; + RC4_KEY *keyIn = 0; + RC4_KEY *keyOut = 0; + + int32_t *ip; + uint32_t uptime; + + char clientbuf[RTMP_SIG_SIZE + 4], *clientsig=clientbuf+4; char serversig[RTMP_SIG_SIZE]; char type; - uint32_t uptime; if (encrypted || r->Link.SWFHash.av_len) FP9HandShake = true; @@ -275,9 +278,9 @@ HandShake(RTMP * r, bool FP9HandShake) r->Link.rc4keyIn = r->Link.rc4keyOut = 0; if (encrypted) - clientbuf[0] = 0x06; /* 0x08 is RTMPE as well */ + clientsig[-1] = 0x06; /* 0x08 is RTMPE as well */ else - clientbuf[0] = 0x03; + clientsig[-1] = 0x03; uptime = htonl(RTMP_GetTime()); memcpy(clientsig, &uptime, 4); @@ -290,7 +293,7 @@ HandShake(RTMP * r, bool FP9HandShake) clientsig[6] = 124; clientsig[7] = 2; - Log(LOGDEBUG, "%s: Client type: %02X\n", __FUNCTION__, clientbuf[0]); + Log(LOGDEBUG, "%s: Client type: %02X\n", __FUNCTION__, clientsig[-1]); } else { @@ -299,11 +302,11 @@ HandShake(RTMP * r, bool FP9HandShake) /* generate random data */ #ifdef _DEBUG - for (i = 8; i < RTMP_SIG_SIZE; i++) - clientsig[i] = 0; + memset(clientsig+8, 0, RTMP_SIG_SIZE=8); #else - for (i = 8; i < RTMP_SIG_SIZE; i++) - clientsig[i] = (char) (rand() % 256); + ip = (int32_t *)(clientsig+8); + for (i = 2; i < RTMP_SIG_SIZE/4; i++) + *ip++ = rand(); #endif /* set handshake digest */ @@ -355,7 +358,7 @@ HandShake(RTMP * r, bool FP9HandShake) LogHex(LOGDEBUG, clientsig, RTMP_SIG_SIZE); #endif - if (!WriteN(r, clientbuf, RTMP_SIG_SIZE + 1)) + if (!WriteN(r, clientsig-1, RTMP_SIG_SIZE + 1)) return false; if (ReadN(r, &type, 1) != 1) /* 0x03 or 0x06 */ @@ -363,9 +366,9 @@ HandShake(RTMP * r, bool FP9HandShake) Log(LOGDEBUG, "%s: Type Answer : %02X", __FUNCTION__, type); - if (type != clientbuf[0]) + if (type != clientsig[-1]) Log(LOGWARNING, "%s: Type mismatch: client sent %d, server answered %d", - __FUNCTION__, clientbuf[0], type); + __FUNCTION__, clientsig[-1], type); if (ReadN(r, serversig, RTMP_SIG_SIZE) != RTMP_SIG_SIZE) return false; @@ -577,9 +580,10 @@ SHandShake(RTMP * r) RC4_KEY *keyOut = 0; bool FP9HandShake = false; bool encrypted; + int32_t *ip; char clientsig[RTMP_SIG_SIZE]; - char serverbuf[RTMP_SIG_SIZE + 1], *serversig = serverbuf+1; + char serverbuf[RTMP_SIG_SIZE + 4], *serversig = serverbuf+4; char type; uint32_t uptime; @@ -606,7 +610,7 @@ SHandShake(RTMP * r) return false; } - serverbuf[0] = type; + serversig[-1] = type; r->Link.rc4keyIn = r->Link.rc4keyOut = 0; @@ -628,11 +632,11 @@ SHandShake(RTMP * r) /* generate random data */ #ifdef _DEBUG - for (i = 8; i < RTMP_SIG_SIZE; i++) - serversig[i] = 0; + memset(serversig+8, 0, RTMP_SIG_SIZE-8); #else - for (i = 8; i < RTMP_SIG_SIZE; i++) - serversig[i] = (char) (rand() % 256); + ip = (int32_t *)(serversig+8); + for (i = 2; i < RTMP_SIG_SIZE/4; i++) + *ip++ = rand(); #endif /* set handshake digest */ @@ -684,7 +688,7 @@ SHandShake(RTMP * r) LogHex(LOGDEBUG, serversig, RTMP_SIG_SIZE); #endif - if (!WriteN(r, serverbuf, RTMP_SIG_SIZE + 1)) + if (!WriteN(r, serversig-1, RTMP_SIG_SIZE + 1)) return false; if (ReadN(r, clientsig, RTMP_SIG_SIZE) != RTMP_SIG_SIZE)