| 1 | /************************************************************************* |
| 2 | * Copyright (C) 2002 Intel Corporation |
| 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 | // |
| 19 | // Purpose: |
| 20 | // Cryptography Primitive. |
| 21 | // Digesting message according to MD5 |
| 22 | // (derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm) |
| 23 | // |
| 24 | // Equivalent code is available from RFC 1321. |
| 25 | // |
| 26 | // Contents: |
| 27 | // cpFinalizeMD5() |
| 28 | // |
| 29 | */ |
| 30 | |
| 31 | #include "owndefs.h" |
| 32 | #include "owncp.h" |
| 33 | #include "hash/pcphash.h" |
| 34 | #include "hash/pcphash_rmf.h" |
| 35 | #include "pcptool.h" |
| 36 | #include "hash/md5/pcpmd5stuff.h" |
| 37 | |
| 38 | /* |
| 39 | // Compute digest |
| 40 | */ |
| 41 | /* clang-format off */ |
| 42 | IPP_OWN_DEFN(void, cpFinalizeMD5, (DigestMD5 pHash, |
| 43 | const Ipp8u* inpBuffer, |
| 44 | int inpLen, |
| 45 | Ipp64u processedMsgLen)) |
| 46 | /* clang-format on */ |
| 47 | { |
| 48 | /* local buffer and it length */ |
| 49 | Ipp8u buffer[MBS_MD5 * 2]; |
| 50 | int bufferLen = inpLen < (MBS_MD5 - (int)MLR_MD5) ? MBS_MD5 : MBS_MD5 * 2; |
| 51 | |
| 52 | /* copy rest of message into internal buffer */ |
| 53 | CopyBlock(inpBuffer, buffer, (cpSize)inpLen); |
| 54 | |
| 55 | /* pad message */ |
| 56 | buffer[inpLen++] = 0x80; |
| 57 | PadBlock(0, buffer + inpLen, (cpSize)(bufferLen - inpLen - (int)MLR_MD5)); |
| 58 | |
| 59 | /* put processed message length in bits */ |
| 60 | processedMsgLen <<= 3; |
| 61 | ((Ipp64u*)(buffer + bufferLen))[-1] = processedMsgLen; |
| 62 | |
| 63 | /* complete hash computation */ |
| 64 | UpdateMD5(pHash, buffer, bufferLen, MD5_cnt); |
| 65 | } |