css.c 57.9 KB
Newer Older
Sam Hocevar's avatar
 
Sam Hocevar committed
1
/*****************************************************************************
2
 * css.c: Functions for DVD authentication and descrambling
Sam Hocevar's avatar
 
Sam Hocevar committed
3
 *****************************************************************************
4
 * Copyright (C) 1999-2003 VideoLAN
Sam Hocevar's avatar
Sam Hocevar committed
5
 * $Id$
Sam Hocevar's avatar
 
Sam Hocevar committed
6
 *
7
8
 * Authors: Stphane Borel <stef@via.ecp.fr>
 *          Hkan Hjort <d95hjort@dtek.chalmers.se>
Sam Hocevar's avatar
 
Sam Hocevar committed
9
10
11
12
13
 *
 * based on:
 *  - css-auth by Derek Fawcus <derek@spider.com>
 *  - DVD CSS ioctls example program by Andrew T. Veliath <andrewtv@usa.net>
 *  - The Divide and conquer attack by Frank A. Stevenson <frank@funcom.com>
14
 *     (see http://www-2.cs.cmu.edu/~dst/DeCSS/FrankStevenson/index.html)
Sam Hocevar's avatar
 
Sam Hocevar committed
15
16
17
 *  - DeCSSPlus by Ethan Hawke
 *  - DecVOB
 *  see http://www.lemuria.org/DeCSS/ by Tom Vogt for more information.
18
 *
Sam Hocevar's avatar
 
Sam Hocevar committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
42
43
#include <sys/types.h>
#include <sys/stat.h>
44
45
46
#ifdef HAVE_SYS_PARAM_H
#   include <sys/param.h>
#endif
47
48
49
#ifdef HAVE_UNISTD_H
#   include <unistd.h>
#endif
50
#include <fcntl.h>
Sam Hocevar's avatar
 
Sam Hocevar committed
51

52
#ifdef HAVE_LIMITS_H
53
54
55
#   include <limits.h>
#endif

Sam Hocevar's avatar
   
Sam Hocevar committed
56
#include "dvdcss/dvdcss.h"
Sam Hocevar's avatar
 
Sam Hocevar committed
57
58
59
60
61
62

#include "common.h"
#include "css.h"
#include "libdvdcss.h"
#include "csstables.h"
#include "ioctl.h"
63
#include "device.h"
Sam Hocevar's avatar
 
Sam Hocevar committed
64
65
66
67

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
68
69
static void PrintKey        ( dvdcss_t, char *, uint8_t const * );

70
71
static int  GetBusKey       ( dvdcss_t );
static int  GetASF          ( dvdcss_t );
72

73
74
75
static void CryptKey        ( int, int, uint8_t const *, uint8_t * );
static void DecryptKey      ( uint8_t,
                              uint8_t const *, uint8_t const *, uint8_t * );
76

77
static int  DecryptDiscKey  ( dvdcss_t, uint8_t const *, dvd_key_t );
78
static int  CrackDiscKey    ( dvdcss_t, uint8_t * );
79
80

static void DecryptTitleKey ( dvd_key_t, dvd_key_t );
81
82
static int  RecoverTitleKey ( int, uint8_t const *,
                              uint8_t const *, uint8_t const *, uint8_t * );
83
static int  CrackTitleKey   ( dvdcss_t, int, int, dvd_key_t );
84

85
static int  AttackPattern   ( uint8_t const[], int, uint8_t * );
86
#if 0
87
static int  AttackPadding   ( uint8_t const[], int, uint8_t * );
88
#endif
Sam Hocevar's avatar
 
Sam Hocevar committed
89
90

/*****************************************************************************
91
 * _dvdcss_test: check if the disc is encrypted or not
Sam Hocevar's avatar
 
Sam Hocevar committed
92
 *****************************************************************************/
93
int _dvdcss_test( dvdcss_t dvdcss )
Sam Hocevar's avatar
 
Sam Hocevar committed
94
95
96
97
98
{
    int i_ret, i_copyright;

    i_ret = ioctl_ReadCopyright( dvdcss->i_fd, 0 /* i_layer */, &i_copyright );

gbazin's avatar
   
gbazin committed
99
100
101
#ifdef WIN32
    if( i_ret < 0 )
    {
102
        /* Maybe we didn't have enough privileges to read the copyright
gbazin's avatar
   
gbazin committed
103
104
         * (see ioctl_ReadCopyright comments).
         * Apparently, on unencrypted DVDs _dvdcss_disckey() always fails, so
105
         * we can check this as a workaround. */
gbazin's avatar
   
gbazin committed
106
        i_ret = 0;
107
        i_copyright = 1;
gbazin's avatar
   
gbazin committed
108
        if( _dvdcss_disckey( dvdcss ) < 0 )
109
        {
gbazin's avatar
   
gbazin committed
110
            i_copyright = 0;
111
        }
gbazin's avatar
   
gbazin committed
112
113
114
    }
#endif

Sam Hocevar's avatar
 
Sam Hocevar committed
115
116
117
    if( i_ret < 0 )
    {
        /* Since it's the first ioctl we try to issue, we add a notice */
118
119
120
        print_error( dvdcss, "css error: ioctl_ReadCopyright failed, "
                     "make sure there is a DVD in the drive, and that "
                     "you have used the correct device node." );
Sam Hocevar's avatar
 
Sam Hocevar committed
121
122
123
124
125
126
127
128

        return i_ret;
    }

    return i_copyright;
}

/*****************************************************************************
129
130
 * _dvdcss_title: crack or decrypt the current title key if needed
 *****************************************************************************
131
 * This function should only be called by dvdcss->pf_seek and should eventually
132
133
 * not be external if possible.
 *****************************************************************************/
134
int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
135
136
137
138
{
    dvd_title_t *p_title;
    dvd_title_t *p_newtitle;
    dvd_key_t    p_title_key;
139
    int          i_fd, i_ret = -1, b_cache = 0;
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

    if( ! dvdcss->b_scrambled )
    {
        return 0;
    }

    /* Check if we've already cracked this key */
    p_title = dvdcss->p_titles;
    while( p_title != NULL
            && p_title->p_next != NULL
            && p_title->p_next->i_startlb <= i_block )
    {
        p_title = p_title->p_next;
    }

    if( p_title != NULL
         && p_title->i_startlb == i_block )
    {
        /* We've already cracked this key, nothing to do */
        memcpy( dvdcss->css.p_title_key, p_title->p_key, sizeof(dvd_key_t) );
        return 0;
    }

163
164
165
166
    /* Check whether the key is in our disk cache */
    if( dvdcss->psz_cachefile[0] )
    {
        /* XXX: be careful, we use sprintf and not snprintf */
167
        sprintf( dvdcss->psz_block, "%.10x", i_block );
168
169
        i_fd = open( dvdcss->psz_cachefile, O_RDONLY );
        b_cache = 1;
170

171
172
        if( i_fd >= 0 )
        {
173
            char psz_key[KEY_SIZE * 3];
Sam Hocevar's avatar
Sam Hocevar committed
174
175
176
177
178
179
180
            unsigned int k0, k1, k2, k3, k4;

            psz_key[KEY_SIZE * 3 - 1] = '\0';

            if( read( i_fd, psz_key, KEY_SIZE * 3 - 1 ) == KEY_SIZE * 3 - 1
                 && sscanf( psz_key, "%x:%x:%x:%x:%x",
                            &k0, &k1, &k2, &k3, &k4 ) == 5 )
181
            {
Sam Hocevar's avatar
Sam Hocevar committed
182
183
184
185
186
187
188
                p_title_key[0] = k0;
                p_title_key[1] = k1;
                p_title_key[2] = k2;
                p_title_key[3] = k3;
                p_title_key[4] = k4;
                PrintKey( dvdcss, "title key found in cache ", p_title_key );

189
190
191
192
                /* Don't try to save it again */
                b_cache = 0;
                i_ret = 1;
            }
Sam Hocevar's avatar
Sam Hocevar committed
193

194
195
196
197
198
            close( i_fd );
        }
    }

    /* Crack or decrypt CSS title key for current VTS */
199
200
    if( i_ret < 0 )
    {
201
202
203
204
        i_ret = _dvdcss_titlekey( dvdcss, i_block, p_title_key );

        if( i_ret < 0 )
        {
205
            print_error( dvdcss, "fatal error in vts css key" );
206
207
208
209
210
            return i_ret;
        }

        if( i_ret == 0 )
        {
211
            print_debug( dvdcss, "unencrypted title" );
212
213
            /* We cache this anyway, so we don't need to check again. */
        }
214
    }
215
216

    /* Key is valid, we store it on disk. */
Sam Hocevar's avatar
Sam Hocevar committed
217
    if( dvdcss->psz_cachefile[0] && b_cache )
218
    {
Sam Hocevar's avatar
Sam Hocevar committed
219
        i_fd = open( dvdcss->psz_cachefile, O_RDWR|O_CREAT, 0644 );
220
221
        if( i_fd >= 0 )
        {
222
            char psz_key[KEY_SIZE * 3 + 2];
Sam Hocevar's avatar
Sam Hocevar committed
223
224
225
226
227
228

            sprintf( psz_key, "%02x:%02x:%02x:%02x:%02x\r\n",
                              p_title_key[0], p_title_key[1], p_title_key[2],
                              p_title_key[3], p_title_key[4] );

            write( i_fd, psz_key, KEY_SIZE * 3 + 1 );
229
230
            close( i_fd );
        }
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
    }

    /* Find our spot in the list */
    p_newtitle = NULL;
    p_title = dvdcss->p_titles;
    while( ( p_title != NULL ) && ( p_title->i_startlb < i_block ) )
    {
        p_newtitle = p_title;
        p_title = p_title->p_next;
    }

    /* Save the found title */
    p_title = p_newtitle;

    /* Write in the new title and its key */
    p_newtitle = malloc( sizeof( dvd_title_t ) );
    p_newtitle->i_startlb = i_block;
    memcpy( p_newtitle->p_key, p_title_key, KEY_SIZE );

    /* Link it at the head of the (possibly empty) list */
    if( p_title == NULL )
    {
        p_newtitle->p_next = dvdcss->p_titles;
        dvdcss->p_titles = p_newtitle;
    }
    /* Link the new title inside the list */
    else
    {
        p_newtitle->p_next = p_title->p_next;
        p_title->p_next = p_newtitle;
    }

    memcpy( dvdcss->css.p_title_key, p_title_key, KEY_SIZE );
    return 0;
}

/*****************************************************************************
 * _dvdcss_disckey: get disc key.
Sam Hocevar's avatar
 
Sam Hocevar committed
269
270
 *****************************************************************************
 * This function should only be called if DVD ioctls are present.
271
 * It will set dvdcss->i_method = DVDCSS_METHOD_TITLE if it fails to find
272
273
 * a valid disc key.
 * Two decryption methods are offered:
Sam Hocevar's avatar
 
Sam Hocevar committed
274
275
276
 *  -disc key hash crack,
 *  -decryption with player keys if they are available.
 *****************************************************************************/
277
int _dvdcss_disckey( dvdcss_t dvdcss )
Sam Hocevar's avatar
 
Sam Hocevar committed
278
{
Sam Hocevar's avatar
Sam Hocevar committed
279
    unsigned char p_buffer[ DVD_DISCKEY_SIZE ];
280
    dvd_key_t p_disc_key;
Sam Hocevar's avatar
 
Sam Hocevar committed
281
282
    int i;

283
    if( GetBusKey( dvdcss ) < 0 )
Sam Hocevar's avatar
 
Sam Hocevar committed
284
285
286
287
288
289
290
    {
        return -1;
    }

    /* Get encrypted disc key */
    if( ioctl_ReadDiscKey( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0 )
    {
291
        print_error( dvdcss, "ioctl ReadDiscKey failed" );
Sam Hocevar's avatar
 
Sam Hocevar committed
292
293
294
        return -1;
    }

295
    /* This should have invaidated the AGID and got us ASF=1. */
296
    if( GetASF( dvdcss ) != 1 )
297
    {
298
        /* Region mismatch (or region not set) is the most likely source. */
299
300
        print_error( dvdcss,
                     "ASF not 1 after reading disc key (region mismatch?)" );
301
302
303
304
        ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
        return -1;
    }

Sam Hocevar's avatar
Sam Hocevar committed
305
    /* Shuffle disc key using bus key */
Sam Hocevar's avatar
Sam Hocevar committed
306
    for( i = 0 ; i < DVD_DISCKEY_SIZE ; i++ )
Sam Hocevar's avatar
 
Sam Hocevar committed
307
    {
308
        p_buffer[ i ] ^= dvdcss->css.p_bus_key[ 4 - (i % KEY_SIZE) ];
Sam Hocevar's avatar
 
Sam Hocevar committed
309
310
    }

Sam Hocevar's avatar
Sam Hocevar committed
311
    /* Decrypt disc key */
Sam Hocevar's avatar
 
Sam Hocevar committed
312
313
314
    switch( dvdcss->i_method )
    {
        case DVDCSS_METHOD_KEY:
315

316
            /* Decrypt disc key with player key. */
317
            PrintKey( dvdcss, "decrypting disc key ", p_buffer );
318
            if( ! DecryptDiscKey( dvdcss, p_buffer, p_disc_key ) )
Sam Hocevar's avatar
 
Sam Hocevar committed
319
            {
320
                PrintKey( dvdcss, "decrypted disc key is ", p_disc_key );
321
322
                break;
            }
323
324
325
            print_debug( dvdcss, "failed to decrypt the disc key, "
                                 "faulty drive/kernel? "
                                 "cracking title keys instead" );
326

327
            /* Fallback, but not to DISC as the disc key might be faulty */
328
            memset( p_disc_key, 0, KEY_SIZE );
329
330
            dvdcss->i_method = DVDCSS_METHOD_TITLE;
            break;
Sam Hocevar's avatar
   
Sam Hocevar committed
331

Sam Hocevar's avatar
 
Sam Hocevar committed
332
        case DVDCSS_METHOD_DISC:
333

Sam Hocevar's avatar
 
Sam Hocevar committed
334
            /* Crack Disc key to be able to use it */
335
            memcpy( p_disc_key, p_buffer, KEY_SIZE );
336
            PrintKey( dvdcss, "cracking disc key ", p_disc_key );
337
            if( ! CrackDiscKey( dvdcss, p_disc_key ) )
338
            {
339
340
                PrintKey( dvdcss, "cracked disc key is ", p_disc_key );
                break;
341
            }
342
            print_debug( dvdcss, "failed to crack the disc key" );
343
            memset( p_disc_key, 0, KEY_SIZE );
344
            dvdcss->i_method = DVDCSS_METHOD_TITLE;
Sam Hocevar's avatar
 
Sam Hocevar committed
345
346
347
            break;

        default:
348

349
            print_debug( dvdcss, "disc key needs not be decrypted" );
Sam Hocevar's avatar
   
Sam Hocevar committed
350
351
            memset( p_disc_key, 0, KEY_SIZE );
            break;
Sam Hocevar's avatar
 
Sam Hocevar committed
352
353
    }

354
    memcpy( dvdcss->css.p_disc_key, p_disc_key, KEY_SIZE );
355

Sam Hocevar's avatar
 
Sam Hocevar committed
356
357
358
359
360
    return 0;
}


/*****************************************************************************
361
 * _dvdcss_titlekey: get title key.
Sam Hocevar's avatar
 
Sam Hocevar committed
362
 *****************************************************************************/
363
int _dvdcss_titlekey( dvdcss_t dvdcss, int i_pos, dvd_key_t p_title_key )
Sam Hocevar's avatar
 
Sam Hocevar committed
364
{
Sam Hocevar's avatar
Sam Hocevar committed
365
    static uint8_t p_garbage[ DVDCSS_BLOCK_SIZE ];  /* we never read it back */
366
    uint8_t p_key[ KEY_SIZE ];
367
    int i, i_ret = 0;
Sam Hocevar's avatar
 
Sam Hocevar committed
368

369
    if( dvdcss->b_ioctls && ( dvdcss->i_method == DVDCSS_METHOD_KEY ||
370
                              dvdcss->i_method == DVDCSS_METHOD_DISC ) )
Sam Hocevar's avatar
 
Sam Hocevar committed
371
    {
372
373
        /* We have a decrypted Disc key and the ioctls are available,
         * read the title key and decrypt it.
Sam Hocevar's avatar
 
Sam Hocevar committed
374
375
         */

376
377
        print_debug( dvdcss, "getting title key at block %i the classic way",
                             i_pos );
378

379
        /* We need to authenticate again every time to get a new session key */
380
        if( GetBusKey( dvdcss ) < 0 )
381
382
383
        {
            return -1;
        }
Sam Hocevar's avatar
 
Sam Hocevar committed
384
385
386
387
388

        /* Get encrypted title key */
        if( ioctl_ReadTitleKey( dvdcss->i_fd, &dvdcss->css.i_agid,
                                i_pos, p_key ) < 0 )
        {
389
390
            print_debug( dvdcss,
                         "ioctl ReadTitleKey failed (region mismatch?)" );
391
392
393
394
            i_ret = -1;
        }

        /* Test ASF, it will be reset to 0 if we got a Region error */
395
        switch( GetASF( dvdcss ) )
396
397
398
        {
            case -1:
                /* An error getting the ASF status, something must be wrong. */
399
                print_debug( dvdcss, "lost ASF requesting title key" );
400
                ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
401
                i_ret = -1;
402
                break;
403
404

            case 0:
405
                /* This might either be a title that has no key,
406
                 * or we encountered a region error. */
407
                print_debug( dvdcss, "lost ASF requesting title key" );
408
                break;
409
410

            case 1:
411
                /* Drive status is ok. */
412
413
414
415
416
417
418
                /* If the title key request failed, but we did not loose ASF,
                 * we might stil have the AGID.  Other code assume that we
                 * will not after this so invalidate it(?). */
                if( i_ret < 0 )
                {
                    ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
                }
419
                break;
Sam Hocevar's avatar
 
Sam Hocevar committed
420
        }
421
422
423
424
425
426
427
428
429

        if( !( i_ret < 0 ) )
        {
            /* Decrypt title key using the bus key */
            for( i = 0 ; i < KEY_SIZE ; i++ )
            {
                p_key[ i ] ^= dvdcss->css.p_bus_key[ 4 - (i % KEY_SIZE) ];
            }

Sam Hocevar's avatar
Sam Hocevar committed
430
            /* If p_key is all zero then there really wasn't any key present
431
432
433
434
435
436
437
             * even though we got to read it without an error. */
            if( !( p_key[0] | p_key[1] | p_key[2] | p_key[3] | p_key[4] ) )
            {
                i_ret = 0;
            }
            else
            {
438
                PrintKey( dvdcss, "initial disc key ", dvdcss->css.p_disc_key );
439
                DecryptTitleKey( dvdcss->css.p_disc_key, p_key );
440
                PrintKey( dvdcss, "decrypted title key ", p_key );
441
442
443
444
445
446
447
448
449
450
451
                i_ret = 1;
            }

            /* All went well either there wasn't a key or we have it now. */
            memcpy( p_title_key, p_key, KEY_SIZE );
            PrintKey( dvdcss, "title key is ", p_title_key );

            return i_ret;
        }

        /* The title key request failed */
452
        print_debug( dvdcss, "resetting drive and cracking title key" );
453

454
        /* Read an unscrambled sector and reset the drive */
455
456
457
        dvdcss->pf_seek( dvdcss, 0 );
        dvdcss->pf_read( dvdcss, p_garbage, 1 );
        dvdcss->pf_seek( dvdcss, 0 );
458
459
460
        _dvdcss_disckey( dvdcss );

        /* Fallback */
461
    }
462

463
464
    /* METHOD is TITLE, we can't use the ioctls or requesting the title key
     * failed above.  For these cases we try to crack the key instead. */
465

466
    /* For now, the read limit is 9Gb / 2048 =  4718592 sectors. */
467
    i_ret = CrackTitleKey( dvdcss, i_pos, 4718592, p_key );
Sam Hocevar's avatar
 
Sam Hocevar committed
468

469
    memcpy( p_title_key, p_key, KEY_SIZE );
470
    PrintKey( dvdcss, "title key is ", p_title_key );
Sam Hocevar's avatar
 
Sam Hocevar committed
471

472
    return i_ret;
Sam Hocevar's avatar
 
Sam Hocevar committed
473
474
475
}

/*****************************************************************************
476
 * _dvdcss_unscramble: does the actual descrambling of data
Sam Hocevar's avatar
 
Sam Hocevar committed
477
 *****************************************************************************
478
 * sec : sector to unscramble
Sam Hocevar's avatar
 
Sam Hocevar committed
479
480
 * key : title key for this sector
 *****************************************************************************/
481
int _dvdcss_unscramble( dvd_key_t p_key, uint8_t *p_sec )
Sam Hocevar's avatar
 
Sam Hocevar committed
482
483
{
    unsigned int    i_t1, i_t2, i_t3, i_t4, i_t5, i_t6;
Sam Hocevar's avatar
Sam Hocevar committed
484
    uint8_t        *p_end = p_sec + DVDCSS_BLOCK_SIZE;
Sam Hocevar's avatar
 
Sam Hocevar committed
485
486

    /* PES_scrambling_control */
487
    if( !(p_sec[0x14] & 0x30) )
Sam Hocevar's avatar
 
Sam Hocevar committed
488
    {
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
        return 0;
    }

    i_t1 = (p_key[0] ^ p_sec[0x54]) | 0x100;
    i_t2 = p_key[1] ^ p_sec[0x55];
    i_t3 = (p_key[2] | (p_key[3] << 8) |
           (p_key[4] << 16)) ^ (p_sec[0x56] |
           (p_sec[0x57] << 8) | (p_sec[0x58] << 16));
    i_t4 = i_t3 & 7;
    i_t3 = i_t3 * 2 + 8 - i_t4;
    p_sec += 0x80;
    i_t5 = 0;

    while( p_sec != p_end )
    {
        i_t4 = p_css_tab2[i_t2] ^ p_css_tab3[i_t1];
        i_t2 = i_t1>>1;
        i_t1 = ( ( i_t1 & 1 ) << 8 ) ^ i_t4;
        i_t4 = p_css_tab5[i_t4];
        i_t6 = ((((((( i_t3 >> 3 ) ^ i_t3 ) >> 1 ) ^
                                     i_t3 ) >> 8 ) ^ i_t3 ) >> 5 ) & 0xff;
        i_t3 = (i_t3 << 8 ) | i_t6;
        i_t6 = p_css_tab4[i_t6];
        i_t5 += i_t6 + i_t4;
        *p_sec = p_css_tab1[*p_sec] ^ ( i_t5 & 0xff );
        p_sec++;
        i_t5 >>= 8;
    }

    return 0;
}
Sam Hocevar's avatar
 
Sam Hocevar committed
520

521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
/* Following functions are local */

/*****************************************************************************
 * GetBusKey : Go through the CSS Authentication process
 *****************************************************************************
 * It simulates the mutual authentication between logical unit and host,
 * and stops when a session key (called bus key) has been established.
 * Always do the full auth sequence. Some drives seem to lie and always
 * respond with ASF=1.  For instance the old DVD roms on Compaq Armada says
 * that ASF=1 from the start and then later fail with a 'read of scrambled
 * block without authentication' error.
 *****************************************************************************/
static int GetBusKey( dvdcss_t dvdcss )
{
    uint8_t   p_buffer[10];
    uint8_t   p_challenge[2*KEY_SIZE];
    dvd_key_t p_key1;
    dvd_key_t p_key2;
    dvd_key_t p_key_check;
    uint8_t   i_variant = 0;
    int       i_ret = -1;
    int       i;

    print_debug( dvdcss, "requesting AGID" );
    i_ret = ioctl_ReportAgid( dvdcss->i_fd, &dvdcss->css.i_agid );

    /* We might have to reset hung authentication processes in the drive
     * by invalidating the corresponding AGID'.  As long as we haven't got
     * an AGID, invalidate one (in sequence) and try again. */
    for( i = 0; i_ret == -1 && i < 4 ; ++i )
    {
        print_debug( dvdcss, "ioctl ReportAgid failed, "
                             "invalidating AGID %d", i );

        /* This is really _not good_, should be handled by the OS.
         * Invalidating an AGID could make another process fail somewhere
         * in its authentication process. */
        dvdcss->css.i_agid = i;
        ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );

        print_debug( dvdcss, "requesting AGID" );
        i_ret = ioctl_ReportAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
    }

    /* Unable to authenticate without AGID */
    if( i_ret == -1 )
    {
        print_error( dvdcss, "ioctl ReportAgid failed, fatal" );
        return -1;
    }

    /* Setup a challenge, any values should work */
    for( i = 0 ; i < 10; ++i )
    {
        p_challenge[i] = i;
    }

    /* Get challenge from host */
    for( i = 0 ; i < 10 ; ++i )
    {
        p_buffer[9-i] = p_challenge[i];
    }

    /* Send challenge to LU */
    if( ioctl_SendChallenge( dvdcss->i_fd,
                             &dvdcss->css.i_agid, p_buffer ) < 0 )
    {
        print_error( dvdcss, "ioctl SendChallenge failed" );
        ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
        return -1;
    }

    /* Get key1 from LU */
    if( ioctl_ReportKey1( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0)
    {
        print_error( dvdcss, "ioctl ReportKey1 failed" );
        ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
        return -1;
    }

    /* Send key1 to host */
    for( i = 0 ; i < KEY_SIZE ; i++ )
    {
        p_key1[i] = p_buffer[4-i];
    }

    for( i = 0 ; i < 32 ; ++i )
    {
        CryptKey( 0, i, p_challenge, p_key_check );

        if( memcmp( p_key_check, p_key1, KEY_SIZE ) == 0 )
Sam Hocevar's avatar
 
Sam Hocevar committed
612
        {
613
614
615
            print_debug( dvdcss, "drive authenticated, using variant %d", i );
            i_variant = i;
            break;
Sam Hocevar's avatar
 
Sam Hocevar committed
616
617
618
        }
    }

619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
    if( i == 32 )
    {
        print_error( dvdcss, "drive would not authenticate" );
        ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
        return -1;
    }

    /* Get challenge from LU */
    if( ioctl_ReportChallenge( dvdcss->i_fd,
                               &dvdcss->css.i_agid, p_buffer ) < 0 )
    {
        print_error( dvdcss, "ioctl ReportKeyChallenge failed" );
        ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
        return -1;
    }

    /* Send challenge to host */
    for( i = 0 ; i < 10 ; ++i )
    {
        p_challenge[i] = p_buffer[9-i];
    }

    CryptKey( 1, i_variant, p_challenge, p_key2 );

    /* Get key2 from host */
    for( i = 0 ; i < KEY_SIZE ; ++i )
    {
        p_buffer[4-i] = p_key2[i];
    }

    /* Send key2 to LU */
    if( ioctl_SendKey2( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0 )
    {
        print_error( dvdcss, "ioctl SendKey2 failed" );
        ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
        return -1;
    }

    /* The drive has accepted us as authentic. */
    print_debug( dvdcss, "authentication established" );

    memcpy( p_challenge, p_key1, KEY_SIZE );
    memcpy( p_challenge + KEY_SIZE, p_key2, KEY_SIZE );

    CryptKey( 2, i_variant, p_challenge, dvdcss->css.p_bus_key );

Sam Hocevar's avatar
 
Sam Hocevar committed
665
666
667
    return 0;
}

668
669
670
671
672
673
674
675
/*****************************************************************************
 * PrintKey : debug function that dumps a key value
 *****************************************************************************/
static void PrintKey( dvdcss_t dvdcss, char *prefix, uint8_t const *data )
{
    print_debug( dvdcss, "%s%02x:%02x:%02x:%02x:%02x", prefix,
                 data[0], data[1], data[2], data[3], data[4] );
}
Sam Hocevar's avatar
 
Sam Hocevar committed
676
677

/*****************************************************************************
678
 * GetASF : Get Authentication success flag
Sam Hocevar's avatar
 
Sam Hocevar committed
679
680
681
682
683
684
 *****************************************************************************
 * Returns :
 *  -1 on ioctl error,
 *  0 if the device needs to be authenticated,
 *  1 either.
 *****************************************************************************/
685
static int GetASF( dvdcss_t dvdcss )
Sam Hocevar's avatar
 
Sam Hocevar committed
686
687
688
{
    int i_asf = 0;

689
    if( ioctl_ReportASF( dvdcss->i_fd, NULL, &i_asf ) != 0 )
Sam Hocevar's avatar
 
Sam Hocevar committed
690
    {
691
        /* The ioctl process has failed */
692
        print_error( dvdcss, "GetASF fatal error" );
693
694
        return -1;
    }
Sam Hocevar's avatar
 
Sam Hocevar committed
695

696
697
    if( i_asf )
    {
698
        print_debug( dvdcss, "GetASF authenticated, ASF=1" );
699
700
701
    }
    else
    {
702
        print_debug( dvdcss, "GetASF not authenticated, ASF=0" );
Sam Hocevar's avatar
 
Sam Hocevar committed
703
704
    }

705
    return i_asf;
Sam Hocevar's avatar
 
Sam Hocevar committed
706
707
708
}

/*****************************************************************************
709
 * CryptKey : shuffles bits and unencrypt keys.
Sam Hocevar's avatar
 
Sam Hocevar committed
710
 *****************************************************************************
711
 * Used during authentication and disc key negociation in GetBusKey.
Sam Hocevar's avatar
 
Sam Hocevar committed
712
 * i_key_type : 0->key1, 1->key2, 2->buskey.
713
 * i_variant : between 0 and 31.
Sam Hocevar's avatar
 
Sam Hocevar committed
714
 *****************************************************************************/
715
static void CryptKey( int i_key_type, int i_variant,
716
                      uint8_t const *p_challenge, uint8_t *p_key )
Sam Hocevar's avatar
 
Sam Hocevar committed
717
718
{
    /* Permutation table for challenge */
719
    uint8_t pp_perm_challenge[3][10] =
Sam Hocevar's avatar
 
Sam Hocevar committed
720
721
722
723
            { { 1, 3, 0, 7, 5, 2, 9, 6, 4, 8 },
              { 6, 1, 9, 3, 8, 5, 7, 4, 0, 2 },
              { 4, 0, 3, 5, 7, 2, 8, 6, 1, 9 } };

724
    /* Permutation table for variant table for key2 and buskey */
725
    uint8_t pp_perm_variant[2][32] =
Sam Hocevar's avatar
 
Sam Hocevar committed
726
727
728
729
730
731
732
733
734
            { { 0x0a, 0x08, 0x0e, 0x0c, 0x0b, 0x09, 0x0f, 0x0d,
                0x1a, 0x18, 0x1e, 0x1c, 0x1b, 0x19, 0x1f, 0x1d,
                0x02, 0x00, 0x06, 0x04, 0x03, 0x01, 0x07, 0x05,
                0x12, 0x10, 0x16, 0x14, 0x13, 0x11, 0x17, 0x15 },
              { 0x12, 0x1a, 0x16, 0x1e, 0x02, 0x0a, 0x06, 0x0e,
                0x10, 0x18, 0x14, 0x1c, 0x00, 0x08, 0x04, 0x0c,
                0x13, 0x1b, 0x17, 0x1f, 0x03, 0x0b, 0x07, 0x0f,
                0x11, 0x19, 0x15, 0x1d, 0x01, 0x09, 0x05, 0x0d } };

735
    uint8_t p_variants[32] =
Sam Hocevar's avatar
 
Sam Hocevar committed
736
737
738
739
740
741
            {   0xB7, 0x74, 0x85, 0xD0, 0xCC, 0xDB, 0xCA, 0x73,
                0x03, 0xFE, 0x31, 0x03, 0x52, 0xE0, 0xB7, 0x42,
                0x63, 0x16, 0xF2, 0x2A, 0x79, 0x52, 0xFF, 0x1B,
                0x7A, 0x11, 0xCA, 0x1A, 0x9B, 0x40, 0xAD, 0x01 };

    /* The "secret" key */
742
743
744
745
746
747
748
749
750
751
752
    uint8_t p_secret[5] = { 0x55, 0xD6, 0xC4, 0xC5, 0x28 };

    uint8_t p_bits[30], p_scratch[10], p_tmp1[5], p_tmp2[5];
    uint8_t i_lfsr0_o;  /* 1 bit used */
    uint8_t i_lfsr1_o;  /* 1 bit used */
    uint8_t i_css_variant, i_cse, i_index, i_combined, i_carry;
    uint8_t i_val = 0;
    uint32_t i_lfsr0, i_lfsr1;
    int i_term = 0;
    int i_bit;
    int i;
Sam Hocevar's avatar
 
Sam Hocevar committed
753
754
755
756

    for (i = 9; i >= 0; --i)
        p_scratch[i] = p_challenge[pp_perm_challenge[i_key_type][i]];

757
758
    i_css_variant = ( i_key_type == 0 ) ? i_variant :
                    pp_perm_variant[i_key_type-1][i_variant];
Sam Hocevar's avatar
 
Sam Hocevar committed
759
760
761
762

    /*
     * This encryption engine implements one of 32 variations
     * one the same theme depending upon the choice in the
763
     * variant parameter (0 - 31).
Sam Hocevar's avatar
 
Sam Hocevar committed
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
     *
     * The algorithm itself manipulates a 40 bit input into
     * a 40 bit output.
     * The parameter 'input' is 80 bits.  It consists of
     * the 40 bit input value that is to be encrypted followed
     * by a 40 bit seed value for the pseudo random number
     * generators.
     */

    /* Feed the secret into the input values such that
     * we alter the seed to the LFSR's used above,  then
     * generate the bits to play with.
     */
    for( i = 5 ; --i >= 0 ; )
    {
        p_tmp1[i] = p_scratch[5 + i] ^ p_secret[i] ^ p_crypt_tab2[i];
    }

    /*
     * We use two LFSR's (seeded from some of the input data bytes) to
     * generate two streams of pseudo-random bits.  These two bit streams
     * are then combined by simply adding with carry to generate a final
     * sequence of pseudo-random bits which is stored in the buffer that
     * 'output' points to the end of - len is the size of this buffer.
     *
     * The first LFSR is of degree 25,  and has a polynomial of:
     * x^13 + x^5 + x^4 + x^1 + 1
     *
     * The second LSFR is of degree 17,  and has a (primitive) polynomial of:
     * x^15 + x^1 + 1
     *
     * I don't know if these polynomials are primitive modulo 2,  and thus
     * represent maximal-period LFSR's.
     *
     *
     * Note that we take the output of each LFSR from the new shifted in
     * bit,  not the old shifted out bit.  Thus for ease of use the LFSR's
     * are implemented in bit reversed order.
     *
     */
804

Sam Hocevar's avatar
 
Sam Hocevar committed
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
    /* In order to ensure that the LFSR works we need to ensure that the
     * initial values are non-zero.  Thus when we initialise them from
     * the seed,  we ensure that a bit is set.
     */
    i_lfsr0 = ( p_tmp1[0] << 17 ) | ( p_tmp1[1] << 9 ) |
              (( p_tmp1[2] & ~7 ) << 1 ) | 8 | ( p_tmp1[2] & 7 );
    i_lfsr1 = ( p_tmp1[3] << 9 ) | 0x100 | p_tmp1[4];

    i_index = sizeof(p_bits);
    i_carry = 0;

    do
    {
        for( i_bit = 0, i_val = 0 ; i_bit < 8 ; ++i_bit )
        {

            i_lfsr0_o = ( ( i_lfsr0 >> 24 ) ^ ( i_lfsr0 >> 21 ) ^
                        ( i_lfsr0 >> 20 ) ^ ( i_lfsr0 >> 12 ) ) & 1;
            i_lfsr0 = ( i_lfsr0 << 1 ) | i_lfsr0_o;

            i_lfsr1_o = ( ( i_lfsr1 >> 16 ) ^ ( i_lfsr1 >> 2 ) ) & 1;
            i_lfsr1 = ( i_lfsr1 << 1 ) | i_lfsr1_o;

            i_combined = !i_lfsr1_o + i_carry + !i_lfsr0_o;
            /* taking bit 1 */
            i_carry = ( i_combined >> 1 ) & 1;
            i_val |= ( i_combined & 1 ) << i_bit;
        }
833

Sam Hocevar's avatar
 
Sam Hocevar committed
834
835
836
837
838
839
840
        p_bits[--i_index] = i_val;
    } while( i_index > 0 );

    /* This term is used throughout the following to
     * select one of 32 different variations on the
     * algorithm.
     */
841
    i_cse = p_variants[i_css_variant] ^ p_crypt_tab2[i_css_variant];
Sam Hocevar's avatar
 
Sam Hocevar committed
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907

    /* Now the actual blocks doing the encryption.  Each
     * of these works on 40 bits at a time and are quite
     * similar.
     */
    i_index = 0;
    for( i = 5, i_term = 0 ; --i >= 0 ; i_term = p_scratch[i] )
    {
        i_index = p_bits[25 + i] ^ p_scratch[i];
        i_index = p_crypt_tab1[i_index] ^ ~p_crypt_tab2[i_index] ^ i_cse;

        p_tmp1[i] = p_crypt_tab2[i_index] ^ p_crypt_tab3[i_index] ^ i_term;
    }
    p_tmp1[4] ^= p_tmp1[0];

    for( i = 5, i_term = 0 ; --i >= 0 ; i_term = p_tmp1[i] )
    {
        i_index = p_bits[20 + i] ^ p_tmp1[i];
        i_index = p_crypt_tab1[i_index] ^ ~p_crypt_tab2[i_index] ^ i_cse;

        p_tmp2[i] = p_crypt_tab2[i_index] ^ p_crypt_tab3[i_index] ^ i_term;
    }
    p_tmp2[4] ^= p_tmp2[0];

    for( i = 5, i_term = 0 ; --i >= 0 ; i_term = p_tmp2[i] )
    {
        i_index = p_bits[15 + i] ^ p_tmp2[i];
        i_index = p_crypt_tab1[i_index] ^ ~p_crypt_tab2[i_index] ^ i_cse;
        i_index = p_crypt_tab2[i_index] ^ p_crypt_tab3[i_index] ^ i_term;

        p_tmp1[i] = p_crypt_tab0[i_index] ^ p_crypt_tab2[i_index];
    }
    p_tmp1[4] ^= p_tmp1[0];

    for( i = 5, i_term = 0 ; --i >= 0 ; i_term = p_tmp1[i] )
    {
        i_index = p_bits[10 + i] ^ p_tmp1[i];
        i_index = p_crypt_tab1[i_index] ^ ~p_crypt_tab2[i_index] ^ i_cse;

        i_index = p_crypt_tab2[i_index] ^ p_crypt_tab3[i_index] ^ i_term;

        p_tmp2[i] = p_crypt_tab0[i_index] ^ p_crypt_tab2[i_index];
    }
    p_tmp2[4] ^= p_tmp2[0];

    for( i = 5, i_term = 0 ; --i >= 0 ; i_term = p_tmp2[i] )
    {
        i_index = p_bits[5 + i] ^ p_tmp2[i];
        i_index = p_crypt_tab1[i_index] ^ ~p_crypt_tab2[i_index] ^ i_cse;

        p_tmp1[i] = p_crypt_tab2[i_index] ^ p_crypt_tab3[i_index] ^ i_term;
    }
    p_tmp1[4] ^= p_tmp1[0];

    for(i = 5, i_term = 0 ; --i >= 0 ; i_term = p_tmp1[i] )
    {
        i_index = p_bits[i] ^ p_tmp1[i];
        i_index = p_crypt_tab1[i_index] ^ ~p_crypt_tab2[i_index] ^ i_cse;

        p_key[i] = p_crypt_tab2[i_index] ^ p_crypt_tab3[i_index] ^ i_term;
    }

    return;
}

/*****************************************************************************
908
 * DecryptKey: decrypt p_crypted with p_key.
Sam Hocevar's avatar
 
Sam Hocevar committed
909
 *****************************************************************************
910
911
 * Used to decrypt the disc key, with a player key, after requesting it
 * in _dvdcss_disckey and to decrypt title keys, with a disc key, requested
912
 * in _dvdcss_titlekey.
913
 * The player keys and the resulting disc key are only used as KEKs
914
 * (key encryption keys).
Sam Hocevar's avatar
 
Sam Hocevar committed
915
916
 * Decryption is slightly dependant on the type of key:
 *  -for disc key, invert is 0x00,
917
 *  -for title key, invert if 0xff.
Sam Hocevar's avatar
 
Sam Hocevar committed
918
 *****************************************************************************/
919
920
static void DecryptKey( uint8_t invert, uint8_t const *p_key,
                        uint8_t const *p_crypted, uint8_t *p_result )
Sam Hocevar's avatar
 
Sam Hocevar committed
921
922
923
924
925
{
    unsigned int    i_lfsr1_lo;
    unsigned int    i_lfsr1_hi;
    unsigned int    i_lfsr0;
    unsigned int    i_combined;
926
927
928
    uint8_t         o_lfsr0;
    uint8_t         o_lfsr1;
    uint8_t         k[5];
Sam Hocevar's avatar
 
Sam Hocevar committed
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
    int             i;

    i_lfsr1_lo = p_key[0] | 0x100;
    i_lfsr1_hi = p_key[1];

    i_lfsr0    = ( ( p_key[4] << 17 )
                 | ( p_key[3] << 9 )
                 | ( p_key[2] << 1 ) )
                 + 8 - ( p_key[2] & 7 );
    i_lfsr0    = ( p_css_tab4[i_lfsr0 & 0xff] << 24 ) |
                 ( p_css_tab4[( i_lfsr0 >> 8 ) & 0xff] << 16 ) |
                 ( p_css_tab4[( i_lfsr0 >> 16 ) & 0xff] << 8 ) |
                   p_css_tab4[( i_lfsr0 >> 24 ) & 0xff];

    i_combined = 0;
    for( i = 0 ; i < KEY_SIZE ; ++i )
    {
        o_lfsr1     = p_css_tab2[i_lfsr1_hi] ^ p_css_tab3[i_lfsr1_lo];
        i_lfsr1_hi  = i_lfsr1_lo >> 1;
        i_lfsr1_lo  = ( ( i_lfsr1_lo & 1 ) << 8 ) ^ o_lfsr1;
        o_lfsr1     = p_css_tab4[o_lfsr1];

        o_lfsr0 = ((((((( i_lfsr0 >> 8 ) ^ i_lfsr0 ) >> 1 )
                        ^ i_lfsr0 ) >> 3 ) ^ i_lfsr0 ) >> 7 );
        i_lfsr0 = ( i_lfsr0 >> 8 ) | ( o_lfsr0 << 24 );

        i_combined += ( o_lfsr0 ^ invert ) + o_lfsr1;
        k[i] = i_combined & 0xff;
        i_combined >>= 8;
    }

960
961
962
963
964
    p_result[4] = k[4] ^ p_css_tab1[p_crypted[4]] ^ p_crypted[3];
    p_result[3] = k[3] ^ p_css_tab1[p_crypted[3]] ^ p_crypted[2];
    p_result[2] = k[2] ^ p_css_tab1[p_crypted[2]] ^ p_crypted[1];
    p_result[1] = k[1] ^ p_css_tab1[p_crypted[1]] ^ p_crypted[0];
    p_result[0] = k[0] ^ p_css_tab1[p_crypted[0]] ^ p_result[4];
Sam Hocevar's avatar
 
Sam Hocevar committed
965

966
967
968
969
970
    p_result[4] = k[4] ^ p_css_tab1[p_result[4]] ^ p_result[3];
    p_result[3] = k[3] ^ p_css_tab1[p_result[3]] ^ p_result[2];
    p_result[2] = k[2] ^ p_css_tab1[p_result[2]] ^ p_result[1];
    p_result[1] = k[1] ^ p_css_tab1[p_result[1]] ^ p_result[0];
    p_result[0] = k[0] ^ p_css_tab1[p_result[0]];
Sam Hocevar's avatar
 
Sam Hocevar committed
971
972
973
974

    return;
}

975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************
 * player_keys: alternate DVD player keys
 *****************************************************************************
 * These player keys were generated using Frank A. Stevenson's PlayerKey
 * cracker. A copy of his article can be found here:
 * http://www-2.cs.cmu.edu/~dst/DeCSS/FrankStevenson/mail2.txt
 *****************************************************************************/
static const dvd_key_t player_keys[] =
{
    { 0x01, 0xaf, 0xe3, 0x12, 0x80 },
    { 0x12, 0x11, 0xca, 0x04, 0x3b },
    { 0x14, 0x0c, 0x9e, 0xd0, 0x09 },
    { 0x14, 0x71, 0x35, 0xba, 0xe2 },
    { 0x1a, 0xa4, 0x33, 0x21, 0xa6 },
    { 0x26, 0xec, 0xc4, 0xa7, 0x4e },
    { 0x2c, 0xb2, 0xc1, 0x09, 0xee },
    { 0x2f, 0x25, 0x9e, 0x96, 0xdd },
    { 0x33, 0x2f, 0x49, 0x6c, 0xe0 },
    { 0x35, 0x5b, 0xc1, 0x31, 0x0f },
    { 0x36, 0x67, 0xb2, 0xe3, 0x85 },
    { 0x39, 0x3d, 0xf1, 0xf1, 0xbd },
    { 0x3b, 0x31, 0x34, 0x0d, 0x91 },
    { 0x45, 0xed, 0x28, 0xeb, 0xd3 },
    { 0x48, 0xb7, 0x6c, 0xce, 0x69 },
    { 0x4b, 0x65, 0x0d, 0xc1, 0xee },
    { 0x4c, 0xbb, 0xf5, 0x5b, 0x23 },
For faster browsing, not all history is shown. View entire blame