X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/8ad349bb6ed4a0be06e34c92be0d98b92e078db4..143464d58d2bd6378e74eec636961ceb0d32fb91:/bsd/dev/random/YarrowCoreLib/src/sha1mod.c diff --git a/bsd/dev/random/YarrowCoreLib/src/sha1mod.c b/bsd/dev/random/YarrowCoreLib/src/sha1mod.c index f2b4d0060..c1e245aa3 100644 --- a/bsd/dev/random/YarrowCoreLib/src/sha1mod.c +++ b/bsd/dev/random/YarrowCoreLib/src/sha1mod.c @@ -1,31 +1,29 @@ /* - * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved. + * Copyright (c) 1999, 2000-2001 Apple Computer, Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * - * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. The rights granted to you under the - * License may not be used to create, or enable the creation or - * redistribution of, unlawful or unlicensed copies of an Apple operating - * system, or to circumvent, violate, or enable the circumvention or - * violation of, any terms of an Apple operating system software license - * agreement. - * - * Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and * limitations under the License. - * - * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* @@ -69,12 +67,13 @@ By Steve Reid /* Hash a single 512-bit block. This is the core of the algorithm. */ -void SHA1Transform(unsigned long state[5], const unsigned char buffer[64]) +__private_extern__ void +YSHA1Transform(u_int32_t state[5], const unsigned char buffer[64]) { -unsigned long a, b, c, d, e; +u_int32_t a, b, c, d, e; typedef union { unsigned char c[64]; - unsigned long l[16]; + u_int32_t l[16]; } CHAR64LONG16; CHAR64LONG16* block; #ifdef SHA1HANDSOFF @@ -122,9 +121,10 @@ static unsigned char workspace[64]; } -/* SHA1Init - Initialize new context */ +/* YSHA1Init - Initialize new context */ -void SHA1Init(SHA1_CTX* context) +__private_extern__ void +YSHA1Init(YSHA1_CTX* context) { /* SHA1 initialization constants */ context->state[0] = 0x67452301; @@ -138,7 +138,8 @@ void SHA1Init(SHA1_CTX* context) /* Run your data through this. */ -void SHA1Update(SHA1_CTX* context, const unsigned char* data, unsigned int len) +__private_extern__ void +YSHA1Update(YSHA1_CTX* context, const unsigned char* data, unsigned int len) { unsigned int i, j; @@ -147,9 +148,9 @@ unsigned int i, j; context->count[1] += (len >> 29); if ((j + len) > 63) { memcpy(&context->buffer[j], data, (i = 64-j)); - SHA1Transform(context->state, context->buffer); + YSHA1Transform(context->state, context->buffer); for ( ; i + 63 < len; i += 64) { - SHA1Transform(context->state, &data[i]); + YSHA1Transform(context->state, &data[i]); } j = 0; } @@ -160,20 +161,21 @@ unsigned int i, j; /* Add padding and return the message digest. */ -void SHA1Final(unsigned char digest[20], SHA1_CTX* context) +__private_extern__ void +YSHA1Final(unsigned char digest[20], YSHA1_CTX* context) { -unsigned long i, j; +u_int32_t i, j; unsigned char finalcount[8]; for (i = 0; i < 8; i++) { finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ } - SHA1Update(context, "\200", 1); + YSHA1Update(context, (const unsigned char *)"\200", 1); while ((context->count[0] & 504) != 448) { - SHA1Update(context, "\0", 1); + YSHA1Update(context, (const unsigned char *)"\0", 1); } - SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ + YSHA1Update(context, finalcount, 8); /* Should cause a YSHA1Transform() */ for (i = 0; i < 20; i++) { digest[i] = (unsigned char) ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); @@ -184,8 +186,8 @@ unsigned char finalcount[8]; memset(context->state, 0, 20); memset(context->count, 0, 8); memset(finalcount, 0, 8); -#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */ - SHA1Transform(context->state, context->buffer); +#ifdef SHA1HANDSOFF /* make YSHA1Transform overwrite it's own static vars */ + YSHA1Transform(context->state, context->buffer); #endif } @@ -199,7 +201,7 @@ unsigned char finalcount[8]; int main(int argc, char** argv) { int i, j; -SHA1_CTX context; +YSHA1_CTX context; unsigned char digest[20], buffer[16384]; FILE* file; @@ -217,12 +219,12 @@ FILE* file; exit(-1); } } - SHA1Init(&context); + YSHA1Init(&context); while (!feof(file)) { /* note: what if ferror(file) */ i = fread(buffer, 1, 16384, file); - SHA1Update(&context, buffer, i); + YSHA1Update(&context, buffer, i); } - SHA1Final(digest, &context); + YSHA1Final(digest, &context); fclose(file); for (i = 0; i < 5; i++) { for (j = 0; j < 4; j++) {