1 /******************************************************************************* 2 * Copyright 2002-2018 Intel Corporation 3 * All Rights Reserved. 4 * 5 * If this software was obtained under the Intel Simplified Software License, 6 * the following terms apply: 7 * 8 * The source code, information and material ("Material") contained herein is 9 * owned by Intel Corporation or its suppliers or licensors, and title to such 10 * Material remains with Intel Corporation or its suppliers or licensors. The 11 * Material contains proprietary information of Intel or its suppliers and 12 * licensors. The Material is protected by worldwide copyright laws and treaty 13 * provisions. No part of the Material may be used, copied, reproduced, 14 * modified, published, uploaded, posted, transmitted, distributed or disclosed 15 * in any way without Intel's prior express written permission. No license under 16 * any patent, copyright or other intellectual property rights in the Material 17 * is granted to or conferred upon you, either expressly, by implication, 18 * inducement, estoppel or otherwise. Any license under such intellectual 19 * property rights must be express and approved by Intel in writing. 20 * 21 * Unless otherwise agreed by Intel in writing, you may not remove or alter this 22 * notice or any other notice embedded in Materials by Intel or Intel's 23 * suppliers or licensors in any way. 24 * 25 * 26 * If this software was obtained under the Apache License, Version 2.0 (the 27 * "License"), the following terms apply: 28 * 29 * You may not use this file except in compliance with the License. You may 30 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 31 * 32 * 33 * Unless required by applicable law or agreed to in writing, software 34 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 35 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 36 * 37 * See the License for the specific language governing permissions and 38 * limitations under the License. 39 *******************************************************************************/ 40 41 /* 42 // 43 // Purpose: 44 // Cryptography Primitive. 45 // Digesting message according to MD5 46 // (derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm) 47 // 48 // Equivalent code is available from RFC 1321. 49 // 50 // Contents: 51 // MD4 methods and constants 52 // 53 */ 54 55 #include "owndefs.h" 56 #include "owncp.h" 57 #include "pcphash.h" 58 #include "pcphash_rmf.h" 59 #include "pcptool.h" 60 61 #if !defined(_PCP_MD5_STUFF_H) 62 #define _PCP_MD5_STUFF_H 63 64 /* MD5 constants */ 65 static const Ipp32u md5_iv[] = { 66 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476}; 67 68 static __ALIGN16 const Ipp32u md5_cnt[] = { 69 0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE, 70 0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501, 71 0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE, 72 0x6B901122, 0xFD987193, 0xA679438E, 0x49B40821, 73 74 0xF61E2562, 0xC040B340, 0x265E5A51, 0xE9B6C7AA, 75 0xD62F105D, 0x02441453, 0xD8A1E681, 0xE7D3FBC8, 76 0x21E1CDE6, 0xC33707D6, 0xF4D50D87, 0x455A14ED, 77 0xA9E3E905, 0xFCEFA3F8, 0x676F02D9, 0x8D2A4C8A, 78 79 0xFFFA3942, 0x8771F681, 0x6D9D6122, 0xFDE5380C, 80 0xA4BEEA44, 0x4BDECFA9, 0xF6BB4B60, 0xBEBFBC70, 81 0x289B7EC6, 0xEAA127FA, 0xD4EF3085, 0x04881D05, 82 0xD9D4D039, 0xE6DB99E5, 0x1FA27CF8, 0xC4AC5665, 83 84 0xF4292244, 0x432AFF97, 0xAB9423A7, 0xFC93A039, 85 0x655B59C3, 0x8F0CCC92, 0xFFEFF47D, 0x85845DD1, 86 0x6FA87E4F, 0xFE2CE6E0, 0xA3014314, 0x4E0811A1, 87 0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391 88 }; 89 90 static void md5_hashInit(void* pHash) 91 { 92 /* setup initial digest */ 93 ((Ipp32u*)pHash)[0] = md5_iv[0]; 94 ((Ipp32u*)pHash)[1] = md5_iv[1]; 95 ((Ipp32u*)pHash)[2] = md5_iv[2]; 96 ((Ipp32u*)pHash)[3] = md5_iv[3]; 97 } 98 99 static void md5_hashUpdate(void* pHash, const Ipp8u* pMsg, int msgLen) 100 { 101 UpdateMD5(pHash, pMsg, msgLen, md5_cnt); 102 } 103 104 static void md5_hashOctString(Ipp8u* pMD, void* pHashVal) 105 { 106 /* md5 does not need conversion into big endian */ 107 ((Ipp32u*)pMD)[0] = ((Ipp32u*)pHashVal)[0]; 108 ((Ipp32u*)pMD)[1] = ((Ipp32u*)pHashVal)[1]; 109 ((Ipp32u*)pMD)[2] = ((Ipp32u*)pHashVal)[2]; 110 ((Ipp32u*)pMD)[3] = ((Ipp32u*)pHashVal)[3]; 111 } 112 113 static void md5_msgRep(Ipp8u* pDst, Ipp64u lenLo, Ipp64u lenHi) 114 { 115 UNREFERENCED_PARAMETER(lenHi); 116 lenLo <<= 3; 117 ((Ipp64u*)(pDst))[0] = lenLo; 118 } 119 120 #define cpFinalizeMD5 OWNAPI(cpFinalizeMD5) 121 122 void cpFinalizeMD5(DigestMD5 pHash, const Ipp8u* inpBuffer, int inpLen, Ipp64u processedMsgLen); 123 124 #endif /* #if !defined(_PCP_MD5_STUFF_H) */ 125