mbed TLS Build

Dependents:   Slave-prot-prod

Committer:
williequesada
Date:
Tue Jun 04 16:03:38 2019 +0000
Revision:
1:1a219dea6cb5
Parent:
0:cdf462088d13
compartir a Pablo

Who changed what in which revision?

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