Mercurial > dropbear
comparison libtomcrypt/demos/tv_gen.c @ 415:8b9aba1d5fa4 channel-fix
merge of '73fe066c5d9e2395354ba74756124d45c978a04d'
and 'f5014cc84558f1e8eba42dbecf9f72f94bfe6134'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 06 Feb 2007 16:00:18 +0000 |
parents | 0cbe8f6dbf9e |
children | f849a5ca2efc |
comparison
equal
deleted
inserted
replaced
414:c53a26c430e5 | 415:8b9aba1d5fa4 |
---|---|
95 if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) { | 95 if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) { |
96 printf("chc_register error: %s\n", error_to_string(err)); | 96 printf("chc_register error: %s\n", error_to_string(err)); |
97 exit(EXIT_FAILURE); | 97 exit(EXIT_FAILURE); |
98 } | 98 } |
99 #endif | 99 #endif |
100 | |
101 #ifdef USE_LTM | |
102 ltc_mp = ltm_desc; | |
103 #elif defined(USE_TFM) | |
104 ltc_mp = tfm_desc; | |
105 #elif defined(USE_GMP) | |
106 ltc_mp = gmp_desc; | |
107 #else | |
108 extern ltc_math_descriptor EXT_MATH_LIB; | |
109 ltc_mp = EXT_MATH_LIB; | |
110 #endif | |
111 | |
100 | 112 |
101 } | 113 } |
102 | 114 |
103 void hash_gen(void) | 115 void hash_gen(void) |
104 { | 116 { |
539 for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){ | 551 for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){ |
540 for (z = 0; z < y1; z++) { | 552 for (z = 0; z < y1; z++) { |
541 plaintext[z] = (unsigned char)(z & 255); | 553 plaintext[z] = (unsigned char)(z & 255); |
542 } | 554 } |
543 len = sizeof(tag); | 555 len = sizeof(tag); |
544 if ((err = ccm_memory(x, key, kl, nonce, 13, plaintext, y1, plaintext, y1, plaintext, tag, &len, CCM_ENCRYPT)) != CRYPT_OK) { | 556 if ((err = ccm_memory(x, key, kl, NULL, nonce, 13, plaintext, y1, plaintext, y1, plaintext, tag, &len, CCM_ENCRYPT)) != CRYPT_OK) { |
545 printf("Error CCM'ing: %s\n", error_to_string(err)); | 557 printf("Error CCM'ing: %s\n", error_to_string(err)); |
546 exit(EXIT_FAILURE); | 558 exit(EXIT_FAILURE); |
547 } | 559 } |
548 fprintf(out, "%3d: ", y1); | 560 fprintf(out, "%3d: ", y1); |
549 for (z = 0; z < y1; z++) { | 561 for (z = 0; z < y1; z++) { |
639 fprintf(out, "%2lu: %s\n", x, dst); | 651 fprintf(out, "%2lu: %s\n", x, dst); |
640 } | 652 } |
641 fclose(out); | 653 fclose(out); |
642 } | 654 } |
643 | 655 |
656 void math_gen(void) | |
657 { | |
658 } | |
659 | |
660 void ecc_gen(void) | |
661 { | |
662 FILE *out; | |
663 unsigned char str[512]; | |
664 void *k, *order, *modulus; | |
665 ecc_point *G, *R; | |
666 int x; | |
667 | |
668 out = fopen("ecc_tv.txt", "w"); | |
669 fprintf(out, "ecc vectors. These are for kG for k=1,3,9,27,...,3**n until k > order of the curve outputs are <k,x,y> triplets\n\n"); | |
670 G = ltc_ecc_new_point(); | |
671 R = ltc_ecc_new_point(); | |
672 mp_init(&k); | |
673 mp_init(&order); | |
674 mp_init(&modulus); | |
675 | |
676 for (x = 0; ltc_ecc_sets[x].size != 0; x++) { | |
677 fprintf(out, "ECC-%d\n", ltc_ecc_sets[x].size*8); | |
678 mp_set(k, 1); | |
679 | |
680 mp_read_radix(order, (char *)ltc_ecc_sets[x].order, 16); | |
681 mp_read_radix(modulus, (char *)ltc_ecc_sets[x].prime, 16); | |
682 mp_read_radix(G->x, (char *)ltc_ecc_sets[x].Gx, 16); | |
683 mp_read_radix(G->y, (char *)ltc_ecc_sets[x].Gy, 16); | |
684 mp_set(G->z, 1); | |
685 | |
686 while (mp_cmp(k, order) == LTC_MP_LT) { | |
687 ltc_mp.ecc_ptmul(k, G, R, modulus, 1); | |
688 mp_tohex(k, (char*)str); fprintf(out, "%s, ", (char*)str); | |
689 mp_tohex(R->x, (char*)str); fprintf(out, "%s, ", (char*)str); | |
690 mp_tohex(R->y, (char*)str); fprintf(out, "%s\n", (char*)str); | |
691 mp_mul_d(k, 3, k); | |
692 } | |
693 } | |
694 mp_clear_multi(k, order, modulus, NULL); | |
695 ltc_ecc_del_point(G); | |
696 ltc_ecc_del_point(R); | |
697 fclose(out); | |
698 } | |
699 | |
700 void lrw_gen(void) | |
701 { | |
702 FILE *out; | |
703 unsigned char tweak[16], key[16], iv[16], buf[1024]; | |
704 int x, y, err; | |
705 symmetric_LRW lrw; | |
706 | |
707 /* initialize default key and tweak */ | |
708 for (x = 0; x < 16; x++) { | |
709 tweak[x] = key[x] = iv[x] = x; | |
710 } | |
711 | |
712 out = fopen("lrw_tv.txt", "w"); | |
713 for (x = 16; x < (int)(sizeof(buf)); x += 16) { | |
714 if ((err = lrw_start(find_cipher("aes"), iv, key, 16, tweak, 0, &lrw)) != CRYPT_OK) { | |
715 fprintf(stderr, "Error starting LRW-AES: %s\n", error_to_string(err)); | |
716 exit(EXIT_FAILURE); | |
717 } | |
718 | |
719 /* encrypt incremental */ | |
720 for (y = 0; y < x; y++) { | |
721 buf[y] = y & 255; | |
722 } | |
723 | |
724 if ((err = lrw_encrypt(buf, buf, x, &lrw)) != CRYPT_OK) { | |
725 fprintf(stderr, "Error encrypting with LRW-AES: %s\n", error_to_string(err)); | |
726 exit(EXIT_FAILURE); | |
727 } | |
728 | |
729 /* display it */ | |
730 fprintf(out, "%d:", x); | |
731 for (y = 0; y < x; y++) { | |
732 fprintf(out, "%02x", buf[y]); | |
733 } | |
734 fprintf(out, "\n"); | |
735 | |
736 /* reset IV */ | |
737 if ((err = lrw_setiv(iv, 16, &lrw)) != CRYPT_OK) { | |
738 fprintf(stderr, "Error setting IV: %s\n", error_to_string(err)); | |
739 exit(EXIT_FAILURE); | |
740 } | |
741 | |
742 /* copy new tweak, iv and key */ | |
743 for (y = 0; y < 16; y++) { | |
744 key[y] = buf[y]; | |
745 iv[y] = buf[(y+16)%x]; | |
746 tweak[y] = buf[(y+32)%x]; | |
747 } | |
748 | |
749 if ((err = lrw_decrypt(buf, buf, x, &lrw)) != CRYPT_OK) { | |
750 fprintf(stderr, "Error decrypting with LRW-AES: %s\n", error_to_string(err)); | |
751 exit(EXIT_FAILURE); | |
752 } | |
753 | |
754 /* display it */ | |
755 fprintf(out, "%d:", x); | |
756 for (y = 0; y < x; y++) { | |
757 fprintf(out, "%02x", buf[y]); | |
758 } | |
759 fprintf(out, "\n"); | |
760 lrw_done(&lrw); | |
761 } | |
762 fclose(out); | |
763 } | |
764 | |
644 int main(void) | 765 int main(void) |
645 { | 766 { |
646 reg_algs(); | 767 reg_algs(); |
647 printf("Generating hash vectors..."); fflush(stdout); hash_gen(); printf("done\n"); | 768 printf("Generating hash vectors..."); fflush(stdout); hash_gen(); printf("done\n"); |
648 printf("Generating cipher vectors..."); fflush(stdout); cipher_gen(); printf("done\n"); | 769 printf("Generating cipher vectors..."); fflush(stdout); cipher_gen(); printf("done\n"); |
649 printf("Generating HMAC vectors..."); fflush(stdout); hmac_gen(); printf("done\n"); | 770 printf("Generating HMAC vectors..."); fflush(stdout); hmac_gen(); printf("done\n"); |
650 printf("Generating OMAC vectors..."); fflush(stdout); omac_gen(); printf("done\n"); | 771 printf("Generating OMAC vectors..."); fflush(stdout); omac_gen(); printf("done\n"); |
651 printf("Generating PMAC vectors..."); fflush(stdout); pmac_gen(); printf("done\n"); | 772 printf("Generating PMAC vectors..."); fflush(stdout); pmac_gen(); printf("done\n"); |
652 printf("Generating EAX vectors..."); fflush(stdout); eax_gen(); printf("done\n"); | 773 printf("Generating EAX vectors..."); fflush(stdout); eax_gen(); printf("done\n"); |
653 printf("Generating OCB vectors..."); fflush(stdout); ocb_gen(); printf("done\n"); | 774 printf("Generating OCB vectors..."); fflush(stdout); ocb_gen(); printf("done\n"); |
654 printf("Generating CCM vectors..."); fflush(stdout); ccm_gen(); printf("done\n"); | 775 printf("Generating CCM vectors..."); fflush(stdout); ccm_gen(); printf("done\n"); |
655 printf("Generating GCM vectors..."); fflush(stdout); gcm_gen(); printf("done\n"); | 776 printf("Generating GCM vectors..."); fflush(stdout); gcm_gen(); printf("done\n"); |
656 printf("Generating BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n"); | 777 printf("Generating BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n"); |
778 printf("Generating MATH vectors..."); fflush(stdout); math_gen(); printf("done\n"); | |
779 printf("Generating ECC vectors..."); fflush(stdout); ecc_gen(); printf("done\n"); | |
780 printf("Generating LRW vectors..."); fflush(stdout); lrw_gen(); printf("done\n"); | |
657 return 0; | 781 return 0; |
658 } | 782 } |
659 | 783 |
660 | |
661 | |
662 | |
663 | |
664 | |
665 | |
666 | |
667 | |
668 /* $Source: /cvs/libtom/libtomcrypt/demos/tv_gen.c,v $ */ | 784 /* $Source: /cvs/libtom/libtomcrypt/demos/tv_gen.c,v $ */ |
669 /* $Revision: 1.4 $ */ | 785 /* $Revision: 1.15 $ */ |
670 /* $Date: 2005/05/05 14:35:56 $ */ | 786 /* $Date: 2006/06/09 22:10:27 $ */ |