Mercurial > dropbear
comparison libtomcrypt/src/ciphers/des.c @ 1471:6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 09 Feb 2018 21:44:05 +0800 |
parents | f849a5ca2efc |
children | 1ff2a1034c52 |
comparison
equal
deleted
inserted
replaced
1470:8bba51a55704 | 1471:6dba84798cd5 |
---|---|
3 * LibTomCrypt is a library that provides various cryptographic | 3 * LibTomCrypt is a library that provides various cryptographic |
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | |
9 * Tom St Denis, [email protected], http://libtom.org | |
10 */ | 8 */ |
11 #include "tomcrypt.h" | 9 #include "tomcrypt.h" |
12 | 10 |
13 /** | 11 /** |
14 @file des.c | 12 @file des.c |
15 LTC_DES code submitted by Dobes Vandermeer | 13 DES code submitted by Dobes Vandermeer |
16 */ | 14 */ |
17 | 15 |
18 #ifdef LTC_DES | 16 #ifdef LTC_DES |
19 | 17 |
20 #define EN0 0 | 18 #define EN0 0 |
30 &des_ecb_encrypt, | 28 &des_ecb_encrypt, |
31 &des_ecb_decrypt, | 29 &des_ecb_decrypt, |
32 &des_test, | 30 &des_test, |
33 &des_done, | 31 &des_done, |
34 &des_keysize, | 32 &des_keysize, |
35 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL | 33 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL |
36 }; | 34 }; |
37 #endif | 35 #endif |
38 | 36 |
39 const struct ltc_cipher_descriptor des3_desc = | 37 const struct ltc_cipher_descriptor des3_desc = |
40 { | 38 { |
45 &des3_ecb_encrypt, | 43 &des3_ecb_encrypt, |
46 &des3_ecb_decrypt, | 44 &des3_ecb_decrypt, |
47 &des3_test, | 45 &des3_test, |
48 &des3_done, | 46 &des3_done, |
49 &des3_keysize, | 47 &des3_keysize, |
50 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL | 48 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL |
51 }; | 49 }; |
52 | 50 |
53 static const ulong32 bytebit[8] = | 51 static const ulong32 bytebit[8] = |
54 { | 52 { |
55 0200, 0100, 040, 020, 010, 04, 02, 01 | 53 0200, 0100, 040, 020, 010, 04, 02, 01 |
1385 *cook |= (*raw0 & 0x0000003fL) << 16; | 1383 *cook |= (*raw0 & 0x0000003fL) << 16; |
1386 *cook |= (*raw1 & 0x0003f000L) >> 4; | 1384 *cook |= (*raw1 & 0x0003f000L) >> 4; |
1387 *cook++ |= (*raw1 & 0x0000003fL); | 1385 *cook++ |= (*raw1 & 0x0000003fL); |
1388 } | 1386 } |
1389 | 1387 |
1390 XMEMCPY(keyout, dough, sizeof dough); | 1388 XMEMCPY(keyout, dough, sizeof(dough)); |
1391 } | 1389 } |
1392 | 1390 |
1393 #ifdef LTC_CLEAN_STACK | 1391 #ifdef LTC_CLEAN_STACK |
1394 static void cookey(const ulong32 *raw1, ulong32 *keyout) | 1392 static void cookey(const ulong32 *raw1, ulong32 *keyout) |
1395 { | 1393 { |
1564 | 1562 |
1565 if(num_rounds != 0 && num_rounds != 16) { | 1563 if(num_rounds != 0 && num_rounds != 16) { |
1566 return CRYPT_INVALID_ROUNDS; | 1564 return CRYPT_INVALID_ROUNDS; |
1567 } | 1565 } |
1568 | 1566 |
1569 if (keylen != 24) { | 1567 if (keylen != 24 && keylen != 16) { |
1570 return CRYPT_INVALID_KEYSIZE; | 1568 return CRYPT_INVALID_KEYSIZE; |
1571 } | 1569 } |
1572 | 1570 |
1573 deskey(key, EN0, skey->des3.ek[0]); | 1571 deskey(key, EN0, skey->des3.ek[0]); |
1574 deskey(key+8, DE1, skey->des3.ek[1]); | 1572 deskey(key+8, DE1, skey->des3.ek[1]); |
1573 if (keylen == 24) { | |
1575 deskey(key+16, EN0, skey->des3.ek[2]); | 1574 deskey(key+16, EN0, skey->des3.ek[2]); |
1575 } else { | |
1576 /* two-key 3DES: K3=K1 */ | |
1577 deskey(key, EN0, skey->des3.ek[2]); | |
1578 } | |
1576 | 1579 |
1577 deskey(key, DE1, skey->des3.dk[2]); | 1580 deskey(key, DE1, skey->des3.dk[2]); |
1578 deskey(key+8, EN0, skey->des3.dk[1]); | 1581 deskey(key+8, EN0, skey->des3.dk[1]); |
1582 if (keylen == 24) { | |
1579 deskey(key+16, DE1, skey->des3.dk[0]); | 1583 deskey(key+16, DE1, skey->des3.dk[0]); |
1584 } else { | |
1585 /* two-key 3DES: K3=K1 */ | |
1586 deskey(key, DE1, skey->des3.dk[0]); | |
1587 } | |
1580 | 1588 |
1581 return CRYPT_OK; | 1589 return CRYPT_OK; |
1582 } | 1590 } |
1583 | 1591 |
1584 #if 0 | 1592 #if 0 |
1745 { 9, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | 1753 { 9, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, |
1746 { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1754 { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1747 { 0x0D, 0x9F, 0x27, 0x9B, 0xA5, 0xD8, 0x72, 0x60 } }, | 1755 { 0x0D, 0x9F, 0x27, 0x9B, 0xA5, 0xD8, 0x72, 0x60 } }, |
1748 {10, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | 1756 {10, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, |
1749 { 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1757 { 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1750 { 0xD9, 0x03, 0x1B, 0x02, 0x71, 0xBD, 0x5A, 0x0A } } | 1758 { 0xD9, 0x03, 0x1B, 0x02, 0x71, 0xBD, 0x5A, 0x0A } }, |
1759 | |
1760 #ifdef LTC_TEST_EXT | |
1761 { 0+11, 0, { 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1762 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1763 { 0x95, 0xA8, 0xD7, 0x28, 0x13, 0xDA, 0xA9, 0x4D } }, | |
1764 { 1+11, 0, { 0x40, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1765 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1766 { 0x0E, 0xEC, 0x14, 0x87, 0xDD, 0x8C, 0x26, 0xD5 } }, | |
1767 { 2+11, 0, { 0x20, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1768 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1769 { 0x7A, 0xD1, 0x6F, 0xFB, 0x79, 0xC4, 0x59, 0x26 } }, | |
1770 { 3+11, 0, { 0x10, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1771 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1772 { 0xD3, 0x74, 0x62, 0x94, 0xCA, 0x6A, 0x6C, 0xF3 } }, | |
1773 { 4+11, 0, { 0x08, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1774 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1775 { 0x80, 0x9F, 0x5F, 0x87, 0x3C, 0x1F, 0xD7, 0x61 } }, | |
1776 { 5+11, 0, { 0x04, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1777 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1778 { 0xC0, 0x2F, 0xAF, 0xFE, 0xC9, 0x89, 0xD1, 0xFC } }, | |
1779 { 6+11, 0, { 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1780 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1781 { 0x46, 0x15, 0xAA, 0x1D, 0x33, 0xE7, 0x2F, 0x10 } }, | |
1782 { 7+11, 0, { 0x01, 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1783 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1784 { 0x20, 0x55, 0x12, 0x33, 0x50, 0xC0, 0x08, 0x58 } }, | |
1785 { 8+11, 0, { 0x01, 0x40, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1786 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1787 { 0xDF, 0x3B, 0x99, 0xD6, 0x57, 0x73, 0x97, 0xC8 } }, | |
1788 { 9+11, 0, { 0x01, 0x20, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1789 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1790 { 0x31, 0xFE, 0x17, 0x36, 0x9B, 0x52, 0x88, 0xC9 } }, | |
1791 {10+11, 0, { 0x01, 0x10, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1792 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1793 { 0xDF, 0xDD, 0x3C, 0xC6, 0x4D, 0xAE, 0x16, 0x42 } }, | |
1794 {11+11, 0, { 0x01, 0x08, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1795 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1796 { 0x17, 0x8C, 0x83, 0xCE, 0x2B, 0x39, 0x9D, 0x94 } }, | |
1797 {12+11, 0, { 0x01, 0x04, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1798 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1799 { 0x50, 0xF6, 0x36, 0x32, 0x4A, 0x9B, 0x7F, 0x80 } }, | |
1800 {13+11, 0, { 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1801 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1802 { 0xA8, 0x46, 0x8E, 0xE3, 0xBC, 0x18, 0xF0, 0x6D } }, | |
1803 {14+11, 0, { 0x01, 0x01, 0x80, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1804 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1805 { 0xA2, 0xDC, 0x9E, 0x92, 0xFD, 0x3C, 0xDE, 0x92 } }, | |
1806 {15+11, 0, { 0x01, 0x01, 0x40, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1807 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1808 { 0xCA, 0xC0, 0x9F, 0x79, 0x7D, 0x03, 0x12, 0x87 } }, | |
1809 {16+11, 0, { 0x01, 0x01, 0x20, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1810 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1811 { 0x90, 0xBA, 0x68, 0x0B, 0x22, 0xAE, 0xB5, 0x25 } }, | |
1812 {17+11, 0, { 0x01, 0x01, 0x10, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1813 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1814 { 0xCE, 0x7A, 0x24, 0xF3, 0x50, 0xE2, 0x80, 0xB6 } }, | |
1815 {18+11, 0, { 0x01, 0x01, 0x08, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1816 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1817 { 0x88, 0x2B, 0xFF, 0x0A, 0xA0, 0x1A, 0x0B, 0x87 } }, | |
1818 {19+11, 0, { 0x01, 0x01, 0x04, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1819 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1820 { 0x25, 0x61, 0x02, 0x88, 0x92, 0x45, 0x11, 0xC2 } }, | |
1821 {20+11, 0, { 0x01, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01 }, | |
1822 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1823 { 0xC7, 0x15, 0x16, 0xC2, 0x9C, 0x75, 0xD1, 0x70 } }, | |
1824 {21+11, 0, { 0x01, 0x01, 0x01, 0x80, 0x01, 0x01, 0x01, 0x01 }, | |
1825 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1826 { 0x51, 0x99, 0xC2, 0x9A, 0x52, 0xC9, 0xF0, 0x59 } }, | |
1827 {22+11, 0, { 0x01, 0x01, 0x01, 0x40, 0x01, 0x01, 0x01, 0x01 }, | |
1828 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1829 { 0xC2, 0x2F, 0x0A, 0x29, 0x4A, 0x71, 0xF2, 0x9F } }, | |
1830 {23+11, 0, { 0x01, 0x01, 0x01, 0x20, 0x01, 0x01, 0x01, 0x01 }, | |
1831 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1832 { 0xEE, 0x37, 0x14, 0x83, 0x71, 0x4C, 0x02, 0xEA } }, | |
1833 {24+11, 0, { 0x01, 0x01, 0x01, 0x10, 0x01, 0x01, 0x01, 0x01 }, | |
1834 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1835 { 0xA8, 0x1F, 0xBD, 0x44, 0x8F, 0x9E, 0x52, 0x2F } }, | |
1836 {25+11, 0, { 0x01, 0x01, 0x01, 0x08, 0x01, 0x01, 0x01, 0x01 }, | |
1837 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1838 { 0x4F, 0x64, 0x4C, 0x92, 0xE1, 0x92, 0xDF, 0xED } }, | |
1839 {26+11, 0, { 0x01, 0x01, 0x01, 0x04, 0x01, 0x01, 0x01, 0x01 }, | |
1840 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1841 { 0x1A, 0xFA, 0x9A, 0x66, 0xA6, 0xDF, 0x92, 0xAE } }, | |
1842 {27+11, 0, { 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01 }, | |
1843 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1844 { 0xB3, 0xC1, 0xCC, 0x71, 0x5C, 0xB8, 0x79, 0xD8 } }, | |
1845 {28+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x80, 0x01, 0x01, 0x01 }, | |
1846 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1847 { 0x19, 0xD0, 0x32, 0xE6, 0x4A, 0xB0, 0xBD, 0x8B } }, | |
1848 {29+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x40, 0x01, 0x01, 0x01 }, | |
1849 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1850 { 0x3C, 0xFA, 0xA7, 0xA7, 0xDC, 0x87, 0x20, 0xDC } }, | |
1851 {30+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x20, 0x01, 0x01, 0x01 }, | |
1852 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1853 { 0xB7, 0x26, 0x5F, 0x7F, 0x44, 0x7A, 0xC6, 0xF3 } }, | |
1854 {31+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x10, 0x01, 0x01, 0x01 }, | |
1855 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1856 { 0x9D, 0xB7, 0x3B, 0x3C, 0x0D, 0x16, 0x3F, 0x54 } }, | |
1857 {32+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x08, 0x01, 0x01, 0x01 }, | |
1858 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1859 { 0x81, 0x81, 0xB6, 0x5B, 0xAB, 0xF4, 0xA9, 0x75 } }, | |
1860 {33+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x04, 0x01, 0x01, 0x01 }, | |
1861 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1862 { 0x93, 0xC9, 0xB6, 0x40, 0x42, 0xEA, 0xA2, 0x40 } }, | |
1863 {34+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x01 }, | |
1864 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1865 { 0x55, 0x70, 0x53, 0x08, 0x29, 0x70, 0x55, 0x92 } }, | |
1866 {35+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x80, 0x01, 0x01 }, | |
1867 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1868 { 0x86, 0x38, 0x80, 0x9E, 0x87, 0x87, 0x87, 0xA0 } }, | |
1869 {36+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x40, 0x01, 0x01 }, | |
1870 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1871 { 0x41, 0xB9, 0xA7, 0x9A, 0xF7, 0x9A, 0xC2, 0x08 } }, | |
1872 {37+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x20, 0x01, 0x01 }, | |
1873 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1874 { 0x7A, 0x9B, 0xE4, 0x2F, 0x20, 0x09, 0xA8, 0x92 } }, | |
1875 {38+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x10, 0x01, 0x01 }, | |
1876 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1877 { 0x29, 0x03, 0x8D, 0x56, 0xBA, 0x6D, 0x27, 0x45 } }, | |
1878 {39+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x08, 0x01, 0x01 }, | |
1879 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1880 { 0x54, 0x95, 0xC6, 0xAB, 0xF1, 0xE5, 0xDF, 0x51 } }, | |
1881 {40+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x04, 0x01, 0x01 }, | |
1882 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1883 { 0xAE, 0x13, 0xDB, 0xD5, 0x61, 0x48, 0x89, 0x33 } }, | |
1884 {41+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01 }, | |
1885 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1886 { 0x02, 0x4D, 0x1F, 0xFA, 0x89, 0x04, 0xE3, 0x89 } }, | |
1887 {42+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x80, 0x01 }, | |
1888 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1889 { 0xD1, 0x39, 0x97, 0x12, 0xF9, 0x9B, 0xF0, 0x2E } }, | |
1890 {43+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x40, 0x01 }, | |
1891 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1892 { 0x14, 0xC1, 0xD7, 0xC1, 0xCF, 0xFE, 0xC7, 0x9E } }, | |
1893 {44+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x20, 0x01 }, | |
1894 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1895 { 0x1D, 0xE5, 0x27, 0x9D, 0xAE, 0x3B, 0xED, 0x6F } }, | |
1896 {45+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x10, 0x01 }, | |
1897 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1898 { 0xE9, 0x41, 0xA3, 0x3F, 0x85, 0x50, 0x13, 0x03 } }, | |
1899 {46+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x08, 0x01 }, | |
1900 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1901 { 0xDA, 0x99, 0xDB, 0xBC, 0x9A, 0x03, 0xF3, 0x79 } }, | |
1902 {47+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04, 0x01 }, | |
1903 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1904 { 0xB7, 0xFC, 0x92, 0xF9, 0x1D, 0x8E, 0x92, 0xE9 } }, | |
1905 {48+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01 }, | |
1906 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1907 { 0xAE, 0x8E, 0x5C, 0xAA, 0x3C, 0xA0, 0x4E, 0x85 } }, | |
1908 {49+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x80 }, | |
1909 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1910 { 0x9C, 0xC6, 0x2D, 0xF4, 0x3B, 0x6E, 0xED, 0x74 } }, | |
1911 {50+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x40 }, | |
1912 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1913 { 0xD8, 0x63, 0xDB, 0xB5, 0xC5, 0x9A, 0x91, 0xA0 } }, | |
1914 {51+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x20 }, | |
1915 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1916 { 0xA1, 0xAB, 0x21, 0x90, 0x54, 0x5B, 0x91, 0xD7 } }, | |
1917 {52+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x10 }, | |
1918 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1919 { 0x08, 0x75, 0x04, 0x1E, 0x64, 0xC5, 0x70, 0xF7 } }, | |
1920 {53+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x08 }, | |
1921 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1922 { 0x5A, 0x59, 0x45, 0x28, 0xBE, 0xBE, 0xF1, 0xCC } }, | |
1923 {54+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04 }, | |
1924 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1925 { 0xFC, 0xDB, 0x32, 0x91, 0xDE, 0x21, 0xF0, 0xC0 } }, | |
1926 {55+11, 0, { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02 }, | |
1927 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
1928 { 0x86, 0x9E, 0xFD, 0x7F, 0x9F, 0x26, 0x5A, 0x09 } }, | |
1929 #endif /* LTC_TEST_EXT */ | |
1751 | 1930 |
1752 /*** more test cases you could add if you are not convinced (the above test cases aren't really too good): | 1931 /*** more test cases you could add if you are not convinced (the above test cases aren't really too good): |
1753 | 1932 |
1754 key plaintext ciphertext | 1933 key plaintext ciphertext |
1755 0000000000000000 0000000000000000 8CA64DE9C1B123A7 | 1934 0000000000000000 0000000000000000 8CA64DE9C1B123A7 |
1803 des_ecb_encrypt(cases[i].txt, tmp, &des); | 1982 des_ecb_encrypt(cases[i].txt, tmp, &des); |
1804 } else { | 1983 } else { |
1805 des_ecb_decrypt(cases[i].txt, tmp, &des); | 1984 des_ecb_decrypt(cases[i].txt, tmp, &des); |
1806 } | 1985 } |
1807 | 1986 |
1808 if (XMEMCMP(cases[i].out, tmp, sizeof(tmp)) != 0) { | 1987 if (compare_testvector(cases[i].out, sizeof(tmp), tmp, sizeof(tmp), "DES", i) != 0) { |
1809 return CRYPT_FAIL_TESTVECTOR; | 1988 return CRYPT_FAIL_TESTVECTOR; |
1810 } | 1989 } |
1811 | 1990 |
1812 /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */ | 1991 /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */ |
1813 for (y = 0; y < 8; y++) tmp[y] = 0; | 1992 for (y = 0; y < 8; y++) tmp[y] = 0; |
1814 for (y = 0; y < 1000; y++) des_ecb_encrypt(tmp, tmp, &des); | 1993 for (y = 0; y < 1000; y++) des_ecb_encrypt(tmp, tmp, &des); |
1815 for (y = 0; y < 1000; y++) des_ecb_decrypt(tmp, tmp, &des); | 1994 for (y = 0; y < 1000; y++) des_ecb_decrypt(tmp, tmp, &des); |
1816 for (y = 0; y < 8; y++) if (tmp[y] != 0) return CRYPT_FAIL_TESTVECTOR; | 1995 for (y = 0; y < 8; y++) if (tmp[y] != 0) return CRYPT_FAIL_TESTVECTOR; |
1817 } | 1996 } |
1818 | 1997 |
1819 return CRYPT_OK; | 1998 return CRYPT_OK; |
1820 #endif | 1999 #endif |
1821 } | 2000 } |
1822 #endif | 2001 #endif |
1847 } | 2026 } |
1848 | 2027 |
1849 des3_ecb_encrypt(pt, ct, &skey); | 2028 des3_ecb_encrypt(pt, ct, &skey); |
1850 des3_ecb_decrypt(ct, tmp, &skey); | 2029 des3_ecb_decrypt(ct, tmp, &skey); |
1851 | 2030 |
1852 if (XMEMCMP(pt, tmp, 8) != 0) { | 2031 if (compare_testvector(pt, 8, tmp, 8, "3DES", 0) != 0) { |
1853 return CRYPT_FAIL_TESTVECTOR; | 2032 return CRYPT_FAIL_TESTVECTOR; |
1854 } | 2033 } |
1855 | 2034 |
1856 return CRYPT_OK; | 2035 return CRYPT_OK; |
1857 #endif | 2036 #endif |
1861 /** Terminate the context | 2040 /** Terminate the context |
1862 @param skey The scheduled key | 2041 @param skey The scheduled key |
1863 */ | 2042 */ |
1864 void des_done(symmetric_key *skey) | 2043 void des_done(symmetric_key *skey) |
1865 { | 2044 { |
2045 LTC_UNUSED_PARAM(skey); | |
1866 } | 2046 } |
1867 #endif | 2047 #endif |
1868 | 2048 |
1869 /** Terminate the context | 2049 /** Terminate the context |
1870 @param skey The scheduled key | 2050 @param skey The scheduled key |
1871 */ | 2051 */ |
1872 void des3_done(symmetric_key *skey) | 2052 void des3_done(symmetric_key *skey) |
1873 { | 2053 { |
1874 (void)skey; | 2054 LTC_UNUSED_PARAM(skey); |
1875 } | 2055 } |
1876 | 2056 |
1877 | 2057 |
1878 #if 0 | 2058 #if 0 |
1879 /** | 2059 /** |
1908 } | 2088 } |
1909 | 2089 |
1910 #endif | 2090 #endif |
1911 | 2091 |
1912 | 2092 |
1913 /* $Source$ */ | 2093 /* ref: $Format:%D$ */ |
1914 /* $Revision$ */ | 2094 /* git commit: $Format:%H$ */ |
1915 /* $Date$ */ | 2095 /* commit time: $Format:%ai$ */ |