My Project
Loading...
Searching...
No Matches
srp.h File Reference

Go to the source code of this file.

Data Structures

struct  SrpHash
 
struct  Srp
 

Typedefs

typedef struct Srp Srp
 

Enumerations

enum  SrpType { SRP_TYPE_SHA = 1 , SRP_TYPE_SHA256 = 2 , SRP_TYPE_SHA384 = 3 , SRP_TYPE_SHA512 = 4 }
 

Functions

WOLFSSL_API int wc_SrpInit (Srp *srp, SrpType type, SrpSide side)
 Initializes the Srp struct for usage.
 
WOLFSSL_API void wc_SrpTerm (Srp *srp)
 Releases the Srp struct resources after usage.
 
WOLFSSL_API int wc_SrpSetUsername (Srp *srp, const byte *username, word32 size)
 Sets the username. This function MUST be called after wc_SrpInit.
 
WOLFSSL_API int wc_SrpSetParams (Srp *srp, const byte *N, word32 nSz, const byte *g, word32 gSz, const byte *salt, word32 saltSz)
 
WOLFSSL_API int wc_SrpSetPassword (Srp *srp, const byte *password, word32 size)
 Sets the password. Setting the password does not persists the clear password data in the srp structure. The client calculates x = H(salt + H(user:pswd)) and stores it in the auth field. This function MUST be called after wc_SrpSetParams and is CLIENT SIDE ONLY.
 
WOLFSSL_API int wc_SrpSetVerifier (Srp *srp, const byte *verifier, word32 size)
 Sets the verifier. This function MUST be called after wc_SrpSetParams and is SERVER SIDE ONLY.
 
WOLFSSL_API int wc_SrpGetVerifier (Srp *srp, byte *verifier, word32 *size)
 Gets the verifier. The client calculates the verifier with v = g ^ x % N. This function MAY be called after wc_SrpSetPassword and is CLIENT SIDE ONLY.
 
WOLFSSL_API int wc_SrpSetPrivate (Srp *srp, const byte *priv, word32 size)
 Sets the private ephemeral value. The private ephemeral value is known as: a at the client side. a = random() b at the server side. b = random() This function is handy for unit test cases or if the developer wants to use an external random source to set the ephemeral value. This function MAY be called before wc_SrpGetPublic.
 
WOLFSSL_API int wc_SrpGetPublic (Srp *srp, byte *pub, word32 *size)
 Gets the public ephemeral value. The public ephemeral value is known as: A at the client side. A = g ^ a % N B at the server side. B = (k * v + (g ˆ b % N)) % N This function MUST be called after wc_SrpSetPassword or wc_SrpSetVerifier. The function wc_SrpSetPrivate may be called before wc_SrpGetPublic.
 
WOLFSSL_API int wc_SrpComputeKey (Srp *srp, byte *clientPubKey, word32 clientPubKeySz, byte *serverPubKey, word32 serverPubKeySz)
 Computes the session key. The key can be accessed at srp->key after success.
 
WOLFSSL_API int wc_SrpGetProof (Srp *srp, byte *proof, word32 *size)
 Gets the proof. This function MUST be called after wc_SrpComputeKey.
 
WOLFSSL_API int wc_SrpVerifyPeersProof (Srp *srp, byte *proof, word32 size)
 Verifies the peers proof. This function MUST be called before wc_SrpGetSessionKey.
 

Variables

 C
 

Enumeration Type Documentation

◆ SrpType

enum SrpType

SRP hash type, SHA[1|256|384|512].

Function Documentation

◆ wc_SrpSetParams()

WOLFSSL_API int wc_SrpSetParams ( Srp * srp,
const byte * N,
word32 nSz,
const byte * g,
word32 gSz,
const byte * salt,
word32 saltSz )

Sets the srp parameters based on the username.

This function MUST be called after wc_SrpSetUsername.

Parameters
[in,out]srpthe Srp structure.
[in]Nthe Modulus. N = 2q+1, [q, N] are primes.
[in]nSzthe N size in bytes.
[in]gthe Generator modulo N.
[in]gSzthe g size in bytes
[in]salta small random salt. Specific for each username.
[in]saltSzthe salt size in bytes
Returns
0 on success, < 0 on error.
See also
error-crypt.h
\ingroup SRP

\brief Sets the srp parameters based on the username..  Must be called
after wc_SrpSetUsername.

\return 0 Success
\return BAD_FUNC_ARG Returns if srp, N, g, or salt is null or if nSz < gSz.
\return SRP_CALL_ORDER_E Returns if wc_SrpSetParams is called before

wc_SrpSetUsername.

Returns
<0 Error
Parameters
srpthe Srp structure.
Nthe Modulus. N = 2q+1, [q, N] are primes.
nSzthe N size in bytes.
gthe Generator modulo N.
gSzthe g size in bytes
salta small random salt. Specific for each username.
saltSzthe salt size in bytes

Example

Srp srp;
byte username[] = "user";
word32 usernameSize = 4;
byte N[] = { }; // Contents of byte array N
byte g[] = { }; // Contents of byte array g
byte salt[] = { }; // Contents of byte array salt
wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE);
wc_SrpSetUsername(&srp, username, usernameSize);
if(wc_SrpSetParams(&srp, N, sizeof(N), g, sizeof(g), salt,
sizeof(salt)) != 0)
{
// Error setting params
}
wc_SrpTerm(&srp);
WOLFSSL_API void wc_SrpTerm(Srp *srp)
Releases the Srp struct resources after usage.
Definition srp.c:267
WOLFSSL_API int wc_SrpInit(Srp *srp, SrpType type, SrpSide side)
Initializes the Srp struct for usage.
Definition srp.c:191
WOLFSSL_API int wc_SrpSetUsername(Srp *srp, const byte *username, word32 size)
Sets the username. This function MUST be called after wc_SrpInit.
Definition srp.c:289
Definition srp.h:103
See also
wc_SrpInit
wc_SrpSetUsername
wc_SrpTerm

Variable Documentation

◆ C

C
extern
Initial value:
{
#endif
#if defined(WOLFSSL_SHA512)
#elif defined(WOLFSSL_SHA384)
#elif !defined(NO_SHA256)
#elif !defined(NO_SHA)
#else
#endif
#define SRP_MODULUS_MIN_BITS 512
#define SRP_PRIVATE_KEY_MIN_BITS 256
#define SRP_SALT_SIZE 16
typedef enum {
SRP_CLIENT_SIDE = 0,
SRP_SERVER_SIDE = 1,
} SrpSide