Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
c7673b02
Commit
c7673b02
authored
Mar 12, 2018
by
Luiz Felipe Silva
Browse files
Merge remote-tracking branch 'upstream/dev' into dev
parents
ba9a938e
5c8af3c4
Changes
114
Expand all
Hide whitespace changes
Inline
Side-by-side
app/include/mbedtls/aes.h
View file @
c7673b02
This diff is collapsed.
Click to expand it.
app/include/mbedtls/aesni.h
View file @
c7673b02
...
...
@@ -2,7 +2,8 @@
* \file aesni.h
*
* \brief AES-NI for hardware AES acceleration on some Intel processors
*
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
app/include/mbedtls/arc4.h
View file @
c7673b02
...
...
@@ -3,6 +3,10 @@
*
* \brief The ARCFOUR stream cipher
*
* \warning ARC4 is considered a weak cipher and its use constitutes a
* security risk. We recommend considering stronger ciphers instead.
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
@@ -19,6 +23,7 @@
* limitations under the License.
*
* This file is part of mbed TLS (https://tls.mbed.org)
*
*/
#ifndef MBEDTLS_ARC4_H
#define MBEDTLS_ARC4_H
...
...
@@ -31,6 +36,8 @@
#include <stddef.h>
#define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019
/**< ARC4 hardware accelerator failed. */
#if !defined(MBEDTLS_ARC4_ALT)
// Regular implementation
//
...
...
@@ -40,7 +47,11 @@ extern "C" {
#endif
/**
* \brief ARC4 context structure
* \brief ARC4 context structure
*
* \warning ARC4 is considered a weak cipher and its use constitutes a
* security risk. We recommend considering stronger ciphers instead.
*
*/
typedef
struct
{
...
...
@@ -54,6 +65,11 @@ mbedtls_arc4_context;
* \brief Initialize ARC4 context
*
* \param ctx ARC4 context to be initialized
*
* \warning ARC4 is considered a weak cipher and its use constitutes a
* security risk. We recommend considering stronger ciphers
* instead.
*
*/
void
mbedtls_arc4_init
(
mbedtls_arc4_context
*
ctx
);
...
...
@@ -61,6 +77,11 @@ void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
* \brief Clear ARC4 context
*
* \param ctx ARC4 context to be cleared
*
* \warning ARC4 is considered a weak cipher and its use constitutes a
* security risk. We recommend considering stronger ciphers
* instead.
*
*/
void
mbedtls_arc4_free
(
mbedtls_arc4_context
*
ctx
);
...
...
@@ -70,6 +91,11 @@ void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
* \param ctx ARC4 context to be setup
* \param key the secret key
* \param keylen length of the key, in bytes
*
* \warning ARC4 is considered a weak cipher and its use constitutes a
* security risk. We recommend considering stronger ciphers
* instead.
*
*/
void
mbedtls_arc4_setup
(
mbedtls_arc4_context
*
ctx
,
const
unsigned
char
*
key
,
unsigned
int
keylen
);
...
...
@@ -83,6 +109,11 @@ void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
* \param output buffer for the output data
*
* \return 0 if successful
*
* \warning ARC4 is considered a weak cipher and its use constitutes a
* security risk. We recommend considering stronger ciphers
* instead.
*
*/
int
mbedtls_arc4_crypt
(
mbedtls_arc4_context
*
ctx
,
size_t
length
,
const
unsigned
char
*
input
,
unsigned
char
*
output
);
...
...
@@ -103,6 +134,11 @@ extern "C" {
* \brief Checkup routine
*
* \return 0 if successful, or 1 if the test failed
*
* \warning ARC4 is considered a weak cipher and its use constitutes a
* security risk. We recommend considering stronger ciphers
* instead.
*
*/
int
mbedtls_arc4_self_test
(
int
verbose
);
...
...
app/include/mbedtls/asn1.h
View file @
c7673b02
...
...
@@ -2,7 +2,8 @@
* \file asn1.h
*
* \brief Generic ASN.1 parsing
*
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
@@ -59,7 +60,7 @@
/**
* \name DER constants
* These constants comply with DER encoded
the ANS
1 type tags.
* These constants comply with
the
DER encoded
ASN.
1 type tags.
* DER encoding uses hexadecimal representation.
* An example DER sequence is:\n
* - 0x02 -- tag indicating INTEGER
...
...
app/include/mbedtls/asn1write.h
View file @
c7673b02
...
...
@@ -2,7 +2,8 @@
* \file asn1write.h
*
* \brief ASN.1 buffer writing functionality
*
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
app/include/mbedtls/base64.h
View file @
c7673b02
...
...
@@ -2,7 +2,8 @@
* \file base64.h
*
* \brief RFC 1521 base64 encoding/decoding
*
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
app/include/mbedtls/bignum.h
View file @
c7673b02
/**
* \file bignum.h
*
* \brief Multi-precision integer library
*
* \brief Multi-precision integer library
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
@@ -70,7 +71,7 @@
* Maximum size of MPIs allowed in bits and bytes for user-MPIs.
* ( Default: 512 bytes => 4096 bits, Maximum tested: 2048 bytes => 16384 bits )
*
* Note: Calculations can
results
temporarily in larger MPIs. So the number
* Note: Calculations can temporarily
result
in larger MPIs. So the number
* of limbs required (MBEDTLS_MPI_MAX_LIMBS) is higher.
*/
#define MBEDTLS_MPI_MAX_SIZE 1024
/**< Maximum number of bytes for usable MPIs. */
...
...
@@ -683,6 +684,10 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
*
* \return 0 if successful,
* MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
*
* \note The bytes obtained from the PRNG are interpreted
* as a big-endian representation of an MPI; this can
* be relevant in applications like deterministic ECDSA.
*/
int
mbedtls_mpi_fill_random
(
mbedtls_mpi
*
X
,
size_t
size
,
int
(
*
f_rng
)(
void
*
,
unsigned
char
*
,
size_t
),
...
...
app/include/mbedtls/blowfish.h
View file @
c7673b02
...
...
@@ -2,7 +2,8 @@
* \file blowfish.h
*
* \brief Blowfish block cipher
*
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
@@ -40,6 +41,7 @@
#define MBEDTLS_BLOWFISH_BLOCKSIZE 8
/* Blowfish uses 64 bit blocks */
#define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016
/**< Invalid key length. */
#define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
/**< Blowfish hardware accelerator failed. */
#define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
/**< Invalid data input length. */
#if !defined(MBEDTLS_BLOWFISH_ALT)
...
...
app/include/mbedtls/bn_mul.h
View file @
c7673b02
/**
* \file bn_mul.h
*
* \brief Multi-precision integer library
*
* \brief Multi-precision integer library
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
app/include/mbedtls/camellia.h
View file @
c7673b02
...
...
@@ -2,7 +2,8 @@
* \file camellia.h
*
* \brief Camellia block cipher
*
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
@@ -37,6 +38,7 @@
#define MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0024
/**< Invalid key length. */
#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026
/**< Invalid data input length. */
#define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027
/**< Camellia hardware accelerator failed. */
#if !defined(MBEDTLS_CAMELLIA_ALT)
// Regular implementation
...
...
app/include/mbedtls/ccm.h
View file @
c7673b02
/**
* \file ccm.h
*
* \brief Counter with CBC-MAC (CCM) for 128-bit block ciphers
* \brief CCM combines Counter mode encryption with CBC-MAC authentication
* for 128-bit block ciphers.
*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* Input to CCM includes the following elements:
* <ul><li>Payload - data that is both authenticated and encrypted.</li>
* <li>Associated data (Adata) - data that is authenticated but not
* encrypted, For example, a header.</li>
* <li>Nonce - A unique value that is assigned to the payload and the
* associated data.</li></ul>
*
*/
/*
* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
...
...
@@ -18,46 +28,54 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of
m
bed TLS (https://tls.mbed.org)
* This file is part of
M
bed TLS (https://tls.mbed.org)
*/
#ifndef MBEDTLS_CCM_H
#define MBEDTLS_CCM_H
#include "cipher.h"
#define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D
/**< Bad input parameters to function. */
#define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F
/**< Authenticated decryption failed. */
#define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D
/**< Bad input parameters to the function. */
#define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F
/**< Authenticated decryption failed. */
#define MBEDTLS_ERR_CCM_HW_ACCEL_FAILED -0x0011
/**< CCM hardware accelerator failed. */
#if !defined(MBEDTLS_CCM_ALT)
// Regular implementation
//
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* \brief CCM context structure
* \brief The CCM context-type definition. The CCM context is passed
* to the APIs called.
*/
typedef
struct
{
mbedtls_cipher_context_t
cipher_ctx
;
/*!< cipher context used */
mbedtls_cipher_context_t
cipher_ctx
;
/*!<
The
cipher context used
.
*/
}
mbedtls_ccm_context
;
/**
* \brief
Initialize CCM context (just makes references valid)
*
Makes the context ready for mbedtls_ccm_setkey() or
* mbedtls_ccm_free().
* \brief
This function initializes the specified CCM context,
*
to make references valid, and prepare the context
*
for mbedtls_ccm_setkey() or
mbedtls_ccm_free().
*
* \param ctx CCM context to initialize
* \param ctx
The
CCM context to initialize
.
*/
void
mbedtls_ccm_init
(
mbedtls_ccm_context
*
ctx
);
/**
* \brief CCM initialization (encryption and decryption)
* \brief This function initializes the CCM context set in the
* \p ctx parameter and sets the encryption key.
*
* \param ctx CCM context to
be
initialize
d
* \param cipher
cipher to use (a
128-bit block cipher
)
* \param key encryption key
* \param keybits key size in bits
(
must be acceptable by the cipher
)
* \param ctx
The
CCM context to initialize
.
* \param cipher
The
128-bit block cipher
to use.
* \param key
The
encryption key
.
* \param keybits
The
key size in bits
. This
must be acceptable by the cipher
.
*
* \return
0 if
success
ful
, or a cipher
specific error code
* \return
\c 0 on
success, or a cipher
-
specific error code
.
*/
int
mbedtls_ccm_setkey
(
mbedtls_ccm_context
*
ctx
,
mbedtls_cipher_id_t
cipher
,
...
...
@@ -65,36 +83,37 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
unsigned
int
keybits
);
/**
* \brief Free a CCM context and underlying cipher sub-context
* \brief This function releases and clears the specified CCM context
* and underlying cipher sub-context.
*
* \param ctx CCM context to
free
* \param ctx
The
CCM context to
clear.
*/
void
mbedtls_ccm_free
(
mbedtls_ccm_context
*
ctx
);
/**
* \brief
CCM buffer encryption
*
* \param ctx CCM context
* \param length length of the input data in
b
ytes
* \param iv
nonce (i
nitialization vector
)
* \param iv_len length of IV in
b
ytes
*
must be 2, 3, 4, 5, 6, 7 or 8
* \param add
additional data
*
\param add_len length of additional data in bytes
*
must be less than 2^16 - 2^8
* \param
in
put buffer holding the
in
put data
*
\param output buffer for holdi
ng
th
e output data
*
must be at least 'le
ngth
' bytes wide
* \param tag
buffer for holding the tag
*
\param tag_len length of the tag to generate in bytes
*
must be 4, 6, 8, 10, 14 or 16
*
*
\note
T
he tag
is written to a separate buffer. To get the tag
*
concatena
te
d
with
the output as in the CCM spec
, use
* tag = output + length and make sure th
e output buffer is
* at least length + tag_len wide.
*
* \return
0 if
success
ful
* \brief
This function encrypts a buffer using CCM.
*
* \param ctx
The
CCM context
to use for encryption.
* \param length
The
length of the input data in
B
ytes
.
* \param iv
I
nitialization vector
(nonce).
* \param iv_len
The
length of
the
IV in
B
ytes
: 7, 8, 9, 10, 11, 12, or 13.
*
\param add The additional data field.
* \param add
_len The length of
additional data
in Bytes.
*
Must be less than 2^16 - 2^8.
*
\param input The buffer holding the input data.
* \param
out
put
The
buffer holding the
out
put data
.
*
Must be at least \p le
ngth
Bytes wide.
*
\param tag The buffer holdi
ng
th
e tag.
* \param tag
_len The length of the tag to generate in Bytes:
*
4, 6, 8, 10, 14 or 16.
*
*
\note The tag is written to a separate buffer. To concatenate
*
t
he
\p
tag
with the \p output, as done in <em>RFC-3610:
*
Coun
te
r
with
CBC-MAC (CCM)</em>
, use
*
\p
tag =
\p
output +
\p
length
,
and make sure th
at the
*
output buffer is
at least
\p
length +
\p
tag_len wide.
*
* \return
\c 0 on
success
.
*/
int
mbedtls_ccm_encrypt_and_tag
(
mbedtls_ccm_context
*
ctx
,
size_t
length
,
const
unsigned
char
*
iv
,
size_t
iv_len
,
...
...
@@ -103,21 +122,22 @@ int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
unsigned
char
*
tag
,
size_t
tag_len
);
/**
* \brief CCM buffer authenticated decryption
*
* \param ctx CCM context
* \param length length of the input data
* \param iv initialization vector
* \param iv_len length of IV
* \param add additional data
* \param add_len length of additional data
* \param input buffer holding the input data
* \param output buffer for holding the output data
* \param tag buffer holding the tag
* \param tag_len length of the tag
*
* \return 0 if successful and authenticated,
* MBEDTLS_ERR_CCM_AUTH_FAILED if tag does not match
* \brief This function performs a CCM authenticated decryption of a
* buffer.
*
* \param ctx The CCM context to use for decryption.
* \param length The length of the input data in Bytes.
* \param iv Initialization vector.
* \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, or 13.
* \param add The additional data field.
* \param add_len The length of additional data in Bytes.
* \param input The buffer holding the input data.
* \param output The buffer holding the output data.
* \param tag The buffer holding the tag.
* \param tag_len The length of the tag in Bytes.
*
* \return 0 if successful and authenticated, or
* #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match.
*/
int
mbedtls_ccm_auth_decrypt
(
mbedtls_ccm_context
*
ctx
,
size_t
length
,
const
unsigned
char
*
iv
,
size_t
iv_len
,
...
...
@@ -125,11 +145,23 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
const
unsigned
char
*
input
,
unsigned
char
*
output
,
const
unsigned
char
*
tag
,
size_t
tag_len
);
#ifdef __cplusplus
}
#endif
#else
/* MBEDTLS_CCM_ALT */
#include "ccm_alt.h"
#endif
/* MBEDTLS_CCM_ALT */
#ifdef __cplusplus
extern
"C"
{
#endif
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
/**
* \brief
C
heckup routine
* \brief
The CCM c
heckup routine
.
*
* \return
0 if
success
ful
, or
1 if the test
fail
ed
* \return
\c 0 on
success, or
\c 1 on
fail
ure.
*/
int
mbedtls_ccm_self_test
(
int
verbose
);
#endif
/* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
...
...
app/include/mbedtls/certs.h
View file @
c7673b02
...
...
@@ -2,7 +2,8 @@
* \file certs.h
*
* \brief Sample certificates and DHM parameters for testing
*
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
app/include/mbedtls/check_config.h
View file @
c7673b02
...
...
@@ -2,7 +2,8 @@
* \file check_config.h
*
* \brief Consistency checks for configuration options
*
*/
/*
* Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
app/include/mbedtls/cipher.h
View file @
c7673b02
This diff is collapsed.
Click to expand it.
app/include/mbedtls/cipher_internal.h
View file @
c7673b02
...
...
@@ -4,7 +4,8 @@
* \brief Cipher wrappers.
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
app/include/mbedtls/cmac.h
View file @
c7673b02
/**
* \file cmac.h
*
* \brief Cipher-based Message Authentication Code (CMAC) Mode for
* Authentication
*
* Copyright (C) 2015-2016, ARM Limited, All Rights Reserved
* \brief The Cipher-based Message Authentication Code (CMAC) Mode for
* Authentication.
*/
/*
* Copyright (C) 2015-2018, Arm Limited (or its affiliates), All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
...
...
@@ -19,8 +20,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of
m
bed TLS (https://tls.mbed.org)
* This file is part of
M
bed TLS (https://tls.mbed.org)
*/
#ifndef MBEDTLS_CMAC_H
#define MBEDTLS_CMAC_H
...
...
@@ -30,106 +32,125 @@
extern
"C"
{
#endif
#define MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED -0x007A
/**< CMAC hardware accelerator failed. */
#define MBEDTLS_AES_BLOCK_SIZE 16
#define MBEDTLS_DES3_BLOCK_SIZE 8
#if defined(MBEDTLS_AES_C)
#define MBEDTLS_CIPHER_BLKSIZE_MAX 16
/* longest used by CMAC is AES */
#define MBEDTLS_CIPHER_BLKSIZE_MAX 16
/*
The
longest
block
used by CMAC is
that of
AES
.
*/
#else
#define MBEDTLS_CIPHER_BLKSIZE_MAX 8
/* longest used by CMAC is 3DES */
#define MBEDTLS_CIPHER_BLKSIZE_MAX 8
/*
The
longest
block
used by CMAC is
that of
3DES
.
*/
#endif
#if !defined(MBEDTLS_CMAC_ALT)
/**
* CMAC context structure
- Contains internal state information only
*
The
CMAC context structure
.
*/
struct
mbedtls_cmac_context_t
{
/**
I
nternal state of the CMAC algorithm */
/**
The i
nternal state of the CMAC algorithm
.
*/
unsigned
char
state
[
MBEDTLS_CIPHER_BLKSIZE_MAX
];
/** Unprocessed data - either data that was not block aligned and is still
* pending
to be
process
ed
, or the final block */
* pending process
ing
, or the final block
.
*/
unsigned
char
unprocessed_block
[
MBEDTLS_CIPHER_BLKSIZE_MAX
];
/**
L
ength of data pending
to be
process
ed
*/
/**
The l
ength of data pending process
ing.
*/
size_t
unprocessed_len
;
};
/**
* \brief Set the CMAC key and prepare to authenticate the input
* data.
* Should be called with an initialized cipher context.
*
* \param ctx Cipher context. This should be a cipher context,
* initialized to be one of the following types:
* MBEDTLS_CIPHER_AES_128_ECB, MBEDTLS_CIPHER_AES_192_ECB,
* MBEDTLS_CIPHER_AES_256_ECB or
* MBEDTLS_CIPHER_DES_EDE3_ECB.
* \param key CMAC key
* \param keybits length of the CMAC key in bits
* (must be acceptable by the cipher)
*
* \return 0 if successful, or a cipher specific error code
* \brief This function sets the CMAC key, and prepares to authenticate
* the input data.
* Must be called with an initialized cipher context.
*
* \param ctx The cipher context used for the CMAC operation, initialized
* as one of the following types:<ul>
* <li>MBEDTLS_CIPHER_AES_128_ECB</li>
* <li>MBEDTLS_CIPHER_AES_192_ECB</li>
* <li>MBEDTLS_CIPHER_AES_256_ECB</li>
* <li>MBEDTLS_CIPHER_DES_EDE3_ECB</li></ul>
* \param key The CMAC key.
* \param keybits The length of the CMAC key in bits.
* Must be supported by the cipher.
*
* \return \c 0 on success, or a cipher-specific error code.
*/
int
mbedtls_cipher_cmac_starts
(
mbedtls_cipher_context_t
*
ctx
,
const
unsigned
char
*
key
,
size_t
keybits
);
/**
* \brief Generic CMAC process buffer.
* Called between mbedtls_cipher_cmac_starts() or
* mbedtls_cipher_cmac_reset() and
* mbedtls_cipher_cmac_finish().
* May be called repeatedly.
*
* \param ctx CMAC context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
* verification fails.
* \brief This function feeds an input buffer into an ongoing CMAC
* computation.
*
* It is called between mbedtls_cipher_cmac_starts() or
* mbedtls_cipher_cmac_reset(), and mbedtls_cipher_cmac_finish().
* Can be called repeatedly.
*
* \param ctx The cipher context used for the CMAC operation.
* \param input The buffer holding the input data.
* \param ilen The length of the input data.
*
* \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA
* if parameter verification fails.
*/
int
mbedtls_cipher_cmac_update
(
mbedtls_cipher_context_t
*
ctx
,
const
unsigned
char
*
input
,
size_t
ilen
);
/**
* \brief Output CMAC.
* Called after mbedtls_cipher_cmac_update().
* Usually followed by mbedtls_cipher_cmac_reset(), then
* mbedtls_cipher_cmac_starts(), or mbedtls_cipher_free().
* \brief This function finishes the CMAC operation, and writes
* the result to the output buffer.
*
* It is called after mbedtls_cipher_cmac_update().
* It can be followed by mbedtls_cipher_cmac_reset() and
* mbedtls_cipher_cmac_update(), or mbedtls_cipher_free().
*
* \param ctx
CMAC context
* \param output
Generic
CMAC checksum result
* \param ctx
The cipher context used for the CMAC operation.
* \param output
The output buffer for the
CMAC checksum result
.
*
* \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA
if parameter
* verification fails.
* \returns
\c
0 on success,
or #
MBEDTLS_ERR_MD_BAD_INPUT_DATA
*
if parameter
verification fails.
*/
int
mbedtls_cipher_cmac_finish
(
mbedtls_cipher_context_t
*
ctx
,
unsigned
char
*
output
);
/**
* \brief
P
repare t
o
authenticat
e a new message with the same key.
*
Called after mbedtls_cipher_cmac_finish() and before
*
mbedtls_cipher_cmac_update()
.
* \brief
This function p
repare
s
t
he
authenticat
ion of another
*
message with the same key as the previous CMAC
*
operation
.
*
* \param ctx CMAC context to be reset
* It is called after mbedtls_cipher_cmac_finish()
* and before mbedtls_cipher_cmac_update().
*
* \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
* verification fails.
* \param ctx The cipher context used for the CMAC operation.
*
* \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA
* if parameter verification fails.
*/
int
mbedtls_cipher_cmac_reset
(
mbedtls_cipher_context_t
*
ctx
);
/**
* \brief Output = Generic_CMAC( cmac key, input buffer )
* \brief This function calculates the full generic CMAC
* on the input buffer with the provided key.
*
* The function allocates the context, performs the
* calculation, and frees the context.
*
* The CMAC result is calculated as
* output = generic CMAC(cmac key, input buffer).
*
* \param cipher_info message digest info
* \param key CMAC key
* \param keylen length of the CMAC key in bits
* \param input buffer holding the data
* \param ilen length of the input data
* \param output Generic CMAC-result
*
* \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter
* verification fails.
* \param cipher_info The cipher information.
* \param key The CMAC key.
* \param keylen The length of the CMAC key in bits.
* \param input The buffer holding the input data.
* \param ilen The length of the input data.
* \param output The buffer for the generic CMAC result.
*
* \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA
* if parameter verification fails.
*/
int
mbedtls_cipher_cmac
(
const
mbedtls_cipher_info_t
*
cipher_info
,
const
unsigned
char
*
key
,
size_t
keylen
,
...
...
@@ -138,27 +159,44 @@ int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info,
#if defined(MBEDTLS_AES_C)
/**
* \brief AES-CMAC-128-PRF
* Implementation of (AES-CMAC-PRF-128), as defined in RFC 4615
*
* \param key PRF key
* \param key_len PRF key length in bytes
* \param input buffer holding the input data
* \param in_len length of the input data in bytes
* \param output buffer holding the generated pseudorandom output (16 bytes)
*
* \return 0 if successful
* \brief This function implements the AES-CMAC-PRF-128 pseudorandom
* function, as defined in
* <em>RFC-4615: The Advanced Encryption Standard-Cipher-based
* Message Authentication Code-Pseudo-Random Function-128
* (AES-CMAC-PRF-128) Algorithm for the Internet Key
* Exchange Protocol (IKE).</em>
*
* \param key The key to use.
* \param key_len The key length in Bytes.
* \param input The buffer holding the input data.
* \param in_len The length of the input data in Bytes.
* \param output The buffer holding the generated 16 Bytes of
* pseudorandom output.
*
* \return \c 0 on success.
*/
int
mbedtls_aes_cmac_prf_128
(
const
unsigned
char
*
key
,
size_t
key_len
,
const
unsigned
char
*
input
,
size_t
in_len
,
unsigned
char
output
[
16
]
);
#endif
/* MBEDTLS_AES_C */
#ifdef __cplusplus
}
#endif
#else
/* !MBEDTLS_CMAC_ALT */
#include "cmac_alt.h"
#endif
/* !MBEDTLS_CMAC_ALT */
#ifdef __cplusplus
extern
"C"
{
#endif
#if defined(MBEDTLS_SELF_TEST) && ( defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) )
/**
* \brief
C
heckup routine
* \brief
The CMAC c
heckup routine
.
*
* \return
0 if
success
ful
, or
1 if the test
fail
ed
* \return
\c 0 on
success, or
\c 1 on
fail
ure.
*/
int
mbedtls_cmac_self_test
(
int
verbose
);
#endif
/* MBEDTLS_SELF_TEST && ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
...
...
app/include/mbedtls/compat-1.3.h
View file @
c7673b02
...
...
@@ -5,7 +5,8 @@
* for the PolarSSL naming conventions.
*
* \deprecated Use the new names directly instead
*
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
app/include/mbedtls/config.h
View file @
c7673b02
...
...
@@ -6,7 +6,8 @@
* This set of compile-time options may be used to enable
* or disable features selectively, and reduce the global
* memory footprint.
*
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
@@ -261,20 +262,32 @@
*
* Uncomment a macro to enable alternate implementation of the corresponding
* module.
*
* \warning MD2, MD4, MD5, ARC4, DES and SHA-1 are considered weak and their
* use constitutes a security risk. If possible, we recommend
* avoiding dependencies on them, and considering stronger message
* digests and ciphers instead.
*
*/
//#define MBEDTLS_AES_ALT
//#define MBEDTLS_ARC4_ALT
//#define MBEDTLS_BLOWFISH_ALT
//#define MBEDTLS_CAMELLIA_ALT
//#define MBEDTLS_CCM_ALT
//#define MBEDTLS_CMAC_ALT
//#define MBEDTLS_DES_ALT
//#define MBEDTLS_XTEA_ALT
//#define MBEDTLS_DHM_ALT
//#define MBEDTLS_ECJPAKE_ALT
//#define MBEDTLS_GCM_ALT
//#define MBEDTLS_MD2_ALT
//#define MBEDTLS_MD4_ALT
//#define MBEDTLS_MD5_ALT
//#define MBEDTLS_RIPEMD160_ALT
//#define MBEDTLS_RSA_ALT
//#define MBEDTLS_SHA1_ALT
//#define MBEDTLS_SHA256_ALT
//#define MBEDTLS_SHA512_ALT
//#define MBEDTLS_XTEA_ALT
/*
* When replacing the elliptic curve module, pleace consider, that it is
* implemented with two .c files:
...
...
@@ -314,6 +327,12 @@
*
* Uncomment a macro to enable alternate implementation of the corresponding
* function.
*
* \warning MD2, MD4, MD5, DES and SHA-1 are considered weak and their use
* constitutes a security risk. If possible, we recommend avoiding
* dependencies on them, and considering stronger message digests
* and ciphers instead.
*
*/
//#define MBEDTLS_MD2_PROCESS_ALT
//#define MBEDTLS_MD4_PROCESS_ALT
...
...
@@ -329,6 +348,11 @@
//#define MBEDTLS_AES_SETKEY_DEC_ALT
//#define MBEDTLS_AES_ENCRYPT_ALT
//#define MBEDTLS_AES_DECRYPT_ALT
//#define MBEDTLS_ECDH_GEN_PUBLIC_ALT
//#define MBEDTLS_ECDH_COMPUTE_SHARED_ALT
//#define MBEDTLS_ECDSA_VERIFY_ALT
//#define MBEDTLS_ECDSA_SIGN_ALT
//#define MBEDTLS_ECDSA_GENKEY_ALT
/**
* \def MBEDTLS_ECP_INTERNAL_ALT
...
...
@@ -513,6 +537,9 @@
* MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA
*
* Uncomment this macro to enable weak ciphersuites
*
* \warning DES is considered a weak cipher and its use constitutes a
* security risk. We recommend considering stronger ciphers instead.
*/
//#define MBEDTLS_ENABLE_WEAK_CIPHERSUITES
...
...
@@ -618,6 +645,13 @@
* MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
* MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA
* MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA
*
* \warning Using DHE constitutes a security risk as it
* is not possible to validate custom DH parameters.
* If possible, it is recommended users should consider
* preferring other methods of key exchange.
* See dhm.h for more details.
*
*/
#define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
...
...
@@ -717,6 +751,13 @@
* MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
* MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
* MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
*
* \warning Using DHE constitutes a security risk as it
* is not possible to validate custom DH parameters.
* If possible, it is recommended users should consider
* preferring other methods of key exchange.
* See dhm.h for more details.
*
*/
#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
...
...
@@ -1155,6 +1196,13 @@
* misuse/misunderstand.
*
* Comment this to disable support for renegotiation.
*
* \note Even if this option is disabled, both client and server are aware
* of the Renegotiation Indication Extension (RFC 5746) used to
* prevent the SSL renegotiation attack (see RFC 5746 Sect. 1).
* (See \c mbedtls_ssl_conf_legacy_renegotiation for the
* configuration of this extension).
*
*/
#define MBEDTLS_SSL_RENEGOTIATION
...
...
@@ -1596,6 +1644,11 @@
* MBEDTLS_TLS_RSA_WITH_RC4_128_MD5
* MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA
* MBEDTLS_TLS_PSK_WITH_RC4_128_SHA
*
* \warning ARC4 is considered a weak cipher and its use constitutes a
* security risk. If possible, we recommend avoidng dependencies on
* it, and considering stronger ciphers instead.
*
*/
#define MBEDTLS_ARC4_C
...
...
@@ -1649,6 +1702,7 @@
* library/ecp.c
* library/ecdsa.c
* library/rsa.c
* library/rsa_internal.c
* library/ssl_tls.c
*
* This module is required for RSA, DHM and ECC (ECDH, ECDSA) support.
...
...
@@ -1821,6 +1875,9 @@
* MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA
*
* PEM_PARSE uses DES/3DES for decrypting encrypted keys.
*
* \warning DES is considered a weak cipher and its use constitutes a
* security risk. We recommend considering stronger ciphers instead.
*/
#define MBEDTLS_DES_C
...
...
@@ -1835,6 +1892,13 @@
*
* This module is used by the following key exchanges:
* DHE-RSA, DHE-PSK
*
* \warning Using DHE constitutes a security risk as it
* is not possible to validate custom DH parameters.
* If possible, it is recommended users should consider
* preferring other methods of key exchange.
* See dhm.h for more details.
*
*/
#define MBEDTLS_DHM_C
...
...
@@ -2000,6 +2064,11 @@
* Caller:
*
* Uncomment to enable support for (rare) MD2-signed X.509 certs.
*
* \warning MD2 is considered a weak message digest and its use constitutes a
* security risk. If possible, we recommend avoiding dependencies on
* it, and considering stronger message digests instead.
*
*/
//#define MBEDTLS_MD2_C
...
...
@@ -2012,6 +2081,11 @@
* Caller:
*
* Uncomment to enable support for (rare) MD4-signed X.509 certs.
*
* \warning MD4 is considered a weak message digest and its use constitutes a
* security risk. If possible, we recommend avoiding dependencies on
* it, and considering stronger message digests instead.
*
*/
//#define MBEDTLS_MD4_C
...
...
@@ -2025,8 +2099,15 @@
* library/pem.c
* library/ssl_tls.c
*
* This module is required for SSL/TLS and X.509.
* PEM_PARSE uses MD5 for decrypting encrypted keys.
* This module is required for SSL/TLS up to version 1.1, and for TLS 1.2
* depending on the handshake parameters. Further, it is used for checking
* MD5-signed certificates, and for PBKDF1 when decrypting PEM-encoded
* encrypted keys.
*
* \warning MD5 is considered a weak message digest and its use constitutes a
* security risk. If possible, we recommend avoiding dependencies on
* it, and considering stronger message digests instead.
*
*/
#define MBEDTLS_MD5_C
...
...
@@ -2262,6 +2343,7 @@
* Enable the RSA public-key cryptosystem.
*
* Module: library/rsa.c
* library/rsa_internal.c
* Caller: library/ssl_cli.c
* library/ssl_srv.c
* library/ssl_tls.c
...
...
@@ -2288,6 +2370,11 @@
*
* This module is required for SSL/TLS up to version 1.1, for TLS 1.2
* depending on the handshake parameters, and for SHA1-signed certificates.
*
* \warning SHA-1 is considered a weak message digest and its use constitutes
* a security risk. If possible, we recommend avoiding dependencies
* on it, and considering stronger message digests instead.
*
*/
#define MBEDTLS_SHA1_C
...
...
@@ -2676,8 +2763,13 @@
* Allow SHA-1 in the default TLS configuration for certificate signing.
* Without this build-time option, SHA-1 support must be activated explicitly
* through mbedtls_ssl_conf_cert_profile. Turning on this option is not
* recommended because of it is possible to generte SHA-1 collisions, however
* recommended because of it is possible to gener
a
te SHA-1 collisions, however
* this may be safe for legacy infrastructure where additional controls apply.
*
* \warning SHA-1 is considered a weak message digest and its use constitutes
* a security risk. If possible, we recommend avoiding dependencies
* on it, and considering stronger message digests instead.
*
*/
// #define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
...
...
@@ -2688,7 +2780,13 @@
* The use of SHA-1 in TLS <= 1.1 and in HMAC-SHA-1 is always allowed by
* default. At the time of writing, there is no practical attack on the use
* of SHA-1 in handshake signatures, hence this option is turned on by default
* for compatibility with existing peers.
* to preserve compatibility with existing peers, but the general
* warning applies nonetheless:
*
* \warning SHA-1 is considered a weak message digest and its use constitutes
* a security risk. If possible, we recommend avoiding dependencies
* on it, and considering stronger message digests instead.
*
*/
#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE
...
...
app/include/mbedtls/ctr_drbg.h
View file @
c7673b02
/**
* \file ctr_drbg.h
*
* \brief CTR_DRBG based on AES-256 (NIST SP 800-90)
* \brief CTR_DRBG is based on AES-256, as defined in <em>NIST SP 800-90A:
* Recommendation for Random Number Generation Using Deterministic
* Random Bit Generators</em>.
*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
*/
/*
* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
...
...
@@ -18,8 +22,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of
m
bed TLS (https://tls.mbed.org)
* This file is part of
M
bed TLS (https://tls.mbed.org)
*/
#ifndef MBEDTLS_CTR_DRBG_H
#define MBEDTLS_CTR_DRBG_H
...
...
@@ -30,78 +35,95 @@
#endif
#define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034
/**< The entropy source failed. */
#define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036
/**< T
oo many random requested in single call
. */
#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038
/**<
Input too large (E
ntropy + additional
)
. */
#define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A
/**< Read
/
write error in file. */
#define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036
/**< T
he requested random buffer length is too big
. */
#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038
/**<
The input (e
ntropy + additional
data) is too large
. */
#define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A
/**< Read
or
write error in file. */
#define MBEDTLS_CTR_DRBG_BLOCKSIZE 16
/**< Block size used by the cipher */
#define MBEDTLS_CTR_DRBG_KEYSIZE 32
/**< Key size used by the cipher */
#define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 )
#define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE )
/**< The seed length (counter + AES key) */
#define MBEDTLS_CTR_DRBG_BLOCKSIZE 16
/**< The block size used by the cipher. */
#define MBEDTLS_CTR_DRBG_KEYSIZE 32
/**< The key size used by the cipher. */
#define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 )
/**< The key size for the DRBG operation, in bits. */
#define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE )
/**< The seed length, calculated as (counter + AES key). */
/**
* \name SECTION: Module settings
*
* The configuration options you can set for this module are in this section.
* Either change them in config.h or define them on the compiler command line.
* Either change them in config.h or define them using the compiler command
* line.
* \{
*/
#if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN)
#if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
/**< Amount of entropy used per seed by default (48 with SHA-512, 32 with SHA-256) */
#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
/**< The amount of entropy used per seed by default:
* <ul><li>48 with SHA-512.</li>
* <li>32 with SHA-256.</li></ul>
*/
#else
#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
/**< Amount of entropy used per seed by default (48 with SHA-512, 32 with SHA-256) */
#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
/**< Amount of entropy used per seed by default:
* <ul><li>48 with SHA-512.</li>
* <li>32 with SHA-256.</li></ul>
*/
#endif
#endif
#if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
/**< Interval before reseed is performed by default */
#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
/**< The interval before reseed is performed by default. */
#endif
#if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT)
#define MBEDTLS_CTR_DRBG_MAX_INPUT 256
/**< Maximum number of additional input bytes */
#define MBEDTLS_CTR_DRBG_MAX_INPUT 256
/**< The maximum number of additional input Bytes. */
#endif
#if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST)
#define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024
/**< Maximum number of requested bytes per call */
#define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024
/**< The maximum number of requested Bytes per call. */
#endif
#if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT)
#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
/**< Maximum size of (re)seed buffer */
#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
/**< The maximum size of seed or reseed buffer. */
#endif
/* \} name SECTION: Module settings */
#define MBEDTLS_CTR_DRBG_PR_OFF 0
/**< No prediction resistance */
#define MBEDTLS_CTR_DRBG_PR_ON 1
/**< Prediction resistance enabled */
#define MBEDTLS_CTR_DRBG_PR_OFF 0
/**< Prediction resistance is disabled. */
#define MBEDTLS_CTR_DRBG_PR_ON 1
/**< Prediction resistance is enabled. */
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* \brief CTR_DRBG context structure
* \brief
The
CTR_DRBG context structure
.
*/
typedef
struct
{
unsigned
char
counter
[
16
];
/*!< counter (V) */
int
reseed_counter
;
/*!< reseed counter */
int
prediction_resistance
;
/*!< enable prediction resistance (Automatic
reseed before every random generation) */
size_t
entropy_len
;
/*!< amount of entropy grabbed on each
(re)seed */
int
reseed_interval
;
/*!< reseed interval */
mbedtls_aes_context
aes_ctx
;
/*!< AES context */
unsigned
char
counter
[
16
];
/*!< The counter (V). */
int
reseed_counter
;
/*!< The reseed counter. */
int
prediction_resistance
;
/*!< This determines whether prediction
resistance is enabled, that is
whether to systematically reseed before
each random generation. */
size_t
entropy_len
;
/*!< The amount of entropy grabbed on each
seed or reseed operation. */
int
reseed_interval
;
/*!< The reseed interval. */
mbedtls_aes_context
aes_ctx
;
/*!< The AES context. */
/*
* Callbacks (Entropy)
*/
int
(
*
f_entropy
)(
void
*
,
unsigned
char
*
,
size_t
);
/*!< The entropy callback function. */
void
*
p_entropy
;
/*!< context for the entropy function */
void
*
p_entropy
;
/*!<
The
context for the entropy function
.
*/
#if defined(MBEDTLS_THREADING_C)
mbedtls_threading_mutex_t
mutex
;
...
...
@@ -110,31 +132,32 @@ typedef struct
mbedtls_ctr_drbg_context
;
/**
* \brief
CTR_DRBG context initialization
*
Makes the context ready
for mbedtls_ctr_drbg_seed()
or
* mbedtls_ctr_drbg_free().
* \brief
This function initializes the CTR_DRBG context,
*
and prepares it
for mbedtls_ctr_drbg_seed()
*
or
mbedtls_ctr_drbg_free().
*
* \param ctx CTR_DRBG context to
be
initialize
d
* \param ctx
The
CTR_DRBG context to initialize
.
*/
void
mbedtls_ctr_drbg_init
(
mbedtls_ctr_drbg_context
*
ctx
);
/**
* \brief
CTR_DRBG initial seeding
*
Seed and setup
entropy source for future reseeds.
* \brief
This function seeds and sets up the CTR_DRBG
* entropy source for future reseeds.
*
*
N
ote
:
Personalization data can be provided in addition to the more generic
* entropy source to make this instantiation as unique as possible.
*
\n
ote Personalization data can be provided in addition to the more generic
* entropy source
,
to make this instantiation as unique as possible.
*
* \param ctx CTR_DRBG context to be seeded
* \param f_entropy Entropy callback (p_entropy, buffer to fill, buffer
* length)
* \param p_entropy Entropy context
* \param custom Personalization data (Device specific identifiers)
* (Can be NULL)
* \param len Length of personalization data
* \param ctx The CTR_DRBG context to seed.
* \param f_entropy The entropy callback, taking as arguments the
* \p p_entropy context, the buffer to fill, and the
length of the buffer.
* \param p_entropy The entropy context.
* \param custom Personalization data, that is device-specific
identifiers. Can be NULL.
* \param len The length of the personalization data.
*
* \return
0 if
success
ful
, or
* MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED
* \return
\c 0 on
success, or
*
#
MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED
on failure.
*/
int
mbedtls_ctr_drbg_seed
(
mbedtls_ctr_drbg_context
*
ctx
,
int
(
*
f_entropy
)(
void
*
,
unsigned
char
*
,
size_t
),
...
...
@@ -143,138 +166,147 @@ int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx,
size_t
len
);
/**
* \brief
C
lear CTR_CRBG context data
* \brief
This function c
lear
s
CTR_CRBG context data
.
*
* \param ctx CTR_DRBG context to clear
* \param ctx
The
CTR_DRBG context to clear
.
*/
void
mbedtls_ctr_drbg_free
(
mbedtls_ctr_drbg_context
*
ctx
);
/**
* \brief Enable / disable prediction resistance (Default: Off)
* \brief This function turns prediction resistance on or off.
* The default value is off.
*
* Note: If enabled, entropy is used for ctx->entropy_len before each call!
* Only use this if you have ample supply of good entropy!
* \note If enabled, entropy is gathered at the beginning of
* every call to mbedtls_ctr_drbg_random_with_add().
* Only use this if your entropy source has sufficient
* throughput.
*
* \param ctx CTR_DRBG context
* \param resistance MBEDTLS_CTR_DRBG_PR_ON or MBEDTLS_CTR_DRBG_PR_OFF
* \param ctx
The
CTR_DRBG context
.
* \param resistance
#
MBEDTLS_CTR_DRBG_PR_ON or
#
MBEDTLS_CTR_DRBG_PR_OFF
.
*/
void
mbedtls_ctr_drbg_set_prediction_resistance
(
mbedtls_ctr_drbg_context
*
ctx
,
int
resistance
);
/**
* \brief Set the amount of entropy grabbed on each (re)seed
* (Default: MBEDTLS_CTR_DRBG_ENTROPY_LEN)
* \brief This function sets the amount of entropy grabbed on each
* seed or reseed. The default value is
* #MBEDTLS_CTR_DRBG_ENTROPY_LEN.
*
* \param ctx CTR_DRBG context
* \param len
A
mount of entropy to grab
* \param ctx
The
CTR_DRBG context
.
* \param len
The a
mount of entropy to grab
.
*/
void
mbedtls_ctr_drbg_set_entropy_len
(
mbedtls_ctr_drbg_context
*
ctx
,
size_t
len
);
/**
* \brief
S
et the reseed interval
*
(D
efault
:
MBEDTLS_CTR_DRBG_RESEED_INTERVAL
)
* \brief
This function s
et
s
the reseed interval
.
*
The d
efault
value is #
MBEDTLS_CTR_DRBG_RESEED_INTERVAL
.
*
* \param ctx CTR_DRBG context
* \param interval
R
eseed interval
* \param ctx
The
CTR_DRBG context
.
* \param interval
The r
eseed interval
.
*/
void
mbedtls_ctr_drbg_set_reseed_interval
(
mbedtls_ctr_drbg_context
*
ctx
,
int
interval
);
/**
* \brief CTR_DRBG reseeding (extracts data from entropy source)
* \brief This function reseeds the CTR_DRBG context, that is
* extracts data from the entropy source.
*
* \param ctx CTR_DRBG context
* \param additional Additional data to add to state
(
Can be NULL
)
* \param len
L
ength of additional data
* \param ctx
The
CTR_DRBG context
.
* \param additional Additional data to add to
the
state
.
Can be NULL
.
* \param len
The l
ength of
the
additional data
.
*
* \return
0
if
success
ful
, or
*
MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED
* \return
\c
0
on
success, or
*
#
MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED
on failure.
*/
int
mbedtls_ctr_drbg_reseed
(
mbedtls_ctr_drbg_context
*
ctx
,
const
unsigned
char
*
additional
,
size_t
len
);
/**
* \brief
CTR_DRBG
update state
* \brief
This function
update
s the
state
of the CTR_DRBG context.
*
* \param ctx CTR_DRBG context
* \param additional
Additional
data to update state with
* \param add_len Length of additional data
* \param ctx
The
CTR_DRBG context
.
* \param additional
The
data to update
the
state with
.
* \param add_len Length of
\p
additional data
.
*
* \note
If
add_len is greater than MBEDTLS_CTR_DRBG_MAX_SEED_INPUT,
*
only the first MBEDTLS_CTR_DRBG_MAX_SEED_INPUT
b
ytes are used
,
*
t
he remaining
on
es are silently discarded.
* \note
If \p
add_len is greater than
#
MBEDTLS_CTR_DRBG_MAX_SEED_INPUT,
* only the first
#
MBEDTLS_CTR_DRBG_MAX_SEED_INPUT
B
ytes are used
.
*
T
he remaining
Byt
es are silently discarded.
*/
void
mbedtls_ctr_drbg_update
(
mbedtls_ctr_drbg_context
*
ctx
,
const
unsigned
char
*
additional
,
size_t
add_len
);
/**
* \brief CTR_DRBG generate random with additional update input
* \brief This function updates a CTR_DRBG instance with additional
* data and uses it to generate random data.
*
*
N
ote
: A
utomatically reseeds if reseed
_
counter is
reach
ed.
*
\n
ote
The function a
utomatically reseeds if
the
reseed
counter is
exceed
ed.
*
* \param p_rng CTR_DRBG context
* \param output Buffer to fill
* \param output_len Length of the buffer
* \param additional Additional data to update with (Can be NULL)
* \param add_len Length of additional data
* \param p_rng The CTR_DRBG context. This must be a pointer to a
* #mbedtls_ctr_drbg_context structure.
* \param output The buffer to fill.
* \param output_len The length of the buffer.
* \param additional Additional data to update. Can be NULL.
* \param add_len The length of the additional data.
*
* \return
0
if
success
ful
, or
*
MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED
,
or
*
MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG
* \return
\c
0
on
success, or
*
#
MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
*
#
MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG
on failure.
*/
int
mbedtls_ctr_drbg_random_with_add
(
void
*
p_rng
,
unsigned
char
*
output
,
size_t
output_len
,
const
unsigned
char
*
additional
,
size_t
add_len
);
/**
* \brief
CTR_DRBG generate random
* \brief
This function uses
CTR_DRBG
to
generate random
data.
*
*
N
ote
: A
utomatically reseeds if reseed
_
counter is
reach
ed.
*
\n
ote
The function a
utomatically reseeds if
the
reseed
counter is
exceed
ed.
*
* \param p_rng CTR_DRBG context
* \param output Buffer to fill
* \param output_len Length of the buffer
* \param p_rng The CTR_DRBG context. This must be a pointer to a
* #mbedtls_ctr_drbg_context structure.
* \param output The buffer to fill.
* \param output_len The length of the buffer.
*
* \return
0 if
success
ful
, or
* MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED
,
or
* MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG
* \return
\c 0 on
success, or
*
#
MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
*
#
MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG
on failure.
*/
int
mbedtls_ctr_drbg_random
(
void
*
p_rng
,
unsigned
char
*
output
,
size_t
output_len
);
#if defined(MBEDTLS_FS_IO)
/**
* \brief
W
rite a seed file
* \brief
This function w
rite
s
a seed file
.
*
* \param ctx CTR_DRBG context
* \param path
N
ame of the file
* \param ctx
The
CTR_DRBG context
.
* \param path
The n
ame of the file
.
*
* \return 0 if successful,
* MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error, or
* MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED
* \return \c 0 on success,
* #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error, or
* #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on
* failure.
*/
int
mbedtls_ctr_drbg_write_seed_file
(
mbedtls_ctr_drbg_context
*
ctx
,
const
char
*
path
);
/**
* \brief
R
ead and update a seed file.
Seed is added to this
* instance
* \brief
This function r
ead
s
and update
s
a seed file.
The seed
*
is added to this
instance
.
*
* \param ctx CTR_DRBG context
* \param path
N
ame of the file
* \param ctx
The
CTR_DRBG context
.
* \param path
The n
ame of the file
.
*
* \return
0 if
success
ful
,
* MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error,
* MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
* MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG
* \return
\c 0 on
success,
*
#
MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error,
*
#
MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
*
#
MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG
on failure.
*/
int
mbedtls_ctr_drbg_update_seed_file
(
mbedtls_ctr_drbg_context
*
ctx
,
const
char
*
path
);
#endif
/* MBEDTLS_FS_IO */
/**
* \brief
C
heckup routine
* \brief
The CTR_DRBG c
heckup routine
.
*
* \return
0 if
success
ful
, or
1 if the test
fail
ed
* \return
\c 0 on
success, or
\c 1 on
fail
ure.
*/
int
mbedtls_ctr_drbg_self_test
(
int
verbose
);
...
...
app/include/mbedtls/debug.h
View file @
c7673b02
...
...
@@ -2,7 +2,8 @@
* \file debug.h
*
* \brief Functions for controlling and providing debug output from the library.
*
*/
/*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
...
...
Prev
1
2
3
4
5
6
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment