You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.3KB

  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. * @file rdt.c
  23. * @brief Realmedia RTSP protocol (RDT) support
  24. * @author Ronald S. Bultje <rbultje@ronald.bitfreak.net>
  25. */
  26. #include "avformat.h"
  27. #include "libavutil/avstring.h"
  28. #include "rdt.h"
  29. #include "libavutil/base64.h"
  30. #include "libavutil/md5.h"
  31. #include "rm.h"
  32. #include "internal.h"
  33. void
  34. ff_rdt_calc_response_and_checksum(char response[41], char chksum[9],
  35. const char *challenge)
  36. {
  37. int ch_len = strlen (challenge), i;
  38. unsigned char zres[16],
  39. buf[64] = { 0xa1, 0xe9, 0x14, 0x9d, 0x0e, 0x6b, 0x3b, 0x59 };
  40. #define XOR_TABLE_SIZE 37
  41. const unsigned char xor_table[XOR_TABLE_SIZE] = {
  42. 0x05, 0x18, 0x74, 0xd0, 0x0d, 0x09, 0x02, 0x53,
  43. 0xc0, 0x01, 0x05, 0x05, 0x67, 0x03, 0x19, 0x70,
  44. 0x08, 0x27, 0x66, 0x10, 0x10, 0x72, 0x08, 0x09,
  45. 0x63, 0x11, 0x03, 0x71, 0x08, 0x08, 0x70, 0x02,
  46. 0x10, 0x57, 0x05, 0x18, 0x54 };
  47. /* some (length) checks */
  48. if (ch_len == 40) /* what a hack... */
  49. ch_len = 32;
  50. else if (ch_len > 56)
  51. ch_len = 56;
  52. memcpy(buf + 8, challenge, ch_len);
  53. /* xor challenge bytewise with xor_table */
  54. for (i = 0; i < XOR_TABLE_SIZE; i++)
  55. buf[8 + i] ^= xor_table[i];
  56. av_md5_sum(zres, buf, 64);
  57. ff_data_to_hex(response, zres, 16);
  58. for (i=0;i<32;i++) response[i] = tolower(response[i]);
  59. /* add tail */
  60. strcpy (response + 32, "01d0a8e3");
  61. /* calculate checksum */
  62. for (i = 0; i < 8; i++)
  63. chksum[i] = response[i * 4];
  64. chksum[8] = 0;
  65. }