1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00
libwebsockets/lib/tls/mbedtls/lws-gencrypto.c

65 lines
1.6 KiB
C
Raw Normal View History

/*
* 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) {
2019-07-17 13:09:40 -07:00
case LWS_GENHASH_TYPE_MD5:
h = MBEDTLS_MD_MD5;
break;
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)
{
2018-12-13 20:05:12 +08:00
if ((size_t)lws_get_random(context, buf, len) == len) {
// lwsl_hexdump_err(buf, len);
return 0;
2018-12-13 20:05:12 +08:00
}
lwsl_err("%s: rng failed\n", __func__);
return -1;
}