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