/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * 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 https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 *
 * $Author: xiaojun.zhu $
 * $Date: 2015/08/08 $
 * $RCSfile: dmx_if.h,v $
 * $Revision: #2 $
 *
 *---------------------------------------------------------------------------*/

/** @file dmx_if.h
 *  Interface of demux driver
 */


#ifndef DMX_DRM_IF_H
#define DMX_DRM_IF_H

//-----------------------------------------------------------------------------
// Include files
//-----------------------------------------------------------------------------
#include "dmx_if.h"
#include "dmx_mm_if.h"

//-----------------------------------------------------------------------------
// Configurations
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Constant definitions
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Type definitions
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Macro definitions
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Prototype  of inter-file functions
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Prototype  of public functions
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
/** DMX_NAND_AES_INIT
 *  NAND AES Initialization
 *
 *  @param  pu1Key          key pointer
 *  @param  u2KeyLen        key length [128|192|256]
 *
 *  @retval TRUE            Succeed
 *  @retval FALSE           Fail
 */
//-----------------------------------------------------------------------------
BOOL DMX_NAND_AES_INIT(UINT8 *pu1Key, UINT16 u2KeyLen);


//-----------------------------------------------------------------------------
/** DMX_NAND_AES_Encryption
 *  NAND AES encryption
 *
 *  @param  u4InBufStart    input buffer address
 *  @param  u4OutBufStart   output buffer address
 *  @param  u4BufSize       buffer size
 *
 *  @retval TRUE            Succeed
 *  @retval FALSE           Fail
 */
//-----------------------------------------------------------------------------
BOOL DMX_NAND_AES_Encryption(UPTR u4InBufStart, UPTR u4OutBufStart, USIZE u4BufSize);


//-----------------------------------------------------------------------------
/** DMX_NAND_AES_Decryption
 *  NAND AES decryption
 *
 *  @param  u4InBufStart    input buffer address
 *  @param  u4OutBufStart   output buffer address
 *  @param  u4BufSize       buffer size
 *
 *  @retval TRUE            Succeed
 *  @retval FALSE           Fail
 */
//-----------------------------------------------------------------------------
BOOL DMX_NAND_AES_Decryption(UPTR u4InBufStart, UPTR u4OutBufStart, USIZE u4BufSize);

//-----------------------------------------------------------------------------
/** DMX_SHA1_Manytimes
 *  DMX_SHA1_Manytimes
 *
 *  @param  fgFirstPacket    the flag of first packet
 *  @param  fgLastPacket    the flag of last packet
 *  @param  u4BufStart    input buffer address
 *  @param  u4BufSize      buffer size ,no need 64 byte alignment
 *  @param  u1HashValue       hashvalue output buffer size;
 *  @param  u4HashValueSize       u4HashValueSize
 *
 *  @retval TRUE            Succeed
 *  @retval FALSE           Fail
 */
//-----------------------------------------------------------------------------
BOOL DMX_SHA1_Manytimes(BOOL fgFirstPacket, BOOL fgLastPacket, UPTR *u4BufStart,
						USIZE u4BufSize, UINT8 *u1HashValue, UINT32 *u4HashValueSize);


//-----------------------------------------------------------------------------
/** _DMX_SHA1_Onece
 *  NAND AES decryption
 *
 *  @param  u4BufStart    input buffer address
 *  @param  u4BufSize      buffer size ,no need 64 byte alignment
 *  @param  u1HashValue       hashvalue output buffer size;
 *  @param  u4HashValueSize       u4HashValueSize
 *
 *  @retval TRUE            Succeed
 *  @retval FALSE           Fail
 */
//-----------------------------------------------------------------------------

BOOL DMX_SHA1_Onece(UPTR *u4BufStart, USIZE u4BufSize, UINT8 *u1HashValue, UINT32 *u4HashValueSize);


//-----------------------------------------------------------------------------
/** DMX_Encrypt_Snapshot
 *  DMX_Encrypt_Snapshot
 *
 *  @param  u1HashValueIn       input clear hash value data
 *  @param  u4HashValueSize    hash value data size
 *  @param  u1HashValueOut    encrypt random aeskey address
  *  @param  u1AeskeyAddr    encrypt random aeskey address
 *  @param  u4AeskeySize    aeskey size
 *
 *  @retval TRUE            Succeed
 *  @retval FALSE           Fail
 */
//-----------------------------------------------------------------------------
BOOL DMX_Encrypt_Snapshot(UINT8 *u1HashValueIn, UINT32 u4HashValueSize, UINT8 *u1HashValueOut, 
									UINT8 *u1AeskeyAddr, UINT32 *u4AeskeySize);


//-----------------------------------------------------------------------------
/** DMX_Decrypt_Snapshot
 *  DMX_Decrypt_Snapshot
 *
 *  @param  u1HashValue_Encrypt    input encrypt hash value buffer
 *  @param  u4HashValueSize     	     hashvalue buffer size
 *  @param  u1HashValue_Clear       input cacullate hash value
 *  @param  u1AeskeyAddr    	     input aes key addr
 *  @param  u4AeskeySize  		    aed key size
 *
 *  @retval TRUE            Succeed
 *  @retval FALSE           Fail
 */
//-----------------------------------------------------------------------------


BOOL DMX_Decrypt_Snapshot(UINT8 *u1HashValue_Encrypt, UINT32 u4HashValueSize, UINT8 *u1HashValue_Clear, 
									UINT8 *u1AeskeyAddr, UINT32 u4AeskeySize);





#endif  // DMX_DRM_IF_H

