1 #ifndef _VKMD5SUM_HPP 2 #define _VKMD5SUM_HPP 3 /*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2023 The Khronos Group Inc. 8 * Copyright (c) 2023 The SQLite Project. 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 * 22 *//*! 23 * \file 24 * \brief Utilities for calculating MD5 checksums. 25 * 26 * This file was modified from Chromium, 27 * https://chromium.googlesource.com/chromium/src/base/+/7ef85b701132474f71e6369f081a2fb84582ee88/md5.h 28 * 29 * This code implements the MD5 message-digest algorithm. 30 * The algorithm is due to Ron Rivest. This code was 31 * written by Colin Plumb in 1993, no copyright is claimed. 32 * This code is in the public domain; do with it what you wish. 33 * 34 * Equivalent code is available from RSA Data Security, Inc. 35 * This code has been tested against that, and is equivalent, 36 * except that you don't need to include two pages of legalese 37 * with every copy. 38 * 39 * To compute the message digest of a chunk of bytes, declare an 40 * MD5Context structure, pass it to MD5Init, call MD5Update as 41 * needed on buffers full of bytes, and then call MD5Final, which 42 * will fill a supplied 16-byte array with the digest. 43 *--------------------------------------------------------------------*/ 44 45 #include <cstdint> 46 #include <deDefs.h> 47 #include <string> 48 49 namespace vk 50 { 51 52 // The output of an MD5 operation. 53 struct MD5Digest 54 { 55 unsigned char a[16]; 56 }; 57 58 // Used for storing intermediate data during an MD5 computation. Callers 59 // should not access the data. 60 typedef char MD5Context[88]; 61 62 void MD5Sum(const void *data, std::size_t length, MD5Digest *digest); 63 64 void MD5Init(MD5Context *context); 65 void MD5Update(MD5Context *context, const uint8_t *data, std::size_t len); 66 void MD5Final(MD5Digest *digest, MD5Context *context); 67 68 // Converts a digest into human-readable hexadecimal. 69 std::string MD5DigestToBase16(const MD5Digest &digest); 70 71 // Helper for doing the common case of MD5Sum followed by MD5DigestToBase16. 72 std::string MD5SumBase16(const void *data, std::size_t length); 73 74 } // namespace vk 75 76 #endif // _VKMD5SUM_HPP 77