Annotation of truecrypt/common/crypto.c, revision 1.1.1.2

1.1.1.2 ! root        1: /* Copyright (C) 2004 TrueCrypt Foundation
1.1       root        2:    This product uses components written by Paul Le Roux <[email protected]> */
                      3: 
                      4: #include "TCdefs.h"
                      5: #include "crypto.h"
                      6: #include "random.h"
                      7: 
                      8: PCRYPTO_INFO
                      9: crypto_open ()
                     10: {
                     11:        /* Do the crt allocation */
                     12:        PCRYPTO_INFO cryptoInfo = TCalloc (sizeof (CRYPTO_INFO));
1.1.1.2 ! root       13: #ifndef DEVICE_DRIVER
        !            14:        VirtualLock (cryptoInfo, sizeof (CRYPTO_INFO));
        !            15: #endif
        !            16: 
1.1       root       17:        if (cryptoInfo == NULL)
                     18:                return NULL;
                     19: 
                     20:        cryptoInfo->cipher = -1;
                     21:        return cryptoInfo;
                     22: }
                     23: 
                     24: void
                     25: crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen)
                     26: {
                     27:        keyInfo->keyLength = nUserKeyLen;
                     28:        burn (keyInfo->userKey, sizeof (keyInfo->userKey));
                     29:        memcpy (keyInfo->userKey, lpszUserKey, nUserKeyLen);
                     30: }
                     31: 
                     32: void
                     33: crypto_close (PCRYPTO_INFO cryptoInfo)
                     34: {
                     35:        burn (cryptoInfo, sizeof (CRYPTO_INFO));
1.1.1.2 ! root       36: #ifndef DEVICE_DRIVER
        !            37:        VirtualUnlock (cryptoInfo, sizeof (CRYPTO_INFO));
        !            38: #endif
1.1       root       39:        TCfree (cryptoInfo);
                     40: }
                     41: 
                     42: int
                     43: get_block_size (int cipher)
                     44: {
1.1.1.2 ! root       45:        if (cipher == AES)
        !            46:                return 16;
        !            47:        else
        !            48:                return 8;
1.1       root       49: }
                     50: 
                     51: int
                     52: get_key_size (int cipher)
                     53: {
                     54:        if (cipher == DES56)
                     55:                return 7;
                     56:        else if (cipher == IDEA)
                     57:                return 16;
                     58:        else if (cipher == BLOWFISH)
                     59:                return 56;
1.1.1.2 ! root       60:        else if (cipher == AES)
        !            61:                return 32;
1.1       root       62:        else if (cipher == TRIPLEDES)
                     63:                return 21;
                     64:        else if (cipher == CAST)
                     65:                return 16;
                     66:        else
                     67:        {
                     68:                return 0;
                     69:        }
                     70: }
                     71: 
                     72: char *
                     73: get_cipher_name (int cipher)
                     74: {
                     75:        if (cipher == BLOWFISH)
                     76:                return "Blowfish";
1.1.1.2 ! root       77:        if (cipher == AES)
        !            78:                return "AES";
1.1       root       79:        else if (cipher == IDEA)
                     80:                return "IDEA";
                     81:        else if (cipher == DES56)
                     82:                return "DES";
                     83:        else if (cipher == TRIPLEDES)
                     84:                return "Triple-DES";
                     85:        else if (cipher == CAST)
                     86:                return "CAST";
                     87:        else if (cipher == NONE)
                     88:                return "None";
                     89:        else
                     90:                return "Unknown";
                     91: }
                     92: 
                     93: char * get_hash_name (int pkcs5)
                     94: {
                     95:        switch (pkcs5)
                     96:        {
                     97:        case SHA1:              return "HMAC-SHA-1";
                     98:        case RIPEMD160: return "HMAC-RIPEMD-160";
                     99:        default:                return "Unknown";
                    100:        }
                    101: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.