]> git.sesse.net Git - vlc/blob - libs/srtp/recv.c
Remove window size parameter.
[vlc] / libs / srtp / recv.c
1 /*
2  * Secure RTP with libgcrypt
3  * Copyright (C) 2007  RĂ©mi Denis-Courmont <rdenis # simphalempin , com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include <stdint.h>
25 #include <stddef.h>
26 #include "srtp.h"
27
28 #include <stdio.h>
29 #include <string.h>
30
31 #include <unistd.h>
32 #include <netinet/in.h>
33
34 int main (void)
35 {
36     int fd = socket (AF_INET, SOCK_DGRAM, 0);
37     struct sockaddr_in addr;
38     memset (&addr, 0, sizeof (addr));
39     addr.sin_family = AF_INET;
40 #ifdef HAVE_SA_LEN
41     addr.sin_len = sizeof (addr);
42 #endif
43     addr.sin_port = htons (10000);
44     addr.sin_addr.s_addr = htonl (0x7f000001);
45     if (bind (fd, (struct sockaddr *)&addr, sizeof (addr)))
46         return 1;
47
48     static const uint8_t key[16] =
49         "\x12\x34\x56\x78\x9A\xBC\xDE\xF0"
50         "\x12\x34\x56\x78\x9A\xBC\xDE\xF0";
51     static const uint8_t salt[14] =
52         "\x12\x34\x56\x78\x90" "\x12\x34\x56\x78\x90" "\x12\x34\x56\x78";
53
54     srtp_session_t *s = srtp_create ("AES_CM_128_HMAC_SHA1_80", 0, 0);
55     if (s == NULL)
56         return 1;
57     if (srtp_setkey (s, key, 16, salt, 14))
58         goto error;
59
60     uint8_t buf[1500];
61     size_t len;
62 #if 0
63     memset (buf, 0, sizeof (buf));
64     buf[0] = 2 << 6;
65     buf[1] = 1;
66     memcpy (buf + 2, &(uint16_t){ htons (9527) }, 2);
67     memcpy (buf + 8, "\xde\xad\xbe\xef", 4);
68     memcpy (buf + 4, &(uint32_t){ htonl (1) }, 4);
69     strcpy ((char *)buf + 12, "a\n");
70     len = 12 + strlen ((char *)buf + 12) + 1;
71 #endif
72     for (;;)
73     {
74         len = read (fd, buf, sizeof (buf));
75         if (srtp_recv (s, buf, &len))
76             fputs ("Cannot decrypt!\n", stderr);
77         puts ((char *)buf + 12);
78         if (srtp_send (s, buf, &len, sizeof (buf)) || srtp_recv (s, buf, &len))
79             break;
80         puts ((char *)buf + 12);
81     }
82
83 error:
84     srtp_destroy (s);
85     close (fd);
86     return 0;
87 }