Skip to content

Commit 67b6b28

Browse files
committed
Add checking of size param and clarify usage in doc
1 parent 6c5e841 commit 67b6b28

File tree

2 files changed

+8
-4
lines changed
  • doc/dox_comments/header_files
  • wolfcrypt/src

2 files changed

+8
-4
lines changed

doc/dox_comments/header_files/srp.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ int wc_SrpSetPrivate(Srp* srp, const byte* priv, word32 size);
340340
This function MUST be called after wc_SrpSetPassword or wc_SrpSetVerifier.
341341
The function wc_SrpSetPrivate may be called before wc_SrpGetPublic.
342342
343+
Caller must observe value of size upon return to know the actual size.
344+
343345
\return 0 Success
344346
\return BAD_FUNC_ARG Returned if srp, pub, or size is null.
345347
\return SRP_CALL_ORDER_E Returned if wc_SrpGetPublic is called out
@@ -349,8 +351,8 @@ int wc_SrpSetPrivate(Srp* srp, const byte* priv, word32 size);
349351
350352
\param srp the Srp structure.
351353
\param pub the buffer to write the public ephemeral value.
352-
\param size the the buffer size in bytes. Will be updated with
353-
the ephemeral value size.
354+
\param size IN: the buffer size in bytes.
355+
OUT: Will be updated with the ephemeral value size.
354356
355357
_Example_
356358
\code
@@ -369,7 +371,7 @@ int wc_SrpSetPrivate(Srp* srp, const byte* priv, word32 size);
369371
wc_SrpSetPassword(&srp, password, passwordSize)
370372
371373
byte public[64];
372-
word32 publicSz = 0;
374+
word32 publicSz = sizeof(public);
373375
374376
if( wc_SrpGetPublic(&srp, public, &publicSz) != 0)
375377
{

wolfcrypt/src/srp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,10 @@ int wc_SrpGetPublic(Srp* srp, byte* pub, word32* size)
627627
}
628628
}
629629

630+
/* Clear buffer */
631+
XMEMSET(pub, 0, *size);
632+
630633
/* extract public key to buffer */
631-
XMEMSET(pub, 0, modulusSz);
632634
if (!r) r = mp_to_unsigned_bin(pubkey, pub);
633635
if (!r) *size = (word32)mp_unsigned_bin_size(pubkey);
634636

0 commit comments

Comments
 (0)