Skip to content

Commit 43b2c80

Browse files
authored
Merge pull request #7552 from dgarske/ecies_own_salt
Add option for using a custom salt for ourselves
2 parents 095906f + 5a0594d commit 43b2c80

3 files changed

Lines changed: 37 additions & 8 deletions

File tree

doc/dox_comments/header_files/ecc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ int wc_ecc_ctx_set_peer_salt(ecEncCtx* ctx, const byte* salt);
17221722
17231723
\param ctx pointer to the ecEncCtx for which to set the salt
17241724
\param salt pointer to salt buffer
1725-
\param len length salt in bytes
1725+
\param sz length salt in bytes
17261726
17271727
_Example_
17281728
\code
@@ -1742,7 +1742,7 @@ int wc_ecc_ctx_set_peer_salt(ecEncCtx* ctx, const byte* salt);
17421742
\sa wc_ecc_ctx_get_peer_salt
17431743
*/
17441744

1745-
int wc_ecc_ctx_set_kdf_salt(ecEncCtx* ctx, const byte* salt, word32 len);
1745+
int wc_ecc_ctx_set_kdf_salt(ecEncCtx* ctx, const byte* salt, word32 sz);
17461746

17471747
/*!
17481748
\ingroup ECC

wolfcrypt/src/ecc.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13830,17 +13830,17 @@ 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
*/
13837-
int wc_ecc_ctx_set_kdf_salt(ecEncCtx* ctx, const byte* salt, word32 len)
13837+
int wc_ecc_ctx_set_kdf_salt(ecEncCtx* ctx, const byte* salt, word32 sz)
1383813838
{
13839-
if (ctx == NULL || (salt == NULL && len != 0))
13839+
if (ctx == NULL || (salt == NULL && sz != 0))
1384013840
return BAD_FUNC_ARG;
1384113841

1384213842
ctx->kdfSalt = salt;
13843-
ctx->kdfSaltSz = len;
13843+
ctx->kdfSaltSz = sz;
1384413844

1384513845
if (ctx->protocol == REQ_RESP_CLIENT) {
1384613846
ctx->cliSt = ecCLI_SALT_SET;
@@ -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)