mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Merge pull request #7349 from mpg/rm-hash-info
Remove `hash_info` module
This commit is contained in:
@ -42,7 +42,6 @@ set(src_crypto
|
||||
entropy_poll.c
|
||||
error.c
|
||||
gcm.c
|
||||
hash_info.c
|
||||
hkdf.c
|
||||
hmac_drbg.c
|
||||
lmots.c
|
||||
|
@ -107,7 +107,6 @@ OBJS_CRYPTO= \
|
||||
entropy_poll.o \
|
||||
error.o \
|
||||
gcm.o \
|
||||
hash_info.o \
|
||||
hkdf.o \
|
||||
hmac_drbg.o \
|
||||
lmots.o \
|
||||
|
@ -30,8 +30,6 @@
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
#include "hash_info.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(MBEDTLS_ECJPAKE_ALT)
|
||||
@ -217,7 +215,7 @@ static int ecjpake_hash(const mbedtls_md_type_t md_type,
|
||||
unsigned char *p = buf;
|
||||
const unsigned char *end = buf + sizeof(buf);
|
||||
const size_t id_len = strlen(id);
|
||||
unsigned char hash[MBEDTLS_HASH_MAX_SIZE];
|
||||
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||
|
||||
/* Write things to temporary buffer */
|
||||
MBEDTLS_MPI_CHK(ecjpake_write_len_point(&p, end, grp, pf, G));
|
||||
@ -244,7 +242,7 @@ static int ecjpake_hash(const mbedtls_md_type_t md_type,
|
||||
|
||||
/* Turn it into an integer mod n */
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(h, hash,
|
||||
mbedtls_hash_info_get_size(md_type)));
|
||||
mbedtls_md_get_size_from_type(md_type)));
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(h, h, &grp->N));
|
||||
|
||||
cleanup:
|
||||
@ -780,7 +778,7 @@ int mbedtls_ecjpake_derive_secret(mbedtls_ecjpake_context *ctx,
|
||||
unsigned char kx[MBEDTLS_ECP_MAX_BYTES];
|
||||
size_t x_bytes;
|
||||
|
||||
*olen = mbedtls_hash_info_get_size(ctx->md_type);
|
||||
*olen = mbedtls_md_get_size_from_type(ctx->md_type);
|
||||
if (len < *olen) {
|
||||
return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Hash information that's independent from the crypto implementation.
|
||||
*
|
||||
* (See the corresponding header file for usage notes.)
|
||||
*/
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "hash_info.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
typedef struct {
|
||||
psa_algorithm_t psa_alg;
|
||||
mbedtls_md_type_t md_type;
|
||||
unsigned char size;
|
||||
unsigned char block_size;
|
||||
} hash_entry;
|
||||
|
||||
static const hash_entry hash_table[] = {
|
||||
#if defined(MBEDTLS_MD_CAN_MD5)
|
||||
{ PSA_ALG_MD5, MBEDTLS_MD_MD5, 16, 64 },
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_RIPEMD160)
|
||||
{ PSA_ALG_RIPEMD160, MBEDTLS_MD_RIPEMD160, 20, 64 },
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA1)
|
||||
{ PSA_ALG_SHA_1, MBEDTLS_MD_SHA1, 20, 64 },
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA224)
|
||||
{ PSA_ALG_SHA_224, MBEDTLS_MD_SHA224, 28, 64 },
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA256)
|
||||
{ PSA_ALG_SHA_256, MBEDTLS_MD_SHA256, 32, 64 },
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA384)
|
||||
{ PSA_ALG_SHA_384, MBEDTLS_MD_SHA384, 48, 128 },
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA512)
|
||||
{ PSA_ALG_SHA_512, MBEDTLS_MD_SHA512, 64, 128 },
|
||||
#endif
|
||||
{ PSA_ALG_NONE, MBEDTLS_MD_NONE, 0, 0 },
|
||||
};
|
||||
|
||||
/* Get size from MD type */
|
||||
unsigned char mbedtls_hash_info_get_size(mbedtls_md_type_t md_type)
|
||||
{
|
||||
const hash_entry *entry = hash_table;
|
||||
while (entry->md_type != MBEDTLS_MD_NONE &&
|
||||
entry->md_type != md_type) {
|
||||
entry++;
|
||||
}
|
||||
|
||||
return entry->size;
|
||||
}
|
||||
|
||||
/* Get block size from MD type */
|
||||
unsigned char mbedtls_hash_info_get_block_size(mbedtls_md_type_t md_type)
|
||||
{
|
||||
const hash_entry *entry = hash_table;
|
||||
while (entry->md_type != MBEDTLS_MD_NONE &&
|
||||
entry->md_type != md_type) {
|
||||
entry++;
|
||||
}
|
||||
|
||||
return entry->block_size;
|
||||
}
|
||||
|
||||
/* Get PSA from MD */
|
||||
psa_algorithm_t mbedtls_hash_info_psa_from_md(mbedtls_md_type_t md_type)
|
||||
{
|
||||
const hash_entry *entry = hash_table;
|
||||
while (entry->md_type != MBEDTLS_MD_NONE &&
|
||||
entry->md_type != md_type) {
|
||||
entry++;
|
||||
}
|
||||
|
||||
return entry->psa_alg;
|
||||
}
|
||||
|
||||
/* Get MD from PSA */
|
||||
mbedtls_md_type_t mbedtls_hash_info_md_from_psa(psa_algorithm_t psa_alg)
|
||||
{
|
||||
const hash_entry *entry = hash_table;
|
||||
while (entry->md_type != MBEDTLS_MD_NONE &&
|
||||
entry->psa_alg != psa_alg) {
|
||||
entry++;
|
||||
}
|
||||
|
||||
return entry->md_type;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
int mbedtls_md_error_from_psa(psa_status_t status)
|
||||
{
|
||||
switch (status) {
|
||||
case PSA_SUCCESS:
|
||||
return 0;
|
||||
case PSA_ERROR_NOT_SUPPORTED:
|
||||
return MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE;
|
||||
case PSA_ERROR_INVALID_ARGUMENT:
|
||||
return MBEDTLS_ERR_MD_BAD_INPUT_DATA;
|
||||
case PSA_ERROR_INSUFFICIENT_MEMORY:
|
||||
return MBEDTLS_ERR_MD_ALLOC_FAILED;
|
||||
default:
|
||||
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
|
||||
}
|
||||
}
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
@ -1,101 +0,0 @@
|
||||
/**
|
||||
* Hash information that's independent from the crypto implementation.
|
||||
*
|
||||
* This can be used by:
|
||||
* - code based on PSA
|
||||
* - code based on the legacy API
|
||||
* - code based on either of them depending on MBEDTLS_USE_PSA_CRYPTO
|
||||
* - code based on either of them depending on what's available
|
||||
*
|
||||
* Note: this internal module will go away when everything becomes based on
|
||||
* PSA Crypto; it is a helper for the transition while hash algorithms are
|
||||
* still represented using mbedtls_md_type_t in most places even when PSA is
|
||||
* used for the actual crypto computations.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MBEDTLS_HASH_INFO_H
|
||||
#define MBEDTLS_HASH_INFO_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include "mbedtls/md.h"
|
||||
#include "psa/crypto.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
/** \def MBEDTLS_HASH_MAX_SIZE
|
||||
*
|
||||
* Maximum size of a hash based on configuration.
|
||||
*/
|
||||
#if defined(MBEDTLS_MD_C) && ( \
|
||||
!defined(MBEDTLS_PSA_CRYPTO_C) || \
|
||||
MBEDTLS_MD_MAX_SIZE >= PSA_HASH_MAX_SIZE)
|
||||
#define MBEDTLS_HASH_MAX_SIZE MBEDTLS_MD_MAX_SIZE
|
||||
#elif defined(MBEDTLS_PSA_CRYPTO_C) && ( \
|
||||
!defined(MBEDTLS_MD_C) || \
|
||||
PSA_HASH_MAX_SIZE >= MBEDTLS_MD_MAX_SIZE)
|
||||
#define MBEDTLS_HASH_MAX_SIZE PSA_HASH_MAX_SIZE
|
||||
#endif
|
||||
|
||||
/** Get the output length of the given hash type from its MD type.
|
||||
*
|
||||
* \note To get the output length from the PSA alg, use \c PSA_HASH_LENGTH().
|
||||
*
|
||||
* \param md_type The hash MD type.
|
||||
*
|
||||
* \return The output length in bytes, or 0 if not known.
|
||||
*/
|
||||
unsigned char mbedtls_hash_info_get_size(mbedtls_md_type_t md_type);
|
||||
|
||||
/** Get the block size of the given hash type from its MD type.
|
||||
*
|
||||
* \note To get the output length from the PSA alg, use
|
||||
* \c PSA_HASH_BLOCK_LENGTH().
|
||||
*
|
||||
* \param md_type The hash MD type.
|
||||
*
|
||||
* \return The block size in bytes, or 0 if not known.
|
||||
*/
|
||||
unsigned char mbedtls_hash_info_get_block_size(mbedtls_md_type_t md_type);
|
||||
|
||||
/** Get the PSA alg from the MD type.
|
||||
*
|
||||
* \param md_type The hash MD type.
|
||||
*
|
||||
* \return The corresponding PSA algorithm identifier,
|
||||
* or PSA_ALG_NONE if not known.
|
||||
*/
|
||||
psa_algorithm_t mbedtls_hash_info_psa_from_md(mbedtls_md_type_t md_type);
|
||||
|
||||
/** Get the MD type alg from the PSA algorithm identifier.
|
||||
*
|
||||
* \param psa_alg The PSA hash algorithm.
|
||||
*
|
||||
* \return The corresponding MD type,
|
||||
* or MBEDTLS_MD_NONE if not known.
|
||||
*/
|
||||
mbedtls_md_type_t mbedtls_hash_info_md_from_psa(psa_algorithm_t psa_alg);
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
/** Convert PSA status to MD error code.
|
||||
*
|
||||
* \param status PSA status.
|
||||
*
|
||||
* \return The corresponding MD error code,
|
||||
*/
|
||||
int MBEDTLS_DEPRECATED mbedtls_md_error_from_psa(psa_status_t status);
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
#endif /* MBEDTLS_HASH_INFO_H */
|
107
library/md.c
107
library/md.c
@ -52,8 +52,13 @@
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/sha512.h"
|
||||
|
||||
#if defined(MBEDTLS_MD_SOME_PSA)
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C)
|
||||
#include <psa/crypto.h>
|
||||
#include "md_psa.h"
|
||||
#include "mbedtls/psa_util.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD_SOME_PSA)
|
||||
#include "psa_crypto_core.h"
|
||||
#endif
|
||||
|
||||
@ -65,6 +70,11 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/* See comment above MBEDTLS_MD_MAX_SIZE in md.h */
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C) && MBEDTLS_MD_MAX_SIZE < PSA_HASH_MAX_SIZE
|
||||
#error "Internal error: MBEDTLS_MD_MAX_SIZE < PSA_HASH_MAX_SIZE"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD_CAN_MD5)
|
||||
const mbedtls_md_info_t mbedtls_md5_info = {
|
||||
"MD5",
|
||||
@ -210,20 +220,6 @@ static int md_can_use_psa(const mbedtls_md_info_t *info)
|
||||
|
||||
return psa_can_do_hash(alg);
|
||||
}
|
||||
|
||||
static int mbedtls_md_error_from_psa(psa_status_t status)
|
||||
{
|
||||
switch (status) {
|
||||
case PSA_SUCCESS:
|
||||
return 0;
|
||||
case PSA_ERROR_NOT_SUPPORTED:
|
||||
return MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE;
|
||||
case PSA_ERROR_INSUFFICIENT_MEMORY:
|
||||
return MBEDTLS_ERR_MD_ALLOC_FAILED;
|
||||
default:
|
||||
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_MD_SOME_PSA */
|
||||
|
||||
void mbedtls_md_init(mbedtls_md_context_t *ctx)
|
||||
@ -678,6 +674,87 @@ mbedtls_md_type_t mbedtls_md_get_type(const mbedtls_md_info_t *md_info)
|
||||
return md_info->type;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C)
|
||||
psa_algorithm_t mbedtls_md_psa_alg_from_type(mbedtls_md_type_t md_type)
|
||||
{
|
||||
switch (md_type) {
|
||||
#if defined(MBEDTLS_MD_CAN_MD5)
|
||||
case MBEDTLS_MD_MD5:
|
||||
return PSA_ALG_MD5;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_RIPEMD160)
|
||||
case MBEDTLS_MD_RIPEMD160:
|
||||
return PSA_ALG_RIPEMD160;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA1)
|
||||
case MBEDTLS_MD_SHA1:
|
||||
return PSA_ALG_SHA_1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA224)
|
||||
case MBEDTLS_MD_SHA224:
|
||||
return PSA_ALG_SHA_224;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA256)
|
||||
case MBEDTLS_MD_SHA256:
|
||||
return PSA_ALG_SHA_256;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA384)
|
||||
case MBEDTLS_MD_SHA384:
|
||||
return PSA_ALG_SHA_384;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA512)
|
||||
case MBEDTLS_MD_SHA512:
|
||||
return PSA_ALG_SHA_512;
|
||||
#endif
|
||||
default:
|
||||
return PSA_ALG_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_md_type_t mbedtls_md_type_from_psa_alg(psa_algorithm_t psa_alg)
|
||||
{
|
||||
switch (psa_alg) {
|
||||
#if defined(MBEDTLS_MD_CAN_MD5)
|
||||
case PSA_ALG_MD5:
|
||||
return MBEDTLS_MD_MD5;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_RIPEMD160)
|
||||
case PSA_ALG_RIPEMD160:
|
||||
return MBEDTLS_MD_RIPEMD160;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA1)
|
||||
case PSA_ALG_SHA_1:
|
||||
return MBEDTLS_MD_SHA1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA224)
|
||||
case PSA_ALG_SHA_224:
|
||||
return MBEDTLS_MD_SHA224;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA256)
|
||||
case PSA_ALG_SHA_256:
|
||||
return MBEDTLS_MD_SHA256;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA384)
|
||||
case PSA_ALG_SHA_384:
|
||||
return MBEDTLS_MD_SHA384;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD_CAN_SHA512)
|
||||
case PSA_ALG_SHA_512:
|
||||
return MBEDTLS_MD_SHA512;
|
||||
#endif
|
||||
default:
|
||||
return MBEDTLS_MD_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
int mbedtls_md_error_from_psa(psa_status_t status)
|
||||
{
|
||||
return PSA_TO_MBEDTLS_ERR_LIST(status, psa_to_md_errors,
|
||||
psa_generic_status_to_mbedtls);
|
||||
}
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* Functions above this separator are part of MBEDTLS_MD_LIGHT, *
|
||||
* functions below are only available when MBEDTLS_MD_C is set. *
|
||||
|
60
library/md_psa.h
Normal file
60
library/md_psa.h
Normal file
@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Translation between MD and PSA identifiers (algorithms, errors).
|
||||
*
|
||||
* Note: this internal module will go away when everything becomes based on
|
||||
* PSA Crypto; it is a helper for the transition period.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MBEDTLS_MD_PSA_H
|
||||
#define MBEDTLS_MD_PSA_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include "mbedtls/md.h"
|
||||
#include "psa/crypto.h"
|
||||
|
||||
/**
|
||||
* \brief This function returns the PSA algorithm identifier
|
||||
* associated with the given digest type.
|
||||
*
|
||||
* \param md_type The type of digest to search for.
|
||||
*
|
||||
* \return The PSA algorithm identifier associated with \p md_type.
|
||||
* \return PSA_ALG_NONE if the algorithm is not supported.
|
||||
*/
|
||||
psa_algorithm_t mbedtls_md_psa_alg_from_type(mbedtls_md_type_t md_type);
|
||||
|
||||
/**
|
||||
* \brief This function returns the given digest type
|
||||
* associated with the PSA algorithm identifier.
|
||||
*
|
||||
* \param psa_alg The PSA algorithm identifier to search for.
|
||||
*
|
||||
* \return The MD type associated with \p psa_alg.
|
||||
* \return MBEDTLS_MD_NONE if the algorithm is not supported.
|
||||
*/
|
||||
mbedtls_md_type_t mbedtls_md_type_from_psa_alg(psa_algorithm_t psa_alg);
|
||||
|
||||
/** Convert PSA status to MD error code.
|
||||
*
|
||||
* \param status PSA status.
|
||||
*
|
||||
* \return The corresponding MD error code,
|
||||
*/
|
||||
int mbedtls_md_error_from_psa(psa_status_t status);
|
||||
|
||||
#endif /* MBEDTLS_MD_PSA_H */
|
@ -29,7 +29,6 @@
|
||||
#include "mbedtls/cipher.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "hash_info.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
@ -25,8 +25,6 @@
|
||||
#include "pkwrite.h"
|
||||
#include "pk_internal.h"
|
||||
|
||||
#include "hash_info.h"
|
||||
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
@ -42,6 +40,7 @@
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C)
|
||||
#include "mbedtls/psa_util.h"
|
||||
#include "md_psa.h"
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
@ -418,7 +417,7 @@ static inline int pk_hashlen_helper(mbedtls_md_type_t md_alg, size_t *hash_len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
*hash_len = mbedtls_hash_info_get_size(md_alg);
|
||||
*hash_len = mbedtls_md_get_size_from_type(md_alg);
|
||||
|
||||
if (*hash_len == 0) {
|
||||
return -1;
|
||||
@ -567,7 +566,7 @@ int mbedtls_pk_verify_ext(mbedtls_pk_type_t type, const void *options,
|
||||
psa_status_t status = PSA_ERROR_DATA_CORRUPT;
|
||||
psa_status_t destruction_status = PSA_ERROR_DATA_CORRUPT;
|
||||
|
||||
psa_algorithm_t psa_md_alg = mbedtls_hash_info_psa_from_md(md_alg);
|
||||
psa_algorithm_t psa_md_alg = mbedtls_md_psa_alg_from_type(md_alg);
|
||||
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_algorithm_t psa_sig_alg = PSA_ALG_RSA_PSS_ANY_SALT(psa_md_alg);
|
||||
@ -735,7 +734,7 @@ int mbedtls_pk_sign_ext(mbedtls_pk_type_t pk_type,
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
psa_md_alg = mbedtls_hash_info_psa_from_md(md_alg);
|
||||
psa_md_alg = mbedtls_md_psa_alg_from_type(md_alg);
|
||||
if (psa_md_alg == 0) {
|
||||
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "pk_wrap.h"
|
||||
#include "pk_internal.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "md_psa.h"
|
||||
|
||||
/* Even if RSA not activated, for the sake of RSA-alt */
|
||||
#include "mbedtls/rsa.h"
|
||||
@ -47,7 +48,6 @@
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#include "psa/crypto.h"
|
||||
#include "hash_info.h"
|
||||
|
||||
#if defined(MBEDTLS_PK_CAN_ECDSA_SOME)
|
||||
#include "mbedtls/asn1write.h"
|
||||
@ -205,7 +205,7 @@ static int rsa_verify_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
|
||||
int key_len;
|
||||
unsigned char buf[MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES];
|
||||
psa_algorithm_t psa_alg_md =
|
||||
PSA_ALG_RSA_PKCS1V15_SIGN(mbedtls_hash_info_psa_from_md(md_alg));
|
||||
PSA_ALG_RSA_PKCS1V15_SIGN(mbedtls_md_psa_alg_from_type(md_alg));
|
||||
size_t rsa_len = mbedtls_rsa_get_len(rsa);
|
||||
|
||||
if (md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len) {
|
||||
@ -357,7 +357,7 @@ static int rsa_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
|
||||
((void) p_rng);
|
||||
|
||||
psa_algorithm_t psa_md_alg;
|
||||
psa_md_alg = mbedtls_hash_info_psa_from_md(md_alg);
|
||||
psa_md_alg = mbedtls_md_psa_alg_from_type(md_alg);
|
||||
if (psa_md_alg == 0) {
|
||||
return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
|
||||
}
|
||||
@ -930,10 +930,10 @@ static int ecdsa_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
|
||||
psa_status_t status;
|
||||
#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
|
||||
psa_algorithm_t psa_sig_md =
|
||||
PSA_ALG_DETERMINISTIC_ECDSA(mbedtls_hash_info_psa_from_md(md_alg));
|
||||
PSA_ALG_DETERMINISTIC_ECDSA(mbedtls_md_psa_alg_from_type(md_alg));
|
||||
#else
|
||||
psa_algorithm_t psa_sig_md =
|
||||
PSA_ALG_ECDSA(mbedtls_hash_info_psa_from_md(md_alg));
|
||||
PSA_ALG_ECDSA(mbedtls_md_psa_alg_from_type(md_alg));
|
||||
#endif
|
||||
#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
|
||||
psa_ecc_family_t curve = pk->ec_family;
|
||||
@ -1631,12 +1631,12 @@ static int pk_opaque_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
|
||||
|
||||
#if defined(MBEDTLS_PK_CAN_ECDSA_SIGN)
|
||||
if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type)) {
|
||||
alg = PSA_ALG_ECDSA(mbedtls_hash_info_psa_from_md(md_alg));
|
||||
alg = PSA_ALG_ECDSA(mbedtls_md_psa_alg_from_type(md_alg));
|
||||
} else
|
||||
#endif /* MBEDTLS_PK_CAN_ECDSA_SIGN */
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
if (PSA_KEY_TYPE_IS_RSA(type)) {
|
||||
alg = PSA_ALG_RSA_PKCS1V15_SIGN(mbedtls_hash_info_psa_from_md(md_alg));
|
||||
alg = PSA_ALG_RSA_PKCS1V15_SIGN(mbedtls_md_psa_alg_from_type(md_alg));
|
||||
} else
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE;
|
||||
|
@ -39,7 +39,6 @@
|
||||
#include "mbedtls/des.h"
|
||||
#endif
|
||||
|
||||
#include "hash_info.h"
|
||||
#include "mbedtls/psa_util.h"
|
||||
|
||||
#if defined(MBEDTLS_ASN1_PARSE_C)
|
||||
@ -290,7 +289,7 @@ int mbedtls_pkcs12_derivation(unsigned char *data, size_t datalen,
|
||||
|
||||
unsigned char diversifier[128];
|
||||
unsigned char salt_block[128], pwd_block[128], hash_block[128] = { 0 };
|
||||
unsigned char hash_output[MBEDTLS_HASH_MAX_SIZE];
|
||||
unsigned char hash_output[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char *p;
|
||||
unsigned char c;
|
||||
int use_password = 0;
|
||||
@ -314,7 +313,7 @@ int mbedtls_pkcs12_derivation(unsigned char *data, size_t datalen,
|
||||
use_password = (pwd && pwdlen != 0);
|
||||
use_salt = (salt && saltlen != 0);
|
||||
|
||||
hlen = mbedtls_hash_info_get_size(md_type);
|
||||
hlen = mbedtls_md_get_size_from_type(md_type);
|
||||
|
||||
if (hlen <= 32) {
|
||||
v = 64;
|
||||
|
@ -44,7 +44,6 @@
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
|
||||
#include "hash_info.h"
|
||||
#include "mbedtls/psa_util.h"
|
||||
|
||||
#if defined(MBEDTLS_ASN1_PARSE_C)
|
||||
|
@ -82,7 +82,7 @@
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/sha512.h"
|
||||
#include "hash_info.h"
|
||||
#include "md_psa.h"
|
||||
|
||||
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(*(array)))
|
||||
|
||||
@ -3610,7 +3610,7 @@ psa_status_t mbedtls_psa_sign_hash_start(
|
||||
operation->ctx->grp.nbits);
|
||||
|
||||
psa_algorithm_t hash_alg = PSA_ALG_SIGN_GET_HASH(alg);
|
||||
operation->md_alg = mbedtls_hash_info_md_from_psa(hash_alg);
|
||||
operation->md_alg = mbedtls_md_type_from_psa_alg(hash_alg);
|
||||
operation->alg = alg;
|
||||
|
||||
/* We only need to store the same length of hash as the private key size
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "psa_crypto_core.h"
|
||||
#include "psa_crypto_ecp.h"
|
||||
#include "psa_crypto_random_impl.h"
|
||||
#include "hash_info.h"
|
||||
#include "md_psa.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -366,7 +366,7 @@ psa_status_t mbedtls_psa_ecdsa_sign_hash(
|
||||
if (PSA_ALG_ECDSA_IS_DETERMINISTIC(alg)) {
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
|
||||
psa_algorithm_t hash_alg = PSA_ALG_SIGN_GET_HASH(alg);
|
||||
mbedtls_md_type_t md_alg = mbedtls_hash_info_md_from_psa(hash_alg);
|
||||
mbedtls_md_type_t md_alg = mbedtls_md_type_from_psa_alg(hash_alg);
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecdsa_sign_det_ext(
|
||||
&ecp->grp, &r, &s,
|
||||
&ecp->d, hash,
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "psa_crypto_random_impl.h"
|
||||
#include "psa_crypto_rsa.h"
|
||||
#include "psa_crypto_hash.h"
|
||||
#include "md_psa.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -37,7 +38,6 @@
|
||||
#include <mbedtls/error.h>
|
||||
#include <mbedtls/pk.h>
|
||||
#include "pk_wrap.h"
|
||||
#include "hash_info.h"
|
||||
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) || \
|
||||
@ -318,7 +318,7 @@ static psa_status_t psa_rsa_decode_md_type(psa_algorithm_t alg,
|
||||
mbedtls_md_type_t *md_alg)
|
||||
{
|
||||
psa_algorithm_t hash_alg = PSA_ALG_SIGN_GET_HASH(alg);
|
||||
*md_alg = mbedtls_hash_info_md_from_psa(hash_alg);
|
||||
*md_alg = mbedtls_md_type_from_psa_alg(hash_alg);
|
||||
|
||||
/* The Mbed TLS RSA module uses an unsigned int for hash length
|
||||
* parameters. Validate that it fits so that we don't risk an
|
||||
@ -332,7 +332,7 @@ static psa_status_t psa_rsa_decode_md_type(psa_algorithm_t alg,
|
||||
if (*md_alg == MBEDTLS_MD_NONE) {
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
if (mbedtls_hash_info_get_size(*md_alg) != hash_length) {
|
||||
if (mbedtls_md_get_size_from_type(*md_alg) != hash_length) {
|
||||
return PSA_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
@ -527,7 +527,7 @@ static int psa_rsa_oaep_set_padding_mode(psa_algorithm_t alg,
|
||||
mbedtls_rsa_context *rsa)
|
||||
{
|
||||
psa_algorithm_t hash_alg = PSA_ALG_RSA_OAEP_GET_HASH(alg);
|
||||
mbedtls_md_type_t md_alg = mbedtls_hash_info_md_from_psa(hash_alg);
|
||||
mbedtls_md_type_t md_alg = mbedtls_md_type_from_psa_alg(hash_alg);
|
||||
|
||||
return mbedtls_rsa_set_padding(rsa, MBEDTLS_RSA_PKCS_V21, md_alg);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@
|
||||
|
||||
/* PSA_SUCCESS is kept at the top of each error table since
|
||||
* it's the most common status when everything functions properly. */
|
||||
#if !defined(MBEDTLS_MD_C) || !defined(MBEDTLS_MD5_C) || defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#if defined(MBEDTLS_MD_LIGHT)
|
||||
const mbedtls_error_pair_t psa_to_md_errors[] =
|
||||
{
|
||||
{ PSA_SUCCESS, 0 },
|
||||
|
@ -46,7 +46,7 @@
|
||||
#include "mbedtls/error.h"
|
||||
#include "constant_time_internal.h"
|
||||
#include "mbedtls/constant_time.h"
|
||||
#include "hash_info.h"
|
||||
#include "md_psa.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -478,7 +478,7 @@ int mbedtls_rsa_set_padding(mbedtls_rsa_context *ctx, int padding,
|
||||
if ((padding == MBEDTLS_RSA_PKCS_V21) &&
|
||||
(hash_id != MBEDTLS_MD_NONE)) {
|
||||
/* Just make sure this hash is supported in this build. */
|
||||
if (mbedtls_hash_info_psa_from_md(hash_id) == PSA_ALG_NONE) {
|
||||
if (mbedtls_md_info_from_type(hash_id) == NULL) {
|
||||
return MBEDTLS_ERR_RSA_INVALID_PADDING;
|
||||
}
|
||||
}
|
||||
@ -1076,7 +1076,7 @@ static int mgf_mask(unsigned char *dst, size_t dlen, unsigned char *src,
|
||||
unsigned char *p;
|
||||
unsigned int hlen;
|
||||
size_t i, use_len;
|
||||
unsigned char mask[MBEDTLS_HASH_MAX_SIZE];
|
||||
unsigned char mask[MBEDTLS_MD_MAX_SIZE];
|
||||
int ret = 0;
|
||||
const mbedtls_md_info_t *md_info;
|
||||
mbedtls_md_context_t md_ctx;
|
||||
@ -1229,7 +1229,7 @@ int mbedtls_rsa_rsaes_oaep_encrypt(mbedtls_rsa_context *ctx,
|
||||
return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
hlen = mbedtls_hash_info_get_size((mbedtls_md_type_t) ctx->hash_id);
|
||||
hlen = mbedtls_md_get_size_from_type((mbedtls_md_type_t) ctx->hash_id);
|
||||
if (hlen == 0) {
|
||||
return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
}
|
||||
@ -1380,7 +1380,7 @@ int mbedtls_rsa_rsaes_oaep_decrypt(mbedtls_rsa_context *ctx,
|
||||
size_t ilen, i, pad_len;
|
||||
unsigned char *p, bad, pad_done;
|
||||
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
|
||||
unsigned char lhash[MBEDTLS_HASH_MAX_SIZE];
|
||||
unsigned char lhash[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned int hlen;
|
||||
|
||||
/*
|
||||
@ -1396,7 +1396,7 @@ int mbedtls_rsa_rsaes_oaep_decrypt(mbedtls_rsa_context *ctx,
|
||||
return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
hlen = mbedtls_hash_info_get_size((mbedtls_md_type_t) ctx->hash_id);
|
||||
hlen = mbedtls_md_get_size_from_type((mbedtls_md_type_t) ctx->hash_id);
|
||||
if (hlen == 0) {
|
||||
return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
}
|
||||
@ -1596,7 +1596,7 @@ static int rsa_rsassa_pss_sign(mbedtls_rsa_context *ctx,
|
||||
|
||||
if (md_alg != MBEDTLS_MD_NONE) {
|
||||
/* Gather length of hash to sign */
|
||||
size_t exp_hashlen = mbedtls_hash_info_get_size(md_alg);
|
||||
size_t exp_hashlen = mbedtls_md_get_size_from_type(md_alg);
|
||||
if (exp_hashlen == 0) {
|
||||
return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
}
|
||||
@ -1606,7 +1606,7 @@ static int rsa_rsassa_pss_sign(mbedtls_rsa_context *ctx,
|
||||
}
|
||||
}
|
||||
|
||||
hlen = mbedtls_hash_info_get_size((mbedtls_md_type_t) ctx->hash_id);
|
||||
hlen = mbedtls_md_get_size_from_type((mbedtls_md_type_t) ctx->hash_id);
|
||||
if (hlen == 0) {
|
||||
return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
}
|
||||
@ -1744,7 +1744,7 @@ static int rsa_rsassa_pkcs1_v15_encode(mbedtls_md_type_t md_alg,
|
||||
|
||||
/* Are we signing hashed or raw data? */
|
||||
if (md_alg != MBEDTLS_MD_NONE) {
|
||||
unsigned char md_size = mbedtls_hash_info_get_size(md_alg);
|
||||
unsigned char md_size = mbedtls_md_get_size_from_type(md_alg);
|
||||
if (md_size == 0) {
|
||||
return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
}
|
||||
@ -1966,7 +1966,7 @@ int mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_rsa_context *ctx,
|
||||
size_t siglen;
|
||||
unsigned char *p;
|
||||
unsigned char *hash_start;
|
||||
unsigned char result[MBEDTLS_HASH_MAX_SIZE];
|
||||
unsigned char result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned int hlen;
|
||||
size_t observed_salt_len, msb;
|
||||
unsigned char buf[MBEDTLS_MPI_MAX_SIZE] = { 0 };
|
||||
@ -1995,7 +1995,7 @@ int mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_rsa_context *ctx,
|
||||
|
||||
if (md_alg != MBEDTLS_MD_NONE) {
|
||||
/* Gather length of hash to sign */
|
||||
size_t exp_hashlen = mbedtls_hash_info_get_size(md_alg);
|
||||
size_t exp_hashlen = mbedtls_md_get_size_from_type(md_alg);
|
||||
if (exp_hashlen == 0) {
|
||||
return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
}
|
||||
@ -2005,7 +2005,7 @@ int mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_rsa_context *ctx,
|
||||
}
|
||||
}
|
||||
|
||||
hlen = mbedtls_hash_info_get_size(mgf1_hash_id);
|
||||
hlen = mbedtls_md_get_size_from_type(mgf1_hash_id);
|
||||
if (hlen == 0) {
|
||||
return MBEDTLS_ERR_RSA_BAD_INPUT_DATA;
|
||||
}
|
||||
|
@ -28,6 +28,9 @@
|
||||
#include "mbedtls/ssl_ciphersuites.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "ssl_misc.h"
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#include "md_psa.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -1966,10 +1969,10 @@ psa_algorithm_t mbedtls_ssl_get_ciphersuite_sig_pk_psa_alg(const mbedtls_ssl_cip
|
||||
case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
|
||||
return PSA_ALG_RSA_PKCS1V15_SIGN(
|
||||
mbedtls_hash_info_psa_from_md(info->mac));
|
||||
mbedtls_md_psa_alg_from_type(info->mac));
|
||||
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
|
||||
return PSA_ALG_ECDSA(mbedtls_hash_info_psa_from_md(info->mac));
|
||||
return PSA_ALG_ECDSA(mbedtls_md_psa_alg_from_type(info->mac));
|
||||
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#include "md_psa.h"
|
||||
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \
|
||||
psa_to_ssl_errors, \
|
||||
psa_generic_status_to_mbedtls)
|
||||
@ -114,7 +115,7 @@ int mbedtls_ssl_cookie_setup(mbedtls_ssl_cookie_ctx *ctx,
|
||||
(void) f_rng;
|
||||
(void) p_rng;
|
||||
|
||||
alg = mbedtls_hash_info_psa_from_md(COOKIE_MD);
|
||||
alg = mbedtls_md_psa_alg_from_type(COOKIE_MD);
|
||||
if (alg == 0) {
|
||||
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
|
||||
}
|
||||
|
@ -30,7 +30,6 @@
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
#include "psa/crypto.h"
|
||||
#include "mbedtls/psa_util.h"
|
||||
#include "hash_info.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD_CAN_MD5)
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#include "md_psa.h"
|
||||
#include "mbedtls/psa_util.h"
|
||||
#include "psa/crypto.h"
|
||||
#endif
|
||||
@ -843,11 +844,11 @@ int mbedtls_ssl_reset_checksum(mbedtls_ssl_context *ssl)
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
status = psa_hash_abort(&ssl->handshake->fin_sha256_psa);
|
||||
if (status != PSA_SUCCESS) {
|
||||
return PSA_TO_MD_ERR(status);
|
||||
return mbedtls_md_error_from_psa(status);
|
||||
}
|
||||
status = psa_hash_setup(&ssl->handshake->fin_sha256_psa, PSA_ALG_SHA_256);
|
||||
if (status != PSA_SUCCESS) {
|
||||
return PSA_TO_MD_ERR(status);
|
||||
return mbedtls_md_error_from_psa(status);
|
||||
}
|
||||
#else
|
||||
mbedtls_md_free(&ssl->handshake->fin_sha256);
|
||||
@ -868,11 +869,11 @@ int mbedtls_ssl_reset_checksum(mbedtls_ssl_context *ssl)
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
status = psa_hash_abort(&ssl->handshake->fin_sha384_psa);
|
||||
if (status != PSA_SUCCESS) {
|
||||
return PSA_TO_MD_ERR(status);
|
||||
return mbedtls_md_error_from_psa(status);
|
||||
}
|
||||
status = psa_hash_setup(&ssl->handshake->fin_sha384_psa, PSA_ALG_SHA_384);
|
||||
if (status != PSA_SUCCESS) {
|
||||
return PSA_TO_MD_ERR(status);
|
||||
return mbedtls_md_error_from_psa(status);
|
||||
}
|
||||
#else
|
||||
mbedtls_md_free(&ssl->handshake->fin_sha384);
|
||||
@ -910,7 +911,7 @@ static int ssl_update_checksum_start(mbedtls_ssl_context *ssl,
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
status = psa_hash_update(&ssl->handshake->fin_sha256_psa, buf, len);
|
||||
if (status != PSA_SUCCESS) {
|
||||
return PSA_TO_MD_ERR(status);
|
||||
return mbedtls_md_error_from_psa(status);
|
||||
}
|
||||
#else
|
||||
ret = mbedtls_md_update(&ssl->handshake->fin_sha256, buf, len);
|
||||
@ -923,7 +924,7 @@ static int ssl_update_checksum_start(mbedtls_ssl_context *ssl,
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
status = psa_hash_update(&ssl->handshake->fin_sha384_psa, buf, len);
|
||||
if (status != PSA_SUCCESS) {
|
||||
return PSA_TO_MD_ERR(status);
|
||||
return mbedtls_md_error_from_psa(status);
|
||||
}
|
||||
#else
|
||||
ret = mbedtls_md_update(&ssl->handshake->fin_sha384, buf, len);
|
||||
@ -940,8 +941,8 @@ static int ssl_update_checksum_sha256(mbedtls_ssl_context *ssl,
|
||||
const unsigned char *buf, size_t len)
|
||||
{
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
return PSA_TO_MD_ERR(psa_hash_update(
|
||||
&ssl->handshake->fin_sha256_psa, buf, len));
|
||||
return mbedtls_md_error_from_psa(psa_hash_update(
|
||||
&ssl->handshake->fin_sha256_psa, buf, len));
|
||||
#else
|
||||
return mbedtls_md_update(&ssl->handshake->fin_sha256, buf, len);
|
||||
#endif
|
||||
@ -953,8 +954,8 @@ static int ssl_update_checksum_sha384(mbedtls_ssl_context *ssl,
|
||||
const unsigned char *buf, size_t len)
|
||||
{
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
return PSA_TO_MD_ERR(psa_hash_update(
|
||||
&ssl->handshake->fin_sha384_psa, buf, len));
|
||||
return mbedtls_md_error_from_psa(psa_hash_update(
|
||||
&ssl->handshake->fin_sha384_psa, buf, len));
|
||||
#else
|
||||
return mbedtls_md_update(&ssl->handshake->fin_sha384, buf, len);
|
||||
#endif
|
||||
@ -6626,7 +6627,7 @@ int ssl_calc_verify_tls_sha256(const mbedtls_ssl_context *ssl,
|
||||
|
||||
exit:
|
||||
psa_hash_abort(&sha256_psa);
|
||||
return PSA_TO_MD_ERR(status);
|
||||
return mbedtls_md_error_from_psa(status);
|
||||
#else
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_md_context_t sha256;
|
||||
@ -6688,7 +6689,7 @@ int ssl_calc_verify_tls_sha384(const mbedtls_ssl_context *ssl,
|
||||
|
||||
exit:
|
||||
psa_hash_abort(&sha384_psa);
|
||||
return PSA_TO_MD_ERR(status);
|
||||
return mbedtls_md_error_from_psa(status);
|
||||
#else
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_md_context_t sha384;
|
||||
@ -7741,7 +7742,7 @@ static int ssl_calc_finished_tls_sha256(
|
||||
exit:
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_hash_abort(&sha256_psa);
|
||||
return PSA_TO_MD_ERR(status);
|
||||
return mbedtls_md_error_from_psa(status);
|
||||
#else
|
||||
mbedtls_md_free(&sha256);
|
||||
return ret;
|
||||
@ -7830,7 +7831,7 @@ static int ssl_calc_finished_tls_sha384(
|
||||
exit:
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_hash_abort(&sha384_psa);
|
||||
return PSA_TO_MD_ERR(status);
|
||||
return mbedtls_md_error_from_psa(status);
|
||||
#else
|
||||
mbedtls_md_free(&sha384);
|
||||
return ret;
|
||||
@ -8292,9 +8293,9 @@ static int ssl_tls12_populate_transform(mbedtls_ssl_transform *transform,
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mac_alg = mbedtls_hash_info_psa_from_md(ciphersuite_info->mac);
|
||||
mac_alg = mbedtls_md_psa_alg_from_type(ciphersuite_info->mac);
|
||||
if (mac_alg == 0) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("mbedtls_hash_info_psa_from_md for %u not found",
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("mbedtls_md_psa_alg_from_type for %u not found",
|
||||
(unsigned) ciphersuite_info->mac));
|
||||
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
|
||||
}
|
||||
@ -8741,7 +8742,7 @@ int mbedtls_ssl_get_key_exchange_md_tls1_2(mbedtls_ssl_context *ssl,
|
||||
{
|
||||
psa_status_t status;
|
||||
psa_hash_operation_t hash_operation = PSA_HASH_OPERATION_INIT;
|
||||
psa_algorithm_t hash_alg = mbedtls_hash_info_psa_from_md(md_alg);
|
||||
psa_algorithm_t hash_alg = mbedtls_md_psa_alg_from_type(md_alg);
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG(3, ("Perform PSA-based computation of digest of ServerKeyExchange"));
|
||||
|
||||
@ -8870,7 +8871,7 @@ unsigned int mbedtls_ssl_tls12_get_preferred_hash_for_sig_alg(
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if (ssl->handshake->key_cert && ssl->handshake->key_cert->key) {
|
||||
psa_algorithm_t psa_hash_alg =
|
||||
mbedtls_hash_info_psa_from_md(hash_alg_received);
|
||||
mbedtls_md_psa_alg_from_type(hash_alg_received);
|
||||
|
||||
if (sig_alg_received == MBEDTLS_SSL_SIG_ECDSA &&
|
||||
!mbedtls_pk_can_do_ext(ssl->handshake->key_cert->key,
|
||||
|
@ -50,8 +50,6 @@
|
||||
#include "mbedtls/platform_util.h"
|
||||
#endif
|
||||
|
||||
#include "hash_info.h"
|
||||
|
||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||
MBEDTLS_CHECK_RETURN_CRITICAL
|
||||
static int ssl_write_renegotiation_ext(mbedtls_ssl_context *ssl,
|
||||
@ -2291,7 +2289,7 @@ start_processing:
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED)
|
||||
if (mbedtls_ssl_ciphersuite_uses_server_signature(ciphersuite_info)) {
|
||||
size_t sig_len, hashlen;
|
||||
unsigned char hash[MBEDTLS_HASH_MAX_SIZE];
|
||||
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||
|
||||
mbedtls_md_type_t md_alg = MBEDTLS_MD_NONE;
|
||||
mbedtls_pk_type_t pk_alg = MBEDTLS_PK_NONE;
|
||||
@ -2408,7 +2406,7 @@ start_processing:
|
||||
mbedtls_pk_rsassa_pss_options rsassa_pss_options;
|
||||
rsassa_pss_options.mgf1_hash_id = md_alg;
|
||||
rsassa_pss_options.expected_salt_len =
|
||||
mbedtls_hash_info_get_size(md_alg);
|
||||
mbedtls_md_get_size_from_type(md_alg);
|
||||
if (rsassa_pss_options.expected_salt_len == 0) {
|
||||
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
||||
}
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "constant_time_internal.h"
|
||||
#include "mbedtls/constant_time.h"
|
||||
#include "hash_info.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -3081,7 +3080,7 @@ curve_matching_done:
|
||||
|
||||
size_t dig_signed_len = ssl->out_msg + ssl->out_msglen - dig_signed;
|
||||
size_t hashlen = 0;
|
||||
unsigned char hash[MBEDTLS_HASH_MAX_SIZE];
|
||||
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "ssl_client.h"
|
||||
#include "ssl_tls13_keys.h"
|
||||
#include "ssl_debug_helpers.h"
|
||||
#include "md_psa.h"
|
||||
|
||||
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \
|
||||
psa_to_ssl_errors, \
|
||||
@ -672,7 +673,7 @@ static psa_algorithm_t ssl_tls13_get_ciphersuite_hash_alg(int ciphersuite)
|
||||
ciphersuite_info = mbedtls_ssl_ciphersuite_from_id(ciphersuite);
|
||||
|
||||
if (ciphersuite_info != NULL) {
|
||||
return mbedtls_psa_translate_md(ciphersuite_info->mac);
|
||||
return mbedtls_md_psa_alg_from_type(ciphersuite_info->mac);
|
||||
}
|
||||
|
||||
return PSA_ALG_NONE;
|
||||
@ -850,7 +851,7 @@ static int ssl_tls13_write_binder(mbedtls_ssl_context *ssl,
|
||||
|
||||
/* Get current state of handshake transcript. */
|
||||
ret = mbedtls_ssl_get_handshake_transcript(
|
||||
ssl, mbedtls_hash_info_md_from_psa(hash_alg),
|
||||
ssl, mbedtls_md_type_from_psa_alg(hash_alg),
|
||||
transcript, sizeof(transcript), &transcript_len);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
@ -1126,7 +1127,7 @@ static int ssl_tls13_parse_server_pre_shared_key_ext(mbedtls_ssl_context *ssl,
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (mbedtls_psa_translate_md(ssl->handshake->ciphersuite_info->mac)
|
||||
if (mbedtls_md_psa_alg_from_type(ssl->handshake->ciphersuite_info->mac)
|
||||
!= hash_alg) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(
|
||||
1, ("Invalid ciphersuite for external psk."));
|
||||
@ -2844,7 +2845,7 @@ static int ssl_tls13_postprocess_new_session_ticket(mbedtls_ssl_context *ssl,
|
||||
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
psa_hash_alg = mbedtls_psa_translate_md(ciphersuite_info->mac);
|
||||
psa_hash_alg = mbedtls_md_psa_alg_from_type(ciphersuite_info->mac);
|
||||
hash_length = PSA_HASH_LENGTH(psa_hash_alg);
|
||||
if (hash_length == -1 ||
|
||||
(size_t) hash_length > sizeof(session->resumption_key)) {
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "mbedtls/platform.h"
|
||||
#include "mbedtls/constant_time.h"
|
||||
#include "psa/crypto.h"
|
||||
#include "mbedtls/psa_util.h"
|
||||
#include "md_psa.h"
|
||||
|
||||
#include "ssl_misc.h"
|
||||
#include "ssl_tls13_invasive.h"
|
||||
@ -274,7 +274,7 @@ static int ssl_tls13_parse_certificate_verify(mbedtls_ssl_context *ssl,
|
||||
goto error;
|
||||
}
|
||||
|
||||
hash_alg = mbedtls_hash_info_psa_from_md(md_alg);
|
||||
hash_alg = mbedtls_md_psa_alg_from_type(md_alg);
|
||||
if (hash_alg == 0) {
|
||||
goto error;
|
||||
}
|
||||
@ -1076,7 +1076,7 @@ static int ssl_tls13_write_certificate_verify_body(mbedtls_ssl_context *ssl,
|
||||
}
|
||||
|
||||
/* Hash verify buffer with indicated hash function */
|
||||
psa_algorithm = mbedtls_hash_info_psa_from_md(md_alg);
|
||||
psa_algorithm = mbedtls_md_psa_alg_from_type(md_alg);
|
||||
status = psa_hash_compute(psa_algorithm,
|
||||
verify_buffer,
|
||||
verify_buffer_len,
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "ssl_tls13_invasive.h"
|
||||
|
||||
#include "psa/crypto.h"
|
||||
#include "md_psa.h"
|
||||
|
||||
#define PSA_TO_MBEDTLS_ERR(status) PSA_TO_MBEDTLS_ERR_LIST(status, \
|
||||
psa_to_ssl_errors, \
|
||||
@ -677,7 +678,7 @@ static int ssl_tls13_key_schedule_stage_application(mbedtls_ssl_context *ssl)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_ssl_handshake_params *handshake = ssl->handshake;
|
||||
psa_algorithm_t const hash_alg = mbedtls_hash_info_psa_from_md(
|
||||
psa_algorithm_t const hash_alg = mbedtls_md_psa_alg_from_type(
|
||||
handshake->ciphersuite_info->mac);
|
||||
|
||||
/*
|
||||
@ -792,7 +793,7 @@ int mbedtls_ssl_tls13_calculate_verify_data(mbedtls_ssl_context *ssl,
|
||||
|
||||
mbedtls_md_type_t const md_type = ssl->handshake->ciphersuite_info->mac;
|
||||
|
||||
psa_algorithm_t hash_alg = mbedtls_hash_info_psa_from_md(
|
||||
psa_algorithm_t hash_alg = mbedtls_md_psa_alg_from_type(
|
||||
ssl->handshake->ciphersuite_info->mac);
|
||||
size_t const hash_len = PSA_HASH_LENGTH(hash_alg);
|
||||
|
||||
@ -1163,7 +1164,7 @@ static int ssl_tls13_generate_early_key(mbedtls_ssl_context *ssl,
|
||||
|
||||
md_type = ciphersuite_info->mac;
|
||||
|
||||
hash_alg = mbedtls_hash_info_psa_from_md(ciphersuite_info->mac);
|
||||
hash_alg = mbedtls_md_psa_alg_from_type(ciphersuite_info->mac);
|
||||
hash_len = PSA_HASH_LENGTH(hash_alg);
|
||||
|
||||
ret = mbedtls_ssl_get_handshake_transcript(ssl, md_type,
|
||||
@ -1291,7 +1292,7 @@ int mbedtls_ssl_tls13_key_schedule_stage_early(mbedtls_ssl_context *ssl)
|
||||
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
hash_alg = mbedtls_hash_info_psa_from_md(handshake->ciphersuite_info->mac);
|
||||
hash_alg = mbedtls_md_psa_alg_from_type(handshake->ciphersuite_info->mac);
|
||||
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED)
|
||||
if (mbedtls_ssl_tls13_key_exchange_mode_with_psk(ssl)) {
|
||||
ret = mbedtls_ssl_tls13_export_handshake_psk(ssl, &psk, &psk_len);
|
||||
@ -1365,7 +1366,7 @@ static int ssl_tls13_generate_handshake_keys(mbedtls_ssl_context *ssl,
|
||||
|
||||
md_type = ciphersuite_info->mac;
|
||||
|
||||
hash_alg = mbedtls_hash_info_psa_from_md(ciphersuite_info->mac);
|
||||
hash_alg = mbedtls_md_psa_alg_from_type(ciphersuite_info->mac);
|
||||
hash_len = PSA_HASH_LENGTH(hash_alg);
|
||||
|
||||
ret = mbedtls_ssl_get_handshake_transcript(ssl, md_type,
|
||||
@ -1472,7 +1473,7 @@ static int ssl_tls13_key_schedule_stage_handshake(mbedtls_ssl_context *ssl)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_ssl_handshake_params *handshake = ssl->handshake;
|
||||
psa_algorithm_t const hash_alg = mbedtls_hash_info_psa_from_md(
|
||||
psa_algorithm_t const hash_alg = mbedtls_md_psa_alg_from_type(
|
||||
handshake->ciphersuite_info->mac);
|
||||
unsigned char *shared_secret = NULL;
|
||||
size_t shared_secret_len = 0;
|
||||
@ -1608,7 +1609,7 @@ static int ssl_tls13_generate_application_keys(
|
||||
|
||||
md_type = handshake->ciphersuite_info->mac;
|
||||
|
||||
hash_alg = mbedtls_hash_info_psa_from_md(handshake->ciphersuite_info->mac);
|
||||
hash_alg = mbedtls_md_psa_alg_from_type(handshake->ciphersuite_info->mac);
|
||||
hash_len = PSA_HASH_LENGTH(hash_alg);
|
||||
|
||||
/* Compute current handshake transcript. It's the caller's responsibility
|
||||
@ -1766,7 +1767,7 @@ int mbedtls_ssl_tls13_compute_resumption_master_secret(mbedtls_ssl_context *ssl)
|
||||
}
|
||||
|
||||
ret = mbedtls_ssl_tls13_derive_resumption_master_secret(
|
||||
mbedtls_psa_translate_md(md_type),
|
||||
mbedtls_md_psa_alg_from_type(md_type),
|
||||
handshake->tls13_master_secrets.app,
|
||||
transcript, transcript_len,
|
||||
&ssl->session_negotiate->app_secrets);
|
||||
@ -1781,7 +1782,7 @@ int mbedtls_ssl_tls13_compute_resumption_master_secret(mbedtls_ssl_context *ssl)
|
||||
MBEDTLS_SSL_DEBUG_BUF(
|
||||
4, "Resumption master secret",
|
||||
ssl->session_negotiate->app_secrets.resumption_master_secret,
|
||||
PSA_HASH_LENGTH(mbedtls_psa_translate_md(md_type)));
|
||||
PSA_HASH_LENGTH(mbedtls_md_psa_alg_from_type(md_type)));
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG(
|
||||
2, ("<= mbedtls_ssl_tls13_compute_resumption_master_secret"));
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/platform.h"
|
||||
#include "mbedtls/constant_time.h"
|
||||
#include "md_psa.h"
|
||||
|
||||
#include "ssl_misc.h"
|
||||
#include "ssl_tls13_keys.h"
|
||||
@ -332,7 +333,7 @@ static int ssl_tls13_offered_psks_check_binder_match(
|
||||
|
||||
/* Get current state of handshake transcript. */
|
||||
ret = mbedtls_ssl_get_handshake_transcript(
|
||||
ssl, mbedtls_hash_info_md_from_psa(psk_hash_alg),
|
||||
ssl, mbedtls_md_type_from_psa_alg(psk_hash_alg),
|
||||
transcript, sizeof(transcript), &transcript_len);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
@ -406,7 +407,7 @@ static int ssl_tls13_select_ciphersuite_for_psk(
|
||||
/* MAC of selected ciphersuite MUST be same with PSK binder if exist.
|
||||
* Otherwise, client should reject.
|
||||
*/
|
||||
if (psk_hash_alg == mbedtls_psa_translate_md(ciphersuite_info->mac)) {
|
||||
if (psk_hash_alg == mbedtls_md_psa_alg_from_type(ciphersuite_info->mac)) {
|
||||
*selected_ciphersuite = cipher_suite;
|
||||
*selected_ciphersuite_info = ciphersuite_info;
|
||||
return 0;
|
||||
@ -612,7 +613,7 @@ static int ssl_tls13_parse_pre_shared_key_ext(
|
||||
|
||||
ret = ssl_tls13_offered_psks_check_binder_match(
|
||||
ssl, binder, binder_len, psk_type,
|
||||
mbedtls_psa_translate_md(ciphersuite_info->mac));
|
||||
mbedtls_md_psa_alg_from_type(ciphersuite_info->mac));
|
||||
if (ret != SSL_TLS1_3_OFFERED_PSK_MATCH) {
|
||||
/* For security reasons, the handshake should be aborted when we
|
||||
* fail to validate a binder value. See RFC 8446 section 4.2.11.2
|
||||
@ -2783,7 +2784,7 @@ static int ssl_tls13_prepare_new_session_ticket(mbedtls_ssl_context *ssl,
|
||||
|
||||
ciphersuite_info =
|
||||
(mbedtls_ssl_ciphersuite_t *) ssl->handshake->ciphersuite_info;
|
||||
psa_hash_alg = mbedtls_psa_translate_md(ciphersuite_info->mac);
|
||||
psa_hash_alg = mbedtls_md_psa_alg_from_type(ciphersuite_info->mac);
|
||||
hash_length = PSA_HASH_LENGTH(psa_hash_alg);
|
||||
if (hash_length == -1 ||
|
||||
(size_t) hash_length > sizeof(session->resumption_key)) {
|
||||
|
@ -47,8 +47,8 @@
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#include "psa/crypto.h"
|
||||
#include "mbedtls/psa_util.h"
|
||||
#include "md_psa.h"
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
#include "hash_info.h"
|
||||
#include "x509_invasive.h"
|
||||
#include "pk_internal.h"
|
||||
|
||||
@ -2024,7 +2024,7 @@ static int x509_crt_verifycrl(mbedtls_x509_crt *crt, mbedtls_x509_crt *ca,
|
||||
const mbedtls_x509_crt_profile *profile)
|
||||
{
|
||||
int flags = 0;
|
||||
unsigned char hash[MBEDTLS_HASH_MAX_SIZE];
|
||||
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_algorithm_t psa_algorithm;
|
||||
#else
|
||||
@ -2064,7 +2064,7 @@ static int x509_crt_verifycrl(mbedtls_x509_crt *crt, mbedtls_x509_crt *ca,
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_algorithm = mbedtls_hash_info_psa_from_md(crl_list->sig_md);
|
||||
psa_algorithm = mbedtls_md_psa_alg_from_type(crl_list->sig_md);
|
||||
if (psa_hash_compute(psa_algorithm,
|
||||
crl_list->tbs.p,
|
||||
crl_list->tbs.len,
|
||||
@ -2133,7 +2133,7 @@ static int x509_crt_check_signature(const mbedtls_x509_crt *child,
|
||||
mbedtls_x509_crt_restart_ctx *rs_ctx)
|
||||
{
|
||||
size_t hash_len;
|
||||
unsigned char hash[MBEDTLS_HASH_MAX_SIZE];
|
||||
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||
#if !defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
const mbedtls_md_info_t *md_info;
|
||||
md_info = mbedtls_md_info_from_type(child->sig_md);
|
||||
@ -2144,7 +2144,7 @@ static int x509_crt_check_signature(const mbedtls_x509_crt *child,
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
psa_algorithm_t hash_alg = mbedtls_hash_info_psa_from_md(child->sig_md);
|
||||
psa_algorithm_t hash_alg = mbedtls_md_psa_alg_from_type(child->sig_md);
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
status = psa_hash_compute(hash_alg,
|
||||
|
@ -45,10 +45,9 @@
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#include "psa/crypto.h"
|
||||
#include "mbedtls/psa_util.h"
|
||||
#include "md_psa.h"
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#include "hash_info.h"
|
||||
|
||||
#define CHECK_OVERFLOW_ADD(a, b) \
|
||||
do \
|
||||
{ \
|
||||
@ -569,7 +568,7 @@ int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx,
|
||||
unsigned char *c, *c2;
|
||||
unsigned char sig[MBEDTLS_PK_SIGNATURE_MAX_SIZE];
|
||||
size_t hash_length = 0;
|
||||
unsigned char hash[MBEDTLS_HASH_MAX_SIZE];
|
||||
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_algorithm_t psa_algorithm;
|
||||
@ -728,7 +727,7 @@ int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx,
|
||||
|
||||
/* Compute hash of CRT. */
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_algorithm = mbedtls_hash_info_psa_from_md(ctx->md_alg);
|
||||
psa_algorithm = mbedtls_md_psa_alg_from_type(ctx->md_alg);
|
||||
|
||||
status = psa_hash_compute(psa_algorithm,
|
||||
c,
|
||||
|
@ -36,8 +36,8 @@
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#include "psa/crypto.h"
|
||||
#include "mbedtls/psa_util.h"
|
||||
#include "md_psa.h"
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
#include "hash_info.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@ -243,13 +243,13 @@ static int x509write_csr_der_internal(mbedtls_x509write_csr *ctx,
|
||||
const char *sig_oid;
|
||||
size_t sig_oid_len = 0;
|
||||
unsigned char *c, *c2;
|
||||
unsigned char hash[MBEDTLS_HASH_MAX_SIZE];
|
||||
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||
size_t pub_len = 0, sig_and_oid_len = 0, sig_len;
|
||||
size_t len = 0;
|
||||
mbedtls_pk_type_t pk_alg;
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
size_t hash_len;
|
||||
psa_algorithm_t hash_alg = mbedtls_hash_info_psa_from_md(ctx->md_alg);
|
||||
psa_algorithm_t hash_alg = mbedtls_md_psa_alg_from_type(ctx->md_alg);
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
/* Write the CSR backwards starting from the end of buf */
|
||||
|
Reference in New Issue
Block a user