1 /********************************************************************** 2 * Copyright (C) 2011 Intel Corporation. All rights reserved. 3 4 * Licensed under the Apache License, Version 2.0 (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 7 8 * http://www.apache.org/licenses/LICENSE-2.0 9 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. 15 **********************************************************************/ 16 17 /*! 18 * NOTE: Don't include this file. It is recommended to include sepdrm.h 19 */ 20 #ifndef __WV_DRM_API_H__ 21 #define __WV_DRM_API_H__ 22 23 #include <inttypes.h> 24 #include "drm_common_api.h" 25 #include "wv_fkp.h" 26 27 /*! 28 * Defines 29 */ 30 #define NEW_FRAME_FLAG (1) 31 #define PREV_PACKET_PARTIAL_BLOCK_FLAG (1 << 1) 32 #define CLEAR_CONTENT_FLAG (1 << 2) 33 34 /*! 35 * Structs 36 */ 37 38 /* 39 * This structure is used to provide necessary information for Widevine audio 40 * ciphertext decryption. 41 * 42 * The members are: 43 * 44 * iv - AES initialization vector. 45 * input_ciphertext_size - Input ciphertext data size in bytes. 46 * p_input_ciphertext - Pointer to the input ciphertext data buffer. 47 * output_plaintext_size - Output plaintext data size in bytes. 48 * p_output_plaintext - Pointer to the output plaintext data buffer. 49 */ 50 struct drm_wv_audio_data 51 { 52 uint8_t iv[AES_IV_COUNTER_SIZE_IN_BYTES]; 53 uint32_t input_ciphertext_size; 54 uint8_t *p_input_ciphertext; 55 uint32_t output_plaintext_size; 56 uint8_t *p_output_plaintext; 57 }; 58 59 60 /* 61 * This structure is used to provide necessary information for Widevine video 62 * ciphertext decryption. 63 * 64 * The members are: 65 * 66 * iv - AES initialization vector. 67 * input_ciphertext_size - Input ciphertext data size in bytes. 68 * p_input_ciphertext - Pointer to the input ciphertext data. 69 */ 70 struct drm_wv_video_cipher 71 { 72 uint8_t iv[AES_IV_COUNTER_SIZE_IN_BYTES]; 73 uint32_t input_ciphertext_size; 74 uint8_t *p_input_ciphertext; 75 uint8_t flags; 76 uint8_t *p_output_enc_ciphertext; 77 uint32_t output_ciphertext_size; 78 }; 79 80 struct drm_wv_nalu_headers 81 { 82 uint32_t frame_size; 83 uint32_t parse_size; 84 uint8_t *p_enc_ciphertext; 85 uint32_t hdrs_buf_len; 86 uint8_t *p_hdrs_buf; 87 }; 88 89 /*! 90 * Functions 91 */ 92 93 94 /* 95 * Set Widevine Asset Key 96 */ 97 uint32_t drm_wv_set_entitlementkey( 98 uint8_t *emm_keyptr, 99 uint32_t emm_keylen); 100 101 /* 102 * Derive Widevine Control Word 103 */ 104 uint32_t drm_wv_derive_controlword( 105 uint8_t *cw_ptr, 106 uint32_t cw_len, 107 uint32_t *flags_ptr); 108 109 /* 110 * Get Widevine Keybox infomation 111 * Retrieve the encypted kbox data and decrypt the encrypted kbox data 112 */ 113 uint32_t drm_wv_get_keyboxinfo( 114 uint8_t *key_data, 115 uint32_t *key_data_size, 116 uint8_t *device_id, 117 uint32_t *device_id_size); 118 119 120 /*! 121 *@brief Create a widevine session 122 * 123 */ 124 uint32_t drm_wv_create_session( 125 uint32_t *session_id); 126 127 128 /* 129 * @brief Creates a Widevine session for HLS content. 130 * @param[out] pSessionID Pointer to a variable that contains the session's ID 131 * number. 132 */ 133 uint32_t drm_wv_hls_create_session( 134 uint32_t *session_id); 135 136 /* 137 * @brief Decrypts Widevine encrypted audio data 138 * 139 * @param session_id DRM Session ID number 140 * @param audio_info Pointer to a buffer containing Widevine audio information 141 * 142 * @return DRM_SUCCESSFUL The Widevine audio ciphertext was decrypted 143 */ 144 uint32_t drm_wv_decrypt_audio( 145 uint32_t session_id, 146 struct drm_wv_audio_data *audio_info); 147 148 149 /* 150 * @brief Decrypts Widevine video ciphertext data into the IMR decryption buffer 151 * @param session_id DRM Session ID number 152 * @param video_info Pointer to the Widevine video data 153 */ 154 uint32_t drm_wv_decrypt_video( 155 uint32_t session_id, 156 struct drm_wv_video_cipher *video_info); 157 158 159 uint32_t drm_wv_return_naluheaders( 160 uint32_t session_id, 161 struct drm_wv_nalu_headers *nalu_info); 162 163 uint32_t drm_wv_keybox_provision( 164 struct wv_keybox *buf); 165 166 167 /* 168 * @brief Encrypts a Widevine keybox with a device specific key. 169 * 170 * @param[in] p_keybox Pointer to a Widevine keybox. May be NULL if 171 * keybox_length is zero. 172 * 173 * @param[in] keybox_length Length of the Widevine keybox in bytes. If zero then 174 * only the size of an encrypted Widevine keybox is returned. 175 * 176 * @param[out] p_wrapped_keybox Pointer to a buffer for the returned encrypted 177 * Widevine keybox. May be NULL if keybox_length is zero. 178 * 179 * @param[out] p_wrapped_keybox_length Length of the encrypted Widevine keybox 180 * in bytes. 181 * 182 * @param[in] p_transport_key Pointer to a transport key. May be NULL if 183 * transport_key_length is zero. 184 * 185 * @param[in] transport_key_length Length of the transport key in bytes. 186 * 187 * A Widevine keybox encrypted with the transport key is not supported. 188 */ 189 uint32_t drm_wv_wrap_keybox(const uint8_t * const p_keybox, 190 const uint32_t keybox_length, 191 uint8_t * const p_wrapped_keybox, 192 uint32_t * const p_wrapped_keybox_length, 193 const uint8_t * const p_transport_key, 194 const uint32_t transport_key_length); 195 196 197 /* 198 * @brief Decrypts a wrapped Widevine keybox and installs it into the device. 199 * 200 * @param[in] p_keybox Pointer to a wrapped Widevine keybox. 201 * 202 * @param[in] keybox_length Length of the Widevine keybox in bytes. 203 */ 204 uint32_t drm_wv_install_keybox(const uint8_t * const p_keybox, 205 const uint32_t keybox_length); 206 207 208 /*! 209 * @brief Erases installed Widevine keybox from secure storage 210 */ 211 uint32_t drm_wv_remove_keybox(void); 212 213 /** 214 * @brief Temporarily loads test keybox. 215 */ 216 uint32_t drm_wv_load_test_keybox(void); 217 218 #endif //__WV_DRM_API_H__ 219