Version 0.5.0 of tinydtls
Dependents: tinydtls_test_cellular tinydtls_test_ethernet tiny-dtls
sha2/sha2.h@1:598a56fe116e, 2014-02-12 (annotated)
- Committer:
- ashleymills
- Date:
- Wed Feb 12 09:30:16 2014 +0000
- Revision:
- 1:598a56fe116e
- Parent:
- 0:ff9ebe0cf0e9
Explicitly removed something instead of relying on MACRO to disable it. Mbed can't use it.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 0:ff9ebe0cf0e9 | 1 | /* |
ashleymills | 0:ff9ebe0cf0e9 | 2 | * FILE: sha2.h |
ashleymills | 0:ff9ebe0cf0e9 | 3 | * AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/ |
ashleymills | 0:ff9ebe0cf0e9 | 4 | * |
ashleymills | 0:ff9ebe0cf0e9 | 5 | * Copyright (c) 2000-2001, Aaron D. Gifford |
ashleymills | 0:ff9ebe0cf0e9 | 6 | * All rights reserved. |
ashleymills | 0:ff9ebe0cf0e9 | 7 | * |
ashleymills | 0:ff9ebe0cf0e9 | 8 | * Redistribution and use in source and binary forms, with or without |
ashleymills | 0:ff9ebe0cf0e9 | 9 | * modification, are permitted provided that the following conditions |
ashleymills | 0:ff9ebe0cf0e9 | 10 | * are met: |
ashleymills | 0:ff9ebe0cf0e9 | 11 | * 1. Redistributions of source code must retain the above copyright |
ashleymills | 0:ff9ebe0cf0e9 | 12 | * notice, this list of conditions and the following disclaimer. |
ashleymills | 0:ff9ebe0cf0e9 | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
ashleymills | 0:ff9ebe0cf0e9 | 14 | * notice, this list of conditions and the following disclaimer in the |
ashleymills | 0:ff9ebe0cf0e9 | 15 | * documentation and/or other materials provided with the distribution. |
ashleymills | 0:ff9ebe0cf0e9 | 16 | * 3. Neither the name of the copyright holder nor the names of contributors |
ashleymills | 0:ff9ebe0cf0e9 | 17 | * may be used to endorse or promote products derived from this software |
ashleymills | 0:ff9ebe0cf0e9 | 18 | * without specific prior written permission. |
ashleymills | 0:ff9ebe0cf0e9 | 19 | * |
ashleymills | 0:ff9ebe0cf0e9 | 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND |
ashleymills | 0:ff9ebe0cf0e9 | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
ashleymills | 0:ff9ebe0cf0e9 | 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
ashleymills | 0:ff9ebe0cf0e9 | 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE |
ashleymills | 0:ff9ebe0cf0e9 | 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
ashleymills | 0:ff9ebe0cf0e9 | 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
ashleymills | 0:ff9ebe0cf0e9 | 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
ashleymills | 0:ff9ebe0cf0e9 | 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
ashleymills | 0:ff9ebe0cf0e9 | 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
ashleymills | 0:ff9ebe0cf0e9 | 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
ashleymills | 0:ff9ebe0cf0e9 | 30 | * SUCH DAMAGE. |
ashleymills | 0:ff9ebe0cf0e9 | 31 | * |
ashleymills | 0:ff9ebe0cf0e9 | 32 | * $Id: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $ |
ashleymills | 0:ff9ebe0cf0e9 | 33 | */ |
ashleymills | 0:ff9ebe0cf0e9 | 34 | |
ashleymills | 0:ff9ebe0cf0e9 | 35 | #ifndef __SHA2_H__ |
ashleymills | 0:ff9ebe0cf0e9 | 36 | #define __SHA2_H__ |
ashleymills | 0:ff9ebe0cf0e9 | 37 | |
ashleymills | 0:ff9ebe0cf0e9 | 38 | #ifdef __cplusplus |
ashleymills | 0:ff9ebe0cf0e9 | 39 | extern "C" { |
ashleymills | 0:ff9ebe0cf0e9 | 40 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 41 | |
ashleymills | 0:ff9ebe0cf0e9 | 42 | #define WITH_SHA256 1 |
ashleymills | 0:ff9ebe0cf0e9 | 43 | /* |
ashleymills | 0:ff9ebe0cf0e9 | 44 | * Import u_intXX_t size_t type definitions from system headers. You |
ashleymills | 0:ff9ebe0cf0e9 | 45 | * may need to change this, or define these things yourself in this |
ashleymills | 0:ff9ebe0cf0e9 | 46 | * file. |
ashleymills | 0:ff9ebe0cf0e9 | 47 | */ |
ashleymills | 0:ff9ebe0cf0e9 | 48 | #ifdef HAVE_SYS_TYPES_H |
ashleymills | 0:ff9ebe0cf0e9 | 49 | #include <sys/types.h> |
ashleymills | 0:ff9ebe0cf0e9 | 50 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 51 | #define SHA2_USE_INTTYPES_H |
ashleymills | 0:ff9ebe0cf0e9 | 52 | |
ashleymills | 0:ff9ebe0cf0e9 | 53 | #ifdef SHA2_USE_INTTYPES_H |
ashleymills | 0:ff9ebe0cf0e9 | 54 | |
ashleymills | 0:ff9ebe0cf0e9 | 55 | #include <inttypes.h> |
ashleymills | 0:ff9ebe0cf0e9 | 56 | |
ashleymills | 0:ff9ebe0cf0e9 | 57 | #endif /* SHA2_USE_INTTYPES_H */ |
ashleymills | 0:ff9ebe0cf0e9 | 58 | |
ashleymills | 0:ff9ebe0cf0e9 | 59 | |
ashleymills | 0:ff9ebe0cf0e9 | 60 | /*** SHA-256/384/512 Various Length Definitions ***********************/ |
ashleymills | 0:ff9ebe0cf0e9 | 61 | #define SHA256_BLOCK_LENGTH 64 |
ashleymills | 0:ff9ebe0cf0e9 | 62 | #define SHA256_DIGEST_LENGTH 32 |
ashleymills | 0:ff9ebe0cf0e9 | 63 | #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) |
ashleymills | 0:ff9ebe0cf0e9 | 64 | #define SHA384_BLOCK_LENGTH 128 |
ashleymills | 0:ff9ebe0cf0e9 | 65 | #define SHA384_DIGEST_LENGTH 48 |
ashleymills | 0:ff9ebe0cf0e9 | 66 | #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1) |
ashleymills | 0:ff9ebe0cf0e9 | 67 | #define SHA512_BLOCK_LENGTH 128 |
ashleymills | 0:ff9ebe0cf0e9 | 68 | #define SHA512_DIGEST_LENGTH 64 |
ashleymills | 0:ff9ebe0cf0e9 | 69 | #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) |
ashleymills | 0:ff9ebe0cf0e9 | 70 | |
ashleymills | 0:ff9ebe0cf0e9 | 71 | |
ashleymills | 0:ff9ebe0cf0e9 | 72 | /*** SHA-256/384/512 Context Structures *******************************/ |
ashleymills | 0:ff9ebe0cf0e9 | 73 | /* NOTE: If your architecture does not define either u_intXX_t types or |
ashleymills | 0:ff9ebe0cf0e9 | 74 | * uintXX_t (from inttypes.h), you may need to define things by hand |
ashleymills | 0:ff9ebe0cf0e9 | 75 | * for your system: |
ashleymills | 0:ff9ebe0cf0e9 | 76 | */ |
ashleymills | 0:ff9ebe0cf0e9 | 77 | #if 0 |
ashleymills | 0:ff9ebe0cf0e9 | 78 | typedef unsigned char u_int8_t; /* 1-byte (8-bits) */ |
ashleymills | 0:ff9ebe0cf0e9 | 79 | typedef unsigned int u_int32_t; /* 4-bytes (32-bits) */ |
ashleymills | 0:ff9ebe0cf0e9 | 80 | typedef unsigned long long u_int64_t; /* 8-bytes (64-bits) */ |
ashleymills | 0:ff9ebe0cf0e9 | 81 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 82 | /* |
ashleymills | 0:ff9ebe0cf0e9 | 83 | * Most BSD systems already define u_intXX_t types, as does Linux. |
ashleymills | 0:ff9ebe0cf0e9 | 84 | * Some systems, however, like Compaq's Tru64 Unix instead can use |
ashleymills | 0:ff9ebe0cf0e9 | 85 | * uintXX_t types defined by very recent ANSI C standards and included |
ashleymills | 0:ff9ebe0cf0e9 | 86 | * in the file: |
ashleymills | 0:ff9ebe0cf0e9 | 87 | * |
ashleymills | 0:ff9ebe0cf0e9 | 88 | * #include <inttypes.h> |
ashleymills | 0:ff9ebe0cf0e9 | 89 | * |
ashleymills | 0:ff9ebe0cf0e9 | 90 | * If you choose to use <inttypes.h> then please define: |
ashleymills | 0:ff9ebe0cf0e9 | 91 | * |
ashleymills | 0:ff9ebe0cf0e9 | 92 | * #define SHA2_USE_INTTYPES_H |
ashleymills | 0:ff9ebe0cf0e9 | 93 | * |
ashleymills | 0:ff9ebe0cf0e9 | 94 | * Or on the command line during compile: |
ashleymills | 0:ff9ebe0cf0e9 | 95 | * |
ashleymills | 0:ff9ebe0cf0e9 | 96 | * cc -DSHA2_USE_INTTYPES_H ... |
ashleymills | 0:ff9ebe0cf0e9 | 97 | */ |
ashleymills | 0:ff9ebe0cf0e9 | 98 | #ifdef SHA2_USE_INTTYPES_H |
ashleymills | 0:ff9ebe0cf0e9 | 99 | |
ashleymills | 0:ff9ebe0cf0e9 | 100 | typedef struct _SHA256_CTX { |
ashleymills | 0:ff9ebe0cf0e9 | 101 | uint32_t state[8]; |
ashleymills | 0:ff9ebe0cf0e9 | 102 | uint64_t bitcount; |
ashleymills | 0:ff9ebe0cf0e9 | 103 | uint8_t buffer[SHA256_BLOCK_LENGTH]; |
ashleymills | 0:ff9ebe0cf0e9 | 104 | } SHA256_CTX; |
ashleymills | 0:ff9ebe0cf0e9 | 105 | typedef struct _SHA512_CTX { |
ashleymills | 0:ff9ebe0cf0e9 | 106 | uint64_t state[8]; |
ashleymills | 0:ff9ebe0cf0e9 | 107 | uint64_t bitcount[2]; |
ashleymills | 0:ff9ebe0cf0e9 | 108 | uint8_t buffer[SHA512_BLOCK_LENGTH]; |
ashleymills | 0:ff9ebe0cf0e9 | 109 | } SHA512_CTX; |
ashleymills | 0:ff9ebe0cf0e9 | 110 | |
ashleymills | 0:ff9ebe0cf0e9 | 111 | #else /* SHA2_USE_INTTYPES_H */ |
ashleymills | 0:ff9ebe0cf0e9 | 112 | |
ashleymills | 0:ff9ebe0cf0e9 | 113 | typedef struct _SHA256_CTX { |
ashleymills | 0:ff9ebe0cf0e9 | 114 | u_int32_t state[8]; |
ashleymills | 0:ff9ebe0cf0e9 | 115 | u_int64_t bitcount; |
ashleymills | 0:ff9ebe0cf0e9 | 116 | u_int8_t buffer[SHA256_BLOCK_LENGTH]; |
ashleymills | 0:ff9ebe0cf0e9 | 117 | } SHA256_CTX; |
ashleymills | 0:ff9ebe0cf0e9 | 118 | typedef struct _SHA512_CTX { |
ashleymills | 0:ff9ebe0cf0e9 | 119 | u_int64_t state[8]; |
ashleymills | 0:ff9ebe0cf0e9 | 120 | u_int64_t bitcount[2]; |
ashleymills | 0:ff9ebe0cf0e9 | 121 | u_int8_t buffer[SHA512_BLOCK_LENGTH]; |
ashleymills | 0:ff9ebe0cf0e9 | 122 | } SHA512_CTX; |
ashleymills | 0:ff9ebe0cf0e9 | 123 | |
ashleymills | 0:ff9ebe0cf0e9 | 124 | #endif /* SHA2_USE_INTTYPES_H */ |
ashleymills | 0:ff9ebe0cf0e9 | 125 | |
ashleymills | 0:ff9ebe0cf0e9 | 126 | typedef SHA512_CTX SHA384_CTX; |
ashleymills | 0:ff9ebe0cf0e9 | 127 | |
ashleymills | 0:ff9ebe0cf0e9 | 128 | |
ashleymills | 0:ff9ebe0cf0e9 | 129 | /*** SHA-256/384/512 Function Prototypes ******************************/ |
ashleymills | 0:ff9ebe0cf0e9 | 130 | #ifndef NOPROTO |
ashleymills | 0:ff9ebe0cf0e9 | 131 | #ifdef SHA2_USE_INTTYPES_H |
ashleymills | 0:ff9ebe0cf0e9 | 132 | |
ashleymills | 0:ff9ebe0cf0e9 | 133 | #ifdef WITH_SHA256 |
ashleymills | 0:ff9ebe0cf0e9 | 134 | void SHA256_Init(SHA256_CTX *); |
ashleymills | 0:ff9ebe0cf0e9 | 135 | void SHA256_Update(SHA256_CTX*, const uint8_t*, size_t); |
ashleymills | 0:ff9ebe0cf0e9 | 136 | void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*); |
ashleymills | 0:ff9ebe0cf0e9 | 137 | char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]); |
ashleymills | 0:ff9ebe0cf0e9 | 138 | char* SHA256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]); |
ashleymills | 0:ff9ebe0cf0e9 | 139 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 140 | |
ashleymills | 0:ff9ebe0cf0e9 | 141 | #ifdef WITH_SHA384 |
ashleymills | 0:ff9ebe0cf0e9 | 142 | void SHA384_Init(SHA384_CTX*); |
ashleymills | 0:ff9ebe0cf0e9 | 143 | void SHA384_Update(SHA384_CTX*, const uint8_t*, size_t); |
ashleymills | 0:ff9ebe0cf0e9 | 144 | void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*); |
ashleymills | 0:ff9ebe0cf0e9 | 145 | char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]); |
ashleymills | 0:ff9ebe0cf0e9 | 146 | char* SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]); |
ashleymills | 0:ff9ebe0cf0e9 | 147 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 148 | |
ashleymills | 0:ff9ebe0cf0e9 | 149 | #ifdef WITH_SHA512 |
ashleymills | 0:ff9ebe0cf0e9 | 150 | void SHA512_Init(SHA512_CTX*); |
ashleymills | 0:ff9ebe0cf0e9 | 151 | void SHA512_Update(SHA512_CTX*, const uint8_t*, size_t); |
ashleymills | 0:ff9ebe0cf0e9 | 152 | void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*); |
ashleymills | 0:ff9ebe0cf0e9 | 153 | char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]); |
ashleymills | 0:ff9ebe0cf0e9 | 154 | char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]); |
ashleymills | 0:ff9ebe0cf0e9 | 155 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 156 | |
ashleymills | 0:ff9ebe0cf0e9 | 157 | #else /* SHA2_USE_INTTYPES_H */ |
ashleymills | 0:ff9ebe0cf0e9 | 158 | |
ashleymills | 0:ff9ebe0cf0e9 | 159 | #ifdef WITH_SHA256 |
ashleymills | 0:ff9ebe0cf0e9 | 160 | void SHA256_Init(SHA256_CTX *); |
ashleymills | 0:ff9ebe0cf0e9 | 161 | void SHA256_Update(SHA256_CTX*, const u_int8_t*, size_t); |
ashleymills | 0:ff9ebe0cf0e9 | 162 | void SHA256_Final(u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*); |
ashleymills | 0:ff9ebe0cf0e9 | 163 | char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]); |
ashleymills | 0:ff9ebe0cf0e9 | 164 | char* SHA256_Data(const u_int8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]); |
ashleymills | 0:ff9ebe0cf0e9 | 165 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 166 | |
ashleymills | 0:ff9ebe0cf0e9 | 167 | #ifdef WITH_SHA384 |
ashleymills | 0:ff9ebe0cf0e9 | 168 | void SHA384_Init(SHA384_CTX*); |
ashleymills | 0:ff9ebe0cf0e9 | 169 | void SHA384_Update(SHA384_CTX*, const u_int8_t*, size_t); |
ashleymills | 0:ff9ebe0cf0e9 | 170 | void SHA384_Final(u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*); |
ashleymills | 0:ff9ebe0cf0e9 | 171 | char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]); |
ashleymills | 0:ff9ebe0cf0e9 | 172 | char* SHA384_Data(const u_int8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]); |
ashleymills | 0:ff9ebe0cf0e9 | 173 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 174 | |
ashleymills | 0:ff9ebe0cf0e9 | 175 | #ifdef WITH_SHA512 |
ashleymills | 0:ff9ebe0cf0e9 | 176 | void SHA512_Init(SHA512_CTX*); |
ashleymills | 0:ff9ebe0cf0e9 | 177 | void SHA512_Update(SHA512_CTX*, const u_int8_t*, size_t); |
ashleymills | 0:ff9ebe0cf0e9 | 178 | void SHA512_Final(u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*); |
ashleymills | 0:ff9ebe0cf0e9 | 179 | char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]); |
ashleymills | 0:ff9ebe0cf0e9 | 180 | char* SHA512_Data(const u_int8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]); |
ashleymills | 0:ff9ebe0cf0e9 | 181 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 182 | |
ashleymills | 0:ff9ebe0cf0e9 | 183 | #endif /* SHA2_USE_INTTYPES_H */ |
ashleymills | 0:ff9ebe0cf0e9 | 184 | |
ashleymills | 0:ff9ebe0cf0e9 | 185 | #else /* NOPROTO */ |
ashleymills | 0:ff9ebe0cf0e9 | 186 | |
ashleymills | 0:ff9ebe0cf0e9 | 187 | #ifdef WITH_SHA256 |
ashleymills | 0:ff9ebe0cf0e9 | 188 | void SHA256_Init(); |
ashleymills | 0:ff9ebe0cf0e9 | 189 | void SHA256_Update(); |
ashleymills | 0:ff9ebe0cf0e9 | 190 | void SHA256_Final(); |
ashleymills | 0:ff9ebe0cf0e9 | 191 | char* SHA256_End(); |
ashleymills | 0:ff9ebe0cf0e9 | 192 | char* SHA256_Data(); |
ashleymills | 0:ff9ebe0cf0e9 | 193 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 194 | |
ashleymills | 0:ff9ebe0cf0e9 | 195 | #ifdef WITH_SHA384 |
ashleymills | 0:ff9ebe0cf0e9 | 196 | void SHA384_Init(); |
ashleymills | 0:ff9ebe0cf0e9 | 197 | void SHA384_Update(); |
ashleymills | 0:ff9ebe0cf0e9 | 198 | void SHA384_Final(); |
ashleymills | 0:ff9ebe0cf0e9 | 199 | char* SHA384_End(); |
ashleymills | 0:ff9ebe0cf0e9 | 200 | char* SHA384_Data(); |
ashleymills | 0:ff9ebe0cf0e9 | 201 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 202 | |
ashleymills | 0:ff9ebe0cf0e9 | 203 | #ifdef WITH_SHA512 |
ashleymills | 0:ff9ebe0cf0e9 | 204 | void SHA512_Init(); |
ashleymills | 0:ff9ebe0cf0e9 | 205 | void SHA512_Update(); |
ashleymills | 0:ff9ebe0cf0e9 | 206 | void SHA512_Final(); |
ashleymills | 0:ff9ebe0cf0e9 | 207 | char* SHA512_End(); |
ashleymills | 0:ff9ebe0cf0e9 | 208 | char* SHA512_Data(); |
ashleymills | 0:ff9ebe0cf0e9 | 209 | #endif |
ashleymills | 0:ff9ebe0cf0e9 | 210 | |
ashleymills | 0:ff9ebe0cf0e9 | 211 | #endif /* NOPROTO */ |
ashleymills | 0:ff9ebe0cf0e9 | 212 | |
ashleymills | 0:ff9ebe0cf0e9 | 213 | #ifdef __cplusplus |
ashleymills | 0:ff9ebe0cf0e9 | 214 | } |
ashleymills | 0:ff9ebe0cf0e9 | 215 | #endif /* __cplusplus */ |
ashleymills | 0:ff9ebe0cf0e9 | 216 | |
ashleymills | 0:ff9ebe0cf0e9 | 217 | #endif /* __SHA2_H__ */ |
ashleymills | 0:ff9ebe0cf0e9 | 218 |