Mercurial > dropbear
comparison src/ciphers/des.c @ 281:997e6f7dc01e libtomcrypt-dropbear
Just import the Dropbear 0.47 libtomcrypt changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 08 Mar 2006 13:02:58 +0000 |
parents | 59400faa4b44 |
children | 999a5eb4ed10 |
comparison
equal
deleted
inserted
replaced
280:59400faa4b44 | 281:997e6f7dc01e |
---|---|
18 #ifdef DES | 18 #ifdef DES |
19 | 19 |
20 #define EN0 0 | 20 #define EN0 0 |
21 #define DE1 1 | 21 #define DE1 1 |
22 | 22 |
23 #if 0 | |
23 const struct ltc_cipher_descriptor des_desc = | 24 const struct ltc_cipher_descriptor des_desc = |
24 { | 25 { |
25 "des", | 26 "des", |
26 13, | 27 13, |
27 8, 8, 8, 16, | 28 8, 8, 8, 16, |
31 &des_test, | 32 &des_test, |
32 &des_done, | 33 &des_done, |
33 &des_keysize, | 34 &des_keysize, |
34 NULL, NULL, NULL, NULL, NULL, NULL, NULL | 35 NULL, NULL, NULL, NULL, NULL, NULL, NULL |
35 }; | 36 }; |
37 #endif | |
36 | 38 |
37 const struct ltc_cipher_descriptor des3_desc = | 39 const struct ltc_cipher_descriptor des3_desc = |
38 { | 40 { |
39 "3des", | 41 "3des", |
40 14, | 42 14, |
1516 _desfunc(block, keys); | 1518 _desfunc(block, keys); |
1517 burn_stack(sizeof(ulong32) * 4 + sizeof(int)); | 1519 burn_stack(sizeof(ulong32) * 4 + sizeof(int)); |
1518 } | 1520 } |
1519 #endif | 1521 #endif |
1520 | 1522 |
1523 #if 0 | |
1521 /** | 1524 /** |
1522 Initialize the DES block cipher | 1525 Initialize the DES block cipher |
1523 @param key The symmetric key you wish to pass | 1526 @param key The symmetric key you wish to pass |
1524 @param keylen The key length in bytes | 1527 @param keylen The key length in bytes |
1525 @param num_rounds The number of rounds desired (0 for default) | 1528 @param num_rounds The number of rounds desired (0 for default) |
1542 deskey(key, EN0, skey->des.ek); | 1545 deskey(key, EN0, skey->des.ek); |
1543 deskey(key, DE1, skey->des.dk); | 1546 deskey(key, DE1, skey->des.dk); |
1544 | 1547 |
1545 return CRYPT_OK; | 1548 return CRYPT_OK; |
1546 } | 1549 } |
1550 #endif | |
1547 | 1551 |
1548 /** | 1552 /** |
1549 Initialize the 3DES-EDE block cipher | 1553 Initialize the 3DES-EDE block cipher |
1550 @param key The symmetric key you wish to pass | 1554 @param key The symmetric key you wish to pass |
1551 @param keylen The key length in bytes | 1555 @param keylen The key length in bytes |
1575 deskey(key+16, DE1, skey->des3.dk[0]); | 1579 deskey(key+16, DE1, skey->des3.dk[0]); |
1576 | 1580 |
1577 return CRYPT_OK; | 1581 return CRYPT_OK; |
1578 } | 1582 } |
1579 | 1583 |
1584 #if 0 | |
1580 /** | 1585 /** |
1581 Encrypts a block of text with DES | 1586 Encrypts a block of text with DES |
1582 @param pt The input plaintext (8 bytes) | 1587 @param pt The input plaintext (8 bytes) |
1583 @param ct The output ciphertext (8 bytes) | 1588 @param ct The output ciphertext (8 bytes) |
1584 @param skey The key as scheduled | 1589 @param skey The key as scheduled |
1612 LOAD32H(work[1], ct+4); | 1617 LOAD32H(work[1], ct+4); |
1613 desfunc(work, skey->des.dk); | 1618 desfunc(work, skey->des.dk); |
1614 STORE32H(work[0],pt+0); | 1619 STORE32H(work[0],pt+0); |
1615 STORE32H(work[1],pt+4); | 1620 STORE32H(work[1],pt+4); |
1616 } | 1621 } |
1622 #endif | |
1617 | 1623 |
1618 /** | 1624 /** |
1619 Encrypts a block of text with 3DES-EDE | 1625 Encrypts a block of text with 3DES-EDE |
1620 @param pt The input plaintext (8 bytes) | 1626 @param pt The input plaintext (8 bytes) |
1621 @param ct The output ciphertext (8 bytes) | 1627 @param ct The output ciphertext (8 bytes) |
1656 desfunc(work, skey->des3.dk[2]); | 1662 desfunc(work, skey->des3.dk[2]); |
1657 STORE32H(work[0],pt+0); | 1663 STORE32H(work[0],pt+0); |
1658 STORE32H(work[1],pt+4); | 1664 STORE32H(work[1],pt+4); |
1659 } | 1665 } |
1660 | 1666 |
1667 #if 0 | |
1661 /** | 1668 /** |
1662 Performs a self-test of the DES block cipher | 1669 Performs a self-test of the DES block cipher |
1663 @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled | 1670 @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled |
1664 */ | 1671 */ |
1665 int des_test(void) | 1672 int des_test(void) |
1802 } | 1809 } |
1803 | 1810 |
1804 return CRYPT_OK; | 1811 return CRYPT_OK; |
1805 #endif | 1812 #endif |
1806 } | 1813 } |
1814 #endif | |
1807 | 1815 |
1808 int des3_test(void) | 1816 int des3_test(void) |
1809 { | 1817 { |
1810 #ifndef LTC_TEST | 1818 #ifndef LTC_TEST |
1811 return CRYPT_NOP; | 1819 return CRYPT_NOP; |
1839 | 1847 |
1840 return CRYPT_OK; | 1848 return CRYPT_OK; |
1841 #endif | 1849 #endif |
1842 } | 1850 } |
1843 | 1851 |
1852 #if 0 | |
1844 /** Terminate the context | 1853 /** Terminate the context |
1845 @param skey The scheduled key | 1854 @param skey The scheduled key |
1846 */ | 1855 */ |
1847 void des_done(symmetric_key *skey) | 1856 void des_done(symmetric_key *skey) |
1848 { | 1857 { |
1849 } | 1858 } |
1859 #endif | |
1850 | 1860 |
1851 /** Terminate the context | 1861 /** Terminate the context |
1852 @param skey The scheduled key | 1862 @param skey The scheduled key |
1853 */ | 1863 */ |
1854 void des3_done(symmetric_key *skey) | 1864 void des3_done(symmetric_key *skey) |
1855 { | 1865 { |
1856 } | 1866 } |
1857 | 1867 |
1858 | 1868 |
1869 #if 0 | |
1859 /** | 1870 /** |
1860 Gets suitable key size | 1871 Gets suitable key size |
1861 @param keysize [in/out] The length of the recommended key (in bytes). This function will store the suitable size back in this variable. | 1872 @param keysize [in/out] The length of the recommended key (in bytes). This function will store the suitable size back in this variable. |
1862 @return CRYPT_OK if the input key size is acceptable. | 1873 @return CRYPT_OK if the input key size is acceptable. |
1863 */ | 1874 */ |
1868 return CRYPT_INVALID_KEYSIZE; | 1879 return CRYPT_INVALID_KEYSIZE; |
1869 } | 1880 } |
1870 *keysize = 8; | 1881 *keysize = 8; |
1871 return CRYPT_OK; | 1882 return CRYPT_OK; |
1872 } | 1883 } |
1884 #endif | |
1873 | 1885 |
1874 /** | 1886 /** |
1875 Gets suitable key size | 1887 Gets suitable key size |
1876 @param keysize [in/out] The length of the recommended key (in bytes). This function will store the suitable size back in this variable. | 1888 @param keysize [in/out] The length of the recommended key (in bytes). This function will store the suitable size back in this variable. |
1877 @return CRYPT_OK if the input key size is acceptable. | 1889 @return CRYPT_OK if the input key size is acceptable. |