Skip to content

Commit 0e27119

Browse files
committed
Issue 136: Add a flag to Disable/Enable SVP functionality
Reason for change: Disable/Enable SVP functionality using flag Risks: None Priority: P1
1 parent bb6c082 commit 0e27119

75 files changed

Lines changed: 614 additions & 310 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

reference/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2020-2023 Comcast Cable Communications Management, LLC
2+
# Copyright 2020-2025 Comcast Cable Communications Management, LLC
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -19,8 +19,15 @@ cmake_minimum_required(VERSION 3.16)
1919

2020
project(tasecureapi)
2121

22-
option(BUILD_TESTS "Builds and installs the unit tests" ON)
23-
option(BUILD_DOC "Build documentation" ON)
22+
option(BUILD_TESTS "Builds and installs the unit tests" ON)
23+
option(BUILD_DOC "Build documentation" ON)
24+
option(ENABLE_SVP "Build SecAPI with SVP" OFF)
25+
26+
if(ENABLE_SVP)
27+
message(STATUS "ENABLE_SVP is ON: Building SecAPI SVP functionality")
28+
else()
29+
message(STATUS "ENABLE_SVP is OFF: Building SecAPI without SVP functionality")
30+
endif()
2431

2532
if(${BUILD_TESTS})
2633
# Download and unpack googletest at configure time

reference/src/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2020-2023 Comcast Cable Communications Management, LLC
2+
# Copyright 2020-2025 Comcast Cable Communications Management, LLC
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -44,6 +44,10 @@ if (DEFINED DISABLE_CENC_TIMING)
4444
set(CMAKE_C_FLAGS "-DDISABLE_CENC_TIMING ${CMAKE_C_FLAGS}")
4545
endif ()
4646

47+
if (ENABLE_SVP)
48+
set(CMAKE_CXX_FLAGS "-DENABLE_SVP ${CMAKE_CXX_FLAGS}")
49+
set(CMAKE_C_FLAGS "-DENABLE_SVP ${CMAKE_C_FLAGS}")
50+
endif ()
4751
add_subdirectory(client)
4852
add_subdirectory(clientimpl)
4953
add_subdirectory(taimpl)

reference/src/client/CMakeLists.txt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2020-2023 Comcast Cable Communications Management, LLC
2+
# Copyright 2020-2025 Comcast Cable Communications Management, LLC
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -128,11 +128,10 @@ target_clangformat_setup(saclient)
128128

129129
if (BUILD_TESTS)
130130
# Google test
131-
add_executable(saclienttest
131+
set(SACLIENT_TEST_SOURCES
132132
test/client_test_helpers.cpp
133133
test/client_test_helpers.h
134134
test/environment.cpp
135-
test/sa_client_thread_test.cpp
136135
test/sa_crypto_cipher_common.h
137136
test/sa_crypto_cipher_common.cpp
138137
test/sa_crypto_cipher_init.cpp
@@ -277,15 +276,25 @@ if (BUILD_TESTS)
277276
test/sa_provider_mac.cpp
278277
test/sa_provider_pkcs7.cpp
279278
test/sa_provider_signature.cpp
280-
test/sa_svp_buffer_alloc.cpp
281-
test/sa_svp_buffer_check.cpp
282-
test/sa_svp_buffer_copy.cpp
283-
test/sa_svp_buffer_create.cpp
284-
test/sa_svp_buffer_release.cpp
285-
test/sa_svp_buffer_write.cpp
286-
test/sa_svp_key_check.cpp
287-
test/sa_svp_common.cpp
288-
test/sa_svp_common.h)
279+
)
280+
# Conditionally add files if ENABLE_SVP is defined
281+
if(ENABLE_SVP)
282+
list(APPEND SACLIENT_TEST_SOURCES
283+
test/sa_client_thread_test.cpp
284+
test/sa_svp_buffer_alloc.cpp
285+
test/sa_svp_buffer_check.cpp
286+
test/sa_svp_buffer_copy.cpp
287+
test/sa_svp_buffer_create.cpp
288+
test/sa_svp_buffer_release.cpp
289+
test/sa_svp_buffer_write.cpp
290+
test/sa_svp_key_check.cpp
291+
test/sa_svp_common.cpp
292+
test/sa_svp_common.h
293+
)
294+
endif()
295+
296+
297+
add_executable(saclienttest ${SACLIENT_TEST_SOURCES})
289298

290299
target_compile_options(saclienttest PRIVATE -Werror -Wall -Wextra -Wno-type-limits -Wno-unused-parameter
291300
-Wno-deprecated-declarations)

reference/src/client/include/sa_svp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 Comcast Cable Communications Management, LLC
2+
* Copyright 2020-2025 Comcast Cable Communications Management, LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@ extern "C" {
4545
*/
4646
sa_status sa_svp_supported();
4747

48+
#ifdef ENABLE_SVP
4849
/**
4950
* Allocate an SVP memory block.
5051
*
@@ -255,6 +256,7 @@ sa_status sa_svp_buffer_check(
255256
const void* hash,
256257
size_t hash_length);
257258

259+
#endif // ENABLE_SVP
258260
#ifdef __cplusplus
259261
}
260262
#endif

reference/src/client/include/sa_ta_types.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 Comcast Cable Communications Management, LLC
2+
* Copyright 2020-2025 Comcast Cable Communications Management, LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -470,6 +470,7 @@ typedef struct {
470470
uint8_t api_version;
471471
} sa_svp_supported_s;
472472

473+
#ifdef ENABLE_SVP
473474
// sa_svp_buffer_create
474475
// param[0] INOUT - sa_svp_buffer
475476
typedef struct {
@@ -534,6 +535,7 @@ typedef struct {
534535
uint64_t length;
535536
uint32_t digest_algorithm;
536537
} sa_svp_buffer_check_s;
538+
#endif // ENABLE_SVP
537539

538540
// sa_process_common_encryption (1 sample per call)
539541
// param[0] INOUT - sa_process_common_encryption_s

reference/src/client/include/sa_types.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 Comcast Cable Communications Management, LLC
2+
* Copyright 2020-2025 Comcast Cable Communications Management, LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -107,10 +107,12 @@ typedef uint64_t sa_handle; // NOLINT
107107
*/
108108
typedef sa_handle sa_key;
109109

110+
#ifdef ENABLE_SVP
110111
/**
111112
* SVP buffer opaque data structure.
112113
*/
113114
typedef sa_handle sa_svp_buffer;
115+
#endif // ENABLE_SVP
114116

115117
/**
116118
* Cipher context handle.
@@ -559,13 +561,15 @@ typedef struct {
559561
size_t offset;
560562
} clear;
561563

564+
#if ENABLE_SVP
562565
/** SVP buffer information */
563566
struct {
564567
/** SVP buffer handle */
565568
sa_svp_buffer buffer;
566569
/** Current offset into the buffer */
567570
size_t offset;
568571
} svp;
572+
#endif // ENABLE_SVP
569573
} context;
570574
} sa_buffer;
571575

@@ -1023,6 +1027,7 @@ typedef struct {
10231027
/**
10241028
* Structure to use in sa_svp_buffer_copy_blocks
10251029
*/
1030+
#ifdef ENABLE_SVP
10261031
typedef struct {
10271032
/** offset into the output buffer. */
10281033
size_t out_offset;
@@ -1031,6 +1036,7 @@ typedef struct {
10311036
/** numbers of bytes to copy or write. */
10321037
size_t length;
10331038
} sa_svp_offset;
1039+
#endif
10341040

10351041
/** TA Key Type Definition */
10361042

reference/src/client/test/client_test_helpers.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 Comcast Cable Communications Management, LLC
2+
* Copyright 2020-2025 Comcast Cable Communications Management, LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -4362,10 +4362,15 @@ namespace client_test_helpers {
43624362
if (buffer_type == SA_BUFFER_TYPE_CLEAR) {
43634363
if (buffer->context.clear.buffer != nullptr)
43644364
free(buffer->context.clear.buffer);
4365-
} else {
4365+
}
4366+
#ifdef ENABLE_SVP
4367+
else if (buffer_type == SA_BUFFER_TYPE_SVP) {
43664368
if (buffer->context.svp.buffer != INVALID_HANDLE)
4369+
{
43674370
sa_svp_buffer_free(buffer->context.svp.buffer);
4371+
}
43684372
}
4373+
#endif
43694374
}
43704375

43714376
delete buffer;
@@ -4380,7 +4385,9 @@ namespace client_test_helpers {
43804385
ERROR("malloc failed");
43814386
return nullptr;
43824387
}
4383-
} else if (buffer_type == SA_BUFFER_TYPE_SVP) {
4388+
}
4389+
#ifdef ENABLE_SVP
4390+
else if (buffer_type == SA_BUFFER_TYPE_SVP) {
43844391
buffer->buffer_type = SA_BUFFER_TYPE_SVP;
43854392
buffer->context.svp.buffer = INVALID_HANDLE;
43864393
sa_svp_buffer svp_buffer;
@@ -4392,6 +4399,7 @@ namespace client_test_helpers {
43924399
buffer->context.svp.buffer = svp_buffer;
43934400
buffer->context.svp.offset = 0;
43944401
}
4402+
#endif // ENABLE_SVP
43954403

43964404
return buffer;
43974405
}
@@ -4406,7 +4414,10 @@ namespace client_test_helpers {
44064414

44074415
if (buffer_type == SA_BUFFER_TYPE_CLEAR) {
44084416
memcpy(buffer->context.clear.buffer, initial_value.data(), initial_value.size());
4409-
} else {
4417+
}
4418+
4419+
#ifdef ENABLE_SVP
4420+
else if (buffer_type == SA_BUFFER_TYPE_SVP) {
44104421
sa_svp_offset offsets = {0, 0, initial_value.size()};
44114422
if (sa_svp_buffer_write(buffer->context.svp.buffer, initial_value.data(), initial_value.size(),
44124423
&offsets, 1) != SA_STATUS_OK) {
@@ -4416,7 +4427,7 @@ namespace client_test_helpers {
44164427

44174428
buffer->context.svp.offset = 0;
44184429
}
4419-
4430+
#endif // ENABLE_SVP
44204431
return buffer;
44214432
}
44224433

reference/src/client/test/sa_client_thread_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2023 Comcast Cable Communications Management, LLC
2+
* Copyright 2022-2025 Comcast Cable Communications Management, LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
*/
1818

19+
#ifdef ENABLE_SVP
1920
#include "client_test_helpers.h"
2021
#include "sa.h"
2122
#include "gtest/gtest.h" // NOLINT
@@ -134,3 +135,4 @@ namespace {
134135
ASSERT_EQ(SA_STATUS_OK, future.get());
135136
}
136137
} // namespace
138+
#endif // ENABLE_SVP

reference/src/client/test/sa_crypto_cipher_process.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 Comcast Cable Communications Management, LLC
2+
* Copyright 2020-2025 Comcast Cable Communications Management, LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -175,8 +175,10 @@ namespace {
175175
ASSERT_NE(out_buffer, nullptr);
176176
if (buffer_type == SA_BUFFER_TYPE_CLEAR)
177177
out_buffer->context.clear.offset = SIZE_MAX - 4;
178-
else
178+
#ifdef ENABLE_SVP
179+
else if (buffer_type == SA_BUFFER_TYPE_SVP)
179180
out_buffer->context.svp.offset = SIZE_MAX - 4;
181+
#endif // ENABLE_SVP
180182

181183
status = sa_crypto_cipher_process(out_buffer.get(), *cipher, in_buffer.get(), &bytes_to_process);
182184
ASSERT_EQ(status, SA_STATUS_INVALID_PARAMETER);
@@ -210,8 +212,10 @@ namespace {
210212
ASSERT_NE(out_buffer, nullptr);
211213
if (buffer_type == SA_BUFFER_TYPE_CLEAR)
212214
in_buffer->context.clear.offset = SIZE_MAX - 4;
213-
else
215+
#ifdef ENABLE_SVP
216+
else if (buffer_type == SA_BUFFER_TYPE_SVP)
214217
in_buffer->context.svp.offset = SIZE_MAX - 4;
218+
#endif // ENABLE_SVP
215219

216220
status = sa_crypto_cipher_process(out_buffer.get(), *cipher, in_buffer.get(), &bytes_to_process);
217221
ASSERT_EQ(status, SA_STATUS_INVALID_PARAMETER);

reference/src/client/test/sa_crypto_cipher_process_aes_gcm.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 Comcast Cable Communications Management, LLC
2+
* Copyright 2020-2025 Comcast Cable Communications Management, LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -345,6 +345,7 @@ namespace {
345345
ASSERT_EQ(status, SA_STATUS_INVALID_PARAMETER);
346346
}
347347

348+
#ifdef ENABLE_SVP
348349
TEST_F(SaCryptoCipherWithoutSvpTest, initAesGcmFailsSvpIn) {
349350
if (sa_svp_supported() == SA_STATUS_OPERATION_NOT_SUPPORTED)
350351
GTEST_SKIP() << "SVP not supported. Skipping all SVP tests";
@@ -418,4 +419,5 @@ namespace {
418419
status = sa_crypto_cipher_process(out_buffer.get(), *cipher, in_buffer.get(), &bytes_to_process);
419420
ASSERT_EQ(status, SA_STATUS_OPERATION_NOT_ALLOWED);
420421
}
422+
#endif // ENABLE_SVP
421423
} // namespace

0 commit comments

Comments
 (0)