Initial release for Tizen
[platform/upstream/ecryptfs-utils.git] / tests / userspace / verify-passphrase-sig / test.c
1 /**
2  * test.c: Check for expected output from generate_passphrase_sig() function
3  * Author: Tyler Hicks <tyhicks@canonical.com>
4  *
5  * Copyright (C) 2012 Canonical, Ltd.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA
21  */
22
23 #include <errno.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include "../../src/include/ecryptfs.h"
27
28 #define ECRYPTFS_MAX_KEY_HEX_BYTES (ECRYPTFS_MAX_KEY_BYTES * 2)
29
30 void usage(const char *name)
31 {
32         fprintf(stderr, "%s PASSPHRASE SALT_HEX EXPECTED_SIG_HEX "
33                 "EXPECTED_FEKEK_HEX\n", name);
34 }
35
36 int main(int argc, char *argv[])
37 {
38         char sig_hex[ECRYPTFS_PASSWORD_SIG_SIZE + 1];
39         char fekek[ECRYPTFS_MAX_KEY_BYTES + 1];
40         char fekek_hex[ECRYPTFS_MAX_KEY_HEX_BYTES + 1];
41         char salt[ECRYPTFS_SALT_SIZE + 1];
42         int rc;
43
44         if (argc != 5 ||
45             strlen(argv[2]) != ECRYPTFS_SALT_SIZE_HEX ||
46             strlen(argv[3]) != ECRYPTFS_PASSWORD_SIG_SIZE ||
47             strlen(argv[4]) != ECRYPTFS_MAX_KEY_HEX_BYTES) {
48                 usage(argv[0]);
49                 return EINVAL;
50         }
51
52         memset(sig_hex, 0, ECRYPTFS_PASSWORD_SIG_SIZE + 1);
53         memset(fekek, 0, ECRYPTFS_MAX_KEY_BYTES + 1);
54         memset(fekek_hex, 0, ECRYPTFS_MAX_KEY_HEX_BYTES + 1);
55         memset(salt, 0, ECRYPTFS_SALT_SIZE + 1);
56         from_hex(salt, argv[2], ECRYPTFS_SALT_SIZE);
57
58         rc = generate_passphrase_sig(sig_hex, fekek, salt, argv[1]);
59         if (rc)
60                 return rc;
61
62         to_hex(fekek_hex, fekek, ECRYPTFS_MAX_KEY_BYTES);
63         if (strcmp(sig_hex, argv[3]) ||
64             strcmp(fekek_hex, argv[4])) {
65                 return EINVAL;
66         }
67
68         return 0;
69 }
70