Skip to content
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

Add FIPS required forward declaration of streaming struct #7585

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -24918,6 +24918,7 @@ static int test_wc_ecc_export_x963_ex(void)
XMEMSET(&key, 0, sizeof(ecc_key));
XMEMSET(&rng, 0, sizeof(WC_RNG));
XMEMSET(out, 0, outlen);
PRIVATE_KEY_UNLOCK();

ExpectIntEQ(wc_ecc_init(&key), 0);
ExpectIntEQ(wc_InitRng(&rng), 0);
Expand Down Expand Up @@ -24958,6 +24959,7 @@ static int test_wc_ecc_export_x963_ex(void)
ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, NOCOMP),
ECC_BAD_ARG_E);
#endif
PRIVATE_KEY_LOCK();

DoExpectIntEQ(wc_FreeRng(&rng), 0);
wc_ecc_free(&key);
Expand Down Expand Up @@ -25049,6 +25051,7 @@ static int test_wc_ecc_import_private_key(void)
XMEMSET(&rng, 0, sizeof(WC_RNG));
XMEMSET(privKey, 0, privKeySz);
XMEMSET(x963Key, 0, x963KeySz);
PRIVATE_KEY_UNLOCK();

ExpectIntEQ(wc_ecc_init(&key), 0);
ExpectIntEQ(wc_ecc_init(&keyImp), 0);
Expand All @@ -25071,6 +25074,7 @@ static int test_wc_ecc_import_private_key(void)
x963KeySz, NULL), BAD_FUNC_ARG);
ExpectIntEQ(wc_ecc_import_private_key(NULL, privKeySz, x963Key, x963KeySz,
&keyImp), BAD_FUNC_ARG);
PRIVATE_KEY_LOCK();

DoExpectIntEQ(wc_FreeRng(&rng), 0);
wc_ecc_free(&keyImp);
Expand Down Expand Up @@ -25101,6 +25105,7 @@ static int test_wc_ecc_export_private_only(void)
XMEMSET(&key, 0, sizeof(ecc_key));
XMEMSET(&rng, 0, sizeof(WC_RNG));
XMEMSET(out, 0, outlen);
PRIVATE_KEY_UNLOCK();

ExpectIntEQ(wc_ecc_init(&key), 0);
ExpectIntEQ(wc_InitRng(&rng), 0);
Expand All @@ -25115,6 +25120,7 @@ static int test_wc_ecc_export_private_only(void)
ExpectIntEQ(wc_ecc_export_private_only(NULL, out, &outlen), BAD_FUNC_ARG);
ExpectIntEQ(wc_ecc_export_private_only(&key, NULL, &outlen), BAD_FUNC_ARG);
ExpectIntEQ(wc_ecc_export_private_only(&key, out, NULL), BAD_FUNC_ARG);
PRIVATE_KEY_LOCK();

DoExpectIntEQ(wc_FreeRng(&rng), 0);
wc_ecc_free(&key);
Expand Down Expand Up @@ -25712,6 +25718,7 @@ static int test_wc_ecc_shared_secret_ssh(void)
XMEMSET(&key2, 0, sizeof(ecc_key));
XMEMSET(&rng, 0, sizeof(WC_RNG));
XMEMSET(secret, 0, secretLen);
PRIVATE_KEY_UNLOCK();

/* Make keys */
ExpectIntEQ(wc_ecc_init(&key), 0);
Expand Down Expand Up @@ -25751,6 +25758,7 @@ static int test_wc_ecc_shared_secret_ssh(void)
key.type = ECC_PUBLICKEY;
ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
&secretLen), ECC_BAD_ARG_E);
PRIVATE_KEY_LOCK();

DoExpectIntEQ(wc_FreeRng(&rng), 0);
wc_ecc_free(&key);
Expand Down Expand Up @@ -26678,6 +26686,7 @@ static int test_wc_EccPrivateKeyToDer(void)

XMEMSET(&eccKey, 0, sizeof(ecc_key));
XMEMSET(&rng, 0, sizeof(WC_RNG));
PRIVATE_KEY_UNLOCK();

ExpectIntEQ(wc_InitRng(&rng), 0);
ExpectIntEQ(wc_ecc_init(&eccKey), 0);
Expand Down Expand Up @@ -26718,6 +26727,7 @@ static int test_wc_EccPrivateKeyToDer(void)
EVP_PKEY_free(pkey); /* EC_KEY should be free'd by free'ing pkey */
}
#endif
PRIVATE_KEY_LOCK();
#endif
return EXPECT_RESULT();
} /* End test_wc_EccPrivateKeyToDer*/
Expand Down
21 changes: 14 additions & 7 deletions wolfssl/wolfcrypt/aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,18 +420,19 @@ struct Aes {
Aes tweak;
};

#ifndef WC_AESXTS_TYPE_DEFINED
typedef struct XtsAes XtsAes;
#define WC_AESXTS_TYPE_DEFINED
#endif

#ifdef WOLFSSL_AESXTS_STREAM
struct XtsAesStreamData {
byte tweak_block[AES_BLOCK_SIZE];
word32 bytes_crypted_with_this_tweak;
};
#endif

#ifndef WC_AESXTS_TYPE_DEFINED
typedef struct XtsAes XtsAes;
typedef struct XtsAesStreamData XtsAesStreamData;
#define WC_AESXTS_TYPE_DEFINED
#endif

#endif


Expand All @@ -456,9 +457,15 @@ struct Aes {
#endif

#ifdef HAVE_AESGCM
typedef struct Gmac {
struct Gmac {
Aes aes;
} Gmac;
};

#ifndef WC_AESGCM_TYPE_DEFINED
typedef struct Gmac Gmac;
#define WC_AESGCM_TYPE_DEFINED
#endif

#endif /* HAVE_AESGCM */
#endif /* HAVE_FIPS */

Expand Down
21 changes: 15 additions & 6 deletions wolfssl/wolfcrypt/ecc.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ typedef byte ecc_oid_t;

/* ECC set type defined a GF(p) curve */
#ifndef WOLFSSL_ECC_CURVE_STATIC
typedef struct ecc_set_type {
struct ecc_set_type {
int size; /* The size of the curve in octets */
int id; /* id of this curve */
const char* name; /* name of this curve */
Expand All @@ -311,13 +311,13 @@ typedef struct ecc_set_type {
word32 oidSz;
word32 oidSum; /* sum of encoded OID bytes */
int cofactor;
} ecc_set_type;
};
#else
#define MAX_ECC_NAME 16
#define MAX_ECC_STRING ((MAX_ECC_BYTES * 2) + 2)
/* The values are stored as text strings. */

typedef struct ecc_set_type {
struct ecc_set_type {
int size; /* The size of the curve in octets */
int id; /* id of this curve */
char name[MAX_ECC_NAME]; /* name of this curve */
Expand All @@ -331,7 +331,7 @@ typedef struct ecc_set_type {
word32 oidSz;
word32 oidSum; /* sum of encoded OID bytes */
int cofactor;
} ecc_set_type;
};
#endif


Expand Down Expand Up @@ -441,10 +441,19 @@ typedef struct alt_fp_int {
#define WC_ECCKEY_TYPE_DEFINED
#endif

#ifndef WC_ECCPOINT_TYPE_DEFINED
typedef struct ecc_point ecc_point;
#define WC_ECCPOINT_TYPE_DEFINED
#endif

#ifndef WC_ECCSET_TYPE_DEFINED
typedef struct ecc_set_type ecc_set_type;
#define WC_ECCSET_TYPE_DEFINED
#endif

/* A point on an ECC curve, stored in Jacobian format such that (x,y,z) =>
(x/z^2, y/z^3, 1) when interpreted as affine */
typedef struct {
struct ecc_point {
#ifndef ALT_ECC_SIZE
mp_int x[1]; /* The x coordinate */
mp_int y[1]; /* The y coordinate */
Expand All @@ -458,7 +467,7 @@ typedef struct {
#if defined(WOLFSSL_SMALL_STACK_CACHE) && !defined(WOLFSSL_ECC_NO_SMALL_STACK)
ecc_key* key;
#endif
} ecc_point;
};

/* ECC Flags */
enum {
Expand Down