Package list libcryptx-perl / 89c2aa8
ltc sync Karel Miko 3 years ago
8 changed file(s) with 466 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
7171 &sha3_512_test,
7272 NULL
7373 };
74 #endif
75
76 #ifdef LTC_KECCAK
77 const struct ltc_hash_descriptor keccak_224_desc =
78 {
79 "keccak224", /* name of hash */
80 29, /* internal ID */
81 28, /* Size of digest in octets */
82 144, /* Input block size in octets */
83 { 0 }, 0, /* no ASN.1 OID */
84 &sha3_224_init,
85 &sha3_process,
86 &keccak_done,
87 &keccak_224_test,
88 NULL
89 };
90
91 const struct ltc_hash_descriptor keccak_256_desc =
92 {
93 "keccak256", /* name of hash */
94 30, /* internal ID */
95 32, /* Size of digest in octets */
96 136, /* Input block size in octets */
97 { 0 }, 0, /* no ASN.1 OID */
98 &sha3_256_init,
99 &sha3_process,
100 &keccak_done,
101 &keccak_256_test,
102 NULL
103 };
104
105 const struct ltc_hash_descriptor keccak_384_desc =
106 {
107 "keccak384", /* name of hash */
108 31, /* internal ID */
109 48, /* Size of digest in octets */
110 104, /* Input block size in octets */
111 { 0 }, 0, /* no ASN.1 OID */
112 &sha3_384_init,
113 &sha3_process,
114 &keccak_done,
115 &keccak_384_test,
116 NULL
117 };
118
119 const struct ltc_hash_descriptor keccak_512_desc =
120 {
121 "keccak512", /* name of hash */
122 32, /* internal ID */
123 64, /* Size of digest in octets */
124 72, /* Input block size in octets */
125 { 0 }, 0, /* no ASN.1 OID */
126 &sha3_512_init,
127 &sha3_process,
128 &keccak_done,
129 &keccak_512_test,
130 NULL
131 };
132 #endif
133
134 #if defined(LTC_SHA3) || defined(LTC_KECCAK)
74135
75136 #define SHA3_KECCAK_SPONGE_WORDS 25 /* 1600 bits > 200 bytes > 25 x ulong64 */
76137 #define SHA3_KECCAK_ROUNDS 24
133194 }
134195 }
135196
197 static LTC_INLINE int _done(hash_state *md, unsigned char *hash, ulong64 pad)
198 {
199 unsigned i;
200
201 LTC_ARGCHK(md != NULL);
202 LTC_ARGCHK(hash != NULL);
203
204 md->sha3.s[md->sha3.word_index] ^= (md->sha3.saved ^ (pad << (md->sha3.byte_index * 8)));
205 md->sha3.s[SHA3_KECCAK_SPONGE_WORDS - md->sha3.capacity_words - 1] ^= CONST64(0x8000000000000000);
206 keccakf(md->sha3.s);
207
208 /* store sha3.s[] as little-endian bytes into sha3.sb */
209 for(i = 0; i < SHA3_KECCAK_SPONGE_WORDS; i++) {
210 STORE64L(md->sha3.s[i], md->sha3.sb + i * 8);
211 }
212
213 XMEMCPY(hash, md->sha3.sb, md->sha3.capacity_words * 4);
214 return CRYPT_OK;
215 }
216
136217 /* Public Inteface */
137218
138219 int sha3_224_init(hash_state *md)
167248 return CRYPT_OK;
168249 }
169250
251 #ifdef LTC_SHA3
170252 int sha3_shake_init(hash_state *md, int num)
171253 {
172254 LTC_ARGCHK(md != NULL);
175257 md->sha3.capacity_words = (unsigned short)(2 * num / (8 * sizeof(ulong64)));
176258 return CRYPT_OK;
177259 }
260 #endif
178261
179262 int sha3_process(hash_state *md, const unsigned char *in, unsigned long inlen)
180263 {
228311 return CRYPT_OK;
229312 }
230313
314 #ifdef LTC_SHA3
231315 int sha3_done(hash_state *md, unsigned char *hash)
232316 {
233 unsigned i;
234
235 LTC_ARGCHK(md != NULL);
236 LTC_ARGCHK(hash != NULL);
237
238 md->sha3.s[md->sha3.word_index] ^= (md->sha3.saved ^ (CONST64(0x06) << (md->sha3.byte_index * 8)));
239 md->sha3.s[SHA3_KECCAK_SPONGE_WORDS - md->sha3.capacity_words - 1] ^= CONST64(0x8000000000000000);
240 keccakf(md->sha3.s);
241
242 /* store sha3.s[] as little-endian bytes into sha3.sb */
243 for(i = 0; i < SHA3_KECCAK_SPONGE_WORDS; i++) {
244 STORE64L(md->sha3.s[i], md->sha3.sb + i * 8);
245 }
246
247 XMEMCPY(hash, md->sha3.sb, md->sha3.capacity_words * 4);
248 return CRYPT_OK;
249 }
250
317 return _done(md, hash, CONST64(0x06));
318 }
319 #endif
320
321 #ifdef LTC_KECCAK
322 int keccak_done(hash_state *md, unsigned char *hash)
323 {
324 return _done(md, hash, CONST64(0x01));
325 }
326 #endif
327
328 #ifdef LTC_SHA3
251329 int sha3_shake_done(hash_state *md, unsigned char *out, unsigned long outlen)
252330 {
253331 /* IMPORTANT NOTE: sha3_shake_done can be called many times */
297375 if ((err = sha3_shake_done(&md, out, *outlen)) != CRYPT_OK) return err;
298376 return CRYPT_OK;
299377 }
378 #endif
300379
301380 #endif
302381
395395
396396 #endif
397397
398 #ifdef LTC_KECCAK
399
400 int keccak_224_test(void)
401 {
402 #ifndef LTC_TEST
403 return CRYPT_NOP;
404 #else
405 hash_state c;
406 unsigned char hash[MAXBLOCKSIZE];
407
408 keccak_224_init(&c);
409 keccak_process(&c, (unsigned char*) "\xcc", 1);
410 keccak_done(&c, hash);
411 if(compare_testvector(hash, 28,
412 "\xa9\xca\xb5\x9e\xb4\x0a\x10\xb2"
413 "\x46\x29\x0f\x2d\x60\x86\xe3\x2e"
414 "\x36\x89\xfa\xf1\xd2\x6b\x47\x0c"
415 "\x89\x9f\x28\x02", 28,
416 "KECCAK-224", 0) != 0) {
417 return CRYPT_FAIL_TESTVECTOR;
418 }
419
420 keccak_224_init(&c);
421 keccak_process(&c, (unsigned char*)"\x41\xfb", 2);
422 keccak_done(&c, hash);
423 if(compare_testvector(hash, 28,
424 "\x61\x5b\xa3\x67\xaf\xdc\x35\xaa"
425 "\xc3\x97\xbc\x7e\xb5\xd5\x8d\x10"
426 "\x6a\x73\x4b\x24\x98\x6d\x5d\x97"
427 "\x8f\xef\xd6\x2c", 28,
428 "KECCAK-224", 1) != 0) {
429 return CRYPT_FAIL_TESTVECTOR;
430 }
431
432 keccak_224_init(&c);
433 keccak_process(&c, (unsigned char*)
434 "\x52\xa6\x08\xab\x21\xcc\xdd\x8a"
435 "\x44\x57\xa5\x7e\xde\x78\x21\x76", 16);
436 keccak_done(&c, hash);
437 if(compare_testvector(hash, 28,
438 "\x56\x79\xcd\x50\x9c\x51\x20\xaf"
439 "\x54\x79\x5c\xf4\x77\x14\x96\x41"
440 "\xcf\x27\xb2\xeb\xb6\xa5\xf9\x03"
441 "\x40\x70\x4e\x57", 28,
442 "KECCAK-224", 2) != 0) {
443 return CRYPT_FAIL_TESTVECTOR;
444 }
445
446 keccak_224_init(&c);
447 keccak_process(&c, (unsigned char*)
448 "\x43\x3c\x53\x03\x13\x16\x24\xc0"
449 "\x02\x1d\x86\x8a\x30\x82\x54\x75"
450 "\xe8\xd0\xbd\x30\x52\xa0\x22\x18"
451 "\x03\x98\xf4\xca\x44\x23\xb9\x82"
452 "\x14\xb6\xbe\xaa\xc2\x1c\x88\x07"
453 "\xa2\xc3\x3f\x8c\x93\xbd\x42\xb0"
454 "\x92\xcc\x1b\x06\xce\xdf\x32\x24"
455 "\xd5\xed\x1e\xc2\x97\x84\x44\x4f"
456 "\x22\xe0\x8a\x55\xaa\x58\x54\x2b"
457 "\x52\x4b\x02\xcd\x3d\x5d\x5f\x69"
458 "\x07\xaf\xe7\x1c\x5d\x74\x62\x22"
459 "\x4a\x3f\x9d\x9e\x53\xe7\xe0\x84"
460 "\x6d\xcb\xb4\xce", 100);
461 keccak_done(&c, hash);
462 if(compare_testvector(hash, 28,
463 "\x62\xb1\x0f\x1b\x62\x36\xeb\xc2"
464 "\xda\x72\x95\x77\x42\xa8\xd4\xe4"
465 "\x8e\x21\x3b\x5f\x89\x34\x60\x4b"
466 "\xfd\x4d\x2c\x3a", 28,
467 "KECCAK-224", 3) != 0) {
468 return CRYPT_FAIL_TESTVECTOR;
469 }
470
471 return CRYPT_OK;
472 #endif
473 }
474
475 int keccak_256_test(void)
476 {
477 #ifndef LTC_TEST
478 return CRYPT_NOP;
479 #else
480 hash_state c;
481 unsigned char hash[MAXBLOCKSIZE];
482
483 keccak_256_init(&c);
484 keccak_process(&c, (unsigned char*) "\xcc", 1);
485 keccak_done(&c, hash);
486 if(compare_testvector(hash, 32,
487 "\xee\xad\x6d\xbf\xc7\x34\x0a\x56"
488 "\xca\xed\xc0\x44\x69\x6a\x16\x88"
489 "\x70\x54\x9a\x6a\x7f\x6f\x56\x96"
490 "\x1e\x84\xa5\x4b\xd9\x97\x0b\x8a", 32,
491 "KECCAK-256", 0) != 0) {
492 return CRYPT_FAIL_TESTVECTOR;
493 }
494
495 keccak_256_init(&c);
496 keccak_process(&c, (unsigned char*)"\x41\xfb", 2);
497 keccak_done(&c, hash);
498 if(compare_testvector(hash, 32,
499 "\xa8\xea\xce\xda\x4d\x47\xb3\x28"
500 "\x1a\x79\x5a\xd9\xe1\xea\x21\x22"
501 "\xb4\x07\xba\xf9\xaa\xbc\xb9\xe1"
502 "\x8b\x57\x17\xb7\x87\x35\x37\xd2", 32,
503 "KECCAK-256", 1) != 0) {
504 return CRYPT_FAIL_TESTVECTOR;
505 }
506
507 keccak_256_init(&c);
508 keccak_process(&c, (unsigned char*)
509 "\x52\xa6\x08\xab\x21\xcc\xdd\x8a"
510 "\x44\x57\xa5\x7e\xde\x78\x21\x76", 16);
511 keccak_done(&c, hash);
512 if(compare_testvector(hash, 32,
513 "\x0e\x32\xde\xfa\x20\x71\xf0\xb5"
514 "\xac\x0e\x6a\x10\x8b\x84\x2e\xd0"
515 "\xf1\xd3\x24\x97\x12\xf5\x8e\xe0"
516 "\xdd\xf9\x56\xfe\x33\x2a\x5f\x95", 32,
517 "KECCAK-256", 2) != 0) {
518 return CRYPT_FAIL_TESTVECTOR;
519 }
520
521 keccak_256_init(&c);
522 keccak_process(&c, (unsigned char*)
523 "\x43\x3c\x53\x03\x13\x16\x24\xc0"
524 "\x02\x1d\x86\x8a\x30\x82\x54\x75"
525 "\xe8\xd0\xbd\x30\x52\xa0\x22\x18"
526 "\x03\x98\xf4\xca\x44\x23\xb9\x82"
527 "\x14\xb6\xbe\xaa\xc2\x1c\x88\x07"
528 "\xa2\xc3\x3f\x8c\x93\xbd\x42\xb0"
529 "\x92\xcc\x1b\x06\xce\xdf\x32\x24"
530 "\xd5\xed\x1e\xc2\x97\x84\x44\x4f"
531 "\x22\xe0\x8a\x55\xaa\x58\x54\x2b"
532 "\x52\x4b\x02\xcd\x3d\x5d\x5f\x69"
533 "\x07\xaf\xe7\x1c\x5d\x74\x62\x22"
534 "\x4a\x3f\x9d\x9e\x53\xe7\xe0\x84"
535 "\x6d\xcb\xb4\xce", 100);
536 keccak_done(&c, hash);
537 if(compare_testvector(hash, 32,
538 "\xce\x87\xa5\x17\x3b\xff\xd9\x23"
539 "\x99\x22\x16\x58\xf8\x01\xd4\x5c"
540 "\x29\x4d\x90\x06\xee\x9f\x3f\x9d"
541 "\x41\x9c\x8d\x42\x77\x48\xdc\x41", 32,
542 "KECCAK-256", 3) != 0) {
543 return CRYPT_FAIL_TESTVECTOR;
544 }
545
546 return CRYPT_OK;
547 #endif
548 }
549
550 int keccak_384_test(void)
551 {
552 #ifndef LTC_TEST
553 return CRYPT_NOP;
554 #else
555 hash_state c;
556 unsigned char hash[MAXBLOCKSIZE];
557
558 keccak_384_init(&c);
559 keccak_process(&c, (unsigned char*) "\xcc", 1);
560 keccak_done(&c, hash);
561 if(compare_testvector(hash, 48,
562 "\x1b\x84\xe6\x2a\x46\xe5\xa2\x01"
563 "\x86\x17\x54\xaf\x5d\xc9\x5c\x4a"
564 "\x1a\x69\xca\xf4\xa7\x96\xae\x40"
565 "\x56\x80\x16\x1e\x29\x57\x26\x41"
566 "\xf5\xfa\x1e\x86\x41\xd7\x95\x83"
567 "\x36\xee\x7b\x11\xc5\x8f\x73\xe9", 48,
568 "KECCAK-384", 0) != 0) {
569 return CRYPT_FAIL_TESTVECTOR;
570 }
571
572 keccak_384_init(&c);
573 keccak_process(&c, (unsigned char*)"\x41\xfb", 2);
574 keccak_done(&c, hash);
575 if(compare_testvector(hash, 48,
576 "\x49\x5c\xce\x27\x14\xcd\x72\xc8"
577 "\xc5\x3c\x33\x63\xd2\x2c\x58\xb5"
578 "\x59\x60\xfe\x26\xbe\x0b\xf3\xbb"
579 "\xc7\xa3\x31\x6d\xd5\x63\xad\x1d"
580 "\xb8\x41\x0e\x75\xee\xfe\xa6\x55"
581 "\xe3\x9d\x46\x70\xec\x0b\x17\x92", 48,
582 "KECCAK-384", 1) != 0) {
583 return CRYPT_FAIL_TESTVECTOR;
584 }
585
586 keccak_384_init(&c);
587 keccak_process(&c, (unsigned char*)
588 "\x52\xa6\x08\xab\x21\xcc\xdd\x8a"
589 "\x44\x57\xa5\x7e\xde\x78\x21\x76", 16);
590 keccak_done(&c, hash);
591 if(compare_testvector(hash, 48,
592 "\x18\x42\x2a\xc1\xd3\xa1\xe5\x4b"
593 "\xad\x87\x68\x83\xd2\xd6\xdd\x65"
594 "\xf6\x5c\x1d\x5f\x33\xa7\x12\x5c"
595 "\xc4\xc1\x86\x40\x5a\x12\xed\x64"
596 "\xba\x96\x67\x2e\xed\xda\x8c\x5a"
597 "\x63\x31\xd2\x86\x83\xf4\x88\xeb", 48,
598 "KECCAK-384", 2) != 0) {
599 return CRYPT_FAIL_TESTVECTOR;
600 }
601
602 keccak_384_init(&c);
603 keccak_process(&c, (unsigned char*)
604 "\x43\x3c\x53\x03\x13\x16\x24\xc0"
605 "\x02\x1d\x86\x8a\x30\x82\x54\x75"
606 "\xe8\xd0\xbd\x30\x52\xa0\x22\x18"
607 "\x03\x98\xf4\xca\x44\x23\xb9\x82"
608 "\x14\xb6\xbe\xaa\xc2\x1c\x88\x07"
609 "\xa2\xc3\x3f\x8c\x93\xbd\x42\xb0"
610 "\x92\xcc\x1b\x06\xce\xdf\x32\x24"
611 "\xd5\xed\x1e\xc2\x97\x84\x44\x4f"
612 "\x22\xe0\x8a\x55\xaa\x58\x54\x2b"
613 "\x52\x4b\x02\xcd\x3d\x5d\x5f\x69"
614 "\x07\xaf\xe7\x1c\x5d\x74\x62\x22"
615 "\x4a\x3f\x9d\x9e\x53\xe7\xe0\x84"
616 "\x6d\xcb\xb4\xce", 100);
617 keccak_done(&c, hash);
618 if(compare_testvector(hash, 48,
619 "\x13\x51\x14\x50\x8d\xd6\x3e\x27"
620 "\x9e\x70\x9c\x26\xf7\x81\x7c\x04"
621 "\x82\x76\x6c\xde\x49\x13\x2e\x3e"
622 "\xdf\x2e\xed\xd8\x99\x6f\x4e\x35"
623 "\x96\xd1\x84\x10\x0b\x38\x48\x68"
624 "\x24\x9f\x1d\x8b\x8f\xda\xa2\xc9", 48,
625 "KECCAK-384", 3) != 0) {
626 return CRYPT_FAIL_TESTVECTOR;
627 }
628
629 return CRYPT_OK;
630 #endif
631 }
632
633 int keccak_512_test(void)
634 {
635 #ifndef LTC_TEST
636 return CRYPT_NOP;
637 #else
638 hash_state c;
639 unsigned char hash[MAXBLOCKSIZE];
640
641 keccak_512_init(&c);
642 keccak_process(&c, (unsigned char*) "\xcc", 1);
643 keccak_done(&c, hash);
644 if(compare_testvector(hash, 64,
645 "\x86\x30\xc1\x3c\xbd\x06\x6e\xa7"
646 "\x4b\xbe\x7f\xe4\x68\xfe\xc1\xde"
647 "\xe1\x0e\xdc\x12\x54\xfb\x4c\x1b"
648 "\x7c\x5f\xd6\x9b\x64\x6e\x44\x16"
649 "\x0b\x8c\xe0\x1d\x05\xa0\x90\x8c"
650 "\xa7\x90\xdf\xb0\x80\xf4\xb5\x13"
651 "\xbc\x3b\x62\x25\xec\xe7\xa8\x10"
652 "\x37\x14\x41\xa5\xac\x66\x6e\xb9", 64,
653 "KECCAK-512", 0) != 0) {
654 return CRYPT_FAIL_TESTVECTOR;
655 }
656
657 keccak_512_init(&c);
658 keccak_process(&c, (unsigned char*)"\x41\xfb", 2);
659 keccak_done(&c, hash);
660 if(compare_testvector(hash, 64,
661 "\x55\x1d\xa6\x23\x6f\x8b\x96\xfc"
662 "\xe9\xf9\x7f\x11\x90\xe9\x01\x32"
663 "\x4f\x0b\x45\xe0\x6d\xbb\xb5\xcd"
664 "\xb8\x35\x5d\x6e\xd1\xdc\x34\xb3"
665 "\xf0\xea\xe7\xdc\xb6\x86\x22\xff"
666 "\x23\x2f\xa3\xce\xce\x0d\x46\x16"
667 "\xcd\xeb\x39\x31\xf9\x38\x03\x66"
668 "\x2a\x28\xdf\x1c\xd5\x35\xb7\x31", 64,
669 "KECCAK-512", 1) != 0) {
670 return CRYPT_FAIL_TESTVECTOR;
671 }
672
673 keccak_512_init(&c);
674 keccak_process(&c, (unsigned char*)
675 "\x52\xa6\x08\xab\x21\xcc\xdd\x8a"
676 "\x44\x57\xa5\x7e\xde\x78\x21\x76", 16);
677 keccak_done(&c, hash);
678 if(compare_testvector(hash, 64,
679 "\x4b\x39\xd3\xda\x5b\xcd\xf4\xd9"
680 "\xb7\x69\x01\x59\x95\x64\x43\x11"
681 "\xc1\x4c\x43\x5b\xf7\x2b\x10\x09"
682 "\xd6\xdd\x71\xb0\x1a\x63\xb9\x7c"
683 "\xfb\x59\x64\x18\xe8\xe4\x23\x42"
684 "\xd1\x17\xe0\x74\x71\xa8\x91\x43"
685 "\x14\xba\x7b\x0e\x26\x4d\xad\xf0"
686 "\xce\xa3\x81\x86\x8c\xbd\x43\xd1", 64,
687 "KECCAK-512", 2) != 0) {
688 return CRYPT_FAIL_TESTVECTOR;
689 }
690
691 keccak_512_init(&c);
692 keccak_process(&c, (unsigned char*)
693 "\x43\x3c\x53\x03\x13\x16\x24\xc0"
694 "\x02\x1d\x86\x8a\x30\x82\x54\x75"
695 "\xe8\xd0\xbd\x30\x52\xa0\x22\x18"
696 "\x03\x98\xf4\xca\x44\x23\xb9\x82"
697 "\x14\xb6\xbe\xaa\xc2\x1c\x88\x07"
698 "\xa2\xc3\x3f\x8c\x93\xbd\x42\xb0"
699 "\x92\xcc\x1b\x06\xce\xdf\x32\x24"
700 "\xd5\xed\x1e\xc2\x97\x84\x44\x4f"
701 "\x22\xe0\x8a\x55\xaa\x58\x54\x2b"
702 "\x52\x4b\x02\xcd\x3d\x5d\x5f\x69"
703 "\x07\xaf\xe7\x1c\x5d\x74\x62\x22"
704 "\x4a\x3f\x9d\x9e\x53\xe7\xe0\x84"
705 "\x6d\xcb\xb4\xce", 100);
706 keccak_done(&c, hash);
707 if(compare_testvector(hash, 64,
708 "\x52\x7d\x28\xe3\x41\xe6\xb1\x4f"
709 "\x46\x84\xad\xb4\xb8\x24\xc4\x96"
710 "\xc6\x48\x2e\x51\x14\x95\x65\xd3"
711 "\xd1\x72\x26\x82\x88\x84\x30\x6b"
712 "\x51\xd6\x14\x8a\x72\x62\x2c\x2b"
713 "\x75\xf5\xd3\x51\x0b\x79\x9d\x8b"
714 "\xdc\x03\xea\xed\xe4\x53\x67\x6a"
715 "\x6e\xc8\xfe\x03\xa1\xad\x0e\xab", 64,
716 "KECCAK-512", 3) != 0) {
717 return CRYPT_FAIL_TESTVECTOR;
718 }
719
720 return CRYPT_OK;
721 #endif
722 }
723
724 #endif
725
398726 /* ref: $Format:%D$ */
399727 /* git commit: $Format:%H$ */
400728 /* commit time: $Format:%ai$ */
3232 #define MAXBLOCKSIZE 144
3333
3434 /* descriptor table size */
35 #define TAB_SIZE 32
35 #define TAB_SIZE 34
3636
3737 /* error codes [will be expanded in future releases] */
3838 enum {
247247 #define LTC_CHC_HASH
248248 #define LTC_WHIRLPOOL
249249 #define LTC_SHA3
250 #define LTC_KECCAK
250251 #define LTC_SHA512
251252 #define LTC_SHA512_256
252253 #define LTC_SHA512_224
77 */
88
99 /* ---- HASH FUNCTIONS ---- */
10 #ifdef LTC_SHA3
10 #if defined(LTC_SHA3) || defined(LTC_KECCAK)
1111 struct sha3_state {
1212 ulong64 saved; /* the portion of the input message that we didn't consume yet */
1313 ulong64 s[25];
154154 #ifdef LTC_WHIRLPOOL
155155 struct whirlpool_state whirlpool;
156156 #endif
157 #ifdef LTC_SHA3
157 #if defined(LTC_SHA3) || defined(LTC_KECCAK)
158158 struct sha3_state sha3;
159159 #endif
160160 #ifdef LTC_SHA512
262262 extern const struct ltc_hash_descriptor whirlpool_desc;
263263 #endif
264264
265 #if defined(LTC_SHA3) || defined(LTC_KECCAK)
266 /* sha3_NNN_init are shared by SHA3 and KECCAK */
267 int sha3_512_init(hash_state * md);
268 int sha3_384_init(hash_state * md);
269 int sha3_256_init(hash_state * md);
270 int sha3_224_init(hash_state * md);
271 /* sha3_process is the same for all variants of SHA3 + KECCAK */
272 int sha3_process(hash_state * md, const unsigned char *in, unsigned long inlen);
273 #endif
274
265275 #ifdef LTC_SHA3
266 int sha3_512_init(hash_state * md);
267276 int sha3_512_test(void);
268277 extern const struct ltc_hash_descriptor sha3_512_desc;
269 int sha3_384_init(hash_state * md);
270278 int sha3_384_test(void);
271279 extern const struct ltc_hash_descriptor sha3_384_desc;
272 int sha3_256_init(hash_state * md);
273280 int sha3_256_test(void);
274281 extern const struct ltc_hash_descriptor sha3_256_desc;
275 int sha3_224_init(hash_state * md);
276282 int sha3_224_test(void);
277283 extern const struct ltc_hash_descriptor sha3_224_desc;
278 /* process + done are the same for all variants */
279 int sha3_process(hash_state * md, const unsigned char *in, unsigned long inlen);
280284 int sha3_done(hash_state *md, unsigned char *hash);
281285 /* SHAKE128 + SHAKE256 */
282286 int sha3_shake_init(hash_state *md, int num);
284288 int sha3_shake_done(hash_state *md, unsigned char *out, unsigned long outlen);
285289 int sha3_shake_test(void);
286290 int sha3_shake_memory(int num, const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen);
291 #endif
292
293 #ifdef LTC_KECCAK
294 #define keccak_512_init(a) sha3_512_init(a)
295 #define keccak_384_init(a) sha3_384_init(a)
296 #define keccak_256_init(a) sha3_256_init(a)
297 #define keccak_224_init(a) sha3_224_init(a)
298 #define keccak_process(a,b,c) sha3_process(a,b,c)
299 extern const struct ltc_hash_descriptor keccak_512_desc;
300 int keccak_512_test(void);
301 extern const struct ltc_hash_descriptor keccak_384_desc;
302 int keccak_384_test(void);
303 extern const struct ltc_hash_descriptor keccak_256_desc;
304 int keccak_256_test(void);
305 extern const struct ltc_hash_descriptor keccak_224_desc;
306 int keccak_224_test(void);
307 int keccak_done(hash_state *md, unsigned char *hash);
287308 #endif
288309
289310 #ifdef LTC_SHA512
151151 #if defined(LTC_SHA3)
152152 " SHA3\n"
153153 #endif
154 #if defined(LTC_KECCAK)
155 " KECCAK\n"
156 #endif
154157 #if defined(LTC_SHA512)
155158 " SHA-512\n"
156159 #endif
5959 REGISTER_HASH(&sha3_384_desc);
6060 REGISTER_HASH(&sha3_512_desc);
6161 #endif
62 #ifdef LTC_KECCAK
63 REGISTER_HASH(&keccak_224_desc);
64 REGISTER_HASH(&keccak_256_desc);
65 REGISTER_HASH(&keccak_384_desc);
66 REGISTER_HASH(&keccak_512_desc);
67 #endif
6268 #ifdef LTC_RIPEMD128
6369 REGISTER_HASH(&rmd128_desc);
6470 #endif
2929 LTC_ARGCHK(outlen != NULL);
3030
3131 if (id->type != LTC_ASN1_CUSTOM_TYPE) {
32 if (id->type >= der_asn1_type_to_identifier_map_sz) {
32 if ((unsigned)id->type >= der_asn1_type_to_identifier_map_sz) {
3333 return CRYPT_INVALID_ARG;
3434 }
3535 if (der_asn1_type_to_identifier_map[id->type] == -1) {