Skip to content

Commit

Permalink
Move export flags to be tr31_export() parameter instead
Browse files Browse the repository at this point in the history
  • Loading branch information
leonlynch committed Nov 1, 2023
1 parent 32752ba commit 97c590f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/tr31-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1474,9 +1474,6 @@ static int do_tr31_export(const struct tr31_tool_options_t* options)
return r;
}

// apply export flags
tr31_ctx.export_flags = options->export_flags;

// populate key block protection key
r = populate_kbpk(options, export_format_version, &kbpk);
if (r) {
Expand All @@ -1486,7 +1483,7 @@ static int do_tr31_export(const struct tr31_tool_options_t* options)
// export TR-31 key block
key_block_len = 16384;
key_block = malloc(key_block_len);
r = tr31_export(&tr31_ctx, &kbpk, key_block, key_block_len);
r = tr31_export(&tr31_ctx, &kbpk, options->export_flags, key_block, key_block_len);
if (r) {
fprintf(stderr, "TR-31 export error %d: %s\n", r, tr31_get_error_string(r));
return 1;
Expand Down
3 changes: 2 additions & 1 deletion src/tr31.c
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,7 @@ int tr31_import(
int tr31_export(
const struct tr31_ctx_t* ctx,
const struct tr31_key_t* kbpk,
uint32_t flags,
char* key_block,
size_t key_block_buf_len
)
Expand Down Expand Up @@ -2172,7 +2173,7 @@ int tr31_export(
// - state.flags
// - state.enc_block_size
// - state.authenticator_length
r = tr31_state_init(ctx->export_flags, ctx->version, &state);
r = tr31_state_init(flags, ctx->version, &state);
if (r) {
// return error value as-is
return r;
Expand Down
6 changes: 3 additions & 3 deletions src/tr31.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ enum tr31_key_version_t {

// TR-31 export flags
#define TR31_EXPORT_NO_KEY_LENGTH_OBFUSCATION (0x01) ///< Disable ANSI X9.143 key length obfuscation during key block export
#define TR31_EXPORT_ZERO_OPT_BLOCK_PB (0x02) ///< Fill optional block PB using zeros instead of random characters during TR-31 export.
#define TR31_EXPORT_ZERO_OPT_BLOCK_PB (0x02) ///< Fill optional block PB using zeros instead of random characters during key block export.

/// TR-31 key object
struct tr31_key_t {
Expand Down Expand Up @@ -273,8 +273,6 @@ struct tr31_ctx_t {

size_t opt_blocks_count; ///< TR-31 number of optional blocks
struct tr31_opt_ctx_t* opt_blocks; ///< TR-31 optional block context objects

uint32_t export_flags; ///< Flags used during TR-31 export
};

/// TR-31 library errors
Expand Down Expand Up @@ -886,13 +884,15 @@ int tr31_import(
*
* @param ctx TR-31 context object input
* @param kbpk TR-31 key block protection key.
* @param flags TR-31 export flags.
* @param key_block TR-31 key block output. Will contain printable ASCII characters and will be null-terminated.
* @param key_block_buf_len TR-31 key block output buffer length.
* @return Zero for success. Less than zero for internal error. Greater than zero for data error. See @ref tr31_error_t
*/
int tr31_export(
const struct tr31_ctx_t* ctx,
const struct tr31_key_t* kbpk,
uint32_t flags,
char* key_block,
size_t key_block_buf_len
);
Expand Down
3 changes: 1 addition & 2 deletions test/tr31_export_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,6 @@ int main(void)
fprintf(stderr, "tr31_init() error %d: %s\n", r, tr31_get_error_string(r));
goto exit;
}
test_tr31.export_flags = test[i].export_flags;
if (test[i].cert_base64_count) {
for (size_t cert_idx = 0; cert_idx < test[i].cert_base64_count; ++cert_idx) {
r = tr31_opt_block_add_CT(
Expand Down Expand Up @@ -877,7 +876,7 @@ int main(void)
}

// Export key block
r = tr31_export(&test_tr31, &test[i].kbpk, key_block, sizeof(key_block));
r = tr31_export(&test_tr31, &test[i].kbpk, test[i].export_flags, key_block, sizeof(key_block));
if (r) {
fprintf(stderr, "tr31_export() error %d: %s\n", r, tr31_get_error_string(r));
goto exit;
Expand Down

0 comments on commit 97c590f

Please sign in to comment.