diff --git a/wolfcrypt/src/srp.c b/wolfcrypt/src/srp.c index 5d893c929..98c981cb7 100644 --- a/wolfcrypt/src/srp.c +++ b/wolfcrypt/src/srp.c @@ -166,9 +166,38 @@ int wc_SrpInit(Srp* srp, SrpType type, SrpSide side) if (side != SRP_CLIENT_SIDE && side != SRP_SERVER_SIDE) return BAD_FUNC_ARG; - if (type != SRP_TYPE_SHA && type != SRP_TYPE_SHA256 && - type != SRP_TYPE_SHA384 && type != SRP_TYPE_SHA512) - return BAD_FUNC_ARG; + switch (type) { + case SRP_TYPE_SHA: + #ifdef NO_SHA + return NOT_COMPILED_IN; + #else + break; /* OK */ + #endif + + case SRP_TYPE_SHA256: + #ifdef NO_SHA256 + return NOT_COMPILED_IN; + #else + break; /* OK */ + #endif + + case SRP_TYPE_SHA384: + #ifndef WOLFSSL_SHA384 + return NOT_COMPILED_IN; + #else + break; /* OK */ + #endif + + case SRP_TYPE_SHA512: + #ifndef WOLFSSL_SHA512 + return NOT_COMPILED_IN; + #else + break; /* OK */ + #endif + + default: + return BAD_FUNC_ARG; + } /* initializing variables */ @@ -402,25 +431,25 @@ int wc_SrpSetPrivate(Srp* srp, const byte* private, word32 size) } /** Generates random data using wolfcrypt RNG. */ -static int wc_SrpGenPrivate(Srp* srp, byte* private, word32 size) +static int wc_SrpGenPrivate(Srp* srp, byte* priv, word32 size) { WC_RNG rng; int r = wc_InitRng(&rng); - if (!r) r = wc_RNG_GenerateBlock(&rng, private, size); - if (!r) r = wc_SrpSetPrivate(srp, private, size); + if (!r) r = wc_RNG_GenerateBlock(&rng, priv, size); + if (!r) r = wc_SrpSetPrivate(srp, priv, size); if (!r) wc_FreeRng(&rng); return r; } -int wc_SrpGetPublic(Srp* srp, byte* public, word32* size) +int wc_SrpGetPublic(Srp* srp, byte* pub, word32* size) { mp_int pubkey; word32 modulusSz; int r; - if (!srp || !public || !size) + if (!srp || !pub || !size) return BAD_FUNC_ARG; if (mp_iszero(&srp->auth)) @@ -436,7 +465,7 @@ int wc_SrpGetPublic(Srp* srp, byte* public, word32* size) /* priv = random() */ if (mp_iszero(&srp->priv)) - r = wc_SrpGenPrivate(srp, public, modulusSz); + r = wc_SrpGenPrivate(srp, pub, modulusSz); /* client side: A = g ^ a % N */ if (srp->side == SRP_CLIENT_SIDE) { @@ -459,8 +488,8 @@ int wc_SrpGetPublic(Srp* srp, byte* public, word32* size) } /* extract public key to buffer */ - XMEMSET(public, 0, modulusSz); - if (!r) r = mp_to_unsigned_bin(&pubkey, public); + XMEMSET(pub, 0, modulusSz); + if (!r) r = mp_to_unsigned_bin(&pubkey, pub); if (!r) *size = mp_unsigned_bin_size(&pubkey); mp_clear(&pubkey); diff --git a/wolfssl/wolfcrypt/srp.h b/wolfssl/wolfcrypt/srp.h index 3992a07ea..af5ba5207 100644 --- a/wolfssl/wolfcrypt/srp.h +++ b/wolfssl/wolfcrypt/srp.h @@ -62,18 +62,10 @@ typedef enum { * SRP hash type, SHA[1|256|384|512]. */ typedef enum { - #ifndef NO_SHA SRP_TYPE_SHA = 1, - #endif - #ifndef NO_SHA256 SRP_TYPE_SHA256 = 2, - #endif - #ifdef WOLFSSL_SHA384 SRP_TYPE_SHA384 = 3, - #endif - #ifdef WOLFSSL_SHA512 SRP_TYPE_SHA512 = 4, - #endif } SrpType; /** @@ -230,12 +222,12 @@ WOLFSSL_API int wc_SrpGetVerifier(Srp* srp, byte* verifier, word32* size); * This function MAY be called before wc_SrpGetPublic. * * @param[in,out] srp the Srp structure. - * @param[in] private the ephemeral value. + * @param[in] priv the ephemeral value. * @param[in] size the private size in bytes. * * @return 0 on success, {@literal <} 0 on error. @see error-crypt.h */ -WOLFSSL_API int wc_SrpSetPrivate(Srp* srp, const byte* private, word32 size); +WOLFSSL_API int wc_SrpSetPrivate(Srp* srp, const byte* priv, word32 size); /** * Gets the public ephemeral value. @@ -246,13 +238,13 @@ WOLFSSL_API int wc_SrpSetPrivate(Srp* srp, const byte* private, word32 size); * This function MUST be called after wc_SrpSetPassword or wc_SrpSetVerifier. * * @param[in,out] srp the Srp structure. - * @param[out] public the buffer to write the public ephemeral value. + * @param[out] pub the buffer to write the public ephemeral value. * @param[in,out] size the the buffer size in bytes. Will be updated with * the ephemeral value size. * * @return 0 on success, {@literal <} 0 on error. @see error-crypt.h */ -WOLFSSL_API int wc_SrpGetPublic(Srp* srp, byte* public, word32* size); +WOLFSSL_API int wc_SrpGetPublic(Srp* srp, byte* pub, word32* size); /**