aboutsummaryrefslogtreecommitdiff
path: root/C/Blake2.h
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-14 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-15 23:55:04 +0500
commitfc662341e6f85da78ada0e443f6116b978f79f22 (patch)
tree1be1cc402a7a9cbc18d4eeea6b141354c2d559e3 /C/Blake2.h
parent5b39dc76f1bc82f941d5c800ab9f34407a06b53a (diff)
download7zip-fc662341e6f85da78ada0e443f6116b978f79f22.tar.gz
7zip-fc662341e6f85da78ada0e443f6116b978f79f22.tar.bz2
7zip-fc662341e6f85da78ada0e443f6116b978f79f22.zip
24.0524.05
Diffstat (limited to 'C/Blake2.h')
-rw-r--r--C/Blake2.h111
1 files changed, 84 insertions, 27 deletions
diff --git a/C/Blake2.h b/C/Blake2.h
index 7235235..801ea7a 100644
--- a/C/Blake2.h
+++ b/C/Blake2.h
@@ -1,47 +1,104 @@
1/* Blake2.h -- BLAKE2 Hash 1/* Blake2.h -- BLAKE2sp Hash
22023-03-04 : Igor Pavlov : Public domain 22024-01-17 : Igor Pavlov : Public domain */
32015 : Samuel Neves : Public domain */
4 3
5#ifndef ZIP7_INC_BLAKE2_H 4#ifndef ZIP7_INC_BLAKE2_H
6#define ZIP7_INC_BLAKE2_H 5#define ZIP7_INC_BLAKE2_H
7 6
8#include "7zTypes.h" 7#include "7zTypes.h"
9 8
10EXTERN_C_BEGIN 9#if 0
10#include "Compiler.h"
11#include "CpuArch.h"
12#if defined(MY_CPU_X86_OR_AMD64)
13#if defined(__SSE2__) \
14 || defined(_MSC_VER) && _MSC_VER > 1200 \
15 || defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 30300) \
16 || defined(__clang__) \
17 || defined(__INTEL_COMPILER)
18#include <emmintrin.h> // SSE2
19#endif
11 20
12#define BLAKE2S_BLOCK_SIZE 64 21#if defined(__AVX2__) \
13#define BLAKE2S_DIGEST_SIZE 32 22 || defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 40900) \
14#define BLAKE2SP_PARALLEL_DEGREE 8 23 || defined(Z7_APPLE_CLANG_VERSION) && (Z7_APPLE_CLANG_VERSION >= 40600) \
24 || defined(Z7_LLVM_CLANG_VERSION) && (Z7_LLVM_CLANG_VERSION >= 30100) \
25 || defined(Z7_MSC_VER_ORIGINAL) && (Z7_MSC_VER_ORIGINAL >= 1800) \
26 || defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1400)
27#include <immintrin.h>
28#if defined(__clang__)
29#include <avxintrin.h>
30#include <avx2intrin.h>
31#endif
32#endif // avx2
33#endif // MY_CPU_X86_OR_AMD64
34#endif // 0
15 35
16typedef struct 36EXTERN_C_BEGIN
17{
18 UInt32 h[8];
19 UInt32 t[2];
20 UInt32 f[2];
21 Byte buf[BLAKE2S_BLOCK_SIZE];
22 UInt32 bufPos;
23 UInt32 lastNode_f1;
24 UInt32 dummy[2]; /* for sizeof(CBlake2s) alignment */
25} CBlake2s;
26
27/* You need to xor CBlake2s::h[i] with input parameter block after Blake2s_Init0() */
28/*
29void Blake2s_Init0(CBlake2s *p);
30void Blake2s_Update(CBlake2s *p, const Byte *data, size_t size);
31void Blake2s_Final(CBlake2s *p, Byte *digest);
32*/
33 37
38#define Z7_BLAKE2S_BLOCK_SIZE 64
39#define Z7_BLAKE2S_DIGEST_SIZE 32
40#define Z7_BLAKE2SP_PARALLEL_DEGREE 8
41#define Z7_BLAKE2SP_NUM_STRUCT_WORDS 16
34 42
43#if 1 || defined(Z7_BLAKE2SP_USE_FUNCTIONS)
44typedef void (Z7_FASTCALL *Z7_BLAKE2SP_FUNC_COMPRESS)(UInt32 *states, const Byte *data, const Byte *end);
45typedef void (Z7_FASTCALL *Z7_BLAKE2SP_FUNC_INIT)(UInt32 *states);
46#endif
47
48// it's required that CBlake2sp is aligned for 32-bytes,
49// because the code can use unaligned access with sse and avx256.
50// but 64-bytes alignment can be better.
51MY_ALIGN(64)
35typedef struct 52typedef struct
36{ 53{
37 CBlake2s S[BLAKE2SP_PARALLEL_DEGREE]; 54 union
38 unsigned bufPos; 55 {
39} CBlake2sp; 56#if 0
57#if defined(MY_CPU_X86_OR_AMD64)
58#if defined(__SSE2__) \
59 || defined(_MSC_VER) && _MSC_VER > 1200 \
60 || defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 30300) \
61 || defined(__clang__) \
62 || defined(__INTEL_COMPILER)
63 __m128i _pad_align_128bit[4];
64#endif // sse2
65#if defined(__AVX2__) \
66 || defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 40900) \
67 || defined(Z7_APPLE_CLANG_VERSION) && (Z7_APPLE_CLANG_VERSION >= 40600) \
68 || defined(Z7_LLVM_CLANG_VERSION) && (Z7_LLVM_CLANG_VERSION >= 30100) \
69 || defined(Z7_MSC_VER_ORIGINAL) && (Z7_MSC_VER_ORIGINAL >= 1800) \
70 || defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1400)
71 __m256i _pad_align_256bit[2];
72#endif // avx2
73#endif // x86
74#endif // 0
40 75
76 void * _pad_align_ptr[8];
77 UInt32 _pad_align_32bit[16];
78 struct
79 {
80 unsigned cycPos;
81 unsigned _pad_unused;
82#if 1 || defined(Z7_BLAKE2SP_USE_FUNCTIONS)
83 Z7_BLAKE2SP_FUNC_COMPRESS func_Compress_Fast;
84 Z7_BLAKE2SP_FUNC_COMPRESS func_Compress_Single;
85 Z7_BLAKE2SP_FUNC_INIT func_Init;
86 Z7_BLAKE2SP_FUNC_INIT func_Final;
87#endif
88 } header;
89 } u;
90 // MY_ALIGN(64)
91 UInt32 states[Z7_BLAKE2SP_PARALLEL_DEGREE * Z7_BLAKE2SP_NUM_STRUCT_WORDS];
92 // MY_ALIGN(64)
93 UInt32 buf32[Z7_BLAKE2SP_PARALLEL_DEGREE * Z7_BLAKE2SP_NUM_STRUCT_WORDS * 2];
94} CBlake2sp;
41 95
96BoolInt Blake2sp_SetFunction(CBlake2sp *p, unsigned algo);
42void Blake2sp_Init(CBlake2sp *p); 97void Blake2sp_Init(CBlake2sp *p);
98void Blake2sp_InitState(CBlake2sp *p);
43void Blake2sp_Update(CBlake2sp *p, const Byte *data, size_t size); 99void Blake2sp_Update(CBlake2sp *p, const Byte *data, size_t size);
44void Blake2sp_Final(CBlake2sp *p, Byte *digest); 100void Blake2sp_Final(CBlake2sp *p, Byte *digest);
101void z7_Black2sp_Prepare(void);
45 102
46EXTERN_C_END 103EXTERN_C_END
47 104