Merge branch 'fix/xtea' into develop

This commit is contained in:
Steffen Jaeckel 2013-03-22 16:08:31 +02:00
commit 9cb6c6b910
20 changed files with 505 additions and 418 deletions

View File

@ -15,7 +15,9 @@ int usage(char *name)
{ {
int x; 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++) { for (x = 0; cipher_descriptor[x].name != NULL; x++) {
printf("%s\n",cipher_descriptor[x].name); printf("%s\n",cipher_descriptor[x].name);
} }
@ -24,8 +26,6 @@ int usage(char *name)
void register_algs(void) void register_algs(void)
{ {
int x;
#ifdef LTC_RIJNDAEL #ifdef LTC_RIJNDAEL
register_cipher (&aes_desc); register_cipher (&aes_desc);
#endif #endif
@ -108,6 +108,27 @@ int main(int argc, char *argv[])
register_algs(); register_algs();
if (argc < 4) { 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]); return usage(argv[0]);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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) int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
{ {
unsigned long x, sum, K[4]; unsigned long x, sum, K[4];
LTC_ARGCHK(key != NULL); LTC_ARGCHK(key != NULL);
LTC_ARGCHK(skey != 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 */ /* load key */
LOAD32L(K[0], key+0); LOAD32H(K[0], key+0);
LOAD32L(K[1], key+4); LOAD32H(K[1], key+4);
LOAD32L(K[2], key+8); LOAD32H(K[2], key+8);
LOAD32L(K[3], key+12); LOAD32H(K[3], key+12);
for (x = sum = 0; x < 32; x++) { for (x = sum = 0; x < 32; x++) {
skey->xtea.A[x] = (sum + K[sum&3]) & 0xFFFFFFFFUL; skey->xtea.A[x] = (sum + K[sum&3]) & 0xFFFFFFFFUL;
sum = (sum + 0x9E3779B9UL) & 0xFFFFFFFFUL; sum = (sum + 0x9E3779B9UL) & 0xFFFFFFFFUL;
skey->xtea.B[x] = (sum + K[(sum>>11)&3]) & 0xFFFFFFFFUL; skey->xtea.B[x] = (sum + K[(sum>>11)&3]) & 0xFFFFFFFFUL;
} }
#ifdef LTC_CLEAN_STACK #ifdef LTC_CLEAN_STACK
zeromem(&K, sizeof(K)); zeromem(&K, sizeof(K));
#endif #endif
return CRYPT_OK; 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(ct != NULL);
LTC_ARGCHK(skey != NULL); LTC_ARGCHK(skey != NULL);
LOAD32L(y, &pt[0]); LOAD32H(y, &pt[0]);
LOAD32L(z, &pt[4]); LOAD32H(z, &pt[4]);
for (r = 0; r < 32; r += 4) { for (r = 0; r < 32; r += 4) {
y = (y + ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r])) & 0xFFFFFFFFUL; y = (y + ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r])) & 0xFFFFFFFFUL;
z = (z + ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[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; 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; z = (z + ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r+3])) & 0xFFFFFFFFUL;
} }
STORE32L(y, &ct[0]); STORE32H(y, &ct[0]);
STORE32L(z, &ct[4]); STORE32H(z, &ct[4]);
return CRYPT_OK; 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 Decrypts a block of text with LTC_XTEA
@param ct The input ciphertext (8 bytes) @param ct The input ciphertext (8 bytes)
@param pt The output plaintext (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 @return CRYPT_OK if successful
*/ */
int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) 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(ct != NULL);
LTC_ARGCHK(skey != NULL); LTC_ARGCHK(skey != NULL);
LOAD32L(y, &ct[0]); LOAD32H(y, &ct[0]);
LOAD32L(z, &ct[4]); LOAD32H(z, &ct[4]);
for (r = 31; r >= 0; r -= 4) { for (r = 31; r >= 0; r -= 4) {
z = (z - ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r])) & 0xFFFFFFFFUL; z = (z - ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r])) & 0xFFFFFFFFUL;
y = (y - ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[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; 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; y = (y - ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r-3])) & 0xFFFFFFFFUL;
} }
STORE32L(y, &pt[0]); STORE32H(y, &pt[0]);
STORE32L(z, &pt[4]); STORE32H(z, &pt[4]);
return CRYPT_OK; return CRYPT_OK;
} }
@ -146,39 +146,105 @@ int xtea_test(void)
{ {
#ifndef LTC_TEST #ifndef LTC_TEST
return CRYPT_NOP; return CRYPT_NOP;
#else #else
static const unsigned char key[16] = static const struct {
{ 0x78, 0x56, 0x34, 0x12, 0xf0, 0xcd, 0xcb, 0x9a, unsigned char key[16], pt[8], ct[8];
0x48, 0x37, 0x26, 0x15, 0xc0, 0xbf, 0xae, 0x9d }; } tests[] = {
static const unsigned char pt[8] = {
{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
static const unsigned char ct[8] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{ 0x75, 0xd7, 0xc5, 0xbf, 0xcf, 0x58, 0xc9, 0x3f }; { 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]; unsigned char tmp[2][8];
symmetric_key skey; symmetric_key skey;
int err, y; 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 ((err = xtea_setup(key, 16, 0, &skey)) != CRYPT_OK) { if (XMEMCMP(tmp[0], tests[i].ct, 8) != 0 || XMEMCMP(tmp[1], tests[i].pt, 8) != 0) {
return err; #if 0
} printf("\n\nTest %d failed\n", i);
xtea_ecb_encrypt(pt, tmp[0], &skey); if (XMEMCMP(tmp[0], tests[i].ct, 8)) {
xtea_ecb_decrypt(tmp[0], tmp[1], &skey); printf("CT: ");
for (i = 0; i < 8; i++) {
if (XMEMCMP(tmp[0], ct, 8) != 0 || XMEMCMP(tmp[1], pt, 8) != 0) { printf("%02x ", tmp[0][i]);
return CRYPT_FAIL_TESTVECTOR; }
} 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 */ /* 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 < 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_encrypt(tmp[0], tmp[0], &skey);
for (y = 0; y < 1000; y++) xtea_ecb_decrypt(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 (y = 0; y < 8; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
} /* for */
return CRYPT_OK; return CRYPT_OK;
#endif #endif
} }
/** Terminate the context /** Terminate the context
@param skey The scheduled key @param skey The scheduled key
*/ */
void xtea_done(symmetric_key *skey) void xtea_done(symmetric_key *skey)
@ -194,7 +260,7 @@ int xtea_keysize(int *keysize)
{ {
LTC_ARGCHK(keysize != NULL); LTC_ARGCHK(keysize != NULL);
if (*keysize < 16) { if (*keysize < 16) {
return CRYPT_INVALID_KEYSIZE; return CRYPT_INVALID_KEYSIZE;
} }
*keysize = 16; *keysize = 16;
return CRYPT_OK; return CRYPT_OK;

View File

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

View File

@ -48,8 +48,8 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2);
#define ARGTYPE 0 #define ARGTYPE 0
#endif #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. * 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** * The x86 platforms allow this but some others [ARM for instance] do not. On those platforms you **MUST**
* use the portable [slower] macros. * 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 ENDIAN_32BITWORD
#define LTC_FAST #define LTC_FAST
#define LTC_FAST_TYPE unsigned long #define LTC_FAST_TYPE unsigned long
#endif #endif
/* detect sparc and sparc64 */ /* detect sparc and sparc64 */
#if defined(__sparc__) #if defined(__sparc__)

View File

@ -1,6 +1,6 @@
/* ---- SYMMETRIC KEY STUFF ----- /* ---- 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. * the key formats in one union. This makes the function prototypes easier to use.
*/ */
#ifdef LTC_BLOWFISH #ifdef LTC_BLOWFISH
@ -109,7 +109,7 @@ struct noekeon_key {
}; };
#endif #endif
#ifdef LTC_SKIPJACK #ifdef LTC_SKIPJACK
struct skipjack_key { struct skipjack_key {
unsigned char key[10]; unsigned char key[10];
}; };
@ -117,18 +117,18 @@ struct skipjack_key {
#ifdef LTC_KHAZAD #ifdef LTC_KHAZAD
struct khazad_key { struct khazad_key {
ulong64 roundKeyEnc[8 + 1]; ulong64 roundKeyEnc[8 + 1];
ulong64 roundKeyDec[8 + 1]; ulong64 roundKeyDec[8 + 1];
}; };
#endif #endif
#ifdef LTC_ANUBIS #ifdef LTC_ANUBIS
struct anubis_key { struct anubis_key {
int keyBits; int keyBits;
int R; int R;
ulong32 roundKeyEnc[18 + 1][4]; ulong32 roundKeyEnc[18 + 1][4];
ulong32 roundKeyDec[18 + 1][4]; ulong32 roundKeyDec[18 + 1][4];
}; };
#endif #endif
#ifdef LTC_MULTI2 #ifdef LTC_MULTI2
@ -182,7 +182,7 @@ typedef union Symmetric_key {
#endif #endif
#ifdef LTC_NOEKEON #ifdef LTC_NOEKEON
struct noekeon_key noekeon; struct noekeon_key noekeon;
#endif #endif
#ifdef LTC_SKIPJACK #ifdef LTC_SKIPJACK
struct skipjack_key skipjack; struct skipjack_key skipjack;
#endif #endif
@ -197,7 +197,7 @@ typedef union Symmetric_key {
#endif #endif
#ifdef LTC_KASUMI #ifdef LTC_KASUMI
struct kasumi_key kasumi; struct kasumi_key kasumi;
#endif #endif
#ifdef LTC_MULTI2 #ifdef LTC_MULTI2
struct multi2_key multi2; struct multi2_key multi2;
#endif #endif
@ -211,10 +211,10 @@ typedef union Symmetric_key {
/** A block cipher ECB structure */ /** A block cipher ECB structure */
typedef struct { typedef struct {
/** The index of the cipher chosen */ /** The index of the cipher chosen */
int cipher, int cipher,
/** The block size of the given cipher */ /** The block size of the given cipher */
blocklen; blocklen;
/** The scheduled key */ /** The scheduled key */
symmetric_key key; symmetric_key key;
} symmetric_ECB; } symmetric_ECB;
#endif #endif
@ -223,14 +223,14 @@ typedef struct {
/** A block cipher CFB structure */ /** A block cipher CFB structure */
typedef struct { typedef struct {
/** The index of the cipher chosen */ /** The index of the cipher chosen */
int cipher, int cipher,
/** The block size of the given cipher */ /** The block size of the given cipher */
blocklen, blocklen,
/** The padding offset */ /** The padding offset */
padlen; padlen;
/** The current IV */ /** The current IV */
unsigned char IV[MAXBLOCKSIZE], unsigned char IV[MAXBLOCKSIZE],
/** The pad used to encrypt/decrypt */ /** The pad used to encrypt/decrypt */
pad[MAXBLOCKSIZE]; pad[MAXBLOCKSIZE];
/** The scheduled key */ /** The scheduled key */
symmetric_key key; symmetric_key key;
@ -241,9 +241,9 @@ typedef struct {
/** A block cipher OFB structure */ /** A block cipher OFB structure */
typedef struct { typedef struct {
/** The index of the cipher chosen */ /** The index of the cipher chosen */
int cipher, int cipher,
/** The block size of the given cipher */ /** The block size of the given cipher */
blocklen, blocklen,
/** The padding offset */ /** The padding offset */
padlen; padlen;
/** The current IV */ /** The current IV */
@ -257,8 +257,8 @@ typedef struct {
/** A block cipher CBC structure */ /** A block cipher CBC structure */
typedef struct { typedef struct {
/** The index of the cipher chosen */ /** The index of the cipher chosen */
int cipher, int cipher,
/** The block size of the given cipher */ /** The block size of the given cipher */
blocklen; blocklen;
/** The current IV */ /** The current IV */
unsigned char IV[MAXBLOCKSIZE]; unsigned char IV[MAXBLOCKSIZE];
@ -273,18 +273,18 @@ typedef struct {
typedef struct { typedef struct {
/** The index of the cipher chosen */ /** The index of the cipher chosen */
int cipher, int cipher,
/** The block size of the given cipher */ /** The block size of the given cipher */
blocklen, blocklen,
/** The padding offset */ /** The padding offset */
padlen, padlen,
/** The mode (endianess) of the CTR, 0==little, 1==big */ /** The mode (endianess) of the CTR, 0==little, 1==big */
mode, mode,
/** counter width */ /** counter width */
ctrlen; ctrlen;
/** The counter */ /** The counter */
unsigned char ctr[MAXBLOCKSIZE], unsigned char ctr[MAXBLOCKSIZE],
/** The pad used to encrypt/decrypt */ /** The pad used to encrypt/decrypt */
pad[MAXBLOCKSIZE]; pad[MAXBLOCKSIZE];
/** The scheduled key */ /** The scheduled key */
symmetric_key key; symmetric_key key;
@ -300,7 +300,7 @@ typedef struct {
/** The current IV */ /** The current IV */
unsigned char IV[16], unsigned char IV[16],
/** the tweak key */ /** the tweak key */
tweak[16], tweak[16],
@ -321,9 +321,9 @@ typedef struct {
/** A block cipher F8 structure */ /** A block cipher F8 structure */
typedef struct { typedef struct {
/** The index of the cipher chosen */ /** The index of the cipher chosen */
int cipher, int cipher,
/** The block size of the given cipher */ /** The block size of the given cipher */
blocklen, blocklen,
/** The padding offset */ /** The padding offset */
padlen; padlen;
/** The current IV */ /** The current IV */
@ -344,14 +344,14 @@ extern struct ltc_cipher_descriptor {
/** internal ID */ /** internal ID */
unsigned char ID; unsigned char ID;
/** min keysize (octets) */ /** min keysize (octets) */
int min_key_length, int min_key_length,
/** max keysize (octets) */ /** max keysize (octets) */
max_key_length, max_key_length,
/** block size (octets) */ /** block size (octets) */
block_length, block_length,
/** default number of rounds */ /** default number of rounds */
default_rounds; default_rounds;
/** Setup the cipher /** Setup the cipher
@param key The input symmetric key @param key The input symmetric key
@param keylen The length of the input key (octets) @param keylen The length of the input key (octets)
@param num_rounds The requested number of rounds (0==default) @param num_rounds The requested number of rounds (0==default)
@ -378,10 +378,10 @@ extern struct ltc_cipher_descriptor {
*/ */
int (*test)(void); int (*test)(void);
/** Terminate the context /** Terminate the context
@param skey The scheduled key @param skey The scheduled key
*/ */
void (*done)(symmetric_key *skey); void (*done)(symmetric_key *skey);
/** Determine a key size /** Determine a key size
@param keysize [in/out] The size of the key desired and the suggested 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); int (*keysize)(int *keysize);
/** Accelerators **/ /** Accelerators **/
/** Accelerated ECB encryption /** Accelerated ECB encryption
@param pt Plaintext @param pt Plaintext
@param ct Ciphertext @param ct Ciphertext
@param blocks The number of complete blocks to process @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); 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 pt Plaintext
@param ct Ciphertext @param ct Ciphertext
@param blocks The number of complete blocks to process @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); 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 pt Plaintext
@param ct Ciphertext @param ct Ciphertext
@param blocks The number of complete blocks to process @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); 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 pt Plaintext
@param ct Ciphertext @param ct Ciphertext
@param blocks The number of complete blocks to process @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); 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 pt Plaintext
@param ct Ciphertext @param ct Ciphertext
@param blocks The number of complete blocks to process @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); 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 pt Plaintext
@param ct Ciphertext @param ct Ciphertext
@param blocks The number of complete blocks to process @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); 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 ct Ciphertext
@param pt Plaintext @param pt Plaintext
@param blocks The number of complete blocks to process @param blocks The number of complete blocks to process
@ -490,7 +490,7 @@ extern struct ltc_cipher_descriptor {
/** Accelerated GCM packet (one shot) /** Accelerated GCM packet (one shot)
@param key The secret key @param key The secret key
@param keylen The length of 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 IVlen The length of the initial vector
@param adata The additional authentication data (header) @param adata The additional authentication data (header)
@param adatalen The length of the adata @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 *IV, unsigned long IVlen,
const unsigned char *adata, unsigned long adatalen, const unsigned char *adata, unsigned long adatalen,
unsigned char *pt, unsigned long ptlen, unsigned char *pt, unsigned long ptlen,
unsigned char *ct, unsigned char *ct,
unsigned char *tag, unsigned long *taglen, unsigned char *tag, unsigned long *taglen,
int direction); int direction);
/** Accelerated one shot LTC_OMAC /** Accelerated one shot LTC_OMAC
@param key The secret key @param key The secret key
@param keylen The key length (octets) @param keylen The key length (octets)
@param in The message @param in The message
@param inlen Length of message (octets) @param inlen Length of message (octets)
@param out [out] Destination for tag @param out [out] Destination for tag
@param outlen [in/out] Initial and final size of out @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, const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen); unsigned char *out, unsigned long *outlen);
/** Accelerated one shot XCBC /** Accelerated one shot XCBC
@param key The secret key @param key The secret key
@param keylen The key length (octets) @param keylen The key length (octets)
@param in The message @param in The message
@param inlen Length of message (octets) @param inlen Length of message (octets)
@param out [out] Destination for tag @param out [out] Destination for tag
@param outlen [in/out] Initial and final size of out @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, const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen); unsigned char *out, unsigned long *outlen);
/** Accelerated one shot F9 /** Accelerated one shot F9
@param key The secret key @param key The secret key
@param keylen The key length (octets) @param keylen The key length (octets)
@param in The message @param in The message
@param inlen Length of message (octets) @param inlen Length of message (octets)
@param out [out] Destination for tag @param out [out] Destination for tag
@param outlen [in/out] Initial and final size of out @param outlen [in/out] Initial and final size of out
@ -777,7 +777,7 @@ extern const struct ltc_cipher_descriptor camellia_desc;
#endif #endif
#ifdef LTC_ECB_MODE #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 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_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); 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 #endif
#ifdef LTC_CFB_MODE #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 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_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); 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 #endif
#ifdef LTC_OFB_MODE #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 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_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); 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 *IV,
const unsigned char *key, int keylen, const unsigned char *key, int keylen,
const unsigned char *tweak, const unsigned char *tweak,
int num_rounds, int num_rounds,
symmetric_LRW *lrw); symmetric_LRW *lrw);
int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, 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); 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 */ /* don't call */
int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw); int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw);
#endif #endif
#ifdef LTC_F8_MODE #ifdef LTC_F8_MODE
int f8_start( int cipher, const unsigned char *IV, int f8_start( int cipher, const unsigned char *IV,
const unsigned char *key, int keylen, const unsigned char *key, int keylen,
const unsigned char *salt_key, int skeylen, const unsigned char *salt_key, int skeylen,
int num_rounds, symmetric_F8 *f8); int num_rounds, symmetric_F8 *f8);
int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, 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; } symmetric_xts;
int xts_start( int cipher, int xts_start( int cipher,
const unsigned char *key1, const unsigned char *key1,
const unsigned char *key2, const unsigned char *key2,
unsigned long keylen, unsigned long keylen,
int num_rounds, int num_rounds,
symmetric_xts *xts); symmetric_xts *xts);
int xts_encrypt( int xts_encrypt(

View File

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

View File

@ -166,7 +166,7 @@ extern struct ltc_hash_descriptor {
@return CRYPT_OK if successful @return CRYPT_OK if successful
*/ */
int (*init)(hash_state *hash); int (*init)(hash_state *hash);
/** Process a block of data /** Process a block of data
@param hash The hash state @param hash The hash state
@param in The data to hash @param in The data to hash
@param inlen The length of the data (octets) @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 */ /* 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, 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); unsigned char *out, unsigned long *outlen);
} hash_descriptor[]; } hash_descriptor[];
@ -329,8 +329,8 @@ int hash_is_valid(int idx);
LTC_MUTEX_PROTO(ltc_hash_mutex) LTC_MUTEX_PROTO(ltc_hash_mutex)
int hash_memory(int hash, int hash_memory(int hash,
const unsigned char *in, unsigned long inlen, const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen); unsigned char *out, unsigned long *outlen);
int hash_memory_multi(int hash, 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, ...); const unsigned char *in, unsigned long inlen, ...);

View File

@ -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_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_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen);
int hmac_test(void); int hmac_test(void);
int hmac_memory(int hash, int hmac_memory(int hash,
const unsigned char *key, unsigned long keylen, 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); 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, const unsigned char *key, unsigned long keylen,
unsigned char *out, unsigned long *outlen, unsigned char *out, unsigned long *outlen,
const unsigned char *in, unsigned long inlen, ...); const unsigned char *in, unsigned long inlen, ...);
int hmac_file(int hash, const char *fname, const unsigned char *key, int hmac_file(int hash, const char *fname, const unsigned char *key,
unsigned long keylen, unsigned long keylen,
unsigned char *dst, unsigned long *dstlen); unsigned char *dst, unsigned long *dstlen);
#endif #endif
#ifdef LTC_OMAC #ifdef LTC_OMAC
typedef struct { typedef struct {
int cipher_idx, int cipher_idx,
buflen, buflen,
blklen; blklen;
unsigned char block[MAXBLOCKSIZE], 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_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_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_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 *key, unsigned long keylen,
const unsigned char *in, unsigned long inlen, const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen); 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, const unsigned char *key, unsigned long keylen,
unsigned char *out, unsigned long *outlen, unsigned char *out, unsigned long *outlen,
const unsigned char *in, unsigned long inlen, ...); 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 unsigned char *key, unsigned long keylen,
const char *filename, const char *filename,
unsigned char *out, unsigned long *outlen); unsigned char *out, unsigned long *outlen);
int omac_test(void); int omac_test(void);
#endif /* LTC_OMAC */ #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_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_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 *key, unsigned long keylen,
const unsigned char *msg, unsigned long msglen, const unsigned char *msg, unsigned long msglen,
unsigned char *out, unsigned long *outlen); 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, const unsigned char *key, unsigned long keylen,
unsigned char *out, unsigned long *outlen, unsigned char *out, unsigned long *outlen,
const unsigned char *in, unsigned long inlen, ...); 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 unsigned char *key, unsigned long keylen,
const char *filename, const char *filename,
unsigned char *out, unsigned long *outlen); unsigned char *out, unsigned long *outlen);
int pmac_test(void); int pmac_test(void);
@ -152,32 +152,32 @@ typedef struct {
block_len; /* length of block */ block_len; /* length of block */
} ocb_state; } 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); 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_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_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, const unsigned char *pt, unsigned long ptlen,
unsigned char *ct, unsigned char *ct,
unsigned char *tag, unsigned long *taglen); 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, const unsigned char *ct, unsigned long ctlen,
unsigned char *pt, unsigned char *pt,
const unsigned char *tag, unsigned long taglen, int *stat); const unsigned char *tag, unsigned long taglen, int *stat);
int ocb_encrypt_authenticate_memory(int cipher, int ocb_encrypt_authenticate_memory(int cipher,
const unsigned char *key, unsigned long keylen, const unsigned char *key, unsigned long keylen,
const unsigned char *nonce, const unsigned char *nonce,
const unsigned char *pt, unsigned long ptlen, const unsigned char *pt, unsigned long ptlen,
unsigned char *ct, unsigned char *ct,
unsigned char *tag, unsigned long *taglen); unsigned char *tag, unsigned long *taglen);
int ocb_decrypt_verify_memory(int cipher, int ocb_decrypt_verify_memory(int cipher,
const unsigned char *key, unsigned long keylen, const unsigned char *key, unsigned long keylen,
const unsigned char *nonce, const unsigned char *nonce,
const unsigned char *ct, unsigned long ctlen, const unsigned char *ct, unsigned long ctlen,
unsigned char *pt, unsigned char *pt,
const unsigned char *tag, unsigned long taglen, 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_AAD 1
#define LTC_GCM_MODE_TEXT 2 #define LTC_GCM_MODE_TEXT 2
typedef struct { typedef struct {
symmetric_key K; symmetric_key K;
unsigned char H[16], /* multiplier */ unsigned char H[16], /* multiplier */
X[16], /* accumulator */ X[16], /* accumulator */
@ -327,7 +327,7 @@ typedef struct {
__attribute__ ((aligned (16))) __attribute__ ((aligned (16)))
#endif #endif
; ;
#endif #endif
} gcm_state; } gcm_state;
void gcm_mult_h(gcm_state *gcm, unsigned char *I); 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_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); const unsigned char *IV, unsigned long IVlen);
int gcm_add_aad(gcm_state *gcm, int gcm_add_aad(gcm_state *gcm,
@ -348,7 +348,7 @@ int gcm_process(gcm_state *gcm,
unsigned char *ct, unsigned char *ct,
int direction); int direction);
int gcm_done(gcm_state *gcm, int gcm_done(gcm_state *gcm,
unsigned char *tag, unsigned long *taglen); unsigned char *tag, unsigned long *taglen);
int gcm_memory( int cipher, int gcm_memory( int cipher,
@ -356,7 +356,7 @@ int gcm_memory( int cipher,
const unsigned char *IV, unsigned long IVlen, const unsigned char *IV, unsigned long IVlen,
const unsigned char *adata, unsigned long adatalen, const unsigned char *adata, unsigned long adatalen,
unsigned char *pt, unsigned long ptlen, unsigned char *pt, unsigned long ptlen,
unsigned char *ct, unsigned char *ct,
unsigned char *tag, unsigned long *taglen, unsigned char *tag, unsigned long *taglen,
int direction); int direction);
int gcm_test(void); 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_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_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_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 *key, unsigned long keylen,
const unsigned char *in, unsigned long inlen, const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen); 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, const unsigned char *key, unsigned long keylen,
unsigned char *out, unsigned long *outlen, unsigned char *out, unsigned long *outlen,
const unsigned char *in, unsigned long inlen, ...); 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 unsigned char *key, unsigned long keylen,
const char *filename, const char *filename,
unsigned char *out, unsigned long *outlen); unsigned char *out, unsigned long *outlen);
int xcbc_test(void); 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_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_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_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 *key, unsigned long keylen,
const unsigned char *in, unsigned long inlen, const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen); 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, const unsigned char *key, unsigned long keylen,
unsigned char *out, unsigned long *outlen, unsigned char *out, unsigned long *outlen,
const unsigned char *in, unsigned long inlen, ...); 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 unsigned char *key, unsigned long keylen,
const char *filename, const char *filename,
unsigned char *out, unsigned long *outlen); unsigned char *out, unsigned long *outlen);
int f9_test(void); int f9_test(void);

View File

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

View File

@ -30,15 +30,15 @@ typedef struct {
@return CRYPT_OK on success @return CRYPT_OK on success
*/ */
int (*init)(void **a); int (*init)(void **a);
/** init copy /** init copy
@param dst The number to initialize and write to @param dst The number to initialize and write to
@param src The number to copy from @param src The number to copy from
@return CRYPT_OK on success @return CRYPT_OK on success
*/ */
int (*init_copy)(void **dst, void *src); int (*init_copy)(void **dst, void *src);
/** deinit /** deinit
@param a The number to free @param a The number to free
@return CRYPT_OK on success @return CRYPT_OK on success
*/ */
@ -52,30 +52,30 @@ typedef struct {
@return CRYPT_OK on success @return CRYPT_OK on success
*/ */
int (*neg)(void *src, void *dst); int (*neg)(void *src, void *dst);
/** copy /** copy
@param src The number to copy from @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 @return CRYPT_OK on success
*/ */
int (*copy)(void *src, void *dst); int (*copy)(void *src, void *dst);
/* ---- trivial low level functions ---- */ /* ---- trivial low level functions ---- */
/** set small constant /** set small constant
@param a Number to write to @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 @return CRYPT_OK on succcess
*/ */
int (*set_int)(void *a, unsigned long n); 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 @param a Number to read, only fetches upto bits_per_digit from the number
@return The lower bits_per_digit of the integer (unsigned) @return The lower bits_per_digit of the integer (unsigned)
*/ */
unsigned long (*get_int)(void *a); unsigned long (*get_int)(void *a);
/** get digit n /** get digit n
@param a The number to read from @param a The number to read from
@param n The number of the digit to fetch @param n The number of the digit to fetch
@return The bits_per_digit sized n'th digit of a @return The bits_per_digit sized n'th digit of a
@ -95,7 +95,7 @@ typedef struct {
*/ */
int (*compare)(void *a, void *b); int (*compare)(void *a, void *b);
/** compare against int /** compare against int
@param a The left side integer @param a The left side integer
@param b The right side integer (upto bits_per_digit) @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) @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); 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 @param a The integer to count
@return The number of contiguous zero LSB bits @return The number of contiguous zero LSB bits
*/ */
@ -122,8 +122,8 @@ typedef struct {
int (*twoexpt)(void *a , int n); int (*twoexpt)(void *a , int n);
/* ---- radix conversions ---- */ /* ---- radix conversions ---- */
/** read ascii string /** read ascii string
@param a The integer to store into @param a The integer to store into
@param str The string to read @param str The string to read
@param radix The radix the integer has been represented in (2-64) @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); 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) @param a The integer to get the size (when stored in array of octets)
@return The length of the integer @return The length of the integer
*/ */
unsigned long (*unsigned_size)(void *a); 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 src The integer to store
@param dst The buffer to store the integer in @param dst The buffer to store the integer in
@return CRYPT_OK on success @return CRYPT_OK on success
@ -154,15 +154,15 @@ typedef struct {
/** read an array of octets and store as integer /** read an array of octets and store as integer
@param dst The integer to load @param dst The integer to load
@param src The array of octets @param src The array of octets
@param len The number of octets @param len The number of octets
@return CRYPT_OK on success @return CRYPT_OK on success
*/ */
int (*unsigned_read)(void *dst, unsigned char *src, unsigned long len); int (*unsigned_read)(void *dst, unsigned char *src, unsigned long len);
/* ---- basic math ---- */ /* ---- basic math ---- */
/** add two integers /** add two integers
@param a The first source integer @param a The first source integer
@param b The second source integer @param b The second source integer
@param c The destination of "a + b" @param c The destination of "a + b"
@ -171,7 +171,7 @@ typedef struct {
int (*add)(void *a, void *b, void *c); int (*add)(void *a, void *b, void *c);
/** add two integers /** add two integers
@param a The first source integer @param a The first source integer
@param b The second source integer (single digit of upto bits_per_digit in length) @param b The second source integer (single digit of upto bits_per_digit in length)
@param c The destination of "a + b" @param c The destination of "a + b"
@ -179,7 +179,7 @@ typedef struct {
*/ */
int (*addi)(void *a, unsigned long b, void *c); int (*addi)(void *a, unsigned long b, void *c);
/** subtract two integers /** subtract two integers
@param a The first source integer @param a The first source integer
@param b The second source integer @param b The second source integer
@param c The destination of "a - b" @param c The destination of "a - b"
@ -187,7 +187,7 @@ typedef struct {
*/ */
int (*sub)(void *a, void *b, void *c); int (*sub)(void *a, void *b, void *c);
/** subtract two integers /** subtract two integers
@param a The first source integer @param a The first source integer
@param b The second source integer (single digit of upto bits_per_digit in length) @param b The second source integer (single digit of upto bits_per_digit in length)
@param c The destination of "a - b" @param c The destination of "a - b"
@ -195,7 +195,7 @@ typedef struct {
*/ */
int (*subi)(void *a, unsigned long b, void *c); int (*subi)(void *a, unsigned long b, void *c);
/** multiply two integers /** multiply two integers
@param a The first source integer @param a The first source integer
@param b The second source integer (single digit of upto bits_per_digit in length) @param b The second source integer (single digit of upto bits_per_digit in length)
@param c The destination of "a * b" @param c The destination of "a * b"
@ -203,7 +203,7 @@ typedef struct {
*/ */
int (*mul)(void *a, void *b, void *c); int (*mul)(void *a, void *b, void *c);
/** multiply two integers /** multiply two integers
@param a The first source integer @param a The first source integer
@param b The second source integer (single digit of upto bits_per_digit in length) @param b The second source integer (single digit of upto bits_per_digit in length)
@param c The destination of "a * b" @param c The destination of "a * b"
@ -227,9 +227,9 @@ typedef struct {
*/ */
int (*mpdiv)(void *a, void *b, void *c, void *d); 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 a The integer to divide (shift right)
@param b The destination @param b The destination
@return CRYPT_OK on success @return CRYPT_OK on success
*/ */
int (*div_2)(void *a, void *b); int (*div_2)(void *a, void *b);
@ -242,7 +242,7 @@ typedef struct {
*/ */
int (*modi)(void *a, unsigned long b, unsigned long *c); int (*modi)(void *a, unsigned long b, unsigned long *c);
/** gcd /** gcd
@param a The first integer @param a The first integer
@param b The second integer @param b The second integer
@param c The destination for (a, b) @param c The destination for (a, b)
@ -250,7 +250,7 @@ typedef struct {
*/ */
int (*gcd)(void *a, void *b, void *c); int (*gcd)(void *a, void *b, void *c);
/** lcm /** lcm
@param a The first integer @param a The first integer
@param b The second integer @param b The second integer
@param c The destination for [a, b] @param c The destination for [a, b]
@ -260,7 +260,7 @@ typedef struct {
/** Modular multiplication /** Modular multiplication
@param a The first source @param a The first source
@param b The second source @param b The second source
@param c The modulus @param c The modulus
@param d The destination (a*b mod c) @param d The destination (a*b mod c)
@return CRYPT_OK on success @return CRYPT_OK on success
@ -277,7 +277,7 @@ typedef struct {
/** Modular inversion /** Modular inversion
@param a The value to invert @param a The value to invert
@param b The modulus @param b The modulus
@param c The destination (1/a mod b) @param c The destination (1/a mod b)
@return CRYPT_OK on success @return CRYPT_OK on success
*/ */
@ -286,13 +286,13 @@ typedef struct {
/* ---- reduction ---- */ /* ---- reduction ---- */
/** setup montgomery /** setup montgomery
@param a The modulus @param a The modulus
@param b The destination for the reduction digit @param b The destination for the reduction digit
@return CRYPT_OK on success @return CRYPT_OK on success
*/ */
int (*montgomery_setup)(void *a, void **b); int (*montgomery_setup)(void *a, void **b);
/** get normalization value /** get normalization value
@param a The destination for the normalization value @param a The destination for the normalization value
@param b The modulus @param b The modulus
@return CRYPT_OK on success @return CRYPT_OK on success
@ -310,7 +310,7 @@ typedef struct {
/** clean up (frees memory) /** clean up (frees memory)
@param a The value "b" from montgomery_setup() @param a The value "b" from montgomery_setup()
@return CRYPT_OK on success @return CRYPT_OK on success
*/ */
void (*montgomery_deinit)(void *a); void (*montgomery_deinit)(void *a);
/* ---- exponentiation ---- */ /* ---- exponentiation ---- */
@ -336,14 +336,14 @@ typedef struct {
/** ECC GF(p) point multiplication (from the NIST curves) /** ECC GF(p) point multiplication (from the NIST curves)
@param k The integer to multiply the point by @param k The integer to multiply the point by
@param G The point to multiply @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 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) @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 @return CRYPT_OK on success
*/ */
int (*ecc_ptmul)(void *k, ecc_point *G, ecc_point *R, void *modulus, int map); 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 P The first point
@param Q The second point @param Q The second point
@param R The destination of P + Q @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); 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 P The first point
@param R The destination of 2P @param R The destination of 2P
@param modulus The modulus @param modulus The modulus
@ -367,7 +367,7 @@ typedef struct {
@param modulus The modulus @param modulus The modulus
@param mp The "b" value from montgomery_setup() @param mp The "b" value from montgomery_setup()
@return CRYPT_OK on success @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. 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); int (*ecc_map)(ecc_point *P, void *modulus, void *mp);
@ -378,9 +378,9 @@ typedef struct {
@param B Second point to multiply @param B Second point to multiply
@param kB What to multiple B by @param kB What to multiple B by
@param C [out] Destination point (can overlap with A or B @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 @return CRYPT_OK on success
*/ */
int (*ecc_mul2add)(ecc_point *A, void *kA, int (*ecc_mul2add)(ecc_point *A, void *kA,
ecc_point *B, void *kB, ecc_point *B, void *kB,
ecc_point *C, ecc_point *C,
@ -388,7 +388,7 @@ typedef struct {
/* ---- (optional) rsa optimized math (for internal CRT) ---- */ /* ---- (optional) rsa optimized math (for internal CRT) ---- */
/** RSA Key Generation /** RSA Key Generation
@param prng An active PRNG state @param prng An active PRNG state
@param wprng The index of the PRNG desired @param wprng The index of the PRNG desired
@param size The size of the modulus (key size) desired (octets) @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 @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); int (*rsa_keygen)(prng_state *prng, int wprng, int size, long e, rsa_key *key);
/** RSA exponentiation /** RSA exponentiation
@param in The octet array representing the base @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 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 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 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 @return CRYPT_OK on success
*/ */
int (*rsa_me)(const unsigned char *in, unsigned long inlen, int (*rsa_me)(const unsigned char *in, unsigned long inlen,
@ -416,7 +416,7 @@ typedef struct {
/** Modular addition /** Modular addition
@param a The first source @param a The first source
@param b The second source @param b The second source
@param c The modulus @param c The modulus
@param d The destination (a + b mod c) @param d The destination (a + b mod c)
@return CRYPT_OK on success @return CRYPT_OK on success
@ -425,7 +425,7 @@ typedef struct {
/** Modular substraction /** Modular substraction
@param a The first source @param a The first source
@param b The second source @param b The second source
@param c The modulus @param c The modulus
@param d The destination (a - b mod c) @param d The destination (a - b mod c)
@return CRYPT_OK on success @return CRYPT_OK on success

View File

@ -1,9 +1,9 @@
/* ---- LTC_BASE64 Routines ---- */ /* ---- LTC_BASE64 Routines ---- */
#ifdef LTC_BASE64 #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); 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); unsigned char *out, unsigned long *outlen);
#endif #endif

View File

@ -32,19 +32,19 @@ typedef struct Rsa_key {
/** Type of key, PK_PRIVATE or PK_PUBLIC */ /** Type of key, PK_PRIVATE or PK_PUBLIC */
int type; int type;
/** The public exponent */ /** The public exponent */
void *e; void *e;
/** The private exponent */ /** The private exponent */
void *d; void *d;
/** The modulus */ /** The modulus */
void *N; void *N;
/** The p factor of N */ /** The p factor of N */
void *p; void *p;
/** The q factor of N */ /** The q factor of N */
void *q; void *q;
/** The 1/q mod p CRT param */ /** The 1/q mod p CRT param */
void *qP; void *qP;
/** The d mod (p - 1) CRT param */ /** The d mod (p - 1) CRT param */
void *dP; void *dP;
/** The d mod (q - 1) CRT param */ /** The d mod (q - 1) CRT param */
void *dQ; void *dQ;
} rsa_key; } rsa_key;
@ -98,7 +98,7 @@ int rsa_verify_hash_ex(const unsigned char *sig, unsigned long siglen,
/* LTC_PKCS #1 import/export */ /* LTC_PKCS #1 import/export */
int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key); 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); int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key);
#endif #endif
/* ---- Katja ---- */ /* ---- Katja ---- */
@ -113,17 +113,17 @@ typedef struct KAT_key {
/** Type of key, PK_PRIVATE or PK_PUBLIC */ /** Type of key, PK_PRIVATE or PK_PUBLIC */
int type; int type;
/** The private exponent */ /** The private exponent */
void *d; void *d;
/** The modulus */ /** The modulus */
void *N; void *N;
/** The p factor of N */ /** The p factor of N */
void *p; void *p;
/** The q factor of N */ /** The q factor of N */
void *q; void *q;
/** The 1/q mod p CRT param */ /** The 1/q mod p CRT param */
void *qP; void *qP;
/** The d mod (p - 1) CRT param */ /** The d mod (p - 1) CRT param */
void *dP; void *dP;
/** The d mod (q - 1) CRT param */ /** The d mod (q - 1) CRT param */
void *dQ; void *dQ;
/** The pq param */ /** The pq param */
@ -143,9 +143,9 @@ int katja_encrypt_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, const unsigned char *lparam, unsigned long lparamlen,
prng_state *prng, int prng_idx, int hash_idx, katja_key *key); prng_state *prng, int prng_idx, int hash_idx, katja_key *key);
int katja_decrypt_key(const unsigned char *in, unsigned long inlen, 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, const unsigned char *lparam, unsigned long lparamlen,
int hash_idx, int *stat, int hash_idx, int *stat,
katja_key *key); katja_key *key);
@ -153,11 +153,11 @@ int katja_decrypt_key(const unsigned char *in, unsigned long inlen,
/* LTC_PKCS #1 import/export */ /* LTC_PKCS #1 import/export */
int katja_export(unsigned char *out, unsigned long *outlen, int type, katja_key *key); 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); int katja_import(const unsigned char *in, unsigned long inlen, katja_key *key);
#endif #endif
/* ---- DH Routines ---- */ /* ---- DH Routines ---- */
#ifdef MDH #ifdef MDH
typedef struct Dh_key { typedef struct Dh_key {
int idx, type; 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); unsigned char *out, unsigned long *outlen);
int dh_encrypt_key(const unsigned char *in, unsigned long keylen, int dh_encrypt_key(const unsigned char *in, unsigned long keylen,
unsigned char *out, unsigned long *outlen, unsigned char *out, unsigned long *outlen,
prng_state *prng, int wprng, int hash, prng_state *prng, int wprng, int hash,
dh_key *key); dh_key *key);
int dh_decrypt_key(const unsigned char *in, unsigned long inlen, int dh_decrypt_key(const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen, unsigned char *out, unsigned long *outlen,
dh_key *key); dh_key *key);
int dh_sign_hash(const unsigned char *in, unsigned long inlen, 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); prng_state *prng, int wprng, dh_key *key);
int dh_verify_hash(const unsigned char *sig, unsigned long siglen, 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); int *stat, dh_key *key);
@ -214,7 +214,7 @@ typedef struct {
int size; int size;
/** name of curve */ /** name of curve */
char *name; char *name;
/** The prime that defines the field the curve is in (encoded in hex) */ /** The prime that defines the field the curve is in (encoded in hex) */
char *prime; char *prime;
@ -224,10 +224,10 @@ typedef struct {
/** The order of the curve (hex) */ /** The order of the curve (hex) */
char *order; char *order;
/** The x co-ordinate of the base point on the curve (hex) */ /** The x co-ordinate of the base point on the curve (hex) */
char *Gx; char *Gx;
/** The y co-ordinate of the base point on the curve (hex) */ /** The y co-ordinate of the base point on the curve (hex) */
char *Gy; char *Gy;
} ltc_ecc_set_type; } 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(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_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); unsigned char *out, unsigned long *outlen);
int ecc_encrypt_key(const unsigned char *in, unsigned long inlen, int ecc_encrypt_key(const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen, unsigned char *out, unsigned long *outlen,
prng_state *prng, int wprng, int hash, prng_state *prng, int wprng, int hash,
ecc_key *key); ecc_key *key);
int ecc_decrypt_key(const unsigned char *in, unsigned long inlen, 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); ecc_key *key);
int ecc_sign_hash(const unsigned char *in, unsigned long inlen, int ecc_sign_hash(const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen, unsigned char *out, unsigned long *outlen,
prng_state *prng, int wprng, ecc_key *key); prng_state *prng, int wprng, ecc_key *key);
int ecc_verify_hash(const unsigned char *sig, unsigned long siglen, 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); int *stat, ecc_key *key);
/* low level functions */ /* low level functions */
@ -365,7 +365,7 @@ int ltc_ecc_map(ecc_point *P, void *modulus, void *mp);
/** DSA key structure */ /** DSA key structure */
typedef struct { typedef struct {
/** The key type, PK_PRIVATE or PK_PUBLIC */ /** The key type, PK_PRIVATE or PK_PUBLIC */
int type; int type;
/** The order of the sub-group used in octets */ /** The order of the sub-group used in octets */
int qord; 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); prng_state *prng, int wprng, dsa_key *key);
int dsa_verify_hash_raw( void *r, void *s, 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 *stat, dsa_key *key);
int dsa_verify_hash(const unsigned char *sig, unsigned long siglen, 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 *stat, dsa_key *key);
int dsa_encrypt_key(const unsigned char *in, unsigned long inlen, int dsa_encrypt_key(const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen, unsigned char *out, unsigned long *outlen,
prng_state *prng, int wprng, int hash, prng_state *prng, int wprng, int hash,
dsa_key *key); dsa_key *key);
int dsa_decrypt_key(const unsigned char *in, unsigned long inlen, 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); dsa_key *key);
int dsa_import(const unsigned char *in, unsigned long inlen, 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_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key);
int dsa_verify_key(dsa_key *key, int *stat); int dsa_verify_key(dsa_key *key, int *stat);
@ -475,12 +475,12 @@ typedef struct ltc_asn1_list_ {
/* SEQUENCE */ /* SEQUENCE */
int der_encode_sequence_ex(ltc_asn1_list *list, unsigned long inlen, int der_encode_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
unsigned char *out, unsigned long *outlen, int type_of); 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, int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
ltc_asn1_list *list, unsigned long outlen, int ordered); 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) #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, 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, int der_encode_setof(ltc_asn1_list *list, unsigned long inlen,
unsigned char *out, unsigned long *outlen); unsigned char *out, unsigned long *outlen);
/* VA list handy helpers with triplets of <type, size, data> */ /* VA list handy helpers with triplets of <type, size, data> */
int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...); int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...);
int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...); 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 */ /* BOOLEAN */
int der_length_boolean(unsigned long *outlen); 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); unsigned char *out, unsigned long *outlen);
int der_decode_boolean(const unsigned char *in, unsigned long inlen, int der_decode_boolean(const unsigned char *in, unsigned long inlen,
int *out); int *out);
/* INTEGER */ /* INTEGER */
int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen); 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); 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); int der_printable_value_decode(int v);
/* UTF-8 */ /* 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> #include <wchar.h>
#else #else
typedef ulong32 wchar_t; typedef ulong32 wchar_t;
@ -616,7 +616,7 @@ typedef struct {
off_mm; /* timezone offset minutes */ off_mm; /* timezone offset minutes */
} ltc_utctime; } ltc_utctime;
int der_encode_utctime(ltc_utctime *utctime, int der_encode_utctime(ltc_utctime *utctime,
unsigned char *out, unsigned long *outlen); unsigned char *out, unsigned long *outlen);
int der_decode_utctime(const unsigned char *in, unsigned long *inlen, int der_decode_utctime(const unsigned char *in, unsigned long *inlen,

View File

@ -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); int pkcs_1_os2ip(void *n, unsigned char *in, unsigned long inlen);
/* *** v1.5 padding */ /* *** 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, unsigned long msglen,
int block_type, int block_type,
unsigned long modulus_bitlen, unsigned long modulus_bitlen,
prng_state *prng, prng_state *prng,
int prng_idx, int prng_idx,
unsigned char *out, unsigned char *out,
unsigned long *outlen); 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, unsigned long msglen,
int block_type, int block_type,
unsigned long modulus_bitlen, unsigned long modulus_bitlen,
unsigned char *out, unsigned char *out,
unsigned long *outlen, unsigned long *outlen,
int *is_valid); int *is_valid);
@ -55,7 +55,7 @@ int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
int *res); int *res);
int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen, 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, int prng_idx, int hash_idx,
unsigned long modulus_bitlen, unsigned long modulus_bitlen,
unsigned char *out, unsigned long *outlen); 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 #ifdef LTC_PKCS_5
/* Algorithm #1 (old) */ /* Algorithm #1 (old) */
int pkcs_5_alg1(const unsigned char *password, unsigned long password_len, int pkcs_5_alg1(const unsigned char *password, unsigned long password_len,
const unsigned char *salt, const unsigned char *salt,
int iteration_count, int hash_idx, int iteration_count, int hash_idx,
unsigned char *out, unsigned long *outlen); unsigned char *out, unsigned long *outlen);
/* Algorithm #2 (new) */ /* 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, const unsigned char *salt, unsigned long salt_len,
int iteration_count, int hash_idx, int iteration_count, int hash_idx,
unsigned char *out, unsigned long *outlen); unsigned char *out, unsigned long *outlen);

View File

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