浏览代码

Merge branch 'fix/xtea' into develop

Steffen Jaeckel 12 年之前
父节点
当前提交
9cb6c6b910

+ 24 - 3
demos/encrypt.c

@@ -15,7 +15,9 @@ int usage(char *name)
 {
    int x;
 
-   printf("Usage: %s [-d](ecrypt) cipher infile outfile\nCiphers:\n", name);
+   printf("Usage encrypt: %s cipher infile outfile\n", name);
+   printf("Usage decrypt: %s -d cipher infile outfile\n", name);
+   printf("Usage test:    %s -t cipher\nCiphers:\n", name);
    for (x = 0; cipher_descriptor[x].name != NULL; x++) {
       printf("%s\n",cipher_descriptor[x].name);
    }
@@ -24,8 +26,6 @@ int usage(char *name)
 
 void register_algs(void)
 {
-   int x;
-
 #ifdef LTC_RIJNDAEL
   register_cipher (&aes_desc);
 #endif
@@ -108,6 +108,27 @@ int main(int argc, char *argv[])
    register_algs();
 
    if (argc < 4) {
+      if ((argc > 2) && (!strcmp(argv[1], "-t"))) {
+        cipher  = argv[2];
+        cipher_idx = find_cipher(cipher);
+        if (cipher_idx == -1) {
+          printf("Invalid cipher %s entered on command line.\n", cipher);
+          exit(-1);
+        } /* if */
+        if (cipher_descriptor[cipher_idx].test)
+        {
+          if (cipher_descriptor[cipher_idx].test() != CRYPT_OK)
+          {
+            printf("Error when testing cipher %s.\n", cipher);
+            exit(-1);
+          }
+          else
+          {
+            printf("Testing cipher %s succeeded.\n", cipher);
+            exit(0);
+          } /* if ... else */
+        } /* if */
+      }
       return usage(argv[0]);
    }
 

+ 50 - 50
notes/cipher_tv.txt

@@ -321,56 +321,56 @@ Key Size: 56 bytes
 
 Cipher: xtea
 Key Size: 16 bytes
- 0: 256004E1F55BC0C7
- 1: 2D385C151A691C42
- 2: F93BFEA758A7DDB4
- 3: 2A905D97C0CA3E48
- 4: 12C7C2787B913AE6
- 5: FB24B1F32549EF59
- 6: 2A8BFF867FB4FF73
- 7: 5692243526C6BA77
- 8: 4CD423ADFCDD1B6C
- 9: 9B99AFC35EB2FED0
-10: 416B4AA4E07DA7F4
-11: 4DBC9052ABFF9510
-12: 8AF9457F8E599216
-13: BC3CA2B1C7267395
-14: E4BE31DF42282F7A
-15: B344CA8AA57E9E40
-16: 57A1F94CD2F4576D
-17: 96177FCD28BFF1BB
-18: 78A1F63A0EBAAC33
-19: 5F3FCBCD7442B617
-20: D6F7CD5ECA688967
-21: D92EDF70CBDE703F
-22: E2E2C2EE5D18E58E
-23: 4BF00478CB7833C3
-24: F9936D550815FE8F
-25: 19A3B07B3E47D7D8
-26: ACA441F099A7E30C
-27: F70183F199988E3F
-28: 0A41FC22F369310A
-29: ABFAF40853A4A38C
-30: 6B5D29DB1155D96B
-31: 0DD0C08A27561D66
-32: 4C56E22292F17AA3
-33: 3F925ED65613DF4A
-34: 521B4C97081DC901
-35: 2B1EC3E1C8CF84EC
-36: 2A412556F42A48F6
-37: 0A57B8A527DFE507
-38: EB55C9C157E3C922
-39: 6E6D6E9AB925ED92
-40: A4C5C90A0D4A8F16
-41: 7F9F9F658C427D55
-42: 9A5139994FF04C3F
-43: 9054771F027E29BC
-44: 90543E7BAED313BD
-45: 5DEC1EBE6A617D36
-46: 19AB6A708CDB9B2D
-47: BABB97BB5CF9D4E4
-48: 2C2ADC05AF255861
-49: 52266710153E3F7E
+ 0: FFC52D10A010010B
+ 1: 9CFB2B659387BC37
+ 2: 7067D153B259E0D6
+ 3: 0A1769C085DD67A9
+ 4: A9D781A1A7B4B292
+ 5: 6FEF8300DF395062
+ 6: A67B66CA99B9121C
+ 7: 006E657E1DAD46D3
+ 8: 2D63322467438A5B
+ 9: 4F67A826126BE01D
+10: 852C6FD597EBAB00
+11: F8DD14F59FF44A20
+12: CD4DC4E92B5CD40B
+13: 802B89A3EFB75810
+14: CCA7D920F69A5491
+15: 0DFF98CA4F71CA0E
+16: 80118F2AE4E83DE8
+17: CD6935285D45D83C
+18: 47B4613483889187
+19: 87F3F1975B8618E3
+20: 49BF15EF40C72DBA
+21: F850822AD58AD1CC
+22: 9701AD2EF51FD705
+23: 705AE7F6FD60420B
+24: E885CC84A9866B28
+25: 93E0D712D27E4E22
+26: 8C9CE43E517D3324
+27: 31004841AF51FB0E
+28: B250BEBF0E58457C
+29: 78290B6D83D442E9
+30: 3EC72388709CC6E2
+31: 099FB875AB5CA6EA
+32: B15E20B58F5E8DD0
+33: A41511E198E0B1E7
+34: B8B5CDD9607B6B40
+35: BEF9624E922DB8AC
+36: AF198FCD314D8DD4
+37: 1A37E433C261EF9D
+38: AB7895A2E9D41EE4
+39: 4C95BE8D34A7D75B
+40: 0D90A8EB03F2852E
+41: 9AAD1D630D835C67
+42: 6AD88003661B2C5E
+43: 4FA7E2CC53EBA728
+44: 862245D794441522
+45: FAB262C13D245B3E
+46: C0A29AA315A5721E
+47: F98617BBEFA6AD6A
+48: 6F84EAB462F10F36
+49: 30850051303CDB96
 
 
 Cipher: rc5

+ 17 - 17
notes/eax_tv.txt

@@ -57,23 +57,23 @@ EAX-blowfish (8 byte key)
  16: 60A315193F58144F5701D547C79FEEED, 912FDBDB05467DF5
 
 EAX-xtea (16 byte key)
-  0: , 86881D824E3BC561
-  1: EE, 4C3505F04611D9C2
-  2: 80C8, 6A3428BEEAD60738
-  3: BF88E7, 04F1E99E9F5906C2
-  4: E06574B7, 33B0153AAEF9776F
-  5: 42D950AF63, 4A0F415640322FDF
-  6: C30F6AD46EC9, 9646FE909D2B95CB
-  7: A0049FCA856A14, A0257289C6BBF278
-  8: 2814B0C1358440E0, C4B0A2354925E887
-  9: BF4F062B52C1E489CF, B56442A3CA57A041
- 10: 63DF433956831B8780FC, ADF9ED0B46DCA19E
- 11: C317FD079817F50E0E8A16, 2EA0EC993FC603AE
- 12: 2BD12FDDD81EB11660346D2A, FBC6F69125BBA88D
- 13: 85D356536FE2843C6BBE60EDBC, BB2FEFD04F230E79
- 14: 22493009DB01B4746F4927A8C4FB, 64CC08471D93C9AC
- 15: C0F3C0DB08DC93FBA725D1E02DE084, 77B762213DDCCFFE
- 16: 568B66D3112556BD98FF9339E9C002E5, C8355F508219FE0C
+  0: , A04FAC8D0416F081
+  1: 5E, F95DAA99F8FE28E9
+  2: B6A7, E2A05E1F1E6D17B5
+  3: 27D698, CCC0CC54F40DA243
+  4: C2E81CCC, 283AB8F109D287ED
+  5: 51B99DF694, A9637DB356B4BC0C
+  6: C2ED3E79A4F2, 413D3A65FFE803BA
+  7: 40E35BE6CA019C, 1B68833B90E4E026
+  8: C246C2B5ACEBEB08, 50CFEB01DEC3BB1F
+  9: 35E2F7AAB57842D50F, 617804483BFFCA9D
+ 10: 2F855AB7A4664958300D, 6F054767FE484664
+ 11: 2824A5486D1B621D0F992A, 238566B9F56ECAB1
+ 12: BF5C121A6144AA0CC05A380E, 63F4DA4B898FB2A8
+ 13: 2EB53E8A4698EDEBB990FC65E6, 7DFFE0E43187D10C
+ 14: 85F77FD150C6649F5826AD45D50D, AA660F37975768FC
+ 15: 8B4EB3750814EE7E8FC6B97B3ED1ED, F79545FB1F1C389B
+ 16: 980EB7FCEEE37558BEDA0E938325F608, 2FAA9235BFA3EA30
 
 EAX-rc5 (8 byte key)
   0: , 169C7954341EF44D

+ 17 - 17
notes/ocb3_tv.txt

@@ -57,23 +57,23 @@ OCB-blowfish (8 byte key)
  16: 1F4919EB6CAD8D19B755157FD1A2E89A, F7EAE8DB5F5FA9B1
 
 OCB-xtea (16 byte key)
-  0: , 311A7010FB045BEE
-  1: F8, E65BD38F1C4E7BFF
-  2: 7AE4, 5B78197CE29D8FD4
-  3: 36A39F, 98FEA390BC03F915
-  4: 9AE3921C, 76F6EEBC194DEFE4
-  5: E925968C09, 105E0FBF3B664875
-  6: 537DE3B6AADF, B2C57709CEDBBA10
-  7: 4525D6927B4343, D83CB96C7ADA6241
-  8: 807A0E8382A91CE9, F6DF1EAA4929EEEE
-  9: 59C09E427C56CDF015, 885813D7F4D4CB40
- 10: F785DAB910D186761A82, 46346AB52983186D
- 11: F11CE4DAAEBCC204B318F2, 67E95CA14FB4FD3D
- 12: 4A7FD586015561801115981F, 70DAC17D50DB4E5C
- 13: CF03722B78DE7AE951B5E6442A, F40D80E40690378E
- 14: B17224FE335A8CC17425D0AA3382, 2BEEC3D3828EA9E8
- 15: 5B333EE0CC163F8C22E5E0747AE7F6, 29BCD90905505D05
- 16: 7FC2C0D4E865D082174AE033E71DD3A9, E34E60A7D43F8EDB
+  0: , 5F751041CDB0C2B5
+  1: A5, C48C22CADB797CF7
+  2: A3E9, CBB821F70FBAEA3A
+  3: 7CA3C5, 686647FF8466C56A
+  4: 318C2DA8, 65C58584A3E9118A
+  5: A7C02B6438, F87A48C547971C30
+  6: 314FBFEE9BDE, E62DC6E65FD35E8B
+  7: 87481270584EB8, C582AC684B8D02A0
+  8: 1E5E0DD030860CBC, A19FF0144005994E
+  9: F0BDCCA3C2463850A5, 15420E4C10821445
+ 10: B6D1C598C7046F921299, EE9C28659EE2927E
+ 11: B1376A4D9B3EF59B873917, 0DD3005E47CE72DB
+ 12: BC9D026F374A89B8A45E55D0, 09DA1DDFDC3A5463
+ 13: CC8DF93BE2D71601CDC52124A7, 9623D92C2FD9D62C
+ 14: 90854B2161951CEA934AAB4E2B6C, E80632AB9F2CE421
+ 15: 7ADE7A19FD0BAF71BE1C6DA601F6D3, 90612EEA15A64111
+ 16: FA21FE68977D60D51ED897915945E5C4, 1A9344DD8E25D45C
 
 OCB-rc5 (8 byte key)
   0: , 4287F61BB46382B2

+ 17 - 17
notes/ocb_tv.txt

@@ -57,23 +57,23 @@ OCB-blowfish (8 byte key)
  16: 3EDC4A0FA95BD8F944BCE4F252B6470C, 87B54BBEA86A5B5C
 
 OCB-xtea (16 byte key)
-  0: , 56722ECFE6ED1300
-  1: CA, DF53479333DB86AA
-  2: 9529, D0B5A859106FCC9B
-  3: DDBAB2, 3B31FFDA57CF51C8
-  4: 22EB7DD4, 2BB34D04FFF810CB
-  5: 108693761A, 7AFF6F52574A019A
-  6: 391FB7C61E76, 616C5E66297F2CCE
-  7: 3E22E4A4A0BD13, E84C385ABE25C8D8
-  8: 94FA11D5243EE34F, 8F017DE96049D0F9
-  9: DADB6B5D27049240A7, CA69E14047C6BBA7
- 10: F79C8EA83C69DE914DAC, 1EF042DA68106C64
- 11: C5B6E04AB8B9491E6A99F8, 143515779A55C972
- 12: 33F493AB7AE62DADA38C5B24, 531BF7799A778620
- 13: 6DAA66BF02E66DF8C0B6C1CC24, 6CDF72786C5EC761
- 14: 4940E22F083A0F3EC01B3D468928, 185EE9CD2D7521AB
- 15: 5D100BF55708147A9537C7DB6E42A6, 78984C682124E904
- 16: 744033532DDB372BA4AFADEA1959251E, 438EB9F6B939844C
+  0: , F996E5CC593FD6E9
+  1: 88, 64636E3C48940F8D
+  2: 223D, 230D7718A8BCB965
+  3: 32531B, 37FEA4728FAE474D
+  4: BDCF3E96, A9F30B4187CD174C
+  5: 7B0CCDE546, E7328648817987FE
+  6: 824BD771B724, 0BDF80C14EDB758B
+  7: 8F0E73B1280717, 2DEDBF2C87180CC4
+  8: 6F7EFA44AF774B1F, 1A9C5509D54A7185
+  9: 9749BCF684F68755AC, E46941DBE948BDD5
+ 10: DCD32D91FE2D5590355D, E17DFA54A5B60E07
+ 11: 3CBBF6464D438AB95B3ACF, C207876D030362EC
+ 12: 1C804A611F6CE4CFD2657366, B957F48EA00C428C
+ 13: 5A2F6927951D8F60C754893790, EB3A27A9E5B8928F
+ 14: C710D28CD02726002596D9196021, C6C9EBF090A20C07
+ 15: 298FFCE0CD42BC329697AEB5F53A56, BB2F0C415317928C
+ 16: 59F6395260ECEAB2E3511991EEEF9656, 278A218A720F8E05
 
 OCB-rc5 (8 byte key)
   0: , E7462C3C0C95A73E

+ 17 - 17
notes/omac_tv.txt

@@ -57,23 +57,23 @@ OMAC-blowfish (8 byte key)
  16: 8E6831D5370678EF
 
 OMAC-xtea (16 byte key)
-  0: 4A0B6160602E6C69
-  1: 1B797D5E14237F21
-  2: 938300C83B99D0AC
-  3: F989B99B3DE563C6
-  4: F65DEA2A6AD45D1E
-  5: 1DB329F0239E162E
-  6: C0C148C4EE8B4E1F
-  7: D82B387D5DFFE1FB
-  8: 1D027A4493898DF2
-  9: 196369F6B0AF971A
- 10: 2A37A2655191D10A
- 11: BD514BE32718EB4A
- 12: B4DBC978F8EE74ED
- 13: 8ACCAD35C3D436AE
- 14: 73ABDC1956630C9B
- 15: 73410D3D169373CE
- 16: 23D797B3C7919374
+  0: A821403929958A1A
+  1: 68C4A02D47C2E7C0
+  2: 7D37358141506DC1
+  3: 9BEA3AAE55B75F52
+  4: 884D053D05CC8DE4
+  5: E953747483FF4E0D
+  6: B6E77E72C9738E4F
+  7: 8AB67D2B24E3D512
+  8: 329C0B9D504A0D41
+  9: 50323DA8ACEF4164
+ 10: FA3239C668C34DA3
+ 11: B5A12FC81FC24084
+ 12: 71A01A3ED3936934
+ 13: F29B630CEB6AEDDB
+ 14: F8802F0D4504D55E
+ 15: F844B92162038F99
+ 16: 99AECD7CA69F0465
 
 OMAC-rc5 (8 byte key)
   0: E374E40562C3CB23

+ 17 - 17
notes/pmac_tv.txt

@@ -57,23 +57,23 @@ PMAC-blowfish (8 byte key)
  16: BDFE0C7F0254BAD5
 
 PMAC-xtea (16 byte key)
-  0: A7EF6BB667216DDA
-  1: B039E53812C4ABDC
-  2: 87D2F8EA5FB6864D
-  3: F85E3F4C1D9F5EFC
-  4: 4EB749D982FB5FE2
-  5: 0BFA0F172027441A
-  6: FF82D01F36A6EC91
-  7: 3BC2AA2028EBBD7A
-  8: 15AA03A97A971E2A
-  9: C974691F5D66B835
- 10: 4FC7AA8F399A79ED
- 11: 2633DA9E94673BAE
- 12: 82A9FD48C5B60902
- 13: 31BF6DA9EE0CE7E4
- 14: 26B2538601B7620E
- 15: D103F3C0B4579BE5
- 16: 031346BA20CD87BC
+  0: F5E28630DFDE34E0
+  1: FFCC52D905DA5198
+  2: 25198AB18B2B290D
+  3: 18914E50791161E9
+  4: 200F832212AD6747
+  5: A9D09C41D734DDF7
+  6: 32D7CCA3F4BD8215
+  7: 91A1AA9389CD5D02
+  8: 35CB1F77D7C25E2F
+  9: D91EEE6D0A3874F3
+ 10: A42872686A8FF6F2
+ 11: 7568908634A79CBD
+ 12: 5B91A633D919BC34
+ 13: 32DCD17176896F1D
+ 14: 2BBBA64F30E672B6
+ 15: AFEB07DBC636AEED
+ 16: 7A417347CA03C598
 
 PMAC-rc5 (8 byte key)
   0: C6B48F8DEC631F7C

+ 105 - 39
src/ciphers/xtea.c

@@ -34,7 +34,7 @@ const struct ltc_cipher_descriptor xtea_desc =
 int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
    unsigned long x, sum, K[4];
-   
+
    LTC_ARGCHK(key != NULL);
    LTC_ARGCHK(skey != NULL);
 
@@ -48,21 +48,21 @@ int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_k
    }
 
    /* load key */
-   LOAD32L(K[0], key+0);
-   LOAD32L(K[1], key+4);
-   LOAD32L(K[2], key+8);
-   LOAD32L(K[3], key+12);
-   
+   LOAD32H(K[0], key+0);
+   LOAD32H(K[1], key+4);
+   LOAD32H(K[2], key+8);
+   LOAD32H(K[3], key+12);
+
    for (x = sum = 0; x < 32; x++) {
        skey->xtea.A[x] = (sum + K[sum&3]) & 0xFFFFFFFFUL;
        sum = (sum + 0x9E3779B9UL) & 0xFFFFFFFFUL;
        skey->xtea.B[x] = (sum + K[(sum>>11)&3]) & 0xFFFFFFFFUL;
    }
-   
+
 #ifdef LTC_CLEAN_STACK
    zeromem(&K, sizeof(K));
-#endif   
-   
+#endif
+
    return CRYPT_OK;
 }
 
@@ -82,8 +82,8 @@ int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *
    LTC_ARGCHK(ct   != NULL);
    LTC_ARGCHK(skey != NULL);
 
-   LOAD32L(y, &pt[0]);
-   LOAD32L(z, &pt[4]);
+   LOAD32H(y, &pt[0]);
+   LOAD32H(z, &pt[4]);
    for (r = 0; r < 32; r += 4) {
        y = (y + ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r])) & 0xFFFFFFFFUL;
        z = (z + ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r])) & 0xFFFFFFFFUL;
@@ -97,8 +97,8 @@ int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *
        y = (y + ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r+3])) & 0xFFFFFFFFUL;
        z = (z + ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r+3])) & 0xFFFFFFFFUL;
    }
-   STORE32L(y, &ct[0]);
-   STORE32L(z, &ct[4]);
+   STORE32H(y, &ct[0]);
+   STORE32H(z, &ct[4]);
    return CRYPT_OK;
 }
 
@@ -106,7 +106,7 @@ int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *
   Decrypts a block of text with LTC_XTEA
   @param ct The input ciphertext (8 bytes)
   @param pt The output plaintext (8 bytes)
-  @param skey The key as scheduled 
+  @param skey The key as scheduled
   @return CRYPT_OK if successful
 */
 int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
@@ -118,8 +118,8 @@ int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *
    LTC_ARGCHK(ct   != NULL);
    LTC_ARGCHK(skey != NULL);
 
-   LOAD32L(y, &ct[0]);
-   LOAD32L(z, &ct[4]);
+   LOAD32H(y, &ct[0]);
+   LOAD32H(z, &ct[4]);
    for (r = 31; r >= 0; r -= 4) {
        z = (z - ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r])) & 0xFFFFFFFFUL;
        y = (y - ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r])) & 0xFFFFFFFFUL;
@@ -133,8 +133,8 @@ int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *
        z = (z - ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r-3])) & 0xFFFFFFFFUL;
        y = (y - ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r-3])) & 0xFFFFFFFFUL;
    }
-   STORE32L(y, &pt[0]);
-   STORE32L(z, &pt[4]);
+   STORE32H(y, &pt[0]);
+   STORE32H(z, &pt[4]);
    return CRYPT_OK;
 }
 
@@ -146,39 +146,105 @@ int xtea_test(void)
 {
  #ifndef LTC_TEST
     return CRYPT_NOP;
- #else    
-   static const unsigned char key[16] = 
-      { 0x78, 0x56, 0x34, 0x12, 0xf0, 0xcd, 0xcb, 0x9a,
-        0x48, 0x37, 0x26, 0x15, 0xc0, 0xbf, 0xae, 0x9d };
-   static const unsigned char pt[8] = 
-      { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
-   static const unsigned char ct[8] = 
-      { 0x75, 0xd7, 0xc5, 0xbf, 0xcf, 0x58, 0xc9, 0x3f };
+ #else
+    static const struct {
+        unsigned char key[16], pt[8], ct[8];
+    } tests[] = {
+       {
+         { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+         { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+         { 0xde, 0xe9, 0xd4, 0xd8, 0xf7, 0x13, 0x1e, 0xd9 }
+       }, {
+         { 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02,
+           0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04 },
+         { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+         { 0xa5, 0x97, 0xab, 0x41, 0x76, 0x01, 0x4d, 0x72 }
+       }, {
+         { 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04,
+           0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06 },
+         { 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02 },
+         { 0xb1, 0xfd, 0x5d, 0xa9, 0xcc, 0x6d, 0xc9, 0xdc }
+       }, {
+         { 0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f,
+           0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 },
+         { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 },
+         { 0x70, 0x4b, 0x31, 0x34, 0x47, 0x44, 0xdf, 0xab }
+       }, {
+         { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+           0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+         { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
+         { 0x49, 0x7d, 0xf3, 0xd0, 0x72, 0x61, 0x2c, 0xb5 }
+       }, {
+         { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+           0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+         { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
+         { 0xe7, 0x8f, 0x2d, 0x13, 0x74, 0x43, 0x41, 0xd8 }
+       }, {
+         { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+           0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+         { 0x5a, 0x5b, 0x6e, 0x27, 0x89, 0x48, 0xd7, 0x7f },
+         { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }
+       }, {
+         { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+         { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
+         { 0xa0, 0x39, 0x05, 0x89, 0xf8, 0xb8, 0xef, 0xa5 }
+       }, {
+         { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+         { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
+         { 0xed, 0x23, 0x37, 0x5a, 0x82, 0x1a, 0x8c, 0x2d }
+       }, {
+         { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+         { 0x70, 0xe1, 0x22, 0x5d, 0x6e, 0x4e, 0x76, 0x55 },
+         { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }
+       }
+    };
    unsigned char tmp[2][8];
    symmetric_key skey;
-   int err, y;
-
-   if ((err = xtea_setup(key, 16, 0, &skey)) != CRYPT_OK)  {
-      return err;
-   }
-   xtea_ecb_encrypt(pt, tmp[0], &skey);
-   xtea_ecb_decrypt(tmp[0], tmp[1], &skey);
-
-   if (XMEMCMP(tmp[0], ct, 8) != 0 || XMEMCMP(tmp[1], pt, 8) != 0) { 
-      return CRYPT_FAIL_TESTVECTOR;
-   }
+   int i, err, y;
+   for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
+       zeromem(&skey, sizeof(skey));
+       if ((err = xtea_setup(tests[i].key, 16, 0, &skey)) != CRYPT_OK)  {
+          return err;
+       }
+       xtea_ecb_encrypt(tests[i].pt, tmp[0], &skey);
+       xtea_ecb_decrypt(tmp[0], tmp[1], &skey);
+
+       if (XMEMCMP(tmp[0], tests[i].ct, 8) != 0 || XMEMCMP(tmp[1], tests[i].pt, 8) != 0) {
+#if 0
+          printf("\n\nTest %d failed\n", i);
+          if (XMEMCMP(tmp[0], tests[i].ct, 8)) {
+            printf("CT: ");
+            for (i = 0; i < 8; i++) {
+              printf("%02x ", tmp[0][i]);
+            }
+            printf("\n");
+          } else {
+            printf("PT: ");
+            for (i = 0; i < 8; i++) {
+              printf("%02x ", tmp[1][i]);
+            }
+            printf("\n");
+          }
+#endif
+          return CRYPT_FAIL_TESTVECTOR;
+       }
 
       /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
       for (y = 0; y < 8; y++) tmp[0][y] = 0;
       for (y = 0; y < 1000; y++) xtea_ecb_encrypt(tmp[0], tmp[0], &skey);
       for (y = 0; y < 1000; y++) xtea_ecb_decrypt(tmp[0], tmp[0], &skey);
       for (y = 0; y < 8; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
+   } /* for */
 
    return CRYPT_OK;
  #endif
 }
 
-/** Terminate the context 
+/** Terminate the context
    @param skey    The scheduled key
 */
 void xtea_done(symmetric_key *skey)
@@ -194,7 +260,7 @@ int xtea_keysize(int *keysize)
 {
    LTC_ARGCHK(keysize != NULL);
    if (*keysize < 16) {
-      return CRYPT_INVALID_KEYSIZE; 
+      return CRYPT_INVALID_KEYSIZE;
    }
    *keysize = 16;
    return CRYPT_OK;

+ 1 - 1
src/headers/tomcrypt_argchk.h

@@ -22,7 +22,7 @@ void crypt_argchk(char *v, char *s, int d);
 
 #elif ARGTYPE == 3
 
-#define LTC_ARGCHK(x) 
+#define LTC_ARGCHK(x)
 #define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
 
 #elif ARGTYPE == 4

+ 3 - 3
src/headers/tomcrypt_cfg.h

@@ -48,8 +48,8 @@ LTC_EXPORT int   LTC_CALL XSTRCMP(const char *s1, const char *s2);
    #define ARGTYPE  0
 #endif
 
-/* Controls endianess and size of registers.  Leave uncommented to get platform neutral [slower] code 
- * 
+/* Controls endianess and size of registers.  Leave uncommented to get platform neutral [slower] code
+ *
  * Note: in order to use the optimized macros your platform must support unaligned 32 and 64 bit read/writes.
  * The x86 platforms allow this but some others [ARM for instance] do not.  On those platforms you **MUST**
  * use the portable [slower] macros.
@@ -83,7 +83,7 @@ LTC_EXPORT int   LTC_CALL XSTRCMP(const char *s1, const char *s2);
    #define ENDIAN_32BITWORD
    #define LTC_FAST
    #define LTC_FAST_TYPE    unsigned long
-#endif   
+#endif
 
 /* detect sparc and sparc64 */
 #if defined(__sparc__)

+ 68 - 68
src/headers/tomcrypt_cipher.h

@@ -1,6 +1,6 @@
 /* ---- SYMMETRIC KEY STUFF -----
  *
- * We put each of the ciphers scheduled keys in their own structs then we put all of 
+ * We put each of the ciphers scheduled keys in their own structs then we put all of
  * the key formats in one union.  This makes the function prototypes easier to use.
  */
 #ifdef LTC_BLOWFISH
@@ -109,7 +109,7 @@ struct noekeon_key {
 };
 #endif
 
-#ifdef LTC_SKIPJACK 
+#ifdef LTC_SKIPJACK
 struct skipjack_key {
     unsigned char key[10];
 };
@@ -117,18 +117,18 @@ struct skipjack_key {
 
 #ifdef LTC_KHAZAD
 struct khazad_key {
-   ulong64 roundKeyEnc[8 + 1]; 
-   ulong64 roundKeyDec[8 + 1]; 
+   ulong64 roundKeyEnc[8 + 1];
+   ulong64 roundKeyDec[8 + 1];
 };
 #endif
 
 #ifdef LTC_ANUBIS
-struct anubis_key { 
-   int keyBits; 
-   int R; 
-   ulong32 roundKeyEnc[18 + 1][4]; 
-   ulong32 roundKeyDec[18 + 1][4]; 
-}; 
+struct anubis_key {
+   int keyBits;
+   int R;
+   ulong32 roundKeyEnc[18 + 1][4];
+   ulong32 roundKeyDec[18 + 1][4];
+};
 #endif
 
 #ifdef LTC_MULTI2
@@ -182,7 +182,7 @@ typedef union Symmetric_key {
 #endif
 #ifdef LTC_NOEKEON
    struct noekeon_key  noekeon;
-#endif   
+#endif
 #ifdef LTC_SKIPJACK
    struct skipjack_key skipjack;
 #endif
@@ -197,7 +197,7 @@ typedef union Symmetric_key {
 #endif
 #ifdef LTC_KASUMI
    struct kasumi_key   kasumi;
-#endif  
+#endif
 #ifdef LTC_MULTI2
    struct multi2_key   multi2;
 #endif
@@ -211,10 +211,10 @@ typedef union Symmetric_key {
 /** A block cipher ECB structure */
 typedef struct {
    /** The index of the cipher chosen */
-   int                 cipher, 
+   int                 cipher,
    /** The block size of the given cipher */
                        blocklen;
-   /** The scheduled key */                       
+   /** The scheduled key */
    symmetric_key       key;
 } symmetric_ECB;
 #endif
@@ -223,14 +223,14 @@ typedef struct {
 /** A block cipher CFB structure */
 typedef struct {
    /** The index of the cipher chosen */
-   int                 cipher, 
-   /** The block size of the given cipher */                        
-                       blocklen, 
+   int                 cipher,
+   /** The block size of the given cipher */
+                       blocklen,
    /** The padding offset */
                        padlen;
    /** The current IV */
-   unsigned char       IV[MAXBLOCKSIZE], 
-   /** The pad used to encrypt/decrypt */ 
+   unsigned char       IV[MAXBLOCKSIZE],
+   /** The pad used to encrypt/decrypt */
                        pad[MAXBLOCKSIZE];
    /** The scheduled key */
    symmetric_key       key;
@@ -241,9 +241,9 @@ typedef struct {
 /** A block cipher OFB structure */
 typedef struct {
    /** The index of the cipher chosen */
-   int                 cipher, 
-   /** The block size of the given cipher */                        
-                       blocklen, 
+   int                 cipher,
+   /** The block size of the given cipher */
+                       blocklen,
    /** The padding offset */
                        padlen;
    /** The current IV */
@@ -257,8 +257,8 @@ typedef struct {
 /** A block cipher CBC structure */
 typedef struct {
    /** The index of the cipher chosen */
-   int                 cipher, 
-   /** The block size of the given cipher */                        
+   int                 cipher,
+   /** The block size of the given cipher */
                        blocklen;
    /** The current IV */
    unsigned char       IV[MAXBLOCKSIZE];
@@ -273,18 +273,18 @@ typedef struct {
 typedef struct {
    /** The index of the cipher chosen */
    int                 cipher,
-   /** The block size of the given cipher */                        
-                       blocklen, 
+   /** The block size of the given cipher */
+                       blocklen,
    /** The padding offset */
-                       padlen, 
+                       padlen,
    /** The mode (endianess) of the CTR, 0==little, 1==big */
                        mode,
    /** counter width */
                        ctrlen;
 
-   /** The counter */                       
-   unsigned char       ctr[MAXBLOCKSIZE], 
-   /** The pad used to encrypt/decrypt */                       
+   /** The counter */
+   unsigned char       ctr[MAXBLOCKSIZE],
+   /** The pad used to encrypt/decrypt */
                        pad[MAXBLOCKSIZE];
    /** The scheduled key */
    symmetric_key       key;
@@ -300,7 +300,7 @@ typedef struct {
 
     /** The current IV */
     unsigned char     IV[16],
- 
+
     /** the tweak key */
                       tweak[16],
 
@@ -321,9 +321,9 @@ typedef struct {
 /** A block cipher F8 structure */
 typedef struct {
    /** The index of the cipher chosen */
-   int                 cipher, 
-   /** The block size of the given cipher */                        
-                       blocklen, 
+   int                 cipher,
+   /** The block size of the given cipher */
+                       blocklen,
    /** The padding offset */
                        padlen;
    /** The current IV */
@@ -344,14 +344,14 @@ extern struct ltc_cipher_descriptor {
    /** internal ID */
    unsigned char ID;
    /** min keysize (octets) */
-   int  min_key_length, 
+   int  min_key_length,
    /** max keysize (octets) */
-        max_key_length, 
+        max_key_length,
    /** block size (octets) */
-        block_length, 
+        block_length,
    /** default number of rounds */
         default_rounds;
-   /** Setup the cipher 
+   /** Setup the cipher
       @param key         The input symmetric key
       @param keylen      The length of the input key (octets)
       @param num_rounds  The requested number of rounds (0==default)
@@ -378,10 +378,10 @@ extern struct ltc_cipher_descriptor {
    */
    int (*test)(void);
 
-   /** Terminate the context 
+   /** Terminate the context
       @param skey    The scheduled key
    */
-   void (*done)(symmetric_key *skey);      
+   void (*done)(symmetric_key *skey);
 
    /** Determine a key size
        @param keysize    [in/out] The size of the key desired and the suggested size
@@ -390,7 +390,7 @@ extern struct ltc_cipher_descriptor {
    int  (*keysize)(int *keysize);
 
 /** Accelerators **/
-   /** Accelerated ECB encryption 
+   /** Accelerated ECB encryption
        @param pt      Plaintext
        @param ct      Ciphertext
        @param blocks  The number of complete blocks to process
@@ -399,7 +399,7 @@ extern struct ltc_cipher_descriptor {
    */
    int (*accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, symmetric_key *skey);
 
-   /** Accelerated ECB decryption 
+   /** Accelerated ECB decryption
        @param pt      Plaintext
        @param ct      Ciphertext
        @param blocks  The number of complete blocks to process
@@ -408,7 +408,7 @@ extern struct ltc_cipher_descriptor {
    */
    int (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey);
 
-   /** Accelerated CBC encryption 
+   /** Accelerated CBC encryption
        @param pt      Plaintext
        @param ct      Ciphertext
        @param blocks  The number of complete blocks to process
@@ -418,7 +418,7 @@ extern struct ltc_cipher_descriptor {
    */
    int (*accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
 
-   /** Accelerated CBC decryption 
+   /** Accelerated CBC decryption
        @param pt      Plaintext
        @param ct      Ciphertext
        @param blocks  The number of complete blocks to process
@@ -428,7 +428,7 @@ extern struct ltc_cipher_descriptor {
    */
    int (*accel_cbc_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
 
-   /** Accelerated CTR encryption 
+   /** Accelerated CTR encryption
        @param pt      Plaintext
        @param ct      Ciphertext
        @param blocks  The number of complete blocks to process
@@ -439,7 +439,7 @@ extern struct ltc_cipher_descriptor {
    */
    int (*accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey);
 
-   /** Accelerated LRW 
+   /** Accelerated LRW
        @param pt      Plaintext
        @param ct      Ciphertext
        @param blocks  The number of complete blocks to process
@@ -450,7 +450,7 @@ extern struct ltc_cipher_descriptor {
    */
    int (*accel_lrw_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey);
 
-   /** Accelerated LRW 
+   /** Accelerated LRW
        @param ct      Ciphertext
        @param pt      Plaintext
        @param blocks  The number of complete blocks to process
@@ -490,7 +490,7 @@ extern struct ltc_cipher_descriptor {
    /** Accelerated GCM packet (one shot)
        @param key        The secret key
        @param keylen     The length of the secret key
-       @param IV         The initial vector 
+       @param IV         The initial vector
        @param IVlen      The length of the initial vector
        @param adata      The additional authentication data (header)
        @param adatalen   The length of the adata
@@ -507,14 +507,14 @@ extern struct ltc_cipher_descriptor {
        const unsigned char *IV,     unsigned long IVlen,
        const unsigned char *adata,  unsigned long adatalen,
              unsigned char *pt,     unsigned long ptlen,
-             unsigned char *ct, 
+             unsigned char *ct,
              unsigned char *tag,    unsigned long *taglen,
                        int direction);
 
-   /** Accelerated one shot LTC_OMAC 
+   /** Accelerated one shot LTC_OMAC
        @param key            The secret key
-       @param keylen         The key length (octets) 
-       @param in             The message 
+       @param keylen         The key length (octets)
+       @param in             The message
        @param inlen          Length of message (octets)
        @param out            [out] Destination for tag
        @param outlen         [in/out] Initial and final size of out
@@ -525,10 +525,10 @@ extern struct ltc_cipher_descriptor {
        const unsigned char *in,  unsigned long inlen,
              unsigned char *out, unsigned long *outlen);
 
-   /** Accelerated one shot XCBC 
+   /** Accelerated one shot XCBC
        @param key            The secret key
-       @param keylen         The key length (octets) 
-       @param in             The message 
+       @param keylen         The key length (octets)
+       @param in             The message
        @param inlen          Length of message (octets)
        @param out            [out] Destination for tag
        @param outlen         [in/out] Initial and final size of out
@@ -539,10 +539,10 @@ extern struct ltc_cipher_descriptor {
        const unsigned char *in,  unsigned long inlen,
              unsigned char *out, unsigned long *outlen);
 
-   /** Accelerated one shot F9 
+   /** Accelerated one shot F9
        @param key            The secret key
-       @param keylen         The key length (octets) 
-       @param in             The message 
+       @param keylen         The key length (octets)
+       @param in             The message
        @param inlen          Length of message (octets)
        @param out            [out] Destination for tag
        @param outlen         [in/out] Initial and final size of out
@@ -777,7 +777,7 @@ extern const struct ltc_cipher_descriptor camellia_desc;
 #endif
 
 #ifdef LTC_ECB_MODE
-int ecb_start(int cipher, const unsigned char *key, 
+int ecb_start(int cipher, const unsigned char *key,
               int keylen, int num_rounds, symmetric_ECB *ecb);
 int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb);
 int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb);
@@ -785,7 +785,7 @@ int ecb_done(symmetric_ECB *ecb);
 #endif
 
 #ifdef LTC_CFB_MODE
-int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key, 
+int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,
               int keylen, int num_rounds, symmetric_CFB *cfb);
 int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb);
 int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb);
@@ -795,7 +795,7 @@ int cfb_done(symmetric_CFB *cfb);
 #endif
 
 #ifdef LTC_OFB_MODE
-int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key, 
+int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,
               int keylen, int num_rounds, symmetric_OFB *ofb);
 int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb);
 int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb);
@@ -842,7 +842,7 @@ int lrw_start(               int   cipher,
               const unsigned char *IV,
               const unsigned char *key,       int keylen,
               const unsigned char *tweak,
-                             int  num_rounds, 
+                             int  num_rounds,
                    symmetric_LRW *lrw);
 int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw);
 int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw);
@@ -853,11 +853,11 @@ int lrw_test(void);
 
 /* don't call */
 int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw);
-#endif    
+#endif
 
 #ifdef LTC_F8_MODE
-int f8_start(                int  cipher, const unsigned char *IV, 
-             const unsigned char *key,                    int  keylen, 
+int f8_start(                int  cipher, const unsigned char *IV,
+             const unsigned char *key,                    int  keylen,
              const unsigned char *salt_key,               int  skeylen,
                              int  num_rounds,   symmetric_F8  *f8);
 int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8);
@@ -875,10 +875,10 @@ typedef struct {
 } symmetric_xts;
 
 int xts_start(                int  cipher,
-              const unsigned char *key1, 
-              const unsigned char *key2, 
+              const unsigned char *key1,
+              const unsigned char *key2,
                     unsigned long  keylen,
-                              int  num_rounds, 
+                              int  num_rounds,
                     symmetric_xts *xts);
 
 int xts_encrypt(

+ 16 - 16
src/headers/tomcrypt_custom.h

@@ -3,19 +3,19 @@
 
 /* macros for various libc functions you can change for embedded targets */
 #ifndef XMALLOC
-   #ifdef malloc 
+   #ifdef malloc
    #define LTC_NO_PROTOTYPES
    #endif
 #define XMALLOC  malloc
 #endif
 #ifndef XREALLOC
-   #ifdef realloc 
+   #ifdef realloc
    #define LTC_NO_PROTOTYPES
    #endif
 #define XREALLOC realloc
 #endif
 #ifndef XCALLOC
-   #ifdef calloc 
+   #ifdef calloc
    #define LTC_NO_PROTOTYPES
    #endif
 #define XCALLOC  calloc
@@ -40,7 +40,7 @@
 #define XMEMCPY  memcpy
 #endif
 #ifndef XMEMCMP
-   #ifdef memcmp 
+   #ifdef memcmp
    #define LTC_NO_PROTOTYPES
    #endif
 #define XMEMCMP  memcmp
@@ -73,19 +73,19 @@
    #define LTC_BLOWFISH
    #define LTC_DES
    #define LTC_CAST5
-   
+
    #define LTC_NO_MODES
    #define LTC_ECB_MODE
    #define LTC_CBC_MODE
    #define LTC_CTR_MODE
-   
+
    #define LTC_NO_HASHES
    #define LTC_SHA1
    #define LTC_SHA512
    #define LTC_SHA384
    #define LTC_SHA256
    #define LTC_SHA224
-   
+
    #define LTC_NO_MACS
    #define LTC_HMAC
    #define LTC_OMAC
@@ -96,11 +96,11 @@
    #define LTC_YARROW
    #define LTC_DEVRANDOM
    #define TRY_URANDOM_FIRST
-      
+
    #define LTC_NO_PK
    #define LTC_MRSA
    #define LTC_MECC
-#endif   
+#endif
 
 /* Use small code where possible */
 /* #define LTC_SMALL_CODE */
@@ -178,7 +178,7 @@
 #define LTC_LRW_MODE
 #ifndef LTC_NO_TABLES
    /* like GCM mode this will enable 16 8x128 tables [64KB] that make
-    * seeking very fast.  
+    * seeking very fast.
     */
    #define LRW_TABLES
 #endif
@@ -189,7 +189,7 @@
 #endif /* LTC_NO_MODES */
 
 /* ---> One-Way Hash Functions <--- */
-#ifndef LTC_NO_HASHES 
+#ifndef LTC_NO_HASHES
 
 #define LTC_CHC_HASH
 #define LTC_WHIRLPOOL
@@ -237,7 +237,7 @@
 
 /* Use 64KiB tables */
 #ifndef LTC_NO_TABLES
-   #define LTC_GCM_TABLES 
+   #define LTC_GCM_TABLES
 #endif
 
 /* USE SSE2? requires GCC works on x86_32 and x86_64*/
@@ -331,7 +331,7 @@
 #endif
 
 /* Include Katja (a Rabin variant like RSA) */
-/* #define MKAT */ 
+/* #define MKAT */
 
 /* Digital Signature Algorithm */
 #define LTC_MDSA
@@ -344,7 +344,7 @@
 
 #if defined(TFM_LTC_DESC) && defined(LTC_MECC)
    #define LTC_MECC_ACCEL
-#endif   
+#endif
 
 /* do we want fixed point ECC */
 /* #define LTC_MECC_FP */
@@ -395,14 +395,14 @@
 
 #ifdef LTC_MRSA
    #define LTC_PKCS_1
-#endif   
+#endif
 
 #if defined(TFM_DESC) && defined(LTC_RSA_BLINDING)
     #warning RSA blinding currently not supported in combination with TFM
     #undef LTC_RSA_BLINDING
 #endif
 
-#if defined(LTC_DER) && !defined(MPI) 
+#if defined(LTC_DER) && !defined(MPI)
    #error ASN.1 DER requires MPI functionality
 #endif
 

+ 4 - 4
src/headers/tomcrypt_hash.h

@@ -166,7 +166,7 @@ extern  struct ltc_hash_descriptor {
       @return CRYPT_OK if successful
     */
     int (*init)(hash_state *hash);
-    /** Process a block of data 
+    /** Process a block of data
       @param hash   The hash state
       @param in     The data to hash
       @param inlen  The length of the data (octets)
@@ -186,7 +186,7 @@ extern  struct ltc_hash_descriptor {
 
     /* accelerated hmac callback: if you need to-do multiple packets just use the generic hmac_memory and provide a hash callback */
     int  (*hmac_block)(const unsigned char *key, unsigned long  keylen,
-                       const unsigned char *in,  unsigned long  inlen, 
+                       const unsigned char *in,  unsigned long  inlen,
                              unsigned char *out, unsigned long *outlen);
 
 } hash_descriptor[];
@@ -329,8 +329,8 @@ int hash_is_valid(int idx);
 
 LTC_MUTEX_PROTO(ltc_hash_mutex)
 
-int hash_memory(int hash, 
-                const unsigned char *in,  unsigned long inlen, 
+int hash_memory(int hash,
+                const unsigned char *in,  unsigned long inlen,
                       unsigned char *out, unsigned long *outlen);
 int hash_memory_multi(int hash, unsigned char *out, unsigned long *outlen,
                       const unsigned char *in, unsigned long inlen, ...);

+ 33 - 33
src/headers/tomcrypt_mac.h

@@ -10,23 +10,23 @@ int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned lon
 int hmac_process(hmac_state *hmac, const unsigned char *in, unsigned long inlen);
 int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen);
 int hmac_test(void);
-int hmac_memory(int hash, 
+int hmac_memory(int hash,
                 const unsigned char *key, unsigned long keylen,
-                const unsigned char *in,  unsigned long inlen, 
+                const unsigned char *in,  unsigned long inlen,
                       unsigned char *out, unsigned long *outlen);
-int hmac_memory_multi(int hash, 
+int hmac_memory_multi(int hash,
                 const unsigned char *key,  unsigned long keylen,
                       unsigned char *out,  unsigned long *outlen,
                 const unsigned char *in,   unsigned long inlen, ...);
 int hmac_file(int hash, const char *fname, const unsigned char *key,
-              unsigned long keylen, 
+              unsigned long keylen,
               unsigned char *dst, unsigned long *dstlen);
 #endif
 
 #ifdef LTC_OMAC
 
 typedef struct {
-   int             cipher_idx, 
+   int             cipher_idx,
                    buflen,
                    blklen;
    unsigned char   block[MAXBLOCKSIZE],
@@ -38,17 +38,17 @@ typedef struct {
 int omac_init(omac_state *omac, int cipher, const unsigned char *key, unsigned long keylen);
 int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen);
 int omac_done(omac_state *omac, unsigned char *out, unsigned long *outlen);
-int omac_memory(int cipher, 
+int omac_memory(int cipher,
                const unsigned char *key, unsigned long keylen,
                const unsigned char *in,  unsigned long inlen,
                      unsigned char *out, unsigned long *outlen);
-int omac_memory_multi(int cipher, 
+int omac_memory_multi(int cipher,
                 const unsigned char *key, unsigned long keylen,
                       unsigned char *out, unsigned long *outlen,
                 const unsigned char *in,  unsigned long inlen, ...);
-int omac_file(int cipher, 
+int omac_file(int cipher,
               const unsigned char *key, unsigned long keylen,
-              const          char *filename, 
+              const          char *filename,
                     unsigned char *out, unsigned long *outlen);
 int omac_test(void);
 #endif /* LTC_OMAC */
@@ -73,19 +73,19 @@ int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned l
 int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen);
 int pmac_done(pmac_state *pmac, unsigned char *out, unsigned long *outlen);
 
-int pmac_memory(int cipher, 
+int pmac_memory(int cipher,
                const unsigned char *key, unsigned long keylen,
                const unsigned char *msg, unsigned long msglen,
                      unsigned char *out, unsigned long *outlen);
 
-int pmac_memory_multi(int cipher, 
+int pmac_memory_multi(int cipher,
                 const unsigned char *key, unsigned long keylen,
                       unsigned char *out, unsigned long *outlen,
                 const unsigned char *in, unsigned long inlen, ...);
 
-int pmac_file(int cipher, 
+int pmac_file(int cipher,
              const unsigned char *key, unsigned long keylen,
-             const          char *filename, 
+             const          char *filename,
                    unsigned char *out, unsigned long *outlen);
 
 int pmac_test(void);
@@ -152,32 +152,32 @@ typedef struct {
                      block_len;               /* length of block */
 } ocb_state;
 
-int ocb_init(ocb_state *ocb, int cipher, 
+int ocb_init(ocb_state *ocb, int cipher,
              const unsigned char *key, unsigned long keylen, const unsigned char *nonce);
 
 int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct);
 int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt);
 
-int ocb_done_encrypt(ocb_state *ocb, 
+int ocb_done_encrypt(ocb_state *ocb,
                      const unsigned char *pt,  unsigned long ptlen,
-                           unsigned char *ct, 
+                           unsigned char *ct,
                            unsigned char *tag, unsigned long *taglen);
 
-int ocb_done_decrypt(ocb_state *ocb, 
+int ocb_done_decrypt(ocb_state *ocb,
                      const unsigned char *ct,  unsigned long ctlen,
-                           unsigned char *pt, 
+                           unsigned char *pt,
                      const unsigned char *tag, unsigned long taglen, int *stat);
 
 int ocb_encrypt_authenticate_memory(int cipher,
     const unsigned char *key,    unsigned long keylen,
-    const unsigned char *nonce,  
+    const unsigned char *nonce,
     const unsigned char *pt,     unsigned long ptlen,
           unsigned char *ct,
           unsigned char *tag,    unsigned long *taglen);
 
 int ocb_decrypt_verify_memory(int cipher,
     const unsigned char *key,    unsigned long keylen,
-    const unsigned char *nonce,  
+    const unsigned char *nonce,
     const unsigned char *ct,     unsigned long ctlen,
           unsigned char *pt,
     const unsigned char *tag,    unsigned long taglen,
@@ -305,7 +305,7 @@ extern const unsigned char gcm_shift_table[];
 #define LTC_GCM_MODE_AAD   1
 #define LTC_GCM_MODE_TEXT  2
 
-typedef struct { 
+typedef struct {
    symmetric_key       K;
    unsigned char       H[16],        /* multiplier */
                        X[16],        /* accumulator */
@@ -327,7 +327,7 @@ typedef struct {
 __attribute__ ((aligned (16)))
 #endif
 ;
-#endif  
+#endif
 } gcm_state;
 
 void gcm_mult_h(gcm_state *gcm, unsigned char *I);
@@ -337,7 +337,7 @@ int gcm_init(gcm_state *gcm, int cipher,
 
 int gcm_reset(gcm_state *gcm);
 
-int gcm_add_iv(gcm_state *gcm, 
+int gcm_add_iv(gcm_state *gcm,
                const unsigned char *IV,     unsigned long IVlen);
 
 int gcm_add_aad(gcm_state *gcm,
@@ -348,7 +348,7 @@ int gcm_process(gcm_state *gcm,
                      unsigned char *ct,
                      int direction);
 
-int gcm_done(gcm_state *gcm, 
+int gcm_done(gcm_state *gcm,
                      unsigned char *tag,    unsigned long *taglen);
 
 int gcm_memory(      int           cipher,
@@ -356,7 +356,7 @@ int gcm_memory(      int           cipher,
                const unsigned char *IV,     unsigned long IVlen,
                const unsigned char *adata,  unsigned long adatalen,
                      unsigned char *pt,     unsigned long ptlen,
-                     unsigned char *ct, 
+                     unsigned char *ct,
                      unsigned char *tag,    unsigned long *taglen,
                                int direction);
 int gcm_test(void);
@@ -402,17 +402,17 @@ typedef struct {
 int xcbc_init(xcbc_state *xcbc, int cipher, const unsigned char *key, unsigned long keylen);
 int xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen);
 int xcbc_done(xcbc_state *xcbc, unsigned char *out, unsigned long *outlen);
-int xcbc_memory(int cipher, 
+int xcbc_memory(int cipher,
                const unsigned char *key, unsigned long keylen,
                const unsigned char *in,  unsigned long inlen,
                      unsigned char *out, unsigned long *outlen);
-int xcbc_memory_multi(int cipher, 
+int xcbc_memory_multi(int cipher,
                 const unsigned char *key, unsigned long keylen,
                       unsigned char *out, unsigned long *outlen,
                 const unsigned char *in,  unsigned long inlen, ...);
-int xcbc_file(int cipher, 
+int xcbc_file(int cipher,
               const unsigned char *key, unsigned long keylen,
-              const          char *filename, 
+              const          char *filename,
                     unsigned char *out, unsigned long *outlen);
 int xcbc_test(void);
 
@@ -436,17 +436,17 @@ typedef struct {
 int f9_init(f9_state *f9, int cipher, const unsigned char *key, unsigned long keylen);
 int f9_process(f9_state *f9, const unsigned char *in, unsigned long inlen);
 int f9_done(f9_state *f9, unsigned char *out, unsigned long *outlen);
-int f9_memory(int cipher, 
+int f9_memory(int cipher,
                const unsigned char *key, unsigned long keylen,
                const unsigned char *in,  unsigned long inlen,
                      unsigned char *out, unsigned long *outlen);
-int f9_memory_multi(int cipher, 
+int f9_memory_multi(int cipher,
                 const unsigned char *key, unsigned long keylen,
                       unsigned char *out, unsigned long *outlen,
                 const unsigned char *in,  unsigned long inlen, ...);
-int f9_file(int cipher, 
+int f9_file(int cipher,
               const unsigned char *key, unsigned long keylen,
-              const          char *filename, 
+              const          char *filename,
                     unsigned char *out, unsigned long *outlen);
 int f9_test(void);
 

+ 5 - 5
src/headers/tomcrypt_macros.h

@@ -7,8 +7,8 @@
    typedef unsigned long long ulong64;
 #endif
 
-/* this is the "32-bit at least" data type 
- * Re-define it to suit your platform but it must be at least 32-bits 
+/* this is the "32-bit at least" data type
+ * Re-define it to suit your platform but it must be at least 32-bits
  */
 #if defined(__x86_64__) || (defined(__sparc__) && defined(__arch64__))
    typedef unsigned ulong32;
@@ -148,7 +148,7 @@ asm __volatile__ (             \
 
 #endif
 
-#ifdef ENDIAN_32BITWORD 
+#ifdef ENDIAN_32BITWORD
 
 #define STORE32L(x, y)        \
      { ulong32  __t = (x); XMEMCPY(y, &__t, 4); }
@@ -209,7 +209,7 @@ asm __volatile__ (             \
          (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16) | \
          (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
 
-#ifdef ENDIAN_32BITWORD 
+#ifdef ENDIAN_32BITWORD
 
 #define STORE32H(x, y)        \
      { ulong32 __t = (x); XMEMCPY(y, &__t, 4); }
@@ -436,7 +436,7 @@ static inline unsigned long ROR64c(unsigned long word, const int i)
    #define byte(x, n) ((unsigned char)((x) >> (8 * (n))))
 #else
    #define byte(x, n) (((x) >> (8 * (n))) & 255)
-#endif   
+#endif
 
 /* $Source$ */
 /* $Revision$ */

+ 45 - 45
src/headers/tomcrypt_math.h

@@ -30,15 +30,15 @@ typedef struct {
      @return  CRYPT_OK on success
    */
    int (*init)(void **a);
-   
-   /** init copy 
+
+   /** init copy
      @param  dst    The number to initialize and write to
      @param  src    The number to copy from
      @return CRYPT_OK on success
    */
    int (*init_copy)(void **dst, void *src);
 
-   /** deinit 
+   /** deinit
       @param   a    The number to free
       @return CRYPT_OK on success
    */
@@ -52,30 +52,30 @@ typedef struct {
       @return CRYPT_OK on success
    */
    int (*neg)(void *src, void *dst);
-   
-   /** copy 
+
+   /** copy
       @param   src   The number to copy from
-      @param   dst   The number to write to 
+      @param   dst   The number to write to
       @return CRYPT_OK on success
    */
    int (*copy)(void *src, void *dst);
 
 /* ---- trivial low level functions ---- */
 
-   /** set small constant 
+   /** set small constant
       @param a    Number to write to
-      @param n    Source upto bits_per_digit (actually meant for very small constants) 
+      @param n    Source upto bits_per_digit (actually meant for very small constants)
       @return CRYPT_OK on succcess
    */
    int (*set_int)(void *a, unsigned long n);
 
-   /** get small constant 
+   /** get small constant
       @param a    Number to read, only fetches upto bits_per_digit from the number
       @return  The lower bits_per_digit of the integer (unsigned)
    */
    unsigned long (*get_int)(void *a);
 
-   /** get digit n 
+   /** get digit n
      @param a  The number to read from
      @param n  The number of the digit to fetch
      @return  The bits_per_digit  sized n'th digit of a
@@ -95,7 +95,7 @@ typedef struct {
    */
    int (*compare)(void *a, void *b);
 
-   /** compare against int 
+   /** compare against int
      @param a   The left side integer
      @param b   The right side integer (upto bits_per_digit)
      @return LTC_MP_LT if a < b, LTC_MP_GT if a > b and LTC_MP_EQ otherwise.  (signed comparison)
@@ -108,7 +108,7 @@ typedef struct {
    */
    int (*count_bits)(void * a);
 
-   /** Count the number of LSB bits which are zero 
+   /** Count the number of LSB bits which are zero
      @param a   The integer to count
      @return The number of contiguous zero LSB bits
    */
@@ -122,8 +122,8 @@ typedef struct {
    int (*twoexpt)(void *a , int n);
 
 /* ---- radix conversions ---- */
-   
-   /** read ascii string 
+
+   /** read ascii string
      @param a     The integer to store into
      @param str   The string to read
      @param radix The radix the integer has been represented in (2-64)
@@ -139,13 +139,13 @@ typedef struct {
    */
    int (*write_radix)(void *a, char *str, int radix);
 
-   /** get size as unsigned char string 
+   /** get size as unsigned char string
      @param a     The integer to get the size (when stored in array of octets)
      @return The length of the integer
    */
    unsigned long (*unsigned_size)(void *a);
 
-   /** store an integer as an array of octets 
+   /** store an integer as an array of octets
      @param src   The integer to store
      @param dst   The buffer to store the integer in
      @return CRYPT_OK on success
@@ -154,15 +154,15 @@ typedef struct {
 
    /** read an array of octets and store as integer
      @param dst   The integer to load
-     @param src   The array of octets 
-     @param len   The number of octets 
+     @param src   The array of octets
+     @param len   The number of octets
      @return CRYPT_OK on success
    */
    int (*unsigned_read)(void *dst, unsigned char *src, unsigned long len);
 
 /* ---- basic math ---- */
 
-   /** add two integers 
+   /** add two integers
      @param a   The first source integer
      @param b   The second source integer
      @param c   The destination of "a + b"
@@ -171,7 +171,7 @@ typedef struct {
    int (*add)(void *a, void *b, void *c);
 
 
-   /** add two integers 
+   /** add two integers
      @param a   The first source integer
      @param b   The second source integer (single digit of upto bits_per_digit in length)
      @param c   The destination of "a + b"
@@ -179,7 +179,7 @@ typedef struct {
    */
    int (*addi)(void *a, unsigned long b, void *c);
 
-   /** subtract two integers 
+   /** subtract two integers
      @param a   The first source integer
      @param b   The second source integer
      @param c   The destination of "a - b"
@@ -187,7 +187,7 @@ typedef struct {
    */
    int (*sub)(void *a, void *b, void *c);
 
-   /** subtract two integers 
+   /** subtract two integers
      @param a   The first source integer
      @param b   The second source integer (single digit of upto bits_per_digit in length)
      @param c   The destination of "a - b"
@@ -195,7 +195,7 @@ typedef struct {
    */
    int (*subi)(void *a, unsigned long b, void *c);
 
-   /** multiply two integers 
+   /** multiply two integers
      @param a   The first source integer
      @param b   The second source integer (single digit of upto bits_per_digit in length)
      @param c   The destination of "a * b"
@@ -203,7 +203,7 @@ typedef struct {
    */
    int (*mul)(void *a, void *b, void *c);
 
-   /** multiply two integers 
+   /** multiply two integers
      @param a   The first source integer
      @param b   The second source integer (single digit of upto bits_per_digit in length)
      @param c   The destination of "a * b"
@@ -227,9 +227,9 @@ typedef struct {
    */
    int (*mpdiv)(void *a, void *b, void *c, void *d);
 
-   /** divide by two 
+   /** divide by two
       @param  a   The integer to divide (shift right)
-      @param  b   The destination 
+      @param  b   The destination
       @return CRYPT_OK on success
    */
    int (*div_2)(void *a, void *b);
@@ -242,7 +242,7 @@ typedef struct {
    */
    int (*modi)(void *a, unsigned long b, unsigned long *c);
 
-   /** gcd 
+   /** gcd
       @param  a     The first integer
       @param  b     The second integer
       @param  c     The destination for (a, b)
@@ -250,7 +250,7 @@ typedef struct {
    */
    int (*gcd)(void *a, void *b, void *c);
 
-   /** lcm 
+   /** lcm
       @param  a     The first integer
       @param  b     The second integer
       @param  c     The destination for [a, b]
@@ -260,7 +260,7 @@ typedef struct {
 
    /** Modular multiplication
       @param  a     The first source
-      @param  b     The second source 
+      @param  b     The second source
       @param  c     The modulus
       @param  d     The destination (a*b mod c)
       @return CRYPT_OK on success
@@ -277,7 +277,7 @@ typedef struct {
 
    /** Modular inversion
       @param  a     The value to invert
-      @param  b     The modulus 
+      @param  b     The modulus
       @param  c     The destination (1/a mod b)
       @return CRYPT_OK on success
    */
@@ -286,13 +286,13 @@ typedef struct {
 /* ---- reduction ---- */
 
    /** setup montgomery
-       @param a  The modulus 
-       @param b  The destination for the reduction digit 
+       @param a  The modulus
+       @param b  The destination for the reduction digit
        @return CRYPT_OK on success
    */
    int (*montgomery_setup)(void *a, void **b);
 
-   /** get normalization value 
+   /** get normalization value
        @param a   The destination for the normalization value
        @param b   The modulus
        @return  CRYPT_OK on success
@@ -310,7 +310,7 @@ typedef struct {
    /** clean up  (frees memory)
        @param a   The value "b" from montgomery_setup()
        @return CRYPT_OK on success
-   */      
+   */
    void (*montgomery_deinit)(void *a);
 
 /* ---- exponentiation ---- */
@@ -336,14 +336,14 @@ typedef struct {
    /** ECC GF(p) point multiplication (from the NIST curves)
        @param k   The integer to multiply the point by
        @param G   The point to multiply
-       @param R   The destination for kG  
+       @param R   The destination for kG
        @param modulus  The modulus for the field
        @param map Boolean indicated whether to map back to affine or not (can be ignored if you work in affine only)
        @return CRYPT_OK on success
    */
    int (*ecc_ptmul)(void *k, ecc_point *G, ecc_point *R, void *modulus, int map);
 
-   /** ECC GF(p) point addition 
+   /** ECC GF(p) point addition
        @param P    The first point
        @param Q    The second point
        @param R    The destination of P + Q
@@ -353,7 +353,7 @@ typedef struct {
    */
    int (*ecc_ptadd)(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp);
 
-   /** ECC GF(p) point double 
+   /** ECC GF(p) point double
        @param P    The first point
        @param R    The destination of 2P
        @param modulus  The modulus
@@ -367,7 +367,7 @@ typedef struct {
        @param modulus The modulus
        @param mp    The "b" value from montgomery_setup()
        @return CRYPT_OK on success
-       @remark  The mapping can be different but keep in mind a ecc_point only has three 
+       @remark  The mapping can be different but keep in mind a ecc_point only has three
                 integers (x,y,z) so if you use a different mapping you have to make it fit.
    */
    int (*ecc_map)(ecc_point *P, void *modulus, void *mp);
@@ -378,9 +378,9 @@ typedef struct {
        @param B        Second point to multiply
        @param kB       What to multiple B by
        @param C        [out] Destination point (can overlap with A or B
-       @param modulus  Modulus for curve 
+       @param modulus  Modulus for curve
        @return CRYPT_OK on success
-   */ 
+   */
    int (*ecc_mul2add)(ecc_point *A, void *kA,
                       ecc_point *B, void *kB,
                       ecc_point *C,
@@ -388,7 +388,7 @@ typedef struct {
 
 /* ---- (optional) rsa optimized math (for internal CRT) ---- */
 
-   /** RSA Key Generation 
+   /** RSA Key Generation
        @param prng     An active PRNG state
        @param wprng    The index of the PRNG desired
        @param size     The size of the modulus (key size) desired (octets)
@@ -397,7 +397,7 @@ typedef struct {
        @return CRYPT_OK if successful, upon error all allocated ram is freed
     */
     int (*rsa_keygen)(prng_state *prng, int wprng, int size, long e, rsa_key *key);
-   
+
 
    /** RSA exponentiation
       @param in       The octet array representing the base
@@ -405,7 +405,7 @@ typedef struct {
       @param out      The destination (to be stored in an octet array format)
       @param outlen   The length of the output buffer and the resulting size (zero padded to the size of the modulus)
       @param which    PK_PUBLIC for public RSA and PK_PRIVATE for private RSA
-      @param key      The RSA key to use 
+      @param key      The RSA key to use
       @return CRYPT_OK on success
    */
    int (*rsa_me)(const unsigned char *in,   unsigned long inlen,
@@ -416,7 +416,7 @@ typedef struct {
 
    /** Modular addition
       @param  a     The first source
-      @param  b     The second source 
+      @param  b     The second source
       @param  c     The modulus
       @param  d     The destination (a + b mod c)
       @return CRYPT_OK on success
@@ -425,7 +425,7 @@ typedef struct {
 
    /** Modular substraction
       @param  a     The first source
-      @param  b     The second source 
+      @param  b     The second source
       @param  c     The modulus
       @param  d     The destination (a - b mod c)
       @return CRYPT_OK on success

+ 2 - 2
src/headers/tomcrypt_misc.h

@@ -1,9 +1,9 @@
 /* ---- LTC_BASE64 Routines ---- */
 #ifdef LTC_BASE64
-int base64_encode(const unsigned char *in,  unsigned long len, 
+int base64_encode(const unsigned char *in,  unsigned long len,
                         unsigned char *out, unsigned long *outlen);
 
-int base64_decode(const unsigned char *in,  unsigned long len, 
+int base64_decode(const unsigned char *in,  unsigned long len,
                         unsigned char *out, unsigned long *outlen);
 #endif
 

+ 49 - 49
src/headers/tomcrypt_pk.h

@@ -32,19 +32,19 @@ typedef struct Rsa_key {
     /** Type of key, PK_PRIVATE or PK_PUBLIC */
     int type;
     /** The public exponent */
-    void *e; 
+    void *e;
     /** The private exponent */
-    void *d; 
+    void *d;
     /** The modulus */
-    void *N; 
+    void *N;
     /** The p factor of N */
-    void *p; 
+    void *p;
     /** The q factor of N */
-    void *q; 
+    void *q;
     /** The 1/q mod p CRT param */
-    void *qP; 
+    void *qP;
     /** The d mod (p - 1) CRT param */
-    void *dP; 
+    void *dP;
     /** The d mod (q - 1) CRT param */
     void *dQ;
 } rsa_key;
@@ -98,7 +98,7 @@ int rsa_verify_hash_ex(const unsigned char *sig,      unsigned long siglen,
 /* LTC_PKCS #1 import/export */
 int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key);
 int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key);
-                        
+
 #endif
 
 /* ---- Katja ---- */
@@ -113,17 +113,17 @@ typedef struct KAT_key {
     /** Type of key, PK_PRIVATE or PK_PUBLIC */
     int type;
     /** The private exponent */
-    void *d; 
+    void *d;
     /** The modulus */
-    void *N; 
+    void *N;
     /** The p factor of N */
-    void *p; 
+    void *p;
     /** The q factor of N */
-    void *q; 
+    void *q;
     /** The 1/q mod p CRT param */
-    void *qP; 
+    void *qP;
     /** The d mod (p - 1) CRT param */
-    void *dP; 
+    void *dP;
     /** The d mod (q - 1) CRT param */
     void *dQ;
     /** The pq param */
@@ -143,9 +143,9 @@ int katja_encrypt_key(const unsigned char *in,     unsigned long inlen,
                             unsigned char *out,    unsigned long *outlen,
                       const unsigned char *lparam, unsigned long lparamlen,
                       prng_state *prng, int prng_idx, int hash_idx, katja_key *key);
-                                        
+
 int katja_decrypt_key(const unsigned char *in,       unsigned long inlen,
-                            unsigned char *out,      unsigned long *outlen, 
+                            unsigned char *out,      unsigned long *outlen,
                       const unsigned char *lparam,   unsigned long lparamlen,
                             int            hash_idx, int *stat,
                             katja_key       *key);
@@ -153,11 +153,11 @@ int katja_decrypt_key(const unsigned char *in,       unsigned long inlen,
 /* LTC_PKCS #1 import/export */
 int katja_export(unsigned char *out, unsigned long *outlen, int type, katja_key *key);
 int katja_import(const unsigned char *in, unsigned long inlen, katja_key *key);
-                        
+
 #endif
 
 /* ---- DH Routines ---- */
-#ifdef MDH 
+#ifdef MDH
 
 typedef struct Dh_key {
     int idx, type;
@@ -179,12 +179,12 @@ int dh_shared_secret(dh_key        *private_key, dh_key        *public_key,
                      unsigned char *out,         unsigned long *outlen);
 
 int dh_encrypt_key(const unsigned char *in,    unsigned long  keylen,
-                         unsigned char *out,   unsigned long *outlen, 
-                         prng_state    *prng,  int wprng, int hash, 
+                         unsigned char *out,   unsigned long *outlen,
+                         prng_state    *prng,  int wprng, int hash,
                          dh_key        *key);
 
-int dh_decrypt_key(const unsigned char *in,  unsigned long  inlen, 
-                         unsigned char *out, unsigned long *outlen, 
+int dh_decrypt_key(const unsigned char *in,  unsigned long  inlen,
+                         unsigned char *out, unsigned long *outlen,
                          dh_key *key);
 
 int dh_sign_hash(const unsigned char *in,   unsigned long inlen,
@@ -192,7 +192,7 @@ int dh_sign_hash(const unsigned char *in,   unsigned long inlen,
                        prng_state    *prng, int wprng, dh_key *key);
 
 int dh_verify_hash(const unsigned char *sig,  unsigned long siglen,
-                   const unsigned char *hash, unsigned long hashlen, 
+                   const unsigned char *hash, unsigned long hashlen,
                    int *stat, dh_key *key);
 
 
@@ -214,7 +214,7 @@ typedef struct {
    int size;
 
    /** name of curve */
-   char *name; 
+   char *name;
 
    /** The prime that defines the field the curve is in (encoded in hex) */
    char *prime;
@@ -224,10 +224,10 @@ typedef struct {
 
    /** The order of the curve (hex) */
    char *order;
-  
+
    /** The x co-ordinate of the base point on the curve (hex) */
    char *Gx;
- 
+
    /** The y co-ordinate of the base point on the curve (hex) */
    char *Gy;
 } ltc_ecc_set_type;
@@ -281,24 +281,24 @@ int ecc_ansi_x963_export(ecc_key *key, unsigned char *out, unsigned long *outlen
 int ecc_ansi_x963_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
 int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, ltc_ecc_set_type *dp);
 
-int  ecc_shared_secret(ecc_key *private_key, ecc_key *public_key, 
+int  ecc_shared_secret(ecc_key *private_key, ecc_key *public_key,
                        unsigned char *out, unsigned long *outlen);
 
 int  ecc_encrypt_key(const unsigned char *in,   unsigned long inlen,
-                           unsigned char *out,  unsigned long *outlen, 
-                           prng_state *prng, int wprng, int hash, 
+                           unsigned char *out,  unsigned long *outlen,
+                           prng_state *prng, int wprng, int hash,
                            ecc_key *key);
 
 int  ecc_decrypt_key(const unsigned char *in,  unsigned long  inlen,
-                           unsigned char *out, unsigned long *outlen, 
+                           unsigned char *out, unsigned long *outlen,
                            ecc_key *key);
 
-int  ecc_sign_hash(const unsigned char *in,  unsigned long inlen, 
-                         unsigned char *out, unsigned long *outlen, 
+int  ecc_sign_hash(const unsigned char *in,  unsigned long inlen,
+                         unsigned char *out, unsigned long *outlen,
                          prng_state *prng, int wprng, ecc_key *key);
 
 int  ecc_verify_hash(const unsigned char *sig,  unsigned long siglen,
-                     const unsigned char *hash, unsigned long hashlen, 
+                     const unsigned char *hash, unsigned long hashlen,
                      int *stat, ecc_key *key);
 
 /* low level functions */
@@ -365,7 +365,7 @@ int ltc_ecc_map(ecc_point *P, void *modulus, void *mp);
 /** DSA key structure */
 typedef struct {
    /** The key type, PK_PRIVATE or PK_PUBLIC */
-   int type; 
+   int type;
 
    /** The order of the sub-group used in octets */
    int qord;
@@ -398,22 +398,22 @@ int dsa_sign_hash(const unsigned char *in,  unsigned long inlen,
                         prng_state *prng, int wprng, dsa_key *key);
 
 int dsa_verify_hash_raw(         void *r,          void *s,
-                    const unsigned char *hash, unsigned long hashlen, 
+                    const unsigned char *hash, unsigned long hashlen,
                                     int *stat,      dsa_key *key);
 
 int dsa_verify_hash(const unsigned char *sig,  unsigned long siglen,
-                    const unsigned char *hash, unsigned long hashlen, 
+                    const unsigned char *hash, unsigned long hashlen,
                           int           *stat, dsa_key       *key);
 
 int dsa_encrypt_key(const unsigned char *in,   unsigned long inlen,
-                          unsigned char *out,  unsigned long *outlen, 
-                          prng_state *prng, int wprng, int hash, 
+                          unsigned char *out,  unsigned long *outlen,
+                          prng_state *prng, int wprng, int hash,
                           dsa_key *key);
-                      
+
 int dsa_decrypt_key(const unsigned char *in,  unsigned long  inlen,
-                          unsigned char *out, unsigned long *outlen, 
+                          unsigned char *out, unsigned long *outlen,
                           dsa_key *key);
-                          
+
 int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key);
 int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key);
 int dsa_verify_key(dsa_key *key, int *stat);
@@ -475,12 +475,12 @@ typedef struct ltc_asn1_list_ {
 /* SEQUENCE */
 int der_encode_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
                            unsigned char *out,  unsigned long *outlen, int type_of);
-                          
-#define der_encode_sequence(list, inlen, out, outlen) der_encode_sequence_ex(list, inlen, out, outlen, LTC_ASN1_SEQUENCE)                        
+
+#define der_encode_sequence(list, inlen, out, outlen) der_encode_sequence_ex(list, inlen, out, outlen, LTC_ASN1_SEQUENCE)
 
 int der_decode_sequence_ex(const unsigned char *in, unsigned long  inlen,
                            ltc_asn1_list *list,     unsigned long  outlen, int ordered);
-                              
+
 #define der_decode_sequence(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, 1)
 
 int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
@@ -503,7 +503,7 @@ int der_encode_set(ltc_asn1_list *list, unsigned long inlen,
 
 int der_encode_setof(ltc_asn1_list *list, unsigned long inlen,
                      unsigned char *out,  unsigned long *outlen);
-                        
+
 /* VA list handy helpers with triplets of <type, size, data> */
 int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...);
 int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...);
@@ -515,10 +515,10 @@ void der_sequence_free(ltc_asn1_list *in);
 
 /* BOOLEAN */
 int der_length_boolean(unsigned long *outlen);
-int der_encode_boolean(int in, 
+int der_encode_boolean(int in,
                        unsigned char *out, unsigned long *outlen);
 int der_decode_boolean(const unsigned char *in, unsigned long inlen,
-                                       int *out);		       
+                                       int *out);
 /* INTEGER */
 int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen);
 int der_decode_integer(const unsigned char *in, unsigned long inlen, void *num);
@@ -584,7 +584,7 @@ int der_printable_char_encode(int c);
 int der_printable_value_decode(int v);
 
 /* UTF-8 */
-#if (defined(SIZE_MAX) || __STDC_VERSION__ >= 199901L || defined(WCHAR_MAX) || defined(_WCHAR_T) || defined(_WCHAR_T_DEFINED) || defined (__WCHAR_TYPE__)) && !defined(LTC_NO_WCHAR) 
+#if (defined(SIZE_MAX) || __STDC_VERSION__ >= 199901L || defined(WCHAR_MAX) || defined(_WCHAR_T) || defined(_WCHAR_T_DEFINED) || defined (__WCHAR_TYPE__)) && !defined(LTC_NO_WCHAR)
 #include <wchar.h>
 #else
 typedef ulong32 wchar_t;
@@ -616,7 +616,7 @@ typedef struct {
             off_mm; /* timezone offset minutes */
 } ltc_utctime;
 
-int der_encode_utctime(ltc_utctime *utctime, 
+int der_encode_utctime(ltc_utctime *utctime,
                        unsigned char *out,   unsigned long *outlen);
 
 int der_decode_utctime(const unsigned char *in, unsigned long *inlen,

+ 9 - 9
src/headers/tomcrypt_pkcs.h

@@ -24,20 +24,20 @@ int pkcs_1_i2osp(void *n, unsigned long modulus_len, unsigned char *out);
 int pkcs_1_os2ip(void *n, unsigned char *in, unsigned long inlen);
 
 /* *** v1.5 padding */
-int pkcs_1_v1_5_encode(const unsigned char *msg, 
+int pkcs_1_v1_5_encode(const unsigned char *msg,
                              unsigned long  msglen,
                              int            block_type,
                              unsigned long  modulus_bitlen,
-                                prng_state *prng, 
+                                prng_state *prng,
                                        int  prng_idx,
-                             unsigned char *out, 
+                             unsigned char *out,
                              unsigned long *outlen);
 
-int pkcs_1_v1_5_decode(const unsigned char *msg, 
+int pkcs_1_v1_5_decode(const unsigned char *msg,
                              unsigned long  msglen,
                                        int  block_type,
                              unsigned long  modulus_bitlen,
-                             unsigned char *out, 
+                             unsigned char *out,
                              unsigned long *outlen,
                                        int *is_valid);
 
@@ -55,7 +55,7 @@ int pkcs_1_oaep_decode(const unsigned char *msg,    unsigned long msglen,
                              int           *res);
 
 int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen,
-                            unsigned long saltlen,  prng_state   *prng,     
+                            unsigned long saltlen,  prng_state   *prng,
                             int           prng_idx, int           hash_idx,
                             unsigned long modulus_bitlen,
                             unsigned char *out,     unsigned long *outlen);
@@ -71,13 +71,13 @@ int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen,
 #ifdef LTC_PKCS_5
 
 /* Algorithm #1 (old) */
-int pkcs_5_alg1(const unsigned char *password, unsigned long password_len, 
-                const unsigned char *salt, 
+int pkcs_5_alg1(const unsigned char *password, unsigned long password_len,
+                const unsigned char *salt,
                 int iteration_count,  int hash_idx,
                 unsigned char *out,   unsigned long *outlen);
 
 /* Algorithm #2 (new) */
-int pkcs_5_alg2(const unsigned char *password, unsigned long password_len, 
+int pkcs_5_alg2(const unsigned char *password, unsigned long password_len,
                 const unsigned char *salt,     unsigned long salt_len,
                 int iteration_count,           int hash_idx,
                 unsigned char *out,            unsigned long *outlen);

+ 7 - 7
src/headers/tomcrypt_prng.h

@@ -23,10 +23,10 @@ struct fortuna_prng {
 
     unsigned char K[32],      /* the current key */
                   IV[16];     /* IV for CTR mode */
-    
+
     unsigned long pool_idx,   /* current pool we will add to */
                   pool0_len,  /* length of 0'th pool */
-                  wd;            
+                  wd;
 
     ulong64       reset_cnt;  /* number of times we have reset */
     LTC_MUTEX_TYPE(prng_lock)
@@ -36,14 +36,14 @@ struct fortuna_prng {
 #ifdef LTC_SOBER128
 struct sober128_prng {
     ulong32      R[17],          /* Working storage for the shift register */
-                 initR[17],      /* saved register contents */ 
+                 initR[17],      /* saved register contents */
                  konst,          /* key dependent constant */
                  sbuf;           /* partial word encryption buffer */
 
     int          nbuf,           /* number of part-word stream bits buffered */
                  flag,           /* first add_entropy call or not? */
                  set;            /* did we call add_entropy to set key? */
-    
+
 };
 #endif
 
@@ -98,7 +98,7 @@ extern struct ltc_prng_descriptor {
         @return CRYPT_OK if successful
     */
     int (*done)(prng_state *prng);
-    /** Export a PRNG state  
+    /** Export a PRNG state
         @param out     [out] The destination for the state
         @param outlen  [in/out] The max size and resulting size of the PRNG state
         @param prng    The PRNG to export
@@ -187,8 +187,8 @@ LTC_MUTEX_PROTO(ltc_prng_mutex)
 /* Slow RNG you **might** be able to use to seed a PRNG with.  Be careful as this
  * might not work on all platforms as planned
  */
-unsigned long rng_get_bytes(unsigned char *out, 
-                            unsigned long outlen, 
+unsigned long rng_get_bytes(unsigned char *out,
+                            unsigned long outlen,
                             void (*callback)(void));
 
 int rng_make_prng(int bits, int wprng, prng_state *prng, void (*callback)(void));