diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/md32_common.h | 309 |
1 files changed, 0 insertions, 309 deletions
diff --git a/src/lib/libcrypto/md32_common.h b/src/lib/libcrypto/md32_common.h deleted file mode 100644 index f61c49f03c..0000000000 --- a/src/lib/libcrypto/md32_common.h +++ /dev/null | |||
| @@ -1,309 +0,0 @@ | |||
| 1 | /* $OpenBSD: md32_common.h,v 1.26 2023/08/10 07:15:23 jsing Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * licensing@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | */ | ||
| 51 | |||
| 52 | /* | ||
| 53 | * This is a generic 32 bit "collector" for message digest algorithms. | ||
| 54 | * Whenever needed it collects input character stream into chunks of | ||
| 55 | * 32 bit values and invokes a block function that performs actual hash | ||
| 56 | * calculations. | ||
| 57 | * | ||
| 58 | * Porting guide. | ||
| 59 | * | ||
| 60 | * Obligatory macros: | ||
| 61 | * | ||
| 62 | * DATA_ORDER_IS_BIG_ENDIAN or DATA_ORDER_IS_LITTLE_ENDIAN | ||
| 63 | * this macro defines byte order of input stream. | ||
| 64 | * HASH_CBLOCK | ||
| 65 | * size of a unit chunk HASH_BLOCK operates on. | ||
| 66 | * HASH_LONG | ||
| 67 | * has to be at least 32 bit wide. | ||
| 68 | * HASH_CTX | ||
| 69 | * context structure that at least contains following | ||
| 70 | * members: | ||
| 71 | * typedef struct { | ||
| 72 | * ... | ||
| 73 | * HASH_LONG Nl,Nh; | ||
| 74 | * either { | ||
| 75 | * HASH_LONG data[HASH_LBLOCK]; | ||
| 76 | * unsigned char data[HASH_CBLOCK]; | ||
| 77 | * }; | ||
| 78 | * unsigned int num; | ||
| 79 | * ... | ||
| 80 | * } HASH_CTX; | ||
| 81 | * data[] vector is expected to be zeroed upon first call to | ||
| 82 | * HASH_UPDATE. | ||
| 83 | * HASH_UPDATE | ||
| 84 | * name of "Update" function, implemented here. | ||
| 85 | * HASH_TRANSFORM | ||
| 86 | * name of "Transform" function, implemented here. | ||
| 87 | * HASH_FINAL | ||
| 88 | * name of "Final" function, implemented here. | ||
| 89 | * HASH_BLOCK_DATA_ORDER | ||
| 90 | * name of "block" function capable of treating *unaligned* input | ||
| 91 | * message in original (data) byte order, implemented externally. | ||
| 92 | * HASH_MAKE_STRING | ||
| 93 | * macro convering context variables to an ASCII hash string. | ||
| 94 | * | ||
| 95 | * MD5 example: | ||
| 96 | * | ||
| 97 | * #define DATA_ORDER_IS_LITTLE_ENDIAN | ||
| 98 | * | ||
| 99 | * #define HASH_LONG MD5_LONG | ||
| 100 | * #define HASH_CTX MD5_CTX | ||
| 101 | * #define HASH_CBLOCK MD5_CBLOCK | ||
| 102 | * #define HASH_UPDATE MD5_Update | ||
| 103 | * #define HASH_TRANSFORM MD5_Transform | ||
| 104 | * #define HASH_FINAL MD5_Final | ||
| 105 | * #define HASH_BLOCK_DATA_ORDER md5_block_data_order | ||
| 106 | * | ||
| 107 | * <appro@fy.chalmers.se> | ||
| 108 | */ | ||
| 109 | |||
| 110 | #include <stdint.h> | ||
| 111 | |||
| 112 | #include <openssl/opensslconf.h> | ||
| 113 | |||
| 114 | #include "crypto_internal.h" | ||
| 115 | |||
| 116 | #if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN) | ||
| 117 | #error "DATA_ORDER must be defined!" | ||
| 118 | #endif | ||
| 119 | |||
| 120 | #ifndef HASH_CBLOCK | ||
| 121 | #error "HASH_CBLOCK must be defined!" | ||
| 122 | #endif | ||
| 123 | #ifndef HASH_LONG | ||
| 124 | #error "HASH_LONG must be defined!" | ||
| 125 | #endif | ||
| 126 | #ifndef HASH_CTX | ||
| 127 | #error "HASH_CTX must be defined!" | ||
| 128 | #endif | ||
| 129 | |||
| 130 | #if !defined(HASH_UPDATE) && !defined(HASH_NO_UPDATE) | ||
| 131 | #error "HASH_UPDATE must be defined!" | ||
| 132 | #endif | ||
| 133 | #if !defined(HASH_TRANSFORM) && !defined(HASH_NO_TRANSFORM) | ||
| 134 | #error "HASH_TRANSFORM must be defined!" | ||
| 135 | #endif | ||
| 136 | #if !defined(HASH_FINAL) && !defined(HASH_NO_FINAL) | ||
| 137 | #error "HASH_FINAL or HASH_NO_FINAL must be defined!" | ||
| 138 | #endif | ||
| 139 | |||
| 140 | #ifndef HASH_BLOCK_DATA_ORDER | ||
| 141 | #error "HASH_BLOCK_DATA_ORDER must be defined!" | ||
| 142 | #endif | ||
| 143 | |||
| 144 | #define ROTATE(a, n) crypto_rol_u32(a, n) | ||
| 145 | |||
| 146 | #if defined(DATA_ORDER_IS_BIG_ENDIAN) | ||
| 147 | |||
| 148 | #if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) | ||
| 149 | # if (defined(__i386) || defined(__i386__) || \ | ||
| 150 | defined(__x86_64) || defined(__x86_64__)) | ||
| 151 | /* | ||
| 152 | * This gives ~30-40% performance improvement in SHA-256 compiled | ||
| 153 | * with gcc [on P4]. Well, first macro to be frank. We can pull | ||
| 154 | * this trick on x86* platforms only, because these CPUs can fetch | ||
| 155 | * unaligned data without raising an exception. | ||
| 156 | */ | ||
| 157 | # define HOST_c2l(c,l) ({ unsigned int r=*((const unsigned int *)(c)); \ | ||
| 158 | asm ("bswapl %0":"=r"(r):"0"(r)); \ | ||
| 159 | (c)+=4; (l)=r; }) | ||
| 160 | # define HOST_l2c(l,c) ({ unsigned int r=(l); \ | ||
| 161 | asm ("bswapl %0":"=r"(r):"0"(r)); \ | ||
| 162 | *((unsigned int *)(c))=r; (c)+=4; }) | ||
| 163 | # endif | ||
| 164 | #endif | ||
| 165 | |||
| 166 | #ifndef HOST_c2l | ||
| 167 | #define HOST_c2l(c,l) do {l =(((unsigned long)(*((c)++)))<<24); \ | ||
| 168 | l|=(((unsigned long)(*((c)++)))<<16); \ | ||
| 169 | l|=(((unsigned long)(*((c)++)))<< 8); \ | ||
| 170 | l|=(((unsigned long)(*((c)++))) ); \ | ||
| 171 | } while (0) | ||
| 172 | #endif | ||
| 173 | #ifndef HOST_l2c | ||
| 174 | #define HOST_l2c(l,c) do {*((c)++)=(unsigned char)(((l)>>24)&0xff); \ | ||
| 175 | *((c)++)=(unsigned char)(((l)>>16)&0xff); \ | ||
| 176 | *((c)++)=(unsigned char)(((l)>> 8)&0xff); \ | ||
| 177 | *((c)++)=(unsigned char)(((l) )&0xff); \ | ||
| 178 | } while (0) | ||
| 179 | #endif | ||
| 180 | |||
| 181 | #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) | ||
| 182 | |||
| 183 | #if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) | ||
| 184 | # define HOST_c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4) | ||
| 185 | # define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4) | ||
| 186 | #endif | ||
| 187 | |||
| 188 | #ifndef HOST_c2l | ||
| 189 | #define HOST_c2l(c,l) do {l =(((unsigned long)(*((c)++))) ); \ | ||
| 190 | l|=(((unsigned long)(*((c)++)))<< 8); \ | ||
| 191 | l|=(((unsigned long)(*((c)++)))<<16); \ | ||
| 192 | l|=(((unsigned long)(*((c)++)))<<24); \ | ||
| 193 | } while (0) | ||
| 194 | #endif | ||
| 195 | #ifndef HOST_l2c | ||
| 196 | #define HOST_l2c(l,c) do {*((c)++)=(unsigned char)(((l) )&0xff); \ | ||
| 197 | *((c)++)=(unsigned char)(((l)>> 8)&0xff); \ | ||
| 198 | *((c)++)=(unsigned char)(((l)>>16)&0xff); \ | ||
| 199 | *((c)++)=(unsigned char)(((l)>>24)&0xff); \ | ||
| 200 | } while (0) | ||
| 201 | #endif | ||
| 202 | |||
| 203 | #endif | ||
| 204 | |||
| 205 | /* | ||
| 206 | * Time for some action:-) | ||
| 207 | */ | ||
| 208 | |||
| 209 | #ifndef HASH_NO_UPDATE | ||
| 210 | int | ||
| 211 | HASH_UPDATE(HASH_CTX *c, const void *data_, size_t len) | ||
| 212 | { | ||
| 213 | const unsigned char *data = data_; | ||
| 214 | unsigned char *p; | ||
| 215 | HASH_LONG l; | ||
| 216 | size_t n; | ||
| 217 | |||
| 218 | if (len == 0) | ||
| 219 | return 1; | ||
| 220 | |||
| 221 | l = (c->Nl + (((HASH_LONG)len) << 3))&0xffffffffUL; | ||
| 222 | /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to | ||
| 223 | * Wei Dai <weidai@eskimo.com> for pointing it out. */ | ||
| 224 | if (l < c->Nl) /* overflow */ | ||
| 225 | c->Nh++; | ||
| 226 | c->Nh+=(HASH_LONG)(len>>29); /* might cause compiler warning on 16-bit */ | ||
| 227 | c->Nl = l; | ||
| 228 | |||
| 229 | n = c->num; | ||
| 230 | if (n != 0) { | ||
| 231 | p = (unsigned char *)c->data; | ||
| 232 | |||
| 233 | if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) { | ||
| 234 | memcpy (p + n, data, HASH_CBLOCK - n); | ||
| 235 | HASH_BLOCK_DATA_ORDER (c, p, 1); | ||
| 236 | n = HASH_CBLOCK - n; | ||
| 237 | data += n; | ||
| 238 | len -= n; | ||
| 239 | c->num = 0; | ||
| 240 | memset (p,0,HASH_CBLOCK); /* keep it zeroed */ | ||
| 241 | } else { | ||
| 242 | memcpy (p + n, data, len); | ||
| 243 | c->num += (unsigned int)len; | ||
| 244 | return 1; | ||
| 245 | } | ||
| 246 | } | ||
| 247 | |||
| 248 | n = len/HASH_CBLOCK; | ||
| 249 | if (n > 0) { | ||
| 250 | HASH_BLOCK_DATA_ORDER (c, data, n); | ||
| 251 | n *= HASH_CBLOCK; | ||
| 252 | data += n; | ||
| 253 | len -= n; | ||
| 254 | } | ||
| 255 | |||
| 256 | if (len != 0) { | ||
| 257 | p = (unsigned char *)c->data; | ||
| 258 | c->num = (unsigned int)len; | ||
| 259 | memcpy (p, data, len); | ||
| 260 | } | ||
| 261 | return 1; | ||
| 262 | } | ||
| 263 | #endif | ||
| 264 | |||
| 265 | #ifndef HASH_NO_TRANSFORM | ||
| 266 | void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data) | ||
| 267 | { | ||
| 268 | HASH_BLOCK_DATA_ORDER (c, data, 1); | ||
| 269 | } | ||
| 270 | #endif | ||
| 271 | |||
| 272 | #ifndef HASH_NO_FINAL | ||
| 273 | int HASH_FINAL (unsigned char *md, HASH_CTX *c) | ||
| 274 | { | ||
| 275 | unsigned char *p = (unsigned char *)c->data; | ||
| 276 | size_t n = c->num; | ||
| 277 | |||
| 278 | p[n] = 0x80; /* there is always room for one */ | ||
| 279 | n++; | ||
| 280 | |||
| 281 | if (n > (HASH_CBLOCK - 8)) { | ||
| 282 | memset (p + n, 0, HASH_CBLOCK - n); | ||
| 283 | n = 0; | ||
| 284 | HASH_BLOCK_DATA_ORDER (c, p, 1); | ||
| 285 | } | ||
| 286 | memset (p + n, 0, HASH_CBLOCK - 8 - n); | ||
| 287 | |||
| 288 | p += HASH_CBLOCK - 8; | ||
| 289 | #if defined(DATA_ORDER_IS_BIG_ENDIAN) | ||
| 290 | HOST_l2c(c->Nh, p); | ||
| 291 | HOST_l2c(c->Nl, p); | ||
| 292 | #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) | ||
| 293 | HOST_l2c(c->Nl, p); | ||
| 294 | HOST_l2c(c->Nh, p); | ||
| 295 | #endif | ||
| 296 | p -= HASH_CBLOCK; | ||
| 297 | HASH_BLOCK_DATA_ORDER (c, p, 1); | ||
| 298 | c->num = 0; | ||
| 299 | memset (p, 0, HASH_CBLOCK); | ||
| 300 | |||
| 301 | #ifndef HASH_MAKE_STRING | ||
| 302 | #error "HASH_MAKE_STRING must be defined!" | ||
| 303 | #else | ||
| 304 | HASH_MAKE_STRING(c, md); | ||
| 305 | #endif | ||
| 306 | |||
| 307 | return 1; | ||
| 308 | } | ||
| 309 | #endif | ||
