Modified mbed TLS headers for AES functionality only to reduce build size
Dependents: BLE_Gateway_Linker_fix BLE_Gateway
Fork of mbedtls by
mbedtls/sha256.h@5:f09f5ed830ca, 2017-07-10 (annotated)
- Committer:
- electronichamsters
- Date:
- Mon Jul 10 04:00:25 2017 +0000
- Revision:
- 5:f09f5ed830ca
- Parent:
- 1:24750b9ad5ef
working gateway
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Christopher Haster |
1:24750b9ad5ef | 1 | /** |
Christopher Haster |
1:24750b9ad5ef | 2 | * \file mbedtls_sha256.h |
Christopher Haster |
1:24750b9ad5ef | 3 | * |
Christopher Haster |
1:24750b9ad5ef | 4 | * \brief SHA-224 and SHA-256 cryptographic hash function |
Christopher Haster |
1:24750b9ad5ef | 5 | * |
Christopher Haster |
1:24750b9ad5ef | 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Christopher Haster |
1:24750b9ad5ef | 7 | * SPDX-License-Identifier: Apache-2.0 |
Christopher Haster |
1:24750b9ad5ef | 8 | * |
Christopher Haster |
1:24750b9ad5ef | 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
Christopher Haster |
1:24750b9ad5ef | 10 | * not use this file except in compliance with the License. |
Christopher Haster |
1:24750b9ad5ef | 11 | * You may obtain a copy of the License at |
Christopher Haster |
1:24750b9ad5ef | 12 | * |
Christopher Haster |
1:24750b9ad5ef | 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
Christopher Haster |
1:24750b9ad5ef | 14 | * |
Christopher Haster |
1:24750b9ad5ef | 15 | * Unless required by applicable law or agreed to in writing, software |
Christopher Haster |
1:24750b9ad5ef | 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Christopher Haster |
1:24750b9ad5ef | 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Christopher Haster |
1:24750b9ad5ef | 18 | * See the License for the specific language governing permissions and |
Christopher Haster |
1:24750b9ad5ef | 19 | * limitations under the License. |
Christopher Haster |
1:24750b9ad5ef | 20 | * |
Christopher Haster |
1:24750b9ad5ef | 21 | * This file is part of mbed TLS (https://tls.mbed.org) |
Christopher Haster |
1:24750b9ad5ef | 22 | */ |
Christopher Haster |
1:24750b9ad5ef | 23 | #ifndef MBEDTLS_SHA256_H |
Christopher Haster |
1:24750b9ad5ef | 24 | #define MBEDTLS_SHA256_H |
Christopher Haster |
1:24750b9ad5ef | 25 | |
Christopher Haster |
1:24750b9ad5ef | 26 | #if !defined(MBEDTLS_CONFIG_FILE) |
Christopher Haster |
1:24750b9ad5ef | 27 | #include "config.h" |
Christopher Haster |
1:24750b9ad5ef | 28 | #else |
Christopher Haster |
1:24750b9ad5ef | 29 | #include MBEDTLS_CONFIG_FILE |
Christopher Haster |
1:24750b9ad5ef | 30 | #endif |
Christopher Haster |
1:24750b9ad5ef | 31 | |
Christopher Haster |
1:24750b9ad5ef | 32 | #include <stddef.h> |
Christopher Haster |
1:24750b9ad5ef | 33 | #include <stdint.h> |
Christopher Haster |
1:24750b9ad5ef | 34 | |
Christopher Haster |
1:24750b9ad5ef | 35 | #if !defined(MBEDTLS_SHA256_ALT) |
Christopher Haster |
1:24750b9ad5ef | 36 | // Regular implementation |
Christopher Haster |
1:24750b9ad5ef | 37 | // |
Christopher Haster |
1:24750b9ad5ef | 38 | |
Christopher Haster |
1:24750b9ad5ef | 39 | #ifdef __cplusplus |
Christopher Haster |
1:24750b9ad5ef | 40 | extern "C" { |
Christopher Haster |
1:24750b9ad5ef | 41 | #endif |
Christopher Haster |
1:24750b9ad5ef | 42 | |
Christopher Haster |
1:24750b9ad5ef | 43 | /** |
Christopher Haster |
1:24750b9ad5ef | 44 | * \brief SHA-256 context structure |
Christopher Haster |
1:24750b9ad5ef | 45 | */ |
Christopher Haster |
1:24750b9ad5ef | 46 | typedef struct |
Christopher Haster |
1:24750b9ad5ef | 47 | { |
Christopher Haster |
1:24750b9ad5ef | 48 | uint32_t total[2]; /*!< number of bytes processed */ |
Christopher Haster |
1:24750b9ad5ef | 49 | uint32_t state[8]; /*!< intermediate digest state */ |
Christopher Haster |
1:24750b9ad5ef | 50 | unsigned char buffer[64]; /*!< data block being processed */ |
Christopher Haster |
1:24750b9ad5ef | 51 | int is224; /*!< 0 => SHA-256, else SHA-224 */ |
Christopher Haster |
1:24750b9ad5ef | 52 | } |
Christopher Haster |
1:24750b9ad5ef | 53 | mbedtls_sha256_context; |
Christopher Haster |
1:24750b9ad5ef | 54 | |
Christopher Haster |
1:24750b9ad5ef | 55 | /** |
Christopher Haster |
1:24750b9ad5ef | 56 | * \brief Initialize SHA-256 context |
Christopher Haster |
1:24750b9ad5ef | 57 | * |
Christopher Haster |
1:24750b9ad5ef | 58 | * \param ctx SHA-256 context to be initialized |
Christopher Haster |
1:24750b9ad5ef | 59 | */ |
Christopher Haster |
1:24750b9ad5ef | 60 | void mbedtls_sha256_init( mbedtls_sha256_context *ctx ); |
Christopher Haster |
1:24750b9ad5ef | 61 | |
Christopher Haster |
1:24750b9ad5ef | 62 | /** |
Christopher Haster |
1:24750b9ad5ef | 63 | * \brief Clear SHA-256 context |
Christopher Haster |
1:24750b9ad5ef | 64 | * |
Christopher Haster |
1:24750b9ad5ef | 65 | * \param ctx SHA-256 context to be cleared |
Christopher Haster |
1:24750b9ad5ef | 66 | */ |
Christopher Haster |
1:24750b9ad5ef | 67 | void mbedtls_sha256_free( mbedtls_sha256_context *ctx ); |
Christopher Haster |
1:24750b9ad5ef | 68 | |
Christopher Haster |
1:24750b9ad5ef | 69 | /** |
Christopher Haster |
1:24750b9ad5ef | 70 | * \brief Clone (the state of) a SHA-256 context |
Christopher Haster |
1:24750b9ad5ef | 71 | * |
Christopher Haster |
1:24750b9ad5ef | 72 | * \param dst The destination context |
Christopher Haster |
1:24750b9ad5ef | 73 | * \param src The context to be cloned |
Christopher Haster |
1:24750b9ad5ef | 74 | */ |
Christopher Haster |
1:24750b9ad5ef | 75 | void mbedtls_sha256_clone( mbedtls_sha256_context *dst, |
Christopher Haster |
1:24750b9ad5ef | 76 | const mbedtls_sha256_context *src ); |
Christopher Haster |
1:24750b9ad5ef | 77 | |
Christopher Haster |
1:24750b9ad5ef | 78 | /** |
Christopher Haster |
1:24750b9ad5ef | 79 | * \brief SHA-256 context setup |
Christopher Haster |
1:24750b9ad5ef | 80 | * |
Christopher Haster |
1:24750b9ad5ef | 81 | * \param ctx context to be initialized |
Christopher Haster |
1:24750b9ad5ef | 82 | * \param is224 0 = use SHA256, 1 = use SHA224 |
Christopher Haster |
1:24750b9ad5ef | 83 | */ |
Christopher Haster |
1:24750b9ad5ef | 84 | void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 ); |
Christopher Haster |
1:24750b9ad5ef | 85 | |
Christopher Haster |
1:24750b9ad5ef | 86 | /** |
Christopher Haster |
1:24750b9ad5ef | 87 | * \brief SHA-256 process buffer |
Christopher Haster |
1:24750b9ad5ef | 88 | * |
Christopher Haster |
1:24750b9ad5ef | 89 | * \param ctx SHA-256 context |
Christopher Haster |
1:24750b9ad5ef | 90 | * \param input buffer holding the data |
Christopher Haster |
1:24750b9ad5ef | 91 | * \param ilen length of the input data |
Christopher Haster |
1:24750b9ad5ef | 92 | */ |
Christopher Haster |
1:24750b9ad5ef | 93 | void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input, |
Christopher Haster |
1:24750b9ad5ef | 94 | size_t ilen ); |
Christopher Haster |
1:24750b9ad5ef | 95 | |
Christopher Haster |
1:24750b9ad5ef | 96 | /** |
Christopher Haster |
1:24750b9ad5ef | 97 | * \brief SHA-256 final digest |
Christopher Haster |
1:24750b9ad5ef | 98 | * |
Christopher Haster |
1:24750b9ad5ef | 99 | * \param ctx SHA-256 context |
Christopher Haster |
1:24750b9ad5ef | 100 | * \param output SHA-224/256 checksum result |
Christopher Haster |
1:24750b9ad5ef | 101 | */ |
Christopher Haster |
1:24750b9ad5ef | 102 | void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] ); |
Christopher Haster |
1:24750b9ad5ef | 103 | |
Christopher Haster |
1:24750b9ad5ef | 104 | /* Internal use */ |
Christopher Haster |
1:24750b9ad5ef | 105 | void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] ); |
Christopher Haster |
1:24750b9ad5ef | 106 | |
Christopher Haster |
1:24750b9ad5ef | 107 | #ifdef __cplusplus |
Christopher Haster |
1:24750b9ad5ef | 108 | } |
Christopher Haster |
1:24750b9ad5ef | 109 | #endif |
Christopher Haster |
1:24750b9ad5ef | 110 | |
Christopher Haster |
1:24750b9ad5ef | 111 | #else /* MBEDTLS_SHA256_ALT */ |
Christopher Haster |
1:24750b9ad5ef | 112 | #include "sha256_alt.h" |
Christopher Haster |
1:24750b9ad5ef | 113 | #endif /* MBEDTLS_SHA256_ALT */ |
Christopher Haster |
1:24750b9ad5ef | 114 | |
Christopher Haster |
1:24750b9ad5ef | 115 | #ifdef __cplusplus |
Christopher Haster |
1:24750b9ad5ef | 116 | extern "C" { |
Christopher Haster |
1:24750b9ad5ef | 117 | #endif |
Christopher Haster |
1:24750b9ad5ef | 118 | |
Christopher Haster |
1:24750b9ad5ef | 119 | /** |
Christopher Haster |
1:24750b9ad5ef | 120 | * \brief Output = SHA-256( input buffer ) |
Christopher Haster |
1:24750b9ad5ef | 121 | * |
Christopher Haster |
1:24750b9ad5ef | 122 | * \param input buffer holding the data |
Christopher Haster |
1:24750b9ad5ef | 123 | * \param ilen length of the input data |
Christopher Haster |
1:24750b9ad5ef | 124 | * \param output SHA-224/256 checksum result |
Christopher Haster |
1:24750b9ad5ef | 125 | * \param is224 0 = use SHA256, 1 = use SHA224 |
Christopher Haster |
1:24750b9ad5ef | 126 | */ |
Christopher Haster |
1:24750b9ad5ef | 127 | void mbedtls_sha256( const unsigned char *input, size_t ilen, |
Christopher Haster |
1:24750b9ad5ef | 128 | unsigned char output[32], int is224 ); |
Christopher Haster |
1:24750b9ad5ef | 129 | |
Christopher Haster |
1:24750b9ad5ef | 130 | /** |
Christopher Haster |
1:24750b9ad5ef | 131 | * \brief Checkup routine |
Christopher Haster |
1:24750b9ad5ef | 132 | * |
Christopher Haster |
1:24750b9ad5ef | 133 | * \return 0 if successful, or 1 if the test failed |
Christopher Haster |
1:24750b9ad5ef | 134 | */ |
Christopher Haster |
1:24750b9ad5ef | 135 | int mbedtls_sha256_self_test( int verbose ); |
Christopher Haster |
1:24750b9ad5ef | 136 | |
Christopher Haster |
1:24750b9ad5ef | 137 | #ifdef __cplusplus |
Christopher Haster |
1:24750b9ad5ef | 138 | } |
Christopher Haster |
1:24750b9ad5ef | 139 | #endif |
Christopher Haster |
1:24750b9ad5ef | 140 | |
Christopher Haster |
1:24750b9ad5ef | 141 | #endif /* mbedtls_sha256.h */ |