mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-30 23:11:10 +00:00
Introduce mbedtls_nv_seed_poll() entropy polling function
This commit is contained in:
parent
cf0a9f96c5
commit
9988d6bbd9
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* \brief Platform-specific and custom entropy polling functions
|
* \brief Platform-specific and custom entropy polling functions
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
* Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
@ -90,6 +90,16 @@ int mbedtls_hardware_poll( void *data,
|
||||||
unsigned char *output, size_t len, size_t *olen );
|
unsigned char *output, size_t len, size_t *olen );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
||||||
|
/**
|
||||||
|
* \brief Entropy poll callback for a non-volatile seed file
|
||||||
|
*
|
||||||
|
* \note This must accept NULL as its first argument.
|
||||||
|
*/
|
||||||
|
int mbedtls_nv_seed_poll( void *data,
|
||||||
|
unsigned char *output, size_t len, size_t *olen );
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Entropy accumulator implementation
|
* Entropy accumulator implementation
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
* Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
@ -99,6 +99,11 @@ void mbedtls_entropy_init( mbedtls_entropy_context *ctx )
|
||||||
MBEDTLS_ENTROPY_MIN_HARDWARE,
|
MBEDTLS_ENTROPY_MIN_HARDWARE,
|
||||||
MBEDTLS_ENTROPY_SOURCE_STRONG );
|
MBEDTLS_ENTROPY_SOURCE_STRONG );
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
||||||
|
mbedtls_entropy_add_source( ctx, mbedtls_nv_seed_poll, NULL,
|
||||||
|
MBEDTLS_ENTROPY_BLOCK_SIZE,
|
||||||
|
MBEDTLS_ENTROPY_SOURCE_STRONG );
|
||||||
|
#endif
|
||||||
#endif /* MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES */
|
#endif /* MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Platform-specific and custom entropy polling functions
|
* Platform-specific and custom entropy polling functions
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
* Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
@ -37,6 +37,9 @@
|
||||||
#if defined(MBEDTLS_HAVEGE_C)
|
#if defined(MBEDTLS_HAVEGE_C)
|
||||||
#include "mbedtls/havege.h"
|
#include "mbedtls/havege.h"
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
||||||
|
#include "mbedtls/platform.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
|
#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
|
||||||
|
|
||||||
|
@ -238,4 +241,27 @@ int mbedtls_havege_poll( void *data,
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_HAVEGE_C */
|
#endif /* MBEDTLS_HAVEGE_C */
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
||||||
|
int mbedtls_nv_seed_poll( void *data,
|
||||||
|
unsigned char *output, size_t len, size_t *olen )
|
||||||
|
{
|
||||||
|
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
|
||||||
|
size_t use_len = MBEDTLS_ENTROPY_BLOCK_SIZE;
|
||||||
|
((void) data);
|
||||||
|
|
||||||
|
memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
||||||
|
|
||||||
|
if( mbedtls_nv_seed_read( buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) < 0 )
|
||||||
|
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
|
||||||
|
|
||||||
|
if( len < use_len )
|
||||||
|
use_len = len;
|
||||||
|
|
||||||
|
memcpy( output, buf, use_len );
|
||||||
|
*olen = use_len;
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
#endif /* MBEDTLS_ENTROPY_NV_SEED */
|
||||||
|
|
||||||
#endif /* MBEDTLS_ENTROPY_C */
|
#endif /* MBEDTLS_ENTROPY_C */
|
||||||
|
|
Loading…
Reference in a new issue