@@ -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+
1385513883static 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-
1386813895static void ecc_ctx_init(ecEncCtx* ctx, int flags, WC_RNG* rng)
1386913896{
1387013897 if (ctx) {
0 commit comments