SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
SharkSslCrypto.h
Go to the documentation of this file.
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * SharkSSL Embedded SSL/TLS Stack
10 ****************************************************************************
11 * PROGRAM MODULE
12 *
13 * $Id: SharkSslCrypto.h 6818 2026-11-08 21:18:02Z gianluca $
14 *
15 * COPYRIGHT: Real Time Logic LLC, 2010 - 2026
16 *
17 * This software is copyrighted by and is the sole property of Real
18 * Time Logic LLC. All rights, title, ownership, or other interests in
19 * the software remain the property of Real Time Logic LLC. This
20 * software may only be used in accordance with the terms and
21 * conditions stipulated in the corresponding license agreement under
22 * which the software has been supplied. Any unauthorized use,
23 * duplication, transmission, distribution, or disclosure of this
24 * software is expressly forbidden.
25 *
26 * This Copyright notice may not be removed or modified without prior
27 * written consent of Real Time Logic LLC.
28 *
29 * Real Time Logic LLC. reserves the right to modify this software
30 * without notice.
31 *
32 * http://www.realtimelogic.com
33 * http://www.sharkssl.com
34 ****************************************************************************
35 *
36 */
37#ifndef _SharkSslCrypto_h
38#define _SharkSslCrypto_h
39
40#define SHARKSSL_LIB 1
41#include "SharkSSL.h"
42
43
44#define SHARKSSL_MD5_HASH_LEN 16
45#define SHARKSSL_SHA1_HASH_LEN 20
46#define SHARKSSL_SHA224_HASH_LEN 28
47#define SHARKSSL_SHA256_HASH_LEN 32
48#define SHARKSSL_SHA384_HASH_LEN 48
49#define SHARKSSL_SHA512_HASH_LEN 64
50#define SHARKSSL_POLY1305_HASH_LEN 16
51
52#define SHARKSSL_MD5_BLOCK_LEN 64
53#define SHARKSSL_SHA1_BLOCK_LEN 64
54#define SHARKSSL_SHA256_BLOCK_LEN 64
55#define SHARKSSL_SHA384_BLOCK_LEN 128
56#define SHARKSSL_SHA512_BLOCK_LEN 128
57
58/* RFC 8032 EdDSA prehash output length */
59#define SHARKSSL_EDDSA_PREHASH_LEN 64
60
63#define SHARKSSL_HASHID_MD5 0x01
64#define SHARKSSL_HASHID_SHA1 0x02
65#define SHARKSSL_HASHID_SHA224 0x03
66#define SHARKSSL_HASHID_SHA256 0x04
67#define SHARKSSL_HASHID_SHA384 0x05
68#define SHARKSSL_HASHID_SHA512 0x06
69
70
71#if SHARKSSL_USE_MD5
75typedef struct SharkSslMd5Ctx
76{
77 U32 total[2];
78 U32 state[4];
79 U8 buffer[64];
81#endif
82
83
84#if SHARKSSL_USE_SHA1
88typedef struct SharkSslSha1Ctx
89{
90 #if SHARKSSL_PSA_CONSUMER
93 #else
94 U32 total[2];
95 U32 state[5];
96 U8 buffer[64];
97 #endif
99#endif
100
101
102#if (SHARKSSL_USE_SHA_224 && SHARKSSL_PSA_CONSUMER)
103typedef struct SharkSslSha224Ctx
104{
108#endif
109
110
111#if SHARKSSL_USE_SHA_256
115typedef struct SharkSslSha256Ctx
116{
117 #if SHARKSSL_PSA_CONSUMER
120 #else
121 U32 total[2];
122 U32 state[8];
123 U8 buffer[64];
124 #endif
126#endif
127
128
137#if (SHARKSSL_USE_SHA_384 || SHARKSSL_USE_SHA_512)
141typedef struct SharkSslSha384Ctx
142{
143 #if SHARKSSL_PSA_CONSUMER
146 #else
147 U32 total[4];
148 U64 state[8];
149 U8 buffer[128];
150 #endif
152#endif
153
154
155#if SHARKSSL_USE_SHA_512
160#endif
161
162
163#if (SHARKSSL_USE_SHA_512 || SHARKSSL_USE_SHA_384 || SHARKSSL_USE_SHA_256 || SHARKSSL_USE_SHA1 || SHARKSSL_USE_MD5)
172typedef struct SharkSslHMACCtx
173{
174 #if SHARKSSL_PSA_CONSUMER
179 #else
180 union
181 {
182 #if SHARKSSL_USE_MD5
183 SharkSslMd5Ctx md5Ctx;
184 #endif
185 #if SHARKSSL_USE_SHA1
186 SharkSslSha1Ctx sha1Ctx;
187 #endif
188 #if SHARKSSL_USE_SHA_256
189 SharkSslSha256Ctx sha256Ctx;
190 #endif
191 #if SHARKSSL_USE_SHA_384
192 SharkSslSha384Ctx sha384Ctx;
193 #endif
194 #if SHARKSSL_USE_SHA_512
195 SharkSslSha512Ctx sha512Ctx;
196 #endif
197 } hashCtx;
198
199 /* descending block length */
200 #if SHARKSSL_USE_SHA_512
202 #elif SHARKSSL_USE_SHA_384
204 #elif SHARKSSL_USE_SHA_256
206 #elif SHARKSSL_USE_SHA1
208 #elif SHARKSSL_USE_MD5
210 #endif
211
212 U8 hashID;
213 #endif
215#endif
216
217
218#if SHARKSSL_USE_POLY1305
223{
224 U32 r[5];
225 U32 key[4];
226 U32 nonce[4];
227 U8 buffer[16];
230#endif
231
232
233#if SHARKSSL_USE_CHACHA20
237typedef struct
238{
239 #if SHARKSSL_PSA_CONSUMER_STANDALONE_CHACHA20
243 U8 stream[64];
246 #else
247 U32 state[16];
248 #endif
250#endif
251
252
253#if (SHARKSSL_USE_AES_256 || SHARKSSL_USE_AES_192 || SHARKSSL_USE_AES_128)
257typedef struct SharkSslAesCtx
258{
259 #if SHARKSSL_PSA_CONSUMER_STANDALONE_AES
260 U8 key[32];
263 #else
264 #if (SHARKSSL_USE_AES_256 || SHARKSSL_NOPACK)
265 U32 key[60];
266 #elif SHARKSSL_USE_AES_192
267 U32 key[52];
268 #else
269 U32 key[44];
270 #endif
271 U16 nr;
272 #endif
274
275typedef enum
276{
280
281#if SHARKSSL_ENABLE_AES_GCM
285typedef struct SharkSslAesGcmCtx
286{
288 #if (!SHARKSSL_PSA_CONSUMER_STANDALONE_AES)
289 U8 M0[16][16];
290 #endif
292#endif
293
294#if SHARKSSL_ENABLE_AES_CCM
298typedef struct SharkSslAesCcmCtx
299{
303#endif
304#endif /* SHARKSSL_USE_AES_256 || SHARKSSL_USE_AES_192 || SHARKSSL_USE_AES_128 */
305
306
307#ifdef __cplusplus
308extern "C" {
309#endif
310
311/* SharkSslCrypto.c */
312#if SHARKSSL_PSA_CONSUMER
318SHARKSSL_API int sharkssl_entropy(void);
319#endif
320#if !SHARKSSL_PSA_CONSUMER || defined(__DOXYGEN__)
347SHARKSSL_API int sharkssl_entropyEx(const U8 *entropy, U16 len);
348#endif
349
350
351SHARKSSL_API int sharkssl_rng(U8*, U16);
352SHARKSSL_API int sharkssl_kmemcmp(const void *a, const void *b, U32 n);
353
354
355#if SHARKSSL_USE_MD5
362
366SHARKSSL_API void SharkSslMd5Ctx_append(SharkSslMd5Ctx *ctx, const U8 *data, U32 len);
367
372
376SHARKSSL_API int sharkssl_md5(const U8*, U32, U8*);
377#endif
378
379#if SHARKSSL_USE_SHA1
386
390SHARKSSL_API int SharkSslSha1Ctx_append(SharkSslSha1Ctx *ctx, const U8 *data, U32 len);
391
396#if SHARKSSL_PSA_CONSUMER
397SHARKSSL_API int SharkSslSha1Ctx_clone(const SharkSslSha1Ctx *source, SharkSslSha1Ctx *target);
399#endif
400
404SHARKSSL_API int sharkssl_sha1(const U8*, U32, U8*);
405#endif
406
407#if (SHARKSSL_USE_SHA_224 && SHARKSSL_PSA_CONSUMER)
409SHARKSSL_API int SharkSslSha224Ctx_append(SharkSslSha224Ctx *ctx, const U8 *data, U32 len);
411SHARKSSL_API int SharkSslSha224Ctx_clone(const SharkSslSha224Ctx *source, SharkSslSha224Ctx *target);
413SHARKSSL_API int sharkssl_sha224(const U8 *data, U32 len, U8 *digest);
414#endif
415
416#if SHARKSSL_USE_SHA_256
423
427SHARKSSL_API int SharkSslSha256Ctx_append(SharkSslSha256Ctx*, const U8 *data, U32 len);
428
433#if SHARKSSL_PSA_CONSUMER
434SHARKSSL_API int SharkSslSha256Ctx_clone(const SharkSslSha256Ctx *source, SharkSslSha256Ctx *target);
436#endif
437
441SHARKSSL_API int sharkssl_sha256(const U8*, U32, U8*);
442#endif
443
444#if SHARKSSL_USE_SHA_384
451#endif
452
453#if (SHARKSSL_USE_SHA_384 || SHARKSSL_USE_SHA_512)
454
458SHARKSSL_API int SharkSslSha384Ctx_append(SharkSslSha384Ctx*, const U8 *data, U32 len);
459
464#if SHARKSSL_PSA_CONSUMER
465SHARKSSL_API int SharkSslSha384Ctx_clone(const SharkSslSha384Ctx *source, SharkSslSha384Ctx *target);
467#endif
468#endif
469
470#if SHARKSSL_USE_SHA_384
471
475SHARKSSL_API int sharkssl_sha384(const U8*, U32, U8*);
476#endif
477
478#if SHARKSSL_USE_SHA_512
485
489SHARKSSL_API int SharkSslSha512Ctx_append(SharkSslSha512Ctx *ctx, const U8 *data, U32 len);
490
495#if SHARKSSL_PSA_CONSUMER
496SHARKSSL_API int SharkSslSha512Ctx_clone(const SharkSslSha512Ctx *source, SharkSslSha512Ctx *target);
498#endif
499
503SHARKSSL_API int sharkssl_sha512(const U8*, U32, U8*);
504#endif
505
506#if (SHARKSSL_USE_SHA_512 || SHARKSSL_USE_SHA_384 || SHARKSSL_USE_SHA_256 || SHARKSSL_USE_SHA1 || SHARKSSL_USE_MD5)
516SHARKSSL_API int SharkSslHMACCtx_constructor(SharkSslHMACCtx *ctx, U8 hashID, const U8 *key, U16 keyLen);
517
521SHARKSSL_API int SharkSslHMACCtx_append(SharkSslHMACCtx*, const U8 *data, U32 len);
522
526SHARKSSL_API int SharkSslHMACCtx_finish(SharkSslHMACCtx*, U8 *HMAC);
528
540SHARKSSL_API int sharkssl_HMAC(const U8 hashID, const U8 *data, U32 len, const U8 *key, U16 keyLen, U8 *digest);
541#endif
542
543void sharkssl_clear(void *data, U32 len);
544U16 sharkssl_getHashLen(U8 hashID);
545int sharkssl_hash(U8 *digest, U8 *data, U32 len, U8 hashID);
546
547
548#if SHARKSSL_USE_POLY1305
555SHARKSSL_API void SharkSslPoly1305Ctx_constructor(SharkSslPoly1305Ctx *ctx, const U8 key[32]);
556
557#define SharkSslPoly1305Ctx_destructor(o) sharkssl_clear(o, sizeof(SharkSslPoly1305Ctx))
558
562SHARKSSL_API void SharkSslPoly1305Ctx_append(SharkSslPoly1305Ctx *ctx, const U8 *in, U32 len);
563
568
572SHARKSSL_API int sharkssl_poly1305(const U8 *data, U32 len, U8 *digest, const U8 key[32]);
573#endif
574
575#if SHARKSSL_USE_CHACHA20
576#if SHARKSSL_PSA_CONSUMER_STANDALONE_CHACHA20
577#define SHARKSSL_CHACHA_API_STATUS int
578#else
579#define SHARKSSL_CHACHA_API_STATUS void
580#endif
589 const U8 *key, U8 keyLen);
590
591#if SHARKSSL_PSA_CONSUMER_STANDALONE_CHACHA20
593#else
594#define SharkSslChaChaCtx_destructor(ctx) sharkssl_clear(ctx, sizeof(SharkSslChaChaCtx))
595#endif
596
604
609 SharkSslChaChaCtx *ctx, const U8 *input, U8 *output, U32 len);
610#undef SHARKSSL_CHACHA_API_STATUS
611#if SHARKSSL_PSA_CONSUMER_STANDALONE_CHACHA20
612SHARKSSL_API int sharkssl_chacha20poly1305_encrypt(const U8 key[32], const U8 nonce[12],
613 const U8 *aad, const U8 *input, U8 *output, U8 tag[16], U32 len, U16 aadLen);
614SHARKSSL_API int sharkssl_chacha20poly1305_decrypt(const U8 key[32], const U8 nonce[12],
615 const U8 *aad, const U8 *input, const U8 tag[16], U8 *output, U32 len, U16 aadLen);
616#endif
617#endif
618
619
620#if (SHARKSSL_USE_AES_256 || SHARKSSL_USE_AES_192 || SHARKSSL_USE_AES_128)
621#if SHARKSSL_PSA_CONSUMER_STANDALONE_AES
622#define SHARKSSL_AES_API_STATUS int
623#else
624#define SHARKSSL_AES_API_STATUS void
625#endif
636 const U8 *key, U8 keyLen);
637#define SharkSslAesCtx_destructor(ctx) sharkssl_clear(ctx, sizeof(SharkSslAesCtx))
638
639#if (!SHARKSSL_DISABLE_AES_ECB_DECRYPT)
643SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_decrypt(SharkSslAesCtx *ctx, const U8 input[16], U8 output[16]);
644#endif
645
649SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_encrypt(SharkSslAesCtx *ctx, U8 input[16], U8 output[16]);
650
651#if SHARKSSL_ENABLE_AES_CBC
656 const U8 *input, U8 *output, U32 len);
657
662 const U8 *input, U8 *output, U32 len);
663#if (SHARKSSL_PSA_CONSUMER_STANDALONE_AES && defined(PSA_ALG_CBC_PKCS7))
667SHARKSSL_API int SharkSslAesCtx_cbc_pkcs7_encrypt(SharkSslAesCtx *ctx, const U8 iv[16],
668 const U8 *input, U8 *output, U32 *outputLen, U32 len, U32 outputCapacity);
669SHARKSSL_API int SharkSslAesCtx_cbc_pkcs7_decrypt(SharkSslAesCtx *ctx, const U8 iv[16],
670 const U8 *input, U8 *output, U32 *outputLen, U32 len, U32 outputCapacity);
671#endif
672#endif
673#if SHARKSSL_ENABLE_AES_CTR_MODE
674
679 const U8 *input, U8 *output, U32 len);
680#endif
681#if SHARKSSL_ENABLE_AES_GCM
690 const U8 *key, U8 keyLen);
691
692#define SharkSslAesGcmCtx_destructor(ctx) sharkssl_clear(ctx, sizeof(SharkSslAesGcmCtx))
693
715 const U8 vect[12], U8 tagout[16],
716 const U8 *auth, U16 authlen,
717 const U8 *input, U8 *output, U32 len);
718
719
740 const U8 vect[12], U8 tagin[16],
741 const U8 *auth, U16 authlen,
742 U8 *input, U8 *output, U32 len);
743#endif
744#if SHARKSSL_ENABLE_AES_CCM
754 const U8 *key, U8 keyLen, U8 tagLen);
755
756#define SharkSslAesCcmCtx_destructor(ctx) sharkssl_clear(ctx, sizeof(SharkSslAesCcmCtx))
757
762 const U8 vect[12], U8 *tagout,
763 const U8 *auth, U16 authlen,
764 const U8 *input, U8 *output, U32 len);
765
766
771 const U8 vect[12], U8 *tagin,
772 const U8 *auth, U16 authlen,
773 const U8 *input, U8 *output, U32 len);
774#endif
775#undef SHARKSSL_AES_API_STATUS
776#endif
777
778#ifdef __cplusplus
779}
780#endif
781
782
783#endif /* _SharkSslCrypto_h */
TLS objects, certificate/session operations, and public-key interfaces.
SHARKSSL_API int sharkssl_entropy(void)
Initialize the selected PSA Crypto provider.
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.
#define SHARKSSL_SHA512_BLOCK_LEN
Definition: SharkSslCrypto.h:56
#define SHARKSSL_SHA384_BLOCK_LEN
Definition: SharkSslCrypto.h:55
#define SHARKSSL_SHA512_HASH_LEN
Definition: SharkSslCrypto.h:49
#define SHARKSSL_POLY1305_HASH_LEN
Definition: SharkSslCrypto.h:50
#define SHARKSSL_MD5_HASH_LEN
Definition: SharkSslCrypto.h:44
#define SHARKSSL_AES_API_STATUS
Definition: SharkSslCrypto.h:622
#define SHARKSSL_SHA1_BLOCK_LEN
Definition: SharkSslCrypto.h:53
#define SHARKSSL_SHA1_HASH_LEN
Definition: SharkSslCrypto.h:45
#define SHARKSSL_SHA384_HASH_LEN
Definition: SharkSslCrypto.h:48
#define SHARKSSL_SHA256_BLOCK_LEN
Definition: SharkSslCrypto.h:54
#define SHARKSSL_MD5_BLOCK_LEN
Definition: SharkSslCrypto.h:52
SharkSslAesCtx_Type
Definition: SharkSslCrypto.h:276
@ SharkSslAesCtx_Encrypt
Definition: SharkSslCrypto.h:278
@ SharkSslAesCtx_Decrypt
Definition: SharkSslCrypto.h:277
#define SHARKSSL_CHACHA_API_STATUS
Definition: SharkSslCrypto.h:577
struct SharkSslSha224Ctx SharkSslSha224Ctx
#define SHARKSSL_SHA256_HASH_LEN
Definition: SharkSslCrypto.h:47
#define SHARKSSL_SHA224_HASH_LEN
Definition: SharkSslCrypto.h:46
int32_t psa_status_t
SharkSSL PSA Crypto API 1.4.1/1.5.0 configurable subset.
Definition: crypto.h:57
uint32_t psa_key_id_t
Definition: crypto.h:60
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_cbc_encrypt(SharkSslAesCtx *ctx, U8 vect[16], const U8 *input, U8 *output, U32 len)
Encrypt.
struct SharkSslAesCtx SharkSslAesCtx
AES.
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_decrypt(SharkSslAesCtx *ctx, const U8 input[16], U8 output[16])
Decrypt.
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_cbc_decrypt(SharkSslAesCtx *ctx, U8 vect[16], const U8 *input, U8 *output, U32 len)
Decrypt.
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_constructor(SharkSslAesCtx *ctx, SharkSslAesCtx_Type type, const U8 *key, U8 keyLen)
Initialize.
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_encrypt(SharkSslAesCtx *ctx, U8 input[16], U8 output[16])
Encrypt.
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.
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCcmCtx_constructor(SharkSslAesCcmCtx *ctx, const U8 *key, U8 keyLen, U8 tagLen)
Initialize.
struct SharkSslAesCcmCtx SharkSslAesCcmCtx
AesCcmCtx.
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.
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.
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.
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesGcmCtx_constructor(SharkSslAesGcmCtx *ctx, const U8 *key, U8 keyLen)
Initialize.
struct SharkSslAesGcmCtx SharkSslAesGcmCtx
AesGcmCtx.
SHARKSSL_API int sharkssl_entropyEx(const U8 *entropy, U16 len)
Seed or reseed the native random-number generator.
SHARKSSL_API SHARKSSL_CHACHA_API_STATUS SharkSslChaChaCtx_crypt(SharkSslChaChaCtx *ctx, const U8 *input, U8 *output, U32 len)
Encrypt or decrypt.
SHARKSSL_API SHARKSSL_CHACHA_API_STATUS SharkSslChaChaCtx_setIV(SharkSslChaChaCtx *ctx, const U8 IV[12])
Initialize.
SHARKSSL_API SHARKSSL_CHACHA_API_STATUS SharkSslChaChaCtx_constructor(SharkSslChaChaCtx *ctx, const U8 *key, U8 keyLen)
Initialize.
struct SharkSslHMACCtx SharkSslHMACCtx
HMAC.
SHARKSSL_API int SharkSslHMACCtx_finish(SharkSslHMACCtx *, U8 *HMAC)
finish
SHARKSSL_API int SharkSslHMACCtx_append(SharkSslHMACCtx *, const U8 *data, U32 len)
append
SHARKSSL_API int SharkSslHMACCtx_constructor(SharkSslHMACCtx *ctx, U8 hashID, const U8 *key, U16 keyLen)
Initialize.
SHARKSSL_API int sharkssl_HMAC(const U8 hashID, const U8 *data, U32 len, const U8 *key, U16 keyLen, U8 *digest)
HMAC.
SHARKSSL_API int sharkssl_md5(const U8 *, U32, U8 *)
md5
struct SharkSslMd5Ctx SharkSslMd5Ctx
MD5.
SHARKSSL_API void SharkSslMd5Ctx_constructor(SharkSslMd5Ctx *ctx)
Initialize.
SHARKSSL_API void SharkSslMd5Ctx_append(SharkSslMd5Ctx *ctx, const U8 *data, U32 len)
append
SHARKSSL_API void SharkSslMd5Ctx_finish(SharkSslMd5Ctx *ctx, U8 digest[SHARKSSL_MD5_HASH_LEN])
finish
SHARKSSL_API void SharkSslPoly1305Ctx_finish(SharkSslPoly1305Ctx *ctx, U8 digest[SHARKSSL_POLY1305_HASH_LEN])
finish
SHARKSSL_API void SharkSslPoly1305Ctx_append(SharkSslPoly1305Ctx *ctx, const U8 *in, U32 len)
append
SHARKSSL_API void SharkSslPoly1305Ctx_constructor(SharkSslPoly1305Ctx *ctx, const U8 key[32])
Initialize.
struct SharkSslPoly1305Ctx SharkSslPoly1305Ctx
POLY1305.
SHARKSSL_API int sharkssl_poly1305(const U8 *data, U32 len, U8 *digest, const U8 key[32])
poly1305
SHARKSSL_API int SharkSslSha1Ctx_append(SharkSslSha1Ctx *ctx, const U8 *data, U32 len)
append
SHARKSSL_API int SharkSslSha1Ctx_constructor(SharkSslSha1Ctx *ctx)
Initialize.
struct SharkSslSha1Ctx SharkSslSha1Ctx
SHA1.
SHARKSSL_API int SharkSslSha1Ctx_finish(SharkSslSha1Ctx *ctx, U8 digest[SHARKSSL_SHA1_HASH_LEN])
finish
SHARKSSL_API int sharkssl_sha1(const U8 *, U32, U8 *)
sha1
SHARKSSL_API int SharkSslSha256Ctx_constructor(SharkSslSha256Ctx *ctx)
Initialize.
SHARKSSL_API int sharkssl_sha256(const U8 *, U32, U8 *)
sha256
SHARKSSL_API int SharkSslSha256Ctx_finish(SharkSslSha256Ctx *, U8 digest[SHARKSSL_SHA256_HASH_LEN])
finish
SHARKSSL_API int SharkSslSha256Ctx_append(SharkSslSha256Ctx *, const U8 *data, U32 len)
append
struct SharkSslSha256Ctx SharkSslSha256Ctx
SHA256.
SHARKSSL_API int SharkSslSha384Ctx_constructor(SharkSslSha384Ctx *ctx)
Initialize.
struct SharkSslSha384Ctx SharkSslSha384Ctx
In PSA consumer builds, hash contexts own provider operations.
SHARKSSL_API int SharkSslSha384Ctx_append(SharkSslSha384Ctx *, const U8 *data, U32 len)
append
SHARKSSL_API int SharkSslSha384Ctx_finish(SharkSslSha384Ctx *, U8 digest[SHARKSSL_SHA384_HASH_LEN])
finish
SHARKSSL_API int sharkssl_sha384(const U8 *, U32, U8 *)
sha384
SHARKSSL_API int SharkSslSha512Ctx_append(SharkSslSha512Ctx *ctx, const U8 *data, U32 len)
append
SHARKSSL_API int sharkssl_sha512(const U8 *, U32, U8 *)
sha512
SHARKSSL_API int SharkSslSha512Ctx_constructor(SharkSslSha512Ctx *ctx)
Initialize.
SHARKSSL_API int SharkSslSha512Ctx_finish(SharkSslSha512Ctx *ctx, U8 digest[SHARKSSL_SHA512_HASH_LEN])
finish
SHARKSSL_API int SharkSslSha224Ctx_abort(SharkSslSha224Ctx *ctx)
Abort a PSA hash operation and release its resources.
SHARKSSL_API int SharkSslSha224Ctx_clone(const SharkSslSha224Ctx *source, SharkSslSha224Ctx *target)
Clone an active PSA hash context without consuming the source.
SHARKSSL_API int SharkSslSha224Ctx_constructor(SharkSslSha224Ctx *ctx)
Initialize a PSA SHA-224 streaming operation.
SHARKSSL_API int SharkSslSha1Ctx_abort(SharkSslSha1Ctx *ctx)
Abort a PSA hash operation and release its resources.
SHARKSSL_API int SharkSslSha1Ctx_clone(const SharkSslSha1Ctx *source, SharkSslSha1Ctx *target)
Clone an active PSA hash context without consuming the source.
SHARKSSL_API int SharkSslSha224Ctx_finish(SharkSslSha224Ctx *ctx, U8 digest[SHARKSSL_SHA224_HASH_LEN])
Finish PSA SHA-224 and release the operation.
SHARKSSL_API int SharkSslAesCtx_cbc_pkcs7_decrypt(SharkSslAesCtx *ctx, const U8 iv[16], const U8 *input, U8 *output, U32 *outputLen, U32 len, U32 outputCapacity)
Decrypt PSA AES-CBC and remove PKCS#7 padding.
SHARKSSL_API int sharkssl_rng(U8 *, U16)
Fill a buffer using the configured random generator.
SHARKSSL_API int SharkSslSha384Ctx_abort(SharkSslSha384Ctx *ctx)
Abort a PSA hash operation and release its resources.
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)
Perform one-shot ChaCha20-Poly1305 encryption and authentication.
void sharkssl_clear(void *data, U32 len)
Overwrite a buffer through the implementation clearing routine.
SHARKSSL_API int SharkSslChaChaCtx_destructor(SharkSslChaChaCtx *ctx)
Abort a standalone PSA ChaCha20 operation and destroy its imported key.
SHARKSSL_API int SharkSslSha256Ctx_abort(SharkSslSha256Ctx *ctx)
Abort a PSA hash operation and release its resources.
int sharkssl_hash(U8 *digest, U8 *data, U32 len, U8 hashID)
Compute a complete digest using a SharkSSL hash ID.
SHARKSSL_API int sharkssl_sha224(const U8 *data, U32 len, U8 *digest)
Compute a one-shot SHA-224 digest through PSA.
SHARKSSL_API int SharkSslHMACCtx_destructor(SharkSslHMACCtx *ctx)
Clear an HMAC context and release any owned PSA resources.
SHARKSSL_API int sharkssl_kmemcmp(const void *a, const void *b, U32 n)
Compare byte strings without early exit based on differing bytes.
SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCtx_ctr_mode(SharkSslAesCtx *ctx, U8 ctr[16], const U8 *input, U8 *output, U32 len)
Apply the SharkSSL AES counter-mode convention to complete blocks.
U16 sharkssl_getHashLen(U8 hashID)
Return the digest size for an enabled SharkSSL hash ID.
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)
Perform one-shot ChaCha20-Poly1305 authenticated decryption.
SHARKSSL_API int SharkSslSha512Ctx_clone(const SharkSslSha512Ctx *source, SharkSslSha512Ctx *target)
Clone an active PSA hash context without consuming the source.
SHARKSSL_API int SharkSslSha512Ctx_abort(SharkSslSha512Ctx *ctx)
Abort a PSA hash operation and release its resources.
SHARKSSL_API int SharkSslSha224Ctx_append(SharkSslSha224Ctx *ctx, const U8 *data, U32 len)
Append bytes to an active PSA SHA-224 operation.
SHARKSSL_API int SharkSslSha256Ctx_clone(const SharkSslSha256Ctx *source, SharkSslSha256Ctx *target)
Clone an active PSA hash context without consuming the source.
SHARKSSL_API int SharkSslSha384Ctx_clone(const SharkSslSha384Ctx *source, SharkSslSha384Ctx *target)
Clone an active PSA hash context without consuming the source.
AesCcmCtx.
Definition: SharkSslCrypto.h:299
U8 tagLen
Definition: SharkSslCrypto.h:301
SharkSslAesCtx super
Definition: SharkSslCrypto.h:300
AES.
Definition: SharkSslCrypto.h:258
U8 valid
Definition: SharkSslCrypto.h:262
U8 keyLen
Definition: SharkSslCrypto.h:261
U8 key[32]
Definition: SharkSslCrypto.h:260
AesGcmCtx.
Definition: SharkSslCrypto.h:286
SharkSslAesCtx super
Definition: SharkSslCrypto.h:287
CHACHA20.
Definition: SharkSslCrypto.h:238
psa_cipher_operation_t operation
Definition: SharkSslCrypto.h:240
U8 active
Definition: SharkSslCrypto.h:245
U8 used
Definition: SharkSslCrypto.h:244
psa_status_t status
Definition: SharkSslCrypto.h:242
psa_key_id_t key
Definition: SharkSslCrypto.h:241
HMAC.
Definition: SharkSslCrypto.h:173
psa_mac_operation_t operation
Definition: SharkSslCrypto.h:175
U8 hashID
Definition: SharkSslCrypto.h:178
psa_key_id_t key
Definition: SharkSslCrypto.h:176
psa_status_t status
Definition: SharkSslCrypto.h:177
MD5.
Definition: SharkSslCrypto.h:76
U8 buffer[64]
Definition: SharkSslCrypto.h:79
U32 state[4]
Definition: SharkSslCrypto.h:78
U32 total[2]
Definition: SharkSslCrypto.h:77
POLY1305.
Definition: SharkSslCrypto.h:223
U32 nonce[4]
Definition: SharkSslCrypto.h:226
U32 r[5]
Definition: SharkSslCrypto.h:224
U8 buffer[16]
Definition: SharkSslCrypto.h:227
U8 flag
Definition: SharkSslCrypto.h:228
U32 key[4]
Definition: SharkSslCrypto.h:225
U8 blen
Definition: SharkSslCrypto.h:228
SHA1.
Definition: SharkSslCrypto.h:89
psa_hash_operation_t operation
Definition: SharkSslCrypto.h:91
psa_status_t status
Definition: SharkSslCrypto.h:92
PSA SHA-224 operation storage.
Definition: SharkSslCrypto.h:104
psa_status_t status
Definition: SharkSslCrypto.h:106
psa_hash_operation_t operation
Definition: SharkSslCrypto.h:105
SHA256.
Definition: SharkSslCrypto.h:116
psa_hash_operation_t operation
Definition: SharkSslCrypto.h:118
psa_status_t status
Definition: SharkSslCrypto.h:119
In PSA consumer builds, hash contexts own provider operations.
Definition: SharkSslCrypto.h:142
psa_status_t status
Definition: SharkSslCrypto.h:145
psa_hash_operation_t operation
Definition: SharkSslCrypto.h:144
AES cipher state; applications must treat all members as opaque.
Definition: crypto.h:846
Hash operation storage is implementation-defined.
Definition: crypto.h:777
MAC operation storage is implementation-defined.
Definition: crypto.h:831