Skip to content

Commit

Permalink
ECC, DH, GCM, GMAC, CCM and AES updated services
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleb-himes committed Jun 12, 2024
1 parent ae9291f commit 20911f2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
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
7 changes: 5 additions & 2 deletions wolfssl/wolfcrypt/aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ struct Aes {

#ifndef WC_AES_TYPE_DEFINED
typedef struct Aes Aes;
#ifdef HAVE_AESGCM
typedef struct Gmac Gmac;
#endif
#define WC_AES_TYPE_DEFINED
#endif

Expand Down Expand Up @@ -457,9 +460,9 @@ struct Aes {
#endif

#ifdef HAVE_AESGCM
typedef struct Gmac {
struct Gmac {
Aes aes;
} Gmac;
};
#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

0 comments on commit 20911f2

Please sign in to comment.