diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-09-21 10:58:45 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-09-21 10:58:45 +0200 |
commit | cb8f979f1f6cf03307234677b05a23ecb9263c6a (patch) | |
tree | 2b7c668b931238ae8b311a3ec2f4eac9c65cde83 | |
parent | dc0e0e379ba1a9474f5e760c26c076fd1f13ac57 (diff) |
Add genkey.
-rw-r--r-- | src/simplertp-genkey.cc | 44 |
1 files changed, 43 insertions, 1 deletions
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 <stdio.h> + +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; +} |