diff options
Diffstat (limited to 'C/Blake2s.c')
-rw-r--r-- | C/Blake2s.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/C/Blake2s.c b/C/Blake2s.c index 3c56a8b..2a84b57 100644 --- a/C/Blake2s.c +++ b/C/Blake2s.c | |||
@@ -1,7 +1,9 @@ | |||
1 | /* Blake2s.c -- BLAKE2s and BLAKE2sp Hash | 1 | /* Blake2s.c -- BLAKE2s and BLAKE2sp Hash |
2 | 2021-02-09 : Igor Pavlov : Public domain | 2 | 2023-03-04 : Igor Pavlov : Public domain |
3 | 2015 : Samuel Neves : Public domain */ | 3 | 2015 : Samuel Neves : Public domain */ |
4 | 4 | ||
5 | #include "Precomp.h" | ||
6 | |||
5 | #include <string.h> | 7 | #include <string.h> |
6 | 8 | ||
7 | #include "Blake2.h" | 9 | #include "Blake2.h" |
@@ -78,21 +80,21 @@ static void Blake2s_Compress(CBlake2s *p) | |||
78 | a += b + m[sigma[2*i+1]]; d ^= a; d = rotr32(d, 8); c += d; b ^= c; b = rotr32(b, 7); \ | 80 | a += b + m[sigma[2*i+1]]; d ^= a; d = rotr32(d, 8); c += d; b ^= c; b = rotr32(b, 7); \ |
79 | 81 | ||
80 | #define R(r) \ | 82 | #define R(r) \ |
81 | G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \ | 83 | G(r,0,v[ 0],v[ 4],v[ 8],v[12]) \ |
82 | G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \ | 84 | G(r,1,v[ 1],v[ 5],v[ 9],v[13]) \ |
83 | G(r,2,v[ 2],v[ 6],v[10],v[14]); \ | 85 | G(r,2,v[ 2],v[ 6],v[10],v[14]) \ |
84 | G(r,3,v[ 3],v[ 7],v[11],v[15]); \ | 86 | G(r,3,v[ 3],v[ 7],v[11],v[15]) \ |
85 | G(r,4,v[ 0],v[ 5],v[10],v[15]); \ | 87 | G(r,4,v[ 0],v[ 5],v[10],v[15]) \ |
86 | G(r,5,v[ 1],v[ 6],v[11],v[12]); \ | 88 | G(r,5,v[ 1],v[ 6],v[11],v[12]) \ |
87 | G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \ | 89 | G(r,6,v[ 2],v[ 7],v[ 8],v[13]) \ |
88 | G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \ | 90 | G(r,7,v[ 3],v[ 4],v[ 9],v[14]) \ |
89 | 91 | ||
90 | { | 92 | { |
91 | unsigned r; | 93 | unsigned r; |
92 | for (r = 0; r < BLAKE2S_NUM_ROUNDS; r++) | 94 | for (r = 0; r < BLAKE2S_NUM_ROUNDS; r++) |
93 | { | 95 | { |
94 | const Byte *sigma = k_Blake2s_Sigma[r]; | 96 | const Byte *sigma = k_Blake2s_Sigma[r]; |
95 | R(r); | 97 | R(r) |
96 | } | 98 | } |
97 | /* R(0); R(1); R(2); R(3); R(4); R(5); R(6); R(7); R(8); R(9); */ | 99 | /* R(0); R(1); R(2); R(3); R(4); R(5); R(6); R(7); R(8); R(9); */ |
98 | } | 100 | } |
@@ -130,7 +132,7 @@ static void Blake2s_Update(CBlake2s *p, const Byte *data, size_t size) | |||
130 | } | 132 | } |
131 | 133 | ||
132 | memcpy(p->buf + pos, data, rem); | 134 | memcpy(p->buf + pos, data, rem); |
133 | Blake2s_Increment_Counter(S, BLAKE2S_BLOCK_SIZE); | 135 | Blake2s_Increment_Counter(S, BLAKE2S_BLOCK_SIZE) |
134 | Blake2s_Compress(p); | 136 | Blake2s_Compress(p); |
135 | p->bufPos = 0; | 137 | p->bufPos = 0; |
136 | data += rem; | 138 | data += rem; |
@@ -143,13 +145,15 @@ static void Blake2s_Final(CBlake2s *p, Byte *digest) | |||
143 | { | 145 | { |
144 | unsigned i; | 146 | unsigned i; |
145 | 147 | ||
146 | Blake2s_Increment_Counter(S, (UInt32)p->bufPos); | 148 | Blake2s_Increment_Counter(S, (UInt32)p->bufPos) |
147 | Blake2s_Set_LastBlock(p); | 149 | Blake2s_Set_LastBlock(p) |
148 | memset(p->buf + p->bufPos, 0, BLAKE2S_BLOCK_SIZE - p->bufPos); | 150 | memset(p->buf + p->bufPos, 0, BLAKE2S_BLOCK_SIZE - p->bufPos); |
149 | Blake2s_Compress(p); | 151 | Blake2s_Compress(p); |
150 | 152 | ||
151 | for (i = 0; i < 8; i++) | 153 | for (i = 0; i < 8; i++) |
152 | SetUi32(digest + sizeof(p->h[i]) * i, p->h[i]); | 154 | { |
155 | SetUi32(digest + sizeof(p->h[i]) * i, p->h[i]) | ||
156 | } | ||
153 | } | 157 | } |
154 | 158 | ||
155 | 159 | ||
@@ -242,3 +246,5 @@ void Blake2sp_Final(CBlake2sp *p, Byte *digest) | |||
242 | 246 | ||
243 | Blake2s_Final(&R, digest); | 247 | Blake2s_Final(&R, digest); |
244 | } | 248 | } |
249 | |||
250 | #undef rotr32 | ||