SharkSSL™ Embedded SSL/TLS Stack
RayCrypto API

Detailed Description

Cryptographic functions, including RSA, ECC, AES, hashing, etc..

RayCrypto offers developers a rich selection of cryptographic technologies, methods including RSA and elliptic curve, symmetric algorithms like 3DES and AES, message authentication, hashing and pseudorandom number generation.

Modules

 MD5
 MD5 cryptographic hash.
 
 SHA1
 SHA1 cryptographic hash.
 
 SHA256
 SHA256 cryptographic hash.
 
 SHA384
 SHA384 cryptographic hash.
 
 SHA512
 SHA512 cryptographic hash.
 
 HMAC
 HMAC keyed-hash message authentication code (in conjunction with: MD5,SHA1,SHA256,SHA384,SHA512)
 
 ARC4
 ARC4.
 
 DES
 DES.
 
 AES
 AES.
 
 AES-GCM
 AES-GCM.
 
 AES-CCM
 AES-CCM.
 
 POLY1305
 POLY1305.
 
 CHACHA20
 CHACHA20.
 
 ECDSA sign/verify functions
 See Signing and Verifying Binaries for an example of how to use the ECDSA ECDSA sign/verify functions.
 
 RSA encrypt/decrypt functions
 

Enumerations

enum  sharkssl_PEM_RetVal {
  SHARKSSL_PEM_OK = 0 , SHARKSSL_PEM_OK_PUBLIC = 1 , SHARKSSL_PEM_ALLOCATION_ERROR = - 3000 , SHARKSSL_PEM_KEY_PARSE_ERROR ,
  SHARKSSL_PEM_KEY_WRONG_IV , SHARKSSL_PEM_KEY_WRONG_LENGTH , SHARKSSL_PEM_KEY_PASSPHRASE_REQUIRED , SHARKSSL_PEM_KEY_UNRECOGNIZED_FORMAT ,
  SHARKSSL_PEM_KEY_UNSUPPORTED_FORMAT , SHARKSSL_PEM_KEY_UNSUPPORTED_MODULUS_LENGTH , SHARKSSL_PEM_KEY_UNSUPPORTED_EXPONENT_LENGTH , SHARKSSL_PEM_KEY_UNSUPPORTED_ENCRYPTION_TYPE ,
  SHARKSSL_PEM_KEY_CERT_MISMATCH , SHARKSSL_PEM_CERT_UNRECOGNIZED_FORMAT , SHARKSSL_PEM_CERT_UNSUPPORTED_TYPE , SHARKSSL_PEM_KEY_UNSUPPORTED_VERSION ,
  SHARKSSL_PEM_KEY_REQUIRED , SHARKSSL_PEM_KEY_PRIVATE_KEY_REQUIRED , SHARKSSL_PEM_INTERNAL_ERROR
}
 Return values from function sharkssl_PEM. More...
 

Functions

SHARKSSL_API sharkssl_PEM_RetVal sharkssl_PEM (const char *certPEM, const char *keyPEM, const char *passphrase, SharkSslCert *sharkSslCert)
 Create a SharkSslCert certificate by using a certificate and key in PEM format. More...
 
SHARKSSL_API int sharkssl_PEM_PBKDF2 (U8 *dk, const char *passphrase, const char *salt, U32 saltLen, U32 iterations, U16 dkLen, U8 hashID)
 sharkssl_PEM_PBKDF2 (output, passphrase, salt, salt_len, iterations, dkLen, hashID) Derives a key from a passphrase using the PBKDF2 algorithm as specified in RFC 8018 section 5.2. More...
 

Enumeration Type Documentation

◆ sharkssl_PEM_RetVal

Return values from function sharkssl_PEM.

Enumerator
SHARKSSL_PEM_OK 

OK.

SHARKSSL_PEM_OK_PUBLIC 

OK_PUBLIC.

SHARKSSL_PEM_ALLOCATION_ERROR 

ALLOCATION_ERROR.

SHARKSSL_PEM_KEY_PARSE_ERROR 

KEY_PARSE_ERROR.

SHARKSSL_PEM_KEY_WRONG_IV 

KEY_WRONG_IV.

SHARKSSL_PEM_KEY_WRONG_LENGTH 

KEY_WRONG_LENGTH.

SHARKSSL_PEM_KEY_PASSPHRASE_REQUIRED 

KEY_PASSPHRASE_REQUIRED.

SHARKSSL_PEM_KEY_UNRECOGNIZED_FORMAT 

KEY_UNRECOGNIZED_FORMAT.

SHARKSSL_PEM_KEY_UNSUPPORTED_FORMAT 

KEY_UNSUPPORTED_FORMAT.

SHARKSSL_PEM_KEY_UNSUPPORTED_MODULUS_LENGTH 

KEY_UNSUPPORTED_MODULUS_LENGTH.

SHARKSSL_PEM_KEY_UNSUPPORTED_EXPONENT_LENGTH 

KEY_UNSUPPORTED_EXPONENT_LENGTH.

SHARKSSL_PEM_KEY_UNSUPPORTED_ENCRYPTION_TYPE 

KEY_UNSUPPORTED_ENCRYPTION_TYPE.

SHARKSSL_PEM_KEY_CERT_MISMATCH 

KEY_CERT_MISMATCH.

SHARKSSL_PEM_CERT_UNRECOGNIZED_FORMAT 

CERT_UNRECOGNIZED_FORMAT.

SHARKSSL_PEM_CERT_UNSUPPORTED_TYPE 

CERT_UNSUPPORTED_TYPE.

SHARKSSL_PEM_KEY_UNSUPPORTED_VERSION 

KEY_UNSUPPORTED_VERSION.

SHARKSSL_PEM_KEY_REQUIRED 

KEY_REQUIRED.

SHARKSSL_PEM_KEY_PRIVATE_KEY_REQUIRED 

A PRIVATE KEY IS REQUIRED.

SHARKSSL_PEM_INTERNAL_ERROR 

INTERNAL ERROR.

Function Documentation

◆ sharkssl_PEM()

SHARKSSL_API sharkssl_PEM_RetVal sharkssl_PEM ( const char *  certPEM,
const char *  keyPEM,
const char *  passphrase,
SharkSslCert sharkSslCert 
)

Create a SharkSslCert certificate by using a certificate and key in PEM format.

example:

int addMyCert(SharkSsl* shark)
{
SharkSslCert *sharkCert;
// The two following functions illustrate how a certificate and
// key can be read from a file system and inserted into an
// allocated buffer.
char* cert=readMyCertFromFileSystem();
char* key=readMyKeyFromFileSystem();
if(sharkssl_PEM(cert,key,NULL,&sharkCert))
return -1;
free(cert);
free(key);
// You may redesign the code and keep a reference to the
// SharkSslCert object if you design a system using dynamic objects
// i.e. if you later plan on releasing the SharkSSL object and
// the SharkSslCert object. You cannot release the SharkSslCert
// object before releasing the SharkSSL object.
SharkSsl_addCertificate(shark,sharkCert);
return 0;
}
SHARKSSL_API sharkssl_PEM_RetVal sharkssl_PEM(const char *certPEM, const char *keyPEM, const char *passphrase, SharkSslCert *sharkSslCert)
Create a SharkSslCert certificate by using a certificate and key in PEM format.
SHARKSSL_API U8 SharkSsl_addCertificate(SharkSsl *o, SharkSslCert cert)
Add a certificate to the SharkSsl object.
const U8 * SharkSslCert
The SharkSSL Certificate is in a binary format optimized for speed and size.
Definition: SharkSSL.h:317
A SharkSsl object is the coordinator for managing SharkSslCon objects (See SharkSsl_constructor for d...
Definition: SharkSSL.h:561

◆ sharkssl_PEM_PBKDF2()

SHARKSSL_API int sharkssl_PEM_PBKDF2 ( U8 *  dk,
const char *  passphrase,
const char *  salt,
U32  saltLen,
U32  iterations,
U16  dkLen,
U8  hashID 
)

sharkssl_PEM_PBKDF2 (output, passphrase, salt, salt_len, iterations, dkLen, hashID) Derives a key from a passphrase using the PBKDF2 algorithm as specified in RFC 8018 section 5.2.

This function performs the Password-Based Key Derivation Function 2 (PBKDF2) to derive a key from a given passphrase. The derived key is computed by iterating the specified hash function over the passphrase and salt.

Parameters
dkpointer to the buffer where the derived key will be stored
passphrasepointer to the passphrase (null-terminated string) used to derive the key
saltpointer to the salt string used in the key derivation process
saltLenlength of the salt in bytes
iterationsnumber of iterations to perform in the key derivation process
dkLendesired length of the derived key in bytes.
hashIDidentifier for the digest function to use; allowed values are: SHARKSSL_HASHID_SHA512, SHARKSSL_HASHID_SHA384, SHARKSSL_HASHID_SHA256
Returns
0 on success, or a non-zero error code on failure