2 * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include "CPointerArray.h"
25 #include "CXMLAttribute.h"
26 #include "CXMLElement.h"
29 #define STACKTRACE(pszFunction) // RETAILMSG(1, pszFunction);
32 #define IF_ERROR_RETURN( error , errcode) if(error < 0){DRM_TAPPS_EXCEPTION("TADC Debug Error Code = %x", errcode); return error;}
33 #define IF_TRUE_RETURN( error , errcode) if(error){DRM_TAPPS_EXCEPTION("TADC Debug Error Code = %x", errcode); return -1;}
36 #define IF_TRUE_RETURN2( error , do1, do2, do3, errcode) if(error){ do1; do2; do3; DRM_TAPPS_EXCEPTION("TADC Debug Error Code = %x", errcode); return -1;}
39 #define TADC_SWAP32(x) ((((TADC_U32)(x) & 0x000000ffL) << 24) | (((TADC_U32)(x) & 0x0000ff00L) << 8) | (((TADC_U32)(x) & 0x00ff0000L) >> 8) | (((TADC_U32)(x) & 0xff000000L) >> 24))
42 #define TADC_U8 unsigned char
43 #define TADC_U16 unsigned short
44 #define TADC_U32 unsigned long
45 #define DWORD unsigned long
46 #define LPBYTE unsigned char*
47 #define TCHAR unsigned char
49 #define BYTE unsigned char
50 #define UINT unsigned int
51 #define ULONG unsigned long
53 #define INT64 long long
58 #define REQU_MAXSIZE 1024*5 //2011.03.08 (HTTP Request Buffer Max Size)
59 #define RESP_MAXSIZE 1024*10 //2011.03.08 (HTTP Response Buffer Max Size)
61 #define ROXML_MAXSIZE 4096*2 //2011.03.08
62 #define CERT_MAXSIZE 4096 //2011.03.08
65 #define CID_SIZE 1024 //2011.03.08 ( 32 -> 1024 )
66 #define CEK_SIZE 32 // multiplication of 8
69 // Core Value Size define
71 #define DEVICEKEY_SIZE 16
73 #define DHKey_SIZE 128 //Max 1024 bit
75 // DRM Type : Tizen DRM DRM - 1
84 typedef struct t_file_header
86 unsigned char Version[2];
87 unsigned char DRMType;
88 unsigned char ContentsType[128];
100 typedef struct t_drm_header
103 unsigned char Version[2];
106 unsigned char ContentsType[128];
107 long EncryptionMethod;
108 long EncryptionLevel;
109 long long EncryptionRange;
110 unsigned char *RIURL;
111 long long PlaintextSize;
112 unsigned char *Packdate;
116 typedef struct t_decice_info
118 unsigned char DUID[DUID_SIZE + 1];
121 typedef struct t_dh_info
123 unsigned char p[DHKey_SIZE+1]; // DH prime binary
125 long g; // DH primitive root. ( 2 or 5 )
126 unsigned char a[DHKey_SIZE+1]; // DH Client private binary
128 unsigned char A[DHKey_SIZE+1]; // DH Client public binary (ga mod p)
130 unsigned char B[DHKey_SIZE+1]; // DH Server public binary (gb mod p)
132 unsigned char K[32+1]; // DH Session Key
135 typedef struct t_ro_content
141 typedef struct t_roacq_info
143 unsigned char* ROAcqURL;
144 unsigned char* ReqID;
146 unsigned char sTimeStamp[21];
149 typedef struct t_individual
151 unsigned char BindingType;
155 typedef struct t_ro_permission
157 T_INDIVIDUAL t_Individual;
164 T_RO_CONTENT t_Content;
165 T_RO_PERMISSION t_Permission;
168 int TADC_SetDeviceInfo(T_DEVICE_INFO *t_DeviceInfo);
169 int TADC_GetFileHeader(unsigned char *inBuffer, T_FILE_HEADER *t_FileHeader);
170 int TADC_GetDRMHeader(unsigned char *inBuffer, T_DRM_HEADER *t_DRMHeader);
171 int TADC_GetDRMHeaderInfo(unsigned char * inBuffer, T_DRM_HEADER *t_DRMHeader);
172 int TADC_GetDRMHeaderFromFile(const char *pTADCFilepath, T_FILE_HEADER *t_FileHeader, T_DRM_HEADER *t_DRMHeader);
173 int TADC_MakeRequestLicense(T_DEVICE_INFO *t_DeviceInfo, T_FILE_HEADER *t_FileHeader, T_DRM_HEADER *t_DRMHeader, unsigned char * outBuffer, size_t outBufferSize);
174 int TADC_GetROAcqInfo(unsigned char *inBuffer, T_ROACQ_INFO *t_ROAcqInfo);
175 int TADC_MakeRequestRO(T_ROACQ_INFO *t_ROAcqInfo, unsigned char *outBuffer, size_t outBufferSize, unsigned char *ROVer=NULL); //2011.03.08
176 int TADC_GetResponseRO(unsigned char *inBuffer, T_ROACQ_INFO *t_ROAcqInfo, T_RO *t_RO, unsigned char *outBuffer);
177 int TADC_GetResponseROInfo(LPBYTE pszXML, T_RO *t_RO);
178 int TADC_GetHashReqID(unsigned char *inBuffer, unsigned char *hashReqID);
179 int TADC_GetCEK(T_DEVICE_INFO *t_DeviceInfo, T_RO *t_RODB, T_DRM_HEADER *t_DRMHeader );
180 int TADC_DecryptBlock(char* pbBuffer, int nSize, const T_DRM_HEADER *t_DRMHeader);
181 int TADC_VerifyROSignature(IN LPBYTE pszXML);
182 DWORD TADC_GetLastError(void);
183 int TADC_MEMFree_RO(T_RO *t_ro);
184 int TADC_MEMFree_FileHeader(T_FILE_HEADER *t_FileHeader);
185 int TADC_MEMFree_DRMHeader(T_DRM_HEADER *t_DrmHeader);
186 int TADC_MEMFree_ROAcqInfo(T_ROACQ_INFO *t_ROAcqInfo);