37#ifndef _SharkSslCrypto_h
38#define _SharkSslCrypto_h
44#define SHARKSSL_MD5_HASH_LEN 16
45#define SHARKSSL_SHA1_HASH_LEN 20
46#define SHARKSSL_SHA256_HASH_LEN 32
47#define SHARKSSL_SHA384_HASH_LEN 48
48#define SHARKSSL_SHA512_HASH_LEN 64
49#define SHARKSSL_POLY1305_HASH_LEN 16
51#define SHARKSSL_MD5_BLOCK_LEN 64
52#define SHARKSSL_SHA1_BLOCK_LEN 64
53#define SHARKSSL_SHA256_BLOCK_LEN 64
54#define SHARKSSL_SHA384_BLOCK_LEN 128
55#define SHARKSSL_SHA512_BLOCK_LEN 128
59#define SHARKSSL_HASHID_MD5 0x01
60#define SHARKSSL_HASHID_SHA1 0x02
61#define SHARKSSL_HASHID_SHA256 0x04
62#define SHARKSSL_HASHID_SHA384 0x05
63#define SHARKSSL_HASHID_SHA512 0x06
70typedef struct SharkSslMd5Ctx
83typedef struct SharkSslSha1Ctx
92#if SHARKSSL_USE_SHA_256
105#if (SHARKSSL_USE_SHA_384 || SHARKSSL_USE_SHA_512)
118#if SHARKSSL_USE_SHA_512
126#if (SHARKSSL_USE_SHA_512 || SHARKSSL_USE_SHA_384 || SHARKSSL_USE_SHA_256 || SHARKSSL_USE_SHA1 || SHARKSSL_USE_MD5)
135 SharkSslMd5Ctx md5Ctx;
137 #if SHARKSSL_USE_SHA1
138 SharkSslSha1Ctx sha1Ctx;
140 #if SHARKSSL_USE_SHA_256
143 #if SHARKSSL_USE_SHA_384
146 #if SHARKSSL_USE_SHA_512
147 SharkSslSha512Ctx sha512Ctx;
152 #if SHARKSSL_USE_SHA_512
153 U8 key[SHARKSSL_SHA512_BLOCK_LEN];
154 #elif SHARKSSL_USE_SHA_384
155 U8 key[SHARKSSL_SHA384_BLOCK_LEN];
156 #elif SHARKSSL_USE_SHA_256
157 U8 key[SHARKSSL_SHA256_BLOCK_LEN];
158 #elif SHARKSSL_USE_SHA1
159 U8 key[SHARKSSL_SHA1_BLOCK_LEN];
160 #elif SHARKSSL_USE_MD5
161 U8 key[SHARKSSL_MD5_BLOCK_LEN];
169#if SHARKSSL_USE_POLY1305
184#if SHARKSSL_USE_CHACHA20
195#if (SHARKSSL_USE_AES_256 || SHARKSSL_USE_AES_192 || SHARKSSL_USE_AES_128)
201 #if (SHARKSSL_USE_AES_256 || SHARKSSL_NOPACK)
203 #elif SHARKSSL_USE_AES_192
213 SharkSslAesCtx_Decrypt,
214 SharkSslAesCtx_Encrypt
215} SharkSslAesCtx_Type;
217#if SHARKSSL_ENABLE_AES_GCM
228#if SHARKSSL_ENABLE_AES_CCM
232typedef struct SharkSslAesCcmCtx
246SHARKSSL_API
int sharkssl_entropy(U32);
247SHARKSSL_API
int sharkssl_rng(U8*, U16);
248SHARKSSL_API
int sharkssl_kmemcmp(
const void *a,
const void *b, U32 n);
257SHARKSSL_API
void SharkSslMd5Ctx_constructor(SharkSslMd5Ctx* ctx);
262SHARKSSL_API
void SharkSslMd5Ctx_append(SharkSslMd5Ctx* ctx,
const U8* data, U32 len);
267SHARKSSL_API
void SharkSslMd5Ctx_finish(SharkSslMd5Ctx* ctx, U8 digest[SHARKSSL_MD5_HASH_LEN]);
272SHARKSSL_API
int sharkssl_md5(
const U8*, U16, U8*);
281SHARKSSL_API
void SharkSslSha1Ctx_constructor(SharkSslSha1Ctx* ctx);
286SHARKSSL_API
void SharkSslSha1Ctx_append(SharkSslSha1Ctx* ctx,
const U8* data, U32 len);
291SHARKSSL_API
void SharkSslSha1Ctx_finish(SharkSslSha1Ctx*, U8 digest[SHARKSSL_SHA1_HASH_LEN]);
296SHARKSSL_API
int sharkssl_sha1(
const U8*, U16, U8*);
299#if SHARKSSL_USE_SHA_256
323#if SHARKSSL_USE_SHA_384
347#if SHARKSSL_USE_SHA_512
353SHARKSSL_API
void SharkSslSha512Ctx_constructor(SharkSslSha512Ctx* ctx);
358#define SharkSslSha512Ctx_append(ctx, d, l) \
359 SharkSslSha384Ctx_append((SharkSslSha384Ctx*)ctx, d, l)
364SHARKSSL_API
void SharkSslSha512Ctx_finish(SharkSslSha512Ctx*, U8 digest[SHARKSSL_SHA512_HASH_LEN]);
369SHARKSSL_API
int sharkssl_sha512(
const U8*, U16, U8*);
372#if (SHARKSSL_USE_SHA_512 || SHARKSSL_USE_SHA_384 || SHARKSSL_USE_SHA_256 || SHARKSSL_USE_SHA1 || SHARKSSL_USE_MD5)
394#define SharkSslHMACCtx_destructor(o) memset(o, 0, sizeof(SharkSslHMACCtx))
407SHARKSSL_API
int sharkssl_HMAC(
const U8 hashID,
const U8 *data, U16 len,
const U8 *key, U16 keyLen, U8 *digest);
410U16 sharkssl_getHashLen(U8 hashID);
411int sharkssl_hash(U8 *digest, U8 *data, U16 len, U8 hashID);
414#if SHARKSSL_USE_POLY1305
423#define SharkSslPoly1305Ctx_destructor(o) memset(o, 0, sizeof(SharkSslPoly1305Ctx))
441#if SHARKSSL_USE_CHACHA20
450 const U8 *key, U8 keyLen);
452#define SharkSslChaChaCtx_destructor(ctx) memset(ctx, 0, sizeof(SharkSslChaChaCtx))
470#if (SHARKSSL_USE_AES_256 || SHARKSSL_USE_AES_192 || SHARKSSL_USE_AES_128)
480 SharkSslAesCtx_Type type,
481 const U8 *key, U8 keyLen);
482#define SharkSslAesCtx_destructor(ctx) memset(ctx, 0, sizeof(SharkSslAesCtx))
484#if (!SHARKSSL_DISABLE_AES_ECB_DECRYPT)
496#if SHARKSSL_ENABLE_AES_CBC
500SHARKSSL_API
void SharkSslAesCtx_cbc_encrypt(
SharkSslAesCtx *ctx, U8 vect[16],
501 const U8 *input, U8 *output, U16 len);
506SHARKSSL_API
void SharkSslAesCtx_cbc_decrypt(
SharkSslAesCtx *ctx, U8 vect[16],
507 const U8 *input, U8 *output, U16 len);
509#if SHARKSSL_ENABLE_AES_CTR_MODE
514SHARKSSL_API
void SharkSslAesCtx_ctr_mode(
SharkSslAesCtx *ctx, U8 ctr[16],
515 const U8 *input, U8 *output, U16 len);
517#if SHARKSSL_ENABLE_AES_GCM
526 const U8 *key, U8 keyLen);
528#define SharkSslAesGcmCtx_destructor(ctx) \
529 memset(ctx, 0, sizeof(SharkSslAesGcmCtx))
561 const U8 vect[12], U8 tagout[16],
562 const U8 *auth, U16 authlen,
563 const U8 *input, U8 *output, U16 len);
581 const U8 vect[12], U8 tagin[16],
582 const U8 *auth, U16 authlen,
583 U8 *input, U8 *output, U16 len);
585#if SHARKSSL_ENABLE_AES_CCM
594SHARKSSL_API
void SharkSslAesCcmCtx_constructor(SharkSslAesCcmCtx *ctx,
595 const U8 *key, U8 keyLen, U8 tagLen);
597#define SharkSslAesCcmCtx_destructor(ctx) memset(ctx, 0, sizeof(SharkSslAesCcmCtx))
602SHARKSSL_API
int SharkSslAesCcmCtx_encrypt(SharkSslAesCcmCtx *ctx,
603 const U8 vect[12], U8 *tagout,
604 const U8 *auth, U16 authlen,
605 const U8 *input, U8 *output, U16 len);
611SHARKSSL_API
int SharkSslAesCcmCtx_decrypt(SharkSslAesCcmCtx *ctx,
612 const U8 vect[12], U8 *tagin,
613 const U8 *auth, U16 authlen,
614 const U8 *input, U8 *output, U16 len);
struct SharkSslAesCtx SharkSslAesCtx
AES.
SHARKSSL_API void SharkSslAesCtx_constructor(SharkSslAesCtx *ctx, SharkSslAesCtx_Type type, const U8 *key, U8 keyLen)
Initialize.
SHARKSSL_API void SharkSslAesCtx_decrypt(SharkSslAesCtx *ctx, const U8 input[16], U8 output[16])
Decrypt.
SHARKSSL_API void SharkSslAesCtx_encrypt(SharkSslAesCtx *ctx, U8 input[16], U8 output[16])
Encrypt.
SHARKSSL_API int SharkSslAesGcmCtx_encrypt(SharkSslAesGcmCtx *ctx, const U8 vect[12], U8 tagout[16], const U8 *auth, U16 authlen, const U8 *input, U8 *output, U16 len)
Encrypt data or a chunk of a large data set.
SHARKSSL_API void SharkSslAesGcmCtx_constructor(SharkSslAesGcmCtx *ctx, const U8 *key, U8 keyLen)
Initialize.
SHARKSSL_API int SharkSslAesGcmCtx_decrypt(SharkSslAesGcmCtx *ctx, const U8 vect[12], U8 tagin[16], const U8 *auth, U16 authlen, U8 *input, U8 *output, U16 len)
Decrypt data or a chunk of a large data set.
struct SharkSslAesGcmCtx SharkSslAesGcmCtx
AesGcmCtx.
SHARKSSL_API void SharkSslChaChaCtx_crypt(SharkSslChaChaCtx *ctx, const U8 *input, U8 *output, U32 len)
Encrypt or decrypt.
SHARKSSL_API void SharkSslChaChaCtx_constructor(SharkSslChaChaCtx *ctx, const U8 *key, U8 keyLen)
Initialize.
SHARKSSL_API void SharkSslChaChaCtx_setIV(SharkSslChaChaCtx *ctx, const U8 IV[12])
Initialize.
struct SharkSslHMACCtx SharkSslHMACCtx
HMAC.
SHARKSSL_API void SharkSslHMACCtx_append(SharkSslHMACCtx *, const U8 *data, U32 len)
append
SHARKSSL_API void SharkSslHMACCtx_finish(SharkSslHMACCtx *, U8 *HMAC)
finish
SHARKSSL_API void SharkSslHMACCtx_constructor(SharkSslHMACCtx *ctx, U8 hashID, const U8 *key, U16 keyLen)
Initialize.
SHARKSSL_API int sharkssl_HMAC(const U8 hashID, const U8 *data, U16 len, const U8 *key, U16 keyLen, U8 *digest)
HMAC.
SHARKSSL_API void SharkSslPoly1305Ctx_finish(SharkSslPoly1305Ctx *ctx, U8 digest[SHARKSSL_POLY1305_HASH_LEN])
finish
SHARKSSL_API void SharkSslPoly1305Ctx_constructor(SharkSslPoly1305Ctx *ctx, const U8 key[32])
Initialize.
struct SharkSslPoly1305Ctx SharkSslPoly1305Ctx
POLY1305.
SHARKSSL_API void SharkSslPoly1305Ctx_append(SharkSslPoly1305Ctx *ctx, const U8 *in, U32 len)
append
SHARKSSL_API int sharkssl_poly1305(const U8 *data, U16 len, U8 *digest, const U8 key[32])
poly1305
SHARKSSL_API int sharkssl_sha256(const U8 *, U16, U8 *)
sha256
SHARKSSL_API void SharkSslSha256Ctx_constructor(SharkSslSha256Ctx *ctx)
Initialize.
SHARKSSL_API void SharkSslSha256Ctx_finish(SharkSslSha256Ctx *, U8 digest[SHARKSSL_SHA256_HASH_LEN])
finish
struct SharkSslSha256Ctx SharkSslSha256Ctx
SHA256.
SHARKSSL_API void SharkSslSha256Ctx_append(SharkSslSha256Ctx *, const U8 *data, U32 len)
append
SHARKSSL_API void SharkSslSha384Ctx_append(SharkSslSha384Ctx *, const U8 *data, U32 len)
append
SHARKSSL_API void SharkSslSha384Ctx_constructor(SharkSslSha384Ctx *ctx)
Initialize.
struct SharkSslSha384Ctx SharkSslSha384Ctx
SHA384.
SHARKSSL_API void SharkSslSha384Ctx_finish(SharkSslSha384Ctx *, U8 digest[SHARKSSL_SHA384_HASH_LEN])
finish
SHARKSSL_API int sharkssl_sha384(const U8 *, U16, U8 *)
sha384
AES.
Definition: SharkSslCrypto.h:200
AesGcmCtx.
Definition: SharkSslCrypto.h:222
CHACHA20.
Definition: SharkSslCrypto.h:189
HMAC.
Definition: SharkSslCrypto.h:131
POLY1305.
Definition: SharkSslCrypto.h:174
SHA256.
Definition: SharkSslCrypto.h:97
SHA384.
Definition: SharkSslCrypto.h:110