mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00

!!! WIP This implements the "genec" layer wrapping mbedtls + openssl ECDH support. API tests are added for the parts that are implemented so far. Stuff related to ec at all, like keys, are prefixed lws_genec_. Stuff specific to ECDH are prefixed lws_genecdh_.
59 lines
1.5 KiB
C
59 lines
1.5 KiB
C
/*
|
|
* libwebsockets - generic crypto api hiding the backend
|
|
*
|
|
* Copyright (C) 2017 - 2018 Andy Green <andy@warmcat.com>
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation:
|
|
* version 2.1 of the License.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
* MA 02110-1301 USA
|
|
*
|
|
* lws-gencrypto openssl-specific common code
|
|
*/
|
|
|
|
#include "core/private.h"
|
|
#include "tls/mbedtls/private.h"
|
|
|
|
mbedtls_md_type_t
|
|
lws_gencrypto_mbedtls_hash_to_MD_TYPE(enum lws_genhash_types hash_type)
|
|
{
|
|
mbedtls_md_type_t h = -1;
|
|
|
|
switch (hash_type) {
|
|
case LWS_GENHASH_TYPE_SHA1:
|
|
h = MBEDTLS_MD_SHA1;
|
|
break;
|
|
case LWS_GENHASH_TYPE_SHA256:
|
|
h = MBEDTLS_MD_SHA256;
|
|
break;
|
|
case LWS_GENHASH_TYPE_SHA384:
|
|
h = MBEDTLS_MD_SHA384;
|
|
break;
|
|
case LWS_GENHASH_TYPE_SHA512:
|
|
h = MBEDTLS_MD_SHA512;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return h;
|
|
}
|
|
|
|
int
|
|
lws_gencrypto_mbedtls_rngf(void *context, unsigned char *buf, size_t len)
|
|
{
|
|
if ((size_t)lws_get_random(context, buf, len) == len)
|
|
return 0;
|
|
|
|
return -1;
|
|
}
|