tlx
Toggle main menu visibility
Loading...
Searching...
No Matches
sha256.hpp
Go to the documentation of this file.
1
/*******************************************************************************
2
* tlx/digest/sha256.hpp
3
*
4
* Public domain implementation of SHA-256 (SHA-2) processor. Copied from
5
* https://github.com/kalven/sha-2, which is based on LibTomCrypt.
6
*
7
* Part of tlx - http://panthema.net/tlx
8
*
9
* Copyright (C) 2018 Timo Bingmann <tb@panthema.net>
10
*
11
* All rights reserved. Published under the Boost Software License, Version 1.0
12
******************************************************************************/
13
14
#ifndef TLX_DIGEST_SHA256_HEADER
15
#define TLX_DIGEST_SHA256_HEADER
16
17
#include <cstdint>
18
#include <string>
19
20
namespace
tlx
{
21
22
//! \addtogroup tlx_digest
23
//! \{
24
25
/*!
26
* SHA-256 processor without external dependencies.
27
*/
28
class
SHA256
29
{
30
public
:
31
//! construct empty object.
32
SHA256
();
33
//! construct context and process data range
34
SHA256
(
const
void
* data, std::uint32_t size);
35
//! construct context and process string
36
explicit
SHA256
(
const
std::string& str);
37
38
//! process more data
39
void
process
(
const
void
* data, std::uint32_t size);
40
//! process more data
41
void
process
(
const
std::string& str);
42
43
//! digest length in bytes
44
static
constexpr
size_t
kDigestLength
= 32;
45
46
//! finalize computation and output 32 byte (256 bit) digest
47
void
finalize
(
void
*
digest
);
48
49
//! finalize computation and return 32 byte (256 bit) digest
50
std::string
digest
();
51
//! finalize computation and return 32 byte (256 bit) digest hex encoded
52
std::string
digest_hex
();
53
//! finalize computation and return 32 byte (256 bit) digest upper-case hex
54
std::string
digest_hex_uc
();
55
56
private
:
57
std::uint64_t
length_
;
58
std::uint32_t
state_
[8];
59
std::uint32_t
curlen_
;
60
std::uint8_t
buf_
[64];
61
};
62
63
//! process data and return 32 byte (256 bit) digest hex encoded
64
std::string
sha256_hex
(
const
void
* data, std::uint32_t size);
65
//! process data and return 32 byte (256 bit) digest hex encoded
66
std::string
sha256_hex
(
const
std::string& str);
67
68
//! process data and return 32 byte (256 bit) digest upper-case hex encoded
69
std::string
sha256_hex_uc
(
const
void
* data, std::uint32_t size);
70
//! process data and return 32 byte (256 bit) digest upper-case hex encoded
71
std::string
sha256_hex_uc
(
const
std::string& str);
72
73
//! \}
74
75
}
// namespace tlx
76
77
#endif
// !TLX_DIGEST_SHA256_HEADER
78
79
/******************************************************************************/
tlx::SHA256::state_
std::uint32_t state_[8]
Definition
sha256.hpp:58
tlx::SHA256::finalize
void finalize(void *digest)
finalize computation and output 32 byte (256 bit) digest
Definition
sha256.cpp:190
tlx::SHA256::digest_hex
std::string digest_hex()
finalize computation and return 32 byte (256 bit) digest hex encoded
Definition
sha256.cpp:227
tlx::SHA256::digest
std::string digest()
finalize computation and return 32 byte (256 bit) digest
Definition
sha256.cpp:221
tlx::SHA256::digest_hex_uc
std::string digest_hex_uc()
finalize computation and return 32 byte (256 bit) digest upper-case hex
Definition
sha256.cpp:233
tlx::SHA256::curlen_
std::uint32_t curlen_
Definition
sha256.hpp:59
tlx::SHA256::kDigestLength
static constexpr size_t kDigestLength
digest length in bytes
Definition
sha256.hpp:44
tlx::SHA256::buf_
std::uint8_t buf_[64]
Definition
sha256.hpp:60
tlx::SHA256::process
void process(const void *data, std::uint32_t size)
process more data
Definition
sha256.cpp:155
tlx::SHA256::SHA256
SHA256()
construct empty object.
Definition
sha256.cpp:132
tlx::SHA256::length_
std::uint64_t length_
Definition
sha256.hpp:57
tlx::sha256_hex_uc
std::string sha256_hex_uc(const void *data, std::uint32_t size)
process data and return 32 byte (256 bit) digest upper-case hex encoded
Definition
sha256.cpp:247
tlx::sha256_hex
std::string sha256_hex(const void *data, std::uint32_t size)
process data and return 32 byte (256 bit) digest hex encoded
Definition
sha256.cpp:239
tlx
Definition
exclusive_scan.hpp:17
tlx
digest
sha256.hpp
Generated on
for tlx by
1.17.0