cordova-plugin-mserviceinterface-2.0 1.0.21 → 1.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +28 -28
- package/plugin.xml +153 -153
- package/src/android/CallbackProgressDialog.java +53 -53
- package/src/android/FileProvider.java +7 -7
- package/src/android/backgroundNotification.java +120 -120
- package/src/android/doubleogradle.gradle +5 -5
- package/src/android/mInterface.java +2087 -2066
- package/src/android/mInterfaceReceiver.java +59 -59
- package/src/android/mInterfaceService.java +749 -749
- package/src/android/mInterfaceUtil.java +1686 -1688
- package/src/android/res/xml/network_security_config.xml +8 -8
- package/src/android/res/xml/opener_paths.xml +16 -16
- package/src/ios/InternetConnection.h +64 -64
- package/src/ios/InternetConnection.m +242 -242
- package/src/ios/SSZipArchive.h +146 -146
- package/src/ios/SSZipArchive.m +1180 -1180
- package/src/ios/SSZipCommon.h +66 -66
- package/src/ios/UICKeyChainStore.h +64 -64
- package/src/ios/UICKeyChainStore.m +434 -434
- package/src/ios/XMLConverter.h +61 -61
- package/src/ios/XMLConverter.m +243 -243
- package/src/ios/ZipArchive.h +19 -19
- package/src/ios/aes/aes.h +270 -270
- package/src/ios/aes/aes_ni.c +687 -687
- package/src/ios/aes/aes_ni.h +59 -59
- package/src/ios/aes/aescrypt.c +301 -301
- package/src/ios/aes/aeskey.c +554 -554
- package/src/ios/aes/aesopt.h +776 -776
- package/src/ios/aes/aestab.c +418 -418
- package/src/ios/aes/aestab.h +173 -173
- package/src/ios/aes/brg_endian.h +127 -127
- package/src/ios/aes/brg_types.h +191 -191
- package/src/ios/aes/fileenc.c +145 -145
- package/src/ios/aes/fileenc.h +121 -121
- package/src/ios/aes/hmac.c +209 -209
- package/src/ios/aes/hmac.h +119 -119
- package/src/ios/aes/prng.c +155 -155
- package/src/ios/aes/prng.h +82 -82
- package/src/ios/aes/pwd2key.c +181 -181
- package/src/ios/aes/pwd2key.h +45 -45
- package/src/ios/aes/sha1.c +283 -283
- package/src/ios/aes/sha1.h +72 -72
- package/src/ios/mInterface.h +2 -0
- package/src/ios/mInterface.m +18 -1
- package/src/ios/minizip/crypt.c +146 -146
- package/src/ios/minizip/crypt.h +66 -66
- package/src/ios/minizip/ioapi.c +353 -353
- package/src/ios/minizip/ioapi.h +154 -154
- package/src/ios/minizip/ioapi_buf.c +452 -452
- package/src/ios/minizip/ioapi_buf.h +52 -52
- package/src/ios/minizip/ioapi_mem.c +167 -167
- package/src/ios/minizip/ioapi_mem.h +52 -52
- package/src/ios/minizip/minishared.c +292 -292
- package/src/ios/minizip/minishared.h +50 -50
- package/src/ios/minizip/unzip.c +2007 -2007
- package/src/ios/minizip/unzip.h +254 -254
- package/src/ios/minizip/zip.c +2007 -2007
- package/src/ios/minizip/zip.h +215 -215
- package/www/mInterface.js +3 -3
package/src/ios/aes/fileenc.c
CHANGED
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
/*
|
|
2
|
-
---------------------------------------------------------------------------
|
|
3
|
-
Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK.
|
|
4
|
-
All rights reserved.
|
|
5
|
-
|
|
6
|
-
LICENSE TERMS
|
|
7
|
-
|
|
8
|
-
The free distribution and use of this software in both source and binary
|
|
9
|
-
form is allowed (with or without changes) provided that:
|
|
10
|
-
|
|
11
|
-
1. distributions of this source code include the above copyright
|
|
12
|
-
notice, this list of conditions and the following disclaimer;
|
|
13
|
-
|
|
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;
|
|
17
|
-
|
|
18
|
-
3. the copyright holder's name is not used to endorse products
|
|
19
|
-
built using this software without specific written permission.
|
|
20
|
-
|
|
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.
|
|
24
|
-
|
|
25
|
-
DISCLAIMER
|
|
26
|
-
|
|
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
|
|
32
|
-
|
|
33
|
-
This file implements password based file encryption and authentication
|
|
34
|
-
using AES in CTR mode, HMAC-SHA1 authentication and RFC2898 password
|
|
35
|
-
based key derivation.
|
|
36
|
-
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
#include <string.h>
|
|
40
|
-
|
|
41
|
-
#include "fileenc.h"
|
|
42
|
-
|
|
43
|
-
#if defined(__cplusplus)
|
|
44
|
-
extern "C"
|
|
45
|
-
{
|
|
46
|
-
#endif
|
|
47
|
-
|
|
48
|
-
/* subroutine for data encryption/decryption */
|
|
49
|
-
/* this could be speeded up a lot by aligning */
|
|
50
|
-
/* buffers and using 32 bit operations */
|
|
51
|
-
|
|
52
|
-
static void encr_data(unsigned char data[], unsigned long d_len, fcrypt_ctx cx[1])
|
|
53
|
-
{
|
|
54
|
-
unsigned int i = 0, pos = cx->encr_pos;
|
|
55
|
-
|
|
56
|
-
while (i < d_len)
|
|
57
|
-
{
|
|
58
|
-
if (pos == AES_BLOCK_SIZE)
|
|
59
|
-
{
|
|
60
|
-
unsigned int j = 0;
|
|
61
|
-
/* increment encryption nonce */
|
|
62
|
-
while (j < 8 && !++cx->nonce[j])
|
|
63
|
-
++j;
|
|
64
|
-
/* encrypt the nonce to form next xor buffer */
|
|
65
|
-
aes_encrypt(cx->nonce, cx->encr_bfr, cx->encr_ctx);
|
|
66
|
-
pos = 0;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
data[i++] ^= cx->encr_bfr[pos++];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
cx->encr_pos = pos;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
int fcrypt_init(
|
|
76
|
-
int mode, /* the mode to be used (input) */
|
|
77
|
-
const unsigned char pwd[], /* the user specified password (input) */
|
|
78
|
-
unsigned int pwd_len, /* the length of the password (input) */
|
|
79
|
-
const unsigned char salt[], /* the salt (input) */
|
|
80
|
-
#ifdef PASSWORD_VERIFIER
|
|
81
|
-
unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */
|
|
82
|
-
#endif
|
|
83
|
-
fcrypt_ctx cx[1]) /* the file encryption context (output) */
|
|
84
|
-
{ unsigned char kbuf[2 * MAX_KEY_LENGTH + PWD_VER_LENGTH];
|
|
85
|
-
|
|
86
|
-
if (pwd_len > MAX_PWD_LENGTH)
|
|
87
|
-
return PASSWORD_TOO_LONG;
|
|
88
|
-
|
|
89
|
-
if (mode < 1 || mode > 3)
|
|
90
|
-
return BAD_MODE;
|
|
91
|
-
|
|
92
|
-
cx->mode = mode;
|
|
93
|
-
cx->pwd_len = pwd_len;
|
|
94
|
-
|
|
95
|
-
/* derive the encryption and authentication keys and the password verifier */
|
|
96
|
-
derive_key(pwd, pwd_len, salt, SALT_LENGTH(mode), KEYING_ITERATIONS,
|
|
97
|
-
kbuf, 2 * KEY_LENGTH(mode) + PWD_VER_LENGTH);
|
|
98
|
-
|
|
99
|
-
/* initialise the encryption nonce and buffer pos */
|
|
100
|
-
cx->encr_pos = AES_BLOCK_SIZE;
|
|
101
|
-
/* if we need a random component in the encryption */
|
|
102
|
-
/* nonce, this is where it would have to be set */
|
|
103
|
-
memset(cx->nonce, 0, AES_BLOCK_SIZE * sizeof(unsigned char));
|
|
104
|
-
|
|
105
|
-
/* initialise for encryption using key 1 */
|
|
106
|
-
aes_encrypt_key(kbuf, KEY_LENGTH(mode), cx->encr_ctx);
|
|
107
|
-
|
|
108
|
-
/* initialise for authentication using key 2 */
|
|
109
|
-
hmac_sha_begin(HMAC_SHA1, cx->auth_ctx);
|
|
110
|
-
hmac_sha_key(kbuf + KEY_LENGTH(mode), KEY_LENGTH(mode), cx->auth_ctx);
|
|
111
|
-
|
|
112
|
-
#ifdef PASSWORD_VERIFIER
|
|
113
|
-
memcpy(pwd_ver, kbuf + 2 * KEY_LENGTH(mode), PWD_VER_LENGTH);
|
|
114
|
-
#endif
|
|
115
|
-
|
|
116
|
-
return GOOD_RETURN;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/* perform 'in place' encryption and authentication */
|
|
120
|
-
|
|
121
|
-
void fcrypt_encrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1])
|
|
122
|
-
{
|
|
123
|
-
encr_data(data, data_len, cx);
|
|
124
|
-
hmac_sha_data(data, data_len, cx->auth_ctx);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/* perform 'in place' authentication and decryption */
|
|
128
|
-
|
|
129
|
-
void fcrypt_decrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1])
|
|
130
|
-
{
|
|
131
|
-
hmac_sha_data(data, data_len, cx->auth_ctx);
|
|
132
|
-
encr_data(data, data_len, cx);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/* close encryption/decryption and return the MAC value */
|
|
136
|
-
|
|
137
|
-
int fcrypt_end(unsigned char mac[], fcrypt_ctx cx[1])
|
|
138
|
-
{
|
|
139
|
-
hmac_sha_end(mac, MAC_LENGTH(cx->mode), cx->auth_ctx);
|
|
140
|
-
return MAC_LENGTH(cx->mode); /* return MAC length in bytes */
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
#if defined(__cplusplus)
|
|
144
|
-
}
|
|
145
|
-
#endif
|
|
1
|
+
/*
|
|
2
|
+
---------------------------------------------------------------------------
|
|
3
|
+
Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK.
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
LICENSE TERMS
|
|
7
|
+
|
|
8
|
+
The free distribution and use of this software in both source and binary
|
|
9
|
+
form is allowed (with or without changes) provided that:
|
|
10
|
+
|
|
11
|
+
1. distributions of this source code include the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer;
|
|
13
|
+
|
|
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;
|
|
17
|
+
|
|
18
|
+
3. the copyright holder's name is not used to endorse products
|
|
19
|
+
built using this software without specific written permission.
|
|
20
|
+
|
|
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.
|
|
24
|
+
|
|
25
|
+
DISCLAIMER
|
|
26
|
+
|
|
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
|
|
32
|
+
|
|
33
|
+
This file implements password based file encryption and authentication
|
|
34
|
+
using AES in CTR mode, HMAC-SHA1 authentication and RFC2898 password
|
|
35
|
+
based key derivation.
|
|
36
|
+
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
#include <string.h>
|
|
40
|
+
|
|
41
|
+
#include "fileenc.h"
|
|
42
|
+
|
|
43
|
+
#if defined(__cplusplus)
|
|
44
|
+
extern "C"
|
|
45
|
+
{
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
/* subroutine for data encryption/decryption */
|
|
49
|
+
/* this could be speeded up a lot by aligning */
|
|
50
|
+
/* buffers and using 32 bit operations */
|
|
51
|
+
|
|
52
|
+
static void encr_data(unsigned char data[], unsigned long d_len, fcrypt_ctx cx[1])
|
|
53
|
+
{
|
|
54
|
+
unsigned int i = 0, pos = cx->encr_pos;
|
|
55
|
+
|
|
56
|
+
while (i < d_len)
|
|
57
|
+
{
|
|
58
|
+
if (pos == AES_BLOCK_SIZE)
|
|
59
|
+
{
|
|
60
|
+
unsigned int j = 0;
|
|
61
|
+
/* increment encryption nonce */
|
|
62
|
+
while (j < 8 && !++cx->nonce[j])
|
|
63
|
+
++j;
|
|
64
|
+
/* encrypt the nonce to form next xor buffer */
|
|
65
|
+
aes_encrypt(cx->nonce, cx->encr_bfr, cx->encr_ctx);
|
|
66
|
+
pos = 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
data[i++] ^= cx->encr_bfr[pos++];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
cx->encr_pos = pos;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
int fcrypt_init(
|
|
76
|
+
int mode, /* the mode to be used (input) */
|
|
77
|
+
const unsigned char pwd[], /* the user specified password (input) */
|
|
78
|
+
unsigned int pwd_len, /* the length of the password (input) */
|
|
79
|
+
const unsigned char salt[], /* the salt (input) */
|
|
80
|
+
#ifdef PASSWORD_VERIFIER
|
|
81
|
+
unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */
|
|
82
|
+
#endif
|
|
83
|
+
fcrypt_ctx cx[1]) /* the file encryption context (output) */
|
|
84
|
+
{ unsigned char kbuf[2 * MAX_KEY_LENGTH + PWD_VER_LENGTH];
|
|
85
|
+
|
|
86
|
+
if (pwd_len > MAX_PWD_LENGTH)
|
|
87
|
+
return PASSWORD_TOO_LONG;
|
|
88
|
+
|
|
89
|
+
if (mode < 1 || mode > 3)
|
|
90
|
+
return BAD_MODE;
|
|
91
|
+
|
|
92
|
+
cx->mode = mode;
|
|
93
|
+
cx->pwd_len = pwd_len;
|
|
94
|
+
|
|
95
|
+
/* derive the encryption and authentication keys and the password verifier */
|
|
96
|
+
derive_key(pwd, pwd_len, salt, SALT_LENGTH(mode), KEYING_ITERATIONS,
|
|
97
|
+
kbuf, 2 * KEY_LENGTH(mode) + PWD_VER_LENGTH);
|
|
98
|
+
|
|
99
|
+
/* initialise the encryption nonce and buffer pos */
|
|
100
|
+
cx->encr_pos = AES_BLOCK_SIZE;
|
|
101
|
+
/* if we need a random component in the encryption */
|
|
102
|
+
/* nonce, this is where it would have to be set */
|
|
103
|
+
memset(cx->nonce, 0, AES_BLOCK_SIZE * sizeof(unsigned char));
|
|
104
|
+
|
|
105
|
+
/* initialise for encryption using key 1 */
|
|
106
|
+
aes_encrypt_key(kbuf, KEY_LENGTH(mode), cx->encr_ctx);
|
|
107
|
+
|
|
108
|
+
/* initialise for authentication using key 2 */
|
|
109
|
+
hmac_sha_begin(HMAC_SHA1, cx->auth_ctx);
|
|
110
|
+
hmac_sha_key(kbuf + KEY_LENGTH(mode), KEY_LENGTH(mode), cx->auth_ctx);
|
|
111
|
+
|
|
112
|
+
#ifdef PASSWORD_VERIFIER
|
|
113
|
+
memcpy(pwd_ver, kbuf + 2 * KEY_LENGTH(mode), PWD_VER_LENGTH);
|
|
114
|
+
#endif
|
|
115
|
+
|
|
116
|
+
return GOOD_RETURN;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* perform 'in place' encryption and authentication */
|
|
120
|
+
|
|
121
|
+
void fcrypt_encrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1])
|
|
122
|
+
{
|
|
123
|
+
encr_data(data, data_len, cx);
|
|
124
|
+
hmac_sha_data(data, data_len, cx->auth_ctx);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* perform 'in place' authentication and decryption */
|
|
128
|
+
|
|
129
|
+
void fcrypt_decrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1])
|
|
130
|
+
{
|
|
131
|
+
hmac_sha_data(data, data_len, cx->auth_ctx);
|
|
132
|
+
encr_data(data, data_len, cx);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* close encryption/decryption and return the MAC value */
|
|
136
|
+
|
|
137
|
+
int fcrypt_end(unsigned char mac[], fcrypt_ctx cx[1])
|
|
138
|
+
{
|
|
139
|
+
hmac_sha_end(mac, MAC_LENGTH(cx->mode), cx->auth_ctx);
|
|
140
|
+
return MAC_LENGTH(cx->mode); /* return MAC length in bytes */
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
#if defined(__cplusplus)
|
|
144
|
+
}
|
|
145
|
+
#endif
|
package/src/ios/aes/fileenc.h
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
/*
|
|
2
|
-
---------------------------------------------------------------------------
|
|
3
|
-
Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK.
|
|
4
|
-
All rights reserved.
|
|
5
|
-
|
|
6
|
-
LICENSE TERMS
|
|
7
|
-
|
|
8
|
-
The free distribution and use of this software in both source and binary
|
|
9
|
-
form is allowed (with or without changes) provided that:
|
|
10
|
-
|
|
11
|
-
1. distributions of this source code include the above copyright
|
|
12
|
-
notice, this list of conditions and the following disclaimer;
|
|
13
|
-
|
|
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;
|
|
17
|
-
|
|
18
|
-
3. the copyright holder's name is not used to endorse products
|
|
19
|
-
built using this software without specific written permission.
|
|
20
|
-
|
|
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.
|
|
24
|
-
|
|
25
|
-
DISCLAIMER
|
|
26
|
-
|
|
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
|
|
32
|
-
|
|
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.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
#ifndef _FENC_H
|
|
39
|
-
#define _FENC_H
|
|
40
|
-
|
|
41
|
-
#include "aes.h"
|
|
42
|
-
#include "hmac.h"
|
|
43
|
-
#include "pwd2key.h"
|
|
44
|
-
|
|
45
|
-
#define PASSWORD_VERIFIER
|
|
46
|
-
|
|
47
|
-
#define MAX_KEY_LENGTH 32
|
|
48
|
-
#define MAX_PWD_LENGTH 128
|
|
49
|
-
#define MAX_SALT_LENGTH 16
|
|
50
|
-
#define KEYING_ITERATIONS 1000
|
|
51
|
-
|
|
52
|
-
#ifdef PASSWORD_VERIFIER
|
|
53
|
-
#define PWD_VER_LENGTH 2
|
|
54
|
-
#else
|
|
55
|
-
#define PWD_VER_LENGTH 0
|
|
56
|
-
#endif
|
|
57
|
-
|
|
58
|
-
#define GOOD_RETURN 0
|
|
59
|
-
#define PASSWORD_TOO_LONG -100
|
|
60
|
-
#define BAD_MODE -101
|
|
61
|
-
|
|
62
|
-
/*
|
|
63
|
-
Field lengths (in bytes) versus File Encryption Mode (0 < mode < 4)
|
|
64
|
-
|
|
65
|
-
Mode Key Salt MAC Overhead
|
|
66
|
-
1 16 8 10 18
|
|
67
|
-
2 24 12 10 22
|
|
68
|
-
3 32 16 10 26
|
|
69
|
-
|
|
70
|
-
The following macros assume that the mode value is correct.
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
#define KEY_LENGTH(mode) (8 * (mode & 3) + 8)
|
|
74
|
-
#define SALT_LENGTH(mode) (4 * (mode & 3) + 4)
|
|
75
|
-
#define MAC_LENGTH(mode) (10)
|
|
76
|
-
|
|
77
|
-
/* the context for file encryption */
|
|
78
|
-
|
|
79
|
-
#if defined(__cplusplus)
|
|
80
|
-
extern "C"
|
|
81
|
-
{
|
|
82
|
-
#endif
|
|
83
|
-
|
|
84
|
-
typedef struct
|
|
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 */
|
|
92
|
-
} fcrypt_ctx;
|
|
93
|
-
|
|
94
|
-
/* initialise file encryption or decryption */
|
|
95
|
-
|
|
96
|
-
int fcrypt_init(
|
|
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) */
|
|
103
|
-
#endif
|
|
104
|
-
fcrypt_ctx cx[1]); /* the file encryption context (output) */
|
|
105
|
-
|
|
106
|
-
/* perform 'in place' encryption or decryption and authentication */
|
|
107
|
-
|
|
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]);
|
|
110
|
-
|
|
111
|
-
/* close encryption/decryption and return the MAC value */
|
|
112
|
-
/* the return value is the length of the MAC */
|
|
113
|
-
|
|
114
|
-
int fcrypt_end(unsigned char mac[], /* the MAC value (output) */
|
|
115
|
-
fcrypt_ctx cx[1]); /* the context (input) */
|
|
116
|
-
|
|
117
|
-
#if defined(__cplusplus)
|
|
118
|
-
}
|
|
119
|
-
#endif
|
|
120
|
-
|
|
121
|
-
#endif
|
|
1
|
+
/*
|
|
2
|
+
---------------------------------------------------------------------------
|
|
3
|
+
Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK.
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
LICENSE TERMS
|
|
7
|
+
|
|
8
|
+
The free distribution and use of this software in both source and binary
|
|
9
|
+
form is allowed (with or without changes) provided that:
|
|
10
|
+
|
|
11
|
+
1. distributions of this source code include the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer;
|
|
13
|
+
|
|
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;
|
|
17
|
+
|
|
18
|
+
3. the copyright holder's name is not used to endorse products
|
|
19
|
+
built using this software without specific written permission.
|
|
20
|
+
|
|
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.
|
|
24
|
+
|
|
25
|
+
DISCLAIMER
|
|
26
|
+
|
|
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
|
|
32
|
+
|
|
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.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
#ifndef _FENC_H
|
|
39
|
+
#define _FENC_H
|
|
40
|
+
|
|
41
|
+
#include "aes.h"
|
|
42
|
+
#include "hmac.h"
|
|
43
|
+
#include "pwd2key.h"
|
|
44
|
+
|
|
45
|
+
#define PASSWORD_VERIFIER
|
|
46
|
+
|
|
47
|
+
#define MAX_KEY_LENGTH 32
|
|
48
|
+
#define MAX_PWD_LENGTH 128
|
|
49
|
+
#define MAX_SALT_LENGTH 16
|
|
50
|
+
#define KEYING_ITERATIONS 1000
|
|
51
|
+
|
|
52
|
+
#ifdef PASSWORD_VERIFIER
|
|
53
|
+
#define PWD_VER_LENGTH 2
|
|
54
|
+
#else
|
|
55
|
+
#define PWD_VER_LENGTH 0
|
|
56
|
+
#endif
|
|
57
|
+
|
|
58
|
+
#define GOOD_RETURN 0
|
|
59
|
+
#define PASSWORD_TOO_LONG -100
|
|
60
|
+
#define BAD_MODE -101
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
Field lengths (in bytes) versus File Encryption Mode (0 < mode < 4)
|
|
64
|
+
|
|
65
|
+
Mode Key Salt MAC Overhead
|
|
66
|
+
1 16 8 10 18
|
|
67
|
+
2 24 12 10 22
|
|
68
|
+
3 32 16 10 26
|
|
69
|
+
|
|
70
|
+
The following macros assume that the mode value is correct.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
#define KEY_LENGTH(mode) (8 * (mode & 3) + 8)
|
|
74
|
+
#define SALT_LENGTH(mode) (4 * (mode & 3) + 4)
|
|
75
|
+
#define MAC_LENGTH(mode) (10)
|
|
76
|
+
|
|
77
|
+
/* the context for file encryption */
|
|
78
|
+
|
|
79
|
+
#if defined(__cplusplus)
|
|
80
|
+
extern "C"
|
|
81
|
+
{
|
|
82
|
+
#endif
|
|
83
|
+
|
|
84
|
+
typedef struct
|
|
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 */
|
|
92
|
+
} fcrypt_ctx;
|
|
93
|
+
|
|
94
|
+
/* initialise file encryption or decryption */
|
|
95
|
+
|
|
96
|
+
int fcrypt_init(
|
|
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) */
|
|
103
|
+
#endif
|
|
104
|
+
fcrypt_ctx cx[1]); /* the file encryption context (output) */
|
|
105
|
+
|
|
106
|
+
/* perform 'in place' encryption or decryption and authentication */
|
|
107
|
+
|
|
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]);
|
|
110
|
+
|
|
111
|
+
/* close encryption/decryption and return the MAC value */
|
|
112
|
+
/* the return value is the length of the MAC */
|
|
113
|
+
|
|
114
|
+
int fcrypt_end(unsigned char mac[], /* the MAC value (output) */
|
|
115
|
+
fcrypt_ctx cx[1]); /* the context (input) */
|
|
116
|
+
|
|
117
|
+
#if defined(__cplusplus)
|
|
118
|
+
}
|
|
119
|
+
#endif
|
|
120
|
+
|
|
121
|
+
#endif
|