2021-01-12 08:08:33 +01:00
|
|
|
/*
|
|
|
|
* Message Processing Stack, Reader implementation
|
|
|
|
*
|
|
|
|
* Copyright The Mbed TLS Contributors
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* This file is part of Mbed TLS (https://tls.mbed.org)
|
|
|
|
*/
|
|
|
|
|
2021-03-05 06:16:45 +01:00
|
|
|
#include "common.h"
|
|
|
|
|
2021-12-08 16:57:54 +01:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
2021-03-05 06:16:45 +01:00
|
|
|
|
2021-01-28 08:08:08 +01:00
|
|
|
#include "mps_reader.h"
|
|
|
|
#include "mps_common.h"
|
|
|
|
#include "mps_trace.h"
|
2021-01-12 08:08:33 +01:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2021-01-28 10:02:18 +01:00
|
|
|
#if defined(MBEDTLS_MPS_ENABLE_TRACE)
|
|
|
|
static int mbedtls_mps_trace_id = MBEDTLS_MPS_TRACE_BIT_READER;
|
|
|
|
#endif /* MBEDTLS_MPS_ENABLE_TRACE */
|
2021-01-12 10:46:03 +01:00
|
|
|
|
2021-01-12 08:08:33 +01:00
|
|
|
/*
|
|
|
|
* GENERAL NOTE ON CODING STYLE
|
|
|
|
*
|
|
|
|
* The following code intentionally separates memory loads
|
|
|
|
* and stores from other operations (arithmetic or branches).
|
|
|
|
* This leads to the introduction of many local variables
|
|
|
|
* and significantly increases the C-code line count, but
|
|
|
|
* should not increase the size of generated assembly.
|
|
|
|
*
|
2021-02-22 16:18:11 +01:00
|
|
|
* The reason for this is twofold:
|
2021-01-12 08:08:33 +01:00
|
|
|
* (1) It will ease verification efforts using the VST
|
2021-02-22 16:18:11 +01:00
|
|
|
* (Verified Software Toolchain)
|
2021-01-12 08:08:33 +01:00
|
|
|
* whose program logic cannot directly reason
|
|
|
|
* about instructions containing a load or store in
|
|
|
|
* addition to other operations (e.g. *p = *q or
|
|
|
|
* tmp = *p + 42).
|
|
|
|
* (2) Operating on local variables and writing the results
|
|
|
|
* back to the target contexts on success only
|
|
|
|
* allows to maintain structure invariants even
|
|
|
|
* on failure - this in turn has two benefits:
|
|
|
|
* (2.a) If for some reason an error code is not caught
|
|
|
|
* and operation continues, functions are nonetheless
|
|
|
|
* called with sane contexts, reducing the risk
|
|
|
|
* of dangerous behavior.
|
|
|
|
* (2.b) Randomized testing is easier if structures
|
|
|
|
* remain intact even in the face of failing
|
|
|
|
* and/or non-sensical calls.
|
|
|
|
* Moreover, it might even reduce code-size because
|
|
|
|
* the compiler need not write back temporary results
|
|
|
|
* to memory in case of failure.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-02-08 09:04:01 +01:00
|
|
|
static inline int mps_reader_is_accumulating(
|
|
|
|
mbedtls_mps_reader const *rd )
|
|
|
|
{
|
2021-02-22 17:38:56 +01:00
|
|
|
mbedtls_mps_size_t acc_remaining;
|
2021-02-08 09:04:01 +01:00
|
|
|
if( rd->acc == NULL )
|
|
|
|
return( 0 );
|
|
|
|
|
2021-02-22 17:38:56 +01:00
|
|
|
acc_remaining = rd->acc_share.acc_remaining;
|
|
|
|
return( acc_remaining > 0 );
|
2021-02-08 09:04:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int mps_reader_is_producing(
|
|
|
|
mbedtls_mps_reader const *rd )
|
|
|
|
{
|
|
|
|
unsigned char *frag = rd->frag;
|
|
|
|
return( frag == NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int mps_reader_is_consuming(
|
|
|
|
mbedtls_mps_reader const *rd )
|
|
|
|
{
|
|
|
|
return( !mps_reader_is_producing( rd ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline mbedtls_mps_size_t mps_reader_get_fragment_offset(
|
|
|
|
mbedtls_mps_reader const *rd )
|
|
|
|
{
|
|
|
|
unsigned char *acc = rd->acc;
|
2021-02-22 17:38:56 +01:00
|
|
|
mbedtls_mps_size_t frag_offset;
|
2021-02-08 09:04:01 +01:00
|
|
|
|
|
|
|
if( acc == NULL )
|
|
|
|
return( 0 );
|
|
|
|
|
2021-02-22 17:38:56 +01:00
|
|
|
frag_offset = rd->acc_share.frag_offset;
|
|
|
|
return( frag_offset );
|
2021-02-08 09:04:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline mbedtls_mps_size_t mps_reader_serving_from_accumulator(
|
|
|
|
mbedtls_mps_reader const *rd )
|
|
|
|
{
|
2021-02-22 17:38:56 +01:00
|
|
|
mbedtls_mps_size_t frag_offset, end;
|
2021-02-08 09:04:01 +01:00
|
|
|
|
2021-02-22 17:38:56 +01:00
|
|
|
frag_offset = mps_reader_get_fragment_offset( rd );
|
2021-02-08 09:04:01 +01:00
|
|
|
end = rd->end;
|
|
|
|
|
2021-02-22 17:38:56 +01:00
|
|
|
return( end < frag_offset );
|
2021-02-08 09:04:01 +01:00
|
|
|
}
|
|
|
|
|
2021-01-28 10:45:47 +01:00
|
|
|
static inline void mps_reader_zero( mbedtls_mps_reader *rd )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
|
|
|
/* A plain memset() would likely be more efficient,
|
|
|
|
* but the current way of zeroing makes it harder
|
|
|
|
* to overlook fields which should not be zero-initialized.
|
2021-02-08 08:54:19 +01:00
|
|
|
* It's also more suitable for FV efforts since it
|
2021-01-12 08:08:33 +01:00
|
|
|
* doesn't require reasoning about structs being
|
|
|
|
* interpreted as unstructured binary blobs. */
|
2021-01-28 10:45:47 +01:00
|
|
|
static mbedtls_mps_reader const zero =
|
2021-02-08 09:07:35 +01:00
|
|
|
{ .frag = NULL,
|
|
|
|
.frag_len = 0,
|
|
|
|
.commit = 0,
|
|
|
|
.end = 0,
|
|
|
|
.pending = 0,
|
|
|
|
.acc = NULL,
|
|
|
|
.acc_len = 0,
|
|
|
|
.acc_available = 0,
|
|
|
|
.acc_share = { .acc_remaining = 0 }
|
2021-01-12 08:08:33 +01:00
|
|
|
};
|
|
|
|
*rd = zero;
|
|
|
|
}
|
|
|
|
|
2021-01-28 10:45:47 +01:00
|
|
|
int mbedtls_mps_reader_init( mbedtls_mps_reader *rd,
|
|
|
|
unsigned char *acc,
|
|
|
|
mbedtls_mps_size_t acc_len )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
2021-02-08 09:04:01 +01:00
|
|
|
MBEDTLS_MPS_TRACE_INIT( "mbedtls_mps_reader_init" );
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
2021-02-08 09:04:01 +01:00
|
|
|
"* Accumulator size: %u bytes", (unsigned) acc_len );
|
2021-01-12 08:08:33 +01:00
|
|
|
mps_reader_zero( rd );
|
|
|
|
rd->acc = acc;
|
|
|
|
rd->acc_len = acc_len;
|
2021-01-28 10:02:18 +01:00
|
|
|
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
|
|
|
|
2021-01-28 10:45:47 +01:00
|
|
|
int mbedtls_mps_reader_free( mbedtls_mps_reader *rd )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
2021-02-08 09:04:01 +01:00
|
|
|
MBEDTLS_MPS_TRACE_INIT( "mbedtls_mps_reader_free" );
|
2021-01-12 08:08:33 +01:00
|
|
|
mps_reader_zero( rd );
|
2021-01-28 10:02:18 +01:00
|
|
|
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
|
|
|
|
2021-01-28 10:45:47 +01:00
|
|
|
int mbedtls_mps_reader_feed( mbedtls_mps_reader *rd,
|
|
|
|
unsigned char *new_frag,
|
|
|
|
mbedtls_mps_size_t new_frag_len )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
|
|
|
mbedtls_mps_size_t copy_to_acc;
|
2021-02-08 09:04:01 +01:00
|
|
|
MBEDTLS_MPS_TRACE_INIT( "mbedtls_mps_reader_feed" );
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
2021-02-08 09:04:01 +01:00
|
|
|
"* Fragment length: %u bytes", (unsigned) new_frag_len );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
|
|
|
if( new_frag == NULL )
|
2021-01-28 10:02:18 +01:00
|
|
|
MBEDTLS_MPS_TRACE_RETURN( MBEDTLS_ERR_MPS_READER_INVALID_ARG );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-02-08 09:04:01 +01:00
|
|
|
MBEDTLS_MPS_STATE_VALIDATE_RAW( mps_reader_is_producing( rd ),
|
2021-01-28 10:45:47 +01:00
|
|
|
"mbedtls_mps_reader_feed() requires reader to be in producing mode" );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-02-08 09:04:01 +01:00
|
|
|
if( mps_reader_is_accumulating( rd ) )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
2021-02-08 09:04:01 +01:00
|
|
|
unsigned char *acc = rd->acc;
|
2021-03-08 17:23:26 +01:00
|
|
|
mbedtls_mps_size_t acc_remaining = rd->acc_share.acc_remaining;
|
|
|
|
mbedtls_mps_size_t acc_available = rd->acc_available;
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-02-08 09:04:01 +01:00
|
|
|
/* Skip over parts of the accumulator that have already been filled. */
|
2021-03-08 17:23:26 +01:00
|
|
|
acc += acc_available;
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-03-08 17:23:26 +01:00
|
|
|
copy_to_acc = acc_remaining;
|
2021-01-12 08:08:33 +01:00
|
|
|
if( copy_to_acc > new_frag_len )
|
|
|
|
copy_to_acc = new_frag_len;
|
|
|
|
|
2021-02-08 09:04:01 +01:00
|
|
|
/* Copy new contents to accumulator. */
|
2021-03-08 17:45:04 +01:00
|
|
|
memcpy( acc, new_frag, copy_to_acc );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
2021-01-28 10:02:18 +01:00
|
|
|
"Copy new data of size %u of %u into accumulator at offset %u",
|
2021-03-08 17:23:26 +01:00
|
|
|
(unsigned) copy_to_acc, (unsigned) new_frag_len, (unsigned) acc_available );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
|
|
|
/* Check if, with the new fragment, we have enough data. */
|
2021-03-08 17:23:26 +01:00
|
|
|
acc_remaining -= copy_to_acc;
|
|
|
|
if( acc_remaining > 0 )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
2021-02-08 09:04:01 +01:00
|
|
|
/* We need to accumulate more data. Stay in producing mode. */
|
2021-03-08 17:23:26 +01:00
|
|
|
acc_available += copy_to_acc;
|
|
|
|
rd->acc_share.acc_remaining = acc_remaining;
|
|
|
|
rd->acc_available = acc_available;
|
2021-01-28 10:02:18 +01:00
|
|
|
MBEDTLS_MPS_TRACE_RETURN( MBEDTLS_ERR_MPS_READER_NEED_MORE );
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
|
|
|
|
2021-02-08 09:04:01 +01:00
|
|
|
/* We have filled the accumulator: Move to consuming mode. */
|
|
|
|
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
2021-01-28 10:02:18 +01:00
|
|
|
"Enough data available to serve user request" );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-02-08 09:04:01 +01:00
|
|
|
/* Remember overlap of accumulator and fragment. */
|
2021-03-08 17:23:26 +01:00
|
|
|
rd->acc_share.frag_offset = acc_available;
|
|
|
|
acc_available += copy_to_acc;
|
|
|
|
rd->acc_available = acc_available;
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
2021-02-08 09:04:01 +01:00
|
|
|
else /* Not accumulating */
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
|
|
|
rd->acc_share.frag_offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rd->frag = new_frag;
|
|
|
|
rd->frag_len = new_frag_len;
|
|
|
|
rd->commit = 0;
|
|
|
|
rd->end = 0;
|
2021-01-28 10:02:18 +01:00
|
|
|
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-28 10:45:47 +01:00
|
|
|
int mbedtls_mps_reader_get( mbedtls_mps_reader *rd,
|
|
|
|
mbedtls_mps_size_t desired,
|
|
|
|
unsigned char **buffer,
|
|
|
|
mbedtls_mps_size_t *buflen )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
2021-02-08 09:04:01 +01:00
|
|
|
unsigned char *frag;
|
2021-02-22 17:38:56 +01:00
|
|
|
mbedtls_mps_size_t frag_len, frag_offset, end, frag_fetched, frag_remaining;
|
2021-02-08 09:04:01 +01:00
|
|
|
MBEDTLS_MPS_TRACE_INIT( "mbedtls_mps_reader_get" );
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
2021-02-08 09:04:01 +01:00
|
|
|
"* Bytes requested: %u", (unsigned) desired );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-02-08 09:04:01 +01:00
|
|
|
MBEDTLS_MPS_STATE_VALIDATE_RAW( mps_reader_is_consuming( rd ),
|
2021-01-28 10:45:47 +01:00
|
|
|
"mbedtls_mps_reader_get() requires reader to be in consuming mode" );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-02-08 09:04:01 +01:00
|
|
|
end = rd->end;
|
2021-02-22 17:38:56 +01:00
|
|
|
frag_offset = mps_reader_get_fragment_offset( rd );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
|
|
|
/* Check if we're still serving from the accumulator. */
|
2021-02-08 09:04:01 +01:00
|
|
|
if( mps_reader_serving_from_accumulator( rd ) )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
2021-02-22 17:46:06 +01:00
|
|
|
/* Illustration of supported and unsupported cases:
|
|
|
|
*
|
|
|
|
* - Allowed #1
|
|
|
|
*
|
|
|
|
* +-----------------------------------+
|
|
|
|
* | frag |
|
|
|
|
* +-----------------------------------+
|
|
|
|
*
|
|
|
|
* end end+desired
|
|
|
|
* | |
|
|
|
|
* +-----v-------v-------------+
|
|
|
|
* | acc |
|
|
|
|
* +---------------------------+
|
|
|
|
* | |
|
2021-03-26 20:20:49 +01:00
|
|
|
* frag_offset acc_available
|
2021-02-22 17:46:06 +01:00
|
|
|
*
|
|
|
|
* - Allowed #2
|
|
|
|
*
|
|
|
|
* +-----------------------------------+
|
|
|
|
* | frag |
|
|
|
|
* +-----------------------------------+
|
|
|
|
*
|
|
|
|
* end end+desired
|
|
|
|
* | |
|
|
|
|
* +----------v----------------v
|
|
|
|
* | acc |
|
|
|
|
* +---------------------------+
|
|
|
|
* | |
|
2021-03-26 20:20:49 +01:00
|
|
|
* frag_offset acc_available
|
2021-02-22 17:46:06 +01:00
|
|
|
*
|
|
|
|
* - Not allowed #1 (could be served, but we don't actually use it):
|
|
|
|
*
|
|
|
|
* +-----------------------------------+
|
|
|
|
* | frag |
|
|
|
|
* +-----------------------------------+
|
|
|
|
*
|
|
|
|
* end end+desired
|
|
|
|
* | |
|
|
|
|
* +------v-------------v------+
|
|
|
|
* | acc |
|
|
|
|
* +---------------------------+
|
|
|
|
* | |
|
2021-03-26 20:20:49 +01:00
|
|
|
* frag_offset acc_available
|
2021-02-22 17:46:06 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* - Not allowed #2 (can't be served with a contiguous buffer):
|
|
|
|
*
|
|
|
|
* +-----------------------------------+
|
|
|
|
* | frag |
|
|
|
|
* +-----------------------------------+
|
|
|
|
*
|
|
|
|
* end end + desired
|
|
|
|
* | |
|
|
|
|
* +------v--------------------+ v
|
|
|
|
* | acc |
|
|
|
|
* +---------------------------+
|
|
|
|
* | |
|
2021-03-26 20:20:49 +01:00
|
|
|
* frag_offset acc_available
|
2021-02-22 17:46:06 +01:00
|
|
|
*
|
|
|
|
* In case of Allowed #2 we're switching to serve from
|
|
|
|
* `frag` starting from the next call to mbedtls_mps_reader_get().
|
|
|
|
*/
|
|
|
|
|
2021-02-08 09:04:01 +01:00
|
|
|
unsigned char *acc;
|
|
|
|
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
2021-01-28 10:02:18 +01:00
|
|
|
"Serve the request from the accumulator" );
|
2021-02-22 17:38:56 +01:00
|
|
|
if( frag_offset - end < desired )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
2021-02-22 17:38:56 +01:00
|
|
|
mbedtls_mps_size_t acc_available;
|
|
|
|
acc_available = rd->acc_available;
|
|
|
|
if( acc_available - end != desired )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
|
|
|
/* It might be possible to serve some of these situations by
|
|
|
|
* making additional space in the accumulator, removing those
|
|
|
|
* parts that have already been committed.
|
|
|
|
* On the other hand, this brings additional complexity and
|
|
|
|
* enlarges the code size, while there doesn't seem to be a use
|
|
|
|
* case where we don't attempt exactly the same `get` calls when
|
|
|
|
* resuming on a reader than what we tried before pausing it.
|
|
|
|
* If we believe we adhere to this restricted usage throughout
|
|
|
|
* the library, this check is a good opportunity to
|
|
|
|
* validate this. */
|
2021-01-28 10:02:18 +01:00
|
|
|
MBEDTLS_MPS_TRACE_RETURN(
|
|
|
|
MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS );
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-08 09:04:01 +01:00
|
|
|
acc = rd->acc;
|
2021-01-12 08:08:33 +01:00
|
|
|
acc += end;
|
2021-02-08 09:04:01 +01:00
|
|
|
|
2021-01-12 08:08:33 +01:00
|
|
|
*buffer = acc;
|
|
|
|
if( buflen != NULL )
|
|
|
|
*buflen = desired;
|
|
|
|
|
|
|
|
end += desired;
|
|
|
|
rd->end = end;
|
|
|
|
rd->pending = 0;
|
|
|
|
|
2021-01-28 10:02:18 +01:00
|
|
|
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Attempt to serve the request from the current fragment */
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
2021-01-28 10:02:18 +01:00
|
|
|
"Serve the request from the current fragment." );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-02-22 17:38:56 +01:00
|
|
|
frag_len = rd->frag_len;
|
|
|
|
frag_fetched = end - frag_offset; /* The amount of data from the current
|
|
|
|
* fragment that has already been passed
|
|
|
|
* to the user. */
|
|
|
|
frag_remaining = frag_len - frag_fetched; /* Remaining data in fragment */
|
2021-01-12 08:08:33 +01:00
|
|
|
|
|
|
|
/* Check if we can serve the read request from the fragment. */
|
|
|
|
if( frag_remaining < desired )
|
|
|
|
{
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
2021-01-28 10:02:18 +01:00
|
|
|
"There's not enough data in the current fragment "
|
|
|
|
"to serve the request." );
|
2021-01-12 08:08:33 +01:00
|
|
|
/* There's not enough data in the current fragment,
|
|
|
|
* so either just RETURN what we have or fail. */
|
|
|
|
if( buflen == NULL )
|
|
|
|
{
|
|
|
|
if( frag_remaining > 0 )
|
|
|
|
{
|
|
|
|
rd->pending = desired - frag_remaining;
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
2021-01-28 10:02:18 +01:00
|
|
|
"Remember to collect %u bytes before re-opening",
|
2021-01-12 08:08:33 +01:00
|
|
|
(unsigned) rd->pending );
|
|
|
|
}
|
2021-01-28 10:02:18 +01:00
|
|
|
MBEDTLS_MPS_TRACE_RETURN( MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
desired = frag_remaining;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There's enough data in the current fragment to serve the
|
|
|
|
* (potentially modified) read request. */
|
2021-02-08 09:04:01 +01:00
|
|
|
|
|
|
|
frag = rd->frag;
|
|
|
|
frag += frag_fetched;
|
|
|
|
|
2021-01-12 08:08:33 +01:00
|
|
|
*buffer = frag;
|
|
|
|
if( buflen != NULL )
|
|
|
|
*buflen = desired;
|
|
|
|
|
|
|
|
end += desired;
|
|
|
|
rd->end = end;
|
|
|
|
rd->pending = 0;
|
2021-01-28 10:02:18 +01:00
|
|
|
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
|
|
|
|
2021-01-28 10:45:47 +01:00
|
|
|
int mbedtls_mps_reader_commit( mbedtls_mps_reader *rd )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
mbedtls_mps_size_t end;
|
2021-02-08 09:04:01 +01:00
|
|
|
MBEDTLS_MPS_TRACE_INIT( "mbedtls_mps_reader_commit" );
|
|
|
|
MBEDTLS_MPS_STATE_VALIDATE_RAW( mps_reader_is_consuming( rd ),
|
2021-01-28 10:45:47 +01:00
|
|
|
"mbedtls_mps_reader_commit() requires reader to be in consuming mode" );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
|
|
|
end = rd->end;
|
|
|
|
rd->commit = end;
|
|
|
|
|
2021-01-28 10:02:18 +01:00
|
|
|
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
|
|
|
|
2021-01-28 10:45:47 +01:00
|
|
|
int mbedtls_mps_reader_reclaim( mbedtls_mps_reader *rd,
|
2021-02-22 17:04:06 +01:00
|
|
|
int *paused )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
|
|
|
unsigned char *frag, *acc;
|
|
|
|
mbedtls_mps_size_t pending, commit;
|
2021-02-22 17:38:56 +01:00
|
|
|
mbedtls_mps_size_t acc_len, frag_offset, frag_len;
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
MBEDTLS_MPS_TRACE_INIT( "mbedtls_mps_reader_reclaim" );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
|
|
|
if( paused != NULL )
|
|
|
|
*paused = 0;
|
|
|
|
|
2021-02-08 09:04:01 +01:00
|
|
|
MBEDTLS_MPS_STATE_VALIDATE_RAW( mps_reader_is_consuming( rd ),
|
2021-02-22 17:38:56 +01:00
|
|
|
"mbedtls_mps_reader_reclaim() requires reader to be in consuming mode" );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-02-22 17:38:56 +01:00
|
|
|
frag = rd->frag;
|
|
|
|
acc = rd->acc;
|
|
|
|
pending = rd->pending;
|
|
|
|
commit = rd->commit;
|
|
|
|
frag_len = rd->frag_len;
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-02-22 17:38:56 +01:00
|
|
|
frag_offset = mps_reader_get_fragment_offset( rd );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
|
|
|
if( pending == 0 )
|
|
|
|
{
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
2021-01-28 10:02:18 +01:00
|
|
|
"No unsatisfied read-request has been logged." );
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
|
2021-01-12 08:08:33 +01:00
|
|
|
/* Check if there's data left to be consumed. */
|
2021-02-22 17:38:56 +01:00
|
|
|
if( commit < frag_offset || commit - frag_offset < frag_len )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
2021-01-28 10:02:18 +01:00
|
|
|
"There is data left to be consumed." );
|
2021-01-12 08:08:33 +01:00
|
|
|
rd->end = commit;
|
2021-01-28 10:02:18 +01:00
|
|
|
MBEDTLS_MPS_TRACE_RETURN( MBEDTLS_ERR_MPS_READER_DATA_LEFT );
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
|
2021-02-08 09:07:35 +01:00
|
|
|
rd->acc_available = 0;
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
rd->acc_share.acc_remaining = 0;
|
|
|
|
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
"Fragment has been fully processed and committed." );
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
int overflow;
|
|
|
|
|
|
|
|
mbedtls_mps_size_t acc_backup_offset;
|
|
|
|
mbedtls_mps_size_t acc_backup_len;
|
2021-01-12 08:08:33 +01:00
|
|
|
mbedtls_mps_size_t frag_backup_offset;
|
|
|
|
mbedtls_mps_size_t frag_backup_len;
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
|
|
|
|
mbedtls_mps_size_t backup_len;
|
|
|
|
mbedtls_mps_size_t acc_len_needed;
|
|
|
|
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
"There has been an unsatisfied read with %u bytes overhead.",
|
|
|
|
(unsigned) pending );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
|
|
|
if( acc == NULL )
|
|
|
|
{
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
2021-01-28 10:02:18 +01:00
|
|
|
"No accumulator present" );
|
|
|
|
MBEDTLS_MPS_TRACE_RETURN(
|
|
|
|
MBEDTLS_ERR_MPS_READER_NEED_ACCUMULATOR );
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
2021-02-22 17:38:56 +01:00
|
|
|
acc_len = rd->acc_len;
|
2021-01-12 08:08:33 +01:00
|
|
|
|
|
|
|
/* Check if the upper layer has already fetched
|
|
|
|
* and committed the contents of the accumulator. */
|
2021-02-22 17:38:56 +01:00
|
|
|
if( commit < frag_offset )
|
2021-01-12 08:08:33 +01:00
|
|
|
{
|
|
|
|
/* No, accumulator is still being processed. */
|
|
|
|
frag_backup_offset = 0;
|
2021-02-22 17:38:56 +01:00
|
|
|
frag_backup_len = frag_len;
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
acc_backup_offset = commit;
|
2021-02-22 17:38:56 +01:00
|
|
|
acc_backup_len = frag_offset - commit;
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Yes, the accumulator is already processed. */
|
2021-02-22 17:38:56 +01:00
|
|
|
frag_backup_offset = commit - frag_offset;
|
|
|
|
frag_backup_len = frag_len - frag_backup_offset;
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
acc_backup_offset = 0;
|
|
|
|
acc_backup_len = 0;
|
|
|
|
}
|
2021-01-12 08:08:33 +01:00
|
|
|
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
backup_len = acc_backup_len + frag_backup_len;
|
|
|
|
acc_len_needed = backup_len + pending;
|
2021-01-12 08:08:33 +01:00
|
|
|
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
overflow = 0;
|
|
|
|
overflow |= ( backup_len < acc_backup_len );
|
|
|
|
overflow |= ( acc_len_needed < backup_len );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-02-22 17:38:56 +01:00
|
|
|
if( overflow || acc_len < acc_len_needed )
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
{
|
|
|
|
/* Except for the different return code, we behave as if
|
|
|
|
* there hadn't been a call to mbedtls_mps_reader_get()
|
|
|
|
* since the last commit. */
|
|
|
|
rd->end = commit;
|
|
|
|
rd->pending = 0;
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_ERROR,
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
"The accumulator is too small to handle the backup." );
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_ERROR,
|
2021-02-22 17:38:56 +01:00
|
|
|
"* Size: %u", (unsigned) acc_len );
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_ERROR,
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
"* Needed: %u (%u + %u)",
|
|
|
|
(unsigned) acc_len_needed,
|
|
|
|
(unsigned) backup_len, (unsigned) pending );
|
|
|
|
MBEDTLS_MPS_TRACE_RETURN(
|
|
|
|
MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL );
|
|
|
|
}
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
"Fragment backup: %u", (unsigned) frag_backup_len );
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
"Accumulator backup: %u", (unsigned) acc_backup_len );
|
|
|
|
|
|
|
|
/* Move uncommitted parts from the accumulator to the front
|
|
|
|
* of the accumulator. */
|
|
|
|
memmove( acc, acc + acc_backup_offset, acc_backup_len );
|
|
|
|
|
2022-12-04 18:19:59 +01:00
|
|
|
/* Copy uncommitted parts of the current fragment to the
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
* accumulator. */
|
|
|
|
memcpy( acc + acc_backup_len,
|
|
|
|
frag + frag_backup_offset, frag_backup_len );
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-02-08 09:07:35 +01:00
|
|
|
rd->acc_available = backup_len;
|
2021-01-12 08:08:33 +01:00
|
|
|
rd->acc_share.acc_remaining = pending;
|
|
|
|
|
|
|
|
if( paused != NULL )
|
|
|
|
*paused = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rd->frag = NULL;
|
|
|
|
rd->frag_len = 0;
|
|
|
|
|
Don't invalidate MPS reader buffers upon commit call
Previously, the semantics of mbedtls_mps_reader_commit() was to invalidate
all buffers previously fetched via mbedtls_mps_reader_get(), forbidding
any further use by the 'consumer'. This was in fact a necessary constraint
for the current implementation, which did some memory moving in
mbedtls_mps_reader_commit().
This commit simplifies the reader's semantics and implementation in
the following way:
- API: A call to mbedtls_mps_reader_commit() does no longer invalidate
the buffers previously obtained via mbedtls_mps_reader_get().
Instead, they can continue to be used until
mbedtls_mps_reader_reclaim() is called.
Calling mbedtls_mps_reader_commit() now only sets a marker
indicating which parts of the data received through
mbedtls_mps_reader_get() need not be backed up once
mbedtls_mps_reader_reclaim() is called. Allowing the user
to call mbedtls_mbedtls_reader_commit() multiple times
before mbedtls_mps_reader_reclaim() is mere convenience:
We'd get exactly the same functionality if instead of
mbedtls_mps_reader_commit(), there was an additional argument
to mbedtls_mps_reader_reclaim() indicating how much data
to retain. However, the present design is more convenient
for the user and doesn't appear to introduce any unnecessary
complexity (anymore), so we stick with it for now.
- Implementation: mbedtls_mps_reader_commit() is now a 1-liner,
setting the 'commit-marker', but doing nothing else.
Instead, the complexity of mbedtls_mp_reader_reclaim()
slightly increases because it has to deal with creating
backups from both the accumulator and the current
fragment. In the previous implementation, which shifted
the accumulator content with every call to
mbedtls_mps_reader_commit(), only the backup from the
fragment was necessary; with the new implementation
which doesn't shift anything in
mbedtls_mps_reader_commit(), we need to do the
accumulator shift in mbedtls_mps_reader_reclaim().
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2021-02-08 07:54:30 +01:00
|
|
|
rd->commit = 0;
|
|
|
|
rd->end = 0;
|
|
|
|
rd->pending = 0;
|
2021-01-12 08:08:33 +01:00
|
|
|
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
2021-01-28 10:02:18 +01:00
|
|
|
"Final state: aa %u, al %u, ar %u",
|
2021-02-08 09:07:35 +01:00
|
|
|
(unsigned) rd->acc_available, (unsigned) rd->acc_len,
|
2021-01-28 10:02:18 +01:00
|
|
|
(unsigned) rd->acc_share.acc_remaining );
|
|
|
|
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
2021-01-12 08:08:33 +01:00
|
|
|
}
|
2021-03-05 06:16:45 +01:00
|
|
|
|
2021-12-08 16:57:54 +01:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
|