libcmutils 0.6.5
Multi-platform C99 utility library
Loading...
Searching...
No Matches
Block ciphers, RSA, Base64 and secure random.

Data Structures

struct  CMUTIL_BlockCrypto
 Block cipher encryption/decryption object. More...
 
struct  CMUTIL_RSAKey
 RSA key object (can be either a private or public key). More...
 
struct  CMUTIL_RSACrypto
 RSA encryption/decryption and signature object. More...
 

Typedefs

typedef CMUTIL_RSAKey CMUTIL_PrivateKey
 An RSA key that can decrypt and sign.
 
typedef CMUTIL_RSAKey CMUTIL_PublicKey
 An RSA key that can encrypt and verify.
 

Functions

CMUTIL_BlockCryptoCMUTIL_BlockCryptoCreate (const char *algo, const char *mode, const char *padding, int key_bits)
 Creates a new block crypto object.
 
CMUTIL_PrivateKeyCMUTIL_PrivateKeyCreateFromPEM (const char *pem, const uint8_t *passphrase)
 Creates a private key object from a PEM-formatted string.
 
CMUTIL_PublicKeyCMUTIL_PublicKeyCreateFromPEM (const char *pem)
 Creates a public key object from a PEM-formatted string.
 
CMUTIL_PrivateKeyCMUTIL_PrivateKeyCreateFromFile (const char *file_path, const uint8_t *passphrase)
 Creates a private key object from a PEM-formatted file.
 
CMUTIL_PublicKeyCMUTIL_PublicKeyCreateFromFile (const char *file_path)
 Creates a public key object from a PEM-formatted file.
 
CMUTIL_RSACryptoCMUTIL_RSACryptoCreate (void)
 Creates a new RSA crypto object.
 
void CMUTIL_CryptoRandom (uint8_t *buf, size_t len)
 Generates cryptographically strong random bytes.
 

Detailed Description

Typedef Documentation

◆ CMUTIL_PrivateKey

An RSA key that can decrypt and sign.

The same object as CMUTIL_RSAKey; the two names exist to say which half of a key pair a function expects.

◆ CMUTIL_PublicKey

An RSA key that can encrypt and verify.

The same object as CMUTIL_RSAKey; the two names exist to say which half of a key pair a function expects.

Function Documentation

◆ CMUTIL_BlockCryptoCreate()

CMUTIL_BlockCrypto * CMUTIL_BlockCryptoCreate ( const char *  algo,
const char *  mode,
const char *  padding,
int  key_bits 
)

Creates a new block crypto object.

Parameters
algoThe encryption algorithm (e.g., "AES").
modeThe encryption mode (e.g., "CBC").
paddingThe padding scheme (e.g., "PKCS5Padding").
key_bitsThe key size in bits.
Returns
A pointer to the newly created block crypto object, or NULL on failure.

◆ CMUTIL_PrivateKeyCreateFromPEM()

CMUTIL_PrivateKey * CMUTIL_PrivateKeyCreateFromPEM ( const char *  pem,
const uint8_t *  passphrase 
)

Creates a private key object from a PEM-formatted string.

Parameters
pemThe PEM-formatted private key string.
passphraseThe passphrase for the private key, or NULL if none.
Returns
A pointer to the newly created private key object, or NULL on failure.

◆ CMUTIL_PublicKeyCreateFromPEM()

CMUTIL_PublicKey * CMUTIL_PublicKeyCreateFromPEM ( const char *  pem)

Creates a public key object from a PEM-formatted string.

Parameters
pemThe PEM-formatted public key string.
Returns
A pointer to the newly created public key object, or NULL on failure.

◆ CMUTIL_PrivateKeyCreateFromFile()

CMUTIL_PrivateKey * CMUTIL_PrivateKeyCreateFromFile ( const char *  file_path,
const uint8_t *  passphrase 
)

Creates a private key object from a PEM-formatted file.

Parameters
file_pathThe path to the PEM-formatted private key file.
passphraseThe passphrase for the private key, or NULL if none.
Returns
A pointer to the newly created private key object, or NULL on failure.

◆ CMUTIL_PublicKeyCreateFromFile()

CMUTIL_PublicKey * CMUTIL_PublicKeyCreateFromFile ( const char *  file_path)

Creates a public key object from a PEM-formatted file.

Parameters
file_pathThe path to the PEM-formatted public key file.
Returns
A pointer to the newly created public key object, or NULL on failure.

◆ CMUTIL_RSACryptoCreate()

CMUTIL_RSACrypto * CMUTIL_RSACryptoCreate ( void  )

Creates a new RSA crypto object.

Returns
A pointer to the newly created RSA crypto object, or NULL on failure.

◆ CMUTIL_CryptoRandom()

void CMUTIL_CryptoRandom ( uint8_t *  buf,
size_t  len 
)

Generates cryptographically strong random bytes.

Parameters
bufThe buffer to store the random bytes.
lenThe number of bytes to generate.