From cb8f979f1f6cf03307234677b05a23ecb9263c6a Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 21 Sep 2014 10:58:45 +0200 Subject: Add genkey. --- src/simplertp-genkey.cc | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/simplertp-genkey.cc b/src/simplertp-genkey.cc index bd28fee..be79c6b 100644 --- a/src/simplertp-genkey.cc +++ b/src/simplertp-genkey.cc @@ -24,5 +24,47 @@ * along with SimpleRTP; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include "simplertp-genkey.h" +#include + +int getrandom(char *buf, size_t size) +{ + FILE *fp = fopen("/dev/random", "r"); + if(!fp) { + perror("Could not open /dev/random for reading"); + return 1; + } + int ret = fread(buf, 1, size, fp); + fclose(fp); + + if(ret != size) { + fprintf(stderr, "Could not read %d bytes from /dev/random, only got %d\n", + size, ret); + return 1; + } + + return 0; +} + +int main() +{ + fprintf(stderr, "Generating key and ssrc...\n"); + fprintf(stderr, " - Move your mouse to generate entropy" + " or this will take a looooong time.\n"); + + char key[30]; + if(getrandom(key, sizeof(key)) != 0) return 1; + + char ssrc[4]; + if(getrandom(ssrc, sizeof(ssrc)) != 0) return 1; + + printf("[crypto]\n"); + printf("key=\""); + for(int i = 0; i < sizeof(key); i++) { + printf("%02x", (unsigned char)key[i]); + } + printf("\"\n"); + printf("ssrc=%u\n", *((unsigned int*)ssrc)); + + return 0; +} -- cgit v1.2.3