@@ -162,6 +162,56 @@ int wc_DsaSign(const byte* digest, byte* out,
162162int wc_DsaVerify (const byte * digest , const byte * sig ,
163163 DsaKey * key , int * answer );
164164
165+ /*!
166+ \ingroup DSA
167+
168+ \brief This function validates DSA domain parameters and the public
169+ key contained in the given DsaKey. It performs the following checks
170+ (a subset of the requirements in FIPS 186-4 and NIST SP 800-89):
171+ p > 1 and q > 1; q divides (p - 1); 1 < g < p; 1 < y < p; g^q mod p
172+ == 1 (so the multiplicative order of g divides q); and y^q mod p == 1
173+ (so the multiplicative order of y divides q). The verify
174+ routines (wc_DsaVerify, wc_DsaVerify_ex) call this internally before
175+ any signature math runs, but the function is also exposed so callers
176+ can validate keys at import or decode time.
177+
178+ \return 0 Returned when the key and domain parameters pass validation.
179+ \return BAD_FUNC_ARG Returned when key is NULL, or when the key fails
180+ any of the validation checks listed above.
181+ \return MEMORY_E Returned on memory allocation failure (small-stack
182+ builds only).
183+ \return MP_INIT_E Returned when mp_int initialization fails.
184+ \return Other negative MP error codes (e.g. MP_EXPTMOD_E) Returned on
185+ internal big-integer failures.
186+
187+ Note: this function does not run primality tests on p or q. Full
188+ FIPS 186-4 domain-parameter validation additionally requires that p
189+ and q be prime; callers that need that level of assurance should use
190+ wc_DsaImportParamsRawCheck() (which validates p) and/or run
191+ mp_prime_is_prime_ex() on q at import time.
192+
193+ \param key pointer to a DsaKey structure populated with p, q, g, and y
194+
195+ _Example_
196+ \code
197+ DsaKey key;
198+ int ret;
199+ wc_InitDsaKey(&key);
200+ // ... import or decode the public key into &key ...
201+ ret = wc_DsaCheckPubKey(&key);
202+ if (ret != 0) {
203+ // domain parameters or public key are invalid; reject
204+ }
205+ wc_FreeDsaKey(&key);
206+ \endcode
207+
208+ \sa wc_DsaVerify
209+ \sa wc_DsaPublicKeyDecode
210+ \sa wc_DsaImportParamsRaw
211+ \sa wc_DsaImportParamsRawCheck
212+ */
213+ int wc_DsaCheckPubKey (DsaKey * key );
214+
165215/*!
166216 \ingroup DSA
167217
0 commit comments