Top Description Fields Constructors Methods
com.ongres.scram.common

public Class ScramFunctions

extends Object
Class Inheritance
Imports
com.ongres.scram.common.stringprep.StringPreparation, com.ongres.scram.common.util.CryptoUtil, java.nio.charset.StandardCharsets, java.util.Arrays

Utility functions (e.g. crypto) for SCRAM.

Field Summary

Modifier and TypeField and Description
private static final byte[]
private static final byte[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static byte[]

Returns:

The client key
clientKey
(ScramMechanism
The SCRAM mechanism
scramMechanism
,
byte[]
The salted password
saltedPassword
)

Generates a client key, from the salted password.

public static byte[]

Returns:

The client key
clientKey
(ScramMechanism
The SCRAM mechanism
scramMechanism
,
StringPreparation
The String preparation
stringPreparation
,
String
The non-salted password
password
,
byte[]
The bytes representing the salt
salt
,
int
The number of iterations
iteration
)

Generates a client key from the password and salt.

public static byte[]

Returns:

The client proof
clientProof
(byte[]
The client key
clientKey
,
byte[]
The client signature
clientSignature
)

Computes the SCRAM client proof to be sent to the server on the client-final-message.

public static byte[]

Returns:

The client signature
clientSignature
(ScramMechanism
The SCRAM mechanism
scramMechanism
,
byte[]
The stored key
storedKey
,
String
The auth message
authMessage
)

Computes the SCRAM client signature.

public static byte[]

Returns:

The hashed value
hash
(ScramMechanism
The SCRAM mechanism
scramMechanism
,
byte[]
The value to hash
value
)

Computes the hash function of a given value, based on the SCRAM mechanism hash function.

public static byte[]

Returns:

The computed HMAC
hmac
(ScramMechanism
The SCRAM mechanism
scramMechanism
,
byte[]
The message to compute the HMAC
message
,
byte[]
The key used to initialize the MAC
key
)

Computes the HMAC of the message and key, using the given SCRAM mechanism.

public static byte[]

Returns:

The salted password
saltedPassword
(ScramMechanism
The SCRAM mechanism
scramMechanism
,
StringPreparation
The String preparation
stringPreparation
,
String
The non-salted password
password
,
byte[]
The bytes representing the salt
salt
,
int
The number of iterations
iteration
)

Compute the salted password, based on the given SCRAM mechanism, the String preparation algorithm, the provided salt and the number of iterations.

public static byte[]

Returns:

The server key
serverKey
(ScramMechanism
The SCRAM mechanism
scramMechanism
,
byte[]
The salted password
saltedPassword
)

Generates a server key, from the salted password.

public static byte[]

Returns:

The server key
serverKey
(ScramMechanism
The SCRAM mechanism
scramMechanism
,
StringPreparation
The String preparation
stringPreparation
,
String
The non-salted password
password
,
byte[]
The bytes representing the salt
salt
,
int
The number of iterations
iteration
)

Generates a server key from the password and salt.

public static byte[]

Returns:

The server signature
serverSignature
(ScramMechanism
The SCRAM mechanism
scramMechanism
,
byte[]
The server key
serverKey
,
String
The auth message
authMessage
)

Compute the SCRAM server signature.

public static byte[]

Returns:

The stored key
storedKey
(ScramMechanism
The SCRAM mechanism
scramMechanism
,
byte[]
The client key
clientKey
)

Generates a stored key, from the salted password.

public static boolean

Returns:

True if the client proof is correct
verifyClientProof
(ScramMechanism
The SCRAM mechanism
scramMechanism
,
byte[]
The provided client proof
clientProof
,
byte[]
The stored key
storedKey
,
String
The auth message
authMessage
)

Verifies that a provided client proof is correct.

public static boolean

Returns:

True if the server signature is correct
verifyServerSignature
(ScramMechanism
The SCRAM mechanism
scramMechanism
,
byte[]
The server key
serverKey
,
String
The auth message
authMessage
,
byte[]
The provided server signature
serverSignature
)

Verifies that a provided server proof is correct.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLIENT_KEY_HMAC_KEYback to summary
private static final byte[] CLIENT_KEY_HMAC_KEY
SERVER_KEY_HMAC_KEYback to summary
private static final byte[] SERVER_KEY_HMAC_KEY

Constructor Detail

ScramFunctionsback to summary
public ScramFunctions()

Method Detail

clientKeyback to summary
public static byte[] clientKey(ScramMechanism scramMechanism, byte[] saltedPassword)

Generates a client key, from the salted password. ClientKey := HMAC(SaltedPassword, "Client Key")

Parameters
scramMechanism:ScramMechanism

The SCRAM mechanism

saltedPassword:byte[]

The salted password

Returns:byte[]

The client key

clientKeyback to summary
public static byte[] clientKey(ScramMechanism scramMechanism, StringPreparation stringPreparation, String password, byte[] salt, int iteration)

Generates a client key from the password and salt. SaltedPassword := Hi(Normalize(password), salt, i) ClientKey := HMAC(SaltedPassword, "Client Key")

Parameters
scramMechanism:ScramMechanism

The SCRAM mechanism

stringPreparation:StringPreparation

The String preparation

password:String

The non-salted password

salt:byte[]

The bytes representing the salt

iteration:int

The number of iterations

Returns:byte[]

The client key

clientProofback to summary
public static byte[] clientProof(byte[] clientKey, byte[] clientSignature)

Computes the SCRAM client proof to be sent to the server on the client-final-message. ClientProof := ClientKey XOR ClientSignature

Parameters
clientKey:byte[]

The client key

clientSignature:byte[]

The client signature

Returns:byte[]

The client proof

clientSignatureback to summary
public static byte[] clientSignature(ScramMechanism scramMechanism, byte[] storedKey, String authMessage)

Computes the SCRAM client signature. ClientSignature := HMAC(StoredKey, AuthMessage)

Parameters
scramMechanism:ScramMechanism

The SCRAM mechanism

storedKey:byte[]

The stored key

authMessage:String

The auth message

Returns:byte[]

The client signature

hashback to summary
public static byte[] hash(ScramMechanism scramMechanism, byte[] value)

Computes the hash function of a given value, based on the SCRAM mechanism hash function.

Parameters
scramMechanism:ScramMechanism

The SCRAM mechanism

value:byte[]

The value to hash

Returns:byte[]

The hashed value

hmacback to summary
public static byte[] hmac(ScramMechanism scramMechanism, byte[] message, byte[] key)

Computes the HMAC of the message and key, using the given SCRAM mechanism.

Parameters
scramMechanism:ScramMechanism

The SCRAM mechanism

message:byte[]

The message to compute the HMAC

key:byte[]

The key used to initialize the MAC

Returns:byte[]

The computed HMAC

saltedPasswordback to summary
public static byte[] saltedPassword(ScramMechanism scramMechanism, StringPreparation stringPreparation, String password, byte[] salt, int iteration)

Compute the salted password, based on the given SCRAM mechanism, the String preparation algorithm, the provided salt and the number of iterations. SaltedPassword := Hi(Normalize(password), salt, i)

Parameters
scramMechanism:ScramMechanism

The SCRAM mechanism

stringPreparation:StringPreparation

The String preparation

password:String

The non-salted password

salt:byte[]

The bytes representing the salt

iteration:int

The number of iterations

Returns:byte[]

The salted password

serverKeyback to summary
public static byte[] serverKey(ScramMechanism scramMechanism, byte[] saltedPassword)

Generates a server key, from the salted password. ServerKey := HMAC(SaltedPassword, "Server Key")

Parameters
scramMechanism:ScramMechanism

The SCRAM mechanism

saltedPassword:byte[]

The salted password

Returns:byte[]

The server key

serverKeyback to summary
public static byte[] serverKey(ScramMechanism scramMechanism, StringPreparation stringPreparation, String password, byte[] salt, int iteration)

Generates a server key from the password and salt. SaltedPassword := Hi(Normalize(password), salt, i) ServerKey := HMAC(SaltedPassword, "Server Key")

Parameters
scramMechanism:ScramMechanism

The SCRAM mechanism

stringPreparation:StringPreparation

The String preparation

password:String

The non-salted password

salt:byte[]

The bytes representing the salt

iteration:int

The number of iterations

Returns:byte[]

The server key

serverSignatureback to summary
public static byte[] serverSignature(ScramMechanism scramMechanism, byte[] serverKey, String authMessage)

Compute the SCRAM server signature. ServerSignature := HMAC(ServerKey, AuthMessage)

Parameters
scramMechanism:ScramMechanism

The SCRAM mechanism

serverKey:byte[]

The server key

authMessage:String

The auth message

Returns:byte[]

The server signature

storedKeyback to summary
public static byte[] storedKey(ScramMechanism scramMechanism, byte[] clientKey)

Generates a stored key, from the salted password. StoredKey := H(ClientKey)

Parameters
scramMechanism:ScramMechanism

The SCRAM mechanism

clientKey:byte[]

The client key

Returns:byte[]

The stored key

verifyClientProofback to summary
public static boolean verifyClientProof(ScramMechanism scramMechanism, byte[] clientProof, byte[] storedKey, String authMessage)

Verifies that a provided client proof is correct.

Parameters
scramMechanism:ScramMechanism

The SCRAM mechanism

clientProof:byte[]

The provided client proof

storedKey:byte[]

The stored key

authMessage:String

The auth message

Returns:boolean

True if the client proof is correct

verifyServerSignatureback to summary
public static boolean verifyServerSignature(ScramMechanism scramMechanism, byte[] serverKey, String authMessage, byte[] serverSignature)

Verifies that a provided server proof is correct.

Parameters
scramMechanism:ScramMechanism

The SCRAM mechanism

serverKey:byte[]

The server key

authMessage:String

The auth message

serverSignature:byte[]

The provided server signature

Returns:boolean

True if the server signature is correct