1 // Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef OPENSSL_HEADER_MD5_H
16 #define OPENSSL_HEADER_MD5_H
17 
18 #include <openssl/base.h>   // IWYU pragma: export
19 
20 #if defined(__cplusplus)
21 extern "C" {
22 #endif
23 
24 
25 // MD5.
26 
27 
28 // MD5_CBLOCK is the block size of MD5.
29 #define MD5_CBLOCK 64
30 
31 // MD5_DIGEST_LENGTH is the length of an MD5 digest.
32 #define MD5_DIGEST_LENGTH 16
33 
34 // MD5_Init initialises |md5| and returns one.
35 OPENSSL_EXPORT int MD5_Init(MD5_CTX *md5);
36 
37 // MD5_Update adds |len| bytes from |data| to |md5| and returns one.
38 OPENSSL_EXPORT int MD5_Update(MD5_CTX *md5, const void *data, size_t len);
39 
40 // MD5_Final adds the final padding to |md5| and writes the resulting digest to
41 // |out|, which must have at least |MD5_DIGEST_LENGTH| bytes of space. It
42 // returns one.
43 OPENSSL_EXPORT int MD5_Final(uint8_t out[MD5_DIGEST_LENGTH], MD5_CTX *md5);
44 
45 // MD5 writes the digest of |len| bytes from |data| to |out| and returns |out|.
46 // There must be at least |MD5_DIGEST_LENGTH| bytes of space in |out|.
47 OPENSSL_EXPORT uint8_t *MD5(const uint8_t *data, size_t len,
48                             uint8_t out[MD5_DIGEST_LENGTH]);
49 
50 // MD5_Transform is a low-level function that performs a single, MD5 block
51 // transformation using the state from |md5| and 64 bytes from |block|.
52 OPENSSL_EXPORT void MD5_Transform(MD5_CTX *md5,
53                                   const uint8_t block[MD5_CBLOCK]);
54 
55 struct md5_state_st {
56   uint32_t h[4];
57   uint32_t Nl, Nh;
58   uint8_t data[MD5_CBLOCK];
59   unsigned num;
60 };
61 
62 
63 #if defined(__cplusplus)
64 }  // extern C
65 #endif
66 
67 #endif  // OPENSSL_HEADER_MD5_H
68