tmedicci commented on code in PR #16016: URL: https://github.com/apache/nuttx/pull/16016#discussion_r2044370763
########## arch/xtensa/src/esp32/esp32_crypto.c: ########## @@ -0,0 +1,478 @@ +/**************************************************************************** + * arch/xtensa/src/esp32/esp32_crypto.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <errno.h> +#include <stddef.h> +#include <sys/queue.h> + +#include <crypto/cryptodev.h> +#include <crypto/xform.h> +#include <nuttx/kmalloc.h> +#include <nuttx/crypto/crypto.h> + +#include "esp_sha.h" +#include <stdio.h> + +/**************************************************************************** + * Private Functions Prototypes + ****************************************************************************/ + +static void sha1_init(void *ctx); +static void sha256_init(void *ctx); +static void sha384_init(void *ctx); +static void sha512_init(void *ctx); +static int sha_update(void *ctx, const uint8_t *in, size_t len); +static void sha_final(uint8_t *out, void *ctx); +static int esp32_freesession(uint32_t sid); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +SLIST_HEAD(esp32_crypto_list, esp32_crypto_data); +static struct esp32_crypto_list *g_esp32_sessions = NULL; +static uint32_t g_esp32_sesnum = 0; + +const struct auth_hash g_auth_hash_sha1_esp32 = +{ + CRYPTO_SHA1, "SHA1", + 0, 20, 12, sizeof(struct esp32_sha_context_s), + 0, + sha1_init, NULL, NULL, + sha_update, + sha_final +}; + +const struct auth_hash g_auth_hash_sha2_256_esp32 = +{ + CRYPTO_SHA2_256, "SHA256", + 0, 32, 12, sizeof(struct esp32_sha_context_s), + 0, + sha256_init, NULL, NULL, + sha_update, + sha_final +}; + +const struct auth_hash g_auth_hash_sha2_384_esp32 = +{ + CRYPTO_SHA2_384, "SHA384", + 0, 48, 12, sizeof(struct esp32_sha_context_s), + 0, + sha384_init, NULL, NULL, + sha_update, + sha_final +}; + +const struct auth_hash g_auth_hash_sha2_512_esp32 = +{ + CRYPTO_SHA2_512, "SHA512", + 0, 64, 12, sizeof(struct esp32_sha_context_s), + 0, + sha512_init, NULL, NULL, + sha_update, + sha_final +}; + +struct esp32_crypto_data +{ + int alg; /* Algorithm */ + union + { + struct + { + uint8_t *ictx; + uint8_t *octx; + uint32_t klen; + const struct auth_hash *axf; + } HWCR_AUTH; + } HWCR_UN; + +#define hw_ictx HWCR_UN.HWCR_AUTH.ictx +#define hw_octx HWCR_UN.HWCR_AUTH.octx +#define hw_klen HWCR_UN.HWCR_AUTH.klen +#define hw_axf HWCR_UN.HWCR_AUTH.axf + + SLIST_ENTRY(esp32_crypto_data) next; +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void sha1_init(void *ctx) +{ + esp32_sha1_starts(ctx); +} + +static void sha256_init(void *ctx) +{ + esp32_sha256_starts(ctx); +} + +static void sha384_init(void *ctx) +{ + esp32_sha384_starts(ctx); +} + +static void sha512_init(void *ctx) +{ + esp32_sha512_starts(ctx); +} + +static int sha_update(void *ctx, const uint8_t *in, size_t len) +{ + return esp32_sha_update((struct esp32_sha_context_s *)ctx, + (const unsigned char *)in, + (size_t)len); +} + +static void sha_final(uint8_t *out, void *ctx) +{ + esp32_sha_finish((struct esp32_sha_context_s *)ctx, + (unsigned char *)out); +} Review Comment: I know it's redundant, but all functions must contain a function header according to [NuttX's coding standard.](https://nuttx.apache.org/docs/latest/contributing/coding_style.html#function-headers) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org