2 ---------------------------------------------------------------------------
3 Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK.
8 The free distribution and use of this software in both source and binary
9 form is allowed (with or without changes) provided that:
11 1. distributions of this source code include the above copyright
12 notice, this list of conditions and the following disclaimer;
14 2. distributions in binary form include the above copyright
15 notice, this list of conditions and the following disclaimer
16 in the documentation and/or other associated materials;
18 3. the copyright holder's name is not used to endorse products
19 built using this software without specific written permission.
21 ALTERNATIVELY, provided that this notice is retained in full, this product
22 may be distributed under the terms of the GNU General Public License (GPL),
23 in which case the provisions of the GPL apply INSTEAD OF those given above.
27 This software is provided 'as is' with no explicit or implied warranties
28 in respect of its properties, including, but not limited to, correctness
29 and/or fitness for purpose.
30 ---------------------------------------------------------------------------
31 Issue Date: 24/01/2003
33 This file contains the header file for fileenc.c, which implements password
34 based file encryption and authentication using AES in CTR mode, HMAC-SHA1
35 authentication and RFC2898 password based key derivation.
45 #define PASSWORD_VERIFIER
47 #define MAX_KEY_LENGTH 32
48 #define MAX_PWD_LENGTH 128
49 #define MAX_SALT_LENGTH 16
50 #define KEYING_ITERATIONS 1000
52 #ifdef PASSWORD_VERIFIER
53 #define PWD_VER_LENGTH 2
55 #define PWD_VER_LENGTH 0
59 #define PASSWORD_TOO_LONG -100
63 Field lengths (in bytes) versus File Encryption Mode (0 < mode < 4)
65 Mode Key Salt MAC Overhead
70 The following macros assume that the mode value is correct.
73 #define KEY_LENGTH(mode) (8 * (mode & 3) + 8)
74 #define SALT_LENGTH(mode) (4 * (mode & 3) + 4)
75 #define MAC_LENGTH(mode) (10)
77 /* the context for file encryption */
79 #if defined(__cplusplus)
85 { unsigned char nonce[AES_BLOCK_SIZE]; /* the CTR nonce */
86 unsigned char encr_bfr[AES_BLOCK_SIZE]; /* encrypt buffer */
87 aes_encrypt_ctx encr_ctx[1]; /* encryption context */
88 hmac_ctx auth_ctx[1]; /* authentication context */
89 unsigned int encr_pos; /* block position (enc) */
90 unsigned int pwd_len; /* password length */
91 unsigned int mode; /* File encryption mode */
94 /* initialise file encryption or decryption */
97 int mode, /* the mode to be used (input) */
98 const unsigned char pwd[], /* the user specified password (input) */
99 unsigned int pwd_len, /* the length of the password (input) */
100 const unsigned char salt[], /* the salt (input) */
101 #ifdef PASSWORD_VERIFIER
102 unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */
104 fcrypt_ctx cx[1]); /* the file encryption context (output) */
106 /* perform 'in place' encryption or decryption and authentication */
108 void fcrypt_encrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]);
109 void fcrypt_decrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]);
111 /* close encryption/decryption and return the MAC value */
112 /* the return value is the length of the MAC */
114 int fcrypt_end(unsigned char mac[], /* the MAC value (output) */
115 fcrypt_ctx cx[1]); /* the context (input) */
117 #if defined(__cplusplus)