-
Notifications
You must be signed in to change notification settings - Fork 30
Fix error in CT compare, add negative tests for TLS pad checks #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ColtonWilley
wants to merge
4
commits into
wolfSSL:master
Choose a base branch
from
ColtonWilley:fix/ct-byte-mask-ne-negative-pad-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ff5292c
Fix error in CT compare, add negative tests for TLS pad checks
ColtonWilley a376757
Update to cleaner CT check, add CT unit tests
ColtonWilley bf535c8
Fix compile warning
ColtonWilley a939063
Fix test_ct.c build failures on gcc-9 and FIPS configs
ColtonWilley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /* test_ct.c | ||
| * | ||
| * Copyright (C) 2006-2025 wolfSSL Inc. | ||
| * | ||
| * This file is part of wolfProvider. | ||
| * | ||
| * wolfProvider is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation; either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * wolfProvider is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with wolfProvider. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include <wolfprovider/internal.h> | ||
| #include "unit.h" | ||
|
|
||
| int test_ct_masks(void *data) | ||
| { | ||
| int err = 0; | ||
| int a, b; | ||
| byte res; | ||
|
|
||
| (void)data; | ||
|
|
||
| PRINT_MSG("Testing CT byte mask functions (exhaustive)"); | ||
|
|
||
| /* Exhaustive test of all 65536 byte pairs for eq, ne, and their | ||
| * relationship: ne(a,b) == (byte)~eq(a,b). */ | ||
| for (a = 0; a <= 255 && err == 0; a++) { | ||
| for (b = 0; b <= 255 && err == 0; b++) { | ||
| byte eqRes = wp_ct_byte_mask_eq((byte)a, (byte)b); | ||
| byte neRes = wp_ct_byte_mask_ne((byte)a, (byte)b); | ||
| byte expEq = (a == b) ? 0xFF : 0x00; | ||
| byte expNe = (a != b) ? 0xFF : 0x00; | ||
| byte eqNeg; | ||
|
|
||
| if (eqRes != expEq) { | ||
| PRINT_ERR_MSG("ct_byte_mask_eq(%d, %d) = 0x%02x, expected " | ||
| "0x%02x", a, b, eqRes, expEq); | ||
| err = 1; | ||
| } | ||
| if (neRes != expNe) { | ||
| PRINT_ERR_MSG("ct_byte_mask_ne(%d, %d) = 0x%02x, expected " | ||
| "0x%02x", a, b, neRes, expNe); | ||
| err = 1; | ||
| } | ||
| eqNeg = (byte)(eqRes ^ (byte)0xFF); | ||
| if (eqNeg != neRes) { | ||
| PRINT_ERR_MSG("ct_byte_mask ne/eq mismatch at (%d, %d): " | ||
| "~eq=0x%02x ne=0x%02x", a, b, | ||
| eqNeg, neRes); | ||
| err = 1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| PRINT_MSG("Testing CT int mask functions (boundary values)"); | ||
|
|
||
| /* Test int comparison functions over a set of boundary values that cover | ||
| * the actual usage domain (padding indices, record lengths, versions). */ | ||
| { | ||
| static const int vals[] = {0, 1, 2, 127, 128, 254, 255, 256, 1000}; | ||
| int nvals = (int)(sizeof(vals) / sizeof(vals[0])); | ||
| int i, j; | ||
|
|
||
| for (i = 0; i < nvals && err == 0; i++) { | ||
| for (j = 0; j < nvals && err == 0; j++) { | ||
| a = vals[i]; | ||
| b = vals[j]; | ||
|
|
||
| res = wp_ct_int_mask_gte(a, b); | ||
| if (res != ((a >= b) ? 0xFF : 0x00)) { | ||
| PRINT_ERR_MSG("ct_int_mask_gte(%d, %d) = 0x%02x, expected " | ||
| "0x%02x", a, b, res, | ||
| (a >= b) ? 0xFF : 0x00); | ||
| err = 1; | ||
| } | ||
|
|
||
| res = wp_ct_int_mask_eq(a, b); | ||
| if (res != ((a == b) ? 0xFF : 0x00)) { | ||
| PRINT_ERR_MSG("ct_int_mask_eq(%d, %d) = 0x%02x, expected " | ||
| "0x%02x", a, b, res, | ||
| (a == b) ? 0xFF : 0x00); | ||
| err = 1; | ||
| } | ||
|
|
||
| res = wp_ct_int_mask_lt(a, b); | ||
| if (res != ((a < b) ? 0xFF : 0x00)) { | ||
| PRINT_ERR_MSG("ct_int_mask_lt(%d, %d) = 0x%02x, expected " | ||
| "0x%02x", a, b, res, | ||
| (a < b) ? 0xFF : 0x00); | ||
| err = 1; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| PRINT_MSG("Testing CT byte mask sel"); | ||
|
|
||
| /* Selection: mask=0xFF picks a, mask=0x00 picks b. */ | ||
| res = wp_ct_byte_mask_sel(0xFF, 0xAB, 0xCD); | ||
| if (res != 0xAB) { | ||
| PRINT_ERR_MSG("ct_byte_mask_sel(0xFF, 0xAB, 0xCD) = 0x%02x", res); | ||
| err = 1; | ||
| } | ||
| res = wp_ct_byte_mask_sel(0x00, 0xAB, 0xCD); | ||
| if (res != 0xCD) { | ||
| PRINT_ERR_MSG("ct_byte_mask_sel(0x00, 0xAB, 0xCD) = 0x%02x", res); | ||
| err = 1; | ||
| } | ||
|
|
||
| /* Selection driven by eq/ne masks. */ | ||
| res = wp_ct_byte_mask_sel(wp_ct_byte_mask_eq(5, 5), 0x11, 0x22); | ||
| if (res != 0x11) { | ||
| PRINT_ERR_MSG("ct_byte_mask_sel(eq(5,5), 0x11, 0x22) = 0x%02x", res); | ||
| err = 1; | ||
| } | ||
| res = wp_ct_byte_mask_sel(wp_ct_byte_mask_eq(5, 6), 0x11, 0x22); | ||
| if (res != 0x22) { | ||
| PRINT_ERR_MSG("ct_byte_mask_sel(eq(5,6), 0x11, 0x22) = 0x%02x", res); | ||
| err = 1; | ||
| } | ||
|
|
||
| return err; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that DES3 CBC is the only path for testing
wp_ct_byte_mask_ne, currently. So this is a good add, but...Can we add some test vectors for
wp_ct_*functions? There seem to be no direct tests of these today. Just to ensure coverage.