annotate libmpdvdkit2/css.c @ 14952:9bd311f645b2

Small fixes.
author jonas
date Wed, 16 Mar 2005 12:49:29 +0000
parents c2ddedd0619e
children 954cdf2171f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
2 * css.c: Functions for DVD authentication and descrambling
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
3 *****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
4 * Copyright (C) 1999-2001 VideoLAN
14860
c2ddedd0619e Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents: 10720
diff changeset
5 *
c2ddedd0619e Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents: 10720
diff changeset
6 * Modified for use with MPlayer, changes contained in libdvdcss_changes.diff.
c2ddedd0619e Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents: 10720
diff changeset
7 * detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
8 * $Id$
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
9 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
10 * Author: Stéphane Borel <stef@via.ecp.fr>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
11 * Håkan Hjort <d95hjort@dtek.chalmers.se>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
12 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
13 * based on:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
14 * - css-auth by Derek Fawcus <derek@spider.com>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
15 * - DVD CSS ioctls example program by Andrew T. Veliath <andrewtv@usa.net>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
16 * - The Divide and conquer attack by Frank A. Stevenson <frank@funcom.com>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
17 * - DeCSSPlus by Ethan Hawke
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
18 * - DecVOB
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
19 * see http://www.lemuria.org/DeCSS/ by Tom Vogt for more information.
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
20 *
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
21 * This program is free software; you can redistribute it and/or modify
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
22 * it under the terms of the GNU General Public License as published by
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
23 * the Free Software Foundation; either version 2 of the License, or
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
24 * (at your option) any later version.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
25 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
26 * This program is distributed in the hope that it will be useful,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
29 * GNU General Public License for more details.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
30 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
31 * You should have received a copy of the GNU General Public License
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
32 * along with this program; if not, write to the Free Software
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
33 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
34 *****************************************************************************/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
35
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
36 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
37 * Preamble
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
38 *****************************************************************************/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
39 #include "config.h"
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
40
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
41 #include <stdio.h>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
42 #include <stdlib.h>
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
43 #include <string.h>
7032
fd2d4be9ed6f applying css-key cache patch
arpi
parents: 7027
diff changeset
44 #include <sys/types.h>
fd2d4be9ed6f applying css-key cache patch
arpi
parents: 7027
diff changeset
45 #include <sys/stat.h>
fd2d4be9ed6f applying css-key cache patch
arpi
parents: 7027
diff changeset
46 #include <fcntl.h>
8637
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
47 #include <unistd.h>
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
48 #include <limits.h>
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
49
7033
596919e4f601 apply mplayer-specific patches
arpi
parents: 7032
diff changeset
50 #include "dvdcss.h"
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
51
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
52 #include "common.h"
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
53 #include "css.h"
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
54 #include "libdvdcss.h"
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
55 #include "csstables.h"
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
56 #include "ioctl.h"
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
57 #include "device.h"
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
58
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
59 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
60 * Local prototypes
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
61 *****************************************************************************/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
62 static int GetBusKey ( dvdcss_t );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
63 static int GetASF ( dvdcss_t );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
64
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
65 static void CryptKey ( int, int, uint8_t const *, uint8_t * );
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
66 static void DecryptKey ( uint8_t,
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
67 uint8_t const *, uint8_t const *, uint8_t * );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
68
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
69 static int DecryptDiscKey ( uint8_t const *, dvd_key_t );
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
70 static int CrackDiscKey ( dvdcss_t, uint8_t * );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
71
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
72 static void DecryptTitleKey ( dvd_key_t, dvd_key_t );
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
73 static int RecoverTitleKey ( int, uint8_t const *,
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
74 uint8_t const *, uint8_t const *, uint8_t * );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
75 static int CrackTitleKey ( dvdcss_t, int, int, dvd_key_t );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
76
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
77 static int AttackPattern ( uint8_t const[], int, uint8_t * );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
78 #if 0
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
79 static int AttackPadding ( uint8_t const[], int, uint8_t * );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
80 #endif
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
81
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
82 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
83 * _dvdcss_test: check if the disc is encrypted or not
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
84 *****************************************************************************/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
85 int _dvdcss_test( dvdcss_t dvdcss )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
86 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
87 int i_ret, i_copyright;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
88
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
89 i_ret = ioctl_ReadCopyright( dvdcss->i_fd, 0 /* i_layer */, &i_copyright );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
90
8637
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
91 #ifdef WIN32
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
92 if( i_ret < 0 )
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
93 {
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
94 /* Maybe we didn't have enough priviledges to read the copyright
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
95 * (see ioctl_ReadCopyright comments).
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
96 * Apparently, on unencrypted DVDs _dvdcss_disckey() always fails, so
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
97 * we can check this as a work-around. */
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
98 i_ret = 0;
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
99 if( _dvdcss_disckey( dvdcss ) < 0 )
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
100 i_copyright = 0;
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
101 else
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
102 i_copyright = 1;
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
103 }
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
104 #endif
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
105
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
106 if( i_ret < 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
107 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
108 /* Since it's the first ioctl we try to issue, we add a notice */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
109 _dvdcss_error( dvdcss, "css error: ioctl_ReadCopyright failed, "
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
110 "make sure there is a DVD in the drive, and that "
8637
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
111 "you have used the correct device node." );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
112
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
113 return i_ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
114 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
115
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
116 return i_copyright;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
117 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
118
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
119 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
120 * GetBusKey : Go through the CSS Authentication process
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
121 *****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
122 * It simulates the mutual authentication between logical unit and host,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
123 * and stops when a session key (called bus key) has been established.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
124 * Always do the full auth sequence. Some drives seem to lie and always
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
125 * respond with ASF=1. For instance the old DVD roms on Compaq Armada says
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
126 * that ASF=1 from the start and then later fail with a 'read of scrambled
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
127 * block without authentication' error.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
128 *****************************************************************************/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
129 static int GetBusKey( dvdcss_t dvdcss )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
130 {
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
131 uint8_t p_buffer[10];
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
132 uint8_t p_challenge[2*KEY_SIZE];
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
133 dvd_key_t p_key1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
134 dvd_key_t p_key2;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
135 dvd_key_t p_key_check;
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
136 uint8_t i_variant = 0;
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
137 char psz_warning[80];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
138 int i_ret = -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
139 int i;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
140
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
141 _dvdcss_debug( dvdcss, "requesting AGID" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
142 i_ret = ioctl_ReportAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
143
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
144 /* We might have to reset hung authentication processes in the drive
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
145 by invalidating the corresponding AGID'. As long as we haven't got
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
146 an AGID, invalidate one (in sequence) and try again. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
147 for( i = 0; i_ret == -1 && i < 4 ; ++i )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
148 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
149 sprintf( psz_warning,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
150 "ioctl ReportAgid failed, invalidating AGID %d", i );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
151 _dvdcss_debug( dvdcss, psz_warning );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
152
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
153 /* This is really _not good_, should be handled by the OS.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
154 Invalidating an AGID could make another process fail some
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
155 where in it's authentication process. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
156 dvdcss->css.i_agid = i;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
157 ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
158
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
159 _dvdcss_debug( dvdcss, "requesting AGID" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
160 i_ret = ioctl_ReportAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
161 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
162
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
163 /* Unable to authenticate without AGID */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
164 if( i_ret == -1 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
165 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
166 _dvdcss_error( dvdcss, "ioctl ReportAgid failed, fatal" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
167 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
168 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
169
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
170 /* Setup a challenge, any values should work */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
171 for( i = 0 ; i < 10; ++i )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
172 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
173 p_challenge[i] = i;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
174 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
175
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
176 /* Get challenge from host */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
177 for( i = 0 ; i < 10 ; ++i )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
178 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
179 p_buffer[9-i] = p_challenge[i];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
180 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
181
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
182 /* Send challenge to LU */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
183 if( ioctl_SendChallenge( dvdcss->i_fd,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
184 &dvdcss->css.i_agid, p_buffer ) < 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
185 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
186 _dvdcss_error( dvdcss, "ioctl SendChallenge failed" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
187 ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
188 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
189 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
190
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
191 /* Get key1 from LU */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
192 if( ioctl_ReportKey1( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
193 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
194 _dvdcss_error( dvdcss, "ioctl ReportKey1 failed" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
195 ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
196 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
197 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
198
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
199 /* Send key1 to host */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
200 for( i = 0 ; i < KEY_SIZE ; i++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
201 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
202 p_key1[i] = p_buffer[4-i];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
203 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
204
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
205 for( i = 0 ; i < 32 ; ++i )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
206 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
207 CryptKey( 0, i, p_challenge, p_key_check );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
208
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
209 if( memcmp( p_key_check, p_key1, KEY_SIZE ) == 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
210 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
211 snprintf( psz_warning, sizeof(psz_warning),
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
212 "drive authenticated, using variant %d", i );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
213 _dvdcss_debug( dvdcss, psz_warning );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
214 i_variant = i;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
215 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
216 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
217 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
218
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
219 if( i == 32 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
220 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
221 _dvdcss_error( dvdcss, "drive would not authenticate" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
222 ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
223 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
224 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
225
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
226 /* Get challenge from LU */
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
227 if( ioctl_ReportChallenge( dvdcss->i_fd,
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
228 &dvdcss->css.i_agid, p_buffer ) < 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
229 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
230 _dvdcss_error( dvdcss, "ioctl ReportKeyChallenge failed" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
231 ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
232 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
233 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
234
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
235 /* Send challenge to host */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
236 for( i = 0 ; i < 10 ; ++i )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
237 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
238 p_challenge[i] = p_buffer[9-i];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
239 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
240
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
241 CryptKey( 1, i_variant, p_challenge, p_key2 );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
242
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
243 /* Get key2 from host */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
244 for( i = 0 ; i < KEY_SIZE ; ++i )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
245 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
246 p_buffer[4-i] = p_key2[i];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
247 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
248
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
249 /* Send key2 to LU */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
250 if( ioctl_SendKey2( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
251 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
252 _dvdcss_error( dvdcss, "ioctl SendKey2 failed" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
253 ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
254 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
255 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
256
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
257 /* The drive has accepted us as authentic. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
258 _dvdcss_debug( dvdcss, "authentication established" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
259
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
260 memcpy( p_challenge, p_key1, KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
261 memcpy( p_challenge + KEY_SIZE, p_key2, KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
262
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
263 CryptKey( 2, i_variant, p_challenge, dvdcss->css.p_bus_key );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
264
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
265 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
266 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
267
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
268 /*****************************************************************************
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
269 * PrintKey : debug function that dumps a key value
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
270 *****************************************************************************/
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
271 static void PrintKey( dvdcss_t dvdcss, char *prefix, uint8_t const *data )
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
272 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
273 char psz_output[80];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
274
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
275 sprintf( psz_output, "%s%02x:%02x:%02x:%02x:%02x", prefix,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
276 data[0], data[1], data[2], data[3], data[4] );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
277 _dvdcss_debug( dvdcss, psz_output );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
278 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
279
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
280 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
281 * _dvdcss_title: crack or decrypt the current title key if needed
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
282 *****************************************************************************
8637
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
283 * This function should only be called by dvdcss->pf_seek and should eventually
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
284 * not be external if possible.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
285 *****************************************************************************/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
286 int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
287 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
288 dvd_title_t *p_title;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
289 dvd_title_t *p_newtitle;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
290 dvd_key_t p_title_key;
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
291 int i_fd, i_ret = -1, b_cache = 0;
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
292
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
293 if( ! dvdcss->b_scrambled )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
294 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
295 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
296 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
297
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
298 /* Check if we've already cracked this key */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
299 p_title = dvdcss->p_titles;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
300 while( p_title != NULL
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
301 && p_title->p_next != NULL
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
302 && p_title->p_next->i_startlb <= i_block )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
303 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
304 p_title = p_title->p_next;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
305 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
306
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
307 if( p_title != NULL
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
308 && p_title->i_startlb == i_block )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
309 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
310 /* We've already cracked this key, nothing to do */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
311 memcpy( dvdcss->css.p_title_key, p_title->p_key, sizeof(dvd_key_t) );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
312 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
313 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
314
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
315 /* Check whether the key is in our disk cache */
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
316 if( dvdcss->psz_cachefile[0] )
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
317 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
318 /* XXX: be careful, we use sprintf and not snprintf */
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
319 sprintf( dvdcss->psz_block, "%.10x", i_block );
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
320 i_fd = open( dvdcss->psz_cachefile, O_RDONLY );
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
321 b_cache = 1;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
322
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
323 if( i_fd >= 0 )
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
324 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
325 if( read( i_fd, p_title_key, 5 ) == 5 )
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
326 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
327 _dvdcss_debug( dvdcss, "key found in cache" );
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
328 /* Don't try to save it again */
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
329 b_cache = 0;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
330 i_ret = 1;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
331 }
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
332 close( i_fd );
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
333 }
7032
fd2d4be9ed6f applying css-key cache patch
arpi
parents: 7027
diff changeset
334 }
fd2d4be9ed6f applying css-key cache patch
arpi
parents: 7027
diff changeset
335
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
336 /* Crack or decrypt CSS title key for current VTS */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
337 if( i_ret < 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
338 {
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
339 i_ret = _dvdcss_titlekey( dvdcss, i_block, p_title_key );
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
340
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
341 if( i_ret < 0 )
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
342 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
343 _dvdcss_error( dvdcss, "fatal error in vts css key" );
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
344 return i_ret;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
345 }
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
346
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
347 if( i_ret == 0 )
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
348 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
349 _dvdcss_debug( dvdcss, "unencrypted title" );
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
350 /* We cache this anyway, so we don't need to check again. */
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
351 }
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
352 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
353
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
354 /* Key is valid, we store it on disk. */
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
355 if( b_cache )
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
356 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
357 i_fd = open( dvdcss->psz_cachefile, O_RDWR|O_CREAT|O_EXCL, 0644 );
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
358 if( i_fd >= 0 )
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
359 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
360 write( i_fd, p_title_key, 5 );
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
361 close( i_fd );
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
362 }
7032
fd2d4be9ed6f applying css-key cache patch
arpi
parents: 7027
diff changeset
363 }
fd2d4be9ed6f applying css-key cache patch
arpi
parents: 7027
diff changeset
364
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
365 /* Find our spot in the list */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
366 p_newtitle = NULL;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
367 p_title = dvdcss->p_titles;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
368 while( ( p_title != NULL ) && ( p_title->i_startlb < i_block ) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
369 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
370 p_newtitle = p_title;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
371 p_title = p_title->p_next;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
372 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
373
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
374 /* Save the found title */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
375 p_title = p_newtitle;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
376
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
377 /* Write in the new title and its key */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
378 p_newtitle = malloc( sizeof( dvd_title_t ) );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
379 p_newtitle->i_startlb = i_block;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
380 memcpy( p_newtitle->p_key, p_title_key, KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
381
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
382 /* Link it at the head of the (possibly empty) list */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
383 if( p_title == NULL )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
384 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
385 p_newtitle->p_next = dvdcss->p_titles;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
386 dvdcss->p_titles = p_newtitle;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
387 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
388 /* Link the new title inside the list */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
389 else
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
390 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
391 p_newtitle->p_next = p_title->p_next;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
392 p_title->p_next = p_newtitle;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
393 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
394
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
395 memcpy( dvdcss->css.p_title_key, p_title_key, KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
396 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
397 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
398
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
399 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
400 * _dvdcss_disckey: get disc key.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
401 *****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
402 * This function should only be called if DVD ioctls are present.
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
403 * It will set dvdcss->i_method = DVDCSS_METHOD_TITLE if it fails to find
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
404 * a valid disc key.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
405 * Two decryption methods are offered:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
406 * -disc key hash crack,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
407 * -decryption with player keys if they are available.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
408 *****************************************************************************/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
409 int _dvdcss_disckey( dvdcss_t dvdcss )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
410 {
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
411 unsigned char p_buffer[ DVD_DISCKEY_SIZE ];
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
412 dvd_key_t p_disc_key;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
413 int i;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
414
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
415 if( GetBusKey( dvdcss ) < 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
416 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
417 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
418 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
419
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
420 /* Get encrypted disc key */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
421 if( ioctl_ReadDiscKey( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
422 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
423 _dvdcss_error( dvdcss, "ioctl ReadDiscKey failed" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
424 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
425 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
426
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
427 /* This should have invaidated the AGID and got us ASF=1. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
428 if( GetASF( dvdcss ) != 1 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
429 {
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
430 /* Region mismatch (or region not set) is the most likely source. */
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
431 _dvdcss_error( dvdcss,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
432 "ASF not 1 after reading disc key (region mismatch?)" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
433 ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
434 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
435 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
436
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
437 /* Decrypt disc key using bus key */
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
438 for( i = 0 ; i < DVD_DISCKEY_SIZE ; i++ )
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
439 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
440 p_buffer[ i ] ^= dvdcss->css.p_bus_key[ 4 - (i % KEY_SIZE) ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
441 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
442
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
443 switch( dvdcss->i_method )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
444 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
445 case DVDCSS_METHOD_KEY:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
446
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
447 /* Decrypt disc key with player key. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
448 _dvdcss_debug( dvdcss, "decrypting disc key with player keys" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
449 if( ! DecryptDiscKey( p_buffer, p_disc_key ) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
450 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
451 PrintKey( dvdcss, "decrypted disc key is ", p_disc_key );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
452 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
453 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
454 _dvdcss_debug( dvdcss, "failed to decrypt the disc key, "
8637
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
455 "faulty drive/kernel? "
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
456 "cracking title keys instead" );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
457
8637
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
458 /* Fallback, but not to DISC as the disc key might be faulty */
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
459 dvdcss->i_method = DVDCSS_METHOD_TITLE;
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
460 break;
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
461
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
462 case DVDCSS_METHOD_DISC:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
463
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
464 /* Crack Disc key to be able to use it */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
465 _dvdcss_debug( dvdcss, "cracking disc key from key hash ..."
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
466 " this will take some time" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
467 memcpy( p_disc_key, p_buffer, KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
468 if( ! CrackDiscKey( dvdcss, p_disc_key ) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
469 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
470 PrintKey( dvdcss, "cracked disc key is ", p_disc_key );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
471 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
472 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
473 _dvdcss_debug( dvdcss, "failed to crack the disc key" );
8637
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
474 memset( p_disc_key, 0, KEY_SIZE );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
475 dvdcss->i_method = DVDCSS_METHOD_TITLE;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
476 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
477
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
478 default:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
479
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
480 _dvdcss_debug( dvdcss, "disc key needs not be decrypted" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
481 memset( p_disc_key, 0, KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
482 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
483 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
484
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
485 memcpy( dvdcss->css.p_disc_key, p_disc_key, KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
486
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
487 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
488 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
489
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
490
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
491 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
492 * _dvdcss_titlekey: get title key.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
493 *****************************************************************************/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
494 int _dvdcss_titlekey( dvdcss_t dvdcss, int i_pos, dvd_key_t p_title_key )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
495 {
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
496 static uint8_t p_garbage[ DVDCSS_BLOCK_SIZE ]; /* we never read it back */
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
497 uint8_t p_key[ KEY_SIZE ];
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
498 int i, i_ret = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
499
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
500 if( dvdcss->b_ioctls && ( dvdcss->i_method == DVDCSS_METHOD_KEY ||
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
501 dvdcss->i_method == DVDCSS_METHOD_DISC ) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
502 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
503 /* We have a decrypted Disc key and the ioctls are available,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
504 * read the title key and decrypt it.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
505 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
506
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
507 _dvdcss_debug( dvdcss, "getting title key the classic way" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
508
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
509 /* We need to authenticate again every time to get a new session key */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
510 if( GetBusKey( dvdcss ) < 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
511 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
512 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
513 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
514
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
515 /* Get encrypted title key */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
516 if( ioctl_ReadTitleKey( dvdcss->i_fd, &dvdcss->css.i_agid,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
517 i_pos, p_key ) < 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
518 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
519 _dvdcss_debug( dvdcss,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
520 "ioctl ReadTitleKey failed (region mismatch?)" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
521 i_ret = -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
522 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
523
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
524 /* Test ASF, it will be reset to 0 if we got a Region error */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
525 switch( GetASF( dvdcss ) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
526 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
527 case -1:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
528 /* An error getting the ASF status, something must be wrong. */
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
529 _dvdcss_debug( dvdcss, "lost ASF requesting title key" );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
530 ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
531 i_ret = -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
532 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
533
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
534 case 0:
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
535 /* This might either be a title that has no key,
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
536 * or we encountered a region error. */
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
537 _dvdcss_debug( dvdcss, "lost ASF requesting title key" );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
538 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
539
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
540 case 1:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
541 /* Drive status is ok. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
542 /* If the title key request failed, but we did not loose ASF,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
543 * we might stil have the AGID. Other code assume that we
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
544 * will not after this so invalidate it(?). */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
545 if( i_ret < 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
546 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
547 ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
548 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
549 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
550 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
551
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
552 if( !( i_ret < 0 ) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
553 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
554 /* Decrypt title key using the bus key */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
555 for( i = 0 ; i < KEY_SIZE ; i++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
556 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
557 p_key[ i ] ^= dvdcss->css.p_bus_key[ 4 - (i % KEY_SIZE) ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
558 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
559
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
560 /* If p_key is all zero then there really wasn't any key present
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
561 * even though we got to read it without an error. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
562 if( !( p_key[0] | p_key[1] | p_key[2] | p_key[3] | p_key[4] ) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
563 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
564 i_ret = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
565 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
566 else
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
567 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
568 DecryptTitleKey( dvdcss->css.p_disc_key, p_key );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
569 i_ret = 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
570 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
571
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
572 /* All went well either there wasn't a key or we have it now. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
573 memcpy( p_title_key, p_key, KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
574 PrintKey( dvdcss, "title key is ", p_title_key );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
575
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
576 return i_ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
577 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
578
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
579 /* The title key request failed */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
580 _dvdcss_debug( dvdcss, "resetting drive and cracking title key" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
581
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
582 /* Read an unscrambled sector and reset the drive */
8637
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
583 dvdcss->pf_seek( dvdcss, 0 );
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
584 dvdcss->pf_read( dvdcss, p_garbage, 1 );
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
585 dvdcss->pf_seek( dvdcss, 0 );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
586 _dvdcss_disckey( dvdcss );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
587
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
588 /* Fallback */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
589 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
590
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
591 /* METHOD is TITLE, we can't use the ioctls or requesting the title key
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
592 * failed above. For these cases we try to crack the key instead. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
593
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
594 /* For now, the read limit is 9Gb / 2048 = 4718592 sectors. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
595 i_ret = CrackTitleKey( dvdcss, i_pos, 4718592, p_key );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
596
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
597 memcpy( p_title_key, p_key, KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
598 PrintKey( dvdcss, "title key is ", p_title_key );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
599
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
600 return i_ret;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
601 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
602
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
603 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
604 * _dvdcss_unscramble: does the actual descrambling of data
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
605 *****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
606 * sec : sector to unscramble
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
607 * key : title key for this sector
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
608 *****************************************************************************/
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
609 int _dvdcss_unscramble( dvd_key_t p_key, uint8_t *p_sec )
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
610 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
611 unsigned int i_t1, i_t2, i_t3, i_t4, i_t5, i_t6;
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
612 uint8_t *p_end = p_sec + DVDCSS_BLOCK_SIZE;
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
613
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
614 /* PES_scrambling_control */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
615 if( p_sec[0x14] & 0x30)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
616 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
617 i_t1 = (p_key[0] ^ p_sec[0x54]) | 0x100;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
618 i_t2 = p_key[1] ^ p_sec[0x55];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
619 i_t3 = (p_key[2] | (p_key[3] << 8) |
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
620 (p_key[4] << 16)) ^ (p_sec[0x56] |
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
621 (p_sec[0x57] << 8) | (p_sec[0x58] << 16));
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
622 i_t4 = i_t3 & 7;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
623 i_t3 = i_t3 * 2 + 8 - i_t4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
624 p_sec += 0x80;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
625 i_t5 = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
626
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
627 while( p_sec != p_end )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
628 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
629 i_t4 = p_css_tab2[i_t2] ^ p_css_tab3[i_t1];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
630 i_t2 = i_t1>>1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
631 i_t1 = ( ( i_t1 & 1 ) << 8 ) ^ i_t4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
632 i_t4 = p_css_tab5[i_t4];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
633 i_t6 = ((((((( i_t3 >> 3 ) ^ i_t3 ) >> 1 ) ^
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
634 i_t3 ) >> 8 ) ^ i_t3 ) >> 5 ) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
635 i_t3 = (i_t3 << 8 ) | i_t6;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
636 i_t6 = p_css_tab4[i_t6];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
637 i_t5 += i_t6 + i_t4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
638 *p_sec = p_css_tab1[*p_sec] ^ ( i_t5 & 0xff );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
639 p_sec++;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
640 i_t5 >>= 8;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
641 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
642 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
643
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
644 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
645 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
646
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
647 /* Following functions are local */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
648
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
649 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
650 * GetASF : Get Authentication success flag
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
651 *****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
652 * Returns :
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
653 * -1 on ioctl error,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
654 * 0 if the device needs to be authenticated,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
655 * 1 either.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
656 *****************************************************************************/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
657 static int GetASF( dvdcss_t dvdcss )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
658 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
659 int i_asf = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
660
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
661 if( ioctl_ReportASF( dvdcss->i_fd, NULL, &i_asf ) != 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
662 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
663 /* The ioctl process has failed */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
664 _dvdcss_error( dvdcss, "GetASF fatal error" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
665 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
666 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
667
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
668 if( i_asf )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
669 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
670 _dvdcss_debug( dvdcss, "GetASF authenticated, ASF=1" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
671 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
672 else
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
673 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
674 _dvdcss_debug( dvdcss, "GetASF not authenticated, ASF=0" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
675 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
676
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
677 return i_asf;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
678 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
679
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
680 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
681 * CryptKey : shuffles bits and unencrypt keys.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
682 *****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
683 * Used during authentication and disc key negociation in GetBusKey.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
684 * i_key_type : 0->key1, 1->key2, 2->buskey.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
685 * i_variant : between 0 and 31.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
686 *****************************************************************************/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
687 static void CryptKey( int i_key_type, int i_variant,
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
688 uint8_t const *p_challenge, uint8_t *p_key )
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
689 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
690 /* Permutation table for challenge */
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
691 uint8_t pp_perm_challenge[3][10] =
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
692 { { 1, 3, 0, 7, 5, 2, 9, 6, 4, 8 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
693 { 6, 1, 9, 3, 8, 5, 7, 4, 0, 2 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
694 { 4, 0, 3, 5, 7, 2, 8, 6, 1, 9 } };
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
695
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
696 /* Permutation table for variant table for key2 and buskey */
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
697 uint8_t pp_perm_variant[2][32] =
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
698 { { 0x0a, 0x08, 0x0e, 0x0c, 0x0b, 0x09, 0x0f, 0x0d,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
699 0x1a, 0x18, 0x1e, 0x1c, 0x1b, 0x19, 0x1f, 0x1d,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
700 0x02, 0x00, 0x06, 0x04, 0x03, 0x01, 0x07, 0x05,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
701 0x12, 0x10, 0x16, 0x14, 0x13, 0x11, 0x17, 0x15 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
702 { 0x12, 0x1a, 0x16, 0x1e, 0x02, 0x0a, 0x06, 0x0e,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
703 0x10, 0x18, 0x14, 0x1c, 0x00, 0x08, 0x04, 0x0c,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
704 0x13, 0x1b, 0x17, 0x1f, 0x03, 0x0b, 0x07, 0x0f,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
705 0x11, 0x19, 0x15, 0x1d, 0x01, 0x09, 0x05, 0x0d } };
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
706
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
707 uint8_t p_variants[32] =
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
708 { 0xB7, 0x74, 0x85, 0xD0, 0xCC, 0xDB, 0xCA, 0x73,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
709 0x03, 0xFE, 0x31, 0x03, 0x52, 0xE0, 0xB7, 0x42,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
710 0x63, 0x16, 0xF2, 0x2A, 0x79, 0x52, 0xFF, 0x1B,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
711 0x7A, 0x11, 0xCA, 0x1A, 0x9B, 0x40, 0xAD, 0x01 };
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
712
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
713 /* The "secret" key */
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
714 uint8_t p_secret[5] = { 0x55, 0xD6, 0xC4, 0xC5, 0x28 };
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
715
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
716 uint8_t p_bits[30], p_scratch[10], p_tmp1[5], p_tmp2[5];
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
717 uint8_t i_lfsr0_o; /* 1 bit used */
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
718 uint8_t i_lfsr1_o; /* 1 bit used */
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
719 uint8_t i_css_variant, i_cse, i_index, i_combined, i_carry;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
720 uint8_t i_val = 0;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
721 uint32_t i_lfsr0, i_lfsr1;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
722 int i_term = 0;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
723 int i_bit;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
724 int i;
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
725
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
726 for (i = 9; i >= 0; --i)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
727 p_scratch[i] = p_challenge[pp_perm_challenge[i_key_type][i]];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
728
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
729 i_css_variant = ( i_key_type == 0 ) ? i_variant :
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
730 pp_perm_variant[i_key_type-1][i_variant];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
731
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
732 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
733 * This encryption engine implements one of 32 variations
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
734 * one the same theme depending upon the choice in the
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
735 * variant parameter (0 - 31).
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
736 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
737 * The algorithm itself manipulates a 40 bit input into
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
738 * a 40 bit output.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
739 * The parameter 'input' is 80 bits. It consists of
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
740 * the 40 bit input value that is to be encrypted followed
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
741 * by a 40 bit seed value for the pseudo random number
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
742 * generators.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
743 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
744
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
745 /* Feed the secret into the input values such that
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
746 * we alter the seed to the LFSR's used above, then
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
747 * generate the bits to play with.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
748 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
749 for( i = 5 ; --i >= 0 ; )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
750 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
751 p_tmp1[i] = p_scratch[5 + i] ^ p_secret[i] ^ p_crypt_tab2[i];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
752 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
753
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
754 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
755 * We use two LFSR's (seeded from some of the input data bytes) to
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
756 * generate two streams of pseudo-random bits. These two bit streams
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
757 * are then combined by simply adding with carry to generate a final
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
758 * sequence of pseudo-random bits which is stored in the buffer that
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
759 * 'output' points to the end of - len is the size of this buffer.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
760 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
761 * The first LFSR is of degree 25, and has a polynomial of:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
762 * x^13 + x^5 + x^4 + x^1 + 1
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
763 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
764 * The second LSFR is of degree 17, and has a (primitive) polynomial of:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
765 * x^15 + x^1 + 1
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
766 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
767 * I don't know if these polynomials are primitive modulo 2, and thus
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
768 * represent maximal-period LFSR's.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
769 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
770 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
771 * Note that we take the output of each LFSR from the new shifted in
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
772 * bit, not the old shifted out bit. Thus for ease of use the LFSR's
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
773 * are implemented in bit reversed order.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
774 *
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
775 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
776
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
777 /* In order to ensure that the LFSR works we need to ensure that the
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
778 * initial values are non-zero. Thus when we initialise them from
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
779 * the seed, we ensure that a bit is set.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
780 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
781 i_lfsr0 = ( p_tmp1[0] << 17 ) | ( p_tmp1[1] << 9 ) |
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
782 (( p_tmp1[2] & ~7 ) << 1 ) | 8 | ( p_tmp1[2] & 7 );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
783 i_lfsr1 = ( p_tmp1[3] << 9 ) | 0x100 | p_tmp1[4];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
784
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
785 i_index = sizeof(p_bits);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
786 i_carry = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
787
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
788 do
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
789 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
790 for( i_bit = 0, i_val = 0 ; i_bit < 8 ; ++i_bit )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
791 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
792
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
793 i_lfsr0_o = ( ( i_lfsr0 >> 24 ) ^ ( i_lfsr0 >> 21 ) ^
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
794 ( i_lfsr0 >> 20 ) ^ ( i_lfsr0 >> 12 ) ) & 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
795 i_lfsr0 = ( i_lfsr0 << 1 ) | i_lfsr0_o;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
796
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
797 i_lfsr1_o = ( ( i_lfsr1 >> 16 ) ^ ( i_lfsr1 >> 2 ) ) & 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
798 i_lfsr1 = ( i_lfsr1 << 1 ) | i_lfsr1_o;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
799
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
800 i_combined = !i_lfsr1_o + i_carry + !i_lfsr0_o;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
801 /* taking bit 1 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
802 i_carry = ( i_combined >> 1 ) & 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
803 i_val |= ( i_combined & 1 ) << i_bit;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
804 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
805
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
806 p_bits[--i_index] = i_val;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
807 } while( i_index > 0 );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
808
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
809 /* This term is used throughout the following to
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
810 * select one of 32 different variations on the
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
811 * algorithm.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
812 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
813 i_cse = p_variants[i_css_variant] ^ p_crypt_tab2[i_css_variant];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
814
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
815 /* Now the actual blocks doing the encryption. Each
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
816 * of these works on 40 bits at a time and are quite
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
817 * similar.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
818 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
819 i_index = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
820 for( i = 5, i_term = 0 ; --i >= 0 ; i_term = p_scratch[i] )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
821 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
822 i_index = p_bits[25 + i] ^ p_scratch[i];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
823 i_index = p_crypt_tab1[i_index] ^ ~p_crypt_tab2[i_index] ^ i_cse;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
824
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
825 p_tmp1[i] = p_crypt_tab2[i_index] ^ p_crypt_tab3[i_index] ^ i_term;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
826 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
827 p_tmp1[4] ^= p_tmp1[0];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
828
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
829 for( i = 5, i_term = 0 ; --i >= 0 ; i_term = p_tmp1[i] )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
830 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
831 i_index = p_bits[20 + i] ^ p_tmp1[i];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
832 i_index = p_crypt_tab1[i_index] ^ ~p_crypt_tab2[i_index] ^ i_cse;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
833
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
834 p_tmp2[i] = p_crypt_tab2[i_index] ^ p_crypt_tab3[i_index] ^ i_term;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
835 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
836 p_tmp2[4] ^= p_tmp2[0];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
837
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
838 for( i = 5, i_term = 0 ; --i >= 0 ; i_term = p_tmp2[i] )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
839 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
840 i_index = p_bits[15 + i] ^ p_tmp2[i];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
841 i_index = p_crypt_tab1[i_index] ^ ~p_crypt_tab2[i_index] ^ i_cse;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
842 i_index = p_crypt_tab2[i_index] ^ p_crypt_tab3[i_index] ^ i_term;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
843
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
844 p_tmp1[i] = p_crypt_tab0[i_index] ^ p_crypt_tab2[i_index];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
845 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
846 p_tmp1[4] ^= p_tmp1[0];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
847
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
848 for( i = 5, i_term = 0 ; --i >= 0 ; i_term = p_tmp1[i] )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
849 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
850 i_index = p_bits[10 + i] ^ p_tmp1[i];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
851 i_index = p_crypt_tab1[i_index] ^ ~p_crypt_tab2[i_index] ^ i_cse;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
852
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
853 i_index = p_crypt_tab2[i_index] ^ p_crypt_tab3[i_index] ^ i_term;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
854
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
855 p_tmp2[i] = p_crypt_tab0[i_index] ^ p_crypt_tab2[i_index];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
856 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
857 p_tmp2[4] ^= p_tmp2[0];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
858
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
859 for( i = 5, i_term = 0 ; --i >= 0 ; i_term = p_tmp2[i] )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
860 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
861 i_index = p_bits[5 + i] ^ p_tmp2[i];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
862 i_index = p_crypt_tab1[i_index] ^ ~p_crypt_tab2[i_index] ^ i_cse;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
863
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
864 p_tmp1[i] = p_crypt_tab2[i_index] ^ p_crypt_tab3[i_index] ^ i_term;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
865 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
866 p_tmp1[4] ^= p_tmp1[0];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
867
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
868 for(i = 5, i_term = 0 ; --i >= 0 ; i_term = p_tmp1[i] )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
869 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
870 i_index = p_bits[i] ^ p_tmp1[i];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
871 i_index = p_crypt_tab1[i_index] ^ ~p_crypt_tab2[i_index] ^ i_cse;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
872
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
873 p_key[i] = p_crypt_tab2[i_index] ^ p_crypt_tab3[i_index] ^ i_term;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
874 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
875
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
876 return;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
877 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
878
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
879 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
880 * DecryptKey: decrypt p_crypted with p_key.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
881 *****************************************************************************
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
882 * Used to decrypt the disc key, with a player key, after requesting it
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
883 * in _dvdcss_disckey and to decrypt title keys, with a disc key, requested
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
884 * in _dvdcss_titlekey.
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
885 * The player keys and the resulting disc key are only used as KEKs
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
886 * (key encryption keys).
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
887 * Decryption is slightly dependant on the type of key:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
888 * -for disc key, invert is 0x00,
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
889 * -for title key, invert if 0xff.
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
890 *****************************************************************************/
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
891 static void DecryptKey( uint8_t invert, uint8_t const *p_key,
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
892 uint8_t const *p_crypted, uint8_t *p_result )
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
893 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
894 unsigned int i_lfsr1_lo;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
895 unsigned int i_lfsr1_hi;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
896 unsigned int i_lfsr0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
897 unsigned int i_combined;
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
898 uint8_t o_lfsr0;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
899 uint8_t o_lfsr1;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
900 uint8_t k[5];
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
901 int i;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
902
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
903 i_lfsr1_lo = p_key[0] | 0x100;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
904 i_lfsr1_hi = p_key[1];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
905
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
906 i_lfsr0 = ( ( p_key[4] << 17 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
907 | ( p_key[3] << 9 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
908 | ( p_key[2] << 1 ) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
909 + 8 - ( p_key[2] & 7 );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
910 i_lfsr0 = ( p_css_tab4[i_lfsr0 & 0xff] << 24 ) |
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
911 ( p_css_tab4[( i_lfsr0 >> 8 ) & 0xff] << 16 ) |
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
912 ( p_css_tab4[( i_lfsr0 >> 16 ) & 0xff] << 8 ) |
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
913 p_css_tab4[( i_lfsr0 >> 24 ) & 0xff];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
914
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
915 i_combined = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
916 for( i = 0 ; i < KEY_SIZE ; ++i )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
917 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
918 o_lfsr1 = p_css_tab2[i_lfsr1_hi] ^ p_css_tab3[i_lfsr1_lo];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
919 i_lfsr1_hi = i_lfsr1_lo >> 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
920 i_lfsr1_lo = ( ( i_lfsr1_lo & 1 ) << 8 ) ^ o_lfsr1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
921 o_lfsr1 = p_css_tab4[o_lfsr1];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
922
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
923 o_lfsr0 = ((((((( i_lfsr0 >> 8 ) ^ i_lfsr0 ) >> 1 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
924 ^ i_lfsr0 ) >> 3 ) ^ i_lfsr0 ) >> 7 );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
925 i_lfsr0 = ( i_lfsr0 >> 8 ) | ( o_lfsr0 << 24 );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
926
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
927 i_combined += ( o_lfsr0 ^ invert ) + o_lfsr1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
928 k[i] = i_combined & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
929 i_combined >>= 8;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
930 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
931
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
932 p_result[4] = k[4] ^ p_css_tab1[p_crypted[4]] ^ p_crypted[3];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
933 p_result[3] = k[3] ^ p_css_tab1[p_crypted[3]] ^ p_crypted[2];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
934 p_result[2] = k[2] ^ p_css_tab1[p_crypted[2]] ^ p_crypted[1];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
935 p_result[1] = k[1] ^ p_css_tab1[p_crypted[1]] ^ p_crypted[0];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
936 p_result[0] = k[0] ^ p_css_tab1[p_crypted[0]] ^ p_result[4];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
937
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
938 p_result[4] = k[4] ^ p_css_tab1[p_result[4]] ^ p_result[3];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
939 p_result[3] = k[3] ^ p_css_tab1[p_result[3]] ^ p_result[2];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
940 p_result[2] = k[2] ^ p_css_tab1[p_result[2]] ^ p_result[1];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
941 p_result[1] = k[1] ^ p_css_tab1[p_result[1]] ^ p_result[0];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
942 p_result[0] = k[0] ^ p_css_tab1[p_result[0]];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
943
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
944 return;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
945 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
946
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
947 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
948 * DecryptDiscKey
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
949 *****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
950 * Decryption of the disc key with player keys if they are available.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
951 * Try to decrypt the disc key from every position with every player key.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
952 * p_struct_disckey: the 2048 byte DVD_STRUCT_DISCKEY data
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
953 * p_disc_key: result, the 5 byte disc key
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
954 *****************************************************************************/
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
955 static int DecryptDiscKey( uint8_t const *p_struct_disckey,
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
956 dvd_key_t p_disc_key )
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
957 {
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
958 uint8_t p_verify[KEY_SIZE];
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
959 unsigned int i, n = 0;
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
960
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
961 static const dvd_key_t player_keys[] =
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
962 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
963 { 0x01, 0xaf, 0xe3, 0x12, 0x80 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
964 { 0x12, 0x11, 0xca, 0x04, 0x3b },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
965 { 0x14, 0x0c, 0x9e, 0xd0, 0x09 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
966 { 0x14, 0x71, 0x35, 0xba, 0xe2 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
967 { 0x1a, 0xa4, 0x33, 0x21, 0xa6 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
968 { 0x26, 0xec, 0xc4, 0xa7, 0x4e },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
969 { 0x2c, 0xb2, 0xc1, 0x09, 0xee },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
970 { 0x2f, 0x25, 0x9e, 0x96, 0xdd },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
971 { 0x33, 0x2f, 0x49, 0x6c, 0xe0 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
972 { 0x35, 0x5b, 0xc1, 0x31, 0x0f },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
973 { 0x36, 0x67, 0xb2, 0xe3, 0x85 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
974 { 0x39, 0x3d, 0xf1, 0xf1, 0xbd },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
975 { 0x3b, 0x31, 0x34, 0x0d, 0x91 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
976 { 0x45, 0xed, 0x28, 0xeb, 0xd3 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
977 { 0x48, 0xb7, 0x6c, 0xce, 0x69 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
978 { 0x4b, 0x65, 0x0d, 0xc1, 0xee },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
979 { 0x4c, 0xbb, 0xf5, 0x5b, 0x23 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
980 { 0x51, 0x67, 0x67, 0xc5, 0xe0 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
981 { 0x53, 0x94, 0xe1, 0x75, 0xbf },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
982 { 0x57, 0x2c, 0x8b, 0x31, 0xae },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
983 { 0x63, 0xdb, 0x4c, 0x5b, 0x4a },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
984 { 0x7b, 0x1e, 0x5e, 0x2b, 0x57 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
985 { 0x85, 0xf3, 0x85, 0xa0, 0xe0 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
986 { 0xab, 0x1e, 0xe7, 0x7b, 0x72 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
987 { 0xab, 0x36, 0xe3, 0xeb, 0x76 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
988 { 0xb1, 0xb8, 0xf9, 0x38, 0x03 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
989 { 0xb8, 0x5d, 0xd8, 0x53, 0xbd },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
990 { 0xbf, 0x92, 0xc3, 0xb0, 0xe2 },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
991 { 0xcf, 0x1a, 0xb2, 0xf8, 0x0a },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
992 { 0xec, 0xa0, 0xcf, 0xb3, 0xff },
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
993 { 0xfc, 0x95, 0xa9, 0x87, 0x35 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
994 };
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
995
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
996 /* Decrypt disc key with the above player keys */
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
997 while( n < sizeof(player_keys) / sizeof(dvd_key_t) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
998 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
999 for( i = 1; i < 409; i++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1000 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1001 /* Check if player key n is the right key for position i. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1002 DecryptKey( 0, player_keys[n], p_struct_disckey + 5 * i,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1003 p_disc_key );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1004
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1005 /* The first part in the struct_disckey block is the
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1006 * 'disc key' encrypted with itself. Using this we
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1007 * can check if we decrypted the correct key. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1008 DecryptKey( 0, p_disc_key, p_struct_disckey, p_verify );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1009
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1010 /* If the position / player key pair worked then return. */
8637
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
1011 if( memcmp( p_disc_key, p_verify, KEY_SIZE ) == 0 )
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1012 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1013 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1014 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1015 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1016 n++;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1017 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1018
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1019 /* Have tried all combinations of positions and keys,
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1020 * and we still didn't succeed. */
8637
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
1021 memset( p_disc_key, 0, KEY_SIZE );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1022 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1023 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1024
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1025 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1026 * DecryptTitleKey
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1027 *****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1028 * Decrypt the title key using the disc key.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1029 * p_disc_key: result, the 5 byte disc key
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1030 * p_titlekey: the encrypted title key, gets overwritten by the decrypted key
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1031 *****************************************************************************/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1032 static void DecryptTitleKey( dvd_key_t p_disc_key, dvd_key_t p_titlekey )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1033 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1034 DecryptKey( 0xff, p_disc_key, p_titlekey, p_titlekey );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1035 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1036
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1037 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1038 * CrackDiscKey: brute force disc key
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1039 * CSS hash reversal function designed by Frank Stevenson
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1040 *****************************************************************************
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1041 * This function uses a big amount of memory to crack the disc key from the
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1042 * disc key hash, if player keys are not available.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1043 *****************************************************************************/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1044 #define K1TABLEWIDTH 10
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1045
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1046 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1047 * Simple function to test if a candidate key produces the given hash
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1048 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1049 static int investigate( unsigned char *hash, unsigned char *ckey )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1050 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1051 unsigned char key[KEY_SIZE];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1052
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1053 DecryptKey( 0, ckey, hash, key );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1054
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1055 return memcmp( key, ckey, KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1056 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1057
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1058 static int CrackDiscKey( dvdcss_t dvdcss, uint8_t *p_disc_key )
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1059 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1060 unsigned char B[5] = { 0,0,0,0,0 }; /* Second Stage of mangle cipher */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1061 unsigned char C[5] = { 0,0,0,0,0 }; /* Output Stage of mangle cipher
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1062 * IntermediateKey */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1063 unsigned char k[5] = { 0,0,0,0,0 }; /* Mangling cipher key
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1064 * Also output from CSS( C ) */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1065 unsigned char out1[5]; /* five first output bytes of LFSR1 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1066 unsigned char out2[5]; /* five first output bytes of LFSR2 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1067 unsigned int lfsr1a; /* upper 9 bits of LFSR1 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1068 unsigned int lfsr1b; /* lower 8 bits of LFSR1 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1069 unsigned int tmp, tmp2, tmp3, tmp4,tmp5;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1070 int i,j;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1071 unsigned int nStepA; /* iterator for LFSR1 start state */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1072 unsigned int nStepB; /* iterator for possible B[0] */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1073 unsigned int nTry; /* iterator for K[1] possibilities */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1074 unsigned int nPossibleK1; /* #of possible K[1] values */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1075 unsigned char* K1table; /* Lookup table for possible K[1] */
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1076 unsigned int* BigTable; /* LFSR2 startstate indexed by
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1077 * 1,2,5 output byte */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1078
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1079 _dvdcss_debug( dvdcss, "cracking disc key" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1080
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1081 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1082 * Prepare tables for hash reversal
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1083 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1084
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1085
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1086 /* initialize lookup tables for k[1] */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1087 K1table = malloc( 65536 * K1TABLEWIDTH );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1088 memset( K1table, 0 , 65536 * K1TABLEWIDTH );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1089 if( K1table == NULL )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1090 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1091 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1092 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1093
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1094 tmp = p_disc_key[0] ^ p_css_tab1[ p_disc_key[1] ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1095 for( i = 0 ; i < 256 ; i++ ) /* k[1] */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1096 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1097 tmp2 = p_css_tab1[ tmp ^ i ]; /* p_css_tab1[ B[1] ]*/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1098
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1099 for( j = 0 ; j < 256 ; j++ ) /* B[0] */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1100 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1101 tmp3 = j ^ tmp2 ^ i; /* C[1] */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1102 tmp4 = K1table[ K1TABLEWIDTH * ( 256 * j + tmp3 ) ]; /* count of entries here */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1103 tmp4++;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1104 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1105 if( tmp4 == K1TABLEWIDTH )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1106 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1107 _dvdcss_debug( dvdcss, "Table disaster %d", tmp4 );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1108 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1109 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1110 if( tmp4 < K1TABLEWIDTH )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1111 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1112 K1table[ K1TABLEWIDTH * ( 256 * j + tmp3 ) + tmp4 ] = i;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1113 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1114 K1table[ K1TABLEWIDTH * ( 256 * j + tmp3 ) ] = tmp4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1115 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1116 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1117
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1118 /* Initing our Really big table */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1119 BigTable = malloc( 16777216 * sizeof(int) );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1120 memset( BigTable, 0 , 16777216 * sizeof(int) );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1121 if( BigTable == NULL )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1122 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1123 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1124 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1125
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1126 tmp3 = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1127
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1128 _dvdcss_debug( dvdcss, "initializing the big table" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1129
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1130 for( i = 0 ; i < 16777216 ; i++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1131 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1132 tmp = (( i + i ) & 0x1fffff0 ) | 0x8 | ( i & 0x7 );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1133
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1134 for( j = 0 ; j < 5 ; j++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1135 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1136 tmp2=((((((( tmp >> 3 ) ^ tmp ) >> 1 ) ^ tmp ) >> 8 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1137 ^ tmp ) >> 5 ) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1138 tmp = ( tmp << 8) | tmp2;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1139 out2[j] = p_css_tab4[ tmp2 ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1140 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1141
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1142 j = ( out2[0] << 16 ) | ( out2[1] << 8 ) | out2[4];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1143 BigTable[j] = i;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1144 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1145
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1146 /*
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1147 * We are done initing, now reverse hash
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1148 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1149 tmp5 = p_disc_key[0] ^ p_css_tab1[ p_disc_key[1] ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1150
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1151 for( nStepA = 0 ; nStepA < 65536 ; nStepA ++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1152 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1153 lfsr1a = 0x100 | ( nStepA >> 8 );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1154 lfsr1b = nStepA & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1155
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1156 /* Generate 5 first output bytes from lfsr1 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1157 for( i = 0 ; i < 5 ; i++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1158 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1159 tmp = p_css_tab2[ lfsr1b ] ^ p_css_tab3[ lfsr1a ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1160 lfsr1b = lfsr1a >> 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1161 lfsr1a = ((lfsr1a&1)<<8) ^ tmp;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1162 out1[ i ] = p_css_tab4[ tmp ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1163 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1164
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1165 /* cumpute and cache some variables */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1166 C[0] = nStepA >> 8;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1167 C[1] = nStepA & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1168 tmp = p_disc_key[3] ^ p_css_tab1[ p_disc_key[4] ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1169 tmp2 = p_css_tab1[ p_disc_key[0] ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1170
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1171 /* Search through all possible B[0] */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1172 for( nStepB = 0 ; nStepB < 256 ; nStepB++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1173 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1174 /* reverse parts of the mangling cipher */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1175 B[0] = nStepB;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1176 k[0] = p_css_tab1[ B[0] ] ^ C[0];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1177 B[4] = B[0] ^ k[0] ^ tmp2;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1178 k[4] = B[4] ^ tmp;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1179 nPossibleK1 = K1table[ K1TABLEWIDTH * (256 * B[0] + C[1]) ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1180
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1181 /* Try out all possible values for k[1] */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1182 for( nTry = 0 ; nTry < nPossibleK1 ; nTry++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1183 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1184 k[1] = K1table[ K1TABLEWIDTH * (256 * B[0] + C[1]) + nTry + 1 ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1185 B[1] = tmp5 ^ k[1];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1186
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1187 /* reconstruct output from LFSR2 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1188 tmp3 = ( 0x100 + k[0] - out1[0] );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1189 out2[0] = tmp3 & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1190 tmp3 = tmp3 & 0x100 ? 0x100 : 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1191 tmp3 = ( tmp3 + k[1] - out1[1] );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1192 out2[1] = tmp3 & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1193 tmp3 = ( 0x100 + k[4] - out1[4] );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1194 out2[4] = tmp3 & 0xff; /* Can be 1 off */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1195
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1196 /* test first possible out2[4] */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1197 tmp4 = ( out2[0] << 16 ) | ( out2[1] << 8 ) | out2[4];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1198 tmp4 = BigTable[ tmp4 ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1199 C[2] = tmp4 & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1200 C[3] = ( tmp4 >> 8 ) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1201 C[4] = ( tmp4 >> 16 ) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1202 B[3] = p_css_tab1[ B[4] ] ^ k[4] ^ C[4];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1203 k[3] = p_disc_key[2] ^ p_css_tab1[ p_disc_key[3] ] ^ B[3];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1204 B[2] = p_css_tab1[ B[3] ] ^ k[3] ^ C[3];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1205 k[2] = p_disc_key[1] ^ p_css_tab1[ p_disc_key[2] ] ^ B[2];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1206
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1207 if( ( B[1] ^ p_css_tab1[ B[2] ] ^ k[ 2 ] ) == C[ 2 ] )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1208 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1209 if( ! investigate( &p_disc_key[0] , &C[0] ) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1210 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1211 goto end;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1212 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1213 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1214
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1215 /* Test second possible out2[4] */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1216 out2[4] = ( out2[4] + 0xff ) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1217 tmp4 = ( out2[0] << 16 ) | ( out2[1] << 8 ) | out2[4];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1218 tmp4 = BigTable[ tmp4 ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1219 C[2] = tmp4 & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1220 C[3] = ( tmp4 >> 8 ) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1221 C[4] = ( tmp4 >> 16 ) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1222 B[3] = p_css_tab1[ B[4] ] ^ k[4] ^ C[4];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1223 k[3] = p_disc_key[2] ^ p_css_tab1[ p_disc_key[3] ] ^ B[3];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1224 B[2] = p_css_tab1[ B[3] ] ^ k[3] ^ C[3];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1225 k[2] = p_disc_key[1] ^ p_css_tab1[ p_disc_key[2] ] ^ B[2];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1226
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1227 if( ( B[1] ^ p_css_tab1[ B[2] ] ^ k[ 2 ] ) == C[ 2 ] )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1228 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1229 if( ! investigate( &p_disc_key[0] , &C[0] ) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1230 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1231 goto end;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1232 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1233 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1234 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1235 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1236 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1237
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1238 end:
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1239
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1240 memcpy( p_disc_key, &C[0], KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1241
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1242 free( K1table );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1243 free( BigTable );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1244
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1245 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1246 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1247
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1248 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1249 * RecoverTitleKey: (title) key recovery from cipher and plain text
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1250 * Function designed by Frank Stevenson
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1251 *****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1252 * Called from Attack* which are in turn called by CrackTitleKey. Given
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1253 * a guessed(?) plain text and the cipher text. Returns -1 on failure.
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1254 *****************************************************************************/
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1255 static int RecoverTitleKey( int i_start, uint8_t const *p_crypted,
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1256 uint8_t const *p_decrypted,
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1257 uint8_t const *p_sector_seed, uint8_t *p_key )
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1258 {
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1259 uint8_t p_buffer[10];
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1260 unsigned int i_t1, i_t2, i_t3, i_t4, i_t5, i_t6;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1261 unsigned int i_try;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1262 unsigned int i_candidate;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1263 unsigned int i, j;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1264 int i_exit = -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1265
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1266 for( i = 0 ; i < 10 ; i++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1267 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1268 p_buffer[i] = p_css_tab1[p_crypted[i]] ^ p_decrypted[i];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1269 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1270
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1271 for( i_try = i_start ; i_try < 0x10000 ; i_try++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1272 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1273 i_t1 = i_try >> 8 | 0x100;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1274 i_t2 = i_try & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1275 i_t3 = 0; /* not needed */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1276 i_t5 = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1277
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1278 /* iterate cipher 4 times to reconstruct LFSR2 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1279 for( i = 0 ; i < 4 ; i++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1280 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1281 /* advance LFSR1 normaly */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1282 i_t4 = p_css_tab2[i_t2] ^ p_css_tab3[i_t1];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1283 i_t2 = i_t1 >> 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1284 i_t1 = ( ( i_t1 & 1 ) << 8 ) ^ i_t4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1285 i_t4 = p_css_tab5[i_t4];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1286 /* deduce i_t6 & i_t5 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1287 i_t6 = p_buffer[i];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1288 if( i_t5 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1289 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1290 i_t6 = ( i_t6 + 0xff ) & 0x0ff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1291 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1292 if( i_t6 < i_t4 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1293 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1294 i_t6 += 0x100;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1295 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1296 i_t6 -= i_t4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1297 i_t5 += i_t6 + i_t4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1298 i_t6 = p_css_tab4[ i_t6 ];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1299 /* feed / advance i_t3 / i_t5 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1300 i_t3 = ( i_t3 << 8 ) | i_t6;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1301 i_t5 >>= 8;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1302 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1303
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1304 i_candidate = i_t3;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1305
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1306 /* iterate 6 more times to validate candidate key */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1307 for( ; i < 10 ; i++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1308 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1309 i_t4 = p_css_tab2[i_t2] ^ p_css_tab3[i_t1];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1310 i_t2 = i_t1 >> 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1311 i_t1 = ( ( i_t1 & 1 ) << 8 ) ^ i_t4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1312 i_t4 = p_css_tab5[i_t4];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1313 i_t6 = ((((((( i_t3 >> 3 ) ^ i_t3 ) >> 1 ) ^
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1314 i_t3 ) >> 8 ) ^ i_t3 ) >> 5 ) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1315 i_t3 = ( i_t3 << 8 ) | i_t6;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1316 i_t6 = p_css_tab4[i_t6];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1317 i_t5 += i_t6 + i_t4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1318 if( ( i_t5 & 0xff ) != p_buffer[i] )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1319 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1320 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1321 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1322
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1323 i_t5 >>= 8;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1324 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1325
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1326 if( i == 10 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1327 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1328 /* Do 4 backwards steps of iterating t3 to deduce initial state */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1329 i_t3 = i_candidate;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1330 for( i = 0 ; i < 4 ; i++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1331 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1332 i_t1 = i_t3 & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1333 i_t3 = ( i_t3 >> 8 );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1334 /* easy to code, and fast enough bruteforce
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1335 * search for byte shifted in */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1336 for( j = 0 ; j < 256 ; j++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1337 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1338 i_t3 = ( i_t3 & 0x1ffff ) | ( j << 17 );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1339 i_t6 = ((((((( i_t3 >> 3 ) ^ i_t3 ) >> 1 ) ^
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1340 i_t3 ) >> 8 ) ^ i_t3 ) >> 5 ) & 0xff;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1341 if( i_t6 == i_t1 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1342 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1343 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1344 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1345 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1346 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1347
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1348 i_t4 = ( i_t3 >> 1 ) - 4;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1349 for( i_t5 = 0 ; i_t5 < 8; i_t5++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1350 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1351 if( ( ( i_t4 + i_t5 ) * 2 + 8 - ( (i_t4 + i_t5 ) & 7 ) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1352 == i_t3 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1353 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1354 p_key[0] = i_try>>8;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1355 p_key[1] = i_try & 0xFF;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1356 p_key[2] = ( ( i_t4 + i_t5 ) >> 0 ) & 0xFF;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1357 p_key[3] = ( ( i_t4 + i_t5 ) >> 8 ) & 0xFF;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1358 p_key[4] = ( ( i_t4 + i_t5 ) >> 16 ) & 0xFF;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1359 i_exit = i_try + 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1360 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1361 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1362 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1363 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1364
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1365 if( i_exit >= 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1366 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1367 p_key[0] ^= p_sector_seed[0];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1368 p_key[1] ^= p_sector_seed[1];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1369 p_key[2] ^= p_sector_seed[2];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1370 p_key[3] ^= p_sector_seed[3];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1371 p_key[4] ^= p_sector_seed[4];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1372 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1373
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1374 return i_exit;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1375 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1376
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1377
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1378 /******************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1379 * Various pices for the title crack engine.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1380 ******************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1381 * The length of the PES packet is located at 0x12-0x13.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1382 * The the copyrigth protection bits are located at 0x14 (bits 0x20 and 0x10).
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1383 * The data of the PES packet begins at 0x15 (if there isn't any PTS/DTS)
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1384 * or at 0x?? if there are both PTS and DTS's.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1385 * The seed value used with the unscrambling key is the 5 bytes at 0x54-0x58.
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1386 * The scrabled part of a sector begins at 0x80.
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1387 *****************************************************************************/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1388
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1389 /* Statistics */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1390 static int i_tries = 0, i_success = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1391
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1392 /*****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1393 * CrackTitleKey: try to crack title key from the contents of a VOB.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1394 *****************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1395 * This function is called by _dvdcss_titlekey to find a title key, if we've
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1396 * chosen to crack title key instead of decrypting it with the disc key.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1397 * The DVD should have been opened and be in an authenticated state.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1398 * i_pos is the starting sector, i_len is the maximum number of sectors to read
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1399 *****************************************************************************/
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1400 static int CrackTitleKey( dvdcss_t dvdcss, int i_pos, int i_len,
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1401 dvd_key_t p_titlekey )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1402 {
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1403 uint8_t p_buf[ DVDCSS_BLOCK_SIZE ];
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1404 const uint8_t p_packstart[4] = { 0x00, 0x00, 0x01, 0xba };
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1405 int i_reads = 0;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1406 int i_encrypted = 0;
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1407 int b_stop_scanning = 0;
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1408 int b_read_error = 0;
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1409 int i_ret;
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1410
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1411 _dvdcss_debug( dvdcss, "cracking title key" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1412
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1413 i_tries = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1414 i_success = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1415
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1416 do
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1417 {
8637
0211de3039eb update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents: 8123
diff changeset
1418 i_ret = dvdcss->pf_seek( dvdcss, i_pos );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1419
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1420 if( i_ret != i_pos )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1421 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1422 _dvdcss_error( dvdcss, "seek failed" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1423 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1424
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1425 i_ret = dvdcss_read( dvdcss, p_buf, 1, DVDCSS_NOFLAGS );
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1426
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1427 /* Either we are at the end of the physical device or the auth
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1428 * have failed / were not done and we got a read error. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1429 if( i_ret <= 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1430 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1431 if( i_ret == 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1432 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1433 _dvdcss_debug( dvdcss, "read returned 0 (end of device?)" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1434 }
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1435 else if( !b_read_error )
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1436 {
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1437 _dvdcss_debug( dvdcss, "read error, resorting to secret "
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1438 "arcanes to recover" );
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1439
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1440 /* Reset the drive before trying to continue */
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1441 _dvdcss_close( dvdcss );
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1442 _dvdcss_open( dvdcss );
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1443
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1444 b_read_error = 1;
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1445 continue;
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1446 }
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1447 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1448 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1449
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1450 /* Stop when we find a non MPEG stream block.
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1451 * (We must have reached the end of the stream).
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1452 * For now, allow all blocks that begin with a start code. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1453 if( memcmp( p_buf, p_packstart, 3 ) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1454 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1455 _dvdcss_debug( dvdcss, "non MPEG block found (end of title)" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1456 break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1457 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1458
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1459 if( p_buf[0x0d] & 0x07 )
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1460 _dvdcss_debug( dvdcss, "stuffing in pack header" );
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1461
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1462 /* PES_scrambling_control does not exist in a system_header,
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1463 * a padding_stream or a private_stream2 (and others?). */
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1464 if( p_buf[0x14] & 0x30 && ! ( p_buf[0x11] == 0xbb
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1465 || p_buf[0x11] == 0xbe
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1466 || p_buf[0x11] == 0xbf ) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1467 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1468 i_encrypted++;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1469
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1470 if( AttackPattern(p_buf, i_reads, p_titlekey) > 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1471 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1472 b_stop_scanning = 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1473 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1474 #if 0
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1475 if( AttackPadding(p_buf, i_reads, p_titlekey) > 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1476 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1477 b_stop_scanning = 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1478 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1479 #endif
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1480 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1481
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1482 i_pos++;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1483 i_len--;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1484 i_reads++;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1485
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1486 /* Emit a progress indication now and then. */
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1487 if( !( i_reads & 0xfff ) )
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1488 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1489 _dvdcss_debug( dvdcss, "still cracking..." );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1490 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1491
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1492 /* Stop after 2000 blocks if we haven't seen any encrypted blocks. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1493 if( i_reads >= 2000 && i_encrypted == 0 ) break;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1494
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1495 } while( !b_stop_scanning && i_len > 0);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1496
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1497 if( !b_stop_scanning )
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1498 {
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1499 _dvdcss_debug( dvdcss, "end of title reached" );
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1500 }
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1501
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1502 { /* Print some statistics. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1503 char psz_info[128];
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1504 snprintf( psz_info, sizeof(psz_info),
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1505 "%d of %d attempts successful, %d of %d blocks scrambled",
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1506 i_success, i_tries, i_encrypted, i_reads );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1507 _dvdcss_debug( dvdcss, psz_info );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1508 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1509
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1510 if( i_success > 0 /* b_stop_scanning */ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1511 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1512 _dvdcss_debug( dvdcss, "vts key initialized" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1513 return 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1514 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1515
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1516 if( i_encrypted == 0 && i_reads > 0 )
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1517 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1518 memset( p_titlekey, 0, KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1519 _dvdcss_debug( dvdcss, "file was unscrambled" );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1520 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1521 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1522
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1523 memset( p_titlekey, 0, KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1524 return -1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1525 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1526
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1527
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1528 /******************************************************************************
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1529 * The original Ethan Hawke (DeCSSPlus) attack (modified).
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1530 ******************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1531 * Tries to find a repeating pattern just before the encrypted part starts.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1532 * Then it guesses that the plain text for first encrypted bytes are
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1533 * a contiuation of that pattern.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1534 *****************************************************************************/
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1535 static int AttackPattern( uint8_t const p_sec[ DVDCSS_BLOCK_SIZE ],
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1536 int i_pos, uint8_t *p_key )
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1537 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1538 unsigned int i_best_plen = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1539 unsigned int i_best_p = 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1540 unsigned int i, j;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1541
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1542 /* For all cycle length from 2 to 48 */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1543 for( i = 2 ; i < 0x30 ; i++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1544 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1545 /* Find the number of bytes that repeats in cycles. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1546 for( j = i + 1;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1547 j < 0x80 && ( p_sec[0x7F - (j%i)] == p_sec[0x7F - j] );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1548 j++ )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1549 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1550 /* We have found j repeating bytes with a cycle length i. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1551 if( j > i_best_plen )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1552 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1553 i_best_plen = j;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1554 i_best_p = i;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1555 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1556 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1557 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1558
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1559 /* We need at most 10 plain text bytes?, so a make sure that we
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1560 * have at least 20 repeated bytes and that they have cycled at
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1561 * least one time. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1562 if( ( i_best_plen > 3 ) && ( i_best_plen / i_best_p >= 2) )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1563 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1564 int res;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1565
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1566 i_tries++;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1567 memset( p_key, 0, KEY_SIZE );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1568 res = RecoverTitleKey( 0, &p_sec[0x80],
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1569 &p_sec[ 0x80 - (i_best_plen / i_best_p) * i_best_p ],
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1570 &p_sec[0x54] /* key_seed */, p_key );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1571 i_success += ( res >= 0 );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1572 #if 0
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1573 if( res >= 0 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1574 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1575 fprintf( stderr, "key is %02x:%02x:%02x:%02x:%02x ",
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1576 p_key[0], p_key[1], p_key[2], p_key[3], p_key[4] );
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1577 fprintf( stderr, "at block %5d pattern len %3d period %3d %s\n",
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1578 i_pos, i_best_plen, i_best_p, (res>=0?"y":"n") );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1579 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1580 #endif
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1581 return ( res >= 0 );
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1582 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1583
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1584 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1585 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1586
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1587
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1588 #if 0
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1589 /******************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1590 * Encrypted Padding_stream attack.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1591 ******************************************************************************
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1592 * DVD specifies that there must only be one type of data in every sector.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1593 * Every sector is one pack and so must obviously be 2048 bytes long.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1594 * For the last pice of video data before a VOBU boundary there might not
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1595 * be exactly the right amount of data to fill a sector. Then one has to
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1596 * pad the pack to 2048 bytes. For just a few bytes this is done in the
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1597 * header but for any large amount you insert a PES packet from the
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1598 * Padding stream. This looks like 0x00 00 01 be xx xx ff ff ...
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1599 * where xx xx is the length of the padding stream.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1600 *****************************************************************************/
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1601 static int AttackPadding( uint8_t const p_sec[ DVDCSS_BLOCK_SIZE ],
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1602 int i_pos, uint8_t *p_key )
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1603 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1604 unsigned int i_pes_length;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1605 /*static int i_tries = 0, i_success = 0;*/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1606
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1607 i_pes_length = (p_sec[0x12]<<8) | p_sec[0x13];
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1608
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1609 /* Coverd by the test below but usfull for debuging. */
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1610 if( i_pes_length == DVDCSS_BLOCK_SIZE - 0x14 ) return 0;
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1611
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1612 /* There must be room for at least 4? bytes of padding stream,
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1613 * and it must be encrypted.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1614 * sector size - pack/pes header - padding startcode - padding length */
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1615 if( ( DVDCSS_BLOCK_SIZE - 0x14 - 4 - 2 - i_pes_length < 4 ) ||
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1616 ( p_sec[0x14 + i_pes_length + 0] == 0x00 &&
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1617 p_sec[0x14 + i_pes_length + 1] == 0x00 &&
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1618 p_sec[0x14 + i_pes_length + 2] == 0x01 ) )
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1619 {
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1620 fprintf( stderr, "plain %d %02x:%02x:%02x:%02x (type %02x sub %02x)\n",
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1621 DVDCSS_BLOCK_SIZE - 0x14 - 4 - 2 - i_pes_length,
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1622 p_sec[0x14 + i_pes_length + 0],
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1623 p_sec[0x14 + i_pes_length + 1],
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1624 p_sec[0x14 + i_pes_length + 2],
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1625 p_sec[0x14 + i_pes_length + 3],
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1626 p_sec[0x11], p_sec[0x17 + p_sec[0x16]]);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1627 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1628 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1629
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1630 /* If we are here we know that there is a where in the pack a
10720
f23c35ce0d16 synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents: 9333
diff changeset
1631 encrypted PES header is (startcode + length). It's never more
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1632 than two packets in the pack, so we 'know' the length. The
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1633 plaintext at offset (0x14 + i_pes_length) will then be
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1634 00 00 01 e0/bd/be xx xx, in the case of be the following bytes
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1635 are also known. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1636
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1637 /* An encrypted SPU PES packet with another encrypted PES packet following.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1638 Normaly if the following was a padding stream that would be in plain
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1639 text. So it will be another SPU PES packet. */
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1640 if( p_sec[0x11] == 0xbd &&
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1641 p_sec[0x17 + p_sec[0x16]] >= 0x20 &&
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1642 p_sec[0x17 + p_sec[0x16]] <= 0x3f )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1643 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1644 i_tries++;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1645 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1646
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1647 /* A Video PES packet with another encrypted PES packet following.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1648 * No reason execpt for time stamps to break the data into two packets.
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1649 * So it's likely that the following PES packet is a padding stream. */
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1650 if( p_sec[0x11] == 0xe0 )
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1651 {
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1652 i_tries++;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1653 }
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1654
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1655 if( 1 )
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1656 {
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1657 /*fprintf( stderr, "key is %02x:%02x:%02x:%02x:%02x ",
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1658 p_key[0], p_key[1], p_key[2], p_key[3], p_key[4] );*/
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1659 fprintf( stderr, "at block %5d padding len %4d "
9333
f0f0f176d298 sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents: 8637
diff changeset
1660 "type %02x sub %02x\n", i_pos, i_pes_length,
7027
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1661 p_sec[0x11], p_sec[0x17 + p_sec[0x16]]);
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1662 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1663
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1664 return 0;
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1665 }
c9a4dfaa9868 importing libdvdcss 1.2.2 files
arpi
parents:
diff changeset
1666 #endif