SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
Nordic CRACEN primitives

Detailed Description

Platform-specific finite-field, EC-KCDSA, DSA, SHAKE256 and SM4 operations.

These APIs require Nordic CRACEN libraries and initialized PSA Crypto. See SharkSSL Nordic CRACEN integration for source selection and platform requirements. They do not add TLS cipher suites or signature schemes.

Files

file  SharkSslCRACENFF.h
 See SharkSSL Nordic CRACEN integration for required sources and platform setup.
 
file  SharkSslCRACENECKCDSA.h
 See SharkSSL Nordic CRACEN integration for required sources and platform setup.
 
file  SharkSslCRACENDSA.h
 See SharkSSL Nordic CRACEN integration for required sources and platform setup.
 
file  SharkSslCRACENSHAKE256.h
 See SharkSSL Nordic CRACEN integration for required sources and platform setup.
 
file  SharkSslCRACENSM4.h
 See SharkSSL Nordic CRACEN integration for required sources and platform setup.
 

Data Structures

struct  SharkSslCRACENFF
 Nordic CRACEN finite-field context. More...
 

Macros

#define SHARKSSL_CRACEN_FF_OK   0
 Operation succeeded (0). More...
 
#define SHARKSSL_CRACEN_FF_BAD_ARGUMENT   -1
 Invalid argument or unsupported input size. More...
 
#define SHARKSSL_CRACEN_FF_UNAVAILABLE   -2
 Required hardware or capability unavailable. More...
 
#define SHARKSSL_CRACEN_FF_HARDWARE_ERROR   -3
 Hardware operation failed. More...
 
#define SHARKSSL_CRACEN_ECKCDSA_P256_BYTES   32
 P-256 scalar and coordinate size in bytes. More...
 
#define SHARKSSL_CRACEN_ECKCDSA_OK   0
 Operation succeeded (0). More...
 
#define SHARKSSL_CRACEN_ECKCDSA_BAD_ARGUMENT   -1
 Invalid argument or unsupported input size. More...
 
#define SHARKSSL_CRACEN_ECKCDSA_INVALID_SIGNATURE   -2
 Signature or public key rejected. More...
 
#define SHARKSSL_CRACEN_ECKCDSA_UNAVAILABLE   -3
 Required hardware or capability unavailable. More...
 
#define SHARKSSL_CRACEN_ECKCDSA_HARDWARE_ERROR   -4
 Hardware operation failed. More...
 
#define SHARKSSL_CRACEN_ECKCDSA_RETRY_NONCE   -5
 Retry signing with a fresh nonce. More...
 
#define SHARKSSL_CRACEN_DSA_P_BYTES   256
 DSA domain prime and public key size in bytes. More...
 
#define SHARKSSL_CRACEN_DSA_Q_BYTES   32
 DSA order, scalar, digest and signature component size in bytes. More...
 
#define SHARKSSL_CRACEN_DSA_OK   0
 Operation succeeded (0). More...
 
#define SHARKSSL_CRACEN_DSA_BAD_ARGUMENT   -1
 Invalid argument or unsupported input size. More...
 
#define SHARKSSL_CRACEN_DSA_INVALID_SIGNATURE   -2
 Signature or public key rejected. More...
 
#define SHARKSSL_CRACEN_DSA_UNAVAILABLE   -3
 Required hardware or capability unavailable. More...
 
#define SHARKSSL_CRACEN_DSA_HARDWARE_ERROR   -4
 Hardware operation failed. More...
 
#define SHARKSSL_CRACEN_DSA_RETRY_NONCE   -5
 Retry signing with a fresh nonce. More...
 
#define SHARKSSL_CRACEN_SHAKE256_MAX_OUTPUT   512
 Maximum SHAKE256 output length in bytes. More...
 
#define SHARKSSL_CRACEN_SHAKE256_OK   0
 Operation succeeded (0). More...
 
#define SHARKSSL_CRACEN_SHAKE256_BAD_ARGUMENT   -1
 Invalid argument or unsupported input size. More...
 
#define SHARKSSL_CRACEN_SHAKE256_UNAVAILABLE   -2
 Required hardware or capability unavailable. More...
 
#define SHARKSSL_CRACEN_SHAKE256_HARDWARE_ERROR   -3
 Hardware operation failed. More...
 
#define SHARKSSL_CRACEN_SM4_BLOCK_LEN   16
 SM4 block size in bytes. More...
 
#define SHARKSSL_CRACEN_SM4_KEY_LEN   16
 SM4 key size in bytes. More...
 
#define SHARKSSL_CRACEN_SM4_MODE_ECB   0
 Electronic codebook mode, without padding. More...
 
#define SHARKSSL_CRACEN_SM4_MODE_CBC   1
 Cipher block chaining mode, without padding. More...
 
#define SHARKSSL_CRACEN_SM4_MODE_CTR   2
 Counter mode, including partial final blocks. More...
 
#define SHARKSSL_CRACEN_SM4_OK   0
 Operation succeeded (0). More...
 
#define SHARKSSL_CRACEN_SM4_BAD_ARGUMENT   -1
 Invalid argument or unsupported input size. More...
 
#define SHARKSSL_CRACEN_SM4_UNAVAILABLE   -2
 Required hardware or capability unavailable. More...
 
#define SHARKSSL_CRACEN_SM4_HARDWARE_ERROR   -3
 Hardware operation failed. More...
 

Typedefs

typedef struct SharkSslCRACENFF SharkSslCRACENFF
 Nordic CRACEN finite-field context. More...
 

Functions

int SharkSslCRACENFF_init (SharkSslCRACENFF *o, const uint8_t *prime, uint16_t primeLen)
 Initialize a caller-owned finite-field context after PSA Crypto initialization. More...
 
int SharkSslCRACENFF_modExp (const SharkSslCRACENFF *o, const uint8_t *base, const uint8_t *exponent, uint8_t *result, uint16_t baseLen, uint16_t exponentLen, uint16_t resultLen)
 Calculate base^exponent modulo the context's prime. More...
 
int sharkssl_CRACENECKCDSA_publicKeyP256 (const uint8_t *privateScalar, uint8_t *publicX, uint8_t *publicY)
 Generate Q = inverse(d) * G for EC-KCDSA on NIST P-256. More...
 
int sharkssl_CRACENECKCDSA_signPartP256 (const uint8_t *privateScalar, const uint8_t *nonce, const uint8_t *r, const uint8_t *h, uint8_t *s)
 Compute the EC-KCDSA component s = d * (k - ((r xor h) mod n)) mod n. More...
 
int sharkssl_CRACENECKCDSA_verifyDigestP256 (const uint8_t *publicX, const uint8_t *publicY, const uint8_t *r, const uint8_t *s, const uint8_t *h)
 Verify a prehashed EC-KCDSA signature on NIST P-256. More...
 
int sharkssl_CRACENDSA_signDigest2048_256 (const uint8_t *p, const uint8_t *q, const uint8_t *g, const uint8_t *privateX, const uint8_t *nonceK, const uint8_t *hash, uint8_t *r, uint8_t *s)
 Sign a SHA-256 digest using trusted DSA 2048/256 domain parameters. More...
 
int sharkssl_CRACENDSA_verifyDigest2048_256 (const uint8_t *p, const uint8_t *q, const uint8_t *g, const uint8_t *publicY, const uint8_t *r, const uint8_t *s, const uint8_t *hash)
 Verify a prehashed DSA 2048/256 signature. More...
 
int sharkssl_CRACENSHAKE256_digest (const uint8_t *input, uint8_t *output, size_t inputLen, size_t outputLen)
 Compute a one-shot SHAKE256 digest using Nordic CRACEN. More...
 
int sharkssl_CRACENSM4_crypt (unsigned int mode, unsigned int decrypt, const uint8_t *key, const uint8_t *iv, const uint8_t *input, size_t inputLen, uint8_t *output, size_t outputSize)
 Encrypt or decrypt using SM4-128 on Nordic CRACEN. More...
 

Macro Definition Documentation

◆ SHARKSSL_CRACEN_DSA_BAD_ARGUMENT

#define SHARKSSL_CRACEN_DSA_BAD_ARGUMENT   -1

Invalid argument or unsupported input size.

◆ SHARKSSL_CRACEN_DSA_HARDWARE_ERROR

#define SHARKSSL_CRACEN_DSA_HARDWARE_ERROR   -4

Hardware operation failed.

◆ SHARKSSL_CRACEN_DSA_INVALID_SIGNATURE

#define SHARKSSL_CRACEN_DSA_INVALID_SIGNATURE   -2

Signature or public key rejected.

◆ SHARKSSL_CRACEN_DSA_OK

#define SHARKSSL_CRACEN_DSA_OK   0

Operation succeeded (0).

◆ SHARKSSL_CRACEN_DSA_P_BYTES

#define SHARKSSL_CRACEN_DSA_P_BYTES   256

DSA domain prime and public key size in bytes.

◆ SHARKSSL_CRACEN_DSA_Q_BYTES

#define SHARKSSL_CRACEN_DSA_Q_BYTES   32

DSA order, scalar, digest and signature component size in bytes.

◆ SHARKSSL_CRACEN_DSA_RETRY_NONCE

#define SHARKSSL_CRACEN_DSA_RETRY_NONCE   -5

Retry signing with a fresh nonce.

◆ SHARKSSL_CRACEN_DSA_UNAVAILABLE

#define SHARKSSL_CRACEN_DSA_UNAVAILABLE   -3

Required hardware or capability unavailable.

◆ SHARKSSL_CRACEN_ECKCDSA_BAD_ARGUMENT

#define SHARKSSL_CRACEN_ECKCDSA_BAD_ARGUMENT   -1

Invalid argument or unsupported input size.

◆ SHARKSSL_CRACEN_ECKCDSA_HARDWARE_ERROR

#define SHARKSSL_CRACEN_ECKCDSA_HARDWARE_ERROR   -4

Hardware operation failed.

◆ SHARKSSL_CRACEN_ECKCDSA_INVALID_SIGNATURE

#define SHARKSSL_CRACEN_ECKCDSA_INVALID_SIGNATURE   -2

Signature or public key rejected.

◆ SHARKSSL_CRACEN_ECKCDSA_OK

#define SHARKSSL_CRACEN_ECKCDSA_OK   0

Operation succeeded (0).

◆ SHARKSSL_CRACEN_ECKCDSA_P256_BYTES

#define SHARKSSL_CRACEN_ECKCDSA_P256_BYTES   32

P-256 scalar and coordinate size in bytes.

◆ SHARKSSL_CRACEN_ECKCDSA_RETRY_NONCE

#define SHARKSSL_CRACEN_ECKCDSA_RETRY_NONCE   -5

Retry signing with a fresh nonce.

◆ SHARKSSL_CRACEN_ECKCDSA_UNAVAILABLE

#define SHARKSSL_CRACEN_ECKCDSA_UNAVAILABLE   -3

Required hardware or capability unavailable.

◆ SHARKSSL_CRACEN_FF_BAD_ARGUMENT

#define SHARKSSL_CRACEN_FF_BAD_ARGUMENT   -1

Invalid argument or unsupported input size.

◆ SHARKSSL_CRACEN_FF_HARDWARE_ERROR

#define SHARKSSL_CRACEN_FF_HARDWARE_ERROR   -3

Hardware operation failed.

◆ SHARKSSL_CRACEN_FF_OK

#define SHARKSSL_CRACEN_FF_OK   0

Operation succeeded (0).

◆ SHARKSSL_CRACEN_FF_UNAVAILABLE

#define SHARKSSL_CRACEN_FF_UNAVAILABLE   -2

Required hardware or capability unavailable.

◆ SHARKSSL_CRACEN_SHAKE256_BAD_ARGUMENT

#define SHARKSSL_CRACEN_SHAKE256_BAD_ARGUMENT   -1

Invalid argument or unsupported input size.

◆ SHARKSSL_CRACEN_SHAKE256_HARDWARE_ERROR

#define SHARKSSL_CRACEN_SHAKE256_HARDWARE_ERROR   -3

Hardware operation failed.

◆ SHARKSSL_CRACEN_SHAKE256_MAX_OUTPUT

#define SHARKSSL_CRACEN_SHAKE256_MAX_OUTPUT   512

Maximum SHAKE256 output length in bytes.

◆ SHARKSSL_CRACEN_SHAKE256_OK

#define SHARKSSL_CRACEN_SHAKE256_OK   0

Operation succeeded (0).

◆ SHARKSSL_CRACEN_SHAKE256_UNAVAILABLE

#define SHARKSSL_CRACEN_SHAKE256_UNAVAILABLE   -2

Required hardware or capability unavailable.

◆ SHARKSSL_CRACEN_SM4_BAD_ARGUMENT

#define SHARKSSL_CRACEN_SM4_BAD_ARGUMENT   -1

Invalid argument or unsupported input size.

◆ SHARKSSL_CRACEN_SM4_BLOCK_LEN

#define SHARKSSL_CRACEN_SM4_BLOCK_LEN   16

SM4 block size in bytes.

◆ SHARKSSL_CRACEN_SM4_HARDWARE_ERROR

#define SHARKSSL_CRACEN_SM4_HARDWARE_ERROR   -3

Hardware operation failed.

◆ SHARKSSL_CRACEN_SM4_KEY_LEN

#define SHARKSSL_CRACEN_SM4_KEY_LEN   16

SM4 key size in bytes.

◆ SHARKSSL_CRACEN_SM4_MODE_CBC

#define SHARKSSL_CRACEN_SM4_MODE_CBC   1

Cipher block chaining mode, without padding.

◆ SHARKSSL_CRACEN_SM4_MODE_CTR

#define SHARKSSL_CRACEN_SM4_MODE_CTR   2

Counter mode, including partial final blocks.

◆ SHARKSSL_CRACEN_SM4_MODE_ECB

#define SHARKSSL_CRACEN_SM4_MODE_ECB   0

Electronic codebook mode, without padding.

◆ SHARKSSL_CRACEN_SM4_OK

#define SHARKSSL_CRACEN_SM4_OK   0

Operation succeeded (0).

◆ SHARKSSL_CRACEN_SM4_UNAVAILABLE

#define SHARKSSL_CRACEN_SM4_UNAVAILABLE   -2

Required hardware or capability unavailable.

Typedef Documentation

◆ SharkSslCRACENFF

Nordic CRACEN finite-field context.

The caller owns prime for the lifetime of the context. The caller must initialize PSA Crypto before init. The prime must be a trusted, validated odd prime; init checks only its encoding and hardware size, not primality.

Function Documentation

◆ sharkssl_CRACENDSA_signDigest2048_256()

int sharkssl_CRACENDSA_signDigest2048_256 ( const uint8_t *  p,
const uint8_t *  q,
const uint8_t *  g,
const uint8_t *  privateX,
const uint8_t *  nonceK,
const uint8_t *  hash,
uint8_t *  r,
uint8_t *  s 
)

Sign a SHA-256 digest using trusted DSA 2048/256 domain parameters.

Initialize PSA Crypto first. The caller must validate the domain's primality and order and supply a fresh secret nonce for every signature. All buffers are caller-owned, must not overlap, and hold unsigned big-endian values.

Parameters
pRequired 256-byte domain prime.
qRequired 32-byte subgroup order.
gRequired 256-byte domain generator.
privateXRequired 32-byte private scalar, from 1 through q-1.
nonceKRequired fresh secret 32-byte nonce, from 1 through q-1.
hashRequired 32-byte SHA-256 message digest.
rRequired 32-byte output for the first signature component.
sRequired 32-byte output for the second signature component.
Return values
SHARKSSL_CRACEN_DSA_OKSignature written.
SHARKSSL_CRACEN_DSA_BAD_ARGUMENTNULL pointer or invalid scalar.
SHARKSSL_CRACEN_DSA_UNAVAILABLERequired CRACEN capability unavailable.
SHARKSSL_CRACEN_DSA_HARDWARE_ERRORCRACEN operation failed; r and s cleared.
SHARKSSL_CRACEN_DSA_RETRY_NONCEOutputs cleared; retry with a new nonce.

◆ sharkssl_CRACENDSA_verifyDigest2048_256()

int sharkssl_CRACENDSA_verifyDigest2048_256 ( const uint8_t *  p,
const uint8_t *  q,
const uint8_t *  g,
const uint8_t *  publicY,
const uint8_t *  r,
const uint8_t *  s,
const uint8_t *  hash 
)

Verify a prehashed DSA 2048/256 signature.

Initialize PSA Crypto first. The caller supplies trusted domain parameters; this function checks the public key's range and subgroup membership. All inputs are required caller-owned, nonoverlapping big-endian buffers, retained only for this call.

Parameters
p256-byte domain prime.
q32-byte subgroup order.
g256-byte domain generator.
publicY256-byte public key.
r32-byte first signature component, from 1 through q-1.
s32-byte second signature component, from 1 through q-1.
hash32-byte SHA-256 message digest.
Return values
SHARKSSL_CRACEN_DSA_OKSignature verified.
SHARKSSL_CRACEN_DSA_BAD_ARGUMENTInvalid pointer or domain encoding.
SHARKSSL_CRACEN_DSA_INVALID_SIGNATUREInvalid signature or public key.
SHARKSSL_CRACEN_DSA_UNAVAILABLERequired CRACEN capability unavailable.
SHARKSSL_CRACEN_DSA_HARDWARE_ERRORCRACEN operation failed.

◆ sharkssl_CRACENECKCDSA_publicKeyP256()

int sharkssl_CRACENECKCDSA_publicKeyP256 ( const uint8_t *  privateScalar,
uint8_t *  publicX,
uint8_t *  publicY 
)

Generate Q = inverse(d) * G for EC-KCDSA on NIST P-256.

Initialize PSA Crypto first. All buffers are caller-owned, must not overlap, and contain unsigned 32-byte big-endian integers. Valid output buffers are cleared on hardware failure.

Parameters
privateScalarRequired private scalar d in the range 1 through n-1, where n is the P-256 group order.
publicXRequired 32-byte output for Q.x.
publicYRequired 32-byte output for Q.y.
Return values
SHARKSSL_CRACEN_ECKCDSA_OKPublic key written.
SHARKSSL_CRACEN_ECKCDSA_BAD_ARGUMENTNULL pointer or invalid scalar.
SHARKSSL_CRACEN_ECKCDSA_UNAVAILABLERequired CRACEN capability unavailable.
SHARKSSL_CRACEN_ECKCDSA_HARDWARE_ERRORCRACEN operation failed.

◆ sharkssl_CRACENECKCDSA_signPartP256()

int sharkssl_CRACENECKCDSA_signPartP256 ( const uint8_t *  privateScalar,
const uint8_t *  nonce,
const uint8_t *  r,
const uint8_t *  h,
uint8_t *  s 
)

Compute the EC-KCDSA component s = d * (k - ((r xor h) mod n)) mod n.

Initialize PSA Crypto first. The caller must generate a fresh secret nonce k for each signature and calculate r = SHA-256((k * G).x) and h = SHA-256(z || message). This is not a complete signer. All buffers are caller-owned, must not overlap, and contain 32-byte big-endian values.

Parameters
privateScalarRequired private scalar d, from 1 through n-1.
nonceRequired fresh secret nonce k, from 1 through n-1.
rRequired SHA-256 digest of the nonce point's x coordinate.
hRequired precomputed EC-KCDSA message digest.
sRequired 32-byte output for the second signature component; cleared on hardware failure or a retry result.
Return values
SHARKSSL_CRACEN_ECKCDSA_OKComponent s written.
SHARKSSL_CRACEN_ECKCDSA_BAD_ARGUMENTNULL pointer or invalid scalar.
SHARKSSL_CRACEN_ECKCDSA_UNAVAILABLERequired CRACEN capability unavailable.
SHARKSSL_CRACEN_ECKCDSA_HARDWARE_ERRORCRACEN operation failed.
SHARKSSL_CRACEN_ECKCDSA_RETRY_NONCEGenerate a new nonce and matching r.

◆ sharkssl_CRACENECKCDSA_verifyDigestP256()

int sharkssl_CRACENECKCDSA_verifyDigestP256 ( const uint8_t *  publicX,
const uint8_t *  publicY,
const uint8_t *  r,
const uint8_t *  s,
const uint8_t *  h 
)

Verify a prehashed EC-KCDSA signature on NIST P-256.

Compute W = ((r xor h) mod n) * G + s * Q and check SHA-256(W.x) == r. Initialize PSA Crypto first. All inputs are required caller-owned, nonoverlapping 32-byte big-endian buffers, retained only for this call.

Parameters
publicXPublic key Q.x.
publicYPublic key Q.y.
rFirst signature component.
sSecond signature component, from 1 through n-1.
hPrecomputed digest SHA-256(z || message).
Return values
SHARKSSL_CRACEN_ECKCDSA_OKSignature verified.
SHARKSSL_CRACEN_ECKCDSA_BAD_ARGUMENTNULL input pointer.
SHARKSSL_CRACEN_ECKCDSA_INVALID_SIGNATUREInvalid signature or public point.
SHARKSSL_CRACEN_ECKCDSA_UNAVAILABLERequired CRACEN capability unavailable.
SHARKSSL_CRACEN_ECKCDSA_HARDWARE_ERRORCRACEN or digest operation failed.

◆ sharkssl_CRACENSHAKE256_digest()

int sharkssl_CRACENSHAKE256_digest ( const uint8_t *  input,
uint8_t *  output,
size_t  inputLen,
size_t  outputLen 
)

Compute a one-shot SHAKE256 digest using Nordic CRACEN.

Initialize PSA Crypto first. Buffers are caller-owned and must not overlap. This interface does not provide streaming XOF output or SHAKE128.

Parameters
inputInput buffer, readable for inputLen bytes; NULL only if inputLen is 0.
outputRequired output buffer, writable for outputLen bytes. Cleared if hardware reservation or processing fails after argument validation.
inputLenInput length in bytes, limited by the CRACEN hash driver.
outputLenRequested digest length in bytes, from 1 through SHARKSSL_CRACEN_SHAKE256_MAX_OUTPUT (512).
Return values
SHARKSSL_CRACEN_SHAKE256_OKDigest written.
SHARKSSL_CRACEN_SHAKE256_BAD_ARGUMENTInvalid pointer/length or driver size limit.
SHARKSSL_CRACEN_SHAKE256_UNAVAILABLEHardware reservation failed.
SHARKSSL_CRACEN_SHAKE256_HARDWARE_ERRORHash operation failed.

◆ sharkssl_CRACENSM4_crypt()

int sharkssl_CRACENSM4_crypt ( unsigned int  mode,
unsigned int  decrypt,
const uint8_t *  key,
const uint8_t *  iv,
const uint8_t *  input,
size_t  inputLen,
uint8_t *  output,
size_t  outputSize 
)

Encrypt or decrypt using SM4-128 on Nordic CRACEN.

Initialize PSA Crypto first. Buffers are caller-owned. The output must not overlap the input, key or IV. CBC/ECB process complete blocks without padding; CTR accepts a partial final block. This operation does not authenticate data.

Parameters
modeSHARKSSL_CRACEN_SM4_MODE_ECB, SHARKSSL_CRACEN_SM4_MODE_CBC or SHARKSSL_CRACEN_SM4_MODE_CTR.
decrypt0 to encrypt or 1 to decrypt.
keyRequired 16-byte key, retained only for this call.
ivNULL for ECB; required 16-byte initialization vector/counter for CBC/CTR. The buffer is not updated and must be chosen for each operation.
inputRequired input buffer, readable for inputLen bytes.
inputLenNonzero length in bytes; a multiple of 16 for ECB/CBC. The length rounded up to a block must fit the CRACEN DMA size limit.
outputRequired output buffer. The first inputLen bytes are cleared if hardware reservation or processing fails after argument validation.
outputSizeOutput capacity in bytes, at least inputLen.
Return values
SHARKSSL_CRACEN_SM4_OKOutput written.
SHARKSSL_CRACEN_SM4_BAD_ARGUMENTInvalid mode, direction, pointer, length or buffer overlap.
SHARKSSL_CRACEN_SM4_UNAVAILABLEHardware reservation failed or SM4 absent.
SHARKSSL_CRACEN_SM4_HARDWARE_ERRORCipher operation failed.

◆ SharkSslCRACENFF_init()

int SharkSslCRACENFF_init ( SharkSslCRACENFF *  o,
const uint8_t *  prime,
uint16_t  primeLen 
)

Initialize a caller-owned finite-field context after PSA Crypto initialization.

The prime must be trusted and validated by the caller. This function checks its encoding and hardware size, not primality. No allocation is performed. On failure, a non-NULL context is reset to an uninitialized state.

Parameters
oRequired context to initialize.
primeRequired unsigned big-endian odd prime with no leading zero. Keep this buffer unchanged and alive while the context is used.
primeLenPrime length in bytes, at least 2 and no larger than the CRACEN finite-field operand limit.
Return values
SHARKSSL_CRACEN_FF_OKContext initialized.
SHARKSSL_CRACEN_FF_BAD_ARGUMENTNULL pointer or invalid prime encoding.
SHARKSSL_CRACEN_FF_UNAVAILABLEHardware capability or size unavailable.

◆ SharkSslCRACENFF_modExp()

int SharkSslCRACENFF_modExp ( const SharkSslCRACENFF *  o,
const uint8_t *  base,
const uint8_t *  exponent,
uint8_t *  result,
uint16_t  baseLen,
uint16_t  exponentLen,
uint16_t  resultLen 
)

Calculate base^exponent modulo the context's prime.

Initialize PSA Crypto and the context first. All integers are unsigned and big-endian. Input and output buffers must not overlap. This primitive does not validate a DH group or peer public value; the caller must do so.

Parameters
oRequired initialized context; its prime buffer remains caller-owned.
baseRequired base buffer, readable for baseLen bytes.
exponentRequired exponent buffer, readable for exponentLen bytes.
resultRequired caller-owned output; receives exactly o->primeLen bytes on success. Those bytes are cleared on hardware failure.
baseLenBase length in bytes, from 1 through o->primeLen.
exponentLenExponent length in bytes, from 1 through o->primeLen.
resultLenOutput capacity in bytes, at least o->primeLen.
Return values
SHARKSSL_CRACEN_FF_OKResult written.
SHARKSSL_CRACEN_FF_BAD_ARGUMENTInvalid context, pointer or length.
SHARKSSL_CRACEN_FF_HARDWARE_ERRORCRACEN operation failed.