unrarsrc  6.1.7
About: unrar extracts, views and tests the contents of archives created with the RAR archiver.
  Fossies Dox: unrarsrc-6.1.7.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

blake2s.hpp
Go to the documentation of this file.
1// Based on public domain code written in 2012 by Samuel Neves
2#ifndef _RAR_BLAKE2_
3#define _RAR_BLAKE2_
4
5#define BLAKE2_DIGEST_SIZE 32
6#define BLAKE2_THREADS_NUMBER 8
7
9{
12};
13
14
15// Alignment to 64 improves performance of both SSE and non-SSE versions.
16// Alignment to n*16 is required for SSE version, so we selected 64.
17// We use the custom alignment scheme instead of __declspec(align(x)),
18// because it is less compiler dependent. Also the compiler directive
19// does not help if structure is a member of class allocated through
20// 'new' operator.
22{
23 enum { BLAKE_ALIGNMENT = 64 };
24
25 // buffer and uint32 h[8], t[2], f[2];
27
29
30 byte *buf; // byte buf[2 * BLAKE2S_BLOCKBYTES].
31 uint32 *h, *t, *f; // uint32 h[8], t[2], f[2].
32
33 size_t buflen;
35
37 {
39 }
40
41 // Required when we declare and assign in the same command.
43 {
45 *this=st;
46 }
47
49 {
50 // Set aligned pointers. Must be done in constructor, not in Init(),
51 // so assignments like 'blake2sp_state res=blake2ctx' work correctly
52 // even if blake2sp_init is not called for 'res'.
54 h = (uint32 *) (buf + 2 * BLAKE2S_BLOCKBYTES);
55 t = h + 8;
56 f = t + 2;
57 }
58
59 void init()
60 {
61 memset( ubuf, 0, sizeof( ubuf ) );
62 buflen = 0;
63 last_node = 0;
64 }
65
66 // Since we use pointers, the default = would work incorrectly.
68 {
69 if (this != &st)
70 {
71 memcpy(buf, st.buf, BLAKE_DATA_SIZE);
72 buflen = st.buflen;
74 }
75 return *this;
76 }
77};
78
79
80#ifdef RAR_SMP
81class ThreadPool;
82#endif
83
85{
89 size_t buflen;
90
91#ifdef RAR_SMP
92 ThreadPool *ThPool;
93 uint MaxThreads;
94#endif
95};
96
98void blake2sp_update( blake2sp_state *S, const byte *in, size_t inlen );
99void blake2sp_final( blake2sp_state *S, byte *digest );
100
101#endif
102
void blake2sp_final(blake2sp_state *S, byte *digest)
Definition: blake2sp.cpp:131
void blake2sp_update(blake2sp_state *S, const byte *in, size_t inlen)
Definition: blake2sp.cpp:67
void blake2sp_init(blake2sp_state *S)
Definition: blake2sp.cpp:16
blake2s_constant
Definition: blake2s.hpp:9
@ BLAKE2S_OUTBYTES
Definition: blake2s.hpp:11
@ BLAKE2S_BLOCKBYTES
Definition: blake2s.hpp:10
#define ALIGN_VALUE(v, a)
Definition: rardefs.hpp:29
unsigned int uint
Definition: rartypes.hpp:8
uint32_t uint32
Definition: rartypes.hpp:9
static byte S[256]
Definition: rijndael.cpp:10
uint32 * h
Definition: blake2s.hpp:31
void set_pointers()
Definition: blake2s.hpp:48
void init()
Definition: blake2s.hpp:59
blake2s_state & operator=(blake2s_state &st)
Definition: blake2s.hpp:67
byte * buf
Definition: blake2s.hpp:30
byte ubuf[BLAKE_DATA_SIZE+BLAKE_ALIGNMENT]
Definition: blake2s.hpp:28
blake2s_state(blake2s_state &st)
Definition: blake2s.hpp:42
byte last_node
Definition: blake2s.hpp:34
size_t buflen
Definition: blake2s.hpp:33
uint32 * t
Definition: blake2s.hpp:31
uint32 * f
Definition: blake2s.hpp:31
byte buf[8 *BLAKE2S_BLOCKBYTES]
Definition: blake2s.hpp:88
blake2s_state S[8]
Definition: blake2s.hpp:86
size_t buflen
Definition: blake2s.hpp:89
blake2s_state R
Definition: blake2s.hpp:87