2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 #ifndef __ECRYPTFS_H__
18 #define __ECRYPTFS_H__
20 #include <sys/types.h>
23 // this is versions of ecryptfs module
24 #define ECRYPTFS_MAJOR_VERSION 0x00
25 #define ECRYPTFS_MINOR_VERSION 0x04
26 #define ECRYPTFS_VERSION ((ECRYPTFS_MAJOR_VERSION << 8) | ECRYPTFS_MINOR_VERSION)
28 #define ECRYPTFS_SALT_SIZE 8
29 #define ECRYPTFS_SIGNATURE_SIZE 16
30 #define ECRYPTFS_MAX_KEY_SIZE 64
31 #define ECRYPTFS_MAX_KEY_MOD_NAME_SIZE 16
32 #define ECRYPTFS_MAX_ENCRYPTED_KEY_SIZE 512
34 struct EcryptfsPassword {
36 PersistentPassword = 0x01,
37 SessionKeyEncryptionKeySet = 0x02
41 int32_t hashAlgorithm;
42 int32_t hashIterations;
43 int32_t sessionKeyEncryptionKeySize;
45 uint8_t sessionKeyEncryptionKey[ECRYPTFS_MAX_KEY_SIZE];
46 uint8_t signature[ECRYPTFS_SIGNATURE_SIZE + 1];
47 uint8_t salt[ECRYPTFS_SALT_SIZE];
50 struct EcryptfsPrivateKey {
53 uint8_t signature[ECRYPTFS_SIGNATURE_SIZE + 1];
54 char keyModAlias[ECRYPTFS_MAX_KEY_MOD_NAME_SIZE + 1];
58 struct EcryptfsSessionKey {
60 UserspaceShouldTryToDecrypt = 0x00000001,
61 UserspaceShouldTryToEncrypt = 0x00000002,
62 ContainsDecryptedKey = 0x00000004,
63 ContainsEncryptedKey = 0x00000008
67 int32_t encryptedKeySize;
68 int32_t decryptedKeySize;
69 uint8_t encryptedKey[ECRYPTFS_MAX_ENCRYPTED_KEY_SIZE];
70 uint8_t decryptedKey[ECRYPTFS_MAX_KEY_SIZE];
73 : flags(0), encryptedKeySize(0), decryptedKeySize(0),
74 encryptedKey{0, }, decryptedKey{0, }
76 } __attribute__((packed));
78 struct EcryptfsPayload {
90 EcryptfsSessionKey sessionKey;
93 EcryptfsPassword password;
94 EcryptfsPrivateKey privateKey;
97 EcryptfsPayload(Type type)
98 : version(ECRYPTFS_VERSION), type(type), flags(0), reserved{0, }
100 ::memset(&token, 0, sizeof(token));
102 } __attribute__((packed));