MagickCore 7.0.10
sha2384.c
Go to the documentation of this file.
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% SSSSS H H AAA %
6% SS H H A A %
7% SSS HHHHH AAAAA %
8% SS H H A A %
9% SSSSS H H A A %
10% %
11% %
12% Wizard's Toolkit Secure Hash Algorithm 2-384 Methods %
13% %
14% Software Design %
15% Cristy %
16% March 2003 %
17% %
18% %
19% Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization %
20% dedicated to making software imaging solutions freely available. %
21% %
22% You may not use this file except in compliance with the License. You may %
23% obtain a copy of the License at %
24% %
25% https://imagemagick.org/script/license.php %
26% %
27% Unless required by applicable law or agreed to in writing, software %
28% distributed under the License is distributed on an "AS IS" BASIS, %
29% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30% See the License for the specific language governing permissions and %
31% limitations under the License. %
32% %
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34%
35% See http://csrc.nist.gov/groups/ST/toolkit/index.html.
36%
37*/
38
39/*
40 Include declarations.
41*/
42#include "wizard/studio.h"
43#include "wizard/exception.h"
45#include "wizard/memory_.h"
46#include "wizard/sha2384.h"
47/*
48 Define declarations.
49*/
50#define SHA2384Blocksize 128
51#define SHA2384Digestsize 48
52
53/*
54 Typedef declarations.
55*/
57{
58 unsigned int
61
65
70
71 size_t
73
76
77 time_t
79
80 size_t
82};
83
84/*
85 Forward declarations.
86*/
87static void
89
90/*
91%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92% %
93% %
94% %
95% A c q u i r e S H A I n f o %
96% %
97% %
98% %
99%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100%
101% AcquireSHA2384Info() allocate the SHA2384Info structure.
102%
103% The format of the AcquireSHA2384Info method is:
104%
105% SHA2384Info *AcquireSHA2384Info(void)
106%
107*/
109{
111 *sha_info;
112
113 unsigned int
114 lsb_first;
115
116 sha_info=(SHA2384Info *) AcquireWizardMemory(sizeof(*sha_info));
117 if (sha_info == (SHA2384Info *) NULL)
119 (void) memset(sha_info,0,sizeof(*sha_info));
121 sha_info->blocksize=SHA2384Blocksize;
125 SHA2384Blocksize,sizeof(*sha_info->accumulator));
126 if (sha_info->accumulator == (WizardSizeType *) NULL)
128 lsb_first=1;
129 sha_info->lsb_first=(int) (*(char *) &lsb_first) == 1 ? WizardTrue :
131 sha_info->timestamp=time((time_t *) NULL);
132 sha_info->signature=WizardSignature;
133 (void) InitializeSHA2384(sha_info);
134 return(sha_info);
135}
136
137/*
138%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139% %
140% %
141% %
142% D e s t r o y S H A I n f o %
143% %
144% %
145% %
146%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147%
148% DestroySHA2384Info() zeros memory associated with the SHA2384Info structure.
149%
150% The format of the DestroySHA2384Info method is:
151%
152% SHA2384Info *DestroySHA2384Info(SHA2384Info *sha_info)
153%
154% A description of each parameter follows:
155%
156% o sha_info: The cipher sha_info.
157%
158*/
160{
162 assert(sha_info != (SHA2384Info *) NULL);
163 assert(sha_info->signature == WizardSignature);
164 if (sha_info->accumulator != (WizardSizeType *) NULL)
166 sha_info->accumulator);
167 if (sha_info->message != (StringInfo *) NULL)
168 sha_info->message=DestroyStringInfo(sha_info->message);
169 if (sha_info->digest != (StringInfo *) NULL)
170 sha_info->digest=DestroyStringInfo(sha_info->digest);
171 sha_info->signature=(~WizardSignature);
172 sha_info=(SHA2384Info *) RelinquishWizardMemory(sha_info);
173 return(sha_info);
174}
175
176/*
177%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178% %
179% %
180% %
181% F i n a l i z e S H A %
182% %
183% %
184% %
185%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186%
187% FinalizeSHA2384() finalizes the SHA2384 message accumulator computation.
188%
189% The format of the FinalizeSHA2384 method is:
190%
191% WizardBooleanType FinalizeSHA2384(SHA2384Info *sha_info)
192%
193% A description of each parameter follows:
194%
195% o sha_info: The address of a structure of type SHA2384Info.
196%
197*/
199{
200 size_t
201 i;
202
203 unsigned char
204 *q;
205
207 *p;
208
209 unsigned char
210 *datum;
211
213 count;
214
216 high_order,
217 low_order;
218
219 /*
220 Add padding and return the message accumulator.
221 */
223 assert(sha_info != (SHA2384Info *) NULL);
224 assert(sha_info->signature == WizardSignature);
225 low_order=sha_info->low_order;
226 high_order=sha_info->high_order;
227 count=(WizardOffsetType) ((low_order >> 3) & 0x7f);
228 datum=GetStringInfoDatum(sha_info->message);
229 datum[count++]=(unsigned char) 0x80;
230 if (count <= (WizardOffsetType) (GetStringInfoLength(sha_info->message)-16))
231 (void) memset(datum+count,0,(size_t) (GetStringInfoLength(
232 sha_info->message)-16-count));
233 else
234 {
235 (void) memset(datum+count,0,(size_t) (GetStringInfoLength(
236 sha_info->message)-count));
237 TransformSHA2384(sha_info);
238 (void) memset(datum,0,(GetStringInfoLength(sha_info->message)-
239 16));
240 }
241 datum[112]=(unsigned char) (high_order >> 56);
242 datum[113]=(unsigned char) (high_order >> 48);
243 datum[114]=(unsigned char) (high_order >> 40);
244 datum[115]=(unsigned char) (high_order >> 32);
245 datum[116]=(unsigned char) (high_order >> 24);
246 datum[117]=(unsigned char) (high_order >> 16);
247 datum[118]=(unsigned char) (high_order >> 8);
248 datum[119]=(unsigned char) high_order;
249 datum[120]=(unsigned char) (low_order >> 56);
250 datum[121]=(unsigned char) (low_order >> 48);
251 datum[122]=(unsigned char) (low_order >> 40);
252 datum[123]=(unsigned char) (low_order >> 32);
253 datum[124]=(unsigned char) (low_order >> 24);
254 datum[125]=(unsigned char) (low_order >> 16);
255 datum[126]=(unsigned char) (low_order >> 8);
256 datum[127]=(unsigned char) low_order;
257 TransformSHA2384(sha_info);
258 p=sha_info->accumulator;
259 q=GetStringInfoDatum(sha_info->digest);
260 for (i=0; i < (SHA2384Digestsize/8); i++)
261 {
262 *q++=(unsigned char) ((*p >> 56) & 0xff);
263 *q++=(unsigned char) ((*p >> 48) & 0xff);
264 *q++=(unsigned char) ((*p >> 40) & 0xff);
265 *q++=(unsigned char) ((*p >> 32) & 0xff);
266 *q++=(unsigned char) ((*p >> 24) & 0xff);
267 *q++=(unsigned char) ((*p >> 16) & 0xff);
268 *q++=(unsigned char) ((*p >> 8) & 0xff);
269 *q++=(unsigned char) (*p & 0xff);
270 p++;
271 }
272 /*
273 Reset working registers.
274 */
275 count=0;
276 high_order=0;
277 low_order=0;
278 return(WizardTrue);
279}
280
281/*
282%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
283% %
284% %
285% %
286% G e t S H A 3 8 4 B l o c k s i z e %
287% %
288% %
289% %
290%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
291%
292% GetSHA2384Blocksize() returns the SHA2384 blocksize.
293%
294% The format of the GetSHA2384Blocksize method is:
295%
296% unsigned int *GetSHA2384Blocksize(const SHA2384Info *sha2384_info)
297%
298% A description of each parameter follows:
299%
300% o sha2384_info: The sha2384 info.
301%
302*/
303WizardExport unsigned int GetSHA2384Blocksize(const SHA2384Info *sha2384_info)
304{
306 WizardAssert(CipherDomain,sha2384_info != (SHA2384Info *) NULL);
308 return(sha2384_info->blocksize);
309}
310
311/*
312%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313% %
314% %
315% %
316% G e t S H A 3 8 4 D i g e s t %
317% %
318% %
319% %
320%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321%
322% GetSHA2384Digest() returns the SHA2384 digest.
323%
324% The format of the GetSHA2384Digest method is:
325%
326% const StringInfo *GetSHA2384Digest(const SHA2384Info *sha2384_info)
327%
328% A description of each parameter follows:
329%
330% o sha2384_info: The sha2384 info.
331%
332*/
334{
336 WizardAssert(HashDomain,sha2384_info != (SHA2384Info *) NULL);
338 return(sha2384_info->digest);
339}
340
341/*
342%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343% %
344% %
345% %
346% G e t S H A 3 8 4 D i g e s t s i z e %
347% %
348% %
349% %
350%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351%
352% GetSHA2384Digestsize() returns the SHA2384 digest size.
353%
354% The format of the GetSHA2384Digestsize method is:
355%
356% unsigned int *GetSHA2384Digestsize(const SHA2384Info *sha2384_info)
357%
358% A description of each parameter follows:
359%
360% o sha2384_info: The sha2384 info.
361%
362*/
363WizardExport unsigned int GetSHA2384Digestsize(const SHA2384Info *sha2384_info)
364{
366 WizardAssert(CipherDomain,sha2384_info != (SHA2384Info *) NULL);
368 return(sha2384_info->digestsize);
369}
370
371/*
372%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
373% %
374% %
375% %
376% I n i t i a l i z e S H A %
377% %
378% %
379% %
380%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
381%
382% IntializeSHA2384() intializes the SHA2384 accumulator.
383%
384% The format of the DestroySHA2384Info method is:
385%
386% WizardBooleanType InitializeSHA2384Info(SHA2384Info *sha_info)
387%
388% A description of each parameter follows:
389%
390% o sha_info: The cipher sha_info.
391%
392*/
394{
396 assert(sha_info != (SHA2384Info *) NULL);
397 assert(sha_info->signature == WizardSignature);
398 sha_info->accumulator[0]=WizardULLConstant(0xcbbb9d5dc1059ed8);
399 sha_info->accumulator[1]=WizardULLConstant(0x629a292a367cd507);
400 sha_info->accumulator[2]=WizardULLConstant(0x9159015a3070dd17);
401 sha_info->accumulator[3]=WizardULLConstant(0x152fecd8f70e5939);
402 sha_info->accumulator[4]=WizardULLConstant(0x67332667ffc00b31);
403 sha_info->accumulator[5]=WizardULLConstant(0x8eb44a8768581511);
404 sha_info->accumulator[6]=WizardULLConstant(0xdb0c2e0d64f98fa7);
405 sha_info->accumulator[7]=WizardULLConstant(0x47b5481dbefa4fa4);
406 sha_info->low_order=0;
407 sha_info->high_order=0;
408 sha_info->offset=0;
409 return(WizardTrue);
410}
411
412/*
413%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
414% %
415% %
416% %
417% T r a n s f o r m S H A %
418% %
419% %
420% %
421%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422%
423% TransformSHA2384() transforms the SHA2384 message accumulator.
424%
425% The format of the TransformSHA2384 method is:
426%
427% TransformSHA2384(SHA2384Info *sha_info)
428%
429% A description of each parameter follows:
430%
431% o sha_info: The address of a structure of type SHA2384Info.
432%
433*/
434
435static inline WizardSizeType Ch(const WizardSizeType x,const WizardSizeType y,
436 const WizardSizeType z)
437{
438 return((x & y) ^ (~x & z));
439}
440
441static inline WizardSizeType Maj(const WizardSizeType x,const WizardSizeType y,
442 const WizardSizeType z)
443{
444 return((x & y) ^ (x & z) ^ (y & z));
445}
446
448{
449 return((WizardSizeType) (x & WizardULLConstant(0xffffffffffffffff)));
450}
451
453 const WizardSizeType n)
454{
455 return(Trunc64((x >> n) | (x << (64-n))));
456}
457
458static void TransformSHA2384(SHA2384Info *sha_info)
459{
460#define Sigma0(x) (RotateRight(x,1) ^ RotateRight(x,8) ^ Trunc64((x) >> 7))
461#define Sigma1(x) (RotateRight(x,19) ^ RotateRight(x,61) ^ Trunc64((x) >> 6))
462#define Suma0(x) (RotateRight(x,28) ^ RotateRight(x,34) ^ RotateRight(x,39))
463#define Suma1(x) (RotateRight(x,14) ^ RotateRight(x,18) ^ RotateRight(x,41))
464
465 ssize_t
466 j;
467
468 ssize_t
469 i;
470
471 unsigned char
472 *p;
473
474 static WizardSizeType
475 K[80] =
476 {
477 WizardULLConstant(0x428a2f98d728ae22),
478 WizardULLConstant(0x7137449123ef65cd),
479 WizardULLConstant(0xb5c0fbcfec4d3b2f),
480 WizardULLConstant(0xe9b5dba58189dbbc),
481 WizardULLConstant(0x3956c25bf348b538),
482 WizardULLConstant(0x59f111f1b605d019),
483 WizardULLConstant(0x923f82a4af194f9b),
484 WizardULLConstant(0xab1c5ed5da6d8118),
485 WizardULLConstant(0xd807aa98a3030242),
486 WizardULLConstant(0x12835b0145706fbe),
487 WizardULLConstant(0x243185be4ee4b28c),
488 WizardULLConstant(0x550c7dc3d5ffb4e2),
489 WizardULLConstant(0x72be5d74f27b896f),
490 WizardULLConstant(0x80deb1fe3b1696b1),
491 WizardULLConstant(0x9bdc06a725c71235),
492 WizardULLConstant(0xc19bf174cf692694),
493 WizardULLConstant(0xe49b69c19ef14ad2),
494 WizardULLConstant(0xefbe4786384f25e3),
495 WizardULLConstant(0x0fc19dc68b8cd5b5),
496 WizardULLConstant(0x240ca1cc77ac9c65),
497 WizardULLConstant(0x2de92c6f592b0275),
498 WizardULLConstant(0x4a7484aa6ea6e483),
499 WizardULLConstant(0x5cb0a9dcbd41fbd4),
500 WizardULLConstant(0x76f988da831153b5),
501 WizardULLConstant(0x983e5152ee66dfab),
502 WizardULLConstant(0xa831c66d2db43210),
503 WizardULLConstant(0xb00327c898fb213f),
504 WizardULLConstant(0xbf597fc7beef0ee4),
505 WizardULLConstant(0xc6e00bf33da88fc2),
506 WizardULLConstant(0xd5a79147930aa725),
507 WizardULLConstant(0x06ca6351e003826f),
508 WizardULLConstant(0x142929670a0e6e70),
509 WizardULLConstant(0x27b70a8546d22ffc),
510 WizardULLConstant(0x2e1b21385c26c926),
511 WizardULLConstant(0x4d2c6dfc5ac42aed),
512 WizardULLConstant(0x53380d139d95b3df),
513 WizardULLConstant(0x650a73548baf63de),
514 WizardULLConstant(0x766a0abb3c77b2a8),
515 WizardULLConstant(0x81c2c92e47edaee6),
516 WizardULLConstant(0x92722c851482353b),
517 WizardULLConstant(0xa2bfe8a14cf10364),
518 WizardULLConstant(0xa81a664bbc423001),
519 WizardULLConstant(0xc24b8b70d0f89791),
520 WizardULLConstant(0xc76c51a30654be30),
521 WizardULLConstant(0xd192e819d6ef5218),
522 WizardULLConstant(0xd69906245565a910),
523 WizardULLConstant(0xf40e35855771202a),
524 WizardULLConstant(0x106aa07032bbd1b8),
525 WizardULLConstant(0x19a4c116b8d2d0c8),
526 WizardULLConstant(0x1e376c085141ab53),
527 WizardULLConstant(0x2748774cdf8eeb99),
528 WizardULLConstant(0x34b0bcb5e19b48a8),
529 WizardULLConstant(0x391c0cb3c5c95a63),
530 WizardULLConstant(0x4ed8aa4ae3418acb),
531 WizardULLConstant(0x5b9cca4f7763e373),
532 WizardULLConstant(0x682e6ff3d6b2b8a3),
533 WizardULLConstant(0x748f82ee5defb2fc),
534 WizardULLConstant(0x78a5636f43172f60),
535 WizardULLConstant(0x84c87814a1f0ab72),
536 WizardULLConstant(0x8cc702081a6439ec),
537 WizardULLConstant(0x90befffa23631e28),
538 WizardULLConstant(0xa4506cebde82bde9),
539 WizardULLConstant(0xbef9a3f7b2c67915),
540 WizardULLConstant(0xc67178f2e372532b),
541 WizardULLConstant(0xca273eceea26619c),
542 WizardULLConstant(0xd186b8c721c0c207),
543 WizardULLConstant(0xeada7dd6cde0eb1e),
544 WizardULLConstant(0xf57d4f7fee6ed178),
545 WizardULLConstant(0x06f067aa72176fba),
546 WizardULLConstant(0x0a637dc5a2c898a6),
547 WizardULLConstant(0x113f9804bef90dae),
548 WizardULLConstant(0x1b710b35131c471b),
549 WizardULLConstant(0x28db77f523047d84),
550 WizardULLConstant(0x32caab7b40c72493),
551 WizardULLConstant(0x3c9ebe0a15c9bebc),
552 WizardULLConstant(0x431d67c49c100d4c),
553 WizardULLConstant(0x4cc5d4becb3e42b6),
554 WizardULLConstant(0x597f299cfc657e2a),
555 WizardULLConstant(0x5fcb6fab3ad6faec),
556 WizardULLConstant(0x6c44198c4a475817)
557 }; /* 64-bit fractional part of the cube root of the first 64 primes */
558
560 A,
561 B,
562 C,
563 D,
564 E,
565 F,
566 G,
567 H,
568 T,
569 T1,
570 T2,
571 W[80];
572
573 p=GetStringInfoDatum(sha_info->message);
574 if (sha_info->lsb_first == WizardFalse)
575 for (i=0; i < 16; i++)
576 {
577 T=(*((WizardSizeType *) p));
578 p+=8;
579 W[i]=(T);
580 }
581 else
582 for (i=0; i < 16; i++)
583 {
584 T=(*((WizardSizeType *) p));
585 p+=8;
586 W[i]=(WizardSizeType)
587 (((T << 56) & WizardULLConstant(0xff00000000000000)) |
588 ((T << 40) & WizardULLConstant(0x00ff000000000000)) |
589 ((T << 24) & WizardULLConstant(0x0000ff0000000000)) |
590 ((T << 8) & WizardULLConstant(0x000000ff00000000)) |
591 ((T >> 8) & WizardULLConstant(0x00000000ff000000)) |
592 ((T >> 24) & WizardULLConstant(0x0000000000ff0000)) |
593 ((T >> 40) & WizardULLConstant(0x000000000000ff00)) |
594 ((T >> 56) & WizardULLConstant(0x00000000000000ff)));
595 }
596 /*
597 Copy accumulator to registers.
598 */
599 A=sha_info->accumulator[0];
600 B=sha_info->accumulator[1];
601 C=sha_info->accumulator[2];
602 D=sha_info->accumulator[3];
603 E=sha_info->accumulator[4];
604 F=sha_info->accumulator[5];
605 G=sha_info->accumulator[6];
606 H=sha_info->accumulator[7];
607 for (i=16; i < 80; i++)
608 W[i]=Trunc64(Sigma1(W[i-2])+W[i-7]+Sigma0(W[i-15])+W[i-16]);
609 for (j=0; j < 80; j++)
610 {
611 T1=Trunc64(H+Suma1(E)+Ch(E,F,G)+K[j]+W[j]);
612 T2=Trunc64(Suma0(A)+Maj(A,B,C));
613 H=G;
614 G=F;
615 F=E;
616 E=Trunc64(D+T1);
617 D=C;
618 C=B;
619 B=A;
620 A=Trunc64(T1+T2);
621 }
622 /*
623 Add registers back to accumulator.
624 */
625 sha_info->accumulator[0]=Trunc64(sha_info->accumulator[0]+A);
626 sha_info->accumulator[1]=Trunc64(sha_info->accumulator[1]+B);
627 sha_info->accumulator[2]=Trunc64(sha_info->accumulator[2]+C);
628 sha_info->accumulator[3]=Trunc64(sha_info->accumulator[3]+D);
629 sha_info->accumulator[4]=Trunc64(sha_info->accumulator[4]+E);
630 sha_info->accumulator[5]=Trunc64(sha_info->accumulator[5]+F);
631 sha_info->accumulator[6]=Trunc64(sha_info->accumulator[6]+G);
632 sha_info->accumulator[7]=Trunc64(sha_info->accumulator[7]+H);
633 /*
634 Reset working registers.
635 */
636 A=0;
637 B=0;
638 C=0;
639 D=0;
640 E=0;
641 F=0;
642 G=0;
643 H=0;
644 T=0;
645 T1=0;
646 T2=0;
647 (void) memset(W,0,sizeof(W));
648}
649
650/*
651%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
652% %
653% %
654% %
655% U p d a t e S H A %
656% %
657% %
658% %
659%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
660%
661% UpdateSHA2384() updates the SHA2384 message accumulator.
662%
663% The format of the UpdateSHA2384 method is:
664%
665% WizardBooleanType UpdateSHA2384(SHA2384Info *sha_info,
666% const StringInfo *message)
667%
668% A description of each parameter follows:
669%
670% o sha_info: The address of a structure of type SHA2384Info.
671%
672% o message: The message.
673%
674*/
676 const StringInfo *message)
677{
678 size_t
679 i;
680
681 unsigned char
682 *p;
683
684 size_t
685 n;
686
688 length;
689
690 /*
691 Update the SHA2384 accumulator.
692 */
693 assert(sha_info != (SHA2384Info *) NULL);
694 assert(sha_info->signature == WizardSignature);
695 n=GetStringInfoLength(message);
696 length=Trunc64(sha_info->low_order+((WizardSizeType) n << 3));
697 if (length < sha_info->low_order)
698 sha_info->high_order++;
699 sha_info->low_order=length;
700 sha_info->high_order+=(WizardSizeType) n >> 61;
701 p=GetStringInfoDatum(message);
702 if (sha_info->offset != 0)
703 {
704 i=GetStringInfoLength(sha_info->message)-sha_info->offset;
705 if (i > n)
706 i=n;
708 sha_info->offset,p,i);
709 n-=i;
710 p+=i;
711 sha_info->offset+=i;
712 if (sha_info->offset != GetStringInfoLength(sha_info->message))
713 return(WizardTrue);
714 TransformSHA2384(sha_info);
715 }
716 while (n >= GetStringInfoLength(sha_info->message))
717 {
718 SetStringInfoDatum(sha_info->message,p);
719 p+=GetStringInfoLength(sha_info->message);
720 n-=GetStringInfoLength(sha_info->message);
721 TransformSHA2384(sha_info);
722 }
723 (void) CopyWizardMemory(GetStringInfoDatum(sha_info->message),p,n);
724 sha_info->offset=n;
725 /*
726 Reset working registers.
727 */
728 i=0;
729 n=0;
730 length=0;
731 return(WizardTrue);
732}
#define WizardAssert(domain, predicate)
#define ThrowWizardFatalError(domain, error)
@ HashDomain
Definition exception.h:30
@ CipherDomain
Definition exception.h:34
@ HashError
Definition exception.h:85
@ MemoryError
Definition exception.h:49
WizardBooleanType LogWizardEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition log.c:1390
@ TraceEvent
Definition log.h:39
#define GetWizardModule()
Definition log.h:30
static unsigned int H(const unsigned int x, const unsigned int y, const unsigned int z)
Definition md5.c:424
static unsigned int F(const unsigned int x, const unsigned int y, const unsigned int z)
Definition md5.c:412
static unsigned int G(const unsigned int x, const unsigned int y, const unsigned int z)
Definition md5.c:418
WizardExport void * AcquireWizardMemory(const size_t size)
Definition memory.c:586
WizardExport void * CopyWizardMemory(void *destination, const void *source, const size_t size)
Definition memory.c:700
WizardExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition memory.c:657
WizardExport void * RelinquishWizardMemory(void *memory)
Definition memory.c:1039
#define WizardExport
#define WizardSignature
#define SHA2384Blocksize
Definition sha2384.c:50
WizardExport SHA2384Info * DestroySHA2384Info(SHA2384Info *sha_info)
Definition sha2384.c:159
WizardExport WizardBooleanType UpdateSHA2384(SHA2384Info *sha_info, const StringInfo *message)
Definition sha2384.c:675
WizardExport SHA2384Info * AcquireSHA2384Info(void)
Definition sha2384.c:108
#define SHA2384Digestsize
Definition sha2384.c:51
#define Suma1(x)
#define Sigma0(x)
#define Sigma1(x)
WizardExport unsigned int GetSHA2384Digestsize(const SHA2384Info *sha2384_info)
Definition sha2384.c:363
#define Suma0(x)
WizardExport unsigned int GetSHA2384Blocksize(const SHA2384Info *sha2384_info)
Definition sha2384.c:303
WizardExport WizardBooleanType FinalizeSHA2384(SHA2384Info *sha_info)
Definition sha2384.c:198
static void TransformSHA2384(SHA2384Info *)
Definition sha2384.c:458
WizardExport const StringInfo * GetSHA2384Digest(const SHA2384Info *sha2384_info)
Definition sha2384.c:333
WizardExport WizardBooleanType InitializeSHA2384(SHA2384Info *sha_info)
Definition sha2384.c:393
static WizardSizeType Trunc64(const WizardSizeType x)
Definition sha2384.c:447
#define RotateRight(x, n)
#define Maj(x, y, z)
#define Ch(x, y, z)
WizardExport size_t GetStringInfoLength(const StringInfo *string_info)
Definition string.c:1280
WizardExport StringInfo * AcquireStringInfo(const size_t length)
Definition string.c:179
WizardExport void SetStringInfoDatum(StringInfo *string_info, const unsigned char *source)
Definition string.c:1832
WizardExport unsigned char * GetStringInfoDatum(const StringInfo *string_info)
Definition string.c:1251
WizardExport StringInfo * DestroyStringInfo(StringInfo *string_info)
Definition string.c:857
WizardSizeType high_order
Definition sha2384.c:69
unsigned int digestsize
Definition sha2384.c:59
StringInfo * message
Definition sha2384.c:64
unsigned int blocksize
Definition sha2384.c:60
size_t signature
Definition sha2384.c:81
time_t timestamp
Definition sha2384.c:78
WizardBooleanType lsb_first
Definition sha2384.c:75
StringInfo * digest
Definition sha2384.c:63
size_t offset
Definition sha2384.c:72
WizardSizeType * accumulator
Definition sha2384.c:67
WizardSizeType low_order
Definition sha2384.c:68
#define WizardULLConstant(c)
Definition wizard-type.h:36
size_t WizardSizeType
Definition wizard-type.h:51
ssize_t WizardOffsetType
Definition wizard-type.h:50
WizardBooleanType
Definition wizard-type.h:26
@ WizardTrue
Definition wizard-type.h:28
@ WizardFalse
Definition wizard-type.h:27