SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
SharkSslCrypto.h File Reference
#include "SharkSSL.h"

Go to the source code of this file.

Data Structures

struct  SharkSslMd5Ctx
 MD5. More...
 
struct  SharkSslSha1Ctx
 SHA1. More...
 
struct  SharkSslSha224Ctx
 PSA SHA-224 operation storage. More...
 
struct  SharkSslSha256Ctx
 SHA256. More...
 
struct  SharkSslSha384Ctx
 In PSA consumer builds, hash contexts own provider operations. More...
 
struct  SharkSslHMACCtx
 HMAC. More...
 
struct  SharkSslPoly1305Ctx
 POLY1305. More...
 
struct  SharkSslChaChaCtx
 CHACHA20. More...
 
struct  SharkSslAesCtx
 AES. More...
 
struct  SharkSslAesGcmCtx
 AesGcmCtx. More...
 
struct  SharkSslAesCcmCtx
 AesCcmCtx. More...
 

Macros

#define SHARKSSL_LIB   1
 
#define SHARKSSL_MD5_HASH_LEN   16
 
#define SHARKSSL_SHA1_HASH_LEN   20
 
#define SHARKSSL_SHA224_HASH_LEN   28
 
#define SHARKSSL_SHA256_HASH_LEN   32
 
#define SHARKSSL_SHA384_HASH_LEN   48
 
#define SHARKSSL_SHA512_HASH_LEN   64
 
#define SHARKSSL_POLY1305_HASH_LEN   16
 
#define SHARKSSL_MD5_BLOCK_LEN   64
 
#define SHARKSSL_SHA1_BLOCK_LEN   64
 
#define SHARKSSL_SHA256_BLOCK_LEN   64
 
#define SHARKSSL_SHA384_BLOCK_LEN   128
 
#define SHARKSSL_SHA512_BLOCK_LEN   128
 
#define SHARKSSL_EDDSA_PREHASH_LEN   64
 
#define SHARKSSL_HASHID_MD5   0x01
 to be used as 'hashID' parameter in SharkSslHMACCtx_constructor More...
 
#define SHARKSSL_HASHID_SHA1   0x02
 
#define SHARKSSL_HASHID_SHA224   0x03
 
#define SHARKSSL_HASHID_SHA256   0x04
 
#define SHARKSSL_HASHID_SHA384   0x05
 
#define SHARKSSL_HASHID_SHA512   0x06
 
#define SharkSslPoly1305Ctx_destructor(o)   sharkssl_clear(o, sizeof(SharkSslPoly1305Ctx))
 
#define SHARKSSL_CHACHA_API_STATUS   int
 
#define SHARKSSL_AES_API_STATUS   int
 
#define SharkSslAesCtx_destructor(ctx)   sharkssl_clear(ctx, sizeof(SharkSslAesCtx))
 
#define SharkSslAesGcmCtx_destructor(ctx)   sharkssl_clear(ctx, sizeof(SharkSslAesGcmCtx))
 
#define SharkSslAesCcmCtx_destructor(ctx)   sharkssl_clear(ctx, sizeof(SharkSslAesCcmCtx))
 

Typedefs

typedef struct SharkSslMd5Ctx SharkSslMd5Ctx
 MD5. More...
 
typedef struct SharkSslSha1Ctx SharkSslSha1Ctx
 SHA1. More...
 
typedef struct SharkSslSha224Ctx SharkSslSha224Ctx
 
typedef struct SharkSslSha256Ctx SharkSslSha256Ctx
 SHA256. More...
 
typedef struct SharkSslSha384Ctx SharkSslSha384Ctx
 In PSA consumer builds, hash contexts own provider operations. More...
 
typedef struct SharkSslSha384Ctx SharkSslSha512Ctx
 SHA512. More...
 
typedef struct SharkSslHMACCtx SharkSslHMACCtx
 HMAC. More...
 
typedef struct SharkSslPoly1305Ctx SharkSslPoly1305Ctx
 POLY1305. More...
 
typedef struct SharkSslAesCtx SharkSslAesCtx
 AES. More...
 
typedef struct SharkSslAesGcmCtx SharkSslAesGcmCtx
 AesGcmCtx. More...
 
typedef struct SharkSslAesCcmCtx SharkSslAesCcmCtx
 AesCcmCtx. More...
 

Enumerations

enum  SharkSslAesCtx_Type { SharkSslAesCtx_Decrypt , SharkSslAesCtx_Encrypt }
 

Functions

SHARKSSL_API int sharkssl_entropy (U32)
 Mix 32 application-supplied bits into the default RNG state. More...
 
SHARKSSL_API int sharkssl_rng (U8 *, U16)
 
SHARKSSL_API int sharkssl_kmemcmp (const void *a, const void *b, U32 n)
 
SHARKSSL_API void SharkSslMd5Ctx_constructor (SharkSslMd5Ctx *ctx)
 Initialize. More...
 
SHARKSSL_API void SharkSslMd5Ctx_append (SharkSslMd5Ctx *ctx, const U8 *data, U32 len)
 append More...
 
SHARKSSL_API void SharkSslMd5Ctx_finish (SharkSslMd5Ctx *ctx, U8 digest[SHARKSSL_MD5_HASH_LEN])
 finish More...
 
SHARKSSL_API int sharkssl_md5 (const U8 *, U32, U8 *)
 md5 More...
 
SHARKSSL_API int SharkSslSha1Ctx_constructor (SharkSslSha1Ctx *ctx)
 Initialize. More...
 
SHARKSSL_API int SharkSslSha1Ctx_append (SharkSslSha1Ctx *ctx, const U8 *data, U32 len)
 append More...
 
SHARKSSL_API int SharkSslSha1Ctx_finish (SharkSslSha1Ctx *ctx, U8 digest[SHARKSSL_SHA1_HASH_LEN])
 finish More...
 
SHARKSSL_API int SharkSslSha1Ctx_clone (const SharkSslSha1Ctx *source, SharkSslSha1Ctx *target)
 
SHARKSSL_API int SharkSslSha1Ctx_abort (SharkSslSha1Ctx *ctx)
 
SHARKSSL_API int sharkssl_sha1 (const U8 *, U32, U8 *)
 sha1 More...
 
SHARKSSL_API int SharkSslSha224Ctx_constructor (SharkSslSha224Ctx *ctx)
 
SHARKSSL_API int SharkSslSha224Ctx_append (SharkSslSha224Ctx *ctx, const U8 *data, U32 len)
 
SHARKSSL_API int SharkSslSha224Ctx_finish (SharkSslSha224Ctx *ctx, U8 digest[SHARKSSL_SHA224_HASH_LEN])
 
SHARKSSL_API int SharkSslSha224Ctx_clone (const SharkSslSha224Ctx *source, SharkSslSha224Ctx *target)
 
SHARKSSL_API int SharkSslSha224Ctx_abort (SharkSslSha224Ctx *ctx)
 
SHARKSSL_API int sharkssl_sha224 (const U8 *data, U32 len, U8 *digest)
 
SHARKSSL_API int SharkSslSha256Ctx_constructor (SharkSslSha256Ctx *ctx)
 Initialize. More...
 
SHARKSSL_API int SharkSslSha256Ctx_append (SharkSslSha256Ctx *, const U8 *data, U32 len)
 append More...
 
SHARKSSL_API int SharkSslSha256Ctx_finish (SharkSslSha256Ctx *, U8 digest[SHARKSSL_SHA256_HASH_LEN])
 finish More...
 
SHARKSSL_API int SharkSslSha256Ctx_clone (const SharkSslSha256Ctx *source, SharkSslSha256Ctx *target)
 
SHARKSSL_API int SharkSslSha256Ctx_abort (SharkSslSha256Ctx *ctx)
 
SHARKSSL_API int sharkssl_sha256 (const U8 *, U32, U8 *)
 sha256 More...
 
SHARKSSL_API int SharkSslSha384Ctx_constructor (SharkSslSha384Ctx *ctx)
 Initialize. More...
 
SHARKSSL_API int SharkSslSha384Ctx_append (SharkSslSha384Ctx *, const U8 *data, U32 len)
 append More...
 
SHARKSSL_API int SharkSslSha384Ctx_finish (SharkSslSha384Ctx *, U8 digest[SHARKSSL_SHA384_HASH_LEN])
 finish More...
 
SHARKSSL_API int SharkSslSha384Ctx_clone (const SharkSslSha384Ctx *source, SharkSslSha384Ctx *target)
 
SHARKSSL_API int SharkSslSha384Ctx_abort (SharkSslSha384Ctx *ctx)
 
SHARKSSL_API int sharkssl_sha384 (const U8 *, U32, U8 *)
 sha384 More...
 
SHARKSSL_API int SharkSslSha512Ctx_constructor (SharkSslSha512Ctx *ctx)
 Initialize. More...
 
SHARKSSL_API int SharkSslSha512Ctx_append (SharkSslSha512Ctx *ctx, const U8 *data, U32 len)
 append More...
 
SHARKSSL_API int SharkSslSha512Ctx_finish (SharkSslSha512Ctx *ctx, U8 digest[SHARKSSL_SHA512_HASH_LEN])
 finish More...
 
SHARKSSL_API int SharkSslSha512Ctx_clone (const SharkSslSha512Ctx *source, SharkSslSha512Ctx *target)
 
SHARKSSL_API int SharkSslSha512Ctx_abort (SharkSslSha512Ctx *ctx)
 
SHARKSSL_API int sharkssl_sha512 (const U8 *, U32, U8 *)
 sha512 More...
 
SHARKSSL_API int SharkSslHMACCtx_constructor (SharkSslHMACCtx *ctx, U8 hashID, const U8 *key, U16 keyLen)
 Initialize. More...
 
SHARKSSL_API int SharkSslHMACCtx_append (SharkSslHMACCtx *, const U8 *data, U32 len)
 append More...
 
SHARKSSL_API int SharkSslHMACCtx_finish (SharkSslHMACCtx *, U8 *HMAC)
 finish More...
 
SHARKSSL_API int SharkSslHMACCtx_destructor (SharkSslHMACCtx *ctx)
 
SHARKSSL_API int sharkssl_HMAC (const U8 hashID, const U8 *data, U32 len, const U8 *key, U16 keyLen, U8 *digest)
 HMAC. More...
 
void sharkssl_clear (void *data, U32 len)
 
U16 sharkssl_getHashLen (U8 hashID)
 
int sharkssl_hash (U8 *digest, U8 *data, U32 len, U8 hashID)
 
SHARKSSL_API void SharkSslPoly1305Ctx_constructor (SharkSslPoly1305Ctx *ctx, const U8 key[32])
 Initialize. More...
 
SHARKSSL_API void SharkSslPoly1305Ctx_append (SharkSslPoly1305Ctx *ctx, const U8 *in, U32 len)
 append More...
 
SHARKSSL_API void SharkSslPoly1305Ctx_finish (SharkSslPoly1305Ctx *ctx, U8 digest[SHARKSSL_POLY1305_HASH_LEN])
 finish More...
 
SHARKSSL_API int sharkssl_poly1305 (const U8 *data, U32 len, U8 *digest, const U8 key[32])
 poly1305 More...
 
SHARKSSL_API SHARKSSL_CHACHA_API_STATUS SharkSslChaChaCtx_constructor (SharkSslChaChaCtx *ctx, const U8 *key, U8 keyLen)
 Initialize. More...
 
SHARKSSL_API int SharkSslChaChaCtx_destructor (SharkSslChaChaCtx *ctx)
 
SHARKSSL_API SHARKSSL_CHACHA_API_STATUS SharkSslChaChaCtx_setIV (SharkSslChaChaCtx *ctx, const U8 IV[12])
 Initialize. More...
 
SHARKSSL_API SHARKSSL_CHACHA_API_STATUS SharkSslChaChaCtx_crypt (SharkSslChaChaCtx *ctx, const U8 *input, U8 *output, U32 len)
 Encrypt or decrypt. More...
 
SHARKSSL_API int sharkssl_chacha20poly1305_encrypt (const U8 key[32], const U8 nonce[12], const U8 *aad, const U8 *input, U8 *output, U8 tag[16], U32 len, U16 aadLen)
 
SHARKSSL_API int sharkssl_chacha20poly1305_decrypt (const U8 key[32], const U8 nonce[12], const U8 *aad, const U8 *input, const U8 tag[16], U8 *output, U32 len, U16 aadLen)
 
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_constructor (SharkSslAesCtx *ctx, SharkSslAesCtx_Type type, const U8 *key, U8 keyLen)
 Initialize. More...
 
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_decrypt (SharkSslAesCtx *ctx, const U8 input[16], U8 output[16])
 Decrypt. More...
 
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_encrypt (SharkSslAesCtx *ctx, U8 input[16], U8 output[16])
 Encrypt. More...
 
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_cbc_encrypt (SharkSslAesCtx *ctx, U8 vect[16], const U8 *input, U8 *output, U32 len)
 Encrypt. More...
 
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_cbc_decrypt (SharkSslAesCtx *ctx, U8 vect[16], const U8 *input, U8 *output, U32 len)
 Decrypt. More...
 
SHARKSSL_API int SharkSslAesCtx_cbc_pkcs7_encrypt (SharkSslAesCtx *ctx, const U8 iv[16], const U8 *input, U8 *output, U32 *outputLen, U32 len, U32 outputCapacity)
 CBC with PKCS#7 padding. More...
 
SHARKSSL_API int SharkSslAesCtx_cbc_pkcs7_decrypt (SharkSslAesCtx *ctx, const U8 iv[16], const U8 *input, U8 *output, U32 *outputLen, U32 len, U32 outputCapacity)
 
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_ctr_mode (SharkSslAesCtx *ctx, U8 ctr[16], const U8 *input, U8 *output, U32 len)
 
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesGcmCtx_constructor (SharkSslAesGcmCtx *ctx, const U8 *key, U8 keyLen)
 Initialize. More...
 
SHARKSSL_API int SharkSslAesGcmCtx_encrypt (SharkSslAesGcmCtx *ctx, const U8 vect[12], U8 tagout[16], const U8 *auth, U16 authlen, const U8 *input, U8 *output, U32 len)
 Encrypt and authenticate one complete message. More...
 
SHARKSSL_API int SharkSslAesGcmCtx_decrypt (SharkSslAesGcmCtx *ctx, const U8 vect[12], U8 tagin[16], const U8 *auth, U16 authlen, U8 *input, U8 *output, U32 len)
 Decrypt and authenticate one complete message. More...
 
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCcmCtx_constructor (SharkSslAesCcmCtx *ctx, const U8 *key, U8 keyLen, U8 tagLen)
 Initialize. More...
 
SHARKSSL_API int SharkSslAesCcmCtx_encrypt (SharkSslAesCcmCtx *ctx, const U8 vect[12], U8 *tagout, const U8 *auth, U16 authlen, const U8 *input, U8 *output, U32 len)
 Encrypt. More...
 
SHARKSSL_API int SharkSslAesCcmCtx_decrypt (SharkSslAesCcmCtx *ctx, const U8 vect[12], U8 *tagin, const U8 *auth, U16 authlen, const U8 *input, U8 *output, U32 len)
 Decrypt. More...
 

Macro Definition Documentation

◆ SHARKSSL_AES_API_STATUS

#define SHARKSSL_AES_API_STATUS   int

◆ SHARKSSL_CHACHA_API_STATUS

#define SHARKSSL_CHACHA_API_STATUS   int

◆ SHARKSSL_EDDSA_PREHASH_LEN

#define SHARKSSL_EDDSA_PREHASH_LEN   64

◆ SHARKSSL_HASHID_MD5

#define SHARKSSL_HASHID_MD5   0x01

to be used as 'hashID' parameter in SharkSslHMACCtx_constructor

◆ SHARKSSL_HASHID_SHA1

#define SHARKSSL_HASHID_SHA1   0x02

◆ SHARKSSL_HASHID_SHA224

#define SHARKSSL_HASHID_SHA224   0x03

◆ SHARKSSL_HASHID_SHA256

#define SHARKSSL_HASHID_SHA256   0x04

◆ SHARKSSL_HASHID_SHA384

#define SHARKSSL_HASHID_SHA384   0x05

◆ SHARKSSL_HASHID_SHA512

#define SHARKSSL_HASHID_SHA512   0x06

◆ SHARKSSL_LIB

#define SHARKSSL_LIB   1

◆ SHARKSSL_MD5_BLOCK_LEN

#define SHARKSSL_MD5_BLOCK_LEN   64

◆ SHARKSSL_MD5_HASH_LEN

#define SHARKSSL_MD5_HASH_LEN   16

◆ SHARKSSL_POLY1305_HASH_LEN

#define SHARKSSL_POLY1305_HASH_LEN   16

◆ SHARKSSL_SHA1_BLOCK_LEN

#define SHARKSSL_SHA1_BLOCK_LEN   64

◆ SHARKSSL_SHA1_HASH_LEN

#define SHARKSSL_SHA1_HASH_LEN   20

◆ SHARKSSL_SHA224_HASH_LEN

#define SHARKSSL_SHA224_HASH_LEN   28

◆ SHARKSSL_SHA256_BLOCK_LEN

#define SHARKSSL_SHA256_BLOCK_LEN   64

◆ SHARKSSL_SHA256_HASH_LEN

#define SHARKSSL_SHA256_HASH_LEN   32

◆ SHARKSSL_SHA384_BLOCK_LEN

#define SHARKSSL_SHA384_BLOCK_LEN   128

◆ SHARKSSL_SHA384_HASH_LEN

#define SHARKSSL_SHA384_HASH_LEN   48

◆ SHARKSSL_SHA512_BLOCK_LEN

#define SHARKSSL_SHA512_BLOCK_LEN   128

◆ SHARKSSL_SHA512_HASH_LEN

#define SHARKSSL_SHA512_HASH_LEN   64

◆ SharkSslAesCcmCtx_destructor

#define SharkSslAesCcmCtx_destructor (   ctx)    sharkssl_clear(ctx, sizeof(SharkSslAesCcmCtx))

◆ SharkSslAesCtx_destructor

#define SharkSslAesCtx_destructor (   ctx)    sharkssl_clear(ctx, sizeof(SharkSslAesCtx))

◆ SharkSslAesGcmCtx_destructor

#define SharkSslAesGcmCtx_destructor (   ctx)    sharkssl_clear(ctx, sizeof(SharkSslAesGcmCtx))

◆ SharkSslPoly1305Ctx_destructor

#define SharkSslPoly1305Ctx_destructor (   o)    sharkssl_clear(o, sizeof(SharkSslPoly1305Ctx))

Typedef Documentation

◆ SharkSslSha224Ctx

Enumeration Type Documentation

◆ SharkSslAesCtx_Type

Enumerator
SharkSslAesCtx_Decrypt 
SharkSslAesCtx_Encrypt 

Function Documentation

◆ sharkssl_chacha20poly1305_decrypt()

SHARKSSL_API int sharkssl_chacha20poly1305_decrypt ( const U8  key[32],
const U8  nonce[12],
const U8 *  aad,
const U8 *  input,
const U8  tag[16],
U8 *  output,
U32  len,
U16  aadLen 
)

◆ sharkssl_chacha20poly1305_encrypt()

SHARKSSL_API int sharkssl_chacha20poly1305_encrypt ( const U8  key[32],
const U8  nonce[12],
const U8 *  aad,
const U8 *  input,
U8 *  output,
U8  tag[16],
U32  len,
U16  aadLen 
)

◆ sharkssl_clear()

void sharkssl_clear ( void *  data,
U32  len 
)

◆ sharkssl_entropy()

SHARKSSL_API int sharkssl_entropy ( U32  )

Mix 32 application-supplied bits into the default RNG state.

Before any cryptographic use, call this function with sufficient unpredictable input from a platform CSPRNG or hardware entropy source. Time values, addresses, or counters alone do not provide an RFC 9846-compliant entropy source.

◆ sharkssl_getHashLen()

U16 sharkssl_getHashLen ( U8  hashID)

◆ sharkssl_hash()

int sharkssl_hash ( U8 *  digest,
U8 *  data,
U32  len,
U8  hashID 
)

◆ sharkssl_kmemcmp()

SHARKSSL_API int sharkssl_kmemcmp ( const void *  a,
const void *  b,
U32  n 
)

◆ sharkssl_rng()

SHARKSSL_API int sharkssl_rng ( U8 *  ,
U16   
)

◆ sharkssl_sha224()

SHARKSSL_API int sharkssl_sha224 ( const U8 *  data,
U32  len,
U8 *  digest 
)

◆ SharkSslAesCtx_cbc_pkcs7_decrypt()

SHARKSSL_API int SharkSslAesCtx_cbc_pkcs7_decrypt ( SharkSslAesCtx *  ctx,
const U8  iv[16],
const U8 *  input,
U8 *  output,
U32 *  outputLen,
U32  len,
U32  outputCapacity 
)

◆ SharkSslAesCtx_cbc_pkcs7_encrypt()

SHARKSSL_API int SharkSslAesCtx_cbc_pkcs7_encrypt ( SharkSslAesCtx *  ctx,
const U8  iv[16],
const U8 *  input,
U8 *  output,
U32 *  outputLen,
U32  len,
U32  outputCapacity 
)

CBC with PKCS#7 padding.

On failure, output is cleared and outputLen is zero.

◆ SharkSslChaChaCtx_destructor()

SHARKSSL_API int SharkSslChaChaCtx_destructor ( SharkSslChaChaCtx *  ctx)

◆ SharkSslHMACCtx_destructor()

SHARKSSL_API int SharkSslHMACCtx_destructor ( SharkSslHMACCtx *  ctx)

◆ SharkSslSha1Ctx_abort()

SHARKSSL_API int SharkSslSha1Ctx_abort ( SharkSslSha1Ctx *  ctx)

◆ SharkSslSha1Ctx_clone()

SHARKSSL_API int SharkSslSha1Ctx_clone ( const SharkSslSha1Ctx *  source,
SharkSslSha1Ctx *  target 
)

◆ SharkSslSha224Ctx_abort()

SHARKSSL_API int SharkSslSha224Ctx_abort ( SharkSslSha224Ctx *  ctx)

◆ SharkSslSha224Ctx_append()

SHARKSSL_API int SharkSslSha224Ctx_append ( SharkSslSha224Ctx *  ctx,
const U8 *  data,
U32  len 
)

◆ SharkSslSha224Ctx_clone()

SHARKSSL_API int SharkSslSha224Ctx_clone ( const SharkSslSha224Ctx *  source,
SharkSslSha224Ctx *  target 
)

◆ SharkSslSha224Ctx_constructor()

SHARKSSL_API int SharkSslSha224Ctx_constructor ( SharkSslSha224Ctx *  ctx)

◆ SharkSslSha224Ctx_finish()

SHARKSSL_API int SharkSslSha224Ctx_finish ( SharkSslSha224Ctx *  ctx,
U8  digest[SHARKSSL_SHA224_HASH_LEN] 
)

◆ SharkSslSha256Ctx_abort()

SHARKSSL_API int SharkSslSha256Ctx_abort ( SharkSslSha256Ctx *  ctx)

◆ SharkSslSha256Ctx_clone()

SHARKSSL_API int SharkSslSha256Ctx_clone ( const SharkSslSha256Ctx *  source,
SharkSslSha256Ctx *  target 
)

◆ SharkSslSha384Ctx_abort()

SHARKSSL_API int SharkSslSha384Ctx_abort ( SharkSslSha384Ctx *  ctx)

◆ SharkSslSha384Ctx_clone()

SHARKSSL_API int SharkSslSha384Ctx_clone ( const SharkSslSha384Ctx *  source,
SharkSslSha384Ctx *  target 
)

◆ SharkSslSha512Ctx_abort()

SHARKSSL_API int SharkSslSha512Ctx_abort ( SharkSslSha512Ctx *  ctx)

◆ SharkSslSha512Ctx_clone()

SHARKSSL_API int SharkSslSha512Ctx_clone ( const SharkSslSha512Ctx *  source,
SharkSslSha512Ctx *  target 
)