/*1* Copyright (c) 2016 Thomas Pornin <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining4* a copy of this software and associated documentation files (the5* "Software"), to deal in the Software without restriction, including6* without limitation the rights to use, copy, modify, merge, publish,7* distribute, sublicense, and/or sell copies of the Software, and to8* permit persons to whom the Software is furnished to do so, subject to9* the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*/2324#ifndef BR_BEARSSL_H__25#define BR_BEARSSL_H__2627#include <stddef.h>28#include <stdint.h>2930/** \mainpage BearSSL API31*32* # API Layout33*34* The functions and structures defined by the BearSSL API are located35* in various header files:36*37* | Header file | Elements |38* | :-------------- | :------------------------------------------------ |39* | bearssl_hash.h | Hash functions |40* | bearssl_hmac.h | HMAC |41* | bearssl_kdf.h | Key Derivation Functions |42* | bearssl_rand.h | Pseudorandom byte generators |43* | bearssl_prf.h | PRF implementations (for SSL/TLS) |44* | bearssl_block.h | Symmetric encryption |45* | bearssl_aead.h | AEAD algorithms (combined encryption + MAC) |46* | bearssl_rsa.h | RSA encryption and signatures |47* | bearssl_ec.h | Elliptic curves support (including ECDSA) |48* | bearssl_ssl.h | SSL/TLS engine interface |49* | bearssl_x509.h | X.509 certificate decoding and validation |50* | bearssl_pem.h | Base64/PEM decoding support functions |51*52* Applications using BearSSL are supposed to simply include `bearssl.h`53* as follows:54*55* #include <bearssl.h>56*57* The `bearssl.h` file itself includes all the other header files. It is58* possible to include specific header files, but it has no practical59* advantage for the application. The API is separated into separate60* header files only for documentation convenience.61*62*63* # Conventions64*65* ## MUST and SHALL66*67* In all descriptions, the usual "MUST", "SHALL", "MAY",... terminology68* is used. Failure to meet requirements expressed with a "MUST" or69* "SHALL" implies undefined behaviour, which means that segmentation70* faults, buffer overflows, and other similar adverse events, may occur.71*72* In general, BearSSL is not very forgiving of programming errors, and73* does not include much failsafes or error reporting when the problem74* does not arise from external transient conditions, and can be fixed75* only in the application code. This is done so in order to make the76* total code footprint lighter.77*78*79* ## `NULL` values80*81* Function parameters with a pointer type shall not be `NULL` unless82* explicitly authorised by the documentation. As an exception, when83* the pointer aims at a sequence of bytes and is accompanied with84* a length parameter, and the length is zero (meaning that there is85* no byte at all to retrieve), then the pointer may be `NULL` even if86* not explicitly allowed.87*88*89* ## Memory Allocation90*91* BearSSL does not perform dynamic memory allocation. This implies that92* for any functionality that requires a non-transient state, the caller93* is responsible for allocating the relevant context structure. Such94* allocation can be done in any appropriate area, including static data95* segments, the heap, and the stack, provided that proper alignment is96* respected. The header files define these context structures97* (including size and contents), so the C compiler should handle98* alignment automatically.99*100* Since there is no dynamic resource allocation, there is also nothing to101* release. When the calling code is done with a BearSSL feature, it102* may simple release the context structures it allocated itself, with103* no "close function" to call. If the context structures were allocated104* on the stack (as local variables), then even that release operation is105* implicit.106*107*108* ## Structure Contents109*110* Except when explicitly indicated, structure contents are opaque: they111* are included in the header files so that calling code may know the112* structure sizes and alignment requirements, but callers SHALL NOT113* access individual fields directly. For fields that are supposed to114* be read from or written to, the API defines accessor functions (the115* simplest of these accessor functions are defined as `static inline`116* functions, and the C compiler will optimise them away).117*118*119* # API Usage120*121* BearSSL usage for running a SSL/TLS client or server is described122* on the [BearSSL Web site](https://www.bearssl.org/api1.html). The123* BearSSL source archive also comes with sample code.124*/125126#include "bearssl_hash.h"127#include "bearssl_hmac.h"128#include "bearssl_kdf.h"129#include "bearssl_rand.h"130#include "bearssl_prf.h"131#include "bearssl_block.h"132#include "bearssl_aead.h"133#include "bearssl_rsa.h"134#include "bearssl_ec.h"135#include "bearssl_ssl.h"136#include "bearssl_x509.h"137#include "bearssl_pem.h"138139#ifdef __cplusplus140extern "C" {141#endif142143/** \brief Type for a configuration option.144*145* A "configuration option" is a value that is selected when the BearSSL146* library itself is compiled. Most options are boolean; their value is147* then either 1 (option is enabled) or 0 (option is disabled). Some148* values have other integer values. Option names correspond to macro149* names. Some of the options can be explicitly set in the internal150* `"config.h"` file.151*/152typedef struct {153/** \brief Configurable option name. */154const char *name;155/** \brief Configurable option value. */156long value;157} br_config_option;158159/** \brief Get configuration report.160*161* This function returns compiled configuration options, each as a162* 'long' value. Names match internal macro names, in particular those163* that can be set in the `"config.h"` inner file. For boolean options,164* the numerical value is 1 if enabled, 0 if disabled. For maximum165* key sizes, values are expressed in bits.166*167* The returned array is terminated by an entry whose `name` is `NULL`.168*169* \return the configuration report.170*/171const br_config_option *br_get_config(void);172173/* ======================================================================= */174175/** \brief Version feature: support for time callback. */176#define BR_FEATURE_X509_TIME_CALLBACK 1177178#ifdef __cplusplus179}180#endif181182#endif183184185