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 sha1_alt.h
be_bryan 0:b74591d5ab33 3 *
be_bryan 0:b74591d5ab33 4 * \brief SHA1 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_SHA1_ALT_H
be_bryan 0:b74591d5ab33 23 #define MBEDTLS_SHA1_ALT_H
be_bryan 0:b74591d5ab33 24
be_bryan 0:b74591d5ab33 25 #if defined (MBEDTLS_SHA1_ALT)
be_bryan 0:b74591d5ab33 26
be_bryan 0:b74591d5ab33 27
be_bryan 0:b74591d5ab33 28 #include "cmsis.h"
be_bryan 0:b74591d5ab33 29 #include <string.h>
be_bryan 0:b74591d5ab33 30
be_bryan 0:b74591d5ab33 31 #ifdef __cplusplus
be_bryan 0:b74591d5ab33 32 extern "C" {
be_bryan 0:b74591d5ab33 33 #endif
be_bryan 0:b74591d5ab33 34
be_bryan 0:b74591d5ab33 35 #define ST_SHA1_BLOCK_SIZE ((size_t) 64) // HW handles 512 bits, ie 64 bytes
be_bryan 0:b74591d5ab33 36 #define ST_SHA1_TIMEOUT ((uint32_t) 3)
be_bryan 0:b74591d5ab33 37 /**
be_bryan 0:b74591d5ab33 38 * \brief SHA-1 context structure
be_bryan 0:b74591d5ab33 39 * \note HAL_HASH_SHA1_Accumulate will accumulate 512 bits packets, unless it is the last call to the function
be_bryan 0:b74591d5ab33 40 * A ST_SHA1_BLOCK_SIZE bytes buffer is used to save values and handle the processing
be_bryan 0:b74591d5ab33 41 * multiples of ST_SHA1_BLOCK_SIZE bytes
be_bryan 0:b74591d5ab33 42 * If SHA1_finish is called and sbuf_len>0, the remaining bytes are accumulated prior to the call to HAL_HASH_SHA1_Finish
be_bryan 0:b74591d5ab33 43 */
be_bryan 0:b74591d5ab33 44 typedef struct
be_bryan 0:b74591d5ab33 45 {
be_bryan 0:b74591d5ab33 46 unsigned char sbuf[ST_SHA1_BLOCK_SIZE]; /*!< MBEDTLS_SHA1_BLOCK_SIZE buffer to store values so that algorithm is caled once the buffer is filled */
be_bryan 0:b74591d5ab33 47 unsigned char sbuf_len; /*!< number of bytes remaining in sbuf to be processed */
be_bryan 0:b74591d5ab33 48 HASH_HandleTypeDef hhash_sha1; /*!< ST HAL HASH struct */
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_sha1_context;
be_bryan 0:b74591d5ab33 54
be_bryan 0:b74591d5ab33 55 /**
be_bryan 0:b74591d5ab33 56 * \brief Initialize SHA-1 context
be_bryan 0:b74591d5ab33 57 *
be_bryan 0:b74591d5ab33 58 * \param ctx SHA-1 context to be initialized
be_bryan 0:b74591d5ab33 59 */
be_bryan 0:b74591d5ab33 60 void mbedtls_sha1_init( mbedtls_sha1_context *ctx );
be_bryan 0:b74591d5ab33 61
be_bryan 0:b74591d5ab33 62 /**
be_bryan 0:b74591d5ab33 63 * \brief Clear SHA-1 context
be_bryan 0:b74591d5ab33 64 *
be_bryan 0:b74591d5ab33 65 * \param ctx SHA-1 context to be cleared
be_bryan 0:b74591d5ab33 66 */
be_bryan 0:b74591d5ab33 67 void mbedtls_sha1_free( mbedtls_sha1_context *ctx );
be_bryan 0:b74591d5ab33 68
be_bryan 0:b74591d5ab33 69 /**
be_bryan 0:b74591d5ab33 70 * \brief Clone (the state of) a SHA-1 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_sha1_clone( mbedtls_sha1_context *dst,
be_bryan 0:b74591d5ab33 76 const mbedtls_sha1_context *src );
be_bryan 0:b74591d5ab33 77
be_bryan 0:b74591d5ab33 78 /**
be_bryan 0:b74591d5ab33 79 * \brief SHA-1 context setup
be_bryan 0:b74591d5ab33 80 *
be_bryan 0:b74591d5ab33 81 * \param ctx context to be initialized
be_bryan 0:b74591d5ab33 82 */
be_bryan 0:b74591d5ab33 83 void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
be_bryan 0:b74591d5ab33 84
be_bryan 0:b74591d5ab33 85 /**
be_bryan 0:b74591d5ab33 86 * \brief SHA-1 process buffer
be_bryan 0:b74591d5ab33 87 *
be_bryan 0:b74591d5ab33 88 * \param ctx SHA-1 context
be_bryan 0:b74591d5ab33 89 * \param input buffer holding the data
be_bryan 0:b74591d5ab33 90 * \param ilen length of the input data
be_bryan 0:b74591d5ab33 91 */
be_bryan 0:b74591d5ab33 92 void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
be_bryan 0:b74591d5ab33 93
be_bryan 0:b74591d5ab33 94 /**
be_bryan 0:b74591d5ab33 95 * \brief SHA-1 final digest
be_bryan 0:b74591d5ab33 96 *
be_bryan 0:b74591d5ab33 97 * \param ctx SHA-1 context
be_bryan 0:b74591d5ab33 98 * \param output SHA-1 checksum result
be_bryan 0:b74591d5ab33 99 */
be_bryan 0:b74591d5ab33 100 void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] );
be_bryan 0:b74591d5ab33 101
be_bryan 0:b74591d5ab33 102 /* Internal use */
be_bryan 0:b74591d5ab33 103 void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[ST_SHA1_BLOCK_SIZE] );
be_bryan 0:b74591d5ab33 104
be_bryan 0:b74591d5ab33 105 #ifdef __cplusplus
be_bryan 0:b74591d5ab33 106 }
be_bryan 0:b74591d5ab33 107 #endif
be_bryan 0:b74591d5ab33 108
be_bryan 0:b74591d5ab33 109 #endif /* MBEDTLS_SHA1_ALT */
be_bryan 0:b74591d5ab33 110
be_bryan 0:b74591d5ab33 111 #endif /* sha1_alt.h */