### Install libcrypto on Ubuntu Source: https://pub.dev/documentation/spake2plus/latest/index.html Installs the OpenSSL development library required for the spake2plus package on Ubuntu systems. Ensure you have the Dart/Flutter SDK installed prior to this step. ```bash sudo apt-get install libssl-dev ``` -------------------------------- ### Install openssl on macOS Source: https://pub.dev/documentation/spake2plus/latest/index.html Installs OpenSSL version 3 or later on macOS using Homebrew, a prerequisite for the spake2plus package. After installation, verify the path to libcrypto.dylib and provide it to the Spake2plus class constructor. ```bash brew install openssl@3 # Homebrew ``` -------------------------------- ### ScryptParameters Constructor Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/ScryptParameters/ScryptParameters.html Initializes a ScryptParameters object with the provided password, salt, cost, block size, parallelization, and derived key length. ```APIDOC ## ScryptParameters Constructor ### Description Initializes a ScryptParameters object with the provided password, salt, cost, block size, parallelization, and derived key length. ### Parameters #### Path Parameters - **pwd** (String) - Required - The password to be hashed. - **salt** (String) - Required - The salt to be used in the hashing process. - **cost** (int) - Required - The cost factor (N) for the scrypt algorithm, determining computational effort. - **blockSize** (int) - Required - The block size (r) for the scrypt algorithm. - **parallelization** (int) - Required - The parallelization factor (p) for the scrypt algorithm. - **dkLen** (int) - Required - The desired length of the derived key in bytes. ``` -------------------------------- ### Spake2plus Constructor Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus-class.html Initializes a new instance of the Spake2plus class. ```APIDOC ## Spake2plus Constructor ### Description Initializes a new instance of the Spake2plus class with the provided library path and curve points. ### Parameters - **libraryPath** (String) - The path to the Spake2plus library. - **curvePointM** (List) - The M curve point. - **curvePointN** (List) - The N curve point. ``` -------------------------------- ### Spake2plus Constructor Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/Spake2plus.html Initializes a new instance of the Spake2plus class. Requires the path to the OpenSSL library and the curve points M and N as lists of integers. ```APIDOC ## Spake2plus Constructor ### Description Initializes a new instance of the Spake2plus class. ### Parameters - **libraryPath** (String) - Required - The file path to the OpenSSL dynamic library. - **curvePointM** (List) - Required - The curve point M as a list of integers. - **curvePointN** (List) - Required - The curve point N as a list of integers. ### Implementation ```dart Spake2plus(String libraryPath, List curvePointM, List curvePointN) : _openssl = OpenSSL(ffi.DynamicLibrary.open(libraryPath)), _curvePointM = Uint8List.fromList(curvePointM), _curvePointN = Uint8List.fromList(curvePointN); ``` ``` -------------------------------- ### Compute Witnesses Implementation Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/computeWitnesses.html This is the main implementation of the computeWitnesses method. It initializes an internal context and then calls a private helper function to perform the actual witness computation. ```dart (Uint8List, Uint8List) computeWitnesses(ScryptParameters scryptParams) { return _context((group, ctx, order) { return _computeWitnesses(scryptParams, group, ctx, order); }); } ``` -------------------------------- ### ScryptParameters Constructor Implementation Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/ScryptParameters/ScryptParameters.html This is the Dart implementation of the ScryptParameters constructor. It initializes the object with the provided password, salt, cost, block size, parallelization, and derived key length. ```dart ScryptParameters(this.pwd, this.salt, this.cost, this.blockSize, this.parallelization, this.dkLen); ``` -------------------------------- ### Spake2plus Constructor Implementation Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/Spake2plus.html Initializes the Spake2plus object by opening the OpenSSL library, and converting the provided curve points into Uint8List format. ```dart Spake2plus(String libraryPath, List curvePointM, List curvePointN) : _openssl = OpenSSL(ffi.DynamicLibrary.open(libraryPath)), _curvePointM = Uint8List.fromList(curvePointM), _curvePointN = Uint8List.fromList(curvePointN); ``` -------------------------------- ### ScryptParameters Constructor Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/ScryptParameters-class.html Constructs a ScryptParameters object with the specified parameters. ```APIDOC ## ScryptParameters Constructor ### Description Initializes a new instance of the `ScryptParameters` class. ### Parameters - **pwd** (String) - The password. - **salt** (String) - The salt. - **cost** (int) - The cost factor (N). - **blockSize** (int) - The block size (r). - **parallelization** (int) - The parallelization factor (p). - **dkLen** (int) - The desired length of the derived key in bytes. ``` -------------------------------- ### computeWitnesses Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus-class.html Computes witnesses using Scrypt parameters. ```APIDOC ## computeWitnesses ### Description Computes witnesses required for the Spake2plus protocol using Scrypt parameters for key derivation. ### Parameters - **scryptParams** (ScryptParameters) - The parameters for the Scrypt key derivation function. ### Returns - **(Uint8List, Uint8List)** - A tuple containing two Uint8List representing the computed witnesses. ``` -------------------------------- ### verifierFinish Method Implementation Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/verifierFinish.html This is the core implementation of the verifierFinish method. It validates input points, performs cryptographic calculations for Z and V, and cleans up allocated resources. Use this method when acting as the verifier in the Spake2plus protocol. ```dart (Uint8List Z, Uint8List V)? verifierFinish( Uint8List w0Bytes, Uint8List bytesL, Uint8List bytesX, Uint8List yBytes, ) { return _context((group, ctx, _) { final X = _openssl.EC_POINT_new(group); _openssl.bytes2point(group, X, bytesX, ctx); final ok = (_openssl.EC_POINT_is_on_curve(group, X, ctx) == 1) && (_openssl.EC_POINT_is_at_infinity(group, X) == 0); if (!ok) { _openssl.EC_POINT_free(X); return null; } final M = _openssl.EC_POINT_new(group); _openssl.bytes2point(group, M, _curvePointM, ctx); final L = _openssl.EC_POINT_new(group); _openssl.bytes2point(group, L, bytesL, ctx); final w0 = _openssl.BN_new(); _openssl.bytes2bn(w0, w0Bytes); final y = _openssl.BN_new(); _openssl.bytes2bn(y, yBytes); final Z = _openssl.calculateZ(group, ctx, X, M, w0, y); final V = _openssl.calculateV_verifier(group, ctx, L, y); final bytesZ = _openssl.point2bytes(group, Z, ctx); final bytesV = _openssl.point2bytes(group, V, ctx); _openssl.EC_POINT_free(V); _openssl.EC_POINT_free(Z); _openssl.EC_POINT_free(L); _openssl.EC_POINT_free(M); _openssl.EC_POINT_free(X); _openssl.BN_free(w0); _openssl.BN_free(y); return (bytesZ, bytesV); }); } ``` -------------------------------- ### ProverFinish Implementation in Spake2plus Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/proverFinish.html This implementation details the prover's final step in the Spake2+ protocol. It validates the verifier's public point Y, calculates intermediate values using private keys and curve parameters, and returns the proof elements Z and V as byte arrays. Ensure all necessary OpenSSL bindings are available. ```dart (Uint8List Z, Uint8List V)? proverFinish(Uint8List w0Bytes, Uint8List w1Bytes, Uint8List xBytes, Uint8List bytesY) { return _context((group, ctx, _) { final Y = _openssl.EC_POINT_new(group); _openssl.bytes2point(group, Y, bytesY, ctx); final ok = (_openssl.EC_POINT_is_on_curve(group, Y, ctx) == 1) && (_openssl.EC_POINT_is_at_infinity(group, Y) == 0); if (!ok) { _openssl.EC_POINT_free(Y); return null; } final N = _openssl.EC_POINT_new(group); _openssl.bytes2point(group, N, _curvePointN, ctx); final x = _openssl.BN_new(); _openssl.bytes2bn(x, xBytes); final w0 = _openssl.BN_new(); _openssl.bytes2bn(w0, w0Bytes); final w1 = _openssl.BN_new(); _openssl.bytes2bn(w1, w1Bytes); final Z = _openssl.calculateZ(group, ctx, Y, N, w0, x); final V = _openssl.calculateV_prover(group, ctx, Y, N, w0, w1, x); final bytesZ = _openssl.point2bytes(group, Z, ctx); final bytesV = _openssl.point2bytes(group, V, ctx); _openssl.EC_POINT_free(V); _openssl.EC_POINT_free(Z); _openssl.EC_POINT_free(N); _openssl.EC_POINT_free(Y); _openssl.BN_free(w1); _openssl.BN_free(w0); _openssl.BN_free(x); return (bytesZ, bytesV); }); } ``` -------------------------------- ### Compute Share V Implementation Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/computeShareV.html This is the core implementation of the computeShareV method. It utilizes OpenSSL bindings to perform cryptographic operations necessary for the Spake2+ protocol. Ensure the OpenSSL library is correctly linked and initialized before calling this method. ```dart Uint8List computeShareV(Uint8List w0Bytes, Uint8List yBytes) { return _context((group, ctx, _) { final w0 = _openssl.BN_new(); _openssl.bytes2bn(w0, w0Bytes); final N = _openssl.EC_POINT_new(group); _openssl.bytes2point(group, N, _curvePointN, ctx); final y = _openssl.BN_new(); _openssl.bytes2bn(y, yBytes); final Y = _openssl.calculatePoint(group, ctx, y, N, w0); final bytesY = _openssl.point2bytes(group, Y, ctx); _openssl.BN_free(y); _openssl.BN_free(w0); _openssl.EC_POINT_free(Y); _openssl.EC_POINT_free(N); return bytesY; }); } ``` -------------------------------- ### verifierFinish Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/verifierFinish.html Completes the Spake2+ verification process. It takes the verifier's initial secret (w0), the commitment point L, the verifier's ephemeral secret X, and the verifier's ephemeral public key y as input. It returns the calculated Z and V values, which are essential for the final verification step. ```APIDOC ## verifierFinish ### Description Completes the Spake2+ verification process by calculating the Z and V values. ### Parameters - **w0Bytes** (Uint8List) - The verifier's initial secret. - **bytesL** (Uint8List) - The commitment point L. - **bytesX** (Uint8List) - The verifier's ephemeral secret X. - **yBytes** (Uint8List) - The verifier's ephemeral public key y. ### Returns - **(Uint8List, Uint8List)?** - A tuple containing the byte representations of Z and V, or null if an error occurs during point validation. ``` -------------------------------- ### ScryptParameters Methods Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/ScryptParameters-class.html Methods available for the ScryptParameters class. ```APIDOC ## ScryptParameters Methods ### toString() - Returns: String - Description: Returns a string representation of the ScryptParameters object. ``` -------------------------------- ### proverFinish Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus-class.html Completes the Spake2plus protocol from the prover's side. ```APIDOC ## proverFinish ### Description Completes the Spake2plus protocol execution from the prover's perspective, generating the final proof. ### Parameters - **w0Bytes** (Uint8List) - Prover's secret share w0. - **w1Bytes** (Uint8List) - Prover's secret share w1. - **xBytes** (Uint8List) - Prover's public value X. - **bytesY** (Uint8List) - Verifier's public value Y. ### Returns - **(Uint8List, Uint8List)?** - A tuple containing the proof and potentially other data, or null if an error occurs. ``` -------------------------------- ### proverFinish Method Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/proverFinish.html The proverFinish method is used by the prover in the Spake2plus protocol to finalize the proof. It takes several byte arrays as input, representing cryptographic values, and returns a tuple of byte arrays representing the calculated Z and V values. ```APIDOC ## proverFinish Method ### Description This method finalizes the Spake2plus proof on the prover's side. It takes the prover's secret values and the verifier's public information to compute the proof elements. ### Signature (Uint8List, Uint8List)? proverFinish( 1. Uint8List w0Bytes, 2. Uint8List w1Bytes, 3. Uint8List xBytes, 4. Uint8List bytesY ) ### Parameters * **w0Bytes** (Uint8List) - The prover's first secret value as bytes. * **w1Bytes** (Uint8List) - The prover's second secret value as bytes. * **xBytes** (Uint8List) - The prover's public value x as bytes. * **bytesY** (Uint8List) - The verifier's public value Y as bytes. ### Returns A tuple of two Uint8List containing the calculated Z and V values if successful, otherwise null. ``` -------------------------------- ### Spake2+ Cost Property Implementation Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/ScryptParameters/cost.html Shows the declaration of the final integer 'cost' property. ```java final int cost; ``` -------------------------------- ### Scrypt Key Derivation Implementation Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Scrypt/deriveScryptKey.html This Dart code implements the Scrypt key derivation function using FFI to call the underlying C library. Ensure proper memory management by freeing allocated native memory after use. ```dart ffi.Pointer deriveScryptKey( String pwd, String salt, int cost, int blockSize, int parallel, int dkLen, [int scryptMaxLen = 128 * 1024 * 1024]) { final dk = calloc(dkLen); final pwdBytes = pwd.toNativeUtf8(); final pwdlen = utf8.encode(pwd).length; final saltBytes = salt.toNativeUtf8(); final saltlen = utf8.encode(salt).length; EVP_PBE_scrypt( pwdBytes.cast(), pwdlen, saltBytes.cast(), saltlen, cost, blockSize, parallel, scryptMaxLen, dk, dkLen, ); calloc.free(saltBytes); calloc.free(pwdBytes); return dk; } ``` -------------------------------- ### computeWitnesses Method Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/computeWitnesses.html Computes the cryptographic witnesses required for the Spake2+ protocol. This method takes Scrypt parameters as input and returns a tuple of Uint8Lists representing the computed witnesses. ```APIDOC ## computeWitnesses Method ### Description Computes the cryptographic witnesses for the Spake2+ protocol using the provided Scrypt parameters. ### Signature ```dart (Uint8List, Uint8List) computeWitnesses(ScryptParameters scryptParams) ``` ### Parameters #### Path Parameters - **scryptParams** (ScryptParameters) - Required - The Scrypt parameters used for key derivation. ### Returns - **(Uint8List, Uint8List)** - A tuple containing two Uint8Lists representing the computed witnesses. ``` -------------------------------- ### deriveScryptKey Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Scrypt/deriveScryptKey.html Derives a cryptographic key using the Scrypt algorithm. This function takes a password, salt, and Scrypt parameters to generate a derived key of a specified length. ```APIDOC ## deriveScryptKey ### Description Derives a cryptographic key using the Scrypt algorithm. This function takes a password, salt, and Scrypt parameters to generate a derived key of a specified length. ### Signature ```dart Pointer deriveScryptKey( String pwd, String salt, int cost, int blockSize, int parallel, int dkLen, [int scryptMaxLen = 128 * 1024 * 1024] ) ``` ### Parameters - **pwd** (String) - The password to use for key derivation. - **salt** (String) - The salt to use for key derivation. - **cost** (int) - The cost factor (N) for Scrypt. - **blockSize** (int) - The block size (r) for Scrypt. - **parallel** (int) - The parallelization factor (p) for Scrypt. - **dkLen** (int) - The desired length of the derived key in bytes. - **scryptMaxLen** (int, optional) - The maximum memory to use for Scrypt. Defaults to 128MB. ``` -------------------------------- ### Implement digestSha256 Method Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/digestSha256.html This is the implementation of the digestSha256 method. It takes a Uint8List transcript as input and returns a Uint8List hash. ```dart Uint8List digestSha256(Uint8List transcript) { return _digest(SN_sha256, transcript); } ``` -------------------------------- ### verifierFinish Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus-class.html Completes the Spake2plus protocol from the verifier's side. ```APIDOC ## verifierFinish ### Description Completes the Spake2plus protocol execution from the verifier's perspective, verifying the proof and generating session keys. ### Parameters - **w0Bytes** (Uint8List) - Prover's secret share w0. - **bytesL** (Uint8List) - The computed record L value. - **bytesX** (Uint8List) - Prover's public value X. - **yBytes** (Uint8List) - Verifier's public value Y. ### Returns - **(Uint8List, Uint8List)?** - A tuple containing the session keys or other verification data, or null if verification fails. ``` -------------------------------- ### Compute Share P in Spake2+ Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/computeShareP.html This function computes the share P using the provided w0bytes and xBytes. It utilizes internal cryptographic functions for BigInt and Elliptic Curve operations. Ensure the input byte arrays are correctly formatted according to the Spake2+ protocol specifications. ```dart Uint8List computeShareP(Uint8List w0bytes, Uint8List xBytes) { return _context((group, ctx, order) { final w0 = _openssl.BN_new(); _openssl.bytes2bn(w0, w0bytes); final M = _openssl.EC_POINT_new(group); _openssl.bytes2point(group, M, _curvePointM, ctx); final x = _openssl.BN_new(); _openssl.bytes2bn(x, xBytes); final X = _openssl.calculatePoint(group, ctx, x, M, w0); final bytesX = _openssl.point2bytes(group, X, ctx); _openssl.EC_POINT_free(X); _openssl.BN_free(x); _openssl.EC_POINT_free(M); _openssl.BN_free(w0); return bytesX; }); } ``` -------------------------------- ### deriveScryptKey Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Scrypt.html Derives a cryptographic key using the Scrypt algorithm. This method is available on OpenSSL and provided by the Scrypt extension. ```APIDOC ## deriveScryptKey ### Description Derives a cryptographic key using the Scrypt algorithm. This method is available on OpenSSL and provided by the Scrypt extension. ### Signature deriveScryptKey(String pwd, String salt, int cost, int blockSize, int parallel, int dkLen, [int scryptMaxLen = 128 * 1024 * 1024]) → Pointer ### Parameters - **pwd** (String) - The password to use for key derivation. - **salt** (String) - The salt to use for key derivation. - **cost** (int) - The cost factor (N) for Scrypt. - **blockSize** (int) - The block size (r) for Scrypt. - **parallel** (int) - The parallelization factor (p) for Scrypt. - **dkLen** (int) - The desired length of the derived key. - **scryptMaxLen** (int, optional) - The maximum length for Scrypt, defaults to 128MB. ``` -------------------------------- ### computeRecordL Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus-class.html Computes the record L value. ```APIDOC ## computeRecordL ### Description Computes the record L value, likely used in a cryptographic protocol. ### Parameters - **w1Bytes** (Uint8List) - The input byte array w1. ### Returns - **Uint8List** - The computed record L value. ``` -------------------------------- ### ScryptParameters Properties Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/ScryptParameters-class.html Properties of the ScryptParameters class. ```APIDOC ## ScryptParameters Properties ### blockSize - Type: int - Description: The block size (r) for Scrypt. ### cost - Type: int - Description: The cost factor (N) for Scrypt. ### dkLen - Type: int - Description: The desired length of the derived key in bytes. ### parallelization - Type: int - Description: The parallelization factor (p) for Scrypt. ### pwd - Type: String - Description: The password used for key derivation. ### salt - Type: String - Description: The salt used for key derivation. ``` -------------------------------- ### Implement digestSha512 Method Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/digestSha512.html This is the implementation of the digestSha512 method. It utilizes an internal _digest function with the SN_sha512 constant. ```dart Uint8List digestSha512(Uint8List transcript) { return _digest(SN_sha512, transcript); } ``` -------------------------------- ### ScryptParameters Operators Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/ScryptParameters-class.html Operators available for the ScryptParameters class. ```APIDOC ## ScryptParameters Operators ### operator ==(Object other) - Returns: bool - Description: Compares this ScryptParameters object with another object for equality. ``` -------------------------------- ### Implement deriveHkdfSha256 Method Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/deriveHkdfSha256.html This is the implementation of the deriveHkdfSha256 method, which internally calls a private _deriveHkdf function with the SHA256 digest algorithm. ```dart Uint8List deriveHkdfSha256( int L, Uint8List salt, Uint8List key, Uint8List info, ) { return _deriveHkdf(_openssl.EVP_sha256(), L, salt, key, info); } ``` -------------------------------- ### computeRecordL Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/computeRecordL.html Computes the record L value. This method takes a Uint8List representing w1 and returns a Uint8List representing L. ```APIDOC ## computeRecordL Method ### Description Computes the record L value using the provided `w1Bytes`. ### Signature `Uint8List computeRecordL(Uint8List w1Bytes)` ### Parameters #### Path Parameters - **w1Bytes** (Uint8List) - Required - The byte representation of w1. ### Request Example ```dart // Assuming w1Bytes is a Uint8List Uint8List resultL = computeRecordL(w1Bytes); ``` ### Response #### Success Response - **bytesL** (Uint8List) - The computed record L value as a byte array. ``` -------------------------------- ### Compute Record L using OpenSSL Bindings Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/computeRecordL.html This function computes the L value by multiplying an input byte array (w1Bytes) with the generator point G using OpenSSL's EC_POINT_mul. Ensure the OpenSSL bindings are correctly initialized. ```dart Uint8List computeRecordL(Uint8List w1Bytes) { return _context((group, ctx, _) { final w1 = _openssl.BN_new(); final L = _openssl.EC_POINT_new(group); _openssl.bytes2bn(w1, w1Bytes); _openssl.EC_POINT_mul( group, L, w1, ffi.nullptr, ffi.nullptr, ctx); // w1 * G final bytesL = _openssl.point2bytes(group, L, ctx); _openssl.BN_free(w1); _openssl.EC_POINT_free(L); return bytesL; }); } ``` -------------------------------- ### computeShareV Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus-class.html Computes the share V value. ```APIDOC ## computeShareV ### Description Computes the share V value, possibly related to a verification or commitment in a protocol. ### Parameters - **w0Bytes** (Uint8List) - The input byte array w0. - **yBytes** (Uint8List) - The input byte array y. ### Returns - **Uint8List** - The computed share V value. ``` -------------------------------- ### Derive HKDF SHA512 Implementation Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/deriveHkdfSha512.html This is the Dart implementation of the deriveHkdfSha512 method. It utilizes an internal _deriveHkdf function with the SHA512 digest. ```dart Uint8List deriveHkdfSha512( int L, Uint8List salt, Uint8List key, Uint8List info, ) { return _deriveHkdf(_openssl.EVP_sha512(), L, salt, key, info); } ``` -------------------------------- ### HMAC-SHA512 Implementation Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/hmacSha512.html This snippet shows the Dart implementation of the HMAC-SHA512 function, which takes a key and data as Uint8List and returns a 64-byte hash. It utilizes an internal OpenSSL binding and manages memory allocation and deallocation. ```dart Uint8List hmacSha512(Uint8List key, Uint8List data) { final hmac = _openssl.hmacSha512(key, data); final ret = Uint8List.fromList((hmac as ffi.Pointer).asTypedList(64)); calloc.free(hmac); return ret; } ``` -------------------------------- ### deriveHkdfSha512 Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/deriveHkdfSha512.html Derives a key using the HKDF-SHA512 algorithm. This function takes the desired length of the output key, a salt, a secret key, and an optional info context as input. ```APIDOC ## deriveHkdfSha512 ### Description Derives a key using the HKDF-SHA512 algorithm. This function takes the desired length of the output key, a salt, a secret key, and an optional info context as input. ### Parameters - **L** (int) - The desired length of the output key in bytes. - **salt** (Uint8List) - The salt to be used in the derivation process. - **key** (Uint8List) - The secret key to be used. - **info** (Uint8List) - Optional context information. ### Implementation ```dart Uint8List deriveHkdfSha512( int L, Uint8List salt, Uint8List key, Uint8List info, ) { return _deriveHkdf(_openssl.EVP_sha512(), L, salt, key, info); } ``` ``` -------------------------------- ### computeShareP Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus-class.html Computes the share P value. ```APIDOC ## computeShareP ### Description Computes the share P value, potentially part of a secret sharing scheme. ### Parameters - **w0bytes** (Uint8List) - The input byte array w0. - **xBytes** (Uint8List) - The input byte array x. ### Returns - **Uint8List** - The computed share P value. ``` -------------------------------- ### hmacSha512 Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/hmacSha512.html Computes the HMAC-SHA512 hash of the provided data using the given key. The function returns a 64-byte Uint8List. ```APIDOC ## hmacSha512 ### Description Computes the HMAC-SHA512 hash of the provided data using the given key. The function returns a 64-byte Uint8List. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Method Signature `Uint8List hmacSha512(Uint8List key, Uint8List data)` ### Parameters - **key** (Uint8List) - The secret key to use for HMAC computation. - **data** (Uint8List) - The data to be hashed. ### Returns - **Uint8List** - A 64-byte array representing the HMAC-SHA512 hash. ### Example ```dart import 'dart:typed_data'; // Assuming _openssl and calloc are properly initialized and imported Uint8List hmacSha512(Uint8List key, Uint8List data) { final hmac = _openssl.hmacSha512(key, data); final ret = Uint8List.fromList((hmac as ffi.Pointer).asTypedList(64)); calloc.free(hmac); return ret; } ``` ``` -------------------------------- ### Declare Parallelization Property Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/ScryptParameters/parallelization.html This snippet shows the declaration of the `parallelization` property as a final integer. ```java final int parallelization; ``` -------------------------------- ### Declare pwd property Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/ScryptParameters/pwd.html This snippet shows the declaration of the 'pwd' property as a final String. ```dart final String pwd; ``` -------------------------------- ### deriveHkdfSha256 Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/deriveHkdfSha256.html Derives a key using the HKDF-SHA256 algorithm. This function takes the desired length of the output key, a salt, the input keying material, and an optional info context. ```APIDOC ## deriveHkdfSha256 Method ### Description Derives a key using the HKDF-SHA256 algorithm. This function takes the desired length of the output key, a salt, the input keying material, and an optional info context. ### Signature ```dart Uint8List deriveHkdfSha256( int L, Uint8List salt, Uint8List key, Uint8List info, ) ``` ### Parameters * **L** (int) - The desired length of the derived key in bytes. * **salt** (Uint8List) - The salt to be used in the HKDF process. * **key** (Uint8List) - The input keying material. * **info** (Uint8List) - Optional context and application specific information. ### Returns * **Uint8List** - The derived key. ``` -------------------------------- ### Declare blockSize Property Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/ScryptParameters/blockSize.html This snippet shows the declaration of the final blockSize property in Java. It is typically initialized during object construction. ```java final int blockSize; ``` -------------------------------- ### computeTranscript Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/computeTranscript.html Computes the transcript of the Spake2+ protocol exchange. This method takes various byte arrays representing protocol elements and constructs a transcript byte array. ```APIDOC ## computeTranscript ### Description Computes the transcript of the Spake2+ protocol exchange. This method takes various byte arrays representing protocol elements and constructs a transcript byte array. ### Method Signature `Uint8List computeTranscript(Uint8List context, Uint8List idProver, Uint8List idVerifier, Uint8List bytesX, Uint8List bytesY, Uint8List bytesZ, Uint8List bytesV, Uint8List w0Bytes)` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **context** (Uint8List) - The context of the protocol exchange. - **idProver** (Uint8List) - The identifier for the prover. - **idVerifier** (Uint8List) - The identifier for the verifier. - **bytesX** (Uint8List) - The X component of the prover's public key. - **bytesY** (Uint8List) - The Y component of the prover's public key. - **bytesZ** (Uint8List) - The Z component of the verifier's public key. - **bytesV** (Uint8List) - The V component used in the protocol. - **w0Bytes** (Uint8List) - The W0 value used in the protocol. ### Request Example ```dart // Example usage (assuming necessary setup and curve points are available) // final transcript = computeTranscript(context, idProver, idVerifier, bytesX, bytesY, bytesZ, bytesV, w0Bytes); ``` ### Response #### Success Response - Returns a `Uint8List` representing the computed transcript. #### Response Example ```dart // Example response (actual bytes will vary) // Uint8List transcript = [0x01, 0x02, 0x03, ...]; ``` ``` -------------------------------- ### computeShareP Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/computeShareP.html Computes a share using the Spake2+ protocol. This method is part of the cryptographic operations for secure password-based key exchange. ```APIDOC ## computeShareP ### Description Computes a share in the Spake2+ protocol. This function is essential for the key exchange process, taking pre-computed values and generating a share. ### Method Signature `Uint8List computeShareP(Uint8List w0bytes, Uint8List xBytes)` ### Parameters #### Parameters - **w0bytes** (Uint8List) - Required - A byte array representing the pre-computed value w0. - **xBytes** (Uint8List) - Required - A byte array representing the user's secret value x. ### Returns - **Uint8List** - A byte array representing the computed share (X). ### Example ```dart // Assuming w0bytes and xBytes are already defined Uint8List variables // final w0bytes = ...; // final xBytes = ...; // final shareP = computeShareP(w0bytes, xBytes); ``` ``` -------------------------------- ### hmacSha256 Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/hmacSha256.html Computes the HMAC-SHA256 hash using the provided key and data. ```APIDOC ## hmacSha256 ### Description Computes the HMAC-SHA256 hash for a given key and data. ### Signature Uint8List hmacSha256(Uint8List key, Uint8List data) ### Parameters #### Arguments 1. **key** (Uint8List) - The secret key for HMAC computation. 2. **data** (Uint8List) - The data to be hashed. ### Returns - **Uint8List** - The resulting HMAC-SHA256 hash (32 bytes). ``` -------------------------------- ### computeShareV Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/computeShareV.html Computes a share value using the Spake2+ protocol. This method is part of the cryptographic operations for secure key agreement. ```APIDOC ## computeShareV ### Description Computes a share value in the Spake2+ protocol. ### Method Signature `Uint8List computeShareV(Uint8List w0Bytes, Uint8List yBytes)` ### Parameters #### Path Parameters - **w0Bytes** (Uint8List) - Required - The first input byte array. - **yBytes** (Uint8List) - Required - The second input byte array. ### Returns - **Uint8List** - A byte array representing the computed share value. ``` -------------------------------- ### dkLen Property Declaration Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/ScryptParameters/dkLen.html Declares the dkLen property as a final integer. ```java final int dkLen; ``` -------------------------------- ### digestSha256 Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/digestSha256.html Computes the SHA-256 digest of the provided transcript. ```APIDOC ## digestSha256 ### Description Computes the SHA-256 hash of the provided transcript. ### Signature Uint8List digestSha256(Uint8List transcript) ### Parameters #### Path Parameters - **transcript** (Uint8List) - Required - The byte array representing the transcript to be hashed. ``` -------------------------------- ### HMAC-SHA256 Implementation Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/hmacSha256.html This function computes the HMAC-SHA256 hash of the given data using the provided key. It utilizes the openssl library and frees allocated memory after computation. ```dart Uint8List hmacSha256(Uint8List key, Uint8List data) { final hmac = _openssl.hmacSha256(key, data); final ret = Uint8List.fromList((hmac as ffi.Pointer).asTypedList(32)); calloc.free(hmac); return ret; } ``` -------------------------------- ### digestSha512 Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/digestSha512.html Computes the SHA-512 digest of the provided transcript. ```APIDOC ## digestSha512 ### Description Computes the SHA-512 digest of the provided transcript. ### Parameters #### Path Parameters - **transcript** (Uint8List) - Required - The input data to be hashed. ### Implementation ```dart Uint8List digestSha512(Uint8List transcript) { return _digest(SN_sha512, transcript); } ``` ``` -------------------------------- ### convertToUncompressedECPoint Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/convertToUncompressedECPoint.html Converts a given EC point data into its uncompressed representation. This method is useful for standardizing EC point formats. ```APIDOC ## convertToUncompressedECPoint ### Description Converts an EC point from its byte representation to an uncompressed EC point format. ### Method Signature ```dart Uint8List convertToUncompressedECPoint(Uint8List pointData) ``` ### Parameters #### Path Parameters - **pointData** (Uint8List) - Required - The byte data representing the EC point. ### Returns - **Uint8List** - The byte data of the EC point in uncompressed format. ``` -------------------------------- ### cmacAes128 Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus-class.html Computes the CMAC-AES128 for the given key and data. ```APIDOC ## cmacAes128 ### Description Computes the Cipher-based Message Authentication Code (CMAC) using AES-128 encryption. ### Parameters - **key** (Uint8List) - The secret key for CMAC computation. - **data** (Uint8List) - The data to authenticate. ### Returns - **Uint8List** - The computed CMAC tag. ``` -------------------------------- ### Compute Spake2+ Transcript Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/computeTranscript.html This function computes the transcript for the Spake2+ protocol. It takes various context and identity byte arrays, converts curve points to uncompressed format, and concatenates them with their lengths in little-endian byte format. ```dart Uint8List computeTranscript( Uint8List context, Uint8List idProver, Uint8List idVerifier, Uint8List bytesX, Uint8List bytesY, Uint8List bytesZ, Uint8List bytesV, Uint8List w0Bytes, ) { final uncompressedM = convertToUncompressedECPoint(_curvePointM); final uncompressedN = convertToUncompressedECPoint(_curvePointN); return Uint8List.fromList([ ...littleEndianBytes(context.length), ...context, ...littleEndianBytes(idProver.length), ...idProver, ...littleEndianBytes(idVerifier.length), ...idVerifier, ...littleEndianBytes(uncompressedM.length), ...uncompressedM, ...littleEndianBytes(uncompressedN.length), ...uncompressedN, ...littleEndianBytes(bytesX.length), ...bytesX, ...littleEndianBytes(bytesY.length), ...bytesY, ...littleEndianBytes(bytesZ.length), ...bytesZ, ...littleEndianBytes(bytesV.length), ...bytesV, ...littleEndianBytes(w0Bytes.length), ...w0Bytes, ]); } ``` -------------------------------- ### Convert to Uncompressed EC Point Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/convertToUncompressedECPoint.html Converts provided point data into an uncompressed elliptic curve point format. Ensure the input pointData is valid. This method utilizes OpenSSL for cryptographic operations. ```dart Uint8List convertToUncompressedECPoint(Uint8List pointData) { return _context((group, ctx, _) { final cp = _openssl.EC_POINT_new(group); final buf = pointData.toPointer(); _openssl.EC_POINT_oct2point(group, cp, buf, pointData.length, ctx); final len = 65; final ptr = calloc(len); _openssl.EC_POINT_point2oct( group, cp, point_conversion_form_t.POINT_CONVERSION_UNCOMPRESSED, ptr, len, ctx, ); final ret = Uint8List.fromList(ptr.cast().asTypedList(len)); _openssl.EC_POINT_free(cp); calloc.free(buf); calloc.free(ptr); return ret; }); } ``` -------------------------------- ### randomValidScalar Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus-class.html Generates a cryptographically secure random scalar. ```APIDOC ## randomValidScalar ### Description Generates a cryptographically secure random scalar value suitable for use in elliptic curve cryptography. ### Returns - **Uint8List** - A random scalar as a byte array. ``` -------------------------------- ### randomValidScalar Method Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/randomValidScalar.html Generates a cryptographically secure random scalar value of 32 bytes. ```APIDOC ## randomValidScalar() ### Description Generates a cryptographically secure random scalar value. This method is used internally for generating random numbers within a specific range, typically for cryptographic protocols. ### Signature `Uint8List randomValidScalar()` ### Returns - `Uint8List`: A 32-byte array representing the random scalar value. ``` -------------------------------- ### cmacAes128 Function Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/cmacAes128.html The cmacAes128 function computes the CMAC for the given data using a provided key. It utilizes an underlying OpenSSL implementation and returns the resulting 16-byte CMAC tag. ```APIDOC ## cmacAes128 Function Signature ### Description Computes the Cipher-based Message Authentication Code (CMAC) using AES-128. ### Parameters - **key** (Uint8List) - The secret key for AES-128 encryption. - **data** (Uint8List) - The data for which to compute the CMAC. ### Returns - **Uint8List** - A 16-byte array representing the CMAC tag. ### Implementation Example ```dart Uint8List cmacAes128(Uint8List key, Uint8List data) { final cmac = _openssl.cmacAes128(key, data); final ret = Uint8List.fromList((cmac as ffi.Pointer).asTypedList(16)); calloc.free(cmac); return ret; } ``` ``` -------------------------------- ### CMAC AES128 Implementation Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/cmacAes128.html This function computes the CMAC for given key and data using AES128. It utilizes an internal OpenSSL binding and frees allocated memory after use. ```dart Uint8List cmacAes128(Uint8List key, Uint8List data) { final cmac = _openssl.cmacAes128(key, data); final ret = Uint8List.fromList((cmac as ffi.Pointer).asTypedList(16)); calloc.free(cmac); return ret; } ``` -------------------------------- ### Generate Random Scalar - Dart Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/Spake2plus/randomValidScalar.html Generates a cryptographically secure random scalar of 32 bytes. This method is used internally for cryptographic operations requiring random values within a specific order. ```dart Uint8List randomValidScalar() { return _context((group, ctx, order) { final p = _openssl.BN_new(); _openssl.BN_rand_range(p, order); final ret = _openssl.bn2bytes(group, p, 32, ctx); _openssl.BN_free(p); return ret; }); } ``` -------------------------------- ### Declare Salt Property in Dart Source: https://pub.dev/documentation/spake2plus/latest/spake2plus/ScryptParameters/salt.html This snippet shows the declaration of the final String salt property in Dart. It is typically used to store a unique salt value for cryptographic operations. ```dart final String salt; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.