source: svn/newcon3bcm2_21bu/nexus/lib/playback_ip/src/radeadecoder.cpp @ 76

Last change on this file since 76 was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 8.3 KB
Line 
1/********************************************************************
2        created:        2006/08/28
3        created:        28:8:2006   19:46
4        filename:       radeadecoder.cpp
5        author:         Seb Martel (smartel@real.com)
6                        RealNetworks, Inc (C) 2006, All rights reserved
7       
8        purpose:        Sample implementation of a RAD/EA decoder.
9*********************************************************************/
10/***************************************************************************
11*     (c)2003-2009 Broadcom Corporation
12
13*  This program is the proprietary software of Broadcom Corporation and/or its licensors,
14*  and may only be used, duplicated, modified or distributed pursuant to the terms and
15*  conditions of a separate, written license agreement executed between you and Broadcom
16*  (an "Authorized License").  Except as set forth in an Authorized License, Broadcom grants
17*  no license (express or implied), right to use, or waiver of any kind with respect to the
18*  Software, and Broadcom expressly reserves all rights in and to the Software and all
19*  intellectual property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU
20*  HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY
21*  NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. 
22*   
23*  Except as expressly set forth in the Authorized License,
24*   
25*  1.     This program, including its structure, sequence and organization, constitutes the valuable trade
26*  secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof,
27*  and to use this information only in connection with your use of Broadcom integrated circuit products.
28*   
29*  2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
30*  AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
31*  WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
32*  THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES
33*  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE,
34*  LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION
35*  OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF
36*  USE OR PERFORMANCE OF THE SOFTWARE.
37
38*  3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
39*  LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR
40*  EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR
41*  USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF
42*  THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT
43*  ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
44*  LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF
45*  ANY LIMITED REMEDY.
46*
47* $brcm_Workfile: radeadecoder.cpp $
48* $brcm_Revision: $
49* $brcm_Date: $
50*
51* Description: RAD/EA module crypto file
52*
53* Revision History:
54*
55* $brcm_Log: /nexus/lib/playback_ip/src/radeadecoder.cpp $
56*
57***************************************************************************/
58#include <string.h>
59#include <cassert>
60#include <vector>
61#include <deque>
62
63#include "string.h"
64#include "b_playback_ip_rad_ea.h"
65#include "cryptdes.h"
66
67static CCryptDES cCrypt;
68
69extern "C"
70{
71#if 0
72static void initEaHeader( )
73{
74    int i = 0;
75    std::vector<char> mBuf;
76    std::auto_ptr<EA_HEADER> mHeader( new EA_HEADER );
77
78    // LISTEN verification. Assume version 3 first,
79    for ( i = 0; i < LISTEN_VERIFY_NUM_CHARS; ++i ) {
80        mBuf.push_back( read() );
81    }
82
83    if ( !isVersion3(&mBuf[0]) ) {
84        throw RADEAException( "Not a version 3 EA header" );
85    }
86    mBuf.clear();
87
88    // EA verification
89    for ( i = 0; i < EA_VERIFY_NUM_CHARS; ++ i ) {
90        mBuf.push_back( read() );
91    }
92    if ( !isEa( &mBuf[0] ) ) {
93        throw RADEAException( "Invalid EA header verification" );
94    }
95   
96    // Read Header size now
97    mBuf.clear();
98    for ( i = 0; i < sizeof( int ); ++i ) {
99        mBuf.push_back( read() );
100    }
101    int bHeaderSize = *reinterpret_cast<int*>( &mBuf[0] );
102    if ( bHeaderSize < EA_MIN_BYTES_TO_FOLLOW ) {
103        throw RADEAException( "EA header isn't big enough for a version 3 header");
104    }
105
106    // If this isn't 0 we need to skip bytes at end of header.
107    int mExtraCharsAtEndOfHeader = bHeaderSize -  EA_MIN_BYTES_TO_FOLLOW;
108
109    // Init header.
110    mHeader->nSize = bHeaderSize;
111    for ( i = 0; i < EA_MIN_BYTES_TO_FOLLOW; ++i ) {
112        *( (char*)mHeader.get() + sizeof( int ) + i )  = (char)read();
113    }
114
115    // skip over extra data unknown to this header.
116    for ( i = 0; i < mExtraCharsAtEndOfHeader; ++i ) {
117        read();
118    }
119
120    if ( mHeader->sMajorVersion < RAD_MAJOR_VERSION ) {
121        throw RADEAException( "Wrong EA major version" ); // we shouldn't be here if the version is less than 3.0
122    }
123
124    if ( mHeader->sMajorVersion == RAD_MAJOR_VERSION && mHeader->Header.v3.sMinorVersion < RAD_MINOR_VERSION ) {
125        throw RADEAException( "Wrong EA minor version" ); // we shouldn't be here if the version is less than 3.0
126    }
127
128    // All is good, save header.
129    std::swap( cHeader, mHeader );
130}
131
132static void initRadHeader()
133{
134    int i = 0;
135    std::vector<char> mBuf;
136    std::auto_ptr<RAD_HEADER> mHeader( new RAD_HEADER );
137
138    // LISTEN verification. Assume version 3 first,
139    for ( i = 0; i < LISTEN_VERIFY_NUM_CHARS; ++i ) {
140        mBuf.push_back( read() );
141    }
142
143    if ( !isVersion3(&mBuf[0]) ) {
144        throw RADEAException( "Not a version 3 RAD header" );
145    }
146    mBuf.clear();
147
148    // we should read "RAD_" now
149    for ( i = 0; i < EA_VERIFY_NUM_CHARS; ++ i ) {
150        mBuf.push_back( read() );
151    }
152    if ( !isRad( &mBuf[0] ) ) {
153        throw RADEAException( "Invalid RAD header verification" ); // this is a rhapsody file but not a RAD!
154    }
155
156    // Read Header size now
157    mBuf.clear();
158    for ( i = 0; i < sizeof( int ); ++i ) {
159        mBuf.push_back( read() );
160    }
161    int bHeaderSize = *reinterpret_cast<int*>( &mBuf[0] );
162    if ( bHeaderSize < RAD_MIN_BYTES_TO_FOLLOW ) {
163        throw RADEAException( "RAD header isn't big enough for a version 3 header");
164    }
165
166    // If this isn't 0 we need to skip bytes at end of header.
167    int mExtraCharsAtEndOfHeader = bHeaderSize -  RAD_MIN_BYTES_TO_FOLLOW;
168
169    // Init header.
170    mHeader->nSize = bHeaderSize;
171    for ( i = 0; i < RAD_MIN_BYTES_TO_FOLLOW; ++i ) {
172        *( (char*)mHeader.get() + sizeof( int ) + i )  = (char)read();
173    }
174
175    // skip over extra data unknown to this header.
176    for ( i = 0; i < mExtraCharsAtEndOfHeader; ++i ) {
177        read();
178    }
179
180    if ( mHeader->sMajorVersion < RAD_MAJOR_VERSION) {
181        throw RADEAException( "unsupported RAD major version" );
182    }
183    if ( mHeader->sMajorVersion == RAD_MAJOR_VERSION && mHeader->Header.v3.sMinorVersion < RAD_MINOR_VERSION ) {
184        throw RADEAException( "unsupported RAD minor version" );
185    }
186   
187    // All is good, save header.
188    std::swap( cHeader, mHeader );
189}
190#endif
191
192void radea_decrypt_frame( unsigned char* radBuffer, unsigned char* eaBuffer, int radBufferSize, char* decryptedBuffer ) 
193{
194    int i = 0;
195    int mNbDesBlocks = radBufferSize / MIN_RAD_BYTES_FOR_DES;
196    char* reassembledPtr;
197
198//    assert( radBufferSize <= RAD_BYTES_PER_FRAME);
199   
200    // triple des decryption is the reverse of the encryption process, so it's:
201    // 1. decrypt with last 8 bytes of key
202    // 2. encrypt with middle 8 bytes of key
203    // 3. decrypt with first 8 bytes of key
204    cCrypt.Init(eaBuffer + 2 * MIN_RAD_BYTES_FOR_DES);
205    cCrypt.des_dec(radBuffer, mNbDesBlocks); /* Nb of 8 bytes blocks */       
206
207    cCrypt.Init(eaBuffer + MIN_RAD_BYTES_FOR_DES);
208    cCrypt.des_enc(radBuffer, mNbDesBlocks); /* Nb of 8 bytes blocks */
209   
210    cCrypt.Init(eaBuffer);
211    cCrypt.des_dec(radBuffer, mNbDesBlocks); /* Nb of 8 bytes blocks */       
212    // Reassemble EA and RAD
213    int mBlocksToInterleave = radBufferSize / RAD_BYTES_PER_BLOCK;
214    for ( i = 0, reassembledPtr = decryptedBuffer; i < mBlocksToInterleave; ++i ) 
215    {
216        // 1 byte from the EA
217        *reassembledPtr = eaBuffer[i];
218        reassembledPtr++;
219
220        // 128 from the RAD
221        int start = i * RAD_BYTES_PER_BLOCK;
222//        int end = (i + 1 ) * RAD_BYTES_PER_BLOCK;
223        memcpy( reassembledPtr, radBuffer + start, RAD_BYTES_PER_BLOCK );
224        reassembledPtr += RAD_BYTES_PER_BLOCK;
225    }
226
227}
228}
Note: See TracBrowser for help on using the repository browser.