Annotation of truecrypt/common/crypto.h, revision 1.1.1.5

1.1.1.3   root        1: /* The source code contained in this file has been derived from the source code
                      2:    of Encryption for the Masses 2.02a by Paul Le Roux. Modifications and
                      3:    additions to that source code contained in this file are Copyright (c) 2004
1.1.1.5 ! root        4:    TrueCrypt Foundation and Copyright (c) 2004 TrueCrypt Team. Unmodified
1.1.1.3   root        5:    parts are Copyright (c) 1998-99 Paul Le Roux. This is a TrueCrypt Foundation
                      6:    release. Please see the file license.txt for full license details. */
1.1       root        7: 
1.1.1.5 ! root        8: /* Update the following when adding a new cipher or EA:
        !             9: 
        !            10:    Crypto.h:
        !            11:      ID #define
        !            12:      MAX_EXPANDED_KEY #define
        !            13: 
        !            14:    Crypto.c:
        !            15:      Ciphers[]
        !            16:      EncryptionAlgorithms[]
        !            17:      CipherInit()
        !            18:      EncipherBlock()
        !            19:      DecipherBlock()
        !            20: */
1.1       root       21: 
                     22: // User text input limits
                     23: #ifndef _DEBUG
1.1.1.5 ! root       24: #define MIN_PASSWORD           1                       // Minimum password length
1.1       root       25: #else
                     26: #define MIN_PASSWORD           0
                     27: #endif
1.1.1.5 ! root       28: #define MAX_PASSWORD           64                      // Maximum password length
        !            29: 
        !            30: #define PASSWORD_LEN_WARNING   12              // Display a warning when a password is shorter than this
1.1       root       31: 
                     32: // User key
                     33: #define USERKEY_ITERATIONS     2000
                     34: #define USERKEY_SALT_SIZE      64
                     35: 
                     36: // Disk key + IV
                     37: #define DISKKEY_SIZE           256
                     38: #define DISK_IV_SIZE           32
                     39: 
                     40: // Volume header byte offsets
                     41: #define        HEADER_USERKEY_SALT             0
                     42: #define HEADER_ENCRYPTEDDATA   USERKEY_SALT_SIZE
                     43: #define        HEADER_DISKKEY                  256
                     44: 
                     45: // Volume header sizes
                     46: #define HEADER_SIZE                                    512
                     47: #define HEADER_ENCRYPTEDDATASIZE       (HEADER_SIZE - HEADER_ENCRYPTEDDATA)
                     48: 
1.1.1.5 ! root       49: /* The offset, in bytes, of the hidden volume header position from the end of the file (a positive value).
        !            50:    The extra offset (SECTOR_SIZE * 2) was added because FAT file system fills the last sector with zeroes
        !            51:    (marked as free; observed when quick format was performed using the OS format tool). One extra sector was
        !            52:    added to the offset for future expandability (should the header size increase, or should header backup be
        !            53:    introduced). */
        !            54: #define HIDDEN_VOL_HEADER_OFFSET       (HEADER_SIZE + SECTOR_SIZE * 2)         
        !            55: 
1.1       root       56: // PKCS5 PRF hash algorithm ID
                     57: #define        SHA1                            1
                     58: #define        RIPEMD160                       2
1.1.1.5 ! root       59: #define LAST_PRF_ID                    2                       // The number of implemented/available pseudo-random functions (PKCS #5 v2.0)
        !            60: 
        !            61: // Modes of operation
        !            62: enum
        !            63: {
        !            64:        CBC = 1,
        !            65:        OUTER_CBC,
        !            66:        INNER_CBC
        !            67: };
1.1       root       68: 
1.1.1.5 ! root       69: // Cipher IDs
1.1       root       70: #define NONE                           0
1.1.1.5 ! root       71: #define AES                                    1
        !            72: #define BLOWFISH                       2
1.1.1.2   root       73: #define CAST                           3
1.1.1.5 ! root       74: #define SERPENT                                4
        !            75: #define TRIPLEDES                      5
        !            76: #define TWOFISH                                6
        !            77: #define DES56                          7                       // Used only by Triple DES
1.1       root       78: 
1.1.1.5 ! root       79: typedef struct
        !            80: {
        !            81:        int Id;                                 // Cipher ID
        !            82:        char *Name;                             // Name
        !            83:        int BlockSize;                  // Block size (bytes)
        !            84:        int KeySize;                    // Key size (bytes)
        !            85:        int KeyScheduleSize;    // Scheduled key size (bytes)
        !            86: } Cipher;
1.1       root       87: 
1.1.1.5 ! root       88: typedef struct
        !            89: {
        !            90:        int Ciphers[4];                 // Null terminated array of ciphers used by encryption algorithm
        !            91:        int Mode;                               // The mode of operation of the whole EA (cipher cascade)
        !            92: } EncryptionAlgorithm;
        !            93: 
        !            94: // Maxium length of scheduled key
        !            95: #define AES_KS                         (sizeof(aes_encrypt_ctx) + sizeof(aes_decrypt_ctx))
        !            96: #define SERPENT_KS                     (140 * 4)
        !            97: #define MAX_EXPANDED_KEY       (AES_KS + SERPENT_KS + TWOFISH_KS)
1.1       root       98: 
                     99: #include "des.h"
                    100: #include "blowfish.h"
1.1.1.2   root      101: #include "aes.h"
1.1       root      102: #include "cast.h"
1.1.1.3   root      103: #include "sha1.h"
                    104: #include "rmd160.h"
1.1.1.5 ! root      105: #include "serpent.h"
        !           106: #include "twofish.h"
1.1       root      107: 
                    108: typedef struct keyInfo_t
                    109: {
                    110:        int noIterations;                                       /* No.of times to iterate setup */
                    111:        int keyLength;                                          /* Length of the key */
                    112:        char userKey[MAX_PASSWORD];                     /* Max pass, WITHOUT +1 for the NULL */
                    113:        char key_salt[USERKEY_SALT_SIZE];       /* Key setup salt */
                    114:        char key[DISKKEY_SIZE];                         /* The keying material itself */
                    115: } KEY_INFO, *PKEY_INFO;
                    116: 
                    117: typedef struct CRYPTO_INFO_t
                    118: {
1.1.1.5 ! root      119:        /* Encryption alogrithm information */
        !           120:        int ea;
1.1       root      121:        unsigned char iv[DISK_IV_SIZE];
                    122:        unsigned char ks[MAX_EXPANDED_KEY];
                    123: 
1.1.1.5 ! root      124:        /* Volume information */
        !           125: 
1.1       root      126:        unsigned char master_decrypted_key[DISKKEY_SIZE];
                    127:        unsigned char key_salt[USERKEY_SALT_SIZE];
                    128:        int noIterations;
                    129:        int pkcs5;
                    130: 
                    131:        unsigned __int64 volume_creation_time;
                    132:        unsigned __int64 header_creation_time;
                    133: 
1.1.1.5 ! root      134:        // Hidden volume status & parameters
        !           135:        BOOL hiddenVolume;              // Indicates whether the volume is mounted/mountable as hidden volume
        !           136:        unsigned __int64 hiddenVolumeSize;              // Size of the hidden volume excluding the header (in bytes). Set to 0 for standard volumes.
        !           137:        unsigned __int64 hiddenVolumeOffset;    // Absolute position, in bytes, of the first hidden volume data sector within the hosting volume (provided that there is a hidden volume).
1.1       root      138: 
1.1.1.5 ! root      139: } CRYPTO_INFO, *PCRYPTO_INFO;
1.1       root      140: 
                    141: PCRYPTO_INFO crypto_open (void);
                    142: void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen);
                    143: void crypto_close (PCRYPTO_INFO cryptoInfo);
1.1.1.5 ! root      144: 
        !           145: int CipherGetBlockSize (int cipher);
        !           146: int CipherGetKeySize (int cipher);
        !           147: int CipherGetKeyScheduleSize (int cipher);
        !           148: char * CipherGetName (int cipher);
        !           149: 
        !           150: void CipherInit (int cipher, unsigned char *key, unsigned char *ks);
        !           151: void EAInit (int ea, unsigned char *key, unsigned char *ks);
        !           152: void EncipherBlock(int cipher, void *data, void *ks);
        !           153: void DecipherBlock(int cipher, void *data, void *ks);
        !           154: 
        !           155: int EAGetFirst ();
        !           156: int EAGetCount (void);
        !           157: int EAGetNext (int previousEA);
        !           158: char * EAGetName (char *buf, int ea);
        !           159: int EAGetKeySize (int ea);
        !           160: int EAGetMode (int ea);
        !           161: char * EAGetModeName (char *name, int ea, BOOL capitalLetters);
        !           162: int EAGetKeyScheduleSize (int ea);
        !           163: int EAGetLargestKey ();
        !           164: 
        !           165: int EAGetCipherCount (int ea);
        !           166: int EAGetFirstCipher (int ea);
        !           167: int EAGetLastCipher (int ea);
        !           168: int EAGetNextCipher (int ea, int previousCipherId);
        !           169: int EAGetPreviousCipher (int ea, int previousCipherId);
        !           170: 
1.1       root      171: char * get_hash_name (int pkcs5);
1.1.1.5 ! root      172: 
        !           173: void EncryptBuffer (unsigned long *buf, unsigned __int64 len, unsigned char *ks, void *iv, void *whitening, int ea);
        !           174: void DecryptBuffer (unsigned long *buf, unsigned __int64 len, unsigned char *ks, void *iv, void *whitening, int ea);
        !           175: void _cdecl EncryptSectors (unsigned long *buf, unsigned __int64 secNo, unsigned __int64 noSectors, unsigned char *ks, void *iv, int ea);
        !           176: void _cdecl DecryptSectors (unsigned long *buf, unsigned __int64 secNo, unsigned __int64 noSectors, unsigned char *ks, void *iv, int ea);

unix.superglobalmegacorp.com

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