⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 app_md5.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 * APP_MD5.C
 *
 * Project:
 * --------
 *   MAUI
 *
 * Description:
 * ------------
 *   This file is intends for MD5 algorithm.
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/
#include "kal_release.h"        /* Basic data type */
#include "fs_type.h"
#include "fs_func.h"
#include "app_md5.h"

#ifdef __STDC__
#define UL(x)     x##U
#else 
#define UL(x)     x
#endif 

/* F, G, H and I are basic MD5 functions */
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/* ROTATE_LEFT rotates x left n bits */
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))

// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 
// Rotation is separate from addition to prevent recomputation 

#define FF(a, b, c, d, x, s, ac){(a) += F ((b), (c), (d)) + (x) + (kal_uint32)(ac);(a) = ROTATE_LEFT ((a), (s));(a) += (b);}
#define GG(a, b, c, d, x, s, ac){(a) += G ((b), (c), (d)) + (x) + (kal_uint32)(ac);(a) = ROTATE_LEFT ((a), (s));(a) += (b);}
#define HH(a, b, c, d, x, s, ac){(a) += H ((b), (c), (d)) + (x) + (kal_uint32)(ac);(a) = ROTATE_LEFT ((a), (s));(a) += (b);}
#define II(a, b, c, d, x, s, ac){(a) += I ((b), (c), (d)) + (x) + (kal_uint32)(ac);(a) = ROTATE_LEFT ((a), (s));(a) += (b);}

#define S11 7
#define S12 12
#define S13 17
#define S14 22
#define S21 5
#define S22 9
#define S23 14
#define S24 20
#define S31 4
#define S32 11
#define S33 16
#define S34 23
#define S41 6
#define S42 10
#define S43 15
#define S44 21

/* forward declaration */

static void Transform(kal_uint32 *buf, kal_uint32 *in);

static const kal_uint8 PADDING[64] = 
{
    0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

// The routine MD5Init initializes the message-digest context
//   mdContext. All fields are set to zero.


/*****************************************************************************
 * FUNCTION
 *  applib_md5_init
 * DESCRIPTION
 *  
 * PARAMETERS
 *  mdContext       [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void applib_md5_init(applib_md5_ctx *mdContext)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mdContext->i[0] = mdContext->i[1] = (kal_uint32) 0;

    /* Load magic initialization constants. */

    mdContext->buf[0] = (kal_uint32) 0x67452301;
    mdContext->buf[1] = (kal_uint32) 0xefcdab89;
    mdContext->buf[2] = (kal_uint32) 0x98badcfe;
    mdContext->buf[3] = (kal_uint32) 0x10325476;
}

// The routine MD5Update updates the message-digest context to
//   account for the presence of each of the characters in the file whose digest is being computed.


/*****************************************************************************
 * FUNCTION
 *  applib_md5_file_update
 * DESCRIPTION
 *  
 * PARAMETERS
 *  mdContext       [?]         
 *  filename        [IN]        
 * RETURNS
 *  
 *****************************************************************************/
kal_bool applib_md5_file_update(applib_md5_ctx *mdContext, const kal_wchar *filename)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint8 buffer[1024];
    kal_uint32 dataLen = 0;
    kal_uint32 fileSize = 0;
    kal_int32 fileHandle;
    kal_uint32 rd_no = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (filename == NULL || mdContext == NULL)
    {
        return KAL_FALSE;
    }

    fileHandle = FS_Open(filename, FS_READ_ONLY);
    if (fileHandle < 0)
    {
        return KAL_FALSE;
    }
    if (FS_GetFileSize(fileHandle, &fileSize) < 0)
    {
        FS_Close(fileHandle);
        return KAL_FALSE;
    }

    while (fileSize)
    {
        if (fileSize > 1024)
        {
            dataLen = 1024;
        }
        else
        {
            dataLen = fileSize;
        }

        FS_Read(fileHandle, buffer, dataLen, &rd_no);
        if (rd_no != dataLen)
        {
            ASSERT(0);
        }
        applib_md5_update(mdContext, buffer, dataLen);
        fileSize -= dataLen;
    }
    FS_Close(fileHandle);
    return KAL_TRUE;
}

// The routine MD5Update updates the message-digest context to

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -