MTE Base Code Examples
Purpose
The objective of an MTE Base "Examples" is to provide short examples of common MTE Base actions.
MTE Setup
To use the MTE in an application there are some headers and/or code snippets that must be included in the project to pull in the native library as well as any wrapper files that have been created.
- C
- C++
- CSharp
- Java
- JavaScript
- Swift
- Python
- Go
- PHP
//--------------------------------------------------------
// Add the path to the "include" directory of the SDK in the
// header search path.
// Each header file needed will neet to be referenced.
//--------------------------------------------------------
#include "mte_base.h"
#include "mte_status.h"
#include "mte_enc.h"
#include "mte_dec.h"
// Include the following relevant headers if using the MKE add-on.
#include "mte_mke_enc.h"
#include "mte_mke_dec.h"
// Include the following relevant header if using the FLEN add-on.
#include "mte_flen_enc.h"
#include "MteBase.h"
#include "mte_status.h"
#include "MteEnc.h"
#include "MteDec.h"
// Include the following relevant headers if using the MKE add-on.
#include "MteMkeEnc.h"
#include "MteMkeDec.h"
// Include the following relevant header if using the FLEN add-on.
#include "MteFlenEnc.h"
//----------------------------------------------------------------------
// There are two different options when setting up the MTE in CSharp
//----------------------------------------------------------------------
// Both of the following options require that the native library
// is also included in the solution
//----------------------------------------------------------------------
//-----------
// Option 1
//-----------
//-------------------------------------------------------------
// Include the Eclypses.MTE.Core NuGet package in the solution
//-------------------------------------------------------------
// Ensure each page where the MTE is referenced has this
using Eclypses.MTE;
//-----------
// Option 2
//-----------
//----------------------------------------------------------------
// Include ALL files found inside the MTE archive folder "/src/cs/"
//----------------------------------------------------------------
// Ensure each page where the MTE is referenced has this
using Eclypses.MTE;
//--------------------------------------------------------
// Include the "com.eclypses.mte" package in the solution
// This can be found in the MTE archive folder "src/java"
//--------------------------------------------------------
// The solution must also include a path to the native
// library itself in the Build Path configuration
//--------------------------------------------------------
// Each page that references the MTE must have the following
//--------------------------------------------------------
import com.eclypses.mte.*;
// import the entire MTE library
import MTELib from "mte-wasm-browser";
// OR, import individual modules
import { MteWasm, MteBase, MteEnc, MteDec } from "mte-wasm-browser";
/*
This is a template bridging header that contains all necessary header
includes. If your project has an existing bridging header, you can copy
the relevant includes to that header. If your project does not have a
bridging header, you can uncomment the relevant lines and use this file
directly.
Note that the headers listed here include other headers, so the entire SDK
include directory should be kept in tact. Directly including these is enough
to get the associated Swift classes to build. You should uncomment only the
includes associated with the classes you need, and only include the classes
you really need in your project. There is a derivation chain, so you need to
include all base classes in your project as well.
*/
// Base (MteBase) includes. These are required to use any part of MTE.
#include "mte_init.h"
#include "mte_license.h"
#include "mte_version.h"
#include "mte_base.h"
#include "mte_wrap_base.h"
// Core decoder (MteDec).
#include "mte_dec.h"
#include "mte_wrap_dec.h"
// Core encoder (MteEnc).
#include "mte_enc.h"
#include "mte_wrap_enc.h"
// Fixed-Length Add-On encoder (MteFlenEnc).
#include "mte_flen_enc.h"
#include "mte_wrap_flen_enc.h"
// Managed-Key Encryption Add-On decoder (MteMkeDec).
#include "mte_mke_dec.h"
#include "mte_wrap_mke_dec.h"
// Managed-Key Encryption Add-On encoder (MteMkeEnc).
#include "mte_mke_enc.h"
#include "mte_wrap_mke_enc.h"
# Initialize MTE Core libraries.
from MteBase import MteBase
from MteStatus import MteStatus
from MteEnc import MteEnc
from MteDec import MteDec
from MteDrbgs import MteDrbgs
from MteVerifiers import MteVerifiers
from MteHashes import MteHashes
from MteCiphers import MteCiphers
# Import the following relevant libraries if you are using the MKE or FLEN add-ons.
from MteMkeEnc import MteMkeEnc
from MteMkeDec import MteMkeDec
from MteFlenEnc import MteFlenEnc
/*
Create a directory named "mte" in the main directory.
Add the contents of the “src/go” directory from the
mte-Windows package or mte-Linux package into the newly
created mte directory.
Add the corresponding "lib" directory and contents
to the mte directory as well.
Add the following to the import statement at the top of the file
where you need to use the MTE
*"moduleName" is the name of your go module
*/
import (
"moduleName/mte"
)
//--------------------------------------------------------
// The mtephp Extension must be installed on your version
// of PHP. PHP7 and PHP8 are supported.
//
// For instructions on how to install the mtephp
// extension please see PHP Extension ReadMe File
//--------------------------------------------------------
MTE Initialization
The MTE initialization must be called before any other MTE function. For many of the languages the wrapper will take care of this for you. The exception to this is C and JavaScript. JavaScript requires that the WASM be initialized.
- C
- JavaScript
// Initialize MTE
if (!mte_init(NULL, NULL))
{
fputs("MTE init error.", stderr);
return -1;
}
import { MteWasm } from "mte-wasm-browser";
const mteWasm = new MteWasm();
await mteWasm.instantiate();
MTE Version
The MTE requires both sides to use compatible versions. To check the version that is running simply call the MTE version method. Additionally, the version of the Language Interface must also match the version of the library, making it very important to update all language interface files when upgrading the MTE library.
- C
- C++
- CSharp
- Java
- JavaScript
- Swift
- Python
- Go
- PHP
// Get version of MTE we are using.
const char* mte_version = mte_base_version();
printf("%s\n", mte_version);
// There are macros available when including
// the header "mte_version.h"
// Get version of MTE in a char pointer.
const char* version = MTE_VERSION;
printf("%s\n", version);
// Get MTE major version number as an integer.
int mte_major_version = MTE_VERSION_MAJOR;
printf("%d\n", mte_major_version);
// Get MTE minor version number as an integer
int mte_minor_version = MTE_VERSION_MINOR;
printf("%d\n", mte_minor_version);
// Get MTE patch version number as an integer
int mte_patch_version = MTE_VERSION_PATCH;
printf("%d\n", mte_patch_version);
// Get version of MTE we are using.
const char* mteVersion = MteBase::getVersion();
std::cout << mteVersion << std::endl;
// Get MTE major version number as size_t.
const size_t mteMajorVersion = MteBase::getVersionMajor();
std::cout << mteMajorVersion << std::endl;
// Get MTE minor version number as size_t.
const size_t mteMinorVersion = MteBase::getVersionMinor();
std::cout << mteMinorVersion << std::endl;
// Get MTE patch version number as size_t.
const size_t mtePatchVersion = MteBase::getVersionPatch();
std::cout << mtePatchVersion << std::endl;
// Create encoder or decoder as shown above
// Get version of MTE in a string
string mteVersion = mteEncoder.GetVersion();
// Get Mte major version number as an integer
int mteMajorVersion = mteEncoder.GetVersionMajor();
// Get MTE minor version number as an integer
int mteMinorVersion = mteEncoder.GetVersionMinor();
// Get MTE patch version number as an integer
int mtePatchVersion = mteEncoder.GetVersionPatch();
// Log MTE Version
logger.LogDebug($"MTE version is {mteMajorVersion}.{mteMinorVersion}.{mtePatchVersion}");
// Get version of MTE we are using
String mteVersion = MteBase.getVersion();
// Get Mte major version number as an integer
int mteMajorVersion = MteBase.getVersionMajor();
// Get MTE minor version number as an integer
int mteMinorVersion = MteBase.getVersionMinor();
// Get MTE patch version number as an integer
int mtePatchVersion = MteBase.getVersionPatch();
// Log MTE Major version
System.out.print("MTE version is " + mteMajorVersion + "." + mteMinorVersion + "." + mtePatchVersion);
import { MteWasm, MteBase, MteDrbgs } from "mte-wasm-browser";
// instantiate wasm
const mteWasm = new MteWasm();
await mteWasm.instantiate();
// create instance of MteBase
const mteBase = new MteBase(mteWasm, MteDrbgs.mte_drbgs_none);
// log MTE version
const version = mteBase.getVersion();
console.log(`MTE Version is: ${version}`);
// Log MTE major version
const major = mteBase.getVersionMajor();
console.log(major);
// Log MTE minor version
const minor = mteBase.getVersionMinor();
console.log(minor);
// Log MTE patch version
const patch = mteBase.getVersionPatch();
console.log(patch);
// Get version of MTE we are using
let mteVersion: String = MteBase.getVersion()
print(mteVersion)
// Get Mte major version number as an integer
let mteMajorVersion: Int = MteBase.getVersionMajor()
print(mteMajorVersion)
// Get MTE minor version number as an integer
let mteMinorVersion: Int = MteBase.getVersionMinor()
print(mteMinorVersion)
// Get MTE patch version number as an integer
let mtePatchVersion: Int = MteBase.getVersionPatch()
print(mtePatchVersion)
# Get version of MTE in a string.
mte_version = MteBase.get_version()
# Get Mte major version number as an integer.
mte_major_version = MteBase.get_version_major()
# Get Mte minor version number as an integer.
mte_minor_version = MteBase.get_version_minor()
# Get Mte patch version number as an integer.
mte_patch_version = MteBase.get_version_patch()
// Get MTE version
mteVersion := mte.GetVersion()
// Get MTE major version number
mteMajorVersion := mte.GetVersionMajor()
// Get MTE minor version number
mteMinorVersion := mte.GetVersionMinor()
// Get MTE patch version number
mtePatchVersion := mte.GetVersionPatch()
// print out MTE version
fmt.Printf("Using MTE Version %s\n", mteVersion)
<?php
$version = mte_get_version();
$major = mte_get_version_major();
$minor = mte_get_version_minor();
$patch = mte_get_version_patch();
echo "MTE Version: " .$version. " ";
echo "MTE Major: " .$major. " ";
echo "MTE Minor: " .$minor. " ";
echo "MTE Patch: " .$patch. " ";
?>
Initializing MTE License
A licensed version of the MTE must be initialized with the company name and license code. A licensed version of the library will have “-LIC” before the version number in the name of the package downloaded from the Eclypses developer’s portal. Below is a code sample:
- C
- C++
- CSharp
- Java
- JavaScript
- Python
- Swift
- Go
- PHP
/* Initialize MTE license. If a license code is not required (e.g., trial
mode), this can be skipped. This demo attempts to load the license info
from the environment if required. */
if (!mte_license_init("YOUR_COMPANY", "YOUR_LICENSE"))
{
company = getenv("MTE_COMPANY");
license = getenv("MTE_LICENSE");
if (company == NULL || license == NULL ||
!mte_license_init(company, license))
{
fprintf(stderr, "License init error (%s): %s\n",
mte_base_status_name(mte_status_license_error),
mte_base_status_description(mte_status_license_error));
return mte_status_license_error;
}
}
// Initialize MTE license. If a license code is not required (e.g., trial
// mode), this can be skipped. This demo attempts to load the license info
// from the environment if required.
if (!MteBase::initLicense("YOUR_COMPANY", "YOUR_LICENSE"))
{
const char *company = getenv("MTE_COMPANY");
const char *license = getenv("MTE_LICENSE");
if (company == NULL || license == NULL ||
!MteBase::initLicense(company, license))
{
std::cerr << "License init error ("
<< MteBase::getStatusName(mte_status_license_error)
<< "): "
<< MteBase::getStatusDescription(mte_status_license_error)
<< std::endl;
return mte_status_license_error;
}
}
// Create mte encoder or decoder
MteEnc mteEncoder = new MteEnc();
// Initialize the MTE license
if (!mteEncoder.InitLicense(appSettings.LicenseCompanyName, appSettings.LicenseKey)) {
// MTE cannot continue so this should be dealt with appropriately
// Set encoder status to a license error
_encoderStatus = MteStatus.mte_status_license_error;
// License error, Mte cannot continue handle appropriately
// Below is an example
Log.LogError ("MTE license appears to be invalid. MTE cannot be initalized ({0}): {1}. Press any key to end.",
mteEncoder.GetStatusName(_encoderStatus),
mteEncoder.GetStatusDescription(_encoderStatus));
return;
}
// Initialize the MTE license
if (!MteBase.initLicense(LicenseCompanyName, LicenseKey)) {
// MTE cannot continue so this should be dealt with appropriately
// Set encoder status to a license error
_encoderStatus = MteStatus.mte_status_license_error;
// Build error
System.out.print("MTE license appears to be invalid. MTE cannot be initalized (" + MteBase.getStatusName(_encoderStatus) + ": "
+ MteBase.getStatusDescription(_encoderStatus) + ". Press any key to end");
return;
}
import { MteWasm, MteBase, MteDrbgs } from "mte-wasm-browser";
// instantiate wasm
const mteWasm = new MteWasm();
await mteWasm.instantiate();
// create instance of MteBase
const mteBase = new MteBase(mteWasm, MteDrbgs.mte_drbgs_none);
// initialize MTE license
const initLicenseResult = mteBase.initLicense(licenseCompany, licenseKey);
if (!initLicenseResult) {
const licenseStatus = MteStatus.mte_status_license_error;
const status = mteBase.getStatusName(licenseStatus);
const message = mteBase.getStatusDescription(licenseStatus);
throw new Error(
`MTE license appears to be invalid. MTE cannot be initalized.\n${status}: ${message}`,
);
}
# Initialize the MTE license.
init_license_result = MteBase.init_license(license_company, license_key)
if not init_license_result:
# MTE cannot continue so this should be dealt with appropriately.
# Set encoder status to a license error.
encoder_status = MteStatus.mte_status_license_error
# License error, Mte cannot continue handle appropriately.
# Below is an example.
(status,message) = MteBase.get_status_name(encoder_status),
MteBase.get_status_description(encoder_status)
print("MTE license appears to be invalid. MTE cannot be initalized. ({0}): {1}. Press any key to end".format(
status,
message),
file=sys.stderr)
input()
exit(1)
// Initialize the MTE license
if (!MteBase.initLicense(licenseCompanyName, licenseKey)) {
// MTE cannot continue so this should be dealt with appropriately
print("MTE license appears to be invalid. MTE cannot be initalized")
}
// Initialize the MTE license
if !mte.InitLicense(companyName, companyLicense) {
fmt.Println("MTE license appears to be invalid. MTE cannot be initalized.")
return
}
<?php
define("COMPANY", "companyName");
define("LICENSE", "companyLicense");
// Initialize the MTE license
if(!mte_license_init(COMPANY, LICENSE)){
echo "MTE license appears to be invalid. MTE cannot be initalized.";
return;
}
?>
Interpreting the MTE Status
Most MTE methods return an MTE status which is meant to reflect if the MTE method was successful or not. If there is an error the status will help the developer to understand what went wrong. For a detailed explanation of what each status means please see the MTE Developer Guides.
- C
- C++
- CSharp
- Java
- JavaScript
- Swift
- Python
- Go
- PHP
// MTE status description where "status" is the MteStatus.
const char* status_description = mte_base_status_description(status);
// MTE status name.
const char* status_name = mte_base_status_name(status);
// MTE status description where "status" is the MteStatus.
const char* statusDescription = MteBase::getStatusDescription(status);
// MTE status name.
const char* statusName = MteBase::getStatusName(status);
// MTE status description where "status" is the MteStatus
string statusDescription = mteEncoder.GetStatusDescription(status);
// MTE status name
string StatusName = mteEncoder.GetStatusName(status);
// MTE status description where "status" is the MteStatus
String statusDescription = MteBase.getStatusDescription(status);
// MTE status name
String StatusName = MteBase.getStatusName(status);
import { MteStatus } from "mte-wasm-browser";
// encode string, and get back encode result
const encodeResult = mteEncoder.encodeStrB64(str);
// check if encode failed
if (encodeResult.status !== MteStatus.mte_status_success) {
const status = mteBase.getStatusName(encodeResult);
const message = mteBase.getStatusDescription(encodeResult);
throw new Error(`Error when MTE encoding data.\n${status}: ${message}`);
return "";
}
// if status was success, return encode result
return encodeResult.str;
// MTE status name and description where "status" is the mte_status returned from a function
let statusName: String = MteBase.getStatusName(status)
let statusDescription: String = MteBase.getStatusDescription(status)
# MTE status description where "status" is the MteStatus.
status_description = MteBase.get_status_description(status)
# MTE status name.
status_name = MteBase.get_status_name(status)
// MTE status description where "status" == MteStatus
statusDescription := mte.GetStatusDescription(status)
// MTE status name where "status" == MteStatus
statusName := mte.GetStatusName(status)
<?php
$mteBase = new MteBase();
// MTE status description where "status" == MteStatus
$statusDescription = $mteBase->getStatusDescription(constant($status));
// MTE status name where "status" == MteStatus
$statusName = $mteBase->getStatusName(constant($status))
?>
Algorithm Name to String and Vice Versa
If settings are being passed into a program from a database or settings file one may need to convert the string name of an algorithm into the actual algorithm parameter or the algorithm parameter name into a string.
- C
- C++
- CSharp
- Java
- Swift
- Python
- Go
- PHP
// Convert from char * to Algorithm.
enum mte_drbgs drbg = mte_base_drbgs_algo("mte_drbgs_ctr_aes128_df");
enum mte_verifiers verifier = mte_base_verifiers_algo("mte_verifiers_t64_crc32");
enum mte_hashes hash = mte_base_hashes_algo("mte_hashes_sha256");
enum mte_ciphers cipher = mte_base_ciphers_algo("mte_ciphers_aes256_ctr");
// Get Algorithm name in a char *.
const char* drbg_string_name = mte_base_drbgs_name(drbg);
const char* verifier_string_name = mte_base_verifiers_name(verifier);
const char* hash_string_name = mte_base_hashes_name(hash);
const char* cipher_string_name = mte_base_ciphers_name(cipher);
// Convert from char * to Algorithm.
mte_drbgs drbg = MteBase::getDrbgsAlgo("mte_drbgs_ctr_aes128_df");
mte_verifiers verifier = MteBase::getVerifiersAlgo("mte_verifiers_t64_crc32");
mte_hashes hash = MteBase::getHashesAlgo("mte_hashes_sha256");
mte_ciphers cipher = MteBase::getCiphersAlgo("mte_ciphers_aes256_ctr");
// Get Algorithm name in a char *.
const char* drbgStringName = MteBase::getDrbgsName(drbg);
const char* verifierStringName = MteBase::getVerifiersName(verifier);
const char* hashStringName = MteBase::getHashesName(hash);
const char* cipherStringName = MteBase::getCiphersName(cipher);
// Create default encoder or decoder
MteEnc mteEncoder = new MteEnc();
// Convert from string to Algorithm
MteDrbgs drbg = mteEncoder.GetDrbgsAlgo("mte_drbgs_ctr_aes128_df");
MteVerifiers verifier = mteEncoder.GetVerifiersAlgo("mte_verifiers_t64_crc32");
MteHashes hash = mteEncoder.GetHashesAlgo("mte_hashes_sha256");
MteCiphers cipher = mteEncoder.GetCiphersAlgo("mte_ciphers_aes256_ctr");
// Get Algorithm name in a string
string drbgStringName = mteEncoder.GetDrbgsName(drbg);
string verifierStringName = mteEncoder.GetVerifiersName(verifier);
string hashStringName = mteEncoder.GetHashesName(hash);
string cipherStringName = mteEncoder.GetCiphersName(cipher);
// Convert from string to Algorithm
MteDrbgs drbg = MteBase.getDrbgsAlgo("mte_drbgs_ctr_aes128_df");
MteVerifiers verifier = MteBase.getVerifiersAlgo("mte_verifiers_t64_crc32");
MteHashes hash = MteBase.getHashesAlgo("mte_hashes_sha256");
MteCiphers cipher = MteBase.getCiphersAlgo("mte_ciphers_aes256_ctr");
// Get Algorithm name in a string
String drbgStringName = MteBase.getDrbgsName(drbg);
String verifierStringName = MteBase.getVerifiersName(verifier);
String hashStringName = MteBase.getHashesName(hash);
String cipherStringName = MteBase.getCiphersName(cipher);
// Convert from the string name of a given algorithm to Algorithm object
let drbg: mte_drbg = MteBase.getDrbgsAlgo("mte_drbgs_ctr_aes128_df")
let verifier: mte_verifiers = MteBase.getVerifiersAlgo("mte_verifiers_t64_crc32")
let hash: mte_hashes = MteBase.getHashesAlgo("mte_hashes_sha256")
let cipher: mte_cipher = MteBase.getCiphersAlgo("mte_ciphers_aes256_ctr")
// Get Algorithm name in a string for a given algorithm
let drbgName: String = MteBase.getDrbgsName(drbg)
let verifiersName: String = MteBase.getVerifiersName(verifier)
let hashName: String = MteBase.getHashesName(hash)
let cipherName: String = MteBase.getCiphersName(cipher)
# Convert from string to Algorithm.
drbg = MteBase.get_drbgs_algo("mte_drbgs_ctr_aes128_df")
verifier = MteBase.get_verifiers_algo("mte_verifiers_t64_crc32")
hash = MteBase.get_hashes_algo("mte_hashes_sha256")
cipher = MteBase.get_ciphers_algo("mte_ciphers_aes256_ctr")
# Get Algorithm name in a string.
drbg_name = MteBase.get_drbgs_name(drbg)
verifiers_name = MteBase.get_verifiers_name(verifier)
hash_name = MteBase.get_hashes_name(hash)
cipher_name = MteBase.get_ciphers_name(cipher)
// Convert from the string name of an algorithm to Algorhtm object
drbg := mte.GetDrbgsAlgo("mte_drbgs_ctr_aes128_df")
verifier := mte.GetVerifiersAlgo("mte_verifiers_t64_crc32")
hash := mte.GetHashesAlgo("mte_hashes_sha256")
cipher := mte.GetCiphersAlgo("mte_ciphers_aes256_ctr")
// Get Algorithm name in a string for a given algorithm
drbgName := mte.GetDrbgsName(drbg)
verifierName := mte.GetVerifiersName(verifier)
hashName := mte.GetHashesName(hash)
cipherName := mte.GetCiphersName(cipher)
<?php
# Convert from string to Algorithm.
$drbg = MteBase.get_drbgs_algo("mte_drbgs_ctr_aes128_df")
$verifier = MteBase.get_verifiers_algo("mte_verifiers_t64_crc32")
$hash = MteBase.get_hashes_algo("mte_hashes_sha256")
$cipher = MteBase.get_ciphers_algo("mte_ciphers_aes256_ctr")
# Get Algorithm name in a string.
$drbg_name = MteBase.get_drbgs_name(constant($drbg))
$verifiers_name = MteBase.get_verifiers_name(constant($verifier))
$hash_name = MteBase.get_hashes_name(constant($hash))
$cipher_name = MteBase.get_ciphers_name(constant($cipher))
?>
Option Min and Max values
Depending on which DRBG algorithm is selected the size of the entropy, personalization string and nonce byte length requirements can change. To get the byte length of these options needed for a given DRBG the following code can be used for and MTE Encoder, the exact same methods are available for an MTE Decoder as well.
- C
- C++
- CSharp
- Java
- Swift
- Python
- Go
- PHP
// Get the minimum and maximum entropy byte length.
size_t min_entropy_bytes = mte_base_drbgs_entropy_min_bytes(MTE_DRBG_ENUM);
size_t max_entropy_bytes = mte_base_drbgs_entropy_max_bytes(MTE_DRBG_ENUM);
// Get min and max personalization string byte length.
size_t min_personal_bytes = mte_base_drbgs_personal_min_bytes(MTE_DRBG_ENUM);
size_t max_personal_bytes = mte_base_drbgs_personal_max_bytes(MTE_DRBG_ENUM);
// Get min and max nonce byte length.
size_t min_nonce_bytes = mte_base_drbgs_nonce_min_bytes(MTE_DRBG_ENUM);
size_t max_nonce_bytes = mte_base_drbgs_nonce_max_bytes(MTE_DRBG_ENUM);
// Get the minimum and maximum entropy byte length.
size_t minEntropyBytes = MteBase::getDrbgsEntropyMinBytes(MTE_DRBG_ENUM);
size_t maxEntropyBytes = MteBase::getDrbgsEntropyMaxBytes(MTE_DRBG_ENUM);
// Get min and max personalization string byte length.
size_t minPersonalBytes = MteBase::getDrbgsPersonalMinBytes(MTE_DRBG_ENUM);
size_t maxPersonalBytes = MteBase::getDrbgsPersonalMaxBytes(MTE_DRBG_ENUM);
// Get min and max nonce byte length.
size_t minNonceBytes = MteBase::getDrbgsNonceMinBytes(MTE_DRBG_ENUM);
size_t maxNonceBytes = MteBase::getDrbgsNonceMaxBytes(MTE_DRBG_ENUM);
// Create the Encoder with default options
MteEnc mteEncoder = new MteEnc();
// Get the minimum and maximum entropy byte length
int minEntropyBytes = mteEncoder.GetDrbgsEntropyMinBytes(mteEncoder.GetDrbg());
int maxEntropyBytes = mteEncoder.GetDrbgsEntropyMaxBytes(mteEncoder.GetDrbg());
// Get min and max personalization string byte length
int minPersonalBytes = mteEncoder.GetDrbgsPersonalMinBytes(mteEncoder.GetDrbg());
int maxPersonalBytes = mteEncoder.GetDrbgsPersonalMaxBytes(mteEncoder.GetDrbg());
// Get min and max nonce byte length
int minNonceBytes = mteEncoder.GetDrbgsNonceMinBytes(mteEncoder.GetDrbg());
int maxNonceBytes = mteEncoder.GetDrbgsNonceMaxBytes(mteEncoder.GetDrbg());
// Create the Encoder with default options
MteEnc encoder = new MteEnc();
// Get the min and max entropy byte length
int minEntropyBytes = MteBase.getDrbgsEntropyMinBytes(mteEncoder.getDrbg());
int maxEntropyBytes = MteBase.getDrbgsEntropyMaxBytes(mteEncoder.getDrbg());
// Get min and max personalization string byte length
int minPersonalBytes = MteBase.getDrbgsPersonalMinBytes(mteEncoder.getDrbg());
int maxPersonalBytes = MteBase.getDrbgsPersonalMaxBytes(mteEncoder.getDrbg());
// Get min and max nonce byte length
int minNonceBytes = MteBase.getDrbgsNonceMinBytes(mteEncoder.getDrbg());
int maxNonceBytes = MteBase.getDrbgsNonceMaxBytes(mteEncoder.getDrbg());
// In this example, an Mte Encoder is created with default options.
// In practice, use the previously initialized MTE, MKE, or FLEN (Fixed-Length) Encoder or Decoder.
let mteEncoder: = try MteEnc()
// Get the min and max entropy byte length
let minEntropyBytes: Int = MteBase.getDrbgsEntropyMinBytes(mteEncoder.getDrbg())
let maxEntropyBytes: UInt64 = MteBase.getDrbgsEntropyMaxBytes(mteEncoder.getDrbg())
// Get min and max personalization string byte length
let minPersonalBytes: Int = MteBase.getDrbgsPersonalMinBytes(mteEncoder.getDrbg())
let maxPersonalBytes: UInt64 = MteBase.getDrbgsPersonalMaxBytes(mteEncoder.getDrbg())
// Get min and max nonce byte length
let minNonceBytes: Int = MteBase.getDrbgsNonceMinBytes(mteEncoder.getDrbg())
let maxNonceBytes: Int = MteBase.getDrbgsNonceMaxBytes(mteEncoder.getDrbg())
# Create the Encoder with default options.
mte_encoder = MteEnc.fromdefault()
# Get the minimum and maximum entropy byte length.
min_entropy_bytes = MteBase.get_drbgs_entropy_min_bytes(mte_encoder.get_drbg())
max_entropy_bytes = MteBase.get_drbgs_entropy_max_bytes(mte_encoder.get_drbg())
# Get min and max personalization string byte length.
min_personal_bytes = MteBase.get_drbgs_personal_min_bytes(mte_encoder.get_drbg())
max_personal_bytes = MteBase.get_drbgs_personal_max_bytes(mte_encoder.get_drbg())
# Get min and max nonce byte length
min_nonce_bytes = MteBase.get_drbgs_nonce_min_bytes(mte_encoder.get_drbg())
max_nonce_bytes = MteBase.get_drbgs_nonce_max_bytes(mte_encoder.get_drbg())
// Create Encoder with default options
mteEncoder := mte.NewEncDef()
defer mteEncoder.Destroy()
// Get the min and max entropy byte length
minEntropyBytes := mte.GetDrbgsEntropyMinBytes(mteEncoder.GetDrbg())
maxEntropyBytes := mte.GetDrbgsEntropyMaxBytes(mteEncoder.GetDrbg())
// Get min and max personalization string byte length
minPersonalBytes := mte.GetDrbgsPersonalMinBytes(mteEncoder.GetDrbg())
maxPersonalBytes := mte.GetDrbgsPersonalMaxBytes(mteEncoder.GetDrbg())
// Get min and max nonce byte length
minNonceBytes := mte.GetDrbgsNonceMinBytes(mteEncoder.GetDrbg())
maxNonceBytes := mte.GetDrbgsNonceMaxBytes(mteEncoder.GetDrbg())
<?php
// Create Encoder with default options
$mteEnc = new MteEnc();
// Get the min and max entropy byte length
$minEntropyBytes = $mteEnc->getDrbgsEntropyMinBytes(constant($mteEnc->getDrbg()));
$maxEntropyBytes = $mteEnc->getDrbgsEntropyMaxBytes(constant($mteEnc->getDrbg()));
// Get the min and max personalization byte length
$minPersonalBytes = $mteEnc->getDrbgsPersonalMinBytes(constant($mteEnc->getDrbg()));
$maxPersonalBytes = $mteEnc->getDrbgsPersonalMaxBytes(constant($mteEnc->getDrbg()));
// Get the min and max nonce byte length
$minNonceBytes = $mteEnc->getDrbgsNonceMinBytes(constant($mteEnc->getDrbg()));
$maxNonceBytes = $mteEnc->getDrbgsNonceMaxBytes(constant($mteEnc->getDrbg()));
?>