summaryrefslogtreecommitdiffstats
path: root/xlators/encryption/crypt/src/metadata.h
blob: a92f149ef506f1bada6d108ac7d821b6d7a6f47c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
  Copyright (c) 2008-2013 Red Hat, Inc. <http://www.redhat.com>
  This file is part of GlusterFS.

  This file is licensed to you under your choice of the GNU Lesser
  General Public License, version 3 or any later version (LGPLv3 or
  later), or the GNU General Public License, version 2 (GPLv2), in all
  cases as published by the Free Software Foundation.
*/

#ifndef __METADATA_H__
#define __METADATA_H__

#define NMTD_8_MAC_SIZE   (8)
#define EMTD_8_MAC_SIZE   (8)

typedef uint8_t nmtd_8_mac_t[NMTD_8_MAC_SIZE];
typedef uint8_t emtd_8_mac_t[EMTD_8_MAC_SIZE] ;

/*
 * Version "v1" of file's metadata.
 * Metadata of this version has 4 components:
 * 
 * 1) EMTD (Encrypted part of MeTaData);
 * 2) NMTD (Non-encrypted part of MeTaData);
 * 3) EMTD_MAC; (EMTD Message Authentication Code);
 * 4) Array of per-link NMTD MACs (for every (hard)link it includes
 *    exactly one MAC)
 */
struct mtd_format_v1 {
	/* EMTD, encrypted part of meta-data */
	uint8_t            alg_id;  /* cipher algorithm id (only AES for now) */
        uint8_t            mode_id; /* cipher mode id; (only XTS for now) */
	uint8_t            block_bits; /* encoded block size */
	uint8_t            minor_id; /* client translator id */
	uint8_t            dkey_factor; /* encoded size of the data key */
	/* MACs */
	emtd_8_mac_t       gmac; /* MAC of the encrypted meta-data, 8 bytes */
	nmtd_8_mac_t       omac; /* per-link MACs of the non-encrypted
				  * meta-data: at least one such MAC is always
				  * present */
} __attribute__((packed));

/*
 * NMTD, the non-encrypted part of metadata of version "v1"
 * is file's gfid, which is generated on trusted machines.
 */
#define SIZE_OF_NMTD_V1 (sizeof(uuid_t))
#define SIZE_OF_EMTD_V1 (offsetof(struct mtd_format_v1, gmac) -		\
			 offsetof(struct mtd_format_v1, alg_id))
#define SIZE_OF_NMTD_V1_MAC (NMTD_8_MAC_SIZE)
#define SIZE_OF_EMTD_V1_MAC (EMTD_8_MAC_SIZE)

static inline unsigned char *get_EMTD_V1(struct mtd_format_v1 *format)
{
        return &format->alg_id;
}

static inline unsigned char *get_NMTD_V1(struct crypt_inode_info *info)
{
        return info->oid;
}

static inline unsigned char *get_EMTD_V1_MAC(struct mtd_format_v1 *format)
{
        return format->gmac;
}

static inline unsigned char *get_NMTD_V1_MAC(struct mtd_format_v1 *format)
{
        return format->omac;
}

#endif /* __METADATA_H__ */