emsha 1.1.1
A compact HMAC-SHA-256 C++11 library.
internal.h
Go to the documentation of this file.
1
29
30#ifndef EMSHA_INTERNAL_H
31#define EMSHA_INTERNAL_H
32
33
34#include <cstdint>
35
36using std::uint8_t;
37using std::uint32_t;
38
39
40namespace emsha {
41
42
43static inline uint32_t
44rotr32(uint32_t x, uint8_t n)
45{
46 return ((x >> n) | (x << (32 - n)));
47}
48
49
50static inline uint32_t
51sha_ch(uint32_t x, uint32_t y, uint32_t z)
52{
53 return ((x & y) ^ ((~x) & z));
54}
55
56
57static inline uint32_t
58sha_maj(uint32_t x, uint32_t y, uint32_t z)
59{
60 return (x & y) ^ (x & z) ^ (y & z);
61}
62
63
64static inline uint32_t
65sha_Sigma0(uint32_t x)
66{
67 return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
68}
69
70
71static inline uint32_t
72sha_Sigma1(uint32_t x)
73{
74 return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
75}
76
77
78static inline uint32_t
79sha_sigma0(uint32_t x)
80{
81 return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >> 3);
82}
83
84
85static inline uint32_t
86sha_sigma1(uint32_t x)
87{
88 return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >> 10);
89}
90
91
92
93} // end of namespace emsha
94
95
96#endif // EMSHA_INTERNAL_H
Definition: emsha.h:39