u-boot/lib/mbedtls/port/sha256_alt.h
Raymond Mao 13de848338 mbedtls: add mbedtls into the build system
Port mbedtls with adapted libc header files.
Add mbedtls default config header file.
Optimize mbedtls default config by disabling unused features to
reduce the target size.
Add mbedtls kbuild makefile.
Add Kconfig skeleton and config submenu entry for selecting
crypto libraries between mbedtls and legacy ones.
Add the mbedtls include directories into the build system.
Port u-boot hash functions as MbedTLS crypto alternatives and set
it as default.

Subsequent patches will separate those Kconfigs into pairs of
_LEGACY and _MBEDTLS for controlling the implementations of legacy
crypto libraries and MbedTLS ones respectively.

The motivation of moving and adapting *INT* macros from kernel.h
to limits.h is to fulfill the MbedTLS building requirement.
The conditional compilation statements in MbedTLS expects the
*INT* macros as constant expressions, thus expressions like
`((int)(~0U >> 1))` will not work.

Prerequisite
------------

This patch series requires mbedtls git repo to be added as a
subtree to the main U-Boot repo via:

$ git subtree add --prefix lib/mbedtls/external/mbedtls \
      https://github.com/Mbed-TLS/mbedtls.git \
      v3.6.0 --squash

Moreover, due to the Windows-style files from mbedtls git repo,
we need to convert the CRLF endings to LF and do a commit manually:

$ git add --renormalize .
$ git commit

Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
2024-10-14 17:58:12 -06:00

64 lines
1.2 KiB
C

/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright (c) 2024 Linaro Limited
* Author: Raymond Mao <raymond.mao@linaro.org>
*/
#ifndef SHA256_ALT_H
#define SHA256_ALT_H
#include <image.h>
#include <u-boot/sha256.h>
typedef sha256_context mbedtls_sha256_context;
static inline void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
{
}
static inline void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
{
}
static inline void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
const mbedtls_sha256_context *src)
{
*dst = *src;
}
static inline int mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
{
if (is224)
return -EOPNOTSUPP;
sha256_starts(ctx);
return 0;
}
static inline int mbedtls_sha256_update(mbedtls_sha256_context *ctx,
const unsigned char *input,
size_t ilen)
{
sha256_update(ctx, input, ilen);
return 0;
}
static inline int mbedtls_sha256_finish(mbedtls_sha256_context *ctx,
unsigned char *output)
{
sha256_finish(ctx, output);
return 0;
}
static inline int mbedtls_sha256(const unsigned char *input,
size_t ilen,
unsigned char *output,
int is224)
{
if (is224)
return -EOPNOTSUPP;
sha256_csum_wd(input, ilen, output, CHUNKSZ_SHA256);
return 0;
}
#endif /* sha256_alt.h */