SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
SharkSSL.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: SharkSSL.h 6825 2026-11-10 21:17:44Z wini $
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 _SharkSsl_h
38#define _SharkSsl_h
39
40#include "TargConfig.h" /* platform dependencies */
41
42#if defined(SHARKDBG_ENABLE) && SHARKDBG_ENABLE
43#define SHARKDBG_PRINTF(x) printf x
44#else
45#define SHARKDBG_PRINTF(x)
46#endif
47
48#ifndef SHARKSSL_API
49#define SHARKSSL_API
50#else /* host integration */
51#define SHARKSSL_BA 1
52#include <ThreadLib.h>
53#include <BaServerLib.h>
54#endif
55
56#include "SharkSSL_cfg.h" /* SharkSSL configuration */
57#if SHARKSSL_PSA_CONSUMER
58#include <psa/crypto.h>
59#endif
60#include <stddef.h> /* size_t */
61
62#include "SharkSslCrypto.h" /* Crypto API */
63
64#ifndef sharkCertSerialNumber2NetworkEndian
69typedef U64 SharkCertSerialNumber;
70#if (BA_BYTE_ORDER == BA_BYTE_ORDER_BIG_ENDIAN)
71#define sharkCertSerialNumber2NetworkEndian(n)
72#else
73#define sharkCertSerialNumber2NetworkEndian(n) \
74 do { \
75 U64 nn=0; \
76 register U8 *t=(U8*)&nn; \
77 register U8 *f=(U8*)&n; \
78 t[7]=f[0]; \
79 t[6]=f[1]; \
80 t[5]=f[2]; \
81 t[4]=f[3]; \
82 t[3]=f[4]; \
83 t[2]=f[5]; \
84 t[1]=f[6]; \
85 t[0]=f[7]; \
86 n=nn; \
87 } while(0)
88#endif
89#endif
90
91/* Forward decl. */
92struct SharkSslCertDN;
95
117#define SHARKSSL_ALERT_LEVEL_WARNING 1
118
120#define SHARKSSL_ALERT_LEVEL_FATAL 2
121
134#define SHARKSSL_ALERT_CLOSE_NOTIFY 0
136#define SHARKSSL_ALERT_UNEXPECTED_MESSAGE 10
138#define SHARKSSL_ALERT_BAD_RECORD_MAC 20
140#define SHARKSSL_ALERT_DECRYPTION_FAILED 21
142#define SHARKSSL_ALERT_RECORD_OVERFLOW 22
144#define SHARKSSL_ALERT_DECOMPRESSION_FAILURE 30
146#define SHARKSSL_ALERT_HANDSHAKE_FAILURE 40
148#define SHARKSSL_ALERT_BAD_CERTIFICATE 42
150#define SHARKSSL_ALERT_UNSUPPORTED_CERTIFICATE 43
152#define SHARKSSL_ALERT_CERTIFICATE_REVOKED 44
154#define SHARKSSL_ALERT_CERTIFICATE_EXPIRED 45
156#define SHARKSSL_ALERT_CERTIFICATE_UNKNOWN 46
158#define SHARKSSL_ALERT_ILLEGAL_PARAMETER 47
160#define SHARKSSL_ALERT_UNKNOWN_CA 48
162#define SHARKSSL_ALERT_ACCESS_DENIED 49
164#define SHARKSSL_ALERT_DECODE_ERROR 50
166#define SHARKSSL_ALERT_DECRYPT_ERROR 51
168#define SHARKSSL_ALERT_EXPORT_RESTRICTION 60
170#define SHARKSSL_ALERT_PROTOCOL_VERSION 70
172#define SHARKSSL_ALERT_INSUFFICIENT_SECURITY 71
174#define SHARKSSL_ALERT_INTERNAL_ERROR 80
176#define SHARKSSL_ALERT_USER_CANCELED 90
178#define SHARKSSL_ALERT_NO_RENEGOTIATION 100
180#define SHARKSSL_ALERT_MISSING_EXTENSION 109
182#define SHARKSSL_ALERT_UNSUPPORTED_EXTENSION 110
184#define SHARKSSL_ALERT_UNRECOGNIZED_NAME 112
186#define SHARKSSL_ALERT_GENERAL_ERROR 117
188#define SHARKSSL_ALERT_NO_APPLICATION_PROTOCOL 120 /* RFC 7301 */
189 /* end group SharkSslAlertMsg */ /* end group SharkSslAlert */
192
193
202#if SHARKSSL_TLS_1_3
204#define TLS_AES_128_GCM_SHA256 0x1301
206#define TLS_AES_256_GCM_SHA384 0x1302
208#define TLS_CHACHA20_POLY1305_SHA256 0x1303
209#endif
210#if SHARKSSL_TLS_1_2
212#define TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 0x009E
214#define TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 0x009F
216#define TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 0xC02B
218#define TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 0xC02C
220#define TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 0xC02F
222#define TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 0xC030
224#define TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 0xCCA8
226#define TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 0xCCA9
228#define TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 0xCCAA
229#endif
230 /* end group SharkSslCiphers */
232
233
241#define SHARKSSL_PROTOCOL_UNKNOWN 0x00
243#define SHARKSSL_PROTOCOL_TLS_1_2 0x33
245#define SHARKSSL_PROTOCOL_TLS_1_3 0x34
246
247/* internal use, with SHARKSSL_PROTOCOL_TLS_1_x as parameter */
248#define SHARKSSL_PROTOCOL_MAJOR(p) (p >> 4)
249#define SHARKSSL_PROTOCOL_MINOR(p) (p & 0xF)
250 /* end group SharkSslProtocol */
252
253
254#if (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA)
255#ifndef BA_API /* standalone SharkSSL */
256#define BA_API SHARKSSL_API
257#ifdef _SHARKSSL_C_
258#define SingleListCode 1
259#endif
260#endif
261#include "SingleList.h"
262#endif
263
264
265#if SHARKSSL_ENABLE_SESSION_CACHE || SHARKSSL_NOPACK
266
275 /* end group SharkSslSessionApi */
277
278#ifndef _DOXYGEN
279typedef struct SharkSslSessionCache
280{
281 SharkSslSession *cache;
282 ThreadMutexBase cacheMutex;
283 U16 cacheSize;
284} SharkSslSessionCache;
285#endif
286#endif
287
288
300typedef enum
301{
306 /* end group SharkSslInfoAndCodes */
308
309
310#if (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA)
318typedef U8* SharkSslKey;
319
320
326typedef const U8 *SharkSslCert;
327
328#ifdef __cplusplus
329extern "C" {
330#endif
331
336SHARKSSL_API U16 SharkSslCert_len(SharkSslCert cert);
337
340#ifdef __DOXYGEN__
342#endif
343
344#if SHARKSSL_ENABLE_CSR_CREATION
409SHARKSSL_API int
411 SharkSslKey privKey,
412 U8 hashID,
413 struct SharkSslCertDN *certDN,
414 const char *SAN,
415 struct SharkSslBitExtReq *keyUsage,
416 struct SharkSslBitExtReq *nsCertType);
417#endif
418
419#if SHARKSSL_ENABLE_CSR_SIGNING
423#endif
424
425#if SHARKSSL_ENABLE_ASN1_KEY_CREATION
432SHARKSSL_API int
434#endif
435
436
437#ifdef __cplusplus
438}
439#endif
440
441
442#if SHARKSSL_ENABLE_CA_LIST
448typedef const U8 *SharkSslCAList;
449#endif
450 /* end group SharkSslInfoAndCodes */
452#endif
453
454#ifndef _DOXYGEN
455struct SharkSsl;
456#endif
457
458
459/* Internal host callback used to manage automatic destruction of
460 SharkSslSCMgr.
461 */
462#ifndef _DOXYGEN
463struct SharkSslIntf;
464typedef void (*SharkSslIntf_Terminate)(struct SharkSslIntf *o,
465 struct SharkSsl *ssl);
466typedef struct SharkSslIntf
467{
468 SharkSslIntf_Terminate terminate;
469} SharkSslIntf;
470#define SharkSslIntf_constructor(o,terminateFunc) (o)->terminate=terminateFunc
471#endif
472
473
496
497
498#ifdef __cplusplus
499extern "C" {
500SHARKSSL_API void *sharkssl_mallocObject(size_t size);
501SHARKSSL_API void sharkssl_freeObject(void *object);
502}
503#endif
504
505
509typedef struct
511{
512#ifdef __cplusplus
513 void *operator new(size_t s) { return sharkssl_mallocObject(s); }
514 void operator delete(void *d) { sharkssl_freeObject(d); }
515 void *operator new(size_t, void *place) { return place; }
516 void operator delete(void*, void *) { }
517
519
521 U16 cacheSize = 0,
522 U16 inBufStartSize = 4096,
523 U16 outBufSize = 4096
524 );
525
526 ~SharkSsl();
527 SharkSslCon *createCon(void);
528 U8 setCAList(SharkSslCAList list);
529 U8 setCAListEx(SharkSslCAList list, U32 caListLen);
530 U8 addCertificate(SharkSslCert cert);
531 void terminateCon(SharkSslCon *sslCon);
532#endif
533 #if (SHARKSSL_SSL_SERVER_CODE && SHARKSSL_SSL_CLIENT_CODE) || SHARKSSL_NOPACK
535 #endif
538 U16 nCon;
539 #if (SHARKSSL_ENABLE_RSA || (SHARKSSL_ENABLE_ECDSA)) || SHARKSSL_NOPACK
540 SingleList certList;
541 #if SHARKSSL_ENABLE_CA_LIST || SHARKSSL_NOPACK
543 #endif
544 #endif
545 #if SHARKSSL_ENABLE_SESSION_CACHE || SHARKSSL_NOPACK
546 SharkSslSessionCache sessionCache;
547 /* Reserved for use with one SharkSslSCMgr object */
548 SharkSslIntf *intf;
549 #endif
551 /* end group SharkSslInfoAndCodes */
553
560typedef enum
561{
565
569
580
594
607
621
630
642
648
652
654 /* end group SharkSslCoreApi */
656
661#if (SHARKSSL_MAX_HANDSHAKE_LENGTH > 0xFFFFUL)
662typedef U32 SharkSslSANLen;
663#else
664typedef U16 SharkSslSANLen;
665#endif
666
667#if (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA)
668
680#if SHARKSSL_ENABLE_CERT_KEYUSAGE
681#define SHARKSSL_CERT_KEYUSAGE_DIGITALSIGNATURE 0x00000001
682#define SHARKSSL_CERT_KEYUSAGE_NONREPUDIATION 0x00000002
683#define SHARKSSL_CERT_KEYUSAGE_KEYENCIPHERMENT 0x00000004
684#define SHARKSSL_CERT_KEYUSAGE_DATAENCIPHERMENT 0x00000008
685#define SHARKSSL_CERT_KEYUSAGE_KEYAGREEMENT 0x00000010
686#define SHARKSSL_CERT_KEYUSAGE_KEYCERTSIGN 0x00000020
687#define SHARKSSL_CERT_KEYUSAGE_CRLSIGN 0x00000040
688#define SHARKSSL_CERT_KEYUSAGE_ENCIPHERONLY 0x00000080
689#define SHARKSSL_CERT_KEYUSAGE_DECIPHERONLY 0x00000100
690#define SHARKSSL_CERT_KEYUSAGE_PRESENT 0x00000200
691#define SHARKSSL_CERT_KEYUSAGE_CRITICAL 0x00000400
692
693#define SHARKSSL_CERT_KEYPURPOSE_SERVERAUTH 0x00010000
694#define SHARKSSL_CERT_KEYPURPOSE_CLIENTAUTH 0x00020000
695#define SHARKSSL_CERT_KEYPURPOSE_CODESIGNING 0x00040000
696#define SHARKSSL_CERT_KEYPURPOSE_EMAILPROTECTION 0x00080000
697#define SHARKSSL_CERT_KEYPURPOSE_TIMESTAMPING 0x00100000
698#define SHARKSSL_CERT_KEYPURPOSE_OCSPSIGNING 0x00200000
699
700#define SharkSslCertInfo_KeyFlagSet(o,f) ((o)->keyUsagePurposes & f)
701
705#define SharkSslCertInfo_isKeyUsagePresent(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_PRESENT)
706#define SharkSslCertInfo_isKeyUsageCritical(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_CRITICAL)
707#define SharkSslCertInfo_KU_digitalSignature(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_DIGITALSIGNATURE)
708#define SharkSslCertInfo_KU_nonRepudiation(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_NONREPUDIATION)
709#define SharkSslCertInfo_KU_keyEncipherment(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_KEYENCIPHERMENT)
710#define SharkSslCertInfo_KU_dataEncipherment(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_DATAENCIPHERMENT)
711#define SharkSslCertInfo_KU_keyAgreement(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_KEYAGREEMENT)
712#define SharkSslCertInfo_KU_keyCertSign(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_KEYCERTSIGN)
713#define SharkSslCertInfo_KU_cRLSign(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_CRLSIGN)
714#define SharkSslCertInfo_KU_encipherOnly(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_ENCIPHERONLY)
715#define SharkSslCertInfo_KU_decipherOnly(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYUSAGE_DECIPHERONLY)
716
717#define SharkSslCertInfo_kp_serverAuth(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYPURPOSE_SERVERAUTH)
718#define SharkSslCertInfo_kp_clientAuth(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYPURPOSE_CLIENTAUTH)
719#define SharkSslCertInfo_kp_codeSigning(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYPURPOSE_CODESIGNING)
720#define SharkSslCertInfo_kp_emailProtection(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYPURPOSE_EMAILPROTECTION)
721#define SharkSslCertInfo_kp_timeStamping(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYPURPOSE_TIMESTAMPING)
722#define SharkSslCertInfo_kp_OCSPSigning(o) SharkSslCertInfo_KeyFlagSet(o, SHARKSSL_CERT_KEYPURPOSE_OCSPSIGNING)
723#endif
724
725
737typedef struct SharkSslCertDN
738{
739 const U8 *countryName;
740 const U8 *province;
741 const U8 *locality;
742 const U8 *organization;
743 const U8 *unit;
747 const U8 *commonName;
748 const U8 *emailAddress;
749
758
761#define SharkSslCertDN_constructor(o) memset(o,0,sizeof(SharkSslCertDN))
764#define SharkSslCertDN_setCountryName(o, countryNameMA) \
765 (o)->countryName=(const U8*)countryNameMA,(o)->countryNameLen=(U8)strlen(countryNameMA)
768#define SharkSslCertDN_setProvince(o, provinceMA) \
769 (o)->province=(const U8*)provinceMA,(o)->provinceLen=(U8)strlen(provinceMA)
772#define SharkSslCertDN_setLocality(o, localityMA) \
773 (o)->locality=(const U8*)localityMA,(o)->localityLen=(U8)strlen(localityMA)
776#define SharkSslCertDN_setOrganization(o, organizationMA) \
777 (o)->organization=(const U8*)organizationMA,(o)->organizationLen=(U8)strlen(organizationMA)
780#define SharkSslCertDN_setUnit(o, unitMA) \
781 (o)->unit=(const U8*)unitMA,(o)->unitLen=(U8)strlen(unitMA)
784#define SharkSslCertDN_setCommonName(o, commonNameMA) \
785 (o)->commonName=(const U8*)commonNameMA,(o)->commonNameLen=(U8)strlen(commonNameMA)
788#define SharkSslCertDN_setEmailAddress(o, emailAddressMA) \
789 (o)->emailAddress=(const U8*)emailAddressMA,(o)->emailAddressLen=(U8)strlen(emailAddressMA)
790
791
795typedef struct SharkSslCertInfo
796{
798 U16 snLen;
799
804
809
812 U8 *sn;
813
817 U8 *timeFrom; /* declaration of U8 timeFromLen below */
818
823 U8 *timeTo; /* declaration of U8 timeToLen below */
824
830
836
850
853
856
857 #if SHARKSSL_ENABLE_CERT_KEYUSAGE
880 U32 keyUsagePurposes;
881 #endif
882
888 /* end group SharkSslCertInfo */
890#endif
891
897#ifdef __cplusplus
898extern "C" {
899#endif
900
946SHARKSSL_API void SharkSsl_constructor(
947 SharkSsl *o,
948 SharkSsl_Role role,
949 U16 cacheSize,
950 U16 inBufStartSize,
951 U16 outBufSize
952 );
953
961SHARKSSL_API void SharkSsl_destructor(SharkSsl *o);
962
963
984
985
1001
1002
1003#if SHARKSSL_ENABLE_SESSION_CACHE
1004
1009SHARKSSL_API U16 SharkSsl_getCacheSize(SharkSsl *o);
1010
1011#define SharkSsl_setIntf(o, sharkSslIntf) (o)->intf=sharkSslIntf
1012#define SharkSsl_getIntf(o) (o)->intf
1013
1014#endif
1015
1016
1023#define SharkSslCon_terminate(o) SharkSsl_terminateCon(0, o)
1024
1047
1048
1083
1084
1099
1100
1101#if (SHARKSSL_TLS_1_3 && SHARKSSL_ENABLE_KEY_UPDATE)
1108#define SHARKSSL_KEY_UPDATE_NOT_REQUESTED 0
1109
1115#define SHARKSSL_KEY_UPDATE_REQUESTED 1
1116
1145SHARKSSL_API U8 SharkSslCon_keyUpdate(SharkSslCon *o, U8 requestUpdate);
1146#if SHARKSSL_ENABLE_AES_GCM
1156#endif
1157#endif
1158
1159
1169
1170
1188
1189
1200
1212
1213
1232
1263U16 SharkSslCon_copyDecData(SharkSslCon *o, U8 *buf, U16 maxLen);
1264
1265
1275SHARKSSL_API U16 SharkSslCon_getDecData(SharkSslCon *o, U8 **bufPtr);
1276
1277
1293
1294
1308
1309
1331
1332
1343
1344
1357
1358
1366
1367
1371
1372
1383
1384
1395
1396
1406#define SharkSslCon_getAlertData(o) SharkSslCon_getEncData(o)
1407
1408
1418#define SharkSslCon_getAlertDataLen(o) SharkSslCon_getEncDataLen(o)
1419 /* end group SharkSslCoreApi */
1421
1422
1423#if SHARKSSL_ENABLE_INFO_API
1424
1428
1431#if (SHARKSSL_TLS_1_3 && SHARKSSL_TLS_1_2)
1433#elif SHARKSSL_TLS_1_3
1434#define SharkSslCon_getProtocol(o) (SHARKSSL_PROTOCOL_TLS_1_3)
1435#elif SHARKSSL_TLS_1_2
1436#define SharkSslCon_getProtocol(o) (SHARKSSL_PROTOCOL_TLS_1_2)
1437#else
1438#error please enable at least one of SHARKSSL_TLS_1_3, SHARKSSL_TLS_1_2
1439#endif
1440
1441#endif
1442
1443
1444#if SHARKSSL_ENABLE_SNI
1445
1446#if SHARKSSL_SSL_CLIENT_CODE
1449SHARKSSL_API U8 SharkSslCon_setSNI(SharkSslCon *o, const char *name, U16 length);
1450#endif
1451
1452#endif
1453
1454
1455#if (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA)
1456#if (SHARKSSL_SSL_CLIENT_CODE && SHARKSSL_ENABLE_CLIENT_AUTH)
1461#endif
1462
1467
1468
1469#if (SHARKSSL_ENABLE_CERTINFO_PARSE_API && (SHARKSSL_SSL_CLIENT_CODE || SHARKSSL_SSL_SERVER_CODE || SHARKSSL_ENABLE_CSR_SIGNING || SHARKSSL_SSL_TOOLS_CODE))
1479SHARKSSL_API int SharkSslCertInfo_parseCert(SharkSslCertInfo *o, const U8 *der, U32 len);
1480#endif
1481
1482
1494
1495#if SHARKSSL_PSA_CONSUMER
1504
1514#endif
1515
1516#if SHARKSSL_ENABLE_CA_LIST
1517
1549SHARKSSL_API U8 SharkSsl_setCAListEx(SharkSsl *o, SharkSslCAList caList, U32 caListLen);
1551#define SharkSsl_setCAList(o, caList) SharkSsl_setCAListEx((o), (caList), 0)
1552
1567
1569#else
1570
1571#define SharkSslCon_trustedCA(o) 0
1572#endif /* SHARKSSL_ENABLE_CA_LIST */
1573
1574#if (SHARKSSL_SSL_SERVER_CODE && SHARKSSL_ENABLE_RSA)
1576#define SHARKSSL_SET_FAVOR_RSA 1
1578#define SHARKSSL_CLEAR_FAVOR_RSA 0
1579
1589#endif /* SHARKSSL_SSL_SERVER_CODE */
1590#endif /* SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA */
1591
1593
1598#if SHARKSSL_ENABLE_SESSION_CACHE
1599
1600#if SHARKSSL_ENABLE_INFO_API
1604#endif
1605
1609
1610#if SHARKSSL_SSL_SERVER_CODE
1614#endif
1615
1616#if SHARKSSL_SSL_CLIENT_CODE
1617
1626
1627
1644
1650#endif
1651#endif
1652 /* end group SharkSslSessionApi */
1654
1655#if (SHARKSSL_SSL_SERVER_CODE && SHARKSSL_ENABLE_CLIENT_AUTH && \
1656 (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA))
1680SHARKSSL_API U8 SharkSslCon_requestClientCertEx(SharkSslCon *o, const void *caList, U32 caListLen);
1682#define SharkSslCon_requestClientCert(o, caList) SharkSslCon_requestClientCertEx((o), (caList), 0)
1683#endif
1684
1685#if (SHARKSSL_TLS_1_3 && SHARKSSL_SSL_CLIENT_CODE && SHARKSSL_ENABLE_CA_EXTENSION && \
1686 (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA))
1706SHARKSSL_API U8 SharkSslCon_setCertificateAuthoritiesEx(SharkSslCon *o, const void *caList, U32 caListLen);
1708#define SharkSslCon_setCertificateAuthorities(o, caList) SharkSslCon_setCertificateAuthoritiesEx((o), (caList), 0)
1709#endif
1710
1711#if SHARKSSL_ENABLE_ALPN_EXTENSION
1712#if SHARKSSL_SSL_CLIENT_CODE
1732SHARKSSL_API U8 SharkSslCon_setALPNProtocols(SharkSslCon *o, const char *protList);
1733
1747SHARKSSL_API const char *SharkSslCon_getALPNProtocol(SharkSslCon *o);
1748#endif
1749#if SHARKSSL_SSL_SERVER_CODE
1750typedef int(*ALPNFunction)(SharkSslCon*, const char*, void*);
1752 SharkSslCon *o, ALPNFunction func, void *pvoid);
1753#endif
1754#endif /* SHARKSSL_ENABLE_ALPN_EXTENSION */
1755
1756#if ((SHARKSSL_SSL_SERVER_CODE || SHARKSSL_SSL_CLIENT_CODE) && \
1757 SHARKSSL_ENABLE_SELECT_CIPHERSUITE)
1786SHARKSSL_API U8 SharkSslCon_selectCiphersuite(SharkSslCon *o, U16 cipherSuite);
1787
1791#endif
1792
1793#if (SHARKSSL_SSL_SERVER_CODE && SHARKSSL_ENABLE_SECURE_RENEGOTIATION)
1814#endif
1815 /* end group SharkSslApi */
1817
1818
1819#if SHARKSSL_ENABLE_PEM_API
1827typedef enum
1828{
1831
1834
1837
1840
1843
1846
1849
1852
1855
1858
1861
1864
1867
1870
1873
1876
1879
1882
1886
1887
1922 const char *certPEM, const char *keyPEM,
1923 const char *passphrase, SharkSslCert *sharkSslCert);
1924
1954SHARKSSL_API sharkssl_PEM_RetVal sharkssl_PEMEx(const char *certPEM, const char *keyPEM,
1955 const char *passphrase, SharkSslCert *sharkSslCert,
1956 U16 passphraseLen);
1957
1958#if SHARKSSL_ENABLE_ENCRYPTED_PKCS8_SUPPORT
1991SHARKSSL_API int sharkssl_PEM_PBKDF2Ex(U8 *dk, const char *passphrase, const char *salt,
1992 U32 saltLen, U32 iterations, U16 passphraseLen,
1993 U16 dkLen, U8 hashID);
1994
2012SHARKSSL_API int sharkssl_PEM_PBKDF2(
2013 U8 *dk, const char *passphrase,
2014 const char *salt, U32 saltLen,
2015 U32 iterations, U16 dkLen, U8 hashID);
2016#endif
2017 /* end group RayCryptoApi */
2019#endif
2020
2021#if SHARKSSL_ENABLE_RSA
2022
2029#define SHARKSSL_RSA_NO_PADDING 0
2030
2031
2035#define SHARKSSL_RSA_PKCS1_PADDING 1
2036
2037
2043typedef enum
2044{
2047
2050
2053
2056
2059
2062
2065
2068
2071
2074
2077
2080
2084#endif
2085 /* end group SharkSslInfoAndCodes */
2087
2088#if SHARKSSL_ENABLE_RSA_API
2089
2100typedef U8* SharkSslRSAKey;
2101
2102#if SHARKSSL_ENABLE_PEM_API
2127 const char *PEMKey, const char *passphrase);
2128
2152SHARKSSL_API SharkSslKey
2154
2155SHARKSSL_API SharkSslKey
2156sharkssl_PEM_extractPublicKey_ext(const char *certPEM, U8 *keyType);
2157#endif /* SHARKSSL_ENABLE_PEM_API */
2158
2159#if (SHARKSSL_ENABLE_PEM_API || (SHARKSSL_ENABLE_RSA && SHARKSSL_ENABLE_RSAKEY_CREATE))
2164#define _SHARKSSLRSAKEY_FREE 1
2165#endif
2166
2167#if SHARKSSL_ENABLE_RSA
2168#if SHARKSSL_ENABLE_RSAKEY_CREATE
2191SHARKSSL_API int SharkSslRSAKey_create(SharkSslRSAKey *privKey, U16 keyLength);
2192
2206#endif
2207
2212
2236 SharkSslRSAKey pubkey, const U8 *in, int len, U8 *out, int padding);
2237
2238
2257 SharkSslRSAKey privkey, const U8 *in, int len, U8 *out, int padding);
2258
2259
2277 SharkSslRSAKey privkey, U8 *sig, U16 *siglen, const U8 *hash, U8 hashID);
2278
2279
2297 SharkSslRSAKey pubkey, U8 *sig, U16 siglen, const U8 *hash, U8 hashID);
2298
2299
2300#if SHARKSSL_ENABLE_RSA_OAEP
2326 SharkSslRSAKey privkey, U8 *in, int len, U8 hashID, U8 *out, const char *label, U16 labelLen);
2327
2328
2355 SharkSslRSAKey pubkey, const U8 *in, int len, U8 hashID, U8 *out, const char *label, U16 labelLen);
2356#endif
2357
2358
2380 SharkSslRSAKey privkey, const U8 *in, int len, U8 *out, int padding);
2381
2382
2404 SharkSslRSAKey pubkey, const U8 *in, int len, U8 *out, int padding);
2405
2406#endif
2407 /* end group RSA */
2409#endif
2410
2411
2424#if SHARKSSL_USE_ECC
2425/*
2426 * NamedCurve, use as curveID parameter
2427 * SECPxxxR1 - RFC 4492 section 5.1.1
2428 * BRAINPOOLPxxxR1 - RFC 7027 section 2
2429 * CURVE25519,448 - RFC 8446 section 4.2.7
2430 */
2431#define SHARKSSL_EC_CURVE_ID_SECP256R1 23
2432#define SHARKSSL_EC_CURVE_ID_SECP384R1 24
2433#define SHARKSSL_EC_CURVE_ID_SECP521R1 25
2434#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP256R1 26
2435#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP384R1 27
2436#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP512R1 28
2437#define SHARKSSL_EC_CURVE_ID_CURVE25519 29
2438#define SHARKSSL_EC_CURVE_ID_CURVE448 30
2439
2440/* RFC 8734 TLS 1.3 NamedGroup IDs for Brainpool key shares */
2441#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP256R1TLS13 31
2442#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP384R1TLS13 32
2443#define SHARKSSL_EC_CURVE_ID_BRAINPOOLP512R1TLS13 33
2444
2445#define SHARKSSL_X25519_KEY_LEN 32
2446
2447
2448#if (SHARKSSL_ECC_USE_CURVE25519 && SHARKSSL_ENABLE_X25519_API)
2466 U8 privateKey[SHARKSSL_X25519_KEY_LEN],
2467 U8 publicKey[SHARKSSL_X25519_KEY_LEN]);
2468
2469
2483 const U8 privateKey[SHARKSSL_X25519_KEY_LEN],
2484 const U8 peerPublicKey[SHARKSSL_X25519_KEY_LEN],
2485 U8 sharedSecret[SHARKSSL_X25519_KEY_LEN]);
2486#endif
2487
2488
2495typedef U8* SharkSslECCKey;
2496
2497#if SHARKSSL_ENABLE_PEM_API
2523 const char *PEMKey, const char *passphrase);
2524#endif /* SHARKSSL_ENABLE_PEM_API */
2525
2526
2527#if SHARKSSL_ENABLE_ECCKEY_CREATE
2528
2529typedef int (*sharkssl_rngfunc)(void *handle, U8 *ptr, U16 len);
2530
2531
2550#define SharkSslECCKey_create(privKey, curveID) SharkSslECCKey_createEx((privKey), (curveID), 0, 0)
2551
2552
2602SHARKSSL_API int SharkSslECCKey_createEx(SharkSslECCKey *privKey, U16 curveID, void *rngHandle, sharkssl_rngfunc rngFunc);
2603#endif
2604
2605
2606#if (SHARKSSL_ENABLE_PEM_API || SHARKSSL_ENABLE_ECCKEY_CREATE)
2612#define _SHARKSSLECCKEY_FREE 1
2613#endif
2614
2615
2616/*
2617 *-----------------------------------------------------------------------------
2618 * To free up the memory allocated by SharkSslECCKey_create and
2619 * SharkSslRSAKey_create, the following macro is provided
2620 * For instance, this function could be called after saving the key to a file
2621 *-----------------------------------------------------------------------------
2622 * key: input parameter, points to a buffer allocated by either
2623 * SharkSslECCKey_create or SharkSslRSAKey_create
2624 */
2625#if defined(_SHARKSSLRSAKEY_FREE)
2626#define SharkSslKey_free SharkSslRSAKey_free
2627#elif defined (_SHARKSSLECCKEY_FREE)
2628#define SharkSslKey_free SharkSslECCKey_free
2629#else
2630#define SharkSslKey_free
2631#endif
2632#undef _SHARKSSLRSAKEY_FREE
2633#undef _SHARKSSLECCKEY_FREE
2634
2635
2641#if SHARKSSL_ENABLE_ECDSA
2645/* ECDSA API and also internal sharkssl_ECDSA_signASN1 */
2646typedef enum
2647{
2650
2653
2656
2659
2662
2665
2668
2671
2674
2678 /* end group SharkSslInfoAndCodes */
2680
2686#if SHARKSSL_ENABLE_ECDSA_API
2687#if (!SHARKSSL_ECDSA_ONLY_VERIFY)
2696SHARKSSL_API U16 sharkssl_ECDSA_siglen(SharkSslECCKey privkey);
2697
2725 SharkSslECCKey privkey, U8 *sig, U16 *siglen, const U8 *hash, U8 hashID);
2726#endif
2727
2750 SharkSslECCKey pubkey, U8 *sig, U16 siglen, const U8 *hash, U8 hashID);
2751
2752#endif /* SHARKSSL_ENABLE_ECDSA_API */
2753#endif /* SHARKSSL_ENABLE_ECDSA */
2754 /* end group ECC */
2756#endif
2757
2758#if (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA)
2766SHARKSSL_API U16 SharkSslKey_vectSize(const SharkSslKey key);
2767#define SharkSslCert_vectSize(c) SharkSslKey_vectSize((const SharkSslCert)c)
2768#define SharkSslCert_vectSize_keyInfo(c, t, p, a, b, x, y) SharkSslKey_vectSize_keyInfo((const SharkSslKey)c, t, p, a, b, x, y)
2769#if SHARKSSL_ENABLE_RSA
2770#define SharkSslRSAKey_vectSize(k) SharkSslKey_vectSize(k)
2771#define SharkSslRSAKey_vectSize_keyInfo(k, t, p, a, b, x, y) SharkSslKey_vectSize_keyInfo((const SharkSslKey)k, t, p, a, b, x, y)
2772#endif
2773#if SHARKSSL_ENABLE_ECDSA
2774#define SharkSslECCKey_vectSize(k) SharkSslKey_vectSize(k)
2775#define SharkSslECCKey_vectSize_keyInfo(k, t, p, a, b, x, y) SharkSslKey_vectSize_keyInfo((const SharkSslKey)k, t, p, a, b, x, y)
2776#endif
2777
2778/* return values of function SharkSslKey_vectSize_keyInfo for the parameter keyType */
2779#define SHARKSSL_KEYTYPE_RSA 0x00
2780#define SHARKSSL_KEYTYPE_EC 0x02
2781
2797SHARKSSL_API U16 SharkSslKey_vectSize_keyInfo(const SharkSslKey key, U8 *keyType, U8 *isKeyPrivate, U8 **d1, U16 *d1Len, U8 **d2, U16 *d2Len);
2798#endif
2799
2800
2801#if (SHARKSSL_ENABLE_CA_LIST && SHARKSSL_ENABLE_CERTSTORE_API)
2802
2808#ifndef BA_API /* standalone SharkSSL */
2809#define BA_API SHARKSSL_API
2810typedef U8 BaBool;
2811#endif
2812#include "DoubleList.h"
2813
2833typedef struct SharkSslCertStore
2834{
2835 DoubleList certList;
2837 U16 elements; /* number of elements in list */
2839
2849
2853
2855#define SharkSslCertStore_release(o) SharkSslCertStore_destructor(o)
2856
2872SHARKSSL_API U16 SharkSslCertStore_add(
2873 SharkSslCertStore *o, const char *cert, U32 certlen);
2874
2886 SharkSslCertStore *o, SharkSslCAList *outList);
2887 /* end group SharkSslCertApi */
2889#endif /* SHARKSSL_ENABLE_CA_LIST && SHARKSSL_ENABLE_CERTSTORE_API */
2890
2891#if ((SHARKSSL_ENABLE_PEM_API) || (SHARKSSL_ENABLE_CERTSTORE_API))
2892SHARKSSL_API U32 sharkssl_B64Decode(
2893 U8 *outStr, U32 outStrSize, const char *b64beg, const char *b64end);
2894#endif
2895
2896
2897
2898#ifdef __cplusplus
2899}
2900
2902 SharkSsl_Role role, U16 cacheSize, U16 inBufStartSize, U16 outBufSize) {
2904}
2906 SharkSsl_destructor(this);
2907}
2909 return SharkSsl_createCon(this);
2910}
2912 SharkSsl_terminateCon(this, sslCon);
2913}
2914
2915#if (SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA)
2917 return SharkSsl_addCertificate(this, cert);
2918}
2919#if SHARKSSL_ENABLE_CA_LIST
2921 return SharkSsl_setCAListEx(this, list, 0);
2922}
2923inline U8 SharkSsl::setCAListEx(SharkSslCAList list, U32 caListLen) {
2924 return SharkSsl_setCAListEx(this, list, caListLen);
2925}
2926#endif /* SHARKSSL_ENABLE_CA_LIST */
2927#endif /* SHARKSSL_ENABLE_RSA || SHARKSSL_ENABLE_ECDSA */
2928
2929#endif /* __cplusplus */
2930
2931
2932#endif
U16 SharkSslSANLen
Preserve 16-bit Subject Alternative Name lengths unless the configured handshake limit permits a cert...
Definition: SharkSSL.h:664
int(* sharkssl_rngfunc)(void *handle, U8 *ptr, U16 len)
Definition: SharkSSL.h:2529
#define SHARKSSL_X25519_KEY_LEN
Definition: SharkSSL.h:2445
SharkSSL feature defaults and dependency checks.
See Choose a SharkSSL API for build scope and the owning API layer.
uint32_t psa_key_id_t
Definition: crypto.h:60
SHARKSSL_API U16 sharkssl_ECDSA_siglen(SharkSslECCKey privkey)
Returns the maximum length (in bytes) of a DER-encoded ECDSA signature generated with the private key...
SHARKSSL_API sharkssl_ECDSA_RetVal sharkssl_ECDSA_verify_hash(SharkSslECCKey pubkey, U8 *sig, U16 siglen, const U8 *hash, U8 hashID)
Verify a message using the ECC public key and a hash algorithm.
SHARKSSL_API sharkssl_ECDSA_RetVal sharkssl_ECDSA_sign_hash(SharkSslECCKey privkey, U8 *sig, U16 *siglen, const U8 *hash, U8 hashID)
Generate the signature using the ECC private key and a hash.
U8 * SharkSslECCKey
SharkSslECCKey is an alias for the SharkSslCert type and is a private/public key converted by sharkss...
Definition: SharkSSL.h:2495
SHARKSSL_API SharkSslECCKey sharkssl_PEM_to_ECCKey(const char *PEMKey, const char *passphrase)
Convert an ECC private or public key in PEM format to the SharkSslECCKey format.
SHARKSSL_API SharkSslRSAKey sharkssl_PEM_to_RSAKey(const char *PEMKey, const char *passphrase)
Convert an RSA private or public key in PEM format to the SharkSslRSAKey format.
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_PKCS1V1_5_verify_hash(SharkSslRSAKey pubkey, U8 *sig, U16 siglen, const U8 *hash, U8 hashID)
Verify a signature hash using a public RSA key.
SHARKSSL_API SharkSslKey sharkssl_PEM_extractPublicKey(const char *certPEM)
Extract the public key form a certificate in PEM format.
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_private_decrypt_OAEP(SharkSslRSAKey privkey, U8 *in, int len, U8 hashID, U8 *out, const char *label, U16 labelLen)
Decrypt ciphertext using the private key, padding is OAEP per RFC 8017.
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_public_encrypt_OAEP(SharkSslRSAKey pubkey, const U8 *in, int len, U8 hashID, U8 *out, const char *label, U16 labelLen)
Encrypt cleartext using the public key, padding is OAEP per RFC 8017.
SHARKSSL_API void SharkSslRSAKey_free(SharkSslRSAKey key)
Release a SharkSslRSAKey allocated by functions sharkssl_PEM_to_RSAKey and sharkssl_PEM_extractPublic...
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_private_encrypt(SharkSslRSAKey privkey, const U8 *in, int len, U8 *out, int padding)
Sign a message digest using the private key.
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_private_decrypt(SharkSslRSAKey privkey, const U8 *in, int len, U8 *out, int padding)
Decrypt ciphertext using the private key.
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_public_encrypt(SharkSslRSAKey pubkey, const U8 *in, int len, U8 *out, int padding)
Encrypt data using the public key or private key.
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_PKCS1V1_5_sign_hash(SharkSslRSAKey privkey, U8 *sig, U16 *siglen, const U8 *hash, U8 hashID)
Sign a hash using a private RSA key.
SHARKSSL_API sharkssl_RSA_RetVal sharkssl_RSA_public_decrypt(SharkSslRSAKey pubkey, const U8 *in, int len, U8 *out, int padding)
Bring back a message digest using the public key or private key.
U8 * SharkSslRSAKey
SharkSslRSAKey is an alias for the SharkSslCert type and is a private/public key converted by sharkss...
Definition: SharkSSL.h:2100
SHARKSSL_API int sharkssl_PEM_PBKDF2Ex(U8 *dk, const char *passphrase, const char *salt, U32 saltLen, U32 iterations, U16 passphraseLen, U16 dkLen, U8 hashID)
Derive a key with PBKDF2-HMAC using an explicit password length.
sharkssl_PEM_RetVal
Return values from function sharkssl_PEM.
Definition: SharkSSL.h:1828
SHARKSSL_API sharkssl_PEM_RetVal sharkssl_PEMEx(const char *certPEM, const char *keyPEM, const char *passphrase, SharkSslCert *sharkSslCert, U16 passphraseLen)
Convert PEM data using an explicit passphrase length.
SHARKSSL_API int sharkssl_X25519_sharedSecret(const U8 privateKey[SHARKSSL_X25519_KEY_LEN], const U8 peerPublicKey[SHARKSSL_X25519_KEY_LEN], U8 sharedSecret[SHARKSSL_X25519_KEY_LEN])
Calculate an X25519 shared secret.
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 fro...
SHARKSSL_API sharkssl_PEM_RetVal sharkssl_PEM(const char *certPEM, const char *keyPEM, const char *passphrase, SharkSslCert *sharkSslCert)
Create a SharkSslCert from PEM data.
SHARKSSL_API int sharkssl_X25519_createKeyPair(U8 privateKey[SHARKSSL_X25519_KEY_LEN], U8 publicKey[SHARKSSL_X25519_KEY_LEN])
Create an X25519 private/public key pair.
@ SHARKSSL_PEM_CERT_UNSUPPORTED_TYPE
CERT_UNSUPPORTED_TYPE.
Definition: SharkSSL.h:1872
@ SHARKSSL_PEM_KEY_UNSUPPORTED_ENCRYPTION_TYPE
KEY_UNSUPPORTED_ENCRYPTION_TYPE.
Definition: SharkSSL.h:1863
@ SHARKSSL_PEM_OK
OK.
Definition: SharkSSL.h:1830
@ SHARKSSL_PEM_OK_PUBLIC
OK_PUBLIC.
Definition: SharkSSL.h:1833
@ SHARKSSL_PEM_KEY_PRIVATE_KEY_REQUIRED
A PRIVATE KEY IS REQUIRED.
Definition: SharkSSL.h:1881
@ SHARKSSL_PEM_KEY_UNSUPPORTED_EXPONENT_LENGTH
KEY_UNSUPPORTED_EXPONENT_LENGTH.
Definition: SharkSSL.h:1860
@ SHARKSSL_PEM_KEY_UNSUPPORTED_FORMAT
KEY_UNSUPPORTED_FORMAT.
Definition: SharkSSL.h:1854
@ SHARKSSL_PEM_KEY_UNRECOGNIZED_FORMAT
KEY_UNRECOGNIZED_FORMAT.
Definition: SharkSSL.h:1851
@ SHARKSSL_PEM_KEY_UNSUPPORTED_VERSION
KEY_UNSUPPORTED_VERSION.
Definition: SharkSSL.h:1875
@ SHARKSSL_PEM_KEY_PASSPHRASE_REQUIRED
KEY_PASSPHRASE_REQUIRED.
Definition: SharkSSL.h:1848
@ SHARKSSL_PEM_KEY_WRONG_LENGTH
KEY_WRONG_LENGTH.
Definition: SharkSSL.h:1845
@ SHARKSSL_PEM_KEY_PARSE_ERROR
KEY_PARSE_ERROR.
Definition: SharkSSL.h:1839
@ SHARKSSL_PEM_CERT_UNRECOGNIZED_FORMAT
CERT_UNRECOGNIZED_FORMAT.
Definition: SharkSSL.h:1869
@ SHARKSSL_PEM_KEY_REQUIRED
KEY_REQUIRED.
Definition: SharkSSL.h:1878
@ SHARKSSL_PEM_ALLOCATION_ERROR
ALLOCATION_ERROR.
Definition: SharkSSL.h:1836
@ SHARKSSL_PEM_KEY_WRONG_IV
KEY_WRONG_IV.
Definition: SharkSSL.h:1842
@ SHARKSSL_PEM_INTERNAL_ERROR
INTERNAL ERROR.
Definition: SharkSSL.h:1884
@ SHARKSSL_PEM_KEY_CERT_MISMATCH
KEY_CERT_MISMATCH.
Definition: SharkSSL.h:1866
@ SHARKSSL_PEM_KEY_UNSUPPORTED_MODULUS_LENGTH
KEY_UNSUPPORTED_MODULUS_LENGTH.
Definition: SharkSSL.h:1857
U8 SharkSslCon_favorRSA(SharkSslCon *o, U8 flag)
Configures TLS 1.2 cipher-suite selection to favor RSA-authenticated suites when both RSA and ECDSA c...
SHARKSSL_API SharkSslKey sharkssl_PEM_extractPublicKey_ext(const char *certPEM, U8 *keyType)
Extract a SharkSSL key allocation and report its internal key type.
SHARKSSL_API U8 SharkSsl_addCertificate(SharkSsl *o, SharkSslCert cert)
Add a certificate to the SharkSsl object.
SharkSslCon * SharkSsl_createCon(SharkSsl *o)
Create a SharkSslCon object.
SHARKSSL_API U8 SharkSslCon_setCertificateAuthoritiesEx(SharkSslCon *o, const void *caList, U32 caListLen)
Configure the TLS 1.3 Certificate Authorities extension specified in RFC 9846, Section 4....
SHARKSSL_API U8 SharkSslCon_setSNI(SharkSslCon *o, const char *name, U16 length)
set Server Name Indication for TLS client connections
SHARKSSL_API U32 sharkssl_B64Decode(U8 *outStr, U32 outStrSize, const char *b64beg, const char *b64end)
Decode Base64 alphabet characters from a bounded text range.
SHARKSSL_API U16 SharkSslCon_getCiphersuite(SharkSslCon *o)
Returns the active session's chiper suite.
SHARKSSL_API void SharkSsl_destructor(SharkSsl *o)
Close the SharkSsl object.
SHARKSSL_API U8 SharkSslCon_setALPNFunction(SharkSslCon *o, ALPNFunction func, void *pvoid)
Install a server-side application-protocol selection callback.
SHARKSSL_API U8 SharkSsl_addCertificatePSA(SharkSsl *o, SharkSslCert cert, psa_key_id_t psaKey)
Add an RSA, EC, or EdDSA certificate with a provider-owned private signing key.
SHARKSSL_API U8 SharkSslCon_setALPNProtocols(SharkSslCon *o, const char *protList)
This function is used by client solutions to specify a list of application layer protocols according ...
U8 SharkSslCon_certificateRequested(SharkSslCon *o)
Returns TRUE if the server requested a certificate from the client to verify that the client's identi...
SHARKSSL_API U8 SharkSslCon_getProtocol(SharkSslCon *o)
Returns the active session's protocol version.
SHARKSSL_API U8 SharkSslCon_requestClientCertEx(SharkSslCon *o, const void *caList, U32 caListLen)
Request client-certificate authentication.
SHARKSSL_API SharkSslCertInfo * SharkSslCon_getCertInfo(SharkSslCon *o)
Returns the peer's certificate if the handshaking has completed.
SHARKSSL_API U16 SharkSsl_getCacheSize(SharkSsl *o)
Returns the SharkSsl session cache size.
SHARKSSL_API U8 SharkSslCon_selectCiphersuite(SharkSslCon *o, U16 cipherSuite)
This function enables you to limit the number of ciphers at runtime.
void SharkSsl_terminateCon(const SharkSsl *o, SharkSslCon *con)
Terminate a SharkSslCon object created by function SharkSsl_createCon.
SHARKSSL_API void sharkssl_freeObject(void *object)
Release storage obtained from sharkssl_mallocObject.
SHARKSSL_API U8 SharkSslCon_selectCertificatePSA(SharkSslCon *o, SharkSslCert cert)
Select one PSA certificate already registered on this connection's SharkSsl object.
SHARKSSL_API U8 SharkSslCon_clearCiphersuiteSelection(SharkSslCon *o)
Clears the selection, thus enabling all ciphers.
SHARKSSL_API U8 SharkSslCon_trustedCA(SharkSslCon *o)
Returns TRUE if the certificate is valid and is signed with a root certificate trusted by SharkSSL.
U8 SharkSslCon_isCAListEmpty(SharkSslCon *o)
Check whether the connection owner has no CA-list pointer.
U8 SharkSslCon_selectProtocol(SharkSslCon *o, U8 protocol)
Select an enabled TLS protocol before negotiation or resumption.
SHARKSSL_API U8 SharkSsl_setCAListEx(SharkSsl *o, SharkSslCAList caList, U32 caListLen)
Set a Certificate Authority (CA) list so the SharkSSL object can perform certificate validation on th...
SHARKSSL_API U8 SharkSslCon_renegotiate(SharkSslCon *o)
This function enables you to renegotiate an already established SSL/TLS connection.
SHARKSSL_API const char * SharkSslCon_getALPNProtocol(SharkSslCon *o)
This function is used by client solutions to return the application layer protocol selected by the se...
SHARKSSL_API void SharkSsl_constructor(SharkSsl *o, SharkSsl_Role role, U16 cacheSize, U16 inBufStartSize, U16 outBufSize)
A SharkSsl object is the coordinator for managing SharkSslCon objects.
SHARKSSL_API void * sharkssl_mallocObject(size_t size)
Allocate aligned storage for SharkSSL C++ objects.
int(* ALPNFunction)(SharkSslCon *, const char *, void *)
Definition: SharkSSL.h:1750
SHARKSSL_API int SharkSslECCKey_createEx(SharkSslECCKey *privKey, U16 curveID, void *rngHandle, sharkssl_rngfunc rngFunc)
Creates an ECC key using the SharkSSL library.
SHARKSSL_API int SharkSslRSAKey_create(SharkSslRSAKey *privKey, U16 keyLength)
RSA key creation.
SHARKSSL_API int SharkSslASN1Create_CSR(struct SharkSslASN1Create *o, SharkSslKey privKey, U8 hashID, struct SharkSslCertDN *certDN, const char *SAN, struct SharkSslBitExtReq *keyUsage, struct SharkSslBitExtReq *nsCertType)
CSR creation (all parameters are input parameters)
SHARKSSL_API void SharkSslCertStore_constructor(SharkSslCertStore *o)
Initialize a SharkSslCertStore object.
SHARKSSL_API void SharkSslCertStore_destructor(SharkSslCertStore *o)
Cleanup all memory used by the SharkSslCAList object.
SHARKSSL_API int SharkSslASN1Create_key(struct SharkSslASN1Create *o, const SharkSslKey key)
CSR signing policy and SharkSslCert_signCSR are declared in SharkSslCSR.h.
SHARKSSL_API U16 SharkSslKey_vectSize(const SharkSslKey key)
Returns the private or public key's "vector size" in bytes.
SHARKSSL_API U16 SharkSslKey_vectSize_keyInfo(const SharkSslKey key, U8 *keyType, U8 *isKeyPrivate, U8 **d1, U16 *d1Len, U8 **d2, U16 *d2Len)
Returns the private or public key's "vector size" in bytes.
SHARKSSL_API U16 SharkSslCertStore_add(SharkSslCertStore *o, const char *cert, U32 certlen)
Add one or more certificates to the CA store.
SHARKSSL_API U8 SharkSslCertStore_assemble(SharkSslCertStore *o, SharkSslCAList *outList)
Assemble all certificates added by calling SharkSslCertStore_add.
struct SharkSslCertStore SharkSslCertStore
SharkSslCertStore is a container object used when assembling a SharkSslCAList.
SHARKSSL_API int SharkSslCertInfo_parseCert(SharkSslCertInfo *o, const U8 *der, U32 len)
Parse a DER certificate and return its certificate information.
SHARKSSL_API void SharkSslECCKey_free(SharkSslECCKey key)
Release a SharkSslECCKey allocated by functions sharkssl_PEM_to_ECCKey or SharkSslECCKey_create.
SHARKSSL_API U16 SharkSslRSAKey_size(SharkSslRSAKey key)
Returns the private or public key's modulus size in bytes.
SHARKSSL_API U16 SharkSslCert_len(SharkSslCert cert)
Get certificate length.
SHARKSSL_API U8 * SharkSslRSAKey_getPublic(SharkSslRSAKey privKey)
RSA public key extraction from a private key.
struct SharkSslCertInfo SharkSslCertInfo
The peer's certificate information returned by SharkSslCon_getCertInfo.
struct SharkSslCertDN SharkSslCertDN
Certificate KeyUsage and ExtendedKeyUsage flags and relative pseudofunctions.
U8 * SharkSslCon_getEncData(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_Encrypted returned by function SharkSslCo...
U16 SharkSslCon_getHandshakeDataLen(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_Handshake returned by function SharkSslCo...
U16 SharkSslCon_getEncDataLen(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_Encrypted returned by function SharkSslCo...
U16 SharkSslCon_getBufLen(SharkSslCon *o)
Returns the number of bytes currently available at the pointer returned by SharkSslCon_getBuf.
SHARKSSL_API U8 SharkSslCon_keyUpdate(SharkSslCon *o, U8 requestUpdate)
Creates a TLS 1.3 KeyUpdate message and advances the local write keys.
SharkSslCon_RetVal
The SharkSslCon_decrypt and SharkSslCon_encrypt return values.
Definition: SharkSSL.h:561
SharkSslCon_RetVal SharkSslCon_decrypt(SharkSslCon *o, U16 readLen)
Decrypt the received data copied into the SharkSslCon receive buffer (the buffer returned by SharkSsl...
U16 SharkSslCon_getEncBufSize(SharkSslCon *o)
Returns the length of the buffer returned by SharkSslCon_getEncBufPtr.
U8 SharkSslCon_encryptMore(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_Encrypted returned by function SharkSslCo...
U8 SharkSslCon_decryptMore(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_Decrypted returned by function SharkSslCo...
U8 * SharkSslCon_getBuf(SharkSslCon *o)
Returns a pointer to the SharkSslCon input/receive buffer.
SHARKSSL_API U16 SharkSslCon_getDecData(SharkSslCon *o, U8 **bufPtr)
Get a pointer to the decoded data.
U8 SharkSslCon_getAlertLevel(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_AlertSend returned by function SharkSslCo...
U16 SharkSslCon_copyDecData(SharkSslCon *o, U8 *buf, U16 maxLen)
Copy decoded data to 'buf'.
SHARKSSL_API int SharkSslCon_proactiveKeyUpdate(SharkSslCon *o)
Apply the automatic AES-GCM KeyUpdate policy while the output buffer is free.
U8 * SharkSslCon_getEncBufPtr(SharkSslCon *o)
This function is used in conjunction with SharkSslCon_encrypt when using the zero copy send API.
U16 SharkSslCon_setHandshakeDataSent(SharkSslCon *o, U16 length)
This function is used in conjunction with SharkSslCon_getHandshakeData.
U8 SharkSslCon_getAlertDescription(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_AlertSend returned by function SharkSslCo...
U8 SharkSslCon_isHandshakeComplete(SharkSslCon *o)
Returns the following values:
U8 * SharkSslCon_getHandshakeData(SharkSslCon *o)
This function is used in conjunction with state SharkSslCon_Handshake returned by function SharkSslCo...
SharkSslCon_RetVal SharkSslCon_encrypt(SharkSslCon *o, U8 *buf, U16 maxLen)
Encrypt the data provided by parameter 'buf' or encrypt data in the SharkSslCon send buffer.
SHARKSSL_API SharkSslCon_RetVal SharkSslCon_close(SharkSslCon *o)
Generates a close_notify alert and closes the local write direction.
@ SharkSslCon_Encrypted
SharkSSL has successfully decrypted a chunk of data.
Definition: SharkSSL.h:641
@ SharkSslCon_Decrypted
Returned when a block of received data has been successfully decrypted.
Definition: SharkSSL.h:579
@ SharkSslCon_AlertSend
Returned when an SSL/TLS alert message must be sent to the peer side.
Definition: SharkSSL.h:620
@ SharkSslCon_AllocationError
The memory pool is too small.
Definition: SharkSSL.h:568
@ SharkSslCon_Error
Indicates general errors, including configuration errors.
Definition: SharkSSL.h:564
@ SharkSslCon_CertificateError
Unrecognized format of a provided certificate.
Definition: SharkSSL.h:651
@ SharkSslCon_AlertRecv
SharkSSL received an SSL/TLS alert message from the peer, which means that the peer either failed to ...
Definition: SharkSSL.h:629
@ SharkSslCon_HandshakeNotComplete
An error condition returned by function SharkSslCon_encrypt if the SSL handshake is not completed.
Definition: SharkSSL.h:647
@ SharkSslCon_Handshake
Returned when an SSL/TLS handshake message has been received or is to be sent.
Definition: SharkSSL.h:593
@ SharkSslCon_NeedMoreData
Returned when SharkSSL holds an incomplete SSL/TLS record or when the connection is initially establi...
Definition: SharkSSL.h:606
U32 baGetUnixTime(void)
Platform dependent function returning seconds since Jan 1 1970.
struct SharkSsl SharkSsl
A SharkSsl object is the coordinator for managing SharkSslCon objects (See SharkSsl_constructor for d...
const U8 * SharkSslCert
The SharkSSL Certificate is in a binary format optimized for speed and size.
Definition: SharkSSL.h:326
const U8 * SharkSslCAList
The SharkSSL Certificate Authority (CA) List is in a binary format optimized for speed and size.
Definition: SharkSSL.h:448
struct SharkSslCon SharkSslCon
SharkSslCon is an opaque handle returned by function SharkSsl_createCon.
Definition: SharkSSL.h:495
SharkSsl_Role
Select one of client or server mode when creating a SharkSsl object.
Definition: SharkSSL.h:301
sharkssl_ECDSA_RetVal
Return values from functions sharkssl_ECDSA_sign_hash, sharkssl_ECDSA_verify_hash.
Definition: SharkSSL.h:2647
sharkssl_RSA_RetVal
Return values from functions sharkssl_RSA_public_encrypt, sharkssl_RSA_private_decrypt,...
Definition: SharkSSL.h:2044
U8 * SharkSslKey
The SharkSslKey type.
Definition: SharkSSL.h:318
@ SharkSsl_Unspecified
Definition: SharkSSL.h:302
@ SharkSsl_Client
Definition: SharkSSL.h:304
@ SharkSsl_Server
Definition: SharkSSL.h:303
@ SHARKSSL_ECDSA_ALLOCATION_ERROR
ALLOCATION_ERROR.
Definition: SharkSSL.h:2652
@ SHARKSSL_ECDSA_WRONG_KEY_FORMAT
WRONG_KEY_FORMAT.
Definition: SharkSSL.h:2661
@ SHARKSSL_ECDSA_WRONG_SIGNATURE
WRONG SIGNATURE.
Definition: SharkSSL.h:2676
@ SHARKSSL_ECDSA_WRONG_PARAMETERS
WRONG_PARAMETERS.
Definition: SharkSSL.h:2658
@ SHARKSSL_ECDSA_OK
OK.
Definition: SharkSSL.h:2649
@ SHARKSSL_ECDSA_VERIFICATION_FAIL
VERIFICATION_FAIL.
Definition: SharkSSL.h:2673
@ SHARKSSL_ECDSA_INTERNAL_ERROR
INTERNAL_ERROR.
Definition: SharkSSL.h:2655
@ SHARKSSL_ECDSA_KEY_NOT_PRIVATE
KEY_IS_NOT_PRIVATE.
Definition: SharkSSL.h:2664
@ SHARKSSL_ECDSA_KEY_NOT_PUBLIC
KEY_IS_NOT_PUBLIC.
Definition: SharkSSL.h:2667
@ SHARKSSL_ECDSA_SIGLEN_TOO_SMALL
SIGLEN_TOO_SMALL.
Definition: SharkSSL.h:2670
@ SHARKSSL_RSA_INPUT_DATA_LENGTH_TOO_BIG
INPUT_DATA_LENGTH_TOO_BIG.
Definition: SharkSSL.h:2064
@ SHARKSSL_RSA_WRONG_LABEL_LENGTH
WRONG_LABEL_LENGTH.
Definition: SharkSSL.h:2082
@ SHARKSSL_RSA_OK
OK.
Definition: SharkSSL.h:2046
@ SHARKSSL_RSA_INTERNAL_ERROR
INTERNAL_ERROR.
Definition: SharkSSL.h:2052
@ SHARKSSL_RSA_WRONG_PARAMETERS
WRONG_PARAMETERS.
Definition: SharkSSL.h:2055
@ SHARKSSL_RSA_WRONG_SIGNATURE
WRONG SIGNATURE.
Definition: SharkSSL.h:2079
@ SHARKSSL_RSA_ALLOCATION_ERROR
ALLOCATION_ERROR.
Definition: SharkSSL.h:2049
@ SHARKSSL_RSA_WRONG_KEY_FORMAT
WRONG_KEY_FORMAT.
Definition: SharkSSL.h:2058
@ SHARKSSL_RSA_PKCS1_PADDING_ERROR
PKCS1_PADDING_ERROR.
Definition: SharkSSL.h:2070
@ SHARKSSL_RSA_INPUT_DATA_LENGTH_AND_KEY_LENGTH_MISMATCH
INPUT_DATA_LENGTH_AND_KEY_LENGTH_MISMATCH.
Definition: SharkSSL.h:2067
@ SHARKSSL_RSA_WRONG_KEY_LENGTH
WRONG_KEY_LENGTH.
Definition: SharkSSL.h:2061
@ SHARKSSL_RSA_VERIFICATION_FAIL
VERIFICATION FAIL.
Definition: SharkSSL.h:2076
@ SHARKSSL_RSA_KEY_NOT_PRIVATE
KEY_IS_NOT_PRIVATE.
Definition: SharkSSL.h:2073
SHARKSSL_API SharkSslSession * SharkSslCon_acquireSession(SharkSslCon *o)
Request a SharkSslSession object from the client's session pool.
struct SharkSslSession SharkSslSession
SharkSslSession is an opaque handle returned by function SharkSslCon_acquireSession.
Definition: SharkSSL.h:274
SHARKSSL_API U8 SharkSslSession_release(SharkSslSession *o, SharkSsl *s)
Release a session created by function SharkSslCon_acquireSession.
SHARKSSL_API U8 SharkSslCon_resumeSession(SharkSslCon *o, SharkSslSession *s)
Resume an existing session.
SHARKSSL_API U32 SharkSslSession_getLatestAccessTime(SharkSslSession *o)
Returns the last time the session was accessed.
SHARKSSL_API U8 SharkSslCon_releaseSession(SharkSslCon *o)
experimental
SHARKSSL_API U8 SharkSslCon_isResumed(SharkSslCon *o)
Returns 1 if the current session is a resumed one.
Opaque object used when creating ASN.1 encoded data.
Definition: SharkSslASN1.h:255
Requested one-byte extension bit mask for CSR creation.
Definition: SharkSslASN1.h:268
Certificate KeyUsage and ExtendedKeyUsage flags and relative pseudofunctions.
Definition: SharkSSL.h:738
U8 unitLen
length in bytes of the field "organization"
Definition: SharkSSL.h:754
U8 provinceLen
length in bytes of the field "country"
Definition: SharkSSL.h:751
const U8 * province
State or Province.
Definition: SharkSSL.h:740
U8 localityLen
length in bytes of the field "province"
Definition: SharkSSL.h:752
const U8 * unit
Organizational Unit (OU: department or organization unit)
Definition: SharkSSL.h:743
const U8 * organization
Organization Name (company or department)
Definition: SharkSSL.h:742
const U8 * commonName
Common Name is the Host + Domain Name (example: www.mycompany.com, where www is host and mycompany....
Definition: SharkSSL.h:747
const U8 * countryName
ISO3166 country code.
Definition: SharkSSL.h:739
U8 organizationLen
length in bytes of the field "locality"
Definition: SharkSSL.h:753
U8 commonNameLen
length in bytes of the field "unit"
Definition: SharkSSL.h:755
const U8 * locality
The city or town name.
Definition: SharkSSL.h:741
U8 countryNameLen
Definition: SharkSSL.h:750
U8 emailAddressLen
length in bytes of the field "common name"
Definition: SharkSSL.h:756
const U8 * emailAddress
Definition: SharkSSL.h:748
The peer's certificate information returned by SharkSslCon_getCertInfo.
Definition: SharkSSL.h:796
U8 timeFromLen
Length of 'timeFrom'.
Definition: SharkSSL.h:852
U8 timeToLen
Length of 'timeTo'.
Definition: SharkSSL.h:855
U16 snLen
Length of 'sn' (serial number)
Definition: SharkSSL.h:798
U8 * timeTo
Certificate expiration date (in Time format: [YY]YYMMDDHHMMSSZ) UTCTime: 2-digit year; GeneralizedTim...
Definition: SharkSSL.h:823
U8 CAflag
The Certificate Authority flag (CA) is set to one if the certificate is a CA i.e.
Definition: SharkSSL.h:808
SharkSslSANLen subjectAltNamesLen
Definition: SharkSSL.h:849
SharkSslCertDN issuer
The entity who has signed and issued the certificate (RFC 2459 4.1.2.4)
Definition: SharkSSL.h:829
SharkSslCertDN subject
The entity associated with the public key (RFC 2459 4.1.2.6).
Definition: SharkSSL.h:835
U8 * sn
Binary serial number.
Definition: SharkSSL.h:812
U8 * timeFrom
Certificate is valid from date (in Time format: [YY]YYMMDDHHMMSSZ) UTCTime: 2-digit year; Generalized...
Definition: SharkSSL.h:817
U8 * subjectAltNamesPtr
Subject Alternative Names subjectAltNamesPtr is a pointer to an ASN1 sequence, whose length is subjec...
Definition: SharkSSL.h:848
struct SharkSslCertInfo * parent
Pointer to parent node when the SharkSslCertInfo object is part of a certificate chain.
Definition: SharkSSL.h:886
U8 version
Certificate version is offset at 0 so add +1 for actual version number.
Definition: SharkSSL.h:803
SharkSslCertStore is a container object used when assembling a SharkSslCAList.
Definition: SharkSSL.h:2834
SharkSslCAList caList
Definition: SharkSSL.h:2836
DoubleList certList
Definition: SharkSSL.h:2835
U16 elements
Definition: SharkSSL.h:2837
A SharkSsl object is the coordinator for managing SharkSslCon objects (See SharkSsl_constructor for d...
Definition: SharkSSL.h:511
U16 outBufSize
Definition: SharkSSL.h:536
SingleList certList
Definition: SharkSSL.h:540
U8 addCertificate(SharkSslCert cert)
Definition: SharkSSL.h:2916
SharkSslCAList caList
Definition: SharkSSL.h:542
U16 inBufStartSize
Definition: SharkSSL.h:537
U16 nCon
Definition: SharkSSL.h:538
U8 setCAListEx(SharkSslCAList list, U32 caListLen)
Definition: SharkSSL.h:2923
SharkSslCon * createCon(void)
Definition: SharkSSL.h:2908
U8 setCAList(SharkSslCAList list)
Definition: SharkSSL.h:2920
SharkSsl()
Definition: SharkSSL.h:518
SharkSslSessionCache sessionCache
Definition: SharkSSL.h:546
SharkSsl_Role role
Definition: SharkSSL.h:534
SharkSslIntf * intf
Definition: SharkSSL.h:548
~SharkSsl()
Definition: SharkSSL.h:2905
void terminateCon(SharkSslCon *sslCon)
Definition: SharkSSL.h:2911