annotate stream/stream_bd.c @ 31848:1241f62e54e7

Return an error when seeking beyond EOF. Avoids an endless loop.
author reimar
date Wed, 04 Aug 2010 13:49:16 +0000
parents 273d40130183
children 66b846665274
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
1 /*
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
2 * Bluray stream playback
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
3 * by cRTrn13 <crtrn13-at-gmail.com> 2009
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
4 *
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
5 * This file is part of MPlayer.
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
6 *
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
7 * MPlayer is free software; you can redistribute it and/or modify
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
10 * (at your option) any later version.
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
11 *
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
12 * MPlayer is distributed in the hope that it will be useful,
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
15 * GNU General Public License for more details.
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
16 *
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License along
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
18 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
20 */
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
21
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
22 #include <stdio.h>
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
23 #include <limits.h>
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
24 #include "libavutil/common.h"
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
25 #include "libavutil/aes.h"
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
26 #include "libavutil/sha.h"
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
27 #include "libmpdemux/demuxer.h"
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
28 #include "libavutil/intreadwrite.h"
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
29 #include "m_struct.h"
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
30 #include "m_option.h"
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
31 #include "stream.h"
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
32
31840
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
33 static const int BD_UNIT_SIZE = 6144;
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
34 static const char *BD_UKF_PATH = "/%s/AACS/Unit_Key_RO.inf";
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
35 static const char *BD_M2TS_PATH = "/%s/BDMV/STREAM/%05d.m2ts";
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
36
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
37 static const char *DEFAULT_BD_DEVICE = "/mnt/bd";
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
38
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
39 static const struct stream_priv_s {
31840
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
40 int title;
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
41 char *device;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
42 } stream_priv_dflts = {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
43 0,
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
44 NULL
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
45 };
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
46
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
47 // Format: bd://[title][</mntlocation>]
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
48 // --> e.g.: bd://117/media/THE_MUMMY/
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
49 // --> or bd://152
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
50 // instead of directly, mount location can also be gotten through -dvd-device
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
51 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
52 static const m_option_t stream_opts_fields[] = {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
53 { "hostname", ST_OFF(title), CONF_TYPE_INT, M_OPT_RANGE, 0, 99999, NULL},
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
54 { "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL},
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
55 { NULL, NULL, 0, 0, 0, 0, NULL }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
56 };
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
57
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
58 static const struct m_struct_st stream_opts = {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
59 "bd",
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
60 sizeof(struct stream_priv_s),
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
61 &stream_priv_dflts,
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
62 stream_opts_fields
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
63 };
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
64
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
65 typedef union {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
66 uint64_t u64[2];
31840
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
67 uint8_t u8[16];
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
68 } key;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
69
31845
678884af8ade Use the "key" type also for the IV constant.
reimar
parents: 31840
diff changeset
70 static const key BD_CBC_IV = {
678884af8ade Use the "key" type also for the IV constant.
reimar
parents: 31840
diff changeset
71 .u8 = {
678884af8ade Use the "key" type also for the IV constant.
reimar
parents: 31840
diff changeset
72 0x0b, 0xa0, 0xf8, 0xdd, 0xfe, 0xa6, 0x1f, 0xb3,
678884af8ade Use the "key" type also for the IV constant.
reimar
parents: 31840
diff changeset
73 0xd8, 0xdf, 0x9f, 0x56, 0x6a, 0x05, 0x0f, 0x78
678884af8ade Use the "key" type also for the IV constant.
reimar
parents: 31840
diff changeset
74 }
678884af8ade Use the "key" type also for the IV constant.
reimar
parents: 31840
diff changeset
75 };
678884af8ade Use the "key" type also for the IV constant.
reimar
parents: 31840
diff changeset
76
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
77 struct uks {
31840
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
78 int count;
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
79 key *keys;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
80 };
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
81
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
82 struct bd_priv {
31840
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
83 key vuk;
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
84 key iv;
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
85 int title;
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
86 const char *device;
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
87 FILE *title_file;
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
88 struct AVAES *aescbc;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
89 struct AVAES *aeseed;
31840
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
90 off_t pos;
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
91 struct uks uks;
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
92 };
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
93
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
94 static void bd_stream_close(stream_t *s)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
95 {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
96 struct bd_priv *bd = s->priv;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
97 fclose(bd->title_file);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
98 av_free(bd->aescbc);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
99 av_free(bd->aeseed);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
100 free(bd->uks.keys);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
101 free(bd);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
102 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
103
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
104 static int bd_stream_seek(stream_t *s, off_t pos)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
105 {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
106 struct bd_priv *bd = s->priv;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
107
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
108 // must seek to start of unit
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
109 pos -= pos % BD_UNIT_SIZE;
31848
1241f62e54e7 Return an error when seeking beyond EOF.
reimar
parents: 31847
diff changeset
110 if (fseek(bd->title_file, pos, SEEK_SET) < 0) {
1241f62e54e7 Return an error when seeking beyond EOF.
reimar
parents: 31847
diff changeset
111 s->eof = 1;
1241f62e54e7 Return an error when seeking beyond EOF.
reimar
parents: 31847
diff changeset
112 return 0;
1241f62e54e7 Return an error when seeking beyond EOF.
reimar
parents: 31847
diff changeset
113 }
1241f62e54e7 Return an error when seeking beyond EOF.
reimar
parents: 31847
diff changeset
114
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
115 bd->pos = pos;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
116 s->pos = pos;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
117
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
118 return 1;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
119 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
120
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
121 static int bd_get_uks(struct bd_priv *bd)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
122 {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
123 unsigned char *buf;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
124 size_t file_size;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
125 int pos;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
126 int i, j;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
127 struct AVAES *a;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
128 struct AVSHA *asha;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
129 FILE *file;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
130 char filename[PATH_MAX];
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
131 uint8_t discid[20];
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
132 char *home;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
133 int vukfound = 0;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
134
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
135 snprintf(filename, sizeof(filename), BD_UKF_PATH, bd->device);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
136 file = fopen(filename, "rb");
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
137 if (!file) {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
138 mp_msg(MSGT_OPEN, MSGL_ERR,
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
139 "Cannot open file %s to get UK and DiscID\n", filename);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
140 return 0;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
141 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
142 fseek(file, 0, SEEK_END);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
143 file_size = ftell(file);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
144 if (file_size > 10 * 1024* 1024) {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
145 mp_msg(MSGT_OPEN, MSGL_ERR, "File %s too large\n", filename);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
146 fclose(file);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
147 return 0;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
148 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
149 rewind(file);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
150 buf = av_malloc(file_size);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
151 fread(buf, 1, file_size, file);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
152 fclose(file);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
153
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
154 // get discid from file
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
155 asha = av_malloc(av_sha_size);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
156 av_sha_init(asha, 160);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
157 av_sha_update(asha, buf, file_size);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
158 av_sha_final(asha, discid);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
159 av_free(asha);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
160
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
161 // look up discid in KEYDB.cfg to get VUK
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
162 home = getenv("HOME");
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
163 snprintf(filename, sizeof(filename), "%s/.dvdcss/KEYDB.cfg", home);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
164 file = fopen(filename, "r");
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
165 if (!file) {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
166 mp_msg(MSGT_OPEN,MSGL_ERR,
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
167 "Cannot open VUK database file %s\n", filename);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
168 av_free(buf);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
169 return 0;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
170 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
171 while (!feof(file)) {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
172 char line[1024];
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
173 uint8_t id[20];
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
174 char d[200];
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
175 char *vst;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
176 unsigned int byte;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
177
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
178 fgets(line, sizeof(line), file);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
179 // file is built up this way:
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
180 // DISCID = title | V | VUK
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
181 // or
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
182 // DISCID = title | key-pair
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
183 // key-pair = V | VUK
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
184 // or D | Date
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
185 // or M | M-key???
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
186 // or I | I-Key
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
187 // can be followed by ; and comment
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
188
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
189 //This means: first string up to whitespace is discid
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
190 sscanf(line, "%40s", d);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
191 for (i = 0; i < 20; ++i) {
31840
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
192 if (sscanf(&d[i*2], "%2x", &byte) != 1)
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
193 break;
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
194 id[i] = byte;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
195 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
196 if (memcmp(id, discid, 20) != 0)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
197 continue;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
198 mp_msg(MSGT_OPEN, MSGL_V, "KeyDB found Entry for DiscID:\n%s\n", line);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
199
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
200 vst = strstr(line, "| V |");
31840
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
201 if (vst == 0)
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
202 break;
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
203 sscanf(&vst[6], "%32s", d);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
204 for (i = 0; i < 16; i++) {
31840
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
205 if (sscanf(&d[i*2], "%2x", &byte) != 1)
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
206 break;
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
207 bd->vuk.u8[i] = byte;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
208 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
209 vukfound = 1;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
210 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
211 fclose(file);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
212 if (!vukfound) {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
213 mp_msg(MSGT_OPEN, MSGL_ERR,
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
214 "No Volume Unique Key (VUK) found for this Disc: ");
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
215 for (j = 0; j < 20; j++) mp_msg(MSGT_OPEN, MSGL_ERR, "%02x", discid[j]);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
216 mp_msg(MSGT_OPEN, MSGL_ERR, "\n");
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
217 return 0;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
218 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
219
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
220 pos = AV_RB32(buf);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
221 if (pos < file_size) {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
222 int key_pos = pos + 48;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
223 int max_count = (file_size - key_pos - 16) / 48;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
224 bd->uks.count = AV_RB16(&buf[pos]);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
225 if (max_count < bd->uks.count) {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
226 mp_msg(MSGT_OPEN, MSGL_ERR,
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
227 "File to small for key count %i, using %i\n",
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
228 bd->uks.count, max_count);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
229 bd->uks.count = max_count;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
230 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
231 bd->uks.keys = calloc(bd->uks.count, sizeof(key));
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
232
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
233 a = av_malloc(av_aes_size);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
234 j = av_aes_init(a, bd->vuk.u8, 128, 1);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
235
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
236 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_BD_DISCID=");
31840
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
237 for (j = 0; j < 20; j++)
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
238 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "%02x", discid[j]);
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
239 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "\n");
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
240 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_BD_VUK=");
31840
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
241 for (j = 0; j < 20; j++)
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
242 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "%02x", discid[j]);
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
243 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "\n");
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
244
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
245 for (i = 0; i < bd->uks.count; i++) {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
246 av_aes_crypt(a, bd->uks.keys[i].u8, &buf[key_pos], 1, NULL, 1); // decrypt unit key
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
247 key_pos += 48;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
248 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
249
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
250 av_free(a);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
251 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
252
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
253 av_free(buf);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
254 return 1;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
255 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
256
31846
3f84ee74869d Minor optimization/simplification and document the alignment requirements
reimar
parents: 31845
diff changeset
257 // NOTE: we assume buf is sufficiently aligned to 64 bit read/writes
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
258 static off_t bd_read(struct bd_priv *bd, uint8_t *buf, int len)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
259 {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
260 int read_len;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
261 len &= ~15;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
262 if (!len)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
263 return 0;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
264
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
265 read_len = fread(buf, 1, len, bd->title_file);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
266 if (read_len != len)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
267 return -1;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
268
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
269 if (bd->pos % BD_UNIT_SIZE) {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
270 // decrypt in place
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
271 av_aes_crypt(bd->aescbc, buf, buf, len / 16, bd->iv.u8, 1);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
272 } else {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
273 // reset aes context as at start of unit
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
274 key enc_seed;
31845
678884af8ade Use the "key" type also for the IV constant.
reimar
parents: 31840
diff changeset
275 bd->iv = BD_CBC_IV;
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
276
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
277 // perform encryption of first 16 bytes of unit (seed)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
278 av_aes_crypt(bd->aeseed, enc_seed.u8, buf, 1, NULL, 0);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
279
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
280 // perform xor
31846
3f84ee74869d Minor optimization/simplification and document the alignment requirements
reimar
parents: 31845
diff changeset
281 enc_seed.u64[0] ^= AV_RN64A(buf);
3f84ee74869d Minor optimization/simplification and document the alignment requirements
reimar
parents: 31845
diff changeset
282 enc_seed.u64[1] ^= AV_RN64A(buf + 8);
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
283
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
284 // set uk AES-CBC key from enc_seed and BD_CBC_IV
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
285 av_aes_init(bd->aescbc, enc_seed.u8, 128, 1);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
286
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
287 // decrypt
31840
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
288 av_aes_crypt(bd->aescbc, &buf[16], &buf[16],
af68430bf5de whitespace cosmetics: prettyprinting, move statements to the next line.
diego
parents: 31836
diff changeset
289 (len - 16) / 16, bd->iv.u8, 1);
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
290 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
291
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
292 bd->pos += read_len;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
293
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
294 return read_len;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
295 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
296
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
297 static int bd_stream_fill_buffer(stream_t *s, char *buf, int len)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
298 {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
299 int read_len;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
300 struct bd_priv *bd = s->priv;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
301
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
302 read_len = bd_read(bd, buf, len);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
303
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
304 s->pos = bd->pos;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
305
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
306 return read_len;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
307 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
308
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
309 static int bd_stream_open(stream_t *s, int mode, void* opts, int* file_format)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
310 {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
311 char filename[PATH_MAX];
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
312
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
313 struct stream_priv_s* p = opts;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
314 struct bd_priv *bd = calloc(1, sizeof(*bd));
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
315
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
316 if (p->device)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
317 bd->device = p->device;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
318 else if (dvd_device)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
319 bd->device = dvd_device;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
320 else
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
321 bd->device = DEFAULT_BD_DEVICE;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
322
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
323 s->sector_size = BD_UNIT_SIZE;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
324 s->flags = STREAM_READ | MP_STREAM_SEEK;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
325 s->fill_buffer = bd_stream_fill_buffer;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
326 s->seek = bd_stream_seek;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
327 s->close = bd_stream_close;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
328 s->start_pos = 0;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
329 s->priv = bd;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
330 s->type = STREAMTYPE_BD;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
331 s->url = strdup("bd://");
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
332
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
333 bd->pos = 0;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
334 bd->title = p->title;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
335
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
336 // get and decrypt unit keys
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
337 if (!bd_get_uks(bd))
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
338 return STREAM_ERROR;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
339
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
340 bd->aescbc = av_malloc(av_aes_size);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
341 bd->aeseed = av_malloc(av_aes_size);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
342
31847
273d40130183 Move one AES initialization out of inner loop.
reimar
parents: 31846
diff changeset
343 // set up AES key from uk
273d40130183 Move one AES initialization out of inner loop.
reimar
parents: 31846
diff changeset
344 av_aes_init(bd->aeseed, bd->uks.keys[0].u8, 128, 0);
273d40130183 Move one AES initialization out of inner loop.
reimar
parents: 31846
diff changeset
345
31836
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
346 snprintf(filename, sizeof(filename), BD_M2TS_PATH, bd->device, bd->title);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
347 mp_msg(MSGT_OPEN, MSGL_STATUS, "Opening %s\n", filename);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
348 bd->title_file = fopen(filename, "rb");
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
349 if (!bd->title_file)
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
350 return STREAM_ERROR;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
351 fseek(bd->title_file, 0, SEEK_END);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
352 s->end_pos = ftell(bd->title_file);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
353 rewind(bd->title_file);
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
354
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
355 return STREAM_OK;
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
356 }
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
357
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
358 const stream_info_t stream_info_bd = {
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
359 "Bluray",
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
360 "bd",
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
361 "cRTrn13",
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
362 "",
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
363 bd_stream_open,
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
364 { "bd", NULL },
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
365 &stream_opts,
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
366 1
dcd515ac5f6c Add support for bd:// streams as a test for a part of the AACS algorithm.
reimar
parents:
diff changeset
367 };