2 * Copyright (c) 2011 Alex Hornung <alex@alexhornung.com>.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include "tcplay_api.h"
38 tc_api_init(int verbose)
42 tc_internal_verbose = verbose;
44 if ((error = tc_play_init()) != 0)
53 check_and_purge_safe_mem();
58 tc_api_get_error_msg(void)
60 return tc_internal_log_buffer;
64 tc_api_get_summary(void)
66 if (summary_fn != NULL) {
68 return tc_internal_log_buffer;
75 tc_api_create_volume(tc_api_opts *api_opts)
77 int nkeyfiles, n_hkeyfiles = 0;
81 if ((api_opts == NULL) ||
82 (api_opts->tc_device == NULL)) {
87 if ((err = tc_api_check_cipher(api_opts)) != TC_OK)
90 if ((err = tc_api_check_prf_hash(api_opts)) != TC_OK)
93 for (nkeyfiles = 0; (nkeyfiles < MAX_KEYFILES) &&
94 (api_opts->tc_keyfiles != NULL) &&
95 (api_opts->tc_keyfiles[nkeyfiles] != NULL); nkeyfiles++)
100 if (api_opts->tc_size_hidden_in_bytes > 0) {
102 for (n_hkeyfiles = 0; (n_hkeyfiles < MAX_KEYFILES) &&
103 (api_opts->tc_keyfiles_hidden != NULL) &&
104 (api_opts->tc_keyfiles_hidden[n_hkeyfiles] != NULL);
109 err = create_volume(api_opts->tc_device, create_hidden,
110 api_opts->tc_keyfiles, nkeyfiles,
111 api_opts->tc_keyfiles_hidden, n_hkeyfiles,
112 check_prf_algo(api_opts->tc_prf_hash, 1),
113 check_cipher_chain(api_opts->tc_cipher, 1),
114 check_prf_algo(api_opts->tc_prf_hash_hidden, 1),
115 check_cipher_chain(api_opts->tc_cipher_hidden, 1),
116 api_opts->tc_passphrase, api_opts->tc_passphrase_hidden,
117 api_opts->tc_size_hidden_in_bytes, 0 /* non-interactive */);
119 return (err) ? TC_ERR : TC_OK;
123 tc_api_map_volume(tc_api_opts *api_opts)
128 if ((api_opts == NULL) ||
129 (api_opts->tc_device == NULL)) {
134 for (nkeyfiles = 0; (nkeyfiles < MAX_KEYFILES) &&
135 (api_opts->tc_keyfiles != NULL) &&
136 (api_opts->tc_keyfiles[nkeyfiles] != NULL); nkeyfiles++)
139 err = map_volume(api_opts->tc_map_name, api_opts->tc_device,
140 /* sflag */ 0, /* sys_dev */ NULL,
141 /* protect_hidden */ 0, api_opts->tc_keyfiles, nkeyfiles,
142 /* h_keyfiles[] */ NULL, /* n_hkeyfiles */ 0,
143 api_opts->tc_passphrase, /* passphrase_hidden */ NULL,
144 api_opts->tc_interactive_prompt, api_opts->tc_password_retries,
145 (time_t)api_opts->tc_prompt_timeout);
147 return (err) ? TC_ERR : TC_OK;
151 tc_api_unmap_volume(tc_api_opts *api_opts)
155 if ((api_opts == NULL) ||
156 (api_opts->tc_map_name == NULL)) {
161 err = dm_teardown(api_opts->tc_map_name, api_opts->tc_device);
162 return (err) ? TC_ERR : TC_OK;
166 tc_api_check_cipher(tc_api_opts *api_opts)
168 struct tc_cipher_chain *chain;
170 if (api_opts == NULL || api_opts->tc_cipher == NULL) {
175 if ((chain = check_cipher_chain(api_opts->tc_cipher, 1)) != NULL)
183 tc_api_check_prf_hash(tc_api_opts *api_opts)
185 struct pbkdf_prf_algo *prf_hash;
187 if (api_opts == NULL || api_opts->tc_prf_hash == NULL) {
192 if ((prf_hash = check_prf_algo(api_opts->tc_prf_hash, 1)) != NULL)