Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MD5HashAlgorithm.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* MD5HashAlgorithm.cc (C) 2000-2023 */
9/* */
10/* Calculates the MD5 hashing function. */
11/*---------------------------------------------------------------------------*/
12
13#include "arcane/utils/StdHeader.h"
14#include "arcane/utils/MD5HashAlgorithm_Licensed.h"
15#include "arcane/utils/MD5HashAlgorithm.h"
16#include "arcane/utils/Array.h"
17#include "arcane/utils/Iostream.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace
29{
30 void _computeHash64(Span<const std::byte> input, ByteArray& output)
31 {
32 unsigned char buf[16];
33 _md5_buffer((const char*)input.data(), input.size(), buf);
34
35 for (int i = 0; i < 16; ++i) {
36 output.add(buf[i]);
37 }
38 }
39} // namespace
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
44MD5HashAlgorithm::
45MD5HashAlgorithm()
46{
47}
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51
54{
55 Span<const Byte> input64(input);
56 return _computeHash64(asBytes(input64), output);
57}
58
59/*---------------------------------------------------------------------------*/
60/*---------------------------------------------------------------------------*/
61
64{
65 Span<const std::byte> bytes(asBytes(input));
66 return _computeHash64(bytes, output);
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
74{
75 return _computeHash64(input, output);
76}
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
81} // namespace Arcane
82
83/*---------------------------------------------------------------------------*/
84/*---------------------------------------------------------------------------*/
void computeHash(ByteConstArrayView input, ByteArray &output) override
Calculates the hash value for the array input.
void computeHash64(Span< const Byte > input, ByteArray &output) override
Calculates the hash value for the array input.
View of an array of elements of type T.
Definition Span.h:635
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< Byte > ByteArray
Dynamic one-dimensional array of characters.
Definition UtilsTypes.h:121
Impl::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of non-modifiable bytes.
Definition Span.h:1032
ConstArrayView< Byte > ByteConstArrayView
C equivalent of a 1D array of characters.
Definition UtilsTypes.h:476