Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

UserRevisionLine numberNew contents of line
be_bryan 0:b74591d5ab33 1 /**
be_bryan 0:b74591d5ab33 2 * \file sha256_alt.h
be_bryan 0:b74591d5ab33 3 *
be_bryan 0:b74591d5ab33 4 * \brief SHA256 hw acceleration (hash function)
be_bryan 0:b74591d5ab33 5 *
be_bryan 0:b74591d5ab33 6 * Copyright (c) 2017, STMicroelectronics
be_bryan 0:b74591d5ab33 7 * SPDX-License-Identifier: Apache-2.0
be_bryan 0:b74591d5ab33 8 *
be_bryan 0:b74591d5ab33 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
be_bryan 0:b74591d5ab33 10 * not use this file except in compliance with the License.
be_bryan 0:b74591d5ab33 11 * You may obtain a copy of the License at
be_bryan 0:b74591d5ab33 12 *
be_bryan 0:b74591d5ab33 13 * http://www.apache.org/licenses/LICENSE-2.0
be_bryan 0:b74591d5ab33 14 *
be_bryan 0:b74591d5ab33 15 * Unless required by applicable law or agreed to in writing, software
be_bryan 0:b74591d5ab33 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
be_bryan 0:b74591d5ab33 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
be_bryan 0:b74591d5ab33 18 * See the License for the specific language governing permissions and
be_bryan 0:b74591d5ab33 19 * limitations under the License.
be_bryan 0:b74591d5ab33 20 *
be_bryan 0:b74591d5ab33 21 */
be_bryan 0:b74591d5ab33 22 #ifndef MBEDTLS_SHA256_ALT_H
be_bryan 0:b74591d5ab33 23 #define MBEDTLS_SHA256_ALT_H
be_bryan 0:b74591d5ab33 24
be_bryan 0:b74591d5ab33 25 #if defined (MBEDTLS_SHA256_ALT)
be_bryan 0:b74591d5ab33 26
be_bryan 0:b74591d5ab33 27 #include "cmsis.h"
be_bryan 0:b74591d5ab33 28 #include <string.h>
be_bryan 0:b74591d5ab33 29
be_bryan 0:b74591d5ab33 30 #ifdef __cplusplus
be_bryan 0:b74591d5ab33 31 extern "C" {
be_bryan 0:b74591d5ab33 32 #endif
be_bryan 0:b74591d5ab33 33
be_bryan 0:b74591d5ab33 34 #define ST_SHA256_BLOCK_SIZE ((size_t) 64) // HW handles 512 bits, ie 64 bytes
be_bryan 0:b74591d5ab33 35 #define ST_SHA256_TIMEOUT ((uint32_t) 3)
be_bryan 0:b74591d5ab33 36 /**
be_bryan 0:b74591d5ab33 37 * \brief SHA-256 context structure
be_bryan 0:b74591d5ab33 38 * \note HAL_HASH_SHA256_Accumulate will accumulate 512 bits packets, unless it is the last call to the function
be_bryan 0:b74591d5ab33 39 * A ST_SHA256_BLOCK_SIZE bytes buffer is used to save values and handle the processing
be_bryan 0:b74591d5ab33 40 * ST_SHA256_BLOCK_SIZE bytes per ST_SHA256_BLOCK_SIZE bytes
be_bryan 0:b74591d5ab33 41 * If sha256_finish is called and sbuf_len>0, the remaining bytes are accumulated prior to the call to HAL_HASH_SHA256_Finish
be_bryan 0:b74591d5ab33 42 */
be_bryan 0:b74591d5ab33 43 typedef struct
be_bryan 0:b74591d5ab33 44 {
be_bryan 0:b74591d5ab33 45 int is224; /*!< 0 => SHA-256, else SHA-224 */
be_bryan 0:b74591d5ab33 46 HASH_HandleTypeDef hhash_sha256;
be_bryan 0:b74591d5ab33 47 unsigned char sbuf[ST_SHA256_BLOCK_SIZE]; /*!< ST_SHA256_BLOCK_SIZE buffer to store values so that algorithm is called once the buffer is filled */
be_bryan 0:b74591d5ab33 48 unsigned char sbuf_len; /*!< number of bytes to be processed in sbuf */
be_bryan 0:b74591d5ab33 49 uint32_t ctx_save_cr;
be_bryan 0:b74591d5ab33 50 uint32_t ctx_save_str;
be_bryan 0:b74591d5ab33 51 uint32_t ctx_save_csr[38];
be_bryan 0:b74591d5ab33 52 }
be_bryan 0:b74591d5ab33 53 mbedtls_sha256_context;
be_bryan 0:b74591d5ab33 54
be_bryan 0:b74591d5ab33 55 /**
be_bryan 0:b74591d5ab33 56 * \brief Initialize SHA-256 context
be_bryan 0:b74591d5ab33 57 *
be_bryan 0:b74591d5ab33 58 * \param ctx SHA-256 context to be initialized
be_bryan 0:b74591d5ab33 59 */
be_bryan 0:b74591d5ab33 60 void mbedtls_sha256_init( mbedtls_sha256_context *ctx );
be_bryan 0:b74591d5ab33 61
be_bryan 0:b74591d5ab33 62 /**
be_bryan 0:b74591d5ab33 63 * \brief Clear SHA-256 context
be_bryan 0:b74591d5ab33 64 *
be_bryan 0:b74591d5ab33 65 * \param ctx SHA-256 context to be cleared
be_bryan 0:b74591d5ab33 66 */
be_bryan 0:b74591d5ab33 67 void mbedtls_sha256_free( mbedtls_sha256_context *ctx );
be_bryan 0:b74591d5ab33 68
be_bryan 0:b74591d5ab33 69 /**
be_bryan 0:b74591d5ab33 70 * \brief Clone (the state of) a SHA-256 context
be_bryan 0:b74591d5ab33 71 *
be_bryan 0:b74591d5ab33 72 * \param dst The destination context
be_bryan 0:b74591d5ab33 73 * \param src The context to be cloned
be_bryan 0:b74591d5ab33 74 */
be_bryan 0:b74591d5ab33 75 void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
be_bryan 0:b74591d5ab33 76 const mbedtls_sha256_context *src );
be_bryan 0:b74591d5ab33 77
be_bryan 0:b74591d5ab33 78 /**
be_bryan 0:b74591d5ab33 79 * \brief SHA-256 context setup
be_bryan 0:b74591d5ab33 80 *
be_bryan 0:b74591d5ab33 81 * \param ctx context to be initialized
be_bryan 0:b74591d5ab33 82 * \param is224 0 = use SHA256, 1 = use SHA224
be_bryan 0:b74591d5ab33 83 */
be_bryan 0:b74591d5ab33 84 void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
be_bryan 0:b74591d5ab33 85
be_bryan 0:b74591d5ab33 86 /**
be_bryan 0:b74591d5ab33 87 * \brief SHA-256 process buffer
be_bryan 0:b74591d5ab33 88 *
be_bryan 0:b74591d5ab33 89 * \param ctx SHA-256 context
be_bryan 0:b74591d5ab33 90 * \param input buffer holding the data
be_bryan 0:b74591d5ab33 91 * \param ilen length of the input data
be_bryan 0:b74591d5ab33 92 */
be_bryan 0:b74591d5ab33 93 void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input,
be_bryan 0:b74591d5ab33 94 size_t ilen );
be_bryan 0:b74591d5ab33 95
be_bryan 0:b74591d5ab33 96 /**
be_bryan 0:b74591d5ab33 97 * \brief SHA-256 final digest
be_bryan 0:b74591d5ab33 98 *
be_bryan 0:b74591d5ab33 99 * \param ctx SHA-256 context
be_bryan 0:b74591d5ab33 100 * \param output SHA-224/256 checksum result
be_bryan 0:b74591d5ab33 101 */
be_bryan 0:b74591d5ab33 102 void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] );
be_bryan 0:b74591d5ab33 103
be_bryan 0:b74591d5ab33 104 /* Internal use */
be_bryan 0:b74591d5ab33 105 void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[ST_SHA256_BLOCK_SIZE] );
be_bryan 0:b74591d5ab33 106
be_bryan 0:b74591d5ab33 107 #ifdef __cplusplus
be_bryan 0:b74591d5ab33 108 }
be_bryan 0:b74591d5ab33 109 #endif
be_bryan 0:b74591d5ab33 110
be_bryan 0:b74591d5ab33 111 #endif /* MBEDTLS_SHA256_ALT */
be_bryan 0:b74591d5ab33 112
be_bryan 0:b74591d5ab33 113 #endif /* sha256_alt.h */