Skip to content

Commit 95095f5

Browse files
committed
Add option for using a custom salt for ourselves. ZD 17988
1 parent 7782f8e commit 95095f5

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

wolfcrypt/src/ecc.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13830,7 +13830,7 @@ int wc_ecc_ctx_set_peer_salt(ecEncCtx* ctx, const byte* salt)
1383013830
*
1383113831
* @param [in, out] ctx ECIES context object.
1383213832
* @param [in] salt Salt to use with KDF.
13833-
* @param [in] len Length of salt in bytes.
13833+
* @param [in] sz Length of salt in bytes.
1383413834
* @return 0 on success.
1383513835
* @return BAD_FUNC_ARG when ctx is NULL or salt is NULL and len is not 0.
1383613836
*/
@@ -13852,9 +13852,37 @@ int wc_ecc_ctx_set_kdf_salt(ecEncCtx* ctx, const byte* salt, word32 len)
1385213852
return 0;
1385313853
}
1385413854

13855+
/* Set your own salt. By default we generate a random salt for ourselves.
13856+
* This allows overriding that after init or reset.
13857+
*
13858+
* @param [in, out] ctx ECIES context object.
13859+
* @param [in] salt Salt to use for ourselves
13860+
* @param [in] sz Length of salt in bytes.
13861+
* @return 0 on success.
13862+
* @return BAD_FUNC_ARG when ctx is NULL or salt is NULL and len is not 0.
13863+
*/
13864+
int wc_ecc_ctx_set_own_salt(ecEncCtx* ctx, const byte* salt, word32 sz)
13865+
{
13866+
byte* saltBuffer;
13867+
13868+
if (ctx == NULL || ctx->protocol == 0 || salt == NULL)
13869+
return BAD_FUNC_ARG;
13870+
13871+
if (sz > EXCHANGE_SALT_SZ)
13872+
sz = EXCHANGE_SALT_SZ;
13873+
saltBuffer = (ctx->protocol == REQ_RESP_CLIENT) ?
13874+
ctx->clientSalt :
13875+
ctx->serverSalt;
13876+
XMEMSET(saltBuffer, 0, EXCHANGE_SALT_SZ);
13877+
XMEMCPY(saltBuffer, salt, sz);
13878+
13879+
return 0;
13880+
}
13881+
13882+
1385513883
static int ecc_ctx_set_salt(ecEncCtx* ctx, int flags)
1385613884
{
13857-
byte* saltBuffer = NULL;
13885+
byte* saltBuffer;
1385813886

1385913887
if (ctx == NULL || flags == 0)
1386013888
return BAD_FUNC_ARG;
@@ -13864,7 +13892,6 @@ static int ecc_ctx_set_salt(ecEncCtx* ctx, int flags)
1386413892
return wc_RNG_GenerateBlock(ctx->rng, saltBuffer, EXCHANGE_SALT_SZ);
1386513893
}
1386613894

13867-
1386813895
static void ecc_ctx_init(ecEncCtx* ctx, int flags, WC_RNG* rng)
1386913896
{
1387013897
if (ctx) {

wolfssl/wolfcrypt/ecc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,8 @@ const byte* wc_ecc_ctx_get_own_salt(ecEncCtx* ctx);
978978
WOLFSSL_API
979979
int wc_ecc_ctx_set_peer_salt(ecEncCtx* ctx, const byte* salt);
980980
WOLFSSL_API
981+
int wc_ecc_ctx_set_own_salt(ecEncCtx* ctx, const byte* salt, word32 sz);
982+
WOLFSSL_API
981983
int wc_ecc_ctx_set_kdf_salt(ecEncCtx* ctx, const byte* salt, word32 sz);
982984
WOLFSSL_API
983985
int wc_ecc_ctx_set_info(ecEncCtx* ctx, const byte* info, int sz);

0 commit comments

Comments
 (0)