cosmopolitan/third_party/mbedtls/hmac_drbg.h
Justine Tunney cc1920749e Add SSL to redbean
Your redbean can now interoperate with clients that require TLS crypto.
This is accomplished using a protocol polyglot that lets us distinguish
between HTTP and HTTPS regardless of the port number. Certificates will
be generated automatically, if none are supplied by the user. Footprint
increases by only a few hundred kb so redbean in MODY=tiny is now 1.0mb

- Add lseek() polyfills for ZIP executable
- Automatically polyfill /tmp/FOO paths on NT
- Fix readdir() / ftw() / nftw() bugs on Windows
- Introduce -B flag for slower SSL that's stronger
- Remove mbedtls features Cosmopolitan doesn't need
- Have base64 decoder support the uri-safe alternative
- Remove Truncated HMAC because it's forbidden by the IETF
- Add all the mbedtls test suites and make them go 3x faster
- Support opendir() / readdir() / closedir() on ZIP executable
- Use Everest for ECDHE-ECDSA because it's so good it's so good
- Add tinier implementation of sha1 since it's not worth the rom
- Add chi-square monte-carlo mean correlation tests for getrandom()
- Source entropy on Windows from the proper interface everyone uses

We're continuing to outperform NGINX and other servers on raw message
throughput. Using SSL means that instead of 1,000,000 qps you can get
around 300,000 qps. However redbean isn't as fast as NGINX yet at SSL
handshakes, since redbean can do 2,627 per second and NGINX does 4.3k

Right now, the SSL UX story works best if you give your redbean a key
signing key since that can be easily generated by openssl using a one
liner then redbean will do all the things that are impossibly hard to
do like signing ecdsa and rsa certificates that'll work in chrome. We
should integrate the let's encrypt acme protocol in the future.

Live Demo: https://redbean.justine.lol/
Root Cert: https://redbean.justine.lol/redbean1.crt
2021-06-24 13:20:50 -07:00

60 lines
2.9 KiB
C

#ifndef MBEDTLS_HMAC_DRBG_H_
#define MBEDTLS_HMAC_DRBG_H_
#include "third_party/mbedtls/config.h"
#include "third_party/mbedtls/md.h"
COSMOPOLITAN_C_START_
/* clang-format off */
#define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003 /**< Too many random requested in single call. */
#define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005 /**< Input too large (Entropy + additional). */
#define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007 /**< Read/write error in file. */
#define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009 /**< The entropy source failed. */
#if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
#define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */
#endif
#if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
#define MBEDTLS_HMAC_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */
#endif
#if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
#define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */
#endif
#if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
#define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */
#endif
#define MBEDTLS_HMAC_DRBG_PR_OFF 0 /**< No prediction resistance */
#define MBEDTLS_HMAC_DRBG_PR_ON 1 /**< Prediction resistance enabled */
typedef struct mbedtls_hmac_drbg_context
{
mbedtls_md_context_t md_ctx;
unsigned char V[MBEDTLS_MD_MAX_SIZE];
int reseed_counter;
size_t entropy_len;
int prediction_resistance;
int reseed_interval;
int (*f_entropy)(void *, unsigned char *, size_t);
void *p_entropy;
} mbedtls_hmac_drbg_context;
void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context * );
int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *, const mbedtls_md_info_t * , int (*)(void *, unsigned char *, size_t), void *, const unsigned char *, size_t );
int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *, const mbedtls_md_info_t *, const unsigned char *, size_t );
void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *, int );
void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *, size_t );
void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *, int );
int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *, const unsigned char *, size_t );
int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *, const unsigned char *, size_t );
int mbedtls_hmac_drbg_random_with_add( void *, unsigned char *, size_t , const unsigned char *, size_t );
int mbedtls_hmac_drbg_random( void *, unsigned char *, size_t );
void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context * );
int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *, const char * );
int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *, const char * );
int mbedtls_hmac_drbg_self_test( int );
COSMOPOLITAN_C_END_
#endif /* MBEDTLS_HMAC_DRBG_H_ */