Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"en-US,en;q\u003d0.5", "gen_ut":1600810112, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"c1d8de668dce774d89b3f4badae2b46c", "oid":{ "oid": "9bff4d84eddb7f793c04947c259a948523641920", "alias": [ "refs/heads/master"]},"blobname": "include/libwebsockets/lws-genec.h", "blob": "/*\n * libwebsockets - small server side websockets and web server implementation\n *\n * Copyright (C) 2010 - 2019 Andy Green \u003candy@warmcat.com\u003e\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \u0022Software\u0022), to\n * deal in the Software without restriction, including without limitation the\n * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n * sell copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \u0022AS IS\u0022, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n * IN THE SOFTWARE.\n */\n\nenum enum_genec_alg {\n\tLEGENEC_UNKNOWN,\n\n\tLEGENEC_ECDH,\n\tLEGENEC_ECDSA\n};\n\nstruct lws_genec_ctx {\n#if defined(LWS_WITH_MBEDTLS)\n\tunion {\n\t\tmbedtls_ecdh_context *ctx_ecdh;\n\t\tmbedtls_ecdsa_context *ctx_ecdsa;\n\t} u;\n#else\n\tEVP_PKEY_CTX *ctx[2];\n#endif\n\tstruct lws_context *context;\n\tconst struct lws_ec_curves *curve_table;\n\tenum enum_genec_alg genec_alg;\n\n\tchar has_private;\n};\n\n#if defined(LWS_WITH_MBEDTLS)\nenum enum_lws_dh_side {\n\tLDHS_OURS \u003d MBEDTLS_ECDH_OURS,\n\tLDHS_THEIRS \u003d MBEDTLS_ECDH_THEIRS\n};\n#else\nenum enum_lws_dh_side {\n\tLDHS_OURS,\n\tLDHS_THEIRS\n};\n#endif\n\nstruct lws_ec_curves {\n\tconst char *name;\n\tint tls_lib_nid;\n\tuint16_t key_bytes;\n};\n\n\n/* ECDH-specific apis */\n\n/** lws_genecdh_create() - Create a genecdh\n *\n * \u005cparam ctx: your genec context\n * \u005cparam context: your lws_context (for RNG access)\n * \u005cparam curve_table: NULL, enabling P-256, P-384 and P-521, or a replacement\n *\t\t struct lws_ec_curves array, terminated by an entry with\n *\t\t .name \u003d NULL, of curves you want to whitelist\n *\n * Initializes a genecdh\n */\nLWS_VISIBLE int\nlws_genecdh_create(struct lws_genec_ctx *ctx, struct lws_context *context,\n\t\t const struct lws_ec_curves *curve_table);\n\n/** lws_genecdh_set_key() - Apply an EC key to our or theirs side\n *\n * \u005cparam ctx: your genecdh context\n * \u005cparam el: your key elements\n * \u005cparam side: LDHS_OURS or LDHS_THEIRS\n *\n * Applies an EC key to one side or the other of an ECDH ctx\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_genecdh_set_key(struct lws_genec_ctx *ctx, struct lws_gencrypto_keyelem *el,\n\t\t enum enum_lws_dh_side side);\n\n/** lws_genecdh_new_keypair() - Create a genec with a new public / private key\n *\n * \u005cparam ctx: your genec context\n * \u005cparam side: LDHS_OURS or LDHS_THEIRS\n * \u005cparam curve_name: an EC curve name, like \u0022P-256\u0022\n * \u005cparam el: array pf LWS_GENCRYPTO_EC_KEYEL_COUNT key elems to take the new key\n *\n * Creates a genecdh with a newly minted EC public / private key\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_genecdh_new_keypair(struct lws_genec_ctx *ctx, enum enum_lws_dh_side side,\n\t\t const char *curve_name, struct lws_gencrypto_keyelem *el);\n\nLWS_VISIBLE LWS_EXTERN int\nlws_genecdh_compute_shared_secret(struct lws_genec_ctx *ctx, uint8_t *ss,\n\t\t int *ss_len);\n\n\n/* ECDSA-specific apis */\n\n/** lws_genecdsa_create() - Create a genecdsa and\n *\n * \u005cparam ctx: your genec context\n * \u005cparam context: your lws_context (for RNG access)\n * \u005cparam curve_table: NULL, enabling P-256, P-384 and P-521, or a replacement\n *\t\t struct lws_ec_curves array, terminated by an entry with\n *\t\t .name \u003d NULL, of curves you want to whitelist\n *\n * Initializes a genecdh\n */\nLWS_VISIBLE int\nlws_genecdsa_create(struct lws_genec_ctx *ctx, struct lws_context *context,\n\t\t const struct lws_ec_curves *curve_table);\n\n/** lws_genecdsa_new_keypair() - Create a genecdsa with a new public / private key\n *\n * \u005cparam ctx: your genec context\n * \u005cparam curve_name: an EC curve name, like \u0022P-256\u0022\n * \u005cparam el: array pf LWS_GENCRYPTO_EC_KEYEL_COUNT key elements to take the new key\n *\n * Creates a genecdsa with a newly minted EC public / private key\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_genecdsa_new_keypair(struct lws_genec_ctx *ctx, const char *curve_name,\n\t\t\t struct lws_gencrypto_keyelem *el);\n\n/** lws_genecdsa_set_key() - Apply an EC key to an ecdsa context\n *\n * \u005cparam ctx: your genecdsa context\n * \u005cparam el: your key elements\n *\n * Applies an EC key to an ecdsa context\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_genecdsa_set_key(struct lws_genec_ctx *ctx,\n\t\t struct lws_gencrypto_keyelem *el);\n\n/** lws_genecdsa_hash_sig_verify_jws() - Verifies a JWS ECDSA signature on a given hash\n *\n * \u005cparam ctx: your struct lws_genrsa_ctx\n * \u005cparam in: unencrypted payload (usually a recomputed hash)\n * \u005cparam hash_type: one of LWS_GENHASH_TYPE_\n * \u005cparam keybits: number of bits in the crypto key\n * \u005cparam sig: pointer to the signature we received with the payload\n * \u005cparam sig_len: length of the signature we are checking in bytes\n *\n * This just looks at the signed hash... that's why there's no input length\n * parameter, it's decided by the choice of hash. It's up to you to confirm\n * separately the actual payload matches the hash that was confirmed by this to\n * be validly signed.\n *\n * Returns \u003c0 for error, or 0 if signature matches the hash + key..\n *\n * The JWS ECDSA signature verification algorithm differs to generic ECDSA\n * signatures and they're not interoperable.\n *\n * This and related APIs operate identically with OpenSSL or mbedTLS backends.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_genecdsa_hash_sig_verify_jws(struct lws_genec_ctx *ctx, const uint8_t *in,\n\t\t\t\t enum lws_genhash_types hash_type, int keybits,\n\t\t\t\t const uint8_t *sig, size_t sig_len);\n\n/** lws_genecdsa_hash_sign_jws() - Creates a JWS ECDSA signature for a hash you provide\n *\n * \u005cparam ctx: your struct lws_genrsa_ctx\n * \u005cparam in: precomputed hash\n * \u005cparam hash_type: one of LWS_GENHASH_TYPE_\n * \u005cparam keybits: number of bits in the crypto key\n * \u005cparam sig: pointer to buffer to take signature\n * \u005cparam sig_len: length of the buffer (must be \u003e\u003d length of key N)\n *\n * Returns \u003c0 for error, or 0 for success.\n *\n * This creates a JWS ECDSA signature for a hash you already computed and provide.\n *\n * The JWS ECDSA signature generation algorithm differs to generic ECDSA\n * signatures and they're not interoperable.\n *\n * This and related APIs operate identically with OpenSSL or mbedTLS backends.\n */\nLWS_VISIBLE LWS_EXTERN int\nlws_genecdsa_hash_sign_jws(struct lws_genec_ctx *ctx, const uint8_t *in,\n\t\t\t enum lws_genhash_types hash_type, int keybits,\n\t\t\t uint8_t *sig, size_t sig_len);\n\n\n/* Apis that apply to both ECDH and ECDSA */\n\nLWS_VISIBLE LWS_EXTERN void\nlws_genec_destroy(struct lws_genec_ctx *ctx);\n\nLWS_VISIBLE LWS_EXTERN void\nlws_genec_destroy_elements(struct lws_gencrypto_keyelem *el);\n\nLWS_VISIBLE LWS_EXTERN int\nlws_genec_dump(struct lws_gencrypto_keyelem *el);\n","s":{"c":1600810112,"u": 429}} ],"g": 2896,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 1, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}