6 * The contents of this file are subject to the terms of the
7 * Common Development and Distribution License (the "License").
8 * You may not use this file except in compliance with the License.
10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 * or http://opensource.org/licenses/CDDL-1.0.
12 * See the License for the specific language governing permissions
13 * and limitations under the License.
15 * When distributing Covered Code, include this CDDL HEADER in each
16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 * If applicable, add the following below this CDDL HEADER, with the
18 * fields enclosed by brackets "[]" replaced with your own identifying
19 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (C) 2009, 2010, Jorn Amundsen <jorn.amundsen@ntnu.no>
24 * Tweaked Edon-R implementation for SUPERCOP, based on NIST API.
28 * Portions copyright (c) 2013, Saso Kiselkov, All rights reserved
29 * Copyright 2016 Gary Mills
32 /* determine where we can get bcopy/bzero declarations */
34 #include <sys/systm.h>
38 #include <sys/edonr.h>
39 #include <sys/debug.h>
41 /* big endian support, provides no-op's if run on little endian hosts */
42 #include "edonr_byteorder.h"
44 #define hashState224(x) ((x)->pipe->p256)
45 #define hashState256(x) ((x)->pipe->p256)
46 #define hashState384(x) ((x)->pipe->p512)
47 #define hashState512(x) ((x)->pipe->p512)
49 /* shift and rotate shortcuts */
50 #define shl(x, n) ((x) << n)
51 #define shr(x, n) ((x) >> n)
53 #define rotl32(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
54 #define rotr32(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
56 #define rotl64(x, n) (((x) << (n)) | ((x) >> (64 - (n))))
57 #define rotr64(x, n) (((x) >> (n)) | ((x) << (64 - (n))))
59 #if !defined(__C99_RESTRICT)
60 #define restrict /* restrict */
63 #define EDONR_VALID_HASHBITLEN(x) \
64 ((x) == 512 || (x) == 384 || (x) == 256 || (x) == 224)
66 /* EdonR224 initial double chaining pipe */
67 static const uint32_t i224p2
[16] = {
68 0x00010203ul
, 0x04050607ul
, 0x08090a0bul
, 0x0c0d0e0ful
,
69 0x10111213ul
, 0x14151617ul
, 0x18191a1bul
, 0x1c1d1e1ful
,
70 0x20212223ul
, 0x24252627ul
, 0x28292a2bul
, 0x2c2d2e2ful
,
71 0x30313233ul
, 0x34353637ul
, 0x38393a3bul
, 0x3c3d3e3ful
,
74 /* EdonR256 initial double chaining pipe */
75 static const uint32_t i256p2
[16] = {
76 0x40414243ul
, 0x44454647ul
, 0x48494a4bul
, 0x4c4d4e4ful
,
77 0x50515253ul
, 0x54555657ul
, 0x58595a5bul
, 0x5c5d5e5ful
,
78 0x60616263ul
, 0x64656667ul
, 0x68696a6bul
, 0x6c6d6e6ful
,
79 0x70717273ul
, 0x74757677ul
, 0x78797a7bul
, 0x7c7d7e7ful
,
82 /* EdonR384 initial double chaining pipe */
83 static const uint64_t i384p2
[16] = {
84 0x0001020304050607ull
, 0x08090a0b0c0d0e0full
,
85 0x1011121314151617ull
, 0x18191a1b1c1d1e1full
,
86 0x2021222324252627ull
, 0x28292a2b2c2d2e2full
,
87 0x3031323334353637ull
, 0x38393a3b3c3d3e3full
,
88 0x4041424344454647ull
, 0x48494a4b4c4d4e4full
,
89 0x5051525354555657ull
, 0x58595a5b5c5d5e5full
,
90 0x6061626364656667ull
, 0x68696a6b6c6d6e6full
,
91 0x7071727374757677ull
, 0x78797a7b7c7d7e7full
94 /* EdonR512 initial double chaining pipe */
95 static const uint64_t i512p2
[16] = {
96 0x8081828384858687ull
, 0x88898a8b8c8d8e8full
,
97 0x9091929394959697ull
, 0x98999a9b9c9d9e9full
,
98 0xa0a1a2a3a4a5a6a7ull
, 0xa8a9aaabacadaeafull
,
99 0xb0b1b2b3b4b5b6b7ull
, 0xb8b9babbbcbdbebfull
,
100 0xc0c1c2c3c4c5c6c7ull
, 0xc8c9cacbcccdcecfull
,
101 0xd0d1d2d3d4d5d6d7ull
, 0xd8d9dadbdcdddedfull
,
102 0xe0e1e2e3e4e5e6e7ull
, 0xe8e9eaebecedeeefull
,
103 0xf0f1f2f3f4f5f6f7ull
, 0xf8f9fafbfcfdfeffull
117 #define LS1_256(c, x0, x1, x2, x3, x4, x5, x6, x7) \
119 uint32_t x04, x17, x23, x56, x07, x26; \
120 x04 = x0+x4, x17 = x1+x7, x07 = x04+x17; \
122 s1 = rotl32(x07 + x3, 4); \
123 s2 = rotl32(x07 + x6, 8); \
125 s5 = rotl32(x04 + x23 + x5, 22); \
127 s6 = rotl32(x17 + x56 + x0, 24); \
129 s3 = rotl32(x26 + x7, 13); \
130 s4 = rotl32(x26 + x1, 17); \
131 s7 = rotl32(x26 + x4, 29); \
134 #define LS1_512(c, x0, x1, x2, x3, x4, x5, x6, x7) \
136 uint64_t x04, x17, x23, x56, x07, x26; \
137 x04 = x0+x4, x17 = x1+x7, x07 = x04+x17; \
139 s1 = rotl64(x07 + x3, 5); \
140 s2 = rotl64(x07 + x6, 15); \
142 s5 = rotl64(x04 + x23 + x5, 40); \
144 s6 = rotl64(x17 + x56 + x0, 50); \
146 s3 = rotl64(x26 + x7, 22); \
147 s4 = rotl64(x26 + x1, 31); \
148 s7 = rotl64(x26 + x4, 59); \
152 * Second Orthogonal Latin Square
162 #define LS2_256(c, y0, y1, y2, y3, y4, y5, y6, y7) \
164 uint32_t y01, y25, y34, y67, y04, y05, y27, y37; \
165 y01 = y0+y1, y25 = y2+y5, y05 = y01+y25; \
166 t0 = ~c + y05 + y7; \
167 t2 = rotl32(y05 + y3, 9); \
168 y34 = y3+y4, y04 = y01+y34; \
169 t1 = rotl32(y04 + y6, 5); \
170 t4 = rotl32(y04 + y5, 15); \
171 y67 = y6+y7, y37 = y34+y67; \
172 t3 = rotl32(y37 + y2, 11); \
173 t7 = rotl32(y37 + y0, 27); \
175 t5 = rotl32(y27 + y4, 20); \
176 t6 = rotl32(y27 + y1, 25); \
179 #define LS2_512(c, y0, y1, y2, y3, y4, y5, y6, y7) \
181 uint64_t y01, y25, y34, y67, y04, y05, y27, y37; \
182 y01 = y0+y1, y25 = y2+y5, y05 = y01+y25; \
183 t0 = ~c + y05 + y7; \
184 t2 = rotl64(y05 + y3, 19); \
185 y34 = y3+y4, y04 = y01+y34; \
186 t1 = rotl64(y04 + y6, 10); \
187 t4 = rotl64(y04 + y5, 36); \
188 y67 = y6+y7, y37 = y34+y67; \
189 t3 = rotl64(y37 + y2, 29); \
190 t7 = rotl64(y37 + y0, 55); \
192 t5 = rotl64(y27 + y4, 44); \
193 t6 = rotl64(y27 + y1, 48); \
196 #define quasi_exform256(r0, r1, r2, r3, r4, r5, r6, r7) \
198 uint32_t s04, s17, s23, s56, t01, t25, t34, t67; \
199 s04 = s0 ^ s4, t01 = t0 ^ t1; \
200 r0 = (s04 ^ s1) + (t01 ^ t5); \
202 r1 = (s04 ^ s7) + (t2 ^ t67); \
204 r7 = (s23 ^ s5) + (t4 ^ t67); \
206 r3 = (s23 ^ s4) + (t0 ^ t34); \
208 r5 = (s3 ^ s56) + (t34 ^ t6); \
210 r6 = (s2 ^ s56) + (t25 ^ t7); \
212 r4 = (s0 ^ s17) + (t1 ^ t25); \
213 r2 = (s17 ^ s6) + (t01 ^ t3); \
216 #define quasi_exform512(r0, r1, r2, r3, r4, r5, r6, r7) \
218 uint64_t s04, s17, s23, s56, t01, t25, t34, t67; \
219 s04 = s0 ^ s4, t01 = t0 ^ t1; \
220 r0 = (s04 ^ s1) + (t01 ^ t5); \
222 r1 = (s04 ^ s7) + (t2 ^ t67); \
224 r7 = (s23 ^ s5) + (t4 ^ t67); \
226 r3 = (s23 ^ s4) + (t0 ^ t34); \
228 r5 = (s3 ^ s56) + (t34 ^ t6); \
230 r6 = (s2 ^ s56) + (t25 ^ t7); \
232 r4 = (s0 ^ s17) + (t1 ^ t25); \
233 r2 = (s17 ^ s6) + (t01 ^ t3); \
237 Q256(size_t bitlen
, const uint32_t *data
, uint32_t *restrict p
)
241 for (bl
= bitlen
; bl
>= EdonR256_BLOCK_BITSIZE
;
242 bl
-= EdonR256_BLOCK_BITSIZE
, data
+= 16) {
243 uint32_t s0
, s1
, s2
, s3
, s4
, s5
, s6
, s7
, t0
, t1
, t2
, t3
, t4
,
245 uint32_t p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
, q0
, q1
, q2
, q3
, q4
,
247 const uint32_t defix
= 0xaaaaaaaa;
248 #if defined(MACHINE_IS_BIG_ENDIAN)
249 uint32_t swp0
, swp1
, swp2
, swp3
, swp4
, swp5
, swp6
, swp7
, swp8
,
250 swp9
, swp10
, swp11
, swp12
, swp13
, swp14
, swp15
;
251 #define d(j) swp ## j
252 #define s32(j) ld_swap32((uint32_t *)data + j, swp ## j)
257 /* First row of quasigroup e-transformations */
258 #if defined(MACHINE_IS_BIG_ENDIAN)
268 LS1_256(defix
, d(15), d(14), d(13), d(12), d(11), d(10), d(9),
270 #if defined(MACHINE_IS_BIG_ENDIAN)
281 LS2_256(defix
, d(0), d(1), d(2), d(3), d(4), d(5), d(6), d(7));
282 quasi_exform256(p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
284 LS1_256(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
285 LS2_256(defix
, d(8), d(9), d(10), d(11), d(12), d(13), d(14),
287 quasi_exform256(q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
289 /* Second row of quasigroup e-transformations */
290 LS1_256(defix
, p
[8], p
[9], p
[10], p
[11], p
[12], p
[13], p
[14],
292 LS2_256(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
293 quasi_exform256(p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
295 LS1_256(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
296 LS2_256(defix
, q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
297 quasi_exform256(q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
299 /* Third row of quasigroup e-transformations */
300 LS1_256(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
301 LS2_256(defix
, p
[0], p
[1], p
[2], p
[3], p
[4], p
[5], p
[6], p
[7]);
302 quasi_exform256(p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
304 LS1_256(defix
, q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
305 LS2_256(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
306 quasi_exform256(q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
308 /* Fourth row of quasigroup e-transformations */
309 LS1_256(defix
, d(7), d(6), d(5), d(4), d(3), d(2), d(1), d(0));
310 LS2_256(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
311 quasi_exform256(p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
313 LS1_256(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
314 LS2_256(defix
, q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
315 quasi_exform256(q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
317 /* Edon-R tweak on the original SHA-3 Edon-R submission. */
337 return (bitlen
- bl
);
340 #if defined(__IBMC__) && defined(_AIX) && defined(__64BIT__)
345 Q512(size_t bitlen
, const uint64_t *data
, uint64_t *restrict p
)
349 for (bl
= bitlen
; bl
>= EdonR512_BLOCK_BITSIZE
;
350 bl
-= EdonR512_BLOCK_BITSIZE
, data
+= 16) {
351 uint64_t s0
, s1
, s2
, s3
, s4
, s5
, s6
, s7
, t0
, t1
, t2
, t3
, t4
,
353 uint64_t p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
, q0
, q1
, q2
, q3
, q4
,
355 const uint64_t defix
= 0xaaaaaaaaaaaaaaaaull
;
356 #if defined(MACHINE_IS_BIG_ENDIAN)
357 uint64_t swp0
, swp1
, swp2
, swp3
, swp4
, swp5
, swp6
, swp7
, swp8
,
358 swp9
, swp10
, swp11
, swp12
, swp13
, swp14
, swp15
;
360 #define s64(j) ld_swap64((uint64_t *)data+j, swp##j)
365 /* First row of quasigroup e-transformations */
366 #if defined(MACHINE_IS_BIG_ENDIAN)
376 LS1_512(defix
, d(15), d(14), d(13), d(12), d(11), d(10), d(9),
378 #if defined(MACHINE_IS_BIG_ENDIAN)
389 LS2_512(defix
, d(0), d(1), d(2), d(3), d(4), d(5), d(6), d(7));
390 quasi_exform512(p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
392 LS1_512(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
393 LS2_512(defix
, d(8), d(9), d(10), d(11), d(12), d(13), d(14),
395 quasi_exform512(q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
397 /* Second row of quasigroup e-transformations */
398 LS1_512(defix
, p
[8], p
[9], p
[10], p
[11], p
[12], p
[13], p
[14],
400 LS2_512(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
401 quasi_exform512(p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
403 LS1_512(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
404 LS2_512(defix
, q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
405 quasi_exform512(q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
407 /* Third row of quasigroup e-transformations */
408 LS1_512(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
409 LS2_512(defix
, p
[0], p
[1], p
[2], p
[3], p
[4], p
[5], p
[6], p
[7]);
410 quasi_exform512(p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
412 LS1_512(defix
, q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
413 LS2_512(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
414 quasi_exform512(q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
416 /* Fourth row of quasigroup e-transformations */
417 LS1_512(defix
, d(7), d(6), d(5), d(4), d(3), d(2), d(1), d(0));
418 LS2_512(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
419 quasi_exform512(p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
421 LS1_512(defix
, p0
, p1
, p2
, p3
, p4
, p5
, p6
, p7
);
422 LS2_512(defix
, q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
423 quasi_exform512(q0
, q1
, q2
, q3
, q4
, q5
, q6
, q7
);
425 /* Edon-R tweak on the original SHA-3 Edon-R submission. */
445 return (bitlen
- bl
);
449 EdonRInit(EdonRState
*state
, size_t hashbitlen
)
451 ASSERT(EDONR_VALID_HASHBITLEN(hashbitlen
));
452 switch (hashbitlen
) {
454 state
->hashbitlen
= 224;
455 state
->bits_processed
= 0;
456 state
->unprocessed_bits
= 0;
457 bcopy(i224p2
, hashState224(state
)->DoublePipe
,
458 16 * sizeof (uint32_t));
462 state
->hashbitlen
= 256;
463 state
->bits_processed
= 0;
464 state
->unprocessed_bits
= 0;
465 bcopy(i256p2
, hashState256(state
)->DoublePipe
,
466 16 * sizeof (uint32_t));
470 state
->hashbitlen
= 384;
471 state
->bits_processed
= 0;
472 state
->unprocessed_bits
= 0;
473 bcopy(i384p2
, hashState384(state
)->DoublePipe
,
474 16 * sizeof (uint64_t));
478 state
->hashbitlen
= 512;
479 state
->bits_processed
= 0;
480 state
->unprocessed_bits
= 0;
481 bcopy(i512p2
, hashState224(state
)->DoublePipe
,
482 16 * sizeof (uint64_t));
489 EdonRUpdate(EdonRState
*state
, const uint8_t *data
, size_t databitlen
)
494 size_t bits_processed
;
496 ASSERT(EDONR_VALID_HASHBITLEN(state
->hashbitlen
));
497 switch (state
->hashbitlen
) {
500 if (state
->unprocessed_bits
> 0) {
501 /* LastBytes = databitlen / 8 */
502 int LastBytes
= (int)databitlen
>> 3;
504 ASSERT(state
->unprocessed_bits
+ databitlen
<=
505 EdonR256_BLOCK_SIZE
* 8);
507 bcopy(data
, hashState256(state
)->LastPart
508 + (state
->unprocessed_bits
>> 3), LastBytes
);
509 state
->unprocessed_bits
+= (int)databitlen
;
510 databitlen
= state
->unprocessed_bits
;
511 /* LINTED E_BAD_PTR_CAST_ALIGN */
512 data32
= (uint32_t *)hashState256(state
)->LastPart
;
514 /* LINTED E_BAD_PTR_CAST_ALIGN */
515 data32
= (uint32_t *)data
;
517 bits_processed
= Q256(databitlen
, data32
,
518 hashState256(state
)->DoublePipe
);
519 state
->bits_processed
+= bits_processed
;
520 databitlen
-= bits_processed
;
521 state
->unprocessed_bits
= (int)databitlen
;
522 if (databitlen
> 0) {
523 /* LastBytes = Ceil(databitlen / 8) */
525 ((~(((-(int)databitlen
) >> 3) & 0x01ff)) +
528 data32
+= bits_processed
>> 5; /* byte size update */
529 bcopy(data32
, hashState256(state
)->LastPart
, LastBytes
);
535 if (state
->unprocessed_bits
> 0) {
536 /* LastBytes = databitlen / 8 */
537 int LastBytes
= (int)databitlen
>> 3;
539 ASSERT(state
->unprocessed_bits
+ databitlen
<=
540 EdonR512_BLOCK_SIZE
* 8);
542 bcopy(data
, hashState512(state
)->LastPart
543 + (state
->unprocessed_bits
>> 3), LastBytes
);
544 state
->unprocessed_bits
+= (int)databitlen
;
545 databitlen
= state
->unprocessed_bits
;
546 /* LINTED E_BAD_PTR_CAST_ALIGN */
547 data64
= (uint64_t *)hashState512(state
)->LastPart
;
549 /* LINTED E_BAD_PTR_CAST_ALIGN */
550 data64
= (uint64_t *)data
;
552 bits_processed
= Q512(databitlen
, data64
,
553 hashState512(state
)->DoublePipe
);
554 state
->bits_processed
+= bits_processed
;
555 databitlen
-= bits_processed
;
556 state
->unprocessed_bits
= (int)databitlen
;
557 if (databitlen
> 0) {
558 /* LastBytes = Ceil(databitlen / 8) */
560 ((~(((-(int)databitlen
) >> 3) & 0x03ff)) +
563 data64
+= bits_processed
>> 6; /* byte size update */
564 bcopy(data64
, hashState512(state
)->LastPart
, LastBytes
);
571 EdonRFinal(EdonRState
*state
, uint8_t *hashval
)
574 uint64_t *data64
, num_bits
;
577 int LastByte
, PadOnePosition
;
579 num_bits
= state
->bits_processed
+ state
->unprocessed_bits
;
580 ASSERT(EDONR_VALID_HASHBITLEN(state
->hashbitlen
));
581 switch (state
->hashbitlen
) {
584 LastByte
= (int)state
->unprocessed_bits
>> 3;
585 PadOnePosition
= 7 - (state
->unprocessed_bits
& 0x07);
586 hashState256(state
)->LastPart
[LastByte
] =
587 (hashState256(state
)->LastPart
[LastByte
]
588 & (0xff << (PadOnePosition
+ 1))) ^
589 (0x01 << PadOnePosition
);
590 /* LINTED E_BAD_PTR_CAST_ALIGN */
591 data64
= (uint64_t *)hashState256(state
)->LastPart
;
593 if (state
->unprocessed_bits
< 448) {
594 (void) memset((hashState256(state
)->LastPart
) +
596 EdonR256_BLOCK_SIZE
- LastByte
- 9);
597 databitlen
= EdonR256_BLOCK_SIZE
* 8;
598 #if defined(MACHINE_IS_BIG_ENDIAN)
599 st_swap64(num_bits
, data64
+ 7);
601 data64
[7] = num_bits
;
604 (void) memset((hashState256(state
)->LastPart
) +
606 EdonR256_BLOCK_SIZE
* 2 - LastByte
- 9);
607 databitlen
= EdonR256_BLOCK_SIZE
* 16;
608 #if defined(MACHINE_IS_BIG_ENDIAN)
609 st_swap64(num_bits
, data64
+ 15);
611 data64
[15] = num_bits
;
615 /* LINTED E_BAD_PTR_CAST_ALIGN */
616 data32
= (uint32_t *)hashState256(state
)->LastPart
;
617 state
->bits_processed
+= Q256(databitlen
, data32
,
618 hashState256(state
)->DoublePipe
);
623 LastByte
= (int)state
->unprocessed_bits
>> 3;
624 PadOnePosition
= 7 - (state
->unprocessed_bits
& 0x07);
625 hashState512(state
)->LastPart
[LastByte
] =
626 (hashState512(state
)->LastPart
[LastByte
]
627 & (0xff << (PadOnePosition
+ 1))) ^
628 (0x01 << PadOnePosition
);
629 /* LINTED E_BAD_PTR_CAST_ALIGN */
630 data64
= (uint64_t *)hashState512(state
)->LastPart
;
632 if (state
->unprocessed_bits
< 960) {
633 (void) memset((hashState512(state
)->LastPart
) +
635 EdonR512_BLOCK_SIZE
- LastByte
- 9);
636 databitlen
= EdonR512_BLOCK_SIZE
* 8;
637 #if defined(MACHINE_IS_BIG_ENDIAN)
638 st_swap64(num_bits
, data64
+ 15);
640 data64
[15] = num_bits
;
643 (void) memset((hashState512(state
)->LastPart
) +
645 EdonR512_BLOCK_SIZE
* 2 - LastByte
- 9);
646 databitlen
= EdonR512_BLOCK_SIZE
* 16;
647 #if defined(MACHINE_IS_BIG_ENDIAN)
648 st_swap64(num_bits
, data64
+ 31);
650 data64
[31] = num_bits
;
654 state
->bits_processed
+= Q512(databitlen
, data64
,
655 hashState512(state
)->DoublePipe
);
659 switch (state
->hashbitlen
) {
661 #if defined(MACHINE_IS_BIG_ENDIAN)
662 /* LINTED: pointer cast may result in improper alignment */
663 uint32_t *d32
= (uint32_t *)hashval
;
664 uint32_t *s32
= hashState224(state
)->DoublePipe
+ 9;
667 for (j
= 0; j
< EdonR224_DIGEST_SIZE
>> 2; j
++)
668 st_swap32(s32
[j
], d32
+ j
);
670 bcopy(hashState256(state
)->DoublePipe
+ 9, hashval
,
671 EdonR224_DIGEST_SIZE
);
676 #if defined(MACHINE_IS_BIG_ENDIAN)
677 /* LINTED: pointer cast may result in improper alignment */
678 uint32_t *d32
= (uint32_t *)hashval
;
679 uint32_t *s32
= hashState224(state
)->DoublePipe
+ 8;
682 for (j
= 0; j
< EdonR256_DIGEST_SIZE
>> 2; j
++)
683 st_swap32(s32
[j
], d32
+ j
);
685 bcopy(hashState256(state
)->DoublePipe
+ 8, hashval
,
686 EdonR256_DIGEST_SIZE
);
691 #if defined(MACHINE_IS_BIG_ENDIAN)
692 /* LINTED: pointer cast may result in improper alignment */
693 uint64_t *d64
= (uint64_t *)hashval
;
694 uint64_t *s64
= hashState384(state
)->DoublePipe
+ 10;
697 for (j
= 0; j
< EdonR384_DIGEST_SIZE
>> 3; j
++)
698 st_swap64(s64
[j
], d64
+ j
);
700 bcopy(hashState384(state
)->DoublePipe
+ 10, hashval
,
701 EdonR384_DIGEST_SIZE
);
706 #if defined(MACHINE_IS_BIG_ENDIAN)
707 /* LINTED: pointer cast may result in improper alignment */
708 uint64_t *d64
= (uint64_t *)hashval
;
709 uint64_t *s64
= hashState512(state
)->DoublePipe
+ 8;
712 for (j
= 0; j
< EdonR512_DIGEST_SIZE
>> 3; j
++)
713 st_swap64(s64
[j
], d64
+ j
);
715 bcopy(hashState512(state
)->DoublePipe
+ 8, hashval
,
716 EdonR512_DIGEST_SIZE
);
725 EdonRHash(size_t hashbitlen
, const uint8_t *data
, size_t databitlen
,
730 EdonRInit(&state
, hashbitlen
);
731 EdonRUpdate(&state
, data
, databitlen
);
732 EdonRFinal(&state
, hashval
);