@@ -6692,11 +6692,12 @@ static int sakke_compute_point_r(SakkeKey* key, const byte* id, word16 idSz,
66926692 * @param [out] auth Authentication data.
66936693 * @param [out] authSz Size of authentication data in bytes.
66946694 * @return 0 on success.
6695- * @return BAD_FUNC_ARG when key, ssv or encSz is NULL, ssvSz is to big or
6696- * encSz is too small.
6695+ * @return BAD_FUNC_ARG when key, ssv or authSz is NULL, when encapsulating
6696+ * and ssvSz is 0 or larger than the curve modulus, or *authSz is
6697+ * too small.
66976698 * @return BAD_STATE_E when identity not set.
66986699 * @return LENGTH_ONLY_E when auth is NULL. authSz contains required size of
6699- * auth in bytes.
6700+ * auth in bytes. ssvSz is not consulted on the size-query path.
67006701 * @return MEMORY_E when dynamic memory allocation fails.
67016702 * @return Other -ve value on internal failure.
67026703 */
@@ -6728,8 +6729,17 @@ int wc_MakeSakkeEncapsulatedSSV(SakkeKey* key, enum wc_HashType hashType,
67286729 /* Uncompressed point */
67296730 outSz = (word16 )(1 + 2 * n );
67306731
6731- if ((auth != NULL ) && (* authSz < outSz )) {
6732- err = BAD_FUNC_ARG ;
6732+ /* ssvSz is only meaningful when actually encapsulating; the
6733+ * size-query path (auth == NULL) only depends on the curve. RFC
6734+ * 6508 6.2.1 step 1 puts SSV in the range 0..2^n-1, so ssvSz must
6735+ * be in [1, n] octets. */
6736+ if (auth != NULL ) {
6737+ if ((ssvSz == 0 ) || (ssvSz > n )) {
6738+ err = BAD_FUNC_ARG ;
6739+ }
6740+ else if (* authSz < outSz ) {
6741+ err = BAD_FUNC_ARG ;
6742+ }
67336743 }
67346744 }
67356745 if (err == 0 ) {
@@ -6867,7 +6877,8 @@ int wc_GenerateSakkeSSV(SakkeKey* key, WC_RNG* rng, byte* ssv, word16* ssvSz)
68676877 * @param [in] auth Authentication data.
68686878 * @param [in] authSz Size of authentication data in bytes.
68696879 * @return 0 on success.
6870- * @return BAD_FUNC_ARG when key, ssv or auth is NULL.
6880+ * @return BAD_FUNC_ARG when key, ssv or auth is NULL, ssvSz is 0 or
6881+ * larger than the curve modulus byte length.
68716882 * @return BAD_STATE_E when RSK or identity not set.
68726883 * @return SAKKE_VERIFY_FAIL_E when calculated R doesn't match the encapsulated
68736884 * data's R.
@@ -6886,7 +6897,7 @@ int wc_DeriveSakkeSSV(SakkeKey* key, enum wc_HashType hashType, byte* ssv,
68866897 byte * test = NULL ;
68876898 byte a [WC_MAX_DIGEST_SIZE ] = {0 };
68886899
6889- if ((key == NULL ) || (ssv == NULL ) || (auth == NULL )) {
6900+ if ((key == NULL ) || (ssv == NULL ) || (auth == NULL ) || ( ssvSz == 0 ) ) {
68906901 err = BAD_FUNC_ARG ;
68916902 }
68926903 if ((err == 0 ) && (!key -> rsk .set || (key -> idSz == 0 ))) {
@@ -6905,6 +6916,10 @@ int wc_DeriveSakkeSSV(SakkeKey* key, enum wc_HashType hashType, byte* ssv,
69056916 if (authSz != 2 * n + 1 ) {
69066917 err = BAD_FUNC_ARG ;
69076918 }
6919+ /* RFC 6508 6.2.1: SSV is in 0..2^n-1, so ssvSz must be <= n. */
6920+ else if (ssvSz > n ) {
6921+ err = BAD_FUNC_ARG ;
6922+ }
69086923 }
69096924 if (err == 0 ) {
69106925 err = sakke_load_base_point (key );
0 commit comments