📄 drmpd.h
字号:
/*
************************************************************************************************************************
*
* Copyright (C),2006, Fuzhou Rockchip Co.,Ltd.
*
* File name : drmpd.h
* Author: hwg, zsx, zym
* Description:
* Remark:
*
* History:
* <author> <time> <version> <desc>
* 06/8/21 1.0
*
************************************************************************************************************************
*/
#ifndef __DRMPD_H__
#define __DRMPD_H__
//#include "string.h"
//#include "memory.h"
//#include "assert.h"
#include "drmtype.h"
/*
* DEFINES
*/
#define IN
#define OUT
#define SIXTEEN_BIT_ADDRESSING 1
#define DEBUG 0
#define Null ((void *)0)
#define DRM_SUCCESS 0
#define BUFFER_TOO_SMALL 1
#define DRM_NOTINITIALIZED 3
#define RC4_TABLESIZE 256
#define DES_KEYSIZE 8
#define SHA_BLOCK_SIZE 64 /*Sha operates on 64 BYTE blocks */
#define SHA_DIGEST_LEN 20
#define DES_BLOCKLEN 8
#define DES_DECRYPT 0
//#define COPYRIGHT_STRING_OFFSET 6
//#define COPYRIGHT_STRING_CHUNK_LEN 5
// license right
#define CHECK_NONSDMI_LIC 1
#define CHECK_SDMI_LIC 2
#define CHECK_ALL_LICENSE 3
#define APPSEC_LEN 4
#define DATE_LEN 4
#define RIGHTS_LEN 4
/*
* MACROS
*/
#if SIXTEEN_BIT_ADDRESSING
#define __CB_DECL(x) ((x)/2 + ((x) & 1))
#define CB_NATIVE_BYTE 2
#define GET_BYTE(pb,ib) DRM_16B_Read8BitByte((pb),(ib))
#define PUT_BYTE(pb,ib,b) DRM_16B_Write8BitByte((pb),(ib),(b))
#define STRLEN(x) ZSP_DRM_strlen(x)
#define MEMCMP(x, y, l) ZSP_DRM_memcmp(x, y, l)
#define MEMCPY(to, from, l) ZSP_DRM_memcpy(to, from, l)
#else
#define __CB_DECL(x) (x)
#define CB_NATIVE_BYTE 1
//#define UWORD32_TO_UWORD64(x) (UWORD64)(x)
//#define SIZEOF(x) sizeof(x)
#define STRLEN(x) strlen(x)
#define MEMCMP(x, y, l) memcmp(x, y, l)
#define MEMCPY(to, from, l) memcpy(to, from, l)
#define GET_BYTE(pb,ib) (pb)[(ib)]
#define PUT_BYTE(pb,ib,b) (pb)[(ib)]=(b)
#define DRM_BYT_CopyBytes(to,tooffset,from,fromoffset,count) \
memcpy(&((to)[(tooffset)]),&((from)[(fromoffset)]),(count))
#endif
//#define BYTE2LITTLEENDIAN(dword, byte) \
// DRM_BYT_CopyBytes((DRM_BYTE*)&(dword),0,(byte),0,4)
//#define BYTES_TO_DWORD BYTE2LITTLEENDIAN
//#define DWORD2LITTLEENDIAN( byte, dword ) \
// DRM_BYT_CopyBytes((byte),0,(DRM_BYTE*)&(dword),0,4)
//#define DWORD_TO_BYTES DWORD2LITTLEENDIAN
#define WORDSWAP(d) ( ( ( (d) >> 16 ) | ( (d) << 16 ) & 0xFFFF0000) )
//#define WORDSWAP(d) ( ( ( (d) >> 16 ) | ( (d) << 16 ) ) )
/* pairwise independent function and summing step */
#define MP_C_STEP_P(pbData,L1, L2, L3, L4, L5, L6, t, sum) \
{\
UWORD32 dwTemp = 0;\
dwTemp = *((DRM_DWORD*)pbData);\
pbData += 4/CB_NATIVE_BYTE;\
t += dwTemp; \
t *= L1; \
t = WORDSWAP(t); \
t *= L2; \
t = WORDSWAP(t); \
t *= L3; \
t = WORDSWAP(t); \
t *= L4; \
t = WORDSWAP(t); \
t *= L5; \
t += L6; \
sum += t; \
}
#define MP_C_STEP_P__(pbData, flag, L1, L2, L3, L4, L5, L6, t, sum) \
{\
UWORD32 dwTemp = 0;\
DRM_BYT_CopyBytes( (DRM_BYTE*)&dwTemp, 0, pbData, flag, 4 );\
pbData += 4/CB_NATIVE_BYTE;\
t += dwTemp; \
t *= L1; \
t = WORDSWAP(t); \
t *= L2; \
t = WORDSWAP(t); \
t *= L3; \
t = WORDSWAP(t); \
t *= L4; \
t = WORDSWAP(t); \
t *= L5; \
t += L6; \
sum += t; \
}
#define MP_C_STEP(Data,L1, L2, L3, L4, L5, L6, t, sum) \
t += Data; \
t *= L1; \
t = WORDSWAP(t); \
t *= L2; \
t = WORDSWAP(t); \
t *= L3; \
t = WORDSWAP(t); \
t *= L4; \
t = WORDSWAP(t); \
t *= L5; \
t += L6; \
sum += t;
/* step to reverse action of multiply-&-swap rounds */
#define INV_STEP_C(iL1, iL2, iL3, iL4, iL5) \
tmp *= iL5; \
tmp = WORDSWAP(tmp); \
tmp *= iL4; \
tmp = WORDSWAP(tmp); \
tmp *= iL3; \
tmp = WORDSWAP(tmp); \
tmp *= iL2; \
tmp = WORDSWAP(tmp); \
tmp *= iL1;
//void memcpy(
// OUT void *dst,
// IN const void *src,
// IN UWORD32 count )
//{
// while( count > 0 )
// {
// *(DRM_BYTE*)dst = *(DRM_BYTE*)src;
// dst = (char *)dst + 1;
// src = (char *)src + 1;
// count--;
// }
//}
//#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
#define ROTATE_LEFT(x, n) rotate_left(x, n)
//#define ROTATE_RIGHT(x, n) (((x) >> (n)) | ((x) << (32-(n))))
/*
#define F(l,r,S) { \
work = ((DRM_DWORD *)pTable)[S ]; \
zork = ((DRM_DWORD *)pTable)[S+1]; \
work ^= r; \
zork ^= r; \
zork = ((zork<<28) & 0xF0000000) | (zork>>4); \
l ^= *(DRM_DWORD *)((DRM_BYTE*)_DRM_Spbox[0] + __CB_DECL((work & 0xfc))); \
l ^= *(DRM_DWORD *)((DRM_BYTE*)_DRM_Spbox[1] + __CB_DECL((zork & 0xfc))); \
l ^= *(DRM_DWORD *)((DRM_BYTE*)_DRM_Spbox[2] + __CB_DECL(((work>> 8)& 0xfc))); \
l ^= *(DRM_DWORD *)((DRM_BYTE*)_DRM_Spbox[3] + __CB_DECL(((zork>> 8)& 0xfc))); \
l ^= *(DRM_DWORD *)((DRM_BYTE*)_DRM_Spbox[4] + __CB_DECL(((work>>16)& 0xfc))); \
l ^= *(DRM_DWORD *)((DRM_BYTE*)_DRM_Spbox[5] + __CB_DECL(((zork>>16)& 0xfc))); \
l ^= *(DRM_DWORD *)((DRM_BYTE*)_DRM_Spbox[6] + __CB_DECL(((work>>24)& 0xfc))); \
l ^= *(DRM_DWORD *)((DRM_BYTE*)_DRM_Spbox[7] + __CB_DECL(((zork>>24)& 0xfc))); }
*/
#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
(b)^=(t),\
(a)^=((t)<<(n)))
#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
(a)=(a)^(t)^(t>>(16-(n))))
/*
* DATA
*/
//extern const DRM_BYTE PMSECRET_SEG0__[5];
//extern const DRM_BYTE pszCopyrightString[22];
//extern UWORD16 g_pmid[__CB_DECL(16)];
//extern UWORD32 unknown2[32];
extern const DRM_DWORD _DRM_Spbox[8][64];
extern const DRM_DWORD _DRM_Sel[8][64];
/*
* STRUCTURES
*/
typedef struct _CBCKey
{
UWORD32 a1, b1, c1, d1, e1, f1, a2, b2, c2, d2, e2, f2;
} DRM_CBCKey; // 24 WORD16
typedef struct __tagCBCState
{
UWORD32 sum,t;
DRM_BYTE buf[__CB_DECL(8)];
LENGTH_TYPE dwBufLen;
} DRM_CBCState; // 10 WORD16
typedef struct tag_RC4_KEYSTRUCT
{
DRM_BYTE S[__CB_DECL(256)]; /* State table */
DRM_BYTE i, j; /* Indices */
} RC4_KEYSTRUCT; // 129 WORD16
typedef struct _destable
{
UWORD32 keytab[16][2]; // 64 WORD16
DRM_BYTE mem2[__CB_DECL(16)]; // 8 WORD16
} DESTable; // 72 WORD16
typedef struct __tagSHA_CONTEXT
{
DRM_BYTE id[__CB_DECL(24)]; // 12 WORD16
UWORD32 ABCDE[5]; // 10 WORD16
UWORD32 dwHighByteCount; // 2 WORD16
UWORD32 dwLowByteCount; // 2 WORD16
DRM_BYTE bTempBuffer[__CB_DECL(64)]; // 32 WORD16
} SHA_CONTEXT; // 58 WORD16
typedef struct tag_LIC_Data
{
DRM_BYTE KID[__CB_DECL(25)]; // 25 byte
DRM_BYTE PMContentKey[__CB_DECL(16)]; // 16 byte
DRM_BYTE rights[__CB_DECL(4)]; // 2 WORD16
DRM_BYTE appSec[__CB_DECL(4)]; // 2 WORD16
DRM_BYTE expiryDate[__CB_DECL(4)]; // 2 WORD16
DRM_BYTE mem4; // 11 byte 好像没用
UWORD16 mem5; // 好像没用
UWORD16 cbContentKey;
UWORD16 mem7; // 好像没用
UWORD16 mem8;
UWORD16 mem9;
} LIC_Data; // 32 WORD16
typedef struct tag_CIPHER_CONTEXT
{ // 与DRM_CIPHER_CONTEXT类似
DRM_CBCKey m_mackey, // 24 WORD16
m_invmackey; // 24 WORD16 #0x30
DRM_CBCState m_cbcstate;// 10 WORD16 #0x60
UWORD32 m_rc4key[2]; // 4 WORD16 #0x74
DRM_BYTE m_shaOut[__CB_DECL(20)]; // 10 WORD16 #0x7c
DRM_BYTE m_fInited; // 1 Byte #0x90
DRM_BYTE m_fDecryptInited; // 1 Byte #0x91
// WORD16 mem31; // 1 WORD16 可能没用
LENGTH_TYPE m_cbPacket; // 2 WORD16 #0x94
LENGTH_TYPE m_iPacket; // 2 WORD16 #0x98
UWORD32 m_desS1[2], // 4 WORD16 #0x9c
m_desS2[2]; // 4 WORD16 #0xa4
RC4_KEYSTRUCT m_rc4ks; // 129 WORD16 #0xac
// WORD16 mem341; // 1 WORD16 可能没用
DESTable m_destable; // 72 WORD16 #0x1b0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -