Nektar++
sha1.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: sha1.h
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35/*
36 Copyright (c) 2011, Micael Hildenborg
37 All rights reserved.
38
39 Redistribution and use in source and binary forms, with or without
40 modification, are permitted provided that the following conditions are met:
41 * Redistributions of source code must retain the above copyright
42 notice, this list of conditions and the following disclaimer.
43 * Redistributions in binary form must reproduce the above copyright
44 notice, this list of conditions and the following disclaimer in the
45 documentation and/or other materials provided with the distribution.
46 * Neither the name of Micael Hildenborg nor the
47 names of its contributors may be used to endorse or promote products
48 derived from this software without specific prior written permission.
49
50 THIS SOFTWARE IS PROVIDED BY Micael Hildenborg ''AS IS'' AND ANY
51 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
52 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
53 DISCLAIMED. IN NO EVENT SHALL Micael Hildenborg BE LIABLE FOR ANY
54 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
55 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
56 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
57 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 */
61
62#ifndef SHA1_DEFINED
63#define SHA1_DEFINED
64
65#include <string>
66
67using std::string;
68
69namespace sha1
70{
71/**
72 * @brief Calculate the SHA1 hash of some data set.
73 *
74 * @param src Points to any kind of data to be hashed.
75 * @param bytelength The number of bytes to hash from the src pointer.
76 * @param hash Points to a buffer of at least 20 bytes of size for
77 * storing the sha1 result in.
78 */
79void calc(const void *src, const int bytelength, unsigned char *hash);
80
81/**
82 * @brief Calculate a string which represents the SHA1 hash as a hexadecimal
83 * number.
84 *
85 * @param hash is 20 bytes of sha1 hash. This is the same data that is
86 * the result from the calc function.
87 * @param hexstring should point to a buffer of at least 41 bytes of size
88 * for storing the hexadecimal representation of the
89 * hash. A zero will be written at position 40, so the
90 * buffer will be a valid zero ended string.
91 */
92void toHexString(const unsigned char *hash, char *hexstring);
93} // namespace sha1
94
95#endif // SHA1_DEFINED
Definition: sha1.cpp:72
void toHexString(const unsigned char *hash, char *hexstring)
Calculate a string which represents the SHA1 hash as a hexadecimal number.
Definition: sha1.cpp:213
void calc(const void *src, const int bytelength, unsigned char *hash)
Calculate the SHA1 hash of some data set.
Definition: sha1.cpp:150