comparison src/ciphers/khazad.c @ 380:d5faf4814ddb libtomcrypt-orig libtomcrypt-1.16

Update to LibTomCrypt 1.16
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:22:00 +0000
parents 59400faa4b44
children
comparison
equal deleted inserted replaced
280:59400faa4b44 380:d5faf4814ddb
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 * 8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org 9 * Tom St Denis, [email protected], http://libtomcrypt.com
10 */ 10 */
11 #include "tomcrypt.h" 11 #include "tomcrypt.h"
12 12
13 /** 13 /**
14 @file khazad.c 14 @file khazad.c
26 &khazad_ecb_encrypt, 26 &khazad_ecb_encrypt,
27 &khazad_ecb_decrypt, 27 &khazad_ecb_decrypt,
28 &khazad_test, 28 &khazad_test,
29 &khazad_done, 29 &khazad_done,
30 &khazad_keysize, 30 &khazad_keysize,
31 NULL, NULL, NULL, NULL, NULL, NULL, NULL 31 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
32 }; 32 };
33 33
34 #define R 8 34 #define R 8
35 #define KEYSIZE 128 35 #define KEYSIZE 128
36 #define KEYSIZEB (KEYSIZE/8) 36 #define KEYSIZEB (KEYSIZE/8)
739 /** 739 /**
740 Encrypts a block of text with Khazad 740 Encrypts a block of text with Khazad
741 @param pt The input plaintext (8 bytes) 741 @param pt The input plaintext (8 bytes)
742 @param ct The output ciphertext (8 bytes) 742 @param ct The output ciphertext (8 bytes)
743 @param skey The key as scheduled 743 @param skey The key as scheduled
744 @return CRYPT_OK if successful
744 */ 745 */
745 void khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) 746 int khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
746 { 747 {
747 LTC_ARGCHK(pt != NULL); 748 LTC_ARGCHK(pt != NULL);
748 LTC_ARGCHK(ct != NULL); 749 LTC_ARGCHK(ct != NULL);
749 LTC_ARGCHK(skey != NULL); 750 LTC_ARGCHK(skey != NULL);
750 khazad_crypt(pt, ct, skey->khazad.roundKeyEnc); 751 khazad_crypt(pt, ct, skey->khazad.roundKeyEnc);
752 return CRYPT_OK;
751 } 753 }
752 754
753 /** 755 /**
754 Decrypts a block of text with Khazad 756 Decrypts a block of text with Khazad
755 @param ct The input ciphertext (8 bytes) 757 @param ct The input ciphertext (8 bytes)
756 @param pt The output plaintext (8 bytes) 758 @param pt The output plaintext (8 bytes)
757 @param skey The key as scheduled 759 @param skey The key as scheduled
760 @return CRYPT_OK if successful
758 */ 761 */
759 void khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) 762 int khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
760 { 763 {
761 LTC_ARGCHK(pt != NULL); 764 LTC_ARGCHK(pt != NULL);
762 LTC_ARGCHK(ct != NULL); 765 LTC_ARGCHK(ct != NULL);
763 LTC_ARGCHK(skey != NULL); 766 LTC_ARGCHK(skey != NULL);
764 khazad_crypt(ct, pt, skey->khazad.roundKeyDec); 767 khazad_crypt(ct, pt, skey->khazad.roundKeyDec);
768 return CRYPT_OK;
765 } 769 }
766 770
767 /** 771 /**
768 Performs a self-test of the Khazad block cipher 772 Performs a self-test of the Khazad block cipher
769 @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled 773 @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
804 808
805 for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { 809 for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
806 khazad_setup(tests[x].key, 16, 0, &skey); 810 khazad_setup(tests[x].key, 16, 0, &skey);
807 khazad_ecb_encrypt(tests[x].pt, buf[0], &skey); 811 khazad_ecb_encrypt(tests[x].pt, buf[0], &skey);
808 khazad_ecb_decrypt(buf[0], buf[1], &skey); 812 khazad_ecb_decrypt(buf[0], buf[1], &skey);
809 if (memcmp(buf[0], tests[x].ct, 8) || memcmp(buf[1], tests[x].pt, 8)) { 813 if (XMEMCMP(buf[0], tests[x].ct, 8) || XMEMCMP(buf[1], tests[x].pt, 8)) {
810 return CRYPT_FAIL_TESTVECTOR; 814 return CRYPT_FAIL_TESTVECTOR;
811 } 815 }
812 816
813 for (y = 0; y < 1000; y++) khazad_ecb_encrypt(buf[0], buf[0], &skey); 817 for (y = 0; y < 1000; y++) khazad_ecb_encrypt(buf[0], buf[0], &skey);
814 for (y = 0; y < 1000; y++) khazad_ecb_decrypt(buf[0], buf[0], &skey); 818 for (y = 0; y < 1000; y++) khazad_ecb_decrypt(buf[0], buf[0], &skey);
815 if (memcmp(buf[0], tests[x].ct, 8)) { 819 if (XMEMCMP(buf[0], tests[x].ct, 8)) {
816 return CRYPT_FAIL_TESTVECTOR; 820 return CRYPT_FAIL_TESTVECTOR;
817 } 821 }
818 822
819 } 823 }
820 return CRYPT_OK; 824 return CRYPT_OK;
845 } 849 }
846 850
847 #endif 851 #endif
848 852
849 /* $Source: /cvs/libtom/libtomcrypt/src/ciphers/khazad.c,v $ */ 853 /* $Source: /cvs/libtom/libtomcrypt/src/ciphers/khazad.c,v $ */
850 /* $Revision: 1.7 $ */ 854 /* $Revision: 1.12 $ */
851 /* $Date: 2005/05/05 14:35:58 $ */ 855 /* $Date: 2006/11/08 23:01:06 $ */