Statistics
| Branch: | Revision:

ffmpeg / libavformat / rdt.c @ e9dea59f

History | View | Annotate | Download (2.32 KB)

1
/*
2
 * Realmedia RTSP protocol (RDT) support.
3
 * Copyright (c) 2007 Ronald S. Bultje
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

    
22
/**
23
 * @file rdt.c
24
 * @brief Realmedia RTSP protocol (RDT) support
25
 * @author Ronald S. Bultje <rbultje@ronald.bitfreak.net>
26
 */
27

    
28
#include "avformat.h"
29
#include "libavutil/avstring.h"
30
#include "rdt.h"
31
#include "libavutil/base64.h"
32
#include "libavutil/md5.h"
33
#include "rm.h"
34
#include "internal.h"
35

    
36
void
37
ff_rdt_calc_response_and_checksum(char response[41], char chksum[9],
38
                                  const char *challenge)
39
{
40
    int ch_len = strlen (challenge), i;
41
    unsigned char zres[16],
42
        buf[64] = { 0xa1, 0xe9, 0x14, 0x9d, 0x0e, 0x6b, 0x3b, 0x59 };
43
#define XOR_TABLE_SIZE 37
44
    const unsigned char xor_table[XOR_TABLE_SIZE] = {
45
        0x05, 0x18, 0x74, 0xd0, 0x0d, 0x09, 0x02, 0x53,
46
        0xc0, 0x01, 0x05, 0x05, 0x67, 0x03, 0x19, 0x70,
47
        0x08, 0x27, 0x66, 0x10, 0x10, 0x72, 0x08, 0x09,
48
        0x63, 0x11, 0x03, 0x71, 0x08, 0x08, 0x70, 0x02,
49
        0x10, 0x57, 0x05, 0x18, 0x54 };
50

    
51
    /* some (length) checks */
52
    if (ch_len == 40) /* what a hack... */
53
        ch_len = 32;
54
    else if (ch_len > 56)
55
        ch_len = 56;
56
    memcpy(buf + 8, challenge, ch_len);
57

    
58
    /* xor challenge bytewise with xor_table */
59
    for (i = 0; i < XOR_TABLE_SIZE; i++)
60
        buf[8 + i] ^= xor_table[i];
61

    
62
    av_md5_sum(zres, buf, 64);
63
    ff_data_to_hex(response, zres, 16);
64
    for (i=0;i<32;i++) response[i] = tolower(response[i]);
65

    
66
    /* add tail */
67
    strcpy (response + 32, "01d0a8e3");
68

    
69
    /* calculate checksum */
70
    for (i = 0; i < 8; i++)
71
        chksum[i] = response[i * 4];
72
    chksum[8] = 0;
73
}